1 /* A very simple monolith program.
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: 01_label_and_button.c,v 1.8 2002/11/02 18:53:46 rich Exp $
28 #include "ml_window.h"
29 #include "ml_flow_layout.h"
31 #include "ml_button.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 ml_label lb; /* Label. */
50 int count; /* Count of number of button presses. */
53 static void increment (ml_session, void *);
54 static void update_label (pool pool, ml_label lb, int count);
57 app_main (ml_session session)
59 pool pool = ml_session_pool (session);
66 /* Create the private, per-session data area. */
67 data = pmalloc (pool, sizeof *data);
70 /* Create the top-level window. */
71 w = new_ml_window (session, pool);
73 /* Create the flow layout widget which will be packed into the window. */
74 lay = new_ml_flow_layout (pool);
76 /* Create the label and button. */
77 data->lb = lb = new_ml_label (pool, 0);
78 update_label (pool, data->lb, 0);
80 b = new_ml_button (pool, "Push me!");
81 ml_button_set_callback (b, increment, session, data);
83 /* Pack the label and button into the flow layout widget. */
84 ml_flow_layout_pack (lay, lb);
85 ml_flow_layout_pack (lay, b);
87 /* Pack the flow layout widget into the window. */
88 ml_window_pack (w, lay);
91 /* This callback is called whenever the button is pressed. */
93 increment (ml_session session, void *vp)
95 struct data *data = (struct data *) vp;
97 update_label (ml_session_pool (session), data->lb, ++data->count);
100 /* This function just updates the label, once from the main function, and
101 * again each time we press the button.
104 update_label (pool pool, ml_label lb, int count)
106 ml_widget_set_property (lb, "text",
108 "Button pressed: <b>%d</b><br>",