📄 prlistviewdialog.cpp
字号:
/* * * prlistviewdialog.cpp * Copyright (C) 2006 Michael H. Overlin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Contact at poster_printer@yahoo.com * */#include "prlistviewdialog.h"#include "resource.h"#include "viewableprintpageslist.h"#include "..\lib\mathutils.h"#include <windows.h>#include <commctrl.h>#include <vector>#define ZOOM_SLIDER_MIN 0#define ZOOM_SLIDER_MAX 100#define ZOOM_OUT_MIN 1#define ZOOM_OUT_MAX_DEFAULT 10#define ZOOM_OUT_MAX_MIN 2#define ZOOM_OUT_MAX_MAX 1000// *************************************************************************************************//static TCHAR g_atstrWinProp[] = TEXT("iuhsqkhbx PRListViewDialog");PRListViewDialog::PRListViewDialog(IN HINSTANCE hinst, IN WORD wTemplateID) : DialogWindow(hinst, wTemplateID) { m_plvw = NULL; m_hcursHand = ::LoadIcon(this->hinst(), MAKEINTRESOURCE(IDI_ICON_HAND)); m_hcursDottedSel = ::LoadIcon(this->hinst(), MAKEINTRESOURCE(IDI_ICON_DOTTEDSELECT)); m_hcursBoxSel = ::LoadIcon(this->hinst(), MAKEINTRESOURCE(IDI_ICON_BOXSELECT)); m_dZoomOutMin = ZOOM_OUT_MIN; m_dZoomOutMax = ZOOM_OUT_MAX_DEFAULT;}PRListViewDialog::~PRListViewDialog() { // NOTHING TO DELETE}::ViewableList* PRListViewDialog::SetList(::ViewableList *pvl, const ::RulerDrawerProvider *prdp, ListViewWindow::ArrowSelectionMode arrowSelMode, const SIZED& szdMinSelectionBox) { ::ViewableList* p = m_plvw->SetList(pvl, prdp, arrowSelMode, szdMinSelectionBox); this->SendDlgItemMessage(IDC_SLIDER_ZOOM, TBM_SETPOS, (WPARAM) TRUE, ZOOM_SLIDER_MIN); this->CalculateZoomScale(); return p;}void PRListViewDialog::SetArrowSelectionBox(BOOL bSelection, const RECTD *prdSelection, IN BOOL bSendNotification) { m_plvw->SetArrowSelectionBox(bSelection, prdSelection, bSendNotification);}void PRListViewDialog::GetItemPointsInMosaic(std::vector<POINT>& vptPages, BOOL bSelected) const { const ::ViewablePrintPagesList *pvppl = (const ::ViewablePrintPagesList*) m_plvw->GetList(); const std::vector<uint>& vsel = this->GetSelectionItems(); for(uint ui = 0; ui < pvppl->GetCount(); ++ui) { POINT ptInMosaic = pvppl->GetItemPointInMosaic(ui); BOOL bAdd = !bSelected || ( (vsel[ui] & ViewableList::eArrowSel) != 0 ); if (bAdd) { vptPages.push_back(ptInMosaic); } }}void PRListViewDialog::SetCursorType(::ListViewWindow::CursorType ct) { m_plvw->SetCursorType(ct); this->SetButtonsForListViewCursorType(ct);}void PRListViewDialog::SetInfoText(LPCTSTR lptstrLabel, int iIndex) { WORD wID = 0; switch(iIndex) { case 0: wID = IDC_STATIC_INFO1; break; case 1: wID = IDC_STATIC_INFO2; break; case 2: wID = IDC_STATIC_INFO3; break; default: ASSERTFAIL(); break; } this->SetDlgItemText(wID, lptstrLabel);}// ***// *** PRIVATE: class PRListViewDialog// ***BOOL PRListViewDialog::InitMsg(WPARAM wParam, LPARAM lParam) { DialogWindow::InitMsg(wParam, lParam); HWND hwndVW = this->GetDlgItem(IDC_PRVIEWWINDOW); RECT r; GetClientRect(hwndVW, &r); m_plvw = (ListViewWindow*) ListViewWindow::TheirGetObjPtr(hwndVW); HWND hwndHand = this->GetDlgItem(IDC_RADIO_HAND); HWND hwndArrow = this->GetDlgItem(IDC_RADIO_ARROW); // 7/2 //::SendMessage(hwndHand, BM_SETIMAGE, IMAGE_ICON, (LPARAM) LoadCursor(NULL, IDC_HAND)); //::SendMessage(hwndArrow, BM_SETIMAGE, IMAGE_ICON, (LPARAM) LoadCursor(NULL, IDC_ARROW)); ::SendMessage(hwndHand, BM_SETIMAGE, IMAGE_ICON, (LPARAM) m_hcursHand); ::SendMessage(hwndArrow, BM_SETIMAGE, IMAGE_ICON, (LPARAM) m_hcursDottedSel); //m_plvw->SetCursorResources(m_hcursHand, NULL); m_plvw->SetCursorResources(LoadCursor(NULL, IDC_HAND), NULL); HWND hwndSlider = ::GetDlgItem(this->hdlg(), IDC_SLIDER_ZOOM); this->SendDlgItemMessage(IDC_SLIDER_ZOOM, TBM_SETRANGE, (WPARAM) FALSE, (LPARAM) MAKELONG(ZOOM_SLIDER_MIN, ZOOM_SLIDER_MAX)); this->SendDlgItemMessage(IDC_SLIDER_ZOOM, TBM_SETPOS, (WPARAM) TRUE, (LPARAM) ZOOM_SLIDER_MIN); // TEMP DEBUG //SIZED szdMinSelectionBox = { 1, 1 }; //m_plvw->Init(ListViewWindow::eSelectItems, szdMinSelectionBox); //m_plvw->Init(ListViewWindow::eSelectBox, szdMinSelectionBox);#if 0 Debug_ViewableList *p = new Debug_ViewableList; std::vector<uint> vuiTicks; vuiTicks.push_back(2); vuiTicks.push_back(2); vuiTicks.push_back(2); RulerDrawer *prdHoriz = new RulerDrawer(vuiTicks, 0.25, 1, 0, 20, RulerPlacementSpec::eHorizontal); RulerDrawer *prdVert = new RulerDrawer(vuiTicks, 0.25, 1, 0, 20, RulerPlacementSpec::eVertical); m_plvw->SetList(p, prdHoriz, prdVert);#endif this->CheckDlgButton(IDC_CHECK_DRAFT, FALSE); // 7/3 ListViewWindow::CursorType ct = m_plvw->GetCursorType(); this->SetButtonsForListViewCursorType(ct); return TRUE;}BOOL PRListViewDialog::CommandMsg(WPARAM wParam, LPARAM lParam) { WORD wCmd = LOWORD(wParam); switch(wCmd) { case IDC_CHECK_DRAFT: { BOOL bDraft = this->IsDlgButtonChecked(IDC_CHECK_DRAFT); m_plvw->SetDraftMode(bDraft); } break; case IDC_RADIO_ARROW: m_plvw->SetCursorType(ListViewWindow::eArrow); break; case IDC_RADIO_HAND: m_plvw->SetCursorType(ListViewWindow::eHand); break; default: break; } // switch(wCmd) return TRUE;}BOOL PRListViewDialog::NotifyMsg(WPARAM wParam, LPARAM lParam) { BOOL bRetValue = FALSE; int idCtrl = (int) wParam; switch(idCtrl) { case IDC_PRVIEWWINDOW: { LPNMHDR lpnmh = (LPNMHDR) lParam; UINT uiCode = lpnmh->code; switch(uiCode) { case ListViewWindow::eRulerUnitsChange: { tstring tstrUnitsLabel; BOOL bHasHorizUnits = m_plvw->HasRulerUnitLabel(RulerPlacementSpec::eHorizontal); BOOL bHasVertUnits = m_plvw->HasRulerUnitLabel(RulerPlacementSpec::eVertical); if (bHasHorizUnits || bHasVertUnits) { if (bHasHorizUnits && bHasVertUnits) { const tstring& tstrHoriz = m_plvw->GetRulerUnitLabel(RulerPlacementSpec::eHorizontal); const tstring& tstrVert = m_plvw->GetRulerUnitLabel(RulerPlacementSpec::eVertical); if (tstrHoriz == tstrVert) { tstrUnitsLabel = tstring(TEXT("Ruler units: ")) + tstrHoriz; } else { tstrUnitsLabel = tstring(TEXT("Horizontal ruler units: ")) + tstrHoriz + tstring(TEXT(" --- Vertical ruler units: ")) + tstrVert; } } else if (bHasHorizUnits) { const tstring& tstr = m_plvw->GetRulerUnitLabel(RulerPlacementSpec::eHorizontal); tstrUnitsLabel = tstring(TEXT("Ruler units: ")) + tstr; } else { const tstring& tstr = m_plvw->GetRulerUnitLabel(RulerPlacementSpec::eVertical); tstrUnitsLabel = tstring(TEXT("Ruler units: ")) + tstr; } } this->SetDlgItemText(IDC_STATIC_RULERUNITS, tstrUnitsLabel.c_str()); bRetValue = TRUE; } break; case ListViewWindow::eArrowSelectionModeChange: { ListViewWindow::ArrowSelectionMode mode = m_plvw->GetArrowSelectionMode(); HWND hwndArrow = this->GetDlgItem(IDC_RADIO_ARROW); switch(mode) { case ListViewWindow::eSelectBox: ::SendMessage(hwndArrow, BM_SETIMAGE, IMAGE_ICON, (LPARAM) m_hcursBoxSel); break; case ListViewWindow::eSelectItems: ::SendMessage(hwndArrow, BM_SETIMAGE, IMAGE_ICON, (LPARAM) m_hcursDottedSel); break; default: // DEBUG / FIX - COMPILE TIME ASSERTFAIL(); break; } } break; default: break; } } break; default: break; } return bRetValue;}inline double sqr(const double d) { return d*d; }BOOL PRListViewDialog::ScrollMsg(UINT msg, WPARAM wParam, LPARAM lParam) { // FIX -- GET MIN/MAX ZOOM FROM THE LIST VIEW double dZoomIn = (double) this->SendDlgItemMessage(IDC_SLIDER_ZOOM, TBM_GETPOS, 0, 0); double dZoomOut = sqr(dZoomIn - ZOOM_SLIDER_MIN) * (m_dZoomOutMax - m_dZoomOutMin) / sqr( (double) (ZOOM_SLIDER_MAX - ZOOM_SLIDER_MIN) ) + m_dZoomOutMin; m_plvw->SetZoomLevel(dZoomOut); return TRUE;}// ****// **** private: class PRListViewDialog// ****void PRListViewDialog::CalculateZoomScale(void) { const ::ViewableList *pList = m_plvw->GetList(); if (pList != NULL) { RECTD rdList ; pList->GetBounds(rdList); SIZED szdList = { RW(rdList), RH(rdList) }; uint nList = pList->GetCount(); double dMax = 0; for(uint ui = 0; ui < nList; ++ui) { RECTD rdItem; pList->GetItemRuledBounds(ui, rdItem); SIZED szdItem = { RW(rdItem), RH(rdItem) }; double d1 = szdList.cx / szdItem.cx; double d2 = szdList.cy / szdItem.cy; double d3 = min(d1, d2) * ZOOM_OUT_MAX_DEFAULT; dMax = max(dMax, d3); } if (dMax < ZOOM_OUT_MAX_MIN) { m_dZoomOutMax = ZOOM_OUT_MAX_MIN; } else if (dMax > ZOOM_OUT_MAX_MAX) { m_dZoomOutMax = ZOOM_OUT_MAX_MAX; } else { m_dZoomOutMax = dMax; } } else { m_dZoomOutMax = ZOOM_OUT_MAX_DEFAULT; }}void PRListViewDialog::SetButtonsForListViewCursorType(::ListViewWindow::CursorType ct) { switch(ct) { case ListViewWindow::eHand: this->CheckDlgButton(IDC_RADIO_HAND, TRUE); this->CheckDlgButton(IDC_RADIO_ARROW, FALSE); break; case ListViewWindow::eArrow: this->CheckDlgButton(IDC_RADIO_HAND, FALSE); this->CheckDlgButton(IDC_RADIO_ARROW, TRUE); break; default: // DEBUG / FIX MAKE THIS A COMPILE TIME CHECK ASSERTFAIL(); break; }}// **********************************************************************************************#if 0class Debug_ViewableList : public ViewableList {public:Debug_ViewableList(VOID) { rd.left = rd.top = 0; rd.right = rd.bottom = 1; }WORD GetCount(VOID) const { return 1; }VOID GetBounds(OUT RECTD& _rd) const { _rd = this->rd; }VOID GetItemBounds(IN WORD wiItem, OUT RECTD& _rd) const { _rd = rd; }BOOL ItemFromPt(OUT uint& uiItem, IN const PPOINTD& ptd) const { return FALSE; }BOOL HitTestItem(IN const POINTD& ptd) const { return FALSE; }VOID DrawItem(OUT HDC hdcDest, IN const RECT& rDest, IN WORD wiItem, IN const CoordTrans& trans, IN BOOL bSelected) const { RECT r; trans.DoTrans(this->rd, r); ::DrawEllipse(hdcDest, r); ::DrawRectangle(hdcDest, r);}VOID Draw(OUT HDC hdcDest, IN const RECT& rDest, IN const CoordTrans& trans, const std::vector<BOOL> &vbSelected) const { DrawItem(hdcDest, rDest, 0, trans, FALSE);}private: RECTD rd;};#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -