xref: /trunk/main/svx/source/tbxctrls/fillctrl.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
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 
22cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
23cdf0e10cSrcweir #include "precompiled_svx.hxx"
24cdf0e10cSrcweir 
25cdf0e10cSrcweir #include <string> // HACK: prevent conflict between STLPORT and Workshop headers
26cdf0e10cSrcweir #include <sfx2/app.hxx>
27cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
28cdf0e10cSrcweir #include <sfx2/objsh.hxx>
29cdf0e10cSrcweir #include <sfx2/viewsh.hxx>
30cdf0e10cSrcweir #include <rtl/ustring.hxx>
31cdf0e10cSrcweir #include <svx/dialogs.hrc>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #define TMP_STR_BEGIN   '['
34cdf0e10cSrcweir #define TMP_STR_END     ']'
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include "svx/drawitem.hxx"
37cdf0e10cSrcweir #include "svx/xattr.hxx"
38cdf0e10cSrcweir #include <svx/xtable.hxx>
39cdf0e10cSrcweir #include <svx/fillctrl.hxx>
40cdf0e10cSrcweir #include <svx/itemwin.hxx>
41cdf0e10cSrcweir #include <svx/dialmgr.hxx>
42cdf0e10cSrcweir #include "helpid.hrc"
43cdf0e10cSrcweir 
44cdf0e10cSrcweir using namespace ::com::sun::star::uno;
45cdf0e10cSrcweir using namespace ::com::sun::star::util;
46cdf0e10cSrcweir using namespace ::com::sun::star::beans;
47cdf0e10cSrcweir using namespace ::com::sun::star::frame;
48cdf0e10cSrcweir using namespace ::com::sun::star::lang;
49cdf0e10cSrcweir 
50cdf0e10cSrcweir SFX_IMPL_TOOLBOX_CONTROL( SvxFillToolBoxControl, XFillStyleItem );
51cdf0e10cSrcweir 
52cdf0e10cSrcweir /*************************************************************************
53cdf0e10cSrcweir |*
54cdf0e10cSrcweir |* SvxFillToolBoxControl
55cdf0e10cSrcweir |*
56cdf0e10cSrcweir \************************************************************************/
57cdf0e10cSrcweir 
SvxFillToolBoxControl(sal_uInt16 nSlotId,sal_uInt16 nId,ToolBox & rTbx)58*00467759SArmin Le Grand SvxFillToolBoxControl::SvxFillToolBoxControl(
59*00467759SArmin Le Grand     sal_uInt16 nSlotId,
60*00467759SArmin Le Grand     sal_uInt16 nId,
61*00467759SArmin Le Grand     ToolBox& rTbx )
62*00467759SArmin Le Grand :   SfxToolBoxControl( nSlotId, nId, rTbx ),
63*00467759SArmin Le Grand     mpStyleItem(0),
64*00467759SArmin Le Grand     mpColorItem(0),
65*00467759SArmin Le Grand     mpGradientItem(0),
66*00467759SArmin Le Grand     mpHatchItem(0),
67*00467759SArmin Le Grand     mpBitmapItem(0),
68*00467759SArmin Le Grand     mpFillControl(0),
69*00467759SArmin Le Grand     mpFillTypeLB(0),
70*00467759SArmin Le Grand     mpFillAttrLB(0),
71*00467759SArmin Le Grand     meLastXFS(XFILL_NONE),
72*00467759SArmin Le Grand     mbUpdate(false)
73cdf0e10cSrcweir {
74cdf0e10cSrcweir     addStatusListener( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:FillColor" )));
75cdf0e10cSrcweir     addStatusListener( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:FillGradient" )));
76cdf0e10cSrcweir     addStatusListener( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:FillHatch" )));
77cdf0e10cSrcweir     addStatusListener( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:FillBitmap" )));
78cdf0e10cSrcweir     addStatusListener( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ColorTableState" )));
79cdf0e10cSrcweir     addStatusListener( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:GradientListState" )));
80cdf0e10cSrcweir     addStatusListener( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:HatchListState" )));
81cdf0e10cSrcweir     addStatusListener( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:BitmapListState" )));
82cdf0e10cSrcweir }
83cdf0e10cSrcweir 
84cdf0e10cSrcweir //========================================================================
85cdf0e10cSrcweir 
~SvxFillToolBoxControl()86cdf0e10cSrcweir SvxFillToolBoxControl::~SvxFillToolBoxControl()
87cdf0e10cSrcweir {
88*00467759SArmin Le Grand     delete mpStyleItem;
89*00467759SArmin Le Grand     delete mpColorItem;
90*00467759SArmin Le Grand     delete mpGradientItem;
91*00467759SArmin Le Grand     delete mpHatchItem;
92*00467759SArmin Le Grand     delete mpBitmapItem;
93cdf0e10cSrcweir }
94cdf0e10cSrcweir 
95cdf0e10cSrcweir //========================================================================
96cdf0e10cSrcweir 
StateChanged(sal_uInt16 nSID,SfxItemState eState,const SfxPoolItem * pState)97cdf0e10cSrcweir void SvxFillToolBoxControl::StateChanged(
98*00467759SArmin Le Grand     sal_uInt16 nSID,
99*00467759SArmin Le Grand     SfxItemState eState,
100*00467759SArmin Le Grand     const SfxPoolItem* pState)
101cdf0e10cSrcweir {
102*00467759SArmin Le Grand     bool bEnableControls(false);
103cdf0e10cSrcweir 
104cdf0e10cSrcweir     if(eState == SFX_ITEM_DISABLED)
105cdf0e10cSrcweir     {
106*00467759SArmin Le Grand         // slot disable state
107cdf0e10cSrcweir         if(nSID == SID_ATTR_FILL_STYLE)
108cdf0e10cSrcweir         {
109*00467759SArmin Le Grand             mpFillTypeLB->Disable();
110*00467759SArmin Le Grand             mpFillTypeLB->SetNoSelection();
111cdf0e10cSrcweir         }
112*00467759SArmin Le Grand 
113*00467759SArmin Le Grand         mpFillAttrLB->Disable();
114*00467759SArmin Le Grand         mpFillAttrLB->SetNoSelection();
115cdf0e10cSrcweir     }
116*00467759SArmin Le Grand     else if(SFX_ITEM_AVAILABLE == eState)
117cdf0e10cSrcweir     {
118*00467759SArmin Le Grand         // slot available state
119cdf0e10cSrcweir         if(nSID == SID_ATTR_FILL_STYLE)
120cdf0e10cSrcweir         {
121*00467759SArmin Le Grand             delete mpStyleItem;
122*00467759SArmin Le Grand             mpStyleItem = static_cast< XFillStyleItem* >(pState->Clone());
123*00467759SArmin Le Grand             mpFillTypeLB->Enable();
124cdf0e10cSrcweir         }
125*00467759SArmin Le Grand         else if(mpStyleItem)
126cdf0e10cSrcweir         {
127*00467759SArmin Le Grand             const XFillStyle eXFS(static_cast< XFillStyle >(mpStyleItem->GetValue()));
128cdf0e10cSrcweir 
129cdf0e10cSrcweir             if(nSID == SID_ATTR_FILL_COLOR)
130cdf0e10cSrcweir             {
131*00467759SArmin Le Grand                 delete mpColorItem;
132*00467759SArmin Le Grand                 mpColorItem = static_cast< XFillColorItem* >(pState->Clone());
133cdf0e10cSrcweir 
134cdf0e10cSrcweir                 if(eXFS == XFILL_SOLID)
135*00467759SArmin Le Grand                 {
136*00467759SArmin Le Grand                     bEnableControls = true;
137*00467759SArmin Le Grand                 }
138cdf0e10cSrcweir             }
139cdf0e10cSrcweir             else if(nSID == SID_ATTR_FILL_GRADIENT)
140cdf0e10cSrcweir             {
141*00467759SArmin Le Grand                 delete mpGradientItem;
142*00467759SArmin Le Grand                 mpGradientItem = static_cast< XFillGradientItem* >(pState->Clone());
143cdf0e10cSrcweir 
144cdf0e10cSrcweir                 if(eXFS == XFILL_GRADIENT)
145*00467759SArmin Le Grand                 {
146*00467759SArmin Le Grand                     bEnableControls = true;
147*00467759SArmin Le Grand                 }
148cdf0e10cSrcweir             }
149cdf0e10cSrcweir             else if(nSID == SID_ATTR_FILL_HATCH)
150cdf0e10cSrcweir             {
151*00467759SArmin Le Grand                 delete mpHatchItem;
152*00467759SArmin Le Grand                 mpHatchItem = static_cast< XFillHatchItem* >(pState->Clone());
153cdf0e10cSrcweir 
154cdf0e10cSrcweir                 if(eXFS == XFILL_HATCH)
155*00467759SArmin Le Grand                 {
156*00467759SArmin Le Grand                     bEnableControls = true;
157*00467759SArmin Le Grand                 }
158cdf0e10cSrcweir             }
159cdf0e10cSrcweir             else if(nSID == SID_ATTR_FILL_BITMAP)
160cdf0e10cSrcweir             {
161*00467759SArmin Le Grand                 delete mpBitmapItem;
162*00467759SArmin Le Grand                 mpBitmapItem = static_cast< XFillBitmapItem* >(pState->Clone());
163cdf0e10cSrcweir 
164cdf0e10cSrcweir                 if(eXFS == XFILL_BITMAP)
1658f1fbbb1SArmin Le Grand                 {
166*00467759SArmin Le Grand                     bEnableControls = true;
167*00467759SArmin Le Grand                 }
168*00467759SArmin Le Grand             }
1698f1fbbb1SArmin Le Grand         }
1708f1fbbb1SArmin Le Grand 
171*00467759SArmin Le Grand         if(mpStyleItem)
172*00467759SArmin Le Grand         {
173*00467759SArmin Le Grand             // ensure that the correct entry is selected in mpFillTypeLB
174*00467759SArmin Le Grand             XFillStyle eXFS(static_cast< XFillStyle >(mpStyleItem->GetValue()));
175*00467759SArmin Le Grand             const bool bFillTypeChangedByUser(mpFillControl->mbFillTypeChanged);
176*00467759SArmin Le Grand 
177*00467759SArmin Le Grand             if(bFillTypeChangedByUser)
178*00467759SArmin Le Grand             {
179*00467759SArmin Le Grand                 meLastXFS = static_cast< XFillStyle >(mpFillControl->mnLastFillTypeControlSelectEntryPos);
180*00467759SArmin Le Grand                 mpFillControl->mbFillTypeChanged = false;
181*00467759SArmin Le Grand             }
182*00467759SArmin Le Grand 
183*00467759SArmin Le Grand             if(meLastXFS != eXFS)
184*00467759SArmin Le Grand             {
185*00467759SArmin Le Grand                 mbUpdate = true;
186*00467759SArmin Le Grand                 mpFillTypeLB->SelectEntryPos(sal::static_int_cast<sal_uInt16>(eXFS));
187*00467759SArmin Le Grand             }
188*00467759SArmin Le Grand 
189*00467759SArmin Le Grand             mpFillAttrLB->Enable();
1908f1fbbb1SArmin Le Grand         }
1918f1fbbb1SArmin Le Grand 
192cdf0e10cSrcweir         if(bEnableControls)
193cdf0e10cSrcweir         {
194*00467759SArmin Le Grand             mpFillAttrLB->Enable();
195*00467759SArmin Le Grand             mbUpdate = true;
196cdf0e10cSrcweir         }
197cdf0e10cSrcweir 
198cdf0e10cSrcweir         Update(pState);
199cdf0e10cSrcweir     }
200cdf0e10cSrcweir     else
201cdf0e10cSrcweir     {
202*00467759SArmin Le Grand         // slot empty or ambigous
203cdf0e10cSrcweir         if(nSID == SID_ATTR_FILL_STYLE)
204cdf0e10cSrcweir         {
205*00467759SArmin Le Grand             mpFillTypeLB->SetNoSelection();
206*00467759SArmin Le Grand             mpFillAttrLB->Disable();
207*00467759SArmin Le Grand             mpFillAttrLB->SetNoSelection();
208*00467759SArmin Le Grand             delete mpStyleItem;
209*00467759SArmin Le Grand             mpStyleItem = 0;
210*00467759SArmin Le Grand             mbUpdate = false;
211cdf0e10cSrcweir         }
212cdf0e10cSrcweir         else
213cdf0e10cSrcweir         {
214*00467759SArmin Le Grand             XFillStyle eXFS(XFILL_NONE);
215*00467759SArmin Le Grand 
216*00467759SArmin Le Grand             if(mpStyleItem)
217*00467759SArmin Le Grand             {
218*00467759SArmin Le Grand                 eXFS = static_cast< XFillStyle >(mpStyleItem->GetValue());
219*00467759SArmin Le Grand             }
220*00467759SArmin Le Grand 
221*00467759SArmin Le Grand             if(!mpStyleItem ||
222cdf0e10cSrcweir                 (nSID == SID_ATTR_FILL_COLOR && eXFS == XFILL_SOLID) ||
223cdf0e10cSrcweir                 (nSID == SID_ATTR_FILL_GRADIENT && eXFS == XFILL_GRADIENT) ||
224cdf0e10cSrcweir                 (nSID == SID_ATTR_FILL_HATCH && eXFS == XFILL_HATCH) ||
225cdf0e10cSrcweir                 (nSID == SID_ATTR_FILL_BITMAP && eXFS == XFILL_BITMAP))
226cdf0e10cSrcweir             {
227*00467759SArmin Le Grand                 mpFillAttrLB->SetNoSelection();
228cdf0e10cSrcweir             }
229cdf0e10cSrcweir         }
230cdf0e10cSrcweir     }
231cdf0e10cSrcweir }
232cdf0e10cSrcweir 
233cdf0e10cSrcweir //========================================================================
234cdf0e10cSrcweir 
Update(const SfxPoolItem * pState)235cdf0e10cSrcweir void SvxFillToolBoxControl::Update(const SfxPoolItem* pState)
236cdf0e10cSrcweir {
237*00467759SArmin Le Grand     if(mpStyleItem && pState && mbUpdate)
238cdf0e10cSrcweir     {
239*00467759SArmin Le Grand         mbUpdate = false;
240*00467759SArmin Le Grand         const XFillStyle eXFS(static_cast< XFillStyle >(mpStyleItem->GetValue()));
241cdf0e10cSrcweir 
242cdf0e10cSrcweir         // Pruefen, ob Fuellstil schon vorher aktiv war
243*00467759SArmin Le Grand         if(meLastXFS != eXFS)
244*00467759SArmin Le Grand         {
245*00467759SArmin Le Grand             // update mnLastFillTypeControlSelectEntryPos and fill style list
246*00467759SArmin Le Grand             mpFillControl->updateLastFillTypeControlSelectEntryPos();
247*00467759SArmin Le Grand             mpFillControl->InitializeFillStyleAccordingToGivenFillType(eXFS);
248*00467759SArmin Le Grand             meLastXFS = eXFS;
249*00467759SArmin Le Grand         }
250cdf0e10cSrcweir 
251cdf0e10cSrcweir         switch(eXFS)
252cdf0e10cSrcweir         {
253cdf0e10cSrcweir             case XFILL_NONE:
254*00467759SArmin Le Grand             {
255cdf0e10cSrcweir                 break;
256*00467759SArmin Le Grand             }
257cdf0e10cSrcweir 
258cdf0e10cSrcweir             case XFILL_SOLID:
259cdf0e10cSrcweir             {
260*00467759SArmin Le Grand                 if(mpColorItem)
261cdf0e10cSrcweir                 {
262*00467759SArmin Le Grand                     String aString(mpColorItem->GetName());
263*00467759SArmin Le Grand                     ::Color aColor = mpColorItem->GetColorValue();
264cdf0e10cSrcweir 
265*00467759SArmin Le Grand                     mpFillAttrLB->SelectEntry(aString);
266cdf0e10cSrcweir 
267*00467759SArmin Le Grand                     if(mpFillAttrLB->GetSelectEntryPos() == LISTBOX_ENTRY_NOTFOUND || mpFillAttrLB->GetSelectEntryColor() != aColor)
268*00467759SArmin Le Grand                     {
269*00467759SArmin Le Grand                         mpFillAttrLB->SelectEntry(aColor);
270*00467759SArmin Le Grand                     }
271cdf0e10cSrcweir 
272cdf0e10cSrcweir                     // Pruefen, ob Eintrag nicht in der Liste ist
273*00467759SArmin Le Grand                     if(mpFillAttrLB->GetSelectEntryPos() == LISTBOX_ENTRY_NOTFOUND || mpFillAttrLB->GetSelectEntryColor() != aColor)
274cdf0e10cSrcweir                     {
275*00467759SArmin Le Grand                         sal_uInt16 nCount = mpFillAttrLB->GetEntryCount();
276cdf0e10cSrcweir                         String aTmpStr;
277cdf0e10cSrcweir                         if(nCount > 0)
278cdf0e10cSrcweir                         {
279cdf0e10cSrcweir                             //Letzter Eintrag wird auf temporaere Farbe geprueft
280*00467759SArmin Le Grand                             aTmpStr = mpFillAttrLB->GetEntry(nCount - 1);
281*00467759SArmin Le Grand 
282*00467759SArmin Le Grand                             if(aTmpStr.GetChar(0) == TMP_STR_BEGIN && aTmpStr.GetChar(aTmpStr.Len() - 1) == TMP_STR_END)
283cdf0e10cSrcweir                             {
284*00467759SArmin Le Grand                                 mpFillAttrLB->RemoveEntry(nCount - 1);
285cdf0e10cSrcweir                             }
286cdf0e10cSrcweir                         }
287*00467759SArmin Le Grand 
288cdf0e10cSrcweir                         aTmpStr = TMP_STR_BEGIN;
289cdf0e10cSrcweir                         aTmpStr += aString;
290cdf0e10cSrcweir                         aTmpStr += TMP_STR_END;
291cdf0e10cSrcweir 
292*00467759SArmin Le Grand                         sal_uInt16 nPos = mpFillAttrLB->InsertEntry(aColor,aTmpStr);
293*00467759SArmin Le Grand                         mpFillAttrLB->SelectEntryPos(nPos);
294cdf0e10cSrcweir                     }
295cdf0e10cSrcweir                 }
296cdf0e10cSrcweir                 else
297*00467759SArmin Le Grand                 {
298*00467759SArmin Le Grand                     mpFillAttrLB->SetNoSelection();
299cdf0e10cSrcweir                 }
300cdf0e10cSrcweir                 break;
301*00467759SArmin Le Grand             }
302cdf0e10cSrcweir 
303cdf0e10cSrcweir             case XFILL_GRADIENT:
304cdf0e10cSrcweir             {
305*00467759SArmin Le Grand                 if(mpGradientItem)
306cdf0e10cSrcweir                 {
307*00467759SArmin Le Grand                     String aString(mpGradientItem->GetName());
308*00467759SArmin Le Grand                     mpFillAttrLB->SelectEntry(aString);
309*00467759SArmin Le Grand 
310cdf0e10cSrcweir                     // Pruefen, ob Eintrag nicht in der Liste ist
311*00467759SArmin Le Grand                     if(mpFillAttrLB->GetSelectEntry() != aString)
312cdf0e10cSrcweir                     {
313*00467759SArmin Le Grand                         sal_uInt16 nCount = mpFillAttrLB->GetEntryCount();
314cdf0e10cSrcweir                         String aTmpStr;
315*00467759SArmin Le Grand 
316cdf0e10cSrcweir                         if(nCount > 0)
317cdf0e10cSrcweir                         {
318cdf0e10cSrcweir                             //Letzter Eintrag wird auf temporaeren Eintrag geprueft
319*00467759SArmin Le Grand                             aTmpStr = mpFillAttrLB->GetEntry(nCount - 1);
320*00467759SArmin Le Grand 
321*00467759SArmin Le Grand                             if(aTmpStr.GetChar(0) == TMP_STR_BEGIN && aTmpStr.GetChar(aTmpStr.Len() - 1) == TMP_STR_END)
322cdf0e10cSrcweir                             {
323*00467759SArmin Le Grand                                 mpFillAttrLB->RemoveEntry(nCount - 1);
324cdf0e10cSrcweir                             }
325cdf0e10cSrcweir                         }
326*00467759SArmin Le Grand 
327cdf0e10cSrcweir                         aTmpStr = TMP_STR_BEGIN;
328cdf0e10cSrcweir                         aTmpStr += aString;
329cdf0e10cSrcweir                         aTmpStr += TMP_STR_END;
330cdf0e10cSrcweir 
331*00467759SArmin Le Grand                         XGradientEntry* pEntry = new XGradientEntry(mpGradientItem->GetGradientValue(),aTmpStr);
332c7be74b1SArmin Le Grand                         XGradientListSharedPtr aGradientList(XPropertyListFactory::CreateSharedXGradientList(String::CreateFromAscii("TmpList")));
333c7be74b1SArmin Le Grand 
334c7be74b1SArmin Le Grand                         aGradientList->Insert(pEntry);
335c7be74b1SArmin Le Grand                         aGradientList->SetDirty(false);
336c7be74b1SArmin Le Grand                         const Bitmap aBmp = aGradientList->GetUiBitmap(0);
337cdf0e10cSrcweir 
33897e8a929SArmin Le Grand                         if(!aBmp.IsEmpty())
339cdf0e10cSrcweir                         {
340*00467759SArmin Le Grand                             ((ListBox*)mpFillAttrLB)->InsertEntry(pEntry->GetName(),aBmp);
341*00467759SArmin Le Grand                             mpFillAttrLB->SelectEntryPos(mpFillAttrLB->GetEntryCount() - 1);
342cdf0e10cSrcweir                         }
343cdf0e10cSrcweir                     }
344cdf0e10cSrcweir                 }
345cdf0e10cSrcweir                 else
346*00467759SArmin Le Grand                 {
347*00467759SArmin Le Grand                     mpFillAttrLB->SetNoSelection();
348cdf0e10cSrcweir                 }
349cdf0e10cSrcweir                 break;
350*00467759SArmin Le Grand             }
351cdf0e10cSrcweir 
352cdf0e10cSrcweir             case XFILL_HATCH:
353cdf0e10cSrcweir             {
354*00467759SArmin Le Grand                 if(mpHatchItem)
355cdf0e10cSrcweir                 {
356*00467759SArmin Le Grand                     String aString(mpHatchItem->GetName());
357*00467759SArmin Le Grand                     mpFillAttrLB->SelectEntry(aString);
358*00467759SArmin Le Grand 
359cdf0e10cSrcweir                     // Pruefen, ob Eintrag nicht in der Liste ist
360*00467759SArmin Le Grand                     if(mpFillAttrLB->GetSelectEntry() != aString)
361cdf0e10cSrcweir                     {
362*00467759SArmin Le Grand                         sal_uInt16 nCount = mpFillAttrLB->GetEntryCount();
363cdf0e10cSrcweir                         String aTmpStr;
364cdf0e10cSrcweir                         if(nCount > 0)
365cdf0e10cSrcweir                         {
366cdf0e10cSrcweir                             //Letzter Eintrag wird auf temporaeren Eintrag geprueft
367*00467759SArmin Le Grand                             aTmpStr = mpFillAttrLB->GetEntry(nCount - 1);
368cdf0e10cSrcweir                             if(aTmpStr.GetChar(0) == TMP_STR_BEGIN &&
369cdf0e10cSrcweir                                 aTmpStr.GetChar(aTmpStr.Len() - 1) == TMP_STR_END)
370cdf0e10cSrcweir                             {
371*00467759SArmin Le Grand                                 mpFillAttrLB->RemoveEntry(nCount - 1);
372cdf0e10cSrcweir                             }
373cdf0e10cSrcweir                         }
374*00467759SArmin Le Grand 
375cdf0e10cSrcweir                         aTmpStr = TMP_STR_BEGIN;
376cdf0e10cSrcweir                         aTmpStr += aString;
377cdf0e10cSrcweir                         aTmpStr += TMP_STR_END;
378cdf0e10cSrcweir 
379*00467759SArmin Le Grand                         XHatchEntry* pEntry = new XHatchEntry(mpHatchItem->GetHatchValue(),aTmpStr);
380c7be74b1SArmin Le Grand                         XHatchListSharedPtr aHatchList(XPropertyListFactory::CreateSharedXHatchList(String::CreateFromAscii("TmpList")));
381c7be74b1SArmin Le Grand 
382c7be74b1SArmin Le Grand                         aHatchList->Insert(pEntry);
383c7be74b1SArmin Le Grand                         aHatchList->SetDirty(sal_False);
384c7be74b1SArmin Le Grand                         const Bitmap aBmp = aHatchList->GetUiBitmap(0);
385cdf0e10cSrcweir 
38697e8a929SArmin Le Grand                         if(!aBmp.IsEmpty())
387cdf0e10cSrcweir                         {
388*00467759SArmin Le Grand                             ((ListBox*)mpFillAttrLB)->InsertEntry(pEntry->GetName(),aBmp);
389*00467759SArmin Le Grand                             mpFillAttrLB->SelectEntryPos(mpFillAttrLB->GetEntryCount() - 1);
390cdf0e10cSrcweir                         }
391cdf0e10cSrcweir                     }
392cdf0e10cSrcweir                 }
393cdf0e10cSrcweir                 else
394*00467759SArmin Le Grand                 {
395*00467759SArmin Le Grand                     mpFillAttrLB->SetNoSelection();
396cdf0e10cSrcweir                 }
397cdf0e10cSrcweir                 break;
398*00467759SArmin Le Grand             }
399cdf0e10cSrcweir 
400cdf0e10cSrcweir             case XFILL_BITMAP:
401cdf0e10cSrcweir             {
402*00467759SArmin Le Grand                 if(mpBitmapItem)
403cdf0e10cSrcweir                 {
404*00467759SArmin Le Grand                     String aString(mpBitmapItem->GetName());
405*00467759SArmin Le Grand                     mpFillAttrLB->SelectEntry(aString);
406cdf0e10cSrcweir 
407cdf0e10cSrcweir                     // Pruefen, ob Eintrag nicht in der Liste ist
408*00467759SArmin Le Grand                     if(mpFillAttrLB->GetSelectEntry() != aString)
409cdf0e10cSrcweir                     {
410*00467759SArmin Le Grand                         sal_uInt16 nCount = mpFillAttrLB->GetEntryCount();
411cdf0e10cSrcweir                         String aTmpStr;
412*00467759SArmin Le Grand 
413cdf0e10cSrcweir                         if(nCount > 0)
414cdf0e10cSrcweir                         {
415cdf0e10cSrcweir                             //Letzter Eintrag wird auf temporaeren Eintrag geprueft
416*00467759SArmin Le Grand                             aTmpStr = mpFillAttrLB->GetEntry(nCount - 1);
417*00467759SArmin Le Grand 
418*00467759SArmin Le Grand                             if(aTmpStr.GetChar(0) == TMP_STR_BEGIN && aTmpStr.GetChar(aTmpStr.Len() - 1) == TMP_STR_END)
419cdf0e10cSrcweir                             {
420*00467759SArmin Le Grand                                 mpFillAttrLB->RemoveEntry(nCount - 1);
421cdf0e10cSrcweir                             }
422cdf0e10cSrcweir                         }
423*00467759SArmin Le Grand 
424cdf0e10cSrcweir                         aTmpStr = TMP_STR_BEGIN;
425cdf0e10cSrcweir                         aTmpStr += aString;
426cdf0e10cSrcweir                         aTmpStr += TMP_STR_END;
427cdf0e10cSrcweir 
428c7be74b1SArmin Le Grand                         XBitmapListSharedPtr aNew(XPropertyListFactory::CreateSharedXBitmapList(String::CreateFromAscii("TmpList")));
429*00467759SArmin Le Grand                         aNew->Insert(new XBitmapEntry(mpBitmapItem->GetGraphicObject(),aTmpStr));
430c7be74b1SArmin Le Grand                         aNew->SetDirty(false);
431c7be74b1SArmin Le Grand 
432*00467759SArmin Le Grand                         mpFillAttrLB->Fill(aNew);
433*00467759SArmin Le Grand                         mpFillAttrLB->SelectEntryPos(mpFillAttrLB->GetEntryCount() - 1);
434cdf0e10cSrcweir                     }
435cdf0e10cSrcweir                 }
436cdf0e10cSrcweir                 else
437*00467759SArmin Le Grand                 {
438*00467759SArmin Le Grand                     mpFillAttrLB->SetNoSelection();
439cdf0e10cSrcweir                 }
440cdf0e10cSrcweir                 break;
441*00467759SArmin Le Grand             }
442cdf0e10cSrcweir 
443cdf0e10cSrcweir             default:
444*00467759SArmin Le Grand             {
445cdf0e10cSrcweir                 DBG_ERROR("Nicht unterstuetzter Flaechentyp");
446cdf0e10cSrcweir                 break;
447cdf0e10cSrcweir             }
448cdf0e10cSrcweir         }
449cdf0e10cSrcweir 
450*00467759SArmin Le Grand         // update mnLastFillAttrControlSelectEntryPos
451*00467759SArmin Le Grand         mpFillControl->updateLastFillAttrControlSelectEntryPos();
452*00467759SArmin Le Grand     }
453*00467759SArmin Le Grand 
454*00467759SArmin Le Grand     if(pState && mpStyleItem)
455cdf0e10cSrcweir     {
456*00467759SArmin Le Grand         XFillStyle eXFS = static_cast< XFillStyle >(mpStyleItem->GetValue());
457cdf0e10cSrcweir 
458cdf0e10cSrcweir         // Die Listen haben sich geaendert ?
459*00467759SArmin Le Grand         switch(eXFS)
460cdf0e10cSrcweir         {
461*00467759SArmin Le Grand             case XFILL_SOLID:
462*00467759SArmin Le Grand             {
463*00467759SArmin Le Grand                 const SvxColorTableItem* pItem = dynamic_cast< const SvxColorTableItem* >(pState);
464*00467759SArmin Le Grand 
465*00467759SArmin Le Grand                 if(pItem)
466*00467759SArmin Le Grand                 {
467*00467759SArmin Le Grand                     ::Color aTmpColor(mpFillAttrLB->GetSelectEntryColor());
468*00467759SArmin Le Grand                     mpFillAttrLB->Clear();
469*00467759SArmin Le Grand                     mpFillAttrLB->Fill(pItem->GetColorTable());
470*00467759SArmin Le Grand                     mpFillAttrLB->SelectEntry(aTmpColor);
471cdf0e10cSrcweir                 }
472*00467759SArmin Le Grand                 break;
473cdf0e10cSrcweir             }
474*00467759SArmin Le Grand             case XFILL_GRADIENT:
475cdf0e10cSrcweir             {
476*00467759SArmin Le Grand                 const SvxGradientListItem* pItem = dynamic_cast< const SvxGradientListItem* >(pState);
477*00467759SArmin Le Grand 
478*00467759SArmin Le Grand                 if(pItem)
479*00467759SArmin Le Grand                 {
480*00467759SArmin Le Grand                     String aString(mpFillAttrLB->GetSelectEntry());
481*00467759SArmin Le Grand                     mpFillAttrLB->Clear();
482*00467759SArmin Le Grand                     mpFillAttrLB->Fill(pItem->GetGradientList());
483*00467759SArmin Le Grand                     mpFillAttrLB->SelectEntry(aString);
484cdf0e10cSrcweir                 }
485*00467759SArmin Le Grand                 break;
486*00467759SArmin Le Grand             }
487*00467759SArmin Le Grand             case XFILL_HATCH:
488cdf0e10cSrcweir             {
489*00467759SArmin Le Grand                 const SvxHatchListItem* pItem = dynamic_cast< const SvxHatchListItem* >(pState);
490*00467759SArmin Le Grand 
491*00467759SArmin Le Grand                 if(pItem)
492*00467759SArmin Le Grand                 {
493*00467759SArmin Le Grand                     String aString(mpFillAttrLB->GetSelectEntry());
494*00467759SArmin Le Grand                     mpFillAttrLB->Clear();
495*00467759SArmin Le Grand                     mpFillAttrLB->Fill(pItem->GetHatchList());
496*00467759SArmin Le Grand                     mpFillAttrLB->SelectEntry(aString);
497*00467759SArmin Le Grand                 }
498*00467759SArmin Le Grand                 break;
499*00467759SArmin Le Grand             }
500*00467759SArmin Le Grand             case XFILL_BITMAP:
501*00467759SArmin Le Grand             {
502*00467759SArmin Le Grand                 const SvxBitmapListItem* pItem = dynamic_cast< const SvxBitmapListItem* >(pState);
503*00467759SArmin Le Grand 
504*00467759SArmin Le Grand                 if(pItem)
505*00467759SArmin Le Grand                 {
506*00467759SArmin Le Grand                     String aString(mpFillAttrLB->GetSelectEntry());
507*00467759SArmin Le Grand                     mpFillAttrLB->Clear();
508*00467759SArmin Le Grand                     mpFillAttrLB->Fill(pItem->GetBitmapList());
509*00467759SArmin Le Grand                     mpFillAttrLB->SelectEntry(aString);
510*00467759SArmin Le Grand                 }
511*00467759SArmin Le Grand                 break;
512*00467759SArmin Le Grand             }
513*00467759SArmin Le Grand             default: // XFILL_NONE
514*00467759SArmin Le Grand             {
515*00467759SArmin Le Grand                 break;
516*00467759SArmin Le Grand             }
517cdf0e10cSrcweir         }
518cdf0e10cSrcweir     }
519cdf0e10cSrcweir }
520cdf0e10cSrcweir 
521cdf0e10cSrcweir //========================================================================
522cdf0e10cSrcweir 
CreateItemWindow(Window * pParent)523cdf0e10cSrcweir Window* SvxFillToolBoxControl::CreateItemWindow(Window *pParent)
524cdf0e10cSrcweir {
525cdf0e10cSrcweir     if(GetSlotId() == SID_ATTR_FILL_STYLE)
526cdf0e10cSrcweir     {
527*00467759SArmin Le Grand         mpFillControl = new FillControl(pParent);
528cdf0e10cSrcweir         // Damit dem FillControl das SvxFillToolBoxControl bekannt ist
529cdf0e10cSrcweir         // (und um kompatibel zu bleiben)
530*00467759SArmin Le Grand         mpFillControl->SetData(this);
531cdf0e10cSrcweir 
532*00467759SArmin Le Grand         mpFillAttrLB = (SvxFillAttrBox*)mpFillControl->mpLbFillAttr;
533*00467759SArmin Le Grand         mpFillTypeLB = (SvxFillTypeBox*)mpFillControl->mpLbFillType;
534cdf0e10cSrcweir 
535*00467759SArmin Le Grand         mpFillAttrLB->SetUniqueId(HID_FILL_ATTR_LISTBOX);
536*00467759SArmin Le Grand         mpFillTypeLB->SetUniqueId(HID_FILL_TYPE_LISTBOX);
537cdf0e10cSrcweir 
538*00467759SArmin Le Grand         if(!mpStyleItem)
539*00467759SArmin Le Grand         {
540*00467759SArmin Le Grand             // for Writer and Calc it's not the same instance of
541*00467759SArmin Le Grand             // SvxFillToolBoxControl which gets used after deselecting
542*00467759SArmin Le Grand             // and selecting a DrawObject, thhus a useful initialization is
543*00467759SArmin Le Grand             // needed to get the FillType and the FillStyle List inited
544*00467759SArmin Le Grand             // correctly. This in combination with meLastXFS inited to
545*00467759SArmin Le Grand             // XFILL_NONE do the trick
546*00467759SArmin Le Grand             mpStyleItem = new XFillStyleItem(XFILL_SOLID);
547*00467759SArmin Le Grand         }
548*00467759SArmin Le Grand 
549*00467759SArmin Le Grand         return mpFillControl;
550cdf0e10cSrcweir     }
551cdf0e10cSrcweir     return NULL;
552cdf0e10cSrcweir }
553cdf0e10cSrcweir 
554cdf0e10cSrcweir /*************************************************************************
555cdf0e10cSrcweir |*
556cdf0e10cSrcweir |* FillControl
557cdf0e10cSrcweir |*
558cdf0e10cSrcweir \************************************************************************/
559cdf0e10cSrcweir 
FillControl(Window * pParent,WinBits nStyle)560*00467759SArmin Le Grand FillControl::FillControl(Window* pParent,WinBits nStyle)
561*00467759SArmin Le Grand :   Window(pParent,nStyle | WB_DIALOGCONTROL),
562*00467759SArmin Le Grand     mpLbFillType(new SvxFillTypeBox(this)),
563*00467759SArmin Le Grand     mpLbFillAttr(new SvxFillAttrBox(this)),
564*00467759SArmin Le Grand     maLogicalFillSize(40,80),
565*00467759SArmin Le Grand     maLogicalAttrSize(50,80),
566*00467759SArmin Le Grand     mnLastFillTypeControlSelectEntryPos(mpLbFillType->GetSelectEntryPos()),
567*00467759SArmin Le Grand     mnLastFillAttrControlSelectEntryPos(mpLbFillAttr->GetSelectEntryPos()),
568*00467759SArmin Le Grand     mbFillTypeChanged(false)
569cdf0e10cSrcweir {
570*00467759SArmin Le Grand     Size aTypeSize(LogicToPixel(maLogicalFillSize,MAP_APPFONT));
571*00467759SArmin Le Grand     Size aAttrSize(LogicToPixel(maLogicalAttrSize,MAP_APPFONT));
572*00467759SArmin Le Grand     mpLbFillType->SetSizePixel(aTypeSize);
573*00467759SArmin Le Grand     mpLbFillAttr->SetSizePixel(aAttrSize);
574*00467759SArmin Le Grand 
575cdf0e10cSrcweir     //to get the base height
576*00467759SArmin Le Grand     aTypeSize = mpLbFillType->GetSizePixel();
577*00467759SArmin Le Grand     aAttrSize = mpLbFillAttr->GetSizePixel();
578*00467759SArmin Le Grand     Point aAttrPnt = mpLbFillAttr->GetPosPixel();
579cdf0e10cSrcweir     SetSizePixel(
580cdf0e10cSrcweir         Size(aAttrPnt.X() + aAttrSize.Width(),
581cdf0e10cSrcweir         Max(aAttrSize.Height(),aTypeSize.Height())));
582cdf0e10cSrcweir 
583*00467759SArmin Le Grand     mpLbFillType->SetSelectHdl(LINK(this,FillControl,SelectFillTypeHdl));
584*00467759SArmin Le Grand     mpLbFillAttr->SetSelectHdl(LINK(this,FillControl,SelectFillAttrHdl));
585cdf0e10cSrcweir }
586cdf0e10cSrcweir 
587cdf0e10cSrcweir //------------------------------------------------------------------------
588cdf0e10cSrcweir 
~FillControl()589cdf0e10cSrcweir FillControl::~FillControl()
590cdf0e10cSrcweir {
591*00467759SArmin Le Grand     delete mpLbFillType;
592*00467759SArmin Le Grand     delete mpLbFillAttr;
593cdf0e10cSrcweir }
594cdf0e10cSrcweir 
595cdf0e10cSrcweir //------------------------------------------------------------------------
596cdf0e10cSrcweir 
InitializeFillStyleAccordingToGivenFillType(XFillStyle aFillStyle)597*00467759SArmin Le Grand void FillControl::InitializeFillStyleAccordingToGivenFillType(XFillStyle aFillStyle)
598cdf0e10cSrcweir {
599cdf0e10cSrcweir     SfxObjectShell* pSh = SfxObjectShell::Current();
600*00467759SArmin Le Grand     bool bDone(false);
601cdf0e10cSrcweir 
602*00467759SArmin Le Grand     if(pSh)
603cdf0e10cSrcweir     {
604*00467759SArmin Le Grand         // clear in all cases, else we would risk a mix of FillStyles in the Style list
605*00467759SArmin Le Grand         mpLbFillAttr->Clear();
606cdf0e10cSrcweir 
607*00467759SArmin Le Grand         switch(aFillStyle)
608*00467759SArmin Le Grand         {
609cdf0e10cSrcweir             case XFILL_SOLID:
610cdf0e10cSrcweir             {
611*00467759SArmin Le Grand                 if(pSh->GetItem(SID_COLOR_TABLE))
612cdf0e10cSrcweir                 {
613*00467759SArmin Le Grand                     const SvxColorTableItem* pItem = static_cast< const SvxColorTableItem* >(pSh->GetItem(SID_COLOR_TABLE));
614*00467759SArmin Le Grand                     mpLbFillAttr->Enable();
615*00467759SArmin Le Grand                     mpLbFillAttr->Fill(pItem->GetColorTable());
616*00467759SArmin Le Grand                     bDone = true;
617cdf0e10cSrcweir                 }
618cdf0e10cSrcweir                 break;
619*00467759SArmin Le Grand             }
620cdf0e10cSrcweir 
621cdf0e10cSrcweir             case XFILL_GRADIENT:
622cdf0e10cSrcweir             {
623*00467759SArmin Le Grand                 if(pSh->GetItem(SID_GRADIENT_LIST))
624cdf0e10cSrcweir                 {
625*00467759SArmin Le Grand                     const SvxGradientListItem* pItem = static_cast< const SvxGradientListItem* >(pSh->GetItem(SID_GRADIENT_LIST));
626*00467759SArmin Le Grand                     mpLbFillAttr->Enable();
627*00467759SArmin Le Grand                     mpLbFillAttr->Fill(pItem->GetGradientList());
628*00467759SArmin Le Grand                     bDone = true;
629cdf0e10cSrcweir                 }
630cdf0e10cSrcweir                 break;
631*00467759SArmin Le Grand             }
632cdf0e10cSrcweir 
633cdf0e10cSrcweir             case XFILL_HATCH:
634cdf0e10cSrcweir             {
635*00467759SArmin Le Grand                 if(pSh->GetItem(SID_HATCH_LIST))
636cdf0e10cSrcweir                 {
637*00467759SArmin Le Grand                     const SvxHatchListItem* pItem = static_cast< const SvxHatchListItem* >(pSh->GetItem(SID_HATCH_LIST));
638*00467759SArmin Le Grand                     mpLbFillAttr->Enable();
639*00467759SArmin Le Grand                     mpLbFillAttr->Fill(pItem->GetHatchList());
640*00467759SArmin Le Grand                     bDone = true;
641cdf0e10cSrcweir                 }
642cdf0e10cSrcweir                 break;
643*00467759SArmin Le Grand             }
644cdf0e10cSrcweir 
645cdf0e10cSrcweir             case XFILL_BITMAP:
646cdf0e10cSrcweir             {
647*00467759SArmin Le Grand                 if(pSh->GetItem(SID_BITMAP_LIST))
648cdf0e10cSrcweir                 {
649*00467759SArmin Le Grand                     const SvxBitmapListItem* pItem = static_cast< const SvxBitmapListItem* >(pSh->GetItem(SID_BITMAP_LIST));
650*00467759SArmin Le Grand                     mpLbFillAttr->Enable();
651*00467759SArmin Le Grand                     mpLbFillAttr->Fill(pItem->GetBitmapList());
652*00467759SArmin Le Grand                     bDone = true;
653cdf0e10cSrcweir                 }
654cdf0e10cSrcweir                 break;
655cdf0e10cSrcweir             }
656*00467759SArmin Le Grand             default: // XFILL_NONE
657cdf0e10cSrcweir             {
658*00467759SArmin Le Grand                 // accept disable (no styles for XFILL_NONE)
659*00467759SArmin Le Grand                 break;
660*00467759SArmin Le Grand             }
661*00467759SArmin Le Grand         }
662*00467759SArmin Le Grand     }
663cdf0e10cSrcweir 
664*00467759SArmin Le Grand     if(!bDone)
665*00467759SArmin Le Grand     {
666*00467759SArmin Le Grand         mpLbFillAttr->Disable();
667*00467759SArmin Le Grand     }
668*00467759SArmin Le Grand }
669*00467759SArmin Le Grand 
updateLastFillTypeControlSelectEntryPos()670*00467759SArmin Le Grand void FillControl::updateLastFillTypeControlSelectEntryPos()
671*00467759SArmin Le Grand {
672*00467759SArmin Le Grand     mnLastFillTypeControlSelectEntryPos = mpLbFillType->GetSelectEntryPos();
673*00467759SArmin Le Grand }
674*00467759SArmin Le Grand 
IMPL_LINK(FillControl,SelectFillTypeHdl,ListBox *,pBox)675*00467759SArmin Le Grand IMPL_LINK(FillControl,SelectFillTypeHdl,ListBox *,pBox)
676*00467759SArmin Le Grand {
677*00467759SArmin Le Grand     if(!pBox) // only work with real calls from ListBox, do not accept direct calls with zeros here
678*00467759SArmin Le Grand     {
679*00467759SArmin Le Grand         return 0;
680*00467759SArmin Le Grand     }
681*00467759SArmin Le Grand 
682*00467759SArmin Le Grand     const bool bAction(
683*00467759SArmin Le Grand            !mpLbFillType->IsTravelSelect() // keep TravelSelect, this means keyboard up/down in the list
684*00467759SArmin Le Grand         && mpLbFillType->GetSelectEntryCount()
685*00467759SArmin Le Grand         && mpLbFillType->GetSelectEntryPos() != mnLastFillTypeControlSelectEntryPos);
686*00467759SArmin Le Grand 
687*00467759SArmin Le Grand     updateLastFillTypeControlSelectEntryPos();
688*00467759SArmin Le Grand     XFillStyle eXFS = static_cast< XFillStyle >(mpLbFillType->GetSelectEntryPos());
689*00467759SArmin Le Grand 
690*00467759SArmin Le Grand     if(bAction && XFILL_NONE != eXFS)
691*00467759SArmin Le Grand     {
692*00467759SArmin Le Grand         mbFillTypeChanged = true;
693*00467759SArmin Le Grand     }
694*00467759SArmin Le Grand 
695*00467759SArmin Le Grand     // update list of FillStyles in any case
696*00467759SArmin Le Grand     InitializeFillStyleAccordingToGivenFillType(eXFS);
697*00467759SArmin Le Grand 
698*00467759SArmin Le Grand     // for XFILL_NONE do no longer call SelectFillAttrHdl (as done before),
699*00467759SArmin Le Grand     // trigger needed actions directly. This is the only action this handler
700*00467759SArmin Le Grand     // can trigger directly as the user action is finished in this case
701*00467759SArmin Le Grand     if(XFILL_NONE == eXFS && bAction)
702*00467759SArmin Le Grand     {
703*00467759SArmin Le Grand         // for XFILL_NONE do no longer call SelectFillAttrHdl,
704*00467759SArmin Le Grand         // trigger needed actions directly
705*00467759SArmin Le Grand         Any a;
706*00467759SArmin Le Grand         Sequence< PropertyValue > aArgsFillStyle(1);
707*00467759SArmin Le Grand         XFillStyleItem aXFillStyleItem(eXFS);
708*00467759SArmin Le Grand 
709*00467759SArmin Le Grand         aArgsFillStyle[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FillStyle"));
710*00467759SArmin Le Grand         aXFillStyleItem.QueryValue(a);
711*00467759SArmin Le Grand         aArgsFillStyle[0].Value = a;
712*00467759SArmin Le Grand         ((SvxFillToolBoxControl*)GetData())->Dispatch(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:FillStyle")), aArgsFillStyle);
713*00467759SArmin Le Grand     }
714*00467759SArmin Le Grand 
715*00467759SArmin Le Grand     mpLbFillType->Selected();
716*00467759SArmin Le Grand 
717*00467759SArmin Le Grand     // release focus. Needed to get focus automatically back to EditView
718*00467759SArmin Le Grand     if(mpLbFillType->IsRelease())
719cdf0e10cSrcweir     {
720cdf0e10cSrcweir         SfxViewShell* pViewShell = SfxViewShell::Current();
721*00467759SArmin Le Grand 
722cdf0e10cSrcweir         if(pViewShell && pViewShell->GetWindow())
723*00467759SArmin Le Grand         {
724cdf0e10cSrcweir             pViewShell->GetWindow()->GrabFocus();
725cdf0e10cSrcweir         }
726cdf0e10cSrcweir     }
727*00467759SArmin Le Grand 
728cdf0e10cSrcweir     return 0;
729cdf0e10cSrcweir }
730cdf0e10cSrcweir 
731cdf0e10cSrcweir //------------------------------------------------------------------------
732cdf0e10cSrcweir 
updateLastFillAttrControlSelectEntryPos()733*00467759SArmin Le Grand void FillControl::updateLastFillAttrControlSelectEntryPos()
734*00467759SArmin Le Grand {
735*00467759SArmin Le Grand     mnLastFillAttrControlSelectEntryPos = mpLbFillAttr->GetSelectEntryPos();
736*00467759SArmin Le Grand }
737*00467759SArmin Le Grand 
IMPL_LINK(FillControl,SelectFillAttrHdl,ListBox *,pBox)738cdf0e10cSrcweir IMPL_LINK(FillControl, SelectFillAttrHdl, ListBox *, pBox)
739cdf0e10cSrcweir {
740*00467759SArmin Le Grand     if(!pBox) // only work with real calls from ListBox, do not accept direct calls with zeros here
741*00467759SArmin Le Grand     {
742*00467759SArmin Le Grand         return 0;
743*00467759SArmin Le Grand     }
744cdf0e10cSrcweir 
745*00467759SArmin Le Grand     const bool bAction(
746*00467759SArmin Le Grand            !mpLbFillAttr->IsTravelSelect() // keep TravelSelect, this means keyboard up/down in the list
747*00467759SArmin Le Grand         && mpLbFillAttr->GetSelectEntryCount()
748*00467759SArmin Le Grand         && mpLbFillAttr->GetSelectEntryPos() != mnLastFillAttrControlSelectEntryPos);
749*00467759SArmin Le Grand 
750*00467759SArmin Le Grand     updateLastFillAttrControlSelectEntryPos();
751*00467759SArmin Le Grand 
752cdf0e10cSrcweir     if(bAction)
753cdf0e10cSrcweir     {
754*00467759SArmin Le Grand         SfxObjectShell* pSh = SfxObjectShell::Current();
755cdf0e10cSrcweir 
756*00467759SArmin Le Grand         // Need to prepare the PropertyValue for the FillStyle dispatch action early,
757*00467759SArmin Le Grand         // else the call for FillType to Dispatch(".uno:FillStyle") will already destroy the current state
758*00467759SArmin Le Grand         // of selection in mpLbFillAttr again by calls to StateChanged which *will* set to no
759*00467759SArmin Le Grand         // selection again (e.g. when two objects, same fill style, but different fill attributes)
760*00467759SArmin Le Grand         Any a;
761*00467759SArmin Le Grand         Sequence< PropertyValue > aArgsFillAttr(1);
762*00467759SArmin Le Grand         ::rtl::OUString aFillAttrCommand;
763*00467759SArmin Le Grand         XFillStyle eXFS(static_cast< XFillStyle >(mpLbFillType->GetSelectEntryPos()));
764cdf0e10cSrcweir 
765cdf0e10cSrcweir         switch(eXFS)
766cdf0e10cSrcweir         {
767cdf0e10cSrcweir             case XFILL_NONE:
768cdf0e10cSrcweir             {
769*00467759SArmin Le Grand                 // handled in SelectFillTypeHdl, nothing to do here
770cdf0e10cSrcweir                 break;
771*00467759SArmin Le Grand             }
772cdf0e10cSrcweir 
773cdf0e10cSrcweir             case XFILL_SOLID:
774cdf0e10cSrcweir             {
775cdf0e10cSrcweir                 //Eintrag wird auf temporaere Farbe geprueft
776*00467759SArmin Le Grand                 String aTmpStr = mpLbFillAttr->GetSelectEntry();
777*00467759SArmin Le Grand 
778cdf0e10cSrcweir                 if(aTmpStr.GetChar(0) == TMP_STR_BEGIN && aTmpStr.GetChar(aTmpStr.Len() - 1) == TMP_STR_END)
779cdf0e10cSrcweir                 {
780cdf0e10cSrcweir                     aTmpStr.Erase(aTmpStr.Len() - 1,1);
781cdf0e10cSrcweir                     aTmpStr.Erase(0,1);
782cdf0e10cSrcweir                 }
783cdf0e10cSrcweir 
784*00467759SArmin Le Grand                 XFillColorItem aXFillColorItem(aTmpStr,mpLbFillAttr->GetSelectEntryColor());
785*00467759SArmin Le Grand                 aArgsFillAttr[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FillColor"));
786cdf0e10cSrcweir                 aXFillColorItem.QueryValue(a);
787*00467759SArmin Le Grand                 aArgsFillAttr[0].Value = a;
788*00467759SArmin Le Grand                 aFillAttrCommand = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:FillColor"));
789cdf0e10cSrcweir                 break;
790*00467759SArmin Le Grand             }
791cdf0e10cSrcweir             case XFILL_GRADIENT:
792cdf0e10cSrcweir             {
793*00467759SArmin Le Grand                 sal_uInt16 nPos = mpLbFillAttr->GetSelectEntryPos();
794cdf0e10cSrcweir 
795cdf0e10cSrcweir                 if(nPos != LISTBOX_ENTRY_NOTFOUND && pSh && pSh->GetItem(SID_GRADIENT_LIST))
796cdf0e10cSrcweir                 {
797*00467759SArmin Le Grand                     const SvxGradientListItem* pItem = static_cast< const SvxGradientListItem* >(pSh->GetItem(SID_GRADIENT_LIST));
798cdf0e10cSrcweir 
799*00467759SArmin Le Grand                     if(nPos < pItem->GetGradientList()->Count())  // kein temp. Eintrag ?
800cdf0e10cSrcweir                     {
801*00467759SArmin Le Grand                         XGradient aGradient = pItem->GetGradientList()->GetGradient(nPos)->GetGradient();
802*00467759SArmin Le Grand                         XFillGradientItem aXFillGradientItem(mpLbFillAttr->GetSelectEntry(),aGradient);
803*00467759SArmin Le Grand                         aArgsFillAttr[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FillGradient"));
804cdf0e10cSrcweir                         aXFillGradientItem.QueryValue(a);
805*00467759SArmin Le Grand                         aArgsFillAttr[0].Value = a;
806*00467759SArmin Le Grand                         aFillAttrCommand = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:FillGradient"));
807cdf0e10cSrcweir                     }
808cdf0e10cSrcweir                 }
809cdf0e10cSrcweir                 break;
810*00467759SArmin Le Grand             }
811cdf0e10cSrcweir 
812cdf0e10cSrcweir             case XFILL_HATCH:
813cdf0e10cSrcweir             {
814*00467759SArmin Le Grand                 sal_uInt16 nPos = mpLbFillAttr->GetSelectEntryPos();
815cdf0e10cSrcweir 
816cdf0e10cSrcweir                 if(nPos != LISTBOX_ENTRY_NOTFOUND && pSh && pSh->GetItem(SID_HATCH_LIST))
817cdf0e10cSrcweir                 {
818*00467759SArmin Le Grand                     const SvxHatchListItem* pItem = static_cast< const SvxHatchListItem* >(pSh->GetItem(SID_HATCH_LIST));
819cdf0e10cSrcweir 
820*00467759SArmin Le Grand                     if(nPos < pItem->GetHatchList()->Count())  // kein temp. Eintrag ?
821cdf0e10cSrcweir                     {
822*00467759SArmin Le Grand                         XHatch aHatch = pItem->GetHatchList()->GetHatch(nPos)->GetHatch();
823*00467759SArmin Le Grand                         XFillHatchItem aXFillHatchItem(mpLbFillAttr->GetSelectEntry(),aHatch);
824cdf0e10cSrcweir 
825*00467759SArmin Le Grand                         aArgsFillAttr[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FillHatch"));
826cdf0e10cSrcweir                         aXFillHatchItem.QueryValue(a);
827*00467759SArmin Le Grand                         aArgsFillAttr[0].Value = a;
828*00467759SArmin Le Grand                         aFillAttrCommand = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:FillHatch"));
829cdf0e10cSrcweir                     }
830cdf0e10cSrcweir                 }
831cdf0e10cSrcweir                 break;
832*00467759SArmin Le Grand             }
833cdf0e10cSrcweir 
834cdf0e10cSrcweir             case XFILL_BITMAP:
835cdf0e10cSrcweir             {
836*00467759SArmin Le Grand                 sal_uInt16 nPos = mpLbFillAttr->GetSelectEntryPos();
837cdf0e10cSrcweir 
838cdf0e10cSrcweir                 if(nPos != LISTBOX_ENTRY_NOTFOUND && pSh && pSh->GetItem(SID_BITMAP_LIST))
839cdf0e10cSrcweir                 {
840*00467759SArmin Le Grand                     const SvxBitmapListItem* pItem = static_cast< const SvxBitmapListItem* >(pSh->GetItem(SID_BITMAP_LIST));
841cdf0e10cSrcweir 
842*00467759SArmin Le Grand                     if(nPos < pItem->GetBitmapList()->Count())  // kein temp. Eintrag ?
843cdf0e10cSrcweir                     {
844*00467759SArmin Le Grand                         const XBitmapEntry* pXBitmapEntry = pItem->GetBitmapList()->GetBitmap(nPos);
845*00467759SArmin Le Grand                         const XFillBitmapItem aXFillBitmapItem(mpLbFillAttr->GetSelectEntry(),pXBitmapEntry->GetGraphicObject());
846cdf0e10cSrcweir 
847*00467759SArmin Le Grand                         aArgsFillAttr[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FillBitmap"));
848cdf0e10cSrcweir                         aXFillBitmapItem.QueryValue(a);
849*00467759SArmin Le Grand                         aArgsFillAttr[0].Value = a;
850*00467759SArmin Le Grand                         aFillAttrCommand = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:FillBitmap"));
851cdf0e10cSrcweir                     }
852cdf0e10cSrcweir                 }
853cdf0e10cSrcweir                 break;
854cdf0e10cSrcweir             }
855*00467759SArmin Le Grand         }
856cdf0e10cSrcweir 
857*00467759SArmin Le Grand         // this is the place where evtl. a new slot action may be introduced to avoid the
858*00467759SArmin Le Grand         // two undo entries. Reason for this is that indeed two actions are executed, the fill style
859*00467759SArmin Le Grand         // and the fill attribute change. The sidebar already handles both separately, so
860*00467759SArmin Le Grand         // changing the fill style already changes the object and adds a default fill attribute for
861*00467759SArmin Le Grand         // the newly choosen fill style.
862*00467759SArmin Le Grand         // This control uses the older user's two-step action to select a fill style and a fill attribute. In
863*00467759SArmin Le Grand         // this case a lot of things may go wrong (e.g. the user stops that action and does something
864*00467759SArmin Le Grand         // different), thus the solution of the sidebar should be preferred from my POV in the future
865*00467759SArmin Le Grand 
866*00467759SArmin Le Grand         // first set the fill style if changed
867*00467759SArmin Le Grand         if(mbFillTypeChanged)
868*00467759SArmin Le Grand         {
869*00467759SArmin Le Grand             Sequence< PropertyValue > aArgsFillStyle(1);
870*00467759SArmin Le Grand             XFillStyleItem aXFillStyleItem(eXFS);
871*00467759SArmin Le Grand 
872*00467759SArmin Le Grand             aArgsFillStyle[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FillStyle"));
873*00467759SArmin Le Grand             aXFillStyleItem.QueryValue(a);
874*00467759SArmin Le Grand             aArgsFillStyle[0].Value = a;
875*00467759SArmin Le Grand             ((SvxFillToolBoxControl*)GetData())->Dispatch(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:FillStyle")), aArgsFillStyle);
876*00467759SArmin Le Grand             mbFillTypeChanged = false;
877*00467759SArmin Le Grand         }
878*00467759SArmin Le Grand 
879*00467759SArmin Le Grand         // second set fill attribute when a change was detected and prepared
880*00467759SArmin Le Grand         if(aFillAttrCommand.getLength())
881*00467759SArmin Le Grand         {
882*00467759SArmin Le Grand             ((SvxFillToolBoxControl*)GetData())->Dispatch(aFillAttrCommand, aArgsFillAttr);
883*00467759SArmin Le Grand         }
884*00467759SArmin Le Grand 
885*00467759SArmin Le Grand         // release focus. Needed to get focus automatically back to EditView
886*00467759SArmin Le Grand         if(mpLbFillAttr->IsRelease() && pBox)
887cdf0e10cSrcweir         {
888cdf0e10cSrcweir             SfxViewShell* pViewShell = SfxViewShell::Current();
889*00467759SArmin Le Grand 
890cdf0e10cSrcweir             if(pViewShell && pViewShell->GetWindow())
891cdf0e10cSrcweir             {
892cdf0e10cSrcweir                 pViewShell->GetWindow()->GrabFocus();
893cdf0e10cSrcweir             }
894cdf0e10cSrcweir         }
895cdf0e10cSrcweir     }
896cdf0e10cSrcweir 
897cdf0e10cSrcweir     return 0;
898cdf0e10cSrcweir }
899cdf0e10cSrcweir 
900cdf0e10cSrcweir //------------------------------------------------------------------------
901cdf0e10cSrcweir 
Resize()902cdf0e10cSrcweir void FillControl::Resize()
903cdf0e10cSrcweir {
904cdf0e10cSrcweir     // Breite der beiden ListBoxen nicht 1/2 : 1/2, sondern 2/5 : 3/5
905cdf0e10cSrcweir     long nW = GetOutputSizePixel().Width() / 5;
906cdf0e10cSrcweir     long nH = 180;
907cdf0e10cSrcweir     long nSep = 0; // war vorher 4
908cdf0e10cSrcweir 
909*00467759SArmin Le Grand     mpLbFillType->SetSizePixel(Size(nW * 2 - nSep,nH));
910*00467759SArmin Le Grand     mpLbFillAttr->SetPosSizePixel(Point(nW * 2 + nSep,0),Size(nW * 3 - nSep,nH));
911cdf0e10cSrcweir }
912cdf0e10cSrcweir 
913*00467759SArmin Le Grand //------------------------------------------------------------------------
914cdf0e10cSrcweir 
DataChanged(const DataChangedEvent & rDCEvt)915cdf0e10cSrcweir void FillControl::DataChanged(const DataChangedEvent& rDCEvt)
916cdf0e10cSrcweir {
917cdf0e10cSrcweir     if((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
918cdf0e10cSrcweir         (rDCEvt.GetFlags() & SETTINGS_STYLE))
919cdf0e10cSrcweir     {
920*00467759SArmin Le Grand         Size aTypeSize(LogicToPixel(maLogicalFillSize,MAP_APPFONT));
921*00467759SArmin Le Grand         Size aAttrSize(LogicToPixel(maLogicalAttrSize,MAP_APPFONT));
922*00467759SArmin Le Grand         mpLbFillType->SetSizePixel(aTypeSize);
923*00467759SArmin Le Grand         mpLbFillAttr->SetSizePixel(aAttrSize);
924*00467759SArmin Le Grand 
925cdf0e10cSrcweir         //to get the base height
926*00467759SArmin Le Grand         aTypeSize = mpLbFillType->GetSizePixel();
927*00467759SArmin Le Grand         aAttrSize = mpLbFillAttr->GetSizePixel();
928*00467759SArmin Le Grand         Point aAttrPnt = mpLbFillAttr->GetPosPixel();
929cdf0e10cSrcweir 
930cdf0e10cSrcweir         SetSizePixel(
931cdf0e10cSrcweir             Size(aAttrPnt.X() + aAttrSize.Width(),
932cdf0e10cSrcweir             Max(aAttrSize.Height(),aTypeSize.Height())));
933cdf0e10cSrcweir     }
934cdf0e10cSrcweir     Window::DataChanged(rDCEvt);
935cdf0e10cSrcweir }
936cdf0e10cSrcweir 
937*00467759SArmin Le Grand //------------------------------------------------------------------------
938*00467759SArmin Le Grand //eof
939