Code

Removed panel menu unless requested. Fixes bug #1492597
[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 "../../icon-size.h"
22 #include "../../prefs-utils.h"
24 namespace Inkscape {
25 namespace UI {
26 namespace Widget {
28 /**
29  *    Construct a Panel
30  *
31  *    \param label Label.
32  */
34 Panel::Panel( const gchar *prefs_path, bool menuDesired ) :
35     _prefs_path(NULL),
36     _menuDesired(menuDesired),
37     _tempArrow( Gtk::ARROW_LEFT, Gtk::SHADOW_ETCHED_OUT ),
38     menu(0),
39     _fillable(0)
40 {
41     _prefs_path = prefs_path;
42     init();
43 }
45 Panel::Panel() :
46     _prefs_path(NULL),
47     _menuDesired(false),
48     _tempArrow( Gtk::ARROW_LEFT, Gtk::SHADOW_ETCHED_OUT ),
49     menu(0),
50     _fillable(0)
51 {
52     init();
53 }
55 Panel::Panel( Glib::ustring const &label, bool menuDesired ) :
56     _prefs_path(NULL),
57     _menuDesired(menuDesired),
58     _tempArrow( Gtk::ARROW_LEFT, Gtk::SHADOW_ETCHED_OUT ),
59     menu(0),
60     _fillable(0)
61 {
62     this->label = label;
63     init();
64 }
66 Panel::~Panel()
67 {
68     delete menu;
69 }
71 void Panel::_popper(GdkEventButton* event)
72 {
73     if ( (event->type == GDK_BUTTON_PRESS) && (event->button == 3 || event->button == 1) ) {
74         if (menu) {
75             menu->popup( event->button, event->time );
76         }
77     }
78 }
80 void Panel::init()
81 {
82     Glib::ustring tmp("<");
83     tabTitle.set_label(this->label);
85     guint panel_size = 0;
86     if (_prefs_path) {
87         panel_size = prefs_get_int_attribute_limited (_prefs_path, "panel_size", 1, 0, 10);
88     }
90     guint panel_mode = 0;
91     if (_prefs_path) {
92         panel_mode = prefs_get_int_attribute_limited (_prefs_path, "panel_mode", 1, 0, 10);
93     }
95     menu = new Gtk::Menu();
96     {
97         const char *things[] = {
98             N_("tiny"),
99             N_("small"),
100             N_("medium"),
101             N_("large"),
102             N_("huge")
103         };
104         Gtk::RadioMenuItem::Group groupOne;
105         for ( unsigned int i = 0; i < G_N_ELEMENTS(things); i++ ) {
106             Glib::ustring foo(gettext(things[i]));
107             Gtk::RadioMenuItem* single = manage(new Gtk::RadioMenuItem(groupOne, foo));
108             menu->append(*single);
109             if ( i == panel_size ) {
110                 single->set_active(true);
111             }
112             single->signal_activate().connect( sigc::bind<int, int>( sigc::mem_fun(*this, &Panel::bounceCall), 0, i) );
113        }
114     }
115     menu->append( *manage(new Gtk::SeparatorMenuItem()) );
116     Gtk::RadioMenuItem::Group group;
117     Glib::ustring oneLab(_("List"));
118     Glib::ustring twoLab(_("Grid"));
119     Gtk::RadioMenuItem *one = manage(new Gtk::RadioMenuItem(group, oneLab));
120     Gtk::RadioMenuItem *two = manage(new Gtk::RadioMenuItem(group, twoLab));
122     if (panel_mode == 0) {
123         one->set_active(true);
124     } else if (panel_mode == 1) {
125         two->set_active(true);
126     }
128     menu->append( *one );
129     menu->append( *two );
130     menu->append( *manage(new Gtk::SeparatorMenuItem()) );
131     one->signal_activate().connect( sigc::bind<int, int>( sigc::mem_fun(*this, &Panel::bounceCall), 1, 0) );
132     two->signal_activate().connect( sigc::bind<int, int>( sigc::mem_fun(*this, &Panel::bounceCall), 1, 1) );
134     menu->show_all_children();
136     //closeButton.set_label("X");
138     topBar.pack_start(tabTitle);
140     //topBar.pack_end(closeButton, false, false);
143     if ( _menuDesired ) {
144         topBar.pack_end(menuPopper, false, false);
145         Gtk::Frame* outliner = manage(new Gtk::Frame());
146         outliner->set_shadow_type( Gtk::SHADOW_ETCHED_IN );
147         outliner->add( _tempArrow );
148         menuPopper.add( *outliner );
149         menuPopper.signal_button_press_event().connect_notify( sigc::mem_fun(*this, &Panel::_popper) );
150     }
152     pack_start( topBar, false, false );
154     Gtk::HBox* boxy = manage( new Gtk::HBox() );
156     boxy->pack_start( contents, true, true );
157     boxy->pack_start( rightBar, false, true );
159     pack_start( *boxy, true, true );
161     show_all_children();
163     bounceCall (0, panel_size);
164     bounceCall (1, panel_mode);
167 void Panel::setLabel(Glib::ustring const &label)
169     this->label = label;
170     tabTitle.set_label(this->label);
173 void Panel::setOrientation( Gtk::AnchorType how )
175     if ( _anchor != how )
176     {
177         _anchor = how;
178         switch ( _anchor )
179         {
180             case Gtk::ANCHOR_NORTH:
181             case Gtk::ANCHOR_SOUTH:
182             {
183                 if ( _menuDesired ) {
184                     menuPopper.reference();
185                     topBar.remove(menuPopper);
186                     rightBar.pack_start(menuPopper, false, false);
187                     menuPopper.unreference();
188                 }
190                 topBar.remove(tabTitle);
191             }
192             break;
194             default:
195                 ; // nothing for now
196         }
197     }
200 void Panel::_regItem( Gtk::MenuItem* item, int group, int id )
202     menu->append( *item );
203     item->signal_activate().connect( sigc::bind<int, int>( sigc::mem_fun(*this, &Panel::bounceCall), group + 2, id) );
204     item->show();
207 void Panel::restorePanelPrefs()
209     guint panel_size = 0;
210     if (_prefs_path) {
211         panel_size = prefs_get_int_attribute_limited (_prefs_path, "panel_size", 1, 0, 10);
212     }
213     guint panel_mode = 0;
214     if (_prefs_path) {
215         panel_mode = prefs_get_int_attribute_limited (_prefs_path, "panel_mode", 1, 0, 10);
216     }
217     bounceCall (0, panel_size);
218     bounceCall (1, panel_mode);
221 void Panel::bounceCall(int i, int j)
223     menu->set_active(0);
224     switch ( i ) {
225     case 0:
226         if (_prefs_path) prefs_set_int_attribute (_prefs_path, "panel_size", j);
227         if ( _fillable ) {
228             ViewType currType = _fillable->getPreviewType();
229             switch ( j ) {
230             case 0:
231             {
232                 _fillable->setStyle(Inkscape::ICON_SIZE_DECORATION, currType);
233             }
234             break;
235             case 1:
236             {
237                 _fillable->setStyle(Inkscape::ICON_SIZE_MENU, currType);
238             }
239             break;
240             case 2:
241             {
242                 _fillable->setStyle(Inkscape::ICON_SIZE_SMALL_TOOLBAR, currType);
243             }
244             break;
245             case 3:
246             {
247                 _fillable->setStyle(Inkscape::ICON_SIZE_BUTTON, currType);
248             }
249             break;
250             case 4:
251             {
252                 _fillable->setStyle(Inkscape::ICON_SIZE_DIALOG, currType);
253             }
254             break;
255             default:
256                 ;
257             }
258         }
259         break;
260     case 1:
261         if (_prefs_path) prefs_set_int_attribute (_prefs_path, "panel_mode", j);
262         if ( _fillable ) {
263             Inkscape::IconSize currSize = _fillable->getPreviewSize();
264             switch ( j ) {
265             case 0:
266             {
267                 _fillable->setStyle(currSize, VIEW_TYPE_LIST);
268             }
269             break;
270             case 1:
271             {
272                 _fillable->setStyle(currSize, VIEW_TYPE_GRID);
273             }
274             break;
275             default:
276                 break;
277             }
278         }
279         break;
280     default:
281         _handleAction( i - 2, j );
282     }
289 Glib::ustring const &Panel::getLabel() const
291     return label;
294 void Panel::_setTargetFillable( PreviewFillable *target )
296     _fillable = target;
299 void Panel::_handleAction( int setId, int itemId )
301 // for subclasses to override
304 } // namespace Widget
305 } // namespace UI
306 } // namespace Inkscape
308 /*
309   Local Variables:
310   mode:c++
311   c-file-style:"stroustrup"
312   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
313   indent-tabs-mode:nil
314   fill-column:99
315   End:
316 */
317 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :