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 <GraphicPropertyPanel.hxx>
26 #include <GraphicPropertyPanel.hrc>
27 #include <svx/dialogs.hrc>
28 #include <svx/dialmgr.hxx>
29 #include <vcl/field.hxx>
30 #include <vcl/lstbox.hxx>
31 #include <svl/intitem.hxx>
32 #include <sfx2/bindings.hxx>
33 #include <sfx2/dispatch.hxx>
34 
35 using namespace css;
36 using namespace cssu;
37 using ::sfx2::sidebar::Theme;
38 
39 #define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString)))
40 
41 //////////////////////////////////////////////////////////////////////////////
42 // namespace open
43 
44 namespace svx { namespace sidebar {
45 
46 //////////////////////////////////////////////////////////////////////////////
47 
48 GraphicPropertyPanel::GraphicPropertyPanel(
49     Window* pParent,
50     const cssu::Reference<css::frame::XFrame>& rxFrame,
51     SfxBindings* pBindings)
52 :   Control(
53         pParent,
54         SVX_RES(RID_SIDEBAR_GRAPHIC_PANEL)),
55     mpFtBrightness(new FixedText(this, SVX_RES(FT_BRIGHTNESS))),
56     mpMtrBrightness(new MetricField(this, SVX_RES(MTR_BRIGHTNESS))),
57     mpFtContrast(new FixedText(this, SVX_RES(FT_CONTRAST))),
58     mpMtrContrast(new MetricField(this, SVX_RES(MTR_CONTRAST))),
59     mpFtColorMode(new FixedText(this, SVX_RES(FT_COLOR_MODE))),
60     mpLBColorMode(new ListBox(this, SVX_RES(LB_COLOR_MODE))),
61     mpFtTrans(new FixedText(this, SVX_RES(FT_TRANSPARENT))),
62     mpMtrTrans(new MetricField(this, SVX_RES(MTR_TRANSPARENT))),
63     mpMtrRed(new MetricField(this, SVX_RES(MF_RED))),
64     mpMtrGreen(new MetricField(this, SVX_RES(MF_GREEN))),
65     mpMtrBlue(new MetricField(this, SVX_RES(MF_BLUE))),
66     mpMtrGamma(new MetricField(this, SVX_RES(MF_GAMMA))),
67     maBrightControl(SID_ATTR_GRAF_LUMINANCE, *pBindings, *this),
68     maContrastControl(SID_ATTR_GRAF_CONTRAST, *pBindings, *this),
69     maTransparenceControl(SID_ATTR_GRAF_TRANSPARENCE, *pBindings, *this),
70     maRedControl(SID_ATTR_GRAF_RED, *pBindings, *this),
71     maGreenControl(SID_ATTR_GRAF_GREEN, *pBindings, *this),
72     maBlueControl(SID_ATTR_GRAF_BLUE, *pBindings, *this),
73     maGammaControl(SID_ATTR_GRAF_GAMMA, *pBindings, *this),
74     maModeControl(SID_ATTR_GRAF_MODE, *pBindings, *this),
75     maImgNormal(SVX_RES(IMG_NORMAL)),
76     maImgBW(SVX_RES(IMG_BW)),
77     maImgGray(SVX_RES(IMG_GRAY)),
78     maImgWater(SVX_RES(IMG_WATER)),
79     maImgRed(this, SVX_RES(IMG_RED)),
80     maImgGreen(this, SVX_RES(IMG_GREEN)),
81     maImgBlue(this, SVX_RES(IMG_BLUE)),
82     maImgGamma(this, SVX_RES(IMG_GAMMA)),
83     msNormal(SVX_RES(STR_NORMAL)),
84     msBW(SVX_RES(STR_BW)),
85     msGray(SVX_RES(STR_GRAY)),
86     msWater(SVX_RES(STR_WATER)),
87     mxFrame(rxFrame),
88     mpBindings(pBindings)
89 {
90     Initialize();
91     FreeResource();
92 }
93 
94 //////////////////////////////////////////////////////////////////////////////
95 
96 GraphicPropertyPanel::~GraphicPropertyPanel()
97 {
98 }
99 
100 //////////////////////////////////////////////////////////////////////////////
101 
102 void GraphicPropertyPanel::Initialize()
103 {
104     mpFtBrightness->SetBackground(Wallpaper());
105     mpFtContrast->SetBackground(Wallpaper());
106     mpFtColorMode->SetBackground(Wallpaper());
107     mpFtTrans->SetBackground(Wallpaper());
108 
109     mpMtrBrightness->SetModifyHdl( LINK( this, GraphicPropertyPanel, ModifyBrightnessHdl ) );
110 	mpMtrBrightness->SetAccessibleName(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Brightness")));	//wj acc
111 	mpMtrContrast->SetModifyHdl( LINK( this, GraphicPropertyPanel, ModifyContrastHdl ) );
112 	mpMtrContrast->SetAccessibleName(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Contrast")));	//wj acc
113 	mpMtrTrans->SetModifyHdl( LINK( this, GraphicPropertyPanel, ModifyTransHdl ) );
114 	mpMtrTrans->SetAccessibleName(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Transparency")));	//wj acc
115 
116 	mpLBColorMode->InsertEntry( msNormal, maImgNormal );
117 	mpLBColorMode->InsertEntry( msGray, maImgGray );
118 	mpLBColorMode->InsertEntry( msBW, maImgBW );
119 	mpLBColorMode->InsertEntry( msWater, maImgWater );
120 	mpLBColorMode->SetSelectHdl( LINK( this, GraphicPropertyPanel, ClickColorModeHdl ));
121 	mpLBColorMode->SetAccessibleName(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Color mode")));	//wj acc
122 
123 	mpMtrRed->SetModifyHdl( LINK( this, GraphicPropertyPanel, RedHdl ) );
124 	mpMtrGreen->SetModifyHdl( LINK( this, GraphicPropertyPanel, GreenHdl ) );
125 	mpMtrBlue->SetModifyHdl( LINK( this, GraphicPropertyPanel, BlueHdl ) );
126 	mpMtrGamma->SetModifyHdl( LINK( this, GraphicPropertyPanel, GammaHdl ) );
127 	mpMtrRed->SetAccessibleName(mpMtrRed->GetQuickHelpText());	//wj acc
128 	mpMtrGreen->SetAccessibleName(mpMtrGreen->GetQuickHelpText());	//wj acc
129 	mpMtrBlue->SetAccessibleName(mpMtrBlue->GetQuickHelpText());		//wj acc
130 	mpMtrGamma->SetAccessibleName(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Gamma value")));	//wj acc
131 
132     mpMtrRed->SetAccessibleRelationLabeledBy(mpMtrRed.get());
133 	mpMtrGreen->SetAccessibleRelationLabeledBy(mpMtrGreen.get());
134 	mpMtrBlue->SetAccessibleRelationLabeledBy(mpMtrBlue.get());
135 	mpMtrGamma->SetAccessibleRelationLabeledBy(mpMtrGamma.get());
136 	mpMtrBrightness->SetAccessibleRelationLabeledBy(mpFtBrightness.get());	//7874
137 	mpMtrContrast->SetAccessibleRelationLabeledBy(mpFtContrast.get());	//7874
138 	mpMtrTrans->SetAccessibleRelationLabeledBy(mpFtTrans.get());	//7874
139 	mpLBColorMode->SetAccessibleRelationLabeledBy(mpFtColorMode.get());	//7874
140 }
141 
142 //////////////////////////////////////////////////////////////////////////////
143 
144 IMPL_LINK( GraphicPropertyPanel, ModifyBrightnessHdl, void *, EMPTYARG )
145 {
146 	sal_Int16 nBright = mpMtrBrightness->GetValue();
147 	SfxInt16Item aBrightItem( SID_ATTR_GRAF_LUMINANCE, nBright );
148 	GetBindings()->GetDispatcher()->Execute(
149 		SID_ATTR_GRAF_LUMINANCE, SFX_CALLMODE_RECORD, &aBrightItem, 0L);
150 	return 0L;
151 }
152 
153 //////////////////////////////////////////////////////////////////////////////
154 
155 IMPL_LINK( GraphicPropertyPanel, ModifyContrastHdl, void *, EMPTYARG )
156 {
157 	sal_Int16 nContrast = mpMtrContrast->GetValue();
158 	SfxInt16Item aContrastItem( SID_ATTR_GRAF_CONTRAST, nContrast );
159 	GetBindings()->GetDispatcher()->Execute(
160 		SID_ATTR_GRAF_CONTRAST, SFX_CALLMODE_RECORD, &aContrastItem, 0L);
161 	return 0L;
162 }
163 
164 //////////////////////////////////////////////////////////////////////////////
165 
166 IMPL_LINK( GraphicPropertyPanel, ModifyTransHdl, void *, EMPTYARG )
167 {
168 	sal_Int16 nTrans = mpMtrTrans->GetValue();
169 	SfxInt16Item aTransItem( SID_ATTR_GRAF_TRANSPARENCE, nTrans );
170 	GetBindings()->GetDispatcher()->Execute(
171 		SID_ATTR_GRAF_TRANSPARENCE, SFX_CALLMODE_RECORD, &aTransItem, 0L);
172 	return 0L;
173 }
174 
175 //////////////////////////////////////////////////////////////////////////////
176 
177 IMPL_LINK( GraphicPropertyPanel, ClickColorModeHdl, ToolBox *, /* pBox */)
178 {
179 	sal_Int16 nTrans = mpLBColorMode->GetSelectEntryPos();
180 	SfxInt16Item aTransItem( SID_ATTR_GRAF_MODE, nTrans );
181 	GetBindings()->GetDispatcher()->Execute(
182 		SID_ATTR_GRAF_MODE, SFX_CALLMODE_RECORD, &aTransItem, 0L);
183 	return 0L;
184 }
185 
186 //////////////////////////////////////////////////////////////////////////////
187 
188 IMPL_LINK( GraphicPropertyPanel, RedHdl, void*, EMPTYARG )
189 {
190 	sal_Int16 nRed = mpMtrRed->GetValue();
191 	SfxInt16Item aRedItem( SID_ATTR_GRAF_RED, nRed );
192 	GetBindings()->GetDispatcher()->Execute(
193 		SID_ATTR_GRAF_RED, SFX_CALLMODE_RECORD, &aRedItem, 0L);
194 	return 0L;
195 }
196 
197 //////////////////////////////////////////////////////////////////////////////
198 
199 IMPL_LINK( GraphicPropertyPanel, GreenHdl, void*, EMPTYARG )
200 {
201 	sal_Int16 nGreen = mpMtrGreen->GetValue();
202 	SfxInt16Item aGreenItem( SID_ATTR_GRAF_GREEN, nGreen );
203 	GetBindings()->GetDispatcher()->Execute(
204 		SID_ATTR_GRAF_GREEN, SFX_CALLMODE_RECORD, &aGreenItem, 0L);
205 	return 0L;
206 }
207 
208 //////////////////////////////////////////////////////////////////////////////
209 
210 IMPL_LINK(GraphicPropertyPanel, BlueHdl, void *, EMPTYARG)
211 {
212 	sal_Int16 nBlue = mpMtrBlue->GetValue();
213 	SfxInt16Item aBlueItem( SID_ATTR_GRAF_BLUE, nBlue );
214 	GetBindings()->GetDispatcher()->Execute(
215 		SID_ATTR_GRAF_BLUE, SFX_CALLMODE_RECORD, &aBlueItem, 0L);
216 	return 0L;
217 }
218 
219 //////////////////////////////////////////////////////////////////////////////
220 
221 IMPL_LINK(GraphicPropertyPanel, GammaHdl, void *, EMPTYARG)
222 {
223 	sal_Int32 nGamma = mpMtrGamma->GetValue();
224 	SfxInt32Item nGammaItem( SID_ATTR_GRAF_GAMMA, nGamma );
225 	GetBindings()->GetDispatcher()->Execute(
226 		SID_ATTR_GRAF_GAMMA, SFX_CALLMODE_RECORD, &nGammaItem, 0L);
227 	return 0L;
228 }
229 
230 //////////////////////////////////////////////////////////////////////////////
231 
232 void GraphicPropertyPanel::SetupIcons(void)
233 {
234     if(Theme::GetBoolean(Theme::Bool_UseSymphonyIcons))
235     {
236         // todo
237     }
238     else
239     {
240         // todo
241     }
242 }
243 
244 //////////////////////////////////////////////////////////////////////////////
245 
246 GraphicPropertyPanel* GraphicPropertyPanel::Create (
247     Window* pParent,
248     const cssu::Reference<css::frame::XFrame>& rxFrame,
249     SfxBindings* pBindings)
250 {
251     if (pParent == NULL)
252         throw lang::IllegalArgumentException(A2S("no parent Window given to GraphicPropertyPanel::Create"), NULL, 0);
253     if ( ! rxFrame.is())
254         throw lang::IllegalArgumentException(A2S("no XFrame given to GraphicPropertyPanel::Create"), NULL, 1);
255     if (pBindings == NULL)
256         throw lang::IllegalArgumentException(A2S("no SfxBindings given to GraphicPropertyPanel::Create"), NULL, 2);
257 
258     return new GraphicPropertyPanel(
259         pParent,
260         rxFrame,
261         pBindings);
262 }
263 
264 //////////////////////////////////////////////////////////////////////////////
265 
266 void GraphicPropertyPanel::DataChanged(
267     const DataChangedEvent& rEvent)
268 {
269     (void)rEvent;
270 
271     SetupIcons();
272 }
273 
274 //////////////////////////////////////////////////////////////////////////////
275 
276 void GraphicPropertyPanel::NotifyItemUpdate(
277     sal_uInt16 nSID,
278     SfxItemState eState,
279     const SfxPoolItem* pState,
280     const bool bIsEnabled)
281 {
282     (void)bIsEnabled;
283 
284 	switch( nSID )
285 	{
286 	case SID_ATTR_GRAF_LUMINANCE:
287 		if( eState >= SFX_ITEM_AVAILABLE)
288 		{
289 			mpMtrBrightness->Enable();
290             const SfxInt16Item* pItem = dynamic_cast< const SfxInt16Item* >(pState);
291 
292 			if(pItem)
293 			{
294 				sal_Int64 nBright = pItem->GetValue();
295 				mpMtrBrightness->SetValue(nBright);
296 			}
297 		}
298 		else if( eState == SFX_ITEM_DISABLED )
299 			mpMtrBrightness->Disable();
300 		else
301 		{
302 			mpMtrBrightness->Enable();
303 			mpMtrBrightness->SetText( String());
304 		}
305 		break;
306 	case SID_ATTR_GRAF_CONTRAST:
307 		if( eState >= SFX_ITEM_AVAILABLE)
308 		{
309 			mpMtrContrast->Enable();
310             const SfxInt16Item* pItem = dynamic_cast< const SfxInt16Item* >(pState);
311 
312             if(pItem)
313 			{
314 				sal_Int64 nContrast = pItem->GetValue();
315 				mpMtrContrast->SetValue(nContrast);
316 			}
317 		}
318 		else if( eState == SFX_ITEM_DISABLED )
319 			mpMtrContrast->Disable();
320 		else
321 		{
322 			mpMtrContrast->Enable();
323 			mpMtrContrast->SetText( String());
324 		}
325 		break;
326 	case SID_ATTR_GRAF_TRANSPARENCE:
327 		if( eState >= SFX_ITEM_AVAILABLE)
328 		{
329 			mpMtrTrans->Enable();
330             const SfxUInt16Item* pItem = dynamic_cast< const SfxUInt16Item* >(pState);
331 
332 			if(pItem)
333 			{
334 				sal_Int64 nTrans = pItem->GetValue();
335 				mpMtrTrans->SetValue(nTrans);
336 			}
337 		}
338 		else if( eState == SFX_ITEM_DISABLED )
339 			mpMtrTrans->Disable();
340 		else
341 		{
342 			mpMtrTrans->Enable();
343 			mpMtrTrans->SetText( String());
344 		}
345 		break;
346 	case SID_ATTR_GRAF_MODE:
347 		if( eState >= SFX_ITEM_AVAILABLE)
348 		{
349 			mpLBColorMode->Enable();
350             const SfxUInt16Item* pItem = dynamic_cast< const SfxUInt16Item* >(pState);
351 
352 			if(pItem)
353 			{
354 				sal_Int64 nTrans = pItem->GetValue();
355 				mpLBColorMode->SelectEntryPos(nTrans);
356 			}
357 		}
358 		else if( eState == SFX_ITEM_DISABLED )
359 			mpLBColorMode->Disable();
360 		else
361 		{
362 			mpLBColorMode->Enable();
363 			mpLBColorMode->SetNoSelection();
364 		}
365 		break;
366 	case SID_ATTR_GRAF_RED:
367 		if( eState >= SFX_ITEM_AVAILABLE)
368 		{
369 			mpMtrRed->Enable();
370             const SfxInt16Item* pItem = dynamic_cast< const SfxInt16Item* >(pState);
371 
372 			if(pItem)
373 			{
374 				sal_Int64 nRed = pItem->GetValue();
375 				mpMtrRed->SetValue( nRed );
376 			}
377 		}
378 		else if( eState == SFX_ITEM_DISABLED )
379 			mpMtrRed->Disable();
380 		else
381 		{
382 			mpMtrRed->Enable();
383 			mpMtrRed->SetText( String());
384 		}
385 		break;
386 	case SID_ATTR_GRAF_GREEN:
387 		if( eState >= SFX_ITEM_AVAILABLE)
388 		{
389 			mpMtrGreen->Enable();
390             const SfxInt16Item* pItem = dynamic_cast< const SfxInt16Item* >(pState);
391 
392 			if(pItem)
393 			{
394 				sal_Int64 nGreen = pItem->GetValue();
395 				mpMtrGreen->SetValue( nGreen );
396 			}
397 		}
398 		else if( eState == SFX_ITEM_DISABLED )
399 			mpMtrGreen->Disable();
400 		else
401 		{
402 			mpMtrGreen->Enable();
403 			mpMtrGreen->SetText( String());
404 		}
405 		break;
406 	case SID_ATTR_GRAF_BLUE:
407 		if( eState >= SFX_ITEM_AVAILABLE)
408 		{
409 			mpMtrBlue->Enable();
410             const SfxInt16Item* pItem = dynamic_cast< const SfxInt16Item* >(pState);
411 
412 			if(pItem)
413 			{
414 				sal_Int64 nBlue = pItem->GetValue();
415 				mpMtrBlue->SetValue( nBlue );
416 			}
417 		}
418 		else if( eState == SFX_ITEM_DISABLED )
419 			mpMtrBlue->Disable();
420 		else
421 		{
422 			mpMtrBlue->Enable();
423 			mpMtrBlue->SetText( String());
424 		}
425 		break;
426 	case SID_ATTR_GRAF_GAMMA:
427 		if( eState >= SFX_ITEM_AVAILABLE)
428 		{
429 			mpMtrGamma->Enable();
430             const SfxUInt32Item* pItem = dynamic_cast< const SfxUInt32Item* >(pState);
431 
432 			if(pItem)
433 			{
434 				sal_Int64 nGamma = pItem->GetValue();
435 				mpMtrGamma->SetValue( nGamma );
436 			}
437 		}
438 		else if( eState == SFX_ITEM_DISABLED )
439 			mpMtrGamma->Disable();
440 		else
441 		{
442 			mpMtrGamma->Enable();
443 			mpMtrGamma->SetText( String());
444 		}
445 		break;
446 	}
447 }
448 
449 
450 
451 
452 //////////////////////////////////////////////////////////////////////////////
453 
454 SfxBindings* GraphicPropertyPanel::GetBindings()
455 {
456     return mpBindings;
457 }
458 
459 //////////////////////////////////////////////////////////////////////////////
460 // namespace close
461 
462 }} // end of namespace ::svx::sidebar
463 
464 //////////////////////////////////////////////////////////////////////////////
465 // eof
466