LibreOffice Module sw (master) 1
viewlayoutctrl.cxx
Go to the documentation of this file.
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 <viewlayoutctrl.hxx>
21
22#include <com/sun/star/beans/PropertyValue.hpp>
23
25#include <vcl/event.hxx>
26#include <vcl/status.hxx>
27#include <vcl/image.hxx>
29#include <strings.hrc>
30#include <bitmaps.hlst>
31#include <swtypes.hxx>
32
34
36{
37 sal_uInt16 mnState; // 0 = auto, 1= single, 2 = book, 3 = none, 4 = off
44};
45
46SwViewLayoutControl::SwViewLayoutControl( sal_uInt16 _nSlotId, sal_uInt16 _nId, StatusBar& rStatusBar ) :
47 SfxStatusBarControl( _nSlotId, _nId, rStatusBar ),
48 mpImpl( new SwViewLayoutControl_Impl )
49{
50 mpImpl->mnState = 1;
51
52 mpImpl->maImageSingleColumn = Image(StockImage::Yes, RID_BMP_VIEWLAYOUT_SINGLECOLUMN);
53 mpImpl->maImageSingleColumn_Active = Image(StockImage::Yes, RID_BMP_VIEWLAYOUT_SINGLECOLUMN_ACTIVE);
54 mpImpl->maImageAutomatic = Image(StockImage::Yes, RID_BMP_VIEWLAYOUT_AUTOMATIC);
55 mpImpl->maImageAutomatic_Active = Image(StockImage::Yes, RID_BMP_VIEWLAYOUT_AUTOMATIC_ACTIVE);
56 mpImpl->maImageBookMode = Image(StockImage::Yes, RID_BMP_VIEWLAYOUT_BOOKMODE);
57 mpImpl->maImageBookMode_Active = Image(StockImage::Yes, RID_BMP_VIEWLAYOUT_BOOKMODE_ACTIVE);
58}
59
61{
62}
63
64void SwViewLayoutControl::StateChangedAtStatusBarControl( sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState )
65{
66 if ( SfxItemState::DEFAULT != eState || pState->IsVoidItem() )
67 {
68 GetStatusBar().SetItemText( GetId(), OUString() );
69 mpImpl->mnState = 4; //tdf#148441 switch off, if disabled
70 }
71 else
72 {
73 assert( dynamic_cast< const SvxViewLayoutItem *>( pState ) && "invalid item type" );
74 const sal_uInt16 nColumns = static_cast<const SvxViewLayoutItem*>( pState )->GetValue();
75 const bool bBookMode = static_cast<const SvxViewLayoutItem*>( pState )->IsBookMode();
76
77 // SingleColumn Mode
78 if ( 1 == nColumns )
79 mpImpl->mnState = 0;
80 // Automatic Mode
81 else if ( 0 == nColumns )
82 mpImpl->mnState = 1;
83 // Book Mode
84 else if ( bBookMode && 2 == nColumns )
85 mpImpl->mnState = 2;
86 else
87 mpImpl->mnState = 3;
88 }
89
90 GetStatusBar().SetItemData( GetId(), nullptr ); // force repaint
91}
92
94{
95 vcl::RenderContext* pDev = rUsrEvt.GetRenderContext();
96 tools::Rectangle aRect(rUsrEvt.GetRect());
97
98 const tools::Rectangle aControlRect = getControlRect();
99
100 if (mpImpl->mnState < 4)
101 {
102 const bool bSingleColumn = 0 == mpImpl->mnState;
103 const bool bAutomatic = 1 == mpImpl->mnState;
104 const bool bBookMode = 2 == mpImpl->mnState;
105 const int nDistance = 6;
106
107 const tools::Long nImageWidthSum = mpImpl->maImageSingleColumn.GetSizePixel().Width() +
108 mpImpl->maImageAutomatic.GetSizePixel().Width() +
109 mpImpl->maImageBookMode.GetSizePixel().Width();
110
111 const tools::Long nXOffset = (aRect.GetWidth() - nImageWidthSum - (2* nDistance)) / 2;
112 const tools::Long nYOffset = (aControlRect.GetHeight() - mpImpl->maImageSingleColumn.GetSizePixel().Height()) / 2;
113
114 aRect.AdjustLeft( nXOffset );
115 aRect.AdjustTop( nYOffset );
116
117 // draw single column image:
118 pDev->DrawImage( aRect.TopLeft(), bSingleColumn ? mpImpl->maImageSingleColumn_Active : mpImpl->maImageSingleColumn );
119
120 // draw automatic image:
121 aRect.AdjustLeft(mpImpl->maImageSingleColumn.GetSizePixel().Width() + nDistance);
122 pDev->DrawImage( aRect.TopLeft(), bAutomatic ? mpImpl->maImageAutomatic_Active : mpImpl->maImageAutomatic );
123
124 // draw bookmode image:
125 aRect.AdjustLeft(mpImpl->maImageAutomatic.GetSizePixel().Width() + nDistance);
126 pDev->DrawImage( aRect.TopLeft(), bBookMode ? mpImpl->maImageBookMode_Active : mpImpl->maImageBookMode );
127 }
128 else
129 {
130 pDev->DrawRect( aControlRect );
131 }
132}
133
135{
136 if (mpImpl->mnState < 4)
137 {
138 const tools::Rectangle aRect = getControlRect();
139 const Point aPoint = rEvt.GetPosPixel();
140 const tools::Long nXDiff = aPoint.X() - aRect.Left();
141
142 sal_uInt16 nColumns = 1;
143 bool bBookMode = false;
144
145 const tools::Long nImageWidthSingle = mpImpl->maImageSingleColumn.GetSizePixel().Width();
146 const tools::Long nImageWidthAuto = mpImpl->maImageAutomatic.GetSizePixel().Width();
147 const tools::Long nImageWidthBook = mpImpl->maImageBookMode.GetSizePixel().Width();
148 const tools::Long nImageWidthSum = nImageWidthSingle + nImageWidthAuto + nImageWidthBook;
149
150 const tools::Long nXOffset = (aRect.GetWidth() - nImageWidthSum)/2;
151
152 if ( nXDiff < nXOffset + nImageWidthSingle )
153 {
154 mpImpl->mnState = 0; // single
155 nColumns = 1;
156 }
157 else if ( nXDiff < nXOffset + nImageWidthSingle + nImageWidthAuto )
158 {
159 mpImpl->mnState = 1; // auto
160 nColumns = 0;
161 }
162 else
163 {
164 mpImpl->mnState = 2; // book
165 nColumns = 2;
166 bBookMode = true;
167 }
168
169 // commit state change
170 SvxViewLayoutItem aViewLayout( nColumns, bBookMode );
171
172 css::uno::Any a;
173 aViewLayout.QueryValue( a );
174
175 css::uno::Sequence< css::beans::PropertyValue > aArgs{ comphelper::makePropertyValue("ViewLayout",
176 a) };
177 execute( aArgs );
178 }
179 return true;
180}
181
183{
184 if (mpImpl->mnState < 4)
185 {
186 const tools::Rectangle aRect = getControlRect();
187 const Point aPoint = rEvt.GetPosPixel();
188 const tools::Long nXDiff = aPoint.X() - aRect.Left();
189
190 const tools::Long nImageWidthSingle = mpImpl->maImageSingleColumn.GetSizePixel().Width();
191 const tools::Long nImageWidthAuto = mpImpl->maImageAutomatic.GetSizePixel().Width();
192 const tools::Long nImageWidthBook = mpImpl->maImageBookMode.GetSizePixel().Width();
193 const tools::Long nImageWidthSum = nImageWidthSingle + nImageWidthAuto + nImageWidthBook;
194
195 const tools::Long nXOffset = (aRect.GetWidth() - nImageWidthSum)/2;
196
197 if ( nXDiff < nXOffset + nImageWidthSingle )
198 {
199 GetStatusBar().SetQuickHelpText(GetId(), SwResId(STR_VIEWLAYOUT_ONE));
200 }
201 else if ( nXDiff < nXOffset + nImageWidthSingle + nImageWidthAuto )
202 {
203 GetStatusBar().SetQuickHelpText(GetId(), SwResId(STR_VIEWLAYOUT_MULTI));
204 }
205 else
206 {
207 GetStatusBar().SetQuickHelpText(GetId(), SwResId(STR_VIEWLAYOUT_BOOK));
208 }
209 }
210 return true;
211}
212
213/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const Point & GetPosPixel() const
void DrawRect(const tools::Rectangle &rRect)
void DrawImage(const Point &rPos, const Image &rImage, DrawImageFlags nStyle=DrawImageFlags::NONE)
constexpr tools::Long X() const
virtual bool IsVoidItem() const
StatusBar & GetStatusBar() const
sal_uInt16 GetId() const
void SetItemText(sal_uInt16 nItemId, const OUString &rText, int nCharsWidth=-1)
void SetQuickHelpText(sal_uInt16 nItemId, const OUString &rText)
void SetItemData(sal_uInt16 nItemId, void *pNewData)
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
SwViewLayoutControl(sal_uInt16 nSlotId, sal_uInt16 nId, StatusBar &rStb)
virtual bool MouseButtonDown(const MouseEvent &) override
virtual bool MouseMove(const MouseEvent &) override
virtual void Paint(const UserDrawEvent &rEvt) override
virtual void StateChangedAtStatusBarControl(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
virtual ~SwViewLayoutControl() override
std::unique_ptr< SwViewLayoutControl_Impl > mpImpl
vcl::RenderContext * GetRenderContext() const
const tools::Rectangle & GetRect() const
constexpr tools::Long GetWidth() const
constexpr Point TopLeft() const
tools::Long AdjustTop(tools::Long nVertMoveDelta)
constexpr tools::Long GetHeight() const
tools::Long AdjustLeft(tools::Long nHorzMoveDelta)
constexpr tools::Long Left() const
uno_Any a
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
long Long
const char GetValue[]
SfxItemState
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:168
SFX_IMPL_STATUSBAR_CONTROL(SwViewLayoutControl, SvxViewLayoutItem)