Page 1 of 1

Forcing 'Overwrite' in editor gadget

Posted: Mon Aug 30, 2010 7:09 pm
by johnfinch
I've searched for a way to set 'overwrite' in the editor gadget but to no avail. It works when I toggle it manually so I figured there should be a way to set the key on and force this 'overwrite' behaviour.

Having Purebasic switching the keyboard keys (in XP) is way above my knowledge right now :(
Any snippets or help much appreciated.

Re: Forcing 'Overwrite' in editor gadget

Posted: Mon Aug 30, 2010 7:13 pm
by Trond

Code: Select all

#W = 512
#H = 384

OpenWindow(0, 0, 0, #W, #H, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
EditorGadget(0, 10, 10, #W-20, #H-20)
SetGadgetText(0, "Overwritable editor gadget")
LoadFont(0, "Lucida Console", 10)
SetGadgetFont(0, FontID(0))
SendMessage_(GadgetID(0), #WM_KEYDOWN, #VK_INSERT, 0)
SendMessage_(GadgetID(0), #WM_KEYUP, #VK_INSERT, 0)

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
  EndSelect
ForEver
But users can still turn if on and off with the insert key.

Re: Forcing 'Overwrite' in editor gadget

Posted: Tue Aug 31, 2010 12:14 am
by johnfinch
Thank you Trond!

Re: Forcing 'Overwrite' in editor gadget

Posted: Tue Aug 31, 2010 12:08 pm
by Michael Vogel
Impressive trick, didn't know, that the insert/overwrite flag is set for each gadget...

Code: Select all

#W = 400
#H = 280
#NextGadget=666

OpenWindow(0, 0, 0, #W, #H, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
EditorGadget(1, 10, 10, #W-20, 80)
EditorGadget(2, 10, 100, #W-20, 80)
EditorGadget(3, 10, 190, #W-20, 80)
SetGadgetText(1, "Insert editor gadget")
SetGadgetText(2, "Overwritable editor gadget")
SetGadgetText(3, "Insert editor gadget")
SendMessage_(GadgetID(2), #WM_KEYDOWN, #VK_INSERT, 0)
SendMessage_(GadgetID(2), #WM_KEYUP, #VK_INSERT, 0)
SetActiveGadget(1)
AddKeyboardShortcut(0,#PB_Shortcut_Tab|#PB_Shortcut_Control,#NextGadget)

Repeat
    Select WaitWindowEvent()
    Case #PB_Event_Menu
        If EventMenu()=#NextGadget
            SetActiveGadget(GetActiveGadget()%3+1)
        EndIf

    Case #PB_Event_CloseWindow
        Break
    EndSelect
ForEver

Re: Forcing 'Overwrite' in editor gadget

Posted: Tue Aug 31, 2010 4:00 pm
by RASHAD
With some more tips

Code: Select all


Global hook

Procedure EG_Column(Gadget)
  SendMessage_(GadgetID(gadget),#EM_EXGETSEL,0,Pos.CHARRANGE) 
  ProcedureReturn (Pos\cpMax-(SendMessage_(GadgetID(gadget),#EM_LINEINDEX,SendMessage_(GadgetID(gadget), #EM_EXLINEFROMCHAR,0,Pos\cpMin),0))+1) 
EndProcedure 

Procedure EG_Row(Gadget)
  SendMessage_(GadgetID(gadget),#EM_EXGETSEL,0,Pos.CHARRANGE) 
  ProcedureReturn SendMessage_(GadgetID(gadget),#EM_EXLINEFROMCHAR,0,Pos\cpMin)+1 
EndProcedure

Procedure.l KeyboardHook(nCode.i, wParam.i, lParam.i) 
  If nCode < 0 
    ProcedureReturn CallNextHookEx_(hook, nCode, wParam, lParam) 
  EndIf
    If wParam = #VK_INSERT Or wParam = #VK_NUMPAD0 
    ProcedureReturn 1
  EndIf 
ProcedureReturn CallNextHookEx_(hook, nCode, wParam, lParam) 
EndProcedure 

OpenWindow(0, 200, 200, 400, 240,"Editor Test", #PB_Window_SystemMenu| #PB_Window_MinimizeGadget| #PB_Window_MaximizeGadget| #PB_Window_ScreenCentered)

CreateStatusBar(0, WindowID(0))
      AddStatusBarField(60)
      AddStatusBarField(40)
      AddStatusBarField(60)
      AddStatusBarField(40)
      AddStatusBarField(50)
      AddStatusBarField(60)
      
      StatusBarText(0, 0, "Line : ")
      StatusBarText(0, 2, "Column: ")
      StatusBarText(0, 4, "Mode :")
      StatusBarText(0, 5, "Insert")

EditorGadget(1,0,0, 400, 180)
SendMessage_(GadgetID(1), #EM_SETTARGETDEVICE, 0, 0)

Text$="{\rtf1\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\fswiss\fcharset0 Arial;}}{\colortbl ;\red255\green0\blue0;\red0\green0\blue0;}"
Text$ = Text$ + "{\*\generator Msftedit 5.41.15.1503;}\viewkind4\uc1\pard\f0\fs20 Hello, this is \cf1\b\fs32 RTF\cf2\b0\fs20 direct!\cf0\par}"

SetGadgetText(1, Text$)
ButtonGadget(2,5,185,80,24,"Toggle",#PB_Button_Toggle)

Repeat
    StatusBarText(0, 1,Str(EG_Row(1)))
    StatusBarText(0, 3,Str(EG_Column(1)))
  
  Select WaitWindowEvent()
       
      Case #PB_Event_CloseWindow
          Q =1 
      
      Case #PB_Event_Gadget 
          Select EventGadget()
            Case 2
                If GetGadgetState(2) = 0
                  StatusBarText(0, 5, "Insert")
                Else
                  StatusBarText(0, 5, "Overwrite")
                EndIf
                UnhookWindowsHookEx_(hook)
                SendMessage_(GadgetID(1), #WM_KEYDOWN, #VK_INSERT, 0)
                SendMessage_(GadgetID(1), #WM_KEYUP, #VK_INSERT, 0)
                SetActiveGadget(1)
                hook = SetWindowsHookEx_(#WH_KEYBOARD, @KeyboardHook(),GetModuleHandle_(0), GetWindowThreadProcessId_(WindowID(0), 0))

           
          EndSelect
  EndSelect
Until Q = 1
UnhookWindowsHookEx_(hook)