00001
00020 #include "mfcpch.h"
00021 #include "sbdmenu.h"
00022
00023 #define MENU_COLUMN_SPACING (menu_char_height / 2)
00024 #define MENU_ITEM_HEIGHT (int)(menu_char_height * 1.5)
00025 #define MENU_SEPARATOR_HEIGHT MENU_COLUMN_SPACING
00026 #define MENU_TEXT_X_OFFSET (menu_char_height / 2)
00027 #define MENU_TEXT_Y_OFFSET menu_char_height/2
00028
00029 #include "notdll.h"
00030 ELISTIZE(MENU_L);
00031
00032 const ERRCODE NOT_SUBMENU_NODE = "Button is not leaf of radio submenu";
00033 const ERRCODE SHOULDNT_BE_CALLED = "Should never get to here!!";
00034
00037 INT_VAR (menu_char_width, 8, "Width of characters in menu text");
00038 INT_VAR (menu_char_height, 14, "Height characters in menu text");
00041
00042
00043
00044
00045
00046
00047
00048
00052 void LEAF_MENU_NODE::plotx(
00053 WINDOW window
00054 ) {
00055 box.plot (window);
00056
00057 text2d (window,
00058 box.left () + MENU_TEXT_X_OFFSET,
00059 box.top () - MENU_TEXT_Y_OFFSET, name.string (), 0, FALSE);
00060 }
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00079 void MENU_NODE::plot(
00080 WINDOW window
00081 ) {
00082 character_height(window, menu_char_height);
00083 interior_style(window, INT_SOLID, TRUE);
00084 perimeter_color_index(window, LIGHT_GREY);
00085 text_color_index(window, WHITE);
00086 fill_color_index(window, GREY);
00087 plotx(window);
00088 }
00089
00090
00099 BOX &MENU_NODE::recalc_bounding_box(
00100 INT16,
00101 INT16
00102 ) {
00103 SHOULDNT_BE_CALLED.error ("MENU_ROOT::recalc_bounding_box", ABORT, NULL);
00104 return box;
00105 }
00106
00107
00112 BOX &MENU_NODE::recalc_fixed_width_bb(
00113 INT16 tl_x,
00114 INT16 tl_y,
00115 INT16 width
00116 ) {
00117 box = BOX (ICOORD (tl_x, tl_y - MENU_ITEM_HEIGHT),
00118 ICOORD (tl_x + width, tl_y));
00119 return box;
00120 }
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00136 void MENU_ROOT::plotx(
00137 WINDOW window
00138 ) {
00139 MENU_L_IT it(&menu_list);
00140
00141 for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
00142 it.data ()->ptr->plotx (window);
00143 }
00144
00145
00150 BOX &MENU_ROOT::recalc_bounding_box(
00151 INT16 tl_x,
00152 INT16 tl_y
00153 ) {
00154 MENU_L_IT it(&menu_list);
00155
00156 box = BOX (ICOORD (tl_x, tl_y), ICOORD (tl_x, tl_y));
00157
00158 for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
00159 box += it.data ()->ptr->recalc_bounding_box (box.right (), box.top ());
00160 box.move_right_edge (MENU_COLUMN_SPACING);
00161 }
00162 box.move_right_edge (-MENU_COLUMN_SPACING);
00163 return box;
00164 }
00165
00166
00170 void MENU_ROOT::write_vars(
00171 FILE *fp,
00172 BOOL8 changes_only
00173 ) {
00174 MENU_L_IT it(&menu_list);
00175
00176 for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
00177 it.data ()->ptr->write_vars (fp, changes_only);
00178 }
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00192 void NON_LEAF_MENU_NODE::link_child(
00193 MENU_NODE *new_child) {
00194 MENU_L_IT it(&menu_list);
00195
00196 it.add_to_end (new MENU_L (new_child));
00197 }
00198
00199
00203 void NON_LEAF_MENU_NODE::link_child_link(
00204 MENU_L *new_child) {
00205 MENU_L_IT it(&menu_list);
00206
00207 it.add_to_end (new_child);
00208 }
00209
00210
00214 void NON_LEAF_MENU_NODE::event(
00215 COMMAND_WINDOW *cmd_win,
00216 FCOORD pt,
00217 INT32 *cmd_event_id,
00218 char *new_value
00219 ) {
00220 MENU_L_IT it(&menu_list);
00221
00222 if (box.contains (pt))
00223 for (it.mark_cycle_pt ();
00224 (*cmd_event_id == UNIDENTIFIED_COMMAND) && !it.cycled_list ();
00225 it.forward ())
00226 it.data ()->ptr->event (cmd_win, pt, cmd_event_id, new_value);
00227 }
00228
00229
00233 INT8 NON_LEAF_MENU_NODE::max_num_chars() {
00234 MENU_L_IT it(&menu_list);
00235 INT8 max_so_far = 0;
00236 INT8 current_char_count = 0;
00237
00238 max_so_far = name.length ();
00239 for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
00240 current_char_count = it.data ()->ptr->max_num_chars ();
00241 if (current_char_count > max_so_far)
00242 max_so_far = current_char_count;
00243 }
00244 return max_so_far;
00245 }
00246
00247
00253 void NON_LEAF_MENU_NODE::plotx(
00254 WINDOW window
00255 ) {
00256 MENU_L_IT it(&menu_list);
00257
00258 box.plot (window);
00259 text2d (window,
00260 box.left () + MENU_TEXT_X_OFFSET,
00261 box.top () - MENU_TEXT_Y_OFFSET, name.string (), 0, FALSE);
00262
00263 move2d (window,
00264 box.left (),
00265 box.top () - MENU_ITEM_HEIGHT - MENU_SEPARATOR_HEIGHT / 2);
00266 draw2d (window,
00267 box.right (),
00268 box.top () - MENU_ITEM_HEIGHT - MENU_SEPARATOR_HEIGHT / 2);
00269
00270 for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ())
00271 it.data ()->ptr->plotx (window);
00272 }
00273
00274
00279 BOX &NON_LEAF_MENU_NODE::recalc_bounding_box(
00280 INT16 tl_x,
00281 INT16 tl_y
00282 ) {
00283 MENU_L_IT it(&menu_list);
00284 INT16
00285 menu_width = max_num_chars () * menu_char_width + 2 * MENU_TEXT_X_OFFSET;
00286
00287 box = BOX (ICOORD (tl_x, tl_y - MENU_ITEM_HEIGHT - MENU_SEPARATOR_HEIGHT),
00288 ICOORD (tl_x + menu_width, tl_y));
00289
00290 for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
00291 box += it.data ()->ptr->recalc_fixed_width_bb (box.left (),
00292 box.bottom (),
00293 box.width ());
00294 }
00295 return box;
00296 }
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00310 void RADIO_MENU::add_child(
00311 RADIO_MENU_LEAF *new_child) {
00312 if (menu_list.empty ()) {
00313 on_button = new_child;
00314 new_child->state = TRUE;
00315 }
00316 link_child(new_child);
00317 }
00318
00319
00323 void RADIO_MENU::event(
00324 COMMAND_WINDOW *cmd_win,
00325 FCOORD pt,
00326 INT32 *cmd_event_id,
00327 char *new_value
00328 ) {
00329 MENU_L_IT it(&menu_list);
00330
00331 if (box.contains (pt)) {
00332 if (!on_button->box.contains (pt)) {
00333 for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
00334 it.data ()->ptr->event (cmd_win, pt, cmd_event_id, new_value);
00335 if (*cmd_event_id != UNIDENTIFIED_COMMAND) {
00336 on_button->state = FALSE;
00337 on_button = (RADIO_MENU_LEAF *) it.data ()->ptr;
00338 break;
00339 }
00340 }
00341 }
00342 }
00343 }
00344
00345
00349 void RADIO_MENU::press_radio_button(
00350 RADIO_MENU_LEAF *button
00351 ) {
00352 MENU_L_IT it(&menu_list);
00353
00354 if (button != on_button) {
00355 for (it.mark_cycle_pt (); !it.cycled_list (); it.forward ()) {
00356 if (it.data ()->ptr == button)
00357 break;
00358 }
00359
00360 if (it.cycled_list ())
00361 NOT_SUBMENU_NODE.error ("MENU::press_radio_button", ABORT, NULL);
00362
00363 on_button->state = FALSE;
00364 button->state = TRUE;
00365 on_button = button;
00366 }
00367 }
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00381 void SIMPLE_MENU_LEAF::event(
00382 COMMAND_WINDOW *,
00383 FCOORD pt,
00384 INT32 *cmd_event_id,
00385 char *new_value
00386 ) {
00387 if (box.contains (pt)) {
00388 *cmd_event_id = event_id;
00389 new_value[0] = '\0';
00390 }
00391 }
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00405 void TOGGLE_MENU_LEAF::event(
00406 COMMAND_WINDOW *,
00407 FCOORD pt,
00408 INT32 *cmd_event_id,
00409 char *new_value
00410 ) {
00411 if (box.contains (pt)) {
00412 state = !state;
00413 *cmd_event_id = event_id;
00414 strcpy (new_value, state ? "T" : "F");
00415 }
00416 }
00417
00418
00424 void TOGGLE_MENU_LEAF::plotx(
00425 WINDOW window
00426 ) {
00427 if (state) {
00428 text_color_index(window, BLACK);
00429 fill_color_index(window, WHITE);
00430 }
00431 else {
00432 text_color_index(window, WHITE);
00433 fill_color_index(window, GREY);
00434 }
00435
00436 LEAF_MENU_NODE::plotx(window);
00437
00438 text_color_index(window, WHITE);
00439 fill_color_index(window, GREY);
00440 }
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00454 void VARIABLE_MENU_LEAF::event(
00455 COMMAND_WINDOW *cmd_win,
00456 FCOORD pt,
00457 INT32 *cmd_event_id,
00458 char *new_value
00459 ) {
00460 char prompt_msg[MAX_CHARS + 1];
00461
00462 if (box.contains (pt)) {
00463 strcpy (new_value, current_value.string ());
00464 sprintf (prompt_msg, "New value for " "%s" "?", name.string ());
00465 if (cmd_win->internal_prompt (prompt_msg, new_value)) {
00466 current_value = new_value;
00467 *cmd_event_id = event_id;
00468 }
00469 else
00470 *cmd_event_id = NULL_COMMAND;
00471 }
00472 }