xref: /aoo4110/main/vcl/source/control/morebtn.cxx (revision b1cdbd2c)
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 
ImplInit(Window * pParent,WinBits nStyle)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 // -----------------------------------------------------------------------
ShowState()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 
MoreButton(Window * pParent,WinBits nStyle)92 MoreButton::MoreButton( Window* pParent, WinBits nStyle ) :
93 	PushButton( WINDOW_MOREBUTTON )
94 {
95 	ImplInit( pParent, nStyle );
96 }
97 
98 // -----------------------------------------------------------------------
99 
MoreButton(Window * pParent,const ResId & rResId)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 
ImplLoadRes(const ResId & rResId)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 
~MoreButton()136 MoreButton::~MoreButton()
137 {
138 	if ( mpMBData->mpItemList )
139 		delete mpMBData->mpItemList;
140     delete mpMBData;
141 }
142 
143 // -----------------------------------------------------------------------
144 
Click()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 	// Je nach Status die Fenster updaten
157 	if ( mbState )
158 	{
159 		// Fenster anzeigen
160 		while ( pWindow )
161 		{
162 			pWindow->Show();
163 			pWindow = mpMBData->mpItemList->Next();
164 		}
165 
166 		// Dialogbox anpassen
167 		Point aPos( pParent->GetPosPixel() );
168 		Rectangle aDeskRect( pParent->ImplGetFrameWindow()->GetDesktopRectPixel() );
169 
170 		aSize.Height() += nDeltaPixel;
171 		if ( (aPos.Y()+aSize.Height()) > aDeskRect.Bottom() )
172 		{
173 			aPos.Y() = aDeskRect.Bottom()-aSize.Height();
174 
175 			if ( aPos.Y() < aDeskRect.Top() )
176 				aPos.Y() = aDeskRect.Top();
177 
178 			pParent->SetPosSizePixel( aPos, aSize );
179 		}
180 		else
181 			pParent->SetSizePixel( aSize );
182 	}
183 	else
184 	{
185 		// Dialogbox anpassen
186 		aSize.Height() -= nDeltaPixel;
187 		pParent->SetSizePixel( aSize );
188 
189 		// Fenster nicht mehr anzeigen
190 		while ( pWindow )
191 		{
192 			pWindow->Hide();
193 			pWindow = mpMBData->mpItemList->Next();
194 		}
195 	}
196 	PushButton::Click();
197 }
198 
199 // -----------------------------------------------------------------------
200 
AddWindow(Window * pWindow)201 void MoreButton::AddWindow( Window* pWindow )
202 {
203 	if ( !mpMBData->mpItemList )
204 		mpMBData->mpItemList = new ImplMoreWindowList( 1024, 16, 16 );
205 
206 	mpMBData->mpItemList->Insert( pWindow, LIST_APPEND );
207 
208 	if ( mbState )
209 		pWindow->Show();
210 	else
211 		pWindow->Hide();
212 }
213 
214 // -----------------------------------------------------------------------
215 
RemoveWindow(Window * pWindow)216 void MoreButton::RemoveWindow( Window* pWindow )
217 {
218 	if ( mpMBData->mpItemList )
219 		mpMBData->mpItemList->Remove( pWindow );
220 }
221 
222 // -----------------------------------------------------------------------
223 
SetText(const XubString & rText)224 void MoreButton::SetText( const XubString& rText )
225 {
226 	PushButton::SetText( rText );
227 }
228 
229 // -----------------------------------------------------------------------
230 
GetText() const231 XubString MoreButton::GetText() const
232 {
233 	return PushButton::GetText();
234 }
235 
236 // -----------------------------------------------------------------------
SetMoreText(const XubString & rText)237 void MoreButton::SetMoreText( const XubString& rText )
238 {
239 	if ( mpMBData )
240         mpMBData->maMoreText = rText;
241 
242     if ( !mbState )
243         SetText( rText );
244 }
245 
246 // -----------------------------------------------------------------------
GetMoreText() const247 XubString MoreButton::GetMoreText() const
248 {
249 	if ( mpMBData )
250         return mpMBData->maMoreText;
251     else
252         return PushButton::GetText();
253 }
254 
255 // -----------------------------------------------------------------------
SetLessText(const XubString & rText)256 void MoreButton::SetLessText( const XubString& rText )
257 {
258 	if ( mpMBData )
259         mpMBData->maLessText = rText;
260 
261     if ( mbState )
262         SetText( rText );
263 }
264 
265 // -----------------------------------------------------------------------
GetLessText() const266 XubString MoreButton::GetLessText() const
267 {
268 	if ( mpMBData )
269         return mpMBData->maLessText;
270     else
271         return PushButton::GetText();
272 }
273 
274