Code

7416e96cc753c6543f1342efa623f35c0a1b7c17
[inkscape.git] / src / ui / dialog / panel-dialog.h
1 /**
2  * \brief A panel holding dialog
3  *
4  * Authors:
5  *   Gustav Broberg <broberg@kth.se>
6  *
7  * Copyright (C) 2007 Authors
8  *
9  * Released under GNU GPL.  Read the file 'COPYING' for more information.
10  */
12 #ifndef INKSCAPE_PANEL_DIALOG_H
13 #define INKSCAPE_PANEL_DIALOG_H
15 #ifdef HAVE_CONFIG_H
16 # include <config.h>
17 #endif
19 #include "verbs.h"
21 #include "dialog.h"
22 #include "dialogs/swatches.h"
23 #include "ui/dialog/undo-history.h"
24 #include "prefs-utils.h"
26 namespace Inkscape {
27 namespace UI {
28 namespace Dialog {
30 struct PanelDialogBase {
31     virtual void present() =0;
32     virtual Panel &getPanel() =0;
33     virtual ~PanelDialogBase() {}
34 };
36 template <typename Behavior>
37 class PanelDialog : public PanelDialogBase, public Inkscape::UI::Dialog::Dialog {
39 public:
40     PanelDialog(Panel &contents, char const *prefs_path, int const verb_num, 
41                 Glib::ustring const &apply_label);
43     virtual ~PanelDialog() {}
45     template <typename T>
46     static PanelDialog<Behavior> *create();
48     virtual void present();
50     Panel &getPanel() { return _panel; }
52 private:
53     Panel &_panel;
55     PanelDialog();  // no constructor without params
56     PanelDialog(PanelDialog<Behavior> const &d);                      // no copy
57     PanelDialog<Behavior>& operator=(PanelDialog<Behavior> const &d); // no assign
58 };
62 template <typename B>
63 PanelDialog<B>::PanelDialog(Panel &panel, char const *prefs_path, int const verb_num, Glib::ustring const &apply_label) :
64     Dialog(&B::create, prefs_path, verb_num, apply_label),
65     _panel (panel)
66 {
67     Gtk::VBox *vbox = get_vbox();
68     _panel.signalResponse().connect(sigc::mem_fun(*this, &PanelDialog::_handleResponse));
69     _panel.signalPresent().connect(sigc::mem_fun(*this, &PanelDialog::present));
71     vbox->pack_start(_panel, true, true, 0);
73     if (prefs_get_int_attribute ("dialogs", "showclose", 0) || !apply_label.empty()) {
74         // TODO: make the order of buttons obey the global preference
75         if (!apply_label.empty()) {
76             panel.addResponseButton(apply_label, Gtk::RESPONSE_APPLY);
77             panel.setDefaultResponse(Gtk::RESPONSE_APPLY);
78         }
79         panel.addResponseButton(Gtk::Stock::CLOSE, Gtk::RESPONSE_CLOSE);
80     }
82     show_all_children();
83 }
85 template <typename B> template <typename P>
86 PanelDialog<B> *
87 PanelDialog<B>::create()
88 {
89     Panel &panel = P::getInstance();
90     return new PanelDialog<B>(panel, panel.getPrefsPath(), 
91                               panel.getVerb(), panel.getApplyLabel());
92 }
94 template <typename B>
95 void
96 PanelDialog<B>::present()
97 {
98     Dialog::present();
99 }
101 } // namespace Dialog
102 } // namespace UI
103 } // namespace Inkscape
105 #endif //INKSCAPE_PANEL_DIALOG_H
107 /*
108   Local Variables:
109   mode:c++
110   c-file-style:"stroustrup"
111   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
112   indent-tabs-mode:nil
113   fill-column:99
114   End:
115 */
116 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :