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