GuiContainer.cpp
上传用户:zhanglf88
上传日期:2013-11-19
资源大小:6036k
文件大小:10k
源码类别:

金融证券系统

开发平台:

Visual C++

  1. //-----------------------------------------------------------------------//
  2. // This is a part of the GuiLib MFC Extention.  //
  3. // Autor  :  Francisco Campos  //
  4. // (C) 2002 Francisco Campos <www.beyondata.com> All rights reserved     //
  5. // This code is provided "as is", with absolutely no warranty expressed  //
  6. // or implied. Any use is at your own risk.  //
  7. // You must obtain the author's consent before you can include this code //
  8. // in a software library.  //
  9. // If the source code in  this file is used in any application  //
  10. // then acknowledgement must be made to the author of this program  //
  11. // fcampos@tutopia.com  //
  12. //-----------------------------------------------------------------------//
  13. #include "stdafx.h"
  14. #include "GuiContainer.h"
  15. #include "GuiVisioFolder.h"
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CGuiContainer
  23. CGuiContainer::CGuiContainer()
  24. {
  25. m_arrContainer.RemoveAll();
  26. m_nItems=0;
  27. m_clrface=GuiDrawLayer::GetRGBColorFace();
  28. m_nItems = -1;
  29. m_bUseWin=FALSE;
  30. m_bDrawBorder=TRUE;
  31. }
  32. CGuiContainer::~CGuiContainer()
  33. {
  34. /* Modified By SunZhenyu 2003/8/22, Add next 7 lines. */
  35. for(int i=0; i<m_arrContainer.GetSize(); i++)
  36. {
  37. CComponents * p = (CComponents*)m_arrContainer[i];
  38. if( p )
  39. delete p;
  40. }
  41. m_arrContainer.RemoveAll();
  42. }
  43. BEGIN_MESSAGE_MAP(CGuiContainer, CWnd)
  44. //{{AFX_MSG_MAP(CGuiContainer)
  45. ON_WM_CREATE()
  46. ON_WM_PAINT()
  47. ON_WM_SIZE()
  48. ON_WM_ERASEBKGND()
  49. ON_WM_SYSCOLORCHANGE()
  50. //}}AFX_MSG_MAP
  51. END_MESSAGE_MAP()
  52. /////////////////////////////////////////////////////////////////////////////
  53. // CGuiContainer message handlers
  54. int CGuiContainer::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  55. {
  56. if (CWnd::OnCreate(lpCreateStruct) == -1)
  57. return -1;
  58. return 0;
  59. }
  60. BOOL CGuiContainer::OnCommand(WPARAM wParam, LPARAM lParam)
  61. {
  62. CWnd* pParent= GetParent();
  63. pParent->SendMessage (WM_COMMAND,wParam);
  64. return TRUE;
  65. }
  66. //********************************************************************************
  67. void CGuiContainer::OnPaint()  
  68. {
  69. CPaintDC dc(this); // device context for painting
  70. CBrush cbr;
  71. CRect m_rectDraw;
  72. GetClientRect(&m_rectDraw);
  73. cbr.CreateSolidBrush(m_clrface);
  74. dc.FillRect(&m_rectDraw,&cbr);
  75. if (m_enBorder == STYLE3D)
  76. dc.Draw3dRect(m_rectDraw,GuiDrawLayer::GetRGBColorBTNHigh(),
  77. GuiDrawLayer::GetRGBColorShadow());
  78. if (m_enBorder == STYLEPRESS)
  79. {
  80. dc.Draw3dRect(m_rectDraw,GuiDrawLayer::GetRGBColorShadow(),
  81. GuiDrawLayer::GetRGBColorBTNHigh());
  82. }
  83. RecalLayout();
  84. }
  85. BOOL CGuiContainer::Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID) 
  86. {
  87. // TODO: Add your specialized code here and/or call the base class
  88. pParent= pParentWnd;
  89. return CWnd::Create(NULL, _T(""), dwStyle, rect, pParentWnd, nID);
  90. }
  91. //********************************************************************************
  92. void CGuiContainer::OnSysColorChange() 
  93. {
  94. CWnd::OnSysColorChange();
  95. m_clrface=GuiDrawLayer::GetRGBColorFace();
  96. for (int i=0; i < m_nItems+1;i++)
  97. {
  98. CComponents* m_cwnd=(CComponents*) m_arrContainer[i];
  99. if(m_cwnd->bMiniTool==TRUE)
  100. m_cwnd->m_guiMini->SetColor(m_clrface);
  101. }
  102. RecalLayout();
  103. }
  104. //********************************************************************************
  105. void CGuiContainer::OnSize(UINT nType, int cx, int cy) 
  106. {
  107. CWnd::OnSize(nType, cx, cy);
  108. RecalLayout();
  109. }
  110. //********************************************************************************
  111. BOOL CGuiContainer::OnEraseBkgnd(CDC* pDC) 
  112. {
  113. return TRUE;
  114. }
  115. void CGuiContainer::UsedAllWindow(BOOL bUseWindow)
  116. {
  117. m_bUseWin=bUseWindow;
  118. }
  119. //********************************************************************************
  120. /*void CGuiContainer::PreSubclassWindow() 
  121. {
  122. CWnd::PreSubclassWindow();
  123. RecalLayout();
  124. }
  125. */
  126. //********************************************************************************
  127. void  CGuiContainer::RecalLayout()
  128. {
  129. if (!GetSafeHwnd()) return;
  130. CRect rcClient;
  131. CClientDC dc(this);
  132. GetClientRect(rcClient);
  133. rcClient.DeflateRect(1,1);
  134. CRect rctemp=rcClient;
  135. int nTipo=0;
  136. CalcAutoSize(rcClient);
  137. for (int i=0; i < m_nItems+1;i++)
  138. {
  139. CComponents* m_cwnd=(CComponents*) m_arrContainer[i];
  140. if(m_cwnd->bMiniTool==TRUE || m_cwnd->bTypeSmall == TRUE)
  141. nTipo=24;
  142. else
  143. nTipo=m_nResultCWnd;
  144. rctemp.bottom=rctemp.top+nTipo;
  145. if (m_cwnd->bMiniTool==TRUE)
  146. m_cwnd->m_guiMini->MoveWindow(rctemp);
  147. else if (nTipo != 0)
  148. {
  149. if (m_bDrawBorder)
  150. dc.Draw3dRect(rctemp,GuiDrawLayer::GetRGBColorShadow(),
  151. GuiDrawLayer::GetRGBColorShadow());
  152. if (m_bUseWin==FALSE)
  153. rctemp.DeflateRect(2,2);
  154. m_cwnd->m_cwnd->MoveWindow(rctemp);
  155. if (m_bUseWin==FALSE)
  156. rctemp.InflateRect(2,2);
  157. }
  158. rctemp.top+=nTipo;
  159. }
  160. }
  161. //********************************************************************************
  162. void CGuiContainer::CalcAutoSize(CRect m_rc)
  163. {
  164. if (m_nItems == -1) return;
  165. m_nResultCWnd=0;
  166.     m_nResultTools=0; 
  167. int m_numCWnd=0;
  168. BOOL m_bExisteCWnd=FALSE;
  169. for (int i=0; i < m_nItems+1;i++)
  170. {
  171. if (((CComponents*) m_arrContainer [i])->bMiniTool==TRUE ||
  172. ((CComponents*) m_arrContainer [i])->bTypeSmall ==TRUE)
  173. m_nResultTools+=24;
  174. else
  175. {
  176. m_bExisteCWnd=TRUE;
  177. m_numCWnd++;
  178. }
  179. }
  180. if (m_bExisteCWnd)
  181. {
  182. if (m_nResultTools > m_rc.Height())  //el espacio no alcanza para los botones
  183. m_nResultCWnd=0;
  184. else
  185. {
  186. m_nResultCWnd=m_rc.Height()-m_nResultTools;
  187. m_nResultCWnd/=m_numCWnd;
  188. }
  189. }
  190. }
  191. //********************************************************************************
  192. BOOL CGuiContainer::AddComponen(CGuiMiniTool* m_miniTool)
  193. {
  194. m_nItems++;
  195. if (!m_miniTool->Create(_T(""),WS_VISIBLE | WS_CHILD |SS_OWNERDRAW, 
  196. CRect(0,0,0,0), this))
  197. return FALSE;
  198. m_arrContainer.SetAtGrow(m_nItems, new CComponents(m_miniTool));
  199. RecalLayout();
  200. return TRUE;
  201. }
  202. //********************************************************************************
  203. void CGuiContainer::SetBorder(Borders m_enborder)
  204. {
  205. m_enBorder=m_enborder;
  206. }
  207. //********************************************************************************
  208. CWnd*  CGuiContainer::AddComponen(CRuntimeClass* m_rtcwnd,UINT nID,DWORD dwStyle)
  209. {
  210. CWnd* m_cwnd=NULL;
  211. BOOL btype=FALSE; //only object small
  212. if (m_rtcwnd->IsDerivedFrom(RUNTIME_CLASS(CComboBox)))
  213. {
  214.  m_cwnd = new CGuiComboBoxExt();
  215.  if (!((CGuiComboBoxExt*)m_cwnd)->Create(dwStyle|WS_CHILD|WS_VISIBLE, CRect(1,1,100,100), this, nID))
  216. return NULL;
  217.  btype=TRUE;
  218.  goto crear;
  219. }
  220. if (m_rtcwnd->IsDerivedFrom(RUNTIME_CLASS(CTreeCtrl)))
  221. {
  222.  m_cwnd = new CTreeCtrl();
  223.  if (!((CTreeCtrl*)m_cwnd)->Create(dwStyle|WS_CHILD|WS_VISIBLE, CRect(0,0,0,0), this, nID))
  224. return NULL;
  225.  goto crear;
  226. }
  227. else if ( m_rtcwnd->IsDerivedFrom(RUNTIME_CLASS(CListCtrl)))
  228. {
  229. m_cwnd = new CListCtrl();
  230.     if (!((CListCtrl*)m_cwnd)->Create(dwStyle|WS_CHILD|WS_VISIBLE, CRect(0,0,0,0), this, nID))
  231. return NULL;
  232. goto crear;
  233. }
  234. else if ( m_rtcwnd->IsDerivedFrom(RUNTIME_CLASS(CListBox)))
  235. {
  236.  m_cwnd = new CListBox();
  237.  if (!((CListBox*)m_cwnd)->Create(dwStyle|WS_CHILD|WS_VISIBLE, CRect(0,0,0,0), this, nID))
  238. return NULL;
  239.  goto crear;
  240. }
  241. else if ( m_rtcwnd->IsDerivedFrom(RUNTIME_CLASS(CEdit)))
  242. {
  243.  m_cwnd = new CEdit();
  244.  if (!((CEdit*)m_cwnd)->Create(dwStyle|WS_CHILD|WS_VISIBLE, CRect(0,0,0,0), this, nID))
  245. return NULL;
  246.  btype=TRUE;
  247.  goto crear;
  248. }
  249. else if ( m_rtcwnd->IsDerivedFrom(RUNTIME_CLASS(CGuiImageLinkButton)))
  250. {
  251.  m_cwnd = new CGuiImageLinkButton();
  252.  if (!((CGuiImageLinkButton*)m_cwnd)->Create(_T(""),dwStyle|WS_CHILD|WS_VISIBLE, CRect(0,0,0,0), this, nID))
  253. return NULL;
  254.  btype=TRUE;
  255.  goto crear;
  256. }
  257. else if ( m_rtcwnd->IsDerivedFrom(RUNTIME_CLASS(CGuiLabelButton)))
  258. {
  259.  m_cwnd = new CGuiLabelButton();
  260.  if (!((CGuiLabelButton*)m_cwnd)->Create(_T(""),dwStyle|WS_CHILD|WS_VISIBLE, CRect(0,0,0,0), this, nID))
  261. return NULL;
  262.  btype=TRUE;
  263.  goto crear;
  264. }
  265. else if ( m_rtcwnd->IsDerivedFrom(RUNTIME_CLASS(CListCtrl)))
  266. {
  267.  m_cwnd = new CListCtrl();
  268.  if (!((CListCtrl*)m_cwnd)->Create(dwStyle|WS_CHILD|WS_VISIBLE, CRect(0,0,0,0), this, nID))
  269. return NULL;
  270.  btype=TRUE;
  271.  goto crear;
  272. }
  273. else if ( m_rtcwnd->IsDerivedFrom(RUNTIME_CLASS(CGuiVisioFolder)))
  274. {
  275.  m_cwnd = new CGuiVisioFolder();
  276.  if (!((CGuiVisioFolder*)m_cwnd)->Create(dwStyle|WS_CHILD|WS_VISIBLE, CRect(0,0,0,0), this, nID))
  277. return NULL;
  278.  goto crear;
  279. }
  280. else if ( m_rtcwnd->IsDerivedFrom(RUNTIME_CLASS(CGuiToolButton)))
  281. {
  282.  m_cwnd = new CGuiToolButton();
  283.  if (!((CGuiToolButton*)m_cwnd)->Create(_T(""),
  284.  dwStyle|WS_CHILD|WS_VISIBLE, CRect(0,0,0,0), this, nID))
  285.  btype=TRUE;
  286. return NULL;
  287.  goto crear;
  288. }
  289. else
  290. {
  291.    m_cwnd=(CWnd*) m_rtcwnd->CreateObject();
  292.    if (!m_cwnd->Create(0,0,dwStyle|WS_CHILD|WS_VISIBLE, CRect(0,0,0,0), this, nID))
  293. return NULL;
  294.    goto crear;
  295. }
  296. crear:
  297. m_nItems++;
  298. m_arrContainer.SetAtGrow(m_nItems, new CComponents(m_cwnd,btype));
  299. RecalLayout();
  300. return m_cwnd;
  301. }
  302. //*************************************************************************
  303. CComponents::CComponents(CGuiMiniTool* m_GuiMini)
  304. {
  305. m_guiMini=m_GuiMini;
  306. bMiniTool=TRUE;
  307. }
  308. //*************************************************************************
  309. CComponents::CComponents(CWnd* m_wnd,BOOL bType)
  310. {
  311. ASSERT(::IsWindow(m_wnd->m_hWnd));
  312. m_cwnd=m_wnd;
  313. bMiniTool=FALSE;
  314. bTypeSmall=bType;
  315. }
  316. BOOL CGuiContainer::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
  317. {
  318. // TODO: Add your specialized code here and/or call the base class
  319. CWnd* pParent= GetParent();
  320. if (pParent->GetSafeHwnd())
  321. pParent->SendMessage(WM_NOTIFY, wParam, lParam);
  322. return TRUE;
  323. }