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 "PageSizeControl.hxx" 25 #include "PagePropertyPanel.hxx" 26 #include "PagePropertyPanel.hrc" 27 28 #include <cmdid.h> 29 #include <swtypes.hxx> 30 31 #include <svx/sidebar/ValueSetWithTextControl.hxx> 32 33 #include <tools/inetmime.hxx> 34 35 namespace sw { namespace sidebar { 36 37 PageSizeControl::PageSizeControl( 38 Window* pParent, 39 PagePropertyPanel& rPanel, 40 const Paper ePaper, 41 const sal_Bool bLandscape, 42 const FieldUnit eFUnit ) 43 : ::svx::sidebar::PopupControl( pParent, SW_RES(RID_POPUP_SWPAGE_SIZE) ) 44 , mpSizeValueSet( new ::svx::sidebar::ValueSetWithTextControl( ::svx::sidebar::ValueSetWithTextControl::TEXT_TEXT, this, SW_RES(VS_SIZE) ) ) 45 , maMoreButton( this, SW_RES(CB_SIZE_MORE) ) 46 , maWidthHeightField( this, SW_RES(FLD_WIDTH_HEIGHT) ) 47 , mePaper( ePaper ) 48 , maPaperList() 49 , mrPagePropPanel(rPanel) 50 { 51 maWidthHeightField.Hide(); 52 SetFieldUnit( maWidthHeightField, eFUnit ); 53 54 maPaperList.push_back( PAPER_A3 ); 55 maPaperList.push_back( PAPER_A4 ); 56 maPaperList.push_back( PAPER_A5 ); 57 maPaperList.push_back( PAPER_B4_ISO ); 58 maPaperList.push_back( PAPER_B5_ISO ); 59 maPaperList.push_back( PAPER_ENV_C5 ); 60 maPaperList.push_back( PAPER_LETTER ); 61 maPaperList.push_back( PAPER_LEGAL ); 62 63 mpSizeValueSet->SetStyle( mpSizeValueSet->GetStyle() | WB_3DLOOK | WB_NO_DIRECTSELECT ); 64 mpSizeValueSet->SetColor( GetSettings().GetStyleSettings().GetMenuColor() ); 65 66 sal_uInt16 nSelectedItem = 0; 67 { 68 XubString aMetricStr; 69 { 70 const XubString aText = maWidthHeightField.GetText(); 71 for (short i = aText.Len() - 1; i >= 0; i--) 72 { 73 xub_Unicode c = aText.GetChar(i); 74 if ( INetMIME::isAlpha(c) || (c == '\'') || (c == '\"') || (c == '%') ) 75 { 76 aMetricStr.Insert(c, 0); 77 } 78 else 79 { 80 if (aMetricStr.Len()) 81 { 82 break; 83 } 84 } 85 } 86 } 87 88 const LocaleDataWrapper& localeDataWrapper = maWidthHeightField.GetLocaleDataWrapper(); 89 String WidthStr; 90 String HeightStr; 91 String ItemText2; 92 for ( ::std::vector< Paper >::size_type nPaperIdx = 0; 93 nPaperIdx < maPaperList.size(); 94 ++nPaperIdx ) 95 { 96 Size aPaperSize = SvxPaperInfo::GetPaperSize( maPaperList[ nPaperIdx ] ); 97 if ( bLandscape ) 98 { 99 Swap( aPaperSize ); 100 } 101 maWidthHeightField.SetValue( maWidthHeightField.Normalize( aPaperSize.Width() ), FUNIT_TWIP ); 102 WidthStr = localeDataWrapper.getNum( 103 maWidthHeightField.GetValue(), 104 maWidthHeightField.GetDecimalDigits(), 105 maWidthHeightField.IsUseThousandSep(), 106 maWidthHeightField.IsShowTrailingZeros() ); 107 108 maWidthHeightField.SetValue( maWidthHeightField.Normalize( aPaperSize.Height() ), FUNIT_TWIP); 109 HeightStr = localeDataWrapper.getNum( 110 maWidthHeightField.GetValue(), 111 maWidthHeightField.GetDecimalDigits(), 112 maWidthHeightField.IsUseThousandSep(), 113 maWidthHeightField.IsShowTrailingZeros() ); 114 115 ItemText2 = HeightStr; 116 ItemText2 += String::CreateFromAscii(" x "); 117 ItemText2 += WidthStr; 118 ItemText2 += String::CreateFromAscii(" "); 119 ItemText2 += aMetricStr; 120 121 mpSizeValueSet->AddItem( 122 SvxPaperInfo::GetName( maPaperList[ nPaperIdx ] ), 123 ItemText2, 124 0 ); 125 126 if ( maPaperList[ nPaperIdx ] == mePaper ) 127 { 128 nSelectedItem = nPaperIdx + 1; 129 } 130 } 131 } 132 133 mpSizeValueSet->SetNoSelection(); 134 mpSizeValueSet->SetSelectHdl( LINK(this, PageSizeControl,ImplSizeHdl ) ); 135 mpSizeValueSet->Show(); 136 137 mpSizeValueSet->SelectItem( nSelectedItem ); 138 mpSizeValueSet->Format(); 139 mpSizeValueSet->StartSelection(); 140 141 maMoreButton.SetClickHdl( LINK( this, PageSizeControl, MoreButtonClickHdl_Impl ) ); 142 maMoreButton.GrabFocus(); 143 144 FreeResource(); 145 } 146 147 148 PageSizeControl::~PageSizeControl(void) 149 { 150 delete mpSizeValueSet; 151 } 152 153 154 IMPL_LINK(PageSizeControl, ImplSizeHdl, void *, pControl) 155 { 156 mpSizeValueSet->SetNoSelection(); 157 if ( pControl == mpSizeValueSet ) 158 { 159 const sal_uInt16 nSelectedPaper = mpSizeValueSet->GetSelectItemId(); 160 const Paper ePaper = maPaperList[nSelectedPaper - 1]; 161 if ( ePaper != mePaper ) 162 { 163 mePaper = ePaper; 164 mrPagePropPanel.ExecuteSizeChange( mePaper ); 165 } 166 } 167 168 mrPagePropPanel.ClosePageSizePopup(); 169 return 0; 170 } 171 172 IMPL_LINK(PageSizeControl, MoreButtonClickHdl_Impl, void *, EMPTYARG) 173 { 174 mrPagePropPanel.GetBindings()->GetDispatcher()->Execute( FN_FORMAT_PAGE_SETTING_DLG, SFX_CALLMODE_ASYNCHRON ); 175 176 mrPagePropPanel.ClosePageSizePopup(); 177 return 0; 178 } 179 180 181 } } // end of namespace sw::sidebar 182 183