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_svx.hxx" 30 #include <string> // HACK: prevent conflict between STLPORT and Workshop headers 31 #include <tools/ref.hxx> 32 #include <tools/shl.hxx> 33 #include <svl/intitem.hxx> 34 #include <svl/eitem.hxx> 35 #include <svl/stritem.hxx> 36 #include <sfx2/dispatch.hxx> 37 #include <vcl/toolbox.hxx> 38 #include <vcl/fixed.hxx> 39 #include "fmitems.hxx" 40 #include "formtoolbars.hxx" 41 42 43 #include <vcl/sound.hxx> 44 #include <svx/dialmgr.hxx> 45 #ifndef _SVX_DIALOGS_HRC 46 #include <svx/dialogs.hrc> 47 #endif 48 #include "svx/tbxctl.hxx" 49 #include "svx/tbxdraw.hxx" 50 #include "tbxform.hxx" 51 #ifndef _SVX_FMRESIDS_HRC 52 #include "svx/fmresids.hrc" 53 #endif 54 #include "fmitems.hxx" 55 #ifndef _SVX_FMHELP_HRC 56 #include "fmhelp.hrc" 57 #endif 58 #include <sfx2/viewfrm.hxx> 59 #include <sfx2/viewsh.hxx> 60 #include <sfx2/imagemgr.hxx> 61 #include <com/sun/star/beans/XPropertySet.hpp> 62 63 using namespace ::com::sun::star::uno; 64 using namespace ::com::sun::star::beans; 65 using namespace ::com::sun::star::frame; 66 using ::com::sun::star::beans::XPropertySet; 67 68 69 //======================================================================== 70 // class SvxFmAbsRecWin 71 //======================================================================== 72 73 // ----------------------------------------------------------------------- 74 SvxFmAbsRecWin::SvxFmAbsRecWin( Window* _pParent, SfxToolBoxControl* _pController ) 75 :NumericField( _pParent, WB_BORDER ) 76 ,m_pController(_pController) 77 { 78 SetMin(1); 79 SetFirst(1); 80 SetSpinSize(1); 81 SetSizePixel( Size(70,19) ); 82 83 SetDecimalDigits(0); 84 SetStrictFormat(sal_True); 85 } 86 87 // ----------------------------------------------------------------------- 88 SvxFmAbsRecWin::~SvxFmAbsRecWin() 89 { 90 } 91 92 // ----------------------------------------------------------------------- 93 void SvxFmAbsRecWin::FirePosition( sal_Bool _bForce ) 94 { 95 if ( _bForce || ( GetText() != GetSavedValue() ) ) 96 { 97 sal_Int64 nRecord = GetValue(); 98 if (nRecord < GetMin() || nRecord > GetMax()) 99 { 100 Sound::Beep(); 101 return; 102 } 103 104 SfxInt32Item aPositionParam( FN_PARAM_1, static_cast<sal_Int32>(nRecord) ); 105 106 Any a; 107 Sequence< PropertyValue > aArgs( 1 ); 108 aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Position" )); 109 aPositionParam.QueryValue( a ); 110 aArgs[0].Value = a; 111 m_pController->Dispatch( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:AbsoluteRecord" )), 112 aArgs ); 113 m_pController->updateStatus(); 114 115 SaveValue(); 116 } 117 } 118 119 // ----------------------------------------------------------------------- 120 void SvxFmAbsRecWin::LoseFocus() 121 { 122 FirePosition( sal_False ); 123 } 124 125 // ----------------------------------------------------------------------- 126 void SvxFmAbsRecWin::KeyInput( const KeyEvent& rKeyEvent ) 127 { 128 if( rKeyEvent.GetKeyCode() == KEY_RETURN && GetText().Len() ) 129 FirePosition( sal_True ); 130 else 131 NumericField::KeyInput( rKeyEvent ); 132 } 133 134 //======================================================================== 135 // class SvxFmTbxCtlConfig 136 //======================================================================== 137 138 struct MapSlotToCmd 139 { 140 sal_uInt16 nSlotId; 141 const char* pCommand; 142 }; 143 144 static MapSlotToCmd SlotToCommands[] = 145 { 146 { SID_FM_PUSHBUTTON, ".uno:Pushbutton" }, 147 { SID_FM_RADIOBUTTON, ".uno:RadioButton" }, 148 { SID_FM_CHECKBOX, ".uno:CheckBox" }, 149 { SID_FM_FIXEDTEXT, ".uno:Label" }, 150 { SID_FM_GROUPBOX, ".uno:GroupBox" }, 151 { SID_FM_LISTBOX, ".uno:ListBox" }, 152 { SID_FM_COMBOBOX, ".uno:ComboBox" }, 153 { SID_FM_EDIT, ".uno:Edit" }, 154 { SID_FM_DBGRID, ".uno:Grid" }, 155 { SID_FM_IMAGEBUTTON, ".uno:Imagebutton" }, 156 { SID_FM_IMAGECONTROL, ".uno:ImageControl" }, 157 { SID_FM_FILECONTROL, ".uno:FileControl" }, 158 { SID_FM_DATEFIELD, ".uno:DateField" }, 159 { SID_FM_TIMEFIELD, ".uno:TimeField" }, 160 { SID_FM_NUMERICFIELD, ".uno:NumericField" }, 161 { SID_FM_CURRENCYFIELD, ".uno:CurrencyField" }, 162 { SID_FM_PATTERNFIELD, ".uno:PatternField" }, 163 { SID_FM_DESIGN_MODE, ".uno:SwitchControlDesignMode" }, 164 { SID_FM_FORMATTEDFIELD, ".uno:FormattedField" }, 165 { SID_FM_SCROLLBAR, ".uno:ScrollBar" }, 166 { SID_FM_SPINBUTTON, ".uno:SpinButton" }, 167 { 0, "" } 168 }; 169 170 SFX_IMPL_TOOLBOX_CONTROL( SvxFmTbxCtlConfig, SfxUInt16Item ); 171 172 //----------------------------------------------------------------------- 173 SvxFmTbxCtlConfig::SvxFmTbxCtlConfig( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) 174 : SfxToolBoxControl( nSlotId, nId, rTbx ) 175 ,nLastSlot( 0 ) 176 { 177 rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) ); 178 } 179 180 //----------------------------------------------------------------------- 181 void SvxFmTbxCtlConfig::StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState ) 182 { 183 if (nSID == SID_FM_CONFIG) 184 { 185 sal_uInt16 nSlot = 0; 186 if (eState >= SFX_ITEM_AVAILABLE) 187 nSlot = ((SfxUInt16Item*)pState)->GetValue(); 188 189 switch( nSlot ) 190 { 191 case SID_FM_PUSHBUTTON: 192 case SID_FM_RADIOBUTTON: 193 case SID_FM_CHECKBOX: 194 case SID_FM_FIXEDTEXT: 195 case SID_FM_GROUPBOX: 196 case SID_FM_LISTBOX: 197 case SID_FM_COMBOBOX: 198 case SID_FM_NAVIGATIONBAR: 199 case SID_FM_EDIT: 200 case SID_FM_DBGRID: 201 case SID_FM_IMAGEBUTTON: 202 case SID_FM_IMAGECONTROL: 203 case SID_FM_FILECONTROL: 204 case SID_FM_DATEFIELD: 205 case SID_FM_TIMEFIELD: 206 case SID_FM_NUMERICFIELD: 207 case SID_FM_CURRENCYFIELD: 208 case SID_FM_PATTERNFIELD: 209 case SID_FM_DESIGN_MODE: 210 case SID_FM_FORMATTEDFIELD: 211 case SID_FM_SCROLLBAR: 212 case SID_FM_SPINBUTTON: 213 { // set a new image, matching to this slot 214 rtl::OUString aSlotURL( RTL_CONSTASCII_USTRINGPARAM( "slot:" )); 215 aSlotURL += rtl::OUString::valueOf( sal_Int32( nSlot )); 216 Image aImage = GetImage( m_xFrame, 217 aSlotURL, 218 hasBigImages(), 219 GetToolBox().GetSettings().GetStyleSettings().GetHighContrastMode() ); 220 221 GetToolBox().SetItemImage( GetId(), aImage ); 222 nLastSlot = nSlot; 223 } 224 break; 225 } 226 } 227 SfxToolBoxControl::StateChanged( nSID, eState,pState ); 228 } 229 230 //----------------------------------------------------------------------- 231 SfxPopupWindowType SvxFmTbxCtlConfig::GetPopupWindowType() const 232 { 233 return( nLastSlot == 0 ? SFX_POPUPWINDOW_ONCLICK : SFX_POPUPWINDOW_ONTIMEOUT ); 234 } 235 236 //----------------------------------------------------------------------- 237 SfxPopupWindow* SvxFmTbxCtlConfig::CreatePopupWindow() 238 { 239 if ( GetSlotId() == SID_FM_CONFIG ) 240 { 241 ::svxform::FormToolboxes aToolboxes( m_xFrame ); 242 createAndPositionSubToolBar( aToolboxes.getToolboxResourceName( SID_FM_CONFIG ) ); 243 } 244 return NULL; 245 } 246 247 //----------------------------------------------------------------------- 248 void SvxFmTbxCtlConfig::Select( sal_uInt16 /*nModifier*/ ) 249 { 250 ////////////////////////////////////////////////////////////////////// 251 // Click auf den Button SID_FM_CONFIG in der ObjectBar 252 if ( nLastSlot ) 253 { 254 sal_uInt16 n = 0; 255 while( SlotToCommands[n].nSlotId > 0 ) 256 { 257 if ( SlotToCommands[n].nSlotId == nLastSlot ) 258 break; 259 n++; 260 } 261 262 if ( SlotToCommands[n].nSlotId > 0 ) 263 { 264 Sequence< PropertyValue > aArgs; 265 Dispatch( rtl::OUString::createFromAscii( SlotToCommands[n].pCommand ), 266 aArgs ); 267 } 268 } 269 } 270 271 272 //======================================================================== 273 // class SvxFmTbxCtlAbsRec 274 //======================================================================== 275 276 SFX_IMPL_TOOLBOX_CONTROL( SvxFmTbxCtlAbsRec, SfxInt32Item ); 277 DBG_NAME(SvxFmTbxCtlAbsRec); 278 //----------------------------------------------------------------------- 279 SvxFmTbxCtlAbsRec::SvxFmTbxCtlAbsRec( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) 280 :SfxToolBoxControl( nSlotId, nId, rTbx ) 281 { 282 DBG_CTOR(SvxFmTbxCtlAbsRec,NULL); 283 } 284 285 //----------------------------------------------------------------------- 286 SvxFmTbxCtlAbsRec::~SvxFmTbxCtlAbsRec() 287 { 288 DBG_DTOR(SvxFmTbxCtlAbsRec,NULL); 289 } 290 291 //----------------------------------------------------------------------- 292 void SvxFmTbxCtlAbsRec::StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState ) 293 { 294 sal_uInt16 nId = GetId(); 295 ToolBox* pToolBox = &GetToolBox(); 296 SvxFmAbsRecWin* pWin = (SvxFmAbsRecWin*)( pToolBox->GetItemWindow(nId) ); 297 298 DBG_ASSERT( pWin, "Control not found!" ); 299 300 if (pState) 301 { 302 const SfxInt32Item* pItem = PTR_CAST( SfxInt32Item, pState ); 303 DBG_ASSERT( pItem, "SvxFmTbxCtlAbsRec::StateChanged: invalid item!" ); 304 pWin->SetValue( pItem ? pItem->GetValue() : -1 ); 305 } 306 307 sal_Bool bEnable = SFX_ITEM_DISABLED != eState && pState; 308 if (!bEnable) 309 pWin->SetText(String()); 310 311 ////////////////////////////////////////////////////////////////////// 312 // Enablen/disablen des Fensters 313 pToolBox->EnableItem(nId, bEnable); 314 SfxToolBoxControl::StateChanged( nSID, eState,pState ); 315 } 316 317 //----------------------------------------------------------------------- 318 Window* SvxFmTbxCtlAbsRec::CreateItemWindow( Window* pParent ) 319 { 320 SvxFmAbsRecWin* pWin = new SvxFmAbsRecWin( pParent, this ); 321 pWin->SetUniqueId( UID_ABSOLUTE_RECORD_WINDOW ); 322 return pWin; 323 } 324 325 326 //======================================================================== 327 // SvxFmTbxCtlRecText 328 //======================================================================== 329 330 SFX_IMPL_TOOLBOX_CONTROL( SvxFmTbxCtlRecText, SfxBoolItem ); 331 DBG_NAME(SvxFmTbxCtlRecText); 332 //----------------------------------------------------------------------- 333 SvxFmTbxCtlRecText::SvxFmTbxCtlRecText( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) 334 :SfxToolBoxControl( nSlotId, nId, rTbx ) 335 { 336 DBG_CTOR(SvxFmTbxCtlRecText,NULL); 337 } 338 339 //----------------------------------------------------------------------- 340 SvxFmTbxCtlRecText::~SvxFmTbxCtlRecText() 341 { 342 DBG_DTOR(SvxFmTbxCtlRecText,NULL); 343 } 344 345 //----------------------------------------------------------------------- 346 Window* SvxFmTbxCtlRecText::CreateItemWindow( Window* pParent ) 347 { 348 XubString aText( SVX_RES(RID_STR_REC_TEXT) ); 349 FixedText* pFixedText = new FixedText( pParent ); 350 Size aSize( pFixedText->GetTextWidth( aText ), pFixedText->GetTextHeight( ) ); 351 pFixedText->SetText( aText ); 352 aSize.Width() += 6; 353 pFixedText->SetSizePixel( aSize ); 354 pFixedText->SetBackground(Wallpaper(Color(COL_TRANSPARENT))); 355 356 return pFixedText; 357 } 358 359 360 //======================================================================== 361 // SvxFmTbxCtlRecFromText 362 //======================================================================== 363 364 SFX_IMPL_TOOLBOX_CONTROL( SvxFmTbxCtlRecFromText, SfxBoolItem ); 365 DBG_NAME(SvxFmTbxCtlRecFromText); 366 //----------------------------------------------------------------------- 367 SvxFmTbxCtlRecFromText::SvxFmTbxCtlRecFromText( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) 368 :SfxToolBoxControl( nSlotId, nId, rTbx ) 369 { 370 DBG_CTOR(SvxFmTbxCtlRecFromText,NULL); 371 } 372 373 //----------------------------------------------------------------------- 374 SvxFmTbxCtlRecFromText::~SvxFmTbxCtlRecFromText() 375 { 376 DBG_DTOR(SvxFmTbxCtlRecFromText,NULL); 377 } 378 379 //----------------------------------------------------------------------- 380 Window* SvxFmTbxCtlRecFromText::CreateItemWindow( Window* pParent ) 381 { 382 XubString aText( SVX_RES(RID_STR_REC_FROM_TEXT) ); 383 FixedText* pFixedText = new FixedText( pParent, WB_CENTER ); 384 Size aSize( pFixedText->GetTextWidth( aText ), pFixedText->GetTextHeight( ) ); 385 aSize.Width() += 12; 386 pFixedText->SetText( aText ); 387 pFixedText->SetSizePixel( aSize ); 388 pFixedText->SetBackground(Wallpaper(Color(COL_TRANSPARENT))); 389 return pFixedText; 390 } 391 392 393 //======================================================================== 394 // SvxFmTbxCtlRecTotal 395 //======================================================================== 396 DBG_NAME(SvxFmTbxCtlRecTotal); 397 SFX_IMPL_TOOLBOX_CONTROL( SvxFmTbxCtlRecTotal, SfxStringItem ); 398 399 //----------------------------------------------------------------------- 400 SvxFmTbxCtlRecTotal::SvxFmTbxCtlRecTotal( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) 401 :SfxToolBoxControl( nSlotId, nId, rTbx ) 402 ,pFixedText( NULL ) 403 { 404 DBG_CTOR(SvxFmTbxCtlRecTotal,NULL); 405 } 406 407 //----------------------------------------------------------------------- 408 SvxFmTbxCtlRecTotal::~SvxFmTbxCtlRecTotal() 409 { 410 DBG_DTOR(SvxFmTbxCtlRecTotal,NULL); 411 } 412 413 //----------------------------------------------------------------------- 414 Window* SvxFmTbxCtlRecTotal::CreateItemWindow( Window* pParent ) 415 { 416 pFixedText = new FixedText( pParent ); 417 String aSample( "123456", sizeof( "123456" ) - 1 ); 418 Size aSize( pFixedText->GetTextWidth( aSample ), pFixedText->GetTextHeight( ) ); 419 aSize.Width() += 12; 420 pFixedText->SetSizePixel( aSize ); 421 pFixedText->SetBackground(); 422 pFixedText->SetPaintTransparent(sal_True); 423 return pFixedText; 424 } 425 426 //----------------------------------------------------------------------- 427 void SvxFmTbxCtlRecTotal::StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState ) 428 { 429 ////////////////////////////////////////////////////////////////////// 430 // Setzen des FixedTextes 431 if (GetSlotId() != SID_FM_RECORD_TOTAL) 432 return; 433 434 XubString aText; 435 if (pState) 436 aText = ((SfxStringItem*)pState)->GetValue(); 437 else 438 aText = '?'; 439 440 pFixedText->SetText( aText ); 441 pFixedText->Update(); 442 pFixedText->Flush(); 443 444 SfxToolBoxControl::StateChanged( nSID, eState,pState ); 445 } 446 447 //======================================================================== 448 // SvxFmTbxNextRec 449 //======================================================================== 450 SFX_IMPL_TOOLBOX_CONTROL( SvxFmTbxNextRec, SfxBoolItem ); 451 452 //----------------------------------------------------------------------- 453 SvxFmTbxNextRec::SvxFmTbxNextRec( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) 454 :SfxToolBoxControl( nSlotId, nId, rTbx ) 455 { 456 rTbx.SetItemBits(nId, rTbx.GetItemBits(nId) | TIB_REPEAT); 457 458 AllSettings aSettings = rTbx.GetSettings(); 459 MouseSettings aMouseSettings = aSettings.GetMouseSettings(); 460 aMouseSettings.SetButtonRepeat(aMouseSettings.GetButtonRepeat() / 4); 461 aSettings.SetMouseSettings(aMouseSettings); 462 rTbx.SetSettings(aSettings, sal_True); 463 } 464 465 //======================================================================== 466 // SvxFmTbxPrevRec 467 //======================================================================== 468 SFX_IMPL_TOOLBOX_CONTROL( SvxFmTbxPrevRec, SfxBoolItem ); 469 470 //----------------------------------------------------------------------- 471 SvxFmTbxPrevRec::SvxFmTbxPrevRec( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) 472 :SfxToolBoxControl( nSlotId, nId, rTbx ) 473 { 474 rTbx.SetItemBits(nId, rTbx.GetItemBits(nId) | TIB_REPEAT); 475 } 476 477 478