Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <vcl/morebtn.hxx>
30 : :
31 : : #include <tools/rc.h>
32 : : #include <vector>
33 : :
34 : : // =======================================================================
35 : :
36 : : typedef ::std::vector< Window* > ImplMoreWindowList;
37 : :
38 [ # # ][ # # ]: 0 : struct ImplMoreButtonData
39 : : {
40 : : ImplMoreWindowList *mpItemList;
41 : : XubString maMoreText;
42 : : XubString maLessText;
43 : : };
44 : :
45 : : // =======================================================================
46 : :
47 : 0 : void MoreButton::ImplInit( Window* pParent, WinBits nStyle )
48 : : {
49 [ # # ]: 0 : mpMBData = new ImplMoreButtonData;
50 : 0 : mnDelta = 0;
51 : 0 : meUnit = MAP_PIXEL;
52 : 0 : mbState = sal_False;
53 : :
54 : 0 : mpMBData->mpItemList = NULL;
55 : :
56 : 0 : PushButton::ImplInit( pParent, nStyle );
57 : :
58 [ # # ]: 0 : mpMBData->maMoreText = Button::GetStandardText( BUTTON_MORE );
59 [ # # ]: 0 : mpMBData->maLessText = Button::GetStandardText( BUTTON_LESS );
60 : :
61 [ # # ]: 0 : SetHelpText( Button::GetStandardHelpText( BUTTON_MORE ) );
62 : :
63 : 0 : ShowState();
64 : :
65 : 0 : SetSymbolAlign( SYMBOLALIGN_RIGHT );
66 : 0 : ImplSetSmallSymbol( sal_True );
67 : :
68 [ # # ]: 0 : if ( ! ( nStyle & ( WB_RIGHT | WB_LEFT ) ) )
69 : : {
70 : 0 : nStyle |= WB_CENTER;
71 : 0 : SetStyle( nStyle );
72 : : }
73 : 0 : }
74 : :
75 : : // -----------------------------------------------------------------------
76 : 0 : void MoreButton::ShowState()
77 : : {
78 [ # # ]: 0 : if ( mbState )
79 : : {
80 : 0 : SetSymbol( SYMBOL_PAGEUP );
81 : 0 : SetText( mpMBData->maLessText );
82 : : }
83 : : else
84 : : {
85 : 0 : SetSymbol( SYMBOL_PAGEDOWN );
86 : 0 : SetText( mpMBData->maMoreText );
87 : : }
88 : 0 : }
89 : :
90 : : // -----------------------------------------------------------------------
91 : :
92 : 0 : MoreButton::MoreButton( Window* pParent, WinBits nStyle ) :
93 : 0 : PushButton( WINDOW_MOREBUTTON )
94 : : {
95 [ # # ]: 0 : ImplInit( pParent, nStyle );
96 : 0 : }
97 : :
98 : : // -----------------------------------------------------------------------
99 : :
100 : 0 : MoreButton::MoreButton( Window* pParent, const ResId& rResId ) :
101 : 0 : PushButton( WINDOW_MOREBUTTON )
102 : : {
103 : 0 : rResId.SetRT( RSC_MOREBUTTON );
104 [ # # ]: 0 : WinBits nStyle = ImplInitRes( rResId );
105 [ # # ]: 0 : ImplInit( pParent, nStyle );
106 [ # # ]: 0 : ImplLoadRes( rResId );
107 : :
108 [ # # ]: 0 : if ( !(nStyle & WB_HIDE) )
109 [ # # ]: 0 : Show();
110 : 0 : }
111 : :
112 : : // -----------------------------------------------------------------------
113 : :
114 : 0 : void MoreButton::ImplLoadRes( const ResId& rResId )
115 : : {
116 : 0 : PushButton::ImplLoadRes( rResId );
117 : :
118 : 0 : sal_uLong nObjMask = ReadLongRes();
119 : :
120 [ # # ]: 0 : if ( nObjMask & RSC_MOREBUTTON_STATE )
121 : : {
122 : : // Nicht Methode rufen, da Dialog nicht umgeschaltet werden soll
123 : 0 : mbState = (sal_Bool)ReadShortRes();
124 : : // SetText( GetText() );
125 : 0 : ShowState();
126 : : }
127 [ # # ]: 0 : if ( nObjMask & RSC_MOREBUTTON_MAPUNIT )
128 : 0 : meUnit = (MapUnit)ReadLongRes();
129 [ # # ]: 0 : if ( nObjMask & RSC_MOREBUTTON_DELTA )
130 : : // Groesse fuer Erweitern des Dialogs
131 : 0 : mnDelta = ReadShortRes();
132 : 0 : }
133 : :
134 : : // -----------------------------------------------------------------------
135 : :
136 : 0 : MoreButton::~MoreButton()
137 : : {
138 [ # # ]: 0 : if ( mpMBData->mpItemList )
139 [ # # ]: 0 : delete mpMBData->mpItemList;
140 [ # # ][ # # ]: 0 : delete mpMBData;
141 [ # # ]: 0 : }
142 : :
143 : : // -----------------------------------------------------------------------
144 : :
145 : 0 : void MoreButton::Click()
146 : : {
147 [ # # ]: 0 : Window* pParent = GetParent();
148 [ # # ]: 0 : Size aSize( pParent->GetSizePixel() );
149 [ # # ][ # # ]: 0 : long nDeltaPixel = LogicToPixel( Size( 0, mnDelta ), meUnit ).Height();
[ # # ]
150 : :
151 : : // Status aendern
152 : 0 : mbState = !mbState;
153 [ # # ]: 0 : ShowState();
154 : :
155 : : // Hier den Click-Handler rufen, damit vorher die Controls initialisiert
156 : : // werden koennen
157 [ # # ]: 0 : PushButton::Click();
158 : :
159 : : // Je nach Status die Fenster updaten
160 [ # # ]: 0 : if ( mbState )
161 : : {
162 : : // Fenster anzeigen
163 [ # # ]: 0 : if ( mpMBData->mpItemList ) {
164 [ # # ]: 0 : for ( size_t i = 0, n = mpMBData->mpItemList->size(); i < n; ++i ) {
165 [ # # ][ # # ]: 0 : (*mpMBData->mpItemList)[ i ]->Show();
166 : : }
167 : : }
168 : :
169 : : // Dialogbox anpassen
170 [ # # ]: 0 : Point aPos( pParent->GetPosPixel() );
171 [ # # ][ # # ]: 0 : Rectangle aDeskRect( pParent->ImplGetFrameWindow()->GetDesktopRectPixel() );
172 : :
173 : 0 : aSize.Height() += nDeltaPixel;
174 [ # # ]: 0 : if ( (aPos.Y()+aSize.Height()) > aDeskRect.Bottom() )
175 : : {
176 : 0 : aPos.Y() = aDeskRect.Bottom()-aSize.Height();
177 : :
178 [ # # ]: 0 : if ( aPos.Y() < aDeskRect.Top() )
179 : 0 : aPos.Y() = aDeskRect.Top();
180 : :
181 [ # # ]: 0 : pParent->SetPosSizePixel( aPos, aSize );
182 : : }
183 : : else
184 [ # # ]: 0 : pParent->SetSizePixel( aSize );
185 : : }
186 : : else
187 : : {
188 : : // Dialogbox anpassen
189 : 0 : aSize.Height() -= nDeltaPixel;
190 [ # # ]: 0 : pParent->SetSizePixel( aSize );
191 : :
192 : : // Fenster nicht mehr anzeigen
193 [ # # ]: 0 : if ( mpMBData->mpItemList ) {
194 [ # # ]: 0 : for ( size_t i = 0, n = mpMBData->mpItemList->size(); i < n; ++i ) {
195 [ # # ][ # # ]: 0 : (*mpMBData->mpItemList)[ i ]->Hide();
196 : : }
197 : : }
198 : : }
199 : 0 : }
200 : :
201 : : // -----------------------------------------------------------------------
202 : :
203 : 0 : void MoreButton::AddWindow( Window* pWindow )
204 : : {
205 [ # # ]: 0 : if ( !mpMBData->mpItemList )
206 [ # # ]: 0 : mpMBData->mpItemList = new ImplMoreWindowList();
207 : :
208 : 0 : mpMBData->mpItemList->push_back( pWindow );
209 : :
210 [ # # ]: 0 : if ( mbState )
211 : 0 : pWindow->Show();
212 : : else
213 : 0 : pWindow->Hide();
214 : 0 : }
215 : :
216 : : // -----------------------------------------------------------------------
217 : :
218 : 0 : void MoreButton::SetText( const XubString& rText )
219 : : {
220 : 0 : PushButton::SetText( rText );
221 : 0 : }
222 : :
223 : : // -----------------------------------------------------------------------
224 : :
225 : 0 : XubString MoreButton::GetText() const
226 : : {
227 : 0 : return PushButton::GetText();
228 : : }
229 : :
230 : : // -----------------------------------------------------------------------
231 : 0 : void MoreButton::SetMoreText( const XubString& rText )
232 : : {
233 [ # # ]: 0 : if ( mpMBData )
234 : 0 : mpMBData->maMoreText = rText;
235 : :
236 [ # # ]: 0 : if ( !mbState )
237 : 0 : SetText( rText );
238 : 0 : }
239 : :
240 : : // -----------------------------------------------------------------------
241 : 0 : XubString MoreButton::GetMoreText() const
242 : : {
243 [ # # ]: 0 : if ( mpMBData )
244 : 0 : return mpMBData->maMoreText;
245 : : else
246 : 0 : return PushButton::GetText();
247 : : }
248 : :
249 : : // -----------------------------------------------------------------------
250 : 0 : void MoreButton::SetLessText( const XubString& rText )
251 : : {
252 [ # # ]: 0 : if ( mpMBData )
253 : 0 : mpMBData->maLessText = rText;
254 : :
255 [ # # ]: 0 : if ( mbState )
256 : 0 : SetText( rText );
257 : 0 : }
258 : :
259 : : // -----------------------------------------------------------------------
260 : 0 : XubString MoreButton::GetLessText() const
261 : : {
262 [ # # ]: 0 : if ( mpMBData )
263 : 0 : return mpMBData->maLessText;
264 : : else
265 : 0 : return PushButton::GetText();
266 : : }
267 : :
268 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|