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