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

Generated by: LCOV version 1.10