It is currently Mon May 20, 2013 9:38 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Automatic handling of ThreeState checkboxes
PostPosted: Fri Apr 13, 2012 6:47 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Feb 09, 2006 11:27 pm
Posts: 1716
Maybe there's a simple approach to handle checkboxes using the #PB_CheckBox_ThreeState flag, but I don't think so.
Wouldn't it be fine, if PB would be able to handle also three state boxes automatically?

Code:
Procedure SetGadgetThreeState(Gadget,Value,*State.Integer=0)
   If Value=2
      Value=-1
   EndIf
   SetGadgetState(Gadget,Value)
   If *State
      *State\i=Value
   EndIf
   ProcedureReturn value
EndProcedure

*** Initialization ***
OptFatLineState=0
SetGadgetState(#OptFatLine,OptFatLineState)

*** Event-Handling ***
  Case #PB_Event_Gadget,#PB_Event_Menu
     Select EventGadget()
        :
   Case #OptFatLine
      OptFatLineState=(OptFatLineState+1)%3
      SetGadgetThreeState(#OptFatLine,OptFatLineState)



Top
 Profile  
 
 Post subject: Re: Automatic handling of ThreeState checkboxes
PostPosted: Sun Apr 15, 2012 12:37 am 
Offline
Addict
Addict
User avatar

Joined: Sat Apr 26, 2003 8:26 am
Posts: 1290
Michael Vogel wrote:
Wouldn't it be fine, if PB would be able to handle also three state boxes automatically?

Like the following on Windows?
Code:
If OpenWindow(0, 0, 0, 270, 160, "CheckBoxGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ButtonGadget(1, 10,  10, 250, 20, "CheckBox three state", #BS_AUTO3STATE)
    Repeat
        Select WaitWindowEvent()
            Case #PB_Event_CloseWindow : End
            Case #PB_Event_Gadget      : Debug SendMessage_(GadgetID(1),#BM_GETSTATE,0,0)&3
        EndSelect
    ForEver
EndIf

Makes sense for cross-platform #PB_CheckBox_ThreeState.

BS_AUTO3STATE wrote:
Creates a button that is the same as a three-state check box, except that the box changes its state when the user selects it.
The state cycles through checked, indeterminate, and cleared.


Top
 Profile  
 
 Post subject: Re: Automatic handling of ThreeState checkboxes
PostPosted: Sun Apr 15, 2012 6:10 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 814
Location: Germany
PB help for CheckBoxGadget() wrote:
By clicking on the checkbox, the user can bring it back to either the "on" or "off" state to apply this to all the items. Therefore the "inbetween" state can only be set by the program via SetGadgetState() and not by the user by clicking on the checkbox.

As a workaround for cycling through all 3 states when clicking onto the
CheckBoxGadget it's not necessary to use API functions. The following
example works cross-platform (tested on Windows 7 x86, Kubuntu 9.04,
Xubuntu 10.04 and MacOS X 10.6.8 ):
Code:
OpenWindow(0, 270, 100, 270, 40, "Cycle through CheckBox states")
CheckBoxGadget(0, 10, 10, 250, 20, "3-state CheckBox", #PB_CheckBox_ThreeState)
CheckBoxState = 1

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Gadget
      If EventGadget() = 0
        CheckBoxState = (CheckBoxState + 1) % 3

        If CheckBoxState = 2
          SetGadgetState(0, #PB_Checkbox_Inbetween)
        EndIf
      EndIf
  EndSelect
ForEver


Top
 Profile  
 
 Post subject: Re: Automatic handling of ThreeState checkboxes
PostPosted: Tue Apr 17, 2012 10:01 am 
Offline
Addict
Addict
User avatar

Joined: Thu Feb 09, 2006 11:27 pm
Posts: 1716
Danilo wrote:
Michael Vogel wrote:
Wouldn't it be fine, if PB would be able to handle also three state boxes automatically?

Like the following on Windows?
Code:
If OpenWindow(0, 0, 0, 270, 160, "CheckBoxGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ButtonGadget(1, 10,  10, 250, 20, "CheckBox three state", #BS_AUTO3STATE)
    Repeat
        Select WaitWindowEvent()
            Case #PB_Event_CloseWindow : End
            Case #PB_Event_Gadget      : Debug SendMessage_(GadgetID(1),#BM_GETSTATE,0,0)&3
        EndSelect
    ForEver
EndIf

Makes sense for cross-platform #PB_CheckBox_ThreeState.

BS_AUTO3STATE wrote:
Creates a button that is the same as a three-state check box, except that the box changes its state when the user selects it.
The state cycles through checked, indeterminate, and cleared.


Exactly, thanks :)

PS: I believe, BM_GETCHECK and BM_SETCHECK should be used for windows


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye