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

📄 svcprowindow.hpp

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

//         Copyright E骾n O'Callaghan 2006 - 2007.
// 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)

#ifndef SVCPROWINDOW_H_INCLUDED
#define SVCPROWINDOW_H_INCLUDED

#include "StdAfx.hpp"
#include "Resource.h"

#include <winstl/controls/commctrl_functionals.hpp>
#include <winstl/controls/listview_sequence.hpp>

#include "auxiliary/wtl_app.hpp"
#include "auxiliary/logger.hpp"

#include "nt_service_profile_heirarchy.hpp"

#include "TabbedDialog.hpp"
#include "SvcListView.hpp"
#include "SvcTreeView.hpp"
#include "ConfigOptions.hpp"

#include "auxiliary/txml_ini_adapter.hpp"
#include "auxiliary/txml_oarchive.hpp"
#include "auxiliary/txml_iarchive.hpp"

class SvcProWindow : 
	public WTL::CFrameWindowImpl<SvcProWindow>,
	public WTL::CUpdateUI<SvcProWindow>,
	public WTL::CMessageFilter, 
	public WTL::CIdleHandler,
	private SettingsIni<SvcProWindow>,
	private boost::noncopyable
{
public:
	typedef SvcProWindow thisClass;
	typedef WTL::CFrameWindowImpl<thisClass> implClass;
	typedef WTL::CUpdateUI<thisClass> updateClass;
	typedef SettingsIni<thisClass> iniClass;

    DECLARE_FRAME_WND_CLASS( _T("Service Profiles"), IDR_MAINFRAME);

	SvcProWindow(aux::txml_ini& ini) :	
		iniClass("svc_profile_window", "settings", ini),
		ini_(ini),
		sort_list_(ini, boost::bind(&SvcProWindow::listview_setting_changed, this, _1),
			boost::bind(&SvcProWindow::listview_items_selected, this, _1)),
		tree_view_(ini, boost::bind(&SvcProWindow::name_changed, this, _1, _2),
			boost::bind(&SvcProWindow::active_profile_selected, this, _1),
			boost::bind(&SvcProWindow::delete_profile, this, _1),
			boost::bind(&SvcProWindow::new_profile, this, _1),
			boost::bind(&SvcProWindow::cancel_edit, this)),
		tabbed_dialog_(ini),
		profiles_(boost::bind(&SvcProWindow::profile_loaded, this, _1, _2, _3)),
		first_run_(true),
		user_save_directory_(aux::app.non_roaming_directory().string())
	{
		rect_ = WTL::CRect(280, 150, 950, 600);

		v_split_position_ = 145;
		h_split_position_ = 165;
	}

    BEGIN_MSG_MAP_EX(thisClass)
        MSG_WM_CREATE(OnCreate)
        MSG_WM_DESTROY(OnDestroy)

        COMMAND_ID_HANDLER_EX(ID_APP_EXIT, OnFileExit)
        COMMAND_ID_HANDLER_EX(ID_FILE_NEW, OnFileNew)
        COMMAND_ID_HANDLER_EX(ID_FILE_SAVE, OnFileSave)
        COMMAND_ID_HANDLER_EX(ID_FILE_IMPORT, OnImport)
        COMMAND_ID_HANDLER_EX(ID_FILE_EXPORT, OnExport)

		COMMAND_ID_HANDLER_EX(ID_OPT_APPLY, OnOptionsApply)
        COMMAND_ID_HANDLER_EX(ID_OPT_OBSERVE, OnObserveMode)

        COMMAND_ID_HANDLER_EX(ID_OPT_SAVEBACKUP, OnSaveBackup)
        COMMAND_ID_HANDLER_EX(ID_OPT_LOADBACKUP, OnLoadBackup)

        COMMAND_ID_HANDLER_EX(ID_OPT_SETTINGS, OnSettings)

        COMMAND_ID_HANDLER_EX(ID_APP_ABOUT, OnAbout)

		REFLECT_NOTIFICATIONS()
		CHAIN_MSG_MAP(updateClass)
        CHAIN_MSG_MAP(implClass)
    END_MSG_MAP()

	BEGIN_UPDATE_UI_MAP(thisClass)
		UPDATE_ELEMENT(ID_VIEW_TOOLBAR, UPDUI_MENUPOPUP)
		UPDATE_ELEMENT(ID_VIEW_STATUS_BAR, UPDUI_MENUPOPUP)
        UPDATE_ELEMENT(0, UPDUI_STATUSBAR)
        UPDATE_ELEMENT(1, UPDUI_STATUSBAR)
        UPDATE_ELEMENT(2, UPDUI_STATUSBAR)
	END_UPDATE_UI_MAP()

protected:
	virtual BOOL PreTranslateMessage(MSG* pMsg)
	{
		if(CFrameWindowImpl<thisClass>::PreTranslateMessage(pMsg))
			return TRUE;

		return tabbed_dialog_.PreTranslateMessage(pMsg);
	}

	virtual BOOL OnIdle()
	{
		UIUpdateStatusBar();
		UIUpdateToolBar();

		return FALSE;
	}

    LRESULT OnCreate(LPCREATESTRUCT lpcs);

	void DoCreateReBar();
	void DoCreateUI();

	void VerifyBackupFile();

    void OnDestroy()
    {        
		iniClass::SaveSettings();

        SetMsgHandled(false);
    }

    LRESULT OnEraseBkgnd(HDC hdc)
    {
		return 0;
    }

    void OnTimer(UINT uTimerID)
    {
        if (1 != uTimerID)
            SetMsgHandled(false);
        else
            RedrawWindow();
    }

	void OnFileNew(UINT uCode, int nID, HWND hwndCtrl);
 
    void OnFileExit(UINT uCode, int nID, HWND hwndCtrl)
    {
        DestroyWindow();
        return;
    }

    void OnFileSave(UINT, int, HWND);
	void OnObserveMode(UINT, int, HWND);
	void OnOptionsApply(UINT, int, HWND);
	void OnSaveBackup(UINT, int, HWND);
	void OnLoadBackup(UINT, int, HWND);
	void OnImport(UINT, int, HWND);
	void OnExport(UINT, int, HWND);

    void OnSettings(UINT, int, HWND)
    {
		ConfigOptionsProp sheet(user_save_directory_, L"Settings", 0, NULL);	
		sheet.DoModal();

        return;
    }

    void OnAbout(UINT, int, HWND)
    {
		ConfigOptionsProp sheet(user_save_directory_, L"Settings", 1, NULL);	
		sheet.DoModal();

        return;
    }

	friend class boost::serialization::access;
	template<class Archive>
    void save(Archive & ar, const unsigned int version) const
    {		
		using boost::serialization::make_nvp;
		GetWindowRect(rect_);

		v_split_position_ = v_split_.GetSplitterPos();
		h_split_position_ = h_split_.GetSplitterPos();

		ar & make_nvp("rect", rect_);

		ar & make_nvp("v_split_position", v_split_position_);
		ar & make_nvp("h_split_position", h_split_position_);

		ar & make_nvp("first_run", first_run_);
		ar & make_nvp("user_save_directory", user_save_directory_);
    }

    template<class Archive>
    void load(Archive & ar, const unsigned int version)
    {
		using boost::serialization::make_nvp;

		ar & make_nvp("rect", rect_);

		ar & make_nvp("v_split_position", v_split_position_);
		ar & make_nvp("h_split_position", h_split_position_);

		ar & make_nvp("first_run", first_run_);
		ar & make_nvp("user_save_directory", user_save_directory_);

		MoveWindow(rect_.left, rect_.top, rect_.right-rect_.left, rect_.bottom-rect_.top, false);	
		
		v_split_.SetSplitterPos(v_split_position_);
		h_split_.SetSplitterPos(h_split_position_);
    }

    BOOST_SERIALIZATION_SPLIT_MEMBER()

private:
	void new_profile(WTL::CTreeItem ti_p);
	void scan_and_load(boost::filesystem::wpath directory);
	void name_changed(size_t i, std::wstring name);
	void active_profile_selected(size_t i);
	void listview_setting_changed(size_t index);
	void update_title();
	void profile_loaded(const std::wstring& name, size_t item, size_t parent);
	void delete_profile(size_t index);
	void apply_profile_settings(std::set<nt_service::service_settings> settings);
	void apply_settings_thread(service_ptr svc_ptr, std::set<nt_service::service_settings>::const_iterator ss_i);
	void save_backup_file(boost::filesystem::wpath filename);
	void load_backup_file(boost::filesystem::wpath filename);
	void listview_items_selected(std::vector<service_ptr>);
	void build_inherted_settings(nt_service_profile_ptr p_ptr, 
		std::set<nt_service::service_settings>& service_settings_set);
	void update_display();

	bool cancel_edit() { return sort_list_.overview_mode(); }

	aux::txml_ini& ini_;

	WTL::CCommandBarCtrl cmd_bar_;
    WTL::CMultiPaneStatusBarCtrl status_bar_;

	WTL::CSplitterWindow v_split_;
	WTL::CHorSplitterWindow h_split_;

	nt_service_profile test_;

	nt_service_profile_heirarchy profiles_;
	nt_service_profile_ptr active_profile_;

	bool first_run_;

	mutable WTL::CRect rect_;

	mutable int v_split_position_;
	mutable int h_split_position_;

	std::wstring user_save_directory_;

	SvcListViewCtrl sort_list_;
	SvcTreeViewCtrl tree_view_;
	TabbedDialog tabbed_dialog_;
};

#endif  // SVCPROWINDOW_H_INCLUDED

⌨️ 快捷键说明

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