Accessing/controlling components from the menu


#1

This is more of an OOP misunderstanding on my part, because I can’t figure out how to reference components like WidgetsDemo.cpp from the JUCE Demo menubar.

If I were to add a new item to the menu that adds a new tab to specifically alter the widgets demo portion of the JUCE demo by calling tabs->addtab() . How would I do it from the ContentComp class?

I’ve tried to make MainComponent available directly in the ContentComp class but I keep getting type errors. I’ve also tried to make the TabbedComponent portion public in my MainComponent, but that didn’t help.

It seems to me that MainDemoWindow.cpp decides which screen is active and loads it by selections made on the menu. The components are called by :

void showDemo (const int demoId)
    {
        if (currentDemo != 0)
            removeChildComponent (currentDemo);

        currentDemo = 0;
        currentDemoId = demoId;

        if (demos[demoId] == 0)
        {
            switch (demoId)
            {
            case 1:
                demos[demoId] = createPathsAndTransformsDemo();
                break;

            case 2:
                demos[demoId] = createFontsAndTextDemo();
                break;

            case 3:
                demos[demoId] = createWidgetsDemo();
                break;

etc...

in the public portion of the ContentComp class…

And I guess the actual definitions of each of the above functions is:

Component* createFontsAndTextDemo();
Component* createPathsAndTransformsDemo();
Component* createWidgetsDemo();
Component* createThreadingDemo();
etc...

In the jucedemo_headers.h

Component* createWidgetsDemo()
{
    return new WidgetsDemo();
}

and at the end of WidgetsDemo.cpp

I’ve tried doing this in ContentComp class in the showInterface function :

[code]
if (amuletToolInterfaces[interfaceId] == 0)
{
switch (interfaceId)
{
case 1:

           amuletToolInterfaces[interfaceId] = createMainDesignInterface();

			break;
        }
    }

    currentInterface = amuletToolInterfaces[interfaceId];
    addAndMakeVisible (currentInterface);  

    currentInterface->tabs->addtab(T("NewTab")); // This line is what I'm trying to do.

    resized();
}[/code]

I’m actually really trying to do this:

void menuItemSelected (MenuBarComponent* menuBar,
                           int menuItemID,
                           int index)
    {
        if (menuItemID == 99)
        {
            JUCEApplication::quit();
        }
        else if (menuItemID == 1)
        {
			currentInterface->tabs->addtab(T("NewTab"));	        
        }

    }

I know this is wrong, but does anyone see what I’m trying to do?

Thanks for dealing with my oop ignorance. :slight_smile:

-Angelo


#2