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

choice_box.h

Go to the documentation of this file.
00001 // Author:  Daniel Albuschat ( daniel@viming.de ) 
00002 // File:    choice_box.h
00003 // Date:    Mon May 12 15:26:35 20030
00004 // Content:  
00005 
00006 #ifndef CHOICE_BOX_H_1109457361
00007 #define CHOICE_BOX_H_1109457361
00008 #include "base_control.h"
00009 #include <vector>
00010 #include <string>
00011 
00012 namespace crs {
00013 
00014   template< typename T > class choice_box: public focused_ctrl, public styled_ctrl {
00015     public:
00016       struct items {
00017         std::string text;
00018         T           value;
00019         items( const std::string Text, const T Value ):
00020           text(Text), value(Value) {
00021           }
00022       };
00023     private:
00024       std::vector< items > mList;
00025       std::vector< items > foo;
00026       typename std::vector< items >::iterator selected;
00027       const std::vector<items> &getList() {
00028         return mList;
00029       }
00030       void setList( const std::vector<items> &new_list ) {
00031         mList = new_list;
00032       }
00033     public:
00034       choice_box( base_control *Parent, std::vector<items> List, window_events *Events=0, const unsigned int Left=0, const unsigned int Top=0,
00035           const unsigned int Width=0, style::styles Style = style::rect ):
00036         focused_ctrl( Parent, Events, Left, Top, Width, 1 ),
00037       styled_ctrl( Style ),
00038       mList( List ),
00039       selected( mList.begin() ),
00040       list( this, &choice_box::getList, &choice_box::setList ) {
00041         selected = mList.begin();
00042       }
00043       property< choice_box<T>, read_write, std::vector<items> > list;
00044       virtual void draw() {
00045         buffer.fill( ' ' );
00046         if( selected != mList.end() )
00047           buffer.setText( selected->text, 1, 0 );
00048         buffer[ 0 ] = sc::getLeftBorder( mStyle, custom_left_border );
00049         buffer[ mWidth - 2 ] = 'v';
00050         buffer[ mWidth - 1 ] = sc::getRightBorder( mStyle, custom_right_border );
00051       }
00052       virtual bool keyPress( const int key ) {
00053         if( key == KEY_DOWN )
00054           if( selected != mList.end()-1 )
00055             selected++;
00056         if( key == KEY_UP )
00057           if( selected != mList.begin() )
00058             selected--;
00059         return true;
00060       }
00061   };
00062 
00063 }
00064 
00065 #endif
00066 

Generated on Mon May 19 20:36:03 2003 for cursive by doxygen1.2.18