00001
00020 #include "mfcpch.h"
00021 #include <ctype.h>
00022 #include "evnts.h"
00023 #include "cmndwin.h"
00024
00025 #define BACKSPACE_KEY '\010'
00026 #define RETURN_KEY '\015'
00027
00028 #define BORDER_HEIGHT (menu_char_height / 2)
00029
00030 #define MSG_AREA_TOP_LEFT_X 0
00031 #define MSG_AREA_TOP_LEFT_Y 0
00032 #define MSG_AREA_HEIGHT (int)(menu_char_height * 1.5 )
00033 #define MSG_TEXT_START_X (menu_char_height / 2)
00034 #define MSG_TEXT_START_Y (MSG_AREA_TOP_LEFT_Y - menu_char_height)
00035
00036 #define PROMPT_AREA_TOP_LEFT_X 0
00037 #define PROMPT_AREA_TOP_LEFT_Y \
00038 (MSG_AREA_TOP_LEFT_Y - MSG_AREA_HEIGHT - BORDER_HEIGHT)
00039 #define PROMPT_AREA_HEIGHT MSG_AREA_HEIGHT
00040 #define PROMPT_TEXT_START_X (menu_char_height / 2)
00041 #define PROMPT_TEXT_START_Y (PROMPT_AREA_TOP_LEFT_Y - menu_char_height)
00042
00043 #define MENU_AREA_TOP_LEFT_X 0
00044 #define MENU_AREA_TOP_LEFT_Y \
00045 (PROMPT_AREA_TOP_LEFT_Y - PROMPT_AREA_HEIGHT - BORDER_HEIGHT)
00046
00047 #define MIN_WINDOW_WIDTH (PROMPT_TEXT_START_X + 80 * menu_char_width)
00048
00049 #define EXTERN
00050
00053 EXTERN INT_VAR (editor_cmdwin_width, 950, "CmdWin max non scrollable width");
00054 EXTERN INT_VAR (editor_cmdwin_height, 550,
00055 "CmdWin max non scrollable height");
00056 EXTERN INT_VAR (editor_cmdwin_xpos1, 20, "X pos of first command window");
00057 EXTERN INT_VAR (editor_cmdwin_ypos1, 20, "Y pos of first command window");
00058 EXTERN INT_VAR (editor_cmdwin_xoffset, 30, "X offset between command windws");
00059 EXTERN INT_VAR (editor_cmdwin_yoffset, 30, "Y offset between command windws");
00062 INT16
00063 COMMAND_WINDOW::next_win_x_pos = 0;
00064 INT16
00065 COMMAND_WINDOW::next_win_y_pos = 0;
00066
00070 COMMAND_WINDOW::COMMAND_WINDOW(const char *name,
00071 MENU_ROOT *menu_ptr
00072 ) {
00073 BOX menu_box;
00074 INT16 window_height;
00075 INT8 window_type = FULLSIZEWIN;
00076 INT16 xsize;
00077 INT16 ysize;
00078
00079 message_str[0] = '\0';
00080 prompt_str[0] = '\0';
00081 strcpy(win_name, name);
00082
00083 menu_root = menu_ptr;
00084 menu_box = menu_root->recalc_bounding_box (MENU_AREA_TOP_LEFT_X,
00085 MENU_AREA_TOP_LEFT_Y);
00086
00087 if (menu_box.width () > MIN_WINDOW_WIDTH) {
00088 window_width = menu_box.width ();
00089 }
00090 else {
00091 window_width = MIN_WINDOW_WIDTH;
00092 }
00093
00094 window_height = MSG_AREA_TOP_LEFT_Y - menu_box.bottom ();
00095
00096 xsize = window_width;
00097 ysize = window_height;
00098
00099 if (window_width > editor_cmdwin_width) {
00100 window_type = SCROLLINGWIN;
00101 xsize = editor_cmdwin_width;
00102 }
00103
00104 if (window_height > editor_cmdwin_height) {
00105 window_type = SCROLLINGWIN;
00106 ysize = editor_cmdwin_height;
00107 }
00108
00109 if ((next_win_x_pos == 0) && (next_win_x_pos == 0)) {
00110
00111 next_win_x_pos = editor_cmdwin_xpos1;
00112 next_win_y_pos = editor_cmdwin_ypos1;
00113 }
00114 x_pos = next_win_x_pos;
00115 y_pos = next_win_y_pos;
00116
00117
00118 fd = create_window (name, window_type, x_pos, y_pos, xsize, ysize, MSG_AREA_TOP_LEFT_X,
00119 window_width,
00120 menu_box.bottom (),
00121 MSG_AREA_TOP_LEFT_Y,
00122 TRUE,
00123 FALSE, FALSE, TRUE);
00124
00125 vdc_extent (fd, 0, 0, xsize, ysize);
00126 next_win_x_pos += editor_cmdwin_xoffset;
00127 next_win_y_pos += editor_cmdwin_yoffset;
00128
00129 plot();
00130 }
00131
00132
00136 void COMMAND_WINDOW::event(
00137 GRAPHICS_EVENT &g_event,
00138 INT32 *cmd_event,
00139 char *new_value
00140 ) {
00141 message_str[0] = '\0';
00142 prompt_str[0] = '\0';
00143 *cmd_event = UNIDENTIFIED_COMMAND;
00144 new_value[0] = '\0';
00145
00146 switch (g_event.type) {
00147 case DOWN_EVENT:
00148 {
00149 menu_root->event (this, FCOORD (g_event.x, g_event.y),
00150 cmd_event, new_value);
00151 if (*cmd_event == UNIDENTIFIED_COMMAND)
00152 *cmd_event = NULL_COMMAND;
00153 break;
00154 }
00155 case KEYPRESS_EVENT:
00156 {
00157 if (g_event.key == 3) {
00158 exit (0);
00159 }
00160 }
00161 default:
00162 {
00163
00164
00165 *cmd_event = NULL_COMMAND;
00166 break;
00167 }
00168 }
00169 plot();
00170 }
00171
00172
00176 void COMMAND_WINDOW::msg(
00177 const char *msg_str
00178 ) {
00179 strcpy(message_str, msg_str);
00180 plot_msg_area();
00181 overlap_picture_ops(TRUE);
00182 }
00183
00184
00188 void COMMAND_WINDOW::plot() {
00189 clear_view_surface(fd);
00190 text_font_index (fd, 1);
00191 character_height(fd, menu_char_height);
00192
00193 plot_msg_area();
00194 plot_prompt_area();
00195
00196 menu_root->plot (fd);
00197 }
00198
00199
00205 void COMMAND_WINDOW::plot_msg_area() {
00206 fill_color_index(fd, DARK_SLATE_BLUE);
00207 interior_style(fd, INT_SOLID, FALSE);
00208
00209 rectangle (fd,
00210 MSG_AREA_TOP_LEFT_X, MSG_AREA_TOP_LEFT_Y,
00211 MSG_AREA_TOP_LEFT_X + window_width - 1,
00212 MSG_AREA_TOP_LEFT_Y - MSG_AREA_HEIGHT);
00213
00214 text_color_index(fd, WHITE);
00215 text2d (fd, MSG_TEXT_START_X, MSG_TEXT_START_Y, message_str, 0, FALSE);
00216 }
00217
00218
00224 void COMMAND_WINDOW::plot_prompt_area() {
00225 INT8 i;
00226 INT8 prompt_len;
00227 char char_str[2];
00228
00229 fill_color_index(fd, DARK_SLATE_BLUE);
00230 interior_style(fd, INT_SOLID, FALSE);
00231
00232 rectangle (fd,
00233 PROMPT_AREA_TOP_LEFT_X, PROMPT_AREA_TOP_LEFT_Y,
00234 PROMPT_AREA_TOP_LEFT_X + window_width - 1,
00235 PROMPT_AREA_TOP_LEFT_Y - MSG_AREA_HEIGHT);
00236
00237 text_color_index(fd, WHITE);
00238 prompt_len = strlen (prompt_str);
00239 char_str[1] = '\0';
00240
00241 for (i = 0; i < prompt_len; i++) {
00242 char_str[0] = prompt_str[i];
00243 text2d (fd,
00244 PROMPT_TEXT_START_X + (i * menu_char_width),
00245 PROMPT_TEXT_START_Y, char_str, 0, FALSE);
00246 }
00247 }
00248
00249
00253 BOOL8 COMMAND_WINDOW::internal_prompt(
00254 const char *msg_str,
00255 char *response_str
00256 ) {
00257 GRAPHICS_EVENT event;
00258 INT8 pos;
00259 BOOL8 ok = TRUE;
00260
00261 strcpy(message_str, msg_str);
00262 strcpy(prompt_str, response_str);
00263 plot_msg_area();
00264 plot_prompt_area();
00265 overlap_picture_ops(TRUE);
00266
00267
00268
00269 event.key = '\0';
00270
00271 while (event.key != RETURN_KEY) {
00272 await_event(fd,
00273 TRUE,
00274 ANY_EVENT,
00275 &event);
00276
00277 if (event.type != KEYPRESS_EVENT) {
00278 ok = FALSE;
00279 response_str[0] = '\0';
00280 break;
00281 }
00282
00283 pos = strlen (response_str);
00284 if (isprint (event.key) && pos < MAX_CHARS) {
00285 response_str[pos] = event.key;
00286 response_str[pos + 1] = '\0';
00287 text2d (fd,
00288 PROMPT_TEXT_START_X + (pos * menu_char_width),
00289 PROMPT_TEXT_START_Y, response_str + pos, 0, FALSE);
00290 }
00291 else {
00292 switch (event.key) {
00293 case BACKSPACE_KEY:
00294 if (pos > 0) {
00295 response_str[pos - 1] = '\0';
00296 fill_color_index(fd, DARK_SLATE_BLUE);
00297 interior_style(fd, INT_SOLID, FALSE);
00298
00299 rectangle (fd,
00300 PROMPT_TEXT_START_X + (pos -
00301 1) * menu_char_width,
00302 PROMPT_AREA_TOP_LEFT_Y,
00303 PROMPT_AREA_TOP_LEFT_X + window_width - 1,
00304 PROMPT_AREA_TOP_LEFT_Y - PROMPT_AREA_HEIGHT);
00305 }
00306 break;
00307 case RETURN_KEY:
00308 break;
00309 default:
00310 sprintf (message_str, "NON PRINTING CHAR: %o", event.key);
00311 plot_msg_area();
00312 }
00313 }
00314 overlap_picture_ops(TRUE);
00315 }
00316 message_str[0] = '\0';
00317 prompt_str[0] = '\0';
00318 #ifdef __UNIX__
00319
00320 #endif
00321 return ok;
00322 }
00323
00324
00328 void COMMAND_WINDOW::press_radio_button(
00329 RADIO_MENU *radio_sub_menu_item,
00330 RADIO_MENU_LEAF *button_menu_item) {
00331 radio_sub_menu_item->press_radio_button (button_menu_item);
00332 plot();
00333 }
00334
00335
00343 void COMMAND_WINDOW::update_menu_tree() {
00344 BOX menu_box;
00345 INT16 window_height;
00346 INT8 window_type = FULLSIZEWIN;
00347 INT16 xsize;
00348 INT16 ysize;
00349
00350 menu_box = menu_root->recalc_bounding_box (MENU_AREA_TOP_LEFT_X,
00351 MENU_AREA_TOP_LEFT_Y);
00352 if (menu_box.width () > MIN_WINDOW_WIDTH) {
00353 window_width = menu_box.width ();
00354 }
00355 else {
00356 window_width = MIN_WINDOW_WIDTH;
00357 }
00358
00359 window_height = MSG_AREA_TOP_LEFT_Y - menu_box.bottom ();
00360
00361 xsize = window_width;
00362 ysize = window_height;
00363
00364 if (window_width > editor_cmdwin_width) {
00365 window_type = SCROLLINGWIN;
00366 xsize = editor_cmdwin_width;
00367 }
00368
00369 if (window_height > editor_cmdwin_height) {
00370 window_type = SCROLLINGWIN;
00371 ysize = editor_cmdwin_height;
00372 }
00373 destroy_window(fd);
00374
00375 fd = create_window (win_name, window_type, x_pos, y_pos,
00376 xsize, ysize, MSG_AREA_TOP_LEFT_X,
00377 window_width,
00378 menu_box.bottom (),
00379 MSG_AREA_TOP_LEFT_Y,
00380 TRUE,
00381 FALSE, FALSE, TRUE);
00382
00383 vdc_extent (fd, 0, 0, xsize, ysize);
00384 plot();
00385 }
00386
00387
00391 BOOL8 COMMAND_WINDOW::prompt(
00392 const char *msg_str,
00393 char *response_str
00394 ) {
00395 BOOL8 ok;
00396
00397 ok = internal_prompt (msg_str, response_str);
00398 plot();
00399 return ok;
00400 }
00401
00402
00406 void COMMAND_WINDOW::replace_menu_text(
00407 LEAF_MENU_NODE *menu_item,
00408 const char *new_label
00409 ) {
00410 menu_item->new_label (new_label);
00411 menu_item->plot (fd);
00412 }
00413
00414
00418 void COMMAND_WINDOW::set_toggle(
00419 TOGGLE_MENU_LEAF *menu_item,
00420 BOOL8 new_value) {
00421 menu_item->set_toggle (new_value);
00422 menu_item->plot (fd);
00423 }