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