xref: /AOO41X/main/padmin/source/progress.cxx (revision 466d5a0b1cd4680d6b00897b7eaafb6844398eb8)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include <ctype.h>
25 #include <stdio.h>
26 #include <tools/string.hxx>
27 #include <tools/stream.hxx>
28 #include <tools/list.hxx>
29 #include <vcl/msgbox.hxx>
30 #include <vcl/svapp.hxx>
31 #include <progress.hxx>
32 #include <helper.hxx>
33 #ifndef _PAD_PADIALOG_HRC_
34 #include <padialog.hrc>
35 #endif
36 
37 using namespace padmin;
38 
ProgressDialog(Window * pParent,sal_Bool bCancelable,int nMin,int nMax)39 ProgressDialog::ProgressDialog( Window* pParent,
40                                 sal_Bool bCancelable,
41                                 int nMin, int nMax ) :
42         ModelessDialog( pParent, PaResId( RID_PROGRESS_DLG ) ),
43         maOperation( this, PaResId( RID_PROGRESS_OPERATION_TXT ) ),
44         maFilename( this, PaResId( RID_PROGRESS_FILENAME_TXT ) ),
45         maProgressTxt( this, PaResId( RID_PROGRESS_PROGRESS_TXT ) ),
46         maCancelButton( this, PaResId( RID_PROGRESS_BTN_CANCEL ) ),
47         maProgressBar( this, PaResId( RID_PROGRESS_STATUSBAR ) ),
48         mnMax( nMax ),
49         mnMin( nMin ),
50         mbCanceled( sal_False )
51 {
52     maFilename.SetStyle( maFilename.GetStyle() | WB_PATHELLIPSIS );
53     if( ! bCancelable )
54     {
55         Point aPos = maProgressBar.GetPosPixel();
56         Size aSize = maProgressBar.GetSizePixel();
57         Size aMySize = GetOutputSizePixel();
58         aMySize.Height() = aPos.Y() + aSize.Height() + 5;
59         SetOutputSizePixel( aMySize );
60     }
61     else
62         maCancelButton.SetClickHdl( LINK( this, ProgressDialog, ClickBtnHdl ) );
63     FreeResource();
64 }
65 
~ProgressDialog()66 ProgressDialog::~ProgressDialog()
67 {
68 }
69 
startOperation(const String & rOperation)70 void ProgressDialog::startOperation( const String& rOperation )
71 {
72     maOperation.SetText( rOperation );
73     maProgressBar.SetValue( 0 );
74     mbCanceled = sal_False;
75     if( ! IsVisible() )
76         Show( sal_True );
77 }
78 
setValue(int nValue)79 void ProgressDialog::setValue( int nValue )
80 {
81     maProgressBar.SetValue( nValue * 100 / ( mnMax - mnMin ) );
82     Application::Reschedule();
83 }
84 
setFilename(const String & rFilename)85 void ProgressDialog::setFilename( const String& rFilename )
86 {
87     maFilename.SetText( rFilename );
88     maFilename.Update();
89     Flush();
90 }
91 
IMPL_LINK(ProgressDialog,ClickBtnHdl,Button *,pButton)92 IMPL_LINK( ProgressDialog, ClickBtnHdl, Button*, pButton )
93 {
94     if( pButton == &maCancelButton )
95     {
96         mbCanceled = sal_True;
97     }
98     return 0;
99 }
100