00001 #ifndef VideoExcel_VideoExcelNode_h
00002 #define VideoExcel_VideoExcelNode_h
00003
00004 #ifndef OglGui_StaticText_h
00005 #include "OglGui/StaticText.h"
00006 #endif
00007
00008 namespace Impala {
00009 namespace Application {
00010 namespace VideoExcel {
00011
00012
00013
00014
00015 class VideoExcelNode : public Window, WindowListener
00016 {
00017 public:
00018
00019 VideoExcelNode(Window* parent, int width, int height,
00020 strconst txt, int options=PlusMinus+Lines) :
00021 Window(parent, width, height)
00022 {
00023 Init(width, height, txt, options);
00024 }
00025
00026 VideoExcelNode(Window* parent, int x, int y, int width, int height,
00027 strconst txt, int options=PlusMinus+Lines) :
00028 Window(parent, x, y, width, height)
00029 {
00030 Init(width, height, txt, options);
00031 }
00032
00033 enum DDOPTIONS {
00034 PlusMinus = 1,
00035 Lines = 2,
00036 };
00037
00038 void AddNode(Window* child, int inset=20, int insertAt=-1)
00039 {
00040 int x,y,w,h;
00041
00042 if (insertAt==-1 || insertAt>mChildNodes.size()-1)
00043 mChildNodes.push_back(child);
00044 else
00045 mChildNodes.insert(mChildNodes.begin()+insertAt+1,child);
00046 child->SetAllowReposition(false);
00047 child->GetDimensions(x,y,w,h);
00048 child->SetDimensions(x+inset,y,w,h);
00049 HandleLayoutChange();
00050 }
00051
00052 void HandleLayoutChange()
00053 {
00054 Window* wnd = this;
00055 while(wnd != 0 && (wnd->GetRunTimeType() & 8))
00056 {
00057 wnd->DisplayFunc();
00058 wnd = wnd->GetParent();
00059 }
00060 }
00061
00062
00063
00064
00065 void RemoveNode(Window* child, bool destroy=false)
00066 {
00067 for (int i=0; i<mChildNodes.size(); i++)
00068 if (child == mChildNodes[i])
00069 {
00070 mChildNodes.erase(mChildNodes.begin() + i);
00071 if (destroy)
00072 delete child;
00073 HandleLayoutChange();
00074 return;
00075 }
00076 }
00077
00078 void DropDown(bool mode=true)
00079 {
00080 mIsDropped = mode;
00081 if (mPlusMinText)
00082 mPlusMinText->SetText(mIsDropped ? "-" : "+");
00083 HandleLayoutChange();
00084 }
00085
00086 void SetClosedHeight(int h) { mClosedHeight = h; }
00087 bool IsDropped() const { return mIsDropped; }
00088 void ShowLines(bool show=true) { mShowLines = show; }
00089 void LinePattern(short pat) { mLinePattern = pat; }
00090 void Spacing(int nPix) { mSpacing = nPix; }
00091
00092 Window* HeaderWindow() { return mHeaderWindow; }
00093 StaticText* HeaderText() { return mHeaderText; }
00094 StaticText* PlusMinText() { return mPlusMinText; }
00095
00096
00097
00098 virtual void
00099 WindowMouseEvent(Window *src, int msg, int but, int state, int x, int y,
00100 void* listenerData)
00101 {
00102 if (but==oglLeftButton)
00103 {
00104 if ((src == mPlusMinText && msg == oglMouseDown))
00105 DropDown(!mIsDropped);
00106 else if(src != mPlusMinText && msg == oglMouseDblClick)
00107 DropDown(!mIsDropped);
00108 }
00109 }
00110
00111
00112
00113 virtual void
00114 DisplayFunc()
00115 {
00116 OGC myOGC;
00117 int curY = WndHeight();
00118 int nY = curY-mHeaderHeight-2, nW = 0, nH = 0;
00119 int lineX, topLineY = nY;
00120 bool itemLines = (mShowLines && mIsDropped);
00121
00122 mHeaderWindow->SetDimensions(RETAIN, nY, RETAIN, mHeaderHeight);
00123
00124 if (mShowLines)
00125 {
00126 OGCSave(&myOGC);
00127 SetStipple(mLinePattern);
00128 SetSolidLineColor(mForeGroundColor);
00129 lineX = mHeaderWindow->WndX();
00130 DrawLine(lineX, nY+7, 0, nY+7);
00131 lineX += 6;
00132 }
00133
00134 for (int i=0 ; i < mChildNodes.size() ; i++)
00135 {
00136 int cX, cY, cW, cH;
00137 Window* child = mChildNodes[i];
00138
00139 if (!HasTags((TAGABLE*)child->GetOGLWND(), visibleTag))
00140 continue;
00141
00142 child->GetDimensions(cX,cY,cW,cH);
00143
00144 nH += cH + ((i==0) ? 4 : mSpacing);
00145 curY -= cH + ((i==0) ? 4 : mSpacing);
00146
00147 child->SetDimensions(RETAIN, curY, RETAIN, RETAIN);
00148
00149 if ((i>0) && itemLines)
00150 {
00151 if (lineX < cX )
00152 DrawLine(lineX, curY+cH-11, cX-2, curY+cH-11);
00153 if (lineX > cX+cW)
00154 DrawLine(lineX, curY+cH-11, cX+cW+2, curY+cH-11);
00155 nY = curY+cH-9;
00156 }
00157
00158 if ((i<1) || (mIsDropped && (nW < cX+cW)))
00159 nW = cX+cW;
00160 }
00161 if (itemLines)
00162 DrawLine(lineX, nY, lineX, topLineY);
00163
00164 nY = WndY() + WndHeight() - (mIsDropped ? nH : mClosedHeight);
00165 nH = mIsDropped ? nH : mClosedHeight;
00166
00167 SetDimensions(WndX(), nY, nW+2, nH);
00168
00169 if (mShowLines) OGCRestore(&myOGC);
00170
00171 Window::DisplayFunc();
00172 }
00173
00174
00175 private :
00176
00177 Window* mHeaderWindow;
00178 StaticText* mPlusMinText;
00179 StaticText* mHeaderText;
00180 std::vector<Window*> mChildNodes;
00181 bool mShowLines;
00182 short mLinePattern;
00183 bool mIsDropped;
00184 int mHeaderHeight;
00185 int mClosedHeight;
00186 int mSpacing;
00187
00188 void
00189 Init(int w, int h, strconst txt, int options)
00190 {
00191 int hdrX = 2;
00192 int hdrTxtX = 4;
00193 bool plMin = (options & 1) ? true : false;
00194
00195 mRunTimeType |= 8;
00196 mHeaderHeight = 16;
00197 mPlusMinText = 0;
00198 mIsDropped = false;
00199 mShowLines = (options & 2) ? true : false;
00200 mLinePattern = (short) oglDot;
00201 mRunTimeType |= 8;
00202 mSpacing = 2;
00203 mClosedHeight = h;
00204
00205 mHeaderWindow = new Window(this, hdrX, 0, w-hdrX, mHeaderHeight);
00206 mHeaderWindow->SetWindowListener(this);
00207
00208 if (plMin)
00209 {
00210 mPlusMinText = new StaticText(mHeaderWindow, 0, 3, 13, 13, "+");
00211 mPlusMinText->SetBorderType(BEV_LINE);
00212 mPlusMinText->SetDoStateFeedback(true);
00213 mPlusMinText->SetWindowListener(this);
00214 hdrTxtX = 14;
00215 }
00216
00217 mHeaderText = new StaticText(mHeaderWindow, hdrTxtX, 0, w-hdrTxtX-2,
00218 16, txt);
00219 mHeaderText->SetAlign(oglLeftAlign, oglBottomAlign);
00220 mHeaderText->SetNoMouseInput(true);
00221 mHeaderText->SetWindowListener(this);
00222
00223 AddWindow(mHeaderWindow, 0);
00224 DropDown(false);
00225 }
00226 };
00227
00228 }
00229 }
00230 }
00231
00232 #endif // VideoExcelNode_h