PB (2003): http://www.purebasic.fr/english/viewtop ... 28&start=1
Arctic Fox (2009): http://www.purebasic.fr/english/viewtop ... 00&start=1
The following code example demonstrates how to toggle the read only state of a StringGadget cross-platform on Linux, MacOS and Windows without the need to delete and recreate the StringGadget. I have tested this code successfully on these operating systems:
- MacOS X 10.6.8 (Snow Leopard)
- Ubuntu 12.04 LTS x64 with KDE
- Windows 7 x64 SP1
Code: Select all
OpenWindow(0, 270, 100, 300, 90, "Toggle ReadOnly attribute")
StringGadget(0, 10, 15, 280, 25, "Status: Read and Write")
ButtonGadget(1, 70, 50, 150, 27, "Enable Read only")
ReadOnlyState = #False
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
If EventGadget() = 1
If EventType() = #PB_EventType_LeftClick
ReadOnlyState = ReadOnlyState ! 1
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
gtk_editable_set_editable_(GadgetID(0), ReadOnlyState ! 1)
CompilerCase #PB_OS_MacOS
CocoaMessage(0, GadgetID(0), "setSelectable:", ReadOnlyState)
CocoaMessage(0, GadgetID(0), "setEditable:", ReadOnlyState ! 1)
CompilerCase #PB_OS_Windows
SendMessage_(GadgetID(0), #EM_SETREADONLY, ReadOnlyState, 0)
CompilerEndSelect
If ReadOnlyState
SetGadgetText(0, "Status: Read only")
SetGadgetText(1, "Disable Read only")
Else
SetGadgetText(0, "Status: Read and Write")
SetGadgetText(1, "Enable Read only")
EndIf
EndIf
EndIf
EndSelect
ForEver