Code : Tout sélectionner
Enumeration
#Editor_0
EndEnumeration
Structure myPARAFORMAT2
cbSize.l
dwMask.l
wNumbering.w
wEffects.w
dxStartIndent.l
dxRightIndent.l
dxOffset.l
wAlignment.w
cTabCount.w
rgxTabs.l[#MAX_TAB_STOPS]
dySpaceBefore.l
dySpaceAfter.l
dyLineSpacing.l
sStyle.w
bLineSpacingRule.b
bOutlineLevel.b
wShadingWeight.w
wShadingStyle.w
wNumberingStart.w
wNumberingStyle.w
wNumberingTab.w
wBorderSpace.w
wBorderWidth.w
wBorders.w
EndStructure
egPara.myPARAFORMAT2
egPara\cbSize = SizeOf(myPARAFORMAT2)
egPara\dwMask = #PFM_NUMBERING | #PFM_NUMBERINGSTART | #PFM_NUMBERINGSTYLE | #PFM_NUMBERINGTAB
egPara\wNumbering = 2 ; 2 = 1..2..3 ; 3 = a..b..c ; 4 = A..B..C ; 5 = i...ii...iii ; 6 = I...II...III
egPara\wNumberingStart = 1 ; premier nombre à utiliser
egPara\wNumberingStyle = $300 ; 0 = NUM) ; $100 = (NUM) ; $300 = NUM
egPara\wNumberingTab = 700 ; esapce
Global egPara
Procedure LineNumber(hWnd, msg, wParam, lParam)
result = #PB_ProcessPureBasicEvents
Shared previousLineCount
Select msg
Case #WM_COMMAND
Select wParam>>16 &$FFFF
Case #EN_CHANGE
currentLineCount = SendMessage_(lParam, #EM_GETLINECOUNT , 0, 0)
If currentLineCount <> previousLineCount
currentLine = SendMessage_(lParam, #EM_LINEFROMCHAR, -1, 0)
currentPos = SendMessage_(lParam, #EM_GETSEL, @startPos, @endPos)
;--> Get current scroll postion so we can come back here after re-writing itmes
SendMessage_(lParam, #EM_GETSCROLLPOS, 0, @scrollP.POINT)
egPara\wNumberingStart = currentLine+1
;--> Turn redraw off For EditorGadget To prevent scrolling when re-writing items
SendMessage_(lParam, #WM_SETREDRAW, 0, 0)
For a = currentLine-1 To currentLineCount -1
egPara\wNumberingStart = a + 1
t$ = GetGadgetItemText(#Editor_0, a, 0)
;--> Line numbering only continues with valid item text
;--> so we'll add a temporary space character
If t$ = ""
t$ = " "
EndIf
SetGadgetItemText(#Editor_0, a, t$, 0)
SendMessage_(lParam, #EM_SETPARAFORMAT, 0, egPara)
;--> We can now remove the temporay space character
If t$ = " "
t$ = ""
SetGadgetItemText(#Editor_0, a, t$, 0)
EndIf
Next a
; --> Put caret back To correct position
SendMessage_(lParam, #EM_SETSCROLLPOS, 0, scrollP.POINT)
SendMessage_(lParam, #EM_SETSEL, startPos, startPos)
; --> Turn redraw back on For EditorGadget
SendMessage_(lParam, #WM_SETREDRAW, 1, 0)
; --> Redraw EditorGadget To show new line numbers
InvalidateRect_(lParam, 0, 1)
EndIf
previousLineCount = SendMessage_(lParam, #EM_GETLINECOUNT , 0, 0)
EndSelect
EndSelect
ProcedureReturn result
EndProcedure
If OpenWindow(0, 0, 0, 600, 450, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "EditorGadget with Line Numbers") And CreateGadgetList(WindowID(0))
EditorGadget (#Editor_0, 0, 0, 600, 450)
SendMessage_(GadgetID(#Editor_0), #EM_SETCHARFORMAT, #SCF_ALL, @egFormat)
SendMessage_(GadgetID(#Editor_0), #EM_SETEVENTMASK, 0, #ENM_CHANGE)
For l = 1 To 300
AddGadgetItem(#Editor_0, l, "Line " + Str(l))
SendMessage_(GadgetID(#Editor_0), #EM_SETPARAFORMAT, 0, egPara)
egPara\wNumberingStart +1
Next
Test(#Editor_0)
SetWindowCallback(@LineNumber())
Repeat
event = WaitWindowEvent()
Until event = #PB_Event_CloseWindow
EndIf
End