canvas_print_layout.h 6.36 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/* Glom
 *
 * Copyright (C) 2007 Murray Cumming
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program 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
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
17 18
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301 USA.
19 20
 */

David King's avatar
David King committed
21 22
#ifndef GLOM_PRINT_LAYOUT_CANVAS_PRINT_LAYOUT_H
#define GLOM_PRINT_LAYOUT_CANVAS_PRINT_LAYOUT_H
23 24 25

#include <glom/base_db.h>
#include <glom/utility_widgets/canvas/canvas_editable.h>
26
#include <glom/print_layout/canvas_layout_item.h>
27
#include <libglom/data_structure/print_layout.h>
28
#include <libglom/data_structure/layout/layoutitem_line.h>
29
#include <giomm/simpleactiongroup.h>
30
#include <gtkmm/pagesetup.h>
31
#include <gtkmm/menu.h>
32
#include <glibmm/weakref.h>
33 34 35 36

namespace Glom
{

Murray Cumming's avatar
Murray Cumming committed
37
class Dialog_TextFormatting;
38
class LayoutItem_Portal;
Murray Cumming's avatar
Murray Cumming committed
39

40 41 42 43 44 45 46 47
/// A canvas that contains CanvasLayoutItem items.
class Canvas_PrintLayout
 : public CanvasEditable,
   public Base_DB
{
public:
  Canvas_PrintLayout();

48 49
  void set_print_layout(const Glib::ustring& table_name, const std::shared_ptr<PrintLayout>& print_layout);
  std::shared_ptr<PrintLayout> get_print_layout();
50 51 52

  void set_page_setup(const Glib::RefPtr<Gtk::PageSetup>& page_setup);
  Glib::RefPtr<Gtk::PageSetup> get_page_setup();
53
  Glib::RefPtr<const Gtk::PageSetup> get_page_setup() const;
Murray Cumming's avatar
Murray Cumming committed
54

55 56
  void set_page_count(guint count);
  guint get_page_count() const;
57 58

  void set_zoom_percent(guint percent);
Murray Cumming's avatar
Murray Cumming committed
59

60 61 62 63
  /** Hide the bounds rectangle and the margin lines:
   */
  void hide_page_bounds();

64
  void add_canvas_layout_item(const Glib::RefPtr<CanvasLayoutItem>& item);
65

66 67
  void remove_canvas_layout_item(const Glib::RefPtr<CanvasLayoutItem>& item);

68 69 70 71
  /** If the item is a field from the System Preferences table,
   * show the content instead of the field name,
   * because it will be the same for all records.
   */
72
  void fill_with_data_system_preferences(const Glib::RefPtr<CanvasLayoutItem>& canvas_item, const std::shared_ptr<Document>& document);
73

74
  void fill_with_data(const FoundSet& found_set, bool avoid_page_margins);
75

76
  void set_grid_gap(double gap = 20.0) override;
77

78 79
  void set_outlines_visibility(bool visible = true);

80 81
  /** Get any items that have get_selected()==true.
   */
82
  type_vec_items get_selected_items() override;
83

Murray Cumming's avatar
Murray Cumming committed
84
  /** Set all items as selected or unselected.
85 86 87
   * @param selected Use false to unselect all.
   */
  void select_all(bool selected = true);
Murray Cumming's avatar
Murray Cumming committed
88 89


90
  Goocanvas::Bounds get_page_bounds(guint page_num) const;
91 92 93

  /** Look for any items that overlap the @a canvas_item and move them down so that the no longer overlap.
   * @param y_start Ignore any items whose y position is less than this.
94 95
   * @param offset Move items down by this amount
   * @param result The highest item that should be moved down to the start of the next page, if any:
96
   */
97
  Glib::RefPtr<CanvasLayoutItem> move_items_down(double y_start, double offset);
Murray Cumming's avatar
Murray Cumming committed
98

99
private:
100

101
#ifndef GLOM_ENABLE_CLIENT_ONLY
102
  void setup_context_menu();
103 104
#endif

105 106 107
  void add_layout_group(const std::shared_ptr<LayoutGroup>& group, bool is_top_level = false);
  void add_layout_group_children(const std::shared_ptr<LayoutGroup>& group);
  void fill_layout_group(const std::shared_ptr<LayoutGroup>& group);
108

109
  //These are not static, because they need access to the document:
110
  void fill_with_data(const Glib::RefPtr<Goocanvas::Group>& canvas_group, const FoundSet& found_set, bool avoid_page_margins);
111
  void fill_with_data_portal(const Glib::RefPtr<CanvasLayoutItem>& canvas_item, const Gnome::Gda::Value& foreign_key_value);
112
  static void set_canvas_item_field_value(const Glib::RefPtr<Goocanvas::Item>& canvas_item, const std::shared_ptr<const LayoutItem_Field>& field, const Gnome::Gda::Value& value);
Murray Cumming's avatar
Murray Cumming committed
113

114
  type_vecConstLayoutFields get_portal_fields_to_show(const std::shared_ptr<const LayoutItem_Portal>& portal);
115

116
  void create_canvas_layout_item_and_add(const std::shared_ptr<LayoutItem>& layout_item);
117

118
#ifndef GLOM_ENABLE_CLIENT_ONLY
119 120
  std::shared_ptr<LayoutItem_Portal> offer_related_records(const std::shared_ptr<LayoutItem_Portal>& portal, Gtk::Window* parent);
  std::shared_ptr<LayoutItem_Line> offer_line(const std::shared_ptr<LayoutItem_Line>& portal, Gtk::Window* parent);
Murray Cumming's avatar
Murray Cumming committed
121

122
  //TODO: Make the signal send the item, so we can pass it by const reference:
123
  void on_item_show_context_menu(GdkEventButton* event, const Glib::WeakRef<CanvasLayoutItem>& item);
124 125 126
  void on_context_menu_edit();
  void on_context_menu_formatting();
  void on_context_menu_delete();
127
  bool on_background_button_press_event(const Glib::RefPtr<Goocanvas::Item>& target, GdkEventButton* button_event);
128

Murray Cumming's avatar
Murray Cumming committed
129
  void on_dialog_format_hide();
130
#endif
Murray Cumming's avatar
Murray Cumming committed
131

132
  void update_page_bounds();
Murray Cumming's avatar
Murray Cumming committed
133

134
  Glib::RefPtr<Goocanvas::Polyline> create_margin_line(double x1, double y1, double x2, double y2);
135

136 137 138
  double get_page_height() const;
  double get_page_height(double& margin_top, double& margin_bottom) const;

139
  Glib::ustring m_table_name;
140
  bool m_modified; //TODO: Actually check this?
141

142 143 144 145
  //A group containing the layout items, so we can remove them without removing anything else:
  Glib::RefPtr<Goocanvas::Group> m_items_group;

  //A rectangle to show the bounds:
146
  Glib::RefPtr<Goocanvas::Group> m_bounds_group; //the page and its margins.
147
  Glib::RefPtr<Goocanvas::Rect> m_bounds_rect;
148
  Glib::RefPtr<Goocanvas::Polyline> m_margin_left, m_margin_right;
Murray Cumming's avatar
Murray Cumming committed
149

150 151 152
  typedef std::vector< Glib::RefPtr<Goocanvas::Polyline> > type_vec_margins;
  type_vec_margins m_vec_margin_tops;
  type_vec_margins m_vec_margin_bottoms;
153

154
  //Context menu for existing items:
155
  std::unique_ptr<Gtk::Menu> m_context_menu;
156 157
  Glib::RefPtr<Gio::SimpleActionGroup> m_context_menu_action_group;
  Glib::RefPtr<Gio::SimpleAction> m_action_edit, m_action_formatting, m_action_delete;
158 159 160
  Glib::RefPtr<CanvasLayoutItem> m_context_item; //The selected item when showing the context menu.,

  Glib::RefPtr<Gtk::PageSetup> m_page_setup;
161

Murray Cumming's avatar
Murray Cumming committed
162
  Dialog_TextFormatting* m_dialog_format;
163 164

  bool m_outline_visibility;
165
  guint m_page_count;
166 167 168 169
};

} //namespace Glom

David King's avatar
David King committed
170
#endif // GLOM_PRINT_LAYOUT_CANVAS_PRINT_LAYOUT_H