Approaching Windows behaviour...

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Approaching Windows behaviour...

Post by Michael Vogel »

Hi,

I'm working around with gadgets and think, windows behaviour can be emulated very often without big problems (and with quite nice code)...

Code: Select all

:
ButtonGadget(#copygadget,232,10,75,22,"Starte")
GadgetToolTip(#copygadget,"Starten des Kopiervorgangs")
ButtonGadget(#quitgadget,314,60,75,22,"Ende", #PB_Button_Default)
GadgetToolTip(#quitgadget,"Programm beenden")
:
AddKeyboardShortcut(1,#PB_Shortcut_S,#copygadget)
AddKeyboardShortcut(1,#PB_Shortcut_Escape,#quitgadget)
AddKeyboardShortcut(1,#PB_Shortcut_E,#quitgadget)
:
Repeat
	Select WaitWindowEvent()
	Case #PB_Event_Gadget,#PB_Event_Menu
		Select EventGadget()
		Case #copygadget
			:
		Case #calcgadget
			:
		Case #cleargadget
			:
		Case #quitgadget
			quit=999
		EndSelect

	Case #PB_Event_CloseWindow
		quit=999
		EndSelect
Until quit>0
...but when using Checkboxes and Optiongadgets it gets more difficult...

Code: Select all

:
CheckBoxGadget(#optautocopygadget,20,78,220,20,"Dateien &automatisch kopieren")
:
OptionGadget(#optemptyallgadget,20,168,220,20,"&One")
OptionGadget(#optemptyallgadget+1,20,188,220,20,"&Two")
OptionGadget(#optemptyallgadget+2,20,208,220,20,"T&hree")
:
SetGadgetState(#optemptyallgadget+SelectedOption,1)
:
AddKeyboardShortcut(2,#PB_Shortcut_Escape,#optokgadget)
AddKeyboardShortcut(2,#PB_Shortcut_A,#optautocopygadget)
AddKeyboardShortcut(2,#PB_Shortcut_O,#optemptyallgadget)
AddKeyboardShortcut(2,#PB_Shortcut_T,#optemptyallgadget+1)
AddKeyboardShortcut(2,#PB_Shortcut_H,#optemptyallgadget+2)
:

The Event structure has to be splitted when keyboard shortcuts are used, otherwise mouse clicking on an option key would not change its status. It's not a big deal to change the checkbox state, but more difficult to change the optiongadget status...

Code: Select all

Procedure InvertGadgetState(g.l)
	SetGadgetState(g,1-GetGadgetState(g))
	SetActiveGadget(g)
EndProcedure
:	
Repeat
        Select WaitWindowEvent()
	Case #PB_Event_Gadget
		If EventGadget()=#optokgadget
			quit=999
		EndIf
	Case #PB_Event_Menu
	button=EventGadget()
	Select button
		Case #optautocheckgadget,#optwinsizegadget,#optautocopygadget,#optrecursivegadget,#optautoremovegadget
			InvertGadgetState(button)
		Case #optemptyallgadget,#optemptyallgadget+1,#optemptyallgadget+2
			SetGadgetState(button,1)
			SetActiveGadget(button)
		Case #optokgadget
			quit=999
	EndSelect

       Case #PB_Event_CloseWindow
	quit=999
       EndSelect
Until quit>0

The result of an Optiongadget has to be "calculated"

Code: Select all

SelectedOption=GetGadgetState(#optemptyallgadget+1)+GetGadgetState(#optemptyallgadget+2)<<1+...

But something is still missing: Cursor Up/Down Handling within the OptionGadgets...
USCode
Addict
Addict
Posts: 923
Joined: Wed Mar 24, 2004 11:04 pm
Location: Seattle

Re: Approaching Windows behaviour...

Post by USCode »

Michael Vogel wrote:... But something is still missing: Cursor Up/Down Handling within the OptionGadgets...
Confirmed, even adding SetActiveGadget doesn't enable for arrow up/down keys between option gadgets:

Code: Select all

If OpenWindow(0, 0, 0, 140, 110, "OptionGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
    OptionGadget(0, 30, 20, 60, 20, "Option 1")
    OptionGadget(1, 30, 45, 60, 20, "Option 2")
    OptionGadget(2, 30, 70, 60, 20, "Option 3")
    SetGadgetState(0, #True)   ; set second option as active one
    SetActiveGadget(0)
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf
It's nice to be able to arrow between options to activate them.
Post Reply