00001 #ifndef MESSAGE_BOX_IMPLEMENTATION_FILE
00002 #define MESSAGE_BOX_IMPLEMENTATION_FILE
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "message_box.h"
00034
00035 #include <basis/function.h>
00036 #include <basis/guards.h>
00037 #include <wp_passive/argument_list.h>
00038 #include <wp_passive/color.h>
00039 #include <wp_passive/system_string.h>
00040 #include <wp_passive/wp_implementation.h>
00041
00042 #include <X11/Composite.h>
00043 #include <Xm/MessageB.h>
00044
00045 message_box::message_box(manager &root, const c_point &origin,
00046 message_box_kinds kind, const char *message, const char *second_message,
00047 const color &foreground, const color &background)
00048 : worker(root, c_rectangle(origin, origin), NIL, foreground, background),
00049 _kind(kind), _message(message), _second_message(second_message),
00050 last_hit(0), extra_help_box(NIL) {}
00051
00052 message_box::~message_box()
00053 {
00054 XtRemoveCallback(self(), XmNokCallback, XtCallbackProc(message_box_callback),
00055 XtPointer(this));
00056 XtRemoveCallback(self(), XmNcancelCallback,
00057 XtCallbackProc(message_box_callback), XtPointer(this));
00058 XtRemoveCallback(self(), XmNhelpCallback,
00059 XtCallbackProc(message_box_callback), XtPointer(this));
00060 if (extra_help_box) delete extra_help_box;
00061 }
00062
00063 void message_box::draw()
00064 {
00065 if (!visible()) {
00066
00067 switch (_kind) {
00068 case PROCEED: setup_proceed_box(); break;
00069 case INFORMATION: setup_information_box(); break;
00070 case WARNING: setup_warning_box(); break;
00071 case HELP: setup_help_box(); break;
00072 }
00073 hookup_callbacks();
00074 color f = foreground(); color b = background();
00075 set_foreground(f); set_background(b);
00076 worker::draw();
00077 root().apply(self());
00078 }
00079 }
00080
00081 void message_box::button_event(int but)
00082 {
00083 FUNCDEF("button_event");
00084 LOG(isprintf("message_box: button hit=%d", but));
00085 }
00086
00087 #ifdef __XWINDOWS__
00088
00089 void message_box::setup_proceed_box()
00090 {
00091 {
00092 argument_list wargs;
00093 wargs.add(XmNautoUnmanage, int(0));
00094 wargs.add(XmNokLabelString, window_string(system_string("Yes")));
00095 wargs.add(XmNcancelLabelString, window_string(system_string("No")));
00096 wargs.add(XmNhelpLabelString, window_string(system_string("Cancel")));
00097 wargs.add(XmNborderWidth, 2);
00098 system_string xmstr(_message);
00099 wargs.add(XmNmessageString, window_string(xmstr));
00100 self(XmCreateMessageBox
00101 (parent(), (char *)"Proceed?", wargs.generate(), wargs.number()));
00102 }
00103 }
00104
00105 void message_box::setup_information_box()
00106 {
00107 {
00108 argument_list wargs;
00109 wargs.add(XmNautoUnmanage, int(0));
00110 system_string xmstr(_message);
00111 wargs.add(XmNmessageString, window_string(xmstr));
00112 self(XmCreateMessageDialog
00113 (parent(), (char *)"Information", wargs.generate(), wargs.number()));
00114 XtUnmanageChild(XmMessageBoxGetChild(self(), XmDIALOG_CANCEL_BUTTON));
00115 XtUnmanageChild(XmMessageBoxGetChild(self(), XmDIALOG_HELP_BUTTON));
00116 }
00117 {
00118 window_handle label = XmMessageBoxGetChild(self(), XmDIALOG_MESSAGE_LABEL);
00119 argument_list wargs;
00120 wargs.add(XmNalignment, XtArgVal(XmALIGNMENT_BEGINNING));
00121 wargs.apply(label);
00122 }
00123 }
00124
00125 void message_box::setup_warning_box()
00126 {
00127 {
00128 argument_list wargs;
00129 wargs.add(XmNautoUnmanage, int(0));
00130 wargs.add(XmNokLabelString, window_string(system_string("Yes")));
00131 wargs.add(XmNhelpLabelString, window_string(system_string("Cancel")));
00132 system_string xmstr(_message);
00133 wargs.add(XmNmessageString, window_string(xmstr));
00134 self(XmCreateWarningDialog
00135 (parent(), (char *)"Warning!", wargs.generate(), wargs.number()));
00136 XtUnmanageChild(XmMessageBoxGetChild(self(), XmDIALOG_CANCEL_BUTTON));
00137 }
00138 {
00139 window_handle label = XmMessageBoxGetChild(self(), XmDIALOG_MESSAGE_LABEL);
00140 argument_list wargs;
00141 wargs.add(XmNalignment, XtArgVal(XmALIGNMENT_BEGINNING));
00142 wargs.apply(label);
00143 }
00144 }
00145
00146 void message_box::setup_help_box()
00147 {
00148 {
00149 argument_list wargs;
00150 wargs.add(XmNautoUnmanage, int(0));
00151 system_string xmstr(_message);
00152 wargs.add(XmNmessageString, window_string(xmstr));
00153 self(XmCreateMessageDialog
00154 (parent(), (char *)"Help Is Available", wargs.generate(), wargs.number()));
00155 }
00156 XtUnmanageChild(XmMessageBoxGetChild(self(), XmDIALOG_CANCEL_BUTTON));
00157 {
00158 window_handle label = XmMessageBoxGetChild(self(), XmDIALOG_MESSAGE_LABEL);
00159 argument_list wargs;
00160 wargs.add(XmNalignment, XtArgVal(XmALIGNMENT_BEGINNING));
00161 wargs.apply(label);
00162 }
00163 }
00164
00165 void message_box::message_box_callback(window_handle formal(w),
00166 message_box *the_box,
00167 XmAnyCallbackStruct *call_data)
00168 {
00169 switch (call_data->reason) {
00170 case XmCR_OK: the_box->last_hit = 0; break;
00171
00172 case XmCR_HELP: the_box->last_hit = 1; break;
00173 case XmCR_CANCEL: the_box->last_hit = 2; break;
00174 default:
00175 non_continuable_error("message_box", "message_box_callback",
00176 "unknown reason for callback");
00177 }
00178 switch (the_box->_kind) {
00179 case HELP:
00180 if (the_box->last_hit == 1) {
00181 the_box->last_hit = HELP_HELP;
00182 the_box->show_help();
00183 }
00184 break;
00185 case PROCEED:
00186 if (the_box->last_hit == 1) the_box->last_hit = PROCEED_CANCEL;
00187 else if (the_box->last_hit == 2) the_box->last_hit = PROCEED_NO;
00188 break;
00189 case INFORMATION:
00190 break;
00191 case WARNING:
00192 if (the_box->last_hit == 1) the_box->last_hit = WARNING_CANCEL;
00193 break;
00194 }
00195 the_box->button_event(the_box->last_hit);
00196 the_box->erase();
00197 }
00198
00199 void message_box::hookup_callbacks()
00200 {
00201 XtAddCallback
00202 (self(), XmNokCallback, XtCallbackProc(message_box_callback),
00203 XtPointer(this));
00204 XtAddCallback
00205 (self(), XmNcancelCallback, XtCallbackProc(message_box_callback),
00206 XtPointer(this));
00207 XtAddCallback
00208 (self(), XmNhelpCallback, XtCallbackProc(message_box_callback),
00209 XtPointer(this));
00210 }
00211
00212 void message_box::show_help()
00213 {
00214 {
00215 color f = foreground(); color b = background();
00216 if (extra_help_box) delete extra_help_box;
00217 extra_help_box = new message_box(root(), drawable::origin(),
00218 INFORMATION, _second_message.s(), (const char *)NIL, f, b);
00219 extra_help_box->draw();
00220 }
00221 }
00222
00223 #elif defined(OS_2)
00224 #elif defined(MS_WINDOWS)
00225 #endif
00226
00227
00228 #endif //MESSAGE_BOX_IMPLEMENTATION_FILE
00229