AutoHideBar.cpp 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605
  1. /////////////////////////////////////////////////////////////////////////
  2. //
  3. // CAutoHideBar Version 1.2
  4. //
  5. // Created: Mar 30, 2004
  6. //
  7. /////////////////////////////////////////////////////////////////////////
  8. // Copyright (C) 2004 by Cuick. All rights reserved.
  9. //
  10. // This code is free for personal and commercial use, providing this
  11. // notice remains intact in the source files and all eventual changes are
  12. // clearly marked with comments.
  13. //
  14. // Send bug reports, bug fixes, enhancements, requests, flames, etc. to
  15. // Cuick@163.net
  16. //
  17. // Hint: These classes are intended to be used as base classes. Do not
  18. // simply add your code to these file - instead create a new class
  19. // derived from CDockPageBar classes and put there what you need. See
  20. // CTestBar classes in the demo projects for examples.
  21. // Modify this file only to fix bugs, and don't forget to send me a copy.
  22. /////////////////////////////////////////////////////////////////////////
  23. // Acknowledgements:
  24. //
  25. //////////////////////////////////////////////////////////////////////////
  26. //Updates
  27. //////////////////////////////////////////////////////////////////////////
  28. // Author | Date | Description
  29. //========================================================================
  30. // Tony |2006-09-04 | Bugfixs:
  31. //=======================| 1.add Timer TID_AUTO_HIDE_DELAY to prevent two
  32. //tony__cb@hotmail.com | AHFloatWnds being displayed at the same time.
  33. // | 2.focus switch problems(especially between AHFloatwnd and
  34. // | DockPageBar).
  35. // | 3.frequence screen flash on sizing the DockPageBar.
  36. // | 4.resize the AHFloatWnds with the wider than the mainframe.
  37. // | 5.link problems related with static MFC lib
  38. // | by setting a new compile flag STATIC_MFC_LINK
  39. // | 6.Verify the pWnd's style in CDockPageBar::AddPage function,
  40. // | to make sure pWnd to have the WS_CHILD style, and to avoid
  41. // | the window management disorder in clean up.
  42. // | ------------------------------------------------
  43. // | Improvements and new features:
  44. // | 1.add the slide in/out animation display for AHFloatWnds
  45. // | (the API ::AnimateWindow doesnt work for the self-draw window)
  46. // | 2.make a lot of detail display changes(border,caption bar,...)
  47. // | to have nicer windows
  48. // | 3.add the new docking detection algorithm(accurate docking)
  49. // | just as MS VC2003, but with the limitation that
  50. // | the horizontal docking always has the higher priority.
  51. // | 4.add the support for MDI style Frame
  52. // | 5.rewrite the NcPaint,NcCalClient,OnNcLButtonXXXX,OnNcHitTest part
  53. // | for CDockPageBar to draw the caption(griper),and item tab button
  54. // | in the NcPaint.
  55. // | 6.disable the DragShowContent mode in CSizingControlBar and
  56. // | the OnNcPaint in CDockPageBar when sizing the bar to avoid
  57. // | the dirty & flashy display
  58. #include "stdafx.h"
  59. #include "AutoHideBar.h"
  60. #ifdef _DEBUG
  61. #define new DEBUG_NEW
  62. #undef THIS_FILE
  63. static char THIS_FILE[] = __FILE__;
  64. #endif
  65. /////////////////////////////////////////////////////////////////////////////
  66. // CAHFloatWnd Implementation Start
  67. CAHFloatWnd::CAHFloatWnd()
  68. {
  69. m_font.CreatePointFont(85, "Tahoma");
  70. m_Title = "AutoHideFloatWnd";
  71. m_bCursorInAutoHideBarItem=FALSE;
  72. m_animDispParam.slideStep=0;
  73. m_animDispParam.slideStepCount=0;
  74. m_animDispParam.bInAnimateDisplay=FALSE;
  75. m_animDispParam.timerId=0;
  76. m_activePageItem=NULL;
  77. }
  78. CAHFloatWnd::~CAHFloatWnd()
  79. {
  80. DeleteObject( m_font );
  81. }
  82. BEGIN_MESSAGE_MAP(CAHFloatWnd, CWnd)
  83. //{{AFX_MSG_MAP(CAHFloatWnd)
  84. ON_WM_NCCALCSIZE()
  85. ON_WM_SIZE()
  86. ON_WM_NCPAINT()
  87. ON_WM_NCMOUSEMOVE()
  88. ON_WM_NCHITTEST()
  89. ON_WM_MOUSEACTIVATE()
  90. ON_WM_NCLBUTTONUP()
  91. ON_WM_TIMER()
  92. ON_WM_NCLBUTTONDOWN()
  93. ON_WM_SHOWWINDOW()
  94. ON_WM_MOUSEMOVE()
  95. //}}AFX_MSG_MAP
  96. ON_WM_GETMINMAXINFO()
  97. END_MESSAGE_MAP()
  98. /////////////////////////////////////////////////////////////////////////////
  99. // CAHFloatWnd message handlers
  100. void CAHFloatWnd::GetBorderWidths(DWORD dwStyle,BORDER_WIDTH & borderWidth)
  101. {
  102. switch(dwStyle&0xFF00)
  103. {
  104. case CBRS_LEFT:
  105. {
  106. borderWidth.cx_left=0;
  107. borderWidth.cx_right=::GetSystemMetrics(SM_CXFRAME);
  108. borderWidth.cy_top=2;
  109. borderWidth.cy_bottom=0;
  110. }
  111. break;
  112. case CBRS_RIGHT:
  113. {
  114. borderWidth.cx_left=::GetSystemMetrics(SM_CXFRAME);
  115. borderWidth.cx_right=1;
  116. borderWidth.cy_top=2;
  117. borderWidth.cy_bottom=0;
  118. }
  119. break;
  120. case CBRS_TOP:
  121. {
  122. borderWidth.cx_left=0;
  123. borderWidth.cx_right=1;
  124. borderWidth.cy_top=2;
  125. borderWidth.cy_bottom=3;
  126. }
  127. break;
  128. case CBRS_BOTTOM:
  129. {
  130. borderWidth.cx_left=0;
  131. borderWidth.cx_right=1;
  132. borderWidth.cy_top=2;
  133. borderWidth.cy_bottom=2;
  134. }
  135. break;
  136. default:
  137. {
  138. borderWidth.cx_left=borderWidth.cx_right=borderWidth.cy_top=borderWidth.cy_bottom=0;
  139. }
  140. break;
  141. }
  142. }
  143. void CAHFloatWnd::StartAnimateDisplay( DWORD dwFlag,DWORD dwTime)
  144. {
  145. m_animDispParam.bInAnimateDisplay=TRUE;
  146. m_animDispParam.slideStepCount=max(1,dwTime/50);
  147. if(TID_SLIDE_IN==dwFlag){
  148. m_animDispParam.slideStep=m_animDispParam.slideStepCount-1;
  149. if(m_activePageItem)
  150. GetWindowRect(&(m_activePageItem->m_lastAHFloatWndRect));
  151. KillTimer(TID_AUTO_HIDE_DELAY);
  152. }else{
  153. SetTimer(TID_AUTO_HIDE_DELAY,AUTO_HIDE_DELAY_TIMES, NULL);
  154. m_animDispParam.slideStep=0;
  155. }
  156. //Reset previous animate display timer
  157. if(m_animDispParam.timerId!=0)
  158. KillTimer(m_animDispParam.timerId);
  159. m_animDispParam.timerId=dwFlag;
  160. SetTimer(dwFlag,50,NULL);
  161. }
  162. void CAHFloatWnd::DoSlideStep()
  163. {
  164. CRect rc(m_animDispParam.rect);
  165. switch(m_dwStyle&CBRS_ALIGN_ANY)
  166. {
  167. case CBRS_ALIGN_LEFT:
  168. rc.OffsetRect((m_animDispParam.slideStep + 1)*rc.Width()/m_animDispParam.slideStepCount-rc.Width(),0);
  169. break;
  170. case CBRS_ALIGN_RIGHT:
  171. rc.OffsetRect(rc.Width()-(m_animDispParam.slideStep + 1)*rc.Width()/m_animDispParam.slideStepCount,0);
  172. break;
  173. case CBRS_ALIGN_TOP:
  174. rc.OffsetRect(0,(m_animDispParam.slideStep + 1)*rc.Height()/m_animDispParam.slideStepCount-rc.Height());
  175. break;
  176. case CBRS_ALIGN_BOTTOM:
  177. rc.OffsetRect(0,rc.Height()-(m_animDispParam.slideStep + 1)*rc.Height()/m_animDispParam.slideStepCount);
  178. break;
  179. }
  180. SetWindowPos(NULL, rc.left, rc.top, rc.Width(), rc.Height(),SWP_NOZORDER|SWP_SHOWWINDOW);
  181. Invalidate(FALSE);
  182. }
  183. void CAHFloatWnd::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp)
  184. {
  185. CWnd::OnNcCalcSize(bCalcValidRects, lpncsp);
  186. CRect rc(&lpncsp->rgrc[0]);
  187. BORDER_WIDTH borderWidth;
  188. GetBorderWidths(m_dwStyle,borderWidth);
  189. rc.DeflateRect(-::GetSystemMetrics(SM_CXFRAME),-::GetSystemMetrics(SM_CXFRAME),
  190. -::GetSystemMetrics(SM_CXFRAME),-::GetSystemMetrics(SM_CXFRAME));
  191. rc.DeflateRect(borderWidth.cx_left+1,CAPTION_HEIGHT+borderWidth.cy_top*2+1, borderWidth.cx_right+1,borderWidth.cy_bottom+1);
  192. lpncsp->rgrc[0] = rc;
  193. //Non Clinet coordinate refered to the windows's topleft
  194. m_captionRect.left=borderWidth.cx_left;
  195. m_captionRect.right=m_captionRect.left+rc.Width();
  196. m_captionRect.top=borderWidth.cy_top;
  197. m_captionRect.bottom=m_captionRect.top+CAPTION_HEIGHT;
  198. }
  199. void CAHFloatWnd::OnNcPaint()
  200. {
  201. //CWnd::OnNcPaint();
  202. CWindowDC dc(this);
  203. //Get bounding rect of the client coordinate
  204. CRect rcBar,rect;
  205. GetWindowRect(rcBar);//Screen coordinate
  206. rcBar.OffsetRect (-rcBar.TopLeft ());//Logic coordinate
  207. rect = rcBar;
  208. BORDER_WIDTH borderWidth;
  209. GetBorderWidths(m_dwStyle,borderWidth);
  210. //Draw the flat frame border
  211. //|-----------------------------|
  212. //| |
  213. //| |
  214. //| |
  215. //| |
  216. //|-----------------------------|
  217. //|
  218. //|
  219. //|
  220. rect.right = borderWidth.cx_left;
  221. dc.FillSolidRect(&rect, ::GetSysColor(COLOR_BTNFACE));
  222. //----------------
  223. rect = rcBar;
  224. rect.top = rect.bottom - borderWidth.cy_bottom;
  225. dc.FillSolidRect(&rect, ::GetSysColor(COLOR_BTNFACE));
  226. //|
  227. //|
  228. //|
  229. rect = rcBar;
  230. rect.left = rect.right - borderWidth.cx_right;
  231. dc.FillSolidRect(&rect, ::GetSysColor(COLOR_BTNFACE));
  232. //-----------------
  233. rect=rcBar;
  234. rect.bottom = rect.top + CAPTION_HEIGHT + borderWidth.cy_top*2;
  235. dc.FillSolidRect(&rect, ::GetSysColor(COLOR_BTNFACE));
  236. CRect clientBorderRc=rcBar;
  237. //if (IsHorzDocked())
  238. clientBorderRc.DeflateRect(borderWidth.cx_left,CAPTION_HEIGHT+borderWidth.cy_top*2
  239. ,borderWidth.cx_right+1,borderWidth.cy_bottom+1);
  240. //else
  241. // clientBorderRc.DeflateRect(1,CAPTION_HEIGHT,3,3);
  242. CPen penRect(PS_SOLID, 1, RGB(128,128,128));
  243. HPEN oldPen = (HPEN)dc.SelectObject (&penRect);
  244. dc.MoveTo(clientBorderRc.TopLeft());
  245. dc.LineTo(clientBorderRc.right,clientBorderRc.top);
  246. dc.LineTo(clientBorderRc.right,clientBorderRc.bottom);
  247. dc.LineTo(clientBorderRc.left,clientBorderRc.bottom);
  248. dc.LineTo(clientBorderRc.left,clientBorderRc.top);
  249. dc.SelectObject (oldPen);
  250. //Draw the single border 3D side adage
  251. CPen pen1(PS_SOLID,1,RGB(128,128,128)); //DarkGrey
  252. CPen pen2(PS_SOLID,1,RGB(0,0,0)); //Black
  253. CPen pen3(PS_SOLID,1,RGB(255,255,255)); //White
  254. CPen pen4(PS_SOLID,1,::GetSysColor(COLOR_BTNFACE));//LightGrey
  255. HPEN pOldPen=NULL;
  256. switch(m_dwStyle&0xFF00) // CBRS_ALIGN_ANY|CBRS_BORDER_ANY == 0xFF00
  257. {
  258. case CBRS_TOP:
  259. {
  260. pOldPen = (HPEN)dc.SelectObject (&pen2);
  261. CPoint pt=rcBar.BottomRight();
  262. pt.Offset(-2,-1);
  263. dc.MoveTo(pt);
  264. pt.Offset(1-rcBar.Width(),0);
  265. dc.LineTo(pt);
  266. dc.SelectObject (&pen1);
  267. pt=rcBar.BottomRight();
  268. pt.Offset(-2,-2);
  269. dc.MoveTo(pt);
  270. pt.Offset(1-rcBar.Width(),0);
  271. dc.LineTo(pt);
  272. }
  273. break;
  274. case CBRS_LEFT:
  275. {
  276. pOldPen = (HPEN)dc.SelectObject (&pen2);
  277. CPoint pt=rcBar.BottomRight();
  278. pt.Offset(-1,0);
  279. dc.MoveTo(pt);
  280. pt.Offset(0,-rcBar.Height());
  281. dc.LineTo(pt);
  282. dc.SelectObject (&pen1);
  283. pt=rcBar.BottomRight();
  284. pt.Offset(-2,0);
  285. dc.MoveTo(pt);
  286. pt.Offset(0,-rcBar.Height());
  287. dc.LineTo(pt);
  288. }
  289. break;
  290. case CBRS_BOTTOM:
  291. {
  292. pOldPen = (HPEN)dc.SelectObject (&pen4);
  293. CPoint pt=rcBar.TopLeft();
  294. dc.MoveTo(pt);
  295. pt.Offset(rcBar.Width()-1,0);
  296. dc.LineTo(pt);
  297. dc.SelectObject (&pen3);
  298. pt=rcBar.TopLeft();
  299. pt.Offset(0,1);
  300. dc.MoveTo(pt);
  301. pt.Offset(rcBar.Width()-1,0);
  302. dc.LineTo(pt);
  303. }
  304. break;
  305. case CBRS_RIGHT:
  306. {
  307. pOldPen = (HPEN)dc.SelectObject (&pen4);
  308. CPoint pt=rcBar.TopLeft();
  309. pt.Offset(1,0);
  310. dc.MoveTo(pt);
  311. pt.Offset(0,rcBar.Height()-1);
  312. dc.LineTo(pt);
  313. dc.SelectObject (&pen3);
  314. pt=rcBar.TopLeft();
  315. pt.Offset(2,0);
  316. dc.MoveTo(pt);
  317. pt.Offset(0,rcBar.Height()-1);
  318. dc.LineTo(pt);
  319. }
  320. break;
  321. default:
  322. break;
  323. }
  324. if (pOldPen!=NULL)
  325. dc.SelectObject(pOldPen);
  326. //Draw the caption
  327. CRect gripper = rect;
  328. CRect rcbtn = m_biHide.GetRect();
  329. gripper.DeflateRect(borderWidth.cx_left,borderWidth.cy_top,
  330. borderWidth.cx_right,borderWidth.cy_top);
  331. CDC* pDC = &dc;
  332. HFONT oldFont = (HFONT)pDC->SelectObject (m_font);
  333. int nPrevBkMode = pDC->SetBkMode(TRANSPARENT);
  334. COLORREF crOldText;
  335. if(TRUE == m_isActive) // active state
  336. {
  337. CBrush brush(RGB(62,132,192));
  338. pDC->FillRect(&gripper, &brush);
  339. crOldText = pDC->SetTextColor(RGB(255,255,255));
  340. //2011-10-31 add
  341. DeleteObject( brush );
  342. }
  343. else
  344. {
  345. CPen pen(PS_SOLID, 1, RGB(128,128,128));
  346. HPEN poldPen = (HPEN)pDC->SelectObject (&pen);
  347. // Draw better caption rect
  348. // ------------------------------
  349. //| |
  350. // ------------------------------
  351. // ------------------------------>
  352. CPoint pt=gripper.TopLeft();
  353. pt.Offset(1,0);
  354. pDC->MoveTo (pt);
  355. pDC->LineTo (gripper.right-1 ,gripper.top );
  356. // ------------------------------>
  357. pt=gripper.TopLeft();
  358. pt.Offset(1,gripper.Height());
  359. pDC->MoveTo (pt);
  360. pDC->LineTo (gripper.right-1 ,gripper.bottom );
  361. // ^
  362. // |
  363. // |
  364. pt=gripper.BottomRight();
  365. pt.Offset(-1,-1);
  366. pDC->MoveTo (pt);
  367. pDC->LineTo (gripper.right-1 ,gripper.top);
  368. //^
  369. //|
  370. //|
  371. pt=gripper.BottomRight();
  372. pt.Offset(-gripper.Width(),-1);
  373. pDC->MoveTo(pt);
  374. pDC->LineTo (gripper.left ,gripper.top);
  375. crOldText = pDC->SetTextColor(RGB(0,0,0));
  376. //2011-10-31 add
  377. DeleteObject( pen );
  378. }
  379. gripper.left += 4;
  380. gripper.top += 2;
  381. // Draw caption text
  382. if (!m_Title.IsEmpty())
  383. {
  384. CString sText = m_Title;
  385. int l = sText.GetLength();
  386. int i;
  387. for(i=0;i<10 && pDC->GetTextExtent(sText).cx > (gripper.Width() - 30);i++,l-=2)
  388. sText = sText.Left(l-2);
  389. if(i > 0)
  390. {
  391. sText = sText.Left(l-2);
  392. sText += "...";
  393. }
  394. pDC->TextOut (gripper.left, gripper.top, sText);
  395. }
  396. pDC->SetTextColor (crOldText);
  397. pDC->SetBkMode(nPrevBkMode);
  398. pDC->SelectObject(oldFont);
  399. if(rcBar.Width()<pDC->GetTextExtent(m_Title).cx+17+13)
  400. {
  401. //2011-10-31 add
  402. DeleteObject( penRect );
  403. DeleteObject( pen1 );
  404. DeleteObject( pen2 );
  405. DeleteObject( pen3 );
  406. DeleteObject( pen4 );
  407. DeleteObject( dc );
  408. DeleteObject( pDC );
  409. return;
  410. }
  411. //Draw the hide & close button
  412. CPoint ptOrgBtn;
  413. ptOrgBtn = CPoint(gripper.right - 15, gripper.top);
  414. m_biHide.Move(ptOrgBtn);
  415. m_biHide.Paint(pDC, m_isActive);
  416. ptOrgBtn.x -= 17;
  417. m_stud.Move (ptOrgBtn);
  418. m_stud.Paint(pDC, m_isActive);
  419. //2011-10-31 add
  420. DeleteObject( penRect );
  421. DeleteObject( pen1 );
  422. DeleteObject( pen2 );
  423. DeleteObject( pen3 );
  424. DeleteObject( pen4 );
  425. ReleaseDC( &dc );
  426. ReleaseDC( pDC );
  427. }
  428. void CAHFloatWnd::OnSize(UINT nType, int cx, int cy)
  429. {
  430. CWnd::OnSize(nType, cx, cy);
  431. CWnd* pWnd = GetWindow(GW_CHILD);
  432. if (pWnd != NULL)
  433. {
  434. pWnd->MoveWindow(0, 0, cx, cy);
  435. }
  436. SendMessage(WM_NCPAINT);
  437. }
  438. void CAHFloatWnd::OnNcMouseMove(UINT nHitTest, CPoint point)
  439. {
  440. BOOL bNeedPaint = FALSE;
  441. CPoint pt;
  442. ::GetCursorPos(&pt);
  443. ///////////////////////////////////////////////////////////
  444. // hit hide
  445. BOOL bHit = (OnNcHitTest(pt) == HTHIDE);
  446. BOOL bLButtonDown = (::GetKeyState(VK_LBUTTON) < 0);
  447. BOOL bWasPushed = m_biHide.bPushed;
  448. m_biHide.bPushed = bHit && bLButtonDown;
  449. BOOL bWasRaised = m_biHide.bRaised;
  450. m_biHide.bRaised = bHit && !bLButtonDown;
  451. bNeedPaint |= (m_biHide.bPushed ^ bWasPushed) ||
  452. (m_biHide.bRaised ^ bWasRaised);
  453. ////////////////////////////////////////////////////////////
  454. // hit stud
  455. bHit = (OnNcHitTest(pt) == HTSTUD);
  456. bWasPushed = m_stud.bPushed;
  457. m_stud.bPushed = bHit && bLButtonDown;
  458. bWasRaised = m_stud.bRaised;
  459. m_stud.bRaised = bHit && !bLButtonDown;
  460. bNeedPaint |= (m_stud.bPushed ^ bWasPushed) ||
  461. (m_stud.bRaised ^ bWasRaised);
  462. if (bNeedPaint)
  463. SendMessage(WM_NCPAINT);
  464. m_bCursorInAutoHideBarItem=FALSE;
  465. CWnd::OnNcMouseMove(nHitTest, point);
  466. }
  467. LRESULT CAHFloatWnd::OnNcHitTest(CPoint point)
  468. {
  469. CRect rcBar;
  470. GetWindowRect(rcBar);
  471. LRESULT nRet = CWnd::OnNcHitTest(point);
  472. CRect rc = m_biHide.GetRect();
  473. rc.OffsetRect(rcBar.TopLeft());
  474. if (rc.PtInRect(point))
  475. return HTHIDE;
  476. else
  477. {
  478. if(TRUE == m_biHide.bRaised)
  479. {
  480. m_biHide.bRaised = FALSE;
  481. SendMessage(WM_NCPAINT);
  482. }
  483. }
  484. rc = m_stud.GetRect();
  485. rc.OffsetRect(rcBar.TopLeft());
  486. if (rc.PtInRect(point))
  487. return HTSTUD;
  488. else
  489. {
  490. if(TRUE == m_stud.bRaised)
  491. {
  492. m_stud.bRaised = FALSE;
  493. SendMessage(WM_NCPAINT);
  494. }
  495. }
  496. rc=m_captionRect;
  497. rc.OffsetRect(rcBar.TopLeft());
  498. if(rc.PtInRect(point))
  499. return HTNCCLIENT;
  500. if (m_dwStyle & CBRS_ALIGN_TOP)
  501. nRet = (HTBOTTOM == nRet?nRet: HTNOWHERE);
  502. else if (m_dwStyle & CBRS_ALIGN_BOTTOM)
  503. nRet = (HTTOP == nRet?nRet: HTNOWHERE);
  504. else if (m_dwStyle & CBRS_ALIGN_LEFT)
  505. nRet = (HTRIGHT == nRet?nRet: HTNOWHERE);
  506. else if (m_dwStyle & CBRS_ALIGN_RIGHT)
  507. nRet = (HTLEFT == nRet?nRet: HTNOWHERE);
  508. else
  509. ASSERT(FALSE); // can never happen
  510. return nRet;
  511. }
  512. int CAHFloatWnd::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message)
  513. {
  514. m_isActive = TRUE;
  515. SendMessage(WM_NCPAINT);
  516. SetFocus();
  517. return CWnd::OnMouseActivate(pDesktopWnd, nHitTest, message);
  518. }
  519. void CAHFloatWnd::OnNcLButtonUp(UINT nHitTest, CPoint point)
  520. {
  521. CWnd::OnNcLButtonUp(nHitTest, point);
  522. if (nHitTest == HTHIDE)
  523. {
  524. ShowWindow(SW_HIDE);
  525. m_biHide.bPushed = FALSE;
  526. }
  527. if (nHitTest == HTSTUD)
  528. {
  529. m_stud.bPushed = FALSE;
  530. OnStudClick();
  531. }
  532. }
  533. void CAHFloatWnd::OnStudClick()
  534. {
  535. m_HideItem->Dock ();
  536. }
  537. void CAHFloatWnd::OnTimer(UINT nIDEvent)
  538. {
  539. switch(nIDEvent)
  540. {
  541. case TID_AUTO_HIDE_DELAY:
  542. {
  543. POINT pt;
  544. GetCursorPos(&pt);
  545. RECT rect;
  546. GetWindowRect(&rect);
  547. if (!PtInRect(&rect,pt)&&!m_bCursorInAutoHideBarItem&&!GetCapture())
  548. {
  549. KillTimer(TID_AUTO_HIDE_DELAY);
  550. StartAnimateDisplay(TID_SLIDE_IN);
  551. }
  552. }
  553. break;
  554. case TID_SLIDE_OUT: //Show
  555. if(m_animDispParam.slideStep<m_animDispParam.slideStepCount-1)
  556. {
  557. m_animDispParam.slideStep++;
  558. DoSlideStep();
  559. }else{
  560. //clean timer and reset animate display parameter
  561. SetWindowPos(NULL,
  562. m_animDispParam.rect.left,m_animDispParam.rect.top,
  563. m_animDispParam.rect.Width(),m_animDispParam.rect.Height(),
  564. SWP_NOZORDER|SWP_SHOWWINDOW);
  565. KillTimer(TID_SLIDE_OUT);
  566. m_animDispParam.slideStep=0;
  567. m_animDispParam.bInAnimateDisplay=FALSE;
  568. }
  569. break;
  570. case TID_SLIDE_IN: //Hide
  571. if(m_animDispParam.slideStep>-1)
  572. {
  573. m_animDispParam.slideStep--;
  574. DoSlideStep();
  575. }else{
  576. //clean timer and reset animate display parameter
  577. KillTimer(TID_SLIDE_IN);
  578. ShowWindow(SW_HIDE);
  579. m_animDispParam.slideStep=m_animDispParam.slideStepCount-1;
  580. m_animDispParam.bInAnimateDisplay=FALSE;
  581. }
  582. break;
  583. default:
  584. break;
  585. }
  586. CWnd::OnTimer(nIDEvent);
  587. }
  588. void CAHFloatWnd::OnNcLButtonDown(UINT nHitTest, CPoint point)
  589. {
  590. BOOL bNeedPaint = FALSE;
  591. BOOL bActiveOld = m_isActive;
  592. m_isActive = TRUE;
  593. if (m_isActive != bActiveOld)
  594. bNeedPaint = TRUE;
  595. ///////////////////////////////////////////////////////////
  596. // hit close
  597. BOOL bHit = (nHitTest == HTHIDE);
  598. BOOL bLButtonDown = TRUE;
  599. BOOL bWasPushed = m_biHide.bPushed;
  600. m_biHide.bPushed = bHit && bLButtonDown;
  601. BOOL bWasRaised = m_biHide.bRaised;
  602. m_biHide.bRaised = bHit && !bLButtonDown;
  603. bNeedPaint |= (m_biHide.bPushed ^ bWasPushed) ||
  604. (m_biHide.bRaised ^ bWasRaised);
  605. ////////////////////////////////////////////////////////////
  606. // hit stud
  607. bHit = (nHitTest == HTSTUD);
  608. bWasPushed = m_stud.bPushed;
  609. m_stud.bPushed = bHit && bLButtonDown;
  610. bWasRaised = m_stud.bRaised;
  611. m_stud.bRaised = bHit && !bLButtonDown;
  612. bNeedPaint |= (m_stud.bPushed ^ bWasPushed) ||
  613. (m_stud.bRaised ^ bWasRaised);
  614. if (bNeedPaint)
  615. SendMessage(WM_NCPAINT);
  616. CWnd::OnNcLButtonDown(nHitTest, point);
  617. }
  618. void CAHFloatWnd::OnShowWindow(BOOL bShow, UINT nStatus)
  619. {
  620. CWnd * pFocusWnd=GetFocus();
  621. if(pFocusWnd!=this)
  622. m_isActive=FALSE;
  623. CWnd::OnShowWindow(bShow, nStatus);
  624. }
  625. void CAHFloatWnd::OnGetMinMaxInfo(MINMAXINFO* lpMMI)
  626. {
  627. // TODO: Add your message handler code here and/or call default
  628. CWnd::OnGetMinMaxInfo(lpMMI);
  629. if(m_animDispParam.bInAnimateDisplay){
  630. lpMMI->ptMinTrackSize.x=5;
  631. lpMMI->ptMinTrackSize.y=5;
  632. }
  633. }
  634. //CAHFloatWnd implementation ends
  635. //////////////////////////////////////////////////////////////////////////
  636. //////////////////////////////////////////////////////////////////////////////////////////
  637. // CHidePageItem
  638. CHidePageItem::CHidePageItem()
  639. {
  640. m_lastAHFloatWndRect.SetRectEmpty();
  641. }
  642. CHidePageItem::~CHidePageItem()
  643. {
  644. }
  645. void CHidePageItem::Draw(CDC *pDC, BOOL bHorz)
  646. {
  647. if(bHorz)
  648. ::DrawIconEx(pDC->m_hDC,m_rect.left+3, m_rect.top+(m_rect.Height()-16)/2+1,m_hIcon,16,16,0,NULL,DI_NORMAL);
  649. else
  650. ::DrawIconEx(pDC->m_hDC,m_rect.left+(m_rect.Width()-16)/2, m_rect.top + 3,m_hIcon,16,16,0,NULL,DI_NORMAL);
  651. CRect rect = m_rect;
  652. rect.left += 3;
  653. rect.top += 1;
  654. if(TRUE == m_isActive)
  655. {
  656. int nPrevBkMode = pDC->SetBkMode(TRANSPARENT);
  657. if(TRUE == bHorz)
  658. {
  659. rect.left += 16 + 6;
  660. pDC->ExtTextOut(rect.left, rect.top+3, ETO_CLIPPED, NULL, m_sText, NULL);
  661. }
  662. else
  663. {
  664. rect.top += 16 + 6;
  665. pDC->ExtTextOut(rect.right-3, rect.top, ETO_CLIPPED, NULL, m_sText, NULL);
  666. }
  667. pDC->SetBkMode(nPrevBkMode);
  668. }
  669. if(TRUE == bHorz)
  670. {
  671. pDC->MoveTo (m_rect.right, m_rect.top+2 );
  672. pDC->LineTo (m_rect.right, m_rect.bottom );
  673. }
  674. else
  675. {
  676. pDC->MoveTo (m_rect.left, m_rect.bottom );
  677. pDC->LineTo (m_rect.right, m_rect.bottom );
  678. }
  679. }
  680. //////////////////////////////////////////////////////////////////////////////////////////
  681. // CHideItem
  682. CHideItem::CHideItem()
  683. {
  684. m_nActivePage = -1;
  685. }
  686. CHideItem::~CHideItem()
  687. {
  688. }
  689. void CHideItem::Draw(CDC *pDC)
  690. {
  691. CBrush brush(GetSysColor(COLOR_3DFACE));
  692. pDC->FillRect(m_rect,&brush);
  693. CPen pen(PS_SOLID, 1, RGB(128,128,128));
  694. HPEN poldPen = (HPEN)pDC->SelectObject (&pen);
  695. if(m_dwStyle & CBRS_ORIENT_HORZ)
  696. {
  697. pDC->MoveTo (m_rect.left, m_rect.top );
  698. pDC->LineTo (m_rect.left, m_rect.bottom );
  699. pDC->MoveTo (m_rect.right, m_rect.top );
  700. pDC->LineTo (m_rect.right, m_rect.bottom );
  701. if (m_dwStyle & CBRS_ALIGN_TOP)
  702. {
  703. pDC->MoveTo (m_rect.left, m_rect.bottom );
  704. pDC->LineTo (m_rect.right+1, m_rect.bottom );//MS CDC Bug???
  705. }
  706. else if (m_dwStyle & CBRS_ALIGN_BOTTOM)
  707. {
  708. pDC->MoveTo (m_rect.left, m_rect.top );
  709. pDC->LineTo (m_rect.right, m_rect.top );
  710. }
  711. }
  712. else if(m_dwStyle & CBRS_ORIENT_VERT)
  713. {
  714. pDC->MoveTo (m_rect.left, m_rect.top );
  715. pDC->LineTo (m_rect.right, m_rect.top );
  716. pDC->MoveTo (m_rect.left, m_rect.bottom );
  717. pDC->LineTo (m_rect.right, m_rect.bottom );
  718. if (m_dwStyle & CBRS_ALIGN_LEFT)
  719. {
  720. pDC->MoveTo (m_rect.right, m_rect.top );
  721. pDC->LineTo (m_rect.right, m_rect.bottom+1);//MS CDC Bug???
  722. }
  723. else if (m_dwStyle & CBRS_ALIGN_RIGHT)
  724. {
  725. pDC->MoveTo (m_rect.left, m_rect.top );
  726. pDC->LineTo (m_rect.left, m_rect.bottom );
  727. }
  728. }
  729. CHidePageItem* pHidePageItem;
  730. for(int i =0; i< m_arrPags.GetSize(); i++)
  731. {
  732. pHidePageItem = (CHidePageItem*)m_arrPags[i];
  733. if(m_dwStyle & CBRS_ORIENT_HORZ)
  734. {
  735. pHidePageItem->Draw (pDC, TRUE);
  736. }
  737. else if(m_dwStyle & CBRS_ORIENT_VERT)
  738. {
  739. pHidePageItem->Draw (pDC, FALSE);
  740. }
  741. }
  742. pDC->SelectObject (poldPen);
  743. //2011-10-31 add
  744. DeleteObject( brush );
  745. DeleteObject( pen );
  746. }
  747. void CHideItem::AddPageItem(CDockPageBar* pPageBar, CWnd* pWnd, DWORD dwStyle)
  748. {
  749. m_dwStyle = dwStyle;
  750. //Copy the dockPageBar's Rect
  751. pPageBar->GetWindowRect (m_oldWndRect );
  752. pPageBar->GetParentFrame()->ScreenToClient (&m_oldWndRect);
  753. m_pAutoHideBar = pWnd;
  754. m_pDockPageBar = pPageBar;
  755. pPageBar->ShowWindow (SW_HIDE);
  756. m_wndFloat.CreateEx(WS_EX_LEFT, AfxRegisterWndClass(CS_VREDRAW | CS_HREDRAW),
  757. NULL, (WS_CHILDWINDOW|WS_BORDER|WS_THICKFRAME|WS_VISIBLE|WS_CLIPCHILDREN|WS_CLIPSIBLINGS),
  758. m_oldWndRect,
  759. AfxGetMainWnd(), 0);
  760. m_wndFloat.m_dwStyle = dwStyle;
  761. m_wndFloat.ShowWindow (SW_HIDE);
  762. m_wndFloat.m_HideItem = this;
  763. m_nActivePage = pPageBar->m_nActivePage;
  764. POSITION pos;
  765. CPageItem* pPageItem;
  766. for(pos=pPageBar->m_PageList.GetHeadPosition();pos!=NULL;)
  767. {
  768. pPageItem=(CPageItem*)pPageBar->m_PageList.GetNext(pos);
  769. if(pPageItem)
  770. {
  771. CHidePageItem* pHidePage = new CHidePageItem;
  772. pHidePage->m_hIcon = pPageItem->m_hIcon;
  773. pHidePage->m_pWnd = pPageItem->m_pWnd;
  774. pHidePage->m_sText = pPageItem->m_sText;
  775. m_arrPags.Add (pHidePage);
  776. }
  777. }
  778. }
  779. void CHideItem::UpDateSize(CDC* pDC, CRect *rect)
  780. {
  781. CHidePageItem* pHidePageItem;
  782. m_rect = *rect;
  783. for(int i =0; i< m_arrPags.GetSize(); i++)
  784. {
  785. pHidePageItem = (CHidePageItem*)m_arrPags[i];
  786. if(NULL != pHidePageItem)
  787. {
  788. if(m_dwStyle & CBRS_ORIENT_HORZ)
  789. {
  790. pHidePageItem->m_rect = *rect;
  791. pHidePageItem->m_rect.right = pHidePageItem->m_rect.left + 21;
  792. pHidePageItem->m_isActive = FALSE;
  793. if(m_nActivePage == i)
  794. {
  795. pHidePageItem->m_rect.right += 24;
  796. pHidePageItem->m_rect.right += pDC->GetTextExtent (pHidePageItem->m_sText).cx;
  797. pHidePageItem->m_rect.right += AUTO_HIDE_BAR_WIDTH;
  798. pHidePageItem->m_isActive = TRUE;
  799. }
  800. m_rect.right = rect->left = pHidePageItem->m_rect.right;
  801. }
  802. else if(m_dwStyle & CBRS_ORIENT_VERT)
  803. {
  804. pHidePageItem->m_rect = *rect;
  805. pHidePageItem->m_rect.bottom = pHidePageItem->m_rect.top + 21;
  806. pHidePageItem->m_isActive = FALSE;
  807. if(m_nActivePage == i)
  808. {
  809. pHidePageItem->m_rect.bottom += 24;
  810. pHidePageItem->m_rect.bottom += pDC->GetTextExtent (pHidePageItem->m_sText).cx;
  811. pHidePageItem->m_rect.bottom += AUTO_HIDE_BAR_WIDTH;
  812. pHidePageItem->m_isActive = TRUE;
  813. }
  814. m_rect.bottom = rect->top = pHidePageItem->m_rect.bottom;
  815. }
  816. }
  817. }
  818. }
  819. BOOL CHideItem::OnMouseMove(CPoint pt)
  820. {
  821. CHidePageItem* pHidePageItem;
  822. for(int i =0; i< m_arrPags.GetSize(); i++)
  823. {
  824. pHidePageItem = (CHidePageItem*)m_arrPags[i];
  825. if(NULL != pHidePageItem)
  826. {
  827. if(pHidePageItem->m_rect.PtInRect (pt))
  828. {
  829. Show(i);
  830. if(m_nActivePage != i)
  831. {
  832. return TRUE;
  833. }
  834. else
  835. {
  836. return FALSE;
  837. }
  838. }
  839. }
  840. }
  841. return FALSE;
  842. }
  843. void CHideItem::Show(int nShow)
  844. {
  845. if(m_nActivePage == nShow&&m_wndFloat.IsWindowVisible ()||
  846. m_wndFloat.m_animDispParam.bInAnimateDisplay)
  847. return;
  848. CRect rect;
  849. m_pAutoHideBar->GetWindowRect(rect);
  850. //Show the new activated one
  851. CHidePageItem * pCurActivePageItem=((CHidePageItem*)m_arrPags[nShow]);
  852. //Get the proper rect size for the new activated item
  853. if(pCurActivePageItem->m_lastAHFloatWndRect.IsRectEmpty())
  854. m_wndFloat.GetWindowRect (m_oldWndRect);
  855. else
  856. m_oldWndRect=pCurActivePageItem->m_lastAHFloatWndRect;
  857. if (m_dwStyle & CBRS_ORIENT_HORZ)
  858. {
  859. rect.bottom = rect.top + m_oldWndRect.Height();
  860. if (m_dwStyle & CBRS_ALIGN_TOP)
  861. {
  862. rect.OffsetRect (0, AUTO_HIDE_BAR_WIDTH-2);
  863. }
  864. else if (m_dwStyle & CBRS_ALIGN_BOTTOM)
  865. {
  866. rect.OffsetRect (0, -m_oldWndRect.Height());
  867. }
  868. }
  869. else if (m_dwStyle & CBRS_ORIENT_VERT)
  870. {
  871. rect.right = rect.left + m_oldWndRect.Width();
  872. if (m_dwStyle & CBRS_ALIGN_LEFT)
  873. rect.OffsetRect (AUTO_HIDE_BAR_WIDTH, 0);
  874. else if (m_dwStyle & CBRS_ALIGN_RIGHT)
  875. rect.OffsetRect (-m_oldWndRect.Width(), 0);
  876. }
  877. else
  878. {
  879. ASSERT(FALSE); // can never happen
  880. }
  881. //Hide the float window first
  882. m_wndFloat.StartAnimateDisplay(TID_SLIDE_IN);
  883. m_wndFloat.MoveWindow(0,0,0,0);
  884. //Hide the previous active page
  885. ((CHidePageItem*)m_arrPags[m_nActivePage])->m_pWnd->ShowWindow (SW_HIDE);
  886. ((CHidePageItem*)m_arrPags[m_nActivePage])->m_pWnd->SetParent (m_pDockPageBar);
  887. //Set the new activated page's to the float window
  888. CWnd * pchild = pCurActivePageItem->m_pWnd;
  889. pchild->SetParent (&m_wndFloat);
  890. m_wndFloat.m_Title = pCurActivePageItem->m_sText;
  891. m_wndFloat.m_activePageItem=pCurActivePageItem;
  892. CWnd* pFrameWnd=AfxGetMainWnd();
  893. //Prevent the m_wndFloat window from being shadowed by the client view window
  894. BRING_CLIENT_WINDOW_TO_BOTTOM(pFrameWnd);
  895. //Use the client coordinate of the main frame
  896. pFrameWnd->ScreenToClient(&rect);
  897. //Prevent the m_pAutoHideBar window from being shadowed by the m_wndFloat window
  898. m_wndFloat.SetWindowPos(m_pAutoHideBar,rect.left,rect.top ,rect.Width (), rect.Height (),SWP_HIDEWINDOW);
  899. m_wndFloat.m_animDispParam.rect=rect;
  900. //Move the new activated page to the float window
  901. CRect clientRect;
  902. m_wndFloat.GetClientRect(clientRect);
  903. pchild->MoveWindow(clientRect);
  904. pchild->ShowWindow (SW_SHOW);
  905. //Animate show
  906. m_nActivePage = nShow;
  907. m_wndFloat.StartAnimateDisplay(TID_SLIDE_OUT);
  908. }
  909. void CHideItem::Dock()
  910. {
  911. ((CHidePageItem*)m_arrPags[m_nActivePage])->m_pWnd->SetParent (m_pDockPageBar);
  912. RemoveAll();
  913. m_wndFloat.DestroyWindow();
  914. m_pDockPageBar->ShowWindow (SW_SHOW);
  915. m_pDockPageBar->UpdateSize();
  916. ((CAutoHideBar*)m_pAutoHideBar)->UpdateBar();
  917. }
  918. /////////////////////////////////////////////////////////////////////////////
  919. // remove all item (2004/04/06)
  920. void CHideItem::RemoveAll()
  921. {
  922. CHidePageItem* pHidePageItem;
  923. int count = m_arrPags.GetSize();
  924. for(int i =0; i< count; i++)
  925. {
  926. pHidePageItem = (CHidePageItem*)m_arrPags[0];
  927. delete pHidePageItem;
  928. pHidePageItem = NULL;
  929. m_arrPags.RemoveAt(0);
  930. }
  931. }
  932. /////////////////////////////////////////////////////////////////////////////
  933. // CAutoHideBar implementation starts
  934. CAutoHideBar::CAutoHideBar()
  935. {
  936. m_pCurSelItem=NULL;
  937. }
  938. CAutoHideBar::~CAutoHideBar()
  939. {
  940. POSITION pos;
  941. CHideItem* pHideItem;
  942. for(pos=m_listBars.GetHeadPosition();pos!=NULL;)
  943. {
  944. pHideItem = (CHideItem*)m_listBars.GetNext(pos);
  945. if(NULL != pHideItem)
  946. {
  947. pHideItem->RemoveAll ();
  948. delete pHideItem;
  949. pHideItem = NULL;
  950. }
  951. }
  952. m_listBars.RemoveAll ();
  953. DeleteObject( m_Font );
  954. }
  955. BEGIN_MESSAGE_MAP(CAutoHideBar, CControlBar)
  956. //{{AFX_MSG_MAP(CAutoHideBar)
  957. ON_MESSAGE(WM_SIZEPARENT, OnSizeParent)
  958. ON_WM_MOUSEMOVE()
  959. ON_WM_PAINT()
  960. //}}AFX_MSG_MAP
  961. ON_WM_SHOWWINDOW()
  962. END_MESSAGE_MAP()
  963. /////////////////////////////////////////////////////////////////////////////
  964. // CAutoHideBar message handlers
  965. BOOL CAutoHideBar::Create(CWnd *pParentWnd, DWORD dwStyle, UINT nID)
  966. {
  967. ASSERT(pParentWnd != NULL);
  968. ASSERT_KINDOF(CFrameWnd, pParentWnd);
  969. m_dwStyle = (dwStyle & CBRS_ALL);
  970. // register and create the window
  971. CString wndclass = ::AfxRegisterWndClass(CS_VREDRAW | CS_HREDRAW,
  972. ::LoadCursor(NULL, IDC_ARROW),
  973. ::GetSysColorBrush(COLOR_BTNFACE), 0);
  974. dwStyle &= ~CBRS_ALL; // keep only the generic window styles
  975. dwStyle |= WS_CLIPCHILDREN; // prevents flashing
  976. if(m_dwStyle & CBRS_ORIENT_HORZ)
  977. {
  978. m_Font.CreateFont(13 ,0, 0,0, FW_NORMAL, 0,0,0, DEFAULT_CHARSET,
  979. OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
  980. FF_ROMAN , "Tahoma");
  981. }
  982. else if(m_dwStyle & CBRS_ORIENT_VERT)
  983. {
  984. m_Font.CreateFont(13,0, -900,-900, FW_NORMAL, 0,0,0, DEFAULT_CHARSET,
  985. OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
  986. FF_ROMAN , "Tahoma");
  987. }
  988. // Note: Parent must resize itself for control bar to be resized
  989. return CWnd::Create(wndclass, NULL, dwStyle, CRect(0, 0, 0, 0), pParentWnd, nID);
  990. }
  991. LRESULT CAutoHideBar::OnSizeParent(WPARAM wParam, LPARAM lParam)
  992. {
  993. AFX_SIZEPARENTPARAMS* lpLayout = (AFX_SIZEPARENTPARAMS*)lParam;
  994. DWORD dwStyle = m_dwStyle;
  995. if(!(dwStyle & WS_VISIBLE))
  996. {
  997. SetWindowPos(NULL, 0, 0, 0, 0,SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_HIDEWINDOW);
  998. }
  999. if ((dwStyle & WS_VISIBLE) && (dwStyle & CBRS_ALIGN_ANY) != 0)
  1000. {
  1001. // align the control bar
  1002. CRect rect;
  1003. rect.CopyRect(&lpLayout->rect);
  1004. CSize sizeAvail = rect.Size(); // maximum size available
  1005. // get maximum requested size
  1006. DWORD dwMode = lpLayout->bStretch ? LM_STRETCH : 0;
  1007. if (dwStyle & CBRS_ORIENT_HORZ)
  1008. dwMode |= LM_HORZ | LM_HORZDOCK;
  1009. else
  1010. dwMode |= LM_VERTDOCK;
  1011. CSize size (AUTO_HIDE_BAR_WIDTH,AUTO_HIDE_BAR_WIDTH);
  1012. size.cx = min(size.cx, sizeAvail.cx);
  1013. size.cy = min(size.cy, sizeAvail.cy);
  1014. if (dwStyle & CBRS_ORIENT_HORZ)
  1015. {
  1016. lpLayout->sizeTotal.cy += size.cy;
  1017. lpLayout->sizeTotal.cx = max(lpLayout->sizeTotal.cx, size.cx);
  1018. if (dwStyle & CBRS_ALIGN_TOP)
  1019. lpLayout->rect.top += size.cy;
  1020. else if (dwStyle & CBRS_ALIGN_BOTTOM)
  1021. {
  1022. size.cy-=2; // Bottom alignment has different width from the Top alignment
  1023. rect.top = rect.bottom - size.cy;
  1024. lpLayout->rect.bottom -= size.cy;
  1025. }
  1026. rect.bottom = rect.top + size.cy;
  1027. rect.right = lpLayout->rect.right;
  1028. }
  1029. else if (dwStyle & CBRS_ORIENT_VERT)
  1030. {
  1031. lpLayout->sizeTotal.cx += size.cx;
  1032. lpLayout->sizeTotal.cy = max(lpLayout->sizeTotal.cy, size.cy);
  1033. if (dwStyle & CBRS_ALIGN_LEFT)
  1034. lpLayout->rect.left += size.cx;
  1035. else if (dwStyle & CBRS_ALIGN_RIGHT)
  1036. {
  1037. rect.left = rect.right - size.cx;
  1038. lpLayout->rect.right -= size.cx;
  1039. }
  1040. rect.right = rect.left + size.cx;
  1041. rect.bottom = lpLayout->rect.bottom ;
  1042. }
  1043. else
  1044. {
  1045. ASSERT(FALSE); // can never happen
  1046. }
  1047. m_size = CSize(rect.BottomRight() - rect.TopLeft());
  1048. SetWindowPos(NULL, rect.left, rect.top, rect.Width(), rect.Height(), SWP_NOZORDER|SWP_NOACTIVATE|SWP_SHOWWINDOW);
  1049. }
  1050. return 0;
  1051. }
  1052. void CAutoHideBar::OnMouseMove(UINT nFlags, CPoint point)
  1053. {
  1054. TRACKMOUSEEVENT trackEvt;
  1055. trackEvt.cbSize=sizeof(TRACKMOUSEEVENT);
  1056. trackEvt.dwFlags=TME_LEAVE|TME_HOVER;
  1057. trackEvt.dwHoverTime=AUTO_HIDE_DELAY_TIMES;
  1058. trackEvt.hwndTrack=m_hWnd;
  1059. _TrackMouseEvent(&trackEvt);
  1060. CControlBar::OnMouseMove(nFlags, point);
  1061. }
  1062. void CAutoHideBar::OnPaint()
  1063. {
  1064. CPaintDC PaintDC(this); // device context for painting
  1065. CRect rcBar;
  1066. GetClientRect(&rcBar);
  1067. CDC dc;
  1068. dc.CreateCompatibleDC(&PaintDC);
  1069. CBitmap bm;
  1070. bm.CreateCompatibleBitmap(&PaintDC, rcBar.Width(), rcBar.Height());
  1071. dc.SelectObject(bm);
  1072. //dc.SetBoundsRect(&rcBar, DCB_DISABLE);
  1073. // draw background
  1074. CBrush brush(RGB(247,243,233));
  1075. dc.FillRect(&rcBar, &brush);
  1076. CPen pen(PS_SOLID,1,RGB(128,128,128)),*pOldPen=dc.SelectObject(&pen);
  1077. dc.Rectangle(&rcBar);
  1078. dc.SelectObject(pOldPen);
  1079. dc.SelectObject (m_Font);
  1080. //COLORREF crOldText;
  1081. //crOldText = dc.SetTextColor(RGB(128,128,128));
  1082. UpDateSize();
  1083. DrawItem(&dc);
  1084. //dc.SetTextColor(crOldText);
  1085. PaintDC.BitBlt (rcBar.left, rcBar.top, rcBar.Width(), rcBar.Height(), &dc, 0,0,SRCCOPY);
  1086. dc.DeleteDC ();
  1087. //2011-10-31 add
  1088. DeleteObject( brush );
  1089. bm.DeleteObject();
  1090. ReleaseDC( &PaintDC );
  1091. }
  1092. void CAutoHideBar::DrawItem(CDC *pDC)
  1093. {
  1094. POSITION pos;
  1095. CHideItem* pHideItem;
  1096. for(pos=m_listBars.GetHeadPosition();pos!=NULL;)
  1097. {
  1098. pHideItem = (CHideItem*)m_listBars.GetNext(pos);;
  1099. if(NULL != pHideItem)
  1100. pHideItem->Draw (pDC);
  1101. }
  1102. }
  1103. void CAutoHideBar::HidePageBar(CDockPageBar *pDockPageBar)
  1104. {
  1105. m_dwStyle |= WS_VISIBLE;
  1106. CHideItem* pHideItem = new CHideItem;
  1107. pHideItem->AddPageItem(pDockPageBar, this, m_dwStyle);
  1108. m_listBars.AddTail (pHideItem);
  1109. Invalidate();
  1110. }
  1111. void CAutoHideBar::UpDateSize()
  1112. {
  1113. CPaintDC dc(this);
  1114. dc.SelectObject (m_Font);
  1115. CRect rect;
  1116. GetClientRect(&rect);
  1117. if(m_dwStyle & CBRS_ORIENT_HORZ)
  1118. {
  1119. rect.left += 2;
  1120. if (m_dwStyle & CBRS_ALIGN_TOP)
  1121. rect.bottom -= 3;
  1122. else if (m_dwStyle & CBRS_ALIGN_BOTTOM)
  1123. rect.top += 2;
  1124. }
  1125. else if(m_dwStyle & CBRS_ORIENT_VERT)
  1126. {
  1127. rect.top += 2;
  1128. if (m_dwStyle & CBRS_ALIGN_LEFT)
  1129. rect.right -= 3;
  1130. else if (m_dwStyle & CBRS_ALIGN_RIGHT)
  1131. rect.left += 2;
  1132. }
  1133. else
  1134. {
  1135. ASSERT(FALSE); // can never happen
  1136. }
  1137. POSITION pos;
  1138. CHideItem* pHideItem;
  1139. for(pos=m_listBars.GetHeadPosition();pos!=NULL;)
  1140. {
  1141. pHideItem = (CHideItem*)m_listBars.GetNext(pos);;
  1142. if(NULL != pHideItem)
  1143. {
  1144. pHideItem->UpDateSize (&dc, &rect);
  1145. if(m_dwStyle & CBRS_ORIENT_HORZ)
  1146. {
  1147. rect.left += 20;
  1148. }
  1149. else if(m_dwStyle & CBRS_ORIENT_VERT)
  1150. {
  1151. rect.top += 20;
  1152. }
  1153. }
  1154. }
  1155. }
  1156. void CAutoHideBar::GetClientRect(CRect *rect)
  1157. {
  1158. CWnd::GetClientRect (rect);
  1159. if(m_dwStyle & CBRS_ORIENT_HORZ)
  1160. {
  1161. if (m_dwStyle & CBRS_ALIGN_TOP)
  1162. rect->bottom -= 1;
  1163. }
  1164. else if(m_dwStyle & CBRS_ORIENT_VERT)
  1165. {
  1166. if (m_dwStyle & CBRS_ALIGN_LEFT)
  1167. rect->right -= 1;
  1168. }
  1169. else
  1170. {
  1171. ASSERT(FALSE); // can never happen
  1172. }
  1173. }
  1174. void CAutoHideBar::UpdateBar()
  1175. {
  1176. POSITION pos, pos2;
  1177. CHideItem* pHideItem;
  1178. for(pos=m_listBars.GetHeadPosition();( pos2 = pos ) != NULL;)
  1179. {
  1180. pHideItem = (CHideItem*)m_listBars.GetNext(pos);;
  1181. if(NULL != pHideItem)
  1182. {
  1183. if(pHideItem->m_arrPags.GetSize () == 0)
  1184. {
  1185. delete pHideItem;
  1186. pHideItem = NULL;
  1187. m_listBars.RemoveAt(pos2);
  1188. }
  1189. }
  1190. }
  1191. if(m_listBars.GetCount () == 0)
  1192. {
  1193. m_dwStyle &= ~WS_VISIBLE;
  1194. }
  1195. Invalidate ();
  1196. GetParentFrame()->RecalcLayout();
  1197. }
  1198. void CAutoHideBar::OnShowWindow(BOOL bShow, UINT nStatus)
  1199. {
  1200. CControlBar::OnShowWindow(bShow, nStatus);
  1201. // TODO: Add your message handler code here
  1202. }
  1203. LRESULT CAutoHideBar::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
  1204. {
  1205. switch(message)
  1206. {
  1207. case WM_MOUSELEAVE:
  1208. if(m_pCurSelItem){
  1209. m_pCurSelItem->m_wndFloat.m_bCursorInAutoHideBarItem=FALSE;
  1210. m_pCurSelItem=NULL;
  1211. }
  1212. break;
  1213. case WM_MOUSEHOVER:
  1214. case WM_LBUTTONDOWN:
  1215. {
  1216. POSITION pos;
  1217. CHideItem* pHideItem;
  1218. CPoint point;
  1219. GetCursorPos(&point);
  1220. ScreenToClient(&point);
  1221. for(pos=m_listBars.GetHeadPosition();pos!=NULL;)
  1222. {
  1223. pHideItem = (CHideItem*)m_listBars.GetNext(pos);
  1224. if(NULL != pHideItem)
  1225. {
  1226. if(pHideItem->m_rect.PtInRect (point))
  1227. {
  1228. pHideItem->OnMouseMove (point);
  1229. pHideItem->m_wndFloat.m_bCursorInAutoHideBarItem=TRUE;
  1230. m_pCurSelItem=pHideItem;
  1231. }else{
  1232. pHideItem->m_wndFloat.m_bCursorInAutoHideBarItem=FALSE;
  1233. m_pCurSelItem=NULL;
  1234. }
  1235. }
  1236. }
  1237. Invalidate(FALSE);
  1238. }
  1239. break;
  1240. default:
  1241. break;
  1242. }
  1243. return CControlBar::WindowProc(message, wParam, lParam);
  1244. }
  1245. void CAutoHideBar::OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler)
  1246. {
  1247. }
  1248. //CAutoHideBar implementation ends
  1249. //////////////////////////////////////////////////////////////////////////
  1250. /////////////////////////////////////////////////////////////////////////////
  1251. // CAutoHideFrame
  1252. const DWORD dwHideBarMap[4][2] =
  1253. {
  1254. { AHBRS_TOP, CBRS_TOP },
  1255. { AHBRS_BOTTOM, CBRS_BOTTOM },
  1256. { AHBRS_LEFT, CBRS_LEFT },
  1257. { AHBRS_RIGHT, CBRS_RIGHT },
  1258. };
  1259. IMPLEMENT_DYNCREATE(CAutoHideFrame, CFrameWnd)
  1260. CAutoHideFrame::CAutoHideFrame()
  1261. {
  1262. }
  1263. CAutoHideFrame::~CAutoHideFrame()
  1264. {
  1265. }
  1266. BEGIN_MESSAGE_MAP(CAutoHideFrame, CFrameWnd)
  1267. //{{AFX_MSG_MAP(CAutoHideFrame)
  1268. ON_WM_DESTROY()
  1269. //}}AFX_MSG_MAP
  1270. END_MESSAGE_MAP()
  1271. /////////////////////////////////////////////////////////////////////////////
  1272. // CAutoHideFrame message handlers
  1273. void CAutoHideFrame::EnableDocking(DWORD dwDockStyle)
  1274. {
  1275. // must be CBRS_ALIGN_XXX or CBRS_FLOAT_MULTI only
  1276. ASSERT((dwDockStyle & ~(CBRS_ALIGN_ANY|CBRS_FLOAT_MULTI)) == 0);
  1277. for (int i = 0; i < 4; i++)
  1278. {
  1279. if (dwHideBarMap[i][1] & dwDockStyle & CBRS_ALIGN_ANY)
  1280. {
  1281. CAutoHideBar* pAutoHide = (CAutoHideBar*)GetControlBar(dwHideBarMap[i][0]);
  1282. if (pAutoHide == NULL)
  1283. {
  1284. pAutoHide = new CAutoHideBar;
  1285. if (!pAutoHide->Create(this,
  1286. WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_CHILD|WS_VISIBLE |
  1287. dwHideBarMap[i][1], dwHideBarMap[i][0]))
  1288. {
  1289. AfxThrowResourceException();
  1290. }
  1291. }
  1292. }
  1293. }
  1294. CFrameWnd::EnableDocking(dwDockStyle);
  1295. }
  1296. void CAutoHideFrame::OnDestroy()
  1297. {
  1298. for (int i = 0; i < 4; i++)
  1299. {
  1300. CAutoHideBar* pAutoHide = (CAutoHideBar*)GetControlBar(dwHideBarMap[i][0]);
  1301. if (pAutoHide != NULL)
  1302. {
  1303. pAutoHide->DestroyWindow();
  1304. delete pAutoHide;
  1305. }
  1306. }
  1307. CFrameWnd::OnDestroy();
  1308. }
  1309. void CAutoHideFrame::GetPureClientRect(LPRECT lpRect)
  1310. {
  1311. ::GetWindowRect(((CFrameWnd*)this)->GetActiveView()->m_hWnd,lpRect);
  1312. }
  1313. void CAutoHideFrame::BringClientWindowToBottom()
  1314. {
  1315. CWnd *pWnd=GetActiveView();
  1316. pWnd->SetWindowPos(&CWnd::wndBottom ,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
  1317. }
  1318. //////////////////////////////////////////////////////////////////////////
  1319. //CMDIAutoHideFrame Implementation starts
  1320. IMPLEMENT_DYNCREATE(CMDIAutoHideFrame, CMDIFrameWnd)
  1321. CMDIAutoHideFrame::CMDIAutoHideFrame()
  1322. {
  1323. }
  1324. CMDIAutoHideFrame::~CMDIAutoHideFrame()
  1325. {
  1326. }
  1327. BEGIN_MESSAGE_MAP(CMDIAutoHideFrame,CMDIFrameWnd)
  1328. //{{AFX_MSG_MAP(CMDIAutoHideFrame)
  1329. ON_WM_DESTROY()
  1330. //}}AFX_MSG_MAP
  1331. END_MESSAGE_MAP()
  1332. /////////////////////////////////////////////////////////////////////////////
  1333. // CMDIAutoHideFrame message handlers
  1334. void CMDIAutoHideFrame::EnableDocking(DWORD dwDockStyle)
  1335. {
  1336. // must be CBRS_ALIGN_XXX or CBRS_FLOAT_MULTI only
  1337. ASSERT((dwDockStyle & ~(CBRS_ALIGN_ANY|CBRS_FLOAT_MULTI)) == 0);
  1338. for (int i = 0; i < 4; i++)
  1339. {
  1340. if (dwHideBarMap[i][1] & dwDockStyle & CBRS_ALIGN_ANY)
  1341. {
  1342. CAutoHideBar* pAutoHide = (CAutoHideBar*)GetControlBar(dwHideBarMap[i][0]);
  1343. if (pAutoHide == NULL)
  1344. {
  1345. pAutoHide = new CAutoHideBar;
  1346. if (!pAutoHide->Create(this,
  1347. WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_CHILD|WS_VISIBLE |
  1348. dwHideBarMap[i][1], dwHideBarMap[i][0]))
  1349. {
  1350. AfxThrowResourceException();
  1351. }
  1352. }
  1353. }
  1354. }
  1355. CMDIFrameWnd::EnableDocking(dwDockStyle);
  1356. }
  1357. void CMDIAutoHideFrame::GetPureClientRect(LPRECT lpRect)
  1358. {
  1359. ::GetWindowRect(((CMDIFrameWnd*)this)->m_hWndMDIClient,lpRect);
  1360. }
  1361. void CMDIAutoHideFrame::BringClientWindowToBottom()
  1362. {
  1363. CWnd *pWnd=CWnd::FromHandle(m_hWndMDIClient);
  1364. pWnd->SetWindowPos(&CWnd::wndBottom ,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE);
  1365. }
  1366. void CMDIAutoHideFrame::OnDestroy()
  1367. {
  1368. for (int i = 0; i < 4; i++)
  1369. {
  1370. CAutoHideBar* pAutoHide = (CAutoHideBar*)GetControlBar(dwHideBarMap[i][0]);
  1371. if (pAutoHide != NULL)
  1372. {
  1373. pAutoHide->DestroyWindow();
  1374. delete pAutoHide;
  1375. }
  1376. }
  1377. CMDIFrameWnd::OnDestroy();
  1378. }
  1379. //////////////////////////////////////////////////////////////////////////
  1380. //CMDIAutoHideFrame implementation ends