00001 #include "../prop.h"
00002 #include "events.h"
00003 #include "drawing_area.h"
00004 #include "cursive.h"
00005 #include <string>
00006 #include <list>
00007
00008 #ifndef BASE_CONTROL_H_982363
00009 #define BASE_CONTROL_H_982363
00010
00011 namespace crs {
00012
00017 class base_control {
00018 public:
00019 typedef std::list< base_control* > controllist;
00020 std::string name;
00021 private:
00022 controllist::iterator parentHandle;
00023 void init();
00024 const int &getTop();
00025 void setTop( const int &val );
00026
00027 const int &getLeft();
00028 void setLeft( const int &val );
00029
00030 const unsigned int &getWidth();
00031 void setWidth( const unsigned int &val );
00032
00033 const unsigned int &getHeight();
00034 void setHeight( const unsigned int &val );
00035
00036 const base_control &getParent();
00037 void setParent( const base_control &win );
00038
00039 const controllist &getControls();
00040
00041 const bool &getVisible();
00042 void setVisible( const bool &is );
00043
00044 const position &getCurPos();
00045 void setCurPos( const position &new_pos );
00046
00047 protected:
00048 position mCursorpos;
00049 window_events *events;
00050 base_control *mParent;
00051 controllist mControls;
00052 void resize();
00053 drawing_area buffer;
00054 int mLeft, mTop;
00055 unsigned int mWidth, mHeight;
00056 unsigned int parentTop, parentLeft, parentWidth, parentHeight;
00057 bool mVisible;
00058
00059 void updateParentCoord();
00060 void fill( const char ch );
00061 void putPixel( const char ch, const unsigned int x, const unsigned int y );
00062 virtual void doMove( const position &old_pos, const position &new_pos );
00063 virtual void doResize( const bounds &old_bounds, const bounds &new_bounds );
00064 virtual void doShow();
00065 virtual void doHide();
00066 void setText( const std::string &text, const unsigned int x=0, const unsigned int y=0 );
00067 public:
00068 void flush( chtype *parentWin, const unsigned int parentWidth, const unsigned int parentHeight );
00069 explicit base_control( base_control *Parent, window_events *Events=0,
00070 const unsigned int Left=0, const unsigned int Top=0, const unsigned int Width=0, const unsigned int Height=0 );
00071 virtual ~base_control();
00072 virtual controllist::iterator registerControl( base_control *control );
00073 virtual void deregisterControl( controllist::iterator &i );
00074 virtual void freeRegistration();
00075 virtual void draw();
00076 virtual void draw_on_screen();
00077 virtual bool keyPress( const int ){ return true; }
00078
00079 property< base_control, read_write, int > top;
00080 property< base_control, read_write, int > left;
00081 property< base_control, read_write, unsigned int > width;
00082 property< base_control, read_write, unsigned int > height;
00083 property< base_control, read_write, const base_control > parent;
00084 property< base_control, read_write, bool > visible;
00085 property< base_control, read_write, position > curpos;
00086 property< base_control, read_only, controllist > controls;
00087 int getAbsTop() const;
00088 int getAbsLeft() const;
00089
00090 const bounds &getBounds();
00091 };
00092
00093 class focused_ctrl: public base_control {
00094 public:
00095 typedef std::list< focused_ctrl* > focuslist;
00096 private:
00097 focuslist::iterator focusHandle;
00098 public:
00099 focused_ctrl( base_control *Parent, window_events *Events=0,
00100 const unsigned int Left=0, const unsigned int Top=0, const unsigned int Width=0, const unsigned int Height=0 );
00101 ~focused_ctrl();
00102 };
00103
00104 class styled_ctrl {
00105 protected:
00106 style::styles mStyle;
00107 chtype custom_left_border;
00108 chtype custom_right_border;
00109 const style::styles &getStyle();
00110 void setStyle( const style::styles &Style );
00111 public:
00112 styled_ctrl( style::styles Style = style::rect, chtype clb = '[', chtype crb = ']' );
00113 property< styled_ctrl, read_write, style::styles > style;
00114 };
00115 }
00116
00117 #endif
00118