2 * irreco - Ir Remote Control
3 * Copyright (C) 2007 Arto Karppinen (arto.karppinen@iki.fi)
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "irreco_button_dlg.h"
21 #include "irreco_button.h"
22 #include "irreco_style_browser_dlg.h"
23 #include "irreco_cmd_chain_editor.h"
26 * @addtogroup IrrecoButtonDlg
29 * @todo PURPOCE OF CLASS.
36 * Source file of @ref IrrecoButtonDlg.
40 IRRECO_STYLE_DLG_SHOW
= 1,
46 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
48 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
49 void irreco_button_dlg_create_window(IrrecoButtonDlg
* button_dlg
,
50 IrrecoWindow
* parent
,
52 void irreco_button_dlg_scrolled_size_request(GtkWidget
* widget
,
53 GtkRequisition
* requisition
,
55 void irreco_button_dlg_size_request(GtkWidget
*widget
,
56 GtkRequisition
*requisition
,
58 void irreco_button_dlg_style_click(IrrecoButton
* irreco_button
,
63 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
64 /* Button dialog structure management. */
65 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
68 * @name Button dialog structure management
76 * Allows user to change the style, command and other properties of a button.
78 IrrecoButtonDlg
* irreco_button_dlg_create(IrrecoData
* irreco_data
)
80 IrrecoButtonDlg
* button_dlg
;
83 button_dlg
= g_slice_new0(IrrecoButtonDlg
);
84 button_dlg
->irreco_data
= irreco_data
;
85 button_dlg
->accepted_cmd_chain
= irreco_cmd_chain_create();
86 IRRECO_RETURN_PTR(button_dlg
);
89 void irreco_button_dlg_clear(IrrecoButtonDlg
* button_dlg
)
93 button_dlg
->new_style
= NULL
;
94 g_free(button_dlg
->accepted_title
);
95 button_dlg
->accepted_title
= NULL
;
96 irreco_cmd_chain_remove_all(button_dlg
->accepted_cmd_chain
);
97 button_dlg
->accepted_style
= NULL
;
102 void irreco_button_dlg_destroy(IrrecoButtonDlg
* button_dlg
)
105 irreco_button_dlg_clear(button_dlg
);
106 irreco_cmd_chain_destroy(button_dlg
->accepted_cmd_chain
);
107 g_slice_free(IrrecoButtonDlg
, button_dlg
);
112 void irreco_button_dlg_print_data(const gchar
* title
,
113 IrrecoCmdChain
* cmd_chain
,
114 IrrecoThemeButton
* style
)
117 IRRECO_PRINTF("Title: \"%s\"\n", title
);
120 IRRECO_PRINTF("Style is NULL\n");
122 IRRECO_PRINTF("Title: \"%s\"\n", style
->name
->str
);
125 if (cmd_chain
== NULL
) {
126 IRRECO_PRINTF("Command chain is NULL\n");
128 IRRECO_PRINTF("Command chain:\n");
129 irreco_cmd_chain_print(cmd_chain
);
135 void irreco_button_dlg_set(IrrecoButtonDlg
* button_dlg
,
137 IrrecoCmdChain
* cmd_chain
,
138 IrrecoThemeButton
* style
)
141 IRRECO_DEBUG("Setting button dialog:\n");
142 irreco_button_dlg_print_data(title
, cmd_chain
, style
);
144 irreco_button_dlg_clear(button_dlg
);
145 button_dlg
->accepted_title
= g_strdup(title
);
146 if (cmd_chain
!= NULL
) {
147 irreco_cmd_chain_copy(cmd_chain
,
148 button_dlg
->accepted_cmd_chain
);
150 button_dlg
->accepted_style
= style
;
155 * Copy information from IrrecoButton into IrrecoButtonDlg.
157 void irreco_button_dlg_data_from_button(IrrecoButtonDlg
* button_dlg
,
158 IrrecoButton
* irreco_button
)
161 irreco_button_dlg_set(button_dlg
, irreco_button
->title
,
162 irreco_button_get_cmd_chain(irreco_button
),
163 irreco_button
->style
);
169 * Copy information from IrrecoButtonDlg to IrrecoButton.
171 void irreco_button_dlg_data_to_button(IrrecoButtonDlg
* button_dlg
,
172 IrrecoButton
* irreco_button
)
175 irreco_button_set_title(irreco_button
, button_dlg
->accepted_title
);
176 irreco_button_set_cmd_chain(irreco_button
,
177 button_dlg
->accepted_cmd_chain
);
178 irreco_button_set_style(irreco_button
, button_dlg
->accepted_style
);
182 void irreco_button_dlg_print(IrrecoButtonDlg
* button_dlg
)
184 IrrecoCmdChain
*new_cmd_chain
= NULL
;
187 IRRECO_DEBUG("Accepted data:\n");
188 irreco_button_dlg_print_data(button_dlg
->accepted_title
,
189 button_dlg
->accepted_cmd_chain
,
190 button_dlg
->accepted_style
);
191 IRRECO_DEBUG("New data:\n");
194 IRRECO_DEBUG("%p\n", (void*) button_dlg
->editor
);
195 if (button_dlg
->editor
) {
197 new_cmd_chain
= irreco_cmd_chain_editor_get_chain(
198 IRRECO_CMD_CHAIN_EDITOR(button_dlg
->editor
));
202 irreco_button_dlg_print_data(
203 gtk_entry_get_text(GTK_ENTRY(button_dlg
->title_entry
)),
204 new_cmd_chain
, button_dlg
->new_style
);
209 void irreco_button_dlg_update_dialog(IrrecoButtonDlg
* button_dlg
)
212 irreco_cmd_chain_editor_set_chain(IRRECO_CMD_CHAIN_EDITOR(
213 button_dlg
->editor
), button_dlg
->accepted_cmd_chain
);
214 if (button_dlg
->accepted_title
!= NULL
) {
215 gtk_entry_set_text(GTK_ENTRY(button_dlg
->title_entry
),
216 button_dlg
->accepted_title
);
218 gtk_entry_set_text(GTK_ENTRY(button_dlg
->title_entry
), "");
221 irreco_button_set_style(button_dlg
->style_button
,
222 button_dlg
->accepted_style
);
223 irreco_button_create_widget(button_dlg
->style_button
);
224 button_dlg
->new_style
= button_dlg
->accepted_style
;
229 * Show button dialog.
231 * Returns TRUE if user clicks OK.
232 * Returns FALSE otherwise.
234 gboolean
irreco_button_dlg_run(IrrecoButtonDlg
* button_dlg
,
235 IrrecoWindow
* parent
,
238 IrrecoData
*irreco_data
= button_dlg
->irreco_data
;
242 /* Prepare dialog. */
243 irreco_button_dlg_create_window(button_dlg
, parent
, title
);
244 irreco_button_dlg_update_dialog(button_dlg
);
247 gtk_widget_show_all(button_dlg
->dialog
);
248 irreco_button_create_widget(button_dlg
->style_button
);
250 while (rvalue
== -1) {
251 switch (gtk_dialog_run(GTK_DIALOG(button_dlg
->dialog
))) {
252 case GTK_RESPONSE_REJECT
:
256 case GTK_RESPONSE_ACCEPT
:
257 g_free(button_dlg
->accepted_title
);
258 button_dlg
->accepted_title
=
259 g_strdup(gtk_entry_get_text(GTK_ENTRY(
260 button_dlg
->title_entry
)));
261 button_dlg
->accepted_style
= button_dlg
->new_style
;
262 irreco_cmd_chain_editor_apply_changes(
263 IRRECO_CMD_CHAIN_EDITOR(button_dlg
->editor
));
267 case IRRECO_STYLE_DLG_SHOW
:
268 if (irreco_show_style_browser_dlg(
270 GTK_WINDOW(button_dlg
->dialog
),
271 &button_dlg
->new_style
)) {
272 irreco_button_set_style(
273 button_dlg
->style_button
,
274 button_dlg
->new_style
);
275 irreco_button_create_widget(
276 button_dlg
->style_button
);
278 /* Large buttons may blow up the dialog a bit,
279 so resize the dialog as small as possible. */
280 gtk_window_resize(GTK_WINDOW(button_dlg
->dialog
), 1, 1);
283 case IRRECO_RESPONSE_CLEAR
:
284 gtk_entry_set_text(GTK_ENTRY(
285 button_dlg
->title_entry
), "");
286 irreco_cmd_chain_editor_clear_chain(
287 IRRECO_CMD_CHAIN_EDITOR(button_dlg
->editor
));
292 gtk_widget_destroy(button_dlg
->dialog
);
293 button_dlg
->dialog
= NULL
;
294 irreco_button_layout_destroy(button_dlg
->layout
);
295 button_dlg
->layout
= NULL
;
296 button_dlg
->title_entry
= NULL
;
297 button_dlg
->style_button
= NULL
;
298 button_dlg
->editor
= NULL
;
299 IRRECO_RETURN_INT(rvalue
);
304 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
305 /* Button dialog building. */
306 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
309 * @name Button dialog building
313 void irreco_button_dlg_create_window(IrrecoButtonDlg
* button_dlg
,
314 IrrecoWindow
* parent
,
318 GtkWidget
*vbox_left
;
319 GtkWidget
*vbox_right
;
321 GtkWidget
*style_frame
;
322 GtkWidget
*style_scrolled
;
323 GtkWidget
*style_fixed
;
325 GtkWidget
*editor_frame
;
328 /* Create objects. */
329 button_dlg
->dialog
= gtk_dialog_new_with_buttons(
330 title
, irreco_window_get_gtk_window(parent
),
331 GTK_DIALOG_MODAL
| GTK_DIALOG_DESTROY_WITH_PARENT
|
332 GTK_DIALOG_NO_SEPARATOR
,
333 GTK_STOCK_CLEAR
, IRRECO_RESPONSE_CLEAR
,
334 GTK_STOCK_CANCEL
, GTK_RESPONSE_REJECT
,
335 GTK_STOCK_OK
, GTK_RESPONSE_ACCEPT
,
337 hbox
= gtk_hbox_new(FALSE
, 10);
338 vbox_left
= gtk_vbox_new(FALSE
, 0);
339 vbox_right
= gtk_vbox_new(FALSE
, 0);
341 button_dlg
->title_entry
= gtk_entry_new();
342 style_frame
= gtk_frame_new(NULL
);
343 style_scrolled
= gtk_scrolled_window_new(NULL
, NULL
);
344 style_fixed
= gtk_fixed_new();
345 button_dlg
->layout
= irreco_button_layout_create(style_fixed
, NULL
);
346 button_dlg
->style_button
= irreco_button_create(button_dlg
->layout
,
351 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(button_dlg
->dialog
)->vbox
),
352 irreco_gtk_align(hbox
, 0, 0, 1, 1, 8, 8, 8, 8));
353 gtk_container_add(GTK_CONTAINER(hbox
), vbox_left
);
354 gtk_container_add(GTK_CONTAINER(hbox
), vbox_right
);
356 /* Connect signals. */
357 g_signal_connect(G_OBJECT(button_dlg
->dialog
), "size-request",
358 G_CALLBACK(irreco_button_dlg_size_request
),
360 g_signal_connect(G_OBJECT(style_scrolled
), "size-request",
361 G_CALLBACK(irreco_button_dlg_scrolled_size_request
),
364 /* Build left side of dialog. */
365 gtk_box_pack_start(GTK_BOX(vbox_left
),
366 irreco_gtk_label(_("Name"), 0.5, 1, 0, 0, 0, 0),
368 gtk_box_pack_start(GTK_BOX(vbox_left
),
369 button_dlg
->title_entry
,
371 gtk_box_pack_start(GTK_BOX(vbox_left
),
372 irreco_gtk_label(_("Style"), 0.5, 1, 10, 0, 0, 0),
374 gtk_box_pack_start(GTK_BOX(vbox_left
),
377 gtk_container_add(GTK_CONTAINER(style_frame
), style_scrolled
);
378 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(style_scrolled
),
379 GTK_POLICY_AUTOMATIC
,
380 GTK_POLICY_AUTOMATIC
);
381 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(
383 irreco_gtk_align(style_fixed
,
384 0.5, 0.5, 0, 0, 8, 8, 8, 8));
386 /* Build right side of dialog. */
387 button_dlg
->editor
= irreco_cmd_chain_editor_new(
388 button_dlg
->irreco_data
, GTK_WINDOW(button_dlg
->dialog
));
389 irreco_cmd_chain_editor_set_chain(IRRECO_CMD_CHAIN_EDITOR(
390 button_dlg
->editor
), button_dlg
->accepted_cmd_chain
);
391 editor_frame
= gtk_frame_new(NULL
);
393 gtk_box_pack_start(GTK_BOX(vbox_right
), irreco_gtk_label(
394 _("Command Chain"), 0.5, 1, 0, 0, 0, 0),
396 gtk_container_add(GTK_CONTAINER(vbox_right
), editor_frame
);
397 gtk_container_add(GTK_CONTAINER(editor_frame
), button_dlg
->editor
);
399 /* Connect callbacks. */
400 irreco_button_layout_set_press_callback(button_dlg
->layout
,
402 irreco_button_layout_set_release_callback(button_dlg
->layout
,
403 irreco_button_dlg_style_click
);
404 irreco_button_layout_set_callback_data(button_dlg
->layout
,
414 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
415 /* Signal callbacks. */
416 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
419 * @name Signal callbacks
424 * Adjust size GtkRequisition in a way that will hide the scrollbar if possible.
426 void irreco_button_dlg_scrolled_size_request(GtkWidget
* widget
,
427 GtkRequisition
* requisition
,
430 GtkAdjustment
*adjustment
;
433 adjustment
= gtk_scrolled_window_get_vadjustment(
434 GTK_SCROLLED_WINDOW(widget
));
435 requisition
->height
= adjustment
->upper
;
436 adjustment
= gtk_scrolled_window_get_hadjustment(
437 GTK_SCROLLED_WINDOW(widget
));
438 requisition
->width
= adjustment
->upper
;
440 IRRECO_DEBUG("value %f\n", adjustment->value);
441 IRRECO_DEBUG("lower %f\n", adjustment->lower);
442 IRRECO_DEBUG("upper %f\n", adjustment->upper);
443 IRRECO_DEBUG("step_increment %f\n", adjustment->step_increment);
444 IRRECO_DEBUG("page_increment %f\n", adjustment->page_increment);
445 IRRECO_DEBUG("page_size %f\n", adjustment->page_size);
451 void irreco_button_dlg_size_request(GtkWidget
*widget
,
452 GtkRequisition
*requisition
,
456 requisition
->height
= 999;
460 void irreco_button_dlg_style_click(IrrecoButton
* irreco_button
,
464 gtk_dialog_response(GTK_DIALOG(dialog
), IRRECO_STYLE_DLG_SHOW
);
465 irreco_button_up(irreco_button
);