xref: /trunk/main/sw/source/ui/sidebar/WrapPropertyPanel.cxx (revision 31bbceb0f9d64c0c2c3b22a794a1666c1f33396e)
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 
23 
24 #include "precompiled_sw.hxx"
25 
26 #include "WrapPropertyPanel.hxx"
27 #include "WrapPropertyPanel.hrc"
28 #include "PropertyPanel.hrc"
29 
30 #include <cmdid.h>
31 #include <swtypes.hxx>
32 
33 #include <sfx2/bindings.hxx>
34 #include <sfx2/dispatch.hxx>
35 #include <sfx2/sidebar/ControlFactory.hxx>
36 #include <sfx2/imagemgr.hxx>
37 #include <svl/eitem.hxx>
38 #include <vcl/svapp.hxx>
39 
40 #include "com/sun/star/lang/IllegalArgumentException.hpp"
41 
42 #define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString)))
43 
44 
45 namespace sw { namespace sidebar {
46 
47 WrapPropertyPanel* WrapPropertyPanel::Create (
48     Window* pParent,
49     const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rxFrame,
50     SfxBindings* pBindings)
51 {
52     if (pParent == NULL)
53         throw ::com::sun::star::lang::IllegalArgumentException(A2S("no parent Window given to WrapPropertyPanel::Create"), NULL, 0);
54     if ( ! rxFrame.is())
55         throw ::com::sun::star::lang::IllegalArgumentException(A2S("no XFrame given to WrapPropertyPanel::Create"), NULL, 1);
56     if (pBindings == NULL)
57         throw ::com::sun::star::lang::IllegalArgumentException(A2S("no SfxBindings given to WrapPropertyPanel::Create"), NULL, 2);
58 
59     return new WrapPropertyPanel(
60         pParent,
61         rxFrame,
62         pBindings);
63 }
64 
65 
66 WrapPropertyPanel::WrapPropertyPanel(
67     Window* pParent,
68     const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rxFrame,
69     SfxBindings* pBindings )
70     : Control(pParent, SW_RES(RID_PROPERTYPANEL_SWOBJWRAP_PAGE))
71     , mxFrame( rxFrame )
72     , mpBindings(pBindings)
73     // visible controls
74     , mpRBNoWrap( ::sfx2::sidebar::ControlFactory::CreateCustomImageRadionButton( this, SW_RES(RB_NO_WRAP) ) )
75     , mpRBWrapLeft( ::sfx2::sidebar::ControlFactory::CreateCustomImageRadionButton( this, SW_RES(RB_WRAP_LEFT) ) )
76     , mpRBWrapRight( ::sfx2::sidebar::ControlFactory::CreateCustomImageRadionButton( this, SW_RES(RB_WRAP_RIGHT) ) )
77     , mpRBWrapParallel( ::sfx2::sidebar::ControlFactory::CreateCustomImageRadionButton( this, SW_RES(RB_WRAP_PARALLEL) ) )
78     , mpRBWrapThrough( ::sfx2::sidebar::ControlFactory::CreateCustomImageRadionButton( this, SW_RES(RB_WRAP_THROUGH) ) )
79     , mpRBIdealWrap( ::sfx2::sidebar::ControlFactory::CreateCustomImageRadionButton( this, SW_RES(RB_WRAP_IDEAL) ) )
80     // resources
81     , aWrapIL(6,2)
82     , aWrapILH(6,2)
83     // controller items
84     , maSwNoWrapControl(FN_FRAME_NOWRAP, *pBindings, *this)
85     , maSwWrapLeftControl(FN_FRAME_WRAP, *pBindings, *this)
86     , maSwWrapRightControl(FN_FRAME_WRAP_RIGHT, *pBindings, *this)
87     , maSwWrapParallelControl(FN_FRAME_WRAP_LEFT, *pBindings, *this)
88     , maSwWrapThroughControl(FN_FRAME_WRAPTHRU, *pBindings, *this)
89     , maSwWrapIdealControl(FN_FRAME_WRAP_IDEAL, *pBindings, *this)
90 {
91     Initialize();
92     FreeResource();
93 }
94 
95 
96 WrapPropertyPanel::~WrapPropertyPanel()
97 {
98 }
99 
100 
101 void WrapPropertyPanel::Initialize()
102 {
103     Link aLink = LINK(this, WrapPropertyPanel, WrapTypeHdl);
104     mpRBNoWrap->SetClickHdl(aLink);
105     mpRBWrapLeft->SetClickHdl(aLink);
106     mpRBWrapRight->SetClickHdl(aLink);
107     mpRBWrapParallel->SetClickHdl(aLink);
108     mpRBWrapThrough->SetClickHdl(aLink);
109     mpRBIdealWrap->SetClickHdl(aLink);
110 
111     aWrapIL.AddImage( IMG_NONE,
112                       ::GetImage( mxFrame, A2S(".uno:WrapOff"), sal_False, sal_False ) );
113     aWrapIL.AddImage( IMG_LEFT,
114                       ::GetImage( mxFrame, A2S(".uno:WrapLeft"), sal_False, sal_False ) );
115     aWrapIL.AddImage( IMG_RIGHT,
116                       ::GetImage( mxFrame, A2S(".uno:WrapRight"), sal_False, sal_False ) );
117     aWrapIL.AddImage( IMG_PARALLEL,
118                       ::GetImage( mxFrame, A2S(".uno:WrapOn"), sal_False, sal_False ) );
119     aWrapIL.AddImage( IMG_THROUGH,
120                       ::GetImage( mxFrame, A2S(".uno:WrapThrough"), sal_False, sal_False ) );
121     aWrapIL.AddImage( IMG_IDEAL,
122                       ::GetImage( mxFrame, A2S(".uno:WrapIdeal"), sal_False, sal_False ) );
123 
124     aWrapILH.AddImage( IMG_NONE,
125                        ::GetImage( mxFrame, A2S(".uno:WrapOff"), sal_False, sal_True ) );
126     aWrapILH.AddImage( IMG_LEFT,
127                        ::GetImage( mxFrame, A2S(".uno:WrapLeft"), sal_False, sal_True ) );
128     aWrapILH.AddImage( IMG_RIGHT,
129                        ::GetImage( mxFrame, A2S(".uno:WrapRight"), sal_False, sal_True ) );
130     aWrapILH.AddImage( IMG_PARALLEL,
131                        ::GetImage( mxFrame, A2S(".uno:WrapOn"), sal_False, sal_True ) );
132     aWrapILH.AddImage( IMG_THROUGH,
133                        ::GetImage( mxFrame, A2S(".uno:WrapThrough"), sal_False, sal_True ) );
134     aWrapILH.AddImage( IMG_IDEAL,
135                        ::GetImage( mxFrame, A2S(".uno:WrapIdeal"), sal_False, sal_True ) );
136 
137     mpRBNoWrap->SetModeRadioImage( aWrapIL.GetImage(IMG_NONE) );
138     mpRBNoWrap->SetModeRadioImage( aWrapILH.GetImage(IMG_NONE) , BMP_COLOR_HIGHCONTRAST );
139     if ( Application::GetSettings().GetLayoutRTL() )
140     {
141         mpRBWrapLeft->SetModeRadioImage( aWrapIL.GetImage(IMG_RIGHT) );
142         mpRBWrapLeft->SetModeRadioImage( aWrapILH.GetImage(IMG_RIGHT) , BMP_COLOR_HIGHCONTRAST );
143         mpRBWrapRight->SetModeRadioImage( aWrapIL.GetImage(IMG_LEFT) );
144         mpRBWrapRight->SetModeRadioImage( aWrapILH.GetImage(IMG_LEFT) , BMP_COLOR_HIGHCONTRAST );
145     }
146     else
147     {
148         mpRBWrapLeft->SetModeRadioImage( aWrapIL.GetImage(IMG_LEFT) );
149         mpRBWrapLeft->SetModeRadioImage( aWrapILH.GetImage(IMG_LEFT) , BMP_COLOR_HIGHCONTRAST );
150         mpRBWrapRight->SetModeRadioImage( aWrapIL.GetImage(IMG_RIGHT) );
151         mpRBWrapRight->SetModeRadioImage( aWrapILH.GetImage(IMG_RIGHT) , BMP_COLOR_HIGHCONTRAST );
152     }
153     mpRBWrapParallel->SetModeRadioImage( aWrapIL.GetImage(IMG_PARALLEL) );
154     mpRBWrapParallel->SetModeRadioImage( aWrapILH.GetImage(IMG_PARALLEL) , BMP_COLOR_HIGHCONTRAST );
155     mpRBWrapThrough->SetModeRadioImage( aWrapIL.GetImage(IMG_THROUGH) );
156     mpRBWrapThrough->SetModeRadioImage( aWrapILH.GetImage(IMG_THROUGH) , BMP_COLOR_HIGHCONTRAST );
157     mpRBIdealWrap->SetModeRadioImage( aWrapIL.GetImage(IMG_IDEAL) );
158     mpRBIdealWrap->SetModeRadioImage( aWrapILH.GetImage(IMG_IDEAL) , BMP_COLOR_HIGHCONTRAST );
159 
160     mpRBNoWrap->SetAccessibleName(mpRBNoWrap->GetQuickHelpText());
161     mpRBWrapLeft->SetAccessibleName(mpRBWrapLeft->GetQuickHelpText());
162     mpRBWrapRight->SetAccessibleName(mpRBWrapRight->GetQuickHelpText());
163     mpRBWrapParallel->SetAccessibleName(mpRBWrapParallel->GetQuickHelpText());
164     mpRBWrapThrough->SetAccessibleName(mpRBWrapThrough->GetQuickHelpText());
165     mpRBIdealWrap->SetAccessibleName(mpRBIdealWrap->GetQuickHelpText());
166 
167     mpBindings->Update( FN_FRAME_NOWRAP );
168     mpBindings->Update( FN_FRAME_WRAP );
169     mpBindings->Update( FN_FRAME_WRAP_RIGHT );
170     mpBindings->Update( FN_FRAME_WRAP_LEFT );
171     mpBindings->Update( FN_FRAME_WRAPTHRU );
172     mpBindings->Update( FN_FRAME_WRAP_IDEAL );
173 }
174 
175 
176 IMPL_LINK(WrapPropertyPanel, WrapTypeHdl, void *, EMPTYARG)
177 {
178     sal_uInt16 nSlot = 0;
179     if ( mpRBWrapLeft->IsChecked() )
180     {
181         nSlot = FN_FRAME_WRAP_LEFT;
182     }
183     else if( mpRBWrapRight->IsChecked() )
184     {
185         nSlot = FN_FRAME_WRAP_RIGHT;
186     }
187     else if ( mpRBWrapParallel->IsChecked() )
188     {
189         nSlot = FN_FRAME_WRAP;
190     }
191     else if( mpRBWrapThrough->IsChecked() )
192     {
193         nSlot = FN_FRAME_WRAPTHRU;
194     }
195     else if( mpRBIdealWrap->IsChecked() )
196     {
197         nSlot = FN_FRAME_WRAP_IDEAL;
198     }
199     else
200     {
201         nSlot = FN_FRAME_NOWRAP;
202     }
203     SfxBoolItem bStateItem( nSlot, sal_True );
204     mpBindings->GetDispatcher()->Execute( nSlot, SFX_CALLMODE_RECORD, &bStateItem, 0L );
205 
206     return 0;
207 }
208 
209 
210 void WrapPropertyPanel::NotifyItemUpdate(
211     const sal_uInt16 nSId,
212     const SfxItemState eState,
213     const SfxPoolItem* pState,
214     const bool bIsEnabled)
215 {
216     (void)bIsEnabled;
217 
218     if ( eState == SFX_ITEM_AVAILABLE &&
219         pState->ISA(SfxBoolItem) )
220     {
221         // Set Radio Button enable
222         mpRBNoWrap->Enable(true);
223         mpRBWrapLeft->Enable(true);
224         mpRBWrapRight->Enable(true);
225         mpRBWrapParallel->Enable(true);
226         mpRBWrapThrough->Enable(true);
227         mpRBIdealWrap->Enable(true);
228 
229         const SfxBoolItem* pBoolItem = static_cast< const SfxBoolItem* >( pState );
230         switch( nSId )
231         {
232         case FN_FRAME_WRAP_RIGHT:
233             mpRBWrapRight->Check( pBoolItem->GetValue() );
234             break;
235         case FN_FRAME_WRAP_LEFT:
236             mpRBWrapLeft->Check( pBoolItem->GetValue() );
237             break;
238         case FN_FRAME_WRAPTHRU:
239             mpRBWrapThrough->Check( pBoolItem->GetValue() );
240             break;
241         case FN_FRAME_WRAP_IDEAL:
242             mpRBIdealWrap->Check( pBoolItem->GetValue() );
243             break;
244         case FN_FRAME_WRAP:
245             mpRBWrapParallel->Check( pBoolItem->GetValue() );
246             break;
247         case FN_FRAME_NOWRAP:
248         default:
249             mpRBNoWrap->Check( pBoolItem->GetValue() );
250             break;
251         }
252     }
253     else
254     {
255         mpRBNoWrap->Enable(false);
256         mpRBWrapLeft->Enable(false);
257         mpRBWrapRight->Enable(false);
258         mpRBWrapParallel->Enable(false);
259         mpRBWrapThrough->Enable(false);
260         mpRBIdealWrap->Enable(false);
261 
262         mpRBNoWrap->Check( sal_False );
263         mpRBWrapLeft->Check( sal_False );
264         mpRBWrapRight->Check( sal_False );
265         mpRBWrapParallel->Check( sal_False );
266         mpRBWrapThrough->Check( sal_False );
267         mpRBIdealWrap->Check( sal_False );
268     }
269 }
270 
271 } } // end of namespace ::sw::sidebar
272 
273 /* vim: set noet sw=4 ts=4: */
274