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