TreePropertySheet.cpp
上传用户:qifu0001
上传日期:2007-01-02
资源大小:52k
文件大小:33k
源码类别:

TreeView控件

开发平台:

Visual C++

  1. // TreePropertySheet.cpp: Implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "TreePropertySheet.h"
  5. #ifdef _DEBUG
  6. #define new DEBUG_NEW
  7. #undef THIS_FILE
  8. static char THIS_FILE[] = __FILE__;
  9. #endif
  10. /////////////////////////////////////////////////////////////////////////////
  11. // CTreePropertySheet
  12. IMPLEMENT_DYNAMIC(CTreePropertySheet, CPropertySheet)
  13. CTreePropertySheet::CTreePropertySheet(int nTreeWidth, UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
  14. : CPropertySheet(nIDCaption, pParentWnd, iSelectPage),
  15. m_cCaptionBarDC(1,1),
  16. m_cCaptionDC(1,1)
  17. {
  18. m_nTreeWidth =nTreeWidth;
  19. m_nSpaceLeft =10;
  20. m_nSpaceMid =10;
  21. m_nSpaceRight =10;
  22. m_nSpaceTop =10;
  23. m_nSpaceBottom =10;
  24. m_nCaptionHeight=32;
  25. m_bCaptionBarInvalidated=true;
  26. m_clrCaptionLeft=RGB(128,128,128);
  27. m_clrCaptionRight=RGB(128,128,128);
  28. m_clrCaptionTextLeft=RGB(255,255,255);
  29. m_clrCaptionTextRight=RGB(255,255,255);
  30. m_nCaptionBorder =tps_capborder_line;
  31. m_clrCaptionBorderTopLeft=RGB(255,255,255);
  32. m_clrCaptionBorderBottomRight=RGB(64,64,64);
  33. m_pCaptionFont =NULL;
  34. m_pCaptionDescrFont=NULL;
  35. m_bDeleteCaptionFont=false;
  36. m_bDeleteCaptionDescrFont=false;
  37. m_bSpecialCaption=false;
  38. m_bDragging=false;
  39. m_bDisableStandardButtons=false;
  40. }
  41. CTreePropertySheet::CTreePropertySheet(int nTreeWidth, LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
  42. : CPropertySheet(pszCaption, pParentWnd, iSelectPage),
  43. m_cCaptionBarDC(1,1),
  44. m_cCaptionDC(1,1)
  45. {
  46. m_nTreeWidth =nTreeWidth;
  47. m_nSpaceLeft =10;
  48. m_nSpaceMid =10;
  49. m_nSpaceRight =10;
  50. m_nSpaceTop =10;
  51. m_nSpaceBottom =10;
  52. m_nCaptionHeight=32;
  53. m_bCaptionBarInvalidated=true;
  54. m_clrCaptionLeft=RGB(128,128,128);
  55. m_clrCaptionRight=RGB(128,128,128);
  56. m_clrCaptionTextLeft=RGB(255,255,255);
  57. m_clrCaptionTextRight=RGB(255,255,255);
  58. m_nCaptionBorder =tps_capborder_line;
  59. m_clrCaptionBorderTopLeft=RGB(255,255,255);
  60. m_clrCaptionBorderBottomRight=RGB(64,64,64);
  61. m_pCaptionFont =NULL;
  62. m_pCaptionDescrFont=NULL;
  63. m_bDeleteCaptionFont=false;
  64. m_bDeleteCaptionDescrFont=false;
  65. m_bSpecialCaption=false;
  66. m_bDragging=false;
  67. m_bDisableStandardButtons=false;
  68. }
  69. CTreePropertySheet::CTreePropertySheet(CWnd* pParentWnd, UINT iSelectPage)
  70. : CPropertySheet( _T(""), pParentWnd, iSelectPage),
  71. m_cCaptionBarDC(1,1),
  72. m_cCaptionDC(1,1)
  73. {
  74. m_nTreeWidth =150;
  75. m_nSpaceLeft =10;
  76. m_nSpaceMid =10;
  77. m_nSpaceRight =10;
  78. m_nSpaceTop =10;
  79. m_nSpaceBottom =10;
  80. m_nCaptionHeight=32;
  81. m_bCaptionBarInvalidated=true;
  82. m_clrCaptionLeft=RGB(128,128,128);
  83. m_clrCaptionRight=RGB(128,128,128);
  84. m_clrCaptionTextLeft=RGB(255,255,255);
  85. m_clrCaptionTextRight=RGB(255,255,255);
  86. m_nCaptionBorder =tps_capborder_line;
  87. m_clrCaptionBorderTopLeft=RGB(255,255,255);
  88. m_clrCaptionBorderBottomRight=RGB(64,64,64);
  89. m_pCaptionFont =NULL;
  90. m_pCaptionDescrFont=NULL;
  91. m_bDeleteCaptionFont=false;
  92. m_bDeleteCaptionDescrFont=false;
  93. m_bSpecialCaption=true;
  94. m_bDragging=false;
  95. m_bDisableStandardButtons=false;
  96. }
  97. CTreePropertySheet::~CTreePropertySheet()
  98. {
  99. if(m_bDeleteCaptionFont && m_pCaptionFont!=NULL)
  100. delete m_pCaptionFont;
  101. if(m_bDeleteCaptionDescrFont && m_pCaptionDescrFont!=NULL)
  102. delete m_pCaptionDescrFont;
  103. int nControl,nControls=m_acControlPos.GetSize();
  104. for(nControl=0;nControl<nControls;nControl++) {
  105. cControlPos& cur=m_acControlPos[nControl];
  106. if(cur.bAutoDelete && cur.pWnd!=NULL)
  107. delete cur.pWnd;
  108. }
  109. int nFont,nFonts=m_apFonts.GetSize();
  110. for(nFont=0;nFont<nFonts;nFont++)
  111. delete m_apFonts[nFont];
  112. }
  113. BEGIN_MESSAGE_MAP(CTreePropertySheet, CPropertySheet)
  114. //{{AFX_MSG_MAP(CTreePropertySheet)
  115. ON_WM_PAINT()
  116. ON_WM_LBUTTONDOWN()
  117. ON_WM_LBUTTONUP()
  118. ON_WM_MOUSEMOVE()
  119. //}}AFX_MSG_MAP
  120. ON_NOTIFY(TVN_SELCHANGED,ID_TREECTRL,OnSelChanged)
  121. END_MESSAGE_MAP()
  122. /////////////////////////////////////////////////////////////////////////////
  123. // Notification handlers
  124. /*--------------------------------------------------------------------
  125. FUNCTION: OnSelChanged(NMHDR* pNotifyStruct, LRESULT* pResult);
  126. RETURNS:
  127. PURPOSE:
  128. --------------------------------------------------------------------*/
  129. void  CTreePropertySheet::OnSelChanged(
  130. NMHDR* pNotifyStruct, 
  131. LRESULT* pResult)
  132. {
  133. NMTREEVIEW *pNotify=(NMTREEVIEW*)pNotifyStruct;
  134. (*pResult) =0;
  135. DWORD dwPage=m_cTreeCtrl.GetItemData(pNotify->itemNew.hItem);
  136. LockWindowUpdate();
  137. SetActivePage(dwPage);
  138. UnlockWindowUpdate();
  139. // Prevent losing the focus when invoked by keyboard
  140. if(pNotify->action==TVC_BYKEYBOARD)
  141. m_cTreeCtrl.SetFocus();
  142. InvalidateRect(&m_rcCaptionBar,FALSE);
  143. }
  144. void CTreePropertySheet::OnPaint() 
  145. {
  146. CPaintDC dc(this); // device context for painting
  147. TEXTMETRIC tm;
  148. RenderCaptionBar();
  149. m_cCaptionDC.FitInto(m_rcCaptionBar.Width(),
  150.  m_rcCaptionBar.Height());
  151. m_cCaptionDC.BitBlt(0,0,m_rcCaptionBar.Width(),m_rcCaptionBar.Height(),
  152. &m_cCaptionBarDC,0,0,SRCCOPY);
  153. CSize extent;
  154. CFont *pOldFont;
  155. int nPage=GetActiveIndex();
  156. cPropPage& curPage=m_acPropPages[nPage];
  157. pOldFont =m_cCaptionDC.GetCurrentFont();
  158. m_cCaptionDC.SelectObject(m_pCaptionFont);
  159. m_cCaptionDC.GetTextMetrics(&tm);
  160. m_cCaptionDC.SetTextColor(m_clrCaptionTextLeft);
  161. m_cCaptionDC.SetBkMode(TRANSPARENT);
  162. m_cCaptionDC.TextOut(4,m_nCaptionHeight-tm.tmAscent-tm.tmDescent-4,
  163.  curPage.sCaption);
  164. m_cCaptionDC.SelectObject(m_pCaptionDescrFont);
  165. m_cCaptionDC.GetTextMetrics(&tm);
  166. m_cCaptionDC.SetTextColor(m_clrCaptionTextRight);
  167. m_cCaptionDC.SetBkMode(TRANSPARENT);
  168. extent =m_cCaptionDC.GetTextExtent(curPage.sCaptionDescr);
  169. m_cCaptionDC.TextOut(m_rcCaptionBar.Width()-4-extent.cx,m_nCaptionHeight-tm.tmAscent-tm.tmDescent-4,
  170.  curPage.sCaptionDescr);
  171. dc.BitBlt( m_rcCaptionBar.left,
  172. m_rcCaptionBar.top,
  173. m_rcCaptionBar.Width(),
  174. m_rcCaptionBar.Height(),
  175. &m_cCaptionDC,0,0,
  176. SRCCOPY);
  177. }
  178. BOOL CTreePropertySheet::OnInitDialog() 
  179. {
  180. CPropertySheet::OnInitDialog();
  181. if(m_bSpecialCaption) {
  182. CRect rcWindow;
  183. ModifyStyle(WS_CAPTION,0,0);
  184. ModifyStyle(WS_SYSMENU,0,0);
  185. GetWindowRect(&rcWindow);
  186. rcWindow.bottom-=GetSystemMetrics(SM_CYCAPTION);
  187. MoveWindow(&rcWindow,FALSE);
  188. }
  189. if(m_bDisableStandardButtons)
  190. HidePpgButtons();
  191. HideTabControl();
  192. AddTreeView();
  193. AlignControls();
  194. int nPage,nPages=m_acPropPages.GetSize();
  195. CArray<HTREEITEM,HTREEITEM> stack;
  196. for(nPage=0;nPage<nPages;nPage++) {
  197. cPropPage& page=m_acPropPages[nPage];
  198. HTREEITEM parent=stack.GetSize()?stack[stack.GetSize()-1]:TVI_ROOT;
  199. HTREEITEM cur=NULL;
  200. if(page.sCaption.GetLength()==0)
  201. GetPage(nPage)->GetWindowText(page.sCaption);
  202. cur =m_cTreeCtrl.InsertItem(page.sCaption,parent);
  203. m_cTreeCtrl.SetItemData(cur,nPage);
  204. int nType=page.nType&tps_item_type_mask;
  205. if(nType==tps_item_branch)
  206. stack.Add(cur);
  207. if(nType==tps_item_endbranch)
  208. stack.SetSize(stack.GetSize()-1);
  209. if(page.nType&tps_item_expanded)
  210. m_cTreeCtrl.SetItemState(cur,
  211.  TVIS_EXPANDED,
  212.  TVIS_EXPANDED);
  213. }
  214. if(m_pCaptionFont==NULL)
  215. SetCaptionFont("MS Sans Serif",24,TRUE);
  216. if(m_pCaptionDescrFont==NULL)
  217. SetCaptionDescrFont("MS Sans Serif",18,TRUE);
  218. return TRUE;  // return TRUE unless you set the focus to a control
  219. }
  220. // Support for dragging window around if 
  221. // m_bSpecialCaption==true
  222. void CTreePropertySheet::OnLButtonDown(UINT nFlags, CPoint point) 
  223. {
  224. if(m_bSpecialCaption) {
  225. if(m_rcCaptionBar.PtInRect(point)) {
  226. m_bDragging =true;
  227. m_lButtonDownPoint =point;
  228. ClientToScreen(&m_lButtonDownPoint);
  229. SetCapture();
  230. }
  231. }
  232. CPropertySheet::OnLButtonDown(nFlags, point);
  233. }
  234. void CTreePropertySheet::OnLButtonUp(UINT nFlags, CPoint point) 
  235. {
  236. if(m_bSpecialCaption) {
  237. m_bDragging=false;
  238. ReleaseCapture();
  239. }
  240. CPropertySheet::OnLButtonUp(nFlags, point);
  241. }
  242. void CTreePropertySheet::OnMouseMove(UINT nFlags, CPoint point) 
  243. {
  244. if(m_bSpecialCaption && nFlags&MK_LBUTTON) {
  245. if(!m_bDragging)
  246. OnLButtonDown(nFlags,point);
  247. if(m_bDragging) {
  248. CRect rcWindow;
  249. CPoint pnt2=point;
  250. int dx,dy;
  251. ClientToScreen(&pnt2);
  252. dx =pnt2.x-m_lButtonDownPoint.x;
  253. dy =pnt2.y-m_lButtonDownPoint.y;
  254. m_lButtonDownPoint=pnt2;
  255. GetWindowRect(&rcWindow);
  256. rcWindow.OffsetRect(dx,dy);
  257. MoveWindow(&rcWindow);
  258. }
  259. }
  260. CPropertySheet::OnMouseMove(nFlags, point);
  261. }
  262. //////////////////////////////////////////////////////////////////////
  263. // Operations
  264. //////////////////////////////////////////////////////////////////////
  265. /*--------------------------------------------------------------------
  266. FUNCTION: SetCaptionDescrFont(LPCTSTR lpszFacename,int nHeight,bool bNoInvalidate=false);
  267. RETURNS: <void>
  268. PURPOSE: Sets the font of the caption description field
  269. --------------------------------------------------------------------*/
  270. void CTreePropertySheet::SetCaptionDescrFont(
  271. LPCTSTR lpszFacename,
  272. int nHeight,
  273. bool bNoInvalidate)
  274. {
  275. if(m_bDeleteCaptionDescrFont && m_pCaptionDescrFont!=NULL)
  276. delete m_pCaptionDescrFont;
  277. m_bDeleteCaptionDescrFont=false;
  278. m_pCaptionDescrFont =GetFont(lpszFacename,nHeight);
  279. if(!bNoInvalidate)
  280. InvalidateRect(m_rcCaptionBar,FALSE);
  281. }
  282. /*--------------------------------------------------------------------
  283. FUNCTION: SetCaptionFont(LPCTSTR lpszFacename,int nHeight,bool bNoInvalidate=false);
  284. RETURNS: <void>
  285. PURPOSE: Sets the font of the caption bar
  286. --------------------------------------------------------------------*/
  287. void CTreePropertySheet::SetCaptionFont(
  288. LPCTSTR lpszFacename,
  289. int nHeight,
  290. bool bNoInvalidate)
  291. {
  292. if(m_bDeleteCaptionFont && m_pCaptionFont!=NULL)
  293. delete m_pCaptionFont;
  294. m_bDeleteCaptionFont =false;
  295. m_pCaptionFont =GetFont(lpszFacename,nHeight);
  296. if(!bNoInvalidate)
  297. InvalidateRect(m_rcCaptionBar,FALSE);
  298. }
  299. /*--------------------------------------------------------------------
  300. FUNCTION: SetSimple();
  301. RETURNS: <void>
  302. PURPOSE: Prepares the sheet to some 'normal' look
  303. --------------------------------------------------------------------*/
  304. void CTreePropertySheet::SetSimple(bool bSpecialCaption)
  305. {
  306. CStatic *info=new CStatic();
  307. info->Create("Please select from below:",WS_CHILD,CRect(0,0,200,16),GetDesktopWindow());
  308. CFont *tempF=GetFont("MS Sans Serif",18);
  309. info->SetFont(tempF);
  310. if(bSpecialCaption) {
  311. m_clrCaptionLeft =RGB(0,0,128);
  312. m_clrCaptionRight =RGB(0,0,128);
  313. } else
  314. {
  315. m_clrCaptionLeft =RGB(128,128,128);
  316. m_clrCaptionRight =RGB(128,128,128);
  317. m_clrCaptionBorderTopLeft=RGB(64,64,64);
  318. m_clrCaptionBorderBottomRight=RGB(255,255,255);
  319. }
  320. m_clrCaptionTextLeft=RGB(255,255,255);
  321. m_clrCaptionTextRight=RGB(255,255,255);
  322. m_nCaptionHeight =28;
  323. m_bSpecialCaption =bSpecialCaption;
  324. InsertExtraControl(tps_above,3,info,0,0,216,0,tps_horz_right|tps_vert_center,TRUE);
  325. SetExtraRowSpace(tps_above,0,8,0);
  326. }
  327. /*--------------------------------------------------------------------
  328. FUNCTION: SetLikeNetscape();
  329. RETURNS: <void>
  330. PURPOSE: Prepares the sheet to imitate Communicator 4.0's outfit
  331. --------------------------------------------------------------------*/
  332. void CTreePropertySheet::SetLikeNetscape(bool bSpecialCaption)
  333. {
  334. CStatic *info=new CStatic();
  335. CButton *okBtn=new CButton();
  336. CButton *cancelBtn=new CButton();
  337. CButton *helpBtn=new CButton();
  338. info->Create("Category:",WS_CHILD|WS_VISIBLE|WS_VISIBLE,CRect(0,0,100,16),GetDesktopWindow());
  339. /*okBtn->Create("OK",WS_CHILD|WS_TABSTOP|WS_VISIBLE|BS_DEFPUSHBUTTON,CRect(0,0,100,28),GetDesktopWindow(),IDOK);
  340. cancelBtn->Create("Cancel",WS_CHILD|WS_TABSTOP|WS_VISIBLE,CRect(0,0,100,28),GetDesktopWindow(),IDCANCEL);
  341. helpBtn->Create("Help",WS_CHILD|WS_TABSTOP|WS_VISIBLE,CRect(0,0,100,28),GetDesktopWindow(),IDHELP);*/
  342. CFont *tempF=GetFont("MS Sans Serif",18);
  343. info->SetFont(tempF);
  344. /* okBtn->SetFont(tempF);
  345. cancelBtn->SetFont(tempF);
  346. helpBtn->SetFont(tempF);*/
  347. m_clrCaptionLeft =RGB(128,128,128);
  348. m_clrCaptionRight =RGB(192,192,192);
  349. m_clrCaptionTextLeft=RGB(0,0,0);
  350. m_clrCaptionTextRight=RGB(0,0,0);
  351. m_nCaptionBorder =tps_capborder_none;
  352. m_bSpecialCaption =bSpecialCaption;
  353. /* InsertExtraSpace(tps_below,0,0);
  354. InsertExtraControl(tps_below,0,okBtn,0,1,116,0,tps_horz_center|tps_vert_center,TRUE);
  355. InsertExtraControl(tps_below,1,cancelBtn,0,2,116,0,tps_horz_center|tps_vert_center,TRUE);
  356. InsertExtraControl(tps_below,2,helpBtn,0,3,108,0,tps_horz_right|tps_vert_center,TRUE);
  357. InsertExtraSpace(tps_below,0,4,16);*/
  358. InsertExtraControl(tps_above,3,info,0,0,116,16,tps_horz_right|tps_vert_center,TRUE);
  359. SetExtraRowSpace(tps_above,0,8,0);
  360. //SetExtraRowSpace(tps_below,0,0,8);
  361. }
  362. /*--------------------------------------------------------------------
  363. FUNCTION: AddPage()
  364. RETURNS: <void>
  365. PURPOSE: Inserts a page into the sheet.
  366. For more information, see the help files.
  367. --------------------------------------------------------------------*/
  368. void CTreePropertySheet::AddPage(
  369. int nType,
  370. CPropertyPage* pPage,
  371. LPCTSTR lpszCaptionDescr)
  372. {
  373. cPropPage page;
  374. pPage->m_psp.dwFlags|=PSP_PREMATURE;
  375. page.nType =nType;
  376. page.pPage =pPage;
  377. page.sCaption=_T("");
  378. page.sCaptionDescr=lpszCaptionDescr;
  379. m_acPropPages.Add(page);
  380. CPropertySheet::AddPage(pPage);
  381. }
  382. /*--------------------------------------------------------------------
  383. FUNCTION: InsertExtraSpace()
  384. RETURNS: <void>
  385. PURPOSE: Insert an empty space into the sheet
  386. --------------------------------------------------------------------*/
  387. void CTreePropertySheet::InsertExtraSpace(
  388. int nVertArrange,
  389. int row,int col,
  390. int nWidth,
  391. int nHeight)
  392. {
  393. if(nVertArrange==tps_above) {
  394. m_anRowHeight_TopPane.SetSize(max(m_anRowHeight_TopPane.GetSize(),row+1));
  395. m_anRowHeight_TopPane[row].nHeight
  396. =max(m_anRowHeight_TopPane[row].nHeight,nHeight);
  397. } else
  398. {
  399. m_anRowHeight_BottomPane.SetSize(max(m_anRowHeight_BottomPane.GetSize(),row+1));
  400. m_anRowHeight_BottomPane[row].nHeight
  401. =max(m_anRowHeight_BottomPane[row].nHeight,nHeight);
  402. }
  403. cControlPos pos;
  404. pos.row =row;
  405. pos.col =col;
  406. pos.nWidth =nWidth;
  407. pos.nHeight =nHeight;
  408. pos.nArrange =0;
  409. pos.nVertArrange=nVertArrange;
  410. pos.pWnd =NULL;
  411. pos.bAutoDelete =false;
  412. pos.rcFinalPos =CRect(0,0,0,0);
  413. m_acControlPos.Add(pos);
  414. }
  415. /*--------------------------------------------------------------------
  416. FUNCTION: InsertExtraControl()
  417. RETURNS: <void>
  418. PURPOSE: Insert an extra control into the sheet.
  419. --------------------------------------------------------------------*/
  420. void CTreePropertySheet::InsertExtraControl(
  421. int nVertArrange,
  422. int zOrder,
  423. CWnd* pWnd,
  424. int row,int col,
  425. int nWidth,int nHeight,
  426. int nArrange,
  427. bool bAutoDelete)
  428. {
  429. cControlPos pos;
  430. pos.nID =0;
  431. if(nHeight==0) {
  432. if(pos.nID!=0)
  433. nHeight=pos.nTHeight;
  434. else {
  435. CRect rcTemp;
  436. pWnd->GetWindowRect(&rcTemp);
  437. nHeight=rcTemp.Height();
  438. }
  439. }
  440. pos.row =row;
  441. pos.col =col;
  442. pos.nWidth =nWidth;
  443. pos.nHeight =nHeight;
  444. pos.nArrange =nArrange;
  445. pos.nVertArrange=nVertArrange;
  446. pos.pWnd =pWnd;
  447. pos.bAutoDelete =bAutoDelete;
  448. pos.rcFinalPos =CRect(0,0,0,0);
  449. m_acControlPos.Add(pos);
  450. if(nVertArrange==tps_above) {
  451. m_anRowHeight_TopPane.SetSize(max(m_anRowHeight_TopPane.GetSize(),row+1));
  452. m_anRowHeight_TopPane[row].nHeight
  453. =max(m_anRowHeight_TopPane[row].nHeight,nHeight);
  454. } else
  455. {
  456. m_anRowHeight_BottomPane.SetSize(max(m_anRowHeight_BottomPane.GetSize(),row+1));
  457. m_anRowHeight_BottomPane[row].nHeight
  458. =max(m_anRowHeight_BottomPane[row].nHeight,nHeight);
  459. }
  460. }
  461. /*--------------------------------------------------------------------
  462. FUNCTION: SetExtraRowSpace(int nVertArrange,int nRow,int nSpaceTop,int nSpaceBottom);
  463. RETURNS: <void>
  464. PURPOSE: Reserves extra space for each row
  465. --------------------------------------------------------------------*/
  466. void CTreePropertySheet::SetExtraRowSpace(
  467. int nVertArrange,
  468. int nRow,
  469. int nSpaceTop,int nSpaceBottom)
  470. {
  471. CArray<cRowInfo,cRowInfo&>&
  472. pane=(nVertArrange==tps_above)?
  473. m_anRowHeight_TopPane:
  474. m_anRowHeight_BottomPane;
  475. pane.SetSize(max(pane.GetSize(),nRow+1));
  476. pane[nRow].nExtraTop =nSpaceTop;
  477. pane[nRow].nExtraBottom =nSpaceBottom;
  478. }
  479. //////////////////////////////////////////////////////////////////////
  480. // Protected operations
  481. //////////////////////////////////////////////////////////////////////
  482. /*--------------------------------------------------------------------
  483. FUNCTION: HidePpgButtons();
  484. RETURNS: <bool>
  485. PURPOSE: Hides the default property sheet buttons
  486. --------------------------------------------------------------------*/
  487. bool CTreePropertySheet::HidePpgButtons()
  488. {
  489. int nControls=m_acControlPos.GetSize();
  490. CRect rcTemp,rcWindow;
  491. GetDlgItem(IDOK)->GetWindowRect(&rcTemp);
  492. GetWindowRect(&rcWindow);
  493. rcWindow.bottom =rcTemp.top;
  494. MoveWindow(&rcWindow,FALSE);
  495. /* for(nControl=0;nControl<nControls;nControl++) {
  496. cControlPos& cur=m_acControlPos[nControl];
  497. CRect rcTemp;
  498. if(cur.pWnd==NULL && cur.nID!=0) {
  499. cur.pWnd =GetDlgItem(cur.nID);
  500. cur.pWnd->SetWindowPos(
  501. NULL,
  502. 0,0,
  503. cur.nTWidth,cur.nTHeight,
  504. SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE);
  505. }
  506. if(cur.pWnd!=NULL) {
  507. cur.pWnd->GetWindowRect(&rcTemp);
  508. if(cur.nWidth==0)
  509. cur.nWidth=rcTemp.Width();
  510. if(cur.nHeight==0)
  511. cur.nHeight=rcTemp.Height();
  512. }
  513. }*/
  514. return true;
  515. }
  516. /*--------------------------------------------------------------------
  517. FUNCTION: GetFont(const CString& sFacename,int nHeight);
  518. RETURNS: <CFont*>
  519. PURPOSE: Allocates a font and returns a pointer to it.
  520. All fonts allocated by this function are deleted
  521. by the destructor.
  522. --------------------------------------------------------------------*/
  523. CFont *CTreePropertySheet::GetFont(
  524. const CString& sFacename,
  525. int nHeight)
  526. {
  527. CFont *temp;
  528. temp =new CFont();
  529. temp->CreateFont( nHeight,0,
  530.   0,0,FW_NORMAL,
  531.   FALSE,FALSE,FALSE,
  532.   DEFAULT_CHARSET,
  533.   OUT_DEFAULT_PRECIS,
  534.   CLIP_DEFAULT_PRECIS,
  535.   DEFAULT_QUALITY,
  536.   FF_DONTCARE|DEFAULT_PITCH,
  537.   sFacename);
  538. m_apFonts.Add(temp);
  539. return temp;
  540. }
  541. /*--------------------------------------------------------------------
  542. FUNCTION: RenderCaptionBar();
  543. RETURNS: <void>
  544. PURPOSE: Paints the caption bar into a memory dc.
  545. --------------------------------------------------------------------*/
  546. void CTreePropertySheet::RenderCaptionBar()
  547. {
  548. if(!m_bCaptionBarInvalidated)
  549. return;
  550. m_bCaptionBarInvalidated=false;
  551. CSize m_szCaptionBar=m_rcCaptionBar.Size();
  552. // Adjust memory DCs' size
  553. m_cCaptionBarDC.FitInto(m_szCaptionBar.cx,m_szCaptionBar.cy);
  554. int x;
  555. CPen *pOldPen,cNullPen;
  556. CBrush *pOldBrush;
  557. cNullPen.CreateStockObject(NULL_PEN);
  558. pOldPen =m_cCaptionBarDC.SelectObject(&cNullPen);
  559. pOldBrush =m_cCaptionBarDC.GetCurrentBrush();
  560. for(x=0;x<m_szCaptionBar.cx;x++) {
  561. COLORREF clrCurrent=_interpolate(
  562. m_clrCaptionLeft,
  563. m_clrCaptionRight,
  564. x,
  565. m_szCaptionBar.cx);
  566. CBrush cBrush(clrCurrent);
  567. m_cCaptionBarDC.SelectObject(&cBrush);
  568. m_cCaptionBarDC.Rectangle(x,0,x+2,m_szCaptionBar.cy+1);
  569. m_cCaptionBarDC.SelectObject(pOldBrush);
  570. }
  571. if(m_nCaptionBorder==tps_capborder_line) {
  572. m_cCaptionBarDC.Draw3dRect( 0,0,m_szCaptionBar.cx,m_szCaptionBar.cy,
  573. m_clrCaptionBorderTopLeft,
  574. m_clrCaptionBorderBottomRight);
  575. }
  576. m_cCaptionBarDC.SelectObject(pOldPen);
  577. }
  578. /*--------------------------------------------------------------------
  579. FUNCTION: _interpolate()
  580. RETURNS: COLORREF
  581. PURPOSE: Interpolates between two given colors
  582. --------------------------------------------------------------------*/
  583. COLORREF CTreePropertySheet::_interpolate(
  584. COLORREF clrLeft, 
  585. COLORREF clrRight, 
  586. int nStep, 
  587. int nSteps)
  588. {
  589. DWORD r0,g0,b0;
  590. DWORD r1,g1,b1;
  591. DWORD rc,gc,bc;
  592. r0 =(DWORD)(clrLeft&0xFFL);
  593. g0 =(DWORD)(clrLeft&0xFF00L)>>8;
  594. b0 =(DWORD)(clrLeft&0xFF0000L)>>16;
  595. r1 =(DWORD)(clrRight&0xFFL);
  596. g1 =(DWORD)(clrRight&0xFF00L)>>8;
  597. b1 =(DWORD)(clrRight&0xFF0000L)>>16;
  598. rc =((r1*nStep)+(r0*(nSteps-nStep)))/(nSteps);
  599. gc =((g1*nStep)+(g0*(nSteps-nStep)))/(nSteps);
  600. bc =((b1*nStep)+(b0*(nSteps-nStep)))/(nSteps);
  601. return RGB(rc,gc,bc);
  602. }
  603. /*--------------------------------------------------------------------
  604. FUNCTION: PlaceControl(cControlPos* pCtrl);
  605. RETURNS: <void>
  606. PURPOSE: Internally places the given control
  607. --------------------------------------------------------------------*/
  608. void CTreePropertySheet::PlaceControl(cControlPos* pCtrl)
  609. {
  610. /* if(pCtrl->pWnd==NULL && pCtrl->nID!=0)
  611. pCtrl->pWnd =GetDlgItem(pCtrl->nID);
  612. */
  613. if(pCtrl->pWnd!=NULL) {
  614. CRect rcItem;
  615. CSize szItem;
  616. pCtrl->pWnd->SetParent(this);
  617. pCtrl->pWnd->GetClientRect(&rcItem);
  618. szItem =rcItem.Size();
  619. int nHorzArr=(pCtrl->nArrange&tps_horz_mask);
  620. int nVertArr=(pCtrl->nArrange&tps_vert_mask);
  621. if( nHorzArr==tps_horz_left) {
  622. rcItem.left =pCtrl->rcFinalPos.left;
  623. rcItem.right=rcItem.left+szItem.cx;
  624. }
  625. if( nHorzArr==tps_horz_center) {
  626. rcItem.left =(pCtrl->rcFinalPos.left+
  627.   pCtrl->rcFinalPos.right-szItem.cx)/2;
  628. rcItem.right=rcItem.left+szItem.cx;
  629. }
  630. if( nHorzArr==tps_horz_right) {
  631. rcItem.left =pCtrl->rcFinalPos.right-szItem.cx;
  632. rcItem.right=rcItem.left+szItem.cx;
  633. }
  634. if( nVertArr==tps_vert_top) {
  635. rcItem.top =pCtrl->rcFinalPos.top;
  636. rcItem.bottom=rcItem.top+szItem.cy;
  637. }
  638. if( nVertArr==tps_vert_center) {
  639. rcItem.top =(pCtrl->rcFinalPos.top+
  640.   pCtrl->rcFinalPos.bottom-szItem.cy)/2;
  641. rcItem.bottom=rcItem.top+szItem.cy;
  642. }
  643. if( nVertArr==tps_vert_top) {
  644. rcItem.top =pCtrl->rcFinalPos.bottom-szItem.cy;
  645. rcItem.bottom=rcItem.top+szItem.cy;
  646. }
  647. pCtrl->pWnd->MoveWindow(&rcItem,FALSE);
  648. pCtrl->pWnd->SetFont(CWnd::GetFont(),TRUE);
  649. }
  650. }
  651. /*--------------------------------------------------------------------
  652. FUNCTION: AddPaneSpace(int nWidth, int nTopPane,int nBottomPane);
  653. RETURNS: <void>
  654. PURPOSE: Reserves space for the extra control panes.
  655. Internally used.
  656. --------------------------------------------------------------------*/
  657. void CTreePropertySheet::AddPaneSpace(int nWidth, int nTopPane,int nBottomPane)
  658. {
  659. CRect rcClient;
  660. CRect rcWindow;
  661. GetClientRect(&rcClient);
  662. GetWindowRect(&rcWindow);
  663. int nAddSpaceX=(nWidth-rcClient.Width());
  664. int nAddSpaceY=nTopPane+nBottomPane;
  665. int nLeft=nAddSpaceX/2;
  666. int nRight=(nAddSpaceX-nLeft);
  667. int nTop=nAddSpaceY/2;
  668. int nBottom=(nAddSpaceY-nTop);
  669. rcWindow.left-=nLeft;
  670. rcWindow.right+=nRight;
  671. rcWindow.top-=nTop;
  672. rcWindow.bottom+=nBottom;
  673. MoveWindow(&rcWindow,FALSE);
  674. ScrollWindow(nLeft,nTopPane);
  675. // Move only the bottoms down by 'nTop'
  676. CWnd* pWndChild=GetWindow(GW_CHILD);
  677. TCHAR szClass[256];
  678. while(pWndChild!=NULL) {
  679. ::GetClassName( pWndChild->GetSafeHwnd(),
  680. szClass,256);
  681. if(stricmp(szClass,"Button")==0) {
  682. CRect rcButton;
  683. pWndChild->GetClientRect(&rcButton);
  684. pWndChild->MapWindowPoints(this,&rcButton);
  685. rcButton.OffsetRect(0,nBottomPane);
  686. pWndChild->MoveWindow(&rcButton,FALSE);
  687. if(m_bDisableStandardButtons) {
  688. pWndChild->EnableWindow(FALSE);
  689. pWndChild->ModifyStyle(BS_DEFPUSHBUTTON,0,0);
  690. }
  691. }
  692. pWndChild =pWndChild->GetWindow(GW_HWNDNEXT);
  693. }
  694. }
  695. /*--------------------------------------------------------------------
  696. FUNCTION: AddTreeView();
  697. RETURNS: <void>
  698. PURPOSE: Adds the tree view control to the standard
  699. property sheet.
  700. --------------------------------------------------------------------*/
  701. void CTreePropertySheet::AddTreeView()
  702. {
  703. // Insert the space to the left
  704. int nAddSpace=m_nTreeWidth+m_nSpaceLeft;
  705. int nLeft=nAddSpace/2;
  706. int nRight=(nAddSpace-nLeft);
  707. int nTopOfTreeView;
  708. CRect rcWindow,rcPage,rcTab;
  709. GetWindowRect(&rcWindow);
  710. rcWindow.left-=nLeft;
  711. rcWindow.right+=nRight;
  712. MoveWindow(&rcWindow,FALSE);
  713. GetPage(0)->GetWindowRect(&rcPage);
  714. ScreenToClient(&rcPage);
  715. GetTabControl()->GetWindowRect(&rcTab);
  716. ScreenToClient(&rcTab);
  717. ScrollWindow(nAddSpace,0);
  718. if(m_bSpecialCaption)
  719. nTopOfTreeView =rcPage.top;
  720. else
  721. nTopOfTreeView =rcPage.top-m_nCaptionHeight;
  722. m_cTreeCtrl.CWnd::CreateEx(WS_EX_CLIENTEDGE,
  723.  WC_TREEVIEW, 
  724.  NULL, 
  725.  WS_CHILD|WS_VISIBLE|WS_TABSTOP|
  726.  TVS_HASLINES|TVS_LINESATROOT|TVS_HASBUTTONS, 
  727.  m_nSpaceLeft,nTopOfTreeView,m_nTreeWidth,rcTab.bottom-nTopOfTreeView,
  728.  GetSafeHwnd(), 
  729.  (HMENU)ID_TREECTRL);
  730. }
  731. /*--------------------------------------------------------------------
  732. FUNCTION: HideTabControl();
  733. RETURNS: <void>
  734. PURPOSE: Hides the tab control of the property sheet.
  735. --------------------------------------------------------------------*/
  736. void CTreePropertySheet::HideTabControl()
  737. {
  738. CRect rcClient,rcTab,rcPage,rcWindow;
  739. GetClientRect(&rcClient);
  740. GetTabControl()->GetWindowRect(&rcTab);
  741. GetPage(0)->GetClientRect(&rcPage);
  742. GetPage(0)->MapWindowPoints(this,&rcPage);
  743. GetWindowRect(&rcWindow);
  744. ScreenToClient(&rcTab);
  745. ScrollWindow( m_nSpaceMid-rcPage.left,
  746. m_nSpaceTop-rcPage.top+m_nCaptionHeight);
  747. rcWindow.right+=m_nSpaceMid-rcPage.left-(rcClient.Width()-rcTab.right)+m_nSpaceRight;
  748. rcWindow.bottom+=m_nSpaceTop-rcPage.top+m_nCaptionHeight;
  749. GetTabControl()->ShowWindow(SW_HIDE);
  750. MoveWindow(&rcWindow,FALSE);
  751. }
  752. /*--------------------------------------------------------------------
  753. FUNCTION: AssignFillerSpace()
  754. RETURNS: <void>
  755. PURPOSE: Assigns each space filler control
  756. (width==-1) the remaining space of each row.
  757. --------------------------------------------------------------------*/
  758. void CTreePropertySheet::AssignFillerSpace(
  759. int nVertArrange, 
  760. int nRow, 
  761. int nSpace)
  762. {
  763. int i,nSize=m_acControlPos.GetSize();
  764. int nFillers=CountFillers(nVertArrange,nRow);
  765. int nCount=0;
  766. if(nFillers==0)
  767. return;
  768. int nItemSpace=nSpace/nFillers;
  769. int nSpaceLeft=nSpace;
  770. int nCurFiller=0;
  771. for(i=0;i<nSize;i++) {
  772. cControlPos& cur=m_acControlPos[i];
  773. if( !(cur.nVertArrange==nVertArrange &&
  774. cur.row==nRow))
  775. continue;
  776. if( cur.nWidth!=-1)
  777. continue;
  778. nCurFiller++;
  779. if(nCurFiller==nFillers)
  780. cur.nWidth =nSpaceLeft;
  781. else
  782. cur.nWidth =nItemSpace;
  783. nSpaceLeft -=cur.nWidth;
  784. }
  785. }
  786. /*--------------------------------------------------------------------
  787. FUNCTION: CountFillers(int nVertArrange,int nRow);
  788. RETURNS: <int>
  789. PURPOSE: Counts the number of space filler controls
  790. for the given row.
  791. --------------------------------------------------------------------*/
  792. int CTreePropertySheet::CountFillers(
  793. int nVertArrange,
  794. int nRow)
  795. {
  796. int i,nSize=m_acControlPos.GetSize();
  797. int nCount=0;
  798. for(i=0;i<nSize;i++) {
  799. cControlPos& cur=m_acControlPos[i];
  800. if( !(cur.nVertArrange==nVertArrange &&
  801. cur.row==nRow))
  802. continue;
  803. if( cur.nWidth==-1)
  804. nCount++;
  805. }
  806. return nCount;
  807. }
  808. /*--------------------------------------------------------------------
  809. FUNCTION: CountColumns(int nVertArrange,int nCol);
  810. RETURNS: <int>
  811. PURPOSE: Counts the number of columns in one row.
  812. --------------------------------------------------------------------*/
  813. int CTreePropertySheet::CountColumns(int nVertArrange,int nRow)
  814. {
  815. int i,nSize=m_acControlPos.GetSize();
  816. int nCount=0;
  817. for(i=0;i<nSize;i++) {
  818. cControlPos& cur=m_acControlPos[i];
  819. if( !(cur.nVertArrange==nVertArrange &&
  820. cur.row==nRow))
  821. continue;
  822. nCount++;
  823. }
  824. return nCount;
  825. }
  826. /*--------------------------------------------------------------------
  827. FUNCTION: GetControl(int nVertArrange,int nRow,int nCol);
  828. RETURNS: <cControlPos*>
  829. PURPOSE: Returns the control description class for the
  830. given row/column.
  831. --------------------------------------------------------------------*/
  832. CTreePropertySheet::cControlPos* CTreePropertySheet::GetControl(
  833. int nVertArrange,
  834. int nRow,
  835. int nCol)
  836. {
  837. int i,nSize=m_acControlPos.GetSize();
  838. int nCount=0;
  839. for(i=0;i<nSize;i++) {
  840. cControlPos& cur=m_acControlPos[i];
  841. if( !(cur.nVertArrange==nVertArrange &&
  842. cur.row==nRow))
  843. continue;
  844. if( cur.col==nCol)
  845. return &cur;
  846. }
  847. return NULL;
  848. }
  849. /*--------------------------------------------------------------------
  850. FUNCTION: GetWidth(int nVertArrange, int nRow);
  851. RETURNS: The width of the given row
  852. PURPOSE: Calculates the width of the given row.
  853. Drops items with the width '-1'.
  854. ASSERTs if the width <-1!!!
  855. --------------------------------------------------------------------*/
  856. int CTreePropertySheet::GetWidth(
  857. int nVertArrange, 
  858. int nRow)
  859. {
  860. int i,nSize=m_acControlPos.GetSize();
  861. int nWidth=0;
  862. for(i=0;i<nSize;i++) {
  863. cControlPos& cur=m_acControlPos[i];
  864. if( !(cur.nVertArrange==nVertArrange &&
  865. cur.row==nRow))
  866. continue;
  867. if( cur.nWidth==-1)
  868. continue;
  869. ASSERT(cur.nWidth>=0);
  870. nWidth +=cur.nWidth;
  871. }
  872. return nWidth;
  873. }
  874. /*--------------------------------------------------------------------
  875. FUNCTION: GetHeight(CArray<cRowInfo,cRowInfo&>& pane)
  876. RETURNS: The sum of the values of the array 'pane'
  877. PURPOSE: Calculates the height of the given pane
  878. --------------------------------------------------------------------*/
  879. int CTreePropertySheet::GetHeight(
  880. CArray<cRowInfo,cRowInfo&>& pane)
  881. {
  882. int i,nSize=pane.GetSize();
  883. int nSum=0;
  884. for(i=0;i<nSize;i++)
  885.         nSum+=pane[i].nHeight+pane[i].nExtraBottom+pane[i].nExtraTop;
  886. return nSum;
  887. }
  888. /*--------------------------------------------------------------------
  889. FUNCTION: AlignControls();
  890. RETURNS: <void>
  891. PURPOSE: Performs the alignment of the extra controls.
  892. --------------------------------------------------------------------*/
  893. void CTreePropertySheet::AlignControls()
  894. {
  895. int nTotalHeight_TopPane=GetHeight(m_anRowHeight_TopPane);
  896. int nTotalHeight_BottomPane=GetHeight(m_anRowHeight_BottomPane);
  897. int nVertArrange;
  898. int nMaxWidth=0;
  899. CRect rcClient;
  900. GetClientRect(&rcClient);
  901. // Determine the maximum width of all rows
  902. for(nVertArrange=tps_above;nVertArrange<=tps_below;nVertArrange++) {
  903. int nRow,nRows;
  904. CArray<cRowInfo,cRowInfo&>&
  905. pane=(nVertArrange==tps_above)?
  906. m_anRowHeight_TopPane:
  907. m_anRowHeight_BottomPane;
  908. nRows =pane.GetSize();
  909. for(nRow=0;nRow<nRows;nRow++) {
  910. int nWidth;
  911. nWidth =GetWidth(nVertArrange,nRow);
  912. nMaxWidth =max(nWidth,nMaxWidth);
  913. }
  914. }
  915. // Get the maximum of the actual dialog width and 'nMaxWidth'
  916. // (to get the overall width)
  917. nMaxWidth =max(rcClient.Width(),nMaxWidth);
  918. // Align the controls' width (to make those with 'width' is -1
  919. // equally spaced)
  920. for(nVertArrange=tps_above;nVertArrange<=tps_below;nVertArrange++) {
  921. int nRow,nRows;
  922. CArray<cRowInfo,cRowInfo&>&
  923. pane=(nVertArrange==tps_above)?
  924. m_anRowHeight_TopPane:
  925. m_anRowHeight_BottomPane;
  926. nRows =pane.GetSize();
  927. for(nRow=0;nRow<nRows;nRow++) {
  928. int nWidth;
  929. nWidth =GetWidth(nVertArrange,nRow);
  930. AssignFillerSpace(nVertArrange,nRow,nMaxWidth-nWidth);
  931. }
  932. }
  933. // Resize the dialog
  934. AddPaneSpace(nMaxWidth, nTotalHeight_TopPane, nTotalHeight_BottomPane);
  935. // Calculate each controls' position
  936. CRect rcPage;
  937. GetPage(0)->GetWindowRect(&rcPage);
  938. ScreenToClient(&rcPage);
  939. int nCurXPos;
  940. int nCurYPos;
  941. int nTopPos;
  942. if(m_bSpecialCaption)
  943. nTopPos =m_nCaptionHeight;
  944. else
  945. nTopPos =0;
  946. for(nVertArrange=tps_above;nVertArrange<=tps_below;nVertArrange++) {
  947. int nRow,nRows;
  948. CArray<cRowInfo,cRowInfo&>&
  949. pane=(nVertArrange==tps_above)?
  950. m_anRowHeight_TopPane:
  951. m_anRowHeight_BottomPane;
  952. nRows =pane.GetSize();
  953. if(nVertArrange==tps_above)
  954. nCurYPos=nTopPos;
  955. else
  956. nCurYPos=rcPage.bottom+m_nSpaceBottom;
  957. for(nRow=0;nRow<nRows;nRow++) {
  958. int nCol,nCols;
  959. nCols =CountColumns(nVertArrange,nRow);
  960. nCurXPos =0;
  961. for(nCol=0;nCol<nCols;nCol++) {
  962. cControlPos *pCur=GetControl(nVertArrange,nRow,nCol);
  963. pCur->rcFinalPos.left =nCurXPos;
  964. pCur->rcFinalPos.right =nCurXPos+pCur->nWidth;
  965. pCur->rcFinalPos.top =nCurYPos+pane[nRow].nExtraTop;
  966. pCur->rcFinalPos.bottom =nCurYPos+pane[nRow].nHeight+pane[nRow].nExtraTop;
  967. PlaceControl(pCur);
  968. nCurXPos +=pCur->nWidth;
  969. }
  970.             nCurYPos        +=pane[nRow].nHeight+pane[nRow].nExtraBottom+pane[nRow].nExtraTop;
  971. }
  972. }
  973. if(m_bSpecialCaption) {
  974. CRect rcTemp;
  975. GetWindowRect(&rcTemp);
  976. m_rcCaptionBar.top =0;
  977. m_rcCaptionBar.left =0;
  978. m_rcCaptionBar.bottom=m_nCaptionHeight;
  979. m_rcCaptionBar.right=rcTemp.Width();
  980. } else
  981. {
  982. m_rcCaptionBar.left =m_nSpaceLeft+m_nTreeWidth+m_nSpaceMid;
  983. m_rcCaptionBar.top =m_nSpaceTop+nTotalHeight_TopPane;
  984. m_rcCaptionBar.right =rcPage.right;
  985. m_rcCaptionBar.bottom =m_nSpaceTop+nTotalHeight_TopPane+m_nCaptionHeight;
  986. }
  987. }