~ubuntu-branches/ubuntu/hardy/uim/hardy

« back to all changes in this revision

Viewing changes to helper/toolbar-standalone-gtk.c

  • Committer: Bazaar Package Importer
  • Author(s): Masahito Omote
  • Date: 2007-04-21 03:46:09 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20070421034609-gpcurkutp8vaysqj
Tags: 1:1.4.1-3
* Switch to dh_gtkmodules for the gtk 2.10 transition (Closes:
  #419318)
  - debian/control: Add ${misc:Depends} and remove libgtk2.0-bin on
    uim-gtk2.0.
  - debian/uim-gtk2.0.post{inst,rm}: Removed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
  toolbar-standalone-gtk.c: toolbar implementation with GTK+
4
4
 
5
 
  Copyright (c) 2003-2006 uim Project http://uim.freedesktop.org/
 
5
  Copyright (c) 2003-2007 uim Project http://uim.freedesktop.org/
6
6
 
7
7
  All rights reserved.
8
8
 
61
61
static void
62
62
delete_event(GtkWidget *widget, gpointer data)
63
63
{
64
 
  gtk_main_quit ();
 
64
  gtk_main_quit();
65
65
}
66
66
 
67
67
static gboolean
68
68
button_press_event_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
69
69
{
70
70
  GdkCursor *cursor;
71
 
 
72
 
  cursor = gdk_cursor_new (GDK_CROSSHAIR);
73
 
  gdk_pointer_grab(widget->window, FALSE,
74
 
                   GDK_BUTTON_RELEASE_MASK |
75
 
                   GDK_POINTER_MOTION_MASK,
76
 
                   NULL,
77
 
                   cursor, event->time);
78
 
  gdk_cursor_destroy (cursor);
79
 
 
80
 
  gtk_window_get_position(GTK_WINDOW(widget),
81
 
                          &window_drag_start_x,
82
 
                          &window_drag_start_y);
83
 
 
84
 
  pointer_drag_start_x = (gint) event->x_root;
85
 
  pointer_drag_start_y = (gint) event->y_root;
86
 
 
87
 
  toolbar_dragging = TRUE;
 
71
  GtkWidget *toolbar;
 
72
  gint height, width;
 
73
 
 
74
  switch (event->type) {
 
75
  case GDK_BUTTON_PRESS:
 
76
    cursor = gdk_cursor_new(GDK_FLEUR);
 
77
    gdk_pointer_grab(widget->window, FALSE,
 
78
                     GDK_BUTTON_RELEASE_MASK |
 
79
                     GDK_POINTER_MOTION_MASK,
 
80
                     NULL,
 
81
                     cursor, event->time);
 
82
    gdk_cursor_destroy(cursor);
 
83
 
 
84
    gtk_window_get_position(GTK_WINDOW(widget),
 
85
                            &window_drag_start_x,
 
86
                            &window_drag_start_y);
 
87
    pointer_drag_start_x = (gint)event->x_root;
 
88
    pointer_drag_start_y = (gint)event->y_root;
 
89
    toolbar_dragging = TRUE;
 
90
    break;
 
91
  case GDK_2BUTTON_PRESS:
 
92
    toolbar = GTK_WIDGET(data);
 
93
    if (GTK_WIDGET_VISIBLE(toolbar)) {
 
94
      gtk_window_get_size(GTK_WINDOW(widget), &width, &height);
 
95
      gtk_widget_hide(toolbar);
 
96
    } else {
 
97
      height = -1;
 
98
      gtk_widget_show(toolbar);
 
99
    }
 
100
    gtk_widget_set_size_request(widget, -1, height);
 
101
    break;
 
102
  default:
 
103
    break;
 
104
  }
88
105
 
89
106
  return FALSE;
90
107
}
92
109
static void
93
110
helper_win_set_position(GtkWidget *window, gint x, gint y)
94
111
{
95
 
    gint wx = x, wy = y;
96
 
    gint w, h, sc_w, sc_h;
97
 
 
98
 
    sc_w = gdk_screen_width();
99
 
    sc_h = gdk_screen_height();
100
 
 
101
 
    gdk_window_get_size(window->window, &w, &h);
102
 
 
103
 
    if (wx < 0)
104
 
      wx = 0;
105
 
    else if (wx > sc_w - w)
106
 
      wx = sc_w - w;
107
 
    if (wy < 0)
108
 
      wy = 0;
109
 
    else if (wy > sc_h - h)
110
 
      wy = sc_h -h;
111
 
 
112
 
    gtk_window_move(GTK_WINDOW(window), wx, wy);
 
112
  gint wx = x, wy = y;
 
113
  gint w, h, sc_w, sc_h;
 
114
 
 
115
  sc_w = gdk_screen_width();
 
116
  sc_h = gdk_screen_height();
 
117
 
 
118
  gdk_window_get_size(window->window, &w, &h);
 
119
 
 
120
  if (wx < 0)
 
121
    wx = 0;
 
122
  else if (wx > sc_w - w)
 
123
    wx = sc_w - w;
 
124
  if (wy < 0)
 
125
    wy = 0;
 
126
  else if (wy > sc_h - h)
 
127
    wy = sc_h -h;
 
128
 
 
129
  gtk_window_move(GTK_WINDOW(window), wx, wy);
113
130
}
114
131
 
115
132
static gboolean
124
141
 
125
142
    gdk_window_get_size(widget->window, &w, &h);
126
143
 
127
 
    wx = window_drag_start_x + ((gint) event->x_root - pointer_drag_start_x);
128
 
    wy = window_drag_start_y + ((gint) event->y_root - pointer_drag_start_y);
 
144
    wx = window_drag_start_x + ((gint)event->x_root - pointer_drag_start_x);
 
145
    wy = window_drag_start_y + ((gint)event->y_root - pointer_drag_start_y);
129
146
 
130
147
    helper_win_set_position(widget, wx, wy);
131
148
 
138
155
static gboolean
139
156
button_release_event_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
140
157
{
 
158
  if (!toolbar_dragging)
 
159
    return FALSE;
 
160
 
141
161
  gdk_pointer_ungrab(event->time);
142
162
 
143
163
  pointer_drag_start_x = -1;
187
207
}
188
208
 
189
209
int
190
 
main (int argc, char *argv[])
 
210
main(int argc, char *argv[])
191
211
{
192
212
  GtkWidget *toolbar;
193
213
  GtkWidget *window;
196
216
  GtkWidget *frame;
197
217
 
198
218
  setlocale(LC_ALL, "");
199
 
  bindtextdomain( PACKAGE, LOCALEDIR );
200
 
  textdomain( PACKAGE );
201
 
  bind_textdomain_codeset( PACKAGE, "UTF-8");
 
219
  bindtextdomain(PACKAGE, LOCALEDIR);
 
220
  textdomain(PACKAGE);
 
221
  bind_textdomain_codeset(PACKAGE, "UTF-8");
202
222
 
203
223
  uim_init();
204
224
 
211
231
  gtk_window_set_type_hint(GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_DOCK);
212
232
 
213
233
  gtk_window_set_skip_taskbar_hint(GTK_WINDOW(window), TRUE);
214
 
  gtk_window_set_decorated (GTK_WINDOW(window), FALSE);
 
234
  gtk_window_set_decorated(GTK_WINDOW(window), FALSE);
215
235
  gtk_window_stick(GTK_WINDOW(window));
216
236
 
217
237
  gtk_widget_add_events(window, GDK_BUTTON_PRESS_MASK);
218
238
 
219
 
  g_signal_connect(G_OBJECT (window), "delete_event",
220
 
                   G_CALLBACK (delete_event), NULL);
221
 
 
 
239
  frame = gtk_frame_new(NULL);
 
240
  gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_OUT);
 
241
  gtk_container_add(GTK_CONTAINER(window), frame);
 
242
 
 
243
  hbox = gtk_hbox_new(FALSE, 0);
 
244
  gtk_container_add(GTK_CONTAINER(frame), hbox);
 
245
 
 
246
  handle = gtk_drawing_area_new();
 
247
  gtk_widget_set_size_request(handle, 8, -1);
 
248
  gtk_box_pack_start(GTK_BOX(hbox), handle, FALSE, FALSE, 0);
 
249
 
 
250
  toolbar = (GtkWidget*)uim_toolbar_standalone_new();
 
251
  gtk_box_pack_start(GTK_BOX(hbox), toolbar, FALSE, FALSE, 0);
 
252
 
 
253
  g_signal_connect(G_OBJECT(handle), "expose-event",
 
254
                   G_CALLBACK(handle_expose_event_cb), NULL);
 
255
 
 
256
  g_signal_connect(G_OBJECT(window), "delete_event",
 
257
                   G_CALLBACK(delete_event), NULL);
222
258
  g_signal_connect(G_OBJECT(window), "button-press-event",
223
 
                   G_CALLBACK(button_press_event_cb), NULL);
 
259
                   G_CALLBACK(button_press_event_cb), toolbar);
