1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <vcl/button.hxx>
22 #include <vcl/fixed.hxx>
23 #include <vcl/edit.hxx>
24 #include <vcl/dialog.hxx>
25 #include <vcl/svapp.hxx>
26 #include "runtime.hxx"
28 #include "rtlproto.hxx"
30 class SvRTLInputBox
: public ModalDialog
35 FixedText aPromptText
;
38 void PositionDialog( long nXTwips
, long nYTwips
, const Size
& rDlgSize
);
39 void InitButtons( const Size
& rDlgSize
);
40 void PositionEdit( const Size
& rDlgSize
);
41 void PositionPrompt( const String
& rPrompt
, const Size
& rDlgSize
);
42 DECL_LINK( OkHdl
, Button
* );
43 DECL_LINK( CancelHdl
, Button
* );
46 SvRTLInputBox( Window
* pParent
, const String
& rPrompt
, const String
& rTitle
,
47 const String
& rDefault
, long nXTwips
= -1, long nYTwips
= -1 );
48 OUString
GetText() const { return aText
; }
51 SvRTLInputBox::SvRTLInputBox( Window
* pParent
, const String
& rPrompt
,
52 const String
& rTitle
, const String
& rDefault
,
53 long nXTwips
, long nYTwips
) :
54 ModalDialog( pParent
,WB_3DLOOK
| WB_MOVEABLE
| WB_CLOSEABLE
),
55 aEdit( this, WB_LEFT
| WB_BORDER
),
56 aOk( this ), aCancel( this ), aPromptText( this, WB_WORDBREAK
)
58 SetMapMode( MapMode( MAP_APPFONT
) );
59 Size
aDlgSizeApp( 280, 80 );
60 PositionDialog( nXTwips
, nYTwips
, aDlgSizeApp
);
61 InitButtons( aDlgSizeApp
);
62 PositionEdit( aDlgSizeApp
);
63 PositionPrompt( rPrompt
, aDlgSizeApp
);
68 SetText( OUString(rTitle
) );
69 Font
aFont( GetFont());
70 Color
aColor( GetBackground().GetColor() );
71 aFont
.SetFillColor( aColor
);
72 aEdit
.SetFont( aFont
);
73 aEdit
.SetText( OUString(rDefault
) );
74 aEdit
.SetSelection( Selection( SELECTION_MIN
, SELECTION_MAX
) );
77 void SvRTLInputBox::InitButtons( const Size
& rDlgSize
)
79 aOk
.SetSizePixel( LogicToPixel( Size( 45, 15) ));
80 aCancel
.SetSizePixel( LogicToPixel( Size( 45, 15) ));
81 Point
aPos( rDlgSize
.Width()-45-10, 5 );
82 aOk
.SetPosPixel( LogicToPixel( Point(aPos
) ));
84 aCancel
.SetPosPixel( LogicToPixel( Point(aPos
) ));
85 aOk
.SetClickHdl(LINK(this,SvRTLInputBox
, OkHdl
));
86 aCancel
.SetClickHdl(LINK(this,SvRTLInputBox
,CancelHdl
));
89 void SvRTLInputBox::PositionDialog(long nXTwips
, long nYTwips
, const Size
& rDlgSize
)
91 SetSizePixel( LogicToPixel(rDlgSize
) );
92 if( nXTwips
!= -1 && nYTwips
!= -1 )
94 Point
aDlgPosApp( nXTwips
, nYTwips
);
95 SetPosPixel( LogicToPixel( aDlgPosApp
, MAP_TWIP
) );
99 void SvRTLInputBox::PositionEdit( const Size
& rDlgSize
)
101 aEdit
.SetPosPixel( LogicToPixel( Point( 5,rDlgSize
.Height()-35)));
102 aEdit
.SetSizePixel( LogicToPixel( Size(rDlgSize
.Width()-15,12)));
106 void SvRTLInputBox::PositionPrompt(const String
& rPrompt
,const Size
& rDlgSize
)
108 if ( rPrompt
.Len() == 0 )
110 String
aText_(convertLineEnd(rPrompt
, LINEEND_CR
));
111 aPromptText
.SetPosPixel( LogicToPixel(Point(5,5)));
112 aPromptText
.SetText( OUString(aText_
) );
113 Size
aSize( rDlgSize
);
115 aSize
.Height() -= 50;
116 aPromptText
.SetSizePixel( LogicToPixel(aSize
));
120 IMPL_LINK_INLINE_START( SvRTLInputBox
, OkHdl
, Button
*, pButton
)
124 aText
= aEdit
.GetText();
128 IMPL_LINK_INLINE_END( SvRTLInputBox
, OkHdl
, Button
*, pButton
)
130 IMPL_LINK_INLINE_START( SvRTLInputBox
, CancelHdl
, Button
*, pButton
)
138 IMPL_LINK_INLINE_END( SvRTLInputBox
, CancelHdl
, Button
*, pButton
)
141 // *********************************************************************
142 // *********************************************************************
144 // Syntax: String InputBox( Prompt, [Title], [Default] [, nXpos, nYpos ] )
151 sal_uIntPtr nArgCount
= rPar
.Count();
153 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
158 sal_Int32 nX
= -1, nY
= -1; // center
159 const String
& rPrompt
= rPar
.Get(1)->GetOUString();
160 if ( nArgCount
> 2 && !rPar
.Get(2)->IsErr() )
161 aTitle
= rPar
.Get(2)->GetOUString();
162 if ( nArgCount
> 3 && !rPar
.Get(3)->IsErr() )
163 aDefault
= rPar
.Get(3)->GetOUString();
166 if ( nArgCount
!= 6 )
168 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
171 nX
= rPar
.Get(4)->GetLong();
172 nY
= rPar
.Get(5)->GetLong();
174 SvRTLInputBox
*pDlg
=new SvRTLInputBox(GetpApp()->GetDefDialogParent(),
175 rPrompt
,aTitle
,aDefault
,nX
,nY
);
177 rPar
.Get(0)->PutString( pDlg
->GetText() );
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */