Skip to content

Commit

Permalink
Remove now dead code guarded with GTK_CHECK_VERSION(3, 0, 0)
Browse files Browse the repository at this point in the history
  • Loading branch information
codebrainz committed Oct 4, 2020
1 parent d065c50 commit eed0f3b
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 217 deletions.
24 changes: 6 additions & 18 deletions src/build.c
Expand Up @@ -1733,14 +1733,10 @@ typedef struct RowWidgets
gboolean used_dst;
} RowWidgets;

#if GTK_CHECK_VERSION(3,0,0)
typedef GdkRGBA InsensitiveColor;
#else
typedef GdkColor InsensitiveColor;
#endif
static InsensitiveColor insensitive_color;

static void set_row_color(RowWidgets *r, InsensitiveColor *color)
static GdkRGBA insensitive_color;

static void set_row_color(RowWidgets *r, GdkRGBA *color)
{
enum GeanyBuildCmdEntries i;

Expand All @@ -1749,11 +1745,7 @@ static void set_row_color(RowWidgets *r, InsensitiveColor *color)
if (i == GEANY_BC_LABEL)
continue;

#if GTK_CHECK_VERSION(3,0,0)
gtk_widget_override_color(r->entries[i], GTK_STATE_FLAG_NORMAL, color);
#else
gtk_widget_modify_text(r->entries[i], GTK_STATE_NORMAL, color);
#endif
}
}

Expand Down Expand Up @@ -1866,23 +1858,19 @@ static RowWidgets *build_add_dialog_row(GeanyDocument *doc, GtkTable *table, gui
enum GeanyBuildCmdEntries i;
guint column = 0;
gchar *text;
GtkStyleContext *ctx;

g_return_val_if_fail(doc == NULL || doc->is_valid, NULL);

text = g_strdup_printf("%d.", cmd + 1);
label = gtk_label_new(text);
g_free(text);
#if GTK_CHECK_VERSION(3,0,0)
{
GtkStyleContext *ctx = gtk_widget_get_style_context(label);

ctx = gtk_widget_get_style_context(label);
gtk_style_context_save(ctx);
gtk_style_context_get_color(ctx, GTK_STATE_FLAG_INSENSITIVE, &insensitive_color);
gtk_style_context_restore(ctx);
}
#else
insensitive_color = gtk_widget_get_style(label)->text[GTK_STATE_INSENSITIVE];
#endif

gtk_table_attach(table, label, column, column + 1, row, row + 1, GTK_FILL,
GTK_FILL | GTK_EXPAND, entry_x_padding, entry_y_padding);
roww = g_new0(RowWidgets, 1);
Expand Down
11 changes: 0 additions & 11 deletions src/document.c
Expand Up @@ -3285,7 +3285,6 @@ const GdkColor *document_get_status_color(GeanyDocument *doc)
return NULL;
if (! document_status_styles[status].loaded)
{
#if GTK_CHECK_VERSION(3, 0, 0)
GdkRGBA color;
GtkWidgetPath *path = gtk_widget_path_new();
GtkStyleContext *ctx = gtk_style_context_new();
Expand All @@ -3303,16 +3302,6 @@ const GdkColor *document_get_status_color(GeanyDocument *doc)
document_status_styles[status].loaded = TRUE;
gtk_widget_path_unref(path);
g_object_unref(ctx);
#else
GtkSettings *settings = gtk_widget_get_settings(GTK_WIDGET(doc->editor->sci));
gchar *path = g_strconcat("GeanyMainWindow.GtkHBox.GtkNotebook.",
document_status_styles[status].name, NULL);
GtkStyle *style = gtk_rc_get_style_by_paths(settings, path, NULL, GTK_TYPE_LABEL);

document_status_styles[status].color = style->fg[GTK_STATE_NORMAL];
document_status_styles[status].loaded = TRUE;
g_free(path);
#endif
}
return &document_status_styles[status].color;
}
Expand Down
15 changes: 1 addition & 14 deletions src/editor.c
Expand Up @@ -4796,8 +4796,7 @@ static gboolean on_editor_focus_in(GtkWidget *widget, GdkEventFocus *event, gpoi
}


