What's the best way to talk to the DocumentWindow that's holding a MainContentComponent from within the main content?
I have a document window object "mainWindow" with a content component that has 3 child components in it. I'm trying to figure out the best way to convert the 3 child components into separate windows (they're subclassing DocumentWindow) and resize/rename the mainWindow. I'm using a MenuBar to hold the commands, as done in the JuceDemo. The MenuBar is inside the content component. When I select the command to switch to separate windows, I need to rename the mainWindow's title as well as resize the window.
right now I'm doing something like this, but I get errors when I exit the app:
class MainWindow: public DocumentWindow { public: MainWindow(String name) : DocumentWindow (name, Colours::lightgrey, DocumentWindow::allButtons) { centreWithSize( getWidth(), getHeight() ); setUsingNativeTitleBar (true); mcc = new MainContentComponent( this ); mcc->setVisible(true); setVisible(true); } void closeButtonPressed() override { JUCEApplication::getInstance()->systemRequestedQuit(); } private: MainContentComponent* mcc; };
class MainContentComponent : public Component, private MenuBarModel, private MenuBarModel::Listener { public: MainContentComponent( DocumentWindow* dw ) { mainWindow = dw; addAndMakeVisible( menuBar = new MenuBarComponent( this ) ); menuBar->setBounds( 0, 0, getWidth(), 20 ); } ~MainContentComponent() { mainWindow = 0; } StringArray getMenuBarNames() { const char* const names[] = { "Options", nullptr }; return StringArray( names ); } PopupMenu getMenuForIndex (int topLevelMenuIndex, const String &menuName) { PopupMenu menu; if( topLevelMenuIndex == 0 ) { //Options PopupMenu subMenu; subMenu.addItem(1, "Use Single Window", true, singleViewMode ); subMenu.addItem(2, "Use Separate Windows", true, !singleViewMode ); menu.addSubMenu("View", subMenu ); } return menu; } void menuItemSelected (int menuItemID, int topLevelMenuIndex) { if( menuItemID == 1 ) { //use Single Window mainWindow->setSize(1310, 654); //can't resize in single view mode mainWindow->setResizable(false, false); singleViewMode = true; } else if( menuItemID == 2 ) { mainWindow->setResizable(true, true); mainWindow->setResizeLimits(300, 300, Desktop::getInstance().getDisplays().getMainDisplay().userArea.getWidth(), Desktop::getInstance().getDisplays().getMainDisplay().userArea.getHeight() ); mainWindow->setSize( 300, 300 ); singleViewMode = false; } menuItemsChanged(); //update tick marks } private: DocumentWindow* mainWindow; ScopedPointer<MenuBarComponent> menuBar; bool singleViewMode = true; }; //end