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