I have tried to make a clean project from beginning so that I can know where I am getting stuck.
[b]/* File : MyApp.cpp */
#include âMainDialog.hâ
class MyApp : public JUCEApplication
{
public:
MyApp(){}
~MyApp(){}
void initialise(const String& commandLine)
{
mMainDialog.centreWithSize(400, 400);
mMainDialog.setVisible(true);
}
void shutdown()
{
//deleteAndZero(mMainDialog);
}
const String getApplicationName()
{
return "JUCE_TUTORIAL_PROJECT_1";
}
const String getApplicationVersion()
{
return "0.0";
}
bool moreThanOneInstanceAllowed()
{
return true;
}
void anotherInstanceStarted( const String& commandLine ) {}
private:
MainDialog mMainDialog;
};
START_JUCE_APPLICATION(MyApp)[/b]
[b]/* File : MainDialog.h */
#pragma once
#ifndef MAINDIALOG_H
#define MAINDIALOG_H
#include âjuce.hâ
#include âTestListBox.hâ
class MainDialog : public DocumentWindow
{
public:
MainDialog();
~MainDialog();
ApplicationCommandManager commandManager;
private:
void closeButtonPressed();
TestListBox mContentComponent;
};
#endif /* End MAINDIALOG_H */[/b]
[b]
/ * File : MainDialog.cpp */
#include âMainDialog.hâ
MainDialog::MainDialog() : DocumentWindow(âJUCE_TUTORIAL_PROJECT_2â, Colours::azure, DocumentWindow::allButtons, true),
mContentComponent()
{
setResizable(true, false);
setTitleBarHeight(20);
setContentComponent(&mContentComponent);
}
MainDialog::~MainDialog()
{
}
void MainDialog::closeButtonPressed()
{
JUCEApplication::getInstance()->systemRequestedQuit();
}[/b]
[b]
/* File : TestListBox.h */
#pragma once
#ifndef TESTLISTBOX_H
#define TESTLISTBOX_H
/* Includes */
#include âjuce.hâ
#include
/* Forward declaration. */
class CustomComponent;
class TestListBox : public juce::Component,
public juce::ListBoxModel,
public juce::ButtonListener
{
public:
TestListBox();
~TestListBox();
private:
virtual void resized();
virtual int getNumRows();
virtual void paintListBoxItem (int rowNumber, Graphics& g, int width, int height, bool rowIsSelected);
virtual void buttonClicked(juce::Button button);
virtual Component refreshComponentForRow (int rowNumber, bool isRowSelected, juce::Component* existingComponentToUpdate);
void AddRow();
void DeleteRow();
void GetAllRowText();
public:
juce::ListBox mListBox;
juce::TextButton mAddRowButton;
juce::TextButton mDeleteRowButton;
juce::TextButton mTestButton;
int mRowCount;
};
#endif /* End TESTLISTBOX_H */ [/b]
[b]
/* File : TestListBox.cpp */
/* Includes */
#include âTestListBox.hâ
TestListBox::TestListBox() : mRowCount(0),
mListBox(âNew words listâ, NULL),
mAddRowButton("+"),
mDeleteRowButton(L"â"), /* em dash (on win os ALT + 0151) */
mTestButton(âTâ)
{
mListBox.setRowHeight(19);
this->addAndMakeVisible(&mListBox);
mListBox.setBounds(10, 10, 372, 300);
mListBox.setOutlineThickness(2);
mListBox.setColour(juce::ListBox::outlineColourId, juce::Colours::lightgrey);
mListBox.setModel(this);
/* mAddRowButton setup & initialization. */
this->addAndMakeVisible(&mAddRowButton);
mAddRowButton.setBounds(20, 340, 18, 18);
mAddRowButton.addListener(this);
mAddRowButton.setConnectedEdges(juce::Button::ConnectedOnLeft | juce::Button::ConnectedOnRight);
/* mDeleteRowButton setup & initialization. */
this->addAndMakeVisible(&mDeleteRowButton);
mDeleteRowButton.setBounds(38, 340, 18, 18);
mDeleteRowButton.addListener(this);
mDeleteRowButton.setConnectedEdges(juce::Button::ConnectedOnLeft | juce::Button::ConnectedOnRight);
/* mTestButton setup & initialization. */
this->addAndMakeVisible(&mTestButton);
mTestButton.setBounds(60, 340, 18, 18);
mTestButton.addListener(this);
mTestButton.setConnectedEdges(juce::Button::ConnectedOnLeft | juce::Button::ConnectedOnRight);
}
TestListBox::~TestListBox()
{
}
void TestListBox::resized()
{
}
int TestListBox::getNumRows()
{
return mRowCount;
}
void TestListBox::paintListBoxItem(int rowNumber, Graphics& g, int width, int height, bool rowIsSelected)
{
}
void TestListBox::buttonClicked(juce::Button *button)
{
if(button == &mAddRowButton)
{
AddRow();
}
else if(button == &mDeleteRowButton)
{
DeleteRow();
}
else if(button == &mTestButton)
{
GetAllRowText();
}
}
Component* TestListBox::refreshComponentForRow(int rowNumber, bool isRowSelected, juce::Component* existingComponentToUpdate)
{
if(rowNumber <= mRowCount)
{
TextEditor textEditor = (TextEditor) existingComponentToUpdate;
if(textEditor == 0)
textEditor = new TextEditor();
return textEditor;
}
else
{
//jassert(existingComponentToUpdate == 0);
return 0;
}
}
void TestListBox::AddRow()
{
mRowCount++;
mListBox.updateContent();
}
void TestListBox::DeleteRow()
{
if(mRowCount > 0)
{
mRowCountâ;
mListBox.updateContent();
}
}
void TestListBox::GetAllRowText()
{
int childCompCount = mListBox.getNumChildComponents();
juce::String str;
for(int i = 0; i < mRowCount; ++i)
{
TextEditor textEditor = (TextEditor)mListBox.getComponentForRowNumber(i);
str += textEditor->getText();
str += â\nâ;
}
juce::AlertWindow::showMessageBox(juce::AlertWindow::WarningIcon, âALL Words In List:â, str);
}[/b]