PaneIcons.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:22k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // PaneIcons.cpp : implementation file
  2. //
  3. // This file is a part of the XTREME TOOLKIT PRO MFC class library.
  4. // (c)1998-2008 Codejock Software, All Rights Reserved.
  5. //
  6. // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
  7. // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
  8. // CONSENT OF CODEJOCK SOFTWARE.
  9. //
  10. // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
  11. // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
  12. // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
  13. // SINGLE COMPUTER.
  14. //
  15. // CONTACT INFORMATION:
  16. // support@codejock.com
  17. // http://www.codejock.com
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include "stdafx.h"
  21. #include "commandbarsdesigner.h"
  22. #include "PaneIcons.h"
  23. #include "MainFrm.h"
  24. #include "DialogNewIcon.h"
  25. #include "DialogBitmapExport.h"
  26. #include "DialogBitmapImport.h"
  27. #ifdef _DEBUG
  28. #define new DEBUG_NEW
  29. #undef THIS_FILE
  30. static char THIS_FILE[] = __FILE__;
  31. #endif
  32. #define ID_PANEICONS_COMBO 1011
  33. BEGIN_MESSAGE_MAP(CControlIconsView, CWnd)
  34. //{{AFX_MSG_MAP(CControlIconsView)
  35. ON_WM_ERASEBKGND()
  36. ON_WM_LBUTTONDOWN()
  37. ON_WM_PAINT()
  38. ON_WM_LBUTTONDBLCLK()
  39. ON_WM_VSCROLL()
  40. ON_WM_HSCROLL()
  41. ON_WM_SIZE()
  42. //}}AFX_MSG_MAP
  43. END_MESSAGE_MAP()
  44. LRESULT CControlIconsView::WindowProc(UINT message,WPARAM wParam,LPARAM lParam)
  45. {
  46. switch (message)
  47. {
  48. case WM_NCPAINT:
  49. {
  50. CWnd::WindowProc(message, wParam, lParam);
  51. CRect rc;
  52. GetWindowRect(&rc);
  53. CWindowDC dc(this);
  54. rc.OffsetRect(-rc.TopLeft());
  55. COLORREF clr = GetStaticFrameColor();
  56. dc.Draw3dRect(rc, clr, clr);
  57. return TRUE;
  58. }
  59. }
  60. return CWnd::WindowProc(message, wParam, lParam);
  61. }
  62. /////////////////////////////////////////////////////////////////////////////
  63. // CControlIconsView construction/destruction
  64. CControlIconsView::CControlIconsView()
  65. {
  66. m_pSelected = NULL;
  67. m_pIconSet = NULL;
  68. m_bScrollVisible[SB_VERT] = FALSE;
  69. m_bScrollVisible[SB_HORZ] = FALSE;
  70. }
  71. CControlIconsView::~CControlIconsView()
  72. {
  73. }
  74. #define THUMB_WIDTH (90 - 20)
  75. #define THUMB_HEIGHT (100 - 20)
  76. #define INFO_HEIGHT 15
  77. void CControlIconsViewItem::Draw(CDC* pDC, BOOL bSelected, int x, int y, CSize sz)
  78. {
  79. CRect rcPicture(x, y, x + sz.cx, y + sz.cy - INFO_HEIGHT);
  80. CRect rcInfo(CPoint(x, y + sz.cy - INFO_HEIGHT), CSize(sz.cx, INFO_HEIGHT));
  81. COLORREF clrText = GetXtremeColor(COLOR_BTNTEXT);
  82. if (!bSelected)
  83. {
  84. pDC->FillSolidRect(rcPicture, GetXtremeColor(COLOR_3DFACE));
  85. pDC->Draw3dRect(rcPicture, GetXtremeColor(COLOR_APPWORKSPACE), GetXtremeColor(COLOR_3DDKSHADOW));
  86. pDC->FillSolidRect(rcInfo, /*RGB(237, 237, 202)*/GetXtremeColor(XPCOLOR_TAB_INACTIVE_BACK));
  87. pDC->Draw3dRect(rcInfo, GetXtremeColor(COLOR_3DSHADOW), GetXtremeColor(COLOR_BTNHIGHLIGHT));
  88. } else
  89. {
  90. pDC->FillSolidRect(rcPicture, GetXtremeColor(COLOR_HIGHLIGHT));
  91. pDC->Draw3dRect(rcPicture, GetXtremeColor(COLOR_3DHIGHLIGHT), GetXtremeColor(COLOR_3DDKSHADOW));
  92. pDC->FillSolidRect(rcInfo, GetXtremeColor(COLOR_HIGHLIGHT));
  93. pDC->Draw3dRect(rcInfo, GetXtremeColor(COLOR_3DSHADOW), GetXtremeColor(COLOR_BTNHIGHLIGHT));
  94. pDC->DrawFocusRect(rcInfo);
  95. clrText = GetXtremeColor(COLOR_HIGHLIGHTTEXT);
  96. }
  97. CString str = imageState == xtpImageNormal? _T("Normal"): imageState == xtpImageChecked? _T("Checked"):
  98. imageState == xtpImageHot? _T("Hot") : imageState == xtpImagePressed? _T("Pressed") : _T("Disabled");
  99. pDC->SetTextColor(clrText);
  100. pDC->DrawText(str, rcInfo, DT_SINGLELINE|DT_END_ELLIPSIS|DT_VCENTER|DT_CENTER);
  101. CSize szDevice = pDC->GetTextExtent(_T("xxx"));
  102. CRect rcDevice(rcPicture);
  103. rcDevice.top = rcPicture.bottom - szDevice.cy - 4;
  104. str.Format(_T("%ix%i"), pIcon->GetWidth(), pIcon->GetHeight());
  105. pDC->DrawText(str, rcDevice, DT_SINGLELINE|DT_END_ELLIPSIS|DT_VCENTER|DT_CENTER);
  106. CRect rcImage (rcPicture);
  107. rcImage.DeflateRect(4, 4, 4, rcDevice.Height());
  108. CXTPImageManagerIconHandle& hIcon = GetIcon();
  109. ASSERT(!hIcon.IsEmpty());
  110. {
  111. CSize sz(min(pIcon->GetWidth(), rcImage.Width()), min(pIcon->GetHeight(), rcImage.Height()));
  112. CRect rcImageRect (CPoint(rcImage.CenterPoint().x - sz.cx /2, rcImage.CenterPoint().y - sz.cy /2), sz);
  113. pIcon->Draw(pDC, rcImageRect.TopLeft(), hIcon);
  114. rcImageRect.InflateRect(1, 1);
  115. pDC->Draw3dRect(rcImageRect, GetXtremeColor(COLOR_3DSHADOW), GetXtremeColor(COLOR_BTNHIGHLIGHT));
  116. }
  117. }
  118. CControlIconsViewItem* CControlIconsView::HitTest(CPoint pt)
  119. {
  120. POSITION pos = m_lstItems.GetHeadPosition();
  121. while (pos)
  122. {
  123. CControlIconsViewItem& item = m_lstItems.GetNext(pos);
  124. CRect rc(CPoint(- GetScrollOffset(SB_HORZ) + 3 + item.ptPosition.x * THUMB_WIDTH,  - GetScrollOffset(SB_VERT) + 3 + item.ptPosition.y * THUMB_HEIGHT), CSize(THUMB_WIDTH - 5, THUMB_HEIGHT - 5));
  125. if (rc.PtInRect(pt))
  126. return &item;
  127. }
  128. return NULL;
  129. }
  130. /////////////////////////////////////////////////////////////////////////////
  131. // CControlIconsView drawing
  132. void CControlIconsView::OnPaint()
  133. {
  134. CPaintDC dcPaint(this);
  135. CXTPClientRect rc(this);
  136. CXTPBufferDC dc(dcPaint, rc);
  137. dc.FillSolidRect(CXTPClientRect(this), GetXtremeColor(COLOR_APPWORKSPACE));
  138. CXTPFontDC fnt(&dc, XTPPaintManager()->GetRegularFont());
  139. dc.SetBkMode(TRANSPARENT);
  140. POSITION pos = m_lstItems.GetHeadPosition();
  141. while (pos)
  142. {
  143. CControlIconsViewItem& item = m_lstItems.GetNext(pos);
  144. item.Draw(&dc, m_pSelected == &item, - GetScrollOffset(SB_HORZ) + 3 + item.ptPosition.x * THUMB_WIDTH, - GetScrollOffset(SB_VERT) + 3 + item.ptPosition.y * THUMB_HEIGHT, CSize(THUMB_WIDTH - 5, THUMB_HEIGHT - 5));
  145. }
  146. }
  147. void CControlIconsView::RefreshIcons(CXTPImageManagerIconSet* pIconSet)
  148. {
  149. DeleteAllItems();
  150. CXTPImageManagerIconSet::CIconSetMap* pMapIcons = pIconSet->GetIcons();
  151. m_pIconSet = pIconSet;
  152. m_pSelected = NULL;
  153. POSITION pos = pMapIcons->GetStartPosition();
  154. UINT nWidth;
  155. CXTPImageManagerIcon* pIcon;
  156. int nCount = 0;
  157. while (pos)
  158. {
  159. pMapIcons->GetNextAssoc(pos, nWidth, pIcon);
  160. if (!pIcon->IsScaled())
  161. {
  162. CControlIconsViewItem itemNormal(nCount, 0, xtpImageNormal, pIcon);
  163. CControlIconsViewItem itemHot(nCount, 1, xtpImageHot, pIcon);
  164. CControlIconsViewItem itemDisabled(nCount, 2, xtpImageDisabled, pIcon);
  165. CControlIconsViewItem itemChecked(nCount, 3, xtpImageChecked, pIcon);
  166. CControlIconsViewItem itemPressed(nCount, 4, xtpImagePressed, pIcon);
  167. m_lstItems.AddTail(itemNormal);
  168. m_lstItems.AddTail(itemHot);
  169. m_lstItems.AddTail(itemDisabled);
  170. m_lstItems.AddTail(itemChecked);
  171. m_lstItems.AddTail(itemPressed);
  172. nCount++;
  173. }
  174. }
  175. UpdateScrollBars();
  176. Invalidate(FALSE);
  177. }
  178. void CControlIconsView::UpdateScrollBars()
  179. {
  180. int nStateCount = 5;
  181. int nCount = (int)m_lstItems.GetCount() / nStateCount;
  182. int nHeight = 3 + nCount * THUMB_HEIGHT;
  183. CXTPClientRect rc(this);
  184. m_bScrollVisible[SB_VERT] = rc.Height() < nHeight;
  185. ShowScrollBar(SB_VERT, m_bScrollVisible[SB_VERT]);
  186. if (m_bScrollVisible[SB_VERT])
  187. {
  188. SCROLLINFO  si ;
  189. si.cbSize = sizeof(SCROLLINFO) ;
  190. si.fMask = SIF_PAGE | SIF_RANGE ;
  191. si.nPage = rc.Height() ;
  192. si.nMax = nHeight - 1;
  193. si.nMin = 0 ;
  194. SetScrollInfo(SB_VERT, &si) ;
  195. EnableScrollBarCtrl(SB_VERT, TRUE);
  196. }
  197. int nWidth = m_lstItems.GetCount() > 0? 3 + nStateCount * THUMB_WIDTH: 0;
  198. m_bScrollVisible[SB_HORZ] = rc.Width() < nWidth;
  199. ShowScrollBar(SB_HORZ, m_bScrollVisible[SB_HORZ]);
  200. if (m_bScrollVisible[SB_HORZ])
  201. {
  202. SCROLLINFO  si ;
  203. si.cbSize = sizeof(SCROLLINFO);
  204. si.fMask = SIF_PAGE | SIF_RANGE ;
  205. si.nPage = rc.Width();
  206. si.nMax = nWidth - 1;
  207. si.nMin = 0 ;
  208. SetScrollInfo(SB_HORZ, &si) ;
  209. EnableScrollBarCtrl(SB_HORZ, TRUE);
  210. }
  211. }
  212. void CControlIconsView::OnSize(UINT nType, int cx, int cy)
  213. {
  214. CWnd::OnSize(nType, cx, cy);
  215. UpdateScrollBars();
  216. }
  217. void CControlIconsView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  218. {
  219. // its horizontal scroll bar
  220. int nCurPos = GetScrollPos(SB_VERT);
  221. // decide what to do for each diffrent scroll event
  222. switch(nSBCode)
  223. {
  224. case SB_LEFT: nCurPos = 0; break;
  225. case SB_RIGHT: nCurPos = GetScrollLimit(SB_VERT); break;
  226. case SB_LINELEFT: nCurPos = max(nCurPos - 6, 0); break;
  227. case SB_LINERIGHT: nCurPos = min(nCurPos + 6, GetScrollLimit(SB_VERT)); break;
  228. case SB_PAGELEFT: nCurPos = max(nCurPos - CXTPClientRect(this).Height(), 0); break;
  229. case SB_PAGERIGHT: nCurPos = min(nCurPos + CXTPClientRect(this).Height(), GetScrollLimit(SB_VERT)); break;
  230. case SB_THUMBTRACK:
  231. case SB_THUMBPOSITION:  nCurPos = nPos; break;
  232. }
  233. SetScrollPos(SB_VERT, nCurPos);
  234. Invalidate(FALSE);
  235. CWnd::OnVScroll(nSBCode, nPos, pScrollBar);
  236. }
  237. void CControlIconsView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  238. {
  239. // its horizontal scroll bar
  240. int nCurPos = GetScrollPos(SB_HORZ);
  241. // decide what to do for each diffrent scroll event
  242. switch(nSBCode)
  243. {
  244. case SB_LEFT: nCurPos = 0; break;
  245. case SB_RIGHT: nCurPos = GetScrollLimit(SB_HORZ); break;
  246. case SB_LINELEFT: nCurPos = max(nCurPos - 6, 0); break;
  247. case SB_LINERIGHT: nCurPos = min(nCurPos + 6, GetScrollLimit(SB_HORZ)); break;
  248. case SB_PAGELEFT: nCurPos = max(nCurPos - CXTPClientRect(this).Width(), 0); break;
  249. case SB_PAGERIGHT: nCurPos = min(nCurPos + CXTPClientRect(this).Width(), GetScrollLimit(SB_HORZ)); break;
  250. case SB_THUMBTRACK:
  251. case SB_THUMBPOSITION:  nCurPos = nPos; break;
  252. }
  253. SetScrollPos(SB_HORZ, nCurPos);
  254. Invalidate(FALSE);
  255. CWnd::OnVScroll(nSBCode, nPos, pScrollBar);
  256. }
  257. int CControlIconsView::GetScrollOffset(int nBar)
  258. {
  259. if (!m_bScrollVisible[nBar])
  260. return 0;
  261. return GetScrollPos(nBar);
  262. }
  263. /////////////////////////////////////////////////////////////////////////////
  264. // CControlIconsView message handlers
  265. BOOL CControlIconsView::OnEraseBkgnd(CDC* /*pDC*/)
  266. {
  267. return TRUE;
  268. }
  269. void CControlIconsView::OnLButtonDown(UINT /*nFlags*/, CPoint point)
  270. {
  271. CControlIconsViewItem* pSelected = HitTest(point);
  272. if (pSelected != m_pSelected)
  273. {
  274. m_pSelected = pSelected;
  275. Invalidate(FALSE);
  276. }
  277. SetFocus();
  278. }
  279. void CControlIconsView::Edit()
  280. {
  281. if (!m_pSelected)
  282. return;
  283. CControlIconsViewItem* pSelected = m_pSelected;
  284. CXTPImageEditorDlg id;
  285. id.SetIcon(pSelected->GetIcon());
  286. if (id.DoModal() == IDOK)
  287. {
  288. CXTPImageManagerIconHandle iconHandle;
  289. id.GetIcon(&iconHandle);
  290. pSelected->pIcon->SetIcon(iconHandle, pSelected->imageState);
  291. m_pPaneIcons->GetImageManager()->RefreshAll();
  292. m_pPaneIcons->SetModified();
  293. m_pPaneIcons->RefreshAll();
  294. }
  295. }
  296. void CControlIconsView::OnLButtonDblClk(UINT nFlags, CPoint point)
  297. {
  298. if (m_pSelected)
  299. {
  300. Edit();
  301. return;
  302. }
  303. CWnd::OnLButtonDblClk(nFlags, point);
  304. }
  305. /////////////////////////////////////////////////////////////////////////////
  306. // CPaneIcons
  307. CPaneIcons::CPaneIcons()
  308. {
  309. m_wndIconsView.m_pPaneIcons = this;
  310. m_pActiveIcons = NULL;
  311. m_pLastControl = NULL;
  312. m_pImageManager = NULL;
  313. m_pActiveFrame = NULL;
  314. m_pActiveResourceManager = NULL;
  315. }
  316. CPaneIcons::~CPaneIcons()
  317. {
  318. }
  319. BEGIN_MESSAGE_MAP(CPaneIcons, CWnd)
  320. //{{AFX_MSG_MAP(CPaneIcons)
  321. ON_WM_CREATE()
  322. ON_WM_SIZE()
  323. ON_COMMAND(ID_PANEICONS_CLEAR, OnPaneiconsClear)
  324. ON_UPDATE_COMMAND_UI(ID_PANEICONS_CLEAR, OnUpdatePaneiconsClear)
  325. ON_COMMAND(ID_PANEICONS_NEW, OnPaneiconsNew)
  326. ON_UPDATE_COMMAND_UI(ID_PANEICONS_NEW, OnUpdatePaneiconsNew)
  327. ON_COMMAND(ID_PANEICONS_EDIT, OnPaneiconsEdit)
  328. ON_UPDATE_COMMAND_UI(ID_PANEICONS_EDIT, OnUpdatePaneiconsEdit)
  329. ON_UPDATE_COMMAND_UI(ID_PANEICONS_IMPORT_AND_EXPORT, OnUpdatePaneiconsImportAndExport)
  330. ON_COMMAND(ID_IMPORTANDEXPORT_EXPORTTOXML, OnImportandexportExporttoxml)
  331. ON_COMMAND(ID_IMPORTANDEXPORT_IMPORTFROMXML, OnImportandexportImportfromxml)
  332. ON_UPDATE_COMMAND_UI(ID_IMPORTANDEXPORT_EXPORTTOXML, OnUpdateXMLCommand)
  333. ON_UPDATE_COMMAND_UI(ID_IMPORTANDEXPORT_IMPORTFROMXML, OnUpdateXMLCommand)
  334. ON_COMMAND(ID_IMPORTANDEXPORT_EXPORTTOBITMAP, OnImportandexportExporttobitmap)
  335. ON_COMMAND(ID_IMPORTANDEXPORT_IMPORTFROMBITMAP, OnImportandexportImportfrombitmap)
  336. //}}AFX_MSG_MAP
  337. ON_CBN_SELCHANGE(ID_PANEICONS_COMBO, OnComboChanged)
  338. END_MESSAGE_MAP()
  339. CString CPaneIcons::GetStringID(int nID)
  340. {
  341. if (m_pActiveResourceManager)
  342. return m_pActiveResourceManager->GetStringID(nID);
  343. CString str;
  344. str.Format(_T("%i"), nID);
  345. return str;
  346. }
  347. void CPaneIcons::RefreshIcons()
  348. {
  349. //m_wndListBox.ResetContent();
  350. m_wndCombo.ResetContent();
  351. m_wndIconsView.DeleteAllItems();
  352. m_wndIconsView.m_pIconSet = NULL;
  353. m_wndIconsView.m_pSelected = NULL;
  354. if (GetImageManager() == NULL)
  355. {
  356. m_wndIconsView.Invalidate(FALSE);
  357. return;
  358. }
  359. CMap<UINT, UINT, CXTPImageManagerIconSet*, CXTPImageManagerIconSet*>* pIcons = GetImageManager()->GetImages();
  360. UINT nIDCommand;
  361. CXTPImageManagerIconSet* pIconSet;
  362. POSITION pos = pIcons->GetStartPosition();
  363. while (pos)
  364. {
  365. pIcons->GetNextAssoc(pos, nIDCommand, pIconSet);
  366. //if (nIDCommand >= 1000 && nIDCommand < 4000)
  367. {
  368. if (pIconSet)
  369. {
  370. CString str = GetStringID(pIconSet->GetID());
  371. int nIndex = m_wndCombo.AddString(str);
  372. m_wndCombo.SetItemData(nIndex, (DWORD_PTR)pIconSet);
  373. if (m_pActiveIcons == pIconSet)
  374. {
  375. m_wndCombo.SetCurSel(nIndex);
  376. m_wndIconsView.RefreshIcons(pIconSet);
  377. }
  378. }
  379. }
  380. }
  381. m_wndIconsView.Invalidate(FALSE);
  382. }
  383. /////////////////////////////////////////////////////////////////////////////
  384. // CPaneIcons message handlers
  385. CXTPImageManager* CPaneIcons::GetImageManager()
  386. {
  387. return m_pImageManager;
  388. }
  389. int CPaneIcons::OnCreate(LPCREATESTRUCT lpCreateStruct)
  390. {
  391. if (CWnd::OnCreate(lpCreateStruct) == -1)
  392. return -1;
  393. VERIFY(m_wndToolBar.CreateToolBar(WS_VISIBLE|WS_CHILD|CBRS_TOOLTIPS, this));
  394. VERIFY(m_wndToolBar.LoadToolBar(IDR_PANE_ICONS));
  395. m_wndToolBar.GetControls()->FindControl(xtpControlButton, ID_PANEICONS_EDIT, TRUE, FALSE)
  396. ->SetStyle(xtpButtonIconAndCaption);
  397. CXTPControlPopup* pControl = (CXTPControlPopup*)m_wndToolBar.GetControls()->SetControlType(3, xtpControlButtonPopup);
  398. pControl->SetStyle(xtpButtonCaption);
  399. CMenu menu;
  400. menu.LoadMenu(IDR_PANE_ICONS_IMPORT_AND_EXPORT);
  401. pControl->GetCommandBar()->LoadMenu(menu.GetSubMenu(0));
  402. if (!m_wndIconsView.CWnd::CreateEx(WS_EX_STATICEDGE, AfxRegisterWndClass(CS_DBLCLKS, ::LoadCursor(0, IDC_ARROW)), NULL,
  403. WS_CHILD|WS_VISIBLE|SS_NOTIFY, CRect(0, 0, 0, 0), this, AFX_IDW_PANE_FIRST))
  404. {
  405. TRACE0("Failed to create tree control.n");
  406. return -1;
  407. }
  408. m_wndIconsView.ModifyStyleEx(0, WS_EX_STATICEDGE);
  409. CFont* pFont = XTPPaintManager()->GetRegularFont();
  410. LOGFONT lf = {sizeof(LOGFONT)};
  411. pFont->GetLogFont(&lf);
  412. m_fntRegular.CreateFontIndirect(&lf);
  413. m_wndCombo.Create(WS_VISIBLE|WS_CHILD|CBS_DROPDOWNLIST, CRect(0, 0, 0, 200), this, ID_PANEICONS_COMBO);
  414. m_wndCombo.SetFont(&m_fntRegular);
  415. return 0;
  416. }
  417. void CPaneIcons::OnSize(UINT nType, int cx, int cy)
  418. {
  419. CWnd::OnSize(nType, cx, cy);
  420. int nTop = 0;
  421. if (m_wndCombo.GetSafeHwnd())
  422. {
  423. CRect rc;
  424. m_wndCombo.GetWindowRect(&rc);
  425. m_wndCombo.MoveWindow(0, 0, cx, rc.Height());
  426. nTop += rc.Height();
  427. }
  428. if (m_wndToolBar.GetSafeHwnd())
  429. {
  430. CSize sz = m_wndToolBar.CalcDockingLayout(cx, /*LM_HIDEWRAP|*/ LM_HORZDOCK|LM_HORZ | LM_COMMIT);
  431. m_wndToolBar.MoveWindow(0, nTop, cx, sz.cy);
  432. m_wndToolBar.Invalidate(FALSE);
  433. nTop += sz.cy;
  434. }
  435. if (m_wndIconsView.GetSafeHwnd())
  436. {
  437. m_wndIconsView.MoveWindow(0, nTop, cx, cy - nTop);
  438. m_wndIconsView.Invalidate(FALSE);
  439. }
  440. }
  441. void CPaneIcons::SetModified()
  442. {
  443. if (m_pActiveFrame)
  444. {
  445. m_pActiveFrame->GetCommandBars()->RedrawCommandBars();
  446. }
  447. }
  448. void CPaneIcons::RefreshAll()
  449. {
  450. GetMainFrame()->RefreshPanes(TRUE);
  451. }
  452. void CPaneIcons::ShowIcons(CXTPImageManager* pImageManager, int nActive)
  453. {
  454. if (!m_hWnd)
  455. return;
  456. if (m_pActiveFrame)
  457. {
  458. m_pActiveFrame->GetCommandBars()->SetDragControl(NULL);
  459. }
  460. m_pActiveResourceManager = NULL;
  461. m_pImageManager = pImageManager;
  462. m_pActiveIcons = pImageManager->GetIconSet(nActive);
  463. m_pLastControl = NULL;
  464. RefreshIcons();
  465. }
  466. void CPaneIcons::Refresh(BOOL bForce)
  467. {
  468. CEmbeddedFrame* pActiveFrame = GetMainFrame()->GetActiveEmbeddedFrame();
  469. CXTPImageManager* pImageManager = pActiveFrame ? pActiveFrame->GetCommandBars()->GetImageManager() : NULL;
  470. if (pActiveFrame != m_pActiveFrame)
  471. {
  472. m_pActiveFrame = pActiveFrame;
  473. m_pImageManager = pImageManager;
  474. m_pActiveResourceManager = m_pActiveFrame ? m_pActiveFrame->ResourceManager() : NULL;
  475. RefreshIcons();
  476. return;
  477. }
  478. if (bForce)
  479. {
  480. RefreshIcons();
  481. return;
  482. }
  483. if (m_pActiveFrame)
  484. {
  485. CXTPControl* pControl = m_pActiveFrame->GetCommandBars()->GetDragControl();
  486. if (pControl && m_pLastControl != pControl)
  487. {
  488. CXTPImageManagerIconSet* pIconSet = m_pActiveFrame->GetCommandBars()->GetImageManager()->GetIconSet(pControl->GetIconId());
  489. if (pIconSet && pIconSet != m_pActiveIcons)
  490. {
  491. m_pImageManager = m_pActiveFrame->GetCommandBars()->GetImageManager();
  492. m_pActiveIcons = pIconSet;
  493. m_pActiveResourceManager = m_pActiveFrame->ResourceManager();
  494. RefreshIcons();
  495. }
  496. m_pLastControl = pControl;
  497. }
  498. }
  499. }
  500. void CPaneIcons::OnComboChanged()
  501. {
  502. int nIndex = m_wndCombo.GetCurSel();
  503. if (nIndex != CB_ERR)
  504. {
  505. m_pActiveIcons = (CXTPImageManagerIconSet*)m_wndCombo.GetItemData(nIndex);
  506. }
  507. else
  508. {
  509. m_pActiveIcons = NULL;
  510. }
  511. RefreshIcons();
  512. }
  513. void CPaneIcons::RemoveIcons(CXTPImageManagerIconSet* pIconSet, CXTPImageManagerIcon* pIconRemove)
  514. {
  515. CXTPImageManagerIconSet::CIconSetMap* pMapIcons = pIconSet->GetIcons();
  516. POSITION pos = pMapIcons->GetStartPosition();
  517. UINT nWidth;
  518. CXTPImageManagerIcon* pIcon;
  519. while (pos)
  520. {
  521. pMapIcons->GetNextAssoc(pos, nWidth, pIcon);
  522. if (pIcon == pIconRemove)
  523. {
  524. pMapIcons->RemoveKey(nWidth);
  525. delete pIcon;
  526. break;
  527. }
  528. }
  529. if (pMapIcons->IsEmpty())
  530. {
  531. CMap<UINT, UINT, CXTPImageManagerIconSet*, CXTPImageManagerIconSet*>* pIcons = GetImageManager()->GetImages();
  532. UINT nIDCommand;
  533. CXTPImageManagerIconSet* pIconSetRemove;
  534. POSITION pos = pIcons->GetStartPosition();
  535. while (pos)
  536. {
  537. pIcons->GetNextAssoc(pos, nIDCommand, pIconSetRemove);
  538. if (pIconSetRemove == pIconSet)
  539. {
  540. pIcons->RemoveKey(nIDCommand);
  541. delete pIconSet;
  542. break;
  543. }
  544. }
  545. }
  546. }
  547. void CPaneIcons::OnPaneiconsClear()
  548. {
  549. CControlIconsViewItem* pSelected = m_wndIconsView.m_pSelected;
  550. if (pSelected)
  551. {
  552. switch(pSelected->imageState)
  553. {
  554. case xtpImageNormal: 
  555. RemoveIcons(m_pActiveIcons, pSelected->pIcon); 
  556. break;
  557. default:
  558. CXTPImageManagerIconHandle& icon = pSelected->pIcon->GetIcon(pSelected->imageState);
  559. CXTPImageManagerIconHandle& iconNormal = pSelected->pIcon->GetIcon();
  560. if (&icon != &iconNormal) icon.Clear(); 
  561. break;
  562. }
  563. RefreshIcons();
  564. SetModified();
  565. }
  566. }
  567. void CPaneIcons::OnUpdatePaneiconsClear(CCmdUI* pCmdUI)
  568. {
  569. pCmdUI->Enable(m_wndIconsView.m_pSelected != NULL);
  570. }
  571. HICON GenerateIcon(int nWidth, int nHeight)
  572. {
  573. CImageList il;
  574. il.Create(nWidth, nHeight, ILC_COLOR24 |ILC_MASK, 0, 0);
  575. il.Add(AfxGetApp()->LoadIcon(IDI_ICONEMPTY));
  576. return il.ExtractIcon(0);
  577. }
  578. void CPaneIcons::OnPaneiconsNew()
  579. {
  580. if (!GetImageManager())
  581. return;
  582. CDialogNewIcon dni;
  583. int nIndex = m_wndCombo.GetCurSel();
  584. if (nIndex != CB_ERR) m_wndCombo.GetLBText(nIndex, dni.m_strId);
  585. if (dni.DoModal() == IDOK)
  586. {
  587. int nIDCommand = m_pActiveResourceManager ? m_pActiveResourceManager->GetStringID(dni.m_strId) : _ttoi(dni.m_strId);
  588. if (nIDCommand == 0)
  589. return;
  590. int nWidth = _ttoi(dni.m_strWidth);
  591. int nHeight = _ttoi(dni.m_strHeight);
  592. HICON hIcon = GenerateIcon(nWidth, nHeight);
  593. GetImageManager()->SetIcon(hIcon, nIDCommand);
  594. m_pActiveIcons = GetImageManager()->GetIconSet(nIDCommand);
  595. RefreshIcons();
  596. SetModified();
  597. RefreshAll();
  598. }
  599. }
  600. void CPaneIcons::OnUpdatePaneiconsNew(CCmdUI* pCmdUI)
  601. {
  602. pCmdUI->Enable(GetImageManager() != NULL);
  603. }
  604. void CPaneIcons::OnPaneiconsEdit()
  605. {
  606. if (m_wndIconsView.m_pSelected)
  607. {
  608. m_wndIconsView.Edit();
  609. }
  610. }
  611. void CPaneIcons::OnUpdatePaneiconsEdit(CCmdUI* pCmdUI)
  612. {
  613. pCmdUI->Enable(m_wndIconsView.m_pSelected != NULL);
  614. }
  615. void CPaneIcons::OnUpdatePaneiconsImportAndExport(CCmdUI* pCmdUI)
  616. {
  617. pCmdUI->Enable(GetImageManager() != NULL);
  618. }
  619. void CPaneIcons::OnImportandexportExporttoxml()
  620. {
  621. if (GetImageManager() == NULL)
  622. return;
  623. CString strFilter = _T("XML Document (*.xml)|*.xml|All files (*.*)|*.*||");
  624. CFileDialog fd(FALSE, _T("xml"), NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, strFilter);
  625. if (fd.DoModal() != IDOK)
  626. return;
  627. CXTPPropExchangeXMLNode px(FALSE, 0, _T("DesignerFile"));
  628. CXTPPropExchangeSection secImages(px.GetSection(_T("Images")));
  629. GetImageManager()->DoPropExchange(&secImages);
  630. px.SaveToFile(fd.GetFileName());
  631. }
  632. void CPaneIcons::OnImportandexportImportfromxml()
  633. {
  634. if (GetImageManager() == NULL)
  635. return;
  636. CString strFilter = _T("XML Document (*.xml)|*.xml|All files (*.*)|*.*||");
  637. CFileDialog fd(TRUE, _T("xml"), NULL, OFN_FILEMUSTEXIST| OFN_HIDEREADONLY, strFilter);
  638. if (fd.DoModal() != IDOK)
  639. return;
  640. CXTPPropExchangeXMLNode px(TRUE, NULL, _T("DesignerFile"));
  641. if (!px.LoadFromFile(fd.GetPathName()))
  642. return;
  643. CXTPPropExchangeSection secImages(px.GetSection(_T("Images")));
  644. GetImageManager()->DoPropExchange(&secImages);
  645. RefreshAll();
  646. SetModified();
  647. }
  648. void CPaneIcons::OnUpdateXMLCommand(CCmdUI* pCmdUI)
  649. {
  650. pCmdUI->Enable(IsXMLEngineAvailable() && GetImageManager() != NULL);
  651. }
  652. void CPaneIcons::OnImportandexportExporttobitmap()
  653. {
  654. if (!GetImageManager())
  655. return;
  656. CDialogBitmapExport dbe(GetImageManager(), m_pActiveResourceManager);
  657. dbe.DoModal();
  658. }
  659. void CPaneIcons::OnImportandexportImportfrombitmap()
  660. {
  661. if (!GetImageManager())
  662. return;
  663. CString strFilter = _T("Bitmap Files (*.bmp;*.png)|*.bmp; *.png|All files (*.*)|*.*||");
  664. CFileDialog fd(TRUE, _T("bmp"), NULL, OFN_FILEMUSTEXIST| OFN_HIDEREADONLY, strFilter);
  665. if (fd.DoModal() != IDOK)
  666. return;
  667. CDialogBitmapImport dbi(GetImageManager(), fd.GetPathName(), m_pActiveResourceManager);
  668. dbi.DoModal();
  669. RefreshAll();
  670. SetModified();
  671. }