DockPageBar.cpp 73 KB

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