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