The CanvasGadget is based on an NSView. But NSViews don't offer the method
isEnabled to query the state of an NSView nor using
setEnabled to enable or disable a Gadget based on an NSView at all. Only Gadgets based on NSCells (or NSView based Gadgets having subviews based on NSCells) are being able to be enabled or disabled. So you have to roll up such a feature for the CanvasGadget by yourself. If you use a CanvasGagdet like an editor, you may try out my very simple example which allows you to disable and enable the CanvasGadget by redrawing the content and change the background and text color. You have to add code for backspacing and for linefeeds to be usefull but the example should just give you the idea. And the example will be even cross-platform if you take care of the different character width and height on the different operating systems.
Code: Select all
EnableExplicit
Procedure DrawCursorIntoCanvas(xPosition.I)
StartDrawing(CanvasOutput(0))
Box(xPosition, 22, 10, 2, 0)
StopDrawing()
EndProcedure
Procedure DrawCanvasText(xPosition.I, Text.S, TextColor.I, BackColor.I)
StartDrawing(CanvasOutput(0))
DrawingFont(FontID(0))
Box(0, 0, GadgetWidth(0), GadgetHeight(0), BackColor)
DrawText(xPosition, 5, Text, TextColor, BackColor)
StopDrawing()
EndProcedure
Define CanvasDisabled.I
Define CanvasText.S = "Test"
Define Character.S
Define xPosition.I
If LoadFont(0, "Monaco", 18)
OpenWindow(0, 270, 100, 180, 85, "CanvasGadget")
CanvasGadget(0, 10, 10, 160, 35,
#PB_Canvas_Border | #PB_Canvas_DrawFocus | #PB_Canvas_Keyboard)
ButtonGadget(1, 20, 55, 140, 25, "Disable Canvas")
DrawCanvasText(2, CanvasText, 0, $FFFFFF)
xPosition = 2 + Len(CanvasText) * 11
DrawCursorIntoCanvas(xPosition)
SetActiveGadget(0)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
Select EventGadget()
Case 0
If EventType() = #PB_EventType_Input And CanvasDisabled = #False
StartDrawing(CanvasOutput(0))
DrawingFont(FontID(0))
Character = Chr(GetGadgetAttribute(0, #PB_Canvas_Input))
CanvasText + Character
DrawText(xPosition, 5, Character, 0, $FFFFFF)
xPosition + 11
StopDrawing()
DrawCursorIntoCanvas(xPosition)
EndIf
Case 1
If GetGadgetText(1) = "Disable Canvas"
DrawCanvasText(2, CanvasText, $666666, $F2F2F2)
CanvasDisabled = #True
SetGadgetText(1, "Enable Canvas")
Else
SetActiveGadget(0)
DrawCanvasText(2, CanvasText, 0, $FFFFFF)
CanvasDisabled = #False
SetGadgetText(1, "Disable Canvas")
xPosition = 2 + Len(CanvasText) * 11
DrawCursorIntoCanvas(xPosition)
EndIf
EndSelect
EndSelect
ForEver
EndIf