LCOV - code coverage report
Current view: top level - sw/source/ui/envelp - labfmt.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 401 0.0 %
Date: 2014-11-03 Functions: 0 32 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <tools/poly.hxx>
      21             : #include <vcl/layout.hxx>
      22             : #include <vcl/settings.hxx>
      23             : 
      24             : #include <viewopt.hxx>
      25             : 
      26             : #include "swtypes.hxx"
      27             : #include "cmdid.h"
      28             : #include "label.hxx"
      29             : #include "../../uibase/envelp/labimp.hxx"
      30             : #include "labimg.hxx"
      31             : #include "labfmt.hxx"
      32             : #include "uitool.hxx"
      33             : 
      34             : #include "../../uibase/envelp/label.hrc"
      35             : #include "labfmt.hrc"
      36             : #include <unomid.h>
      37             : #include <boost/scoped_ptr.hpp>
      38             : 
      39             : using namespace utl;
      40             : using namespace ::com::sun::star::uno;
      41             : using namespace ::com::sun::star::beans;
      42             : 
      43             : #define ROUND(x) static_cast<long>((x) + .5)
      44             : 
      45           0 : SwLabPreview::SwLabPreview(vcl::Window* pParent)
      46             :     : Window(pParent, 0)
      47             :     , aGrayColor(COL_LIGHTGRAY)
      48             :     , aHDistStr(SW_RESSTR(STR_HDIST))
      49             :     , aVDistStr(SW_RESSTR(STR_VDIST))
      50             :     , aWidthStr(SW_RESSTR(STR_WIDTH))
      51             :     , aHeightStr(SW_RESSTR(STR_HEIGHT))
      52             :     , aLeftStr(SW_RESSTR(STR_LEFT))
      53             :     , aUpperStr(SW_RESSTR(STR_UPPER))
      54             :     , aColsStr(SW_RESSTR(STR_COLS))
      55             :     , aRowsStr(SW_RESSTR(STR_ROWS))
      56             :     , aPWidthStr(SW_RESSTR(STR_PWIDTH))
      57           0 :     , aPHeightStr(SW_RESSTR(STR_PHEIGHT))
      58             : {
      59           0 :     SetMapMode(MAP_PIXEL);
      60             : 
      61           0 :     const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
      62           0 :     const Color& rWinColor = rStyleSettings.GetWindowColor();
      63           0 :     SetBackground(Wallpaper(rWinColor));
      64             : 
      65           0 :     vcl::Font aFont = GetFont();
      66           0 :     aFont.SetTransparent(true);
      67           0 :     aFont.SetWeight  (WEIGHT_NORMAL);
      68           0 :     SetFont(aFont);
      69             : 
      70           0 :     lHDistWidth  = GetTextWidth(aHDistStr );
      71           0 :     lVDistWidth  = GetTextWidth(aVDistStr );
      72           0 :     lHeightWidth = GetTextWidth(aHeightStr);
      73           0 :     lLeftWidth   = GetTextWidth(aLeftStr  );
      74           0 :     lUpperWidth  = GetTextWidth(aUpperStr );
      75           0 :     lColsWidth   = GetTextWidth(aColsStr  );
      76           0 :     lPWidthWidth  = GetTextWidth(aPWidthStr);
      77           0 :     lPHeightWidth = GetTextWidth(aPHeightStr);
      78           0 :     lXHeight = GetTextHeight();
      79           0 :     lXWidth  = GetTextWidth(OUString('X'));
      80           0 : }
      81             : 
      82           0 : Size SwLabPreview::GetOptimalSize() const
      83             : {
      84           0 :     return LogicToPixel(Size(146 , 161), MapMode(MAP_APPFONT));
      85             : }
      86             : 
      87           0 : extern "C" SAL_DLLPUBLIC_EXPORT vcl::Window* SAL_CALL makeSwLabPreview(vcl::Window *pParent, VclBuilder::stringmap &)
      88             : {
      89           0 :     return new SwLabPreview(pParent);
      90             : }
      91             : 
      92           0 : void SwLabPreview::Paint(const Rectangle &)
      93             : {
      94           0 :     const Size aSz(GetOutputSizePixel());
      95             : 
      96           0 :     const long lOutWPix   = aSz.Width ();
      97           0 :     const long lOutHPix   = aSz.Height();
      98             : 
      99             :     // Scale factor
     100           0 :     const float fxpix = (float)(lOutWPix - (2 * (lLeftWidth + 15))) / (float)lOutWPix;
     101             : 
     102           0 :     const long lOutWPix23 = (long)((float)lOutWPix * fxpix);
     103           0 :     const long lOutHPix23 = (long)((float)lOutHPix * fxpix);
     104             : 
     105           0 :     const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
     106           0 :     const Color& rWinColor = rStyleSettings.GetWindowColor();
     107           0 :     const Color& rFieldTextColor = SwViewOption::GetFontColor();
     108             : 
     109           0 :     vcl::Font aFont = GetFont();
     110           0 :     aFont.SetFillColor( rWinColor );
     111           0 :     aFont.SetColor(rFieldTextColor);
     112           0 :     SetFont(aFont);
     113             : 
     114           0 :     SetBackground(Wallpaper(rWinColor));
     115             : 
     116           0 :     SetLineColor(rWinColor);
     117           0 :     SetFillColor(aGrayColor);
     118           0 :     vcl::Font aPaintFont(GetFont());
     119           0 :     aPaintFont.SetTransparent(false);
     120           0 :     SetFont(aPaintFont);
     121             : 
     122             :     // size of region to be displayed
     123           0 :     const long lDispW = aItem.lLeft + aItem.lHDist
     124           0 :         + ((aItem.nCols == 1) ? aItem.lLeft : ROUND(aItem.lHDist/10.0));
     125           0 :     const long lDispH = aItem.lUpper + aItem.lVDist
     126           0 :         + ((aItem.nRows == 1) ? aItem.lUpper : ROUND(aItem.lVDist/10.0));
     127             : 
     128             :     // Scale factor
     129           0 :     const float fx = (float) lOutWPix23 / std::max(1L, lDispW);
     130           0 :     const float fy = (float) lOutHPix23 / std::max(1L, lDispH);
     131           0 :     const float f  = fx < fy ? fx : fy;
     132             : 
     133             :     // zero point
     134           0 :     const long lOutlineW = ROUND(f * lDispW);
     135           0 :     const long lOutlineH = ROUND(f * lDispH);
     136             : 
     137           0 :     const long lX0 = (lOutWPix - lOutlineW) / 2;
     138           0 :     const long lY0 = (lOutHPix - lOutlineH) / 2;
     139           0 :     const long lX1 = lX0 + ROUND(f *  aItem.lLeft );
     140           0 :     const long lY1 = lY0 + ROUND(f *  aItem.lUpper);
     141           0 :     const long lX2 = lX0 + ROUND(f * (aItem.lLeft  + aItem.lWidth ));
     142           0 :     const long lY2 = lY0 + ROUND(f * (aItem.lUpper + aItem.lHeight));
     143           0 :     const long lX3 = lX0 + ROUND(f * (aItem.lLeft  + aItem.lHDist ));
     144           0 :     const long lY3 = lY0 + ROUND(f * (aItem.lUpper + aItem.lVDist ));
     145             : 
     146             :     // draw outline (area)
     147           0 :     DrawRect(Rectangle(Point(lX0, lY0), Size(lOutlineW, lOutlineH)));
     148             : 
     149             :     // draw outline (border)
     150           0 :     SetLineColor(rFieldTextColor);
     151           0 :     DrawLine(Point(lX0, lY0), Point(lX0 + lOutlineW - 1, lY0)); // Up
     152           0 :     DrawLine(Point(lX0, lY0), Point(lX0, lY0 + lOutlineH - 1)); // Left
     153           0 :     if (aItem.nCols == 1)
     154           0 :         DrawLine(Point(lX0 + lOutlineW - 1, lY0), Point(lX0 + lOutlineW - 1, lY0 + lOutlineH - 1)); // Right
     155           0 :     if (aItem.nRows == 1)
     156           0 :         DrawLine(Point(lX0, lY0 + lOutlineH - 1), Point(lX0 + lOutlineW - 1, lY0 + lOutlineH - 1)); // Down
     157             : 
     158             :     // Labels
     159           0 :     SetClipRegion(vcl::Region(Rectangle(Point(lX0, lY0), Size(lOutlineW, lOutlineH))));
     160           0 :     SetFillColor( COL_LIGHTGRAYBLUE );
     161           0 :     const sal_Int32 nRows = std::min<sal_Int32>(2, aItem.nRows);
     162           0 :     const sal_Int32 nCols = std::min<sal_Int32>(2, aItem.nCols);
     163           0 :     for (sal_Int32 nRow = 0; nRow < nRows; ++nRow)
     164           0 :         for (sal_Int32 nCol = 0; nCol < nCols; ++nCol)
     165             :             DrawRect(Rectangle(
     166           0 :               Point(lX0 + ROUND(f * (aItem.lLeft  + nCol * aItem.lHDist)),
     167           0 :                     lY0 + ROUND(f * (aItem.lUpper + nRow * aItem.lVDist))),
     168           0 :               Size (ROUND(f * aItem.lWidth ),
     169           0 :                     ROUND(f * aItem.lHeight))));
     170           0 :     SetClipRegion();
     171             : 
     172             :     // annotation: left border
     173           0 :     if (aItem.lLeft)
     174             :     {
     175           0 :         long lX = (lX0 + lX1) / 2;
     176           0 :         DrawArrow(Point(lX0, lY0 - 5), Point(lX1, lY0 - 5), false);
     177           0 :         DrawArrow(Point(lX, lY0 - 10), Point(lX, lY0 - 5), true);
     178           0 :         DrawText(Point(lX1 - lLeftWidth, lY0 - 10 - lXHeight), aLeftStr);
     179             :     }
     180             : 
     181             :     // annotation: upper border
     182           0 :     if (aItem.lUpper)
     183             :     {
     184           0 :         DrawArrow(Point(lX0 - 5, lY0), Point(lX0 - 5, lY1), false);
     185           0 :         DrawText(Point(lX0 - 10 - lUpperWidth, lY0 + ROUND(f*aItem.lUpper/2.0 - lXHeight/2.0)), aUpperStr);
     186             :     }
     187             : 
     188             :     // annotation: width and height
     189             :     {
     190           0 :         long lX = lX2 - lXWidth / 2 - lHeightWidth / 2;
     191           0 :         long lY = lY1 + lXHeight;
     192             : 
     193           0 :         DrawLine(Point(lX1, lY), Point(lX2 - 1, lY));
     194           0 :         DrawLine(Point(lX, lY1), Point(lX, lY2 - 1));
     195             : 
     196           0 :         DrawText(Point(lX1 + lXWidth / 2, lY - lXHeight / 2), aWidthStr);
     197           0 :         DrawText(Point(lX - lHeightWidth / 2, lY2 - lXHeight - lXHeight / 2), aHeightStr);
     198             :     }
     199             : 
     200             :     // annotation: horizontal gap
     201           0 :     if (aItem.nCols > 1)
     202             :     {
     203           0 :         long lX = (lX1 + lX3) / 2;
     204           0 :         DrawArrow(Point(lX1, lY0 - 5), Point(lX3, lY0 - 5), false);
     205           0 :         DrawArrow(Point(lX, lY0 - 10), Point(lX, lY0 - 5), true);
     206           0 :         DrawText(Point(lX - lHDistWidth / 2, lY0 - 10 - lXHeight), aHDistStr);
     207             :     }
     208             : 
     209             :     // annotation: vertical gap
     210           0 :     if (aItem.nRows > 1)
     211             :     {
     212           0 :         DrawArrow(Point(lX0 - 5, lY1), Point(lX0 - 5, lY3), false);
     213           0 :         DrawText(Point(lX0 - 10 - lVDistWidth, lY1 + ROUND(f*aItem.lVDist/2.0 - lXHeight/2.0)), aVDistStr);
     214             :     }
     215             : 
     216             :     // annotation: columns
     217             :     {
     218           0 :         long lY = lY0 + lOutlineH + 4;
     219           0 :         DrawArrow(Point(lX0, lY), Point(lX0 + lOutlineW - 1, lY), true);
     220           0 :         DrawText(Point((lX0 + lX0 + lOutlineW - 1) / 2 - lColsWidth / 2, lY + 5), aColsStr);
     221             :     }
     222             : 
     223             :     // annotation: lines
     224             :     {
     225           0 :         long lX = lX0 + lOutlineW + 4;
     226           0 :         DrawArrow(Point(lX, lY0), Point(lX, lY0 + lOutlineH - 1), true);
     227           0 :         DrawText(Point(lX + 5, (lY0 + lY0 + lOutlineH - 1 - lXHeight / 2) / 2), aRowsStr);
     228           0 :     }
     229           0 : }
     230             : 
     231             : // Arrow or interval character
     232           0 : void SwLabPreview::DrawArrow(const Point &rP1, const Point &rP2, bool bArrow)
     233             : {
     234           0 :     DrawLine(rP1, rP2);
     235           0 :     if (bArrow)
     236             :     {
     237           0 :         Point aArr[3];
     238             : 
     239             :         // Arrow character
     240           0 :         if (rP1.Y() == rP2.Y())
     241             :         {
     242             :             // Horizontal
     243           0 :             aArr[0].X() = rP2.X() - 5;
     244           0 :             aArr[0].Y() = rP2.Y() - 2;
     245           0 :             aArr[1].X() = rP2.X();
     246           0 :             aArr[1].Y() = rP2.Y();
     247           0 :             aArr[2].X() = rP2.X() - 5;
     248           0 :             aArr[2].Y() = rP2.Y() + 2;
     249             :         }
     250             :         else
     251             :         {
     252             :             // Vertical
     253           0 :             aArr[0].X() = rP2.X() - 2;
     254           0 :             aArr[0].Y() = rP2.Y() - 5;
     255           0 :             aArr[1].X() = rP2.X() + 2;
     256           0 :             aArr[1].Y() = rP2.Y() - 5;
     257           0 :             aArr[2].X() = rP2.X();
     258           0 :             aArr[2].Y() = rP2.Y();
     259             :         }
     260             : 
     261           0 :         const Color& rFieldTextColor = SwViewOption::GetFontColor();
     262           0 :         SetFillColor(rFieldTextColor);
     263           0 :         DrawPolygon(Polygon(3, aArr));
     264             :     }
     265             :     else
     266             :     {
     267             :         // Interval symbol
     268           0 :         if (rP1.Y() == rP2.Y())
     269             :         {
     270             :             // Horizontal
     271           0 :             DrawLine(Point(rP1.X(), rP1.Y() - 2), Point(rP1.X(), rP1.Y() + 2));
     272           0 :             DrawLine(Point(rP2.X(), rP2.Y() - 2), Point(rP2.X(), rP2.Y() + 2));
     273             :         }
     274             :         else
     275             :         {
     276             :             // Vertical
     277           0 :             DrawLine(Point(rP1.X() - 2, rP1.Y()), Point(rP1.X() + 2, rP1.Y()));
     278           0 :             DrawLine(Point(rP2.X() - 2, rP2.Y()), Point(rP2.X() + 2, rP2.Y()));
     279             :         }
     280             :     }
     281           0 : }
     282             : 
     283           0 : void SwLabPreview::UpdateItem(const SwLabItem& rItem)
     284             : {
     285           0 :     aItem = rItem;
     286           0 :     Invalidate();
     287           0 : }
     288             : 
     289           0 : SwLabFmtPage::SwLabFmtPage(vcl::Window* pParent, const SfxItemSet& rSet)
     290             :     : SfxTabPage(pParent, "LabelFormatPage",
     291             :         "modules/swriter/ui/labelformatpage.ui", &rSet)
     292             :     , bModified(false)
     293           0 :     , aItem((const SwLabItem&) rSet.Get(FN_LABEL))
     294             : {
     295           0 :     SetExchangeSupport();
     296             : 
     297           0 :     get(m_pMakeFI, "make");
     298           0 :     get(m_pTypeFI, "type");
     299           0 :     get(m_pPreview, "preview");
     300           0 :     get(m_pHDistField, "hori");
     301           0 :     get(m_pVDistField, "vert");
     302           0 :     get(m_pWidthField, "width");
     303           0 :     get(m_pHeightField, "height");
     304           0 :     get(m_pLeftField, "left");
     305           0 :     get(m_pUpperField, "top");
     306           0 :     get(m_pColsField, "cols");
     307           0 :     get(m_pRowsField, "rows");
     308           0 :     get(m_pPWidthField, "pagewidth");
     309           0 :     get(m_pPHeightField, "pageheight");
     310           0 :     get(m_pSavePB, "save");
     311             : 
     312             :     // Metrics
     313           0 :     FieldUnit aMetric = ::GetDfltMetric(false);
     314           0 :     SetMetric(*m_pHDistField, aMetric);
     315           0 :     SetMetric(*m_pVDistField , aMetric);
     316           0 :     SetMetric(*m_pWidthField , aMetric);
     317           0 :     SetMetric(*m_pHeightField, aMetric);
     318           0 :     SetMetric(*m_pLeftField  , aMetric);
     319           0 :     SetMetric(*m_pUpperField , aMetric);
     320           0 :     SetMetric(*m_pPWidthField , aMetric);
     321           0 :     SetMetric(*m_pPHeightField, aMetric);
     322             : 
     323             :     // Install handlers
     324           0 :     Link aLk = LINK(this, SwLabFmtPage, ModifyHdl);
     325           0 :     m_pHDistField->SetModifyHdl( aLk );
     326           0 :     m_pVDistField->SetModifyHdl( aLk );
     327           0 :     m_pWidthField->SetModifyHdl( aLk );
     328           0 :     m_pHeightField->SetModifyHdl( aLk );
     329           0 :     m_pLeftField->SetModifyHdl( aLk );
     330           0 :     m_pUpperField->SetModifyHdl( aLk );
     331           0 :     m_pColsField->SetModifyHdl( aLk );
     332           0 :     m_pRowsField->SetModifyHdl( aLk );
     333           0 :     m_pPWidthField->SetModifyHdl( aLk );
     334           0 :     m_pPHeightField->SetModifyHdl( aLk );
     335             : 
     336           0 :     aLk = LINK(this, SwLabFmtPage, LoseFocusHdl);
     337           0 :     m_pHDistField->SetLoseFocusHdl( aLk );
     338           0 :     m_pVDistField->SetLoseFocusHdl( aLk );
     339           0 :     m_pWidthField->SetLoseFocusHdl( aLk );
     340           0 :     m_pHeightField->SetLoseFocusHdl( aLk );
     341           0 :     m_pLeftField->SetLoseFocusHdl( aLk );
     342           0 :     m_pUpperField->SetLoseFocusHdl( aLk );
     343           0 :     m_pColsField->SetLoseFocusHdl( aLk );
     344           0 :     m_pRowsField->SetLoseFocusHdl( aLk );
     345           0 :     m_pPWidthField->SetLoseFocusHdl( aLk );
     346           0 :     m_pPHeightField->SetLoseFocusHdl( aLk );
     347             : 
     348           0 :     m_pSavePB->SetClickHdl( LINK (this, SwLabFmtPage, SaveHdl));
     349             :     // Set timer
     350           0 :     aPreviewTimer.SetTimeout(1000);
     351           0 :     aPreviewTimer.SetTimeoutHdl(LINK(this, SwLabFmtPage, PreviewHdl));
     352           0 : }
     353             : 
     354           0 : SwLabFmtPage::~SwLabFmtPage()
     355             : {
     356           0 : }
     357             : 
     358             : // Modify-handler of MetricFields. start preview timer
     359           0 : IMPL_LINK_NOARG_INLINE_START(SwLabFmtPage, ModifyHdl)
     360             : {
     361           0 :     bModified = true;
     362           0 :     aPreviewTimer.Start();
     363           0 :     return 0;
     364             : }
     365           0 : IMPL_LINK_NOARG_INLINE_END(SwLabFmtPage, ModifyHdl)
     366             : 
     367             : // Invalidate preview
     368           0 : IMPL_LINK_NOARG_INLINE_START(SwLabFmtPage, PreviewHdl)
     369             : {
     370           0 :     aPreviewTimer.Stop();
     371           0 :     ChangeMinMax();
     372           0 :     FillItem( aItem );
     373           0 :     m_pPreview->UpdateItem( aItem );
     374             : 
     375           0 :     return 0;
     376             : }
     377           0 : IMPL_LINK_NOARG_INLINE_END(SwLabFmtPage, PreviewHdl)
     378             : 
     379             : // LoseFocus-Handler: Update on change
     380           0 : IMPL_LINK_INLINE_START( SwLabFmtPage, LoseFocusHdl, Control *, pControl )
     381             : {
     382           0 :     if (((Edit*) pControl)->IsModified())
     383           0 :         PreviewHdl(0);
     384           0 :     return 0;
     385             : }
     386           0 : IMPL_LINK_INLINE_END( SwLabFmtPage, LoseFocusHdl, Control *, pControl )
     387             : 
     388           0 : void SwLabFmtPage::ChangeMinMax()
     389             : {
     390           0 :     long lMax = 31748; // 56 cm
     391           0 :     long nMinSize = 10; // 0,1cm
     392             : 
     393             :     // Min and Max
     394             : 
     395           0 :     int nCols   = m_pColsField->GetValue(),
     396           0 :         nRows   = m_pRowsField->GetValue();
     397           0 :     long lLeft   = static_cast< long >(GETFLDVAL(*m_pLeftField )),
     398           0 :          lUpper  = static_cast< long >(GETFLDVAL(*m_pUpperField)),
     399           0 :          lHDist  = static_cast< long >(GETFLDVAL(*m_pHDistField)),
     400           0 :          lVDist  = static_cast< long >(GETFLDVAL(*m_pVDistField)),
     401           0 :          lWidth  = static_cast< long >(GETFLDVAL(*m_pWidthField)),
     402           0 :          lHeight = static_cast< long >(GETFLDVAL(*m_pHeightField)),
     403           0 :          lMinPWidth  = lLeft  + (nCols - 1) * lHDist + lWidth,
     404           0 :          lMinPHeight = lUpper + (nRows - 1) * lVDist + lHeight;
     405             : 
     406           0 :     m_pHDistField->SetMin(nMinSize, FUNIT_CM);
     407           0 :     m_pVDistField->SetMin(nMinSize, FUNIT_CM);
     408             : 
     409           0 :     m_pHDistField->SetMax((long) 100 * ((lMax - lLeft ) / std::max(1L, (long) nCols)), FUNIT_TWIP);
     410           0 :     m_pVDistField->SetMax((long) 100 * ((lMax - lUpper) / std::max(1L, (long) nRows)), FUNIT_TWIP);
     411             : 
     412           0 :     m_pWidthField->SetMin(nMinSize, FUNIT_CM);
     413           0 :     m_pHeightField->SetMin(nMinSize, FUNIT_CM);
     414             : 
     415           0 :     m_pWidthField->SetMax((long) 100 * (lHDist), FUNIT_TWIP);
     416           0 :     m_pHeightField->SetMax((long) 100 * (lVDist), FUNIT_TWIP);
     417             : 
     418           0 :     m_pLeftField->SetMax((long) 100 * (lMax - nCols * lHDist), FUNIT_TWIP);
     419           0 :     m_pUpperField->SetMax((long) 100 * (lMax - nRows * lVDist), FUNIT_TWIP);
     420             : 
     421           0 :     m_pColsField->SetMin( 1 );
     422           0 :     m_pRowsField->SetMin( 1 );
     423             : 
     424           0 :     m_pColsField->SetMax((lMax - lLeft ) / std::max(1L, lHDist));
     425           0 :     m_pRowsField->SetMax((lMax - lUpper) / std::max(1L, lVDist));
     426           0 :     m_pPWidthField->SetMin( (long) 100 * lMinPWidth,  FUNIT_TWIP );
     427           0 :     m_pPHeightField->SetMin( (long) 100 * lMinPHeight, FUNIT_TWIP );
     428             : 
     429           0 :     m_pPWidthField->SetMax( (long) 100 * lMax, FUNIT_TWIP);
     430           0 :     m_pPHeightField->SetMax( (long) 100 * lMax, FUNIT_TWIP);
     431             :     // First and Last
     432             : 
     433           0 :     m_pHDistField->SetFirst(m_pHDistField->GetMin());
     434           0 :     m_pVDistField->SetFirst(m_pVDistField->GetMin());
     435             : 
     436           0 :     m_pHDistField->SetLast (m_pHDistField->GetMax());
     437           0 :     m_pVDistField->SetLast (m_pVDistField->GetMax());
     438             : 
     439           0 :     m_pWidthField->SetFirst(m_pWidthField->GetMin());
     440           0 :     m_pHeightField->SetFirst(m_pHeightField->GetMin());
     441             : 
     442           0 :     m_pWidthField->SetLast (m_pWidthField->GetMax());
     443           0 :     m_pHeightField->SetLast (m_pHeightField->GetMax());
     444             : 
     445           0 :     m_pLeftField->SetLast (m_pLeftField->GetMax());
     446           0 :     m_pUpperField->SetLast (m_pUpperField->GetMax());
     447             : 
     448           0 :     m_pColsField->SetLast (m_pColsField->GetMax());
     449           0 :     m_pRowsField->SetLast (m_pRowsField->GetMax());
     450           0 :     m_pPWidthField->SetFirst(m_pPWidthField->GetMin());
     451           0 :     m_pPHeightField->SetFirst(m_pPHeightField->GetMin());
     452             : 
     453           0 :     m_pPWidthField->SetLast (m_pPWidthField->GetMax());
     454           0 :     m_pPHeightField->SetLast (m_pPHeightField->GetMax());
     455           0 :     m_pHDistField->Reformat();
     456           0 :     m_pVDistField->Reformat();
     457           0 :     m_pWidthField->Reformat();
     458           0 :     m_pHeightField->Reformat();
     459           0 :     m_pLeftField->Reformat();
     460           0 :     m_pUpperField->Reformat();
     461           0 :     m_pColsField->Reformat();
     462           0 :     m_pRowsField->Reformat();
     463           0 :     m_pPWidthField->Reformat();
     464           0 :     m_pPHeightField->Reformat();
     465           0 : }
     466             : 
     467           0 : SfxTabPage* SwLabFmtPage::Create(vcl::Window* pParent, const SfxItemSet* rSet)
     468             : {
     469           0 :     return new SwLabFmtPage(pParent, *rSet);
     470             : }
     471             : 
     472           0 : void SwLabFmtPage::ActivatePage(const SfxItemSet& rSet)
     473             : {
     474           0 :     SfxItemSet aSet(rSet);
     475           0 :     Reset(&aSet);
     476           0 : }
     477             : 
     478           0 : int SwLabFmtPage::DeactivatePage(SfxItemSet* _pSet)
     479             : {
     480           0 :     if (_pSet)
     481           0 :         FillItemSet(_pSet);
     482             : 
     483           0 :     return sal_True;
     484             : }
     485             : 
     486           0 : void SwLabFmtPage::FillItem(SwLabItem& rItem)
     487             : {
     488           0 :     if (bModified)
     489             :     {
     490           0 :         rItem.aMake = rItem.aType = SW_RESSTR(STR_CUSTOM);
     491             : 
     492           0 :         SwLabRec& rRec = GetParentSwLabDlg()->Recs()[0];
     493           0 :         rItem.lHDist  = rRec.lHDist  = static_cast< long >(GETFLDVAL(*m_pHDistField ));
     494           0 :         rItem.lVDist  = rRec.lVDist  = static_cast< long >(GETFLDVAL(*m_pVDistField ));
     495           0 :         rItem.lWidth  = rRec.lWidth  = static_cast< long >(GETFLDVAL(*m_pWidthField ));
     496           0 :         rItem.lHeight = rRec.lHeight = static_cast< long >(GETFLDVAL(*m_pHeightField));
     497           0 :         rItem.lLeft   = rRec.lLeft   = static_cast< long >(GETFLDVAL(*m_pLeftField  ));
     498           0 :         rItem.lUpper  = rRec.lUpper  = static_cast< long >(GETFLDVAL(*m_pUpperField ));
     499           0 :         rItem.nCols   = rRec.nCols   = static_cast< sal_Int32 >(m_pColsField->GetValue());
     500           0 :         rItem.nRows   = rRec.nRows   = static_cast< sal_Int32 >(m_pRowsField->GetValue());
     501           0 :         rItem.lPWidth  = rRec.lPWidth  = static_cast< long >(GETFLDVAL(*m_pPWidthField ));
     502           0 :         rItem.lPHeight = rRec.lPHeight = static_cast< long >(GETFLDVAL(*m_pPHeightField));
     503             :     }
     504           0 : }
     505             : 
     506           0 : bool SwLabFmtPage::FillItemSet(SfxItemSet* rSet)
     507             : {
     508           0 :     FillItem(aItem);
     509           0 :     rSet->Put(aItem);
     510             : 
     511           0 :     return true;
     512             : }
     513             : 
     514           0 : void SwLabFmtPage::Reset(const SfxItemSet* )
     515             : {
     516             :     // Initialise fields
     517           0 :     GetParentSwLabDlg()->GetLabItem(aItem);
     518             : 
     519           0 :     m_pHDistField->SetMax(100 * aItem.lHDist , FUNIT_TWIP);
     520           0 :     m_pVDistField->SetMax(100 * aItem.lVDist , FUNIT_TWIP);
     521           0 :     m_pWidthField->SetMax(100 * aItem.lWidth , FUNIT_TWIP);
     522           0 :     m_pHeightField->SetMax(100 * aItem.lHeight, FUNIT_TWIP);
     523           0 :     m_pLeftField->SetMax(100 * aItem.lLeft  , FUNIT_TWIP);
     524           0 :     m_pUpperField->SetMax(100 * aItem.lUpper , FUNIT_TWIP);
     525           0 :     m_pPWidthField->SetMax(100 * aItem.lPWidth , FUNIT_TWIP);
     526           0 :     m_pPHeightField->SetMax(100 * aItem.lPHeight, FUNIT_TWIP);
     527             : 
     528           0 :     SETFLDVAL(*m_pHDistField, aItem.lHDist );
     529           0 :     SETFLDVAL(*m_pVDistField , aItem.lVDist );
     530           0 :     SETFLDVAL(*m_pWidthField , aItem.lWidth );
     531           0 :     SETFLDVAL(*m_pHeightField, aItem.lHeight);
     532           0 :     SETFLDVAL(*m_pLeftField  , aItem.lLeft  );
     533           0 :     SETFLDVAL(*m_pUpperField , aItem.lUpper );
     534           0 :     SETFLDVAL(*m_pPWidthField , aItem.lPWidth );
     535           0 :     SETFLDVAL(*m_pPHeightField, aItem.lPHeight);
     536             : 
     537           0 :     m_pColsField->SetMax(aItem.nCols);
     538           0 :     m_pRowsField->SetMax(aItem.nRows);
     539             : 
     540           0 :     m_pColsField->SetValue(aItem.nCols);
     541           0 :     m_pRowsField->SetValue(aItem.nRows);
     542           0 :     m_pMakeFI->SetText(aItem.aMake);
     543           0 :     m_pTypeFI->SetText(aItem.aType);
     544           0 :     PreviewHdl(0);
     545           0 : }
     546             : 
     547           0 : IMPL_LINK_NOARG(SwLabFmtPage, SaveHdl)
     548             : {
     549           0 :     SwLabRec aRec;
     550           0 :     aRec.lHDist  = static_cast< long >(GETFLDVAL(*m_pHDistField));
     551           0 :     aRec.lVDist  = static_cast< long >(GETFLDVAL(*m_pVDistField ));
     552           0 :     aRec.lWidth  = static_cast< long >(GETFLDVAL(*m_pWidthField ));
     553           0 :     aRec.lHeight = static_cast< long >(GETFLDVAL(*m_pHeightField));
     554           0 :     aRec.lLeft   = static_cast< long >(GETFLDVAL(*m_pLeftField  ));
     555           0 :     aRec.lUpper  = static_cast< long >(GETFLDVAL(*m_pUpperField ));
     556           0 :     aRec.nCols   = static_cast< sal_Int32 >(m_pColsField->GetValue());
     557           0 :     aRec.nRows   = static_cast< sal_Int32 >(m_pRowsField->GetValue());
     558           0 :     aRec.lPWidth  = static_cast< long >(GETFLDVAL(*m_pPWidthField ));
     559           0 :     aRec.lPHeight = static_cast< long >(GETFLDVAL(*m_pPHeightField));
     560           0 :     aRec.bCont = aItem.bCont;
     561           0 :     boost::scoped_ptr<SwSaveLabelDlg> pSaveDlg(new SwSaveLabelDlg(this, aRec));
     562           0 :     pSaveDlg->SetLabel(aItem.aLstMake, aItem.aLstType);
     563           0 :     pSaveDlg->Execute();
     564           0 :     if(pSaveDlg->GetLabel(aItem))
     565             :     {
     566           0 :         bModified = false;
     567           0 :         const std::vector<OUString>& rMan = GetParentSwLabDlg()->GetLabelsConfig().GetManufacturers();
     568           0 :         std::vector<OUString>& rMakes(GetParentSwLabDlg()->Makes());
     569           0 :         if(rMakes.size() < rMan.size())
     570             :         {
     571           0 :             rMakes = rMan;
     572             :         }
     573           0 :         m_pMakeFI->SetText(aItem.aMake);
     574           0 :         m_pTypeFI->SetText(aItem.aType);
     575             :     }
     576           0 :     return 0;
     577             : }
     578             : 
     579           0 : SwSaveLabelDlg::SwSaveLabelDlg(SwLabFmtPage* pParent, SwLabRec& rRec)
     580             :     : ModalDialog(pParent, "SaveLabelDialog",
     581             :         "modules/swriter/ui/savelabeldialog.ui")
     582             :     , bSuccess(false)
     583             :     , pLabPage(pParent)
     584           0 :     , rLabRec(rRec)
     585             : {
     586           0 :     get(m_pMakeCB, "brand");
     587           0 :     get(m_pTypeED, "type");
     588           0 :     get(m_pOKPB, "ok");
     589             : 
     590           0 :     m_pOKPB->SetClickHdl(LINK(this, SwSaveLabelDlg, OkHdl));
     591           0 :     Link aLk(LINK(this, SwSaveLabelDlg, ModifyHdl));
     592           0 :     m_pMakeCB->SetModifyHdl(aLk);
     593           0 :     m_pTypeED->SetModifyHdl(aLk);
     594             : 
     595           0 :     SwLabelConfig& rCfg = pLabPage->GetParentSwLabDlg()->GetLabelsConfig();
     596           0 :     const std::vector<OUString>& rMan = rCfg.GetManufacturers();
     597           0 :     for (size_t i = 0; i < rMan.size(); ++i)
     598             :     {
     599           0 :         m_pMakeCB->InsertEntry(rMan[i]);
     600             :     }
     601           0 : }
     602             : 
     603           0 : IMPL_LINK_NOARG(SwSaveLabelDlg, OkHdl)
     604             : {
     605           0 :     SwLabelConfig& rCfg = pLabPage->GetParentSwLabDlg()->GetLabelsConfig();
     606           0 :     OUString sMake(m_pMakeCB->GetText());
     607           0 :     OUString sType(m_pTypeED->GetText());
     608           0 :     if(rCfg.HasLabel(sMake, sType))
     609             :     {
     610           0 :         if ( rCfg.IsPredefinedLabel(sMake, sType) )
     611             :         {
     612             :             SAL_WARN( "sw.envelp", "label is predefined and cannot be overwritten" );
     613           0 :             MessageDialog(this, "CannotSaveLabelDialog", "modules/swriter/ui/cannotsavelabeldialog.ui").Execute();
     614           0 :             return 0;
     615             :         }
     616             : 
     617             :         MessageDialog aQuery(this, "QuerySaveLabelDialog",
     618           0 :             "modules/swriter/ui/querysavelabeldialog.ui");
     619             : 
     620             :         aQuery.set_primary_text(aQuery.get_primary_text().
     621           0 :             replaceAll("%1", sMake).replaceAll("%2", sType));
     622             :         aQuery.set_secondary_text(aQuery.get_secondary_text().
     623           0 :             replaceAll("%1", sMake).replaceAll("%2", sType));
     624             : 
     625           0 :         if (RET_YES != aQuery.Execute())
     626           0 :             return 0;
     627             :     }
     628           0 :     rLabRec.aType = sType;
     629           0 :     rCfg.SaveLabel(sMake, sType, rLabRec);
     630           0 :     bSuccess = true;
     631           0 :     EndDialog(RET_OK);
     632           0 :     return 0;
     633             : }
     634             : 
     635           0 : IMPL_LINK_NOARG(SwSaveLabelDlg, ModifyHdl)
     636             : {
     637           0 :     m_pOKPB->Enable(!m_pMakeCB->GetText().isEmpty() && !m_pTypeED->GetText().isEmpty());
     638           0 :     return 0;
     639             : }
     640             : 
     641           0 : bool SwSaveLabelDlg::GetLabel(SwLabItem& rItem)
     642             : {
     643           0 :     if(bSuccess)
     644             :     {
     645           0 :         rItem.aMake = m_pMakeCB->GetText();
     646           0 :         rItem.aType = m_pTypeED->GetText();
     647           0 :         rItem.lHDist  = rLabRec.lHDist;
     648           0 :         rItem.lVDist  = rLabRec.lVDist;
     649           0 :         rItem.lWidth  = rLabRec.lWidth;
     650           0 :         rItem.lHeight = rLabRec.lHeight;
     651           0 :         rItem.lLeft   = rLabRec.lLeft;
     652           0 :         rItem.lUpper  = rLabRec.lUpper;
     653           0 :         rItem.nCols   = rLabRec.nCols;
     654           0 :         rItem.nRows   = rLabRec.nRows;
     655           0 :         rItem.lPWidth  = rLabRec.lPWidth;
     656           0 :         rItem.lPHeight = rLabRec.lPHeight;
     657             :     }
     658           0 :     return bSuccess;
     659           0 : }
     660             : 
     661             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10