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