5#include "Stroika/Foundation/StroikaPreComp.h"
10#include "LedItResources.h"
13#include "RulerToolbar.h"
16using namespace Stroika::Frameworks::Led;
17using namespace Stroika::Frameworks::Led::Platform;
18using namespace Stroika::Frameworks::Led::StyledTextIO;
20using RulerItem = RulerBar::RulerItem;
21using CComboRulerItem = RulerBar::CComboRulerItem;
22using CTabRulerItem = RulerBar::CTabRulerItem;
25#define RULERBARHEIGHT 17
27RulerItem::RulerItem (UINT nBitmapID)
29 m_nAlignment = TA_CENTER;
35 m_hbmMask = ::LoadBitmap (AfxFindResourceHandle (MAKEINTRESOURCE (nBitmapID + 1), RT_BITMAP), MAKEINTRESOURCE (nBitmapID + 1));
36 ASSERT (m_hbmMask != NULL);
37 VERIFY (LoadMaskedBitmap (MAKEINTRESOURCE (nBitmapID)));
39 ::GetObject (m_hbm,
sizeof (BITMAP), &bm);
40 m_size = CSize (bm.bmWidth, bm.bmHeight);
44RulerItem::~RulerItem ()
47 ::DeleteObject (m_hbm);
48 if (m_hbmMask != NULL)
49 ::DeleteObject (m_hbmMask);
52BOOL RulerItem::LoadMaskedBitmap (LPCTSTR lpszResourceName)
54 ASSERT (lpszResourceName != NULL);
57 ::DeleteObject (m_hbm);
59 HINSTANCE hInst = AfxFindResourceHandle (lpszResourceName, RT_BITMAP);
60 HRSRC hRsrc = ::FindResource (hInst, lpszResourceName, RT_BITMAP);
64 m_hbm = AfxLoadSysColorBitmap (hInst, hRsrc);
65 return (m_hbm != NULL);
68void RulerItem::SetHorzPosTwips (
int nXPos)
70 if (GetHorzPosTwips () != nXPos) {
81void RulerItem::TrackHorzPosTwips (
int nXPos, BOOL )
89 SetHorzPosTwips (nXPos);
92void RulerItem::DrawFocusLine ()
94 if (GetHorzPosTwips () != 0) {
95 m_rcTrack.left = m_rcTrack.right = GetHorzPosPix ();
96 ASSERT (m_pDC != NULL);
97 int nLeft = m_pRuler->XRulerToClient (m_rcTrack.left);
98 m_pDC->MoveTo (nLeft, m_rcTrack.top);
99 m_pDC->LineTo (nLeft, m_rcTrack.bottom);
103void RulerItem::SetTrack (BOOL b)
109 m_pDC->RestoreDC (-1);
114 CView* pView = m_pRuler->GetView ();
115 ASSERT (pView != NULL);
116 pView->GetClientRect (&m_rcTrack);
117 m_pDC =
new CWindowDC (pView);
119 m_pDC->SelectObject (&m_pRuler->penFocusLine);
120 m_pDC->SetROP2 (R2_XORPEN);
125void RulerItem::Invalidate ()
127 CRect rc = GetHitRectPix ();
128 m_pRuler->RulerToClient (rc.TopLeft ());
129 m_pRuler->RulerToClient (rc.BottomRight ());
130 m_pRuler->InvalidateRect (rc);
133CRect RulerItem::GetHitRectPix ()
135 int nx = GetHorzPosPix ();
136 return CRect (CPoint ((m_nAlignment == TA_CENTER) ? (nx - m_size.cx / 2)
137 : (m_nAlignment == TA_LEFT) ? nx
143void RulerItem::Draw (CDC& dc)
146 dcBitmap.CreateCompatibleDC (&dc);
147 CPoint pt (GetHorzPosPix (), GetVertPosPix ());
149 HGDIOBJ hbm = ::SelectObject (dcBitmap.m_hDC, m_hbmMask);
152 if (m_nAlignment == TA_CENTER)
153 dc.BitBlt (pt.x - m_size.cx / 2, pt.y, m_size.cx, m_size.cy, &dcBitmap, 0, 0, SRCAND);
154 else if (m_nAlignment == TA_LEFT)
155 dc.BitBlt (pt.x, pt.y, m_size.cx, m_size.cy, &dcBitmap, 0, 0, SRCAND);
157 dc.BitBlt (pt.x - m_size.cx, pt.y, m_size.cx, m_size.cy, &dcBitmap, 0, 0, SRCAND);
160 ::SelectObject (dcBitmap.m_hDC, m_hbm);
162 if (m_nAlignment == TA_CENTER)
163 dc.BitBlt (pt.x - m_size.cx / 2, pt.y, m_size.cx, m_size.cy, &dcBitmap, 0, 0, SRCINVERT);
164 else if (m_nAlignment == TA_LEFT)
165 dc.BitBlt (pt.x, pt.y, m_size.cx, m_size.cy, &dcBitmap, 0, 0, SRCINVERT);
167 dc.BitBlt (pt.x - m_size.cx, pt.y, m_size.cx, m_size.cy, &dcBitmap, 0, 0, SRCINVERT);
169 ::SelectObject (dcBitmap.m_hDC, hbm);
172CComboRulerItem::CComboRulerItem (UINT nBitmapID1, UINT nBitmapID2, RulerItem& item)
173 : RulerItem (nBitmapID1)
174 , m_secondary (nBitmapID2)
177 m_bHitPrimary = TRUE;
180BOOL CComboRulerItem::HitTestPix (CPoint pt)
182 m_bHitPrimary = FALSE;
183 if (RulerItem::GetHitRectPix ().PtInRect (pt))
184 m_bHitPrimary = TRUE;
186 return m_secondary.HitTestPix (pt);
190void CComboRulerItem::Draw (CDC& dc)
192 RulerItem::Draw (dc);
193 m_secondary.Draw (dc);
196void CComboRulerItem::SetHorzPosTwips (
int nXPos)
199 m_link.SetHorzPosTwips (m_link.GetHorzPosTwips () + nXPos - GetHorzPosTwips ());
200 RulerItem::SetHorzPosTwips (nXPos);
201 m_secondary.SetHorzPosTwips (nXPos);
204void CComboRulerItem::TrackHorzPosTwips (
int nXPos, BOOL )
206 int nMin = GetMin ();
207 int nMax = GetMax ();
212 SetHorzPosTwips (nXPos);
215void CComboRulerItem::SetVertPos (
int nYPos)
217 m_secondary.SetVertPos (nYPos);
218 nYPos += m_secondary.GetHitRectPix ().Height ();
219 RulerItem::SetVertPos (nYPos);
222void CComboRulerItem::SetAlignment (
int nAlign)
224 RulerItem::SetAlignment (nAlign);
225 m_secondary.SetAlignment (nAlign);
228void CComboRulerItem::SetRuler (RulerBar* pRuler)
231 m_secondary.SetRuler (pRuler);
234void CComboRulerItem::SetBounds (
int nMin,
int nMax)
236 RulerItem::SetBounds (nMin, nMax);
237 m_secondary.SetBounds (nMin, nMax);
240int CComboRulerItem::GetMin ()
243 int nPDist = GetHorzPosTwips () - RulerItem::GetMin ();
244 int nLDist = m_link.GetHorzPosTwips () - m_link.GetMin ();
245 return GetHorzPosTwips () - min (nPDist, nLDist);
248 return RulerItem::GetMin ();
251int CComboRulerItem::GetMax ()
254 int nPDist = RulerItem::GetMax () - GetHorzPosTwips ();
255 int nLDist = m_link.GetMax () - m_link.GetHorzPosTwips ();
256 int nMinDist = (nPDist < nLDist) ? nPDist : nLDist;
257 return GetHorzPosTwips () + nMinDist;
260 return RulerItem::GetMax ();
263void CTabRulerItem::TrackHorzPosTwips (
int nXPos, BOOL bOnRuler)
266 RulerItem::TrackHorzPosTwips (nXPos, bOnRuler);
268 RulerItem::TrackHorzPosTwips (0, bOnRuler);
271BEGIN_MESSAGE_MAP (RulerBar, CControlBar)
276ON_WM_SYSCOLORCHANGE ()
277ON_WM_WINDOWPOSCHANGING ()
279ON_WM_WINDOWPOSCHANGED ()
281ON_MESSAGE (WM_SIZEPARENT, OnSizeParent)
285RulerBar::RulerBar (BOOL b3DExt)
286 : m_leftmargin (IDB_RULER_BLOCK, IDB_RULER_UP, m_indent)
287 , m_indent (IDB_RULER_DOWN)
288 , m_rightmargin (IDB_RULER_UP)
289 , m_tabItem (IDB_RULER_TAB)
291 m_bDeferInProgress = FALSE;
292 m_leftmargin.SetRuler (
this);
293 m_indent.SetRuler (
this);
294 m_rightmargin.SetRuler (
this);
297 for (
int i = 0; i < MAX_TAB_STOPS; ++i) {
298 m_pTabItems[i].m_hbm = m_tabItem.m_hbm;
299 m_pTabItems[i].m_hbmMask = m_tabItem.m_hbmMask;
300 m_pTabItems[i].m_size = m_tabItem.m_size;
308 HFONT hFont = (HFONT)GetStockObject (DEFAULT_GUI_FONT);
310 hFont = (HFONT)GetStockObject (ANSI_VAR_FONT);
311 VERIFY (GetObject (hFont,
sizeof (LOGFONT), &m_lf));
315 memcpy (&lf, &m_lf,
sizeof (LOGFONT));
318 VERIFY (fnt.CreateFontIndirect (&lf));
321 m_leftmargin.SetVertPos (9);
322 m_indent.SetVertPos (-1);
323 m_rightmargin.SetVertPos (9);
326 m_cxLeftBorder = Led_CvtScreenPixelsFromTWIPSH (kLedItViewLHSMargin);
327 m_bDraw3DExt = b3DExt;
330 m_cyBottomBorder = 6;
334 CWindowDC screenDC (NULL);
335 m_logx = screenDC.GetDeviceCaps (LOGPIXELSX);
340RulerBar::~RulerBar ()
343 for (
int i = 0; i < MAX_TAB_STOPS; ++i) {
344 m_pTabItems[i].m_hbm = NULL;
345 m_pTabItems[i].m_hbmMask = NULL;
349void RulerBar::CreateGDIObjects ()
351 penFocusLine.DeleteObject ();
352 penBtnHighLight.DeleteObject ();
353 penBtnShadow.DeleteObject ();
354 penWindowFrame.DeleteObject ();
355 penBtnText.DeleteObject ();
356 penBtnFace.DeleteObject ();
357 penWindowText.DeleteObject ();
358 penWindow.DeleteObject ();
359 brushWindow.DeleteObject ();
360 brushBtnFace.DeleteObject ();
362 penFocusLine.CreatePen (PS_DOT, 1, GetSysColor (COLOR_WINDOWTEXT));
363 penBtnHighLight.CreatePen (PS_SOLID, 0, GetSysColor (COLOR_BTNHIGHLIGHT));
364 penBtnShadow.CreatePen (PS_SOLID, 0, GetSysColor (COLOR_BTNSHADOW));
365 penWindowFrame.CreatePen (PS_SOLID, 0, GetSysColor (COLOR_WINDOWFRAME));
366 penBtnText.CreatePen (PS_SOLID, 0, GetSysColor (COLOR_BTNTEXT));
367 penBtnFace.CreatePen (PS_SOLID, 0, GetSysColor (COLOR_BTNFACE));
368 penWindowText.CreatePen (PS_SOLID, 0, GetSysColor (COLOR_WINDOWTEXT));
369 penWindow.CreatePen (PS_SOLID, 0, GetSysColor (COLOR_WINDOW));
370 brushWindow.CreateSolidBrush (GetSysColor (COLOR_WINDOW));
371 brushBtnFace.CreateSolidBrush (GetSysColor (COLOR_BTNFACE));
374LedItView* RulerBar::GetView ()
376 ASSERT (GetParent () != NULL);
377 return dynamic_cast<LedItView*
> (((CFrameWnd*)GetParent ())->GetActiveView ());
380void RulerBar::OnUpdateCmdUI (CFrameWnd* , BOOL )
385 if (m_pSelItem == NULL) {
386 LedItView* pView = GetView ();
389 CSize fakePaperSize (0x2fd0, 0x3de0);
390 CRect fakeMargins (0x5a0, 0x05a0, 0x708, 0x708);
391 Update (fakePaperSize, fakeMargins);
395 Update (pView->GetParaFormatSelection ());
400 ASSERT(pView != NULL);
401 Update(pView->GetPaperSize(), pView->GetMargins());
402 Update(pView->GetParaFormatSelection());
404 pView->GetRichEditCtrl().GetRect(&rect);
405 CPoint pt = rect.TopLeft();
406 pView->ClientToScreen(&pt);
408 if (m_cxLeftBorder != pt.x) {
409 m_cxLeftBorder = pt.x;
412 int nScroll = pView->GetScrollPos(SB_HORZ);
413 if (nScroll != m_nScroll) {
421CSize RulerBar::GetBaseUnits ()
423 ASSERT (fnt.GetSafeHandle () != NULL);
424 CWindowDC screenDC (NULL);
425 CFont* pFont = screenDC.SelectObject (&fnt);
427 VERIFY (screenDC.GetTextMetrics (&tm) == TRUE);
428 screenDC.SelectObject (pFont);
429 return CSize (tm.tmAveCharWidth, tm.tmHeight);
432BOOL RulerBar::Create (CWnd* pParentWnd, DWORD dwStyle, UINT nID)
434 ASSERT_VALID (pParentWnd);
436 dwStyle |= WS_CLIPSIBLINGS;
438 m_dwStyle = (dwStyle & CBRS_ALL);
442 rect.SetRectEmpty ();
443 LPCTSTR lpszClass = AfxRegisterWndClass (0, ::LoadCursor (NULL, IDC_ARROW), (HBRUSH)(COLOR_BTNFACE + 1), NULL);
445 if (!CWnd::Create (lpszClass, NULL, dwStyle, rect, pParentWnd, nID))
451 for (i = 0; i < MAX_TAB_STOPS; ++i) {
452 m_pTabItems[i].SetRuler (
this);
453 m_pTabItems[i].SetVertPos (8);
454 m_pTabItems[i].SetHorzPosTwips (0);
455 m_pTabItems[i].SetBounds (0, nMax);
460CSize RulerBar::CalcFixedLayout (BOOL bStretch, BOOL bHorz)
463 CSize m_size = CControlBar::CalcFixedLayout (bStretch, bHorz);
465 rectSize.SetRectEmpty ();
466 CalcInsideRect (rectSize, bHorz);
467 m_size.cy = RULERBARHEIGHT - rectSize.Height ();
473 if (pf.GetTabStopList_Valid ()) {
474 StandardTabStopList tabStops = pf.GetTabStopList ();
475 DistanceType tabSoFar = 0;
476 Require (tabStops.fTabStops.size () <= MAX_TAB_STOPS);
478 for (; i < tabStops.fTabStops.size (); ++i) {
479 tabSoFar += tabStops.fTabStops[i];
480 m_pTabItems[i].SetHorzPosTwips (tabSoFar);
482 for (; i < MAX_TAB_STOPS; ++i) {
483 m_pTabItems[i].SetHorzPosTwips (0);
487 if (pf.GetMargins_Valid ()) {
488 m_leftmargin.SetHorzPosTwips (pf.GetLeftMargin ());
489 m_rightmargin.SetHorzPosTwips (pf.GetRightMargin ());
490 if (pf.GetFirstIndent_Valid ()) {
491 m_indent.SetHorzPosTwips (pf.GetLeftMargin () + pf.GetFirstIndent ());
496void RulerBar::Update (CSize sizePaper,
const CRect& rectMargins)
498 if ((sizePaper != m_sizePaper) || (rectMargins != m_rectMargin)) {
499 m_sizePaper = sizePaper;
500 m_rectMargin = rectMargins;
504 if (m_unit.GetTPU () != StandardUnits::GetCurrentUnits ().GetTPU ()) {
505 m_unit = StandardUnits::GetCurrentUnits ();
511 if (m_unit.m_nTPU != theApp.GetTPU()) {
512 m_unit = theApp.GetUnit();
526 for (
size_t i = 0; i < MAX_TAB_STOPS; ++i) {
530 if (nPos != m_pTabItems[i].GetHorzPosTwips ()) {
531 nPos = m_pTabItems[i].GetHorzPosTwips ();
532 Assert (nPos > soFar);
534 v.push_back (TWIPS (nPos - soFar));
538 pf.SetTabStopList (StandardTabStopList{v});
540 pf.SetMargins (TWIPS{m_leftmargin.GetHorzPosTwips ()}, TWIPS{m_rightmargin.GetHorzPosTwips ()});
541 pf.SetFirstIndent (TWIPS{m_indent.GetHorzPosTwips () - m_leftmargin.GetHorzPosTwips ()});
545void RulerBar::SortTabs ()
548 for (i = 0; i < MAX_TAB_STOPS - 1; ++i) {
549 for (j = i + 1; j < MAX_TAB_STOPS; ++j) {
550 if (m_pTabItems[j].GetHorzPosTwips () < m_pTabItems[i].GetHorzPosTwips ()) {
551 nPos = m_pTabItems[j].GetHorzPosTwips ();
552 m_pTabItems[j].SetHorzPosTwips (m_pTabItems[i].GetHorzPosTwips ());
553 m_pTabItems[i].SetHorzPosTwips (nPos);
559void RulerBar::DoPaint (CDC* pDC)
561 CControlBar::DoPaint (pDC);
562 if (m_unit.m_nTPU != 0) {
565 CPoint pointOffset (0, 0);
566 RulerToClient (pointOffset);
567 pDC->SetViewportOrg (pointOffset);
570 DrawTickMarks (*pDC);
573 m_leftmargin.Draw (*pDC);
574 m_indent.Draw (*pDC);
575 m_rightmargin.Draw (*pDC);
582void RulerBar::DrawTabs (CDC& dc)
586 for (i = 0; i < MAX_TAB_STOPS; ++i) {
587 if (m_pTabItems[i].GetHorzPosTwips () > nPos)
588 nPos = (m_pTabItems[i].GetHorzPosTwips ());
589 m_pTabItems[i].Draw (dc);
591 int nPageWidth = PrintWidth ();
592 nPos = nPos - nPos % 720 + 720;
593 dc.SelectObject (&penBtnShadow);
594 for (; nPos < nPageWidth; nPos += 720) {
595 int nx = XTwipsToRuler (nPos);
596 dc.MoveTo (nx, HEIGHT - 1);
597 dc.LineTo (nx, HEIGHT + 1);
601void RulerBar::DrawFace (CDC& dc)
603 int nPageWidth = XTwipsToRuler (PrintWidth ());
604 int nPageEdge = XTwipsToRuler (PrintWidth () + m_rectMargin.right);
608 dc.SelectObject (&penBtnShadow);
610 dc.LineTo (nPageEdge - 1, 0);
611 dc.LineTo (nPageEdge - 1, HEIGHT - 2);
612 dc.LineTo (nPageWidth - 1, HEIGHT - 2);
613 dc.LineTo (nPageWidth - 1, 1);
614 dc.LineTo (nPageWidth, 1);
615 dc.LineTo (nPageWidth, HEIGHT - 2);
617 dc.SelectObject (&penBtnHighLight);
618 dc.MoveTo (nPageWidth, HEIGHT - 1);
619 dc.LineTo (nPageEdge, HEIGHT - 1);
620 dc.MoveTo (nPageWidth + 1, HEIGHT - 3);
621 dc.LineTo (nPageWidth + 1, 1);
622 dc.LineTo (nPageEdge - 1, 1);
624 dc.SelectObject (&penWindow);
625 dc.MoveTo (0, HEIGHT - 1);
626 dc.LineTo (nPageWidth, HEIGHT - 1);
628 dc.SelectObject (&penBtnFace);
629 dc.MoveTo (1, HEIGHT - 2);
630 dc.LineTo (nPageWidth - 1, HEIGHT - 2);
632 dc.SelectObject (&penWindowFrame);
633 dc.MoveTo (0, HEIGHT - 2);
635 dc.LineTo (nPageWidth - 1, 1);
637 dc.FillRect (CRect (1, 2, nPageWidth - 1, HEIGHT - 2), &brushWindow);
638 dc.FillRect (CRect (nPageWidth + 2, 2, nPageEdge - 1, HEIGHT - 2), &brushBtnFace);
641 GetClientRect (&rcClient);
642 ClientToRuler (rcClient);
643 rcClient.top = HEIGHT;
644 rcClient.bottom = HEIGHT + 2;
645 dc.FillRect (rcClient, &brushBtnFace);
647 CRect rectFill (rcClient.left, HEIGHT + 4, rcClient.right, HEIGHT + 9);
648 dc.FillRect (rectFill, &brushWindow);
651 dc.SelectObject (&penBtnShadow);
652 dc.MoveTo (rcClient.left, HEIGHT + 8);
653 dc.LineTo (rcClient.left, HEIGHT + 2);
654 dc.LineTo (rcClient.right - 1, HEIGHT + 2);
656 dc.SelectObject (&penWindowFrame);
657 dc.MoveTo (rcClient.left + 1, HEIGHT + 8);
658 dc.LineTo (rcClient.left + 1, HEIGHT + 3);
659 dc.LineTo (rcClient.right - 2, HEIGHT + 3);
661 dc.SelectObject (&penBtnHighLight);
662 dc.MoveTo (rcClient.right - 1, HEIGHT + 2);
663 dc.LineTo (rcClient.right - 1, HEIGHT + 8);
665 dc.SelectObject (&penBtnFace);
666 dc.MoveTo (rcClient.right - 2, HEIGHT + 3);
667 dc.LineTo (rcClient.right - 2, HEIGHT + 8);
670 dc.SelectObject (&penBtnShadow);
671 dc.MoveTo (rcClient.left, HEIGHT + 2);
672 dc.LineTo (rcClient.right, HEIGHT + 2);
674 dc.SelectObject (&penWindowFrame);
675 dc.MoveTo (rcClient.left, HEIGHT + 3);
676 dc.LineTo (rcClient.right, HEIGHT + 3);
682void RulerBar::DrawTickMarks (CDC& dc)
686 dc.SelectObject (&penWindowText);
687 dc.SelectObject (&fnt);
688 dc.SetTextColor (GetSysColor (COLOR_WINDOWTEXT));
689 dc.SetBkMode (TRANSPARENT);
691 DrawDiv (dc, m_unit.m_nSmallDiv, m_unit.m_nLargeDiv, 2);
692 DrawDiv (dc, m_unit.m_nMediumDiv, m_unit.m_nLargeDiv, 5);
693 DrawNumbers (dc, m_unit.m_nLargeDiv, m_unit.m_nTPU);
698void RulerBar::DrawNumbers (CDC& dc,
int nInc,
int nTPU)
700 int nPageWidth = PrintWidth ();
701 int nPageEdge = nPageWidth + m_rectMargin.right;
704 int nTwips, nPixel, nLen;
706 for (nTwips = nInc; nTwips < nPageEdge; nTwips += nInc) {
707 if (nTwips == nPageWidth)
709 nPixel = XTwipsToRuler (nTwips);
710 wsprintf (buf, _T(
"%d"), nTwips / nTPU);
711 nLen = lstrlen (buf);
712 CSize sz = dc.GetTextExtent (buf, nLen);
713 dc.ExtTextOut (nPixel - sz.cx / 2, HEIGHT / 2 - sz.cy / 2, 0, NULL, buf, nLen, NULL);
717void RulerBar::DrawDiv (CDC& dc,
int nInc,
int nLargeDiv,
int nLength)
719 int nPageWidth = PrintWidth ();
720 int nPageEdge = nPageWidth + m_rectMargin.right;
724 for (nTwips = nInc; nTwips < nPageEdge; nTwips += nInc) {
725 if (nTwips == nPageWidth || nTwips % nLargeDiv == 0)
727 nPixel = XTwipsToRuler (nTwips);
728 dc.MoveTo (nPixel, HEIGHT / 2 - nLength / 2);
729 dc.LineTo (nPixel, HEIGHT / 2 - nLength / 2 + nLength);
733void RulerBar::OnLButtonDown (UINT nFlags, CPoint point)
739 if (m_leftmargin.HitTestPix (pt))
740 m_pSelItem = &m_leftmargin;
741 else if (m_indent.HitTestPix (pt))
742 m_pSelItem = &m_indent;
743 else if (m_rightmargin.HitTestPix (pt))
744 m_pSelItem = &m_rightmargin;
746 m_pSelItem = GetHitTabPix (pt);
747 if (m_pSelItem == NULL)
748 m_pSelItem = GetFreeTab ();
749 if (m_pSelItem == NULL)
753 m_pSelItem->SetTrack (TRUE);
755 OnMouseMove (nFlags, point);
758void RulerBar::SetMarginBounds ()
760 m_leftmargin.SetBounds (0, m_rightmargin.GetHorzPosTwips ());
761 m_indent.SetBounds (0, m_rightmargin.GetHorzPosTwips ());
763 int nMin = (m_leftmargin.GetHorzPosTwips () > m_indent.GetHorzPosTwips ()) ? m_leftmargin.GetHorzPosTwips () : m_indent.GetHorzPosTwips ();
764 int nMax = PrintWidth () + m_rectMargin.right;
765 m_rightmargin.SetBounds (nMin, nMax);
768 for (
int i = 0; i < MAX_TAB_STOPS; ++i)
769 m_pTabItems[i].SetBounds (0, nMax);
772RulerItem* RulerBar::GetFreeTab ()
775 for (i = 0; i < MAX_TAB_STOPS; ++i) {
776 if (m_pTabItems[i].GetHorzPosTwips () == 0)
777 return &m_pTabItems[i];
782CTabRulerItem* RulerBar::GetHitTabPix (CPoint point)
785 for (i = 0; i < MAX_TAB_STOPS; ++i) {
786 if (m_pTabItems[i].HitTestPix (point))
787 return &m_pTabItems[i];
792void RulerBar::OnLButtonUp (UINT nFlags, CPoint point)
794 if (::GetCapture () != m_hWnd)
796 OnMouseMove (nFlags, point);
797 m_pSelItem->SetTrack (FALSE);
799 LedItView* pView = GetView ();
801 FillInParaFormat (pf);
802 pView->SetParaFormatSelection (pf);
807void RulerBar::OnMouseMove (UINT nFlags, CPoint point)
809 CControlBar::OnMouseMove (nFlags, point);
811 if (::GetCapture () != m_hWnd)
813 ASSERT (m_pSelItem != NULL);
814 CRect rc (0, 0, XTwipsToRuler (PrintWidth () + m_rectMargin.right), HEIGHT);
816 BOOL bOnRuler = rc.PtInRect (point);
819 point.x = XClientToTwips (point.x);
820 point.x += m_unit.m_nMinMove / 2;
821 point.x -= point.x % m_unit.m_nMinMove;
823 m_pSelItem->TrackHorzPosTwips (point.x, bOnRuler);
827void RulerBar::OnSysColorChange ()
829 CControlBar::OnSysColorChange ();
834void RulerBar::OnWindowPosChanging (WINDOWPOS FAR* lpwndpos)
836 CControlBar::OnWindowPosChanging (lpwndpos);
838 GetClientRect (rect);
839 int minx = min (rect.Width (), lpwndpos->cx);
840 int maxx = max (rect.Width (), lpwndpos->cx);
841 rect.SetRect (minx - 2, rect.bottom - 6, minx, rect.bottom);
842 InvalidateRect (rect);
843 rect.SetRect (maxx - 2, rect.bottom - 6, maxx, rect.bottom);
844 InvalidateRect (rect);
847void RulerBar::OnShowWindow (BOOL bShow, UINT nStatus)
849 CControlBar::OnShowWindow (bShow, nStatus);
850 m_bDeferInProgress = FALSE;
853void RulerBar::OnWindowPosChanged (WINDOWPOS FAR* lpwndpos)
855 CControlBar::OnWindowPosChanged (lpwndpos);
856 m_bDeferInProgress = FALSE;
859LRESULT RulerBar::OnSizeParent (WPARAM wParam, LPARAM lParam)
861 BOOL bVis = GetStyle () & WS_VISIBLE;
862 if ((bVis && (m_nStateFlags & delayHide)) || (!bVis && (m_nStateFlags & delayShow))) {
863 m_bDeferInProgress = TRUE;
865 return CControlBar::OnSizeParent (wParam, lParam);