AutoHideBar.cpp 39 KB

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