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) :
35 _prefs_path(NULL),
36 _tempArrow( Gtk::ARROW_LEFT, Gtk::SHADOW_ETCHED_OUT ),
37 menu(0),
38 _fillable(0)
39 {
40 _prefs_path = prefs_path;
41 init();
42 }
44 Panel::Panel() :
45 _prefs_path(NULL),
46 _tempArrow( Gtk::ARROW_LEFT, Gtk::SHADOW_ETCHED_OUT ),
47 menu(0),
48 _fillable(0)
49 {
50 init();
51 }
53 Panel::Panel(Glib::ustring const &label) :
54 _prefs_path(NULL),
55 _tempArrow( Gtk::ARROW_LEFT, Gtk::SHADOW_ETCHED_OUT ),
56 menu(0),
57 _fillable(0)
58 {
59 this->label = label;
60 init();
61 }
63 Panel::~Panel()
64 {
65 delete menu;
66 }
68 void Panel::_popper(GdkEventButton* event)
69 {
70 if ( (event->type == GDK_BUTTON_PRESS) && (event->button == 3 || event->button == 1) ) {
71 if (menu) {
72 menu->popup( event->button, event->time );
73 }
74 }
75 }
77 void Panel::init()
78 {
79 Glib::ustring tmp("<");
80 tabTitle.set_label(this->label);
82 guint panel_size = 0;
83 if (_prefs_path) {
84 panel_size = prefs_get_int_attribute_limited (_prefs_path, "panel_size", 1, 0, 10);
85 }
87 guint panel_mode = 0;
88 if (_prefs_path) {
89 panel_mode = prefs_get_int_attribute_limited (_prefs_path, "panel_mode", 1, 0, 10);
90 }
92 menu = new Gtk::Menu();
93 {
94 const char *things[] = {
95 N_("tiny"),
96 N_("small"),
97 N_("medium"),
98 N_("large"),
99 N_("huge")
100 };
101 Gtk::RadioMenuItem::Group groupOne;
102 for ( unsigned int i = 0; i < G_N_ELEMENTS(things); i++ ) {
103 Glib::ustring foo(gettext(things[i]));
104 Gtk::RadioMenuItem* single = manage(new Gtk::RadioMenuItem(groupOne, foo));
105 menu->append(*single);
106 if ( i == panel_size ) {
107 single->set_active(true);
108 }
109 single->signal_activate().connect( sigc::bind<int, int>( sigc::mem_fun(*this, &Panel::bounceCall), 0, i) );
110 }
111 }
112 menu->append( *manage(new Gtk::SeparatorMenuItem()) );
113 Gtk::RadioMenuItem::Group group;
114 Glib::ustring oneLab(_("List"));
115 Glib::ustring twoLab(_("Grid"));
116 Gtk::RadioMenuItem *one = manage(new Gtk::RadioMenuItem(group, oneLab));
117 Gtk::RadioMenuItem *two = manage(new Gtk::RadioMenuItem(group, twoLab));
119 if (panel_mode == 0) {
120 one->set_active(true);
121 } else if (panel_mode == 1) {
122 two->set_active(true);
123 }
125 menu->append( *one );
126 menu->append( *two );
127 menu->append( *manage(new Gtk::SeparatorMenuItem()) );
128 one->signal_activate().connect( sigc::bind<int, int>( sigc::mem_fun(*this, &Panel::bounceCall), 1, 0) );
129 two->signal_activate().connect( sigc::bind<int, int>( sigc::mem_fun(*this, &Panel::bounceCall), 1, 1) );
131 menu->show_all_children();
133 //closeButton.set_label("X");
135 topBar.pack_start(tabTitle);
137 //topBar.pack_end(closeButton, false, false);
140 topBar.pack_end(menuPopper, false, false);
141 Gtk::Frame* outliner = manage(new Gtk::Frame());
142 outliner->set_shadow_type( Gtk::SHADOW_ETCHED_IN );
143 outliner->add( _tempArrow );
144 menuPopper.add( *outliner );
145 menuPopper.signal_button_press_event().connect_notify( sigc::mem_fun(*this, &Panel::_popper) );
147 pack_start( topBar, false, false );
149 Gtk::HBox* boxy = manage( new Gtk::HBox() );
151 boxy->pack_start( contents, true, true );
152 boxy->pack_start( rightBar, false, true );
154 pack_start( *boxy, true, true );
156 show_all_children();
158 bounceCall (0, panel_size);
159 bounceCall (1, panel_mode);
160 }
162 void Panel::setLabel(Glib::ustring const &label)
163 {
164 this->label = label;
165 tabTitle.set_label(this->label);
166 }
168 void Panel::setOrientation( Gtk::AnchorType how )
169 {
170 if ( _anchor != how )
171 {
172 _anchor = how;
173 switch ( _anchor )
174 {
175 case Gtk::ANCHOR_NORTH:
176 case Gtk::ANCHOR_SOUTH:
177 {
178 menuPopper.reference();
179 topBar.remove(menuPopper);
180 rightBar.pack_start(menuPopper, false, false);
181 menuPopper.unreference();
183 topBar.remove(tabTitle);
184 }
185 break;
187 default:
188 ; // nothing for now
189 }
190 }
191 }
193 void Panel::_regItem( Gtk::MenuItem* item, int group, int id )
194 {
195 menu->append( *item );
196 item->signal_activate().connect( sigc::bind<int, int>( sigc::mem_fun(*this, &Panel::bounceCall), group + 2, id) );
197 item->show();
198 }
200 void Panel::restorePanelPrefs()
201 {
202 guint panel_size = 0;
203 if (_prefs_path) {
204 panel_size = prefs_get_int_attribute_limited (_prefs_path, "panel_size", 1, 0, 10);
205 }
206 guint panel_mode = 0;
207 if (_prefs_path) {
208 panel_mode = prefs_get_int_attribute_limited (_prefs_path, "panel_mode", 1, 0, 10);
209 }
210 bounceCall (0, panel_size);
211 bounceCall (1, panel_mode);
212 }
214 void Panel::bounceCall(int i, int j)
215 {
216 menu->set_active(0);
217 switch ( i ) {
218 case 0:
219 if (_prefs_path) prefs_set_int_attribute (_prefs_path, "panel_size", j);
220 if ( _fillable ) {
221 ViewType currType = _fillable->getPreviewType();
222 switch ( j ) {
223 case 0:
224 {
225 _fillable->setStyle(Inkscape::ICON_SIZE_DECORATION, currType);
226 }
227 break;
228 case 1:
229 {
230 _fillable->setStyle(Inkscape::ICON_SIZE_MENU, currType);
231 }
232 break;
233 case 2:
234 {
235 _fillable->setStyle(Inkscape::ICON_SIZE_SMALL_TOOLBAR, currType);
236 }
237 break;
238 case 3:
239 {
240 _fillable->setStyle(Inkscape::ICON_SIZE_BUTTON, currType);
241 }
242 break;
243 case 4:
244 {
245 _fillable->setStyle(Inkscape::ICON_SIZE_DIALOG, currType);
246 }
247 break;
248 default:
249 ;
250 }
251 }
252 break;
253 case 1:
254 if (_prefs_path) prefs_set_int_attribute (_prefs_path, "panel_mode", j);
255 if ( _fillable ) {
256 Inkscape::IconSize currSize = _fillable->getPreviewSize();
257 switch ( j ) {
258 case 0:
259 {
260 _fillable->setStyle(currSize, VIEW_TYPE_LIST);
261 }
262 break;
263 case 1:
264 {
265 _fillable->setStyle(currSize, VIEW_TYPE_GRID);
266 }
267 break;
268 default:
269 break;
270 }
271 }
272 break;
273 default:
274 _handleAction( i - 2, j );
275 }
276 }
282 Glib::ustring const &Panel::getLabel() const
283 {
284 return label;
285 }
287 void Panel::_setTargetFillable( PreviewFillable *target )
288 {
289 _fillable = target;
290 }
292 void Panel::_handleAction( int setId, int itemId )
293 {
294 // for subclasses to override
295 }
297 } // namespace Widget
298 } // namespace UI
299 } // namespace Inkscape
301 /*
302 Local Variables:
303 mode:c++
304 c-file-style:"stroustrup"
305 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
306 indent-tabs-mode:nil
307 fill-column:99
308 End:
309 */
310 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :