Page 2 of 2

Re: Switch multiple StringGadgets from ReadOnly to editable

Posted: Wed Nov 25, 2015 9:26 am
by Dude
thinkitsimple wrote:can i change a flag (#PB_String_ReadOnly) after the StringGadget is created?
I know you want cross-platform, but for Windows only you can do this:

Code: Select all

SendMessage_(GadgetID(gad),#EM_SETREADONLY,state,0)
Where "state" is 1 for locked, or 0 for unlocked. Posting this for future reference for Windows users.

Re: Switch multiple StringGadgets from ReadOnly to editable

Posted: Wed Nov 25, 2015 10:54 am
by infratec
Hi,

as I promised, I tested this on OS X el capitan.
It works:

Code: Select all

EnableExplicit

Define.i Event, Exit


OpenWindow(0, 0, 0, 400, 300, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

ContainerGadget(9, 0, 0, 200, 160)
StringGadget(0, 10, 10, 100, 20, "")
StringGadget(1, 10, 40, 100, 20, "")
StringGadget(2, 10, 70, 100, 20, "")
StringGadget(3, 10, 100, 100, 20, "")
TextGadget(5, 10, 130, 100, 20, "DummyText")
CloseGadgetList()

DisableGadget(9, #True)

ButtonGadget(10, 200, 10, 80, 30, "Toggle", #PB_Button_Toggle)


Repeat
 
  Event = WaitWindowEvent()
 
  Select Event
    Case #PB_Event_Gadget
      If EventGadget() = 10
        If GetGadgetState(10)
          DisableGadget(9, #False)
        Else
          SetActiveGadget(5)
          DisableGadget(9, #True)
        EndIf
      EndIf
     
    Case #PB_Event_CloseWindow
      Exit = #True
     
  EndSelect
 
Until Exit
Bernd

Re: Switch multiple StringGadgets from ReadOnly to editable

Posted: Wed Nov 25, 2015 11:09 am
by HeX0R
Disabling the StringGadget is not the same then ReadOnly mode!
You can still select the text in a ReadOnly StringGadget, but not in a disabled one!

The only possibility to do this without API is to recreate all of the gadgets.

Re: Switch multiple StringGadgets from ReadOnly to editable

Posted: Wed Nov 25, 2015 12:40 pm
by RASHAD
It is not that perfect
But I am trying to use all what I can get from PB :mrgreen:

Code: Select all

OpenWindow(0, 0, 0, 400, 300, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

StringGadget(0, 10, 10, 100, 20, "")
StringGadget(1, 10, 40, 100, 20, "")
StringGadget(2, 10, 70, 100, 20, "")
StringGadget(3, 10, 100, 100, 20, "")
EditorGadget(5, 10, 130, 100, 20)
SetGadgetText(5,"For test")

ButtonGadget(10, 200, 10, 80, 30, "Toggle", #PB_Button_Toggle)

Repeat
 
  Event = WaitWindowEvent()
 
  Select Event
    Case #PB_Event_Menu
      Select EventMenu()
        Case 10,11
      EndSelect
           
    Case #PB_Event_Gadget
      Select  EventGadget()
        Case 0 To 3
          If Flag = 1
              SetGadgetAttribute(EventGadget(),#PB_String_MaximumLength,0)
              AddKeyboardShortcut(0,#PB_Shortcut_Delete,10)
              AddKeyboardShortcut(0,#PB_Shortcut_Back,11)              
              ;AddKeyboardShortcut(0,#PB_Shortcut_Left,12)
              ;AddKeyboardShortcut(0,#PB_Shortcut_Right,13)
          Else
              SetGadgetAttribute(EventGadget(),#PB_String_MaximumLength,256)
              RemoveKeyboardShortcut(0,#PB_Shortcut_All)
          EndIf          
          Debug GetGadgetText(EventGadget())
          
        Case 5
            RemoveKeyboardShortcut(0,#PB_Shortcut_All)
          
        Case 10
            If GetGadgetState(10)
              flag = 1
            Else
              flag = 0
            EndIf
      EndSelect
     
    Case #PB_Event_CloseWindow
      Exit = #True
     
  EndSelect
 
Until Exit

Re: Switch multiple StringGadgets from ReadOnly to editable

Posted: Wed Nov 25, 2015 2:08 pm
by IdeasVacuum
..another way would be to have a pair of string gadgets defined in the same place - display the read-only one at first, with the editable one hidden.
In other words: can i change a flag (#PB_String_ReadOnly) after the StringGadget is created?
Nope.

Re: Switch multiple StringGadgets from ReadOnly to editable

Posted: Wed Nov 25, 2015 2:22 pm
by RASHAD
Taking HeX0R comment into account
Just modifying Bernd last post a little bit
What do you need from StringGadget() except GetGadgetText()

Code: Select all

;EnableExplicit

Global Flag

Procedure _GetGadgetText(Gad)
If Flag = 1
  DisableGadget(9, #False)  
  Debug GetGadgetText(Gad)
  DisableGadget(9, #True)
Else
  Debug GetGadgetText(Gad)
EndIf
EndProcedure 

OpenWindow(0, 0, 0, 400, 300, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

ContainerGadget(9, 0, 0, 200, 160)
StringGadget(0, 10, 10, 100, 20, "")
StringGadget(1, 10, 40, 100, 20, "")
StringGadget(2, 10, 70, 100, 20, "")
StringGadget(3, 10, 100, 100, 20, "")
TextGadget(5, 10, 130, 100, 20, "DummyText")
CloseGadgetList()

ButtonGadget(10, 200, 10, 80, 30, "Toggle", #PB_Button_Toggle)

ButtonGadget(20, 200, 50, 80, 30, "Get #0 Text")


Repeat
 
  Event = WaitWindowEvent()
 
  Select Event
      
    Case #PB_Event_Gadget
      Select EventGadget()
      Case 10
        If GetGadgetState(10) = 0
          DisableGadget(9, #False)
          Flag = 0
        Else
          OldGad = GetActiveGadget()
          SetActiveGadget(5)
          SetGadgetColor(0,#PB_Gadget_BackColor,$ABF6FE)
          DisableGadget(9, #True)
          Flag = 1
        EndIf
      
    Case 20    
      _GetGadgetText(0)
      EndSelect
     
    Case #PB_Event_CloseWindow
      Exit = #True
     
  EndSelect
 
Until Exit

Re: Switch multiple StringGadgets from ReadOnly to editable

Posted: Wed Nov 25, 2015 6:41 pm
by Shardik
IdeasVacuum wrote:
In other words: can i change a flag (#PB_String_ReadOnly) after the StringGadget is created?
Nope.
Not quite right! I posted already this code example which demonstrates how to toggle the read only attribute of a StringGadget cross-platform... :wink:

Re: Switch multiple StringGadgets from ReadOnly to editable

Posted: Thu Nov 26, 2015 12:28 am
by IdeasVacuum
Nice example Shardik - given that it is possible via API on all supported platforms, surely PB should allow this natively.