display/sbdmenu.cpp

Go to the documentation of this file.
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  *       LEAF_MENU_NODE     MEMBER FUNCTIONS
00045  *
00046  ***********************************************************************
00047  ==================== */
00048 
00052 void LEAF_MENU_NODE::plotx(               //draw it
00053                            WINDOW window  //in this 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  *       MENU_NODE     MEMBER FUNCTIONS
00067  *
00068  ***********************************************************************
00069  ==================== */
00070 
00079 void MENU_NODE::plot(               //draw it
00080                      WINDOW window  //window to draw in
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(        // calculate size
00100                                     INT16,  // start topleft x
00101                                     INT16   // start topleft y
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(             // calc BB
00113                                       INT16 tl_x,  // start topleft x
00114                                       INT16 tl_y,  // start topleft y
00115                                       INT16 width  // 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  *       MENU_ROOT     MEMBER FUNCTIONS
00127  *
00128  ***********************************************************************
00129  ==================== */
00130 
00136 void MENU_ROOT::plotx(               //draw it
00137                       WINDOW window  //in this 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(             // calculate size
00151                                     INT16 tl_x,  // start topleft x
00152                                     INT16 tl_y   // start topleft 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(                    //save config vars
00171                            FILE *fp,           //in this file
00172                            BOOL8 changes_only  //Changed vars 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  *       NON_LEAF_MENU_NODE     MEMBER FUNCTIONS
00185  *
00186  ***********************************************************************
00187  ==================== */
00188 
00192 void NON_LEAF_MENU_NODE::link_child(  //add to menu end
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(  //add to menu
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(                          //User clicked...
00215                                COMMAND_WINDOW *cmd_win,  //For UI, update etc
00216                                FCOORD pt,                //here
00217                                INT32 *cmd_event_id,      //Command selected
00218                                char *new_value           //Edited 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() {  //calc char width
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(               //draw it
00254                                WINDOW window  //in this 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(             // calc BB
00280                                              INT16 tl_x,  // start topleft x
00281                                              INT16 tl_y   // start topleft 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  *       RADIO_MENU     MEMBER FUNCTIONS
00303  *
00304  ***********************************************************************
00305  ==================== */
00306 
00310 void RADIO_MENU::add_child(                               //Add button
00311                            RADIO_MENU_LEAF *new_child) {  //item to add
00312   if (menu_list.empty ()) {      //Init 1st choice ON
00313     on_button = new_child;
00314     new_child->state = TRUE;
00315   }
00316   link_child(new_child); 
00317 }
00318 
00319 
00323 void RADIO_MENU::event(                          //User clicked...
00324                        COMMAND_WINDOW *cmd_win,  //For UI, update etc
00325                        FCOORD pt,                //here
00326                        INT32 *cmd_event_id,      //Command selected
00327                        char *new_value           //Edited 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(                         //Chnge selctd butn
00350                                     RADIO_MENU_LEAF *button  //to this one
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 ())       //couldnt find it
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  *       SIMPLE_MENU_LEAF     MEMBER FUNCTIONS
00374  *
00375  ***********************************************************************
00376  ==================== */
00377 
00381 void SIMPLE_MENU_LEAF::event(                      //User clicked...
00382                              COMMAND_WINDOW *,     //For UI, update etc
00383                              FCOORD pt,            //here
00384                              INT32 *cmd_event_id,  //Command selected
00385                              char *new_value       //Edited 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  *       TOGGLE_MENU_LEAF     MEMBER FUNCTIONS
00398  *
00399  ***********************************************************************
00400  ==================== */
00401 
00405 void TOGGLE_MENU_LEAF::event(                      //User clicked...
00406                              COMMAND_WINDOW *,     //For UI, update etc
00407                              FCOORD pt,            //here
00408                              INT32 *cmd_event_id,  //Command selected
00409                              char *new_value       //Edited 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(               //draw it
00425                              WINDOW window  //in this 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  *       VARIABLE_MENU_LEAF     MEMBER FUNCTIONS
00447  *
00448  ***********************************************************************
00449  ==================== */
00450 
00454 void VARIABLE_MENU_LEAF::event(                          //User clicked...
00455                                COMMAND_WINDOW *cmd_win,  //For UI, update etc
00456                                FCOORD pt,                //here
00457                                INT32 *cmd_event_id,      //Command selected
00458                                char *new_value           //Edited 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 }

Generated on Wed Feb 28 19:49:11 2007 for Tesseract by  doxygen 1.5.1