1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
23 #include <tools/shl.hxx>
24 #include <vcl/image.hxx>
25 #include <vcl/svapp.hxx>
26 #include <vcl/settings.hxx>
27 #include <svl/eitem.hxx>
28 #include <svl/rectitem.hxx>
29 #include <svl/smplhint.hxx>
30 #include <sfx2/dispatch.hxx>
31 #include <svx/dialogs.hrc>
32 #include <svx/dialmgr.hxx>
33 #include <svx/ruler.hxx>
34 #include <svx/rulritem.hxx>
35 #include <editeng/tstpitem.hxx>
36 #include <editeng/lrspitem.hxx>
37 #include <editeng/protitem.hxx>
39 #include <svx/svdtrans.hxx>
41 #include "rlrcitem.hxx"
44 #define RULER_TAB_RTL ((sal_uInt16)0x0010)
47 // STATIC DATA -----------------------------------------------------------
49 #define CTRL_ITEM_COUNT 14
51 #define OBJECT_BORDER_COUNT 4
54 #define INDENT_FIRST_LINE 2
55 #define INDENT_LEFT_MARGIN 3
56 #define INDENT_RIGHT_MARGIN 4
57 #define INDENT_COUNT 3 //without the first two old values
60 #include <vcl/lstbox.hxx>
61 class RulerDebugWindow
: public Window
65 RulerDebugWindow(Window
* pParent
) :
66 Window(pParent
, WB_BORDER
|WB_SIZEMOVE
|WB_DIALOGCONTROL
|WB_CLIPCHILDREN
|WB_SYSTEMWINDOW
),
69 Size
aOutput(200, 400);
70 SetOutputSizePixel(aOutput
);
71 aBox
.SetSizePixel(aOutput
);
74 Size
aParentSize(pParent
->GetOutputSizePixel());
75 Size
aOwnSize(GetSizePixel());
76 aParentSize
.Width() -= aOwnSize
.Width();
77 aParentSize
.Height() -= aOwnSize
.Height();
78 SetPosPixel(Point(aParentSize
.Width(), aParentSize
.Height()));
82 ListBox
& GetLBox() {return aBox
;}
83 static void AddDebugText(const sal_Char
* pDescription
, const OUString
& rText
);
85 static RulerDebugWindow
* pDebugWindow
= 0;
87 RulerDebugWindow::~RulerDebugWindow()
91 void RulerDebugWindow::AddDebugText(const sal_Char
* pDescription
, const OUString
& rText
)
95 Window
* pParent
= Application::GetFocusWindow();
96 while(pParent
->GetParent())
97 pParent
= pParent
->GetParent();
98 pDebugWindow
= new RulerDebugWindow(pParent
);
100 OUString
sContent( OUString::createFromAscii(pDescription
) );
102 sal_uInt16 nPos
= pDebugWindow
->GetLBox().InsertEntry(sContent
);
103 pDebugWindow
->GetLBox().SelectEntryPos(nPos
);
104 pDebugWindow
->GrabFocus();
107 #define ADD_DEBUG_TEXT(cDescription, sValue) \
108 RulerDebugWindow::AddDebugText(cDescription, sValue);
110 #define REMOVE_DEBUG_WINDOW \
111 delete pDebugWindow; \
115 #define ADD_DEBUG_TEXT(cDescription, sValue)
116 #define REMOVE_DEBUG_WINDOW
119 struct SvxRuler_Impl
{
120 sal_uInt16
*pPercBuf
;
121 sal_uInt16
*pBlockBuf
;
122 sal_uInt16 nPercSize
;
129 SvxProtectItem aProtectItem
;
130 SfxBoolItem
* pTextRTLItem
;
131 sal_uInt16 nControlerItems
;
133 sal_uInt16 nColLeftPix
;
134 sal_uInt16 nColRightPix
; // Pixel values for left / right edge
135 // For columns; buffered to prevent
136 // recalculation errors
137 // May be has to be widen for future values
138 bool bIsTableRows
: 1; // mpColumnItem contains table rows instead of columns
139 //#i24363# tab stops relative to indent
140 bool bIsTabsRelativeToIndent
: 1; // Tab stops relative to paragraph indent?
143 pPercBuf(0), pBlockBuf(0), nPercSize(0), nTotalDist(0),
144 lOldWinPos(0), lMaxLeftLogic(0), lMaxRightLogic(0),
145 lLastLMargin(0), lLastRMargin(0), aProtectItem(SID_RULER_PROTECT
),
146 pTextRTLItem(0), nControlerItems(0), nIdx(0),
147 nColLeftPix(0), nColRightPix(0),
149 bIsTabsRelativeToIndent(true)
155 nPercSize
= 0; nTotalDist
= 0;
156 delete[] pPercBuf
; delete[] pBlockBuf
; pPercBuf
= 0;
159 void SetPercSize(sal_uInt16 nSize
);
163 void SvxRuler_Impl::SetPercSize(sal_uInt16 nSize
)
165 if(nSize
> nPercSize
)
169 pPercBuf
= new sal_uInt16
[nPercSize
= nSize
];
170 pBlockBuf
= new sal_uInt16
[nPercSize
= nSize
];
172 size_t nSize2
= sizeof(sal_uInt16
) * nPercSize
;
173 memset(pPercBuf
, 0, nSize2
);
174 memset(pBlockBuf
, 0, nSize2
);
177 // Constructor of the ruler
179 // SID_ATTR_ULSPACE, SID_ATTR_LRSPACE
180 // expects as parameter SvxULSpaceItem for page edge
181 // (either left/right or top/bottom)
182 // Ruler: SetMargin1, SetMargin2
184 // SID_RULER_PAGE_POS
185 // expectes as parameter the initial value of the page and page width
189 // expects: SvxTabStopItem
192 // SID_ATTR_PARA_LRSPACE
193 // left, right paragraph edge in H-ruler
197 // Table borders, columns
198 // expects: something like SwTabCols
202 Window
* pParent
, // StarView Parent
203 Window
* pWin
, // Output window: is used for conversion
204 // logical units <-> pixels
205 sal_uInt16 flags
, // Display flags, see ruler.hxx
206 SfxBindings
&rBindings
, // associated Bindings
207 WinBits nWinStyle
) : // StarView WinBits
208 Ruler(pParent
, nWinStyle
),
209 pCtrlItem(new SvxRulerItem
* [CTRL_ITEM_COUNT
]),
211 mpRulerImpl(new SvxRuler_Impl
),
212 bAppSetNullOffset(false), // Is the 0-offset of the ruler set by the application?
214 lAppNullOffset(LONG_MAX
),
219 nDefTabType(RULER_TAB_LEFT
),
224 mpBorders(1), // due to one column tables
225 pBindings(&rBindings
),
232 mbCoarseSnapping(false),
236 /* Constructor; Initialize data buffer; controller items are created */
238 memset(pCtrlItem
, 0, sizeof(SvxRulerItem
*) * CTRL_ITEM_COUNT
);
240 rBindings
.EnterRegistrations();
242 // Create Supported Items
246 pCtrlItem
[i
++] = new SvxRulerItem(SID_RULER_LR_MIN_MAX
, *this, rBindings
);
247 if((nWinStyle
& WB_VSCROLL
) == WB_VSCROLL
)
250 pCtrlItem
[i
++] = new SvxRulerItem(SID_ATTR_LONG_ULSPACE
, *this, rBindings
);
255 pCtrlItem
[i
++] = new SvxRulerItem(SID_ATTR_LONG_LRSPACE
, *this, rBindings
);
259 pCtrlItem
[i
++] = new SvxRulerItem(SID_RULER_PAGE_POS
, *this, rBindings
);
261 if((nFlags
& SVXRULER_SUPPORT_TABS
) == SVXRULER_SUPPORT_TABS
)
263 sal_uInt16 nTabStopId
= bHorz
? SID_ATTR_TABSTOP
: SID_ATTR_TABSTOP_VERTICAL
;
264 pCtrlItem
[i
++] = new SvxRulerItem(nTabStopId
, *this, rBindings
);
265 SetExtraType(RULER_EXTRA_TAB
, nDefTabType
);
268 if(0 != (nFlags
& (SVXRULER_SUPPORT_PARAGRAPH_MARGINS
|SVXRULER_SUPPORT_PARAGRAPH_MARGINS_VERTICAL
)))
271 pCtrlItem
[i
++] = new SvxRulerItem(SID_ATTR_PARA_LRSPACE
, *this, rBindings
);
273 pCtrlItem
[i
++] = new SvxRulerItem(SID_ATTR_PARA_LRSPACE_VERTICAL
, *this, rBindings
);
275 mpIndents
.resize(5 + INDENT_GAP
);
277 for(sal_uInt32 nIn
= 0; nIn
< mpIndents
.size(); nIn
++)
279 mpIndents
[nIn
].nPos
= 0;
280 mpIndents
[nIn
].nStyle
= RULER_STYLE_DONTKNOW
;
283 mpIndents
[0].nStyle
= RULER_STYLE_DONTKNOW
;
284 mpIndents
[1].nStyle
= RULER_STYLE_DONTKNOW
;
285 mpIndents
[INDENT_FIRST_LINE
].nStyle
= RULER_INDENT_TOP
;
286 mpIndents
[INDENT_LEFT_MARGIN
].nStyle
= RULER_INDENT_BOTTOM
;
287 mpIndents
[INDENT_RIGHT_MARGIN
].nStyle
= RULER_INDENT_BOTTOM
;
290 if( (nFlags
& SVXRULER_SUPPORT_BORDERS
) == SVXRULER_SUPPORT_BORDERS
)
292 pCtrlItem
[i
++] = new SvxRulerItem(bHorz
? SID_RULER_BORDERS
: SID_RULER_BORDERS_VERTICAL
, *this, rBindings
);
293 pCtrlItem
[i
++] = new SvxRulerItem(bHorz
? SID_RULER_ROWS
: SID_RULER_ROWS_VERTICAL
, *this, rBindings
);
296 pCtrlItem
[i
++] = new SvxRulerItem(SID_RULER_TEXT_RIGHT_TO_LEFT
, *this, rBindings
);
298 if( (nFlags
& SVXRULER_SUPPORT_OBJECT
) == SVXRULER_SUPPORT_OBJECT
)
300 pCtrlItem
[i
++] = new SvxRulerItem(SID_RULER_OBJECT
, *this, rBindings
);
301 mpObjectBorders
.resize(OBJECT_BORDER_COUNT
);
302 for(sal_uInt16 nBorder
= 0; nBorder
< OBJECT_BORDER_COUNT
; ++nBorder
)
304 mpObjectBorders
[nBorder
].nPos
= 0;
305 mpObjectBorders
[nBorder
].nWidth
= 0;
306 mpObjectBorders
[nBorder
].nStyle
= RULER_BORDER_MOVEABLE
;
310 pCtrlItem
[i
++] = new SvxRulerItem(SID_RULER_PROTECT
, *this, rBindings
);
311 pCtrlItem
[i
++] = new SvxRulerItem(SID_RULER_BORDER_DISTANCE
, *this, rBindings
);
312 mpRulerImpl
->nControlerItems
=i
;
314 if( (nFlags
& SVXRULER_SUPPORT_SET_NULLOFFSET
) == SVXRULER_SUPPORT_SET_NULLOFFSET
)
315 SetExtraType(RULER_EXTRA_NULLOFFSET
, 0);
317 rBindings
.LeaveRegistrations();
320 SvxRuler::~SvxRuler()
322 /* Destructor ruler; release internal buffer */
325 EndListening(*pBindings
);
327 pBindings
->EnterRegistrations();
329 for(sal_uInt16 i
= 0; i
< CTRL_ITEM_COUNT
&& pCtrlItem
[i
]; ++i
)
333 pBindings
->LeaveRegistrations();
336 long SvxRuler::MakePositionSticky(long aPosition
, long aPointOfReference
, bool aSnapToFrameMargin
) const
338 long aPointOfReferencePixel
= ConvertHPosPixel(aPointOfReference
);
339 long aLeftFramePosition
= ConvertHPosPixel(GetLeftFrameMargin());
340 long aRightFramePosition
= ConvertHPosPixel(GetRightFrameMargin());
342 double aTick
= GetCurrentRulerUnit().nTick1
;
344 if (mbCoarseSnapping
)
345 aTick
= GetCurrentRulerUnit().nTick2
;
347 long aTickPixel
= pEditWin
->LogicToPixel(Size(aTick
, 0), GetCurrentMapMode()).Width();
349 double aHalfTick
= aTick
/ 2.0;
350 double aHalfTickPixel
= aTickPixel
/ 2.0;
352 if (aSnapToFrameMargin
)
354 if (aPosition
> aLeftFramePosition
- aHalfTickPixel
&& aPosition
< aLeftFramePosition
+ aHalfTickPixel
)
355 return aLeftFramePosition
;
357 if (aPosition
> aRightFramePosition
- aHalfTickPixel
&& aPosition
< aRightFramePosition
+ aHalfTickPixel
)
358 return aRightFramePosition
;
364 // Move "coordinate system" to frame position so ticks are calculated correctly
365 long aTranslatedPosition
= aPosition
- aPointOfReferencePixel
;
366 // Convert position to current selected map mode
367 long aPositionLogic
= pEditWin
->PixelToLogic(Size(aTranslatedPosition
, 0), GetCurrentMapMode()).Width();
368 // Normalize -- snap to nearest tick
369 aPositionLogic
= rtl::math::round((aPositionLogic
+ aHalfTick
) / aTick
) * aTick
;
370 // Convert back to pixels
371 aPosition
= pEditWin
->LogicToPixel(Size(aPositionLogic
, 0), GetCurrentMapMode()).Width();
372 // Move "coordinate system" back to original position
373 return aPosition
+ aPointOfReferencePixel
;
376 long SvxRuler::ConvertHPosPixel(long nVal
) const
378 return pEditWin
->LogicToPixel(Size(nVal
, 0)).Width();
381 long SvxRuler::ConvertVPosPixel(long nVal
) const
383 return pEditWin
->LogicToPixel(Size(0, nVal
)).Height();
386 long SvxRuler::ConvertHSizePixel(long nVal
) const
388 return pEditWin
->LogicToPixel(Size(nVal
, 0)).Width();
391 long SvxRuler::ConvertVSizePixel(long nVal
) const
393 return pEditWin
->LogicToPixel(Size(0, nVal
)).Height();
396 long SvxRuler::ConvertPosPixel(long nVal
) const
398 return bHorz
? ConvertHPosPixel(nVal
): ConvertVPosPixel(nVal
);
401 long SvxRuler::ConvertSizePixel(long nVal
) const
403 return bHorz
? ConvertHSizePixel(nVal
): ConvertVSizePixel(nVal
);
406 inline long SvxRuler::ConvertHPosLogic(long nVal
) const
408 return pEditWin
->PixelToLogic(Size(nVal
, 0)).Width();
411 inline long SvxRuler::ConvertVPosLogic(long nVal
) const
413 return pEditWin
->PixelToLogic(Size(0, nVal
)).Height();
416 inline long SvxRuler::ConvertHSizeLogic(long nVal
) const
418 return pEditWin
->PixelToLogic(Size(nVal
, 0)).Width();
421 inline long SvxRuler::ConvertVSizeLogic(long nVal
) const
423 return pEditWin
->PixelToLogic(Size(0, nVal
)).Height();
426 inline long SvxRuler::ConvertPosLogic(long nVal
) const
428 return bHorz
? ConvertHPosLogic(nVal
): ConvertVPosLogic(nVal
);
431 inline long SvxRuler::ConvertSizeLogic(long nVal
) const
433 return bHorz
? ConvertHSizeLogic(nVal
): ConvertVSizeLogic(nVal
);
436 long SvxRuler::PixelHAdjust(long nVal
, long nValOld
) const
438 if(ConvertHSizePixel(nVal
) != ConvertHSizePixel(nValOld
))
444 long SvxRuler::PixelVAdjust(long nVal
, long nValOld
) const
446 if(ConvertVSizePixel(nVal
) != ConvertVSizePixel(nValOld
))
452 long SvxRuler::PixelAdjust(long nVal
, long nValOld
) const
454 if(ConvertSizePixel(nVal
) != ConvertSizePixel(nValOld
))
460 inline sal_uInt16
SvxRuler::GetObjectBordersOff(sal_uInt16 nIdx
) const
462 return bHorz
? nIdx
: nIdx
+ 2;
466 Update Upper Left edge.
467 Items are translated into the representation of the ruler.
469 void SvxRuler::UpdateFrame()
471 const sal_uInt16 nMarginStyle
=
472 ( mpRulerImpl
->aProtectItem
.IsSizeProtected() ||
473 mpRulerImpl
->aProtectItem
.IsPosProtected() ) ?
474 0 : RULER_MARGIN_SIZEABLE
;
476 if(mpLRSpaceItem
.get() && mpPagePosItem
.get())
478 // if no initialization by default app behavior
479 const long nOld
= lLogicNullOffset
;
480 lLogicNullOffset
= mpColumnItem
.get() ? mpColumnItem
->GetLeft(): mpLRSpaceItem
->GetLeft();
482 if(bAppSetNullOffset
)
483 lAppNullOffset
+= lLogicNullOffset
- nOld
;
485 if(!bAppSetNullOffset
|| lAppNullOffset
== LONG_MAX
)
487 Ruler::SetNullOffset(ConvertHPosPixel(lLogicNullOffset
));
488 SetMargin1(0, nMarginStyle
);
493 SetMargin1(ConvertHPosPixel(lAppNullOffset
), nMarginStyle
);
498 // evaluate the table right edge of the table
499 if(mpColumnItem
.get() && mpColumnItem
->IsTable())
500 lRight
= mpColumnItem
->GetRight();
502 lRight
= mpLRSpaceItem
->GetRight();
504 long aWidth
= mpPagePosItem
->GetWidth() - lRight
- lLogicNullOffset
+ lAppNullOffset
;
505 long aWidthPixel
= ConvertHPosPixel(aWidth
);
507 SetMargin2(aWidthPixel
, nMarginStyle
);
509 else if(mpULSpaceItem
.get() && mpPagePosItem
.get())
511 // relative the upper edge of the surrounding frame
512 const long nOld
= lLogicNullOffset
;
513 lLogicNullOffset
= mpColumnItem
.get() ? mpColumnItem
->GetLeft() : mpULSpaceItem
->GetUpper();
515 if(bAppSetNullOffset
)
516 lAppNullOffset
+= lLogicNullOffset
- nOld
;
518 if(!bAppSetNullOffset
|| lAppNullOffset
== LONG_MAX
)
520 Ruler::SetNullOffset(ConvertVPosPixel(lLogicNullOffset
));
522 SetMargin1(0, nMarginStyle
);
526 SetMargin1(ConvertVPosPixel(lAppNullOffset
), nMarginStyle
);
529 long lLower
= mpColumnItem
.get() ? mpColumnItem
->GetRight() : mpULSpaceItem
->GetLower();
530 long nMargin2
= mpPagePosItem
->GetHeight() - lLower
- lLogicNullOffset
+ lAppNullOffset
;
531 long nMargin2Pixel
= ConvertVPosPixel(nMargin2
);
533 SetMargin2(nMargin2Pixel
, nMarginStyle
);
537 // turns off the view
542 if(mpColumnItem
.get())
544 mpRulerImpl
->nColLeftPix
= (sal_uInt16
) ConvertSizePixel(mpColumnItem
->GetLeft());
545 mpRulerImpl
->nColRightPix
= (sal_uInt16
) ConvertSizePixel(mpColumnItem
->GetRight());
549 void SvxRuler::MouseMove( const MouseEvent
& rMEvt
)
553 pBindings
->Update( SID_RULER_LR_MIN_MAX
);
554 pBindings
->Update( SID_ATTR_LONG_ULSPACE
);
555 pBindings
->Update( SID_ATTR_LONG_LRSPACE
);
556 pBindings
->Update( SID_RULER_PAGE_POS
);
557 pBindings
->Update( bHorz
? SID_ATTR_TABSTOP
: SID_ATTR_TABSTOP_VERTICAL
);
558 pBindings
->Update( bHorz
? SID_ATTR_PARA_LRSPACE
: SID_ATTR_PARA_LRSPACE_VERTICAL
);
559 pBindings
->Update( bHorz
? SID_RULER_BORDERS
: SID_RULER_BORDERS_VERTICAL
);
560 pBindings
->Update( bHorz
? SID_RULER_ROWS
: SID_RULER_ROWS_VERTICAL
);
561 pBindings
->Update( SID_RULER_OBJECT
);
562 pBindings
->Update( SID_RULER_PROTECT
);
565 Ruler::MouseMove( rMEvt
);
567 RulerSelection aSelection
= GetHoverSelection();
569 if (aSelection
.eType
== RULER_TYPE_DONTKNOW
)
571 SetQuickHelpText("");
575 RulerUnitData aUnitData
= GetCurrentRulerUnit();
576 double aRoundingFactor
= aUnitData
.nTickUnit
/ aUnitData
.nTick1
;
577 sal_Int32 aNoDecimalPlaces
= 1 + std::ceil(std::log10(aRoundingFactor
));
578 OUString sUnit
= OUString::createFromAscii(aUnitData
.aUnitStr
);
580 switch (aSelection
.eType
)
582 case RULER_TYPE_INDENT
:
584 if (!mpParaItem
.get())
587 long nIndex
= aSelection
.nAryPos
+ INDENT_GAP
;
589 long nIndentValue
= 0.0;
590 if (nIndex
== INDENT_LEFT_MARGIN
)
591 nIndentValue
= mpParaItem
->GetTxtLeft();
592 else if (nIndex
== INDENT_FIRST_LINE
)
593 nIndentValue
= mpParaItem
->GetTxtFirstLineOfst();
594 else if (nIndex
== INDENT_RIGHT_MARGIN
)
595 nIndentValue
= mpParaItem
->GetRight();
597 double fValue
= pEditWin
->LogicToLogic(Size(nIndentValue
, 0), pEditWin
->GetMapMode(), GetCurrentMapMode()).Width();
598 fValue
= rtl::math::round(fValue
/ aUnitData
.nTickUnit
, aNoDecimalPlaces
);
600 SetQuickHelpText(OUString::number(fValue
) + " " + sUnit
);
603 case RULER_TYPE_BORDER
:
605 if (mpColumnItem
.get() == NULL
)
608 SvxColumnItem
& aColumnItem
= *mpColumnItem
.get();
610 if (aSelection
.nAryPos
+ 1 >= aColumnItem
.Count())
613 double fStart
= pEditWin
->LogicToLogic(Size(aColumnItem
[aSelection
.nAryPos
].nEnd
, 0), pEditWin
->GetMapMode(), GetCurrentMapMode()).Width();
614 fStart
= rtl::math::round(fStart
/ aUnitData
.nTickUnit
, aNoDecimalPlaces
);
615 double fEnd
= pEditWin
->LogicToLogic(Size(aColumnItem
[aSelection
.nAryPos
+ 1].nStart
, 0), pEditWin
->GetMapMode(), GetCurrentMapMode()).Width();
616 fEnd
= rtl::math::round(fEnd
/ aUnitData
.nTickUnit
, aNoDecimalPlaces
);
619 OUString::number(fStart
) + " " + sUnit
+ " - " +
620 OUString::number(fEnd
) + " " + sUnit
);
623 case RULER_TYPE_MARGIN1
:
626 if (mpLRSpaceItem
.get())
627 nLeft
= mpLRSpaceItem
->GetLeft();
628 else if (mpULSpaceItem
.get())
629 nLeft
= mpULSpaceItem
->GetUpper();
633 double fValue
= pEditWin
->LogicToLogic(Size(nLeft
, 0), pEditWin
->GetMapMode(), GetCurrentMapMode()).Width();
634 fValue
= rtl::math::round(fValue
/ aUnitData
.nTickUnit
, aNoDecimalPlaces
);
635 SetQuickHelpText(OUString::number(fValue
) + " " + sUnit
);
639 case RULER_TYPE_MARGIN2
:
642 if (mpLRSpaceItem
.get())
643 nRight
= mpLRSpaceItem
->GetRight();
644 else if (mpULSpaceItem
.get())
645 nRight
= mpULSpaceItem
->GetLower();
649 double fValue
= pEditWin
->LogicToLogic(Size(nRight
, 0), pEditWin
->GetMapMode(), GetCurrentMapMode()).Width();
650 fValue
= rtl::math::round(fValue
/ aUnitData
.nTickUnit
, aNoDecimalPlaces
);
651 SetQuickHelpText(OUString::number(fValue
) + " " + sUnit
);
657 SetQuickHelpText("");
663 void SvxRuler::StartListening_Impl()
668 StartListening(*pBindings
);
673 void SvxRuler::UpdateFrame(const SvxLongLRSpaceItem
*pItem
) // new value LRSpace
675 /* Store new value LRSpace; delete old ones if possible */
679 mpLRSpaceItem
.reset(new SvxLongLRSpaceItem(*pItem
));
681 mpLRSpaceItem
.reset();
682 StartListening_Impl();
686 void SvxRuler::UpdateFrameMinMax(const SfxRectangleItem
*pItem
) // value for MinMax
688 /* Set new value for MinMax; delete old ones if possible */
692 mpMinMaxItem
.reset(new SfxRectangleItem(*pItem
));
694 mpMinMaxItem
.reset();
699 void SvxRuler::UpdateFrame(const SvxLongULSpaceItem
*pItem
) // new value
701 /* Update Right/bottom margin */
702 if(bActive
&& !bHorz
)
705 mpULSpaceItem
.reset(new SvxLongULSpaceItem(*pItem
));
707 mpULSpaceItem
.reset();
708 StartListening_Impl();
712 void SvxRuler::Update( const SvxProtectItem
* pItem
)
715 mpRulerImpl
->aProtectItem
= *pItem
;
718 void SvxRuler::UpdateTextRTL(const SfxBoolItem
* pItem
)
722 delete mpRulerImpl
->pTextRTLItem
;
723 mpRulerImpl
->pTextRTLItem
= 0;
725 mpRulerImpl
->pTextRTLItem
= new SfxBoolItem(*pItem
);
726 SetTextRTL(mpRulerImpl
->pTextRTLItem
&& mpRulerImpl
->pTextRTLItem
->GetValue());
727 StartListening_Impl();
731 void SvxRuler::Update(
732 const SvxColumnItem
*pItem
, // new value
733 sal_uInt16 nSID
) //Slot Id to identify NULL items
735 /* Set new value for column view */
740 mpColumnItem
.reset(new SvxColumnItem(*pItem
));
741 mpRulerImpl
->bIsTableRows
= (pItem
->Which() == SID_RULER_ROWS
|| pItem
->Which() == SID_RULER_ROWS_VERTICAL
);
742 if(!bHorz
&& !mpRulerImpl
->bIsTableRows
)
743 mpColumnItem
->SetWhich(SID_RULER_BORDERS_VERTICAL
);
745 else if(mpColumnItem
.get() && mpColumnItem
->Which() == nSID
)
746 //there are two groups of column items table/frame columns and table rows
747 //both can occur in vertical or horizontal mode
748 //the horizontal ruler handles the SID_RULER_BORDERS and SID_RULER_ROWS_VERTICAL
749 //and the vertical handles SID_RULER_BORDERS_VERTICAL and SID_RULER_ROWS
750 //if mpColumnItem is already set with one of the ids then a NULL pItem argument
753 mpColumnItem
.reset();
754 mpRulerImpl
->bIsTableRows
= false;
756 StartListening_Impl();
761 void SvxRuler::UpdateColumns()
763 /* Update column view */
764 if(mpColumnItem
.get() && mpColumnItem
->Count() > 1)
766 mpBorders
.resize(mpColumnItem
->Count());
768 sal_uInt16 nStyleFlags
= RULER_BORDER_VARIABLE
;
770 bool bProtectColumns
=
771 mpRulerImpl
->aProtectItem
.IsSizeProtected() ||
772 mpRulerImpl
->aProtectItem
.IsPosProtected();
774 if( !bProtectColumns
)
775 nStyleFlags
|= RULER_BORDER_MOVEABLE
;
777 if( mpColumnItem
->IsTable() )
778 nStyleFlags
|= RULER_BORDER_TABLE
;
779 else if ( !bProtectColumns
)
780 nStyleFlags
|= RULER_BORDER_SIZEABLE
;
782 sal_uInt16 nBorders
= mpColumnItem
->Count();
784 if(!mpRulerImpl
->bIsTableRows
)
787 for(sal_uInt16 i
= 0; i
< nBorders
; ++i
)
789 mpBorders
[i
].nStyle
= nStyleFlags
;
790 if(!mpColumnItem
->At(i
).bVisible
)
791 mpBorders
[i
].nStyle
|= RULER_STYLE_INVISIBLE
;
793 mpBorders
[i
].nPos
= ConvertPosPixel(mpColumnItem
->At(i
).nEnd
+ lAppNullOffset
);
795 if(mpColumnItem
->Count() == i
+ 1)
797 //with table rows the end of the table is contained in the
798 //column item but it has no width!
799 mpBorders
[i
].nWidth
= 0;
803 mpBorders
[i
].nWidth
= ConvertSizePixel(mpColumnItem
->At(i
+ 1).nStart
- mpColumnItem
->At(i
).nEnd
);
805 mpBorders
[i
].nMinPos
= ConvertPosPixel(mpColumnItem
->At(i
).nEndMin
+ lAppNullOffset
);
806 mpBorders
[i
].nMaxPos
= ConvertPosPixel(mpColumnItem
->At(i
).nEndMax
+ lAppNullOffset
);
808 SetBorders(mpColumnItem
->Count() - 1, &mpBorders
[0]);
816 void SvxRuler::UpdateObject()
818 /* Update view of object representation */
819 if(mpObjectItem
.get())
821 DBG_ASSERT(!mpObjectBorders
.empty(), "no Buffer");
822 // !! to the page margin
823 long nMargin
= mpLRSpaceItem
.get() ? mpLRSpaceItem
->GetLeft() : 0;
824 mpObjectBorders
[0].nPos
=
825 ConvertPosPixel(mpObjectItem
->GetStartX() -
826 nMargin
+ lAppNullOffset
);
827 mpObjectBorders
[1].nPos
=
828 ConvertPosPixel(mpObjectItem
->GetEndX() - nMargin
+ lAppNullOffset
);
829 nMargin
= mpULSpaceItem
.get() ? mpULSpaceItem
->GetUpper() : 0;
830 mpObjectBorders
[2].nPos
=
831 ConvertPosPixel(mpObjectItem
->GetStartY() -
832 nMargin
+ lAppNullOffset
);
833 mpObjectBorders
[3].nPos
=
834 ConvertPosPixel(mpObjectItem
->GetEndY() - nMargin
+ lAppNullOffset
);
836 const sal_uInt16 nOffset
= GetObjectBordersOff(0);
837 SetBorders(2, &mpObjectBorders
[0] + nOffset
);
845 void SvxRuler::UpdatePara()
848 /* Update the view for paragraph indents:
849 Left margin, first line indent, right margin paragraph update
850 mpIndents[0] = Buffer for old intent
851 mpIndents[1] = Buffer for old intent
852 mpIndents[INDENT_FIRST_LINE] = first line indent
853 mpIndents[INDENT_LEFT_MARGIN] = left margin
854 mpIndents[INDENT_RIGHT_MARGIN] = right margin
857 // Dependence on PagePosItem
858 if(mpParaItem
.get() && mpPagePosItem
.get() && !mpObjectItem
.get())
860 bool bRTLText
= mpRulerImpl
->pTextRTLItem
&& mpRulerImpl
->pTextRTLItem
->GetValue();
861 // First-line indent is negative to the left paragraph margin
862 long nLeftFrameMargin
= GetLeftFrameMargin();
863 long nRightFrameMargin
= GetRightFrameMargin();
864 SetLeftFrameMargin(ConvertHPosPixel(nLeftFrameMargin
));
865 SetRightFrameMargin(ConvertHPosPixel(nRightFrameMargin
));
873 leftMargin
= nRightFrameMargin
- mpParaItem
->GetTxtLeft() + lAppNullOffset
;
874 leftFirstLine
= leftMargin
- mpParaItem
->GetTxtFirstLineOfst();
875 rightMargin
= nLeftFrameMargin
+ mpParaItem
->GetRight() + lAppNullOffset
;
879 leftMargin
= nLeftFrameMargin
+ mpParaItem
->GetTxtLeft() + lAppNullOffset
;
880 leftFirstLine
= leftMargin
+ mpParaItem
->GetTxtFirstLineOfst();
881 rightMargin
= nRightFrameMargin
- mpParaItem
->GetRight() + lAppNullOffset
;
884 mpIndents
[INDENT_LEFT_MARGIN
].nPos
= ConvertHPosPixel(leftMargin
);
885 mpIndents
[INDENT_FIRST_LINE
].nPos
= ConvertHPosPixel(leftFirstLine
);
886 mpIndents
[INDENT_RIGHT_MARGIN
].nPos
= ConvertHPosPixel(rightMargin
);
888 if( mpParaItem
->IsAutoFirst() )
889 mpIndents
[INDENT_FIRST_LINE
].nStyle
|= RULER_STYLE_INVISIBLE
;
891 mpIndents
[INDENT_FIRST_LINE
].nStyle
&= ~RULER_STYLE_INVISIBLE
;
893 SetIndents(INDENT_COUNT
, &mpIndents
[0] + INDENT_GAP
);
897 if(!mpIndents
.empty())
899 mpIndents
[INDENT_FIRST_LINE
].nPos
= 0;
900 mpIndents
[INDENT_LEFT_MARGIN
].nPos
= 0;
901 mpIndents
[INDENT_RIGHT_MARGIN
].nPos
= 0;
903 SetIndents(); // turn off
907 void SvxRuler::UpdatePara(const SvxLRSpaceItem
*pItem
) // new value of paragraph indents
909 /* Store new value of paragraph indents */
913 mpParaItem
.reset(new SvxLRSpaceItem(*pItem
));
916 StartListening_Impl();
920 void SvxRuler::UpdateParaBorder(const SvxLRSpaceItem
* pItem
)
922 /* Border distance */
926 mpParaBorderItem
.reset(new SvxLRSpaceItem(*pItem
));
928 mpParaBorderItem
.reset();
929 StartListening_Impl();
933 void SvxRuler::UpdatePage()
935 /* Update view of position and width of page */
936 if(mpPagePosItem
.get())
938 // all objects are automatically adjusted
942 pEditWin
->LogicToPixel(mpPagePosItem
->GetPos()).X(),
943 pEditWin
->LogicToPixel(Size(mpPagePosItem
->GetWidth(), 0)).
949 pEditWin
->LogicToPixel(mpPagePosItem
->GetPos()).Y(),
950 pEditWin
->LogicToPixel(Size(0, mpPagePosItem
->GetHeight())).
953 if(bAppSetNullOffset
)
954 SetNullOffset(ConvertSizePixel(-lAppNullOffset
+ lLogicNullOffset
));
962 Point aOwnPos
= GetPosPixel();
963 Point aEdtWinPos
= pEditWin
->GetPosPixel();
964 if( Application::GetSettings().GetLayoutRTL() && bHorz
)
966 //#i73321# in RTL the window and the ruler is not mirrored but the
967 // influence of the vertical ruler is inverted
968 Size aOwnSize
= GetSizePixel();
969 Size aEdtWinSize
= pEditWin
->GetSizePixel();
970 lPos
= aOwnSize
.Width() - aEdtWinSize
.Width();
971 lPos
-= (aEdtWinPos
- aOwnPos
).X();
975 Point
aPos(aEdtWinPos
- aOwnPos
);
976 lPos
= bHorz
? aPos
.X() : aPos
.Y();
979 // Unfortunately, we get the offset of the edit window to the ruler never
980 // through a status message. So we set it ourselves if necessary.
981 if(lPos
!= mpRulerImpl
->lOldWinPos
)
983 mpRulerImpl
->lOldWinPos
=lPos
;
988 void SvxRuler::Update(const SvxPagePosSizeItem
*pItem
) // new value of page attributes
990 /* Store new value of page attributes */
994 mpPagePosItem
.reset(new SvxPagePosSizeItem(*pItem
));
996 mpPagePosItem
.reset();
997 StartListening_Impl();
1001 void SvxRuler::SetDefTabDist(long inDefTabDist
) // New distance for DefaultTabs in App-Metrics
1003 /* New distance is set for DefaultTabs */
1004 lDefTabDist
= inDefTabDist
;
1008 sal_uInt16
ToSvTab_Impl(SvxTabAdjust eAdj
)
1010 /* Internal conversion routine between SV-Tab.-Enum and Svx */
1012 case SVX_TAB_ADJUST_LEFT
: return RULER_TAB_LEFT
;
1013 case SVX_TAB_ADJUST_RIGHT
: return RULER_TAB_RIGHT
;
1014 case SVX_TAB_ADJUST_DECIMAL
: return RULER_TAB_DECIMAL
;
1015 case SVX_TAB_ADJUST_CENTER
: return RULER_TAB_CENTER
;
1016 case SVX_TAB_ADJUST_DEFAULT
: return RULER_TAB_DEFAULT
;
1017 default: ; //prevent warning
1022 SvxTabAdjust
ToAttrTab_Impl(sal_uInt16 eAdj
)
1025 case RULER_TAB_LEFT
: return SVX_TAB_ADJUST_LEFT
;
1026 case RULER_TAB_RIGHT
: return SVX_TAB_ADJUST_RIGHT
;
1027 case RULER_TAB_DECIMAL
: return SVX_TAB_ADJUST_DECIMAL
;
1028 case RULER_TAB_CENTER
: return SVX_TAB_ADJUST_CENTER
;
1029 case RULER_TAB_DEFAULT
: return SVX_TAB_ADJUST_DEFAULT
;
1031 return SVX_TAB_ADJUST_LEFT
;
1034 void SvxRuler::UpdateTabs()
1039 if( mpPagePosItem
.get() &&
1041 mpTabStopItem
.get() &&
1042 !mpObjectItem
.get() )
1044 // buffer for DefaultTabStop
1045 // Distance last Tab <-> Right paragraph margin / DefaultTabDist
1046 bool bRTL
= mpRulerImpl
->pTextRTLItem
&& mpRulerImpl
->pTextRTLItem
->GetValue();
1048 long nLeftFrameMargin
= GetLeftFrameMargin();
1049 long nRightFrameMargin
= GetRightFrameMargin();
1051 //#i24363# tab stops relative to indent
1052 const long nParaItemTxtLeft
= mpParaItem
->GetTxtLeft();
1054 const long lParaIndent
= nLeftFrameMargin
+ nParaItemTxtLeft
;
1056 const long lLastTab
= mpTabStopItem
->Count()
1057 ? ConvertHPosPixel(mpTabStopItem
->At(mpTabStopItem
->Count() - 1).GetTabPos())
1059 const long lPosPixel
= ConvertHPosPixel(lParaIndent
) + lLastTab
;
1060 const long lRightIndent
= ConvertHPosPixel(nRightFrameMargin
- mpParaItem
->GetRight());
1062 long nDefTabDist
= ConvertHPosPixel(lDefTabDist
);
1067 const sal_uInt16 nDefTabBuf
= lPosPixel
> lRightIndent
|| lLastTab
> lRightIndent
1069 : (sal_uInt16
)( (lRightIndent
- lPosPixel
) / nDefTabDist
);
1071 if(mpTabStopItem
->Count() + TAB_GAP
+ nDefTabBuf
> nTabBufSize
)
1073 // 10 (GAP) in stock
1074 nTabBufSize
= mpTabStopItem
->Count() + TAB_GAP
+ nDefTabBuf
+ GAP
;
1075 mpTabs
.resize(nTabBufSize
);
1081 //#i24363# tab stops relative to indent
1082 const long lRightPixMargin
= ConvertSizePixel(nRightFrameMargin
- nParaItemTxtLeft
);
1083 const long lParaIndentPix
= ConvertSizePixel(lParaIndent
);
1085 for(j
= 0; j
< mpTabStopItem
->Count(); ++j
)
1087 const SvxTabStop
* pTab
= &mpTabStopItem
->At(j
);
1088 if (mpRulerImpl
->bIsTabsRelativeToIndent
)
1090 long nTabPosition
= ConvertHPosPixel(lParaIndent
+ pTab
->GetTabPos() + lAppNullOffset
);
1091 mpTabs
[nTabCount
+ TAB_GAP
].nPos
= nTabPosition
;
1095 long nTabPosition
= ConvertHPosPixel(0 + pTab
->GetTabPos() + lAppNullOffset
);
1096 mpTabs
[nTabCount
+ TAB_GAP
].nPos
= nTabPosition
;
1101 mpTabs
[nTabCount
+ TAB_GAP
].nPos
= lParaIndentPix
+ lRightPixMargin
- mpTabs
[nTabCount
+ TAB_GAP
].nPos
;
1103 mpTabs
[nTabCount
+ TAB_GAP
].nStyle
= ToSvTab_Impl(pTab
->GetAdjustment());
1107 if(!mpTabStopItem
->Count())
1108 mpTabs
[0].nPos
= bRTL
? lRightPixMargin
: lParaIndentPix
;
1110 // fill the rest with default Tabs
1113 sal_Int32 aFirst
= mpTabs
[nTabCount
].nPos
;
1114 for(j
= 0; j
< nDefTabBuf
; ++j
)
1116 mpTabs
[nTabCount
+ TAB_GAP
].nPos
=
1117 aFirst
- ConvertHPosPixel(j
* lDefTabDist
);
1121 mpTabs
[nTabCount
+ TAB_GAP
].nPos
-=
1122 ((mpTabs
[nTabCount
+ TAB_GAP
].nPos
- lRightPixMargin
)
1126 if(mpTabs
[nTabCount
+ TAB_GAP
].nPos
<= lParaIndentPix
)
1128 mpTabs
[nTabCount
+ TAB_GAP
].nStyle
= RULER_TAB_DEFAULT
;
1134 sal_Int32 aFirst
= 0;
1135 for(j
= 0; j
< nDefTabBuf
; ++j
)
1139 //set the first default tab stop
1140 if(mpRulerImpl
->bIsTabsRelativeToIndent
)
1142 mpTabs
[nTabCount
+ TAB_GAP
].nPos
= (mpTabs
[nTabCount
].nPos
+ nDefTabDist
);
1144 mpTabs
[nTabCount
+ TAB_GAP
].nPos
-=
1145 (mpTabs
[nTabCount
+ TAB_GAP
].nPos
- lParaIndentPix
) % nDefTabDist
;
1146 aFirst
= mpTabs
[nTabCount
+ TAB_GAP
].nPos
;
1150 if( mpTabs
[nTabCount
].nPos
< 0 )
1151 aFirst
= ( mpTabs
[nTabCount
].nPos
/ nDefTabDist
) * nDefTabDist
;
1153 aFirst
= ( mpTabs
[nTabCount
].nPos
/ nDefTabDist
+ 1 ) * nDefTabDist
;
1154 mpTabs
[nTabCount
+ TAB_GAP
].nPos
= aFirst
;
1159 //simply add the default distance to the last position
1161 mpTabs
[nTabCount
+ TAB_GAP
].nPos
= aFirst
+ ConvertHPosPixel(j
* lDefTabDist
);
1164 if(mpTabs
[nTabCount
+ TAB_GAP
].nPos
>= lRightIndent
)
1166 mpTabs
[nTabCount
+ TAB_GAP
].nStyle
= RULER_TAB_DEFAULT
;
1170 SetTabs(nTabCount
, &mpTabs
[0] + TAB_GAP
);
1171 DBG_ASSERT(nTabCount
+ TAB_GAP
<= nTabBufSize
, "BufferSize too small");
1179 void SvxRuler::Update(const SvxTabStopItem
*pItem
) // new value for tabs
1181 /* Store new value for tabs; delete old ones if possible */
1186 mpTabStopItem
.reset(new SvxTabStopItem(*pItem
));
1188 mpTabStopItem
->SetWhich(SID_ATTR_TABSTOP_VERTICAL
);
1192 mpTabStopItem
.reset();
1194 StartListening_Impl();
1198 void SvxRuler::Update(const SvxObjectItem
*pItem
) // new value for objects
1200 /* Store new value for objects */
1204 mpObjectItem
.reset(new SvxObjectItem(*pItem
));
1206 mpObjectItem
.reset();
1207 StartListening_Impl();
1211 void SvxRuler::SetNullOffsetLogic(long lVal
) // Setting of the logic NullOffsets
1213 lAppNullOffset
= lLogicNullOffset
- lVal
;
1214 bAppSetNullOffset
= true;
1215 Ruler::SetNullOffset(ConvertSizePixel(lVal
));
1219 void SvxRuler::Update()
1221 /* Perform update of view */
1227 if((nFlags
& SVXRULER_SUPPORT_OBJECT
) == SVXRULER_SUPPORT_OBJECT
)
1232 if(0 != (nFlags
& (SVXRULER_SUPPORT_PARAGRAPH_MARGINS
| SVXRULER_SUPPORT_PARAGRAPH_MARGINS_VERTICAL
)))
1235 if(0 != (nFlags
& SVXRULER_SUPPORT_TABS
))
1239 long SvxRuler::GetPageWidth() const
1241 if (!mpPagePosItem
.get())
1243 return bHorz
? mpPagePosItem
->GetWidth() : mpPagePosItem
->GetHeight();
1246 inline long SvxRuler::GetFrameLeft() const
1248 /* Get Left margin in Pixels */
1249 return bAppSetNullOffset
?
1250 GetMargin1() + ConvertSizePixel(lLogicNullOffset
) :
1251 Ruler::GetNullOffset();
1254 inline void SvxRuler::SetFrameLeft(long lFrameLeft
)
1256 /* Set Left margin in Pixels */
1257 bool bProtectColumns
=
1258 mpRulerImpl
->aProtectItem
.IsSizeProtected() ||
1259 mpRulerImpl
->aProtectItem
.IsPosProtected();
1260 if(bAppSetNullOffset
)
1262 SetMargin1(lFrameLeft
- ConvertSizePixel(lLogicNullOffset
),
1263 bProtectColumns
? 0 : RULER_MARGIN_SIZEABLE
);
1267 Ruler::SetNullOffset(lFrameLeft
);
1271 long SvxRuler::GetFirstLineIndent() const
1273 /* Get First-line indent in pixels */
1274 return mpParaItem
.get() ? mpIndents
[INDENT_FIRST_LINE
].nPos
: GetMargin1();
1277 long SvxRuler::GetLeftIndent() const
1279 /* Get Left paragraph margin in Pixels */
1280 return mpParaItem
.get() ? mpIndents
[INDENT_LEFT_MARGIN
].nPos
: GetMargin1();
1283 long SvxRuler::GetRightIndent() const
1285 /* Get Right paragraph margin in Pixels */
1286 return mpParaItem
.get() ? mpIndents
[INDENT_RIGHT_MARGIN
].nPos
: GetMargin2();
1289 long SvxRuler::GetLogicRightIndent() const
1291 /* Get Right paragraph margin in Logic */
1292 return mpParaItem
.get() ? GetRightFrameMargin() - mpParaItem
->GetRight() : GetRightFrameMargin();
1295 // Left margin in App values, is either the margin (= 0) or the left edge of
1296 // the column that is set in the column attribute as current column.
1297 long SvxRuler::GetLeftFrameMargin() const
1299 // #126721# for some unknown reason the current column is set to 0xffff
1300 DBG_ASSERT(!mpColumnItem
.get() || mpColumnItem
->GetActColumn() < mpColumnItem
->Count(),
1301 "issue #126721# - invalid current column!");
1303 if (mpColumnItem
.get() &&
1304 mpColumnItem
->Count() &&
1305 mpColumnItem
->IsConsistent())
1307 nLeft
= mpColumnItem
->GetActiveColumnDescription().nStart
;
1313 inline long SvxRuler::GetLeftMin() const
1315 DBG_ASSERT(mpMinMaxItem
.get(), "no MinMax value set");
1316 if (mpMinMaxItem
.get())
1319 return mpMinMaxItem
->GetValue().Left();
1321 return mpMinMaxItem
->GetValue().Top();
1326 inline long SvxRuler::GetRightMax() const
1328 DBG_ASSERT(mpMinMaxItem
.get(), "no MinMax value set");
1329 if (mpMinMaxItem
.get())
1332 return mpMinMaxItem
->GetValue().Right();
1334 return mpMinMaxItem
->GetValue().Bottom();
1340 long SvxRuler::GetRightFrameMargin() const
1342 /* Get right frame margin (in logical units) */
1343 if (mpColumnItem
.get())
1345 if (!IsActLastColumn(true))
1347 return mpColumnItem
->At(GetActRightColumn(true)).nEnd
;
1351 long lResult
= lLogicNullOffset
;
1353 // If possible deduct right table entry
1354 if(mpColumnItem
.get() && mpColumnItem
->IsTable())
1355 lResult
+= mpColumnItem
->GetRight();
1356 else if(bHorz
&& mpLRSpaceItem
.get())
1357 lResult
+= mpLRSpaceItem
->GetRight();
1358 else if(!bHorz
&& mpULSpaceItem
.get())
1359 lResult
+= mpULSpaceItem
->GetLower();
1362 lResult
= mpPagePosItem
->GetWidth() - lResult
;
1364 lResult
= mpPagePosItem
->GetHeight() - lResult
;
1369 #define NEG_FLAG ( (nFlags & SVXRULER_SUPPORT_NEGATIVE_MARGINS) == \
1370 SVXRULER_SUPPORT_NEGATIVE_MARGINS )
1371 #define TAB_FLAG ( mpColumnItem.get() && mpColumnItem->IsTable() )
1373 long SvxRuler::GetCorrectedDragPos( bool bLeft
, bool bRight
)
1376 Corrects the position within the calculated limits. The limit values are in
1377 pixels relative to the page edge.
1380 const long lNullPix
= Ruler::GetNullOffset();
1381 long lDragPos
= GetDragPos() + lNullPix
;
1382 ADD_DEBUG_TEXT("lDragPos: ", OUString::number(lDragPos
))
1383 bool bHoriRows
= bHorz
&& mpRulerImpl
->bIsTableRows
;
1384 if((bLeft
|| (bHoriRows
)) && lDragPos
< nMaxLeft
)
1385 lDragPos
= nMaxLeft
;
1386 else if((bRight
||bHoriRows
) && lDragPos
> nMaxRight
)
1387 lDragPos
= nMaxRight
;
1388 return lDragPos
- lNullPix
;
1391 void ModifyTabs_Impl( sal_uInt16 nCount
, // Number of Tabs
1392 RulerTab
* pTabs
, // Tab buffer
1393 long lDiff
) // difference to be added
1395 /* Helper function, move all the tabs by a fixed value */
1398 for(sal_uInt16 i
= 0; i
< nCount
; ++i
)
1400 pTabs
[i
].nPos
+= lDiff
;
1405 void SvxRuler::DragMargin1()
1407 /* Dragging the left edge of frame */
1408 long aDragPosition
= GetCorrectedDragPos( !TAB_FLAG
|| !NEG_FLAG
, true );
1410 aDragPosition
= MakePositionSticky(aDragPosition
, GetRightFrameMargin(), false);
1412 // Check if position changed
1413 if (aDragPosition
== 0)
1416 DrawLine_Impl(lTabPos
, ( TAB_FLAG
&& NEG_FLAG
) ? 3 : 7, bHorz
);
1417 if (mpColumnItem
.get() && (nDragType
& DRAG_OBJECT_SIZE_PROPORTIONAL
))
1419 AdjustMargin1(aDragPosition
);
1422 void SvxRuler::AdjustMargin1(long lInputDiff
)
1424 const long nOld
= bAppSetNullOffset
? GetMargin1(): GetNullOffset();
1425 const long lDragPos
= lInputDiff
;
1427 bool bProtectColumns
=
1428 mpRulerImpl
->aProtectItem
.IsSizeProtected() ||
1429 mpRulerImpl
->aProtectItem
.IsPosProtected();
1431 const sal_uInt16 nMarginStyle
=
1432 bProtectColumns
? 0 : RULER_MARGIN_SIZEABLE
;
1434 if(!bAppSetNullOffset
)
1436 long lDiff
= lDragPos
;
1437 SetNullOffset(nOld
+ lDiff
);
1438 if (!mpColumnItem
.get() || !(nDragType
& DRAG_OBJECT_SIZE_LINEAR
))
1440 SetMargin2( GetMargin2() - lDiff
, nMarginStyle
);
1442 if (!mpColumnItem
.get() && !mpObjectItem
.get() && mpParaItem
.get())
1444 // Right indent of the old position
1445 mpIndents
[INDENT_RIGHT_MARGIN
].nPos
-= lDiff
;
1446 SetIndents(INDENT_COUNT
, &mpIndents
[0] + INDENT_GAP
);
1448 if(mpObjectItem
.get())
1450 mpObjectBorders
[GetObjectBordersOff(0)].nPos
-= lDiff
;
1451 mpObjectBorders
[GetObjectBordersOff(1)].nPos
-= lDiff
;
1452 SetBorders(2, &mpObjectBorders
[0] + GetObjectBordersOff(0));
1454 if(mpColumnItem
.get())
1456 for(sal_uInt16 i
= 0; i
< mpColumnItem
->Count()-1; ++i
)
1457 mpBorders
[i
].nPos
-= lDiff
;
1458 SetBorders(mpColumnItem
->Count()-1, &mpBorders
[0]);
1459 if(mpColumnItem
->IsFirstAct())
1461 // Right indent of the old position
1462 if(mpParaItem
.get())
1464 mpIndents
[INDENT_RIGHT_MARGIN
].nPos
-= lDiff
;
1465 SetIndents(INDENT_COUNT
, &mpIndents
[0] + INDENT_GAP
);
1470 if(mpParaItem
.get())
1472 mpIndents
[INDENT_FIRST_LINE
].nPos
-= lDiff
;
1473 mpIndents
[INDENT_LEFT_MARGIN
].nPos
-= lDiff
;
1474 mpIndents
[INDENT_RIGHT_MARGIN
].nPos
-= lDiff
;
1475 SetIndents(INDENT_COUNT
, &mpIndents
[0] + INDENT_GAP
);
1478 if(mpTabStopItem
.get() && (nDragType
& DRAG_OBJECT_SIZE_PROPORTIONAL
)
1479 &&!IsActFirstColumn())
1481 ModifyTabs_Impl(nTabCount
+ TAB_GAP
, &mpTabs
[0], -lDiff
);
1482 SetTabs(nTabCount
, &mpTabs
[0] + TAB_GAP
);
1489 long lDiff
= lDragPos
- nOld
;
1490 SetMargin1(nOld
+ lDiff
, nMarginStyle
);
1492 if (!mpColumnItem
.get() || !(nDragType
& (DRAG_OBJECT_SIZE_LINEAR
| DRAG_OBJECT_SIZE_PROPORTIONAL
)))
1494 if (!mpColumnItem
.get() && !mpObjectItem
.get() && mpParaItem
.get())
1496 // Left indent of the old position
1497 mpIndents
[INDENT_FIRST_LINE
].nPos
+= lDiff
;
1498 mpIndents
[INDENT_LEFT_MARGIN
].nPos
+= lDiff
;
1499 SetIndents(INDENT_COUNT
, &mpIndents
[0] + INDENT_GAP
);
1502 if (mpColumnItem
.get())
1504 for(sal_uInt16 i
= 0; i
< mpColumnItem
->Count() - 1; ++i
)
1505 mpBorders
[i
].nPos
+= lDiff
;
1506 SetBorders(mpColumnItem
->Count() - 1, &mpBorders
[0]);
1507 if (mpColumnItem
->IsFirstAct())
1509 // Left indent of the old position
1510 if(mpParaItem
.get())
1512 mpIndents
[INDENT_FIRST_LINE
].nPos
+= lDiff
;
1513 mpIndents
[INDENT_LEFT_MARGIN
].nPos
+= lDiff
;
1514 SetIndents(INDENT_COUNT
, &mpIndents
[0] + INDENT_GAP
);
1519 if(mpParaItem
.get())
1521 mpIndents
[INDENT_FIRST_LINE
].nPos
+= lDiff
;
1522 mpIndents
[INDENT_LEFT_MARGIN
].nPos
+= lDiff
;
1523 mpIndents
[INDENT_RIGHT_MARGIN
].nPos
+= lDiff
;
1524 SetIndents(INDENT_COUNT
, &mpIndents
[0] + INDENT_GAP
);
1528 if(mpTabStopItem
.get())
1530 ModifyTabs_Impl(nTabCount
+ TAB_GAP
, &mpTabs
[0], lDiff
);
1531 SetTabs(nTabCount
, &mpTabs
[0] + TAB_GAP
);
1537 void SvxRuler::DragMargin2()
1539 /* Dragging the right edge of frame */
1540 long aDragPosition
= GetCorrectedDragPos( true, !TAB_FLAG
|| !NEG_FLAG
);
1541 aDragPosition
= MakePositionSticky(aDragPosition
, GetLeftFrameMargin(), false);
1542 long lDiff
= aDragPosition
- GetMargin2();
1544 // Check if position changed
1548 if( mpRulerImpl
->bIsTableRows
&&
1550 mpColumnItem
.get() &&
1551 (nDragType
& DRAG_OBJECT_SIZE_PROPORTIONAL
))
1556 bool bProtectColumns
=
1557 mpRulerImpl
->aProtectItem
.IsSizeProtected() ||
1558 mpRulerImpl
->aProtectItem
.IsPosProtected();
1560 const sal_uInt16 nMarginStyle
= bProtectColumns
? 0 : RULER_MARGIN_SIZEABLE
;
1562 SetMargin2( aDragPosition
, nMarginStyle
);
1564 // Right indent of the old position
1565 if((!mpColumnItem
.get() || IsActLastColumn()) && mpParaItem
.get())
1567 mpIndents
[INDENT_FIRST_LINE
].nPos
+= lDiff
;
1568 SetIndents(INDENT_COUNT
, &mpIndents
[0] + INDENT_GAP
);
1571 DrawLine_Impl(lTabPos
, ( TAB_FLAG
&& NEG_FLAG
) ? 5 : 7, bHorz
);
1574 void SvxRuler::DragIndents()
1576 /* Dragging the paragraph indents */
1577 long aDragPosition
= NEG_FLAG
? GetDragPos() : GetCorrectedDragPos();
1578 const sal_uInt16 nIndex
= GetDragAryPos() + INDENT_GAP
;
1580 bool bRTL
= mpRulerImpl
->pTextRTLItem
&& mpRulerImpl
->pTextRTLItem
->GetValue();
1582 if(nIndex
== INDENT_RIGHT_MARGIN
)
1583 aDragPosition
= MakePositionSticky(aDragPosition
, bRTL
? GetLeftFrameMargin() : GetRightFrameMargin());
1585 aDragPosition
= MakePositionSticky(aDragPosition
, bRTL
? GetRightFrameMargin() : GetLeftFrameMargin());
1587 const long lDiff
= mpIndents
[nIndex
].nPos
- aDragPosition
;
1589 // Check if position changed
1593 if((nIndex
== INDENT_FIRST_LINE
|| nIndex
== INDENT_LEFT_MARGIN
) &&
1594 (nDragType
& DRAG_OBJECT_LEFT_INDENT_ONLY
) != DRAG_OBJECT_LEFT_INDENT_ONLY
)
1596 mpIndents
[INDENT_FIRST_LINE
].nPos
-= lDiff
;
1599 mpIndents
[nIndex
].nPos
= aDragPosition
;
1601 SetIndents(INDENT_COUNT
, &mpIndents
[0] + INDENT_GAP
);
1602 DrawLine_Impl(lTabPos
, 1, bHorz
);
1605 void SvxRuler::DrawLine_Impl(long& lTabPosition
, int nNew
, bool bHorizontal
)
1608 Output routine for the ledger line when moving tabs, tables and other
1613 const long nHeight
= pEditWin
->GetOutputSize().Height();
1614 Point aZero
= pEditWin
->GetMapMode().GetOrigin();
1615 if(lTabPosition
!= -1)
1617 pEditWin
->InvertTracking(
1618 Rectangle( Point(lTabPosition
, -aZero
.Y()),
1619 Point(lTabPosition
, -aZero
.Y() + nHeight
)),
1620 SHOWTRACK_SPLIT
| SHOWTRACK_CLIP
);
1624 long nDrapPosition
= GetCorrectedDragPos( ( nNew
& 4 ) != 0, ( nNew
& 2 ) != 0 );
1625 nDrapPosition
= MakePositionSticky(nDrapPosition
, GetLeftFrameMargin());
1626 lTabPosition
= ConvertHSizeLogic( nDrapPosition
+ GetNullOffset() );
1627 if(mpPagePosItem
.get())
1628 lTabPosition
+= mpPagePosItem
->GetPos().X();
1629 pEditWin
->InvertTracking(
1630 Rectangle( Point(lTabPosition
, -aZero
.Y()),
1631 Point(lTabPosition
, -aZero
.Y() + nHeight
) ),
1632 SHOWTRACK_CLIP
| SHOWTRACK_SPLIT
);
1637 const long nWidth
= pEditWin
->GetOutputSize().Width();
1638 Point aZero
= pEditWin
->GetMapMode().GetOrigin();
1639 if(lTabPosition
!= -1)
1641 pEditWin
->InvertTracking(
1642 Rectangle( Point(-aZero
.X(), lTabPosition
),
1643 Point(-aZero
.X() + nWidth
, lTabPosition
)),
1644 SHOWTRACK_SPLIT
| SHOWTRACK_CLIP
);
1649 long nDrapPosition
= GetCorrectedDragPos();
1650 nDrapPosition
= MakePositionSticky(nDrapPosition
, GetLeftFrameMargin());
1651 lTabPosition
= ConvertVSizeLogic(nDrapPosition
+ GetNullOffset());
1652 if(mpPagePosItem
.get())
1653 lTabPosition
+= mpPagePosItem
->GetPos().Y();
1654 pEditWin
->InvertTracking(
1655 Rectangle( Point(-aZero
.X(), lTabPosition
),
1656 Point(-aZero
.X()+nWidth
, lTabPosition
)),
1657 SHOWTRACK_CLIP
| SHOWTRACK_SPLIT
);
1662 void SvxRuler::DragTabs()
1664 /* Dragging of Tabs */
1665 long aDragPosition
= GetCorrectedDragPos(true, false);
1666 aDragPosition
= MakePositionSticky(aDragPosition
, GetLeftFrameMargin());
1668 sal_uInt16 nIdx
= GetDragAryPos() + TAB_GAP
;
1669 long nDiff
= aDragPosition
- mpTabs
[nIdx
].nPos
;
1673 DrawLine_Impl(lTabPos
, 7, bHorz
);
1675 if(nDragType
& DRAG_OBJECT_SIZE_LINEAR
)
1678 for(sal_uInt16 i
= nIdx
; i
< nTabCount
; ++i
)
1680 mpTabs
[i
].nPos
+= nDiff
;
1682 if(mpTabs
[i
].nPos
> GetMargin2())
1683 mpTabs
[nIdx
].nStyle
|= RULER_STYLE_INVISIBLE
;
1685 mpTabs
[nIdx
].nStyle
&= ~RULER_STYLE_INVISIBLE
;
1688 else if(nDragType
& DRAG_OBJECT_SIZE_PROPORTIONAL
)
1690 mpRulerImpl
->nTotalDist
-= nDiff
;
1691 mpTabs
[nIdx
].nPos
= aDragPosition
;
1692 for(sal_uInt16 i
= nIdx
+1; i
< nTabCount
; ++i
)
1694 if(mpTabs
[i
].nStyle
& RULER_TAB_DEFAULT
)
1695 // can be canceled at the DefaultTabs
1697 long nDelta
= mpRulerImpl
->nTotalDist
* mpRulerImpl
->pPercBuf
[i
];
1699 mpTabs
[i
].nPos
= mpTabs
[nIdx
].nPos
+ nDelta
;
1700 if(mpTabs
[i
].nPos
+ GetNullOffset() > nMaxRight
)
1701 mpTabs
[i
].nStyle
|= RULER_STYLE_INVISIBLE
;
1703 mpTabs
[i
].nStyle
&= ~RULER_STYLE_INVISIBLE
;
1708 mpTabs
[nIdx
].nPos
= aDragPosition
;
1712 mpTabs
[nIdx
].nStyle
|= RULER_STYLE_INVISIBLE
;
1714 mpTabs
[nIdx
].nStyle
&= ~RULER_STYLE_INVISIBLE
;
1715 SetTabs(nTabCount
, &mpTabs
[0] + TAB_GAP
);
1718 void SvxRuler::SetActive(bool bOn
)
1728 pBindings
->EnterRegistrations();
1730 for(sal_uInt16 i
=0;i
<mpRulerImpl
->nControlerItems
;i
++)
1731 pCtrlItem
[i
]->ReBind();
1733 for(sal_uInt16 j
=0;j
<mpRulerImpl
->nControlerItems
;j
++)
1734 pCtrlItem
[j
]->UnBind();
1735 pBindings
->LeaveRegistrations();
1740 void SvxRuler::UpdateParaContents_Impl(
1742 UpdateType eType
) // Art (all, left or right)
1744 /* Helper function; carry Tabs and Paragraph Margins */
1748 mpIndents
[INDENT_RIGHT_MARGIN
].nPos
+= lDifference
;
1751 mpIndents
[INDENT_RIGHT_MARGIN
].nPos
+= lDifference
;
1755 mpIndents
[INDENT_FIRST_LINE
].nPos
+= lDifference
;
1756 mpIndents
[INDENT_LEFT_MARGIN
].nPos
+= lDifference
;
1757 if (!mpTabs
.empty())
1759 for(sal_uInt16 i
= 0; i
< nTabCount
+TAB_GAP
; ++i
)
1761 mpTabs
[i
].nPos
+= lDifference
;
1763 SetTabs(nTabCount
, &mpTabs
[0] + TAB_GAP
);
1768 SetIndents(INDENT_COUNT
, &mpIndents
[0] + INDENT_GAP
);
1771 void SvxRuler::DragBorders()
1773 /* Dragging of Borders (Tables and other columns) */
1774 bool bLeftIndentsCorrected
= false;
1775 bool bRightIndentsCorrected
= false;
1778 if(GetDragType() == RULER_TYPE_BORDER
)
1780 DrawLine_Impl(lTabPos
, 7, bHorz
);
1781 nIndex
= GetDragAryPos();
1788 sal_uInt16 nDragSize
= GetDragSize();
1791 // the drag position has to be corrected to be able to prevent borders from passing each other
1792 long lPos
= MakePositionSticky(GetCorrectedDragPos(), GetLeftFrameMargin());
1796 case RULER_DRAGSIZE_MOVE
:
1798 ADD_DEBUG_TEXT("lLastLMargin: ", OUString::number(mpRulerImpl
->lLastLMargin
))
1799 if(GetDragType() == RULER_TYPE_BORDER
)
1800 lDiff
= lPos
- nDragOffset
- mpBorders
[nIndex
].nPos
;
1802 lDiff
= GetDragType() == RULER_TYPE_MARGIN1
? lPos
- mpRulerImpl
->lLastLMargin
: lPos
- mpRulerImpl
->lLastRMargin
;
1804 if(nDragType
& DRAG_OBJECT_SIZE_LINEAR
)
1806 long nRight
= GetMargin2() - lMinFrame
; // Right limiters
1807 for(int i
= mpBorders
.size() - 2; i
>= nIndex
; --i
)
1809 long l
= mpBorders
[i
].nPos
;
1810 mpBorders
[i
].nPos
+= lDiff
;
1811 mpBorders
[i
].nPos
= std::min(mpBorders
[i
].nPos
, nRight
- mpBorders
[i
].nWidth
);
1812 nRight
= mpBorders
[i
].nPos
- lMinFrame
;
1813 // RR update the column
1814 if(i
== GetActRightColumn())
1816 UpdateParaContents_Impl(mpBorders
[i
].nPos
- l
, MOVE_RIGHT
);
1817 bRightIndentsCorrected
= true;
1819 // LAR, EZE update the column
1820 else if(i
== GetActLeftColumn())
1822 UpdateParaContents_Impl(mpBorders
[i
].nPos
- l
, MOVE_LEFT
);
1823 bLeftIndentsCorrected
= true;
1827 else if(nDragType
& DRAG_OBJECT_SIZE_PROPORTIONAL
)
1831 int nStartLimit
= mpBorders
.size() - 2;
1832 switch(GetDragType())
1834 default: ;//prevent warning
1835 OSL_FAIL("svx::SvxRuler::DragBorders(), unknown drag type!" );
1836 case RULER_TYPE_BORDER
:
1837 if(mpRulerImpl
->bIsTableRows
)
1839 mpBorders
[nIndex
].nPos
+= lDiff
;
1842 lLeft
= mpBorders
[nIndex
].nPos
;
1843 mpRulerImpl
->nTotalDist
-= lDiff
;
1844 nLimit
= nIndex
+ 1;
1849 nStartLimit
= nIndex
- 1;
1850 mpRulerImpl
->nTotalDist
+= lDiff
;
1856 nLimit
= nIndex
+ 1;
1857 mpBorders
[nIndex
].nPos
+= lDiff
;
1858 lLeft
= mpBorders
[nIndex
].nPos
;
1859 mpRulerImpl
->nTotalDist
-= lDiff
;
1862 case RULER_TYPE_MARGIN1
:
1864 lLeft
= mpRulerImpl
->lLastLMargin
+ lDiff
;
1865 mpRulerImpl
->nTotalDist
-= lDiff
;
1867 case RULER_TYPE_MARGIN2
:
1870 nStartLimit
= mpBorders
.size() - 2;
1871 mpRulerImpl
->nTotalDist
+= lDiff
;
1875 for(int i
= nStartLimit
; i
>= nLimit
; --i
)
1878 long l
= mpBorders
[i
].nPos
;
1881 (mpRulerImpl
->nTotalDist
* mpRulerImpl
->pPercBuf
[i
]) / 1000 +
1882 mpRulerImpl
->pBlockBuf
[i
];
1884 // RR update the column
1885 if(!mpRulerImpl
->bIsTableRows
)
1887 if(i
== GetActRightColumn())
1889 UpdateParaContents_Impl(mpBorders
[i
].nPos
- l
, MOVE_RIGHT
);
1890 bRightIndentsCorrected
= true;
1892 // LAR, EZE update the column
1893 else if(i
== GetActLeftColumn())
1895 UpdateParaContents_Impl(mpBorders
[i
].nPos
- l
, MOVE_LEFT
);
1896 bLeftIndentsCorrected
= true;
1900 if(mpRulerImpl
->bIsTableRows
)
1902 //in vertical tables the left borders have to be moved
1905 for(int i
= 0; i
< nIndex
; ++i
)
1906 mpBorders
[i
].nPos
+= lDiff
;
1907 AdjustMargin1(lDiff
);
1911 //otherwise the right borders are moved
1912 for(int i
= mpColumnItem
->Count() - 1; i
> nIndex
; --i
)
1913 mpBorders
[i
].nPos
+= lDiff
;
1914 SetMargin2( GetMargin2() + lDiff
, 0 );
1918 else if(mpRulerImpl
->bIsTableRows
)
1920 //moving rows: if a row is resized all following rows
1921 //have to be moved by the same amount.
1922 //This includes the left border when the table is not limited
1923 //to a lower frame border.
1925 if(GetDragType()==RULER_TYPE_BORDER
)
1927 nLimit
= nIndex
+ 1;
1928 mpBorders
[nIndex
].nPos
+= lDiff
;
1934 //in vertical tables the left borders have to be moved
1937 for(int i
= 0; i
< nIndex
; ++i
)
1939 mpBorders
[i
].nPos
+= lDiff
;
1941 AdjustMargin1(lDiff
);
1945 //otherwise the right borders are moved
1946 for(int i
= mpBorders
.size() - 2; i
>= nLimit
; --i
)
1948 mpBorders
[i
].nPos
+= lDiff
;
1950 SetMargin2( GetMargin2() + lDiff
, 0 );
1954 mpBorders
[nIndex
].nPos
+= lDiff
;
1957 case RULER_DRAGSIZE_1
:
1959 lDiff
= lPos
- mpBorders
[nIndex
].nPos
;
1960 mpBorders
[nIndex
].nWidth
+= mpBorders
[nIndex
].nPos
- lPos
;
1961 mpBorders
[nIndex
].nPos
= lPos
;
1964 case RULER_DRAGSIZE_2
:
1966 const long nOld
= mpBorders
[nIndex
].nWidth
;
1967 mpBorders
[nIndex
].nWidth
= lPos
- mpBorders
[nIndex
].nPos
;
1968 lDiff
= mpBorders
[nIndex
].nWidth
- nOld
;
1972 if(!bRightIndentsCorrected
&&
1973 GetActRightColumn() == nIndex
&&
1974 nDragSize
!= RULER_DRAGSIZE_2
&&
1975 !mpIndents
.empty() &&
1976 !mpRulerImpl
->bIsTableRows
)
1978 UpdateParaContents_Impl(lDiff
, MOVE_RIGHT
);
1980 else if(!bLeftIndentsCorrected
&&
1981 GetActLeftColumn() == nIndex
&&
1982 nDragSize
!= RULER_DRAGSIZE_1
&&
1985 UpdateParaContents_Impl(lDiff
, MOVE_LEFT
);
1987 SetBorders(mpColumnItem
->Count() - 1, &mpBorders
[0]);
1990 void SvxRuler::DragObjectBorder()
1992 /* Dragging of object edges */
1993 if(RULER_DRAGSIZE_MOVE
== GetDragSize())
1995 const long lPosition
= MakePositionSticky(GetCorrectedDragPos(), GetLeftFrameMargin());
1997 const sal_uInt16 nIdx
= GetDragAryPos();
1998 mpObjectBorders
[GetObjectBordersOff(nIdx
)].nPos
= lPosition
;
1999 SetBorders(2, &mpObjectBorders
[0] + GetObjectBordersOff(0));
2000 DrawLine_Impl(lTabPos
, 7, bHorz
);
2005 void SvxRuler::ApplyMargins()
2007 /* Applying margins; changed by dragging. */
2008 const SfxPoolItem
* pItem
= NULL
;
2009 sal_uInt16 nId
= SID_ATTR_LONG_LRSPACE
;
2013 const long lOldNull
= lLogicNullOffset
;
2014 if(mpRulerImpl
->lMaxLeftLogic
!= -1 && nMaxLeft
== GetMargin1() + Ruler::GetNullOffset())
2016 lLogicNullOffset
= mpRulerImpl
->lMaxLeftLogic
;
2017 mpLRSpaceItem
->SetLeft(lLogicNullOffset
);
2021 lLogicNullOffset
= ConvertHPosLogic(GetFrameLeft()) - lAppNullOffset
;
2022 mpLRSpaceItem
->SetLeft(PixelHAdjust(lLogicNullOffset
, mpLRSpaceItem
->GetLeft()));
2025 if(bAppSetNullOffset
)
2026 lAppNullOffset
+= lLogicNullOffset
- lOldNull
;
2029 if(mpRulerImpl
->lMaxRightLogic
!= -1
2030 && nMaxRight
== GetMargin2() + Ruler::GetNullOffset())
2032 nRight
= GetPageWidth() - mpRulerImpl
->lMaxRightLogic
;
2036 nRight
= std::max((long)0,
2037 mpPagePosItem
->GetWidth() - mpLRSpaceItem
->GetLeft() -
2038 (ConvertHPosLogic(GetMargin2()) - lAppNullOffset
));
2040 nRight
= PixelHAdjust( nRight
, mpLRSpaceItem
->GetRight());
2042 mpLRSpaceItem
->SetRight(nRight
);
2044 pItem
= mpLRSpaceItem
.get();
2047 Debug_Impl(pEditWin
, *mpLRSpaceItem
);
2053 const long lOldNull
= lLogicNullOffset
;
2054 mpULSpaceItem
->SetUpper(
2057 ConvertVPosLogic(GetFrameLeft()) -
2058 lAppNullOffset
, mpULSpaceItem
->GetUpper()));
2059 if(bAppSetNullOffset
)
2060 lAppNullOffset
+= lLogicNullOffset
- lOldNull
;
2061 mpULSpaceItem
->SetLower(
2063 std::max((long)0, mpPagePosItem
->GetHeight() -
2064 mpULSpaceItem
->GetUpper() -
2065 (ConvertVPosLogic(GetMargin2()) -
2066 lAppNullOffset
)), mpULSpaceItem
->GetLower()));
2067 pItem
= mpULSpaceItem
.get();
2068 nId
= SID_ATTR_LONG_ULSPACE
;
2071 Debug_Impl(pEditWin
,*mpULSpaceItem
.get());
2075 pBindings
->GetDispatcher()->Execute( nId
, SFX_CALLMODE_RECORD
, pItem
, 0L );
2076 if(mpTabStopItem
.get())
2080 long SvxRuler::RoundToCurrentMapMode(long lValue
) const
2082 RulerUnitData aUnitData
= GetCurrentRulerUnit();
2083 double aRoundingFactor
= aUnitData
.nTickUnit
/ aUnitData
.nTick1
;
2085 long lNewValue
= pEditWin
->LogicToLogic(Size(lValue
, 0), pEditWin
->GetMapMode(), GetCurrentMapMode()).Width();
2086 lNewValue
= (rtl::math::round(lNewValue
/ (double) aUnitData
.nTickUnit
* aRoundingFactor
) / aRoundingFactor
) * aUnitData
.nTickUnit
;
2087 return pEditWin
->LogicToLogic(Size(lNewValue
, 0), GetCurrentMapMode(), pEditWin
->GetMapMode()).Width();
2090 void SvxRuler::ApplyIndents()
2092 /* Applying paragraph settings; changed by dragging. */
2094 long nLeftFrameMargin
= GetLeftFrameMargin();
2096 bool bRTL
= mpRulerImpl
->pTextRTLItem
&& mpRulerImpl
->pTextRTLItem
->GetValue();
2099 long nNewFirstLineOffset
;
2102 long nFirstLine
= ConvertPosLogic(mpIndents
[INDENT_FIRST_LINE
].nPos
);
2103 long nLeftMargin
= ConvertPosLogic(mpIndents
[INDENT_LEFT_MARGIN
].nPos
);
2104 long nRightMargin
= ConvertPosLogic(mpIndents
[INDENT_RIGHT_MARGIN
].nPos
);
2106 if(mpColumnItem
.get() && ((bRTL
&& !IsActLastColumn(true)) || (!bRTL
&& !IsActFirstColumn(true))))
2110 long nRightColumn
= GetActRightColumn(true);
2111 long nRightBorder
= ConvertPosLogic(mpBorders
[nRightColumn
].nPos
);
2112 nNewTxtLeft
= nRightBorder
- nLeftMargin
- lAppNullOffset
;
2116 long nLeftColumn
= GetActLeftColumn(true);
2117 long nLeftBorder
= ConvertPosLogic(mpBorders
[nLeftColumn
].nPos
+ mpBorders
[nLeftColumn
].nWidth
);
2118 nNewTxtLeft
= nLeftMargin
- nLeftBorder
- lAppNullOffset
;
2125 long nRightBorder
= ConvertPosLogic(GetMargin2());
2126 nNewTxtLeft
= nRightBorder
- nLeftMargin
- lAppNullOffset
;
2130 long nLeftBorder
= ConvertPosLogic(GetMargin1());
2131 nNewTxtLeft
= nLeftBorder
+ nLeftMargin
- nLeftFrameMargin
- lAppNullOffset
;
2136 nNewFirstLineOffset
= nLeftMargin
- nFirstLine
- lAppNullOffset
;
2138 nNewFirstLineOffset
= nFirstLine
- nLeftMargin
- lAppNullOffset
;
2140 if(mpColumnItem
.get() && ((!bRTL
&& !IsActLastColumn(true)) || (bRTL
&& !IsActFirstColumn(true))))
2144 long nLeftColumn
= GetActLeftColumn(true);
2145 long nLeftBorder
= ConvertPosLogic(mpBorders
[nLeftColumn
].nPos
+ mpBorders
[nLeftColumn
].nWidth
);
2146 nNewRight
= nRightMargin
- nLeftBorder
- lAppNullOffset
;
2150 long nRightColumn
= GetActRightColumn(true);
2151 long nRightBorder
= ConvertPosLogic(mpBorders
[nRightColumn
].nPos
);
2152 nNewRight
= nRightBorder
- nRightMargin
- lAppNullOffset
;
2159 long nLeftBorder
= ConvertPosLogic(GetMargin1());
2160 nNewRight
= nLeftBorder
+ nRightMargin
- nLeftFrameMargin
- lAppNullOffset
;
2164 long nRightBorder
= ConvertPosLogic(GetMargin2());
2165 nNewRight
= nRightBorder
- nRightMargin
- lAppNullOffset
;
2171 nNewTxtLeft
= RoundToCurrentMapMode(nNewTxtLeft
);
2172 nNewFirstLineOffset
= RoundToCurrentMapMode(nNewFirstLineOffset
);
2173 nNewRight
= RoundToCurrentMapMode(nNewRight
);
2176 mpParaItem
->SetTxtFirstLineOfst(sal::static_int_cast
<short>(nNewFirstLineOffset
));
2177 mpParaItem
->SetTxtLeft(nNewTxtLeft
);
2178 mpParaItem
->SetRight(nNewRight
);
2180 sal_uInt16 nParagraphId
= bHorz
? SID_ATTR_PARA_LRSPACE
: SID_ATTR_PARA_LRSPACE_VERTICAL
;
2181 pBindings
->GetDispatcher()->Execute( nParagraphId
, SFX_CALLMODE_RECORD
, mpParaItem
.get(), 0L );
2185 void SvxRuler::ApplyTabs()
2187 /* Apply tab settings, changed by dragging. */
2188 bool bRTL
= mpRulerImpl
->pTextRTLItem
&& mpRulerImpl
->pTextRTLItem
->GetValue();
2189 const sal_uInt16 nCoreIdx
= GetDragAryPos();
2192 mpTabStopItem
->Remove(nCoreIdx
);
2194 else if(DRAG_OBJECT_SIZE_LINEAR
& nDragType
||
2195 DRAG_OBJECT_SIZE_PROPORTIONAL
& nDragType
)
2197 SvxTabStopItem
*pItem
= new SvxTabStopItem(mpTabStopItem
->Which());
2198 //remove default tab stops
2199 for ( sal_uInt16 i
= 0; i
< pItem
->Count(); )
2201 if ( SVX_TAB_ADJUST_DEFAULT
== (*pItem
)[i
].GetAdjustment() )
2210 for(j
= 0; j
< nCoreIdx
; ++j
)
2212 pItem
->Insert(mpTabStopItem
->At(j
));
2214 for(; j
< mpTabStopItem
->Count(); ++j
)
2216 SvxTabStop aTabStop
= mpTabStopItem
->At(j
);
2217 aTabStop
.GetTabPos() = PixelHAdjust(
2219 mpTabs
[j
+ TAB_GAP
].nPos
- GetLeftIndent()) - lAppNullOffset
,
2220 aTabStop
.GetTabPos());
2221 pItem
->Insert(aTabStop
);
2223 mpTabStopItem
.reset(pItem
);
2225 else if( mpTabStopItem
->Count() == 0 )
2229 SvxTabStop aTabStop
= mpTabStopItem
->At(nCoreIdx
);
2230 if( mpRulerImpl
->lMaxRightLogic
!= -1 &&
2231 mpTabs
[nCoreIdx
+ TAB_GAP
].nPos
+ Ruler::GetNullOffset() == nMaxRight
)
2233 aTabStop
.GetTabPos() = mpRulerImpl
->lMaxRightLogic
- lLogicNullOffset
;
2239 //#i24363# tab stops relative to indent
2240 const long nTmpLeftIndent
= mpRulerImpl
->bIsTabsRelativeToIndent
?
2242 ConvertHPosPixel( GetRightFrameMargin() + lAppNullOffset
);
2244 long nNewPosition
= ConvertHPosLogic(nTmpLeftIndent
- mpTabs
[nCoreIdx
+ TAB_GAP
].nPos
);
2245 aTabStop
.GetTabPos() = PixelHAdjust(nNewPosition
- lAppNullOffset
, aTabStop
.GetTabPos());
2249 //#i24363# tab stops relative to indent
2250 const long nTmpLeftIndent
= mpRulerImpl
->bIsTabsRelativeToIndent
?
2251 GetLeftIndent() : 0;
2253 long nNewPosition
= ConvertHPosLogic(mpTabs
[nCoreIdx
+ TAB_GAP
].nPos
- nTmpLeftIndent
);
2254 aTabStop
.GetTabPos() = PixelHAdjust(nNewPosition
- lAppNullOffset
, aTabStop
.GetTabPos());
2257 mpTabStopItem
->Remove(nCoreIdx
);
2258 mpTabStopItem
->Insert(aTabStop
);
2260 sal_uInt16 nTabStopId
= bHorz
? SID_ATTR_TABSTOP
: SID_ATTR_TABSTOP_VERTICAL
;
2261 pBindings
->GetDispatcher()->Execute( nTabStopId
, SFX_CALLMODE_RECORD
, mpTabStopItem
.get(), 0L );
2265 void SvxRuler::ApplyBorders()
2267 /* Applying (table) column settings; changed by dragging. */
2268 if(mpColumnItem
->IsTable())
2270 long lValue
= GetFrameLeft();
2271 if(lValue
!= mpRulerImpl
->nColLeftPix
)
2273 long nLeft
= PixelHAdjust(
2274 ConvertHPosLogic(lValue
) -
2276 mpColumnItem
->GetLeft());
2277 mpColumnItem
->SetLeft(nLeft
);
2280 lValue
= GetMargin2();
2282 if(lValue
!= mpRulerImpl
->nColRightPix
)
2284 long nWidthOrHeight
= bHorz
? mpPagePosItem
->GetWidth() : mpPagePosItem
->GetHeight();
2285 long nRight
= PixelHAdjust(
2287 mpColumnItem
->GetLeft() -
2288 ConvertHPosLogic(lValue
) -
2290 mpColumnItem
->GetRight() );
2291 mpColumnItem
->SetRight(nRight
);
2295 for(sal_uInt16 i
= 0; i
< mpColumnItem
->Count() - 1; ++i
)
2297 long& nEnd
= mpColumnItem
->At(i
).nEnd
;
2298 nEnd
= PixelHAdjust(
2299 ConvertPosLogic(mpBorders
[i
].nPos
),
2300 mpColumnItem
->At(i
).nEnd
);
2301 long& nStart
= mpColumnItem
->At(i
+ 1).nStart
;
2302 nStart
= PixelHAdjust(
2303 ConvertSizeLogic(mpBorders
[i
].nPos
+
2304 mpBorders
[i
].nWidth
) -
2306 mpColumnItem
->At(i
+ 1).nStart
);
2307 // It may be that, due to the PixelHAdjust readjustment to old values,
2308 // the width becomes < 0. This we readjust.
2314 Debug_Impl(pEditWin
,*mpColumnItem
.get());
2317 SfxBoolItem
aFlag(SID_RULER_ACT_LINE_ONLY
,
2318 nDragType
& DRAG_OBJECT_ACTLINE_ONLY
? sal_True
: sal_False
);
2320 sal_uInt16 nColId
= mpRulerImpl
->bIsTableRows
? (bHorz
? SID_RULER_ROWS
: SID_RULER_ROWS_VERTICAL
) :
2321 (bHorz
? SID_RULER_BORDERS
: SID_RULER_BORDERS_VERTICAL
);
2323 pBindings
->GetDispatcher()->Execute( nColId
, SFX_CALLMODE_RECORD
, mpColumnItem
.get(), &aFlag
, 0L );
2326 void SvxRuler::ApplyObject()
2328 /* Applying object settings, changed by dragging. */
2330 // to the page margin
2331 long nMargin
= mpLRSpaceItem
.get() ? mpLRSpaceItem
->GetLeft() : 0;
2332 long nStartX
= PixelAdjust(
2333 ConvertPosLogic(mpObjectBorders
[0].nPos
) +
2336 mpObjectItem
->GetStartX());
2337 mpObjectItem
->SetStartX(nStartX
);
2339 long nEndX
= PixelAdjust(
2340 ConvertPosLogic(mpObjectBorders
[1].nPos
) +
2343 mpObjectItem
->GetEndX());
2344 mpObjectItem
->SetEndX(nEndX
);
2346 nMargin
= mpULSpaceItem
.get() ? mpULSpaceItem
->GetUpper() : 0;
2347 long nStartY
= PixelAdjust(
2348 ConvertPosLogic(mpObjectBorders
[2].nPos
) +
2351 mpObjectItem
->GetStartY());
2352 mpObjectItem
->SetStartY(nStartY
);
2354 long nEndY
= PixelAdjust(
2355 ConvertPosLogic(mpObjectBorders
[3].nPos
) +
2358 mpObjectItem
->GetEndY());
2359 mpObjectItem
->SetEndY(nEndY
);
2361 pBindings
->GetDispatcher()->Execute(SID_RULER_OBJECT
, SFX_CALLMODE_RECORD
, mpObjectItem
.get(), 0L);
2364 void SvxRuler::PrepareProportional_Impl(RulerType eType
)
2367 Preparation proportional dragging, and it is calculated based on the
2368 proportional share of the total width in parts per thousand.
2370 mpRulerImpl
->nTotalDist
= GetMargin2();
2373 case RULER_TYPE_MARGIN2
:
2374 case RULER_TYPE_MARGIN1
:
2375 case RULER_TYPE_BORDER
:
2377 DBG_ASSERT(mpColumnItem
.get(), "no ColumnItem");
2379 mpRulerImpl
->SetPercSize(mpColumnItem
->Count());
2384 sal_uInt16 nIdx
=GetDragAryPos();
2389 if(eType
!= RULER_TYPE_BORDER
)
2391 lOrigLPos
= GetMargin1();
2397 if(mpRulerImpl
->bIsTableRows
&&!bHorz
)
2399 lOrigLPos
= GetMargin1();
2404 lOrigLPos
= mpBorders
[nIdx
].nPos
+ mpBorders
[nIdx
].nWidth
;
2407 lActBorderSum
= mpBorders
[nIdx
].nWidth
;
2410 //in horizontal mode the percentage value has to be
2411 //calculated on a "current change" position base
2412 //because the height of the table changes while dragging
2413 if(mpRulerImpl
->bIsTableRows
&& RULER_TYPE_BORDER
== eType
)
2415 sal_uInt16 nStartBorder
;
2416 sal_uInt16 nEndBorder
;
2419 nStartBorder
= nIdx
+ 1;
2420 nEndBorder
= mpColumnItem
->Count() - 1;
2428 lWidth
= mpBorders
[nIdx
].nPos
;
2430 lWidth
= GetMargin2() - lWidth
;
2431 mpRulerImpl
->nTotalDist
= lWidth
;
2432 lPos
= lOrigLPos
= mpBorders
[nIdx
].nPos
;
2434 for(sal_uInt16 i
= nStartBorder
; i
< nEndBorder
; ++i
)
2438 lActWidth
+= mpBorders
[i
].nPos
- lPos
;
2439 lPos
= mpBorders
[i
].nPos
+ mpBorders
[i
].nWidth
;
2442 lActWidth
= mpBorders
[i
].nPos
;
2443 mpRulerImpl
->pPercBuf
[i
] = (sal_uInt16
)((lActWidth
* 1000)
2444 / mpRulerImpl
->nTotalDist
);
2445 mpRulerImpl
->pBlockBuf
[i
] = (sal_uInt16
)lActBorderSum
;
2446 lActBorderSum
+= mpBorders
[i
].nWidth
;
2452 for(sal_uInt16 ii
= nStart
; ii
< mpColumnItem
->Count() - 1; ++ii
)
2454 lWidth
+= mpBorders
[ii
].nPos
- lPos
;
2455 lPos
= mpBorders
[ii
].nPos
+ mpBorders
[ii
].nWidth
;
2458 lWidth
+= GetMargin2() - lPos
;
2459 mpRulerImpl
->nTotalDist
= lWidth
;
2462 for(sal_uInt16 i
= nStart
; i
< mpColumnItem
->Count() - 1; ++i
)
2464 lActWidth
+= mpBorders
[i
].nPos
- lPos
;
2465 lPos
= mpBorders
[i
].nPos
+ mpBorders
[i
].nWidth
;
2466 mpRulerImpl
->pPercBuf
[i
] = (sal_uInt16
)((lActWidth
* 1000)
2467 / mpRulerImpl
->nTotalDist
);
2468 mpRulerImpl
->pBlockBuf
[i
] = (sal_uInt16
)lActBorderSum
;
2469 lActBorderSum
+= mpBorders
[i
].nWidth
;
2474 case RULER_TYPE_TAB
:
2476 const sal_uInt16 nIdx
= GetDragAryPos()+TAB_GAP
;
2477 mpRulerImpl
->nTotalDist
-= mpTabs
[nIdx
].nPos
;
2478 mpRulerImpl
->SetPercSize(nTabCount
);
2479 for(sal_uInt16 n
=0;n
<=nIdx
;mpRulerImpl
->pPercBuf
[n
++]=0) ;
2480 for(sal_uInt16 i
= nIdx
+1; i
< nTabCount
; ++i
)
2482 const long nDelta
= mpTabs
[i
].nPos
- mpTabs
[nIdx
].nPos
;
2483 mpRulerImpl
->pPercBuf
[i
] = (sal_uInt16
)((nDelta
* 1000) / mpRulerImpl
->nTotalDist
);
2490 void SvxRuler::EvalModifier()
2495 Control: move proportional
2496 Shift + Control: Table: only current line
2497 Alt: disable snapping
2498 Alt + Shift: coarse snapping
2501 sal_uInt16 nModifier
= GetDragModifier();
2502 if(mpRulerImpl
->bIsTableRows
)
2504 //rows can only be moved in one way, additionally current column is possible
2505 if(nModifier
== KEY_SHIFT
)
2512 nDragType
= DRAG_OBJECT_SIZE_LINEAR
;
2514 case KEY_MOD2
| KEY_SHIFT
:
2515 mbCoarseSnapping
= true;
2522 const RulerType eType
= GetDragType();
2523 nDragType
= DRAG_OBJECT_SIZE_PROPORTIONAL
;
2524 if( RULER_TYPE_TAB
== eType
||
2525 ( ( RULER_TYPE_BORDER
== eType
||
2526 RULER_TYPE_MARGIN1
== eType
||
2527 RULER_TYPE_MARGIN2
== eType
) &&
2528 mpColumnItem
.get() ) )
2530 PrepareProportional_Impl(eType
);
2534 case KEY_MOD1
| KEY_SHIFT
:
2535 if( GetDragType() != RULER_TYPE_MARGIN1
&&
2536 GetDragType() != RULER_TYPE_MARGIN2
)
2538 nDragType
= DRAG_OBJECT_ACTLINE_ONLY
;
2544 void SvxRuler::Click()
2546 /* Overloaded handler SV; sets Tab per dispatcher call */
2550 pBindings
->Update( SID_RULER_LR_MIN_MAX
);
2551 pBindings
->Update( SID_ATTR_LONG_ULSPACE
);
2552 pBindings
->Update( SID_ATTR_LONG_LRSPACE
);
2553 pBindings
->Update( SID_RULER_PAGE_POS
);
2554 pBindings
->Update( bHorz
? SID_ATTR_TABSTOP
: SID_ATTR_TABSTOP_VERTICAL
);
2555 pBindings
->Update( bHorz
? SID_ATTR_PARA_LRSPACE
: SID_ATTR_PARA_LRSPACE_VERTICAL
);
2556 pBindings
->Update( bHorz
? SID_RULER_BORDERS
: SID_RULER_BORDERS_VERTICAL
);
2557 pBindings
->Update( bHorz
? SID_RULER_ROWS
: SID_RULER_ROWS_VERTICAL
);
2558 pBindings
->Update( SID_RULER_OBJECT
);
2559 pBindings
->Update( SID_RULER_PROTECT
);
2560 pBindings
->Update( SID_ATTR_PARA_LRSPACE_VERTICAL
);
2562 bool bRTL
= mpRulerImpl
->pTextRTLItem
&& mpRulerImpl
->pTextRTLItem
->GetValue();
2563 if(mpTabStopItem
.get() &&
2564 (nFlags
& SVXRULER_SUPPORT_TABS
) == SVXRULER_SUPPORT_TABS
)
2566 bool bContentProtected
= mpRulerImpl
->aProtectItem
.IsCntntProtected();
2567 if( bContentProtected
) return;
2568 const long lPos
= GetClickPos();
2569 if((bRTL
&& lPos
< std::min(GetFirstLineIndent(), GetLeftIndent()) && lPos
> GetRightIndent()) ||
2570 (!bRTL
&& lPos
> std::min(GetFirstLineIndent(), GetLeftIndent()) && lPos
< GetRightIndent()))
2572 //convert position in left-to-right text
2574 //#i24363# tab stops relative to indent
2576 nTabPos
= ( mpRulerImpl
->bIsTabsRelativeToIndent
?
2578 ConvertHPosPixel( GetRightFrameMargin() + lAppNullOffset
) ) -
2582 ( mpRulerImpl
->bIsTabsRelativeToIndent
?
2586 SvxTabStop
aTabStop(ConvertHPosLogic(nTabPos
),
2587 ToAttrTab_Impl(nDefTabType
));
2588 mpTabStopItem
->Insert(aTabStop
);
2594 bool SvxRuler::CalcLimits ( long& nMax1
, // minimum value to be set
2595 long& nMax2
, // minimum value to be set
2599 Default implementation of the virtual function; the application can be
2600 overloaded to implement customized limits. The values are based on the page.
2607 void SvxRuler::CalcMinMax()
2610 Calculates the limits for dragging; which are in pixels relative to the
2613 bool bRTL
= mpRulerImpl
->pTextRTLItem
&& mpRulerImpl
->pTextRTLItem
->GetValue();
2614 const long lNullPix
= ConvertPosPixel(lLogicNullOffset
);
2615 mpRulerImpl
->lMaxLeftLogic
=mpRulerImpl
->lMaxRightLogic
=-1;
2616 switch(GetDragType())
2618 case RULER_TYPE_MARGIN1
:
2619 { // left edge of the surrounding Frame
2620 // DragPos - NOf between left - right
2621 mpRulerImpl
->lMaxLeftLogic
= GetLeftMin();
2622 nMaxLeft
=ConvertSizePixel(mpRulerImpl
->lMaxLeftLogic
);
2624 if (!mpColumnItem
.get() || mpColumnItem
->Count() == 1 )
2628 nMaxRight
= lNullPix
- GetRightIndent() +
2629 std::max(GetFirstLineIndent(), GetLeftIndent()) -
2634 nMaxRight
= lNullPix
+ GetRightIndent() -
2635 std::max(GetFirstLineIndent(), GetLeftIndent()) -
2639 else if(mpRulerImpl
->bIsTableRows
)
2641 //top border is not moveable when table rows are displayed
2642 // protection of content means the margin is not moveable
2643 // - it's just a page break inside of a cell
2644 if(bHorz
&& !mpRulerImpl
->aProtectItem
.IsCntntProtected())
2646 nMaxLeft
= mpBorders
[0].nMinPos
+ lNullPix
;
2647 if(nDragType
& DRAG_OBJECT_SIZE_PROPORTIONAL
)
2648 nMaxRight
= GetRightIndent() + lNullPix
-
2649 (mpColumnItem
->Count() - 1 ) * lMinFrame
;
2651 nMaxRight
= mpBorders
[0].nPos
- lMinFrame
+ lNullPix
;
2654 nMaxLeft
= nMaxRight
= lNullPix
;
2658 if (nDragType
& DRAG_OBJECT_SIZE_PROPORTIONAL
)
2660 nMaxRight
=lNullPix
+CalcPropMaxRight();
2662 else if (nDragType
& DRAG_OBJECT_SIZE_LINEAR
)
2664 nMaxRight
= ConvertPosPixel(
2666 (mpColumnItem
->IsTable() && mpLRSpaceItem
.get())
2667 ? mpLRSpaceItem
->GetRight() : 0))
2668 - GetMargin2() + GetMargin1();
2672 nMaxRight
= lNullPix
- lMinFrame
;
2673 if (mpColumnItem
->IsFirstAct())
2677 nMaxRight
+= std::min(
2679 std::max(GetFirstLineIndent(), GetLeftIndent()) - GetRightIndent());
2683 nMaxRight
+= std::min(
2684 mpBorders
[0].nPos
, GetRightIndent() -
2685 std::max(GetFirstLineIndent(), GetLeftIndent()));
2688 else if ( mpColumnItem
->Count() > 1 )
2690 nMaxRight
+= mpBorders
[0].nPos
;
2694 nMaxRight
+= GetRightIndent() - std::max(GetFirstLineIndent(), GetLeftIndent());
2696 // Do not drag the left table edge over the edge of the page
2697 if(mpLRSpaceItem
.get() && mpColumnItem
->IsTable())
2699 long nTmp
=ConvertSizePixel(mpLRSpaceItem
->GetLeft());
2707 case RULER_TYPE_MARGIN2
:
2708 { // right edge of the surrounding Frame
2709 mpRulerImpl
->lMaxRightLogic
=
2710 mpMinMaxItem
.get() ?
2711 GetPageWidth() - GetRightMax() :
2713 nMaxRight
= ConvertSizePixel(mpRulerImpl
->lMaxRightLogic
);
2716 if(!mpColumnItem
.get())
2720 nMaxLeft
= GetMargin2() + GetRightIndent() -
2721 std::max(GetFirstLineIndent(),GetLeftIndent()) - GetMargin1()+
2722 lMinFrame
+ lNullPix
;
2726 nMaxLeft
= GetMargin2() - GetRightIndent() +
2727 std::max(GetFirstLineIndent(),GetLeftIndent()) - GetMargin1()+
2728 lMinFrame
+ lNullPix
;
2731 else if(mpRulerImpl
->bIsTableRows
)
2733 // get the bottom move range from the last border position - only available for rows!
2734 // protection of content means the margin is not moveable - it's just a page break inside of a cell
2735 if(bHorz
|| mpRulerImpl
->aProtectItem
.IsCntntProtected())
2737 nMaxLeft
= nMaxRight
= mpBorders
[mpColumnItem
->Count() - 1].nMaxPos
+ lNullPix
;
2741 if(nDragType
& DRAG_OBJECT_SIZE_PROPORTIONAL
)
2743 nMaxLeft
= (mpColumnItem
->Count()) * lMinFrame
+ lNullPix
;
2747 if(mpColumnItem
->Count() > 1)
2748 nMaxLeft
= mpBorders
[mpColumnItem
->Count() - 2].nPos
+ lMinFrame
+ lNullPix
;
2750 nMaxLeft
= lMinFrame
+ lNullPix
;
2752 if(mpColumnItem
->Count() > 1)
2753 nMaxRight
= mpBorders
[mpColumnItem
->Count() - 2].nMaxPos
+ lNullPix
;
2755 nMaxRight
-= GetRightIndent() - lNullPix
;
2760 nMaxLeft
= lMinFrame
+ lNullPix
;
2761 if(IsActLastColumn() || mpColumnItem
->Count() < 2 ) //If last active column
2765 nMaxLeft
= lMinFrame
+ lNullPix
+ GetMargin2() +
2766 GetRightIndent() - std::max(GetFirstLineIndent(),
2771 nMaxLeft
= lMinFrame
+ lNullPix
+ GetMargin2() -
2772 GetRightIndent() + std::max(GetFirstLineIndent(),
2776 if( mpColumnItem
->Count() >= 2 )
2779 lMinFrame
+ lNullPix
+
2780 mpBorders
[mpColumnItem
->Count() - 2].nPos
+
2781 mpBorders
[mpColumnItem
->Count() - 2].nWidth
;
2782 nMaxLeft
= std::max(nMaxLeft
, nNewMaxLeft
);
2788 case RULER_TYPE_BORDER
:
2789 { // Table, column (Modifier)
2790 const sal_uInt16 nIdx
= GetDragAryPos();
2791 switch(GetDragSize())
2793 case RULER_DRAGSIZE_1
:
2795 nMaxRight
= mpBorders
[nIdx
].nPos
+
2796 mpBorders
[nIdx
].nWidth
+ lNullPix
;
2799 nMaxLeft
= lNullPix
;
2801 nMaxLeft
= mpBorders
[nIdx
- 1].nPos
+ mpBorders
[nIdx
- 1].nWidth
+ lNullPix
;
2802 if(nIdx
== mpColumnItem
->GetActColumn())
2806 nMaxLeft
+= mpBorders
[nIdx
].nPos
+
2807 GetRightIndent() - std::max(GetFirstLineIndent(),
2812 nMaxLeft
+= mpBorders
[nIdx
].nPos
-
2813 GetRightIndent() + std::max(GetFirstLineIndent(),
2817 nMaxLeft
-= mpBorders
[nIdx
-1].nPos
+
2818 mpBorders
[nIdx
-1].nWidth
;
2820 nMaxLeft
+= lMinFrame
;
2821 nMaxLeft
+= nDragOffset
;
2824 case RULER_DRAGSIZE_MOVE
:
2826 if(mpColumnItem
.get())
2828 //nIdx contains the position of the currently moved item
2829 //next visible separator on the left
2830 sal_uInt16 nLeftCol
=GetActLeftColumn(false, nIdx
);
2831 //next visible separator on the right
2832 sal_uInt16 nRightCol
=GetActRightColumn(false, nIdx
);
2833 //next separator on the left - regardless if visible or not
2834 sal_uInt16 nActLeftCol
=GetActLeftColumn();
2835 //next separator on the right - regardless if visible or not
2836 sal_uInt16 nActRightCol
=GetActRightColumn();
2837 if(mpColumnItem
->IsTable())
2839 if(nDragType
& DRAG_OBJECT_ACTLINE_ONLY
)
2841 //the current row/column should be modified only
2842 //then the next/previous visible border position
2843 //marks the min/max positions
2844 nMaxLeft
= nLeftCol
== USHRT_MAX
?
2846 mpBorders
[nLeftCol
].nPos
;
2847 //rows can always be increased without a limit
2848 if(mpRulerImpl
->bIsTableRows
)
2849 nMaxRight
= mpBorders
[nIdx
].nMaxPos
;
2851 nMaxRight
= nRightCol
== USHRT_MAX
?
2853 mpBorders
[nRightCol
].nPos
;
2854 nMaxLeft
+= lNullPix
;
2855 nMaxRight
+= lNullPix
;
2859 if(DRAG_OBJECT_SIZE_PROPORTIONAL
& nDragType
&& !bHorz
&& mpRulerImpl
->bIsTableRows
)
2860 nMaxLeft
= (nIdx
+ 1) * lMinFrame
+ lNullPix
;
2862 nMaxLeft
= mpBorders
[nIdx
].nMinPos
+ lNullPix
;
2863 if(DRAG_OBJECT_SIZE_PROPORTIONAL
& nDragType
||
2864 (DRAG_OBJECT_SIZE_LINEAR
& nDragType
) )
2866 if(mpRulerImpl
->bIsTableRows
)
2869 nMaxRight
= GetRightIndent() + lNullPix
-
2870 (mpColumnItem
->Count() - nIdx
- 1) * lMinFrame
;
2872 nMaxRight
= mpBorders
[nIdx
].nMaxPos
+ lNullPix
;
2875 nMaxRight
=lNullPix
+CalcPropMaxRight(nIdx
);
2878 nMaxRight
= mpBorders
[nIdx
].nMaxPos
+ lNullPix
;
2880 nMaxLeft
+= lMinFrame
;
2881 nMaxRight
-= lMinFrame
;
2886 if(nLeftCol
==USHRT_MAX
)
2889 nMaxLeft
= mpBorders
[nLeftCol
].nPos
+
2890 mpBorders
[nLeftCol
].nWidth
+ lNullPix
;
2892 if(nActRightCol
== nIdx
)
2896 nMaxLeft
+= mpBorders
[nIdx
].nPos
+
2897 GetRightIndent() - std::max(GetFirstLineIndent(),
2899 if(nActLeftCol
!=USHRT_MAX
)
2900 nMaxLeft
-= mpBorders
[nActLeftCol
].nPos
+
2901 mpBorders
[nActLeftCol
].nWidth
;
2905 nMaxLeft
+= mpBorders
[nIdx
].nPos
-
2906 GetRightIndent() + std::max(GetFirstLineIndent(),
2908 if(nActLeftCol
!=USHRT_MAX
)
2909 nMaxLeft
-= mpBorders
[nActLeftCol
].nPos
+
2910 mpBorders
[nActLeftCol
].nWidth
;
2913 nMaxLeft
+= lMinFrame
;
2914 nMaxLeft
+= nDragOffset
;
2917 // linear / proprotional move
2918 if(DRAG_OBJECT_SIZE_PROPORTIONAL
& nDragType
||
2919 (DRAG_OBJECT_SIZE_LINEAR
& nDragType
) )
2921 nMaxRight
=lNullPix
+CalcPropMaxRight(nIdx
);
2923 else if(DRAG_OBJECT_SIZE_LINEAR
& nDragType
)
2925 nMaxRight
= lNullPix
+ GetMargin2() - GetMargin1() +
2926 (mpBorders
.size() - nIdx
- 1) * lMinFrame
;
2930 if(nRightCol
==USHRT_MAX
)
2932 nMaxRight
= GetMargin2() + lNullPix
;
2933 if(IsActLastColumn())
2938 GetMargin2() + GetRightIndent() -
2939 std::max(GetFirstLineIndent(),
2945 GetMargin2() - GetRightIndent() +
2946 std::max(GetFirstLineIndent(),
2949 nMaxRight
+= mpBorders
[nIdx
].nPos
+
2950 mpBorders
[nIdx
].nWidth
;
2955 nMaxRight
= lNullPix
+ mpBorders
[nRightCol
].nPos
;
2956 sal_uInt16 nNotHiddenRightCol
=
2957 GetActRightColumn(true, nIdx
);
2959 if( nActLeftCol
== nIdx
)
2961 long nBorder
= nNotHiddenRightCol
==
2964 mpBorders
[nNotHiddenRightCol
].nPos
;
2967 nMaxRight
-= nBorder
+ GetRightIndent() -
2968 std::max(GetFirstLineIndent(),
2973 nMaxRight
-= nBorder
- GetRightIndent() +
2974 std::max(GetFirstLineIndent(),
2977 nMaxRight
+= mpBorders
[nIdx
].nPos
+
2978 mpBorders
[nIdx
].nWidth
;
2981 nMaxRight
-= lMinFrame
;
2982 nMaxRight
-= mpBorders
[nIdx
].nWidth
;
2989 if(mpObjectItem
->HasLimits())
2991 if(CalcLimits(nMaxLeft
, nMaxRight
, nIdx
& 1? sal_False
: sal_True
))
2993 nMaxLeft
= ConvertPosPixel(nMaxLeft
);
2994 nMaxRight
= ConvertPosPixel(nMaxRight
);
2999 nMaxLeft
= LONG_MIN
;
3000 nMaxRight
= LONG_MAX
;
3005 case RULER_DRAGSIZE_2
:
3007 nMaxLeft
= lNullPix
+ mpBorders
[nIdx
].nPos
;
3008 if(nIdx
== mpColumnItem
->Count()-2) { // last column
3009 nMaxRight
= GetMargin2() + lNullPix
;
3010 if(mpColumnItem
->IsLastAct()) {
3012 GetMargin2() - GetRightIndent() +
3013 std::max(GetFirstLineIndent(),
3015 nMaxRight
+= mpBorders
[nIdx
].nPos
+
3016 mpBorders
[nIdx
].nWidth
;
3020 nMaxRight
= lNullPix
+ mpBorders
[nIdx
+1].nPos
;
3021 if(mpColumnItem
->GetActColumn()-1 == nIdx
) {
3022 nMaxRight
-= mpBorders
[nIdx
+1].nPos
- GetRightIndent() +
3023 std::max(GetFirstLineIndent(),
3025 nMaxRight
+= mpBorders
[nIdx
].nPos
+
3026 mpBorders
[nIdx
].nWidth
;
3029 nMaxRight
-= lMinFrame
;
3030 nMaxRight
-= mpBorders
[nIdx
].nWidth
;
3034 nMaxRight
+= nDragOffset
;
3037 case RULER_TYPE_INDENT
:
3039 const sal_uInt16 nIdx
= GetDragAryPos();
3041 case INDENT_FIRST_LINE
- INDENT_GAP
:
3042 case INDENT_LEFT_MARGIN
- INDENT_GAP
:
3046 nMaxLeft
= lNullPix
+ GetRightIndent();
3048 if(mpColumnItem
.get() && !mpColumnItem
->IsFirstAct())
3049 nMaxLeft
+= mpBorders
[mpColumnItem
->GetActColumn()-1].nPos
+
3050 mpBorders
[mpColumnItem
->GetActColumn()-1].nWidth
;
3051 nMaxRight
= lNullPix
+ GetMargin2();
3054 if((INDENT_FIRST_LINE
- INDENT_GAP
) != nIdx
&&
3055 (nDragType
& DRAG_OBJECT_LEFT_INDENT_ONLY
) !=
3056 DRAG_OBJECT_LEFT_INDENT_ONLY
)
3058 if(GetLeftIndent() > GetFirstLineIndent())
3059 nMaxLeft
+= GetLeftIndent() - GetFirstLineIndent();
3061 nMaxRight
-= GetFirstLineIndent() - GetLeftIndent();
3066 nMaxLeft
= lNullPix
;
3068 if(mpColumnItem
.get() && !mpColumnItem
->IsFirstAct())
3069 nMaxLeft
+= mpBorders
[mpColumnItem
->GetActColumn()-1].nPos
+
3070 mpBorders
[mpColumnItem
->GetActColumn()-1].nWidth
;
3071 nMaxRight
= lNullPix
+ GetRightIndent() - lMinFrame
;
3074 if((INDENT_FIRST_LINE
- INDENT_GAP
) != nIdx
&&
3075 (nDragType
& DRAG_OBJECT_LEFT_INDENT_ONLY
) !=
3076 DRAG_OBJECT_LEFT_INDENT_ONLY
)
3078 if(GetLeftIndent() > GetFirstLineIndent())
3079 nMaxLeft
+= GetLeftIndent() - GetFirstLineIndent();
3081 nMaxRight
-= GetFirstLineIndent() - GetLeftIndent();
3086 case INDENT_RIGHT_MARGIN
- INDENT_GAP
:
3090 nMaxLeft
= lNullPix
;
3091 nMaxRight
= lNullPix
+ std::min(GetFirstLineIndent(), GetLeftIndent()) - lMinFrame
;
3092 if(mpColumnItem
.get())
3094 sal_uInt16 nRightCol
=GetActRightColumn( true );
3095 if(!IsActLastColumn( true ))
3096 nMaxRight
+= mpBorders
[nRightCol
].nPos
;
3098 nMaxRight
+= GetMargin2();
3102 nMaxLeft
+= GetMargin1();
3104 nMaxLeft
+= lMinFrame
;
3108 nMaxLeft
= lNullPix
+
3109 std::max(GetFirstLineIndent(), GetLeftIndent());
3110 nMaxRight
= lNullPix
;
3111 if(mpColumnItem
.get())
3113 sal_uInt16 nRightCol
=GetActRightColumn( true );
3114 if(!IsActLastColumn( true ))
3115 nMaxRight
+= mpBorders
[nRightCol
].nPos
;
3117 nMaxRight
+= GetMargin2();
3120 nMaxRight
+= GetMargin2();
3121 nMaxLeft
+= lMinFrame
;
3128 case RULER_TYPE_TAB
: // Tabs (Modifier)
3129 /* left = NOf + Max(LAR, EZ)
3130 right = NOf + RAR */
3133 nMaxLeft
= lNullPix
+ GetRightIndent();
3135 nMaxLeft
= lNullPix
+ std::min(GetFirstLineIndent(), GetLeftIndent());
3137 mpRulerImpl
->lMaxRightLogic
= GetLogicRightIndent() + lLogicNullOffset
;
3138 nMaxRight
= ConvertSizePixel(mpRulerImpl
->lMaxRightLogic
);
3140 default: ; //prevent warning
3144 long SvxRuler::StartDrag()
3147 Beginning of a drag operation (SV-handler) evaluates modifier and
3152 <SvxRuler::EvalModifier()>
3153 <SvxRuler::CalcMinMax()>
3154 <SvxRuler::EndDrag()>
3156 bool bContentProtected
= mpRulerImpl
->aProtectItem
.IsCntntProtected();
3161 mpRulerImpl
->lLastLMargin
= GetMargin1();
3162 mpRulerImpl
->lLastRMargin
= GetMargin2();
3166 if(GetStartDragHdl().IsSet())
3167 bOk
= Ruler::StartDrag();
3171 lInitialDragPos
= GetDragPos();
3172 switch(GetDragType())
3174 case RULER_TYPE_MARGIN1
: // left edge of the surrounding Frame
3175 case RULER_TYPE_MARGIN2
: // right edge of the surrounding Frame
3176 if((bHorz
&& mpLRSpaceItem
.get()) || (!bHorz
&& mpULSpaceItem
.get()))
3178 if(!mpColumnItem
.get())
3181 nDragType
= DRAG_OBJECT
;
3188 case RULER_TYPE_BORDER
: // Table, column (Modifier)
3189 if(mpColumnItem
.get())
3192 if (!mpColumnItem
->IsTable())
3193 nDragOffset
= GetDragPos() - mpBorders
[GetDragAryPos()].nPos
;
3199 case RULER_TYPE_INDENT
: // Paragraph indents (Modifier)
3201 if( bContentProtected
)
3203 sal_uInt16 nIndent
= INDENT_LEFT_MARGIN
;
3204 if((nIndent
) == GetDragAryPos() + INDENT_GAP
) { // Left paragraph indent
3205 mpIndents
[0] = mpIndents
[INDENT_FIRST_LINE
];
3206 mpIndents
[0].nStyle
|= RULER_STYLE_DONTKNOW
;
3211 nDragType
= DRAG_OBJECT
;
3213 mpIndents
[1] = mpIndents
[GetDragAryPos() + INDENT_GAP
];
3214 mpIndents
[1].nStyle
|= RULER_STYLE_DONTKNOW
;
3217 case RULER_TYPE_TAB
: // Tabs (Modifier)
3218 if( bContentProtected
)
3221 mpTabs
[0] = mpTabs
[GetDragAryPos() + 1];
3222 mpTabs
[0].nStyle
|= RULER_STYLE_DONTKNOW
;
3239 void SvxRuler::Drag()
3241 /* SV-Draghandler */
3242 if(IsDragCanceled())
3247 switch(GetDragType()) {
3248 case RULER_TYPE_MARGIN1
: // left edge of the surrounding Frame
3250 mpRulerImpl
->lLastLMargin
= GetMargin1();
3252 case RULER_TYPE_MARGIN2
: // right edge of the surrounding Frame
3254 mpRulerImpl
->lLastRMargin
= GetMargin2();
3256 case RULER_TYPE_INDENT
: // Paragraph indents
3259 case RULER_TYPE_BORDER
: // Table, columns
3260 if(mpColumnItem
.get())
3262 else if(mpObjectItem
.get())
3265 case RULER_TYPE_TAB
: // Tabs
3269 break; //prevent warning
3274 void SvxRuler::EndDrag()
3277 SV-handler; is called when ending the dragging. Triggers the updating of data
3278 on the application, by calling the respective Apply...() methods to send the
3279 data to the application.
3281 const bool bUndo
= IsDragCanceled();
3282 const long lPos
= GetDragPos();
3283 DrawLine_Impl(lTabPos
, 6, bHorz
);
3288 switch(GetDragType())
3290 case RULER_TYPE_MARGIN1
: // upper left edge of the surrounding Frame
3291 case RULER_TYPE_MARGIN2
: // lower right edge of the surrounding Frame
3293 if(!mpColumnItem
.get() || !mpColumnItem
->IsTable())
3296 if(mpColumnItem
.get() &&
3297 (mpColumnItem
->IsTable() ||
3298 (nDragType
& DRAG_OBJECT_SIZE_PROPORTIONAL
)))
3303 case RULER_TYPE_BORDER
: // Table, columns
3304 if(lInitialDragPos
!= lPos
||
3305 (mpRulerImpl
->bIsTableRows
&& bHorz
)) //special case - the null offset is changed here
3307 if(mpColumnItem
.get())
3313 else if(mpObjectItem
.get())
3317 case RULER_TYPE_INDENT
: // Paragraph indents
3318 if(lInitialDragPos
!= lPos
)
3320 SetIndents(INDENT_COUNT
, &mpIndents
[0] + INDENT_GAP
);
3322 case RULER_TYPE_TAB
: // Tabs
3325 mpTabs
[GetDragAryPos()].nStyle
&= ~RULER_STYLE_INVISIBLE
;
3326 SetTabs(nTabCount
, &mpTabs
[0] + TAB_GAP
);
3330 break; //prevent warning
3335 mbCoarseSnapping
= false;
3341 for(sal_uInt16 i
= 0; i
< mpRulerImpl
->nControlerItems
; i
++)
3343 pCtrlItem
[i
]->ClearCache();
3344 pCtrlItem
[i
]->GetBindings().Invalidate(pCtrlItem
[i
]->GetId());
3349 void SvxRuler::ExtraDown()
3351 /* Overloaded SV method, sets the new type for the Default tab. */
3354 if(mpTabStopItem
.get() &&
3355 (nFlags
& SVXRULER_SUPPORT_TABS
) == SVXRULER_SUPPORT_TABS
)
3358 if(RULER_TAB_DEFAULT
== nDefTabType
)
3359 nDefTabType
= RULER_TAB_LEFT
;
3360 SetExtraType(RULER_EXTRA_TAB
, nDefTabType
);
3365 void SvxRuler::Notify(SfxBroadcaster
&, const SfxHint
& rHint
)
3368 Report through the bindings that the status update is completed. The ruler
3369 updates its appearance and gets registered again in the bindings.
3374 rHint
.Type() == TYPE(SfxSimpleHint
) &&
3375 ((SfxSimpleHint
&) rHint
).GetId() == SFX_HINT_UPDATEDONE
)
3378 EndListening(*pBindings
);
3385 IMPL_LINK_INLINE_START( SvxRuler
, MenuSelect
, Menu
*, pMenu
)
3387 /* Handler of the context menus for switching the unit of measurement */
3388 SetUnit(FieldUnit(pMenu
->GetCurItemId()));
3391 IMPL_LINK_INLINE_END( SvxRuler
, MenuSelect
, Menu
*, pMenu
)
3393 IMPL_LINK( SvxRuler
, TabMenuSelect
, Menu
*, pMenu
)
3395 /* Handler of the tab menu for setting the type */
3396 if(mpTabStopItem
.get() && mpTabStopItem
->Count() > mpRulerImpl
->nIdx
)
3398 SvxTabStop aTabStop
= mpTabStopItem
->At(mpRulerImpl
->nIdx
);
3399 aTabStop
.GetAdjustment() = ToAttrTab_Impl(pMenu
->GetCurItemId() - 1);
3400 mpTabStopItem
->Remove(mpRulerImpl
->nIdx
);
3401 mpTabStopItem
->Insert(aTabStop
);
3402 sal_uInt16 nTabStopId
= bHorz
? SID_ATTR_TABSTOP
: SID_ATTR_TABSTOP_VERTICAL
;
3403 pBindings
->GetDispatcher()->Execute( nTabStopId
, SFX_CALLMODE_RECORD
, mpTabStopItem
.get(), 0L );
3405 mpRulerImpl
->nIdx
= 0;
3410 void SvxRuler::Command( const CommandEvent
& rCommandEvent
)
3412 /* Mouse context menu for switching the unit of measurement */
3413 if ( COMMAND_CONTEXTMENU
== rCommandEvent
.GetCommand() )
3416 bool bRTL
= mpRulerImpl
->pTextRTLItem
&& mpRulerImpl
->pTextRTLItem
->GetValue();
3417 if ( !mpTabs
.empty() &&
3419 GetType( rCommandEvent
.GetMousePosPixel(), &mpRulerImpl
->nIdx
) &&
3420 mpTabs
[mpRulerImpl
->nIdx
+ TAB_GAP
].nStyle
< RULER_TAB_DEFAULT
)
3423 aMenu
.SetSelectHdl(LINK(this, SvxRuler
, TabMenuSelect
));
3425 const Size
aSz(RULER_TAB_WIDTH
+ 2, RULER_TAB_HEIGHT
+ 2);
3426 aDev
.SetOutputSize(aSz
);
3427 aDev
.SetBackground(Wallpaper(Color(COL_WHITE
)));
3428 Color
aFillColor(aDev
.GetSettings().GetStyleSettings().GetShadowColor());
3429 const Point
aPt(aSz
.Width() / 2, aSz
.Height() / 2);
3431 for ( sal_uInt16 i
= RULER_TAB_LEFT
; i
< RULER_TAB_DEFAULT
; ++i
)
3433 sal_uInt16 nStyle
= bRTL
? i
|RULER_TAB_RTL
: i
;
3434 nStyle
|= static_cast<sal_uInt16
>(bHorz
? WB_HORZ
: WB_VERT
);
3435 DrawTab(&aDev
, aFillColor
, aPt
, nStyle
);
3436 aMenu
.InsertItem(i
+ 1,
3437 ResId(RID_SVXSTR_RULER_START
+ i
, DIALOG_MGR()).toString(),
3438 Image(aDev
.GetBitmap(Point(), aSz
), Color(COL_WHITE
)));
3439 aMenu
.CheckItem(i
+ 1, i
== mpTabs
[mpRulerImpl
->nIdx
+ TAB_GAP
].nStyle
);
3440 aDev
.SetOutputSize(aSz
); // delete device
3442 aMenu
.Execute( this, rCommandEvent
.GetMousePosPixel() );
3446 PopupMenu
aMenu(ResId(RID_SVXMN_RULER
, DIALOG_MGR()));
3447 aMenu
.SetSelectHdl(LINK(this, SvxRuler
, MenuSelect
));
3448 FieldUnit eUnit
= GetUnit();
3449 const sal_uInt16 nCount
= aMenu
.GetItemCount();
3451 bool bReduceMetric
= 0 != (nFlags
& SVXRULER_SUPPORT_REDUCED_METRIC
);
3452 for ( sal_uInt16 i
= nCount
; i
; --i
)
3454 const sal_uInt16 nId
= aMenu
.GetItemId(i
- 1);
3455 aMenu
.CheckItem(nId
, nId
== (sal_uInt16
)eUnit
);
3458 if ( nId
== FUNIT_M
||
3460 nId
== FUNIT_FOOT
||
3463 aMenu
.RemoveItem(i
- 1);
3465 else if (( nId
== FUNIT_CHAR
) && !bHorz
)
3467 aMenu
.RemoveItem(i
- 1);
3469 else if (( nId
== FUNIT_LINE
) && bHorz
)
3471 aMenu
.RemoveItem(i
- 1);
3475 aMenu
.Execute( this, rCommandEvent
.GetMousePosPixel() );
3480 Ruler::Command( rCommandEvent
);
3484 sal_uInt16
SvxRuler::GetActRightColumn(
3485 bool bForceDontConsiderHidden
,
3486 sal_uInt16 nAct
) const
3488 if( nAct
== USHRT_MAX
)
3489 nAct
= mpColumnItem
->GetActColumn();
3491 nAct
++; //To be able to pass on the ActDrag
3493 bool bConsiderHidden
= !bForceDontConsiderHidden
&&
3494 !(nDragType
& DRAG_OBJECT_ACTLINE_ONLY
);
3496 while( nAct
< mpColumnItem
->Count() - 1 )
3498 if (mpColumnItem
->At(nAct
).bVisible
|| bConsiderHidden
)
3506 sal_uInt16
SvxRuler::GetActLeftColumn(
3507 bool bForceDontConsiderHidden
,
3508 sal_uInt16 nAct
) const
3510 if(nAct
== USHRT_MAX
)
3511 nAct
= mpColumnItem
->GetActColumn();
3513 sal_uInt16 nLeftOffset
= 1;
3515 bool bConsiderHidden
= !bForceDontConsiderHidden
&&
3516 !(nDragType
& DRAG_OBJECT_ACTLINE_ONLY
);
3518 while(nAct
>= nLeftOffset
)
3520 if (mpColumnItem
->At(nAct
- nLeftOffset
).bVisible
|| bConsiderHidden
)
3521 return nAct
- nLeftOffset
;
3528 bool SvxRuler::IsActLastColumn(
3529 bool bForceDontConsiderHidden
,
3530 sal_uInt16 nAct
) const
3532 return GetActRightColumn(bForceDontConsiderHidden
, nAct
) == USHRT_MAX
;
3535 bool SvxRuler::IsActFirstColumn(
3536 bool bForceDontConsiderHidden
,
3537 sal_uInt16 nAct
) const
3539 return GetActLeftColumn(bForceDontConsiderHidden
, nAct
) == USHRT_MAX
;
3542 long SvxRuler::CalcPropMaxRight(sal_uInt16 nCol
) const
3545 if(!(nDragType
& DRAG_OBJECT_SIZE_LINEAR
))
3547 // Remove the minimum width for all affected columns
3548 // starting from the right edge
3549 long _nMaxRight
= GetMargin2() - GetMargin1();
3552 long lMinSpace
= USHRT_MAX
;
3557 if(!mpColumnItem
->IsTable())
3559 if(nCol
== USHRT_MAX
)
3561 lOldPos
= GetMargin1();
3566 lOldPos
= mpBorders
[nCol
].nPos
+ mpBorders
[nCol
].nWidth
;
3568 lFences
= mpBorders
[nCol
].nWidth
;
3571 for(sal_uInt16 i
= nStart
; i
< mpBorders
.size() - 1; ++i
)
3573 long lWidth
= mpBorders
[i
].nPos
- lOldPos
;
3575 if(lWidth
< lMinSpace
)
3577 lOldPos
= mpBorders
[i
].nPos
+ mpBorders
[i
].nWidth
;
3578 lFences
+= mpBorders
[i
].nWidth
;
3580 long lWidth
= GetMargin2() - lOldPos
;
3582 if(lWidth
< lMinSpace
)
3588 if(nCol
== USHRT_MAX
) //CalcMinMax for LeftMargin
3590 lOldPos
= GetMargin1();
3594 lOldPos
= mpBorders
[nCol
].nPos
;
3596 lColumns
= GetMargin2()-lOldPos
;
3599 while(nActCol
< mpBorders
.size() || nActCol
== USHRT_MAX
)
3602 if(nActCol
== USHRT_MAX
)
3605 while(!(*mpColumnItem
.get())[nRight
].bVisible
)
3612 nRight
= GetActRightColumn(false, nActCol
);
3616 if(nRight
!= USHRT_MAX
)
3618 lWidth
= mpBorders
[nRight
].nPos
- lOldPos
;
3619 lOldPos
= mpBorders
[nRight
].nPos
;
3623 lWidth
=GetMargin2() - lOldPos
;
3626 if(lWidth
< lMinSpace
)
3628 if(nActCol
== USHRT_MAX
)
3633 _nMaxRight
-= (long)(lFences
+ lMinFrame
/ (float) lMinSpace
* lColumns
);
3638 if(mpColumnItem
->IsTable())
3640 sal_uInt16 nVisCols
= 0;
3641 for(sal_uInt16 i
= GetActRightColumn(false, nCol
); i
< mpBorders
.size();)
3643 if((*mpColumnItem
.get())[i
].bVisible
)
3645 i
= GetActRightColumn(false, i
);
3647 return GetMargin2() - GetMargin1() - (nVisCols
+ 1) * lMinFrame
;
3652 for(sal_uInt16 i
= nCol
; i
< mpBorders
.size() - 1; i
++)
3654 lWidth
+= lMinFrame
+ mpBorders
[i
].nWidth
;
3656 return GetMargin2() - GetMargin1() - lWidth
;
3661 // Tab stops relative to indent (#i24363#)
3662 void SvxRuler::SetTabsRelativeToIndent( bool bRel
)
3664 mpRulerImpl
->bIsTabsRelativeToIndent
= bRel
;
3667 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */