Basic Univers
; Line-Numbering by LP0304
; Bon, je pense à un autre code pour la numérotation des lignes qui me permet de faire des trucs plus sympas !

Declare MAKELONG(low, high)
Declare ReleaseOutput()
Declare WindowIDOutput(hWnd) ; returns the outputID for the declared window handle
Declare _iEditor_CallBack(hwnd, msg, wParam, lParam)

Procedure MAKELONG(low, high)
  ProcedureReturn low |(high<<16)
EndProcedure

Structure DrawingInfoStruct
  Type.l
  Window.l
  DC.l
  ReleaseProcedure.l
  PixelBuffer.l
  Pitch.l
  Width.l
  Height.l
  Depth.l
EndStructure
Global DS.DrawingInfoStruct
Procedure ReleaseOutput()
  ReleaseDC_(DSWindow, DSDC)
EndProcedure

Procedure WindowIDOutput(hWnd) ; returns the outputID for the declared window handle
  DS\Type = 1
  DS\Window = hWnd
  DS\DC = GetDC_(hWnd) ; GetWindowDC_(hWnd)
  DS\ReleaseProcedure =@ReleaseOutput()
  ProcedureReturn DS
EndProcedure

Procedure _iEditor_CallBack(hwnd, msg, wParam, lParam)
  Protected rc.rect
  Protected fontsizecy
  Shared OLDP
  Shared *font.long
  Protected point.point
  res = CallWindowProc_(OLDP, hwnd, msg, wParam, lParam)
  If msg = #WM_PAINT
    HideCaret_(hwnd)
    GetClientRect_(hwnd, rc)
    startindex = SendMessage_(hwnd, #EM_CHARFROMPOS, 0, @point)
    startline = SendMessage_(hwnd, #EM_LINEFROMCHAR, startindex, 0)
    point\x = rc\right
    point\y = rc\bottom
    endindex = SendMessage_(hwnd, #EM_CHARFROMPOS, 0, @point)
    endline = SendMessage_(hwnd, #EM_LINEFROMCHAR, endindex, 0)
    StartDrawing(WindowIDOutput(hwnd))
      Box(0, 0, 48, rc\bottom, $C0C0C0)
      DrawingFont(*font\l)
      fontsizecy = TextHeight("M")
      lastLine = rc\bottom / fontsizecy + startline - 1
      x = 43
      x2 = x
      While(startline <= lastLine) And(startline <= endline)
        DrawText(x - TextWidth(Str(startline + 1)), y, Str(startline + 1), $000000, $C0C0C0)
        y + fontsizecy
        startline + 1
      Wend
    StopDrawing()
     
    ShowCaret_(hwnd)
    ProcedureReturn 0
  EndIf
  ProcedureReturn res
EndProcedure
;##################################################### ;# ;#####################################################

Define.long *font
Define.long *editor
Define.long *window
Define.l Event



*window = OpenWindow(#PB_Any, 0, 0, 400, 400, "", 1|#WS_SYSMENU)
If *window
  CreateGadgetList(*window\l)
  *editor = EditorGadget(#PB_Any, 0, 0, 395, 375)
  *font = LoadFont(#PB_Any, "Courier New", 10)
  SetGadgetFont(*editor, *font\l)
  OLDP = SetWindowLong_(*editor\l, #GWL_WNDPROC, @_iEditor_CallBack())
  SendMessage_(*editor\l, #EM_SETMARGINS, #EC_LEFTMARGIN, MAKELONG(50, 0))
  ;-
  For i = 0 To 30
    AddGadgetItem(*editor, i, "line" + Str(i))
  Next
  Repeat
    Event = WaitWindowEvent()
  Until Event = #WM_CLOSE ;-
EndIf
End