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