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 cairo_t
*cr
= g_object_get_data(G_OBJECT(gtkwb
->pixmap
), "cairo-context");
288 g_object_unref(gtkwb
->pixmap
);
289 gtkwb
->pixmap
= NULL
;
292 colour_dialog
= g_object_get_data(G_OBJECT(gtkwb
->window
), "colour-dialog");
294 gtk_widget_destroy(colour_dialog
);
295 g_object_set_data(G_OBJECT(gtkwb
->window
), "colour-dialog", NULL
);
300 gtk_widget_destroy(gtkwb
->window
);
301 gtkwb
->window
= NULL
;
307 static gboolean
whiteboard_close_cb(GtkWidget
*widget
, GdkEvent
*event
, PidginWhiteboard
*gtkwb
)
309 PurpleWhiteboard
*wb
;
311 g_return_val_if_fail(gtkwb
!= NULL
, FALSE
);
313 g_return_val_if_fail(wb
!= NULL
, FALSE
);
315 purple_whiteboard_destroy(wb
);
321 * Whiteboard start button on conversation window (move this code to gtkconv?
322 * and use new prpl_info member?)
325 static void pidginwhiteboard_button_start_press(GtkButton
*button
, gpointer data
)
327 PurpleConversation
*conv
= data
;
328 PurpleAccount
*account
= purple_conversation_get_account(conv
);
329 PurpleConnection
*gc
= purple_account_get_connection(account
);
330 char *to
= (char*)(purple_conversation_get_name(conv
));
332 /* Only handle this if local client requested Doodle session (else local
333 * client would have sent one)
335 PurpleWhiteboard
*wb
= purple_whiteboard_get(account
, to
);
337 /* Write a local message to this conversation showing that a request for a
338 * Doodle session has been made
340 /* XXXX because otherwise gettext will see this string, even though it's
341 * in an #if 0 block. Remove the XXXX if you want to use this code.
342 * But, it really shouldn't be a Yahoo-specific string. ;) */
343 purple_conv_im_write(PURPLE_CONV_IM(conv
), "", XXXX_("Sent Doodle request."),
344 PURPLE_MESSAGE_NICK
| PURPLE_MESSAGE_RECV
, time(NULL
));
346 yahoo_doodle_command_send_request(gc
, to
);
347 yahoo_doodle_command_send_ready(gc
, to
);
349 /* Insert this 'session' in the list. At this point, it's only a requested
352 wb
= purple_whiteboard_create(account
, to
, DOODLE_STATE_REQUESTING
);
356 static gboolean
pidgin_whiteboard_configure_event(GtkWidget
*widget
, GdkEventConfigure
*event
, gpointer data
)
358 PidginWhiteboard
*gtkwb
= (PidginWhiteboard
*)data
;
359 GdkPixmap
*pixmap
= gtkwb
->pixmap
;
363 cr
= g_object_get_data(G_OBJECT(pixmap
), "cairo-context");
366 g_object_unref(pixmap
);
369 pixmap
= gdk_pixmap_new(widget
->window
,
370 widget
->allocation
.width
,
371 widget
->allocation
.height
,
373 gtkwb
->pixmap
= pixmap
;
375 cr
= gdk_cairo_create(GDK_DRAWABLE(pixmap
));
376 g_object_set_data(G_OBJECT(pixmap
), "cairo-context", cr
);
377 gdk_cairo_set_source_color(cr
, &widget
->style
->white
);
380 widget
->allocation
.width
, widget
->allocation
.height
);
386 static gboolean
pidgin_whiteboard_expose_event(GtkWidget
*widget
, GdkEventExpose
*event
, gpointer data
)
388 PidginWhiteboard
*gtkwb
= (PidginWhiteboard
*)(data
);
389 GdkPixmap
*pixmap
= gtkwb
->pixmap
;
392 cr
= gdk_cairo_create(GDK_DRAWABLE(widget
->window
));
393 gdk_cairo_set_source_pixmap(cr
, pixmap
, 0, 0);
395 event
->area
.x
, event
->area
.y
,
396 event
->area
.width
, event
->area
.height
);
403 static gboolean
pidgin_whiteboard_brush_down(GtkWidget
*widget
, GdkEventButton
*event
, gpointer data
)
405 PidginWhiteboard
*gtkwb
= (PidginWhiteboard
*)data
;
406 GdkPixmap
*pixmap
= gtkwb
->pixmap
;
408 PurpleWhiteboard
*wb
= gtkwb
->wb
;
409 GList
*draw_list
= wb
->draw_list
;
411 if(BrushState
!= BRUSH_STATE_UP
)
413 /* Potential double-click DOWN to DOWN? */
414 BrushState
= BRUSH_STATE_DOWN
;
419 BrushState
= BRUSH_STATE_DOWN
;
421 if(event
->button
== 1 && pixmap
!= NULL
)
423 /* Check if draw_list has contents; if so, clear it */
426 purple_whiteboard_draw_list_destroy(draw_list
);
430 /* Set tracking variables */
436 draw_list
= g_list_append(draw_list
, GINT_TO_POINTER(LastX
));
437 draw_list
= g_list_append(draw_list
, GINT_TO_POINTER(LastY
));
439 pidgin_whiteboard_draw_brush_point(gtkwb
->wb
,
441 gtkwb
->brush_color
, gtkwb
->brush_size
);
444 wb
->draw_list
= draw_list
;
449 static gboolean
pidgin_whiteboard_brush_motion(GtkWidget
*widget
, GdkEventMotion
*event
, gpointer data
)
456 GdkModifierType state
;
458 PidginWhiteboard
*gtkwb
= (PidginWhiteboard
*)data
;
459 GdkPixmap
*pixmap
= gtkwb
->pixmap
;
461 PurpleWhiteboard
*wb
= gtkwb
->wb
;
462 GList
*draw_list
= wb
->draw_list
;
465 gdk_window_get_pointer(event
->window
, &x
, &y
, &state
);
470 state
= event
->state
;
473 if(state
& GDK_BUTTON1_MASK
&& pixmap
!= NULL
)
475 if((BrushState
!= BRUSH_STATE_DOWN
) && (BrushState
!= BRUSH_STATE_MOTION
))
477 purple_debug_error("gtkwhiteboard", "***Bad brush state transition %d to MOTION\n", BrushState
);
479 BrushState
= BRUSH_STATE_MOTION
;
483 BrushState
= BRUSH_STATE_MOTION
;
490 /* NOTE 100 is a temporary constant for how many deltas/motions in a
491 * stroke (needs UI Ops?)
493 if(MotionCount
== 100)
495 draw_list
= g_list_append(draw_list
, GINT_TO_POINTER(dx
));
496 draw_list
= g_list_append(draw_list
, GINT_TO_POINTER(dy
));
498 /* Send draw list to the draw_list handler */
499 purple_whiteboard_send_draw_list(gtkwb
->wb
, draw_list
);
501 /* The brush stroke is finished, clear the list for another one */
504 purple_whiteboard_draw_list_destroy(draw_list
);
508 /* Reset motion tracking */
511 draw_list
= g_list_append(draw_list
, GINT_TO_POINTER(LastX
));
512 draw_list
= g_list_append(draw_list
, GINT_TO_POINTER(LastY
));
518 draw_list
= g_list_append(draw_list
, GINT_TO_POINTER(dx
));
519 draw_list
= g_list_append(draw_list
, GINT_TO_POINTER(dy
));
521 pidgin_whiteboard_draw_brush_line(gtkwb
->wb
,
524 gtkwb
->brush_color
, gtkwb
->brush_size
);
526 /* Set tracking variables */
531 wb
->draw_list
= draw_list
;
536 static gboolean
pidgin_whiteboard_brush_up(GtkWidget
*widget
, GdkEventButton
*event
, gpointer data
)
538 PidginWhiteboard
*gtkwb
= (PidginWhiteboard
*)data
;
539 GdkPixmap
*pixmap
= gtkwb
->pixmap
;
541 PurpleWhiteboard
*wb
= gtkwb
->wb
;
542 GList
*draw_list
= wb
->draw_list
;
544 if((BrushState
!= BRUSH_STATE_DOWN
) && (BrushState
!= BRUSH_STATE_MOTION
))
546 purple_debug_error("gtkwhiteboard", "***Bad brush state transition %d to UP\n", BrushState
);
548 BrushState
= BRUSH_STATE_UP
;
552 BrushState
= BRUSH_STATE_UP
;
554 if(event
->button
== 1 && pixmap
!= NULL
)
556 /* If the brush was never moved, express two sets of two deltas That's a
557 * 'point,' but not for Yahoo!
559 /* if((event->x == LastX) && (event->y == LastY)) */
564 /* For Yahoo!, a (0 0) indicates the end of drawing */
565 /* FIXME: Yahoo Doodle specific! */
566 for(index
= 0; index
< 2; index
++)
568 draw_list
= g_list_append(draw_list
, 0);
569 draw_list
= g_list_append(draw_list
, 0);
577 /* Send draw list to prpl draw_list handler */
578 purple_whiteboard_send_draw_list(gtkwb
->wb
, draw_list
);
580 pidgin_whiteboard_set_canvas_as_icon(gtkwb
);
582 /* The brush stroke is finished, clear the list for another one */
584 purple_whiteboard_draw_list_destroy(draw_list
);
586 wb
->draw_list
= NULL
;
592 static void pidgin_whiteboard_draw_brush_point(PurpleWhiteboard
*wb
, int x
, int y
, int color
, int size
)
594 PidginWhiteboard
*gtkwb
= wb
->ui_data
;
595 GtkWidget
*widget
= gtkwb
->drawing_area
;
596 GdkPixmap
*pixmap
= gtkwb
->pixmap
;
598 cairo_t
*gfx_con
= g_object_get_data(G_OBJECT(pixmap
), "cairo-context");
601 /* Interpret and convert color */
602 pidgin_whiteboard_rgb24_to_rgb48(color
, &col
);
604 gdk_cairo_set_source_color(gfx_con
, &col
);
613 gtk_widget_queue_draw_area(widget
,
614 x
- size
/ 2, y
- size
/ 2,
618 /* Uses Bresenham's algorithm (as provided by Wikipedia) */
619 static void pidgin_whiteboard_draw_brush_line(PurpleWhiteboard
*wb
, int x0
, int y0
, int x1
, int y1
, int color
, int size
)
635 gboolean steep
= abs(y1
- y0
) > abs(x1
- x0
);
639 temp
= x0
; x0
= y0
; y0
= temp
;
640 temp
= x1
; x1
= y1
; y1
= temp
;
663 pidgin_whiteboard_draw_brush_point(wb
, y
, x
, color
, size
);
665 pidgin_whiteboard_draw_brush_point(wb
, x
, y
, color
, size
);
672 if((error
* 2) >= dx
)
679 pidgin_whiteboard_draw_brush_point(wb
, y
, x
, color
, size
);
681 pidgin_whiteboard_draw_brush_point(wb
, x
, y
, color
, size
);
685 static void pidgin_whiteboard_set_dimensions(PurpleWhiteboard
*wb
, int width
, int height
)
687 PidginWhiteboard
*gtkwb
= wb
->ui_data
;
689 gtkwb
->width
= width
;
690 gtkwb
->height
= height
;
693 static void pidgin_whiteboard_set_brush(PurpleWhiteboard
*wb
, int size
, int color
)
695 PidginWhiteboard
*gtkwb
= wb
->ui_data
;
697 gtkwb
->brush_size
= size
;
698 gtkwb
->brush_color
= color
;
701 static void pidgin_whiteboard_clear(PurpleWhiteboard
*wb
)
703 PidginWhiteboard
*gtkwb
= wb
->ui_data
;
704 GdkPixmap
*pixmap
= gtkwb
->pixmap
;
705 GtkWidget
*drawing_area
= gtkwb
->drawing_area
;
706 cairo_t
*cr
= g_object_get_data(G_OBJECT(pixmap
), "cairo-context");
708 gdk_cairo_set_source_color(cr
, &drawing_area
->style
->white
);
711 drawing_area
->allocation
.width
,
712 drawing_area
->allocation
.height
);
715 gtk_widget_queue_draw_area(drawing_area
,
717 drawing_area
->allocation
.width
,
718 drawing_area
->allocation
.height
);
721 static void pidgin_whiteboard_button_clear_press(GtkWidget
*widget
, gpointer data
)
723 PidginWhiteboard
*gtkwb
= (PidginWhiteboard
*)(data
);
725 /* Confirm whether the user really wants to clear */
726 GtkWidget
*dialog
= gtk_message_dialog_new(GTK_WINDOW(gtkwb
->window
),
727 GTK_DIALOG_DESTROY_WITH_PARENT
,
728 GTK_MESSAGE_QUESTION
,
730 _("Do you really want to clear?"));
731 gint response
= gtk_dialog_run(GTK_DIALOG(dialog
));
732 gtk_widget_destroy(dialog
);
734 if (response
== GTK_RESPONSE_YES
)
736 pidgin_whiteboard_clear(gtkwb
->wb
);
738 pidgin_whiteboard_set_canvas_as_icon(gtkwb
);
740 /* Do protocol specific clearing procedures */
741 purple_whiteboard_send_clear(gtkwb
->wb
);
745 static void pidgin_whiteboard_button_save_press(GtkWidget
*widget
, gpointer data
)
747 PidginWhiteboard
*gtkwb
= (PidginWhiteboard
*)(data
);
754 dialog
= gtk_file_chooser_dialog_new (_("Save File"),
755 GTK_WINDOW(gtkwb
->window
),
756 GTK_FILE_CHOOSER_ACTION_SAVE
,
757 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
758 GTK_STOCK_SAVE
, GTK_RESPONSE_ACCEPT
,
761 /* gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), (gboolean)(TRUE)); */
763 /* if(user_edited_a_new_document) */
765 /* gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), default_folder_for_saving); */
766 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog
), "whiteboard.jpg");
770 gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog), filename_for_existing_document);
773 result
= gtk_dialog_run(GTK_DIALOG(dialog
));
775 if(result
== GTK_RESPONSE_ACCEPT
)
779 filename
= gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog
));
781 gtk_widget_destroy(dialog
);
783 /* Makes an icon from the whiteboard's canvas 'image' */
784 pixbuf
= gdk_pixbuf_get_from_drawable(NULL
,
785 (GdkDrawable
*)(gtkwb
->pixmap
),
786 gdk_drawable_get_colormap(gtkwb
->pixmap
),
789 gtkwb
->width
, gtkwb
->height
);
791 if(gdk_pixbuf_save(pixbuf
, filename
, "jpeg", NULL
, "quality", "100", NULL
))
792 purple_debug_info("gtkwhiteboard", "File Saved...\n");
794 purple_debug_info("gtkwhiteboard", "File not Saved... Error\n");
797 else if(result
== GTK_RESPONSE_CANCEL
)
799 gtk_widget_destroy(dialog
);
801 purple_debug_info("gtkwhiteboard", "File not Saved... Cancelled\n");
805 static void pidgin_whiteboard_set_canvas_as_icon(PidginWhiteboard
*gtkwb
)
809 /* Makes an icon from the whiteboard's canvas 'image' */
810 pixbuf
= gdk_pixbuf_get_from_drawable(NULL
,
811 (GdkDrawable
*)(gtkwb
->pixmap
),
812 gdk_drawable_get_colormap(gtkwb
->pixmap
),
815 gtkwb
->width
, gtkwb
->height
);
817 gtk_window_set_icon((GtkWindow
*)(gtkwb
->window
), pixbuf
);
820 static void pidgin_whiteboard_rgb24_to_rgb48(int color_rgb
, GdkColor
*color
)
822 color
->red
= (color_rgb
>> 8) | 0xFF;
823 color
->green
= (color_rgb
& 0xFF00) | 0xFF;
824 color
->blue
= ((color_rgb
& 0xFF) << 8) | 0xFF;
828 change_color_cb(GtkColorSelection
*selection
, PidginWhiteboard
*gtkwb
)
834 PurpleWhiteboard
*wb
= gtkwb
->wb
;
836 gtk_color_selection_get_current_color(selection
, &color
);
837 new_color
= (color
.red
& 0xFF00) << 8;
838 new_color
|= (color
.green
& 0xFF00);
839 new_color
|= (color
.blue
& 0xFF00) >> 8;
841 purple_whiteboard_get_brush(wb
, &old_size
, &old_color
);
842 purple_whiteboard_send_brush(wb
, old_size
, new_color
);
845 static void color_selection_dialog_destroy(GtkWidget
*w
, PidginWhiteboard
*gtkwb
)
847 GtkWidget
*dialog
= g_object_get_data(G_OBJECT(gtkwb
->window
), "colour-dialog");
848 gtk_widget_destroy(dialog
);
849 g_object_set_data(G_OBJECT(gtkwb
->window
), "colour-dialog", NULL
);
852 static void color_select_dialog(GtkWidget
*widget
, PidginWhiteboard
*gtkwb
)
855 GtkColorSelectionDialog
*dialog
;
857 dialog
= (GtkColorSelectionDialog
*)gtk_color_selection_dialog_new(_("Select color"));
858 g_object_set_data(G_OBJECT(gtkwb
->window
), "colour-dialog", dialog
);
860 g_signal_connect(G_OBJECT(dialog
->colorsel
), "color-changed",
861 G_CALLBACK(change_color_cb
), gtkwb
);
863 gtk_widget_destroy(dialog
->cancel_button
);
864 gtk_widget_destroy(dialog
->help_button
);
866 g_signal_connect(G_OBJECT(dialog
->ok_button
), "clicked",
867 G_CALLBACK(color_selection_dialog_destroy
), gtkwb
);
869 gtk_color_selection_set_has_palette(GTK_COLOR_SELECTION(dialog
->colorsel
), TRUE
);
871 pidgin_whiteboard_rgb24_to_rgb48(gtkwb
->brush_color
, &color
);
872 gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(dialog
->colorsel
), &color
);
874 gtk_widget_show_all(GTK_WIDGET(dialog
));