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 XLineDashItem aItemB(mpLBStyle->GetSelectEntry(), mpLineStyleList->GetDash(nPos - 2)->GetDash());
764 
765             GetBindings()->GetDispatcher()->Execute(SID_ATTR_LINE_STYLE, SFX_CALLMODE_RECORD, &aItemA, 0L);
766             GetBindings()->GetDispatcher()->Execute(SID_ATTR_LINE_DASH, SFX_CALLMODE_RECORD, &aItemB, 0L);
767         }
768     }
769 
770     return 0;
771 }
772 
773 
774 
775 IMPL_LINK(LinePropertyPanel, ChangeStartHdl, void*, EMPTYARG)
776 {
777 	sal_uInt16	nPos = mpLBStart->GetSelectEntryPos();
778 	if( nPos != LISTBOX_ENTRY_NOTFOUND && nPos != mpLBStart->GetSavedValue() )
779 	{
780 		XLineStartItem* pItem = NULL;
781 		if( nPos == 0 )
782 			pItem = new XLineStartItem();
783 		else if( mpLineEndList && mpLineEndList->Count() > (long) ( nPos - 1 ) )
784 			pItem = new XLineStartItem( mpLBStart->GetSelectEntry(),mpLineEndList->GetLineEnd( nPos - 1 )->GetLineEnd() );
785 		GetBindings()->GetDispatcher()->Execute(SID_ATTR_LINEEND_STYLE, SFX_CALLMODE_RECORD, pItem,  0L);
786 		delete pItem;
787 	}
788 	return 0;
789 }
790 
791 
792 
793 
794 IMPL_LINK(LinePropertyPanel, ChangeEndHdl, void*, EMPTYARG)
795 {
796 	sal_uInt16	nPos = mpLBEnd->GetSelectEntryPos();
797 	if( nPos != LISTBOX_ENTRY_NOTFOUND && nPos != mpLBEnd->GetSavedValue() )
798 	{
799 		XLineEndItem* pItem = NULL;
800 		if( nPos == 0 )
801 			pItem = new XLineEndItem();
802 		else if( mpLineEndList && mpLineEndList->Count() > (long) ( nPos - 1 ) )
803 			pItem = new XLineEndItem( mpLBEnd->GetSelectEntry(), mpLineEndList->GetLineEnd( nPos - 1 )->GetLineEnd() );
804 		GetBindings()->GetDispatcher()->Execute(SID_ATTR_LINEEND_STYLE, SFX_CALLMODE_RECORD, pItem,  0L);
805 		delete pItem;
806 	}
807 	return 0;
808 }
809 
810 
811 
812 
813 IMPL_LINK(LinePropertyPanel, ChangeEdgeStyleHdl, void*, EMPTYARG)
814 {
815     const sal_uInt16 nPos(mpLBEdgeStyle->GetSelectEntryPos());
816 
817     if(LISTBOX_ENTRY_NOTFOUND != nPos && nPos != mpLBEdgeStyle->GetSavedValue())
818     {
819         XLineJointItem* pItem = 0;
820 
821         switch(nPos)
822         {
823             case 0: // rounded
824             {
825                 pItem = new XLineJointItem(com::sun::star::drawing::LineJoint_ROUND);
826                 break;
827             }
828             case 1: // none
829             {
830                 pItem = new XLineJointItem(com::sun::star::drawing::LineJoint_NONE);
831                 break;
832             }
833             case 2: // mitered
834             {
835                 pItem = new XLineJointItem(com::sun::star::drawing::LineJoint_MITER);
836                 break;
837             }
838             case 3: // beveled
839             {
840                 pItem = new XLineJointItem(com::sun::star::drawing::LineJoint_BEVEL);
841                 break;
842             }
843         }
844 
845         GetBindings()->GetDispatcher()->Execute(SID_ATTR_LINE_JOINT, SFX_CALLMODE_RECORD, pItem,  0L);
846         delete pItem;
847     }
848     return 0;
849 }
850 
851 
852 
853 
854 IMPL_LINK(LinePropertyPanel, ChangeCapStyleHdl, void*, EMPTYARG)
855 {
856     const sal_uInt16 nPos(mpLBCapStyle->GetSelectEntryPos());
857 
858     if(LISTBOX_ENTRY_NOTFOUND != nPos && nPos != mpLBCapStyle->GetSavedValue())
859     {
860         XLineCapItem* pItem = 0;
861 
862         switch(nPos)
863         {
864             case 0: // flat
865             {
866                 pItem = new XLineCapItem(com::sun::star::drawing::LineCap_BUTT);
867                 break;
868             }
869             case 1: // round
870             {
871                 pItem = new XLineCapItem(com::sun::star::drawing::LineCap_ROUND);
872                 break;
873             }
874             case 2: // square
875             {
876                 pItem = new XLineCapItem(com::sun::star::drawing::LineCap_SQUARE);
877                 break;
878             }
879         }
880 
881         GetBindings()->GetDispatcher()->Execute(SID_ATTR_LINE_CAP, SFX_CALLMODE_RECORD, pItem,  0L);
882         delete pItem;
883     }
884     return 0;
885 }
886 
887 
888 
889 
890 IMPL_LINK(LinePropertyPanel, ToolboxWidthSelectHdl,ToolBox*, pToolBox)
891 {
892 	if (pToolBox->GetCurItemId() == TBI_WIDTH)
893 	{
894 		maLineWidthPopup.SetWidthSelect(mnWidthCoreValue, mbWidthValuable, meMapUnit);
895         maLineWidthPopup.Show(*pToolBox);
896 	}
897 	return 0;
898 }
899 
900 
901 
902 
903 IMPL_LINK( LinePropertyPanel, ChangeTransparentHdl, void *, EMPTYARG )
904 {
905 	sal_uInt16 nVal = (sal_uInt16)mpMFTransparent->GetValue();
906 	XLineTransparenceItem aItem( nVal );
907 
908 	GetBindings()->GetDispatcher()->Execute(SID_ATTR_LINE_STYLE, SFX_CALLMODE_RECORD, &aItem, 0L);
909 	return( 0L );
910 }
911 
912 
913 
914 
915 PopupControl* LinePropertyPanel::CreateColorPopupControl (PopupContainer* pParent)
916 {
917     const ResId aResId(SVX_RES(STR_AUTOMATICE));
918 
919     return new ColorControl(
920         pParent,
921         mpBindings,
922         SVX_RES(RID_POPUPPANEL_LINEPAGE_COLOR),
923         SVX_RES(VS_COLOR),
924         ::boost::bind(GetTransparentColor),
925         ::boost::bind(&LinePropertyPanel::SetColor, this, _1, _2),
926         pParent,
927         &aResId);
928 }
929 
930 
931 
932 
933 PopupControl* LinePropertyPanel::CreateLineWidthPopupControl (PopupContainer* pParent)
934 {
935     return new LineWidthControl(pParent, *this);
936 }
937 
938 
939 
940 
941 void LinePropertyPanel::EndLineWidthPopupMode (void)
942 {
943     maLineWidthPopup.Hide();
944 }
945 
946 
947 
948 
949 void LinePropertyPanel::SetWidthIcon(int n)
950 {
951 	if(n==0)
952 		mpTBWidth->SetItemImage( TBI_WIDTH, maIMGNone);
953 	else
954 		mpTBWidth->SetItemImage( TBI_WIDTH, GetDisplayBackground().GetColor().IsDark() ? mpIMGWidthIconH[n-1] : mpIMGWidthIcon[n-1]);
955 }
956 
957 
958 
959 void LinePropertyPanel::SetWidthIcon()
960 {
961 	if(!mbWidthValuable)
962 	{
963 		mpTBWidth->SetItemImage( TBI_WIDTH, maIMGNone);
964 		return;
965 	}
966 
967 	long nVal = LogicToLogic(mnWidthCoreValue * 10,(MapUnit)meMapUnit , MAP_POINT);
968 
969 	if(nVal <= 6)
970 		mpTBWidth->SetItemImage( TBI_WIDTH, GetDisplayBackground().GetColor().IsDark() ? mpIMGWidthIconH[0] : mpIMGWidthIcon[0]);
971 	else if(nVal > 6 && nVal <= 9)
972 		mpTBWidth->SetItemImage( TBI_WIDTH, GetDisplayBackground().GetColor().IsDark() ? mpIMGWidthIconH[1] : mpIMGWidthIcon[1]);
973 	else if(nVal > 9 && nVal <= 12)
974 		mpTBWidth->SetItemImage( TBI_WIDTH, GetDisplayBackground().GetColor().IsDark() ? mpIMGWidthIconH[2] : mpIMGWidthIcon[2]);
975 	else if(nVal > 12 && nVal <= 19)
976 		mpTBWidth->SetItemImage( TBI_WIDTH, GetDisplayBackground().GetColor().IsDark() ? mpIMGWidthIconH[3] : mpIMGWidthIcon[3]);
977 	else if(nVal > 19 && nVal <= 26)
978 		mpTBWidth->SetItemImage( TBI_WIDTH, GetDisplayBackground().GetColor().IsDark() ? mpIMGWidthIconH[4] : mpIMGWidthIcon[4]);
979 	else if(nVal > 26 && nVal <= 37)
980 		mpTBWidth->SetItemImage( TBI_WIDTH, GetDisplayBackground().GetColor().IsDark() ? mpIMGWidthIconH[5] : mpIMGWidthIcon[5]);
981 	else if(nVal > 37 && nVal <=52)
982 		mpTBWidth->SetItemImage( TBI_WIDTH, GetDisplayBackground().GetColor().IsDark() ? mpIMGWidthIconH[6] : mpIMGWidthIcon[6]);
983 	else if(nVal > 52)
984 		mpTBWidth->SetItemImage( TBI_WIDTH, GetDisplayBackground().GetColor().IsDark() ? mpIMGWidthIconH[7] : mpIMGWidthIcon[7]);
985 
986 }
987 
988 
989 
990 void LinePropertyPanel::SetColor (
991     const String& rsColorName,
992     const Color aColor)
993 {
994     XLineColorItem aColorItem(rsColorName, aColor);
995     mpBindings->GetDispatcher()->Execute(SID_ATTR_LINE_COLOR, SFX_CALLMODE_RECORD, &aColorItem, 0L);
996     maColor = aColor;
997 }
998 
999 
1000 
1001 void LinePropertyPanel::SetWidth(long nWidth)
1002 {
1003     mnWidthCoreValue = nWidth;
1004     mbWidthValuable = true;
1005 }
1006 
1007 
1008 
1009 void  LinePropertyPanel::FillLineEndList()
1010 {
1011 	SfxObjectShell* pSh = SfxObjectShell::Current();
1012 	if ( pSh && pSh->GetItem( SID_LINEEND_LIST ) )
1013 	{
1014 		mpLBStart->Enable();
1015 		SvxLineEndListItem aItem( *(const SvxLineEndListItem*)(pSh->GetItem( SID_LINEEND_LIST ) ) );
1016 		mpLineEndList = aItem.GetLineEndList();
1017 
1018         if(mpLineEndList)
1019 		{
1020             FillLineEndListBox(*mpLBStart, *mpLBEnd, *mpLineEndList);
1021 		}
1022 
1023 		mpLBStart->SelectEntryPos(0);
1024 		mpLBEnd->SelectEntryPos(0);
1025 	}
1026 	else
1027 	{
1028 		mpLBStart->Disable();
1029 		mpLBEnd->Disable();
1030 	}
1031 }
1032 
1033 
1034 
1035 void  LinePropertyPanel::FillLineStyleList()
1036 {
1037 	SfxObjectShell* pSh = SfxObjectShell::Current();
1038 	if ( pSh && pSh->GetItem( SID_DASH_LIST ) )
1039 	{
1040 		mpLBStyle->Enable();
1041 		SvxDashListItem aItem( *(const SvxDashListItem*)(pSh->GetItem( SID_DASH_LIST ) ) );
1042 		mpLineStyleList = aItem.GetDashList();
1043 
1044         if(mpLineStyleList)
1045 		{
1046             FillLineStyleListBox(*mpLBStyle, *mpLineStyleList);
1047 		}
1048 
1049 		mpLBStyle->SelectEntryPos(0);
1050 	}
1051 	else
1052 	{
1053 		mpLBStyle->Disable();
1054 	}
1055 }
1056 
1057 
1058 
1059 void LinePropertyPanel::SelectLineStyle()
1060 {
1061 	if( !mbStyleAvailable || !mbDashAvailable )
1062 	{
1063 		mpLBStyle->SetNoSelection();
1064 		return;
1065 	}
1066 
1067     const XLineStyle eXLS(mpStyleItem ? (XLineStyle)mpStyleItem->GetValue() : XLINE_NONE);
1068 	bool bSelected(false);
1069 
1070     switch(eXLS)
1071     {
1072         case XLINE_NONE:
1073             break;
1074         case XLINE_SOLID:
1075 			mpLBStyle->SelectEntryPos(1);
1076 			bSelected = true;
1077             break;
1078         default:
1079             if(mpDashItem && mpLineStyleList)
1080 	        {
1081 		        const XDash& rDash = mpDashItem->GetDashValue();
1082 		        for(sal_Int32 a(0);!bSelected &&  a < mpLineStyleList->Count(); a++)
1083 		        {
1084 			        XDashEntry* pEntry = mpLineStyleList->GetDash(a);
1085 			        const XDash& rEntry = pEntry->GetDash();
1086 			        if(rDash == rEntry)
1087 			        {
1088 				        mpLBStyle->SelectEntryPos((sal_uInt16)a + 2);
1089 				        bSelected = true;
1090 			        }
1091 		        }
1092 	        }
1093             break;
1094     }
1095 
1096     if(!bSelected)
1097 		mpLBStyle->SelectEntryPos( 0 );
1098 }
1099 
1100 void LinePropertyPanel::SelectEndStyle(bool bStart)
1101 {
1102 	sal_Bool bSelected(false);
1103 
1104 	if(bStart)
1105 	{
1106 		//<<add
1107 		if( !mbStartAvailable )
1108 		{
1109 			mpLBStart->SetNoSelection();
1110 			return;
1111 		}
1112 		//add end>>
1113 		if(mpStartItem && mpLineEndList)
1114 		{
1115 			const basegfx::B2DPolyPolygon& rItemPolygon = mpStartItem->GetLineStartValue();
1116 			for(sal_Int32 a(0);!bSelected &&  a < mpLineEndList->Count(); a++)
1117 			{
1118 				XLineEndEntry* pEntry = mpLineEndList->GetLineEnd(a);
1119 				const basegfx::B2DPolyPolygon& rEntryPolygon = pEntry->GetLineEnd();
1120 				if(rItemPolygon == rEntryPolygon)
1121 				{
1122 					mpLBStart->SelectEntryPos((sal_uInt16)a + 1);
1123 					bSelected = true;
1124 				}
1125 			}
1126 		}
1127 		if(!bSelected)
1128 			mpLBStart->SelectEntryPos( 0 );
1129 	}
1130 	else
1131 	{
1132 		//<<add
1133 		if( !mbEndAvailable )
1134 		{
1135 			mpLBEnd->SetNoSelection();
1136 			return;
1137 		}
1138 		//add end>>
1139 		if(mpEndItem && mpLineEndList)
1140 		{
1141 			const basegfx::B2DPolyPolygon& rItemPolygon = mpEndItem->GetLineEndValue();
1142 			for(sal_Int32 a(0);!bSelected &&  a < mpLineEndList->Count(); a++)
1143 			{
1144 				XLineEndEntry* pEntry = mpLineEndList->GetLineEnd(a);
1145 				const basegfx::B2DPolyPolygon& rEntryPolygon = pEntry->GetLineEnd();
1146 				if(rItemPolygon == rEntryPolygon)
1147 				{
1148 					mpLBEnd->SelectEntryPos((sal_uInt16)a + 1);
1149 					bSelected = true;
1150 				}
1151 			}
1152 		}
1153 		if(!bSelected)
1154 			mpLBEnd->SelectEntryPos( 0 );
1155 	}
1156 }
1157 
1158 
1159 } } // end of namespace svx::sidebar
1160 
1161 // eof
1162