From 4272d7cd99ac7dae12765a4d2039479c078b8358 Mon Sep 17 00:00:00 2001 From: John Peterson Date: Mon, 31 Aug 2009 23:09:50 +0000 Subject: [PATCH] GUI: No need to remove the log window git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@4131 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/DebuggerWX/Src/CodeWindow.cpp | 9 +- Source/Core/DolphinWX/DolphinWX.vcproj | 8 + Source/Core/DolphinWX/Src/Frame.cpp | 44 ++- Source/Core/DolphinWX/Src/Frame.h | 11 +- Source/Core/DolphinWX/Src/FrameTools.cpp | 36 +- Source/Core/DolphinWX/Src/LogWindow.cpp | 436 ++++++++++++++++++++++ Source/Core/DolphinWX/Src/LogWindow.h | 90 +++++ Source/Core/DolphinWX/Src/Main.cpp | 9 +- Source/Core/DolphinWX/Src/SConscript | 1 + 9 files changed, 628 insertions(+), 16 deletions(-) create mode 100644 Source/Core/DolphinWX/Src/LogWindow.cpp create mode 100644 Source/Core/DolphinWX/Src/LogWindow.h diff --git a/Source/Core/DebuggerWX/Src/CodeWindow.cpp b/Source/Core/DebuggerWX/Src/CodeWindow.cpp index 4835dab9e4..1b3588f263 100644 --- a/Source/Core/DebuggerWX/Src/CodeWindow.cpp +++ b/Source/Core/DebuggerWX/Src/CodeWindow.cpp @@ -208,6 +208,11 @@ void CCodeWindow::OnHostMessage(wxCommandEvent& event) case IDM_NOTIFYMAPLOADED: NotifyMapLoaded(); break; + /* + case IDM_UPDATELOGDISPLAY: + if (m_LogWindow) m_LogWindow->NotifyUpdate(); + break; + */ case IDM_UPDATEDISASMDIALOG: Update(); if (m_RegisterWindow) m_RegisterWindow->NotifyUpdate(); @@ -437,6 +442,7 @@ void CCodeWindow::Load() std::string _Section = StringFromFormat("P - %s", (Parent->ActivePerspective < Parent->Perspectives.size()) ? Parent->Perspectives.at(Parent->ActivePerspective).Name.c_str() : ""); + ini.Get(_Section.c_str(), "Log", &iLogWindow, 1); ini.Get(_Section.c_str(), "Console", &iConsoleWindow, 1); ini.Get(_Section.c_str(), "Code", &iCodeWindow, 1); ini.Get(_Section.c_str(), "Registers", &iRegisterWindow, 1); @@ -472,6 +478,7 @@ void CCodeWindow::Save() std::string _Section = StringFromFormat("P - %s", (Parent->ActivePerspective < Parent->Perspectives.size()) ? Parent->Perspectives.at(Parent->ActivePerspective).Name.c_str() : ""); + ini.Set(_Section.c_str(), "Log", iLogWindow); ini.Set(_Section.c_str(), "Console", iConsoleWindow); ini.Set(_Section.c_str(), "Code", iCodeWindow); ini.Set(_Section.c_str(), "Registers", iRegisterWindow); @@ -909,4 +916,4 @@ void CCodeWindow::OnStatusBar_(wxUpdateUIEvent& event) //if(event.GetId() != IDM_ADDRBOX) DoTip(wxEmptyString); #endif } -///////////////////////////////////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/Source/Core/DolphinWX/DolphinWX.vcproj b/Source/Core/DolphinWX/DolphinWX.vcproj index b46fe67446..1414e80ef2 100644 --- a/Source/Core/DolphinWX/DolphinWX.vcproj +++ b/Source/Core/DolphinWX/DolphinWX.vcproj @@ -1152,6 +1152,14 @@ RelativePath=".\Src\ISOProperties.h" > + + + + diff --git a/Source/Core/DolphinWX/Src/Frame.cpp b/Source/Core/DolphinWX/Src/Frame.cpp index 9374e2ad38..9961030e75 100644 --- a/Source/Core/DolphinWX/Src/Frame.cpp +++ b/Source/Core/DolphinWX/Src/Frame.cpp @@ -17,14 +17,22 @@ +////////////////////////////////////////////////////////////////////////////////////////// +// Windows /* ŻŻŻŻŻŻŻŻŻŻŻŻŻŻ -CFrame is the main parent window. Inside CFrame there is an m_Panel that is the -parent for the rendering window (when we render to the main window). In Windows -the rendering window is created by giving CreateWindow() m_Panel->GetHandle() -as parent window and creating a new child window to m_Panel. The new child -window handle that is returned by CreateWindow() can be accessed from -Core::GetWindowHandle(). */ +CFrame is the main parent window. Inside CFrame there is an m_Panel that is the parent for +the rendering window (when we render to the main window). In Windows the rendering window is +created by giving CreateWindow() m_Panel->GetHandle() as parent window and creating a new +child window to m_Panel. The new child window handle that is returned by CreateWindow() can +be accessed from Core::GetWindowHandle(). + +///////////////////////////////////////////////*/ + + +// ---------------------------------------------------------------------------- +// includes +// ---------------------------------------------------------------------------- #include "Common.h" // Common #include "FileUtil.h" @@ -46,9 +54,13 @@ Core::GetWindowHandle(). */ #include "HW/DVDInterface.h" #include "State.h" #include "VolumeHandler.h" -#include "LogManager.h" + #include // wxWidgets +// ---------------------------------------------------------------------------- +// resources +// ---------------------------------------------------------------------------- + extern "C" { #include "../resources/Dolphin.c" // Dolphin icon #include "../resources/toolbar_browse.c" @@ -256,6 +268,7 @@ EVT_MENU(IDM_TOGGLE_DUALCORE, CFrame::OnToggleDualCore) EVT_MENU(IDM_TOGGLE_SKIPIDLE, CFrame::OnToggleSkipIdle) EVT_MENU(IDM_TOGGLE_TOOLBAR, CFrame::OnToggleToolbar) EVT_MENU(IDM_TOGGLE_STATUSBAR, CFrame::OnToggleStatusbar) +EVT_MENU(IDM_LOGWINDOW, CFrame::OnToggleLogWindow) EVT_MENU(IDM_CONSOLEWINDOW, CFrame::OnToggleConsole) EVT_MENU(IDM_LISTDRIVES, CFrame::GameListChanged) @@ -298,8 +311,14 @@ EVT_AUINOTEBOOK_ALLOW_DND(wxID_ANY, CFrame::OnAllowNotebookDnD) EVT_AUINOTEBOOK_PAGE_CHANGED(wxID_ANY, CFrame::OnNotebookPageChanged) END_EVENT_TABLE() +///////////////////////////////////////////////////////////////////////////////////////////////////////// -CFrame::CFrame(wxFrame* parent, + +///////////////////////////////////////////////////////////////////////////////////////////////////////// +// Creation and close, quit functions +// ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ +CFrame::CFrame(bool showLogWindow, + wxFrame* parent, wxWindowID id, const wxString& title, const wxPoint& pos, @@ -307,15 +326,20 @@ CFrame::CFrame(wxFrame* parent, bool _UseDebugger, long style) : wxFrame(parent, id, title, pos, size, style) - , UseDebugger(_UseDebugger) + , UseDebugger(_UseDebugger), m_LogWindow(NULL) , m_pStatusBar(NULL), bRenderToMain(true), HaveLeds(false) , HaveSpeakers(false), m_Panel(NULL), m_ToolBar(NULL), m_ToolBarDebug(NULL) + , m_bLogWindow(showLogWindow || SConfig::GetInstance().m_InterfaceLogWindow) , m_fLastClickTime(0), m_iLastMotionTime(0), LastMouseX(0), LastMouseY(0) #if wxUSE_TIMER , m_timer(this) #endif { + #ifndef _WIN32 + m_bLogWindow = false; + #endif + // Give it a console ConsoleListener *Console = LogManager::GetInstance()->getConsoleListener(); if (SConfig::GetInstance().m_InterfaceConsole) Console->Open(); @@ -461,6 +485,7 @@ CFrame::CFrame(wxFrame* parent, if (!UseDebugger) { SetSimplePaneSize(); + if (m_bLogWindow) DoToggleWindow(IDM_LOGWINDOW, true); if (SConfig::GetInstance().m_InterfaceConsole) DoToggleWindow(IDM_CONSOLEWINDOW, true); } @@ -687,6 +712,7 @@ void CFrame::ReloadPanes() // Open notebook pages AddRemoveBlankPage(); g_pCodeWindow->OpenPages(); + if (m_bLogWindow) DoToggleWindow(IDM_LOGWINDOW, true); if (SConfig::GetInstance().m_InterfaceConsole) DoToggleWindow(IDM_CONSOLEWINDOW, true); } void CFrame::DoLoadPerspective() diff --git a/Source/Core/DolphinWX/Src/Frame.h b/Source/Core/DolphinWX/Src/Frame.h index ee9bd26058..64118e30f3 100644 --- a/Source/Core/DolphinWX/Src/Frame.h +++ b/Source/Core/DolphinWX/Src/Frame.h @@ -28,6 +28,7 @@ #include "CDUtils.h" #include "CodeWindow.h" +#include "LogWindow.h" // A shortcut to access the bitmaps #define wxGetBitmapFromMemory(name) _wxGetBitmapFromMemory(name, sizeof(name)) @@ -39,13 +40,15 @@ inline wxBitmap _wxGetBitmapFromMemory(const unsigned char* data, int length) // Class declarations class CGameListCtrl; +class CLogWindow; class CFrame : public wxFrame { public: - CFrame(wxFrame* parent, - wxWindowID id = wxID_ANY, + CFrame(bool showLogWindow, + wxFrame* parent, + wxWindowID id = wxID_ANY, const wxString& title = wxT("Dolphin"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, @@ -71,6 +74,7 @@ class CFrame : public wxFrame void DoStop(); bool bRenderToMain; void UpdateGUI(); + void ToggleLogWindow(bool, int i = -1); void ToggleConsole(bool, int i = -1); void PostEvent(wxCommandEvent& event); void PostMenuEvent(wxMenuEvent& event); @@ -155,6 +159,8 @@ class CFrame : public wxFrame CGameListCtrl* m_GameListCtrl; wxPanel* m_Panel; wxToolBarToolBase* m_ToolPlay; + bool m_bLogWindow; + CLogWindow* m_LogWindow; char **drives; @@ -252,6 +258,7 @@ class CFrame : public wxFrame void OnToggleToolbar(wxCommandEvent& event); void DoToggleToolbar(bool); void OnToggleStatusbar(wxCommandEvent& event); + void OnToggleLogWindow(wxCommandEvent& event); void OnToggleConsole(wxCommandEvent& event); void OnKeyDown(wxKeyEvent& event); void OnKeyUp(wxKeyEvent& event); diff --git a/Source/Core/DolphinWX/Src/FrameTools.cpp b/Source/Core/DolphinWX/Src/FrameTools.cpp index e6614fe4b9..556f3d76a5 100644 --- a/Source/Core/DolphinWX/Src/FrameTools.cpp +++ b/Source/Core/DolphinWX/Src/FrameTools.cpp @@ -54,8 +54,8 @@ Core::GetWindowHandle(). #include "AboutDolphin.h" #include "GameListCtrl.h" #include "BootManager.h" +#include "LogWindow.h" #include "WxUtils.h" -#include "LogManager.h" #include "ConfigManager.h" // Core #include "Core.h" @@ -198,6 +198,11 @@ void CFrame::CreateMenu() viewMenu->Check(IDM_TOGGLE_TOOLBAR, SConfig::GetInstance().m_InterfaceToolbar); viewMenu->AppendCheckItem(IDM_TOGGLE_STATUSBAR, _T("Show &Statusbar")); viewMenu->Check(IDM_TOGGLE_STATUSBAR, SConfig::GetInstance().m_InterfaceStatusbar); + viewMenu->AppendCheckItem(IDM_LOGWINDOW, _T("Show &Logwindow")); + viewMenu->Check(IDM_LOGWINDOW, m_bLogWindow); + #ifndef _WIN32 + viewMenu->Enable(IDM_LOGWINDOW, false); + #endif viewMenu->AppendCheckItem(IDM_CONSOLEWINDOW, _T("Show &Console")); viewMenu->Check(IDM_CONSOLEWINDOW, SConfig::GetInstance().m_InterfaceConsole); viewMenu->AppendSeparator(); @@ -1085,6 +1090,7 @@ int CFrame::GetNootebookAffiliation(wxString Name) } void CFrame::ClosePages() { + DoToggleWindow(IDM_LOGWINDOW, false); //DoToggleWindow(IDM_CONSOLEWINDOW, false); DoToggleWindow(IDM_CODEWINDOW, false); DoToggleWindow(IDM_REGISTERWINDOW, false); @@ -1098,6 +1104,7 @@ void CFrame::DoToggleWindow(int Id, bool Show) { switch (Id) { + case IDM_LOGWINDOW: ToggleLogWindow(Show, UseDebugger ? g_pCodeWindow->iLogWindow : 0); break; case IDM_CONSOLEWINDOW: ToggleConsole(Show, UseDebugger ? g_pCodeWindow->iConsoleWindow : 0); break; case IDM_CODEWINDOW: g_pCodeWindow->OnToggleCodeWindow(Show, g_pCodeWindow->iCodeWindow); break; case IDM_REGISTERWINDOW: g_pCodeWindow->OnToggleRegisterWindow(Show, g_pCodeWindow->iRegisterWindow); break; @@ -1117,6 +1124,7 @@ void CFrame::OnNotebookPageChanged(wxAuiNotebookEvent& event) AddRemoveBlankPage(); // Update the notebook affiliation + if(GetNootebookAffiliation(wxT("Log")) >= 0) g_pCodeWindow->iLogWindow = GetNootebookAffiliation(wxT("Log")); if(GetNootebookAffiliation(wxT("Console")) >= 0) g_pCodeWindow->iConsoleWindow = GetNootebookAffiliation(wxT("Console")); if(GetNootebookAffiliation(wxT("Code")) >= 0) g_pCodeWindow->iCodeWindow = GetNootebookAffiliation(wxT("Code")); if(GetNootebookAffiliation(wxT("Registers")) >= 0) g_pCodeWindow->iRegisterWindow = GetNootebookAffiliation(wxT("Registers")); @@ -1133,6 +1141,7 @@ void CFrame::OnNotebookPageClose(wxAuiNotebookEvent& event) wxAuiNotebook* Ctrl = (wxAuiNotebook*)event.GetEventObject(); + if (Ctrl->GetPageText(event.GetSelection()).IsSameAs(wxT("Log"))) { GetMenuBar()->FindItem(IDM_LOGWINDOW)->Check(false); DoToggleWindow(IDM_LOGWINDOW, false); } if (Ctrl->GetPageText(event.GetSelection()).IsSameAs(wxT("Console"))) { GetMenuBar()->FindItem(IDM_CONSOLEWINDOW)->Check(false); DoToggleWindow(IDM_CONSOLEWINDOW, false); } if (Ctrl->GetPageText(event.GetSelection()).IsSameAs(wxT("Registers"))) { GetMenuBar()->FindItem(IDM_REGISTERWINDOW)->Check(false); DoToggleWindow(IDM_REGISTERWINDOW, false); } if (Ctrl->GetPageText(event.GetSelection()).IsSameAs(wxT("Breakpoints"))) { GetMenuBar()->FindItem(IDM_BREAKPOINTWINDOW)->Check(false); DoToggleWindow(IDM_BREAKPOINTWINDOW, false); } @@ -1262,6 +1271,31 @@ void CFrame::OnToggleStatusbar(wxCommandEvent& event) this->SendSizeEvent(); } +// Enable and disable the log window +void CFrame::OnToggleLogWindow(wxCommandEvent& event) +{ + DoToggleWindow(event.GetId(), event.IsChecked()); +} +void CFrame::ToggleLogWindow(bool Show, int i) +{ + SConfig::GetInstance().m_InterfaceLogWindow = Show; + if (Show) + { + if (!m_LogWindow) m_LogWindow = new CLogWindow(this); + DoAddPage(m_LogWindow, i, "Log"); + } + else + { + DoRemovePage(m_LogWindow); + } + + // Hide pane + if (!UseDebugger) HidePane(); + + // Make sure the check is updated (if wxw isn't calling this func) + //GetMenuBar()->FindItem(IDM_LOGWINDOW)->Check(Show); +} +// Enable and disable the console void CFrame::OnToggleConsole(wxCommandEvent& event) { DoToggleWindow(event.GetId(), event.IsChecked()); diff --git a/Source/Core/DolphinWX/Src/LogWindow.cpp b/Source/Core/DolphinWX/Src/LogWindow.cpp new file mode 100644 index 0000000000..2235f0db3e --- /dev/null +++ b/Source/Core/DolphinWX/Src/LogWindow.cpp @@ -0,0 +1,436 @@ +// Copyright (C) 2003 Dolphin Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official SVN repository and contact information can be found at +// http://code.google.com/p/dolphin-emu/ + + +#include +#include +#include +#include +#include + +#include "Core.h" // for Core::GetState() +#include "LogWindow.h" +#include "Console.h" + +// milliseconds between msgQueue flushes to wxTextCtrl +#define UPDATETIME 200 + +BEGIN_EVENT_TABLE(CLogWindow, wxDialog) + EVT_CLOSE(CLogWindow::OnClose) + EVT_TEXT_ENTER(IDM_SUBMITCMD, CLogWindow::OnSubmit) + EVT_BUTTON(IDM_CLEARLOG, CLogWindow::OnClear) + EVT_BUTTON(IDM_TOGGLEALL, CLogWindow::OnToggleAll) + EVT_RADIOBOX(IDM_VERBOSITY, CLogWindow::OnOptionsCheck) + EVT_CHECKBOX(IDM_WRITEFILE, CLogWindow::OnOptionsCheck) + EVT_CHECKBOX(IDM_WRITECONSOLE, CLogWindow::OnOptionsCheck) + EVT_CHECKBOX(IDM_WRITEWINDOW, CLogWindow::OnOptionsCheck) + EVT_CHECKLISTBOX(IDM_LOGCHECKS, CLogWindow::OnLogCheck) + EVT_TIMER(IDTM_UPDATELOG, CLogWindow::OnLogTimer) +END_EVENT_TABLE() + +CLogWindow::CLogWindow(wxWindow* parent) + : wxDialog(parent, wxID_ANY, wxT("Log"), + wxPoint(100, 700), wxSize(800, 270), + wxNO_BORDER) + , m_logSection(1) +{ + m_logManager = LogManager::GetInstance(); + for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i) + m_logManager->addListener((LogTypes::LOG_TYPE)i, this); + m_fileLog = m_logManager->getFileListener(); + m_console = m_logManager->getConsoleListener(); + + CreateGUIControls(); + + LoadSettings(); +} + +void CLogWindow::CreateGUIControls() +{ + wxBoxSizer* sUber = new wxBoxSizer(wxHORIZONTAL), // whole plane + * sLeft = new wxBoxSizer(wxVERTICAL), // LEFT sizer + * sRight = new wxBoxSizer(wxVERTICAL), // RIGHT sizer + * sRightBottom = new wxBoxSizer(wxHORIZONTAL); // submit row + + // Left side: buttons (-submit), options, and log type selection + wxStaticBoxSizer* sbLeftOptions = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Options")); + + wxArrayString wxLevels; + for (int i = 1; i <= MAX_LOGLEVEL; ++i) + wxLevels.Add(wxString::Format(wxT("%i"), i)); + m_verbosity = new wxRadioBox(this, IDM_VERBOSITY, wxT("Verbosity"), wxDefaultPosition, wxDefaultSize, wxLevels, 0, wxRA_SPECIFY_COLS, wxDefaultValidator); + sbLeftOptions->Add(m_verbosity); + + m_writeFileCB = new wxCheckBox(this, IDM_WRITEFILE, wxT("Write to File"), wxDefaultPosition, wxDefaultSize, 0); + sbLeftOptions->Add(m_writeFileCB); + + m_writeConsoleCB = new wxCheckBox(this, IDM_WRITECONSOLE, wxT("Write to Console"), wxDefaultPosition, wxDefaultSize, 0); + sbLeftOptions->Add(m_writeConsoleCB); + + m_writeWindowCB = new wxCheckBox(this, IDM_WRITEWINDOW, wxT("Write to Window ->"), wxDefaultPosition, wxDefaultSize, 0); + sbLeftOptions->Add(m_writeWindowCB); + + sLeft->Add(sbLeftOptions, 0, wxEXPAND); + + wxBoxSizer* sLogCtrl = new wxBoxSizer(wxHORIZONTAL); + sLogCtrl->Add(new wxButton(this, IDM_TOGGLEALL, wxT("Toggle all"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT), 1); + sLogCtrl->Add(new wxButton(this, IDM_CLEARLOG, wxT("Clear"), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT), 1); + sLeft->Add(sLogCtrl, 0, wxEXPAND); + + m_checks = new wxCheckListBox(this, IDM_LOGCHECKS, wxDefaultPosition, wxDefaultSize); + sLeft->Add(m_checks, 1, wxEXPAND); + + // Right side: Log viewer and submit row + m_log = new wxTextCtrl(this, IDM_LOG, wxEmptyString, wxDefaultPosition, wxDefaultSize, + wxTE_RICH2 | wxTE_MULTILINE | wxTE_READONLY | wxTE_DONTWRAP); + // FIXME See note in UpdateLog() + //m_log->SetBackgroundColour(*wxBLACK); + //m_log->SetFont(DebuggerFont); + + m_cmdline = new wxTextCtrl(this, IDM_SUBMITCMD, wxEmptyString, wxDefaultPosition, wxDefaultSize, + wxTE_PROCESS_ENTER | wxTE_PROCESS_TAB); + //m_cmdline->SetFont(DebuggerFont); + + sRightBottom->Add(m_cmdline, 1, wxEXPAND); + sRight->Add(m_log, 1, wxEXPAND | wxSHRINK); + sRight->Add(sRightBottom, 0, wxEXPAND); + + // Take care of the main sizer and some settings + sUber->Add(sLeft, 0, wxEXPAND); + sUber->Add(sRight, 1, wxEXPAND); + + SetSizer(sUber); + SetAffirmativeId(IDM_SUBMITCMD); + UpdateChecks(); + m_cmdline->SetFocus(); + + m_logTimer = new wxTimer(this, IDTM_UPDATELOG); + m_logTimer->Start(UPDATETIME); +} + +CLogWindow::~CLogWindow() +{ + for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i) + { + m_logManager->removeListener((LogTypes::LOG_TYPE)i, this); + } + m_logTimer->Stop(); + delete m_logTimer; + + SaveSettings(); +} + +void CLogWindow::OnClose(wxCloseEvent& event) +{ + wxGetApp().GetCFrame()->ToggleLogWindow(false); + event.Skip(); +} + +void CLogWindow::SaveSettings() +{ + IniFile ini; + ini.Set("LogWindow", "x", GetPosition().x); + ini.Set("LogWindow", "y", GetPosition().y); + ini.Set("LogWindow", "w", GetSize().GetWidth()); + ini.Set("LogWindow", "h", GetSize().GetHeight()); + ini.Set("Options", "Verbosity", m_verbosity->GetSelection() + 1); + ini.Set("Options", "WriteToFile", m_writeFile); + ini.Set("Options", "WriteToConsole", m_writeConsole); + ini.Set("Options", "WriteToWindow", m_writeWindow); + for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i) + ini.Set("Logs", m_logManager->getShortName((LogTypes::LOG_TYPE)i), m_checks->IsChecked(i)); + ini.Save(LOGGER_CONFIG_FILE); +} + +void CLogWindow::LoadSettings() +{ + IniFile ini; + ini.Load(LOGGER_CONFIG_FILE); + int x,y,w,h,verbosity; + ini.Get("LogWindow", "x", &x, GetPosition().x); + ini.Get("LogWindow", "y", &y, GetPosition().y); + ini.Get("LogWindow", "w", &w, GetSize().GetWidth()); + ini.Get("LogWindow", "h", &h, GetSize().GetHeight()); + SetSize(x, y, w, h); + ini.Get("Options", "Verbosity", &verbosity, 0); + if (verbosity < 1) verbosity = 1; + if (verbosity > DEBUG_LEVEL) verbosity = DEBUG_LEVEL; + m_verbosity->SetSelection(verbosity - 1); + ini.Get("Options", "WriteToFile", &m_writeFile, true); + m_writeFileCB->SetValue(m_writeFile); + ini.Get("Options", "WriteToConsole", &m_writeConsole, true); + m_writeConsoleCB->SetValue(m_writeConsole); + ini.Get("Options", "WriteToWindow", &m_writeWindow, true); + m_writeWindowCB->SetValue(m_writeWindow); + for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i) + { + bool enable; + ini.Get("Logs", m_logManager->getShortName((LogTypes::LOG_TYPE)i), &enable, true); + + if (m_writeWindow && enable) + m_logManager->addListener((LogTypes::LOG_TYPE)i, this); + else + m_logManager->removeListener((LogTypes::LOG_TYPE)i, this); + + if (m_writeFile && enable) + m_logManager->addListener((LogTypes::LOG_TYPE)i, m_fileLog); + else + m_logManager->removeListener((LogTypes::LOG_TYPE)i, m_fileLog); + + if (m_writeConsole && enable) + m_logManager->addListener((LogTypes::LOG_TYPE)i, m_console); + else + m_logManager->removeListener((LogTypes::LOG_TYPE)i, m_console); + m_logManager->setLogLevel((LogTypes::LOG_TYPE)i, (LogTypes::LOG_LEVELS)(verbosity)); + } + UpdateChecks(); +} + +void CLogWindow::OnSubmit(wxCommandEvent& WXUNUSED (event)) +{ + Console_Submit(m_cmdline->GetValue().To8BitData()); + m_cmdline->SetValue(wxEmptyString); + NotifyUpdate(); +} + +void CLogWindow::OnClear(wxCommandEvent& WXUNUSED (event)) +{ + m_log->Clear(); + + m_logSection.Enter(); + int msgQueueSize = (int)msgQueue.size(); + for (int i = 0; i < msgQueueSize; i++) + msgQueue.pop(); + m_logSection.Leave(); + + m_console->ClearScreen(); + NOTICE_LOG(CONSOLE, "Console cleared"); + NotifyUpdate(); +} + +// Enable or disable all boxes for the current verbosity level and save the changes. +void CLogWindow::OnToggleAll(wxCommandEvent& WXUNUSED (event)) +{ + static bool enableAll = false; + for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i) + { + ToggleLog(i, enableAll); + } + + SaveSettings(); + enableAll = !enableAll; +} + +// Append checkboxes and update checked groups. +void CLogWindow::UpdateChecks() +{ + // This is only run once to append checkboxes to the wxCheckListBox. + if (m_checks->GetCount() == 0) + { + // [F|RES] hide the window while we fill it... wxwidgets gets trouble + // if you don't do it (at least the win version) + m_checks->Freeze(); + + for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; i++) + { + m_checks->Append(wxString::FromAscii(m_logManager->getFullName( (LogTypes::LOG_TYPE)i ))); + } + m_checks->Thaw(); + } + + m_checks->Freeze(); + for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; i++) + { + m_checks->Check(i, + m_logManager->isListener((LogTypes::LOG_TYPE)i, this) || + m_logManager->isListener((LogTypes::LOG_TYPE)i, m_console) || + m_logManager->isListener((LogTypes::LOG_TYPE)i, m_fileLog)); + } + m_checks->Thaw(); +} + +// When an option is changed, save the change +void CLogWindow::OnOptionsCheck(wxCommandEvent& event) +{ + switch (event.GetId()) + { + case IDM_VERBOSITY: + { + // get selection + int v = m_verbosity->GetSelection() + 1; + for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; i++) + { + m_logManager->setLogLevel((LogTypes::LOG_TYPE)i, (LogTypes::LOG_LEVELS)v); + } + } + break; + + case IDM_WRITEFILE: + for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i) + { + m_writeFile = event.IsChecked(); + if (m_checks->IsChecked(i)) + { + if (m_writeFile) + m_logManager->addListener((LogTypes::LOG_TYPE)i, m_fileLog); + else + m_logManager->removeListener((LogTypes::LOG_TYPE)i, m_fileLog); + } + } + break; + + case IDM_WRITEWINDOW: + for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i) + { + m_writeWindow = event.IsChecked(); + if (m_checks->IsChecked(i)) + { + if (m_writeWindow) + m_logManager->addListener((LogTypes::LOG_TYPE)i, this); + else + m_logManager->removeListener((LogTypes::LOG_TYPE)i, this); + } + } + break; + + case IDM_WRITECONSOLE: + for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i) + { + m_writeConsole = event.IsChecked(); + if (m_checks->IsChecked(i)) + { + if (m_writeConsole) + m_logManager->addListener((LogTypes::LOG_TYPE)i, m_console); + else + m_logManager->removeListener((LogTypes::LOG_TYPE)i, m_console); + } + } + if (m_writeConsole && !m_console->IsOpen()) + wxGetApp().GetCFrame()->ToggleConsole(true); + else if (!m_writeConsole && m_console->IsOpen()) + wxGetApp().GetCFrame()->ToggleConsole(false); + break; + } + SaveSettings(); +} + +// When a checkbox is changed +void CLogWindow::OnLogCheck(wxCommandEvent& event) +{ + int i = event.GetInt(); + ToggleLog(i, m_checks->IsChecked(i)); + + SaveSettings(); +} + +void CLogWindow::ToggleLog(int _logType, bool enable) +{ + LogTypes::LOG_TYPE logType = (LogTypes::LOG_TYPE)_logType; + + m_checks->Check(_logType, enable); + + m_logManager->setEnable(logType, enable); + + if (enable) + { + if (m_writeWindow) + m_logManager->addListener(logType, this); + if (m_writeFile) + m_logManager->addListener(logType, m_fileLog); + if (m_writeConsole) + m_logManager->addListener(logType, m_console); + } + else + { + m_logManager->removeListener(logType, this); + m_logManager->removeListener(logType, m_fileLog); + m_logManager->removeListener(logType, m_console); + } +} + +void CLogWindow::OnLogTimer(wxTimerEvent& WXUNUSED(event)) +{ + UpdateLog(); +} + +void CLogWindow::NotifyUpdate() +{ + UpdateChecks(); + //UpdateLog(); +} + +void CLogWindow::UpdateLog() +{ + m_logTimer->Stop(); + wxString collected_text; + + m_logSection.Enter(); + // rough estimate + collected_text.reserve(100 * msgQueue.size()); + int msgQueueSize = (int)msgQueue.size(); + for (int i = 0; i < msgQueueSize; i++) + { +#ifndef _WIN32 + // FIXME This looks horrible on windows: SetForegroundColour changes + // ALL text in the control, and SetDefaultStyle doesn't work at all + switch (msgQueue.front().first) + { + // red + case ERROR_LEVEL: + m_log->SetForegroundColour(*wxRED); + break; + // yellow + case WARNING_LEVEL: + m_log->SetForegroundColour(wxColour(255, 255, 0)); + break; + // green + case NOTICE_LEVEL: + m_log->SetForegroundColour(*wxGREEN); + break; + // cyan + case INFO_LEVEL: + m_log->SetForegroundColour(*wxCYAN); + break; + // light gray + case DEBUG_LEVEL: + m_log->SetForegroundColour(wxColour(211, 211, 211)); + break; + // white + default: + m_log->SetForegroundColour(*wxWHITE); + break; + } +#endif + collected_text.Append(msgQueue.front().second); + msgQueue.pop(); + } + m_logSection.Leave(); + + if (collected_text.size()) { + m_log->AppendText(collected_text); + } + m_logTimer->Start(UPDATETIME); +} + +void CLogWindow::Log(LogTypes::LOG_LEVELS level, const char *text) +{ + m_logSection.Enter(); + if (msgQueue.size() >= 100) + msgQueue.pop(); + msgQueue.push(std::pair((u8)level, wxString::FromAscii(text))); + m_logSection.Leave(); +} diff --git a/Source/Core/DolphinWX/Src/LogWindow.h b/Source/Core/DolphinWX/Src/LogWindow.h new file mode 100644 index 0000000000..1bb5403116 --- /dev/null +++ b/Source/Core/DolphinWX/Src/LogWindow.h @@ -0,0 +1,90 @@ +// Copyright (C) 2003 Dolphin Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official SVN repository and contact information can be found at +// http://code.google.com/p/dolphin-emu/ + +#ifndef LOGWINDOW_H_ +#define LOGWINDOW_H_ +#include "Main.h" // for wxGetApp +#include "LogManager.h" +#include "IniFile.h" +#include "Thread.h" +#include + +enum +{ + IDM_LOG, + IDM_CLEARLOG, + IDM_LOGCHECKS, + IDM_OPTIONS, + IDM_TOGGLEALL, + IDM_WRITEFILE, + IDM_WRITECONSOLE, + IDM_WRITEWINDOW, + IDTM_UPDATELOG, + IDM_VERBOSITY, + IDM_SUBMITCMD +}; + +class wxTextCtrl; +class wxCheckListBox; +class wxString; + +// Uses multiple inheritance - only sane because LogListener is a pure virtual interface. +class CLogWindow : public wxDialog, LogListener +{ +public: + CLogWindow(wxWindow* parent); + ~CLogWindow(); + void NotifyUpdate(); + + void SaveSettings(); + void LoadSettings(); + void Log(LogTypes::LOG_LEVELS, const char *text); + +private: + wxTextCtrl *m_log, *m_cmdline; + bool m_writeFile, m_writeConsole, m_writeWindow; + wxCheckBox *m_writeFileCB, *m_writeConsoleCB, *m_writeWindowCB; + wxTimer *m_logTimer; + wxCheckListBox* m_checks; + wxRadioBox *m_verbosity; + FileLogListener *m_fileLog; + ConsoleListener *m_console; + LogManager *m_logManager; + std::queue > msgQueue; + + Common::CriticalSection m_logSection; + + DECLARE_EVENT_TABLE() + + void CreateGUIControls(); + void OnClose(wxCloseEvent& event); + void OnSubmit(wxCommandEvent& event); + void OnOptionsCheck(wxCommandEvent& event); + void OnLogCheck(wxCommandEvent& event); + void OnClear(wxCommandEvent& event); + void OnToggleAll(wxCommandEvent& event); + void OnLogTimer(wxTimerEvent& WXUNUSED(event)); + + void ToggleLog(int _logType, bool enable); + void UpdateChecks(); + void UpdateLog(); + + // LogListener + const char *getName() const { return "LogWindow"; } +}; + +#endif /*LOGWINDOW_H_*/ diff --git a/Source/Core/DolphinWX/Src/Main.cpp b/Source/Core/DolphinWX/Src/Main.cpp index 8707651069..f7553755ab 100644 --- a/Source/Core/DolphinWX/Src/Main.cpp +++ b/Source/Core/DolphinWX/Src/Main.cpp @@ -36,7 +36,7 @@ #include "Main.h" #include "ConfigManager.h" #include "CodeWindow.h" -#include "LogManager.h" +#include "LogWindow.h" #include "JitWindow.h" #include "ExtendedTrace.h" #include "BootManager.h" @@ -89,6 +89,7 @@ bool DolphinApp::OnInit() NOTICE_LOG(BOOT, "Starting application"); // Declarations and definitions bool UseDebugger = false; + bool UseLogger = false; bool LoadElf = false; wxString ElfFile; @@ -261,6 +262,7 @@ bool DolphinApp::OnInit() } UseDebugger = parser.Found(_T("debugger")); + UseLogger = parser.Found(_T("logger")); LoadElf = parser.Found(_T("elf"), &ElfFile); if( LoadElf && ElfFile == wxEmptyString ) @@ -293,14 +295,15 @@ bool DolphinApp::OnInit() ini.Get("MainWindow", "w", &w, 800); ini.Get("MainWindow", "h", &h, 600); + UseDebugger = true; if (UseDebugger) { - main_frame = new CFrame((wxFrame*) NULL, wxID_ANY, wxString::FromAscii(title), + main_frame = new CFrame(UseLogger, (wxFrame*) NULL, wxID_ANY, wxString::FromAscii(title), wxPoint(x, y), wxSize(w, h), true); } else { - main_frame = new CFrame((wxFrame*) NULL, wxID_ANY, wxString::FromAscii(title), + main_frame = new CFrame(UseLogger, (wxFrame*) NULL, wxID_ANY, wxString::FromAscii(title), wxPoint(100, 100), wxSize(800, 600)); } diff --git a/Source/Core/DolphinWX/Src/SConscript b/Source/Core/DolphinWX/Src/SConscript index eab6201a69..e1aaee59e8 100644 --- a/Source/Core/DolphinWX/Src/SConscript +++ b/Source/Core/DolphinWX/Src/SConscript @@ -27,6 +27,7 @@ if wxenv['HAVE_WX']: 'ARCodeAddEdit.cpp', 'ConfigMain.cpp', 'Frame.cpp', + 'LogWindow.cpp', 'FrameTools.cpp', 'GameListCtrl.cpp', 'Globals.cpp',