Just a simple cross-platform function I wrote for a project I am working on, but it comes in handy:
Code: Select all
Procedure EditorGadgetDisplayOnly(pEditorGadget,pDisplayOnly)
; Parameters:
; pEditorGadget : the editor gadget to affect
;
; pDisplayOnly :
; 1 = Make the EditorGadget displayonly
; 0 = Make the EditorGadget editable
;
; Returns:
; 1 if successful
; -1 if OS is incorrect
;
lRetVal = 1
If (pDisplayOnly)
; set to display only/non-editable...
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
gtk_text_set_editable_(GadgetID(pEditorGadget),0)
CompilerCase #PB_OS_Windows
SendMessage_(GadgetID(pEditorGadget),#EM_SETREADONLY,#True,0)
CompilerDefault
lRetVal = -1
CompilerEndSelect
Else
; set to editable...
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
gtk_text_set_editable_(GadgetID(pEditorGadget),1)
CompilerCase #PB_OS_Windows
SendMessage_(GadgetID(pEditorGadget),#EM_SETREADONLY,#False,0)
CompilerDefault
lRetVal = -1
CompilerEndSelect
EndIf
ProcedureReturn lRetVal
EndProcedure
Code: Select all
;- Window Constants
Enumeration
#Window_0
EndEnumeration
;- Gadget Constants
Enumeration
#Editor_0
#CheckBox_0
EndEnumeration
;- The EditorGadgetDisplayOnly function
Procedure EditorGadgetDisplayOnly(pEditorGadget,pDisplayOnly)
lRetVal = 1
If (pDisplayOnly)
; set to display only/non-editable...
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
gtk_text_set_editable_(GadgetID(pEditorGadget),0)
CompilerCase #PB_OS_Windows
SendMessage_(GadgetID(pEditorGadget),#EM_SETREADONLY,#True,0)
CompilerDefault
lRetVal = -1
CompilerEndSelect
Else
; set to editable...
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
gtk_text_set_editable_(GadgetID(pEditorGadget),1)
CompilerCase #PB_OS_Windows
SendMessage_(GadgetID(pEditorGadget),#EM_SETREADONLY,#False,0)
CompilerDefault
lRetVal = -1
CompilerEndSelect
EndIf
ProcedureReturn lRetVal
EndProcedure
If OpenWindow(#Window_0, 244, 124, 600, 300, "EditorGadget - Display Only Example", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered)
EditorGadget(#Editor_0, 10, 10, 580, 256)
SetGadgetText(#Editor_0, "Edit this text")
CheckBoxGadget(#CheckBox_0, 10, 270, 185, 20, "Display Only")
EndIf
Repeat
Event = WaitWindowEvent()
WindowID = EventWindow()
GadgetID = EventGadget()
EventType = EventType()
If Event = #PB_Event_Gadget
If GadgetID = #Editor_0
ElseIf GadgetID = #CheckBox_0
EditorGadgetDisplayOnly(#Editor_0,GetGadgetState(#CheckBox_0))
EndIf
EndIf
Until Event = #PB_Event_CloseWindow
End