1 /*
2  * Copyright (C) 2002 - David W. Durham
3  *
4  * This file is part of ReZound, an audio editing application.
5  *
6  * ReZound is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published
8  * by the Free Software Foundation; either version 2 of the License,
9  * or (at your option) any later version.
10  *
11  * ReZound is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
19  */
20 
21 #include "CProgressDialog.h"
22 
23 //#include "CFOXIcons.h"
24 
25 FXDEFMAP(CProgressDialog) CProgressDialogMap[]=
26 {
27 //	Message_Type			ID					Message_Handler
28 	FXMAPFUNC(SEL_CLOSE,		0,					CProgressDialog::onCloseWindow),
29 	FXMAPFUNC(SEL_COMMAND,		CProgressDialog::ID_CANCEL_BUTTON,	CProgressDialog::onCancelButton),
30 };
31 
32 
FXIMPLEMENT(CProgressDialog,FXDialogBox,CProgressDialogMap,ARRAYNUMBER (CProgressDialogMap))33 FXIMPLEMENT(CProgressDialog,FXDialogBox,CProgressDialogMap,ARRAYNUMBER(CProgressDialogMap))
34 
35 
36 
37 // ----------------------------------------
38 
39 #define ASSURE_WIDTH(parent,width) new FXFrame(parent,FRAME_NONE|LAYOUT_SIDE_BOTTOM | LAYOUT_FIX_WIDTH|LAYOUT_FIX_HEIGHT,0,0,width,1);
40 
41 CProgressDialog::CProgressDialog(FXWindow *owner,const FXString &title,bool showCancelButton) :
42 	FXDialogBox(owner,title,DECOR_TITLE|DECOR_BORDER|DECOR_RESIZE, 0,0,0,0, 0,0,0,0, 0,0),
43 	isCancelled(false),
44 	vContents(new FXVerticalFrame(this,FRAME_RAISED|FRAME_THICK | LAYOUT_FILL_X|LAYOUT_FILL_Y, 0,0,0,0, 6,6,6,6, 0,2)),
45 		hContents(new FXHorizontalFrame(vContents,LAYOUT_FILL_X | FRAME_NONE, 0,0,0,0, 0,0,0,0, 6,0)),
46 			progressBar(new FXProgressBar(hContents,NULL,0,PROGRESSBAR_NORMAL | LAYOUT_FILL_X,0,0,250,20)),
47 			cancelButton(!showCancelButton ? NULL : new FXButton(hContents,_("&Cancel"),/*FOXIcons->RedX1*/NULL,this,ID_CANCEL_BUTTON,LAYOUT_CENTER_Y | FRAME_RAISED|FRAME_THICK | JUSTIFY_NORMAL | ICON_ABOVE_TEXT, 0,0,0,0, 10,10,2,2)),
48 		timeElapsedLabel(new FXLabel(vContents,"Elapsed Time xxx:xx:xx",NULL,LAYOUT_FILL_X|JUSTIFY_RIGHT)),
49 		timeRemainingLabel(new FXLabel(vContents,"Estimated Time Remaining xxx:xx:xx",NULL,LAYOUT_FILL_X|JUSTIFY_RIGHT))
50 {
51 	ASSURE_WIDTH(this,260)
52 	progressBar->setTotal(100);
53 	progressBar->showNumber();
54 }
55 
~CProgressDialog()56 CProgressDialog::~CProgressDialog()
57 {
58 }
59 
onCancelButton(FXObject * sender,FXSelector sel,void * ptr)60 long CProgressDialog::onCancelButton(FXObject *sender,FXSelector sel,void *ptr)
61 {
62 	isCancelled=true;
63 	return 1;
64 }
65 
onCloseWindow(FXObject * sender,FXSelector sel,void * ptr)66 long CProgressDialog::onCloseWindow(FXObject *sender,FXSelector sel,void *ptr)
67 {
68 	// don't close
69 	return 1;
70 }
71 
setProgress(int progress,const string timeElapsed,const string timeRemaining)72 void CProgressDialog::setProgress(int progress,const string timeElapsed,const string timeRemaining)
73 {
74 	progressBar->setProgress(progress);
75 	if(timeElapsed=="")
76 	{
77 		if(timeElapsedLabel->shown())
78 			timeElapsedLabel->hide();
79 	}
80 	else
81 	{
82 		if(!timeElapsedLabel->shown())
83 			timeElapsedLabel->show();
84 		timeElapsedLabel->setText((_("Time Elapsed ")+timeElapsed).c_str());
85 	}
86 
87 	if(timeRemaining=="")
88 	{
89 		if(timeRemainingLabel->shown())
90 			timeRemainingLabel->hide();
91 	}
92 	else
93 	{
94 		if(!timeRemainingLabel->shown())
95 			timeRemainingLabel->show();
96 		timeRemainingLabel->setText((_("Estimated Time Remaining ")+timeRemaining).c_str());
97 	}
98 
99 	if(cancelButton)
100 		getApp()->runModalWhileEvents(cancelButton); // give cancel button an oppertunity to be clicked
101 }
102 
show(FXuint placement)103 void CProgressDialog::show(FXuint placement)
104 {
105 	FXDialogBox::show(placement);
106 	resize(vContents->getDefaultWidth(),vContents->getDefaultHeight());
107 }
108 
hide()109 void CProgressDialog::hide()
110 {
111 	FXDialogBox::hide();
112 }
113 
114