1 /* Sticky Notes
2 * Copyright (C) 2002-2003 Loban A Rahman
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2, or (at your option)
7 * any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
18 */
19
20 #include <config.h>
21 #include <stickynotes_callbacks.h>
22
23 /* Sticky Window Callback : Lock/Unlock the window */
24 gboolean
stickynote_toggle_lock_cb(GtkWidget * widget,StickyNote * note)25 stickynote_toggle_lock_cb (GtkWidget *widget,
26 StickyNote *note)
27 {
28 stickynote_set_locked (note, !note->locked);
29
30 return TRUE;
31 }
32
33 /* Sticky Window Callback : Close the window. */
34 gboolean
stickynote_close_cb(GtkWidget * widget,StickyNote * note)35 stickynote_close_cb (GtkWidget *widget,
36 StickyNote *note)
37 {
38 stickynotes_remove (note);
39
40 return TRUE;
41 }
42
43 /* Sticky Window Callback : Resize the window. */
stickynote_resize_cb(GtkWidget * widget,GdkEventButton * event,StickyNote * note)44 gboolean stickynote_resize_cb (GtkWidget *widget,
45 GdkEventButton *event,
46 StickyNote *note)
47 {
48 if (event->type == GDK_BUTTON_PRESS && event->button == 1) {
49 if (widget == note->w_resize_se)
50 gtk_window_begin_resize_drag (GTK_WINDOW (note->w_window),
51 GDK_WINDOW_EDGE_SOUTH_EAST,
52 event->button, event->x_root,
53 event->y_root, event->time);
54 else /* if (widget == note->w_resize_sw) */
55 gtk_window_begin_resize_drag (GTK_WINDOW (note->w_window),
56 GDK_WINDOW_EDGE_SOUTH_WEST,
57 event->button, event->x_root,
58 event->y_root, event->time);
59 }
60 else
61 return FALSE;
62
63 return TRUE;
64 }
65
66 /* Sticky Window Callback : Move the window or edit the title. */
67 gboolean
stickynote_move_cb(GtkWidget * widget,GdkEventButton * event,StickyNote * note)68 stickynote_move_cb (GtkWidget *widget,
69 GdkEventButton *event,
70 StickyNote *note)
71 {
72 if (event->type == GDK_BUTTON_PRESS && event->button == 1)
73 gtk_window_begin_move_drag (GTK_WINDOW (note->w_window),
74 event->button, event->x_root,
75 event->y_root, event->time);
76 else if (event->type == GDK_2BUTTON_PRESS && event->button == 1)
77 stickynote_change_properties (note);
78 else
79 return FALSE;
80
81 return TRUE;
82 }
83
84 /* Sticky Window Callback : Store settings when resizing/moving the window */
85 gboolean
stickynote_configure_cb(GtkWidget * widget,GdkEventConfigure * event,StickyNote * note)86 stickynote_configure_cb (GtkWidget *widget,
87 GdkEventConfigure *event,
88 StickyNote *note)
89 {
90 note->x = event->x;
91 note->y = event->y;
92 note->w = event->width;
93 note->h = event->height;
94
95 stickynotes_save ();
96
97 return FALSE;
98 }
99
100 /* Sticky Window Callback : Get confirmation when deleting the window. */
101 gboolean
stickynote_delete_cb(GtkWidget * widget,GdkEvent * event,StickyNote * note)102 stickynote_delete_cb (GtkWidget *widget,
103 GdkEvent *event,
104 StickyNote *note)
105 {
106 stickynotes_remove (note);
107
108 return TRUE;
109 }
110
111 /* Sticky Window Callback : Popup the right click menu. */
112 gboolean
stickynote_show_popup_menu(GtkWidget * widget,GdkEventButton * event,GtkWidget * popup_menu)113 stickynote_show_popup_menu (GtkWidget *widget,
114 GdkEventButton *event,
115 GtkWidget *popup_menu)
116 {
117 if (event->type == GDK_BUTTON_PRESS && event->button == 3) {
118 gtk_menu_popup_at_pointer (GTK_MENU (popup_menu),
119 (const GdkEvent*) event);
120 }
121
122 return FALSE;
123 }
124
125
126 /* Popup Menu Callback : Create a new sticky note */
popup_create_cb(GtkWidget * widget,StickyNote * note)127 void popup_create_cb (GtkWidget *widget,
128 StickyNote *note)
129 {
130 stickynotes_add (gtk_widget_get_screen (note->w_window));
131 }
132
133 /* Popup Menu Callback : Destroy selected sticky note */
134 void
popup_destroy_cb(GtkWidget * widget,StickyNote * note)135 popup_destroy_cb (GtkWidget *widget,
136 StickyNote *note)
137 {
138 stickynotes_remove (note);
139 }
140
141 /* Popup Menu Callback : Lock/Unlock selected sticky note */
142 void
popup_toggle_lock_cb(GtkToggleAction * action,StickyNote * note)143 popup_toggle_lock_cb (GtkToggleAction *action,
144 StickyNote *note)
145 {
146 stickynote_set_locked (note,
147 gtk_toggle_action_get_active (action));
148 }
149
150 /* Popup Menu Callback : Change sticky note properties */
151 void
popup_properties_cb(GtkWidget * widget,StickyNote * note)152 popup_properties_cb (GtkWidget *widget,
153 StickyNote *note)
154 {
155 stickynote_change_properties (note);
156 }
157
158 /* Properties Dialog Callback : Apply title */
159 void
properties_apply_title_cb(StickyNote * note)160 properties_apply_title_cb (StickyNote *note)
161 {
162 stickynote_set_title (note,
163 gtk_entry_get_text (GTK_ENTRY (note->w_entry)));
164 }
165
166 /* Properties Dialog Callback : Apply color */
167 void
properties_apply_color_cb(StickyNote * note)168 properties_apply_color_cb (StickyNote *note)
169 {
170 char *color_str = NULL;
171 char *font_color_str = NULL;
172
173 if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (note->w_def_color))) {
174 GdkRGBA color, font_color;
175
176 gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (note->w_color),
177 &color);
178 gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (note->w_font_color),
179 &font_color);
180
181 color_str = gdk_rgba_to_string (&color);
182 font_color_str = gdk_rgba_to_string (&font_color);
183 }
184
185 stickynote_set_color (note, color_str,
186 font_color_str, TRUE);
187
188 g_free (color_str);
189 g_free (font_color_str);
190 }
191
192 /* Properties Dialog Callback : Apply font */
properties_apply_font_cb(StickyNote * note)193 void properties_apply_font_cb (StickyNote *note)
194 {
195 const gchar *font_str = NULL;
196
197 if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (note->w_def_font)))
198 font_str = gtk_font_button_get_font_name (GTK_FONT_BUTTON (note->w_font));
199
200 stickynote_set_font (note, font_str, TRUE);
201 }
202
203 /* Properties Dialog Callback : Color */
204 void
properties_color_cb(GtkWidget * button,StickyNote * note)205 properties_color_cb (GtkWidget *button,
206 StickyNote *note)
207 {
208 properties_apply_color_cb (note);
209 }
210
211 /* Properties Dialog Callback : Font */
212 void
properties_font_cb(GtkWidget * button,StickyNote * note)213 properties_font_cb (GtkWidget *button,
214 StickyNote *note)
215 {
216 const char *font_str = gtk_font_button_get_font_name (GTK_FONT_BUTTON (button));
217 stickynote_set_font (note, font_str, TRUE);
218 }
219
220 /* Properties Dialog Callback : Activate */
221 void
properties_activate_cb(GtkWidget * widget,StickyNote * note)222 properties_activate_cb (GtkWidget *widget,
223 StickyNote *note)
224 {
225 gtk_dialog_response (GTK_DIALOG (note->w_properties),
226 GTK_RESPONSE_CLOSE);
227 }
228