1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_vcl.hxx" 30 #include <vcl/morebtn.hxx> 31 32 #ifndef _SV_RD_H 33 #include <tools/rc.h> 34 #endif 35 36 37 38 // ======================================================================= 39 40 DECLARE_LIST( ImplMoreWindowList, Window* ) 41 42 struct ImplMoreButtonData 43 { 44 ImplMoreWindowList *mpItemList; 45 XubString maMoreText; 46 XubString maLessText; 47 }; 48 49 // ======================================================================= 50 51 void MoreButton::ImplInit( Window* pParent, WinBits nStyle ) 52 { 53 mpMBData = new ImplMoreButtonData; 54 mnDelta = 0; 55 meUnit = MAP_PIXEL; 56 mbState = sal_False; 57 58 mpMBData->mpItemList = NULL; 59 60 PushButton::ImplInit( pParent, nStyle ); 61 62 mpMBData->maMoreText = Button::GetStandardText( BUTTON_MORE ); 63 mpMBData->maLessText = Button::GetStandardText( BUTTON_LESS ); 64 65 SetHelpText( Button::GetStandardHelpText( BUTTON_MORE ) ); 66 67 ShowState(); 68 69 SetSymbolAlign( SYMBOLALIGN_RIGHT ); 70 ImplSetSmallSymbol( sal_True ); 71 72 if ( ! ( nStyle & ( WB_RIGHT | WB_LEFT ) ) ) 73 { 74 nStyle |= WB_CENTER; 75 SetStyle( nStyle ); 76 } 77 } 78 79 // ----------------------------------------------------------------------- 80 void MoreButton::ShowState() 81 { 82 if ( mbState ) 83 { 84 SetSymbol( SYMBOL_PAGEUP ); 85 SetText( mpMBData->maLessText ); 86 } 87 else 88 { 89 SetSymbol( SYMBOL_PAGEDOWN ); 90 SetText( mpMBData->maMoreText ); 91 } 92 } 93 94 // ----------------------------------------------------------------------- 95 96 MoreButton::MoreButton( Window* pParent, WinBits nStyle ) : 97 PushButton( WINDOW_MOREBUTTON ) 98 { 99 ImplInit( pParent, nStyle ); 100 } 101 102 // ----------------------------------------------------------------------- 103 104 MoreButton::MoreButton( Window* pParent, const ResId& rResId ) : 105 PushButton( WINDOW_MOREBUTTON ) 106 { 107 rResId.SetRT( RSC_MOREBUTTON ); 108 WinBits nStyle = ImplInitRes( rResId ); 109 ImplInit( pParent, nStyle ); 110 ImplLoadRes( rResId ); 111 112 if ( !(nStyle & WB_HIDE) ) 113 Show(); 114 } 115 116 // ----------------------------------------------------------------------- 117 118 void MoreButton::ImplLoadRes( const ResId& rResId ) 119 { 120 PushButton::ImplLoadRes( rResId ); 121 122 sal_uLong nObjMask = ReadLongRes(); 123 124 if ( nObjMask & RSC_MOREBUTTON_STATE ) 125 { 126 // Nicht Methode rufen, da Dialog nicht umgeschaltet werden soll 127 mbState = (sal_Bool)ReadShortRes(); 128 // SetText( GetText() ); 129 ShowState(); 130 } 131 if ( nObjMask & RSC_MOREBUTTON_MAPUNIT ) 132 meUnit = (MapUnit)ReadLongRes(); 133 if ( nObjMask & RSC_MOREBUTTON_DELTA ) 134 // Groesse fuer Erweitern des Dialogs 135 mnDelta = ReadShortRes(); 136 } 137 138 // ----------------------------------------------------------------------- 139 140 MoreButton::~MoreButton() 141 { 142 if ( mpMBData->mpItemList ) 143 delete mpMBData->mpItemList; 144 delete mpMBData; 145 } 146 147 // ----------------------------------------------------------------------- 148 149 void MoreButton::Click() 150 { 151 Window* pParent = GetParent(); 152 Size aSize( pParent->GetSizePixel() ); 153 Window* pWindow = (mpMBData->mpItemList) ? mpMBData->mpItemList->First() : NULL; 154 long nDeltaPixel = LogicToPixel( Size( 0, mnDelta ), meUnit ).Height(); 155 156 // Status aendern 157 mbState = !mbState; 158 ShowState(); 159 160 // Hier den Click-Handler rufen, damit vorher die Controls initialisiert 161 // werden koennen 162 PushButton::Click(); 163 164 // Je nach Status die Fenster updaten 165 if ( mbState ) 166 { 167 // Fenster anzeigen 168 while ( pWindow ) 169 { 170 pWindow->Show(); 171 pWindow = mpMBData->mpItemList->Next(); 172 } 173 174 // Dialogbox anpassen 175 Point aPos( pParent->GetPosPixel() ); 176 Rectangle aDeskRect( pParent->ImplGetFrameWindow()->GetDesktopRectPixel() ); 177 178 aSize.Height() += nDeltaPixel; 179 if ( (aPos.Y()+aSize.Height()) > aDeskRect.Bottom() ) 180 { 181 aPos.Y() = aDeskRect.Bottom()-aSize.Height(); 182 183 if ( aPos.Y() < aDeskRect.Top() ) 184 aPos.Y() = aDeskRect.Top(); 185 186 pParent->SetPosSizePixel( aPos, aSize ); 187 } 188 else 189 pParent->SetSizePixel( aSize ); 190 } 191 else 192 { 193 // Dialogbox anpassen 194 aSize.Height() -= nDeltaPixel; 195 pParent->SetSizePixel( aSize ); 196 197 // Fenster nicht mehr anzeigen 198 while ( pWindow ) 199 { 200 pWindow->Hide(); 201 pWindow = mpMBData->mpItemList->Next(); 202 } 203 } 204 } 205 206 // ----------------------------------------------------------------------- 207 208 void MoreButton::AddWindow( Window* pWindow ) 209 { 210 if ( !mpMBData->mpItemList ) 211 mpMBData->mpItemList = new ImplMoreWindowList( 1024, 16, 16 ); 212 213 mpMBData->mpItemList->Insert( pWindow, LIST_APPEND ); 214 215 if ( mbState ) 216 pWindow->Show(); 217 else 218 pWindow->Hide(); 219 } 220 221 // ----------------------------------------------------------------------- 222 223 void MoreButton::RemoveWindow( Window* pWindow ) 224 { 225 if ( mpMBData->mpItemList ) 226 mpMBData->mpItemList->Remove( pWindow ); 227 } 228 229 // ----------------------------------------------------------------------- 230 231 void MoreButton::SetText( const XubString& rText ) 232 { 233 PushButton::SetText( rText ); 234 } 235 236 // ----------------------------------------------------------------------- 237 238 XubString MoreButton::GetText() const 239 { 240 return PushButton::GetText(); 241 } 242 243 // ----------------------------------------------------------------------- 244 void MoreButton::SetMoreText( const XubString& rText ) 245 { 246 if ( mpMBData ) 247 mpMBData->maMoreText = rText; 248 249 if ( !mbState ) 250 SetText( rText ); 251 } 252 253 // ----------------------------------------------------------------------- 254 XubString MoreButton::GetMoreText() const 255 { 256 if ( mpMBData ) 257 return mpMBData->maMoreText; 258 else 259 return PushButton::GetText(); 260 } 261 262 // ----------------------------------------------------------------------- 263 void MoreButton::SetLessText( const XubString& rText ) 264 { 265 if ( mpMBData ) 266 mpMBData->maLessText = rText; 267 268 if ( mbState ) 269 SetText( rText ); 270 } 271 272 // ----------------------------------------------------------------------- 273 XubString MoreButton::GetLessText() const 274 { 275 if ( mpMBData ) 276 return mpMBData->maLessText; 277 else 278 return PushButton::GetText(); 279 } 280 281