Announcement

Collapse
No announcement yet.

Edit Pane Synchronization

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Jules Marchildon
    replied
    Borje, when was the last time you had your IQ tested?
    I'd say it is very close to GENIUS level!!!

    Regards,
    Jules

    Leave a comment:


  • Keith Waters
    replied
    Borje

    I'm back at my home computer and I've just tried your method of
    intercepting %WM_CTLCOLOREDIT and %WM_CTLCOLORSTATIC in my
    application and it works just fine (no surprise). Not only does
    your solution cure a problem I had but it results in simpler
    code than I had originally.

    Again, many thanks.

    Keith



    ------------------

    Leave a comment:


  • Borje Hagsten
    replied
    just posted a couple of extended samples in sorce code. one for listbox at http://www.powerbasic.com/support/pb...ad.php?t=22998

    and for textbox: http://www.powerbasic.com/support/pb...ad.php?t=22999


    ------------------

    Leave a comment:


  • Keith Waters
    replied
    Semen

    Yes one of my panes is read only. The situation is basically this.

    My main application window has two multi-line edit controls side-by-side
    with a "splitter" bar between them for sizing. The left hand pane is
    read/write and holds a list of arithmetic expressions, one per line.
    The right hand pane is read only and holds the evaluated results of the
    expressions. I have to keep the two panes "synchronised" so that each
    result is directly opposite its corresponding expression.

    So (as Aldo remarks and Borje has already tested) I will be intercepting
    both %WM_CTLCOLOREDIT and %WM_CTLCOLORSTATIC.

    Borje

    I tried using ListBoxes when I first started the project but I could find no
    way of cancelling the "smooth" scroll action of the ListBoxes. This gave
    a most peculiar effect that if I scrolled one pane up and down at just the
    right frequency the other pane could be made "oscillate" in anti-phase.
    That's why I used Edit controls.

    Keith


    ------------------

    Leave a comment:


  • Borje Hagsten
    replied
    %ES_READONLY textbox triggers %WM_CTLCOLORSTATIC instead, for some
    odd MS reason. Just tried sample above - add %ES_READONLY style and
    change to "CASE %WM_CTLCOLOREDIT, %WM_CTLCOLORSTATIC" - works fine.

    Yes, also found this interesting. Can be used with listboxes too, via
    WM_CTLCOLORLISTBOX, and scrollbars via WM_CTLCOLORSCROLLBAR, and..


    ------------------

    Leave a comment:


  • Aldo Cavini
    replied
    Semen,

    may be I've not understood your question. What I know is READONLY edit controls send %WM_CTLCOLORSTATIC instead of %WM_CTLCOLOREDIT.

    ------------------

    Leave a comment:


  • Semen Matusovski
    replied
    Interesting, what means to "synchonize" not ES_READONLY ?


    ------------------
    E-MAIL: [email protected]

    Leave a comment:


  • Keith Waters
    replied
    Borje

    Another great idea. Thanks.

    I'm already synchronising scroll, caret position and selection so
    that part's sorted. Also, I'm already intercepting %WM_CTLCOLOREDIT
    (for colour control) but hadn't thought of calling the synchronisation
    code here. I will try it when I get back to my home machine.
    Many thanks.

    Keith



    ------------------

    Leave a comment:


  • Borje Hagsten
    replied
    Works fine in WM_CTLCOLOREDIT. No need to trap changes anywhere else.
    Small sample:
    Code:
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Example of synchronising textboxes via parent's WM_CTLCOLOREDIT
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    #COMPILE EXE
    #INCLUDE "WIN32API.INC"
    %ID_TEXT     = 21
    %ID_TEXT2    = 22
    DECLARE CALLBACK FUNCTION DlgProc() AS LONG
     
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Create dialog and controls, etc
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    FUNCTION PBMAIN () AS LONG
      LOCAL hDlg AS LONG, I AS LONG, txt AS STRING
     
      FOR I = 1 TO 50
         txt = txt & "Line" & STR$(I) & $CRLF
      NEXT
     
      DIALOG NEW 0, "Synchronized textbox scroll",,, 188, 155, %WS_CAPTION OR %WS_SYSMENU, 0 TO hDlg
     
      CONTROL ADD TEXTBOX, hDlg, %ID_TEXT, txt, 4, 4, 180, 60, _
                           %WS_CHILD OR %ES_MULTILINE OR %WS_VSCROLL, _
                           %WS_EX_CLIENTEDGE CALL DlgProc
     
      CONTROL ADD TEXTBOX, hDlg, %ID_TEXT2, txt, 4, 74, 180, 60, _
                           %WS_CHILD OR %ES_MULTILINE OR %WS_VSCROLL, _
                           %WS_EX_CLIENTEDGE CALL DlgProc
     
      CONTROL ADD BUTTON, hDlg, %IDOK, "E&xit", 135, 138, 50, 14
      CONTROL SET FOCUS hDlg, %ID_TEXT
     
      DIALOG SHOW MODAL hDlg CALL DlgProc
    END FUNCTION
     
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Main callback
    ' NOTE, this sample only synchronizes scroll. Easy to add code to synchronize
    ' text contents, plus caret pos or selection via EM_GETSEL/EM_SETSEL, etc.
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    CALLBACK FUNCTION DlgProc() AS LONG
      STATIC NoUpdate AS LONG 'to avoid un-neccessay updating
     
      SELECT CASE CBMSG
         CASE %WM_CTLCOLOREDIT
            'note: returning brush or setting textcolor, etc. must be done here, before NoUpdate flag
     
            IF NoUpdate THEN EXIT FUNCTION
            NoUpdate = %TRUE
     
            LOCAL hEdit AS LONG, hEdit2 AS LONG, fLine AS LONG, fLine2 AS LONG
     
            hEdit = GetDlgItem(CBHNDL, %ID_TEXT)
            hEdit2 = GetDlgItem(CBHNDL, %ID_TEXT2)
     
            IF CBLPARAM = hEdit THEN  'trap visual changes in first textbox
               fLine  = SendMessage(hEdit, %EM_GETFIRSTVISIBLELINE, 0, 0)   '<- get first visible line in 1
               fLine2 = SendMessage(hEdit2, %EM_GETFIRSTVISIBLELINE, 0, 0)  '<- get first visible line in 2
               IF fLine <> fLine2 THEN
                  SendMessage hEdit2, %EM_LINESCROLL, 0, fLine - fLine2     '<- amount to scroll textbox 2
               END IF
     
            ELSEIF CBLPARAM = hEdit2 THEN  'trap visual changes in second textbox
               fLine  = SendMessage(hEdit, %EM_GETFIRSTVISIBLELINE, 0, 0)   '<- get first visible line in 1
               fLine2 = SendMessage(hEdit2, %EM_GETFIRSTVISIBLELINE, 0, 0)  '<- get first visible line in 2
               IF fLine <> fLine2 THEN
                  SendMessage hEdit, %EM_LINESCROLL, 0, fLine2 - fLine      '<- amount to scroll textbox 1
               END IF
            END IF
            NoUpdate = %FALSE
     
         CASE %WM_COMMAND
            IF CBCTL = %IDOK THEN DIALOG END CBHNDL
     
      END SELECT
     
    END FUNCTION
    ------------------
    Added static NoUpdate, to avoid recursive behaviour when second
    textbox is updated..



    [This message has been edited by Borje Hagsten (edited April 24, 2001).]

    Leave a comment:


  • Borje Hagsten
    replied
    Haven't tried this myself, but what about trapping visual changes in
    any of the textboxes in parent dialog's WM_CTLCOLOREDIT? That one is
    always triggered when a child textbox needs to be redrawn, so it
    should be possible to synchronize them there, I think..


    ------------------

    Leave a comment:


  • Keith Waters
    replied
    Aldo

    I'm doing %EM_GETFIRSTVISIBLELINE at the moment but I hadn't
    thought of doing it inside a timer. Many thanks for that idea.

    Keith

    ------------------


    [This message has been edited by Keith Waters (edited April 24, 2001).]

    Leave a comment:


  • Aldo Cavini
    replied
    Keith,

    May be the simplest way to do this is to check the top visible line via the %EM_GETFIRSTVISIBLELINE message inside a timer. This way you'll have all the possible scroll situations checked the same way.

    ------------------

    Leave a comment:


  • Keith Waters
    started a topic Edit Pane Synchronization

    Edit Pane Synchronization

    Has anyone experience of synchronizing multi-line edit controls?

    My application has two multi-line edit controls side-by-side. The controls
    are subclassed and syncronised so that any scroll action in one is mirrored
    in the other. I syncronize the panes in response to %WM_MOUSEWHEEL,
    %WM_LBUTTONDOWN, %WM_KEYDOWN, %WM_CHAR and %WM_VSCROLL. All works very
    well except for the case when one pane auto-scrolls to bring the caret
    into view. This can happen when I resize the application (from maximised
    to restored). It can also happen when I "Undo" so that text below the
    current caret position is restored.

    Does this "auto-scroll" action generate any window message I can intercept?

    Keith

    ------------------
Working...
X