1*e1f63238SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*e1f63238SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*e1f63238SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*e1f63238SAndrew Rist * distributed with this work for additional information 6*e1f63238SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*e1f63238SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*e1f63238SAndrew Rist * "License"); you may not use this file except in compliance 9*e1f63238SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*e1f63238SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*e1f63238SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*e1f63238SAndrew Rist * software distributed under the License is distributed on an 15*e1f63238SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*e1f63238SAndrew Rist * KIND, either express or implied. See the License for the 17*e1f63238SAndrew Rist * specific language governing permissions and limitations 18*e1f63238SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*e1f63238SAndrew Rist *************************************************************/ 21*e1f63238SAndrew Rist 22*e1f63238SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_basic.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #ifndef _SV_BUTTON_HXX //autogen 28cdf0e10cSrcweir #include <vcl/button.hxx> 29cdf0e10cSrcweir #endif 30cdf0e10cSrcweir #include <vcl/fixed.hxx> 31cdf0e10cSrcweir #include <vcl/edit.hxx> 32cdf0e10cSrcweir #include <vcl/dialog.hxx> 33cdf0e10cSrcweir #include <vcl/svapp.hxx> 34cdf0e10cSrcweir #include "runtime.hxx" 35cdf0e10cSrcweir #include "stdobj.hxx" 36cdf0e10cSrcweir #include "rtlproto.hxx" 37cdf0e10cSrcweir 38cdf0e10cSrcweir class SvRTLInputBox : public ModalDialog 39cdf0e10cSrcweir { 40cdf0e10cSrcweir Edit aEdit; 41cdf0e10cSrcweir OKButton aOk; 42cdf0e10cSrcweir CancelButton aCancel; 43cdf0e10cSrcweir FixedText aPromptText; 44cdf0e10cSrcweir String aText; 45cdf0e10cSrcweir 46cdf0e10cSrcweir void PositionDialog( long nXTwips, long nYTwips, const Size& rDlgSize ); 47cdf0e10cSrcweir void InitButtons( const Size& rDlgSize ); 48cdf0e10cSrcweir void PositionEdit( const Size& rDlgSize ); 49cdf0e10cSrcweir void PositionPrompt( const String& rPrompt, const Size& rDlgSize ); 50cdf0e10cSrcweir DECL_LINK( OkHdl, Button * ); 51cdf0e10cSrcweir DECL_LINK( CancelHdl, Button * ); 52cdf0e10cSrcweir 53cdf0e10cSrcweir public: 54cdf0e10cSrcweir SvRTLInputBox( Window* pParent, const String& rPrompt, const String& rTitle, 55cdf0e10cSrcweir const String& rDefault, long nXTwips = -1, long nYTwips = -1 ); 56cdf0e10cSrcweir String GetText() const { return aText; } 57cdf0e10cSrcweir }; 58cdf0e10cSrcweir 59cdf0e10cSrcweir SvRTLInputBox::SvRTLInputBox( Window* pParent, const String& rPrompt, 60cdf0e10cSrcweir const String& rTitle, const String& rDefault, 61cdf0e10cSrcweir long nXTwips, long nYTwips ) : 62cdf0e10cSrcweir ModalDialog( pParent,WB_3DLOOK | WB_MOVEABLE | WB_CLOSEABLE ), 63cdf0e10cSrcweir aEdit( this, WB_LEFT | WB_BORDER ), 64cdf0e10cSrcweir aOk( this ), aCancel( this ), aPromptText( this, WB_WORDBREAK ) 65cdf0e10cSrcweir { 66cdf0e10cSrcweir SetMapMode( MapMode( MAP_APPFONT ) ); 67cdf0e10cSrcweir Size aDlgSizeApp( 280, 80 ); 68cdf0e10cSrcweir PositionDialog( nXTwips, nYTwips, aDlgSizeApp ); 69cdf0e10cSrcweir InitButtons( aDlgSizeApp ); 70cdf0e10cSrcweir PositionEdit( aDlgSizeApp ); 71cdf0e10cSrcweir PositionPrompt( rPrompt, aDlgSizeApp ); 72cdf0e10cSrcweir aOk.Show(); 73cdf0e10cSrcweir aCancel.Show(); 74cdf0e10cSrcweir aEdit.Show(); 75cdf0e10cSrcweir aPromptText.Show(); 76cdf0e10cSrcweir SetText( rTitle ); 77cdf0e10cSrcweir Font aFont( GetFont()); 78cdf0e10cSrcweir Color aColor( GetBackground().GetColor() ); 79cdf0e10cSrcweir aFont.SetFillColor( aColor ); 80cdf0e10cSrcweir aEdit.SetFont( aFont ); 81cdf0e10cSrcweir aEdit.SetText( rDefault ); 82cdf0e10cSrcweir aEdit.SetSelection( Selection( SELECTION_MIN, SELECTION_MAX ) ); 83cdf0e10cSrcweir } 84cdf0e10cSrcweir 85cdf0e10cSrcweir void SvRTLInputBox::InitButtons( const Size& rDlgSize ) 86cdf0e10cSrcweir { 87cdf0e10cSrcweir aOk.SetSizePixel( LogicToPixel( Size( 45, 15) )); 88cdf0e10cSrcweir aCancel.SetSizePixel( LogicToPixel( Size( 45, 15) )); 89cdf0e10cSrcweir Point aPos( rDlgSize.Width()-45-10, 5 ); 90cdf0e10cSrcweir aOk.SetPosPixel( LogicToPixel( Point(aPos) )); 91cdf0e10cSrcweir aPos.Y() += 16; 92cdf0e10cSrcweir aCancel.SetPosPixel( LogicToPixel( Point(aPos) )); 93cdf0e10cSrcweir aOk.SetClickHdl(LINK(this,SvRTLInputBox, OkHdl)); 94cdf0e10cSrcweir aCancel.SetClickHdl(LINK(this,SvRTLInputBox,CancelHdl)); 95cdf0e10cSrcweir } 96cdf0e10cSrcweir 97cdf0e10cSrcweir void SvRTLInputBox::PositionDialog(long nXTwips, long nYTwips, const Size& rDlgSize) 98cdf0e10cSrcweir { 99cdf0e10cSrcweir SetSizePixel( LogicToPixel(rDlgSize) ); 100cdf0e10cSrcweir if( nXTwips != -1 && nYTwips != -1 ) 101cdf0e10cSrcweir { 102cdf0e10cSrcweir Point aDlgPosApp( nXTwips, nYTwips ); 103cdf0e10cSrcweir SetPosPixel( LogicToPixel( aDlgPosApp, MAP_TWIP ) ); 104cdf0e10cSrcweir } 105cdf0e10cSrcweir } 106cdf0e10cSrcweir 107cdf0e10cSrcweir void SvRTLInputBox::PositionEdit( const Size& rDlgSize ) 108cdf0e10cSrcweir { 109cdf0e10cSrcweir aEdit.SetPosPixel( LogicToPixel( Point( 5,rDlgSize.Height()-35))); 110cdf0e10cSrcweir aEdit.SetSizePixel( LogicToPixel( Size(rDlgSize.Width()-15,12))); 111cdf0e10cSrcweir } 112cdf0e10cSrcweir 113cdf0e10cSrcweir 114cdf0e10cSrcweir void SvRTLInputBox::PositionPrompt(const String& rPrompt,const Size& rDlgSize) 115cdf0e10cSrcweir { 116cdf0e10cSrcweir if ( rPrompt.Len() == 0 ) 117cdf0e10cSrcweir return; 118cdf0e10cSrcweir String aText_( rPrompt ); 119cdf0e10cSrcweir aText_.ConvertLineEnd( LINEEND_CR ); 120cdf0e10cSrcweir aPromptText.SetPosPixel( LogicToPixel(Point(5,5))); 121cdf0e10cSrcweir aPromptText.SetText( aText_ ); 122cdf0e10cSrcweir Size aSize( rDlgSize ); 123cdf0e10cSrcweir aSize.Width() -= 70; 124cdf0e10cSrcweir aSize.Height() -= 50; 125cdf0e10cSrcweir aPromptText.SetSizePixel( LogicToPixel(aSize)); 126cdf0e10cSrcweir } 127cdf0e10cSrcweir 128cdf0e10cSrcweir 129cdf0e10cSrcweir IMPL_LINK_INLINE_START( SvRTLInputBox, OkHdl, Button *, pButton ) 130cdf0e10cSrcweir { 131cdf0e10cSrcweir (void)pButton; 132cdf0e10cSrcweir 133cdf0e10cSrcweir aText = aEdit.GetText(); 134cdf0e10cSrcweir EndDialog( 1 ); 135cdf0e10cSrcweir return 0; 136cdf0e10cSrcweir } 137cdf0e10cSrcweir IMPL_LINK_INLINE_END( SvRTLInputBox, OkHdl, Button *, pButton ) 138cdf0e10cSrcweir 139cdf0e10cSrcweir IMPL_LINK_INLINE_START( SvRTLInputBox, CancelHdl, Button *, pButton ) 140cdf0e10cSrcweir { 141cdf0e10cSrcweir (void)pButton; 142cdf0e10cSrcweir 143cdf0e10cSrcweir aText.Erase(); 144cdf0e10cSrcweir EndDialog( 0 ); 145cdf0e10cSrcweir return 0; 146cdf0e10cSrcweir } 147cdf0e10cSrcweir IMPL_LINK_INLINE_END( SvRTLInputBox, CancelHdl, Button *, pButton ) 148cdf0e10cSrcweir 149cdf0e10cSrcweir 150cdf0e10cSrcweir // ********************************************************************* 151cdf0e10cSrcweir // ********************************************************************* 152cdf0e10cSrcweir // ********************************************************************* 153cdf0e10cSrcweir 154cdf0e10cSrcweir // Syntax: String InputBox( Prompt, [Title], [Default] [, nXpos, nYpos ] ) 155cdf0e10cSrcweir 156cdf0e10cSrcweir RTLFUNC(InputBox) 157cdf0e10cSrcweir { 158cdf0e10cSrcweir (void)pBasic; 159cdf0e10cSrcweir (void)bWrite; 160cdf0e10cSrcweir 161cdf0e10cSrcweir sal_uIntPtr nArgCount = rPar.Count(); 162cdf0e10cSrcweir if ( nArgCount < 2 ) 163cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 164cdf0e10cSrcweir else 165cdf0e10cSrcweir { 166cdf0e10cSrcweir String aTitle; 167cdf0e10cSrcweir String aDefault; 168cdf0e10cSrcweir sal_Int32 nX = -1, nY = -1; // zentrieren 169cdf0e10cSrcweir const String& rPrompt = rPar.Get(1)->GetString(); 170cdf0e10cSrcweir if ( nArgCount > 2 && !rPar.Get(2)->IsErr() ) 171cdf0e10cSrcweir aTitle = rPar.Get(2)->GetString(); 172cdf0e10cSrcweir if ( nArgCount > 3 && !rPar.Get(3)->IsErr() ) 173cdf0e10cSrcweir aDefault = rPar.Get(3)->GetString(); 174cdf0e10cSrcweir if ( nArgCount > 4 ) 175cdf0e10cSrcweir { 176cdf0e10cSrcweir if ( nArgCount != 6 ) 177cdf0e10cSrcweir { 178cdf0e10cSrcweir StarBASIC::Error( SbERR_BAD_ARGUMENT ); 179cdf0e10cSrcweir return; 180cdf0e10cSrcweir } 181cdf0e10cSrcweir nX = rPar.Get(4)->GetLong(); 182cdf0e10cSrcweir nY = rPar.Get(5)->GetLong(); 183cdf0e10cSrcweir } 184cdf0e10cSrcweir SvRTLInputBox *pDlg=new SvRTLInputBox(GetpApp()->GetDefDialogParent(), 185cdf0e10cSrcweir rPrompt,aTitle,aDefault,nX,nY); 186cdf0e10cSrcweir pDlg->Execute(); 187cdf0e10cSrcweir rPar.Get(0)->PutString( pDlg->GetText() ); 188cdf0e10cSrcweir delete pDlg; 189cdf0e10cSrcweir } 190cdf0e10cSrcweir } 191cdf0e10cSrcweir 192cdf0e10cSrcweir 193cdf0e10cSrcweir 194