xref: /trunk/main/vcl/source/control/morebtn.cxx (revision 989b13ef2270bbb43d1b5fb03162470a47d7f4cc)
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 DECLARE_LIST( ImplMoreWindowList, Window* )
33 
34 struct ImplMoreButtonData
35 {
36     ImplMoreWindowList *mpItemList;
37     XubString           maMoreText;
38     XubString           maLessText;
39 };
40 
41 // =======================================================================
42 
43 void MoreButton::ImplInit( Window* pParent, WinBits nStyle )
44 {
45     mpMBData    = new ImplMoreButtonData;
46     mnDelta     = 0;
47     meUnit      = MAP_PIXEL;
48     mbState     = sal_False;
49 
50     mpMBData->mpItemList = NULL;
51 
52     PushButton::ImplInit( pParent, nStyle );
53 
54     mpMBData->maMoreText = Button::GetStandardText( BUTTON_MORE );
55     mpMBData->maLessText = Button::GetStandardText( BUTTON_LESS );
56 
57     SetHelpText( Button::GetStandardHelpText( BUTTON_MORE ) );
58 
59     ShowState();
60 
61     SetSymbolAlign( SYMBOLALIGN_RIGHT );
62     ImplSetSmallSymbol( sal_True );
63 
64     if ( ! ( nStyle & ( WB_RIGHT | WB_LEFT ) ) )
65     {
66         nStyle |= WB_CENTER;
67         SetStyle( nStyle );
68     }
69 }
70 
71 // -----------------------------------------------------------------------
72 void MoreButton::ShowState()
73 {
74     if ( mbState )
75     {
76         SetSymbol( SYMBOL_SPIN_UP );
77         SetText( mpMBData->maLessText );
78     }
79     else
80     {
81         SetSymbol( SYMBOL_SPIN_DOWN );
82         SetText( mpMBData->maMoreText );
83     }
84 }
85 
86 // -----------------------------------------------------------------------
87 
88 MoreButton::MoreButton( Window* pParent, WinBits nStyle ) :
89     PushButton( WINDOW_MOREBUTTON )
90 {
91     ImplInit( pParent, nStyle );
92 }
93 
94 // -----------------------------------------------------------------------
95 
96 MoreButton::MoreButton( Window* pParent, const ResId& rResId ) :
97     PushButton( WINDOW_MOREBUTTON )
98 {
99     rResId.SetRT( RSC_MOREBUTTON );
100     WinBits nStyle = ImplInitRes( rResId );
101     ImplInit( pParent, nStyle );
102     ImplLoadRes( rResId );
103 
104     if ( !(nStyle & WB_HIDE) )
105         Show();
106 }
107 
108 // -----------------------------------------------------------------------
109 
110 void MoreButton::ImplLoadRes( const ResId& rResId )
111 {
112     PushButton::ImplLoadRes( rResId );
113 
114     sal_uLong nObjMask = ReadLongRes();
115 
116     if ( nObjMask & RSC_MOREBUTTON_STATE )
117     {
118         // Nicht Methode rufen, da Dialog nicht umgeschaltet werden soll
119         mbState = (sal_Bool)ReadShortRes();
120         // SetText( GetText() );
121         ShowState();
122     }
123     if ( nObjMask & RSC_MOREBUTTON_MAPUNIT )
124         meUnit = (MapUnit)ReadLongRes();
125     if ( nObjMask & RSC_MOREBUTTON_DELTA )
126         // Größe für Erweitern des Dialogs
127         mnDelta = ReadShortRes();
128 }
129 
130 // -----------------------------------------------------------------------
131 
132 MoreButton::~MoreButton()
133 {
134     if ( mpMBData->mpItemList )
135         delete mpMBData->mpItemList;
136     delete mpMBData;
137 }
138 
139 // -----------------------------------------------------------------------
140 
141 void MoreButton::Click()
142 {
143     Window*     pParent = GetParent();
144     Size        aSize( pParent->GetSizePixel() );
145     Window*     pWindow = (mpMBData->mpItemList) ? mpMBData->mpItemList->First() : NULL;
146     long        nDeltaPixel = LogicToPixel( Size( 0, mnDelta ), meUnit ).Height();
147 
148     // Status ändern
149     mbState = !mbState;
150     ShowState();
151 
152     // Je nach Status die Fenster updaten
153     if ( mbState )
154     {
155         // Fenster anzeigen
156         while ( pWindow )
157         {
158             pWindow->Show();
159             pWindow = mpMBData->mpItemList->Next();
160         }
161 
162         // Dialogbox anpassen
163         Point aPos( pParent->GetPosPixel() );
164         Rectangle aDeskRect( pParent->ImplGetFrameWindow()->GetDesktopRectPixel() );
165 
166         aSize.Height() += nDeltaPixel;
167         if ( (aPos.Y()+aSize.Height()) > aDeskRect.Bottom() )
168         {
169             aPos.Y() = aDeskRect.Bottom()-aSize.Height();
170 
171             if ( aPos.Y() < aDeskRect.Top() )
172                 aPos.Y() = aDeskRect.Top();
173 
174             pParent->SetPosSizePixel( aPos, aSize );
175         }
176         else
177             pParent->SetSizePixel( aSize );
178     }
179     else
180     {
181         // Dialogbox anpassen
182         aSize.Height() -= nDeltaPixel;
183         pParent->SetSizePixel( aSize );
184 
185         // Fenster nicht mehr anzeigen
186         while ( pWindow )
187         {
188             pWindow->Hide();
189             pWindow = mpMBData->mpItemList->Next();
190         }
191     }
192     PushButton::Click();
193 }
194 
195 // -----------------------------------------------------------------------
196 
197 void MoreButton::AddWindow( Window* pWindow )
198 {
199     if ( !mpMBData->mpItemList )
200         mpMBData->mpItemList = new ImplMoreWindowList( 1024, 16, 16 );
201 
202     mpMBData->mpItemList->Insert( pWindow, LIST_APPEND );
203 
204     if ( mbState )
205         pWindow->Show();
206     else
207         pWindow->Hide();
208 }
209 
210 // -----------------------------------------------------------------------
211 
212 void MoreButton::RemoveWindow( Window* pWindow )
213 {
214     if ( mpMBData->mpItemList )
215         mpMBData->mpItemList->Remove( pWindow );
216 }
217 
218 // -----------------------------------------------------------------------
219 
220 void MoreButton::SetText( const XubString& rText )
221 {
222     PushButton::SetText( rText );
223 }
224 
225 // -----------------------------------------------------------------------
226 
227 XubString MoreButton::GetText() const
228 {
229     return PushButton::GetText();
230 }
231 
232 // -----------------------------------------------------------------------
233 void MoreButton::SetMoreText( const XubString& rText )
234 {
235     if ( mpMBData )
236         mpMBData->maMoreText = rText;
237 
238     if ( !mbState )
239         SetText( rText );
240 }
241 
242 // -----------------------------------------------------------------------
243 XubString MoreButton::GetMoreText() const
244 {
245     if ( mpMBData )
246         return mpMBData->maMoreText;
247     else
248         return PushButton::GetText();
249 }
250 
251 // -----------------------------------------------------------------------
252 void MoreButton::SetLessText( const XubString& rText )
253 {
254     if ( mpMBData )
255         mpMBData->maLessText = rText;
256 
257     if ( mbState )
258         SetText( rText );
259 }
260 
261 // -----------------------------------------------------------------------
262 XubString MoreButton::GetLessText() const
263 {
264     if ( mpMBData )
265         return mpMBData->maLessText;
266     else
267         return PushButton::GetText();
268 }
269 
270 /* vim: set noet sw=4 ts=4: */
271