2009-08-31 23:09:50 +00:00
|
|
|
// 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 "LogWindow.h"
|
2010-01-19 19:28:27 +00:00
|
|
|
#include "ConsoleListener.h"
|
2009-08-31 23:09:50 +00:00
|
|
|
#include "Console.h"
|
2010-08-03 03:20:44 +00:00
|
|
|
#include "IniFile.h"
|
2010-02-02 21:56:29 +00:00
|
|
|
#include "FileUtil.h"
|
2011-02-13 06:06:32 +00:00
|
|
|
#include "Debugger/DebuggerUIUtil.h"
|
2011-01-20 06:05:52 +00:00
|
|
|
#include <wx/fontmap.h>
|
2010-01-19 19:28:27 +00:00
|
|
|
|
2009-09-01 02:41:48 +00:00
|
|
|
// Milliseconds between msgQueue flushes to wxTextCtrl
|
2009-08-31 23:09:50 +00:00
|
|
|
#define UPDATETIME 200
|
|
|
|
|
2009-09-07 21:37:27 +00:00
|
|
|
BEGIN_EVENT_TABLE(CLogWindow, wxPanel)
|
2009-08-31 23:09:50 +00:00
|
|
|
EVT_CLOSE(CLogWindow::OnClose)
|
|
|
|
EVT_TEXT_ENTER(IDM_SUBMITCMD, CLogWindow::OnSubmit)
|
|
|
|
EVT_BUTTON(IDM_CLEARLOG, CLogWindow::OnClear)
|
2011-02-18 12:34:24 +00:00
|
|
|
EVT_CHOICE(IDM_FONT, CLogWindow::OnFontChange)
|
|
|
|
EVT_CHECKBOX(IDM_WRAPLINE, CLogWindow::OnWrapLineCheck)
|
2009-08-31 23:09:50 +00:00
|
|
|
EVT_TIMER(IDTM_UPDATELOG, CLogWindow::OnLogTimer)
|
2010-07-31 14:14:01 +00:00
|
|
|
EVT_SIZE(CLogWindow::OnSize)
|
2009-08-31 23:09:50 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2010-07-22 02:05:28 +00:00
|
|
|
CLogWindow::CLogWindow(CFrame *parent, wxWindowID id, const wxPoint& pos,
|
|
|
|
const wxSize& size, long style, const wxString& name)
|
|
|
|
: wxPanel(parent, id, pos, size, style, name)
|
2010-07-27 22:12:19 +00:00
|
|
|
, x(0), y(0), winpos(0)
|
|
|
|
, Parent(parent) , m_LogAccess(true)
|
2010-03-07 22:48:37 +00:00
|
|
|
, m_Log(NULL), m_cmdline(NULL), m_FontChoice(NULL)
|
|
|
|
, m_LogSection(1)
|
2011-02-19 22:56:51 +00:00
|
|
|
, m_SJISConv(wxT(""))
|
2011-01-20 06:05:52 +00:00
|
|
|
{
|
2011-01-27 23:59:12 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
static bool validCP932 = ::IsValidCodePage(932) != 0;
|
|
|
|
if (validCP932)
|
|
|
|
{
|
|
|
|
m_SJISConv = wxCSConv(wxFontMapper::GetEncodingName(wxFONTENCODING_SHIFT_JIS));
|
|
|
|
}
|
2011-02-03 06:01:34 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
WARN_LOG(COMMON, "Cannot Convert from Charset Windows Japanese cp 932");
|
2011-02-19 22:56:51 +00:00
|
|
|
m_SJISConv = *(wxCSConv*)wxConvCurrent;
|
2011-02-03 06:01:34 +00:00
|
|
|
}
|
2011-01-27 23:59:12 +00:00
|
|
|
#else
|
|
|
|
m_SJISConv = wxCSConv(wxFontMapper::GetEncodingName(wxFONTENCODING_EUC_JP));
|
|
|
|
#endif
|
2011-01-20 06:05:52 +00:00
|
|
|
|
2009-09-02 12:09:51 +00:00
|
|
|
m_LogManager = LogManager::GetInstance();
|
2010-12-14 17:52:01 +00:00
|
|
|
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
|
|
|
|
m_LogManager->addListener((LogTypes::LOG_TYPE)i, this);
|
2009-09-02 12:09:51 +00:00
|
|
|
m_fileLog = m_LogManager->getFileListener();
|
|
|
|
m_console = m_LogManager->getConsoleListener();
|
2009-08-31 23:09:50 +00:00
|
|
|
|
|
|
|
CreateGUIControls();
|
|
|
|
|
|
|
|
LoadSettings();
|
2010-08-03 03:20:44 +00:00
|
|
|
|
2011-02-19 04:43:51 +00:00
|
|
|
m_WrapLine->SetValue(m_bWrapLines);
|
|
|
|
ToggleWrapLine(m_bWrapLines);
|
|
|
|
|
2010-08-03 03:20:44 +00:00
|
|
|
m_LogTimer = new wxTimer(this, IDTM_UPDATELOG);
|
|
|
|
m_LogTimer->Start(UPDATETIME);
|
2009-08-31 23:09:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CLogWindow::CreateGUIControls()
|
|
|
|
{
|
2009-09-02 12:09:51 +00:00
|
|
|
// Font
|
2010-08-03 03:20:44 +00:00
|
|
|
m_FontChoice = new wxChoice(this, IDM_FONT,
|
|
|
|
wxDefaultPosition, wxDefaultSize, 0, NULL, 0, wxDefaultValidator);
|
2011-01-05 04:35:46 +00:00
|
|
|
m_FontChoice->Append(_("Default font"));
|
|
|
|
m_FontChoice->Append(_("Monospaced font"));
|
|
|
|
m_FontChoice->Append(_("Selected font"));
|
2009-09-02 12:09:51 +00:00
|
|
|
m_FontChoice->SetSelection(0);
|
2010-07-27 22:12:19 +00:00
|
|
|
DefaultFont = GetFont();
|
2011-01-06 13:57:46 +00:00
|
|
|
MonoSpaceFont.SetNativeFontInfoUserDesc(_T("lucida console windows-1252"));
|
2010-08-03 03:20:44 +00:00
|
|
|
LogFont.push_back(DefaultFont);
|
|
|
|
LogFont.push_back(MonoSpaceFont);
|
|
|
|
LogFont.push_back(DebuggerFont);
|
2009-09-02 12:09:51 +00:00
|
|
|
|
2011-02-19 04:43:51 +00:00
|
|
|
m_WrapLine = new wxCheckBox(this, IDM_WRAPLINE, _("Word Wrap"));
|
2009-08-31 23:09:50 +00:00
|
|
|
|
2009-09-02 12:09:51 +00:00
|
|
|
// Log viewer and submit row
|
|
|
|
m_Log = CreateTextCtrl(this, IDM_LOG, wxTE_RICH | wxTE_MULTILINE | wxTE_READONLY | wxTE_DONTWRAP);
|
2009-08-31 23:09:50 +00:00
|
|
|
m_cmdline = new wxTextCtrl(this, IDM_SUBMITCMD, wxEmptyString, wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxTE_PROCESS_ENTER | wxTE_PROCESS_TAB);
|
|
|
|
|
2009-09-01 07:32:07 +00:00
|
|
|
// Sizers
|
2011-02-18 12:34:24 +00:00
|
|
|
wxBoxSizer *sTop = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
sTop->Add(new wxButton(this, IDM_CLEARLOG, _("Clear"),
|
|
|
|
wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT));
|
|
|
|
sTop->Add(m_FontChoice, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 3);
|
|
|
|
sTop->Add(m_WrapLine, 0, wxALIGN_CENTER_VERTICAL);
|
2009-09-01 07:32:07 +00:00
|
|
|
|
2011-02-18 12:34:24 +00:00
|
|
|
sBottom = new wxBoxSizer(wxVERTICAL);
|
2009-09-02 12:09:51 +00:00
|
|
|
PopulateRight();
|
2010-07-27 22:12:19 +00:00
|
|
|
|
2011-02-18 12:34:24 +00:00
|
|
|
wxBoxSizer *sMain = new wxBoxSizer(wxVERTICAL);
|
|
|
|
sMain->Add(sTop, 0, wxEXPAND);
|
|
|
|
sMain->Add(sBottom, 1, wxEXPAND);
|
|
|
|
SetSizer(sMain);
|
2009-08-31 23:09:50 +00:00
|
|
|
|
|
|
|
m_cmdline->SetFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
CLogWindow::~CLogWindow()
|
|
|
|
{
|
2010-12-14 17:52:01 +00:00
|
|
|
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
|
2009-08-31 23:09:50 +00:00
|
|
|
{
|
2010-12-14 17:52:01 +00:00
|
|
|
m_LogManager->removeListener((LogTypes::LOG_TYPE)i, this);
|
2009-08-31 23:09:50 +00:00
|
|
|
}
|
2009-09-02 12:09:51 +00:00
|
|
|
m_LogTimer->Stop();
|
|
|
|
delete m_LogTimer;
|
2009-08-31 23:09:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CLogWindow::OnClose(wxCloseEvent& event)
|
|
|
|
{
|
2010-03-18 14:34:37 +00:00
|
|
|
SaveSettings();
|
2009-08-31 23:09:50 +00:00
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
2010-07-31 14:14:01 +00:00
|
|
|
void CLogWindow::OnSize(wxSizeEvent& event)
|
|
|
|
{
|
|
|
|
if (!Parent->g_pCodeWindow &&
|
2011-01-06 13:57:46 +00:00
|
|
|
Parent->m_Mgr->GetPane(wxT("Pane 1")).IsShown())
|
2010-07-31 14:14:01 +00:00
|
|
|
{
|
2011-01-06 13:57:46 +00:00
|
|
|
x = Parent->m_Mgr->GetPane(wxT("Pane 1")).rect.GetWidth();
|
|
|
|
y = Parent->m_Mgr->GetPane(wxT("Pane 1")).rect.GetHeight();
|
|
|
|
winpos = Parent->m_Mgr->GetPane(wxT("Pane 1")).dock_direction;
|
2010-07-31 14:14:01 +00:00
|
|
|
}
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
2009-08-31 23:09:50 +00:00
|
|
|
void CLogWindow::SaveSettings()
|
|
|
|
{
|
|
|
|
IniFile ini;
|
2010-07-31 14:14:01 +00:00
|
|
|
ini.Load(File::GetUserPath(F_LOGGERCONFIG_IDX));
|
|
|
|
|
2010-07-27 22:12:19 +00:00
|
|
|
if (!Parent->g_pCodeWindow)
|
|
|
|
{
|
2011-01-06 13:57:46 +00:00
|
|
|
ini.Set("LogWindow", "x", x);
|
|
|
|
ini.Set("LogWindow", "y", y);
|
|
|
|
ini.Set("LogWindow", "pos", winpos);
|
2010-07-27 22:12:19 +00:00
|
|
|
}
|
2010-06-03 18:05:08 +00:00
|
|
|
ini.Set("Options", "Font", m_FontChoice->GetSelection());
|
2011-02-19 04:43:51 +00:00
|
|
|
ini.Set("Options", "WrapLines", m_bWrapLines);
|
2010-02-02 21:56:29 +00:00
|
|
|
ini.Save(File::GetUserPath(F_LOGGERCONFIG_IDX));
|
2009-08-31 23:09:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CLogWindow::LoadSettings()
|
|
|
|
{
|
|
|
|
IniFile ini;
|
2010-02-02 21:56:29 +00:00
|
|
|
ini.Load(File::GetUserPath(F_LOGGERCONFIG_IDX));
|
2010-07-27 22:12:19 +00:00
|
|
|
|
|
|
|
ini.Get("LogWindow", "x", &x, Parent->GetSize().GetX() / 2);
|
|
|
|
ini.Get("LogWindow", "y", &y, Parent->GetSize().GetY());
|
|
|
|
ini.Get("LogWindow", "pos", &winpos, wxAUI_DOCK_RIGHT);
|
|
|
|
|
2009-09-15 21:35:32 +00:00
|
|
|
int verbosity,font;
|
2010-06-03 18:05:08 +00:00
|
|
|
ini.Get("Options", "Verbosity", &verbosity, 0);
|
2009-08-31 23:09:50 +00:00
|
|
|
if (verbosity < 1) verbosity = 1;
|
2009-09-02 12:09:51 +00:00
|
|
|
if (verbosity > MAX_LOGLEVEL) verbosity = MAX_LOGLEVEL;
|
2011-02-18 12:34:24 +00:00
|
|
|
|
2010-06-03 18:05:08 +00:00
|
|
|
ini.Get("Options", "Font", &font, 0);
|
2009-09-03 22:52:58 +00:00
|
|
|
m_FontChoice->SetSelection(font);
|
2010-08-03 03:20:44 +00:00
|
|
|
if (m_FontChoice->GetSelection() < (int)LogFont.size())
|
|
|
|
m_Log->SetDefaultStyle(wxTextAttr(wxNullColour, wxNullColour, LogFont[m_FontChoice->GetSelection()]));
|
2011-02-18 12:34:24 +00:00
|
|
|
|
2011-02-19 04:43:51 +00:00
|
|
|
ini.Get("Options", "WrapLines", &m_bWrapLines, false);
|
|
|
|
|
2010-12-23 06:00:17 +00:00
|
|
|
ini.Get("Options", "WriteToFile", &m_writeFile, false);
|
2010-06-03 18:05:08 +00:00
|
|
|
ini.Get("Options", "WriteToConsole", &m_writeConsole, true);
|
|
|
|
ini.Get("Options", "WriteToWindow", &m_writeWindow, true);
|
2010-12-14 17:52:01 +00:00
|
|
|
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
|
2009-08-31 23:09:50 +00:00
|
|
|
{
|
|
|
|
bool enable;
|
2010-12-14 17:52:01 +00:00
|
|
|
ini.Get("Logs", m_LogManager->getShortName((LogTypes::LOG_TYPE)i), &enable, true);
|
2009-08-31 23:09:50 +00:00
|
|
|
|
|
|
|
if (m_writeWindow && enable)
|
2010-12-14 17:52:01 +00:00
|
|
|
m_LogManager->addListener((LogTypes::LOG_TYPE)i, this);
|
2009-08-31 23:09:50 +00:00
|
|
|
else
|
2010-12-14 17:52:01 +00:00
|
|
|
m_LogManager->removeListener((LogTypes::LOG_TYPE)i, this);
|
2009-08-31 23:09:50 +00:00
|
|
|
|
|
|
|
if (m_writeFile && enable)
|
2010-12-14 17:52:01 +00:00
|
|
|
m_LogManager->addListener((LogTypes::LOG_TYPE)i, m_fileLog);
|
2009-08-31 23:09:50 +00:00
|
|
|
else
|
2010-12-14 17:52:01 +00:00
|
|
|
m_LogManager->removeListener((LogTypes::LOG_TYPE)i, m_fileLog);
|
2009-08-31 23:09:50 +00:00
|
|
|
|
|
|
|
if (m_writeConsole && enable)
|
2010-12-14 17:52:01 +00:00
|
|
|
m_LogManager->addListener((LogTypes::LOG_TYPE)i, m_console);
|
2009-08-31 23:09:50 +00:00
|
|
|
else
|
2010-12-14 17:52:01 +00:00
|
|
|
m_LogManager->removeListener((LogTypes::LOG_TYPE)i, m_console);
|
|
|
|
m_LogManager->setLogLevel((LogTypes::LOG_TYPE)i, (LogTypes::LOG_LEVELS)(verbosity));
|
2009-08-31 23:09:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLogWindow::OnSubmit(wxCommandEvent& WXUNUSED (event))
|
|
|
|
{
|
2009-09-02 12:09:51 +00:00
|
|
|
if (!m_cmdline) return;
|
2009-08-31 23:09:50 +00:00
|
|
|
Console_Submit(m_cmdline->GetValue().To8BitData());
|
|
|
|
m_cmdline->SetValue(wxEmptyString);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CLogWindow::OnClear(wxCommandEvent& WXUNUSED (event))
|
|
|
|
{
|
2009-09-02 12:09:51 +00:00
|
|
|
m_Log->Clear();
|
2009-08-31 23:09:50 +00:00
|
|
|
|
2009-09-02 12:09:51 +00:00
|
|
|
m_LogSection.Enter();
|
2009-08-31 23:09:50 +00:00
|
|
|
int msgQueueSize = (int)msgQueue.size();
|
2010-07-27 22:12:19 +00:00
|
|
|
for (int i = 0; i < msgQueueSize; i++)
|
2009-08-31 23:09:50 +00:00
|
|
|
msgQueue.pop();
|
2009-09-02 12:09:51 +00:00
|
|
|
m_LogSection.Leave();
|
2009-11-14 17:08:32 +00:00
|
|
|
|
2009-08-31 23:09:50 +00:00
|
|
|
m_console->ClearScreen();
|
|
|
|
}
|
|
|
|
|
2009-09-02 12:09:51 +00:00
|
|
|
void CLogWindow::UnPopulateRight()
|
|
|
|
{
|
2011-02-18 12:34:24 +00:00
|
|
|
sBottom->Detach(m_Log);
|
|
|
|
sBottom->Detach(m_cmdline);
|
2009-09-02 12:09:51 +00:00
|
|
|
}
|
2011-02-18 12:34:24 +00:00
|
|
|
|
2009-09-02 12:09:51 +00:00
|
|
|
void CLogWindow::PopulateRight()
|
|
|
|
{
|
2011-02-18 12:34:24 +00:00
|
|
|
sBottom->Add(m_Log, 1, wxEXPAND | wxSHRINK);
|
|
|
|
sBottom->Add(m_cmdline, 0, wxEXPAND);
|
|
|
|
Layout();
|
2009-09-02 12:09:51 +00:00
|
|
|
}
|
|
|
|
|
2009-09-07 21:37:27 +00:00
|
|
|
wxTextCtrl* CLogWindow::CreateTextCtrl(wxPanel* parent, wxWindowID id, long Style)
|
2009-09-02 12:09:51 +00:00
|
|
|
{
|
2010-07-27 22:12:19 +00:00
|
|
|
wxTextCtrl* TC = new wxTextCtrl(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, Style);
|
2010-12-12 05:38:37 +00:00
|
|
|
#ifdef __APPLE__
|
2010-12-05 15:59:11 +00:00
|
|
|
TC->SetBackgroundColour(*wxLIGHT_GREY);
|
2010-12-12 05:38:37 +00:00
|
|
|
#else
|
|
|
|
TC->SetBackgroundColour(*wxBLACK);
|
|
|
|
#endif
|
2009-09-03 22:52:58 +00:00
|
|
|
if (m_FontChoice)
|
|
|
|
{
|
2010-08-03 03:20:44 +00:00
|
|
|
if (m_FontChoice->GetSelection() < (int)LogFont.size())
|
|
|
|
TC->SetDefaultStyle(wxTextAttr(wxNullColour, wxNullColour, LogFont[m_FontChoice->GetSelection()]));
|
2009-09-03 22:52:58 +00:00
|
|
|
}
|
2009-09-02 12:09:51 +00:00
|
|
|
return TC;
|
|
|
|
}
|
|
|
|
|
2011-02-18 12:34:24 +00:00
|
|
|
void CLogWindow::OnFontChange(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
// Update selected font
|
|
|
|
LogFont[LogFont.size()-1] = DebuggerFont;
|
|
|
|
m_Log->SetStyle(0, m_Log->GetLastPosition(),
|
|
|
|
wxTextAttr(wxNullColour, wxNullColour, LogFont[event.GetSelection()]));
|
|
|
|
m_Log->SetDefaultStyle(wxTextAttr(wxNullColour, wxNullColour, LogFont[event.GetSelection()]));
|
|
|
|
|
|
|
|
SaveSettings();
|
|
|
|
}
|
|
|
|
|
2009-08-31 23:09:50 +00:00
|
|
|
// When an option is changed, save the change
|
2011-02-18 12:34:24 +00:00
|
|
|
void CLogWindow::OnWrapLineCheck(wxCommandEvent& event)
|
2009-08-31 23:09:50 +00:00
|
|
|
{
|
2011-02-19 04:43:51 +00:00
|
|
|
m_bWrapLines ^= true;
|
|
|
|
ToggleWrapLine(event.IsChecked());
|
|
|
|
SaveSettings();
|
|
|
|
}
|
2009-09-02 12:09:51 +00:00
|
|
|
|
2011-02-19 04:43:51 +00:00
|
|
|
void CLogWindow::ToggleWrapLine(bool word_wrap)
|
|
|
|
{
|
2010-08-03 03:20:44 +00:00
|
|
|
#ifdef __WXGTK__
|
2011-02-18 12:34:24 +00:00
|
|
|
m_Log->SetWindowStyleFlag(m_Log->GetWindowStyleFlag() ^ (wxTE_WORDWRAP | wxTE_DONTWRAP));
|
2010-08-03 03:20:44 +00:00
|
|
|
#else
|
2011-02-19 04:43:51 +00:00
|
|
|
wxString Text;
|
2011-02-18 12:34:24 +00:00
|
|
|
// Unfortunately wrapping styles can only be changed dynamically with wxGTK
|
|
|
|
// Notice: To retain the colors when changing word wrapping we need to
|
|
|
|
// loop through every letter with GetStyle and then reapply them letter by letter
|
|
|
|
// Prevent m_Log access while it's being destroyed
|
|
|
|
m_LogAccess = false;
|
|
|
|
UnPopulateRight();
|
|
|
|
Text = m_Log->GetValue();
|
|
|
|
m_Log->Destroy();
|
2011-02-19 04:43:51 +00:00
|
|
|
if (word_wrap)
|
2011-02-18 12:34:24 +00:00
|
|
|
m_Log = CreateTextCtrl(this, IDM_LOG,
|
|
|
|
wxTE_RICH | wxTE_MULTILINE | wxTE_READONLY | wxTE_WORDWRAP);
|
|
|
|
else
|
|
|
|
m_Log = CreateTextCtrl(this, IDM_LOG,
|
|
|
|
wxTE_RICH | wxTE_MULTILINE | wxTE_READONLY | wxTE_DONTWRAP);
|
|
|
|
m_Log->SetDefaultStyle(wxTextAttr(*wxWHITE));
|
|
|
|
m_Log->AppendText(Text);
|
|
|
|
PopulateRight();
|
|
|
|
m_LogAccess = true;
|
2010-08-03 03:20:44 +00:00
|
|
|
#endif
|
2009-08-31 23:09:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CLogWindow::OnLogTimer(wxTimerEvent& WXUNUSED(event))
|
|
|
|
{
|
2009-09-02 12:09:51 +00:00
|
|
|
if (!m_LogAccess) return;
|
|
|
|
|
2009-08-31 23:09:50 +00:00
|
|
|
UpdateLog();
|
2010-08-03 03:20:44 +00:00
|
|
|
// Scroll to the last line
|
2009-09-29 22:32:53 +00:00
|
|
|
if (msgQueue.size() > 0)
|
2009-09-03 20:00:09 +00:00
|
|
|
{
|
|
|
|
m_Log->ScrollLines(1);
|
|
|
|
m_Log->ShowPosition( m_Log->GetLastPosition() );
|
|
|
|
}
|
2009-08-31 23:09:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CLogWindow::UpdateLog()
|
|
|
|
{
|
2009-09-02 12:09:51 +00:00
|
|
|
if (!m_LogAccess) return;
|
|
|
|
if (!m_Log) return;
|
|
|
|
|
|
|
|
m_LogTimer->Stop();
|
2009-08-31 23:09:50 +00:00
|
|
|
|
2009-09-02 12:09:51 +00:00
|
|
|
m_LogSection.Enter();
|
2009-08-31 23:09:50 +00:00
|
|
|
int msgQueueSize = (int)msgQueue.size();
|
|
|
|
for (int i = 0; i < msgQueueSize; i++)
|
|
|
|
{
|
2010-07-27 22:12:19 +00:00
|
|
|
switch (msgQueue.front().first)
|
|
|
|
{
|
2011-01-05 04:35:46 +00:00
|
|
|
|
2010-07-27 22:12:19 +00:00
|
|
|
case ERROR_LEVEL:
|
|
|
|
m_Log->SetDefaultStyle(wxTextAttr(*wxRED));
|
|
|
|
break;
|
2011-01-05 04:35:46 +00:00
|
|
|
|
2010-07-27 22:12:19 +00:00
|
|
|
case WARNING_LEVEL:
|
2011-01-05 04:35:46 +00:00
|
|
|
m_Log->SetDefaultStyle(wxTextAttr(wxColour(255, 255, 0))); // YELLOW
|
2010-07-27 22:12:19 +00:00
|
|
|
break;
|
2011-01-05 04:35:46 +00:00
|
|
|
|
2010-07-27 22:12:19 +00:00
|
|
|
case NOTICE_LEVEL:
|
|
|
|
m_Log->SetDefaultStyle(wxTextAttr(*wxGREEN));
|
|
|
|
break;
|
2011-01-05 04:35:46 +00:00
|
|
|
|
2010-07-27 22:12:19 +00:00
|
|
|
case INFO_LEVEL:
|
|
|
|
m_Log->SetDefaultStyle(wxTextAttr(*wxCYAN));
|
|
|
|
break;
|
2011-01-05 04:35:46 +00:00
|
|
|
|
2010-07-27 22:12:19 +00:00
|
|
|
case DEBUG_LEVEL:
|
2011-01-05 04:35:46 +00:00
|
|
|
m_Log->SetDefaultStyle(wxTextAttr(*wxLIGHT_GREY));
|
2010-07-27 22:12:19 +00:00
|
|
|
break;
|
2011-01-05 04:35:46 +00:00
|
|
|
|
2010-07-27 22:12:19 +00:00
|
|
|
default:
|
|
|
|
m_Log->SetDefaultStyle(wxTextAttr(*wxWHITE));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (msgQueue.front().second.size())
|
2009-09-02 12:09:51 +00:00
|
|
|
{
|
|
|
|
int j = m_Log->GetLastPosition();
|
|
|
|
m_Log->AppendText(msgQueue.front().second);
|
|
|
|
// White timestamp
|
|
|
|
m_Log->SetStyle(j, j + 9, wxTextAttr(*wxWHITE));
|
|
|
|
}
|
2010-07-27 22:12:19 +00:00
|
|
|
msgQueue.pop();
|
2009-08-31 23:09:50 +00:00
|
|
|
}
|
2009-09-02 12:09:51 +00:00
|
|
|
m_LogSection.Leave();
|
2010-08-03 03:20:44 +00:00
|
|
|
|
2009-09-02 12:09:51 +00:00
|
|
|
m_LogTimer->Start(UPDATETIME);
|
2009-08-31 23:09:50 +00:00
|
|
|
}
|
|
|
|
|
2010-12-14 17:52:01 +00:00
|
|
|
void CLogWindow::Log(LogTypes::LOG_LEVELS level, const char *text)
|
2009-08-31 23:09:50 +00:00
|
|
|
{
|
2009-09-02 12:09:51 +00:00
|
|
|
m_LogSection.Enter();
|
2009-11-14 17:08:32 +00:00
|
|
|
if (msgQueue.size() >= 100)
|
|
|
|
msgQueue.pop();
|
2011-01-27 23:59:12 +00:00
|
|
|
msgQueue.push(std::pair<u8, wxString>((u8)level, wxString(text, m_SJISConv)));
|
2009-09-02 12:09:51 +00:00
|
|
|
m_LogSection.Leave();
|
2009-08-31 23:09:50 +00:00
|
|
|
}
|