Localisation For "Proceed","Confirm","Notify"

Started by _PJ_, July 25, 2023, 12:04:37

Previous topic - Next topic

_PJ_

 A barebones override for MaxGUI "Proceed","Confirm" and "Notify" functions which will allow for localisation.
There are a couple issues - the icon display is missing (I need to understand how to extract from shell.dll) and the textbox looks a little sad.

The localization tokens need to be defined elsewhere, but the following templates are used here and assigned to constants.

{{loc_proceed}} Proceed
{{loc_confirm}} Confirm
{{loc_notify}} Notify
{{loc_ok}} Ok
{{loc_yes}} Yes
{{loc_no}} No
{{loc_cancel}} Cancel









'Import MaxGUI.Drivers
'Import MaxGUI.Localization

Const SEVERITY_CRITICAL:Byte=1
Const SEVERITY_INFORMATION:Byte=0

Const LOC_PROCEED:String="{{loc_proceed}}"
Const LOC_CONFIRM:String="{{loc_confirm}}"
Const LOC_NOTIFY:String="{{loc_notify}}"
Const LOC_OK:String="{{loc_ok}}"
Const LOC_YES:String="{{loc_yes}}"
Const LOC_NO:String="{{loc_no}}"
Const LOC_CANCEL:String="{{loc_cancel}}"

'Assumes Localisation Mode is active
Function Proceed:Int(Text:String,Severity:Byte=SEVERITY_INFORMATION)
    Local PWind:TGadget=CreateWindow(LocalizeString(LOC_PROCEED),0,0,256,128,Null,WINDOW_TITLEBAR|WINDOW_TOOL|WINDOW_CENTER)
    Local YesButton:TGadget=CreateButton(LocalizeString(LOC_YES),16,GadgetHeight(PWind)-64,64,24,PWind,BUTTON_OK)
    Local NoButton:TGadget=CreateButton(LocalizeString(LOC_NO),96,GadgetHeight(PWind)-64,64,24,PWind,BUTTON_PUSH)
    Local CancelButton:TGadget=CreateButton(LocalizeString(LOC_CANCEL),176,GadgetHeight(PWind)-64,64,24,PWind,BUTTON_CANCEL)

    'Add "Hotkeys" functionality-------------------------------------------------------------------------------------------------- TO DO

    Local TextArea:TGadget=CreateTextArea(16,0,GadgetWidth(PWind)-32,64,PWind,TEXTAREA_WORDWRAP|TEXTAREA_READONLY)
    SetMargins(TextArea,48)
    SetGadgetText(TextArea,Text)'SetGadgetText(TextArea,LocalizeString(Text)) [Localization of content can be handled by the dev in all cases]
   
    'Add "Serious" Icon according to Severity------------------------------------------------------------------------------------- TO DO
   
    Local Done:Byte=Null       
    Local Result:Int=0
   
        ActivateWindow(PWind)
        EnableGadget(PWind)
        ShowGadget(PWind)
       
    Repeat   
       
        Local nPEvent=WaitEvent()
           
        Select EventID()       
            Case EVENT_WINDOWCLOSE
                If (Not(Done)) Then Result=-1
                Done=True               
            Case EVENT_GADGETACTION
                Select (EventSource())
                    Case YesButton
                        Done=True
                        Result=1
                        Local E:TEvent=CreateEvent(EVENT_WINDOWCLOSE,PWind)
                        PostEvent(E,False)
                    Case NoButton
                        Done=True
                        Result=0
                        Local E:TEvent=CreateEvent(EVENT_WINDOWCLOSE,PWind)
                        PostEvent(E,False)   
                    Case CancelButton
                        Done=True
                        Result=-1
                        Local E:TEvent=CreateEvent(EVENT_WINDOWCLOSE,PWind)
                        PostEvent(E,False)
                End Select
        End Select   
    Until (Done)
    Return Result
End Function

