Add to git.
[monolith.git] / examples / 03_many_toy_calculators.c
1 /* Toy calculator from example 02 turned into a reusable widget.
2  * - by Richard W.M. Jones <rich@annexia.org>
3  *
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.
8  *
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.
13  *
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.
17  *
18  * $Id: 03_many_toy_calculators.c,v 1.3 2002/09/07 13:46:58 rich Exp $
19  */
20
21 #include <string.h>
22
23 #include <pool.h>
24 #include <pstring.h>
25 #include <pthr_cgi.h>
26
27 #include "monolith.h"
28 #include "ml_window.h"
29 #include "ml_table_layout.h"
30
31 #include "toy_calculator.h"
32
33 /* Main entry point to the app. */
34 static void app_main (ml_session);
35
36 int
37 handle_request (rws_request rq)
38 {
39   return ml_entry_point (rq, app_main);
40 }
41
42 static void
43 app_main (ml_session session)
44 {
45   pool pool = ml_session_pool (session);
46   ml_window w;
47   ml_table_layout tbl;
48   toy_calculator calcs[4];
49
50   /* Create the top-level window. */
51   w = new_ml_window (session, pool);
52
53   /* Create a table layout widget to arrange the calculators. */
54   tbl = new_ml_table_layout (pool, 2, 2);
55
56   /* Create the calculators and pack them into the table layout. */
57   calcs[0] = new_toy_calculator (pool, session);
58   ml_table_layout_pack (tbl, calcs[0], 0, 0);
59   calcs[1] = new_toy_calculator (pool, session);
60   ml_table_layout_pack (tbl, calcs[1], 0, 1);
61   calcs[2] = new_toy_calculator (pool, session);
62   ml_table_layout_pack (tbl, calcs[2], 1, 0);
63   calcs[3] = new_toy_calculator (pool, session);
64   ml_table_layout_pack (tbl, calcs[3], 1, 1);
65
66   /* Pack the table into the window. */
67   ml_window_pack (w, tbl);
68 }