1ff0525f2SOliver-Rainer Wittmann /**************************************************************
2ff0525f2SOliver-Rainer Wittmann *
3ff0525f2SOliver-Rainer Wittmann * Licensed to the Apache Software Foundation (ASF) under one
4ff0525f2SOliver-Rainer Wittmann * or more contributor license agreements. See the NOTICE file
5ff0525f2SOliver-Rainer Wittmann * distributed with this work for additional information
6ff0525f2SOliver-Rainer Wittmann * regarding copyright ownership. The ASF licenses this file
7ff0525f2SOliver-Rainer Wittmann * to you under the Apache License, Version 2.0 (the
8ff0525f2SOliver-Rainer Wittmann * "License"); you may not use this file except in compliance
9ff0525f2SOliver-Rainer Wittmann * with the License. You may obtain a copy of the License at
10ff0525f2SOliver-Rainer Wittmann *
11ff0525f2SOliver-Rainer Wittmann * http://www.apache.org/licenses/LICENSE-2.0
12ff0525f2SOliver-Rainer Wittmann *
13ff0525f2SOliver-Rainer Wittmann * Unless required by applicable law or agreed to in writing,
14ff0525f2SOliver-Rainer Wittmann * software distributed under the License is distributed on an
15ff0525f2SOliver-Rainer Wittmann * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16ff0525f2SOliver-Rainer Wittmann * KIND, either express or implied. See the License for the
17ff0525f2SOliver-Rainer Wittmann * specific language governing permissions and limitations
18ff0525f2SOliver-Rainer Wittmann * under the License.
19ff0525f2SOliver-Rainer Wittmann *
20ff0525f2SOliver-Rainer Wittmann *************************************************************/
21ff0525f2SOliver-Rainer Wittmann
22ff0525f2SOliver-Rainer Wittmann #include "precompiled_sw.hxx"
23ff0525f2SOliver-Rainer Wittmann
24ff0525f2SOliver-Rainer Wittmann #include "PageSizeControl.hxx"
25ff0525f2SOliver-Rainer Wittmann #include "PagePropertyPanel.hxx"
26ff0525f2SOliver-Rainer Wittmann #include "PagePropertyPanel.hrc"
27ff0525f2SOliver-Rainer Wittmann
28ff0525f2SOliver-Rainer Wittmann #include <cmdid.h>
29ff0525f2SOliver-Rainer Wittmann #include <swtypes.hxx>
30ff0525f2SOliver-Rainer Wittmann
31ff0525f2SOliver-Rainer Wittmann #include <svx/sidebar/ValueSetWithTextControl.hxx>
32ff0525f2SOliver-Rainer Wittmann
33ff0525f2SOliver-Rainer Wittmann #include <tools/inetmime.hxx>
34f120fe41SAndre Fischer #include <editeng/paperinf.hxx>
35f120fe41SAndre Fischer #include <sfx2/bindings.hxx>
36f120fe41SAndre Fischer #include <sfx2/dispatch.hxx>
37f120fe41SAndre Fischer
38ff0525f2SOliver-Rainer Wittmann
39ff0525f2SOliver-Rainer Wittmann namespace sw { namespace sidebar {
40ff0525f2SOliver-Rainer Wittmann
PageSizeControl(Window * pParent,PagePropertyPanel & rPanel,const Paper ePaper,const sal_Bool bLandscape,const FieldUnit eFUnit)41ff0525f2SOliver-Rainer Wittmann PageSizeControl::PageSizeControl(
42ff0525f2SOliver-Rainer Wittmann Window* pParent,
43ff0525f2SOliver-Rainer Wittmann PagePropertyPanel& rPanel,
44ff0525f2SOliver-Rainer Wittmann const Paper ePaper,
45ff0525f2SOliver-Rainer Wittmann const sal_Bool bLandscape,
46ff0525f2SOliver-Rainer Wittmann const FieldUnit eFUnit )
47ff0525f2SOliver-Rainer Wittmann : ::svx::sidebar::PopupControl( pParent, SW_RES(RID_POPUP_SWPAGE_SIZE) )
48ff0525f2SOliver-Rainer Wittmann , mpSizeValueSet( new ::svx::sidebar::ValueSetWithTextControl( ::svx::sidebar::ValueSetWithTextControl::TEXT_TEXT, this, SW_RES(VS_SIZE) ) )
49ff0525f2SOliver-Rainer Wittmann , maMoreButton( this, SW_RES(CB_SIZE_MORE) )
50ff0525f2SOliver-Rainer Wittmann , maWidthHeightField( this, SW_RES(FLD_WIDTH_HEIGHT) )
51ff0525f2SOliver-Rainer Wittmann , mePaper( ePaper )
52ff0525f2SOliver-Rainer Wittmann , maPaperList()
53ff0525f2SOliver-Rainer Wittmann , mrPagePropPanel(rPanel)
54ff0525f2SOliver-Rainer Wittmann {
55ff0525f2SOliver-Rainer Wittmann maWidthHeightField.Hide();
56ff0525f2SOliver-Rainer Wittmann SetFieldUnit( maWidthHeightField, eFUnit );
57ff0525f2SOliver-Rainer Wittmann
58ff0525f2SOliver-Rainer Wittmann maPaperList.push_back( PAPER_A3 );
59ff0525f2SOliver-Rainer Wittmann maPaperList.push_back( PAPER_A4 );
60ff0525f2SOliver-Rainer Wittmann maPaperList.push_back( PAPER_A5 );
61ff0525f2SOliver-Rainer Wittmann maPaperList.push_back( PAPER_B4_ISO );
62ff0525f2SOliver-Rainer Wittmann maPaperList.push_back( PAPER_B5_ISO );
63ff0525f2SOliver-Rainer Wittmann maPaperList.push_back( PAPER_ENV_C5 );
64ff0525f2SOliver-Rainer Wittmann maPaperList.push_back( PAPER_LETTER );
65ff0525f2SOliver-Rainer Wittmann maPaperList.push_back( PAPER_LEGAL );
66ff0525f2SOliver-Rainer Wittmann
67ff0525f2SOliver-Rainer Wittmann mpSizeValueSet->SetStyle( mpSizeValueSet->GetStyle() | WB_3DLOOK | WB_NO_DIRECTSELECT );
68ff0525f2SOliver-Rainer Wittmann mpSizeValueSet->SetColor( GetSettings().GetStyleSettings().GetMenuColor() );
69ff0525f2SOliver-Rainer Wittmann
70ff0525f2SOliver-Rainer Wittmann sal_uInt16 nSelectedItem = 0;
71ff0525f2SOliver-Rainer Wittmann {
72ff0525f2SOliver-Rainer Wittmann XubString aMetricStr;
73ff0525f2SOliver-Rainer Wittmann {
74ff0525f2SOliver-Rainer Wittmann const XubString aText = maWidthHeightField.GetText();
75ff0525f2SOliver-Rainer Wittmann for (short i = aText.Len() - 1; i >= 0; i--)
76ff0525f2SOliver-Rainer Wittmann {
77ff0525f2SOliver-Rainer Wittmann xub_Unicode c = aText.GetChar(i);
78ff0525f2SOliver-Rainer Wittmann if ( INetMIME::isAlpha(c) || (c == '\'') || (c == '\"') || (c == '%') )
79ff0525f2SOliver-Rainer Wittmann {
80ff0525f2SOliver-Rainer Wittmann aMetricStr.Insert(c, 0);
81ff0525f2SOliver-Rainer Wittmann }
82ff0525f2SOliver-Rainer Wittmann else
83ff0525f2SOliver-Rainer Wittmann {
84ff0525f2SOliver-Rainer Wittmann if (aMetricStr.Len())
85ff0525f2SOliver-Rainer Wittmann {
86ff0525f2SOliver-Rainer Wittmann break;
87ff0525f2SOliver-Rainer Wittmann }
88ff0525f2SOliver-Rainer Wittmann }
89ff0525f2SOliver-Rainer Wittmann }
90ff0525f2SOliver-Rainer Wittmann }
91ff0525f2SOliver-Rainer Wittmann
92ff0525f2SOliver-Rainer Wittmann const LocaleDataWrapper& localeDataWrapper = maWidthHeightField.GetLocaleDataWrapper();
93ff0525f2SOliver-Rainer Wittmann String WidthStr;
94ff0525f2SOliver-Rainer Wittmann String HeightStr;
95ff0525f2SOliver-Rainer Wittmann String ItemText2;
96ff0525f2SOliver-Rainer Wittmann for ( ::std::vector< Paper >::size_type nPaperIdx = 0;
97ff0525f2SOliver-Rainer Wittmann nPaperIdx < maPaperList.size();
98ff0525f2SOliver-Rainer Wittmann ++nPaperIdx )
99ff0525f2SOliver-Rainer Wittmann {
100ff0525f2SOliver-Rainer Wittmann Size aPaperSize = SvxPaperInfo::GetPaperSize( maPaperList[ nPaperIdx ] );
101ff0525f2SOliver-Rainer Wittmann if ( bLandscape )
102ff0525f2SOliver-Rainer Wittmann {
103ff0525f2SOliver-Rainer Wittmann Swap( aPaperSize );
104ff0525f2SOliver-Rainer Wittmann }
105ff0525f2SOliver-Rainer Wittmann maWidthHeightField.SetValue( maWidthHeightField.Normalize( aPaperSize.Width() ), FUNIT_TWIP );
106ff0525f2SOliver-Rainer Wittmann WidthStr = localeDataWrapper.getNum(
107ff0525f2SOliver-Rainer Wittmann maWidthHeightField.GetValue(),
108ff0525f2SOliver-Rainer Wittmann maWidthHeightField.GetDecimalDigits(),
109ff0525f2SOliver-Rainer Wittmann maWidthHeightField.IsUseThousandSep(),
110ff0525f2SOliver-Rainer Wittmann maWidthHeightField.IsShowTrailingZeros() );
111ff0525f2SOliver-Rainer Wittmann
112ff0525f2SOliver-Rainer Wittmann maWidthHeightField.SetValue( maWidthHeightField.Normalize( aPaperSize.Height() ), FUNIT_TWIP);
113ff0525f2SOliver-Rainer Wittmann HeightStr = localeDataWrapper.getNum(
114ff0525f2SOliver-Rainer Wittmann maWidthHeightField.GetValue(),
115ff0525f2SOliver-Rainer Wittmann maWidthHeightField.GetDecimalDigits(),
116ff0525f2SOliver-Rainer Wittmann maWidthHeightField.IsUseThousandSep(),
117ff0525f2SOliver-Rainer Wittmann maWidthHeightField.IsShowTrailingZeros() );
118ff0525f2SOliver-Rainer Wittmann
119*e807eedeSOliver-Rainer Wittmann ItemText2 = WidthStr;
120ff0525f2SOliver-Rainer Wittmann ItemText2 += String::CreateFromAscii(" x ");
121*e807eedeSOliver-Rainer Wittmann ItemText2 += HeightStr;
122ff0525f2SOliver-Rainer Wittmann ItemText2 += String::CreateFromAscii(" ");
123ff0525f2SOliver-Rainer Wittmann ItemText2 += aMetricStr;
124ff0525f2SOliver-Rainer Wittmann
125ff0525f2SOliver-Rainer Wittmann mpSizeValueSet->AddItem(
126ff0525f2SOliver-Rainer Wittmann SvxPaperInfo::GetName( maPaperList[ nPaperIdx ] ),
127ff0525f2SOliver-Rainer Wittmann ItemText2,
128ff0525f2SOliver-Rainer Wittmann 0 );
129ff0525f2SOliver-Rainer Wittmann
130ff0525f2SOliver-Rainer Wittmann if ( maPaperList[ nPaperIdx ] == mePaper )
131ff0525f2SOliver-Rainer Wittmann {
132ff0525f2SOliver-Rainer Wittmann nSelectedItem = nPaperIdx + 1;
133ff0525f2SOliver-Rainer Wittmann }
134ff0525f2SOliver-Rainer Wittmann }
135ff0525f2SOliver-Rainer Wittmann }
136ff0525f2SOliver-Rainer Wittmann
137ff0525f2SOliver-Rainer Wittmann mpSizeValueSet->SetNoSelection();
138ff0525f2SOliver-Rainer Wittmann mpSizeValueSet->SetSelectHdl( LINK(this, PageSizeControl,ImplSizeHdl ) );
139ff0525f2SOliver-Rainer Wittmann mpSizeValueSet->Show();
140ff0525f2SOliver-Rainer Wittmann
141ff0525f2SOliver-Rainer Wittmann mpSizeValueSet->SelectItem( nSelectedItem );
142ff0525f2SOliver-Rainer Wittmann mpSizeValueSet->Format();
143ff0525f2SOliver-Rainer Wittmann mpSizeValueSet->StartSelection();
144ff0525f2SOliver-Rainer Wittmann
145ff0525f2SOliver-Rainer Wittmann maMoreButton.SetClickHdl( LINK( this, PageSizeControl, MoreButtonClickHdl_Impl ) );
146ff0525f2SOliver-Rainer Wittmann maMoreButton.GrabFocus();
147ff0525f2SOliver-Rainer Wittmann
148ff0525f2SOliver-Rainer Wittmann FreeResource();
149ff0525f2SOliver-Rainer Wittmann }
150ff0525f2SOliver-Rainer Wittmann
151ff0525f2SOliver-Rainer Wittmann
~PageSizeControl(void)152ff0525f2SOliver-Rainer Wittmann PageSizeControl::~PageSizeControl(void)
153ff0525f2SOliver-Rainer Wittmann {
154ff0525f2SOliver-Rainer Wittmann delete mpSizeValueSet;
155ff0525f2SOliver-Rainer Wittmann }
156ff0525f2SOliver-Rainer Wittmann
157ff0525f2SOliver-Rainer Wittmann
IMPL_LINK(PageSizeControl,ImplSizeHdl,void *,pControl)158ff0525f2SOliver-Rainer Wittmann IMPL_LINK(PageSizeControl, ImplSizeHdl, void *, pControl)
159ff0525f2SOliver-Rainer Wittmann {
160ff0525f2SOliver-Rainer Wittmann mpSizeValueSet->SetNoSelection();
161ff0525f2SOliver-Rainer Wittmann if ( pControl == mpSizeValueSet )
162ff0525f2SOliver-Rainer Wittmann {
163ff0525f2SOliver-Rainer Wittmann const sal_uInt16 nSelectedPaper = mpSizeValueSet->GetSelectItemId();
164ff0525f2SOliver-Rainer Wittmann const Paper ePaper = maPaperList[nSelectedPaper - 1];
165ff0525f2SOliver-Rainer Wittmann if ( ePaper != mePaper )
166ff0525f2SOliver-Rainer Wittmann {
167ff0525f2SOliver-Rainer Wittmann mePaper = ePaper;
168ff0525f2SOliver-Rainer Wittmann mrPagePropPanel.ExecuteSizeChange( mePaper );
169ff0525f2SOliver-Rainer Wittmann }
170ff0525f2SOliver-Rainer Wittmann }
171ff0525f2SOliver-Rainer Wittmann
172ff0525f2SOliver-Rainer Wittmann mrPagePropPanel.ClosePageSizePopup();
173ff0525f2SOliver-Rainer Wittmann return 0;
174ff0525f2SOliver-Rainer Wittmann }
175ff0525f2SOliver-Rainer Wittmann
IMPL_LINK(PageSizeControl,MoreButtonClickHdl_Impl,void *,EMPTYARG)176ff0525f2SOliver-Rainer Wittmann IMPL_LINK(PageSizeControl, MoreButtonClickHdl_Impl, void *, EMPTYARG)
177ff0525f2SOliver-Rainer Wittmann {
178ff0525f2SOliver-Rainer Wittmann mrPagePropPanel.GetBindings()->GetDispatcher()->Execute( FN_FORMAT_PAGE_SETTING_DLG, SFX_CALLMODE_ASYNCHRON );
179ff0525f2SOliver-Rainer Wittmann
180ff0525f2SOliver-Rainer Wittmann mrPagePropPanel.ClosePageSizePopup();
181ff0525f2SOliver-Rainer Wittmann return 0;
182ff0525f2SOliver-Rainer Wittmann }
183ff0525f2SOliver-Rainer Wittmann
184ff0525f2SOliver-Rainer Wittmann
185ff0525f2SOliver-Rainer Wittmann } } // end of namespace sw::sidebar
186ff0525f2SOliver-Rainer Wittmann
187