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