From 0be270ad00151037880ed857d2aa1a2f78c38700 Mon Sep 17 00:00:00 2001 From: bgk Date: Sun, 20 Feb 2011 16:36:25 +0000 Subject: [PATCH] GTK: Cleanup includes. Don't instanciate global objects. git-svn-id: https://svn.code.sf.net/p/vbam/code/trunk@987 a31d4220-a93d-0410-bf67-fe4944624d44 --- src/gtk/cheatedit.cpp | 33 +++++++------------------- src/gtk/cheatedit.h | 22 ++++++++++++++++- src/gtk/cheatlist.cpp | 43 ++++++++++------------------------ src/gtk/cheatlist.h | 20 +++++++++++++++- src/gtk/gameboyadvanceconfig.h | 3 ++- src/gtk/gameboyconfig.h | 3 ++- src/gtk/stringtokenizer.cpp | 2 ++ src/gtk/stringtokenizer.h | 5 +--- 8 files changed, 68 insertions(+), 63 deletions(-) diff --git a/src/gtk/cheatedit.cpp b/src/gtk/cheatedit.cpp index e722cb93..553ee90e 100644 --- a/src/gtk/cheatedit.cpp +++ b/src/gtk/cheatedit.cpp @@ -23,23 +23,6 @@ namespace VBA { -class CheatCodeColumns : public Gtk::TreeModel::ColumnRecord -{ - public: - CheatCodeColumns() - { - add(uText); - add(iType); - } - - ~CheatCodeColumns() {} - - Gtk::TreeModelColumn uText; - Gtk::TreeModelColumn iType; -}; - -CheatCodeColumns cTypeModel; - /** * GameBoyAdvanceCheatEditDialog * @@ -55,24 +38,24 @@ CheatEditDialog::CheatEditDialog(GtkDialog* _pstDialog, const Glib::RefPtrget_widget("CheatCancelButton", m_poCheatCancelButton); // Tree View model - m_poCheatTypeStore = Gtk::ListStore::create(cTypeModel); + m_poCheatTypeStore = Gtk::ListStore::create(m_oTypeModel); m_poCheatTypeComboBox->set_model(m_poCheatTypeStore); Gtk::TreeModel::Row row = *(m_poCheatTypeStore->append()); - row[cTypeModel.iType] = CheatGeneric; - row[cTypeModel.uText] = "Generic Code"; + row[m_oTypeModel.iType] = CheatGeneric; + row[m_oTypeModel.uText] = "Generic Code"; row = *(m_poCheatTypeStore->append()); - row[cTypeModel.iType] = CheatGSA; - row[cTypeModel.uText] = "Gameshark Advance"; + row[m_oTypeModel.iType] = CheatGSA; + row[m_oTypeModel.uText] = "Gameshark Advance"; row = *(m_poCheatTypeStore->append()); - row[cTypeModel.iType] = CheatCBA; - row[cTypeModel.uText] = "CodeBreaker Advance"; + row[m_oTypeModel.iType] = CheatCBA; + row[m_oTypeModel.uText] = "CodeBreaker Advance"; m_poCheatTypeComboBox->set_active(CheatGeneric); @@ -98,7 +81,7 @@ ECheatType CheatEditDialog::vGetType() { Gtk::TreeModel::Row row = *iter; - return row[cTypeModel.iType]; + return row[m_oTypeModel.iType]; } return CheatGeneric; diff --git a/src/gtk/cheatedit.h b/src/gtk/cheatedit.h index 6027caf5..4e9fe2f0 100644 --- a/src/gtk/cheatedit.h +++ b/src/gtk/cheatedit.h @@ -19,7 +19,11 @@ #ifndef __VBA_CHEATEDIT_H__ #define __VBA_CHEATEDIT_H__ -#include +#include +#include +#include +#include +#include #include "window.h" @@ -33,6 +37,21 @@ enum ECheatType CheatCBA }; +class EditCheatCodeColumns : public Gtk::TreeModel::ColumnRecord +{ + public: + EditCheatCodeColumns() + { + add(uText); + add(iType); + } + + ~EditCheatCodeColumns() {} + + Gtk::TreeModelColumn uText; + Gtk::TreeModelColumn iType; +}; + class CheatEditDialog : public Gtk::Dialog { public: @@ -54,6 +73,7 @@ private: Gtk::Button * m_poCheatCancelButton; Glib::RefPtr m_poCheatInputBuffer; Glib::RefPtr m_poCheatTypeStore; + EditCheatCodeColumns m_oTypeModel; }; } // namespace VBA diff --git a/src/gtk/cheatlist.cpp b/src/gtk/cheatlist.cpp index 3d8c456f..acef25cd 100644 --- a/src/gtk/cheatlist.cpp +++ b/src/gtk/cheatlist.cpp @@ -18,6 +18,8 @@ #include "cheatlist.h" +#include + #include "intl.h" #include "stringtokenizer.h" #include @@ -25,25 +27,6 @@ namespace VBA { -class CheatCodeColumns : public Gtk::TreeModel::ColumnRecord -{ - public: - CheatCodeColumns() - { - add(iIndex); - add(bEnabled); - add(uDesc); - } - - ~CheatCodeColumns() {} - - Gtk::TreeModelColumn iIndex; - Gtk::TreeModelColumn bEnabled; - Gtk::TreeModelColumn uDesc; -}; - -CheatCodeColumns cRecordModel; - CheatListDialog::CheatListDialog(GtkDialog* _pstDialog, const Glib::RefPtr& refBuilder) : Gtk::Dialog(_pstDialog) { @@ -56,7 +39,7 @@ CheatListDialog::CheatListDialog(GtkDialog* _pstDialog, const Glib::RefPtrget_widget("CheatTreeView", m_poCheatTreeView); // Tree View model - m_poCheatListStore = Gtk::ListStore::create(cRecordModel); + m_poCheatListStore = Gtk::ListStore::create(m_oRecordModel); m_poCheatTreeView->set_model(m_poCheatListStore); @@ -69,9 +52,9 @@ CheatListDialog::CheatListDialog(GtkDialog* _pstDialog, const Glib::RefPtrget_column(cols_count - 1); if (pColumn) - pColumn->add_attribute(pRenderer->property_active(), cRecordModel.bEnabled); + pColumn->add_attribute(pRenderer->property_active(), m_oRecordModel.bEnabled); - m_poCheatTreeView->append_column("Description", cRecordModel.uDesc); + m_poCheatTreeView->append_column("Description", m_oRecordModel.uDesc); m_poCheatOpenButton->signal_clicked().connect(sigc::mem_fun(*this, &CheatListDialog::vOnCheatOpen)); m_poCheatSaveButton->signal_clicked().connect(sigc::mem_fun(*this, &CheatListDialog::vOnCheatSave)); @@ -230,7 +213,7 @@ void CheatListDialog::vOnCheatRemove() { Gtk::TreeModel::Row row = *iter; - cheatsDelete(row[cRecordModel.iIndex], false); + cheatsDelete(row[m_oRecordModel.iIndex], false); m_poCheatListStore->erase(iter); } @@ -251,9 +234,9 @@ void CheatListDialog::vOnCheatMarkAll() { Gtk::TreeModel::Row row = *iter; - row[cRecordModel.bEnabled] = bMark; + row[m_oRecordModel.bEnabled] = bMark; - vToggleCheat(row[cRecordModel.iIndex], row[cRecordModel.bEnabled]); + vToggleCheat(row[m_oRecordModel.iIndex], row[m_oRecordModel.bEnabled]); } bMark = !bMark; @@ -265,9 +248,9 @@ void CheatListDialog::vOnCheatToggled(Glib::ustring const& string_path) Gtk::TreeModel::Row row = *iter; - row[cRecordModel.bEnabled] = !row[cRecordModel.bEnabled]; + row[m_oRecordModel.bEnabled] = !row[m_oRecordModel.bEnabled]; - vToggleCheat(row[cRecordModel.iIndex], row[cRecordModel.bEnabled]); + vToggleCheat(row[m_oRecordModel.iIndex], row[m_oRecordModel.bEnabled]); } void CheatListDialog::vToggleCheat(int index, bool enable) { @@ -284,9 +267,9 @@ void CheatListDialog::vUpdateList(int previous) // Add row for each newly added cheat Gtk::TreeModel::Row row = *(m_poCheatListStore->append()); - row[cRecordModel.iIndex] = i; - row[cRecordModel.bEnabled] = cheatsList[i].enabled; - row[cRecordModel.uDesc] = cheatsList[i].desc; + row[m_oRecordModel.iIndex] = i; + row[m_oRecordModel.bEnabled] = cheatsList[i].enabled; + row[m_oRecordModel.uDesc] = cheatsList[i].desc; } } diff --git a/src/gtk/cheatlist.h b/src/gtk/cheatlist.h index 4a522aa4..39bc9d3c 100644 --- a/src/gtk/cheatlist.h +++ b/src/gtk/cheatlist.h @@ -19,7 +19,7 @@ #ifndef __VBA_CHEATLIST_H__ #define __VBA_CHEATLIST_H__ -#include +#include #include "../System.h" #include "../gba/Cheats.h" @@ -32,6 +32,23 @@ namespace VBA { +class ListCheatCodeColumns : public Gtk::TreeModel::ColumnRecord +{ + public: + ListCheatCodeColumns() + { + add(iIndex); + add(bEnabled); + add(uDesc); + } + + ~ListCheatCodeColumns() {} + + Gtk::TreeModelColumn iIndex; + Gtk::TreeModelColumn bEnabled; + Gtk::TreeModelColumn uDesc; +}; + class CheatListDialog : public Gtk::Dialog { public: @@ -59,6 +76,7 @@ private: Gtk::ToolButton * m_poCheatMarkAllButton; Gtk::TreeView * m_poCheatTreeView; Glib::RefPtr m_poCheatListStore; + ListCheatCodeColumns m_oRecordModel; bool bMark; }; diff --git a/src/gtk/gameboyadvanceconfig.h b/src/gtk/gameboyadvanceconfig.h index 591ef4ea..07dab178 100644 --- a/src/gtk/gameboyadvanceconfig.h +++ b/src/gtk/gameboyadvanceconfig.h @@ -19,7 +19,8 @@ #ifndef __VBA_GAMEBOYADVANCECONFIG_H__ #define __VBA_GAMEBOYADVANCECONFIG_H__ -#include +#include +#include #include "configfile.h" #include "window.h" diff --git a/src/gtk/gameboyconfig.h b/src/gtk/gameboyconfig.h index 5253e0c8..09348f1d 100644 --- a/src/gtk/gameboyconfig.h +++ b/src/gtk/gameboyconfig.h @@ -19,7 +19,8 @@ #ifndef __VBA_GAMEBOYCONFIG_H__ #define __VBA_GAMEBOYCONFIG_H__ -#include +#include +#include #include "configfile.h" #include "window.h" diff --git a/src/gtk/stringtokenizer.cpp b/src/gtk/stringtokenizer.cpp index 056e9f9f..f64ce36b 100644 --- a/src/gtk/stringtokenizer.cpp +++ b/src/gtk/stringtokenizer.cpp @@ -23,6 +23,8 @@ namespace VBA void StringTokenizer::tokenize(Glib::ustring source, std::vector& tokens) { + Glib::ustring delimiters = " \t\n\r"; + // Skip delimiters at beginning. Glib::ustring::size_type lastPos = source.find_first_not_of(delimiters, 0); // Find first "non-delimiter". diff --git a/src/gtk/stringtokenizer.h b/src/gtk/stringtokenizer.h index 41912aed..02380151 100644 --- a/src/gtk/stringtokenizer.h +++ b/src/gtk/stringtokenizer.h @@ -20,8 +20,7 @@ #ifndef __VBA_STRINGTOKENIZER_H__ #define __VBA_STRINGTOKENIZER_H__ -#include -#include +#include #include namespace VBA @@ -33,8 +32,6 @@ public: static void tokenize(Glib::ustring source, std::vector& tokens); }; -static const Glib::ustring delimiters = " \t\n\r"; - } // VBA namespace #endif