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

Generated by: LCOV version 1.11