// Canvas.h : ラベル編集キャンバス(ダイアログ上の子ウィンドウ) // 旧 CLabelView の編集ロジックを CWnd ベースに移植(スクロール無し・ズーム有り)。 #pragma once #include "CoordMap.h" class CLabelLayout; class CPrintItem; class CCanvas : public CWnd { public: CCanvas(); virtual ~CCanvas(); BOOL Create(CWnd* pParent, const CRect& rc, UINT id); void SetLayout(CLabelLayout* p) { m_pLayout = p; m_pSelected = nullptr; } // ダイアログのボタンから呼ぶ操作 void InsertText(); void InsertRect(); void InsertLine(); void InsertImage(); void EditSelectedProperties(); void DeleteSelected(); void ZoomIn() { SetZoom(m_zoom * 1.25); } void ZoomOut() { SetZoom(m_zoom / 1.25); } void FitZoom(); // 用紙がキャンバスに収まる倍率へ // コピー/複製/Zオーダー/整列(ダイアログ・キーから呼ぶ) void CopySelected(); void Paste(); void DuplicateSelected(); void BringSelectedToFront(); void SendSelectedToBack(); void BringSelectedForward(); void SendSelectedBackward(); void AlignSelected(int how); // 0=左 1=水平中央 2=右 3=上 4=垂直中央 5=下 // グリッド/スナップ void SetSnap(BOOL b) { m_snap = b; Invalidate(); } BOOL GetSnap() const { return m_snap; } BOOL HasSelection() const { return m_pSelected != nullptr; } BOOL IsDirty() const { return m_dirty; } void SetDirty(BOOL b) { m_dirty = b; } void OnLayoutReplaced(); // New/Open 後の再描画+選択解除 double m_zoom; protected: CLabelLayout* m_pLayout; CPrintItem* m_pSelected; CPrintItem* m_pClipboard; // コピー保持(自前所有) BOOL m_dirty; BOOL m_snap; // グリッドスナップ有効 int m_gridHu; // グリッド間隔(1/100mm) int SnapHu(int hu) const; // 最近接グリッドへ丸め enum class Drag { None, Move, Resize }; Drag m_drag; int m_dragHandle; CPoint m_dragStartHu; CRect m_origRect; static const int kMargin = 14; CoordMap MakeMap() const; CoordMap MakeMap(int dpiX, int dpiY) const; CPoint HuFromClient(CPoint pt); void SetZoom(double z); void AddAndSelect(CPrintItem* p); afx_msg void OnPaint(); afx_msg BOOL OnEraseBkgnd(CDC* pDC); afx_msg void OnLButtonDown(UINT nFlags, CPoint point); afx_msg void OnLButtonUp(UINT nFlags, CPoint point); afx_msg void OnMouseMove(UINT nFlags, CPoint point); afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point); afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message); afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags); afx_msg UINT OnGetDlgCode(); // 矢印キー等をキャンバスへ届ける DECLARE_MESSAGE_MAP() };