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