LibreOffice Module vcl (master)  1
morebtn.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 <vcl/toolkit/morebtn.hxx>
21 #include <vcl/stdtext.hxx>
22 
24 {
25  OUString maMoreText;
26  OUString maLessText;
27 };
28 
29 void MoreButton::ImplInit( vcl::Window* pParent, WinBits nStyle )
30 {
31  mpMBData.reset(new ImplMoreButtonData);
32  mbState = false;
33 
34  PushButton::ImplInit( pParent, nStyle );
35 
36  mpMBData->maMoreText = GetStandardText( StandardButtonType::More );
37  mpMBData->maLessText = GetStandardText( StandardButtonType::Less );
38 
39  ShowState();
40 
41  SetSymbolAlign(SymbolAlign::RIGHT);
42  SetImageAlign(ImageAlign::Right); //Resolves: fdo#31849 ensure button remains vertically centered
44 
45  if ( ! ( nStyle & ( WB_RIGHT | WB_LEFT ) ) )
46  {
47  nStyle |= WB_CENTER;
48  SetStyle( nStyle );
49  }
50 }
51 
53 {
54  if ( mbState )
55  {
57  SetText( mpMBData->maLessText );
58  }
59  else
60  {
62  SetText( mpMBData->maMoreText );
63  }
64 }
65 
68 {
69  ImplInit( pParent, nStyle );
70 }
71 
73 {
74  disposeOnce();
75 }
76 
78 {
79  mpMBData.reset();
81 }
82 
84 {
85  vcl::Window* pParent = GetParent();
86  Size aSize( pParent->GetSizePixel() );
87  long nDeltaPixel = LogicToPixel(Size(0, 0), MapMode(MapUnit::MapPixel)).Height();
88 
89  // Change status
90  mbState = !mbState;
91  ShowState();
92 
93  // Update the windows according to the status
94  if ( mbState )
95  {
96  // Adapt dialogbox
97  Point aPos( pParent->GetPosPixel() );
98  tools::Rectangle aDeskRect( pParent->ImplGetFrameWindow()->GetDesktopRectPixel() );
99 
100  aSize.AdjustHeight(nDeltaPixel );
101  if ( (aPos.Y()+aSize.Height()) > aDeskRect.Bottom() )
102  {
103  aPos.setY( aDeskRect.Bottom()-aSize.Height() );
104 
105  if ( aPos.Y() < aDeskRect.Top() )
106  aPos.setY( aDeskRect.Top() );
107 
108  pParent->SetPosSizePixel( aPos, aSize );
109  }
110  else
111  pParent->SetSizePixel( aSize );
112  }
113  else
114  {
115  // Adapt Dialogbox
116  aSize.AdjustHeight( -nDeltaPixel );
117  pParent->SetSizePixel( aSize );
118  }
119  // Call Click handler here, so that we can initialize the Controls
121 }
122 
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual Point GetPosPixel() const
Definition: window.cxx:2806
bool mbState
Definition: morebtn.hxx:37
void Click() override
Definition: morebtn.cxx:83
OUString GetStandardText(StandardButtonType eButton)
Definition: stdtext.cxx:93
virtual Size GetSizePixel() const
Definition: window.cxx:2364
SAL_DLLPRIVATE vcl::Window * ImplGetFrameWindow() const
Definition: window2.cxx:890
virtual void SetSizePixel(const Size &rNewSize)
Definition: window2.cxx:1251
WinBits const WB_RIGHT
tools::Rectangle GetDesktopRectPixel() const
Definition: window.cxx:2811
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: button.cxx:105
SAL_DLLPRIVATE void ImplInit(vcl::Window *pParent, WinBits nStyle)
Definition: button.cxx:585
void SetSymbolAlign(SymbolAlign eAlign)
Definition: button.cxx:1518
sal_Int64 WinBits
void SetSymbol(SymbolType eSymbol)
Definition: button.cxx:1509
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: morebtn.cxx:77
std::unique_ptr< ImplMoreButtonData > mpMBData
Definition: morebtn.hxx:36
virtual void Click()
Definition: button.cxx:121
void SetImageAlign(ImageAlign eAlign)
Definition: button.cxx:146
MoreButton(const MoreButton &)=delete
virtual ~MoreButton() override
Definition: morebtn.cxx:72
void setY(long y)
virtual void SetText(const OUString &rStr) override
Definition: ctrl.cxx:95
SAL_DLLPRIVATE void ShowState()
Definition: morebtn.cxx:52
vcl::Window * GetParent() const
Definition: window2.cxx:1086
WinBits const WB_LEFT
void SetStyle(WinBits nStyle)
Definition: window.cxx:1925
virtual void SetPosSizePixel(const Point &rNewPos, const Size &rNewSize)
Definition: window2.cxx:1257
Point LogicToPixel(const Point &rLogicPt) const
Definition: map.cxx:940
void SetSmallSymbol()
Definition: button.cxx:502
WindowType
OUString maLessText
Definition: morebtn.cxx:26
WinBits const WB_CENTER
SAL_DLLPRIVATE void ImplInit(vcl::Window *pParent, WinBits nStyle)
Definition: morebtn.cxx:29
OUString maMoreText
Definition: morebtn.cxx:25