J'aimerait que dans un EditorGadget, TAB fasse un aliné au lieu de donner le focus a un autre element !
Comme dans PureBASIC par exemple, ou comme le NotePad...
Merci

Code : Tout sélectionner
Procedure EditorKeyHandler(VirtualKey)
Shared VK_ReturnState
If VirtualKey = #VK_RETURN And VK_ReturnState = 0
PreviousCursorX = CursorPositionX-1
SyntaxHighlighting()
*Line = AllocateMemory(#MEM_KEYHANDLER1, 2000, 0)
PokeW(*Line, 1000)
SendMessage_(*RichEditGadget, #EM_GETSEL , @StartPosition, 0)
StartPosition = SendMessage_(*RichEditGadget, #EM_EXLINEFROMCHAR, 0 , StartPosition)
SendMessage_(*RichEditGadget, #EM_GETLINE , StartPosition , *Line) ; Get the current line buffer..
VK_ReturnState = 1 ; Very tricky. This inform the WindowCallback to ignore the following #VK_RETURN return, else it's a dead loop
SendMessage_(*RichEditGadget, #WM_KEYDOWN, #VK_RETURN, 1)
ClearEffects() ; Reset all the font effects for the newline..
*Cursor.Byte = UseMemory(#MEM_KEYHANDLER1)
While *Cursor\b = ' ' And PreviousCursorX > 0 ; Insert space at the start of the newline (auto-indent)
SendMessage_(*RichEditGadget, #WM_CHAR, ' ', 1)
*Cursor+1
PreviousCursorX-1
Wend
FreeMemory(#MEM_KEYHANDLER1)
ElseIf VirtualKey = #VK_TAB
If GetKeyState_(#VK_SHIFT) < 0
ShiftMode = 1
Else
ShiftMode = 0
EndIf
SendMessage_(*RichEditGadget, #EM_GETSEL , @StartPosition, @EndPosition)
FirstLineIndex = SendMessage_(*RichEditGadget, #EM_EXLINEFROMCHAR, 0 , StartPosition)
LastLineIndex = SendMessage_(*RichEditGadget, #EM_EXLINEFROMCHAR, 0 , EndPosition)
LastLinePosition = SendMessage_(*RichEditGadget, #EM_LINEINDEX , LastLineIndex , 0)
*Buffer = AllocateMemory(#MEM_KEYHANDLER2, EndPosition-StartPosition, 0)
If LastLinePosition = EndPosition And LastLineIndex <> FirstLineIndex ; Needed to handle the case where the selection is at the very end of the
LastLineIndex-1 ; line and then the new line is take in count too.
EndIf
If FirstLineIndex <> LastLineIndex ; Block indent when pressing TAB
For k=FirstLineIndex To LastLineIndex
LineIndex = SendMessage_(*RichEditGadget, #EM_LINEINDEX , k , 0)
LineLength = SendMessage_(*RichEditGadget, #EM_LINELENGTH, LineIndex, 0)
If LineLength > 0 And OldLineIndex+LineLength+1 <> EndPosition
If ShiftMode
If TabLength > LineLength
RealTabLength = LineLength
Else
RealTabLength = TabLength
EndIf
SendMessage_(*RichEditGadget, #EM_SETSEL , LineIndex, LineIndex+RealTabLength)
SendMessage_(*RichEditGadget, #EM_GETSELTEXT, 0 , *Buffer)
Counter = RealTabLength
*Cursor = *Buffer
While (*Cursor\b = 9 Or *Cursor\b = ' ') And Counter
*Cursor+1
Counter-1
Wend
If Counter < RealTabLength
SendMessage_(*RichEditGadget, #EM_SETSEL, LineIndex, LineIndex+RealTabLength-Counter)
SendMessage_(*RichEditGadget, #EM_REPLACESEL, 1, "")
EndIf
Offset-(RealTabLength-Counter)
Else
SendMessage_(*RichEditGadget, #EM_SETSEL, LineIndex, LineIndex) ; Cursor to the beginning of the line
ClearEffects() ; Reset all the font effects for the newline..
SendMessage_(*RichEditGadget, #EM_REPLACESEL, 1, Space(TabLength))
Offset+TabLength
EndIf
EndIf
Next
SendMessage_(*RichEditGadget, #EM_SETSEL, StartPosition, EndPosition+Offset)
Else
ClearEffects() ; Reset all the font effects for start of the newline..
RealTabLength = TabLength-MOD(CursorPositionX-1, TabLength) ; Smart indent
SendMessage_(*RichEditGadget, #EM_REPLACESEL, 1, Space(RealTabLength))
EndIf
Else
VK_ReturnState = 0
EndIf
EndProcedure
Code : Tout sélectionner
SetWindowLong_(GadgetID(0),#gwl_style,GetWindowLong_(GadgetID(0),#gwl_style)-#ws_tabstop)
Code : Tout sélectionner
Case 256
If EventwParam()=9
For x=1 To 4
keybd_event_($20, 0, 0, 0)
keybd_event_($20, 0, #KEYEVENTF_KEYUP, 0)
Next c
EndIf
Code : Tout sélectionner
;nico
OpenWindow(1,200,200,400,400,#PB_Window_SystemMenu,"Fenêtre principale")
test=1
If CreateGadgetList(WindowID(1))
EditorGadget (1,10,40,380,300,#PB_Container_Raised)
EndIf
SetWindowLong_(GadgetID(1),#GWL_STYLE,GetWindowLong_(GadgetID(1),#GWL_STYLE)!#WS_TABSTOP)
Repeat
EventID.l=WaitWindowEvent()
Select EventID
Case #WM_KEYDOWN
If EventwParam()=9
If test=1
keybd_event_($11, 0, 0, 0)
keybd_event_($9, 0, #KEYEVENTF_KEYUP, 0)
keybd_event_($9, 0, 0, 0)
keybd_event_($11, 0, #KEYEVENTF_KEYUP, 0)
test=0
EndIf
EndIf
Case #WM_KEYUP
If EventwParam()=$11
test=1
EndIf
Case #PB_EventGadget
Select EventGadgetID()
EndSelect
Case #WM_CLOSE
Quit=1
EndSelect
Until Quit=1