xref: /trunk/main/vcl/source/control/morebtn.cxx (revision d8dff77764cb74143fabc617dc8ee25d946bae78)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 // MARKER(update_precomp.py): autogen include statement, do not remove
23 #include "precompiled_vcl.hxx"
24 #include <vcl/morebtn.hxx>
25 
26 #ifndef _SV_RD_H
27 #include <tools/rc.h>
28 #endif
29 
30 
31 // =======================================================================
32 
33 DECLARE_LIST( ImplMoreWindowList, Window* )
34 
35 struct ImplMoreButtonData
36 {
37     ImplMoreWindowList *mpItemList;
38     XubString           maMoreText;
39     XubString           maLessText;
40 };
41 
42 // =======================================================================
43 
44 void MoreButton::ImplInit( Window* pParent, WinBits nStyle )
45 {
46     mpMBData    = new ImplMoreButtonData;
47     mnDelta     = 0;
48     meUnit      = MAP_PIXEL;
49     mbState     = sal_False;
50 
51     mpMBData->mpItemList = NULL;
52 
53     PushButton::ImplInit( pParent, nStyle );
54 
55     mpMBData->maMoreText = Button::GetStandardText( BUTTON_MORE );
56     mpMBData->maLessText = Button::GetStandardText( BUTTON_LESS );
57 
58     SetHelpText( Button::GetStandardHelpText( BUTTON_MORE ) );
59 
60     ShowState();
61 
62     SetSymbolAlign( SYMBOLALIGN_RIGHT );
63     ImplSetSmallSymbol( sal_True );
64 
65     if ( ! ( nStyle & ( WB_RIGHT | WB_LEFT ) ) )
66     {
67         nStyle |= WB_CENTER;
68         SetStyle( nStyle );
69     }
70 }
71 
72 // -----------------------------------------------------------------------
73 void MoreButton::ShowState()
74 {
75     if ( mbState )
76     {
77         SetSymbol( SYMBOL_SPIN_UP );
78         SetText( mpMBData->maLessText );
79     }
80     else
81     {
82         SetSymbol( SYMBOL_SPIN_DOWN );
83         SetText( mpMBData->maMoreText );
84     }
85 }
86 
87 // -----------------------------------------------------------------------
88 
89 MoreButton::MoreButton( Window* pParent, WinBits nStyle ) :
90     PushButton( WINDOW_MOREBUTTON )
91 {
92     ImplInit( pParent, nStyle );
93 }
94 
95 // -----------------------------------------------------------------------
96 
97 MoreButton::MoreButton( Window* pParent, const ResId& rResId ) :
98     PushButton( WINDOW_MOREBUTTON )
99 {
100     rResId.SetRT( RSC_MOREBUTTON );
101     WinBits nStyle = ImplInitRes( rResId );
102     ImplInit( pParent, nStyle );
103     ImplLoadRes( rResId );
104 
105     if ( !(nStyle & WB_HIDE) )
106         Show();
107 }
108 
109 // -----------------------------------------------------------------------
110 
111 void MoreButton::ImplLoadRes( const ResId& rResId )
112 {
113     PushButton::ImplLoadRes( rResId );
114 
115     sal_uLong nObjMask = ReadLongRes();
116 
117     if ( nObjMask & RSC_MOREBUTTON_STATE )
118     {
119         // Nicht Methode rufen, da Dialog nicht umgeschaltet werden soll
120         mbState = (sal_Bool)ReadShortRes();
121         // SetText( GetText() );
122         ShowState();
123     }
124     if ( nObjMask & RSC_MOREBUTTON_MAPUNIT )
125         meUnit = (MapUnit)ReadLongRes();
126     if ( nObjMask & RSC_MOREBUTTON_DELTA )
127         // Groesse fuer Erweitern des Dialogs
128         mnDelta = ReadShortRes();
129 }
130 
131 // -----------------------------------------------------------------------
132 
133 MoreButton::~MoreButton()
134 {
135     if ( mpMBData->mpItemList )
136         delete mpMBData->mpItemList;
137     delete mpMBData;
138 }
139 
140 // -----------------------------------------------------------------------
141 
142 void MoreButton::Click()
143 {
144     Window*     pParent = GetParent();
145     Size        aSize( pParent->GetSizePixel() );
146     Window*     pWindow = (mpMBData->mpItemList) ? mpMBData->mpItemList->First() : NULL;
147     long        nDeltaPixel = LogicToPixel( Size( 0, mnDelta ), meUnit ).Height();
148 
149     // Status aendern
150     mbState = !mbState;
151     ShowState();
152 
153     // Je nach Status die Fenster updaten
154     if ( mbState )
155     {
156         // Fenster anzeigen
157         while ( pWindow )
158         {
159             pWindow->Show();
160             pWindow = mpMBData->mpItemList->Next();
161         }
162 
163         // Dialogbox anpassen
164         Point aPos( pParent->GetPosPixel() );
165         Rectangle aDeskRect( pParent->ImplGetFrameWindow()->GetDesktopRectPixel() );
166 
167         aSize.Height() += nDeltaPixel;
168         if ( (aPos.Y()+aSize.Height()) > aDeskRect.Bottom() )
169         {
170             aPos.Y() = aDeskRect.Bottom()-aSize.Height();
171 
172             if ( aPos.Y() < aDeskRect.Top() )
173                 aPos.Y() = aDeskRect.Top();
174 
175             pParent->SetPosSizePixel( aPos, aSize );
176         }
177         else
178             pParent->SetSizePixel( aSize );
179     }
180     else
181     {
182         // Dialogbox anpassen
183         aSize.Height() -= nDeltaPixel;
184         pParent->SetSizePixel( aSize );
185 
186         // Fenster nicht mehr anzeigen
187         while ( pWindow )
188         {
189             pWindow->Hide();
190             pWindow = mpMBData->mpItemList->Next();
191         }
192     }
193     PushButton::Click();
194 }
195 
196 // -----------------------------------------------------------------------
197 
198 void MoreButton::AddWindow( Window* pWindow )
199 {
200     if ( !mpMBData->mpItemList )
201         mpMBData->mpItemList = new ImplMoreWindowList( 1024, 16, 16 );
202 
203     mpMBData->mpItemList->Insert( pWindow, LIST_APPEND );
204 
205     if ( mbState )
206         pWindow->Show();
207     else
208         pWindow->Hide();
209 }
210 
211 // -----------------------------------------------------------------------
212 
213 void MoreButton::RemoveWindow( Window* pWindow )
214 {
215     if ( mpMBData->mpItemList )
216         mpMBData->mpItemList->Remove( pWindow );
217 }
218 
219 // -----------------------------------------------------------------------
220 
221 void MoreButton::SetText( const XubString& rText )
222 {
223     PushButton::SetText( rText );
224 }
225 
226 // -----------------------------------------------------------------------
227 
228 XubString MoreButton::GetText() const
229 {
230     return PushButton::GetText();
231 }
232 
233 // -----------------------------------------------------------------------
234 void MoreButton::SetMoreText( const XubString& rText )
235 {
236     if ( mpMBData )
237         mpMBData->maMoreText = rText;
238 
239     if ( !mbState )
240         SetText( rText );
241 }
242 
243 // -----------------------------------------------------------------------
244 XubString MoreButton::GetMoreText() const
245 {
246     if ( mpMBData )
247         return mpMBData->maMoreText;
248     else
249         return PushButton::GetText();
250 }
251 
252 // -----------------------------------------------------------------------
253 void MoreButton::SetLessText( const XubString& rText )
254 {
255     if ( mpMBData )
256         mpMBData->maLessText = rText;
257 
258     if ( mbState )
259         SetText( rText );
260 }
261 
262 // -----------------------------------------------------------------------
263 XubString MoreButton::GetLessText() const
264 {
265     if ( mpMBData )
266         return mpMBData->maLessText;
267     else
268         return PushButton::GetText();
269 }
270 
271 /* vim: set noet sw=4 ts=4: */
272