WindowSkin.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. #include "StdAfx.h"
  2. #include "WindowSkin.h"
  3. ////////////////////CWinButtonSkin//////////////
  4. IMPLEMENT_SERIAL( CWinButtonSkin , CObjectSkin , 1 )
  5. CWinButtonSkin::CWinButtonSkin()
  6. {
  7. m_nSkinType = keWinButtonSkin;
  8. }
  9. CWinButtonSkin::CWinButtonSkin( CString strName , int nWinButtonType ) : CObjectSkin( strName,keWinButtonSkin ) , m_nWinButtonType( nWinButtonType )
  10. {
  11. }
  12. CWinButtonSkin::~CWinButtonSkin()
  13. {
  14. }
  15. void CWinButtonSkin::Serialize( CArchive & ar )
  16. {
  17. CObjectSkin::Serialize( ar );
  18. if ( ar.IsStoring() )
  19. {
  20. ar << m_nWinButtonType;
  21. for ( int i = 0 ; i < keWinButtonStateSize ; i ++ )
  22. ar.Write( &m_iamgeButton[i],sizeof( SkinImageRect ) );
  23. }
  24. else
  25. {
  26. ar >> m_nWinButtonType;
  27. for ( int i = 0 ; i < keWinButtonStateSize ; i ++ )
  28. ar.Read( &m_iamgeButton[i],sizeof( SkinImageRect ) );
  29. }
  30. }
  31. void CWinButtonSkin::DrawButton( CDC * pDC , CRect rtDest , int nStateButton )
  32. {
  33. if ( nStateButton < 0 || nStateButton > keWinButtonStateSize )
  34. {
  35. nStateButton = 0;
  36. }
  37. DrawImageRect( pDC,rtDest,m_iamgeButton[nStateButton] );
  38. }
  39. ////////////////////////////////////////////////
  40. IMPLEMENT_SERIAL( CWindowSkin , CObjectSkin , 1 )
  41. CWindowSkin::CWindowSkin( void )
  42. {
  43. m_nSkinType = keWindowSkin;
  44. m_rtMargins = CRect( 12,45,12,25 );
  45. ::ZeroMemory( &m_imageBackground,sizeof( m_imageBackground ) );
  46. }
  47. CWindowSkin::CWindowSkin( CString strName ) : CObjectSkin( strName,keWindowSkin )
  48. {
  49. m_rtMargins = CRect( 12,45,12,25 );
  50. m_bSkinClient = TRUE;
  51. ::ZeroMemory( &m_imageBackground,sizeof( m_imageBackground ) );
  52. }
  53. CWindowSkin::~CWindowSkin( void )
  54. {
  55. }
  56. void CWindowSkin::Serialize( CArchive & ar )
  57. {
  58. CObjectSkin::Serialize( ar );
  59. if ( ar.IsStoring() )
  60. {
  61. ar.Write( &m_frameActive,sizeof( m_frameActive ) );
  62. ar.Write( &m_frameInactive,sizeof( m_frameInactive ) );
  63. ar.Write( &m_skinMenuBar,sizeof( m_skinMenuBar ) );
  64. ar.Write( &m_imageBackground,sizeof( m_imageBackground ) );
  65. ar << m_bSkinClient << m_colorBack << m_rtMargins;
  66. int nObjectSkin = ( int ) m_arrayChildrens.GetSize();
  67. ar.Write( &nObjectSkin,sizeof( nObjectSkin ) );
  68. for ( int i = 0 ; i < nObjectSkin ; i++ )
  69. {
  70. CObjectSkin * pObject = m_arrayChildrens.GetAt( i );
  71. int nType = pObject->GetSkinType();
  72. ar.Write( &nType,sizeof( nType ) );
  73. pObject->Serialize( ar );
  74. }
  75. }
  76. else
  77. {
  78. ar.Read( &m_frameActive,sizeof( m_frameActive ) );
  79. ar.Read( &m_frameInactive,sizeof( m_frameInactive ) );
  80. ar.Read( &m_skinMenuBar,sizeof( m_skinMenuBar ) );
  81. ar.Read( &m_imageBackground,sizeof( m_imageBackground ) );
  82. ar >> m_bSkinClient >> m_colorBack >> m_rtMargins;
  83. int nObjectSkin = 0;
  84. ar.Read( &nObjectSkin,sizeof( nObjectSkin ) );
  85. for ( int i = 0 ; i < nObjectSkin ; i++ )
  86. {
  87. CObjectSkin * pObject = NULL;
  88. int nType = keUnknowSkin;
  89. ar.Read( &nType,sizeof( nType ) );
  90. if ( nType == keWinButtonSkin )
  91. {
  92. pObject = new CWinButtonSkin;
  93. pObject->SetParent( this );
  94. pObject->Serialize( ar );
  95. }
  96. else
  97. {
  98. }
  99. m_arrayChildrens.Add( pObject );
  100. }
  101. }
  102. }
  103. void CWindowSkin::CalcPartsRect( CRect rtDest )
  104. {
  105. if ( m_rtWindow == rtDest )
  106. {
  107. return;
  108. }
  109. else
  110. {
  111. m_rtWindow = rtDest;
  112. }
  113. m_rectParts[SKINPART_TOP_LEFT].left = rtDest.left;
  114. m_rectParts[SKINPART_TOP_LEFT].top = rtDest.top;
  115. m_rectParts[SKINPART_TOP_LEFT].right = rtDest.left + m_rtMargins.left;
  116. m_rectParts[SKINPART_TOP_LEFT].bottom = rtDest.top + m_rtMargins.top;
  117. m_rectParts[SKINPART_TOP].left = rtDest.left + m_rtMargins.left;
  118. m_rectParts[SKINPART_TOP].top = rtDest.top;
  119. m_rectParts[SKINPART_TOP].right = rtDest.right - m_rtMargins.right;
  120. m_rectParts[SKINPART_TOP].bottom = rtDest.top + m_rtMargins.top;
  121. m_rectParts[SKINPART_TOP_BORDER] = m_rectParts[SKINPART_TOP];
  122. m_rectParts[SKINPART_TOP_BORDER].bottom = m_rectParts[SKINPART_TOP_BORDER].top + m_rtMargins.bottom;
  123. m_rectParts[SKINPART_TOP_RIGHT].left = rtDest.right - m_rtMargins.right;
  124. m_rectParts[SKINPART_TOP_RIGHT].top = rtDest.top;
  125. m_rectParts[SKINPART_TOP_RIGHT].right = rtDest.right;
  126. m_rectParts[SKINPART_TOP_RIGHT].bottom = rtDest.top + m_rtMargins.top;
  127. m_rectParts[SKINPART_LEFT].left = rtDest.left;
  128. m_rectParts[SKINPART_LEFT].top = rtDest.top + m_rtMargins.top;
  129. m_rectParts[SKINPART_LEFT].right = rtDest.left + m_rtMargins.left;
  130. m_rectParts[SKINPART_LEFT].bottom = rtDest.bottom - m_rtMargins.bottom;
  131. m_rectParts[SKINPART_RIGHT].left = rtDest.right - m_rtMargins.right;
  132. m_rectParts[SKINPART_RIGHT].top = rtDest.top + m_rtMargins.top;
  133. m_rectParts[SKINPART_RIGHT].right = rtDest.right;
  134. m_rectParts[SKINPART_RIGHT].bottom = rtDest.bottom - m_rtMargins.bottom;
  135. m_rectParts[SKINPART_BOTTOM_LEFT].left = rtDest.left;
  136. m_rectParts[SKINPART_BOTTOM_LEFT].top = rtDest.bottom - m_rtMargins.bottom;
  137. m_rectParts[SKINPART_BOTTOM_LEFT].right = rtDest.left + m_rtMargins.left;
  138. m_rectParts[SKINPART_BOTTOM_LEFT].bottom = rtDest.bottom;
  139. m_rectParts[SKINPART_BOTTOM].left = rtDest.left + m_rtMargins.left;
  140. m_rectParts[SKINPART_BOTTOM].top = rtDest.bottom - m_rtMargins.bottom;
  141. m_rectParts[SKINPART_BOTTOM].right = rtDest.right - m_rtMargins.right;
  142. m_rectParts[SKINPART_BOTTOM].bottom = rtDest.bottom;
  143. m_rectParts[SKINPART_BOTTOM_RIGHT].left = rtDest.right - m_rtMargins.right;
  144. m_rectParts[SKINPART_BOTTOM_RIGHT].top = rtDest.bottom - m_rtMargins.bottom;
  145. m_rectParts[SKINPART_BOTTOM_RIGHT].right = rtDest.right;
  146. m_rectParts[SKINPART_BOTTOM_RIGHT].bottom = rtDest.bottom;
  147. CalcButtonRect( rtDest );
  148. }
  149. void CWindowSkin::CalcButtonRect( CRect rtDest )
  150. {
  151. CObjectSkin * pObject = NULL;
  152. for ( int i = 0 ; i < m_arrayChildrens.GetSize() ; i++ )
  153. {
  154. pObject = m_arrayChildrens.GetAt( i );
  155. if ( pObject->GetSkinType() == keWinButtonSkin )
  156. {
  157. CWinButtonSkin * pWinButton = ( CWinButtonSkin * ) pObject;
  158. pObject->SetParent( this );
  159. pObject->CalcOffset();
  160. if ( pWinButton->GetWinButtonType() == keClose )
  161. m_rtButtons[SKINBUTTON_CLOSE] = pWinButton->CalcPosition( rtDest );
  162. else if ( pWinButton->GetWinButtonType() == keMax )
  163. m_rtButtons[SKINBUTTON_MAX] = pWinButton->CalcPosition( rtDest );
  164. else if ( pWinButton->GetWinButtonType() == keMin )
  165. m_rtButtons[SKINBUTTON_MIN] = pWinButton->CalcPosition( rtDest );
  166. else if ( pWinButton->GetWinButtonType() == keHelp )
  167. m_rtButtons[SKINBUTTON_HELP] = pWinButton->CalcPosition( rtDest );
  168. else if ( pWinButton->GetWinButtonType() == keSysMenu )
  169. m_rtButtons[SKINBUTTON_SYSTEM] = pWinButton->CalcPosition( rtDest );
  170. }
  171. }
  172. }
  173. void CWindowSkin::SetMargins( const SkinMargins & margins )
  174. {
  175. m_rtMargins = margins;
  176. }
  177. void CWindowSkin::SetMargins( int left , int top , int right , int bottom )
  178. {
  179. m_rtMargins.left = left;
  180. m_rtMargins.top = top;
  181. m_rtMargins.right = right;
  182. m_rtMargins.bottom = bottom;
  183. }
  184. SkinMargins CWindowSkin::GetMargins()
  185. {
  186. return m_rtMargins;
  187. }
  188. BOOL CWindowSkin::DrawFrame( CDC * pDC , CRect rtDest , BOOL bActive )
  189. {
  190. CRect rtMargins = m_rtMargins;
  191. CRect rtParts[4];
  192. rtParts[0].left = rtDest.left + rtMargins.left;
  193. rtParts[0].top = rtDest.top;
  194. rtParts[0].right = rtDest.right - rtMargins.right;
  195. rtParts[0].bottom = rtDest.top + rtMargins.top;
  196. rtParts[1].left = rtDest.left;
  197. rtParts[1].top = rtDest.top ;
  198. rtParts[1].right = rtDest.left + rtMargins.left;
  199. rtParts[1].bottom = rtDest.bottom;
  200. rtParts[2].left = rtDest.right - rtMargins.right;
  201. rtParts[2].top = rtDest.top ;
  202. rtParts[2].right = rtDest.right;
  203. rtParts[2].bottom = rtDest.bottom;
  204. rtParts[3].left = rtDest.left + rtMargins.left;
  205. rtParts[3].top = rtDest.bottom - rtMargins.bottom;
  206. rtParts[3].right = rtDest.right - rtMargins.right;
  207. rtParts[3].bottom = rtDest.bottom;
  208. if ( bActive )
  209. {
  210. TransDrawImageSection( pDC,rtParts[0],m_frameActive.imageTop,RGB( 255,0,255 ) );
  211. TransDrawImageSection( pDC,rtParts[1],m_frameActive.imageLeft,RGB( 255,0,255 ) );
  212. TransDrawImageSection( pDC,rtParts[2],m_frameActive.imageRight,RGB( 255,0,255 ) );
  213. TransDrawImageSection( pDC,rtParts[3],m_frameActive.imageBottom,RGB( 255,0,255 ) );
  214. }
  215. else
  216. {
  217. DrawImageSection( pDC,rtParts[0],m_frameActive.imageTop );
  218. DrawImageSection( pDC,rtParts[1],m_frameActive.imageLeft );
  219. DrawImageSection( pDC,rtParts[2],m_frameActive.imageRight );
  220. DrawImageSection( pDC,rtParts[3],m_frameActive.imageBottom );
  221. }
  222. return true;
  223. }
  224. BOOL CWindowSkin::DrawLeft( CDC * pDC , CRect rtWindow , BOOL bActive )
  225. {
  226. CRect rtMargins = m_rtMargins;
  227. CRect rtParts;
  228. rtParts.left = rtWindow.left;
  229. rtParts.top = rtWindow.top ;
  230. rtParts.right = rtWindow.left + rtMargins.left;
  231. rtParts.bottom = rtWindow.bottom;
  232. CMemDC dcMen ( pDC,&rtParts );
  233. if ( bActive )
  234. {
  235. return TransDrawImageSection( &dcMen,rtParts,m_frameActive.imageLeft,RGB( 255,0,255 ) );
  236. }
  237. else
  238. {
  239. return DrawImageSection( &dcMen,rtParts,m_frameActive.imageLeft );
  240. }
  241. }
  242. BOOL CWindowSkin::DrawRight( CDC * pDC , CRect rtWindow , BOOL bActive )
  243. {
  244. CRect rtMargins = m_rtMargins;
  245. CRect rtParts;
  246. rtParts.left = rtWindow.right - rtMargins.right;
  247. rtParts.top = rtWindow.top ;
  248. rtParts.right = rtWindow.right;
  249. rtParts.bottom = rtWindow.bottom;
  250. CMemDC dcMen ( pDC,&rtParts );
  251. if ( bActive )
  252. {
  253. return TransDrawImageSection( &dcMen,rtParts,m_frameActive.imageRight,RGB( 255,0,255 ) );
  254. }
  255. else
  256. {
  257. return DrawImageSection( &dcMen,rtParts,m_frameActive.imageRight );
  258. }
  259. }
  260. BOOL CWindowSkin::DrawTop( CDC * pDC , CRect rtWindow , BOOL bActive )
  261. {
  262. CRect rtMargins = m_rtMargins;
  263. CRect rtParts;
  264. rtParts.left = rtWindow.left + rtMargins.left;
  265. rtParts.top = rtWindow.top;
  266. rtParts.right = rtWindow.right - rtMargins.right;
  267. rtParts.bottom = rtWindow.top + rtMargins.top;
  268. CMemDC dcMen ( pDC,&rtParts );
  269. if ( bActive )
  270. {
  271. return TransDrawImageSection( &dcMen,rtParts,m_frameActive.imageTop,RGB( 255,0,255 ) );
  272. }
  273. else
  274. {
  275. return DrawImageSection( &dcMen,rtParts,m_frameActive.imageTop );
  276. }
  277. }
  278. BOOL CWindowSkin::DrawBottom( CDC * pDC , CRect rtWindow , BOOL bActive )
  279. {
  280. CRect rtMargins = m_rtMargins;
  281. CRect rtParts;
  282. rtParts.left = rtWindow.left + rtMargins.left;
  283. rtParts.top = rtWindow.bottom - rtMargins.bottom;
  284. rtParts.right = rtWindow.right - rtMargins.right;
  285. rtParts.bottom = rtWindow.bottom;
  286. CMemDC dcMen ( pDC,&rtParts );
  287. if ( bActive )
  288. {
  289. return TransDrawImageSection( &dcMen,rtParts,m_frameActive.imageBottom,RGB( 255,0,255 ) );
  290. }
  291. else
  292. {
  293. return DrawImageSection( &dcMen,rtParts,m_frameActive.imageBottom );
  294. }
  295. }
  296. HRGN CWindowSkin::GetRgn( CDC * pDC , CRect rtDest )
  297. {
  298. if ( !pDC || rtDest.IsRectEmpty() )
  299. {
  300. return NULL;
  301. }
  302. CDC memDC;
  303. memDC.CreateCompatibleDC( pDC );
  304. CSkinBitmap * bmp = new CSkinBitmap;
  305. bmp->CreateCompatibleBitmap( pDC,rtDest.right,rtDest.bottom );
  306. CBitmap * pOld = memDC.SelectObject( bmp );
  307. CRect rtMargins = m_rtMargins;
  308. CRect rtParts;
  309. rtParts.left = rtDest.left + rtMargins.left;
  310. rtParts.top = rtDest.top;
  311. rtParts.right = rtDest.right - rtMargins.right;
  312. rtParts.bottom = rtDest.top + rtMargins.top;
  313. DrawImageSection( &memDC,rtParts,m_frameActive.imageTop );
  314. rtParts.left = rtDest.right - rtMargins.right;
  315. rtParts.top = rtDest.top ;
  316. rtParts.right = rtDest.right;
  317. rtParts.bottom = rtDest.bottom;
  318. DrawImageSection( &memDC,rtParts,m_frameActive.imageRight );
  319. rtParts.left = rtDest.left;
  320. rtParts.top = rtDest.top ;
  321. rtParts.right = rtDest.left + rtMargins.left;
  322. rtParts.bottom = rtDest.bottom;
  323. DrawImageSection( &memDC,rtParts,m_frameActive.imageLeft );
  324. rtParts.left = rtDest.left + rtMargins.left;
  325. rtParts.top = rtDest.bottom - rtMargins.bottom;
  326. rtParts.right = rtDest.right - rtMargins.right;
  327. rtParts.bottom = rtDest.bottom;
  328. DrawImageSection( &memDC,rtParts,m_frameActive.imageBottom );
  329. //rgn.CreateRectRgn( 0, 0, rtDest.Width(), rtDest.Height() );
  330. HRGN hrgn = bmp->CreateRgnFromFile( RGB( 255,0,255 ) );
  331. memDC.SelectObject( pOld );
  332. memDC.DeleteDC();
  333. bmp->DeleteObject();
  334. if ( bmp )
  335. {
  336. delete bmp;
  337. }
  338. return hrgn;
  339. }
  340. void CWindowSkin::DrawBackground( CDC * pDC , CRect rtDest )
  341. {
  342. DrawImageRect( pDC,rtDest,m_imageBackground );
  343. }
  344. void CWindowSkin::DrawCaption( CDC * pDC , CRect rtDest , int nStateButton )
  345. {
  346. }
  347. void CWindowSkin::DrawButton( CDC * pDC , CRect rtParent , int nStateButton )
  348. {
  349. CObjectSkin * pObject = NULL;
  350. for ( int i = 0 ; i < m_arrayChildrens.GetSize() ; i++ )
  351. {
  352. pObject = m_arrayChildrens.GetAt( i );
  353. CRect rtPos;
  354. if ( pObject->GetSkinType() == keWinButtonSkin )
  355. {
  356. CWinButtonSkin * pSkinButton = ( CWinButtonSkin * ) pObject;
  357. pSkinButton->CalcOffset();
  358. rtPos = pSkinButton->CalcPosition( rtParent );
  359. if ( pSkinButton->GetWinButtonType() == keMax )
  360. pSkinButton->DrawButton( pDC,rtPos,nStateButton );
  361. else if ( pSkinButton->GetWinButtonType() == keClose )
  362. pSkinButton->DrawButton( pDC,rtPos,nStateButton );
  363. else if ( pSkinButton->GetWinButtonType() == keSysMenu )
  364. pSkinButton->DrawButton( pDC,rtPos,nStateButton );
  365. else if ( pSkinButton->GetWinButtonType() == keMin )
  366. pSkinButton->DrawButton( pDC,rtPos,nStateButton );
  367. else if ( pSkinButton->GetWinButtonType() == keHelp )
  368. pSkinButton->DrawButton( pDC,rtPos,nStateButton );
  369. else if ( pSkinButton->GetWinButtonType() == keRestore )
  370. pSkinButton->DrawButton( pDC,rtPos,nStateButton );
  371. }
  372. }
  373. }
  374. void CWindowSkin::DrawMaxButton( CDC * pDC , int nStateButton )
  375. {
  376. CObjectSkin * pObject = NULL;
  377. for ( int i = 0 ; i < m_arrayChildrens.GetSize() ; i++ )
  378. {
  379. pObject = m_arrayChildrens.GetAt( i );
  380. if ( pObject->GetSkinType() == keWinButtonSkin )
  381. {
  382. CWinButtonSkin * pSkinButton = ( CWinButtonSkin * ) pObject;
  383. if ( pSkinButton->GetWinButtonType() == keMax )
  384. pSkinButton->DrawButton( pDC,m_rtButtons[keMax],nStateButton );
  385. }
  386. }
  387. }
  388. void CWindowSkin::DrawMinButton( CDC * pDC , int nStateButton )
  389. {
  390. CObjectSkin * pObject = NULL;
  391. for ( int i = 0 ; i < m_arrayChildrens.GetSize() ; i++ )
  392. {
  393. pObject = m_arrayChildrens.GetAt( i );
  394. if ( pObject->GetSkinType() == keWinButtonSkin )
  395. {
  396. CWinButtonSkin * pSkinButton = ( CWinButtonSkin * ) pObject;
  397. if ( pSkinButton->GetWinButtonType() == keMin )
  398. pSkinButton->DrawButton( pDC,m_rtButtons[keMin],nStateButton );
  399. }
  400. }
  401. }
  402. void CWindowSkin::DrawCloseButton( CDC * pDC , int nStateButton )
  403. {
  404. CObjectSkin * pObject = NULL;
  405. for ( int i = 0 ; i < m_arrayChildrens.GetSize() ; i++ )
  406. {
  407. pObject = m_arrayChildrens.GetAt( i );
  408. if ( pObject->GetSkinType() == keWinButtonSkin )
  409. {
  410. CWinButtonSkin * pSkinButton = ( CWinButtonSkin * ) pObject;
  411. if ( pSkinButton->GetWinButtonType() == keClose )
  412. pSkinButton->DrawButton( pDC,m_rtButtons[keClose],nStateButton );
  413. }
  414. }
  415. }
  416. void CWindowSkin::DrawRestoreButton( CDC * pDC , int nStateButton )
  417. {
  418. CObjectSkin * pObject = NULL;
  419. for ( int i = 0 ; i < m_arrayChildrens.GetSize() ; i++ )
  420. {
  421. pObject = m_arrayChildrens.GetAt( i );
  422. if ( pObject->GetSkinType() == keWinButtonSkin )
  423. {
  424. CWinButtonSkin * pSkinButton = ( CWinButtonSkin * ) pObject;
  425. if ( pSkinButton->GetWinButtonType() == keRestore )
  426. pSkinButton->DrawButton( pDC,m_rtButtons[keRestore],nStateButton );
  427. }
  428. }
  429. }
  430. void CWindowSkin::DrawMaxButton( CDC * pDC , CRect rtParent , int nStateButton )
  431. {
  432. CObjectSkin * pObject = NULL;
  433. CRect rtPos ;
  434. for ( int i = 0 ; i < m_arrayChildrens.GetSize() ; i++ )
  435. {
  436. pObject = m_arrayChildrens.GetAt( i );
  437. if ( pObject->GetSkinType() == keWinButtonSkin )
  438. {
  439. CWinButtonSkin * pSkinButton = ( CWinButtonSkin * ) pObject;
  440. if ( pSkinButton->GetWinButtonType() == keMax )
  441. {
  442. pSkinButton->CalcOffset();
  443. rtPos = pSkinButton->CalcPosition( rtParent );
  444. pSkinButton->DrawButton( pDC,rtPos,nStateButton );
  445. return;
  446. }
  447. }
  448. }
  449. }
  450. void CWindowSkin::DrawMinButton( CDC * pDC , CRect rtParent , int nStateButton )
  451. {
  452. CObjectSkin * pObject = NULL;
  453. CRect rtPos ;
  454. for ( int i = 0 ; i < m_arrayChildrens.GetSize() ; i++ )
  455. {
  456. pObject = m_arrayChildrens.GetAt( i );
  457. if ( pObject->GetSkinType() == keWinButtonSkin )
  458. {
  459. CWinButtonSkin * pSkinButton = ( CWinButtonSkin * ) pObject;
  460. if ( pSkinButton->GetWinButtonType() == keMin )
  461. {
  462. pSkinButton->CalcOffset();
  463. rtPos = pSkinButton->CalcPosition( rtParent );
  464. pSkinButton->DrawButton( pDC,rtPos,nStateButton );
  465. return;
  466. }
  467. }
  468. }
  469. }
  470. void CWindowSkin::DrawCloseButton( CDC * pDC , CRect rtParent , int nStateButton )
  471. {
  472. CObjectSkin * pObject = NULL;
  473. CRect rtPos ;
  474. for ( int i = 0 ; i < m_arrayChildrens.GetSize() ; i++ )
  475. {
  476. pObject = m_arrayChildrens.GetAt( i );
  477. if ( pObject->GetSkinType() == keWinButtonSkin )
  478. {
  479. CWinButtonSkin * pSkinButton = ( CWinButtonSkin * ) pObject;
  480. if ( pSkinButton->GetWinButtonType() == keClose )
  481. {
  482. pSkinButton->CalcOffset();
  483. rtPos = pSkinButton->CalcPosition( rtParent );
  484. pSkinButton->DrawButton( pDC,rtPos,nStateButton );
  485. return;
  486. }
  487. }
  488. }
  489. }
  490. void CWindowSkin::DrawRestoreButton( CDC * pDC , CRect rtParent , int nStateButton )
  491. {
  492. CObjectSkin * pObject = NULL;
  493. CRect rtPos ;
  494. for ( int i = 0 ; i < m_arrayChildrens.GetSize() ; i++ )
  495. {
  496. pObject = m_arrayChildrens.GetAt( i );
  497. if ( pObject->GetSkinType() == keWinButtonSkin )
  498. {
  499. CWinButtonSkin * pSkinButton = ( CWinButtonSkin * ) pObject;
  500. if ( pSkinButton->GetWinButtonType() == keRestore )
  501. {
  502. pSkinButton->CalcOffset();
  503. rtPos = pSkinButton->CalcPosition( rtParent );
  504. pSkinButton->DrawButton( pDC,rtPos,nStateButton );
  505. return;
  506. }
  507. }
  508. }
  509. }
  510. UINT CWindowSkin::HitTest( CPoint pt )
  511. {
  512. if ( m_rtButtons[SKINBUTTON_SYSTEM].PtInRect( pt ) )
  513. {
  514. return HTSYSMENU;
  515. }
  516. else if ( m_rtButtons[SKINBUTTON_HELP].PtInRect( pt ) )
  517. {
  518. return HTHELP;
  519. }
  520. else if ( m_rtButtons[SKINBUTTON_MIN].PtInRect( pt ) )
  521. {
  522. return HTMINBUTTON;
  523. }
  524. else if ( m_rtButtons[SKINBUTTON_MAX].PtInRect( pt ) )
  525. {
  526. return HTMAXBUTTON;
  527. }
  528. else if ( m_rtButtons[SKINBUTTON_CLOSE].PtInRect( pt ) )
  529. {
  530. return HTCLOSE;
  531. }
  532. else if ( m_rectParts[SKINPART_TOP_LEFT].PtInRect( pt ) )
  533. {
  534. return HTTOPLEFT;
  535. }
  536. else if ( m_rectParts[SKINPART_TOP_BORDER].PtInRect( pt ) )
  537. {
  538. return HTTOP;
  539. }
  540. else if ( m_rectParts[SKINPART_TOP].PtInRect( pt ) )
  541. {
  542. return HTCAPTION;
  543. }
  544. else if ( m_rectParts[SKINPART_TOP_RIGHT].PtInRect( pt ) )
  545. {
  546. return HTTOPRIGHT;
  547. }
  548. else if ( m_rectParts[SKINPART_LEFT].PtInRect( pt ) )
  549. {
  550. return HTLEFT;
  551. }
  552. else if ( m_rectParts[SKINPART_RIGHT].PtInRect( pt ) )
  553. {
  554. return HTRIGHT;
  555. }
  556. else if ( m_rectParts[SKINPART_BOTTOM_LEFT].PtInRect( pt ) )
  557. {
  558. return HTBOTTOMLEFT;
  559. }
  560. else if ( m_rectParts[SKINPART_BOTTOM].PtInRect( pt ) )
  561. {
  562. return HTBOTTOM;
  563. }
  564. else if ( m_rectParts[SKINPART_BOTTOM_RIGHT].PtInRect( pt ) )
  565. {
  566. return HTBOTTOMRIGHT;
  567. }
  568. else
  569. {
  570. return HTNOWHERE;
  571. }
  572. }
  573. void CWindowSkin::AddWinButton( CWinButtonSkin * pSkinButton )
  574. {
  575. if ( pSkinButton == NULL )
  576. {
  577. return ;
  578. }
  579. pSkinButton->SetParent( this );
  580. m_arrayChildrens.Add( pSkinButton );
  581. }
  582. BOOL CWindowSkin::DeleteWinButton( CString strName )
  583. {
  584. if ( strName.IsEmpty() )
  585. {
  586. return FALSE;
  587. }
  588. CObjectSkin * pObject;
  589. for ( int i = 0 ; i < m_arrayChildrens.GetSize() ; i++ )
  590. {
  591. pObject = m_arrayChildrens.GetAt( i );
  592. if ( pObject->GetSkinType() == keWinButtonSkin )
  593. {
  594. if ( pObject->GetName() == strName )
  595. {
  596. delete ( CWinButtonSkin * ) pObject;
  597. return TRUE;
  598. m_arrayChildrens.RemoveAt( i );
  599. }
  600. }
  601. }
  602. return FALSE;
  603. }
  604. int CWindowSkin::GetButtonCount()
  605. {
  606. return ( int ) m_arrayChildrens.GetSize();
  607. }
  608. CWinButtonSkin * CWindowSkin::FindButton( CString strName )
  609. {
  610. if ( strName.IsEmpty() )
  611. {
  612. return NULL;
  613. }
  614. CObjectSkin * pObject = NULL;
  615. for ( int i = 0 ; i < m_arrayChildrens.GetSize() ; i++ )
  616. {
  617. pObject = m_arrayChildrens.GetAt( i );
  618. if ( pObject->GetSkinType() == keWinButtonSkin )
  619. {
  620. CString strTemp = pObject->GetName();
  621. if ( strTemp == strName )
  622. return ( CWinButtonSkin * ) pObject;
  623. }
  624. }
  625. return NULL;
  626. }
  627. ////////////////////////////////////////////////
  628. IMPLEMENT_SERIAL( CShapeWndSkin , CObjectSkin , 1 )
  629. CShapeWndSkin::CShapeWndSkin( void )
  630. {
  631. m_nSkinType = keWindowSkin;
  632. }
  633. CShapeWndSkin::CShapeWndSkin( CString strName ) : CObjectSkin( strName,keWindowSkin )
  634. {
  635. }
  636. CShapeWndSkin::~CShapeWndSkin( void )
  637. {
  638. }
  639. void CShapeWndSkin::Serialize( CArchive & ar )
  640. {
  641. }