1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
|
/**
* \brief Panel widget
*
* Authors:
* Bryce Harrington <bryce@bryceharrington.org>
* Jon A. Cruz <jon@joncruz.org>
*
* Copyright (C) 2004 Bryce Harrington
* Copyright (C) 2005 Jon A. Cruz
*
* Released under GNU GPL. Read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <glibmm/i18n.h>
#include "panel.h"
#include "../../icon-size.h"
#include "../../prefs-utils.h"
namespace Inkscape {
namespace UI {
namespace Widget {
static const int PANEL_SETTING_SIZE = 0;
static const int PANEL_SETTING_MODE = 1;
static const int PANEL_SETTING_WRAP = 2;
static const int PANEL_SETTING_NEXTFREE = 3;
/**
* Construct a Panel
*
* \param label Label.
*/
Panel::Panel() :
_prefs_path(NULL),
_menuDesired(false),
_tempArrow( Gtk::ARROW_LEFT, Gtk::SHADOW_ETCHED_OUT ),
menu(0),
_fillable(0)
{
init();
}
Panel::Panel( Glib::ustring const &label, gchar const* prefs_path, bool menuDesired ) :
_prefs_path(prefs_path),
_menuDesired(menuDesired),
label(label),
_tempArrow( Gtk::ARROW_LEFT, Gtk::SHADOW_ETCHED_OUT ),
menu(0),
_fillable(0)
{
init();
}
Panel::~Panel()
{
delete menu;
}
void Panel::_popper(GdkEventButton* event)
{
if ( (event->type == GDK_BUTTON_PRESS) && (event->button == 3 || event->button == 1) ) {
if (menu) {
menu->popup( event->button, event->time );
}
}
}
void Panel::init()
{
Glib::ustring tmp("<");
_anchor = Gtk::ANCHOR_CENTER;
tabTitle.set_label(this->label);
guint panel_size = 0;
if (_prefs_path) {
panel_size = prefs_get_int_attribute_limited( _prefs_path, "panel_size", 1, 0, 10 );
}
guint panel_mode = 0;
if (_prefs_path) {
panel_mode = prefs_get_int_attribute_limited( _prefs_path, "panel_mode", 1, 0, 10 );
}
guint panel_wrap = 0;
if (_prefs_path) {
panel_wrap = prefs_get_int_attribute_limited( _prefs_path, "panel_wrap", 0, 0, 1 );
}
menu = new Gtk::Menu();
{
const char *things[] = {
N_("tiny"),
N_("small"),
N_("medium"),
N_("large"),
N_("huge")
};
Gtk::RadioMenuItem::Group groupOne;
for ( unsigned int i = 0; i < G_N_ELEMENTS(things); i++ ) {
Glib::ustring foo(gettext(things[i]));
Gtk::RadioMenuItem* single = manage(new Gtk::RadioMenuItem(groupOne, foo));
menu->append(*single);
if ( i == panel_size ) {
single->set_active(true);
}
single->signal_activate().connect( sigc::bind<int, int>( sigc::mem_fun(*this, &Panel::bounceCall), PANEL_SETTING_SIZE, i) );
}
}
menu->append( *manage(new Gtk::SeparatorMenuItem()) );
Gtk::RadioMenuItem::Group group;
Glib::ustring oneLab(_("List"));
Glib::ustring twoLab(_("Grid"));
Gtk::RadioMenuItem *one = manage(new Gtk::RadioMenuItem(group, oneLab));
Gtk::RadioMenuItem *two = manage(new Gtk::RadioMenuItem(group, twoLab));
if (panel_mode == 0) {
one->set_active(true);
} else if (panel_mode == 1) {
two->set_active(true);
}
menu->append( *one );
nonHorizontal.push_back( one );
menu->append( *two );
nonHorizontal.push_back( two );
Gtk::MenuItem* sep = manage( new Gtk::SeparatorMenuItem());
menu->append( *sep );
nonHorizontal.push_back( sep );
one->signal_activate().connect( sigc::bind<int, int>( sigc::mem_fun(*this, &Panel::bounceCall), PANEL_SETTING_MODE, 0) );
two->signal_activate().connect( sigc::bind<int, int>( sigc::mem_fun(*this, &Panel::bounceCall), PANEL_SETTING_MODE, 1) );
{
Glib::ustring wrapLab(_("Wrap"));
Gtk::CheckMenuItem *check = manage(new Gtk::CheckMenuItem(wrapLab));
check->set_active( panel_wrap );
menu->append( *check );
nonVertical.push_back(check);
check->signal_toggled().connect( sigc::bind<Gtk::CheckMenuItem*>(sigc::mem_fun(*this, &Panel::_wrapToggled), check) );
sep = manage( new Gtk::SeparatorMenuItem());
menu->append( *sep );
nonVertical.push_back( sep );
}
menu->show_all_children();
for ( std::vector<Gtk::Widget*>::iterator iter = nonVertical.begin(); iter != nonVertical.end(); ++iter ) {
(*iter)->hide();
}
//closeButton.set_label("X");
topBar.pack_start(tabTitle);
//topBar.pack_end(closeButton, false, false);
if ( _menuDesired ) {
topBar.pack_end(menuPopper, false, false);
Gtk::Frame* outliner = manage(new Gtk::Frame());
outliner->set_shadow_type( Gtk::SHADOW_ETCHED_IN );
outliner->add( _tempArrow );
menuPopper.add( *outliner );
menuPopper.signal_button_press_event().connect_notify( sigc::mem_fun(*this, &Panel::_popper) );
}
pack_start( topBar, false, false );
Gtk::HBox* boxy = manage( new Gtk::HBox() );
boxy->pack_start( contents, true, true );
boxy->pack_start( rightBar, false, true );
pack_start( *boxy, true, true );
show_all_children();
bounceCall( PANEL_SETTING_SIZE, panel_size );
bounceCall( PANEL_SETTING_MODE, panel_mode );
bounceCall( PANEL_SETTING_WRAP, panel_wrap );
}
void Panel::setLabel(Glib::ustring const &label)
{
this->label = label;
tabTitle.set_label(this->label);
}
void Panel::setOrientation( Gtk::AnchorType how )
{
if ( _anchor != how )
{
_anchor = how;
switch ( _anchor )
{
case Gtk::ANCHOR_NORTH:
case Gtk::ANCHOR_SOUTH:
{
if ( _menuDesired ) {
menuPopper.reference();
topBar.remove(menuPopper);
rightBar.pack_start(menuPopper, false, false);
menuPopper.unreference();
for ( std::vector<Gtk::Widget*>::iterator iter = nonHorizontal.begin(); iter != nonHorizontal.end(); ++iter ) {
(*iter)->hide();
}
for ( std::vector<Gtk::Widget*>::iterator iter = nonVertical.begin(); iter != nonVertical.end(); ++iter ) {
(*iter)->show();
}
}
// Ensure we are not in "list" mode
bounceCall( PANEL_SETTING_MODE, 1 );
topBar.remove(tabTitle);
}
break;
default:
{
if ( _menuDesired ) {
for ( std::vector<Gtk::Widget*>::iterator iter = nonHorizontal.begin(); iter != nonHorizontal.end(); ++iter ) {
(*iter)->show();
}
for ( std::vector<Gtk::Widget*>::iterator iter = nonVertical.begin(); iter != nonVertical.end(); ++iter ) {
(*iter)->hide();
}
}
}
}
}
}
void Panel::_regItem( Gtk::MenuItem* item, int group, int id )
{
menu->append( *item );
item->signal_activate().connect( sigc::bind<int, int>( sigc::mem_fun(*this, &Panel::bounceCall), group + PANEL_SETTING_NEXTFREE, id) );
item->show();
}
void Panel::restorePanelPrefs()
{
guint panel_size = 0;
if (_prefs_path) {
panel_size = prefs_get_int_attribute_limited (_prefs_path, "panel_size", 1, 0, 10);
}
guint panel_mode = 0;
if (_prefs_path) {
panel_mode = prefs_get_int_attribute_limited (_prefs_path, "panel_mode", 1, 0, 10);
}
guint panel_wrap = 0;
if (_prefs_path) {
panel_wrap = prefs_get_int_attribute_limited( _prefs_path, "panel_wrap", 0, 0, 1 );
}
bounceCall( PANEL_SETTING_SIZE, panel_size );
bounceCall( PANEL_SETTING_MODE, panel_mode );
bounceCall( PANEL_SETTING_WRAP, panel_wrap );
}
void Panel::bounceCall(int i, int j)
{
menu->set_active(0);
switch ( i ) {
case PANEL_SETTING_SIZE:
if (_prefs_path) {
prefs_set_int_attribute( _prefs_path, "panel_size", j );
}
if ( _fillable ) {
ViewType currType = _fillable->getPreviewType();
switch ( j ) {
case 0:
{
_fillable->setStyle(Inkscape::ICON_SIZE_DECORATION, currType);
}
break;
case 1:
{
_fillable->setStyle(Inkscape::ICON_SIZE_MENU, currType);
}
break;
case 2:
{
_fillable->setStyle(Inkscape::ICON_SIZE_SMALL_TOOLBAR, currType);
}
break;
case 3:
{
_fillable->setStyle(Inkscape::ICON_SIZE_BUTTON, currType);
}
break;
case 4:
{
_fillable->setStyle(Inkscape::ICON_SIZE_DIALOG, currType);
}
break;
default:
;
}
}
break;
case PANEL_SETTING_MODE:
if (_prefs_path) {
prefs_set_int_attribute (_prefs_path, "panel_mode", j);
}
if ( _fillable ) {
Inkscape::IconSize currSize = _fillable->getPreviewSize();
switch ( j ) {
case 0:
{
_fillable->setStyle(currSize, VIEW_TYPE_LIST);
}
break;
case 1:
{
_fillable->setStyle(currSize, VIEW_TYPE_GRID);
}
break;
default:
break;
}
}
break;
case PANEL_SETTING_WRAP:
if (_prefs_path) {
prefs_set_int_attribute (_prefs_path, "panel_wrap", j ? 1 : 0);
}
if ( _fillable ) {
_fillable->setWrap( j );
}
break;
default:
_handleAction( i - PANEL_SETTING_NEXTFREE, j );
}
}
void Panel::_wrapToggled(Gtk::CheckMenuItem* toggler)
{
if ( toggler ) {
bounceCall( PANEL_SETTING_WRAP, toggler->get_active() ? 1 : 0 );
}
}
Glib::ustring const &Panel::getLabel() const
{
return label;
}
void Panel::_setTargetFillable( PreviewFillable *target )
{
_fillable = target;
}
void Panel::_handleAction( int setId, int itemId )
{
// for subclasses to override
}
} // namespace Widget
} // namespace UI
} // namespace Inkscape
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
|