4 * Pidgin is the legal property of its developers, whose names are too numerous
5 * to list here. Please refer to the COPYRIGHT file distributed with this
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
28 #include "gtkwhiteboard.h"
31 /******************************************************************************
33 *****************************************************************************/
34 static void pidgin_whiteboard_create(PurpleWhiteboard
*wb
);
36 static void pidgin_whiteboard_destroy(PurpleWhiteboard
*wb
);
37 static gboolean
whiteboard_close_cb(GtkWidget
*widget
, GdkEvent
*event
, PidginWhiteboard
*gtkwb
);
39 /*static void pidginwhiteboard_button_start_press(GtkButton *button, gpointer data); */
41 static gboolean
pidgin_whiteboard_configure_event(GtkWidget
*widget
, GdkEventConfigure
*event
, gpointer data
);
42 static gboolean
pidgin_whiteboard_expose_event(GtkWidget
*widget
, GdkEventExpose
*event
, gpointer data
);
44 static gboolean
pidgin_whiteboard_brush_down(GtkWidget
*widget
, GdkEventButton
*event
, gpointer data
);
45 static gboolean
pidgin_whiteboard_brush_motion(GtkWidget
*widget
, GdkEventMotion
*event
, gpointer data
);
46 static gboolean
pidgin_whiteboard_brush_up(GtkWidget
*widget
, GdkEventButton
*event
, gpointer data
);
48 static void pidgin_whiteboard_draw_brush_point(PurpleWhiteboard
*wb
,
49 int x
, int y
, int color
, int size
);
50 static void pidgin_whiteboard_draw_brush_line(PurpleWhiteboard
*wb
, int x0
, int y0
,
51 int x1
, int y1
, int color
, int size
);
53 static void pidgin_whiteboard_set_dimensions(PurpleWhiteboard
*wb
, int width
, int height
);
54 static void pidgin_whiteboard_set_brush(PurpleWhiteboard
*wb
, int size
, int color
);
55 static void pidgin_whiteboard_clear(PurpleWhiteboard
*wb
);
57 static void pidgin_whiteboard_button_clear_press(GtkWidget
*widget
, gpointer data
);
58 static void pidgin_whiteboard_button_save_press(GtkWidget
*widget
, gpointer data
);
60 static void pidgin_whiteboard_set_canvas_as_icon(PidginWhiteboard
*gtkwb
);
62 static void pidgin_whiteboard_rgb24_to_rgb48(int color_rgb
, GdkColor
*color
);
64 static void color_select_dialog(GtkWidget
*widget
, PidginWhiteboard
*gtkwb
);
66 /******************************************************************************
68 *****************************************************************************/
70 GList *buttonList = NULL;
71 GdkColor DefaultColor[PALETTE_NUM_COLORS];
74 static int LastX
; /* Tracks last position of the mouse when drawing */
76 static int MotionCount
; /* Tracks how many brush motions made */
77 static int BrushState
= BRUSH_STATE_UP
;
79 static PurpleWhiteboardUiOps ui_ops
=
81 pidgin_whiteboard_create
,
82 pidgin_whiteboard_destroy
,
83 pidgin_whiteboard_set_dimensions
,
84 pidgin_whiteboard_set_brush
,
85 pidgin_whiteboard_draw_brush_point
,
86 pidgin_whiteboard_draw_brush_line
,
87 pidgin_whiteboard_clear
,
94 /******************************************************************************
96 *****************************************************************************/
97 PurpleWhiteboardUiOps
*pidgin_whiteboard_get_ui_ops(void)
102 static void pidgin_whiteboard_create(PurpleWhiteboard
*wb
)
106 GtkWidget
*drawing_area
;
107 GtkWidget
*vbox_controls
;
108 GtkWidget
*hbox_canvas_and_controls
;
111 --------------------------
112 |[][][][palette[][][][][]|
113 |------------------------|
119 --------------------------
121 GtkWidget
*clear_button
;
122 GtkWidget
*save_button
;
123 GtkWidget
*color_button
;
125 PidginWhiteboard
*gtkwb
= g_new0(PidginWhiteboard
, 1);
130 /* Get dimensions (default?) for the whiteboard canvas */
131 if (!purple_whiteboard_get_dimensions(wb
, >kwb
->width
, >kwb
->height
))
133 /* Give some initial board-size */
138 if (!purple_whiteboard_get_brush(wb
, >kwb
->brush_size
, >kwb
->brush_color
))
140 /* Give some initial brush-info */
141 gtkwb
->brush_size
= 2;
142 gtkwb
->brush_color
= 0xff0000;
145 /* Try and set window title as the name of the buddy, else just use their
148 buddy
= purple_find_buddy(wb
->account
, wb
->who
);
150 window
= pidgin_create_window(buddy
!= NULL
? purple_buddy_get_contact_alias(buddy
) : wb
->who
, 0, NULL
, FALSE
);
151 gtkwb
->window
= window
;
152 gtk_widget_set_name(window
, wb
->who
);
154 g_signal_connect(G_OBJECT(window
), "delete_event",
155 G_CALLBACK(whiteboard_close_cb
), gtkwb
);
160 GtkWidget
*hbox_palette
;
161 GtkWidget
*vbox_palette_above_canvas_and_controls
;
162 GtkWidget
*palette_color_box
[PALETTE_NUM_COLORS
];
164 /* Create vertical box to place palette above the canvas and controls */
165 vbox_palette_above_canvas_and_controls
= gtk_vbox_new(FALSE
, 0);
166 gtk_container_add(GTK_CONTAINER(window
), vbox_palette_above_canvas_and_controls
);
167 gtk_widget_show(vbox_palette_above_canvas_and_controls
);
169 /* Create horizontal box for the palette and all its entries */
170 hbox_palette
= gtk_hbox_new(FALSE
, 0);
171 gtk_box_pack_start(GTK_BOX(vbox_palette_above_canvas_and_controls
),
172 hbox_palette
, FALSE
, FALSE
, PIDGIN_HIG_BORDER
);
173 gtk_widget_show(hbox_palette
);
175 /* Create horizontal box to seperate the canvas from the controls */
176 hbox_canvas_and_controls
= gtk_hbox_new(FALSE
, 0);
177 gtk_box_pack_start(GTK_BOX(vbox_palette_above_canvas_and_controls
),
178 hbox_canvas_and_controls
, FALSE
, FALSE
, PIDGIN_HIG_BORDER
);
179 gtk_widget_show(hbox_canvas_and_controls
);
181 for(i
= 0; i
< PALETTE_NUM_COLORS
; i
++)
183 palette_color_box
[i
] = gtk_image_new_from_pixbuf(NULL
);
184 gtk_widget_set_size_request(palette_color_box
[i
], gtkwb
->width
/ PALETTE_NUM_COLORS
,32);
185 gtk_container_add(GTK_CONTAINER(hbox_palette
), palette_color_box
[i
]);
187 gtk_widget_show(palette_color_box
[i
]);
191 hbox_canvas_and_controls
= gtk_hbox_new(FALSE
, 0);
192 gtk_widget_show(hbox_canvas_and_controls
);
194 gtk_container_add(GTK_CONTAINER(window
), hbox_canvas_and_controls
);
195 gtk_container_set_border_width(GTK_CONTAINER(window
), PIDGIN_HIG_BORDER
);
197 /* Create the drawing area */
198 drawing_area
= gtk_drawing_area_new();
199 gtkwb
->drawing_area
= drawing_area
;
200 gtk_widget_set_size_request(GTK_WIDGET(drawing_area
), gtkwb
->width
, gtkwb
->height
);
201 gtk_box_pack_start(GTK_BOX(hbox_canvas_and_controls
), drawing_area
, TRUE
, TRUE
, PIDGIN_HIG_BOX_SPACE
);
203 gtk_widget_show(drawing_area
);
205 /* Signals used to handle backing pixmap */
206 g_signal_connect(G_OBJECT(drawing_area
), "expose_event",
207 G_CALLBACK(pidgin_whiteboard_expose_event
), gtkwb
);
209 g_signal_connect(G_OBJECT(drawing_area
), "configure_event",
210 G_CALLBACK(pidgin_whiteboard_configure_event
), gtkwb
);
213 g_signal_connect(G_OBJECT(drawing_area
), "button_press_event",
214 G_CALLBACK(pidgin_whiteboard_brush_down
), gtkwb
);
216 g_signal_connect(G_OBJECT(drawing_area
), "motion_notify_event",
217 G_CALLBACK(pidgin_whiteboard_brush_motion
), gtkwb
);
219 g_signal_connect(G_OBJECT(drawing_area
), "button_release_event",
220 G_CALLBACK(pidgin_whiteboard_brush_up
), gtkwb
);
222 gtk_widget_set_events(drawing_area
,
224 GDK_LEAVE_NOTIFY_MASK
|
225 GDK_BUTTON_PRESS_MASK
|
226 GDK_POINTER_MOTION_MASK
|
227 GDK_BUTTON_RELEASE_MASK
|
228 GDK_POINTER_MOTION_HINT_MASK
);
230 /* Create vertical box to contain the controls */
231 vbox_controls
= gtk_vbox_new(FALSE
, 0);
232 gtk_box_pack_start(GTK_BOX(hbox_canvas_and_controls
),
233 vbox_controls
, FALSE
, FALSE
, PIDGIN_HIG_BOX_SPACE
);
234 gtk_widget_show(vbox_controls
);
236 /* Add a clear button */
237 clear_button
= gtk_button_new_from_stock(GTK_STOCK_CLEAR
);
238 gtk_box_pack_start(GTK_BOX(vbox_controls
), clear_button
, FALSE
, FALSE
, PIDGIN_HIG_BOX_SPACE
);
239 gtk_widget_show(clear_button
);
240 g_signal_connect(G_OBJECT(clear_button
), "clicked",
241 G_CALLBACK(pidgin_whiteboard_button_clear_press
), gtkwb
);
243 /* Add a save button */
244 save_button
= gtk_button_new_from_stock(GTK_STOCK_SAVE
);
245 gtk_box_pack_start(GTK_BOX(vbox_controls
), save_button
, FALSE
, FALSE
, PIDGIN_HIG_BOX_SPACE
);
246 gtk_widget_show(save_button
);
248 g_signal_connect(G_OBJECT(save_button
), "clicked",
249 G_CALLBACK(pidgin_whiteboard_button_save_press
), gtkwb
);
251 /* Add a color selector */
252 color_button
= gtk_button_new_from_stock(GTK_STOCK_SELECT_COLOR
);
253 gtk_box_pack_start(GTK_BOX(vbox_controls
), color_button
, FALSE
, FALSE
, PIDGIN_HIG_BOX_SPACE
);
254 gtk_widget_show(color_button
);
255 g_signal_connect(G_OBJECT(color_button
), "clicked",
256 G_CALLBACK(color_select_dialog
), gtkwb
);
258 /* Make all this (window) visible */
259 gtk_widget_show(window
);
261 pidgin_whiteboard_set_canvas_as_icon(gtkwb
);
263 /* TODO Specific protocol/whiteboard assignment here? Needs a UI Op? */
264 /* Set default brush size and color */
266 ds->brush_size = DOODLE_BRUSH_MEDIUM;
271 static void pidgin_whiteboard_destroy(PurpleWhiteboard
*wb
)
273 PidginWhiteboard
*gtkwb
;
274 GtkWidget
*colour_dialog
;
276 g_return_if_fail(wb
!= NULL
);
278 g_return_if_fail(gtkwb
!= NULL
);
280 /* TODO Ask if user wants to save picture before the session is closed */
282 /* Clear graphical memory */
285 g_object_unref(gtkwb
->pixmap
);
286 gtkwb
->pixmap
= NULL
;
289 colour_dialog
= g_object_get_data(G_OBJECT(gtkwb
->window
), "colour-dialog");
291 gtk_widget_destroy(colour_dialog
);
292 g_object_set_data(G_OBJECT(gtkwb
->window
), "colour-dialog", NULL
);
297 gtk_widget_destroy(gtkwb
->window
);
298 gtkwb
->window
= NULL
;
304 static gboolean
whiteboard_close_cb(GtkWidget
*widget
, GdkEvent
*event
, PidginWhiteboard
*gtkwb
)
306 PurpleWhiteboard
*wb
;
308 g_return_val_if_fail(gtkwb
!= NULL
, FALSE
);
310 g_return_val_if_fail(wb
!= NULL
, FALSE
);
312 purple_whiteboard_destroy(wb
);
318 * Whiteboard start button on conversation window (move this code to gtkconv?
319 * and use new prpl_info member?)
322 static void pidginwhiteboard_button_start_press(GtkButton
*button
, gpointer data
)
324 PurpleConversation
*conv
= data
;
325 PurpleAccount
*account
= purple_conversation_get_account(conv
);
326 PurpleConnection
*gc
= purple_account_get_connection(account
);
327 char *to
= (char*)(purple_conversation_get_name(conv
));
329 /* Only handle this if local client requested Doodle session (else local
330 * client would have sent one)
332 PurpleWhiteboard
*wb
= purple_whiteboard_get(account
, to
);
334 /* Write a local message to this conversation showing that a request for a
335 * Doodle session has been made
337 /* XXXX because otherwise gettext will see this string, even though it's
338 * in an #if 0 block. Remove the XXXX if you want to use this code.
339 * But, it really shouldn't be a Yahoo-specific string. ;) */
340 purple_conv_im_write(PURPLE_CONV_IM(conv
), "", XXXX_("Sent Doodle request."),
341 PURPLE_MESSAGE_NICK
| PURPLE_MESSAGE_RECV
, time(NULL
));
343 yahoo_doodle_command_send_request(gc
, to
);
344 yahoo_doodle_command_send_ready(gc
, to
);
346 /* Insert this 'session' in the list. At this point, it's only a requested
349 wb
= purple_whiteboard_create(account
, to
, DOODLE_STATE_REQUESTING
);
353 static gboolean
pidgin_whiteboard_configure_event(GtkWidget
*widget
, GdkEventConfigure
*event
, gpointer data
)
355 PidginWhiteboard
*gtkwb
= (PidginWhiteboard
*)data
;
357 GdkPixmap
*pixmap
= gtkwb
->pixmap
;
360 g_object_unref(pixmap
);
362 pixmap
= gdk_pixmap_new(widget
->window
,
363 widget
->allocation
.width
,
364 widget
->allocation
.height
,
367 gtkwb
->pixmap
= pixmap
;
369 gdk_draw_rectangle(pixmap
,
370 widget
->style
->white_gc
,
373 widget
->allocation
.width
,
374 widget
->allocation
.height
);
379 static gboolean
pidgin_whiteboard_expose_event(GtkWidget
*widget
, GdkEventExpose
*event
, gpointer data
)
381 PidginWhiteboard
*gtkwb
= (PidginWhiteboard
*)(data
);
382 GdkPixmap
*pixmap
= gtkwb
->pixmap
;
384 gdk_draw_drawable(widget
->window
,
385 widget
->style
->fg_gc
[GTK_WIDGET_STATE(widget
)],
387 event
->area
.x
, event
->area
.y
,
388 event
->area
.x
, event
->area
.y
,
389 event
->area
.width
, event
->area
.height
);
394 static gboolean
pidgin_whiteboard_brush_down(GtkWidget
*widget
, GdkEventButton
*event
, gpointer data
)
396 PidginWhiteboard
*gtkwb
= (PidginWhiteboard
*)data
;
397 GdkPixmap
*pixmap
= gtkwb
->pixmap
;
399 PurpleWhiteboard
*wb
= gtkwb
->wb
;
400 GList
*draw_list
= wb
->draw_list
;
402 if(BrushState
!= BRUSH_STATE_UP
)
404 /* Potential double-click DOWN to DOWN? */
405 BrushState
= BRUSH_STATE_DOWN
;
410 BrushState
= BRUSH_STATE_DOWN
;
412 if(event
->button
== 1 && pixmap
!= NULL
)
414 /* Check if draw_list has contents; if so, clear it */
417 purple_whiteboard_draw_list_destroy(draw_list
);
421 /* Set tracking variables */
427 draw_list
= g_list_append(draw_list
, GINT_TO_POINTER(LastX
));
428 draw_list
= g_list_append(draw_list
, GINT_TO_POINTER(LastY
));
430 pidgin_whiteboard_draw_brush_point(gtkwb
->wb
,
432 gtkwb
->brush_color
, gtkwb
->brush_size
);
435 wb
->draw_list
= draw_list
;
440 static gboolean
pidgin_whiteboard_brush_motion(GtkWidget
*widget
, GdkEventMotion
*event
, gpointer data
)
447 GdkModifierType state
;
449 PidginWhiteboard
*gtkwb
= (PidginWhiteboard
*)data
;
450 GdkPixmap
*pixmap
= gtkwb
->pixmap
;
452 PurpleWhiteboard
*wb
= gtkwb
->wb
;
453 GList
*draw_list
= wb
->draw_list
;
456 gdk_window_get_pointer(event
->window
, &x
, &y
, &state
);
461 state
= event
->state
;
464 if(state
& GDK_BUTTON1_MASK
&& pixmap
!= NULL
)
466 if((BrushState
!= BRUSH_STATE_DOWN
) && (BrushState
!= BRUSH_STATE_MOTION
))
468 purple_debug_error("gtkwhiteboard", "***Bad brush state transition %d to MOTION\n", BrushState
);
470 BrushState
= BRUSH_STATE_MOTION
;
474 BrushState
= BRUSH_STATE_MOTION
;
481 /* NOTE 100 is a temporary constant for how many deltas/motions in a
482 * stroke (needs UI Ops?)
484 if(MotionCount
== 100)
486 draw_list
= g_list_append(draw_list
, GINT_TO_POINTER(dx
));
487 draw_list
= g_list_append(draw_list
, GINT_TO_POINTER(dy
));
489 /* Send draw list to the draw_list handler */
490 purple_whiteboard_send_draw_list(gtkwb
->wb
, draw_list
);
492 /* The brush stroke is finished, clear the list for another one */
495 purple_whiteboard_draw_list_destroy(draw_list
);
499 /* Reset motion tracking */
502 draw_list
= g_list_append(draw_list
, GINT_TO_POINTER(LastX
));
503 draw_list
= g_list_append(draw_list
, GINT_TO_POINTER(LastY
));
509 draw_list
= g_list_append(draw_list
, GINT_TO_POINTER(dx
));
510 draw_list
= g_list_append(draw_list
, GINT_TO_POINTER(dy
));
512 pidgin_whiteboard_draw_brush_line(gtkwb
->wb
,
515 gtkwb
->brush_color
, gtkwb
->brush_size
);
517 /* Set tracking variables */
522 wb
->draw_list
= draw_list
;
527 static gboolean
pidgin_whiteboard_brush_up(GtkWidget
*widget
, GdkEventButton
*event
, gpointer data
)
529 PidginWhiteboard
*gtkwb
= (PidginWhiteboard
*)data
;
530 GdkPixmap
*pixmap
= gtkwb
->pixmap
;
532 PurpleWhiteboard
*wb
= gtkwb
->wb
;
533 GList
*draw_list
= wb
->draw_list
;
535 if((BrushState
!= BRUSH_STATE_DOWN
) && (BrushState
!= BRUSH_STATE_MOTION
))
537 purple_debug_error("gtkwhiteboard", "***Bad brush state transition %d to UP\n", BrushState
);
539 BrushState
= BRUSH_STATE_UP
;
543 BrushState
= BRUSH_STATE_UP
;
545 if(event
->button
== 1 && pixmap
!= NULL
)
547 /* If the brush was never moved, express two sets of two deltas That's a
548 * 'point,' but not for Yahoo!
550 /* if((event->x == LastX) && (event->y == LastY)) */
555 /* For Yahoo!, a (0 0) indicates the end of drawing */
556 /* FIXME: Yahoo Doodle specific! */
557 for(index
= 0; index
< 2; index
++)
559 draw_list
= g_list_append(draw_list
, 0);
560 draw_list
= g_list_append(draw_list
, 0);
568 /* Send draw list to prpl draw_list handler */
569 purple_whiteboard_send_draw_list(gtkwb
->wb
, draw_list
);
571 pidgin_whiteboard_set_canvas_as_icon(gtkwb
);
573 /* The brush stroke is finished, clear the list for another one */
575 purple_whiteboard_draw_list_destroy(draw_list
);
577 wb
->draw_list
= NULL
;
583 static void pidgin_whiteboard_draw_brush_point(PurpleWhiteboard
*wb
, int x
, int y
, int color
, int size
)
585 PidginWhiteboard
*gtkwb
= wb
->ui_data
;
586 GtkWidget
*widget
= gtkwb
->drawing_area
;
587 GdkPixmap
*pixmap
= gtkwb
->pixmap
;
589 GdkRectangle update_rect
;
591 GdkGC
*gfx_con
= gdk_gc_new(pixmap
);
594 update_rect
.x
= x
- size
/ 2;
595 update_rect
.y
= y
- size
/ 2;
596 update_rect
.width
= size
;
597 update_rect
.height
= size
;
599 /* Interpret and convert color */
600 pidgin_whiteboard_rgb24_to_rgb48(color
, &col
);
602 gdk_gc_set_rgb_fg_color(gfx_con
, &col
);
603 /* gdk_gc_set_rgb_bg_color(gfx_con, &col); */
605 /* NOTE 5 is a size constant for now... this is because of how poorly the
606 * gdk_draw_arc draws small circles
610 /* Draw a rectangle/square */
611 gdk_draw_rectangle(pixmap
,
614 update_rect
.x
, update_rect
.y
,
615 update_rect
.width
, update_rect
.height
);
623 update_rect
.x
, update_rect
.y
,
624 update_rect
.width
, update_rect
.height
,
625 0, FULL_CIRCLE_DEGREES
);
628 gtk_widget_queue_draw_area(widget
,
629 update_rect
.x
, update_rect
.y
,
630 update_rect
.width
, update_rect
.height
);
632 g_object_unref(G_OBJECT(gfx_con
));
635 /* Uses Bresenham's algorithm (as provided by Wikipedia) */
636 static void pidgin_whiteboard_draw_brush_line(PurpleWhiteboard
*wb
, int x0
, int y0
, int x1
, int y1
, int color
, int size
)
652 gboolean steep
= abs(y1
- y0
) > abs(x1
- x0
);
656 temp
= x0
; x0
= y0
; y0
= temp
;
657 temp
= x1
; x1
= y1
; y1
= temp
;
680 pidgin_whiteboard_draw_brush_point(wb
, y
, x
, color
, size
);
682 pidgin_whiteboard_draw_brush_point(wb
, x
, y
, color
, size
);
689 if((error
* 2) >= dx
)
696 pidgin_whiteboard_draw_brush_point(wb
, y
, x
, color
, size
);
698 pidgin_whiteboard_draw_brush_point(wb
, x
, y
, color
, size
);
702 static void pidgin_whiteboard_set_dimensions(PurpleWhiteboard
*wb
, int width
, int height
)
704 PidginWhiteboard
*gtkwb
= wb
->ui_data
;
706 gtkwb
->width
= width
;
707 gtkwb
->height
= height
;
710 static void pidgin_whiteboard_set_brush(PurpleWhiteboard
*wb
, int size
, int color
)
712 PidginWhiteboard
*gtkwb
= wb
->ui_data
;
714 gtkwb
->brush_size
= size
;
715 gtkwb
->brush_color
= color
;
718 static void pidgin_whiteboard_clear(PurpleWhiteboard
*wb
)
720 PidginWhiteboard
*gtkwb
= wb
->ui_data
;
721 GdkPixmap
*pixmap
= gtkwb
->pixmap
;
722 GtkWidget
*drawing_area
= gtkwb
->drawing_area
;
724 gdk_draw_rectangle(pixmap
,
725 drawing_area
->style
->white_gc
,
728 drawing_area
->allocation
.width
,
729 drawing_area
->allocation
.height
);
731 gtk_widget_queue_draw_area(drawing_area
,
733 drawing_area
->allocation
.width
,
734 drawing_area
->allocation
.height
);
737 static void pidgin_whiteboard_button_clear_press(GtkWidget
*widget
, gpointer data
)
739 PidginWhiteboard
*gtkwb
= (PidginWhiteboard
*)(data
);
741 /* Confirm whether the user really wants to clear */
742 GtkWidget
*dialog
= gtk_message_dialog_new(GTK_WINDOW(gtkwb
->window
),
743 GTK_DIALOG_DESTROY_WITH_PARENT
,
744 GTK_MESSAGE_QUESTION
,
746 _("Do you really want to clear?"));
747 gint response
= gtk_dialog_run(GTK_DIALOG(dialog
));
748 gtk_widget_destroy(dialog
);
750 if (response
== GTK_RESPONSE_YES
)
752 pidgin_whiteboard_clear(gtkwb
->wb
);
754 pidgin_whiteboard_set_canvas_as_icon(gtkwb
);
756 /* Do protocol specific clearing procedures */
757 purple_whiteboard_send_clear(gtkwb
->wb
);
761 static void pidgin_whiteboard_button_save_press(GtkWidget
*widget
, gpointer data
)
763 PidginWhiteboard
*gtkwb
= (PidginWhiteboard
*)(data
);
770 dialog
= gtk_file_chooser_dialog_new (_("Save File"),
771 GTK_WINDOW(gtkwb
->window
),
772 GTK_FILE_CHOOSER_ACTION_SAVE
,
773 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
774 GTK_STOCK_SAVE
, GTK_RESPONSE_ACCEPT
,
777 /* gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), (gboolean)(TRUE)); */
779 /* if(user_edited_a_new_document) */
781 /* gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), default_folder_for_saving); */
782 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog
), "whiteboard.jpg");
786 gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog), filename_for_existing_document);
789 result
= gtk_dialog_run(GTK_DIALOG(dialog
));
791 if(result
== GTK_RESPONSE_ACCEPT
)
795 filename
= gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog
));
797 gtk_widget_destroy(dialog
);
799 /* Makes an icon from the whiteboard's canvas 'image' */
800 pixbuf
= gdk_pixbuf_get_from_drawable(NULL
,
801 (GdkDrawable
*)(gtkwb
->pixmap
),
802 gdk_drawable_get_colormap(gtkwb
->pixmap
),
805 gtkwb
->width
, gtkwb
->height
);
807 if(gdk_pixbuf_save(pixbuf
, filename
, "jpeg", NULL
, "quality", "100", NULL
))
808 purple_debug_info("gtkwhiteboard", "File Saved...\n");
810 purple_debug_info("gtkwhiteboard", "File not Saved... Error\n");
813 else if(result
== GTK_RESPONSE_CANCEL
)
815 gtk_widget_destroy(dialog
);
817 purple_debug_info("gtkwhiteboard", "File not Saved... Cancelled\n");
821 static void pidgin_whiteboard_set_canvas_as_icon(PidginWhiteboard
*gtkwb
)
825 /* Makes an icon from the whiteboard's canvas 'image' */
826 pixbuf
= gdk_pixbuf_get_from_drawable(NULL
,
827 (GdkDrawable
*)(gtkwb
->pixmap
),
828 gdk_drawable_get_colormap(gtkwb
->pixmap
),
831 gtkwb
->width
, gtkwb
->height
);
833 gtk_window_set_icon((GtkWindow
*)(gtkwb
->window
), pixbuf
);
836 static void pidgin_whiteboard_rgb24_to_rgb48(int color_rgb
, GdkColor
*color
)
838 color
->red
= (color_rgb
>> 8) | 0xFF;
839 color
->green
= (color_rgb
& 0xFF00) | 0xFF;
840 color
->blue
= ((color_rgb
& 0xFF) << 8) | 0xFF;
844 change_color_cb(GtkColorSelection
*selection
, PidginWhiteboard
*gtkwb
)
850 PurpleWhiteboard
*wb
= gtkwb
->wb
;
852 gtk_color_selection_get_current_color(selection
, &color
);
853 new_color
= (color
.red
& 0xFF00) << 8;
854 new_color
|= (color
.green
& 0xFF00);
855 new_color
|= (color
.blue
& 0xFF00) >> 8;
857 purple_whiteboard_get_brush(wb
, &old_size
, &old_color
);
858 purple_whiteboard_send_brush(wb
, old_size
, new_color
);
861 static void color_selection_dialog_destroy(GtkWidget
*w
, PidginWhiteboard
*gtkwb
)
863 GtkWidget
*dialog
= g_object_get_data(G_OBJECT(gtkwb
->window
), "colour-dialog");
864 gtk_widget_destroy(dialog
);
865 g_object_set_data(G_OBJECT(gtkwb
->window
), "colour-dialog", NULL
);
868 static void color_select_dialog(GtkWidget
*widget
, PidginWhiteboard
*gtkwb
)
871 GtkColorSelectionDialog
*dialog
;
873 dialog
= (GtkColorSelectionDialog
*)gtk_color_selection_dialog_new(_("Select color"));
874 g_object_set_data(G_OBJECT(gtkwb
->window
), "colour-dialog", dialog
);
876 g_signal_connect(G_OBJECT(dialog
->colorsel
), "color-changed",
877 G_CALLBACK(change_color_cb
), gtkwb
);
879 gtk_widget_destroy(dialog
->cancel_button
);
880 gtk_widget_destroy(dialog
->help_button
);
882 g_signal_connect(G_OBJECT(dialog
->ok_button
), "clicked",
883 G_CALLBACK(color_selection_dialog_destroy
), gtkwb
);
885 gtk_color_selection_set_has_palette(GTK_COLOR_SELECTION(dialog
->colorsel
), TRUE
);
887 pidgin_whiteboard_rgb24_to_rgb48(gtkwb
->brush_color
, &color
);
888 gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(dialog
->colorsel
), &color
);
890 gtk_widget_show_all(GTK_WIDGET(dialog
));