update dev300-m58
[ooovba.git] / vcl / source / control / morebtn.cxx
blobce815af637394a7a003059ace3bfa19e09bbb3bb
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: morebtn.cxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
33 #include <vcl/morebtn.hxx>
35 #ifndef _SV_RD_H
36 #include <tools/rc.h>
37 #endif
41 // =======================================================================
43 DECLARE_LIST( ImplMoreWindowList, Window* )
45 struct ImplMoreButtonData
47 ImplMoreWindowList *mpItemList;
48 XubString maMoreText;
49 XubString maLessText;
52 // =======================================================================
54 void MoreButton::ImplInit( Window* pParent, WinBits nStyle )
56 mpMBData = new ImplMoreButtonData;
57 mnDelta = 0;
58 meUnit = MAP_PIXEL;
59 mbState = FALSE;
61 mpMBData->mpItemList = NULL;
63 PushButton::ImplInit( pParent, nStyle );
65 mpMBData->maMoreText = Button::GetStandardText( BUTTON_MORE );
66 mpMBData->maLessText = Button::GetStandardText( BUTTON_LESS );
68 SetHelpText( Button::GetStandardHelpText( BUTTON_MORE ) );
70 ShowState();
72 SetSymbolAlign( SYMBOLALIGN_RIGHT );
73 ImplSetSmallSymbol( TRUE );
75 if ( ! ( nStyle & ( WB_RIGHT | WB_LEFT ) ) )
77 nStyle |= WB_CENTER;
78 SetStyle( nStyle );
82 // -----------------------------------------------------------------------
83 void MoreButton::ShowState()
85 if ( mbState )
87 SetSymbol( SYMBOL_PAGEUP );
88 SetText( mpMBData->maLessText );
90 else
92 SetSymbol( SYMBOL_PAGEDOWN );
93 SetText( mpMBData->maMoreText );
97 // -----------------------------------------------------------------------
99 MoreButton::MoreButton( Window* pParent, WinBits nStyle ) :
100 PushButton( WINDOW_MOREBUTTON )
102 ImplInit( pParent, nStyle );
105 // -----------------------------------------------------------------------
107 MoreButton::MoreButton( Window* pParent, const ResId& rResId ) :
108 PushButton( WINDOW_MOREBUTTON )
110 rResId.SetRT( RSC_MOREBUTTON );
111 WinBits nStyle = ImplInitRes( rResId );
112 ImplInit( pParent, nStyle );
113 ImplLoadRes( rResId );
115 if ( !(nStyle & WB_HIDE) )
116 Show();
119 // -----------------------------------------------------------------------
121 void MoreButton::ImplLoadRes( const ResId& rResId )
123 PushButton::ImplLoadRes( rResId );
125 ULONG nObjMask = ReadLongRes();
127 if ( nObjMask & RSC_MOREBUTTON_STATE )
129 // Nicht Methode rufen, da Dialog nicht umgeschaltet werden soll
130 mbState = (BOOL)ReadShortRes();
131 // SetText( GetText() );
132 ShowState();
134 if ( nObjMask & RSC_MOREBUTTON_MAPUNIT )
135 meUnit = (MapUnit)ReadLongRes();
136 if ( nObjMask & RSC_MOREBUTTON_DELTA )
137 // Groesse fuer Erweitern des Dialogs
138 mnDelta = ReadShortRes();
141 // -----------------------------------------------------------------------
143 MoreButton::~MoreButton()
145 if ( mpMBData->mpItemList )
146 delete mpMBData->mpItemList;
147 delete mpMBData;
150 // -----------------------------------------------------------------------
152 void MoreButton::Click()
154 Window* pParent = GetParent();
155 Size aSize( pParent->GetSizePixel() );
156 Window* pWindow = (mpMBData->mpItemList) ? mpMBData->mpItemList->First() : NULL;
157 long nDeltaPixel = LogicToPixel( Size( 0, mnDelta ), meUnit ).Height();
159 // Status aendern
160 mbState = !mbState;
161 ShowState();
163 // Hier den Click-Handler rufen, damit vorher die Controls initialisiert
164 // werden koennen
165 PushButton::Click();
167 // Je nach Status die Fenster updaten
168 if ( mbState )
170 // Fenster anzeigen
171 while ( pWindow )
173 pWindow->Show();
174 pWindow = mpMBData->mpItemList->Next();
177 // Dialogbox anpassen
178 Point aPos( pParent->GetPosPixel() );
179 Rectangle aDeskRect( pParent->ImplGetFrameWindow()->GetDesktopRectPixel() );
181 aSize.Height() += nDeltaPixel;
182 if ( (aPos.Y()+aSize.Height()) > aDeskRect.Bottom() )
184 aPos.Y() = aDeskRect.Bottom()-aSize.Height();
186 if ( aPos.Y() < aDeskRect.Top() )
187 aPos.Y() = aDeskRect.Top();
189 pParent->SetPosSizePixel( aPos, aSize );
191 else
192 pParent->SetSizePixel( aSize );
194 else
196 // Dialogbox anpassen
197 aSize.Height() -= nDeltaPixel;
198 pParent->SetSizePixel( aSize );
200 // Fenster nicht mehr anzeigen
201 while ( pWindow )
203 pWindow->Hide();
204 pWindow = mpMBData->mpItemList->Next();
209 // -----------------------------------------------------------------------
211 void MoreButton::AddWindow( Window* pWindow )
213 if ( !mpMBData->mpItemList )
214 mpMBData->mpItemList = new ImplMoreWindowList( 1024, 16, 16 );
216 mpMBData->mpItemList->Insert( pWindow, LIST_APPEND );
218 if ( mbState )
219 pWindow->Show();
220 else
221 pWindow->Hide();
224 // -----------------------------------------------------------------------
226 void MoreButton::RemoveWindow( Window* pWindow )
228 if ( mpMBData->mpItemList )
229 mpMBData->mpItemList->Remove( pWindow );
232 // -----------------------------------------------------------------------
234 void MoreButton::SetText( const XubString& rText )
236 PushButton::SetText( rText );
239 // -----------------------------------------------------------------------
241 XubString MoreButton::GetText() const
243 return PushButton::GetText();
246 // -----------------------------------------------------------------------
247 void MoreButton::SetMoreText( const XubString& rText )
249 if ( mpMBData )
250 mpMBData->maMoreText = rText;
252 if ( !mbState )
253 SetText( rText );
256 // -----------------------------------------------------------------------
257 XubString MoreButton::GetMoreText() const
259 if ( mpMBData )
260 return mpMBData->maMoreText;
261 else
262 return PushButton::GetText();
265 // -----------------------------------------------------------------------
266 void MoreButton::SetLessText( const XubString& rText )
268 if ( mpMBData )
269 mpMBData->maLessText = rText;
271 if ( mbState )
272 SetText( rText );
275 // -----------------------------------------------------------------------
276 XubString MoreButton::GetLessText() const
278 if ( mpMBData )
279 return mpMBData->maLessText;
280 else
281 return PushButton::GetText();