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: 08_menus.c,v 1.1 2002/11/30 15:55:46 rich Exp $
28 #include "ml_window.h"
30 #include "ml_text_label.h"
32 /*----- The following standard boilerplate code must appear -----*/
34 /* Main entry point to the app. */
35 static void app_main (ml_session);
38 handle_request (rws_request rq)
40 return ml_entry_point (rq, app_main);
43 /*----- End of standard boilerplate code -----*/
45 /* Private per-session data. */
48 ml_window win; /* Top-level window. */
49 ml_menubar menubar; /* Menubar along top of window. */
50 ml_text_label text; /* Label displayed in the main window. */
53 static void set_red (ml_session session, void *vdata);
54 static void set_green (ml_session session, void *vdata);
55 static void set_blue (ml_session session, void *vdata);
56 static void set_black (ml_session session, void *vdata);
57 static void set_small (ml_session session, void *vdata);
58 static void set_medium (ml_session session, void *vdata);
59 static void set_large (ml_session session, void *vdata);
62 app_main (ml_session session)
64 pool pool = ml_session_pool (session);
68 /* Create the private, per-session data area and save it in the
71 data = pmalloc (pool, sizeof *data);
73 /* Create the top-level window. */
74 data->win = new_ml_window (session, pool);
76 /* Create the menubar. */
77 data->menubar = new_ml_menubar (pool);
79 /* Create the "Colours" menu. */
80 menu = new_ml_menu (pool);
81 ml_menu_push_back_button (menu, "Red", set_red, session, data);
82 ml_menu_push_back_button (menu, "Green", set_green, session, data);
83 ml_menu_push_back_button (menu, "Blue", set_blue, session, data);
84 ml_menu_push_back_button (menu, "Black", set_black, session, data);
86 /* Pack the "Colours" menu. */
87 ml_menubar_push_back (data->menubar, "Colours", menu);
89 /* Create the "Sizes" menu. */
90 menu = new_ml_menu (pool);
91 ml_menu_push_back_button (menu, "Small", set_small, session, data);
92 ml_menu_push_back_button (menu, "Medium", set_medium, session, data);
93 ml_menu_push_back_button (menu, "Large", set_large, session, data);
95 /* Pack the "Sizes" menu. */
96 ml_menubar_push_back (data->menubar, "Sizes", menu);
98 /* Create the text which appears on the page. (C) Eric Meyer. */
99 data->text = new_ml_text_label
102 "In other CSS-aware browsers, like Internet Explorer or Opera, you'll see the toplevel links, and they'll work just fine. The popout menus won't work, that's all. Of course, this means that the browser is downloading the contents of the complete menu, but only able to display a small part of what it downloaded. This is in some respects unfortunate, but at least the basic menu will still function. And the amount of markup involved is probably a lot fewer characters than a similar Javascript-driven menu intended to serve a similar purpose.\n\n"
103 "(And if you're grumbling that you don't see why anyone would deploy a menu system that only worked in one browser, then you should see how many Javascript menus I deal with that don't work in more than one or two browsers-- usually because they're doing browser sniffing as if this were still 1998. But I digress.)\n\n"
104 "If the browser is too old to understand CSS, or doesn't support CSS because (for example) it's a text-mode browser like Lynx, then the user will get the entire menu as a set of nested lists. No problem.\n\n");
106 /* Put the text into the menubar widget, so it appears. */
107 ml_menubar_pack (data->menubar, data->text);
109 /* Pack the menubar inside the window. */
110 ml_window_pack (data->win, data->menubar);
114 set_red (ml_session session, void *vdata)
116 struct data *data = (struct data *) vdata;
118 ml_widget_set_property (data->text, "color", "red");
122 set_green (ml_session session, void *vdata)
124 struct data *data = (struct data *) vdata;
126 ml_widget_set_property (data->text, "color", "green");
130 set_blue (ml_session session, void *vdata)
132 struct data *data = (struct data *) vdata;
134 ml_widget_set_property (data->text, "color", "blue");
138 set_black (ml_session session, void *vdata)
140 struct data *data = (struct data *) vdata;
142 ml_widget_set_property (data->text, "color", "black");
146 set_small (ml_session session, void *vdata)
148 struct data *data = (struct data *) vdata;
150 ml_widget_set_property (data->text, "font.size", "small");
154 set_medium (ml_session session, void *vdata)
156 struct data *data = (struct data *) vdata;
158 ml_widget_set_property (data->text, "font.size", "medium");
162 set_large (ml_session session, void *vdata)
164 struct data *data = (struct data *) vdata;
166 ml_widget_set_property (data->text, "font.size", "large");