GuiTabPowerPoint.cpp
上传用户:wlkj888
上传日期:2022-08-01
资源大小:806k
文件大小:9k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. /****************************************************************************
  2.  * *  
  3.  * GuiToolKit   *
  4.  *  (MFC extension) *  
  5.  * Created by Francisco Campos G. www.beyondata.com fcampos@beyondata.com *
  6.  *--------------------------------------------------------------------------*    
  7.  * *
  8.  * This program is free software;so you are free to use it any of your *
  9.  * applications (Freeware, Shareware, Commercial),but leave this header *
  10.  * intact. *
  11.  * *
  12.  * These files are provided "as is" without warranty of any kind. *
  13.  * *
  14.  *        GuiToolKit is forever FREE CODE !!!!! *
  15.  * *
  16.  *--------------------------------------------------------------------------*
  17.  * Created by: Francisco Campos G. *
  18.  * Bug Fixes and improvements : (Add your name) *
  19.  * -Francisco Campos *
  20.  * *
  21.  ****************************************************************************/
  22. #include "stdafx.h"
  23. #include "guitabpowerpoint.h"
  24. #include "GuiDrawLayer.h"
  25. #include "GuiBaseTab.h"
  26. #ifdef _DEBUG
  27. #define new DEBUG_NEW
  28. #undef THIS_FILE
  29. static char THIS_FILE[] = __FILE__;
  30. #endif
  31. CGuiTabPowerPoint::CGuiTabPowerPoint(void)
  32. {
  33. bAutoAjust=TRUE;
  34. m_clrTabs=GuiDrawLayer::GetRGBColorFace(GuiDrawLayer::m_Theme);
  35. m_bShowButton=TRUE;
  36. }
  37. CGuiTabPowerPoint::~CGuiTabPowerPoint(void)
  38. {
  39. }
  40. BEGIN_MESSAGE_MAP(CGuiTabPowerPoint, CGuiTabWnd)
  41. ON_WM_CREATE()
  42. END_MESSAGE_MAP()
  43. BOOL CGuiTabPowerPoint::OnCommand(WPARAM wParam, LPARAM lParam)
  44. {
  45. HWND hwnd = (HWND) lParam;
  46. if (m_ToolButton.GetSafeHwnd() == hwnd)
  47. {
  48. UINT x=m_ToolButton.GetDlgCtrlID();
  49. CWnd* pParent= GetParent();
  50. pParent->SendMessage (WM_COMMAND,x);
  51. // AfxGetMainWnd()->SendMessage(WM_COMMAND,x);
  52. }
  53. return TRUE;
  54. }
  55. void CGuiTabPowerPoint::AjustTabs()
  56. {
  57. int m_iSizeAct=0;
  58. m_iMinValRec=4;
  59. CClientDC dc(this);
  60. GetClientRect(m_rectCliente);
  61. m_rectCliente.bottom=m_rectCliente.top+(m_sizeImag.cy+4+1);
  62. CFont* m_fontOld=dc.SelectObject(&m_cfont);
  63. for (int iCont=0; iCont< m_Numtabs;iCont++)
  64. {
  65. CGuiTab* ct=(CGuiTab*) m_pArray[iCont];
  66. CRect m_Arect;
  67. CSize m_sChar=dc.GetTextExtent(ct->lpMsg);
  68. m_Arect.left=m_iMinValRec+1;
  69. m_iMinValRec+=m_alnTab!=ALN_TOP?m_sizeImag.cx+2+m_sChar.cx+14:m_sChar.cx+14;
  70. if(m_alnTab==ALN_BOTTOM)
  71. {
  72. m_Arect.top=m_rectCliente.bottom;
  73. m_Arect.right=m_iMinValRec;
  74. m_Arect.bottom=m_rectCliente.bottom+4+m_sizeImag.cy;
  75. }
  76. else
  77. {
  78. m_Arect.top=m_rectCliente.top;
  79. m_Arect.right=m_iMinValRec;
  80. m_Arect.bottom=m_rectCliente.top+4+m_sizeImag.cy;
  81. }
  82. ct->rect= m_Arect;
  83. }
  84. dc.SelectObject(m_fontOld);
  85. if (bAutoAjust)
  86. {
  87. int m_NewResize=4;
  88. if (m_iMinValRec > m_rectCliente.Width()-4)
  89. {
  90. m_iSizeAct=(m_rectCliente.Width()-12)/m_Numtabs;
  91. for (int iCont=0; iCont< m_Numtabs;iCont++)
  92. {
  93. CGuiTab* ct=(CGuiTab*) m_pArray[iCont];
  94. if (ct->uIcon != -1)
  95. {
  96. if (m_sizeImag.cx+22 > m_NewResize+m_iSizeAct)
  97. continue;
  98. }
  99. CRect m_Arect;
  100. m_Arect.left=m_NewResize;
  101. m_Arect.right=m_NewResize+m_iSizeAct;
  102. m_Arect.top=m_alnTab==ALN_TOP? m_rectCliente.top:m_rectCliente.bottom;
  103. m_Arect.bottom=m_alnTab==ALN_TOP? m_rectCliente.top+4+m_sizeImag.cy:m_rectCliente.bottom+4+m_sizeImag.cy;
  104. m_NewResize+=m_iSizeAct+1;
  105. ct->rect= m_Arect;
  106. }
  107. }
  108. }
  109. }
  110. void CGuiTabPowerPoint::Drawtabs(CDC* dc)
  111. {
  112. CBrush cb;
  113. CRect rectText;
  114. CRect rc;
  115. int nHeight=0;
  116. CBrush cbr;
  117. CPen cp(PS_SOLID,1,::GetSysColor(COLOR_BTNSHADOW));
  118. CPen cpw(PS_SOLID,1,GuiDrawLayer::GetRGBColorWhite());
  119. cbr.CreateSolidBrush(m_clrTabs);
  120. dc->FillRect(m_rectTab,&cbr);
  121. CFont* m_fontOld=dc->SelectObject(&m_cfont);
  122. CPen penShadow(PS_SOLID, 1, GuiDrawLayer::GetRGBColorShadow());
  123. CPen* pOldPen;
  124. dc->MoveTo(m_rectTab.left,m_rectTab.bottom-1);
  125. dc->LineTo(m_rectTab.right,m_rectTab.bottom-1);
  126. int nMode = dc->SetBkMode(TRANSPARENT);
  127. int m_right=0;
  128. pOldPen=dc->SelectObject(&penShadow);
  129. for ( int iCont=0; iCont< m_Numtabs;iCont++)
  130. {
  131. CGuiTab* ctb=(CGuiTab*)m_pArray[iCont];
  132. CRect mrt=ctb->rect;
  133. int ancho=mrt.Width();
  134. mrt.left=m_right;
  135. mrt.right=mrt.left+ancho;
  136. CPoint Coor[4];
  137. CPoint CoorFive[6];
  138. if (iCont-1 == m_iSelectTab ) 
  139. {
  140. CBrush brushRed(GuiDrawLayer::GetRGBColorFace(GuiDrawLayer::m_Theme));
  141. CBrush* pOldBrush = dc->SelectObject(&brushRed);
  142. CoorFive[0].x=mrt.left+(m_rectTab.Height()/4)+1;
  143. CoorFive[0].y=(mrt.bottom-m_rectTab.Height()/2)+1;
  144. CoorFive[1].x=(mrt.left)+m_rectTab.Height()/2;
  145. CoorFive[1].y=mrt.top+1;
  146. CoorFive[2].x=(mrt.right)-m_rectTab.Height()/2;
  147. CoorFive[2].y=mrt.top+1;
  148. if (iCont == m_Numtabs-1)
  149. {
  150. CoorFive[3].x=mrt.right-2;
  151. CoorFive[3].y=mrt.bottom+1;
  152. }
  153. else
  154. {
  155. CoorFive[3].x=(mrt.right)-5;
  156. CoorFive[3].y=(mrt.bottom-(m_rectTab.Height()/2))+1;
  157. }
  158. CoorFive[4].x=(mrt.right)-8;
  159. CoorFive[4].y=mrt.bottom+1;
  160. CoorFive[5].x=(mrt.left)+9;
  161. CoorFive[5].y=mrt.bottom+1;
  162. dc->Polygon(CoorFive,6);
  163. dc->SelectObject(pOldBrush);
  164. }
  165. else
  166. {
  167. CBrush brushRed(GuiDrawLayer::GetRGBColorXP());
  168. CBrush* pOldBrush = dc->SelectObject(&brushRed);
  169. CoorFive[0].x=mrt.left;
  170. CoorFive[0].y=mrt.bottom+1;
  171. CoorFive[1].x=(mrt.left)+m_rectTab.Height()/2;
  172. CoorFive[1].y=mrt.top+1;
  173. CoorFive[2].x=(mrt.right)-m_rectTab.Height()/2;
  174. CoorFive[2].y=mrt.top+1;
  175. if (iCont == m_iSelectTab || iCont == m_Numtabs-1 )
  176. {
  177. CoorFive[3].x=mrt.right-2;
  178. CoorFive[3].y=mrt.bottom+1;
  179. }
  180. else
  181. {
  182. CoorFive[3].x=(mrt.right)-5;
  183. CoorFive[3].y=(mrt.bottom-(m_rectTab.Height()/2))+1;
  184. }
  185. CoorFive[4].x=(mrt.right)-8;
  186. CoorFive[4].y=mrt.bottom+1;
  187. CoorFive[5].x=(mrt.left)+9;
  188. CoorFive[5].y=mrt.bottom+1;
  189. dc->Polygon(CoorFive,6);
  190. dc->SelectObject(pOldBrush);
  191. }
  192. m_right=mrt.right;
  193. if (iCont == m_iSelectTab )
  194. {
  195. CBrush brushRed(GuiDrawLayer::GetRGBColorWhite());
  196. CBrush* pOldBrush = dc->SelectObject(&brushRed);
  197. Coor[0].x=mrt.left;
  198. Coor[0].y=mrt.bottom;
  199. Coor[1].x=(mrt.left)+m_rectTab.Height()/2;
  200. Coor[1].y=mrt.top+1;
  201. Coor[2].x=(mrt.right)-m_rectTab.Height()/2; 
  202. Coor[2].y=mrt.top+1;
  203. Coor[3].x=(mrt.right-1);
  204. Coor[3].y=mrt.bottom;
  205. dc->Polygon(Coor,4);
  206. dc->SelectObject(pOldBrush);
  207. CPen* pOldPen=dc->SelectObject(&cpw);
  208. dc->MoveTo(mrt.left+1,mrt.bottom);
  209. dc->LineTo(mrt.right-1,mrt.bottom);
  210. dc->MoveTo(mrt.left+1,mrt.bottom+1);
  211. dc->LineTo(mrt.right-1,mrt.bottom+1);
  212. dc->SelectObject(pOldPen);
  213. }
  214. m_fontOld=dc->SelectObject(&m_cfont);
  215. dc->SetBkMode(TRANSPARENT);
  216. CRect mrtt=mrt; mrtt.top+=2;
  217. CSize m_sChar=dc->GetTextExtent(ctb->lpMsg,lstrlen(ctb->lpMsg));
  218. ctb->rect=mrt;
  219. m_right-=(m_rectTab.Height()/2);
  220. if (m_sChar.cx < ctb->rect.Width()-8)  
  221. {
  222. rectText=ctb->rect;
  223. dc->DrawText(ctb->lpMsg,mrtt,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
  224. }
  225. else
  226. {
  227. int nDif= ctb->rect.Width()-m_sizeImag.cx;
  228. nDif/=2;
  229. if(ctb->uIcon == -1) continue;
  230. Image.Draw(dc,ctb->uIcon,CPoint(ctb->rect.left+nDif,ctb->rect.top+2),ILD_TRANSPARENT);
  231. CToolTip.SetToolRect(this,iCont+1,CRect(0,0,0,0));
  232. }
  233. }
  234. GetClientRect(rc);
  235. if (m_ToolButton.GetSafeHwnd())
  236. {
  237. CSize m_SizeBtn=m_ToolButton.GetSizeButton();
  238. if (m_bShowButton==TRUE)
  239. {
  240. if (m_right+m_SizeBtn.cx > rc.Width())
  241. m_ToolButton.ShowWindow(SW_HIDE);
  242. else
  243. {
  244. rc.left=rc.right-(m_SizeBtn.cx+2);
  245. rc.bottom=m_rectTab.Height()-2;
  246. m_ToolButton.MoveWindow(rc.left,rc.top+1,m_SizeBtn.cx,rc.bottom-1);
  247. m_ToolButton.ShowWindow(SW_SHOW);
  248. }
  249. }
  250. }
  251. cbr.DeleteObject();
  252. dc->SetBkMode(nMode);
  253. dc->SelectObject(m_fontOld);
  254. dc->SelectObject(pOldPen);
  255. }
  256. void CGuiTabPowerPoint::ShowButtonClose(BOOL bShowButton)
  257. {
  258. m_bShowButton=bShowButton;
  259. };
  260. void CGuiTabPowerPoint::SetAutoAjust(BOOL bAjust)
  261. {
  262. bAutoAjust=bAjust;
  263. if (m_ToolButton.GetSafeHwnd())
  264. m_ToolButton.ShowWindow(bAutoAjust==FALSE?SW_HIDE:SW_SHOW);
  265. }
  266. void CGuiTabPowerPoint::SetColorTabs(COLORREF clrTabs)
  267. {
  268. m_clrTabs=clrTabs;
  269. }
  270. int CGuiTabPowerPoint::OnCreate(LPCREATESTRUCT lpCreateStruct)
  271. {
  272. if (CGuiTabWnd::OnCreate(lpCreateStruct) == -1)
  273. return -1;
  274. if (!m_img.Create(IDB_GUI_MDIICONS,9,3,RGB(255,0,255)))
  275. {
  276. TRACE0("error imagelist");
  277. }
  278. SetActualTitle(FALSE);
  279. SetALingTabs(CGuiTabWnd::ALN_TOP); //los tabs arriba
  280. SetStyle(CGuiTabWnd::FLAT);
  281. // TODO:  Add your specialized creation code here
  282. return 0;
  283. }
  284. void CGuiTabPowerPoint::SetIdButtonClose(UINT uClose)
  285. {
  286. m_ToolButton.ShowDark(FALSE);
  287. m_ToolButton.Create(_T(""),WS_CHILD|WS_VISIBLE|BS_OWNERDRAW,CRect(0,0,0,0),this,uClose);
  288. m_ToolButton.SetToolTip(_T("Close"));
  289. m_ToolButton.SethIcon(m_img.ExtractIcon(2));
  290. m_ToolButton.SetColor(GuiDrawLayer::GetRGBColorFace(GuiDrawLayer::m_Theme));
  291. m_bShowButton=TRUE;
  292. Invalidate();
  293. UpdateWindow();
  294. }