update credits
[LibreOffice.git] / basic / source / runtime / inputbox.cxx
blobe993bed63cb8a68b7eb9db81e189e702d22e4b62
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <tools/lineend.hxx>
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"
27 #include "stdobj.hxx"
28 #include "rtlproto.hxx"
29 #include <boost/scoped_ptr.hpp>
31 class SvRTLInputBox : public ModalDialog
33 VclPtr<Edit> aEdit;
34 VclPtr<OKButton> aOk;
35 VclPtr<CancelButton> aCancel;
36 VclPtr<FixedText> aPromptText;
37 OUString aText;
39 void PositionDialog( long nXTwips, long nYTwips, const Size& rDlgSize );
40 void InitButtons( const Size& rDlgSize );
41 void PositionEdit( const Size& rDlgSize );
42 void PositionPrompt( const OUString& rPrompt, const Size& rDlgSize );
43 DECL_LINK( OkHdl, Button * );
44 DECL_LINK( CancelHdl, Button * );
46 public:
47 SvRTLInputBox( vcl::Window* pParent, const OUString& rPrompt, const OUString& rTitle,
48 const OUString& rDefault, long nXTwips = -1, long nYTwips = -1 );
49 virtual ~SvRTLInputBox() { disposeOnce(); }
50 virtual void dispose() SAL_OVERRIDE;
51 OUString GetText() const SAL_OVERRIDE { return aText; }
54 SvRTLInputBox::SvRTLInputBox( vcl::Window* pParent, const OUString& rPrompt,
55 const OUString& rTitle, const OUString& rDefault,
56 long nXTwips, long nYTwips ) :
57 ModalDialog( pParent,WB_3DLOOK | WB_MOVEABLE | WB_CLOSEABLE ),
58 aEdit( VclPtr<Edit>::Create(this, WB_LEFT | WB_BORDER) ),
59 aOk( VclPtr<OKButton>::Create(this) ), aCancel( VclPtr<CancelButton>::Create(this) ), aPromptText( VclPtr<FixedText>::Create(this, WB_WORDBREAK) )
61 SetMapMode( MapMode( MAP_APPFONT ) );
62 Size aDlgSizeApp( 280, 80 );
63 PositionDialog( nXTwips, nYTwips, aDlgSizeApp );
64 InitButtons( aDlgSizeApp );
65 PositionEdit( aDlgSizeApp );
66 PositionPrompt( rPrompt, aDlgSizeApp );
67 aOk->Show();
68 aCancel->Show();
69 aEdit->Show();
70 aPromptText->Show();
71 SetText( rTitle );
72 vcl::Font aFont( GetFont());
73 Color aColor( GetBackground().GetColor() );
74 aFont.SetFillColor( aColor );
75 aEdit->SetFont( aFont );
76 aEdit->SetText( rDefault );
77 aEdit->SetSelection( Selection( SELECTION_MIN, SELECTION_MAX ) );
80 void SvRTLInputBox::dispose()
82 aEdit.disposeAndClear();
83 aOk.disposeAndClear();
84 aCancel.disposeAndClear();
85 aPromptText.disposeAndClear();
86 ModalDialog::dispose();
89 void SvRTLInputBox::InitButtons( const Size& rDlgSize )
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));
101 void SvRTLInputBox::PositionDialog(long nXTwips, long nYTwips, const Size& rDlgSize)
103 SetSizePixel( LogicToPixel(rDlgSize) );
104 if( nXTwips != -1 && nYTwips != -1 )
106 Point aDlgPosApp( nXTwips, nYTwips );
107 SetPosPixel( LogicToPixel( aDlgPosApp, MAP_TWIP ) );
111 void SvRTLInputBox::PositionEdit( const Size& rDlgSize )
113 aEdit->SetPosPixel( LogicToPixel( Point( 5,rDlgSize.Height()-35)));
114 aEdit->SetSizePixel( LogicToPixel( Size(rDlgSize.Width()-15,12)));
118 void SvRTLInputBox::PositionPrompt(const OUString& rPrompt,const Size& rDlgSize)
120 if ( rPrompt.isEmpty() )
121 return;
122 OUString aText_(convertLineEnd(rPrompt, LINEEND_CR));
123 aPromptText->SetPosPixel( LogicToPixel(Point(5,5)));
124 aPromptText->SetText( aText_ );
125 Size aSize( rDlgSize );
126 aSize.Width() -= 70;
127 aSize.Height() -= 50;
128 aPromptText->SetSizePixel( LogicToPixel(aSize));
132 IMPL_LINK( SvRTLInputBox, OkHdl, Button *, pButton )
134 (void)pButton;
136 aText = aEdit->GetText();
137 EndDialog( 1 );
138 return 0;
141 IMPL_LINK( SvRTLInputBox, CancelHdl, Button *, pButton )
143 (void)pButton;
145 aText.clear();
146 EndDialog( 0 );
147 return 0;
151 // *********************************************************************
152 // *********************************************************************
154 // Syntax: String InputBox( Prompt, [Title], [Default] [, nXpos, nYpos ] )
156 RTLFUNC(InputBox)
158 (void)pBasic;
159 (void)bWrite;
161 sal_uInt32 nArgCount = rPar.Count();
162 if ( nArgCount < 2 )
163 StarBASIC::Error( SbERR_BAD_ARGUMENT );
164 else
166 OUString aTitle;
167 OUString aDefault;
168 sal_Int32 nX = -1, nY = -1; // center
169 const OUString& rPrompt = rPar.Get(1)->GetOUString();
170 if ( nArgCount > 2 && !rPar.Get(2)->IsErr() )
171 aTitle = rPar.Get(2)->GetOUString();
172 if ( nArgCount > 3 && !rPar.Get(3)->IsErr() )
173 aDefault = rPar.Get(3)->GetOUString();
174 if ( nArgCount > 4 )
176 if ( nArgCount != 6 )
178 StarBASIC::Error( SbERR_BAD_ARGUMENT );
179 return;
181 nX = rPar.Get(4)->GetLong();
182 nY = rPar.Get(5)->GetLong();
184 VclPtrInstance<SvRTLInputBox> pDlg(Application::GetDefDialogParent(),
185 rPrompt,aTitle,aDefault,nX,nY);
186 pDlg->Execute();
187 rPar.Get(0)->PutString( pDlg->GetText() );
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */