[glom] Print Layout: Deselect all items when clicking on the background.



commit 07025fe558293ae8da380adab7cd6c9870f8461a
Author: Murray Cumming <murrayc murrayc com>
Date:   Mon Aug 8 22:01:55 2011 +0200

    Print Layout: Deselect all items when clicking on the background.
    
    * glom/print_layout/canvas_print_layout.[h|cc]:
    set_page_setup(): Handle button-press-event signals on the background,
    deselecting any selected items.
    create_margin_line(): Do the same if the user manages to click on a
    line instead.

 ChangeLog                                     |   10 ++++++++++
 glom/print_layout/canvas_print_layout.cc      |   21 ++++++++++++++-------
 glom/print_layout/canvas_print_layout.h       |    1 +
 glom/utility_widgets/canvas/canvas_editable.h |    7 +++++++
 4 files changed, 32 insertions(+), 7 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 03eb9be..52e5097 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2011-08-08  Murray Cumming  <murrayc murrayc com>
 
+	Print Layout: Deselect all items when clicking on the background.
+
+	* glom/print_layout/canvas_print_layout.[h|cc]: 
+	set_page_setup(): Handle button-press-event signals on the background,
+	deselecting any selected items.
+	create_margin_line(): Do the same if the user manages to click on a 
+	line instead.
+
+2011-08-08  Murray Cumming  <murrayc murrayc com>
+
 	Relationships Overview: Correct the packing in the dialog.
 
 	* ui/developer/dialog_relationships_overview.glade:
diff --git a/glom/print_layout/canvas_print_layout.cc b/glom/print_layout/canvas_print_layout.cc
index f702f2e..12564c8 100644
--- a/glom/print_layout/canvas_print_layout.cc
+++ b/glom/print_layout/canvas_print_layout.cc
@@ -38,13 +38,6 @@
 namespace Glom
 {
 
-/*
-static bool on_group_button_press_event(const Glib::RefPtr<Goocanvas::Item>& target, GdkEventButton* event)
-{
-  return true; // Let the child items get the event.
-}
-*/
-
 Canvas_PrintLayout::Canvas_PrintLayout()
 : m_modified(false),
   m_dialog_format(0),
@@ -295,6 +288,13 @@ void Canvas_PrintLayout::on_item_show_context_menu(guint button, guint32 activat
   m_context_menu->popup(button, activate_time);
 }
 
+bool Canvas_PrintLayout::on_background_button_press_event(const Glib::RefPtr<Goocanvas::Item>& /* target */, GdkEventButton* /* event */)
+{
+  //A click on empty space should deselect any selected items:
+  select_all(false);
+  return false;
+}
+
 sharedptr<LayoutItem_Portal> Canvas_PrintLayout::offer_related_records(const sharedptr<LayoutItem_Portal>& portal, Gtk::Window* parent)
 {
   sharedptr<LayoutItem_Portal> result = portal;
@@ -449,6 +449,11 @@ Glib::RefPtr<Goocanvas::Polyline> Canvas_PrintLayout::create_margin_line(double
   line->property_line_width() = 0.5;
   line->property_stroke_color() = "light gray";
 
+  //Interpret a click on the line like a click on the background behind it:
+  //TODO: Do this for grid lines and rules too:
+  line->signal_button_press_event().connect(
+    sigc::mem_fun(*this, &Canvas_PrintLayout::on_background_button_press_event));
+
   m_bounds_group->add_child(line);
   return line;
 }
@@ -500,6 +505,8 @@ void Canvas_PrintLayout::set_page_setup(const Glib::RefPtr<Gtk::PageSetup>& page
   m_bounds_rect = Goocanvas::Rect::create(bounds.get_x1(), bounds.get_y1(), bounds.get_x2(), bounds.get_y2());
   m_bounds_rect->property_fill_color() = "white";
   m_bounds_rect->property_line_width() = 0;
+  m_bounds_rect->signal_button_press_event().connect(
+    sigc::mem_fun(*this, &Canvas_PrintLayout::on_background_button_press_event));
   m_bounds_group->add_child(m_bounds_rect);
 
   //Make sure that the bounds rect is at the bottom,
diff --git a/glom/print_layout/canvas_print_layout.h b/glom/print_layout/canvas_print_layout.h
index 3a86790..cc0879c 100644
--- a/glom/print_layout/canvas_print_layout.h
+++ b/glom/print_layout/canvas_print_layout.h
@@ -102,6 +102,7 @@ private:
   void on_context_menu_edit();
   void on_context_menu_formatting();
   void on_context_menu_delete();
+  bool on_background_button_press_event(const Glib::RefPtr<Goocanvas::Item>& target, GdkEventButton* event);
 
   void on_dialog_format_hide();
 #endif
diff --git a/glom/utility_widgets/canvas/canvas_editable.h b/glom/utility_widgets/canvas/canvas_editable.h
index 03a7582..3925343 100644
--- a/glom/utility_widgets/canvas/canvas_editable.h
+++ b/glom/utility_widgets/canvas/canvas_editable.h
@@ -65,6 +65,13 @@ public:
    */
   virtual type_vec_items get_selected_items();
 
+  /** Set all items as selected or unselected. 
+   * @param selected Use false to unselect all.
+   *
+   * Derived classes may override this to only examine items that they consider interesting.
+   */
+  virtual void select_all(bool selected = true);
+
 
   //TODO: Actually emit this, so we actually show the context menu when clicking on blank space:
   /** void on_show_context(guint button, guint32 activate_time);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]