[Libreoffice-commits] core.git: 3 commits - include/svtools svtools/source svx/source
Tomaž Vajngerl
quikee at gmail.com
Mon Sep 2 22:49:40 PDT 2013
include/svtools/ruler.hxx | 19 -
svtools/source/control/ruler.cxx | 641 +++++++++++++++++++++------------------
svx/source/dialog/svxruler.cxx | 91 +++--
3 files changed, 420 insertions(+), 331 deletions(-)
New commits:
commit dda8877b989ebe330315e94523b983a6803e1372
Author: Tomaž Vajngerl <quikee at gmail.com>
Date: Mon Sep 2 23:25:33 2013 +0200
Ruler: minimal unit 1/16 inch, 1/10 cm, dynamic tick draw, various
- minimal unit for inch is 1/16 and for cm 1/10 (1mm)
- additional tick level (now 4 in total)
- top and bottom tick in addition to the number (highes tick level)
- dynamically draw tick levels depending on the tick gap (should be
at least 6 pixel wide)
Change-Id: I0598b16e32d19eb1294a2358eacbeb19a70966a2
diff --git a/include/svtools/ruler.hxx b/include/svtools/ruler.hxx
index 97d27fb..7bcc67d 100644
--- a/include/svtools/ruler.hxx
+++ b/include/svtools/ruler.hxx
@@ -592,9 +592,10 @@ struct RulerUnitData
{
MapUnit eMapUnit; // MAP_UNIT for calculaion
long nTickUnit; // Unit divider
- long nTick1; // Minimal step
- long nTick2; // Tick half unit
- long nTick3; // Tick whole unit
+ double nTick1; // Minimal step
+ double nTick2; // Tick quarter unit
+ double nTick3; // Tick half unit
+ double nTick4; // Tick whole unit
long n100THMM; // 100mm Unit divider
sal_uInt16 nUnitDigits; // Number of digits
sal_Char aUnitStr[8]; // Unit string
@@ -665,7 +666,7 @@ private:
SVT_DLLPRIVATE void ImplVDrawRect( long nX1, long nY1, long nX2, long nY2 );
SVT_DLLPRIVATE void ImplVDrawText( long nX, long nY, const OUString& rText, long nMin = LONG_MIN, long nMax = LONG_MAX );
- SVT_DLLPRIVATE void ImplDrawTicks( long nMin, long nMax, long nStart, long nCenter );
+ SVT_DLLPRIVATE void ImplDrawTicks( long nMin, long nMax, long nStart, long nVirTop, long nVirBottom );
SVT_DLLPRIVATE void ImplDrawBorders( long nMin, long nMax, long nVirTop, long nVirBottom );
SVT_DLLPRIVATE void ImplDrawIndent( const Polygon& rPoly, sal_uInt16 nStyle, bool bIsHit = false );
SVT_DLLPRIVATE void ImplDrawIndents( long nMin, long nMax, long nVirTop, long nVirBottom );
diff --git a/svtools/source/control/ruler.cxx b/svtools/source/control/ruler.cxx
index 494fe26..5740bcb 100644
--- a/svtools/source/control/ruler.cxx
+++ b/svtools/source/control/ruler.cxx
@@ -37,9 +37,6 @@ using namespace std;
#define RULER_RESIZE_OFF 4
#define RULER_MIN_SIZE 3
-#define RULER_TICK1_WIDTH 1
-#define RULER_TICK2_WIDTH 3
-
#define RULER_VAR_SIZE 8
#define RULER_TAB_HEIGHT2 2
@@ -112,17 +109,17 @@ public:
static const RulerUnitData aImplRulerUnitTab[RULER_UNIT_COUNT] =
{
-{ MAP_100TH_MM, 100, 25, 50, 100, 100, 3, " mm" }, // MM
-{ MAP_100TH_MM, 1000, 250, 500, 1000, 1000, 3, " cm" }, // CM
-{ MAP_MM, 1000, 250, 500, 1000, 10000, 4, " m" }, // M
-{ MAP_CM, 100000, 25000, 50000, 100000, 100000, 6, " km" }, // KM
-{ MAP_1000TH_INCH, 1000, 125, 500, 1000, 25400, 3, "\"" }, // INCH
-{ MAP_100TH_INCH, 1200, 120, 600, 1200, 30480, 3, "'" }, // FOOT
-{ MAP_10TH_INCH, 633600, 63360, 316800, 633600, 1609344, 4, " miles" }, // MILE
-{ MAP_POINT, 1, 12, 12, 36, 353, 2, " pt" }, // POINT
-{ MAP_100TH_MM, 423, 423, 423, 846, 423, 3, " pi" }, // PICA
-{ MAP_100TH_MM, 371, 371, 371, 743, 371, 3, " ch" }, // CHAR
-{ MAP_100TH_MM, 551, 551, 551, 1102, 551, 3, " li" } // LINE
+{ MAP_100TH_MM, 100, 25.0, 25.0, 50.0, 100.0, 100, 3, " mm" }, // MM
+{ MAP_100TH_MM, 1000, 100.0, 500.0, 1000.0, 1000.0, 1000, 3, " cm" }, // CM
+{ MAP_MM, 1000, 10.0, 250.0, 500.0, 1000.0, 10000, 4, " m" }, // M
+{ MAP_CM, 100000, 12500.0, 25000.0, 50000.0, 100000.0, 100000, 6, " km" }, // KM
+{ MAP_1000TH_INCH, 1000, 62.5, 125.0, 500.0, 1000.0, 25400, 3, "\"" }, // INCH
+{ MAP_100TH_INCH, 1200, 120.0, 120.0, 600.0, 1200.0, 30480, 3, "'" }, // FOOT
+{ MAP_10TH_INCH, 633600, 63360.0, 63360.0, 316800.0, 633600.0, 1609344, 4, " miles" }, // MILE
+{ MAP_POINT, 1, 12.0, 12.0, 12.0, 36.0, 353, 2, " pt" }, // POINT
+{ MAP_100TH_MM, 423, 423.0, 423.0, 423.0, 846.0, 423, 3, " pi" }, // PICA
+{ MAP_100TH_MM, 371, 371.0, 371.0, 371.0, 743.0, 371, 3, " ch" }, // CHAR
+{ MAP_100TH_MM, 551, 551.0, 551.0, 551.0, 1102.0, 551, 3, " li" } // LINE
};
// =======================================================================
@@ -297,7 +294,7 @@ void Ruler::ImplInit( WinBits nWinBits )
// Setup the default size
Rectangle aRect;
GetTextBoundRect( aRect, OUString( "0123456789" ) );
- long nDefHeight = aRect.GetHeight() + RULER_OFF*2 + RULER_TEXTOFF*2 + mnBorderWidth;
+ long nDefHeight = aRect.GetHeight() + RULER_OFF * 2 + RULER_TEXTOFF * 2 + mnBorderWidth;
Size aDefSize;
if ( nWinBits & WB_HORZ )
@@ -315,9 +312,8 @@ Ruler::Ruler( Window* pParent, WinBits nWinStyle ) :
maVirDev( *this ),
maMapMode( MAP_100TH_MM ),
mpSaveData(new ImplRulerData),
- mpData(0),
- mpDragData(new ImplRulerData),
- mpPreviousHitTest(NULL)
+ mpData(NULL),
+ mpDragData(new ImplRulerData)
{
ImplInit( nWinStyle );
}
@@ -465,41 +461,53 @@ void Ruler::ImplInvertLines( sal_Bool bErase )
// -----------------------------------------------------------------------
-void Ruler::ImplDrawTicks( long nMin, long nMax, long nStart, long nCenter )
+void Ruler::ImplDrawTicks( long nMin, long nMax, long nStart, long nTop, long nBottom )
{
- long n = 0;
- long nTick3 = aImplRulerUnitTab[mnUnitIndex].nTick3;
- long nTickCount = aImplRulerUnitTab[mnUnitIndex].nTick1;
- Size aPixSize = maVirDev.LogicToPixel( Size( nTick3, nTick3 ), maMapMode );
- long nTickWidth;
- bool bNoTicks = false;
+ long nCenter = nTop + ((nBottom - nTop) / 2);
+
+ long nTickLength3 = (nBottom - nTop) * 0.5;
+ long nTickLength2 = nTickLength3 * 0.66;
+ long nTickLength1 = nTickLength2 * 0.66;
+
+ long n = 0;
+ double nTick4 = aImplRulerUnitTab[mnUnitIndex].nTick4;
+ double nTick3 = 0;
+ double nTick2 = 0;
+ double nTickCount = aImplRulerUnitTab[mnUnitIndex].nTick1;
+ double nTickUnit = 0;
+ long nTickWidth;
+ long nTickLength;
+ bool bNoTicks = false;
+
+ double nAcceptanceDelta = 0.0001;
+
+ Size aPixSize = maVirDev.LogicToPixel( Size( nTick4, nTick4 ), maMapMode );
- long nTickUnit = 0;
- long nTick2 = 0;
if ( mnUnitIndex == RULER_UNIT_CHAR )
{
if ( mnCharWidth == 0 )
mnCharWidth = 371;
- nTick3 = mnCharWidth*2;
+ nTick4 = mnCharWidth * 2;
+ nTick2 = mnCharWidth;
nTickCount = mnCharWidth;
nTickUnit = mnCharWidth;
- nTick2 = mnCharWidth;
}
else if ( mnUnitIndex == RULER_UNIT_LINE )
{
if ( mnLineHeight == 0 )
mnLineHeight = 551;
- nTick3 = mnLineHeight*2;
- nTickCount = mnLineHeight;
- nTickUnit = mnLineHeight;
+ nTick4 = mnLineHeight * 2;
nTick2 = mnLineHeight;
+ nTickUnit = mnLineHeight;
+ nTickCount = mnLineHeight;
}
- aPixSize = maVirDev.LogicToPixel( Size( nTick3, nTick3 ), maMapMode );
// Groessenvorberechnung
// Sizes calculation
if ( mnWinStyle & WB_HORZ )
+ {
nTickWidth = aPixSize.Width();
+ }
else
{
Font aFont = GetFont();
@@ -510,6 +518,7 @@ void Ruler::ImplDrawTicks( long nMin, long nMax, long nStart, long nCenter )
maVirDev.SetFont( aFont );
nTickWidth = aPixSize.Height();
}
+
long nMaxWidth = maVirDev.PixelToLogic( Size( mpData->nPageWidth, 0 ), maMapMode ).Width();
if ( nMaxWidth < 0 )
nMaxWidth = -nMaxWidth;
@@ -518,18 +527,24 @@ void Ruler::ImplDrawTicks( long nMin, long nMax, long nStart, long nCenter )
nMaxWidth /= nTickUnit;
else
nMaxWidth /= aImplRulerUnitTab[mnUnitIndex].nTickUnit;
- OUString aNumStr = OUString::number(nMaxWidth);
- long nTxtWidth = GetTextWidth( aNumStr );
- const long nTextOff = 4;
- if ( nTickWidth < nTxtWidth+nTextOff )
+
+ OUString aNumString = OUString::number(nMaxWidth);
+ long nTxtWidth = GetTextWidth( aNumString );
+ const long nTextOff = 4;
+
+ // Determine the number divider for ruler drawn numbers - means which numbers
+ // should be shown on the ruler and which should be skipped because the ruller
+ // is not big enough to draw them
+ if ( nTickWidth < nTxtWidth + nTextOff )
{
// Calculate the scale of the ruler
- long nMulti = 1;
- long nOrgTick3 = nTick3;
- while ( nTickWidth < nTxtWidth+nTextOff )
+ long nMulti = 1;
+ long nOrgTick4 = nTick4;
+
+ while ( nTickWidth < nTxtWidth + nTextOff )
{
long nOldMulti = nMulti;
- if ( !nTickWidth ) //If nTickWidth equals 0
+ if ( nTickWidth == 0 )
nMulti *= 10;
else if ( nMulti < 10 )
nMulti++;
@@ -539,6 +554,7 @@ void Ruler::ImplDrawTicks( long nMin, long nMax, long nStart, long nCenter )
nMulti += 100;
else
nMulti += 1000;
+
// Ueberlauf, dann geben wir nichts aus, da wir bei so einem
// unsinnigen Massstab sowieso nichts vernuenftiges anzeigen
// koennen
@@ -548,33 +564,51 @@ void Ruler::ImplDrawTicks( long nMin, long nMax, long nStart, long nCenter )
break;
}
- nTick3 = nOrgTick3 * nMulti;
- aPixSize = maVirDev.LogicToPixel( Size( nTick3, nTick3 ), maMapMode );
+ nTick4 = nOrgTick4 * nMulti;
+ aPixSize = maVirDev.LogicToPixel( Size( nTick4, nTick4 ), maMapMode );
if ( mnWinStyle & WB_HORZ )
nTickWidth = aPixSize.Width();
else
nTickWidth = aPixSize.Height();
}
- nTickCount = nTick3;
+ nTickCount = nTick4;
}
else
+ {
maVirDev.SetLineColor( GetSettings().GetStyleSettings().GetShadowColor() );
+ }
if ( !bNoTicks )
{
- long nTick = 0;
- while ( ((nStart-n) >= nMin) || ((nStart+n) <= nMax) )
+ double nTick = 0.0;
+
+ if ( ( mnUnitIndex != RULER_UNIT_CHAR ) && ( mnUnitIndex != RULER_UNIT_LINE ) )
+ {
+ nTick2 = aImplRulerUnitTab[mnUnitIndex].nTick2;
+ nTick3 = aImplRulerUnitTab[mnUnitIndex].nTick3;
+ }
+
+ Size nTickGapSize;
+
+ nTickGapSize = maVirDev.LogicToPixel( Size( nTickCount, nTickCount ), maMapMode );
+ long nTickGap1 = mnWinStyle & WB_HORZ ? nTickGapSize.Width() : nTickGapSize.Height();
+ nTickGapSize = maVirDev.LogicToPixel( Size( nTick2, nTick2 ), maMapMode );
+ long nTickGap2 = mnWinStyle & WB_HORZ ? nTickGapSize.Width() : nTickGapSize.Height();
+ nTickGapSize = maVirDev.LogicToPixel( Size( nTick3, nTick3 ), maMapMode );
+ long nTickGap3 = mnWinStyle & WB_HORZ ? nTickGapSize.Width() : nTickGapSize.Height();
+
+ while ( ((nStart - n) >= nMin) || ((nStart + n) <= nMax) )
{
- // Null-Punkt
- if ( !nTick )
+ // Null point
+ if ( nTick == 0.0 )
{
if ( nStart > nMin )
{
// 0 is only painted when Margin1 is not equal to zero
if ( (mpData->nMargin1Style & RULER_STYLE_INVISIBLE) || (mpData->nMargin1 != 0) )
{
- aNumStr = "0";
- ImplVDrawText( nStart, nCenter, aNumStr );
+ aNumString = "0";
+ ImplVDrawText( nStart, nCenter, aNumString );
}
}
}
@@ -587,41 +621,57 @@ void Ruler::ImplDrawTicks( long nMin, long nMax, long nStart, long nCenter )
else
n = aPixSize.Height();
- // Tick3 - Output (Text)
- if ( !(nTick % nTick3) )
+ // Tick4 - Output (Text)
+ double aStep = (nTick / nTick4);
+ double aRest = std::abs(aStep - std::floor(aStep));
+
+ if ( aRest < nAcceptanceDelta )
{
if ( ( mnUnitIndex == RULER_UNIT_CHAR ) || ( mnUnitIndex == RULER_UNIT_LINE ) )
- aNumStr = OUString::number( nTick / nTickUnit );
+ aNumString = OUString::number( nTick / nTickUnit );
else
- aNumStr = OUString::number( nTick / aImplRulerUnitTab[mnUnitIndex].nTickUnit );
+ aNumString = OUString::number( nTick / aImplRulerUnitTab[mnUnitIndex].nTickUnit );
+
+ ImplVDrawText( nStart + n, nCenter, aNumString, nMin, nMax );
+ ImplVDrawText( nStart - n, nCenter, aNumString, nMin, nMax );
+
+ ImplVDrawLine( nStart + n, nBottom, nStart + n, nBottom - 1 );
+ ImplVDrawLine( nStart + n, nTop, nStart + n, nTop + 1 );
- ImplVDrawText( nStart + n, nCenter, aNumStr, nMin, nMax );
- ImplVDrawText( nStart - n, nCenter, aNumStr, nMin, nMax );
}
// Tick/Tick2 - Output (Strokes)
else
{
- if ( ( mnUnitIndex != RULER_UNIT_CHAR ) && ( mnUnitIndex != RULER_UNIT_LINE ) )
- nTick2 = aImplRulerUnitTab[mnUnitIndex].nTick2;
- if ( !(nTick % nTick2 ) )
- nTickWidth = RULER_TICK2_WIDTH;
- else
- nTickWidth = RULER_TICK1_WIDTH;
- long nT1 = nCenter-(nTickWidth/2);
- long nT2 = nT1+nTickWidth-1;
- long nT;
-
- nT = nStart+n;
- if ( nT < nMax )
- ImplVDrawLine( nT, nT1, nT, nT2 );
- nT = nStart-n;
- if ( nT > nMin )
- ImplVDrawLine( nT, nT1, nT, nT2 );
+ nTickLength = nTickLength1;
+
+ aStep = (nTick / nTick2);
+ aRest = std::abs(aStep - std::floor(aStep));
+ if ( aRest < nAcceptanceDelta )
+ nTickLength = nTickLength2;
+
+ aStep = (nTick / nTick3);
+ aRest = std::abs(aStep - std::floor(aStep));
+ if ( aRest < nAcceptanceDelta )
+ nTickLength = nTickLength3;
+
+ if ( (nTickLength == nTickLength1 && nTickGap1 > 6) ||
+ (nTickLength == nTickLength2 && nTickGap2 > 6) ||
+ (nTickLength == nTickLength3 && nTickGap3 > 6) )
+ {
+ long nT1 = nCenter - (nTickLength / 2);
+ long nT2 = nT1 + nTickLength - 1;
+ long nT;
+
+ nT = nStart + n;
+
+ if ( nT < nMax )
+ ImplVDrawLine( nT, nT1, nT, nT2 );
+ nT = nStart - n;
+ if ( nT > nMin )
+ ImplVDrawLine( nT, nT1, nT, nT2 );
+ }
}
}
- // #i49017# with some zoom factors the value nTick can overflow
- if( ((sal_uLong)nTick + (sal_uLong)nTickCount) > (sal_uLong)LONG_MAX)
- break;
nTick += nTickCount;
}
}
@@ -862,59 +912,59 @@ static void ImplDrawRulerTab( OutputDevice* pDevice,
aRect3.SetEmpty();
if ( nTabStyle == RULER_TAB_DEFAULT )
{
- aRect1.Left() = rPos.X() - RULER_TAB_DWIDTH2 + 1;
- aRect1.Top() = rPos.Y() - RULER_TAB_DHEIGHT2 + 1;
- aRect1.Right() = rPos.X() - RULER_TAB_DWIDTH2 + RULER_TAB_DWIDTH;
+ aRect1.Left() = rPos.X() - RULER_TAB_DWIDTH2 + 1;
+ aRect1.Top() = rPos.Y() - RULER_TAB_DHEIGHT2 + 1;
+ aRect1.Right() = rPos.X() - RULER_TAB_DWIDTH2 + RULER_TAB_DWIDTH;
aRect1.Bottom() = rPos.Y();
- aRect2.Left() = rPos.X() - RULER_TAB_DWIDTH2 + RULER_TAB_DWIDTH3;
- aRect2.Top() = rPos.Y() - RULER_TAB_DHEIGHT + 1;
- aRect2.Right() = rPos.X() - RULER_TAB_DWIDTH2 + RULER_TAB_DWIDTH3 + RULER_TAB_DWIDTH4 - 1;
+ aRect2.Left() = rPos.X() - RULER_TAB_DWIDTH2 + RULER_TAB_DWIDTH3;
+ aRect2.Top() = rPos.Y() - RULER_TAB_DHEIGHT + 1;
+ aRect2.Right() = rPos.X() - RULER_TAB_DWIDTH2 + RULER_TAB_DWIDTH3 + RULER_TAB_DWIDTH4 - 1;
aRect2.Bottom() = rPos.Y();
}
else if ( (!bRTL && nTabStyle == RULER_TAB_LEFT) || ( bRTL && nTabStyle == RULER_TAB_RIGHT))
{
- aRect1.Left() = rPos.X();
- aRect1.Top() = rPos.Y() - RULER_TAB_HEIGHT2 + 1;
- aRect1.Right() = rPos.X() + RULER_TAB_WIDTH - 1;
+ aRect1.Left() = rPos.X();
+ aRect1.Top() = rPos.Y() - RULER_TAB_HEIGHT2 + 1;
+ aRect1.Right() = rPos.X() + RULER_TAB_WIDTH - 1;
aRect1.Bottom() = rPos.Y();
- aRect2.Left() = rPos.X();
- aRect2.Top() = rPos.Y() - RULER_TAB_HEIGHT + 1;
- aRect2.Right() = rPos.X() + RULER_TAB_WIDTH2 - 1;
+ aRect2.Left() = rPos.X();
+ aRect2.Top() = rPos.Y() - RULER_TAB_HEIGHT + 1;
+ aRect2.Right() = rPos.X() + RULER_TAB_WIDTH2 - 1;
aRect2.Bottom() = rPos.Y();
}
else if ( (!bRTL && nTabStyle == RULER_TAB_RIGHT) ||( bRTL && nTabStyle == RULER_TAB_LEFT))
{
- aRect1.Left() = rPos.X() - RULER_TAB_WIDTH + 1;
- aRect1.Top() = rPos.Y() - RULER_TAB_HEIGHT2 + 1;
- aRect1.Right() = rPos.X();
+ aRect1.Left() = rPos.X() - RULER_TAB_WIDTH + 1;
+ aRect1.Top() = rPos.Y() - RULER_TAB_HEIGHT2 + 1;
+ aRect1.Right() = rPos.X();
aRect1.Bottom() = rPos.Y();
- aRect2.Left() = rPos.X() - RULER_TAB_WIDTH2 + 1;
- aRect2.Top() = rPos.Y() - RULER_TAB_HEIGHT + 1;
- aRect2.Right() = rPos.X();
+ aRect2.Left() = rPos.X() - RULER_TAB_WIDTH2 + 1;
+ aRect2.Top() = rPos.Y() - RULER_TAB_HEIGHT + 1;
+ aRect2.Right() = rPos.X();
aRect2.Bottom() = rPos.Y();
}
else
{
- aRect1.Left() = rPos.X() - RULER_TAB_CWIDTH2 + 1;
- aRect1.Top() = rPos.Y() - RULER_TAB_HEIGHT2 + 1;
- aRect1.Right() = rPos.X() - RULER_TAB_CWIDTH2 + RULER_TAB_CWIDTH;
+ aRect1.Left() = rPos.X() - RULER_TAB_CWIDTH2 + 1;
+ aRect1.Top() = rPos.Y() - RULER_TAB_HEIGHT2 + 1;
+ aRect1.Right() = rPos.X() - RULER_TAB_CWIDTH2 + RULER_TAB_CWIDTH;
aRect1.Bottom() = rPos.Y();
- aRect2.Left() = rPos.X() - RULER_TAB_CWIDTH2 + RULER_TAB_CWIDTH3;
- aRect2.Top() = rPos.Y() - RULER_TAB_HEIGHT + 1;
- aRect2.Right() = rPos.X() - RULER_TAB_CWIDTH2 + RULER_TAB_CWIDTH3 + RULER_TAB_CWIDTH4 - 1;
+ aRect2.Left() = rPos.X() - RULER_TAB_CWIDTH2 + RULER_TAB_CWIDTH3;
+ aRect2.Top() = rPos.Y() - RULER_TAB_HEIGHT + 1;
+ aRect2.Right() = rPos.X() - RULER_TAB_CWIDTH2 + RULER_TAB_CWIDTH3 + RULER_TAB_CWIDTH4 - 1;
aRect2.Bottom() = rPos.Y();
if ( nTabStyle == RULER_TAB_DECIMAL )
{
- aRect3.Left() = rPos.X() - RULER_TAB_CWIDTH2 + RULER_TAB_CWIDTH - 1;
- aRect3.Top() = rPos.Y() - RULER_TAB_HEIGHT + 1 + 1;
- aRect3.Right() = rPos.X() - RULER_TAB_CWIDTH2 + RULER_TAB_CWIDTH;
- aRect3.Bottom()= rPos.Y() - RULER_TAB_HEIGHT + 1 + 2 ;
+ aRect3.Left() = rPos.X() - RULER_TAB_CWIDTH2 + RULER_TAB_CWIDTH - 1;
+ aRect3.Top() = rPos.Y() - RULER_TAB_HEIGHT + 1 + 1;
+ aRect3.Right() = rPos.X() - RULER_TAB_CWIDTH2 + RULER_TAB_CWIDTH;
+ aRect3.Bottom() = rPos.Y() - RULER_TAB_HEIGHT + 1 + 2 ;
}
}
if( 0 == (nWinBits & WB_HORZ) )
@@ -1198,7 +1248,6 @@ void Ruler::ImplFormat()
// Lineal-Beschriftung (nur wenn keine Bemassungspfeile)
long nMin = nVirLeft;
long nMax = nP2;
- long nCenter = nVirTop + ((nVirBottom - nVirTop) / 2);
long nStart = 0;
if (mpData->bTextRTL)
@@ -1213,7 +1262,7 @@ void Ruler::ImplFormat()
nMax--;
// Draw captions
- ImplDrawTicks( nMin, nMax, nStart, nCenter );
+ ImplDrawTicks( nMin, nMax, nStart, nVirTop, nVirBottom );
// Draw borders
if ( !mpData->pBorders.empty() )
diff --git a/svx/source/dialog/svxruler.cxx b/svx/source/dialog/svxruler.cxx
index 734836a..18c739f 100644
--- a/svx/source/dialog/svxruler.cxx
+++ b/svx/source/dialog/svxruler.cxx
@@ -333,10 +333,10 @@ long SvxRuler::MakePositionSticky(long aPosition, bool aSnapToFrameMargin) const
long aLeftFramePosition = ConvertHPosPixel(GetLeftFrameMargin());
long aRightFramePosition = ConvertHPosPixel(GetRightFrameMargin());
- long aTick = GetCurrentRulerUnit().nTick1;
+ double aTick = GetCurrentRulerUnit().nTick1;
long aTickPixel = pEditWin->LogicToPixel(Size(0, aTick), GetCurrentMapMode()).Height();
- long aHalfTick = aTick / 2;
- long aHalfTickPixel = aTickPixel / 2;
+ double aHalfTick = aTick / 2;
+ double aHalfTickPixel = aTickPixel / 2;
if (aSnapToFrameMargin)
{
@@ -354,7 +354,7 @@ long SvxRuler::MakePositionSticky(long aPosition, bool aSnapToFrameMargin) const
long aTranslatedPosition = aPosition - aLeftFramePosition;
// Convert position to current selected map mode
long aPositionLogic = pEditWin->PixelToLogic(Size(0, aTranslatedPosition), GetCurrentMapMode()).Height();
- aPositionLogic = ((aPositionLogic + aHalfTick) / aTick) * aTick;
+ aPositionLogic = std::floor((aPositionLogic + aHalfTick) / aTick) * aTick;
// Convert back to pixels
aPosition = pEditWin->LogicToPixel(Size(0, aPositionLogic), GetCurrentMapMode()).Height();
// Move "coordinate system" back to original position
@@ -934,11 +934,16 @@ void SvxRuler::UpdateTabs()
{
if(IsDrag())
return;
- if(mpPagePosItem.get() && mpParaItem.get() && mpTabStopItem.get() && !mpObjectItem.get())
+
+ if( mpPagePosItem.get() &&
+ mpParaItem.get() &&
+ mpTabStopItem.get() &&
+ !mpObjectItem.get() )
{
// buffer for DefaultTabStop
// Distance last Tab <-> Right paragraph margin / DefaultTabDist
sal_Bool bRTL = mpRulerImpl->pTextRTLItem && mpRulerImpl->pTextRTLItem->GetValue();
+
long nLeftFrameMargin = GetLeftFrameMargin();
long nRightFrameMargin = GetRightFrameMargin();
@@ -947,20 +952,20 @@ void SvxRuler::UpdateTabs()
const long lParaIndent = nLeftFrameMargin + nParaItemTxtLeft;
- const long lLastTab =
- mpTabStopItem->Count()?
- ConvertHPosPixel((*mpTabStopItem.get())[mpTabStopItem->Count()-1].GetTabPos()): 0;
- const long lPosPixel =
- ConvertHPosPixel(lParaIndent) + lLastTab;
- const long lRightIndent =
- ConvertHPosPixel(nRightFrameMargin - mpParaItem->GetRight());
+ const long lLastTab = mpTabStopItem->Count()
+ ? ConvertHPosPixel((*mpTabStopItem.get())[mpTabStopItem->Count()-1].GetTabPos())
+ : 0;
+ const long lPosPixel = ConvertHPosPixel(lParaIndent) + lLastTab;
+ const long lRightIndent = ConvertHPosPixel(nRightFrameMargin - mpParaItem->GetRight());
+
long nDefTabDist = ConvertHPosPixel(lDefTabDist);
+
if( !nDefTabDist )
nDefTabDist = 1;
- const sal_uInt16 nDefTabBuf = lPosPixel > lRightIndent ||
- lLastTab > lRightIndent
- ? 0
- : (sal_uInt16)( (lRightIndent - lPosPixel) / nDefTabDist );
+
+ const sal_uInt16 nDefTabBuf = lPosPixel > lRightIndent || lLastTab > lRightIndent
+ ? 0
+ : (sal_uInt16)( (lRightIndent - lPosPixel) / nDefTabDist );
if(mpTabStopItem->Count() + TAB_GAP + nDefTabBuf > nTabBufSize)
{
@@ -971,22 +976,29 @@ void SvxRuler::UpdateTabs()
nTabCount = 0;
sal_uInt16 j;
+
//#i24363# tab stops relative to indent
const long lRightPixMargin = ConvertSizePixel(nRightFrameMargin - nParaItemTxtLeft );
const long lParaIndentPix = ConvertSizePixel(lParaIndent);
+
for(j = 0; j < mpTabStopItem->Count(); ++j)
{
- const SvxTabStop *pTab = &(*mpTabStopItem.get())[j];
- mpTabs[nTabCount+TAB_GAP].nPos =
- ConvertHPosPixel(
- (mpRulerImpl->bIsTabsRelativeToIndent ? lParaIndent : 0 ) + pTab->GetTabPos() + lAppNullOffset);
+ const SvxTabStop* pTab = &(*mpTabStopItem.get())[j];
+ if (mpRulerImpl->bIsTabsRelativeToIndent)
+ mpTabs[nTabCount + TAB_GAP].nPos =
+ ConvertHPosPixel( lParaIndent + pTab->GetTabPos() + lAppNullOffset);
+ else
+ mpTabs[nTabCount + TAB_GAP].nPos =
+ ConvertHPosPixel( 0 + pTab->GetTabPos() + lAppNullOffset);
+
if(bRTL)
{
- mpTabs[nTabCount+TAB_GAP].nPos = lParaIndentPix + lRightPixMargin - mpTabs[nTabCount+TAB_GAP].nPos;
+ mpTabs[nTabCount + TAB_GAP].nPos = lParaIndentPix + lRightPixMargin - mpTabs[nTabCount+TAB_GAP].nPos;
}
- mpTabs[nTabCount+TAB_GAP].nStyle = ToSvTab_Impl(pTab->GetAdjustment());
+ mpTabs[nTabCount + TAB_GAP].nStyle = ToSvTab_Impl(pTab->GetAdjustment());
++nTabCount;
}
+
if(!mpTabStopItem->Count())
mpTabs[0].nPos = bRTL ? lRightPixMargin : lParaIndentPix;
@@ -3240,7 +3252,7 @@ void SvxRuler::Command( const CommandEvent& rCommandEvent )
PopupMenu aMenu;
aMenu.SetSelectHdl(LINK(this, SvxRuler, TabMenuSelect));
VirtualDevice aDev;
- const Size aSz(RULER_TAB_WIDTH+2, RULER_TAB_HEIGHT+2);
+ const Size aSz(RULER_TAB_WIDTH + 2, RULER_TAB_HEIGHT + 2);
aDev.SetOutputSize(aSz);
aDev.SetBackground(Wallpaper(Color(COL_WHITE)));
Color aFillColor(aDev.GetSettings().GetStyleSettings().GetShadowColor());
@@ -3249,12 +3261,12 @@ void SvxRuler::Command( const CommandEvent& rCommandEvent )
for ( sal_uInt16 i = RULER_TAB_LEFT; i < RULER_TAB_DEFAULT; ++i )
{
sal_uInt16 nStyle = bRTL ? i|RULER_TAB_RTL : i;
- nStyle |= (sal_uInt16)(bHorz ? WB_HORZ : WB_VERT);
+ nStyle |= static_cast<sal_uInt16>(bHorz ? WB_HORZ : WB_VERT);
DrawTab(&aDev, aFillColor, aPt, nStyle);
aMenu.InsertItem(i + 1,
ResId(RID_SVXSTR_RULER_START + i, DIALOG_MGR()).toString(),
Image(aDev.GetBitmap(Point(), aSz), Color(COL_WHITE)));
- aMenu.CheckItem(i+1, i == mpTabs[mpRulerImpl->nIdx + TAB_GAP].nStyle);
+ aMenu.CheckItem(i + 1, i == mpTabs[mpRulerImpl->nIdx + TAB_GAP].nStyle);
aDev.SetOutputSize(aSz); // delete device
}
aMenu.Execute( this, rCommandEvent.GetMousePosPixel() );
@@ -3271,20 +3283,23 @@ void SvxRuler::Command( const CommandEvent& rCommandEvent )
{
const sal_uInt16 nId = aMenu.GetItemId(i - 1);
aMenu.CheckItem(nId, nId == (sal_uInt16)eUnit);
- if(bReduceMetric &&
- (nId == FUNIT_M ||
- nId == FUNIT_KM ||
- nId == FUNIT_FOOT ||
- nId == FUNIT_MILE ||
- nId == FUNIT_CHAR ||
- nId == FUNIT_LINE ))
+ if( bReduceMetric )
{
- if (( nId == FUNIT_CHAR ) && bHorz )
- ;
- else if (( nId == FUNIT_LINE ) && !bHorz )
- ;
- else
- aMenu.RemoveItem(i - 1);
+ if ( nId == FUNIT_M ||
+ nId == FUNIT_KM ||
+ nId == FUNIT_FOOT ||
+ nId == FUNIT_MILE )
+ {
+ aMenu.RemoveItem(i - 1);
+ }
+ else if (( nId == FUNIT_CHAR ) && !bHorz )
+ {
+ aMenu.RemoveItem(i - 1);
+ }
+ else if (( nId == FUNIT_LINE ) && bHorz )
+ {
+ aMenu.RemoveItem(i - 1);
+ }
}
}
aMenu.Execute( this, rCommandEvent.GetMousePosPixel() );
commit be0759283c22d06e8fd7683776866c5abc1bf8f2
Author: Tomaž Vajngerl <quikee at gmail.com>
Date: Sun Sep 1 13:38:58 2013 +0200
Ruler: clear ruler elements at copying only when input is not empty
Change-Id: I633dcd452a0df426421eaccadf648ad06b8e124c
diff --git a/svtools/source/control/ruler.cxx b/svtools/source/control/ruler.cxx
index 17c5875..494fe26 100644
--- a/svtools/source/control/ruler.cxx
+++ b/svtools/source/control/ruler.cxx
@@ -189,34 +189,45 @@ ImplRulerData& ImplRulerData::operator=( const ImplRulerData& rData )
bAutoPageWidth = rData.bAutoPageWidth;
bTextRTL = rData.bTextRTL;
- pLines.clear();
- pBorders.clear();
- pIndents.clear();
- pTabs.clear();
-
if ( !rData.pLines.empty() )
{
pLines.resize(rData.pLines.size());
std::copy(rData.pLines.begin(), rData.pLines.end(), pLines.begin());
}
+ else
+ {
+ pLines.clear();
+ }
if ( !rData.pBorders.empty() )
{
pBorders.resize(rData.pBorders.size());
std::copy(rData.pBorders.begin(), rData.pBorders.end(), pBorders.begin());
}
+ else
+ {
+ pBorders.clear();
+ }
if ( !rData.pIndents.empty() )
{
pIndents.resize(rData.pIndents.size());
std::copy(rData.pIndents.begin(), rData.pIndents.end(), pIndents.begin());
}
+ else
+ {
+ pIndents.clear();
+ }
if ( !rData.pTabs.empty() )
{
pTabs.resize(rData.pTabs.size());
std::copy(rData.pTabs.begin(), rData.pTabs.end(), pTabs.begin());
}
+ else
+ {
+ pTabs.clear();
+ }
return *this;
}
commit 516455206510fe2ad928cde37e4adfae4a57859a
Author: Tomaž Vajngerl <quikee at gmail.com>
Date: Sat Aug 31 12:56:04 2013 +0200
Ruler: use vector instead of array for elements
Change-Id: I099387648988b83d4d4b53f59237906e8f939c6e
diff --git a/include/svtools/ruler.hxx b/include/svtools/ruler.hxx
index 7bf8f5e..97d27fb 100644
--- a/include/svtools/ruler.hxx
+++ b/include/svtools/ruler.hxx
@@ -781,12 +781,12 @@ public:
void SetLeftFrameMargin( long nPos );
void SetRightFrameMargin( long nPos );
- void SetLines( sal_uInt16 n = 0, const RulerLine* pLineAry = NULL );
- void SetBorders( sal_uInt16 n = 0, const RulerBorder* pBrdAry = NULL );
- void SetIndents( sal_uInt16 n = 0, const RulerIndent* pIndentAry = NULL );
+ void SetLines( sal_uInt32 n = 0, const RulerLine* pLineAry = NULL );
+ void SetBorders( sal_uInt32 n = 0, const RulerBorder* pBrdAry = NULL );
+ void SetIndents( sal_uInt32 n = 0, const RulerIndent* pIndentAry = NULL );
- void SetTabs( sal_uInt16 n = 0, const RulerTab* pTabAry = NULL );
- sal_uInt16 GetTabCount() const;
+ void SetTabs( sal_uInt32 n = 0, const RulerTab* pTabAry = NULL );
+ sal_uInt32 GetTabCount() const;
const RulerTab* GetTabs() const;
static void DrawTab( OutputDevice* pDevice, const Color &rFillColor,
diff --git a/svtools/source/control/ruler.cxx b/svtools/source/control/ruler.cxx
index a75571a..17c5875 100644
--- a/svtools/source/control/ruler.cxx
+++ b/svtools/source/control/ruler.cxx
@@ -25,6 +25,11 @@
#include <svtools/ruler.hxx>
+#include <boost/scoped_array.hpp>
+#include <vector>
+
+using namespace std;
+
// =======================================================================
#define RULER_OFF 3
@@ -68,7 +73,7 @@
#define RULER_UNIT_PICA 8
#define RULER_UNIT_CHAR 9
#define RULER_UNIT_LINE 10
-#define RULER_UNIT_COUNT 11
+#define RULER_UNIT_COUNT 11
// -----------------
// - ImplRulerData -
@@ -78,33 +83,31 @@ class ImplRulerData
friend class Ruler;
private:
- RulerLine* pLines;
- RulerBorder* pBorders;
- RulerIndent* pIndents;
- RulerTab* pTabs;
- long nNullVirOff;
- long nRulVirOff;
- long nRulWidth;
- long nPageOff;
- long nPageWidth;
- long nNullOff;
- long nMargin1;
- long nMargin2;
- long nLeftFrameMargin;
- long nRightFrameMargin;
- sal_uInt16 nLines;
- sal_uInt16 nBorders;
- sal_uInt16 nIndents;
- sal_uInt16 nTabs;
- sal_uInt16 nMargin1Style;
- sal_uInt16 nMargin2Style;
- bool bAutoPageWidth;
- sal_Bool bTextRTL;
+ vector<RulerLine> pLines;
+ vector<RulerBorder> pBorders;
+ vector<RulerIndent> pIndents;
+ vector<RulerTab> pTabs;
+
+ long nNullVirOff;
+ long nRulVirOff;
+ long nRulWidth;
+ long nPageOff;
+ long nPageWidth;
+ long nNullOff;
+ long nMargin1;
+ long nMargin2;
+ long nLeftFrameMargin;
+ long nRightFrameMargin;
+ sal_uInt16 nMargin1Style;
+ sal_uInt16 nMargin2Style;
+ bool bAutoPageWidth;
+ bool bTextRTL;
public:
- ImplRulerData();
- ~ImplRulerData();
- ImplRulerData& operator=( const ImplRulerData& rData );
+ ImplRulerData();
+ ~ImplRulerData();
+
+ ImplRulerData& operator=( const ImplRulerData& rData );
};
static const RulerUnitData aImplRulerUnitTab[RULER_UNIT_COUNT] =
@@ -128,34 +131,41 @@ struct ImplRulerHitTest
{
long nPos;
RulerType eType;
- sal_uInt16 nAryPos;
- sal_uInt16 mnDragSize;
+ sal_uInt16 nAryPos;
+ sal_uInt16 mnDragSize;
bool bSize;
bool bSizeBar;
bool bExpandTest;
+
ImplRulerHitTest() :
- bExpandTest( false ) {}
+ bExpandTest( false )
+ {}
};
// =======================================================================
-ImplRulerData::ImplRulerData()
+ImplRulerData::ImplRulerData() :
+ nNullVirOff (0),
+ nRulVirOff (0),
+ nRulWidth (0),
+ nPageOff (0),
+ nPageWidth (0),
+ nNullOff (0),
+ nMargin1 (0),
+ nMargin2 (0),
+ nLeftFrameMargin (0),
+ nRightFrameMargin (0),
+ nMargin1Style (0),
+ nMargin2Style (0),
+ bAutoPageWidth (true), // Page width == EditWin width
+ bTextRTL (false)
{
- memset( this, 0, sizeof( ImplRulerData ) );
-
- // PageBreite == EditWinBreite
- bAutoPageWidth = true;
}
// -----------------------------------------------------------------------
ImplRulerData::~ImplRulerData()
-{
- delete[] pLines;
- delete[] pBorders;
- delete[] pIndents;
- delete[] pTabs;
-}
+{}
// -----------------------------------------------------------------------
@@ -164,35 +174,48 @@ ImplRulerData& ImplRulerData::operator=( const ImplRulerData& rData )
if( this == &rData )
return *this;
- delete[] pLines;
- delete[] pBorders;
- delete[] pIndents;
- delete[] pTabs;
+ nNullVirOff = rData.nNullVirOff;
+ nRulVirOff = rData.nRulVirOff;
+ nRulWidth = rData.nRulWidth;
+ nPageOff = rData.nPageOff;
+ nPageWidth = rData.nPageWidth;
+ nNullOff = rData.nNullOff;
+ nMargin1 = rData.nMargin1;
+ nMargin2 = rData.nMargin2;
+ nLeftFrameMargin = rData.nLeftFrameMargin;
+ nRightFrameMargin = rData.nRightFrameMargin;
+ nMargin1Style = rData.nMargin1Style;
+ nMargin2Style = rData.nMargin2Style;
+ bAutoPageWidth = rData.bAutoPageWidth;
+ bTextRTL = rData.bTextRTL;
- memcpy( this, &rData, sizeof( ImplRulerData ) );
+ pLines.clear();
+ pBorders.clear();
+ pIndents.clear();
+ pTabs.clear();
- if ( rData.pLines )
+ if ( !rData.pLines.empty() )
{
- pLines = new RulerLine[nLines];
- memcpy( pLines, rData.pLines, nLines*sizeof( RulerLine ) );
+ pLines.resize(rData.pLines.size());
+ std::copy(rData.pLines.begin(), rData.pLines.end(), pLines.begin());
}
- if ( rData.pBorders )
+ if ( !rData.pBorders.empty() )
{
- pBorders = new RulerBorder[nBorders];
- memcpy( pBorders, rData.pBorders, nBorders*sizeof( RulerBorder ) );
+ pBorders.resize(rData.pBorders.size());
+ std::copy(rData.pBorders.begin(), rData.pBorders.end(), pBorders.begin());
}
- if ( rData.pIndents )
+ if ( !rData.pIndents.empty() )
{
- pIndents = new RulerIndent[nIndents];
- memcpy( pIndents, rData.pIndents, nIndents*sizeof( RulerIndent ) );
+ pIndents.resize(rData.pIndents.size());
+ std::copy(rData.pIndents.begin(), rData.pIndents.end(), pIndents.begin());
}
- if ( rData.pTabs )
+ if ( !rData.pTabs.empty() )
{
- pTabs = new RulerTab[nTabs];
- memcpy( pTabs, rData.pTabs, nTabs*sizeof( RulerTab ) );
+ pTabs.resize(rData.pTabs.size());
+ std::copy(rData.pTabs.begin(), rData.pTabs.end(), pTabs.begin());
}
return *this;
@@ -370,7 +393,8 @@ void Ruler::ImplVDrawText( long nX, long nY, const OUString& rText, long nMin, l
void Ruler::ImplInvertLines( sal_Bool bErase )
{
// Positionslinien
- if ( mpData->nLines && mbActive && !mbDrag && !mbFormat &&
+ if ( !mpData->pLines.empty() &&
+ mbActive && !mbDrag && !mbFormat &&
!(mnUpdateFlags & RULER_UPDATE_LINES) )
{
long n;
@@ -387,9 +411,9 @@ void Ruler::ImplInvertLines( sal_Bool bErase )
aRect.Right() = nY;
// Linien ausgeben
- for ( sal_uInt16 i = 0; i < mpData->nLines; i++ )
+ for ( sal_uInt16 i = 0; i < mpData->pLines.size(); i++ )
{
- n = mpData->pLines[i].nPos+nNullWinOff;
+ n = mpData->pLines[i].nPos + nNullWinOff;
if ( (n >= nRulX1) && (n < nRulX2) )
{
if ( mnWinStyle & WB_HORZ )
@@ -602,15 +626,15 @@ void Ruler::ImplDrawBorders( long nMin, long nMax, long nVirTop, long nVirBottom
long n2;
long nTemp1;
long nTemp2;
- sal_uInt16 i;
+ sal_uInt32 i;
- for ( i = 0; i < mpData->nBorders; i++ )
+ for ( i = 0; i < mpData->pBorders.size(); i++ )
{
if ( mpData->pBorders[i].nStyle & RULER_STYLE_INVISIBLE )
continue;
- n1 = mpData->pBorders[i].nPos+mpData->nNullVirOff;
- n2 = n1+mpData->pBorders[i].nWidth;
+ n1 = mpData->pBorders[i].nPos + mpData->nNullVirOff;
+ n2 = n1 + mpData->pBorders[i].nWidth;
if ( ((n1 >= nMin) && (n1 <= nMax)) || ((n2 >= nMin) && (n2 <= nMax)) )
{
@@ -710,13 +734,13 @@ void Ruler::ImplDrawIndent( const Polygon& rPoly, sal_uInt16 nStyle, bool bIsHit
void Ruler::ImplDrawIndents( long nMin, long nMax, long nVirTop, long nVirBottom )
{
- sal_uInt16 j;
+ sal_uInt32 j;
long n;
long nIndentHeight = (mnVirHeight/2) - 1;
long nIndentWidth2 = nIndentHeight-3;
Polygon aPoly( 5 );
- for ( j = 0; j < mpData->nIndents; j++ )
+ for ( j = 0; j < mpData->pIndents.size(); j++ )
{
if ( mpData->pIndents[j].nStyle & RULER_STYLE_INVISIBLE )
continue;
@@ -732,23 +756,23 @@ void Ruler::ImplDrawIndents( long nMin, long nMax, long nVirTop, long nVirBottom
{
const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
maVirDev.SetLineColor( rStyleSettings.GetShadowColor() );
- ImplVDrawLine( n, nVirTop+1, n, nVirBottom-1 );
+ ImplVDrawLine( n, nVirTop + 1, n, nVirBottom - 1 );
}
else if ( nIndentStyle == RULER_INDENT_BOTTOM )
{
- aPoly.SetPoint( Point( n+0, nVirBottom-nIndentHeight ), 0 );
- aPoly.SetPoint( Point( n-nIndentWidth2, nVirBottom-3 ), 1 );
- aPoly.SetPoint( Point( n-nIndentWidth2, nVirBottom ), 2 );
- aPoly.SetPoint( Point( n+nIndentWidth2, nVirBottom ), 3 );
- aPoly.SetPoint( Point( n+nIndentWidth2, nVirBottom-3 ), 4 );
+ aPoly.SetPoint( Point( n + 0, nVirBottom - nIndentHeight ), 0 );
+ aPoly.SetPoint( Point( n - nIndentWidth2, nVirBottom - 3 ), 1 );
+ aPoly.SetPoint( Point( n - nIndentWidth2, nVirBottom ), 2 );
+ aPoly.SetPoint( Point( n + nIndentWidth2, nVirBottom ), 3 );
+ aPoly.SetPoint( Point( n + nIndentWidth2, nVirBottom - 3 ), 4 );
}
else
{
- aPoly.SetPoint( Point( n+0, nVirTop+nIndentHeight ), 0 );
- aPoly.SetPoint( Point( n-nIndentWidth2, nVirTop+3 ), 1 );
- aPoly.SetPoint( Point( n-nIndentWidth2, nVirTop ), 2 );
- aPoly.SetPoint( Point( n+nIndentWidth2, nVirTop ), 3 );
- aPoly.SetPoint( Point( n+nIndentWidth2, nVirTop+3 ), 4 );
+ aPoly.SetPoint( Point( n + 0, nVirTop+nIndentHeight ), 0 );
+ aPoly.SetPoint( Point( n - nIndentWidth2, nVirTop + 3 ), 1 );
+ aPoly.SetPoint( Point( n - nIndentWidth2, nVirTop ), 2 );
+ aPoly.SetPoint( Point( n + nIndentWidth2, nVirTop ), 3 );
+ aPoly.SetPoint( Point( n + nIndentWidth2, nVirTop + 3 ), 4 );
}
if(0 == (mnWinStyle & WB_HORZ))
@@ -918,7 +942,7 @@ void Ruler::ImplDrawTab( OutputDevice* pDevice, const Point& rPos, sal_uInt16 nS
void Ruler::ImplDrawTabs( long nMin, long nMax, long nVirTop, long nVirBottom )
{
- for ( sal_uInt16 i = 0; i < mpData->nTabs; i++ )
+ for ( sal_uInt32 i = 0; i < mpData->pTabs.size(); i++ )
{
if ( mpData->pTabs[i].nStyle & RULER_STYLE_INVISIBLE )
continue;
@@ -1181,18 +1205,16 @@ void Ruler::ImplFormat()
ImplDrawTicks( nMin, nMax, nStart, nCenter );
// Draw borders
- if ( mpData->pBorders )
+ if ( !mpData->pBorders.empty() )
ImplDrawBorders( nVirLeft, nP2, nVirTop, nVirBottom );
// Draw indents
- if ( mpData->pIndents )
+ if ( !mpData->pIndents.empty() )
ImplDrawIndents( nVirLeft, nP2, nVirTop - 1, nVirBottom + 1 );
// Tabs
- if ( mpData->pTabs )
- {
+ if ( !mpData->pTabs.empty() )
ImplDrawTabs( nVirLeft, nP2, nVirTop-1, nVirBottom+1 );
- }
// Wir haben formatiert
mbFormat = sal_False;
@@ -1387,8 +1409,8 @@ void Ruler::ImplUpdate( sal_Bool bMustCalc )
sal_Bool Ruler::ImplHitTest( const Point& rPos, ImplRulerHitTest* pHitTest,
sal_Bool bRequireStyle, sal_uInt16 nRequiredStyle ) const
{
- sal_uInt16 i;
- sal_uInt16 nStyle;
+ sal_Int32 i;
+ sal_uInt16 nStyle;
long nHitBottom;
long nX;
long nY;
@@ -1420,7 +1442,7 @@ sal_Bool Ruler::ImplHitTest( const Point& rPos, ImplRulerHitTest* pHitTest,
// Damit ueberstehende Tabs und Einzuege mit beruecksichtigt werden
long nXExtraOff;
- if ( mpData->pTabs || mpData->pIndents )
+ if ( !mpData->pTabs.empty() || !mpData->pIndents.empty() )
nXExtraOff = (mnVirHeight/2) - 4;
else
nXExtraOff = 0;
@@ -1442,14 +1464,14 @@ sal_Bool Ruler::ImplHitTest( const Point& rPos, ImplRulerHitTest* pHitTest,
// Zuerst die Tabs testen
Rectangle aRect;
- if ( mpData->pTabs )
+ if ( !mpData->pTabs.empty() )
{
aRect.Bottom() = nHitBottom;
aRect.Top() = aRect.Bottom()-RULER_TAB_HEIGHT-RULER_OFF;
- for ( i = mpData->nTabs; i; i-- )
+ for ( i = mpData->pTabs.size() - 1; i >= 0; i-- )
{
- nStyle = mpData->pTabs[i-1].nStyle;
+ nStyle = mpData->pTabs[i].nStyle;
if ( !(nStyle & RULER_STYLE_INVISIBLE) )
{
nStyle &= RULER_TAB_STYLE;
@@ -1457,28 +1479,28 @@ sal_Bool Ruler::ImplHitTest( const Point& rPos, ImplRulerHitTest* pHitTest,
// Default-Tabs werden nur angezeigt
if ( nStyle != RULER_TAB_DEFAULT )
{
- n1 = mpData->pTabs[i-1].nPos;
+ n1 = mpData->pTabs[i].nPos;
if ( nStyle == RULER_TAB_LEFT )
{
- aRect.Left() = n1;
- aRect.Right() = n1+RULER_TAB_WIDTH-1;
+ aRect.Left() = n1;
+ aRect.Right() = n1 + RULER_TAB_WIDTH - 1;
}
else if ( nStyle == RULER_TAB_RIGHT )
{
- aRect.Right() = n1;
- aRect.Left() = n1-RULER_TAB_WIDTH-1;
+ aRect.Right() = n1;
+ aRect.Left() = n1 - RULER_TAB_WIDTH - 1;
}
else
{
- aRect.Left() = n1-RULER_TAB_CWIDTH2+1;
- aRect.Right() = n1-RULER_TAB_CWIDTH2+RULER_TAB_CWIDTH;
+ aRect.Left() = n1 - RULER_TAB_CWIDTH2 + 1;
+ aRect.Right() = n1 - RULER_TAB_CWIDTH2 + RULER_TAB_CWIDTH;
}
if ( aRect.IsInside( Point( nX, nY ) ) )
{
- pHitTest->eType = RULER_TYPE_TAB;
- pHitTest->nAryPos = i-1;
+ pHitTest->eType = RULER_TYPE_TAB;
+ pHitTest->nAryPos = i;
return sal_True;
}
}
@@ -1487,12 +1509,12 @@ sal_Bool Ruler::ImplHitTest( const Point& rPos, ImplRulerHitTest* pHitTest,
}
// Dann die Einzuege
- if ( mpData->pIndents )
+ if ( !mpData->pIndents.empty() )
{
long nIndentHeight = (mnVirHeight/2) - 1;
long nIndentWidth2 = nIndentHeight-3;
- for ( i = mpData->nIndents; i; i-- )
+ for ( i = mpData->pIndents.size(); i; i-- )
{
nStyle = mpData->pIndents[i-1].nStyle;
if ( (! bRequireStyle || nStyle == nRequiredStyle) &&
@@ -1541,7 +1563,7 @@ sal_Bool Ruler::ImplHitTest( const Point& rPos, ImplRulerHitTest* pHitTest,
nBorderTolerance++;
}
- for ( i = mpData->nBorders; i; i-- )
+ for ( i = mpData->pBorders.size(); i; i-- )
{
n1 = mpData->pBorders[i-1].nPos;
n2 = n1 + mpData->pBorders[i-1].nWidth;
@@ -1634,14 +1656,14 @@ sal_Bool Ruler::ImplHitTest( const Point& rPos, ImplRulerHitTest* pHitTest,
}
// Jetzt nocheinmal die Tabs testen, nur mit etwas mehr spielraum
- if ( mpData->pTabs )
+ if ( !mpData->pTabs.empty() )
{
aRect.Top() = RULER_OFF;
aRect.Bottom() = nHitBottom;
- for ( i = mpData->nTabs; i; i-- )
+ for ( i = mpData->pTabs.size() - 1; i >= 0; i-- )
{
- nStyle = mpData->pTabs[i-1].nStyle;
+ nStyle = mpData->pTabs[i].nStyle;
if ( !(nStyle & RULER_STYLE_INVISIBLE) )
{
nStyle &= RULER_TAB_STYLE;
@@ -1649,22 +1671,22 @@ sal_Bool Ruler::ImplHitTest( const Point& rPos, ImplRulerHitTest* pHitTest,
// Default-Tabs werden nur angezeigt
if ( nStyle != RULER_TAB_DEFAULT )
{
- n1 = mpData->pTabs[i-1].nPos;
+ n1 = mpData->pTabs[i].nPos;
if ( nStyle == RULER_TAB_LEFT )
{
- aRect.Left() = n1;
- aRect.Right() = n1+RULER_TAB_WIDTH-1;
+ aRect.Left() = n1;
+ aRect.Right() = n1 + RULER_TAB_WIDTH - 1;
}
else if ( nStyle == RULER_TAB_RIGHT )
{
- aRect.Right() = n1;
- aRect.Left() = n1-RULER_TAB_WIDTH-1;
+ aRect.Right() = n1;
+ aRect.Left() = n1 - RULER_TAB_WIDTH - 1;
}
else
{
- aRect.Left() = n1-RULER_TAB_CWIDTH2+1;
- aRect.Right() = n1-RULER_TAB_CWIDTH2+RULER_TAB_CWIDTH;
+ aRect.Left() = n1 - RULER_TAB_CWIDTH2 + 1;
+ aRect.Right() = n1 - RULER_TAB_CWIDTH2 + RULER_TAB_CWIDTH;
}
aRect.Left()--;
@@ -1672,8 +1694,8 @@ sal_Bool Ruler::ImplHitTest( const Point& rPos, ImplRulerHitTest* pHitTest,
if ( aRect.IsInside( Point( nX, nY ) ) )
{
- pHitTest->eType = RULER_TYPE_TAB;
- pHitTest->nAryPos = i-1;
+ pHitTest->eType = RULER_TYPE_TAB;
+ pHitTest->nAryPos = i;
return sal_True;
}
}
@@ -2115,7 +2137,7 @@ void Ruler::Resize()
// Hier schon Linien loeschen
sal_Bool bVisible = IsReallyVisible();
- if ( bVisible && mpData->nLines )
+ if ( bVisible && !mpData->pLines.empty() )
{
ImplInvertLines();
mnUpdateFlags |= RULER_UPDATE_LINES;
@@ -2597,14 +2619,14 @@ void Ruler::SetMargin2( long nPos, sal_uInt16 nMarginStyle )
// -----------------------------------------------------------------------
-void Ruler::SetLines( sal_uInt16 n, const RulerLine* pLineAry )
+void Ruler::SetLines( sal_uInt32 aLineArraySize, const RulerLine* pLineArray )
{
// To determine if what has changed
- if ( mpData->nLines == n )
+ if ( mpData->pLines.size() == aLineArraySize )
{
- sal_uInt16 i = n;
- const RulerLine* pAry1 = mpData->pLines;
- const RulerLine* pAry2 = pLineAry;
+ sal_uInt32 i = aLineArraySize;
+ const RulerLine* pAry1 = &mpData->pLines[0];
+ const RulerLine* pAry2 = pLineArray;
while ( i )
{
if ( (pAry1->nPos != pAry2->nPos) ||
@@ -2630,24 +2652,22 @@ void Ruler::SetLines( sal_uInt16 n, const RulerLine* pLineAry )
ImplInvertLines();
// New data set
- if ( !n || !pLineAry )
+ if ( !aLineArraySize || !pLineArray )
{
- if ( !mpData->pLines )
+ if ( mpData->pLines.empty() )
return;
- delete[] mpData->pLines;
- mpData->nLines = 0;
- mpData->pLines = NULL;
+ mpData->pLines.clear();
}
else
{
- if ( mpData->nLines != n )
+ if ( mpData->pLines.size() != aLineArraySize )
{
- delete[] mpData->pLines;
- mpData->nLines = n;
- mpData->pLines = new RulerLine[n];
+ mpData->pLines.resize(aLineArraySize);
}
- memcpy( mpData->pLines, pLineAry, n*sizeof( RulerLine ) );
+ std::copy( pLineArray,
+ pLineArray + aLineArraySize,
+ mpData->pLines.begin() );
// Linien neu ausgeben
if ( bMustUpdate )
@@ -2657,29 +2677,25 @@ void Ruler::SetLines( sal_uInt16 n, const RulerLine* pLineAry )
// -----------------------------------------------------------------------
-void Ruler::SetBorders( sal_uInt16 n, const RulerBorder* pBrdAry )
+void Ruler::SetBorders( sal_uInt32 aBorderArraySize, const RulerBorder* pBorderArray )
{
- if ( !n || !pBrdAry )
+ if ( !aBorderArraySize || !pBorderArray )
{
- if ( !mpData->pBorders )
+ if ( mpData->pBorders.empty() )
return;
- delete[] mpData->pBorders;
- mpData->nBorders = 0;
- mpData->pBorders = NULL;
+ mpData->pBorders.clear();
}
else
{
- if ( mpData->nBorders != n )
+ if ( mpData->pBorders.size() != aBorderArraySize )
{
- delete[] mpData->pBorders;
- mpData->nBorders = n;
- mpData->pBorders = new RulerBorder[n];
+ mpData->pBorders.resize(aBorderArraySize);
}
else
{
- sal_uInt16 i = n;
- const RulerBorder* pAry1 = mpData->pBorders;
- const RulerBorder* pAry2 = pBrdAry;
+ sal_uInt32 i = aBorderArraySize;
+ const RulerBorder* pAry1 = &mpData->pBorders[0];
+ const RulerBorder* pAry2 = pBorderArray;
while ( i )
{
if ( (pAry1->nPos != pAry2->nPos) ||
@@ -2693,8 +2709,9 @@ void Ruler::SetBorders( sal_uInt16 n, const RulerBorder* pBrdAry )
if ( !i )
return;
}
-
- memcpy( mpData->pBorders, pBrdAry, n*sizeof( RulerBorder ) );
+ std::copy( pBorderArray,
+ pBorderArray + aBorderArraySize,
+ mpData->pBorders.begin() );
}
ImplUpdate();
@@ -2702,30 +2719,26 @@ void Ruler::SetBorders( sal_uInt16 n, const RulerBorder* pBrdAry )
// -----------------------------------------------------------------------
-void Ruler::SetIndents( sal_uInt16 n, const RulerIndent* pIndentAry )
+void Ruler::SetIndents( sal_uInt32 aIndentArraySize, const RulerIndent* pIndentArray )
{
- if ( !n || !pIndentAry )
+ if ( !aIndentArraySize || !pIndentArray )
{
- if ( !mpData->pIndents )
+ if ( mpData->pIndents.empty() )
return;
- delete[] mpData->pIndents;
- mpData->nIndents = 0;
- mpData->pIndents = NULL;
+ mpData->pIndents.clear();
}
else
{
- if ( mpData->nIndents != n )
+ if ( mpData->pIndents.size() != aIndentArraySize )
{
- delete[] mpData->pIndents;
- mpData->nIndents = n;
- mpData->pIndents = new RulerIndent[n];
+ mpData->pIndents.resize(aIndentArraySize);
}
else
{
- sal_uInt16 i = n;
- const RulerIndent* pAry1 = mpData->pIndents;
- const RulerIndent* pAry2 = pIndentAry;
+ sal_uInt32 i = aIndentArraySize;
+ const RulerIndent* pAry1 = &mpData->pIndents[0];
+ const RulerIndent* pAry2 = pIndentArray;
while ( i )
{
if ( (pAry1->nPos != pAry2->nPos) ||
@@ -2739,7 +2752,9 @@ void Ruler::SetIndents( sal_uInt16 n, const RulerIndent* pIndentAry )
return;
}
- memcpy( mpData->pIndents, pIndentAry, n*sizeof( RulerIndent ) );
+ std::copy( pIndentArray,
+ pIndentArray + aIndentArraySize,
+ mpData->pIndents.begin() );
}
ImplUpdate();
@@ -2747,43 +2762,41 @@ void Ruler::SetIndents( sal_uInt16 n, const RulerIndent* pIndentAry )
// -----------------------------------------------------------------------
-void Ruler::SetTabs( sal_uInt16 n, const RulerTab* pTabAry )
+void Ruler::SetTabs( sal_uInt32 aTabArraySize, const RulerTab* pTabArray )
{
- if ( !n || !pTabAry )
+ if ( aTabArraySize == 0 || pTabArray == NULL )
{
- if ( !mpData->pTabs )
+ if ( mpData->pTabs.empty() )
return;
- delete[] mpData->pTabs;
- mpData->nTabs = 0;
- mpData->pTabs = NULL;
+ mpData->pTabs.clear();
}
else
{
- if ( mpData->nTabs != n )
+ if ( mpData->pTabs.size() != aTabArraySize )
{
- delete[] mpData->pTabs;
- mpData->nTabs = n;
- mpData->pTabs = new RulerTab[n];
+ mpData->pTabs.resize(aTabArraySize);
}
else
{
- sal_uInt16 i = n;
- const RulerTab* pAry1 = mpData->pTabs;
- const RulerTab* pAry2 = pTabAry;
+ sal_uInt32 i = aTabArraySize;
+ vector<RulerTab>::iterator aTabIterator = mpData->pTabs.begin();
+ const RulerTab* pInputArray = pTabArray;
while ( i )
{
- if ( (pAry1->nPos != pAry2->nPos) ||
- (pAry1->nStyle != pAry2->nStyle) )
+ RulerTab& aCurrent = *aTabIterator;
+ if ( aCurrent.nPos != pInputArray->nPos ||
+ aCurrent.nStyle != pInputArray->nStyle )
+ {
break;
- pAry1++;
- pAry2++;
+ }
+ aTabIterator++;
+ pInputArray++;
i--;
}
if ( !i )
return;
}
-
- memcpy( mpData->pTabs, pTabAry, n*sizeof( RulerTab ) );
+ std::copy(pTabArray, pTabArray + aTabArraySize, mpData->pTabs.begin());
}
ImplUpdate();
More information about the Libreoffice-commits
mailing list