Bump version to 6.4.7.2.M8
[LibreOffice.git] / basic / source / runtime / inputbox.cxx
blob24a71850607b621158fae17d76ab810a9b4462ec
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 <basic/sberrors.hxx>
21 #include <tools/lineend.hxx>
22 #include <vcl/svapp.hxx>
23 #include <vcl/weld.hxx>
24 #include <vcl/window.hxx>
25 #include <rtlproto.hxx>
26 #include <memory>
28 class SvRTLInputBox : public weld::GenericDialogController
30 std::unique_ptr<weld::Entry> m_xEdit;
31 std::unique_ptr<weld::Button> m_xOk;
32 std::unique_ptr<weld::Button> m_xCancel;
33 std::unique_ptr<weld::Label> m_xPromptText;
34 OUString m_aText;
36 void PositionDialog( long nXTwips, long nYTwips );
37 void InitButtons();
38 void SetPrompt(const OUString& rPrompt);
39 DECL_LINK( OkHdl, weld::Button&, void );
40 DECL_LINK( CancelHdl, weld::Button&, void );
42 public:
43 SvRTLInputBox(weld::Window* pParent, const OUString& rPrompt, const OUString& rTitle,
44 const OUString& rDefault, long nXTwips, long nYTwips );
45 OUString const & GetText() const { return m_aText; }
48 SvRTLInputBox::SvRTLInputBox(weld::Window* pParent, const OUString& rPrompt,
49 const OUString& rTitle, const OUString& rDefault,
50 long nXTwips, long nYTwips)
51 : GenericDialogController(pParent, "svt/ui/inputbox.ui", "InputBox")
52 , m_xEdit(m_xBuilder->weld_entry("entry"))
53 , m_xOk(m_xBuilder->weld_button("ok"))
54 , m_xCancel(m_xBuilder->weld_button("cancel"))
55 , m_xPromptText(m_xBuilder->weld_label("prompt"))
57 PositionDialog( nXTwips, nYTwips );
58 InitButtons();
59 SetPrompt(rPrompt);
60 m_xDialog->set_title(rTitle);
61 m_xEdit->set_text(rDefault);
62 m_xEdit->select_region(0, -1);
65 void SvRTLInputBox::InitButtons()
67 m_xOk->connect_clicked(LINK(this,SvRTLInputBox, OkHdl));
68 m_xCancel->connect_clicked(LINK(this,SvRTLInputBox,CancelHdl));
71 void SvRTLInputBox::PositionDialog(long nXTwips, long nYTwips)
73 if( nXTwips != -1 && nYTwips != -1 )
75 Point aDlgPosApp( nXTwips, nYTwips );
76 OutputDevice* pDefaultDevice = Application::GetDefaultDevice();
77 pDefaultDevice->Push(PushFlags::MAPMODE);
78 pDefaultDevice->SetMapMode(MapMode( MapUnit::MapAppFont));
79 aDlgPosApp = pDefaultDevice->LogicToPixel(aDlgPosApp, MapMode(MapUnit::MapTwip));
80 pDefaultDevice->Pop();
81 m_xDialog->window_move(aDlgPosApp.X(), aDlgPosApp.Y());
85 void SvRTLInputBox::SetPrompt(const OUString& rPrompt)
87 if (rPrompt.isEmpty())
88 return;
89 OUString aText_(convertLineEnd(rPrompt, LINEEND_CR));
90 m_xPromptText->set_label( aText_ );
93 IMPL_LINK_NOARG( SvRTLInputBox, OkHdl, weld::Button&, void )
95 m_aText = m_xEdit->get_text();
96 m_xDialog->response(RET_OK);
99 IMPL_LINK_NOARG( SvRTLInputBox, CancelHdl, weld::Button&, void )
101 m_aText.clear();
102 m_xDialog->response(RET_CANCEL);
105 // Syntax: String InputBox( Prompt, [Title], [Default] [, nXpos, nYpos ] )
107 void SbRtl_InputBox(StarBASIC *, SbxArray & rPar, bool)
109 sal_uInt32 nArgCount = rPar.Count();
110 if ( nArgCount < 2 )
111 StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
112 else
114 OUString aTitle;
115 OUString aDefault;
116 sal_Int32 nX = -1, nY = -1; // center
117 const OUString& rPrompt = rPar.Get(1)->GetOUString();
118 if ( nArgCount > 2 && !rPar.Get(2)->IsErr() )
119 aTitle = rPar.Get(2)->GetOUString();
120 if ( nArgCount > 3 && !rPar.Get(3)->IsErr() )
121 aDefault = rPar.Get(3)->GetOUString();
122 if ( nArgCount > 4 )
124 if ( nArgCount != 6 )
126 StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
127 return;
129 nX = rPar.Get(4)->GetLong();
130 nY = rPar.Get(5)->GetLong();
132 vcl::Window* pParent = Application::GetDefDialogParent();
133 SvRTLInputBox aDlg(pParent ? pParent->GetFrameWeld() : nullptr,rPrompt,aTitle,aDefault,nX,nY);
134 aDlg.run();
135 rPar.Get(0)->PutString(aDlg.GetText());
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */