Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <string.h>
21 : #include <limits.h>
22 : #include <tools/shl.hxx>
23 : #include <vcl/image.hxx>
24 : #include <svl/eitem.hxx>
25 : #include <svl/rectitem.hxx>
26 : #include <sfx2/dispatch.hxx>
27 :
28 : #include <svl/smplhint.hxx>
29 :
30 : #include <svx/dialogs.hrc>
31 : #include <svx/dialmgr.hxx>
32 : #include <svx/ruler.hxx>
33 : #include "rlrcitem.hxx"
34 : #include "svx/rulritem.hxx"
35 : #include <editeng/tstpitem.hxx>
36 : #include <editeng/lrspitem.hxx>
37 : #include "editeng/protitem.hxx"
38 : #include <vcl/svapp.hxx>
39 : #ifndef RULER_TAB_RTL
40 : #define RULER_TAB_RTL ((sal_uInt16)0x0010)
41 : #endif
42 :
43 : // STATIC DATA -----------------------------------------------------------
44 :
45 : #define CTRL_ITEM_COUNT 14
46 : #define GAP 10
47 : #define OBJECT_BORDER_COUNT 4
48 : #define TAB_GAP 1
49 : #define INDENT_GAP 2
50 : #define INDENT_FIRST_LINE 4
51 : #define INDENT_LEFT_MARGIN 5
52 : #define INDENT_RIGHT_MARGIN 6
53 : #define INDENT_LEFT_BORDER 2
54 : #define INDENT_RIGHT_BORDER 3
55 : #define INDENT_COUNT 5 //without the first two old values
56 :
57 : #define PIXEL_H_ADJUST( l1, l2 ) PixelHAdjust(l1,l2)
58 :
59 : #ifdef DEBUGLIN
60 :
61 : inline long ToMM(Window *pWin, long lVal)
62 : {
63 : return pWin->PixelToLogic(Size(lVal, 0), MapMode(MAP_MM)).Width();
64 : }
65 :
66 : void Debug_Impl(Window *pWin, SvxColumnItem& rColItem)
67 : {
68 : String aTmp("Aktuell: ");
69 : aTmp += rColItem.GetActColumn();
70 : aTmp += " ColLeft: ";
71 : aTmp += String(ToMM(pWin, rColItem.GetLeft()));
72 : aTmp += " ColRight: ";
73 : aTmp += String(ToMM(pWin, rColItem.GetRight()));
74 : for(sal_uInt16 i = 0; i < rColItem.Count(); ++i) {
75 : aTmp += " Start: ";
76 : aTmp += String(ToMM(pWin, rColItem[i].nStart));
77 : aTmp += " End: ";
78 : aTmp += String(ToMM(pWin, rColItem[i].nEnd));
79 : }
80 :
81 : InfoBox(0, aTmp).Execute();
82 : }
83 :
84 : void Debug_Impl(Window *pWin, const SvxLongLRSpaceItem& rLRSpace)
85 : {
86 : String aTmp("Left: ");
87 : aTmp += pWin->PixelToLogic(Size(rLRSpace.GetLeft(), 0), MapMode(MAP_MM)).Width();
88 : aTmp += " Right: ";
89 : aTmp +=pWin->PixelToLogic(Size(rLRSpace.GetRight(), 0), MapMode(MAP_MM)).Width();
90 : InfoBox(0, aTmp).Execute();
91 : }
92 :
93 : void Debug_Impl(Window *pWin, const SvxLongULSpaceItem& rULSpace)
94 : {
95 : String aTmp("Upper: ");
96 : aTmp += pWin->PixelToLogic(Size(rULSpace.GetUpper(), 0), MapMode(MAP_MM)).Width();
97 : aTmp += " Lower: ";
98 : aTmp += pWin->PixelToLogic(Size(rULSpace.GetLower(), 0), MapMode(MAP_MM)).Width();
99 :
100 : InfoBox(0, aTmp).Execute();
101 : }
102 :
103 : void DebugTabStops_Impl(const SvxTabStopItem& rTabs)
104 : {
105 : String aTmp("Tabs: ");
106 :
107 : // Delete Def Tabs
108 : for(sal_uInt16 i = 0; i < rTabs.Count(); ++i)
109 : {
110 : aTmp += String(rTabs[i].GetTabPos() / 56);
111 : aTmp += " : ";
112 : }
113 : InfoBox(0, aTmp).Execute();
114 : }
115 :
116 : void DebugParaMargin_Impl(const SvxLRSpaceItem& rLRSpace)
117 : {
118 : String aTmp("ParaLeft: ");
119 : aTmp += rLRSpace.GetTxtLeft() / 56;
120 : aTmp += " ParaRight: ";
121 : aTmp += rLRSpace.GetRight() / 56;
122 : aTmp += " FLI: ";
123 : aTmp += rLRSpace.GetTxtFirstLineOfst() / 56;
124 : InfoBox(0, aTmp).Execute();
125 : }
126 :
127 : #endif // DEBUGLIN
128 : #ifdef DEBUG_RULER
129 : #include <vcl/lstbox.hxx>
130 : class RulerDebugWindow : public Window
131 : {
132 : ListBox aBox;
133 : public:
134 : RulerDebugWindow(Window* pParent) :
135 : Window(pParent, WB_BORDER|WB_SIZEMOVE|WB_DIALOGCONTROL|WB_CLIPCHILDREN|WB_SYSTEMWINDOW),
136 : aBox(this, WB_BORDER)
137 : {
138 : Size aOutput(200, 400);
139 : SetOutputSizePixel(aOutput);
140 : aBox.SetSizePixel(aOutput);
141 : aBox.Show();
142 : Show();
143 : Size aParentSize(pParent->GetOutputSizePixel());
144 : Size aOwnSize(GetSizePixel());
145 : aParentSize.Width() -= aOwnSize.Width();
146 : aParentSize.Height() -= aOwnSize.Height();
147 : SetPosPixel(Point(aParentSize.Width(), aParentSize.Height()));
148 : }
149 : ~RulerDebugWindow();
150 :
151 : ListBox& GetLBox() {return aBox;}
152 : static void AddDebugText(const sal_Char* pDescription, const String& rText );
153 : };
154 : static RulerDebugWindow* pDebugWindow = 0;
155 :
156 : RulerDebugWindow::~RulerDebugWindow()
157 : {
158 : pDebugWindow = 0;
159 : }
160 : void RulerDebugWindow::AddDebugText(const sal_Char* pDescription, const String& rText )
161 : {
162 : if(!pDebugWindow)
163 : {
164 : Window* pParent = Application::GetFocusWindow();
165 : while(pParent->GetParent())
166 : pParent = pParent->GetParent();
167 : pDebugWindow = new RulerDebugWindow(pParent);
168 : }
169 : OUString sContent( OUString::createFromAscii(pDescription) );
170 : sContent += rText;
171 : sal_uInt16 nPos = pDebugWindow->GetLBox().InsertEntry(sContent);
172 : pDebugWindow->GetLBox().SelectEntryPos(nPos);
173 : pDebugWindow->GrabFocus();
174 : }
175 :
176 : #define ADD_DEBUG_TEXT(cDescription, sValue) \
177 : RulerDebugWindow::AddDebugText(cDescription, sValue);
178 :
179 : #define REMOVE_DEBUG_WINDOW \
180 : delete pDebugWindow; \
181 : pDebugWindow = 0;
182 :
183 : #else
184 : #define ADD_DEBUG_TEXT(cDescription, sValue)
185 : #define REMOVE_DEBUG_WINDOW
186 : #endif
187 :
188 : struct SvxRuler_Impl {
189 : sal_uInt16 *pPercBuf;
190 : sal_uInt16 *pBlockBuf;
191 : sal_uInt16 nPercSize;
192 : long nTotalDist;
193 : long lOldWinPos;
194 : long lMaxLeftLogic;
195 : long lMaxRightLogic;
196 : long lLastLMargin;
197 : long lLastRMargin;
198 : SvxProtectItem aProtectItem;
199 : SfxBoolItem* pTextRTLItem;
200 : sal_uInt16 nControlerItems;
201 : sal_uInt16 nIdx;
202 : sal_uInt16 nColLeftPix, nColRightPix; // Pixel values for left / right edge
203 : // For columns; buffered to prevent
204 : // recalculation errors
205 : // May be has to be widen for future values
206 : sal_Bool bIsTableRows : 1; // pColumnItem contains table rows instead of columns
207 : //#i24363# tab stops relative to indent
208 : sal_Bool bIsTabsRelativeToIndent : 1; // Tab stops relative to paragraph indent?
209 1690 : SvxRuler_Impl() :
210 : pPercBuf(0), pBlockBuf(0),
211 : nPercSize(0), nTotalDist(0),
212 : lOldWinPos(0),
213 : lMaxLeftLogic(0), lMaxRightLogic(0),
214 : lLastLMargin(0), lLastRMargin(0),
215 : aProtectItem(SID_RULER_PROTECT),
216 : pTextRTLItem(0), nControlerItems(0),
217 : nIdx(0),
218 : nColLeftPix(0), nColRightPix(0),
219 :
220 : bIsTableRows(sal_False),
221 1690 : bIsTabsRelativeToIndent(sal_True)
222 : {
223 1690 : }
224 1688 : ~SvxRuler_Impl()
225 1688 : {
226 1688 : nPercSize = 0; nTotalDist = 0;
227 1688 : delete[] pPercBuf; delete[] pBlockBuf; pPercBuf = 0;
228 1688 : delete pTextRTLItem;
229 1688 : }
230 : void SetPercSize(sal_uInt16 nSize);
231 :
232 : };
233 :
234 :
235 :
236 0 : void SvxRuler_Impl::SetPercSize(sal_uInt16 nSize)
237 : {
238 0 : if(nSize > nPercSize)
239 : {
240 0 : delete[] pPercBuf;
241 0 : delete[] pBlockBuf;
242 0 : pPercBuf = new sal_uInt16[nPercSize = nSize];
243 0 : pBlockBuf = new sal_uInt16[nPercSize = nSize];
244 : }
245 0 : size_t nSize2 = sizeof(sal_uInt16) * nPercSize;
246 0 : memset(pPercBuf, 0, nSize2);
247 0 : memset(pBlockBuf, 0, nSize2);
248 0 : }
249 :
250 :
251 : // Constructor of the ruler
252 :
253 : // SID_ATTR_ULSPACE, SID_ATTR_LRSPACE
254 : // expects as parameter SvxULSpaceItem for page edge
255 : // (either left/right or top/bottom)
256 : // Ruler: SetMargin1, SetMargin2
257 :
258 : // SID_RULER_PAGE_POS
259 : // expectes as parameter the initial value of the page and page width
260 : // Ruler: SetPagePos
261 :
262 : // SID_ATTR_TABSTOP
263 : // expects: SvxTabStopItem
264 : // Ruler: SetTabs
265 :
266 : // SID_ATTR_PARA_LRSPACE
267 : // left, right paragraph edge in H-ruler
268 : // Ruler: SetIndents
269 :
270 : // SID_RULER_BORDERS
271 : // Table borders, columns
272 : // expects: something like SwTabCols
273 : // Ruler: SetBorders
274 :
275 :
276 1690 : SvxRuler::SvxRuler
277 : (
278 : Window* pParent, // StarView Parent
279 : Window* pWin, // Output window: is used for conversion
280 : // logical units <-> pixels
281 : sal_uInt16 flags, // Display flags, see ruler.hxx
282 : SfxBindings &rBindings, // associated Bindings
283 : WinBits nWinStyle // StarView WinBits
284 : )
285 : : Ruler(pParent, nWinStyle),
286 1690 : pCtrlItem(new SvxRulerItem *[CTRL_ITEM_COUNT]),
287 : pLRSpaceItem(0),
288 : pMinMaxItem(0),
289 : pULSpaceItem(0),
290 : pTabStopItem(0),
291 : pParaItem(0),
292 : pParaBorderItem(0),
293 : pPagePosItem(0),
294 : pColumnItem(0),
295 : pObjectItem(0),
296 : pEditWin(pWin),
297 1690 : pRuler_Imp(new SvxRuler_Impl),
298 : bAppSetNullOffset(sal_False), // Is the 0-offset of the ruler set by the application?
299 : lLogicNullOffset(0),
300 : lAppNullOffset(LONG_MAX),
301 : lMinFrame(5),
302 : lInitialDragPos(0),
303 : nFlags(flags),
304 : nDragType(NONE),
305 : nDefTabType(RULER_TAB_LEFT),
306 : nTabCount(0),
307 : nTabBufSize(0),
308 : lDefTabDist(50),
309 : lTabPos(-1),
310 : pTabs(0),
311 : pIndents(0),
312 1690 : pBorders(new RulerBorder[1]), // due to one column tables
313 : nBorderCount(0),
314 : pObjectBorders(0),
315 : pBindings(&rBindings),
316 : nDragOffset(0),
317 : nMaxLeft(0),
318 : nMaxRight(0),
319 : bValid(sal_False),
320 : bListening(sal_False),
321 6760 : bActive(sal_True)
322 :
323 : /* [Description]
324 :
325 : Constructor; Initialize data buffer; controller items are created
326 : */
327 : {
328 1690 : memset(pCtrlItem, 0, sizeof(SvxRulerItem *) * CTRL_ITEM_COUNT);
329 :
330 1690 : rBindings.EnterRegistrations();
331 :
332 : // Create Supported Items
333 1690 : sal_uInt16 i = 0;
334 : // Page edges
335 :
336 1690 : pCtrlItem[i++] = new SvxRulerItem(SID_RULER_LR_MIN_MAX, *this, rBindings);
337 1690 : if((nWinStyle & WB_VSCROLL) == WB_VSCROLL)
338 : {
339 845 : bHorz = sal_False;
340 845 : pCtrlItem[i++] = new SvxRulerItem(SID_ATTR_LONG_ULSPACE, *this, rBindings);
341 : }
342 : else
343 : {
344 845 : bHorz = sal_True;
345 845 : pCtrlItem[i++] = new SvxRulerItem(SID_ATTR_LONG_LRSPACE, *this, rBindings);
346 : }
347 :
348 : // Page Position
349 1690 : pCtrlItem[i++] = new SvxRulerItem(SID_RULER_PAGE_POS, *this, rBindings);
350 :
351 1690 : if((nFlags & SVXRULER_SUPPORT_TABS) == SVXRULER_SUPPORT_TABS)
352 : {
353 1638 : sal_uInt16 nTabStopId = bHorz ? SID_ATTR_TABSTOP : SID_ATTR_TABSTOP_VERTICAL;
354 1638 : pCtrlItem[i++] = new SvxRulerItem(nTabStopId, *this, rBindings);
355 1638 : SetExtraType(RULER_EXTRA_TAB, nDefTabType);
356 : }
357 :
358 :
359 1690 : if(0 != (nFlags & (SVXRULER_SUPPORT_PARAGRAPH_MARGINS |SVXRULER_SUPPORT_PARAGRAPH_MARGINS_VERTICAL)))
360 : {
361 1638 : if(bHorz)
362 845 : pCtrlItem[i++] = new SvxRulerItem(SID_ATTR_PARA_LRSPACE, *this, rBindings);
363 : else
364 793 : pCtrlItem[i++] = new SvxRulerItem(SID_ATTR_PARA_LRSPACE_VERTICAL, *this, rBindings);
365 1638 : pIndents = new RulerIndent[5+INDENT_GAP];
366 1638 : memset(pIndents, 0, sizeof(RulerIndent)*(3+INDENT_GAP));
367 1638 : pIndents[0].nStyle = RULER_STYLE_DONTKNOW;
368 1638 : pIndents[1].nStyle = RULER_STYLE_DONTKNOW;
369 1638 : pIndents[INDENT_FIRST_LINE].nStyle = RULER_INDENT_TOP;
370 1638 : pIndents[INDENT_LEFT_MARGIN].nStyle = RULER_INDENT_BOTTOM;
371 1638 : pIndents[INDENT_RIGHT_MARGIN].nStyle = RULER_INDENT_BOTTOM;
372 1638 : pIndents[INDENT_LEFT_BORDER].nStyle = RULER_INDENT_BORDER;
373 1638 : pIndents[INDENT_RIGHT_BORDER].nStyle = RULER_INDENT_BORDER;
374 13104 : for(sal_uInt16 nIn = 0; nIn < 7; nIn++)
375 11466 : pIndents[nIn].nPos = 0;
376 : }
377 :
378 1690 : if((nFlags & SVXRULER_SUPPORT_BORDERS) == SVXRULER_SUPPORT_BORDERS)
379 : {
380 1586 : pCtrlItem[i++] = new SvxRulerItem(bHorz ? SID_RULER_BORDERS : SID_RULER_BORDERS_VERTICAL, *this, rBindings);
381 1586 : pCtrlItem[i++] = new SvxRulerItem(bHorz ? SID_RULER_ROWS : SID_RULER_ROWS_VERTICAL, *this, rBindings);
382 : }
383 :
384 1690 : pCtrlItem[i++] = new SvxRulerItem(SID_RULER_TEXT_RIGHT_TO_LEFT, *this, rBindings);
385 :
386 1690 : if((nFlags & SVXRULER_SUPPORT_OBJECT) == SVXRULER_SUPPORT_OBJECT)
387 : {
388 104 : pCtrlItem[i++] = new SvxRulerItem(SID_RULER_OBJECT, *this, rBindings );
389 104 : pObjectBorders = new RulerBorder[OBJECT_BORDER_COUNT];
390 104 : size_t nSize = sizeof( RulerBorder ) * OBJECT_BORDER_COUNT;
391 104 : memset(pObjectBorders, 0, nSize);
392 520 : for(sal_uInt16 nBorder = 0; nBorder < OBJECT_BORDER_COUNT; ++nBorder)
393 : {
394 416 : pObjectBorders[nBorder].nPos = 0;
395 416 : pObjectBorders[nBorder].nWidth = 0;
396 416 : pObjectBorders[nBorder].nStyle = RULER_BORDER_MOVEABLE;
397 : }
398 : }
399 :
400 1690 : pCtrlItem[i++] = new SvxRulerItem( SID_RULER_PROTECT, *this, rBindings );
401 1690 : pCtrlItem[i++] = new SvxRulerItem(SID_RULER_BORDER_DISTANCE, *this, rBindings);
402 1690 : pRuler_Imp->nControlerItems=i;
403 :
404 1690 : if((nFlags & SVXRULER_SUPPORT_SET_NULLOFFSET) ==
405 : SVXRULER_SUPPORT_SET_NULLOFFSET)
406 52 : SetExtraType(RULER_EXTRA_NULLOFFSET, 0);
407 :
408 1690 : rBindings.LeaveRegistrations();
409 1690 : }
410 :
411 :
412 4168 : SvxRuler::~SvxRuler()
413 :
414 : /* [Description]
415 :
416 : Destructor ruler; release internal buffer
417 : */
418 : {
419 : REMOVE_DEBUG_WINDOW
420 1688 : if(bListening)
421 38 : EndListening(*pBindings);
422 :
423 1688 : pBindings->EnterRegistrations();
424 :
425 18360 : for(sal_uInt16 i = 0; i < CTRL_ITEM_COUNT && pCtrlItem[i]; ++i)
426 16672 : delete pCtrlItem[i];
427 1688 : delete[] pCtrlItem;
428 :
429 1688 : delete pLRSpaceItem;
430 1688 : delete pMinMaxItem;
431 1688 : delete pULSpaceItem;
432 1688 : delete pTabStopItem;
433 1688 : delete pParaItem;
434 1688 : delete pParaBorderItem;
435 1688 : delete pPagePosItem;
436 1688 : delete pColumnItem;
437 1688 : delete pObjectItem;
438 1688 : delete[] pIndents;
439 1688 : delete[] pBorders;
440 1688 : delete[] pObjectBorders;
441 1688 : delete[] pTabs;
442 1688 : delete pRuler_Imp;
443 :
444 1688 : pBindings->LeaveRegistrations();
445 2480 : }
446 :
447 : /* [Description]
448 :
449 : Internal conversion routines
450 : */
451 :
452 3412 : long SvxRuler::ConvertHPosPixel(long nVal) const
453 : {
454 3412 : return pEditWin->LogicToPixel(Size(nVal, 0)).Width();
455 : }
456 :
457 728 : long SvxRuler::ConvertVPosPixel(long nVal) const
458 : {
459 728 : return pEditWin->LogicToPixel(Size(0, nVal)).Height();
460 : }
461 :
462 759 : long SvxRuler::ConvertHSizePixel(long nVal) const
463 : {
464 759 : return pEditWin->LogicToPixel(Size(nVal, 0)).Width();
465 : }
466 :
467 93 : long SvxRuler::ConvertVSizePixel(long nVal) const
468 : {
469 93 : return pEditWin->LogicToPixel(Size(0, nVal)).Height();
470 : }
471 :
472 9 : long SvxRuler::ConvertPosPixel(long nVal) const
473 : {
474 9 : return bHorz ? ConvertHPosPixel(nVal): ConvertVPosPixel(nVal);
475 : }
476 :
477 852 : long SvxRuler::ConvertSizePixel(long nVal) const
478 : {
479 852 : return bHorz? ConvertHSizePixel(nVal): ConvertVSizePixel(nVal);
480 : }
481 :
482 :
483 0 : inline long SvxRuler::ConvertHPosLogic(long nVal) const
484 : {
485 0 : return pEditWin->PixelToLogic(Size(nVal, 0)).Width();
486 : }
487 :
488 0 : inline long SvxRuler::ConvertVPosLogic(long nVal) const
489 : {
490 0 : return pEditWin->PixelToLogic(Size(0, nVal)).Height();
491 : }
492 :
493 0 : inline long SvxRuler::ConvertHSizeLogic(long nVal) const
494 : {
495 0 : return pEditWin->PixelToLogic(Size(nVal, 0)).Width();
496 : }
497 :
498 0 : inline long SvxRuler::ConvertVSizeLogic(long nVal) const
499 : {
500 0 : return pEditWin->PixelToLogic(Size(0, nVal)).Height();
501 : }
502 :
503 0 : inline long SvxRuler::ConvertPosLogic(long nVal) const
504 : {
505 0 : return bHorz? ConvertHPosLogic(nVal): ConvertVPosLogic(nVal);
506 : }
507 :
508 0 : inline long SvxRuler::ConvertSizeLogic(long nVal) const
509 : {
510 0 : return bHorz? ConvertHSizeLogic(nVal): ConvertVSizeLogic(nVal);
511 : }
512 :
513 0 : long SvxRuler::PixelHAdjust(long nVal, long nValOld) const
514 : {
515 0 : if(ConvertHSizePixel(nVal)!=ConvertHSizePixel(nValOld))
516 0 : return nVal;
517 : else
518 0 : return nValOld;
519 : }
520 :
521 0 : long SvxRuler::PixelVAdjust(long nVal, long nValOld) const
522 : {
523 0 : if(ConvertVSizePixel(nVal)!=ConvertVSizePixel(nValOld))
524 0 : return nVal;
525 : else
526 0 : return nValOld;
527 : }
528 :
529 0 : long SvxRuler::PixelAdjust(long nVal, long nValOld) const
530 : {
531 0 : if(ConvertSizePixel(nVal)!=ConvertSizePixel(nValOld))
532 0 : return nVal;
533 : else
534 0 : return nValOld;
535 : }
536 :
537 :
538 0 : inline sal_uInt16 SvxRuler::GetObjectBordersOff(sal_uInt16 nIdx) const
539 : {
540 0 : return bHorz? nIdx: nIdx + 2;
541 : }
542 :
543 :
544 7867 : void SvxRuler::UpdateFrame()
545 :
546 : /* [Description]
547 :
548 : Update Upper Left edge.
549 : Items are translated into the representation of the ruler.
550 : */
551 :
552 : {
553 : const sal_uInt16 nMarginStyle =
554 7867 : ( pRuler_Imp->aProtectItem.IsSizeProtected() ||
555 7845 : pRuler_Imp->aProtectItem.IsPosProtected() ) ?
556 15712 : 0 : RULER_MARGIN_SIZEABLE;
557 :
558 7867 : if(pLRSpaceItem && pPagePosItem)
559 : {
560 : // if no initialization by default app behavior
561 361 : const long nOld = lLogicNullOffset;
562 : lLogicNullOffset = pColumnItem?
563 361 : pColumnItem->GetLeft(): pLRSpaceItem->GetLeft();
564 361 : if(bAppSetNullOffset)
565 56 : lAppNullOffset += lLogicNullOffset - nOld;
566 361 : if(!bAppSetNullOffset || lAppNullOffset == LONG_MAX)
567 : {
568 305 : Ruler::SetNullOffset(ConvertHPosPixel(lLogicNullOffset));
569 305 : SetMargin1( 0, nMarginStyle );
570 305 : lAppNullOffset = 0;
571 : }
572 : else
573 56 : SetMargin1( ConvertHPosPixel( lAppNullOffset ), nMarginStyle );
574 361 : long lRight = 0;
575 : // evaluate the table right edge of the table
576 361 : if(pColumnItem && pColumnItem->IsTable())
577 1 : lRight = pColumnItem->GetRight();
578 : else
579 360 : lRight = pLRSpaceItem->GetRight();
580 :
581 : sal_uIntPtr aWidth=
582 361 : ConvertHPosPixel(pPagePosItem->GetWidth() - lRight -
583 361 : lLogicNullOffset + lAppNullOffset);
584 361 : SetMargin2( aWidth, nMarginStyle );
585 : }
586 : else
587 7506 : if(pULSpaceItem && pPagePosItem)
588 : {
589 : // relative the upper edge of the surrounding frame
590 361 : const long nOld = lLogicNullOffset;
591 : lLogicNullOffset = pColumnItem?
592 361 : pColumnItem->GetLeft(): pULSpaceItem->GetUpper();
593 361 : if(bAppSetNullOffset)
594 56 : lAppNullOffset += lLogicNullOffset - nOld;
595 361 : if(!bAppSetNullOffset || lAppNullOffset == LONG_MAX) {
596 305 : Ruler::SetNullOffset(ConvertVPosPixel(lLogicNullOffset));
597 305 : lAppNullOffset = 0;
598 305 : SetMargin1( 0, nMarginStyle );
599 : }
600 : else
601 56 : SetMargin1( ConvertVPosPixel( lAppNullOffset ),nMarginStyle );
602 :
603 : long lLower = pColumnItem ?
604 361 : pColumnItem->GetRight() : pULSpaceItem->GetLower();
605 :
606 361 : SetMargin2(ConvertVPosPixel(pPagePosItem->GetHeight() - lLower -
607 : lLogicNullOffset + lAppNullOffset),
608 722 : nMarginStyle );
609 : }
610 : else
611 : {
612 : // turns off the view
613 7145 : SetMargin1();
614 7145 : SetMargin2();
615 : }
616 7867 : if(pColumnItem)
617 : {
618 2 : pRuler_Imp->nColLeftPix = (sal_uInt16) ConvertSizePixel(pColumnItem->GetLeft());
619 2 : pRuler_Imp->nColRightPix = (sal_uInt16) ConvertSizePixel(pColumnItem->GetRight());
620 : }
621 :
622 7867 : }
623 :
624 0 : void SvxRuler::MouseMove( const MouseEvent& rMEvt )
625 : {
626 0 : if( bActive )
627 : {
628 0 : pBindings->Update( SID_RULER_LR_MIN_MAX );
629 0 : pBindings->Update( SID_ATTR_LONG_ULSPACE );
630 0 : pBindings->Update( SID_ATTR_LONG_LRSPACE );
631 0 : pBindings->Update( SID_RULER_PAGE_POS );
632 0 : pBindings->Update( bHorz ? SID_ATTR_TABSTOP : SID_ATTR_TABSTOP_VERTICAL);
633 0 : pBindings->Update( bHorz ? SID_ATTR_PARA_LRSPACE : SID_ATTR_PARA_LRSPACE_VERTICAL);
634 0 : pBindings->Update( bHorz ? SID_RULER_BORDERS : SID_RULER_BORDERS_VERTICAL);
635 0 : pBindings->Update( bHorz ? SID_RULER_ROWS : SID_RULER_ROWS_VERTICAL);
636 0 : pBindings->Update( SID_RULER_OBJECT );
637 0 : pBindings->Update( SID_RULER_PROTECT );
638 : }
639 0 : Ruler::MouseMove( rMEvt );
640 0 : }
641 3720 : void SvxRuler::StartListening_Impl()
642 : {
643 3720 : if(!bListening)
644 : {
645 531 : bValid = sal_False;
646 531 : StartListening(*pBindings);
647 531 : bListening = sal_True;
648 : }
649 3720 : }
650 :
651 258 : void SvxRuler::UpdateFrame
652 : (
653 : const SvxLongLRSpaceItem *pItem // new value LRSpace
654 : )
655 :
656 : /* [Description]
657 :
658 : Store new value LRSpace; delete old ones if possible
659 : */
660 :
661 : {
662 258 : if(bActive)
663 : {
664 258 : delete pLRSpaceItem; pLRSpaceItem = 0;
665 258 : if(pItem)
666 258 : pLRSpaceItem = new SvxLongLRSpaceItem(*pItem);
667 258 : StartListening_Impl();
668 : }
669 258 : }
670 :
671 :
672 514 : void SvxRuler::UpdateFrameMinMax
673 : (
674 : const SfxRectangleItem *pItem // value for MinMax
675 : )
676 :
677 : /* [Description]
678 :
679 : Set new value for MinMax; delete old ones if possible
680 : */
681 :
682 : {
683 514 : if(bActive)
684 : {
685 514 : delete pMinMaxItem; pMinMaxItem = 0;
686 514 : if(pItem)
687 514 : pMinMaxItem = new SfxRectangleItem(*pItem);
688 : }
689 514 : }
690 :
691 :
692 259 : void SvxRuler::UpdateFrame
693 : (
694 : const SvxLongULSpaceItem *pItem // new value
695 : )
696 :
697 : /* [Description]
698 :
699 : Update Right/bottom margin
700 : */
701 :
702 :
703 : {
704 259 : if(bActive && !bHorz)
705 : {
706 259 : delete pULSpaceItem; pULSpaceItem = 0;
707 259 : if(pItem)
708 259 : pULSpaceItem = new SvxLongULSpaceItem(*pItem);
709 259 : StartListening_Impl();
710 : }
711 259 : }
712 :
713 510 : void SvxRuler::Update( const SvxProtectItem* pItem )
714 : {
715 510 : if( pItem ) pRuler_Imp->aProtectItem = *pItem;
716 510 : }
717 :
718 510 : void SvxRuler::UpdateTextRTL(const SfxBoolItem* pItem)
719 : {
720 510 : if(bActive && bHorz)
721 : {
722 255 : delete pRuler_Imp->pTextRTLItem; pRuler_Imp->pTextRTLItem = 0;
723 255 : if(pItem)
724 255 : pRuler_Imp->pTextRTLItem = new SfxBoolItem(*pItem);
725 255 : SetTextRTL(pRuler_Imp->pTextRTLItem && pRuler_Imp->pTextRTLItem->GetValue());
726 255 : StartListening_Impl();
727 : }
728 510 : }
729 :
730 892 : void SvxRuler::Update
731 : (
732 : const SvxColumnItem *pItem, // new value
733 : sal_uInt16 nSID //Slot Id to identify NULL items
734 : )
735 :
736 : /* [Description]
737 :
738 : Set new value for column view
739 : */
740 :
741 : {
742 892 : if(bActive)
743 : {
744 892 : if(pItem)
745 : {
746 2 : delete pColumnItem; pColumnItem = 0;
747 2 : pRuler_Imp->bIsTableRows = (pItem->Which() == SID_RULER_ROWS || pItem->Which() == SID_RULER_ROWS_VERTICAL);
748 2 : pColumnItem = new SvxColumnItem(*pItem);
749 2 : if(!bHorz && !pRuler_Imp->bIsTableRows)
750 0 : pColumnItem->SetWhich(SID_RULER_BORDERS_VERTICAL);
751 : }
752 890 : else if(pColumnItem && pColumnItem->Which() == nSID)
753 : //there are two groups of column items table/frame columns and table rows
754 : //both can occur in vertical or horizontal mode
755 : //the horizontal ruler handles the SID_RULER_BORDERS and SID_RULER_ROWS_VERTICAL
756 : //and the vertical handles SID_RULER_BORDERS_VERTICAL and SID_RULER_ROWS
757 : //if pColumnItem is already set with one of the ids then a NULL pItem argument
758 : //must not delete it
759 : {
760 0 : delete pColumnItem; pColumnItem = 0;
761 0 : pRuler_Imp->bIsTableRows = sal_False;
762 : }
763 892 : StartListening_Impl();
764 : }
765 892 : }
766 :
767 :
768 7070 : void SvxRuler::UpdateColumns()
769 :
770 : /* [Description]
771 :
772 : Update column view
773 : */
774 : {
775 7070 : if(pColumnItem && pColumnItem->Count() > 1)
776 : {
777 2 : if( nBorderCount < pColumnItem->Count())
778 : {
779 2 : delete[] pBorders;
780 2 : nBorderCount = pColumnItem->Count();
781 2 : pBorders = new RulerBorder[nBorderCount];
782 : }
783 2 : sal_uInt16 _nFlags = RULER_BORDER_VARIABLE;
784 : sal_Bool bProtectColumns =
785 4 : pRuler_Imp->aProtectItem.IsSizeProtected() ||
786 4 : pRuler_Imp->aProtectItem.IsPosProtected();
787 2 : if( !bProtectColumns )
788 2 : _nFlags |= RULER_BORDER_MOVEABLE;
789 2 : if( pColumnItem->IsTable() )
790 2 : _nFlags |= RULER_BORDER_TABLE;
791 : else
792 0 : if ( !bProtectColumns )
793 0 : _nFlags |= RULER_BORDER_SIZEABLE;
794 :
795 2 : sal_uInt16 nBorders = pColumnItem->Count();
796 2 : if(!pRuler_Imp->bIsTableRows)
797 1 : --nBorders;
798 5 : for(sal_uInt16 i = 0; i < nBorders; ++i)
799 : {
800 3 : pBorders[i].nStyle = _nFlags;
801 3 : if(!(*pColumnItem)[i].bVisible)
802 1 : pBorders[i].nStyle |= RULER_STYLE_INVISIBLE;
803 3 : pBorders[i].nPos =
804 3 : ConvertPosPixel((*pColumnItem)[i].nEnd + lAppNullOffset);
805 3 : if(pColumnItem->Count() == i + 1)
806 : {
807 : //with table rows the end of the table is contained in the
808 : //column item but it has no width!
809 1 : pBorders[i].nWidth = 0;
810 : }
811 : else
812 : {
813 2 : pBorders[i].nWidth =
814 2 : ConvertSizePixel((*pColumnItem)[i+1].nStart -
815 2 : (*pColumnItem)[i].nEnd);
816 : }
817 3 : pBorders[i].nMinPos =
818 3 : ConvertPosPixel((*pColumnItem)[i].nEndMin + lAppNullOffset);
819 3 : pBorders[i].nMaxPos =
820 3 : ConvertPosPixel((*pColumnItem)[i].nEndMax + lAppNullOffset);
821 : }
822 2 : SetBorders(pColumnItem->Count()-1, pBorders);
823 : }
824 : else
825 : {
826 7068 : SetBorders();
827 : }
828 7070 : }
829 :
830 :
831 797 : void SvxRuler::UpdateObject()
832 :
833 : /* [Description]
834 :
835 : Update view of object representation
836 : */
837 :
838 : {
839 797 : if(pObjectItem)
840 : {
841 : DBG_ASSERT(pObjectBorders, "no Buffer");
842 : // !! to the page margin
843 0 : long nMargin = pLRSpaceItem? pLRSpaceItem->GetLeft(): 0;
844 0 : pObjectBorders[0].nPos =
845 0 : ConvertPosPixel(pObjectItem->GetStartX() -
846 0 : nMargin + lAppNullOffset);
847 0 : pObjectBorders[1].nPos =
848 0 : ConvertPosPixel(pObjectItem->GetEndX() - nMargin + lAppNullOffset);
849 0 : nMargin = pULSpaceItem? pULSpaceItem->GetUpper(): 0;
850 0 : pObjectBorders[2].nPos =
851 0 : ConvertPosPixel(pObjectItem->GetStartY() -
852 0 : nMargin + lAppNullOffset);
853 0 : pObjectBorders[3].nPos =
854 0 : ConvertPosPixel(pObjectItem->GetEndY() - nMargin + lAppNullOffset);
855 :
856 0 : const sal_uInt16 nOff = GetObjectBordersOff(0);
857 0 : SetBorders(2, pObjectBorders + nOff);
858 : }
859 : else
860 : {
861 797 : SetBorders();
862 : }
863 797 : }
864 :
865 :
866 7469 : void SvxRuler::UpdatePara()
867 :
868 : /* [Description]
869 :
870 : Update the view for paragraph indents:
871 : Left margin, first line indent, right margin paragraph update
872 : pIndents[0] = Buffer for old intent
873 : pIndents[1] = Buffer for old intent
874 : pIndents[INDENT_FIRST_LINE] = First line indent
875 : pIndents[3] = left margin
876 : pIndents[4] = right margin
877 : pIndents[5] = left border distance
878 : pIndents[6] = right border distance
879 :
880 : */
881 :
882 : {
883 : // Dependence on PagePosItem
884 7469 : if(pParaItem && pPagePosItem && !pObjectItem)
885 : {
886 360 : sal_Bool bRTLText = pRuler_Imp->pTextRTLItem && pRuler_Imp->pTextRTLItem->GetValue();
887 : // First-line indent is negative to the left paragraph margin
888 360 : long nLeftFrameMargin = GetLeftFrameMargin();
889 360 : long nRightFrameMargin = GetRightFrameMargin();
890 360 : if(bRTLText)
891 0 : pIndents[INDENT_FIRST_LINE].nPos =
892 : ConvertHPosPixel(
893 0 : nRightFrameMargin -
894 0 : pParaItem->GetTxtLeft() -
895 0 : pParaItem->GetTxtFirstLineOfst() + lAppNullOffset );
896 : else
897 360 : pIndents[INDENT_FIRST_LINE].nPos =
898 : ConvertHPosPixel(
899 360 : nLeftFrameMargin +
900 720 : pParaItem->GetTxtLeft() +
901 360 : pParaItem->GetTxtFirstLineOfst() +
902 360 : lAppNullOffset);
903 360 : if( pParaItem->IsAutoFirst() )
904 0 : pIndents[INDENT_FIRST_LINE].nStyle |= RULER_STYLE_INVISIBLE;
905 : else
906 360 : pIndents[INDENT_FIRST_LINE].nStyle &= ~RULER_STYLE_INVISIBLE;
907 :
908 360 : if(bRTLText)
909 : {
910 : // left margin
911 0 : pIndents[INDENT_LEFT_MARGIN].nPos =
912 : ConvertHPosPixel(
913 0 : nRightFrameMargin -
914 0 : pParaItem->GetTxtLeft() + lAppNullOffset);
915 : // right margin
916 0 : pIndents[INDENT_RIGHT_MARGIN].nPos =
917 : ConvertHPosPixel(
918 0 : nLeftFrameMargin +
919 0 : pParaItem->GetRight() + lAppNullOffset);
920 : }
921 : else
922 : {
923 : // left margin
924 360 : pIndents[INDENT_LEFT_MARGIN].nPos =
925 : ConvertHPosPixel(
926 360 : nLeftFrameMargin +
927 720 : pParaItem->GetTxtLeft() + lAppNullOffset);
928 : // right margin, always negative to the right edge of the surrounding frames
929 360 : pIndents[INDENT_RIGHT_MARGIN].nPos =
930 : ConvertHPosPixel(
931 360 : nRightFrameMargin -
932 720 : pParaItem->GetRight() + lAppNullOffset);
933 : }
934 360 : if(pParaBorderItem)
935 : {
936 304 : pIndents[INDENT_LEFT_BORDER].nPos =
937 304 : ConvertHPosPixel( nLeftFrameMargin + lAppNullOffset);
938 304 : pIndents[INDENT_RIGHT_BORDER].nPos =
939 304 : ConvertHPosPixel(nRightFrameMargin - lAppNullOffset);
940 304 : pIndents[INDENT_LEFT_BORDER].nStyle = pIndents[INDENT_RIGHT_BORDER].nStyle &= ~RULER_STYLE_INVISIBLE;
941 : }
942 : else
943 56 : pIndents[INDENT_LEFT_BORDER].nStyle = pIndents[INDENT_RIGHT_BORDER].nStyle |= RULER_STYLE_INVISIBLE;
944 :
945 360 : SetIndents(INDENT_COUNT, pIndents+INDENT_GAP);
946 : }
947 : else
948 : {
949 7109 : if(pIndents)
950 : {
951 7109 : pIndents[INDENT_FIRST_LINE].nPos =
952 7109 : pIndents[INDENT_LEFT_MARGIN].nPos =
953 7109 : pIndents[INDENT_RIGHT_MARGIN].nPos = 0;
954 : }
955 7109 : SetIndents(); // turn off
956 : }
957 7469 : }
958 :
959 :
960 476 : void SvxRuler::UpdatePara
961 : (
962 : const SvxLRSpaceItem *pItem // new value of paragraph indents
963 : )
964 :
965 : /* [Description]
966 :
967 : Store new value of paragraph indents
968 : */
969 :
970 : {
971 476 : if(bActive)
972 : {
973 476 : delete pParaItem; pParaItem = 0;
974 476 : if(pItem)
975 253 : pParaItem = new SvxLRSpaceItem(*pItem);
976 476 : StartListening_Impl();
977 : }
978 476 : }
979 510 : void SvxRuler::UpdateParaBorder(const SvxLRSpaceItem * pItem )
980 :
981 : /* [Description]
982 :
983 : Border distance
984 : */
985 :
986 : {
987 510 : if(bActive)
988 : {
989 510 : delete pParaBorderItem; pParaBorderItem = 0;
990 510 : if(pItem)
991 446 : pParaBorderItem = new SvxLRSpaceItem(*pItem);
992 510 : StartListening_Impl();
993 : }
994 510 : }
995 :
996 :
997 7867 : void SvxRuler::UpdatePage()
998 :
999 : /* [Description]
1000 :
1001 : Update view of position and width of page
1002 : */
1003 :
1004 : {
1005 7867 : if(pPagePosItem)
1006 : {
1007 : // all objects are automatically adjusted
1008 722 : if(bHorz)
1009 : SetPagePos(
1010 722 : pEditWin->LogicToPixel(pPagePosItem->GetPos()).X(),
1011 722 : pEditWin->LogicToPixel(Size(pPagePosItem->GetWidth(),0)).
1012 1083 : Width());
1013 : else
1014 : SetPagePos(
1015 722 : pEditWin->LogicToPixel(pPagePosItem->GetPos()).Y(),
1016 722 : pEditWin->LogicToPixel(Size(0, pPagePosItem->GetHeight())).
1017 1083 : Height());
1018 722 : if(bAppSetNullOffset)
1019 112 : SetNullOffset(ConvertSizePixel(-lAppNullOffset + lLogicNullOffset));
1020 : }
1021 : else
1022 7145 : SetPagePos();
1023 :
1024 7867 : long lPos = 0;
1025 7867 : Point aOwnPos = GetPosPixel();
1026 7867 : Point aEdtWinPos = pEditWin->GetPosPixel();
1027 7867 : if( Application::GetSettings().GetLayoutRTL() && bHorz )
1028 : {
1029 : //#i73321# in RTL the window and the ruler is not mirrored but the
1030 : // influence of the vertical ruler is inverted
1031 0 : Size aOwnSize = GetSizePixel();
1032 0 : Size aEdtWinSize = pEditWin->GetSizePixel();
1033 0 : lPos = aOwnSize.Width() - aEdtWinSize.Width();
1034 0 : lPos -= (aEdtWinPos - aOwnPos).X();
1035 : }
1036 : else
1037 : {
1038 7867 : Point aPos(aEdtWinPos - aOwnPos);
1039 7867 : lPos= bHorz ? aPos.X() : aPos.Y();
1040 : }
1041 :
1042 : // Unfortunately, we get the offset of the edit window to the ruler never
1043 : // through a status message. So we set it ourselves if necessary.
1044 7867 : if(lPos!=pRuler_Imp->lOldWinPos)
1045 : {
1046 826 : pRuler_Imp->lOldWinPos=lPos;
1047 826 : SetWinPos(lPos);
1048 : }
1049 7867 : }
1050 :
1051 :
1052 528 : void SvxRuler::Update
1053 : (
1054 : const SvxPagePosSizeItem *pItem // new value of page attributes
1055 : )
1056 :
1057 : /* [Description]
1058 :
1059 : Store new value of page attributes
1060 : */
1061 :
1062 : {
1063 528 : if(bActive)
1064 : {
1065 528 : delete pPagePosItem; pPagePosItem = 0;
1066 528 : if(pItem)
1067 528 : pPagePosItem = new SvxPagePosSizeItem(*pItem);
1068 528 : StartListening_Impl();
1069 : }
1070 528 : }
1071 :
1072 :
1073 : //
1074 :
1075 574 : void SvxRuler::SetDefTabDist
1076 : (
1077 : long l // New distance for DefaultTabs in App-Metrics
1078 : )
1079 :
1080 : /* [Description]
1081 :
1082 : New distance is set for DefaultTabs
1083 : */
1084 :
1085 : {
1086 :
1087 574 : lDefTabDist = l;
1088 574 : UpdateTabs();
1089 574 : }
1090 :
1091 :
1092 0 : sal_uInt16 ToSvTab_Impl(SvxTabAdjust eAdj)
1093 :
1094 : /* [Description]
1095 :
1096 : Internal convertion routine between SV-Tab.-Enum and Svx
1097 : */
1098 :
1099 : {
1100 0 : switch(eAdj) {
1101 0 : case SVX_TAB_ADJUST_LEFT: return RULER_TAB_LEFT;
1102 0 : case SVX_TAB_ADJUST_RIGHT: return RULER_TAB_RIGHT;
1103 0 : case SVX_TAB_ADJUST_DECIMAL: return RULER_TAB_DECIMAL;
1104 0 : case SVX_TAB_ADJUST_CENTER: return RULER_TAB_CENTER;
1105 0 : case SVX_TAB_ADJUST_DEFAULT: return RULER_TAB_DEFAULT;
1106 : default: ;//prevent warning
1107 : }
1108 0 : return 0;
1109 : }
1110 :
1111 :
1112 0 : SvxTabAdjust ToAttrTab_Impl(sal_uInt16 eAdj)
1113 : {
1114 0 : switch(eAdj) {
1115 0 : case RULER_TAB_LEFT: return SVX_TAB_ADJUST_LEFT ;
1116 0 : case RULER_TAB_RIGHT: return SVX_TAB_ADJUST_RIGHT ;
1117 0 : case RULER_TAB_DECIMAL: return SVX_TAB_ADJUST_DECIMAL ;
1118 0 : case RULER_TAB_CENTER: return SVX_TAB_ADJUST_CENTER ;
1119 0 : case RULER_TAB_DEFAULT: return SVX_TAB_ADJUST_DEFAULT ;
1120 : }
1121 0 : return SVX_TAB_ADJUST_LEFT;
1122 : }
1123 :
1124 :
1125 8043 : void SvxRuler::UpdateTabs()
1126 :
1127 : /* [Description]
1128 :
1129 : Update of Tabs
1130 : */
1131 :
1132 : {
1133 8043 : if(IsDrag())
1134 8043 : return;
1135 8043 : if(pPagePosItem && pParaItem && pTabStopItem && !pObjectItem)
1136 : {
1137 : // buffer for DefaultTabStop
1138 : // Distance last Tab <-> Right paragraph margin / DefaultTabDist
1139 333 : sal_Bool bRTL = pRuler_Imp->pTextRTLItem && pRuler_Imp->pTextRTLItem->GetValue();
1140 333 : long nLeftFrameMargin = GetLeftFrameMargin();
1141 333 : long nRightFrameMargin = GetRightFrameMargin();
1142 :
1143 : //#i24363# tab stops relative to indent
1144 333 : const long nParaItemTxtLeft = pParaItem->GetTxtLeft();
1145 :
1146 333 : const long lParaIndent = nLeftFrameMargin + nParaItemTxtLeft;
1147 :
1148 : const long lLastTab =
1149 333 : pTabStopItem->Count()?
1150 333 : ConvertHPosPixel((*pTabStopItem)[pTabStopItem->Count()-1].GetTabPos()): 0;
1151 : const long lPosPixel =
1152 333 : ConvertHPosPixel(lParaIndent) + lLastTab;
1153 : const long lRightIndent =
1154 333 : ConvertHPosPixel(nRightFrameMargin - pParaItem->GetRight());
1155 333 : long nDefTabDist = ConvertHPosPixel(lDefTabDist);
1156 333 : if( !nDefTabDist )
1157 0 : nDefTabDist = 1;
1158 333 : const sal_uInt16 nDefTabBuf = lPosPixel > lRightIndent ||
1159 : lLastTab > lRightIndent
1160 : ? 0
1161 666 : : (sal_uInt16)( (lRightIndent - lPosPixel) / nDefTabDist );
1162 :
1163 333 : if(pTabStopItem->Count() + TAB_GAP + nDefTabBuf > nTabBufSize)
1164 : {
1165 205 : delete[] pTabs;
1166 : // 10 (GAP) in stock
1167 205 : nTabBufSize = pTabStopItem->Count() + TAB_GAP + nDefTabBuf + GAP;
1168 205 : pTabs = new RulerTab[nTabBufSize];
1169 : }
1170 :
1171 333 : nTabCount = 0;
1172 : sal_uInt16 j;
1173 : //#i24363# tab stops relative to indent
1174 333 : const long lRightPixMargin = ConvertSizePixel(nRightFrameMargin - nParaItemTxtLeft );
1175 333 : const long lParaIndentPix = ConvertSizePixel(lParaIndent);
1176 333 : for(j = 0; j < pTabStopItem->Count(); ++j)
1177 : {
1178 0 : const SvxTabStop *pTab = &(*pTabStopItem)[j];
1179 0 : pTabs[nTabCount+TAB_GAP].nPos =
1180 : ConvertHPosPixel(
1181 0 : (pRuler_Imp->bIsTabsRelativeToIndent ? lParaIndent : 0 ) + pTab->GetTabPos() + lAppNullOffset);
1182 0 : if(bRTL)
1183 : {
1184 0 : pTabs[nTabCount+TAB_GAP].nPos = lParaIndentPix + lRightPixMargin - pTabs[nTabCount+TAB_GAP].nPos;
1185 : }
1186 0 : pTabs[nTabCount+TAB_GAP].nStyle = ToSvTab_Impl(pTab->GetAdjustment());
1187 0 : ++nTabCount;
1188 : }
1189 333 : if(!pTabStopItem->Count())
1190 333 : pTabs[0].nPos = bRTL ? lRightPixMargin : lParaIndentPix;
1191 :
1192 : // fill the rest with default Tabs
1193 333 : if(bRTL)
1194 : {
1195 0 : for(j = 0; j < nDefTabBuf; ++j)
1196 : {
1197 0 : pTabs[nTabCount + TAB_GAP].nPos =
1198 0 : pTabs[nTabCount].nPos - nDefTabDist;
1199 :
1200 0 : if(j == 0 )
1201 : pTabs[nTabCount + TAB_GAP].nPos -=
1202 0 : ((pTabs[nTabCount + TAB_GAP].nPos - lRightPixMargin)
1203 0 : % nDefTabDist );
1204 0 : if(pTabs[nTabCount+TAB_GAP].nPos <= lParaIndentPix)
1205 0 : break;
1206 0 : pTabs[nTabCount + TAB_GAP].nStyle = RULER_TAB_DEFAULT;
1207 0 : ++nTabCount;
1208 : }
1209 : }
1210 : else
1211 : {
1212 4669 : for(j = 0; j < nDefTabBuf; ++j)
1213 : {
1214 4336 : if( j == 0 )
1215 : {
1216 : //set the first default tab stop
1217 333 : if(pRuler_Imp->bIsTabsRelativeToIndent)
1218 : {
1219 333 : pTabs[nTabCount + TAB_GAP].nPos =
1220 333 : (pTabs[nTabCount].nPos + nDefTabDist);
1221 : pTabs[nTabCount + TAB_GAP].nPos -=
1222 333 : ((pTabs[nTabCount + TAB_GAP].nPos - lParaIndentPix)
1223 666 : % nDefTabDist );
1224 : }
1225 : else
1226 : {
1227 0 : if( pTabs[nTabCount].nPos < 0 )
1228 : {
1229 0 : pTabs[nTabCount + TAB_GAP].nPos = ( pTabs[nTabCount].nPos / nDefTabDist ) * nDefTabDist;
1230 : }
1231 : else
1232 : {
1233 0 : pTabs[nTabCount + TAB_GAP].nPos = ( pTabs[nTabCount].nPos / nDefTabDist + 1 ) * nDefTabDist;
1234 : }
1235 : }
1236 :
1237 : }
1238 : else
1239 : {
1240 : //simply add the default distance to the last position
1241 4003 : pTabs[nTabCount + TAB_GAP].nPos =
1242 4003 : pTabs[nTabCount].nPos + nDefTabDist;
1243 : }
1244 :
1245 4336 : if(pTabs[nTabCount+TAB_GAP].nPos >= lRightIndent)
1246 0 : break;
1247 4336 : pTabs[nTabCount + TAB_GAP].nStyle = RULER_TAB_DEFAULT;
1248 4336 : ++nTabCount;
1249 : }
1250 : }
1251 333 : SetTabs(nTabCount, pTabs+TAB_GAP);
1252 333 : DBG_ASSERT(nTabCount + TAB_GAP <= nTabBufSize, "BufferSize too small");
1253 : }
1254 : else
1255 : {
1256 7710 : SetTabs();
1257 : }
1258 : }
1259 :
1260 :
1261 478 : void SvxRuler::Update
1262 : (
1263 : const SvxTabStopItem *pItem // new value for tabs
1264 : )
1265 :
1266 : /* [Description]
1267 :
1268 : Store new value for tabs; delete old ones if possible
1269 : */
1270 :
1271 : {
1272 478 : if(bActive)
1273 : {
1274 478 : delete pTabStopItem; pTabStopItem = 0;
1275 478 : if(pItem)
1276 : {
1277 222 : pTabStopItem = new SvxTabStopItem(*pItem);
1278 222 : if(!bHorz)
1279 0 : pTabStopItem->SetWhich(SID_ATTR_TABSTOP_VERTICAL);
1280 : }
1281 478 : StartListening_Impl();
1282 : }
1283 478 : }
1284 :
1285 :
1286 64 : void SvxRuler::Update
1287 : (
1288 : const SvxObjectItem *pItem // new value for objects
1289 : )
1290 :
1291 : /* [Description]
1292 :
1293 : Store new value for objects
1294 : */
1295 :
1296 : {
1297 64 : if(bActive)
1298 : {
1299 64 : delete pObjectItem; pObjectItem = 0;
1300 64 : if(pItem)
1301 0 : pObjectItem = new SvxObjectItem(*pItem);
1302 64 : StartListening_Impl();
1303 : }
1304 64 : }
1305 :
1306 :
1307 68 : void SvxRuler::SetNullOffsetLogic
1308 : (
1309 : long lVal // Setting of the logic NullOffsets
1310 : )
1311 : {
1312 68 : lAppNullOffset = lLogicNullOffset - lVal;
1313 68 : bAppSetNullOffset = sal_True;
1314 68 : Ruler::SetNullOffset(ConvertSizePixel(lVal));
1315 68 : Update();
1316 68 : }
1317 :
1318 :
1319 7867 : void SvxRuler::Update()
1320 :
1321 : /* [Description]
1322 :
1323 : Perform update of view
1324 : */
1325 :
1326 : {
1327 7867 : if(IsDrag())
1328 7867 : return;
1329 7867 : UpdatePage();
1330 7867 : UpdateFrame();
1331 7867 : if((nFlags & SVXRULER_SUPPORT_OBJECT) == SVXRULER_SUPPORT_OBJECT)
1332 797 : UpdateObject();
1333 : else
1334 7070 : UpdateColumns();
1335 :
1336 7867 : if(0 != (nFlags & (SVXRULER_SUPPORT_PARAGRAPH_MARGINS |SVXRULER_SUPPORT_PARAGRAPH_MARGINS_VERTICAL)))
1337 7469 : UpdatePara();
1338 7867 : if(0 != (nFlags & SVXRULER_SUPPORT_TABS))
1339 7469 : UpdateTabs();
1340 : }
1341 :
1342 :
1343 7085 : long SvxRuler::GetPageWidth() const
1344 : {
1345 7085 : if ( !pPagePosItem )
1346 6475 : return 0;
1347 610 : return bHorz ? pPagePosItem->GetWidth() : pPagePosItem->GetHeight();
1348 : }
1349 :
1350 :
1351 0 : inline long SvxRuler::GetFrameLeft() const
1352 :
1353 : /* [Description]
1354 :
1355 : Get Left margin in Pixels
1356 : */
1357 :
1358 :
1359 : {
1360 : return bAppSetNullOffset?
1361 0 : GetMargin1() + ConvertSizePixel(lLogicNullOffset):
1362 0 : Ruler::GetNullOffset();
1363 : }
1364 :
1365 : inline void SvxRuler::SetFrameLeft(long l)
1366 :
1367 : /* [Description]
1368 :
1369 : Set Left margin in Pixels
1370 : */
1371 :
1372 : {
1373 : sal_Bool bProtectColumns =
1374 : pRuler_Imp->aProtectItem.IsSizeProtected() ||
1375 : pRuler_Imp->aProtectItem.IsPosProtected();
1376 : if(bAppSetNullOffset)
1377 : SetMargin1(l - ConvertSizePixel(lLogicNullOffset),
1378 : bProtectColumns ? 0 : RULER_MARGIN_SIZEABLE);
1379 : else
1380 : Ruler::SetNullOffset(l);
1381 : }
1382 :
1383 :
1384 0 : long SvxRuler::GetFirstLineIndent() const
1385 :
1386 : /* [Description]
1387 :
1388 : Get First-line indent in pixels
1389 : */
1390 :
1391 : {
1392 0 : return pParaItem? pIndents[INDENT_FIRST_LINE].nPos: GetMargin1();
1393 : }
1394 :
1395 :
1396 0 : long SvxRuler::GetLeftIndent() const
1397 :
1398 : /* [Description]
1399 :
1400 : Get Left paragraph margin in Pixels
1401 : */
1402 :
1403 : {
1404 0 : return pParaItem? pIndents[INDENT_LEFT_MARGIN].nPos: GetMargin1();
1405 : }
1406 :
1407 :
1408 :
1409 0 : long SvxRuler::GetRightIndent() const
1410 :
1411 : /* [Description]
1412 :
1413 : Get Right paragraph margin in Pixels
1414 : */
1415 :
1416 : {
1417 0 : return pParaItem? pIndents[INDENT_RIGHT_MARGIN].nPos: GetMargin2();
1418 : }
1419 :
1420 :
1421 0 : long SvxRuler::GetLogicRightIndent() const
1422 :
1423 : /* [Description]
1424 :
1425 : Get Right paragraph margin in Logic
1426 : */
1427 :
1428 : {
1429 0 : return pParaItem ? GetRightFrameMargin()-pParaItem->GetRight() : GetRightFrameMargin();
1430 : }
1431 :
1432 : // Left margin in App values, is either the margin (= 0) or the left edge of
1433 : // the column that is set in the column attribute as current column.
1434 693 : long SvxRuler::GetLeftFrameMargin() const
1435 : {
1436 : // #126721# for some unknown reason the current column is set to 0xffff
1437 : DBG_ASSERT(!pColumnItem || pColumnItem->GetActColumn() < pColumnItem->Count(),
1438 : "issue #126721# - invalid current column!");
1439 : long nLeft =
1440 3 : pColumnItem && pColumnItem->Count() && pColumnItem->GetActColumn() < pColumnItem->Count() ?
1441 696 : (*pColumnItem)[pColumnItem->GetActColumn()].nStart : 0;
1442 693 : if(pParaBorderItem && (!pColumnItem || pColumnItem->IsTable()))
1443 637 : nLeft += pParaBorderItem->GetLeft();
1444 693 : return nLeft;
1445 : }
1446 :
1447 0 : inline long SvxRuler::GetLeftMin() const
1448 : {
1449 : DBG_ASSERT(pMinMaxItem, "no MinMax value set");
1450 : return pMinMaxItem?
1451 0 : bHorz? pMinMaxItem->GetValue().Left(): pMinMaxItem->GetValue().Top()
1452 0 : : 0;
1453 : }
1454 :
1455 0 : inline long SvxRuler::GetRightMax() const
1456 : {
1457 : DBG_ASSERT(pMinMaxItem, "no MinMax value set");
1458 : return pMinMaxItem?
1459 0 : bHorz? pMinMaxItem->GetValue().Right(): pMinMaxItem->GetValue().Bottom()
1460 0 : : 0;
1461 : }
1462 :
1463 :
1464 693 : long SvxRuler::GetRightFrameMargin() const
1465 :
1466 : /* [Description]
1467 :
1468 : Get right frame margin (in logical units)
1469 : */
1470 :
1471 : {
1472 693 : if(pColumnItem)
1473 : {
1474 3 : if(!IsActLastColumn( sal_True ))
1475 : {
1476 3 : long nRet = (*pColumnItem)[GetActRightColumn( sal_True )].nEnd;
1477 3 : if(pColumnItem->IsTable() && pParaBorderItem)
1478 3 : nRet -= pParaBorderItem->GetRight();
1479 3 : return nRet;
1480 : }
1481 : }
1482 :
1483 690 : long l = lLogicNullOffset;
1484 :
1485 : // If possible deduct right table entry
1486 690 : if(pColumnItem && pColumnItem->IsTable())
1487 0 : l += pColumnItem->GetRight();
1488 690 : else if(bHorz && pLRSpaceItem)
1489 690 : l += pLRSpaceItem->GetRight();
1490 0 : else if(!bHorz && pULSpaceItem)
1491 0 : l += pULSpaceItem->GetLower();
1492 :
1493 1958 : if(pParaBorderItem &&
1494 634 : (!pColumnItem || pColumnItem->IsTable()||IsActLastColumn( sal_True )))
1495 634 : l += pParaBorderItem->GetRight();
1496 :
1497 690 : if(bHorz)
1498 690 : l = pPagePosItem->GetWidth() - l;
1499 : else
1500 0 : l = pPagePosItem->GetHeight() - l;
1501 690 : return l;
1502 : }
1503 :
1504 : #define NEG_FLAG ( (nFlags & SVXRULER_SUPPORT_NEGATIVE_MARGINS) == \
1505 : SVXRULER_SUPPORT_NEGATIVE_MARGINS )
1506 : #define TAB_FLAG ( pColumnItem && pColumnItem->IsTable() )
1507 :
1508 0 : long SvxRuler::GetCorrectedDragPos( sal_Bool bLeft, sal_Bool bRight )
1509 :
1510 : /* [Description]
1511 :
1512 : Corrects the position within the calculated limits. The limit values are in
1513 : pixels relative to the page edge.
1514 : */
1515 :
1516 : {
1517 0 : const long lNullPix = Ruler::GetNullOffset();
1518 0 : long lDragPos = GetDragPos() + lNullPix;
1519 : ADD_DEBUG_TEXT("lDragPos: ", OUString::number(lDragPos))
1520 0 : sal_Bool bHoriRows = bHorz && pRuler_Imp->bIsTableRows;
1521 0 : if((bLeft || (bHoriRows)) && lDragPos < nMaxLeft)
1522 0 : lDragPos = nMaxLeft;
1523 0 : else if((bRight||bHoriRows) && lDragPos > nMaxRight)
1524 0 : lDragPos = nMaxRight;
1525 0 : return lDragPos - lNullPix;
1526 : }
1527 :
1528 :
1529 :
1530 0 : void ModifyTabs_Impl
1531 : (
1532 : sal_uInt16 nCount, // Number of Tabs
1533 : RulerTab *pTabs, // Tab buffer
1534 : long lDiff // difference to be added
1535 : )
1536 :
1537 : /* [Description]
1538 :
1539 : Helper function, move all the tabs by a fixed value
1540 : */
1541 : {
1542 0 : if( pTabs )
1543 0 : for(sal_uInt16 i = 0; i < nCount; ++i) pTabs[i].nPos += lDiff;
1544 0 : }
1545 :
1546 :
1547 :
1548 0 : void SvxRuler::DragMargin1()
1549 :
1550 : /* [Description]
1551 :
1552 : Dragging the left edge of frame
1553 : */
1554 : {
1555 0 : const long lDragPos = GetCorrectedDragPos( !TAB_FLAG || !NEG_FLAG, sal_True );
1556 0 : DrawLine_Impl(lTabPos, ( TAB_FLAG && NEG_FLAG ) ? 3 : 7, bHorz);
1557 0 : if(pColumnItem&&
1558 0 : (nDragType & DRAG_OBJECT_SIZE_PROPORTIONAL))
1559 0 : DragBorders();
1560 0 : AdjustMargin1(lDragPos);
1561 0 : }
1562 0 : void SvxRuler::AdjustMargin1(long lDiff)
1563 : {
1564 0 : const long nOld = bAppSetNullOffset? GetMargin1(): GetNullOffset();
1565 0 : const long lDragPos = lDiff;
1566 : sal_Bool bProtectColumns =
1567 0 : pRuler_Imp->aProtectItem.IsSizeProtected() ||
1568 0 : pRuler_Imp->aProtectItem.IsPosProtected();
1569 :
1570 : const sal_uInt16 nMarginStyle =
1571 0 : bProtectColumns ? 0 : RULER_MARGIN_SIZEABLE;
1572 :
1573 0 : if(!bAppSetNullOffset)
1574 : {
1575 0 : long _lDiff = lDragPos;
1576 0 : SetNullOffset(nOld + _lDiff);
1577 0 : if(!pColumnItem||!(nDragType & DRAG_OBJECT_SIZE_LINEAR))
1578 : {
1579 0 : SetMargin2( GetMargin2() - _lDiff, nMarginStyle );
1580 :
1581 0 : if(!pColumnItem && !pObjectItem && pParaItem)
1582 : {
1583 : // Right indent of the old position
1584 0 : pIndents[INDENT_RIGHT_MARGIN].nPos -= _lDiff;
1585 0 : SetIndents(INDENT_COUNT, pIndents+INDENT_GAP);
1586 : }
1587 0 : if(pObjectItem)
1588 : {
1589 0 : pObjectBorders[GetObjectBordersOff(0)].nPos -= _lDiff;
1590 0 : pObjectBorders[GetObjectBordersOff(1)].nPos -= _lDiff;
1591 0 : SetBorders(2, pObjectBorders + GetObjectBordersOff(0));
1592 : }
1593 0 : if(pColumnItem)
1594 : {
1595 0 : for(sal_uInt16 i = 0; i < pColumnItem->Count()-1; ++i)
1596 0 : pBorders[i].nPos -= _lDiff;
1597 0 : SetBorders(pColumnItem->Count()-1, pBorders);
1598 0 : if(pColumnItem->IsFirstAct())
1599 : {
1600 : // Right indent of the old position
1601 0 : if(pParaItem)
1602 : {
1603 0 : pIndents[INDENT_RIGHT_MARGIN].nPos -= _lDiff;
1604 0 : SetIndents(INDENT_COUNT, pIndents+INDENT_GAP);
1605 : }
1606 : }
1607 : else
1608 : {
1609 0 : if(pParaItem)
1610 : {
1611 0 : pIndents[INDENT_FIRST_LINE].nPos -= _lDiff;
1612 0 : pIndents[INDENT_LEFT_MARGIN].nPos -= _lDiff;
1613 0 : pIndents[INDENT_RIGHT_MARGIN].nPos -= _lDiff;
1614 0 : SetIndents(INDENT_COUNT, pIndents+INDENT_GAP);
1615 : }
1616 : }
1617 0 : if(pTabStopItem&& (nDragType & DRAG_OBJECT_SIZE_PROPORTIONAL)
1618 0 : &&!IsActFirstColumn())
1619 : {
1620 0 : ModifyTabs_Impl(nTabCount+TAB_GAP, pTabs, -_lDiff);
1621 0 : SetTabs(nTabCount, pTabs+TAB_GAP);
1622 : }
1623 : }
1624 : }
1625 : }
1626 : else
1627 : {
1628 0 : long _lDiff = lDragPos - nOld;
1629 0 : SetMargin1(nOld + _lDiff, nMarginStyle );
1630 :
1631 0 : if(!pColumnItem||!(nDragType & (DRAG_OBJECT_SIZE_LINEAR |
1632 : DRAG_OBJECT_SIZE_PROPORTIONAL)))
1633 : {
1634 0 : if(!pColumnItem && !pObjectItem && pParaItem)
1635 : {
1636 : // Left indent of the old position
1637 0 : pIndents[INDENT_FIRST_LINE].nPos += _lDiff;
1638 0 : pIndents[INDENT_LEFT_MARGIN].nPos += _lDiff;
1639 0 : SetIndents(INDENT_COUNT, pIndents+INDENT_GAP);
1640 : }
1641 :
1642 0 : if(pColumnItem)
1643 : {
1644 0 : for(sal_uInt16 i = 0; i < pColumnItem->Count()-1; ++i)
1645 0 : pBorders[i].nPos += _lDiff;
1646 0 : SetBorders(pColumnItem->Count()-1, pBorders);
1647 0 : if(pColumnItem->IsFirstAct())
1648 : {
1649 : // Left indent of the old position
1650 0 : if(pParaItem)
1651 : {
1652 0 : pIndents[INDENT_FIRST_LINE].nPos += _lDiff;
1653 0 : pIndents[INDENT_LEFT_MARGIN].nPos += _lDiff;
1654 0 : SetIndents(INDENT_COUNT, pIndents+INDENT_GAP);
1655 : }
1656 : }
1657 : else
1658 : {
1659 0 : if(pParaItem)
1660 : {
1661 0 : pIndents[INDENT_FIRST_LINE].nPos += _lDiff;
1662 0 : pIndents[INDENT_LEFT_MARGIN].nPos += _lDiff;
1663 0 : pIndents[INDENT_RIGHT_MARGIN].nPos += _lDiff;
1664 0 : SetIndents(INDENT_COUNT, pIndents+INDENT_GAP);
1665 : }
1666 : }
1667 : }
1668 0 : if(pTabStopItem)
1669 : {
1670 0 : ModifyTabs_Impl(nTabCount+TAB_GAP, pTabs, _lDiff);
1671 0 : SetTabs(nTabCount, pTabs+TAB_GAP);
1672 : }
1673 : }
1674 : }
1675 0 : }
1676 :
1677 :
1678 0 : void SvxRuler::DragMargin2()
1679 :
1680 : /* [Description]
1681 :
1682 : Dragging the right edge of frame
1683 : */
1684 : {
1685 0 : const long lDragPos = GetCorrectedDragPos( sal_True, !TAB_FLAG || !NEG_FLAG);
1686 0 : DrawLine_Impl(lTabPos, ( TAB_FLAG && NEG_FLAG ) ? 5 : 7, bHorz);
1687 0 : long lDiff = lDragPos - GetMargin2();
1688 :
1689 0 : if(pRuler_Imp->bIsTableRows && !bHorz && pColumnItem&&
1690 0 : (nDragType & DRAG_OBJECT_SIZE_PROPORTIONAL))
1691 0 : DragBorders();
1692 :
1693 : sal_Bool bProtectColumns =
1694 0 : pRuler_Imp->aProtectItem.IsSizeProtected() ||
1695 0 : pRuler_Imp->aProtectItem.IsPosProtected();
1696 : const sal_uInt16 nMarginStyle =
1697 0 : bProtectColumns ? 0 : RULER_MARGIN_SIZEABLE;
1698 0 : SetMargin2( lDragPos, nMarginStyle );
1699 :
1700 : // Right indent of the old position
1701 0 : if((!pColumnItem || IsActLastColumn()) && pParaItem)
1702 : {
1703 0 : pIndents[INDENT_FIRST_LINE].nPos += lDiff;
1704 0 : SetIndents(INDENT_COUNT, pIndents+INDENT_GAP);
1705 : }
1706 0 : }
1707 :
1708 :
1709 0 : void SvxRuler::DragIndents()
1710 :
1711 : /* [Description]
1712 :
1713 : Dragging the paragraph indents
1714 : */
1715 : {
1716 0 : const long lDragPos = NEG_FLAG ? GetDragPos() : GetCorrectedDragPos();
1717 0 : const sal_uInt16 nIdx = GetDragAryPos()+INDENT_GAP;
1718 0 : const long lDiff = pIndents[nIdx].nPos - lDragPos;
1719 :
1720 0 : if((nIdx == INDENT_FIRST_LINE ||
1721 0 : nIdx == INDENT_LEFT_MARGIN ) &&
1722 0 : (nDragType & DRAG_OBJECT_LEFT_INDENT_ONLY) !=
1723 : DRAG_OBJECT_LEFT_INDENT_ONLY)
1724 0 : pIndents[INDENT_FIRST_LINE].nPos -= lDiff;
1725 :
1726 0 : pIndents[nIdx].nPos = lDragPos;
1727 :
1728 0 : SetIndents(INDENT_COUNT, pIndents + INDENT_GAP);
1729 0 : DrawLine_Impl(lTabPos, 1, bHorz);
1730 0 : }
1731 :
1732 :
1733 0 : void SvxRuler::DrawLine_Impl(long &_lTabPos, int nNew, sal_Bool Hori)
1734 :
1735 : /* [Description]
1736 :
1737 : Output routine for the ledger line when moving tabs, tables and other
1738 : columns
1739 : */
1740 : {
1741 0 : if(Hori)
1742 : {
1743 0 : const long nHeight = pEditWin->GetOutputSize().Height();
1744 0 : Point aZero=pEditWin->GetMapMode().GetOrigin();
1745 0 : if(_lTabPos!=-1)
1746 : pEditWin->InvertTracking(
1747 0 : Rectangle( Point(_lTabPos, -aZero.Y()),
1748 0 : Point(_lTabPos, -aZero.Y()+nHeight)),
1749 0 : SHOWTRACK_SPLIT | SHOWTRACK_CLIP );
1750 0 : if( nNew & 1 )
1751 : {
1752 :
1753 : _lTabPos = ConvertHSizeLogic(
1754 0 : GetCorrectedDragPos( ( nNew&4 ) != 0, ( nNew&2 ) != 0 ) +
1755 0 : GetNullOffset() );
1756 0 : if(pPagePosItem)
1757 0 : _lTabPos += pPagePosItem->GetPos().X();
1758 : pEditWin->InvertTracking(
1759 0 : Rectangle(Point(_lTabPos, -aZero.Y()),
1760 0 : Point(_lTabPos, -aZero.Y()+nHeight)),
1761 0 : SHOWTRACK_CLIP | SHOWTRACK_SPLIT );
1762 : }
1763 : }
1764 : else
1765 : {
1766 0 : const long nWidth = pEditWin->GetOutputSize().Width();
1767 0 : Point aZero=pEditWin->GetMapMode().GetOrigin();
1768 0 : if(_lTabPos != -1)
1769 : {
1770 : pEditWin->InvertTracking(
1771 0 : Rectangle( Point(-aZero.X(), _lTabPos),
1772 0 : Point(-aZero.X()+nWidth, _lTabPos)),
1773 0 : SHOWTRACK_SPLIT | SHOWTRACK_CLIP );
1774 : }
1775 :
1776 0 : if(nNew & 1)
1777 : {
1778 0 : _lTabPos = ConvertVSizeLogic(GetCorrectedDragPos()+GetNullOffset());
1779 0 : if(pPagePosItem)
1780 0 : _lTabPos += pPagePosItem->GetPos().Y();
1781 : pEditWin->InvertTracking(
1782 0 : Rectangle( Point(-aZero.X(), _lTabPos),
1783 0 : Point(-aZero.X()+nWidth, _lTabPos)),
1784 0 : SHOWTRACK_CLIP | SHOWTRACK_SPLIT );
1785 : }
1786 : }
1787 0 : }
1788 :
1789 :
1790 :
1791 :
1792 0 : void SvxRuler::DragTabs()
1793 :
1794 : /* [Description]
1795 :
1796 : Dragging of Tabs
1797 : */
1798 : {
1799 :
1800 0 : long lDragPos = GetCorrectedDragPos(sal_True, sal_False);
1801 :
1802 0 : sal_uInt16 nIdx = GetDragAryPos()+TAB_GAP;
1803 0 : DrawLine_Impl(lTabPos, 7, bHorz);
1804 :
1805 0 : long nDiff = lDragPos - pTabs[nIdx].nPos;
1806 :
1807 0 : if(nDragType & DRAG_OBJECT_SIZE_LINEAR)
1808 : {
1809 :
1810 0 : for(sal_uInt16 i = nIdx; i < nTabCount; ++i)
1811 : {
1812 0 : pTabs[i].nPos += nDiff;
1813 : // limit on maximum
1814 0 : if(pTabs[i].nPos > GetMargin2())
1815 0 : pTabs[nIdx].nStyle |= RULER_STYLE_INVISIBLE;
1816 : else
1817 0 : pTabs[nIdx].nStyle &= ~RULER_STYLE_INVISIBLE;
1818 : }
1819 : }
1820 0 : else if(nDragType & DRAG_OBJECT_SIZE_PROPORTIONAL)
1821 : {
1822 0 : pRuler_Imp->nTotalDist -= nDiff;
1823 0 : pTabs[nIdx].nPos = lDragPos;
1824 0 : for(sal_uInt16 i = nIdx+1; i < nTabCount; ++i)
1825 : {
1826 0 : if(pTabs[i].nStyle & RULER_TAB_DEFAULT)
1827 : // can be canceled at the DefaultTabs
1828 0 : break;
1829 0 : long nDelta = pRuler_Imp->nTotalDist * pRuler_Imp->pPercBuf[i];
1830 0 : nDelta /= 1000;
1831 0 : pTabs[i].nPos = pTabs[nIdx].nPos + nDelta;
1832 0 : if(pTabs[i].nPos+GetNullOffset() > nMaxRight)
1833 0 : pTabs[i].nStyle |= RULER_STYLE_INVISIBLE;
1834 : else
1835 0 : pTabs[i].nStyle &= ~RULER_STYLE_INVISIBLE;
1836 : }
1837 : }
1838 : else
1839 0 : pTabs[nIdx].nPos = lDragPos;
1840 :
1841 0 : if(IsDragDelete())
1842 0 : pTabs[nIdx].nStyle |= RULER_STYLE_INVISIBLE;
1843 : else
1844 0 : pTabs[nIdx].nStyle &= ~RULER_STYLE_INVISIBLE;
1845 0 : SetTabs(nTabCount, pTabs+TAB_GAP);
1846 0 : }
1847 :
1848 :
1849 :
1850 6709 : void SvxRuler::SetActive(sal_Bool bOn)
1851 : {
1852 6709 : if(bOn)
1853 : {
1854 3567 : Activate();
1855 : }
1856 : else
1857 3142 : Deactivate();
1858 6709 : if(bActive!=bOn)
1859 : {
1860 4698 : pBindings->EnterRegistrations();
1861 4698 : if(bOn)
1862 17116 : for(sal_uInt16 i=0;i<pRuler_Imp->nControlerItems;i++)
1863 15560 : pCtrlItem[i]->ReBind();
1864 : else
1865 34562 : for(sal_uInt16 j=0;j<pRuler_Imp->nControlerItems;j++)
1866 31420 : pCtrlItem[j]->UnBind();
1867 4698 : pBindings->LeaveRegistrations();
1868 : }
1869 6709 : bActive = bOn;
1870 6709 : }
1871 :
1872 :
1873 :
1874 :
1875 0 : void SvxRuler::UpdateParaContents_Impl
1876 : (
1877 : long l, // Difference
1878 : UpdateType eType // Art (all, left or right)
1879 : )
1880 :
1881 : /* [Description]
1882 :
1883 : Helper function; carry Tabs and Paragraph Margins
1884 : */
1885 : {
1886 0 : switch(eType) {
1887 : case MOVE_RIGHT:
1888 0 : pIndents[INDENT_RIGHT_MARGIN].nPos += l;
1889 0 : break;
1890 : case MOVE_ALL:
1891 0 : pIndents[INDENT_RIGHT_MARGIN].nPos += l;
1892 : // no break
1893 : case MOVE_LEFT:
1894 : {
1895 0 : pIndents[INDENT_FIRST_LINE].nPos += l;
1896 0 : pIndents[INDENT_LEFT_MARGIN].nPos += l;
1897 0 : if ( pTabs )
1898 : {
1899 0 : for(sal_uInt16 i = 0; i < nTabCount+TAB_GAP;++i)
1900 0 : pTabs[i].nPos += l;
1901 0 : SetTabs(nTabCount, pTabs+TAB_GAP);
1902 : }
1903 0 : break;
1904 : }
1905 : }
1906 0 : SetIndents(INDENT_COUNT, pIndents+INDENT_GAP);
1907 0 : }
1908 :
1909 :
1910 0 : void SvxRuler::DragBorders()
1911 :
1912 : /* [Description]
1913 :
1914 : Dragging of Borders (Tables and other columns)
1915 : */
1916 : {
1917 0 : sal_Bool bLeftIndentsCorrected = sal_False, bRightIndentsCorrected = sal_False;
1918 : int nIdx;
1919 :
1920 0 : if(GetDragType()==RULER_TYPE_BORDER)
1921 : {
1922 0 : DrawLine_Impl(lTabPos, 7, bHorz);
1923 0 : nIdx = GetDragAryPos();
1924 : }
1925 : else
1926 0 : nIdx=0;
1927 :
1928 0 : sal_uInt16 nDragSize = GetDragSize();
1929 0 : long lDiff = 0;
1930 :
1931 : // the drag position has to be corrected to be able to prevent borders from passing each other
1932 0 : long lPos = GetCorrectedDragPos();
1933 :
1934 :
1935 0 : switch(nDragSize)
1936 : {
1937 : case RULER_DRAGSIZE_MOVE:
1938 : {
1939 : ADD_DEBUG_TEXT("lLastLMargin: ", OUString::number(pRuler_Imp->lLastLMargin))
1940 0 : lDiff = GetDragType()==RULER_TYPE_BORDER ?
1941 0 : lPos-nDragOffset - pBorders[nIdx].nPos
1942 0 : : GetDragType() == RULER_TYPE_MARGIN1 ? lPos - pRuler_Imp->lLastLMargin : lPos - pRuler_Imp->lLastRMargin;
1943 :
1944 0 : if(nDragType & DRAG_OBJECT_SIZE_LINEAR)
1945 : {
1946 0 : long nRight = GetMargin2()-lMinFrame; // Right limiters
1947 0 : for(int i = nBorderCount-2; i >= nIdx; --i)
1948 : {
1949 0 : long l = pBorders[i].nPos;
1950 0 : pBorders[i].nPos += lDiff;
1951 0 : pBorders[i].nPos = std::min(pBorders[i].nPos, nRight - pBorders[i].nWidth);
1952 0 : nRight = pBorders[i].nPos - lMinFrame;
1953 : // RR update the column
1954 0 : if(i == GetActRightColumn())
1955 : {
1956 0 : UpdateParaContents_Impl(pBorders[i].nPos - l, MOVE_RIGHT);
1957 0 : bRightIndentsCorrected = sal_True;
1958 : }
1959 : // LAR, EZE update the column
1960 0 : else if(i == GetActLeftColumn())
1961 : {
1962 0 : UpdateParaContents_Impl(pBorders[i].nPos - l, MOVE_LEFT);
1963 0 : bLeftIndentsCorrected = sal_True;
1964 : }
1965 : }
1966 : }
1967 0 : else if(nDragType & DRAG_OBJECT_SIZE_PROPORTIONAL)
1968 : {
1969 : int nLimit;
1970 : long lLeft;
1971 0 : int nStartLimit = nBorderCount-2;
1972 0 : switch(GetDragType())
1973 : {
1974 : default: ;//prevent warning
1975 : OSL_FAIL("svx::SvxRuler::DragBorders(), unknown drag type!" );
1976 : case RULER_TYPE_BORDER:
1977 0 : if(pRuler_Imp->bIsTableRows)
1978 : {
1979 0 : pBorders[nIdx].nPos += lDiff;
1980 0 : if(bHorz)
1981 : {
1982 0 : lLeft = pBorders[nIdx].nPos;
1983 0 : pRuler_Imp->nTotalDist -= lDiff;
1984 0 : nLimit=nIdx+1;
1985 : }
1986 : else
1987 : {
1988 0 : lLeft = 0;
1989 0 : nStartLimit = nIdx - 1;
1990 0 : pRuler_Imp->nTotalDist += lDiff;
1991 0 : nLimit = 0;
1992 : }
1993 : }
1994 : else
1995 : {
1996 0 : nLimit=nIdx+1;
1997 0 : pBorders[nIdx].nPos += lDiff;
1998 0 : lLeft = pBorders[nIdx].nPos;
1999 0 : pRuler_Imp->nTotalDist-=lDiff;
2000 : }
2001 0 : break;
2002 : case RULER_TYPE_MARGIN1:
2003 0 : nLimit=0;
2004 0 : lLeft=pRuler_Imp->lLastLMargin+lDiff;
2005 0 : pRuler_Imp->nTotalDist-=lDiff;
2006 0 : break;
2007 : case RULER_TYPE_MARGIN2:
2008 0 : nLimit = 0;
2009 0 : lLeft= 0;
2010 0 : nStartLimit = nBorderCount - 2;
2011 0 : pRuler_Imp->nTotalDist += lDiff;
2012 0 : break;
2013 : }
2014 :
2015 0 : for(int i = nStartLimit; i >= nLimit; --i)
2016 : {
2017 :
2018 0 : long l = pBorders[i].nPos;
2019 0 : pBorders[i].nPos=lLeft+
2020 0 : (pRuler_Imp->nTotalDist*pRuler_Imp->pPercBuf[i])/1000+
2021 0 : pRuler_Imp->pBlockBuf[i];
2022 :
2023 : // RR update the column
2024 0 : if(!pRuler_Imp->bIsTableRows)
2025 : {
2026 0 : if(i == GetActRightColumn())
2027 : {
2028 0 : UpdateParaContents_Impl(pBorders[i].nPos - l, MOVE_RIGHT);
2029 0 : bRightIndentsCorrected = sal_True;
2030 : }
2031 : // LAR, EZE update the column
2032 0 : else if(i == GetActLeftColumn())
2033 : {
2034 0 : UpdateParaContents_Impl(pBorders[i].nPos - l, MOVE_LEFT);
2035 0 : bLeftIndentsCorrected = sal_True;
2036 : }
2037 : }
2038 : }
2039 0 : if(pRuler_Imp->bIsTableRows)
2040 : {
2041 : //in vertical tables the left borders have to be moved
2042 0 : if(bHorz)
2043 : {
2044 0 : for(int i = 0; i < nIdx; ++i)
2045 0 : pBorders[i].nPos += lDiff;
2046 0 : AdjustMargin1(lDiff);
2047 : }
2048 : else
2049 : {
2050 : //otherwise the right borders are moved
2051 0 : for(int i = pColumnItem->Count() - 1; i > nIdx; --i)
2052 0 : pBorders[i].nPos += lDiff;
2053 0 : SetMargin2( GetMargin2() + lDiff, 0 );
2054 : }
2055 : }
2056 : }
2057 0 : else if(pRuler_Imp->bIsTableRows)
2058 : {
2059 : //moving rows: if a row is resized all following rows
2060 : //have to be moved by the same amount.
2061 : //This includes the left border when the table is not limited
2062 : //to a lower frame border.
2063 : int nLimit;
2064 0 : if(GetDragType()==RULER_TYPE_BORDER)
2065 : {
2066 0 : nLimit=nIdx+1;
2067 0 : pBorders[nIdx].nPos+=lDiff;
2068 : }
2069 : else
2070 : {
2071 0 : nLimit=0;
2072 : }
2073 : //in vertical tables the left borders have to be moved
2074 0 : if(bHorz)
2075 : {
2076 0 : for(int i = 0; i < nIdx; ++i)
2077 : {
2078 0 : pBorders[i].nPos += lDiff;
2079 : }
2080 0 : AdjustMargin1(lDiff);
2081 : }
2082 : else
2083 : {
2084 : //otherwise the right borders are moved
2085 0 : for(int i = nBorderCount-2; i >= nLimit; --i)
2086 : {
2087 0 : pBorders[i].nPos += lDiff;
2088 : }
2089 0 : SetMargin2( GetMargin2() + lDiff, 0 );
2090 : }
2091 : }
2092 : else
2093 0 : pBorders[nIdx].nPos+=lDiff;
2094 0 : break;
2095 : }
2096 : case RULER_DRAGSIZE_1:
2097 : {
2098 0 : lDiff = lPos - pBorders[nIdx].nPos;
2099 0 : pBorders[nIdx].nWidth += pBorders[nIdx].nPos - lPos;
2100 0 : pBorders[nIdx].nPos = lPos;
2101 0 : break;
2102 : }
2103 : case RULER_DRAGSIZE_2:
2104 : {
2105 0 : const long nOld = pBorders[nIdx].nWidth;
2106 0 : pBorders[nIdx].nWidth = lPos - pBorders[nIdx].nPos;
2107 0 : lDiff = pBorders[nIdx].nWidth - nOld;
2108 0 : break;
2109 : }
2110 : }
2111 0 : if(!bRightIndentsCorrected &&
2112 0 : GetActRightColumn() == nIdx &&
2113 0 : nDragSize != RULER_DRAGSIZE_2 && pIndents &&
2114 0 : !pRuler_Imp->bIsTableRows)
2115 : {
2116 0 : UpdateParaContents_Impl(lDiff, MOVE_RIGHT);
2117 : }
2118 0 : else if(!bLeftIndentsCorrected &&
2119 0 : GetActLeftColumn()==nIdx &&
2120 0 : nDragSize != RULER_DRAGSIZE_1 && pIndents)
2121 : {
2122 0 : UpdateParaContents_Impl(lDiff, MOVE_LEFT);
2123 : }
2124 0 : SetBorders(pColumnItem->Count()-1, pBorders);
2125 0 : }
2126 :
2127 :
2128 0 : void SvxRuler::DragObjectBorder()
2129 :
2130 : /* [Description]
2131 :
2132 : Dragging of object edges
2133 : */
2134 : {
2135 0 : if(RULER_DRAGSIZE_MOVE == GetDragSize())
2136 : {
2137 0 : const long lPos = GetCorrectedDragPos();
2138 0 : const sal_uInt16 nIdx = GetDragAryPos();
2139 0 : pObjectBorders[GetObjectBordersOff(nIdx)].nPos = lPos;
2140 0 : SetBorders(2, pObjectBorders + GetObjectBordersOff(0));
2141 0 : DrawLine_Impl(lTabPos, 7, bHorz);
2142 :
2143 : }
2144 0 : }
2145 :
2146 :
2147 0 : void SvxRuler::ApplyMargins()
2148 :
2149 : /* [Description]
2150 :
2151 : Applying margins; changed by dragging.
2152 : */
2153 : {
2154 0 : const SfxPoolItem *pItem = 0;
2155 0 : sal_uInt16 nId = SID_ATTR_LONG_LRSPACE;
2156 0 : if(bHorz)
2157 : {
2158 0 : const long lOldNull = lLogicNullOffset;
2159 0 : if(pRuler_Imp->lMaxLeftLogic!=-1&&nMaxLeft==GetMargin1()+Ruler::GetNullOffset())
2160 0 : pLRSpaceItem->SetLeft(lLogicNullOffset=pRuler_Imp->lMaxLeftLogic);
2161 : else
2162 : pLRSpaceItem->SetLeft(PixelHAdjust(
2163 0 : lLogicNullOffset = ConvertHPosLogic(GetFrameLeft()) -
2164 0 : lAppNullOffset, pLRSpaceItem->GetLeft()));
2165 :
2166 0 : if(bAppSetNullOffset)
2167 0 : lAppNullOffset += lLogicNullOffset - lOldNull;
2168 :
2169 0 : if(pRuler_Imp->lMaxRightLogic!=-1
2170 0 : &&nMaxRight==GetMargin2()+Ruler::GetNullOffset())
2171 0 : pLRSpaceItem->SetRight(GetPageWidth()-pRuler_Imp->lMaxRightLogic);
2172 : else
2173 : pLRSpaceItem->SetRight(
2174 : PixelHAdjust(
2175 0 : std::max((long)0,pPagePosItem->GetWidth() -
2176 0 : pLRSpaceItem->GetLeft() -
2177 0 : (ConvertHPosLogic(GetMargin2()) -
2178 0 : lAppNullOffset)),pLRSpaceItem->GetRight()));
2179 0 : pItem = pLRSpaceItem;
2180 : #ifdef DEBUGLIN
2181 : Debug_Impl(pEditWin,*pLRSpaceItem);
2182 : #endif // DEBUGLIN
2183 : }
2184 : else {
2185 0 : const long lOldNull = lLogicNullOffset;
2186 : pULSpaceItem->SetUpper(
2187 : PixelVAdjust(
2188 : lLogicNullOffset =
2189 0 : ConvertVPosLogic(GetFrameLeft()) -
2190 0 : lAppNullOffset,pULSpaceItem->GetUpper()));
2191 0 : if(bAppSetNullOffset)
2192 0 : lAppNullOffset += lLogicNullOffset - lOldNull;
2193 : pULSpaceItem->SetLower(
2194 : PixelVAdjust(
2195 0 : std::max((long)0, pPagePosItem->GetHeight() -
2196 0 : pULSpaceItem->GetUpper() -
2197 0 : (ConvertVPosLogic(GetMargin2()) -
2198 0 : lAppNullOffset)),pULSpaceItem->GetLower()));
2199 0 : pItem = pULSpaceItem;
2200 0 : nId = SID_ATTR_LONG_ULSPACE;
2201 : #ifdef DEBUGLIN
2202 : Debug_Impl(pEditWin,*pULSpaceItem);
2203 : #endif // DEBUGLIN
2204 : }
2205 0 : pBindings->GetDispatcher()->Execute( nId, SFX_CALLMODE_RECORD, pItem, 0L );
2206 0 : if(pTabStopItem)
2207 0 : UpdateTabs();
2208 0 : }
2209 :
2210 :
2211 0 : void SvxRuler::ApplyIndents()
2212 :
2213 : /* [Description]
2214 :
2215 : Applying paragraph settings; changed by dragging.
2216 : */
2217 : {
2218 : long nNewTxtLeft;
2219 0 : if(pColumnItem&&!IsActFirstColumn( sal_True ))
2220 : {
2221 0 : long nLeftCol=GetActLeftColumn( sal_True );
2222 : nNewTxtLeft =
2223 : PixelHAdjust(
2224 : ConvertHPosLogic(
2225 0 : pIndents[INDENT_LEFT_MARGIN].nPos-
2226 0 : (pBorders[nLeftCol].nPos +
2227 0 : pBorders[nLeftCol].nWidth))-
2228 0 : lAppNullOffset,pParaItem->GetTxtLeft());
2229 : }
2230 : else
2231 : nNewTxtLeft =
2232 : PixelHAdjust(
2233 0 : ConvertHPosLogic(pIndents[INDENT_LEFT_MARGIN].nPos),
2234 0 : pParaItem->GetTxtLeft());
2235 :
2236 0 : sal_Bool bRTL = pRuler_Imp->pTextRTLItem && pRuler_Imp->pTextRTLItem->GetValue();
2237 :
2238 : long nNewFirstLineOffset;
2239 0 : if(bRTL)
2240 : {
2241 0 : long nRightFrameMargin = GetRightFrameMargin();
2242 0 : nNewFirstLineOffset = PixelHAdjust(nRightFrameMargin -
2243 0 : ConvertHPosLogic(pIndents[INDENT_FIRST_LINE].nPos ) -
2244 : lAppNullOffset,
2245 0 : pParaItem->GetTxtFirstLineOfst());
2246 : }
2247 : else
2248 : nNewFirstLineOffset=
2249 : PixelHAdjust(
2250 0 : ConvertHPosLogic(pIndents[INDENT_FIRST_LINE].nPos -
2251 0 : pIndents[INDENT_LEFT_MARGIN].nPos) -
2252 : lAppNullOffset,
2253 0 : pParaItem->GetTxtFirstLineOfst());
2254 :
2255 : // If the new TxtLeft is smaller than the old FirstLineIndent, then the
2256 : // difference is lost and the paragraph is in total indented too far,
2257 : // so first set the FirstLineOffset, then the TxtLeft
2258 :
2259 0 : if(bRTL)
2260 : {
2261 0 : long nLeftFrameMargin = GetLeftFrameMargin();
2262 0 : long nRightFrameMargin = GetRightFrameMargin();
2263 0 : nNewTxtLeft = nRightFrameMargin - nNewTxtLeft - nLeftFrameMargin;
2264 0 : nNewFirstLineOffset -= nNewTxtLeft;
2265 0 : if(pParaBorderItem)
2266 : {
2267 0 : nNewTxtLeft += pParaBorderItem->GetLeft() + pParaBorderItem->GetRight();
2268 0 : nNewFirstLineOffset -= pParaBorderItem->GetRight();
2269 : }
2270 : }
2271 : pParaItem->SetTxtFirstLineOfst(
2272 0 : sal::static_int_cast< short >(nNewFirstLineOffset));
2273 0 : pParaItem->SetTxtLeft(nNewTxtLeft);
2274 :
2275 0 : if(pColumnItem && ((!bRTL && !IsActLastColumn( sal_True ))|| (bRTL && !IsActFirstColumn())))
2276 : {
2277 0 : if(bRTL)
2278 : {
2279 0 : long nActBorder = pBorders[GetActLeftColumn( sal_True )].nPos;
2280 0 : long nRightMargin = pIndents[INDENT_RIGHT_MARGIN].nPos;
2281 0 : long nConvert = ConvertHPosLogic( nRightMargin - nActBorder );
2282 0 : pParaItem->SetRight( PixelHAdjust( nConvert - lAppNullOffset, pParaItem->GetRight() ) );
2283 : }
2284 : else
2285 : {
2286 : pParaItem->SetRight(
2287 : PixelHAdjust(
2288 : ConvertHPosLogic(
2289 0 : pBorders[GetActRightColumn( sal_True )].nPos -
2290 0 : pIndents[INDENT_RIGHT_MARGIN].nPos) -
2291 : lAppNullOffset,
2292 0 : pParaItem->GetRight()));
2293 : }
2294 :
2295 : }
2296 : else
2297 : {
2298 0 : if(bRTL)
2299 : {
2300 : pParaItem->SetRight( PixelHAdjust(
2301 0 : ConvertHPosLogic(GetMargin1() +
2302 0 : pIndents[INDENT_RIGHT_MARGIN].nPos) - GetLeftFrameMargin() +
2303 0 : (pParaBorderItem ? pParaBorderItem->GetLeft() : 0) -
2304 0 : lAppNullOffset, pParaItem->GetRight()));
2305 : }
2306 : else
2307 : {
2308 : pParaItem->SetRight( PixelHAdjust(
2309 0 : ConvertHPosLogic(GetMargin2() -
2310 0 : pIndents[INDENT_RIGHT_MARGIN].nPos) -
2311 0 : lAppNullOffset, pParaItem->GetRight()));
2312 : }
2313 : }
2314 0 : sal_uInt16 nParaId = bHorz ? SID_ATTR_PARA_LRSPACE : SID_ATTR_PARA_LRSPACE_VERTICAL;
2315 0 : pBindings->GetDispatcher()->Execute( nParaId, SFX_CALLMODE_RECORD, pParaItem, 0L );
2316 0 : UpdateTabs();
2317 0 : }
2318 :
2319 :
2320 0 : void SvxRuler::ApplyTabs()
2321 :
2322 : /* [Description]
2323 :
2324 : Apply tab settings, changed by dragging.
2325 : */
2326 : {
2327 0 : sal_Bool bRTL = pRuler_Imp->pTextRTLItem && pRuler_Imp->pTextRTLItem->GetValue();
2328 0 : const sal_uInt16 nCoreIdx = GetDragAryPos();
2329 0 : if(IsDragDelete())
2330 : {
2331 0 : pTabStopItem->Remove(nCoreIdx);
2332 : }
2333 0 : else if(DRAG_OBJECT_SIZE_LINEAR & nDragType ||
2334 0 : DRAG_OBJECT_SIZE_PROPORTIONAL & nDragType)
2335 : {
2336 0 : SvxTabStopItem *pItem = new SvxTabStopItem(pTabStopItem->Which());
2337 : //remove default tab stops
2338 0 : for ( sal_uInt16 i = 0; i < pItem->Count(); )
2339 : {
2340 0 : if ( SVX_TAB_ADJUST_DEFAULT == (*pItem)[i].GetAdjustment() )
2341 : {
2342 0 : pItem->Remove(i);
2343 0 : continue;
2344 : }
2345 0 : ++i;
2346 : }
2347 :
2348 : sal_uInt16 j;
2349 0 : for(j = 0; j < nCoreIdx; ++j)
2350 : {
2351 0 : pItem->Insert((*pTabStopItem)[j]);
2352 : }
2353 0 : for(; j < pTabStopItem->Count(); ++j)
2354 : {
2355 0 : SvxTabStop aTabStop = (*pTabStopItem)[j];
2356 0 : aTabStop.GetTabPos() = PixelHAdjust(
2357 0 : ConvertHPosLogic(pTabs[j+TAB_GAP].nPos -
2358 0 : GetLeftIndent()) -
2359 : lAppNullOffset,
2360 0 : aTabStop.GetTabPos());
2361 0 : pItem->Insert(aTabStop);
2362 : }
2363 0 : delete pTabStopItem;
2364 0 : pTabStopItem = pItem;
2365 : }
2366 0 : else if( pTabStopItem->Count() == 0 )
2367 0 : return;
2368 : else
2369 : {
2370 0 : SvxTabStop aTabStop = (*pTabStopItem)[nCoreIdx];
2371 0 : if(pRuler_Imp->lMaxRightLogic!=-1&&
2372 0 : pTabs[nCoreIdx+TAB_GAP].nPos+Ruler::GetNullOffset()==nMaxRight)
2373 0 : aTabStop.GetTabPos() = pRuler_Imp->lMaxRightLogic-lLogicNullOffset;
2374 : else
2375 : {
2376 0 : if(bRTL)
2377 : {
2378 : //#i24363# tab stops relative to indent
2379 : const long nTmpLeftIndent = pRuler_Imp->bIsTabsRelativeToIndent ?
2380 : GetLeftIndent() :
2381 0 : ConvertHPosPixel( GetRightFrameMargin() + lAppNullOffset );
2382 :
2383 0 : aTabStop.GetTabPos() = PixelHAdjust(
2384 0 : ConvertHPosLogic( nTmpLeftIndent - pTabs[nCoreIdx+TAB_GAP].nPos) - lAppNullOffset,
2385 0 : aTabStop.GetTabPos());
2386 : }
2387 : else
2388 : {
2389 : //#i24363# tab stops relative to indent
2390 : const long nTmpLeftIndent = pRuler_Imp->bIsTabsRelativeToIndent ?
2391 : GetLeftIndent() :
2392 0 : 0;
2393 :
2394 0 : aTabStop.GetTabPos() = PixelHAdjust(
2395 0 : ConvertHPosLogic( pTabs[nCoreIdx+TAB_GAP].nPos - nTmpLeftIndent ) - lAppNullOffset,
2396 0 : aTabStop.GetTabPos() );
2397 : }
2398 : }
2399 0 : pTabStopItem->Remove(nCoreIdx);
2400 0 : pTabStopItem->Insert(aTabStop);
2401 : }
2402 0 : sal_uInt16 nTabStopId = bHorz ? SID_ATTR_TABSTOP : SID_ATTR_TABSTOP_VERTICAL;
2403 0 : pBindings->GetDispatcher()->Execute( nTabStopId, SFX_CALLMODE_RECORD, pTabStopItem, 0L );
2404 0 : UpdateTabs();
2405 : }
2406 :
2407 :
2408 0 : void SvxRuler::ApplyBorders()
2409 :
2410 : /* [Description]
2411 :
2412 : Applying (table) column settings; changed by dragging.
2413 : */
2414 : {
2415 0 : if(pColumnItem->IsTable())
2416 : {
2417 0 : long l = GetFrameLeft();
2418 0 : if(l != pRuler_Imp->nColLeftPix)
2419 : pColumnItem->SetLeft( PixelHAdjust(
2420 0 : ConvertHPosLogic(l) - lAppNullOffset, pColumnItem->GetLeft()));
2421 0 : l = GetMargin2();
2422 0 : if(l != pRuler_Imp->nColRightPix)
2423 : {
2424 0 : long nWidthOrHeight = bHorz ? pPagePosItem->GetWidth() : pPagePosItem->GetHeight();
2425 0 : pColumnItem->SetRight( PixelHAdjust( nWidthOrHeight -
2426 0 : pColumnItem->GetLeft() - ConvertHPosLogic(l) -
2427 0 : lAppNullOffset, pColumnItem->GetRight() ) );
2428 : }
2429 : }
2430 0 : for(sal_uInt16 i = 0; i < pColumnItem->Count()-1; ++i)
2431 : {
2432 0 : long& nEnd = (*pColumnItem)[i].nEnd;
2433 0 : nEnd = PIXEL_H_ADJUST(
2434 : ConvertPosLogic(pBorders[i].nPos),
2435 0 : (*pColumnItem)[i].nEnd);
2436 0 : long& nStart = (*pColumnItem)[i+1].nStart;
2437 0 : nStart = PIXEL_H_ADJUST(
2438 : ConvertSizeLogic(pBorders[i].nPos +
2439 : pBorders[i].nWidth) -
2440 : lAppNullOffset,
2441 0 : (*pColumnItem)[i+1].nStart);
2442 : // It may be that, due to the PIXEL_H_ADJUST readjustment to old values,
2443 : // the width becomes < 0. This we readjust.
2444 0 : if( nEnd > nStart )
2445 0 : nStart = nEnd;
2446 : }
2447 : #ifdef DEBUGLIN
2448 : Debug_Impl(pEditWin,*pColumnItem);
2449 : #endif // DEBUGLIN
2450 : SfxBoolItem aFlag(SID_RULER_ACT_LINE_ONLY,
2451 0 : nDragType & DRAG_OBJECT_ACTLINE_ONLY? sal_True : sal_False);
2452 : sal_uInt16 nColId = pRuler_Imp->bIsTableRows ? (bHorz ? SID_RULER_ROWS : SID_RULER_ROWS_VERTICAL) :
2453 0 : (bHorz ? SID_RULER_BORDERS : SID_RULER_BORDERS_VERTICAL);
2454 0 : pBindings->GetDispatcher()->Execute( nColId, SFX_CALLMODE_RECORD, pColumnItem, &aFlag, 0L );
2455 0 : }
2456 :
2457 0 : void SvxRuler::ApplyObject()
2458 :
2459 : /* [Description]
2460 :
2461 : Applying object settings, changed by dragging.
2462 : */
2463 : {
2464 : // to the page margin
2465 0 : long nMargin = pLRSpaceItem? pLRSpaceItem->GetLeft(): 0;
2466 : pObjectItem->SetStartX(
2467 : PixelAdjust(
2468 0 : ConvertPosLogic(pObjectBorders[0].nPos)
2469 0 : + nMargin - lAppNullOffset,pObjectItem->GetStartX()));
2470 : pObjectItem->SetEndX(
2471 : PixelAdjust(
2472 0 : ConvertPosLogic(pObjectBorders[1].nPos)
2473 0 : + nMargin - lAppNullOffset,pObjectItem->GetEndX()));
2474 0 : nMargin = pULSpaceItem? pULSpaceItem->GetUpper(): 0;
2475 : pObjectItem->SetStartY(
2476 : PixelAdjust(
2477 0 : ConvertPosLogic(pObjectBorders[2].nPos)
2478 0 : + nMargin - lAppNullOffset,pObjectItem->GetStartY()));
2479 : pObjectItem->SetEndY(
2480 : PixelAdjust(
2481 0 : ConvertPosLogic(pObjectBorders[3].nPos)
2482 0 : + nMargin - lAppNullOffset,pObjectItem->GetEndY()));
2483 0 : pBindings->GetDispatcher()->Execute( SID_RULER_OBJECT, SFX_CALLMODE_RECORD, pObjectItem, 0L );
2484 0 : }
2485 :
2486 0 : void SvxRuler::PrepareProportional_Impl(RulerType eType)
2487 :
2488 : /* [Description]
2489 :
2490 : Preparation proportional dragging, and it is calculated based on the
2491 : proportional share of the total width in parts per thousand.
2492 : */
2493 : {
2494 0 : pRuler_Imp->nTotalDist = GetMargin2();
2495 0 : switch((int)eType)
2496 : {
2497 : case RULER_TYPE_MARGIN2:
2498 : case RULER_TYPE_MARGIN1:
2499 : case RULER_TYPE_BORDER:
2500 : {
2501 : DBG_ASSERT(pColumnItem, "no ColumnItem");
2502 :
2503 0 : pRuler_Imp->SetPercSize(pColumnItem->Count());
2504 :
2505 : long lPos;
2506 0 : long lWidth=0;
2507 : sal_uInt16 nStart;
2508 0 : sal_uInt16 nIdx=GetDragAryPos();
2509 0 : long lActWidth=0;
2510 : long lActBorderSum;
2511 : long lOrigLPos;
2512 :
2513 0 : if(eType != RULER_TYPE_BORDER)
2514 : {
2515 0 : lOrigLPos = GetMargin1();
2516 0 : nStart = 0;
2517 0 : lActBorderSum = 0;
2518 : }
2519 : else
2520 : {
2521 0 : if(pRuler_Imp->bIsTableRows &&!bHorz)
2522 : {
2523 0 : lOrigLPos = GetMargin1();
2524 0 : nStart = 0;
2525 : }
2526 : else
2527 : {
2528 0 : lOrigLPos = pBorders[nIdx].nPos + pBorders[nIdx].nWidth;
2529 0 : nStart = 1;
2530 : }
2531 0 : lActBorderSum = pBorders[nIdx].nWidth;
2532 : }
2533 :
2534 : //in horizontal mode the percentage value has to be
2535 : //calculated on a "current change" position base
2536 : //because the height of the table changes while dragging
2537 0 : if(pRuler_Imp->bIsTableRows && RULER_TYPE_BORDER == eType)
2538 : {
2539 : sal_uInt16 nStartBorder;
2540 : sal_uInt16 nEndBorder;
2541 0 : if(bHorz)
2542 : {
2543 0 : nStartBorder = nIdx + 1;
2544 0 : nEndBorder = pColumnItem->Count() - 1;
2545 : }
2546 : else
2547 : {
2548 0 : nStartBorder = 0;
2549 0 : nEndBorder = nIdx;
2550 : }
2551 :
2552 0 : lWidth = pBorders[nIdx].nPos;
2553 0 : if(bHorz)
2554 0 : lWidth = GetMargin2() - lWidth;
2555 0 : pRuler_Imp->nTotalDist = lWidth;
2556 0 : lPos = lOrigLPos = pBorders[nIdx].nPos;
2557 :
2558 0 : for(sal_uInt16 i = nStartBorder; i < nEndBorder; ++i)
2559 : {
2560 0 : if(bHorz)
2561 : {
2562 0 : lActWidth += pBorders[i].nPos - lPos;
2563 0 : lPos = pBorders[i].nPos + pBorders[i].nWidth;
2564 : }
2565 : else
2566 0 : lActWidth = pBorders[i].nPos;
2567 0 : pRuler_Imp->pPercBuf[i] = (sal_uInt16)((lActWidth * 1000)
2568 0 : / pRuler_Imp->nTotalDist);
2569 0 : pRuler_Imp->pBlockBuf[i] = (sal_uInt16)lActBorderSum;
2570 0 : lActBorderSum += pBorders[i].nWidth;
2571 0 : }
2572 : }
2573 : else
2574 : {
2575 0 : lPos = lOrigLPos;
2576 0 : for(sal_uInt16 ii = nStart; ii < pColumnItem->Count() - 1; ++ii)
2577 : {
2578 0 : lWidth += pBorders[ii].nPos - lPos;
2579 0 : lPos = pBorders[ii].nPos + pBorders[ii].nWidth;
2580 : }
2581 :
2582 0 : lWidth += GetMargin2() - lPos;
2583 0 : pRuler_Imp->nTotalDist = lWidth;
2584 0 : lPos = lOrigLPos;
2585 :
2586 0 : for(sal_uInt16 i = nStart; i < pColumnItem->Count() - 1; ++i)
2587 : {
2588 0 : lActWidth += pBorders[i].nPos - lPos;
2589 0 : lPos = pBorders[i].nPos + pBorders[i].nWidth;
2590 0 : pRuler_Imp->pPercBuf[i] = (sal_uInt16)((lActWidth * 1000)
2591 0 : / pRuler_Imp->nTotalDist);
2592 0 : pRuler_Imp->pBlockBuf[i] = (sal_uInt16)lActBorderSum;
2593 0 : lActBorderSum += pBorders[i].nWidth;
2594 : }
2595 : }
2596 : }
2597 0 : break;
2598 : case RULER_TYPE_TAB:
2599 : {
2600 0 : const sal_uInt16 nIdx = GetDragAryPos()+TAB_GAP;
2601 0 : pRuler_Imp->nTotalDist -= pTabs[nIdx].nPos;
2602 0 : pRuler_Imp->SetPercSize(nTabCount);
2603 0 : for(sal_uInt16 n=0;n<=nIdx;pRuler_Imp->pPercBuf[n++]=0) ;
2604 0 : for(sal_uInt16 i = nIdx+1; i < nTabCount; ++i)
2605 : {
2606 0 : const long nDelta = pTabs[i].nPos - pTabs[nIdx].nPos;
2607 0 : pRuler_Imp->pPercBuf[i] = (sal_uInt16)((nDelta * 1000) / pRuler_Imp->nTotalDist);
2608 : }
2609 0 : break;
2610 : }
2611 : }
2612 0 : }
2613 :
2614 :
2615 0 : void SvxRuler::EvalModifier()
2616 :
2617 : /* [Description]
2618 :
2619 : Eval Drag Modifier
2620 :
2621 : Shift: move linear
2622 : Control: move proportional
2623 : Shift+Control: Table: only current line
2624 : Alt: dimension arrows (not implemented) //!!
2625 :
2626 : */
2627 :
2628 : {
2629 0 : sal_uInt16 nModifier = GetDragModifier();
2630 0 : if(pRuler_Imp->bIsTableRows)
2631 : {
2632 : //rows can only be moved in one way, additionally current column is possible
2633 0 : if(nModifier == KEY_SHIFT)
2634 0 : nModifier = 0;
2635 : }
2636 0 : switch(nModifier)
2637 : {
2638 : case KEY_SHIFT:
2639 0 : nDragType = DRAG_OBJECT_SIZE_LINEAR;
2640 0 : break;
2641 : case KEY_MOD1: {
2642 0 : const RulerType eType = GetDragType();
2643 0 : nDragType = DRAG_OBJECT_SIZE_PROPORTIONAL;
2644 0 : if( RULER_TYPE_TAB == eType ||
2645 0 : ( ( RULER_TYPE_BORDER == eType || RULER_TYPE_MARGIN1 == eType ||
2646 0 : RULER_TYPE_MARGIN2 == eType ) &&
2647 : pColumnItem ) )
2648 0 : PrepareProportional_Impl(eType);
2649 0 : break;
2650 : }
2651 : case KEY_MOD1 | KEY_SHIFT:
2652 0 : if(GetDragType()!=RULER_TYPE_MARGIN1&&
2653 0 : GetDragType()!=RULER_TYPE_MARGIN2)
2654 0 : nDragType = DRAG_OBJECT_ACTLINE_ONLY;
2655 0 : break;
2656 : // ALT: Dimension arrows
2657 : }
2658 0 : }
2659 :
2660 :
2661 0 : void SvxRuler::Click()
2662 :
2663 : /* [Description]
2664 :
2665 : Overloaded handler SV; sets Tab per dispatcher call
2666 : */
2667 :
2668 : {
2669 0 : Ruler::Click();
2670 0 : if( bActive )
2671 : {
2672 0 : pBindings->Update( SID_RULER_LR_MIN_MAX );
2673 0 : pBindings->Update( SID_ATTR_LONG_ULSPACE );
2674 0 : pBindings->Update( SID_ATTR_LONG_LRSPACE );
2675 0 : pBindings->Update( SID_RULER_PAGE_POS );
2676 0 : pBindings->Update( bHorz ? SID_ATTR_TABSTOP : SID_ATTR_TABSTOP_VERTICAL);
2677 0 : pBindings->Update( bHorz ? SID_ATTR_PARA_LRSPACE : SID_ATTR_PARA_LRSPACE_VERTICAL);
2678 0 : pBindings->Update( bHorz ? SID_RULER_BORDERS : SID_RULER_BORDERS_VERTICAL);
2679 0 : pBindings->Update( bHorz ? SID_RULER_ROWS : SID_RULER_ROWS_VERTICAL);
2680 0 : pBindings->Update( SID_RULER_OBJECT );
2681 0 : pBindings->Update( SID_RULER_PROTECT );
2682 0 : pBindings->Update( SID_ATTR_PARA_LRSPACE_VERTICAL );
2683 : }
2684 0 : sal_Bool bRTL = pRuler_Imp->pTextRTLItem && pRuler_Imp->pTextRTLItem->GetValue();
2685 0 : if(pTabStopItem &&
2686 0 : (nFlags & SVXRULER_SUPPORT_TABS) == SVXRULER_SUPPORT_TABS)
2687 : {
2688 0 : sal_Bool bContentProtected = pRuler_Imp->aProtectItem.IsCntntProtected();
2689 0 : if( bContentProtected ) return;
2690 0 : const long lPos = GetClickPos();
2691 0 : if((bRTL && lPos < std::min(GetFirstLineIndent(), GetLeftIndent()) && lPos > GetRightIndent()) ||
2692 0 : (!bRTL && lPos > std::min(GetFirstLineIndent(), GetLeftIndent()) && lPos < GetRightIndent()))
2693 : {
2694 : //convert position in left-to-right text
2695 : long nTabPos;
2696 : //#i24363# tab stops relative to indent
2697 0 : if(bRTL)
2698 : nTabPos = ( pRuler_Imp->bIsTabsRelativeToIndent ?
2699 : GetLeftIndent() :
2700 0 : ConvertHPosPixel( GetRightFrameMargin() + lAppNullOffset ) ) -
2701 0 : lPos;
2702 : else
2703 0 : nTabPos = lPos -
2704 : ( pRuler_Imp->bIsTabsRelativeToIndent ?
2705 : GetLeftIndent() :
2706 0 : 0 );
2707 :
2708 : SvxTabStop aTabStop(ConvertHPosLogic(nTabPos),
2709 0 : ToAttrTab_Impl(nDefTabType));
2710 0 : pTabStopItem->Insert(aTabStop);
2711 0 : UpdateTabs();
2712 : }
2713 : }
2714 : }
2715 :
2716 :
2717 0 : sal_Bool SvxRuler::CalcLimits
2718 : (
2719 : long &nMax1, // minimum value to be set
2720 : long &nMax2, // minimum value to be set
2721 : sal_Bool
2722 : ) const
2723 :
2724 : /* [Description]
2725 :
2726 : Default implementation of the virtual function; the application can be
2727 : overloaded to implement customized limits. The values are based on the page.
2728 : */
2729 : {
2730 0 : nMax1 = LONG_MIN;
2731 0 : nMax2 = LONG_MAX;
2732 0 : return sal_False;
2733 : }
2734 :
2735 :
2736 0 : void SvxRuler::CalcMinMax()
2737 :
2738 : /* [Description]
2739 :
2740 : Calculates the limits for dragging; which are in pixels relative to the
2741 : page edge
2742 : */
2743 :
2744 : {
2745 0 : sal_Bool bRTL = pRuler_Imp->pTextRTLItem && pRuler_Imp->pTextRTLItem->GetValue();
2746 0 : const long lNullPix = ConvertPosPixel(lLogicNullOffset);
2747 0 : pRuler_Imp->lMaxLeftLogic=pRuler_Imp->lMaxRightLogic=-1;
2748 0 : switch(GetDragType())
2749 : {
2750 : case RULER_TYPE_MARGIN1:
2751 : { // left edge of the surrounding Frame
2752 : // DragPos - NOf between left - right
2753 0 : pRuler_Imp->lMaxLeftLogic = GetLeftMin();
2754 0 : nMaxLeft=ConvertSizePixel(pRuler_Imp->lMaxLeftLogic);
2755 :
2756 0 : if(!pColumnItem || pColumnItem->Count() == 1 )
2757 : {
2758 0 : if(bRTL)
2759 : {
2760 0 : nMaxRight = lNullPix - GetRightIndent() +
2761 0 : std::max(GetFirstLineIndent(), GetLeftIndent()) -
2762 0 : lMinFrame;
2763 : }
2764 : else
2765 : {
2766 0 : nMaxRight = lNullPix + GetRightIndent() -
2767 0 : std::max(GetFirstLineIndent(), GetLeftIndent()) -
2768 0 : lMinFrame;
2769 : }
2770 : }
2771 0 : else if(pRuler_Imp->bIsTableRows)
2772 : {
2773 : //top border is not moveable when table rows are displayed
2774 : // protection of content means the margin is not moveable
2775 : // - it's just a page break inside of a cell
2776 0 : if(bHorz && !pRuler_Imp->aProtectItem.IsCntntProtected())
2777 : {
2778 0 : nMaxLeft = pBorders[0].nMinPos + lNullPix;
2779 0 : if(nDragType & DRAG_OBJECT_SIZE_PROPORTIONAL)
2780 0 : nMaxRight = GetRightIndent() + lNullPix -
2781 0 : (pColumnItem->Count() - 1 ) * lMinFrame;
2782 : else
2783 0 : nMaxRight = pBorders[0].nPos - lMinFrame + lNullPix;
2784 : }
2785 : else
2786 0 : nMaxLeft = nMaxRight = lNullPix;
2787 : }
2788 : else
2789 : {
2790 0 : if(nDragType & DRAG_OBJECT_SIZE_PROPORTIONAL)
2791 : {
2792 0 : nMaxRight=lNullPix+CalcPropMaxRight();
2793 : }
2794 0 : else if(nDragType & DRAG_OBJECT_SIZE_LINEAR)
2795 : {
2796 : nMaxRight = ConvertPosPixel(
2797 0 : GetPageWidth() - (
2798 0 : (pColumnItem->IsTable() && pLRSpaceItem)
2799 0 : ? pLRSpaceItem->GetRight() : 0))
2800 0 : - GetMargin2() + GetMargin1();
2801 : }
2802 : else
2803 : {
2804 0 : nMaxRight = lNullPix - lMinFrame;
2805 0 : if(pColumnItem->IsFirstAct())
2806 : {
2807 0 : if(bRTL)
2808 : {
2809 : nMaxRight += std::min(
2810 0 : pBorders[0].nPos,
2811 0 : std::max(GetFirstLineIndent(), GetLeftIndent()) - GetRightIndent());
2812 : }
2813 : else
2814 : {
2815 : nMaxRight += std::min(
2816 0 : pBorders[0].nPos, GetRightIndent() -
2817 0 : std::max(GetFirstLineIndent(), GetLeftIndent()));
2818 : }
2819 : }
2820 0 : else if( pColumnItem->Count() > 1 )
2821 0 : nMaxRight += pBorders[0].nPos;
2822 : else
2823 0 : nMaxRight +=GetRightIndent() -
2824 0 : std::max(GetFirstLineIndent(), GetLeftIndent());
2825 : // Do not drag the left table edge over the edge of the page
2826 0 : if(pLRSpaceItem&&pColumnItem->IsTable())
2827 : {
2828 0 : long nTmp=ConvertSizePixel(pLRSpaceItem->GetLeft());
2829 0 : if(nTmp>nMaxLeft)
2830 0 : nMaxLeft=nTmp;
2831 : }
2832 : }
2833 : }
2834 0 : break;
2835 : }
2836 : case RULER_TYPE_MARGIN2:
2837 : { // right edge of the surrounding Frame
2838 : pRuler_Imp->lMaxRightLogic =
2839 : pMinMaxItem ?
2840 0 : GetPageWidth() - GetRightMax() : GetPageWidth();
2841 0 : nMaxRight = ConvertSizePixel(pRuler_Imp->lMaxRightLogic);
2842 :
2843 :
2844 0 : if(!pColumnItem)
2845 : {
2846 0 : if(bRTL)
2847 : {
2848 0 : nMaxLeft = GetMargin2() + GetRightIndent() -
2849 0 : std::max(GetFirstLineIndent(),GetLeftIndent()) - GetMargin1()+
2850 0 : lMinFrame + lNullPix;
2851 : }
2852 : else
2853 : {
2854 0 : nMaxLeft = GetMargin2() - GetRightIndent() +
2855 0 : std::max(GetFirstLineIndent(),GetLeftIndent()) - GetMargin1()+
2856 0 : lMinFrame + lNullPix;
2857 : }
2858 : }
2859 0 : else if(pRuler_Imp->bIsTableRows)
2860 : {
2861 : // get the bottom move range from the last border position - only available for rows!
2862 : // protection of content means the margin is not moveable - it's just a page break inside of a cell
2863 0 : if(bHorz || pRuler_Imp->aProtectItem.IsCntntProtected())
2864 : {
2865 0 : nMaxLeft = nMaxRight = pBorders[pColumnItem->Count() - 1].nMaxPos + lNullPix;
2866 : }
2867 : else
2868 : {
2869 0 : if(nDragType & DRAG_OBJECT_SIZE_PROPORTIONAL)
2870 : {
2871 0 : nMaxLeft = (pColumnItem->Count()) * lMinFrame + lNullPix;
2872 : }
2873 : else
2874 : {
2875 0 : if(pColumnItem->Count() > 1)
2876 0 : nMaxLeft = pBorders[pColumnItem->Count() - 2].nPos + lMinFrame + lNullPix;
2877 : else
2878 0 : nMaxLeft = lMinFrame + lNullPix;
2879 : }
2880 0 : if(pColumnItem->Count() > 1)
2881 0 : nMaxRight = pBorders[pColumnItem->Count() - 2].nMaxPos + lNullPix;
2882 : else
2883 0 : nMaxRight -= GetRightIndent() - lNullPix;
2884 : }
2885 : }
2886 : else
2887 : {
2888 0 : nMaxLeft = lMinFrame + lNullPix;
2889 0 : if(IsActLastColumn() || pColumnItem->Count() < 2 ) //If last active column
2890 : {
2891 0 : if(bRTL)
2892 : {
2893 0 : nMaxLeft = lMinFrame + lNullPix + GetMargin2() +
2894 0 : GetRightIndent() - std::max(GetFirstLineIndent(),
2895 0 : GetLeftIndent());
2896 : }
2897 : else
2898 : {
2899 0 : nMaxLeft = lMinFrame + lNullPix + GetMargin2() -
2900 0 : GetRightIndent() + std::max(GetFirstLineIndent(),
2901 0 : GetLeftIndent());
2902 : }
2903 : }
2904 0 : if( pColumnItem->Count() >= 2 )
2905 : {
2906 : long nNewMaxLeft =
2907 0 : lMinFrame + lNullPix +
2908 0 : pBorders[pColumnItem->Count()-2].nPos +
2909 0 : pBorders[pColumnItem->Count()-2].nWidth;
2910 0 : nMaxLeft=std::max(nMaxLeft,nNewMaxLeft);
2911 : }
2912 :
2913 : }
2914 0 : break;
2915 : }
2916 : case RULER_TYPE_BORDER:
2917 : { // Table, column (Modifier)
2918 0 : const sal_uInt16 nIdx = GetDragAryPos();
2919 0 : switch(GetDragSize())
2920 : {
2921 : case RULER_DRAGSIZE_1 :
2922 : {
2923 0 : nMaxRight = pBorders[nIdx].nPos +
2924 0 : pBorders[nIdx].nWidth + lNullPix;
2925 :
2926 0 : if(0 == nIdx)
2927 0 : nMaxLeft = lNullPix;
2928 : else
2929 0 : nMaxLeft = pBorders[nIdx-1].nPos +
2930 0 : pBorders[nIdx-1].nWidth + lNullPix;
2931 0 : if(nIdx == pColumnItem->GetActColumn())
2932 : {
2933 0 : if(bRTL)
2934 : {
2935 0 : nMaxLeft += pBorders[nIdx].nPos +
2936 0 : GetRightIndent() - std::max(GetFirstLineIndent(),
2937 0 : GetLeftIndent());
2938 : }
2939 : else
2940 : {
2941 0 : nMaxLeft += pBorders[nIdx].nPos -
2942 0 : GetRightIndent() + std::max(GetFirstLineIndent(),
2943 0 : GetLeftIndent());
2944 : }
2945 0 : if(0 != nIdx)
2946 0 : nMaxLeft -= pBorders[nIdx-1].nPos +
2947 0 : pBorders[nIdx-1].nWidth;
2948 : }
2949 0 : nMaxLeft += lMinFrame;
2950 0 : nMaxLeft += nDragOffset;
2951 0 : break;
2952 : }
2953 : case RULER_DRAGSIZE_MOVE:
2954 : {
2955 0 : if(pColumnItem)
2956 : {
2957 : //nIdx contains the position of the currently moved item
2958 : //next visible separator on the left
2959 0 : sal_uInt16 nLeftCol=GetActLeftColumn(sal_False, nIdx);
2960 : //next visible separator on the right
2961 0 : sal_uInt16 nRightCol=GetActRightColumn(sal_False, nIdx);
2962 : //next separator on the left - regardless if visible or not
2963 0 : sal_uInt16 nActLeftCol=GetActLeftColumn();
2964 : //next separator on the right - regardless if visible or not
2965 0 : sal_uInt16 nActRightCol=GetActRightColumn();
2966 0 : if(pColumnItem->IsTable())
2967 : {
2968 0 : if(nDragType & DRAG_OBJECT_ACTLINE_ONLY)
2969 : {
2970 : //the current row/column should be modified only
2971 : //then the next/previous visible border position
2972 : //marks the min/max positions
2973 : nMaxLeft = nLeftCol == USHRT_MAX ?
2974 : 0 :
2975 0 : pBorders[nLeftCol].nPos;
2976 : //rows can always be increased without a limit
2977 0 : if(pRuler_Imp->bIsTableRows)
2978 0 : nMaxRight = pBorders[nIdx].nMaxPos;
2979 : else
2980 : nMaxRight = nRightCol == USHRT_MAX ?
2981 0 : GetMargin2():
2982 0 : pBorders[nRightCol].nPos;
2983 0 : nMaxLeft += lNullPix;
2984 0 : nMaxRight += lNullPix;
2985 : }
2986 : else
2987 : {
2988 0 : if(DRAG_OBJECT_SIZE_PROPORTIONAL & nDragType && !bHorz && pRuler_Imp->bIsTableRows)
2989 0 : nMaxLeft = (nIdx + 1) * lMinFrame + lNullPix;
2990 : else
2991 0 : nMaxLeft = pBorders[nIdx].nMinPos + lNullPix;
2992 0 : if(DRAG_OBJECT_SIZE_PROPORTIONAL & nDragType||
2993 0 : (DRAG_OBJECT_SIZE_LINEAR & nDragType) )
2994 : {
2995 0 : if(pRuler_Imp->bIsTableRows)
2996 : {
2997 0 : if(bHorz)
2998 0 : nMaxRight = GetRightIndent() + lNullPix -
2999 0 : (pColumnItem->Count() - nIdx - 1) * lMinFrame;
3000 : else
3001 0 : nMaxRight = pBorders[nIdx].nMaxPos + lNullPix;
3002 : }
3003 : else
3004 0 : nMaxRight=lNullPix+CalcPropMaxRight(nIdx);
3005 : }
3006 : else
3007 0 : nMaxRight = pBorders[nIdx].nMaxPos + lNullPix;
3008 : }
3009 0 : nMaxLeft += lMinFrame;
3010 0 : nMaxRight -= lMinFrame;
3011 :
3012 : }
3013 : else
3014 : {
3015 0 : if(nLeftCol==USHRT_MAX)
3016 0 : nMaxLeft=lNullPix;
3017 : else
3018 0 : nMaxLeft = pBorders[nLeftCol].nPos +
3019 0 : pBorders[nLeftCol].nWidth + lNullPix;
3020 :
3021 0 : if(nActRightCol == nIdx)
3022 : {
3023 0 : if(bRTL)
3024 : {
3025 0 : nMaxLeft += pBorders[nIdx].nPos +
3026 0 : GetRightIndent() - std::max(GetFirstLineIndent(),
3027 0 : GetLeftIndent());
3028 0 : if(nActLeftCol!=USHRT_MAX)
3029 0 : nMaxLeft -= pBorders[nActLeftCol].nPos +
3030 0 : pBorders[nActLeftCol].nWidth;
3031 : }
3032 : else
3033 : {
3034 0 : nMaxLeft += pBorders[nIdx].nPos -
3035 0 : GetRightIndent() + std::max(GetFirstLineIndent(),
3036 0 : GetLeftIndent());
3037 0 : if(nActLeftCol!=USHRT_MAX)
3038 0 : nMaxLeft -= pBorders[nActLeftCol].nPos +
3039 0 : pBorders[nActLeftCol].nWidth;
3040 : }
3041 : }
3042 0 : nMaxLeft += lMinFrame;
3043 0 : nMaxLeft += nDragOffset;
3044 :
3045 : // nMaxRight
3046 : // linear / proprotional move
3047 0 : if(DRAG_OBJECT_SIZE_PROPORTIONAL & nDragType||
3048 0 : (DRAG_OBJECT_SIZE_LINEAR & nDragType) )
3049 : {
3050 0 : nMaxRight=lNullPix+CalcPropMaxRight(nIdx);
3051 : }
3052 0 : else if(DRAG_OBJECT_SIZE_LINEAR & nDragType)
3053 : {
3054 0 : nMaxRight=lNullPix+GetMargin2()-GetMargin1()+
3055 0 : (nBorderCount-nIdx-1)*lMinFrame;
3056 : }
3057 : else
3058 : {
3059 0 : if(nRightCol==USHRT_MAX)
3060 : { // last column
3061 0 : nMaxRight = GetMargin2() + lNullPix;
3062 0 : if(IsActLastColumn())
3063 : {
3064 0 : if(bRTL)
3065 : {
3066 : nMaxRight -=
3067 0 : GetMargin2() + GetRightIndent() -
3068 0 : std::max(GetFirstLineIndent(),
3069 0 : GetLeftIndent());
3070 : }
3071 : else
3072 : {
3073 : nMaxRight -=
3074 0 : GetMargin2() - GetRightIndent() +
3075 0 : std::max(GetFirstLineIndent(),
3076 0 : GetLeftIndent());
3077 : }
3078 0 : nMaxRight += pBorders[nIdx].nPos +
3079 0 : pBorders[nIdx].nWidth;
3080 : }
3081 : }
3082 : else
3083 : {
3084 0 : nMaxRight = lNullPix + pBorders[nRightCol].nPos;
3085 : sal_uInt16 nNotHiddenRightCol =
3086 0 : GetActRightColumn(sal_True, nIdx);
3087 :
3088 0 : if( nActLeftCol == nIdx )
3089 : {
3090 : long nBorder = nNotHiddenRightCol ==
3091 : USHRT_MAX ?
3092 0 : GetMargin2() :
3093 0 : pBorders[nNotHiddenRightCol].nPos;
3094 0 : if(bRTL)
3095 : {
3096 0 : nMaxRight -= nBorder + GetRightIndent() -
3097 0 : std::max(GetFirstLineIndent(),
3098 0 : GetLeftIndent());
3099 : }
3100 : else
3101 : {
3102 0 : nMaxRight -= nBorder - GetRightIndent() +
3103 0 : std::max(GetFirstLineIndent(),
3104 0 : GetLeftIndent());
3105 : }
3106 0 : nMaxRight += pBorders[nIdx].nPos +
3107 0 : pBorders[nIdx].nWidth;
3108 : }
3109 : }
3110 0 : nMaxRight -= lMinFrame;
3111 0 : nMaxRight -= pBorders[nIdx].nWidth;
3112 : }
3113 : }
3114 : }
3115 : // ObjectItem
3116 : else
3117 : {
3118 0 : if(pObjectItem->HasLimits())
3119 : {
3120 0 : if(CalcLimits(nMaxLeft, nMaxRight, nIdx & 1? sal_False : sal_True))
3121 : {
3122 0 : nMaxLeft = ConvertPosPixel(nMaxLeft);
3123 0 : nMaxRight = ConvertPosPixel(nMaxRight);
3124 : }
3125 : }
3126 : else
3127 : {
3128 0 : nMaxLeft = LONG_MIN;
3129 0 : nMaxRight = LONG_MAX;
3130 : }
3131 : }
3132 0 : break;
3133 : }
3134 : case RULER_DRAGSIZE_2:
3135 : {
3136 0 : nMaxLeft = lNullPix + pBorders[nIdx].nPos;
3137 0 : if(nIdx == pColumnItem->Count()-2) { // last column
3138 0 : nMaxRight = GetMargin2() + lNullPix;
3139 0 : if(pColumnItem->IsLastAct()) {
3140 : nMaxRight -=
3141 0 : GetMargin2() - GetRightIndent() +
3142 0 : std::max(GetFirstLineIndent(),
3143 0 : GetLeftIndent());
3144 0 : nMaxRight += pBorders[nIdx].nPos +
3145 0 : pBorders[nIdx].nWidth;
3146 : }
3147 : }
3148 : else {
3149 0 : nMaxRight = lNullPix + pBorders[nIdx+1].nPos;
3150 0 : if(pColumnItem->GetActColumn()-1 == nIdx) {
3151 0 : nMaxRight -= pBorders[nIdx+1].nPos - GetRightIndent() +
3152 0 : std::max(GetFirstLineIndent(),
3153 0 : GetLeftIndent());
3154 0 : nMaxRight += pBorders[nIdx].nPos +
3155 0 : pBorders[nIdx].nWidth;
3156 : }
3157 : }
3158 0 : nMaxRight -= lMinFrame;
3159 0 : nMaxRight -= pBorders[nIdx].nWidth;
3160 0 : break;
3161 : }
3162 : }
3163 0 : nMaxRight += nDragOffset;
3164 0 : break;
3165 : }
3166 : case RULER_TYPE_INDENT:
3167 : {
3168 0 : const sal_uInt16 nIdx = GetDragAryPos();
3169 0 : switch(nIdx) {
3170 : case INDENT_FIRST_LINE - INDENT_GAP:
3171 : case INDENT_LEFT_MARGIN - INDENT_GAP:
3172 : {
3173 0 : if(bRTL)
3174 : {
3175 0 : nMaxLeft = lNullPix + GetRightIndent();
3176 :
3177 0 : if(pColumnItem && !pColumnItem->IsFirstAct())
3178 0 : nMaxLeft += pBorders[pColumnItem->GetActColumn()-1].nPos +
3179 0 : pBorders[pColumnItem->GetActColumn()-1].nWidth;
3180 0 : nMaxRight = lNullPix + GetMargin2();
3181 :
3182 : // Dragging along
3183 0 : if((INDENT_FIRST_LINE - INDENT_GAP) != nIdx &&
3184 0 : (nDragType & DRAG_OBJECT_LEFT_INDENT_ONLY) !=
3185 : DRAG_OBJECT_LEFT_INDENT_ONLY)
3186 : {
3187 0 : if(GetLeftIndent() > GetFirstLineIndent())
3188 0 : nMaxLeft += GetLeftIndent() - GetFirstLineIndent();
3189 : else
3190 0 : nMaxRight -= GetFirstLineIndent() - GetLeftIndent();
3191 : }
3192 : }
3193 : else
3194 : {
3195 0 : nMaxLeft = lNullPix;
3196 :
3197 0 : if(pColumnItem && !pColumnItem->IsFirstAct())
3198 0 : nMaxLeft += pBorders[pColumnItem->GetActColumn()-1].nPos +
3199 0 : pBorders[pColumnItem->GetActColumn()-1].nWidth;
3200 0 : nMaxRight = lNullPix + GetRightIndent() - lMinFrame;
3201 :
3202 : // Dragging along
3203 0 : if((INDENT_FIRST_LINE - INDENT_GAP) != nIdx &&
3204 0 : (nDragType & DRAG_OBJECT_LEFT_INDENT_ONLY) !=
3205 : DRAG_OBJECT_LEFT_INDENT_ONLY)
3206 : {
3207 0 : if(GetLeftIndent() > GetFirstLineIndent())
3208 0 : nMaxLeft += GetLeftIndent() - GetFirstLineIndent();
3209 : else
3210 0 : nMaxRight -= GetFirstLineIndent() - GetLeftIndent();
3211 : }
3212 : }
3213 : }
3214 0 : break;
3215 : case INDENT_RIGHT_MARGIN - INDENT_GAP:
3216 : {
3217 0 : if(bRTL)
3218 : {
3219 0 : nMaxLeft = lNullPix;
3220 0 : nMaxRight = lNullPix + std::min(GetFirstLineIndent(), GetLeftIndent()) - lMinFrame;
3221 0 : if(pColumnItem)
3222 : {
3223 0 : sal_uInt16 nRightCol=GetActRightColumn( sal_True );
3224 0 : if(!IsActLastColumn( sal_True ))
3225 0 : nMaxRight += pBorders[nRightCol].nPos;
3226 : else
3227 0 : nMaxRight += GetMargin2();
3228 : }
3229 : else
3230 0 : nMaxLeft += GetMargin1();
3231 0 : nMaxLeft += lMinFrame;
3232 : }
3233 : else
3234 : {
3235 0 : nMaxLeft = lNullPix +
3236 0 : std::max(GetFirstLineIndent(), GetLeftIndent());
3237 0 : nMaxRight = lNullPix;
3238 0 : if(pColumnItem)
3239 : {
3240 0 : sal_uInt16 nRightCol=GetActRightColumn( sal_True );
3241 0 : if(!IsActLastColumn( sal_True ))
3242 0 : nMaxRight += pBorders[nRightCol].nPos;
3243 : else
3244 0 : nMaxRight += GetMargin2();
3245 : }
3246 : else
3247 0 : nMaxRight += GetMargin2();
3248 0 : nMaxLeft += lMinFrame;
3249 : }
3250 : }
3251 0 : break;
3252 : }
3253 0 : break;
3254 : }
3255 : case RULER_TYPE_TAB: // Tabs (Modifier)
3256 : /*
3257 : left = NOf + Max(LAR, EZ)
3258 : right = NOf + RAR
3259 : */
3260 0 : nMaxLeft = bRTL ? lNullPix + GetRightIndent()
3261 0 : : lNullPix + std::min(GetFirstLineIndent(), GetLeftIndent());
3262 0 : pRuler_Imp->lMaxRightLogic=GetLogicRightIndent()+lLogicNullOffset;
3263 0 : nMaxRight = ConvertSizePixel(pRuler_Imp->lMaxRightLogic);
3264 0 : break;
3265 : default: ; //prevent warning
3266 : }
3267 : #ifdef DEBUGLIN
3268 : {
3269 : String aStr("MinLeft: ");
3270 : Size aSize(nMaxLeft + lNullPix, 0);
3271 : Size aSize2(nMaxRight + lNullPix, 0);
3272 : aSize = pEditWin->PixelToLogic(aSize, MapMode(MAP_MM));
3273 : aSize2 = pEditWin->PixelToLogic(aSize2, MapMode(MAP_MM));
3274 : aStr += String(aSize.Width());
3275 : aStr += " MaxRight: ";
3276 : aStr += String(aSize2.Width());
3277 : InfoBox(0, aStr).Execute();
3278 : }
3279 : #endif
3280 0 : }
3281 :
3282 :
3283 0 : long SvxRuler::StartDrag()
3284 :
3285 : /* [Description]
3286 :
3287 : Beginning of a drag operation (SV-handler) evaluates modifier and
3288 : calculated values
3289 :
3290 : [Cross-reference]
3291 :
3292 : <SvxRuler::EvalModifier()>
3293 : <SvxRuler::CalcMinMax()>
3294 : <SvxRuler::EndDrag()>
3295 : */
3296 :
3297 : {
3298 0 : sal_Bool bContentProtected = pRuler_Imp->aProtectItem.IsCntntProtected();
3299 0 : if(!bValid)
3300 0 : return sal_False;
3301 :
3302 0 : pRuler_Imp->lLastLMargin=GetMargin1();
3303 0 : pRuler_Imp->lLastRMargin=GetMargin2();
3304 0 : long bOk = 1;
3305 0 : if(GetStartDragHdl().IsSet())
3306 0 : bOk = Ruler::StartDrag();
3307 0 : if(bOk) {
3308 0 : lInitialDragPos = GetDragPos();
3309 0 : switch(GetDragType()) {
3310 : case RULER_TYPE_MARGIN1: // left edge of the surrounding Frame
3311 : case RULER_TYPE_MARGIN2: // right edge of the surrounding Frame
3312 0 : if((bHorz && pLRSpaceItem) || (!bHorz && pULSpaceItem))
3313 : {
3314 0 : if(pColumnItem)
3315 0 : EvalModifier();
3316 : else
3317 0 : nDragType = DRAG_OBJECT;
3318 : }
3319 : else
3320 0 : bOk = sal_False;
3321 0 : break;
3322 : case RULER_TYPE_BORDER: // Table, column (Modifier)
3323 0 : if(pColumnItem)
3324 : {
3325 0 : nDragOffset = pColumnItem->IsTable()? 0 :
3326 0 : GetDragPos() - pBorders[GetDragAryPos()].nPos;
3327 0 : EvalModifier();
3328 :
3329 : }
3330 : else
3331 0 : nDragOffset = 0;
3332 0 : break;
3333 : case RULER_TYPE_INDENT: { // Paragraph indents (Modifier)
3334 0 : if( bContentProtected )
3335 0 : return sal_False;
3336 0 : sal_uInt16 nIndent = INDENT_LEFT_MARGIN;
3337 0 : if((nIndent) == GetDragAryPos() + INDENT_GAP) { // Left paragraph indent
3338 0 : pIndents[0] = pIndents[INDENT_FIRST_LINE];
3339 0 : pIndents[0].nStyle |= RULER_STYLE_DONTKNOW;
3340 0 : EvalModifier();
3341 : }
3342 : else
3343 0 : nDragType = DRAG_OBJECT;
3344 0 : pIndents[1] = pIndents[GetDragAryPos()+INDENT_GAP];
3345 0 : pIndents[1].nStyle |= RULER_STYLE_DONTKNOW;
3346 0 : break;
3347 : }
3348 : case RULER_TYPE_TAB: // Tabs (Modifier)
3349 0 : if( bContentProtected ) return sal_False;
3350 0 : EvalModifier();
3351 0 : pTabs[0] = pTabs[GetDragAryPos()+1];
3352 0 : pTabs[0].nStyle |= RULER_STYLE_DONTKNOW;
3353 0 : break;
3354 : default:
3355 0 : nDragType = NONE;
3356 : }
3357 : }
3358 : else
3359 0 : nDragType = NONE;
3360 0 : if(bOk)
3361 0 : CalcMinMax();
3362 0 : return bOk;
3363 : }
3364 :
3365 :
3366 0 : void SvxRuler::Drag()
3367 :
3368 : /* [Description]
3369 :
3370 : SV-Draghandler
3371 : */
3372 : {
3373 0 : if(IsDragCanceled())
3374 : {
3375 0 : Ruler::Drag();
3376 0 : return;
3377 : }
3378 0 : switch(GetDragType()) {
3379 : case RULER_TYPE_MARGIN1: // left edge of the surrounding Frame
3380 0 : DragMargin1();
3381 0 : pRuler_Imp->lLastLMargin=GetMargin1();
3382 0 : break;
3383 : case RULER_TYPE_MARGIN2: // right edge of the surrounding Frame
3384 0 : DragMargin2();
3385 0 : pRuler_Imp->lLastRMargin = GetMargin2();
3386 0 : break;
3387 : case RULER_TYPE_INDENT: // Paragraph indents
3388 0 : DragIndents();
3389 0 : break;
3390 : case RULER_TYPE_BORDER: // Table, columns
3391 0 : if(pColumnItem)
3392 0 : DragBorders();
3393 0 : else if(pObjectItem)
3394 0 : DragObjectBorder();
3395 0 : break;
3396 : case RULER_TYPE_TAB: // Tabs
3397 0 : DragTabs();
3398 0 : break;
3399 : default: ;//prevent warning
3400 : }
3401 0 : Ruler::Drag();
3402 : }
3403 :
3404 :
3405 0 : void SvxRuler::EndDrag()
3406 :
3407 : /* [Description]
3408 :
3409 : SV-handler; is called when ending the dragging. Triggers the updating of data
3410 : on the application, by calling the respective Apply...() methods to send the
3411 : data to the application.
3412 : */
3413 : {
3414 0 : const sal_Bool bUndo = IsDragCanceled();
3415 0 : const long lPos = GetDragPos();
3416 0 : DrawLine_Impl(lTabPos, 6, bHorz);
3417 0 : lTabPos=-1;
3418 0 : if(!bUndo)
3419 0 : switch(GetDragType())
3420 : {
3421 : case RULER_TYPE_MARGIN1: // upper left edge of the surrounding Frame
3422 : case RULER_TYPE_MARGIN2: // lower right edge of the surrounding Frame
3423 : {
3424 0 : if(!pColumnItem || !pColumnItem->IsTable())
3425 0 : ApplyMargins();
3426 :
3427 0 : if(pColumnItem &&
3428 0 : (pColumnItem->IsTable() ||
3429 0 : (nDragType & DRAG_OBJECT_SIZE_PROPORTIONAL)))
3430 0 : ApplyBorders();
3431 :
3432 : }
3433 0 : break;
3434 : case RULER_TYPE_BORDER: // Table, columns
3435 0 : if(lInitialDragPos != lPos ||
3436 0 : (pRuler_Imp->bIsTableRows && bHorz)) //special case - the null offset is changed here
3437 : {
3438 0 : if(pColumnItem)
3439 : {
3440 0 : ApplyBorders();
3441 0 : if(bHorz)
3442 0 : UpdateTabs();
3443 : }
3444 0 : else if(pObjectItem)
3445 0 : ApplyObject();
3446 : }
3447 0 : break;
3448 : case RULER_TYPE_INDENT: // Paragraph indents
3449 0 : if(lInitialDragPos != lPos)
3450 0 : ApplyIndents();
3451 0 : SetIndents(INDENT_COUNT, pIndents+INDENT_GAP);
3452 0 : break;
3453 : case RULER_TYPE_TAB: // Tabs
3454 : {
3455 0 : ApplyTabs();
3456 0 : pTabs[GetDragAryPos()].nStyle &= ~RULER_STYLE_INVISIBLE;
3457 0 : SetTabs(nTabCount, pTabs+TAB_GAP);
3458 : }
3459 0 : break;
3460 : default: ; //prevent warning
3461 : }
3462 0 : nDragType = NONE;
3463 0 : Ruler::EndDrag();
3464 0 : if(bUndo)
3465 0 : for(sal_uInt16 i=0;i<pRuler_Imp->nControlerItems;i++)
3466 : {
3467 0 : pCtrlItem[i]->ClearCache();
3468 0 : pCtrlItem[i]->GetBindings().Invalidate(pCtrlItem[i]->GetId());
3469 : }
3470 0 : }
3471 :
3472 :
3473 0 : void SvxRuler::ExtraDown()
3474 :
3475 : /* [Description]
3476 :
3477 : Overloaded SV method, sets the new type for the Default tab.
3478 : */
3479 :
3480 : {
3481 : // Switch Tab Type
3482 0 : if(pTabStopItem &&
3483 0 : (nFlags & SVXRULER_SUPPORT_TABS) == SVXRULER_SUPPORT_TABS) {
3484 0 : ++nDefTabType;
3485 0 : if(RULER_TAB_DEFAULT == nDefTabType)
3486 0 : nDefTabType = RULER_TAB_LEFT;
3487 0 : SetExtraType(RULER_EXTRA_TAB, nDefTabType);
3488 : }
3489 0 : Ruler::ExtraDown();
3490 0 : }
3491 :
3492 :
3493 500 : void SvxRuler::Notify(SfxBroadcaster&, const SfxHint& rHint)
3494 :
3495 : /* [Description]
3496 :
3497 : Report through the bindings that the status update is completed. The ruler
3498 : updates its appearance and gets registered again in the bindings.
3499 : */
3500 :
3501 : {
3502 : // start update
3503 1000 : if(bActive &&
3504 995 : rHint.Type() == TYPE(SfxSimpleHint) &&
3505 495 : ((SfxSimpleHint&) rHint ).GetId() == SFX_HINT_UPDATEDONE ) {
3506 493 : Update();
3507 493 : EndListening(*pBindings);
3508 493 : bValid = sal_True;
3509 493 : bListening = sal_False;
3510 : }
3511 500 : }
3512 :
3513 :
3514 0 : IMPL_LINK_INLINE_START( SvxRuler, MenuSelect, Menu *, pMenu )
3515 :
3516 : /* [Description]
3517 :
3518 : Handler of the context menus for switching the unit of measurement
3519 : */
3520 :
3521 : {
3522 0 : SetUnit(FieldUnit(pMenu->GetCurItemId()));
3523 0 : return 0;
3524 : }
3525 0 : IMPL_LINK_INLINE_END( SvxRuler, MenuSelect, Menu *, pMenu )
3526 :
3527 :
3528 0 : IMPL_LINK( SvxRuler, TabMenuSelect, Menu *, pMenu )
3529 :
3530 : /* [Description]
3531 :
3532 : Handler of the tab menu for setting the type
3533 : */
3534 :
3535 : {
3536 0 : if(pTabStopItem && pTabStopItem->Count() > pRuler_Imp->nIdx)
3537 : {
3538 0 : SvxTabStop aTabStop = (*pTabStopItem)[pRuler_Imp->nIdx];
3539 0 : aTabStop.GetAdjustment() = ToAttrTab_Impl(pMenu->GetCurItemId()-1);
3540 0 : pTabStopItem->Remove(pRuler_Imp->nIdx);
3541 0 : pTabStopItem->Insert(aTabStop);
3542 0 : sal_uInt16 nTabStopId = bHorz ? SID_ATTR_TABSTOP : SID_ATTR_TABSTOP_VERTICAL;
3543 0 : pBindings->GetDispatcher()->Execute( nTabStopId, SFX_CALLMODE_RECORD, pTabStopItem, 0L );
3544 0 : UpdateTabs();
3545 0 : pRuler_Imp->nIdx = 0;
3546 : }
3547 0 : return 0;
3548 : }
3549 :
3550 :
3551 0 : void SvxRuler::Command( const CommandEvent& rCEvt )
3552 :
3553 : /* [Description]
3554 :
3555 : Mouse context menu for switching the unit of measurement
3556 : */
3557 :
3558 : {
3559 0 : if ( COMMAND_CONTEXTMENU == rCEvt.GetCommand() )
3560 : {
3561 0 : CancelDrag();
3562 0 : sal_Bool bRTL = pRuler_Imp->pTextRTLItem && pRuler_Imp->pTextRTLItem->GetValue();
3563 0 : if ( pTabs &&
3564 : RULER_TYPE_TAB ==
3565 0 : GetType( rCEvt.GetMousePosPixel(), &pRuler_Imp->nIdx ) &&
3566 0 : pTabs[pRuler_Imp->nIdx+TAB_GAP].nStyle < RULER_TAB_DEFAULT )
3567 : {
3568 0 : PopupMenu aMenu;
3569 0 : aMenu.SetSelectHdl(LINK(this, SvxRuler, TabMenuSelect));
3570 0 : VirtualDevice aDev;
3571 0 : const Size aSz(RULER_TAB_WIDTH+2, RULER_TAB_HEIGHT+2);
3572 0 : aDev.SetOutputSize(aSz);
3573 0 : aDev.SetBackground(Wallpaper(Color(COL_WHITE)));
3574 0 : Color aFillColor(aDev.GetSettings().GetStyleSettings().GetShadowColor());
3575 0 : const Point aPt(aSz.Width() / 2, aSz.Height() / 2);
3576 :
3577 0 : for ( sal_uInt16 i = RULER_TAB_LEFT; i < RULER_TAB_DEFAULT; ++i )
3578 : {
3579 0 : sal_uInt16 nStyle = bRTL ? i|RULER_TAB_RTL : i;
3580 0 : nStyle |= (sal_uInt16)(bHorz ? WB_HORZ : WB_VERT);
3581 0 : DrawTab(&aDev, aFillColor, aPt, nStyle);
3582 : aMenu.InsertItem(i+1,
3583 0 : String(ResId(RID_SVXSTR_RULER_START+i, DIALOG_MGR())),
3584 0 : Image(aDev.GetBitmap(Point(), aSz), Color(COL_WHITE)));
3585 0 : aMenu.CheckItem(i+1, i == pTabs[pRuler_Imp->nIdx+TAB_GAP].nStyle);
3586 0 : aDev.SetOutputSize(aSz); // delete device
3587 : }
3588 0 : aMenu.Execute( this, rCEvt.GetMousePosPixel() );
3589 : }
3590 : else
3591 : {
3592 0 : PopupMenu aMenu(ResId(RID_SVXMN_RULER, DIALOG_MGR()));
3593 0 : aMenu.SetSelectHdl(LINK(this, SvxRuler, MenuSelect));
3594 0 : FieldUnit eUnit = GetUnit();
3595 0 : const sal_uInt16 nCount = aMenu.GetItemCount();
3596 :
3597 0 : sal_Bool bReduceMetric = 0 != (nFlags &SVXRULER_SUPPORT_REDUCED_METRIC);
3598 0 : for ( sal_uInt16 i = nCount; i; --i )
3599 : {
3600 0 : const sal_uInt16 nId = aMenu.GetItemId(i - 1);
3601 0 : aMenu.CheckItem(nId, nId == (sal_uInt16)eUnit);
3602 0 : if(bReduceMetric &&
3603 0 : (nId == FUNIT_M ||
3604 0 : nId == FUNIT_KM ||
3605 0 : nId == FUNIT_FOOT ||
3606 0 : nId == FUNIT_MILE ||
3607 0 : nId == FUNIT_CHAR ||
3608 : nId == FUNIT_LINE ))
3609 : {
3610 0 : if (( nId == FUNIT_CHAR ) && bHorz )
3611 : ;
3612 0 : else if (( nId == FUNIT_LINE ) && !bHorz )
3613 : ;
3614 : else
3615 0 : aMenu.RemoveItem(i - 1);
3616 : }
3617 : }
3618 0 : aMenu.Execute( this, rCEvt.GetMousePosPixel() );
3619 : }
3620 : }
3621 : else
3622 0 : Ruler::Command( rCEvt );
3623 0 : }
3624 :
3625 :
3626 6 : sal_uInt16 SvxRuler::GetActRightColumn(
3627 : sal_Bool bForceDontConsiderHidden, sal_uInt16 nAct ) const
3628 : {
3629 6 : if( nAct == USHRT_MAX )
3630 6 : nAct = pColumnItem->GetActColumn();
3631 0 : else nAct++; //To be able to pass on the ActDrag
3632 :
3633 6 : sal_Bool bConsiderHidden = !bForceDontConsiderHidden &&
3634 6 : !( nDragType & DRAG_OBJECT_ACTLINE_ONLY );
3635 :
3636 12 : while( nAct < pColumnItem->Count() - 1 )
3637 : {
3638 6 : if( (*pColumnItem)[nAct].bVisible || bConsiderHidden )
3639 6 : return nAct;
3640 : else
3641 0 : nAct++;
3642 : }
3643 0 : return USHRT_MAX;
3644 : }
3645 :
3646 :
3647 :
3648 0 : sal_uInt16 SvxRuler::GetActLeftColumn(
3649 : sal_Bool bForceDontConsiderHidden, sal_uInt16 nAct ) const
3650 : {
3651 0 : if(nAct==USHRT_MAX)
3652 0 : nAct=pColumnItem->GetActColumn();
3653 :
3654 0 : sal_uInt16 nLOffs=1;
3655 :
3656 0 : sal_Bool bConsiderHidden = !bForceDontConsiderHidden &&
3657 0 : !( nDragType & DRAG_OBJECT_ACTLINE_ONLY );
3658 :
3659 0 : while(nAct>=nLOffs)
3660 : {
3661 0 : if( (*pColumnItem)[ nAct - nLOffs ].bVisible || bConsiderHidden )
3662 0 : return nAct-nLOffs;
3663 : else
3664 0 : nLOffs++;
3665 : }
3666 0 : return USHRT_MAX;
3667 : }
3668 :
3669 :
3670 3 : sal_Bool SvxRuler::IsActLastColumn(
3671 : sal_Bool bForceDontConsiderHidden, sal_uInt16 nAct) const
3672 : {
3673 3 : return GetActRightColumn(bForceDontConsiderHidden, nAct)==USHRT_MAX;
3674 : }
3675 :
3676 0 : sal_Bool SvxRuler::IsActFirstColumn(
3677 : sal_Bool bForceDontConsiderHidden, sal_uInt16 nAct) const
3678 : {
3679 0 : return GetActLeftColumn(bForceDontConsiderHidden, nAct)==USHRT_MAX;
3680 : }
3681 :
3682 0 : long SvxRuler::CalcPropMaxRight(sal_uInt16 nCol) const
3683 : {
3684 :
3685 0 : if(!(nDragType & DRAG_OBJECT_SIZE_LINEAR))
3686 : {
3687 : // Remove the minimum width for all affected columns
3688 : // starting from the right edge
3689 0 : long _nMaxRight = GetMargin2()-GetMargin1();
3690 :
3691 0 : long lFences=0;
3692 0 : long lMinSpace=USHRT_MAX;
3693 : long lOldPos;
3694 0 : long lColumns=0;
3695 : sal_uInt16 nStart;
3696 0 : if(!pColumnItem->IsTable())
3697 : {
3698 0 : if(nCol==USHRT_MAX)
3699 : {
3700 0 : lOldPos=GetMargin1();
3701 0 : nStart=0;
3702 : }
3703 : else
3704 : {
3705 0 : lOldPos=pBorders[nCol].nPos+pBorders[nCol].nWidth;
3706 0 : nStart=nCol+1;
3707 0 : lFences=pBorders[nCol].nWidth;
3708 : }
3709 :
3710 0 : for(sal_uInt16 i = nStart; i < nBorderCount-1; ++i)
3711 : {
3712 0 : long lWidth=pBorders[i].nPos-lOldPos;
3713 0 : lColumns+=lWidth;
3714 0 : if(lWidth<lMinSpace)
3715 0 : lMinSpace=lWidth;
3716 0 : lOldPos=pBorders[i].nPos+pBorders[i].nWidth;
3717 0 : lFences+=pBorders[i].nWidth;
3718 : }
3719 0 : long lWidth=GetMargin2()-lOldPos;
3720 0 : lColumns+=lWidth;
3721 0 : if(lWidth<lMinSpace)
3722 0 : lMinSpace=lWidth;
3723 : }
3724 : else
3725 : {
3726 : sal_uInt16 nActCol;
3727 0 : if(nCol==USHRT_MAX) //CalcMinMax for LeftMargin
3728 : {
3729 0 : lOldPos=GetMargin1();
3730 : }
3731 : else
3732 : {
3733 0 : lOldPos=pBorders[nCol].nPos;
3734 : }
3735 0 : lColumns=GetMargin2()-lOldPos;
3736 0 : nActCol=nCol;
3737 0 : lFences=0;
3738 0 : while(nActCol<nBorderCount||nActCol==USHRT_MAX)
3739 : {
3740 : sal_uInt16 nRight;
3741 0 : if(nActCol==USHRT_MAX)
3742 : {
3743 0 : nRight=0;
3744 0 : while(!(*pColumnItem)[nRight].bVisible)
3745 0 : nRight++;
3746 : }
3747 : else
3748 0 : nRight=GetActRightColumn(sal_False, nActCol);
3749 : long lWidth;
3750 0 : if(nRight!=USHRT_MAX)
3751 : {
3752 0 : lWidth=pBorders[nRight].nPos-lOldPos;
3753 0 : lOldPos=pBorders[nRight].nPos;
3754 : }
3755 : else
3756 0 : lWidth=GetMargin2()-lOldPos;
3757 0 : nActCol=nRight;
3758 0 : if(lWidth<lMinSpace)
3759 0 : lMinSpace=lWidth;
3760 0 : if(nActCol==USHRT_MAX)
3761 0 : break;
3762 : }
3763 : }
3764 :
3765 0 : _nMaxRight-=(long)(lFences+lMinFrame/(float)lMinSpace*lColumns);
3766 0 : return _nMaxRight;
3767 : }
3768 : else
3769 : {
3770 0 : if(pColumnItem->IsTable())
3771 : {
3772 0 : sal_uInt16 nVisCols=0;
3773 0 : for(sal_uInt16 i=GetActRightColumn(sal_False, nCol);i<nBorderCount;)
3774 : {
3775 0 : if((*pColumnItem)[i].bVisible)
3776 0 : nVisCols++;
3777 0 : i=GetActRightColumn(sal_False, i);
3778 : }
3779 0 : return GetMargin2()-GetMargin1()-(nVisCols+1)*lMinFrame;
3780 : }
3781 : else
3782 : {
3783 0 : long lWidth=0;
3784 0 : for(sal_uInt16 i=nCol;i<nBorderCount-1;i++)
3785 : {
3786 0 : lWidth+=lMinFrame+pBorders[i].nWidth;
3787 : }
3788 0 : return GetMargin2()-GetMargin1()-lWidth;
3789 : }
3790 : }
3791 : }
3792 :
3793 : // Tab stops relative to indent (#i24363#)
3794 540 : void SvxRuler::SetTabsRelativeToIndent( sal_Bool bRel )
3795 : {
3796 540 : pRuler_Imp->bIsTabsRelativeToIndent = bRel;
3797 756 : }
3798 :
3799 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|