Code

Node tool: fix handle retraction with non-cusp nodes
[inkscape.git] / src / ui / widget / page-sizer.h
1 /** \file
2  * \brief Widget for specifying page size; part of Document Preferences dialog.
3  *
4  * Author:
5  *   Ralf Stephan <ralf@ark.in-berlin.de>
6  *
7  * Copyright (C) 2005-2006 Authors
8  *
9  * Released under GNU GPL.  Read the file 'COPYING' for more information.
10  */
12 #ifndef INKSCAPE_UI_WIDGET_PAGE_SIZER__H
13 #define INKSCAPE_UI_WIDGET_PAGE_SIZER__H
15 #include <gtkmm.h>
16 #include <sigc++/sigc++.h>
18 #include "helper/units.h"
19 #include "ui/widget/registry.h"
20 #include "ui/widget/registered-widget.h"
21 #include "xml/node.h"
23 namespace Inkscape {    
24 namespace UI {
25 namespace Widget {
27 /**
28  * Data class used to store common paper dimensions.  Used to make
29  * PageSizer's _paperSizeTable. 
30  */ 
31 class PaperSize
32 {
33 public:
35     /**
36      * Default constructor
37      */
38     PaperSize()
39         { init(); }
41     /**
42      * Main constructor.  Use this one.
43      */
44     PaperSize(const Glib::ustring &nameArg,
45                   double smallerArg,
46                   double largerArg,
47                           SPUnitId unitArg)
48             {
49             name    = nameArg;
50             smaller = smallerArg;
51             larger  = largerArg;
52             unit    = unitArg;
53             }
55     /**
56      * Copy constructor
57      */
58     PaperSize(const PaperSize &other)
59         { assign(other); }
60         
61     /**
62      * Assignment operator
63      */      
64     PaperSize &operator=(const PaperSize &other)
65         { assign(other); return *this; }
67     /**
68      * Destructor
69      */      
70         virtual ~PaperSize()
71             {}
72             
73     /**
74      * Name of this paper specification
75      */      
76     Glib::ustring name;
77     
78     /**
79      * The lesser of the two dimensions
80      */      
81     double smaller;
82     
83     /**
84      * The greater of the two dimensions
85      */      
86     double larger;
87     
88     /**
89      * The units (px, pt, mm, etc) of this specification
90      */      
91     SPUnitId unit;
93 private:
95         void init()
96             {
97             name    = "";
98             smaller = 0.0;
99             larger  = 0.0;
100             unit    = SP_UNIT_PX;
101             }
103         void assign(const PaperSize &other)
104             {
105             name    = other.name;
106             smaller = other.smaller;
107             larger  = other.larger;
108             unit    = other.unit;
109         }
111 };
117 /**
118  * A compound widget that allows the user to select the desired
119  * page size.  This widget is used in DocumentPreferences 
120  */ 
121 class PageSizer : public Gtk::VBox
123 public:
125     /**
126      * Constructor
127      */
128     PageSizer(Registry & _wr);
130     /**
131      * Destructor
132      */
133     virtual ~PageSizer();
135     /**
136      * Set up or reset this widget
137      */      
138     void init ();
139     
140     /**
141      * Set the page size to the given dimensions.  If 'changeList' is
142      * true, then reset the paper size list to the closest match
143      */
144     void setDim (double w, double h, bool changeList=true);
145     
146     /**
147      * Updates the scalar widgets for the fit margins.  (Just changes the value
148      * of the ui widgets to match the xml).
149      */
150     void updateFitMarginsUI(Inkscape::XML::Node *nv_repr);
151  
152 protected:
154     /**
155      * Our handy table of all 'standard' paper sizes.
156      */      
157     std::map<Glib::ustring, PaperSize> _paperSizeTable;
159     /**
160      *  Find the closest standard paper size in the table, to the
161      */
162     Gtk::ListStore::iterator find_paper_size (double w, double h) const;
163  
164     void fire_fit_canvas_to_selection_or_drawing();
165     
166     Gtk::Tooltips _tips;
167     
168     //### The Paper Size selection list
169     Gtk::HBox _paperSizeListBox;
170     Gtk::Label _paperSizeListLabel;
171     class PaperSizeColumns : public Gtk::TreeModel::ColumnRecord
172         {
173         public:
174             PaperSizeColumns()
175                { add(nameColumn); add(descColumn);  }
176             Gtk::TreeModelColumn<Glib::ustring> nameColumn;
177             Gtk::TreeModelColumn<Glib::ustring> descColumn;
178         };
180     PaperSizeColumns _paperSizeListColumns;
181     Glib::RefPtr<Gtk::ListStore> _paperSizeListStore;
182     Gtk::TreeView _paperSizeList;
183     Glib::RefPtr<Gtk::TreeSelection> _paperSizeListSelection;
184     Gtk::ScrolledWindow  _paperSizeListScroller;
185     //callback
186     void on_paper_size_list_changed();
187     sigc::connection    _paper_size_list_connection;
188     
189     //### Portrait or landscape orientation
190     Gtk::HBox           _orientationBox;
191     Gtk::Label          _orientationLabel;
192     Gtk::RadioButton    _portraitButton;
193     Gtk::RadioButton    _landscapeButton;
194     //callbacks
195     void on_portrait();
196     void on_landscape();
197     sigc::connection    _portrait_connection;
198     sigc::connection    _landscape_connection;
200     //### Custom size frame
201     Gtk::Frame           _customFrame;
202     Gtk::Table           _customDimTable;
203     RegisteredUnitMenu   _dimensionUnits;
204     RegisteredScalarUnit _dimensionWidth;
205     RegisteredScalarUnit _dimensionHeight;
206     GList *              _dimTabOrderGList;
208     //### Fit Page options
209     Gtk::Expander        _fitPageMarginExpander;
210     Gtk::Table           _marginTable;
211     Gtk::Alignment       _marginTopAlign;
212     Gtk::Alignment       _marginLeftAlign;
213     Gtk::Alignment       _marginRightAlign;
214     Gtk::Alignment       _marginBottomAlign;
215     RegisteredScalar     _marginTop;
216     RegisteredScalar     _marginLeft;
217     RegisteredScalar     _marginRight;
218     RegisteredScalar     _marginBottom;
219     Gtk::Alignment       _fitPageButtonAlign;
220     Gtk::Button          _fitPageButton;
222     //callback
223     void on_value_changed();
224     sigc::connection    _changedw_connection;
225     sigc::connection    _changedh_connection;
227     Registry            *_widgetRegistry;
229     //### state - whether we are currently landscape or portrait
230     bool                 _landscape;
232 };
234 } // namespace Widget
235 } // namespace UI
236 } // namespace Inkscape
239 #endif /* INKSCAPE_UI_WIDGET_PAGE_SIZER__H */
241 /*
242   Local Variables:
243   mode:c++
244   c-file-style:"stroustrup"
245   c-file-offsets:((innamespace . 0)(inline-open . 0))
246   indent-tabs-mode:nil
247   fill-column:99
248   End:
249 */
250 // vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :