1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #include <sfx2/sidebar/propertypanel.hrc>
23 #include <sfx2/sidebar/Theme.hxx>
24 #include <sfx2/sidebar/ControlFactory.hxx>
25 #include <LinePropertyPanel.hxx>
26 #include <LinePropertyPanel.hrc>
27 #include <svx/dialogs.hrc>
28 #include <svx/dialmgr.hxx>
29 #include <sfx2/objsh.hxx>
30 #include <sfx2/bindings.hxx>
31 #include <sfx2/dispatch.hxx>
32 #include <svx/xlnclit.hxx>
33 #include <svx/xtable.hxx>
34 #include <svx/xdash.hxx>
35 #include <svx/drawitem.hxx>
36 #include <svx/svxitems.hrc>
37 #include <svtools/valueset.hxx>
38 #include <unotools/pathoptions.hxx>
39 #include <unotools/viewoptions.hxx>
40 #include <comphelper/processfactory.hxx>
41 #include <i18npool/mslangid.hxx>
42 #include <svx/xlineit0.hxx>
43 #include <svx/xlndsit.hxx>
44 #include <vcl/svapp.hxx>
45 #include <svx/xlnwtit.hxx>
46 #include <vcl/lstbox.hxx>
47 #include <svx/tbxcolorupdate.hxx>
48 #include <vcl/toolbox.hxx>
49 #include <svx/xlntrit.hxx>
50 #include <svx/xlnstit.hxx>
51 #include <svx/xlnedit.hxx>
52 #include <svx/xlncapit.hxx>
53 #include <svx/xlinjoit.hxx>
54 #include "svx/sidebar/PopupContainer.hxx"
55 #include "svx/sidebar/PopupControl.hxx"
56 #include <svx/sidebar/ColorControl.hxx>
57 #include "LineWidthControl.hxx"
58 #include <boost/bind.hpp>
59 
60 using namespace css;
61 using namespace cssu;
62 using ::sfx2::sidebar::Theme;
63 
64 #define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString)))
65 
66 namespace {
67     short GetItemId_Impl_line( ValueSet& rValueSet, const Color& rCol )
68     {
69         if(rCol == COL_AUTO)
70             return 0;
71 
72         bool	bFound = false;
73         sal_uInt16 nCount = rValueSet.GetItemCount();
74         sal_uInt16	n	   = 1;
75 
76         while ( !bFound && n <= nCount )
77         {
78             Color aValCol = rValueSet.GetItemColor(n);
79 
80             bFound = (   aValCol.GetRed()   == rCol.GetRed()
81                 && aValCol.GetGreen() == rCol.GetGreen()
82                 && aValCol.GetBlue()  == rCol.GetBlue() );
83 
84             if ( !bFound )
85                 n++;
86         }
87         return bFound ? n : -1;
88     }
89 
90     void FillLineEndListBox(ListBox& rListBoxStart, ListBox& rListBoxEnd, const XLineEndListSharedPtr aList)
91     {
92         const sal_uInt32 nCount(aList.get() ? aList->Count() : 0);
93         const String sNone(SVX_RES(RID_SVXSTR_NONE));
94 
95         rListBoxStart.SetUpdateMode(false);
96         rListBoxEnd.SetUpdateMode(false);
97 
98         rListBoxStart.Clear();
99         rListBoxEnd.Clear();
100 
101         // add 'none' entries
102         rListBoxStart.InsertEntry(sNone);
103         rListBoxEnd.InsertEntry(sNone);
104 
105         for(sal_uInt32 i(0); i < nCount; i++)
106         {
107             XLineEndEntry* pEntry = aList->GetLineEnd(i);
108             const Bitmap aBitmap = aList->GetUiBitmap(i);
109 
110             if(!aBitmap.IsEmpty())
111             {
112                 Bitmap aCopyStart(aBitmap);
113                 Bitmap aCopyEnd(aBitmap);
114                 // delete pBitmap;
115                 const Size aBmpSize(aCopyStart.GetSizePixel());
116                 const Rectangle aCropRectStart(Point(), Size(aBmpSize.Width() / 2, aBmpSize.Height()));
117                 const Rectangle aCropRectEnd(Point(aBmpSize.Width() / 2, 0), Size(aBmpSize.Width() / 2, aBmpSize.Height()));
118 
119                 aCopyStart.Crop(aCropRectStart);
120                 rListBoxStart.InsertEntry(
121                     pEntry->GetName(),
122                     aCopyStart);
123 
124                 aCopyEnd.Crop(aCropRectEnd);
125                 rListBoxEnd.InsertEntry(
126                     pEntry->GetName(),
127                     aCopyEnd);
128             }
129             else
130             {
131                 rListBoxStart.InsertEntry(pEntry->GetName());
132                 rListBoxEnd.InsertEntry(pEntry->GetName());
133             }
134         }
135 
136         rListBoxStart.SetUpdateMode(true);
137         rListBoxEnd.SetUpdateMode(true);
138     }
139 
140     void FillLineStyleListBox(ListBox& rListBox, const XDashListSharedPtr aList)
141     {
142         const sal_uInt32 nCount(aList.get() ? aList->Count() : 0);
143         rListBox.SetUpdateMode(false);
144 
145         rListBox.Clear();
146 
147         // entry for 'none'
148         rListBox.InsertEntry(aList->GetStringForUiNoLine());
149 
150         // entry for solid line
151         rListBox.InsertEntry(aList->GetStringForUiSolidLine(), aList->GetBitmapForUISolidLine());
152 
153         for(sal_uInt32 i(0); i < nCount; i++)
154         {
155             XDashEntry* pEntry = aList->GetDash(i);
156             const Bitmap aBitmap = aList->GetUiBitmap(i);
157 
158             if(!aBitmap.IsEmpty())
159             {
160                 rListBox.InsertEntry(
161                     pEntry->GetName(),
162                     aBitmap);
163                 // delete pBitmap;
164             }
165             else
166             {
167                 rListBox.InsertEntry(pEntry->GetName());
168             }
169         }
170 
171         rListBox.SetUpdateMode(true);
172     }
173 } // end of anonymous namespace
174 
175 // namespace open
176 
177 namespace svx { namespace sidebar {
178 
179 LinePropertyPanel::LinePropertyPanel(
180     Window* pParent,
181     const cssu::Reference<css::frame::XFrame>& rxFrame,
182     SfxBindings* pBindings)
183 :   Control(
184         pParent,
185         SVX_RES(RID_SIDEBAR_LINE_PANEL)),
186     mpFTWidth(new FixedText(this, SVX_RES(FT_WIDTH))),
187     mpTBWidthBackground(sfx2::sidebar::ControlFactory::CreateToolBoxBackground(this)),
188     mpTBWidth(sfx2::sidebar::ControlFactory::CreateToolBox(mpTBWidthBackground.get(), SVX_RES(TB_WIDTH))),
189     mpFTColor(new FixedText(this, SVX_RES(FT_COLOR))),
190     mpTBColorBackground(sfx2::sidebar::ControlFactory::CreateToolBoxBackground(this)),
191     mpTBColor(sfx2::sidebar::ControlFactory::CreateToolBox(mpTBColorBackground.get(), SVX_RES(TB_COLOR))),
192     mpFTStyle(new FixedText(this, SVX_RES(FT_STYLE))),
193     mpLBStyle(new ListBox(this, SVX_RES(LB_STYLE))),
194     mpFTTrancparency(new FixedText(this, SVX_RES(FT_TRANSPARENT))),
195     mpMFTransparent(new MetricField(this, SVX_RES(MF_TRANSPARENT))),
196     mpFTArrow(new FixedText(this, SVX_RES(FT_ARROW))),
197     mpLBStart(new ListBox(this, SVX_RES(LB_START))),
198     mpLBEnd(new ListBox(this, SVX_RES(LB_END))),
199     mpFTEdgeStyle(new FixedText(this, SVX_RES(FT_EDGESTYLE))),
200     mpLBEdgeStyle(new ListBox(this, SVX_RES(LB_EDGESTYLE))),
201     mpFTCapStyle(new FixedText(this, SVX_RES(FT_CAPSTYLE))),
202     mpLBCapStyle(new ListBox(this, SVX_RES(LB_CAPSTYLE))),
203     maStyleControl(SID_ATTR_LINE_STYLE, *pBindings, *this),
204     maDashControl (SID_ATTR_LINE_DASH, *pBindings, *this),
205     maWidthControl(SID_ATTR_LINE_WIDTH, *pBindings, *this),
206     maColorControl(SID_ATTR_LINE_COLOR, *pBindings, *this),
207     maStartControl(SID_ATTR_LINE_START, *pBindings, *this),
208     maEndControl(SID_ATTR_LINE_END, *pBindings, *this),
209     maLineEndListControl(SID_LINEEND_LIST, *pBindings, *this),
210     maLineStyleListControl(SID_DASH_LIST, *pBindings, *this),
211     maTransControl(SID_ATTR_LINE_TRANSPARENCE, *pBindings, *this),
212     maEdgeStyle(SID_ATTR_LINE_JOINT, *pBindings, *this),
213     maCapStyle(SID_ATTR_LINE_CAP, *pBindings, *this),
214     maColor(COL_BLACK),
215     mpColorUpdater(new ::svx::ToolboxButtonColorUpdater(SID_ATTR_LINE_COLOR, TBI_COLOR, mpTBColor.get(), TBX_UPDATER_MODE_CHAR_COLOR_NEW)),
216     mpStyleItem(),
217     mpDashItem(),
218     mnTrans(0),
219     meMapUnit(SFX_MAPUNIT_MM),
220     mnWidthCoreValue(0),
221     maLineEndList(),
222     maLineStyleList(),
223     mpStartItem(0),
224     mpEndItem(0),
225     maColorPopup(this, ::boost::bind(&LinePropertyPanel::CreateColorPopupControl, this, _1)),
226     maLineWidthPopup(this, ::boost::bind(&LinePropertyPanel::CreateLineWidthPopupControl, this, _1)),
227     maIMGColor(SVX_RES(IMG_COLOR)),
228     maIMGNone(SVX_RES(IMG_NONE_ICON)),
229     mpIMGWidthIcon(),
230     mpIMGWidthIconH(),
231     mxFrame(rxFrame),
232     mpBindings(pBindings),
233     mbColorAvailable(true),
234     mbWidthValuable(true)
235 {
236     Initialize();
237     FreeResource();
238 }
239 
240 
241 
242 LinePropertyPanel::~LinePropertyPanel()
243 {
244     // Destroy the toolboxes, then their background windows.
245     mpTBWidth.reset();
246     mpTBColor.reset();
247 
248     mpTBWidthBackground.reset();
249     mpTBColorBackground.reset();
250 }
251 
252 
253 
254 void LinePropertyPanel::Initialize()
255 {
256     mpFTWidth->SetBackground(Wallpaper());
257     mpFTColor->SetBackground(Wallpaper());
258     mpFTStyle->SetBackground(Wallpaper());
259     mpFTTrancparency->SetBackground(Wallpaper());
260     mpFTArrow->SetBackground(Wallpaper());
261     mpFTEdgeStyle->SetBackground(Wallpaper());
262     mpFTCapStyle->SetBackground(Wallpaper());
263 
264     mpIMGWidthIcon.reset(new Image[8]);
265     mpIMGWidthIcon[0] = Image(SVX_RES(IMG_WIDTH1_ICON));
266     mpIMGWidthIcon[1] = Image(SVX_RES(IMG_WIDTH2_ICON));
267     mpIMGWidthIcon[2] = Image(SVX_RES(IMG_WIDTH3_ICON));
268     mpIMGWidthIcon[3] = Image(SVX_RES(IMG_WIDTH4_ICON));
269     mpIMGWidthIcon[4] = Image(SVX_RES(IMG_WIDTH5_ICON));
270     mpIMGWidthIcon[5] = Image(SVX_RES(IMG_WIDTH6_ICON));
271     mpIMGWidthIcon[6] = Image(SVX_RES(IMG_WIDTH7_ICON));
272     mpIMGWidthIcon[7] = Image(SVX_RES(IMG_WIDTH8_ICON));
273 
274     //high contrast
275     mpIMGWidthIconH.reset(new Image[8]);
276     mpIMGWidthIconH[0] = Image(SVX_RES(IMG_WIDTH1_ICON_H));
277     mpIMGWidthIconH[1] = Image(SVX_RES(IMG_WIDTH2_ICON_H));
278     mpIMGWidthIconH[2] = Image(SVX_RES(IMG_WIDTH3_ICON_H));
279     mpIMGWidthIconH[3] = Image(SVX_RES(IMG_WIDTH4_ICON_H));
280     mpIMGWidthIconH[4] = Image(SVX_RES(IMG_WIDTH5_ICON_H));
281     mpIMGWidthIconH[5] = Image(SVX_RES(IMG_WIDTH6_ICON_H));
282     mpIMGWidthIconH[6] = Image(SVX_RES(IMG_WIDTH7_ICON_H));
283     mpIMGWidthIconH[7] = Image(SVX_RES(IMG_WIDTH8_ICON_H));
284 
285     meMapUnit = maWidthControl.GetCoreMetric();
286 
287     mpTBColor->SetItemImage(TBI_COLOR, maIMGColor);
288     Size aTbxSize( mpTBColor->CalcWindowSizePixel() );
289     mpTBColor->SetOutputSizePixel( aTbxSize );
290     mpTBColor->SetItemBits( TBI_COLOR, mpTBColor->GetItemBits( TBI_COLOR ) | TIB_DROPDOWNONLY );
291     mpTBColor->SetQuickHelpText(TBI_COLOR,String(SVX_RES(STR_QH_TB_COLOR))); //Add
292     mpTBColor->SetBackground(Wallpaper());
293     mpTBColor->SetPaintTransparent(true);
294     Link aLink = LINK(this, LinePropertyPanel, ToolboxColorSelectHdl);
295     mpTBColor->SetDropdownClickHdl ( aLink );
296     mpTBColor->SetSelectHdl ( aLink );
297 
298     FillLineStyleList();
299     SelectLineStyle();
300     aLink = LINK( this, LinePropertyPanel, ChangeLineStyleHdl );
301     mpLBStyle->SetSelectHdl( aLink );
302     mpLBStyle->SetAccessibleName(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Style")));
303     mpLBStyle->AdaptDropDownLineCountToMaximum();
304 
305     mpTBWidth->SetItemImage(TBI_WIDTH, mpIMGWidthIcon[0]);
306     aTbxSize = mpTBWidth->CalcWindowSizePixel() ;
307     mpTBWidth->SetOutputSizePixel( aTbxSize );
308     mpTBWidth->SetItemBits( TBI_WIDTH, mpTBWidth->GetItemBits( TBI_WIDTH ) | TIB_DROPDOWNONLY );
309     mpTBWidth->SetQuickHelpText(TBI_WIDTH,String(SVX_RES(STR_QH_TB_WIDTH))); //Add
310     mpTBWidth->SetBackground(Wallpaper());
311     mpTBWidth->SetPaintTransparent(true);
312     aLink = LINK(this, LinePropertyPanel, ToolboxWidthSelectHdl);
313     mpTBWidth->SetDropdownClickHdl ( aLink );
314     mpTBWidth->SetSelectHdl ( aLink );
315 
316     FillLineEndList();
317     SelectEndStyle(true);
318     SelectEndStyle(false);
319     aLink = LINK( this, LinePropertyPanel, ChangeStartHdl );
320     mpLBStart->SetSelectHdl( aLink );
321     mpLBStart->SetAccessibleName(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Beginning Style")));	//wj acc
322     mpLBStart->AdaptDropDownLineCountToMaximum();
323     aLink = LINK( this, LinePropertyPanel, ChangeEndHdl );
324     mpLBEnd->SetSelectHdl( aLink );
325     mpLBEnd->SetAccessibleName(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Ending Style")));	//wj acc
326     mpLBEnd->AdaptDropDownLineCountToMaximum();
327 
328     aLink = LINK(this, LinePropertyPanel, ChangeTransparentHdl);
329     mpMFTransparent->SetModifyHdl(aLink);
330     mpMFTransparent->SetAccessibleName(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Transparency")));	//wj acc
331 
332     mpTBWidth->SetAccessibleRelationLabeledBy(mpFTWidth.get());
333     mpTBColor->SetAccessibleRelationLabeledBy(mpFTColor.get());
334     mpLBStyle->SetAccessibleRelationLabeledBy(mpFTStyle.get());
335     mpMFTransparent->SetAccessibleRelationLabeledBy(mpFTTrancparency.get());
336     mpLBStart->SetAccessibleRelationLabeledBy(mpFTArrow.get());
337     mpLBEnd->SetAccessibleRelationLabeledBy(mpLBEnd.get());
338 
339     aLink = LINK( this, LinePropertyPanel, ChangeEdgeStyleHdl );
340     mpLBEdgeStyle->SetSelectHdl( aLink );
341     mpLBEdgeStyle->SetAccessibleName(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Corner Style")));
342 
343     aLink = LINK( this, LinePropertyPanel, ChangeCapStyleHdl );
344     mpLBCapStyle->SetSelectHdl( aLink );
345     mpLBCapStyle->SetAccessibleName(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Cap Style")));
346 }
347 
348 
349 
350 void LinePropertyPanel::SetupIcons(void)
351 {
352     if(Theme::GetBoolean(Theme::Bool_UseSymphonyIcons))
353     {
354         // todo
355     }
356     else
357     {
358         // todo
359     }
360 }
361 
362 
363 
364 LinePropertyPanel* LinePropertyPanel::Create (
365     Window* pParent,
366     const cssu::Reference<css::frame::XFrame>& rxFrame,
367     SfxBindings* pBindings)
368 {
369     if (pParent == NULL)
370         throw lang::IllegalArgumentException(A2S("no parent Window given to LinePropertyPanel::Create"), NULL, 0);
371     if ( ! rxFrame.is())
372         throw lang::IllegalArgumentException(A2S("no XFrame given to LinePropertyPanel::Create"), NULL, 1);
373     if (pBindings == NULL)
374         throw lang::IllegalArgumentException(A2S("no SfxBindings given to LinePropertyPanel::Create"), NULL, 2);
375 
376     return new LinePropertyPanel(
377         pParent,
378         rxFrame,
379         pBindings);
380 }
381 
382 
383 
384 
385 void LinePropertyPanel::DataChanged(
386     const DataChangedEvent& rEvent)
387 {
388     (void)rEvent;
389 
390     SetupIcons();
391 }
392 
393 
394 
395 
396 void LinePropertyPanel::NotifyItemUpdate(
397     sal_uInt16 nSID,
398     SfxItemState eState,
399     const SfxPoolItem* pState,
400     const bool bIsEnabled)
401 {
402     (void)bIsEnabled;
403     const bool bDisabled(SFX_ITEM_DISABLED == eState);
404 
405     switch(nSID)
406     {
407         case SID_ATTR_LINE_COLOR:
408         {
409             if(bDisabled)
410             {
411                 mpFTColor->Disable();
412                 mpTBColor->Disable();
413             }
414             else
415             {
416                 mpFTColor->Enable();
417                 mpTBColor->Enable();
418             }
419 
420             if(eState >= SFX_ITEM_DEFAULT)
421             {
422                 const XLineColorItem* pItem = dynamic_cast< const XLineColorItem* >(pState);
423                 if(pItem)
424                 {
425                     maColor = pItem->GetColorValue();
426                     mbColorAvailable = true;
427                     mpColorUpdater->Update(maColor);
428                     break;
429                 }
430             }
431 
432             mbColorAvailable = false;
433             mpColorUpdater->Update(COL_WHITE);
434             break;
435         }
436         case SID_ATTR_LINE_DASH:
437         case SID_ATTR_LINE_STYLE:
438         {
439             if(bDisabled)
440             {
441                 mpFTStyle->Disable();
442                 mpLBStyle->Disable();
443             }
444             else
445             {
446                 mpFTStyle->Enable();
447                 mpLBStyle->Enable();
448             }
449 
450             if(eState  >= SFX_ITEM_DEFAULT)
451             {
452                 if(nSID == SID_ATTR_LINE_STYLE)
453                 {
454                     const XLineStyleItem* pItem = dynamic_cast< const XLineStyleItem* >(pState);
455 
456                     if(pItem)
457                     {
458                         mpStyleItem.reset(pState ? (XLineStyleItem*)pItem->Clone() : 0);
459                     }
460                 }
461                 else // if(nSID == SID_ATTR_LINE_DASH)
462                 {
463                     const XLineDashItem* pItem = dynamic_cast< const XLineDashItem* >(pState);
464 
465                     if(pItem)
466                     {
467                         mpDashItem.reset(pState ? (XLineDashItem*)pItem->Clone() : 0);
468                     }
469                 }
470             }
471             else
472             {
473                 if(nSID == SID_ATTR_LINE_STYLE)
474                 {
475                     mpStyleItem.reset(0);
476                 }
477                 else
478                 {
479                     mpDashItem.reset(0);
480                 }
481             }
482 
483             SelectLineStyle();
484             break;
485         }
486         case SID_ATTR_LINE_TRANSPARENCE:
487         {
488             if(bDisabled)
489             {
490                 mpFTTrancparency->Disable();
491                 mpMFTransparent->Disable();
492             }
493             else
494             {
495                 mpFTTrancparency->Enable();
496                 mpMFTransparent->Enable();
497             }
498 
499             if(eState >= SFX_ITEM_DEFAULT)
500             {
501                 const XLineTransparenceItem* pItem = dynamic_cast< const XLineTransparenceItem* >(pState);
502 
503                 if(pItem)
504                 {
505                     mnTrans = pItem->GetValue();
506                     mpMFTransparent->SetValue(mnTrans);
507                     break;
508                 }
509             }
510 
511             mpMFTransparent->SetValue(0);//add
512             mpMFTransparent->SetText(String());
513             break;
514         }
515         case SID_ATTR_LINE_WIDTH:
516         {
517             if(bDisabled)
518             {
519                 mpTBWidth->Disable();
520                 mpFTWidth->Disable();
521             }
522             else
523             {
524                 mpTBWidth->Enable();
525                 mpFTWidth->Enable();
526             }
527 
528             if(eState >= SFX_ITEM_DEFAULT)
529             {
530                 const XLineWidthItem* pItem = dynamic_cast< const XLineWidthItem* >(pState);
531 
532                 if(pItem)
533                 {
534                     mnWidthCoreValue = pItem->GetValue();
535                     mbWidthValuable = true;
536                     SetWidthIcon();
537                     break;
538                 }
539             }
540 
541             mbWidthValuable = false;
542             SetWidthIcon();
543             break;
544         }
545         case SID_ATTR_LINE_START:
546         {
547             if(bDisabled)
548             {
549                 mpFTArrow->Disable();
550                 mpLBStart->Disable();
551             }
552             else
553             {
554                 mpFTArrow->Enable();
555                 mpLBStart->Enable();
556             }
557 
558             if(eState >= SFX_ITEM_DEFAULT)
559             {
560                 const XLineStartItem* pItem = dynamic_cast< const XLineStartItem* >(pState);
561 
562                 if(pItem)
563                 {
564                     mpStartItem.reset(pItem ? (XLineStartItem*)pItem->Clone() : 0);
565                     SelectEndStyle(true);
566                     break;
567                 }
568             }
569 
570             mpStartItem.reset(0);
571             SelectEndStyle(true);
572             break;
573         }
574         case SID_ATTR_LINE_END:
575         {
576             if(bDisabled)
577             {
578                 mpFTArrow->Disable();
579                 mpLBEnd->Disable();
580             }
581             else
582             {
583                 mpFTArrow->Enable();
584                 mpLBEnd->Enable();
585             }
586 
587             if(eState >= SFX_ITEM_DEFAULT)
588             {
589                 const XLineEndItem* pItem = dynamic_cast< const XLineEndItem* >(pState);
590 
591                 if(pItem)
592                 {
593                     mpEndItem.reset(pItem ? (XLineEndItem*)pItem->Clone() : 0);
594                     SelectEndStyle(false);
595                     break;
596                 }
597             }
598 
599             mpEndItem.reset(0);
600             SelectEndStyle(false);
601             break;
602         }
603         case SID_LINEEND_LIST:
604         {
605             FillLineEndList();
606             SelectEndStyle(true);
607             SelectEndStyle(false);
608             break;
609         }
610         case SID_DASH_LIST:
611         {
612             FillLineStyleList();
613             SelectLineStyle();
614             break;
615         }
616         case SID_ATTR_LINE_JOINT:
617         {
618             if(bDisabled)
619             {
620                 mpLBEdgeStyle->Disable();
621             }
622             else
623             {
624                 mpLBEdgeStyle->Enable();
625             }
626 
627             if(eState >= SFX_ITEM_DEFAULT)
628             {
629                 const XLineJointItem* pItem = dynamic_cast< const XLineJointItem* >(pState);
630 
631                 if(pItem)
632                 {
633                     sal_uInt16 nEntryPos(0);
634 
635                     switch(pItem->GetValue())
636                     {
637                         case com::sun::star::drawing::LineJoint_MIDDLE:
638                         case com::sun::star::drawing::LineJoint_ROUND:
639                         {
640                             nEntryPos = 1;
641                             break;
642                         }
643                         case com::sun::star::drawing::LineJoint_NONE:
644                         {
645                             nEntryPos = 2;
646                             break;
647                         }
648                         case com::sun::star::drawing::LineJoint_MITER:
649                         {
650                             nEntryPos = 3;
651                             break;
652                         }
653                         case com::sun::star::drawing::LineJoint_BEVEL:
654                         {
655                             nEntryPos = 4;
656                             break;
657                         }
658 
659                         default:
660                             break;
661                     }
662 
663                     if(nEntryPos)
664                     {
665                         mpLBEdgeStyle->SelectEntryPos(nEntryPos - 1);
666                         break;
667                     }
668                 }
669             }
670 
671             mpLBEdgeStyle->SetNoSelection();
672             break;
673         }
674         case SID_ATTR_LINE_CAP:
675         {
676             if(bDisabled)
677             {
678                 mpLBCapStyle->Disable();
679             }
680             else
681             {
682                 mpLBCapStyle->Enable();
683             }
684 
685             if(eState >= SFX_ITEM_DEFAULT)
686             {
687                 const XLineCapItem* pItem = dynamic_cast< const XLineCapItem* >(pState);
688 
689                 if(pItem)
690                 {
691                     sal_uInt16 nEntryPos(0);
692 
693                     switch(pItem->GetValue())
694                     {
695                         case com::sun::star::drawing::LineCap_BUTT:
696                         {
697                             nEntryPos = 1;
698                             break;
699                         }
700                         case com::sun::star::drawing::LineCap_ROUND:
701                         {
702                             nEntryPos = 2;
703                             break;
704                         }
705                         case com::sun::star::drawing::LineCap_SQUARE:
706                         {
707                             nEntryPos = 3;
708                             break;
709                         }
710 
711                         default:
712                             break;
713                     }
714 
715                     if(nEntryPos)
716                     {
717                         mpLBCapStyle->SelectEntryPos(nEntryPos - 1);
718                         break;
719                     }
720                 }
721             }
722 
723             mpLBCapStyle->SetNoSelection();
724             break;
725         }
726     }
727 }
728 
729 
730 
731 
732 SfxBindings* LinePropertyPanel::GetBindings()
733 {
734     return mpBindings;
735 }
736 
737 
738 
739 IMPL_LINK( LinePropertyPanel, ImplPopupModeEndHdl, FloatingWindow*, EMPTYARG )
740 {
741     return 0;
742 }
743 
744 
745 
746 
747 IMPL_LINK(LinePropertyPanel, ToolboxColorSelectHdl,ToolBox*, pToolBox)
748 {
749     sal_uInt16 nId = pToolBox->GetCurItemId();
750     if(nId == TBI_COLOR)
751     {
752         maColorPopup.Show(*pToolBox);
753         maColorPopup.SetCurrentColor(maColor, mbColorAvailable);
754     }
755     return 0;
756 }
757 
758 
759 
760 
761 IMPL_LINK(LinePropertyPanel, ChangeLineStyleHdl, ToolBox*, /* pToolBox */)
762 {
763     const sal_uInt16 nPos(mpLBStyle->GetSelectEntryPos());
764 
765     if(LISTBOX_ENTRY_NOTFOUND != nPos && nPos != mpLBStyle->GetSavedValue())
766     {
767         if(0 == nPos)
768         {
769             // XLINE_NONE
770             const XLineStyleItem aItem(XLINE_NONE);
771 
772             GetBindings()->GetDispatcher()->Execute(SID_ATTR_LINE_STYLE, SFX_CALLMODE_RECORD, &aItem, 0L);
773         }
774         else if(1 == nPos)
775         {
776             // XLINE_SOLID
777             const XLineStyleItem aItem(XLINE_SOLID);
778 
779             GetBindings()->GetDispatcher()->Execute(SID_ATTR_LINE_STYLE, SFX_CALLMODE_RECORD, &aItem, 0L);
780         }
781         else if(maLineStyleList.get() && maLineStyleList->Count() > (long)(nPos - 2))
782         {
783             // XLINE_DASH
784             const XLineStyleItem aItemA(XLINE_DASH);
785             const XDashEntry* pDashEntry = maLineStyleList->GetDash(nPos - 2);
786             OSL_ENSURE(pDashEntry, "OOps, got empty XDash from XDashList (!)");
787             const XLineDashItem aItemB(
788                 pDashEntry ? pDashEntry->GetName() : String(),
789                 pDashEntry ? pDashEntry->GetDash() : XDash());
790 
791             GetBindings()->GetDispatcher()->Execute(SID_ATTR_LINE_STYLE, SFX_CALLMODE_RECORD, &aItemA, 0L);
792             GetBindings()->GetDispatcher()->Execute(SID_ATTR_LINE_DASH, SFX_CALLMODE_RECORD, &aItemB, 0L);
793         }
794     }
795 
796     return 0;
797 }
798 
799 
800 
801 IMPL_LINK(LinePropertyPanel, ChangeStartHdl, void*, EMPTYARG)
802 {
803     sal_uInt16	nPos = mpLBStart->GetSelectEntryPos();
804     if( nPos != LISTBOX_ENTRY_NOTFOUND && nPos != mpLBStart->GetSavedValue() )
805     {
806         XLineStartItem* pItem = NULL;
807         if( nPos == 0 )
808             pItem = new XLineStartItem();
809         else if( maLineEndList.get() && maLineEndList->Count() > (long) ( nPos - 1 ) )
810             pItem = new XLineStartItem( mpLBStart->GetSelectEntry(),maLineEndList->GetLineEnd( nPos - 1 )->GetLineEnd() );
811         GetBindings()->GetDispatcher()->Execute(SID_ATTR_LINEEND_STYLE, SFX_CALLMODE_RECORD, pItem,  0L);
812         delete pItem;
813     }
814     return 0;
815 }
816 
817 
818 
819 
820 IMPL_LINK(LinePropertyPanel, ChangeEndHdl, void*, EMPTYARG)
821 {
822     sal_uInt16	nPos = mpLBEnd->GetSelectEntryPos();
823     if( nPos != LISTBOX_ENTRY_NOTFOUND && nPos != mpLBEnd->GetSavedValue() )
824     {
825         XLineEndItem* pItem = NULL;
826         if( nPos == 0 )
827             pItem = new XLineEndItem();
828         else if( maLineEndList.get() && maLineEndList->Count() > (long) ( nPos - 1 ) )
829             pItem = new XLineEndItem( mpLBEnd->GetSelectEntry(), maLineEndList->GetLineEnd( nPos - 1 )->GetLineEnd() );
830         GetBindings()->GetDispatcher()->Execute(SID_ATTR_LINEEND_STYLE, SFX_CALLMODE_RECORD, pItem,  0L);
831         delete pItem;
832     }
833     return 0;
834 }
835 
836 
837 
838 
839 IMPL_LINK(LinePropertyPanel, ChangeEdgeStyleHdl, void*, EMPTYARG)
840 {
841     const sal_uInt16 nPos(mpLBEdgeStyle->GetSelectEntryPos());
842 
843     if(LISTBOX_ENTRY_NOTFOUND != nPos && nPos != mpLBEdgeStyle->GetSavedValue())
844     {
845         XLineJointItem* pItem = 0;
846 
847         switch(nPos)
848         {
849             case 0: // rounded
850             {
851                 pItem = new XLineJointItem(com::sun::star::drawing::LineJoint_ROUND);
852                 break;
853             }
854             case 1: // none
855             {
856                 pItem = new XLineJointItem(com::sun::star::drawing::LineJoint_NONE);
857                 break;
858             }
859             case 2: // mitered
860             {
861                 pItem = new XLineJointItem(com::sun::star::drawing::LineJoint_MITER);
862                 break;
863             }
864             case 3: // beveled
865             {
866                 pItem = new XLineJointItem(com::sun::star::drawing::LineJoint_BEVEL);
867                 break;
868             }
869         }
870 
871         GetBindings()->GetDispatcher()->Execute(SID_ATTR_LINE_JOINT, SFX_CALLMODE_RECORD, pItem,  0L);
872         delete pItem;
873     }
874     return 0;
875 }
876 
877 
878 
879 
880 IMPL_LINK(LinePropertyPanel, ChangeCapStyleHdl, void*, EMPTYARG)
881 {
882     const sal_uInt16 nPos(mpLBCapStyle->GetSelectEntryPos());
883 
884     if(LISTBOX_ENTRY_NOTFOUND != nPos && nPos != mpLBCapStyle->GetSavedValue())
885     {
886         XLineCapItem* pItem = 0;
887 
888         switch(nPos)
889         {
890             case 0: // flat
891             {
892                 pItem = new XLineCapItem(com::sun::star::drawing::LineCap_BUTT);
893                 break;
894             }
895             case 1: // round
896             {
897                 pItem = new XLineCapItem(com::sun::star::drawing::LineCap_ROUND);
898                 break;
899             }
900             case 2: // square
901             {
902                 pItem = new XLineCapItem(com::sun::star::drawing::LineCap_SQUARE);
903                 break;
904             }
905         }
906 
907         GetBindings()->GetDispatcher()->Execute(SID_ATTR_LINE_CAP, SFX_CALLMODE_RECORD, pItem,  0L);
908         delete pItem;
909     }
910     return 0;
911 }
912 
913 
914 
915 
916 IMPL_LINK(LinePropertyPanel, ToolboxWidthSelectHdl,ToolBox*, pToolBox)
917 {
918     if (pToolBox->GetCurItemId() == TBI_WIDTH)
919     {
920         maLineWidthPopup.SetWidthSelect(mnWidthCoreValue, mbWidthValuable, meMapUnit);
921         maLineWidthPopup.Show(*pToolBox);
922     }
923     return 0;
924 }
925 
926 
927 
928 
929 IMPL_LINK( LinePropertyPanel, ChangeTransparentHdl, void *, EMPTYARG )
930 {
931     sal_uInt16 nVal = (sal_uInt16)mpMFTransparent->GetValue();
932     XLineTransparenceItem aItem( nVal );
933 
934     GetBindings()->GetDispatcher()->Execute(SID_ATTR_LINE_STYLE, SFX_CALLMODE_RECORD, &aItem, 0L);
935     return( 0L );
936 }
937 
938 
939 
940 
941 namespace
942 {
943     Color GetTransparentColor (void)
944     {
945         return COL_TRANSPARENT;
946     }
947 } // end of anonymous namespace
948 
949 PopupControl* LinePropertyPanel::CreateColorPopupControl (PopupContainer* pParent)
950 {
951     return new ColorControl(
952         pParent,
953         mpBindings,
954         SVX_RES(RID_POPUPPANEL_LINEPAGE_COLOR),
955         SVX_RES(VS_COLOR),
956         ::boost::bind(GetTransparentColor),
957         ::boost::bind(&LinePropertyPanel::SetColor, this, _1, _2),
958         pParent,
959         0);
960 }
961 
962 
963 
964 
965 PopupControl* LinePropertyPanel::CreateLineWidthPopupControl (PopupContainer* pParent)
966 {
967     return new LineWidthControl(pParent, *this);
968 }
969 
970 
971 
972 
973 void LinePropertyPanel::EndLineWidthPopupMode (void)
974 {
975     maLineWidthPopup.Hide();
976 }
977 
978 
979 
980 
981 void LinePropertyPanel::SetWidthIcon(int n)
982 {
983     if(n==0)
984         mpTBWidth->SetItemImage( TBI_WIDTH, maIMGNone);
985     else
986         mpTBWidth->SetItemImage( TBI_WIDTH, GetDisplayBackground().GetColor().IsDark() ? mpIMGWidthIconH[n-1] : mpIMGWidthIcon[n-1]);
987 }
988 
989 
990 
991 void LinePropertyPanel::SetWidthIcon()
992 {
993     if(!mbWidthValuable)
994     {
995         mpTBWidth->SetItemImage( TBI_WIDTH, maIMGNone);
996         return;
997     }
998 
999     long nVal = LogicToLogic(mnWidthCoreValue * 10,(MapUnit)meMapUnit , MAP_POINT);
1000 
1001     if(nVal <= 6)
1002         mpTBWidth->SetItemImage( TBI_WIDTH, GetDisplayBackground().GetColor().IsDark() ? mpIMGWidthIconH[0] : mpIMGWidthIcon[0]);
1003     else if(nVal > 6 && nVal <= 9)
1004         mpTBWidth->SetItemImage( TBI_WIDTH, GetDisplayBackground().GetColor().IsDark() ? mpIMGWidthIconH[1] : mpIMGWidthIcon[1]);
1005     else if(nVal > 9 && nVal <= 12)
1006         mpTBWidth->SetItemImage( TBI_WIDTH, GetDisplayBackground().GetColor().IsDark() ? mpIMGWidthIconH[2] : mpIMGWidthIcon[2]);
1007     else if(nVal > 12 && nVal <= 19)
1008         mpTBWidth->SetItemImage( TBI_WIDTH, GetDisplayBackground().GetColor().IsDark() ? mpIMGWidthIconH[3] : mpIMGWidthIcon[3]);
1009     else if(nVal > 19 && nVal <= 26)
1010         mpTBWidth->SetItemImage( TBI_WIDTH, GetDisplayBackground().GetColor().IsDark() ? mpIMGWidthIconH[4] : mpIMGWidthIcon[4]);
1011     else if(nVal > 26 && nVal <= 37)
1012         mpTBWidth->SetItemImage( TBI_WIDTH, GetDisplayBackground().GetColor().IsDark() ? mpIMGWidthIconH[5] : mpIMGWidthIcon[5]);
1013     else if(nVal > 37 && nVal <=52)
1014         mpTBWidth->SetItemImage( TBI_WIDTH, GetDisplayBackground().GetColor().IsDark() ? mpIMGWidthIconH[6] : mpIMGWidthIcon[6]);
1015     else if(nVal > 52)
1016         mpTBWidth->SetItemImage( TBI_WIDTH, GetDisplayBackground().GetColor().IsDark() ? mpIMGWidthIconH[7] : mpIMGWidthIcon[7]);
1017 
1018 }
1019 
1020 
1021 
1022 void LinePropertyPanel::SetColor (
1023     const String& rsColorName,
1024     const Color aColor)
1025 {
1026     XLineColorItem aColorItem(rsColorName, aColor);
1027     mpBindings->GetDispatcher()->Execute(SID_ATTR_LINE_COLOR, SFX_CALLMODE_RECORD, &aColorItem, 0L);
1028     maColor = aColor;
1029 }
1030 
1031 
1032 
1033 void LinePropertyPanel::SetWidth(long nWidth)
1034 {
1035     mnWidthCoreValue = nWidth;
1036     mbWidthValuable = true;
1037 }
1038 
1039 
1040 
1041 void  LinePropertyPanel::FillLineEndList()
1042 {
1043     SfxObjectShell* pSh = SfxObjectShell::Current();
1044     if ( pSh && pSh->GetItem( SID_LINEEND_LIST ) )
1045     {
1046         mpLBStart->Enable();
1047         SvxLineEndListItem aItem( *(const SvxLineEndListItem*)(pSh->GetItem( SID_LINEEND_LIST ) ) );
1048         maLineEndList = aItem.GetLineEndList();
1049 
1050         if(maLineEndList.get())
1051         {
1052             FillLineEndListBox(*mpLBStart, *mpLBEnd, maLineEndList);
1053         }
1054 
1055         mpLBStart->SelectEntryPos(0);
1056         mpLBEnd->SelectEntryPos(0);
1057     }
1058     else
1059     {
1060         mpLBStart->Disable();
1061         mpLBEnd->Disable();
1062     }
1063 }
1064 
1065 
1066 
1067 void  LinePropertyPanel::FillLineStyleList()
1068 {
1069     SfxObjectShell* pSh = SfxObjectShell::Current();
1070     if ( pSh && pSh->GetItem( SID_DASH_LIST ) )
1071     {
1072         mpLBStyle->Enable();
1073         SvxDashListItem aItem( *(const SvxDashListItem*)(pSh->GetItem( SID_DASH_LIST ) ) );
1074         maLineStyleList = aItem.GetDashList();
1075 
1076         if(maLineStyleList.get())
1077         {
1078             FillLineStyleListBox(*mpLBStyle, maLineStyleList);
1079         }
1080 
1081         mpLBStyle->SelectEntryPos(0);
1082     }
1083     else
1084     {
1085         mpLBStyle->Disable();
1086     }
1087 }
1088 
1089 
1090 
1091 void LinePropertyPanel::SelectLineStyle()
1092 {
1093     if( !mpStyleItem.get() || !mpDashItem.get() )
1094     {
1095         mpLBStyle->SetNoSelection();
1096         return;
1097     }
1098 
1099     const XLineStyle eXLS(mpStyleItem ? (XLineStyle)mpStyleItem->GetValue() : XLINE_NONE);
1100     bool bSelected(false);
1101 
1102     switch(eXLS)
1103     {
1104         case XLINE_NONE:
1105             break;
1106         case XLINE_SOLID:
1107             mpLBStyle->SelectEntryPos(1);
1108             bSelected = true;
1109             break;
1110         default:
1111             if(mpDashItem && maLineStyleList.get())
1112             {
1113                 const XDash& rDash = mpDashItem->GetDashValue();
1114                 for(sal_Int32 a(0);!bSelected &&  a < maLineStyleList->Count(); a++)
1115                 {
1116                     XDashEntry* pEntry = maLineStyleList->GetDash(a);
1117                     const XDash& rEntry = pEntry->GetDash();
1118                     if(rDash == rEntry)
1119                     {
1120                         mpLBStyle->SelectEntryPos((sal_uInt16)a + 2);
1121                         bSelected = true;
1122                     }
1123                 }
1124             }
1125             break;
1126     }
1127 
1128     if(!bSelected)
1129         mpLBStyle->SelectEntryPos( 0 );
1130 }
1131 
1132 void LinePropertyPanel::SelectEndStyle(bool bStart)
1133 {
1134     sal_Bool bSelected(false);
1135 
1136     if(bStart)
1137     {
1138         if( !mpStartItem.get() )
1139         {
1140             mpLBStart->SetNoSelection();
1141             return;
1142         }
1143 
1144         if(mpStartItem && maLineEndList.get())
1145         {
1146             const basegfx::B2DPolyPolygon& rItemPolygon = mpStartItem->GetLineStartValue();
1147             for(sal_Int32 a(0);!bSelected &&  a < maLineEndList->Count(); a++)
1148             {
1149                 XLineEndEntry* pEntry = maLineEndList->GetLineEnd(a);
1150                 const basegfx::B2DPolyPolygon& rEntryPolygon = pEntry->GetLineEnd();
1151                 if(rItemPolygon == rEntryPolygon)
1152                 {
1153                     mpLBStart->SelectEntryPos((sal_uInt16)a + 1);
1154                     bSelected = true;
1155                 }
1156             }
1157         }
1158 
1159         if(!bSelected)
1160         {
1161             mpLBStart->SelectEntryPos( 0 );
1162         }
1163     }
1164     else
1165     {
1166         if( !mpEndItem.get() )
1167         {
1168             mpLBEnd->SetNoSelection();
1169             return;
1170         }
1171 
1172         if(mpEndItem && maLineEndList.get())
1173         {
1174             const basegfx::B2DPolyPolygon& rItemPolygon = mpEndItem->GetLineEndValue();
1175             for(sal_Int32 a(0);!bSelected &&  a < maLineEndList->Count(); a++)
1176             {
1177                 XLineEndEntry* pEntry = maLineEndList->GetLineEnd(a);
1178                 const basegfx::B2DPolyPolygon& rEntryPolygon = pEntry->GetLineEnd();
1179                 if(rItemPolygon == rEntryPolygon)
1180                 {
1181                     mpLBEnd->SelectEntryPos((sal_uInt16)a + 1);
1182                     bSelected = true;
1183                 }
1184             }
1185         }
1186 
1187         if(!bSelected)
1188         {
1189             mpLBEnd->SelectEntryPos( 0 );
1190         }
1191     }
1192 }
1193 
1194 
1195 } } // end of namespace svx::sidebar
1196 
1197 // eof
1198