comparison src/gtkwhiteboard.c @ 13467:16544c190fe6

[gaim-migrate @ 15842] Clean up the destroy code, fixing CID 66 for real, I hope. Also, mark all the functions as static. They were marked static in the prototypes, but I don't know if that actually makes them static. committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Wed, 08 Mar 2006 21:31:10 +0000
parents 184d62658af2
children d6912eee114e
comparison
equal deleted inserted replaced
13466:d7b01bcfb031 13467:16544c190fe6
32 * Prototypes 32 * Prototypes
33 *****************************************************************************/ 33 *****************************************************************************/
34 static void gaim_gtk_whiteboard_create(GaimWhiteboard *wb); 34 static void gaim_gtk_whiteboard_create(GaimWhiteboard *wb);
35 35
36 static void gaim_gtk_whiteboard_destroy(GaimWhiteboard *wb); 36 static void gaim_gtk_whiteboard_destroy(GaimWhiteboard *wb);
37 static void gaim_gtk_whiteboard_exit(GtkWidget *widget, gpointer data); 37 static gboolean whiteboard_close_cb(GtkWidget *widget, GdkEvent *event, GaimGtkWhiteboard *gtkwb);
38 38
39 /*static void gaim_gtkwhiteboard_button_start_press(GtkButton *button, gpointer data); */ 39 /*static void gaim_gtkwhiteboard_button_start_press(GtkButton *button, gpointer data); */
40 40
41 static gboolean gaim_gtk_whiteboard_configure_event(GtkWidget *widget, GdkEventConfigure *event, gpointer data); 41 static gboolean gaim_gtk_whiteboard_configure_event(GtkWidget *widget, GdkEventConfigure *event, gpointer data);
42 static gboolean gaim_gtk_whiteboard_expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data); 42 static gboolean gaim_gtk_whiteboard_expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data);
68 *****************************************************************************/ 68 *****************************************************************************/
69 /* 69 /*
70 GList *buttonList = NULL; 70 GList *buttonList = NULL;
71 GdkColor DefaultColor[PALETTE_NUM_COLORS]; 71 GdkColor DefaultColor[PALETTE_NUM_COLORS];
72 */ 72 */
73
74 static gboolean LocalShutdownRequest;
75 73
76 static int LastX; /* Tracks last position of the mouse when drawing */ 74 static int LastX; /* Tracks last position of the mouse when drawing */
77 static int LastY; 75 static int LastY;
78 static int MotionCount; /* Tracks how many brush motions made */ 76 static int MotionCount; /* Tracks how many brush motions made */
79 static int BrushState = BRUSH_STATE_UP; 77 static int BrushState = BRUSH_STATE_UP;
95 GaimWhiteboardUiOps *gaim_gtk_whiteboard_get_ui_ops(void) 93 GaimWhiteboardUiOps *gaim_gtk_whiteboard_get_ui_ops(void)
96 { 94 {
97 return &ui_ops; 95 return &ui_ops;
98 } 96 }
99 97
100 void gaim_gtk_whiteboard_create(GaimWhiteboard *wb) 98 static void gaim_gtk_whiteboard_create(GaimWhiteboard *wb)
101 { 99 {
102 GtkWidget *window; 100 GtkWidget *window;
103 GtkWidget *drawing_area; 101 GtkWidget *drawing_area;
104 GtkWidget *vbox_controls; 102 GtkWidget *vbox_controls;
105 GtkWidget *hbox_canvas_and_controls; 103 GtkWidget *hbox_canvas_and_controls;
154 else 152 else
155 gtk_window_set_title((GtkWindow*)(window), wb->who); 153 gtk_window_set_title((GtkWindow*)(window), wb->who);
156 154
157 gtk_window_set_resizable((GtkWindow*)(window), FALSE); 155 gtk_window_set_resizable((GtkWindow*)(window), FALSE);
158 156
159 g_signal_connect(G_OBJECT(window), "destroy", 157 g_signal_connect(G_OBJECT(window), "delete_event",
160 G_CALLBACK(gaim_gtk_whiteboard_exit), gtkwb); 158 G_CALLBACK(whiteboard_close_cb), gtkwb);
161 159
162 #if 0 160 #if 0
163 int i; 161 int i;
164 162
165 GtkWidget *hbox_palette; 163 GtkWidget *hbox_palette;
271 ds->brush_size = DOODLE_BRUSH_MEDIUM; 269 ds->brush_size = DOODLE_BRUSH_MEDIUM;
272 ds->brush_color = 0; 270 ds->brush_color = 0;
273 */ 271 */
274 } 272 }
275 273
276 void gaim_gtk_whiteboard_destroy(GaimWhiteboard *wb) 274 static void gaim_gtk_whiteboard_destroy(GaimWhiteboard *wb)
277 { 275 {
278 GaimGtkWhiteboard *gtkwb = wb->ui_data; 276 GaimGtkWhiteboard *gtkwb;
277
278 g_return_if_fail(wb != NULL);
279 gtkwb = wb->ui_data;
280 g_return_if_fail(gtkwb != NULL);
279 281
280 /* TODO Ask if user wants to save picture before the session is closed */ 282 /* TODO Ask if user wants to save picture before the session is closed */
281 283
282 /* Clear graphical memory */ 284 /* Clear graphical memory */
283 if(gtkwb->pixmap) 285 if(gtkwb->pixmap)
289 if(gtkwb->window) 291 if(gtkwb->window)
290 { 292 {
291 gtk_widget_destroy(gtkwb->window); 293 gtk_widget_destroy(gtkwb->window);
292 gtkwb->window = NULL; 294 gtkwb->window = NULL;
293 } 295 }
294 } 296 g_free(gtkwb);
295 297 wb->ui_data = NULL;
296 void gaim_gtk_whiteboard_exit(GtkWidget *widget, gpointer data) 298 }
297 { 299
298 GaimGtkWhiteboard *gtkwb = (GaimGtkWhiteboard*)data; 300 static gboolean whiteboard_close_cb(GtkWidget *widget, GdkEvent *event, GaimGtkWhiteboard *gtkwb)
301 {
299 GaimWhiteboard *wb; 302 GaimWhiteboard *wb;
300 303
301 g_return_if_fail(gtkwb != NULL); 304 g_return_if_fail(gtkwb != NULL);
302 wb = gtkwb->wb; 305 wb = gtkwb->wb;
303 306 g_return_if_fail(wb != NULL);
304 if(gtkwb->window && gtkwb->pixmap) 307
305 { 308 gaim_whiteboard_destroy(wb);
306 LocalShutdownRequest = TRUE; 309
307 310 return FALSE;
308 gaim_gtk_whiteboard_destroy(wb);
309 }
310 else
311 LocalShutdownRequest = FALSE;
312
313 g_free(gtkwb);
314 wb->ui_data = NULL;
315
316 /* Destroy whiteboard core, if the local user exited the whiteboard window */
317 if(wb && LocalShutdownRequest)
318 {
319 gaim_whiteboard_destroy(wb);
320 }
321 } 311 }
322 312
323 /* 313 /*
324 * Whiteboard start button on conversation window (move this code to gtkconv? 314 * Whiteboard start button on conversation window (move this code to gtkconv?
325 * and use new prpl_info member?) 315 * and use new prpl_info member?)
326 */ 316 */
327 #if 0 317 #if 0
328 void gaim_gtkwhiteboard_button_start_press(GtkButton *button, gpointer data) 318 static void gaim_gtkwhiteboard_button_start_press(GtkButton *button, gpointer data)
329 { 319 {
330 GaimConversation *conv = data; 320 GaimConversation *conv = data;
331 GaimAccount *account = gaim_conversation_get_account(conv); 321 GaimAccount *account = gaim_conversation_get_account(conv);
332 GaimConnection *gc = gaim_account_get_connection(account); 322 GaimConnection *gc = gaim_account_get_connection(account);
333 char *to = (char*)(gaim_conversation_get_name(conv)); 323 char *to = (char*)(gaim_conversation_get_name(conv));
338 GaimWhiteboard *wb = gaim_whiteboard_get(account, to); 328 GaimWhiteboard *wb = gaim_whiteboard_get(account, to);
339 329
340 /* Write a local message to this conversation showing that a request for a 330 /* Write a local message to this conversation showing that a request for a
341 * Doodle session has been made 331 * Doodle session has been made
342 */ 332 */
343 gaim_conv_im_write(GAIM_CONV_IM(conv), "", _("Sent Doodle request."), 333 /* XXXX because otherwise gettext will see this string, even though it's
334 * in an #if 0 block. Remove the XXXX if you want to use this code.
335 * But, it really shouldn't be a Yahoo-specific string. ;) */
336 gaim_conv_im_write(GAIM_CONV_IM(conv), "", XXXX_("Sent Doodle request."),
344 GAIM_MESSAGE_NICK | GAIM_MESSAGE_RECV, time(NULL)); 337 GAIM_MESSAGE_NICK | GAIM_MESSAGE_RECV, time(NULL));
345 338
346 yahoo_doodle_command_send_request(gc, to); 339 yahoo_doodle_command_send_request(gc, to);
347 yahoo_doodle_command_send_ready(gc, to); 340 yahoo_doodle_command_send_ready(gc, to);
348 341
351 */ 344 */
352 wb = gaim_whiteboard_create(account, to, DOODLE_STATE_REQUESTING); 345 wb = gaim_whiteboard_create(account, to, DOODLE_STATE_REQUESTING);
353 } 346 }
354 #endif 347 #endif
355 348
356 gboolean gaim_gtk_whiteboard_configure_event(GtkWidget *widget, GdkEventConfigure *event, gpointer data) 349 static gboolean gaim_gtk_whiteboard_configure_event(GtkWidget *widget, GdkEventConfigure *event, gpointer data)
357 { 350 {
358 GaimGtkWhiteboard *gtkwb = (GaimGtkWhiteboard*)data; 351 GaimGtkWhiteboard *gtkwb = (GaimGtkWhiteboard*)data;
359 352
360 GdkPixmap *pixmap = gtkwb->pixmap; 353 GdkPixmap *pixmap = gtkwb->pixmap;
361 354
377 widget->allocation.height); 370 widget->allocation.height);
378 371
379 return TRUE; 372 return TRUE;
380 } 373 }
381 374
382 gboolean gaim_gtk_whiteboard_expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data) 375 static gboolean gaim_gtk_whiteboard_expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data)
383 { 376 {
384 GaimGtkWhiteboard *gtkwb = (GaimGtkWhiteboard*)(data); 377 GaimGtkWhiteboard *gtkwb = (GaimGtkWhiteboard*)(data);
385 GdkPixmap *pixmap = gtkwb->pixmap; 378 GdkPixmap *pixmap = gtkwb->pixmap;
386 379
387 gdk_draw_drawable(widget->window, 380 gdk_draw_drawable(widget->window,
392 event->area.width, event->area.height); 385 event->area.width, event->area.height);
393 386
394 return FALSE; 387 return FALSE;
395 } 388 }
396 389
397 gboolean gaim_gtk_whiteboard_brush_down(GtkWidget *widget, GdkEventButton *event, gpointer data) 390 static gboolean gaim_gtk_whiteboard_brush_down(GtkWidget *widget, GdkEventButton *event, gpointer data)
398 { 391 {
399 GaimGtkWhiteboard *gtkwb = (GaimGtkWhiteboard*)data; 392 GaimGtkWhiteboard *gtkwb = (GaimGtkWhiteboard*)data;
400 GdkPixmap *pixmap = gtkwb->pixmap; 393 GdkPixmap *pixmap = gtkwb->pixmap;
401 394
402 GaimWhiteboard *wb = gtkwb->wb; 395 GaimWhiteboard *wb = gtkwb->wb;
438 wb->draw_list = draw_list; 431 wb->draw_list = draw_list;
439 432
440 return TRUE; 433 return TRUE;
441 } 434 }
442 435
443 gboolean gaim_gtk_whiteboard_brush_motion(GtkWidget *widget, GdkEventMotion *event, gpointer data) 436 static gboolean gaim_gtk_whiteboard_brush_motion(GtkWidget *widget, GdkEventMotion *event, gpointer data)
444 { 437 {
445 int x; 438 int x;
446 int y; 439 int y;
447 int dx; 440 int dx;
448 int dy; 441 int dy;
525 wb->draw_list = draw_list; 518 wb->draw_list = draw_list;
526 519
527 return TRUE; 520 return TRUE;
528 } 521 }
529 522
530 gboolean gaim_gtk_whiteboard_brush_up(GtkWidget *widget, GdkEventButton *event, gpointer data) 523 static gboolean gaim_gtk_whiteboard_brush_up(GtkWidget *widget, GdkEventButton *event, gpointer data)
531 { 524 {
532 GaimGtkWhiteboard *gtkwb = (GaimGtkWhiteboard*)data; 525 GaimGtkWhiteboard *gtkwb = (GaimGtkWhiteboard*)data;
533 GdkPixmap *pixmap = gtkwb->pixmap; 526 GdkPixmap *pixmap = gtkwb->pixmap;
534 527
535 GaimWhiteboard *wb = gtkwb->wb; 528 GaimWhiteboard *wb = gtkwb->wb;
581 } 574 }
582 575
583 return TRUE; 576 return TRUE;
584 } 577 }
585 578
586 void gaim_gtk_whiteboard_draw_brush_point(GaimWhiteboard *wb, int x, int y, int color, int size) 579 static void gaim_gtk_whiteboard_draw_brush_point(GaimWhiteboard *wb, int x, int y, int color, int size)
587 { 580 {
588 GaimGtkWhiteboard *gtkwb = wb->ui_data; 581 GaimGtkWhiteboard *gtkwb = wb->ui_data;
589 GtkWidget *widget = gtkwb->drawing_area; 582 GtkWidget *widget = gtkwb->drawing_area;
590 GdkPixmap *pixmap = gtkwb->pixmap; 583 GdkPixmap *pixmap = gtkwb->pixmap;
591 584
634 627
635 gdk_gc_unref(gfx_con); 628 gdk_gc_unref(gfx_con);
636 } 629 }
637 630
638 /* Uses Bresenham's algorithm (as provided by Wikipedia) */ 631 /* Uses Bresenham's algorithm (as provided by Wikipedia) */
639 void gaim_gtk_whiteboard_draw_brush_line(GaimWhiteboard *wb, int x0, int y0, int x1, int y1, int color, int size) 632 static void gaim_gtk_whiteboard_draw_brush_line(GaimWhiteboard *wb, int x0, int y0, int x1, int y1, int color, int size)
640 { 633 {
641 int temp; 634 int temp;
642 635
643 int xstep; 636 int xstep;
644 int ystep; 637 int ystep;
700 else 693 else
701 gaim_gtk_whiteboard_draw_brush_point(wb, x, y, color, size); 694 gaim_gtk_whiteboard_draw_brush_point(wb, x, y, color, size);
702 } 695 }
703 } 696 }
704 697
705 void gaim_gtk_whiteboard_set_dimensions(GaimWhiteboard *wb, int width, int height) 698 static void gaim_gtk_whiteboard_set_dimensions(GaimWhiteboard *wb, int width, int height)
706 { 699 {
707 GaimGtkWhiteboard *gtkwb = wb->ui_data; 700 GaimGtkWhiteboard *gtkwb = wb->ui_data;
708 701
709 gtkwb->width = width; 702 gtkwb->width = width;
710 gtkwb->height = height; 703 gtkwb->height = height;
711 } 704 }
712 705
713 void gaim_gtk_whiteboard_set_brush(GaimWhiteboard *wb, int size, int color) 706 static void gaim_gtk_whiteboard_set_brush(GaimWhiteboard *wb, int size, int color)
714 { 707 {
715 GaimGtkWhiteboard *gtkwb = wb->ui_data; 708 GaimGtkWhiteboard *gtkwb = wb->ui_data;
716 709
717 gtkwb->brush_size = size; 710 gtkwb->brush_size = size;
718 gtkwb->brush_color = color; 711 gtkwb->brush_color = color;
719 } 712 }
720 713
721 void gaim_gtk_whiteboard_clear(GaimWhiteboard *wb) 714 static void gaim_gtk_whiteboard_clear(GaimWhiteboard *wb)
722 { 715 {
723 GaimGtkWhiteboard *gtkwb = wb->ui_data; 716 GaimGtkWhiteboard *gtkwb = wb->ui_data;
724 GdkPixmap *pixmap = gtkwb->pixmap; 717 GdkPixmap *pixmap = gtkwb->pixmap;
725 GtkWidget *drawing_area = gtkwb->drawing_area; 718 GtkWidget *drawing_area = gtkwb->drawing_area;
726 719
735 0, 0, 728 0, 0,
736 drawing_area->allocation.width, 729 drawing_area->allocation.width,
737 drawing_area->allocation.height); 730 drawing_area->allocation.height);
738 } 731 }
739 732
740 void gaim_gtk_whiteboard_button_clear_press(GtkWidget *widget, gpointer data) 733 static void gaim_gtk_whiteboard_button_clear_press(GtkWidget *widget, gpointer data)
741 { 734 {
742 GaimGtkWhiteboard *gtkwb = (GaimGtkWhiteboard*)(data); 735 GaimGtkWhiteboard *gtkwb = (GaimGtkWhiteboard*)(data);
743 736
744 gaim_gtk_whiteboard_clear(gtkwb->wb); 737 gaim_gtk_whiteboard_clear(gtkwb->wb);
745 738
747 740
748 /* Do protocol specific clearing procedures */ 741 /* Do protocol specific clearing procedures */
749 gaim_whiteboard_send_clear(gtkwb->wb); 742 gaim_whiteboard_send_clear(gtkwb->wb);
750 } 743 }
751 744
752 void gaim_gtk_whiteboard_button_save_press(GtkWidget *widget, gpointer data) 745 static void gaim_gtk_whiteboard_button_save_press(GtkWidget *widget, gpointer data)
753 { 746 {
754 GaimGtkWhiteboard *gtkwb = (GaimGtkWhiteboard*)(data); 747 GaimGtkWhiteboard *gtkwb = (GaimGtkWhiteboard*)(data);
755 GdkPixbuf *pixbuf; 748 GdkPixbuf *pixbuf;
756 749
757 GtkWidget *dialog; 750 GtkWidget *dialog;
814 807
815 gaim_debug_info("gtkwhiteboard", "File not Saved... Canceled\n"); 808 gaim_debug_info("gtkwhiteboard", "File not Saved... Canceled\n");
816 } 809 }
817 } 810 }
818 811
819 void gaim_gtk_whiteboard_set_canvas_as_icon(GaimGtkWhiteboard *gtkwb) 812 static void gaim_gtk_whiteboard_set_canvas_as_icon(GaimGtkWhiteboard *gtkwb)
820 { 813 {
821 GdkPixbuf *pixbuf; 814 GdkPixbuf *pixbuf;
822 815
823 /* Makes an icon from the whiteboard's canvas 'image' */ 816 /* Makes an icon from the whiteboard's canvas 'image' */
824 pixbuf = gdk_pixbuf_get_from_drawable(NULL, 817 pixbuf = gdk_pixbuf_get_from_drawable(NULL,
829 gtkwb->width, gtkwb->height); 822 gtkwb->width, gtkwb->height);
830 823
831 gtk_window_set_icon((GtkWindow*)(gtkwb->window), pixbuf); 824 gtk_window_set_icon((GtkWindow*)(gtkwb->window), pixbuf);
832 } 825 }
833 826
834 void gaim_gtk_whiteboard_rgb24_to_rgb48(int color_rgb, GdkColor *color) 827 static void gaim_gtk_whiteboard_rgb24_to_rgb48(int color_rgb, GdkColor *color)
835 { 828 {
836 color->red = (color_rgb >> 8) | 0xFF; 829 color->red = (color_rgb >> 8) | 0xFF;
837 color->green = (color_rgb & 0xFF00) | 0xFF; 830 color->green = (color_rgb & 0xFF00) | 0xFF;
838 color->blue = ((color_rgb & 0xFF) << 8) | 0xFF; 831 color->blue = ((color_rgb & 0xFF) << 8) | 0xFF;
839 } 832 }