display/sbdmenu.h

Go to the documentation of this file.
00001 
00019 #ifndef SBDMENU_H
00020 #define SBDMENU_H
00021 
00022 #include "hosthplb.h"
00023 #include "elst.h"
00024 #include "strngs.h"
00025 #include "grphics.h"
00026 #include "varable.h"
00027 #include "rect.h"
00028 #include "points.h"
00029 #include          "notdll.h"
00030 
00042 extern INT_VAR_H (menu_char_width, 8, "Width of characters in menu text");
00043 extern INT_VAR_H (menu_char_height, 14, "Height characters in menu text");
00046 class MENU_L;                    //Forward Declaration
00047 ELISTIZEH(MENU_L); 
00048 
00049 class COMMAND_WINDOW;            //Fwd Decl #inc at end
00050 
00051 /* Forward declarations showing the inheritance tree of the MENU_NODE
00052   subclasses */
00053 
00054 class MENU_NODE;
00055 class LEAF_MENU_NODE;
00056 class SIMPLE_MENU_LEAF;
00057 class TOGGLE_MENU_LEAF;
00058 class RADIO_MENU_LEAF;
00059 class VARIABLE_MENU_LEAF;
00060 class NON_LEAF_MENU_NODE;
00061 class MENU_ROOT;
00062 class NON_RADIO_MENU;
00063 class RADIO_MENU;
00064 
00069 class MENU_NODE
00070 {
00071   friend class MENU_ROOT;
00072   friend class NON_LEAF_MENU_NODE;
00073   friend class LEAF_MENU_NODE;
00074   friend class RADIO_MENU;
00075   protected:
00076     STRING name;                 //Text of option
00077     BOX box;                     //Display area
00078 
00079     MENU_NODE(  //constructor
00080               const char *txt) {
00081       name = STRING (txt);
00082     }
00083 
00084     virtual void event (         //User clicked...
00085       COMMAND_WINDOW * cmd_win,  //For UI, update etc
00086       FCOORD pt,                 //here
00087       INT32 * cmd_event_id,      //Command selected
00088       char *new_value) = 0;      //Edited value
00089 
00090                                  //char width reqd
00091     virtual INT8 max_num_chars () = 0;
00092 
00093     virtual void plotx (         //draw it
00094       WINDOW window) = 0;        //in this window
00095 
00096                                  //build box
00097     virtual BOX &recalc_bounding_box(INT16 tl_x,   //top left x
00098                                      INT16 tl_y);  //top left y
00099 
00100   private:
00101     BOX &recalc_fixed_width_bb(               //build box
00102                                INT16 tl_x,    //top left x
00103                                INT16 tl_y,    //top left y
00104                                INT16 width);  //required width
00105 
00106   public:
00107                                  //return ptr to name
00108     virtual const char *cmp_str() { 
00109       return name.string ();
00110     }
00111 
00112     void plot(                 //draw it
00113               WINDOW window);  //in this window
00114 
00115     void new_label(  //replace name
00116                    const char *label) {
00117       name = label;
00118     }
00119 
00120     virtual void write_vars(          //save config vars
00121                             FILE *,   //in this file
00122                             BOOL8) {  //Changed vars only?
00123                                  //default do nothing
00124     }
00125 };
00126 
00131 class LEAF_MENU_NODE:public MENU_NODE
00132 {
00133   protected:
00134     LEAF_MENU_NODE (             //constructor
00135     const char *menu_text):MENU_NODE (menu_text) {
00136     }
00137 
00138     INT8 max_num_chars() {  //char width reqd
00139       return (INT8) name.length ();
00140     }
00141 
00142     virtual void plotx(                 //draw it
00143                        WINDOW window);  //in this window
00144 };
00145 
00150 class SIMPLE_MENU_LEAF:public LEAF_MENU_NODE
00151 {
00152   INT32 event_id;                //Return event code
00153 
00154   private:
00155     void event(                          //User clicked...
00156                COMMAND_WINDOW *cmd_win,  //For UI, update etc
00157                FCOORD pt,                //here
00158                INT32 *cmd_event_id,      //Command selected
00159                char *new_value);         //Edited value
00160 
00161   public:
00162     SIMPLE_MENU_LEAF (           //constructor
00163       const char *menu_text,
00164     INT32 code):LEAF_MENU_NODE (menu_text) {
00165       event_id = code;
00166     }
00167 };
00168 
00173 class TOGGLE_MENU_LEAF:public LEAF_MENU_NODE
00174 {
00175   friend class RADIO_MENU;
00176 
00177   INT32 event_id;                //Return event code
00178   BOOL8 state;                   //ON/OFF
00179 
00180   private:
00181     void event(                          //User clicked...
00182                COMMAND_WINDOW *cmd_win,  //For UI, update etc
00183                FCOORD pt,                //here
00184                INT32 *cmd_event_id,      //Command selected
00185                char *new_value);         //Edited value
00186 
00187     void plotx(                 //draw it
00188                WINDOW window);  //in this window
00189 
00190   public:
00191     TOGGLE_MENU_LEAF (           //constructor
00192       const char *menu_text,
00193       INT32 code,
00194     BOOL8 initial_state):LEAF_MENU_NODE (menu_text) {
00195       event_id = code;
00196       state = initial_state;
00197     }
00198 
00199     void set_toggle(  //Explicit override
00200                     BOOL8 value) {
00201       state = value;
00202     }
00203 };
00204 
00209 class RADIO_MENU_LEAF:public TOGGLE_MENU_LEAF
00210 {
00211   public:
00212     RADIO_MENU_LEAF (            //constructor
00213       const char *menu_text,
00214     INT32 code):TOGGLE_MENU_LEAF (menu_text, code, FALSE) {
00215     }
00216 };
00217 
00222 class VARIABLE_MENU_LEAF:public LEAF_MENU_NODE
00223 {
00224   INT32 event_id;                //Return event code
00225   STRING current_value;          //Variable value
00226 
00227   void event(                          //User clicked...
00228              COMMAND_WINDOW *cmd_win,  //For UI, update etc
00229              FCOORD pt,                //here
00230              INT32 *cmd_event_id,      //Command selected
00231              char *new_value);         //Edited value
00232 
00233   public:
00234     VARIABLE_MENU_LEAF (         //constructor
00235       const char *menu_text,
00236       INT32 code,
00237     const char *initial_value):LEAF_MENU_NODE (menu_text) {
00238       event_id = code;
00239       current_value = STRING (initial_value);
00240     }
00241 
00242     void replace_value(  //change current_value
00243                        const char *new_value) {
00244       current_value = new_value;
00245     }
00246 };
00247 
00252 class NON_LEAF_MENU_NODE:public MENU_NODE
00253 {
00254   public:
00255     void clear_children() { 
00256       menu_list.clear ();
00257     };
00258 
00259   protected:
00260     MENU_L_LIST menu_list;
00261 
00262     NON_LEAF_MENU_NODE (         //constructor
00263     const char *menu_text):MENU_NODE (menu_text) {
00264     }
00265 
00266     void link_child(                        //add to sub-menu end
00267                     MENU_NODE *new_child);  //item to add
00268 
00269     void link_child_link(                     //add to sub-menu end
00270                          MENU_L *new_child);  //item to add
00271 
00272     virtual void event(                          //User clicked...
00273                        COMMAND_WINDOW *cmd_win,  //For UI, update etc
00274                        FCOORD pt,                //here
00275                        INT32 *cmd_event_id,      //Command selected
00276                        char *new_value);         //Edited value
00277 
00278     INT8 max_num_chars();  //char width reqd
00279 
00280     virtual void plotx(                 //draw it
00281                        WINDOW window);  //in this window
00282 
00283                                  //build box
00284     virtual BOX &recalc_bounding_box(INT16 tl_x,   //top left x
00285                                      INT16 tl_y);  //top left y
00286 
00287 };
00288 
00293 class MENU_ROOT:public NON_LEAF_MENU_NODE
00294 {
00295   private:
00296     void plotx(                 //draw it
00297                WINDOW window);  //in this window
00298 
00299   public:
00300     MENU_ROOT ():NON_LEAF_MENU_NODE ("") {
00301     }
00302     //cnstrctr
00303 
00304     void add_child(  //add to sub-menu end //item to add
00305                    NON_LEAF_MENU_NODE *new_child) {
00306       link_child(new_child); 
00307     }
00308 
00309     /* Public defn of event - at menu_root only*/
00310     void event(                          //User clicked...
00311                COMMAND_WINDOW *cmd_win,  //For UI, update etc
00312                FCOORD pt,                //here
00313                INT32 *cmd_event_id,      //Command selected
00314                char *new_value) {        //Edited value
00315       NON_LEAF_MENU_NODE::event(cmd_win, pt, cmd_event_id, new_value); 
00316     }
00317 
00318     BOX &recalc_bounding_box(              //build box
00319                              INT16 tl_x,   //top left x
00320                              INT16 tl_y);  //top left y
00321 
00322     /* Public defn of write_vars - at menu_root only*/
00323     void write_vars(                      //save config vars
00324                     FILE *fp,             //in this file
00325                     BOOL8 changes_only);  //Changed vars only?
00326 };
00327 
00332 class NON_RADIO_MENU:public NON_LEAF_MENU_NODE
00333 {
00334   public:
00335     NON_RADIO_MENU (             //constructor
00336     const char *menu_text):NON_LEAF_MENU_NODE (menu_text) {
00337     }
00338 
00339     void add_child(  //add to sub-menu end //item to add
00340                    SIMPLE_MENU_LEAF *new_child) {
00341       link_child(new_child); 
00342     }
00343 
00344     void add_child(  //add to sub-menu end //item to add
00345                    TOGGLE_MENU_LEAF *new_child) {
00346       link_child(new_child); 
00347     }
00348 
00349     void add_child(  //add to sub-menu end //item to add
00350                    VARIABLE_MENU_LEAF *new_child) {
00351       link_child(new_child); 
00352     }
00353 
00354 };
00355 
00360 class RADIO_MENU:public NON_LEAF_MENU_NODE
00361 {
00362   private:
00363     RADIO_MENU_LEAF * on_button; //which one is on?
00364 
00365     void event(                          //User clicked...
00366                COMMAND_WINDOW *cmd_win,  //For UI, update etc
00367                FCOORD pt,                //here
00368                INT32 *cmd_event_id,      //Command selected
00369                char *new_value);         //Edited value
00370 
00371   public:
00372     RADIO_MENU (                 //constructor
00373     const char *menu_text):NON_LEAF_MENU_NODE (menu_text) {
00374     }
00375 
00376     void add_child(                              //add to sub-menu end
00377                    RADIO_MENU_LEAF *new_child);  //item to add
00378 
00379     void press_radio_button(                           //Change selected butn
00380                             RADIO_MENU_LEAF *button);  //to this one
00381 };
00382 
00387 class MENU_L:public ELIST_LINK
00388 {
00389   public:
00390     MENU_NODE * ptr;             //Generic menu item
00391 
00392     MENU_L() { 
00393     }                            //copy list constrctr
00394 
00395     MENU_L(  //normal constructor
00396            MENU_NODE *p) {
00397       ptr = p;
00398     }
00399 };
00400 
00401 #include "cmndwin.h"
00402 #include          "notdll.h"
00403 #endif

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