'Assumes Localisation Mode is active
Function Confirm:Int(Text:String,Severity:Byte=SEVERITY_INFORMATION)
    Local CWind:TGadget=CreateWindow(LocalizeString(LOC_CONFIRM),0,0,256,128,Null,WINDOW_TITLEBAR|WINDOW_TOOL|WINDOW_CENTER)
    Local OkButton:TGadget=CreateButton(LocalizeString(LOC_OK),16,GadgetHeight(CWind)-64,64,24,CWind,BUTTON_OK)
    Local CancelButton:TGadget=CreateButton(LocalizeString(LOC_CANCEL),176,GadgetHeight(CWind)-64,64,24,CWind,BUTTON_CANCEL)

    Local TextArea:TGadget=CreateTextArea(16,0,GadgetWidth(CWind)-32,64,CWind,TEXTAREA_WORDWRAP|TEXTAREA_READONLY)
    SetMargins(TextArea,48)
    SetGadgetText(TextArea,Text)'SetGadgetText(TextArea,LocalizeString(Text)) [Localization of content can be handled by the dev in all cases]
   
    'Add "Serious" Icon according to Severity------------------------------------------------------------------------------------- TO DO
   
    Local Done:Byte=Null       
    Local Result:Int=0

        ActivateWindow(CWind)
        EnableGadget(CWind)
        ShowGadget(CWind)   
    Repeat

               
        Local nCEvent=WaitEvent()
             
        Select EventID()
            Case EVENT_WINDOWCLOSE
                If (Not(Done)) Then Result=0
                Done=True
            Case EVENT_GADGETACTION
                Select (EventSource())
                    Case OkButton
                        Done=True
                        Result=1
                        Local E:TEvent=CreateEvent(EVENT_WINDOWCLOSE,CWind)
                        PostEvent(E,True)
                    Case CancelButton
                        Done=True
                        Result=0
                        Local E:TEvent=CreateEvent(EVENT_WINDOWCLOSE,CWind)
                        PostEvent(E,True)
                End Select   
        End Select   
    Until (Done)
    Return Result
End Function

'Assumes Localisation Mode is active. Traditional Notify always returns 0, this version will return True if user actually pressed the OK button
Function Notify:Int(Text:String,Severity:Byte=SEVERITY_INFORMATION)
    Local NWind:TGadget=CreateWindow(LocalizeString(LOC_NOTIFY),0,0,256,128,Null,WINDOW_TITLEBAR|WINDOW_TOOL|WINDOW_CENTER)
    Local OkButton:TGadget=CreateButton(LocalizeString(LOC_OK),96,GadgetHeight(NWind)-64,64,24,NWind,BUTTON_OK)

    Local TextArea:TGadget=CreateTextArea(16,0,GadgetWidth(NWind)-32,64,NWind,TEXTAREA_WORDWRAP|TEXTAREA_READONLY)
    SetMargins(TextArea,48)
    SetGadgetText(TextArea,Text)'SetGadgetText(TextArea,LocalizeString(Text)) [Localization of content can be handled by the dev in all cases]
   
    'Add "Serious" Icon according to Severity------------------------------------------------------------------------------------- TO DO
   
    Local Done:Byte=Null       
    Local Result:Int=0
   
        ActivateWindow(NWind)
        EnableGadget(NWind)
        ShowGadget(NWind)
       
    Repeat
   
        Local nNEvent=WaitEvent()
           
        Select EventID()   
            Case EVENT_WINDOWCLOSE
                If (Not(Done)) Then Result=0
                Done=True
            Case EVENT_GADGETACTION
                Select (EventSource())
                    Case OkButton
                        Done=True
                        Result=1
                        Local E:TEvent=CreateEvent(EVENT_WINDOWCLOSE,NWind)
                        PostEvent(E,True)
                End Select   
        End Select   
    Until Done
    Return Result
End Function

Midimaster

As far as I know these Gadget are localized by default!!!
See german windows screenshot for this code:
Import maxgui.drivers
Graphics 800,600
Confirm "Hallo"


ConfirmGermany.png
...back from Egypt

_PJ_


Thanks, Midimaster.
The opportunity is here to ensure whatever localisation is chosen in the application is consistent regardless of OS setting.