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/ResourceDefinitions.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                 mpFTEdgeStyle->Disable();
622             }
623             else
624             {
625                 mpLBEdgeStyle->Enable();
626                 mpFTEdgeStyle->Enable();
627             }
628 
629             if(eState >= SFX_ITEM_DEFAULT)
630             {
631                 const XLineJointItem* pItem = dynamic_cast< const XLineJointItem* >(pState);
632 
633                 if(pItem)
634                 {
635                     sal_uInt16 nEntryPos(0);
636 
637                     switch(pItem->GetValue())
638                     {
639                         case com::sun::star::drawing::LineJoint_MIDDLE:
640                         case com::sun::star::drawing::LineJoint_ROUND:
641                         {
642                             nEntryPos = 1;
643                             break;
644                         }
645                         case com::sun::star::drawing::LineJoint_NONE:
646                         {
647                             nEntryPos = 2;
648                             break;
649                         }
650                         case com::sun::star::drawing::LineJoint_MITER:
651                         {
652                             nEntryPos = 3;
653                             break;
654                         }
655                         case com::sun::star::drawing::LineJoint_BEVEL:
656                         {
657                             nEntryPos = 4;
658                             break;
659                         }
660 
661                         default:
662                             break;
663                     }
664 
665                     if(nEntryPos)
666                     {
667                         mpLBEdgeStyle->SelectEntryPos(nEntryPos - 1);
668                         break;
669                     }
670                 }
671             }
672 
673             mpLBEdgeStyle->SetNoSelection();
674             break;
675         }
676         case SID_ATTR_LINE_CAP:
677         {
678             if(bDisabled)
679             {
680                 mpLBCapStyle->Disable();
681                 mpFTCapStyle->Disable();
682             }
683             else
684             {
685                 mpLBCapStyle->Enable();
686                 mpLBCapStyle->Enable();
687             }
688 
689             if(eState >= SFX_ITEM_DEFAULT)
690             {
691                 const XLineCapItem* pItem = dynamic_cast< const XLineCapItem* >(pState);
692 
693                 if(pItem)
694                 {
695                     sal_uInt16 nEntryPos(0);
696 
697                     switch(pItem->GetValue())
698                     {
699                         case com::sun::star::drawing::LineCap_BUTT:
700                         {
701                             nEntryPos = 1;
702                             break;
703                         }
704                         case com::sun::star::drawing::LineCap_ROUND:
705                         {
706                             nEntryPos = 2;
707                             break;
708                         }
709                         case com::sun::star::drawing::LineCap_SQUARE:
710                         {
711                             nEntryPos = 3;
712                             break;
713                         }
714 
715                         default:
716                             break;
717                     }
718 
719                     if(nEntryPos)
720                     {
721                         mpLBCapStyle->SelectEntryPos(nEntryPos - 1);
722                         break;
723                     }
724                 }
725             }
726 
727             mpLBCapStyle->SetNoSelection();
728             break;
729         }
730     }
731 }
732 
733 
734 
735 
736 SfxBindings* LinePropertyPanel::GetBindings()
737 {
738     return mpBindings;
739 }
740 
741 
742 
743 IMPL_LINK( LinePropertyPanel, ImplPopupModeEndHdl, FloatingWindow*, EMPTYARG )
744 {
745     return 0;
746 }
747 
748 
749 
750 
751 IMPL_LINK(LinePropertyPanel, ToolboxColorSelectHdl,ToolBox*, pToolBox)
752 {
753     sal_uInt16 nId = pToolBox->GetCurItemId();
754     if(nId == TBI_COLOR)
755     {
756         maColorPopup.Show(*pToolBox);
757         maColorPopup.SetCurrentColor(maColor, mbColorAvailable);
758     }
759     return 0;
760 }
761 
762 
763 
764 
765 IMPL_LINK(LinePropertyPanel, ChangeLineStyleHdl, ToolBox*, /* pToolBox */)
766 {
767     const sal_uInt16 nPos(mpLBStyle->GetSelectEntryPos());
768 
769     if(LISTBOX_ENTRY_NOTFOUND != nPos && nPos != mpLBStyle->GetSavedValue())
770     {
771         if(0 == nPos)
772         {
773             // XLINE_NONE
774             const XLineStyleItem aItem(XLINE_NONE);
775 
776             GetBindings()->GetDispatcher()->Execute(SID_ATTR_LINE_STYLE, SFX_CALLMODE_RECORD, &aItem, 0L);
777         }
778         else if(1 == nPos)
779         {
780             // XLINE_SOLID
781             const XLineStyleItem aItem(XLINE_SOLID);
782 
783             GetBindings()->GetDispatcher()->Execute(SID_ATTR_LINE_STYLE, SFX_CALLMODE_RECORD, &aItem, 0L);
784         }
785         else if(maLineStyleList.get() && maLineStyleList->Count() > (long)(nPos - 2))
786         {
787             // XLINE_DASH
788             const XLineStyleItem aItemA(XLINE_DASH);
789             const XDashEntry* pDashEntry = maLineStyleList->GetDash(nPos - 2);
790             OSL_ENSURE(pDashEntry, "OOps, got empty XDash from XDashList (!)");
791             const XLineDashItem aItemB(
792                 pDashEntry ? pDashEntry->GetName() : String(),
793                 pDashEntry ? pDashEntry->GetDash() : XDash());
794 
795             GetBindings()->GetDispatcher()->Execute(SID_ATTR_LINE_STYLE, SFX_CALLMODE_RECORD, &aItemA, 0L);
796             GetBindings()->GetDispatcher()->Execute(SID_ATTR_LINE_DASH, SFX_CALLMODE_RECORD, &aItemB, 0L);
797         }
798     }
799 
800     return 0;
801 }
802 
803 
804 
805 IMPL_LINK(LinePropertyPanel, ChangeStartHdl, void*, EMPTYARG)
806 {
807     sal_uInt16	nPos = mpLBStart->GetSelectEntryPos();
808     if( nPos != LISTBOX_ENTRY_NOTFOUND && nPos != mpLBStart->GetSavedValue() )
809     {
810         XLineStartItem* pItem = NULL;
811         if( nPos == 0 )
812             pItem = new XLineStartItem();
813         else if( maLineEndList.get() && maLineEndList->Count() > (long) ( nPos - 1 ) )
814             pItem = new XLineStartItem( mpLBStart->GetSelectEntry(),maLineEndList->GetLineEnd( nPos - 1 )->GetLineEnd() );
815         GetBindings()->GetDispatcher()->Execute(SID_ATTR_LINEEND_STYLE, SFX_CALLMODE_RECORD, pItem,  0L);
816         delete pItem;
817     }
818     return 0;
819 }
820 
821 
822 
823 
824 IMPL_LINK(LinePropertyPanel, ChangeEndHdl, void*, EMPTYARG)
825 {
826     sal_uInt16	nPos = mpLBEnd->GetSelectEntryPos();
827     if( nPos != LISTBOX_ENTRY_NOTFOUND && nPos != mpLBEnd->GetSavedValue() )
828     {
829         XLineEndItem* pItem = NULL;
830         if( nPos == 0 )
831             pItem = new XLineEndItem();
832         else if( maLineEndList.get() && maLineEndList->Count() > (long) ( nPos - 1 ) )
833             pItem = new XLineEndItem( mpLBEnd->GetSelectEntry(), maLineEndList->GetLineEnd( nPos - 1 )->GetLineEnd() );
834         GetBindings()->GetDispatcher()->Execute(SID_ATTR_LINEEND_STYLE, SFX_CALLMODE_RECORD, pItem,  0L);
835         delete pItem;
836     }
837     return 0;
838 }
839 
840 
841 
842 
843 IMPL_LINK(LinePropertyPanel, ChangeEdgeStyleHdl, void*, EMPTYARG)
844 {
845     const sal_uInt16 nPos(mpLBEdgeStyle->GetSelectEntryPos());
846 
847     if(LISTBOX_ENTRY_NOTFOUND != nPos && nPos != mpLBEdgeStyle->GetSavedValue())
848     {
849         XLineJointItem* pItem = 0;
850 
851         switch(nPos)
852         {
853             case 0: // rounded
854             {
855                 pItem = new XLineJointItem(com::sun::star::drawing::LineJoint_ROUND);
856                 break;
857             }
858             case 1: // none
859             {
860                 pItem = new XLineJointItem(com::sun::star::drawing::LineJoint_NONE);
861                 break;
862             }
863             case 2: // mitered
864             {
865                 pItem = new XLineJointItem(com::sun::star::drawing::LineJoint_MITER);
866                 break;
867             }
868             case 3: // beveled
869             {
870                 pItem = new XLineJointItem(com::sun::star::drawing::LineJoint_BEVEL);
871                 break;
872             }
873         }
874 
875         GetBindings()->GetDispatcher()->Execute(SID_ATTR_LINE_JOINT, SFX_CALLMODE_RECORD, pItem,  0L);
876         delete pItem;
877     }
878     return 0;
879 }
880 
881 
882 
883 
884 IMPL_LINK(LinePropertyPanel, ChangeCapStyleHdl, void*, EMPTYARG)
885 {
886     const sal_uInt16 nPos(mpLBCapStyle->GetSelectEntryPos());
887 
888     if(LISTBOX_ENTRY_NOTFOUND != nPos && nPos != mpLBCapStyle->GetSavedValue())
889     {
890         XLineCapItem* pItem = 0;
891 
892         switch(nPos)
893         {
894             case 0: // flat
895             {
896                 pItem = new XLineCapItem(com::sun::star::drawing::LineCap_BUTT);
897                 break;
898             }
899             case 1: // round
900             {
901                 pItem = new XLineCapItem(com::sun::star::drawing::LineCap_ROUND);
902                 break;
903             }
904             case 2: // square
905             {
906                 pItem = new XLineCapItem(com::sun::star::drawing::LineCap_SQUARE);
907                 break;
908             }
909         }
910 
911         GetBindings()->GetDispatcher()->Execute(SID_ATTR_LINE_CAP, SFX_CALLMODE_RECORD, pItem,  0L);
912         delete pItem;
913     }
914     return 0;
915 }
916 
917 
918 
919 
920 IMPL_LINK(LinePropertyPanel, ToolboxWidthSelectHdl,ToolBox*, pToolBox)
921 {
922     if (pToolBox->GetCurItemId() == TBI_WIDTH)
923     {
924         maLineWidthPopup.SetWidthSelect(mnWidthCoreValue, mbWidthValuable, meMapUnit);
925         maLineWidthPopup.Show(*pToolBox);
926     }
927     return 0;
928 }
929 
930 
931 
932 
933 IMPL_LINK( LinePropertyPanel, ChangeTransparentHdl, void *, EMPTYARG )
934 {
935     sal_uInt16 nVal = (sal_uInt16)mpMFTransparent->GetValue();
936     XLineTransparenceItem aItem( nVal );
937 
938     GetBindings()->GetDispatcher()->Execute(SID_ATTR_LINE_STYLE, SFX_CALLMODE_RECORD, &aItem, 0L);
939     return( 0L );
940 }
941 
942 
943 
944 
945 namespace
946 {
947     Color GetTransparentColor (void)
948     {
949         return COL_TRANSPARENT;
950     }
951 } // end of anonymous namespace
952 
953 PopupControl* LinePropertyPanel::CreateColorPopupControl (PopupContainer* pParent)
954 {
955     return new ColorControl(
956         pParent,
957         mpBindings,
958         SVX_RES(RID_POPUPPANEL_LINEPAGE_COLOR),
959         SVX_RES(VS_COLOR),
960         ::boost::bind(GetTransparentColor),
961         ::boost::bind(&LinePropertyPanel::SetColor, this, _1, _2),
962         pParent,
963         0);
964 }
965 
966 
967 
968 
969 PopupControl* LinePropertyPanel::CreateLineWidthPopupControl (PopupContainer* pParent)
970 {
971     return new LineWidthControl(pParent, *this);
972 }
973 
974 
975 
976 
977 void LinePropertyPanel::EndLineWidthPopupMode (void)
978 {
979     maLineWidthPopup.Hide();
980 }
981 
982 
983 
984 
985 void LinePropertyPanel::SetWidthIcon(int n)
986 {
987     if(n==0)
988         mpTBWidth->SetItemImage( TBI_WIDTH, maIMGNone);
989     else
990         mpTBWidth->SetItemImage( TBI_WIDTH, GetDisplayBackground().GetColor().IsDark() ? mpIMGWidthIconH[n-1] : mpIMGWidthIcon[n-1]);
991 }
992 
993 
994 
995 void LinePropertyPanel::SetWidthIcon()
996 {
997     if(!mbWidthValuable)
998     {
999         mpTBWidth->SetItemImage( TBI_WIDTH, maIMGNone);
1000         return;
1001     }
1002 
1003     long nVal = LogicToLogic(mnWidthCoreValue * 10,(MapUnit)meMapUnit , MAP_POINT);
1004 
1005     if(nVal <= 6)
1006         mpTBWidth->SetItemImage( TBI_WIDTH, GetDisplayBackground().GetColor().IsDark() ? mpIMGWidthIconH[0] : mpIMGWidthIcon[0]);
1007     else if(nVal > 6 && nVal <= 9)
1008         mpTBWidth->SetItemImage( TBI_WIDTH, GetDisplayBackground().GetColor().IsDark() ? mpIMGWidthIconH[1] : mpIMGWidthIcon[1]);
1009     else if(nVal > 9 && nVal <= 12)
1010         mpTBWidth->SetItemImage( TBI_WIDTH, GetDisplayBackground().GetColor().IsDark() ? mpIMGWidthIconH[2] : mpIMGWidthIcon[2]);
1011     else if(nVal > 12 && nVal <= 19)
1012         mpTBWidth->SetItemImage( TBI_WIDTH, GetDisplayBackground().GetColor().IsDark() ? mpIMGWidthIconH[3] : mpIMGWidthIcon[3]);
1013     else if(nVal > 19 && nVal <= 26)
1014         mpTBWidth->SetItemImage( TBI_WIDTH, GetDisplayBackground().GetColor().IsDark() ? mpIMGWidthIconH[4] : mpIMGWidthIcon[4]);
1015     else if(nVal > 26 && nVal <= 37)
1016         mpTBWidth->SetItemImage( TBI_WIDTH, GetDisplayBackground().GetColor().IsDark() ? mpIMGWidthIconH[5] : mpIMGWidthIcon[5]);
1017     else if(nVal > 37 && nVal <=52)
1018         mpTBWidth->SetItemImage( TBI_WIDTH, GetDisplayBackground().GetColor().IsDark() ? mpIMGWidthIconH[6] : mpIMGWidthIcon[6]);
1019     else if(nVal > 52)
1020         mpTBWidth->SetItemImage( TBI_WIDTH, GetDisplayBackground().GetColor().IsDark() ? mpIMGWidthIconH[7] : mpIMGWidthIcon[7]);
1021 
1022 }
1023 
1024 
1025 
1026 void LinePropertyPanel::SetColor (
1027     const String& rsColorName,
1028     const Color aColor)
1029 {
1030     XLineColorItem aColorItem(rsColorName, aColor);
1031     mpBindings->GetDispatcher()->Execute(SID_ATTR_LINE_COLOR, SFX_CALLMODE_RECORD, &aColorItem, 0L);
1032     maColor = aColor;
1033 }
1034 
1035 
1036 
1037 void LinePropertyPanel::SetWidth(long nWidth)
1038 {
1039     mnWidthCoreValue = nWidth;
1040     mbWidthValuable = true;
1041 }
1042 
1043 
1044 
1045 void  LinePropertyPanel::FillLineEndList()
1046 {
1047     SfxObjectShell* pSh = SfxObjectShell::Current();
1048     if ( pSh && pSh->GetItem( SID_LINEEND_LIST ) )
1049     {
1050         mpLBStart->Enable();
1051         SvxLineEndListItem aItem( *(const SvxLineEndListItem*)(pSh->GetItem( SID_LINEEND_LIST ) ) );
1052         maLineEndList = aItem.GetLineEndList();
1053 
1054         if(maLineEndList.get())
1055         {
1056             FillLineEndListBox(*mpLBStart, *mpLBEnd, maLineEndList);
1057         }
1058 
1059         mpLBStart->SelectEntryPos(0);
1060         mpLBEnd->SelectEntryPos(0);
1061     }
1062     else
1063     {
1064         mpLBStart->Disable();
1065         mpLBEnd->Disable();
1066     }
1067 }
1068 
1069 
1070 
1071 void  LinePropertyPanel::FillLineStyleList()
1072 {
1073     SfxObjectShell* pSh = SfxObjectShell::Current();
1074     if ( pSh && pSh->GetItem( SID_DASH_LIST ) )
1075     {
1076         mpLBStyle->Enable();
1077         SvxDashListItem aItem( *(const SvxDashListItem*)(pSh->GetItem( SID_DASH_LIST ) ) );
1078         maLineStyleList = aItem.GetDashList();
1079 
1080         if(maLineStyleList.get())
1081         {
1082             FillLineStyleListBox(*mpLBStyle, maLineStyleList);
1083         }
1084 
1085         mpLBStyle->SelectEntryPos(0);
1086     }
1087     else
1088     {
1089         mpLBStyle->Disable();
1090     }
1091 }
1092 
1093 
1094 
1095 void LinePropertyPanel::SelectLineStyle()
1096 {
1097     if( !mpStyleItem.get() || !mpDashItem.get() )
1098     {
1099         mpLBStyle->SetNoSelection();
1100         mpLBStyle->Disable();
1101         return;
1102     }
1103 
1104     const XLineStyle eXLS(mpStyleItem ? (XLineStyle)mpStyleItem->GetValue() : XLINE_NONE);
1105     bool bSelected(false);
1106 
1107     switch(eXLS)
1108     {
1109         case XLINE_NONE:
1110             break;
1111         case XLINE_SOLID:
1112             mpLBStyle->SelectEntryPos(1);
1113             bSelected = true;
1114             break;
1115         default:
1116             if(mpDashItem && maLineStyleList.get())
1117             {
1118                 const XDash& rDash = mpDashItem->GetDashValue();
1119                 for(sal_Int32 a(0);!bSelected &&  a < maLineStyleList->Count(); a++)
1120                 {
1121                     XDashEntry* pEntry = maLineStyleList->GetDash(a);
1122                     const XDash& rEntry = pEntry->GetDash();
1123                     if(rDash == rEntry)
1124                     {
1125                         mpLBStyle->SelectEntryPos((sal_uInt16)a + 2);
1126                         bSelected = true;
1127                     }
1128                 }
1129             }
1130             break;
1131     }
1132 
1133     if(!bSelected)
1134         mpLBStyle->SelectEntryPos( 0 );
1135 }
1136 
1137 void LinePropertyPanel::SelectEndStyle(bool bStart)
1138 {
1139     sal_Bool bSelected(false);
1140 
1141     if(bStart)
1142     {
1143         if( !mpStartItem.get() )
1144         {
1145             mpLBStart->SetNoSelection();
1146             mpLBStart->Disable();
1147             return;
1148         }
1149 
1150         if(mpStartItem && maLineEndList.get())
1151         {
1152             const basegfx::B2DPolyPolygon& rItemPolygon = mpStartItem->GetLineStartValue();
1153             for(sal_Int32 a(0);!bSelected &&  a < maLineEndList->Count(); a++)
1154             {
1155                 XLineEndEntry* pEntry = maLineEndList->GetLineEnd(a);
1156                 const basegfx::B2DPolyPolygon& rEntryPolygon = pEntry->GetLineEnd();
1157                 if(rItemPolygon == rEntryPolygon)
1158                 {
1159                     mpLBStart->SelectEntryPos((sal_uInt16)a + 1);
1160                     bSelected = true;
1161                 }
1162             }
1163         }
1164 
1165         if(!bSelected)
1166         {
1167             mpLBStart->SelectEntryPos( 0 );
1168         }
1169     }
1170     else
1171     {
1172         if( !mpEndItem.get() )
1173         {
1174             mpLBEnd->SetNoSelection();
1175             mpLBEnd->Disable();
1176             return;
1177         }
1178 
1179         if(mpEndItem && maLineEndList.get())
1180         {
1181             const basegfx::B2DPolyPolygon& rItemPolygon = mpEndItem->GetLineEndValue();
1182             for(sal_Int32 a(0);!bSelected &&  a < maLineEndList->Count(); a++)
1183             {
1184                 XLineEndEntry* pEntry = maLineEndList->GetLineEnd(a);
1185                 const basegfx::B2DPolyPolygon& rEntryPolygon = pEntry->GetLineEnd();
1186                 if(rItemPolygon == rEntryPolygon)
1187                 {
1188                     mpLBEnd->SelectEntryPos((sal_uInt16)a + 1);
1189                     bSelected = true;
1190                 }
1191             }
1192         }
1193 
1194         if(!bSelected)
1195         {
1196             mpLBEnd->SelectEntryPos( 0 );
1197         }
1198     }
1199 }
1200 
1201 
1202 } } // end of namespace svx::sidebar
1203 
1204 // eof
1205