FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Calling default implementation of on_button_press_event

 
Post new topic   Reply to topic     Forum Index -> gtkD
View previous topic :: View next topic  
Author Message
eldar



Joined: 14 Jun 2008
Posts: 101
Location: Ufa, Russia

PostPosted: Sat Sep 13, 2008 1:38 pm    Post subject: Calling default implementation of on_button_press_event Reply with quote

I am trying to implement Popup menu functionality for a TreeView widget. I use addOnButtonPress() to add an event handler for an mouse button press. But this overrides the default implementation of mouse press event of the TreeView widget. This default implementation handles rows selection. In gtkmm tutorial for a TreeView there is an example for popup menus:http://www.gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/sec-treeview-examples.html . In on_button_press_event of their custom TreeView they call TreeView::on_button_press_event(event);

Code:

bool TreeView_WithPopup::on_button_press_event(GdkEventButton* event)
{
  //Call base class, to allow normal handling,
  //such as allowing the row to be selected by the right-click:
  bool return_value = TreeView::on_button_press_event(event);

  //Then do our custom stuff:
  if( (event->type == GDK_BUTTON_PRESS) && (event->button == 3) )
  {
    m_Menu_Popup.popup(event->button, event->time);
  }

  return return_value;
}

I need something like this in gtkD - is it possible? I don't want to handcode rows-selection behaviour because it is already done in gtk itself.
Back to top
View user's profile Send private message
eldar



Joined: 14 Jun 2008
Posts: 101
Location: Ufa, Russia

PostPosted: Sun Sep 14, 2008 12:48 am    Post subject: Reply with quote

I understood, that if I return false in event handler - the default handler will be called, but this is not suitable for me, because I need the default implementation of on_button_press to be called before my implementation - because it should select necessary Tree nodes, and only after that I will do something with this selection.
Back to top
View user's profile Send private message
eldar



Joined: 14 Jun 2008
Posts: 101
Location: Ufa, Russia

PostPosted: Sun Sep 14, 2008 8:55 am    Post subject: Reply with quote

So I did what I wanted to do in C:
Code:

typedef gboolean (*button_press) (GtkWidget   *widget, GdkEventButton      *event);

button_press tree_view_button_press = NULL;

gboolean view_onButtonPressed (GtkWidget *treeview, GdkEventButton *event, gpointer userdata)
{
  g_print ("Single click on the tree view.\n");
  gboolean result = tree_view_button_press(treeview, event);
   
  view_popup_menu(treeview, event, userdata);

  return result; /* we handled this */
}

create_view_and_model (void)
{
  GtkWidget           *view;
 
  view = gtk_tree_view_new ();

...
  tree_view_button_press = ((struct _GtkWidgetClass*)(G_OBJECT_GET_CLASS(view)))->button_press_event;

  g_signal_connect(view, "button-press-event", (GCallback) view_onButtonPressed, NULL);
}

So what we need is access gtkWidgetClass structure fo a widget. Or it would be even better if it will be done like in gtkmm:
http://www.everfall.com/paste/id.php?8ei9j9w3bdex
It is a header for GtkWidget - necessary methods start from 350 line - the default event handlers. http://www.gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/sec-overriding-default-signal-handlers.html - here is the tutorial that explains it. Having in gtkD something like this will be nice.
Back to top
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Sun Sep 14, 2008 9:15 am    Post subject: Reply with quote

currently no, I'll try to get something working tonight.
Back to top
View user's profile Send private message
Dubhead



Joined: 08 Sep 2008
Posts: 4
Location: Tokyo, Japan

PostPosted: Sun Sep 14, 2008 10:04 am    Post subject: Reply with quote

eldar wrote:
I understood, that if I return false in event handler - the default handler will be called, but this is not suitable for me, because I need the default implementation of on_button_press to be called before my implementation - because it should select necessary Tree nodes, and only after that I will do something with this selection.


Have you tried passing an optional parameter connectFlags=ConnectFlags.AFTER to addOnButtonPress() ?
Back to top
View user's profile Send private message
eldar



Joined: 14 Jun 2008
Posts: 101
Location: Ufa, Russia

PostPosted: Sun Sep 14, 2008 1:06 pm    Post subject: Reply with quote

Dubhead, yes I tried. As I tried it in plain C gtk+: g_signal_connect_after(). Because the default implementation of an event handler returns true - my handler is not executed. So there is an only option to call the default handler explicitly and gtk+ API gives that possibility.
Back to top
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Sun Sep 14, 2008 1:19 pm    Post subject: Reply with quote

Added Widget.onButtonPressEvent(GdkEventButton* event) in svn r610, i'll add the others next.
Back to top
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Mon Sep 15, 2008 3:28 am    Post subject: Reply with quote

svn r612 adds the other Widget.on*Event functions.
Back to top
View user's profile Send private message
eldar



Joined: 14 Jun 2008
Posts: 101
Location: Ufa, Russia

PostPosted: Mon Sep 15, 2008 3:46 am    Post subject: Reply with quote

Thank you!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> gtkD All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group