⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logtab.hpp

📁 j2me is based on j2mepolish, client & server for mobile application.
💻 HPP
字号:

//         Copyright E骾n O'Callaghan 2008 - 2008.
// Distributed under the Boost Software License, Version 1.0.
//    (See accompanying file LICENSE_1_0.txt or copy at
//          http://www.boost.org/LICENSE_1_0.txt)

#pragma once

#include "StdAfx.hpp"
#include <deque>

#include "Resource.h"

#define WM_USER_LOGPOST	WM_USER + 101

#include "TabPage.hpp"
#include "event_logger.hpp"
#include "SortListViewCtrlEx.hpp"

class LogTab :
	public WTLx::TabPageImpl<LogTab>,
	public WTL::CDialogResize<LogTab>,
	public WTL::CWinDataExchange<LogTab>,
	private boost::noncopyable
{
protected:
	typedef LogTab thisClass;
	typedef WTLx::TabPageImpl<thisClass> baseClass;
	typedef WTL::CDialogResize<thisClass> resizeClass;

private:
	class LogTabList :
		public WTLx::SortListViewCtrlEx<LogTabList>,
		private SettingsIni<LogTabList>,
		private boost::noncopyable
	{
		typedef LogTabList thisClass;
		typedef WTLx::SortListViewCtrlEx<thisClass> listClass;
		typedef SettingsIni<thisClass> iniClass;
		friend class listClass;
		
	public:
		BEGIN_MSG_MAP_EX(thisClass)
			MSG_WM_DESTROY(OnDestroy)
			MESSAGE_HANDLER_EX(WM_USER_LOGPOST, OnMessageLogPost)

			CHAIN_MSG_MAP(listClass)
			DEFAULT_REFLECTION_HANDLER()
		END_MSG_MAP()

		LogTabList(aux::txml_ini& ini) :
			iniClass("tab_pane/log_tab", "log_listview", ini)
		{}

		void AfterSubclassWindow()
		{			
			boost::array<std::wstring, 3> names = {L"Timestamp", L"Message", L"Level"};
			boost::array<int, 3> widths = {100, 310, 60};
			boost::array<bool, 3> visible = {true, true, true};

			for (int i=0, e=3; i<e; ++i)
			{
				AddColumn(names[i].c_str(), i, visible[i], widths[i]);
			}

			SetColumnOrderState();
			SetSort(false);

			iniClass::LoadSettings();
			
			conn_ = logger.attach(bind(&LogTabList::operator(), this, _1));

			SetMsgHandled(false);
		}

		friend class boost::serialization::access;
		template<class Archive>
		void serialize(Archive& ar, const unsigned int version)
		{
			ar & boost::serialization::make_nvp("listview", 
				boost::serialization::base_object<listClass>(*this));
		}

		void operator()(boost::shared_ptr<event_type> ev)
		{
			boost::mutex::scoped_lock l(mutex_);

			try
			{
			
			if (ev->level() > event_logger::debug)
			{
				events_.push_back(ev);			
				PostMessage(WM_USER_LOGPOST, 0, 0);
			}
			
			}
			catch(...)
			{}
		}

		LRESULT OnMessageLogPost(UINT uMsg, WPARAM wParam, LPARAM lParam)
		{
			boost::mutex::scoped_lock l(mutex_);

			try
			{
			if (events_.begin() == events_.end()) return 0;

			boost::shared_ptr<event_type> e(*events_.begin());

			std::wstring time = boost::lexical_cast<std::wstring>(e->time_stamp());

			int itemPos = AddItem(0, 0, time.c_str());

			SetItemText(itemPos, 1,	e->msg().c_str());

			SetItemText(itemPos, 2,
				event_logger::event_level_to_str(e->level()).c_str());
				
			if (256 <= GetItemCount()) DeleteItem(256);

			}
			catch(...)
			{}

			events_.pop_front();

			return 0;
		}

	private:
		void OnDestroy()
		{
			boost::mutex::scoped_lock l(mutex_);

			conn_.disconnect();
			iniClass::SaveSettings();
		}

		mutable boost::mutex mutex_;

		boost::signals::connection conn_;
		std::deque<boost::shared_ptr<event_type> > events_;
	};

public:
	enum { IDD = IDD_LOG_TAB };

	LogTab(aux::txml_ini& ini) :
		log_list_(ini)
	{}
	
	BOOL PreTranslateMessage(MSG* pMsg)
	{
		return this->IsDialogMessage(pMsg);
	}

	BEGIN_MSG_MAP_EX(thisClass)
		MSG_WM_INITDIALOG(onInitDialog)
		MSG_WM_CLOSE(onClose)

		COMMAND_ID_HANDLER_EX(IDC_LOG_FILECHECK, onFileCheck)

		if (uMsg == WM_FORWARDMSG)
			if (PreTranslateMessage((LPMSG)lParam)) return TRUE;

		CHAIN_MSG_MAP(resizeClass)
		CHAIN_MSG_MAP(baseClass)
		REFLECT_NOTIFICATIONS()
	END_MSG_MAP()

	BOOL DoDataExchange(BOOL bSaveAndValidate = FALSE, UINT nCtlID = (UINT)-1);

	BEGIN_DLGRESIZE_MAP(thisClass)
		DLGRESIZE_CONTROL(IDC_LOG_LISTVIEW, DLSZ_SIZE_X|DLSZ_SIZE_Y)
	//	DLGRESIZE_CONTROL(IDC_LOG_FILECHECK, DLSZ_SIZE_X|DLSZ_MOVE_Y)
	END_DLGRESIZE_MAP()

	LRESULT onInitDialog(HWND, LPARAM);
	void onClose();
	void onFileCheck(UINT, int, HWND hWnd) { DoDataExchange(true); }

protected:
	LogTabList log_list_;
	int debugLevel;
};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -