
I am trying to complete a template program that consists of all the necessary elements to enhance the StringGadget with support for Insert/Overwrite toggling on more than one StringGadget.
I am still missing some elements...
1) How can I get the current position of the caret in the input field? This is necessary (a) to edit the line manually at the correct position and (2) to put the caret back at the same position after a character has been added or replaced (or deleted with Backspace).
2) After hitting the Ins-key several times, the blinking "image" of the underline caret does not blink, despite the API statement SetCaretBlinkTime_(200)... it blinks only again when a character is entered.
3) There is a line that reads Case _SGad(0),_SGad(1),_SGad(2)... As long there are few elements, no problems, but how can I simplify that line if there were 100 elements?
Thanks!
Code: Select all
Global _TGad
Global Dim _SGad(2)
Procedure.b zInsState()
InsState.b=GetKeyState_(#PB_Shortcut_Insert)
If InsState & 1
Mode.s="OVR ("+Str(InsState)+")"
Else
Mode.s="INS ("+Str(InsState)+")"
EndIf
SetGadgetText(_TGad,Mode)
ProcedureReturn InsState
EndProcedure
Font2=LoadFont(#PB_Any,"Courier",14)
CreateImage(0,18,20)
StartDrawing(ImageOutput(0))
Box(0,17,10,3,$FFFFFF)
StopDrawing()
OpenWindow(0,0,0,300,200,"Toggle Insert/Overwrite",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
AddKeyboardShortcut(0, #PB_Shortcut_Insert,1045)
_TGad=TextGadget(#PB_Any,200,150,100,20,"")
InsState.b=zInsState()
_SGad(0)=StringGadget(#PB_Any,10,10,280,26,"")
SetGadgetFont(_SGad(0),FontID(Font2))
_SGad(1)=StringGadget(#PB_Any,10,40,280,26,"")
SetGadgetFont(_SGad(1),FontID(Font2))
_SGad(2)=StringGadget(#PB_Any,10,70,280,26,"")
SetGadgetFont(_SGad(2),FontID(Font2))
SetActiveGadget(_SGad(0))
Repeat
Event=WaitWindowEvent()
CurrentGadget=GetActiveGadget()
If Event=#PB_Event_Gadget
Select EventGadget()
Case _SGad(0),_SGad(1),_SGad(2)
If EventType()=#PB_EventType_Change
;get caret position <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Select InsState
Case 0,-128
;insert chr
Case -127
;replace chr
EndSelect
EndIf
EndSelect
EndIf
If Event=#PB_Event_Menu
Select EventMenu()
Case 1045
If zInsState() & 1
;DestroyCaret_()
CreateCaret_(GadgetID(CurrentGadget),ImageID(0),0,0)
SetCaretBlinkTime_(200); immobile = -1, normal blinking = 500
ShowCaret_(GadgetID(CurrentGadget))
Else
;DestroyCaret_()
CreateCaret_(GadgetID(CurrentGadget),0,10,20); second parameter: 0=solid block, 1=dotted block
SetCaretBlinkTime_(-1); immobile = -1, normal blinking = 500
ShowCaret_(GadgetID(CurrentGadget))
EndIf
EndSelect
EndIf
Until event = #PB_Event_CloseWindow
CloseWindow(0)
