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
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 GetStatusBar().SetItemText( GetId(), OUString() );
68 else
69 {
70 assert( dynamic_cast< const SvxViewLayoutItem *>( pState ) && "invalid item type" );
71 const sal_uInt16 nColumns = static_cast<const SvxViewLayoutItem*>( pState )->GetValue();
72 const bool bBookMode = static_cast<const SvxViewLayoutItem*>( pState )->IsBookMode();
73
74 // SingleColumn Mode
75 if ( 1 == nColumns )
76 mpImpl->mnState = 0;
77 // Automatic Mode
78 else if ( 0 == nColumns )
79 mpImpl->mnState = 1;
80 // Book Mode
81 else if ( bBookMode && 2 == nColumns )
82 mpImpl->mnState = 2;
83 else
84 mpImpl->mnState = 3;
85 }
86
87 GetStatusBar().SetItemData( GetId(), nullptr ); // force repaint
88}
89
91{
92 vcl::RenderContext* pDev = rUsrEvt.GetRenderContext();
93 tools::Rectangle aRect(rUsrEvt.GetRect());
94
95 const tools::Rectangle aControlRect = getControlRect();
96
97 const bool bSingleColumn = 0 == mpImpl->mnState;
98 const bool bAutomatic = 1 == mpImpl->mnState;
99 const bool bBookMode = 2 == mpImpl->mnState;
100
101 const tools::Long nImageWidthSum = mpImpl->maImageSingleColumn.GetSizePixel().Width() +
102 mpImpl->maImageAutomatic.GetSizePixel().Width() +
103 mpImpl->maImageBookMode.GetSizePixel().Width();
104
105 const tools::Long nXOffset = (aRect.GetWidth() - nImageWidthSum) / 2;
106 const tools::Long nYOffset = (aControlRect.GetHeight() - mpImpl->maImageSingleColumn.GetSizePixel().Height()) / 2;
107
108 aRect.AdjustLeft( nXOffset );
109 aRect.AdjustTop( nYOffset );
110
111 // draw single column image:
112 pDev->DrawImage( aRect.TopLeft(), bSingleColumn ? mpImpl->maImageSingleColumn_Active : mpImpl->maImageSingleColumn );
113
114 // draw automatic image:
115 aRect.AdjustLeft(mpImpl->maImageSingleColumn.GetSizePixel().Width() );
116 pDev->DrawImage( aRect.TopLeft(), bAutomatic ? mpImpl->maImageAutomatic_Active : mpImpl->maImageAutomatic );
117
118 // draw bookmode image:
119 aRect.AdjustLeft(mpImpl->maImageAutomatic.GetSizePixel().Width() );
120 pDev->DrawImage( aRect.TopLeft(), bBookMode ? mpImpl->maImageBookMode_Active : mpImpl->maImageBookMode );
121}
122
124{
125 const tools::Rectangle aRect = getControlRect();
126 const Point aPoint = rEvt.GetPosPixel();
127 const tools::Long nXDiff = aPoint.X() - aRect.Left();
128
129 sal_uInt16 nColumns = 1;
130 bool bBookMode = false;
131
132 const tools::Long nImageWidthSingle = mpImpl->maImageSingleColumn.GetSizePixel().Width();
133 const tools::Long nImageWidthAuto = mpImpl->maImageAutomatic.GetSizePixel().Width();
134 const tools::Long nImageWidthBook = mpImpl->maImageBookMode.GetSizePixel().Width();
135 const tools::Long nImageWidthSum = nImageWidthSingle + nImageWidthAuto + nImageWidthBook;
136
137 const tools::Long nXOffset = (aRect.GetWidth() - nImageWidthSum)/2;
138
139 if ( nXDiff < nXOffset + nImageWidthSingle )
140 {
141 mpImpl->mnState = 0; // single
142 nColumns = 1;
143 }
144 else if ( nXDiff < nXOffset + nImageWidthSingle + nImageWidthAuto )
145 {
146 mpImpl->mnState = 1; // auto
147 nColumns = 0;
148 }
149 else
150 {
151 mpImpl->mnState = 2; // book
152 nColumns = 2;
153 bBookMode = true;
154 }
155
156 // commit state change
157 SvxViewLayoutItem aViewLayout( nColumns, bBookMode );
158
159 css::uno::Any a;
160 aViewLayout.QueryValue( a );
161
162 css::uno::Sequence< css::beans::PropertyValue > aArgs{ comphelper::makePropertyValue("ViewLayout",
163 a) };
164 execute( aArgs );
165
166 return true;
167}
168
170{
171 const tools::Rectangle aRect = getControlRect();
172 const Point aPoint = rEvt.GetPosPixel();
173 const tools::Long nXDiff = aPoint.X() - aRect.Left();
174
175 const tools::Long nImageWidthSingle = mpImpl->maImageSingleColumn.GetSizePixel().Width();
176 const tools::Long nImageWidthAuto = mpImpl->maImageAutomatic.GetSizePixel().Width();
177 const tools::Long nImageWidthBook = mpImpl->maImageBookMode.GetSizePixel().Width();
178 const tools::Long nImageWidthSum = nImageWidthSingle + nImageWidthAuto + nImageWidthBook;
179
180 const tools::Long nXOffset = (aRect.GetWidth() - nImageWidthSum)/2;
181
182 if ( nXDiff < nXOffset + nImageWidthSingle )
183 {
184 GetStatusBar().SetQuickHelpText(GetId(), SwResId(STR_VIEWLAYOUT_ONE));
185 }
186 else if ( nXDiff < nXOffset + nImageWidthSingle + nImageWidthAuto )
187 {
188 GetStatusBar().SetQuickHelpText(GetId(), SwResId(STR_VIEWLAYOUT_MULTI));
189 }
190 else
191 {
192 GetStatusBar().SetQuickHelpText(GetId(), SwResId(STR_VIEWLAYOUT_BOOK));
193 }
194 return true;
195}
196
197/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const Point & GetPosPixel() const
void DrawImage(const Point &rPos, const Image &rImage, DrawImageFlags nStyle=DrawImageFlags::NONE)
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:165
SFX_IMPL_STATUSBAR_CONTROL(SwViewLayoutControl, SvxViewLayoutItem)