00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "CATTab.h"
00017 #include "CATApp.h"
00018 #include "CATFileSystem.h"
00019 #include "CATStream.h"
00020 #include "CATEvent.h"
00021 #include "CATWindow.h"
00022 #include "CATEventDefs.h"
00023
00024
00025
00026
00027
00028
00029
00030 CATTab::CATTab( const CATString& element,
00031 const CATString& rootDir)
00032 : CATLayer(element, rootDir)
00033 {
00034 fCurTab = 0;
00035 fVisible = false;
00036 }
00037
00038
00039
00040
00041 CATTab::~CATTab()
00042 {
00043 }
00044
00045
00046 CATResult CATTab::ParseAttributes()
00047 {
00048 CATResult result = CATLayer::ParseAttributes();
00049 CATString attrib;
00050
00051 fCurTab = GetAttribute(L"StartTab",fCurTab);
00052
00053 return result;
00054
00055 }
00056
00057
00058
00059
00060 CATControl* CATTab::HitTest(const CATPOINT& point)
00061 {
00062 if (!fRect.InRect(point))
00063 {
00064 return 0;
00065 }
00066
00067 CATPOINT layerPt = point;
00068 layerPt.x -= fRect.left;
00069 layerPt.y -= fRect.top;
00070
00071 CATUInt32 numControls = this->GetNumChildren();
00072 if ((fCurTab < 0) || (fCurTab >= numControls))
00073 {
00074 CATASSERT(false,"Invalid value for fCurTab!");
00075 fCurTab = 0;
00076 }
00077
00078 CATControl* finalHit = 0;
00079
00080 CATXMLObject* curChild = GetChild(fCurTab);
00081 if (fCurTab)
00082 {
00083 CATWidget* curControl = (CATWidget*)curChild;
00084 if (curControl->IsEnabled())
00085 {
00086 CATControl* hitControl = curControl->HitTest(layerPt);
00087 if (hitControl)
00088 {
00089 finalHit = hitControl;
00090 }
00091 }
00092 }
00093
00094 return finalHit;
00095 }
00096
00097
00098 void CATTab::Draw(CATImage* image, const CATRect& dirtyRect)
00099 {
00100 if (this->IsVisible() == false)
00101 {
00102 return;
00103 }
00104
00105
00106 CATRect layerRect;
00107 if (!fRect.Intersect( dirtyRect, &layerRect))
00108 return;
00109
00110 layerRect.Offset( -fRect.left, -fRect.top);
00111
00112 CATUInt32 numControls = this->GetNumChildren();
00113 if ((fCurTab < 0) || (fCurTab >= numControls))
00114 {
00115 CATASSERT(false,"Invalid value for fCurTab!");
00116 fCurTab = 0;
00117 }
00118
00119 CATImage* subImage = 0;
00120
00121 if (CATSUCCEEDED(CATImage::CreateSub( image,
00122 subImage,
00123 fRect.left,
00124 fRect.top,
00125 CATMin(image->Width() - fRect.left, fRect.Width()),
00126 CATMin(image->Height() - fRect.top, fRect.Height()) )))
00127 {
00128
00129 CATXMLObject* curChild = GetChild(fCurTab);
00130 if (curChild)
00131 {
00132 CATWidget* curControl = (CATWidget*)curChild;
00133 curControl->Draw(subImage,layerRect);
00134 }
00135
00136 CATImage::ReleaseImage(subImage);
00137 }
00138 }
00139
00140 void CATTab::PostDraw(CATDRAWCONTEXT context, const CATRect& dirtyRect)
00141 {
00142
00143 CATRect layerRect;
00144 if (!fRect.Intersect( dirtyRect, &layerRect))
00145 return;
00146 layerRect.Offset( -fRect.left, -fRect.top);
00147
00148
00149 CATUInt32 numControls = this->GetNumChildren();
00150 if ((fCurTab < 0) || (fCurTab >= numControls))
00151 {
00152 CATASSERT(false,"Invalid value for fCurTab!");
00153 fCurTab = 0;
00154 }
00155
00156
00157 CATXMLObject* curChild = GetChild(fCurTab);
00158 if (curChild)
00159 {
00160 CATWidget* curControl = (CATWidget*)curChild;
00161 curControl->PostDraw(context,layerRect);
00162 }
00163 }
00164
00165
00166 CATResult CATTab::OnEvent( const CATEvent& event, CATInt32& retVal)
00167 {
00168
00169
00170
00171 if ( (event.fEventCode == CATEVENT_TAB_SHOW) ||
00172 (event.fEventCode == CATEVENT_TAB_HIDE) )
00173 {
00174 CATUInt32 numControls = this->GetNumChildren();
00175 if ((fCurTab < 0) || (fCurTab >= numControls))
00176 {
00177 CATASSERT(false,"Invalid value for fCurTab!");
00178 fCurTab = 0;
00179 }
00180 CATXMLObject* curChild = GetChild(fCurTab);
00181 if (curChild)
00182 {
00183 CATWidget* curControl = (CATWidget*)curChild;
00184 return curControl->OnEvent( event, retVal);
00185 }
00186 }
00187
00188 return CATLayer::OnEvent(event,retVal);
00189 }
00190
00191
00192 CATResult CATTab::SetCurTab( CATUInt32 curTab )
00193 {
00194 if (curTab >= this->GetNumChildren())
00195 {
00196 return CATRESULT(CAT_ERR_INVALID_TAB);
00197 }
00198
00199
00200
00201 if (this->IsVisible())
00202 {
00203 fCurTab = curTab;
00204 for (CATUInt32 i = 0; i < this->GetNumChildren(); i++)
00205 {
00206 CATXMLObject* curChild =0;
00207 if (0 != (curChild = GetChild(i)))
00208 {
00209 CATInt32 retVal;
00210
00211 CATWidget* curControl = (CATWidget*)curChild;
00212 if (i == curTab)
00213 {
00214 curControl->OnEvent(CATEVENT_TAB_SHOW,retVal);
00215 }
00216 else
00217 {
00218 curControl->OnEvent(CATEVENT_TAB_HIDE,retVal);
00219 }
00220 }
00221 }
00222 }
00223 else
00224 {
00225 fCurTab = curTab;
00226 }
00227
00228
00229 CATResult result = this->GetWindow()->ResetBackground();
00230
00231 this->MarkDirty(0,true);
00232 return result;
00233 }
00234
00235 CATUInt32 CATTab::GetCurTab( )
00236 {
00237 return fCurTab;
00238 }
00239
00240 CATUInt32 CATTab::GetNumTabs()
00241 {
00242 return this->GetNumChildren();
00243 }
00244
00245 CATResult CATTab::Load(CATPROGRESSCB progressCB,
00246 void* progressParam,
00247 CATFloat32 progMin,
00248 CATFloat32 progMax)
00249 {
00250 CATResult result = CATLayer::Load(progressCB, progressParam, progMin, progMax);
00251 this->SetCurTab(fCurTab);
00252
00253 return result;
00254 }
00255
00256 void CATTab::OnParentCreate()
00257 {
00258 CATLayer::OnParentCreate();
00259
00260 this->fVisible = true;
00261 this->SetCurTab(fCurTab);
00262 }
00263
00264 bool CATTab::GetPostRects(CATStack<CATRect>& rectStack)
00265 {
00266 CATUInt32 numControls = this->GetNumChildren();
00267 if ((fCurTab < 0) || (fCurTab >= numControls))
00268 {
00269 CATASSERT(false,"Invalid value for fCurTab!");
00270 fCurTab = 0;
00271 }
00272
00273
00274 CATXMLObject* curChild = GetChild(fCurTab);
00275 if (curChild)
00276 {
00277 CATWidget* curControl = (CATWidget*)curChild;
00278 return curControl->GetPostRects(rectStack);
00279 }
00280
00281 return false;
00282 }
00283
00284 bool CATTab::IsVisible(const CATGuiObj* object) const
00285 {
00286 if (fVisible)
00287 {
00288 if (object == 0)
00289 {
00290 return ((CATGuiObj*)fParent)->IsVisible(this);
00291 }
00292
00293
00294 CATXMLObject* curChild = GetChild(fCurTab);
00295 if (curChild)
00296 {
00297 if ((CATGuiObj*)curChild == object)
00298 {
00299 return ((CATGuiObj*)fParent)->IsVisible(this);
00300 }
00301 }
00302 }
00303 return false;
00304 }