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 "LineWidthControl.hxx"
23 #include "LinePropertyPanel.hrc"
24 #include "LinePropertyPanel.hxx"
25 
26 #include <svx/dialogs.hrc>
27 #include <svx/dialmgr.hxx>
28 #include <sfx2/sidebar/ResourceDefinitions.hrc>
29 #include <comphelper/processfactory.hxx>
30 #include <vcl/svapp.hxx>
31 #include <unotools/viewoptions.hxx>
32 #include <svx/xlnwtit.hxx>
33 #include <sfx2/bindings.hxx>
34 #include <sfx2/dispatch.hxx>
35 #include "svx/sidebar/PopupContainer.hxx"
36 
37 
38 namespace svx { namespace sidebar {
39 
LineWidthControl(Window * pParent,LinePropertyPanel & rPanel)40 LineWidthControl::LineWidthControl (
41     Window* pParent,
42     LinePropertyPanel& rPanel)
43     : svx::sidebar::PopupControl(pParent,SVX_RES(RID_POPUPPANEL_LINEPAGE_WIDTH)),
44       mrLinePropertyPanel(rPanel),
45       mpBindings(NULL),
46       maVSWidth( this, SVX_RES(VS_WIDTH)),
47       maFTCus( this, SVX_RES(FT_CUSTOME)),
48       maFTWidth( this, SVX_RES(FT_LINE_WIDTH)),
49       maMFWidth( this, SVX_RES(MF_WIDTH)),
50       meMapUnit(SFX_MAPUNIT_TWIP),
51       rStr(NULL),
52       mstrPT(SVX_RES(STR_PT)),
53       mnCustomWidth(0),
54       mbCustom(false),
55       mbColseByEdit(false),
56       mnTmpCusomWidth(0),
57       mbVSFocus(true),
58       maIMGCus(SVX_RES(IMG_WIDTH_CUSTOM)),
59       maIMGCusGray(SVX_RES(IMG_WIDTH_CUSTOM_GRAY))
60 {
61 	Initialize();
62 	FreeResource();
63 	mpBindings = mrLinePropertyPanel.GetBindings();
64 }
65 
66 
67 
68 
~LineWidthControl(void)69 LineWidthControl::~LineWidthControl (void)
70 {
71 	delete[] rStr;
72 }
73 
74 
75 
76 
Paint(const Rectangle & rect)77 void LineWidthControl::Paint(const Rectangle& rect)
78 {
79 	svx::sidebar::PopupControl::Paint(rect);
80 
81 	Color aOldLineColor = GetLineColor();
82 	Color aOldFillColor = GetFillColor();
83 
84 	Point aPos( LogicToPixel( Point( CUSTOM_X, CUSTOM_Y), MAP_APPFONT ));
85 	Size aSize( LogicToPixel( Size(  CUSTOM_W, CUSTOM_H ), MAP_APPFONT ));
86 	Rectangle aRect( aPos, aSize );
87 	aRect.Left() -= 1;
88 	aRect.Top() -= 1;
89 	aRect.Right() += 1;
90 	aRect.Bottom() += 1;
91 
92 	Color aLineColor(189,201,219);
93 	if(!GetSettings().GetStyleSettings().GetHighContrastMode())
94 		SetLineColor(aLineColor);
95 	else
96 		SetLineColor(GetSettings().GetStyleSettings().GetShadowColor());
97 	SetFillColor(COL_TRANSPARENT);
98 	DrawRect(aRect);
99 
100 	SetLineColor(aOldLineColor);
101 	SetFillColor(aOldFillColor);
102 }
103 
104 
105 
106 
Initialize()107 void LineWidthControl::Initialize()
108 {
109 	maVSWidth.SetStyle( maVSWidth.GetStyle()| WB_3DLOOK |  WB_NO_DIRECTSELECT  );// WB_NAMEFIELD | WB_ITEMBORDER |WB_DOUBLEBORDER | WB_NONEFIELD |
110 	//for high contract wj
111 	if(GetSettings().GetStyleSettings().GetHighContrastMode())
112 	{
113 		maVSWidth.SetColor(GetSettings().GetStyleSettings().GetMenuColor());
114 	//	maBorder.SetBackground(GetSettings().GetStyleSettings().GetMenuColor());
115 		maFTWidth.SetBackground(GetSettings().GetStyleSettings().GetMenuColor());
116 	}
117 	else
118 	{
119 		maVSWidth.SetColor(COL_WHITE);
120 	//	maBorder.SetBackground(Wallpaper(COL_WHITE));
121 		maFTWidth.SetBackground(Wallpaper(COL_WHITE));
122 	}
123 
124 	sal_Int64 nFirst= maMFWidth.Denormalize( maMFWidth.GetFirst( FUNIT_TWIP ) );
125 	sal_Int64 nLast = maMFWidth.Denormalize( maMFWidth.GetLast( FUNIT_TWIP ) );
126 	sal_Int64 nMin = maMFWidth.Denormalize( maMFWidth.GetMin( FUNIT_TWIP ) );
127 	sal_Int64 nMax = maMFWidth.Denormalize( maMFWidth.GetMax( FUNIT_TWIP ) );
128 	maMFWidth.SetSpinSize( 10 );
129 	maMFWidth.SetUnit( FUNIT_POINT );
130     if( maMFWidth.GetDecimalDigits() > 1 )
131 		 maMFWidth.SetDecimalDigits( 1 );
132 	maMFWidth.SetFirst( maMFWidth.Normalize( nFirst ), FUNIT_TWIP );
133 	maMFWidth.SetLast( maMFWidth.Normalize( nLast ), FUNIT_TWIP );
134 	maMFWidth.SetMin( maMFWidth.Normalize( nMin ), FUNIT_TWIP );
135 	maMFWidth.SetMax( maMFWidth.Normalize( nMax ), FUNIT_TWIP );
136 
137 	rStr = new XubString[9];
138 	//modify,
139 	rStr[0] = String("05", 2, RTL_TEXTENCODING_ASCII_US);
140 	rStr[1] = String("08", 2, RTL_TEXTENCODING_ASCII_US);
141 	rStr[2] = String("10", 2, RTL_TEXTENCODING_ASCII_US);
142 	rStr[3] = String("15", 2, RTL_TEXTENCODING_ASCII_US);
143 	rStr[4] = String("23", 2, RTL_TEXTENCODING_ASCII_US);
144 	rStr[5] = String("30", 2, RTL_TEXTENCODING_ASCII_US);
145 	rStr[6] = String("45", 2, RTL_TEXTENCODING_ASCII_US);
146 	rStr[7] = String("60", 2, RTL_TEXTENCODING_ASCII_US);
147 	rStr[8] = String( SVX_RES(STR_WIDTH_LAST_CUSTOM) );
148 
149 	LocaleDataWrapper aLocaleWrapper( ::comphelper::getProcessServiceFactory(), Application::GetSettings().GetLocale() );
150 	const sal_Unicode cSep = aLocaleWrapper.getNumDecimalSep().GetChar(0);
151 
152 	for(int i = 0; i <= 7 ; i++)
153 	{
154 		rStr[i] = rStr[i].Insert(cSep, 1);//Modify
155 		rStr[i].Append(mstrPT);
156 	}
157 	//end
158 
159 	for(sal_uInt16 i = 1 ; i <= 9 ; i++)
160 	{
161 		maVSWidth.InsertItem(i);
162 		maVSWidth.SetItemText(i, rStr[i-1]);
163 	}
164 	maVSWidth.SetUnit(rStr);
165 	maVSWidth.SetItemData(1,(void*)5);
166 	maVSWidth.SetItemData(2,(void*)8);
167 	maVSWidth.SetItemData(3,(void*)10);
168 	maVSWidth.SetItemData(4,(void*)15);
169 	maVSWidth.SetItemData(5,(void*)23);
170 	maVSWidth.SetItemData(6,(void*)30);
171 	maVSWidth.SetItemData(7,(void*)45);
172 	maVSWidth.SetItemData(8,(void*)60);
173 	maVSWidth.SetImage(maIMGCusGray);
174 
175 	maVSWidth.SetSelItem(0);
176 	Link aLink =  LINK( this, LineWidthControl, VSSelectHdl ) ;
177     maVSWidth.SetSelectHdl(aLink);
178 	aLink = LINK(this, LineWidthControl, MFModifyHdl);
179 	maMFWidth.SetModifyHdl(aLink);
180 
181 	maVSWidth.StartSelection();
182 	maVSWidth.Show();
183 }
184 
185 
186 
187 
GetFocus()188 void LineWidthControl::GetFocus()
189 {
190 	if(!mbVSFocus)
191 		maMFWidth.GrabFocus();
192 	else
193 		maVSWidth.GrabFocus();
194 }
195 
196 
197 
198 
GetValueSet()199 ValueSet& LineWidthControl::GetValueSet()
200 {
201 	return maVSWidth;
202 }
203 
204 
205 
206 
SetWidthSelect(long lValue,bool bValuable,SfxMapUnit eMapUnit)207 void LineWidthControl::SetWidthSelect( long lValue, bool bValuable, SfxMapUnit eMapUnit)
208 {
209 	mbVSFocus = true;
210 	maVSWidth.SetSelItem(0);
211 	mbColseByEdit = false;
212 	meMapUnit = eMapUnit;
213 	SvtViewOptions aWinOpt( E_WINDOW, SIDEBAR_LINE_WIDTH_GLOBAL_VALUE );
214     if ( aWinOpt.Exists() )
215 	{
216 		::com::sun::star::uno::Sequence < ::com::sun::star::beans::NamedValue > aSeq = aWinOpt.GetUserData();
217 		::rtl::OUString aTmp;
218 		if ( aSeq.getLength())
219 			aSeq[0].Value >>= aTmp;
220 
221 		String aWinData( aTmp );
222 		mnCustomWidth = aWinData.ToInt32();
223 		mbCustom = true;
224 		maVSWidth.SetImage(maIMGCus);
225 		maVSWidth.SetCusEnable(true);
226 
227 		String aStrTip( String::CreateFromDouble( (double)mnCustomWidth / 10));
228 		aStrTip.Append(mstrPT);		//
229 		maVSWidth.SetItemText(9, aStrTip);
230 	}
231 	else
232 	{
233 		mbCustom = false;
234 		maVSWidth.SetImage(maIMGCusGray);
235 		maVSWidth.SetCusEnable(false);
236 		//modify
237 		//String aStrTip(String(SVX_RES(STR_WIDTH_LAST_CUSTOM)));
238 		//maVSWidth.SetItemText(9, aStrTip);
239 		maVSWidth.SetItemText(9, rStr[8]);
240 	}
241 
242 	if(bValuable)
243     {
244         sal_Int64 nVal = OutputDevice::LogicToLogic( lValue, (MapUnit)eMapUnit, MAP_100TH_MM );
245         nVal = maMFWidth.Normalize( nVal );
246         maMFWidth.SetValue( nVal, FUNIT_100TH_MM );
247     }
248 	else
249     {
250 		maMFWidth.SetText( String() );
251     }
252 
253 	MapUnit eOrgUnit = (MapUnit)eMapUnit;
254 	MapUnit ePntUnit( MAP_TWIP );
255 	lValue = LogicToLogic( lValue , eOrgUnit, ePntUnit );
256 
257 	XubString strCurrValue = maMFWidth.GetText();
258 	sal_uInt16 i = 0;
259 	for(; i < 8; i++)
260 		if(strCurrValue == rStr[i])
261 		{
262 			maVSWidth.SetSelItem(i+1);
263 			break;
264 		}
265 	if (i>=8)
266 	{
267 		mbVSFocus = false;
268 		maVSWidth.SetSelItem(0);
269 	}
270 	maVSWidth.Format();
271 	maVSWidth.StartSelection();
272 }
273 
274 
275 
276 
IMPL_LINK(LineWidthControl,VSSelectHdl,void *,pControl)277 IMPL_LINK(LineWidthControl, VSSelectHdl, void *, pControl)
278 {
279 	if(pControl == &maVSWidth)
280 	{
281 		sal_uInt16 iPos = maVSWidth.GetSelectItemId();
282 		if(iPos >= 1 && iPos <= 8)
283 		{
284 			long nVal = LogicToLogic((long)(unsigned long)maVSWidth.GetItemData( iPos ) , MAP_POINT, (MapUnit)meMapUnit);
285 			nVal = maMFWidth.Denormalize(nVal);
286 			XLineWidthItem aWidthItem( nVal );
287 			mpBindings->GetDispatcher()->Execute(SID_ATTR_LINE_WIDTH, SFX_CALLMODE_RECORD, &aWidthItem, 0L);
288 			mrLinePropertyPanel.SetWidthIcon(iPos);
289 			mrLinePropertyPanel.SetWidth(nVal);
290 			mbColseByEdit = false;
291 			mnTmpCusomWidth = 0;
292 		}
293 		else if(iPos == 9)
294 		{//last custom
295 			//modified
296 			if(mbCustom)
297 			{
298 				long nVal = LogicToLogic(mnCustomWidth , MAP_POINT, (MapUnit)meMapUnit);
299 				nVal = maMFWidth.Denormalize(nVal);
300 				XLineWidthItem aWidthItem( nVal );
301 				mpBindings->GetDispatcher()->Execute(SID_ATTR_LINE_WIDTH, SFX_CALLMODE_RECORD, &aWidthItem, 0L);
302 				mrLinePropertyPanel.SetWidth(nVal);
303 				mbColseByEdit = false;
304 				mnTmpCusomWidth = 0;
305 			}
306 			else
307 			{
308 				maVSWidth.SetNoSelection();		//add , set no selection and keep the last select item
309 				maVSWidth.Format();
310 				Invalidate();
311 				maVSWidth.StartSelection();
312 			}
313 			//modify end
314 		}
315 		if((iPos >= 1 && iPos <= 8) || (iPos == 9 && mbCustom)) //add
316 			mrLinePropertyPanel.EndLineWidthPopupMode();
317 	}
318 	return( 0L );
319 }
320 
321 
322 
323 
IMPL_LINK(LineWidthControl,MFModifyHdl,void *,pControl)324 IMPL_LINK(LineWidthControl, MFModifyHdl, void *, pControl)
325 {
326 	if(pControl == &maMFWidth)
327 	{
328 		if(maVSWidth.GetSelItem())
329 		{
330 			maVSWidth.SetSelItem(0);
331 			maVSWidth.Format();
332 			Invalidate();
333 			maVSWidth.StartSelection();
334 		}
335 		long nTmp = static_cast<long>(maMFWidth.GetValue());
336 		long nVal = LogicToLogic( nTmp, MAP_POINT, (MapUnit)meMapUnit );
337 		sal_Int32 nNewWidth = (short)maMFWidth.Denormalize( nVal );
338 		XLineWidthItem aWidthItem(nNewWidth);
339 		mpBindings->GetDispatcher()->Execute(SID_ATTR_LINE_WIDTH, SFX_CALLMODE_RECORD, &aWidthItem, 0L);
340 
341 		mbColseByEdit = true;
342 		mnTmpCusomWidth = nTmp;
343 		/*for(sal_uInt16 i = 0; i < 8; i++)
344 		{
345 			if(nTmp == (sal_Int32)maVSWidth.GetItemData(i))
346 			{
347 				mbColseByEdit = false;
348 				break;
349 			}
350 		}*/
351 
352 	}
353 	return( 0L );
354 }
355 
356 
357 
358 
IsCloseByEdit()359 bool LineWidthControl::IsCloseByEdit()
360 {
361 	return mbColseByEdit;
362 }
363 
364 
365 
366 
GetTmpCustomWidth()367 long LineWidthControl::GetTmpCustomWidth()
368 {
369 	return mnTmpCusomWidth;
370 }
371 
372 
373 
374 } } // end of namespace svx::sidebar
375 
376 // eof
377