Communicate.h
Code: Select all
#include "Panels.h"
#include <wx/wxprec.h>
#include <wx/filename.h>
#include <wx/textfile.h>
class Communicate : public wxFrame
{
public:
Communicate(const wxString& title);
~Communicate();
void OnQuit(wxCommandEvent& event);
void OnOpenFile(wxCommandEvent& eventt);
void OnSearch(wxCommandEvent& eventt);
LeftPanel* getLeftPanel() { return lPanel; }
RightPanel* getRightPanel() { return rPanel; }
wxPanel* getParentPanel() { return panelParent; }
private:
LeftPanel *lPanel;
RightPanel *rPanel;
wxPanel *panelParent;
};
Code: Select all
#include "Communicate.h"
Communicate::Communicate(const wxString& title)
: wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(650, 500))
{
this->panelParent = new wxPanel(this, wxID_ANY);
wxMenuBar* menuBar = new wxMenuBar;
wxMenu* menuFile = new wxMenu;
menuFile->Append(wxID_OPEN, wxT("&Open"));
menuFile->Append(wxID_FIND, wxT("&Search"));
menuFile->Append(wxID_EXIT, wxT("&Quit"));
menuBar->Append(menuFile, wxT("&File"));
this->SetMenuBar(menuBar);
Connect(wxID_OPEN, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(Communicate::OnOpenFile));
Connect(wxID_FIND, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(Communicate::OnSearch));
Connect(wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(Communicate::OnQuit));
wxBoxSizer *mainBox = new wxBoxSizer(wxHORIZONTAL);
this->lPanel = new LeftPanel(this->panelParent, wxID_ANY);
this->rPanel = new RightPanel(this->panelParent, wxID_ANY);
mainBox->Add(lPanel, 2, wxEXPAND | wxALL, 5);
mainBox->Add(rPanel, 8, wxEXPAND | wxALL, 5);
this->panelParent->SetSizer(mainBox);
this->Centre();
}
void Communicate::OnQuit(wxCommandEvent& WXUNUSED(event))
{
Close(true);
}
void Communicate::OnOpenFile(wxCommandEvent& event)
{
wxTextFile file;
wxFileDialog* FileDialog1 = new wxFileDialog(this);
int result;
result = FileDialog1->ShowModal();
if(result==wxID_OK)
{
file.Close();
//add extension checking
wxStaticText* textArea = rPanel->getTextArea();
textArea->SetLabel(FileDialog1->GetPath());
}
}
void Communicate::OnSearch(wxCommandEvent& event)
{
wxTextEntryDialog myDialog(this, _("Enter what you are looking for..."), _("Search"), _(""));
if ( myDialog.ShowModal() == wxID_OK )
{
wxStaticText* textArea = rPanel->getTextArea();
textArea->SetLabel(myDialog.GetValue());
this->rPanel->FitInside();
}
}
Communicate::~Communicate()
{
delete rPanel;
delete lPanel;
delete panelParent;
std::cout << "com" << std::endl;
}
Code: Select all
#include <wx/wx.h>
#include <wx/panel.h>
#include <vector>
class LeftPanel : public wxScrolledWindow
{
public:
LeftPanel(wxWindow* parent, wxWindowID id);
~LeftPanel();
void showId(wxCommandEvent & event);
std::vector<wxButton*> getButtons() { return buttons; }
void addButton();
wxWindow* getParentWindow() { return windowParent; }
private:
wxBoxSizer* sizer;
std::vector <wxButton*> buttons;
wxWindow *windowParent;
};
class RightPanel : public wxScrolledWindow
{
public:
RightPanel(wxWindow* parent, wxWindowID id);
~RightPanel();
wxStaticText* getTextArea() { return textArea; }
private:
wxStaticText *textArea;
};
Code: Select all
#include <wx/stattext.h>
#include "Communicate.h"
LeftPanel::LeftPanel(wxWindow* parent, wxWindowID id)
: wxScrolledWindow(parent, id)
{
this->windowParent = parent;
this->sizer = new wxBoxSizer(wxVERTICAL);
for (int w=0; w<10; w++)
{
this->buttons.push_back(new wxButton(this, w + 111, wxString::Format(wxT("Button %i"), w)));
Connect(w + 111, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(LeftPanel::showId));
this->sizer->Add(buttons[w], 0, wxALL, 1);
}
this->SetSizer(sizer);
// this part makes the scrollbars show up
this->FitInside(); // ask the sizer about the needed size
this->SetScrollRate(5, 5);
}
void LeftPanel::showId(wxCommandEvent& event)
{
Communicate *comm = (Communicate *) this->windowParent->GetParent();
RightPanel *rpanel = comm->getRightPanel();
wxStaticText *textArea = rpanel->getTextArea();
textArea->SetLabel(wxString::Format(wxT("%d"), event.GetId()));
this->addButton();
}
void LeftPanel::addButton()
{
wxButton* wxB = new wxButton(this, this->buttons.size() + 112, wxString::Format(wxT("Button %i"), this->buttons.size()));
this->buttons.push_back(wxB);
Connect(wxB->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(LeftPanel::showId));
this->sizer->Add(wxB, 0, wxALL, 3);
this->sizer->Layout();
this->FitInside();
}
LeftPanel::~LeftPanel()
{
//this->sizer->Clear(1);
//delete this->sizer;
for(auto btn: this->buttons)
{
delete btn;
}
this->buttons.clear();
}
RightPanel::RightPanel(wxWindow* parent, wxWindowID id)
: wxScrolledWindow(parent, id)
{
wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
this->textArea = new wxStaticText(this, -1,
wxT("0asd\ndasd0\n0saasas\n0ww1wsa\nas\nasdad\nasd\nasdwasd\n"));
sizer->Add( this->textArea, 0, wxALL, 3);
this->SetSizer(sizer);
// this part makes the scrollbars show up
//need to do that after text changing
this->FitInside(); // ask the sizer about the needed size
this->SetScrollRate(5, 5);
}
RightPanel::~RightPanel()
{
delete this->textArea;
}