It is currently Thu Jul 18, 2019 10:15 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Send EditorGadget() to bottom line?
PostPosted: Sun Jul 08, 2007 9:42 pm 
Offline
User
User
User avatar

Joined: Fri Jan 23, 2004 6:54 pm
Posts: 44
Hi all.

Just wondered if it was possible (natively or using GTK 2 API) to force the EditorGadget to jump straight down the bottom of it's contents?

I've found some info here...

http://developer.gnome.org/doc/API/2.0/ ... table.html

...but have no idea quite how to work with it. Any assistance would be much appreciated :)


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Jul 10, 2007 9:06 am 
Offline
User
User
User avatar

Joined: Fri Jan 23, 2004 6:54 pm
Posts: 44
Anyone? :/

Even just some tips on how to interact with GTK (API) would be helpful :)


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Jul 10, 2007 1:23 pm 
Offline
PureBasic Team
PureBasic Team
User avatar

Joined: Fri Apr 25, 2003 5:21 pm
Posts: 5777
Location: Germany
Sorry, i overlooked this one.

The EditorGadget (in gtk2) is a GtkTextView which is contained inside a
GtkScrolledWindow to handle the scrolling. So you have to get the parent
of the widget returned by GadgetID(), and then you can work with the
GtkScrolledWindow related functions (here i get the vertical adjustment and change it)

Code:
; Note: In the PB definitions, gdouble is defined as a structure of 2 longs,
;   due to the missing double support in pre-4.00 versions. We will have
;   to change this now that doubles are supported.
;
;   For now, just use this redefined structure instead:
;
Structure _GtkAdjustment
  parent_instance.GtkObject
  lower.d
  upper.d
  value.d
  step_increment.d
  page_increment.d
  page_size.d
EndStructure


#Button = 0
#Editor = 1

If OpenWindow(0, 0, 0, 400, 200, "editor scroll", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  CreateGadgetList(WindowID(0))
 
  ButtonGadget(#Button, 10, 10, 150, 30, "add line")
  EditorGadget(#Editor, 10, 50, 380, 140)
 
  Repeat
    Event = WaitWindowEvent()
   
    If Event = #PB_Event_Gadget And EventGadget() = #Button
      AddGadgetItem(#Editor, -1, "New line: " + Str(LineCount))
      LineCount + 1
     
      ; get the vertical adjustment of the scrolled window     
      *Adjustment._GtkAdjustment = gtk_scrolled_window_get_vadjustment_(gtk_widget_get_parent_(GadgetID(#Editor)))
     
      ; change the value to the max
      *Adjustment\value = *Adjustment\upper
     
      ; notify the scrolled window of the change
      gtk_adjustment_value_changed_(*Adjustment)     
    EndIf
   
  Until Event = #PB_Event_CloseWindow 
EndIf

End


I think i will add native scrolling functions to the EditorGadget so there is a crossplatform way for it.

_________________
quidquid Latine dictum sit altum videtur


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Jul 10, 2007 1:36 pm 
Offline
User
User
User avatar

Joined: Fri Jan 23, 2004 6:54 pm
Posts: 44
Ah! Now I realise how the gadget is created it makes much more sense now. Thanks for the info :) I've just learned so much from your one post :)


Top
 Profile  
Reply with quote  
 Post subject: Re: Send EditorGadget() to bottom line?
PostPosted: Tue Jun 11, 2019 9:35 pm 
Offline
User
User

Joined: Thu May 02, 2019 3:57 am
Posts: 26
Location: USA
When I try the code that Freak posted, I get an error: Structure not found: GtkObject.
Need help.
Thanks,
Robert


Top
 Profile  
Reply with quote  
 Post subject: Re: Send EditorGadget() to bottom line?
PostPosted: Fri Jun 14, 2019 11:21 am 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 1628
Location: Germany
In order to use freak's code you have to activate subsystem GTK2 (Menu > Compiler > Compiler Options... > Library Subsystem: gtk2). In PureBasic's default subsystem GTK3 the structure GtkAdjustment has been changed to be private, so in GTK3 it isn't possible anymore to access the structure members.

You may therefore try the following alternative example which works with both GTK2 and GTK3 (tested successfully with Xubuntu 18.04 x86 and PB 5.46 x86 in ASCII and Unicode mode):
Code:
EnableExplicit

Define i.I
Define Iter.GtkTextIter
Define *TextBuffer.GtkTextBuffer

OpenWindow(0, 100, 100, 180, 120, "EditorGadget", #PB_Window_SystemMenu)
EditorGadget(0, 5, 5, WindowWidth(0) - 10, WindowHeight(0) - 45)
ButtonGadget(1, WindowWidth(0) / 2 - 60, WindowHeight(0) - 33, 120, 25, "Scroll to last line")

For i = 1 To 20
  AddGadgetItem(0, - 1, "Line number " + Trim(Str(i)))
Next

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Gadget
      If EventGadget() = 1 And EventType() = #PB_EventType_LeftClick
        *TextBuffer = gtk_text_view_get_buffer_(GadgetID(0))
        gtk_text_buffer_get_iter_at_line_(*TextBuffer, @Iter, CountGadgetItems(0) - 1)
        gtk_text_view_scroll_to_iter_(GadgetID(0), Iter, 0.0, #False, 0.0, 0.0)
      EndIf
  EndSelect
ForEver


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye