Editorgadget line numbers possible??

Just starting out? Need help? Post your questions and find answers here.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

***Edited to try a new fix one more time***

I changed line 64 from

Code: Select all

hdc = GetDC_(id)
to this

Code: Select all

hdc = GetDCEx_(id, 0, #DCX_CACHE)
and it seems to work ok now.

Code: Select all

Enumeration 
  #WIN: #EDIT: #EDIT_PASTE 
endEnumeration 

declare openMainWindow() 
declare drawLinenumbers() 
declare editCallback(hWnd, uMsg,  wParam, lParam) 

global editProc, leftM = 64 

openMainWindow() 

repeat 
  select waitWindowEvent() 
    case #PB_EVENT_MENU 
      select eventMenu() 
        case #EDIT_PASTE 
          sendMessage_(gadgetId(#EDIT), #EM_PASTESPECIAL, #CF_TEXT, 0) 
      endSelect 
    case #PB_EVENT_SIZEWINDOW 
      winW = windowWidth(#WIN) 
      winH = windowHeight(#WIN) 
      resizeGadget(#EDIT, 0, 25, winW, winH - 50) 
    case #PB_EVENT_CLOSEWINDOW 
      end 
  endSelect 
forever 

procedure openMainWindow() 
  if openWindow(#WIN, 0, 0, 800, 600, "Linenumbers", $CF0001) 
    if createGadgetList(windowID(#WIN)) 
      editorGadget(#EDIT, 0, 25, 800, 600 - 50) 
      ;font 
      hFont = loadFont(0, "calibri", 14) 
      setGadgetFont(#EDIT, hFont) 
      addKeyboardShortcut(#WIN, #PB_SHORTCUT_CONTROL | #PB_SHORTCUT_V, #EDIT_PASTE) 
      ;margins 
      getClientRect_(gadgetId(#EDIT), rc.RECT) 
      rc\left = leftM 
      sendMessage_(gadgetId(#EDIT), #EM_SETRECT, 0, rc) 
      ;remove the editorgadget border 
      style = getWindowLong_(gadgetId(#EDIT), #GWL_EXSTYLE) 
      newstyle = style & (~#WS_EX_CLIENTEDGE) 
      setWindowLong_(gadgetId(#EDIT), #GWL_EXSTYLE, newstyle) 
      setWindowPos_(gadgetId(#EDIT), 0, 0, 0, 0, 0, #SWP_SHOWWINDOW | #SWP_NOSIZE | #SWP_NOMOVE | #SWP_FRAMECHANGED) 
      ;subclass the editorgadget 
      editProc = setWindowLong_(gadgetID(#EDIT), #GWL_WNDPROC, @editCallback()) 
    endIf 
  endIf 
endProcedure 

procedure editCallback(hWnd, uMsg, wParam, lParam) 
  select uMsg 
    case #WM_PAINT 
      callWindowProc_(editProc, hWnd, uMsg, wParam, lParam) 
      drawLineNumbers() 
      procedurereturn 0 
  endSelect 
  procedureReturn callWindowProc_(editProc, hWnd, uMsg, wParam, lParam) 
endProcedure 

procedure drawLinenumbers() 
  id = gadgetId(#EDIT) 
  hdc = GetDCEx_(id, 0, #DCX_CACHE)
  
  hFont = fontId(getGadgetFont(#EDIT)) 
  prevObj = selectObject_(hDC, hFont) 
  
  getTextMetrics_(hDC, @tm.TEXTMETRIC) 
  fontH = tm\tmHeight 
  
  getClientRect_(id, rc.RECT) 
  rc\right = leftM - 8 
  fillRect_(hDC, rc, getStockObject_(#WHITE_BRUSH)) 
  setBkMode_(hdc, #TRANSPARENT) 
  setTextColor_(hdc, $C0C0C0) 
  
  ;get the first line 
  first = SendMessage_(id, #EM_GETFIRSTVISIBLELINE, 0, 0) 
  
  ;get the last character/line  
  pt.POINT\x = rc\left 
  pt\y = rc\bottom 
  lastChar = SendMessage_(id, #EM_CHARFROMPOS, 0, pt) 
  last = SendMessage_(id, #EM_LINEFROMCHAR, lastChar, 0) 
  ; get the first character 
  pt\y = rc\top 
  firstChar = SendMessage_(id, #EM_CHARFROMPOS, 0, pt) 
  
  ;get the client coordinates fo the first character 
  SendMessage_(id, #EM_POSFROMCHAR, @tChar.POINT, firstChar) 
  ;adjust linenumber RECT 
  rc\top = tChar\y  
  
  For line = first To last 
    ;if rc\top >= -fontH / 4 
    drawText_(hdc, Str(line + 1), -1, rc, #DT_RIGHT) 
    ;endIf 
    rc\top + fontH 
  Next 
  
  SelectObject_(hdc, prevObj) 
  ReleaseDC_(id, hdc) 
EndProcedure 
Last edited by Sparkie on Wed Oct 31, 2007 12:27 am, edited 1 time in total.
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
utopiomania
Addict
Addict
Posts: 1655
Joined: Tue May 10, 2005 10:00 pm
Location: Norway

Post by utopiomania »

Sparkie, your hack brings back the linenumber sync problem obviously! but your previous code works very well with a small change, so many
thanks for your help! :)
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Damn :x ....

Ok, I tried more more time if you'd like to back ^ up there ^ to the last code snippet and see what happens now.
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
utopiomania
Addict
Addict
Posts: 1655
Joined: Tue May 10, 2005 10:00 pm
Location: Norway

Post by utopiomania »

Thanks for trying one more time.. :) It works perfect now.
Post Reply