Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Set scrollbar position in QM_DlgInfo-control
#1
1. Is it possible to save and restore a scroll position in a 'QM_DlgInfo' control?
2. And is it possible to set the scroll position based on the caret position from the current QM item in QM.
   (for example, user working in "Macro 1" and caret is at line 20, then when the below dialog becomes active it will set the scrollbar
    position to line 20)

If '2' is not possible, is '1' then at least possible?
Below I attempted to save (which seems to work) and then restore with a +10 offset (which doesn't work)
 
Function test_scroll_qmdi
Code:
Copy      Help
str dd=
;BEGIN DIALOG
;0 "" 0x90CC0AC8 0x0 0 0 223 171 "Dialog"
;3 QM_DlgInfo 0x54330005 0x200 1 6 216 159 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2040601 "*" "" "" ""

if(!ShowDialog(dd &sub.DlgProc 0)) ret


#sub DlgProc
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,,;; Put current item from QM in the 'QM_DlgInfo' control
,,QMITEM q
,,int i
,,i=qmitem("" 0 &q 1|8)
,,q.text.from("<><code>" q.text "</code>")
,,q.text.setwintext(id(3 hDlg))
,case WM_ACTIVATE
,,int- pos
,,if(wParam>0) ;; on activate, set scrollbarpos
,,,SendDlgItemMessage hDlg 3 WM_VSCROLL MakeInt(SB_THUMBPOSITION pos+10) 1
,,if(wParam=0) ;; on deactivate, save scrollbar pos
,,,pos=GetScrollPos(id(3 hDlg) SB_VERT)
,,,outt F"position saved: {pos}"
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1


To get line number from caret I use (don't know if this is best method, probably better ways but this seems to work):

Function getline_from_caret
Code:
Copy      Help
function int'hDlg int'ctrl

int ctrl=(id(ctrl hDlg))

int cpos
SendMessage(ctrl, EM_GETSEL,&cpos,0)
SendMessage(ctrl, EM_POSFROMCHAR, cpos, 0)
cpos=cpos+1

str gettext.getwintext(id(ctrl hDlg))
str gettext_until_charpos.left(gettext cpos)
ret numlines(gettext_until_charpos)
#2
QM_DlgInfo control is Scintilla.
QM code editor control is Scintilla too.

https://www.scintilla.org/ScintillaDoc.h...cScrolling

Code:
Copy      Help
,,if(wParam>0) ;; on activate, set scrollbarpos
,,,SendDlgItemMessage(hDlg 3 SCI.SCI_SETFIRSTVISIBLELINE pos+10 0)
,,if(wParam=0) ;; on deactivate, save scrollbar pos
,,,pos=SendDlgItemMessage(hDlg 3 SCI.SCI_GETFIRSTVISIBLELINE 0 0)
,,,outt F"position saved: {pos}"
#3
Makes sense now!!!
Thank you!!!


Forum Jump:


Users browsing this thread: 1 Guest(s)