224
260
  g_signal_connect(G_OBJECT(window), "button-release-event",
225
261
                   G_CALLBACK(button_release_event_cb), NULL);
226
262
  g_signal_connect(G_OBJECT(window), "motion-notify-event",
227
263
                   G_CALLBACK(motion_notify_event_cb), NULL);
228
264
  g_signal_connect(G_OBJECT(window), "size-allocate",
229
265
                   G_CALLBACK(size_allocate_cb), NULL);
230
 
 
231
 
  frame = gtk_frame_new(NULL);
232
 
  gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_OUT);
233
 
  gtk_container_add (GTK_CONTAINER (window), frame);
234
 
 
235
 
  hbox = gtk_hbox_new (FALSE, 0);
236
 
  gtk_container_add (GTK_CONTAINER (frame), hbox);
237
 
 
238
 
  handle = gtk_drawing_area_new();
239
 
  g_signal_connect(G_OBJECT (handle), "expose-event",
240
 
                   G_CALLBACK (handle_expose_event_cb), NULL);
241
 
  gtk_widget_set_size_request(handle, 8, -1);
242
 
  gtk_box_pack_start(GTK_BOX (hbox), handle, FALSE, FALSE, 0);
243
 
 
244
 
  toolbar = (GtkWidget*)uim_toolbar_standalone_new();
245
 
  gtk_box_pack_start(GTK_BOX (hbox), toolbar, FALSE, FALSE, 0);
246
266
  g_signal_connect(G_OBJECT(window), "size-request",
247
267
                   G_CALLBACK(size_request_cb), NULL);
248
268
 
249
 
  gtk_widget_show_all(GTK_WIDGET (window));
 
269
  gtk_widget_show_all(GTK_WIDGET(window));
250
270
 
251
271
  if (argc > 1) {
252
 
    if (!gtk_window_parse_geometry(GTK_WINDOW (window), argv[1])) {
 
272
    if (!gtk_window_parse_geometry(GTK_WINDOW(window), argv[1])) {
253
273
 
254
274
#if GLIB_CHECK_VERSION(2, 6, 0)
255
275
      parse_options(argc, argv);