Skip to content

Commit

Permalink
use accessor functions
Browse files Browse the repository at this point in the history
gtk3 does not allow direct use of data structures,
use accessor functions instead
  • Loading branch information
nadvornik committed Aug 13, 2012
1 parent 55ccc0f commit dc0a8b7
Show file tree
Hide file tree
Showing 41 changed files with 456 additions and 385 deletions.
6 changes: 3 additions & 3 deletions src/bar.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,9 @@ static void bar_menu_popup(GtkWidget *widget)
else
{
expander = widget;
bar = widget->parent;
bar = gtk_widget_get_parent(widget);
while (bar && !g_object_get_data(G_OBJECT(bar), "bar_data"))
bar = bar->parent;
bar = gtk_widget_get_parent(bar);
if (!bar) return;
}

Expand Down Expand Up @@ -496,7 +496,7 @@ void bar_update_expander(GtkWidget *pane)

if (!pd) return;

expander = pane->parent;
expander = gtk_widget_get_parent(pane);

gtk_expander_set_expanded(GTK_EXPANDER(expander), pd->expanded);
}
Expand Down
17 changes: 10 additions & 7 deletions src/bar_exif.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ static void bar_pane_exif_entry_dnd_get(GtkWidget *entry, GdkDragContext *contex
switch (info)
{
case TARGET_APP_EXIF_ENTRY:
gtk_selection_data_set(selection_data, selection_data->target,
gtk_selection_data_set(selection_data, gtk_selection_data_get_target(selection_data),
8, (gpointer) &entry, sizeof(entry));
break;

Expand Down Expand Up @@ -378,14 +378,14 @@ static void bar_pane_exif_dnd_receive(GtkWidget *pane, GdkDragContext *context,
switch (info)
{
case TARGET_APP_EXIF_ENTRY:
new_entry = *(gpointer *)selection_data->data;
new_entry = *(gpointer *)gtk_selection_data_get_data(selection_data);

if (new_entry->parent && new_entry->parent != ped->vbox) bar_pane_exif_reparent_entry(new_entry, pane);
if (gtk_widget_get_parent(new_entry) && gtk_widget_get_parent(new_entry) != ped->vbox) bar_pane_exif_reparent_entry(new_entry, pane);

break;
default:
/* FIXME: this needs a check for valid exif keys */
new_entry = bar_pane_exif_add_entry(ped, (gchar *)selection_data->data, NULL, TRUE, FALSE);
new_entry = bar_pane_exif_add_entry(ped, (gchar *)gtk_selection_data_get_data(selection_data), NULL, TRUE, FALSE);
break;
}

Expand All @@ -396,17 +396,20 @@ static void bar_pane_exif_dnd_receive(GtkWidget *pane, GdkDragContext *context,
{
gint nx, ny;
GtkWidget *entry = work->data;
GtkAllocation allocation;
work = work->next;

if (entry == new_entry) continue;

gtk_widget_get_allocation(entry, &allocation);

#if GTK_CHECK_VERSION(2,20,0)
if (gtk_widget_is_drawable(entry) &&
#else
if (GTK_WIDGET_DRAWABLE(entry) &&
#endif
gtk_widget_translate_coordinates(pane, entry, x, y, &nx, &ny) &&
ny < entry->allocation.height / 2) break;
ny < allocation.height / 2) break;
pos++;
}
g_list_free(list);
Expand Down Expand Up @@ -488,13 +491,13 @@ static void bar_pane_exif_edit_ok_cb(GenericDialog *gd, gpointer data)
if (ee)
{
const gchar *title;
GtkWidget *pane = cdd->widget->parent;
GtkWidget *pane = gtk_widget_get_parent(cdd->widget);

while (pane)
{
ped = g_object_get_data(G_OBJECT(pane), "pane_data");
if (ped) break;
pane = pane->parent;
pane = gtk_widget_get_parent(pane);
}

if (!pane) return;
Expand Down
16 changes: 5 additions & 11 deletions src/bar_histogram.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,11 @@ static gboolean bar_pane_histogram_expose_event_cb(GtkWidget *widget, GdkEventEx

if (!phd->pixbuf) return TRUE;

gdk_draw_pixbuf(widget->window,
#if GTK_CHECK_VERSION(2,20,0)
widget->style->fg_gc[gtk_widget_get_state(widget)],
#else
widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
#endif
phd->pixbuf,
0, 0,
0, 0,
-1, -1,
GDK_RGB_DITHER_NORMAL, 0, 0);
cairo_t *cr = gdk_cairo_create(gtk_widget_get_window(widget));
gdk_cairo_set_source_pixbuf (cr, phd->pixbuf, 0, 0);
cairo_paint (cr);
cairo_destroy (cr);

return TRUE;
}

Expand Down
6 changes: 3 additions & 3 deletions src/bar_keywords.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ static void bar_pane_keywords_dnd_get(GtkWidget *tree_view, GdkDragContext *cont
case TARGET_APP_KEYWORD_PATH:
{
GList *path = keyword_tree_get_path(keyword_tree, &child_iter);
gtk_selection_data_set(selection_data, selection_data->target,
gtk_selection_data_set(selection_data, gtk_selection_data_get_target(selection_data),
8, (gpointer) &path, sizeof(path));
break;
}
Expand Down Expand Up @@ -611,13 +611,13 @@ static void bar_pane_keywords_dnd_receive(GtkWidget *tree_view, GdkDragContext *
{
case TARGET_APP_KEYWORD_PATH:
{
GList *path = *(gpointer *)selection_data->data;
GList *path = *(gpointer *)gtk_selection_data_get_data(selection_data);
src_valid = keyword_tree_get_iter(keyword_tree, &src_kw_iter, path);
string_list_free(path);
break;
}
default:
new_keywords = string_to_keywords_list((gchar *)selection_data->data);
new_keywords = string_to_keywords_list((gchar *)gtk_selection_data_get_data(selection_data));
break;
}

Expand Down
6 changes: 3 additions & 3 deletions src/bar_sort.c
Original file line number Diff line number Diff line change
Expand Up @@ -599,12 +599,12 @@ static GtkWidget *bar_sort_new(LayoutWindow *lw, SortActionType action,
gtk_box_pack_start(GTK_BOX(sd->vbox), label, FALSE, FALSE, 0);
gtk_widget_show(label);

combo = gtk_combo_box_new_text();
combo = gtk_combo_box_text_new();
gtk_box_pack_start(GTK_BOX(sd->vbox), combo, FALSE, FALSE, 0);
gtk_widget_show(combo);

gtk_combo_box_append_text(GTK_COMBO_BOX(combo), _("Folders"));
gtk_combo_box_append_text(GTK_COMBO_BOX(combo), _("Collections"));
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), _("Folders"));
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), _("Collections"));

g_signal_connect(G_OBJECT(combo), "changed",
G_CALLBACK(bar_sort_mode_cb), sd);
Expand Down
4 changes: 2 additions & 2 deletions src/cache_maint.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ void cache_maintain_home(gboolean metadata, gboolean clear, GtkWidget *parent)
gtk_widget_show(hbox);

cm->entry = gtk_entry_new();
GTK_WIDGET_UNSET_FLAGS(cm->entry, GTK_CAN_FOCUS);
gtk_widget_set_can_focus(cm->entry, FALSE);
gtk_editable_set_editable(GTK_EDITABLE(cm->entry), FALSE);
gtk_box_pack_start(GTK_BOX(hbox), cm->entry, TRUE, TRUE, 0);
gtk_widget_show(cm->entry);
Expand Down Expand Up @@ -910,7 +910,7 @@ static void cache_manager_render_dialog(GtkWidget *widget, const gchar *path)
hbox = pref_box_new(cd->gd->vbox, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE);

cd->progress = gtk_entry_new();
GTK_WIDGET_UNSET_FLAGS(cd->progress, GTK_CAN_FOCUS);
gtk_widget_set_can_focus(cd->progress, FALSE);
gtk_editable_set_editable(GTK_EDITABLE(cd->progress), FALSE);
gtk_entry_set_text(GTK_ENTRY(cd->progress), _("click start to begin"));
gtk_box_pack_start(GTK_BOX(hbox), cd->progress, TRUE, TRUE, 0);
Expand Down
57 changes: 34 additions & 23 deletions src/cellrenderericon.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ static void
gqv_cell_renderer_icon_init(GQvCellRendererIcon *cellicon)
{
GTK_CELL_RENDERER(cellicon)->mode = GTK_CELL_RENDERER_MODE_ACTIVATABLE;
GTK_CELL_RENDERER(cellicon)->xpad = 2;
GTK_CELL_RENDERER(cellicon)->ypad = 2;
gtk_cell_renderer_set_padding(GTK_CELL_RENDERER(cellicon), 2, 2);
}

static void
Expand Down Expand Up @@ -553,6 +552,11 @@ gqv_cell_renderer_icon_get_size(GtkCellRenderer *cell,
GQvCellRendererIcon *cellicon = (GQvCellRendererIcon *) cell;
gint calc_width;
gint calc_height;
gint xpad, ypad;
gint xalign, yalign;

gtk_cell_renderer_get_padding(cell, &xpad, &ypad);
gtk_cell_renderer_get_alignment(cell, &xalign, &yalign);

if (cellicon->fixed_width > 0)
{
Expand Down Expand Up @@ -591,8 +595,8 @@ gqv_cell_renderer_icon_get_size(GtkCellRenderer *cell,
calc_width = MAX(calc_width, TOGGLE_SPACING * cellicon->num_marks);
}

calc_width += (gint)cell->xpad * 2;
calc_height += (gint)cell->ypad * 2;
calc_width += xpad * 2;
calc_height += ypad * 2;

if (x_offset) *x_offset = 0;
if (y_offset) *y_offset = 0;
Expand All @@ -601,13 +605,13 @@ gqv_cell_renderer_icon_get_size(GtkCellRenderer *cell,
{
if (x_offset)
{
*x_offset = (cell->xalign * (cell_area->width - calc_width - 2 * cell->xpad));
*x_offset = MAX(*x_offset, 0) + cell->xpad;
*x_offset = (xalign * (cell_area->width - calc_width - 2 * xpad));
*x_offset = MAX(*x_offset, 0) + xpad;
}
if (y_offset)
{
*y_offset = (cell->yalign * (cell_area->height - calc_height - 2 * cell->ypad));
*y_offset = MAX(*y_offset, 0) + cell->ypad;
*y_offset = (yalign * (cell_area->height - calc_height - 2 * ypad));
*y_offset = MAX(*y_offset, 0) + ypad;
}
}

Expand All @@ -630,20 +634,24 @@ gqv_cell_renderer_icon_render(GtkCellRenderer *cell,
const gchar *text;
GdkRectangle cell_rect;
GtkStateType state;
gint xpad, ypad;


pixbuf = cellicon->pixbuf;
text = cellicon->text;

if (!pixbuf && !text) return;

gtk_cell_renderer_get_padding(cell, &xpad, &ypad);

gqv_cell_renderer_icon_get_size(cell, widget, cell_area,
&cell_rect.x, &cell_rect.y,
&cell_rect.width, &cell_rect.height);

cell_rect.x += cell->xpad;
cell_rect.y += cell->ypad;
cell_rect.width -= cell->xpad * 2;
cell_rect.height -= cell->ypad * 2;
cell_rect.x += xpad;
cell_rect.y += ypad;
cell_rect.width -= xpad * 2;
cell_rect.height -= ypad * 2;

if ((flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED)
{
Expand Down Expand Up @@ -680,7 +688,7 @@ gqv_cell_renderer_icon_render(GtkCellRenderer *cell,

if (cellicon->fixed_height > 0)
{
pix_rect.y = cell_area->y + cell->ypad + (cellicon->fixed_height - pix_rect.height) / 2;
pix_rect.y = cell_area->y + ypad + (cellicon->fixed_height - pix_rect.height) / 2;
}
else
{
Expand Down Expand Up @@ -717,8 +725,8 @@ gqv_cell_renderer_icon_render(GtkCellRenderer *cell,

pix_rect.width = text_rect.width;
pix_rect.height = text_rect.height;
pix_rect.x = cell_area->x + cell->xpad + (cell_rect.width - text_rect.width + 1) / 2;
pix_rect.y = cell_area->y + cell->ypad + (cell_rect.height - text_rect.height);
pix_rect.x = cell_area->x + xpad + (cell_rect.width - text_rect.width + 1) / 2;
pix_rect.y = cell_area->y + ypad + (cell_rect.height - text_rect.height);

if (cellicon->show_marks)
{
Expand Down Expand Up @@ -747,8 +755,8 @@ gqv_cell_renderer_icon_render(GtkCellRenderer *cell,

pix_rect.width = TOGGLE_SPACING * cellicon->num_marks;
pix_rect.height = TOGGLE_SPACING;
pix_rect.x = cell_area->x + cell->xpad + (cell_rect.width - pix_rect.width + 1) / 2 + (TOGGLE_SPACING - TOGGLE_WIDTH) / 2;
pix_rect.y = cell_area->y + cell->ypad + (cell_rect.height - pix_rect.height) + (TOGGLE_SPACING - TOGGLE_WIDTH) / 2;
pix_rect.x = cell_area->x + xpad + (cell_rect.width - pix_rect.width + 1) / 2 + (TOGGLE_SPACING - TOGGLE_WIDTH) / 2;
pix_rect.y = cell_area->y + ypad + (cell_rect.height - pix_rect.height) + (TOGGLE_SPACING - TOGGLE_WIDTH) / 2;

if (gdk_rectangle_intersect(cell_area, &pix_rect, &draw_rect) &&
gdk_rectangle_intersect(expose_area, &draw_rect, &draw_rect))
Expand Down Expand Up @@ -800,22 +808,25 @@ gqv_cell_renderer_icon_activate(GtkCellRenderer *cell,
GdkRectangle rect;
GdkRectangle cell_rect;
gint i;
gint xpad, ypad;

gtk_cell_renderer_get_padding(cell, &xpad, &ypad);

gqv_cell_renderer_icon_get_size(cell, widget, cell_area,
&cell_rect.x, &cell_rect.y,
&cell_rect.width, &cell_rect.height);

cell_rect.x += cell->xpad;
cell_rect.y += cell->ypad;
cell_rect.width -= cell->xpad * 2;
cell_rect.height -= cell->ypad * 2;
cell_rect.x += xpad;
cell_rect.y += ypad;
cell_rect.width -= xpad * 2;
cell_rect.height -= ypad * 2;

rect.width = TOGGLE_WIDTH;
rect.height = TOGGLE_WIDTH;
rect.y = cell_area->y + cell->ypad + (cell_rect.height - TOGGLE_SPACING) + (TOGGLE_SPACING - TOGGLE_WIDTH) / 2;
rect.y = cell_area->y + ypad + (cell_rect.height - TOGGLE_SPACING) + (TOGGLE_SPACING - TOGGLE_WIDTH) / 2;
for (i = 0; i < cellicon->num_marks; i++)
{
rect.x = cell_area->x + cell->xpad + (cell_rect.width - TOGGLE_SPACING * cellicon->num_marks + 1) / 2 + i * TOGGLE_SPACING;
rect.x = cell_area->x + xpad + (cell_rect.width - TOGGLE_SPACING * cellicon->num_marks + 1) / 2 + i * TOGGLE_SPACING;

if (bevent->x >= rect.x && bevent->x < rect.x + rect.width &&
bevent->y >= rect.y && bevent->y < rect.y + rect.height)
Expand Down
Loading

0 comments on commit dc0a8b7

Please sign in to comment.