1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: inputbox.cxx,v $
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>
37 #include <vcl/fixed.hxx>
38 #include <vcl/edit.hxx>
39 #include <vcl/dialog.hxx>
40 #include <vcl/svapp.hxx>
41 #include "runtime.hxx"
43 #include "rtlproto.hxx"
45 class SvRTLInputBox
: public ModalDialog
50 FixedText aPromptText
;
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
* );
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
);
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
) ));
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 )
125 String
aText_( rPrompt
);
126 aText_
.ConvertLineEnd( LINEEND_CR
);
127 aPromptText
.SetPosPixel( LogicToPixel(Point(5,5)));
128 aPromptText
.SetText( aText_
);
129 Size
aSize( rDlgSize
);
131 aSize
.Height() -= 50;
132 aPromptText
.SetSizePixel( LogicToPixel(aSize
));
136 IMPL_LINK_INLINE_START( SvRTLInputBox
, OkHdl
, Button
*, pButton
)
140 aText
= aEdit
.GetText();
144 IMPL_LINK_INLINE_END( SvRTLInputBox
, OkHdl
, Button
*, pButton
)
146 IMPL_LINK_INLINE_START( SvRTLInputBox
, CancelHdl
, Button
*, pButton
)
154 IMPL_LINK_INLINE_END( SvRTLInputBox
, CancelHdl
, Button
*, pButton
)
157 // *********************************************************************
158 // *********************************************************************
159 // *********************************************************************
161 // Syntax: String InputBox( Prompt, [Title], [Default] [, nXpos, nYpos ] )
168 ULONG nArgCount
= rPar
.Count();
170 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
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();
183 if ( nArgCount
!= 6 )
185 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
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
);
194 rPar
.Get(0)->PutString( pDlg
->GetText() );