00001
00002
00003
00004
00005
00012 #ifndef HPANEL_H
00013 # define HPANEL_H
00014
00015 #ifndef HARRAY_H
00016 # include <HArray.h>
00017 #endif
00018
00019 #ifndef HWIDGET_H
00020 # include <HWidget.h>
00021 #endif
00022
00028 class HPanelItem : public HID,
00029 public HWidget
00030 {
00031 typedef HWidget base_class;
00032 static StringPtr ClassName(void) { return "HPanelItem"; }
00033
00034 friend class HPanel;
00035
00036
00037
00038 protected:
00039 HMap<int32,HANDLE> m_actions;
00040
00041
00042
00043 public:
00044 HPanelItem(int32 id = 0) : HID(id), HWidget()
00045 { }
00046
00047 virtual
00048 ~HPanelItem(void)
00049 { Destroy(); }
00050
00051
00052
00053 BEGIN_MSG_MAP("HPanelItem")
00054 CHAIN_MAP( base_class )
00055 END_MSG_MAP
00056
00057
00058
00059 public:
00068 ErrCode
00069 AddAction(int32 id, StringPtr pstrLabel, uint32 uFlags)
00070 {
00071 ErrCode ec = HError::NoError();
00072 HANDLE hAction = NULL;
00073
00074 try
00075 {
00076 if (!IsValid())
00077 HError::Throw(ERR_NOT_INITIALIZED, __FILE__, __LINE__);
00078
00079 hAction = GI_create_widget_static( m_hMe, TEXT(kStrEmpty),
00080 5, 0, 0, 20,
00081 uFlags, TEXT(pstrLabel));
00082 if (NULL_HND(hAction))
00083 HError::Throw(ERR_API_ERROR, __FILE__, __LINE__);
00084
00085 if (GI_widget_static_use_parent_background(hAction, 1) != S_OK)
00086 (void) HError::Set(ERR_API_ERROR, __FILE__, __LINE__);
00087
00088 if (GI_LayoutAdd( m_hMe, hAction, 0, 0,
00089 WGF_LAYOUT_FIXSIZE,
00090 WGF_LAYOUT_ALIGN_SPACING) != S_OK)
00091 {
00092 HError::Throw(ERR_API_ERROR, __FILE__, __LINE__);
00093 }
00094
00095
00096 if ((ec = m_actions.Set(id, hAction)) == NO_ERROR)
00097 {
00098 DEBUG_LOG( "HPanelItem[%p]::AddAction() => added action #%ld \"%s\".\n",
00099 this, id, STR_SAFE(pstrLabel));
00100 }
00101 }
00102 catch (const std::exception & e)
00103 {
00104 DEBUG_LOG("HPanel[%p]::AddAction() => caught %s\n", this, e.what());
00105 if ((ec = ErrCode( HError::GetLastError() )) == NO_ERROR)
00106 ec = HError::Set(ERR_STL_EXCEPTION, __FILE__, __LINE__);
00107
00108 if (GOOD_HND(hAction))
00109 (void) GI_destroy_window( reinterpret_cast<s_window *>(hAction) );
00110 }
00111
00112 return ec;
00113 }
00122 ErrCode
00123 Create(HANDLE hParent, int32 id, StringPtr pstrTitle)
00124 {
00125 ErrCode ec = HError::NoError();
00126
00127 ASSERT( NULL_HND(m_hMe) );
00128
00129 if (GOOD_HND(hParent) && id)
00130 {
00131 m_hMe = GI_CreateWidgetPanelItem( hParent, TEXT(pstrTitle),
00132 0, 0, 0, 0, 0, 0);
00133 if (GOOD_HND(m_hMe))
00134 {
00135 m_id = id;
00136 ec = enableMessages();
00137
00138 DEBUG_LOG( "HPanelItem[%p]::Create() => m_hMe = 0x%08lX\n",
00139 this, int32(m_hMe));
00140 }
00141 else
00142 ec = HError::Set(ERR_API_ERROR, __FILE__, __LINE__);
00143 }
00144 else
00145 ec = HError::Set(ERR_BAD_PARAMETER, __FILE__, __LINE__);
00146
00147 return ec;
00148 }
00155 ErrCode
00156 RemoveAction(int32 id)
00157 {
00158 HANDLE hAction = NULL;
00159 ErrCode ec = HError::NoError();
00160
00161 try
00162 {
00163 if ((ec = m_actions.Get(id, hAction)) != NO_ERROR ||
00164 (ec = m_actions.Remove(id)) != NO_ERROR)
00165 {
00166 throw HError::GetLastError();
00167 }
00168
00169 if (GOOD_HND(hAction))
00170 {
00171 if (GI_LayoutRemove(m_hMe, hAction) != S_OK ||
00172 GI_destroy_window( reinterpret_cast<s_window *>(hAction) ) != S_OK)
00173 {
00174 HError::Throw(ERR_API_ERROR, __FILE__, __LINE__);
00175 }
00176 }
00177
00178 DEBUG_LOG( "HPanelItem[%p]::RemoveAction() => removed action #%ld.\n",
00179 this, id);
00180 }
00181 catch (const std::exception & e)
00182 {
00183 DEBUG_LOG("HPanel[%p]::RemoveAction() => caught %s\n", this, e.what());
00184 if ((ec = ErrCode( HError::GetLastError() )) == NO_ERROR)
00185 ec = HError::Set(ERR_STL_EXCEPTION, __FILE__, __LINE__);
00186 }
00187
00188 return ec;
00189 }
00194 ErrCode
00195 RemoveAllActions(void)
00196 {
00197 ErrCode ec = HError::NoError();
00198
00199 while (m_actions.IsNotEmpty())
00200 {
00201 ASSERT( m_actions.begin() != m_actions.end() );
00202 if ((ec = RemoveAction( m_actions.begin()->first )) != NO_ERROR)
00203 break;
00204 }
00205
00206 return ec;
00207 }
00208 protected:
00211 ErrCode
00212 adjustLayout(void) const
00213 {
00214 ErrCode ec = HError::NoError();
00215
00216 if (IsValid())
00217 {
00218 if (GI_LayoutReLayout(m_hMe) != S_OK)
00219 ec = HError::Set(ERR_API_ERROR, __FILE__, __LINE__);
00220 }
00221 else
00222 ec = HError::Set(ERR_BAD_WINDOW, __FILE__, __LINE__);
00223
00224 return ec;
00225 }
00226
00227
00228
00229 public:
00232 inline int32 GetActionCount(void) const
00233 { return m_actions.GetSize(); }
00234
00235
00236
00237 public:
00240 inline bool HasID(int32 id) const
00241 { return (m_id == id); }
00242 };
00243
00244 typedef HPanelItem * HPanelItemPtr;
00251 class HPanel : public HID,
00252 public HWidget
00253 {
00254 typedef HWidget base_class;
00255 static StringPtr ClassName(void) { return "HPanel"; }
00256
00257
00258
00259 protected:
00260 HArray<HPanelItemPtr> m_items;
00261
00262
00263
00264 public:
00265 HPanel(int32 id = 0) : HID(id), HWidget()
00266 { }
00267
00268 virtual
00269 ~HPanel(void)
00270 { Destroy(); }
00271
00272
00273
00274 protected:
00275 BEGIN_MSG_MAP("HPanel")
00276 CHAIN_MAP( base_class )
00277 END_MSG_MAP
00278
00279
00280
00281 public:
00290 ErrCode
00291 AddItem(int32 id, StringPtr pstrTitle, HPanelItemPtr & pItem)
00292 {
00293 ErrCode ec = HError::NoError();
00294
00295 pItem = NULL;
00296
00297 try
00298 {
00299 if (!IsValid())
00300 HError::Throw(ERR_NOT_INITIALIZED, __FILE__, __LINE__);
00301
00302 pItem = new HPanelItem;
00303 ASSERT_PTR( pItem );
00304
00305 if ((ec = pItem->Create(m_hMe, id, pstrTitle)) != NO_ERROR)
00306 throw HError::GetLastError();
00307
00308 if ((ec = m_items.Append(pItem)) != NO_ERROR)
00309 throw HError::GetLastError();
00310
00311 DEBUG_LOG( "HPanel[%p]::AddItem() => added item #%ld \"%s\".\n",
00312 this, id, STR_SAFE(pstrTitle));
00313
00314 Smudge();
00315 }
00316 catch (const std::exception & e)
00317 {
00318 DEBUG_LOG("HPanel[%p]::AddItem() => caught %s\n", this, e.what());
00319 if ((ec = ErrCode( HError::GetLastError() )) == NO_ERROR)
00320 ec = HError::Set(ERR_STL_EXCEPTION, __FILE__, __LINE__);
00321
00322 if (GOOD_PTR(pItem))
00323 {
00324 delete pItem;
00325 pItem = NULL;
00326 }
00327 }
00328
00329 return ec;
00330 }
00340 ErrCode
00341 Create(HANDLE hParent, StringPtr pstrName,
00342 HRect * prBounds = NULL, uint32 uStyle = 0)
00343 {
00344 ErrCode ec = HError::NoError();
00345
00346 if (NULL_HND(hParent))
00347 ec = HError::Set(ERR_BAD_PARAMETER, __FILE__, __LINE__);
00348 else if (IsValid())
00349 ec = HError::Set(ERR_DUPLICATE, __FILE__, __LINE__);
00350 else
00351 {
00352 int32 nX, nY,
00353 nXDim, nYDim;
00354
00355 if (NULL_PTR(prBounds) || prBounds->IsEmpty())
00356 nX = nY = nXDim = nYDim = 0;
00357 else
00358 {
00359 nX = prBounds->x1;
00360 nY = prBounds->y1;
00361 nXDim = prBounds->GetWidth();
00362 nYDim = prBounds->GetHeight();
00363 }
00364
00365 m_hMe = GI_CreateWidgetPanel(hParent, TEXT(pstrName),
00366 nX, nY, nXDim, nYDim,
00367 uStyle, 0);
00368 if (NULL_HND(m_hMe))
00369 ec = HError::Set(ERR_API_ERROR, __FILE__, __LINE__);
00370 else
00371 {
00372 HRESULT hr;
00373
00374 DEBUG_LOG( "HPanel[%p]::Create() => m_hMe = 0x%08lX\n",
00375 this, int32(m_hMe));
00376
00377 hr = GI_WidgetSetProperty( m_hMe,
00378 reinterpret_cast<fpProperty>( GI_WidgetPanelPropertySet ),
00379 PROP_COLOR_CAPTION_FILL, 0x00C1C1C1,
00380 PROP_COLOR_FILL, 0x00E3E2E2,
00381 PROP_COLOR_CAPTION_TEXT, 0x002C2C2C,
00382 PROP_COLOR_FRAME, 0x00C1C1C1,
00383 0, 0);
00384 DEBUG_CHECK(hr == S_OK);
00385
00386
00387
00388
00389 ec = enableMessages();
00390 }
00391 }
00392
00393 return ec;
00394 }
00400 ErrCode
00401 Destroy(void)
00402 {
00403 (void) HError::NoError();
00404
00405 #if __DEBUG__
00406 if (m_items.IsNotEmpty())
00407 {
00408 HArray<HPanelItemPtr>::const_iterator it;
00409
00410 DEBUG_LOG("HPanel::Destroy() => deleting %lu items\n", m_items.GetSize());
00411
00412 for (it = m_items.begin(); it != m_items.end(); ++it)
00413 ASSERT_PTR( *it );
00414 }
00415 #endif
00416
00417
00418
00419 while (m_items.IsNotEmpty())
00420 {
00421 delete m_items.back();
00422 m_items.pop_back();
00423 }
00424
00425 return base_class::Destroy();
00426 }
00427
00428
00429
00433 HPanelItem * GetItem(int32 id) const
00434 {
00435 HArray<HPanelItemPtr>::const_iterator it;
00436
00437 it = find_if(m_items.begin(), m_items.end(),
00438 std::bind2nd(std::mem_fun(&HPanelItem::HasID), id));
00439
00440 DEBUG_LOG( "HPanel::GetItem(%ld) =>%sFOUND\n",
00441 id, ((it == m_items.end()) ? " NOT " : " "));
00442
00443 return (it != m_items.end()) ? *it : NULL;
00444 }
00447 inline uint32 GetItemCount(void) const
00448 { return m_items.GetSize(); }
00452 inline HPanelItem * GetNthItem(uint32 udx) const
00453 { return (udx < GetItemCount()) ? m_items[udx] : NULL; }
00458 ErrCode SetHeight(int32 id, int32 nHeight)
00459 {
00460 ErrCode ec = HError::NoError();
00461 HPanelItem * pItem = GetItem(id);
00462
00463 if (!IsValid())
00464 ec = HError::Set(ERR_BAD_WINDOW, __FILE__, __LINE__);
00465 else if (NULL_PTR(pItem) || nHeight < 0)
00466 ec = HError::Set(ERR_BAD_PARAMETER, __FILE__, __LINE__);
00467 else if (GI_LayoutSetItemSize(m_hMe, pItem->GetHandle(), nHeight) != S_OK)
00468 ec = HError::Set(ERR_API_ERROR, __FILE__, __LINE__);
00469
00470 return ec;
00471 }
00476 ErrCode SetFont(const HFont & font, int32 nPoints)
00477 {
00478 ErrCode ec = HError::NoError();
00479
00480 if (IsValid() &&
00481 font.IsValid() &&
00482 nPoints > 1)
00483 {
00484 GI_widget_static_set_font(m_hMe, font.Get(), nPoints);
00485 }
00486 else
00487 ec = HError::Set(ERR_BAD_PARAMETER, __FILE__, __LINE__);
00488
00489 return ec;
00490 }
00491 };
00492
00493 #endif // HPANEL_H
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530