1 /* Monolith dialog class.
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: ml_dialog.c,v 1.4 2002/11/13 21:41:01 rich Exp $
23 #include <pthr_iolib.h>
26 #include "ml_widget.h"
27 #include "ml_table_layout.h"
28 #include "ml_flow_layout.h"
30 #include "ml_text_label.h"
32 #include "ml_button.h"
33 #include "ml_close_button.h"
34 #include "ml_dialog.h"
36 static void repaint (void *, ml_session, const char *, io_handle);
38 struct ml_widget_operations dialog_ops =
45 struct ml_widget_operations *ops;
46 pool pool; /* Pool for allocations. */
48 ml_table_layout tbl; /* Top-level table layout. */
49 ml_text_label title; /* Title-bar. */
50 ml_image icon; /* Icon. */
51 ml_label text; /* Main text. */
52 ml_flow_layout buttons; /* Buttons. */
56 new_ml_dialog (pool pool)
58 ml_dialog w = pmalloc (pool, sizeof *w);
63 /* At the top level, a dialog is nothing more than a table layout. */
64 w->tbl = new_ml_table_layout (pool, 3, 2);
67 w->title = new_ml_text_label (pool, 0);
68 ml_widget_set_property (w->title, "font.weight", "bold");
69 ml_table_layout_pack (w->tbl, w->title, 0, 0);
70 ml_table_layout_set_colspan (w->tbl, 0, 0, 2);
73 w->icon = new_ml_image (pool, 0);
74 ml_table_layout_pack (w->tbl, w->icon, 1, 0);
77 w->text = new_ml_label (pool, 0);
78 ml_table_layout_pack (w->tbl, w->text, 1, 1);
81 w->buttons = new_ml_flow_layout (pool);
82 ml_table_layout_pack (w->tbl, w->buttons, 2, 0);
83 ml_table_layout_set_colspan (w->tbl, 2, 0, 2);
89 ml_dialog_set_text (ml_dialog w, const char *text)
91 ml_widget_set_property (w->text, "text", text);
95 ml_dialog_get_text (ml_dialog w)
99 ml_widget_get_property (w->text, "text", text);
104 ml_dialog_set_title (ml_dialog w, const char *title)
106 ml_widget_set_property (w->title, "text", title);
110 ml_dialog_get_title (ml_dialog w)
114 ml_widget_get_property (w->title, "text", title);
119 ml_dialog_set_icon (ml_dialog w, const char *icon)
121 ml_widget_set_property (w->icon, "image", icon);
125 ml_dialog_get_icon (ml_dialog w)
129 ml_widget_get_property (w->icon, "image", icon);
134 ml_dialog_clear_buttons (ml_dialog w)
136 ml_flow_layout_clear (w->buttons);
140 ml_dialog_add_button (ml_dialog w, const char *text,
141 void (*callback_fn) (ml_session, void *),
142 ml_session session, void *data)
146 /* Create a new button widget. */
147 b = new_ml_button (w->pool, text);
148 ml_button_set_callback (b, callback_fn, session, data);
150 /* Pack it into the buttons flow layout. */
151 ml_flow_layout_pack (w->buttons, b);
155 ml_dialog_add_close_button (ml_dialog w, const char *text, int flags)
159 /* Create new button. */
160 b = new_ml_close_button (w->pool, text);
162 if ((flags & ML_DIALOG_CLOSE_RELOAD_OPENER))
163 ml_widget_set_property (b, "button.reload-opener", 1);
166 ml_flow_layout_pack (w->buttons, b);
170 ml_ok_window (pool pool, ml_session session, const char *text, int flags)
174 const char *title = "That operation was carried out successfully";
176 win = new_ml_window (session, pool);
177 dlg = new_ml_dialog (pool);
179 ml_window_set_title (win, title);
180 ml_dialog_set_text (dlg, text);
181 ml_dialog_set_title (dlg, title);
182 // ml_dialog_set_icon (dlg, ...);
184 if ((flags & ML_DIALOG_CLOSE_BUTTON))
185 ml_dialog_add_close_button (dlg, "Close window", flags);
187 ml_window_pack (win, dlg);
193 ml_error_window (pool pool, ml_session session, const char *text, int flags)
197 const char *title = "There was an error";
199 win = new_ml_window (session, pool);
200 dlg = new_ml_dialog (pool);
202 ml_window_set_title (win, title);
203 ml_dialog_set_text (dlg, text);
204 ml_dialog_set_title (dlg, title);
205 // ml_dialog_set_icon (dlg, ...);
207 if ((flags & ML_DIALOG_CLOSE_BUTTON))
208 ml_dialog_add_close_button (dlg, "Close window", flags);
210 ml_window_pack (win, dlg);
216 repaint (void *vw, ml_session session, const char *windowid, io_handle io)
218 ml_dialog w = (ml_dialog) vw;
220 ml_widget_repaint (w->tbl, session, windowid, io);