1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
|
/*
* ===========================
* VDK Visual Development Kit
* Version 2.0
* December 2000
* ===========================
*
* Copyright (C) 1998, Mario Motta
* Developed by Mario Motta <mmotta@guest.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*/
#include <vdk/application.h>
#include <vdk/forms.h>
#include <gdk/gdkkeysyms.h>
static int answer = 0;
static int mtype = 0;
static int timerId = 0;
static int
OnDialogDestroy (GtkWidget* dialog, gpointer gp)
{
if(timerId)
{
gtk_timeout_remove(timerId);
timerId = 0;
}
gtk_widget_destroy(dialog);
gtk_main_quit();
return TRUE;
}
static void
OnDialogResponse(GtkWidget *dialog, gint response_id, gpointer gp)
{
switch(response_id)
{
case GTK_RESPONSE_OK:
answer = VDK_IDOK;
break;
case GTK_RESPONSE_CANCEL:
answer = VDK_IDCANCEL;
break;
case GTK_RESPONSE_YES:
answer = VDK_IDYES;
break;
case GTK_RESPONSE_NO:
answer = VDK_IDNO;
break;
case GTK_RESPONSE_DELETE_EVENT:
switch(mtype & VDK_TYPEMASK)
{
case VDK_OKCANCEL:
answer = VDK_IDCANCEL;
break;
case VDK_YESNO:
answer = VDK_IDNO;
break;
default:
answer = VDK_IDCANCEL;
}
break;
default:
answer = response_id;
}
OnDialogDestroy(dialog,NULL);
}
static int
OnDialogKeyPress(GtkWidget *dialog, GdkEvent* ev, gpointer gp)
{
GdkEventKey* event = (GdkEventKey*) ev;
int answer = -1;
switch(event->keyval)
{
case GDK_Return :
switch(mtype & VDK_TYPEMASK)
{
case VDK_OKCANCEL:
answer = VDK_IDOK;
break;
case VDK_YESNO:
answer = VDK_IDYES;
break;
default:
answer = VDK_IDOK;
}
break;
case GDK_Escape:
switch(mtype & VDK_TYPEMASK)
{
case VDK_OKCANCEL:
answer = VDK_IDCANCEL;
break;
case VDK_YESNO:
answer = VDK_IDNO;
break;
default:
answer = VDK_IDCANCEL;
}
}
if(answer >= 0)
{
OnDialogResponse(dialog, answer, gp);
return TRUE;
}
else
return FALSE;
}
static int HandleTimeOut(gpointer gp)
{
if(timerId)
{
gtk_timeout_remove(timerId);
timerId = 0;
}
GtkWidget* dialog = reinterpret_cast <GtkWidget*>(gp);
OnDialogResponse(dialog, GTK_RESPONSE_DELETE_EVENT,NULL);
return FALSE;
}
static GtkWidget*
MakeDialog(GtkMessageType type,GtkButtonsType buttons, char* prompt,
GtkWindow* parent, unsigned int wait)
{
answer = 0;
GtkWidget* dialog =
gtk_message_dialog_new (
parent,
GtkDialogFlags(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT),
type,
buttons,
prompt);
if(parent)
{
gtk_window_set_transient_for (GTK_WINDOW (dialog),
GTK_WINDOW (parent));
gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
}
gtk_signal_connect (GTK_OBJECT (dialog), "destroy",
GTK_SIGNAL_FUNC (::OnDialogDestroy), NULL);
gtk_signal_connect (GTK_OBJECT (dialog), "key_press_event",
GTK_SIGNAL_FUNC (::OnDialogKeyPress), NULL);
gtk_signal_connect (GTK_OBJECT (dialog),
"response",
GTK_SIGNAL_FUNC (::OnDialogResponse),
NULL);
if(wait)
timerId = gtk_timeout_add(wait,::HandleTimeOut,dialog);
return dialog;
}
gint
VDKApplication::VDKMessageBox(char* caption, char* text,
int mode,char *oktext ,char *canceltext ,unsigned int wait)
{
GtkMessageType type;
GtkButtonsType buttons;
mtype = mode;
/* masks icon */
switch(mode & VDK_ICONMASK)
{
case VDK_ICONQUESTION:
type = GTK_MESSAGE_QUESTION;
break;
case VDK_ICONINFORMATION:
type = GTK_MESSAGE_INFO;
break;
case VDK_ICONERROR:
type = GTK_MESSAGE_ERROR;
break;
case VDK_ICONSTOP:
type = GTK_MESSAGE_WARNING;
break;
default:
type = GTK_MESSAGE_INFO;
}
/* masks buttons */
switch(mode & VDK_TYPEMASK)
{
case VDK_OKCANCEL:
buttons = GTK_BUTTONS_OK_CANCEL;
break;
case VDK_YESNO:
buttons = GTK_BUTTONS_YES_NO;
break;
case VDK_OK:
buttons = GTK_BUTTONS_OK;
break;
default:
buttons = GTK_BUTTONS_OK;
break;
}
GtkWidget *dialog = MakeDialog(type,
buttons,
text,
GTK_WINDOW(MainForm->Window()),
wait);
if(caption)
gtk_window_set_title(GTK_WINDOW(dialog),caption);
gtk_window_position(GTK_WINDOW(dialog),GTK_WIN_POS_CENTER);
gtk_widget_show(dialog);
gtk_main();
/*
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
*/
return answer;
}
|