Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

CheckBoxValueBars.h

Go to the documentation of this file.
00001 //345678901234567890123456789012345678901234567890123456789012345678901234567890
00002 // CheckBoxValueBars.h
00003 // A dynamic list of CheckBoxValueBar* items.
00004 // When right clicking on a checkbox the user can change the CheckBox text
00005 // to a choice from a DropDownStringSelector.
00006 //
00007 // Author: Richard van Balen
00008 
00009 #ifndef OglGui_CheckBoxValueBars_h
00010 #define OglGui_CheckBoxValueBars_h
00011 
00012 #include "OglGui/DynamicList.h"
00013 #include "OglGui/CheckBoxValueBar.h"
00014 #include "OglGui/DropDownStringSelector.h"
00015 #include "OglGui/ColorTargetModalDialog.h"
00016 
00017 namespace OglGui
00018 {
00019 
00020 class CheckBoxValueBars :   public DynamicList,
00021                             public WindowListener,
00022                             public StringListener
00023 {
00024     static const int ON_CHECKBOX    = 1;
00025     static const int ON_HEADER      = 2;
00026     static const int ON_MODALWND    = 3;
00027 
00028 public:
00029     CheckBoxValueBars(Window* parent, int w, int h, int options=0) :
00030         DynamicList(parent, w, h)
00031     {
00032         Init(w,h,options);
00033     }
00034 
00035     CheckBoxValueBars(Window* parent,int x,int y,int w,int h, int options=0):
00036         DynamicList(parent, x, y, w, h)
00037     {
00038         Init(w,h,options);
00039     }
00040 
00041     void CheckBoxWidth(int w)           { mCheckBoxWidth = w; } 
00042     int  CheckBoxWidth()                { return mCheckBoxWidth; }
00043     int  NrOfItems()                    { return mChildWindows.size(); }
00044 
00045     CheckBoxValueBar* AddItem(strconst str, ULONG color)
00046     {
00047         bool menuBtn = mOptions != 0;
00048         CheckBoxValueBar* chBoxVB =
00049             new CheckBoxValueBar(this,W(),22,str,color,mCheckBoxWidth,menuBtn);
00050         chBoxVB->ConnectTo(this,L2L|R2R);
00051         if (mOptions)
00052             chBoxVB->MenuBtn()->SetWindowListener(this,(void*)chBoxVB->ChBox());
00053         this->AddWindow(chBoxVB);
00054         return chBoxVB;
00055     }
00056 
00057     CheckBoxValueBar* GetItem(int idx)
00058     {
00059         if (idx<0 || idx>mChildWindows.size()-1)
00060             return 0;
00061         return (CheckBoxValueBar*) mChildWindows[idx];
00062     }
00063 
00064     CheckBoxValueBar* GetItem(strconst str)
00065     {
00066         CheckBoxValueBar* chBoxVB;
00067         for (int i=0; i<mChildWindows.size(); i++)
00068         {
00069             chBoxVB = (CheckBoxValueBar*) mChildWindows[i];
00070             if (chBoxVB->ChBox()->GetText() == str)
00071                 return chBoxVB;
00072         }
00073         return 0;
00074     }
00075 
00076     void AddChoice(strconst str)
00077     {
00078         if (mDropSelector)
00079             mDropSelector->StrSelector()->AddString(str);
00080     }
00081 
00082     void ClearChoices()
00083     {
00084         if (mDropSelector)
00085             mDropSelector->StrSelector()->RemoveStrings();
00086     }
00087 
00088     virtual void
00089     StringSelectionEvent(StringSelector *src, int strIndex, void* userData)
00090     {
00091         std::string         str   = src->GetString(strIndex);
00092         CheckBox*           chBox = (CheckBox*) userData;
00093         CheckBoxValueBar*   cbVB;
00094 
00095         if ((mOptions & 2) && strIndex==0) // Change Color
00096         {
00097             cbVB = GetItem(chBox->GetText());
00098             HideDropSelector();
00099             ULONG col = chBox->GetBorderBackground();
00100             ColorTargetModalDialogFunc(src,cbVB->ValueBar(),0,col,800,400);
00101             return;
00102         }
00103 
00104         chBox->SetText("");
00105         cbVB = GetItem(str);
00106         if (cbVB)               // If other item has same text then clear it
00107             cbVB->Name("");
00108         chBox->SetText(str);
00109         HideDropSelector();
00110 
00111         // Trick to allow listener to sync
00112         chBox->DoSelect(chBox->GetSelected());
00113     }
00114 
00115     void SelectorPopUpAtCheckBox(CheckBox* chBox)
00116     {
00117         mModalWnd->SetVisible(true);
00118         oglSys.BringToFront(mModalWnd->GetOGLWND());
00119 
00120         StringSelector* strSelector = mDropSelector->StrSelector();
00121         strSelector->SetStringListener(this,(void*)chBox);
00122         strSelector->SetDimensions(chBox->W(),RETAIN);
00123         strSelector->SetCurrentString(0,true);
00124 
00125         int x=0, y=0;
00126         chBox->OffsetXY(mTopWnd,x,y);
00127         mDropSelector->DropDown(false);
00128         mDropSelector->SetDimensions(x,y+2,RETAIN,RETAIN);
00129         mDropSelector->SetBackground(chBox->GetBorderBackground());
00130         mDropSelector->HeaderText()->SetText(chBox->GetText());
00131         mDropSelector->DropDown(true);
00132     }
00133 
00134     void HideDropSelector()
00135     {
00136         if (mModalWnd)
00137             mModalWnd->SetVisible(false);
00138     }
00139 
00140     virtual void InitDisplayFunc()
00141     {
00142         for (int i=0; i<mChildWindows.size(); i++)
00143         {
00144             CheckBoxValueBar* chBoxVB = (CheckBoxValueBar*) mChildWindows[i];
00145             ULONG col = chBoxVB->ValueBar()->GetBackground();
00146             chBoxVB->ChBox()->SetBorderBackground(col);
00147         }
00148         DynamicList::InitDisplayFunc();
00149     }
00150 
00151     virtual void
00152     WindowMouseEvent(Window *src, int msg, int but, int state,
00153                      int x, int y, void* userData )
00154     {
00155         if (msg==oglMouseDown)
00156         {
00157             if (userData==(void*)ON_HEADER || userData==(void*)ON_MODALWND)
00158                 HideDropSelector();
00159             else
00160                 SelectorPopUpAtCheckBox((CheckBox*) userData);
00161         }
00162     }
00163 
00164 protected:
00165     Window*                     mTopWnd;
00166     Window*                     mModalWnd; // To make the DropDownSelector modal
00167     DropDownStringSelector*     mDropSelector;
00168 
00169     int                         mCheckBoxWidth;
00170     int                         mOptions;
00171 
00172 private:
00173     void HandleOptions()
00174     {
00175         mModalWnd = new Window(mTopWnd,0,0,mTopWnd->W(),mTopWnd->H());
00176         mModalWnd->SetVisible(false);
00177         mModalWnd->ConnectTo(mTopWnd);
00178         mModalWnd->SetWindowListener(this, (void*)ON_MODALWND);
00179 
00180         mDropSelector =
00181             new DropDownStringSelector(mModalWnd,0,0,100,"",100,120,0);
00182         mDropSelector->SetBorderType(BEV_RAISED);
00183         mDropSelector->StrSelector()->SetBackground(oglWHITE);
00184         mDropSelector->StrSelector()->SetBorderFillShaded(2);
00185 
00186         mDropSelector->HeaderWindow()->SetWindowListener(this,(void*)ON_HEADER);
00187         if (mOptions & 2)
00188             AddChoice("Change Color...");
00189     }
00190 
00191     void Init(int w, int h, int options)
00192     {
00193         mTopWnd = this;
00194         Window* parent = this;
00195         while(parent = parent->GetParent())
00196             mTopWnd = parent;
00197 
00198         mCheckBoxWidth  = 120;
00199         mDropSelector = 0;
00200         mModalWnd = 0;
00201         if (mOptions = options)
00202             HandleOptions();
00203     }
00204 };
00205 
00206 } // Namespace OglGui
00207 #endif
00208 

Generated on Fri Mar 19 09:31:34 2010 for ImpalaSrc by  doxygen 1.5.1