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