From 2a88c4f2a8ac84269f53e4316ed47f4c9133bb09 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Sat, 27 Aug 2016 13:01:58 +0200 Subject: [PATCH] Event sources and toolbar management now more dynamic --- EventMonitor/ETWLog.cpp | 47 ++++++---- EventMonitor/ETWLog.h | 54 ++++++++++-- EventMonitor/Frame.cpp | 190 +++++++++++++++++----------------------- EventMonitor/Frame.h | 14 +-- EventMonitor/StdAfx.h | 1 + 5 files changed, 164 insertions(+), 142 deletions(-) diff --git a/EventMonitor/ETWLog.cpp b/EventMonitor/ETWLog.cpp index 6f41a41..77e99ab 100644 --- a/EventMonitor/ETWLog.cpp +++ b/EventMonitor/ETWLog.cpp @@ -158,11 +158,7 @@ const GUID wxETWListCtrl::s_provider_schannel = { 0x1F678132, 0x5938, 0x4686, { wxETWListCtrl::wxETWListCtrl(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxValidator& validator, const wxString& name) : m_proc(NULL), - m_item_id(0), m_scroll_auto(true), - m_source_eaphost(false), - m_source_schannel(false), - m_source_product(true), m_level(TRACE_LEVEL_INFORMATION), m_rec_db(wxETWEVENT_RECORDS_MAX), m_rec_idx(wxETWEVENT_RECORDS_MAX), @@ -255,6 +251,7 @@ wxETWListCtrl::wxETWListCtrl(wxWindow *parent, wxWindowID id, const wxPoint& pos wxLogDebug(wxString::Format(_("Error enabling %s event provider (error %u)."), wxT(PRODUCT_NAME_STR)), ulResult); return; } + m_sources.insert(EAPMETHOD_TRACE_EVENT_PROVIDER); if ((ulResult = EnableTraceEx( &s_provider_eaphost, @@ -466,10 +463,8 @@ void wxETWListCtrl::RebuildItems() bool wxETWListCtrl::IsVisible(const EVENT_RECORD &rec) const { return - (m_source_product && IsEqualGUID(rec.EventHeader.ProviderId, EAPMETHOD_TRACE_EVENT_PROVIDER) || - m_source_eaphost && IsEqualGUID(rec.EventHeader.ProviderId, s_provider_eaphost ) || - m_source_schannel && IsEqualGUID(rec.EventHeader.ProviderId, s_provider_schannel )) && - rec.EventHeader.EventDescriptor.Level <= m_level; + m_sources.find(rec.EventHeader.ProviderId) != m_sources.end() && + rec.EventHeader.EventDescriptor.Level <= m_level; } @@ -711,11 +706,14 @@ void wxPersistentETWListCtrl::Save() const SaveValue(wxString::Format(wxT("Column%sWidth"), col.GetText().c_str()), col.GetWidth()); } - SaveValue(wxT("ScrollAuto" ), wnd->m_scroll_auto ); - SaveValue(wxT("SourceEapHost" ), wnd->m_source_eaphost ); - SaveValue(wxT("SourceSchannel"), wnd->m_source_schannel); - SaveValue(wxT("SourceProduct" ), wnd->m_source_product ); - SaveValue(wxT("Level" ), (int)wnd->m_level ); + SaveValue(wxT("ScrollAuto" ), wnd->m_scroll_auto); + + SaveValue(wxT("SourceCount"), (long)wnd->m_sources.size()); + long i = 0; + for (wxETWListCtrl::guidset::const_iterator src = wnd->m_sources.cbegin(), src_end = wnd->m_sources.cend(); src != src_end; ++src, i++) + SaveValue(wxString::Format(wxT("Source%u"), i), tstring_guid(*src)); + + SaveValue(wxT("Level"), (int)wnd->m_level); } @@ -734,12 +732,25 @@ bool wxPersistentETWListCtrl::Restore() wnd->SetColumnWidth(i, width); } - int dummy_int; + RestoreValue(wxT("ScrollAuto"), &(wnd->m_scroll_auto)); - RestoreValue(wxT("ScrollAuto" ), &(wnd->m_scroll_auto )); - RestoreValue(wxT("SourceEapHost" ), &(wnd->m_source_eaphost )); - RestoreValue(wxT("SourceSchannel"), &(wnd->m_source_schannel)); - RestoreValue(wxT("SourceProduct" ), &(wnd->m_source_product )); + wnd->m_sources.clear(); + long n; + if (RestoreValue(wxT("SourceCount"), &n)) { + wxString guid_str; + for (long i = 0; i < n; i++) { + if (RestoreValue(wxString::Format(wxT("Source%u"), i), &guid_str)) { + GUID guid; + if (StringToGuid(guid_str.c_str(), &guid)) + wnd->m_sources.insert(guid); + } + } + } else { + // Insert our provider by default. + wnd->m_sources.insert(EAPMETHOD_TRACE_EVENT_PROVIDER); + } + + int dummy_int; if (RestoreValue(wxT("Level"), &dummy_int)) wnd->m_level = (UCHAR)std::min(std::max(dummy_int, TRACE_LEVEL_ERROR), TRACE_LEVEL_VERBOSE); diff --git a/EventMonitor/ETWLog.h b/EventMonitor/ETWLog.h index 77c1891..ffd9101 100644 --- a/EventMonitor/ETWLog.h +++ b/EventMonitor/ETWLog.h @@ -58,6 +58,7 @@ class wxPersistentETWListCtrl; #include #include +#include class wxETWEvent : public wxEvent @@ -110,6 +111,30 @@ protected: class wxETWListCtrl : public wxListCtrl { +protected: + /// + /// Functor for GUID comparison + /// + struct less_guid : public std::binary_function + { + bool operator()(const GUID &a, const GUID &b) const + { + if (a.Data1 < b.Data1) return true; + if (a.Data1 > b.Data1) return false; + if (a.Data2 < b.Data2) return true; + if (a.Data2 > b.Data2) return false; + if (a.Data3 < b.Data3) return true; + if (a.Data3 > b.Data3) return false; + if (memcmp(a.Data4, b.Data4, sizeof(a.Data4)) < 0) return true; + return false; + } + }; + + /// + /// A set of GUIDs + /// + typedef std::set guidset; + public: wxETWListCtrl( wxWindow *parent, @@ -121,7 +146,7 @@ public: const wxString &name = wxListCtrlNameStr); virtual ~wxETWListCtrl(); - bool IsEmpty() const { return m_rec_db.empty(); } + inline bool IsEmpty() const { return m_rec_db.empty(); } void CopySelected() const; void CopyAll() const; void ClearAll(); @@ -129,6 +154,27 @@ public: void SelectNone(); void RebuildItems(); + inline bool IsSourceEnabled(const GUID &guid) const + { + return m_sources.find(guid) != m_sources.end(); + } + + inline void EnableSource(const GUID &guid, bool enable = true) + { + guidset::iterator s = m_sources.find(guid); + if (enable) { + if (s == m_sources.end()) { + m_sources.insert(guid); + RebuildItems(); + } + } else { + if (s != m_sources.end()) { + m_sources.erase(s); + RebuildItems(); + } + } + } + friend class wxPersistentETWListCtrl; // Allow saving/restoring window state. protected: @@ -144,9 +190,6 @@ protected: public: bool m_scroll_auto; ///< Is autoscrolling enabled? - bool m_source_eaphost; ///< Shows EapHost messages - bool m_source_schannel; ///< Shows Schannel messages - bool m_source_product; ///< Shows native messages UCHAR m_level; ///< Shows messages up to this level of verboseness static const GUID s_provider_eaphost; ///< EapHost event provider ID @@ -155,7 +198,8 @@ public: protected: winstd::event_session m_session; ///< Event session wxEventTraceProcessorThread *m_proc; ///< Processor thread - long m_item_id; ///< Next free list item ID + + guidset m_sources; ///< Set of enabled sources wxListItemAttr m_item_attr[2][4]; ///< Current item attributes winstd::vector_queue m_rec_db; ///< Event record database diff --git a/EventMonitor/Frame.cpp b/EventMonitor/Frame.cpp index 32d3e36..6e9ce59 100644 --- a/EventMonitor/Frame.cpp +++ b/EventMonitor/Frame.cpp @@ -197,62 +197,62 @@ wxEventMonitorFrame::wxEventMonitorFrame(wxWindow* parent, wxWindowID id, const wxPersistentAuiManager(&m_mgr).Restore(); // Connect Events - this->Connect(wxID_EXIT , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnExit )); - this->Connect(wxID_COPY , wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnEditCopyUpdate )); - this->Connect(wxID_COPY , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnEditCopy )); - this->Connect(wxID_COPY_ALL , wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnEditCopyAllUpdate )); - this->Connect(wxID_COPY_ALL , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnEditCopyAll )); - this->Connect(wxID_CLEAR , wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnEditClearUpdate )); - this->Connect(wxID_CLEAR , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnEditClear )); - this->Connect(wxID_SELECT_ALL , wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnEditSelectAllUpdate )); - this->Connect(wxID_SELECT_ALL , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnEditSelectAll )); - this->Connect(wxID_SELECT_NONE , wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnEditSelectNoneUpdate )); - this->Connect(wxID_SELECT_NONE , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnEditSelectNone )); - this->Connect(wxID_VIEW_SCROLL_AUTO , wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnViewScrollUpdate )); - this->Connect(wxID_VIEW_SCROLL_AUTO , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnViewScroll )); - this->Connect(wxID_VIEW_SOURCE_EAPHOST , wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnViewSourceEapHostUpdate )); - this->Connect(wxID_VIEW_SOURCE_EAPHOST , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnViewSourceEapHost )); - this->Connect(wxID_VIEW_SOURCE_SCHANNEL, wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnViewSourceSchannelUpdate)); - this->Connect(wxID_VIEW_SOURCE_SCHANNEL, wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnViewSourceSchannel )); - this->Connect(wxID_VIEW_SOURCE_PRODUCT , wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnViewSourceProductUpdate )); - this->Connect(wxID_VIEW_SOURCE_PRODUCT , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnViewSourceProduct )); - this->Connect(wxID_VIEW_LEVEL_VERBOSE , wxID_VIEW_LEVEL_ERROR, wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnViewLevelUpdate )); - this->Connect(wxID_VIEW_LEVEL_VERBOSE , wxID_VIEW_LEVEL_ERROR, wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnViewLevel )); - this->Connect(wxID_VIEW_TOOLBAR_EDIT , wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnViewToolbarEditUpdate )); - this->Connect(wxID_VIEW_TOOLBAR_EDIT , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnViewToolbarEdit )); - this->Connect(wxID_VIEW_TOOLBAR_VIEW , wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnViewToolbarViewUpdate )); - this->Connect(wxID_VIEW_TOOLBAR_VIEW , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnViewToolbarView )); + this->Connect(wxID_EXIT , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnExit )); + this->Connect(wxID_COPY , wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnEditCopyUpdate )); + this->Connect(wxID_COPY , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnEditCopy )); + this->Connect(wxID_COPY_ALL , wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnEditCopyAllUpdate )); + this->Connect(wxID_COPY_ALL , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnEditCopyAll )); + this->Connect(wxID_CLEAR , wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnEditClearUpdate )); + this->Connect(wxID_CLEAR , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnEditClear )); + this->Connect(wxID_SELECT_ALL , wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnEditSelectAllUpdate )); + this->Connect(wxID_SELECT_ALL , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnEditSelectAll )); + this->Connect(wxID_SELECT_NONE , wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnEditSelectNoneUpdate)); + this->Connect(wxID_SELECT_NONE , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnEditSelectNone )); + this->Connect(wxID_VIEW_SCROLL_AUTO , wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnViewScrollUpdate )); + this->Connect(wxID_VIEW_SCROLL_AUTO , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnViewScroll )); + this->Connect(wxID_VIEW_SOURCE_EAPHOST , wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnViewSourceUpdate ), new wxObjectWithData(wxETWListCtrl::s_provider_eaphost )); + this->Connect(wxID_VIEW_SOURCE_EAPHOST , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnViewSource ), new wxObjectWithData(wxETWListCtrl::s_provider_eaphost )); + this->Connect(wxID_VIEW_SOURCE_SCHANNEL, wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnViewSourceUpdate ), new wxObjectWithData(wxETWListCtrl::s_provider_schannel)); + this->Connect(wxID_VIEW_SOURCE_SCHANNEL, wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnViewSource ), new wxObjectWithData(wxETWListCtrl::s_provider_schannel)); + this->Connect(wxID_VIEW_SOURCE_PRODUCT , wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnViewSourceUpdate ), new wxObjectWithData(EAPMETHOD_TRACE_EVENT_PROVIDER )); + this->Connect(wxID_VIEW_SOURCE_PRODUCT , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnViewSource ), new wxObjectWithData(EAPMETHOD_TRACE_EVENT_PROVIDER )); + this->Connect(wxID_VIEW_LEVEL_VERBOSE , wxID_VIEW_LEVEL_ERROR, wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnViewLevelUpdate )); + this->Connect(wxID_VIEW_LEVEL_VERBOSE , wxID_VIEW_LEVEL_ERROR, wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnViewLevel )); + this->Connect(wxID_VIEW_TOOLBAR_EDIT , wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnViewToolbarUpdate ), new wxObjectWithData(&m_mgr.GetPane(m_toolbarEdit))); + this->Connect(wxID_VIEW_TOOLBAR_EDIT , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnViewToolbar ), new wxObjectWithData(&m_mgr.GetPane(m_toolbarEdit))); + this->Connect(wxID_VIEW_TOOLBAR_VIEW , wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnViewToolbarUpdate ), new wxObjectWithData(&m_mgr.GetPane(m_toolbarView))); + this->Connect(wxID_VIEW_TOOLBAR_VIEW , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnViewToolbar ), new wxObjectWithData(&m_mgr.GetPane(m_toolbarView))); } wxEventMonitorFrame::~wxEventMonitorFrame() { // Disconnect Events - this->Disconnect(wxID_EXIT , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnExit )); - this->Disconnect(wxID_COPY , wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnEditCopyUpdate )); - this->Disconnect(wxID_COPY , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnEditCopy )); - this->Disconnect(wxID_COPY_ALL , wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnEditCopyAllUpdate )); - this->Disconnect(wxID_COPY_ALL , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnEditCopyAll )); - this->Disconnect(wxID_CLEAR , wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnEditClearUpdate )); - this->Disconnect(wxID_CLEAR , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnEditClear )); - this->Disconnect(wxID_SELECT_ALL , wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnEditSelectAllUpdate )); - this->Disconnect(wxID_SELECT_ALL , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnEditSelectAll )); - this->Disconnect(wxID_SELECT_NONE , wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnEditSelectNoneUpdate )); - this->Disconnect(wxID_SELECT_NONE , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnEditSelectNone )); - this->Disconnect(wxID_VIEW_SCROLL_AUTO , wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnViewScrollUpdate )); - this->Disconnect(wxID_VIEW_SCROLL_AUTO , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnViewScroll )); - this->Disconnect(wxID_VIEW_SOURCE_EAPHOST , wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnViewSourceEapHostUpdate )); - this->Disconnect(wxID_VIEW_SOURCE_EAPHOST , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnViewSourceEapHost )); - this->Disconnect(wxID_VIEW_SOURCE_SCHANNEL, wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnViewSourceSchannelUpdate)); - this->Disconnect(wxID_VIEW_SOURCE_SCHANNEL, wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnViewSourceSchannel )); - this->Disconnect(wxID_VIEW_SOURCE_PRODUCT , wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnViewSourceProductUpdate )); - this->Disconnect(wxID_VIEW_SOURCE_PRODUCT , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnViewSourceProduct )); - this->Disconnect(wxID_VIEW_LEVEL_VERBOSE , wxID_VIEW_LEVEL_ERROR, wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnViewLevelUpdate )); - this->Disconnect(wxID_VIEW_LEVEL_VERBOSE , wxID_VIEW_LEVEL_ERROR, wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnViewLevel )); - this->Disconnect(wxID_VIEW_TOOLBAR_EDIT , wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnViewToolbarEditUpdate )); - this->Disconnect(wxID_VIEW_TOOLBAR_EDIT , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnViewToolbarEdit )); - this->Disconnect(wxID_VIEW_TOOLBAR_VIEW , wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnViewToolbarViewUpdate )); - this->Disconnect(wxID_VIEW_TOOLBAR_VIEW , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnViewToolbarView )); + this->Disconnect(wxID_EXIT , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnExit )); + this->Disconnect(wxID_COPY , wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnEditCopyUpdate )); + this->Disconnect(wxID_COPY , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnEditCopy )); + this->Disconnect(wxID_COPY_ALL , wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnEditCopyAllUpdate )); + this->Disconnect(wxID_COPY_ALL , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnEditCopyAll )); + this->Disconnect(wxID_CLEAR , wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnEditClearUpdate )); + this->Disconnect(wxID_CLEAR , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnEditClear )); + this->Disconnect(wxID_SELECT_ALL , wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnEditSelectAllUpdate )); + this->Disconnect(wxID_SELECT_ALL , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnEditSelectAll )); + this->Disconnect(wxID_SELECT_NONE , wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnEditSelectNoneUpdate)); + this->Disconnect(wxID_SELECT_NONE , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnEditSelectNone )); + this->Disconnect(wxID_VIEW_SCROLL_AUTO , wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnViewScrollUpdate )); + this->Disconnect(wxID_VIEW_SCROLL_AUTO , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnViewScroll )); + this->Disconnect(wxID_VIEW_SOURCE_EAPHOST , wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnViewSourceUpdate )); + this->Disconnect(wxID_VIEW_SOURCE_EAPHOST , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnViewSource )); + this->Disconnect(wxID_VIEW_SOURCE_SCHANNEL, wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnViewSourceUpdate )); + this->Disconnect(wxID_VIEW_SOURCE_SCHANNEL, wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnViewSource )); + this->Disconnect(wxID_VIEW_SOURCE_PRODUCT , wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnViewSourceUpdate )); + this->Disconnect(wxID_VIEW_SOURCE_PRODUCT , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnViewSource )); + this->Disconnect(wxID_VIEW_LEVEL_VERBOSE , wxID_VIEW_LEVEL_ERROR, wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnViewLevelUpdate )); + this->Disconnect(wxID_VIEW_LEVEL_VERBOSE , wxID_VIEW_LEVEL_ERROR, wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnViewLevel )); + this->Disconnect(wxID_VIEW_TOOLBAR_EDIT , wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnViewToolbarUpdate )); + this->Disconnect(wxID_VIEW_TOOLBAR_EDIT , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnViewToolbar )); + this->Disconnect(wxID_VIEW_TOOLBAR_VIEW , wxEVT_UPDATE_UI, wxUpdateUIEventHandler(wxEventMonitorFrame::OnViewToolbarUpdate )); + this->Disconnect(wxID_VIEW_TOOLBAR_VIEW , wxEVT_MENU , wxCommandEventHandler (wxEventMonitorFrame::OnViewToolbar )); // Save wxAuiManager's state. wxPersistentAuiManager(&m_mgr).Save(); @@ -337,6 +337,7 @@ void wxEventMonitorFrame::OnViewScroll(wxCommandEvent& event) { m_panel->m_log->m_scroll_auto = event.IsChecked(); if (m_panel->m_log->m_scroll_auto) { + // Scroll to the last record. long count = m_panel->m_log->GetItemCount(); if (count) m_panel->m_log->EnsureVisible(count - 1); @@ -344,56 +345,31 @@ void wxEventMonitorFrame::OnViewScroll(wxCommandEvent& event) } -void wxEventMonitorFrame::OnViewSourceEapHostUpdate(wxUpdateUIEvent& event) +void wxEventMonitorFrame::OnViewSourceUpdate(wxUpdateUIEvent& event) { - event.Check(m_panel->m_log->m_source_eaphost); + wxObjectWithData *source = dynamic_cast*>(event.m_callbackUserData); + if (source) { + // Update GUI control according to event source state. + event.Check(m_panel->m_log->IsSourceEnabled(source->m_data)); + event.Enable(true); + } else + event.Enable(false); } -void wxEventMonitorFrame::OnViewSourceEapHost(wxCommandEvent& event) +void wxEventMonitorFrame::OnViewSource(wxCommandEvent& event) { - bool state_new = event.IsChecked(); - if (m_panel->m_log->m_source_eaphost != state_new) { - m_panel->m_log->m_source_eaphost = state_new; - m_panel->m_log->RebuildItems(); - } -} - - -void wxEventMonitorFrame::OnViewSourceSchannelUpdate(wxUpdateUIEvent& event) -{ - event.Check(m_panel->m_log->m_source_schannel); -} - - -void wxEventMonitorFrame::OnViewSourceSchannel(wxCommandEvent& event) -{ - bool state_new = event.IsChecked(); - if (m_panel->m_log->m_source_schannel != state_new) { - m_panel->m_log->m_source_schannel = state_new; - m_panel->m_log->RebuildItems(); - } -} - - -void wxEventMonitorFrame::OnViewSourceProductUpdate(wxUpdateUIEvent& event) -{ - event.Check(m_panel->m_log->m_source_product); -} - - -void wxEventMonitorFrame::OnViewSourceProduct(wxCommandEvent& event) -{ - bool state_new = event.IsChecked(); - if (m_panel->m_log->m_source_product != state_new) { - m_panel->m_log->m_source_product = state_new; - m_panel->m_log->RebuildItems(); + wxObjectWithData *source = dynamic_cast*>(event.m_callbackUserData); + if (source) { + // Enable event source. + m_panel->m_log->EnableSource(source->m_data, event.IsChecked()); } } void wxEventMonitorFrame::OnViewLevelUpdate(wxUpdateUIEvent& event) { + // Update GUI control according to log level. event.Check(TRACE_LEVEL_ERROR + wxID_VIEW_LEVEL_ERROR - event.GetId() == m_panel->m_log->m_level); } @@ -402,37 +378,33 @@ void wxEventMonitorFrame::OnViewLevel(wxCommandEvent& event) { UCHAR state_new = TRACE_LEVEL_ERROR + wxID_VIEW_LEVEL_ERROR - event.GetId(); if (m_panel->m_log->m_level != state_new) { + // Set new log level. m_panel->m_log->m_level = state_new; m_panel->m_log->RebuildItems(); } } -void wxEventMonitorFrame::OnViewToolbarEditUpdate(wxUpdateUIEvent& event) +void wxEventMonitorFrame::OnViewToolbarUpdate(wxUpdateUIEvent& event) { - event.Check(m_mgr.GetPane(m_toolbarEdit).IsShown()); + wxObjectWithData *source = dynamic_cast*>(event.m_callbackUserData); + if (source && source->m_data) { + // Update GUI control according to toolbar/panel visibility. + event.Check(source->m_data->IsShown()); + event.Enable(true); + } else + event.Enable(false); } -void wxEventMonitorFrame::OnViewToolbarEdit(wxCommandEvent& /*event*/) +void wxEventMonitorFrame::OnViewToolbar(wxCommandEvent& event) { - wxAuiPaneInfo &paneInfo = m_mgr.GetPane(m_toolbarEdit); - paneInfo.Show(!paneInfo.IsShown()); - m_mgr.Update(); -} - - -void wxEventMonitorFrame::OnViewToolbarViewUpdate(wxUpdateUIEvent& event) -{ - event.Check(m_mgr.GetPane(m_toolbarView).IsShown()); -} - - -void wxEventMonitorFrame::OnViewToolbarView(wxCommandEvent& /*event*/) -{ - wxAuiPaneInfo &paneInfo = m_mgr.GetPane(m_toolbarView); - paneInfo.Show(!paneInfo.IsShown()); - m_mgr.Update(); + wxObjectWithData *source = dynamic_cast*>(event.m_callbackUserData); + if (source && source->m_data) { + // Toggle toolbar/panel visibility. + source->m_data->Show(!source->m_data->IsShown()); + m_mgr.Update(); + } } diff --git a/EventMonitor/Frame.h b/EventMonitor/Frame.h index f4c1aef..9e45563 100644 --- a/EventMonitor/Frame.h +++ b/EventMonitor/Frame.h @@ -83,18 +83,12 @@ protected: void OnEditSelectNone(wxCommandEvent& event); void OnViewScrollUpdate(wxUpdateUIEvent& event); void OnViewScroll(wxCommandEvent& event); - void OnViewSourceEapHostUpdate(wxUpdateUIEvent& event); - void OnViewSourceEapHost(wxCommandEvent& event); - void OnViewSourceSchannelUpdate(wxUpdateUIEvent& event); - void OnViewSourceSchannel(wxCommandEvent& event); - void OnViewSourceProductUpdate(wxUpdateUIEvent& event); - void OnViewSourceProduct(wxCommandEvent& event); + void OnViewSourceUpdate(wxUpdateUIEvent& event); + void OnViewSource(wxCommandEvent& event); void OnViewLevelUpdate(wxUpdateUIEvent& event); void OnViewLevel(wxCommandEvent& event); - void OnViewToolbarEditUpdate(wxUpdateUIEvent& event); - void OnViewToolbarEdit(wxCommandEvent& event); - void OnViewToolbarViewUpdate(wxUpdateUIEvent& event); - void OnViewToolbarView(wxCommandEvent& event); + void OnViewToolbarUpdate(wxUpdateUIEvent& event); + void OnViewToolbar(wxCommandEvent& event); protected: wxMenuBar* m_menubar; diff --git a/EventMonitor/StdAfx.h b/EventMonitor/StdAfx.h index f0ca8ec..1b20a03 100644 --- a/EventMonitor/StdAfx.h +++ b/EventMonitor/StdAfx.h @@ -30,6 +30,7 @@ #include "../include/Version.h" #include +#include #include #include