00001 class registerclass_scope_delayed {
00002 public:
00003 registerclass_scope_delayed() : m_class(0) {}
00004
00005 bool is_registered() const {return m_class != 0;}
00006 void toggle_on(UINT p_style,WNDPROC p_wndproc,int p_clsextra,int p_wndextra,HICON p_icon,HCURSOR p_cursor,HBRUSH p_background,const TCHAR * p_classname,const TCHAR * p_menuname);
00007 void toggle_off();
00008 ATOM get_class() const {return m_class;}
00009
00010 ~registerclass_scope_delayed() {toggle_off();}
00011 private:
00012 registerclass_scope_delayed(const registerclass_scope_delayed &) {throw pfc::exception_not_implemented();}
00013 const registerclass_scope_delayed & operator=(const registerclass_scope_delayed &) {throw pfc::exception_not_implemented();}
00014
00015 ATOM m_class;
00016 };
00017
00018
00019
00020 template<typename t_object>
00021 class syncd_storage {
00022 private:
00023 typedef syncd_storage<t_object> t_self;
00024 public:
00025 syncd_storage() {}
00026 template<typename t_source>
00027 syncd_storage(const t_source & p_source) : m_object(p_source) {}
00028 template<typename t_source>
00029 void set(t_source const & p_in) {
00030 insync(m_sync);
00031 m_object = p_in;
00032 }
00033 template<typename t_destination>
00034 void get(t_destination & p_out) const {
00035 insync(m_sync);
00036 p_out = m_object;
00037 }
00038 t_object get() const {
00039 insync(m_sync);
00040 return m_object;
00041 }
00042 template<typename t_source>
00043 const t_self & operator=(t_source const & p_source) {set(p_source); return *this;}
00044 private:
00045 mutable critical_section m_sync;
00046 t_object m_object;
00047 };
00048
00049 template<typename t_object>
00050 class syncd_storage_flagged {
00051 private:
00052 typedef syncd_storage_flagged<t_object> t_self;
00053 public:
00054 syncd_storage_flagged() : m_changed_flag(false) {}
00055 template<typename t_source>
00056 syncd_storage_flagged(const t_source & p_source) : m_changed_flag(false), m_object(p_source) {}
00057 void set_changed(bool p_flag = true) {
00058 insync(m_sync);
00059 m_changed_flag = p_flag;
00060 }
00061 template<typename t_source>
00062 void set(t_source const & p_in) {
00063 insync(m_sync);
00064 m_object = p_in;
00065 m_changed_flag = true;
00066 }
00067 bool has_changed() const {
00068 insync(m_sync);
00069 return m_changed_flag;
00070 }
00071 t_object peek() const {insync(m_sync); return m_object;}
00072 template<typename t_destination>
00073 bool get_if_changed(t_destination & p_out) {
00074 insync(m_sync);
00075 if (m_changed_flag) {
00076 p_out = m_object;
00077 m_changed_flag = false;
00078 return true;
00079 } else {
00080 return false;
00081 }
00082 }
00083 t_object get() {
00084 insync(m_sync);
00085 m_changed_flag = false;
00086 return m_object;
00087 }
00088 template<typename t_destination>
00089 void get(t_destination & p_out) {
00090 insync(m_sync);
00091 p_out = m_object;
00092 m_changed_flag = false;
00093 }
00094 template<typename t_source>
00095 const t_self & operator=(t_source const & p_source) {set(p_source); return *this;}
00096 private:
00097 bool m_changed_flag;
00098 mutable critical_section m_sync;
00099 t_object m_object;
00100 };
00101
00102 class CGlobalLock {
00103 public:
00104 CGlobalLock(HGLOBAL p_handle) : m_handle(p_handle), m_ptr(GlobalLock(p_handle)) {}
00105 ~CGlobalLock() {
00106 if (m_ptr != NULL) GlobalUnlock(m_handle);
00107 }
00108 void * GetPtr() const {return m_ptr;}
00109 t_size GetSize() const {return GlobalSize(m_handle);}
00110 private:
00111 void * m_ptr;
00112 HGLOBAL m_handle;
00113 };
00114
00115 bool uGetClipboardString(pfc::string_base & p_out);
00116
00117
00118
00119 #ifdef __ATLWIN_H__
00120
00121 class CMenuSelectionReceiver : public CWindowImpl<CMenuSelectionReceiver> {
00122 public:
00123 CMenuSelectionReceiver(HWND p_parent) {
00124 SetLastError(NO_ERROR);
00125 if (Create(p_parent) == NULL) throw exception_win32(GetLastError());
00126 }
00127 ~CMenuSelectionReceiver() {
00128 DestroyWindow();
00129 }
00130 typedef CWindowImpl<CMenuSelectionReceiver> _baseClass;
00131 DECLARE_WND_CLASS_EX(TEXT("{DF0087DB-E765-4283-BBAB-6AB2E8AB64A1}"),0,0);
00132
00133 BEGIN_MSG_MAP(CMenuSelectionReceiver)
00134 MESSAGE_HANDLER(WM_MENUSELECT,OnMenuSelect)
00135 END_MSG_MAP()
00136 protected:
00137 virtual bool QueryHint(unsigned p_id,pfc::string_base & p_out) {
00138 return false;
00139 }
00140 private:
00141 LRESULT OnMenuSelect(UINT,WPARAM p_wp,LPARAM p_lp,BOOL&) {
00142 if (p_lp != 0) {
00143 if (HIWORD(p_wp) & MF_POPUP) {
00144 m_status.release();
00145 } else {
00146 pfc::string8 msg;
00147 if (!QueryHint(LOWORD(p_wp),msg)) {
00148 m_status.release();
00149 } else {
00150 if (m_status.is_empty()) {
00151 if (!static_api_ptr_t<ui_control>()->override_status_text_create(m_status)) m_status.release();
00152 }
00153 if (m_status.is_valid()) {
00154 m_status->override_text(msg);
00155 }
00156 }
00157 }
00158 } else {
00159 m_status.release();
00160 }
00161 return 0;
00162 }
00163
00164 service_ptr_t<ui_status_text_override> m_status;
00165
00166 PFC_CLASS_NOT_COPYABLE(CMenuSelectionReceiver,CMenuSelectionReceiver);
00167 };
00168 #endif //#ifdef __ATLWIN_H__