Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "WrapPropertyPanel.hxx"
21 : #include "PropertyPanel.hrc"
22 :
23 : #include <cmdid.h>
24 : #include <swtypes.hxx>
25 :
26 : #include <sfx2/bindings.hxx>
27 : #include <sfx2/dispatch.hxx>
28 : #include <sfx2/sidebar/ControlFactory.hxx>
29 : #include <sfx2/imagemgr.hxx>
30 : #include <svl/eitem.hxx>
31 : #include <vcl/svapp.hxx>
32 : #include <vcl/settings.hxx>
33 :
34 : #include <com/sun/star/lang/IllegalArgumentException.hpp>
35 :
36 : const char UNO_WRAPOFF[] = ".uno:WrapOff";
37 : const char UNO_WRAPLEFT[] = ".uno:WrapLeft";
38 : const char UNO_WRAPRIGHT[] = ".uno:WrapRight";
39 : const char UNO_WRAPON[] = ".uno:WrapOn";
40 : const char UNO_WRAPTHROUGH[] = ".uno:WrapThrough";
41 : const char UNO_WRAPIDEAL[] = ".uno:WrapIdeal";
42 :
43 : namespace sw { namespace sidebar {
44 :
45 0 : WrapPropertyPanel* WrapPropertyPanel::Create (
46 : vcl::Window* pParent,
47 : const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rxFrame,
48 : SfxBindings* pBindings)
49 : {
50 0 : if (pParent == NULL)
51 0 : throw ::com::sun::star::lang::IllegalArgumentException("no parent Window given to WrapPropertyPanel::Create", NULL, 0);
52 0 : if ( ! rxFrame.is())
53 0 : throw ::com::sun::star::lang::IllegalArgumentException("no XFrame given to WrapPropertyPanel::Create", NULL, 1);
54 0 : if (pBindings == NULL)
55 0 : throw ::com::sun::star::lang::IllegalArgumentException("no SfxBindings given to WrapPropertyPanel::Create", NULL, 2);
56 :
57 : return new WrapPropertyPanel(
58 : pParent,
59 : rxFrame,
60 0 : pBindings);
61 : }
62 :
63 0 : WrapPropertyPanel::WrapPropertyPanel(
64 : vcl::Window* pParent,
65 : const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rxFrame,
66 : SfxBindings* pBindings )
67 : : PanelLayout(pParent, "WrapPropertyPanel", "modules/swriter/ui/sidebarwrap.ui", rxFrame)
68 : , mxFrame( rxFrame )
69 : , mpBindings(pBindings)
70 : // resources
71 : , aWrapIL(6,2)
72 : // controller items
73 : , maSwNoWrapControl(FN_FRAME_NOWRAP, *pBindings, *this)
74 : , maSwWrapLeftControl(FN_FRAME_WRAP, *pBindings, *this)
75 : , maSwWrapRightControl(FN_FRAME_WRAP_RIGHT, *pBindings, *this)
76 : , maSwWrapParallelControl(FN_FRAME_WRAP_LEFT, *pBindings, *this)
77 : , maSwWrapThroughControl(FN_FRAME_WRAPTHRU, *pBindings, *this)
78 0 : , maSwWrapIdealControl(FN_FRAME_WRAP_IDEAL, *pBindings, *this)
79 : {
80 0 : get(mpRBNoWrap, "buttonnone");
81 0 : get(mpRBWrapLeft, "buttonbefore");
82 0 : get(mpRBWrapRight, "buttonafter");
83 0 : get(mpRBWrapParallel, "buttonparallel");
84 0 : get(mpRBWrapThrough, "buttonthrough");
85 0 : get(mpRBIdealWrap, "buttonoptimal");
86 :
87 0 : Initialize();
88 0 : }
89 :
90 0 : WrapPropertyPanel::~WrapPropertyPanel()
91 : {
92 0 : }
93 :
94 0 : void WrapPropertyPanel::Initialize()
95 : {
96 0 : Link aLink = LINK(this, WrapPropertyPanel, WrapTypeHdl);
97 0 : mpRBNoWrap->SetClickHdl(aLink);
98 0 : mpRBWrapLeft->SetClickHdl(aLink);
99 0 : mpRBWrapRight->SetClickHdl(aLink);
100 0 : mpRBWrapParallel->SetClickHdl(aLink);
101 0 : mpRBWrapThrough->SetClickHdl(aLink);
102 0 : mpRBIdealWrap->SetClickHdl(aLink);
103 :
104 : aWrapIL.AddImage( UNO_WRAPOFF,
105 0 : ::GetImage( mxFrame, UNO_WRAPOFF, false ) );
106 : aWrapIL.AddImage( UNO_WRAPLEFT,
107 0 : ::GetImage( mxFrame, UNO_WRAPLEFT, false ) );
108 : aWrapIL.AddImage( UNO_WRAPRIGHT,
109 0 : ::GetImage( mxFrame, UNO_WRAPRIGHT, false ) );
110 : aWrapIL.AddImage( UNO_WRAPON,
111 0 : ::GetImage( mxFrame, UNO_WRAPON, false ) );
112 : aWrapIL.AddImage( UNO_WRAPTHROUGH,
113 0 : ::GetImage( mxFrame, UNO_WRAPTHROUGH, false ) );
114 : aWrapIL.AddImage( UNO_WRAPIDEAL,
115 0 : ::GetImage( mxFrame, UNO_WRAPIDEAL, false ) );
116 :
117 0 : mpRBNoWrap->SetModeRadioImage( aWrapIL.GetImage(UNO_WRAPOFF) );
118 0 : if ( Application::GetSettings().GetLayoutRTL() )
119 : {
120 0 : mpRBWrapLeft->SetModeRadioImage( aWrapIL.GetImage(UNO_WRAPRIGHT) );
121 0 : mpRBWrapRight->SetModeRadioImage( aWrapIL.GetImage(UNO_WRAPLEFT) );
122 : }
123 : else
124 : {
125 0 : mpRBWrapLeft->SetModeRadioImage( aWrapIL.GetImage(UNO_WRAPLEFT) );
126 0 : mpRBWrapRight->SetModeRadioImage( aWrapIL.GetImage(UNO_WRAPRIGHT) );
127 : }
128 0 : mpRBWrapParallel->SetModeRadioImage( aWrapIL.GetImage(UNO_WRAPON) );
129 0 : mpRBWrapThrough->SetModeRadioImage( aWrapIL.GetImage(UNO_WRAPTHROUGH) );
130 0 : mpRBIdealWrap->SetModeRadioImage( aWrapIL.GetImage(UNO_WRAPIDEAL) );
131 :
132 0 : mpRBNoWrap->SetAccessibleName(mpRBNoWrap->GetQuickHelpText());
133 0 : mpRBWrapLeft->SetAccessibleName(mpRBWrapLeft->GetQuickHelpText());
134 0 : mpRBWrapRight->SetAccessibleName(mpRBWrapRight->GetQuickHelpText());
135 0 : mpRBWrapParallel->SetAccessibleName(mpRBWrapParallel->GetQuickHelpText());
136 0 : mpRBWrapThrough->SetAccessibleName(mpRBWrapThrough->GetQuickHelpText());
137 0 : mpRBIdealWrap->SetAccessibleName(mpRBIdealWrap->GetQuickHelpText());
138 :
139 0 : mpBindings->Update( FN_FRAME_NOWRAP );
140 0 : mpBindings->Update( FN_FRAME_WRAP );
141 0 : mpBindings->Update( FN_FRAME_WRAP_RIGHT );
142 0 : mpBindings->Update( FN_FRAME_WRAP_LEFT );
143 0 : mpBindings->Update( FN_FRAME_WRAPTHRU );
144 0 : mpBindings->Update( FN_FRAME_WRAP_IDEAL );
145 0 : }
146 :
147 0 : IMPL_LINK(WrapPropertyPanel, WrapTypeHdl, void *, EMPTYARG)
148 : {
149 0 : sal_uInt16 nSlot = 0;
150 0 : if ( mpRBWrapLeft->IsChecked() )
151 : {
152 0 : nSlot = FN_FRAME_WRAP_LEFT;
153 : }
154 0 : else if( mpRBWrapRight->IsChecked() )
155 : {
156 0 : nSlot = FN_FRAME_WRAP_RIGHT;
157 : }
158 0 : else if ( mpRBWrapParallel->IsChecked() )
159 : {
160 0 : nSlot = FN_FRAME_WRAP;
161 : }
162 0 : else if( mpRBWrapThrough->IsChecked() )
163 : {
164 0 : nSlot = FN_FRAME_WRAPTHRU;
165 : }
166 0 : else if( mpRBIdealWrap->IsChecked() )
167 : {
168 0 : nSlot = FN_FRAME_WRAP_IDEAL;
169 : }
170 : else
171 : {
172 0 : nSlot = FN_FRAME_NOWRAP;
173 : }
174 0 : SfxBoolItem bStateItem( nSlot, true );
175 0 : mpBindings->GetDispatcher()->Execute( nSlot, SfxCallMode::RECORD, &bStateItem, 0L );
176 :
177 0 : return 0;
178 : }
179 :
180 0 : void WrapPropertyPanel::NotifyItemUpdate(
181 : const sal_uInt16 nSId,
182 : const SfxItemState eState,
183 : const SfxPoolItem* pState,
184 : const bool bIsEnabled)
185 : {
186 : (void)bIsEnabled;
187 :
188 0 : if ( eState == SfxItemState::DEFAULT &&
189 0 : pState->ISA(SfxBoolItem) )
190 : {
191 : //Set Radio Button enable
192 0 : mpRBNoWrap->Enable(true);
193 0 : mpRBWrapLeft->Enable(true);
194 0 : mpRBWrapRight->Enable(true);
195 0 : mpRBWrapParallel->Enable(true);
196 0 : mpRBWrapThrough->Enable(true);
197 0 : mpRBIdealWrap->Enable(true);
198 :
199 0 : const SfxBoolItem* pBoolItem = static_cast< const SfxBoolItem* >( pState );
200 0 : switch( nSId )
201 : {
202 : case FN_FRAME_WRAP_RIGHT:
203 0 : mpRBWrapRight->Check( pBoolItem->GetValue() );
204 0 : break;
205 : case FN_FRAME_WRAP_LEFT:
206 0 : mpRBWrapLeft->Check( pBoolItem->GetValue() );
207 0 : break;
208 : case FN_FRAME_WRAPTHRU:
209 0 : mpRBWrapThrough->Check( pBoolItem->GetValue() );
210 0 : break;
211 : case FN_FRAME_WRAP_IDEAL:
212 0 : mpRBIdealWrap->Check( pBoolItem->GetValue() );
213 0 : break;
214 : case FN_FRAME_WRAP:
215 0 : mpRBWrapParallel->Check( pBoolItem->GetValue() );
216 0 : break;
217 : case FN_FRAME_NOWRAP:
218 : default:
219 0 : mpRBNoWrap->Check( pBoolItem->GetValue() );
220 0 : break;
221 : }
222 : }
223 : else
224 : {
225 0 : mpRBNoWrap->Enable(false);
226 0 : mpRBWrapLeft->Enable(false);
227 0 : mpRBWrapRight->Enable(false);
228 0 : mpRBWrapParallel->Enable(false);
229 0 : mpRBWrapThrough->Enable(false);
230 0 : mpRBIdealWrap->Enable(false);
231 :
232 0 : mpRBNoWrap->Check( false );
233 0 : mpRBWrapLeft->Check( false );
234 0 : mpRBWrapRight->Check( false );
235 0 : mpRBWrapParallel->Check( false );
236 0 : mpRBWrapThrough->Check( false );
237 0 : mpRBIdealWrap->Check( false );
238 : }
239 0 : }
240 :
241 270 : } } // end of namespace ::sw::sidebar
242 :
243 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|