2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 #include "LineWidthControl.hxx"
19 #include "LinePropertyPanel.hrc"
20 #include "LinePropertyPanel.hxx"
22 #include <svx/dialogs.hrc>
23 #include <svx/dialmgr.hxx>
24 #include <sfx2/sidebar/ResourceDefinitions.hrc>
25 #include <comphelper/processfactory.hxx>
26 #include <vcl/svapp.hxx>
27 #include <unotools/viewoptions.hxx>
28 #include <svx/xlnwtit.hxx>
29 #include <sfx2/bindings.hxx>
30 #include <sfx2/dispatch.hxx>
31 #include "svx/sidebar/PopupContainer.hxx"
34 namespace svx
{ namespace sidebar
{
36 LineWidthControl::LineWidthControl (
38 LinePropertyPanel
& rPanel
)
39 : svx::sidebar::PopupControl(pParent
,SVX_RES(RID_POPUPPANEL_LINEPAGE_WIDTH
)),
40 mrLinePropertyPanel(rPanel
),
42 maVSWidth( this, SVX_RES(VS_WIDTH
)),
43 maFTCus( this, SVX_RES(FT_CUSTOME
)),
44 maFTWidth( this, SVX_RES(FT_LINE_WIDTH
)),
45 maMFWidth( this, SVX_RES(MF_WIDTH
)),
46 meMapUnit(SFX_MAPUNIT_TWIP
),
48 mstrPT(SVX_RES(STR_PT
)),
54 maIMGCus(SVX_RES(IMG_WIDTH_CUSTOM
)),
55 maIMGCusGray(SVX_RES(IMG_WIDTH_CUSTOM_GRAY
))
59 mpBindings
= mrLinePropertyPanel
.GetBindings();
65 LineWidthControl::~LineWidthControl (void)
73 void LineWidthControl::Paint(const Rectangle
& rect
)
75 svx::sidebar::PopupControl::Paint(rect
);
77 Color aOldLineColor
= GetLineColor();
78 Color aOldFillColor
= GetFillColor();
80 Point
aPos( LogicToPixel( Point( CUSTOM_X
, CUSTOM_Y
), MAP_APPFONT
));
81 Size
aSize( LogicToPixel( Size( CUSTOM_W
, CUSTOM_H
), MAP_APPFONT
));
82 Rectangle
aRect( aPos
, aSize
);
88 Color
aLineColor(189,201,219);
89 if(!GetSettings().GetStyleSettings().GetHighContrastMode())
90 SetLineColor(aLineColor
);
92 SetLineColor(GetSettings().GetStyleSettings().GetShadowColor());
93 SetFillColor(COL_TRANSPARENT
);
96 SetLineColor(aOldLineColor
);
97 SetFillColor(aOldFillColor
);
103 void LineWidthControl::Initialize()
105 maVSWidth
.SetStyle( maVSWidth
.GetStyle()| WB_3DLOOK
| WB_NO_DIRECTSELECT
);// WB_NAMEFIELD | WB_ITEMBORDER |WB_DOUBLEBORDER | WB_NONEFIELD |
106 //for high contrast wj
107 if(GetSettings().GetStyleSettings().GetHighContrastMode())
109 maVSWidth
.SetColor(GetSettings().GetStyleSettings().GetMenuColor());
110 // maBorder.SetBackground(GetSettings().GetStyleSettings().GetMenuColor());
111 maFTWidth
.SetBackground(GetSettings().GetStyleSettings().GetMenuColor());
115 maVSWidth
.SetColor(COL_WHITE
);
116 // maBorder.SetBackground(Wallpaper(COL_WHITE));
117 maFTWidth
.SetBackground(Wallpaper(COL_WHITE
));
120 sal_Int64 nFirst
= maMFWidth
.Denormalize( maMFWidth
.GetFirst( FUNIT_TWIP
) );
121 sal_Int64 nLast
= maMFWidth
.Denormalize( maMFWidth
.GetLast( FUNIT_TWIP
) );
122 sal_Int64 nMin
= maMFWidth
.Denormalize( maMFWidth
.GetMin( FUNIT_TWIP
) );
123 sal_Int64 nMax
= maMFWidth
.Denormalize( maMFWidth
.GetMax( FUNIT_TWIP
) );
124 maMFWidth
.SetSpinSize( 10 );
125 maMFWidth
.SetUnit( FUNIT_POINT
);
126 if( maMFWidth
.GetDecimalDigits() > 1 )
127 maMFWidth
.SetDecimalDigits( 1 );
128 maMFWidth
.SetFirst( maMFWidth
.Normalize( nFirst
), FUNIT_TWIP
);
129 maMFWidth
.SetLast( maMFWidth
.Normalize( nLast
), FUNIT_TWIP
);
130 maMFWidth
.SetMin( maMFWidth
.Normalize( nMin
), FUNIT_TWIP
);
131 maMFWidth
.SetMax( maMFWidth
.Normalize( nMax
), FUNIT_TWIP
);
133 rStr
= new XubString
[9];
135 rStr
[0] = String("05", 2, RTL_TEXTENCODING_ASCII_US
);
136 rStr
[1] = String("08", 2, RTL_TEXTENCODING_ASCII_US
);
137 rStr
[2] = String("10", 2, RTL_TEXTENCODING_ASCII_US
);
138 rStr
[3] = String("15", 2, RTL_TEXTENCODING_ASCII_US
);
139 rStr
[4] = String("23", 2, RTL_TEXTENCODING_ASCII_US
);
140 rStr
[5] = String("30", 2, RTL_TEXTENCODING_ASCII_US
);
141 rStr
[6] = String("45", 2, RTL_TEXTENCODING_ASCII_US
);
142 rStr
[7] = String("60", 2, RTL_TEXTENCODING_ASCII_US
);
143 rStr
[8] = String( SVX_RES(STR_WIDTH_LAST_CUSTOM
) );
145 const LocaleDataWrapper
& rLocaleWrapper( Application::GetSettings().GetLocaleDataWrapper() );
146 const sal_Unicode cSep
= rLocaleWrapper
.getNumDecimalSep()[0];
148 for(int i
= 0; i
<= 7 ; i
++)
150 rStr
[i
] = rStr
[i
].Insert(cSep
, 1);//Modify
151 rStr
[i
].Append(mstrPT
);
155 for(sal_uInt16 i
= 1 ; i
<= 9 ; i
++)
157 maVSWidth
.InsertItem(i
);
158 maVSWidth
.SetItemText(i
, rStr
[i
-1]);
160 maVSWidth
.SetUnit(rStr
);
161 maVSWidth
.SetItemData(1,(void*)5);
162 maVSWidth
.SetItemData(2,(void*)8);
163 maVSWidth
.SetItemData(3,(void*)10);
164 maVSWidth
.SetItemData(4,(void*)15);
165 maVSWidth
.SetItemData(5,(void*)23);
166 maVSWidth
.SetItemData(6,(void*)30);
167 maVSWidth
.SetItemData(7,(void*)45);
168 maVSWidth
.SetItemData(8,(void*)60);
169 maVSWidth
.SetImage(maIMGCusGray
);
171 maVSWidth
.SetSelItem(0);
172 Link aLink
= LINK( this, LineWidthControl
, VSSelectHdl
) ;
173 maVSWidth
.SetSelectHdl(aLink
);
174 aLink
= LINK(this, LineWidthControl
, MFModifyHdl
);
175 maMFWidth
.SetModifyHdl(aLink
);
177 maVSWidth
.StartSelection();
184 void LineWidthControl::GetFocus()
187 maMFWidth
.GrabFocus();
189 maVSWidth
.GrabFocus();
195 ValueSet
& LineWidthControl::GetValueSet()
203 void LineWidthControl::SetWidthSelect( long lValue
, bool bValuable
, SfxMapUnit eMapUnit
)
206 maVSWidth
.SetSelItem(0);
207 mbColseByEdit
= false;
208 meMapUnit
= eMapUnit
;
209 SvtViewOptions
aWinOpt( E_WINDOW
, SIDEBAR_LINE_WIDTH_GLOBAL_VALUE
);
210 if ( aWinOpt
.Exists() )
212 ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::NamedValue
> aSeq
= aWinOpt
.GetUserData();
213 ::rtl::OUString aTmp
;
214 if ( aSeq
.getLength())
215 aSeq
[0].Value
>>= aTmp
;
217 String
aWinData( aTmp
);
218 mnCustomWidth
= aWinData
.ToInt32();
220 maVSWidth
.SetImage(maIMGCus
);
221 maVSWidth
.SetCusEnable(true);
223 String
aStrTip( OUString::number( (double)mnCustomWidth
/ 10));
224 aStrTip
.Append(mstrPT
); //
225 maVSWidth
.SetItemText(9, aStrTip
);
230 maVSWidth
.SetImage(maIMGCusGray
);
231 maVSWidth
.SetCusEnable(false);
233 //String aStrTip(String(SVX_RES(STR_WIDTH_LAST_CUSTOM)));
234 //maVSWidth.SetItemText(9, aStrTip);
235 maVSWidth
.SetItemText(9, rStr
[8]);
240 sal_Int64 nVal
= OutputDevice::LogicToLogic( lValue
, (MapUnit
)eMapUnit
, MAP_100TH_MM
);
241 nVal
= maMFWidth
.Normalize( nVal
);
242 maMFWidth
.SetValue( nVal
, FUNIT_100TH_MM
);
246 maMFWidth
.SetText( String() );
249 MapUnit eOrgUnit
= (MapUnit
)eMapUnit
;
250 MapUnit
ePntUnit( MAP_TWIP
);
251 lValue
= LogicToLogic( lValue
, eOrgUnit
, ePntUnit
);
253 XubString strCurrValue
= maMFWidth
.GetText();
256 if(strCurrValue
== rStr
[i
])
258 maVSWidth
.SetSelItem(i
+1);
264 maVSWidth
.SetSelItem(0);
267 maVSWidth
.StartSelection();
273 IMPL_LINK(LineWidthControl
, VSSelectHdl
, void *, pControl
)
275 if(pControl
== &maVSWidth
)
277 sal_uInt16 iPos
= maVSWidth
.GetSelectItemId();
278 if(iPos
>= 1 && iPos
<= 8)
280 long nVal
= LogicToLogic((long)(unsigned long)maVSWidth
.GetItemData( iPos
) , MAP_POINT
, (MapUnit
)meMapUnit
);
281 nVal
= maMFWidth
.Denormalize(nVal
);
282 XLineWidthItem
aWidthItem( nVal
);
283 mpBindings
->GetDispatcher()->Execute(SID_ATTR_LINE_WIDTH
, SFX_CALLMODE_RECORD
, &aWidthItem
, 0L);
284 mrLinePropertyPanel
.SetWidthIcon(iPos
);
285 mrLinePropertyPanel
.SetWidth(nVal
);
286 mbColseByEdit
= false;
294 long nVal
= LogicToLogic(mnCustomWidth
, MAP_POINT
, (MapUnit
)meMapUnit
);
295 nVal
= maMFWidth
.Denormalize(nVal
);
296 XLineWidthItem
aWidthItem( nVal
);
297 mpBindings
->GetDispatcher()->Execute(SID_ATTR_LINE_WIDTH
, SFX_CALLMODE_RECORD
, &aWidthItem
, 0L);
298 mrLinePropertyPanel
.SetWidth(nVal
);
299 mbColseByEdit
= false;
304 maVSWidth
.SetNoSelection(); //add , set no selection and keep the last select item
307 maVSWidth
.StartSelection();
311 if((iPos
>= 1 && iPos
<= 8) || (iPos
== 9 && mbCustom
)) //add
312 mrLinePropertyPanel
.EndLineWidthPopupMode();
320 IMPL_LINK(LineWidthControl
, MFModifyHdl
, void *, pControl
)
322 if(pControl
== &maMFWidth
)
324 if(maVSWidth
.GetSelItem())
326 maVSWidth
.SetSelItem(0);
329 maVSWidth
.StartSelection();
331 long nTmp
= static_cast<long>(maMFWidth
.GetValue());
332 long nVal
= LogicToLogic( nTmp
, MAP_POINT
, (MapUnit
)meMapUnit
);
333 sal_Int32 nNewWidth
= (short)maMFWidth
.Denormalize( nVal
);
334 XLineWidthItem
aWidthItem(nNewWidth
);
335 mpBindings
->GetDispatcher()->Execute(SID_ATTR_LINE_WIDTH
, SFX_CALLMODE_RECORD
, &aWidthItem
, 0L);
337 mbColseByEdit
= true;
338 mnTmpCusomWidth
= nTmp
;
339 /*for(sal_uInt16 i = 0; i < 8; i++)
341 if(nTmp == (sal_Int32)maVSWidth.GetItemData(i))
343 mbColseByEdit = false;
355 bool LineWidthControl::IsCloseByEdit()
357 return mbColseByEdit
;
363 long LineWidthControl::GetTmpCustomWidth()
365 return mnTmpCusomWidth
;
370 } } // end of namespace svx::sidebar