Code

added fix from Dale Harvey to expand incomplete JIDs specified in user
[inkscape.git] / src / ui / widget / panel.cpp
1 /**
2  * \brief Panel widget
3  *
4  * Authors:
5  *   Bryce Harrington <bryce@bryceharrington.org>
6  *   Jon A. Cruz <jon@joncruz.org>
7  *
8  * Copyright (C) 2004 Bryce Harrington
9  * Copyright (C) 2005 Jon A. Cruz
10  *
11  * Released under GNU GPL.  Read the file 'COPYING' for more information
12  */
14 #ifdef HAVE_CONFIG_H
15 # include <config.h>
16 #endif
18 #include <glibmm/i18n.h>
20 #include "panel.h"
21 #include "../../prefs-utils.h"
23 namespace Inkscape {
24 namespace UI {
25 namespace Widget {
27 /**
28  *    Construct a Panel
29  *
30  *    \param label Label.
31  */
33 Panel::Panel(const gchar *prefs_path) :
34     _prefs_path(NULL),
35     _fillable(0)
36 {
37     _prefs_path = prefs_path;
38     init();
39 }
41 Panel::Panel() :
42     _prefs_path(NULL),
43     _fillable(0)
44 {
45     init();
46 }
48 Panel::Panel(Glib::ustring const &label) :
49     _prefs_path(NULL),
50     _fillable(0)
51 {
52     this->label = label;
53     init();
54 }
56 Panel::~Panel()
57 {
58 }
60 void Panel::init()
61 {
62     Glib::ustring tmp("<");
63     tabTitle.set_label(this->label);
65     guint panel_size = 0;
66     if (_prefs_path) {
67         panel_size = prefs_get_int_attribute_limited (_prefs_path, "panel_size", 1, 0, 10);
68     }
70     guint panel_mode = 0;
71     if (_prefs_path) {
72         panel_mode = prefs_get_int_attribute_limited (_prefs_path, "panel_mode", 1, 0, 10);
73     }
75     tabButton.set_menu(menu);
76     Gtk::MenuItem* dummy = manage(new Gtk::MenuItem(tmp));
77     menu.append( *dummy );
78     menu.append( *manage(new Gtk::SeparatorMenuItem()) );
79     {
80         const char *things[] = {
81             N_("small"),
82             N_("medium"),
83             N_("large"),
84             N_("huge")
85         };
86         Gtk::RadioMenuItem::Group groupOne;
87         for ( unsigned int i = 0; i < G_N_ELEMENTS(things); i++ ) {
88             Glib::ustring foo(gettext(things[i]));
89             Gtk::RadioMenuItem* single = manage(new Gtk::RadioMenuItem(groupOne, foo));
90             menu.append(*single);
91             if ( i == panel_size ) {
92                 single->set_active(true);
93             }
94             single->signal_activate().connect( sigc::bind<int, int>( sigc::mem_fun(*this, &Panel::bounceCall), 0, i) );
95        }
96     }
97     menu.append( *manage(new Gtk::SeparatorMenuItem()) );
98     Gtk::RadioMenuItem::Group group;
99     Glib::ustring oneLab(_("List"));
100     Glib::ustring twoLab(_("Grid"));
101     Gtk::RadioMenuItem *one = manage(new Gtk::RadioMenuItem(group, oneLab));
102     Gtk::RadioMenuItem *two = manage(new Gtk::RadioMenuItem(group, twoLab));
104     if (panel_mode == 0) {
105         one->set_active(true);
106     } else if (panel_mode == 1) {
107         two->set_active(true);
108     }
110     menu.append( *one );
111     menu.append( *two );
112     menu.append( *manage(new Gtk::SeparatorMenuItem()) );
113     one->signal_activate().connect( sigc::bind<int, int>( sigc::mem_fun(*this, &Panel::bounceCall), 1, 0) );
114     two->signal_activate().connect( sigc::bind<int, int>( sigc::mem_fun(*this, &Panel::bounceCall), 1, 1) );
116     //closeButton.set_label("X");
118     topBar.pack_start(tabTitle);
120     //topBar.pack_end(closeButton, false, false);
121     topBar.pack_end(tabButton, false, false);
123     pack_start( topBar, false, false );
125     Gtk::HBox* boxy = manage( new Gtk::HBox() );
127     boxy->pack_start( contents, true, true );
128     boxy->pack_start( rightBar, false, true );
130     pack_start( *boxy, true, true );
132     show_all_children();
134     bounceCall (0, panel_size);
135     bounceCall (1, panel_mode);
138 void Panel::setLabel(Glib::ustring const &label)
140     this->label = label;
141     tabTitle.set_label(this->label);
144 void Panel::setOrientation( Gtk::AnchorType how )
146     if ( _anchor != how )
147     {
148         _anchor = how;
149         switch ( _anchor )
150         {
151             case Gtk::ANCHOR_NORTH:
152             case Gtk::ANCHOR_SOUTH:
153             {
154                 tabButton.reference();
155                 topBar.remove(tabButton);
156                 rightBar.pack_start(tabButton, false, false);
157                 tabButton.unreference();
159                 topBar.remove(tabTitle);
160             }
161             break;
163             default:
164                 ; // nothing for now
165         }
166     }
169 void Panel::_regItem( Gtk::MenuItem* item, int group, int id )
171     menu.append( *item );
172     item->signal_activate().connect( sigc::bind<int, int>( sigc::mem_fun(*this, &Panel::bounceCall), group + 2, id) );
175 void Panel::restorePanelPrefs()
177     guint panel_size = 0;
178     if (_prefs_path) {
179         panel_size = prefs_get_int_attribute_limited (_prefs_path, "panel_size", 1, 0, 10);
180     }
181     guint panel_mode = 0;
182     if (_prefs_path) {
183         panel_mode = prefs_get_int_attribute_limited (_prefs_path, "panel_mode", 1, 0, 10);
184     }
185     bounceCall (0, panel_size);
186     bounceCall (1, panel_mode);
189 void Panel::bounceCall(int i, int j)
191     menu.set_active(0);
192     switch ( i ) {
193     case 0:
194         if (_prefs_path) prefs_set_int_attribute (_prefs_path, "panel_size", j);
195         if ( _fillable ) {
196             ViewType currType = _fillable->getPreviewType();
197             switch ( j ) {
198             case 0:
199             {
200                 _fillable->setStyle(Gtk::ICON_SIZE_MENU, currType);
201             }
202             break;
203             case 1:
204             {
205                 _fillable->setStyle(Gtk::ICON_SIZE_SMALL_TOOLBAR, currType);
206             }
207             break;
208             case 2:
209             {
210                 _fillable->setStyle(Gtk::ICON_SIZE_BUTTON, currType);
211             }
212             break;
213             case 3:
214             {
215                 _fillable->setStyle(Gtk::ICON_SIZE_DIALOG, currType);
216             }
217             break;
218             default:
219                 ;
220             }
221         }
222         break;
223     case 1:
224         if (_prefs_path) prefs_set_int_attribute (_prefs_path, "panel_mode", j);
225         if ( _fillable ) {
226             Gtk::BuiltinIconSize currSize = _fillable->getPreviewSize();
227             switch ( j ) {
228             case 0:
229             {
230                 _fillable->setStyle(currSize, VIEW_TYPE_LIST);
231             }
232             break;
233             case 1:
234             {
235                 _fillable->setStyle(currSize, VIEW_TYPE_GRID);
236             }
237             break;
238             default:
239                 break;
240             }
241         }
242         break;
243     default:
244         _handleAction( i - 2, j );
245     }
252 Glib::ustring const &Panel::getLabel() const
254     return label;
257 void Panel::_setTargetFillable( PreviewFillable *target )
259     _fillable = target;
262 void Panel::_handleAction( int setId, int itemId )
264 // for subclasses to override
267 } // namespace Widget
268 } // namespace UI
269 } // namespace Inkscape
271 /*
272   Local Variables:
273   mode:c++
274   c-file-style:"stroustrup"
275   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
276   indent-tabs-mode:nil
277   fill-column:99
278   End:
279 */
280 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :