DockPageBar.cpp 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965
  1. /////////////////////////////////////////////////////////////////////////
  2. //
  3. // CDockPageBar Version 1.2
  4. //
  5. // Created: Mar 16, 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. // o 感谢Cristi Posea的CSizingControlBar
  25. // o 借鉴了王骏的《轻松实现类VC界面》中的部分代码,在这里表示感谢。
  26. // o 感谢hengai帮助修改了部分内存泄漏问题
  27. // o 开发过程中遇到的问题得到了VC知识库论坛中很多人的帮助,这里一并感谢。
  28. //
  29. //////////////////////////////////////////////////////////////////////////
  30. //Updates
  31. //////////////////////////////////////////////////////////////////////////
  32. // Author | Date | Description
  33. //========================================================================
  34. // Tony |2006-09-04 | Bugfixs:
  35. //=======================| 1.add Timer TID_AUTO_HIDE_DELAY to prevent two
  36. //tony__cb@hotmail.com | AHFloatWnds being displayed at the same time.
  37. // | 2.focus switch problems(especially between AHFloatwnd and
  38. // | DockPageBar).
  39. // | 3.frequence screen flash on sizing the DockPageBar.
  40. // | 4.resize the AHFloatWnds with the wider than the mainframe.
  41. // | 5.link problems related with static MFC lib
  42. // | by setting a new compile flag STATIC_MFC_LINK
  43. // | 6.Verify the pWnd's style in CDockPageBar::AddPage function,
  44. // | to make sure pWnd to have the WS_CHILD style, and to avoid
  45. // | the window management disorder in clean up.
  46. // | ------------------------------------------------
  47. // | Improvements and new features:
  48. // | 1.add the slide in/out animation display for AHFloatWnds
  49. // | (the API ::AnimateWindow doesnt work for the self-draw window)
  50. // | 2.make a lot of detail display changes(border,caption bar,...)
  51. // | to have nicer windows
  52. // | 3.add the new docking detection algorithm(accurate docking)
  53. // | just as MS VC2003, but with the limitation that
  54. // | the horizontal docking always has the higher priority.
  55. // | 4.add the support for MDI style Frame
  56. // | 5.rewrite the NcPaint,NcCalClient,OnNcLButtonXXXX,OnNcHitTest part
  57. // | for CDockPageBar to draw the caption(griper),and item tab button
  58. // | in the NcPaint.
  59. // | 6.disable the DragShowContent mode in CSizingControlBar and
  60. // | the OnNcPaint in CDockPageBar when sizing the bar to avoid
  61. // | the dirty & flashy display
  62. // DockPageBar.cpp : implementation file
  63. //
  64. #include "stdafx.h"
  65. #include "DockPageBar.h"
  66. #include ".\dockpagebar.h"
  67. #ifdef _DEBUG
  68. #define new DEBUG_NEW
  69. #undef THIS_FILE
  70. static char THIS_FILE[] = __FILE__;
  71. #endif
  72. #include "MainFrm.h"
  73. extern CMainFrame *g_pMainFrm;
  74. /////////////////////////////////////////////////////////////////////////
  75. // delete the line between menu bar and tool bar
  76. // From <afximpl.h>
  77. struct AUX_DATA
  78. {
  79. int _unused1, _unused2;
  80. int _unused3, _unused4;
  81. int cxBorder2, cyBorder2;
  82. };
  83. extern __declspec(dllimport) AUX_DATA afxData;
  84. class INIT_afxData
  85. {
  86. public:
  87. INIT_afxData ()
  88. {
  89. afxData.cxBorder2 = afxData.cyBorder2 = 0;
  90. }
  91. } g_afxData2;
  92. /////////////////////////////////////////////////////////////////////////
  93. // CMyButton
  94. CMyButton::CMyButton()
  95. {
  96. bRaised = FALSE;
  97. bPushed = FALSE;
  98. }
  99. void CMyButton::Paint(CDC* pDC, BOOL isActive)
  100. {
  101. CRect rc = GetRect();
  102. if (bPushed)
  103. pDC->Draw3dRect(rc, ::GetSysColor(COLOR_BTNSHADOW),
  104. ::GetSysColor(COLOR_BTNHIGHLIGHT));
  105. else
  106. if (bRaised)
  107. pDC->Draw3dRect(rc, ::GetSysColor(COLOR_BTNHIGHLIGHT),
  108. ::GetSysColor(COLOR_BTNSHADOW));
  109. }
  110. // draw close button
  111. void CCloseButton::Paint(CDC* pDC, BOOL isActive)
  112. {
  113. CMyButton::Paint(pDC, isActive);
  114. COLORREF clrOldTextColor = pDC->GetTextColor();
  115. //if(TRUE == isActive)
  116. pDC->SetTextColor(RGB(255,255,255));
  117. //else
  118. // pDC->SetTextColor(RGB(0,0,0));
  119. int nPrevBkMode = pDC->SetBkMode(TRANSPARENT);
  120. CFont font;
  121. int ppi = pDC->GetDeviceCaps(LOGPIXELSX);
  122. int pointsize = MulDiv(75, 96, ppi); // 6 points at 96 ppi
  123. font.CreatePointFont(pointsize, _T("Marlett"));
  124. CFont* oldfont = pDC->SelectObject(&font);
  125. pDC->TextOut(ptOrg.x + 2, ptOrg.y + 2, CString(_T("r"))); // x-like
  126. pDC->SelectObject(oldfont);
  127. pDC->SetBkMode(nPrevBkMode);
  128. pDC->SetTextColor(clrOldTextColor);
  129. //2011-10-31 add
  130. DeleteObject( font );
  131. }
  132. CStudButton::CStudButton()
  133. {
  134. }
  135. // draw stud
  136. void CStudButton::Paint(CDC* pDC, BOOL isActive)
  137. {
  138. CMyButton::Paint(pDC, isActive);
  139. HPEN oldPen;
  140. CPen pen;
  141. //if(TRUE == isActive)
  142. pen.CreatePen (PS_SOLID, 1, RGB(255,255,255));
  143. //else
  144. // pen.CreatePen (PS_SOLID, 1, RGB(0,0,0));
  145. oldPen = (HPEN)pDC->SelectObject (pen);
  146. if(FALSE == bFloat)
  147. {
  148. pDC->MoveTo (ptOrg.x + 4, ptOrg.y + 8);
  149. pDC->LineTo (ptOrg.x + 4, ptOrg.y + 3);
  150. pDC->LineTo (ptOrg.x + 8, ptOrg.y + 3);
  151. pDC->LineTo (ptOrg.x + 8, ptOrg.y + 8);
  152. pDC->MoveTo (ptOrg.x + 7, ptOrg.y + 3);
  153. pDC->LineTo (ptOrg.x + 7, ptOrg.y + 8);
  154. pDC->MoveTo (ptOrg.x + 2, ptOrg.y + 8);
  155. pDC->LineTo (ptOrg.x + 11, ptOrg.y + 8);
  156. pDC->MoveTo (ptOrg.x + 6, ptOrg.y + 8);
  157. pDC->LineTo (ptOrg.x + 6, ptOrg.y + 12);
  158. }
  159. else
  160. {
  161. pDC->MoveTo (ptOrg.x + 5, ptOrg.y + 4);
  162. pDC->LineTo (ptOrg.x + 10, ptOrg.y + 4);
  163. pDC->LineTo (ptOrg.x + 10, ptOrg.y + 8);
  164. pDC->LineTo (ptOrg.x + 5, ptOrg.y + 8);
  165. pDC->MoveTo (ptOrg.x + 5, ptOrg.y + 7);
  166. pDC->LineTo (ptOrg.x + 10, ptOrg.y + 7);
  167. pDC->MoveTo (ptOrg.x + 5, ptOrg.y + 2);
  168. pDC->LineTo (ptOrg.x + 5, ptOrg.y + 11);
  169. pDC->MoveTo (ptOrg.x + 1, ptOrg.y + 6);
  170. pDC->LineTo (ptOrg.x + 5, ptOrg.y + 6);
  171. }
  172. pDC->SelectObject(oldPen);
  173. //2011-10-31 add
  174. DeleteObject( pen );
  175. }
  176. /////////////////////////////////////////////////////////////////////////////
  177. // CPageItem
  178. void CPageItem::Draw(CDC *pDC, BOOL bActive)
  179. {
  180. CRect rect = m_rect;
  181. COLORREF crOldText;
  182. rect.top +=2;
  183. if(bActive)
  184. {
  185. rect.bottom -= 2;
  186. CRect rcButton=rect;
  187. rcButton.DeflateRect(-1,0,0,-2);
  188. CBrush brush(GetSysColor(COLOR_3DFACE));
  189. pDC->FillRect(rcButton,&brush);
  190. CPen pen(PS_SOLID,1,GetSysColor(COLOR_3DDKSHADOW));
  191. HPEN oldPen = (HPEN)pDC->SelectObject (&pen);
  192. pDC->MoveTo (rect.left-1 , rect.bottom+2 );
  193. pDC->LineTo (rect.right ,rect.bottom+2);
  194. pDC->MoveTo (rect.right-1, rect.top);
  195. pDC->LineTo (rect.right-1,rect.bottom+3 );
  196. pDC->SelectObject (oldPen);
  197. crOldText = pDC->SetTextColor(RGB(0,0,0));
  198. m_pWnd->ShowWindow(SW_SHOW);
  199. //2011-10-31 add
  200. DeleteObject( pen );
  201. DeleteObject( brush );
  202. }
  203. else
  204. {
  205. CPen pen(PS_SOLID, 1, RGB(128,128,128));
  206. HPEN oldPen = (HPEN)pDC->SelectObject (&pen);
  207. pDC->MoveTo (rect.right, rect.top + 5);
  208. pDC->LineTo (rect.right, rect.bottom -1);
  209. pDC->SelectObject (oldPen);
  210. crOldText = pDC->SetTextColor(RGB(128,128,128));
  211. m_pWnd->ShowWindow(SW_HIDE);
  212. //2011-10-31 add
  213. DeleteObject( pen );
  214. }
  215. rect.left += 3;
  216. rect.right -= 2;
  217. // draw Icon
  218. if(rect.Width() > 16 && m_hIcon != NULL)
  219. {
  220. ::DrawIconEx(pDC->m_hDC,rect.left,rect.top + 3,m_hIcon,16,16,0,NULL,DI_NORMAL);
  221. rect.left += 22;
  222. }
  223. if (!m_sText.IsEmpty())
  224. {
  225. // draw text
  226. rect.top += 2;
  227. CString sText = m_sText;
  228. int l = sText.GetLength();
  229. int i;
  230. for(i=0;i<10 && pDC->GetTextExtent(sText).cx > rect.Width();i++,l-=2)
  231. sText = sText.Left(l-2);
  232. if(i > 0)
  233. {
  234. sText = sText.Left(l-2);
  235. sText += "...";
  236. }
  237. int nPrevBkMode = pDC->SetBkMode(TRANSPARENT);
  238. pDC->DrawText(sText, &rect, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
  239. pDC->SetBkMode(nPrevBkMode);
  240. }
  241. pDC->SetTextColor (crOldText);
  242. }
  243. /////////////////////////////////////////////////////////////////////////////
  244. // CDockPageBar
  245. IMPLEMENT_DYNAMIC(CDockPageBar, baseCDockPageBar);
  246. CDockPageBar::CDockPageBar()
  247. {
  248. m_szMinHorz = CSize(50, 50);
  249. m_szMinVert = CSize(60, 60);
  250. m_szMinFloat = CSize(150, 150);
  251. m_cyGripper = CAPTION_HEIGHT+4;
  252. m_isActive = FALSE;
  253. m_Title = "";
  254. m_nActivePage = -1;
  255. m_stud.bFloat = FALSE;
  256. m_bDrawTitleBar = true;
  257. }
  258. CDockPageBar::~CDockPageBar()
  259. {
  260. for(POSITION pos = m_PageList.GetHeadPosition(); pos;)
  261. {
  262. CPageItem* pItem=(CPageItem*)m_PageList.GetNext(pos);
  263. delete pItem; pItem=NULL;
  264. }
  265. m_PageList.RemoveAll();
  266. for(pos = m_pDPBContext.GetHeadPosition(); pos;)
  267. {
  268. CDockPageBarContext* pDPBContext = (CDockPageBarContext*)m_pDPBContext.GetNext(pos);
  269. if(pDPBContext)
  270. {
  271. pDPBContext->FreeAll();
  272. }
  273. }
  274. m_pDPBContext.RemoveAll();
  275. DeleteObject( m_font );
  276. }
  277. BEGIN_MESSAGE_MAP(CDockPageBar, baseCDockPageBar)
  278. //{{AFX_MSG_MAP(CDockPageBar)
  279. ON_WM_CREATE()
  280. ON_WM_NCPAINT()
  281. ON_WM_SIZE()
  282. //ON_WM_PAINT()
  283. ON_WM_NCHITTEST()
  284. ON_WM_NCLBUTTONUP()
  285. ON_WM_NCLBUTTONDOWN()
  286. ON_WM_NCLBUTTONDBLCLK()
  287. ON_WM_DESTROY()
  288. //}}AFX_MSG_MAP
  289. ON_WM_ERASEBKGND()
  290. END_MESSAGE_MAP()
  291. /////////////////////////////////////////////////////////////////////////////
  292. // CDockPageBar message handlers
  293. int CDockPageBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
  294. {
  295. if (baseCDockPageBar::OnCreate(lpCreateStruct) == -1)
  296. return -1;
  297. if (m_font.CreatePointFont(85, "Tahoma"))
  298. SetFont(&m_font);
  299. m_isActive = FALSE;
  300. //SetBkColor( this->GetDC()->GetSafeHdc(),RGB( 0,0,0 ) );
  301. return 0;
  302. }
  303. void CDockPageBar::OnDestroy()
  304. {
  305. }
  306. void CDockPageBar::OnUpdateCmdUI(CFrameWnd *pTarget, BOOL bDisableIfNoHndler)
  307. {
  308. if (!HasGripper())
  309. return;
  310. BOOL bNeedPaint = FALSE;
  311. CWnd* pFocus = GetFocus();
  312. BOOL bActiveOld = m_isActive;
  313. m_isActive = (pFocus->GetSafeHwnd() && IsChild(pFocus));
  314. m_isActive = m_isActive || (pFocus == this);
  315. if (m_isActive != bActiveOld)
  316. bNeedPaint = TRUE;
  317. CPoint pt;
  318. ::GetCursorPos(&pt);
  319. ///////////////////////////////////////////////////////////
  320. // hit close
  321. BOOL bHit = (OnNcHitTest(pt) == HTCLOSE);
  322. BOOL bLButtonDown = (::GetKeyState(VK_LBUTTON) < 0);
  323. BOOL bWasPushed = m_biHide.bPushed;
  324. m_biHide.bPushed = bHit && bLButtonDown;
  325. BOOL bWasRaised = m_biHide.bRaised;
  326. m_biHide.bRaised = bHit && !bLButtonDown;
  327. bNeedPaint |= (m_biHide.bPushed ^ bWasPushed) ||
  328. (m_biHide.bRaised ^ bWasRaised);
  329. ////////////////////////////////////////////////////////////
  330. // hit stud
  331. bHit = (OnNcHitTest(pt) == HTSTUD);
  332. bWasPushed = m_stud.bPushed;
  333. m_stud.bPushed = bHit && bLButtonDown;
  334. bWasRaised = m_stud.bRaised;
  335. m_stud.bRaised = bHit && !bLButtonDown;
  336. bNeedPaint |= (m_stud.bPushed ^ bWasPushed) ||
  337. (m_stud.bRaised ^ bWasRaised);
  338. if (bNeedPaint)
  339. SendMessage(WM_NCPAINT);
  340. }
  341. // draw title bar
  342. void CDockPageBar::NcPaintGripper(CDC *pDC, CRect rcClient)
  343. {
  344. //Note: Here the rcClient' coordinate is for NonClient painting,
  345. // so it is referenced to the current window's topleft.
  346. if( !m_bDrawTitleBar )
  347. return;
  348. if (!HasGripper())
  349. return;
  350. CRect clientBorderRc,gripper;
  351. clientBorderRc=gripper=rcClient;
  352. CRect rcbtn = m_biHide.GetRect();
  353. gripper.DeflateRect(-1,-1,0,0);
  354. gripper.top -= m_cyGripper;
  355. gripper.bottom = gripper.top + CAPTION_HEIGHT;
  356. HFONT oldFont = (HFONT)pDC->SelectObject (m_font);
  357. int nPrevBkMode = pDC->SetBkMode(TRANSPARENT);
  358. COLORREF crOldText;
  359. if(TRUE == m_isActive) // active state
  360. {
  361. CBrush brush(RGB(62,132,192));
  362. pDC->FillRect(&gripper, &brush);
  363. crOldText = pDC->SetTextColor(RGB(255,255,255));
  364. //2011-10-31 add
  365. DeleteObject( brush );
  366. }
  367. else
  368. {
  369. CPen pen(PS_SOLID, 1, RGB(128,128,128));
  370. HPEN poldPen = (HPEN)pDC->SelectObject (&pen);
  371. // Draw better rect
  372. // ------------------------------
  373. //| |
  374. //| |
  375. // ------------------------------
  376. CPoint pt=gripper.TopLeft();
  377. pt.Offset(1,0);
  378. pDC->MoveTo (pt);
  379. pDC->LineTo (gripper.right ,gripper.top );
  380. pt=gripper.TopLeft();
  381. pt.Offset(1,gripper.Height());
  382. pDC->MoveTo (pt);
  383. pDC->LineTo (gripper.right ,gripper.bottom );
  384. pt=gripper.BottomRight();
  385. pt.Offset(0,-1);
  386. pDC->MoveTo (pt);
  387. pDC->LineTo (gripper.right ,gripper.top);
  388. pt=gripper.BottomRight();
  389. pt.Offset(-gripper.Width(),-1);
  390. pDC->MoveTo(pt);
  391. pDC->LineTo (gripper.left ,gripper.top);
  392. pDC->SelectObject (poldPen);
  393. //crOldText = pDC->SetTextColor(RGB(0,0,0));
  394. CBrush brush(RGB(62,132,192));
  395. pDC->FillRect(&gripper, &brush);
  396. crOldText = pDC->SetTextColor(RGB(255,255,255));
  397. //2011-10-31 add
  398. DeleteObject( pen );
  399. DeleteObject( brush );
  400. }
  401. gripper.left += 4;
  402. gripper.top += 2;
  403. // draw caption
  404. if (!m_Title.IsEmpty())
  405. {
  406. CString sText = m_Title;
  407. int l = sText.GetLength();
  408. int i;
  409. for(i=0;i<10 && pDC->GetTextExtent(sText).cx > (gripper.Width() - 30);i++,l-=2)
  410. sText = sText.Left(l-2);
  411. if(i > 0)
  412. {
  413. sText = sText.Left(l-2);
  414. sText += "...";
  415. }
  416. pDC->TextOut (gripper.left, gripper.top, sText);
  417. }
  418. pDC->SetTextColor (crOldText);
  419. pDC->SetBkMode(nPrevBkMode);
  420. pDC->SelectObject(oldFont);
  421. CPoint ptOrgBtn;
  422. ptOrgBtn = CPoint(gripper.right - 15, gripper.top);
  423. m_biHide.Move(ptOrgBtn);
  424. m_biHide.Paint(pDC, m_isActive);
  425. //ptOrgBtn.x -= 17;
  426. //m_stud.Move (ptOrgBtn);
  427. //m_stud.Paint(pDC, m_isActive);
  428. }
  429. void CDockPageBar::NcCalcClient(LPRECT pRc, UINT nDockBarID)
  430. {
  431. if( !m_bDrawTitleBar )
  432. return;
  433. CRect rcBar(pRc); // save the bar rect
  434. // subtract edges
  435. baseCDockPageBar::NcCalcClient(pRc, nDockBarID);
  436. if (!HasGripper()&&!m_PageList.GetCount())
  437. return;
  438. CRect rc(pRc); // the client rect as calculated by the base class
  439. rc.DeflateRect(1,0,1,0);
  440. BOOL bHorz = (nDockBarID == AFX_IDW_DOCKBAR_TOP) ||
  441. (nDockBarID == AFX_IDW_DOCKBAR_BOTTOM);
  442. if(!IsFloating()){
  443. bHorz ? rc.DeflateRect(0, m_cyGripper-1, 2,0):
  444. rc.DeflateRect(0, m_cyGripper-1, 0,0);
  445. }
  446. if(m_PageList.GetCount()>1)
  447. rc.DeflateRect(0,0,0,ITEMBUTTON_HEIGHT);
  448. DEFLECT_RECT_FOR_STATIC_LINK(rc);
  449. *pRc = rc;
  450. }
  451. void CDockPageBar::OnStudClick()
  452. {
  453. //GetParentFrame()->PostMessage(WM_AUTOHIDE_ON, m_nDockBarID, (LPARAM)this);
  454. //CDockPageBar * pWnd = (CDockPageBar *)lParam;
  455. CAutoHideBar * pAutoHideBar;
  456. switch(m_nDockBarID)
  457. {
  458. case AFX_IDW_DOCKBAR_TOP:
  459. pAutoHideBar = (CAutoHideBar *)((CFrameWnd*)AfxGetMainWnd())->GetControlBar(AHBRS_TOP);
  460. break;
  461. case AFX_IDW_DOCKBAR_BOTTOM:
  462. pAutoHideBar = (CAutoHideBar *)((CFrameWnd*)AfxGetMainWnd())->GetControlBar(AHBRS_BOTTOM);
  463. break;
  464. case AFX_IDW_DOCKBAR_LEFT:
  465. pAutoHideBar = (CAutoHideBar *)((CFrameWnd*)AfxGetMainWnd())->GetControlBar(AHBRS_LEFT);
  466. break;
  467. case AFX_IDW_DOCKBAR_RIGHT:
  468. pAutoHideBar = (CAutoHideBar *)((CFrameWnd*)AfxGetMainWnd())->GetControlBar(AHBRS_RIGHT);
  469. break;
  470. }
  471. pAutoHideBar->HidePageBar(this);
  472. ((CFrameWnd*)AfxGetMainWnd())->RecalcLayout();
  473. }
  474. BOOL CDockPageBar::HasGripper() const
  475. {
  476. if (IsFloating())
  477. return FALSE;
  478. return TRUE;
  479. }
  480. UINT CDockPageBar::OnNcHitTest(CPoint point)
  481. {
  482. CRect rcBar;
  483. GetWindowRect(rcBar);
  484. UINT nRet = baseCDockPageBar::OnNcHitTest(point);
  485. if (nRet != HTCLIENT)
  486. return nRet;
  487. CRect rc = m_biHide.GetRect();
  488. rc.OffsetRect(rcBar.TopLeft());
  489. if (rc.PtInRect(point))
  490. return HTCLOSE;
  491. rc = m_stud.GetRect();
  492. rc.OffsetRect(rcBar.TopLeft());
  493. if (rc.PtInRect(point))
  494. return HTSTUD;
  495. GetItemGroupRect(&rc);
  496. if(rc.PtInRect(point))
  497. return HTITEMBUTTON;
  498. GetCaptionRect(&rc);
  499. if(rc.PtInRect(point))
  500. return HTGRIPPER;
  501. return HTCLIENT;
  502. }
  503. LRESULT CDockPageBar::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
  504. {
  505. // TODO: 在此添加专用代码和/或调用基类
  506. switch( message )
  507. {
  508. case WM_MY_INVALIDATE:
  509. {
  510. if( g_pMainFrm )
  511. {
  512. if( this==&g_pMainFrm->m_hbottomDockBar )
  513. {
  514. CAutoHideBar * pAutoHideBar;
  515. pAutoHideBar = (CAutoHideBar *)((CFrameWnd*)AfxGetMainWnd())->GetControlBar(AHBRS_BOTTOM);
  516. POSITION pos;
  517. CHideItem* pHideItem;
  518. for(pos=pAutoHideBar->m_listBars.GetHeadPosition();pos!=NULL;)
  519. {
  520. pHideItem = (CHideItem*)pAutoHideBar->m_listBars.GetNext(pos);
  521. pHideItem->m_wndFloat.m_stud.bPushed = FALSE;
  522. pHideItem->m_wndFloat.OnStudClick();
  523. }
  524. }
  525. //else if( this==&g_pMainFrm->m_wndDockPageBar1 )
  526. //{
  527. // m_pDockSite->ShowControlBar(this, TRUE, FALSE);
  528. // if(::IsWindow(m_hWnd))
  529. // SendMessage(WM_NCPAINT);
  530. // //CAutoHideBar * pAutoHideBar;
  531. // //pAutoHideBar = (CAutoHideBar *)((CFrameWnd*)AfxGetMainWnd())->GetControlBar(AHBRS_LEFT);
  532. // //POSITION pos;
  533. // //CHideItem* pHideItem;
  534. // //for(pos=pAutoHideBar->m_listBars.GetHeadPosition();pos!=NULL;)
  535. // //{
  536. // // pHideItem = (CHideItem*)pAutoHideBar->m_listBars.GetNext(pos);
  537. // // pHideItem->m_wndFloat.m_stud.bPushed = FALSE;
  538. // // pHideItem->m_wndFloat.OnStudClick();
  539. // //}
  540. //}
  541. }
  542. }
  543. break;
  544. }
  545. return CSizingControlBar::WindowProc(message, wParam, lParam);
  546. }
  547. /////////////////////////////////////////////////////////////////////////////
  548. // about PageIte
  549. CPageItem* CDockPageBar::GetPageItem(int nIndex)
  550. {
  551. CPageItem *pItem = NULL;
  552. POSITION pos = m_PageList.FindIndex(nIndex);
  553. if(pos)
  554. pItem = (CPageItem*)m_PageList.GetAt(pos);
  555. return pItem;
  556. }
  557. void CDockPageBar::SetActivePage(int nIndex)
  558. {
  559. if(nIndex == m_nActivePage)
  560. return;
  561. CPageItem *pItem;
  562. pItem = (CPageItem*)GetPageItem(nIndex);
  563. if(!pItem) return;
  564. m_nActivePage = nIndex;
  565. m_Title = pItem->m_sText;
  566. SetWindowText(m_Title);
  567. SendMessage(WM_NCPAINT);
  568. Invalidate();
  569. }
  570. void CDockPageBar::OnSize(UINT nType, int cx, int cy)
  571. {
  572. UpdateSize();
  573. Invalidate();
  574. SendMessage(WM_NCPAINT);
  575. if( g_pMainFrm )
  576. {
  577. if( this==&g_pMainFrm->m_hbottomDockBar )
  578. g_pMainFrm->SendMessage( WM_MY_SIZECHANGE,m_szHorz.cx,m_szHorz.cy );
  579. }
  580. }
  581. void CDockPageBar::UpdateSize()
  582. {
  583. UINT PageCount = m_PageList.GetCount();
  584. if(PageCount < 1) return;
  585. CPageItem *pItem;
  586. CRect ClientRect;
  587. if(PageCount == 1)
  588. {
  589. GetClientRect(ClientRect);
  590. pItem = (CPageItem*)GetPageItem(0);;
  591. if(pItem->m_pWnd)
  592. {
  593. pItem->m_pWnd->MoveWindow(ClientRect);
  594. pItem->m_pWnd->ShowWindow(SW_SHOW);
  595. }
  596. return;
  597. }
  598. POSITION pos;
  599. CRect rect,ItemRect,wndRect;
  600. GetWindowRect(&wndRect);
  601. GetClientRect(ClientRect);
  602. //Note: Here the rect/ItemRect' coordinate is for NonClient painting,
  603. // so it is referenced to the current window's topleft.
  604. GetItemGroupRect(&rect);
  605. rect.OffsetRect(-wndRect.TopLeft());
  606. rect.DeflateRect(4,-3,4,3);
  607. DEFLECT_RECT_FOR_STATIC_LINK(rect);
  608. //rect.right-=10;
  609. ItemRect = rect;
  610. int AreaWidth = 0,ItemWidth,ItemIndex=0;
  611. for(pos=m_PageList.GetHeadPosition();pos!=NULL;ItemIndex++)
  612. {
  613. pItem=(CPageItem*)m_PageList.GetNext(pos);
  614. if(pItem)
  615. {
  616. ItemWidth = pItem->m_TabWidth;
  617. AreaWidth += ItemWidth;
  618. ItemRect.right = ItemRect.left+ItemWidth-1;
  619. pItem->m_rect = ItemRect;
  620. ItemRect.left = ItemRect.right + 1;
  621. if(pItem->m_pWnd)
  622. pItem->m_pWnd->MoveWindow(ClientRect);
  623. }
  624. }
  625. if(AreaWidth > rect.Width())
  626. {
  627. ItemRect = rect;
  628. int AreaWidth,MaxWidth = rect.Width()/PageCount;
  629. for(pos=m_PageList.GetHeadPosition();pos!=NULL;)
  630. {
  631. pItem=(CPageItem*)m_PageList.GetNext(pos);
  632. if(pItem)
  633. {
  634. AreaWidth = pItem->m_TabWidth;
  635. ItemWidth = (MaxWidth < AreaWidth)?MaxWidth:AreaWidth;
  636. ItemRect.right = ItemRect.left+ItemWidth;
  637. pItem->m_rect = ItemRect;
  638. ItemRect.left = ItemRect.right + 1;
  639. }
  640. }
  641. }
  642. }
  643. void CDockPageBar::GetItemGroupRect(LPRECT lpRect)
  644. {
  645. CRect rcBar,cr;
  646. GetWindowRect(rcBar);
  647. rcBar.left+=1;
  648. rcBar.right-=3;
  649. rcBar.bottom-=1;
  650. #ifdef STATIC_MFC_LINK
  651. rcBar.top=rcBar.bottom-ITEMBUTTON_HEIGHT;//+2;
  652. #else
  653. rcBar.top=rcBar.bottom-ITEMBUTTON_HEIGHT+2;
  654. #endif
  655. //Note: Here we return the rect, which referenced to the screen
  656. *lpRect=rcBar;
  657. }
  658. void CDockPageBar::GetCaptionRect(LPRECT lpRect)
  659. {
  660. CRect rcBar,cr;
  661. GetWindowRect(rcBar);
  662. rcBar.left+=1;
  663. rcBar.right-=3;
  664. rcBar.top-=1;
  665. rcBar.bottom=rcBar.top+CAPTION_HEIGHT;
  666. *lpRect=rcBar;
  667. }
  668. BOOL CDockPageBar::AddPage(CWnd *pWnd, LPCTSTR sText, UINT IconID)
  669. {
  670. ASSERT(IsWindow(pWnd->m_hWnd));
  671. DWORD dwStyle=pWnd->GetStyle();
  672. if(!(dwStyle&WS_CHILD)){
  673. TRACE0("Force the dock page bar content to be WS_CHILD style!");
  674. pWnd->ModifyStyle(WS_POPUP|WS_OVERLAPPED,WS_CHILD);
  675. }
  676. CPageItem *pItem;
  677. pItem = new CPageItem();
  678. pItem->m_pWnd = pWnd;
  679. pItem->m_pWnd->SetParent (this);
  680. pItem->m_sText = sText;
  681. CClientDC dc(this);
  682. pItem->m_TabWidth = dc.GetTextExtent (sText).cx;
  683. if(IconID)
  684. {
  685. pItem->m_hIcon = AfxGetApp()->LoadIcon(IconID);
  686. pItem->m_TabWidth += 18;
  687. }
  688. else
  689. pItem->m_hIcon = NULL;
  690. pItem->m_TabWidth += 9;
  691. if(pWnd)
  692. {
  693. CRect rect;
  694. GetClientRect(rect);
  695. pWnd->MoveWindow(rect);
  696. pWnd->ShowWindow(SW_HIDE);
  697. }
  698. m_PageList.AddTail(pItem);
  699. UpdateWindow();
  700. return TRUE;
  701. }
  702. BOOL CDockPageBar::AddPage(CPageItem *pPageItem)
  703. {
  704. pPageItem->m_pWnd->SetParent (this);
  705. m_PageList.AddTail(pPageItem);
  706. SetFocus();
  707. //Fore the system to send WM_NCCALCSIZE to update the client rect
  708. SetWindowPos(NULL,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE);
  709. //Use the new size to update the window
  710. UpdateWindow();
  711. return TRUE;
  712. }
  713. BOOL CDockPageBar::AddPage(CDockPageBar *dockPageBar)
  714. {
  715. POSITION pos;
  716. CPageItem* pItem;
  717. for(pos = dockPageBar->m_PageList.GetHeadPosition();pos!=NULL;)
  718. {
  719. pItem=(CPageItem*)dockPageBar->m_PageList.GetNext(pos);
  720. if(pItem)
  721. {
  722. AddPage(pItem);
  723. SetActivePage(m_PageList.GetCount()-1);
  724. }
  725. }
  726. dockPageBar->m_pDockContext->m_pDockSite->FloatControlBar(dockPageBar,CSize(0,0),0);
  727. dockPageBar->m_PageList.RemoveAll();
  728. dockPageBar->m_pDockContext->m_pDockSite->RemoveControlBar(dockPageBar);
  729. UpdateWindow();
  730. return dockPageBar->DestroyWindow ();
  731. }
  732. CPageItem* CDockPageBar::DeletePage()
  733. {
  734. CPageItem *pItem = NULL;
  735. POSITION pos = m_PageList.FindIndex(m_nActivePage);
  736. if(!pos)
  737. {
  738. return NULL;
  739. }
  740. pItem = (CPageItem*)m_PageList.GetAt(pos);
  741. pItem->m_pWnd->ShowWindow(SW_HIDE);
  742. m_PageList.RemoveAt (pos);
  743. m_nActivePage = -1;
  744. //Fore the system to send WM_NCCALCSIZE to update the client rect
  745. if(m_PageList.GetCount()==1)
  746. SetWindowPos(NULL,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE);
  747. UpdateWindow();
  748. return pItem;
  749. }
  750. void CDockPageBar::UpdateWindow()
  751. {
  752. if(m_nActivePage < 0)
  753. SetActivePage(0);
  754. UpdateSize();
  755. Invalidate();
  756. SendMessage(WM_NCPAINT);;
  757. }
  758. void CDockPageBar::DEFLECT_RECT_FOR_STATIC_LINK(CRect & rect)
  759. {
  760. #ifdef STATIC_MFC_LINK
  761. switch(m_dwStyle&CBRS_ALIGN_ANY)
  762. {
  763. case CBRS_ALIGN_LEFT:
  764. rect.DeflateRect(1,1,1,1);
  765. break;
  766. case CBRS_ALIGN_RIGHT:
  767. rect.DeflateRect(1,1,0,1);
  768. break;
  769. case CBRS_ALIGN_TOP:
  770. rect.DeflateRect(1,1,0,1);
  771. break;
  772. case CBRS_ALIGN_BOTTOM:
  773. rect.DeflateRect(1,1,0,1);
  774. break;
  775. default:
  776. ASSERT(FALSE);
  777. }
  778. #endif
  779. }
  780. void CDockPageBar::OnNcPaint()
  781. {
  782. //If you are drawing the plastic line to change the dock page bar'size,
  783. //No painting will be done to avoid the dirty result
  784. if(m_bTracking)
  785. return;
  786. // get window DC that is clipped to the non-client area
  787. CWindowDC dc(this);
  788. CRect rcClient, rcBar;
  789. GetClientRect(rcClient);
  790. ClientToScreen(rcClient);
  791. rcClient.DeflateRect(-1,0,-1,0);
  792. GetWindowRect(rcBar);
  793. rcClient.OffsetRect(-rcBar.TopLeft());
  794. rcBar.OffsetRect(-rcBar.TopLeft());
  795. CDC mdc;
  796. mdc.CreateCompatibleDC(&dc);
  797. CBitmap bm;
  798. bm.CreateCompatibleBitmap(&dc, rcBar.Width(), rcBar.Height());
  799. CBitmap* pOldBm = mdc.SelectObject(&bm);
  800. // draw borders in non-client area
  801. CRect rcDraw = rcBar;
  802. DrawBorders(&mdc, rcDraw);
  803. // erase the NC background
  804. mdc.FillRect(rcDraw, CBrush::FromHandle(
  805. (HBRUSH) GetClassLong(m_hWnd, GCL_HBRBACKGROUND)));
  806. //Draw border edges
  807. if (m_dwSCBStyle & SCBS_SHOWEDGES)
  808. {
  809. CRect rcEdge; // paint the sizing edges
  810. for (int i = 0; i < 4; i++)
  811. if (GetEdgeRect(rcBar, GetEdgeHTCode(i), rcEdge))
  812. mdc.Draw3dRect(rcEdge, ::GetSysColor(COLOR_BTNHIGHLIGHT),
  813. ::GetSysColor(COLOR_BTNSHADOW));
  814. }
  815. //Draw Gripper(the caption bar)
  816. CRect rc=rcClient;
  817. DEFLECT_RECT_FOR_STATIC_LINK(rcClient);
  818. NcPaintGripper(&mdc, rcClient);
  819. rcClient=rc; //restore
  820. //Draw Client Boarder
  821. CRect clientBorderRc=rcBar;
  822. clientBorderRc.left=rcClient.left-1;
  823. clientBorderRc.right=rcClient.right;
  824. DEFLECT_RECT_FOR_STATIC_LINK(clientBorderRc);
  825. //if (IsHorzDocked())
  826. // clientBorderRc.DeflateRect(1,m_cyGripper,5,3);
  827. //else
  828. // clientBorderRc.DeflateRect(1,m_cyGripper,3,3);
  829. if (IsHorzDocked())
  830. clientBorderRc.DeflateRect(0,m_cyGripper,0,3);
  831. else
  832. clientBorderRc.DeflateRect(0,m_cyGripper,0,3);
  833. if(m_PageList.GetCount()>1)
  834. clientBorderRc.DeflateRect(0,0,0,ITEMBUTTON_HEIGHT);
  835. CPen penRect(PS_SOLID, 1, RGB(128,128,128));
  836. HPEN oldPen = (HPEN)mdc.SelectObject (&penRect);
  837. mdc.MoveTo(clientBorderRc.TopLeft());
  838. mdc.LineTo(clientBorderRc.right,clientBorderRc.top);
  839. mdc.LineTo(clientBorderRc.right,clientBorderRc.bottom);
  840. mdc.LineTo(clientBorderRc.left,clientBorderRc.bottom);
  841. mdc.LineTo(clientBorderRc.left,clientBorderRc.top);
  842. mdc.SelectObject (oldPen);
  843. //Draw item tab button
  844. if(m_PageList.GetCount()>1)
  845. {
  846. CPageItem *pItem;
  847. POSITION pos;
  848. int nItemIndex = 0;
  849. CRect rect,wndRect;
  850. GetItemGroupRect(&rect);
  851. GetWindowRect(&wndRect);
  852. rect.OffsetRect(-wndRect.TopLeft());
  853. rect.OffsetRect(0,-1);
  854. DEFLECT_RECT_FOR_STATIC_LINK(rect);
  855. //rect.DeflateRect(0,-2,0,0);
  856. CBrush brush(RGB(247,243,233));
  857. mdc.FillRect(rect,&brush);
  858. CPen penButton(PS_SOLID,1,GetSysColor(COLOR_3DDKSHADOW));
  859. HPEN oldPen = (HPEN)mdc.SelectObject (&penButton);
  860. mdc.MoveTo (rect.TopLeft() );
  861. mdc.LineTo (rect.right, rect.top);
  862. mdc.SelectObject (oldPen);
  863. HFONT oldFont = (HFONT)mdc.SelectObject (m_font);
  864. // draw PageItem
  865. for(pos=m_PageList.GetHeadPosition();pos!=NULL;nItemIndex++)
  866. {
  867. pItem=(CPageItem*)m_PageList.GetNext(pos);
  868. if(pItem)
  869. {
  870. pItem->Draw(&mdc,(m_nActivePage==nItemIndex)?TRUE:FALSE);
  871. }
  872. }
  873. mdc.SelectObject (oldFont);
  874. //2011-10-31 add
  875. DeleteObject( penButton );
  876. DeleteObject( brush );
  877. }
  878. // client area is not our bussiness :)
  879. dc.IntersectClipRect(rcBar);
  880. rcClient.DeflateRect(1,0,1,0);
  881. dc.ExcludeClipRect(rcClient);
  882. dc.BitBlt(0, 0, rcBar.Width(), rcBar.Height(), &mdc, 0, 0, SRCCOPY);
  883. ReleaseDC(&dc);
  884. mdc.SelectObject(pOldBm);
  885. bm.DeleteObject();
  886. mdc.DeleteDC();
  887. //2011-10-31 add
  888. DeleteObject( penRect );
  889. }
  890. /////////////////////////////////////////////////////////////////////////////
  891. //
  892. void CDockPageBar::OnNcLButtonUp(UINT nHitTest, CPoint point)
  893. {
  894. if (nHitTest == HTCLOSE)
  895. {
  896. if( g_pMainFrm )
  897. {
  898. if( this==&g_pMainFrm->m_hbottomDockBar )
  899. OnStudClick();
  900. else
  901. m_pDockSite->ShowControlBar(this, FALSE, FALSE); // hide
  902. }
  903. else
  904. m_pDockSite->ShowControlBar(this, FALSE, FALSE); // hide
  905. }
  906. if (nHitTest == HTSTUD)
  907. OnStudClick();
  908. baseCDockPageBar::OnNcLButtonUp(nHitTest, point);
  909. if(::IsWindow(m_hWnd))
  910. SendMessage(WM_NCPAINT);
  911. }
  912. void CDockPageBar::OnNcLButtonDown(UINT nFlags, CPoint point)
  913. {
  914. #if 1
  915. if (nFlags == HTCLOSE)
  916. {
  917. if( g_pMainFrm )
  918. {
  919. if( this==&g_pMainFrm->m_hbottomDockBar )
  920. OnStudClick();
  921. else
  922. m_pDockSite->ShowControlBar(this, FALSE, FALSE); // hide
  923. }
  924. else
  925. m_pDockSite->ShowControlBar(this, FALSE, FALSE); // hide
  926. }
  927. if (nFlags == HTSTUD)
  928. OnStudClick();
  929. baseCDockPageBar::OnNcLButtonDown(nFlags, point);
  930. if(::IsWindow(m_hWnd))
  931. SendMessage(WM_NCPAINT);
  932. #else
  933. UINT nItemIndex=0;
  934. POSITION pos;
  935. CPageItem *pItem;
  936. CRect rect;
  937. //Note: Here the rect coordinate is for NonClient painting,
  938. // so it is referenced to the current window's topleft.
  939. GetWindowRect(&rect);
  940. point.Offset(-rect.TopLeft());
  941. if (HTITEMBUTTON==nFlags){
  942. for(pos=m_PageList.GetHeadPosition();pos!=NULL;nItemIndex++)
  943. {
  944. pItem=(CPageItem*)m_PageList.GetNext(pos);
  945. if(pItem)
  946. {
  947. if(pItem->m_rect.PtInRect(point))
  948. {
  949. SetFocus();
  950. SetActivePage(nItemIndex);
  951. CanDrag(point); // drag PageItem
  952. return;
  953. }
  954. }
  955. }
  956. }
  957. //Note: Here the rect coordinate is referenced to the screen
  958. point.Offset(rect.TopLeft());
  959. if ((nFlags >= HTSIZEFIRST) && (nFlags <= HTSIZELAST))
  960. {
  961. baseCDockPageBar::OnNcLButtonDown(nFlags, point);
  962. return;
  963. }
  964. ((CDockPageBarContext*)m_pDockContext)->m_isPage = FALSE;
  965. if (m_pDockBar != NULL&&HTGRIPPER==nFlags)
  966. {
  967. // start the drag
  968. SetFocus();
  969. ASSERT(m_pDockContext != NULL);
  970. m_pDockContext->StartDrag(point);
  971. }
  972. else
  973. CWnd::OnNcLButtonDown(nFlags, point);
  974. #endif
  975. }
  976. void CDockPageBar::OnNcLButtonDblClk(UINT nFlags, CPoint point)
  977. {
  978. return;
  979. if (HTGRIPPER==nFlags&&m_pDockBar != NULL)
  980. {
  981. // start the drag
  982. ASSERT(m_pDockContext != NULL);
  983. m_pDockContext->ToggleDocking();
  984. }
  985. else
  986. CWnd::OnNcLButtonDblClk(nFlags, point);
  987. }
  988. void CDockPageBar::EnableDocking(DWORD dwDockStyle)
  989. {
  990. // must be CBRS_ALIGN_XXX or CBRS_FLOAT_MULTI only
  991. ASSERT((dwDockStyle & ~(CBRS_ALIGN_ANY|CBRS_FLOAT_MULTI)) == 0);
  992. // cannot have the CBRS_FLOAT_MULTI style
  993. ASSERT((dwDockStyle & CBRS_FLOAT_MULTI) == 0);
  994. // the bar must have CBRS_SIZE_DYNAMIC style
  995. ASSERT((m_dwStyle & CBRS_SIZE_DYNAMIC) != 0);
  996. m_dwDockStyle = dwDockStyle;
  997. if (m_pDockContext == NULL)
  998. {
  999. m_pDockContext = new CDockPageBarContext(this);
  1000. m_pDPBContext.AddTail(m_pDockContext); //hengai
  1001. }
  1002. // permanently wire the bar's owner to its current parent
  1003. if (m_hWndOwner == NULL)
  1004. m_hWndOwner = ::GetParent(m_hWnd);
  1005. }
  1006. void CDockPageBar::CanDrag(CPoint pt)
  1007. {
  1008. SetCapture();
  1009. // get messages until capture lost or cancelled/accepted
  1010. while (CWnd::GetCapture() == this)
  1011. {
  1012. MSG msg;
  1013. if (!::GetMessage(&msg, NULL, 0, 0))
  1014. {
  1015. AfxPostQuitMessage(msg.wParam);
  1016. break;
  1017. }
  1018. switch (msg.message)
  1019. {
  1020. case WM_LBUTTONUP:
  1021. ReleaseCapture();
  1022. break;
  1023. case WM_MOUSEMOVE:
  1024. Move(msg.pt);
  1025. break;
  1026. default:
  1027. DispatchMessage(&msg);
  1028. break;
  1029. }
  1030. }
  1031. }
  1032. void CDockPageBar::Move(CPoint pt)
  1033. {
  1034. CRect rect,wndRect;
  1035. //Note: Here the rect coordinate is for NonClient painting,
  1036. // so it is referenced to the current window's topleft.
  1037. GetWindowRect(&wndRect);
  1038. GetItemGroupRect(&rect);
  1039. rect.OffsetRect(-wndRect.TopLeft());
  1040. pt.Offset(-wndRect.TopLeft());
  1041. if(rect.PtInRect(pt))
  1042. {
  1043. int nItemIndex=0;
  1044. POSITION pos;
  1045. CPageItem *pItem;
  1046. for(pos=m_PageList.GetHeadPosition();pos!=NULL;nItemIndex++)
  1047. {
  1048. pItem=(CPageItem*)m_PageList.GetNext(pos);
  1049. if(pItem)
  1050. {
  1051. if(pItem->m_rect.PtInRect(pt))
  1052. {
  1053. if(nItemIndex != m_nActivePage)
  1054. {
  1055. POSITION oldPos = m_PageList.FindIndex(m_nActivePage);
  1056. POSITION curPos = m_PageList.FindIndex(nItemIndex);
  1057. CPageItem *pOldItem = (CPageItem*)m_PageList.GetAt(oldPos);
  1058. // exchange PageItem
  1059. m_PageList.SetAt(oldPos, pItem);
  1060. m_PageList.SetAt(curPos, pOldItem);
  1061. m_nActivePage = nItemIndex;
  1062. UpdateWindow();
  1063. break;
  1064. }
  1065. }
  1066. }
  1067. }
  1068. }
  1069. else
  1070. {
  1071. ReleaseCapture();
  1072. StartDrag(pt);
  1073. }
  1074. }
  1075. void CDockPageBar::StartDrag(CPoint pt)
  1076. {
  1077. ClientToScreen(&pt);
  1078. ((CDockPageBarContext*)m_pDockContext)->m_isPage = TRUE;
  1079. m_pDockContext->StartDrag(pt);
  1080. ((CDockPageBarContext*)m_pDockContext)->m_isPage = FALSE;
  1081. }
  1082. /////////////////////////////////////////////////////////////////////////////
  1083. // CDockPageBar
  1084. IMPLEMENT_DYNAMIC(CcHnDockPageBar, baseCDockPageBar);
  1085. CcHnDockPageBar::CcHnDockPageBar()
  1086. {
  1087. m_szMinHorz = CSize(50, 50);
  1088. m_szMinVert = CSize(60, 60);
  1089. m_szMinFloat = CSize(150, 150);
  1090. m_cyGripper = CAPTION_HEIGHT+4;
  1091. m_isActive = FALSE;
  1092. m_Title = "";
  1093. m_nActivePage = -1;
  1094. m_stud.bFloat = FALSE;
  1095. m_bDrawStudBtn = false;
  1096. }
  1097. CcHnDockPageBar::~CcHnDockPageBar()
  1098. {
  1099. for(POSITION pos = m_PageList.GetHeadPosition(); pos;)
  1100. {
  1101. CPageItem* pItem=(CPageItem*)m_PageList.GetNext(pos);
  1102. delete pItem; pItem=NULL;
  1103. }
  1104. m_PageList.RemoveAll();
  1105. for(pos = m_pDPBContext.GetHeadPosition(); pos;)
  1106. {
  1107. CDockPageBarContext* pDPBContext = (CDockPageBarContext*)m_pDPBContext.GetNext(pos);
  1108. if(pDPBContext)
  1109. {
  1110. pDPBContext->FreeAll();
  1111. }
  1112. }
  1113. m_pDPBContext.RemoveAll();
  1114. DeleteObject( m_font );
  1115. }
  1116. BEGIN_MESSAGE_MAP(CcHnDockPageBar, baseCDockPageBar)
  1117. //{{AFX_MSG_MAP(CcHnDockPageBar)
  1118. ON_WM_CREATE()
  1119. ON_WM_NCPAINT()
  1120. ON_WM_SIZE()
  1121. //ON_WM_PAINT()
  1122. ON_WM_NCHITTEST()
  1123. ON_WM_NCLBUTTONUP()
  1124. ON_WM_NCLBUTTONDOWN()
  1125. ON_WM_NCLBUTTONDBLCLK()
  1126. ON_WM_DESTROY()
  1127. //}}AFX_MSG_MAP
  1128. ON_WM_ERASEBKGND()
  1129. END_MESSAGE_MAP()
  1130. /////////////////////////////////////////////////////////////////////////////
  1131. // CcHnDockPageBar message handlers
  1132. int CcHnDockPageBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
  1133. {
  1134. if (baseCDockPageBar::OnCreate(lpCreateStruct) == -1)
  1135. return -1;
  1136. if (m_font.CreatePointFont(85, "Tahoma"))
  1137. SetFont(&m_font);
  1138. m_isActive = FALSE;
  1139. //SetBkColor( this->GetDC()->GetSafeHdc(),RGB( 0,0,0 ) );
  1140. return 0;
  1141. }
  1142. void CcHnDockPageBar::OnDestroy()
  1143. {
  1144. }
  1145. void CcHnDockPageBar::OnUpdateCmdUI(CFrameWnd *pTarget, BOOL bDisableIfNoHndler)
  1146. {
  1147. if (!HasGripper())
  1148. return;
  1149. BOOL bNeedPaint = FALSE;
  1150. CWnd* pFocus = GetFocus();
  1151. BOOL bActiveOld = m_isActive;
  1152. m_isActive = (pFocus->GetSafeHwnd() && IsChild(pFocus));
  1153. m_isActive = m_isActive || (pFocus == this);
  1154. if (m_isActive != bActiveOld)
  1155. bNeedPaint = TRUE;
  1156. CPoint pt;
  1157. ::GetCursorPos(&pt);
  1158. ///////////////////////////////////////////////////////////
  1159. // hit close
  1160. BOOL bHit = (OnNcHitTest(pt) == HTCLOSE);
  1161. BOOL bLButtonDown = (::GetKeyState(VK_LBUTTON) < 0);
  1162. BOOL bWasPushed = m_biHide.bPushed;
  1163. m_biHide.bPushed = bHit && bLButtonDown;
  1164. BOOL bWasRaised = m_biHide.bRaised;
  1165. m_biHide.bRaised = bHit && !bLButtonDown;
  1166. bNeedPaint |= (m_biHide.bPushed ^ bWasPushed) ||
  1167. (m_biHide.bRaised ^ bWasRaised);
  1168. ////////////////////////////////////////////////////////////
  1169. // hit stud
  1170. bHit = (OnNcHitTest(pt) == HTSTUD);
  1171. bWasPushed = m_stud.bPushed;
  1172. m_stud.bPushed = bHit && bLButtonDown;
  1173. bWasRaised = m_stud.bRaised;
  1174. m_stud.bRaised = bHit && !bLButtonDown;
  1175. bNeedPaint |= (m_stud.bPushed ^ bWasPushed) ||
  1176. (m_stud.bRaised ^ bWasRaised);
  1177. if (bNeedPaint)
  1178. SendMessage(WM_NCPAINT);
  1179. }
  1180. // draw title bar
  1181. void CcHnDockPageBar::NcPaintGripper(CDC *pDC, CRect rcClient)
  1182. {
  1183. //Note: Here the rcClient' coordinate is for NonClient painting,
  1184. // so it is referenced to the current window's topleft.
  1185. if (!HasGripper())
  1186. return;
  1187. CRect clientBorderRc,gripper;
  1188. clientBorderRc=gripper=rcClient;
  1189. CRect rcbtn = m_biHide.GetRect();
  1190. gripper.DeflateRect(-1,-1,0,0);
  1191. gripper.top -= m_cyGripper;
  1192. gripper.bottom = gripper.top + CAPTION_HEIGHT;
  1193. HFONT oldFont = (HFONT)pDC->SelectObject (m_font);
  1194. int nPrevBkMode = pDC->SetBkMode(TRANSPARENT);
  1195. COLORREF crOldText;
  1196. if(TRUE == m_isActive) // active state
  1197. {
  1198. CBrush brush(RGB(62,132,192));
  1199. pDC->FillRect(&gripper, &brush);
  1200. crOldText = pDC->SetTextColor(RGB(255,255,255));
  1201. //2011-10-31 add
  1202. DeleteObject( brush );
  1203. }
  1204. else
  1205. {
  1206. CPen pen(PS_SOLID, 1, RGB(128,128,128));
  1207. HPEN poldPen = (HPEN)pDC->SelectObject (&pen);
  1208. // Draw better rect
  1209. // ------------------------------
  1210. //| |
  1211. //| |
  1212. // ------------------------------
  1213. CPoint pt=gripper.TopLeft();
  1214. pt.Offset(1,0);
  1215. pDC->MoveTo (pt);
  1216. pDC->LineTo (gripper.right ,gripper.top );
  1217. pt=gripper.TopLeft();
  1218. pt.Offset(1,gripper.Height());
  1219. pDC->MoveTo (pt);
  1220. pDC->LineTo (gripper.right ,gripper.bottom );
  1221. pt=gripper.BottomRight();
  1222. pt.Offset(0,-1);
  1223. pDC->MoveTo (pt);
  1224. pDC->LineTo (gripper.right ,gripper.top);
  1225. pt=gripper.BottomRight();
  1226. pt.Offset(-gripper.Width(),-1);
  1227. pDC->MoveTo(pt);
  1228. pDC->LineTo (gripper.left ,gripper.top);
  1229. pDC->SelectObject (poldPen);
  1230. //crOldText = pDC->SetTextColor(RGB(0,0,0));
  1231. CBrush brush(RGB(62,132,192));
  1232. pDC->FillRect(&gripper, &brush);
  1233. crOldText = pDC->SetTextColor(RGB(255,255,255));
  1234. //2011-10-31 add
  1235. DeleteObject( pen );
  1236. DeleteObject( brush );
  1237. }
  1238. gripper.left += 4;
  1239. gripper.top += 2;
  1240. // draw caption
  1241. if (!m_Title.IsEmpty())
  1242. {
  1243. CString sText = m_Title;
  1244. int l = sText.GetLength();
  1245. int i;
  1246. for(i=0;i<10 && pDC->GetTextExtent(sText).cx > (gripper.Width() - 30);i++,l-=2)
  1247. sText = sText.Left(l-2);
  1248. if(i > 0)
  1249. {
  1250. sText = sText.Left(l-2);
  1251. sText += "...";
  1252. }
  1253. pDC->TextOut (gripper.left, gripper.top, sText);
  1254. }
  1255. pDC->SetTextColor (crOldText);
  1256. pDC->SetBkMode(nPrevBkMode);
  1257. pDC->SelectObject(oldFont);
  1258. CPoint ptOrgBtn;
  1259. ptOrgBtn = CPoint(gripper.right - 15, gripper.top);
  1260. m_biHide.Move(ptOrgBtn);
  1261. m_biHide.Paint(pDC, m_isActive);
  1262. if( m_bDrawStudBtn )
  1263. {
  1264. ptOrgBtn.x -= 17;
  1265. m_stud.Move (ptOrgBtn);
  1266. m_stud.Paint(pDC, m_isActive);
  1267. }
  1268. }
  1269. void CcHnDockPageBar::NcCalcClient(LPRECT pRc, UINT nDockBarID)
  1270. {
  1271. CRect rcBar(pRc); // save the bar rect
  1272. // subtract edges
  1273. baseCDockPageBar::NcCalcClient(pRc, nDockBarID);
  1274. if (!HasGripper()&&!m_PageList.GetCount())
  1275. return;
  1276. CRect rc(pRc); // the client rect as calculated by the base class
  1277. rc.DeflateRect(1,0,1,0);
  1278. BOOL bHorz = (nDockBarID == AFX_IDW_DOCKBAR_TOP) ||
  1279. (nDockBarID == AFX_IDW_DOCKBAR_BOTTOM);
  1280. if(!IsFloating()){
  1281. bHorz ? rc.DeflateRect(0, m_cyGripper-1, 2,0):
  1282. rc.DeflateRect(0, m_cyGripper-1, 0,0);
  1283. }
  1284. if(m_PageList.GetCount()>1)
  1285. rc.DeflateRect(0,0,0,ITEMBUTTON_HEIGHT);
  1286. DEFLECT_RECT_FOR_STATIC_LINK(rc);
  1287. *pRc = rc;
  1288. }
  1289. void CcHnDockPageBar::OnStudClick()
  1290. {
  1291. //GetParentFrame()->PostMessage(WM_AUTOHIDE_ON, m_nDockBarID, (LPARAM)this);
  1292. //CcHnDockPageBar * pWnd = (CcHnDockPageBar *)lParam;
  1293. CAutoHideBar * pAutoHideBar;
  1294. switch(m_nDockBarID)
  1295. {
  1296. case AFX_IDW_DOCKBAR_TOP:
  1297. pAutoHideBar = (CAutoHideBar *)((CFrameWnd*)AfxGetMainWnd())->GetControlBar(AHBRS_TOP);
  1298. break;
  1299. case AFX_IDW_DOCKBAR_BOTTOM:
  1300. pAutoHideBar = (CAutoHideBar *)((CFrameWnd*)AfxGetMainWnd())->GetControlBar(AHBRS_BOTTOM);
  1301. break;
  1302. case AFX_IDW_DOCKBAR_LEFT:
  1303. pAutoHideBar = (CAutoHideBar *)((CFrameWnd*)AfxGetMainWnd())->GetControlBar(AHBRS_LEFT);
  1304. break;
  1305. case AFX_IDW_DOCKBAR_RIGHT:
  1306. pAutoHideBar = (CAutoHideBar *)((CFrameWnd*)AfxGetMainWnd())->GetControlBar(AHBRS_RIGHT);
  1307. break;
  1308. }
  1309. pAutoHideBar->HidePageBar((CDockPageBar *)this);
  1310. ((CFrameWnd*)AfxGetMainWnd())->RecalcLayout();
  1311. }
  1312. BOOL CcHnDockPageBar::HasGripper() const
  1313. {
  1314. if (IsFloating())
  1315. return FALSE;
  1316. return TRUE;
  1317. }
  1318. UINT CcHnDockPageBar::OnNcHitTest(CPoint point)
  1319. {
  1320. CRect rcBar;
  1321. GetWindowRect(rcBar);
  1322. UINT nRet = baseCDockPageBar::OnNcHitTest(point);
  1323. if (nRet != HTCLIENT)
  1324. return nRet;
  1325. CRect rc = m_biHide.GetRect();
  1326. rc.OffsetRect(rcBar.TopLeft());
  1327. if (rc.PtInRect(point))
  1328. return HTCLOSE;
  1329. rc = m_stud.GetRect();
  1330. rc.OffsetRect(rcBar.TopLeft());
  1331. if (rc.PtInRect(point))
  1332. return HTSTUD;
  1333. GetItemGroupRect(&rc);
  1334. if(rc.PtInRect(point))
  1335. return HTITEMBUTTON;
  1336. GetCaptionRect(&rc);
  1337. if(rc.PtInRect(point))
  1338. return HTGRIPPER;
  1339. return HTCLIENT;
  1340. }
  1341. LRESULT CcHnDockPageBar::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
  1342. {
  1343. // TODO: 在此添加专用代码和/或调用基类
  1344. switch( message )
  1345. {
  1346. case WM_MY_INVALIDATE:
  1347. {
  1348. if( g_pMainFrm )
  1349. {
  1350. if( this==&g_pMainFrm->m_hleftDockBar )
  1351. {
  1352. m_pDockSite->ShowControlBar(this, TRUE, FALSE);
  1353. if(::IsWindow(m_hWnd))
  1354. SendMessage(WM_NCPAINT);
  1355. //CAutoHideBar * pAutoHideBar;
  1356. //pAutoHideBar = (CAutoHideBar *)((CFrameWnd*)AfxGetMainWnd())->GetControlBar(AHBRS_LEFT);
  1357. //POSITION pos;
  1358. //CHideItem* pHideItem;
  1359. //for(pos=pAutoHideBar->m_listBars.GetHeadPosition();pos!=NULL;)
  1360. //{
  1361. // pHideItem = (CHideItem*)pAutoHideBar->m_listBars.GetNext(pos);
  1362. // pHideItem->m_wndFloat.m_stud.bPushed = FALSE;
  1363. // pHideItem->m_wndFloat.OnStudClick();
  1364. //}
  1365. }
  1366. }
  1367. }
  1368. break;
  1369. }
  1370. return CSizingControlBar::WindowProc(message, wParam, lParam);
  1371. }
  1372. /////////////////////////////////////////////////////////////////////////////
  1373. // about PageIte
  1374. CPageItem* CcHnDockPageBar::GetPageItem(int nIndex)
  1375. {
  1376. CPageItem *pItem = NULL;
  1377. POSITION pos = m_PageList.FindIndex(nIndex);
  1378. if(pos)
  1379. pItem = (CPageItem*)m_PageList.GetAt(pos);
  1380. return pItem;
  1381. }
  1382. void CcHnDockPageBar::SetActivePage(int nIndex)
  1383. {
  1384. if(nIndex == m_nActivePage)
  1385. return;
  1386. CPageItem *pItem;
  1387. pItem = (CPageItem*)GetPageItem(nIndex);
  1388. if(!pItem) return;
  1389. m_nActivePage = nIndex;
  1390. m_Title = pItem->m_sText;
  1391. SetWindowText(m_Title);
  1392. SendMessage(WM_NCPAINT);
  1393. Invalidate();
  1394. }
  1395. void CcHnDockPageBar::OnSize(UINT nType, int cx, int cy)
  1396. {
  1397. UpdateSize();
  1398. Invalidate();
  1399. SendMessage(WM_NCPAINT);
  1400. //if( g_pMainFrm )
  1401. //{
  1402. // if( this==&g_pMainFrm->m_wndDockPageBar2 )
  1403. // g_pMainFrm->SendMessage( WM_MY_SIZECHANGE,m_szHorz.cx,m_szHorz.cy );
  1404. //}
  1405. }
  1406. void CcHnDockPageBar::UpdateSize()
  1407. {
  1408. UINT PageCount = m_PageList.GetCount();
  1409. if(PageCount < 1) return;
  1410. CPageItem *pItem;
  1411. CRect ClientRect;
  1412. if(PageCount == 1)
  1413. {
  1414. GetClientRect(ClientRect);
  1415. pItem = (CPageItem*)GetPageItem(0);;
  1416. if(pItem->m_pWnd)
  1417. {
  1418. pItem->m_pWnd->MoveWindow(ClientRect);
  1419. pItem->m_pWnd->ShowWindow(SW_SHOW);
  1420. }
  1421. return;
  1422. }
  1423. POSITION pos;
  1424. CRect rect,ItemRect,wndRect;
  1425. GetWindowRect(&wndRect);
  1426. GetClientRect(ClientRect);
  1427. //Note: Here the rect/ItemRect' coordinate is for NonClient painting,
  1428. // so it is referenced to the current window's topleft.
  1429. GetItemGroupRect(&rect);
  1430. rect.OffsetRect(-wndRect.TopLeft());
  1431. rect.DeflateRect(4,-3,4,3);
  1432. DEFLECT_RECT_FOR_STATIC_LINK(rect);
  1433. //rect.right-=10;
  1434. ItemRect = rect;
  1435. int AreaWidth = 0,ItemWidth,ItemIndex=0;
  1436. for(pos=m_PageList.GetHeadPosition();pos!=NULL;ItemIndex++)
  1437. {
  1438. pItem=(CPageItem*)m_PageList.GetNext(pos);
  1439. if(pItem)
  1440. {
  1441. ItemWidth = pItem->m_TabWidth;
  1442. AreaWidth += ItemWidth;
  1443. ItemRect.right = ItemRect.left+ItemWidth-1;
  1444. pItem->m_rect = ItemRect;
  1445. ItemRect.left = ItemRect.right + 1;
  1446. if(pItem->m_pWnd)
  1447. pItem->m_pWnd->MoveWindow(ClientRect);
  1448. }
  1449. }
  1450. if(AreaWidth > rect.Width())
  1451. {
  1452. ItemRect = rect;
  1453. int AreaWidth,MaxWidth = rect.Width()/PageCount;
  1454. for(pos=m_PageList.GetHeadPosition();pos!=NULL;)
  1455. {
  1456. pItem=(CPageItem*)m_PageList.GetNext(pos);
  1457. if(pItem)
  1458. {
  1459. AreaWidth = pItem->m_TabWidth;
  1460. ItemWidth = (MaxWidth < AreaWidth)?MaxWidth:AreaWidth;
  1461. ItemRect.right = ItemRect.left+ItemWidth;
  1462. pItem->m_rect = ItemRect;
  1463. ItemRect.left = ItemRect.right + 1;
  1464. }
  1465. }
  1466. }
  1467. }
  1468. void CcHnDockPageBar::GetItemGroupRect(LPRECT lpRect)
  1469. {
  1470. CRect rcBar,cr;
  1471. GetWindowRect(rcBar);
  1472. rcBar.left+=1;
  1473. rcBar.right-=3;
  1474. rcBar.bottom-=1;
  1475. #ifdef STATIC_MFC_LINK
  1476. rcBar.top=rcBar.bottom-ITEMBUTTON_HEIGHT;//+2;
  1477. #else
  1478. rcBar.top=rcBar.bottom-ITEMBUTTON_HEIGHT+2;
  1479. #endif
  1480. //Note: Here we return the rect, which referenced to the screen
  1481. *lpRect=rcBar;
  1482. }
  1483. void CcHnDockPageBar::GetCaptionRect(LPRECT lpRect)
  1484. {
  1485. CRect rcBar,cr;
  1486. GetWindowRect(rcBar);
  1487. rcBar.left+=1;
  1488. rcBar.right-=3;
  1489. rcBar.top-=1;
  1490. rcBar.bottom=rcBar.top+CAPTION_HEIGHT;
  1491. *lpRect=rcBar;
  1492. }
  1493. BOOL CcHnDockPageBar::AddPage(CWnd *pWnd, LPCTSTR sText, UINT IconID)
  1494. {
  1495. ASSERT(IsWindow(pWnd->m_hWnd));
  1496. DWORD dwStyle=pWnd->GetStyle();
  1497. if(!(dwStyle&WS_CHILD)){
  1498. TRACE0("Force the dock page bar content to be WS_CHILD style!");
  1499. pWnd->ModifyStyle(WS_POPUP|WS_OVERLAPPED,WS_CHILD);
  1500. }
  1501. CPageItem *pItem;
  1502. pItem = new CPageItem();
  1503. pItem->m_pWnd = pWnd;
  1504. pItem->m_pWnd->SetParent (this);
  1505. pItem->m_sText = sText;
  1506. CClientDC dc(this);
  1507. pItem->m_TabWidth = dc.GetTextExtent (sText).cx;
  1508. if(IconID)
  1509. {
  1510. pItem->m_hIcon = AfxGetApp()->LoadIcon(IconID);
  1511. pItem->m_TabWidth += 18;
  1512. }
  1513. else
  1514. pItem->m_hIcon = NULL;
  1515. pItem->m_TabWidth += 9;
  1516. if(pWnd)
  1517. {
  1518. CRect rect;
  1519. GetClientRect(rect);
  1520. pWnd->MoveWindow(rect);
  1521. pWnd->ShowWindow(SW_HIDE);
  1522. }
  1523. m_PageList.AddTail(pItem);
  1524. UpdateWindow();
  1525. return TRUE;
  1526. }
  1527. BOOL CcHnDockPageBar::AddPage(CPageItem *pPageItem)
  1528. {
  1529. pPageItem->m_pWnd->SetParent (this);
  1530. m_PageList.AddTail(pPageItem);
  1531. SetFocus();
  1532. //Fore the system to send WM_NCCALCSIZE to update the client rect
  1533. SetWindowPos(NULL,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE);
  1534. //Use the new size to update the window
  1535. UpdateWindow();
  1536. return TRUE;
  1537. }
  1538. BOOL CcHnDockPageBar::AddPage(CcHnDockPageBar *dockPageBar)
  1539. {
  1540. POSITION pos;
  1541. CPageItem* pItem;
  1542. for(pos = dockPageBar->m_PageList.GetHeadPosition();pos!=NULL;)
  1543. {
  1544. pItem=(CPageItem*)dockPageBar->m_PageList.GetNext(pos);
  1545. if(pItem)
  1546. {
  1547. AddPage(pItem);
  1548. SetActivePage(m_PageList.GetCount()-1);
  1549. }
  1550. }
  1551. dockPageBar->m_pDockContext->m_pDockSite->FloatControlBar(dockPageBar,CSize(0,0),0);
  1552. dockPageBar->m_PageList.RemoveAll();
  1553. dockPageBar->m_pDockContext->m_pDockSite->RemoveControlBar(dockPageBar);
  1554. UpdateWindow();
  1555. return dockPageBar->DestroyWindow ();
  1556. }
  1557. CPageItem* CcHnDockPageBar::DeletePage()
  1558. {
  1559. CPageItem *pItem = NULL;
  1560. POSITION pos = m_PageList.FindIndex(m_nActivePage);
  1561. if(!pos)
  1562. {
  1563. return NULL;
  1564. }
  1565. pItem = (CPageItem*)m_PageList.GetAt(pos);
  1566. pItem->m_pWnd->ShowWindow(SW_HIDE);
  1567. m_PageList.RemoveAt (pos);
  1568. m_nActivePage = -1;
  1569. //Fore the system to send WM_NCCALCSIZE to update the client rect
  1570. if(m_PageList.GetCount()==1)
  1571. SetWindowPos(NULL,0,0,0,0,SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE);
  1572. UpdateWindow();
  1573. return pItem;
  1574. }
  1575. void CcHnDockPageBar::UpdateWindow()
  1576. {
  1577. if(m_nActivePage < 0)
  1578. SetActivePage(0);
  1579. UpdateSize();
  1580. Invalidate();
  1581. SendMessage(WM_NCPAINT);;
  1582. }
  1583. void CcHnDockPageBar::DEFLECT_RECT_FOR_STATIC_LINK(CRect & rect)
  1584. {
  1585. #ifdef STATIC_MFC_LINK
  1586. switch(m_dwStyle&CBRS_ALIGN_ANY)
  1587. {
  1588. case CBRS_ALIGN_LEFT:
  1589. rect.DeflateRect(1,1,1,1);
  1590. break;
  1591. case CBRS_ALIGN_RIGHT:
  1592. rect.DeflateRect(1,1,0,1);
  1593. break;
  1594. case CBRS_ALIGN_TOP:
  1595. rect.DeflateRect(1,1,0,1);
  1596. break;
  1597. case CBRS_ALIGN_BOTTOM:
  1598. rect.DeflateRect(1,1,0,1);
  1599. break;
  1600. default:
  1601. ASSERT(FALSE);
  1602. }
  1603. #endif
  1604. }
  1605. void CcHnDockPageBar::OnNcPaint()
  1606. {
  1607. //If you are drawing the plastic line to change the dock page bar'size,
  1608. //No painting will be done to avoid the dirty result
  1609. if(m_bTracking)
  1610. return;
  1611. // get window DC that is clipped to the non-client area
  1612. CWindowDC dc(this);
  1613. CRect rcClient, rcBar;
  1614. GetClientRect(rcClient);
  1615. ClientToScreen(rcClient);
  1616. rcClient.DeflateRect(-1,0,-1,0);
  1617. GetWindowRect(rcBar);
  1618. rcClient.OffsetRect(-rcBar.TopLeft());
  1619. rcBar.OffsetRect(-rcBar.TopLeft());
  1620. CDC mdc;
  1621. mdc.CreateCompatibleDC(&dc);
  1622. CBitmap bm;
  1623. bm.CreateCompatibleBitmap(&dc, rcBar.Width(), rcBar.Height());
  1624. CBitmap* pOldBm = mdc.SelectObject(&bm);
  1625. // draw borders in non-client area
  1626. CRect rcDraw = rcBar;
  1627. DrawBorders(&mdc, rcDraw);
  1628. // erase the NC background
  1629. mdc.FillRect(rcDraw, CBrush::FromHandle(
  1630. (HBRUSH) GetClassLong(m_hWnd, GCL_HBRBACKGROUND)));
  1631. //Draw border edges
  1632. if (m_dwSCBStyle & SCBS_SHOWEDGES)
  1633. {
  1634. CRect rcEdge; // paint the sizing edges
  1635. for (int i = 0; i < 4; i++)
  1636. if (GetEdgeRect(rcBar, GetEdgeHTCode(i), rcEdge))
  1637. mdc.Draw3dRect(rcEdge, ::GetSysColor(COLOR_BTNHIGHLIGHT),
  1638. ::GetSysColor(COLOR_BTNSHADOW));
  1639. }
  1640. //Draw Gripper(the caption bar)
  1641. CRect rc=rcClient;
  1642. DEFLECT_RECT_FOR_STATIC_LINK(rcClient);
  1643. NcPaintGripper(&mdc, rcClient);
  1644. rcClient=rc; //restore
  1645. //Draw Client Boarder
  1646. CRect clientBorderRc=rcBar;
  1647. clientBorderRc.left=rcClient.left-1;
  1648. clientBorderRc.right=rcClient.right;
  1649. DEFLECT_RECT_FOR_STATIC_LINK(clientBorderRc);
  1650. //if (IsHorzDocked())
  1651. // clientBorderRc.DeflateRect(1,m_cyGripper,5,3);
  1652. //else
  1653. // clientBorderRc.DeflateRect(1,m_cyGripper,3,3);
  1654. if (IsHorzDocked())
  1655. clientBorderRc.DeflateRect(0,m_cyGripper,0,3);
  1656. else
  1657. clientBorderRc.DeflateRect(0,m_cyGripper,0,3);
  1658. if(m_PageList.GetCount()>1)
  1659. clientBorderRc.DeflateRect(0,0,0,ITEMBUTTON_HEIGHT);
  1660. CPen penRect(PS_SOLID, 1, RGB(128,128,128));
  1661. HPEN oldPen = (HPEN)mdc.SelectObject (&penRect);
  1662. mdc.MoveTo(clientBorderRc.TopLeft());
  1663. mdc.LineTo(clientBorderRc.right,clientBorderRc.top);
  1664. mdc.LineTo(clientBorderRc.right,clientBorderRc.bottom);
  1665. mdc.LineTo(clientBorderRc.left,clientBorderRc.bottom);
  1666. mdc.LineTo(clientBorderRc.left,clientBorderRc.top);
  1667. mdc.SelectObject (oldPen);
  1668. //Draw item tab button
  1669. if(m_PageList.GetCount()>1)
  1670. {
  1671. CPageItem *pItem;
  1672. POSITION pos;
  1673. int nItemIndex = 0;
  1674. CRect rect,wndRect;
  1675. GetItemGroupRect(&rect);
  1676. GetWindowRect(&wndRect);
  1677. rect.OffsetRect(-wndRect.TopLeft());
  1678. rect.OffsetRect(0,-1);
  1679. DEFLECT_RECT_FOR_STATIC_LINK(rect);
  1680. //rect.DeflateRect(0,-2,0,0);
  1681. CBrush brush(RGB(247,243,233));
  1682. mdc.FillRect(rect,&brush);
  1683. CPen penButton(PS_SOLID,1,GetSysColor(COLOR_3DDKSHADOW));
  1684. HPEN oldPen = (HPEN)mdc.SelectObject (&penButton);
  1685. mdc.MoveTo (rect.TopLeft() );
  1686. mdc.LineTo (rect.right, rect.top);
  1687. mdc.SelectObject (oldPen);
  1688. HFONT oldFont = (HFONT)mdc.SelectObject (m_font);
  1689. // draw PageItem
  1690. for(pos=m_PageList.GetHeadPosition();pos!=NULL;nItemIndex++)
  1691. {
  1692. pItem=(CPageItem*)m_PageList.GetNext(pos);
  1693. if(pItem)
  1694. {
  1695. pItem->Draw(&mdc,(m_nActivePage==nItemIndex)?TRUE:FALSE);
  1696. }
  1697. }
  1698. mdc.SelectObject (oldFont);
  1699. //2011-10-31 add
  1700. DeleteObject( penButton );
  1701. DeleteObject( brush );
  1702. }
  1703. // client area is not our bussiness :)
  1704. dc.IntersectClipRect(rcBar);
  1705. rcClient.DeflateRect(1,0,1,0);
  1706. dc.ExcludeClipRect(rcClient);
  1707. dc.BitBlt(0, 0, rcBar.Width(), rcBar.Height(), &mdc, 0, 0, SRCCOPY);
  1708. ReleaseDC(&dc);
  1709. mdc.SelectObject(pOldBm);
  1710. bm.DeleteObject();
  1711. mdc.DeleteDC();
  1712. //2011-10-31 add
  1713. DeleteObject( penRect );
  1714. }
  1715. /////////////////////////////////////////////////////////////////////////////
  1716. //
  1717. void CcHnDockPageBar::OnNcLButtonUp(UINT nHitTest, CPoint point)
  1718. {
  1719. if (nHitTest == HTCLOSE)
  1720. {
  1721. m_pDockSite->ShowControlBar(this, FALSE, FALSE); // hide
  1722. }
  1723. if (nHitTest == HTSTUD)
  1724. OnStudClick();
  1725. baseCDockPageBar::OnNcLButtonUp(nHitTest, point);
  1726. if(::IsWindow(m_hWnd))
  1727. SendMessage(WM_NCPAINT);
  1728. }
  1729. void CcHnDockPageBar::OnNcLButtonDown(UINT nFlags, CPoint point)
  1730. {
  1731. #if 1
  1732. if (nFlags == HTCLOSE)
  1733. {
  1734. m_pDockSite->ShowControlBar(this, FALSE, FALSE); // hide
  1735. }
  1736. if (nFlags == HTSTUD)
  1737. OnStudClick();
  1738. baseCDockPageBar::OnNcLButtonDown(nFlags, point);
  1739. if(::IsWindow(m_hWnd))
  1740. SendMessage(WM_NCPAINT);
  1741. #else
  1742. UINT nItemIndex=0;
  1743. POSITION pos;
  1744. CPageItem *pItem;
  1745. CRect rect;
  1746. //Note: Here the rect coordinate is for NonClient painting,
  1747. // so it is referenced to the current window's topleft.
  1748. GetWindowRect(&rect);
  1749. point.Offset(-rect.TopLeft());
  1750. if (HTITEMBUTTON==nFlags){
  1751. for(pos=m_PageList.GetHeadPosition();pos!=NULL;nItemIndex++)
  1752. {
  1753. pItem=(CPageItem*)m_PageList.GetNext(pos);
  1754. if(pItem)
  1755. {
  1756. if(pItem->m_rect.PtInRect(point))
  1757. {
  1758. SetFocus();
  1759. SetActivePage(nItemIndex);
  1760. CanDrag(point); // drag PageItem
  1761. return;
  1762. }
  1763. }
  1764. }
  1765. }
  1766. //Note: Here the rect coordinate is referenced to the screen
  1767. point.Offset(rect.TopLeft());
  1768. if ((nFlags >= HTSIZEFIRST) && (nFlags <= HTSIZELAST))
  1769. {
  1770. baseCDockPageBar::OnNcLButtonDown(nFlags, point);
  1771. return;
  1772. }
  1773. ((CDockPageBarContext*)m_pDockContext)->m_isPage = FALSE;
  1774. if (m_pDockBar != NULL&&HTGRIPPER==nFlags)
  1775. {
  1776. // start the drag
  1777. SetFocus();
  1778. ASSERT(m_pDockContext != NULL);
  1779. m_pDockContext->StartDrag(point);
  1780. }
  1781. else
  1782. CWnd::OnNcLButtonDown(nFlags, point);
  1783. #endif
  1784. }
  1785. void CcHnDockPageBar::OnNcLButtonDblClk(UINT nFlags, CPoint point)
  1786. {
  1787. return;
  1788. if (HTGRIPPER==nFlags&&m_pDockBar != NULL)
  1789. {
  1790. // start the drag
  1791. ASSERT(m_pDockContext != NULL);
  1792. m_pDockContext->ToggleDocking();
  1793. }
  1794. else
  1795. CWnd::OnNcLButtonDblClk(nFlags, point);
  1796. }
  1797. void CcHnDockPageBar::EnableDocking(DWORD dwDockStyle)
  1798. {
  1799. // must be CBRS_ALIGN_XXX or CBRS_FLOAT_MULTI only
  1800. ASSERT((dwDockStyle & ~(CBRS_ALIGN_ANY|CBRS_FLOAT_MULTI)) == 0);
  1801. // cannot have the CBRS_FLOAT_MULTI style
  1802. ASSERT((dwDockStyle & CBRS_FLOAT_MULTI) == 0);
  1803. // the bar must have CBRS_SIZE_DYNAMIC style
  1804. ASSERT((m_dwStyle & CBRS_SIZE_DYNAMIC) != 0);
  1805. m_dwDockStyle = dwDockStyle;
  1806. if (m_pDockContext == NULL)
  1807. {
  1808. m_pDockContext = new CDockPageBarContext(this);
  1809. m_pDPBContext.AddTail(m_pDockContext); //hengai
  1810. }
  1811. // permanently wire the bar's owner to its current parent
  1812. if (m_hWndOwner == NULL)
  1813. m_hWndOwner = ::GetParent(m_hWnd);
  1814. }
  1815. void CcHnDockPageBar::CanDrag(CPoint pt)
  1816. {
  1817. SetCapture();
  1818. // get messages until capture lost or cancelled/accepted
  1819. while (CWnd::GetCapture() == this)
  1820. {
  1821. MSG msg;
  1822. if (!::GetMessage(&msg, NULL, 0, 0))
  1823. {
  1824. AfxPostQuitMessage(msg.wParam);
  1825. break;
  1826. }
  1827. switch (msg.message)
  1828. {
  1829. case WM_LBUTTONUP:
  1830. ReleaseCapture();
  1831. break;
  1832. case WM_MOUSEMOVE:
  1833. Move(msg.pt);
  1834. break;
  1835. default:
  1836. DispatchMessage(&msg);
  1837. break;
  1838. }
  1839. }
  1840. }
  1841. void CcHnDockPageBar::Move(CPoint pt)
  1842. {
  1843. CRect rect,wndRect;
  1844. //Note: Here the rect coordinate is for NonClient painting,
  1845. // so it is referenced to the current window's topleft.
  1846. GetWindowRect(&wndRect);
  1847. GetItemGroupRect(&rect);
  1848. rect.OffsetRect(-wndRect.TopLeft());
  1849. pt.Offset(-wndRect.TopLeft());
  1850. if(rect.PtInRect(pt))
  1851. {
  1852. int nItemIndex=0;
  1853. POSITION pos;
  1854. CPageItem *pItem;
  1855. for(pos=m_PageList.GetHeadPosition();pos!=NULL;nItemIndex++)
  1856. {
  1857. pItem=(CPageItem*)m_PageList.GetNext(pos);
  1858. if(pItem)
  1859. {
  1860. if(pItem->m_rect.PtInRect(pt))
  1861. {
  1862. if(nItemIndex != m_nActivePage)
  1863. {
  1864. POSITION oldPos = m_PageList.FindIndex(m_nActivePage);
  1865. POSITION curPos = m_PageList.FindIndex(nItemIndex);
  1866. CPageItem *pOldItem = (CPageItem*)m_PageList.GetAt(oldPos);
  1867. // exchange PageItem
  1868. m_PageList.SetAt(oldPos, pItem);
  1869. m_PageList.SetAt(curPos, pOldItem);
  1870. m_nActivePage = nItemIndex;
  1871. UpdateWindow();
  1872. break;
  1873. }
  1874. }
  1875. }
  1876. }
  1877. }
  1878. else
  1879. {
  1880. ReleaseCapture();
  1881. StartDrag(pt);
  1882. }
  1883. }
  1884. void CcHnDockPageBar::StartDrag(CPoint pt)
  1885. {
  1886. ClientToScreen(&pt);
  1887. ((CDockPageBarContext*)m_pDockContext)->m_isPage = TRUE;
  1888. m_pDockContext->StartDrag(pt);
  1889. ((CDockPageBarContext*)m_pDockContext)->m_isPage = FALSE;
  1890. }
  1891. // draw title bar
  1892. /////////////////////////////////////////////////////////////////////////////
  1893. // CDockPageBarContext
  1894. #define _AfxGetDlgCtrlID(hWnd) ((UINT)(WORD)::GetDlgCtrlID(hWnd))
  1895. #define CX_BORDER 1
  1896. #define CY_BORDER 1
  1897. #define CBRS_ALIGN_INSERT_PAGE 0x0001L // drag to another CDockPageBar
  1898. #define HORZF(dw) (dw & CBRS_ORIENT_HORZ)
  1899. #define VERTF(dw) (dw & CBRS_ORIENT_VERT)
  1900. static void AFXAPI _AfxAdjustRectangle(CRect& rect, CPoint pt)
  1901. {
  1902. int nXOffset = (pt.x < rect.left) ? (pt.x - rect.left) :
  1903. (pt.x > rect.right) ? (pt.x - rect.right) : 0;
  1904. int nYOffset = (pt.y < rect.top) ? (pt.y - rect.top) :
  1905. (pt.y > rect.bottom) ? (pt.y - rect.bottom) : 0;
  1906. rect.OffsetRect(nXOffset, nYOffset);
  1907. }
  1908. void CDockPageBarContext::StartDrag(CPoint pt)
  1909. {
  1910. ASSERT_VALID(m_pBar);
  1911. m_bDragging = TRUE;
  1912. InitLoop();
  1913. // GetWindowRect returns screen coordinates(not mirrored),
  1914. // so if the desktop is mirrored then turn off mirroring
  1915. // for the desktop dc so that we get correct focus rect drawn.
  1916. // This layout change should be remembered, just in case ...
  1917. if (m_pDC->GetLayout() & LAYOUT_RTL)
  1918. m_pDC->SetLayout(LAYOUT_LTR);
  1919. if (m_pBar->m_dwStyle & CBRS_SIZE_DYNAMIC)
  1920. {
  1921. // get true bar size (including borders)
  1922. CRect rect;
  1923. m_pBar->GetWindowRect(rect);
  1924. m_ptLast = pt;
  1925. CSize sizeHorz = m_pBar->CalcDynamicLayout(0, LM_HORZ | LM_HORZDOCK);
  1926. CSize sizeVert = m_pBar->CalcDynamicLayout(0, LM_VERTDOCK);
  1927. CSize sizeFloat = m_pBar->CalcDynamicLayout(0, LM_HORZ | LM_MRUWIDTH);
  1928. m_rectDragHorz = CRect(rect.TopLeft(), sizeHorz);
  1929. m_rectDragVert = CRect(rect.TopLeft(), sizeVert);
  1930. // calculate frame dragging rectangle
  1931. m_rectFrameDragHorz = CRect(rect.TopLeft(), sizeFloat);
  1932. m_rectFrameDragVert = CRect(rect.TopLeft(), sizeFloat);
  1933. CMiniFrameWnd::CalcBorders(&m_rectFrameDragHorz);
  1934. CMiniFrameWnd::CalcBorders(&m_rectFrameDragVert);
  1935. m_rectFrameDragHorz.InflateRect(-afxData.cxBorder2, -afxData.cyBorder2);
  1936. m_rectFrameDragVert.InflateRect(-afxData.cxBorder2, -afxData.cyBorder2);
  1937. }
  1938. else if (m_pBar->m_dwStyle & CBRS_SIZE_FIXED)
  1939. {
  1940. // get true bar size (including borders)
  1941. CRect rect;
  1942. m_pBar->GetWindowRect(rect);
  1943. m_ptLast = pt;
  1944. CSize sizeHorz = m_pBar->CalcDynamicLayout(-1, LM_HORZ | LM_HORZDOCK);
  1945. CSize sizeVert = m_pBar->CalcDynamicLayout(-1, LM_VERTDOCK);
  1946. // calculate frame dragging rectangle
  1947. m_rectFrameDragHorz = m_rectDragHorz = CRect(rect.TopLeft(), sizeHorz);
  1948. m_rectFrameDragVert = m_rectDragVert = CRect(rect.TopLeft(), sizeVert);
  1949. CMiniFrameWnd::CalcBorders(&m_rectFrameDragHorz);
  1950. CMiniFrameWnd::CalcBorders(&m_rectFrameDragVert);
  1951. m_rectFrameDragHorz.InflateRect(-afxData.cxBorder2, -afxData.cyBorder2);
  1952. m_rectFrameDragVert.InflateRect(-afxData.cxBorder2, -afxData.cyBorder2);
  1953. }
  1954. else
  1955. {
  1956. // get true bar size (including borders)
  1957. CRect rect;
  1958. m_pBar->GetWindowRect(rect);
  1959. m_ptLast = pt;
  1960. BOOL bHorz = HORZF(m_dwStyle);
  1961. DWORD dwMode = !bHorz ? (LM_HORZ | LM_HORZDOCK) : LM_VERTDOCK;
  1962. CSize size = m_pBar->CalcDynamicLayout(-1, dwMode);
  1963. // calculate inverted dragging rect
  1964. if (bHorz)
  1965. {
  1966. m_rectDragHorz = rect;
  1967. m_rectDragVert = CRect(CPoint(pt.x - rect.Height()/2, rect.top), size);
  1968. }
  1969. else // vertical orientation
  1970. {
  1971. m_rectDragVert = rect;
  1972. m_rectDragHorz = CRect(CPoint(rect.left, pt.y - rect.Width()/2), size);
  1973. }
  1974. // calculate frame dragging rectangle
  1975. m_rectFrameDragHorz = m_rectDragHorz;
  1976. m_rectFrameDragVert = m_rectDragVert;
  1977. CMiniFrameWnd::CalcBorders(&m_rectFrameDragHorz);
  1978. CMiniFrameWnd::CalcBorders(&m_rectFrameDragVert);
  1979. m_rectFrameDragHorz.InflateRect(-afxData.cxBorder2, -afxData.cyBorder2);
  1980. m_rectFrameDragVert.InflateRect(-afxData.cxBorder2, -afxData.cyBorder2);
  1981. }
  1982. // adjust rectangles so that point is inside
  1983. _AfxAdjustRectangle(m_rectDragHorz, pt);
  1984. _AfxAdjustRectangle(m_rectDragVert, pt);
  1985. _AfxAdjustRectangle(m_rectFrameDragHorz, pt);
  1986. _AfxAdjustRectangle(m_rectFrameDragVert, pt);
  1987. // initialize tracking state and enter tracking loop
  1988. m_dwOverDockStyle = CanDock();
  1989. Move(pt); // call it here to handle special keys
  1990. Track();
  1991. }
  1992. CDockPageBarContext::~CDockPageBarContext(void)
  1993. {
  1994. }
  1995. //hengai
  1996. void CDockPageBarContext::FreeAll()
  1997. {
  1998. for(POSITION pos = m_pDPBar.GetHeadPosition(); pos;)
  1999. {
  2000. CDockPageBar* pBar = (CDockPageBar*)m_pDPBar.GetNext(pos);
  2001. ASSERT(pBar != NULL);
  2002. delete pBar->m_pDockBar; pBar->m_pDockBar = NULL;
  2003. delete pBar; pBar = NULL;
  2004. }
  2005. m_pDPBar.RemoveAll (); // cuick 2004/04/08
  2006. }
  2007. BOOL CDockPageBarContext::Track()
  2008. {
  2009. // don't handle if capture already set
  2010. if (::GetCapture() != NULL)
  2011. return FALSE;
  2012. // set capture to the window which received this message
  2013. m_pBar->SetCapture();
  2014. ASSERT(m_pBar == CWnd::GetCapture());
  2015. // get messages until capture lost or cancelled/accepted
  2016. while (CWnd::GetCapture() == m_pBar)
  2017. {
  2018. MSG msg;
  2019. if (!::GetMessage(&msg, NULL, 0, 0))
  2020. {
  2021. AfxPostQuitMessage(msg.wParam);
  2022. break;
  2023. }
  2024. switch (msg.message)
  2025. {
  2026. case WM_LBUTTONUP:
  2027. if (m_bDragging)
  2028. EndDrag();
  2029. else
  2030. EndResize();
  2031. return TRUE;
  2032. case WM_MOUSEMOVE:
  2033. if (m_bDragging)
  2034. Move(msg.pt);
  2035. else
  2036. Stretch(msg.pt);
  2037. break;
  2038. case WM_KEYUP:
  2039. if (m_bDragging)
  2040. OnKey((int)msg.wParam, FALSE);
  2041. break;
  2042. case WM_KEYDOWN:
  2043. if (m_bDragging)
  2044. OnKey((int)msg.wParam, TRUE);
  2045. if (msg.wParam == VK_ESCAPE)
  2046. {
  2047. CancelLoop();
  2048. return FALSE;
  2049. }
  2050. break;
  2051. case WM_RBUTTONDOWN:
  2052. CancelLoop();
  2053. return FALSE;
  2054. // just dispatch rest of the messages
  2055. default:
  2056. DispatchMessage(&msg);
  2057. break;
  2058. }
  2059. }
  2060. CancelLoop();
  2061. return FALSE;
  2062. }
  2063. CDockPageBar * CDockPageBarContext::TryToGetDockPageBar(POINT pt)
  2064. {
  2065. CFrameWnd * pFrameWnd=(CFrameWnd *)AfxGetMainWnd();
  2066. POSITION pos = pFrameWnd->m_listControlBars.GetHeadPosition();
  2067. while (pos != NULL)
  2068. {
  2069. CControlBar* pBar = (CControlBar*)pFrameWnd->m_listControlBars.GetNext(pos);
  2070. ASSERT(pBar != NULL);
  2071. if (pBar->IsKindOf(RUNTIME_CLASS(CDockPageBar)))
  2072. {
  2073. CRect rect;
  2074. pBar->GetWindowRect(&rect);
  2075. if(rect.PtInRect(pt)&&!pBar->IsFloating())
  2076. return (CDockPageBar*)pBar;
  2077. }
  2078. }
  2079. return NULL;
  2080. }
  2081. //////////////////////////////////////////////////////////////////////
  2082. // drag and draw focus rect
  2083. void CDockPageBarContext::Move(CPoint pt)
  2084. {
  2085. CPoint ptOffset = pt - m_ptLast;
  2086. if(TRUE == isDockPage(pt))
  2087. {
  2088. m_dwOverDockStyle = CBRS_ALIGN_INSERT_PAGE;
  2089. }
  2090. else
  2091. {
  2092. //MACRO Definition for the adavnced docking
  2093. //#define CBRS_ALIGN_INSERT_PAGE 0x0001L
  2094. #define DOCK_ALIGN_INSERT_PAGE CBRS_ALIGN_INSERT_PAGE
  2095. #define DOCK_IN_FRAME_CLIENT 0x02
  2096. #define DOCK_IN_FRAME_BORDER 0x04
  2097. #define DOCK_IN_DOCK_PAGE_BAR 0x08
  2098. #define HOR_BORDER_DETECT_PIXELS max(CAPTION_HEIGHT+8,ITEMBUTTON_HEIGHT+8)
  2099. #define VER_BORDER_DETECT_PIXELS 16
  2100. #define BORDER_DETECT_LEFT 0x0100
  2101. #define BORDER_DETECT_RIGHT 0x0200
  2102. #define BORDER_DETECT_TOP 0x0400
  2103. #define BORDER_DETECT_BOTTOM 0x0800
  2104. //POINT pt;
  2105. //GetCursorPos(&pt);
  2106. CWnd *pCurWnd= CWnd::FromHandle(::WindowFromPoint(pt));
  2107. CDockPageBar *pDockPageBarWnd;
  2108. DWORD borderDetect=0;
  2109. CRect mainFrameRect,mainFrameClientRect;
  2110. DWORD dwDockStyle=0;
  2111. m_bAdvancedDock=FALSE;
  2112. m_endDragDockStruct.dwDockStyle=0;
  2113. CWnd *pMainFrameWnd=AfxGetMainWnd();
  2114. pMainFrameWnd->GetWindowRect(&mainFrameRect);
  2115. //Try to find a docking position
  2116. if(mainFrameRect.PtInRect(pt))
  2117. {
  2118. //Get the pure client rect of the frame wnd
  2119. GET_MAIN_FRAME_PURE_CLIENT(pMainFrameWnd,mainFrameClientRect);
  2120. if((pDockPageBarWnd=TryToGetDockPageBar(pt))!=NULL){
  2121. pDockPageBarWnd->GetWindowRect(&m_curRect);
  2122. m_endDragDockStruct.dwDockStyle=dwDockStyle=DOCK_IN_DOCK_PAGE_BAR;
  2123. m_bAdvancedDock=TRUE;
  2124. }else if(mainFrameClientRect.PtInRect(pt)){
  2125. m_curRect=mainFrameClientRect;
  2126. m_endDragDockStruct.dwDockStyle=dwDockStyle=DOCK_IN_FRAME_CLIENT;
  2127. m_bAdvancedDock=TRUE;
  2128. }else{ //the bar is move to the non client area (tool bar for example)
  2129. CRect rc=mainFrameClientRect;
  2130. rc.DeflateRect(-VER_BORDER_DETECT_PIXELS,-HOR_BORDER_DETECT_PIXELS);
  2131. if(rc.PtInRect(pt)){
  2132. m_curRect=rc;
  2133. m_endDragDockStruct.dwDockStyle=dwDockStyle=DOCK_IN_FRAME_BORDER;
  2134. m_bAdvancedDock=TRUE;
  2135. }else{
  2136. const CRuntimeClass * pRunTimeClass=pCurWnd->GetRuntimeClass();
  2137. TRACE0("Unprocessed window type:");
  2138. TRACE0(pRunTimeClass->m_lpszClassName);
  2139. TRACE0("\r\n");
  2140. m_bAdvancedDock=FALSE;
  2141. }
  2142. }
  2143. }else{
  2144. CRect rc=mainFrameRect;
  2145. rc.DeflateRect(-VER_BORDER_DETECT_PIXELS,-HOR_BORDER_DETECT_PIXELS);
  2146. if(rc.PtInRect(pt)){
  2147. m_curRect=rc;
  2148. m_endDragDockStruct.dwDockStyle=dwDockStyle=DOCK_IN_FRAME_BORDER;
  2149. m_bAdvancedDock=TRUE;
  2150. }else{
  2151. const CRuntimeClass * pRunTimeClass=pCurWnd->GetRuntimeClass();
  2152. TRACE0("Unprocessed window type:");
  2153. TRACE0(pRunTimeClass->m_lpszClassName);
  2154. TRACE0("\r\n");
  2155. m_bAdvancedDock=FALSE;
  2156. }
  2157. }
  2158. //Check whether the current position can be used for the advanced docking :-)
  2159. if(m_bAdvancedDock&&
  2160. m_curRect.Width()>VER_BORDER_DETECT_PIXELS*2+1&&
  2161. m_curRect.Height()>HOR_BORDER_DETECT_PIXELS*2+1)
  2162. {
  2163. //Init the current detection border rect
  2164. CRect rectLeft(m_curRect.TopLeft(),CSize(VER_BORDER_DETECT_PIXELS,m_curRect.Height())),
  2165. rectTop(m_curRect.TopLeft(),CSize(m_curRect.Width(),HOR_BORDER_DETECT_PIXELS));
  2166. CRect rectRight=rectLeft,rectBottom=rectTop;
  2167. rectRight.OffsetRect(m_curRect.Width()-VER_BORDER_DETECT_PIXELS,0);
  2168. rectBottom.OffsetRect(0,m_curRect.Height()-HOR_BORDER_DETECT_PIXELS);
  2169. borderDetect|=rectLeft.PtInRect(pt) ? BORDER_DETECT_LEFT:0;
  2170. borderDetect|=rectRight.PtInRect(pt) ? BORDER_DETECT_RIGHT:0;
  2171. borderDetect|=rectTop.PtInRect(pt) ? BORDER_DETECT_TOP:0;
  2172. borderDetect|=rectBottom.PtInRect(pt) ? BORDER_DETECT_BOTTOM:0;
  2173. ASSERT(!((borderDetect&BORDER_DETECT_LEFT)&&(borderDetect&BORDER_DETECT_RIGHT)));
  2174. ASSERT(!((borderDetect&BORDER_DETECT_TOP)&&(borderDetect&BORDER_DETECT_BOTTOM)));
  2175. if(borderDetect&BORDER_DETECT_LEFT)
  2176. {
  2177. borderDetect=BORDER_DETECT_LEFT;
  2178. if(DOCK_IN_FRAME_CLIENT==dwDockStyle||DOCK_IN_FRAME_BORDER==dwDockStyle)
  2179. dwDockStyle=CBRS_ALIGN_LEFT;
  2180. else
  2181. dwDockStyle=pDockPageBarWnd->m_dwStyle;
  2182. }else if(borderDetect&BORDER_DETECT_RIGHT){
  2183. borderDetect=BORDER_DETECT_RIGHT;
  2184. if(DOCK_IN_FRAME_CLIENT==dwDockStyle||DOCK_IN_FRAME_BORDER==dwDockStyle)
  2185. dwDockStyle=CBRS_ALIGN_RIGHT;
  2186. else
  2187. dwDockStyle=pDockPageBarWnd->m_dwStyle;
  2188. }else if(borderDetect&BORDER_DETECT_TOP){
  2189. borderDetect=BORDER_DETECT_TOP;
  2190. if(DOCK_IN_FRAME_CLIENT==dwDockStyle||DOCK_IN_FRAME_BORDER==dwDockStyle)
  2191. dwDockStyle=CBRS_ALIGN_TOP;
  2192. else
  2193. dwDockStyle=pDockPageBarWnd->m_dwStyle;
  2194. }else if(borderDetect&BORDER_DETECT_BOTTOM){
  2195. borderDetect=BORDER_DETECT_BOTTOM;
  2196. if(DOCK_IN_FRAME_CLIENT==dwDockStyle||DOCK_IN_FRAME_BORDER==dwDockStyle)
  2197. dwDockStyle=CBRS_ALIGN_BOTTOM;
  2198. else
  2199. dwDockStyle=pDockPageBarWnd->m_dwStyle;
  2200. }
  2201. CRect rc;
  2202. m_pBar->GetWindowRect(&rc);
  2203. INT hightWidth;
  2204. if(DOCK_IN_FRAME_BORDER==m_endDragDockStruct.dwDockStyle)
  2205. {
  2206. m_curRect.DeflateRect(VER_BORDER_DETECT_PIXELS,HOR_BORDER_DETECT_PIXELS);
  2207. if(borderDetect&(BORDER_DETECT_LEFT|BORDER_DETECT_RIGHT)){
  2208. if(m_curRect==mainFrameClientRect)
  2209. (borderDetect&BORDER_DETECT_LEFT ? m_curRect.left:m_curRect.right)=
  2210. (borderDetect&BORDER_DETECT_LEFT ? mainFrameClientRect.left:mainFrameClientRect.right);
  2211. else
  2212. (borderDetect&BORDER_DETECT_LEFT ? m_curRect.left:m_curRect.right)=
  2213. (borderDetect&BORDER_DETECT_LEFT ? mainFrameRect.left:mainFrameRect.right);
  2214. m_curRect.top=mainFrameRect.top;
  2215. m_curRect.bottom=mainFrameRect.bottom;
  2216. }else{
  2217. if(m_curRect==mainFrameClientRect)
  2218. (borderDetect&BORDER_DETECT_TOP ? m_curRect.top:m_curRect.bottom)=
  2219. (borderDetect&BORDER_DETECT_TOP ? mainFrameClientRect.top:mainFrameClientRect.bottom);
  2220. else
  2221. (borderDetect&BORDER_DETECT_TOP ? m_curRect.top:m_curRect.bottom)=
  2222. (borderDetect&BORDER_DETECT_TOP ? mainFrameRect.top:mainFrameRect.bottom);
  2223. m_curRect.left=mainFrameRect.left;
  2224. m_curRect.right=mainFrameRect.right;
  2225. }
  2226. hightWidth=borderDetect&(BORDER_DETECT_LEFT|BORDER_DETECT_RIGHT) ? mainFrameRect.Width():mainFrameRect.Height();
  2227. }else
  2228. hightWidth=borderDetect&(BORDER_DETECT_LEFT|BORDER_DETECT_RIGHT) ? rc.Width():rc.Height();
  2229. switch(borderDetect)
  2230. {
  2231. case BORDER_DETECT_LEFT:
  2232. m_curRect.right=m_curRect.left+min(hightWidth,m_curRect.Width()/2);
  2233. break;
  2234. case BORDER_DETECT_RIGHT:
  2235. m_curRect.left=m_curRect.right-min(hightWidth,m_curRect.Width()/2);
  2236. break;
  2237. case BORDER_DETECT_TOP:
  2238. m_curRect.bottom=m_curRect.top+min(hightWidth,m_curRect.Height()/2);
  2239. break;
  2240. case BORDER_DETECT_BOTTOM:
  2241. m_curRect.top=m_curRect.bottom-min(hightWidth,m_curRect.Height()/2);
  2242. break;
  2243. default:
  2244. m_bAdvancedDock=FALSE;
  2245. }
  2246. }else
  2247. m_bAdvancedDock=FALSE;
  2248. if(m_bAdvancedDock){
  2249. ASSERT(VERTF(dwDockStyle)||HORZF(dwDockStyle));
  2250. m_dwOverDockStyle=dwDockStyle;
  2251. if(DOCK_IN_DOCK_PAGE_BAR==m_endDragDockStruct.dwDockStyle){
  2252. m_endDragDockStruct.pDockPageBar=pDockPageBarWnd;
  2253. m_endDragDockStruct.dwDockStyle|=borderDetect;
  2254. }
  2255. else
  2256. m_endDragDockStruct.pDockPageBar=NULL;;
  2257. m_rectDragVert.OffsetRect(ptOffset);
  2258. m_rectDragHorz.OffsetRect(ptOffset);
  2259. m_rectFrameDragHorz.OffsetRect(ptOffset);
  2260. m_rectFrameDragVert.OffsetRect(ptOffset);
  2261. }else{
  2262. // offset all drag rects to new position
  2263. m_rectDragHorz.OffsetRect(ptOffset);
  2264. m_rectFrameDragHorz.OffsetRect(ptOffset);
  2265. m_rectDragVert.OffsetRect(ptOffset);
  2266. m_rectFrameDragVert.OffsetRect(ptOffset);
  2267. m_dwOverDockStyle = 0;/*m_bForceFrame ? 0 : CanDock();*/
  2268. }
  2269. }
  2270. m_ptLast = pt;
  2271. // update feedback
  2272. if(FALSE == m_isMe)
  2273. DrawFocusRect();
  2274. else
  2275. DrawFocusRect(TRUE);
  2276. }
  2277. // get the target CDockPageBar on mouse move
  2278. BOOL CDockPageBarContext::isDockPage(CPoint pt)
  2279. {
  2280. m_isMe = FALSE;
  2281. HWND hWnd = WindowFromPoint(pt);
  2282. CWnd * pWnd=CWnd::FromHandle (hWnd);
  2283. if(pWnd->IsKindOf (RUNTIME_CLASS(CDockPageBar)))
  2284. {
  2285. CDockPageBar* pBar = (CDockPageBar*)pWnd;
  2286. if(pBar != m_pBar)
  2287. {
  2288. CRect rectCaption,rectItem;
  2289. pBar->GetWindowRect (&rectCaption);
  2290. rectItem=rectCaption;
  2291. rectCaption.bottom = rectCaption.top + pBar->m_cyGripper;
  2292. rectItem.top=rectItem.bottom-ITEMBUTTON_HEIGHT;
  2293. if(rectCaption.PtInRect (pt)||
  2294. (pBar->m_PageList.GetCount()>1)&&(rectItem.PtInRect(pt)))
  2295. {
  2296. m_pTgDockPage = pBar;
  2297. pBar->GetWindowRect (&m_addRect);
  2298. return TRUE;
  2299. }
  2300. }
  2301. else
  2302. {
  2303. m_isMe = TRUE;
  2304. }
  2305. }else if(pWnd->IsKindOf(RUNTIME_CLASS(CMiniDockFrameWnd))){ //Docking in the float window
  2306. CMiniDockFrameWnd * pFrameWnd=(CMiniDockFrameWnd *)pWnd;
  2307. //Get the DockPageBar on the Floating MiniDockFrameWnd
  2308. CDockPageBar* pBar = (CDockPageBar* )CWnd::FromHandle(pWnd->m_hWndOwner);
  2309. ASSERT(pBar->IsKindOf(RUNTIME_CLASS(CDockPageBar)));
  2310. if(pBar != m_pBar)
  2311. {
  2312. CRect rectCaption,rectItem;
  2313. pFrameWnd->GetWindowRect (&rectCaption);
  2314. pBar->GetWindowRect(&rectItem);
  2315. rectCaption.bottom = rectCaption.top + pBar->m_cyGripper;
  2316. rectItem.top=rectItem.bottom-ITEMBUTTON_HEIGHT;
  2317. if(rectCaption.PtInRect (pt)||
  2318. (pBar->m_PageList.GetCount()>1)&&(rectItem.PtInRect(pt)))
  2319. {
  2320. m_pTgDockPage = pBar;
  2321. pBar->GetWindowRect (&m_addRect);
  2322. return TRUE;
  2323. }
  2324. }
  2325. else
  2326. {
  2327. m_isMe = TRUE;
  2328. }
  2329. }
  2330. m_pTgDockPage = NULL;
  2331. return FALSE;
  2332. }
  2333. void CDockPageBarContext::EndDrag()
  2334. {
  2335. CancelLoop();
  2336. if(TRUE == m_isMe)
  2337. return;
  2338. // drag to another CDockPageBar
  2339. if((NULL != m_pTgDockPage) && (m_dwOverDockStyle == CBRS_ALIGN_INSERT_PAGE))
  2340. {
  2341. if(TRUE == m_isPage) // drag PageItem
  2342. {
  2343. CPageItem * pItem = (CPageItem *)((CDockPageBar*)m_pBar)->DeletePage ();
  2344. m_pTgDockPage->AddPage(pItem);
  2345. }
  2346. else // drag a CDockPageBar object to another CDockPageBar
  2347. {
  2348. m_pTgDockPage->AddPage((CDockPageBar*)m_pBar);
  2349. }
  2350. return;
  2351. }
  2352. // if drag a PageItem, create a new bar which contains the PageItem
  2353. CControlBar* pBar;
  2354. if(TRUE == m_isPage) // drag PageItem (dock or float)
  2355. pBar = CreateNewBar();
  2356. else
  2357. pBar = m_pBar; // drag CDockPageBar
  2358. if(NULL == pBar)
  2359. return;
  2360. if (m_dwOverDockStyle != 0)
  2361. {
  2362. CDockBar* pDockBar;
  2363. CFrameWnd * pFrameWnd=(CFrameWnd *)AfxGetMainWnd();
  2364. //Find the specific docking bar
  2365. POSITION pos = pFrameWnd->m_listControlBars.GetHeadPosition();
  2366. while (pos != NULL)
  2367. {
  2368. pDockBar = (CDockBar*)pFrameWnd->m_listControlBars.GetNext(pos);
  2369. if (pDockBar->IsDockBar() && pDockBar->IsWindowVisible() &&
  2370. (pDockBar->m_dwStyle & m_dwOverDockStyle & CBRS_ALIGN_ANY) &&
  2371. (!pDockBar->m_bFloating ||
  2372. (m_dwOverDockStyle & pDockBar->m_dwStyle & CBRS_FLOAT_MULTI)))
  2373. {
  2374. break;
  2375. }
  2376. }
  2377. ASSERT(pDockBar != NULL);
  2378. CRect rect;
  2379. if(m_bAdvancedDock){
  2380. rect=m_curRect;
  2381. if(m_endDragDockStruct.dwDockStyle&DOCK_IN_DOCK_PAGE_BAR)
  2382. {
  2383. ASSERT(m_endDragDockStruct.pDockPageBar);
  2384. ASSERT(m_endDragDockStruct.pDockPageBar->IsKindOf(RUNTIME_CLASS(CDockPageBar)));
  2385. CRect rc;
  2386. m_endDragDockStruct.pDockPageBar->GetWindowRect(&rc);
  2387. if(VERTF(m_endDragDockStruct.pDockPageBar->m_dwStyle))
  2388. {
  2389. if(m_endDragDockStruct.dwDockStyle&BORDER_DETECT_RIGHT)
  2390. rect.OffsetRect(rc.Width()/2,0);
  2391. else if(m_endDragDockStruct.dwDockStyle&BORDER_DETECT_LEFT)
  2392. rect.OffsetRect(-rc.Width()/2,0);
  2393. }else if(HORZF(m_endDragDockStruct.pDockPageBar->m_dwStyle))
  2394. {
  2395. if(m_endDragDockStruct.dwDockStyle&BORDER_DETECT_TOP)
  2396. rect.OffsetRect(0,-rc.Width()/2);
  2397. else if(m_endDragDockStruct.dwDockStyle&BORDER_DETECT_BOTTOM)
  2398. rect.OffsetRect(0,rc.Width()/2);
  2399. }else
  2400. ASSERT(FALSE);
  2401. }
  2402. //Advanced docking :)
  2403. if(VERTF(m_dwOverDockStyle))
  2404. {
  2405. ((CDockPageBar*)pBar)->GetVerSize().cx=rect.Width();
  2406. ((CDockPageBar*)pBar)->GetVerSize().cy=rect.Height();
  2407. }else if(HORZF(m_dwOverDockStyle))
  2408. {
  2409. ((CDockPageBar*)pBar)->GetHorSize().cx=rect.Width();
  2410. ((CDockPageBar*)pBar)->GetHorSize().cy=rect.Height();
  2411. }else
  2412. ASSERT(FALSE);
  2413. }else
  2414. rect= (m_dwOverDockStyle & CBRS_ORIENT_VERT) ? m_rectDragVert : m_rectDragHorz;
  2415. UINT uID = _AfxGetDlgCtrlID(pDockBar->m_hWnd);
  2416. if (uID >= AFX_IDW_DOCKBAR_TOP &&
  2417. uID <= AFX_IDW_DOCKBAR_BOTTOM)
  2418. {
  2419. m_uMRUDockID = uID;
  2420. m_rectMRUDockPos = rect;
  2421. pDockBar->ScreenToClient(&m_rectMRUDockPos);
  2422. }
  2423. // dock it at the specified position, RecalcLayout will snap
  2424. m_pDockSite->DockControlBar(pBar, pDockBar, &rect);
  2425. m_pDockSite->RecalcLayout();
  2426. if(DOCK_IN_DOCK_PAGE_BAR==m_endDragDockStruct.dwDockStyle)
  2427. m_endDragDockStruct.pDockPageBar->SetFocus();
  2428. }
  2429. else if ((m_dwStyle & CBRS_SIZE_DYNAMIC) || (HORZF(m_dwStyle) && !m_bFlip) ||
  2430. (VERTF(m_dwStyle) && m_bFlip))
  2431. {
  2432. m_dwMRUFloatStyle = CBRS_ALIGN_TOP | (m_dwDockStyle & CBRS_FLOAT_MULTI);
  2433. m_ptMRUFloatPos = m_rectFrameDragHorz.TopLeft();
  2434. m_pDockSite->FloatControlBar(pBar, m_ptMRUFloatPos, m_dwMRUFloatStyle);
  2435. }
  2436. else // vertical float
  2437. {
  2438. m_dwMRUFloatStyle = CBRS_ALIGN_LEFT | (m_dwDockStyle & CBRS_FLOAT_MULTI);
  2439. m_ptMRUFloatPos = m_rectFrameDragVert.TopLeft();
  2440. m_pDockSite->FloatControlBar(pBar, m_ptMRUFloatPos, m_dwMRUFloatStyle);
  2441. }
  2442. }
  2443. CDockPageBar* CDockPageBarContext::CreateNewBar()
  2444. {
  2445. CPageItem * pItem = (CPageItem *)((CDockPageBar*)m_pBar)->DeletePage ();
  2446. CDockPageBar* pBar = new CDockPageBar();
  2447. if (!(pBar->Create(_T("New Bar"), m_pDockSite, 12345)))
  2448. {
  2449. TRACE0("Failed to create mybar\n");
  2450. return NULL; // fail to create
  2451. }
  2452. pBar->SetBarStyle(m_pBar->GetBarStyle() |
  2453. CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
  2454. pBar->EnableDocking(CBRS_ALIGN_ANY);
  2455. pBar->AddPage (pItem);
  2456. m_pDPBar.AddTail(pBar);
  2457. return pBar;
  2458. }
  2459. void CDockPageBarContext::DrawFocusRect(BOOL bRemoveRect)
  2460. {
  2461. ASSERT(m_pDC != NULL);
  2462. // default to thin frame
  2463. CSize size(3,3);
  2464. // determine new rect and size
  2465. CRect rect;
  2466. CBrush* pWhiteBrush = CBrush::FromHandle((HBRUSH)::GetStockObject(WHITE_BRUSH));
  2467. CBrush* pDitherBrush = CDC::GetHalftoneBrush();
  2468. CBrush* pBrush = pDitherBrush;
  2469. if(m_bAdvancedDock)
  2470. {
  2471. rect=m_curRect;;
  2472. }else{
  2473. if (HORZF(m_dwOverDockStyle))
  2474. rect = m_rectDragHorz;
  2475. else if (VERTF(m_dwOverDockStyle))
  2476. rect = m_rectDragVert;
  2477. else
  2478. {
  2479. // use thick frame instead
  2480. size.cx = GetSystemMetrics(SM_CXFRAME) - CX_BORDER;
  2481. size.cy = GetSystemMetrics(SM_CYFRAME) - CY_BORDER;
  2482. if ((HORZF(m_dwStyle) && !m_bFlip) || (VERTF(m_dwStyle) && m_bFlip))
  2483. rect = m_rectFrameDragHorz;
  2484. else
  2485. rect = m_rectFrameDragVert;
  2486. pBrush = pDitherBrush;
  2487. }
  2488. }
  2489. if (bRemoveRect)
  2490. size.cx = size.cy = 0;
  2491. if(m_dwOverDockStyle == CBRS_ALIGN_INSERT_PAGE)
  2492. rect = m_addRect; // rect of target CDockPageBar
  2493. // draw it and remember last size
  2494. m_pDC->DrawDragRect(&rect, size, &m_rectLast, m_sizeLast,
  2495. pBrush, m_bDitherLast ? pDitherBrush : pWhiteBrush);
  2496. m_rectLast = rect;
  2497. m_sizeLast = size;
  2498. m_bDitherLast = (pBrush == pDitherBrush);
  2499. }