xref: /trunk/main/svx/source/sidebar/graphic/GraphicPropertyPanel.cxx (revision bfaba8a2bfbeecb976bed59dc67e51a3365db0fb)
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 {
281     switch( nSID )
282     {
283     case SID_ATTR_GRAF_LUMINANCE:
284         if( eState >= SFX_ITEM_AVAILABLE)
285         {
286             mpMtrBrightness->Enable();
287             const SfxInt16Item* pItem = dynamic_cast< const SfxInt16Item* >(pState);
288 
289             if(pItem)
290             {
291                 sal_Int64 nBright = pItem->GetValue();
292                 mpMtrBrightness->SetValue(nBright);
293             }
294         }
295         else if( eState == SFX_ITEM_DISABLED )
296             mpMtrBrightness->Disable();
297         else
298         {
299             mpMtrBrightness->Enable();
300             mpMtrBrightness->SetText( String());
301         }
302         break;
303     case SID_ATTR_GRAF_CONTRAST:
304         if( eState >= SFX_ITEM_AVAILABLE)
305         {
306             mpMtrContrast->Enable();
307             const SfxInt16Item* pItem = dynamic_cast< const SfxInt16Item* >(pState);
308 
309             if(pItem)
310             {
311                 sal_Int64 nContrast = pItem->GetValue();
312                 mpMtrContrast->SetValue(nContrast);
313             }
314         }
315         else if( eState == SFX_ITEM_DISABLED )
316             mpMtrContrast->Disable();
317         else
318         {
319             mpMtrContrast->Enable();
320             mpMtrContrast->SetText( String());
321         }
322         break;
323     case SID_ATTR_GRAF_TRANSPARENCE:
324         if( eState >= SFX_ITEM_AVAILABLE)
325         {
326             mpMtrTrans->Enable();
327             const SfxUInt16Item* pItem = dynamic_cast< const SfxUInt16Item* >(pState);
328 
329             if(pItem)
330             {
331                 sal_Int64 nTrans = pItem->GetValue();
332                 mpMtrTrans->SetValue(nTrans);
333             }
334         }
335         else if( eState == SFX_ITEM_DISABLED )
336             mpMtrTrans->Disable();
337         else
338         {
339             mpMtrTrans->Enable();
340             mpMtrTrans->SetText( String());
341         }
342         break;
343     case SID_ATTR_GRAF_MODE:
344         if( eState >= SFX_ITEM_AVAILABLE)
345         {
346             mpLBColorMode->Enable();
347             const SfxUInt16Item* pItem = dynamic_cast< const SfxUInt16Item* >(pState);
348 
349             if(pItem)
350             {
351                 sal_Int64 nTrans = pItem->GetValue();
352                 mpLBColorMode->SelectEntryPos(nTrans);
353             }
354         }
355         else if( eState == SFX_ITEM_DISABLED )
356             mpLBColorMode->Disable();
357         else
358         {
359             mpLBColorMode->Enable();
360             mpLBColorMode->SetNoSelection();
361         }
362         break;
363     case SID_ATTR_GRAF_RED:
364         if( eState >= SFX_ITEM_AVAILABLE)
365         {
366             mpMtrRed->Enable();
367             const SfxInt16Item* pItem = dynamic_cast< const SfxInt16Item* >(pState);
368 
369             if(pItem)
370             {
371                 sal_Int64 nRed = pItem->GetValue();
372                 mpMtrRed->SetValue( nRed );
373             }
374         }
375         else if( eState == SFX_ITEM_DISABLED )
376             mpMtrRed->Disable();
377         else
378         {
379             mpMtrRed->Enable();
380             mpMtrRed->SetText( String());
381         }
382         break;
383     case SID_ATTR_GRAF_GREEN:
384         if( eState >= SFX_ITEM_AVAILABLE)
385         {
386             mpMtrGreen->Enable();
387             const SfxInt16Item* pItem = dynamic_cast< const SfxInt16Item* >(pState);
388 
389             if(pItem)
390             {
391                 sal_Int64 nGreen = pItem->GetValue();
392                 mpMtrGreen->SetValue( nGreen );
393             }
394         }
395         else if( eState == SFX_ITEM_DISABLED )
396             mpMtrGreen->Disable();
397         else
398         {
399             mpMtrGreen->Enable();
400             mpMtrGreen->SetText( String());
401         }
402         break;
403     case SID_ATTR_GRAF_BLUE:
404         if( eState >= SFX_ITEM_AVAILABLE)
405         {
406             mpMtrBlue->Enable();
407             const SfxInt16Item* pItem = dynamic_cast< const SfxInt16Item* >(pState);
408 
409             if(pItem)
410             {
411                 sal_Int64 nBlue = pItem->GetValue();
412                 mpMtrBlue->SetValue( nBlue );
413             }
414         }
415         else if( eState == SFX_ITEM_DISABLED )
416             mpMtrBlue->Disable();
417         else
418         {
419             mpMtrBlue->Enable();
420             mpMtrBlue->SetText( String());
421         }
422         break;
423     case SID_ATTR_GRAF_GAMMA:
424         if( eState >= SFX_ITEM_AVAILABLE)
425         {
426             mpMtrGamma->Enable();
427             const SfxUInt32Item* pItem = dynamic_cast< const SfxUInt32Item* >(pState);
428 
429             if(pItem)
430             {
431                 sal_Int64 nGamma = pItem->GetValue();
432                 mpMtrGamma->SetValue( nGamma );
433             }
434         }
435         else if( eState == SFX_ITEM_DISABLED )
436             mpMtrGamma->Disable();
437         else
438         {
439             mpMtrGamma->Enable();
440             mpMtrGamma->SetText( String());
441         }
442         break;
443     }
444 }
445 
446 //////////////////////////////////////////////////////////////////////////////
447 
448 SfxBindings* GraphicPropertyPanel::GetBindings()
449 {
450     return mpBindings;
451 }
452 
453 //////////////////////////////////////////////////////////////////////////////
454 // namespace close
455 
456 }} // end of namespace ::svx::sidebar
457 
458 //////////////////////////////////////////////////////////////////////////////
459 // eof
460