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