1f6e50924SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3f6e50924SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4f6e50924SAndrew Rist * or more contributor license agreements. See the NOTICE file 5f6e50924SAndrew Rist * distributed with this work for additional information 6f6e50924SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7f6e50924SAndrew Rist * to you under the Apache License, Version 2.0 (the 8f6e50924SAndrew Rist * "License"); you may not use this file except in compliance 9f6e50924SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11f6e50924SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13f6e50924SAndrew Rist * Unless required by applicable law or agreed to in writing, 14f6e50924SAndrew Rist * software distributed under the License is distributed on an 15f6e50924SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16f6e50924SAndrew Rist * KIND, either express or implied. See the License for the 17f6e50924SAndrew Rist * specific language governing permissions and limitations 18f6e50924SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20f6e50924SAndrew Rist *************************************************************/ 21f6e50924SAndrew Rist 22f6e50924SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_svx.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <svx/dialogs.hrc> 28cdf0e10cSrcweir 29cdf0e10cSrcweir 30cdf0e10cSrcweir #include <tools/list.hxx> 31cdf0e10cSrcweir #include <sfx2/viewsh.hxx> 32cdf0e10cSrcweir #include <sfx2/objsh.hxx> 33cdf0e10cSrcweir #include <sfx2/dispatch.hxx> 34cdf0e10cSrcweir #include <vcl/image.hxx> 35cdf0e10cSrcweir 36cdf0e10cSrcweir #include <svx/colrctrl.hxx> 37cdf0e10cSrcweir 38cdf0e10cSrcweir #include <svx/svdview.hxx> 39cdf0e10cSrcweir #include "svx/drawitem.hxx" 40cdf0e10cSrcweir #include <editeng/colritem.hxx> 41cdf0e10cSrcweir #include "svx/xattr.hxx" 42cdf0e10cSrcweir #include <svx/xtable.hxx> 43cdf0e10cSrcweir #include <svx/dialmgr.hxx> 44cdf0e10cSrcweir #include "svx/xexch.hxx" 45cdf0e10cSrcweir #include <vcl/svapp.hxx> 46cdf0e10cSrcweir 47cdf0e10cSrcweir // ------------------------ 48cdf0e10cSrcweir // - SvxColorValueSetData - 49cdf0e10cSrcweir // ------------------------ 50cdf0e10cSrcweir 51cdf0e10cSrcweir class SvxColorValueSetData : public TransferableHelper 52cdf0e10cSrcweir { 53cdf0e10cSrcweir private: 54cdf0e10cSrcweir 55cdf0e10cSrcweir XFillExchangeData maData; 56cdf0e10cSrcweir 57cdf0e10cSrcweir protected: 58cdf0e10cSrcweir 59cdf0e10cSrcweir virtual void AddSupportedFormats(); 60cdf0e10cSrcweir virtual sal_Bool GetData( const ::com::sun::star::datatransfer::DataFlavor& rFlavor ); 61cdf0e10cSrcweir virtual sal_Bool WriteObject( SotStorageStreamRef& rxOStm, void* pUserObject, sal_uInt32 nUserObjectId, const ::com::sun::star::datatransfer::DataFlavor& rFlavor ); 62cdf0e10cSrcweir 63cdf0e10cSrcweir public: 64cdf0e10cSrcweir 65cdf0e10cSrcweir SvxColorValueSetData( const XFillAttrSetItem& rSetItem ) : 66cdf0e10cSrcweir maData( rSetItem ) {} 67cdf0e10cSrcweir }; 68cdf0e10cSrcweir 69cdf0e10cSrcweir // ----------------------------------------------------------------------------- 70cdf0e10cSrcweir 71cdf0e10cSrcweir void SvxColorValueSetData::AddSupportedFormats() 72cdf0e10cSrcweir { 73cdf0e10cSrcweir AddFormat( SOT_FORMATSTR_ID_XFA ); 74cdf0e10cSrcweir } 75cdf0e10cSrcweir 76cdf0e10cSrcweir // ----------------------------------------------------------------------------- 77cdf0e10cSrcweir 78cdf0e10cSrcweir sal_Bool SvxColorValueSetData::GetData( const ::com::sun::star::datatransfer::DataFlavor& rFlavor ) 79cdf0e10cSrcweir { 80cdf0e10cSrcweir sal_Bool bRet = sal_False; 81cdf0e10cSrcweir 82cdf0e10cSrcweir if( SotExchange::GetFormat( rFlavor ) == SOT_FORMATSTR_ID_XFA ) 83cdf0e10cSrcweir { 84cdf0e10cSrcweir SetObject( &maData, 0, rFlavor ); 85cdf0e10cSrcweir bRet = sal_True; 86cdf0e10cSrcweir } 87cdf0e10cSrcweir 88cdf0e10cSrcweir return bRet; 89cdf0e10cSrcweir } 90cdf0e10cSrcweir 91cdf0e10cSrcweir // ----------------------------------------------------------------------------- 92cdf0e10cSrcweir 93cdf0e10cSrcweir sal_Bool SvxColorValueSetData::WriteObject( SotStorageStreamRef& rxOStm, void*, sal_uInt32 , const ::com::sun::star::datatransfer::DataFlavor& ) 94cdf0e10cSrcweir { 95cdf0e10cSrcweir *rxOStm << maData; 96cdf0e10cSrcweir return( rxOStm->GetError() == ERRCODE_NONE ); 97cdf0e10cSrcweir } 98cdf0e10cSrcweir 99cdf0e10cSrcweir /************************************************************************* 100cdf0e10cSrcweir |* 10128bcfa49SArmin Le Grand |* SvxColorValueSet_docking: Ctor 102cdf0e10cSrcweir |* 103cdf0e10cSrcweir \************************************************************************/ 104cdf0e10cSrcweir 10528bcfa49SArmin Le Grand SvxColorValueSet_docking::SvxColorValueSet_docking( Window* _pParent, WinBits nWinStyle ) : 10628bcfa49SArmin Le Grand SvxColorValueSet( _pParent, nWinStyle ), 107cdf0e10cSrcweir DragSourceHelper( this ), 10828bcfa49SArmin Le Grand mbLeftButton(true) 109cdf0e10cSrcweir { 110cdf0e10cSrcweir SetAccessibleName(String( SVX_RES( STR_COLORTABLE ) ) ); 111cdf0e10cSrcweir } 112cdf0e10cSrcweir 113cdf0e10cSrcweir /************************************************************************* 114cdf0e10cSrcweir |* 11528bcfa49SArmin Le Grand |* SvxColorValueSet_docking: Ctor 116cdf0e10cSrcweir |* 117cdf0e10cSrcweir \************************************************************************/ 118cdf0e10cSrcweir 11928bcfa49SArmin Le Grand SvxColorValueSet_docking::SvxColorValueSet_docking( Window* _pParent, const ResId& rResId ) : 12028bcfa49SArmin Le Grand SvxColorValueSet( _pParent, rResId ), 121cdf0e10cSrcweir DragSourceHelper( this ), 12228bcfa49SArmin Le Grand mbLeftButton(true) 123cdf0e10cSrcweir { 124cdf0e10cSrcweir SetAccessibleName(String( SVX_RES( STR_COLORTABLE ) )); 125cdf0e10cSrcweir } 126cdf0e10cSrcweir 127cdf0e10cSrcweir /************************************************************************* 128cdf0e10cSrcweir |* 12928bcfa49SArmin Le Grand |* SvxColorValueSet_docking: MouseButtonDown 130cdf0e10cSrcweir |* 131cdf0e10cSrcweir \************************************************************************/ 132cdf0e10cSrcweir 13328bcfa49SArmin Le Grand void SvxColorValueSet_docking::MouseButtonDown( const MouseEvent& rMEvt ) 134cdf0e10cSrcweir { 135cdf0e10cSrcweir // Fuer Mac noch anders handlen ! 136cdf0e10cSrcweir if( rMEvt.IsLeft() ) 137cdf0e10cSrcweir { 13828bcfa49SArmin Le Grand mbLeftButton = true; 13928bcfa49SArmin Le Grand SvxColorValueSet::MouseButtonDown( rMEvt ); 140cdf0e10cSrcweir } 141cdf0e10cSrcweir else 142cdf0e10cSrcweir { 14328bcfa49SArmin Le Grand mbLeftButton = false; 144cdf0e10cSrcweir MouseEvent aMEvt( rMEvt.GetPosPixel(), 145cdf0e10cSrcweir rMEvt.GetClicks(), 146cdf0e10cSrcweir rMEvt.GetMode(), 147cdf0e10cSrcweir MOUSE_LEFT, 148cdf0e10cSrcweir rMEvt.GetModifier() ); 14928bcfa49SArmin Le Grand SvxColorValueSet::MouseButtonDown( aMEvt ); 150cdf0e10cSrcweir } 151cdf0e10cSrcweir 152cdf0e10cSrcweir aDragPosPixel = GetPointerPosPixel(); 153cdf0e10cSrcweir } 154cdf0e10cSrcweir 155cdf0e10cSrcweir /************************************************************************* 156cdf0e10cSrcweir |* 15728bcfa49SArmin Le Grand |* SvxColorValueSet_docking: MouseButtonUp 158cdf0e10cSrcweir |* 159cdf0e10cSrcweir \************************************************************************/ 160cdf0e10cSrcweir 16128bcfa49SArmin Le Grand void SvxColorValueSet_docking::MouseButtonUp( const MouseEvent& rMEvt ) 162cdf0e10cSrcweir { 163cdf0e10cSrcweir // Fuer Mac noch anders handlen ! 164cdf0e10cSrcweir if( rMEvt.IsLeft() ) 165cdf0e10cSrcweir { 16628bcfa49SArmin Le Grand mbLeftButton = true; 16728bcfa49SArmin Le Grand SvxColorValueSet::MouseButtonUp( rMEvt ); 168cdf0e10cSrcweir } 169cdf0e10cSrcweir else 170cdf0e10cSrcweir { 17128bcfa49SArmin Le Grand mbLeftButton = false; 172cdf0e10cSrcweir MouseEvent aMEvt( rMEvt.GetPosPixel(), 173cdf0e10cSrcweir rMEvt.GetClicks(), 174cdf0e10cSrcweir rMEvt.GetMode(), 175cdf0e10cSrcweir MOUSE_LEFT, 176cdf0e10cSrcweir rMEvt.GetModifier() ); 17728bcfa49SArmin Le Grand SvxColorValueSet::MouseButtonUp( aMEvt ); 178cdf0e10cSrcweir } 179cdf0e10cSrcweir SetNoSelection(); 180cdf0e10cSrcweir } 181cdf0e10cSrcweir 182cdf0e10cSrcweir /************************************************************************* 183cdf0e10cSrcweir |* 184cdf0e10cSrcweir |* Command-Event 185cdf0e10cSrcweir |* 186cdf0e10cSrcweir \************************************************************************/ 187cdf0e10cSrcweir 18828bcfa49SArmin Le Grand void SvxColorValueSet_docking::Command(const CommandEvent& rCEvt) 189cdf0e10cSrcweir { 190cdf0e10cSrcweir // Basisklasse 19128bcfa49SArmin Le Grand SvxColorValueSet::Command(rCEvt); 192cdf0e10cSrcweir } 193cdf0e10cSrcweir 194cdf0e10cSrcweir /************************************************************************* 195cdf0e10cSrcweir |* 196cdf0e10cSrcweir |* StartDrag 197cdf0e10cSrcweir |* 198cdf0e10cSrcweir \************************************************************************/ 199cdf0e10cSrcweir 20028bcfa49SArmin Le Grand void SvxColorValueSet_docking::StartDrag( sal_Int8 , const Point& ) 201cdf0e10cSrcweir { 20228bcfa49SArmin Le Grand Application::PostUserEvent(STATIC_LINK(this, SvxColorValueSet_docking, ExecDragHdl)); 203cdf0e10cSrcweir } 204cdf0e10cSrcweir 205cdf0e10cSrcweir /************************************************************************* 206cdf0e10cSrcweir |* 207cdf0e10cSrcweir |* Drag&Drop asynchron ausfuehren 208cdf0e10cSrcweir |* 209cdf0e10cSrcweir \************************************************************************/ 210cdf0e10cSrcweir 21128bcfa49SArmin Le Grand void SvxColorValueSet_docking::DoDrag() 212cdf0e10cSrcweir { 213cdf0e10cSrcweir SfxObjectShell* pDocSh = SfxObjectShell::Current(); 214cdf0e10cSrcweir sal_uInt16 nItemId = GetItemId( aDragPosPixel ); 215cdf0e10cSrcweir 216cdf0e10cSrcweir if( pDocSh && nItemId ) 217cdf0e10cSrcweir { 218cdf0e10cSrcweir XFillAttrSetItem aXFillSetItem( &pDocSh->GetPool() ); 219cdf0e10cSrcweir SfxItemSet& rSet = aXFillSetItem.GetItemSet(); 220cdf0e10cSrcweir 221cdf0e10cSrcweir rSet.Put( XFillColorItem( GetItemText( nItemId ), GetItemColor( nItemId ) ) ); 222cdf0e10cSrcweir rSet.Put(XFillStyleItem( ( 1 == nItemId ) ? XFILL_NONE : XFILL_SOLID ) ); 223cdf0e10cSrcweir 224cdf0e10cSrcweir EndSelection(); 225cdf0e10cSrcweir ( new SvxColorValueSetData( aXFillSetItem ) )->StartDrag( this, DND_ACTION_COPY ); 226cdf0e10cSrcweir ReleaseMouse(); 227cdf0e10cSrcweir } 228cdf0e10cSrcweir } 229cdf0e10cSrcweir 230cdf0e10cSrcweir /************************************************************************* 231cdf0e10cSrcweir |* 232cdf0e10cSrcweir |* 233cdf0e10cSrcweir |* 234cdf0e10cSrcweir \************************************************************************/ 235cdf0e10cSrcweir 23628bcfa49SArmin Le Grand IMPL_STATIC_LINK(SvxColorValueSet_docking, ExecDragHdl, void*, EMPTYARG) 237cdf0e10cSrcweir { 238cdf0e10cSrcweir // Als Link, damit asynchron ohne ImpMouseMoveMsg auf dem Stack auch die 239cdf0e10cSrcweir // Farbleiste geloescht werden darf 240cdf0e10cSrcweir pThis->DoDrag(); 241cdf0e10cSrcweir return(0); 242cdf0e10cSrcweir } 243cdf0e10cSrcweir 244cdf0e10cSrcweir /************************************************************************* 245cdf0e10cSrcweir |* 246cdf0e10cSrcweir |* Ctor: SvxColorDockingWindow 247cdf0e10cSrcweir |* 248cdf0e10cSrcweir \************************************************************************/ 249cdf0e10cSrcweir 250cdf0e10cSrcweir SvxColorDockingWindow::SvxColorDockingWindow 251cdf0e10cSrcweir ( 252cdf0e10cSrcweir SfxBindings* _pBindings, 253cdf0e10cSrcweir SfxChildWindow* pCW, 254cdf0e10cSrcweir Window* _pParent, 255cdf0e10cSrcweir const ResId& rResId 256cdf0e10cSrcweir ) : 257cdf0e10cSrcweir 258cdf0e10cSrcweir SfxDockingWindow( _pBindings, pCW, _pParent, rResId ), 259cdf0e10cSrcweir 260*c7be74b1SArmin Le Grand maColorTable(), 261cdf0e10cSrcweir aColorSet ( this, ResId( 1, *rResId.GetResMgr() ) ), 262cdf0e10cSrcweir nLeftSlot ( SID_ATTR_FILL_COLOR ), 263cdf0e10cSrcweir nRightSlot ( SID_ATTR_LINE_COLOR ), 264cdf0e10cSrcweir nCols ( 20 ), 26528bcfa49SArmin Le Grand nLines ( 1 ) 266cdf0e10cSrcweir 267cdf0e10cSrcweir { 268cdf0e10cSrcweir FreeResource(); 269cdf0e10cSrcweir 270cdf0e10cSrcweir aColorSet.SetStyle( aColorSet.GetStyle() | WB_ITEMBORDER ); 271cdf0e10cSrcweir aColorSet.SetSelectHdl( LINK( this, SvxColorDockingWindow, SelectHdl ) ); 272cdf0e10cSrcweir 273cdf0e10cSrcweir // Get the model from the view shell. Using SfxObjectShell::Current() 274cdf0e10cSrcweir // is unreliable when called at the wrong times. 275cdf0e10cSrcweir SfxObjectShell* pDocSh = NULL; 276cdf0e10cSrcweir if (_pBindings != NULL) 277cdf0e10cSrcweir { 278cdf0e10cSrcweir SfxDispatcher* pDispatcher = _pBindings->GetDispatcher(); 279cdf0e10cSrcweir if (pDispatcher != NULL) 280cdf0e10cSrcweir { 281cdf0e10cSrcweir SfxViewFrame* pFrame = pDispatcher->GetFrame(); 282cdf0e10cSrcweir if (pFrame != NULL) 283cdf0e10cSrcweir { 284cdf0e10cSrcweir SfxViewShell* pViewShell = pFrame->GetViewShell(); 285cdf0e10cSrcweir if (pViewShell != NULL) 286cdf0e10cSrcweir pDocSh = pViewShell->GetObjectShell(); 287cdf0e10cSrcweir } 288cdf0e10cSrcweir } 289cdf0e10cSrcweir } 290cdf0e10cSrcweir 291cdf0e10cSrcweir if ( pDocSh ) 292cdf0e10cSrcweir { 293cdf0e10cSrcweir const SfxPoolItem* pItem = pDocSh->GetItem( SID_COLOR_TABLE ); 294cdf0e10cSrcweir if( pItem ) 295cdf0e10cSrcweir { 296*c7be74b1SArmin Le Grand maColorTable = static_cast< const SvxColorTableItem* >(pItem)->GetColorTable(); 297cdf0e10cSrcweir FillValueSet(); 298cdf0e10cSrcweir } 299cdf0e10cSrcweir } 30028bcfa49SArmin Le Grand 30128bcfa49SArmin Le Grand aItemSize = aColorSet.CalcItemSizePixel(Size(aColorSet.getEntryEdgeLength(), aColorSet.getEntryEdgeLength())); 30228bcfa49SArmin Le Grand aItemSize.Width() = aItemSize.Width() + aColorSet.getEntryEdgeLength(); 303cdf0e10cSrcweir aItemSize.Width() /= 2; 30428bcfa49SArmin Le Grand aItemSize.Height() = aItemSize.Height() + aColorSet.getEntryEdgeLength(); 305cdf0e10cSrcweir aItemSize.Height() /= 2; 306cdf0e10cSrcweir 307cdf0e10cSrcweir SetSize(); 308cdf0e10cSrcweir aColorSet.Show(); 309cdf0e10cSrcweir StartListening( *_pBindings, sal_True ); 310cdf0e10cSrcweir } 311cdf0e10cSrcweir 312cdf0e10cSrcweir 313cdf0e10cSrcweir /************************************************************************* 314cdf0e10cSrcweir |* 315cdf0e10cSrcweir |* Dtor: SvxColorDockingWindow 316cdf0e10cSrcweir |* 317cdf0e10cSrcweir \************************************************************************/ 318cdf0e10cSrcweir 319cdf0e10cSrcweir SvxColorDockingWindow::~SvxColorDockingWindow() 320cdf0e10cSrcweir { 321cdf0e10cSrcweir EndListening( GetBindings() ); 322cdf0e10cSrcweir } 323cdf0e10cSrcweir 324cdf0e10cSrcweir /************************************************************************* 325cdf0e10cSrcweir |* 326cdf0e10cSrcweir |* Notify 327cdf0e10cSrcweir |* 328cdf0e10cSrcweir \************************************************************************/ 329cdf0e10cSrcweir 330cdf0e10cSrcweir void SvxColorDockingWindow::Notify( SfxBroadcaster& , const SfxHint& rHint ) 331cdf0e10cSrcweir { 332cdf0e10cSrcweir const SfxPoolItemHint *pPoolItemHint = PTR_CAST(SfxPoolItemHint, &rHint); 333cdf0e10cSrcweir if ( pPoolItemHint 334cdf0e10cSrcweir && ( pPoolItemHint->GetObject()->ISA( SvxColorTableItem ) ) ) 335cdf0e10cSrcweir { 336cdf0e10cSrcweir // Die Liste der Farben hat sich geaendert 337*c7be74b1SArmin Le Grand maColorTable = static_cast< SvxColorTableItem* >(pPoolItemHint->GetObject())->GetColorTable(); 338cdf0e10cSrcweir FillValueSet(); 339cdf0e10cSrcweir } 340cdf0e10cSrcweir } 341cdf0e10cSrcweir 342cdf0e10cSrcweir /************************************************************************* 343cdf0e10cSrcweir |* 344cdf0e10cSrcweir |* FillValueSet 345cdf0e10cSrcweir |* 346cdf0e10cSrcweir \************************************************************************/ 347cdf0e10cSrcweir 348cdf0e10cSrcweir void SvxColorDockingWindow::FillValueSet() 349cdf0e10cSrcweir { 350*c7be74b1SArmin Le Grand if( maColorTable.get() ) 351cdf0e10cSrcweir { 352*c7be74b1SArmin Le Grand nCount = maColorTable->Count(); 353cdf0e10cSrcweir aColorSet.Clear(); 354cdf0e10cSrcweir 35528bcfa49SArmin Le Grand // create the first entry for 'invisible/none' 35628bcfa49SArmin Le Grand const Size aColorSize(aColorSet.getEntryEdgeLength(), aColorSet.getEntryEdgeLength()); 357cdf0e10cSrcweir long nPtX = aColorSize.Width() - 1; 358cdf0e10cSrcweir long nPtY = aColorSize.Height() - 1; 359cdf0e10cSrcweir VirtualDevice aVD; 36028bcfa49SArmin Le Grand 361cdf0e10cSrcweir aVD.SetOutputSizePixel( aColorSize ); 362cdf0e10cSrcweir aVD.SetLineColor( Color( COL_BLACK ) ); 363cdf0e10cSrcweir aVD.SetBackground( Wallpaper( Color( COL_WHITE ) ) ); 364cdf0e10cSrcweir aVD.DrawLine( Point(), Point( nPtX, nPtY ) ); 365cdf0e10cSrcweir aVD.DrawLine( Point( 0, nPtY ), Point( nPtX, 0 ) ); 366cdf0e10cSrcweir 367cdf0e10cSrcweir Bitmap aBmp( aVD.GetBitmap( Point(), aColorSize ) ); 368cdf0e10cSrcweir 369cdf0e10cSrcweir aColorSet.InsertItem( (sal_uInt16)1, Image(aBmp), SVX_RESSTR( RID_SVXSTR_INVISIBLE ) ); 370*c7be74b1SArmin Le Grand aColorSet.addEntriesForXColorList(maColorTable, 2); 371cdf0e10cSrcweir } 372cdf0e10cSrcweir } 373cdf0e10cSrcweir 374cdf0e10cSrcweir /************************************************************************* 375cdf0e10cSrcweir |* 376cdf0e10cSrcweir |* SetSize 377cdf0e10cSrcweir |* 378cdf0e10cSrcweir \************************************************************************/ 379cdf0e10cSrcweir 380cdf0e10cSrcweir void SvxColorDockingWindow::SetSize() 381cdf0e10cSrcweir { 382cdf0e10cSrcweir // Groesse fuer ValueSet berechnen 383cdf0e10cSrcweir Size aSize = GetOutputSizePixel(); 384cdf0e10cSrcweir aSize.Width() -= 4; 385cdf0e10cSrcweir aSize.Height() -= 4; 386cdf0e10cSrcweir 387cdf0e10cSrcweir // Zeilen und Spalten berechnen 388cdf0e10cSrcweir nCols = (sal_uInt16) ( aSize.Width() / aItemSize.Width() ); 389cdf0e10cSrcweir nLines = (sal_uInt16) ( (float) aSize.Height() / (float) aItemSize.Height() /*+ 0.35*/ ); 390cdf0e10cSrcweir if( nLines == 0 ) 391cdf0e10cSrcweir nLines++; 392cdf0e10cSrcweir 393cdf0e10cSrcweir // Scrollbar setzen/entfernen 394cdf0e10cSrcweir WinBits nBits = aColorSet.GetStyle(); 395cdf0e10cSrcweir if ( nLines * nCols >= nCount ) 396cdf0e10cSrcweir nBits &= ~WB_VSCROLL; 397cdf0e10cSrcweir else 398cdf0e10cSrcweir nBits |= WB_VSCROLL; 399cdf0e10cSrcweir aColorSet.SetStyle( nBits ); 400cdf0e10cSrcweir 401cdf0e10cSrcweir // ScrollBar ? 402cdf0e10cSrcweir long nScrollWidth = aColorSet.GetScrollWidth(); 403cdf0e10cSrcweir if( nScrollWidth > 0 ) 404cdf0e10cSrcweir { 405cdf0e10cSrcweir // Spalten mit ScrollBar berechnen 406cdf0e10cSrcweir nCols = (sal_uInt16) ( ( aSize.Width() - nScrollWidth ) / aItemSize.Width() ); 407cdf0e10cSrcweir } 408cdf0e10cSrcweir aColorSet.SetColCount( nCols ); 409cdf0e10cSrcweir 410cdf0e10cSrcweir if( IsFloatingMode() ) 411cdf0e10cSrcweir aColorSet.SetLineCount( nLines ); 412cdf0e10cSrcweir else 413cdf0e10cSrcweir { 414cdf0e10cSrcweir aColorSet.SetLineCount( 0 ); // sonst wird LineHeight ignoriert 415cdf0e10cSrcweir aColorSet.SetItemHeight( aItemSize.Height() ); 416cdf0e10cSrcweir } 417cdf0e10cSrcweir 418cdf0e10cSrcweir aColorSet.SetPosSizePixel( Point( 2, 2 ), aSize ); 419cdf0e10cSrcweir } 420cdf0e10cSrcweir 421cdf0e10cSrcweir /************************************************************************* 422cdf0e10cSrcweir |* 423cdf0e10cSrcweir |* SvxColorDockingWindow: Close 424cdf0e10cSrcweir |* 425cdf0e10cSrcweir \************************************************************************/ 426cdf0e10cSrcweir 427cdf0e10cSrcweir sal_Bool SvxColorDockingWindow::Close() 428cdf0e10cSrcweir { 429cdf0e10cSrcweir SfxBoolItem aItem( SID_COLOR_CONTROL, sal_False ); 430cdf0e10cSrcweir GetBindings().GetDispatcher()->Execute( 431cdf0e10cSrcweir SID_COLOR_CONTROL, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD, &aItem, 0L ); 432cdf0e10cSrcweir SfxDockingWindow::Close(); 433cdf0e10cSrcweir return( sal_True ); 434cdf0e10cSrcweir } 435cdf0e10cSrcweir 436cdf0e10cSrcweir /************************************************************************* 437cdf0e10cSrcweir |* 438cdf0e10cSrcweir |* SelectHdl 439cdf0e10cSrcweir |* 440cdf0e10cSrcweir \************************************************************************/ 441cdf0e10cSrcweir 442cdf0e10cSrcweir IMPL_LINK( SvxColorDockingWindow, SelectHdl, void *, EMPTYARG ) 443cdf0e10cSrcweir { 444cdf0e10cSrcweir SfxDispatcher* pDispatcher = GetBindings().GetDispatcher(); 445cdf0e10cSrcweir sal_uInt16 nPos = aColorSet.GetSelectItemId(); 446cdf0e10cSrcweir Color aColor( aColorSet.GetItemColor( nPos ) ); 447cdf0e10cSrcweir String aStr( aColorSet.GetItemText( nPos ) ); 448cdf0e10cSrcweir 449cdf0e10cSrcweir if (aColorSet.IsLeftButton()) 450cdf0e10cSrcweir { 451cdf0e10cSrcweir if ( nLeftSlot == SID_ATTR_FILL_COLOR ) 452cdf0e10cSrcweir { 453cdf0e10cSrcweir if ( nPos == 1 ) // unsichtbar 454cdf0e10cSrcweir { 455cdf0e10cSrcweir XFillStyleItem aXFillStyleItem( XFILL_NONE ); 456cdf0e10cSrcweir pDispatcher->Execute( nLeftSlot, SFX_CALLMODE_RECORD, &aXFillStyleItem, 0L ); 457cdf0e10cSrcweir } 458cdf0e10cSrcweir else 459cdf0e10cSrcweir { 460cdf0e10cSrcweir sal_Bool bDone = sal_False; 461cdf0e10cSrcweir 462cdf0e10cSrcweir // Wenn wir eine DrawView haben und uns im TextEdit-Modus befinden, 463cdf0e10cSrcweir // wird nicht die Flaechen-, sondern die Textfarbe zugewiesen 464cdf0e10cSrcweir SfxViewShell* pViewSh = SfxViewShell::Current(); 465cdf0e10cSrcweir if ( pViewSh ) 466cdf0e10cSrcweir { 467cdf0e10cSrcweir SdrView* pView = pViewSh->GetDrawView(); 468cdf0e10cSrcweir if ( pView && pView->IsTextEdit() ) 469cdf0e10cSrcweir { 470cdf0e10cSrcweir SvxColorItem aTextColorItem( aColor, SID_ATTR_CHAR_COLOR ); 471cdf0e10cSrcweir pDispatcher->Execute( 472cdf0e10cSrcweir SID_ATTR_CHAR_COLOR, SFX_CALLMODE_RECORD, &aTextColorItem, 0L ); 473cdf0e10cSrcweir bDone = sal_True; 474cdf0e10cSrcweir } 475cdf0e10cSrcweir } 476cdf0e10cSrcweir if ( !bDone ) 477cdf0e10cSrcweir { 478cdf0e10cSrcweir XFillStyleItem aXFillStyleItem( XFILL_SOLID ); 479cdf0e10cSrcweir XFillColorItem aXFillColorItem( aStr, aColor ); 480cdf0e10cSrcweir pDispatcher->Execute( 481cdf0e10cSrcweir nLeftSlot, SFX_CALLMODE_RECORD, &aXFillColorItem, &aXFillStyleItem, 0L ); 482cdf0e10cSrcweir } 483cdf0e10cSrcweir } 484cdf0e10cSrcweir } 485cdf0e10cSrcweir else if ( nPos != 1 ) // unsichtbar 486cdf0e10cSrcweir { 487cdf0e10cSrcweir SvxColorItem aLeftColorItem( aColor, nLeftSlot ); 488cdf0e10cSrcweir pDispatcher->Execute( nLeftSlot, SFX_CALLMODE_RECORD, &aLeftColorItem, 0L ); 489cdf0e10cSrcweir } 490cdf0e10cSrcweir } 491cdf0e10cSrcweir else 492cdf0e10cSrcweir { 493cdf0e10cSrcweir if ( nRightSlot == SID_ATTR_LINE_COLOR ) 494cdf0e10cSrcweir { 495cdf0e10cSrcweir if( nPos == 1 ) // unsichtbar 496cdf0e10cSrcweir { 497cdf0e10cSrcweir XLineStyleItem aXLineStyleItem( XLINE_NONE ); 498cdf0e10cSrcweir pDispatcher->Execute( nRightSlot, SFX_CALLMODE_RECORD, &aXLineStyleItem, 0L ); 499cdf0e10cSrcweir } 500cdf0e10cSrcweir else 501cdf0e10cSrcweir { 502cdf0e10cSrcweir // Sollte der LineStyle unsichtbar sein, so wird er auf SOLID gesetzt 503cdf0e10cSrcweir SfxViewShell* pViewSh = SfxViewShell::Current(); 504cdf0e10cSrcweir if ( pViewSh ) 505cdf0e10cSrcweir { 506cdf0e10cSrcweir SdrView* pView = pViewSh->GetDrawView(); 507cdf0e10cSrcweir if ( pView ) 508cdf0e10cSrcweir { 509cdf0e10cSrcweir SfxItemSet aAttrSet( pView->GetModel()->GetItemPool() ); 510cdf0e10cSrcweir pView->GetAttributes( aAttrSet ); 511cdf0e10cSrcweir if ( aAttrSet.GetItemState( XATTR_LINESTYLE ) != SFX_ITEM_DONTCARE ) 512cdf0e10cSrcweir { 513cdf0e10cSrcweir XLineStyle eXLS = (XLineStyle) 514cdf0e10cSrcweir ( (const XLineStyleItem&)aAttrSet.Get( XATTR_LINESTYLE ) ).GetValue(); 515cdf0e10cSrcweir if ( eXLS == XLINE_NONE ) 516cdf0e10cSrcweir { 517cdf0e10cSrcweir XLineStyleItem aXLineStyleItem( XLINE_SOLID ); 518cdf0e10cSrcweir pDispatcher->Execute( nRightSlot, SFX_CALLMODE_RECORD, &aXLineStyleItem, 0L ); 519cdf0e10cSrcweir } 520cdf0e10cSrcweir } 521cdf0e10cSrcweir } 522cdf0e10cSrcweir } 523cdf0e10cSrcweir 524cdf0e10cSrcweir XLineColorItem aXLineColorItem( aStr, aColor ); 525cdf0e10cSrcweir pDispatcher->Execute( nRightSlot, SFX_CALLMODE_RECORD, &aXLineColorItem, 0L ); 526cdf0e10cSrcweir } 527cdf0e10cSrcweir } 528cdf0e10cSrcweir else if ( nPos != 1 ) // unsichtbar 529cdf0e10cSrcweir { 530cdf0e10cSrcweir SvxColorItem aRightColorItem( aColor, nRightSlot ); 531cdf0e10cSrcweir pDispatcher->Execute( nRightSlot, SFX_CALLMODE_RECORD, &aRightColorItem, 0L ); 532cdf0e10cSrcweir } 533cdf0e10cSrcweir } 534cdf0e10cSrcweir 535cdf0e10cSrcweir return 0; 536cdf0e10cSrcweir } 537cdf0e10cSrcweir 538cdf0e10cSrcweir /************************************************************************* 539cdf0e10cSrcweir |* 540cdf0e10cSrcweir |* Resizing 541cdf0e10cSrcweir |* 542cdf0e10cSrcweir \************************************************************************/ 543cdf0e10cSrcweir 544cdf0e10cSrcweir 545cdf0e10cSrcweir void SvxColorDockingWindow::Resizing( Size& rNewSize ) 546cdf0e10cSrcweir { 547cdf0e10cSrcweir rNewSize.Width() -= 4; 548cdf0e10cSrcweir rNewSize.Height() -= 4; 549cdf0e10cSrcweir 550cdf0e10cSrcweir // Spalten und Reihen ermitteln 551cdf0e10cSrcweir nCols = (sal_uInt16) ( (float) rNewSize.Width() / (float) aItemSize.Width() + 0.5 ); 552cdf0e10cSrcweir nLines = (sal_uInt16) ( (float) rNewSize.Height() / (float) aItemSize.Height() + 0.5 ); 553cdf0e10cSrcweir if( nLines == 0 ) 554cdf0e10cSrcweir nLines = 1; 555cdf0e10cSrcweir 556cdf0e10cSrcweir // Scrollbar setzen/entfernen 557cdf0e10cSrcweir WinBits nBits = aColorSet.GetStyle(); 558cdf0e10cSrcweir if ( nLines * nCols >= nCount ) 559cdf0e10cSrcweir nBits &= ~WB_VSCROLL; 560cdf0e10cSrcweir else 561cdf0e10cSrcweir nBits |= WB_VSCROLL; 562cdf0e10cSrcweir aColorSet.SetStyle( nBits ); 563cdf0e10cSrcweir 564cdf0e10cSrcweir // ScrollBar ? 565cdf0e10cSrcweir long nScrollWidth = aColorSet.GetScrollWidth(); 566cdf0e10cSrcweir if( nScrollWidth > 0 ) 567cdf0e10cSrcweir { 568cdf0e10cSrcweir // Spalten mit ScrollBar berechnen 569cdf0e10cSrcweir nCols = (sal_uInt16) ( ( ( (float) rNewSize.Width() - (float) nScrollWidth ) ) 570cdf0e10cSrcweir / (float) aItemSize.Width() + 0.5 ); 571cdf0e10cSrcweir } 572cdf0e10cSrcweir if( nCols <= 1 ) 573cdf0e10cSrcweir nCols = 2; 574cdf0e10cSrcweir 575cdf0e10cSrcweir // Max. Reihen anhand der gegebenen Spalten berechnen 576cdf0e10cSrcweir long nMaxLines = nCount / nCols; 577cdf0e10cSrcweir if( nCount % nCols ) 578cdf0e10cSrcweir nMaxLines++; 579cdf0e10cSrcweir 580cdf0e10cSrcweir nLines = sal::static_int_cast< sal_uInt16 >( 581cdf0e10cSrcweir std::min< long >( nLines, nMaxLines ) ); 582cdf0e10cSrcweir 583cdf0e10cSrcweir // Groesse des Windows setzen 584cdf0e10cSrcweir rNewSize.Width() = nCols * aItemSize.Width() + nScrollWidth + 4; 585cdf0e10cSrcweir rNewSize.Height() = nLines * aItemSize.Height() + 4; 586cdf0e10cSrcweir } 587cdf0e10cSrcweir 588cdf0e10cSrcweir /************************************************************************* 589cdf0e10cSrcweir |* 590cdf0e10cSrcweir |* Resize 591cdf0e10cSrcweir |* 592cdf0e10cSrcweir \************************************************************************/ 593cdf0e10cSrcweir 594cdf0e10cSrcweir void SvxColorDockingWindow::Resize() 595cdf0e10cSrcweir { 596cdf0e10cSrcweir if ( !IsFloatingMode() || !GetFloatingWindow()->IsRollUp() ) 597cdf0e10cSrcweir SetSize(); 598cdf0e10cSrcweir SfxDockingWindow::Resize(); 599cdf0e10cSrcweir } 600cdf0e10cSrcweir 601cdf0e10cSrcweir 602cdf0e10cSrcweir 603cdf0e10cSrcweir void SvxColorDockingWindow::GetFocus (void) 604cdf0e10cSrcweir { 605cdf0e10cSrcweir SfxDockingWindow::GetFocus(); 606cdf0e10cSrcweir // Grab the focus to the color value set so that it can be controlled 607cdf0e10cSrcweir // with the keyboard. 608cdf0e10cSrcweir aColorSet.GrabFocus(); 609cdf0e10cSrcweir } 610cdf0e10cSrcweir 611cdf0e10cSrcweir long SvxColorDockingWindow::Notify( NotifyEvent& rNEvt ) 612cdf0e10cSrcweir { 613cdf0e10cSrcweir long nRet = 0; 614cdf0e10cSrcweir if( ( rNEvt.GetType() == EVENT_KEYINPUT ) ) 615cdf0e10cSrcweir { 616cdf0e10cSrcweir KeyEvent aKeyEvt = *rNEvt.GetKeyEvent(); 617cdf0e10cSrcweir sal_uInt16 nKeyCode = aKeyEvt.GetKeyCode().GetCode(); 618cdf0e10cSrcweir switch( nKeyCode ) 619cdf0e10cSrcweir { 620cdf0e10cSrcweir case KEY_ESCAPE: 621cdf0e10cSrcweir GrabFocusToDocument(); 622cdf0e10cSrcweir nRet = 1; 623cdf0e10cSrcweir break; 624cdf0e10cSrcweir } 625cdf0e10cSrcweir } 626cdf0e10cSrcweir 627cdf0e10cSrcweir return nRet ? nRet : SfxDockingWindow::Notify( rNEvt ); 628cdf0e10cSrcweir } 629