[lazarus] How to scroll TMemo control in code

hernan.et at pg.com hernan.et at pg.com
Thu Mar 27 20:17:48 EST 2003


Looking at how the TMemo is created in gtkobject.inc,

      P := gtk_scrolled_window_new(nil, nil);
      TempWidget := gtk_text_new(nil, nil);
      gtk_container_add(p, TempWidget);

      GTK_WIDGET_UNSET_FLAGS(PGtkScrolledWindow(p)^.hscrollbar, GTK_CAN_FOCUS);
      GTK_WIDGET_UNSET_FLAGS(PGtkScrolledWindow(p)^.vscrollbar, GTK_CAN_FOCUS);
      gtk_scrolled_window_set_policy(PGtkScrolledWindow(p),
                                     GTK_POLICY_AUTOMATIC,
                                     GTK_POLICY_AUTOMATIC);
      gtk_text_set_adjustments(PGtkText(TempWidget),
        gtk_scrolled_window_get_hadjustment(PGtkScrolledWindow(p)),
        gtk_scrolled_window_get_vadjustment(PGtkScrolledWindow(p)));

      SetMainWidget(p, TempWidget);
      GetWidgetInfo(p, True)^.ImplementationWidget := TempWidget;

It looks to me that you can manipulate the scrollbar by getting the handle of of the GtkWidget gtk_adjustment and setting the value

i.e
gtk_adjustment_set_value("Gtk adjustment handle here", "then the new value here") although this will not be widgetset independent.

I am not really sure, I am just thinking how to manipulate the scrollbars.

Note that according to Gtk documentation, gtktext is a descendant of gtkeditable. And in gtkEditable there is a signal called "move-to-row"
but I don't know how to fire this signal so that the scrollbar will move accordingly.

Also note that I am just learing how gtk works as well as how Lazarus handles messages, sometimes I am totally confused as how things happen.

And I am so glad that I can talk to really great delphi/lazarus coder around the globe.

Regards,

Yoyong




                                                                
 Internet Mail Message                                          
 Received from host:                                            
 svcr-216-37-230-2.dsl.svcr.epix.net                            
 [216.37.230.2]                                                 
                                                                


From: Marc Weustink <marc at dommelstein.net> on 03/28/2003 12:03 AM GMT
                                                                             
          Marc Weustink           To:   lazarus at miraclec.com,                
 <marc at dommelstein.net>        lazarus at miraclec.com                          
                                  Cc:    (bcc: Yoyong Hernan-ET/PGI)         
                          Subject:      Re: [lazarus] How to scroll TMemo    
    03/28/2003 08:03 AM        control in code                               
      Please respond to                                                      
   lazarus at miraclec.com                                                      
                                                                             





At 00:47 28-3-2003 +0100, Mattias Gaertner wrote:
>On Fri, 28 Mar 2003 00:32:12 +0100
>Marc Weustink <marc at dommelstein.net> wrote:
>
> > At 07:02 28-3-2003 +0800, you wrote:
> > >Can anybody try help me figure out how to scroll the TMemo
> > >programatically?
> > >
> > >I have seen this code in Delphi, though I am not sure if it works (in
> > >Delphi)
> > >
> > >procedure MemoScrollDown(Memo: TMemo);
> > >var
> > >  ScrollMessage:TWMVScroll; (I replace this one with TLMVScroll)
> > >  i:integer;
> > >begin
> > >  ScrollMessage.Msg:=WM_VScroll; (this one with LM_VScroll)
> > >  for i := 0 to Memo.Lines.Count do
> > >  begin
> > >      ScrollMessage.ScrollCode:=sb_LineDown;
> > >      ScrollMessage.Pos:=0;
> > >   Memo.Dispatch(ScrollMessage);
> > >  end;
> > >end;
> > >
> > >
> > >If I try the above code, it does not do anything.
> >
> > :-)
> >
> > It might work in Delphi, but it doesn't in the LCL (and never will)
> >
> > Some background info:
> >
> > The widgetset of you choice (GTK, win32, QT, GNOME) may be message based
> > or event based or whatever to signal when the user does something. The
> > interface object of the LCL translates this to LCL-Messages (and object
> > calls) to be a bit Delphi compatible so that Delphi code based on messages
> >
> > would work (code for WM_LBUTTONDOWN etc). This is thus from userinterface
> > to code.
> > However the otherway around, the LCL doesn't translate messages from code
> > to the user interface.
>
>Right.
>I think, we should add some properties to TCustomMemo to control the
>scrollbars.
>Other components need them too, so we should do that in an independent way.
>Ideas?

First idea:

Add H and V scrollbars like TScrollingWinControl, however created according
to TScrollStyle and with limited properties (Not nesecary derived from
TScrollbar).

Marc

_________________________________________________________________
     To unsubscribe: mail lazarus-request at miraclec.com with
                "unsubscribe" as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives







More information about the Lazarus mailing list