Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

NDK_XX::MenuBar Class Reference

#include <ndk++.h>

Inheritance diagram for NDK_XX::MenuBar:

NDK_XX::ListBox NDK_XX::Control NDK_XX::FramedMenuBar NDK_XX::SubMenu List of all members.

Public Methods

 MenuBar (int id, const string &title,int lines, int cols, int y, int x,char orient='h',int style=hidden|tabstop|notify)
 ~MenuBar ()
char get_orientation () const
 we are wide-oriented or tall-oriented?

int execute ()
int add_item (MenuItemData *new_item)
int add_item (const string &text)
void items_owner (bool t_or_f=true)

Public Attributes

bool is_main_menu

Protected Methods

int move_up ()
int move_down ()
int move_left ()
int move_right ()
int driver (int key)
int execute_current_item (int key)
void find_clicked ()
 mouse support

int get_next_item_y ()
 Calculate the position of the next item to be inserted.

int get_next_item_x ()

Protected Attributes

bool b_own_items
char orientation
 Should we delete the added items?

string titlePos

Constructor & Destructor Documentation

NDK_XX::MenuBar::MenuBar int    id,
const string &    title,
int    lines,
int    cols,
int    y,
int    x,
char    orient = 'h',
int    style = hidden|tabstop|notify
[inline]
 

MenuBar Constructor

Parameters:
orient  (default: h) this menu bar will deploy h (horizontally) or v (vertically)
other params: See parameters for class Control

Definition at line 1364 of file ndk++.h.

References NDK_XX::Control::framed, NDK_XX::Control::notify, NDK_XX::Control::tabstop, and NDK_XX::Control::title.

01366         :  MenuBar (id,title,lines+2,cols,y,x,orient,style)
01367     {
01368     }
01369 };
01370 
01371 
01372 /************************************************************************

NDK_XX::MenuBar::~MenuBar   [inline]
 

Definition at line 1374 of file ndk++.h.

01376               : public MenuBar
01377 {
01378 public:


Member Function Documentation

int NDK_XX::MenuBar::add_item const string &    text [inline]
 

If we get only a text, then the assumed intention is to place a placeholder (i.e. a non implemented yet label

Definition at line 1403 of file ndk++.h.

References orientation.

int NDK_XX::MenuBar::add_item MenuItemData   new_item [inline]
 

specialized add_item: a MenuBar, as oposed to a ListBox adds the visible item at the same time as the data item (implicit to this is that you should not add more data items than the visible ones. This limitation is which allows us to deploy the items each one at its own position. (By now, anyway. Later we may add the ability to scroll items, but it's unlikely we will ever want to...)

Definition at line 1391 of file ndk++.h.

References orientation.

Referenced by NDK_XX::PopUpMenu::action().

01392                  {
01393         if(orientation=='h')
01394             return true;
01395         return MenuBar::move_up();
01396     };  
01397     int move_down(){
01398         if(orientation=='h')
01399             return true;

int NDK_XX::MenuBar::driver int    key [protected, virtual]
 

get a chance at processing the key, before parent does

Reimplemented from NDK_XX::ListBox.

Definition at line 1650 of file ndk++.cc.

References NDK_XX::DialogBox::do_modal(), execute_current_item(), EXIT_APP, find_clicked(), NDK_XX::Control::get_param(), IDYES, KEY_ENTER, KEY_ESC, and NDK_XX::ListBox::refresh().

Referenced by execute().

01651 {
01652     int result = false;
01653     switch(key) {
01654         case EXIT_APP:
01655         {
01656             string prompt(get_param("exit app","prompt","Esta seguro que quiere salir de la aplicacion?"));
01657             YesNoBox mb(Application::get_application()->get_title(),prompt);
01658             int req =mb.do_modal();
01659             refresh();
01660             if(req==IDYES){
01661                 result=true;
01662             }
01663             break;
01664         }
01665         case KEY_ESC:
01666             if(is_main_menu) ///in this case, KEY_ESC is like EXIT_APP
01667                 result = driver(EXIT_APP);
01668             else result =true;
01669             break;
01670         case KEY_ENTER:
01671             result = execute_current_item(key);
01672                     switch(result) {
01673                         case EXIT_APP:
01674                         case KEY_ESC:
01675                         case KEY_LEFT:
01676                         case KEY_RIGHT:
01677                             return driver(result);
01678                         default:
01679                             break;
01680                     }
01681             break;
01682 #ifdef NCURSES_MOUSE_VERSION
01683         case KEY_MOUSE:
01684         {
01685             MEVENT  event;
01686             getmouse(&event);
01687             if (event.bstate & (BUTTON1_CLICKED)){
01688                 if( wenclose(w,event.y, event.x))
01689                 {   // we react only if the click was in the userwin, that means
01690                     // inside the menu display area or at the decoration window.
01691                     find_clicked();
01692                     result = execute_current_item(key);
01693                     switch(result) {
01694                         case EXIT_APP:
01695                         case KEY_ESC:
01696                         case KEY_LEFT:
01697                         case KEY_RIGHT:
01698                             return driver(result);
01699                         default:
01700                             break;
01701                     }
01702                 }
01703                 else result = true;
01704             }
01705             break;
01706         }
01707 #endif /* NCURSES_MOUSE_VERSION */
01708         default:
01709             result = ListBox::driver(key);
01710             break;
01711     }
01712     return result;
01713 }

