xref: /aoo41x/main/padmin/source/progress.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include <ctype.h>
29 #include <stdio.h>
30 #include <tools/string.hxx>
31 #include <tools/stream.hxx>
32 #include <tools/list.hxx>
33 #include <vcl/msgbox.hxx>
34 #include <vcl/svapp.hxx>
35 #include <progress.hxx>
36 #include <helper.hxx>
37 #ifndef _PAD_PADIALOG_HRC_
38 #include <padialog.hrc>
39 #endif
40 
41 using namespace padmin;
42 
43 ProgressDialog::ProgressDialog( Window* pParent,
44 								sal_Bool bCancelable,
45 								int nMin, int nMax ) :
46 		ModelessDialog( pParent, PaResId( RID_PROGRESS_DLG ) ),
47 		maOperation( this, PaResId( RID_PROGRESS_OPERATION_TXT ) ),
48 		maFilename( this, PaResId( RID_PROGRESS_FILENAME_TXT ) ),
49 		maProgressTxt( this, PaResId( RID_PROGRESS_PROGRESS_TXT ) ),
50 		maCancelButton( this, PaResId( RID_PROGRESS_BTN_CANCEL ) ),
51 		maProgressBar( this, PaResId( RID_PROGRESS_STATUSBAR ) ),
52 		mnMax( nMax ),
53 		mnMin( nMin ),
54 		mbCanceled( sal_False )
55 {
56     maFilename.SetStyle( maFilename.GetStyle() | WB_PATHELLIPSIS );
57 	if( ! bCancelable )
58 	{
59 		Point aPos = maProgressBar.GetPosPixel();
60 		Size aSize = maProgressBar.GetSizePixel();
61 		Size aMySize = GetOutputSizePixel();
62 		aMySize.Height() = aPos.Y() + aSize.Height() + 5;
63 		SetOutputSizePixel( aMySize );
64 	}
65 	else
66 		maCancelButton.SetClickHdl( LINK( this, ProgressDialog, ClickBtnHdl ) );
67 	FreeResource();
68 }
69 
70 ProgressDialog::~ProgressDialog()
71 {
72 }
73 
74 void ProgressDialog::startOperation( const String& rOperation )
75 {
76 	maOperation.SetText( rOperation );
77 	maProgressBar.SetValue( 0 );
78 	mbCanceled = sal_False;
79 	if( ! IsVisible() )
80 		Show( sal_True );
81 }
82 
83 void ProgressDialog::setValue( int nValue )
84 {
85 	maProgressBar.SetValue( nValue * 100 / ( mnMax - mnMin ) );
86 	Application::Reschedule();
87 }
88 
89 void ProgressDialog::setFilename( const String& rFilename )
90 {
91 	maFilename.SetText( rFilename );
92 	maFilename.Update();
93 	Flush();
94 }
95 
96 IMPL_LINK( ProgressDialog, ClickBtnHdl, Button*, pButton )
97 {
98 	if( pButton == &maCancelButton )
99 	{
100 		mbCanceled = sal_True;
101 	}
102 	return 0;
103 }
104