Page 1 of 2

Switch multiple StringGadgets from ReadOnly to editable

Posted: Tue Nov 24, 2015 4:49 pm
by thinkitsimple
Hi,

i have a group of StringGadgets. When creating them, they are set to #PB_String_ReadOnly. How can i remove the flag #PB_String_ReadOnly for all the StringGadgets at once?

Code: Select all

CustomerDetails = ScrollAreaGadget(#PB_Any, 0, 0, 300, 100, 300, 500)
  lblCustomerNumber = TextGadget(#PB_Any, 10, 10, 280, 20, LANG_CustomerNumber.s)
  txtCustomerNumber = StringGadget(#PB_Any, 10, 25, 280, 20, "", #PB_String_ReadOnly)
  lblCompany = TextGadget(#PB_Any, 10, 50, 280, 20, LANG_Company.s)
  txtCompany = StringGadget(#PB_Any, 10, 65, 280, 20, "", #PB_String_ReadOnly)
  lblTelephone = TextGadget(#PB_Any, 10, 90, 280, 20, LANG_Telephone.s)
  txtTelephone = StringGadget(#PB_Any, 10, 105, 280, 20, "", #PB_String_ReadOnly)
  lblTelefax = TextGadget(#PB_Any, 10, 130, 280, 20, LANG_Telefax.s)
  txtTelefax = StringGadget(#PB_Any, 10, 145, 280, 20, "", #PB_String_ReadOnly)
  lblEmail = TextGadget(#PB_Any, 10, 170, 280, 20, LANG_Email.s)
  txtEmail = StringGadget(#PB_Any, 10, 185, 280, 20, "", #PB_String_ReadOnly)
  lblInternet = TextGadget(#PB_Any, 10, 210, 280, 20, LANG_Internet.s)
  txtInternet = StringGadget(#PB_Any, 10, 225, 280, 20, "", #PB_String_ReadOnly)
  lblStreet = TextGadget(#PB_Any, 10, 250, 280, 20, LANG_Street.s)
  txtStreet = StringGadget(#PB_Any, 10, 265, 280, 20, "", #PB_String_ReadOnly)
  lblStreetnumber = TextGadget(#PB_Any, 10, 290, 280, 20, LANG_StreetNumber.s)
  txtStreetNumber = StringGadget(#PB_Any, 10, 305, 280, 20, "", #PB_String_ReadOnly)
  lblPostcode = TextGadget(#PB_Any, 10, 330, 280, 20, LANG_Postcode.s)
  txtPostcode = StringGadget(#PB_Any, 10, 345, 280, 20, "", #PB_String_ReadOnly)
  lblCity = TextGadget(#PB_Any, 10, 370, 280, 20, LANG_City.s)
  txtCity = StringGadget(#PB_Any, 10, 385, 280, 20, "", #PB_String_ReadOnly)
  lblCountry = TextGadget(#PB_Any, 10, 410, 280, 20, LANG_Country.s)
  txtCountry = StringGadget(#PB_Any, 10, 425, 280, 20, "", #PB_String_ReadOnly)
  lblStatus = TextGadget(#PB_Any, 10, 450, 280, 20, LANG_Status.s)
  txtStatus = StringGadget(#PB_Any, 10, 465, 280, 20, "", #PB_String_ReadOnly)
  CloseGadgetList()

Re: Switch multiple StringGadgets from ReadOnly to editable

Posted: Tue Nov 24, 2015 5:13 pm
by infratec
Hi,

if you want to do it with PB internal commands, then use DisableGadget() instead of #PB_String_ReadOnly

Code: Select all

EnableExplicit


Procedure Disable(State.i)
  
  Protected i.i
  
  For i = 0 To 3
    DisableGadget(i, State)
  Next i
EndProcedure



Define.i Event, Exit


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, "")

Disable(#True)

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


Repeat
  
  Event = WaitWindowEvent()
  
  Select Event
    Case #PB_Event_Gadget
      If EventGadget() = 10
        If GetGadgetState(10)
          Disable(#False)
        Else
          Disable(#True)
        EndIf
      EndIf
      
    Case #PB_Event_CloseWindow
      Exit = #True
      
  EndSelect
  
Until Exit

Bernd

Re: Switch multiple StringGadgets from ReadOnly to editable

Posted: Tue Nov 24, 2015 5:13 pm
by skywalk
Without api, you could rebuild your gui with the flags omitted and the window momentarily disabled to avoid flicker.

Re: Switch multiple StringGadgets from ReadOnly to editable

Posted: Tue Nov 24, 2015 5:23 pm
by thinkitsimple
infratec wrote:Hi,

if you want to do it with PB internal commands, then use DisableGadget() instead of #PB_String_ReadOnly

Bernd
But using DisableGadget() will result in a grey StringGadget, right?

Re: Switch multiple StringGadgets from ReadOnly to editable

Posted: Tue Nov 24, 2015 5:39 pm
by RASHAD
Windows only

Code: Select all


Dim GID(12)

OpenWindow(0,0,0,340,150,"Test",#PB_Window_SystemMenu |#PB_Window_ScreenCentered)
CustomerDetails = ScrollAreaGadget(#PB_Any, 0, 0, 340, 100, 300, 500)
    lblCustomerNumber = TextGadget(#PB_Any, 10, 10, 280, 20, LANG_CustomerNumber.s)
    txtCustomerNumber = StringGadget(#PB_Any, 10, 25, 280, 20, "", #PB_String_ReadOnly)
    GID(1) = GadgetID(txtCustomerNumber)
    lblCompany = TextGadget(#PB_Any, 10, 50, 280, 20, LANG_Company.s)
    txtCompany = StringGadget(#PB_Any, 10, 65, 280, 20, "", #PB_String_ReadOnly)
    GID(2) = GadgetID(txtCompany)
    lblTelephone = TextGadget(#PB_Any, 10, 90, 280, 20, LANG_Telephone.s)
    txtTelephone = StringGadget(#PB_Any, 10, 105, 280, 20, "", #PB_String_ReadOnly)
    GID(3) = GadgetID(txtTelephone)
    lblTelefax = TextGadget(#PB_Any, 10, 130, 280, 20, LANG_Telefax.s)
    txtTelefax = StringGadget(#PB_Any, 10, 145, 280, 20, "", #PB_String_ReadOnly)
    GID(4) = GadgetID(txtTelefax)
    lblEmail = TextGadget(#PB_Any, 10, 170, 280, 20, LANG_Email.s)
    txtEmail = StringGadget(#PB_Any, 10, 185, 280, 20, "", #PB_String_ReadOnly)
    GID(5) = GadgetID(txtEmail)
    lblInternet = TextGadget(#PB_Any, 10, 210, 280, 20, LANG_Internet.s)
    txtInternet = StringGadget(#PB_Any, 10, 225, 280, 20, "", #PB_String_ReadOnly)
    GID(6) = GadgetID(txtInternet)
    lblStreet = TextGadget(#PB_Any, 10, 250, 280, 20, LANG_Street.s)
    txtStreet = StringGadget(#PB_Any, 10, 265, 280, 20, "", #PB_String_ReadOnly)
    GID(7) = GadgetID(txtStreet)
    lblStreetnumber = TextGadget(#PB_Any, 10, 290, 280, 20, LANG_StreetNumber.s)
    txtStreetNumber = StringGadget(#PB_Any, 10, 305, 280, 20, "", #PB_String_ReadOnly)
    GID(8) = GadgetID(txtStreetNumber)
    lblPostcode = TextGadget(#PB_Any, 10, 330, 280, 20, LANG_Postcode.s)
    txtPostcode = StringGadget(#PB_Any, 10, 345, 280, 20, "", #PB_String_ReadOnly)
    GID(9) = GadgetID(txtPostcode)
    lblCity = TextGadget(#PB_Any, 10, 370, 280, 20, LANG_City.s)
    txtCity = StringGadget(#PB_Any, 10, 385, 280, 20, "", #PB_String_ReadOnly)
    GID(10) = GadgetID(txtCity)
    lblCountry = TextGadget(#PB_Any, 10, 410, 280, 20, LANG_Country.s)
    txtCountry = StringGadget(#PB_Any, 10, 425, 280, 20, "", #PB_String_ReadOnly)
    GID(11) = GadgetID(txtCountry)
    lblStatus = TextGadget(#PB_Any, 10, 450, 280, 20, LANG_Status.s)
    txtStatus = StringGadget(#PB_Any, 10, 465, 280, 20, "", #PB_String_ReadOnly)
    GID(12) = GadgetID(txtStatus)
  CloseGadgetList()
  
  change = ButtonGadget(#PB_Any,10,120,60,20,"Change")
  Readonly = 1
Repeat
           
  Select WaitWindowEvent()
      
      Case #PB_Event_CloseWindow
            Quit = 1
     
      Case #PB_Event_Menu
          Select EventMenu() 
          EndSelect
      
      Case #PB_Event_Gadget
          Select EventGadget()
           Case change
              Readonly ! 1
              For x = 1 To 12
                hWnd = Gid(x)
                SendMessage_(hwnd,#EM_SETREADONLY,Readonly,0)
              Next           
          EndSelect
             
  EndSelect 

Until Quit = 1
  

Re: Switch multiple StringGadgets from ReadOnly to editable

Posted: Tue Nov 24, 2015 5:41 pm
by thinkitsimple
Thanks,

i need this cross-plattform. So i now use 2 procedures to set DisableGadget to 0 or 1.

Re: Switch multiple StringGadgets from ReadOnly to editable

Posted: Tue Nov 24, 2015 6:01 pm
by RASHAD
Cross platform and very simple

Code: Select all


OpenWindow(0,0,0,340,150,"Test",#PB_Window_SystemMenu |#PB_Window_ScreenCentered)
CustomerDetails = ScrollAreaGadget(#PB_Any, 0, 0, 340, 100, 300, 500)
  Cont = ContainerGadget(#PB_Any,0,0,300,500)
    lblCustomerNumber = TextGadget(#PB_Any, 10, 10, 280, 20, LANG_CustomerNumber.s)
    txtCustomerNumber = StringGadget(#PB_Any, 10, 25, 280, 20, "")
    lblCompany = TextGadget(#PB_Any, 10, 50, 280, 20, LANG_Company.s)
    txtCompany = StringGadget(#PB_Any, 10, 65, 280, 20, "")
    lblTelephone = TextGadget(#PB_Any, 10, 90, 280, 20, LANG_Telephone.s)
    txtTelephone = StringGadget(#PB_Any, 10, 105, 280, 20, "")
    lblTelefax = TextGadget(#PB_Any, 10, 130, 280, 20, LANG_Telefax.s)
    txtTelefax = StringGadget(#PB_Any, 10, 145, 280, 20, "")
    lblEmail = TextGadget(#PB_Any, 10, 170, 280, 20, LANG_Email.s)
    txtEmail = StringGadget(#PB_Any, 10, 185, 280, 20, "")
    lblInternet = TextGadget(#PB_Any, 10, 210, 280, 20, LANG_Internet.s)
    txtInternet = StringGadget(#PB_Any, 10, 225, 280, 20, "")
    lblStreet = TextGadget(#PB_Any, 10, 250, 280, 20, LANG_Street.s)
    txtStreet = StringGadget(#PB_Any, 10, 265, 280, 20, "")
    lblStreetnumber = TextGadget(#PB_Any, 10, 290, 280, 20, LANG_StreetNumber.s)
    txtStreetNumber = StringGadget(#PB_Any, 10, 305, 280, 20, "")
    lblPostcode = TextGadget(#PB_Any, 10, 330, 280, 20, LANG_Postcode.s)
    txtPostcode = StringGadget(#PB_Any, 10, 345, 280, 20, "")
    lblCity = TextGadget(#PB_Any, 10, 370, 280, 20, LANG_City.s)
    txtCity = StringGadget(#PB_Any, 10, 385, 280, 20, "")
    lblCountry = TextGadget(#PB_Any, 10, 410, 280, 20, LANG_Country.s)
    txtCountry = StringGadget(#PB_Any, 10, 425, 280, 20, "")
    lblStatus = TextGadget(#PB_Any, 10, 450, 280, 20, LANG_Status.s)
    txtStatus = StringGadget(#PB_Any, 10, 465, 280, 20, "")
    CloseGadgetList()
  CloseGadgetList()  
  
  change = ButtonGadget(#PB_Any,10,120,60,20,"Change")
Repeat
           
  Select WaitWindowEvent()
      
      Case #PB_Event_CloseWindow
            Quit = 1
     
      Case #PB_Event_Menu
          Select EventMenu() 
          EndSelect
      
      Case #PB_Event_Gadget
          Select EventGadget()
           Case change
              Readonly ! 1
              If Readonly = 1
                DisableGadget(Cont,1)
              Else
                DisableGadget(Cont,0)
              EndIf          
          EndSelect
             
  EndSelect 

Until Quit = 1
  

Re: Switch multiple StringGadgets from ReadOnly to editable

Posted: Tue Nov 24, 2015 7:21 pm
by infratec
My example with the container trick:

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, 130)
StringGadget(0, 10, 10, 100, 20, "")
StringGadget(1, 10, 40, 100, 20, "")
StringGadget(2, 10, 70, 100, 20, "")
StringGadget(3, 10, 100, 100, 20, "")
CloseGadgetList()

DisableGadget(9, #True)

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


Repeat
 
  Event = WaitWindowEvent()
 
  Select Event
    Case #PB_Event_Gadget
      If EventGadget() = 10
        If GetGadgetState(10)
          DisableGadget(9, #False)
        Else
          DisableGadget(9, #True)
        EndIf
      EndIf
     
    Case #PB_Event_CloseWindow
      Exit = #True
     
  EndSelect
 
Until Exit
Maybe it looks easier as RASHADS example with additional ScrollAreaGadget() :wink:

Bernd

Re: Switch multiple StringGadgets from ReadOnly to editable

Posted: Tue Nov 24, 2015 7:50 pm
by TI-994A
thinkitsimple wrote:...i now use 2 procedures to set DisableGadget to 0 or 1.
You'd need just one:

Code: Select all

#MainWindow = 0
#Timer = 0

Enumeration Gadgets
  #Calendar
  #ListView
  #Progress
  #Editor
  #String1
  #String2
  #Button
EndEnumeration

Procedure toggleStringGadgets()
  Static state
  state ! 1
  For i = #Calendar To #Button
    If GadgetType(i) = #PB_GadgetType_String
      DisableGadget(i, state)      
    EndIf
  Next i
EndProcedure

wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(#MainWindow, #PB_Any, #PB_Any, 430, 520, "Toggle StringGadgets", wFlags)
CalendarGadget(#Calendar, 10, 50, 250, 170, 0)
ListViewGadget(#ListView, 270, 50, 150, 380)
ProgressBarGadget(#Progress, 10, 230, 250, 30, 0, 100)
EditorGadget(#Editor, 10, 270, 250, 160)
SetGadgetText(#Editor, "Editor gdaget...")
StringGadget(#String1, 10, 440, 410, 30, "String gadget...")
StringGadget(#String2, 10, 480, 410, 30, "Another string gadget...")
ButtonGadget(#Button, 10, 10, 410, 30, "Toggle StringGadget() States")
AddWindowTimer(#MainWindow, #Timer, 100)

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      appQuit = 1
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #Button
          toggleStringGadgets()
      EndSelect
    Case #PB_Event_Timer
      Select EventTimer()
        Case #Timer
          progress + 1          
          SetGadgetState(#Progress, progress)
          AddGadgetItem(#ListView, -1, Str(progress))
          If progress > 100
            progress = 0
            ClearGadgetItems(#ListView)
          EndIf
      EndSelect
  EndSelect
Until appQuit = 1

Re: Switch multiple StringGadgets from ReadOnly to editable

Posted: Tue Nov 24, 2015 9:51 pm
by thinkitsimple
RASHAD wrote:Cross platform and very simple

Code: Select all


OpenWindow(0,0,0,340,150,"Test",#PB_Window_SystemMenu |#PB_Window_ScreenCentered)
CustomerDetails = ScrollAreaGadget(#PB_Any, 0, 0, 340, 100, 300, 500)
  Cont = ContainerGadget(#PB_Any,0,0,300,500)
    lblCustomerNumber = TextGadget(#PB_Any, 10, 10, 280, 20, LANG_CustomerNumber.s)
    txtCustomerNumber = StringGadget(#PB_Any, 10, 25, 280, 20, "")
    lblCompany = TextGadget(#PB_Any, 10, 50, 280, 20, LANG_Company.s)
    txtCompany = StringGadget(#PB_Any, 10, 65, 280, 20, "")
    lblTelephone = TextGadget(#PB_Any, 10, 90, 280, 20, LANG_Telephone.s)
    txtTelephone = StringGadget(#PB_Any, 10, 105, 280, 20, "")
    lblTelefax = TextGadget(#PB_Any, 10, 130, 280, 20, LANG_Telefax.s)
    txtTelefax = StringGadget(#PB_Any, 10, 145, 280, 20, "")
    lblEmail = TextGadget(#PB_Any, 10, 170, 280, 20, LANG_Email.s)
    txtEmail = StringGadget(#PB_Any, 10, 185, 280, 20, "")
    lblInternet = TextGadget(#PB_Any, 10, 210, 280, 20, LANG_Internet.s)
    txtInternet = StringGadget(#PB_Any, 10, 225, 280, 20, "")
    lblStreet = TextGadget(#PB_Any, 10, 250, 280, 20, LANG_Street.s)
    txtStreet = StringGadget(#PB_Any, 10, 265, 280, 20, "")
    lblStreetnumber = TextGadget(#PB_Any, 10, 290, 280, 20, LANG_StreetNumber.s)
    txtStreetNumber = StringGadget(#PB_Any, 10, 305, 280, 20, "")
    lblPostcode = TextGadget(#PB_Any, 10, 330, 280, 20, LANG_Postcode.s)
    txtPostcode = StringGadget(#PB_Any, 10, 345, 280, 20, "")
    lblCity = TextGadget(#PB_Any, 10, 370, 280, 20, LANG_City.s)
    txtCity = StringGadget(#PB_Any, 10, 385, 280, 20, "")
    lblCountry = TextGadget(#PB_Any, 10, 410, 280, 20, LANG_Country.s)
    txtCountry = StringGadget(#PB_Any, 10, 425, 280, 20, "")
    lblStatus = TextGadget(#PB_Any, 10, 450, 280, 20, LANG_Status.s)
    txtStatus = StringGadget(#PB_Any, 10, 465, 280, 20, "")
    CloseGadgetList()
  CloseGadgetList()  
  
  change = ButtonGadget(#PB_Any,10,120,60,20,"Change")
Repeat
           
  Select WaitWindowEvent()
      
      Case #PB_Event_CloseWindow
            Quit = 1
     
      Case #PB_Event_Menu
          Select EventMenu() 
          EndSelect
      
      Case #PB_Event_Gadget
          Select EventGadget()
           Case change
              Readonly ! 1
              If Readonly = 1
                DisableGadget(Cont,1)
              Else
                DisableGadget(Cont,0)
              EndIf          
          EndSelect
             
  EndSelect 

Until Quit = 1
  
But when i make some input in the StringGadgets and then click on change, i can continue to edit the specific StringGadget. Just the other StringGadgets where i made no input are readonly then.

Re: Switch multiple StringGadgets from ReadOnly to editable

Posted: Tue Nov 24, 2015 10:10 pm
by RASHAD
Hi thinkitsimple
I tested it with PB 5.4 x86,PB 5.31 x86 windows 10 x64 and it works perfectly
I presume you are using Linux
Post your configuration and maybe Berned(Infratec) can help

Sorry I am a windows user only :)

Re: Switch multiple StringGadgets from ReadOnly to editable

Posted: Tue Nov 24, 2015 10:13 pm
by thinkitsimple
As you can see in my signature, i use Mac OS X.

The only way i works correct, is to enable and disable each StringGadget. But then the StringGadget uses the default "greytext" for the disabled Gadgets which is not good to read.

Re: Switch multiple StringGadgets from ReadOnly to editable

Posted: Tue Nov 24, 2015 11:38 pm
by infratec
Hm...
maybe you can use SetActiveGadget() before you disable the container.
Use it to switch to a TextGadget for example.
Maybe this helps.

I'll test it tomorrow on a MacBook Pro.

Bernd

Re: Switch multiple StringGadgets from ReadOnly to editable

Posted: Wed Nov 25, 2015 2:33 am
by IdeasVacuum
A disabled gadget on Windows can have it's colour changed with SetGadgetColor() - it stays disabled but looks better.

Code: Select all

Enumeration
#Win
#StrGdt
EndEnumeration


Procedure Win()
;--------------

       If OpenWindow(#Win, 0, 0, 300, 100, "Win", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
          
             SetWindowColor(#Win, RGB(96,96,96))

               StringGadget(#StrGdt, 50, 50, 200, 22, "", #PB_String_ReadOnly)
             SetGadgetColor(#StrGdt, #PB_Gadget_BackColor, RGB(255,255,255))
       EndIf

       Repeat
       Until WaitWindowEvent(1) = #PB_Event_CloseWindow

EndProcedure


Win()

End
.... might work on OS X too

Re: Switch multiple StringGadgets from ReadOnly to editable

Posted: Wed Nov 25, 2015 9:17 am
by thinkitsimple
When i use #PB_String_ReadOnly on Mac, the StringGadget will be readonly and the text stays the same color (back). Thats what i want. Is there a way to switch only the flag #PB_String_ReadOnly of a StringGadget?

In other words: can i change a flag (#PB_String_ReadOnly) after the StringGadget is created?