int NDK_XX::MenuBar::execute  
 

Definition at line 1634 of file ndk++.cc.

References driver(), NDK_XX::ListBox::hide(), NDK_XX::ListBox::refresh(), and NDK_XX::ListBox::show().

Referenced by NDK_XX::PopUpMenu::action().

01635 {
01636     show();
01637     refresh();
01638     bool bBreakLoop=false;
01639     do{
01640         bBreakLoop=driver(getch());
01641         
01642     } while( bBreakLoop==false);
01643     hide();
01644     refresh();
01645     return bBreakLoop;
01646 }

int NDK_XX::MenuBar::execute_current_item int    key [protected]
 

Definition at line 1717 of file ndk++.cc.

References NDK_XX::ListBox::curr_item, NDK_XX::ListBox::data, NDK_XX::MenuItem::driver(), NDK_XX::ListBox::refresh(), and NDK_XX::ListBox::visible_item().

Referenced by driver().

01718 {
01719     int result=false;
01720     if(curr_item > -1 && curr_item < data.size()){
01721         MenuItem *pItem = dynamic_cast<MenuItem *>(visible_item(curr_item));
01722         if(pItem){
01723             result = pItem->driver(key);
01724         }
01725         refresh();
01726     }
01727     return result;
01728 }

void NDK_XX::MenuBar::find_clicked   [protected]
 

mouse support

Definition at line 1765 of file ndk++.cc.

References NDK_XX::Control::clicked_inside(), NDK_XX::ListBox::first_visible, NDK_XX::ListBox::items, and NDK_XX::ListBox::set_cur_pos().

Referenced by driver().

01766 {
01767     MEVENT  event;
01768     getmouse(&event);
01769     int ry = event.y, rx = event.x; /* screen coordinates */
01770 
01771     if (mouse_trafo(&ry,&rx,FALSE)){
01772         if(clicked_inside(ry,rx)){
01773             for(int i=0;i<items.size();i++){
01774                 if(items[i]->clicked_inside(ry,rx))
01775                     set_cur_pos(first_visible + i );
01776             }
01777         }
01778     }
01779 }

int NDK_XX::MenuBar::get_next_item_x   [protected]
 

Definition at line 1732 of file ndk++.cc.

References NDK_XX::ListBox::items, orientation, and NDK_XX::ListBox::pos_x.

01733 {
01734     int result = 0;
01735     if(orientation=='v'){
01736         result = pos_x;
01737     }
01738     else{
01739         VisibleItems::iterator it;
01740         for(it=items.begin();it!=items.end();it++){
01741             result += (*it)->width();
01742         }
01743     }
01744     return result;
01745 
01746 }

int NDK_XX::MenuBar::get_next_item_y   [protected]
 

Calculate the position of the next item to be inserted.

Definition at line 1750 of file ndk++.cc.

