From 2a3581c9a5e6d18b3cd0ea2fe523063a116af8f8 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Mon, 2 May 2016 09:47:14 +0200 Subject: Working on clip erase basic work done but broken (bzr r14865.1.1) --- src/widgets/eraser-toolbar.cpp | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/eraser-toolbar.cpp b/src/widgets/eraser-toolbar.cpp index 45989936f..5b883905b 100644 --- a/src/widgets/eraser-toolbar.cpp +++ b/src/widgets/eraser-toolbar.cpp @@ -67,15 +67,15 @@ static void sp_erc_mass_value_changed( GtkAdjustment *adj, GObject* tbl ) static void sp_erasertb_mode_changed( EgeSelectOneAction *act, GObject *tbl ) { SPDesktop *desktop = static_cast(g_object_get_data( tbl, "desktop" )); - bool eraserMode = ege_select_one_action_get_active( act ) != 0; + guint eraser_mode = ege_select_one_action_get_active( act ); if (DocumentUndo::getUndoSensitive(desktop->getDocument())) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setBool( "/tools/eraser/mode", eraserMode ); + prefs->setInt( "/tools/eraser/mode", eraser_mode ); } GtkAction *split = GTK_ACTION( g_object_get_data(tbl, "split") ); GtkAction *mass = GTK_ACTION( g_object_get_data(tbl, "mass") ); GtkAction *width = GTK_ACTION( g_object_get_data(tbl, "width") ); - if(eraserMode == TRUE){ + if(eraser_mode != 0){ gtk_action_set_visible( split, TRUE ); gtk_action_set_visible( mass, TRUE ); gtk_action_set_visible( width, TRUE ); @@ -90,7 +90,7 @@ static void sp_erasertb_mode_changed( EgeSelectOneAction *act, GObject *tbl ) g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) ); /* - if ( eraserMode != 0 ) { + if ( eraser_mode != 0 ) { } else { } */ @@ -111,7 +111,7 @@ void sp_eraser_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb { Inkscape::IconSize secondarySize = ToolboxFactory::prefToSize("/toolbox/secondary", 1); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - gint eraserMode = FALSE; + gint eraser_mode = FALSE; { GtkListStore* model = gtk_list_store_new( 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING ); GtkTreeIter iter; @@ -125,10 +125,17 @@ void sp_eraser_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb gtk_list_store_append( model, &iter ); gtk_list_store_set( model, &iter, 0, _("Cut"), - 1, _("Cut out from objects"), + 1, _("Cut out from paths and shapes"), 2, INKSCAPE_ICON("path-difference"), -1 ); + gtk_list_store_append( model, &iter ); + gtk_list_store_set( model, &iter, + 0, _("Clip"), + 1, _("Clip from objects"), + 2, INKSCAPE_ICON("path-intersection"), + -1 ); + EgeSelectOneAction* act = ege_select_one_action_new( "EraserModeAction", (""), (""), NULL, GTK_TREE_MODEL(model) ); g_object_set( act, "short_label", _("Mode:"), NULL ); gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); @@ -137,12 +144,13 @@ void sp_eraser_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb ege_select_one_action_set_appearance( act, "full" ); ege_select_one_action_set_radio_action_type( act, INK_RADIO_ACTION_TYPE ); g_object_set( G_OBJECT(act), "icon-property", "iconId", NULL ); - ege_select_one_action_set_icon_column( act, 2 ); - ege_select_one_action_set_tooltip_column( act, 1 ); + ege_select_one_action_set_icon_column( act, 2); + ege_select_one_action_set_icon_size( act, secondarySize ); + ege_select_one_action_set_tooltip_column( act, 1); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - eraserMode = prefs->getBool("/tools/eraser/mode") ? TRUE : FALSE; - ege_select_one_action_set_active( act, eraserMode ); + eraser_mode = prefs->getInt("/tools/eraser/mode", 2); + ege_select_one_action_set_active( act, eraser_mode ); g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(sp_erasertb_mode_changed), holder ); } @@ -195,7 +203,7 @@ void sp_eraser_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb GtkAction *split = GTK_ACTION( g_object_get_data(holder, "split") ); GtkAction *mass = GTK_ACTION( g_object_get_data(holder, "mass") ); GtkAction *width = GTK_ACTION( g_object_get_data(holder, "width") ); - if(eraserMode == TRUE){ + if (eraser_mode != 0) { gtk_action_set_visible( split, TRUE ); gtk_action_set_visible( mass, TRUE ); gtk_action_set_visible( width, TRUE ); -- cgit v1.2.3 From 331336b5f924ad3200a343f571178e19b55532a1 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 22 May 2016 04:13:59 +0200 Subject: Clip eraser done! Thanks Doctormon! (bzr r14865.1.9) --- src/widgets/eraser-toolbar.cpp | 12 ++++++++++-- src/widgets/toolbox.cpp | 3 ++- 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/eraser-toolbar.cpp b/src/widgets/eraser-toolbar.cpp index f69ac633f..482075dc6 100644 --- a/src/widgets/eraser-toolbar.cpp +++ b/src/widgets/eraser-toolbar.cpp @@ -76,7 +76,11 @@ static void sp_erasertb_mode_changed( EgeSelectOneAction *act, GObject *tbl ) GtkAction *mass = GTK_ACTION( g_object_get_data(tbl, "mass") ); GtkAction *width = GTK_ACTION( g_object_get_data(tbl, "width") ); if(eraser_mode != 0){ - gtk_action_set_visible( split, TRUE ); + if(eraser_mode == 1) { + gtk_action_set_visible( split, TRUE ); + } else { + gtk_action_set_visible( split, FALSE ); + } gtk_action_set_visible( mass, TRUE ); gtk_action_set_visible( width, TRUE ); } else { @@ -204,7 +208,11 @@ void sp_eraser_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb GtkAction *mass = GTK_ACTION( g_object_get_data(holder, "mass") ); GtkAction *width = GTK_ACTION( g_object_get_data(holder, "width") ); if (eraser_mode != 0) { - gtk_action_set_visible( split, TRUE ); + if(eraser_mode == 1) { + gtk_action_set_visible( split, TRUE ); + } else { + gtk_action_set_visible( split, FALSE ); + } gtk_action_set_visible( mass, TRUE ); gtk_action_set_visible( width, TRUE ); } else { diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index f7b5e585f..8113c9619 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -499,9 +499,10 @@ static gchar const * ui_descr = " " " " " " - " " " " " " + " " + " " " " " " -- cgit v1.2.3 From d7887bf24bbb703739e56fa9056e1c67d8483b4c Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sun, 22 May 2016 20:44:21 +0200 Subject: Added some widgets from caligraphic tool (bzr r14865.1.13) --- src/widgets/eraser-toolbar.cpp | 113 ++++++++++++++++++++++++++++++++++++++++- src/widgets/toolbox.cpp | 7 +++ 2 files changed, 119 insertions(+), 1 deletion(-) (limited to 'src/widgets') diff --git a/src/widgets/eraser-toolbar.cpp b/src/widgets/eraser-toolbar.cpp index 482075dc6..ddfe31d72 100644 --- a/src/widgets/eraser-toolbar.cpp +++ b/src/widgets/eraser-toolbar.cpp @@ -64,6 +64,28 @@ static void sp_erc_mass_value_changed( GtkAdjustment *adj, GObject* tbl ) update_presets_list(tbl); } +static void sp_erc_velthin_value_changed( GtkAdjustment *adj, GObject* tbl ) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setDouble("/tools/eraser/thinning", gtk_adjustment_get_value(adj) ); + update_presets_list(tbl); +} + +static void sp_erc_cap_rounding_value_changed( GtkAdjustment *adj, GObject* tbl ) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setDouble( "/tools/eraser/cap_rounding", gtk_adjustment_get_value(adj) ); + update_presets_list(tbl); +} + +static void sp_erc_tremor_value_changed( GtkAdjustment *adj, GObject* tbl ) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setDouble( "/tools/eraser/tremor", gtk_adjustment_get_value(adj) ); + update_presets_list(tbl); +} + + static void sp_erasertb_mode_changed( EgeSelectOneAction *act, GObject *tbl ) { SPDesktop *desktop = static_cast(g_object_get_data( tbl, "desktop" )); @@ -75,15 +97,27 @@ static void sp_erasertb_mode_changed( EgeSelectOneAction *act, GObject *tbl ) GtkAction *split = GTK_ACTION( g_object_get_data(tbl, "split") ); GtkAction *mass = GTK_ACTION( g_object_get_data(tbl, "mass") ); GtkAction *width = GTK_ACTION( g_object_get_data(tbl, "width") ); - if(eraser_mode != 0){ + GtkAction *usepressure = GTK_ACTION( g_object_get_data(tbl, "usepressure") ); + GtkAction *cap_rounding = GTK_ACTION( g_object_get_data(tbl, "cap_rounding") ); + GtkAction *thinning = GTK_ACTION( g_object_get_data(tbl, "thinning") ); + GtkAction *tremor = GTK_ACTION( g_object_get_data(tbl, "tremor") ); + if (eraser_mode != 0) { if(eraser_mode == 1) { gtk_action_set_visible( split, TRUE ); } else { gtk_action_set_visible( split, FALSE ); } + gtk_action_set_visible(usepressure, TRUE ); + gtk_action_set_visible(tremor, TRUE ); + gtk_action_set_visible(cap_rounding, TRUE ); + gtk_action_set_visible(thinning, TRUE ); gtk_action_set_visible( mass, TRUE ); gtk_action_set_visible( width, TRUE ); } else { + gtk_action_set_visible(usepressure, FALSE ); + gtk_action_set_visible(tremor, FALSE ); + gtk_action_set_visible(cap_rounding, FALSE ); + gtk_action_set_visible(thinning, FALSE ); gtk_action_set_visible( split, FALSE ); gtk_action_set_visible( mass, FALSE ); gtk_action_set_visible( width, FALSE ); @@ -175,6 +209,71 @@ void sp_eraser_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb g_object_set_data( holder, "width", eact ); gtk_action_set_sensitive( GTK_ACTION(eact), TRUE ); } + /* Use Pressure button */ + { + InkToggleAction* act = ink_toggle_action_new( "EraserPressureAction", + _("Eraser Pressure"), + _("Use the pressure of the input device to alter the width of the pen"), + INKSCAPE_ICON("draw-use-pressure"), + Inkscape::ICON_SIZE_DECORATION ); + gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); + PrefPusher *pusher = new PrefPusher(GTK_TOGGLE_ACTION(act), "/tools/eraser/usepressure", update_presets_list, holder); + g_signal_connect( holder, "destroy", G_CALLBACK(delete_prefspusher), pusher); + g_object_set_data( holder, "usepressure", act ); + } + { + + /* Thinning */ + gchar const* labels[] = {_("(speed blows up stroke)"), 0, 0, _("(slight widening)"), _("(constant width)"), _("(slight thinning, default)"), 0, 0, _("(speed deflates stroke)")}; + gdouble values[] = {-100, -40, -20, -10, 0, 10, 20, 40, 100}; + EgeAdjustmentAction* eact = create_adjustment_action( "EraserThinningAction", + _("Eraser Stroke Thinning"), _("Thinning:"), + _("How much velocity thins the stroke (> 0 makes fast strokes thinner, < 0 makes them broader, 0 makes width independent of velocity)"), + "/tools/eraser/thinning", 10, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, + -100, 100, 1, 10.0, + labels, values, G_N_ELEMENTS(labels), + sp_erc_velthin_value_changed, NULL /*unit tracker*/, 1, 0); + gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); + g_object_set_data( holder, "thinning", eact ); + gtk_action_set_sensitive( GTK_ACTION(eact), TRUE ); + } + { + /* Cap Rounding */ + gchar const* labels[] = {_("(blunt caps, default)"), _("(slightly bulging)"), 0, 0, _("(approximately round)"), _("(long protruding caps)")}; + gdouble values[] = {0, 0.3, 0.5, 1.0, 1.4, 5.0}; + // TRANSLATORS: "cap" means "end" (both start and finish) here + EgeAdjustmentAction* eact = create_adjustment_action( "EraserCapRoundingAction", + _("Eraser Cap rounding"), _("Caps:"), + _("Increase to make caps at the ends of strokes protrude more (0 = no caps, 1 = round caps)"), + "/tools/eraser/cap_rounding", 0.0, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, + 0.0, 5.0, 0.01, 0.1, + labels, values, G_N_ELEMENTS(labels), + sp_erc_cap_rounding_value_changed, NULL /*unit tracker*/, 0.01, 2 ); + gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); + g_object_set_data( holder, "cap_rounding", eact ); + gtk_action_set_sensitive( GTK_ACTION(eact), TRUE ); + } + + { + /* Tremor */ + gchar const* labels[] = {_("(smooth line)"), _("(slight tremor)"), _("(noticeable tremor)"), 0, 0, _("(maximum tremor)")}; + gdouble values[] = {0, 10, 20, 40, 60, 100}; + EgeAdjustmentAction* eact = create_adjustment_action( "EraserTremorAction", + _("EraserStroke Tremor"), _("Tremor:"), + _("Increase to make strokes rugged and trembling"), + "/tools/eraser/tremor", 0.0, + GTK_WIDGET(desktop->canvas), holder, FALSE, NULL, + 0.0, 100, 1, 10.0, + labels, values, G_N_ELEMENTS(labels), + sp_erc_tremor_value_changed, NULL /*unit tracker*/, 1, 0); + + ege_adjustment_action_set_appearance( eact, TOOLBAR_SLIDER_HINT ); + g_object_set_data( holder, "tremor", eact ); + gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); + gtk_action_set_sensitive( GTK_ACTION(eact), TRUE ); + } { /* Mass */ gchar const* labels[] = {_("(no inertia)"), _("(slight smoothing, default)"), _("(noticeable lagging)"), 0, 0, _("(maximum inertia)")}; @@ -207,15 +306,27 @@ void sp_eraser_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb GtkAction *split = GTK_ACTION( g_object_get_data(holder, "split") ); GtkAction *mass = GTK_ACTION( g_object_get_data(holder, "mass") ); GtkAction *width = GTK_ACTION( g_object_get_data(holder, "width") ); + GtkAction *usepressure = GTK_ACTION( g_object_get_data(holder, "usepressure") ); + GtkAction *cap_rounding = GTK_ACTION( g_object_get_data(holder, "cap_rounding") ); + GtkAction *thinning = GTK_ACTION( g_object_get_data(holder, "thinning") ); + GtkAction *tremor = GTK_ACTION( g_object_get_data(holder, "tremor") ); if (eraser_mode != 0) { if(eraser_mode == 1) { gtk_action_set_visible( split, TRUE ); } else { gtk_action_set_visible( split, FALSE ); } + gtk_action_set_visible(usepressure, TRUE ); + gtk_action_set_visible(tremor, TRUE ); + gtk_action_set_visible(cap_rounding, TRUE ); + gtk_action_set_visible(thinning, TRUE ); gtk_action_set_visible( mass, TRUE ); gtk_action_set_visible( width, TRUE ); } else { + gtk_action_set_visible(usepressure, FALSE ); + gtk_action_set_visible(tremor, FALSE ); + gtk_action_set_visible(cap_rounding, FALSE ); + gtk_action_set_visible(thinning, FALSE ); gtk_action_set_visible( split, FALSE ); gtk_action_set_visible( mass, FALSE ); gtk_action_set_visible( width, FALSE ); diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 8113c9619..52b31e4c5 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -499,6 +499,13 @@ static gchar const * ui_descr = " " " " " " + " " + " " + " " + " " + " " + " " + " " " " " " " " -- cgit v1.2.3 From 1636c1dd1651780d01759676b194312529f211f7 Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Sat, 25 Jun 2016 22:24:26 +0200 Subject: Moved next functions, added namespace, renamed range functions (bzr r14954.1.10) --- src/widgets/arc-toolbar.cpp | 8 ++++---- src/widgets/connector-toolbar.cpp | 6 +++--- src/widgets/fill-style.cpp | 2 +- src/widgets/gradient-toolbar.cpp | 6 +++--- src/widgets/mesh-toolbar.cpp | 4 ++-- src/widgets/pencil-toolbar.cpp | 4 ++-- src/widgets/rect-toolbar.cpp | 4 ++-- src/widgets/spiral-toolbar.cpp | 4 ++-- src/widgets/star-toolbar.cpp | 12 ++++++------ src/widgets/stroke-style.cpp | 6 +++--- src/widgets/text-toolbar.cpp | 8 ++++---- 11 files changed, 32 insertions(+), 32 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/arc-toolbar.cpp b/src/widgets/arc-toolbar.cpp index 7b872e8b1..5db714f85 100644 --- a/src/widgets/arc-toolbar.cpp +++ b/src/widgets/arc-toolbar.cpp @@ -97,7 +97,7 @@ sp_arctb_startend_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const *v gchar* namespaced_name = g_strconcat("sodipodi:", value_name, NULL); bool modmade = false; - std::vector itemlist=desktop->getSelection()->itemList(); + std::vector itemlist= desktop->getSelection()->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (SP_IS_GENERICELLIPSE(item)) { @@ -163,7 +163,7 @@ static void sp_arctb_open_state_changed( EgeSelectOneAction *act, GObject *tbl ) bool modmade = false; if ( ege_select_one_action_get_active(act) != 0 ) { - std::vector itemlist=desktop->getSelection()->itemList(); + std::vector itemlist= desktop->getSelection()->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (SP_IS_GENERICELLIPSE(item)) { @@ -174,7 +174,7 @@ static void sp_arctb_open_state_changed( EgeSelectOneAction *act, GObject *tbl ) } } } else { - std::vector itemlist=desktop->getSelection()->itemList(); + std::vector itemlist= desktop->getSelection()->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (SP_IS_GENERICELLIPSE(item)) { @@ -264,7 +264,7 @@ static void sp_arc_toolbox_selection_changed(Inkscape::Selection *selection, GOb purge_repr_listener( tbl, tbl ); - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (SP_IS_GENERICELLIPSE(item)) { diff --git a/src/widgets/connector-toolbar.cpp b/src/widgets/connector-toolbar.cpp index 733fb34e8..54b4be547 100644 --- a/src/widgets/connector-toolbar.cpp +++ b/src/widgets/connector-toolbar.cpp @@ -97,7 +97,7 @@ static void sp_connector_orthogonal_toggled( GtkToggleAction* act, GObject *tbl gchar *value = is_orthog ? orthog_str : polyline_str ; bool modmade = false; - std::vector itemlist=desktop->getSelection()->itemList(); + std::vector itemlist= desktop->getSelection()->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; @@ -144,7 +144,7 @@ static void connector_curvature_changed(GtkAdjustment *adj, GObject* tbl) g_ascii_dtostr(value, G_ASCII_DTOSTR_BUF_SIZE, newValue); bool modmade = false; - std::vector itemlist=desktop->getSelection()->itemList(); + std::vector itemlist= desktop->getSelection()->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; @@ -227,7 +227,7 @@ static void sp_connector_graph_layout(void) int saved_compensation = prefs->getInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED); prefs->setInt("/options/clonecompensation/value", SP_CLONE_COMPENSATION_UNMOVED); - graphlayout(SP_ACTIVE_DESKTOP->getSelection()->itemList()); + graphlayout(SP_ACTIVE_DESKTOP->getSelection()->items()); prefs->setInt("/options/clonecompensation/value", saved_compensation); diff --git a/src/widgets/fill-style.cpp b/src/widgets/fill-style.cpp index a96776894..8c3a0a0a8 100644 --- a/src/widgets/fill-style.cpp +++ b/src/widgets/fill-style.cpp @@ -476,7 +476,7 @@ void FillNStroke::updateFromPaint() SPDocument *document = desktop->getDocument(); Inkscape::Selection *selection = desktop->getSelection(); - std::vector const items = selection->itemList(); + std::vector const items = selection->items(); switch (psel->mode) { case SPPaintSelector::MODE_EMPTY: diff --git a/src/widgets/gradient-toolbar.cpp b/src/widgets/gradient-toolbar.cpp index a44e9962e..ab345b73f 100644 --- a/src/widgets/gradient-toolbar.cpp +++ b/src/widgets/gradient-toolbar.cpp @@ -116,7 +116,7 @@ void gr_apply_gradient(Inkscape::Selection *selection, GrDrag *drag, SPGradient } // If no drag or no dragger selected, act on selection - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ gr_apply_gradient_to_item(*i, gr, initialType, initialMode, initialMode); } @@ -216,7 +216,7 @@ void gr_get_dt_selected_gradient(Inkscape::Selection *selection, SPGradient *&gr { SPGradient *gradient = 0; - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i;// get the items gradient, not the getVector() version SPStyle *style = item->style; @@ -284,7 +284,7 @@ void gr_read_selection( Inkscape::Selection *selection, } // If no selected dragger, read desktop selection - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; SPStyle *style = item->style; diff --git a/src/widgets/mesh-toolbar.cpp b/src/widgets/mesh-toolbar.cpp index 3643ce00c..5d326253c 100644 --- a/src/widgets/mesh-toolbar.cpp +++ b/src/widgets/mesh-toolbar.cpp @@ -89,7 +89,7 @@ void ms_read_selection( Inkscape::Selection *selection, bool first = true; ms_type = SP_MESH_TYPE_COONS; - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; SPStyle *style = item->style; @@ -216,7 +216,7 @@ void ms_get_dt_selected_gradient(Inkscape::Selection *selection, SPMesh *&ms_sel { SPMesh *gradient = 0; - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i;// get the items gradient, not the getVector() version SPStyle *style = item->style; diff --git a/src/widgets/pencil-toolbar.cpp b/src/widgets/pencil-toolbar.cpp index 55127206c..34cebbe1b 100644 --- a/src/widgets/pencil-toolbar.cpp +++ b/src/widgets/pencil-toolbar.cpp @@ -240,7 +240,7 @@ static void sp_pencil_tb_defaults(GtkWidget * /*widget*/, GObject *obj) static void sp_simplify_flatten(GtkWidget * /*widget*/, GObject *obj) { SPDesktop *desktop = static_cast(g_object_get_data(obj, "desktop")); - std::vector selected = desktop->getSelection()->itemList(); + std::vector selected = desktop->getSelection()->items(); for (std::vector::iterator it(selected.begin()); it != selected.end(); ++it){ SPLPEItem* lpeitem = dynamic_cast(*it); if (lpeitem && lpeitem->hasPathEffect()){ @@ -285,7 +285,7 @@ static void sp_pencil_tb_tolerance_value_changed(GtkAdjustment *adj, GObject *tb gtk_adjustment_get_value(adj)); g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); SPDesktop *desktop = static_cast(g_object_get_data(tbl, "desktop")); - std::vector selected = desktop->getSelection()->itemList(); + std::vector selected = desktop->getSelection()->items(); for (std::vector::iterator it(selected.begin()); it != selected.end(); ++it){ SPLPEItem* lpeitem = dynamic_cast(*it); if (lpeitem && lpeitem->hasPathEffect()){ diff --git a/src/widgets/rect-toolbar.cpp b/src/widgets/rect-toolbar.cpp index bc27d003c..2ee38608b 100644 --- a/src/widgets/rect-toolbar.cpp +++ b/src/widgets/rect-toolbar.cpp @@ -106,7 +106,7 @@ static void sp_rtb_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const * bool modmade = false; Inkscape::Selection *selection = desktop->getSelection(); - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ if (SP_IS_RECT(*i)) { if (gtk_adjustment_get_value(adj) != 0) { @@ -243,7 +243,7 @@ static void sp_rect_toolbox_selection_changed(Inkscape::Selection *selection, GO } purge_repr_listener( tbl, tbl ); - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ if (SP_IS_RECT(*i)) { n_selected++; diff --git a/src/widgets/spiral-toolbar.cpp b/src/widgets/spiral-toolbar.cpp index 7e7398091..8f5f10bf8 100644 --- a/src/widgets/spiral-toolbar.cpp +++ b/src/widgets/spiral-toolbar.cpp @@ -79,7 +79,7 @@ static void sp_spl_tb_value_changed(GtkAdjustment *adj, GObject *tbl, Glib::ustr gchar* namespaced_name = g_strconcat("sodipodi:", value_name.data(), NULL); bool modmade = false; - std::vector itemlist=desktop->getSelection()->itemList(); + std::vector itemlist= desktop->getSelection()->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end(); ++i){ SPItem *item = *i; if (SP_IS_SPIRAL(item)) { @@ -195,7 +195,7 @@ static void sp_spiral_toolbox_selection_changed(Inkscape::Selection *selection, purge_repr_listener( tbl, tbl ); - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end(); ++i){ SPItem *item = *i; if (SP_IS_SPIRAL(item)) { diff --git a/src/widgets/star-toolbar.cpp b/src/widgets/star-toolbar.cpp index 982a3c854..fc8757162 100644 --- a/src/widgets/star-toolbar.cpp +++ b/src/widgets/star-toolbar.cpp @@ -83,7 +83,7 @@ static void sp_stb_magnitude_value_changed( GtkAdjustment *adj, GObject *dataKlu bool modmade = false; Inkscape::Selection *selection = desktop->getSelection(); - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (SP_IS_STAR(item)) { @@ -128,7 +128,7 @@ static void sp_stb_proportion_value_changed( GtkAdjustment *adj, GObject *dataKl bool modmade = false; Inkscape::Selection *selection = desktop->getSelection(); - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (SP_IS_STAR(item)) { @@ -185,7 +185,7 @@ static void sp_stb_sides_flat_state_changed( EgeSelectOneAction *act, GObject *d gtk_action_set_visible( prop_action, !flat ); } - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (SP_IS_STAR(item)) { @@ -224,7 +224,7 @@ static void sp_stb_rounded_value_changed( GtkAdjustment *adj, GObject *dataKludg bool modmade = false; Inkscape::Selection *selection = desktop->getSelection(); - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (SP_IS_STAR(item)) { @@ -264,7 +264,7 @@ static void sp_stb_randomized_value_changed( GtkAdjustment *adj, GObject *dataKl bool modmade = false; Inkscape::Selection *selection = desktop->getSelection(); - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (SP_IS_STAR(item)) { @@ -367,7 +367,7 @@ sp_star_toolbox_selection_changed(Inkscape::Selection *selection, GObject *tbl) purge_repr_listener( tbl, tbl ); - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (SP_IS_STAR(item)) { diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp index 84a6e77ad..7ed2c3180 100644 --- a/src/widgets/stroke-style.cpp +++ b/src/widgets/stroke-style.cpp @@ -515,7 +515,7 @@ void StrokeStyle::markerSelectCB(MarkerComboBox *marker_combo, StrokeStyle *spw, //spw->updateMarkerHist(which); Inkscape::Selection *selection = spw->desktop->getSelection(); - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (!SP_IS_SHAPE(item) || SP_IS_RECT(item)) { // can't set marker to rect, until it's converted to using @@ -988,7 +988,7 @@ StrokeStyle::updateLine() if (!sel || sel->isEmpty()) return; - std::vector const objects = sel->itemList(); + std::vector const objects = sel->items(); SPObject * const object = objects[0]; SPStyle * const style = object->style; @@ -1044,7 +1044,7 @@ StrokeStyle::scaleLine() SPDocument *document = desktop->getDocument(); Inkscape::Selection *selection = desktop->getSelection(); - std::vector items=selection->itemList(); + std::vector items= selection->items(); /* TODO: Create some standardized method */ SPCSSAttr *css = sp_repr_css_attr_new(); diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index 23acb74af..3d08b04f1 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -378,7 +378,7 @@ static void sp_text_align_mode_changed( EgeSelectOneAction *act, GObject *tbl ) // move the x of all texts to preserve the same bbox Inkscape::Selection *selection = desktop->getSelection(); - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end(); ++i){ if (SP_IS_TEXT(*i)) { SPItem *item = *i; @@ -560,7 +560,7 @@ static void sp_text_lineheight_value_changed( GtkAdjustment *adj, GObject *tbl ) // Only need to save for undo if a text item has been changed. Inkscape::Selection *selection = desktop->getSelection(); bool modmade = false; - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end(); ++i){ if (SP_IS_TEXT (*i)) { modmade = true; @@ -625,7 +625,7 @@ static void sp_text_lineheight_unit_changed( gpointer /* */, GObject *tbl ) SPDesktop *desktop = SP_ACTIVE_DESKTOP; Inkscape::Selection *selection = desktop->getSelection(); - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); // Convert between units if ((unit->abbr == "" || unit->abbr == "em") && old_unit == SP_CSS_UNIT_EX) { @@ -1120,7 +1120,7 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/ // Only flowed text can be justified, only normal text can be kerned... // Find out if we have flowed text now so we can use it several places gboolean isFlow = false; - std::vector itemlist=SP_ACTIVE_DESKTOP->getSelection()->itemList(); + std::vector itemlist= SP_ACTIVE_DESKTOP->getSelection()->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end(); ++i){ // const gchar* id = reinterpret_cast(items->data)->getId(); // std::cout << " " << id << std::endl; -- cgit v1.2.3 From d1947e768272c703674129d5c583204ff2b59251 Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Wed, 13 Jul 2016 13:36:19 +0200 Subject: Second part of new SPObject children list (bzr r14954.1.19) --- src/widgets/gradient-toolbar.cpp | 12 ++++++------ src/widgets/gradient-vector.cpp | 28 ++++++++++++++-------------- src/widgets/stroke-marker-selector.cpp | 6 +++--- 3 files changed, 23 insertions(+), 23 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/gradient-toolbar.cpp b/src/widgets/gradient-toolbar.cpp index a395d1954..c4b2ed59a 100644 --- a/src/widgets/gradient-toolbar.cpp +++ b/src/widgets/gradient-toolbar.cpp @@ -720,9 +720,9 @@ static void select_stop_by_drag(GtkWidget *combo_box, SPGradient *gradient, Tool static void select_stop_in_list( GtkWidget *combo_box, SPGradient *gradient, SPStop *new_stop, GtkWidget *data, gboolean block) { int i = 0; - for ( SPObject *ochild = gradient->firstChild() ; ochild ; ochild = ochild->getNext() ) { - if (SP_IS_STOP(ochild)) { - if (ochild == new_stop) { + for (auto& ochild: gradient->_children) { + if (SP_IS_STOP(&ochild)) { + if (&ochild == new_stop) { blocked = block; gtk_combo_box_set_active(GTK_COMBO_BOX(combo_box) , i); gr_stop_set_offset(GTK_COMBO_BOX(combo_box), data); @@ -765,9 +765,9 @@ static gboolean update_stop_list( GtkWidget *stop_combo, SPGradient *gradient, S /* Populate the combobox store */ std::vector sl; if ( gradient->hasStops() ) { - for ( SPObject *ochild = gradient->firstChild() ; ochild ; ochild = ochild->getNext() ) { - if (SP_IS_STOP(ochild)) { - sl.push_back(ochild); + for (auto& ochild: gradient->_children) { + if (SP_IS_STOP(&ochild)) { + sl.push_back(&ochild); } } } diff --git a/src/widgets/gradient-vector.cpp b/src/widgets/gradient-vector.cpp index 97e65141f..813a2d28e 100644 --- a/src/widgets/gradient-vector.cpp +++ b/src/widgets/gradient-vector.cpp @@ -363,13 +363,13 @@ unsigned long sp_gradient_to_hhssll(SPGradient *gr) static GSList *get_all_doc_items(GSList *list, SPObject *from, bool onlyvisible, bool onlysensitive, bool ingroups, GSList const *exclude) { - for ( SPObject *child = from->firstChild() ; child; child = child->getNext() ) { - if (SP_IS_ITEM(child)) { - list = g_slist_prepend(list, SP_ITEM(child)); + for (auto& child: from->_children) { + if (SP_IS_ITEM(&child)) { + list = g_slist_prepend(list, SP_ITEM(&child)); } - if (ingroups || SP_IS_ITEM(child)) { - list = get_all_doc_items(list, child, onlyvisible, onlysensitive, ingroups, exclude); + if (ingroups || SP_IS_ITEM(&child)) { + list = get_all_doc_items(list, &child, onlyvisible, onlysensitive, ingroups, exclude); } } @@ -525,10 +525,10 @@ static void verify_grad(SPGradient *gradient) int i = 0; SPStop *stop = NULL; /* count stops */ - for ( SPObject *ochild = gradient->firstChild() ; ochild ; ochild = ochild->getNext() ) { - if (SP_IS_STOP(ochild)) { + for (auto& ochild: gradient->_children) { + if (SP_IS_STOP(&ochild)) { i++; - stop = SP_STOP(ochild); + stop = SP_STOP(&ochild); } } @@ -568,9 +568,9 @@ static void select_stop_in_list( GtkWidget *vb, SPGradient *gradient, SPStop *ne GtkWidget *combo_box = static_cast(g_object_get_data(G_OBJECT(vb), "combo_box")); int i = 0; - for ( SPObject *ochild = gradient->firstChild() ; ochild ; ochild = ochild->getNext() ) { - if (SP_IS_STOP(ochild)) { - if (ochild == new_stop) { + for (auto& ochild: gradient->_children) { + if (SP_IS_STOP(&ochild)) { + if (&ochild == new_stop) { gtk_combo_box_set_active (GTK_COMBO_BOX(combo_box) , i); break; } @@ -603,9 +603,9 @@ static void update_stop_list( GtkWidget *vb, SPGradient *gradient, SPStop *new_s /* Populate the combobox store */ GSList *sl = NULL; if ( gradient->hasStops() ) { - for ( SPObject *ochild = gradient->firstChild() ; ochild ; ochild = ochild->getNext() ) { - if (SP_IS_STOP(ochild)) { - sl = g_slist_append(sl, ochild); + for (auto& ochild: gradient->_children) { + if (SP_IS_STOP(&ochild)) { + sl = g_slist_append(sl, &ochild); } } } diff --git a/src/widgets/stroke-marker-selector.cpp b/src/widgets/stroke-marker-selector.cpp index e273faad7..fd7b5f6cd 100644 --- a/src/widgets/stroke-marker-selector.cpp +++ b/src/widgets/stroke-marker-selector.cpp @@ -335,10 +335,10 @@ GSList *MarkerComboBox::get_marker_list (SPDocument *source) return NULL; } - for ( SPObject *child = defs->firstChild(); child; child = child->getNext() ) + for (auto& child: defs->_children) { - if (SP_IS_MARKER(child)) { - ml = g_slist_prepend (ml, child); + if (SP_IS_MARKER(&child)) { + ml = g_slist_prepend (ml, &child); } } return ml; -- cgit v1.2.3 From 24d3f50003ca3cec6a03a7f5267cc4fe5588c69f Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Thu, 14 Jul 2016 13:17:21 +0200 Subject: Renamed children list in SPObject (bzr r14954.1.21) --- src/widgets/gradient-toolbar.cpp | 4 ++-- src/widgets/gradient-vector.cpp | 8 ++++---- src/widgets/stroke-marker-selector.cpp | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/gradient-toolbar.cpp b/src/widgets/gradient-toolbar.cpp index c4b2ed59a..1565e16f3 100644 --- a/src/widgets/gradient-toolbar.cpp +++ b/src/widgets/gradient-toolbar.cpp @@ -720,7 +720,7 @@ static void select_stop_by_drag(GtkWidget *combo_box, SPGradient *gradient, Tool static void select_stop_in_list( GtkWidget *combo_box, SPGradient *gradient, SPStop *new_stop, GtkWidget *data, gboolean block) { int i = 0; - for (auto& ochild: gradient->_children) { + for (auto& ochild: gradient->children) { if (SP_IS_STOP(&ochild)) { if (&ochild == new_stop) { blocked = block; @@ -765,7 +765,7 @@ static gboolean update_stop_list( GtkWidget *stop_combo, SPGradient *gradient, S /* Populate the combobox store */ std::vector sl; if ( gradient->hasStops() ) { - for (auto& ochild: gradient->_children) { + for (auto& ochild: gradient->children) { if (SP_IS_STOP(&ochild)) { sl.push_back(&ochild); } diff --git a/src/widgets/gradient-vector.cpp b/src/widgets/gradient-vector.cpp index 813a2d28e..5f549a77c 100644 --- a/src/widgets/gradient-vector.cpp +++ b/src/widgets/gradient-vector.cpp @@ -363,7 +363,7 @@ unsigned long sp_gradient_to_hhssll(SPGradient *gr) static GSList *get_all_doc_items(GSList *list, SPObject *from, bool onlyvisible, bool onlysensitive, bool ingroups, GSList const *exclude) { - for (auto& child: from->_children) { + for (auto& child: from->children) { if (SP_IS_ITEM(&child)) { list = g_slist_prepend(list, SP_ITEM(&child)); } @@ -525,7 +525,7 @@ static void verify_grad(SPGradient *gradient) int i = 0; SPStop *stop = NULL; /* count stops */ - for (auto& ochild: gradient->_children) { + for (auto& ochild: gradient->children) { if (SP_IS_STOP(&ochild)) { i++; stop = SP_STOP(&ochild); @@ -568,7 +568,7 @@ static void select_stop_in_list( GtkWidget *vb, SPGradient *gradient, SPStop *ne GtkWidget *combo_box = static_cast(g_object_get_data(G_OBJECT(vb), "combo_box")); int i = 0; - for (auto& ochild: gradient->_children) { + for (auto& ochild: gradient->children) { if (SP_IS_STOP(&ochild)) { if (&ochild == new_stop) { gtk_combo_box_set_active (GTK_COMBO_BOX(combo_box) , i); @@ -603,7 +603,7 @@ static void update_stop_list( GtkWidget *vb, SPGradient *gradient, SPStop *new_s /* Populate the combobox store */ GSList *sl = NULL; if ( gradient->hasStops() ) { - for (auto& ochild: gradient->_children) { + for (auto& ochild: gradient->children) { if (SP_IS_STOP(&ochild)) { sl = g_slist_append(sl, &ochild); } diff --git a/src/widgets/stroke-marker-selector.cpp b/src/widgets/stroke-marker-selector.cpp index fd7b5f6cd..af3f03420 100644 --- a/src/widgets/stroke-marker-selector.cpp +++ b/src/widgets/stroke-marker-selector.cpp @@ -335,7 +335,7 @@ GSList *MarkerComboBox::get_marker_list (SPDocument *source) return NULL; } - for (auto& child: defs->_children) + for (auto& child: defs->children) { if (SP_IS_MARKER(&child)) { ml = g_slist_prepend (ml, &child); -- cgit v1.2.3 From ff4fbbc93f67afd6cbf851691833a50d6c76b350 Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Wed, 27 Jul 2016 12:19:03 +0200 Subject: Renamed some functions, fixed tests (bzr r14954.1.28) --- src/widgets/select-toolbar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/widgets') diff --git a/src/widgets/select-toolbar.cpp b/src/widgets/select-toolbar.cpp index 9851b0606..322c33cc3 100644 --- a/src/widgets/select-toolbar.cpp +++ b/src/widgets/select-toolbar.cpp @@ -257,7 +257,7 @@ sp_object_layout_any_value_changed(GtkAdjustment *adj, GObject *tbl) scaler = get_scale_transform_for_uniform_stroke (*bbox_geom, 0, 0, false, false, x0, y0, x1, y1); } - sp_selection_apply_affine(selection, scaler); + sp_object_set_apply_affine(selection, scaler); DocumentUndo::maybeDone(document, actionkey, SP_VERB_CONTEXT_SELECT, _("Transform by toolbar")); -- cgit v1.2.3 From 3078d10fcf276c0d36975bfd48ef064b46f60b3d Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Wed, 27 Jul 2016 17:21:52 +0100 Subject: Disable GTK+ 2 support and delete internal copy of GDL Fixed bugs: - https://launchpad.net/bugs/1424830 - https://launchpad.net/bugs/1606558 (bzr r15023.2.1) --- src/widgets/CMakeLists.txt | 7 ++----- src/widgets/Makefile_insert | 8 ++------ 2 files changed, 4 insertions(+), 11 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/CMakeLists.txt b/src/widgets/CMakeLists.txt index 225afe317..ba71b39f4 100644 --- a/src/widgets/CMakeLists.txt +++ b/src/widgets/CMakeLists.txt @@ -33,6 +33,7 @@ set(widgets_SRC gradient-toolbar.cpp gradient-vector.cpp icon.cpp + image-menu-item.c ink-action.cpp ink-comboboxentry-action.cpp paint-selector.cpp @@ -88,6 +89,7 @@ set(widgets_SRC gradient-toolbar.h gradient-vector.h icon.h + image-menu-item.h ink-action.h ink-comboboxentry-action.h paint-selector.h @@ -108,11 +110,6 @@ set(widgets_SRC widget-sizes.h ) -if(${WITH_GTK3_EXPERIMENTAL}) - set(image_menu_item_SRC image-menu-item.h image-menu-item.c) - add_inkscape_source("${image_menu_item_SRC}") -endif() - # add_inkscape_lib(widgets_LIB "${widgets_SRC}") add_inkscape_source("${widgets_SRC}") diff --git a/src/widgets/Makefile_insert b/src/widgets/Makefile_insert index c9f04de14..8f10e1d56 100644 --- a/src/widgets/Makefile_insert +++ b/src/widgets/Makefile_insert @@ -1,11 +1,5 @@ ## Makefile.am fragment sourced by src/Makefile.am. -if WITH_GTKMM_3_0 -ink_common_sources += \ - widgets/image-menu-item.c \ - widgets/image-menu-item.h -endif - ink_common_sources += \ widgets/arc-toolbar.cpp \ widgets/arc-toolbar.h \ @@ -50,6 +44,8 @@ ink_common_sources += \ widgets/gradient-vector.h \ widgets/icon.cpp \ widgets/icon.h \ + widgets/image-menu-item.c \ + widgets/image-menu-item.h \ widgets/ink-action.cpp \ widgets/ink-action.h \ widgets/ink-comboboxentry-action.cpp \ -- cgit v1.2.3 From 9e1a6b6cdc87bde1b85137f2841a510283904b71 Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Wed, 27 Jul 2016 17:45:46 +0100 Subject: widgets/ruler: Drop GTK2 fallbacks (bzr r15023.2.4) --- src/widgets/ruler.cpp | 154 -------------------------------------------------- 1 file changed, 154 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/ruler.cpp b/src/widgets/ruler.cpp index deffd384a..92c2b611d 100644 --- a/src/widgets/ruler.cpp +++ b/src/widgets/ruler.cpp @@ -120,7 +120,6 @@ static void sp_ruler_unmap (GtkWidget *widget); static void sp_ruler_size_allocate (GtkWidget *widget, GtkAllocation *allocation); -#if GTK_CHECK_VERSION(3,0,0) static void sp_ruler_get_preferred_width (GtkWidget *widget, gint *minimum_width, gint *natural_width); @@ -129,21 +128,11 @@ static void sp_ruler_get_preferred_height (GtkWidget *widget, gint *minimum_height, gint *natural_height); static void sp_ruler_style_updated (GtkWidget *widget); -#else -static void sp_ruler_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static void sp_ruler_style_set (GtkWidget *widget, - GtkStyle *prev_style); -#endif static gboolean sp_ruler_motion_notify (GtkWidget *widget, GdkEventMotion *event); static gboolean sp_ruler_draw (GtkWidget *widget, cairo_t *cr); -#if !GTK_CHECK_VERSION(3,0,0) -static gboolean sp_ruler_expose (GtkWidget *widget, - GdkEventExpose *event); -#endif static void sp_ruler_draw_ticks (SPRuler *ruler); static GdkRectangle sp_ruler_get_pos_rect (SPRuler *ruler, gdouble position); @@ -181,16 +170,10 @@ sp_ruler_class_init (SPRulerClass *klass) widget_class->map = sp_ruler_map; widget_class->unmap = sp_ruler_unmap; widget_class->size_allocate = sp_ruler_size_allocate; -#if GTK_CHECK_VERSION(3,0,0) widget_class->get_preferred_width = sp_ruler_get_preferred_width; widget_class->get_preferred_height = sp_ruler_get_preferred_height; widget_class->style_updated = sp_ruler_style_updated; widget_class->draw = sp_ruler_draw; -#else - widget_class->size_request = sp_ruler_size_request; - widget_class->style_set = sp_ruler_style_set; - widget_class->expose_event = sp_ruler_expose; -#endif widget_class->motion_notify_event = sp_ruler_motion_notify; g_type_class_add_private (object_class, sizeof (SPRulerPrivate)); @@ -487,16 +470,10 @@ sp_ruler_realize (GtkWidget *widget) attributes.width = allocation.width; attributes.height = allocation.height; attributes.wclass = GDK_INPUT_ONLY; -#if GTK_CHECK_VERSION(3,0,0) attributes.event_mask = (gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK); -#else - attributes.event_mask = (gtk_widget_get_events (widget) | - GDK_EXPOSURE_MASK | - GDK_POINTER_MOTION_MASK); -#endif attributes_mask = GDK_WA_X | GDK_WA_Y; @@ -599,7 +576,6 @@ sp_ruler_size_request (GtkWidget *widget, size = 2 + ink_rect.height * 1.7; -#if GTK_CHECK_VERSION(3,0,0) GtkStyleContext *context = gtk_widget_get_style_context (widget); GtkBorder border; @@ -607,47 +583,25 @@ sp_ruler_size_request (GtkWidget *widget, requisition->width = border.left + border.right; requisition->height = border.top + border.bottom; -#else - GtkStyle *style = gtk_widget_get_style(widget); -#endif if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) { -#if GTK_CHECK_VERSION(3,0,0) requisition->width += 1; requisition->height += size; -#else - requisition->width = style->xthickness * 2 + 1; - requisition->height = style->ythickness * 2 + size; -#endif } else { -#if GTK_CHECK_VERSION(3,0,0) requisition->width += size; requisition->height += 1; -#else - requisition->width = style->xthickness * 2 + size; - requisition->height = style->ythickness * 2 + 1; -#endif } } static void -#if GTK_CHECK_VERSION(3,0,0) sp_ruler_style_updated (GtkWidget *widget) -#else -sp_ruler_style_set (GtkWidget *widget, - GtkStyle *prev_style) -#endif { SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (widget); -#if GTK_CHECK_VERSION(3,0,0) GTK_WIDGET_CLASS (sp_ruler_parent_class)->style_updated (widget); -#else - GTK_WIDGET_CLASS (sp_ruler_parent_class)->style_set (widget, prev_style); -#endif gtk_widget_style_get (widget, "font-scale", &priv->font_scale, @@ -660,7 +614,6 @@ sp_ruler_style_set (GtkWidget *widget, } } -#if GTK_CHECK_VERSION(3,0,0) static void sp_ruler_get_preferred_width (GtkWidget *widget, gint *minimum_width, @@ -684,26 +637,6 @@ sp_ruler_get_preferred_height (GtkWidget *widget, *minimum_height = *natural_height = requisition.height; } -#else -static gboolean -sp_ruler_expose (GtkWidget *widget, - GdkEventExpose *event) -{ - cairo_t *cr = gdk_cairo_create(gtk_widget_get_window(widget)); - GtkAllocation allocation; - - gdk_cairo_region (cr, event->region); - cairo_clip (cr); - - gtk_widget_get_allocation (widget, &allocation); - - gboolean result = sp_ruler_draw (widget, cr); - - cairo_destroy (cr); - - return result; -} -#endif static gboolean sp_ruler_draw (GtkWidget *widget, @@ -749,13 +682,8 @@ sp_ruler_draw_pos (SPRuler *ruler, { GtkWidget *widget = GTK_WIDGET (ruler); -#if GTK_CHECK_VERSION(3,0,0) GtkStyleContext *context = gtk_widget_get_style_context (widget); GdkRGBA color; -#else - GtkStyle *style = gtk_widget_get_style (widget); - GtkStateType state = gtk_widget_get_state (widget); -#endif SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); GdkRectangle pos_rect; @@ -767,13 +695,9 @@ sp_ruler_draw_pos (SPRuler *ruler, if ((pos_rect.width > 0) && (pos_rect.height > 0)) { -#if GTK_CHECK_VERSION(3,0,0) gtk_style_context_get_color (context, gtk_widget_get_state_flags (widget), &color); gdk_cairo_set_source_rgba (cr, &color); -#else - gdk_cairo_set_source_color (cr, &style->fg[state]); -#endif cairo_move_to (cr, pos_rect.x, pos_rect.y); @@ -1112,16 +1036,9 @@ sp_ruler_draw_ticks (SPRuler *ruler) { GtkWidget *widget = GTK_WIDGET (ruler); -#if GTK_CHECK_VERSION(3,0,0) GtkStyleContext *context = gtk_widget_get_style_context (widget); GtkBorder border; GdkRGBA color; -#else - GtkStyle *style = gtk_widget_get_style (widget); - GtkStateType state = gtk_widget_get_state (widget); - gint xthickness; - gint ythickness; -#endif SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); GtkAllocation allocation; @@ -1150,12 +1067,7 @@ sp_ruler_draw_ticks (SPRuler *ruler) gtk_widget_get_allocation (widget, &allocation); -#if GTK_CHECK_VERSION(3,0,0) gtk_style_context_get_border (context, static_cast(0), &border); -#else - xthickness = style->xthickness; - ythickness = style->ythickness; -#endif layout = sp_ruler_get_layout (widget, "0123456789"); pango_layout_get_extents (layout, &ink_rect, &logical_rect); @@ -1166,25 +1078,16 @@ sp_ruler_draw_ticks (SPRuler *ruler) if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) { width = allocation.width; -#if GTK_CHECK_VERSION(3,0,0) height = allocation.height - (border.top + border.bottom); -#else - height = allocation.height - ythickness * 2; -#endif } else { width = allocation.height; -#if GTK_CHECK_VERSION(3,0,0) height = allocation.width - (border.top + border.bottom); -#else - height = allocation.width - ythickness * 2; -#endif } cr = cairo_create (priv->backing_store); -#if GTK_CHECK_VERSION(3,0,0) gtk_render_background (context, cr, 0, 0, allocation.width, allocation.height); gtk_render_frame (context, cr, 0, 0, allocation.width, allocation.height); @@ -1208,30 +1111,6 @@ sp_ruler_draw_ticks (SPRuler *ruler) 1, allocation.height - (border.top + border.bottom)); } -#else - gdk_cairo_set_source_color (cr, &style->bg[state]); - - cairo_paint (cr); - - gdk_cairo_set_source_color(cr, &style->fg[state]); - - if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) - { - cairo_rectangle (cr, - xthickness, - height + ythickness, - allocation.width - 2 * xthickness, - 1); - } - else - { - cairo_rectangle (cr, - height + xthickness, - ythickness, - 1, - allocation.height - 2 * ythickness); - } -#endif sp_ruler_get_range (ruler, &lower, &upper, &max_size); @@ -1312,7 +1191,6 @@ sp_ruler_draw_ticks (SPRuler *ruler) // by a pixel, and jump back on the next redraw). This is suppressed by adding 1e-9 (that's only one nanopixel ;-)) pos = gint(Inkscape::round((cur - lower) * increment + 1e-12)); -#if GTK_CHECK_VERSION(3,0,0) if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) { cairo_rectangle (cr, @@ -1325,20 +1203,6 @@ sp_ruler_draw_ticks (SPRuler *ruler) height + border.left - length, pos, length, 1); } -#else - if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) - { - cairo_rectangle (cr, - pos, height + ythickness - length, - 1, length); - } - else - { - cairo_rectangle (cr, - height + xthickness - length, pos, - length, 1); - } -#endif /* draw label */ double label_spacing_px = fabs(increment*(double)ruler_metric.ruler_scale[scale]/ruler_metric.subdivide[i]); @@ -1356,15 +1220,9 @@ sp_ruler_draw_ticks (SPRuler *ruler) pango_layout_set_text (layout, unit_str, -1); pango_layout_get_extents (layout, &logical_rect, NULL); -#if GTK_CHECK_VERSION(3,0,0) cairo_move_to (cr, pos + 2, border.top + PANGO_PIXELS (logical_rect.y - digit_offset)); -#else - cairo_move_to (cr, - pos + 2, - ythickness + PANGO_PIXELS (logical_rect.y - digit_offset)); -#endif pango_cairo_show_layout(cr, layout); } @@ -1378,15 +1236,9 @@ sp_ruler_draw_ticks (SPRuler *ruler) pango_layout_set_text (layout, digit_str, 1); pango_layout_get_extents (layout, NULL, &logical_rect); -#if GTK_CHECK_VERSION(3,0,0) cairo_move_to (cr, border.left + 1, pos + digit_height * j + 2 + PANGO_PIXELS (logical_rect.y - digit_offset)); -#else - cairo_move_to (cr, - xthickness + 1, - pos + digit_height * j + 2 + PANGO_PIXELS (logical_rect.y - digit_offset)); -#endif pango_cairo_show_layout (cr, layout); } } @@ -1423,7 +1275,6 @@ sp_ruler_get_pos_rect (SPRuler *ruler, gtk_widget_get_allocation (widget, &allocation); -#if GTK_CHECK_VERSION(3,0,0) GtkStyleContext *context = gtk_widget_get_style_context (widget); GtkBorder padding; @@ -1431,11 +1282,6 @@ sp_ruler_get_pos_rect (SPRuler *ruler, xthickness = padding.left + padding.right; ythickness = padding.top + padding.bottom; -#else - GtkStyle *style = gtk_widget_get_style (widget); - xthickness = style->xthickness; - ythickness = style->ythickness; -#endif if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) { -- cgit v1.2.3 From 58111034d09da960cf9982b703c6ab2647422e0b Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Thu, 28 Jul 2016 13:19:42 +0100 Subject: ui/widgets: Drop GTK2 fallbacks (bzr r15023.2.6) --- src/widgets/desktop-widget.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/widgets') diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp index 164a06910..ef1f31751 100644 --- a/src/widgets/desktop-widget.cpp +++ b/src/widgets/desktop-widget.cpp @@ -2211,7 +2211,6 @@ set_adjustment (GtkAdjustment *adj, double l, double u, double ps, double si, do gtk_adjustment_set_page_size(adj, ps); gtk_adjustment_set_step_increment(adj, si); gtk_adjustment_set_page_increment(adj, pi); - gtk_adjustment_changed (adj); } } -- cgit v1.2.3 From dcd91f59f597ab4af07cee5929ce0e2e1f9104d5 Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Thu, 28 Jul 2016 16:16:18 +0100 Subject: Drop remaining GTKMM 2 fallback support (bzr r15023.2.7) --- src/widgets/dash-selector.cpp | 14 +-- src/widgets/dash-selector.h | 5 - src/widgets/desktop-widget.cpp | 178 ++++-------------------------------- src/widgets/sp-attribute-widget.cpp | 27 +----- src/widgets/sp-attribute-widget.h | 9 -- src/widgets/stroke-style.cpp | 60 ------------ src/widgets/stroke-style.h | 11 --- src/widgets/toolbox.cpp | 55 ++--------- 8 files changed, 27 insertions(+), 332 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/dash-selector.cpp b/src/widgets/dash-selector.cpp index 9d591d33d..7c6c22ba3 100644 --- a/src/widgets/dash-selector.cpp +++ b/src/widgets/dash-selector.cpp @@ -61,18 +61,9 @@ SPDashSelector::SPDashSelector() dash_combo.signal_changed().connect( sigc::mem_fun(*this, &SPDashSelector::on_selection) ); this->pack_start(dash_combo, false, false, 0); - -#if WITH_GTKMM_3_0 offset = Gtk::Adjustment::create(0.0, 0.0, 10.0, 0.1, 1.0, 0.0); -#else - offset = new Gtk::Adjustment(0.0, 0.0, 10.0, 0.1, 1.0, 0.0); -#endif offset->signal_value_changed().connect(sigc::mem_fun(*this, &SPDashSelector::offset_value_changed)); -#if WITH_GTKMM_3_0 - Inkscape::UI::Widget::SpinButton *sb = new Inkscape::UI::Widget::SpinButton(offset, 0.1, 2); -#else - Inkscape::UI::Widget::SpinButton *sb = new Inkscape::UI::Widget::SpinButton(*offset, 0.1, 2); -#endif + auto sb = new Inkscape::UI::Widget::SpinButton(offset, 0.1, 2); sb->set_tooltip_text(_("Pattern offset")); sp_dialog_defocus_on_enter_cpp(sb); sb->show(); @@ -99,9 +90,6 @@ SPDashSelector::SPDashSelector() SPDashSelector::~SPDashSelector() { // FIXME: for some reason this doesn't get called; does the call to manage() in // sp_stroke_style_line_widget_new() not processed correctly? -#if !WITH_GTKMM_3_0 - delete offset; -#endif } void SPDashSelector::prepareImageRenderer( Gtk::TreeModel::const_iterator const &row ) { diff --git a/src/widgets/dash-selector.h b/src/widgets/dash-selector.h index ec5a1cbd5..f176acf04 100644 --- a/src/widgets/dash-selector.h +++ b/src/widgets/dash-selector.h @@ -85,12 +85,7 @@ private: Glib::RefPtr dash_store; Gtk::ComboBox dash_combo; Gtk::CellRendererPixbuf image_renderer; - -#if WITH_GTKMM_3_0 Glib::RefPtr offset; -#else - Gtk::Adjustment *offset; -#endif static gchar const *const _prefs_path; int preview_width; diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp index ef1f31751..8b035eb15 100644 --- a/src/widgets/desktop-widget.cpp +++ b/src/widgets/desktop-widget.cpp @@ -70,9 +70,7 @@ #include "widget-sizes.h" #include "verbs.h" -#if GTK_CHECK_VERSION(3,0,0) -# include -#endif +#include #include #include @@ -256,16 +254,11 @@ Geom::Point SPDesktopWidget::window_get_pointer() { gint x,y; - GdkWindow *window = gtk_widget_get_window(GTK_WIDGET(canvas)); - -#if GTK_CHECK_VERSION(3,0,0) - GdkDisplay *display = gdk_window_get_display(window); - GdkDeviceManager *dm = gdk_display_get_device_manager(display); - GdkDevice *device = gdk_device_manager_get_client_pointer(dm); + auto window = gtk_widget_get_window(GTK_WIDGET(canvas)); + auto display = gdk_window_get_display(window); + auto dm = gdk_display_get_device_manager(display); + auto device = gdk_device_manager_get_client_pointer(dm); gdk_window_get_device_position(window, device, &x, &y, NULL); -#else - gdk_window_get_pointer(window, &x, &y, NULL); -#endif return Geom::Point(x,y); } @@ -344,21 +337,11 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) dtw->_interaction_disabled_counter = 0; /* Main table */ -#if GTK_CHECK_VERSION(3,0,0) dtw->vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); gtk_widget_set_name(dtw->vbox, "DesktopMainTable"); -#else - dtw->vbox = gtk_vbox_new (FALSE, 0); -#endif gtk_container_add( GTK_CONTAINER(dtw), GTK_WIDGET(dtw->vbox) ); - -#if GTK_CHECK_VERSION(3,0,0) dtw->statusbar = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); gtk_widget_set_name(dtw->statusbar, "DesktopStatusBar"); -#else - dtw->statusbar = gtk_hbox_new (FALSE, 0); -#endif - //gtk_widget_set_usize (dtw->statusbar, -1, BOTTOM_BAR_HEIGHT); gtk_box_pack_end (GTK_BOX (dtw->vbox), dtw->statusbar, FALSE, TRUE, 0); { @@ -366,19 +349,12 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) dtw->panels = new SwatchesPanel("/embedded/swatches" /*false*/); dtw->panels->setOrientation(SP_ANCHOR_SOUTH); -#if GTK_CHECK_VERSION(3,0,0) dtw->panels->set_vexpand(false); -#endif - gtk_box_pack_end( GTK_BOX( dtw->vbox ), GTK_WIDGET(dtw->panels->gobj()), FALSE, TRUE, 0 ); } -#if GTK_CHECK_VERSION(3,0,0) dtw->hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); gtk_widget_set_name(dtw->hbox, "DesktopHbox"); -#else - dtw->hbox = gtk_hbox_new(FALSE, 0); -#endif gtk_box_pack_end( GTK_BOX (dtw->vbox), dtw->hbox, TRUE, TRUE, 0 ); gtk_widget_show(dtw->hbox); @@ -402,14 +378,12 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) NULL, INKSCAPE_ICON("object-locked"), _("Toggle lock of all guides in the document")); -#if GTK_CHECK_VERSION(3,0,0) - Glib::RefPtr guides_lock_style_provider = Gtk::CssProvider::create(); + auto guides_lock_style_provider = Gtk::CssProvider::create(); guides_lock_style_provider->load_from_data("GtkWidget { padding-left: 0; padding-right: 0; padding-top: 0; padding-bottom: 0; }"); - Gtk::Widget * wnd = Glib::wrap(dtw->guides_lock); + auto wnd = Glib::wrap(dtw->guides_lock); wnd->set_name("LockGuides"); - Glib::RefPtr context = wnd->get_style_context(); + auto context = wnd->get_style_context(); context->add_provider(guides_lock_style_provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); -#endif /* Horizontal ruler */ GtkWidget *eventbox = gtk_event_box_new (); @@ -424,29 +398,13 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) g_signal_connect (G_OBJECT (eventbox), "button_release_event", G_CALLBACK (sp_dt_hruler_event), dtw); g_signal_connect (G_OBJECT (eventbox), "motion_notify_event", G_CALLBACK (sp_dt_hruler_event), dtw); -#if GTK_CHECK_VERSION(3,0,0) - GtkWidget *tbl_wrapper = gtk_grid_new(); // Is this widget really needed? + auto tbl_wrapper = gtk_grid_new(); // Is this widget really needed? gtk_widget_set_name(tbl_wrapper, "CanvasTableWrapper"); dtw->canvas_tbl = gtk_grid_new(); gtk_widget_set_name(dtw->canvas_tbl, "CanvasTable"); gtk_grid_attach(GTK_GRID(dtw->canvas_tbl), dtw->guides_lock, 0, 0, 1, 1); gtk_grid_attach(GTK_GRID(dtw->canvas_tbl), eventbox, 1, 0, 1, 1); -#else - GtkWidget *tbl_wrapper = gtk_table_new(2, 3, FALSE); - dtw->canvas_tbl = gtk_table_new(3, 3, FALSE); - - gtk_table_attach(GTK_TABLE(dtw->canvas_tbl), - dtw->guides_lock, - 0, 1, 0, 1, - GTK_FILL, GTK_FILL, - 0, 0); - gtk_table_attach(GTK_TABLE(dtw->canvas_tbl), - eventbox, - 1, 2, 0, 1, - GTK_FILL, GTK_FILL, - 0, 0); -#endif g_signal_connect (G_OBJECT (dtw->guides_lock), "toggled", G_CALLBACK (sp_update_guides_lock), dtw); gtk_box_pack_start( GTK_BOX(dtw->hbox), tbl_wrapper, TRUE, TRUE, 1 ); @@ -460,16 +418,7 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) sp_ruler_set_unit (SP_RULER (dtw->vruler), pt); gtk_widget_set_tooltip_text (dtw->vruler_box, gettext(pt->name_plural.c_str())); gtk_container_add (GTK_CONTAINER (eventbox), GTK_WIDGET (dtw->vruler)); - -#if GTK_CHECK_VERSION(3,0,0) gtk_grid_attach(GTK_GRID(dtw->canvas_tbl), eventbox, 0, 1, 1, 1); -#else - gtk_table_attach(GTK_TABLE (dtw->canvas_tbl), - eventbox, - 0, 1, 1, 2, - GTK_FILL, GTK_FILL, - 0, 0); -#endif g_signal_connect (G_OBJECT (eventbox), "button_press_event", G_CALLBACK (sp_dt_vruler_event), dtw); g_signal_connect (G_OBJECT (eventbox), "button_release_event", G_CALLBACK (sp_dt_vruler_event), dtw); @@ -477,19 +426,10 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) // Horizontal scrollbar dtw->hadj = GTK_ADJUSTMENT(gtk_adjustment_new(0.0, -4000.0, 4000.0, 10.0, 100.0, 4.0)); - -#if GTK_CHECK_VERSION(3,0,0) dtw->hscrollbar = gtk_scrollbar_new(GTK_ORIENTATION_HORIZONTAL, GTK_ADJUSTMENT (dtw->hadj)); gtk_widget_set_name(dtw->hscrollbar, "HorizontalScrollbar"); gtk_grid_attach(GTK_GRID(dtw->canvas_tbl), dtw->hscrollbar, 1, 2, 1, 1); dtw->vscrollbar_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); -#else - dtw->hscrollbar = gtk_hscrollbar_new (GTK_ADJUSTMENT (dtw->hadj)); - gtk_table_attach(GTK_TABLE (dtw->canvas_tbl), dtw->hscrollbar, 1, 2, 2, 3, - GTK_FILL, GTK_SHRINK, - 0, 0); - dtw->vscrollbar_box = gtk_vbox_new (FALSE, 0); -#endif // Sticky zoom button dtw->sticky_zoom = sp_button_new_from_data ( Inkscape::ICON_SIZE_DECORATION, @@ -504,23 +444,10 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) // Vertical scrollbar dtw->vadj = GTK_ADJUSTMENT(gtk_adjustment_new(0.0, -4000.0, 4000.0, 10.0, 100.0, 4.0)); - -#if GTK_CHECK_VERSION(3,0,0) dtw->vscrollbar = gtk_scrollbar_new(GTK_ORIENTATION_VERTICAL, GTK_ADJUSTMENT(dtw->vadj)); gtk_widget_set_name(dtw->vscrollbar, "VerticalScrollbar"); -#else - dtw->vscrollbar = gtk_vscrollbar_new (GTK_ADJUSTMENT (dtw->vadj)); -#endif - gtk_box_pack_start (GTK_BOX (dtw->vscrollbar_box), dtw->vscrollbar, TRUE, TRUE, 0); - -#if GTK_CHECK_VERSION(3,0,0) gtk_grid_attach(GTK_GRID(dtw->canvas_tbl), dtw->vscrollbar_box, 2, 0, 1, 2); -#else - gtk_table_attach(GTK_TABLE(dtw->canvas_tbl), dtw->vscrollbar_box, 2, 3, 0, 2, - GTK_SHRINK, GTK_FILL, - 0, 0); -#endif gchar const* tip = ""; Inkscape::Verb* verb = Inkscape::Verb::get( SP_VERB_VIEW_CMS_TOGGLE ); @@ -554,15 +481,7 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) cms_adjust_set_sensitive(dtw, FALSE); #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) -#if GTK_CHECK_VERSION(3,0,0) gtk_grid_attach( GTK_GRID(dtw->canvas_tbl), dtw->cms_adjust, 2, 2, 1, 1); -#else - gtk_table_attach( GTK_TABLE(dtw->canvas_tbl), dtw->cms_adjust, 2, 3, 2, 3, - (GtkAttachOptions)(GTK_SHRINK), - (GtkAttachOptions)(GTK_SHRINK), - 0, 0); -#endif - { if (!watcher) { watcher = new CMSPrefWatcher(); @@ -579,10 +498,8 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) sp_ruler_add_track_widget (SP_RULER(dtw->hruler), GTK_WIDGET(dtw->canvas)); sp_ruler_add_track_widget (SP_RULER(dtw->vruler), GTK_WIDGET(dtw->canvas)); - -#if GTK_CHECK_VERSION(3,0,0) - GtkCssProvider *css_provider = gtk_css_provider_new(); - GtkStyleContext *style_context = gtk_widget_get_style_context(GTK_WIDGET(dtw->canvas)); + auto css_provider = gtk_css_provider_new(); + auto style_context = gtk_widget_get_style_context(GTK_WIDGET(dtw->canvas)); gtk_css_provider_load_from_data(css_provider, "SPCanvas {\n" @@ -593,21 +510,11 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) gtk_style_context_add_provider(style_context, GTK_STYLE_PROVIDER(css_provider), GTK_STYLE_PROVIDER_PRIORITY_USER); -#else - GtkStyle *style = gtk_style_copy(gtk_widget_get_style(GTK_WIDGET(dtw->canvas))); - style->bg[GTK_STATE_NORMAL] = style->white; - gtk_widget_set_style (GTK_WIDGET (dtw->canvas), style); -#endif - g_signal_connect (G_OBJECT (dtw->canvas), "event", G_CALLBACK (sp_desktop_widget_event), dtw); -#if GTK_CHECK_VERSION(3,0,0) gtk_widget_set_hexpand(GTK_WIDGET(dtw->canvas), TRUE); gtk_widget_set_vexpand(GTK_WIDGET(dtw->canvas), TRUE); gtk_grid_attach(GTK_GRID(dtw->canvas_tbl), GTK_WIDGET(dtw->canvas), 1, 1, 1, 1); -#else - gtk_table_attach (GTK_TABLE (dtw->canvas_tbl), GTK_WIDGET(dtw->canvas), 1, 2, 1, 2, (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), (GtkAttachOptions)(GTK_FILL | GTK_EXPAND), 0, 0); -#endif /* Dock */ bool create_dock = @@ -616,12 +523,8 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) if (create_dock) { dtw->dock = new Inkscape::UI::Widget::Dock(); -#if WITH_GTKMM_3_0 - Gtk::Paned *paned = new Gtk::Paned(); + auto paned = new Gtk::Paned(); paned->set_name("Canvas_and_Dock"); -#else - Gtk::HPaned *paned = new Gtk::HPaned(); -#endif paned->pack1(*Glib::wrap(dtw->canvas_tbl)); paned->pack2(dtw->dock->getWidget(), Gtk::FILL); @@ -632,24 +535,13 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) paned_class->cycle_handle_focus = NULL; } -#if GTK_CHECK_VERSION(3,0,0) gtk_widget_set_hexpand(GTK_WIDGET(paned->gobj()), TRUE); gtk_widget_set_vexpand(GTK_WIDGET(paned->gobj()), TRUE); gtk_grid_attach(GTK_GRID(tbl_wrapper), GTK_WIDGET (paned->gobj()), 1, 1, 1, 1); -#else - gtk_table_attach (GTK_TABLE (tbl_wrapper), GTK_WIDGET (paned->gobj()), 1, 2, 1, 2, (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), - (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), 0, 0); -#endif - } else { -#if GTK_CHECK_VERSION(3,0,0) gtk_widget_set_hexpand(GTK_WIDGET(dtw->canvas_tbl), TRUE); gtk_widget_set_vexpand(GTK_WIDGET(dtw->canvas_tbl), TRUE); gtk_grid_attach(GTK_GRID(tbl_wrapper), GTK_WIDGET (dtw->canvas_tbl), 1, 1, 1, 1); -#else - gtk_table_attach (GTK_TABLE (tbl_wrapper), GTK_WIDGET (dtw->canvas_tbl), 1, 2, 1, 2, (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), - (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), 0, 0); -#endif } // connect scrollbar signals @@ -666,11 +558,7 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) // Separator gtk_box_pack_start(GTK_BOX(dtw->statusbar), -#if GTK_CHECK_VERSION(3,0,0) gtk_separator_new(GTK_ORIENTATION_VERTICAL), -#else - gtk_vseparator_new(), -#endif FALSE, FALSE, 0); // Layer Selector @@ -689,12 +577,7 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) gtk_label_set_lines (GTK_LABEL(dtw->select_status), 2); #endif -#if GTK_CHECK_VERSION(3,0,0) gtk_widget_set_halign(dtw->select_status, GTK_ALIGN_START); -#else - gtk_misc_set_alignment (GTK_MISC (dtw->select_status), 0.0, 0.5); -#endif - gtk_widget_set_size_request (dtw->select_status, 1, -1); // Display the initial welcome message in the statusbar @@ -720,65 +603,36 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) dtw->zoom_update = g_signal_connect (G_OBJECT (dtw->zoom_status), "populate_popup", G_CALLBACK (sp_dtw_zoom_populate_popup), dtw); // Cursor coordinates -#if GTK_CHECK_VERSION(3,0,0) dtw->coord_status = gtk_grid_new(); gtk_widget_set_name(dtw->coord_status, "CoordinateAndZStatus"); gtk_grid_set_row_spacing(GTK_GRID(dtw->coord_status), 0); gtk_grid_set_column_spacing(GTK_GRID(dtw->coord_status), 2); - GtkWidget* sep = gtk_separator_new(GTK_ORIENTATION_VERTICAL); + auto sep = gtk_separator_new(GTK_ORIENTATION_VERTICAL); gtk_widget_set_name(sep, "CoordinateSeparator"); gtk_grid_attach(GTK_GRID(dtw->coord_status), GTK_WIDGET(sep), 0, 0, 1, 2); -#else - dtw->coord_status = gtk_table_new(5, 2, FALSE); - gtk_table_set_row_spacings(GTK_TABLE(dtw->coord_status), 0); - gtk_table_set_col_spacings(GTK_TABLE(dtw->coord_status), 2); - gtk_table_attach(GTK_TABLE(dtw->coord_status), - gtk_vseparator_new(), - 0, 1, 0, 2, - GTK_FILL, GTK_FILL, 0, 0); -#endif gtk_widget_set_tooltip_text (dtw->coord_status, _("Cursor coordinates")); - GtkWidget *label_x = gtk_label_new(_("X:")); - GtkWidget *label_y = gtk_label_new(_("Y:")); - -#if GTK_CHECK_VERSION(3,0,0) + auto label_x = gtk_label_new(_("X:")); + auto label_y = gtk_label_new(_("Y:")); gtk_widget_set_halign(label_x, GTK_ALIGN_START); gtk_widget_set_halign(label_y, GTK_ALIGN_START); gtk_grid_attach(GTK_GRID(dtw->coord_status), label_x, 1, 0, 1, 1); gtk_grid_attach(GTK_GRID(dtw->coord_status), label_y, 1, 1, 1, 1); -#else - gtk_misc_set_alignment (GTK_MISC(label_x), 0.0, 0.5); - gtk_misc_set_alignment (GTK_MISC(label_y), 0.0, 0.5); - gtk_table_attach(GTK_TABLE(dtw->coord_status), label_x, 1,2, 0,1, GTK_FILL, GTK_FILL, 0, 0); - gtk_table_attach(GTK_TABLE(dtw->coord_status), label_y, 1,2, 1,2, GTK_FILL, GTK_FILL, 0, 0); -#endif - dtw->coord_status_x = gtk_label_new(NULL); dtw->coord_status_y = gtk_label_new(NULL); gtk_label_set_markup( GTK_LABEL(dtw->coord_status_x), " 0.00 " ); gtk_label_set_markup( GTK_LABEL(dtw->coord_status_y), " 0.00 " ); - GtkWidget* label_z = gtk_label_new(_("Z:")); + auto label_z = gtk_label_new(_("Z:")); gtk_widget_set_name(label_z, "ZLabel"); - -#if GTK_CHECK_VERSION(3,0,0) gtk_widget_set_halign(dtw->coord_status_x, GTK_ALIGN_END); gtk_widget_set_halign(dtw->coord_status_y, GTK_ALIGN_END); gtk_grid_attach(GTK_GRID(dtw->coord_status), dtw->coord_status_x, 2, 0, 1, 1); gtk_grid_attach(GTK_GRID(dtw->coord_status), dtw->coord_status_y, 2, 1, 1, 1); gtk_grid_attach(GTK_GRID(dtw->coord_status), label_z, 3, 0, 1, 2); gtk_grid_attach(GTK_GRID(dtw->coord_status), dtw->zoom_status, 4, 0, 1, 2); -#else - gtk_misc_set_alignment (GTK_MISC(dtw->coord_status_x), 1.0, 0.5); - gtk_misc_set_alignment (GTK_MISC(dtw->coord_status_y), 1.0, 0.5); - gtk_table_attach(GTK_TABLE(dtw->coord_status), dtw->coord_status_x, 2,3, 0,1, GTK_FILL, GTK_FILL, 0, 0); - gtk_table_attach(GTK_TABLE(dtw->coord_status), dtw->coord_status_y, 2,3, 1,2, GTK_FILL, GTK_FILL, 0, 0); - gtk_table_attach(GTK_TABLE(dtw->coord_status), label_z, 3,4, 0,2, GTK_FILL, GTK_FILL, 0, 0); - gtk_table_attach(GTK_TABLE(dtw->coord_status), dtw->zoom_status, 4,5, 0,2, GTK_FILL, GTK_FILL, 0, 0); -#endif sp_set_font_size_smaller (dtw->coord_status); diff --git a/src/widgets/sp-attribute-widget.cpp b/src/widgets/sp-attribute-widget.cpp index fb7eb1420..2e782cf16 100644 --- a/src/widgets/sp-attribute-widget.cpp +++ b/src/widgets/sp-attribute-widget.cpp @@ -17,12 +17,7 @@ #include #include #include - -#if WITH_GTKMM_3_0 -# include -#else -# include -#endif +#include #include #include @@ -156,11 +151,7 @@ void SPAttributeTable::set_object(SPObject *object, release_connection = object->connectRelease (sigc::bind<1>(sigc::ptr_fun(&sp_attribute_table_object_release), this)); // Create table -#if WITH_GTKMM_3_0 table = new Gtk::Grid(); -#else - table = new Gtk::Table(attributes.size(), 2, false); -#endif if (!(parent == NULL)) gtk_container_add(GTK_CONTAINER(parent), (GtkWidget*)table->gobj()); @@ -171,27 +162,17 @@ void SPAttributeTable::set_object(SPObject *object, Gtk::Label *ll = new Gtk::Label (_(labels[i].c_str())); ll->show(); ll->set_alignment (1.0, 0.5); - -#if WITH_GTKMM_3_0 ll->set_vexpand(); ll->set_margin_left(XPAD); ll->set_margin_right(XPAD); ll->set_margin_top(XPAD); ll->set_margin_bottom(XPAD); table->attach(*ll, 0, i, 1, 1); -#else - table->attach (*ll, 0, 1, i, i + 1, - Gtk::FILL, - (Gtk::EXPAND | Gtk::FILL), - XPAD, YPAD ); -#endif Gtk::Entry *ee = new Gtk::Entry(); ee->show(); const gchar *val = object->getRepr()->attribute(attributes[i].c_str()); ee->set_text (val ? val : (const gchar *) ""); - -#if WITH_GTKMM_3_0 ee->set_hexpand(); ee->set_vexpand(); ee->set_margin_left(XPAD); @@ -199,12 +180,6 @@ void SPAttributeTable::set_object(SPObject *object, ee->set_margin_top(XPAD); ee->set_margin_bottom(XPAD); table->attach(*ee, 1, i, 1, 1); -#else - table->attach (*ee, 1, 2, i, i + 1, - (Gtk::EXPAND | Gtk::FILL), - (Gtk::EXPAND | Gtk::FILL), - XPAD, YPAD ); -#endif _entries.push_back(ee); g_signal_connect ( ee->gobj(), "changed", diff --git a/src/widgets/sp-attribute-widget.h b/src/widgets/sp-attribute-widget.h index d9b972201..161bb706a 100644 --- a/src/widgets/sp-attribute-widget.h +++ b/src/widgets/sp-attribute-widget.h @@ -25,12 +25,7 @@ namespace Gtk { class Entry; - -#if WITH_GTKMM_3_0 class Grid; -#else -class Table; -#endif } namespace Inkscape { @@ -138,11 +133,7 @@ private: /** * Container widget for the dynamically created child widgets (labels and entry boxes). */ -#if WITH_GTKMM_3_0 Gtk::Grid *table; -#else - Gtk::Table *table; -#endif /** * List of attributes. diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp index 84a6e77ad..990ec8d35 100644 --- a/src/widgets/stroke-style.cpp +++ b/src/widgets/stroke-style.cpp @@ -155,17 +155,9 @@ StrokeStyle::StrokeStyle() : Gtk::HBox *f = new Gtk::HBox(false, 0); f->show(); add(*f); - -#if WITH_GTKMM_3_0 table = new Gtk::Grid(); table->set_border_width(4); table->set_row_spacing(4); -#else - table = new Gtk::Table(3, 6, false); - table->set_border_width(4); - table->set_row_spacings(4); -#endif - table->show(); f->add(*table); @@ -181,13 +173,7 @@ StrokeStyle::StrokeStyle() : // stroke_width_set_unit will be removed (because ScalarUnit takes care of conversions itself), and // with it, the two remaining calls of stroke_average_width, allowing us to get rid of that // function in desktop-style. - -#if WITH_GTKMM_3_0 widthAdj = new Glib::RefPtr(Gtk::Adjustment::create(1.0, 0.0, 1000.0, 0.1, 10.0, 0.0)); -#else - widthAdj = new Gtk::Adjustment(1.0, 0.0, 1000.0, 0.1, 10.0, 0.0); -#endif - widthSpin = new Inkscape::UI::Widget::SpinButton(*widthAdj, 0.1, 3); widthSpin->set_tooltip_text(_("Stroke width")); widthSpin->show(); @@ -213,12 +199,7 @@ StrokeStyle::StrokeStyle() : us->show(); hb->pack_start(*us, FALSE, FALSE, 0); - -#if WITH_GTKMM_3_0 (*widthAdj)->signal_value_changed().connect(sigc::mem_fun(*this, &StrokeStyle::widthChangedCB)); -#else - widthAdj->signal_value_changed().connect(sigc::mem_fun(*this, &StrokeStyle::widthChangedCB)); -#endif i++; /* Dash */ @@ -230,16 +211,10 @@ StrokeStyle::StrokeStyle() : dashSelector = Gtk::manage(new SPDashSelector); dashSelector->show(); - -#if WITH_GTKMM_3_0 dashSelector->set_hexpand(); dashSelector->set_halign(Gtk::ALIGN_FILL); dashSelector->set_valign(Gtk::ALIGN_CENTER); table->attach(*dashSelector, 1, i, 3, 1); -#else - table->attach(*dashSelector, 1, 4, i, i+1, (Gtk::EXPAND | Gtk::FILL), static_cast(0), 0, 0); -#endif - dashSelector->changed_signal.connect(sigc::mem_fun(*this, &StrokeStyle::lineDashChangedCB)); i++; @@ -323,28 +298,14 @@ StrokeStyle::StrokeStyle() : // miter limit is to cut off such spikes (i.e. convert them into bevels) // when they become too long. //spw_label(t, _("Miter _limit:"), 0, i); - -#if WITH_GTKMM_3_0 miterLimitAdj = new Glib::RefPtr(Gtk::Adjustment::create(4.0, 0.0, 100.0, 0.1, 10.0, 0.0)); miterLimitSpin = new Inkscape::UI::Widget::SpinButton(*miterLimitAdj, 0.1, 2); -#else - miterLimitAdj = new Gtk::Adjustment(4.0, 0.0, 100.0, 0.1, 10.0, 0.0); - miterLimitSpin = new Inkscape::UI::Widget::SpinButton(*miterLimitAdj, 0.1, 2); -#endif - miterLimitSpin->set_tooltip_text(_("Maximum length of the miter (in units of stroke width)")); miterLimitSpin->show(); sp_dialog_defocus_on_enter_cpp(miterLimitSpin); hb->pack_start(*miterLimitSpin, false, false, 0); - -#if WITH_GTKMM_3_0 (*miterLimitAdj)->signal_value_changed().connect(sigc::mem_fun(*this, &StrokeStyle::miterLimitChangedCB)); - -#else - miterLimitAdj->signal_value_changed().connect(sigc::mem_fun(*this, &StrokeStyle::miterLimitChangedCB)); -#endif - i++; /* Cap type */ @@ -927,17 +888,9 @@ StrokeStyle::updateLine() if (unit->type == Inkscape::Util::UNIT_TYPE_LINEAR) { double avgwidth = Inkscape::Util::Quantity::convert(query.stroke_width.computed, "px", unit); -#if WITH_GTKMM_3_0 (*widthAdj)->set_value(avgwidth); -#else - widthAdj->set_value(avgwidth); -#endif } else { -#if WITH_GTKMM_3_0 (*widthAdj)->set_value(100); -#else - widthAdj->set_value(100); -#endif } // if none of the selected objects has a stroke, than quite some controls should be disabled @@ -958,11 +911,7 @@ StrokeStyle::updateLine() } if (result_ml != QUERY_STYLE_NOTHING) -#if WITH_GTKMM_3_0 (*miterLimitAdj)->set_value(query.stroke_miterlimit.value); // TODO: reflect averagedness? -#else - miterLimitAdj->set_value(query.stroke_miterlimit.value); // TODO: reflect averagedness? -#endif if (result_join != QUERY_STYLE_MULTIPLE_DIFFERENT && result_join != QUERY_STYLE_NOTHING ) { @@ -1050,13 +999,8 @@ StrokeStyle::scaleLine() SPCSSAttr *css = sp_repr_css_attr_new(); if (!items.empty()) { -#if WITH_GTKMM_3_0 double width_typed = (*widthAdj)->get_value(); double const miterlimit = (*miterLimitAdj)->get_value(); -#else - double width_typed = widthAdj->get_value(); - double const miterlimit = miterLimitAdj->get_value(); -#endif Inkscape::Util::Unit const *const unit = unitSelector->getUnit(); @@ -1096,11 +1040,7 @@ StrokeStyle::scaleLine() if (unit->type != Inkscape::Util::UNIT_TYPE_LINEAR) { // reset to 100 percent -#if WITH_GTKMM_3_0 (*widthAdj)->set_value(100.0); -#else - widthAdj->set_value(100.0); -#endif } } diff --git a/src/widgets/stroke-style.h b/src/widgets/stroke-style.h index d83067a4a..76582602d 100644 --- a/src/widgets/stroke-style.h +++ b/src/widgets/stroke-style.h @@ -23,12 +23,7 @@ #include "widgets/dash-selector.h" #include - -#if WITH_GTKMM_3_0 #include -#else -#include -#endif #include @@ -189,15 +184,9 @@ private: MarkerComboBox *startMarkerCombo; MarkerComboBox *midMarkerCombo; MarkerComboBox *endMarkerCombo; -#if WITH_GTKMM_3_0 Gtk::Grid *table; Glib::RefPtr *widthAdj; Glib::RefPtr *miterLimitAdj; -#else - Gtk::Table *table; - Gtk::Adjustment *widthAdj; - Gtk::Adjustment *miterLimitAdj; -#endif Inkscape::UI::Widget::SpinButton *miterLimitSpin; Inkscape::UI::Widget::SpinButton *widthSpin; Inkscape::UI::Widget::UnitMenu *unitSelector; diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 8113c9619..caca0c267 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -1016,26 +1016,18 @@ static GtkWidget* toolboxNewCommon( GtkWidget* tb, BarId id, GtkPositionType /*h GtkWidget *ToolboxFactory::createToolToolbox() { -#if GTK_CHECK_VERSION(3,0,0) - GtkWidget *tb = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); + auto tb = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); gtk_widget_set_name(tb, "ToolToolbox"); gtk_box_set_homogeneous(GTK_BOX(tb), FALSE); -#else - GtkWidget *tb = gtk_vbox_new(FALSE, 0); -#endif return toolboxNewCommon( tb, BAR_TOOL, GTK_POS_TOP ); } GtkWidget *ToolboxFactory::createAuxToolbox() { -#if GTK_CHECK_VERSION(3,0,0) - GtkWidget *tb = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); + auto tb = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); gtk_widget_set_name(tb, "AuxToolbox"); gtk_box_set_homogeneous(GTK_BOX(tb), FALSE); -#else - GtkWidget *tb = gtk_vbox_new(FALSE, 0); -#endif return toolboxNewCommon( tb, BAR_AUX, GTK_POS_LEFT ); } @@ -1046,38 +1038,26 @@ GtkWidget *ToolboxFactory::createAuxToolbox() GtkWidget *ToolboxFactory::createCommandsToolbox() { -#if GTK_CHECK_VERSION(3,0,0) - GtkWidget *tb = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); + auto tb = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); gtk_widget_set_name(tb, "CommandsToolbox"); gtk_box_set_homogeneous(GTK_BOX(tb), FALSE); -#else - GtkWidget *tb = gtk_vbox_new(FALSE, 0); -#endif return toolboxNewCommon( tb, BAR_COMMANDS, GTK_POS_LEFT ); } GtkWidget *ToolboxFactory::createSnapToolbox() { -#if GTK_CHECK_VERSION(3,0,0) - GtkWidget *tb = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); + auto tb = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); gtk_widget_set_name(tb, "SnapToolbox"); gtk_box_set_homogeneous(GTK_BOX(tb), FALSE); -#else - GtkWidget *tb = gtk_vbox_new(FALSE, 0); -#endif return toolboxNewCommon( tb, BAR_SNAP, GTK_POS_LEFT ); } static GtkWidget* createCustomSlider( GtkAdjustment *adjustment, gdouble climbRate, guint digits, Inkscape::UI::Widget::UnitTracker *unit_tracker) { -#if WITH_GTKMM_3_0 - Glib::RefPtr adj = Glib::wrap(adjustment, true); - Inkscape::UI::Widget::SpinButton *inkSpinner = new Inkscape::UI::Widget::SpinButton(adj, climbRate, digits); -#else - Inkscape::UI::Widget::SpinButton *inkSpinner = new Inkscape::UI::Widget::SpinButton(*Glib::wrap(adjustment, true), climbRate, digits); -#endif + auto adj = Glib::wrap(adjustment, true); + auto inkSpinner = new Inkscape::UI::Widget::SpinButton(adj, climbRate, digits); inkSpinner->addUnitTracker(unit_tracker); inkSpinner = Gtk::manage( inkSpinner ); GtkWidget *widget = GTK_WIDGET( inkSpinner->gobj() ); @@ -1439,17 +1419,10 @@ void setup_aux_toolbox(GtkWidget *toolbox, SPDesktop *desktop) if ( aux_toolboxes[i].prep_func ) { // converted to GtkActions and UIManager - GtkWidget* kludge = dataHolders[aux_toolboxes[i].type_name]; - -#if GTK_CHECK_VERSION(3,0,0) - GtkWidget* holder = gtk_grid_new(); + auto kludge = dataHolders[aux_toolboxes[i].type_name]; + auto holder = gtk_grid_new(); gtk_widget_set_name( holder, "ToolbarHolder" ); gtk_grid_attach( GTK_GRID(holder), kludge, 2, 0, 1, 1); -#else - GtkWidget* holder = gtk_table_new( 1, 3, FALSE ); - gtk_table_attach( GTK_TABLE(holder), kludge, 2, 3, 0, 1, GTK_SHRINK, GTK_SHRINK, 0, 0 ); -#endif - gchar* tmp = g_strdup_printf( "/ui/%s", aux_toolboxes[i].ui_name ); GtkWidget* toolBar = gtk_ui_manager_get_widget( mgr, tmp ); g_free( tmp ); @@ -1461,30 +1434,20 @@ void setup_aux_toolbox(GtkWidget *toolbox, SPDesktop *desktop) Inkscape::IconSize toolboxSize = ToolboxFactory::prefToSize("/toolbox/small"); gtk_toolbar_set_icon_size( GTK_TOOLBAR(toolBar), static_cast(toolboxSize) ); - -#if GTK_CHECK_VERSION(3,0,0) gtk_widget_set_hexpand(toolBar, TRUE); gtk_grid_attach( GTK_GRID(holder), toolBar, 0, 0, 1, 1); -#else - gtk_table_attach( GTK_TABLE(holder), toolBar, 0, 1, 0, 1, (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), 0, 0 ); -#endif if ( aux_toolboxes[i].swatch_verb_id != SP_VERB_INVALID ) { Inkscape::UI::Widget::StyleSwatch *swatch = new Inkscape::UI::Widget::StyleSwatch( NULL, _(aux_toolboxes[i].swatch_tip) ); swatch->setDesktop( desktop ); swatch->setClickVerb( aux_toolboxes[i].swatch_verb_id ); swatch->setWatchedTool( aux_toolboxes[i].swatch_tool, true ); - GtkWidget *swatch_ = GTK_WIDGET( swatch->gobj() ); - -#if GTK_CHECK_VERSION(3,0,0) + auto swatch_ = GTK_WIDGET( swatch->gobj() ); gtk_widget_set_margin_left(swatch_, AUX_BETWEEN_BUTTON_GROUPS); gtk_widget_set_margin_right(swatch_, AUX_BETWEEN_BUTTON_GROUPS); gtk_widget_set_margin_top(swatch_, AUX_SPACING); gtk_widget_set_margin_bottom(swatch_, AUX_SPACING); gtk_grid_attach( GTK_GRID(holder), swatch_, 1, 0, 1, 1); -#else - gtk_table_attach( GTK_TABLE(holder), swatch_, 1, 2, 0, 1, (GtkAttachOptions)(GTK_SHRINK | GTK_FILL), (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), AUX_BETWEEN_BUTTON_GROUPS, AUX_SPACING ); -#endif } if(i==0){ gtk_widget_show_all( holder ); -- cgit v1.2.3 From 49a7927ecf31ace696e9e5770e8d6543c356db7a Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Thu, 28 Jul 2016 19:15:34 +0100 Subject: Finish removing GTK+ 2 fallbacks (bzr r15023.2.8) --- src/widgets/button.cpp | 29 ------ src/widgets/eek-preview.cpp | 148 +------------------------------ src/widgets/ege-adjustment-action.cpp | 12 +-- src/widgets/ege-output-action.cpp | 6 +- src/widgets/ege-select-one-action.cpp | 32 +------ src/widgets/font-selector.cpp | 33 +------ src/widgets/gradient-image.cpp | 45 ---------- src/widgets/gradient-selector.cpp | 13 +-- src/widgets/gradient-selector.h | 8 -- src/widgets/gradient-vector.cpp | 65 +------------- src/widgets/gradient-vector.h | 8 -- src/widgets/icon.cpp | 51 ----------- src/widgets/ink-action.cpp | 39 +------- src/widgets/ink-comboboxentry-action.cpp | 14 --- src/widgets/paint-selector.cpp | 54 ++--------- src/widgets/paint-selector.h | 8 -- src/widgets/select-toolbar.cpp | 6 +- src/widgets/sp-color-selector.cpp | 6 -- src/widgets/sp-color-selector.h | 9 -- src/widgets/sp-widget.cpp | 30 ------- src/widgets/sp-xmlview-attr-list.cpp | 19 +--- src/widgets/sp-xmlview-content.cpp | 19 +--- src/widgets/sp-xmlview-tree.cpp | 20 +---- src/widgets/spw-utilities.cpp | 69 +------------- src/widgets/spw-utilities.h | 12 --- src/widgets/text-toolbar.cpp | 19 +--- 26 files changed, 29 insertions(+), 745 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/button.cpp b/src/widgets/button.cpp index 6ea8c1360..400cf2658 100644 --- a/src/widgets/button.cpp +++ b/src/widgets/button.cpp @@ -23,15 +23,8 @@ #include static void sp_button_dispose(GObject *object); - -#if GTK_CHECK_VERSION(3, 0, 0) static void sp_button_get_preferred_width(GtkWidget *widget, gint *minimal_width, gint *natural_width); - static void sp_button_get_preferred_height(GtkWidget *widget, gint *minimal_height, gint *natural_height); -#else -static void sp_button_size_request(GtkWidget *widget, GtkRequisition *requisition); -#endif - static void sp_button_clicked(GtkButton *button); static void sp_button_perform_action(SPButton *button, gpointer data); static gint sp_button_process_event(SPButton *button, GdkEvent *event); @@ -50,12 +43,8 @@ static void sp_button_class_init(SPButtonClass *klass) GtkButtonClass *button_class = GTK_BUTTON_CLASS(klass); object_class->dispose = sp_button_dispose; -#if GTK_CHECK_VERSION(3, 0, 0) widget_class->get_preferred_width = sp_button_get_preferred_width; widget_class->get_preferred_height = sp_button_get_preferred_height; -#else - widget_class->size_request = sp_button_size_request; -#endif button_class->clicked = sp_button_clicked; } @@ -92,7 +81,6 @@ static void sp_button_dispose(GObject *object) (G_OBJECT_CLASS(sp_button_parent_class))->dispose(object); } -#if GTK_CHECK_VERSION(3, 0, 0) static void sp_button_get_preferred_width(GtkWidget *widget, gint *minimal_width, gint *natural_width) { GtkWidget *child = gtk_bin_get_child(GTK_BIN(widget)); @@ -136,23 +124,6 @@ static void sp_button_get_preferred_height(GtkWidget *widget, gint *minimal_heig *minimal_height += MAX(2, padding.top + padding.bottom + border.top + border.bottom); *natural_height += MAX(2, padding.top + padding.bottom + border.top + border.bottom); } -#else -static void sp_button_size_request(GtkWidget *widget, GtkRequisition *requisition) -{ - GtkWidget *child = gtk_bin_get_child(GTK_BIN(widget)); - GtkStyle *style = gtk_widget_get_style(widget); - - if (child) { - gtk_widget_size_request(GTK_WIDGET(child), requisition); - } else { - requisition->width = 0; - requisition->height = 0; - } - - requisition->width += 2 + 2 * MAX(2, style->xthickness); - requisition->height += 2 + 2 * MAX(2, style->ythickness); -} -#endif static void sp_button_clicked(GtkButton *button) { diff --git a/src/widgets/eek-preview.cpp b/src/widgets/eek-preview.cpp index 9951a8957..5f1997672 100644 --- a/src/widgets/eek-preview.cpp +++ b/src/widgets/eek-preview.cpp @@ -194,7 +194,6 @@ static void eek_preview_size_request( GtkWidget* widget, GtkRequisition* req ) req->height = height; } -#if GTK_CHECK_VERSION(3,0,0) static void eek_preview_get_preferred_width(GtkWidget *widget, gint *minimal_width, gint *natural_width) { GtkRequisition requisition; @@ -208,7 +207,6 @@ static void eek_preview_get_preferred_height(GtkWidget *widget, gint *minimal_he eek_preview_size_request(widget, &requisition); *minimal_height = *natural_height = requisition.height; } -#endif enum { CLICKED_SIGNAL, @@ -219,22 +217,6 @@ enum { static guint eek_preview_signals[LAST_SIGNAL] = { 0 }; -#if !GTK_CHECK_VERSION(3,0,0) -static gboolean eek_preview_expose_event( GtkWidget* widget, GdkEventExpose* /* event */ ) -{ - gboolean result = FALSE; - - if (gtk_widget_is_drawable(widget)) { - GdkWindow* window = gtk_widget_get_window(widget); - cairo_t* cr = gdk_cairo_create(window); - result = eek_preview_draw(widget, cr); - cairo_destroy(cr); - } - - return result; -} -#endif - static gboolean eek_preview_draw(GtkWidget *widget, cairo_t *cr) @@ -246,14 +228,6 @@ gboolean eek_preview_draw(GtkWidget *widget, GtkAllocation allocation; gtk_widget_get_allocation(widget, &allocation); -#if !GTK_CHECK_VERSION(3,0,0) - GdkColor fg = { 0, - static_cast(priv->r), - static_cast(priv->g), - static_cast(priv->b) - }; -#endif - gint insetTop = 0, insetBottom = 0; gint insetLeft = 0, insetRight = 0; @@ -270,9 +244,7 @@ gboolean eek_preview_draw(GtkWidget *widget, insetLeft = insetRight = 1; } - -#if GTK_CHECK_VERSION(3,0,0) - GtkStyleContext *context = gtk_widget_get_style_context(widget); + auto context = gtk_widget_get_style_context(widget); gtk_render_frame(context, cr, @@ -283,22 +255,6 @@ gboolean eek_preview_draw(GtkWidget *widget, cr, 0, 0, allocation.width, allocation.height); -#else - GtkStyle *style = gtk_widget_get_style(widget); - GdkWindow *window = gtk_widget_get_window(widget); - - gtk_paint_flat_box( style, - window, - (GtkStateType)gtk_widget_get_state(widget), - GTK_SHADOW_NONE, - NULL, - widget, - NULL, - 0, 0, - allocation.width, allocation.height); - - gdk_colormap_alloc_color( gdk_colormap_get_system(), &fg, FALSE, TRUE ); -#endif // Border if (priv->border != BORDER_NONE) { @@ -377,27 +333,12 @@ gboolean eek_preview_draw(GtkWidget *widget, if (priv->linked & PREVIEW_LINK_IN) { -#if GTK_CHECK_VERSION(3,0,0) gtk_render_arrow(context, cr, G_PI, // Down-pointing arrow area.x, area.y, min(area.width, area.height) ); -#else - gtk_paint_arrow( style, - window, - gtk_widget_get_state (widget), - GTK_SHADOW_ETCHED_IN, - NULL, /* clip area. &area, */ - widget, /* may be NULL */ - NULL, /* detail */ - GTK_ARROW_DOWN, - FALSE, - area.x, area.y, - area.width, area.height - ); -#endif } if (priv->linked & PREVIEW_LINK_OUT) @@ -407,27 +348,12 @@ gboolean eek_preview_draw(GtkWidget *widget, otherArea.y = possible.y + (possible.height - otherArea.height); } -#if GTK_CHECK_VERSION(3,0,0) gtk_render_arrow(context, cr, G_PI, // Down-pointing arrow otherArea.x, otherArea.y, min(otherArea.width, otherArea.height) ); -#else - gtk_paint_arrow( style, - window, - gtk_widget_get_state (widget), - GTK_SHADOW_ETCHED_OUT, - NULL, /* clip area. &area, */ - widget, /* may be NULL */ - NULL, /* detail */ - GTK_ARROW_DOWN, - FALSE, - otherArea.x, otherArea.y, - otherArea.width, otherArea.height - ); -#endif } if (priv->linked & PREVIEW_LINK_OTHER) @@ -437,27 +363,12 @@ gboolean eek_preview_draw(GtkWidget *widget, otherArea.y = possible.y + (possible.height - otherArea.height) / 2; } -#if GTK_CHECK_VERSION(3,0,0) gtk_render_arrow(context, cr, 1.5*G_PI, // Left-pointing arrow otherArea.x, otherArea.y, min(otherArea.width, otherArea.height) ); -#else - gtk_paint_arrow( style, - window, - gtk_widget_get_state (widget), - GTK_SHADOW_ETCHED_OUT, - NULL, /* clip area. &area, */ - widget, /* may be NULL */ - NULL, /* detail */ - GTK_ARROW_LEFT, - FALSE, - otherArea.x, otherArea.y, - otherArea.width, otherArea.height - ); -#endif } @@ -469,22 +380,10 @@ gboolean eek_preview_draw(GtkWidget *widget, if ( otherArea.height < possible.height ) { otherArea.y = possible.y + (possible.height - otherArea.height) / 2; } -#if GTK_CHECK_VERSION(3,0,0) gtk_render_check(context, cr, otherArea.x, otherArea.y, otherArea.width, otherArea.height ); -#else - gtk_paint_check( style, - window, - gtk_widget_get_state (widget), - GTK_SHADOW_ETCHED_OUT, - NULL, - widget, - NULL, - otherArea.x, otherArea.y, - otherArea.width, otherArea.height ); -#endif } if (priv->linked & PREVIEW_STROKE) @@ -495,23 +394,11 @@ gboolean eek_preview_draw(GtkWidget *widget, if ( otherArea.height < possible.height ) { otherArea.y = possible.y + (possible.height - otherArea.height) / 2; } -#if GTK_CHECK_VERSION(3,0,0) // This should be a diamond too? gtk_render_check(context, cr, otherArea.x, otherArea.y, otherArea.width, otherArea.height ); -#else - gtk_paint_diamond( style, - window, - gtk_widget_get_state (widget), - GTK_SHADOW_ETCHED_OUT, - NULL, - widget, - NULL, - otherArea.x, otherArea.y, - otherArea.width, otherArea.height ); -#endif } } @@ -519,21 +406,10 @@ gboolean eek_preview_draw(GtkWidget *widget, if ( gtk_widget_has_focus(widget) ) { gtk_widget_get_allocation (widget, &allocation); -#if GTK_CHECK_VERSION(3,0,0) gtk_render_focus(context, cr, 0 + 1, 0 + 1, allocation.width - 2, allocation.height - 2 ); -#else - gtk_paint_focus( style, - window, - GTK_STATE_NORMAL, - NULL, /* GdkRectangle *area, */ - widget, - NULL, - 0 + 1, 0 + 1, - allocation.width - 2, allocation.height - 2 ); -#endif } return FALSE; @@ -547,11 +423,7 @@ static gboolean eek_preview_enter_cb( GtkWidget* widget, GdkEventCrossing* event EekPreviewPrivate *priv = EEK_PREVIEW_GET_PRIVATE(preview); priv->within = TRUE; -#if GTK_CHECK_VERSION(3,0,0) gtk_widget_set_state_flags( widget, priv->hot ? GTK_STATE_FLAG_ACTIVE : GTK_STATE_FLAG_PRELIGHT, false ); -#else - gtk_widget_set_state( widget, priv->hot ? GTK_STATE_ACTIVE : GTK_STATE_PRELIGHT ); -#endif } return FALSE; @@ -564,11 +436,7 @@ static gboolean eek_preview_leave_cb( GtkWidget* widget, GdkEventCrossing* event EekPreviewPrivate *priv = EEK_PREVIEW_GET_PRIVATE(preview); priv->within = FALSE; -#if GTK_CHECK_VERSION(3,0,0) gtk_widget_set_state_flags( widget, GTK_STATE_FLAG_NORMAL, false ); -#else - gtk_widget_set_state( widget, GTK_STATE_NORMAL ); -#endif } return FALSE; @@ -593,11 +461,7 @@ static gboolean eek_preview_button_press_cb( GtkWidget* widget, GdkEventButton* if ( priv->within ) { -#if GTK_CHECK_VERSION(3,0,0) gtk_widget_set_state_flags( widget, GTK_STATE_FLAG_ACTIVE, false ); -#else - gtk_widget_set_state( widget, GTK_STATE_ACTIVE ); -#endif } } } @@ -612,11 +476,7 @@ static gboolean eek_preview_button_release_cb( GtkWidget* widget, GdkEventButton EekPreviewPrivate *priv = EEK_PREVIEW_GET_PRIVATE(preview); priv->hot = FALSE; -#if GTK_CHECK_VERSION(3,0,0) gtk_widget_set_state_flags( widget, GTK_STATE_FLAG_NORMAL, false ); -#else - gtk_widget_set_state( widget, GTK_STATE_NORMAL ); -#endif if ( priv->within && (event->button == PRIME_BUTTON_MAGIC_NUMBER || @@ -697,15 +557,9 @@ static void eek_preview_class_init( EekPreviewClass *klass ) parent_class = (GtkWidgetClass*)g_type_class_peek_parent( klass ); -#if GTK_CHECK_VERSION(3,0,0) widgetClass->get_preferred_width = eek_preview_get_preferred_width; widgetClass->get_preferred_height = eek_preview_get_preferred_height; widgetClass->draw = eek_preview_draw; -#else - widgetClass->size_request = eek_preview_size_request; - widgetClass->expose_event = eek_preview_expose_event; -#endif - widgetClass->button_press_event = eek_preview_button_press_cb; widgetClass->button_release_event = eek_preview_button_release_cb; widgetClass->enter_notify_event = eek_preview_enter_cb; diff --git a/src/widgets/ege-adjustment-action.cpp b/src/widgets/ege-adjustment-action.cpp index 272217aa4..8fef21741 100644 --- a/src/widgets/ege-adjustment-action.cpp +++ b/src/widgets/ege-adjustment-action.cpp @@ -813,12 +813,8 @@ static GtkWidget* create_tool_item( GtkAction* action ) if ( IS_EGE_ADJUSTMENT_ACTION(action) ) { EgeAdjustmentAction* act = EGE_ADJUSTMENT_ACTION( action ); GtkWidget* spinbutton = 0; -#if GTK_CHECK_VERSION(3,0,0) - GtkWidget* hb = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5); + auto hb = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5); gtk_box_set_homogeneous(GTK_BOX(hb), FALSE); -#else - GtkWidget* hb = gtk_hbox_new( FALSE, 5 ); -#endif GValue value; memset( &value, 0, sizeof(value) ); g_value_init( &value, G_TYPE_STRING ); @@ -865,13 +861,7 @@ static GtkWidget* create_tool_item( GtkAction* action ) gtk_box_pack_start( GTK_BOX(hb), icon, FALSE, FALSE, 0 ); } else { GtkWidget* lbl = gtk_label_new( g_value_get_string( &value ) ? g_value_get_string( &value ) : "wwww" ); - -#if GTK_CHECK_VERSION(3,0,0) gtk_widget_set_halign(lbl, GTK_ALIGN_END); -#else - gtk_misc_set_alignment( GTK_MISC(lbl), 1.0, 0.5 ); -#endif - gtk_box_pack_start( GTK_BOX(hb), lbl, FALSE, FALSE, 0 ); } } diff --git a/src/widgets/ege-output-action.cpp b/src/widgets/ege-output-action.cpp index 5dece8e91..da29524a5 100644 --- a/src/widgets/ege-output-action.cpp +++ b/src/widgets/ege-output-action.cpp @@ -166,12 +166,8 @@ GtkWidget* create_tool_item( GtkAction* action ) if ( IS_EGE_OUTPUT_ACTION(action) ) { GValue value; -#if GTK_CHECK_VERSION(3,0,0) - GtkWidget* hb = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5); + auto hb = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5); gtk_box_set_homogeneous(GTK_BOX(hb), FALSE); -#else - GtkWidget* hb = gtk_hbox_new( FALSE, 5 ); -#endif GtkWidget* lbl = 0; memset( &value, 0, sizeof(value) ); diff --git a/src/widgets/ege-select-one-action.cpp b/src/widgets/ege-select-one-action.cpp index 2e106154e..5555663e4 100644 --- a/src/widgets/ege-select-one-action.cpp +++ b/src/widgets/ege-select-one-action.cpp @@ -632,12 +632,8 @@ GtkWidget* create_tool_item( GtkAction* action ) item = GTK_WIDGET( gtk_tool_item_new() ); if ( act->private_data->appearanceMode == APPEARANCE_FULL ) { -#if GTK_CHECK_VERSION(3,0,0) - GtkWidget* holder = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); + auto holder = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); gtk_box_set_homogeneous(GTK_BOX(holder), FALSE); -#else - GtkWidget* holder = gtk_hbox_new( FALSE, 0 ); -#endif GtkRadioAction* ract = 0; GSList* group = 0; @@ -744,12 +740,8 @@ GtkWidget* create_tool_item( GtkAction* action ) gtk_container_add( GTK_CONTAINER(item), holder ); } else { -#if GTK_CHECK_VERSION(3,0,0) - GtkWidget* holder = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4); + auto holder = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4); gtk_box_set_homogeneous(GTK_BOX(holder), FALSE); -#else - GtkWidget *holder = gtk_hbox_new( FALSE, 4 ); -#endif GtkEntry *entry = 0; GtkWidget *normal; @@ -818,14 +810,8 @@ GtkWidget* create_tool_item( GtkAction* action ) gtk_box_pack_start( GTK_BOX(holder), normal, FALSE, FALSE, 0 ); { -#if GTK_CHECK_VERSION(3,0,0) gtk_widget_set_halign(holder, GTK_ALIGN_START); gtk_container_add(GTK_CONTAINER(item), holder); -#else - GtkWidget *align = gtk_alignment_new(0, 0.5, 0, 0); - gtk_container_add( GTK_CONTAINER(align), holder); - gtk_container_add( GTK_CONTAINER(item), align ); -#endif } } @@ -861,13 +847,6 @@ void resync_active( EgeSelectOneAction* act, gint active, gboolean override ) if ( children && children->data ) { gpointer combodata = g_object_get_data( G_OBJECT(children->data), "ege-combo-box" ); -#if !GTK_CHECK_VERSION(3,0,0) - if (!combodata && GTK_IS_ALIGNMENT(children->data)) { - GList *other = gtk_container_get_children( GTK_CONTAINER(children->data) ); - combodata = g_object_get_data( G_OBJECT(other->data), "ege-combo-box" ); - } -#endif - if ( GTK_IS_COMBO_BOX(combodata) ) { GtkComboBox* combo = GTK_COMBO_BOX(combodata); if ((active == -1) && (gtk_combo_box_get_has_entry(combo))) { @@ -925,13 +904,6 @@ void resync_sensitive( EgeSelectOneAction* act ) if ( children && children->data ) { gpointer combodata = g_object_get_data( G_OBJECT(children->data), "ege-combo-box" ); -#if !GTK_CHECK_VERSION(3,0,0) - if (!combodata && GTK_IS_ALIGNMENT(children->data)) { - GList *other = gtk_container_get_children( GTK_CONTAINER(children->data) ); - combodata = g_object_get_data( G_OBJECT(other->data), "ege-combo-box" ); - } -#endif - if ( GTK_IS_COMBO_BOX(combodata) ) { /* Not implemented */ } else if ( GTK_IS_BOX(children->data) ) { diff --git a/src/widgets/font-selector.cpp b/src/widgets/font-selector.cpp index aefcb2e81..54b693ce0 100644 --- a/src/widgets/font-selector.cpp +++ b/src/widgets/font-selector.cpp @@ -36,11 +36,7 @@ struct SPFontSelector { -#if GTK_CHECK_VERSION(3,0,0) GtkBox hbox; -#else - GtkHBox hbox; -#endif unsigned int block_emit : 1; @@ -61,11 +57,7 @@ struct SPFontSelector struct SPFontSelectorClass { -#if GTK_CHECK_VERSION(3,0,0) GtkBoxClass parent_class; -#else - GtkHBoxClass parent_class; -#endif void (* font_set) (SPFontSelector *fsel, gchar *fontspec); }; @@ -91,11 +83,7 @@ static void sp_font_selector_set_sizes( SPFontSelector *fsel ); static guint fs_signals[LAST_SIGNAL] = { 0 }; -#if GTK_CHECK_VERSION(3,0,0) G_DEFINE_TYPE(SPFontSelector, sp_font_selector, GTK_TYPE_BOX); -#else -G_DEFINE_TYPE(SPFontSelector, sp_font_selector, GTK_TYPE_HBOX); -#endif static void sp_font_selector_class_init(SPFontSelectorClass *c) { @@ -160,8 +148,7 @@ static void sp_font_selector_init(SPFontSelector *fsel) /* Muck with style, see text-toolbar.cpp */ gtk_widget_set_name( GTK_WIDGET(fsel->family_treeview), "font_selector_family" ); -#if GTK_CHECK_VERSION(3,0,0) - GtkCssProvider *css_provider = gtk_css_provider_new(); + auto css_provider = gtk_css_provider_new(); gtk_css_provider_load_from_data(css_provider, "#font_selector_family {\n" " -GtkWidget-wide-separators: true;\n" @@ -169,14 +156,10 @@ static void sp_font_selector_init(SPFontSelector *fsel) "}\n", -1, NULL); - GdkScreen *screen = gdk_screen_get_default(); + auto screen = gdk_screen_get_default(); gtk_style_context_add_provider_for_screen(screen, GTK_STYLE_PROVIDER(css_provider), GTK_STYLE_PROVIDER_PRIORITY_USER); -#else - gtk_rc_parse_string ( - "widget \"*font_selector_family\" style \"fontfamily-separator-style\""); -#endif Inkscape::FontLister* fontlister = Inkscape::FontLister::get_instance(); Glib::RefPtr store = fontlister->get_font_list(); @@ -195,12 +178,8 @@ static void sp_font_selector_init(SPFontSelector *fsel) gtk_widget_show(f); gtk_box_pack_start(GTK_BOX (fsel), f, TRUE, TRUE, 0); -#if GTK_CHECK_VERSION(3,0,0) - GtkWidget *vb = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4); + auto vb = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4); gtk_box_set_homogeneous(GTK_BOX(vb), FALSE); -#else - GtkWidget *vb = gtk_vbox_new(FALSE, 4); -#endif gtk_widget_show(vb); gtk_container_set_border_width(GTK_CONTAINER (vb), 4); gtk_container_add(GTK_CONTAINER(f), vb); @@ -235,12 +214,8 @@ static void sp_font_selector_init(SPFontSelector *fsel) selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(fsel->style_treeview)); g_signal_connect (G_OBJECT(selection), "changed", G_CALLBACK (sp_font_selector_style_select_row), fsel); -#if GTK_CHECK_VERSION(3,0,0) - GtkWidget *hb = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4); + auto hb = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4); gtk_box_set_homogeneous(GTK_BOX(hb), FALSE); -#else - GtkWidget *hb = gtk_hbox_new(FALSE, 4); -#endif gtk_widget_show(hb); gtk_box_pack_start(GTK_BOX(vb), hb, FALSE, FALSE, 0); diff --git a/src/widgets/gradient-image.cpp b/src/widgets/gradient-image.cpp index 6901b8549..dff564feb 100644 --- a/src/widgets/gradient-image.cpp +++ b/src/widgets/gradient-image.cpp @@ -21,7 +21,6 @@ static void sp_gradient_image_size_request (GtkWidget *widget, GtkRequisition *requisition); -#if GTK_CHECK_VERSION(3,0,0) static void sp_gradient_image_destroy(GtkWidget *object); static void sp_gradient_image_get_preferred_width(GtkWidget *widget, gint *minimal_width, @@ -30,11 +29,6 @@ static void sp_gradient_image_get_preferred_width(GtkWidget *widget, static void sp_gradient_image_get_preferred_height(GtkWidget *widget, gint *minimal_height, gint *natural_height); -#else -static void sp_gradient_image_destroy(GtkObject *object); -static gboolean sp_gradient_image_expose(GtkWidget *widget, GdkEventExpose *event); -#endif - static gboolean sp_gradient_image_draw(GtkWidget *widget, cairo_t *cr); static void sp_gradient_image_gradient_release (SPObject *, SPGradientImage *im); static void sp_gradient_image_gradient_modified (SPObject *, guint flags, SPGradientImage *im); @@ -46,18 +40,10 @@ static void sp_gradient_image_class_init(SPGradientImageClass *klass) { GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); -#if GTK_CHECK_VERSION(3,0,0) widget_class->get_preferred_width = sp_gradient_image_get_preferred_width; widget_class->get_preferred_height = sp_gradient_image_get_preferred_height; widget_class->draw = sp_gradient_image_draw; widget_class->destroy = sp_gradient_image_destroy; -#else - GtkObjectClass *object_class = GTK_OBJECT_CLASS(klass); - - object_class->destroy = sp_gradient_image_destroy; - widget_class->size_request = sp_gradient_image_size_request; - widget_class->expose_event = sp_gradient_image_expose; -#endif } static void @@ -71,11 +57,7 @@ sp_gradient_image_init (SPGradientImage *image) new (&image->modified_connection) sigc::connection(); } -#if GTK_CHECK_VERSION(3,0,0) static void sp_gradient_image_destroy(GtkWidget *object) -#else -static void sp_gradient_image_destroy(GtkObject *object) -#endif { SPGradientImage *image = SP_GRADIENT_IMAGE (object); @@ -88,13 +70,8 @@ static void sp_gradient_image_destroy(GtkObject *object) image->release_connection.~connection(); image->modified_connection.~connection(); -#if GTK_CHECK_VERSION(3,0,0) if (GTK_WIDGET_CLASS(sp_gradient_image_parent_class)->destroy) GTK_WIDGET_CLASS(sp_gradient_image_parent_class)->destroy(object); -#else - if (GTK_OBJECT_CLASS(sp_gradient_image_parent_class)->destroy) - GTK_OBJECT_CLASS(sp_gradient_image_parent_class)->destroy(object); -#endif } static void sp_gradient_image_size_request(GtkWidget * /*widget*/, GtkRequisition *requisition) @@ -103,7 +80,6 @@ static void sp_gradient_image_size_request(GtkWidget * /*widget*/, GtkRequisitio requisition->height = 12; } -#if GTK_CHECK_VERSION(3,0,0) static void sp_gradient_image_get_preferred_width(GtkWidget *widget, gint *minimal_width, gint *natural_width) { GtkRequisition requisition; @@ -117,27 +93,6 @@ static void sp_gradient_image_get_preferred_height(GtkWidget *widget, gint *mini sp_gradient_image_size_request(widget, &requisition); *minimal_height = *natural_height = requisition.height; } -#endif - -#if !GTK_CHECK_VERSION(3,0,0) -static gboolean sp_gradient_image_expose(GtkWidget *widget, GdkEventExpose *event) -{ - gboolean result = TRUE; - if(gtk_widget_is_drawable(widget)) { - cairo_t *ct = gdk_cairo_create(gtk_widget_get_window (widget)); - cairo_rectangle(ct, event->area.x, event->area.y, - event->area.width, event->area.height); - cairo_clip(ct); - GtkAllocation allocation; - gtk_widget_get_allocation(widget, &allocation); - cairo_translate(ct, allocation.x, allocation.y); - result = sp_gradient_image_draw(widget, ct); - cairo_destroy(ct); - } - - return result; -} -#endif static gboolean sp_gradient_image_draw(GtkWidget *widget, cairo_t *ct) { diff --git a/src/widgets/gradient-selector.cpp b/src/widgets/gradient-selector.cpp index 604ecd108..7d88499ab 100644 --- a/src/widgets/gradient-selector.cpp +++ b/src/widgets/gradient-selector.cpp @@ -60,11 +60,7 @@ static void sp_gradient_selector_delete_vector_clicked (GtkWidget *w, SPGradient static guint signals[LAST_SIGNAL] = {0}; -#if GTK_CHECK_VERSION(3,0,0) G_DEFINE_TYPE(SPGradientSelector, sp_gradient_selector, GTK_TYPE_BOX); -#else -G_DEFINE_TYPE(SPGradientSelector, sp_gradient_selector, GTK_TYPE_VBOX); -#endif static void sp_gradient_selector_class_init(SPGradientSelectorClass *klass) { @@ -116,9 +112,7 @@ static void sp_gradient_selector_init(SPGradientSelector *sel) sel->safelyInit = true; sel->blocked = false; -#if GTK_CHECK_VERSION(3,0,0) gtk_orientable_set_orientation(GTK_ORIENTABLE(sel), GTK_ORIENTATION_VERTICAL); -#endif new (&sel->nonsolid) std::vector(); new (&sel->swatch_widgets) std::vector(); @@ -180,13 +174,8 @@ static void sp_gradient_selector_init(SPGradientSelector *sel) /* Create box for buttons */ -#if GTK_CHECK_VERSION(3,0,0) - GtkWidget *hb = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); + auto hb = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); gtk_box_set_homogeneous(GTK_BOX(hb), FALSE); -#else - GtkWidget *hb = gtk_hbox_new( FALSE, 2 ); -#endif - //sel->nonsolid.push_back(hb); gtk_box_pack_start( GTK_BOX(sel), hb, FALSE, FALSE, 0 ); sel->add = gtk_button_new(); diff --git a/src/widgets/gradient-selector.h b/src/widgets/gradient-selector.h index e090d7cbd..6b5d4ca60 100644 --- a/src/widgets/gradient-selector.h +++ b/src/widgets/gradient-selector.h @@ -45,11 +45,7 @@ class TreeView; struct SPGradientSelector { -#if GTK_CHECK_VERSION(3,0,0) GtkBox vbox; -#else - GtkVBox vbox; -#endif enum SelectorMode { MODE_LINEAR, @@ -131,11 +127,7 @@ struct SPGradientSelector { }; struct SPGradientSelectorClass { -#if GTK_CHECK_VERSION(3,0,0) GtkBoxClass parent_class; -#else - GtkVBoxClass parent_class; -#endif void (* grabbed) (SPGradientSelector *sel); void (* dragged) (SPGradientSelector *sel); diff --git a/src/widgets/gradient-vector.cpp b/src/widgets/gradient-vector.cpp index 97e65141f..ce571bb6f 100644 --- a/src/widgets/gradient-vector.cpp +++ b/src/widgets/gradient-vector.cpp @@ -66,11 +66,7 @@ enum { LAST_SIGNAL }; -#if GTK_CHECK_VERSION(3,0,0) static void sp_gradient_vector_selector_destroy(GtkWidget *object); -#else -static void sp_gradient_vector_selector_destroy(GtkObject *object); -#endif static void sp_gvs_gradient_release(SPObject *obj, SPGradientVectorSelector *gvs); static void sp_gvs_defs_release(SPObject *defs, SPGradientVectorSelector *gvs); @@ -89,11 +85,7 @@ static win_data wd; static gint x = -1000, y = -1000, w = 0, h = 0; // impossible original values to make sure they are read from prefs static Glib::ustring const prefs_path = "/dialogs/gradienteditor/"; -#if GTK_CHECK_VERSION(3,0,0) G_DEFINE_TYPE(SPGradientVectorSelector, sp_gradient_vector_selector, GTK_TYPE_BOX); -#else -G_DEFINE_TYPE(SPGradientVectorSelector, sp_gradient_vector_selector, GTK_TYPE_VBOX); -#endif static void sp_gradient_vector_selector_class_init(SPGradientVectorSelectorClass *klass) { @@ -108,20 +100,13 @@ static void sp_gradient_vector_selector_class_init(SPGradientVectorSelectorClass G_TYPE_NONE, 1, G_TYPE_POINTER); -#if GTK_CHECK_VERSION(3,0,0) GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass); widget_class->destroy = sp_gradient_vector_selector_destroy; -#else - GtkObjectClass *object_class = GTK_OBJECT_CLASS(klass); - object_class->destroy = sp_gradient_vector_selector_destroy; -#endif } static void sp_gradient_vector_selector_init(SPGradientVectorSelector *gvs) { -#if GTK_CHECK_VERSION(3,0,0) gtk_orientable_set_orientation(GTK_ORIENTABLE(gvs), GTK_ORIENTATION_VERTICAL); -#endif gvs->idlabel = TRUE; @@ -140,11 +125,7 @@ static void sp_gradient_vector_selector_init(SPGradientVectorSelector *gvs) } -#if GTK_CHECK_VERSION(3,0,0) static void sp_gradient_vector_selector_destroy(GtkWidget *object) -#else -static void sp_gradient_vector_selector_destroy(GtkObject *object) -#endif { SPGradientVectorSelector *gvs = SP_GRADIENT_VECTOR_SELECTOR(object); @@ -165,15 +146,9 @@ static void sp_gradient_vector_selector_destroy(GtkObject *object) gvs->defs_modified_connection.~connection(); gvs->tree_select_connection.~connection(); -#if GTK_CHECK_VERSION(3,0,0) if ((GTK_WIDGET_CLASS(sp_gradient_vector_selector_parent_class))->destroy) { (GTK_WIDGET_CLASS(sp_gradient_vector_selector_parent_class))->destroy(object); } -#else - if ((GTK_OBJECT_CLASS(sp_gradient_vector_selector_parent_class))->destroy) { - (GTK_OBJECT_CLASS(sp_gradient_vector_selector_parent_class))->destroy(object); - } -#endif } GtkWidget *sp_gradient_vector_selector_new(SPDocument *doc, SPGradient *gr) @@ -484,15 +459,8 @@ static GtkWidget *sp_gradient_vector_widget_new(SPGradient *gradient, SPStop *st static void sp_gradient_vector_widget_load_gradient(GtkWidget *widget, SPGradient *gradient); static gint sp_gradient_vector_dialog_delete(GtkWidget *widget, GdkEvent *event, GtkWidget *dialog); - -#if GTK_CHECK_VERSION(3,0,0) static void sp_gradient_vector_dialog_destroy(GtkWidget *object, gpointer data); static void sp_gradient_vector_widget_destroy(GtkWidget *object, gpointer data); -#else -static void sp_gradient_vector_dialog_destroy(GtkObject *object, gpointer data); -static void sp_gradient_vector_widget_destroy(GtkObject *object, gpointer data); -#endif - static void sp_gradient_vector_gradient_release(SPObject *obj, GtkWidget *widget); static void sp_gradient_vector_gradient_modified(SPObject *obj, guint flags, GtkWidget *widget); static void sp_gradient_vector_color_dragged(Inkscape::UI::SelectedColor *selected_color, GObject *object); @@ -845,12 +813,8 @@ static GtkWidget * sp_gradient_vector_widget_new(SPGradient *gradient, SPStop *s g_return_val_if_fail(gradient != NULL, NULL); g_return_val_if_fail(SP_IS_GRADIENT(gradient), NULL); -#if GTK_CHECK_VERSION(3,0,0) vb = gtk_box_new(GTK_ORIENTATION_VERTICAL, PAD); gtk_box_set_homogeneous(GTK_BOX(vb), FALSE); -#else - vb = gtk_vbox_new(FALSE, PAD); -#endif g_signal_connect(G_OBJECT(vb), "destroy", G_CALLBACK(sp_gradient_vector_widget_destroy), NULL); w = sp_gradient_image_new(gradient); @@ -883,12 +847,8 @@ static GtkWidget * sp_gradient_vector_widget_new(SPGradient *gradient, SPStop *s g_signal_connect(G_OBJECT(combo_box), "changed", G_CALLBACK(sp_grad_edit_combo_box_changed), vb); /* Add and Remove buttons */ -#if GTK_CHECK_VERSION(3,0,0) - GtkWidget *hb = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 1); + auto hb = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 1); gtk_box_set_homogeneous(GTK_BOX(hb), FALSE); -#else - GtkWidget *hb = gtk_hbox_new(FALSE, 1); -#endif // TRANSLATORS: "Stop" means: a "phase" of a gradient GtkWidget *b = gtk_button_new_with_label(_("Add stop")); gtk_widget_show(b); @@ -905,21 +865,12 @@ static GtkWidget * sp_gradient_vector_widget_new(SPGradient *gradient, SPStop *s gtk_box_pack_start(GTK_BOX(vb),hb, FALSE, FALSE, AUX_BETWEEN_BUTTON_GROUPS); /* Offset Slider and stuff */ -#if GTK_CHECK_VERSION(3,0,0) hb = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); gtk_box_set_homogeneous(GTK_BOX(hb), FALSE); -#else - hb = gtk_hbox_new(FALSE, 0); -#endif /* Label */ GtkWidget *l = gtk_label_new(C_("Gradient","Offset:")); - -#if GTK_CHECK_VERSION(3,0,0) gtk_widget_set_halign(l, GTK_ALIGN_END); -#else - gtk_misc_set_alignment(GTK_MISC(l), 1.0, 0.5); -#endif gtk_box_pack_start(GTK_BOX(hb),l, FALSE, FALSE, AUX_BETWEEN_BUTTON_GROUPS); gtk_widget_show(l); @@ -937,11 +888,7 @@ static GtkWidget * sp_gradient_vector_widget_new(SPGradient *gradient, SPStop *s gtk_adjustment_set_value(Offset_adj, stop->offset); /* Slider */ -#if GTK_CHECK_VERSION(3,0,0) - GtkWidget *slider = gtk_scale_new(GTK_ORIENTATION_HORIZONTAL, Offset_adj); -#else - GtkWidget *slider = gtk_hscale_new(Offset_adj); -#endif + auto slider = gtk_scale_new(GTK_ORIENTATION_HORIZONTAL, Offset_adj); gtk_scale_set_draw_value( GTK_SCALE(slider), FALSE ); gtk_widget_show(slider); gtk_box_pack_start(GTK_BOX(hb),slider, TRUE, TRUE, AUX_BETWEEN_BUTTON_GROUPS); @@ -1179,11 +1126,7 @@ static void sp_gradient_vector_widget_load_gradient(GtkWidget *widget, SPGradien blocked = FALSE; } -#if GTK_CHECK_VERSION(3,0,0) static void sp_gradient_vector_dialog_destroy(GtkWidget * /*object*/, gpointer /*data*/) -#else -static void sp_gradient_vector_dialog_destroy(GtkObject * /*object*/, gpointer /*data*/) -#endif { GObject *obj = G_OBJECT(dlg); assert(obj != NULL); @@ -1234,11 +1177,7 @@ static gboolean sp_gradient_vector_dialog_delete(GtkWidget */*widget*/, GdkEvent } /* Widget destroy handler */ -#if GTK_CHECK_VERSION(3,0,0) static void sp_gradient_vector_widget_destroy(GtkWidget *object, gpointer /*data*/) -#else -static void sp_gradient_vector_widget_destroy(GtkObject *object, gpointer /*data*/) -#endif { SPObject *gradient = SP_OBJECT(g_object_get_data(G_OBJECT(object), "gradient")); diff --git a/src/widgets/gradient-vector.h b/src/widgets/gradient-vector.h index 5ae90b28f..b51b276b9 100644 --- a/src/widgets/gradient-vector.h +++ b/src/widgets/gradient-vector.h @@ -35,11 +35,7 @@ class SPGradient; class SPStop; struct SPGradientVectorSelector { -#if GTK_CHECK_VERSION(3,0,0) GtkBox vbox; -#else - GtkVBox vbox; -#endif guint idlabel : 1; @@ -61,11 +57,7 @@ struct SPGradientVectorSelector { }; struct SPGradientVectorSelectorClass { -#if GTK_CHECK_VERSION(3,0,0) GtkBoxClass parent_class; -#else - GtkVBoxClass parent_class; -#endif void (* vector_set) (SPGradientVectorSelector *gvs, SPGradient *gr); }; diff --git a/src/widgets/icon.cpp b/src/widgets/icon.cpp index f2031fe51..38b4f2897 100644 --- a/src/widgets/icon.cpp +++ b/src/widgets/icon.cpp @@ -64,10 +64,6 @@ struct IconImpl { static void sizeAllocate(GtkWidget *widget, GtkAllocation *allocation); static gboolean draw(GtkWidget *widget, cairo_t *cr); -#if !GTK_CHECK_VERSION(3,0,0) - static gboolean expose(GtkWidget *widget, GdkEventExpose *event); -#endif - static void screenChanged( GtkWidget *widget, GdkScreen *previous_screen ); static void styleSet( GtkWidget *widget, GtkStyle *previous_style ); static void themeChanged( SPIcon *icon ); @@ -149,14 +145,9 @@ sp_icon_class_init(SPIconClass *klass) object_class->dispose = IconImpl::dispose; -#if GTK_CHECK_VERSION(3,0,0) widget_class->get_preferred_width = IconImpl::getPreferredWidth; widget_class->get_preferred_height = IconImpl::getPreferredHeight; widget_class->draw = IconImpl::draw; -#else - widget_class->size_request = IconImpl::sizeRequest; - widget_class->expose_event = IconImpl::expose; -#endif widget_class->size_allocate = IconImpl::sizeAllocate; widget_class->screen_changed = IconImpl::screenChanged; widget_class->style_set = IconImpl::styleSet; @@ -244,37 +235,15 @@ gboolean IconImpl::draw(GtkWidget *widget, cairo_t* cr) bool unref_image = false; /* copied from the expose function of GtkImage */ -#if GTK_CHECK_VERSION(3,0,0) if (gtk_widget_get_state_flags (GTK_WIDGET(icon)) != GTK_STATE_FLAG_NORMAL && image) { -#else - if (gtk_widget_get_state (GTK_WIDGET(icon)) != GTK_STATE_NORMAL && image) { - std::cerr << "IconImpl::draw: Ooops! It is called in GTK2" << std::endl; -#endif std::cerr << "IconImpl::draw: No image, creating fallback" << std::endl; -#if GTK_CHECK_VERSION(3,0,0) - // image = gtk_render_icon_pixbuf(gtk_widget_get_style_context(widget), - // source, - // (GtkIconSize)-1); - - // gtk_render_icon_pixbuf deprecated, replaced by: GtkIconTheme *icon_theme = gtk_icon_theme_get_default(); image = gtk_icon_theme_load_icon (icon_theme, "gtk-image", 32, (GtkIconLookupFlags)0, NULL); -#else - GtkIconSource *source = gtk_icon_source_new(); - gtk_icon_source_set_pixbuf(source, icon->pb); - gtk_icon_source_set_size(source, GTK_ICON_SIZE_SMALL_TOOLBAR); // note: this is boilerplate and not used - gtk_icon_source_set_size_wildcarded(source, FALSE); - image = gtk_style_render_icon(gtk_widget_get_style(widget), source, - gtk_widget_get_direction(widget), - (GtkStateType) gtk_widget_get_state(widget), - (GtkIconSize)-1, widget, "gtk-image"); - gtk_icon_source_free(source); -#endif unref_image = true; } @@ -283,12 +252,7 @@ gboolean IconImpl::draw(GtkWidget *widget, cairo_t* cr) GtkAllocation allocation; GtkRequisition requisition; gtk_widget_get_allocation(widget, &allocation); - -#if GTK_CHECK_VERSION(3,0,0) gtk_widget_get_preferred_size(widget, &requisition, NULL); -#else - gtk_widget_get_requisition(widget, &requisition); -#endif int x = floor(allocation.x + ((allocation.width - requisition.width) * 0.5)); int y = floor(allocation.y + ((allocation.height - requisition.height) * 0.5)); @@ -308,21 +272,6 @@ gboolean IconImpl::draw(GtkWidget *widget, cairo_t* cr) return TRUE; } -#if !GTK_CHECK_VERSION(3,0,0) -gboolean IconImpl::expose(GtkWidget *widget, GdkEventExpose * /*event*/) -{ - gboolean result = TRUE; - - if (gtk_widget_is_drawable(widget)) { - cairo_t * cr = gdk_cairo_create(gtk_widget_get_window(widget)); - result = draw(widget, cr); - cairo_destroy(cr); - } - - return result; -} -#endif - // PUBLIC CALL: void sp_icon_fetch_pixbuf( SPIcon *icon ) { diff --git a/src/widgets/ink-action.cpp b/src/widgets/ink-action.cpp index ace99d9aa..52999dcce 100644 --- a/src/widgets/ink-action.cpp +++ b/src/widgets/ink-action.cpp @@ -2,18 +2,12 @@ #include "icon-size.h" #include - +#include "widgets/image-menu-item.h" #include "widgets/ink-action.h" - #include "widgets/button.h" #include -#if GTK_CHECK_VERSION(3,0,0) - // Fork of gtk-imagemenuitem to continue support - #include "widgets/image-menu-item.h" - -#endif static void ink_action_finalize( GObject* obj ); static void ink_action_get_property( GObject* obj, guint propId, GValue* value, GParamSpec * pspec ); @@ -165,12 +159,7 @@ static GtkWidget* ink_action_create_menu_item( GtkAction* action ) if ( act->private_data->iconId ) { gchar* label = 0; g_object_get( G_OBJECT(act), "label", &label, NULL ); - -#if GTK_CHECK_VERSION(3,0,0) item = image_menu_item_new_with_mnemonic( label ); -#else - item = gtk_image_menu_item_new_with_mnemonic( label ); -#endif GtkWidget* child = sp_icon_new( Inkscape::ICON_SIZE_MENU, act->private_data->iconId ); // TODO this work-around is until SPIcon will live properly inside of a popup menu @@ -185,12 +174,7 @@ static GtkWidget* ink_action_create_menu_item( GtkAction* action ) } } gtk_widget_show_all( child ); - -#if GTK_CHECK_VERSION(3,0,0) image_menu_item_set_image( IMAGE_MENU_ITEM(item), child ); -#else - gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM(item), child ); -#endif g_free( label ); label = 0; @@ -393,15 +377,9 @@ static GtkWidget* ink_toggle_action_create_tool_item( GtkAction* action ) if ( act->private_data->iconId ) { GtkWidget* child = sp_icon_new( act->private_data->iconSize, act->private_data->iconId ); -#if GTK_CHECK_VERSION(3,0,0) gtk_widget_set_hexpand(child, FALSE); gtk_widget_set_vexpand(child, FALSE); gtk_tool_button_set_icon_widget(button, child); -#else - GtkWidget* align = gtk_alignment_new( 0.5, 0.5, 0.0, 0.0 ); - gtk_container_add( GTK_CONTAINER(align), child ); - gtk_tool_button_set_icon_widget( button, align ); -#endif } else { gchar *label = 0; g_object_get( G_OBJECT(action), "short_label", &label, NULL ); @@ -430,18 +408,10 @@ static void ink_toggle_action_update_icon( InkToggleAction* action ) GtkToolButton* button = GTK_TOOL_BUTTON(proxies->data); GtkWidget* child = sp_icon_new( action->private_data->iconSize, action->private_data->iconId ); - -#if GTK_CHECK_VERSION(3,0,0) gtk_widget_set_hexpand(child, FALSE); gtk_widget_set_vexpand(child, FALSE); gtk_widget_show_all(child); gtk_tool_button_set_icon_widget(button, child); -#else - GtkWidget* align = gtk_alignment_new( 0.5, 0.5, 0.0, 0.0 ); - gtk_container_add( GTK_CONTAINER(align), child ); - gtk_widget_show_all( align ); - gtk_tool_button_set_icon_widget( button, align ); -#endif } } @@ -610,16 +580,9 @@ static GtkWidget* ink_radio_action_create_tool_item( GtkAction* action ) GtkToolButton* button = GTK_TOOL_BUTTON(item); GtkWidget* child = sp_icon_new( act->private_data->iconSize, act->private_data->iconId ); - -#if GTK_CHECK_VERSION(3,0,0) gtk_widget_set_hexpand(child, FALSE); gtk_widget_set_vexpand(child, FALSE); gtk_tool_button_set_icon_widget(button, child); -#else - GtkWidget* align = gtk_alignment_new( 0.5, 0.5, 0.0, 0.0 ); - gtk_container_add( GTK_CONTAINER(align), child ); - gtk_tool_button_set_icon_widget( button, align ); -#endif } else { // For now trigger a warning but don't do anything else GtkToolButton* button = GTK_TOOL_BUTTON(item); diff --git a/src/widgets/ink-comboboxentry-action.cpp b/src/widgets/ink-comboboxentry-action.cpp index ec5e26cf5..2fecb06a4 100644 --- a/src/widgets/ink-comboboxentry-action.cpp +++ b/src/widgets/ink-comboboxentry-action.cpp @@ -371,16 +371,10 @@ GtkWidget* create_tool_item( GtkAction* action ) g_free( combobox_name ); { -#if GTK_CHECK_VERSION(3,0,0) gtk_widget_set_halign(comboBoxEntry, GTK_ALIGN_START); gtk_widget_set_hexpand(comboBoxEntry, FALSE); gtk_widget_set_vexpand(comboBoxEntry, FALSE); gtk_container_add(GTK_CONTAINER(item), comboBoxEntry); -#else - GtkWidget *align = gtk_alignment_new(0, 0.5, 0, 0); - gtk_container_add( GTK_CONTAINER(align), comboBoxEntry ); - gtk_container_add( GTK_CONTAINER(item), align ); -#endif } ink_comboboxentry_action->combobox = GTK_COMBO_BOX (comboBoxEntry); @@ -414,11 +408,7 @@ GtkWidget* create_tool_item( GtkAction* action ) // Optionally widen the combobox width... which widens the drop-down list in list mode. if( ink_comboboxentry_action->extra_width > 0 ) { GtkRequisition req; -#if GTK_CHECK_VERSION(3,0,0) gtk_widget_get_preferred_size(GTK_WIDGET(ink_comboboxentry_action->combobox), &req, NULL); -#else - gtk_widget_size_request( GTK_WIDGET( ink_comboboxentry_action->combobox ), &req ); -#endif gtk_widget_set_size_request( GTK_WIDGET( ink_comboboxentry_action->combobox ), req.width + ink_comboboxentry_action->extra_width, -1 ); } @@ -635,11 +625,7 @@ void ink_comboboxentry_action_set_extra_width( Ink_ComboBoxEntry_Action* action, // Widget may not have been created.... if( action->combobox ) { GtkRequisition req; -#if GTK_CHECK_VERSION(3,0,0) gtk_widget_get_preferred_size(GTK_WIDGET(action->combobox), &req, NULL); -#else - gtk_widget_size_request( GTK_WIDGET( action->combobox ), &req ); -#endif gtk_widget_set_size_request( GTK_WIDGET( action->combobox ), req.width + action->extra_width, -1 ); } } diff --git a/src/widgets/paint-selector.cpp b/src/widgets/paint-selector.cpp index 58a178aec..a554f3cde 100644 --- a/src/widgets/paint-selector.cpp +++ b/src/widgets/paint-selector.cpp @@ -134,11 +134,7 @@ static SPGradientSelector *getGradientFromData(SPPaintSelector const *psel) return grad; } -#if GTK_CHECK_VERSION(3,0,0) G_DEFINE_TYPE(SPPaintSelector, sp_paint_selector, GTK_TYPE_BOX); -#else -G_DEFINE_TYPE(SPPaintSelector, sp_paint_selector, GTK_TYPE_VBOX); -#endif static void sp_paint_selector_class_init(SPPaintSelectorClass *klass) @@ -197,19 +193,13 @@ sp_paint_selector_class_init(SPPaintSelectorClass *klass) static void sp_paint_selector_init(SPPaintSelector *psel) { -#if GTK_CHECK_VERSION(3,0,0) gtk_orientable_set_orientation(GTK_ORIENTABLE(psel), GTK_ORIENTATION_VERTICAL); -#endif psel->mode = static_cast(-1); // huh? do you mean 0xff? -- I think this means "not in the enum" /* Paint style button box */ -#if GTK_CHECK_VERSION(3,0,0) psel->style = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); gtk_box_set_homogeneous(GTK_BOX(psel->style), FALSE); -#else - psel->style = gtk_hbox_new(FALSE, 0); -#endif gtk_widget_show(psel->style); gtk_container_set_border_width(GTK_CONTAINER(psel->style), 4); gtk_box_pack_start(GTK_BOX(psel), psel->style, FALSE, FALSE, 0); @@ -236,12 +226,8 @@ sp_paint_selector_init(SPPaintSelector *psel) /* Fillrule */ { -#if GTK_CHECK_VERSION(3,0,0) - psel->fillrulebox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); - gtk_box_set_homogeneous(GTK_BOX(psel->fillrulebox), FALSE); -#else - psel->fillrulebox = gtk_hbox_new(FALSE, 0); -#endif + psel->fillrulebox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); + gtk_box_set_homogeneous(GTK_BOX(psel->fillrulebox), FALSE); gtk_box_pack_end(GTK_BOX(psel->style), psel->fillrulebox, FALSE, FALSE, 0); GtkWidget *w; @@ -270,22 +256,14 @@ sp_paint_selector_init(SPPaintSelector *psel) /* Frame */ psel->label = gtk_label_new(""); -#if GTK_CHECK_VERSION(3,0,0) - GtkWidget *lbbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4); + auto lbbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4); gtk_box_set_homogeneous(GTK_BOX(lbbox), FALSE); -#else - GtkWidget *lbbox = gtk_hbox_new(FALSE, 4); -#endif gtk_widget_show(psel->label); gtk_box_pack_start(GTK_BOX(lbbox), psel->label, false, false, 4); gtk_box_pack_start(GTK_BOX(psel), lbbox, false, false, 4); -#if GTK_CHECK_VERSION(3,0,0) psel->frame = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4); gtk_box_set_homogeneous(GTK_BOX(psel->frame), FALSE); -#else - psel->frame = gtk_vbox_new(FALSE, 4); -#endif gtk_widget_show(psel->frame); //gtk_container_set_border_width(GTK_CONTAINER(psel->frame), 0); gtk_box_pack_start(GTK_BOX(psel), psel->frame, TRUE, TRUE, 0); @@ -700,12 +678,8 @@ static void sp_paint_selector_set_mode_color(SPPaintSelector *psel, SPPaintSelec sp_paint_selector_clear_frame(psel); /* Create new color selector */ /* Create vbox */ -#if GTK_CHECK_VERSION(3,0,0) - GtkWidget *vb = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4); - gtk_box_set_homogeneous(GTK_BOX(vb), FALSE); -#else - GtkWidget *vb = gtk_vbox_new(FALSE, 4); -#endif + auto vb = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4); + gtk_box_set_homogeneous(GTK_BOX(vb), FALSE); gtk_widget_show(vb); /* Color selector */ @@ -1046,21 +1020,13 @@ static void sp_paint_selector_set_mode_pattern(SPPaintSelector *psel, SPPaintSel sp_paint_selector_clear_frame(psel); /* Create vbox */ -#if GTK_CHECK_VERSION(3,0,0) tbl = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4); gtk_box_set_homogeneous(GTK_BOX(tbl), FALSE); -#else - tbl = gtk_vbox_new(FALSE, 4); -#endif gtk_widget_show(tbl); { -#if GTK_CHECK_VERSION(3,0,0) - GtkWidget *hb = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 1); + auto hb = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 1); gtk_box_set_homogeneous(GTK_BOX(hb), FALSE); -#else - GtkWidget *hb = gtk_hbox_new(FALSE, 1); -#endif /** * Create a combo_box and store with 4 columns, @@ -1088,13 +1054,9 @@ static void sp_paint_selector_set_mode_pattern(SPPaintSelector *psel, SPPaintSel } { -#if GTK_CHECK_VERSION(3,0,0) - GtkWidget *hb = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); + auto hb = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); gtk_box_set_homogeneous(GTK_BOX(hb), FALSE); -#else - GtkWidget *hb = gtk_hbox_new(FALSE, 0); -#endif - GtkWidget *l = gtk_label_new(NULL); + auto l = gtk_label_new(NULL); gtk_label_set_markup(GTK_LABEL(l), _("Use the Node tool to adjust position, scale, and rotation of the pattern on canvas. Use Object > Pattern > Objects to Pattern to create a new pattern from selection.")); gtk_label_set_line_wrap(GTK_LABEL(l), true); gtk_widget_set_size_request(l, 180, -1); diff --git a/src/widgets/paint-selector.h b/src/widgets/paint-selector.h index 23c2dd456..dde14b6a6 100644 --- a/src/widgets/paint-selector.h +++ b/src/widgets/paint-selector.h @@ -40,11 +40,7 @@ class SPStyle; * Generic paint selector widget. */ struct SPPaintSelector { -#if GTK_CHECK_VERSION(3,0,0) GtkBox vbox; -#else - GtkVBox vbox; -#endif enum Mode { MODE_EMPTY, @@ -130,11 +126,7 @@ enum {COMBO_COL_LABEL=0, COMBO_COL_STOCK=1, COMBO_COL_PATTERN=2, COMBO_COL_SEP=3 /// The SPPaintSelector vtable struct SPPaintSelectorClass { -#if GTK_CHECK_VERSION(3,0,0) GtkBoxClass parent_class; -#else - GtkVBoxClass parent_class; -#endif void (* mode_changed) (SPPaintSelector *psel, SPPaintSelector::Mode mode); diff --git a/src/widgets/select-toolbar.cpp b/src/widgets/select-toolbar.cpp index 9851b0606..7dfa18f49 100644 --- a/src/widgets/select-toolbar.cpp +++ b/src/widgets/select-toolbar.cpp @@ -415,12 +415,8 @@ void sp_select_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GOb g_object_set_data(G_OBJECT(spw), "dtw", desktop->getCanvas()); // The vb frame holds all other widgets and is used to set sensitivity depending on selection state. -#if GTK_CHECK_VERSION(3,0,0) - GtkWidget *vb = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); + auto vb = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); gtk_box_set_homogeneous(GTK_BOX(vb), FALSE); -#else - GtkWidget *vb = gtk_hbox_new(FALSE, 0); -#endif gtk_widget_show(vb); gtk_container_add(GTK_CONTAINER(spw), vb); diff --git a/src/widgets/sp-color-selector.cpp b/src/widgets/sp-color-selector.cpp index 93eaaee8b..1d448b67b 100644 --- a/src/widgets/sp-color-selector.cpp +++ b/src/widgets/sp-color-selector.cpp @@ -32,11 +32,7 @@ static guint csel_signals[LAST_SIGNAL] = {0}; double ColorSelector::_epsilon = 1e-4; -#if GTK_CHECK_VERSION(3,0,0) G_DEFINE_TYPE(SPColorSelector, sp_color_selector, GTK_TYPE_BOX); -#else -G_DEFINE_TYPE(SPColorSelector, sp_color_selector, GTK_TYPE_VBOX); -#endif void sp_color_selector_class_init( SPColorSelectorClass *klass ) { @@ -86,9 +82,7 @@ void sp_color_selector_class_init( SPColorSelectorClass *klass ) void sp_color_selector_init( SPColorSelector *csel ) { -#if GTK_CHECK_VERSION(3,0,0) gtk_orientable_set_orientation(GTK_ORIENTABLE(csel), GTK_ORIENTATION_VERTICAL); -#endif if ( csel->base ) { diff --git a/src/widgets/sp-color-selector.h b/src/widgets/sp-color-selector.h index 75cb79b00..14a9fccdf 100644 --- a/src/widgets/sp-color-selector.h +++ b/src/widgets/sp-color-selector.h @@ -64,21 +64,12 @@ private: #define SP_COLOR_SELECTOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SP_TYPE_COLOR_SELECTOR, SPColorSelectorClass)) struct SPColorSelector { -#if GTK_CHECK_VERSION(3,0,0) GtkBox vbox; -#else - GtkVBox vbox; -#endif - ColorSelector* base; }; struct SPColorSelectorClass { -#if GTK_CHECK_VERSION(3,0,0) GtkBoxClass parent_class; -#else - GtkVBoxClass parent_class; -#endif const gchar **name; guint submode_count; diff --git a/src/widgets/sp-widget.cpp b/src/widgets/sp-widget.cpp index 5ab6b1bb5..0a4e722a5 100644 --- a/src/widgets/sp-widget.cpp +++ b/src/widgets/sp-widget.cpp @@ -41,7 +41,6 @@ public: static void show(GtkWidget *widget); static void hide(GtkWidget *widget); -#if GTK_CHECK_VERSION(3,0,0) static void getPreferredWidth(GtkWidget *widget, gint *minimal_width, gint *natural_width); @@ -50,10 +49,6 @@ public: gint *minimal_height, gint *natural_height); static gboolean draw(GtkWidget *widget, cairo_t *cr); -#else - static void sizeRequest(GtkWidget *widget, GtkRequisition *requisition); - static gboolean expose(GtkWidget *widget, GdkEventExpose *event); -#endif static void sizeAllocate(GtkWidget *widget, GtkAllocation *allocation); static void modifySelectionCB(Selection *selection, guint flags, SPWidget *spw); @@ -120,14 +115,9 @@ sp_widget_class_init(SPWidgetClass *klass) widget_class->show = SPWidgetImpl::show; widget_class->hide = SPWidgetImpl::hide; -#if GTK_CHECK_VERSION(3,0,0) widget_class->get_preferred_width = SPWidgetImpl::getPreferredWidth; widget_class->get_preferred_height = SPWidgetImpl::getPreferredHeight; widget_class->draw = SPWidgetImpl::draw; -#else - widget_class->size_request = SPWidgetImpl::sizeRequest; - widget_class->expose_event = SPWidgetImpl::expose; -#endif widget_class->size_allocate = SPWidgetImpl::sizeAllocate; } @@ -207,27 +197,18 @@ void SPWidgetImpl::hide(GtkWidget *widget) } } -#if GTK_CHECK_VERSION(3,0,0) gboolean SPWidgetImpl::draw(GtkWidget *widget, cairo_t *cr) -#else -gboolean SPWidgetImpl::expose(GtkWidget *widget, GdkEventExpose *event) -#endif { GtkBin *bin = GTK_BIN(widget); GtkWidget *child = gtk_bin_get_child(bin); if (child) { -#if GTK_CHECK_VERSION(3,0,0) gtk_container_propagate_draw(GTK_CONTAINER(widget), child, cr); -#else - gtk_container_propagate_expose(GTK_CONTAINER(widget), child, event); -#endif } return FALSE; } -#if GTK_CHECK_VERSION(3,0,0) void SPWidgetImpl::getPreferredWidth(GtkWidget *widget, gint *minimal_width, gint *natural_width) { GtkBin *bin = GTK_BIN(widget); @@ -247,17 +228,6 @@ void SPWidgetImpl::getPreferredHeight(GtkWidget *widget, gint *minimal_height, g gtk_widget_get_preferred_height(child, minimal_height, natural_height); } } -#else -void SPWidgetImpl::sizeRequest(GtkWidget *widget, GtkRequisition *requisition) -{ - GtkBin *bin = GTK_BIN(widget); - GtkWidget *child = gtk_bin_get_child(bin); - - if (child) { - gtk_widget_size_request(child, requisition); - } -} -#endif void SPWidgetImpl::sizeAllocate(GtkWidget *widget, GtkAllocation *allocation) { diff --git a/src/widgets/sp-xmlview-attr-list.cpp b/src/widgets/sp-xmlview-attr-list.cpp index a4c00db7c..8fe01a33d 100644 --- a/src/widgets/sp-xmlview-attr-list.cpp +++ b/src/widgets/sp-xmlview-attr-list.cpp @@ -20,11 +20,7 @@ #include "../xml/node-event-vector.h" #include "sp-xmlview-attr-list.h" -#if GTK_CHECK_VERSION(3,0,0) static void sp_xmlview_attr_list_destroy(GtkWidget * object); -#else -static void sp_xmlview_attr_list_destroy(GtkObject * object); -#endif static void event_attr_changed (Inkscape::XML::Node * repr, const gchar * name, const gchar * old_value, const gchar * new_value, bool is_interactive, gpointer data); @@ -87,13 +83,8 @@ G_DEFINE_TYPE(SPXMLViewAttrList, sp_xmlview_attr_list, GTK_TYPE_TREE_VIEW); void sp_xmlview_attr_list_class_init (SPXMLViewAttrListClass * klass) { -#if GTK_CHECK_VERSION(3,0,0) - GtkWidgetClass * widget_class = GTK_WIDGET_CLASS(klass); + auto widget_class = GTK_WIDGET_CLASS(klass); widget_class->destroy = sp_xmlview_attr_list_destroy; -#else - GtkObjectClass * object_class = GTK_OBJECT_CLASS(klass); - object_class->destroy = sp_xmlview_attr_list_destroy; -#endif g_signal_new("row-value-changed", G_TYPE_FROM_CLASS(klass), @@ -112,11 +103,7 @@ sp_xmlview_attr_list_init (SPXMLViewAttrList * list) list->repr = NULL; } -#if GTK_CHECK_VERSION(3,0,0) void sp_xmlview_attr_list_destroy(GtkWidget * object) -#else -void sp_xmlview_attr_list_destroy(GtkObject * object) -#endif { SPXMLViewAttrList * list; @@ -125,11 +112,7 @@ void sp_xmlview_attr_list_destroy(GtkObject * object) g_object_unref(list->store); sp_xmlview_attr_list_set_repr (list, NULL); -#if GTK_CHECK_VERSION(3,0,0) GTK_WIDGET_CLASS(sp_xmlview_attr_list_parent_class)->destroy (object); -#else - GTK_OBJECT_CLASS(sp_xmlview_attr_list_parent_class)->destroy (object); -#endif } void sp_xmlview_attr_list_select_row_by_key(SPXMLViewAttrList * list, const gchar *name) diff --git a/src/widgets/sp-xmlview-content.cpp b/src/widgets/sp-xmlview-content.cpp index a1d8475ba..6e59ba3cd 100644 --- a/src/widgets/sp-xmlview-content.cpp +++ b/src/widgets/sp-xmlview-content.cpp @@ -23,11 +23,7 @@ using Inkscape::DocumentUndo; -#if GTK_CHECK_VERSION(3,0,0) static void sp_xmlview_content_destroy(GtkWidget * object); -#else -static void sp_xmlview_content_destroy(GtkObject * object); -#endif void sp_xmlview_content_changed (GtkTextBuffer *tb, SPXMLViewContent *text); @@ -80,13 +76,8 @@ G_DEFINE_TYPE(SPXMLViewContent, sp_xmlview_content, GTK_TYPE_TEXT_VIEW); void sp_xmlview_content_class_init(SPXMLViewContentClass * klass) { -#if GTK_CHECK_VERSION(3,0,0) - GtkWidgetClass * widget_class = GTK_WIDGET_CLASS(klass); + auto widget_class = GTK_WIDGET_CLASS(klass); widget_class->destroy = sp_xmlview_content_destroy; -#else - GtkObjectClass * object_class = GTK_OBJECT_CLASS(klass); - object_class->destroy = sp_xmlview_content_destroy; -#endif } void @@ -96,21 +87,13 @@ sp_xmlview_content_init (SPXMLViewContent *text) text->blocked = FALSE; } -#if GTK_CHECK_VERSION(3,0,0) void sp_xmlview_content_destroy(GtkWidget * object) -#else -void sp_xmlview_content_destroy(GtkObject * object) -#endif { SPXMLViewContent * text = SP_XMLVIEW_CONTENT (object); sp_xmlview_content_set_repr (text, NULL); -#if GTK_CHECK_VERSION(3,0,0) GTK_WIDGET_CLASS (sp_xmlview_content_parent_class)->destroy (object); -#else - GTK_OBJECT_CLASS (sp_xmlview_content_parent_class)->destroy (object); -#endif } void diff --git a/src/widgets/sp-xmlview-tree.cpp b/src/widgets/sp-xmlview-tree.cpp index 5dff9adf3..131ac16bf 100644 --- a/src/widgets/sp-xmlview-tree.cpp +++ b/src/widgets/sp-xmlview-tree.cpp @@ -23,11 +23,7 @@ struct NodeData { enum { STORE_TEXT_COL = 0, STORE_DATA_COL, STORE_REPR_COL, STORE_N_COLS }; -#if GTK_CHECK_VERSION(3,0,0) static void sp_xmlview_tree_destroy(GtkWidget * object); -#else -static void sp_xmlview_tree_destroy(GtkObject * object); -#endif static NodeData * node_data_new (SPXMLViewTree * tree, GtkTreeIter * node, GtkTreeRowReference *rowref, Inkscape::XML::Node * repr); @@ -121,13 +117,8 @@ G_DEFINE_TYPE(SPXMLViewTree, sp_xmlview_tree, GTK_TYPE_TREE_VIEW); void sp_xmlview_tree_class_init(SPXMLViewTreeClass * klass) { -#if GTK_CHECK_VERSION(3,0,0) - GtkWidgetClass * widget_class = GTK_WIDGET_CLASS(klass); + auto widget_class = GTK_WIDGET_CLASS(klass); widget_class->destroy = sp_xmlview_tree_destroy; -#else - GtkObjectClass * object_class = GTK_OBJECT_CLASS(klass); - object_class->destroy = sp_xmlview_tree_destroy; -#endif // Signal for when a tree drag and drop has completed g_signal_new ( "tree_move", @@ -148,22 +139,13 @@ sp_xmlview_tree_init (SPXMLViewTree * tree) tree->dndactive = FALSE; } - -#if GTK_CHECK_VERSION(3,0,0) void sp_xmlview_tree_destroy(GtkWidget * object) -#else -void sp_xmlview_tree_destroy(GtkObject * object) -#endif { SPXMLViewTree * tree = SP_XMLVIEW_TREE (object); sp_xmlview_tree_set_repr (tree, NULL); -#if GTK_CHECK_VERSION(3,0,0) GTK_WIDGET_CLASS(sp_xmlview_tree_parent_class)->destroy (object); -#else - GTK_OBJECT_CLASS(sp_xmlview_tree_parent_class)->destroy (object); -#endif } /* diff --git a/src/widgets/spw-utilities.cpp b/src/widgets/spw-utilities.cpp index 5500e1068..c0d4d9d58 100644 --- a/src/widgets/spw-utilities.cpp +++ b/src/widgets/spw-utilities.cpp @@ -19,12 +19,7 @@ #include #include - -#if GTK_CHECK_VERSION(3,0,0) #include -#else -#include -#endif #include "selection.h" @@ -36,11 +31,7 @@ * Creates a label widget with the given text, at the given col, row * position in the table. */ -#if GTK_CHECK_VERSION(3,0,0) Gtk::Label * spw_label(Gtk::Grid *table, const gchar *label_text, int col, int row, Gtk::Widget* target) -#else -Gtk::Label * spw_label(Gtk::Table *table, const gchar *label_text, int col, int row, Gtk::Widget* target) -#endif { Gtk::Label *label_widget = new Gtk::Label(); g_assert(label_widget != NULL); @@ -56,7 +47,6 @@ Gtk::Label * spw_label(Gtk::Table *table, const gchar *label_text, int col, int label_widget->set_alignment(1.0, 0.5); label_widget->show(); -#if GTK_CHECK_VERSION(3,0,0) label_widget->set_hexpand(); label_widget->set_halign(Gtk::ALIGN_FILL); label_widget->set_valign(Gtk::ALIGN_CENTER); @@ -70,9 +60,6 @@ Gtk::Label * spw_label(Gtk::Table *table, const gchar *label_text, int col, int #endif table->attach(*label_widget, col, row, 1, 1); -#else - table->attach(*label_widget, col, col+1, row, row+1, (Gtk::EXPAND | Gtk::FILL), static_cast(0), 4, 0); -#endif return label_widget; } @@ -84,16 +71,9 @@ spw_label_old(GtkWidget *table, const gchar *label_text, int col, int row) label_widget = gtk_label_new (label_text); g_assert(label_widget != NULL); - -#if GTK_CHECK_VERSION(3,0,0) gtk_widget_set_halign(label_widget, GTK_ALIGN_END); -#else - gtk_misc_set_alignment (GTK_MISC (label_widget), 1.0, 0.5); -#endif - gtk_widget_show (label_widget); -#if GTK_CHECK_VERSION(3,0,0) #if GTK_CHECK_VERSION(3,12,0) gtk_widget_set_margin_start(label_widget, 4); gtk_widget_set_margin_end(label_widget, 4); @@ -105,10 +85,6 @@ spw_label_old(GtkWidget *table, const gchar *label_text, int col, int row) gtk_widget_set_halign(label_widget, GTK_ALIGN_FILL); gtk_widget_set_valign(label_widget, GTK_ALIGN_CENTER); gtk_grid_attach(GTK_GRID(table), label_widget, col, row, 1, 1); -#else - gtk_table_attach(GTK_TABLE (table), label_widget, col, col+1, row, row+1, - (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), (GtkAttachOptions)0, 4, 0); -#endif return label_widget; } @@ -117,25 +93,16 @@ spw_label_old(GtkWidget *table, const gchar *label_text, int col, int row) * Creates a horizontal layout manager with 4-pixel spacing between children * and space for 'width' columns. */ -#if GTK_CHECK_VERSION(3,0,0) Gtk::HBox * spw_hbox(Gtk::Grid * table, int width, int col, int row) -#else -Gtk::HBox * spw_hbox(Gtk::Table * table, int width, int col, int row) -#endif { /* Create a new hbox with a 4-pixel spacing between children */ Gtk::HBox *hb = new Gtk::HBox(false, 4); g_assert(hb != NULL); hb->show(); - -#if GTK_CHECK_VERSION(3,0,0) hb->set_hexpand(); hb->set_halign(Gtk::ALIGN_FILL); hb->set_valign(Gtk::ALIGN_CENTER); table->attach(*hb, col, row, width, 1); -#else - table->attach(*hb, col, col+width, row, row+1, (Gtk::EXPAND | Gtk::FILL), static_cast(0), 0, 0); -#endif return hb; } @@ -177,37 +144,21 @@ spw_checkbutton(GtkWidget * dialog, GtkWidget * table, g_assert(table != NULL); GtkWidget *l = gtk_label_new (label); - -#if GTK_CHECK_VERSION(3,0,0) gtk_widget_set_halign(l, GTK_ALIGN_END); -#else - gtk_misc_set_alignment (GTK_MISC (l), 1.0, 0.5); -#endif - gtk_widget_show (l); -#if GTK_CHECK_VERSION(3,0,0) gtk_widget_set_halign(l, GTK_ALIGN_FILL); gtk_widget_set_hexpand(l, TRUE); gtk_widget_set_valign(l, GTK_ALIGN_CENTER); gtk_grid_attach(GTK_GRID(table), l, 0, row, 1, 1); -#else - gtk_table_attach (GTK_TABLE (table), l, 0, 1, row, row+1, - (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), (GtkAttachOptions)0, 0, 0); -#endif b = gtk_check_button_new (); gtk_widget_show (b); -#if GTK_CHECK_VERSION(3,0,0) gtk_widget_set_halign(b, GTK_ALIGN_FILL); gtk_widget_set_hexpand(b, TRUE); gtk_widget_set_valign(b, GTK_ALIGN_CENTER); gtk_grid_attach(GTK_GRID(table), b, 1, row, 1, 1); -#else - gtk_table_attach (GTK_TABLE (table), b, 1, 2, row, row+1, - (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), (GtkAttachOptions)0, 0, 0); -#endif g_object_set_data (G_OBJECT (b), "key", key); g_object_set_data (G_OBJECT (dialog), key, b); @@ -235,16 +186,10 @@ spw_dropdown(GtkWidget * dialog, GtkWidget * table, spw_label_old(table, label_text, 0, row); gtk_widget_show (selector); - -#if GTK_CHECK_VERSION(3,0,0) gtk_widget_set_halign(selector, GTK_ALIGN_FILL); gtk_widget_set_hexpand(selector, TRUE); gtk_widget_set_valign(selector, GTK_ALIGN_CENTER); gtk_grid_attach(GTK_GRID(table), selector, 1, row, 1, 1); -#else - gtk_table_attach (GTK_TABLE (table), selector, 1, 2, row, row+1, - (GtkAttachOptions)(GTK_EXPAND | GTK_FILL), (GtkAttachOptions)0, 0, 0); -#endif g_object_set_data (G_OBJECT (dialog), key, selector); return selector; @@ -255,8 +200,7 @@ sp_set_font_size_recursive (GtkWidget *w, gpointer font) { guint size = GPOINTER_TO_UINT (font); -#if GTK_CHECK_VERSION(3,0,0) - GtkCssProvider *css_provider = gtk_css_provider_new(); + auto css_provider = gtk_css_provider_new(); const double pt_size = size / static_cast(PANGO_SCALE); std::ostringstream css_data; @@ -268,25 +212,16 @@ sp_set_font_size_recursive (GtkWidget *w, gpointer font) css_data.str().c_str(), -1, NULL); - GtkStyleContext *style_context = gtk_widget_get_style_context(w); + auto style_context = gtk_widget_get_style_context(w); gtk_style_context_add_provider(style_context, GTK_STYLE_PROVIDER(css_provider), GTK_STYLE_PROVIDER_PRIORITY_USER); -#else - PangoFontDescription* pan = pango_font_description_new (); - pango_font_description_set_size (pan, size); - gtk_widget_modify_font (w, pan); -#endif if (GTK_IS_CONTAINER(w)) { gtk_container_foreach (GTK_CONTAINER(w), (GtkCallback) sp_set_font_size_recursive, font); } -#if GTK_CHECK_VERSION(3,0,0) g_object_unref(css_provider); -#else - pango_font_description_free (pan); -#endif } void diff --git a/src/widgets/spw-utilities.h b/src/widgets/spw-utilities.h index 31f29e026..71b451631 100644 --- a/src/widgets/spw-utilities.h +++ b/src/widgets/spw-utilities.h @@ -20,25 +20,13 @@ namespace Gtk { class Label; - -#if GTK_CHECK_VERSION(3,0,0) class Grid; -#else - class Table; -#endif - class HBox; class Widget; } -#if GTK_CHECK_VERSION(3,0,0) Gtk::Label * spw_label(Gtk::Grid *table, gchar const *label_text, int col, int row, Gtk::Widget *target); Gtk::HBox * spw_hbox(Gtk::Grid *table, int width, int col, int row); -#else -Gtk::Label * spw_label(Gtk::Table *table, gchar const *label_text, int col, int row, Gtk::Widget *target); -Gtk::HBox * spw_hbox(Gtk::Table *table, int width, int col, int row); -#endif - GtkWidget * spw_label_old(GtkWidget *table, gchar const *label_text, int col, int row); GtkWidget * diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index 23acb74af..f256b466c 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -1562,8 +1562,7 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje g_object_set_data( holder, "TextFontFamilyAction", act ); // Change style of drop-down from menu to list -#if GTK_CHECK_VERSION(3,0,0) - GtkCssProvider *css_provider = gtk_css_provider_new(); + auto css_provider = gtk_css_provider_new(); gtk_css_provider_load_from_data(css_provider, "#TextFontFamilyAction_combobox {\n" " -GtkComboBox-appears-as-list: true;\n" @@ -1574,24 +1573,10 @@ void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObje "}\n", -1, NULL); - GdkScreen *screen = gdk_screen_get_default(); + auto screen = gdk_screen_get_default(); gtk_style_context_add_provider_for_screen(screen, GTK_STYLE_PROVIDER(css_provider), GTK_STYLE_PROVIDER_PRIORITY_USER); -#else - gtk_rc_parse_string ( - "style \"dropdown-as-list-style\"\n" - "{\n" - " GtkComboBox::appears-as-list = 1\n" - "}\n" - "widget \"*.TextFontFamilyAction_combobox\" style \"dropdown-as-list-style\"" - "style \"fontfamily-separator-style\"\n" - "{\n" - " GtkWidget::wide-separators = 1\n" - " GtkWidget::separator-height = 6\n" - "}\n" - "widget \"*gtk-combobox-popup-window.GtkScrolledWindow.GtkTreeView\" style \"fontfamily-separator-style\""); -#endif } /* Font size */ -- cgit v1.2.3 From 1bd64804910f28ff16ea47e34baed41f22768fee Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Fri, 29 Jul 2016 14:35:20 +0100 Subject: ruler: Backport upstream patches (bzr r15023.2.9) --- src/widgets/ruler.cpp | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/ruler.cpp b/src/widgets/ruler.cpp index 92c2b611d..8b0a344f6 100644 --- a/src/widgets/ruler.cpp +++ b/src/widgets/ruler.cpp @@ -642,8 +642,14 @@ static gboolean sp_ruler_draw (GtkWidget *widget, cairo_t *cr) { - SPRuler *ruler = SP_RULER (widget); - SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); + SPRuler *ruler = SP_RULER (widget); + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); + GtkStyleContext *context = gtk_widget_get_style_context (widget); + GtkAllocation allocation; + + gtk_widget_get_allocation (widget, &allocation); + gtk_render_background (context, cr, 0, 0, allocation.width, allocation.height); + gtk_render_frame (context, cr, 0, 0, allocation.width, allocation.height); sp_ruler_draw_ticks (ruler); @@ -669,7 +675,7 @@ sp_ruler_make_pixmap (SPRuler *ruler) priv->backing_store = gdk_window_create_similar_surface (gtk_widget_get_window (widget), - CAIRO_CONTENT_COLOR, + CAIRO_CONTENT_COLOR_ALPHA, allocation.width, allocation.height); @@ -1088,9 +1094,10 @@ sp_ruler_draw_ticks (SPRuler *ruler) cr = cairo_create (priv->backing_store); - gtk_render_background (context, cr, 0, 0, allocation.width, allocation.height); - gtk_render_frame (context, cr, 0, 0, allocation.width, allocation.height); - + cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); + cairo_paint (cr); + cairo_set_operator (cr, CAIRO_OPERATOR_OVER); + gtk_style_context_get_color (context, gtk_widget_get_state_flags (widget), &color); gdk_cairo_set_source_rgba (cr, &color); @@ -1319,9 +1326,6 @@ sp_ruler_get_pos_rect (SPRuler *ruler, rect.y = ROUND ((position - lower) * increment) + (ythickness - rect.height) / 2 - 1; } - rect.x += allocation.x; - rect.y += allocation.y; - return rect; } @@ -1344,18 +1348,21 @@ sp_ruler_queue_pos_redraw (SPRuler *ruler) { SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); const GdkRectangle rect = sp_ruler_get_pos_rect (ruler, priv->position); + GtkAllocation allocation; + + gtk_widget_get_allocation (GTK_WIDGET(ruler), &allocation); gtk_widget_queue_draw_area (GTK_WIDGET(ruler), - rect.x, - rect.y, + rect.x + allocation.x, + rect.y + allocation.y, rect.width, rect.height); if (priv->last_pos_rect.width != 0 || priv->last_pos_rect.height != 0) { gtk_widget_queue_draw_area (GTK_WIDGET(ruler), - priv->last_pos_rect.x, - priv->last_pos_rect.y, + priv->last_pos_rect.x + allocation.x, + priv->last_pos_rect.y + allocation.y, priv->last_pos_rect.width, priv->last_pos_rect.height); -- cgit v1.2.3 From 35830f456cadaecf8b8e3944e3031a1a93f6cb41 Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Wed, 3 Aug 2016 15:29:38 +0200 Subject: Removed unused includes, decreased compilation time. Once again (bzr r15034) --- src/widgets/arc-toolbar.cpp | 4 +--- src/widgets/box3d-toolbar.cpp | 3 +-- src/widgets/button.cpp | 2 -- src/widgets/calligraphy-toolbar.cpp | 3 +-- src/widgets/connector-toolbar.cpp | 6 +----- src/widgets/dash-selector.cpp | 4 +--- src/widgets/desktop-widget.cpp | 8 -------- src/widgets/dropper-toolbar.cpp | 2 +- src/widgets/eraser-toolbar.cpp | 3 +-- src/widgets/fill-style.cpp | 6 +----- src/widgets/font-selector.cpp | 7 +------ src/widgets/gradient-selector.cpp | 5 +---- src/widgets/gradient-toolbar.cpp | 3 +-- src/widgets/gradient-vector.cpp | 6 +----- src/widgets/icon.cpp | 7 ++----- src/widgets/ink-action.cpp | 5 ----- src/widgets/lpe-toolbar.cpp | 10 +--------- src/widgets/measure-toolbar.cpp | 3 +-- src/widgets/mesh-toolbar.cpp | 13 +------------ src/widgets/node-toolbar.cpp | 5 +---- src/widgets/paint-selector.cpp | 3 --- src/widgets/paintbucket-toolbar.cpp | 4 +--- src/widgets/pencil-toolbar.cpp | 7 +------ src/widgets/rect-toolbar.cpp | 6 +----- src/widgets/ruler.cpp | 1 - src/widgets/select-toolbar.cpp | 6 +----- src/widgets/sp-attribute-widget.cpp | 4 ---- src/widgets/sp-color-selector.cpp | 4 +--- src/widgets/sp-widget.cpp | 1 - src/widgets/sp-xmlview-attr-list.cpp | 2 +- src/widgets/sp-xmlview-tree.cpp | 1 - src/widgets/spinbutton-events.cpp | 3 +-- src/widgets/spiral-toolbar.cpp | 5 +---- src/widgets/spray-toolbar.cpp | 3 +-- src/widgets/spw-utilities.cpp | 4 +--- src/widgets/star-toolbar.cpp | 5 +---- src/widgets/stroke-marker-selector.cpp | 6 ------ src/widgets/stroke-style.cpp | 3 --- src/widgets/text-toolbar.cpp | 7 +------ src/widgets/toolbox.cpp | 9 +-------- src/widgets/tweak-toolbar.cpp | 3 +-- src/widgets/zoom-toolbar.cpp | 2 +- 42 files changed, 33 insertions(+), 161 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/arc-toolbar.cpp b/src/widgets/arc-toolbar.cpp index 7b872e8b1..35c8c0308 100644 --- a/src/widgets/arc-toolbar.cpp +++ b/src/widgets/arc-toolbar.cpp @@ -25,7 +25,7 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include #endif #include @@ -39,7 +39,6 @@ #include "widgets/ege-select-one-action.h" #include "widgets/ink-action.h" #include "mod360.h" -#include "preferences.h" #include "selection.h" #include "sp-ellipse.h" #include "toolbox.h" @@ -49,7 +48,6 @@ #include "verbs.h" #include "widgets/spinbutton-events.h" #include "xml/node-event-vector.h" -#include "xml/repr.h" using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; diff --git a/src/widgets/box3d-toolbar.cpp b/src/widgets/box3d-toolbar.cpp index 31b897ced..b8c67ee76 100644 --- a/src/widgets/box3d-toolbar.cpp +++ b/src/widgets/box3d-toolbar.cpp @@ -25,7 +25,7 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include #endif #include @@ -40,7 +40,6 @@ #include "widgets/ink-action.h" #include "inkscape.h" #include "persp3d.h" -#include "selection.h" #include "toolbox.h" #include "ui/icon-names.h" #include "ui/tools/box3d-tool.h" diff --git a/src/widgets/button.cpp b/src/widgets/button.cpp index 6ea8c1360..bc59d1a39 100644 --- a/src/widgets/button.cpp +++ b/src/widgets/button.cpp @@ -20,8 +20,6 @@ #include "shortcuts.h" #include "helper/action.h" -#include - static void sp_button_dispose(GObject *object); #if GTK_CHECK_VERSION(3, 0, 0) diff --git a/src/widgets/calligraphy-toolbar.cpp b/src/widgets/calligraphy-toolbar.cpp index 4ae6427ad..ba51499aa 100644 --- a/src/widgets/calligraphy-toolbar.cpp +++ b/src/widgets/calligraphy-toolbar.cpp @@ -25,7 +25,7 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include #endif #include "ui/dialog/calligraphic-profile-rename.h" @@ -37,7 +37,6 @@ #include "widgets/ege-adjustment-action.h" #include "widgets/ege-select-one-action.h" #include "widgets/ink-action.h" -#include "preferences.h" #include "toolbox.h" #include "ui/icon-names.h" #include "ui/uxmanager.h" diff --git a/src/widgets/connector-toolbar.cpp b/src/widgets/connector-toolbar.cpp index 733fb34e8..f80f49db7 100644 --- a/src/widgets/connector-toolbar.cpp +++ b/src/widgets/connector-toolbar.cpp @@ -25,7 +25,7 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include #endif #include @@ -40,10 +40,7 @@ #include "graphlayout.h" #include "widgets/ink-action.h" #include "inkscape.h" -#include "preferences.h" -#include "selection.h" #include "sp-namedview.h" -#include "sp-path.h" #include "toolbox.h" #include "ui/icon-names.h" #include "ui/tools/connector-tool.h" @@ -51,7 +48,6 @@ #include "verbs.h" #include "widgets/spinbutton-events.h" #include "xml/node-event-vector.h" -#include "xml/repr.h" using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; diff --git a/src/widgets/dash-selector.cpp b/src/widgets/dash-selector.cpp index 9d591d33d..e1cb563a7 100644 --- a/src/widgets/dash-selector.cpp +++ b/src/widgets/dash-selector.cpp @@ -13,15 +13,13 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include #endif #include "dash-selector.h" #include -#include #include -#include #include <2geom/coord.h> #include "style.h" diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp index 164a06910..ec155ce4c 100644 --- a/src/widgets/desktop-widget.cpp +++ b/src/widgets/desktop-widget.cpp @@ -36,21 +36,15 @@ #include "desktop-widget.h" #include "display/sp-canvas.h" #include "display/canvas-arena.h" -#include "document.h" #include "ege-color-prof-tracker.h" #include "widgets/ege-select-one-action.h" #include #include "file.h" #include "helper/action.h" -#include "helper/action-context.h" #include "util/units.h" #include "ui/widget/unit-tracker.h" -#include "inkscape.h" #include "ui/interface.h" -#include "macros.h" -#include "preferences.h" #include "sp-image.h" -#include "sp-item.h" #include "sp-namedview.h" #include "ui/dialog/swatches.h" #include "ui/icon-names.h" @@ -76,8 +70,6 @@ #include #include -#include - #if defined (SOLARIS) && (SOLARIS == 8) #include "round.h" using Inkscape::round; diff --git a/src/widgets/dropper-toolbar.cpp b/src/widgets/dropper-toolbar.cpp index 45ed9ead4..f60955da5 100644 --- a/src/widgets/dropper-toolbar.cpp +++ b/src/widgets/dropper-toolbar.cpp @@ -25,7 +25,7 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include #endif #include diff --git a/src/widgets/eraser-toolbar.cpp b/src/widgets/eraser-toolbar.cpp index bb553f4e6..b30d542a6 100644 --- a/src/widgets/eraser-toolbar.cpp +++ b/src/widgets/eraser-toolbar.cpp @@ -25,7 +25,7 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include #endif #include @@ -38,7 +38,6 @@ #include "widgets/ege-adjustment-action.h" #include "widgets/ege-select-one-action.h" #include "widgets/ink-action.h" -#include "preferences.h" #include "toolbox.h" #include "ui/icon-names.h" diff --git a/src/widgets/fill-style.cpp b/src/widgets/fill-style.cpp index a96776894..aff88aca5 100644 --- a/src/widgets/fill-style.cpp +++ b/src/widgets/fill-style.cpp @@ -19,7 +19,7 @@ #define noSP_FS_VERBOSE #ifdef HAVE_CONFIG_H -# include "config.h" +#include #endif #include @@ -27,8 +27,6 @@ #include "verbs.h" -#include - #include "desktop.h" #include "selection.h" @@ -38,13 +36,11 @@ #include "document-undo.h" #include "gradient-chemistry.h" #include "inkscape.h" -#include "selection.h" #include "sp-linear-gradient.h" #include "sp-pattern.h" #include "sp-radial-gradient.h" #include "style.h" #include "widgets/paint-selector.h" -#include "xml/repr.h" #include "fill-style.h" #include "fill-n-stroke-factory.h" diff --git a/src/widgets/font-selector.cpp b/src/widgets/font-selector.cpp index aefcb2e81..2ed6705d7 100644 --- a/src/widgets/font-selector.cpp +++ b/src/widgets/font-selector.cpp @@ -16,21 +16,16 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include #endif #include #include -#include <2geom/transforms.h> - -#include - #include #include "desktop.h" #include "widgets/font-selector.h" -#include "preferences.h" /* SPFontSelector */ diff --git a/src/widgets/gradient-selector.cpp b/src/widgets/gradient-selector.cpp index 604ecd108..425eb9cbc 100644 --- a/src/widgets/gradient-selector.cpp +++ b/src/widgets/gradient-selector.cpp @@ -14,7 +14,7 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include #endif #include @@ -28,14 +28,11 @@ #include "inkscape.h" #include "verbs.h" #include "helper/action.h" -#include "helper/action-context.h" #include "preferences.h" #include "widgets/icon.h" #include -#include -#include "gradient-selector.h" #include "paint-selector.h" #include "style.h" #include "id-clash.h" diff --git a/src/widgets/gradient-toolbar.cpp b/src/widgets/gradient-toolbar.cpp index a44e9962e..7e9223770 100644 --- a/src/widgets/gradient-toolbar.cpp +++ b/src/widgets/gradient-toolbar.cpp @@ -13,7 +13,7 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include #endif #include "ui/widget/color-preview.h" @@ -29,7 +29,6 @@ #include "gradient-toolbar.h" #include "widgets/ink-action.h" #include "macros.h" -#include "preferences.h" #include "selection.h" #include "sp-defs.h" #include "sp-linear-gradient.h" diff --git a/src/widgets/gradient-vector.cpp b/src/widgets/gradient-vector.cpp index 97e65141f..6e7c8cdf8 100644 --- a/src/widgets/gradient-vector.cpp +++ b/src/widgets/gradient-vector.cpp @@ -20,14 +20,13 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include #endif #include #include "gradient-vector.h" #include "ui/widget/color-preview.h" #include "verbs.h" -#include #include "macros.h" #include #include @@ -50,8 +49,6 @@ #include "desktop.h" #include "layer-manager.h" -#include -#include #include "document-undo.h" #include "ui/dialog-events.h" @@ -476,7 +473,6 @@ void SPGradientVectorSelector::setSwatched() #include "widgets/widget-sizes.h" #include "xml/node-event-vector.h" #include "svg/svg-color.h" -#include "ui/widget/color-notebook.h" #define PAD 4 diff --git a/src/widgets/icon.cpp b/src/widgets/icon.cpp index f2031fe51..515deb565 100644 --- a/src/widgets/icon.cpp +++ b/src/widgets/icon.cpp @@ -16,22 +16,19 @@ # include "config.h" #endif +#include +#include #include #include -#include #include #include #include -#include -#include -#include #include <2geom/transforms.h> #include "path-prefix.h" #include "preferences.h" #include "inkscape.h" #include "document.h" -#include "sp-item.h" #include "display/cairo-utils.h" #include "display/drawing-context.h" #include "display/drawing-item.h" diff --git a/src/widgets/ink-action.cpp b/src/widgets/ink-action.cpp index ace99d9aa..c0797b236 100644 --- a/src/widgets/ink-action.cpp +++ b/src/widgets/ink-action.cpp @@ -1,14 +1,9 @@ #include "widgets/icon.h" -#include "icon-size.h" -#include - #include "widgets/ink-action.h" #include "widgets/button.h" -#include - #if GTK_CHECK_VERSION(3,0,0) // Fork of gtk-imagemenuitem to continue support #include "widgets/image-menu-item.h" diff --git a/src/widgets/lpe-toolbar.cpp b/src/widgets/lpe-toolbar.cpp index 387bf6dee..d44983a15 100644 --- a/src/widgets/lpe-toolbar.cpp +++ b/src/widgets/lpe-toolbar.cpp @@ -25,27 +25,19 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include #endif #include "live_effects/lpe-line_segment.h" #include "lpe-toolbar.h" -#include "desktop.h" -#include "document-undo.h" #include "widgets/ege-select-one-action.h" #include "helper/action-context.h" #include "helper/action.h" #include "widgets/ink-action.h" -#include "live_effects/effect.h" -#include "preferences.h" -#include "selection.h" -#include "sp-namedview.h" #include "ui/tools-switch.h" #include "ui/tools/lpe-tool.h" #include "ui/widget/unit-tracker.h" -#include "util/units.h" -#include "verbs.h" using Inkscape::UI::Widget::UnitTracker; using Inkscape::Util::Unit; diff --git a/src/widgets/measure-toolbar.cpp b/src/widgets/measure-toolbar.cpp index 990989f4a..53790cfac 100644 --- a/src/widgets/measure-toolbar.cpp +++ b/src/widgets/measure-toolbar.cpp @@ -25,7 +25,7 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include #endif #include @@ -38,7 +38,6 @@ #include "document-undo.h" #include "widgets/ege-adjustment-action.h" #include "widgets/ege-output-action.h" -#include "preferences.h" #include "toolbox.h" #include "widgets/ink-action.h" #include "ui/icon-names.h" diff --git a/src/widgets/mesh-toolbar.cpp b/src/widgets/mesh-toolbar.cpp index 3643ce00c..1e5c12d41 100644 --- a/src/widgets/mesh-toolbar.cpp +++ b/src/widgets/mesh-toolbar.cpp @@ -15,7 +15,7 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include #endif // REVIEW THESE AT END OF REWRITE @@ -25,17 +25,13 @@ #include "verbs.h" -#include "macros.h" #include "widgets/button.h" -#include "widgets/widget-sizes.h" -#include "widgets/spw-utilities.h" #include "widgets/spinbutton-events.h" #include "widgets/gradient-vector.h" #include "widgets/gradient-image.h" #include "style.h" #include "inkscape.h" -#include "preferences.h" #include "document-private.h" #include "document-undo.h" #include "desktop.h" @@ -47,23 +43,16 @@ #include "gradient-drag.h" #include "sp-mesh.h" #include "gradient-chemistry.h" -#include "gradient-selector.h" -#include "selection.h" #include "ui/icon-names.h" #include "widgets/ege-adjustment-action.h" -#include "widgets/ege-output-action.h" #include "widgets/ege-select-one-action.h" #include "widgets/ink-action.h" -#include "widgets/ink-comboboxentry-action.h" #include "sp-stop.h" #include "svg/css-ostringstream.h" -#include "svg/svg-color.h" #include "desktop-style.h" -#include "toolbox.h" - using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; using Inkscape::UI::PrefPusher; diff --git a/src/widgets/node-toolbar.cpp b/src/widgets/node-toolbar.cpp index 113061519..ed3e33acc 100644 --- a/src/widgets/node-toolbar.cpp +++ b/src/widgets/node-toolbar.cpp @@ -25,7 +25,7 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include #endif #include "ui/tool/multi-path-manipulator.h" @@ -37,16 +37,13 @@ #include "widgets/ege-adjustment-action.h" #include "widgets/ink-action.h" #include "inkscape.h" -#include "preferences.h" #include "selection-chemistry.h" -#include "selection.h" #include "sp-namedview.h" #include "toolbox.h" #include "ui/icon-names.h" #include "ui/tool/control-point-selection.h" #include "ui/tools/node-tool.h" #include "ui/widget/unit-tracker.h" -#include "util/units.h" #include "verbs.h" #include "widgets/widget-sizes.h" diff --git a/src/widgets/paint-selector.cpp b/src/widgets/paint-selector.cpp index 58a178aec..a421ea7d3 100644 --- a/src/widgets/paint-selector.cpp +++ b/src/widgets/paint-selector.cpp @@ -41,7 +41,6 @@ #include #include #include -#include "svg/svg-color.h" #include "svg/css-ostringstream.h" #include "path-prefix.h" #include "io/sys.h" @@ -55,8 +54,6 @@ #include "svg/svg-icc-color.h" #endif // SP_PS_VERBOSE -#include - using Inkscape::Widgets::SwatchSelector; using Inkscape::UI::SelectedColor; diff --git a/src/widgets/paintbucket-toolbar.cpp b/src/widgets/paintbucket-toolbar.cpp index b717d74fa..3d1565924 100644 --- a/src/widgets/paintbucket-toolbar.cpp +++ b/src/widgets/paintbucket-toolbar.cpp @@ -25,7 +25,7 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include #endif #include @@ -35,13 +35,11 @@ #include "document-undo.h" #include "widgets/ege-adjustment-action.h" #include "widgets/ege-select-one-action.h" -#include "preferences.h" #include "toolbox.h" #include "ui/icon-names.h" #include "ui/tools/flood-tool.h" #include "ui/uxmanager.h" #include "ui/widget/unit-tracker.h" -#include "util/units.h" #include "widgets/ink-action.h" using Inkscape::UI::Widget::UnitTracker; diff --git a/src/widgets/pencil-toolbar.cpp b/src/widgets/pencil-toolbar.cpp index 55127206c..d402cc714 100644 --- a/src/widgets/pencil-toolbar.cpp +++ b/src/widgets/pencil-toolbar.cpp @@ -25,19 +25,17 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include #endif #include #include -#include #include "pencil-toolbar.h" #include "desktop.h" #include "widgets/ege-adjustment-action.h" #include "widgets/ege-select-one-action.h" #include "widgets/ink-action.h" -#include "preferences.h" #include "toolbox.h" #include "ui/tools-switch.h" #include "ui/icon-names.h" @@ -46,13 +44,10 @@ #include "widgets/spinbutton-events.h" #include #include "display/curve.h" -#include "live_effects/effect.h" #include "live_effects/lpe-simplify.h" #include "live_effects/lpe-powerstroke.h" -#include "live_effects/effect-enum.h" #include "live_effects/lpeobject.h" #include "live_effects/lpeobject-reference.h" -#include "sp-lpe-item.h" using Inkscape::UI::UXManager; using Inkscape::UI::ToolboxFactory; diff --git a/src/widgets/rect-toolbar.cpp b/src/widgets/rect-toolbar.cpp index bc27d003c..c9b75294b 100644 --- a/src/widgets/rect-toolbar.cpp +++ b/src/widgets/rect-toolbar.cpp @@ -25,7 +25,7 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include #endif #include @@ -38,8 +38,6 @@ #include "widgets/ege-output-action.h" #include "widgets/ink-action.h" #include "inkscape.h" -#include "preferences.h" -#include "selection.h" #include "sp-namedview.h" #include "sp-rect.h" #include "toolbox.h" @@ -47,11 +45,9 @@ #include "ui/tools/rect-tool.h" #include "ui/uxmanager.h" #include "ui/widget/unit-tracker.h" -#include "util/units.h" #include "verbs.h" #include "widgets/widget-sizes.h" #include "xml/node-event-vector.h" -#include "xml/repr.h" using Inkscape::UI::Widget::UnitTracker; using Inkscape::UI::UXManager; diff --git a/src/widgets/ruler.cpp b/src/widgets/ruler.cpp index deffd384a..1f6e4396c 100644 --- a/src/widgets/ruler.cpp +++ b/src/widgets/ruler.cpp @@ -31,7 +31,6 @@ #include #include -#include "widget-sizes.h" #include "ruler.h" #include "round.h" #include diff --git a/src/widgets/select-toolbar.cpp b/src/widgets/select-toolbar.cpp index 9851b0606..9a48b9a07 100644 --- a/src/widgets/select-toolbar.cpp +++ b/src/widgets/select-toolbar.cpp @@ -13,7 +13,7 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include #endif #include <2geom/rect.h> @@ -32,19 +32,15 @@ #include "widgets/ink-action.h" #include "inkscape.h" #include "message-stack.h" -#include "preferences.h" #include "selection-chemistry.h" -#include "selection.h" #include "sp-item-transform.h" #include "sp-namedview.h" #include "toolbox.h" #include "ui/icon-names.h" #include "ui/widget/unit-tracker.h" -#include "util/units.h" #include "verbs.h" #include "widgets/icon.h" #include "widgets/sp-widget.h" -#include "widgets/spw-utilities.h" #include "widgets/widget-sizes.h" using Inkscape::UI::Widget::UnitTracker; diff --git a/src/widgets/sp-attribute-widget.cpp b/src/widgets/sp-attribute-widget.cpp index fb7eb1420..de44cdbb4 100644 --- a/src/widgets/sp-attribute-widget.cpp +++ b/src/widgets/sp-attribute-widget.cpp @@ -16,7 +16,6 @@ #include #include -#include #if WITH_GTKMM_3_0 # include @@ -24,9 +23,6 @@ # include #endif -#include -#include - #include "sp-object.h" #include "xml/repr.h" #include "macros.h" diff --git a/src/widgets/sp-color-selector.cpp b/src/widgets/sp-color-selector.cpp index 93eaaee8b..932f074d2 100644 --- a/src/widgets/sp-color-selector.cpp +++ b/src/widgets/sp-color-selector.cpp @@ -4,7 +4,7 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include #endif #include @@ -180,8 +180,6 @@ gfloat ColorSelector::getAlpha() const return _alpha; } -#include "svg/svg-icc-color.h" - /** Called from the outside to set the color; optionally emits signal (only when called from downstream, e.g. the RGBA value field, but not from the rest of the program) diff --git a/src/widgets/sp-widget.cpp b/src/widgets/sp-widget.cpp index 5ab6b1bb5..180704f59 100644 --- a/src/widgets/sp-widget.cpp +++ b/src/widgets/sp-widget.cpp @@ -13,7 +13,6 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include "macros.h" #include "document.h" #include "inkscape.h" #include "sp-widget.h" diff --git a/src/widgets/sp-xmlview-attr-list.cpp b/src/widgets/sp-xmlview-attr-list.cpp index a4c00db7c..45dbae52a 100644 --- a/src/widgets/sp-xmlview-attr-list.cpp +++ b/src/widgets/sp-xmlview-attr-list.cpp @@ -10,7 +10,7 @@ */ #ifdef HAVE_CONFIG_H -# include +#include #endif #include diff --git a/src/widgets/sp-xmlview-tree.cpp b/src/widgets/sp-xmlview-tree.cpp index 5dff9adf3..5af7c243d 100644 --- a/src/widgets/sp-xmlview-tree.cpp +++ b/src/widgets/sp-xmlview-tree.cpp @@ -10,7 +10,6 @@ */ #include -#include #include "xml/node-event-vector.h" #include "sp-xmlview-tree.h" diff --git a/src/widgets/spinbutton-events.cpp b/src/widgets/spinbutton-events.cpp index 0280694f6..fdf88ec85 100644 --- a/src/widgets/spinbutton-events.cpp +++ b/src/widgets/spinbutton-events.cpp @@ -12,7 +12,7 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include #endif #include @@ -21,7 +21,6 @@ #include "ui/tools/tool-base.h" #include "sp-widget.h" -#include "widget-sizes.h" #include "spinbutton-events.h" gboolean spinbutton_focus_in(GtkWidget *w, GdkEventKey * /*event*/, gpointer /*data*/) diff --git a/src/widgets/spiral-toolbar.cpp b/src/widgets/spiral-toolbar.cpp index 7e7398091..7406be255 100644 --- a/src/widgets/spiral-toolbar.cpp +++ b/src/widgets/spiral-toolbar.cpp @@ -25,7 +25,7 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include #endif #include @@ -37,7 +37,6 @@ #include "widgets/ege-adjustment-action.h" #include "widgets/ege-output-action.h" #include "widgets/ink-action.h" -#include "preferences.h" #include "selection.h" #include "sp-spiral.h" #include "toolbox.h" @@ -46,8 +45,6 @@ #include "verbs.h" #include "widgets/spinbutton-events.h" #include "xml/node-event-vector.h" -#include "xml/node.h" -#include "xml/repr.h" using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; diff --git a/src/widgets/spray-toolbar.cpp b/src/widgets/spray-toolbar.cpp index 9e142a8db..43d00c53e 100644 --- a/src/widgets/spray-toolbar.cpp +++ b/src/widgets/spray-toolbar.cpp @@ -26,7 +26,7 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include #endif #include @@ -37,7 +37,6 @@ #include "widgets/ege-adjustment-action.h" #include "widgets/ege-select-one-action.h" #include "widgets/ink-action.h" -#include "preferences.h" #include "toolbox.h" #include "ui/dialog/clonetiler.h" #include "ui/dialog/dialog-manager.h" diff --git a/src/widgets/spw-utilities.cpp b/src/widgets/spw-utilities.cpp index 5500e1068..8bc472601 100644 --- a/src/widgets/spw-utilities.cpp +++ b/src/widgets/spw-utilities.cpp @@ -11,7 +11,7 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include #endif #include @@ -30,8 +30,6 @@ #include "spw-utilities.h" -#include - /** * Creates a label widget with the given text, at the given col, row * position in the table. diff --git a/src/widgets/star-toolbar.cpp b/src/widgets/star-toolbar.cpp index 982a3c854..7f4293b62 100644 --- a/src/widgets/star-toolbar.cpp +++ b/src/widgets/star-toolbar.cpp @@ -25,7 +25,7 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include #endif #include @@ -45,10 +45,7 @@ #include "ui/tools/star-tool.h" #include "ui/uxmanager.h" #include "verbs.h" -#include "widgets/../preferences.h" #include "xml/node-event-vector.h" -#include "xml/node.h" -#include "xml/repr.h" using Inkscape::UI::UXManager; using Inkscape::DocumentUndo; diff --git a/src/widgets/stroke-marker-selector.cpp b/src/widgets/stroke-marker-selector.cpp index e273faad7..2a0a10efa 100644 --- a/src/widgets/stroke-marker-selector.cpp +++ b/src/widgets/stroke-marker-selector.cpp @@ -18,17 +18,13 @@ #include "stroke-marker-selector.h" -#include -#include #include -#include <2geom/coord.h> #include "style.h" #include "ui/dialog-events.h" #include "desktop-style.h" -#include "preferences.h" #include "path-prefix.h" #include "io/sys.h" #include "sp-marker.h" @@ -39,10 +35,8 @@ #include "gradient-vector.h" #include -#include #include "ui/widget/spinbutton.h" #include "stroke-style.h" -#include "gradient-chemistry.h" static Inkscape::UI::Cache::SvgPreview svg_preview_cache; diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp index 84a6e77ad..b66d97c1d 100644 --- a/src/widgets/stroke-style.cpp +++ b/src/widgets/stroke-style.cpp @@ -18,11 +18,8 @@ #define noSP_SS_VERBOSE #include "stroke-style.h" -#include "gradient-chemistry.h" -#include "sp-gradient.h" #include "sp-stop.h" #include "svg/svg-color.h" -#include "util/units.h" #include "ui/widget/unit-menu.h" #include "desktop-widget.h" diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index 23acb74af..3fa240a05 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -25,7 +25,7 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include #endif #include "libnrtype/font-lister.h" @@ -41,9 +41,7 @@ #include "widgets/ink-action.h" #include "widgets/ink-comboboxentry-action.h" #include "inkscape.h" -#include "preferences.h" #include "selection-chemistry.h" -#include "selection.h" #include "sp-flowtext.h" #include "sp-root.h" #include "sp-text.h" @@ -53,11 +51,8 @@ #include "toolbox.h" #include "ui/icon-names.h" #include "ui/tools/text-tool.h" -#include "ui/tools/tool-base.h" #include "ui/widget/unit-tracker.h" -#include "util/units.h" #include "verbs.h" -#include "xml/repr.h" using Inkscape::DocumentUndo; using Inkscape::UI::ToolboxFactory; diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 8113c9619..1e67cca8f 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -27,7 +27,7 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include "config.h" #endif #include @@ -40,14 +40,9 @@ #include "../desktop-style.h" #include "document-undo.h" #include "widgets/ege-adjustment-action.h" -#include "widgets/ege-output-action.h" -#include "widgets/ege-select-one-action.h" -#include "../graphlayout.h" #include "../helper/action.h" -#include "../helper/action-context.h" #include "icon.h" #include "ink-action.h" -#include "ink-comboboxentry-action.h" #include "../inkscape.h" #include "ui/interface.h" #include "../shortcuts.h" @@ -64,7 +59,6 @@ #include "../widgets/widget-sizes.h" #include "../xml/attribute-record.h" #include "../xml/node-event-vector.h" -#include "../xml/repr.h" #include "ui/uxmanager.h" @@ -95,7 +89,6 @@ #include "zoom-toolbar.h" #include "toolbox.h" -#include #include "ui/tools/tool-base.h" diff --git a/src/widgets/tweak-toolbar.cpp b/src/widgets/tweak-toolbar.cpp index a185ea956..9a021082c 100644 --- a/src/widgets/tweak-toolbar.cpp +++ b/src/widgets/tweak-toolbar.cpp @@ -25,7 +25,7 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include "config.h" #endif #include "ui/widget/spinbutton.h" @@ -37,7 +37,6 @@ #include "widgets/ege-output-action.h" #include "widgets/ege-select-one-action.h" #include "widgets/ink-action.h" -#include "preferences.h" #include "toolbox.h" #include "ui/icon-names.h" #include "ui/tools/tweak-tool.h" diff --git a/src/widgets/zoom-toolbar.cpp b/src/widgets/zoom-toolbar.cpp index 79feef86d..a961c0061 100644 --- a/src/widgets/zoom-toolbar.cpp +++ b/src/widgets/zoom-toolbar.cpp @@ -25,7 +25,7 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include "config.h" #endif #include "zoom-toolbar.h" -- cgit v1.2.3 From a0cacd78d5d987eafa3739bb8f45587d82246780 Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Fri, 5 Aug 2016 19:07:48 +0100 Subject: Split InkAction classes into separate files (bzr r15043) --- src/widgets/CMakeLists.txt | 6 + src/widgets/Makefile_insert | 6 + src/widgets/arc-toolbar.cpp | 3 +- src/widgets/box3d-toolbar.cpp | 2 +- src/widgets/calligraphy-toolbar.cpp | 1 + src/widgets/connector-toolbar.cpp | 3 +- src/widgets/dropper-toolbar.cpp | 2 +- src/widgets/eraser-toolbar.cpp | 4 +- src/widgets/gradient-toolbar.cpp | 4 +- src/widgets/ink-action.cpp | 440 +---------------------------------- src/widgets/ink-action.h | 124 +--------- src/widgets/ink-radio-action.cpp | 185 +++++++++++++++ src/widgets/ink-radio-action.h | 52 +++++ src/widgets/ink-toggle-action.cpp | 221 ++++++++++++++++++ src/widgets/ink-toggle-action.h | 53 +++++ src/widgets/ink-tool-menu-action.cpp | 49 ++++ src/widgets/ink-tool-menu-action.h | 52 +++++ src/widgets/lpe-toolbar.cpp | 3 +- src/widgets/measure-toolbar.cpp | 3 +- src/widgets/mesh-toolbar.cpp | 4 +- src/widgets/node-toolbar.cpp | 3 +- src/widgets/pencil-toolbar.cpp | 4 +- src/widgets/select-toolbar.cpp | 3 +- src/widgets/spray-toolbar.cpp | 3 +- src/widgets/star-toolbar.cpp | 3 +- src/widgets/text-toolbar.cpp | 3 +- src/widgets/toolbox.cpp | 1 + src/widgets/tweak-toolbar.cpp | 3 +- 28 files changed, 680 insertions(+), 560 deletions(-) create mode 100644 src/widgets/ink-radio-action.cpp create mode 100644 src/widgets/ink-radio-action.h create mode 100644 src/widgets/ink-toggle-action.cpp create mode 100644 src/widgets/ink-toggle-action.h create mode 100644 src/widgets/ink-tool-menu-action.cpp create mode 100644 src/widgets/ink-tool-menu-action.h (limited to 'src/widgets') diff --git a/src/widgets/CMakeLists.txt b/src/widgets/CMakeLists.txt index ba71b39f4..47ffe82ac 100644 --- a/src/widgets/CMakeLists.txt +++ b/src/widgets/CMakeLists.txt @@ -36,6 +36,9 @@ set(widgets_SRC image-menu-item.c ink-action.cpp ink-comboboxentry-action.cpp + ink-radio-action.cpp + ink-toggle-action.cpp + ink-tool-menu-action.cpp paint-selector.cpp ruler.cpp select-toolbar.cpp @@ -92,6 +95,9 @@ set(widgets_SRC image-menu-item.h ink-action.h ink-comboboxentry-action.h + ink-radio-action.h + ink-toggle-action.h + ink-tool-menu-action.h paint-selector.h ruler.h select-toolbar.h diff --git a/src/widgets/Makefile_insert b/src/widgets/Makefile_insert index 8f10e1d56..7434a5394 100644 --- a/src/widgets/Makefile_insert +++ b/src/widgets/Makefile_insert @@ -50,6 +50,12 @@ ink_common_sources += \ widgets/ink-action.h \ widgets/ink-comboboxentry-action.cpp \ widgets/ink-comboboxentry-action.h \ + widgets/ink-radio-action.cpp \ + widgets/ink-radio-action.h \ + widgets/ink-toggle-action.cpp \ + widgets/ink-toggle-action.h \ + widgets/ink-tool-menu-action.cpp \ + widgets/ink-tool-menu-action.h \ widgets/lpe-toolbar.cpp \ widgets/lpe-toolbar.h \ widgets/measure-toolbar.cpp \ diff --git a/src/widgets/arc-toolbar.cpp b/src/widgets/arc-toolbar.cpp index 35c8c0308..81cde97d4 100644 --- a/src/widgets/arc-toolbar.cpp +++ b/src/widgets/arc-toolbar.cpp @@ -37,7 +37,8 @@ #include "widgets/ege-adjustment-action.h" #include "widgets/ege-output-action.h" #include "widgets/ege-select-one-action.h" -#include "widgets/ink-action.h" +#include "ink-action.h" +#include "ink-radio-action.h" #include "mod360.h" #include "selection.h" #include "sp-ellipse.h" diff --git a/src/widgets/box3d-toolbar.cpp b/src/widgets/box3d-toolbar.cpp index b8c67ee76..95de28cf2 100644 --- a/src/widgets/box3d-toolbar.cpp +++ b/src/widgets/box3d-toolbar.cpp @@ -37,7 +37,7 @@ #include "document-undo.h" #include "document.h" #include "widgets/ege-adjustment-action.h" -#include "widgets/ink-action.h" +#include "widgets/ink-toggle-action.h" #include "inkscape.h" #include "persp3d.h" #include "toolbox.h" diff --git a/src/widgets/calligraphy-toolbar.cpp b/src/widgets/calligraphy-toolbar.cpp index ba51499aa..031295ccd 100644 --- a/src/widgets/calligraphy-toolbar.cpp +++ b/src/widgets/calligraphy-toolbar.cpp @@ -37,6 +37,7 @@ #include "widgets/ege-adjustment-action.h" #include "widgets/ege-select-one-action.h" #include "widgets/ink-action.h" +#include "widgets/ink-toggle-action.h" #include "toolbox.h" #include "ui/icon-names.h" #include "ui/uxmanager.h" diff --git a/src/widgets/connector-toolbar.cpp b/src/widgets/connector-toolbar.cpp index f80f49db7..46493f3ae 100644 --- a/src/widgets/connector-toolbar.cpp +++ b/src/widgets/connector-toolbar.cpp @@ -38,7 +38,8 @@ #include "widgets/ege-adjustment-action.h" #include "enums.h" #include "graphlayout.h" -#include "widgets/ink-action.h" +#include "ink-action.h" +#include "ink-toggle-action.h" #include "inkscape.h" #include "sp-namedview.h" #include "toolbox.h" diff --git a/src/widgets/dropper-toolbar.cpp b/src/widgets/dropper-toolbar.cpp index f60955da5..4e26a99a0 100644 --- a/src/widgets/dropper-toolbar.cpp +++ b/src/widgets/dropper-toolbar.cpp @@ -33,7 +33,7 @@ #include "dropper-toolbar.h" #include "document-undo.h" #include "widgets/ege-output-action.h" -#include "widgets/ink-action.h" +#include "ink-toggle-action.h" #include "preferences.h" #include "widgets/spinbutton-events.h" diff --git a/src/widgets/eraser-toolbar.cpp b/src/widgets/eraser-toolbar.cpp index b30d542a6..7f710a777 100644 --- a/src/widgets/eraser-toolbar.cpp +++ b/src/widgets/eraser-toolbar.cpp @@ -37,7 +37,9 @@ #include "document-undo.h" #include "widgets/ege-adjustment-action.h" #include "widgets/ege-select-one-action.h" -#include "widgets/ink-action.h" +#include "ink-action.h" +#include "ink-radio-action.h" +#include "ink-toggle-action.h" #include "toolbox.h" #include "ui/icon-names.h" diff --git a/src/widgets/gradient-toolbar.cpp b/src/widgets/gradient-toolbar.cpp index 7e9223770..fd2eb7efe 100644 --- a/src/widgets/gradient-toolbar.cpp +++ b/src/widgets/gradient-toolbar.cpp @@ -27,7 +27,9 @@ #include "gradient-chemistry.h" #include "gradient-drag.h" #include "gradient-toolbar.h" -#include "widgets/ink-action.h" +#include "ink-action.h" +#include "ink-radio-action.h" +#include "ink-toggle-action.h" #include "macros.h" #include "selection.h" #include "sp-defs.h" diff --git a/src/widgets/ink-action.cpp b/src/widgets/ink-action.cpp index 501aeaa74..2f1bf94e4 100644 --- a/src/widgets/ink-action.cpp +++ b/src/widgets/ink-action.cpp @@ -205,433 +205,13 @@ static GtkWidget* ink_action_create_tool_item( GtkAction* action ) return item; } - - -/* --------------------------------------------------------------- */ -/* --------------------------------------------------------------- */ -/* --------------------------------------------------------------- */ -/* --------------------------------------------------------------- */ - - -static void ink_toggle_action_finalize( GObject* obj ); -static void ink_toggle_action_get_property( GObject* obj, guint propId, GValue* value, GParamSpec * pspec ); -static void ink_toggle_action_set_property( GObject* obj, guint propId, const GValue *value, GParamSpec* pspec ); - -static GtkWidget* ink_toggle_action_create_menu_item( GtkAction* action ); -static GtkWidget* ink_toggle_action_create_tool_item( GtkAction* action ); - -static void ink_toggle_action_update_icon( InkToggleAction* action ); - -struct _InkToggleActionPrivate -{ - gchar* iconId; - Inkscape::IconSize iconSize; -}; - -#define INK_TOGGLE_ACTION_GET_PRIVATE( o ) ( G_TYPE_INSTANCE_GET_PRIVATE( (o), INK_TOGGLE_ACTION_TYPE, InkToggleActionPrivate ) ) - -G_DEFINE_TYPE(InkToggleAction, ink_toggle_action, GTK_TYPE_TOGGLE_ACTION); - -static void ink_toggle_action_class_init( InkToggleActionClass* klass ) -{ - if ( klass ) { - GObjectClass * objClass = G_OBJECT_CLASS( klass ); - - objClass->finalize = ink_toggle_action_finalize; - objClass->get_property = ink_toggle_action_get_property; - objClass->set_property = ink_toggle_action_set_property; - - klass->parent_class.parent_class.create_menu_item = ink_toggle_action_create_menu_item; - klass->parent_class.parent_class.create_tool_item = ink_toggle_action_create_tool_item; - /*klass->parent_class.connect_proxy = connect_proxy;*/ - /*klass->parent_class.disconnect_proxy = disconnect_proxy;*/ - - g_object_class_install_property( objClass, - PROP_INK_ID, - g_param_spec_string( "iconId", - "Icon ID", - "The id for the icon", - "", - (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) ); - - g_object_class_install_property( objClass, - PROP_INK_SIZE, - g_param_spec_int( "iconSize", - "Icon Size", - "The size the icon", - (int)Inkscape::ICON_SIZE_MENU, - (int)99, - (int)Inkscape::ICON_SIZE_SMALL_TOOLBAR, - (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) ); - - g_type_class_add_private( klass, sizeof(InkToggleActionClass) ); - } -} - -static void ink_toggle_action_init( InkToggleAction* action ) -{ - action->private_data = INK_TOGGLE_ACTION_GET_PRIVATE( action ); - action->private_data->iconId = 0; - action->private_data->iconSize = Inkscape::ICON_SIZE_SMALL_TOOLBAR; -} - -static void ink_toggle_action_finalize( GObject* obj ) -{ - InkToggleAction* action = INK_TOGGLE_ACTION( obj ); - - g_free( action->private_data->iconId ); - g_free( action->private_data ); - -} - -InkToggleAction* ink_toggle_action_new( const gchar *name, - const gchar *label, - const gchar *tooltip, - const gchar *inkId, - Inkscape::IconSize size, - SPAttributeEnum attr) -{ - GObject* obj = (GObject*)g_object_new( INK_TOGGLE_ACTION_TYPE, - "name", name, - "label", label, - "tooltip", tooltip, - "iconId", inkId, - "iconSize", Inkscape::getRegisteredIconSize(size), - //"SP_ATTR_INKSCAPE", attr, // Why doesn't this work and do I need to use g_object_set_data below? - NULL ); - - g_object_set_data(obj, "SP_ATTR_INKSCAPE", GINT_TO_POINTER(attr)); - InkToggleAction* action = INK_TOGGLE_ACTION( obj ); - - return action; -} - -static void ink_toggle_action_get_property( GObject* obj, guint propId, GValue* value, GParamSpec * pspec ) -{ - InkToggleAction* action = INK_TOGGLE_ACTION( obj ); - (void)action; - switch ( propId ) { - case PROP_INK_ID: - { - g_value_set_string( value, action->private_data->iconId ); - } - break; - - case PROP_INK_SIZE: - { - g_value_set_int( value, action->private_data->iconSize ); - } - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID( obj, propId, pspec ); - } -} - -void ink_toggle_action_set_property( GObject* obj, guint propId, const GValue *value, GParamSpec* pspec ) -{ - InkToggleAction* action = INK_TOGGLE_ACTION( obj ); - (void)action; - switch ( propId ) { - case PROP_INK_ID: - { - gchar* tmp = action->private_data->iconId; - action->private_data->iconId = g_value_dup_string( value ); - g_free( tmp ); - - ink_toggle_action_update_icon( action ); - } - break; - - case PROP_INK_SIZE: - { - action->private_data->iconSize = (Inkscape::IconSize)g_value_get_int( value ); - } - break; - - default: - { - G_OBJECT_WARN_INVALID_PROPERTY_ID( obj, propId, pspec ); - } - } -} - -static GtkWidget* ink_toggle_action_create_menu_item( GtkAction* action ) -{ - GtkWidget* item = GTK_TOGGLE_ACTION_CLASS(ink_toggle_action_parent_class)->parent_class.create_menu_item(action); - - return item; -} - -static GtkWidget* ink_toggle_action_create_tool_item( GtkAction* action ) -{ - InkToggleAction* act = INK_TOGGLE_ACTION( action ); - - GtkWidget* item = GTK_TOGGLE_ACTION_CLASS(ink_toggle_action_parent_class)->parent_class.create_tool_item(action); - if ( GTK_IS_TOOL_BUTTON(item) ) { - GtkToolButton* button = GTK_TOOL_BUTTON(item); - if ( act->private_data->iconId ) { - GtkWidget* child = sp_icon_new( act->private_data->iconSize, act->private_data->iconId ); - - gtk_widget_set_hexpand(child, FALSE); - gtk_widget_set_vexpand(child, FALSE); - gtk_tool_button_set_icon_widget(button, child); - } else { - gchar *label = 0; - g_object_get( G_OBJECT(action), "short_label", &label, NULL ); - gtk_tool_button_set_label( button, label ); - g_free( label ); - label = 0; - } - } else { - // For now trigger a warning but don't do anything else - GtkToolButton* button = GTK_TOOL_BUTTON(item); - (void)button; - } - gtk_widget_show_all( item ); - - return item; -} - - -static void ink_toggle_action_update_icon( InkToggleAction* action ) -{ - if ( action ) { - GSList* proxies = gtk_action_get_proxies( GTK_ACTION(action) ); - while ( proxies ) { - if ( GTK_IS_TOOL_ITEM(proxies->data) ) { - if ( GTK_IS_TOOL_BUTTON(proxies->data) ) { - GtkToolButton* button = GTK_TOOL_BUTTON(proxies->data); - - GtkWidget* child = sp_icon_new( action->private_data->iconSize, action->private_data->iconId ); - gtk_widget_set_hexpand(child, FALSE); - gtk_widget_set_vexpand(child, FALSE); - gtk_widget_show_all(child); - gtk_tool_button_set_icon_widget(button, child); - } - } - - proxies = g_slist_next( proxies ); - } - } -} - - -/* --------------------------------------------------------------- */ -/* --------------------------------------------------------------- */ -/* --------------------------------------------------------------- */ -/* --------------------------------------------------------------- */ - - -static void ink_radio_action_finalize( GObject* obj ); -static void ink_radio_action_get_property( GObject* obj, guint propId, GValue* value, GParamSpec * pspec ); -static void ink_radio_action_set_property( GObject* obj, guint propId, const GValue *value, GParamSpec* pspec ); - -static GtkWidget* ink_radio_action_create_menu_item( GtkAction* action ); -static GtkWidget* ink_radio_action_create_tool_item( GtkAction* action ); - -struct _InkRadioActionPrivate -{ - gchar* iconId; - Inkscape::IconSize iconSize; -}; - -#define INK_RADIO_ACTION_GET_PRIVATE( o ) ( G_TYPE_INSTANCE_GET_PRIVATE( (o), INK_RADIO_ACTION_TYPE, InkRadioActionPrivate ) ) - -G_DEFINE_TYPE(InkRadioAction, ink_radio_action, GTK_TYPE_RADIO_ACTION); - -static void ink_radio_action_class_init( InkRadioActionClass* klass ) -{ - if ( klass ) { - GObjectClass * objClass = G_OBJECT_CLASS( klass ); - - objClass->finalize = ink_radio_action_finalize; - objClass->get_property = ink_radio_action_get_property; - objClass->set_property = ink_radio_action_set_property; - - klass->parent_class.parent_class.parent_class.create_menu_item = ink_radio_action_create_menu_item; - klass->parent_class.parent_class.parent_class.create_tool_item = ink_radio_action_create_tool_item; - /*klass->parent_class.connect_proxy = connect_proxy;*/ - /*klass->parent_class.disconnect_proxy = disconnect_proxy;*/ - - g_object_class_install_property( objClass, - PROP_INK_ID, - g_param_spec_string( "iconId", - "Icon ID", - "The id for the icon", - "", - (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) ); - - g_object_class_install_property( objClass, - PROP_INK_SIZE, - g_param_spec_int( "iconSize", - "Icon Size", - "The size the icon", - (int)Inkscape::ICON_SIZE_MENU, - (int)Inkscape::ICON_SIZE_DECORATION, - (int)Inkscape::ICON_SIZE_SMALL_TOOLBAR, - (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) ); - - g_type_class_add_private( klass, sizeof(InkRadioActionClass) ); - } -} - -static void ink_radio_action_init( InkRadioAction* action ) -{ - action->private_data = INK_RADIO_ACTION_GET_PRIVATE( action ); - action->private_data->iconId = 0; - action->private_data->iconSize = Inkscape::ICON_SIZE_SMALL_TOOLBAR; -} - -static void ink_radio_action_finalize( GObject* obj ) -{ - InkRadioAction* action = INK_RADIO_ACTION( obj ); - - g_free( action->private_data->iconId ); - g_free( action->private_data ); - -} - -InkRadioAction* ink_radio_action_new( const gchar *name, - const gchar *label, - const gchar *tooltip, - const gchar *inkId, - Inkscape::IconSize size ) -{ - GObject* obj = (GObject*)g_object_new( INK_RADIO_ACTION_TYPE, - "name", name, - "label", label, - "tooltip", tooltip, - "iconId", inkId, - "iconSize", Inkscape::getRegisteredIconSize(size), - NULL ); - - InkRadioAction* action = INK_RADIO_ACTION( obj ); - - return action; -} - -static void ink_radio_action_get_property( GObject* obj, guint propId, GValue* value, GParamSpec * pspec ) -{ - InkRadioAction* action = INK_RADIO_ACTION( obj ); - (void)action; - switch ( propId ) { - case PROP_INK_ID: - { - g_value_set_string( value, action->private_data->iconId ); - } - break; - - case PROP_INK_SIZE: - { - g_value_set_int( value, action->private_data->iconSize ); - } - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID( obj, propId, pspec ); - } -} - -void ink_radio_action_set_property( GObject* obj, guint propId, const GValue *value, GParamSpec* pspec ) -{ - InkRadioAction* action = INK_RADIO_ACTION( obj ); - (void)action; - switch ( propId ) { - case PROP_INK_ID: - { - gchar* tmp = action->private_data->iconId; - action->private_data->iconId = g_value_dup_string( value ); - g_free( tmp ); - } - break; - - case PROP_INK_SIZE: - { - action->private_data->iconSize = (Inkscape::IconSize)g_value_get_int( value ); - } - break; - - default: - { - G_OBJECT_WARN_INVALID_PROPERTY_ID( obj, propId, pspec ); - } - } -} - -static GtkWidget* ink_radio_action_create_menu_item( GtkAction* action ) -{ - GtkWidget* item = GTK_RADIO_ACTION_CLASS(ink_radio_action_parent_class)->parent_class.parent_class.create_menu_item(action); - - return item; -} - -static GtkWidget* ink_radio_action_create_tool_item( GtkAction* action ) -{ - InkRadioAction* act = INK_RADIO_ACTION( action ); - GtkWidget* item = GTK_RADIO_ACTION_CLASS(ink_radio_action_parent_class)->parent_class.parent_class.create_tool_item(action); - - if ( act->private_data->iconId ) { - if ( GTK_IS_TOOL_BUTTON(item) ) { - GtkToolButton* button = GTK_TOOL_BUTTON(item); - - GtkWidget* child = sp_icon_new( act->private_data->iconSize, act->private_data->iconId ); - gtk_widget_set_hexpand(child, FALSE); - gtk_widget_set_vexpand(child, FALSE); - gtk_tool_button_set_icon_widget(button, child); - } else { - // For now trigger a warning but don't do anything else - GtkToolButton* button = GTK_TOOL_BUTTON(item); - (void)button; - } - } - - // TODO investigate if needed - gtk_widget_show_all( item ); - - return item; -} - - -/* --------------------------------------------------------------- */ -/* --------------------------------------------------------------- */ -/* --------------------------------------------------------------- */ -/* --------------------------------------------------------------- */ - -// ToolMenu Action is happily derived from http://www.gtkforums.com/viewtopic.php?t=4215 - -G_DEFINE_TYPE(InkToolMenuAction, ink_tool_menu_action, INK_ACTION_TYPE); - -static void -ink_tool_menu_action_class_init (InkToolMenuActionClass *klass) -{ - GtkActionClass *action_class = GTK_ACTION_CLASS (klass); - action_class->toolbar_item_type = GTK_TYPE_MENU_TOOL_BUTTON; -} - -static void -ink_tool_menu_action_init (InkToolMenuAction* /*tma*/) -{ -} - -InkToolMenuAction * -ink_tool_menu_action_new (const gchar *name, - const gchar *label, - const gchar *tooltip, - const gchar *inkId, - Inkscape::IconSize size ) -{ - g_return_val_if_fail (name != NULL, NULL); - - GObject* obj = (GObject*)g_object_new( INK_TOOL_MENU_ACTION_TYPE, - "name", name, - "label", label, - "tooltip", tooltip, - "iconId", inkId, - "iconSize", size, - NULL ); - - InkToolMenuAction* action = INK_TOOL_MENU_ACTION( obj ); - - return action; -} +/* + 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/widgets/ink-action.h b/src/widgets/ink-action.h index ac5cb9873..738212c61 100644 --- a/src/widgets/ink-action.h +++ b/src/widgets/ink-action.h @@ -1,7 +1,6 @@ #ifndef SEEN_INK_ACTION #define SEEN_INK_ACTION - #include #include "icon-size.h" #include "attributes.h" @@ -41,119 +40,16 @@ InkAction* ink_action_new( const gchar *name, Inkscape::IconSize size ); -/* --------------------------------------------------------------- */ -/* --------------------------------------------------------------- */ -/* --------------------------------------------------------------- */ -/* --------------------------------------------------------------- */ - - -#define INK_TOGGLE_ACTION_TYPE ( ink_toggle_action_get_type() ) -#define INK_TOGGLE_ACTION( obj ) ( G_TYPE_CHECK_INSTANCE_CAST( (obj), INK_TOGGLE_ACTION_TYPE, InkToggleAction) ) -#define INK_TOGGLE_ACTION_CLASS( klass ) ( G_TYPE_CHECK_CLASS_CAST( (klass), INK_TOGGLE_ACTION_TYPE, InkToggleActionClass) ) -#define IS_INK_TOGGLE_ACTION( obj ) ( G_TYPE_CHECK_INSTANCE_TYPE( (obj), INK_TOGGLE_ACTION_TYPE) ) -#define IS_INK_TOGGLE_ACTION_CLASS( klass ) ( G_TYPE_CHECK_CLASS_TYPE( (klass), INK_TOGGLE_ACTION_TYPE) ) -#define INK_TOGGLE_ACTION_GET_CLASS( obj ) ( G_TYPE_INSTANCE_GET_CLASS( (obj), INK_TOGGLE_ACTION_TYPE, InkToggleActionClass) ) - -typedef struct _InkToggleAction InkToggleAction; -typedef struct _InkToggleActionClass InkToggleActionClass; -typedef struct _InkToggleActionPrivate InkToggleActionPrivate; - -struct _InkToggleAction -{ - GtkToggleAction action; - InkToggleActionPrivate *private_data; -}; - -struct _InkToggleActionClass -{ - GtkToggleActionClass parent_class; -}; - -GType ink_toggle_action_get_type( void ); - -InkToggleAction* ink_toggle_action_new( const gchar *name, - const gchar *label, - const gchar *tooltip, - const gchar *inkId, - Inkscape::IconSize size, - SPAttributeEnum attr = SP_ATTR_INVALID); - - -/* --------------------------------------------------------------- */ -/* --------------------------------------------------------------- */ -/* --------------------------------------------------------------- */ -/* --------------------------------------------------------------- */ - - -#define INK_RADIO_ACTION_TYPE ( ink_radio_action_get_type() ) -#define INK_RADIO_ACTION( obj ) ( G_TYPE_CHECK_INSTANCE_CAST( (obj), INK_RADIO_ACTION_TYPE, InkRadioAction) ) -#define INK_RADIO_ACTION_CLASS( klass ) ( G_TYPE_CHECK_CLASS_CAST( (klass), INK_RADIO_ACTION_TYPE, InkRadioActionClass) ) -#define IS_INK_RADIO_ACTION( obj ) ( G_TYPE_CHECK_INSTANCE_TYPE( (obj), INK_RADIO_ACTION_TYPE) ) -#define IS_INK_RADIO_ACTION_CLASS( klass ) ( G_TYPE_CHECK_CLASS_TYPE( (klass), INK_RADIO_ACTION_TYPE) ) -#define INK_RADIO_ACTION_GET_CLASS( obj ) ( G_TYPE_INSTANCE_GET_CLASS( (obj), INK_RADIO_ACTION_TYPE, InkRadioActionClass) ) - -typedef struct _InkRadioAction InkRadioAction; -typedef struct _InkRadioActionClass InkRadioActionClass; -typedef struct _InkRadioActionPrivate InkRadioActionPrivate; - -struct _InkRadioAction -{ - GtkRadioAction action; - InkRadioActionPrivate *private_data; -}; - -struct _InkRadioActionClass -{ - GtkRadioActionClass parent_class; -}; - -GType ink_radio_action_get_type( void ); - -InkRadioAction* ink_radio_action_new( const gchar *name, - const gchar *label, - const gchar *tooltip, - const gchar *inkId, - Inkscape::IconSize size ); - - -/* --------------------------------------------------------------- */ -/* --------------------------------------------------------------- */ -/* --------------------------------------------------------------- */ -/* --------------------------------------------------------------- */ - -// ToolMenu Action is happily derived from http://www.gtkforums.com/viewtopic.php?t=4215 - -#define INK_TOOL_MENU_ACTION_TYPE ( ink_tool_menu_action_get_type() ) -#define INK_TOOL_MENU_ACTION( obj ) ( G_TYPE_CHECK_INSTANCE_CAST( (obj), INK_TOOL_MENU_ACTION_TYPE, InkToolMenuAction) ) -#define INK_TOOL_MENU_ACTION_CLASS( klass ) ( G_TYPE_CHECK_CLASS_CAST( (klass), INK_TOOL_MENU_ACTION_TYPE, InkToolMenuActionClass) ) -#define IS_INK_TOOL_MENU_ACTION( obj ) ( G_TYPE_CHECK_INSTANCE_TYPE( (obj), INK_TOOL_MENU_ACTION_TYPE) ) -#define IS_INK_TOOL_MENU_ACTION_CLASS( klass ) ( G_TYPE_CHECK_CLASS_TYPE( (klass), INK_TOOL_MENU_ACTION_TYPE) ) -#define INK_TOOL_MENU_ACTION_GET_CLASS( obj ) ( G_TYPE_INSTANCE_GET_CLASS( (obj), INK_TOOL_MENU_ACTION_TYPE, InkToolMenuActionClass) ) - -typedef struct _InkToolMenuAction InkToolMenuAction; -typedef struct _InkToolMenuActionClass InkToolMenuActionClass; -typedef struct _InkToolMenuActionPrivate InkToolMenuActionPrivate; - -struct _InkToolMenuAction -{ - InkAction action; -}; - -struct _InkToolMenuActionClass -{ - InkActionClass parent_class; -}; - -GType ink_tool_menu_action_get_type( void ); - -InkToolMenuAction* ink_tool_menu_action_new( const gchar *name, - const gchar *label, - const gchar *tooltip, - const gchar *inkId, - Inkscape::IconSize size ); - - - G_END_DECLS #endif /* SEEN_INK_ACTION */ +/* + 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/widgets/ink-radio-action.cpp b/src/widgets/ink-radio-action.cpp new file mode 100644 index 000000000..2113819c3 --- /dev/null +++ b/src/widgets/ink-radio-action.cpp @@ -0,0 +1,185 @@ +#include "ink-radio-action.h" + +static void ink_radio_action_finalize( GObject* obj ); +static void ink_radio_action_get_property( GObject* obj, guint propId, GValue* value, GParamSpec * pspec ); +static void ink_radio_action_set_property( GObject* obj, guint propId, const GValue *value, GParamSpec* pspec ); + +static GtkWidget* ink_radio_action_create_menu_item( GtkAction* action ); +static GtkWidget* ink_radio_action_create_tool_item( GtkAction* action ); + +struct _InkRadioActionPrivate +{ + gchar* iconId; + Inkscape::IconSize iconSize; +}; + +#define INK_RADIO_ACTION_GET_PRIVATE( o ) ( G_TYPE_INSTANCE_GET_PRIVATE( (o), INK_RADIO_ACTION_TYPE, InkRadioActionPrivate ) ) + +G_DEFINE_TYPE(InkRadioAction, ink_radio_action, GTK_TYPE_RADIO_ACTION); + +enum { + PROP_INK_ID = 1, + PROP_INK_SIZE +}; + +static void ink_radio_action_class_init( InkRadioActionClass* klass ) +{ + if ( klass ) { + GObjectClass * objClass = G_OBJECT_CLASS( klass ); + + objClass->finalize = ink_radio_action_finalize; + objClass->get_property = ink_radio_action_get_property; + objClass->set_property = ink_radio_action_set_property; + + klass->parent_class.parent_class.parent_class.create_menu_item = ink_radio_action_create_menu_item; + klass->parent_class.parent_class.parent_class.create_tool_item = ink_radio_action_create_tool_item; + /*klass->parent_class.connect_proxy = connect_proxy;*/ + /*klass->parent_class.disconnect_proxy = disconnect_proxy;*/ + + g_object_class_install_property( objClass, + PROP_INK_ID, + g_param_spec_string( "iconId", + "Icon ID", + "The id for the icon", + "", + (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) ); + + g_object_class_install_property( objClass, + PROP_INK_SIZE, + g_param_spec_int( "iconSize", + "Icon Size", + "The size the icon", + (int)Inkscape::ICON_SIZE_MENU, + (int)Inkscape::ICON_SIZE_DECORATION, + (int)Inkscape::ICON_SIZE_SMALL_TOOLBAR, + (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) ); + + g_type_class_add_private( klass, sizeof(InkRadioActionClass) ); + } +} + +static void ink_radio_action_init( InkRadioAction* action ) +{ + action->private_data = INK_RADIO_ACTION_GET_PRIVATE( action ); + action->private_data->iconId = 0; + action->private_data->iconSize = Inkscape::ICON_SIZE_SMALL_TOOLBAR; +} + +static void ink_radio_action_finalize( GObject* obj ) +{ + InkRadioAction* action = INK_RADIO_ACTION( obj ); + + g_free( action->private_data->iconId ); + g_free( action->private_data ); + +} + +InkRadioAction* ink_radio_action_new( const gchar *name, + const gchar *label, + const gchar *tooltip, + const gchar *inkId, + Inkscape::IconSize size ) +{ + GObject* obj = (GObject*)g_object_new( INK_RADIO_ACTION_TYPE, + "name", name, + "label", label, + "tooltip", tooltip, + "iconId", inkId, + "iconSize", Inkscape::getRegisteredIconSize(size), + NULL ); + + InkRadioAction* action = INK_RADIO_ACTION( obj ); + + return action; +} + +static void ink_radio_action_get_property( GObject* obj, guint propId, GValue* value, GParamSpec * pspec ) +{ + InkRadioAction* action = INK_RADIO_ACTION( obj ); + (void)action; + switch ( propId ) { + case PROP_INK_ID: + { + g_value_set_string( value, action->private_data->iconId ); + } + break; + + case PROP_INK_SIZE: + { + g_value_set_int( value, action->private_data->iconSize ); + } + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID( obj, propId, pspec ); + } +} + +void ink_radio_action_set_property( GObject* obj, guint propId, const GValue *value, GParamSpec* pspec ) +{ + InkRadioAction* action = INK_RADIO_ACTION( obj ); + (void)action; + switch ( propId ) { + case PROP_INK_ID: + { + gchar* tmp = action->private_data->iconId; + action->private_data->iconId = g_value_dup_string( value ); + g_free( tmp ); + } + break; + + case PROP_INK_SIZE: + { + action->private_data->iconSize = (Inkscape::IconSize)g_value_get_int( value ); + } + break; + + default: + { + G_OBJECT_WARN_INVALID_PROPERTY_ID( obj, propId, pspec ); + } + } +} + +static GtkWidget* ink_radio_action_create_menu_item( GtkAction* action ) +{ + GtkWidget* item = GTK_RADIO_ACTION_CLASS(ink_radio_action_parent_class)->parent_class.parent_class.create_menu_item(action); + + return item; +} + +static GtkWidget* ink_radio_action_create_tool_item( GtkAction* action ) +{ + InkRadioAction* act = INK_RADIO_ACTION( action ); + GtkWidget* item = GTK_RADIO_ACTION_CLASS(ink_radio_action_parent_class)->parent_class.parent_class.create_tool_item(action); + + if ( act->private_data->iconId ) { + if ( GTK_IS_TOOL_BUTTON(item) ) { + GtkToolButton* button = GTK_TOOL_BUTTON(item); + + GtkWidget* child = sp_icon_new( act->private_data->iconSize, act->private_data->iconId ); + gtk_widget_set_hexpand(child, FALSE); + gtk_widget_set_vexpand(child, FALSE); + gtk_tool_button_set_icon_widget(button, child); + } else { + // For now trigger a warning but don't do anything else + GtkToolButton* button = GTK_TOOL_BUTTON(item); + (void)button; + } + } + + // TODO investigate if needed + gtk_widget_show_all( item ); + + return item; +} +/* + 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/widgets/ink-radio-action.h b/src/widgets/ink-radio-action.h new file mode 100644 index 000000000..c1f059c4f --- /dev/null +++ b/src/widgets/ink-radio-action.h @@ -0,0 +1,52 @@ +#ifndef INK_RADIO_ACTION_H +#define INK_RADIO_ACTION_H + +#include + +#include "icon.h" + +G_BEGIN_DECLS + +#define INK_RADIO_ACTION_TYPE ( ink_radio_action_get_type() ) +#define INK_RADIO_ACTION( obj ) ( G_TYPE_CHECK_INSTANCE_CAST( (obj), INK_RADIO_ACTION_TYPE, InkRadioAction) ) +#define INK_RADIO_ACTION_CLASS( klass ) ( G_TYPE_CHECK_CLASS_CAST( (klass), INK_RADIO_ACTION_TYPE, InkRadioActionClass) ) +#define IS_INK_RADIO_ACTION( obj ) ( G_TYPE_CHECK_INSTANCE_TYPE( (obj), INK_RADIO_ACTION_TYPE) ) +#define IS_INK_RADIO_ACTION_CLASS( klass ) ( G_TYPE_CHECK_CLASS_TYPE( (klass), INK_RADIO_ACTION_TYPE) ) +#define INK_RADIO_ACTION_GET_CLASS( obj ) ( G_TYPE_INSTANCE_GET_CLASS( (obj), INK_RADIO_ACTION_TYPE, InkRadioActionClass) ) + +typedef struct _InkRadioAction InkRadioAction; +typedef struct _InkRadioActionClass InkRadioActionClass; +typedef struct _InkRadioActionPrivate InkRadioActionPrivate; + +struct _InkRadioAction +{ + GtkRadioAction action; + InkRadioActionPrivate *private_data; +}; + +struct _InkRadioActionClass +{ + GtkRadioActionClass parent_class; +}; + +GType ink_radio_action_get_type( void ); + +InkRadioAction* ink_radio_action_new( const gchar *name, + const gchar *label, + const gchar *tooltip, + const gchar *inkId, + Inkscape::IconSize size ); + +G_END_DECLS + +#endif // INK_RADIO_ACTION_H +/* + 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/widgets/ink-toggle-action.cpp b/src/widgets/ink-toggle-action.cpp new file mode 100644 index 000000000..3eed974dc --- /dev/null +++ b/src/widgets/ink-toggle-action.cpp @@ -0,0 +1,221 @@ +#include "ink-toggle-action.h" +#include "icon.h" + +static void ink_toggle_action_finalize( GObject* obj ); +static void ink_toggle_action_get_property( GObject* obj, guint propId, GValue* value, GParamSpec * pspec ); +static void ink_toggle_action_set_property( GObject* obj, guint propId, const GValue *value, GParamSpec* pspec ); + +static GtkWidget* ink_toggle_action_create_menu_item( GtkAction* action ); +static GtkWidget* ink_toggle_action_create_tool_item( GtkAction* action ); + +static void ink_toggle_action_update_icon( InkToggleAction* action ); + +struct _InkToggleActionPrivate +{ + gchar* iconId; + Inkscape::IconSize iconSize; +}; + +#define INK_TOGGLE_ACTION_GET_PRIVATE( o ) ( G_TYPE_INSTANCE_GET_PRIVATE( (o), INK_TOGGLE_ACTION_TYPE, InkToggleActionPrivate ) ) + +G_DEFINE_TYPE(InkToggleAction, ink_toggle_action, GTK_TYPE_TOGGLE_ACTION); + +enum { + PROP_INK_ID = 1, + PROP_INK_SIZE +}; + +static void ink_toggle_action_class_init( InkToggleActionClass* klass ) +{ + if ( klass ) { + GObjectClass * objClass = G_OBJECT_CLASS( klass ); + + objClass->finalize = ink_toggle_action_finalize; + objClass->get_property = ink_toggle_action_get_property; + objClass->set_property = ink_toggle_action_set_property; + + klass->parent_class.parent_class.create_menu_item = ink_toggle_action_create_menu_item; + klass->parent_class.parent_class.create_tool_item = ink_toggle_action_create_tool_item; + /*klass->parent_class.connect_proxy = connect_proxy;*/ + /*klass->parent_class.disconnect_proxy = disconnect_proxy;*/ + + g_object_class_install_property( objClass, + PROP_INK_ID, + g_param_spec_string( "iconId", + "Icon ID", + "The id for the icon", + "", + (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) ); + + g_object_class_install_property( objClass, + PROP_INK_SIZE, + g_param_spec_int( "iconSize", + "Icon Size", + "The size the icon", + (int)Inkscape::ICON_SIZE_MENU, + (int)99, + (int)Inkscape::ICON_SIZE_SMALL_TOOLBAR, + (GParamFlags)(G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT) ) ); + + g_type_class_add_private( klass, sizeof(InkToggleActionClass) ); + } +} + +static void ink_toggle_action_init( InkToggleAction* action ) +{ + action->private_data = INK_TOGGLE_ACTION_GET_PRIVATE( action ); + action->private_data->iconId = 0; + action->private_data->iconSize = Inkscape::ICON_SIZE_SMALL_TOOLBAR; +} + +static void ink_toggle_action_finalize( GObject* obj ) +{ + InkToggleAction* action = INK_TOGGLE_ACTION( obj ); + + g_free( action->private_data->iconId ); + g_free( action->private_data ); + +} + +InkToggleAction* ink_toggle_action_new( const gchar *name, + const gchar *label, + const gchar *tooltip, + const gchar *inkId, + Inkscape::IconSize size, + SPAttributeEnum attr) +{ + GObject* obj = (GObject*)g_object_new( INK_TOGGLE_ACTION_TYPE, + "name", name, + "label", label, + "tooltip", tooltip, + "iconId", inkId, + "iconSize", Inkscape::getRegisteredIconSize(size), + //"SP_ATTR_INKSCAPE", attr, // Why doesn't this work and do I need to use g_object_set_data below? + NULL ); + + g_object_set_data(obj, "SP_ATTR_INKSCAPE", GINT_TO_POINTER(attr)); + InkToggleAction* action = INK_TOGGLE_ACTION( obj ); + + return action; +} + +static void ink_toggle_action_get_property( GObject* obj, guint propId, GValue* value, GParamSpec * pspec ) +{ + InkToggleAction* action = INK_TOGGLE_ACTION( obj ); + (void)action; + switch ( propId ) { + case PROP_INK_ID: + { + g_value_set_string( value, action->private_data->iconId ); + } + break; + + case PROP_INK_SIZE: + { + g_value_set_int( value, action->private_data->iconSize ); + } + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID( obj, propId, pspec ); + } +} + +void ink_toggle_action_set_property( GObject* obj, guint propId, const GValue *value, GParamSpec* pspec ) +{ + InkToggleAction* action = INK_TOGGLE_ACTION( obj ); + (void)action; + switch ( propId ) { + case PROP_INK_ID: + { + gchar* tmp = action->private_data->iconId; + action->private_data->iconId = g_value_dup_string( value ); + g_free( tmp ); + + ink_toggle_action_update_icon( action ); + } + break; + + case PROP_INK_SIZE: + { + action->private_data->iconSize = (Inkscape::IconSize)g_value_get_int( value ); + } + break; + + default: + { + G_OBJECT_WARN_INVALID_PROPERTY_ID( obj, propId, pspec ); + } + } +} + +static GtkWidget* ink_toggle_action_create_menu_item( GtkAction* action ) +{ + GtkWidget* item = GTK_TOGGLE_ACTION_CLASS(ink_toggle_action_parent_class)->parent_class.create_menu_item(action); + + return item; +} + +static GtkWidget* ink_toggle_action_create_tool_item( GtkAction* action ) +{ + InkToggleAction* act = INK_TOGGLE_ACTION( action ); + + GtkWidget* item = GTK_TOGGLE_ACTION_CLASS(ink_toggle_action_parent_class)->parent_class.create_tool_item(action); + if ( GTK_IS_TOOL_BUTTON(item) ) { + GtkToolButton* button = GTK_TOOL_BUTTON(item); + if ( act->private_data->iconId ) { + GtkWidget* child = sp_icon_new( act->private_data->iconSize, act->private_data->iconId ); + + gtk_widget_set_hexpand(child, FALSE); + gtk_widget_set_vexpand(child, FALSE); + gtk_tool_button_set_icon_widget(button, child); + } else { + gchar *label = 0; + g_object_get( G_OBJECT(action), "short_label", &label, NULL ); + gtk_tool_button_set_label( button, label ); + g_free( label ); + label = 0; + } + } else { + // For now trigger a warning but don't do anything else + GtkToolButton* button = GTK_TOOL_BUTTON(item); + (void)button; + } + gtk_widget_show_all( item ); + + return item; +} + + +static void ink_toggle_action_update_icon( InkToggleAction* action ) +{ + if ( action ) { + GSList* proxies = gtk_action_get_proxies( GTK_ACTION(action) ); + while ( proxies ) { + if ( GTK_IS_TOOL_ITEM(proxies->data) ) { + if ( GTK_IS_TOOL_BUTTON(proxies->data) ) { + GtkToolButton* button = GTK_TOOL_BUTTON(proxies->data); + + GtkWidget* child = sp_icon_new( action->private_data->iconSize, action->private_data->iconId ); + gtk_widget_set_hexpand(child, FALSE); + gtk_widget_set_vexpand(child, FALSE); + gtk_widget_show_all(child); + gtk_tool_button_set_icon_widget(button, child); + } + } + + proxies = g_slist_next( proxies ); + } + } +} + +/* + 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/widgets/ink-toggle-action.h b/src/widgets/ink-toggle-action.h new file mode 100644 index 000000000..8e9d5e257 --- /dev/null +++ b/src/widgets/ink-toggle-action.h @@ -0,0 +1,53 @@ +#ifndef INK_TOGGLE_ACTION_H +#define INK_TOGGLE_ACTION_H + +#include + +#include "attributes.h" +#include "icon-size.h" + +G_BEGIN_DECLS +#define INK_TOGGLE_ACTION_TYPE ( ink_toggle_action_get_type() ) +#define INK_TOGGLE_ACTION( obj ) ( G_TYPE_CHECK_INSTANCE_CAST( (obj), INK_TOGGLE_ACTION_TYPE, InkToggleAction) ) +#define INK_TOGGLE_ACTION_CLASS( klass ) ( G_TYPE_CHECK_CLASS_CAST( (klass), INK_TOGGLE_ACTION_TYPE, InkToggleActionClass) ) +#define IS_INK_TOGGLE_ACTION( obj ) ( G_TYPE_CHECK_INSTANCE_TYPE( (obj), INK_TOGGLE_ACTION_TYPE) ) +#define IS_INK_TOGGLE_ACTION_CLASS( klass ) ( G_TYPE_CHECK_CLASS_TYPE( (klass), INK_TOGGLE_ACTION_TYPE) ) +#define INK_TOGGLE_ACTION_GET_CLASS( obj ) ( G_TYPE_INSTANCE_GET_CLASS( (obj), INK_TOGGLE_ACTION_TYPE, InkToggleActionClass) ) + +typedef struct _InkToggleAction InkToggleAction; +typedef struct _InkToggleActionClass InkToggleActionClass; +typedef struct _InkToggleActionPrivate InkToggleActionPrivate; + +struct _InkToggleAction +{ + GtkToggleAction action; + InkToggleActionPrivate *private_data; +}; + +struct _InkToggleActionClass +{ + GtkToggleActionClass parent_class; +}; + +GType ink_toggle_action_get_type( void ); + +InkToggleAction* ink_toggle_action_new( const gchar *name, + const gchar *label, + const gchar *tooltip, + const gchar *inkId, + Inkscape::IconSize size, + SPAttributeEnum attr = SP_ATTR_INVALID); + +G_END_DECLS + +#endif // INK_TOGGLE_ACTION_H +/* + 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/widgets/ink-tool-menu-action.cpp b/src/widgets/ink-tool-menu-action.cpp new file mode 100644 index 000000000..29d8dc92f --- /dev/null +++ b/src/widgets/ink-tool-menu-action.cpp @@ -0,0 +1,49 @@ +#include "ink-tool-menu-action.h" + +// ToolMenu Action is happily derived from http://www.gtkforums.com/viewtopic.php?t=4215 + +G_DEFINE_TYPE(InkToolMenuAction, ink_tool_menu_action, INK_ACTION_TYPE); + +static void +ink_tool_menu_action_class_init (InkToolMenuActionClass *klass) +{ + GtkActionClass *action_class = GTK_ACTION_CLASS (klass); + action_class->toolbar_item_type = GTK_TYPE_MENU_TOOL_BUTTON; +} + +static void +ink_tool_menu_action_init (InkToolMenuAction* /*tma*/) +{ +} + +InkToolMenuAction * +ink_tool_menu_action_new (const gchar *name, + const gchar *label, + const gchar *tooltip, + const gchar *inkId, + Inkscape::IconSize size ) +{ + g_return_val_if_fail (name != NULL, NULL); + + GObject* obj = (GObject*)g_object_new( INK_TOOL_MENU_ACTION_TYPE, + "name", name, + "label", label, + "tooltip", tooltip, + "iconId", inkId, + "iconSize", size, + NULL ); + + InkToolMenuAction* action = INK_TOOL_MENU_ACTION( obj ); + + return action; +} +/* + 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/widgets/ink-tool-menu-action.h b/src/widgets/ink-tool-menu-action.h new file mode 100644 index 000000000..be04489d3 --- /dev/null +++ b/src/widgets/ink-tool-menu-action.h @@ -0,0 +1,52 @@ +#ifndef INK_TOOL_MENU_ACTION_H +#define INK_TOOL_MENU_ACTION_H + +#include "ink-action.h" + +// ToolMenu Action is happily derived from http://www.gtkforums.com/viewtopic.php?t=4215 + +G_BEGIN_DECLS + +#define INK_TOOL_MENU_ACTION_TYPE ( ink_tool_menu_action_get_type() ) +#define INK_TOOL_MENU_ACTION( obj ) ( G_TYPE_CHECK_INSTANCE_CAST( (obj), INK_TOOL_MENU_ACTION_TYPE, InkToolMenuAction) ) +#define INK_TOOL_MENU_ACTION_CLASS( klass ) ( G_TYPE_CHECK_CLASS_CAST( (klass), INK_TOOL_MENU_ACTION_TYPE, InkToolMenuActionClass) ) +#define IS_INK_TOOL_MENU_ACTION( obj ) ( G_TYPE_CHECK_INSTANCE_TYPE( (obj), INK_TOOL_MENU_ACTION_TYPE) ) +#define IS_INK_TOOL_MENU_ACTION_CLASS( klass ) ( G_TYPE_CHECK_CLASS_TYPE( (klass), INK_TOOL_MENU_ACTION_TYPE) ) +#define INK_TOOL_MENU_ACTION_GET_CLASS( obj ) ( G_TYPE_INSTANCE_GET_CLASS( (obj), INK_TOOL_MENU_ACTION_TYPE, InkToolMenuActionClass) ) + +typedef struct _InkToolMenuAction InkToolMenuAction; +typedef struct _InkToolMenuActionClass InkToolMenuActionClass; +typedef struct _InkToolMenuActionPrivate InkToolMenuActionPrivate; + +struct _InkToolMenuAction +{ + InkAction action; +}; + +struct _InkToolMenuActionClass +{ + InkActionClass parent_class; +}; + +GType ink_tool_menu_action_get_type( void ); + +InkToolMenuAction* ink_tool_menu_action_new( const gchar *name, + const gchar *label, + const gchar *tooltip, + const gchar *inkId, + Inkscape::IconSize size ); + +G_END_DECLS + +#endif // INK_TOOL_MENU_ACTION_H + +/* + 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/widgets/lpe-toolbar.cpp b/src/widgets/lpe-toolbar.cpp index d44983a15..5df5fde70 100644 --- a/src/widgets/lpe-toolbar.cpp +++ b/src/widgets/lpe-toolbar.cpp @@ -34,7 +34,8 @@ #include "widgets/ege-select-one-action.h" #include "helper/action-context.h" #include "helper/action.h" -#include "widgets/ink-action.h" +#include "ink-radio-action.h" +#include "ink-toggle-action.h" #include "ui/tools-switch.h" #include "ui/tools/lpe-tool.h" #include "ui/widget/unit-tracker.h" diff --git a/src/widgets/measure-toolbar.cpp b/src/widgets/measure-toolbar.cpp index 53790cfac..a8c974bbc 100644 --- a/src/widgets/measure-toolbar.cpp +++ b/src/widgets/measure-toolbar.cpp @@ -39,7 +39,8 @@ #include "widgets/ege-adjustment-action.h" #include "widgets/ege-output-action.h" #include "toolbox.h" -#include "widgets/ink-action.h" +#include "ink-action.h" +#include "ink-toggle-action.h" #include "ui/icon-names.h" #include "ui/tools/measure-tool.h" #include "ui/widget/unit-tracker.h" diff --git a/src/widgets/mesh-toolbar.cpp b/src/widgets/mesh-toolbar.cpp index 1e5c12d41..3bc6cb288 100644 --- a/src/widgets/mesh-toolbar.cpp +++ b/src/widgets/mesh-toolbar.cpp @@ -47,7 +47,9 @@ #include "widgets/ege-adjustment-action.h" #include "widgets/ege-select-one-action.h" -#include "widgets/ink-action.h" +#include "ink-action.h" +#include "ink-radio-action.h" +#include "ink-toggle-action.h" #include "sp-stop.h" #include "svg/css-ostringstream.h" diff --git a/src/widgets/node-toolbar.cpp b/src/widgets/node-toolbar.cpp index ed3e33acc..31efaa0b4 100644 --- a/src/widgets/node-toolbar.cpp +++ b/src/widgets/node-toolbar.cpp @@ -35,7 +35,8 @@ #include "desktop.h" #include "document-undo.h" #include "widgets/ege-adjustment-action.h" -#include "widgets/ink-action.h" +#include "ink-toggle-action.h" +#include "ink-tool-menu-action.h" #include "inkscape.h" #include "selection-chemistry.h" #include "sp-namedview.h" diff --git a/src/widgets/pencil-toolbar.cpp b/src/widgets/pencil-toolbar.cpp index d402cc714..32cdb0a7d 100644 --- a/src/widgets/pencil-toolbar.cpp +++ b/src/widgets/pencil-toolbar.cpp @@ -35,7 +35,9 @@ #include "desktop.h" #include "widgets/ege-adjustment-action.h" #include "widgets/ege-select-one-action.h" -#include "widgets/ink-action.h" +#include "ink-action.h" +#include "ink-radio-action.h" +#include "ink-toggle-action.h" #include "toolbox.h" #include "ui/tools-switch.h" #include "ui/icon-names.h" diff --git a/src/widgets/select-toolbar.cpp b/src/widgets/select-toolbar.cpp index fde5a95cd..81fb2371b 100644 --- a/src/widgets/select-toolbar.cpp +++ b/src/widgets/select-toolbar.cpp @@ -29,7 +29,8 @@ #include "widgets/ege-adjustment-action.h" #include "helper/action-context.h" #include "helper/action.h" -#include "widgets/ink-action.h" +#include "ink-action.h" +#include "ink-toggle-action.h" #include "inkscape.h" #include "message-stack.h" #include "selection-chemistry.h" diff --git a/src/widgets/spray-toolbar.cpp b/src/widgets/spray-toolbar.cpp index 43d00c53e..a724637e3 100644 --- a/src/widgets/spray-toolbar.cpp +++ b/src/widgets/spray-toolbar.cpp @@ -36,7 +36,8 @@ #include "inkscape.h" #include "widgets/ege-adjustment-action.h" #include "widgets/ege-select-one-action.h" -#include "widgets/ink-action.h" +#include "ink-radio-action.h" +#include "ink-toggle-action.h" #include "toolbox.h" #include "ui/dialog/clonetiler.h" #include "ui/dialog/dialog-manager.h" diff --git a/src/widgets/star-toolbar.cpp b/src/widgets/star-toolbar.cpp index 7f4293b62..e06733740 100644 --- a/src/widgets/star-toolbar.cpp +++ b/src/widgets/star-toolbar.cpp @@ -37,7 +37,8 @@ #include "widgets/ege-adjustment-action.h" #include "widgets/ege-output-action.h" #include "widgets/ege-select-one-action.h" -#include "widgets/ink-action.h" +#include "ink-action.h" +#include "ink-radio-action.h" #include "selection.h" #include "sp-star.h" #include "toolbox.h" diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index 41199ecfe..4ab631765 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -38,7 +38,8 @@ #include "document.h" #include "widgets/ege-adjustment-action.h" #include "widgets/ege-select-one-action.h" -#include "widgets/ink-action.h" +#include "ink-radio-action.h" +#include "ink-toggle-action.h" #include "widgets/ink-comboboxentry-action.h" #include "inkscape.h" #include "selection-chemistry.h" diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 20c3936a3..f74be4b15 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -43,6 +43,7 @@ #include "../helper/action.h" #include "icon.h" #include "ink-action.h" +#include "ink-toggle-action.h" #include "../inkscape.h" #include "ui/interface.h" #include "../shortcuts.h" diff --git a/src/widgets/tweak-toolbar.cpp b/src/widgets/tweak-toolbar.cpp index 9a021082c..a6b8ba436 100644 --- a/src/widgets/tweak-toolbar.cpp +++ b/src/widgets/tweak-toolbar.cpp @@ -36,7 +36,8 @@ #include "widgets/ege-adjustment-action.h" #include "widgets/ege-output-action.h" #include "widgets/ege-select-one-action.h" -#include "widgets/ink-action.h" +#include "ink-radio-action.h" +#include "ink-toggle-action.h" #include "toolbox.h" #include "ui/icon-names.h" #include "ui/tools/tweak-tool.h" -- cgit v1.2.3 From 56fa2433ef69a260f68b8c3147ad3769ee5c8fdb Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Mon, 8 Aug 2016 11:01:15 +0100 Subject: Move GIMP widgets to their own folder (bzr r15043.1.2) --- src/widgets/CMakeLists.txt | 75 +- src/widgets/desktop-widget.cpp | 2 +- src/widgets/ege-adjustment-action.cpp | 2 +- src/widgets/gimp/CMakeLists.txt | 13 + src/widgets/gimp/gimpcolorwheel.c | 1467 +++++++++++++++++++++++++++++++++ src/widgets/gimp/gimpcolorwheel.h | 95 +++ src/widgets/gimp/gimpspinscale.c | 969 ++++++++++++++++++++++ src/widgets/gimp/gimpspinscale.h | 82 ++ src/widgets/gimp/ruler.cpp | 1425 ++++++++++++++++++++++++++++++++ src/widgets/gimp/ruler.h | 86 ++ src/widgets/ruler.cpp | 1425 -------------------------------- src/widgets/ruler.h | 86 -- 12 files changed, 4176 insertions(+), 1551 deletions(-) create mode 100644 src/widgets/gimp/CMakeLists.txt create mode 100644 src/widgets/gimp/gimpcolorwheel.c create mode 100644 src/widgets/gimp/gimpcolorwheel.h create mode 100644 src/widgets/gimp/gimpspinscale.c create mode 100644 src/widgets/gimp/gimpspinscale.h create mode 100644 src/widgets/gimp/ruler.cpp create mode 100644 src/widgets/gimp/ruler.h delete mode 100644 src/widgets/ruler.cpp delete mode 100644 src/widgets/ruler.h (limited to 'src/widgets') diff --git a/src/widgets/CMakeLists.txt b/src/widgets/CMakeLists.txt index 47ffe82ac..b2071af4e 100644 --- a/src/widgets/CMakeLists.txt +++ b/src/widgets/CMakeLists.txt @@ -1,24 +1,25 @@ +add_subdirectory(gimp) set(widgets_SRC button.cpp - arc-toolbar.cpp - box3d-toolbar.cpp - calligraphy-toolbar.cpp - connector-toolbar.cpp - dropper-toolbar.cpp - eraser-toolbar.cpp - lpe-toolbar.cpp - measure-toolbar.cpp - mesh-toolbar.cpp - node-toolbar.cpp - pencil-toolbar.cpp - rect-toolbar.cpp - spiral-toolbar.cpp - spray-toolbar.cpp - star-toolbar.cpp - text-toolbar.cpp - tweak-toolbar.cpp - zoom-toolbar.cpp + arc-toolbar.cpp + box3d-toolbar.cpp + calligraphy-toolbar.cpp + connector-toolbar.cpp + dropper-toolbar.cpp + eraser-toolbar.cpp + lpe-toolbar.cpp + measure-toolbar.cpp + mesh-toolbar.cpp + node-toolbar.cpp + pencil-toolbar.cpp + rect-toolbar.cpp + spiral-toolbar.cpp + spray-toolbar.cpp + star-toolbar.cpp + text-toolbar.cpp + tweak-toolbar.cpp + zoom-toolbar.cpp dash-selector.cpp desktop-widget.cpp eek-preview.cpp @@ -40,7 +41,6 @@ set(widgets_SRC ink-toggle-action.cpp ink-tool-menu-action.cpp paint-selector.cpp - ruler.cpp select-toolbar.cpp sp-attribute-widget.cpp sp-color-selector.cpp @@ -59,24 +59,24 @@ set(widgets_SRC # ------- # Headers button.h - arc-toolbar.h - box3d-toolbar.h - calligraphy-toolbar.h - connector-toolbar.h - dropper-toolbar.h - eraser-toolbar.h - lpe-toolbar.h - measure-toolbar.h - mesh-toolbar.h - node-toolbar.h - pencil-toolbar.h - rect-toolbar.h - spiral-toolbar.h - spray-toolbar.h - star-toolbar.h - text-toolbar.h - tweak-toolbar.h - zoom-toolbar.h + arc-toolbar.h + box3d-toolbar.h + calligraphy-toolbar.h + connector-toolbar.h + dropper-toolbar.h + eraser-toolbar.h + lpe-toolbar.h + measure-toolbar.h + mesh-toolbar.h + node-toolbar.h + pencil-toolbar.h + rect-toolbar.h + spiral-toolbar.h + spray-toolbar.h + star-toolbar.h + text-toolbar.h + tweak-toolbar.h + zoom-toolbar.h dash-selector.h desktop-widget.h eek-preview.h @@ -99,7 +99,6 @@ set(widgets_SRC ink-toggle-action.h ink-tool-menu-action.h paint-selector.h - ruler.h select-toolbar.h sp-attribute-widget.h sp-color-selector.h diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp index aa485498e..bd72560c6 100644 --- a/src/widgets/desktop-widget.cpp +++ b/src/widgets/desktop-widget.cpp @@ -57,7 +57,7 @@ // We're in the "widgets" directory, so no need to explicitly prefix these: #include "button.h" -#include "ruler.h" +#include "gimp/ruler.h" #include "spinbutton-events.h" #include "spw-utilities.h" #include "toolbox.h" diff --git a/src/widgets/ege-adjustment-action.cpp b/src/widgets/ege-adjustment-action.cpp index 8fef21741..6678d1e5a 100644 --- a/src/widgets/ege-adjustment-action.cpp +++ b/src/widgets/ege-adjustment-action.cpp @@ -47,7 +47,7 @@ #include "icon-size.h" #include "widgets/ege-adjustment-action.h" -#include "ui/widget/gimpspinscale.h" +#include "gimp/gimpspinscale.h" #include "ui/icon-names.h" diff --git a/src/widgets/gimp/CMakeLists.txt b/src/widgets/gimp/CMakeLists.txt new file mode 100644 index 000000000..7b3e834e3 --- /dev/null +++ b/src/widgets/gimp/CMakeLists.txt @@ -0,0 +1,13 @@ +set(gimpwidgets_SRC + gimpcolorwheel.c + gimpspinscale.c + ruler.cpp + + # ------- + # Headers + gimpcolorwheel.h + gimpspinscale.h + ruler.h +) + +add_inkscape_source("${gimpwidgets_SRC}") diff --git a/src/widgets/gimp/gimpcolorwheel.c b/src/widgets/gimp/gimpcolorwheel.c new file mode 100644 index 000000000..212391497 --- /dev/null +++ b/src/widgets/gimp/gimpcolorwheel.c @@ -0,0 +1,1467 @@ +/* HSV color selector for GTK+ + * + * Copyright (C) 1999 The Free Software Foundation + * + * Authors: Simon Budig (original code) + * Federico Mena-Quintero (cleanup for GTK+) + * Jonathan Blandford (cleanup for GTK+) + * Michael Natterer (ported back to GIMP) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/* + * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS + * file for a list of people on the GTK+ Team. See the ChangeLog + * files for a list of changes. These files are distributed with + * GTK+ at ftp://ftp.gtk.org/pub/gtk/. + */ + +/* + * This widget was adopted by Inkscape by Alex Valavanis + * on 2013-01-08. Last merges with GIMP code were applied using the following + * commits from the GIMP git repository at + * http://git.gnome.org/browse/gimp/tree/modules/gimpcolorwheel.c + * + * Gtk+ 2 code merge: commit 632c5 (2013-01-06) + * Gtk+ 3 code merge: commit bcfc6, gtk3-port branch (2013-01-06) + */ + +#include "config.h" + +#include +#include + +#include "gimpcolorwheel.h" +#include + + +/* Default ring fraction */ +#define DEFAULT_FRACTION 0.1 + +/* Default width/height */ +#define DEFAULT_SIZE 100 + +/* Default ring width */ +#define DEFAULT_RING_WIDTH 10 + + +/* Dragging modes */ +typedef enum +{ + DRAG_NONE, + DRAG_H, + DRAG_SV +} DragMode; + +/* Private part of the GimpColorWheel structure */ +typedef struct +{ + /* Color value */ + gdouble h; + gdouble s; + gdouble v; + + /* ring_width is this fraction of size */ + gdouble ring_fraction; + + /* Size and ring width */ + gint size; + gint ring_width; + + /* Window for capturing events */ + GdkWindow *window; + + /* Dragging mode */ + DragMode mode; + + guint focus_on_ring : 1; +} GimpColorWheelPrivate; + +enum +{ + CHANGED, + MOVE, + LAST_SIGNAL +}; + +static void gimp_color_wheel_map (GtkWidget *widget); +static void gimp_color_wheel_unmap (GtkWidget *widget); +static void gimp_color_wheel_realize (GtkWidget *widget); +static void gimp_color_wheel_unrealize (GtkWidget *widget); +static void gimp_color_wheel_size_allocate (GtkWidget *widget, + GtkAllocation *allocation); +static gboolean gimp_color_wheel_button_press (GtkWidget *widget, + GdkEventButton *event); +static gboolean gimp_color_wheel_button_release (GtkWidget *widget, + GdkEventButton *event); +static gboolean gimp_color_wheel_motion (GtkWidget *widget, + GdkEventMotion *event); +static gboolean gimp_color_wheel_draw (GtkWidget *widget, + cairo_t *cr); +static void gimp_color_wheel_get_preferred_width (GtkWidget *widget, + gint *minimum_width, + gint *natural_width); +static void gimp_color_wheel_get_preferred_height (GtkWidget *widget, + gint *minimum_height, + gint *natural_height); +static gboolean gimp_color_wheel_grab_broken (GtkWidget *widget, + GdkEventGrabBroken *event); +static gboolean gimp_color_wheel_focus (GtkWidget *widget, + GtkDirectionType direction); +static void gimp_color_wheel_move (GimpColorWheel *wheel, + GtkDirectionType dir); + + +static guint wheel_signals[LAST_SIGNAL]; + +G_DEFINE_TYPE (GimpColorWheel, gimp_color_wheel, GTK_TYPE_WIDGET) + +#define parent_class gimp_color_wheel_parent_class + + +static void +gimp_color_wheel_class_init (GimpColorWheelClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class); + GimpColorWheelClass *wheel_class = GIMP_COLOR_WHEEL_CLASS (class); + GtkBindingSet *binding_set; + + widget_class->map = gimp_color_wheel_map; + widget_class->unmap = gimp_color_wheel_unmap; + widget_class->realize = gimp_color_wheel_realize; + widget_class->unrealize = gimp_color_wheel_unrealize; + widget_class->size_allocate = gimp_color_wheel_size_allocate; + widget_class->button_press_event = gimp_color_wheel_button_press; + widget_class->button_release_event = gimp_color_wheel_button_release; + widget_class->motion_notify_event = gimp_color_wheel_motion; + widget_class->get_preferred_width = gimp_color_wheel_get_preferred_width; + widget_class->get_preferred_height = gimp_color_wheel_get_preferred_height; + widget_class->draw = gimp_color_wheel_draw; + widget_class->focus = gimp_color_wheel_focus; + widget_class->grab_broken_event = gimp_color_wheel_grab_broken; + + wheel_class->move = gimp_color_wheel_move; + + wheel_signals[CHANGED] = + g_signal_new ("changed", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (GimpColorWheelClass, changed), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + + wheel_signals[MOVE] = + g_signal_new ("move", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (GimpColorWheelClass, move), + NULL, NULL, + g_cclosure_marshal_VOID__ENUM, + G_TYPE_NONE, 1, + GTK_TYPE_DIRECTION_TYPE); + + binding_set = gtk_binding_set_by_class (class); + + gtk_binding_entry_add_signal (binding_set, GDK_KEY_Up, 0, + "move", 1, + G_TYPE_ENUM, GTK_DIR_UP); + gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Up, 0, + "move", 1, + G_TYPE_ENUM, GTK_DIR_UP); + + gtk_binding_entry_add_signal (binding_set, GDK_KEY_Down, 0, + "move", 1, + G_TYPE_ENUM, GTK_DIR_DOWN); + gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Down, 0, + "move", 1, + G_TYPE_ENUM, GTK_DIR_DOWN); + + + gtk_binding_entry_add_signal (binding_set, GDK_KEY_Right, 0, + "move", 1, + G_TYPE_ENUM, GTK_DIR_RIGHT); + gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Right, 0, + "move", 1, + G_TYPE_ENUM, GTK_DIR_RIGHT); + + gtk_binding_entry_add_signal (binding_set, GDK_KEY_Left, 0, + "move", 1, + G_TYPE_ENUM, GTK_DIR_LEFT); + gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Left, 0, + "move", 1, + G_TYPE_ENUM, GTK_DIR_LEFT); + + g_type_class_add_private (object_class, sizeof (GimpColorWheelPrivate)); +} + +static void +gimp_color_wheel_init (GimpColorWheel *wheel) +{ + GimpColorWheelPrivate *priv; + + priv = G_TYPE_INSTANCE_GET_PRIVATE (wheel, GIMP_TYPE_COLOR_WHEEL, + GimpColorWheelPrivate); + + wheel->priv = priv; + + gtk_widget_set_has_window (GTK_WIDGET (wheel), FALSE); + gtk_widget_set_can_focus (GTK_WIDGET (wheel), TRUE); + + priv->ring_fraction = DEFAULT_FRACTION; + priv->size = DEFAULT_SIZE; + priv->ring_width = DEFAULT_RING_WIDTH; +} + +static void +gimp_color_wheel_map (GtkWidget *widget) +{ + GimpColorWheel *wheel = GIMP_COLOR_WHEEL (widget); + GimpColorWheelPrivate *priv = wheel->priv; + + GTK_WIDGET_CLASS (parent_class)->map (widget); + + gdk_window_show (priv->window); +} + +static void +gimp_color_wheel_unmap (GtkWidget *widget) +{ + GimpColorWheel *wheel = GIMP_COLOR_WHEEL (widget); + GimpColorWheelPrivate *priv = wheel->priv; + + gdk_window_hide (priv->window); + + GTK_WIDGET_CLASS (parent_class)->unmap (widget); +} + +static void +gimp_color_wheel_realize (GtkWidget *widget) +{ + GimpColorWheel *wheel = GIMP_COLOR_WHEEL (widget); + GimpColorWheelPrivate *priv = wheel->priv; + GtkAllocation allocation; + GdkWindowAttr attr; + gint attr_mask; + GdkWindow *parent_window; + + gtk_widget_get_allocation (widget, &allocation); + + gtk_widget_set_realized (widget, TRUE); + + attr.window_type = GDK_WINDOW_CHILD; + attr.x = allocation.x; + attr.y = allocation.y; + attr.width = allocation.width; + attr.height = allocation.height; + attr.wclass = GDK_INPUT_ONLY; + attr.event_mask = (gtk_widget_get_events (widget) | + GDK_KEY_PRESS_MASK | + GDK_BUTTON_PRESS_MASK | + GDK_BUTTON_RELEASE_MASK | + GDK_POINTER_MOTION_MASK | + GDK_ENTER_NOTIFY_MASK | + GDK_LEAVE_NOTIFY_MASK); + + attr_mask = GDK_WA_X | GDK_WA_Y; + + parent_window = gtk_widget_get_parent_window (widget); + + gtk_widget_set_window (widget, parent_window); + g_object_ref (parent_window); + + priv->window = gdk_window_new (parent_window, &attr, attr_mask); + gdk_window_set_user_data (priv->window, wheel); +} + +static void +gimp_color_wheel_unrealize (GtkWidget *widget) +{ + GimpColorWheel *wheel = GIMP_COLOR_WHEEL (widget); + GimpColorWheelPrivate *priv = wheel->priv; + + gdk_window_set_user_data (priv->window, NULL); + gdk_window_destroy (priv->window); + priv->window = NULL; + + GTK_WIDGET_CLASS (parent_class)->unrealize (widget); +} + +static void +gimp_color_wheel_get_preferred_width (GtkWidget *widget, + gint *minimum_width, + gint *natural_width) +{ + gint focus_width; + gint focus_pad; + + gtk_widget_style_get (widget, + "focus-line-width", &focus_width, + "focus-padding", &focus_pad, + NULL); + + *minimum_width = *natural_width = DEFAULT_SIZE + 2 * (focus_width + focus_pad); +} + +static void +gimp_color_wheel_get_preferred_height (GtkWidget *widget, + gint *minimum_height, + gint *natural_height) +{ + gint focus_width; + gint focus_pad; + + gtk_widget_style_get (widget, + "focus-line-width", &focus_width, + "focus-padding", &focus_pad, + NULL); + + *minimum_height = *natural_height = DEFAULT_SIZE + 2 * (focus_width + focus_pad); +} + +static void +gimp_color_wheel_size_allocate (GtkWidget *widget, + GtkAllocation *allocation) +{ + GimpColorWheel *wheel = GIMP_COLOR_WHEEL (widget); + GimpColorWheelPrivate *priv = wheel->priv; + gint focus_width; + gint focus_pad; + + gtk_widget_set_allocation (widget, allocation); + + gtk_widget_style_get (widget, + "focus-line-width", &focus_width, + "focus-padding", &focus_pad, + NULL); + + priv->size = MIN (allocation->width - 2 * (focus_width + focus_pad), + allocation->height - 2 * (focus_width + focus_pad)); + + priv->ring_width = priv->size * priv->ring_fraction; + + if (gtk_widget_get_realized (widget)) + gdk_window_move_resize (priv->window, + allocation->x, + allocation->y, + allocation->width, + allocation->height); +} + + +/* Utility functions */ + +#define INTENSITY(r, g, b) ((r) * 0.30 + (g) * 0.59 + (b) * 0.11) + +/* Converts from HSV to RGB */ +static void +hsv_to_rgb (gdouble *h, + gdouble *s, + gdouble *v) +{ + gdouble hue, saturation, value; + gdouble f, p, q, t; + + if (*s == 0.0) + { + *h = *v; + *s = *v; + *v = *v; /* heh */ + } + else + { + hue = *h * 6.0; + saturation = *s; + value = *v; + + if (hue == 6.0) + hue = 0.0; + + f = hue - (int) hue; + p = value * (1.0 - saturation); + q = value * (1.0 - saturation * f); + t = value * (1.0 - saturation * (1.0 - f)); + + switch ((int) hue) + { + case 0: + *h = value; + *s = t; + *v = p; + break; + + case 1: + *h = q; + *s = value; + *v = p; + break; + + case 2: + *h = p; + *s = value; + *v = t; + break; + + case 3: + *h = p; + *s = q; + *v = value; + break; + + case 4: + *h = t; + *s = p; + *v = value; + break; + + case 5: + *h = value; + *s = p; + *v = q; + break; + + default: + g_assert_not_reached (); + } + } +} + +/* Computes the vertices of the saturation/value triangle */ +static void +compute_triangle (GimpColorWheel *wheel, + gint *hx, + gint *hy, + gint *sx, + gint *sy, + gint *vx, + gint *vy) +{ + GimpColorWheelPrivate *priv = wheel->priv; + GtkAllocation allocation; + gdouble center_x; + gdouble center_y; + gdouble inner, outer; + gdouble angle; + + gtk_widget_get_allocation (GTK_WIDGET (wheel), &allocation); + + center_x = allocation.width / 2.0; + center_y = allocation.height / 2.0; + + outer = priv->size / 2.0; + inner = outer - priv->ring_width; + angle = priv->h * 2.0 * G_PI; + + *hx = floor (center_x + cos (angle) * inner + 0.5); + *hy = floor (center_y - sin (angle) * inner + 0.5); + *sx = floor (center_x + cos (angle + 2.0 * G_PI / 3.0) * inner + 0.5); + *sy = floor (center_y - sin (angle + 2.0 * G_PI / 3.0) * inner + 0.5); + *vx = floor (center_x + cos (angle + 4.0 * G_PI / 3.0) * inner + 0.5); + *vy = floor (center_y - sin (angle + 4.0 * G_PI / 3.0) * inner + 0.5); +} + +/* Computes whether a point is inside the hue ring */ +static gboolean +is_in_ring (GimpColorWheel *wheel, + gdouble x, + gdouble y) +{ + GimpColorWheelPrivate *priv = wheel->priv; + GtkAllocation allocation; + gdouble dx, dy, dist; + gdouble center_x; + gdouble center_y; + gdouble inner, outer; + + gtk_widget_get_allocation (GTK_WIDGET (wheel), &allocation); + + center_x = allocation.width / 2.0; + center_y = allocation.height / 2.0; + + outer = priv->size / 2.0; + inner = outer - priv->ring_width; + + dx = x - center_x; + dy = center_y - y; + dist = dx * dx + dy * dy; + + return (dist >= inner * inner && dist <= outer * outer); +} + +/* Computes a saturation/value pair based on the mouse coordinates */ +static void +compute_sv (GimpColorWheel *wheel, + gdouble x, + gdouble y, + gdouble *s, + gdouble *v) +{ + GtkAllocation allocation; + gint ihx, ihy, isx, isy, ivx, ivy; + gdouble hx, hy, sx, sy, vx, vy; + gdouble center_x; + gdouble center_y; + + gtk_widget_get_allocation (GTK_WIDGET (wheel), &allocation); + + compute_triangle (wheel, &ihx, &ihy, &isx, &isy, &ivx, &ivy); + + center_x = allocation.width / 2.0; + center_y = allocation.height / 2.0; + + hx = ihx - center_x; + hy = center_y - ihy; + sx = isx - center_x; + sy = center_y - isy; + vx = ivx - center_x; + vy = center_y - ivy; + x -= center_x; + y = center_y - y; + + if (vx * (x - sx) + vy * (y - sy) < 0.0) + { + *s = 1.0; + *v = (((x - sx) * (hx - sx) + (y - sy) * (hy-sy)) + / ((hx - sx) * (hx - sx) + (hy - sy) * (hy - sy))); + + if (*v < 0.0) + *v = 0.0; + else if (*v > 1.0) + *v = 1.0; + } + else if (hx * (x - sx) + hy * (y - sy) < 0.0) + { + *s = 0.0; + *v = (((x - sx) * (vx - sx) + (y - sy) * (vy - sy)) + / ((vx - sx) * (vx - sx) + (vy - sy) * (vy - sy))); + + if (*v < 0.0) + *v = 0.0; + else if (*v > 1.0) + *v = 1.0; + } + else if (sx * (x - hx) + sy * (y - hy) < 0.0) + { + *v = 1.0; + *s = (((x - vx) * (hx - vx) + (y - vy) * (hy - vy)) / + ((hx - vx) * (hx - vx) + (hy - vy) * (hy - vy))); + + if (*s < 0.0) + *s = 0.0; + else if (*s > 1.0) + *s = 1.0; + } + else + { + *v = (((x - sx) * (hy - vy) - (y - sy) * (hx - vx)) + / ((vx - sx) * (hy - vy) - (vy - sy) * (hx - vx))); + + if (*v<= 0.0) + { + *v = 0.0; + *s = 0.0; + } + else + { + if (*v > 1.0) + *v = 1.0; + + if (fabs (hy - vy) < fabs (hx - vx)) + *s = (x - sx - *v * (vx - sx)) / (*v * (hx - vx)); + else + *s = (y - sy - *v * (vy - sy)) / (*v * (hy - vy)); + + if (*s < 0.0) + *s = 0.0; + else if (*s > 1.0) + *s = 1.0; + } + } +} + +/* Computes whether a point is inside the saturation/value triangle */ +static gboolean +is_in_triangle (GimpColorWheel *wheel, + gdouble x, + gdouble y) +{ + gint hx, hy, sx, sy, vx, vy; + gdouble det, s, v; + + compute_triangle (wheel, &hx, &hy, &sx, &sy, &vx, &vy); + + det = (vx - sx) * (hy - sy) - (vy - sy) * (hx - sx); + + s = ((x - sx) * (hy - sy) - (y - sy) * (hx - sx)) / det; + v = ((vx - sx) * (y - sy) - (vy - sy) * (x - sx)) / det; + + return (s >= 0.0 && v >= 0.0 && s + v <= 1.0); +} + +/* Computes a value based on the mouse coordinates */ +static double +compute_v (GimpColorWheel *wheel, + gdouble x, + gdouble y) +{ + GtkAllocation allocation; + gdouble center_x; + gdouble center_y; + gdouble dx, dy; + gdouble angle; + + gtk_widget_get_allocation (GTK_WIDGET (wheel), &allocation); + + center_x = allocation.width / 2.0; + center_y = allocation.height / 2.0; + + dx = x - center_x; + dy = center_y - y; + + angle = atan2 (dy, dx); + if (angle < 0.0) + angle += 2.0 * G_PI; + + return angle / (2.0 * G_PI); +} + +static void +set_cross_grab (GimpColorWheel *wheel, + guint32 time) +{ + GimpColorWheelPrivate *priv = wheel->priv; + GdkCursor *cursor; + + cursor = + gdk_cursor_new_for_display (gtk_widget_get_display (GTK_WIDGET (wheel)), + GDK_CROSSHAIR); + + gdk_device_grab (gtk_get_current_event_device(), + priv->window, + GDK_OWNERSHIP_NONE, + FALSE, + GDK_POINTER_MOTION_MASK | + GDK_POINTER_MOTION_HINT_MASK | + GDK_BUTTON_RELEASE_MASK, + cursor, time); + g_object_unref (cursor); +} + +static gboolean gimp_color_wheel_grab_broken(GtkWidget *widget, GdkEventGrabBroken *event) +{ + (void)event; + GimpColorWheel *wheel = GIMP_COLOR_WHEEL (widget); + GimpColorWheelPrivate *priv = wheel->priv; + + priv->mode = DRAG_NONE; + + return TRUE; +} + +static gboolean +gimp_color_wheel_button_press (GtkWidget *widget, + GdkEventButton *event) +{ + GimpColorWheel *wheel = GIMP_COLOR_WHEEL (widget); + GimpColorWheelPrivate *priv = wheel->priv; + gdouble x, y; + + if (priv->mode != DRAG_NONE || event->button != 1) + return FALSE; + + x = event->x; + y = event->y; + + if (is_in_ring (wheel, x, y)) + { + priv->mode = DRAG_H; + set_cross_grab (wheel, event->time); + + gimp_color_wheel_set_color (wheel, + compute_v (wheel, x, y), + priv->s, + priv->v); + + gtk_widget_grab_focus (widget); + priv->focus_on_ring = TRUE; + + return TRUE; + } + + if (is_in_triangle (wheel, x, y)) + { + gdouble s, v; + + priv->mode = DRAG_SV; + set_cross_grab (wheel, event->time); + + compute_sv (wheel, x, y, &s, &v); + gimp_color_wheel_set_color (wheel, priv->h, s, v); + + gtk_widget_grab_focus (widget); + priv->focus_on_ring = FALSE; + + return TRUE; + } + + return FALSE; +} + +static gboolean +gimp_color_wheel_button_release (GtkWidget *widget, + GdkEventButton *event) +{ + GimpColorWheel *wheel = GIMP_COLOR_WHEEL (widget); + GimpColorWheelPrivate *priv = wheel->priv; + DragMode mode; + gdouble x, y; + + if (priv->mode == DRAG_NONE || event->button != 1) + return FALSE; + + /* Set the drag mode to DRAG_NONE so that signal handlers for "catched" + * can see that this is the final color state. + */ + + mode = priv->mode; + priv->mode = DRAG_NONE; + + x = event->x; + y = event->y; + + if (mode == DRAG_H) + { + gimp_color_wheel_set_color (wheel, + compute_v (wheel, x, y), priv->s, priv->v); + } + else if (mode == DRAG_SV) + { + gdouble s, v; + + compute_sv (wheel, x, y, &s, &v); + gimp_color_wheel_set_color (wheel, priv->h, s, v); + } + else + g_assert_not_reached (); + + gdk_device_ungrab (gtk_get_current_event_device(), + event->time); + + return TRUE; +} + +static gboolean +gimp_color_wheel_motion (GtkWidget *widget, + GdkEventMotion *event) +{ + GimpColorWheel *wheel = GIMP_COLOR_WHEEL (widget); + GimpColorWheelPrivate *priv = wheel->priv; + gdouble x, y; + + if (priv->mode == DRAG_NONE) + return FALSE; + + gdk_event_request_motions (event); + x = event->x; + y = event->y; + + if (priv->mode == DRAG_H) + { + gimp_color_wheel_set_color (wheel, + compute_v (wheel, x, y), priv->s, priv->v); + return TRUE; + } + else if (priv->mode == DRAG_SV) + { + gdouble s, v; + + compute_sv (wheel, x, y, &s, &v); + gimp_color_wheel_set_color (wheel, priv->h, s, v); + return TRUE; + } + + g_assert_not_reached (); + + return FALSE; +} + + +/* Redrawing */ + +/* Paints the hue ring */ +static void +paint_ring (GimpColorWheel *wheel, + cairo_t *cr) +{ + GtkWidget *widget = GTK_WIDGET (wheel); + GimpColorWheelPrivate *priv = wheel->priv; + gint width, height; + gint xx, yy; + gdouble dx, dy, dist; + gdouble center_x; + gdouble center_y; + gdouble inner, outer; + guint32 *buf, *p; + gdouble angle; + gdouble hue; + gdouble r, g, b; + cairo_surface_t *source; + cairo_t *source_cr; + gint stride; + + width = gtk_widget_get_allocated_width (widget); + height = gtk_widget_get_allocated_height (widget); + + center_x = width / 2.0; + center_y = height / 2.0; + + outer = priv->size / 2.0; + inner = outer - priv->ring_width; + + /* Create an image initialized with the ring colors */ + + stride = cairo_format_stride_for_width (CAIRO_FORMAT_RGB24, width); + buf = g_new (guint32, height * stride / 4); + + for (yy = 0; yy < height; yy++) + { + p = buf + yy * width; + dy = -(yy - center_y); + + for (xx = 0; xx < width; xx++) + { + dx = xx - center_x; + + dist = dx * dx + dy * dy; + if (dist < ((inner-1) * (inner-1)) || dist > ((outer+1) * (outer+1))) + { + *p++ = 0; + continue; + } + + angle = atan2 (dy, dx); + if (angle < 0.0) + angle += 2.0 * G_PI; + + hue = angle / (2.0 * G_PI); + + r = hue; + g = 1.0; + b = 1.0; + hsv_to_rgb (&r, &g, &b); + + *p++ = (((int)floor (r * 255 + 0.5) << 16) | + ((int)floor (g * 255 + 0.5) << 8) | + (int)floor (b * 255 + 0.5)); + } + } + + source = cairo_image_surface_create_for_data ((unsigned char *)buf, + CAIRO_FORMAT_RGB24, + width, height, stride); + + /* Now draw the value marker onto the source image, so that it + * will get properly clipped at the edges of the ring + */ + source_cr = cairo_create (source); + + r = priv->h; + g = 1.0; + b = 1.0; + hsv_to_rgb (&r, &g, &b); + + if (INTENSITY (r, g, b) > 0.5) + cairo_set_source_rgb (source_cr, 0.0, 0.0, 0.0); + else + cairo_set_source_rgb (source_cr, 1.0, 1.0, 1.0); + + cairo_move_to (source_cr, center_x, center_y); + cairo_line_to (source_cr, + center_x + cos (priv->h * 2.0 * G_PI) * priv->size / 2, + center_y - sin (priv->h * 2.0 * G_PI) * priv->size / 2); + cairo_stroke (source_cr); + cairo_destroy (source_cr); + + /* Draw the ring using the source image */ + + cairo_save (cr); + + cairo_set_source_surface (cr, source, 0, 0); + cairo_surface_destroy (source); + + cairo_set_line_width (cr, priv->ring_width); + cairo_new_path (cr); + cairo_arc (cr, + center_x, center_y, + priv->size / 2.0 - priv->ring_width / 2.0, + 0, 2 * G_PI); + cairo_stroke (cr); + + cairo_restore (cr); + + g_free (buf); +} + +/* Converts an HSV triplet to an integer RGB triplet */ +static void +get_color (gdouble h, + gdouble s, + gdouble v, + gint *r, + gint *g, + gint *b) +{ + hsv_to_rgb (&h, &s, &v); + + *r = floor (h * 255 + 0.5); + *g = floor (s * 255 + 0.5); + *b = floor (v * 255 + 0.5); +} + +#define SWAP(a, b, t) ((t) = (a), (a) = (b), (b) = (t)) + +#define LERP(a, b, v1, v2, i) (((v2) - (v1) != 0) \ + ? ((a) + ((b) - (a)) * ((i) - (v1)) / ((v2) - (v1))) \ + : (a)) + +/* Number of pixels we extend out from the edges when creating + * color source to avoid artifacts + */ +#define PAD 3 + +/* Paints the HSV triangle */ +static void +paint_triangle (GimpColorWheel *wheel, + cairo_t *cr, + gboolean draw_focus) +{ + GtkWidget *widget = GTK_WIDGET (wheel); + GimpColorWheelPrivate *priv = wheel->priv; + gint hx, hy, sx, sy, vx, vy; /* HSV vertices */ + gint x1, y1, r1, g1, b1; /* First vertex in scanline order */ + gint x2, y2, r2, g2, b2; /* Second vertex */ + gint x3, y3, r3, g3, b3; /* Third vertex */ + gint t; + guint32 *buf, *p, c; + gint xl, xr, rl, rr, gl, gr, bl, br; /* Scanline data */ + gint xx, yy; + gint x_interp, y_interp; + gint x_start, x_end; + cairo_surface_t *source; + gdouble r, g, b; + gint stride; + gint width, height; + GtkStyleContext *context; + + width = gtk_widget_get_allocated_width (widget); + height = gtk_widget_get_allocated_height (widget); + + /* Compute triangle's vertices */ + + compute_triangle (wheel, &hx, &hy, &sx, &sy, &vx, &vy); + + x1 = hx; + y1 = hy; + get_color (priv->h, 1.0, 1.0, &r1, &g1, &b1); + + x2 = sx; + y2 = sy; + get_color (priv->h, 1.0, 0.0, &r2, &g2, &b2); + + x3 = vx; + y3 = vy; + get_color (priv->h, 0.0, 1.0, &r3, &g3, &b3); + + if (y2 > y3) + { + SWAP (x2, x3, t); + SWAP (y2, y3, t); + SWAP (r2, r3, t); + SWAP (g2, g3, t); + SWAP (b2, b3, t); + } + + if (y1 > y3) + { + SWAP (x1, x3, t); + SWAP (y1, y3, t); + SWAP (r1, r3, t); + SWAP (g1, g3, t); + SWAP (b1, b3, t); + } + + if (y1 > y2) + { + SWAP (x1, x2, t); + SWAP (y1, y2, t); + SWAP (r1, r2, t); + SWAP (g1, g2, t); + SWAP (b1, b2, t); + } + + /* Shade the triangle */ + + stride = cairo_format_stride_for_width (CAIRO_FORMAT_RGB24, width); + buf = g_new (guint32, height * stride / 4); + + for (yy = 0; yy < height; yy++) + { + p = buf + yy * width; + + if (yy >= y1 - PAD && yy < y3 + PAD) + { + y_interp = CLAMP (yy, y1, y3); + + if (y_interp < y2) + { + xl = LERP (x1, x2, y1, y2, y_interp); + + rl = LERP (r1, r2, y1, y2, y_interp); + gl = LERP (g1, g2, y1, y2, y_interp); + bl = LERP (b1, b2, y1, y2, y_interp); + } + else + { + xl = LERP (x2, x3, y2, y3, y_interp); + + rl = LERP (r2, r3, y2, y3, y_interp); + gl = LERP (g2, g3, y2, y3, y_interp); + bl = LERP (b2, b3, y2, y3, y_interp); + } + + xr = LERP (x1, x3, y1, y3, y_interp); + + rr = LERP (r1, r3, y1, y3, y_interp); + gr = LERP (g1, g3, y1, y3, y_interp); + br = LERP (b1, b3, y1, y3, y_interp); + + if (xl > xr) + { + SWAP (xl, xr, t); + SWAP (rl, rr, t); + SWAP (gl, gr, t); + SWAP (bl, br, t); + } + + x_start = MAX (xl - PAD, 0); + x_end = MIN (xr + PAD, width); + x_start = MIN (x_start, x_end); + + c = (rl << 16) | (gl << 8) | bl; + + for (xx = 0; xx < x_start; xx++) + *p++ = c; + + for (; xx < x_end; xx++) + { + x_interp = CLAMP (xx, xl, xr); + + *p++ = ((LERP (rl, rr, xl, xr, x_interp) << 16) | + (LERP (gl, gr, xl, xr, x_interp) << 8) | + LERP (bl, br, xl, xr, x_interp)); + } + + c = (rr << 16) | (gr << 8) | br; + + for (; xx < width; xx++) + *p++ = c; + } + } + + source = cairo_image_surface_create_for_data ((unsigned char *)buf, + CAIRO_FORMAT_RGB24, + width, height, stride); + + /* Draw a triangle with the image as a source */ + + cairo_set_source_surface (cr, source, 0, 0); + cairo_surface_destroy (source); + + cairo_move_to (cr, x1, y1); + cairo_line_to (cr, x2, y2); + cairo_line_to (cr, x3, y3); + cairo_close_path (cr); + cairo_fill (cr); + + g_free (buf); + + /* Draw value marker */ + + xx = floor (sx + (vx - sx) * priv->v + (hx - vx) * priv->s * priv->v + 0.5); + yy = floor (sy + (vy - sy) * priv->v + (hy - vy) * priv->s * priv->v + 0.5); + + r = priv->h; + g = priv->s; + b = priv->v; + hsv_to_rgb (&r, &g, &b); + + context = gtk_widget_get_style_context (widget); + + gtk_style_context_save (context); + + if (INTENSITY (r, g, b) > 0.5) + { + gtk_style_context_add_class (context, "light-area-focus"); + cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); + } + else + { + gtk_style_context_add_class (context, "dark-area-focus"); + cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); + } + +#define RADIUS 4 +#define FOCUS_RADIUS 6 + + cairo_new_path (cr); + cairo_arc (cr, xx, yy, RADIUS, 0, 2 * G_PI); + cairo_stroke (cr); + + /* Draw focus outline */ + + if (draw_focus && ! priv->focus_on_ring) + { + gint focus_width; + gint focus_pad; + + gtk_widget_style_get (widget, + "focus-line-width", &focus_width, + "focus-padding", &focus_pad, + NULL); + + gtk_render_focus (context, cr, + xx - FOCUS_RADIUS - focus_width - focus_pad, + yy - FOCUS_RADIUS - focus_width - focus_pad, + 2 * (FOCUS_RADIUS + focus_width + focus_pad), + 2 * (FOCUS_RADIUS + focus_width + focus_pad)); + } + + gtk_style_context_restore (context); +} + +static gboolean +gimp_color_wheel_draw (GtkWidget *widget, + cairo_t *cr) +{ + GimpColorWheel *wheel = GIMP_COLOR_WHEEL (widget); + GimpColorWheelPrivate *priv = wheel->priv; + gboolean draw_focus; + + draw_focus = gtk_widget_has_visible_focus (widget); + + paint_ring (wheel, cr); + paint_triangle (wheel, cr, draw_focus); + + if (draw_focus && priv->focus_on_ring) + { + GtkStyleContext *context = gtk_widget_get_style_context (widget); + + gtk_render_focus (context, cr, 0, 0, + gtk_widget_get_allocated_width (widget), + gtk_widget_get_allocated_height (widget)); + } + + return FALSE; +} + +static gboolean +gimp_color_wheel_focus (GtkWidget *widget, + GtkDirectionType dir) +{ + GimpColorWheel *wheel = GIMP_COLOR_WHEEL (widget); + GimpColorWheelPrivate *priv = wheel->priv; + + if (!gtk_widget_has_focus (widget)) + { + if (dir == GTK_DIR_TAB_BACKWARD) + priv->focus_on_ring = FALSE; + else + priv->focus_on_ring = TRUE; + + gtk_widget_grab_focus (widget); + return TRUE; + } + + switch (dir) + { + case GTK_DIR_UP: + if (priv->focus_on_ring) + return FALSE; + else + priv->focus_on_ring = TRUE; + break; + + case GTK_DIR_DOWN: + if (priv->focus_on_ring) + priv->focus_on_ring = FALSE; + else + return FALSE; + break; + + case GTK_DIR_LEFT: + case GTK_DIR_TAB_BACKWARD: + if (priv->focus_on_ring) + return FALSE; + else + priv->focus_on_ring = TRUE; + break; + + case GTK_DIR_RIGHT: + case GTK_DIR_TAB_FORWARD: + if (priv->focus_on_ring) + priv->focus_on_ring = FALSE; + else + return FALSE; + break; + } + + gtk_widget_queue_draw (widget); + + return TRUE; +} + +/** + * gimp_color_wheel_new: + * + * Creates a new HSV color selector. + * + * Return value: A newly-created HSV color selector. + * + * Since: 2.14 + */ +GtkWidget* +gimp_color_wheel_new (void) +{ + return g_object_new (GIMP_TYPE_COLOR_WHEEL, NULL); +} + +/** + * gimp_color_wheel_set_color: + * @hsv: An HSV color selector + * @h: Hue + * @s: Saturation + * @v: Value + * + * Sets the current color in an HSV color selector. + * Color component values must be in the [0.0, 1.0] range. + * + * Since: 2.14 + */ +void +gimp_color_wheel_set_color (GimpColorWheel *wheel, + gdouble h, + gdouble s, + gdouble v) +{ + GimpColorWheelPrivate *priv; + + g_return_if_fail (GIMP_IS_COLOR_WHEEL (wheel)); + g_return_if_fail (h >= 0.0 && h <= 1.0); + g_return_if_fail (s >= 0.0 && s <= 1.0); + g_return_if_fail (v >= 0.0 && v <= 1.0); + + priv = wheel->priv; + + if(h == 0.0 && s == 0.0) { + h = priv->h; + } + + priv->h = h; + priv->s = s; + priv->v = v; + + g_signal_emit (wheel, wheel_signals[CHANGED], 0); + + gtk_widget_queue_draw (GTK_WIDGET (wheel)); +} + +/** + * gimp_color_wheel_get_color: + * @hsv: An HSV color selector + * @h: (out): Return value for the hue + * @s: (out): Return value for the saturation + * @v: (out): Return value for the value + * + * Queries the current color in an HSV color selector. + * Returned values will be in the [0.0, 1.0] range. + * + * Since: 2.14 + */ +void +gimp_color_wheel_get_color (GimpColorWheel *wheel, + gdouble *h, + gdouble *s, + gdouble *v) +{ + GimpColorWheelPrivate *priv; + + g_return_if_fail (GIMP_IS_COLOR_WHEEL (wheel)); + + priv = wheel->priv; + + if (h) *h = priv->h; + if (s) *s = priv->s; + if (v) *v = priv->v; +} + +/** + * gimp_color_wheel_set_ring_fraction: + * @ring: A wheel color selector + * @fraction: Ring fraction + * + * Sets the ring fraction of a wheel color selector. + * + * Since: GIMP 2.10 + */ +void +gimp_color_wheel_set_ring_fraction (GimpColorWheel *hsv, + gdouble fraction) +{ + GimpColorWheelPrivate *priv; + + g_return_if_fail (GIMP_IS_COLOR_WHEEL (hsv)); + + priv = hsv->priv; + + priv->ring_fraction = CLAMP (fraction, 0.01, 0.99); + + gtk_widget_queue_draw (GTK_WIDGET (hsv)); +} + +/** + * gimp_color_wheel_get_ring_fraction: + * @ring: A wheel color selector + * + * Returns value: The ring fraction of the wheel color selector. + * + * Since: GIMP 2.10 + */ +gdouble +gimp_color_wheel_get_ring_fraction (GimpColorWheel *wheel) +{ + GimpColorWheelPrivate *priv; + + g_return_val_if_fail (GIMP_IS_COLOR_WHEEL (wheel), DEFAULT_FRACTION); + + priv = wheel->priv; + + return priv->ring_fraction; +} + +/** + * gimp_color_wheel_is_adjusting: + * @hsv: A #GimpColorWheel + * + * An HSV color selector can be said to be adjusting if multiple rapid + * changes are being made to its value, for example, when the user is + * adjusting the value with the mouse. This function queries whether + * the HSV color selector is being adjusted or not. + * + * Return value: %TRUE if clients can ignore changes to the color value, + * since they may be transitory, or %FALSE if they should consider + * the color value status to be final. + * + * Since: 2.14 + */ +gboolean +gimp_color_wheel_is_adjusting (GimpColorWheel *wheel) +{ + GimpColorWheelPrivate *priv; + + g_return_val_if_fail (GIMP_IS_COLOR_WHEEL (wheel), FALSE); + + priv = wheel->priv; + + return priv->mode != DRAG_NONE; +} + +static void +gimp_color_wheel_move (GimpColorWheel *wheel, + GtkDirectionType dir) +{ + GimpColorWheelPrivate *priv = wheel->priv; + gdouble hue, sat, val; + gint hx, hy, sx, sy, vx, vy; /* HSV vertices */ + gint x, y; /* position in triangle */ + + hue = priv->h; + sat = priv->s; + val = priv->v; + + compute_triangle (wheel, &hx, &hy, &sx, &sy, &vx, &vy); + + x = floor (sx + (vx - sx) * priv->v + (hx - vx) * priv->s * priv->v + 0.5); + y = floor (sy + (vy - sy) * priv->v + (hy - vy) * priv->s * priv->v + 0.5); + +#define HUE_DELTA 0.002 + switch (dir) + { + case GTK_DIR_UP: + if (priv->focus_on_ring) + hue += HUE_DELTA; + else + { + y -= 1; + compute_sv (wheel, x, y, &sat, &val); + } + break; + + case GTK_DIR_DOWN: + if (priv->focus_on_ring) + hue -= HUE_DELTA; + else + { + y += 1; + compute_sv (wheel, x, y, &sat, &val); + } + break; + + case GTK_DIR_LEFT: + if (priv->focus_on_ring) + hue += HUE_DELTA; + else + { + x -= 1; + compute_sv (wheel, x, y, &sat, &val); + } + break; + + case GTK_DIR_RIGHT: + if (priv->focus_on_ring) + hue -= HUE_DELTA + ; + else + { + x += 1; + compute_sv (wheel, x, y, &sat, &val); + } + break; + + default: + /* we don't care about the tab directions */ + break; + } + + /* Wrap */ + if (hue < 0.0) + hue = 1.0; + else if (hue > 1.0) + hue = 0.0; + + gimp_color_wheel_set_color (wheel, hue, sat, val); +} diff --git a/src/widgets/gimp/gimpcolorwheel.h b/src/widgets/gimp/gimpcolorwheel.h new file mode 100644 index 000000000..016fb593f --- /dev/null +++ b/src/widgets/gimp/gimpcolorwheel.h @@ -0,0 +1,95 @@ +/* HSV color selector for GTK+ + * + * Copyright (C) 1999 The Free Software Foundation + * + * Authors: Simon Budig (original code) + * Federico Mena-Quintero (cleanup for GTK+) + * Jonathan Blandford (cleanup for GTK+) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/* + * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS + * file for a list of people on the GTK+ Team. See the ChangeLog + * files for a list of changes. These files are distributed with + * GTK+ at ftp://ftp.gtk.org/pub/gtk/. + */ + +#ifndef __GIMP_COLOR_WHEEL_H__ +#define __GIMP_COLOR_WHEEL_H__ + +G_BEGIN_DECLS + +#define GIMP_TYPE_COLOR_WHEEL (gimp_color_wheel_get_type ()) +#define GIMP_COLOR_WHEEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_COLOR_WHEEL, GimpColorWheel)) +#define GIMP_COLOR_WHEEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_COLOR_WHEEL, GimpColorWheelClass)) +#define GIMP_IS_COLOR_WHEEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_COLOR_WHEEL)) +#define GIMP_IS_COLOR_WHEEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_COLOR_WHEEL)) +#define GIMP_COLOR_WHEEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_COLOR_WHEEL, GimpColorWheelClass)) + + +typedef struct _GimpColorWheel GimpColorWheel; +typedef struct _GimpColorWheelClass GimpColorWheelClass; + +struct _GimpColorWheel +{ + GtkWidget parent_instance; + + /* Private data */ + gpointer priv; +}; + +struct _GimpColorWheelClass +{ + GtkWidgetClass parent_class; + + /* Notification signals */ + void (* changed) (GimpColorWheel *wheel); + + /* Keybindings */ + void (* move) (GimpColorWheel *wheel, + GtkDirectionType type); + + /* Padding for future expansion */ + void (*_gimp_reserved1) (void); + void (*_gimp_reserved2) (void); + void (*_gimp_reserved3) (void); + void (*_gimp_reserved4) (void); +}; + + +GType gimp_color_wheel_get_type (void) G_GNUC_CONST; +GtkWidget * gimp_color_wheel_new (void); + +void gimp_color_wheel_set_color (GimpColorWheel *wheel, + double h, + double s, + double v); +void gimp_color_wheel_get_color (GimpColorWheel *wheel, + gdouble *h, + gdouble *s, + gdouble *v); + +void gimp_color_wheel_set_ring_fraction (GimpColorWheel *wheel, + gdouble fraction); +gdouble gimp_color_wheel_get_ring_fraction (GimpColorWheel *wheel); + +gboolean gimp_color_wheel_is_adjusting (GimpColorWheel *wheel); + +G_END_DECLS + +#endif /* __GIMP_COLOR_WHEEL_H__ */ diff --git a/src/widgets/gimp/gimpspinscale.c b/src/widgets/gimp/gimpspinscale.c new file mode 100644 index 000000000..8d8c6c935 --- /dev/null +++ b/src/widgets/gimp/gimpspinscale.c @@ -0,0 +1,969 @@ +/* GIMP - The GNU Image Manipulation Program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * gimpspinscale.c + * Copyright (C) 2010 Michael Natterer + * 2012 Øyvind Kolås + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include + +#include "gimpspinscale.h" + + +enum +{ + PROP_0, + PROP_LABEL, + PROP_FOCUS_WIDGET +}; + +typedef enum +{ + TARGET_NUMBER, + TARGET_UPPER, + TARGET_LOWER, + TARGET_NONE +} SpinScaleTarget; + +typedef enum +{ + APPEARANCE_FULL = 1, /* Full size suitable for tablets */ + APPEARANCE_COMPACT, /* Compact, suitable for desktops with mouse control */ +} SpinScaleAppearance; + +typedef struct _GimpSpinScalePrivate GimpSpinScalePrivate; + +struct _GimpSpinScalePrivate +{ + gchar *label; + + gboolean scale_limits_set; + gdouble scale_lower; + gdouble scale_upper; + gdouble gamma; + + PangoLayout *layout; + gboolean changing_value; + gboolean relative_change; + gdouble start_x; + gdouble start_value; + + GtkWidget* focusWidget; + gboolean transferFocus; + SpinScaleAppearance appearanceMode; +}; + +#define GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \ + GIMP_TYPE_SPIN_SCALE, \ + GimpSpinScalePrivate)) + + +static void gimp_spin_scale_dispose (GObject *object); +static void gimp_spin_scale_finalize (GObject *object); +static void gimp_spin_scale_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void gimp_spin_scale_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +static void gimp_spin_scale_style_set (GtkWidget *widget, + GtkStyle *prev_style); + +static void gimp_spin_scale_get_preferred_width (GtkWidget *widget, + gint *minimum_width, + gint *natural_width); +static void gimp_spin_scale_get_preferred_height (GtkWidget *widget, + gint *minimum_width, + gint *natural_width); +static gboolean gimp_spin_scale_draw (GtkWidget *widget, + cairo_t *cr); + +static gboolean gimp_spin_scale_button_press (GtkWidget *widget, + GdkEventButton *event); +static gboolean gimp_spin_scale_button_release (GtkWidget *widget, + GdkEventButton *event); +static gboolean gimp_spin_scale_motion_notify (GtkWidget *widget, + GdkEventMotion *event); +static gboolean gimp_spin_scale_leave_notify (GtkWidget *widget, + GdkEventCrossing *event); +static gboolean gimp_spin_scale_keypress( GtkWidget *widget, + GdkEventKey *event); + +static void gimp_spin_scale_defocus( GtkSpinButton *spin_button ); + +static void gimp_spin_scale_value_changed (GtkSpinButton *spin_button); + + +G_DEFINE_TYPE (GimpSpinScale, gimp_spin_scale, GTK_TYPE_SPIN_BUTTON); + +#define parent_class gimp_spin_scale_parent_class + + +static void +gimp_spin_scale_class_init (GimpSpinScaleClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + GtkSpinButtonClass *spin_button_class = GTK_SPIN_BUTTON_CLASS (klass); + + object_class->dispose = gimp_spin_scale_dispose; + object_class->finalize = gimp_spin_scale_finalize; + object_class->set_property = gimp_spin_scale_set_property; + object_class->get_property = gimp_spin_scale_get_property; + + widget_class->style_set = gimp_spin_scale_style_set; + widget_class->get_preferred_width = gimp_spin_scale_get_preferred_width; + widget_class->get_preferred_height = gimp_spin_scale_get_preferred_height; + widget_class->draw = gimp_spin_scale_draw; + widget_class->button_press_event = gimp_spin_scale_button_press; + widget_class->button_release_event = gimp_spin_scale_button_release; + widget_class->motion_notify_event = gimp_spin_scale_motion_notify; + widget_class->leave_notify_event = gimp_spin_scale_leave_notify; + widget_class->key_press_event = gimp_spin_scale_keypress; + + spin_button_class->value_changed = gimp_spin_scale_value_changed; + + g_object_class_install_property (object_class, PROP_LABEL, + g_param_spec_string ("label", NULL, NULL, + NULL, + G_PARAM_READWRITE)); + + g_type_class_add_private (klass, sizeof (GimpSpinScalePrivate)); +} + +static void +gimp_spin_scale_init (GimpSpinScale *scale) +{ + GimpSpinScalePrivate *private = GET_PRIVATE (scale); + + gtk_widget_add_events (GTK_WIDGET (scale), + GDK_BUTTON_PRESS_MASK | + GDK_BUTTON_RELEASE_MASK | + GDK_POINTER_MOTION_MASK | + GDK_BUTTON1_MOTION_MASK | + GDK_LEAVE_NOTIFY_MASK); + + gtk_entry_set_alignment (GTK_ENTRY (scale), 1.0); + gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (scale), TRUE); + + private->gamma = 1.0; + private->focusWidget = NULL; + private->transferFocus = FALSE; + private->appearanceMode = APPEARANCE_COMPACT; +} + +static void +gimp_spin_scale_dispose (GObject *object) +{ + GimpSpinScalePrivate *private = GET_PRIVATE (object); + + if (private->layout) + { + g_object_unref (private->layout); + private->layout = NULL; + } + + G_OBJECT_CLASS (parent_class)->dispose (object); +} + +static void +gimp_spin_scale_finalize (GObject *object) +{ + GimpSpinScalePrivate *private = GET_PRIVATE (object); + + if (private->label) + { + g_free (private->label); + private->label = NULL; + } + + G_OBJECT_CLASS (parent_class)->finalize (object); +} + +static void +gimp_spin_scale_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + GimpSpinScalePrivate *private = GET_PRIVATE (object); + GimpSpinScale *scale = GIMP_SPIN_SCALE (object); + + switch (property_id) + { + case PROP_LABEL: + gimp_spin_scale_set_label (scale, g_value_get_string (value)); + break; + + case PROP_FOCUS_WIDGET: + { + /* TODO unhook prior */ + private->focusWidget = GTK_WIDGET (g_value_get_pointer (value)); + } + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +gimp_spin_scale_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + GimpSpinScalePrivate *private = GET_PRIVATE (object); + GimpSpinScale *scale = GIMP_SPIN_SCALE (object); + + switch (property_id) + { + case PROP_LABEL: + g_value_set_string (value, gimp_spin_scale_get_label (scale)); + break; + + case PROP_FOCUS_WIDGET: + g_value_set_pointer (value, private->focusWidget); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + + +void +gimp_spin_scale_set_focuswidget( GtkWidget *scale, GtkWidget* widget ) +{ + GimpSpinScalePrivate *private = GET_PRIVATE (scale); + + /* TODO unhook prior */ + + private->focusWidget = widget; +} + +void +gimp_spin_scale_set_appearance( GtkWidget *widget, const gchar *appearance) +{ + GimpSpinScalePrivate *private = GET_PRIVATE (widget); + + if ( strcmp("full", appearance) == 0 ) { + private->appearanceMode = APPEARANCE_FULL; + } else if ( strcmp("compact", appearance) == 0 ) { + private->appearanceMode = APPEARANCE_COMPACT; + } +} + +static void +gimp_spin_scale_get_preferred_width (GtkWidget *widget, + gint *minimum_width, + gint *natural_width) +{ + GimpSpinScalePrivate *private = GET_PRIVATE (widget); + PangoContext *context = gtk_widget_get_pango_context (widget); + PangoFontMetrics *metrics; + + GTK_WIDGET_CLASS (parent_class)->get_preferred_width (widget, + minimum_width, + natural_width); + + metrics = pango_context_get_metrics (context, + pango_context_get_font_description (context), + pango_context_get_language (context)); + + if (private->label) + { + gint char_width; + gint digit_width; + gint char_pixels; + + char_width = pango_font_metrics_get_approximate_char_width (metrics); + digit_width = pango_font_metrics_get_approximate_digit_width (metrics); + char_pixels = PANGO_PIXELS (MAX (char_width, digit_width)); + + /* ~3 chars for the ellipse */ + *minimum_width += char_pixels * 3; + *natural_width += char_pixels * 3; + } + + pango_font_metrics_unref (metrics); +} + +static void +gimp_spin_scale_get_preferred_height (GtkWidget *widget, + gint *minimum_height, + gint *natural_height) +{ + PangoContext *context = gtk_widget_get_pango_context (widget); + PangoFontMetrics *metrics; + //gint height; + + GTK_WIDGET_CLASS (parent_class)->get_preferred_height (widget, + minimum_height, + natural_height); + + metrics = pango_context_get_metrics (context, + pango_context_get_font_description (context), + pango_context_get_language (context)); + + //height = PANGO_PIXELS (pango_font_metrics_get_ascent (metrics) + + // pango_font_metrics_get_descent (metrics)); + + *minimum_height += 1; + *natural_height += 1; + + pango_font_metrics_unref (metrics); +} + +static void +gimp_spin_scale_style_set (GtkWidget *widget, + GtkStyle *prev_style) +{ + GimpSpinScalePrivate *private = GET_PRIVATE (widget); + + GTK_WIDGET_CLASS (parent_class)->style_set (widget, prev_style); + + if (private->layout) + { + g_object_unref (private->layout); + private->layout = NULL; + } +} + + +static gboolean + gimp_spin_scale_draw (GtkWidget *widget, + cairo_t *cr) +{ + GimpSpinScalePrivate *private = GET_PRIVATE (widget); + GtkStyleContext *style = gtk_widget_get_style_context(widget); + GtkAllocation allocation; + GdkRGBA color; + + cairo_save (cr); + GTK_WIDGET_CLASS (parent_class)->draw (widget, cr); + cairo_restore (cr); + + gtk_widget_get_allocation (widget, &allocation); + + cairo_set_line_width (cr, 1.0); + + if (private->label) + { + GdkRectangle text_area; + gint minimum_width; + gint natural_width; + PangoRectangle logical; + gint layout_offset_x; + gint layout_offset_y; + GtkStateFlags state; + GdkRGBA text_color; + GdkRGBA bar_text_color; + gdouble progress_fraction; + gint progress_x; + gint progress_y; + gint progress_width; + gint progress_height; + + gtk_entry_get_text_area (GTK_ENTRY (widget), &text_area); + + GTK_WIDGET_CLASS (parent_class)->get_preferred_width (widget, + &minimum_width, + &natural_width); + + if (! private->layout) + { + private->layout = gtk_widget_create_pango_layout (widget, + private->label); + pango_layout_set_ellipsize (private->layout, PANGO_ELLIPSIZE_END); + } + + pango_layout_set_width (private->layout, + PANGO_SCALE * + (allocation.width - minimum_width)); + pango_layout_get_pixel_extents (private->layout, NULL, &logical); + + gtk_entry_get_layout_offsets (GTK_ENTRY (widget), NULL, &layout_offset_y); + + if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) + layout_offset_x = text_area.x + text_area.width - logical.width - 4; + else + layout_offset_x = 4; + + layout_offset_x -= logical.x; + + state = gtk_widget_get_state_flags (widget); + + gtk_style_context_get_color (style, state, &text_color); + + gtk_style_context_save (style); + gtk_style_context_add_class (style, GTK_STYLE_CLASS_PROGRESSBAR); + gtk_style_context_get_color (style, state, &bar_text_color); + gtk_style_context_restore (style); + + progress_fraction = gtk_entry_get_progress_fraction (GTK_ENTRY (widget)); + + if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) + { + progress_fraction = 1.0 - progress_fraction; + + progress_x = text_area.width * progress_fraction; + progress_y = 0; + progress_width = text_area.width - progress_x; + progress_height = text_area.height; + } + else + { + progress_x = 0; + progress_y = 0; + progress_width = text_area.width * progress_fraction; + progress_height = text_area.height; + } + + cairo_save (cr); + + cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD); + cairo_rectangle (cr, 0, 0, text_area.width, text_area.height); + cairo_rectangle (cr, progress_x, progress_y, + progress_width, progress_height); + cairo_clip (cr); + cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING); + + cairo_move_to (cr, layout_offset_x, text_area.y + layout_offset_y-3); + gdk_cairo_set_source_rgba (cr, &text_color); + pango_cairo_show_layout (cr, private->layout); + cairo_restore (cr); + + cairo_rectangle (cr, progress_x, progress_y, + progress_width, progress_height); + cairo_clip (cr); + + cairo_move_to (cr, layout_offset_x, text_area.y + layout_offset_y-3); + gdk_cairo_set_source_rgba (cr, &bar_text_color); + pango_cairo_show_layout (cr, private->layout); + } + + return FALSE; +} + +/* Returns TRUE if a translation should be done */ +static gboolean +gtk_widget_get_translation_to_window (GtkWidget *widget, + GdkWindow *window, + int *x, + int *y) +{ + GdkWindow *w, *widget_window; + + if (!gtk_widget_get_has_window (widget)) + { + GtkAllocation allocation; + + gtk_widget_get_allocation (widget, &allocation); + + *x = -allocation.x; + *y = -allocation.y; + } + else + { + *x = 0; + *y = 0; + } + + widget_window = gtk_widget_get_window (widget); + + for (w = window; w && w != widget_window; w = gdk_window_get_parent (w)) + { + int wx, wy; + gdk_window_get_position (w, &wx, &wy); + *x += wx; + *y += wy; + } + + if (w == NULL) + { + *x = 0; + *y = 0; + return FALSE; + } + + return TRUE; +} + +static void +gimp_spin_scale_event_to_widget_coords (GtkWidget *widget, + GdkWindow *window, + gdouble event_x, + gdouble event_y, + gint *widget_x, + gint *widget_y) +{ + gint tx, ty; + + if (gtk_widget_get_translation_to_window (widget, window, &tx, &ty)) + { + event_x += tx; + event_y += ty; + } + + *widget_x = event_x; + *widget_y = event_y; +} + +static SpinScaleTarget +gimp_spin_scale_get_target (GtkWidget *widget, + gdouble x, + gdouble y) +{ + GtkAllocation allocation; + PangoRectangle logical; + gint layout_x; + gint layout_y; + + gtk_widget_get_allocation (widget, &allocation); + gtk_entry_get_layout_offsets (GTK_ENTRY (widget), &layout_x, &layout_y); + pango_layout_get_pixel_extents (gtk_entry_get_layout (GTK_ENTRY (widget)), + NULL, &logical); + + GdkRectangle text_area; + gtk_entry_get_text_area (GTK_ENTRY (widget), &text_area); + + if (x >= text_area.x && x < text_area.width && + y >= text_area.y && y < text_area.height) + { + x -= text_area.x; + y -= text_area.y; + + if (x > layout_x && x < layout_x + logical.width && + y > layout_y && y < layout_y + logical.height) + { + return TARGET_NUMBER; + } + else if (y > text_area.height / 2) + { + return TARGET_LOWER; + } + + return TARGET_UPPER; + } + + return TARGET_NONE; +} + +static void +gimp_spin_scale_get_limits (GimpSpinScale *scale, + gdouble *lower, + gdouble *upper) +{ + GimpSpinScalePrivate *private = GET_PRIVATE (scale); + + if (private->scale_limits_set) + { + *lower = private->scale_lower; + *upper = private->scale_upper; + } + else + { + GtkSpinButton *spin_button = GTK_SPIN_BUTTON (scale); + GtkAdjustment *adjustment = gtk_spin_button_get_adjustment (spin_button); + + *lower = gtk_adjustment_get_lower (adjustment); + *upper = gtk_adjustment_get_upper (adjustment); + } +} + +static void +gimp_spin_scale_change_value (GtkWidget *widget, + gdouble x) +{ + GimpSpinScalePrivate *private = GET_PRIVATE (widget); + GtkSpinButton *spin_button = GTK_SPIN_BUTTON (widget); + GtkAdjustment *adjustment = gtk_spin_button_get_adjustment (spin_button); + gdouble lower; + gdouble upper; + gdouble value; + GdkRectangle text_area; + gtk_entry_get_text_area (GTK_ENTRY (widget), &text_area); + gimp_spin_scale_get_limits (GIMP_SPIN_SCALE (widget), &lower, &upper); + + if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) + x = text_area.width - x; + + if (private->relative_change) + { + gdouble diff; + gdouble step; + + step = (upper - lower) / text_area.width / 10.0; + if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) + diff = x - (text_area.width - private->start_x); + else + diff = x - private->start_x; + + value = (private->start_value + diff * step); + } + else + { + gdouble fraction; + + fraction = x / (gdouble) text_area.width; + if (fraction > 0.0) + fraction = pow (fraction, private->gamma); + + value = fraction * (upper - lower) + lower; + } + + gtk_adjustment_set_value (adjustment, value); +} + +static gboolean +gimp_spin_scale_button_press (GtkWidget *widget, + GdkEventButton *event) +{ + GimpSpinScalePrivate *private = GET_PRIVATE (widget); + + private->changing_value = FALSE; + private->relative_change = FALSE; + + gint x, y; + gimp_spin_scale_event_to_widget_coords (widget, event->window, + event->x, event->y, + &x, &y); + switch (gimp_spin_scale_get_target (widget, x, y)) + { + case TARGET_UPPER: + private->changing_value = TRUE; + + gtk_widget_grab_focus (widget); + + gimp_spin_scale_change_value (widget, x); + + return TRUE; + + case TARGET_LOWER: + private->changing_value = TRUE; + + gtk_widget_grab_focus (widget); + + private->relative_change = TRUE; + private->start_x = x; + private->start_value = gtk_adjustment_get_value (gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (widget))); + + return TRUE; + + default: + break; + } + + return GTK_WIDGET_CLASS (parent_class)->button_press_event (widget, event); +} + +static gboolean +gimp_spin_scale_button_release (GtkWidget *widget, + GdkEventButton *event) +{ + GimpSpinScalePrivate *private = GET_PRIVATE (widget); + gint x, y; + + gimp_spin_scale_event_to_widget_coords (widget, event->window, + event->x, event->y, + &x, &y); + + if (private->changing_value) + { + private->changing_value = FALSE; + gimp_spin_scale_change_value (widget, x); + return TRUE; + } + + return GTK_WIDGET_CLASS (parent_class)->button_release_event (widget, event); +} + +static gboolean +gimp_spin_scale_motion_notify (GtkWidget *widget, + GdkEventMotion *event) +{ + GimpSpinScalePrivate *private = GET_PRIVATE (widget); + + gdk_event_request_motions (event); + + gint x, y; + + gimp_spin_scale_event_to_widget_coords (widget, event->window, + event->x, event->y, + &x, &y); + + if (private->changing_value) + { + gimp_spin_scale_change_value (widget, x); + + return TRUE; + } + + GTK_WIDGET_CLASS (parent_class)->motion_notify_event (widget, event); + + if (! (event->state & + (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK)) + ) + { + GdkDisplay *display = gtk_widget_get_display (widget); + GdkCursor *cursor = NULL; + + switch (gimp_spin_scale_get_target (widget, x, y)) + { + case TARGET_NUMBER: + cursor = gdk_cursor_new_for_display (display, GDK_XTERM); + break; + + case TARGET_UPPER: + cursor = gdk_cursor_new_for_display (display, GDK_SB_UP_ARROW); + break; + + case TARGET_LOWER: + cursor = gdk_cursor_new_for_display (display, GDK_SB_H_DOUBLE_ARROW); + break; + + default: + break; + } + + if (cursor) + { + gdk_window_set_cursor (event->window, cursor); + g_object_unref (cursor); + } + } + + return FALSE; +} + +static gboolean +gimp_spin_scale_leave_notify (GtkWidget *widget, + GdkEventCrossing *event) +{ + gdk_window_set_cursor (event->window, NULL); + + return GTK_WIDGET_CLASS (parent_class)->leave_notify_event (widget, event); +} + +gboolean gimp_spin_scale_keypress( GtkWidget *widget, GdkEventKey *event) +{ + GimpSpinScalePrivate *private = GET_PRIVATE (widget); + guint key = 0; + gdk_keymap_translate_keyboard_state( gdk_keymap_get_for_display( gdk_display_get_default() ), + event->hardware_keycode, (GdkModifierType)event->state, + 0, &key, 0, 0, 0 ); + + switch ( key ) { + + case GDK_KEY_Escape: + case GDK_KEY_Return: + case GDK_KEY_KP_Enter: + { + private->transferFocus = TRUE; + gimp_spin_scale_defocus( GTK_SPIN_BUTTON(widget) ); + } + break; + + } + + return GTK_WIDGET_CLASS (parent_class)->key_press_event (widget, event); +} + +static void +gimp_spin_scale_defocus( GtkSpinButton *spin_button ) +{ + GimpSpinScalePrivate *private = GET_PRIVATE (spin_button); + + if ( private->transferFocus ) { + if ( private->focusWidget ) { + gtk_widget_grab_focus( private->focusWidget ); + } + } +} + +static void +gimp_spin_scale_value_changed (GtkSpinButton *spin_button) +{ + GtkAdjustment *adjustment = gtk_spin_button_get_adjustment (spin_button); + GimpSpinScalePrivate *private = GET_PRIVATE (spin_button); + gdouble lower; + gdouble upper; + gdouble value; + + gimp_spin_scale_get_limits (GIMP_SPIN_SCALE (spin_button), &lower, &upper); + + value = CLAMP (gtk_adjustment_get_value (adjustment), lower, upper); + + gtk_entry_set_progress_fraction (GTK_ENTRY (spin_button), + pow ((value - lower) / (upper - lower), + 1.0 / private->gamma)); + + // TODO - Allow scrollwheel to change value then return focus, + // but clicks/keypress should keep focus in the control + //if ( gtk_widget_has_focus( GTK_WIDGET(spin_button) ) ) { + // gimp_spin_scale_defocus( spin_button ); + //} +} + + +/* public functions */ + +GtkWidget * +gimp_spin_scale_new (GtkAdjustment *adjustment, + const gchar *label, + gint digits) +{ + g_return_val_if_fail (GTK_IS_ADJUSTMENT (adjustment), NULL); + + return g_object_new (GIMP_TYPE_SPIN_SCALE, + "adjustment", adjustment, + "label", label, + "digits", digits, + NULL); +} + +void +gimp_spin_scale_set_label (GimpSpinScale *scale, + const gchar *label) +{ + GimpSpinScalePrivate *private; + + g_return_if_fail (GIMP_IS_SPIN_SCALE (scale)); + + private = GET_PRIVATE (scale); + + if (label == private->label) + return; + + g_free (private->label); + private->label = g_strdup (label); + + if (private->layout) + { + g_object_unref (private->layout); + private->layout = NULL; + } + + gtk_widget_queue_resize (GTK_WIDGET (scale)); + + g_object_notify (G_OBJECT (scale), "label"); +} + +const gchar * +gimp_spin_scale_get_label (GimpSpinScale *scale) +{ + g_return_val_if_fail (GIMP_IS_SPIN_SCALE (scale), NULL); + + return GET_PRIVATE (scale)->label; +} + +void +gimp_spin_scale_set_scale_limits (GimpSpinScale *scale, + gdouble lower, + gdouble upper) +{ + GimpSpinScalePrivate *private; + GtkSpinButton *spin_button; + GtkAdjustment *adjustment; + + g_return_if_fail (GIMP_IS_SPIN_SCALE (scale)); + + private = GET_PRIVATE (scale); + spin_button = GTK_SPIN_BUTTON (scale); + adjustment = gtk_spin_button_get_adjustment (spin_button); + + g_return_if_fail (lower >= gtk_adjustment_get_lower (adjustment)); + g_return_if_fail (upper <= gtk_adjustment_get_upper (adjustment)); + + private->scale_limits_set = TRUE; + private->scale_lower = lower; + private->scale_upper = upper; + private->gamma = 1.0; + + gimp_spin_scale_value_changed (spin_button); +} + +void +gimp_spin_scale_unset_scale_limits (GimpSpinScale *scale) +{ + GimpSpinScalePrivate *private; + + g_return_if_fail (GIMP_IS_SPIN_SCALE (scale)); + + private = GET_PRIVATE (scale); + + private->scale_limits_set = FALSE; + private->scale_lower = 0.0; + private->scale_upper = 0.0; + + gimp_spin_scale_value_changed (GTK_SPIN_BUTTON (scale)); +} + +gboolean +gimp_spin_scale_get_scale_limits (GimpSpinScale *scale, + gdouble *lower, + gdouble *upper) +{ + GimpSpinScalePrivate *private; + + g_return_val_if_fail (GIMP_IS_SPIN_SCALE (scale), FALSE); + + private = GET_PRIVATE (scale); + + if (lower) + *lower = private->scale_lower; + + if (upper) + *upper = private->scale_upper; + + return private->scale_limits_set; +} + +void +gimp_spin_scale_set_gamma (GimpSpinScale *scale, + gdouble gamma) +{ + GimpSpinScalePrivate *private; + + g_return_if_fail (GIMP_IS_SPIN_SCALE (scale)); + + private = GET_PRIVATE (scale); + + private->gamma = gamma; + + gimp_spin_scale_value_changed (GTK_SPIN_BUTTON (scale)); +} + +gdouble +gimp_spin_scale_get_gamma (GimpSpinScale *scale) +{ + g_return_val_if_fail (GIMP_IS_SPIN_SCALE (scale), 1.0); + + return GET_PRIVATE(scale)->gamma; +} diff --git a/src/widgets/gimp/gimpspinscale.h b/src/widgets/gimp/gimpspinscale.h new file mode 100644 index 000000000..b42a0faf8 --- /dev/null +++ b/src/widgets/gimp/gimpspinscale.h @@ -0,0 +1,82 @@ +/* GIMP - The GNU Image Manipulation Program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * gimpspinscale.h + * Copyright (C) 2010 Michael Natterer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef __GIMP_SPIN_SCALE_H__ +#define __GIMP_SPIN_SCALE_H__ + +#ifndef WITH_GIMP +#include +#endif + +G_BEGIN_DECLS + +#define GIMP_TYPE_SPIN_SCALE (gimp_spin_scale_get_type ()) +#define GIMP_SPIN_SCALE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_SPIN_SCALE, GimpSpinScale)) +#define GIMP_SPIN_SCALE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_SPIN_SCALE, GimpSpinScaleClass)) +#define GIMP_IS_SPIN_SCALE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_SPIN_SCALE)) +#define GIMP_IS_SPIN_SCALE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_SPIN_SCALE)) +#define GIMP_SPIN_SCALE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_SPIN_SCALE, GimpSpinScaleClass)) + + +typedef struct _GimpSpinScale GimpSpinScale; +typedef struct _GimpSpinScaleClass GimpSpinScaleClass; + +struct _GimpSpinScale +{ + GtkSpinButton parent_instance; +}; + +struct _GimpSpinScaleClass +{ + GtkSpinButtonClass parent_class; +}; + + +GType gimp_spin_scale_get_type (void) G_GNUC_CONST; + +GtkWidget * gimp_spin_scale_new (GtkAdjustment *adjustment, + const gchar *label, + gint digits); + +void gimp_spin_scale_set_label (GimpSpinScale *scale, + const gchar *label); +const gchar * gimp_spin_scale_get_label (GimpSpinScale *scale); + +void gimp_spin_scale_set_scale_limits (GimpSpinScale *scale, + gdouble lower, + gdouble upper); +void gimp_spin_scale_unset_scale_limits (GimpSpinScale *scale); +gboolean gimp_spin_scale_get_scale_limits (GimpSpinScale *scale, + gdouble *lower, + gdouble *upper); + +void gimp_spin_scale_set_gamma (GimpSpinScale *scale, + gdouble gamma); +gdouble gimp_spin_scale_get_gamma (GimpSpinScale *scale); + +void gimp_spin_scale_set_focuswidget (GtkWidget *scale, + GtkWidget *widget); + +void gimp_spin_scale_set_appearance (GtkWidget *scale, + const gchar *appearance); + +G_END_DECLS + +#endif /* __GIMP_SPIN_SCALE_H__ */ diff --git a/src/widgets/gimp/ruler.cpp b/src/widgets/gimp/ruler.cpp new file mode 100644 index 000000000..bfb9c9071 --- /dev/null +++ b/src/widgets/gimp/ruler.cpp @@ -0,0 +1,1425 @@ +/* + * Customized ruler class for inkscape. Note that this is a fork of + * the GimpRuler widget from GIMP: libgimpwidgets/gimpruler.c. + * The GIMP code is released under the GPL 3. The GIMP code itself + * is a fork of the now-obsolete GtkRuler widget from GTK+ 2. + * + * Major differences between implementations in Inkscape and GIMP are + * as follows: + * - We use a 1,2,4,8... scale for inches and 1,2,5,10... for everything + * else. GIMP uses 1,2,5,10... for everything. + * + * - We use a default font size of PANGO_SCALE_X_SMALL for labels, + * GIMP uses PANGO_SCALE_SMALL (i.e., a bit larger than ours). + * + * - We abbreviate large numbers in tick-labels (e.g., 10000 -> 10k) + * + * Authors: + * Lauris Kaplinski + * Frank Felfe + * bulia byak + * Diederik van Lierop + * Jon A. Cruz + * Alex Valavanis + * + * Copyright (C) 1999-2011 authors + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include +#include +#include + +#include "ruler.h" +#include "round.h" +#include +#include "util/units.h" + +#define ROUND(x) ((int) ((x) + 0.5)) + +#define GTK_PARAM_READWRITE G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB + +#define DEFAULT_RULER_FONT_SCALE PANGO_SCALE_X_SMALL +#define MINIMUM_INCR 5 +#define IMMEDIATE_REDRAW_THRESHOLD 20 + +using Inkscape::Util::unit_table; + +enum { + PROP_0, + PROP_ORIENTATION, + PROP_UNIT, + PROP_LOWER, + PROP_UPPER, + PROP_POSITION, + PROP_MAX_SIZE +}; + + +/* All distances below are in 1/72nd's of an inch. (According to + * Adobe, that's a point, but points are really 1/72.27 in.) + */ +typedef struct +{ + GtkOrientation orientation; + Inkscape::Util::Unit const *unit; + gdouble lower; + gdouble upper; + gdouble position; + gdouble max_size; + + GdkWindow *input_window; + cairo_surface_t *backing_store; + gboolean backing_store_valid; + GdkRectangle last_pos_rect; + guint pos_redraw_idle_id; + PangoLayout *layout; + gdouble font_scale; + + GList *track_widgets; +} SPRulerPrivate; + +#define SP_RULER_GET_PRIVATE(ruler) \ + G_TYPE_INSTANCE_GET_PRIVATE (ruler, SP_TYPE_RULER, SPRulerPrivate) + + +struct SPRulerMetric +{ + gdouble ruler_scale[16]; + gint subdivide[5]; +}; + +// Ruler metric for general use. +static SPRulerMetric const ruler_metric_general = { + { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000, 10000, 25000, 50000, 100000 }, + { 1, 5, 10, 50, 100 } +}; + +// Ruler metric for inch scales. +static SPRulerMetric const ruler_metric_inches = { + { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 }, + { 1, 2, 4, 8, 16 } +}; + +static void sp_ruler_dispose (GObject *object); +static void sp_ruler_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec); +static void sp_ruler_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec); + +static void sp_ruler_realize (GtkWidget *widget); +static void sp_ruler_unrealize (GtkWidget *widget); +static void sp_ruler_map (GtkWidget *widget); +static void sp_ruler_unmap (GtkWidget *widget); +static void sp_ruler_size_allocate (GtkWidget *widget, + GtkAllocation *allocation); + +static void sp_ruler_get_preferred_width (GtkWidget *widget, + gint *minimum_width, + gint *natural_width); + +static void sp_ruler_get_preferred_height (GtkWidget *widget, + gint *minimum_height, + gint *natural_height); +static void sp_ruler_style_updated (GtkWidget *widget); + +static gboolean sp_ruler_motion_notify (GtkWidget *widget, + GdkEventMotion *event); +static gboolean sp_ruler_draw (GtkWidget *widget, + cairo_t *cr); +static void sp_ruler_draw_ticks (SPRuler *ruler); +static GdkRectangle sp_ruler_get_pos_rect (SPRuler *ruler, + gdouble position); +static gboolean sp_ruler_idle_queue_pos_redraw(gpointer data); +static void sp_ruler_queue_pos_redraw (SPRuler *ruler); +static void sp_ruler_draw_pos (SPRuler *ruler, + cairo_t *cr); +static void sp_ruler_make_pixmap (SPRuler *ruler); + +static PangoLayout * sp_ruler_get_layout (GtkWidget *widget, + const gchar *text); + + +G_DEFINE_TYPE (SPRuler, sp_ruler, GTK_TYPE_WIDGET) + +#define parent_class sp_ruler_parent_class + + +static void +sp_ruler_class_init (SPRulerClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + +#if GTK_CHECK_VERSION(3,20,0) + gtk_widget_class_set_css_name (widget_class, "ruler-widget"); +#endif + + object_class->dispose = sp_ruler_dispose; + object_class->set_property = sp_ruler_set_property; + object_class->get_property = sp_ruler_get_property; + + widget_class->realize = sp_ruler_realize; + widget_class->unrealize = sp_ruler_unrealize; + widget_class->map = sp_ruler_map; + widget_class->unmap = sp_ruler_unmap; + widget_class->size_allocate = sp_ruler_size_allocate; + widget_class->get_preferred_width = sp_ruler_get_preferred_width; + widget_class->get_preferred_height = sp_ruler_get_preferred_height; + widget_class->style_updated = sp_ruler_style_updated; + widget_class->draw = sp_ruler_draw; + widget_class->motion_notify_event = sp_ruler_motion_notify; + + g_type_class_add_private (object_class, sizeof (SPRulerPrivate)); + + g_object_class_install_property (object_class, + PROP_ORIENTATION, + g_param_spec_enum ("orientation", + _("Orientation"), + _("The orientation of the ruler"), + GTK_TYPE_ORIENTATION, + GTK_ORIENTATION_HORIZONTAL, + static_cast(GTK_PARAM_READWRITE))); + + /* FIXME: Should probably use g_param_spec_enum */ + g_object_class_install_property (object_class, + PROP_UNIT, + g_param_spec_string ("unit", + _("Unit"), + _("Unit of the ruler"), + "px", + static_cast(GTK_PARAM_READWRITE))); + + g_object_class_install_property (object_class, + PROP_LOWER, + g_param_spec_double ("lower", + _("Lower"), + _("Lower limit of ruler"), + -G_MAXDOUBLE, + G_MAXDOUBLE, + 0.0, + static_cast(GTK_PARAM_READWRITE))); + + g_object_class_install_property (object_class, + PROP_UPPER, + g_param_spec_double ("upper", + _("Upper"), + _("Upper limit of ruler"), + -G_MAXDOUBLE, + G_MAXDOUBLE, + 0.0, + static_cast(GTK_PARAM_READWRITE))); + + g_object_class_install_property (object_class, + PROP_POSITION, + g_param_spec_double ("position", + _("Position"), + _("Position of mark on the ruler"), + -G_MAXDOUBLE, + G_MAXDOUBLE, + 0.0, + static_cast(GTK_PARAM_READWRITE))); + + g_object_class_install_property (object_class, + PROP_MAX_SIZE, + g_param_spec_double ("max-size", + _("Max Size"), + _("Maximum size of the ruler"), + -G_MAXDOUBLE, + G_MAXDOUBLE, + 0.0, + static_cast(GTK_PARAM_READWRITE))); + + gtk_widget_class_install_style_property (widget_class, + g_param_spec_double ("font-scale", + NULL, NULL, + 0.0, + G_MAXDOUBLE, + DEFAULT_RULER_FONT_SCALE, + G_PARAM_READABLE)); +} + +static void +sp_ruler_init (SPRuler *ruler) +{ + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); + + gtk_widget_set_has_window (GTK_WIDGET (ruler), FALSE); + + priv->orientation = GTK_ORIENTATION_HORIZONTAL; + priv->unit = unit_table.getUnit("px"); + priv->lower = 0; + priv->upper = 0; + priv->position = 0; + priv->max_size = 0; + + priv->backing_store = NULL; + priv->backing_store_valid = FALSE; + + priv->last_pos_rect.x = 0; + priv->last_pos_rect.y = 0; + priv->last_pos_rect.width = 0; + priv->last_pos_rect.height = 0; + priv->pos_redraw_idle_id = 0; + + priv->font_scale = DEFAULT_RULER_FONT_SCALE; +} + +static void +sp_ruler_dispose (GObject *object) +{ + SPRuler *ruler = SP_RULER (object); + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); + + while (priv->track_widgets) + sp_ruler_remove_track_widget (ruler, GTK_WIDGET(priv->track_widgets->data)); + + if (priv->pos_redraw_idle_id) + { + g_source_remove (priv->pos_redraw_idle_id); + priv->pos_redraw_idle_id = 0; + } + + G_OBJECT_CLASS (parent_class)->dispose (object); +} + + +/** + * sp_ruler_set_range: + * @ruler: the SPRuler + * @lower: the lower limit of the ruler + * @upper: the upper limit of the ruler + * @max_size: the maximum size of the ruler used when calculating the space to + * leave for the text + * + * This sets the range of the ruler. + */ +void +sp_ruler_set_range (SPRuler *ruler, + gdouble lower, + gdouble upper, + gdouble max_size) +{ + SPRulerPrivate *priv; + + g_return_if_fail (SP_IS_RULER (ruler)); + + priv = SP_RULER_GET_PRIVATE (ruler); + + g_object_freeze_notify (G_OBJECT (ruler)); + if (priv->lower != lower) + { + priv->lower = lower; + g_object_notify (G_OBJECT (ruler), "lower"); + } + if (priv->upper != upper) + { + priv->upper = upper; + g_object_notify (G_OBJECT (ruler), "upper"); + } + if (priv->max_size != max_size) + { + priv->max_size = max_size; + g_object_notify (G_OBJECT (ruler), "max-size"); + } + g_object_thaw_notify (G_OBJECT (ruler)); + + priv->backing_store_valid = FALSE; + gtk_widget_queue_draw (GTK_WIDGET (ruler)); +} + +/** + * sp_ruler_get_range: + * @ruler: a #SPRuler + * @lower: (allow-none): location to store lower limit of the ruler, or %NULL + * @upper: (allow-none): location to store upper limit of the ruler, or %NULL + * @max_size: location to store the maximum size of the ruler used when calculating + * the space to leave for the text, or %NULL. + * + * Retrieves values indicating the range and current position of a #SPRuler. + * See sp_ruler_set_range(). + **/ +void +sp_ruler_get_range (SPRuler *ruler, + gdouble *lower, + gdouble *upper, + gdouble *max_size) +{ + SPRulerPrivate *priv; + + g_return_if_fail (SP_IS_RULER (ruler)); + + priv = SP_RULER_GET_PRIVATE (ruler); + + if (lower) + *lower = priv->lower; + if (upper) + *upper = priv->upper; + if (max_size) + *max_size = priv->max_size; +} + +static void +sp_ruler_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + SPRuler *ruler = SP_RULER (object); + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); + + switch (prop_id) + { + case PROP_ORIENTATION: + priv->orientation = static_cast(g_value_get_enum (value)); + gtk_widget_queue_resize (GTK_WIDGET (ruler)); + break; + + case PROP_UNIT: + sp_ruler_set_unit (ruler, unit_table.getUnit(g_value_get_string (value))); + break; + + case PROP_LOWER: + sp_ruler_set_range (ruler, + g_value_get_double (value), + priv->upper, + priv->max_size); + break; + case PROP_UPPER: + sp_ruler_set_range (ruler, + priv->lower, + g_value_get_double (value), + priv->max_size); + break; + + case PROP_POSITION: + sp_ruler_set_position (ruler, g_value_get_double (value)); + break; + + case PROP_MAX_SIZE: + sp_ruler_set_range (ruler, + priv->lower, + priv->upper, + g_value_get_double (value)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +sp_ruler_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + SPRuler *ruler = SP_RULER (object); + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); + + switch (prop_id) + { + case PROP_ORIENTATION: + g_value_set_enum (value, priv->orientation); + break; + + case PROP_UNIT: + g_value_set_string (value, priv->unit->abbr.c_str()); + break; + case PROP_LOWER: + g_value_set_double (value, priv->lower); + break; + case PROP_UPPER: + g_value_set_double (value, priv->upper); + break; + case PROP_POSITION: + g_value_set_double (value, priv->position); + break; + case PROP_MAX_SIZE: + g_value_set_double (value, priv->max_size); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +sp_ruler_realize (GtkWidget *widget) +{ + SPRuler *ruler = SP_RULER (widget); + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); + GtkAllocation allocation; + GdkWindowAttr attributes; + gint attributes_mask; + + GTK_WIDGET_CLASS (sp_ruler_parent_class)->realize (widget); + + gtk_widget_get_allocation (widget, &allocation); + + attributes.window_type = GDK_WINDOW_CHILD; + attributes.x = allocation.x; + attributes.y = allocation.y; + attributes.width = allocation.width; + attributes.height = allocation.height; + attributes.wclass = GDK_INPUT_ONLY; + attributes.event_mask = (gtk_widget_get_events (widget) | + GDK_EXPOSURE_MASK | + GDK_POINTER_MOTION_MASK | + GDK_POINTER_MOTION_HINT_MASK); + + attributes_mask = GDK_WA_X | GDK_WA_Y; + + priv->input_window = gdk_window_new (gtk_widget_get_parent_window (widget), + &attributes, attributes_mask); + gdk_window_set_user_data (priv->input_window, ruler); + + sp_ruler_make_pixmap (ruler); +} + +static void +sp_ruler_unrealize(GtkWidget *widget) +{ + SPRuler *ruler = SP_RULER (widget); + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); + + if (priv->backing_store) + { + cairo_surface_destroy (priv->backing_store); + priv->backing_store = NULL; + } + + priv->backing_store_valid = FALSE; + + if (priv->layout) + { + g_object_unref (priv->layout); + priv->layout = NULL; + } + + if (priv->input_window) + { + gdk_window_destroy (priv->input_window); + priv->input_window = NULL; + } + + GTK_WIDGET_CLASS (sp_ruler_parent_class)->unrealize (widget); +} + +static void +sp_ruler_map (GtkWidget *widget) +{ + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (widget); + + GTK_WIDGET_CLASS (sp_ruler_parent_class)->map (widget); + + if (priv->input_window) + gdk_window_show (priv->input_window); +} + +static void +sp_ruler_unmap (GtkWidget *widget) +{ + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (widget); + + if (priv->input_window) + gdk_window_hide (priv->input_window); + + GTK_WIDGET_CLASS (sp_ruler_parent_class)->unmap (widget); +} + +static void +sp_ruler_size_allocate (GtkWidget *widget, + GtkAllocation *allocation) +{ + SPRuler *ruler = SP_RULER(widget); + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); + GtkAllocation widget_allocation; + gboolean resized; + + gtk_widget_get_allocation (widget, &widget_allocation); + + resized = (widget_allocation.width != allocation->width || + widget_allocation.height != allocation->height); + + gtk_widget_set_allocation(widget, allocation); + + if (gtk_widget_get_realized (widget)) + { + gdk_window_move_resize (priv->input_window, + allocation->x, allocation->y, + allocation->width, allocation->height); + + if (resized) + sp_ruler_make_pixmap (ruler); + } +} + +static void +sp_ruler_size_request (GtkWidget *widget, + GtkRequisition *requisition) +{ + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (widget); + PangoLayout *layout; + PangoRectangle ink_rect; + gint size; + + layout = sp_ruler_get_layout (widget, "0123456789"); + pango_layout_get_pixel_extents (layout, &ink_rect, NULL); + + size = 2 + ink_rect.height * 1.7; + + GtkStyleContext *context = gtk_widget_get_style_context (widget); + GtkBorder border; + + gtk_style_context_get_border (context, static_cast(0), &border); + + requisition->width = border.left + border.right; + requisition->height = border.top + border.bottom; + + if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) + { + requisition->width += 1; + requisition->height += size; + } + else + { + requisition->width += size; + requisition->height += 1; + } +} + +static void +sp_ruler_style_updated (GtkWidget *widget) +{ + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (widget); + + GTK_WIDGET_CLASS (sp_ruler_parent_class)->style_updated (widget); + + gtk_widget_style_get (widget, + "font-scale", &priv->font_scale, + NULL); + + if (priv->layout) + { + g_object_unref (priv->layout); + priv->layout = NULL; + } +} + +static void +sp_ruler_get_preferred_width (GtkWidget *widget, + gint *minimum_width, + gint *natural_width) +{ + GtkRequisition requisition; + + sp_ruler_size_request (widget, &requisition); + + *minimum_width = *natural_width = requisition.width; +} + +static void +sp_ruler_get_preferred_height (GtkWidget *widget, + gint *minimum_height, + gint *natural_height) +{ + GtkRequisition requisition; + + sp_ruler_size_request(widget, &requisition); + + *minimum_height = *natural_height = requisition.height; +} + +static gboolean +sp_ruler_draw (GtkWidget *widget, + cairo_t *cr) +{ + SPRuler *ruler = SP_RULER (widget); + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); + GtkStyleContext *context = gtk_widget_get_style_context (widget); + GtkAllocation allocation; + + gtk_widget_get_allocation (widget, &allocation); + gtk_render_background (context, cr, 0, 0, allocation.width, allocation.height); + gtk_render_frame (context, cr, 0, 0, allocation.width, allocation.height); + + sp_ruler_draw_ticks (ruler); + + cairo_set_source_surface(cr, priv->backing_store, 0, 0); + cairo_paint(cr); + + sp_ruler_draw_pos (ruler, cr); + + return FALSE; +} + +static void +sp_ruler_make_pixmap (SPRuler *ruler) +{ + GtkWidget *widget = GTK_WIDGET (ruler); + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); + GtkAllocation allocation; + + gtk_widget_get_allocation(widget, &allocation); + + if (priv->backing_store) + cairo_surface_destroy (priv->backing_store); + + priv->backing_store = + gdk_window_create_similar_surface (gtk_widget_get_window (widget), + CAIRO_CONTENT_COLOR_ALPHA, + allocation.width, + allocation.height); + + priv->backing_store_valid = FALSE; +} + +static void +sp_ruler_draw_pos (SPRuler *ruler, + cairo_t *cr) +{ + GtkWidget *widget = GTK_WIDGET (ruler); + + GtkStyleContext *context = gtk_widget_get_style_context (widget); + GdkRGBA color; + + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); + GdkRectangle pos_rect; + + if (! gtk_widget_is_drawable (widget)) + return; + + pos_rect = sp_ruler_get_pos_rect (ruler, sp_ruler_get_position (ruler)); + + if ((pos_rect.width > 0) && (pos_rect.height > 0)) + { + gtk_style_context_get_color (context, gtk_widget_get_state_flags (widget), + &color); + gdk_cairo_set_source_rgba (cr, &color); + + cairo_move_to (cr, pos_rect.x, pos_rect.y); + + if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) + { + cairo_line_to (cr, pos_rect.x + pos_rect.width / 2.0, + pos_rect.y + pos_rect.height); + cairo_line_to (cr, pos_rect.x + pos_rect.width, + pos_rect.y); + } + else + { + cairo_line_to (cr, pos_rect.x + pos_rect.width, + + pos_rect.y + pos_rect.height / 2.0); + cairo_line_to (cr, pos_rect.x, + pos_rect.y + pos_rect.height); + } + + cairo_fill (cr); + } + + priv->last_pos_rect = pos_rect; +} + +/** + * sp_ruler_new: + * @orientation: the ruler's orientation + * + * Creates a new ruler. + * + * Return value: a new #SPRuler widget. + */ +GtkWidget * +sp_ruler_new (GtkOrientation orientation) +{ + return GTK_WIDGET (g_object_new (SP_TYPE_RULER, + "orientation", orientation, + NULL)); +} + +static void +sp_ruler_update_position (SPRuler *ruler, + gdouble x, + gdouble y) +{ + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); + GtkAllocation allocation; + gdouble lower; + gdouble upper; + + gtk_widget_get_allocation (GTK_WIDGET (ruler), &allocation); + sp_ruler_get_range (ruler, &lower, &upper, NULL); + + if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) + { + sp_ruler_set_position (ruler, + lower + + (upper - lower) * x / allocation.width); + } + else + { + sp_ruler_set_position (ruler, + lower + + (upper - lower) * y / allocation.height); + } +} + +/* Returns TRUE if a translation should be done */ +static gboolean +gtk_widget_get_translation_to_window (GtkWidget *widget, + GdkWindow *window, + int *x, + int *y) +{ + GdkWindow *w, *widget_window; + + if (! gtk_widget_get_has_window (widget)) + { + GtkAllocation allocation; + + gtk_widget_get_allocation (widget, &allocation); + + *x = -allocation.x; + *y = -allocation.y; + } + else + { + *x = 0; + *y = 0; + } + + widget_window = gtk_widget_get_window (widget); + + for (w = window; + w && w != widget_window; + w = gdk_window_get_effective_parent (w)) + { + gdouble px, py; + + gdk_window_coords_to_parent (w, *x, *y, &px, &py); + + *x += px; + *y += px; + } + + if (w == NULL) + { + *x = 0; + *y = 0; + return FALSE; + } + + return TRUE; +} + +static void +sp_ruler_event_to_widget_coords (GtkWidget *widget, + GdkWindow *window, + gdouble event_x, + gdouble event_y, + gint *widget_x, + gint *widget_y) +{ + gint tx, ty; + + if (gtk_widget_get_translation_to_window (widget, window, &tx, &ty)) + { + event_x += tx; + event_y += ty; + } + + *widget_x = event_x; + *widget_y = event_y; +} + +static gboolean +sp_ruler_track_widget_motion_notify (GtkWidget *widget, + GdkEventMotion *mevent, + SPRuler *ruler) +{ + gint widget_x; + gint widget_y; + gint ruler_x; + gint ruler_y; + + widget = gtk_get_event_widget (reinterpret_cast(mevent)); + + sp_ruler_event_to_widget_coords (widget, mevent->window, + mevent->x, mevent->y, + &widget_x, &widget_y); + + if (gtk_widget_translate_coordinates (widget, GTK_WIDGET (ruler), + widget_x, widget_y, + &ruler_x, &ruler_y)) + { + sp_ruler_update_position (ruler, ruler_x, ruler_y); + } + + return FALSE; +} + +void +sp_ruler_add_track_widget (SPRuler *ruler, + GtkWidget *widget) +{ + SPRulerPrivate *priv; + + g_return_if_fail (SP_IS_RULER (ruler)); + g_return_if_fail (GTK_IS_WIDGET (ruler)); + + priv = SP_RULER_GET_PRIVATE (ruler); + + g_return_if_fail (g_list_find (priv->track_widgets, widget) == NULL); + + priv->track_widgets = g_list_prepend (priv->track_widgets, widget); + + g_signal_connect (widget, "motion-notify-event", + G_CALLBACK (sp_ruler_track_widget_motion_notify), + ruler); + g_signal_connect (widget, "destroy", + G_CALLBACK (sp_ruler_remove_track_widget), + ruler); +} + +/** + * sp_ruler_remove_track_widget: + * @ruler: an #SPRuler + * @widget: the track widget to remove + * + * Removes a previously added track widget from the ruler. See + * sp_ruler_add_track_widget(). + */ +void +sp_ruler_remove_track_widget (SPRuler *ruler, + GtkWidget *widget) +{ + SPRulerPrivate *priv; + + g_return_if_fail (SP_IS_RULER (ruler)); + g_return_if_fail (GTK_IS_WIDGET (ruler)); + + priv = SP_RULER_GET_PRIVATE (ruler); + + g_return_if_fail (g_list_find (priv->track_widgets, widget) != NULL); + + priv->track_widgets = g_list_remove (priv->track_widgets, widget); + + g_signal_handlers_disconnect_by_func (widget, + (gpointer) G_CALLBACK (sp_ruler_track_widget_motion_notify), + ruler); + g_signal_handlers_disconnect_by_func (widget, + (gpointer) G_CALLBACK (sp_ruler_remove_track_widget), + ruler); +} + +/** + * sp_ruler_set_unit: + * @ruler: a #SPRuler + * @unit: the #SPMetric to set the ruler to + * + * This sets the unit of the ruler. + */ +void +sp_ruler_set_unit (SPRuler *ruler, + Inkscape::Util::Unit const *unit) +{ + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); + + g_return_if_fail (SP_IS_RULER (ruler)); + + if (*priv->unit != *unit) + { + priv->unit = unit; + g_object_notify(G_OBJECT(ruler), "unit"); + + priv->backing_store_valid = FALSE; + gtk_widget_queue_draw (GTK_WIDGET (ruler)); + } +} + +/** + * sp_ruler_get_unit: + * @ruler: a #SPRuler + * + * Return value: the unit currently used in the @ruler widget. + **/ +Inkscape::Util::Unit const* +sp_ruler_get_unit (SPRuler *ruler) +{ + return SP_RULER_GET_PRIVATE (ruler)->unit; +} + +/** + * sp_ruler_set_position: + * @ruler: a #SPRuler + * @position: the position to set the ruler to + * + * This sets the position of the ruler. + */ +void +sp_ruler_set_position (SPRuler *ruler, + gdouble position) +{ + SPRulerPrivate *priv; + + g_return_if_fail (SP_IS_RULER (ruler)); + + priv = SP_RULER_GET_PRIVATE (ruler); + + if (priv->position != position) + { + GdkRectangle rect; + gint xdiff, ydiff; + + priv->position = position; + g_object_notify (G_OBJECT (ruler), "position"); + + rect = sp_ruler_get_pos_rect (ruler, priv->position); + + xdiff = rect.x - priv->last_pos_rect.x; + ydiff = rect.y - priv->last_pos_rect.y; + + /* + * If the position has changed far enough, queue a redraw immediately. + * Otherwise, we only queue a redraw in a low priority idle handler, to + * allow for other things (like updating the canvas) to run. + * + * TODO: This might not be necessary any more in GTK3 with the frame + * clock. Investigate this more after the port to GTK3. + */ + if (priv->last_pos_rect.width != 0 && + priv->last_pos_rect.height != 0 && + (ABS (xdiff) > IMMEDIATE_REDRAW_THRESHOLD || + ABS (ydiff) > IMMEDIATE_REDRAW_THRESHOLD)) + { + sp_ruler_queue_pos_redraw (ruler); + } + else if (! priv->pos_redraw_idle_id) + { + priv->pos_redraw_idle_id = + g_idle_add_full (G_PRIORITY_LOW, + sp_ruler_idle_queue_pos_redraw, + ruler, NULL); + } + } +} + +/** + * sp_ruler_get_position: + * @ruler: a #SPRuler + * + * Return value: the current position of the @ruler widget. + */ +gdouble +sp_ruler_get_position (SPRuler *ruler) +{ + g_return_val_if_fail (SP_IS_RULER (ruler), 0.0); + + return SP_RULER_GET_PRIVATE (ruler)->position; +} + +static gboolean +sp_ruler_motion_notify (GtkWidget *widget, + GdkEventMotion *event) +{ + SPRuler *ruler = SP_RULER(widget); + + sp_ruler_update_position (ruler, event->x, event->y); + + return FALSE; +} + +static void +sp_ruler_draw_ticks (SPRuler *ruler) +{ + GtkWidget *widget = GTK_WIDGET (ruler); + + GtkStyleContext *context = gtk_widget_get_style_context (widget); + GtkBorder border; + GdkRGBA color; + + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); + GtkAllocation allocation; + cairo_t *cr; + gint i; + gint width, height; + gint length, ideal_length; + gdouble lower, upper; /* Upper and lower limits, in ruler units */ + gdouble increment; /* Number of pixels per unit */ + guint scale; /* Number of units per major unit */ + gdouble start, end, cur; + gchar unit_str[32]; + gint digit_height; + gint digit_offset; + gchar digit_str[2] = { '\0', '\0' }; + gint text_size; + gint pos; + gdouble max_size; + Inkscape::Util::Unit const *unit = NULL; + SPRulerMetric ruler_metric = ruler_metric_general; /* The metric to use for this unit system */ + PangoLayout *layout; + PangoRectangle logical_rect, ink_rect; + + if (! gtk_widget_is_drawable (widget)) + return; + + gtk_widget_get_allocation (widget, &allocation); + + gtk_style_context_get_border (context, static_cast(0), &border); + + layout = sp_ruler_get_layout (widget, "0123456789"); + pango_layout_get_extents (layout, &ink_rect, &logical_rect); + + digit_height = PANGO_PIXELS (ink_rect.height) + 2; + digit_offset = ink_rect.y; + + if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) + { + width = allocation.width; + height = allocation.height - (border.top + border.bottom); + } + else + { + width = allocation.height; + height = allocation.width - (border.top + border.bottom); + } + + cr = cairo_create (priv->backing_store); + + cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); + cairo_paint (cr); + cairo_set_operator (cr, CAIRO_OPERATOR_OVER); + + gtk_style_context_get_color (context, gtk_widget_get_state_flags (widget), + &color); + gdk_cairo_set_source_rgba (cr, &color); + + if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) + { + cairo_rectangle (cr, + border.left, + height + border.top, + allocation.width - (border.left + border.right), + 1); + } + else + { + cairo_rectangle (cr, + height + border.left, + border.top, + 1, + allocation.height - (border.top + border.bottom)); + } + + sp_ruler_get_range (ruler, &lower, &upper, &max_size); + + if ((upper - lower) == 0) + goto out; + + increment = (gdouble) width / (upper - lower); + + /* determine the scale + * Use the maximum extents of the ruler to determine the largest + * possible number to be displayed. Calculate the height in pixels + * of this displayed text. Use this height to find a scale which + * leaves sufficient room for drawing the ruler. + * + * We calculate the text size as for the vruler instead of + * actually measuring the text width, so that the result for the + * scale looks consistent with an accompanying vruler + */ + scale = ceil (priv->max_size); + sprintf (unit_str, "%d", scale); + text_size = strlen (unit_str) * digit_height + 1; + + /* Inkscape change to ruler: Use a 1,2,4,8... scale for inches + * or a 1,2,5,10... scale for everything else */ + if (*sp_ruler_get_unit (ruler) == *unit_table.getUnit("in")) + ruler_metric = ruler_metric_inches; + + for (scale = 0; scale < G_N_ELEMENTS (ruler_metric.ruler_scale); scale++) + if (ruler_metric.ruler_scale[scale] * fabs (increment) > 2 * text_size) + break; + + if (scale == G_N_ELEMENTS (ruler_metric.ruler_scale)) + scale = G_N_ELEMENTS (ruler_metric.ruler_scale) - 1; + + unit = sp_ruler_get_unit (ruler); + + /* drawing starts here */ + length = 0; + for (i = G_N_ELEMENTS (ruler_metric.subdivide) - 1; i >= 0; i--) + { + gdouble subd_incr; + + /* hack to get proper subdivisions at full pixels */ + if (*unit == *unit_table.getUnit("px") && scale == 1 && i == 1) + subd_incr = 1.0; + else + subd_incr = ((gdouble) ruler_metric.ruler_scale[scale] / + (gdouble) ruler_metric.subdivide[i]); + + if (subd_incr * fabs (increment) <= MINIMUM_INCR) + continue; + + /* Calculate the length of the tickmarks. Make sure that + * this length increases for each set of ticks + */ + ideal_length = height / (i + 1) - 1; + if (ideal_length > ++length) + length = ideal_length; + + if (lower < upper) + { + start = floor (lower / subd_incr) * subd_incr; + end = ceil (upper / subd_incr) * subd_incr; + } + else + { + start = floor (upper / subd_incr) * subd_incr; + end = ceil (lower / subd_incr) * subd_incr; + } + + gint tick_index = 0; + + for (cur = start; cur <= end; cur += subd_incr) + { + // due to the typical values for cur, lower and increment, pos will often end up to + // be e.g. 641.50000000000; rounding behaviour is not defined in such a case (see round.h) + // and jitter will be apparent (upon redrawing some of the lines on the ruler might jump a + // by a pixel, and jump back on the next redraw). This is suppressed by adding 1e-9 (that's only one nanopixel ;-)) + pos = gint(Inkscape::round((cur - lower) * increment + 1e-12)); + + if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) + { + cairo_rectangle (cr, + pos, height + border.top - length, + 1, length); + } + else + { + cairo_rectangle (cr, + height + border.left - length, pos, + length, 1); + } + + /* draw label */ + double label_spacing_px = fabs(increment*(double)ruler_metric.ruler_scale[scale]/ruler_metric.subdivide[i]); + if (i == 0 && + (label_spacing_px > 6*digit_height || tick_index%2 == 0 || cur == 0) && + (label_spacing_px > 3*digit_height || tick_index%4 == 0 || cur == 0)) + { + if (std::abs((int)cur) >= 2000 && (((int) cur)/1000)*1000 == ((int) cur)) + sprintf (unit_str, "%dk", ((int) cur)/1000); + else + sprintf (unit_str, "%d", (int) cur); + + if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) + { + pango_layout_set_text (layout, unit_str, -1); + pango_layout_get_extents (layout, &logical_rect, NULL); + + cairo_move_to (cr, + pos + 2, + border.top + PANGO_PIXELS (logical_rect.y - digit_offset)); + + pango_cairo_show_layout(cr, layout); + } + else + { + gint j; + + for (j = 0; j < (int) strlen (unit_str); j++) + { + digit_str[0] = unit_str[j]; + pango_layout_set_text (layout, digit_str, 1); + pango_layout_get_extents (layout, NULL, &logical_rect); + + cairo_move_to (cr, + border.left + 1, + pos + digit_height * j + 2 + PANGO_PIXELS (logical_rect.y - digit_offset)); + pango_cairo_show_layout (cr, layout); + } + } + } + + ++tick_index; + } + } + + cairo_fill (cr); + + priv->backing_store_valid = TRUE; + +out: + cairo_destroy (cr); +} + +static GdkRectangle +sp_ruler_get_pos_rect (SPRuler *ruler, + gdouble position) +{ + GtkWidget *widget = GTK_WIDGET (ruler); + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); + GtkAllocation allocation; + gint width, height; + gint xthickness; + gint ythickness; + gdouble upper, lower; + gdouble increment; + GdkRectangle rect = { 0, 0, 0, 0 }; + + if (! gtk_widget_is_drawable (widget)) + return rect; + + gtk_widget_get_allocation (widget, &allocation); + + GtkStyleContext *context = gtk_widget_get_style_context (widget); + GtkBorder padding; + + gtk_style_context_get_border(context, static_cast(0), &padding); + + xthickness = padding.left + padding.right; + ythickness = padding.top + padding.bottom; + + if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) + { + width = allocation.width; + height = allocation.height - ythickness * 2; + + rect.width = height / 2 + 2; + rect.width |= 1; /* make sure it's odd */ + rect.height = rect.width / 2 + 1; + } + else + { + width = allocation.width - xthickness * 2; + height = allocation.height; + + rect.height = width / 2 + 2; + rect.height |= 1; /* make sure it's odd */ + rect.width = rect.height / 2 + 1; + } + + sp_ruler_get_range (ruler, &lower, &upper, NULL); + + if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) + { + increment = (gdouble) width / (upper - lower); + + rect.x = ROUND ((position - lower) * increment) + (xthickness - rect.width) / 2 - 1; + rect.y = (height + rect.height) / 2 + ythickness; + } + else + { + increment = (gdouble) height / (upper - lower); + + rect.x = (width + rect.width) / 2 + xthickness; + rect.y = ROUND ((position - lower) * increment) + (ythickness - rect.height) / 2 - 1; + } + + return rect; +} + +static gboolean +sp_ruler_idle_queue_pos_redraw (gpointer data) +{ + SPRuler *ruler = (SPRuler *)data; + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); + + sp_ruler_queue_pos_redraw (ruler); + + gboolean ret = g_source_remove(priv->pos_redraw_idle_id); + priv->pos_redraw_idle_id = 0; + + return ret; +} + +static void +sp_ruler_queue_pos_redraw (SPRuler *ruler) +{ + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); + const GdkRectangle rect = sp_ruler_get_pos_rect (ruler, priv->position); + GtkAllocation allocation; + + gtk_widget_get_allocation (GTK_WIDGET(ruler), &allocation); + + gtk_widget_queue_draw_area (GTK_WIDGET(ruler), + rect.x + allocation.x, + rect.y + allocation.y, + rect.width, + rect.height); + + if (priv->last_pos_rect.width != 0 || priv->last_pos_rect.height != 0) + { + gtk_widget_queue_draw_area (GTK_WIDGET(ruler), + priv->last_pos_rect.x + allocation.x, + priv->last_pos_rect.y + allocation.y, + priv->last_pos_rect.width, + priv->last_pos_rect.height); + + priv->last_pos_rect.x = 0; + priv->last_pos_rect.y = 0; + priv->last_pos_rect.width = 0; + priv->last_pos_rect.height = 0; + } +} + +static PangoLayout* +sp_ruler_create_layout (GtkWidget *widget, + const gchar *text) +{ + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (widget); + PangoLayout *layout; + PangoAttrList *attrs; + PangoAttribute *attr; + + layout = gtk_widget_create_pango_layout (widget, text); + + attrs = pango_attr_list_new (); + + attr = pango_attr_scale_new (priv->font_scale); + attr->start_index = 0; + attr->end_index = -1; + pango_attr_list_insert (attrs, attr); + + pango_layout_set_attributes (layout, attrs); + pango_attr_list_unref (attrs); + + return layout; +} + +static PangoLayout * +sp_ruler_get_layout (GtkWidget *widget, + const gchar *text) +{ + SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (widget); + + if (priv->layout) + { + pango_layout_set_text (priv->layout, text, -1); + return priv->layout; + } + + priv->layout = sp_ruler_create_layout (widget, text); + + return priv->layout; +} + +/* + 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/widgets/gimp/ruler.h b/src/widgets/gimp/ruler.h new file mode 100644 index 000000000..ed529d082 --- /dev/null +++ b/src/widgets/gimp/ruler.h @@ -0,0 +1,86 @@ +#ifndef __SP_RULER_H__ +#define __SP_RULER_H__ + +/* + * Customized ruler class for inkscape + * + * Authors: + * Lauris Kaplinski + * Frank Felfe + * + * Copyright (C) 1999-2002 authors + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include +#include +#include + +namespace Inkscape { + namespace Util { + class Unit; + } +} + +G_BEGIN_DECLS + +#define SP_TYPE_RULER (sp_ruler_get_type ()) +#define SP_RULER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SP_TYPE_RULER, SPRuler)) +#define SP_RULER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SP_TYPE_RULER, SPRulerClass)) +#define SP_IS_RULER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SP_TYPE_RULER)) +#define SP_IS_RULER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SP_TYPE_RULER)) +#define SP_RULER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SP_TYPE_RULER, SPRulerClass)) + +typedef struct _SPRuler SPRuler; +typedef struct _SPRulerClass SPRulerClass; + +struct _SPRuler +{ + GtkWidget parent_instance; +}; + +struct _SPRulerClass +{ + GtkWidgetClass parent_class; +}; + + +GType sp_ruler_get_type (void) G_GNUC_CONST; + +GtkWidget* sp_ruler_new (GtkOrientation orientation); + +void sp_ruler_add_track_widget (SPRuler *ruler, + GtkWidget *widget); +void sp_ruler_remove_track_widget (SPRuler *ruler, + GtkWidget *widget); + +void sp_ruler_set_unit (SPRuler *ruler, + const Inkscape::Util::Unit *unit); +Inkscape::Util::Unit const * sp_ruler_get_unit (SPRuler *ruler); +void sp_ruler_set_position (SPRuler *ruler, + gdouble set_position); +gdouble sp_ruler_get_position (SPRuler *ruler); +void sp_ruler_set_range (SPRuler *ruler, + gdouble lower, + gdouble upper, + gdouble max_size); +void sp_ruler_get_range (SPRuler *ruler, + gdouble *lower, + gdouble *upper, + gdouble *max_size); + +G_END_DECLS + +#endif /* __SP_RULER_H__ */ + +/* + 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/widgets/ruler.cpp b/src/widgets/ruler.cpp deleted file mode 100644 index bfb9c9071..000000000 --- a/src/widgets/ruler.cpp +++ /dev/null @@ -1,1425 +0,0 @@ -/* - * Customized ruler class for inkscape. Note that this is a fork of - * the GimpRuler widget from GIMP: libgimpwidgets/gimpruler.c. - * The GIMP code is released under the GPL 3. The GIMP code itself - * is a fork of the now-obsolete GtkRuler widget from GTK+ 2. - * - * Major differences between implementations in Inkscape and GIMP are - * as follows: - * - We use a 1,2,4,8... scale for inches and 1,2,5,10... for everything - * else. GIMP uses 1,2,5,10... for everything. - * - * - We use a default font size of PANGO_SCALE_X_SMALL for labels, - * GIMP uses PANGO_SCALE_SMALL (i.e., a bit larger than ours). - * - * - We abbreviate large numbers in tick-labels (e.g., 10000 -> 10k) - * - * Authors: - * Lauris Kaplinski - * Frank Felfe - * bulia byak - * Diederik van Lierop - * Jon A. Cruz - * Alex Valavanis - * - * Copyright (C) 1999-2011 authors - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include -#include -#include - -#include "ruler.h" -#include "round.h" -#include -#include "util/units.h" - -#define ROUND(x) ((int) ((x) + 0.5)) - -#define GTK_PARAM_READWRITE G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB - -#define DEFAULT_RULER_FONT_SCALE PANGO_SCALE_X_SMALL -#define MINIMUM_INCR 5 -#define IMMEDIATE_REDRAW_THRESHOLD 20 - -using Inkscape::Util::unit_table; - -enum { - PROP_0, - PROP_ORIENTATION, - PROP_UNIT, - PROP_LOWER, - PROP_UPPER, - PROP_POSITION, - PROP_MAX_SIZE -}; - - -/* All distances below are in 1/72nd's of an inch. (According to - * Adobe, that's a point, but points are really 1/72.27 in.) - */ -typedef struct -{ - GtkOrientation orientation; - Inkscape::Util::Unit const *unit; - gdouble lower; - gdouble upper; - gdouble position; - gdouble max_size; - - GdkWindow *input_window; - cairo_surface_t *backing_store; - gboolean backing_store_valid; - GdkRectangle last_pos_rect; - guint pos_redraw_idle_id; - PangoLayout *layout; - gdouble font_scale; - - GList *track_widgets; -} SPRulerPrivate; - -#define SP_RULER_GET_PRIVATE(ruler) \ - G_TYPE_INSTANCE_GET_PRIVATE (ruler, SP_TYPE_RULER, SPRulerPrivate) - - -struct SPRulerMetric -{ - gdouble ruler_scale[16]; - gint subdivide[5]; -}; - -// Ruler metric for general use. -static SPRulerMetric const ruler_metric_general = { - { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000, 10000, 25000, 50000, 100000 }, - { 1, 5, 10, 50, 100 } -}; - -// Ruler metric for inch scales. -static SPRulerMetric const ruler_metric_inches = { - { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 }, - { 1, 2, 4, 8, 16 } -}; - -static void sp_ruler_dispose (GObject *object); -static void sp_ruler_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec); -static void sp_ruler_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec); - -static void sp_ruler_realize (GtkWidget *widget); -static void sp_ruler_unrealize (GtkWidget *widget); -static void sp_ruler_map (GtkWidget *widget); -static void sp_ruler_unmap (GtkWidget *widget); -static void sp_ruler_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); - -static void sp_ruler_get_preferred_width (GtkWidget *widget, - gint *minimum_width, - gint *natural_width); - -static void sp_ruler_get_preferred_height (GtkWidget *widget, - gint *minimum_height, - gint *natural_height); -static void sp_ruler_style_updated (GtkWidget *widget); - -static gboolean sp_ruler_motion_notify (GtkWidget *widget, - GdkEventMotion *event); -static gboolean sp_ruler_draw (GtkWidget *widget, - cairo_t *cr); -static void sp_ruler_draw_ticks (SPRuler *ruler); -static GdkRectangle sp_ruler_get_pos_rect (SPRuler *ruler, - gdouble position); -static gboolean sp_ruler_idle_queue_pos_redraw(gpointer data); -static void sp_ruler_queue_pos_redraw (SPRuler *ruler); -static void sp_ruler_draw_pos (SPRuler *ruler, - cairo_t *cr); -static void sp_ruler_make_pixmap (SPRuler *ruler); - -static PangoLayout * sp_ruler_get_layout (GtkWidget *widget, - const gchar *text); - - -G_DEFINE_TYPE (SPRuler, sp_ruler, GTK_TYPE_WIDGET) - -#define parent_class sp_ruler_parent_class - - -static void -sp_ruler_class_init (SPRulerClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - -#if GTK_CHECK_VERSION(3,20,0) - gtk_widget_class_set_css_name (widget_class, "ruler-widget"); -#endif - - object_class->dispose = sp_ruler_dispose; - object_class->set_property = sp_ruler_set_property; - object_class->get_property = sp_ruler_get_property; - - widget_class->realize = sp_ruler_realize; - widget_class->unrealize = sp_ruler_unrealize; - widget_class->map = sp_ruler_map; - widget_class->unmap = sp_ruler_unmap; - widget_class->size_allocate = sp_ruler_size_allocate; - widget_class->get_preferred_width = sp_ruler_get_preferred_width; - widget_class->get_preferred_height = sp_ruler_get_preferred_height; - widget_class->style_updated = sp_ruler_style_updated; - widget_class->draw = sp_ruler_draw; - widget_class->motion_notify_event = sp_ruler_motion_notify; - - g_type_class_add_private (object_class, sizeof (SPRulerPrivate)); - - g_object_class_install_property (object_class, - PROP_ORIENTATION, - g_param_spec_enum ("orientation", - _("Orientation"), - _("The orientation of the ruler"), - GTK_TYPE_ORIENTATION, - GTK_ORIENTATION_HORIZONTAL, - static_cast(GTK_PARAM_READWRITE))); - - /* FIXME: Should probably use g_param_spec_enum */ - g_object_class_install_property (object_class, - PROP_UNIT, - g_param_spec_string ("unit", - _("Unit"), - _("Unit of the ruler"), - "px", - static_cast(GTK_PARAM_READWRITE))); - - g_object_class_install_property (object_class, - PROP_LOWER, - g_param_spec_double ("lower", - _("Lower"), - _("Lower limit of ruler"), - -G_MAXDOUBLE, - G_MAXDOUBLE, - 0.0, - static_cast(GTK_PARAM_READWRITE))); - - g_object_class_install_property (object_class, - PROP_UPPER, - g_param_spec_double ("upper", - _("Upper"), - _("Upper limit of ruler"), - -G_MAXDOUBLE, - G_MAXDOUBLE, - 0.0, - static_cast(GTK_PARAM_READWRITE))); - - g_object_class_install_property (object_class, - PROP_POSITION, - g_param_spec_double ("position", - _("Position"), - _("Position of mark on the ruler"), - -G_MAXDOUBLE, - G_MAXDOUBLE, - 0.0, - static_cast(GTK_PARAM_READWRITE))); - - g_object_class_install_property (object_class, - PROP_MAX_SIZE, - g_param_spec_double ("max-size", - _("Max Size"), - _("Maximum size of the ruler"), - -G_MAXDOUBLE, - G_MAXDOUBLE, - 0.0, - static_cast(GTK_PARAM_READWRITE))); - - gtk_widget_class_install_style_property (widget_class, - g_param_spec_double ("font-scale", - NULL, NULL, - 0.0, - G_MAXDOUBLE, - DEFAULT_RULER_FONT_SCALE, - G_PARAM_READABLE)); -} - -static void -sp_ruler_init (SPRuler *ruler) -{ - SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); - - gtk_widget_set_has_window (GTK_WIDGET (ruler), FALSE); - - priv->orientation = GTK_ORIENTATION_HORIZONTAL; - priv->unit = unit_table.getUnit("px"); - priv->lower = 0; - priv->upper = 0; - priv->position = 0; - priv->max_size = 0; - - priv->backing_store = NULL; - priv->backing_store_valid = FALSE; - - priv->last_pos_rect.x = 0; - priv->last_pos_rect.y = 0; - priv->last_pos_rect.width = 0; - priv->last_pos_rect.height = 0; - priv->pos_redraw_idle_id = 0; - - priv->font_scale = DEFAULT_RULER_FONT_SCALE; -} - -static void -sp_ruler_dispose (GObject *object) -{ - SPRuler *ruler = SP_RULER (object); - SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); - - while (priv->track_widgets) - sp_ruler_remove_track_widget (ruler, GTK_WIDGET(priv->track_widgets->data)); - - if (priv->pos_redraw_idle_id) - { - g_source_remove (priv->pos_redraw_idle_id); - priv->pos_redraw_idle_id = 0; - } - - G_OBJECT_CLASS (parent_class)->dispose (object); -} - - -/** - * sp_ruler_set_range: - * @ruler: the SPRuler - * @lower: the lower limit of the ruler - * @upper: the upper limit of the ruler - * @max_size: the maximum size of the ruler used when calculating the space to - * leave for the text - * - * This sets the range of the ruler. - */ -void -sp_ruler_set_range (SPRuler *ruler, - gdouble lower, - gdouble upper, - gdouble max_size) -{ - SPRulerPrivate *priv; - - g_return_if_fail (SP_IS_RULER (ruler)); - - priv = SP_RULER_GET_PRIVATE (ruler); - - g_object_freeze_notify (G_OBJECT (ruler)); - if (priv->lower != lower) - { - priv->lower = lower; - g_object_notify (G_OBJECT (ruler), "lower"); - } - if (priv->upper != upper) - { - priv->upper = upper; - g_object_notify (G_OBJECT (ruler), "upper"); - } - if (priv->max_size != max_size) - { - priv->max_size = max_size; - g_object_notify (G_OBJECT (ruler), "max-size"); - } - g_object_thaw_notify (G_OBJECT (ruler)); - - priv->backing_store_valid = FALSE; - gtk_widget_queue_draw (GTK_WIDGET (ruler)); -} - -/** - * sp_ruler_get_range: - * @ruler: a #SPRuler - * @lower: (allow-none): location to store lower limit of the ruler, or %NULL - * @upper: (allow-none): location to store upper limit of the ruler, or %NULL - * @max_size: location to store the maximum size of the ruler used when calculating - * the space to leave for the text, or %NULL. - * - * Retrieves values indicating the range and current position of a #SPRuler. - * See sp_ruler_set_range(). - **/ -void -sp_ruler_get_range (SPRuler *ruler, - gdouble *lower, - gdouble *upper, - gdouble *max_size) -{ - SPRulerPrivate *priv; - - g_return_if_fail (SP_IS_RULER (ruler)); - - priv = SP_RULER_GET_PRIVATE (ruler); - - if (lower) - *lower = priv->lower; - if (upper) - *upper = priv->upper; - if (max_size) - *max_size = priv->max_size; -} - -static void -sp_ruler_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - SPRuler *ruler = SP_RULER (object); - SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); - - switch (prop_id) - { - case PROP_ORIENTATION: - priv->orientation = static_cast(g_value_get_enum (value)); - gtk_widget_queue_resize (GTK_WIDGET (ruler)); - break; - - case PROP_UNIT: - sp_ruler_set_unit (ruler, unit_table.getUnit(g_value_get_string (value))); - break; - - case PROP_LOWER: - sp_ruler_set_range (ruler, - g_value_get_double (value), - priv->upper, - priv->max_size); - break; - case PROP_UPPER: - sp_ruler_set_range (ruler, - priv->lower, - g_value_get_double (value), - priv->max_size); - break; - - case PROP_POSITION: - sp_ruler_set_position (ruler, g_value_get_double (value)); - break; - - case PROP_MAX_SIZE: - sp_ruler_set_range (ruler, - priv->lower, - priv->upper, - g_value_get_double (value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -sp_ruler_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - SPRuler *ruler = SP_RULER (object); - SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); - - switch (prop_id) - { - case PROP_ORIENTATION: - g_value_set_enum (value, priv->orientation); - break; - - case PROP_UNIT: - g_value_set_string (value, priv->unit->abbr.c_str()); - break; - case PROP_LOWER: - g_value_set_double (value, priv->lower); - break; - case PROP_UPPER: - g_value_set_double (value, priv->upper); - break; - case PROP_POSITION: - g_value_set_double (value, priv->position); - break; - case PROP_MAX_SIZE: - g_value_set_double (value, priv->max_size); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -sp_ruler_realize (GtkWidget *widget) -{ - SPRuler *ruler = SP_RULER (widget); - SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); - GtkAllocation allocation; - GdkWindowAttr attributes; - gint attributes_mask; - - GTK_WIDGET_CLASS (sp_ruler_parent_class)->realize (widget); - - gtk_widget_get_allocation (widget, &allocation); - - attributes.window_type = GDK_WINDOW_CHILD; - attributes.x = allocation.x; - attributes.y = allocation.y; - attributes.width = allocation.width; - attributes.height = allocation.height; - attributes.wclass = GDK_INPUT_ONLY; - attributes.event_mask = (gtk_widget_get_events (widget) | - GDK_EXPOSURE_MASK | - GDK_POINTER_MOTION_MASK | - GDK_POINTER_MOTION_HINT_MASK); - - attributes_mask = GDK_WA_X | GDK_WA_Y; - - priv->input_window = gdk_window_new (gtk_widget_get_parent_window (widget), - &attributes, attributes_mask); - gdk_window_set_user_data (priv->input_window, ruler); - - sp_ruler_make_pixmap (ruler); -} - -static void -sp_ruler_unrealize(GtkWidget *widget) -{ - SPRuler *ruler = SP_RULER (widget); - SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); - - if (priv->backing_store) - { - cairo_surface_destroy (priv->backing_store); - priv->backing_store = NULL; - } - - priv->backing_store_valid = FALSE; - - if (priv->layout) - { - g_object_unref (priv->layout); - priv->layout = NULL; - } - - if (priv->input_window) - { - gdk_window_destroy (priv->input_window); - priv->input_window = NULL; - } - - GTK_WIDGET_CLASS (sp_ruler_parent_class)->unrealize (widget); -} - -static void -sp_ruler_map (GtkWidget *widget) -{ - SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (widget); - - GTK_WIDGET_CLASS (sp_ruler_parent_class)->map (widget); - - if (priv->input_window) - gdk_window_show (priv->input_window); -} - -static void -sp_ruler_unmap (GtkWidget *widget) -{ - SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (widget); - - if (priv->input_window) - gdk_window_hide (priv->input_window); - - GTK_WIDGET_CLASS (sp_ruler_parent_class)->unmap (widget); -} - -static void -sp_ruler_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) -{ - SPRuler *ruler = SP_RULER(widget); - SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); - GtkAllocation widget_allocation; - gboolean resized; - - gtk_widget_get_allocation (widget, &widget_allocation); - - resized = (widget_allocation.width != allocation->width || - widget_allocation.height != allocation->height); - - gtk_widget_set_allocation(widget, allocation); - - if (gtk_widget_get_realized (widget)) - { - gdk_window_move_resize (priv->input_window, - allocation->x, allocation->y, - allocation->width, allocation->height); - - if (resized) - sp_ruler_make_pixmap (ruler); - } -} - -static void -sp_ruler_size_request (GtkWidget *widget, - GtkRequisition *requisition) -{ - SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (widget); - PangoLayout *layout; - PangoRectangle ink_rect; - gint size; - - layout = sp_ruler_get_layout (widget, "0123456789"); - pango_layout_get_pixel_extents (layout, &ink_rect, NULL); - - size = 2 + ink_rect.height * 1.7; - - GtkStyleContext *context = gtk_widget_get_style_context (widget); - GtkBorder border; - - gtk_style_context_get_border (context, static_cast(0), &border); - - requisition->width = border.left + border.right; - requisition->height = border.top + border.bottom; - - if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) - { - requisition->width += 1; - requisition->height += size; - } - else - { - requisition->width += size; - requisition->height += 1; - } -} - -static void -sp_ruler_style_updated (GtkWidget *widget) -{ - SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (widget); - - GTK_WIDGET_CLASS (sp_ruler_parent_class)->style_updated (widget); - - gtk_widget_style_get (widget, - "font-scale", &priv->font_scale, - NULL); - - if (priv->layout) - { - g_object_unref (priv->layout); - priv->layout = NULL; - } -} - -static void -sp_ruler_get_preferred_width (GtkWidget *widget, - gint *minimum_width, - gint *natural_width) -{ - GtkRequisition requisition; - - sp_ruler_size_request (widget, &requisition); - - *minimum_width = *natural_width = requisition.width; -} - -static void -sp_ruler_get_preferred_height (GtkWidget *widget, - gint *minimum_height, - gint *natural_height) -{ - GtkRequisition requisition; - - sp_ruler_size_request(widget, &requisition); - - *minimum_height = *natural_height = requisition.height; -} - -static gboolean -sp_ruler_draw (GtkWidget *widget, - cairo_t *cr) -{ - SPRuler *ruler = SP_RULER (widget); - SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); - GtkStyleContext *context = gtk_widget_get_style_context (widget); - GtkAllocation allocation; - - gtk_widget_get_allocation (widget, &allocation); - gtk_render_background (context, cr, 0, 0, allocation.width, allocation.height); - gtk_render_frame (context, cr, 0, 0, allocation.width, allocation.height); - - sp_ruler_draw_ticks (ruler); - - cairo_set_source_surface(cr, priv->backing_store, 0, 0); - cairo_paint(cr); - - sp_ruler_draw_pos (ruler, cr); - - return FALSE; -} - -static void -sp_ruler_make_pixmap (SPRuler *ruler) -{ - GtkWidget *widget = GTK_WIDGET (ruler); - SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); - GtkAllocation allocation; - - gtk_widget_get_allocation(widget, &allocation); - - if (priv->backing_store) - cairo_surface_destroy (priv->backing_store); - - priv->backing_store = - gdk_window_create_similar_surface (gtk_widget_get_window (widget), - CAIRO_CONTENT_COLOR_ALPHA, - allocation.width, - allocation.height); - - priv->backing_store_valid = FALSE; -} - -static void -sp_ruler_draw_pos (SPRuler *ruler, - cairo_t *cr) -{ - GtkWidget *widget = GTK_WIDGET (ruler); - - GtkStyleContext *context = gtk_widget_get_style_context (widget); - GdkRGBA color; - - SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); - GdkRectangle pos_rect; - - if (! gtk_widget_is_drawable (widget)) - return; - - pos_rect = sp_ruler_get_pos_rect (ruler, sp_ruler_get_position (ruler)); - - if ((pos_rect.width > 0) && (pos_rect.height > 0)) - { - gtk_style_context_get_color (context, gtk_widget_get_state_flags (widget), - &color); - gdk_cairo_set_source_rgba (cr, &color); - - cairo_move_to (cr, pos_rect.x, pos_rect.y); - - if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) - { - cairo_line_to (cr, pos_rect.x + pos_rect.width / 2.0, - pos_rect.y + pos_rect.height); - cairo_line_to (cr, pos_rect.x + pos_rect.width, - pos_rect.y); - } - else - { - cairo_line_to (cr, pos_rect.x + pos_rect.width, - - pos_rect.y + pos_rect.height / 2.0); - cairo_line_to (cr, pos_rect.x, - pos_rect.y + pos_rect.height); - } - - cairo_fill (cr); - } - - priv->last_pos_rect = pos_rect; -} - -/** - * sp_ruler_new: - * @orientation: the ruler's orientation - * - * Creates a new ruler. - * - * Return value: a new #SPRuler widget. - */ -GtkWidget * -sp_ruler_new (GtkOrientation orientation) -{ - return GTK_WIDGET (g_object_new (SP_TYPE_RULER, - "orientation", orientation, - NULL)); -} - -static void -sp_ruler_update_position (SPRuler *ruler, - gdouble x, - gdouble y) -{ - SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); - GtkAllocation allocation; - gdouble lower; - gdouble upper; - - gtk_widget_get_allocation (GTK_WIDGET (ruler), &allocation); - sp_ruler_get_range (ruler, &lower, &upper, NULL); - - if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) - { - sp_ruler_set_position (ruler, - lower + - (upper - lower) * x / allocation.width); - } - else - { - sp_ruler_set_position (ruler, - lower + - (upper - lower) * y / allocation.height); - } -} - -/* Returns TRUE if a translation should be done */ -static gboolean -gtk_widget_get_translation_to_window (GtkWidget *widget, - GdkWindow *window, - int *x, - int *y) -{ - GdkWindow *w, *widget_window; - - if (! gtk_widget_get_has_window (widget)) - { - GtkAllocation allocation; - - gtk_widget_get_allocation (widget, &allocation); - - *x = -allocation.x; - *y = -allocation.y; - } - else - { - *x = 0; - *y = 0; - } - - widget_window = gtk_widget_get_window (widget); - - for (w = window; - w && w != widget_window; - w = gdk_window_get_effective_parent (w)) - { - gdouble px, py; - - gdk_window_coords_to_parent (w, *x, *y, &px, &py); - - *x += px; - *y += px; - } - - if (w == NULL) - { - *x = 0; - *y = 0; - return FALSE; - } - - return TRUE; -} - -static void -sp_ruler_event_to_widget_coords (GtkWidget *widget, - GdkWindow *window, - gdouble event_x, - gdouble event_y, - gint *widget_x, - gint *widget_y) -{ - gint tx, ty; - - if (gtk_widget_get_translation_to_window (widget, window, &tx, &ty)) - { - event_x += tx; - event_y += ty; - } - - *widget_x = event_x; - *widget_y = event_y; -} - -static gboolean -sp_ruler_track_widget_motion_notify (GtkWidget *widget, - GdkEventMotion *mevent, - SPRuler *ruler) -{ - gint widget_x; - gint widget_y; - gint ruler_x; - gint ruler_y; - - widget = gtk_get_event_widget (reinterpret_cast(mevent)); - - sp_ruler_event_to_widget_coords (widget, mevent->window, - mevent->x, mevent->y, - &widget_x, &widget_y); - - if (gtk_widget_translate_coordinates (widget, GTK_WIDGET (ruler), - widget_x, widget_y, - &ruler_x, &ruler_y)) - { - sp_ruler_update_position (ruler, ruler_x, ruler_y); - } - - return FALSE; -} - -void -sp_ruler_add_track_widget (SPRuler *ruler, - GtkWidget *widget) -{ - SPRulerPrivate *priv; - - g_return_if_fail (SP_IS_RULER (ruler)); - g_return_if_fail (GTK_IS_WIDGET (ruler)); - - priv = SP_RULER_GET_PRIVATE (ruler); - - g_return_if_fail (g_list_find (priv->track_widgets, widget) == NULL); - - priv->track_widgets = g_list_prepend (priv->track_widgets, widget); - - g_signal_connect (widget, "motion-notify-event", - G_CALLBACK (sp_ruler_track_widget_motion_notify), - ruler); - g_signal_connect (widget, "destroy", - G_CALLBACK (sp_ruler_remove_track_widget), - ruler); -} - -/** - * sp_ruler_remove_track_widget: - * @ruler: an #SPRuler - * @widget: the track widget to remove - * - * Removes a previously added track widget from the ruler. See - * sp_ruler_add_track_widget(). - */ -void -sp_ruler_remove_track_widget (SPRuler *ruler, - GtkWidget *widget) -{ - SPRulerPrivate *priv; - - g_return_if_fail (SP_IS_RULER (ruler)); - g_return_if_fail (GTK_IS_WIDGET (ruler)); - - priv = SP_RULER_GET_PRIVATE (ruler); - - g_return_if_fail (g_list_find (priv->track_widgets, widget) != NULL); - - priv->track_widgets = g_list_remove (priv->track_widgets, widget); - - g_signal_handlers_disconnect_by_func (widget, - (gpointer) G_CALLBACK (sp_ruler_track_widget_motion_notify), - ruler); - g_signal_handlers_disconnect_by_func (widget, - (gpointer) G_CALLBACK (sp_ruler_remove_track_widget), - ruler); -} - -/** - * sp_ruler_set_unit: - * @ruler: a #SPRuler - * @unit: the #SPMetric to set the ruler to - * - * This sets the unit of the ruler. - */ -void -sp_ruler_set_unit (SPRuler *ruler, - Inkscape::Util::Unit const *unit) -{ - SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); - - g_return_if_fail (SP_IS_RULER (ruler)); - - if (*priv->unit != *unit) - { - priv->unit = unit; - g_object_notify(G_OBJECT(ruler), "unit"); - - priv->backing_store_valid = FALSE; - gtk_widget_queue_draw (GTK_WIDGET (ruler)); - } -} - -/** - * sp_ruler_get_unit: - * @ruler: a #SPRuler - * - * Return value: the unit currently used in the @ruler widget. - **/ -Inkscape::Util::Unit const* -sp_ruler_get_unit (SPRuler *ruler) -{ - return SP_RULER_GET_PRIVATE (ruler)->unit; -} - -/** - * sp_ruler_set_position: - * @ruler: a #SPRuler - * @position: the position to set the ruler to - * - * This sets the position of the ruler. - */ -void -sp_ruler_set_position (SPRuler *ruler, - gdouble position) -{ - SPRulerPrivate *priv; - - g_return_if_fail (SP_IS_RULER (ruler)); - - priv = SP_RULER_GET_PRIVATE (ruler); - - if (priv->position != position) - { - GdkRectangle rect; - gint xdiff, ydiff; - - priv->position = position; - g_object_notify (G_OBJECT (ruler), "position"); - - rect = sp_ruler_get_pos_rect (ruler, priv->position); - - xdiff = rect.x - priv->last_pos_rect.x; - ydiff = rect.y - priv->last_pos_rect.y; - - /* - * If the position has changed far enough, queue a redraw immediately. - * Otherwise, we only queue a redraw in a low priority idle handler, to - * allow for other things (like updating the canvas) to run. - * - * TODO: This might not be necessary any more in GTK3 with the frame - * clock. Investigate this more after the port to GTK3. - */ - if (priv->last_pos_rect.width != 0 && - priv->last_pos_rect.height != 0 && - (ABS (xdiff) > IMMEDIATE_REDRAW_THRESHOLD || - ABS (ydiff) > IMMEDIATE_REDRAW_THRESHOLD)) - { - sp_ruler_queue_pos_redraw (ruler); - } - else if (! priv->pos_redraw_idle_id) - { - priv->pos_redraw_idle_id = - g_idle_add_full (G_PRIORITY_LOW, - sp_ruler_idle_queue_pos_redraw, - ruler, NULL); - } - } -} - -/** - * sp_ruler_get_position: - * @ruler: a #SPRuler - * - * Return value: the current position of the @ruler widget. - */ -gdouble -sp_ruler_get_position (SPRuler *ruler) -{ - g_return_val_if_fail (SP_IS_RULER (ruler), 0.0); - - return SP_RULER_GET_PRIVATE (ruler)->position; -} - -static gboolean -sp_ruler_motion_notify (GtkWidget *widget, - GdkEventMotion *event) -{ - SPRuler *ruler = SP_RULER(widget); - - sp_ruler_update_position (ruler, event->x, event->y); - - return FALSE; -} - -static void -sp_ruler_draw_ticks (SPRuler *ruler) -{ - GtkWidget *widget = GTK_WIDGET (ruler); - - GtkStyleContext *context = gtk_widget_get_style_context (widget); - GtkBorder border; - GdkRGBA color; - - SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); - GtkAllocation allocation; - cairo_t *cr; - gint i; - gint width, height; - gint length, ideal_length; - gdouble lower, upper; /* Upper and lower limits, in ruler units */ - gdouble increment; /* Number of pixels per unit */ - guint scale; /* Number of units per major unit */ - gdouble start, end, cur; - gchar unit_str[32]; - gint digit_height; - gint digit_offset; - gchar digit_str[2] = { '\0', '\0' }; - gint text_size; - gint pos; - gdouble max_size; - Inkscape::Util::Unit const *unit = NULL; - SPRulerMetric ruler_metric = ruler_metric_general; /* The metric to use for this unit system */ - PangoLayout *layout; - PangoRectangle logical_rect, ink_rect; - - if (! gtk_widget_is_drawable (widget)) - return; - - gtk_widget_get_allocation (widget, &allocation); - - gtk_style_context_get_border (context, static_cast(0), &border); - - layout = sp_ruler_get_layout (widget, "0123456789"); - pango_layout_get_extents (layout, &ink_rect, &logical_rect); - - digit_height = PANGO_PIXELS (ink_rect.height) + 2; - digit_offset = ink_rect.y; - - if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) - { - width = allocation.width; - height = allocation.height - (border.top + border.bottom); - } - else - { - width = allocation.height; - height = allocation.width - (border.top + border.bottom); - } - - cr = cairo_create (priv->backing_store); - - cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); - cairo_paint (cr); - cairo_set_operator (cr, CAIRO_OPERATOR_OVER); - - gtk_style_context_get_color (context, gtk_widget_get_state_flags (widget), - &color); - gdk_cairo_set_source_rgba (cr, &color); - - if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) - { - cairo_rectangle (cr, - border.left, - height + border.top, - allocation.width - (border.left + border.right), - 1); - } - else - { - cairo_rectangle (cr, - height + border.left, - border.top, - 1, - allocation.height - (border.top + border.bottom)); - } - - sp_ruler_get_range (ruler, &lower, &upper, &max_size); - - if ((upper - lower) == 0) - goto out; - - increment = (gdouble) width / (upper - lower); - - /* determine the scale - * Use the maximum extents of the ruler to determine the largest - * possible number to be displayed. Calculate the height in pixels - * of this displayed text. Use this height to find a scale which - * leaves sufficient room for drawing the ruler. - * - * We calculate the text size as for the vruler instead of - * actually measuring the text width, so that the result for the - * scale looks consistent with an accompanying vruler - */ - scale = ceil (priv->max_size); - sprintf (unit_str, "%d", scale); - text_size = strlen (unit_str) * digit_height + 1; - - /* Inkscape change to ruler: Use a 1,2,4,8... scale for inches - * or a 1,2,5,10... scale for everything else */ - if (*sp_ruler_get_unit (ruler) == *unit_table.getUnit("in")) - ruler_metric = ruler_metric_inches; - - for (scale = 0; scale < G_N_ELEMENTS (ruler_metric.ruler_scale); scale++) - if (ruler_metric.ruler_scale[scale] * fabs (increment) > 2 * text_size) - break; - - if (scale == G_N_ELEMENTS (ruler_metric.ruler_scale)) - scale = G_N_ELEMENTS (ruler_metric.ruler_scale) - 1; - - unit = sp_ruler_get_unit (ruler); - - /* drawing starts here */ - length = 0; - for (i = G_N_ELEMENTS (ruler_metric.subdivide) - 1; i >= 0; i--) - { - gdouble subd_incr; - - /* hack to get proper subdivisions at full pixels */ - if (*unit == *unit_table.getUnit("px") && scale == 1 && i == 1) - subd_incr = 1.0; - else - subd_incr = ((gdouble) ruler_metric.ruler_scale[scale] / - (gdouble) ruler_metric.subdivide[i]); - - if (subd_incr * fabs (increment) <= MINIMUM_INCR) - continue; - - /* Calculate the length of the tickmarks. Make sure that - * this length increases for each set of ticks - */ - ideal_length = height / (i + 1) - 1; - if (ideal_length > ++length) - length = ideal_length; - - if (lower < upper) - { - start = floor (lower / subd_incr) * subd_incr; - end = ceil (upper / subd_incr) * subd_incr; - } - else - { - start = floor (upper / subd_incr) * subd_incr; - end = ceil (lower / subd_incr) * subd_incr; - } - - gint tick_index = 0; - - for (cur = start; cur <= end; cur += subd_incr) - { - // due to the typical values for cur, lower and increment, pos will often end up to - // be e.g. 641.50000000000; rounding behaviour is not defined in such a case (see round.h) - // and jitter will be apparent (upon redrawing some of the lines on the ruler might jump a - // by a pixel, and jump back on the next redraw). This is suppressed by adding 1e-9 (that's only one nanopixel ;-)) - pos = gint(Inkscape::round((cur - lower) * increment + 1e-12)); - - if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) - { - cairo_rectangle (cr, - pos, height + border.top - length, - 1, length); - } - else - { - cairo_rectangle (cr, - height + border.left - length, pos, - length, 1); - } - - /* draw label */ - double label_spacing_px = fabs(increment*(double)ruler_metric.ruler_scale[scale]/ruler_metric.subdivide[i]); - if (i == 0 && - (label_spacing_px > 6*digit_height || tick_index%2 == 0 || cur == 0) && - (label_spacing_px > 3*digit_height || tick_index%4 == 0 || cur == 0)) - { - if (std::abs((int)cur) >= 2000 && (((int) cur)/1000)*1000 == ((int) cur)) - sprintf (unit_str, "%dk", ((int) cur)/1000); - else - sprintf (unit_str, "%d", (int) cur); - - if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) - { - pango_layout_set_text (layout, unit_str, -1); - pango_layout_get_extents (layout, &logical_rect, NULL); - - cairo_move_to (cr, - pos + 2, - border.top + PANGO_PIXELS (logical_rect.y - digit_offset)); - - pango_cairo_show_layout(cr, layout); - } - else - { - gint j; - - for (j = 0; j < (int) strlen (unit_str); j++) - { - digit_str[0] = unit_str[j]; - pango_layout_set_text (layout, digit_str, 1); - pango_layout_get_extents (layout, NULL, &logical_rect); - - cairo_move_to (cr, - border.left + 1, - pos + digit_height * j + 2 + PANGO_PIXELS (logical_rect.y - digit_offset)); - pango_cairo_show_layout (cr, layout); - } - } - } - - ++tick_index; - } - } - - cairo_fill (cr); - - priv->backing_store_valid = TRUE; - -out: - cairo_destroy (cr); -} - -static GdkRectangle -sp_ruler_get_pos_rect (SPRuler *ruler, - gdouble position) -{ - GtkWidget *widget = GTK_WIDGET (ruler); - SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); - GtkAllocation allocation; - gint width, height; - gint xthickness; - gint ythickness; - gdouble upper, lower; - gdouble increment; - GdkRectangle rect = { 0, 0, 0, 0 }; - - if (! gtk_widget_is_drawable (widget)) - return rect; - - gtk_widget_get_allocation (widget, &allocation); - - GtkStyleContext *context = gtk_widget_get_style_context (widget); - GtkBorder padding; - - gtk_style_context_get_border(context, static_cast(0), &padding); - - xthickness = padding.left + padding.right; - ythickness = padding.top + padding.bottom; - - if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) - { - width = allocation.width; - height = allocation.height - ythickness * 2; - - rect.width = height / 2 + 2; - rect.width |= 1; /* make sure it's odd */ - rect.height = rect.width / 2 + 1; - } - else - { - width = allocation.width - xthickness * 2; - height = allocation.height; - - rect.height = width / 2 + 2; - rect.height |= 1; /* make sure it's odd */ - rect.width = rect.height / 2 + 1; - } - - sp_ruler_get_range (ruler, &lower, &upper, NULL); - - if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) - { - increment = (gdouble) width / (upper - lower); - - rect.x = ROUND ((position - lower) * increment) + (xthickness - rect.width) / 2 - 1; - rect.y = (height + rect.height) / 2 + ythickness; - } - else - { - increment = (gdouble) height / (upper - lower); - - rect.x = (width + rect.width) / 2 + xthickness; - rect.y = ROUND ((position - lower) * increment) + (ythickness - rect.height) / 2 - 1; - } - - return rect; -} - -static gboolean -sp_ruler_idle_queue_pos_redraw (gpointer data) -{ - SPRuler *ruler = (SPRuler *)data; - SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); - - sp_ruler_queue_pos_redraw (ruler); - - gboolean ret = g_source_remove(priv->pos_redraw_idle_id); - priv->pos_redraw_idle_id = 0; - - return ret; -} - -static void -sp_ruler_queue_pos_redraw (SPRuler *ruler) -{ - SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler); - const GdkRectangle rect = sp_ruler_get_pos_rect (ruler, priv->position); - GtkAllocation allocation; - - gtk_widget_get_allocation (GTK_WIDGET(ruler), &allocation); - - gtk_widget_queue_draw_area (GTK_WIDGET(ruler), - rect.x + allocation.x, - rect.y + allocation.y, - rect.width, - rect.height); - - if (priv->last_pos_rect.width != 0 || priv->last_pos_rect.height != 0) - { - gtk_widget_queue_draw_area (GTK_WIDGET(ruler), - priv->last_pos_rect.x + allocation.x, - priv->last_pos_rect.y + allocation.y, - priv->last_pos_rect.width, - priv->last_pos_rect.height); - - priv->last_pos_rect.x = 0; - priv->last_pos_rect.y = 0; - priv->last_pos_rect.width = 0; - priv->last_pos_rect.height = 0; - } -} - -static PangoLayout* -sp_ruler_create_layout (GtkWidget *widget, - const gchar *text) -{ - SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (widget); - PangoLayout *layout; - PangoAttrList *attrs; - PangoAttribute *attr; - - layout = gtk_widget_create_pango_layout (widget, text); - - attrs = pango_attr_list_new (); - - attr = pango_attr_scale_new (priv->font_scale); - attr->start_index = 0; - attr->end_index = -1; - pango_attr_list_insert (attrs, attr); - - pango_layout_set_attributes (layout, attrs); - pango_attr_list_unref (attrs); - - return layout; -} - -static PangoLayout * -sp_ruler_get_layout (GtkWidget *widget, - const gchar *text) -{ - SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (widget); - - if (priv->layout) - { - pango_layout_set_text (priv->layout, text, -1); - return priv->layout; - } - - priv->layout = sp_ruler_create_layout (widget, text); - - return priv->layout; -} - -/* - 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:fileencoding=utf-8:textwidth=99 : diff --git a/src/widgets/ruler.h b/src/widgets/ruler.h deleted file mode 100644 index ed529d082..000000000 --- a/src/widgets/ruler.h +++ /dev/null @@ -1,86 +0,0 @@ -#ifndef __SP_RULER_H__ -#define __SP_RULER_H__ - -/* - * Customized ruler class for inkscape - * - * Authors: - * Lauris Kaplinski - * Frank Felfe - * - * Copyright (C) 1999-2002 authors - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include -#include -#include - -namespace Inkscape { - namespace Util { - class Unit; - } -} - -G_BEGIN_DECLS - -#define SP_TYPE_RULER (sp_ruler_get_type ()) -#define SP_RULER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SP_TYPE_RULER, SPRuler)) -#define SP_RULER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SP_TYPE_RULER, SPRulerClass)) -#define SP_IS_RULER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SP_TYPE_RULER)) -#define SP_IS_RULER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SP_TYPE_RULER)) -#define SP_RULER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SP_TYPE_RULER, SPRulerClass)) - -typedef struct _SPRuler SPRuler; -typedef struct _SPRulerClass SPRulerClass; - -struct _SPRuler -{ - GtkWidget parent_instance; -}; - -struct _SPRulerClass -{ - GtkWidgetClass parent_class; -}; - - -GType sp_ruler_get_type (void) G_GNUC_CONST; - -GtkWidget* sp_ruler_new (GtkOrientation orientation); - -void sp_ruler_add_track_widget (SPRuler *ruler, - GtkWidget *widget); -void sp_ruler_remove_track_widget (SPRuler *ruler, - GtkWidget *widget); - -void sp_ruler_set_unit (SPRuler *ruler, - const Inkscape::Util::Unit *unit); -Inkscape::Util::Unit const * sp_ruler_get_unit (SPRuler *ruler); -void sp_ruler_set_position (SPRuler *ruler, - gdouble set_position); -gdouble sp_ruler_get_position (SPRuler *ruler); -void sp_ruler_set_range (SPRuler *ruler, - gdouble lower, - gdouble upper, - gdouble max_size); -void sp_ruler_get_range (SPRuler *ruler, - gdouble *lower, - gdouble *upper, - gdouble *max_size); - -G_END_DECLS - -#endif /* __SP_RULER_H__ */ - -/* - 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:fileencoding=utf-8:textwidth=99 : -- cgit v1.2.3 From 41e0cdaf25ae70d09f1283e74dd3c47d64bf0ec0 Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Mon, 8 Aug 2016 11:35:00 +0100 Subject: Fix autotools build (bzr r15045) --- src/widgets/Makefile_insert | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/Makefile_insert b/src/widgets/Makefile_insert index 7434a5394..99a85c5b6 100644 --- a/src/widgets/Makefile_insert +++ b/src/widgets/Makefile_insert @@ -70,8 +70,12 @@ ink_common_sources += \ widgets/pencil-toolbar.h \ widgets/rect-toolbar.cpp \ widgets/rect-toolbar.h \ - widgets/ruler.cpp \ - widgets/ruler.h \ + widgets/gimp/gimpspinscale.c \ + widgets/gimp/gimpspinscale.h \ + widgets/gimp/gimpcolorwheel.c \ + widgets/gimp/gimpcolorwheel.h \ + widgets/gimp/ruler.cpp \ + widgets/gimp/ruler.h \ widgets/select-toolbar.cpp \ widgets/select-toolbar.h \ widgets/spray-toolbar.cpp \ -- cgit v1.2.3 From e471a664f923f517b68071f2e33fbb6ce070f8b7 Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Mon, 8 Aug 2016 13:56:40 +0100 Subject: Remove deprecated Autotools and btool files. Please use CMake instead (bzr r15046) --- src/widgets/Makefile_insert | 129 -------------------------------------------- 1 file changed, 129 deletions(-) delete mode 100644 src/widgets/Makefile_insert (limited to 'src/widgets') diff --git a/src/widgets/Makefile_insert b/src/widgets/Makefile_insert deleted file mode 100644 index 99a85c5b6..000000000 --- a/src/widgets/Makefile_insert +++ /dev/null @@ -1,129 +0,0 @@ -## Makefile.am fragment sourced by src/Makefile.am. - -ink_common_sources += \ - widgets/arc-toolbar.cpp \ - widgets/arc-toolbar.h \ - widgets/box3d-toolbar.cpp \ - widgets/box3d-toolbar.h \ - widgets/button.cpp \ - widgets/button.h \ - widgets/calligraphy-toolbar.cpp \ - widgets/calligraphy-toolbar.h \ - widgets/connector-toolbar.cpp \ - widgets/connector-toolbar.h \ - widgets/dash-selector.cpp \ - widgets/dash-selector.h \ - widgets/desktop-widget.cpp \ - widgets/desktop-widget.h \ - widgets/dropper-toolbar.cpp \ - widgets/dropper-toolbar.h \ - widgets/eek-preview.cpp \ - widgets/eek-preview.h \ - widgets/ege-adjustment-action.cpp \ - widgets/ege-adjustment-action.h \ - widgets/ege-paint-def.cpp \ - widgets/ege-paint-def.h \ - widgets/ege-output-action.cpp \ - widgets/ege-output-action.h \ - widgets/ege-select-one-action.cpp \ - widgets/ege-select-one-action.h \ - widgets/eraser-toolbar.cpp \ - widgets/eraser-toolbar.h \ - widgets/fill-style.cpp \ - widgets/fill-style.h \ - widgets/fill-n-stroke-factory.h \ - widgets/font-selector.cpp \ - widgets/font-selector.h \ - widgets/gradient-image.cpp \ - widgets/gradient-image.h \ - widgets/gradient-selector.cpp \ - widgets/gradient-selector.h \ - widgets/gradient-toolbar.cpp \ - widgets/gradient-toolbar.h \ - widgets/gradient-vector.cpp \ - widgets/gradient-vector.h \ - widgets/icon.cpp \ - widgets/icon.h \ - widgets/image-menu-item.c \ - widgets/image-menu-item.h \ - widgets/ink-action.cpp \ - widgets/ink-action.h \ - widgets/ink-comboboxentry-action.cpp \ - widgets/ink-comboboxentry-action.h \ - widgets/ink-radio-action.cpp \ - widgets/ink-radio-action.h \ - widgets/ink-toggle-action.cpp \ - widgets/ink-toggle-action.h \ - widgets/ink-tool-menu-action.cpp \ - widgets/ink-tool-menu-action.h \ - widgets/lpe-toolbar.cpp \ - widgets/lpe-toolbar.h \ - widgets/measure-toolbar.cpp \ - widgets/measure-toolbar.h \ - widgets/mesh-toolbar.cpp \ - widgets/mesh-toolbar.h \ - widgets/node-toolbar.cpp \ - widgets/node-toolbar.h \ - widgets/paint-selector.cpp \ - widgets/paint-selector.h \ - widgets/pencil-toolbar.cpp \ - widgets/pencil-toolbar.h \ - widgets/rect-toolbar.cpp \ - widgets/rect-toolbar.h \ - widgets/gimp/gimpspinscale.c \ - widgets/gimp/gimpspinscale.h \ - widgets/gimp/gimpcolorwheel.c \ - widgets/gimp/gimpcolorwheel.h \ - widgets/gimp/ruler.cpp \ - widgets/gimp/ruler.h \ - widgets/select-toolbar.cpp \ - widgets/select-toolbar.h \ - widgets/spray-toolbar.cpp \ - widgets/spray-toolbar.h \ - widgets/spiral-toolbar.cpp \ - widgets/spiral-toolbar.h \ - widgets/sp-attribute-widget.cpp \ - widgets/sp-attribute-widget.h \ - widgets/sp-color-selector.cpp \ - widgets/sp-color-selector.h \ - widgets/spinbutton-events.cpp \ - widgets/spinbutton-events.h \ - widgets/sp-widget.cpp \ - widgets/sp-widget.h \ - widgets/spw-utilities.cpp \ - widgets/spw-utilities.h \ - widgets/sp-xmlview-attr-list.cpp \ - widgets/sp-xmlview-attr-list.h \ - widgets/sp-xmlview-content.cpp \ - widgets/sp-xmlview-content.h \ - widgets/sp-xmlview-tree.cpp \ - widgets/sp-xmlview-tree.h \ - widgets/star-toolbar.cpp \ - widgets/star-toolbar.h \ - widgets/stroke-marker-selector.cpp \ - widgets/stroke-marker-selector.h \ - widgets/stroke-style.cpp \ - widgets/stroke-style.h \ - widgets/swatch-selector.cpp \ - widgets/swatch-selector.h \ - widgets/text-toolbar.cpp \ - widgets/text-toolbar.h \ - widgets/toolbox.cpp \ - widgets/toolbox.h \ - widgets/tweak-toolbar.cpp \ - widgets/tweak-toolbar.h \ - widgets/widget-sizes.h \ - widgets/zoom-toolbar.cpp \ - widgets/zoom-toolbar.h \ - widgets/widget-sizes.h - -if HAVE_POTRACE - -ink_common_sources += \ - widgets/paintbucket-toolbar.cpp \ - widgets/paintbucket-toolbar.h - -endif - -widgets/button.$(OBJEXT): helper/sp-marshal.h -widgets/menu.$(OBJEXT): helper/sp-marshal.h -- cgit v1.2.3 From a796d4f9aafacf8a177c36cf50881366e450b817 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Thu, 1 Sep 2016 15:10:48 +0200 Subject: Make GTK3 width of Text and Font dialog more reasonable. (bzr r15099) --- src/widgets/font-selector.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/font-selector.cpp b/src/widgets/font-selector.cpp index 4822020be..f400de89c 100644 --- a/src/widgets/font-selector.cpp +++ b/src/widgets/font-selector.cpp @@ -110,8 +110,8 @@ static void sp_font_selector_set_size_tooltip(SPFontSelector *fsel) */ static void sp_font_selector_init(SPFontSelector *fsel) { - gtk_box_set_homogeneous(GTK_BOX(fsel), TRUE); - gtk_box_set_spacing(GTK_BOX(fsel), 4); + //gtk_box_set_homogeneous(GTK_BOX(fsel), TRUE); + //gtk_box_set_spacing(GTK_BOX(fsel), 4); /* Family frame */ GtkWidget *f = gtk_frame_new(_("Font family")); @@ -133,6 +133,7 @@ static void sp_font_selector_init(SPFontSelector *fsel) GtkTreeViewColumn *column = gtk_tree_view_column_new (); GtkCellRenderer *cell = gtk_cell_renderer_text_new (); gtk_tree_view_column_pack_start (column, cell, FALSE); + gtk_tree_view_column_set_fixed_width (column, 200); gtk_tree_view_column_set_attributes (column, cell, "text", 0, NULL); gtk_tree_view_column_set_cell_data_func (column, cell, GtkTreeCellDataFunc (font_lister_cell_data_func), @@ -171,7 +172,7 @@ static void sp_font_selector_init(SPFontSelector *fsel) /* Style frame */ f = gtk_frame_new(C_("Font selector", "Style")); gtk_widget_show(f); - gtk_box_pack_start(GTK_BOX (fsel), f, TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX (fsel), f, FALSE, TRUE, 0); auto vb = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4); gtk_box_set_homogeneous(GTK_BOX(vb), FALSE); -- cgit v1.2.3 From 15986c2286dbc36f42de43e3cb98aad9fc0f16c7 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 3 Sep 2016 13:24:49 +1000 Subject: CMake: add missing headers (bzr r15102) --- src/widgets/CMakeLists.txt | 88 ++++++++++++++++++++++------------------------ 1 file changed, 43 insertions(+), 45 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/CMakeLists.txt b/src/widgets/CMakeLists.txt index b2071af4e..c87fa1500 100644 --- a/src/widgets/CMakeLists.txt +++ b/src/widgets/CMakeLists.txt @@ -1,32 +1,20 @@ add_subdirectory(gimp) set(widgets_SRC - button.cpp arc-toolbar.cpp box3d-toolbar.cpp + button.cpp calligraphy-toolbar.cpp connector-toolbar.cpp - dropper-toolbar.cpp - eraser-toolbar.cpp - lpe-toolbar.cpp - measure-toolbar.cpp - mesh-toolbar.cpp - node-toolbar.cpp - pencil-toolbar.cpp - rect-toolbar.cpp - spiral-toolbar.cpp - spray-toolbar.cpp - star-toolbar.cpp - text-toolbar.cpp - tweak-toolbar.cpp - zoom-toolbar.cpp dash-selector.cpp desktop-widget.cpp + dropper-toolbar.cpp eek-preview.cpp + ege-adjustment-action.cpp + ege-output-action.cpp ege-paint-def.cpp - ege-adjustment-action.cpp - ege-output-action.cpp - ege-select-one-action.cpp + ege-select-one-action.cpp + eraser-toolbar.cpp fill-style.cpp font-selector.cpp gradient-image.cpp @@ -40,7 +28,13 @@ set(widgets_SRC ink-radio-action.cpp ink-toggle-action.cpp ink-tool-menu-action.cpp + lpe-toolbar.cpp + measure-toolbar.cpp + mesh-toolbar.cpp + node-toolbar.cpp paint-selector.cpp + pencil-toolbar.cpp + rect-toolbar.cpp select-toolbar.cpp sp-attribute-widget.cpp sp-color-selector.cpp @@ -49,41 +43,35 @@ set(widgets_SRC sp-xmlview-content.cpp sp-xmlview-tree.cpp spinbutton-events.cpp + spiral-toolbar.cpp + spray-toolbar.cpp spw-utilities.cpp + star-toolbar.cpp stroke-marker-selector.cpp stroke-style.cpp swatch-selector.cpp + text-toolbar.cpp toolbox.cpp + tweak-toolbar.cpp + zoom-toolbar.cpp # ------- # Headers - button.h arc-toolbar.h box3d-toolbar.h + button.h calligraphy-toolbar.h connector-toolbar.h - dropper-toolbar.h - eraser-toolbar.h - lpe-toolbar.h - measure-toolbar.h - mesh-toolbar.h - node-toolbar.h - pencil-toolbar.h - rect-toolbar.h - spiral-toolbar.h - spray-toolbar.h - star-toolbar.h - text-toolbar.h - tweak-toolbar.h - zoom-toolbar.h dash-selector.h desktop-widget.h + dropper-toolbar.h eek-preview.h + ege-adjustment-action.h + ege-output-action.h ege-paint-def.h - ege-adjustment-action.h - ege-output-action.h - ege-select-one-action.h + ege-select-one-action.h + eraser-toolbar.h fill-n-stroke-factory.h fill-style.h font-selector.h @@ -93,12 +81,18 @@ set(widgets_SRC gradient-vector.h icon.h image-menu-item.h - ink-action.h - ink-comboboxentry-action.h + ink-action.h + ink-comboboxentry-action.h ink-radio-action.h - ink-toggle-action.h - ink-tool-menu-action.h + ink-toggle-action.h + ink-tool-menu-action.h + lpe-toolbar.h + measure-toolbar.h + mesh-toolbar.h + node-toolbar.h paint-selector.h + pencil-toolbar.h + rect-toolbar.h select-toolbar.h sp-attribute-widget.h sp-color-selector.h @@ -107,25 +101,29 @@ set(widgets_SRC sp-xmlview-content.h sp-xmlview-tree.h spinbutton-events.h + spiral-toolbar.h + spray-toolbar.h spw-utilities.h + star-toolbar.h stroke-marker-selector.h stroke-style.h swatch-selector.h + text-toolbar.h toolbox.h + tweak-toolbar.h widget-sizes.h + zoom-toolbar.h ) # add_inkscape_lib(widgets_LIB "${widgets_SRC}") add_inkscape_source("${widgets_SRC}") -set ( widgets_paintbucket_SRC - paintbucket-toolbar.cpp - paintbucket-toolbar.h +set(widgets_paintbucket_SRC + paintbucket-toolbar.cpp + paintbucket-toolbar.h ) if ("${HAVE_POTRACE}") add_inkscape_source("${widgets_paintbucket_SRC}") endif() - - -- cgit v1.2.3 From 4bcca9f2bf8e89d1589833112a51d5db45225037 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Mon, 5 Sep 2016 14:56:53 +0200 Subject: Save new 'x' and 'y' attribute values when 'line-height' changed. Partial fix for bug #1590141. (bzr r15106) --- src/widgets/text-toolbar.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/widgets') diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index 0160bcac7..0ce2db4b2 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -567,6 +567,15 @@ static void sp_text_lineheight_value_changed( GtkAdjustment *adj, GObject *tbl ) if(modmade) { DocumentUndo::maybeDone(SP_ACTIVE_DESKTOP->getDocument(), "ttb:line-height", SP_VERB_NONE, _("Text: Change line-height")); + // Call to Document::maybeDone() causes rebuild of text layout (with all proper style + // cascading, etc.). For multi-line text with sodipodi::role="line", we must explicitly + // save new 'x' and 'y' attribute values by calling updateRepr(). + // Partial fix for bug #1590141. + for(auto i=itemlist.begin();i!=itemlist.end(); ++i){ + if (SP_IS_TEXT (*i)) { + (*i)->updateRepr(); + } + } } // If no selected objects, set default. -- cgit v1.2.3 From e9d7e78e43ccfe0feda34998d31d921138232da6 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Mon, 5 Sep 2016 15:44:11 +0200 Subject: Fix history handling for previous commit. (bzr r15107) --- src/widgets/text-toolbar.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/text-toolbar.cpp b/src/widgets/text-toolbar.cpp index 0ce2db4b2..4b22c8d7e 100644 --- a/src/widgets/text-toolbar.cpp +++ b/src/widgets/text-toolbar.cpp @@ -565,17 +565,18 @@ static void sp_text_lineheight_value_changed( GtkAdjustment *adj, GObject *tbl ) // Save for undo if(modmade) { - DocumentUndo::maybeDone(SP_ACTIVE_DESKTOP->getDocument(), "ttb:line-height", SP_VERB_NONE, - _("Text: Change line-height")); - // Call to Document::maybeDone() causes rebuild of text layout (with all proper style + // Call ensureUpToDate() causes rebuild of text layout (with all proper style // cascading, etc.). For multi-line text with sodipodi::role="line", we must explicitly // save new 'x' and 'y' attribute values by calling updateRepr(). // Partial fix for bug #1590141. + desktop->getDocument()->ensureUpToDate(); for(auto i=itemlist.begin();i!=itemlist.end(); ++i){ if (SP_IS_TEXT (*i)) { (*i)->updateRepr(); } } + DocumentUndo::maybeDone(SP_ACTIVE_DESKTOP->getDocument(), "ttb:line-height", SP_VERB_NONE, + _("Text: Change line-height")); } // If no selected objects, set default. -- cgit v1.2.3 From f9ec83dbb254701f39d3b7a30c0bacb5eaae9ee9 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Tue, 27 Sep 2016 10:51:26 +0200 Subject: Rename to per SVG 2 CR specificiation. Note: has been repurposed to be a special shape that tightly wraps a mesh gradient. (bzr r15137) --- src/widgets/mesh-toolbar.cpp | 24 ++++++++++++------------ src/widgets/paint-selector.cpp | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/mesh-toolbar.cpp b/src/widgets/mesh-toolbar.cpp index fb540b5f5..0e689fee0 100644 --- a/src/widgets/mesh-toolbar.cpp +++ b/src/widgets/mesh-toolbar.cpp @@ -41,7 +41,7 @@ #include "ui/tools/gradient-tool.h" #include "ui/tools/mesh-tool.h" #include "gradient-drag.h" -#include "sp-mesh.h" +#include "sp-mesh-gradient.h" #include "gradient-chemistry.h" #include "ui/icon-names.h" @@ -70,7 +70,7 @@ static bool blocked = false; * Get the current selection and dragger status from the desktop */ void ms_read_selection( Inkscape::Selection *selection, - SPMesh *&ms_selected, + SPMeshGradient *&ms_selected, bool &ms_selected_multi, SPMeshType &ms_type, bool &ms_type_multi ) @@ -87,9 +87,9 @@ void ms_read_selection( Inkscape::Selection *selection, if (style && (style->fill.isPaintserver())) { SPPaintServer *server = item->style->getFillPaintServer(); - if ( SP_IS_MESH(server) ) { + if ( SP_IS_MESHGRADIENT(server) ) { - SPMesh *gradient = SP_MESH(server); // ->getVector(); + SPMeshGradient *gradient = SP_MESHGRADIENT(server); // ->getVector(); SPMeshType type = gradient->type; if (gradient != ms_selected) { @@ -112,9 +112,9 @@ void ms_read_selection( Inkscape::Selection *selection, if (style && (style->stroke.isPaintserver())) { SPPaintServer *server = item->style->getStrokePaintServer(); - if ( SP_IS_MESH(server) ) { + if ( SP_IS_MESHGRADIENT(server) ) { - SPMesh *gradient = SP_MESH(server); // ->getVector(); + SPMeshGradient *gradient = SP_MESHGRADIENT(server); // ->getVector(); SPMeshType type = gradient->type; if (gradient != ms_selected) { @@ -164,7 +164,7 @@ static void ms_tb_selection_changed(Inkscape::Selection * /*selection*/, gpointe // // Hide/show handles? // } - SPMesh *ms_selected = 0; + SPMeshGradient *ms_selected = 0; SPMeshType ms_type = SP_MESH_TYPE_COONS; bool ms_selected_multi = false; bool ms_type_multi = false; @@ -203,9 +203,9 @@ static void ms_defs_modified(SPObject * /*defs*/, guint /*flags*/, GObject *widg ms_tb_selection_changed(NULL, widget); } -void ms_get_dt_selected_gradient(Inkscape::Selection *selection, SPMesh *&ms_selected) +void ms_get_dt_selected_gradient(Inkscape::Selection *selection, SPMeshGradient *&ms_selected) { - SPMesh *gradient = 0; + SPMeshGradient *gradient = 0; auto itemlist= selection->items(); for(auto i=itemlist.begin();i!=itemlist.end();++i){ @@ -220,8 +220,8 @@ void ms_get_dt_selected_gradient(Inkscape::Selection *selection, SPMesh *&ms_sel server = item->style->getStrokePaintServer(); } - if ( SP_IS_MESH(server) ) { - gradient = SP_MESH(server); + if ( SP_IS_MESHGRADIENT(server) ) { + gradient = SP_MESHGRADIENT(server); } } @@ -295,7 +295,7 @@ static void ms_type_changed(EgeSelectOneAction *act, GtkWidget *widget) SPDesktop *desktop = static_cast(g_object_get_data(G_OBJECT(widget), "desktop")); Inkscape::Selection *selection = desktop->getSelection(); - SPMesh *gradient = 0; + SPMeshGradient *gradient = 0; ms_get_dt_selected_gradient(selection, gradient); if (gradient) { diff --git a/src/widgets/paint-selector.cpp b/src/widgets/paint-selector.cpp index 01118f337..ddac90730 100644 --- a/src/widgets/paint-selector.cpp +++ b/src/widgets/paint-selector.cpp @@ -33,7 +33,7 @@ #include "sp-linear-gradient.h" #include "sp-radial-gradient.h" -#include "sp-mesh.h" +#include "sp-mesh-gradient.h" #include "sp-stop.h" /* fixme: Move it from dialogs to here */ #include "gradient-selector.h" @@ -1221,7 +1221,7 @@ SPPaintSelector::Mode SPPaintSelector::getModeForStyle(SPStyle const & style, Fi } else if (SP_IS_RADIALGRADIENT(server)) { mode = MODE_GRADIENT_RADIAL; #ifdef WITH_MESH - } else if (SP_IS_MESH(server)) { + } else if (SP_IS_MESHGRADIENT(server)) { mode = MODE_GRADIENT_MESH; #endif } else if (SP_IS_PATTERN(server)) { -- cgit v1.2.3 From b6ec8d66b6ba6889217dfb0cbff4fd3c9901acd2 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Sat, 1 Oct 2016 23:14:55 -0400 Subject: Adjust dock size to minimum width during canvas table size allocation signal. (bzr r15142) --- src/widgets/desktop-widget.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp index bd72560c6..55dc82dc0 100644 --- a/src/widgets/desktop-widget.cpp +++ b/src/widgets/desktop-widget.cpp @@ -307,12 +307,19 @@ sp_desktop_widget_class_init (SPDesktopWidgetClass *klass) * This adjusts the range of the rulers when the dock container is adjusted * (fixes lp:950552) */ -static void canvas_tbl_size_allocate(GtkWidget * /*widget*/, +static void canvas_tbl_size_allocate(GtkWidget * widget, GdkRectangle * /*allocation*/, gpointer data) { SPDesktopWidget *dtw = SP_DESKTOP_WIDGET(data); sp_desktop_widget_update_rulers(dtw); + + GtkWidget* parent = gtk_widget_get_parent(widget); + if(GTK_IS_PANED(parent)) { + GtkPaned *paned = GTK_PANED(parent); + // Could use gtk paned property 'max-position' here + gtk_paned_set_position(paned, 10000); + } } /** @@ -527,8 +534,8 @@ void SPDesktopWidget::init( SPDesktopWidget *dtw ) paned_class->cycle_handle_focus = NULL; } - gtk_widget_set_hexpand(GTK_WIDGET(paned->gobj()), TRUE); - gtk_widget_set_vexpand(GTK_WIDGET(paned->gobj()), TRUE); + paned->set_hexpand(true); + paned->set_vexpand(true); gtk_grid_attach(GTK_GRID(tbl_wrapper), GTK_WIDGET (paned->gobj()), 1, 1, 1, 1); } else { gtk_widget_set_hexpand(GTK_WIDGET(dtw->canvas_tbl), TRUE); -- cgit v1.2.3