DialogWindow and ContentOwned

Hi there,

 

Can anyone help me giving me one example on how to use dialog windows and to put inside the dialog windows one component.

And when the component is closed (press a button on the component to close it) the window is closed.

What i've made so far is this:

String m; m << "";
DialogWindow::LaunchOptions options;
Label* label = new Label();
label->setText(m, dontSendNotification);
label->setColour(Label::textColourId, Colours::darkgrey);
options.content.setOwned(label);
Rectangle<int> area(0, 0, 378, 407);
options.content->setSize(area.getWidth(), area.getHeight());
options.dialogTitle = "Login Window";
options.dialogBackgroundColour = Colours::darkgrey;
options.componentToCentreAround;
options.escapeKeyTriggersCloseButton = true;
options.useNativeTitleBar = false;
options.resizable = false;

DialogWindow* dw = options.launchAsync();
dw->setContentOwned(showLoginPage(), false);
dw->setTitleBarHeight(0);
dw->setVisible(true);
dw->centreWithSize(378, 407);

But the result is that when i press the close button on the component called showLoginPage().

I've got this code from the demo of Juce, but of course it's not the correct way to do it.

Paulo

 

Hi again,

unfortunally no one give a suggestion, i've found out the way to close it.

On the component, i added this associated with the close button:

Component::getParentComponent()->exitModalState(0);

But if anyone as a better way to do it, tell ...

Paulo

The code you've copied from WindowsDemo.cpp of the JUCE demo adds a Label (a Component) to the DialogWindow:

DialogWindow::LaunchOptions options;
Label* label = new Label();
label->setText (m, dontSendNotification);
label->setColour (Label::textColourId, Colours::whitesmoke);
options.content.setOwned (label);

Instead of Label, you could add your own component.

Also, from the documentation for launchAsync(), "When the dialog's close button is clicked, it'll automatically terminate its modal state..." So you shouldn't need to do this yourself. I'm guessing if you do it the way it's done in WindowsDemo.cpp, you won't need your hack.

Hi,

On the DialogWindow that I've created, i have a button that when pressed should close my dialogWindow and open a newComponent.

I have a call to my MainWindow:

FrontPageComponent* frontPage = NULL;

if (buttonThatWasClicked == btnExit)
{
//Close Dialog Window
Component::getParentComponent()->exitModalState(0);
} else if (buttonThatWasClicked == btnOk)
{
//Show First Component 
frontPage->showComponentOne();
}

in my FrontPageComponent I have this function showComponentOne():

void FrontPageComponent::showComponentOne()
{
Component::getCurrentlyModalComponent()->exitModalState(0);
addAndMakeVisible(showFirstComponent());
if (showFirstComponent() != nullptr)
{
showFirstComponent()->setBounds(0,0,1024,768);
}
}

What is happening is when i press the button on the DialogWindow that calls the showComponentOne and nothing happens, DialogWindow is closed but my component is not shown.

What am I doing wrong ?

How can I position this component to be on my DocumentWindow.

I can use a button on my FrontPageComponent that opens the new component called FirstComponent without any problem the same way:

addAndMakeVisible(showFirstComponent());
if (showFirstComponent() != nullptr)
{
showFirstComponent()->setBounds(0,0,1024,768);
}

But opening a DialogWindow and from the DialogWindow calling this, cannot !

Paulo

You’re way over thinking this… Simply create a new class based on Component, in the main class display the the opaque new class on top of the original class as a child and make it the same size as the parent. It will completely cover the parent and when you close it the parent will be visible.

Rail

Hi Rail,

the situation is not related with me hidding the main component, but what I want is that from the DialogWindow to be able to close it and show a diferent Component, not the main.

 

So when the first component closes have the parent create and display the next component class object… The parent is always there and runs the show… The parent doesn’t need to be your main window… It can be a controller class which handles what components you display

Rail

On my MainWindow i have this function:

void MainWindow::showComponentOne()
{
Component::getCurrentlyModalComponent()->exitModalState(0);
firstComponent = new FirstComponent();
getContentComponent()->addChildComponent(firstComponent, -1);
}

that is called from my DialogWindow.

Main purpose is to close the DialogWindow and show a new Component.

But, it gives me this error:

"Unhandled exception at 0x00CCCFBF in JuceDemoTest.exe: 0xC0000005: Access violation reading location 0x00000120."

And takes me to this function:

ScopedPointer& operator= (ObjectType* const newObjectToTakePossessionOf)
{
if (object != newObjectToTakePossessionOf)
{

What is wrong ?

Paulo

You’re trying to access an object which doesn’t exist… If you look at the this value in the debugger it’ll be NULL

Rail