summaryrefslogtreecommitdiff
path: root/libs/gtkmm2/gtk/src/menu.ccg
blob: c52a9d43ad66ab4dab885d79f3d188c5b2c837c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// -*- c++ -*-
/* $Id: menu.ccg,v 1.7 2006/05/11 11:40:24 murrayc Exp $ */

/* Copyright 1998-2002 The gtkmm Development Team
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <gtk/gtkdnd.h>
#include <gtk/gtkmenu.h>
#include <gtkmm/accelgroup.h>


static void SignalProxy_PopupPosition_gtk_callback(GtkMenu*, int* x, int* y, gboolean* push_in, void* data)
{
  Gtk::Menu::SlotPositionCalc* the_slot = static_cast<Gtk::Menu::SlotPositionCalc*>(data);

  int  temp_x = (x) ? *x : 0;
  int  temp_y = (y) ? *y : 0;
  bool temp_push_in = (push_in) ? bool(*push_in) : false;

  #ifdef GLIBMM_EXCEPTIONS_ENABLED
  try
  {
  #endif //GLIBMM_EXCEPTIONS_ENABLED
    (*the_slot)(temp_x, temp_y, temp_push_in);
  #ifdef GLIBMM_EXCEPTIONS_ENABLED
  }
  catch(...)
  {
    Glib::exception_handlers_invoke();
  }
  #endif //GLIBMM_EXCEPTIONS_ENABLED

  if(x) *x = temp_x;
  if(y) *y = temp_y;
  if(push_in) *push_in = temp_push_in;
}



namespace Gtk
{

void Menu::popup(const SlotPositionCalc& position_calc_slot, guint button, guint32 activate_time)
{
  // Tell GTK+ to call the static function with the slot's address as the extra
  // data, so that the static function can then call the sigc::slot:
  gtk_menu_popup(gobj(), 0, 0, &SignalProxy_PopupPosition_gtk_callback, const_cast<SlotPositionCalc*>(&position_calc_slot), button, activate_time);
}

void Menu::popup(MenuShell& parent_menu_shell, MenuItem& parent_menu_item, const SlotPositionCalc& position_calc_slot, guint button, guint32 activate_time)
{
  // Tell GTK+ to call the static function with the slot's address as the extra
  // data, so that the static function can then call the sigc::slot:
  gtk_menu_popup(gobj(), parent_menu_shell.Gtk::Widget::gobj(), parent_menu_item.Gtk::Widget::gobj(), &SignalProxy_PopupPosition_gtk_callback, const_cast<SlotPositionCalc*>(&position_calc_slot), button, activate_time);
}

void Menu::popup(guint button, guint32 activate_time)
{
  gtk_menu_popup(gobj(), 0, 0, 0, 0, button, activate_time);
}

void Menu::reorder_child(const MenuItem& child, int position)
{
  gtk_menu_reorder_child(
      gobj(),
      const_cast<GtkWidget*>(child.Gtk::Widget::gobj()),
      position);
}

void Menu::unset_accel_group()
{
  gtk_menu_set_accel_group(gobj(), 0);
}

void Menu::unset_title()
{
  gtk_menu_set_title(gobj(), 0);
}

void Menu::attach_to_widget(Widget& attach_widget)
{
  gtk_menu_attach_to_widget(gobj(), (attach_widget).gobj(), 0 /* allowed by the C docs. */);
}


} // namespace Gtk