summaryrefslogtreecommitdiffstats
path: root/src/ui/widget
diff options
context:
space:
mode:
authorgustav_b <gustav_b@users.sourceforge.net>2007-11-22 00:14:41 +0000
committergustav_b <gustav_b@users.sourceforge.net>2007-11-22 00:14:41 +0000
commit5caa6ff4dfb7b538555d60fa2732272bf8b9828b (patch)
tree65c6fb0232f8621fa6cecdcdf68d0790bd955777 /src/ui/widget
parentFix ordering of LPE parameters (no longer use map, just use vector) (diff)
downloadinkscape-5caa6ff4dfb7b538555d60fa2732272bf8b9828b.tar.gz
inkscape-5caa6ff4dfb7b538555d60fa2732272bf8b9828b.zip
The dialog to panel refactoring:
* Made the current dialogs subclass the Panel class instead of the Dialog class. * Extended the Panel class with some functionality that the dialogs relied on. * Added a PanelDialog class which is a dialog container for a single panel with the dialog behavior as a template parameter. (* Fixed coding style for the Panel and Dialog class) For details, see http://www.nabble.com/Re%3A-Dockable-dialogs%2C-todo-list-p12728194.html http://www.nabble.com/Re%3A-Inkscape-overcomes-Xara-in-Google-Trends-p13126622.html (bzr r4126)
Diffstat (limited to 'src/ui/widget')
-rw-r--r--src/ui/widget/dock-item.cpp60
-rw-r--r--src/ui/widget/dock-item.h12
-rw-r--r--src/ui/widget/panel.cpp366
-rw-r--r--src/ui/widget/panel.h107
-rw-r--r--src/ui/widget/selected-style.cpp41
5 files changed, 341 insertions, 245 deletions
diff --git a/src/ui/widget/dock-item.cpp b/src/ui/widget/dock-item.cpp
index f3fba93bf..6390eca50 100644
--- a/src/ui/widget/dock-item.cpp
+++ b/src/ui/widget/dock-item.cpp
@@ -32,21 +32,6 @@ DockItem::DockItem(Dock& dock, const Glib::ustring& name, const Glib::ustring& l
_window (NULL),
_dock_item_action_area (NULL)
{
- /* Add a "signal_response" signal to the GdlDockItem, make sure it is
- * only done once for the class.
- */
- static guint response_signal = 0;
-
- if (response_signal == 0) {
- response_signal = g_signal_new ("signal_response",
- GDL_TYPE_DOCK_ITEM,
- G_SIGNAL_RUN_FIRST,
- 0,
- NULL, NULL,
- g_cclosure_marshal_VOID__INT,
- G_TYPE_NONE, 1, G_TYPE_INT);
- }
-
GdlDockItemBehavior gdl_dock_behavior =
(prefs_get_int_attribute_limited ("options.dock", "cancenterdock", 1, 0, 1) == 0 ?
@@ -228,20 +213,6 @@ DockItem::getPlacement() const
return (Placement)placement;
}
-
-void
-DockItem::addButton(Gtk::Button* button, int /*response_id*/)
-{
- // Create a button box for the response buttons if it's the first button to be added
- if (!_dock_item_action_area) {
- _dock_item_action_area = new Gtk::HButtonBox(Gtk::BUTTONBOX_END, 6);
- _dock_item_box.pack_end(*_dock_item_action_area, Gtk::PACK_SHRINK, 0);
- _dock_item_action_area->set_border_width(6);
- }
-
- _dock_item_action_area->pack_start(*button);
-}
-
void
DockItem::hide()
{
@@ -326,13 +297,6 @@ DockItem::signal_delete_event()
&_signal_delete_event_proxy);
}
-Glib::SignalProxy1<void, int>
-DockItem::signal_response()
-{
- return Glib::SignalProxy1<void, int>(Glib::wrap(GTK_WIDGET(_gdl_dock_item)),
- &_signal_response_proxy);
-}
-
Glib::SignalProxy0<void>
DockItem::signal_drag_begin()
{
@@ -477,14 +441,6 @@ DockItem::_signal_delete_event_proxy =
const Glib::SignalProxyInfo
-DockItem::_signal_response_proxy =
-{
- "signal_response",
- (GCallback) &_signal_response_callback,
- (GCallback) &_signal_response_callback
-};
-
-const Glib::SignalProxyInfo
DockItem::_signal_drag_begin_proxy =
{
"dock-drag-begin",
@@ -531,22 +487,6 @@ DockItem::_signal_delete_event_callback(GtkWidget *self, GdkEventAny *event, voi
}
void
-DockItem::_signal_response_callback(GtkWidget *self, gint response_id, void *data)
-{
- using namespace Gtk;
- typedef sigc::slot<void, int> SlotType;
-
- if (Glib::ObjectBase::_get_current_wrapper((GObject *) self)) {
- try {
- if(sigc::slot_base *const slot = Glib::SignalProxyNormal::data_to_slot(data))
- (*static_cast<SlotType *>(slot))(response_id);
- } catch(...) {
- Glib::exception_handlers_invoke();
- }
- }
-}
-
-void
DockItem::_signal_drag_end_callback(GtkWidget *self, gboolean cancelled, void *data)
{
using namespace Gtk;
diff --git a/src/ui/widget/dock-item.h b/src/ui/widget/dock-item.h
index af2f3ac70..c0f52a77a 100644
--- a/src/ui/widget/dock-item.h
+++ b/src/ui/widget/dock-item.h
@@ -75,8 +75,6 @@ public:
Gtk::Window *getWindow(); //< gives the parent window, if the dock item has one (i.e. it's floating)
- void addButton(Gtk::Button *button, int response_id);
-
void hide();
void show();
void show_all();
@@ -88,7 +86,6 @@ public:
Glib::SignalProxy0<void> signal_show();
Glib::SignalProxy0<void> signal_hide();
Glib::SignalProxy1<bool, GdkEventAny *> signal_delete_event();
- Glib::SignalProxy1<void, int> signal_response();
Glib::SignalProxy0<void> signal_drag_begin();
Glib::SignalProxy1<void, bool> signal_drag_end();
Glib::SignalProxy0<void> signal_realize();
@@ -121,7 +118,6 @@ private:
void _onHide();
void _onHideWindow();
void _onShow();
- void _onResponse(int response_id);
void _onDragBegin();
void _onDragEnd(bool cancelled);
void _onRealize();
@@ -136,7 +132,7 @@ private:
static const Glib::SignalProxyInfo _signal_show_proxy;
static const Glib::SignalProxyInfo _signal_hide_proxy;
static const Glib::SignalProxyInfo _signal_delete_event_proxy;
- static const Glib::SignalProxyInfo _signal_response_proxy;
+
static const Glib::SignalProxyInfo _signal_drag_begin_proxy;
static const Glib::SignalProxyInfo _signal_drag_end_proxy;
static const Glib::SignalProxyInfo _signal_realize_proxy;
@@ -144,12 +140,6 @@ private:
static gboolean _signal_delete_event_callback(GtkWidget *self, GdkEventAny *event, void *data);
static void _signal_drag_end_callback(GtkWidget* self, gboolean p0, void* data);
- /** In order to emulate a signal_response signal like the one for Gtk::Dialog we inject a new
- * signal into GdlDockItem. This signal will be emitted when a button in the dock item added
- * through the addButton(..., response_id) method, is clicked.
- */
- static void _signal_response_callback(GtkWidget* self, gint p0, void* data);
-
sigc::signal<void, State, State> _signal_state_changed;
DockItem();
diff --git a/src/ui/widget/panel.cpp b/src/ui/widget/panel.cpp
index 8be563828..1e868191d 100644
--- a/src/ui/widget/panel.cpp
+++ b/src/ui/widget/panel.cpp
@@ -17,9 +17,14 @@
#include <glibmm/i18n.h>
+#include <gtkmm/dialog.h> // for Gtk::RESPONSE_*
+#include <gtkmm/stock.h>
+
#include "panel.h"
-#include "../../icon-size.h"
-#include "../../prefs-utils.h"
+#include "icon-size.h"
+#include "prefs-utils.h"
+#include "desktop-handles.h"
+#include "inkscape.h"
namespace Inkscape {
namespace UI {
@@ -32,50 +37,42 @@ 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 ) :
+Panel::Panel(Glib::ustring const &label, gchar const *prefs_path,
+ int verb_num, Glib::ustring const &apply_label,
+ bool menu_desired) :
_prefs_path(prefs_path),
- _menuDesired(menuDesired),
- label(label),
- _tempArrow( Gtk::ARROW_LEFT, Gtk::SHADOW_ETCHED_OUT ),
- menu(0),
+ _menu_desired(menu_desired),
+ _label(label),
+ _apply_label(apply_label),
+ _verb_num(verb_num),
+ _temp_arrow(Gtk::ARROW_LEFT, Gtk::SHADOW_ETCHED_OUT),
+ _menu(0),
+ _action_area(0),
_fillable(0)
{
- init();
+ _init();
}
Panel::~Panel()
{
- delete menu;
+ 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 );
+ if (_menu) {
+ _menu->popup(event->button, event->time);
}
}
}
-void Panel::init()
+void Panel::_init()
{
Glib::ustring tmp("<");
_anchor = Gtk::ANCHOR_CENTER;
- tabTitle.set_label(this->label);
guint panel_size = 0;
if (_prefs_path) {
@@ -92,7 +89,7 @@ void Panel::init()
panel_wrap = prefs_get_int_attribute_limited( _prefs_path, "panel_wrap", 0, 0, 1 );
}
- menu = new Gtk::Menu();
+ _menu = new Gtk::Menu();
{
const char *things[] = {
N_("tiny"),
@@ -102,22 +99,22 @@ void Panel::init()
N_("huge")
};
Gtk::RadioMenuItem::Group groupOne;
- for ( unsigned int i = 0; i < G_N_ELEMENTS(things); i++ ) {
+ 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 ) {
+ _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) );
+ single->signal_activate().connect(sigc::bind<int, int>(sigc::mem_fun(*this, &Panel::_bounceCall), PANEL_SETTING_SIZE, i));
}
}
- menu->append( *manage(new Gtk::SeparatorMenuItem()) );
+ _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));
+ Glib::ustring one_label(_("List"));
+ Glib::ustring two_label(_("Grid"));
+ Gtk::RadioMenuItem *one = manage(new Gtk::RadioMenuItem(group, one_label));
+ Gtk::RadioMenuItem *two = manage(new Gtk::RadioMenuItem(group, two_label));
if (panel_mode == 0) {
one->set_active(true);
@@ -125,109 +122,118 @@ void Panel::init()
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) );
+ _menu->append(*one);
+ _non_horizontal.push_back(one);
+ _menu->append(*two);
+ _non_horizontal.push_back(two);
+ Gtk::MenuItem* sep = manage(new Gtk::SeparatorMenuItem());
+ _menu->append(*sep);
+ _non_horizontal.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);
+ Glib::ustring wrap_label(_("Wrap"));
+ Gtk::CheckMenuItem *check = manage(new Gtk::CheckMenuItem(wrap_label));
+ check->set_active(panel_wrap);
+ _menu->append(*check);
+ _non_vertical.push_back(check);
- check->signal_toggled().connect( sigc::bind<Gtk::CheckMenuItem*>(sigc::mem_fun(*this, &Panel::_wrapToggled), 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 );
+ sep = manage(new Gtk::SeparatorMenuItem());
+ _menu->append(*sep);
+ _non_vertical.push_back(sep);
}
- menu->show_all_children();
- for ( std::vector<Gtk::Widget*>::iterator iter = nonVertical.begin(); iter != nonVertical.end(); ++iter ) {
+ _menu->show_all_children();
+ for ( std::vector<Gtk::Widget*>::iterator iter = _non_vertical.begin(); iter != _non_vertical.end(); ++iter ) {
(*iter)->hide();
}
- //closeButton.set_label("X");
+ // _close_button.set_label("X");
- topBar.pack_start(tabTitle);
+ if (!_label.empty()) {
+ _tab_title.set_label(_label);
+ _top_bar.pack_start(_tab_title);
+ }
- //topBar.pack_end(closeButton, false, false);
+ // _top_bar.pack_end(_close_button, false, false);
- if ( _menuDesired ) {
- topBar.pack_end(menuPopper, false, false);
+ if ( _menu_desired ) {
+ _top_bar.pack_end(_menu_popper, 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) );
+ outliner->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
+ outliner->add(_temp_arrow);
+ _menu_popper.add(*outliner);
+ _menu_popper.signal_button_press_event().connect_notify(sigc::mem_fun(*this, &Panel::_popper));
}
- pack_start( topBar, false, false );
+ pack_start(_top_bar, false, false);
- Gtk::HBox* boxy = manage( new Gtk::HBox() );
+ Gtk::HBox* boxy = manage(new Gtk::HBox());
- boxy->pack_start( contents, true, true );
- boxy->pack_start( rightBar, false, true );
+ boxy->pack_start(_contents, true, true);
+ boxy->pack_start(_right_bar, false, true);
- pack_start( *boxy, true, true );
+ pack_start(*boxy, true, true);
+
+ signalResponse().connect(sigc::mem_fun(*this, &Panel::_handleResponse));
show_all_children();
- bounceCall( PANEL_SETTING_SIZE, panel_size );
- bounceCall( PANEL_SETTING_MODE, panel_mode );
- bounceCall( PANEL_SETTING_WRAP, panel_wrap );
+ _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);
+ if (_label.empty() && !label.empty())
+ _top_bar.pack_start(_tab_title);
+ else if (!_label.empty() && label.empty())
+ _top_bar.remove(_tab_title);
+
+ _label = label;
+ _tab_title.set_label(_label);
}
-void Panel::setOrientation( Gtk::AnchorType how )
+void Panel::setOrientation(Gtk::AnchorType how)
{
- if ( _anchor != how )
- {
+ if (_anchor != how) {
_anchor = how;
- switch ( _anchor )
- {
+ 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();
+ if (_menu_desired) {
+ _menu_popper.reference();
+ _top_bar.remove(_menu_popper);
+ _right_bar.pack_start(_menu_popper, false, false);
+ _menu_popper.unreference();
- for ( std::vector<Gtk::Widget*>::iterator iter = nonHorizontal.begin(); iter != nonHorizontal.end(); ++iter ) {
+ for (std::vector<Gtk::Widget*>::iterator iter = _non_horizontal.begin(); iter != _non_horizontal.end(); ++iter) {
(*iter)->hide();
}
- for ( std::vector<Gtk::Widget*>::iterator iter = nonVertical.begin(); iter != nonVertical.end(); ++iter ) {
+ for (std::vector<Gtk::Widget*>::iterator iter = _non_vertical.begin(); iter != _non_vertical.end(); ++iter) {
(*iter)->show();
}
}
// Ensure we are not in "list" mode
- bounceCall( PANEL_SETTING_MODE, 1 );
- topBar.remove(tabTitle);
+ _bounceCall(PANEL_SETTING_MODE, 1);
+ if (!_label.empty())
+ _top_bar.remove(_tab_title);
}
break;
default:
{
- if ( _menuDesired ) {
- for ( std::vector<Gtk::Widget*>::iterator iter = nonHorizontal.begin(); iter != nonHorizontal.end(); ++iter ) {
+ if ( _menu_desired ) {
+ for (std::vector<Gtk::Widget*>::iterator iter = _non_horizontal.begin(); iter != _non_horizontal.end(); ++iter) {
(*iter)->show();
}
- for ( std::vector<Gtk::Widget*>::iterator iter = nonVertical.begin(); iter != nonVertical.end(); ++iter ) {
+ for (std::vector<Gtk::Widget*>::iterator iter = _non_vertical.begin(); iter != _non_vertical.end(); ++iter) {
(*iter)->hide();
}
}
@@ -236,66 +242,77 @@ void Panel::setOrientation( Gtk::AnchorType how )
}
}
-void Panel::_regItem( Gtk::MenuItem* item, int group, int id )
+void Panel::present()
{
- menu->append( *item );
- item->signal_activate().connect( sigc::bind<int, int>( sigc::mem_fun(*this, &Panel::bounceCall), group + PANEL_SETTING_NEXTFREE, id) );
- item->show();
+ _signal_present.emit();
}
+
void Panel::restorePanelPrefs()
{
guint panel_size = 0;
if (_prefs_path) {
- panel_size = prefs_get_int_attribute_limited (_prefs_path, "panel_size", 1, 0, 10);
+ 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);
+ 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 );
+ 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 );
+ _bounceCall(PANEL_SETTING_SIZE, panel_size);
+ _bounceCall(PANEL_SETTING_MODE, panel_mode);
+ _bounceCall(PANEL_SETTING_WRAP, panel_wrap);
+}
+
+sigc::signal<void, int> &
+Panel::signalResponse()
+{
+ return _signal_response;
+}
+
+sigc::signal<void> &
+Panel::signalPresent()
+{
+ return _signal_present;
}
-void Panel::bounceCall(int i, int j)
+void Panel::_bounceCall(int i, int j)
{
- menu->set_active(0);
- switch ( i ) {
+ _menu->set_active(0);
+ switch (i) {
case PANEL_SETTING_SIZE:
if (_prefs_path) {
- prefs_set_int_attribute( _prefs_path, "panel_size", j );
+ prefs_set_int_attribute(_prefs_path, "panel_size", j);
}
- if ( _fillable ) {
- ViewType currType = _fillable->getPreviewType();
- switch ( j ) {
+ if (_fillable) {
+ ViewType curr_type = _fillable->getPreviewType();
+ switch (j) {
case 0:
{
- _fillable->setStyle(Inkscape::ICON_SIZE_DECORATION, currType);
+ _fillable->setStyle(Inkscape::ICON_SIZE_DECORATION, curr_type);
}
break;
case 1:
{
- _fillable->setStyle(Inkscape::ICON_SIZE_MENU, currType);
+ _fillable->setStyle(Inkscape::ICON_SIZE_MENU, curr_type);
}
break;
case 2:
{
- _fillable->setStyle(Inkscape::ICON_SIZE_SMALL_TOOLBAR, currType);
+ _fillable->setStyle(Inkscape::ICON_SIZE_SMALL_TOOLBAR, curr_type);
}
break;
case 3:
{
- _fillable->setStyle(Inkscape::ICON_SIZE_BUTTON, currType);
+ _fillable->setStyle(Inkscape::ICON_SIZE_BUTTON, curr_type);
}
break;
case 4:
{
- _fillable->setStyle(Inkscape::ICON_SIZE_DIALOG, currType);
+ _fillable->setStyle(Inkscape::ICON_SIZE_DIALOG, curr_type);
}
break;
default:
@@ -307,17 +324,17 @@ void Panel::bounceCall(int i, int j)
if (_prefs_path) {
prefs_set_int_attribute (_prefs_path, "panel_mode", j);
}
- if ( _fillable ) {
- Inkscape::IconSize currSize = _fillable->getPreviewSize();
- switch ( j ) {
+ if (_fillable) {
+ Inkscape::IconSize curr_size = _fillable->getPreviewSize();
+ switch (j) {
case 0:
{
- _fillable->setStyle(currSize, VIEW_TYPE_LIST);
+ _fillable->setStyle(curr_size, VIEW_TYPE_LIST);
}
break;
case 1:
{
- _fillable->setStyle(currSize, VIEW_TYPE_GRID);
+ _fillable->setStyle(curr_size, VIEW_TYPE_GRID);
}
break;
default:
@@ -330,41 +347,136 @@ void Panel::bounceCall(int i, int j)
prefs_set_int_attribute (_prefs_path, "panel_wrap", j ? 1 : 0);
}
if ( _fillable ) {
- _fillable->setWrap( j );
+ _fillable->setWrap(j);
}
break;
default:
- _handleAction( i - PANEL_SETTING_NEXTFREE, j );
+ _handleAction(i - PANEL_SETTING_NEXTFREE, j);
}
}
void Panel::_wrapToggled(Gtk::CheckMenuItem* toggler)
{
- if ( toggler ) {
- bounceCall( PANEL_SETTING_WRAP, toggler->get_active() ? 1 : 0 );
+ if (toggler) {
+ _bounceCall(PANEL_SETTING_WRAP, toggler->get_active() ? 1 : 0);
}
}
+gchar const *Panel::getPrefsPath() const
+{
+ return _prefs_path;
+}
+Glib::ustring const &Panel::getLabel() const
+{
+ return _label;
+}
+int const &Panel::getVerb() const
+{
+ return _verb_num;
+}
-
-Glib::ustring const &Panel::getLabel() const
+Glib::ustring const &Panel::getApplyLabel() const
{
- return label;
+ return _apply_label;
}
-void Panel::_setTargetFillable( PreviewFillable *target )
+void Panel::_setTargetFillable(PreviewFillable *target)
{
_fillable = target;
}
-void Panel::_handleAction( int setId, int itemId )
+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::_handleAction(int set_id, int item_id)
{
// for subclasses to override
}
+void
+Panel::_apply()
+{
+ g_warning("Apply button clicked for panel [Panel::_apply()]");
+}
+
+Gtk::Button *
+Panel::addResponseButton(const Glib::ustring &button_text, int response_id)
+{
+ Gtk::Button *button = new Gtk::Button(button_text);
+ _addResponseButton(button, response_id);
+ return button;
+}
+
+Gtk::Button *
+Panel::addResponseButton(const Gtk::StockID &stock_id, int response_id)
+{
+ Gtk::Button *button = new Gtk::Button(stock_id);
+ _addResponseButton(button, response_id);
+ return button;
+}
+
+void
+Panel::_addResponseButton(Gtk::Button *button, int response_id)
+{
+ // Create a button box for the response buttons if it's the first button to be added
+ if (!_action_area) {
+ _action_area = new Gtk::HButtonBox(Gtk::BUTTONBOX_END, 6);
+ _action_area->set_border_width(4);
+ pack_end(*_action_area, Gtk::PACK_SHRINK, 0);
+ }
+
+ _action_area->pack_end(*button);
+
+ if (response_id != 0) {
+ // Re-emit clicked signals as response signals
+ button->signal_clicked().connect(sigc::bind(_signal_response.make_slot(), response_id));
+ _response_map[response_id] = button;
+ }
+}
+
+void
+Panel::setDefaultResponse(int response_id)
+{
+ ResponseMap::iterator widget_found;
+ widget_found = _response_map.find(response_id);
+
+ if (widget_found != _response_map.end()) {
+ widget_found->second->activate();
+ widget_found->second->property_can_default() = true;
+ widget_found->second->grab_default();
+ }
+}
+
+void
+Panel::setResponseSensitive(int response_id, bool setting)
+{
+ if (_response_map[response_id])
+ _response_map[response_id]->set_sensitive(setting);
+}
+
+void
+Panel::_handleResponse(int response_id)
+{
+ switch (response_id) {
+ case Gtk::RESPONSE_APPLY: {
+ _apply();
+ break;
+ }
+ }
+}
+
+Inkscape::Selection *Panel::_getSelection()
+{
+ return sp_desktop_selection(SP_ACTIVE_DESKTOP);
+}
+
} // namespace Widget
} // namespace UI
} // namespace Inkscape
diff --git a/src/ui/widget/panel.h b/src/ui/widget/panel.h
index e091c82a1..10f74cf2b 100644
--- a/src/ui/widget/panel.h
+++ b/src/ui/widget/panel.h
@@ -17,64 +17,107 @@
#include <vector>
#include <gtkmm/arrow.h>
#include <gtkmm/box.h>
+#include <gtkmm/button.h>
+#include <gtkmm/buttonbox.h>
#include <gtkmm/eventbox.h>
#include <gtkmm/frame.h>
-#include <gtkmm/table.h>
-#include <gtkmm/button.h>
#include <gtkmm/label.h>
#include <gtkmm/menu.h>
#include <gtkmm/optionmenu.h>
-#include "../previewfillable.h"
+#include <gtkmm/table.h>
+#include <gtkmm/tooltips.h>
+
+#include "ui/previewfillable.h"
+#include "selection.h"
namespace Inkscape {
namespace UI {
namespace Widget {
-class Panel : public Gtk::VBox
-{
+class Panel : public Gtk::VBox {
+
public:
- Panel();
virtual ~Panel();
- Panel(Glib::ustring const &label, gchar const *prefs_path = 0, bool menuDesired = false );
+ Panel(Glib::ustring const &label = "", gchar const *prefs_path = 0,
+ int verb_num = 0, Glib::ustring const &apply_label = "",
+ bool menu_desired = false);
+ gchar const *getPrefsPath() const;
void setLabel(Glib::ustring const &label);
Glib::ustring const &getLabel() const;
+ int const &getVerb() const;
+ Glib::ustring const &getApplyLabel() const;
- virtual void setOrientation( Gtk::AnchorType how );
+ virtual void setOrientation(Gtk::AnchorType how);
+
+ virtual void present(); //< request to be present
- const gchar *_prefs_path;
void restorePanelPrefs();
+ /** Signal accessors */
+ virtual sigc::signal<void, int> &signalResponse();
+ virtual sigc::signal<void> &signalPresent();
+
+ /** Methods providing a Gtk::Dialog like interface for adding buttons that emit Gtk::RESPONSE
+ * signals on click. */
+ Gtk::Button* addResponseButton (const Glib::ustring &button_text, int response_id);
+ Gtk::Button* addResponseButton (const Gtk::StockID &stock_id, int response_id);
+ void setDefaultResponse(int response_id);
+ void setResponseSensitive(int response_id, bool setting);
+
protected:
- Gtk::Box* _getContents() { return &contents; }
- void _setTargetFillable( PreviewFillable *target );
- void _regItem( Gtk::MenuItem* item, int group, int id );
+ Gtk::Box *_getContents() { return &_contents; }
+ void _setTargetFillable(PreviewFillable *target);
+ void _regItem(Gtk::MenuItem* item, int group, int id);
+
+ virtual void _handleAction(int set_id, int item_id);
+ virtual void _apply();
+
+ virtual void _handleResponse(int response_id);
+
+ /** Helper methods */
+ void _addResponseButton(Gtk::Button *button, int response_id);
+ Inkscape::Selection *_getSelection();
- virtual void _handleAction( int setId, int itemId );
- bool _menuDesired;
+ /** Tooltips object for all descendants to use */
+ Gtk::Tooltips _tooltips;
+ const gchar *_prefs_path;
+
+ bool _menu_desired;
Gtk::AnchorType _anchor;
+ /** Signals */
+ sigc::signal<void, int> _signal_response;
+ sigc::signal<void> _signal_present;
+
private:
- void init();
- void bounceCall(int i, int j);
-
- void _popper(GdkEventButton* btn);
- void _wrapToggled(Gtk::CheckMenuItem* toggler);
-
- Glib::ustring label;
-
- Gtk::HBox topBar;
- Gtk::VBox rightBar;
- Gtk::VBox contents;
- Gtk::Label tabTitle;
- Gtk::Arrow _tempArrow;
- Gtk::EventBox menuPopper;
- Gtk::Button closeButton;
- Gtk::Menu* menu;
- std::vector<Gtk::Widget*> nonHorizontal;
- std::vector<Gtk::Widget*> nonVertical;
+ void _init();
+ void _bounceCall(int i, int j);
+
+ void _popper(GdkEventButton *btn);
+ void _wrapToggled(Gtk::CheckMenuItem *toggler);
+
+ Glib::ustring _label;
+ Glib::ustring _apply_label;
+ int _verb_num;
+
+ Gtk::HBox _top_bar;
+ Gtk::VBox _right_bar;
+ Gtk::VBox _contents;
+ Gtk::Label _tab_title;
+ Gtk::Arrow _temp_arrow;
+ Gtk::EventBox _menu_popper;
+ Gtk::Button _close_button;
+ Gtk::Menu *_menu;
+ Gtk::HButtonBox *_action_area; //< stores response buttons
+ std::vector<Gtk::Widget *> _non_horizontal;
+ std::vector<Gtk::Widget *> _non_vertical;
PreviewFillable *_fillable;
+
+ /** A map to store which widget that emits a certain response signal */
+ typedef std::map<int, Gtk::Widget *> ResponseMap;
+ ResponseMap _response_map;
};
} // namespace Widget
diff --git a/src/ui/widget/selected-style.cpp b/src/ui/widget/selected-style.cpp
index cbba0b1e8..20838ee22 100644
--- a/src/ui/widget/selected-style.cpp
+++ b/src/ui/widget/selected-style.cpp
@@ -29,6 +29,7 @@
#include "sp-pattern.h"
#include "ui/dialog/dialog-manager.h"
#include "ui/dialog/fill-and-stroke.h"
+#include "ui/dialog/panel-dialog.h"
#include "xml/repr.h"
#include "document.h"
#include "widgets/widget-sizes.h"
@@ -92,6 +93,8 @@ static GtkTargetEntry ui_drop_target_entries [] = {
#define ENTRIES_SIZE(n) sizeof(n)/sizeof(n[0])
static guint nui_drop_target_entries = ENTRIES_SIZE(ui_drop_target_entries);
+/* convenience function */
+static Dialog::FillAndStroke *get_fill_and_stroke_panel(SPDesktop *desktop);
SelectedStyle::SelectedStyle(bool /*layout*/)
: _desktop (NULL),
@@ -773,15 +776,13 @@ void SelectedStyle::on_fillstroke_swap() {
}
void SelectedStyle::on_fill_edit() {
- if (Dialog::FillAndStroke *dialog = dynamic_cast<Dialog::FillAndStroke *>(
- _desktop->_dlg_mgr->getDialog("FillAndStroke")))
- dialog->showPageFill();
+ if (Dialog::FillAndStroke *fs = get_fill_and_stroke_panel(_desktop))
+ fs->showPageFill();
}
void SelectedStyle::on_stroke_edit() {
- if (Dialog::FillAndStroke *dialog = dynamic_cast<Dialog::FillAndStroke *>(
- _desktop->_dlg_mgr->getDialog("FillAndStroke")))
- dialog->showPageStrokePaint();
+ if (Dialog::FillAndStroke *fs = get_fill_and_stroke_panel(_desktop))
+ fs->showPageStrokePaint();
}
bool
@@ -789,9 +790,8 @@ SelectedStyle::on_fill_click(GdkEventButton *event)
{
if (event->button == 1) { // click, open fill&stroke
- if (Dialog::FillAndStroke *dialog = dynamic_cast<Dialog::FillAndStroke *>(
- _desktop->_dlg_mgr->getDialog("FillAndStroke")))
- dialog->showPageFill();
+ if (Dialog::FillAndStroke *fs = get_fill_and_stroke_panel(_desktop))
+ fs->showPageFill();
} else if (event->button == 3) { // right-click, popup menu
_popup[SS_FILL].popup(event->button, event->time);
@@ -809,9 +809,8 @@ bool
SelectedStyle::on_stroke_click(GdkEventButton *event)
{
if (event->button == 1) { // click, open fill&stroke
- if (Dialog::FillAndStroke *dialog = dynamic_cast<Dialog::FillAndStroke *>(
- _desktop->_dlg_mgr->getDialog("FillAndStroke")))
- dialog->showPageStrokePaint();
+ if (Dialog::FillAndStroke *fs = get_fill_and_stroke_panel(_desktop))
+ fs->showPageStrokePaint();
} else if (event->button == 3) { // right-click, popup menu
_popup[SS_STROKE].popup(event->button, event->time);
} else if (event->button == 2) { // middle click, toggle none/lastcolor
@@ -828,9 +827,8 @@ bool
SelectedStyle::on_sw_click(GdkEventButton *event)
{
if (event->button == 1) { // click, open fill&stroke
- if (Dialog::FillAndStroke *dialog = dynamic_cast<Dialog::FillAndStroke *>(
- _desktop->_dlg_mgr->getDialog("FillAndStroke")))
- dialog->showPageStrokeStyle();
+ if (Dialog::FillAndStroke *fs = get_fill_and_stroke_panel(_desktop))
+ fs->showPageStrokeStyle();
} else if (event->button == 3) { // right-click, popup menu
_popup_sw.popup(event->button, event->time);
} else if (event->button == 2) { // middle click, toggle none/lastwidth?
@@ -1322,6 +1320,19 @@ RotateableSwatch::do_release(double by, guint modifier) {
startcolor_set = false;
}
+Dialog::FillAndStroke *get_fill_and_stroke_panel(SPDesktop *desktop)
+{
+ if (Dialog::PanelDialogBase *panel_dialog =
+ dynamic_cast<Dialog::PanelDialogBase *>(desktop->_dlg_mgr->getDialog("FillAndStroke"))) {
+ try {
+ Dialog::FillAndStroke &fill_and_stroke =
+ dynamic_cast<Dialog::FillAndStroke &>(panel_dialog->getPanel());
+ return &fill_and_stroke;
+ } catch (std::exception e) { }
+ }
+
+ return 0;
+}
} // namespace Widget
} // namespace UI