LCOV - code coverage report
Current view: top level - basic/source/runtime - inputbox.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 85 0.0 %
Date: 2012-08-25 Functions: 0 13 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 212 0.0 %

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

Generated by: LCOV version 1.10