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 "PageOrientationControl.hxx" 25 #include "PagePropertyPanel.hxx" 26 #include "PagePropertyPanel.hrc" 27 28 #include <swtypes.hxx> 29 30 #include <svx/sidebar/ValueSetWithTextControl.hxx> 31 32 namespace sw { namespace sidebar { 33 34 PageOrientationControl::PageOrientationControl( 35 Window* pParent, 36 PagePropertyPanel& rPanel, 37 const sal_Bool bLandscape ) 38 : ::svx::sidebar::PopupControl( pParent, SW_RES(RID_POPUP_SWPAGE_ORIENTATION) ) 39 , mpOrientationValueSet( new ::svx::sidebar::ValueSetWithTextControl( ::svx::sidebar::ValueSetWithTextControl::IMAGE_TEXT, this, SW_RES(VS_ORIENTATION) ) ) 40 , mbLandscape( bLandscape ) 41 , mrPagePropPanel(rPanel) 42 { 43 mpOrientationValueSet->SetStyle( mpOrientationValueSet->GetStyle() | WB_3DLOOK | WB_NO_DIRECTSELECT ); 44 mpOrientationValueSet->SetColor(GetSettings().GetStyleSettings().GetMenuColor()); 45 46 // initialize <ValueSetWithText> control 47 { 48 mpOrientationValueSet->AddItem( SW_RES(IMG_PORTRAIT), 0, SW_RES(STR_PORTRAIT), 0 ); 49 mpOrientationValueSet->AddItem( SW_RES(IMG_LANDSCAPE), 0, SW_RES(STR_LANDSCAPE), 0 ); 50 } 51 52 Link aLink = LINK(this, PageOrientationControl,ImplOrientationHdl ); 53 mpOrientationValueSet->SetSelectHdl(aLink); 54 mpOrientationValueSet->SetNoSelection(); 55 mpOrientationValueSet->StartSelection(); 56 mpOrientationValueSet->Show(); 57 mpOrientationValueSet->SelectItem( (mbLandscape == sal_True) ? 2 : 1 ); 58 mpOrientationValueSet->GrabFocus(); 59 mpOrientationValueSet->Format(); 60 mpOrientationValueSet->StartSelection(); 61 62 FreeResource(); 63 } 64 65 66 PageOrientationControl::~PageOrientationControl(void) 67 { 68 delete mpOrientationValueSet; 69 } 70 71 72 IMPL_LINK(PageOrientationControl, ImplOrientationHdl, void *, pControl) 73 { 74 mpOrientationValueSet->SetNoSelection(); 75 if ( pControl == mpOrientationValueSet ) 76 { 77 const sal_uInt32 iPos = mpOrientationValueSet->GetSelectItemId(); 78 const bool bChanged = ( ( iPos == 1 ) && mbLandscape ) || 79 ( ( iPos == 2 ) && !mbLandscape ); 80 if ( bChanged ) 81 { 82 mbLandscape = !mbLandscape; 83 mrPagePropPanel.ExecuteOrientationChange( mbLandscape ); 84 } 85 } 86 87 mrPagePropPanel.ClosePageOrientationPopup(); 88 return 0; 89 } 90 91 92 } } // end of namespace sw::sidebar 93 94