MOOS 0.2375
/home/toby/moos-ivp/MOOS-2375-Oct0611/Thirdparty/FLTKVW/FLTKCheckList.h
Go to the documentation of this file.
00001 #ifndef CFLTKCheckListH
00002 #define CFLTKCheckListH
00003 #include "Flv_Table.H"
00004 #include <FL/fl_draw.H>
00005 
00006 #include <map>
00007 #include <vector>
00008 #include <string>
00009 #include <iostream>
00010 
00011 
00012 class CFLTKCheckList :  public Flv_Table
00013 {
00014 private:
00015     typedef Flv_Table BASE;
00016 public:
00017     CFLTKCheckList( int X, int Y, int W, int H, const char *l ) : BASE(X,Y,W,H,l)
00018     {
00019         cols(2);
00020         //set up callbacks
00021         callback_when( FLVEcb_CLICKED );
00022         callback((Fl_Callback*)ListCallback);
00023         max_clicks(2);
00024         Flv_Style s;
00025         BASE::get_style(s,0,0);
00026         global_style.background(FL_GRAY);
00027         color(FL_BLUE);
00028 
00029         has_scrollbar(FLVS_VERTICAL);
00030 
00031         feature(FLVF_DIVIDERS|FLVF_MULTI_SELECT|FLVF_FULL_RESIZE);
00032         feature_remove(FLVF_MULTI_SELECT | FLVF_COL_HEADER |FLVF_DIVIDERS);
00033         AddItem("lala",true);
00034         AddItem("la",false);
00035         AddItem("spock",true);
00036         AddItem("bock",true);
00037 
00038     }
00039 
00040     void OnListCallBack()
00041     {
00042         if(why_event()==FLVE_CLICKED)
00043         {
00044             //this is a double click
00045             int c = select_start_col();
00046             int r = select_start_row();
00047             m_Data[r].second = !m_Data[r].second;
00048         }
00049     }
00050 
00051     static void ListCallback(CFLTKCheckList *pMe, void * )
00052     {
00053         pMe->OnListCallBack();
00054         std::cout<<"InCallBack"<<std::endl;
00055     }
00056     
00057     virtual void add_selection_style( Flv_Style &s, int R, int C ){};
00058 
00059 
00060     void AddItem(const std::string & sStr,bool bInitialValue)
00061     {
00062         m_Data.push_back( std::pair<std::string, bool>(sStr,bInitialValue));
00063         m_Index[sStr] = m_Data.size()-1;      
00064         rows(m_Data.size());
00065     }
00066 
00067     bool IsChecked(const std::string & sStr)
00068     {
00069         std::map<std::string, int>::iterator p = m_Index.find(sStr);
00070 
00071         if(p!=m_Index.end())
00072         {
00073             return m_Data[p->second].second;
00074         }
00075         else
00076         {
00077             return false;
00078         }
00079     }
00080 
00081 
00082     virtual int col_width( int C )
00083     {
00084         static int LW=-1;
00085         static int cw[2];
00086 
00087         int scrollbar_width = (scrollbar.visible()?scrollbar.w():0);
00088         int W = w()- scrollbar_width-1;
00089     
00090         //  Either always calculate or be sure to check that width
00091         //  hasn't changed.
00092         if (W!=LW)                          //  Width change, recalculate
00093         {
00094             cw[0] = (W*80)/100;
00095             cw[1] = (W-cw[0]-1);
00096         }
00097         return cw[C];
00098 
00099     }
00100 
00101     virtual void draw_cell( int Offset, int &X, int &Y, int &W, int &H, int R, int C )
00102     {
00103         Flv_Style s;
00104         get_style(s, R, C);
00105         Flv_Table::draw_cell(Offset,X,Y,W,H,R,C);
00106 
00107         if(R>-1 && R<(int)m_Data.size())
00108         {
00109             if(C==0)
00110             {
00111                 fl_draw(m_Data[R].first.c_str(), X-Offset, Y, W, H, s.align() );
00112             }
00113             else if(C==1)
00114             {
00115                 if(m_Data[R].second)
00116                 {
00117                     #define SZ 5
00118                     fl_draw_symbol("@square", X-Offset+(W-SZ)/2, Y+(H-SZ)/2, SZ,
00119                                             SZ, (Fl_Color)(FL_RED) );
00120                 }
00121                 else
00122                 {
00123                     fl_draw_symbol("@square", X-Offset+(W-SZ)/2, Y+(H-SZ)/2, SZ,
00124                                             SZ, (Fl_Color)(FL_LIGHT1) );
00125                 }
00126             }
00127         }
00128     };
00129     
00130     
00131     private:
00132     std::vector< std::pair<std::string,bool> > m_Data;
00133     std::map<std::string, int> m_Index; 
00134     
00135 
00136 };
00137 
00138 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines