xref: /trunk/main/svx/source/tbxctrls/fillctrl.cxx (revision 00467759)
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
10f6e50924SAndrew Rist  *
11f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12f6e50924SAndrew Rist  *
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.
19f6e50924SAndrew Rist  *
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)
101*00467759SArmin Le Grand {
102*00467759SArmin Le Grand     bool bEnableControls(false);
103*00467759SArmin Le Grand 
104*00467759SArmin Le Grand     if(eState == SFX_ITEM_DISABLED)
105*00467759SArmin Le Grand     {
106*00467759SArmin Le Grand         // slot disable state
107*00467759SArmin Le Grand         if(nSID == SID_ATTR_FILL_STYLE)
108*00467759SArmin Le Grand         {
109*00467759SArmin Le Grand             mpFillTypeLB->Disable();
110*00467759SArmin Le Grand             mpFillTypeLB->SetNoSelection();
111*00467759SArmin Le Grand         }
112cdf0e10cSrcweir 
113*00467759SArmin Le Grand         mpFillAttrLB->Disable();
114*00467759SArmin Le Grand         mpFillAttrLB->SetNoSelection();
115*00467759SArmin Le Grand     }
116*00467759SArmin Le Grand     else if(SFX_ITEM_AVAILABLE == eState)
117*00467759SArmin Le Grand     {
118*00467759SArmin Le Grand         // slot available state
119*00467759SArmin Le Grand         if(nSID == SID_ATTR_FILL_STYLE)
120*00467759SArmin Le Grand         {
121*00467759SArmin Le Grand             delete mpStyleItem;
122*00467759SArmin Le Grand             mpStyleItem = static_cast< XFillStyleItem* >(pState->Clone());
123*00467759SArmin Le Grand             mpFillTypeLB->Enable();
124*00467759SArmin Le Grand         }
125*00467759SArmin Le Grand         else if(mpStyleItem)
126*00467759SArmin Le Grand         {
127*00467759SArmin Le Grand             const XFillStyle eXFS(static_cast< XFillStyle >(mpStyleItem->GetValue()));
128cdf0e10cSrcweir 
129*00467759SArmin Le Grand             if(nSID == SID_ATTR_FILL_COLOR)
1308f1fbbb1SArmin Le Grand             {
131*00467759SArmin Le Grand                 delete mpColorItem;
132*00467759SArmin Le Grand                 mpColorItem = static_cast< XFillColorItem* >(pState->Clone());
133*00467759SArmin Le Grand 
134*00467759SArmin Le Grand                 if(eXFS == XFILL_SOLID)
1358f1fbbb1SArmin Le Grand                 {
136*00467759SArmin Le Grand                     bEnableControls = true;
1378f1fbbb1SArmin Le Grand                 }
138*00467759SArmin Le Grand             }
139*00467759SArmin Le Grand             else if(nSID == SID_ATTR_FILL_GRADIENT)
140*00467759SArmin Le Grand             {
141*00467759SArmin Le Grand                 delete mpGradientItem;
142*00467759SArmin Le Grand                 mpGradientItem = static_cast< XFillGradientItem* >(pState->Clone());
1438f1fbbb1SArmin Le Grand 
144*00467759SArmin Le Grand                 if(eXFS == XFILL_GRADIENT)
145*00467759SArmin Le Grand                 {
146*00467759SArmin Le Grand                     bEnableControls = true;
147*00467759SArmin Le Grand                 }
1488f1fbbb1SArmin Le Grand             }
149*00467759SArmin Le Grand             else if(nSID == SID_ATTR_FILL_HATCH)
150*00467759SArmin Le Grand             {
151*00467759SArmin Le Grand                 delete mpHatchItem;
152*00467759SArmin Le Grand                 mpHatchItem = static_cast< XFillHatchItem* >(pState->Clone());
1538f1fbbb1SArmin Le Grand 
154*00467759SArmin Le Grand                 if(eXFS == XFILL_HATCH)
155*00467759SArmin Le Grand                 {
156*00467759SArmin Le Grand                     bEnableControls = true;
157*00467759SArmin Le Grand                 }
158*00467759SArmin Le Grand             }
159*00467759SArmin Le Grand             else if(nSID == SID_ATTR_FILL_BITMAP)
160*00467759SArmin Le Grand             {
161*00467759SArmin Le Grand                 delete mpBitmapItem;
162*00467759SArmin Le Grand                 mpBitmapItem = static_cast< XFillBitmapItem* >(pState->Clone());
163cdf0e10cSrcweir 
164*00467759SArmin Le Grand                 if(eXFS == XFILL_BITMAP)
165*00467759SArmin Le Grand                 {
166*00467759SArmin Le Grand                     bEnableControls = true;
167*00467759SArmin Le Grand                 }
168*00467759SArmin Le Grand             }
169cdf0e10cSrcweir         }
170*00467759SArmin 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();
190*00467759SArmin Le Grand         }
191*00467759SArmin Le Grand 
192*00467759SArmin Le Grand         if(bEnableControls)
193*00467759SArmin Le Grand         {
194*00467759SArmin Le Grand             mpFillAttrLB->Enable();
195*00467759SArmin Le Grand             mbUpdate = true;
196*00467759SArmin Le Grand         }
197*00467759SArmin Le Grand 
198*00467759SArmin Le Grand         Update(pState);
199*00467759SArmin Le Grand     }
200*00467759SArmin Le Grand     else
201*00467759SArmin Le Grand     {
202*00467759SArmin Le Grand         // slot empty or ambigous
203*00467759SArmin Le Grand         if(nSID == SID_ATTR_FILL_STYLE)
204*00467759SArmin Le Grand         {
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;
211*00467759SArmin Le Grand         }
212*00467759SArmin Le Grand         else
213*00467759SArmin Le Grand         {
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 ||
222*00467759SArmin Le Grand                 (nSID == SID_ATTR_FILL_COLOR && eXFS == XFILL_SOLID) ||
223*00467759SArmin Le Grand                 (nSID == SID_ATTR_FILL_GRADIENT && eXFS == XFILL_GRADIENT) ||
224*00467759SArmin Le Grand                 (nSID == SID_ATTR_FILL_HATCH && eXFS == XFILL_HATCH) ||
225*00467759SArmin Le Grand                 (nSID == SID_ATTR_FILL_BITMAP && eXFS == XFILL_BITMAP))
226*00467759SArmin Le Grand             {
227*00467759SArmin Le Grand                 mpFillAttrLB->SetNoSelection();
228*00467759SArmin Le Grand             }
229*00467759SArmin Le Grand         }
230*00467759SArmin Le Grand     }
231cdf0e10cSrcweir }
232cdf0e10cSrcweir 
233cdf0e10cSrcweir //========================================================================
234cdf0e10cSrcweir 
Update(const SfxPoolItem * pState)235*00467759SArmin Le Grand void SvxFillToolBoxControl::Update(const SfxPoolItem* pState)
236cdf0e10cSrcweir {
237*00467759SArmin Le Grand     if(mpStyleItem && pState && mbUpdate)
238*00467759SArmin Le Grand     {
239*00467759SArmin Le Grand         mbUpdate = false;
240*00467759SArmin Le Grand         const XFillStyle eXFS(static_cast< XFillStyle >(mpStyleItem->GetValue()));
241*00467759SArmin Le Grand 
242*00467759SArmin Le Grand         // 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         }
250*00467759SArmin Le Grand 
251*00467759SArmin Le Grand         switch(eXFS)
252*00467759SArmin Le Grand         {
253*00467759SArmin Le Grand             case XFILL_NONE:
254*00467759SArmin Le Grand             {
255*00467759SArmin Le Grand                 break;
256*00467759SArmin Le Grand             }
257*00467759SArmin Le Grand 
258*00467759SArmin Le Grand             case XFILL_SOLID:
259*00467759SArmin Le Grand             {
260*00467759SArmin Le Grand                 if(mpColorItem)
261*00467759SArmin Le Grand                 {
262*00467759SArmin Le Grand                     String aString(mpColorItem->GetName());
263*00467759SArmin Le Grand                     ::Color aColor = mpColorItem->GetColorValue();
264*00467759SArmin Le Grand 
265*00467759SArmin Le Grand                     mpFillAttrLB->SelectEntry(aString);
266*00467759SArmin Le Grand 
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                     }
271*00467759SArmin Le Grand 
272*00467759SArmin Le Grand                     // Pruefen, ob Eintrag nicht in der Liste ist
273*00467759SArmin Le Grand                     if(mpFillAttrLB->GetSelectEntryPos() == LISTBOX_ENTRY_NOTFOUND || mpFillAttrLB->GetSelectEntryColor() != aColor)
274*00467759SArmin Le Grand                     {
275*00467759SArmin Le Grand                         sal_uInt16 nCount = mpFillAttrLB->GetEntryCount();
276*00467759SArmin Le Grand                         String aTmpStr;
277*00467759SArmin Le Grand                         if(nCount > 0)
278*00467759SArmin Le Grand                         {
279*00467759SArmin Le Grand                             //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)
283*00467759SArmin Le Grand                             {
284*00467759SArmin Le Grand                                 mpFillAttrLB->RemoveEntry(nCount - 1);
285*00467759SArmin Le Grand                             }
286*00467759SArmin Le Grand                         }
287*00467759SArmin Le Grand 
288*00467759SArmin Le Grand                         aTmpStr = TMP_STR_BEGIN;
289*00467759SArmin Le Grand                         aTmpStr += aString;
290*00467759SArmin Le Grand                         aTmpStr += TMP_STR_END;
291*00467759SArmin Le Grand 
292*00467759SArmin Le Grand                         sal_uInt16 nPos = mpFillAttrLB->InsertEntry(aColor,aTmpStr);
293*00467759SArmin Le Grand                         mpFillAttrLB->SelectEntryPos(nPos);
294*00467759SArmin Le Grand                     }
295*00467759SArmin Le Grand                 }
296*00467759SArmin Le Grand                 else
297*00467759SArmin Le Grand                 {
298*00467759SArmin Le Grand                     mpFillAttrLB->SetNoSelection();
299*00467759SArmin Le Grand                 }
300*00467759SArmin Le Grand                 break;
301*00467759SArmin Le Grand             }
302*00467759SArmin Le Grand 
303*00467759SArmin Le Grand             case XFILL_GRADIENT:
304*00467759SArmin Le Grand             {
305*00467759SArmin Le Grand                 if(mpGradientItem)
306*00467759SArmin Le Grand                 {
307*00467759SArmin Le Grand                     String aString(mpGradientItem->GetName());
308*00467759SArmin Le Grand                     mpFillAttrLB->SelectEntry(aString);
309*00467759SArmin Le Grand 
310*00467759SArmin Le Grand                     // Pruefen, ob Eintrag nicht in der Liste ist
311*00467759SArmin Le Grand                     if(mpFillAttrLB->GetSelectEntry() != aString)
312*00467759SArmin Le Grand                     {
313*00467759SArmin Le Grand                         sal_uInt16 nCount = mpFillAttrLB->GetEntryCount();
314*00467759SArmin Le Grand                         String aTmpStr;
315*00467759SArmin Le Grand 
316*00467759SArmin Le Grand                         if(nCount > 0)
317*00467759SArmin Le Grand                         {
318*00467759SArmin Le Grand                             //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)
322*00467759SArmin Le Grand                             {
323*00467759SArmin Le Grand                                 mpFillAttrLB->RemoveEntry(nCount - 1);
324*00467759SArmin Le Grand                             }
325*00467759SArmin Le Grand                         }
326*00467759SArmin Le Grand 
327*00467759SArmin Le Grand                         aTmpStr = TMP_STR_BEGIN;
328*00467759SArmin Le Grand                         aTmpStr += aString;
329*00467759SArmin Le Grand                         aTmpStr += TMP_STR_END;
330*00467759SArmin Le Grand 
331*00467759SArmin Le Grand                         XGradientEntry* pEntry = new XGradientEntry(mpGradientItem->GetGradientValue(),aTmpStr);
332c7be74b1SArmin Le Grand                         XGradientListSharedPtr aGradientList(XPropertyListFactory::CreateSharedXGradientList(String::CreateFromAscii("TmpList")));
333*00467759SArmin Le Grand 
334c7be74b1SArmin Le Grand                         aGradientList->Insert(pEntry);
335*00467759SArmin Le Grand                         aGradientList->SetDirty(false);
336*00467759SArmin Le Grand                         const Bitmap aBmp = aGradientList->GetUiBitmap(0);
337*00467759SArmin Le Grand 
338*00467759SArmin Le Grand                         if(!aBmp.IsEmpty())
339*00467759SArmin Le Grand                         {
340*00467759SArmin Le Grand                             ((ListBox*)mpFillAttrLB)->InsertEntry(pEntry->GetName(),aBmp);
341*00467759SArmin Le Grand                             mpFillAttrLB->SelectEntryPos(mpFillAttrLB->GetEntryCount() - 1);
342*00467759SArmin Le Grand                         }
343*00467759SArmin Le Grand                     }
344*00467759SArmin Le Grand                 }
345*00467759SArmin Le Grand                 else
346*00467759SArmin Le Grand                 {
347*00467759SArmin Le Grand                     mpFillAttrLB->SetNoSelection();
348*00467759SArmin Le Grand                 }
349*00467759SArmin Le Grand                 break;
350*00467759SArmin Le Grand             }
351*00467759SArmin Le Grand 
352*00467759SArmin Le Grand             case XFILL_HATCH:
353*00467759SArmin Le Grand             {
354*00467759SArmin Le Grand                 if(mpHatchItem)
355*00467759SArmin Le Grand                 {
356*00467759SArmin Le Grand                     String aString(mpHatchItem->GetName());
357*00467759SArmin Le Grand                     mpFillAttrLB->SelectEntry(aString);
358*00467759SArmin Le Grand 
359*00467759SArmin Le Grand                     // Pruefen, ob Eintrag nicht in der Liste ist
360*00467759SArmin Le Grand                     if(mpFillAttrLB->GetSelectEntry() != aString)
361*00467759SArmin Le Grand                     {
362*00467759SArmin Le Grand                         sal_uInt16 nCount = mpFillAttrLB->GetEntryCount();
363*00467759SArmin Le Grand                         String aTmpStr;
364*00467759SArmin Le Grand                         if(nCount > 0)
365*00467759SArmin Le Grand                         {
366*00467759SArmin Le Grand                             //Letzter Eintrag wird auf temporaeren Eintrag geprueft
367*00467759SArmin Le Grand                             aTmpStr = mpFillAttrLB->GetEntry(nCount - 1);
368*00467759SArmin Le Grand                             if(aTmpStr.GetChar(0) == TMP_STR_BEGIN &&
369*00467759SArmin Le Grand                                 aTmpStr.GetChar(aTmpStr.Len() - 1) == TMP_STR_END)
370*00467759SArmin Le Grand                             {
371*00467759SArmin Le Grand                                 mpFillAttrLB->RemoveEntry(nCount - 1);
372*00467759SArmin Le Grand                             }
373*00467759SArmin Le Grand                         }
374*00467759SArmin Le Grand 
375*00467759SArmin Le Grand                         aTmpStr = TMP_STR_BEGIN;
376*00467759SArmin Le Grand                         aTmpStr += aString;
377*00467759SArmin Le Grand                         aTmpStr += TMP_STR_END;
378*00467759SArmin Le Grand 
379*00467759SArmin Le Grand                         XHatchEntry* pEntry = new XHatchEntry(mpHatchItem->GetHatchValue(),aTmpStr);
380*00467759SArmin Le Grand                         XHatchListSharedPtr aHatchList(XPropertyListFactory::CreateSharedXHatchList(String::CreateFromAscii("TmpList")));
381*00467759SArmin Le Grand 
382*00467759SArmin Le Grand                         aHatchList->Insert(pEntry);
383*00467759SArmin Le Grand                         aHatchList->SetDirty(sal_False);
384*00467759SArmin Le Grand                         const Bitmap aBmp = aHatchList->GetUiBitmap(0);
385*00467759SArmin Le Grand 
386*00467759SArmin Le Grand                         if(!aBmp.IsEmpty())
387*00467759SArmin Le Grand                         {
388*00467759SArmin Le Grand                             ((ListBox*)mpFillAttrLB)->InsertEntry(pEntry->GetName(),aBmp);
389*00467759SArmin Le Grand                             mpFillAttrLB->SelectEntryPos(mpFillAttrLB->GetEntryCount() - 1);
390*00467759SArmin Le Grand                         }
391*00467759SArmin Le Grand                     }
392*00467759SArmin Le Grand                 }
393*00467759SArmin Le Grand                 else
394*00467759SArmin Le Grand                 {
395*00467759SArmin Le Grand                     mpFillAttrLB->SetNoSelection();
396*00467759SArmin Le Grand                 }
397*00467759SArmin Le Grand                 break;
398*00467759SArmin Le Grand             }
399*00467759SArmin Le Grand 
400*00467759SArmin Le Grand             case XFILL_BITMAP:
401*00467759SArmin Le Grand             {
402*00467759SArmin Le Grand                 if(mpBitmapItem)
403*00467759SArmin Le Grand                 {
404*00467759SArmin Le Grand                     String aString(mpBitmapItem->GetName());
405*00467759SArmin Le Grand                     mpFillAttrLB->SelectEntry(aString);
406*00467759SArmin Le Grand 
407*00467759SArmin Le Grand                     // Pruefen, ob Eintrag nicht in der Liste ist
408*00467759SArmin Le Grand                     if(mpFillAttrLB->GetSelectEntry() != aString)
409*00467759SArmin Le Grand                     {
410*00467759SArmin Le Grand                         sal_uInt16 nCount = mpFillAttrLB->GetEntryCount();
411*00467759SArmin Le Grand                         String aTmpStr;
412*00467759SArmin Le Grand 
413*00467759SArmin Le Grand                         if(nCount > 0)
414*00467759SArmin Le Grand                         {
415*00467759SArmin Le Grand                             //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)
419*00467759SArmin Le Grand                             {
420*00467759SArmin Le Grand                                 mpFillAttrLB->RemoveEntry(nCount - 1);
421*00467759SArmin Le Grand                             }
422*00467759SArmin Le Grand                         }
423*00467759SArmin Le Grand 
424*00467759SArmin Le Grand                         aTmpStr = TMP_STR_BEGIN;
425*00467759SArmin Le Grand                         aTmpStr += aString;
426*00467759SArmin Le Grand                         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);
434*00467759SArmin Le Grand                     }
435*00467759SArmin Le Grand                 }
436*00467759SArmin Le Grand                 else
437*00467759SArmin Le Grand                 {
438*00467759SArmin Le Grand                     mpFillAttrLB->SetNoSelection();
439*00467759SArmin Le Grand                 }
440*00467759SArmin Le Grand                 break;
441*00467759SArmin Le Grand             }
442*00467759SArmin Le Grand 
443*00467759SArmin Le Grand             default:
444*00467759SArmin Le Grand             {
445*00467759SArmin Le Grand                 DBG_ERROR("Nicht unterstuetzter Flaechentyp");
446*00467759SArmin Le Grand                 break;
447*00467759SArmin Le Grand             }
448*00467759SArmin Le Grand         }
449*00467759SArmin Le Grand 
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)
455*00467759SArmin Le Grand     {
456*00467759SArmin Le Grand         XFillStyle eXFS = static_cast< XFillStyle >(mpStyleItem->GetValue());
457*00467759SArmin Le Grand 
458*00467759SArmin Le Grand         // Die Listen haben sich geaendert ?
459*00467759SArmin Le Grand         switch(eXFS)
460*00467759SArmin Le Grand         {
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);
471*00467759SArmin Le Grand                 }
472*00467759SArmin Le Grand                 break;
473*00467759SArmin Le Grand             }
474*00467759SArmin Le Grand             case XFILL_GRADIENT:
475*00467759SArmin Le Grand             {
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);
484*00467759SArmin Le Grand                 }
485*00467759SArmin Le Grand                 break;
486*00467759SArmin Le Grand             }
487*00467759SArmin Le Grand             case XFILL_HATCH:
488*00467759SArmin Le Grand             {
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             }
517*00467759SArmin Le Grand         }
518*00467759SArmin Le Grand     }
519cdf0e10cSrcweir }
520cdf0e10cSrcweir 
521cdf0e10cSrcweir //========================================================================
522cdf0e10cSrcweir 
CreateItemWindow(Window * pParent)523*00467759SArmin Le Grand Window* SvxFillToolBoxControl::CreateItemWindow(Window *pParent)
524cdf0e10cSrcweir {
525*00467759SArmin Le Grand     if(GetSlotId() == SID_ATTR_FILL_STYLE)
526*00467759SArmin Le Grand     {
527*00467759SArmin Le Grand         mpFillControl = new FillControl(pParent);
528*00467759SArmin Le Grand         // Damit dem FillControl das SvxFillToolBoxControl bekannt ist
529*00467759SArmin Le Grand         // (und um kompatibel zu bleiben)
530*00467759SArmin Le Grand         mpFillControl->SetData(this);
531*00467759SArmin Le Grand 
532*00467759SArmin Le Grand         mpFillAttrLB = (SvxFillAttrBox*)mpFillControl->mpLbFillAttr;
533*00467759SArmin Le Grand         mpFillTypeLB = (SvxFillTypeBox*)mpFillControl->mpLbFillType;
534*00467759SArmin Le Grand 
535*00467759SArmin Le Grand         mpFillAttrLB->SetUniqueId(HID_FILL_ATTR_LISTBOX);
536*00467759SArmin Le Grand         mpFillTypeLB->SetUniqueId(HID_FILL_TYPE_LISTBOX);
537*00467759SArmin Le Grand 
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;
550*00467759SArmin Le Grand     }
551*00467759SArmin Le Grand     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();
579*00467759SArmin Le Grand     SetSizePixel(
580*00467759SArmin Le Grand         Size(aAttrPnt.X() + aAttrSize.Width(),
581*00467759SArmin Le Grand         Max(aAttrSize.Height(),aTypeSize.Height())));
582*00467759SArmin Le Grand 
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 {
599*00467759SArmin Le Grand     SfxObjectShell* pSh = SfxObjectShell::Current();
600*00467759SArmin Le Grand     bool bDone(false);
601*00467759SArmin Le Grand 
602*00467759SArmin Le Grand     if(pSh)
603*00467759SArmin Le Grand     {
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();
606*00467759SArmin Le Grand 
607*00467759SArmin Le Grand         switch(aFillStyle)
608*00467759SArmin Le Grand         {
609*00467759SArmin Le Grand             case XFILL_SOLID:
610*00467759SArmin Le Grand             {
611*00467759SArmin Le Grand                 if(pSh->GetItem(SID_COLOR_TABLE))
612*00467759SArmin Le Grand                 {
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;
617*00467759SArmin Le Grand                 }
618*00467759SArmin Le Grand                 break;
619*00467759SArmin Le Grand             }
620*00467759SArmin Le Grand 
621*00467759SArmin Le Grand             case XFILL_GRADIENT:
622*00467759SArmin Le Grand             {
623*00467759SArmin Le Grand                 if(pSh->GetItem(SID_GRADIENT_LIST))
624*00467759SArmin Le Grand                 {
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;
629*00467759SArmin Le Grand                 }
630*00467759SArmin Le Grand                 break;
631*00467759SArmin Le Grand             }
632*00467759SArmin Le Grand 
633*00467759SArmin Le Grand             case XFILL_HATCH:
634*00467759SArmin Le Grand             {
635*00467759SArmin Le Grand                 if(pSh->GetItem(SID_HATCH_LIST))
636*00467759SArmin Le Grand                 {
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;
641*00467759SArmin Le Grand                 }
642*00467759SArmin Le Grand                 break;
643*00467759SArmin Le Grand             }
644*00467759SArmin Le Grand 
645*00467759SArmin Le Grand             case XFILL_BITMAP:
646*00467759SArmin Le Grand             {
647*00467759SArmin Le Grand                 if(pSh->GetItem(SID_BITMAP_LIST))
648*00467759SArmin Le Grand                 {
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;
653*00467759SArmin Le Grand                 }
654*00467759SArmin Le Grand                 break;
655*00467759SArmin Le Grand             }
656*00467759SArmin Le Grand             default: // XFILL_NONE
657*00467759SArmin Le Grand             {
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     }
663*00467759SArmin Le Grand 
664*00467759SArmin Le Grand     if(!bDone)
665*00467759SArmin Le Grand     {
666*00467759SArmin Le Grand         mpLbFillAttr->Disable();
667*00467759SArmin Le Grand     }
668cdf0e10cSrcweir }
669cdf0e10cSrcweir 
updateLastFillTypeControlSelectEntryPos()670*00467759SArmin Le Grand void FillControl::updateLastFillTypeControlSelectEntryPos()
671*00467759SArmin Le Grand {
672*00467759SArmin Le Grand     mnLastFillTypeControlSelectEntryPos = mpLbFillType->GetSelectEntryPos();
673*00467759SArmin Le Grand }
674cdf0e10cSrcweir 
IMPL_LINK(FillControl,SelectFillTypeHdl,ListBox *,pBox)675*00467759SArmin Le Grand IMPL_LINK(FillControl,SelectFillTypeHdl,ListBox *,pBox)
676cdf0e10cSrcweir {
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);
713cdf0e10cSrcweir     }
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())
719*00467759SArmin Le Grand     {
720*00467759SArmin Le Grand         SfxViewShell* pViewShell = SfxViewShell::Current();
721*00467759SArmin Le Grand 
722*00467759SArmin Le Grand         if(pViewShell && pViewShell->GetWindow())
723*00467759SArmin Le Grand         {
724*00467759SArmin Le Grand             pViewShell->GetWindow()->GrabFocus();
725*00467759SArmin Le Grand         }
726*00467759SArmin Le Grand     }
727*00467759SArmin Le Grand 
728*00467759SArmin Le Grand     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)738*00467759SArmin Le Grand 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     }
744*00467759SArmin Le Grand 
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();
751cdf0e10cSrcweir 
752*00467759SArmin Le Grand     if(bAction)
753cdf0e10cSrcweir     {
754*00467759SArmin Le Grand         SfxObjectShell* pSh = SfxObjectShell::Current();
755*00467759SArmin Le Grand 
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)
760cdf0e10cSrcweir         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()));
764*00467759SArmin Le Grand 
765*00467759SArmin Le Grand         switch(eXFS)
766cdf0e10cSrcweir         {
767cdf0e10cSrcweir             case XFILL_NONE:
768cdf0e10cSrcweir             {
769*00467759SArmin Le Grand                 // handled in SelectFillTypeHdl, nothing to do here
770*00467759SArmin Le Grand                 break;
771cdf0e10cSrcweir             }
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 
778*00467759SArmin Le Grand                 if(aTmpStr.GetChar(0) == TMP_STR_BEGIN && aTmpStr.GetChar(aTmpStr.Len() - 1) == TMP_STR_END)
779cdf0e10cSrcweir                 {
780*00467759SArmin Le Grand                     aTmpStr.Erase(aTmpStr.Len() - 1,1);
781*00467759SArmin Le Grand                     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"));
786*00467759SArmin Le Grand                 aXFillColorItem.QueryValue(a);
787*00467759SArmin Le Grand                 aArgsFillAttr[0].Value = a;
788*00467759SArmin Le Grand                 aFillAttrCommand = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:FillColor"));
789*00467759SArmin Le Grand                 break;
790cdf0e10cSrcweir             }
791cdf0e10cSrcweir             case XFILL_GRADIENT:
792cdf0e10cSrcweir             {
793*00467759SArmin Le Grand                 sal_uInt16 nPos = mpLbFillAttr->GetSelectEntryPos();
794cdf0e10cSrcweir 
795*00467759SArmin Le Grand                 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"));
804*00467759SArmin Le Grand                         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                 }
809*00467759SArmin Le Grand                 break;
810cdf0e10cSrcweir             }
811cdf0e10cSrcweir 
812cdf0e10cSrcweir             case XFILL_HATCH:
813cdf0e10cSrcweir             {
814*00467759SArmin Le Grand                 sal_uInt16 nPos = mpLbFillAttr->GetSelectEntryPos();
815cdf0e10cSrcweir 
816*00467759SArmin Le Grand                 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);
824*00467759SArmin Le Grand 
825*00467759SArmin Le Grand                         aArgsFillAttr[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FillHatch"));
826*00467759SArmin Le Grand                         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                 }
831*00467759SArmin Le Grand                 break;
832cdf0e10cSrcweir             }
833cdf0e10cSrcweir 
834cdf0e10cSrcweir             case XFILL_BITMAP:
835cdf0e10cSrcweir             {
836*00467759SArmin Le Grand                 sal_uInt16 nPos = mpLbFillAttr->GetSelectEntryPos();
837cdf0e10cSrcweir 
838*00467759SArmin Le Grand                 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"));
848*00467759SArmin Le Grand                         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                 }
853*00467759SArmin Le Grand                 break;
854cdf0e10cSrcweir             }
855cdf0e10cSrcweir         }
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)
887*00467759SArmin Le Grand         {
888*00467759SArmin Le Grand             SfxViewShell* pViewShell = SfxViewShell::Current();
889*00467759SArmin Le Grand 
890*00467759SArmin Le Grand             if(pViewShell && pViewShell->GetWindow())
891*00467759SArmin Le Grand             {
892*00467759SArmin Le Grand                 pViewShell->GetWindow()->GrabFocus();
893*00467759SArmin Le Grand             }
894*00467759SArmin Le Grand         }
895cdf0e10cSrcweir     }
896cdf0e10cSrcweir 
897cdf0e10cSrcweir     return 0;
898cdf0e10cSrcweir }
899cdf0e10cSrcweir 
900cdf0e10cSrcweir //------------------------------------------------------------------------
901cdf0e10cSrcweir 
Resize()902cdf0e10cSrcweir void FillControl::Resize()
903cdf0e10cSrcweir {
904*00467759SArmin Le Grand     // Breite der beiden ListBoxen nicht 1/2 : 1/2, sondern 2/5 : 3/5
905*00467759SArmin Le Grand     long nW = GetOutputSizePixel().Width() / 5;
906*00467759SArmin Le Grand     long nH = 180;
907*00467759SArmin Le Grand     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)915*00467759SArmin Le Grand void FillControl::DataChanged(const DataChangedEvent& rDCEvt)
916cdf0e10cSrcweir {
917*00467759SArmin Le Grand     if((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
918*00467759SArmin Le Grand         (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(
931*00467759SArmin Le Grand             Size(aAttrPnt.X() + aAttrSize.Width(),
932*00467759SArmin Le Grand             Max(aAttrSize.Height(),aTypeSize.Height())));
933cdf0e10cSrcweir     }
934*00467759SArmin Le Grand     Window::DataChanged(rDCEvt);
935cdf0e10cSrcweir }
936cdf0e10cSrcweir 
937*00467759SArmin Le Grand //------------------------------------------------------------------------
938*00467759SArmin Le Grand //eof
939