[gtkmm-documentation] Update custom and treeview_popup examples
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtkmm-documentation] Update custom and treeview_popup examples
- Date: Tue, 20 Nov 2018 09:06:11 +0000 (UTC)
commit 92ef8a7aad2e5b3b29fd04717eab222408b33a07
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date: Tue Nov 20 10:03:36 2018 +0100
Update custom and treeview_popup examples
* examples/book/custom/custom_container/mycontainer.[cc|h]:
* examples/book/custom/custom_widget/mywidget.[cc|h]: on_size_allocate() now
takes two ints instead of one Gtk::Allocation.
* examples/book/treeview/popup/treeview_withpopup.[cc|h]: Replace on_event()
by a Gtk::GestureMultiPress instance.
examples/book/custom/custom_container/mycontainer.cc | 20 +++++++++-----------
examples/book/custom/custom_container/mycontainer.h | 2 +-
examples/book/custom/custom_widget/mywidget.cc | 5 ++---
examples/book/custom/custom_widget/mywidget.h | 2 +-
examples/book/treeview/popup/treeview_withpopup.cc | 20 +++++++++-----------
examples/book/treeview/popup/treeview_withpopup.h | 5 ++---
6 files changed, 24 insertions(+), 30 deletions(-)
---
diff --git a/examples/book/custom/custom_container/mycontainer.cc
b/examples/book/custom/custom_container/mycontainer.cc
index 06a8d53..18e8b9a 100644
--- a/examples/book/custom/custom_container/mycontainer.cc
+++ b/examples/book/custom/custom_container/mycontainer.cc
@@ -125,7 +125,7 @@ void MyContainer::measure_vfunc(Gtk::Orientation orientation, int for_size,
}
}
-void MyContainer::on_size_allocate(const Gtk::Allocation& allocation, int baseline)
+void MyContainer::on_size_allocate(int width, int height, int baseline)
{
//Do something with the space that we have actually been given:
//(We will not be given heights or widths less than we have requested, though
@@ -151,32 +151,30 @@ void MyContainer::on_size_allocate(const Gtk::Allocation& allocation, int basel
Gtk::Allocation child_allocation_two;
//Place the first child at the top-left:
- child_allocation_one.set_x( allocation.get_x() );
- child_allocation_one.set_y( allocation.get_y() );
+ child_allocation_one.set_x(0);
+ child_allocation_one.set_y(0);
//Make it take up the full width available:
- child_allocation_one.set_width( allocation.get_width() );
+ child_allocation_one.set_width(width);
if (visible_one)
{
//Divide the height equally among the visible children.
- child_allocation_one.set_height(allocation.get_height() / nvis_children);
+ child_allocation_one.set_height(height / nvis_children);
m_child_one->size_allocate(child_allocation_one, baseline);
}
else
child_allocation_one.set_height(0);
//Place the second child below the first child:
- child_allocation_two.set_x( allocation.get_x() );
- child_allocation_two.set_y( allocation.get_y() +
- child_allocation_one.get_height());
+ child_allocation_two.set_x(0);
+ child_allocation_two.set_y(child_allocation_one.get_height());
//Make it take up the full width available:
- child_allocation_two.set_width( allocation.get_width() );
+ child_allocation_two.set_width(width);
//Make it take up the remaining height:
- child_allocation_two.set_height( allocation.get_height() -
- child_allocation_one.get_height());
+ child_allocation_two.set_height(height - child_allocation_one.get_height());
if (visible_two)
{
diff --git a/examples/book/custom/custom_container/mycontainer.h
b/examples/book/custom/custom_container/mycontainer.h
index c21f336..20be76b 100644
--- a/examples/book/custom/custom_container/mycontainer.h
+++ b/examples/book/custom/custom_container/mycontainer.h
@@ -33,7 +33,7 @@ protected:
Gtk::SizeRequestMode get_request_mode_vfunc() const override;
void measure_vfunc(Gtk::Orientation orientation, int for_size, int& minimum, int& natural,
int& minimum_baseline, int& natural_baseline) const override;
- void on_size_allocate(const Gtk::Allocation& allocation, int baseline) override;
+ void on_size_allocate(int width, int height, int baseline) override;
void forall_vfunc(const ForeachSlot& slot) override;
diff --git a/examples/book/custom/custom_widget/mywidget.cc b/examples/book/custom/custom_widget/mywidget.cc
index 64f1582..4b0a5e6 100644
--- a/examples/book/custom/custom_widget/mywidget.cc
+++ b/examples/book/custom/custom_widget/mywidget.cc
@@ -108,7 +108,7 @@ void MyWidget::measure_vfunc(Gtk::Orientation orientation, int /* for_size */,
natural_baseline = -1;
}
-void MyWidget::on_size_allocate(const Gtk::Allocation& allocation, int /* baseline */)
+void MyWidget::on_size_allocate(int width, int height, int /* baseline */)
{
//Do something with the space that we have actually been given:
//(We will not be given heights or widths less than we have requested, though
@@ -116,8 +116,7 @@ void MyWidget::on_size_allocate(const Gtk::Allocation& allocation, int /* baseli
if(m_refGdkSurface)
{
- m_refGdkSurface->move_resize( allocation.get_x(), allocation.get_y(),
- allocation.get_width(), allocation.get_height() );
+ m_refGdkSurface->move_resize(0, 0, width, height);
}
}
diff --git a/examples/book/custom/custom_widget/mywidget.h b/examples/book/custom/custom_widget/mywidget.h
index 8601681..c3bb027 100644
--- a/examples/book/custom/custom_widget/mywidget.h
+++ b/examples/book/custom/custom_widget/mywidget.h
@@ -36,7 +36,7 @@ protected:
Gtk::SizeRequestMode get_request_mode_vfunc() const override;
void measure_vfunc(Gtk::Orientation orientation, int for_size, int& minimum, int& natural,
int& minimum_baseline, int& natural_baseline) const override;
- void on_size_allocate(const Gtk::Allocation& allocation, int baseline) override;
+ void on_size_allocate(int width, int height, int baseline) override;
void on_map() override;
void on_unmap() override;
void on_realize() override;
diff --git a/examples/book/treeview/popup/treeview_withpopup.cc
b/examples/book/treeview/popup/treeview_withpopup.cc
index fcfd9f7..57191f2 100644
--- a/examples/book/treeview/popup/treeview_withpopup.cc
+++ b/examples/book/treeview/popup/treeview_withpopup.cc
@@ -40,6 +40,13 @@ TreeView_WithPopup::TreeView_WithPopup()
append_column("ID", m_Columns.m_col_id);
append_column("Name", m_Columns.m_col_name);
+ // Catch button press events:
+ auto refGesture = Gtk::GestureMultiPress::create();
+ refGesture->set_button(GDK_BUTTON_SECONDARY);
+ refGesture->signal_pressed().connect(
+ sigc::mem_fun(*this, &TreeView_WithPopup::on_popup_button_pressed));
+ add_controller(refGesture);
+
//Fill popup menu:
auto item = Gtk::make_managed<Gtk::MenuItem>("_Edit", true);
item->signal_activate().connect(
@@ -63,18 +70,9 @@ TreeView_WithPopup::~TreeView_WithPopup()
{
}
-bool TreeView_WithPopup::on_event(const Glib::RefPtr<Gdk::Event>& event)
+void TreeView_WithPopup::on_popup_button_pressed(int /* n_press */, double /* x */, double /* y */)
{
- //Call base class, to allow normal handling,
- //such as allowing the row to be selected by the right-click:
- const bool return_value = TreeView::on_event(event);
-
- //Then do our custom stuff:
- if (event->get_event_type() == Gdk::Event::Type::BUTTON_PRESS &&
- std::static_pointer_cast<Gdk::EventButton>(event)->shall_trigger_context_menu())
- m_Menu_Popup.popup_at_pointer(event);
-
- return return_value;
+ m_Menu_Popup.popup_at_pointer();
}
void TreeView_WithPopup::on_menu_file_popup_generic()
diff --git a/examples/book/treeview/popup/treeview_withpopup.h
b/examples/book/treeview/popup/treeview_withpopup.h
index 3879098..5d5b057 100644
--- a/examples/book/treeview/popup/treeview_withpopup.h
+++ b/examples/book/treeview/popup/treeview_withpopup.h
@@ -26,9 +26,8 @@ public:
virtual ~TreeView_WithPopup();
protected:
- // Override Signal handler:
- // Alternatively, use signalevent().connect_notify()
- bool on_event(const Glib::RefPtr<Gdk::Event>& event) override;
+ // Signal handler for showing popup menu:
+ void on_popup_button_pressed(int n_press, double x, double y);
//Signal handler for popup menu items:
void on_menu_file_popup_generic();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]