static gboolean on_editor_expose_event(GtkWidget *widget, GdkEventExpose *event,
gpointer user_data)
static gboolean on_editor_draw(GtkWidget *widget, cairo_t *cr, gpointer user_data)
{
GeanyEditor *editor = user_data;

Expand All @@ -4808,14 +4807,6 @@ static gboolean on_editor_expose_event(GtkWidget *widget, GdkEventExpose *event,
}


#if GTK_CHECK_VERSION(3, 0, 0)
static gboolean on_editor_draw(GtkWidget *widget, cairo_t *cr, gpointer user_data)
{
return on_editor_expose_event(widget, NULL, user_data);
}
#endif


static void setup_sci_keys(ScintillaObject *sci)
{
/* disable some Scintilla keybindings to be able to redefine them cleanly */
Expand Down Expand Up @@ -4961,11 +4952,7 @@ static ScintillaObject *create_new_sci(GeanyEditor *editor)
g_signal_connect(sci, "scroll-event", G_CALLBACK(on_editor_scroll_event), editor);
g_signal_connect(sci, "motion-notify-event", G_CALLBACK(on_motion_event), NULL);
g_signal_connect(sci, "focus-in-event", G_CALLBACK(on_editor_focus_in), editor);
#if GTK_CHECK_VERSION(3, 0, 0)
g_signal_connect(sci, "draw", G_CALLBACK(on_editor_draw), editor);
#else
g_signal_connect(sci, "expose-event", G_CALLBACK(on_editor_expose_event), editor);
#endif
}
return sci;
}
Expand Down
39 changes: 3 additions & 36 deletions src/gb.c
Expand Up @@ -78,22 +78,14 @@ static GType geany_pong_get_type(void) G_GNUC_CONST;
G_DEFINE_TYPE(GeanyPong, geany_pong, GTK_TYPE_DIALOG)


#if GTK_CHECK_VERSION(3, 0, 0)
static void geany_pong_set_cairo_source_color(cairo_t *cr, GdkRGBA *c, gdouble a)
{
cairo_set_source_rgba(cr, c->red, c->green, c->blue, MIN(c->alpha, a));
}
#else
static void geany_pong_set_cairo_source_color(cairo_t *cr, GdkColor *c, gdouble a)
{
cairo_set_source_rgba(cr, c->red/65535.0, c->green/65535.0, c->blue/65535.0, a);
}
#endif


