xref: /trunk/main/vcl/source/control/morebtn.cxx (revision ad3a95a3)
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(); // IAccessibility2 Implementation 2009
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 //IAccessibility2 Implementation 2009-----
201 	PushButton::Click();
202 //-----IAccessibility2 Implementation 2009
203 }
204 
205 // -----------------------------------------------------------------------
206 
207 void MoreButton::AddWindow( Window* pWindow )
208 {
209 	if ( !mpMBData->mpItemList )
210 		mpMBData->mpItemList = new ImplMoreWindowList( 1024, 16, 16 );
211 
212 	mpMBData->mpItemList->Insert( pWindow, LIST_APPEND );
213 
214 	if ( mbState )
215 		pWindow->Show();
216 	else
217 		pWindow->Hide();
218 }
219 
220 // -----------------------------------------------------------------------
221 
222 void MoreButton::RemoveWindow( Window* pWindow )
223 {
224 	if ( mpMBData->mpItemList )
225 		mpMBData->mpItemList->Remove( pWindow );
226 }
227 
228 // -----------------------------------------------------------------------
229 
230 void MoreButton::SetText( const XubString& rText )
231 {
232 	PushButton::SetText( rText );
233 }
234 
235 // -----------------------------------------------------------------------
236 
237 XubString MoreButton::GetText() const
238 {
239 	return PushButton::GetText();
240 }
241 
242 // -----------------------------------------------------------------------
243 void MoreButton::SetMoreText( const XubString& rText )
244 {
245 	if ( mpMBData )
246         mpMBData->maMoreText = rText;
247 
248     if ( !mbState )
249         SetText( rText );
250 }
251 
252 // -----------------------------------------------------------------------
253 XubString MoreButton::GetMoreText() const
254 {
255 	if ( mpMBData )
256         return mpMBData->maMoreText;
257     else
258         return PushButton::GetText();
259 }
260 
261 // -----------------------------------------------------------------------
262 void MoreButton::SetLessText( const XubString& rText )
263 {
264 	if ( mpMBData )
265         mpMBData->maLessText = rText;
266 
267     if ( mbState )
268         SetText( rText );
269 }
270 
271 // -----------------------------------------------------------------------
272 XubString MoreButton::GetLessText() const
273 {
274 	if ( mpMBData )
275         return mpMBData->maLessText;
276     else
277         return PushButton::GetText();
278 }
279 
280