[ create a new paste ] login | about

Link: http://codepad.org/jBzAYNyE    [ raw code | fork ]

hurracane - C++, pasted on Dec 24:
#include <iostream>

#include "wx/wx.h"
#include "wx/grid.h"
#include "wx/xrc/xmlres.h"

#include "gui.h"
#include "MovieDB.h"
#include "MovieLibrary.h"
#include "general_functions.h"

#include <set>

#ifdef __WXMAC__
#include <ApplicationServices/ApplicationServices.h>
#endif


// ----------------------------------------------------------------------------
// the application class
// ----------------------------------------------------------------------------

// 'Main program' equivalent: the program execution "starts" here
bool MyApp::OnInit() {
#ifdef __WXMAC__
	ProcessSerialNumber PSN;
	GetCurrentProcess(&PSN);
	TransformProcessType(&PSN,kProcessTransformToForegroundApplication);
#endif
	wxXmlResource::Get()->InitAllHandlers();
	wxXmlResource::Get()->Load(_T("gui.xrc"));

	Collection* library = new Collection;
	MovieDB database ("db.txt");
	database.loadDB(*library);

	MainWindow* frame = new MainWindow(wxString(_T("XML resources demo")), wxPoint(50, 50), wxSize(800, 600), library);
	fillGrid(frame->grid_, *library);
	frame->Show(true);
	return true;
}

// ----------------------------------------------------------------------------
// main frame
// ----------------------------------------------------------------------------

// frame constructor
MainWindow::MainWindow(const wxString& title, const wxPoint& pos, const wxSize& size, Collection* library)
: wxFrame(), library_(library) {
	wxXmlResource::Get()->LoadFrame(this, NULL, _T("hoofdvenster"));

	grid_ = (wxGrid *)FindWindowById(XRCID("filmtabel"));
	grid_->CreateGrid(0, 4, wxGrid::wxGridSelectRows);
	grid_->SetColLabelValue(0, _T("Title"));
	grid_->SetColLabelValue(1, _T("Release Date"));
	grid_->SetColLabelValue(2, _T("Medium"));
	grid_->SetColLabelValue(3, _T("Genres"));
}
void MainWindow::openAddWindow(wxCommandEvent& event) {
	std::cout << "opening add window" << std::endl;

	// HIER SEGMENTATION FAULT
	AddWindow* frame2 = new AddWindow(wxString(_T("XML resources demo")), wxPoint(50, 50), wxSize(800, 600));
	//fillGrid(frame->grid_, *library_);
}
/*void MainWindow::zoek(wxCommandEvent& event) {
	std::cout << "Hallo!" << std::endl;
	std::cout << "De huidige zoekterm is: " << zoekterm_input_->GetValue().utf8_str() << std::endl;
}*/
void AddWindow::addMedium(wxCommandEvent& event) {
	std::cout << "addMedium placeholder" << std::endl;
}
void AddWindow::addFilmData(wxCommandEvent& event) {
	std::cout << "addFilmData placeholder" << std::endl;
}
void fillGrid(wxGrid* grid_, Collection library) {
	grid_->BeginBatch();
	grid_->ClearGrid();
	wxGridTableBase * table = grid_->GetTable();

	//std::cout << library.filmdata_.size() << std::endl;
	unsigned int row = 0;
	for (Collection::iterator it = library.begin(); it != library.end(); it++) {
		for(FilmData::iterator itm = (*it)->begin(); itm != (*it)->end(); itm++) {
			grid_->AppendRows(1);
			unsigned int col = 0;
			if((*it)->isShow_) {
				Season* s = static_cast<Season*>(*it);
				table->SetValue(row, col++, wxString((s->title_ + " " + s->seasonNumber_).c_str(), wxConvUTF8));
			}
			else table->SetValue(row, col++, wxString((*it)->title_.c_str(), wxConvUTF8));
			table->SetValue(row, col++, wxString((*it)->year_.c_str(), wxConvUTF8));
			table->SetValue(row, col++, wxString((*itm)->medium.c_str(), wxConvUTF8));
			std::string genres;
			std::string genres_temp;
			for(std::set<std::string>::iterator itg = (*it)->genres_.begin(); itg != (*it)->genres_.end();) {
				genres_temp = (*itg);
				itg++;
				if(itg == (*it)->genres_.end())
					genres += genres_temp;
				else genres += genres_temp + ", ";
			}
			table->SetValue(row, col++, wxString(genres.c_str(), wxConvUTF8));
			row++;
		}
	}
	grid_->AutoSizeColumns();
	grid_->EndBatch();
}


AddWindow::AddWindow(const wxString& title, const wxPoint& pos, const wxSize& size)
: wxFrame() {
	wxXmlResource::Get()->LoadFrame(this, NULL, _T("toevoegvenster"));

	title_input_ = (wxTextCtrl *)FindWindowById(XRCID("title_input_"));
	release_date_input_ = (wxTextCtrl *)FindWindowById(XRCID("release_date_input"));
	genres_input_ = (wxTextCtrl *)FindWindowById(XRCID("genres_input"));
	cast_input_ = (wxTextCtrl *)FindWindowById(XRCID("cast_input"));
	episodes_input_ = (wxTextCtrl *)FindWindowById(XRCID("episodes_input"));

	grid_ = (wxGrid *)FindWindowById(XRCID("filmtabel_addwindow"));
	grid_->CreateGrid(0, 4, wxGrid::wxGridSelectRows);
	grid_->SetColLabelValue(0, _T("Title"));
	grid_->SetColLabelValue(1, _T("Release Date"));
	grid_->SetColLabelValue(2, _T("Medium"));
	grid_->SetColLabelValue(3, _T("Genres"));

}


Create a new paste based on this one


Comments: