2 * - by Richard W.M. Jones <rich@annexia.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library 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 GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 * $Id: 07_toggle_buttons.c,v 1.2 2002/10/30 21:03:01 rich Exp $
28 #include "ml_window.h"
29 #include "ml_toggle_button.h"
30 #include "ml_table_layout.h"
31 #include "ml_text_label.h"
33 /*----- The following standard boilerplate code must appear -----*/
35 /* Main entry point to the app. */
36 static void app_main (ml_session);
39 handle_request (rws_request rq)
41 return ml_entry_point (rq, app_main);
44 /*----- End of standard boilerplate code -----*/
46 /* Private per-session data. */
49 /* The toggle buttons. */
50 ml_toggle_button b[4];
55 static void update_text (ml_session, void *);
58 app_main (ml_session session)
60 pool pool = ml_session_pool (session);
65 /* Create the private, per-session data area and save it in the
68 data = pmalloc (pool, sizeof *data);
70 /* Create the top-level window. */
71 win = new_ml_window (session, pool);
73 /* Create the table layout. */
74 tbl = new_ml_table_layout (pool, 2, 4);
76 /* Create the toggle buttons. */
77 data->b[0] = new_ml_toggle_button (pool, session, "A");
78 data->b[1] = new_ml_toggle_button (pool, session, "B");
79 data->b[2] = new_ml_toggle_button (pool, session, "C");
80 data->b[3] = new_ml_toggle_button (pool, session, "D");
82 /* Create the status label. */
83 data->text = new_ml_text_label (pool, "(press a button)");
85 /* Set the callback on the buttons to a function which will
88 ml_toggle_button_set_callback (data->b[0], update_text, session, data);
89 ml_toggle_button_set_callback (data->b[1], update_text, session, data);
90 ml_toggle_button_set_callback (data->b[2], update_text, session, data);
91 ml_toggle_button_set_callback (data->b[3], update_text, session, data);
93 /* Pack everything together. */
94 ml_table_layout_pack (tbl, data->b[0], 0, 0);
95 ml_table_layout_pack (tbl, data->b[1], 0, 1);
96 ml_table_layout_pack (tbl, data->b[2], 0, 2);
97 ml_table_layout_pack (tbl, data->b[3], 0, 3);
98 ml_table_layout_pack (tbl, data->text, 1, 0);
99 ml_table_layout_set_colspan (tbl, 1, 0, 4);
100 ml_window_pack (win, tbl);
104 update_text (ml_session session, void *vp)
106 pool pool = ml_session_pool (session);
107 struct data *data = (struct data *) vp;
110 /* Get the state of the four buttons. */
111 a = ml_toggle_button_get_state (data->b[0]);
112 b = ml_toggle_button_get_state (data->b[1]);
113 c = ml_toggle_button_get_state (data->b[2]);
114 d = ml_toggle_button_get_state (data->b[3]);
116 ml_widget_set_property
123 a ? "pressed" : "not pressed",
124 b ? "pressed" : "not pressed",
125 c ? "pressed" : "not pressed",
126 d ? "pressed" : "not pressed"));