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