merge the formfield patch from ooo-build
[ooovba.git] / basic / source / runtime / inputbox.cxx
blob78445d39afe71b48c3c4b1804ca6bfae7faf4883
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: inputbox.cxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_basic.hxx"
34 #ifndef _SV_BUTTON_HXX //autogen
35 #include <vcl/button.hxx>
36 #endif
37 #include <vcl/fixed.hxx>
38 #include <vcl/edit.hxx>
39 #include <vcl/dialog.hxx>
40 #include <vcl/svapp.hxx>
41 #include "runtime.hxx"
42 #include "stdobj.hxx"
43 #include "rtlproto.hxx"
45 class SvRTLInputBox : public ModalDialog
47 Edit aEdit;
48 OKButton aOk;
49 CancelButton aCancel;
50 FixedText aPromptText;
51 String aText;
53 void PositionDialog( long nXTwips, long nYTwips, const Size& rDlgSize );
54 void InitButtons( const Size& rDlgSize );
55 void PositionEdit( const Size& rDlgSize );
56 void PositionPrompt( const String& rPrompt, const Size& rDlgSize );
57 DECL_LINK( OkHdl, Button * );
58 DECL_LINK( CancelHdl, Button * );
60 public:
61 SvRTLInputBox( Window* pParent, const String& rPrompt, const String& rTitle,
62 const String& rDefault, long nXTwips = -1, long nYTwips = -1 );
63 String GetText() const { return aText; }
66 SvRTLInputBox::SvRTLInputBox( Window* pParent, const String& rPrompt,
67 const String& rTitle, const String& rDefault,
68 long nXTwips, long nYTwips ) :
69 ModalDialog( pParent,WB_3DLOOK | WB_MOVEABLE | WB_CLOSEABLE ),
70 aEdit( this, WB_LEFT | WB_BORDER ),
71 aOk( this ), aCancel( this ), aPromptText( this, WB_WORDBREAK )
73 SetMapMode( MapMode( MAP_APPFONT ) );
74 Size aDlgSizeApp( 280, 80 );
75 PositionDialog( nXTwips, nYTwips, aDlgSizeApp );
76 InitButtons( aDlgSizeApp );
77 PositionEdit( aDlgSizeApp );
78 PositionPrompt( rPrompt, aDlgSizeApp );
79 aOk.Show();
80 aCancel.Show();
81 aEdit.Show();
82 aPromptText.Show();
83 SetText( rTitle );
84 Font aFont( GetFont());
85 Color aColor( GetBackground().GetColor() );
86 aFont.SetFillColor( aColor );
87 aEdit.SetFont( aFont );
88 aEdit.SetText( rDefault );
89 aEdit.SetSelection( Selection( SELECTION_MIN, SELECTION_MAX ) );
92 void SvRTLInputBox::InitButtons( const Size& rDlgSize )
94 aOk.SetSizePixel( LogicToPixel( Size( 45, 15) ));
95 aCancel.SetSizePixel( LogicToPixel( Size( 45, 15) ));
96 Point aPos( rDlgSize.Width()-45-10, 5 );
97 aOk.SetPosPixel( LogicToPixel( Point(aPos) ));
98 aPos.Y() += 16;
99 aCancel.SetPosPixel( LogicToPixel( Point(aPos) ));
100 aOk.SetClickHdl(LINK(this,SvRTLInputBox, OkHdl));
101 aCancel.SetClickHdl(LINK(this,SvRTLInputBox,CancelHdl));
104 void SvRTLInputBox::PositionDialog(long nXTwips, long nYTwips, const Size& rDlgSize)
106 SetSizePixel( LogicToPixel(rDlgSize) );
107 if( nXTwips != -1 && nYTwips != -1 )
109 Point aDlgPosApp( nXTwips, nYTwips );
110 SetPosPixel( LogicToPixel( aDlgPosApp, MAP_TWIP ) );
114 void SvRTLInputBox::PositionEdit( const Size& rDlgSize )
116 aEdit.SetPosPixel( LogicToPixel( Point( 5,rDlgSize.Height()-35)));
117 aEdit.SetSizePixel( LogicToPixel( Size(rDlgSize.Width()-15,12)));
121 void SvRTLInputBox::PositionPrompt(const String& rPrompt,const Size& rDlgSize)
123 if ( rPrompt.Len() == 0 )
124 return;
125 String aText_( rPrompt );
126 aText_.ConvertLineEnd( LINEEND_CR );
127 aPromptText.SetPosPixel( LogicToPixel(Point(5,5)));
128 aPromptText.SetText( aText_ );
129 Size aSize( rDlgSize );
130 aSize.Width() -= 70;
131 aSize.Height() -= 50;
132 aPromptText.SetSizePixel( LogicToPixel(aSize));
136 IMPL_LINK_INLINE_START( SvRTLInputBox, OkHdl, Button *, pButton )
138 (void)pButton;
140 aText = aEdit.GetText();
141 EndDialog( 1 );
142 return 0;
144 IMPL_LINK_INLINE_END( SvRTLInputBox, OkHdl, Button *, pButton )
146 IMPL_LINK_INLINE_START( SvRTLInputBox, CancelHdl, Button *, pButton )
148 (void)pButton;
150 aText.Erase();
151 EndDialog( 0 );
152 return 0;
154 IMPL_LINK_INLINE_END( SvRTLInputBox, CancelHdl, Button *, pButton )
157 // *********************************************************************
158 // *********************************************************************
159 // *********************************************************************
161 // Syntax: String InputBox( Prompt, [Title], [Default] [, nXpos, nYpos ] )
163 RTLFUNC(InputBox)
165 (void)pBasic;
166 (void)bWrite;
168 ULONG nArgCount = rPar.Count();
169 if ( nArgCount < 2 )
170 StarBASIC::Error( SbERR_BAD_ARGUMENT );
171 else
173 String aTitle;
174 String aDefault;
175 INT32 nX = -1, nY = -1; // zentrieren
176 const String& rPrompt = rPar.Get(1)->GetString();
177 if ( nArgCount > 2 && !rPar.Get(2)->IsErr() )
178 aTitle = rPar.Get(2)->GetString();
179 if ( nArgCount > 3 && !rPar.Get(3)->IsErr() )
180 aDefault = rPar.Get(3)->GetString();
181 if ( nArgCount > 4 )
183 if ( nArgCount != 6 )
185 StarBASIC::Error( SbERR_BAD_ARGUMENT );
186 return;
188 nX = rPar.Get(4)->GetLong();
189 nY = rPar.Get(5)->GetLong();
191 SvRTLInputBox *pDlg=new SvRTLInputBox(GetpApp()->GetDefDialogParent(),
192 rPrompt,aTitle,aDefault,nX,nY);
193 pDlg->Execute();
194 rPar.Get(0)->PutString( pDlg->GetText() );
195 delete pDlg;