Stroika Library 3.0d18
 
Loading...
Searching...
No Matches
RulerToolbar.h
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4
5#ifndef __RulerToolbar_h__
6#define __RulerToolbar_h__ 1
7
8#include "Stroika/Foundation/StroikaPreComp.h"
9
10#include <afxext.h>
11
12#include "Stroika/Frameworks/Led/Support.h"
13#include "Stroika/Frameworks/Led/WordProcessor.h"
14
15#include "LedItConfig.h"
16#include "Units.h"
17
18class LedItView;
19
20class RulerBar : public CControlBar {
21public:
22 RulerBar (BOOL b3DExt = TRUE);
23 ~RulerBar ();
24
25public:
26 virtual BOOL Create (CWnd* pParentWnd, DWORD dwStyle, UINT nID);
27
28protected:
29 void Update (const IncrementalParagraphInfo& pf);
30 void Update (const PARAFORMAT& pf);
31 void Update (CSize sizePaper, const CRect& rectMargins);
32
33 // ruler items include left margin, right margin, indent, and tabs
34
35 // horz positions in twips -- necessary to avoid rounding errors
36 // vertical position in pixels
37public:
38 class RulerItem {
39 public:
40 RulerItem (UINT nBitmapID = 0);
41 ~RulerItem ();
42 virtual BOOL HitTestPix (CPoint pt)
43 {
44 return GetHitRectPix ().PtInRect (pt);
45 }
46 virtual void Draw (CDC& dc);
47 virtual void SetHorzPosTwips (int nXPos);
48 virtual void TrackHorzPosTwips (int nXPos, BOOL bOnRuler = TRUE);
49 virtual void SetVertPos (int nYPos)
50 {
51 m_nYPosPix = nYPos;
52 }
53 virtual void SetAlignment (int nAlign)
54 {
55 m_nAlignment = nAlign;
56 }
57 virtual void SetRuler (RulerBar* pRuler)
58 {
59 m_pRuler = pRuler;
60 }
61 virtual void SetBounds (int nMin, int nMax)
62 {
63 m_nMin = nMin;
64 m_nMax = nMax;
65 }
66 int GetMin ()
67 {
68 return m_nMin;
69 }
70 int GetMax ()
71 {
72 return m_nMax;
73 }
74 void Invalidate ();
75 int GetVertPosPix ()
76 {
77 return m_nYPosPix;
78 }
79 int GetHorzPosTwips ()
80 {
81 return m_nXPosTwips;
82 }
83 int GetHorzPosPix ();
84 CRect GetHitRectPix ();
85 void DrawFocusLine ();
86 void SetTrack (BOOL b);
87
88 HBITMAP m_hbm;
89 HBITMAP m_hbmMask;
90 CSize m_size; // size of item in pixels
91
92 // Operations
93 BOOL LoadMaskedBitmap (LPCTSTR lpszResourceName);
94
95 protected:
96 int m_nYPosPix;
97 int m_nXPosTwips;
98 int m_nAlignment;
99 BOOL m_bTrack;
100 RulerBar* m_pRuler;
101 CRect m_rcTrack;
102 CDC* m_pDC; // dc used for drawing tracking line
103 int m_nMin, m_nMax;
104 };
105
106 class CComboRulerItem : public RulerItem {
107 public:
108 CComboRulerItem (UINT nBitmapID1, UINT nBitmapID2, RulerItem& item);
109 virtual BOOL HitTestPix (CPoint pt);
110 virtual void Draw (CDC& dc);
111 virtual void SetHorzPosTwips (int nXPos);
112 virtual void TrackHorzPosTwips (int nXPos, BOOL bOnRuler = TRUE);
113 virtual void SetVertPos (int nYPos);
114 virtual void SetAlignment (int nAlign);
115 virtual void SetRuler (RulerBar* pRuler);
116 virtual void SetBounds (int nMin, int nMax);
117 int GetMin ();
118 int GetMax ();
119
120 protected:
121 RulerItem m_secondary;
122 RulerItem& m_link;
123 BOOL m_bHitPrimary;
124 };
125
126 class CTabRulerItem : public RulerItem {
127 public:
128 CTabRulerItem ()
129 {
130 SetAlignment (TA_LEFT);
131 }
132 virtual void Draw (CDC& dc)
133 {
134 if (GetHorzPosTwips () != 0)
135 RulerItem::Draw (dc);
136 }
137 virtual void TrackHorzPosTwips (int nXPos, BOOL bOnRuler = TRUE);
138 virtual BOOL HitTestPix (CPoint pt)
139 {
140 return (GetHorzPosTwips () != 0) ? RulerItem::HitTestPix (pt) : FALSE;
141 }
142 };
143
144private:
145 BOOL m_bDeferInProgress;
146 BOOL m_bDraw3DExt;
147 Unit m_unit;
148 RulerItem* m_pSelItem;
149 CFont fnt;
150 CSize GetBaseUnits ();
151 CComboRulerItem m_leftmargin;
152 RulerItem m_indent;
153 RulerItem m_rightmargin;
154 RulerItem m_tabItem;
155 CTabRulerItem m_pTabItems[MAX_TAB_STOPS];
156 CSize m_sizePaper;
157 CRect m_rectMargin;
158 int PrintWidth ()
159 {
160 return m_sizePaper.cx - m_rectMargin.left - m_rectMargin.right;
161 }
162 int m_nTabs;
163 int m_logx;
164 int m_nLinePos;
165 int m_nScroll; // in pixels
166
167 CPen penFocusLine;
168 CPen penBtnHighLight;
169 CPen penBtnShadow;
170 CPen penWindowFrame;
171 CPen penBtnText;
172 CPen penBtnFace;
173 CPen penWindowText;
174 CPen penWindow;
175 CBrush brushWindow;
176 CBrush brushBtnFace;
177
178 // Implementation
179public:
180 virtual void DoPaint (CDC* pDC);
181 virtual CSize CalcFixedLayout (BOOL bStretch, BOOL bHorz);
182 void ClientToRuler (CPoint& pt)
183 {
184 pt.Offset (-m_cxLeftBorder + m_nScroll, -m_cyTopBorder);
185 }
186 void ClientToRuler (CRect& rect)
187 {
188 rect.OffsetRect (-m_cxLeftBorder + m_nScroll, -m_cyTopBorder);
189 }
190 void RulerToClient (CPoint& pt)
191 {
192 pt.Offset (m_cxLeftBorder - m_nScroll, m_cyTopBorder);
193 }
194 void RulerToClient (CRect& rect)
195 {
196 rect.OffsetRect (m_cxLeftBorder - m_nScroll, m_cyTopBorder);
197 }
198
199 int XTwipsToClient (int nT)
200 {
201 return MulDiv (nT, m_logx, 1440) + m_cxLeftBorder - m_nScroll;
202 }
203 int XClientToTwips (int nC)
204 {
205 return MulDiv (nC - m_cxLeftBorder + m_nScroll, 1440, m_logx);
206 }
207
208 int XTwipsToRuler (int nT)
209 {
210 return MulDiv (nT, m_logx, 1440);
211 }
212 int XRulerToTwips (int nR)
213 {
214 return MulDiv (nR, 1440, m_logx);
215 }
216
217 int XRulerToClient (int nR)
218 {
219 return nR + m_cxLeftBorder - m_nScroll;
220 }
221 int XClientToRuler (int nC)
222 {
223 return nC - m_cxLeftBorder + m_nScroll;
224 }
225
226protected:
227 virtual void OnUpdateCmdUI (CFrameWnd* pTarget, BOOL bDisableIfNoHndler);
228 void CreateGDIObjects ();
229 void DrawFace (CDC& dc);
230 void DrawTickMarks (CDC& dC);
231 void DrawNumbers (CDC& dc, int nInc, int nTPU);
232 void DrawDiv (CDC& dc, int nInc, int nLargeDiv, int nLength);
233 void DrawTabs (CDC& dc);
234 void FillInParaFormat (IncrementalParagraphInfo& pf);
235 void SortTabs ();
236 void SetMarginBounds ();
237 RulerItem* GetFreeTab ();
238 LedItView* GetView ();
239
240 CTabRulerItem* GetHitTabPix (CPoint pt);
241 afx_msg void OnLButtonDown (UINT nFlags, CPoint point);
242 afx_msg void OnLButtonUp (UINT nFlags, CPoint point);
243 afx_msg void OnMouseMove (UINT nFlags, CPoint point);
244 afx_msg void OnSysColorChange ();
245 afx_msg void OnWindowPosChanging (WINDOWPOS FAR* lpwndpos);
246 afx_msg void OnShowWindow (BOOL bShow, UINT nStatus);
247 afx_msg void OnWindowPosChanged (WINDOWPOS FAR* lpwndpos);
248 afx_msg LRESULT OnSizeParent (WPARAM wParam, LPARAM lParam);
249 DECLARE_MESSAGE_MAP ()
250private:
251 friend class RulerItem;
252};
253
254/*
255 ********************************************************************************
256 ***************************** Implementation Details ***************************
257 ********************************************************************************
258 */
259inline int RulerBar::RulerItem::GetHorzPosPix ()
260{
261 return m_pRuler->XTwipsToRuler (m_nXPosTwips);
262}
263
264#endif /*__RulerToolbar_h__*/