static gboolean geany_pong_area_draw(GtkWidget *area, cairo_t *cr, GeanyPong *self)
{
#if GTK_CHECK_VERSION(3, 0, 0)
/* we use the window style context because the area one has a transparent
* background and we want something to paint for the overlay */
GtkStyleContext *ctx = gtk_widget_get_style_context(GTK_WIDGET(self));
Expand All @@ -102,11 +94,6 @@ static gboolean geany_pong_area_draw(GtkWidget *area, cairo_t *cr, GeanyPong *se

gtk_style_context_get_color(ctx, state, &fg);
gtk_style_context_get_background_color(ctx, state, &bg);
#else
GtkStyle *style = gtk_widget_get_style(area);
GdkColor fg = style->fg[GTK_STATE_NORMAL];
GdkColor bg = style->bg[GTK_STATE_NORMAL];
#endif

self->area_width = gtk_widget_get_allocated_width(area);
self->area_height = gtk_widget_get_allocated_height(area);
Expand Down Expand Up @@ -134,24 +121,22 @@ static gboolean geany_pong_area_draw(GtkWidget *area, cairo_t *cr, GeanyPong *se
PangoLayout *layout;
gint pw, ph;
gdouble scale;
PangoFontDescription *font = NULL;

geany_pong_set_cairo_source_color(cr, &bg, 0.8);
cairo_rectangle(cr, 0, 0, self->area_width, self->area_height);
cairo_paint(cr);

geany_pong_set_cairo_source_color(cr, &fg, 1.0);
layout = pango_cairo_create_layout(cr);
#if GTK_CHECK_VERSION(3, 0, 0)
PangoFontDescription *font = NULL;

gtk_style_context_get(ctx, state, GTK_STYLE_PROPERTY_FONT, &font, NULL);
if (font)
{
pango_layout_set_font_description(layout, font);
pango_font_description_free(font);
}
#else
pango_layout_set_font_description(layout, style->font_desc);
#endif

if (! self->handle_width)
pango_layout_set_markup(layout, "<b>You won!</b>\n<small>OK, go back to work now.</small>", -1);
else
Expand All @@ -171,20 +156,6 @@ static gboolean geany_pong_area_draw(GtkWidget *area, cairo_t *cr, GeanyPong *se
}


#if ! GTK_CHECK_VERSION(3, 0, 0)
static gboolean geany_pong_area_expose(GtkWidget *area, GdkEventExpose *event, GeanyPong *self)
{
cairo_t *cr = gdk_cairo_create(gtk_widget_get_window(area));
gboolean ret;

ret = geany_pong_area_draw(area, cr, self);
cairo_destroy(cr);

return ret;
}
#endif


static void geany_pong_reset_ball(GeanyPong *self)
{
self->ball_speed = 5;
Expand Down Expand Up @@ -365,11 +336,7 @@ static void geany_pong_init(GeanyPong *self)

self->area = gtk_drawing_area_new();
gtk_widget_add_events(self->area, GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
#if GTK_CHECK_VERSION(3, 0, 0)
g_signal_connect(self->area, "draw", G_CALLBACK(geany_pong_area_draw), self);
#else
g_signal_connect(self->area, "expose-event", G_CALLBACK(geany_pong_area_expose), self);
#endif
g_signal_connect(self->area, "button-press-event", G_CALLBACK(geany_pong_area_button_press), self);
g_signal_connect(self->area, "motion-notify-event", G_CALLBACK(geany_pong_area_motion_notify), self);
gtk_widget_set_size_request(self->area, AREA_SIZE, AREA_SIZE);
Expand Down
46 changes: 5 additions & 41 deletions src/geanywraplabel.c
Expand Up @@ -48,7 +48,6 @@ struct _GeanyWrapLabel
};


#if GTK_CHECK_VERSION(3, 0, 0)
static gboolean geany_wrap_label_draw(GtkWidget *widget, cairo_t *cr);
static void geany_wrap_label_get_preferred_width (GtkWidget *widget,
gint *minimal_width, gint *natural_width);
Expand All @@ -59,10 +58,7 @@ static void geany_wrap_label_get_preferred_width_for_height (GtkWidget *widget,
static void geany_wrap_label_get_preferred_height_for_width (GtkWidget *widget,
gint width, gint *minimal_height, gint *natural_height);
static GtkSizeRequestMode geany_wrap_label_get_request_mode(GtkWidget *widget);
#else
static gboolean geany_wrap_label_expose (GtkWidget *widget, GdkEventExpose *event);
static void geany_wrap_label_size_request (GtkWidget *widget, GtkRequisition *req);
#endif

static void geany_wrap_label_size_allocate (GtkWidget *widget, GtkAllocation *alloc);
static void geany_wrap_label_set_wrap_width (GtkWidget *widget, gint width);
static void geany_wrap_label_label_notify (GObject *object, GParamSpec *pspec, gpointer data);
Expand All @@ -75,17 +71,12 @@ static void geany_wrap_label_class_init(GeanyWrapLabelClass *klass)
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);

widget_class->size_allocate = geany_wrap_label_size_allocate;
#if GTK_CHECK_VERSION(3, 0, 0)
widget_class->draw = geany_wrap_label_draw;
widget_class->get_preferred_width = geany_wrap_label_get_preferred_width;
widget_class->get_preferred_width_for_height = geany_wrap_label_get_preferred_width_for_height;
widget_class->get_preferred_height = geany_wrap_label_get_preferred_height;
widget_class->get_preferred_height_for_width = geany_wrap_label_get_preferred_height_for_width;
widget_class->get_request_mode = geany_wrap_label_get_request_mode;
#else
widget_class->size_request = geany_wrap_label_size_request;
widget_class->expose_event = geany_wrap_label_expose;
#endif

g_type_class_add_private(klass, sizeof (GeanyWrapLabelPrivate));
}
Expand Down Expand Up @@ -140,7 +131,6 @@ static void geany_wrap_label_label_notify(GObject *object, GParamSpec *pspec, gp
}


#if GTK_CHECK_VERSION(3, 0, 0)
/* makes sure the layout is setup for rendering and chains to parent renderer */
static gboolean geany_wrap_label_draw(GtkWidget *widget, cairo_t *cr)
{
Expand Down Expand Up @@ -199,48 +189,22 @@ static GtkSizeRequestMode geany_wrap_label_get_request_mode(GtkWidget *widget)
return GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT;
}

#else /* GTK3 */

/* makes sure the layout is setup for rendering and chains to parent renderer */
static gboolean geany_wrap_label_expose(GtkWidget *widget, GdkEventExpose *event)
{
GeanyWrapLabel *self = GEANY_WRAP_LABEL(widget);
PangoLayout *layout = gtk_label_get_layout(GTK_LABEL(widget));

pango_layout_set_width(layout, self->priv->wrap_width * PANGO_SCALE);
pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);

return (* GTK_WIDGET_CLASS(geany_wrap_label_parent_class)->expose_event)(widget, event);
}


/* Forces the height to be the size necessary for the Pango layout, while allowing the
* width to be flexible. */
static void geany_wrap_label_size_request(GtkWidget *widget, GtkRequisition *req)
{
req->width = 0;
req->height = GEANY_WRAP_LABEL(widget)->priv->wrap_height;
}
#endif /* GTK3 */


/* Sets the wrap width to the width allocated to us. */
static void geany_wrap_label_size_allocate(GtkWidget *widget, GtkAllocation *alloc)
{
GtkWidget *parent;

(* GTK_WIDGET_CLASS(geany_wrap_label_parent_class)->size_allocate)(widget, alloc);

geany_wrap_label_set_wrap_width(widget, alloc->width);

#if GTK_CHECK_VERSION(3, 0, 0)
{
/* ask the parent to recompute our size, because it seems GTK3 size
/* ask the parent to recompute our size, because it seems GTK size
* caching is too aggressive */
GtkWidget *parent = gtk_widget_get_parent(widget);
parent = gtk_widget_get_parent(widget);
if (GTK_IS_CONTAINER(parent))
gtk_container_check_resize(GTK_CONTAINER(parent));
}
#endif
}


GtkWidget *geany_wrap_label_new(const gchar *text)
Expand Down
50 changes: 1 addition & 49 deletions src/libmain.c
Expand Up @@ -1015,52 +1015,6 @@ static const gchar *get_locale(void)
}


#if ! GTK_CHECK_VERSION(3, 0, 0)
/* This prepends our own gtkrc file to the list of RC files to be loaded by GTK at startup.
* This function *has* to be called before gtk_init().
*
* We have a custom RC file defining various styles we need, and we want the user to be
* able to override them (e.g. if they want -- or need -- other colors). Fair enough, one
* would simply call gtk_rc_parse() with the appropriate filename. However, the styling
* rules applies in the order they are loaded, then if we load our styles after GTK has
* loaded the user's ones we'd override them.
*
* There are 2 solutions to fix this:
* 1) set our styles' priority to something with lower than "user" (actually "theme"
* priority because rules precedence are first calculated depending on the priority
* no matter of how precise the rules is, so we need to override the theme).
* 2) prepend our custom style to GTK's list while keeping priority to user (which is the
* default), so it gets loaded before real user's ones and so gets overridden by them.
*
* One would normally go for 1 because it's ways simpler and requires less code: you just
* have to add the priorities to your styles, which is a matter of adding a few ":theme" in
* the RC file. However, KDE being a bitch it doesn't set the gtk-theme-name but rather
* directly includes the style to use in a user gtkrc file, which makes the theme have
* "user" priority, hence overriding our styles. So, we cannot set priorities in the RC
* file if we want to support running under KDE, which pretty much leave us with no choice
* but to go with solution 2, which unfortunately requires writing ugly code since GTK
* don't have a gtk_rc_prepend_default_file() function. Thank you very much KDE.
*
* Though, as a side benefit it also makes the code work with people using gtk-chtheme,
* which also found it funny to include the theme in the user RC file. */
static void setup_gtk2_styles(void)
{
gchar **gtk_files = gtk_rc_get_default_files();
gchar **new_files = g_malloc(sizeof *new_files * (g_strv_length(gtk_files) + 2));
guint i = 0;

new_files[i++] = g_build_filename(app->datadir, "geany.gtkrc", NULL);
for (; *gtk_files; gtk_files++)
new_files[i++] = g_strdup(*gtk_files);
new_files[i] = NULL;

gtk_rc_set_default_files(new_files);

g_strfreev(new_files);
}
#endif


GEANY_EXPORT_SYMBOL
gint main_lib(gint argc, gchar **argv)
{
Expand Down Expand Up @@ -1088,9 +1042,7 @@ gint main_lib(gint argc, gchar **argv)
memset(&ui_widgets, 0, sizeof(UIWidgets));

setup_paths();
#if ! GTK_CHECK_VERSION(3, 0, 0)
setup_gtk2_styles();
#endif

#ifdef ENABLE_NLS
main_locale_init(utils_resource_dir(RESOURCE_DIR_LOCALE), GETTEXT_PACKAGE);
#endif
Expand Down

0 comments on commit eed0f3b

Please sign in to comment.