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 <vcl/morebtn.hxx>
21 :
22 : #include <tools/rc.h>
23 : #include <vector>
24 :
25 : typedef ::std::vector< vcl::Window* > ImplMoreWindowList;
26 :
27 0 : struct ImplMoreButtonData
28 : {
29 : ImplMoreWindowList *mpItemList;
30 : OUString maMoreText;
31 : OUString maLessText;
32 : };
33 :
34 0 : void MoreButton::ImplInit( vcl::Window* pParent, WinBits nStyle )
35 : {
36 0 : mpMBData = new ImplMoreButtonData;
37 0 : mnDelta = 0;
38 0 : meUnit = MAP_PIXEL;
39 0 : mbState = false;
40 :
41 0 : mpMBData->mpItemList = NULL;
42 :
43 0 : PushButton::ImplInit( pParent, nStyle );
44 :
45 0 : mpMBData->maMoreText = Button::GetStandardText( BUTTON_MORE );
46 0 : mpMBData->maLessText = Button::GetStandardText( BUTTON_LESS );
47 :
48 0 : ShowState();
49 :
50 0 : SetSymbolAlign(SYMBOLALIGN_RIGHT);
51 0 : SetImageAlign(IMAGEALIGN_RIGHT); //Resoves: fdo#31849 ensure button remains vertically centered
52 0 : SetSmallSymbol(true);
53 :
54 0 : if ( ! ( nStyle & ( WB_RIGHT | WB_LEFT ) ) )
55 : {
56 0 : nStyle |= WB_CENTER;
57 0 : SetStyle( nStyle );
58 : }
59 0 : }
60 :
61 0 : void MoreButton::ShowState()
62 : {
63 0 : if ( mbState )
64 : {
65 0 : SetSymbol( SymbolType::PAGEUP );
66 0 : SetText( mpMBData->maLessText );
67 : }
68 : else
69 : {
70 0 : SetSymbol( SymbolType::PAGEDOWN );
71 0 : SetText( mpMBData->maMoreText );
72 : }
73 0 : }
74 :
75 0 : MoreButton::MoreButton( vcl::Window* pParent, WinBits nStyle ) :
76 0 : PushButton( WINDOW_MOREBUTTON )
77 : {
78 0 : ImplInit( pParent, nStyle );
79 0 : }
80 :
81 0 : MoreButton::~MoreButton()
82 : {
83 0 : delete mpMBData->mpItemList;
84 0 : delete mpMBData;
85 0 : }
86 :
87 0 : void MoreButton::Click()
88 : {
89 0 : vcl::Window* pParent = GetParent();
90 0 : Size aSize( pParent->GetSizePixel() );
91 0 : long nDeltaPixel = LogicToPixel( Size( 0, mnDelta ), meUnit ).Height();
92 :
93 : // Change status
94 0 : mbState = !mbState;
95 0 : ShowState();
96 :
97 : // Update the windows according to the status
98 0 : if ( mbState )
99 : {
100 : // Show window
101 0 : if ( mpMBData->mpItemList ) {
102 0 : for ( size_t i = 0, n = mpMBData->mpItemList->size(); i < n; ++i ) {
103 0 : (*mpMBData->mpItemList)[ i ]->Show();
104 : }
105 : }
106 :
107 : // Adapt dialogbox
108 0 : Point aPos( pParent->GetPosPixel() );
109 0 : Rectangle aDeskRect( pParent->ImplGetFrameWindow()->GetDesktopRectPixel() );
110 :
111 0 : aSize.Height() += nDeltaPixel;
112 0 : if ( (aPos.Y()+aSize.Height()) > aDeskRect.Bottom() )
113 : {
114 0 : aPos.Y() = aDeskRect.Bottom()-aSize.Height();
115 :
116 0 : if ( aPos.Y() < aDeskRect.Top() )
117 0 : aPos.Y() = aDeskRect.Top();
118 :
119 0 : pParent->SetPosSizePixel( aPos, aSize );
120 : }
121 : else
122 0 : pParent->SetSizePixel( aSize );
123 : }
124 : else
125 : {
126 : // Adapt Dialogbox
127 0 : aSize.Height() -= nDeltaPixel;
128 0 : pParent->SetSizePixel( aSize );
129 :
130 : // Hide window(s) again
131 0 : if ( mpMBData->mpItemList ) {
132 0 : for ( size_t i = 0, n = mpMBData->mpItemList->size(); i < n; ++i ) {
133 0 : (*mpMBData->mpItemList)[ i ]->Hide();
134 : }
135 : }
136 : }
137 : // Call Click handler here, so that we can initialize the Controls
138 0 : PushButton::Click();
139 0 : }
140 :
141 0 : void MoreButton::SetText( const OUString& rText )
142 : {
143 0 : PushButton::SetText( rText );
144 0 : }
145 :
146 0 : OUString MoreButton::GetText() const
147 : {
148 0 : return PushButton::GetText();
149 1233 : }
150 :
151 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|