References NDK_XX::Control::has_frame(), NDK_XX::ListBox::items, orientation, and NDK_XX::ListBox::pos_y.

01751 {
01752     int result = 0;
01753     if(orientation=='h'){
01754         result = pos_y;
01755     }
01756     else{
01757         result = items.size();
01758     }
01759     return result+has_frame();
01760 
01761 }

char NDK_XX::MenuBar::get_orientation   const [inline]
 

we are wide-oriented or tall-oriented?

Definition at line 1381 of file ndk++.h.

References NDK_XX::Control::framed, NDK_XX::Control::notify, NDK_XX::Control::tabstop, and NDK_XX::Control::title.

01386 :  MenuBar (id,title,lines+2,cols+2+1,y,x,orient,style)

void NDK_XX::MenuBar::items_owner bool    t_or_f = true [inline]
 

Definition at line 1405 of file ndk++.h.

Referenced by NDK_XX::PopUpMenu::action().

01407 {

int NDK_XX::MenuBar::move_down   [inline, protected, virtual]
 

Reimplemented from NDK_XX::ListBox.

Reimplemented in NDK_XX::SubMenu.

Definition at line 1423 of file ndk++.h.

References NDK_XX::PopUpMenu::cur_sel, NDK_XX::PopUpMenu::S, and NDK_XX::ListItemData::text.

01423                                   : MenuItemData(text),S(0),cur_sel(-1){    }
01424     ~PopUpMenu();
01425     
01426     int action();
01427     
01428     int largest_name_len()const;

int NDK_XX::MenuBar::move_left   [inline, protected, virtual]
 

move_left and move_right:

if arrow_is_tab == true, they return false, so the owner can process KEY_LEFT and KEY_RIGHT, and properly move to previous or next control.

Reimplemented from NDK_XX::Control.

Reimplemented in NDK_XX::SubMenu.

Definition at line 1429 of file ndk++.h.

References NDK_XX::PopUpMenu::items, NDK_XX::ListItems, NDK_XX::PopUpMenu::S, and NDK_XX::PopUpMenu::sub_menu_label.

Referenced by NDK_XX::CheckListBox::CheckListBox().

01430          :
01431     /// So we can know the right width for the submenu
01432     string sub_menu_label;
01433     ListItems items;
01434     SubMenu *S;
    int cur_sel;

int NDK_XX::MenuBar::move_right   [inline, protected, virtual]
 

Reimplemented from NDK_XX::Control.

Reimplemented in NDK_XX::SubMenu.

Definition at line 1435 of file ndk++.h.

References NDK_XX::PopUpMenu::cur_sel.

01445                : public Control

int NDK_XX::MenuBar::move_up   [inline, protected, virtual]
 

Reimplemented from NDK_XX::ListBox.

Reimplemented in NDK_XX::SubMenu.

Definition at line 1417 of file ndk++.h.

01420                 : public MenuItemData
01421 {
01422 public:


Member Data Documentation

bool NDK_XX::MenuBar::b_own_items [protected]
 

Definition at line 1412 of file ndk++.h.

Referenced by NDK_XX::CheckListBox::CheckListBox(), and NDK_XX::SelectionBox::SelectionBox().

bool NDK_XX::MenuBar::is_main_menu
 

This one si for processing of the ESC key. On the main menu, you MUST treat ESC as EXIT_APP, don't you...? This flag lets the driver know what behavior is intended

Definition at line 1410 of file ndk++.h.

Referenced by NDK_XX::CheckListBox::CheckListBox(), and NDK_XX::SelectionBox::SelectionBox().

char NDK_XX::MenuBar::orientation [protected]
 

Should we delete the added items?

Definition at line 1413 of file ndk++.h.

Referenced by add_item(), NDK_XX::CheckListBox::CheckListBox(), get_next_item_x(), get_next_item_y(), and NDK_XX::SelectionBox::SelectionBox().

string NDK_XX::MenuBar::titlePos [protected]
 

Definition at line 1415 of file ndk++.h.

Referenced by NDK_XX::CheckListBox::CheckListBox().


The documentation for this class was generated from the following files:
Generated on Thu Oct 10 16:02:20 2002 by doxygen1.2.17