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