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