[473884]: src / rox_panel_icon.c Maximize Restore History

Download this file

rox_panel_icon.c    209 lines (177 with data), 6.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/*
rox-media (Media) - DeviceKit-disks utility for ROX
Copyright (C) 2009 Tony Houghton <h@realh.co.uk>
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, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "rox_panel_icon.h"
#include "rox_panel_icon_priv.h"
#include "rox_panel_info.h"
#define H_ROX_PANEL_ICON_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE((obj), \
H_TYPE_ROX_PANEL_ICON, HRoxPanelIconPrivate))
static void
size_allocate(GtkWidget *widget, GtkAllocation *allocation, HRoxPanelIcon *self)
{
HPanelIcon *iself = H_PANEL_ICON(self);
int width, height;
if (h_panel_icon_get_panel_orientation(iself) == GTK_ORIENTATION_VERTICAL)
{
width = allocation->width;
height = -1;
}
else
{
width = -1;
height = allocation->height;
}
h_panel_icon_size_set(iself, width, height);
}
static void
show_pixbuf(HPanelIcon *iself, GdkPixbuf *pixbuf)
{
HRoxPanelIcon *self = H_ROX_PANEL_ICON(iself);
HRoxPanelIconPrivate *priv = self->priv;
int width, height;
gtk_image_set_from_pixbuf(GTK_IMAGE(priv->image), pixbuf);
width = gdk_pixbuf_get_width(pixbuf);
height = gdk_pixbuf_get_height(pixbuf);
gtk_widget_set_size_request(priv->image, width, height);
}
static GtkOrientation
get_panel_orientation(HPanelIcon *iself)
{
return rox_panel_info_get_orientation(
gtk_widget_get_parent(GTK_WIDGET(iself)));
}
static void
position_menu(GtkMenu *menu, int *x, int *y, gboolean *push_in,
gpointer widget)
{
GtkRequisition req;
GdkScreen *screen;
int monitor;
int x0, y0, width, height;
GtkPositionType panel_pos = rox_panel_info_get_position(widget);
GdkRectangle mon_geom;
gtk_widget_size_request(GTK_WIDGET(menu), &req);
rox_panel_info_get_icon_position(widget, &screen, &monitor,
&x0, &y0, &width, &height);
gtk_menu_set_screen(menu, screen);
gtk_menu_set_monitor(menu, monitor);
gdk_screen_get_monitor_geometry(screen, monitor, &mon_geom);
if (panel_pos == GTK_POS_LEFT)
{
*x = x0 + width;
}
else if (panel_pos == GTK_POS_RIGHT)
{
*x = x0 - req.width;
}
else
{
*x = x0 + (width - req.width) / 2;
}
if (panel_pos == GTK_POS_TOP)
{
*y = y0 + height;
}
else if (panel_pos == GTK_POS_BOTTOM)
{
*y = y0 - req.height;
}
else
{
*y = y0 + (height - req.height) / 2;
}
*x = CLAMP(*x, mon_geom.x, mon_geom.x + mon_geom.width);
*y = CLAMP(*y, mon_geom.y, mon_geom.y + mon_geom.height);
*push_in = FALSE;
}
static GtkMenuPositionFunc
get_menu_position_func(HPanelIcon *iself)
{
return position_menu;
}
static HPanelIconData *
get_icon_data(HPanelIcon *iself)
{
return &(H_ROX_PANEL_ICON(iself)->priv->icon_data);
}
static void destroy(HPanelIcon *iself)
{
H_ROX_PANEL_ICON(iself)->priv->image = NULL;
gtk_widget_destroy(GTK_WIDGET(iself));
}
typedef void (*SetTooltipFunc)(HPanelIcon *, const char *);
typedef char *(*GetTooltipFunc)(HPanelIcon *);
static void
h_rox_panel_icon_init_h_panel_icon(HPanelIconInterface *iface)
{
iface->set_icon_source = h_panel_icon_standard_set_icon_source;
iface->destroy = destroy;
iface->set_tooltip_text = (SetTooltipFunc) gtk_widget_set_tooltip_text;
iface->get_tooltip_text = (GetTooltipFunc) gtk_widget_get_tooltip_text;
iface->set_tooltip_markup = (SetTooltipFunc) gtk_widget_set_tooltip_markup;
iface->get_tooltip_markup = (GetTooltipFunc) gtk_widget_get_tooltip_markup;
iface->size_set = h_panel_icon_standard_size_set;
iface->show_pixbuf = show_pixbuf;
iface->get_panel_orientation = get_panel_orientation;
iface->get_menu_position_func = get_menu_position_func;
iface->get_data = get_icon_data;
}
G_DEFINE_TYPE_WITH_CODE(HRoxPanelIcon, h_rox_panel_icon, GTK_TYPE_EVENT_BOX,
G_IMPLEMENT_INTERFACE(H_TYPE_PANEL_ICON,
h_rox_panel_icon_init_h_panel_icon));
static void
h_rox_panel_icon_init(HRoxPanelIcon *self)
{
HRoxPanelIconPrivate *priv = self->priv =
H_ROX_PANEL_ICON_GET_PRIVATE(self);
h_panel_icon_data_init(&priv->icon_data);
priv->image = gtk_image_new();
g_signal_connect(priv->image, "size-allocate",
G_CALLBACK(size_allocate), self);
gtk_container_add(GTK_CONTAINER(self), priv->image);
gtk_widget_set_size_request(priv->image, 8, 8);
}
static void
h_rox_panel_icon_dispose(GObject *gobj)
{
HRoxPanelIcon *self = H_ROX_PANEL_ICON(gobj);
HRoxPanelIconPrivate *priv = self->priv;
h_panel_icon_data_dispose(&priv->icon_data);
G_OBJECT_CLASS(h_rox_panel_icon_parent_class)->dispose(gobj);
}
static void
h_rox_panel_icon_finalize(GObject *gobj)
{
G_OBJECT_CLASS(h_rox_panel_icon_parent_class)->finalize(gobj);
}
static void
h_rox_panel_icon_class_init(HRoxPanelIconClass *klass)
{
GObjectClass *gclass;
g_type_class_add_private(klass, sizeof(HRoxPanelIconPrivate));
gclass = G_OBJECT_CLASS(klass);
gclass->dispose = h_rox_panel_icon_dispose;
gclass->finalize = h_rox_panel_icon_finalize;
}
HRoxPanelIcon *
h_rox_panel_icon_new(HIconSource *source)
{
HRoxPanelIcon *self =
H_ROX_PANEL_ICON(g_object_new(H_TYPE_ROX_PANEL_ICON, NULL));
if (source)
h_panel_icon_set_icon_source(H_PANEL_ICON(self), source);
return self;
}