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