LCOV - code coverage report
Current view: top level - basic/source/runtime - inputbox.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 84 1.2 %
Date: 2014-11-03 Functions: 2 15 13.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      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>
      30             : 
      31           0 : class SvRTLInputBox : public ModalDialog
      32             : {
      33             :     Edit aEdit;
      34             :     OKButton aOk;
      35             :     CancelButton aCancel;
      36             :     FixedText aPromptText;
      37             :     OUString aText;
      38             : 
      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 * );
      45             : 
      46             : public:
      47             :     SvRTLInputBox( vcl::Window* pParent, const OUString& rPrompt, const OUString& rTitle,
      48             :         const OUString& rDefault, long nXTwips = -1, long nYTwips = -1 );
      49           0 :     OUString GetText() const SAL_OVERRIDE { return aText; }
      50             : };
      51             : 
      52           0 : SvRTLInputBox::SvRTLInputBox( vcl::Window* pParent, const OUString& rPrompt,
      53             :         const OUString& rTitle, const OUString& rDefault,
      54             :         long nXTwips, long nYTwips ) :
      55             :     ModalDialog( pParent,WB_3DLOOK | WB_MOVEABLE | WB_CLOSEABLE ),
      56             :     aEdit( this,  WB_LEFT | WB_BORDER ),
      57           0 :     aOk( this ), aCancel( this ), aPromptText( this, WB_WORDBREAK )
      58             : {
      59           0 :     SetMapMode( MapMode( MAP_APPFONT ) );
      60           0 :     Size aDlgSizeApp( 280, 80 );
      61           0 :     PositionDialog( nXTwips, nYTwips, aDlgSizeApp );
      62           0 :     InitButtons( aDlgSizeApp );
      63           0 :     PositionEdit( aDlgSizeApp );
      64           0 :     PositionPrompt( rPrompt, aDlgSizeApp );
      65           0 :     aOk.Show();
      66           0 :     aCancel.Show();
      67           0 :     aEdit.Show();
      68           0 :     aPromptText.Show();
      69           0 :     SetText( rTitle );
      70           0 :     vcl::Font aFont( GetFont());
      71           0 :     Color aColor( GetBackground().GetColor() );
      72           0 :     aFont.SetFillColor( aColor );
      73           0 :     aEdit.SetFont( aFont );
      74           0 :     aEdit.SetText( rDefault );
      75           0 :     aEdit.SetSelection( Selection( SELECTION_MIN, SELECTION_MAX ) );
      76           0 : }
      77             : 
      78           0 : void SvRTLInputBox::InitButtons( const Size& rDlgSize )
      79             : {
      80           0 :     aOk.SetSizePixel( LogicToPixel( Size( 45, 15) ));
      81           0 :     aCancel.SetSizePixel( LogicToPixel( Size( 45, 15) ));
      82           0 :     Point aPos( rDlgSize.Width()-45-10, 5 );
      83           0 :     aOk.SetPosPixel( LogicToPixel( Point(aPos) ));
      84           0 :     aPos.Y() += 16;
      85           0 :     aCancel.SetPosPixel( LogicToPixel( Point(aPos) ));
      86           0 :     aOk.SetClickHdl(LINK(this,SvRTLInputBox, OkHdl));
      87           0 :     aCancel.SetClickHdl(LINK(this,SvRTLInputBox,CancelHdl));
      88           0 : }
      89             : 
      90           0 : void SvRTLInputBox::PositionDialog(long nXTwips, long nYTwips, const Size& rDlgSize)
      91             : {
      92           0 :     SetSizePixel( LogicToPixel(rDlgSize) );
      93           0 :     if( nXTwips != -1 && nYTwips != -1 )
      94             :     {
      95           0 :         Point aDlgPosApp( nXTwips, nYTwips );
      96           0 :         SetPosPixel( LogicToPixel( aDlgPosApp, MAP_TWIP ) );
      97             :     }
      98           0 : }
      99             : 
     100           0 : void SvRTLInputBox::PositionEdit( const Size& rDlgSize )
     101             : {
     102           0 :     aEdit.SetPosPixel( LogicToPixel( Point( 5,rDlgSize.Height()-35)));
     103           0 :     aEdit.SetSizePixel( LogicToPixel( Size(rDlgSize.Width()-15,12)));
     104           0 : }
     105             : 
     106             : 
     107           0 : void SvRTLInputBox::PositionPrompt(const OUString& rPrompt,const Size& rDlgSize)
     108             : {
     109           0 :     if ( rPrompt.isEmpty() )
     110           0 :         return;
     111           0 :     OUString aText_(convertLineEnd(rPrompt, LINEEND_CR));
     112           0 :     aPromptText.SetPosPixel( LogicToPixel(Point(5,5)));
     113           0 :     aPromptText.SetText( aText_ );
     114           0 :     Size aSize( rDlgSize );
     115           0 :     aSize.Width() -= 70;
     116           0 :     aSize.Height() -= 50;
     117           0 :     aPromptText.SetSizePixel( LogicToPixel(aSize));
     118             : }
     119             : 
     120             : 
     121           0 : IMPL_LINK_INLINE_START( SvRTLInputBox, OkHdl, Button *, pButton )
     122             : {
     123             :     (void)pButton;
     124             : 
     125           0 :     aText = aEdit.GetText();
     126           0 :     EndDialog( 1 );
     127           0 :     return 0;
     128             : }
     129           0 : IMPL_LINK_INLINE_END( SvRTLInputBox, OkHdl, Button *, pButton )
     130             : 
     131           0 : IMPL_LINK_INLINE_START( SvRTLInputBox, CancelHdl, Button *, pButton )
     132             : {
     133             :     (void)pButton;
     134             : 
     135           0 :     aText="";
     136           0 :     EndDialog( 0 );
     137           0 :     return 0;
     138             : }
     139           0 : IMPL_LINK_INLINE_END( SvRTLInputBox, CancelHdl, Button *, pButton )
     140             : 
     141             : 
     142             : // *********************************************************************
     143             : // *********************************************************************
     144             : 
     145             : // Syntax: String InputBox( Prompt, [Title], [Default] [, nXpos, nYpos ] )
     146             : 
     147           0 : RTLFUNC(InputBox)
     148             : {
     149             :     (void)pBasic;
     150             :     (void)bWrite;
     151             : 
     152           0 :     sal_uInt32 nArgCount = rPar.Count();
     153           0 :     if ( nArgCount < 2 )
     154           0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
     155             :     else
     156             :     {
     157           0 :         OUString aTitle;
     158           0 :         OUString aDefault;
     159           0 :         sal_Int32 nX = -1, nY = -1;  // center
     160           0 :         const OUString& rPrompt = rPar.Get(1)->GetOUString();
     161           0 :         if ( nArgCount > 2 && !rPar.Get(2)->IsErr() )
     162           0 :             aTitle = rPar.Get(2)->GetOUString();
     163           0 :         if ( nArgCount > 3 && !rPar.Get(3)->IsErr() )
     164           0 :             aDefault = rPar.Get(3)->GetOUString();
     165           0 :         if ( nArgCount > 4 )
     166             :         {
     167           0 :             if ( nArgCount != 6 )
     168             :             {
     169           0 :                 StarBASIC::Error( SbERR_BAD_ARGUMENT );
     170           0 :                 return;
     171             :             }
     172           0 :             nX = rPar.Get(4)->GetLong();
     173           0 :             nY = rPar.Get(5)->GetLong();
     174             :         }
     175             :         boost::scoped_ptr<SvRTLInputBox> pDlg(new SvRTLInputBox(Application::GetDefDialogParent(),
     176           0 :                     rPrompt,aTitle,aDefault,nX,nY));
     177           0 :         pDlg->Execute();
     178           0 :         rPar.Get(0)->PutString( pDlg->GetText() );
     179             :     }
     180        1203 : }
     181             : 
     182             : 
     183             : 
     184             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10