source: trunk/third/gnome-utils/gdialog/msgbox.c @ 18641

Revision 18641, 3.4 KB checked in by ghudson, 21 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18640, which included commits to RCS files with non-trunk default branches.
Line 
1/*
2 *  msgbox.c -- implements the message box and info box
3 *
4 *  AUTHOR: Savio Lam (lam836@cs.cuhk.hk)
5 *
6 *  This program is free software; you can redistribute it and/or
7 *  modify it under the terms of the GNU General Public License
8 *  as published by the Free Software Foundation; either version 2
9 *  of the License, or (at your option) any later version.
10 *
11 *  This program is distributed in the hope that it will be useful,
12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 *  GNU General Public License for more details.
15 *
16 *  You should have received a copy of the GNU General Public License
17 *  along with this program; if not, write to the Free Software
18 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21#include "dialog.h"
22
23#define DIALOG_INFOBOX_TIMEOUT 5000 /* Quit after 5 sec. in --infobox mode */
24
25static gboolean dialog_infobox_quit (gpointer data)
26{
27        gtk_main_quit ();
28        return FALSE; /* Automatically calls g_source_remove */
29}
30
31static void cancelled(GtkWidget *w, gpointer *d)
32{
33        exit(-1);
34}
35
36static void okayed(GtkWidget *w, int button, gpointer *d)
37{
38        exit(0);
39}
40
41
42/*
43 * Display a message box. Program will pause and display an "OK" button
44 * if the parameter 'pause' is non-zero.
45 */
46int dialog_msgbox(const char *title, const char *prompt, int height, int width,
47                  int pause)
48{
49        int i, x, y, key = 0;
50        WINDOW *dialog;
51
52
53        if (gnome_mode) {
54                GtkWidget *w;
55
56                w = gtk_dialog_new_with_buttons (title, NULL,
57                                                GTK_DIALOG_DESTROY_WITH_PARENT,
58                                                GTK_STOCK_OK,
59                                                GTK_RESPONSE_OK,
60                                                NULL);
61                gtk_window_set_position (GTK_WINDOW (w), GTK_WIN_POS_CENTER);
62
63                label_autowrap (GTK_DIALOG (w)->vbox, prompt, width);
64
65                gtk_signal_connect(GTK_OBJECT(w), "close",
66                        GTK_SIGNAL_FUNC(cancelled), NULL);
67                gtk_signal_connect_object (GTK_OBJECT (w), "response",
68                              GTK_SIGNAL_FUNC (okayed),NULL);
69                gtk_widget_show_all(w);
70
71                /*
72                 * For --infobox mode.
73                 */
74                if (!pause) {
75                        if (fork ()) {
76                                return 0;
77                        } else {
78                                g_timeout_add (DIALOG_INFOBOX_TIMEOUT,
79                                               dialog_infobox_quit, NULL);
80                        }
81                }
82
83                gtk_main();
84                return 0;
85        }
86        /* center dialog box on screen */
87        x = (COLS - width) / 2;
88        y = (LINES - height) / 2;
89
90#ifndef NO_COLOR_CURSES
91        if (use_shadow)
92                draw_shadow(stdscr, y, x, height, width);
93#endif
94        dialog = newwin(height, width, y, x);
95#ifdef WITH_GPM
96        mouse_setbase(x, y);
97#endif
98        keypad(dialog, TRUE);
99
100        draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr);
101
102        if (title != NULL) {
103                wattrset(dialog, title_attr);
104                wmove(dialog, 0, (width - strlen(title)) / 2 - 1);
105                waddch(dialog, ' ');
106                waddstr(dialog, title);
107                waddch(dialog, ' ');
108        }
109        wattrset(dialog, dialog_attr);
110        print_autowrap(dialog, prompt, width - 2, 1, 2);
111
112        if (pause) {
113                wattrset(dialog, border_attr);
114                wmove(dialog, height - 3, 0);
115                waddch(dialog, ACS_LTEE);
116                for (i = 0; i < width - 2; i++)
117                        waddch(dialog, ACS_HLINE);
118                wattrset(dialog, dialog_attr);
119                waddch(dialog, ACS_RTEE);
120                wmove(dialog, height - 2, 1);
121                for (i = 0; i < width - 2; i++)
122                        waddch(dialog, ' ');
123#ifdef WITH_GPM
124                mouse_mkbutton(height - 2, width / 2 - 4, 6, '\n');
125#endif
126                print_button(dialog, "  OK  ",
127                             height - 2, width / 2 - 4, TRUE);
128
129                wrefresh(dialog);
130                while (key != ESC && key != '\n' && key != ' ')
131                        key = mouse_wgetch(dialog);
132        } else {
133                key = '\n';
134                wrefresh(dialog);
135        }
136
137        delwin(dialog);
138        return key == ESC ? -1 : 0;
139}
Note: See TracBrowser for help on using the repository browser.