DialogWindow with Progressbar issue in my class


#1

HI,

The Below class is for DialogWindow with Progressbar .

1). Progressbar is not getting closed automatically when the Thread stops.
2). I want to disable the Close box or When I click the close it should not exit from the window.(I wrote the closeButtonPressed() but not executing this definition)

Please help to solve above issues.

//class member function calls
objMyDlg.startThread();
objMyDlg.showModalDialog("",m_ptrPrgBar,NULL,Colours::white,false);
//

class MyDialog: public DialogWindow,public Thread
{
public:
	String strDlgName;
 	double dval ;
	ProgressBar* m_ptrPrgBar ;
	MyDialog(String strDlgName):DialogWindow(strDlgName,Colours::white,false),Thread("Test")
	{
		 dval = -1.0;
		 m_ptrPrgBar = new  ProgressBar(dval); 
		 m_ptrPrgBar->setSize(300,30);
	}
	void run()
	{
 	    while (! threadShouldExit())
            {
		Thread::sleep(5000);
		signalThreadShouldExit();
		//findParentComponentOfClass ((DialogWindow*) 0)->exitModalState(10); 
		m_ptrPrgBar->exitModalState(20);
		break;
            }
	}
void closeButtonPressed(){               // wrote this for handling close from DocumentWindow-DialogWindow
		return;//do nothing
	}
~MyDialog(){
		delete m_ptrPrgBar;
	}
};

#2

Please use the bbcode ‘code’ tag to make your listings readable!

And why are you calling exitModalState on your progress bar? Presumably that’s not the modal component.


#3

I am new to JUCE so I do’t know what I am supposed to call exit from dialog window.
So I tried the exitModalState on both DialogWindow and/or progressbar for exiting from the dialogwindow.
It did not exit.


#4

Well, there’s no point calling exitModalState on anything that isn’t modal. Somewhere you must be calling runModalLoop on a component, so that’s the component that you need to tell to stop being modal!

But exitModalState won’t make the component magically disappear, it just stops it being modal. You probably also want to delete the dialog box or make it invisible.


#5

Thanks for the explanation .
Yes. I want to delete the Dialog Box.what do I need to do?


#6

After doing some analysis I got the solution. just need to replace the above run with below code

void run()
{
	while (! threadShouldExit())
        {
			const MessageManagerLock mml (Thread::getCurrentThread());
			m_ptrPrgBar->getParentComponent()->getTopLevelComponent()->setEnabled(false);
                         Thread::Sleep(5000);  // for testing 
			if (! mml.lockWasGained())  // if something is trying to kill this job, the lock
				return;  
			signalThreadShouldExit();
			if(m_ptrPrgBar->getParentComponent() != NULL)
					m_ptrPrgBar->getParentComponent()->exitModalState(10);
       }
}