diff --git a/DuiLib/Control/UITreeView.cpp b/DuiLib/Control/UITreeView.cpp index d30b358..c8d4ad4 100644 --- a/DuiLib/Control/UITreeView.cpp +++ b/DuiLib/Control/UITreeView.cpp @@ -232,28 +232,91 @@ namespace DuiLib //************************************ bool CTreeNodeUI::AddAt( CControlUI* pControl, int iIndex ) { - if(NULL == static_cast(pControl->GetInterface(_T("TreeNode")))) - return false; + if (!pControl) + return false; - CTreeNodeUI* pIndexNode = static_cast(mTreeNodes.GetAt(iIndex)); - if(!pIndexNode){ - if(!mTreeNodes.Add(pControl)) - return false; + if(_tcsicmp(pControl->GetClass(), _T("TreeNodeUI")) != 0) + return false; + + if (!GetFolderButton()->IsSelected()) //add byRedrain 2014.8.8 + { + m_pManager->SendNotify(this, DUI_MSGTYPE_ITEMDBCLICK); } - else if(pIndexNode && !mTreeNodes.InsertAt(iIndex,pControl)) - return false; - if(!pIndexNode && pTreeView && pTreeView->GetItemAt(GetTreeIndex()+1)) - pIndexNode = static_cast(pTreeView->GetItemAt(GetTreeIndex()+1)->GetInterface(_T("TreeNode"))); + //filter invalidate index + int iDestIndex = iIndex; + if (iDestIndex < 0) + { + iDestIndex = 0; + } + else if (iDestIndex > GetCountChild()) + { + iDestIndex = GetCountChild(); + } + if(iIndex != iDestIndex) iIndex = iDestIndex; - pControl = CalLocation((CTreeNodeUI*)pControl); + CTreeNodeUI* pIndexNode = static_cast(mTreeNodes.GetAt(iIndex)); - if(pTreeView && pIndexNode) - return pTreeView->AddAt((CTreeNodeUI*)pControl,pIndexNode); - else - return pTreeView->Add((CTreeNodeUI*)pControl); + pControl = CalLocation((CTreeNodeUI*)pControl); - return true; + bool bRet = false; + int iTreeIndex = -1; + if (pTreeView) + { + //Get TreeView insert index + if (pIndexNode) + { + iTreeIndex = pIndexNode->GetTreeIndex(); + bRet = pTreeView->AddAt((CTreeNodeUI*)pControl, iTreeIndex) >= 0; + if (bRet) + { + mTreeNodes.InsertAt(iIndex, pControl); + } + } + else + { + CTreeNodeUI *pChildNode = NULL; + //insert child node position index(new node insert to tail, default add tail) + int iChIndex = -1; + //insert child node tree-view position index(new node insert to tail) + int iChTreeIndex = -1; + //search tree index reverse + for (int i = GetCountChild(); i > 0; i++) + { + pChildNode = GetChildNode(i - 1); + iChTreeIndex = pChildNode->GetTreeIndex(); + if (iChTreeIndex >= GetTreeIndex() && iChTreeIndex <= GetTreeIndex() + GetCountChild() ) + { + //new child node position + iChIndex = i; + //child node tree position + iTreeIndex = iChTreeIndex + 1; + break; + } + } + //child not find tree index directly insert to parent tail + if (iTreeIndex <= GetTreeIndex()) + { + iTreeIndex = GetTreeIndex() + 1; + } + //insert TreeNode to TreeView + bRet = pTreeView->AddAt((CTreeNodeUI*)pControl, iTreeIndex) >= 0; + //insert TreeNode to parent TreeNode + if (bRet) + { + if (iChIndex > 0) + bRet = mTreeNodes.InsertAt(iChIndex, pControl); + else + bRet = mTreeNodes.Add(pControl); + } + } + } + else + { + //parent TreeNode not bind TreeView just insert to parent TreeNode + bRet = mTreeNodes.InsertAt(iIndex, pControl); + } + return bRet; } //************************************ @@ -354,6 +417,10 @@ namespace DuiLib if (_tcsicmp(_pTreeNodeUI->GetClass(), _T("TreeNodeUI")) != 0) return false; + if (!GetFolderButton()->IsSelected()) //add byRedrain 2014.8.8 + { + m_pManager->SendNotify(this, DUI_MSGTYPE_ITEMDBCLICK); + } _pTreeNodeUI = CalLocation(_pTreeNodeUI); bool nRet = true; @@ -792,8 +859,8 @@ namespace DuiLib pControl->GetFolderButton()->OnNotify += MakeDelegate(this,&CTreeViewUI::OnFolderChanged); pControl->GetCheckBox()->OnNotify += MakeDelegate(this,&CTreeViewUI::OnCheckBoxChanged); - pControl->SetVisibleFolderBtn(m_bVisibleFolderBtn); pControl->SetVisibleCheckBtn(m_bVisibleCheckBtn); + pControl->SetVisibleFolderBtn(m_bVisibleFolderBtn); if(m_uItemMinWidth > 0) pControl->SetMinWidth(m_uItemMinWidth); @@ -809,6 +876,7 @@ namespace DuiLib Add(pNode); } } + else pControl->SetTreeView(this); return true; @@ -829,9 +897,21 @@ namespace DuiLib if (_tcsicmp(pControl->GetClass(), _T("TreeNodeUI")) != 0) return -1; - CTreeNodeUI* pParent = static_cast(GetItemAt(iIndex - 1)); - if(!pParent) - return -1; + //filter invalidate index + int iDestIndex = iIndex; + if (iDestIndex < 0) + { + iDestIndex = 0; + } + else if (iDestIndex > GetCount()) + { + iDestIndex = GetCount(); + } + if(iIndex != iDestIndex) iIndex = iDestIndex; + + //CTreeNodeUI* pParent = static_cast(GetItemAt(iIndex)); + //if(!pParent) + // return -1; pControl->OnNotify += MakeDelegate(this,&CTreeViewUI::OnDBClickItem); pControl->GetFolderButton()->OnNotify += MakeDelegate(this,&CTreeViewUI::OnFolderChanged); @@ -839,6 +919,7 @@ namespace DuiLib pControl->SetVisibleFolderBtn(m_bVisibleFolderBtn); pControl->SetVisibleCheckBtn(m_bVisibleCheckBtn); + pControl->SetTreeView(this); if(m_uItemMinWidth > 0) pControl->SetMinWidth(m_uItemMinWidth); @@ -852,13 +933,12 @@ namespace DuiLib { CTreeNodeUI* pNode = pControl->GetChildNode(nIndex); if(pNode) - return AddAt(pNode,iIndex+1); + { + iIndex = AddAt(pNode, iIndex +1); + } } } - else - return iIndex+1; - - return -1; + return iIndex; } //************************************ diff --git a/README.md b/README.md index 76dc2b7..a49a76a 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ 2. Kernel is MSOpen hiredis, GUILIB is duilib 3. Support official Redis 2.6 2.7 2.8 new.. -![UI](https://raw.githubusercontent.com/cinience/RedisStudio/master/package/redis.png "RedisStudio UI") +![UI](https://raw.githubusercontent.com/cinience/RedisStudio/master/docs/redis.png "RedisStudio UI") ## Supported platforms diff --git a/RedisStudio/AbstractUI.h b/RedisStudio/AbstractUI.h index f3deb21..d29b4ce 100644 --- a/RedisStudio/AbstractUI.h +++ b/RedisStudio/AbstractUI.h @@ -1,47 +1,47 @@ -#pragma once - -class AbstraceUI : public CContainerUI, public CNotifyPump -{ -public: - AbstraceUI(CPaintManagerUI* pm):m_hWnd(NULL),m_pPaintManager(pm){}; - - virtual ~AbstraceUI(){}; - - virtual void Initialize() {}; - - virtual CDuiString GetVirtualwndName() = 0; - - virtual void RefreshWnd() = 0; - - virtual int GetIndex() = 0; - - virtual bool CanChange() - { - return true; - } - - virtual LRESULT HandleCustomMessage( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled ) - { - bHandled = FALSE; - return 0; - } - - // ôھ - inline void SetHWND(HWND hwnd) - { - m_hWnd = hwnd; - } - - inline HWND GetHWND() - { - return m_hWnd; - } - - inline CPaintManagerUI* GetPaintMgr() - { - return m_pPaintManager; - } -private: - CPaintManagerUI* m_pPaintManager; - HWND m_hWnd; +#pragma once + +class AbstraceUI : public CContainerUI, public CNotifyPump +{ +public: + AbstraceUI(CPaintManagerUI* pm):m_hWnd(NULL),m_pPaintManager(pm){}; + + virtual ~AbstraceUI(){}; + + virtual void Initialize() {}; + + virtual CDuiString GetVirtualwndName() = 0; + + virtual void RefreshWnd() = 0; + + virtual int GetIndex() = 0; + + virtual bool CanChange() + { + return true; + } + + virtual LRESULT HandleCustomMessage( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled ) + { + bHandled = FALSE; + return 0; + } + + /// 设置窗口句柄 + inline void SetHWND(HWND hwnd) + { + m_hWnd = hwnd; + } + + inline HWND GetHWND() + { + return m_hWnd; + } + + inline CPaintManagerUI* GetPaintMgr() + { + return m_pPaintManager; + } +private: + CPaintManagerUI* m_pPaintManager; + HWND m_hWnd; }; \ No newline at end of file diff --git a/RedisStudio/Base/CharacterSet.cpp b/RedisStudio/Base/CharacterSet.cpp index a16e7c8..0db21c6 100644 --- a/RedisStudio/Base/CharacterSet.cpp +++ b/RedisStudio/Base/CharacterSet.cpp @@ -1,56 +1,56 @@ -#include "StdAfx.h" -#include "CharacterSet.h" - -namespace Base { - -std::string CharacterSet::UnicodeConvert( const std::wstring& strWide, UINT uCodePage ) -{ - std::string strANSI; - int iLen = ::WideCharToMultiByte(uCodePage, 0, strWide.c_str(), -1, NULL, 0, NULL, NULL); - - if (iLen > 1) - { - strANSI.resize(iLen-1); - ::WideCharToMultiByte(uCodePage, 0, strWide.c_str(), -1, &strANSI[0], iLen, NULL, NULL); - } - - return strANSI; -} - -std::string CharacterSet::UnicodeToUTF8( const std::wstring& strWide ) -{ - return UnicodeConvert(strWide, CP_UTF8); -} - -std::string CharacterSet::UnicodeToANSI( const std::wstring& strWide ) -{ - return UnicodeConvert(strWide, CP_ACP); -} - -std::wstring CharacterSet::ANSIToUnicode( const std::string& str ) -{ - int uniocedeLen = ::MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, NULL, 0); - wchar_t* pUnicode = new wchar_t[uniocedeLen + 1]; - memset(pUnicode, 0 ,(uniocedeLen+1)*sizeof(wchar_t)); - ::MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, (LPWSTR)pUnicode, uniocedeLen); - - wstring rt = (wchar_t*) pUnicode; - delete pUnicode; - - return rt; -} - -std::wstring CharacterSet::UTF8ToUnicode( const std::string& str ) -{ - int uniocedeLen = ::MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.size(), NULL, 0); - wchar_t* pUnicode = new wchar_t[uniocedeLen + 1]; - memset(pUnicode, 0 ,(uniocedeLen+1)*sizeof(wchar_t)); - ::MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.size(), (LPWSTR)pUnicode, uniocedeLen); - - wstring rt = (wchar_t*) pUnicode; - delete pUnicode; - - return rt; -} - -} // namespace Base +#include "StdAfx.h" +#include "CharacterSet.h" + +namespace Base { + +std::string CharacterSet::UnicodeConvert( const std::wstring& strWide, UINT uCodePage ) +{ + std::string strANSI; + int iLen = ::WideCharToMultiByte(uCodePage, 0, strWide.c_str(), -1, NULL, 0, NULL, NULL); + + if (iLen > 1) + { + strANSI.resize(iLen-1); + ::WideCharToMultiByte(uCodePage, 0, strWide.c_str(), -1, &strANSI[0], iLen, NULL, NULL); + } + + return strANSI; +} + +std::string CharacterSet::UnicodeToUTF8( const std::wstring& strWide ) +{ + return UnicodeConvert(strWide, CP_UTF8); +} + +std::string CharacterSet::UnicodeToANSI( const std::wstring& strWide ) +{ + return UnicodeConvert(strWide, CP_ACP); +} + +std::wstring CharacterSet::ANSIToUnicode( const std::string& str ) +{ + int uniocedeLen = ::MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, NULL, 0); + wchar_t* pUnicode = new wchar_t[uniocedeLen + 1]; + memset(pUnicode, 0 ,(uniocedeLen+1)*sizeof(wchar_t)); + ::MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, (LPWSTR)pUnicode, uniocedeLen); + + wstring rt = (wchar_t*) pUnicode; + delete pUnicode; + + return rt; +} + +std::wstring CharacterSet::UTF8ToUnicode( const std::string& str ) +{ + int uniocedeLen = ::MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.size(), NULL, 0); + wchar_t* pUnicode = new wchar_t[uniocedeLen + 1]; + memset(pUnicode, 0 ,(uniocedeLen+1)*sizeof(wchar_t)); + ::MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.size(), (LPWSTR)pUnicode, uniocedeLen); + + wstring rt = (wchar_t*) pUnicode; + delete pUnicode; + + return rt; +} + +} // namespace Base diff --git a/RedisStudio/Base/CharacterSet.h b/RedisStudio/Base/CharacterSet.h index 5c85a1c..a75d89e 100644 --- a/RedisStudio/Base/CharacterSet.h +++ b/RedisStudio/Base/CharacterSet.h @@ -1,23 +1,23 @@ -#ifndef Base_CharacterSet_INCLUDED -#define Base_CharacterSet_INCLUDED - -namespace Base { - -class CharacterSet -{ -public: - static std::string UnicodeConvert(const std::wstring& strWide, UINT uCodePage); - - static std::string UnicodeToUTF8(const std::wstring& strWide); - - static std::string UnicodeToANSI(const std::wstring& strWide); - - static std::wstring ANSIToUnicode(const std::string& str); - - static std::wstring UTF8ToUnicode(const std::string& str); - -}; - -} // namespace Base - +#ifndef Base_CharacterSet_INCLUDED +#define Base_CharacterSet_INCLUDED + +namespace Base { + +class CharacterSet +{ +public: + static std::string UnicodeConvert(const std::wstring& strWide, UINT uCodePage); + + static std::string UnicodeToUTF8(const std::wstring& strWide); + + static std::string UnicodeToANSI(const std::wstring& strWide); + + static std::wstring ANSIToUnicode(const std::string& str); + + static std::wstring UTF8ToUnicode(const std::string& str); + +}; + +} // namespace Base + #endif \ No newline at end of file diff --git a/RedisStudio/Base/Event.cpp b/RedisStudio/Base/Event.cpp index 28914f9..2df361f 100644 --- a/RedisStudio/Base/Event.cpp +++ b/RedisStudio/Base/Event.cpp @@ -1,45 +1,45 @@ -#include "StdAfx.h" -#include "Event.h" - -namespace Base { - -Event::Event(bool autoReset) -{ - _event = CreateEventW(NULL, autoReset ? FALSE : TRUE, FALSE, NULL); - if (!_event) - throw std::exception("cannot create event"); -} - - -Event::~Event() -{ - CloseHandle(_event); -} - - -void Event::wait() -{ - switch (WaitForSingleObject(_event, INFINITE)) - { - case WAIT_OBJECT_0: - return; - default: - throw std::exception("wait for event failed"); - } -} - - -bool Event::wait(long milliseconds) -{ - switch (WaitForSingleObject(_event, milliseconds + 1)) - { - case WAIT_TIMEOUT: - return false; - case WAIT_OBJECT_0: - return true; - default: - throw std::exception("wait for event failed"); - } -} - +#include "StdAfx.h" +#include "Event.h" + +namespace Base { + +Event::Event(bool autoReset) +{ + _event = CreateEventW(NULL, autoReset ? FALSE : TRUE, FALSE, NULL); + if (!_event) + throw std::exception("cannot create event"); +} + + +Event::~Event() +{ + CloseHandle(_event); +} + + +void Event::wait() +{ + switch (WaitForSingleObject(_event, INFINITE)) + { + case WAIT_OBJECT_0: + return; + default: + throw std::exception("wait for event failed"); + } +} + + +bool Event::wait(long milliseconds) +{ + switch (WaitForSingleObject(_event, milliseconds + 1)) + { + case WAIT_TIMEOUT: + return false; + case WAIT_OBJECT_0: + return true; + default: + throw std::exception("wait for event failed"); + } +} + } //namespace Base \ No newline at end of file diff --git a/RedisStudio/Base/Event.h b/RedisStudio/Base/Event.h index 77d6783..cf46417 100644 --- a/RedisStudio/Base/Event.h +++ b/RedisStudio/Base/Event.h @@ -1,45 +1,45 @@ -#ifndef Base_Event_INCLUDED -#define Base_Event_INCLUDED - -#include -#include - -namespace Base { -class Event -{ -public: - Event(bool autoReset); - ~Event(); - void set(); - void wait(); - bool wait(long milliseconds); - void reset(); - -private: - HANDLE _event; -}; - - -// -// inlines -// -inline void Event::set() -{ - if (!SetEvent(_event)) - { - throw std::exception("cannot signal event"); - } -} - - -inline void Event::reset() -{ - if (!ResetEvent(_event)) - { - throw std::exception("cannot reset event"); - } -} - -} //namespace Base - +#ifndef Base_Event_INCLUDED +#define Base_Event_INCLUDED + +#include +#include + +namespace Base { +class Event +{ +public: + Event(bool autoReset); + ~Event(); + void set(); + void wait(); + bool wait(long milliseconds); + void reset(); + +private: + HANDLE _event; +}; + + +// +// inlines +// +inline void Event::set() +{ + if (!SetEvent(_event)) + { + throw std::exception("cannot signal event"); + } +} + + +inline void Event::reset() +{ + if (!ResetEvent(_event)) + { + throw std::exception("cannot reset event"); + } +} + +} //namespace Base + #endif \ No newline at end of file diff --git a/RedisStudio/Base/Http.cpp b/RedisStudio/Base/Http.cpp new file mode 100644 index 0000000..81acf1e --- /dev/null +++ b/RedisStudio/Base/Http.cpp @@ -0,0 +1,125 @@ +#include "StdAfx.h" +#include "Http.h" + +#include +#include +#include +#include +#pragma comment(lib, "ws2_32.lib") + +#include "String.h" +#include + +#define BUFFERSIZE 1024 + +namespace Base { + +Http::Http(const std::string& hostname, int port) +{ + struct hostent *remoteHost = gethostbyname(hostname.c_str()); + struct in_addr addr; + _host = hostname; + _port = port; + if (remoteHost != NULL) { + if (remoteHost->h_addrtype == AF_INET) + { + if (remoteHost->h_addr_list[0] != 0) { + addr.s_addr = *(u_long *) remoteHost->h_addr_list[0]; + _ip = inet_ntoa(addr); + } + } + } +} + +Http::~Http() +{ + +} + +bool Http::ping() +{ + if (_ip.empty()) return false; + return true; +} + +Http::Response Http::post(const std::string& path, const std::string& data) +{ + string request; + string response; + int resp_leng; + Response res; + res.status = -1; + + char buffer[1024]; + struct sockaddr_in serveraddr; + int sock; + + std::stringstream ss; + ss << data.length(); + + std::stringstream request2; + + request2 << "POST " << path << " HTTP/1.1"<0) + response+= string(buffer).substr(0,resp_leng); + //note: download lag is not handled in this code + } + //disconnect + closesocket(sock); + + String::TSeqStr seq; + String::Split(response, "\n", seq); + if (seq.size() == 0) { + res.status = -1; + res.data = "response data is wrong"; + return res; + } + String::TSeqStr hdrseq; + String::Split(seq[0], " ", hdrseq); + if (hdrseq.size() > 1) { + res.status = atoi(hdrseq[1].c_str()); + } + if (res.status == 200) { + res.data = seq[seq.size()-1]; + } + return res; +} + +} // namespace Base \ No newline at end of file diff --git a/RedisStudio/Base/Http.h b/RedisStudio/Base/Http.h new file mode 100644 index 0000000..4589b38 --- /dev/null +++ b/RedisStudio/Base/Http.h @@ -0,0 +1,33 @@ +#ifndef Base_Http_INCLUDED +#define Base_Http_INCLUDED + +#include "ScopedLock.h" + +namespace Base { + +class Http +{ +public: + class Response { + public: + int status; + std::string data; + }; + + Http(const std::string& hostname, int port); + + ~Http(); + + bool ping(); + + Response post(const std::string& path, const std::string& data); + +private: + std::string _host; + std::string _ip; + int _port; +}; + +} // namespace Base + +#endif \ No newline at end of file diff --git a/RedisStudio/Base/Mutex.cpp b/RedisStudio/Base/Mutex.cpp index 48d35f5..3841db6 100644 --- a/RedisStudio/Base/Mutex.cpp +++ b/RedisStudio/Base/Mutex.cpp @@ -1,17 +1,17 @@ -#include "StdAfx.h" -#include "Mutex.h" - -namespace Base { - -Mutex::Mutex() -{ - InitializeCriticalSectionAndSpinCount(&_cs, 4000); -} - - -Mutex::~Mutex() -{ - DeleteCriticalSection(&_cs); -} - +#include "StdAfx.h" +#include "Mutex.h" + +namespace Base { + +Mutex::Mutex() +{ + InitializeCriticalSectionAndSpinCount(&_cs, 4000); +} + + +Mutex::~Mutex() +{ + DeleteCriticalSection(&_cs); +} + } // namespace Mutex \ No newline at end of file diff --git a/RedisStudio/Base/Mutex.h b/RedisStudio/Base/Mutex.h index f02aecb..eb8ad85 100644 --- a/RedisStudio/Base/Mutex.h +++ b/RedisStudio/Base/Mutex.h @@ -1,56 +1,56 @@ -#ifndef Base_ScopedMutex_INCLUDED -#define Base_ScopedMutex_INCLUDED - -#include "ScopedLock.h" - -namespace Base { - -class Mutex -{ -public: - typedef ScopedLock ScopedLock; -public: - Mutex(); - ~Mutex(); - void lock(); - bool tryLock(); - void unlock(); - -private: - CRITICAL_SECTION _cs; -}; - -inline void Mutex::lock() -{ - try - { - EnterCriticalSection(&_cs); - } - catch (...) - { - throw std::exception("cannot lock mutex"); - } -} - - -inline bool Mutex::tryLock() -{ - try - { - return TryEnterCriticalSection(&_cs) != 0; - } - catch (...) - { - } - throw std::exception("cannot lock mutex"); -} - - -inline void Mutex::unlock() -{ - LeaveCriticalSection(&_cs); -} - -} // namespace Base - +#ifndef Base_ScopedMutex_INCLUDED +#define Base_ScopedMutex_INCLUDED + +#include "ScopedLock.h" + +namespace Base { + +class Mutex +{ +public: + typedef ScopedLock ScopedLock; +public: + Mutex(); + ~Mutex(); + void lock(); + bool tryLock(); + void unlock(); + +private: + CRITICAL_SECTION _cs; +}; + +inline void Mutex::lock() +{ + try + { + EnterCriticalSection(&_cs); + } + catch (...) + { + throw std::exception("cannot lock mutex"); + } +} + + +inline bool Mutex::tryLock() +{ + try + { + return TryEnterCriticalSection(&_cs) != 0; + } + catch (...) + { + } + throw std::exception("cannot lock mutex"); +} + + +inline void Mutex::unlock() +{ + LeaveCriticalSection(&_cs); +} + +} // namespace Base + #endif \ No newline at end of file diff --git a/RedisStudio/Base/Runnable.cpp b/RedisStudio/Base/Runnable.cpp index c785daa..4797d1d 100644 --- a/RedisStudio/Base/Runnable.cpp +++ b/RedisStudio/Base/Runnable.cpp @@ -1,18 +1,18 @@ -#include "StdAfx.h" -#include "Runnable.h" - - -namespace Base { - - -Runnable::Runnable() -{ -} - - -Runnable::~Runnable() -{ -} - - -} // namespace Base +#include "StdAfx.h" +#include "Runnable.h" + + +namespace Base { + + +Runnable::Runnable() +{ +} + + +Runnable::~Runnable() +{ +} + + +} // namespace Base diff --git a/RedisStudio/Base/Runnable.h b/RedisStudio/Base/Runnable.h index 8c99dee..33915bd 100644 --- a/RedisStudio/Base/Runnable.h +++ b/RedisStudio/Base/Runnable.h @@ -1,21 +1,21 @@ -#ifndef Base_Runnable_INCLUDED -#define Base_Runnable_INCLUDED - -namespace Base { - -class Runnable -{ -public: - Runnable(); - virtual ~Runnable(); - - virtual void run() = 0; - /// Do whatever the thread needs to do. Must - /// be overridden by subclasses. -}; - - -} // namespace Base - - -#endif // Base_Runnable_INCLUDED +#ifndef Base_Runnable_INCLUDED +#define Base_Runnable_INCLUDED + +namespace Base { + +class Runnable +{ +public: + Runnable(); + virtual ~Runnable(); + + virtual void run() = 0; + /// Do whatever the thread needs to do. Must + /// be overridden by subclasses. +}; + + +} // namespace Base + + +#endif // Base_Runnable_INCLUDED diff --git a/RedisStudio/Base/RunnableAdapter.h b/RedisStudio/Base/RunnableAdapter.h index e14b8c5..524fbae 100644 --- a/RedisStudio/Base/RunnableAdapter.h +++ b/RedisStudio/Base/RunnableAdapter.h @@ -1,60 +1,60 @@ -#ifndef Base_RunnableAdapter_INCLUDED -#define Base_RunnableAdapter_INCLUDED - -#include "Base/Runnable.h" - - -namespace Base { - - -template -class RunnableAdapter: public Runnable - /// This adapter simplifies using ordinary methods as - /// targets for threads. - /// Usage: - /// RunnableAdapter ra(myObject, &MyObject::doSomething)); - /// Thread thr; - /// thr.Start(ra); - /// - /// For using a freestanding or static member function as a thread - /// target, please see the ThreadTarget class. -{ -public: - typedef void (C::*Callback)(); - - RunnableAdapter(C& object, Callback method): _pObject(&object), _method(method) - { - } - - RunnableAdapter(const RunnableAdapter& ra): _pObject(ra._pObject), _method(ra._method) - { - } - - ~RunnableAdapter() - { - } - - RunnableAdapter& operator = (const RunnableAdapter& ra) - { - _pObject = ra._pObject; - _method = ra._method; - return *this; - } - - void run() - { - (_pObject->*_method)(); - } - -private: - RunnableAdapter(); - - C* _pObject; - Callback _method; -}; - - -} // namespace Base - - -#endif // Base_RunnableAdapter_INCLUDED +#ifndef Base_RunnableAdapter_INCLUDED +#define Base_RunnableAdapter_INCLUDED + +#include "Base/Runnable.h" + + +namespace Base { + + +template +class RunnableAdapter: public Runnable + /// This adapter simplifies using ordinary methods as + /// targets for threads. + /// Usage: + /// RunnableAdapter ra(myObject, &MyObject::doSomething)); + /// Thread thr; + /// thr.Start(ra); + /// + /// For using a freestanding or static member function as a thread + /// target, please see the ThreadTarget class. +{ +public: + typedef void (C::*Callback)(); + + RunnableAdapter(C& object, Callback method): _pObject(&object), _method(method) + { + } + + RunnableAdapter(const RunnableAdapter& ra): _pObject(ra._pObject), _method(ra._method) + { + } + + ~RunnableAdapter() + { + } + + RunnableAdapter& operator = (const RunnableAdapter& ra) + { + _pObject = ra._pObject; + _method = ra._method; + return *this; + } + + void run() + { + (_pObject->*_method)(); + } + +private: + RunnableAdapter(); + + C* _pObject; + Callback _method; +}; + + +} // namespace Base + + +#endif // Base_RunnableAdapter_INCLUDED diff --git a/RedisStudio/Base/ScopedLock.h b/RedisStudio/Base/ScopedLock.h index 01a5d26..7c33353 100644 --- a/RedisStudio/Base/ScopedLock.h +++ b/RedisStudio/Base/ScopedLock.h @@ -1,30 +1,30 @@ -#ifndef Base_ScopedLock_INCLUDED -#define Base_ScopedLock_INCLUDED - -namespace Base { - -template -class ScopedLock -{ -public: - ScopedLock(M& mutex): _mutex(mutex) - { - _mutex.lock(); - } - - ~ScopedLock() - { - _mutex.unlock(); - } - -private: - M& _mutex; - - ScopedLock(); - ScopedLock(const ScopedLock&); - ScopedLock& operator = (const ScopedLock&); -}; - -} // namespace - +#ifndef Base_ScopedLock_INCLUDED +#define Base_ScopedLock_INCLUDED + +namespace Base { + +template +class ScopedLock +{ +public: + ScopedLock(M& mutex): _mutex(mutex) + { + _mutex.lock(); + } + + ~ScopedLock() + { + _mutex.unlock(); + } + +private: + M& _mutex; + + ScopedLock(); + ScopedLock(const ScopedLock&); + ScopedLock& operator = (const ScopedLock&); +}; + +} // namespace + #endif \ No newline at end of file diff --git a/RedisStudio/Base/String.cpp b/RedisStudio/Base/String.cpp index ad2bc57..026ab52 100644 --- a/RedisStudio/Base/String.cpp +++ b/RedisStudio/Base/String.cpp @@ -1,74 +1,74 @@ -#include "stdafx.h" -#include "String.h" - -namespace Base { - -bool String::IsSpace( const char& ch ) -{ - return ch==' '; -} - -void String::Split(const std::string& str, const std::string& separators, TSeqStr& tokens, int options) -{ - std::string::const_iterator it1 = str.begin(); - std::string::const_iterator it2; - std::string::const_iterator it3; - std::string::const_iterator end = str.end(); - - while (it1 != end) - { - if (options & TOK_TRIM) - { - while (it1 != end && IsSpace(*it1)) ++it1; - } - it2 = it1; - while (it2 != end && separators.find(*it2) == std::string::npos) ++it2; - it3 = it2; - if (it3 != it1 && (options & TOK_TRIM)) - { - --it3; - while (it3 != it1 && IsSpace(*it3)) --it3; - if (!IsSpace(*it3)) ++it3; - } - if (options & TOK_IGNORE_EMPTY) - { - if (it3 != it1) - tokens.push_back(std::string(it1, it3)); - } - else - { - tokens.push_back(std::string(it1, it3)); - } - it1 = it2; - if (it1 != end) ++it1; - } -} - -std::string String::Chrtos( char byte) -{ - std::string str; - size_t len = 0; - char buf[24] = {0}; - size_t size = 23; - switch(byte) { - case '\\': - case '"': - len = _snprintf(buf,size,"\\%c",byte); - break; - case '\n': len = _snprintf(buf,size,"\\n"); break; - case '\r': len = _snprintf(buf,size,"\\r"); break; - case '\t': len = _snprintf(buf,size,"\\t"); break; - case '\a': len = _snprintf(buf,size,"\\a"); break; - case '\b': len = _snprintf(buf,size,"\\b"); break; - default: - if (byte >= 33 && byte <=93) - len = _snprintf(buf,size,"%c",byte); - else - len = _snprintf(buf,size,"\\x%02x",(unsigned char)byte); - break; - } - str.assign(buf, len); - return str; -} - +#include "stdafx.h" +#include "String.h" + +namespace Base { + +bool String::IsSpace( const char& ch ) +{ + return ch==' '; +} + +void String::Split(const std::string& str, const std::string& separators, TSeqStr& tokens, int options) +{ + std::string::const_iterator it1 = str.begin(); + std::string::const_iterator it2; + std::string::const_iterator it3; + std::string::const_iterator end = str.end(); + + while (it1 != end) + { + if (options & TOK_TRIM) + { + while (it1 != end && IsSpace(*it1)) ++it1; + } + it2 = it1; + while (it2 != end && separators.find(*it2) == std::string::npos) ++it2; + it3 = it2; + if (it3 != it1 && (options & TOK_TRIM)) + { + --it3; + while (it3 != it1 && IsSpace(*it3)) --it3; + if (!IsSpace(*it3)) ++it3; + } + if (options & TOK_IGNORE_EMPTY) + { + if (it3 != it1) + tokens.push_back(std::string(it1, it3)); + } + else + { + tokens.push_back(std::string(it1, it3)); + } + it1 = it2; + if (it1 != end) ++it1; + } +} + +std::string String::Chrtos( char byte) +{ + std::string str; + size_t len = 0; + char buf[24] = {0}; + size_t size = 23; + switch(byte) { + case '\\': + case '"': + len = _snprintf(buf,size,"\\%c",byte); + break; + case '\n': len = _snprintf(buf,size,"\\n"); break; + case '\r': len = _snprintf(buf,size,"\\r"); break; + case '\t': len = _snprintf(buf,size,"\\t"); break; + case '\a': len = _snprintf(buf,size,"\\a"); break; + case '\b': len = _snprintf(buf,size,"\\b"); break; + default: + if (byte >= 33 && byte <=93) + len = _snprintf(buf,size,"%c",byte); + else + len = _snprintf(buf,size,"\\x%02x",(unsigned char)byte); + break; + } + str.assign(buf, len); + return str; +} + } // namespace Base \ No newline at end of file diff --git a/RedisStudio/Base/String.h b/RedisStudio/Base/String.h index 7a88038..378efa3 100644 --- a/RedisStudio/Base/String.h +++ b/RedisStudio/Base/String.h @@ -1,29 +1,29 @@ -#ifndef Base_String_INCLUDED -#define Base_String_INCLUDED - -#include -#include - -namespace Base { - -class String -{ -public: - typedef std::vector TSeqStr; -public: - enum Options - { - TOK_IGNORE_EMPTY = 1, /// ignore empty tokens - TOK_TRIM = 2 /// remove leading and trailing whitespace from tokens - }; - - static bool IsSpace(const char& ch); - - static void Split(const std::string& str, const std::string& separators, TSeqStr& tokens, int options=0); - - static std::string Chrtos(char byte); -}; - -} // namespace Base - +#ifndef Base_String_INCLUDED +#define Base_String_INCLUDED + +#include +#include + +namespace Base { + +class String +{ +public: + typedef std::vector TSeqStr; +public: + enum Options + { + TOK_IGNORE_EMPTY = 1, /// ignore empty tokens + TOK_TRIM = 2 /// remove leading and trailing whitespace from tokens + }; + + static bool IsSpace(const char& ch); + + static void Split(const std::string& str, const std::string& separators, TSeqStr& tokens, int options=0); + + static std::string Chrtos(char byte); +}; + +} // namespace Base + #endif \ No newline at end of file diff --git a/RedisStudio/Base/Thread.cpp b/RedisStudio/Base/Thread.cpp index d699844..972d73c 100644 --- a/RedisStudio/Base/Thread.cpp +++ b/RedisStudio/Base/Thread.cpp @@ -1,197 +1,197 @@ -#include "StdAfx.h" -#include "Thread.h" -#include -#include - -namespace Base { - - -Thread::CurrentThreadHolder Thread::_currentThreadHolder; - - -Thread::Thread(): - _pRunnableTarget(0), - _thread(0), - _threadId(0), - _prio(PRIO_NORMAL_IMPL), - _stackSize(0) // os default -{ -} - - -Thread::~Thread() -{ - if (_thread) CloseHandle(_thread); -} - - -void Thread::setPriority(int prio) -{ - if (prio != _prio) - { - _prio = prio; - if (_thread) - { - if (SetThreadPriority(_thread, _prio) == 0) - throw std::exception("cannot set thread priority"); - } - } -} - - -void Thread::setOSPriority(int prio, int /* policy */) -{ - setPriority(prio); -} - - -void Thread::start(Runnable& target) -{ - if (isRunning()) - throw std::exception("thread already running"); - - _pRunnableTarget = ⌖ - - create(runnableEntry, this); -} - - -void Thread::start(Callable target, void* pData) -{ - if (isRunning()) - throw std::exception("thread already running"); - - threadCleanup(); - _callbackTarget.callback = target; - _callbackTarget.pData = pData; - - create(callableEntry, this); -} - - -void Thread::create(Entry ent, void* pData) -{ -#if defined(_DLL) - _thread = CreateThread(NULL, _stackSize, ent, pData, 0, &_threadId); -#else - unsigned threadId; - _thread = (HANDLE) _beginthreadex(NULL, _stackSize, ent, this, 0, &threadId); - _threadId = static_cast(threadId); -#endif - if (!_thread) - throw std::exception("cannot create thread"); - if (_prio != PRIO_NORMAL_IMPL && !SetThreadPriority(_thread, _prio)) - throw std::exception("cannot set thread priority"); -} - - -void Thread::join() -{ - if (!_thread) return; - - switch (WaitForSingleObject(_thread, INFINITE)) - { - case WAIT_OBJECT_0: - threadCleanup(); - return; - default: - throw std::exception("cannot join thread"); - } -} - - -bool Thread::join(long milliseconds) -{ - if (!_thread) return true; - - switch (WaitForSingleObject(_thread, milliseconds + 1)) - { - case WAIT_TIMEOUT: - return false; - case WAIT_OBJECT_0: - threadCleanup(); - return true; - default: - throw std::exception("cannot join thread"); - } -} - - -bool Thread::isRunning() const -{ - if (_thread) - { - DWORD ec = 0; - return GetExitCodeThread(_thread, &ec) && ec == STILL_ACTIVE; - } - return false; -} - - -void Thread::threadCleanup() -{ - if (!_thread) return; - if (CloseHandle(_thread)) _thread = 0; -} - - -Thread* Thread::current() -{ - return _currentThreadHolder.get(); -} - - -Thread::TIDImpl Thread::currentTid() -{ - return GetCurrentThreadId(); -} - - -#if defined(_DLL) -DWORD WINAPI Thread::runnableEntry(LPVOID pThread) -#else -unsigned __stdcall Thread::runnableEntry(void* pThread) -#endif -{ - _currentThreadHolder.set(reinterpret_cast(pThread)); - try - { - reinterpret_cast(pThread)->_pRunnableTarget->run(); - } - catch (std::exception& exc) - { - (void)exc; - } - catch (...) - { - - } - return 0; -} - - -#if defined(_DLL) -DWORD WINAPI Thread::callableEntry(LPVOID pThread) -#else -unsigned __stdcall Thread::callableEntry(void* pThread) -#endif -{ - _currentThreadHolder.set(reinterpret_cast(pThread)); - try - { - Thread* pTI = reinterpret_cast(pThread); - pTI->_callbackTarget.callback(pTI->_callbackTarget.pData); - } - catch (std::exception& exc) - { - (void)exc; - } - catch (...) - { - - } - return 0; -} - - -} // namespace Poco +#include "StdAfx.h" +#include "Thread.h" +#include +#include + +namespace Base { + + +Thread::CurrentThreadHolder Thread::_currentThreadHolder; + + +Thread::Thread(): + _pRunnableTarget(0), + _thread(0), + _threadId(0), + _prio(PRIO_NORMAL_IMPL), + _stackSize(0) // os default +{ +} + + +Thread::~Thread() +{ + if (_thread) CloseHandle(_thread); +} + + +void Thread::setPriority(int prio) +{ + if (prio != _prio) + { + _prio = prio; + if (_thread) + { + if (SetThreadPriority(_thread, _prio) == 0) + throw std::exception("cannot set thread priority"); + } + } +} + + +void Thread::setOSPriority(int prio, int /* policy */) +{ + setPriority(prio); +} + + +void Thread::start(Runnable& target) +{ + if (isRunning()) + throw std::exception("thread already running"); + + _pRunnableTarget = ⌖ + + create(runnableEntry, this); +} + + +void Thread::start(Callable target, void* pData) +{ + if (isRunning()) + throw std::exception("thread already running"); + + threadCleanup(); + _callbackTarget.callback = target; + _callbackTarget.pData = pData; + + create(callableEntry, this); +} + + +void Thread::create(Entry ent, void* pData) +{ +#if defined(_DLL) + _thread = CreateThread(NULL, _stackSize, ent, pData, 0, &_threadId); +#else + unsigned threadId; + _thread = (HANDLE) _beginthreadex(NULL, _stackSize, ent, this, 0, &threadId); + _threadId = static_cast(threadId); +#endif + if (!_thread) + throw std::exception("cannot create thread"); + if (_prio != PRIO_NORMAL_IMPL && !SetThreadPriority(_thread, _prio)) + throw std::exception("cannot set thread priority"); +} + + +void Thread::join() +{ + if (!_thread) return; + + switch (WaitForSingleObject(_thread, INFINITE)) + { + case WAIT_OBJECT_0: + threadCleanup(); + return; + default: + throw std::exception("cannot join thread"); + } +} + + +bool Thread::join(long milliseconds) +{ + if (!_thread) return true; + + switch (WaitForSingleObject(_thread, milliseconds + 1)) + { + case WAIT_TIMEOUT: + return false; + case WAIT_OBJECT_0: + threadCleanup(); + return true; + default: + throw std::exception("cannot join thread"); + } +} + + +bool Thread::isRunning() const +{ + if (_thread) + { + DWORD ec = 0; + return GetExitCodeThread(_thread, &ec) && ec == STILL_ACTIVE; + } + return false; +} + + +void Thread::threadCleanup() +{ + if (!_thread) return; + if (CloseHandle(_thread)) _thread = 0; +} + + +Thread* Thread::current() +{ + return _currentThreadHolder.get(); +} + + +Thread::TIDImpl Thread::currentTid() +{ + return GetCurrentThreadId(); +} + + +#if defined(_DLL) +DWORD WINAPI Thread::runnableEntry(LPVOID pThread) +#else +unsigned __stdcall Thread::runnableEntry(void* pThread) +#endif +{ + _currentThreadHolder.set(reinterpret_cast(pThread)); + try + { + reinterpret_cast(pThread)->_pRunnableTarget->run(); + } + catch (std::exception& exc) + { + (void)exc; + } + catch (...) + { + + } + return 0; +} + + +#if defined(_DLL) +DWORD WINAPI Thread::callableEntry(LPVOID pThread) +#else +unsigned __stdcall Thread::callableEntry(void* pThread) +#endif +{ + _currentThreadHolder.set(reinterpret_cast(pThread)); + try + { + Thread* pTI = reinterpret_cast(pThread); + pTI->_callbackTarget.callback(pTI->_callbackTarget.pData); + } + catch (std::exception& exc) + { + (void)exc; + } + catch (...) + { + + } + return 0; +} + + +} // namespace Poco diff --git a/RedisStudio/Base/Thread.h b/RedisStudio/Base/Thread.h index b776041..079e9b8 100644 --- a/RedisStudio/Base/Thread.h +++ b/RedisStudio/Base/Thread.h @@ -1,182 +1,182 @@ -#ifndef Base_Thread_INCLUDED -#define Base_Thread_INCLUDED - -#include -#include "Runnable.h" - -namespace Base { - - -class Thread -{ -public: - typedef DWORD TIDImpl; - typedef void (*Callable)(void*); - -#if defined(_DLL) - typedef DWORD (WINAPI *Entry)(LPVOID); -#else - typedef unsigned (__stdcall *Entry)(void*); -#endif - - struct CallbackData - { - CallbackData(): callback(0), pData(0) - { - } - - Callable callback; - void* pData; - }; - - enum Priority - { - PRIO_LOWEST_IMPL = THREAD_PRIORITY_LOWEST, - PRIO_LOW_IMPL = THREAD_PRIORITY_BELOW_NORMAL, - PRIO_NORMAL_IMPL = THREAD_PRIORITY_NORMAL, - PRIO_HIGH_IMPL = THREAD_PRIORITY_ABOVE_NORMAL, - PRIO_HIGHEST_IMPL = THREAD_PRIORITY_HIGHEST - }; - - enum Policy - { - POLICY_DEFAULT_IMPL = 0 - }; - - Thread(); - ~Thread(); - - TIDImpl tid() const; - void setPriority(int prio); - int getPriority() const; - void setOSPriority(int prio, int policy = 0); - int getOSPriority() const; - static int getMinOSPriority(int policy); - static int getMaxOSPriority(int policy); - void setStackSize(int size); - int getStackSize() const; - void start(Runnable& target); - void start(Callable target, void* pData = 0); - - void join(); - bool join(long milliseconds); - bool isRunning() const; - static void sleep(long milliseconds); - static void yieldImpl(); - static Thread* current(); - static TIDImpl currentTid(); - -protected: -#if defined(_DLL) - static DWORD WINAPI runnableEntry(LPVOID pThread); -#else - static unsigned __stdcall runnableEntry(void* pThread); -#endif - -#if defined(_DLL) - static DWORD WINAPI callableEntry(LPVOID pThread); -#else - static unsigned __stdcall callableEntry(void* pThread); -#endif - - void create(Entry ent, void* pData); - void threadCleanup(); - -private: - class CurrentThreadHolder - { - public: - CurrentThreadHolder(): _slot(TlsAlloc()) - { - if (_slot == TLS_OUT_OF_INDEXES) - throw std::exception("cannot allocate thread context key"); - } - ~CurrentThreadHolder() - { - TlsFree(_slot); - } - Thread* get() const - { - return reinterpret_cast(TlsGetValue(_slot)); - } - void set(Thread* pThread) - { - TlsSetValue(_slot, pThread); - } - - private: - DWORD _slot; - }; - - Runnable* _pRunnableTarget; - CallbackData _callbackTarget; - HANDLE _thread; - DWORD _threadId; - int _prio; - int _stackSize; - - static CurrentThreadHolder _currentThreadHolder; -}; - - -// -// inlines -// -inline int Thread::getPriority() const -{ - return _prio; -} - - -inline int Thread::getOSPriority() const -{ - return _prio; -} - - -inline int Thread::getMinOSPriority(int /* policy */) -{ - return PRIO_LOWEST_IMPL; -} - - -inline int Thread::getMaxOSPriority(int /* policy */) -{ - return PRIO_HIGHEST_IMPL; -} - - -inline void Thread::sleep(long milliseconds) -{ - Sleep(DWORD(milliseconds)); -} - - -inline void Thread::yieldImpl() -{ - Sleep(0); -} - - -inline void Thread::setStackSize(int size) -{ - _stackSize = size; -} - - -inline int Thread::getStackSize() const -{ - return _stackSize; -} - - -inline Thread::TIDImpl Thread::tid() const -{ - return _threadId; -} - - -} // namespace Base - - -#endif // Base_Thread_INCLUDED +#ifndef Base_Thread_INCLUDED +#define Base_Thread_INCLUDED + +#include +#include "Runnable.h" + +namespace Base { + + +class Thread +{ +public: + typedef DWORD TIDImpl; + typedef void (*Callable)(void*); + +#if defined(_DLL) + typedef DWORD (WINAPI *Entry)(LPVOID); +#else + typedef unsigned (__stdcall *Entry)(void*); +#endif + + struct CallbackData + { + CallbackData(): callback(0), pData(0) + { + } + + Callable callback; + void* pData; + }; + + enum Priority + { + PRIO_LOWEST_IMPL = THREAD_PRIORITY_LOWEST, + PRIO_LOW_IMPL = THREAD_PRIORITY_BELOW_NORMAL, + PRIO_NORMAL_IMPL = THREAD_PRIORITY_NORMAL, + PRIO_HIGH_IMPL = THREAD_PRIORITY_ABOVE_NORMAL, + PRIO_HIGHEST_IMPL = THREAD_PRIORITY_HIGHEST + }; + + enum Policy + { + POLICY_DEFAULT_IMPL = 0 + }; + + Thread(); + ~Thread(); + + TIDImpl tid() const; + void setPriority(int prio); + int getPriority() const; + void setOSPriority(int prio, int policy = 0); + int getOSPriority() const; + static int getMinOSPriority(int policy); + static int getMaxOSPriority(int policy); + void setStackSize(int size); + int getStackSize() const; + void start(Runnable& target); + void start(Callable target, void* pData = 0); + + void join(); + bool join(long milliseconds); + bool isRunning() const; + static void sleep(long milliseconds); + static void yieldImpl(); + static Thread* current(); + static TIDImpl currentTid(); + +protected: +#if defined(_DLL) + static DWORD WINAPI runnableEntry(LPVOID pThread); +#else + static unsigned __stdcall runnableEntry(void* pThread); +#endif + +#if defined(_DLL) + static DWORD WINAPI callableEntry(LPVOID pThread); +#else + static unsigned __stdcall callableEntry(void* pThread); +#endif + + void create(Entry ent, void* pData); + void threadCleanup(); + +private: + class CurrentThreadHolder + { + public: + CurrentThreadHolder(): _slot(TlsAlloc()) + { + if (_slot == TLS_OUT_OF_INDEXES) + throw std::exception("cannot allocate thread context key"); + } + ~CurrentThreadHolder() + { + TlsFree(_slot); + } + Thread* get() const + { + return reinterpret_cast(TlsGetValue(_slot)); + } + void set(Thread* pThread) + { + TlsSetValue(_slot, pThread); + } + + private: + DWORD _slot; + }; + + Runnable* _pRunnableTarget; + CallbackData _callbackTarget; + HANDLE _thread; + DWORD _threadId; + int _prio; + int _stackSize; + + static CurrentThreadHolder _currentThreadHolder; +}; + + +// +// inlines +// +inline int Thread::getPriority() const +{ + return _prio; +} + + +inline int Thread::getOSPriority() const +{ + return _prio; +} + + +inline int Thread::getMinOSPriority(int /* policy */) +{ + return PRIO_LOWEST_IMPL; +} + + +inline int Thread::getMaxOSPriority(int /* policy */) +{ + return PRIO_HIGHEST_IMPL; +} + + +inline void Thread::sleep(long milliseconds) +{ + Sleep(DWORD(milliseconds)); +} + + +inline void Thread::yieldImpl() +{ + Sleep(0); +} + + +inline void Thread::setStackSize(int size) +{ + _stackSize = size; +} + + +inline int Thread::getStackSize() const +{ + return _stackSize; +} + + +inline Thread::TIDImpl Thread::tid() const +{ + return _threadId; +} + + +} // namespace Base + + +#endif // Base_Thread_INCLUDED diff --git a/RedisStudio/ConnInfoSubWhd.cpp b/RedisStudio/ConnInfoSubWhd.cpp index c55c54c..8e9a072 100644 --- a/RedisStudio/ConnInfoSubWhd.cpp +++ b/RedisStudio/ConnInfoSubWhd.cpp @@ -1,204 +1,203 @@ -#include "stdafx.h" -#include -#include "ConnInfoSubWhd.h" -#include "ConnInfoUI.h" -#include "Base/CharacterSet.h" -#include "UserMessage.h" - - -DUI_BEGIN_MESSAGE_MAP(ConnInfoSubWhd, WindowImplBase) -DUI_ON_MSGTYPE(DUI_MSGTYPE_CLICK,OnClick) -DUI_END_MESSAGE_MAP() - -ConnInfoSubWhd::ConnInfoSubWhd(TDicTables* pDic, bool &needApply, OperatorType type, int celIdx) -{ - ASSERT(pDic); - m_pdicServerInfo = pDic; - m_celIdx = celIdx; - m_type = type; - m_needApply = &needApply; -} - -ConnInfoSubWhd::~ConnInfoSubWhd(void) -{ -} - -void ConnInfoSubWhd::InitWindow() -{ - TDicTables& dicObj = *m_pdicServerInfo; - m_pEditName = static_cast(m_PaintManager.FindControl(_T("edt_server_name"))); - m_pEditHost = static_cast(m_PaintManager.FindControl(_T("edt_server_ip"))); - m_pEditPort = static_cast(m_PaintManager.FindControl(_T("edt_server_port"))); - m_pEditAuth = static_cast(m_PaintManager.FindControl(_T("edt_server_passwd"))); - CLabelUI* pLabelAdd = static_cast(m_PaintManager.FindControl(_T("lab_conn_add"))); - CLabelUI* pLabelAlt = static_cast(m_PaintManager.FindControl(_T("lab_conn_alt"))); - if (m_type == Type_Add) - { - pLabelAdd->SetVisible(true); - pLabelAlt->SetVisible(false); - } - else - { - m_pEditName->SetText(Base::CharacterSet::ANSIToUnicode(dicObj[ConnInfoUI::kServerNameIndex][m_celIdx]).c_str()); - m_pEditHost->SetText(Base::CharacterSet::ANSIToUnicode(dicObj[ConnInfoUI::kServerIpIndex][m_celIdx]).c_str()); - m_pEditPort->SetText(Base::CharacterSet::ANSIToUnicode(dicObj[ConnInfoUI::kServerPortIndex][m_celIdx]).c_str()); - m_pEditAuth->SetText(Base::CharacterSet::ANSIToUnicode(dicObj[ConnInfoUI::kServerAuthIndex][m_celIdx]).c_str()); - pLabelAdd->SetVisible(false); - pLabelAlt->SetVisible(true); - } - *m_needApply = false; -} - - - -LPCTSTR ConnInfoSubWhd::GetWindowClassName() const -{ - return _T("UIConnInfoSubWhd"); -} - - -UINT ConnInfoSubWhd::GetClassStyle() const -{ - return UI_CLASSSTYLE_DIALOG; -} - - -void ConnInfoSubWhd::OnFinalMessage( HWND hWnd) -{ - delete this; -} - - -DuiLib::UILIB_RESOURCETYPE ConnInfoSubWhd::GetResourceType() const -{ - return UILIB_FILE; -} - -DuiLib::CDuiString ConnInfoSubWhd::GetSkinFolder() -{ - return _T("..\\skin\\"); -} - -DuiLib::CDuiString ConnInfoSubWhd::GetSkinFile() -{ - return _T("ConnSubInfo.xml"); -} - -LRESULT ConnInfoSubWhd::HandleCustomMessage( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled ) -{ - return 0; -} - -void ConnInfoSubWhd::OnClick( TNotifyUI& msg ) -{ - if(msg.pSender->GetName() == _T("btn_conn_cancel")) - { - Close(); - *m_needApply = false; - return; - } - else if (msg.pSender->GetName() == _T("btn_conn_save")) - { - bool retVal = false; - if (m_type == Type_Add) - { - retVal = OnAddInfo(); - } - else - { - retVal = OnAltInfo(); - } - if (retVal) - { - *m_needApply = true; - } - else - { - *m_needApply = false; - } - Close(); - } -} - -bool ConnInfoSubWhd::OnAddInfo() -{ - std::string name = Base::CharacterSet::UnicodeToANSI(m_pEditName->GetText().GetData()); - CDuiString ipStr = m_pEditHost->GetText(); - ipStr.Replace(_T(" "), _T("")); - std::string ip = Base::CharacterSet::UnicodeToANSI(ipStr.GetData()); - - CDuiString portStr = m_pEditPort->GetText(); - portStr.Replace(_T(" "), _T("")); - std::string port = Base::CharacterSet::UnicodeToANSI(portStr.GetData()); - std::string auth = Base::CharacterSet::UnicodeToANSI(m_pEditAuth->GetText().GetData()); - - if (name.empty()) - { - CDuiString CtlName = m_pEditName->GetName(); - CtlName.Replace(_T("edt"), _T("lbl") ); - CLabelUI* pLbl = static_cast (m_PaintManager.FindControl(CtlName)); - UserMessageBox(GetHWND(), 10011, pLbl->GetText(), MB_ICONINFORMATION); - return false; - } - if (ip.empty()) - { - CDuiString CtlName = m_pEditHost->GetName(); - CtlName.Replace(_T("edt"), _T("lbl") ); - CLabelUI* pLbl = static_cast (m_PaintManager.FindControl(CtlName)); - UserMessageBox(GetHWND(), 10011, pLbl->GetText(), MB_ICONINFORMATION); - return false; - } - if (port.empty()) - { - CDuiString CtlName = m_pEditPort->GetName(); - CtlName.Replace(_T("edt"), _T("lbl") ); - CLabelUI* pLbl = static_cast (m_PaintManager.FindControl(CtlName)); - UserMessageBox(GetHWND(), 10011, pLbl->GetText(), MB_ICONINFORMATION); - return false; - } - TDicTables& dicObj = *m_pdicServerInfo; - for (std::size_t idx=0; idxGetText().GetData()); - - /// ×ÔśŻČĽłýżŐ¸ń - CDuiString ipStr = m_pEditHost->GetText(); - ipStr.Replace(_T(" "), _T("")); - std::string ip = Base::CharacterSet::UnicodeToANSI(ipStr.GetData()); - - CDuiString portStr = m_pEditPort->GetText(); - portStr.Replace(_T(" "), _T("")); - std::string port = Base::CharacterSet::UnicodeToANSI(portStr.GetData()); - - std::string auth = Base::CharacterSet::UnicodeToANSI(m_pEditAuth->GetText().GetData()); - TDicTables& dicObj = *m_pdicServerInfo; - for (std::size_t idx=0; idx +#include "ConnInfoSubWhd.h" +#include "ConnInfoUI.h" +#include "Base/CharacterSet.h" +#include "UserMessage.h" + + +DUI_BEGIN_MESSAGE_MAP(ConnInfoSubWhd, WindowImplBase) +DUI_ON_MSGTYPE(DUI_MSGTYPE_CLICK,OnClick) +DUI_END_MESSAGE_MAP() + +ConnInfoSubWhd::ConnInfoSubWhd(TDicTables* pDic, bool &needApply, OperatorType type, int celIdx) +{ + ASSERT(pDic); + m_pdicServerInfo = pDic; + m_celIdx = celIdx; + m_type = type; + m_needApply = &needApply; +} + +ConnInfoSubWhd::~ConnInfoSubWhd(void) +{ +} + +void ConnInfoSubWhd::InitWindow() +{ + TDicTables& dicObj = *m_pdicServerInfo; + m_pEditName = static_cast(m_PaintManager.FindControl(_T("edt_server_name"))); + m_pEditHost = static_cast(m_PaintManager.FindControl(_T("edt_server_ip"))); + m_pEditPort = static_cast(m_PaintManager.FindControl(_T("edt_server_port"))); + m_pEditAuth = static_cast(m_PaintManager.FindControl(_T("edt_server_passwd"))); + CLabelUI* pLabelAdd = static_cast(m_PaintManager.FindControl(_T("lab_conn_add"))); + CLabelUI* pLabelAlt = static_cast(m_PaintManager.FindControl(_T("lab_conn_alt"))); + if (m_type == Type_Add) + { + pLabelAdd->SetVisible(true); + pLabelAlt->SetVisible(false); + } + else + { + m_pEditName->SetText(Base::CharacterSet::ANSIToUnicode(dicObj[ConnInfoUI::kServerNameIndex][m_celIdx]).c_str()); + m_pEditHost->SetText(Base::CharacterSet::ANSIToUnicode(dicObj[ConnInfoUI::kServerIpIndex][m_celIdx]).c_str()); + m_pEditPort->SetText(Base::CharacterSet::ANSIToUnicode(dicObj[ConnInfoUI::kServerPortIndex][m_celIdx]).c_str()); + m_pEditAuth->SetText(Base::CharacterSet::ANSIToUnicode(dicObj[ConnInfoUI::kServerAuthIndex][m_celIdx]).c_str()); + pLabelAdd->SetVisible(false); + pLabelAlt->SetVisible(true); + } + *m_needApply = false; +} + + + +LPCTSTR ConnInfoSubWhd::GetWindowClassName() const +{ + return _T("UIConnInfoSubWhd"); +} + + +UINT ConnInfoSubWhd::GetClassStyle() const +{ + return UI_CLASSSTYLE_DIALOG; +} + + +void ConnInfoSubWhd::OnFinalMessage( HWND hWnd) +{ + delete this; +} + + +DuiLib::UILIB_RESOURCETYPE ConnInfoSubWhd::GetResourceType() const +{ + return UILIB_FILE; +} + +DuiLib::CDuiString ConnInfoSubWhd::GetSkinFolder() +{ + return _T("..\\skin\\"); +} + +DuiLib::CDuiString ConnInfoSubWhd::GetSkinFile() +{ + return _T("ConnSubInfo.xml"); +} + +LRESULT ConnInfoSubWhd::HandleCustomMessage( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled ) +{ + return 0; +} + +void ConnInfoSubWhd::OnClick( TNotifyUI& msg ) +{ + if(msg.pSender->GetName() == _T("btn_conn_cancel")) + { + Close(); + *m_needApply = false; + return; + } + else if (msg.pSender->GetName() == _T("btn_conn_save")) + { + bool retVal = false; + if (m_type == Type_Add) + { + retVal = OnAddInfo(); + } + else + { + retVal = OnAltInfo(); + } + if (retVal) + { + *m_needApply = true; + } + else + { + *m_needApply = false; + } + Close(); + } +} + +bool ConnInfoSubWhd::OnAddInfo() +{ + std::string name = Base::CharacterSet::UnicodeToANSI(m_pEditName->GetText().GetData()); + CDuiString ipStr = m_pEditHost->GetText(); + ipStr.Replace(_T(" "), _T("")); + std::string ip = Base::CharacterSet::UnicodeToANSI(ipStr.GetData()); + + CDuiString portStr = m_pEditPort->GetText(); + portStr.Replace(_T(" "), _T("")); + std::string port = Base::CharacterSet::UnicodeToANSI(portStr.GetData()); + std::string auth = Base::CharacterSet::UnicodeToANSI(m_pEditAuth->GetText().GetData()); + + if (name.empty()) + { + CDuiString CtlName = m_pEditName->GetName(); + CtlName.Replace(_T("edt"), _T("lbl") ); + CLabelUI* pLbl = static_cast (m_PaintManager.FindControl(CtlName)); + UserMessageBox(GetHWND(), 10011, pLbl->GetText(), MB_ICONINFORMATION); + return false; + } + if (ip.empty()) + { + CDuiString CtlName = m_pEditHost->GetName(); + CtlName.Replace(_T("edt"), _T("lbl") ); + CLabelUI* pLbl = static_cast (m_PaintManager.FindControl(CtlName)); + UserMessageBox(GetHWND(), 10011, pLbl->GetText(), MB_ICONINFORMATION); + return false; + } + if (port.empty()) + { + CDuiString CtlName = m_pEditPort->GetName(); + CtlName.Replace(_T("edt"), _T("lbl") ); + CLabelUI* pLbl = static_cast (m_PaintManager.FindControl(CtlName)); + UserMessageBox(GetHWND(), 10011, pLbl->GetText(), MB_ICONINFORMATION); + return false; + } + TDicTables& dicObj = *m_pdicServerInfo; + for (std::size_t idx=0; idxGetText().GetData()); + + CDuiString ipStr = m_pEditHost->GetText(); + ipStr.Replace(_T(" "), _T("")); + std::string ip = Base::CharacterSet::UnicodeToANSI(ipStr.GetData()); + + CDuiString portStr = m_pEditPort->GetText(); + portStr.Replace(_T(" "), _T("")); + std::string port = Base::CharacterSet::UnicodeToANSI(portStr.GetData()); + + std::string auth = Base::CharacterSet::UnicodeToANSI(m_pEditAuth->GetText().GetData()); + TDicTables& dicObj = *m_pdicServerInfo; + for (std::size_t idx=0; idx -#include - -class ConnInfoSubWhd : public WindowImplBase -{ -private: - typedef std::vector TSeqColumn; - typedef std::map TDicTables; - -public: - enum OperatorType - { - Type_Add, - Type_Alt - }; -public: - ConnInfoSubWhd(TDicTables* pDic, bool &needApply, OperatorType type, int celIdx=0); - - ~ConnInfoSubWhd(void); - - void InitWindow(); - - LPCTSTR GetWindowClassName() const; - - UINT GetClassStyle() const;; - - void OnFinalMessage(HWND hWnd);; - - virtual CDuiString GetSkinFolder(); - - virtual CDuiString GetSkinFile(); - - virtual UILIB_RESOURCETYPE GetResourceType() const; - - virtual LRESULT HandleCustomMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - - DUI_DECLARE_MESSAGE_MAP() - - virtual void OnClick(TNotifyUI& msg); - - bool OnAddInfo(); - - bool OnAltInfo(); - -private: - bool* m_needApply; - TDicTables* m_pdicServerInfo; - - CEditUI* m_pEditName; - CEditUI* m_pEditHost; - CEditUI* m_pEditPort; - CEditUI* m_pEditAuth; - int m_celIdx; - OperatorType m_type; -}; +#pragma once + +#include +#include + +class ConnInfoSubWhd : public WindowImplBase +{ +private: + typedef std::vector TSeqColumn; + typedef std::map TDicTables; + +public: + enum OperatorType + { + Type_Add, + Type_Alt + }; +public: + ConnInfoSubWhd(TDicTables* pDic, bool &needApply, OperatorType type, int celIdx=0); + + ~ConnInfoSubWhd(void); + + void InitWindow(); + + LPCTSTR GetWindowClassName() const; + + UINT GetClassStyle() const;; + + void OnFinalMessage(HWND hWnd);; + + virtual CDuiString GetSkinFolder(); + + virtual CDuiString GetSkinFile(); + + virtual UILIB_RESOURCETYPE GetResourceType() const; + + virtual LRESULT HandleCustomMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + + DUI_DECLARE_MESSAGE_MAP() + + virtual void OnClick(TNotifyUI& msg); + + bool OnAddInfo(); + + bool OnAltInfo(); + +private: + bool* m_needApply; + TDicTables* m_pdicServerInfo; + + CEditUI* m_pEditName; + CEditUI* m_pEditHost; + CEditUI* m_pEditPort; + CEditUI* m_pEditAuth; + int m_celIdx; + OperatorType m_type; +}; diff --git a/RedisStudio/ConnInfoUI.cpp b/RedisStudio/ConnInfoUI.cpp index 5728ada..e329a5b 100644 Binary files a/RedisStudio/ConnInfoUI.cpp and b/RedisStudio/ConnInfoUI.cpp differ diff --git a/RedisStudio/ConnInfoUI.h b/RedisStudio/ConnInfoUI.h index 6e021be..7091d7d 100644 --- a/RedisStudio/ConnInfoUI.h +++ b/RedisStudio/ConnInfoUI.h @@ -1,71 +1,71 @@ -#pragma once - -#include "stdafx.h" -#include -#include -#include -#include "AbstractUI.h" -#include "hiredis/hiredis.h" - -class ConnInfoUI : public AbstraceUI,public IListCallbackUI -{ -public: - ConnInfoUI(const CDuiString& strXML, CPaintManagerUI* pm); - - void Initialize(); - - int GetIndex(); - - CDuiString GetVirtualwndName(); - - void RefreshWnd(); - - bool LoadConfig(const std::string& path); - - bool SaveConfig(const std::string& path); - - LPCTSTR GetItemText(CControlUI* pControl, int iIndex, int iSubItem); - - DUI_DECLARE_MESSAGE_MAP() - - virtual void OnClick(TNotifyUI& msg); - - virtual void OnSelectChanged( TNotifyUI &msg ); - - virtual void OnItemClick( TNotifyUI &msg ); - - virtual void OnItemActive( TNotifyUI &msg ); - - void OnAddConnInfo(TNotifyUI& msg); - - void OnDelConnInfo(TNotifyUI& msg); - - void OnAltConnInfo(TNotifyUI& msg); - - void OnRfhConnInfo(TNotifyUI& msg); - - void DoConnect(); - -private: - typedef std::vector TSeqColumn; - typedef std::map TDicTables; - TDicTables m_dicServerInfo; - - CListUI* m_pListUI; - -public: - static DWORD WINAPI BackgroundWork(LPVOID lpParameter); - static bool m_isConecting; - -public: - static const int kServerNameIndex = 0; - static const int kServerIpIndex = 1; - static const int kServerPortIndex = 2; - static const int kServerAuthIndex = 3; - -private: - CButtonUI* m_pAddBtn; - CButtonUI* m_pDelBtn; - CButtonUI* m_pAltBtn; - CButtonUI* m_pRfhBtn; +#pragma once + +#include "stdafx.h" +#include +#include +#include +#include "AbstractUI.h" +#include "hiredis/hiredis.h" + +class ConnInfoUI : public AbstraceUI,public IListCallbackUI +{ +public: + ConnInfoUI(const CDuiString& strXML, CPaintManagerUI* pm); + + void Initialize(); + + int GetIndex(); + + CDuiString GetVirtualwndName(); + + void RefreshWnd(); + + bool LoadConfig(const std::string& path); + + bool SaveConfig(const std::string& path); + + LPCTSTR GetItemText(CControlUI* pControl, int iIndex, int iSubItem); + + DUI_DECLARE_MESSAGE_MAP() + + virtual void OnClick(TNotifyUI& msg); + + virtual void OnSelectChanged( TNotifyUI &msg ); + + virtual void OnItemClick( TNotifyUI &msg ); + + virtual void OnItemActive( TNotifyUI &msg ); + + void OnAddConnInfo(TNotifyUI& msg); + + void OnDelConnInfo(TNotifyUI& msg); + + void OnAltConnInfo(TNotifyUI& msg); + + void OnRfhConnInfo(TNotifyUI& msg); + + void DoConnect(); + +private: + typedef std::vector TSeqColumn; + typedef std::map TDicTables; + TDicTables m_dicServerInfo; + + CListUI* m_pListUI; + +public: + static DWORD WINAPI BackgroundWork(LPVOID lpParameter); + static bool m_isConecting; + +public: + static const int kServerNameIndex = 0; + static const int kServerIpIndex = 1; + static const int kServerPortIndex = 2; + static const int kServerAuthIndex = 3; + +private: + CButtonUI* m_pAddBtn; + CButtonUI* m_pDelBtn; + CButtonUI* m_pAltBtn; + CButtonUI* m_pRfhBtn; }; \ No newline at end of file diff --git a/RedisStudio/DuiEx/ObserverBase.h b/RedisStudio/DuiEx/ObserverBase.h index 9d103db..c1d479f 100644 --- a/RedisStudio/DuiEx/ObserverBase.h +++ b/RedisStudio/DuiEx/ObserverBase.h @@ -1,186 +1,186 @@ -#ifndef OBSERVER_IMPL_BASE_HPP -#define OBSERVER_IMPL_BASE_HPP - -#include - -template -class ReceiverImplBase; - -template -class ObserverImplBase -{ -public: - virtual void AddReceiver(ReceiverImplBase* receiver) = 0; - virtual void RemoveReceiver(ReceiverImplBase* receiver) = 0; - virtual void RemoveAll() = 0; - virtual ReturnT Broadcast(ParamT param) = 0; - virtual ReturnT RBroadcast(ParamT param) = 0; - virtual ReturnT Notify(ParamT param) = 0; -}; - -template -class ReceiverImplBase -{ -public: - virtual void AddObserver(ObserverImplBase* observer) = 0; - virtual void RemoveObserver() = 0; - virtual ReturnT Receive(ParamT param) = 0; - virtual ReturnT Respond(ParamT param, ObserverImplBase* observer) = 0; -}; - -template -class ReceiverImpl; - -template -class ObserverImpl : public ObserverImplBase -{ - template - friend class Iterator; -public: - ObserverImpl() - {} - - virtual ~ObserverImpl() {} - - virtual void AddReceiver(ReceiverImplBase* receiver) - { - if (receiver == NULL) - return; - - receivers_.push_back(receiver); - receiver->AddObserver(this); - } - - virtual void RemoveReceiver(ReceiverImplBase* receiver) - { - if (receiver == NULL) - return; - - ReceiversVector::iterator it = receivers_.begin(); - for (; it != receivers_.end(); ++it) - { - if (*it == receiver) - { - receivers_.erase(it); - break; - } - } - } - - virtual void RemoveAll() - { - ReceiversVector::iterator it = receivers_.begin(); - for (; it != receivers_.end(); ) - { - it = receivers_.erase(it); - } - } - - virtual ReturnT Broadcast(ParamT param) - { - ReceiversVector::iterator it = receivers_.begin(); - for (; it != receivers_.end(); ++it) - { - (*it)->Receive(param); - } - - return ReturnT(); - } - - virtual ReturnT RBroadcast(ParamT param) - { - ReceiversVector::reverse_iterator it = receivers_.rbegin(); - for (; it != receivers_.rend(); ++it) - { - (*it)->Receive(param); - } - - return ReturnT(); - } - - virtual ReturnT Notify(ParamT param) - { - ReceiversVector::iterator it = receivers_.begin(); - for (; it != receivers_.end(); ++it) - { - (*it)->Respond(param, this); - } - - return ReturnT(); - } - - template - class Iterator - { - ObserverImpl & _tbl; - DWORD index; - ReceiverImplBase* ptr; - public: - Iterator( ObserverImpl & table ) - : _tbl( table ), index(0), ptr(NULL) - {} - - Iterator( const Iterator & v ) - : _tbl( v._tbl ), index(v.index), ptr(v.ptr) - {} - - ReceiverImplBase* next() - { - if ( index >= _tbl.receivers_.size() ) - return NULL; - - for ( ; index < _tbl.receivers_.size(); ) - { - ptr = _tbl.receivers_[ index++ ]; - if ( ptr ) - return ptr; - } - return NULL; - } - }; - -protected: - typedef std::vector*> ReceiversVector; - ReceiversVector receivers_; -}; - - -template -class ReceiverImpl : public ReceiverImplBase -{ -public: - ReceiverImpl() - {} - - virtual ~ReceiverImpl() {} - - virtual void AddObserver(ObserverImplBase* observer) - { - observers_.push_back(observer); - } - - virtual void RemoveObserver() - { - ObserversVector::iterator it = observers_.begin(); - for (; it != observers_.end(); ++it) - { - (*it)->RemoveReceiver(this); - } - } - - virtual ReturnT Receive(ParamT param) - { - return ReturnT(); - } - - virtual ReturnT Respond(ParamT param, ObserverImplBase* observer) - { - return ReturnT(); - } - -protected: - typedef std::vector*> ObserversVector; - ObserversVector observers_; -}; - +#ifndef OBSERVER_IMPL_BASE_HPP +#define OBSERVER_IMPL_BASE_HPP + +#include + +template +class ReceiverImplBase; + +template +class ObserverImplBase +{ +public: + virtual void AddReceiver(ReceiverImplBase* receiver) = 0; + virtual void RemoveReceiver(ReceiverImplBase* receiver) = 0; + virtual void RemoveAll() = 0; + virtual ReturnT Broadcast(ParamT param) = 0; + virtual ReturnT RBroadcast(ParamT param) = 0; + virtual ReturnT Notify(ParamT param) = 0; +}; + +template +class ReceiverImplBase +{ +public: + virtual void AddObserver(ObserverImplBase* observer) = 0; + virtual void RemoveObserver() = 0; + virtual ReturnT Receive(ParamT param) = 0; + virtual ReturnT Respond(ParamT param, ObserverImplBase* observer) = 0; +}; + +template +class ReceiverImpl; + +template +class ObserverImpl : public ObserverImplBase +{ + template + friend class Iterator; +public: + ObserverImpl() + {} + + virtual ~ObserverImpl() {} + + virtual void AddReceiver(ReceiverImplBase* receiver) + { + if (receiver == NULL) + return; + + receivers_.push_back(receiver); + receiver->AddObserver(this); + } + + virtual void RemoveReceiver(ReceiverImplBase* receiver) + { + if (receiver == NULL) + return; + + ReceiversVector::iterator it = receivers_.begin(); + for (; it != receivers_.end(); ++it) + { + if (*it == receiver) + { + receivers_.erase(it); + break; + } + } + } + + virtual void RemoveAll() + { + ReceiversVector::iterator it = receivers_.begin(); + for (; it != receivers_.end(); ) + { + it = receivers_.erase(it); + } + } + + virtual ReturnT Broadcast(ParamT param) + { + ReceiversVector::iterator it = receivers_.begin(); + for (; it != receivers_.end(); ++it) + { + (*it)->Receive(param); + } + + return ReturnT(); + } + + virtual ReturnT RBroadcast(ParamT param) + { + ReceiversVector::reverse_iterator it = receivers_.rbegin(); + for (; it != receivers_.rend(); ++it) + { + (*it)->Receive(param); + } + + return ReturnT(); + } + + virtual ReturnT Notify(ParamT param) + { + ReceiversVector::iterator it = receivers_.begin(); + for (; it != receivers_.end(); ++it) + { + (*it)->Respond(param, this); + } + + return ReturnT(); + } + + template + class Iterator + { + ObserverImpl & _tbl; + DWORD index; + ReceiverImplBase* ptr; + public: + Iterator( ObserverImpl & table ) + : _tbl( table ), index(0), ptr(NULL) + {} + + Iterator( const Iterator & v ) + : _tbl( v._tbl ), index(v.index), ptr(v.ptr) + {} + + ReceiverImplBase* next() + { + if ( index >= _tbl.receivers_.size() ) + return NULL; + + for ( ; index < _tbl.receivers_.size(); ) + { + ptr = _tbl.receivers_[ index++ ]; + if ( ptr ) + return ptr; + } + return NULL; + } + }; + +protected: + typedef std::vector*> ReceiversVector; + ReceiversVector receivers_; +}; + + +template +class ReceiverImpl : public ReceiverImplBase +{ +public: + ReceiverImpl() + {} + + virtual ~ReceiverImpl() {} + + virtual void AddObserver(ObserverImplBase* observer) + { + observers_.push_back(observer); + } + + virtual void RemoveObserver() + { + ObserversVector::iterator it = observers_.begin(); + for (; it != observers_.end(); ++it) + { + (*it)->RemoveReceiver(this); + } + } + + virtual ReturnT Receive(ParamT param) + { + return ReturnT(); + } + + virtual ReturnT Respond(ParamT param, ObserverImplBase* observer) + { + return ReturnT(); + } + +protected: + typedef std::vector*> ObserversVector; + ObserversVector observers_; +}; + #endif // OBSERVER_IMPL_BASE_HPP \ No newline at end of file diff --git a/RedisStudio/DuiEx/UIMenu.cpp b/RedisStudio/DuiEx/UIMenu.cpp index 026aef8..5bdbb27 100644 --- a/RedisStudio/DuiEx/UIMenu.cpp +++ b/RedisStudio/DuiEx/UIMenu.cpp @@ -1,713 +1,713 @@ -#include "StdAfx.h" -#include "UIMenu.h" - -namespace DuiLib { - -static ContextMenuObserver s_context_menu_observer; - -const TCHAR* const kMenuUIClassName = _T("MenuUI"); -const TCHAR* const kMenuUIInterfaceName = _T("Menu"); - -const TCHAR* const kMenuElementUIClassName = _T("MenuElementUI"); -const TCHAR* const kMenuElementUIInterfaceName = _T("MenuElement"); - - -CMenuUI::CMenuUI() -{ - if (GetHeader() != NULL) - GetHeader()->SetVisible(false); -} - -CMenuUI::~CMenuUI() -{} - -LPCTSTR CMenuUI::GetClass() const -{ - return kMenuUIClassName; -} - -LPVOID CMenuUI::GetInterface(LPCTSTR pstrName) -{ - if( _tcsicmp(pstrName, kMenuUIInterfaceName) == 0 ) return static_cast(this); - return CListUI::GetInterface(pstrName); -} - -void CMenuUI::DoEvent(TEventUI& event) -{ - return __super::DoEvent(event); -} - -bool CMenuUI::Add(CControlUI* pControl) -{ - CMenuElementUI* pMenuItem = static_cast(pControl->GetInterface(kMenuElementUIInterfaceName)); - if (pMenuItem == NULL) - return false; - - for (int i = 0; i < pMenuItem->GetCount(); ++i) - { - if (pMenuItem->GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName) != NULL) - { - (static_cast(pMenuItem->GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName)))->SetInternVisible(false); - } - } - return CListUI::Add(pControl); -} - -bool CMenuUI::AddAt(CControlUI* pControl, int iIndex) -{ - CMenuElementUI* pMenuItem = static_cast(pControl->GetInterface(kMenuElementUIInterfaceName)); - if (pMenuItem == NULL) - return false; - - for (int i = 0; i < pMenuItem->GetCount(); ++i) - { - if (pMenuItem->GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName) != NULL) - { - (static_cast(pMenuItem->GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName)))->SetInternVisible(false); - } - } - return CListUI::AddAt(pControl, iIndex); -} - -int CMenuUI::GetItemIndex(CControlUI* pControl) const -{ - CMenuElementUI* pMenuItem = static_cast(pControl->GetInterface(kMenuElementUIInterfaceName)); - if (pMenuItem == NULL) - return -1; - - return __super::GetItemIndex(pControl); -} - -bool CMenuUI::SetItemIndex(CControlUI* pControl, int iIndex) -{ - CMenuElementUI* pMenuItem = static_cast(pControl->GetInterface(kMenuElementUIInterfaceName)); - if (pMenuItem == NULL) - return false; - - return __super::SetItemIndex(pControl, iIndex); -} - -bool CMenuUI::Remove(CControlUI* pControl) -{ - CMenuElementUI* pMenuItem = static_cast(pControl->GetInterface(kMenuElementUIInterfaceName)); - if (pMenuItem == NULL) - return false; - - return __super::Remove(pControl); -} - -SIZE CMenuUI::EstimateSize(SIZE szAvailable) -{ - int cxFixed = 0; - int cyFixed = 0; - for( int it = 0; it < GetCount(); it++ ) { - CControlUI* pControl = static_cast(GetItemAt(it)); - if( !pControl->IsVisible() ) continue; - SIZE sz = pControl->EstimateSize(szAvailable); - cyFixed += sz.cy; - if( cxFixed < sz.cx ) - cxFixed = sz.cx; - } - return CSize(cxFixed, cyFixed); -} - -void CMenuUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue) -{ - CListUI::SetAttribute(pstrName, pstrValue); -} - -///////////////////////////////////////////////////////////////////////////////////// -// -class CMenuBuilderCallback: public IDialogBuilderCallback -{ - CControlUI* CreateControl(LPCTSTR pstrClass) - { - if (_tcsicmp(pstrClass, kMenuUIInterfaceName) == 0) - { - return new CMenuUI(); - } - else if (_tcsicmp(pstrClass, kMenuElementUIInterfaceName) == 0) - { - return new CMenuElementUI(); - } - return NULL; - } -}; - -CMenuWnd::CMenuWnd(HWND hParent): -m_hParent(hParent), -m_pOwner(NULL), -m_pLayout(), -m_xml(_T("")) -{} - -BOOL CMenuWnd::Receive(ContextMenuParam param) -{ - if (param.iType == UIEVENT_BUTTONDOWN && param.bLeaf==true) - { - TEventUI myEvent; - myEvent.pSender = param.pSender; - if (OnClick) OnClick(&myEvent); - } - switch (param.wParam) - { - case 1: - Close(); - break; - case 2: - { - HWND hParent = GetParent(m_hWnd); - while (hParent != NULL) - { - if (hParent == param.hWnd) - { - Close(); - break; - } - hParent = GetParent(hParent); - } - } - break; - default: - break; - } - - return TRUE; -} - -void CMenuWnd::Init(CMenuElementUI* pOwner, STRINGorID xml, LPCTSTR pSkinType, POINT point) -{ - m_BasedPoint = point; - m_pOwner = pOwner; - m_pLayout = NULL; - - if (pSkinType != NULL) - m_sType = pSkinType; - - m_xml = xml; - - s_context_menu_observer.AddReceiver(this); - - Create((m_pOwner == NULL) ? m_hParent : m_pOwner->GetManager()->GetPaintWindow(), NULL, WS_POPUP, WS_EX_TOOLWINDOW | WS_EX_TOPMOST, CDuiRect()); - // HACK: Don't deselect the parent's caption - HWND hWndParent = m_hWnd; - while( ::GetParent(hWndParent) != NULL ) hWndParent = ::GetParent(hWndParent); - ::ShowWindow(m_hWnd, SW_SHOW); -#if defined(WIN32) && !defined(UNDER_CE) - ::SendMessage(hWndParent, WM_NCACTIVATE, TRUE, 0L); -#endif -} - -LPCTSTR CMenuWnd::GetWindowClassName() const -{ - return _T("MenuWnd"); -} - -void CMenuWnd::OnFinalMessage(HWND hWnd) -{ - RemoveObserver(); - if( m_pOwner != NULL ) { - for( int i = 0; i < m_pOwner->GetCount(); i++ ) { - if( static_cast(m_pOwner->GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName)) != NULL ) { - (static_cast(m_pOwner->GetItemAt(i)))->SetOwner(m_pOwner->GetParent()); - (static_cast(m_pOwner->GetItemAt(i)))->SetVisible(false); - (static_cast(m_pOwner->GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName)))->SetInternVisible(false); - } - } - m_pOwner->m_pWindow = NULL; - m_pOwner->m_uButtonState &= ~ UISTATE_PUSHED; - m_pOwner->Invalidate(); - } - delete this; -} - -LRESULT CMenuWnd::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) -{ - if( uMsg == WM_CREATE ) { - if( m_pOwner != NULL) { - LONG styleValue = ::GetWindowLong(*this, GWL_STYLE); - styleValue &= ~WS_CAPTION; - ::SetWindowLong(*this, GWL_STYLE, styleValue | WS_CLIPSIBLINGS | WS_CLIPCHILDREN); - RECT rcClient; - ::GetClientRect(*this, &rcClient); - ::SetWindowPos(*this, NULL, rcClient.left, rcClient.top, rcClient.right - rcClient.left, \ - rcClient.bottom - rcClient.top, SWP_FRAMECHANGED); - - m_pm.Init(m_hWnd); - // The trick is to add the items to the new container. Their owner gets - // reassigned by this operation - which is why it is important to reassign - // the items back to the righfull owner/manager when the window closes. - m_pLayout = new CMenuUI(); - m_pm.UseParentResource(m_pOwner->GetManager()); - m_pLayout->SetManager(&m_pm, NULL, true); - LPCTSTR pDefaultAttributes = m_pOwner->GetManager()->GetDefaultAttributeList(kMenuUIInterfaceName); - if( pDefaultAttributes ) { - m_pLayout->ApplyAttributeList(pDefaultAttributes); - } - m_pLayout->SetBkColor(0xFFFFFFFF); - m_pLayout->SetBorderColor(0xFF85E4FF); - m_pLayout->SetBorderSize(0); - m_pLayout->SetAutoDestroy(false); - m_pLayout->EnableScrollBar(); - for( int i = 0; i < m_pOwner->GetCount(); i++ ) { - if(m_pOwner->GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName) != NULL ){ - (static_cast(m_pOwner->GetItemAt(i)))->SetOwner(m_pLayout); - m_pLayout->Add(static_cast(m_pOwner->GetItemAt(i))); - } - } - m_pm.AttachDialog(m_pLayout); - - // Position the popup window in absolute space - RECT rcOwner = m_pOwner->GetPos(); - RECT rc = rcOwner; - - int cxFixed = 0; - int cyFixed = 0; - -#if defined(WIN32) && !defined(UNDER_CE) - MONITORINFO oMonitor = {}; - oMonitor.cbSize = sizeof(oMonitor); - ::GetMonitorInfo(::MonitorFromWindow(*this, MONITOR_DEFAULTTOPRIMARY), &oMonitor); - CDuiRect rcWork = oMonitor.rcWork; -#else - CDuiRect rcWork; - GetWindowRect(m_pOwner->GetManager()->GetPaintWindow(), &rcWork); -#endif - SIZE szAvailable = { rcWork.right - rcWork.left, rcWork.bottom - rcWork.top }; - - for( int it = 0; it < m_pOwner->GetCount(); it++ ) { - if(m_pOwner->GetItemAt(it)->GetInterface(kMenuElementUIInterfaceName) != NULL ){ - CControlUI* pControl = static_cast(m_pOwner->GetItemAt(it)); - SIZE sz = pControl->EstimateSize(szAvailable); - cyFixed += sz.cy; - - if( cxFixed < sz.cx ) - cxFixed = sz.cx; - } - } - cyFixed += 4; - cxFixed += 4; - - RECT rcWindow; - GetWindowRect(m_pOwner->GetManager()->GetPaintWindow(), &rcWindow); - - rc.top = rcOwner.top; - rc.bottom = rc.top + cyFixed; - ::MapWindowRect(m_pOwner->GetManager()->GetPaintWindow(), HWND_DESKTOP, &rc); - rc.left = rcWindow.right; - rc.right = rc.left + cxFixed; - rc.right += 2; - - bool bReachBottom = false; - bool bReachRight = false; - LONG chRightAlgin = 0; - LONG chBottomAlgin = 0; - - RECT rcPreWindow = {0}; - ContextMenuObserver::Iterator iterator(s_context_menu_observer); - ReceiverImplBase* pReceiver = iterator.next(); - while( pReceiver != NULL ) { - CMenuWnd* pContextMenu = dynamic_cast(pReceiver); - if( pContextMenu != NULL ) { - GetWindowRect(pContextMenu->GetHWND(), &rcPreWindow); - - bReachRight = rcPreWindow.left >= rcWindow.right; - bReachBottom = rcPreWindow.top >= rcWindow.bottom; - if( pContextMenu->GetHWND() == m_pOwner->GetManager()->GetPaintWindow() - || bReachBottom || bReachRight ) - break; - } - pReceiver = iterator.next(); - } - - if (bReachBottom) - { - rc.bottom = rcWindow.top; - rc.top = rc.bottom - cyFixed; - } - - if (bReachRight) - { - rc.right = rcWindow.left; - rc.left = rc.right - cxFixed; - } - - if( rc.bottom > rcWork.bottom ) - { - rc.bottom = rc.top; - rc.top = rc.bottom - cyFixed; - } - - if (rc.right > rcWork.right) - { - rc.right = rcWindow.left; - rc.left = rc.right - cxFixed; - - rc.top = rcWindow.bottom; - rc.bottom = rc.top + cyFixed; - } - - if( rc.top < rcWork.top ) - { - rc.top = rcOwner.top; - rc.bottom = rc.top + cyFixed; - } - - if (rc.left < rcWork.left) - { - rc.left = rcWindow.right; - rc.right = rc.left + cxFixed; - } - - MoveWindow(m_hWnd, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, FALSE); - } - else { - m_pm.Init(m_hWnd); - - CDialogBuilder builder; - CMenuBuilderCallback menuCallback; - - CControlUI* pRoot = builder.Create(m_xml, m_sType.GetData(), &menuCallback, &m_pm); - m_pm.AttachDialog(pRoot); - -#if defined(WIN32) && !defined(UNDER_CE) - MONITORINFO oMonitor = {}; - oMonitor.cbSize = sizeof(oMonitor); - ::GetMonitorInfo(::MonitorFromWindow(*this, MONITOR_DEFAULTTOPRIMARY), &oMonitor); - CDuiRect rcWork = oMonitor.rcWork; -#else - CDuiRect rcWork; - GetWindowRect(m_pOwner->GetManager()->GetPaintWindow(), &rcWork); -#endif - SIZE szAvailable = { rcWork.right - rcWork.left, rcWork.bottom - rcWork.top }; - szAvailable = pRoot->EstimateSize(szAvailable); - m_pm.SetInitSize(szAvailable.cx, szAvailable.cy); - - DWORD dwAlignment = eMenuAlignment_Left | eMenuAlignment_Top; - - SIZE szInit = m_pm.GetInitSize(); - CDuiRect rc; - CPoint point = m_BasedPoint; - rc.left = point.x; - rc.top = point.y; - rc.right = rc.left + szInit.cx; - rc.bottom = rc.top + szInit.cy; - - int nWidth = rc.GetWidth(); - int nHeight = rc.GetHeight(); - - if (dwAlignment & eMenuAlignment_Right) - { - rc.right = point.x; - rc.left = rc.right - nWidth; - } - - if (dwAlignment & eMenuAlignment_Bottom) - { - rc.bottom = point.y; - rc.top = rc.bottom - nHeight; - } - - SetForegroundWindow(m_hWnd); - MoveWindow(m_hWnd, rc.left, rc.top, rc.GetWidth(), rc.GetHeight(), FALSE); - SetWindowPos(m_hWnd, HWND_TOPMOST, rc.left, rc.top, rc.GetWidth(), rc.GetHeight(), SWP_SHOWWINDOW); - } - - return 0; - } - else if( uMsg == WM_CLOSE ) { - if( m_pOwner != NULL ) - { - m_pOwner->SetManager(m_pOwner->GetManager(), m_pOwner->GetParent(), false); - m_pOwner->SetPos(m_pOwner->GetPos()); - m_pOwner->SetFocus(); - } - } - else if( uMsg == WM_RBUTTONDOWN || uMsg == WM_CONTEXTMENU || uMsg == WM_RBUTTONUP || uMsg == WM_RBUTTONDBLCLK ) - { - return 0L; - } - else if( uMsg == WM_KILLFOCUS ) - { - HWND hFocusWnd = (HWND)wParam; - - BOOL bInMenuWindowList = FALSE; - ContextMenuParam param; - param.hWnd = GetHWND(); - - ContextMenuObserver::Iterator iterator(s_context_menu_observer); - ReceiverImplBase* pReceiver = iterator.next(); - while( pReceiver != NULL ) { - CMenuWnd* pContextMenu = dynamic_cast(pReceiver); - if( pContextMenu != NULL && pContextMenu->GetHWND() == hFocusWnd ) { - bInMenuWindowList = TRUE; - break; - } - pReceiver = iterator.next(); - } - - if( !bInMenuWindowList ) { - param.wParam = ContextMenuParam::RemoveAll; - param.iType = 0; - s_context_menu_observer.RBroadcast(param); - - return 0; - } - } - else if( uMsg == WM_KEYDOWN) - { - if( wParam == VK_ESCAPE) - { - Close(); - } - } - - LRESULT lRes = 0; - if( m_pm.MessageHandler(uMsg, wParam, lParam, lRes) ) return lRes; - return CWindowWnd::HandleMessage(uMsg, wParam, lParam); -} - -///////////////////////////////////////////////////////////////////////////////////// -// - -CMenuElementUI::CMenuElementUI(): -m_pWindow(NULL) -{ - m_cxyFixed.cy = 25; - m_bMouseChildEnabled = true; - - SetMouseChildEnabled(false); -} - -CMenuElementUI::~CMenuElementUI() -{} - -LPCTSTR CMenuElementUI::GetClass() const -{ - return kMenuElementUIClassName; -} - -LPVOID CMenuElementUI::GetInterface(LPCTSTR pstrName) -{ - if( _tcsicmp(pstrName, kMenuElementUIInterfaceName) == 0 ) return static_cast(this); - return CListContainerElementUI::GetInterface(pstrName); -} - -void CMenuElementUI::DoPaint(HDC hDC, const RECT& rcPaint) -{ - if( !::IntersectRect(&m_rcPaint, &rcPaint, &m_rcItem) ) return; - CMenuElementUI::DrawItemBk(hDC, m_rcItem); - DrawItemText(hDC, m_rcItem); - for (int i = 0; i < GetCount(); ++i) - { - if (GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName) == NULL) - GetItemAt(i)->DoPaint(hDC, rcPaint); - } -} - -void CMenuElementUI::DrawItemText(HDC hDC, const RECT& rcItem) -{ - if( m_sText.IsEmpty() ) return; - - if( m_pOwner == NULL ) return; - TListInfoUI* pInfo = m_pOwner->GetListInfo(); - DWORD iTextColor = pInfo->dwTextColor; - if( (m_uButtonState & UISTATE_HOT) != 0 ) { - iTextColor = pInfo->dwHotTextColor; - } - if( IsSelected() ) { - iTextColor = pInfo->dwSelectedTextColor; - } - if( !IsEnabled() ) { - iTextColor = pInfo->dwDisabledTextColor; - } - int nLinks = 0; - RECT rcText = rcItem; - rcText.left += pInfo->rcTextPadding.left; - rcText.right -= pInfo->rcTextPadding.right; - rcText.top += pInfo->rcTextPadding.top; - rcText.bottom -= pInfo->rcTextPadding.bottom; - - if( pInfo->bShowHtml ) - CRenderEngine::DrawHtmlText(hDC, m_pManager, rcText, m_sText, iTextColor, \ - NULL, NULL, nLinks, DT_SINGLELINE | pInfo->uTextStyle); - else - CRenderEngine::DrawText(hDC, m_pManager, rcText, m_sText, iTextColor, \ - pInfo->nFont, DT_SINGLELINE | pInfo->uTextStyle); -} - - -SIZE CMenuElementUI::EstimateSize(SIZE szAvailable) -{ - SIZE cXY = {0}; - for( int it = 0; it < GetCount(); it++ ) { - CControlUI* pControl = static_cast(GetItemAt(it)); - if( !pControl->IsVisible() ) continue; - SIZE sz = pControl->EstimateSize(szAvailable); - cXY.cy += sz.cy; - if( cXY.cx < sz.cx ) - cXY.cx = sz.cx; - } - if(cXY.cy == 0) { - TListInfoUI* pInfo = m_pOwner->GetListInfo(); - - DWORD iTextColor = pInfo->dwTextColor; - if( (m_uButtonState & UISTATE_HOT) != 0 ) { - iTextColor = pInfo->dwHotTextColor; - } - if( IsSelected() ) { - iTextColor = pInfo->dwSelectedTextColor; - } - if( !IsEnabled() ) { - iTextColor = pInfo->dwDisabledTextColor; - } - - RECT rcText = { 0, 0, max(szAvailable.cx, m_cxyFixed.cx), 9999 }; - rcText.left += pInfo->rcTextPadding.left; - rcText.right -= pInfo->rcTextPadding.right; - if( pInfo->bShowHtml ) { - int nLinks = 0; - CRenderEngine::DrawHtmlText(m_pManager->GetPaintDC(), m_pManager, rcText, m_sText, iTextColor, NULL, NULL, nLinks, DT_CALCRECT | pInfo->uTextStyle); - } - else { - CRenderEngine::DrawText(m_pManager->GetPaintDC(), m_pManager, rcText, m_sText, iTextColor, pInfo->nFont, DT_CALCRECT | pInfo->uTextStyle); - } - cXY.cx = rcText.right - rcText.left + pInfo->rcTextPadding.left + pInfo->rcTextPadding.right + 20; - cXY.cy = rcText.bottom - rcText.top + pInfo->rcTextPadding.top + pInfo->rcTextPadding.bottom; - } - - if( m_cxyFixed.cy != 0 ) cXY.cy = m_cxyFixed.cy; - return cXY; -} - -void CMenuElementUI::DoEvent(TEventUI& event) -{ - if( event.Type == UIEVENT_MOUSEENTER ) - { - CListContainerElementUI::DoEvent(event); - if( m_pWindow ) return; - bool hasSubMenu = false; - for( int i = 0; i < GetCount(); ++i ) - { - if( GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName) != NULL ) - { - (static_cast(GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName)))->SetVisible(true); - (static_cast(GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName)))->SetInternVisible(true); - - hasSubMenu = true; - } - } - if( hasSubMenu ) - { - m_pOwner->SelectItem(GetIndex(), true); - CreateMenuWnd(); - } - else - { - ContextMenuParam param; - param.hWnd = m_pManager->GetPaintWindow(); - param.wParam = ContextMenuParam::RemoveSubMenu; - param.bLeaf = true; - param.iType = event.Type; - param.pSender = this; - s_context_menu_observer.RBroadcast(param); - m_pOwner->SelectItem(GetIndex(), true); - } - return; - } - - if( event.Type == UIEVENT_BUTTONDOWN ) - { - if( IsEnabled() ){ - CListContainerElementUI::DoEvent(event); - - if( m_pWindow ) return; - - bool hasSubMenu = false; - for( int i = 0; i < GetCount(); ++i ) { - if( GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName) != NULL ) { - (static_cast(GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName)))->SetVisible(true); - (static_cast(GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName)))->SetInternVisible(true); - - hasSubMenu = true; - } - } - if( hasSubMenu ) - { - CreateMenuWnd(); - } - else - { - ContextMenuParam param; - param.hWnd = m_pManager->GetPaintWindow(); - param.wParam = ContextMenuParam::RemoveAll; - param.bLeaf = true; - param.pSender = this; - param.iType = event.Type; - s_context_menu_observer.RBroadcast(param); - } - } - return; - } - - CListContainerElementUI::DoEvent(event); -} - -bool CMenuElementUI::Activate() -{ - if (CListContainerElementUI::Activate() && m_bSelected) - { - if( m_pWindow ) return true; - bool hasSubMenu = false; - for (int i = 0; i < GetCount(); ++i) - { - if (GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName) != NULL) - { - (static_cast(GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName)))->SetVisible(true); - (static_cast(GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName)))->SetInternVisible(true); - - hasSubMenu = true; - } - } - if (hasSubMenu) - { - CreateMenuWnd(); - } - else - { - ContextMenuParam param; - param.hWnd = m_pManager->GetPaintWindow(); - param.wParam = ContextMenuParam::RemoveAll; - param.bLeaf = true; - param.iType = 0; - s_context_menu_observer.RBroadcast(param); - } - - return true; - } - return false; -} - -CMenuWnd* CMenuElementUI::GetMenuWnd() -{ - return m_pWindow; -} - -void CMenuElementUI::CreateMenuWnd() -{ - if( m_pWindow ) return; - - m_pWindow = new CMenuWnd(m_pManager->GetPaintWindow()); - ASSERT(m_pWindow); - - ContextMenuParam param; - param.hWnd = m_pManager->GetPaintWindow(); - param.wParam = ContextMenuParam::RemoveSubMenu; - param.iType = 0; - s_context_menu_observer.RBroadcast(param); - - m_pWindow->Init(static_cast(this), _T(""), _T(""), CPoint()); -} - - -} // namespace DuiLib +#include "StdAfx.h" +#include "UIMenu.h" + +namespace DuiLib { + +static ContextMenuObserver s_context_menu_observer; + +const TCHAR* const kMenuUIClassName = _T("MenuUI"); +const TCHAR* const kMenuUIInterfaceName = _T("Menu"); + +const TCHAR* const kMenuElementUIClassName = _T("MenuElementUI"); +const TCHAR* const kMenuElementUIInterfaceName = _T("MenuElement"); + + +CMenuUI::CMenuUI() +{ + if (GetHeader() != NULL) + GetHeader()->SetVisible(false); +} + +CMenuUI::~CMenuUI() +{} + +LPCTSTR CMenuUI::GetClass() const +{ + return kMenuUIClassName; +} + +LPVOID CMenuUI::GetInterface(LPCTSTR pstrName) +{ + if( _tcsicmp(pstrName, kMenuUIInterfaceName) == 0 ) return static_cast(this); + return CListUI::GetInterface(pstrName); +} + +void CMenuUI::DoEvent(TEventUI& event) +{ + return __super::DoEvent(event); +} + +bool CMenuUI::Add(CControlUI* pControl) +{ + CMenuElementUI* pMenuItem = static_cast(pControl->GetInterface(kMenuElementUIInterfaceName)); + if (pMenuItem == NULL) + return false; + + for (int i = 0; i < pMenuItem->GetCount(); ++i) + { + if (pMenuItem->GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName) != NULL) + { + (static_cast(pMenuItem->GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName)))->SetInternVisible(false); + } + } + return CListUI::Add(pControl); +} + +bool CMenuUI::AddAt(CControlUI* pControl, int iIndex) +{ + CMenuElementUI* pMenuItem = static_cast(pControl->GetInterface(kMenuElementUIInterfaceName)); + if (pMenuItem == NULL) + return false; + + for (int i = 0; i < pMenuItem->GetCount(); ++i) + { + if (pMenuItem->GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName) != NULL) + { + (static_cast(pMenuItem->GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName)))->SetInternVisible(false); + } + } + return CListUI::AddAt(pControl, iIndex); +} + +int CMenuUI::GetItemIndex(CControlUI* pControl) const +{ + CMenuElementUI* pMenuItem = static_cast(pControl->GetInterface(kMenuElementUIInterfaceName)); + if (pMenuItem == NULL) + return -1; + + return __super::GetItemIndex(pControl); +} + +bool CMenuUI::SetItemIndex(CControlUI* pControl, int iIndex) +{ + CMenuElementUI* pMenuItem = static_cast(pControl->GetInterface(kMenuElementUIInterfaceName)); + if (pMenuItem == NULL) + return false; + + return __super::SetItemIndex(pControl, iIndex); +} + +bool CMenuUI::Remove(CControlUI* pControl) +{ + CMenuElementUI* pMenuItem = static_cast(pControl->GetInterface(kMenuElementUIInterfaceName)); + if (pMenuItem == NULL) + return false; + + return __super::Remove(pControl); +} + +SIZE CMenuUI::EstimateSize(SIZE szAvailable) +{ + int cxFixed = 0; + int cyFixed = 0; + for( int it = 0; it < GetCount(); it++ ) { + CControlUI* pControl = static_cast(GetItemAt(it)); + if( !pControl->IsVisible() ) continue; + SIZE sz = pControl->EstimateSize(szAvailable); + cyFixed += sz.cy; + if( cxFixed < sz.cx ) + cxFixed = sz.cx; + } + return CSize(cxFixed, cyFixed); +} + +void CMenuUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue) +{ + CListUI::SetAttribute(pstrName, pstrValue); +} + +///////////////////////////////////////////////////////////////////////////////////// +// +class CMenuBuilderCallback: public IDialogBuilderCallback +{ + CControlUI* CreateControl(LPCTSTR pstrClass) + { + if (_tcsicmp(pstrClass, kMenuUIInterfaceName) == 0) + { + return new CMenuUI(); + } + else if (_tcsicmp(pstrClass, kMenuElementUIInterfaceName) == 0) + { + return new CMenuElementUI(); + } + return NULL; + } +}; + +CMenuWnd::CMenuWnd(HWND hParent): +m_hParent(hParent), +m_pOwner(NULL), +m_pLayout(), +m_xml(_T("")) +{} + +BOOL CMenuWnd::Receive(ContextMenuParam param) +{ + if (param.iType == UIEVENT_BUTTONDOWN && param.bLeaf==true) + { + TEventUI myEvent; + myEvent.pSender = param.pSender; + if (OnClick) OnClick(&myEvent); + } + switch (param.wParam) + { + case 1: + Close(); + break; + case 2: + { + HWND hParent = GetParent(m_hWnd); + while (hParent != NULL) + { + if (hParent == param.hWnd) + { + Close(); + break; + } + hParent = GetParent(hParent); + } + } + break; + default: + break; + } + + return TRUE; +} + +void CMenuWnd::Init(CMenuElementUI* pOwner, STRINGorID xml, LPCTSTR pSkinType, POINT point) +{ + m_BasedPoint = point; + m_pOwner = pOwner; + m_pLayout = NULL; + + if (pSkinType != NULL) + m_sType = pSkinType; + + m_xml = xml; + + s_context_menu_observer.AddReceiver(this); + + Create((m_pOwner == NULL) ? m_hParent : m_pOwner->GetManager()->GetPaintWindow(), NULL, WS_POPUP, WS_EX_TOOLWINDOW | WS_EX_TOPMOST, CDuiRect()); + // HACK: Don't deselect the parent's caption + HWND hWndParent = m_hWnd; + while( ::GetParent(hWndParent) != NULL ) hWndParent = ::GetParent(hWndParent); + ::ShowWindow(m_hWnd, SW_SHOW); +#if defined(WIN32) && !defined(UNDER_CE) + ::SendMessage(hWndParent, WM_NCACTIVATE, TRUE, 0L); +#endif +} + +LPCTSTR CMenuWnd::GetWindowClassName() const +{ + return _T("MenuWnd"); +} + +void CMenuWnd::OnFinalMessage(HWND hWnd) +{ + RemoveObserver(); + if( m_pOwner != NULL ) { + for( int i = 0; i < m_pOwner->GetCount(); i++ ) { + if( static_cast(m_pOwner->GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName)) != NULL ) { + (static_cast(m_pOwner->GetItemAt(i)))->SetOwner(m_pOwner->GetParent()); + (static_cast(m_pOwner->GetItemAt(i)))->SetVisible(false); + (static_cast(m_pOwner->GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName)))->SetInternVisible(false); + } + } + m_pOwner->m_pWindow = NULL; + m_pOwner->m_uButtonState &= ~ UISTATE_PUSHED; + m_pOwner->Invalidate(); + } + delete this; +} + +LRESULT CMenuWnd::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + if( uMsg == WM_CREATE ) { + if( m_pOwner != NULL) { + LONG styleValue = ::GetWindowLong(*this, GWL_STYLE); + styleValue &= ~WS_CAPTION; + ::SetWindowLong(*this, GWL_STYLE, styleValue | WS_CLIPSIBLINGS | WS_CLIPCHILDREN); + RECT rcClient; + ::GetClientRect(*this, &rcClient); + ::SetWindowPos(*this, NULL, rcClient.left, rcClient.top, rcClient.right - rcClient.left, \ + rcClient.bottom - rcClient.top, SWP_FRAMECHANGED); + + m_pm.Init(m_hWnd); + // The trick is to add the items to the new container. Their owner gets + // reassigned by this operation - which is why it is important to reassign + // the items back to the righfull owner/manager when the window closes. + m_pLayout = new CMenuUI(); + m_pm.UseParentResource(m_pOwner->GetManager()); + m_pLayout->SetManager(&m_pm, NULL, true); + LPCTSTR pDefaultAttributes = m_pOwner->GetManager()->GetDefaultAttributeList(kMenuUIInterfaceName); + if( pDefaultAttributes ) { + m_pLayout->ApplyAttributeList(pDefaultAttributes); + } + m_pLayout->SetBkColor(0xFFFFFFFF); + m_pLayout->SetBorderColor(0xFF85E4FF); + m_pLayout->SetBorderSize(0); + m_pLayout->SetAutoDestroy(false); + m_pLayout->EnableScrollBar(); + for( int i = 0; i < m_pOwner->GetCount(); i++ ) { + if(m_pOwner->GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName) != NULL ){ + (static_cast(m_pOwner->GetItemAt(i)))->SetOwner(m_pLayout); + m_pLayout->Add(static_cast(m_pOwner->GetItemAt(i))); + } + } + m_pm.AttachDialog(m_pLayout); + + // Position the popup window in absolute space + RECT rcOwner = m_pOwner->GetPos(); + RECT rc = rcOwner; + + int cxFixed = 0; + int cyFixed = 0; + +#if defined(WIN32) && !defined(UNDER_CE) + MONITORINFO oMonitor = {}; + oMonitor.cbSize = sizeof(oMonitor); + ::GetMonitorInfo(::MonitorFromWindow(*this, MONITOR_DEFAULTTOPRIMARY), &oMonitor); + CDuiRect rcWork = oMonitor.rcWork; +#else + CDuiRect rcWork; + GetWindowRect(m_pOwner->GetManager()->GetPaintWindow(), &rcWork); +#endif + SIZE szAvailable = { rcWork.right - rcWork.left, rcWork.bottom - rcWork.top }; + + for( int it = 0; it < m_pOwner->GetCount(); it++ ) { + if(m_pOwner->GetItemAt(it)->GetInterface(kMenuElementUIInterfaceName) != NULL ){ + CControlUI* pControl = static_cast(m_pOwner->GetItemAt(it)); + SIZE sz = pControl->EstimateSize(szAvailable); + cyFixed += sz.cy; + + if( cxFixed < sz.cx ) + cxFixed = sz.cx; + } + } + cyFixed += 4; + cxFixed += 4; + + RECT rcWindow; + GetWindowRect(m_pOwner->GetManager()->GetPaintWindow(), &rcWindow); + + rc.top = rcOwner.top; + rc.bottom = rc.top + cyFixed; + ::MapWindowRect(m_pOwner->GetManager()->GetPaintWindow(), HWND_DESKTOP, &rc); + rc.left = rcWindow.right; + rc.right = rc.left + cxFixed; + rc.right += 2; + + bool bReachBottom = false; + bool bReachRight = false; + LONG chRightAlgin = 0; + LONG chBottomAlgin = 0; + + RECT rcPreWindow = {0}; + ContextMenuObserver::Iterator iterator(s_context_menu_observer); + ReceiverImplBase* pReceiver = iterator.next(); + while( pReceiver != NULL ) { + CMenuWnd* pContextMenu = dynamic_cast(pReceiver); + if( pContextMenu != NULL ) { + GetWindowRect(pContextMenu->GetHWND(), &rcPreWindow); + + bReachRight = rcPreWindow.left >= rcWindow.right; + bReachBottom = rcPreWindow.top >= rcWindow.bottom; + if( pContextMenu->GetHWND() == m_pOwner->GetManager()->GetPaintWindow() + || bReachBottom || bReachRight ) + break; + } + pReceiver = iterator.next(); + } + + if (bReachBottom) + { + rc.bottom = rcWindow.top; + rc.top = rc.bottom - cyFixed; + } + + if (bReachRight) + { + rc.right = rcWindow.left; + rc.left = rc.right - cxFixed; + } + + if( rc.bottom > rcWork.bottom ) + { + rc.bottom = rc.top; + rc.top = rc.bottom - cyFixed; + } + + if (rc.right > rcWork.right) + { + rc.right = rcWindow.left; + rc.left = rc.right - cxFixed; + + rc.top = rcWindow.bottom; + rc.bottom = rc.top + cyFixed; + } + + if( rc.top < rcWork.top ) + { + rc.top = rcOwner.top; + rc.bottom = rc.top + cyFixed; + } + + if (rc.left < rcWork.left) + { + rc.left = rcWindow.right; + rc.right = rc.left + cxFixed; + } + + MoveWindow(m_hWnd, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, FALSE); + } + else { + m_pm.Init(m_hWnd); + + CDialogBuilder builder; + CMenuBuilderCallback menuCallback; + + CControlUI* pRoot = builder.Create(m_xml, m_sType.GetData(), &menuCallback, &m_pm); + m_pm.AttachDialog(pRoot); + +#if defined(WIN32) && !defined(UNDER_CE) + MONITORINFO oMonitor = {}; + oMonitor.cbSize = sizeof(oMonitor); + ::GetMonitorInfo(::MonitorFromWindow(*this, MONITOR_DEFAULTTOPRIMARY), &oMonitor); + CDuiRect rcWork = oMonitor.rcWork; +#else + CDuiRect rcWork; + GetWindowRect(m_pOwner->GetManager()->GetPaintWindow(), &rcWork); +#endif + SIZE szAvailable = { rcWork.right - rcWork.left, rcWork.bottom - rcWork.top }; + szAvailable = pRoot->EstimateSize(szAvailable); + m_pm.SetInitSize(szAvailable.cx, szAvailable.cy); + + DWORD dwAlignment = eMenuAlignment_Left | eMenuAlignment_Top; + + SIZE szInit = m_pm.GetInitSize(); + CDuiRect rc; + CPoint point = m_BasedPoint; + rc.left = point.x; + rc.top = point.y; + rc.right = rc.left + szInit.cx; + rc.bottom = rc.top + szInit.cy; + + int nWidth = rc.GetWidth(); + int nHeight = rc.GetHeight(); + + if (dwAlignment & eMenuAlignment_Right) + { + rc.right = point.x; + rc.left = rc.right - nWidth; + } + + if (dwAlignment & eMenuAlignment_Bottom) + { + rc.bottom = point.y; + rc.top = rc.bottom - nHeight; + } + + SetForegroundWindow(m_hWnd); + MoveWindow(m_hWnd, rc.left, rc.top, rc.GetWidth(), rc.GetHeight(), FALSE); + SetWindowPos(m_hWnd, HWND_TOPMOST, rc.left, rc.top, rc.GetWidth(), rc.GetHeight(), SWP_SHOWWINDOW); + } + + return 0; + } + else if( uMsg == WM_CLOSE ) { + if( m_pOwner != NULL ) + { + m_pOwner->SetManager(m_pOwner->GetManager(), m_pOwner->GetParent(), false); + m_pOwner->SetPos(m_pOwner->GetPos()); + m_pOwner->SetFocus(); + } + } + else if( uMsg == WM_RBUTTONDOWN || uMsg == WM_CONTEXTMENU || uMsg == WM_RBUTTONUP || uMsg == WM_RBUTTONDBLCLK ) + { + return 0L; + } + else if( uMsg == WM_KILLFOCUS ) + { + HWND hFocusWnd = (HWND)wParam; + + BOOL bInMenuWindowList = FALSE; + ContextMenuParam param; + param.hWnd = GetHWND(); + + ContextMenuObserver::Iterator iterator(s_context_menu_observer); + ReceiverImplBase* pReceiver = iterator.next(); + while( pReceiver != NULL ) { + CMenuWnd* pContextMenu = dynamic_cast(pReceiver); + if( pContextMenu != NULL && pContextMenu->GetHWND() == hFocusWnd ) { + bInMenuWindowList = TRUE; + break; + } + pReceiver = iterator.next(); + } + + if( !bInMenuWindowList ) { + param.wParam = ContextMenuParam::RemoveAll; + param.iType = 0; + s_context_menu_observer.RBroadcast(param); + + return 0; + } + } + else if( uMsg == WM_KEYDOWN) + { + if( wParam == VK_ESCAPE) + { + Close(); + } + } + + LRESULT lRes = 0; + if( m_pm.MessageHandler(uMsg, wParam, lParam, lRes) ) return lRes; + return CWindowWnd::HandleMessage(uMsg, wParam, lParam); +} + +///////////////////////////////////////////////////////////////////////////////////// +// + +CMenuElementUI::CMenuElementUI(): +m_pWindow(NULL) +{ + m_cxyFixed.cy = 25; + m_bMouseChildEnabled = true; + + SetMouseChildEnabled(false); +} + +CMenuElementUI::~CMenuElementUI() +{} + +LPCTSTR CMenuElementUI::GetClass() const +{ + return kMenuElementUIClassName; +} + +LPVOID CMenuElementUI::GetInterface(LPCTSTR pstrName) +{ + if( _tcsicmp(pstrName, kMenuElementUIInterfaceName) == 0 ) return static_cast(this); + return CListContainerElementUI::GetInterface(pstrName); +} + +void CMenuElementUI::DoPaint(HDC hDC, const RECT& rcPaint) +{ + if( !::IntersectRect(&m_rcPaint, &rcPaint, &m_rcItem) ) return; + CMenuElementUI::DrawItemBk(hDC, m_rcItem); + DrawItemText(hDC, m_rcItem); + for (int i = 0; i < GetCount(); ++i) + { + if (GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName) == NULL) + GetItemAt(i)->DoPaint(hDC, rcPaint); + } +} + +void CMenuElementUI::DrawItemText(HDC hDC, const RECT& rcItem) +{ + if( m_sText.IsEmpty() ) return; + + if( m_pOwner == NULL ) return; + TListInfoUI* pInfo = m_pOwner->GetListInfo(); + DWORD iTextColor = pInfo->dwTextColor; + if( (m_uButtonState & UISTATE_HOT) != 0 ) { + iTextColor = pInfo->dwHotTextColor; + } + if( IsSelected() ) { + iTextColor = pInfo->dwSelectedTextColor; + } + if( !IsEnabled() ) { + iTextColor = pInfo->dwDisabledTextColor; + } + int nLinks = 0; + RECT rcText = rcItem; + rcText.left += pInfo->rcTextPadding.left; + rcText.right -= pInfo->rcTextPadding.right; + rcText.top += pInfo->rcTextPadding.top; + rcText.bottom -= pInfo->rcTextPadding.bottom; + + if( pInfo->bShowHtml ) + CRenderEngine::DrawHtmlText(hDC, m_pManager, rcText, m_sText, iTextColor, \ + NULL, NULL, nLinks, DT_SINGLELINE | pInfo->uTextStyle); + else + CRenderEngine::DrawText(hDC, m_pManager, rcText, m_sText, iTextColor, \ + pInfo->nFont, DT_SINGLELINE | pInfo->uTextStyle); +} + + +SIZE CMenuElementUI::EstimateSize(SIZE szAvailable) +{ + SIZE cXY = {0}; + for( int it = 0; it < GetCount(); it++ ) { + CControlUI* pControl = static_cast(GetItemAt(it)); + if( !pControl->IsVisible() ) continue; + SIZE sz = pControl->EstimateSize(szAvailable); + cXY.cy += sz.cy; + if( cXY.cx < sz.cx ) + cXY.cx = sz.cx; + } + if(cXY.cy == 0) { + TListInfoUI* pInfo = m_pOwner->GetListInfo(); + + DWORD iTextColor = pInfo->dwTextColor; + if( (m_uButtonState & UISTATE_HOT) != 0 ) { + iTextColor = pInfo->dwHotTextColor; + } + if( IsSelected() ) { + iTextColor = pInfo->dwSelectedTextColor; + } + if( !IsEnabled() ) { + iTextColor = pInfo->dwDisabledTextColor; + } + + RECT rcText = { 0, 0, max(szAvailable.cx, m_cxyFixed.cx), 9999 }; + rcText.left += pInfo->rcTextPadding.left; + rcText.right -= pInfo->rcTextPadding.right; + if( pInfo->bShowHtml ) { + int nLinks = 0; + CRenderEngine::DrawHtmlText(m_pManager->GetPaintDC(), m_pManager, rcText, m_sText, iTextColor, NULL, NULL, nLinks, DT_CALCRECT | pInfo->uTextStyle); + } + else { + CRenderEngine::DrawText(m_pManager->GetPaintDC(), m_pManager, rcText, m_sText, iTextColor, pInfo->nFont, DT_CALCRECT | pInfo->uTextStyle); + } + cXY.cx = rcText.right - rcText.left + pInfo->rcTextPadding.left + pInfo->rcTextPadding.right + 20; + cXY.cy = rcText.bottom - rcText.top + pInfo->rcTextPadding.top + pInfo->rcTextPadding.bottom; + } + + if( m_cxyFixed.cy != 0 ) cXY.cy = m_cxyFixed.cy; + return cXY; +} + +void CMenuElementUI::DoEvent(TEventUI& event) +{ + if( event.Type == UIEVENT_MOUSEENTER ) + { + CListContainerElementUI::DoEvent(event); + if( m_pWindow ) return; + bool hasSubMenu = false; + for( int i = 0; i < GetCount(); ++i ) + { + if( GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName) != NULL ) + { + (static_cast(GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName)))->SetVisible(true); + (static_cast(GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName)))->SetInternVisible(true); + + hasSubMenu = true; + } + } + if( hasSubMenu ) + { + m_pOwner->SelectItem(GetIndex(), true); + CreateMenuWnd(); + } + else + { + ContextMenuParam param; + param.hWnd = m_pManager->GetPaintWindow(); + param.wParam = ContextMenuParam::RemoveSubMenu; + param.bLeaf = true; + param.iType = event.Type; + param.pSender = this; + s_context_menu_observer.RBroadcast(param); + m_pOwner->SelectItem(GetIndex(), true); + } + return; + } + + if( event.Type == UIEVENT_BUTTONDOWN ) + { + if( IsEnabled() ){ + CListContainerElementUI::DoEvent(event); + + if( m_pWindow ) return; + + bool hasSubMenu = false; + for( int i = 0; i < GetCount(); ++i ) { + if( GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName) != NULL ) { + (static_cast(GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName)))->SetVisible(true); + (static_cast(GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName)))->SetInternVisible(true); + + hasSubMenu = true; + } + } + if( hasSubMenu ) + { + CreateMenuWnd(); + } + else + { + ContextMenuParam param; + param.hWnd = m_pManager->GetPaintWindow(); + param.wParam = ContextMenuParam::RemoveAll; + param.bLeaf = true; + param.pSender = this; + param.iType = event.Type; + s_context_menu_observer.RBroadcast(param); + } + } + return; + } + + CListContainerElementUI::DoEvent(event); +} + +bool CMenuElementUI::Activate() +{ + if (CListContainerElementUI::Activate() && m_bSelected) + { + if( m_pWindow ) return true; + bool hasSubMenu = false; + for (int i = 0; i < GetCount(); ++i) + { + if (GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName) != NULL) + { + (static_cast(GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName)))->SetVisible(true); + (static_cast(GetItemAt(i)->GetInterface(kMenuElementUIInterfaceName)))->SetInternVisible(true); + + hasSubMenu = true; + } + } + if (hasSubMenu) + { + CreateMenuWnd(); + } + else + { + ContextMenuParam param; + param.hWnd = m_pManager->GetPaintWindow(); + param.wParam = ContextMenuParam::RemoveAll; + param.bLeaf = true; + param.iType = 0; + s_context_menu_observer.RBroadcast(param); + } + + return true; + } + return false; +} + +CMenuWnd* CMenuElementUI::GetMenuWnd() +{ + return m_pWindow; +} + +void CMenuElementUI::CreateMenuWnd() +{ + if( m_pWindow ) return; + + m_pWindow = new CMenuWnd(m_pManager->GetPaintWindow()); + ASSERT(m_pWindow); + + ContextMenuParam param; + param.hWnd = m_pManager->GetPaintWindow(); + param.wParam = ContextMenuParam::RemoveSubMenu; + param.iType = 0; + s_context_menu_observer.RBroadcast(param); + + m_pWindow->Init(static_cast(this), _T(""), _T(""), CPoint()); +} + + +} // namespace DuiLib diff --git a/RedisStudio/DuiEx/UIMenu.h b/RedisStudio/DuiEx/UIMenu.h index 3170627..b1fd1c3 100644 --- a/RedisStudio/DuiEx/UIMenu.h +++ b/RedisStudio/DuiEx/UIMenu.h @@ -1,127 +1,127 @@ -#ifndef __UIMENU_H__ -#define __UIMENU_H__ - -#ifdef _MSC_VER -#pragma once -#endif - -#include "ObserverBase.h" - -namespace DuiLib { - -///////////////////////////////////////////////////////////////////////////////////// -// -struct ContextMenuParam -{ - - enum - { - RemoveAll = 1, - RemoveSubMenu = 2 - }; - - HWND hWnd; /// ǰ - int iType; /// ¼ - CControlUI* pSender; - bool bLeaf; /// ǷҶӽڵ˵ - WPARAM wParam; // 1: remove all - // 2: remove the sub menu - LPARAM lParam; -}; - -enum MenuAlignment -{ - eMenuAlignment_Left = 1 << 1, - eMenuAlignment_Top = 1 << 2, - eMenuAlignment_Right = 1 << 3, - eMenuAlignment_Bottom = 1 << 4, -}; - -typedef class ObserverImpl ContextMenuObserver; -typedef class ReceiverImpl ContextMenuReceiver; - -class CListUI; -class CMenuUI : public CListUI -{ -public: - CMenuUI(); - ~CMenuUI(); - - LPCTSTR GetClass() const; - LPVOID GetInterface(LPCTSTR pstrName); - - virtual void DoEvent(TEventUI& event); - - virtual bool Add(CControlUI* pControl); - virtual bool AddAt(CControlUI* pControl, int iIndex); - - virtual int GetItemIndex(CControlUI* pControl) const; - virtual bool SetItemIndex(CControlUI* pControl, int iIndex); - virtual bool Remove(CControlUI* pControl); - - SIZE EstimateSize(SIZE szAvailable); - - void SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue); -}; - - -class CMenuElementUI; -class CMenuWnd : public CWindowWnd, public ContextMenuReceiver -{ -public: - CMenuWnd(HWND hParent = NULL); - void Init(CMenuElementUI* pOwner, STRINGorID xml, LPCTSTR pSkinType, POINT point); - - LPCTSTR GetWindowClassName() const; - - void OnFinalMessage(HWND hWnd); - - LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam); - - BOOL Receive(ContextMenuParam param); - -public: - HWND m_hParent; - POINT m_BasedPoint; - STRINGorID m_xml; - CDuiString m_sType; - CPaintManagerUI m_pm; - CMenuElementUI* m_pOwner; - CMenuUI* m_pLayout; - -public: - CEventSource OnClick; -}; - -class CListContainerElementUI; -class CMenuElementUI : public CListContainerElementUI -{ - friend CMenuWnd; -public: - CMenuElementUI(); - ~CMenuElementUI(); - - LPCTSTR GetClass() const; - LPVOID GetInterface(LPCTSTR pstrName); - - void DoPaint(HDC hDC, const RECT& rcPaint); - - void DrawItemText(HDC hDC, const RECT& rcItem); - - SIZE EstimateSize(SIZE szAvailable); - - bool Activate(); - - void DoEvent(TEventUI& event); - - CMenuWnd* GetMenuWnd(); - - void CreateMenuWnd(); - -protected: - CMenuWnd* m_pWindow; -}; - -} // namespace DuiLib - -#endif // __UIMENU_H__ +#ifndef __UIMENU_H__ +#define __UIMENU_H__ + +#ifdef _MSC_VER +#pragma once +#endif + +#include "ObserverBase.h" + +namespace DuiLib { + +///////////////////////////////////////////////////////////////////////////////////// +// +struct ContextMenuParam +{ + + enum + { + RemoveAll = 1, + RemoveSubMenu = 2 + }; + + HWND hWnd; /// 当前窗口 + int iType; /// 事件类型 + CControlUI* pSender; + bool bLeaf; /// 是否叶子节点菜单 + WPARAM wParam; // 1: remove all + // 2: remove the sub menu + LPARAM lParam; +}; + +enum MenuAlignment +{ + eMenuAlignment_Left = 1 << 1, + eMenuAlignment_Top = 1 << 2, + eMenuAlignment_Right = 1 << 3, + eMenuAlignment_Bottom = 1 << 4, +}; + +typedef class ObserverImpl ContextMenuObserver; +typedef class ReceiverImpl ContextMenuReceiver; + +class CListUI; +class CMenuUI : public CListUI +{ +public: + CMenuUI(); + ~CMenuUI(); + + LPCTSTR GetClass() const; + LPVOID GetInterface(LPCTSTR pstrName); + + virtual void DoEvent(TEventUI& event); + + virtual bool Add(CControlUI* pControl); + virtual bool AddAt(CControlUI* pControl, int iIndex); + + virtual int GetItemIndex(CControlUI* pControl) const; + virtual bool SetItemIndex(CControlUI* pControl, int iIndex); + virtual bool Remove(CControlUI* pControl); + + SIZE EstimateSize(SIZE szAvailable); + + void SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue); +}; + + +class CMenuElementUI; +class CMenuWnd : public CWindowWnd, public ContextMenuReceiver +{ +public: + CMenuWnd(HWND hParent = NULL); + void Init(CMenuElementUI* pOwner, STRINGorID xml, LPCTSTR pSkinType, POINT point); + + LPCTSTR GetWindowClassName() const; + + void OnFinalMessage(HWND hWnd); + + LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam); + + BOOL Receive(ContextMenuParam param); + +public: + HWND m_hParent; + POINT m_BasedPoint; + STRINGorID m_xml; + CDuiString m_sType; + CPaintManagerUI m_pm; + CMenuElementUI* m_pOwner; + CMenuUI* m_pLayout; + +public: + CEventSource OnClick; +}; + +class CListContainerElementUI; +class CMenuElementUI : public CListContainerElementUI +{ + friend CMenuWnd; +public: + CMenuElementUI(); + ~CMenuElementUI(); + + LPCTSTR GetClass() const; + LPVOID GetInterface(LPCTSTR pstrName); + + void DoPaint(HDC hDC, const RECT& rcPaint); + + void DrawItemText(HDC hDC, const RECT& rcItem); + + SIZE EstimateSize(SIZE szAvailable); + + bool Activate(); + + void DoEvent(TEventUI& event); + + CMenuWnd* GetMenuWnd(); + + void CreateMenuWnd(); + +protected: + CMenuWnd* m_pWindow; +}; + +} // namespace DuiLib + +#endif // __UIMENU_H__ diff --git a/RedisStudio/Main.cpp b/RedisStudio/Main.cpp index 7ae6423..c6a8735 100644 --- a/RedisStudio/Main.cpp +++ b/RedisStudio/Main.cpp @@ -1,19 +1,22 @@ -#include "StdAfx.h" -#include "MainFrameWhd.h" -#include "win32fix/winfix.h" -#include - -void win32Cleanup(void) { - /* Clear winsocks */ - WSACleanup(); -} - -int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPSTR /*lpCmdLine*/, int nCmdShow) -{ - TCHAR szFileName[_MAX_PATH] = {0}; +#include "StdAfx.h" +#include +#include "MainFrameWhd.h" +#include "win32fix/winfix.h" + + +void win32Cleanup(void) { + /* Clear winsocks */ + WSACleanup(); +} + +int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPSTR /*lpCmdLine*/, int nCmdShow) +{ +#if 0 + /* avoid UAC */ + TCHAR szFileName[_MAX_PATH] = {0}; GetModuleFileName(NULL, szFileName, _MAX_PATH); - for (int i = sizeof(szFileName)-1; i>=0; i--) + for (int i = sizeof(szFileName)-1; i>=0; i--) { if (szFileName[i]=='\\') { @@ -21,29 +24,30 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPSTR /*l SetCurrentDirectory(szFileName); break; } - } - - if (!w32initWinSock()) { - printf("Winsock init error %d", WSAGetLastError()); - exit(1); - }; - - atexit((void(*)(void)) win32Cleanup); - - CPaintManagerUI::SetInstance(hInstance); - - HRESULT Hr = ::CoInitialize(NULL); - if( FAILED(Hr) ) return 0; - - CMainFrameWnd* pFrame = new CMainFrameWnd(); - - if( pFrame == NULL ) return 0; - pFrame->Create(NULL, _T("Redis Studio"), UI_WNDSTYLE_FRAME, 0L, 0, 0, 800, 572); - pFrame->CenterWindow(); - ::ShowWindow(*pFrame, SW_SHOW); - - CPaintManagerUI::MessageLoop(); - - ::CoUninitialize(); - return 0; + } +#endif + + if (!w32initWinSock()) { + printf("Winsock init error %d", WSAGetLastError()); + exit(1); + }; + + atexit((void(*)(void)) win32Cleanup); + + CPaintManagerUI::SetInstance(hInstance); + + HRESULT Hr = ::CoInitialize(NULL); + if ( FAILED(Hr) ) return 0; + + CMainFrameWnd* pFrame = new CMainFrameWnd(); + + if ( pFrame == NULL ) return 0; + pFrame->Create(NULL, _T("Redis Studio"), UI_WNDSTYLE_FRAME, 0L, 0, 0, 800, 572); + pFrame->CenterWindow(); + ::ShowWindow(*pFrame, SW_SHOW); + + CPaintManagerUI::MessageLoop(); + + ::CoUninitialize(); + return 0; } \ No newline at end of file diff --git a/RedisStudio/MainFrameWhd.cpp b/RedisStudio/MainFrameWhd.cpp index e96ee90..f82fed7 100644 --- a/RedisStudio/MainFrameWhd.cpp +++ b/RedisStudio/MainFrameWhd.cpp @@ -1,344 +1,378 @@ -#include "stdafx.h" -#include -#include -#include -#include "resource.h" -#include "MainFrameWhd.h" -#include "UserMessage.h" -#include "Redis/RedisClient.h" -#include "ConnInfoUI.h" -#include "RedisInfoUI.h" -#include "RedisDataUI.h" -#include "RedisConfigUI.h" -#include "RedisMgrUI.h" -#include "RedisHelpUI.h" - - -DUI_BEGIN_MESSAGE_MAP(CMainFrameWnd, WindowImplBase) -DUI_ON_MSGTYPE(DUI_MSGTYPE_CLICK,OnClick) -DUI_ON_MSGTYPE(DUI_MSGTYPE_SELECTCHANGED,OnSelectChanged) -DUI_ON_MSGTYPE(DUI_MSGTYPE_ITEMCLICK,OnItemClick) -DUI_END_MESSAGE_MAP() - - -HWND CMainFrameWnd::m_hwnd = NULL; - -CMainFrameWnd::CMainFrameWnd() -{ -} - -CMainFrameWnd::~CMainFrameWnd() -{ - for (int idx=0; idx(m_PaintManager.FindControl(_T("closebtn"))); - m_pMaxBtn = static_cast(m_PaintManager.FindControl(_T("maxbtn"))); - m_pRestoreBtn = static_cast(m_PaintManager.FindControl(_T("restorebtn"))); - m_pMinBtn = static_cast(m_PaintManager.FindControl(_T("minbtn"))); - - - m_pConnectControl = static_cast(m_PaintManager.FindControl(_T("txt_notice_success"))); - m_pUnConnectControl = static_cast(m_PaintManager.FindControl(_T("txt_notice_fail"))); - m_pConnectingControl = static_cast(m_PaintManager.FindControl(_T("txt_notice_connectting"))); - - m_pLayConnect = static_cast(m_PaintManager.FindControl(_T("main_notice_success"))); - m_pLayConnecting = static_cast(m_PaintManager.FindControl(_T("main_notice_connectting"))); - m_pLayUnconect = static_cast(m_PaintManager.FindControl(_T("main_notice_fail"))); - - for (int idx=0; idxInitialize(); - - } - //ˢĬϴڼ - for (int idx=0; idxGetIndex() == 0) - { - p->RefreshWnd(); - break; - } - } -} - -LPCTSTR CMainFrameWnd::GetWindowClassName() const -{ - return _T("MainFrameWhd"); -} - -UINT CMainFrameWnd::GetClassStyle() const -{ - return CS_DBLCLKS; -} - -void CMainFrameWnd::OnFinalMessage( HWND hWnd ) -{ - delete this; -} - -DuiLib::CDuiString CMainFrameWnd::GetSkinFolder() -{ - return _T("skin\\"); -} - -DuiLib::CDuiString CMainFrameWnd::GetSkinFile() -{ - return _T("skin.xml"); -} - -//DuiLib::CDuiString CMainFrameWnd::GetZIPFileName() -//{ -// return _T(""); -//} - -DuiLib::UILIB_RESOURCETYPE CMainFrameWnd::GetResourceType() const -{ - return UILIB_FILE; -} - -CControlUI* CMainFrameWnd::CreateControl(LPCTSTR pstrClassName) -{ - CDuiString strXML; - CDialogBuilder builder; - AbstraceUI* p = NULL; - - if (_tcsicmp(pstrClassName, _T("ConnInfo")) == 0) - { - strXML = _T("ConnInfo.xml"); - p = new ConnInfoUI(strXML, &m_PaintManager); - } - else if (_tcsicmp(pstrClassName, _T("RedisInfo")) == 0) - { - strXML = _T("RedisInfo.xml"); - p = new RedisInfoUI(strXML, &m_PaintManager); - } - else if (_tcsicmp(pstrClassName, _T("RedisData")) == 0) - { - strXML = _T("RedisData.xml"); - p = new RedisDataUI(strXML, &m_PaintManager); - } - else if (_tcsicmp(pstrClassName, _T("RedisConfig")) == 0) - { - strXML = _T("RedisConfig.xml"); - p = new RedisConfigUI(strXML, &m_PaintManager); - } - else if (_tcsicmp(pstrClassName, _T("RedisMgr")) == 0) - { - strXML = _T("RedisMgr.xml"); - p = new RedisMgrUI(strXML, &m_PaintManager); - } - else if (_tcsicmp(pstrClassName, _T("RedisHelp")) == 0) - { - strXML = _T("RedisHelp.xml"); - p = new RedisHelpUI(strXML, &m_PaintManager); - } - //if (! strXML.IsEmpty()) - //{ - // CControlUI* pUI = builder.Create(strXML.GetData(), NULL, NULL, &m_PaintManager, NULL); // 봫m_PaintManagerȻXMLʹĬϹϢ - // return pUI; - //} - - if (p) - { - AddVirtualWnd(p->GetVirtualwndName(), p); - p->SetHWND(GetHWND()); - m_TabContainer.Set(p->GetVirtualwndName(), p); - return p; - } - return NULL; -} - -void CMainFrameWnd::Notify(TNotifyUI& msg) -{ - return WindowImplBase::Notify(msg); -} - - -void CMainFrameWnd::OnClick( TNotifyUI& msg ) -{ - if( msg.pSender == m_pCloseBtn ) - { - PostQuitMessage(0); - return; - } - else if( msg.pSender == m_pMinBtn ) - { - SendMessage(WM_SYSCOMMAND, SC_MINIMIZE, 0); - return; - } - else if( msg.pSender == m_pMaxBtn ) - { - SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE, 0); - return; - } - else if( msg.pSender == m_pRestoreBtn ) - { - SendMessage(WM_SYSCOMMAND, SC_RESTORE, 0); - return; - } - else if (msg.pSender->GetName() == _T("Issue")) - { - ::ShellExecute(NULL, NULL, _T("https://github.com/cinience/RedisStudio/issues"), NULL, NULL, NULL); - } - else if (msg.pSender->GetName() == _T("Star")) - { - ::ShellExecute(NULL, NULL, _T("https://github.com/cinience/RedisStudio/stargazers"), NULL, NULL, NULL); - } -} - -void CMainFrameWnd::OnSelectChanged( TNotifyUI &msg ) -{ - CDuiString name = msg.pSender->GetName(); - name.Replace(_T("btn_"), _T("")); - CTabLayoutUI* pControl = static_cast(m_PaintManager.FindControl(_T("switch"))); - - if (name != _T("ConnInfo") && - name != _T("RedisHelp") && - !RedisClient::GetInstance().IsConnected()) - { - pControl->SelectItem(0); - COptionUI* pBut = static_cast(m_PaintManager.FindControl(_T("btn_ConnInfo"))); - pBut->Selected(true); - UserMessageBox(GetHWND(), 10010, NULL, MB_ICONINFORMATION); - return; - } - static COptionUI* pLastButton = NULL; - static AbstraceUI* pLastTab = NULL; - AbstraceUI* p = NULL; - /// tabİťϢ⣬ϢԴ˴ֻжtabصϢ - for (int idx=0; idxCanChange()) { - if (pLastButton) pLastButton->Selected(true); - UserMessageBox(GetHWND(), 10012, NULL, MB_ICONINFORMATION); - return; - } - - if (p && p!=pLastTab) { - p->RefreshWnd(); - pControl->SelectItem(p->GetIndex()); - pLastTab = p; - pLastButton = static_cast(m_PaintManager.FindControl(msg.pSender->GetName())); - } -} - -void CMainFrameWnd::OnItemClick( TNotifyUI &msg ) -{ - -} - -void CMainFrameWnd::DoConnectEvent( void* data ) -{ - SendMessage(WM_USER_CONNECTED, (WPARAM)data); -} - -void CMainFrameWnd::DoUnConnectEvent( void* data ) -{ - SendMessage(WM_USER_UNCONNECT, (WPARAM)data); -} - -LRESULT CMainFrameWnd::OnConnected( HWND hwnd, WPARAM wParam, LPARAM lParam ) -{ - static const CDuiString OldText = m_pConnectControl->GetText(); - - CDuiString* s = (CDuiString*)(wParam); - CDuiString newText = OldText; - newText.Replace(_T("$"), s->GetData()); - delete s; - m_pConnectControl->SetText(newText); - // m_pConnectControl->SetVisible(true); - /*m_pConnectControl->NeedUpdate();*/ - - m_pLayConnect->SetVisible(true); - m_pLayConnecting->SetVisible(false); - m_pLayUnconect->SetVisible(false); - - return TRUE; -} - -LRESULT CMainFrameWnd::OnUnConnected( HWND hwnd, WPARAM wParam, LPARAM lParam ) -{ - CDuiString *s = (CDuiString*)wParam; - if (s != NULL) - UserMessageBox(GetHWND(), 10016, s->GetData(), MB_ICONINFORMATION); - m_pLayConnect->SetVisible(false); - m_pLayConnecting->SetVisible(false); - m_pLayUnconect->SetVisible(true); - delete s; - return TRUE; -} - -LRESULT CMainFrameWnd::OnConnecting( HWND hwnd, WPARAM wParam, LPARAM lParam ) -{ - static const CDuiString OldText = m_pConnectingControl->GetText(); - - CDuiString* s = (CDuiString*)(wParam); - CDuiString newText = OldText; - newText.Replace(_T("$"), s->GetData()); - delete s; - m_pConnectingControl->SetText(newText); - m_pLayConnect->SetVisible(false); - m_pLayConnecting->SetVisible(true); - m_pLayUnconect->SetVisible(false); - return TRUE; -} - -void CMainFrameWnd::OndisConnectCallback( const CDuiString& name ) -{ - CDuiString* s = new CDuiString(name); - ::PostMessage(m_hwnd, WM_USER_UNCONNECT, (WPARAM) s, NULL); -} - -LRESULT CMainFrameWnd::HandleCustomMessage( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled ) -{ - LRESULT lRes = TRUE; - bHandled = TRUE; - switch(uMsg) - { - case WM_USER_CONNECTED: - lRes = OnConnected(*this, wParam, lParam); - break; - case WM_USER_UNCONNECT: - lRes = OnUnConnected(*this, wParam, lParam); - break; - case WM_USER_CONNECTING: - lRes = OnConnecting(*this, wParam, lParam); - break; - default: - bHandled = FALSE; - break; - } - if (!bHandled) - { - for (int idx=0; idxHandleCustomMessage(uMsg, wParam, lParam, bHandled); - } - } - return lRes; -} - - - - - +#include "stdafx.h" +#include +#include +#include +#include "resource.h" +#include "Version.h" +#include "MainFrameWhd.h" +#include "UserMessage.h" +#include "Redis/RedisClient.h" +#include "ConnInfoUI.h" +#include "RedisInfoUI.h" +#include "RedisDataUI.h" +#include "RedisConfigUI.h" +#include "RedisMgrUI.h" +#include "RedisHelpUI.h" + +#include "Base/Http.h" +#include "Base/CharacterSet.h" + +DUI_BEGIN_MESSAGE_MAP(CMainFrameWnd, WindowImplBase) +DUI_ON_MSGTYPE(DUI_MSGTYPE_CLICK,OnClick) +DUI_ON_MSGTYPE(DUI_MSGTYPE_SELECTCHANGED,OnSelectChanged) +DUI_ON_MSGTYPE(DUI_MSGTYPE_ITEMCLICK,OnItemClick) +DUI_END_MESSAGE_MAP() + + +HWND CMainFrameWnd::m_hwnd = NULL; + +CMainFrameWnd::CMainFrameWnd() +{ +} + +CMainFrameWnd::~CMainFrameWnd() +{ + for (int idx=0; idx(m_PaintManager.FindControl(_T("closebtn"))); + m_pMaxBtn = static_cast(m_PaintManager.FindControl(_T("maxbtn"))); + m_pRestoreBtn = static_cast(m_PaintManager.FindControl(_T("restorebtn"))); + m_pMinBtn = static_cast(m_PaintManager.FindControl(_T("minbtn"))); + + m_pVersionControl = static_cast(m_PaintManager.FindControl(_T("main_version"))); + m_pConnectControl = static_cast(m_PaintManager.FindControl(_T("txt_notice_success"))); + m_pUnConnectControl = static_cast(m_PaintManager.FindControl(_T("txt_notice_fail"))); + m_pConnectingControl = static_cast(m_PaintManager.FindControl(_T("txt_notice_connectting"))); + + m_pLayConnect = static_cast(m_PaintManager.FindControl(_T("main_notice_success"))); + m_pLayConnecting = static_cast(m_PaintManager.FindControl(_T("main_notice_connectting"))); + m_pLayUnconect = static_cast(m_PaintManager.FindControl(_T("main_notice_fail"))); + + /// 设置版本号 + CDuiString theMsg = m_pVersionControl->GetText(); + theMsg.Replace(_T("$version"), _T(VERSION)); + m_pVersionControl->SetText(theMsg); + + for (int idx=0; idxInitialize(); + + } + /// 刷新默认窗口加载数据 + for (int idx=0; idxGetIndex() == 0) + { + p->RefreshWnd(); + break; + } + } + + DWORD dwThreadID = 0; + HANDLE hThread = CreateThread(NULL, 0, &CMainFrameWnd::BackgroundWork, GetHWND(), 0, &dwThreadID); +} + +LPCTSTR CMainFrameWnd::GetWindowClassName() const +{ + return _T("MainFrameWhd"); +} + +UINT CMainFrameWnd::GetClassStyle() const +{ + return CS_DBLCLKS; +} + +void CMainFrameWnd::OnFinalMessage( HWND hWnd ) +{ + delete this; +} + +DuiLib::CDuiString CMainFrameWnd::GetSkinFolder() +{ + return _T("skin\\"); +} + +DuiLib::CDuiString CMainFrameWnd::GetSkinFile() +{ + return _T("skin.xml"); +} + +//DuiLib::CDuiString CMainFrameWnd::GetZIPFileName() +//{ +// return _T(""); +//} + +DuiLib::UILIB_RESOURCETYPE CMainFrameWnd::GetResourceType() const +{ + return UILIB_FILE; +} + +CControlUI* CMainFrameWnd::CreateControl(LPCTSTR pstrClassName) +{ + CDuiString strXML; + CDialogBuilder builder; + AbstraceUI* p = NULL; + + if (_tcsicmp(pstrClassName, _T("ConnInfo")) == 0) + { + strXML = _T("ConnInfo.xml"); + p = new ConnInfoUI(strXML, &m_PaintManager); + } + else if (_tcsicmp(pstrClassName, _T("RedisInfo")) == 0) + { + strXML = _T("RedisInfo.xml"); + p = new RedisInfoUI(strXML, &m_PaintManager); + } + else if (_tcsicmp(pstrClassName, _T("RedisData")) == 0) + { + strXML = _T("RedisData.xml"); + p = new RedisDataUI(strXML, &m_PaintManager); + } + else if (_tcsicmp(pstrClassName, _T("RedisConfig")) == 0) + { + strXML = _T("RedisConfig.xml"); + p = new RedisConfigUI(strXML, &m_PaintManager); + } + else if (_tcsicmp(pstrClassName, _T("RedisMgr")) == 0) + { + strXML = _T("RedisMgr.xml"); + p = new RedisMgrUI(strXML, &m_PaintManager); + } + else if (_tcsicmp(pstrClassName, _T("RedisHelp")) == 0) + { + strXML = _T("RedisHelp.xml"); + p = new RedisHelpUI(strXML, &m_PaintManager); + } + //if (! strXML.IsEmpty()) + //{ + // CControlUI* pUI = builder.Create(strXML.GetData(), NULL, NULL, &m_PaintManager, NULL); // 这里必须传入m_PaintManager,不然子XML不能使用默认滚动条等信息。 + // return pUI; + //} + + if (p) + { + AddVirtualWnd(p->GetVirtualwndName(), p); + p->SetHWND(GetHWND()); + m_TabContainer.Set(p->GetVirtualwndName(), p); + return p; + } + return NULL; +} + +void CMainFrameWnd::Notify(TNotifyUI& msg) +{ + return WindowImplBase::Notify(msg); +} + + +void CMainFrameWnd::OnClick( TNotifyUI& msg ) +{ + if( msg.pSender == m_pCloseBtn ) + { + PostQuitMessage(0); + return; + } + else if( msg.pSender == m_pMinBtn ) + { + SendMessage(WM_SYSCOMMAND, SC_MINIMIZE, 0); + return; + } + else if( msg.pSender == m_pMaxBtn ) + { + SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE, 0); + return; + } + else if( msg.pSender == m_pRestoreBtn ) + { + SendMessage(WM_SYSCOMMAND, SC_RESTORE, 0); + return; + } + else if (msg.pSender->GetName() == _T("Issue")) + { + ::ShellExecute(NULL, NULL, _T("https://github.com/cinience/RedisStudio/issues"), NULL, NULL, NULL); + } + else if (msg.pSender->GetName() == _T("Star")) + { + ::ShellExecute(NULL, NULL, _T("https://github.com/cinience/RedisStudio/stargazers"), NULL, NULL, NULL); + } +} + +void CMainFrameWnd::OnSelectChanged( TNotifyUI &msg ) +{ + CDuiString name = msg.pSender->GetName(); + name.Replace(_T("btn_"), _T("")); + CTabLayoutUI* pControl = static_cast(m_PaintManager.FindControl(_T("switch"))); + + if (name != _T("ConnInfo") && + name != _T("RedisHelp") && + !RedisClient::GetInstance().IsConnected()) + { + pControl->SelectItem(0); + COptionUI* pBut = static_cast(m_PaintManager.FindControl(_T("btn_ConnInfo"))); + pBut->Selected(true); + UserMessageBox(GetHWND(), 10010, NULL, MB_ICONINFORMATION); + return; + } + static COptionUI* pLastButton = NULL; + static AbstraceUI* pLastTab = NULL; + AbstraceUI* p = NULL; + /// 除了tab的按钮的消息外,还有其它消息,所以此处只判断tab相关的消息 + for (int idx=0; idxCanChange()) { + if (pLastButton) pLastButton->Selected(true); + UserMessageBox(GetHWND(), 10012, NULL, MB_ICONINFORMATION); + return; + } + + if (p && p!=pLastTab) { + p->RefreshWnd(); + pControl->SelectItem(p->GetIndex()); + pLastTab = p; + pLastButton = static_cast(m_PaintManager.FindControl(msg.pSender->GetName())); + } +} + +void CMainFrameWnd::OnItemClick( TNotifyUI &msg ) +{ + +} + +void CMainFrameWnd::DoConnectEvent( void* data ) +{ + SendMessage(WM_USER_CONNECTED, (WPARAM)data); +} + +void CMainFrameWnd::DoUnConnectEvent( void* data ) +{ + SendMessage(WM_USER_UNCONNECT, (WPARAM)data); +} + +LRESULT CMainFrameWnd::OnConnected( HWND hwnd, WPARAM wParam, LPARAM lParam ) +{ + static const CDuiString OldText = m_pConnectControl->GetText(); + + CDuiString* s = (CDuiString*)(wParam); + CDuiString newText = OldText; + newText.Replace(_T("$"), s->GetData()); + delete s; + m_pConnectControl->SetText(newText); + // m_pConnectControl->SetVisible(true); + /*m_pConnectControl->NeedUpdate();*/ + + m_pLayConnect->SetVisible(true); + m_pLayConnecting->SetVisible(false); + m_pLayUnconect->SetVisible(false); + + return TRUE; +} + +LRESULT CMainFrameWnd::OnUnConnected( HWND hwnd, WPARAM wParam, LPARAM lParam ) +{ + CDuiString *s = (CDuiString*)wParam; + if (s != NULL) + UserMessageBox(GetHWND(), 10016, s->GetData(), MB_ICONINFORMATION); + m_pLayConnect->SetVisible(false); + m_pLayConnecting->SetVisible(false); + m_pLayUnconect->SetVisible(true); + delete s; + return TRUE; +} + +LRESULT CMainFrameWnd::OnConnecting( HWND hwnd, WPARAM wParam, LPARAM lParam ) +{ + static const CDuiString OldText = m_pConnectingControl->GetText(); + + CDuiString* s = (CDuiString*)(wParam); + CDuiString newText = OldText; + newText.Replace(_T("$"), s->GetData()); + delete s; + m_pConnectingControl->SetText(newText); + m_pLayConnect->SetVisible(false); + m_pLayConnecting->SetVisible(true); + m_pLayUnconect->SetVisible(false); + return TRUE; +} + +LRESULT CMainFrameWnd::OnUpdate(HWND hwnd, WPARAM wParam, LPARAM lParam) +{ + UserMessageBox(GetHWND(), 20000, NULL, MB_ICONINFORMATION); + ::ShellExecute(NULL, NULL, _T("https://github.com/cinience/RedisStudio/releases"), NULL, NULL, NULL); + return TRUE; +} + +DWORD WINAPI CMainFrameWnd::BackgroundWork( LPVOID lpParameter ) +{ + Base::Http http("hiredis.com", 80); + Base::Http::Response rep = {0, ""}; + if (http.ping()) { + rep = http.post("/redisstudio/version", ""); + } + + if (rep.status == 200 && rep.data.size() > 2 && rep.data != VERSION) { + ::PostMessage(m_hwnd, WM_USER_UPDATE, (WPARAM)NULL, NULL); + } + return 0; +} + +void CMainFrameWnd::OndisConnectCallback( const CDuiString& name ) +{ + CDuiString* s = new CDuiString(name); + ::PostMessage(m_hwnd, WM_USER_UNCONNECT, (WPARAM) s, NULL); +} + +LRESULT CMainFrameWnd::HandleCustomMessage( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled ) +{ + LRESULT lRes = TRUE; + bHandled = TRUE; + switch(uMsg) + { + case WM_USER_CONNECTED: + lRes = OnConnected(*this, wParam, lParam); + break; + case WM_USER_UNCONNECT: + lRes = OnUnConnected(*this, wParam, lParam); + break; + case WM_USER_CONNECTING: + lRes = OnConnecting(*this, wParam, lParam); + break; + case WM_USER_UPDATE: + lRes = OnUpdate(*this, wParam, lParam); + default: + bHandled = FALSE; + break; + } + if (!bHandled) + { + for (int idx=0; idxHandleCustomMessage(uMsg, wParam, lParam, bHandled); + } + } + return lRes; +} + + + + + diff --git a/RedisStudio/MainFrameWhd.h b/RedisStudio/MainFrameWhd.h index 545b98e..a7e0836 100644 --- a/RedisStudio/MainFrameWhd.h +++ b/RedisStudio/MainFrameWhd.h @@ -1,76 +1,80 @@ -#pragma once - -#include "stdafx.h" -#include -#include - -class ConnInfoUI; -class RedisInfoUI; - -class CMainFrameWnd : public WindowImplBase -{ -public: - CMainFrameWnd(); - - ~CMainFrameWnd(); - - LPCTSTR GetWindowClassName() const; - - UINT GetClassStyle() const; - - void OnFinalMessage(HWND hWnd); - - virtual CDuiString GetSkinFolder(); - - virtual CDuiString GetSkinFile(); - - virtual UILIB_RESOURCETYPE GetResourceType() const; - - void InitWindow() ; - - CControlUI* CreateControl(LPCTSTR pstrClassName); - - void Notify(TNotifyUI& msg); - - virtual LRESULT HandleCustomMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - - DUI_DECLARE_MESSAGE_MAP() - - virtual void OnClick(TNotifyUI& msg); - - virtual void OnSelectChanged( TNotifyUI &msg ); - - virtual void OnItemClick( TNotifyUI &msg ); - - LRESULT OnConnected(HWND hwnd, WPARAM wParam, LPARAM lParam); - - LRESULT OnUnConnected(HWND hwnd, WPARAM wParam, LPARAM lParam); - - LRESULT OnConnecting(HWND hwnd, WPARAM wParam, LPARAM lParam); - -public: - void DoConnectEvent(void* data); - - void DoUnConnectEvent(void* data); - -public: - static HWND m_hwnd; - static void OndisConnectCallback(const CDuiString& name); - -private: - CButtonUI* m_pCloseBtn; - CButtonUI* m_pMaxBtn; - CButtonUI* m_pRestoreBtn; - CButtonUI* m_pMinBtn; - - CHorizontalLayoutUI* m_pLayConnect; - CHorizontalLayoutUI* m_pLayConnecting; - CHorizontalLayoutUI* m_pLayUnconect; - CTextUI* m_pConnectControl ; - CTextUI* m_pUnConnectControl ; - CTextUI* m_pConnectingControl ; - - CStdStringPtrMap m_TabContainer; -}; - - +#pragma once + +#include "stdafx.h" +#include +#include + +class ConnInfoUI; +class RedisInfoUI; + +class CMainFrameWnd : public WindowImplBase +{ +public: + CMainFrameWnd(); + + ~CMainFrameWnd(); + + LPCTSTR GetWindowClassName() const; + + UINT GetClassStyle() const; + + void OnFinalMessage(HWND hWnd); + + virtual CDuiString GetSkinFolder(); + + virtual CDuiString GetSkinFile(); + + virtual UILIB_RESOURCETYPE GetResourceType() const; + + void InitWindow() ; + + CControlUI* CreateControl(LPCTSTR pstrClassName); + + void Notify(TNotifyUI& msg); + + virtual LRESULT HandleCustomMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); + + DUI_DECLARE_MESSAGE_MAP() + + virtual void OnClick(TNotifyUI& msg); + + virtual void OnSelectChanged( TNotifyUI &msg ); + + virtual void OnItemClick( TNotifyUI &msg ); + + LRESULT OnConnected(HWND hwnd, WPARAM wParam, LPARAM lParam); + + LRESULT OnUnConnected(HWND hwnd, WPARAM wParam, LPARAM lParam); + + LRESULT OnConnecting(HWND hwnd, WPARAM wParam, LPARAM lParam); + + LRESULT OnUpdate(HWND hwnd, WPARAM wParam, LPARAM lParam); + +public: + void DoConnectEvent(void* data); + + void DoUnConnectEvent(void* data); + +public: + static DWORD WINAPI BackgroundWork(LPVOID lpParameter); + static HWND m_hwnd; + static void OndisConnectCallback(const CDuiString& name); + +private: + CButtonUI* m_pCloseBtn; + CButtonUI* m_pMaxBtn; + CButtonUI* m_pRestoreBtn; + CButtonUI* m_pMinBtn; + + CHorizontalLayoutUI* m_pLayConnect; + CHorizontalLayoutUI* m_pLayConnecting; + CHorizontalLayoutUI* m_pLayUnconect; + CTextUI* m_pConnectControl ; + CTextUI* m_pUnConnectControl ; + CTextUI* m_pConnectingControl ; + CTextUI* m_pVersionControl; + + CStdStringPtrMap m_TabContainer; +}; + + diff --git a/RedisStudio/MessageBoxWhd.cpp b/RedisStudio/MessageBoxWhd.cpp index e41e9c3..78cb703 100644 --- a/RedisStudio/MessageBoxWhd.cpp +++ b/RedisStudio/MessageBoxWhd.cpp @@ -1,99 +1,99 @@ -#include "stdafx.h" -#include "MessageBoxWhd.h" -#include -#include "Base/CharacterSet.h" - -DUI_BEGIN_MESSAGE_MAP(MessageBoxWhd, WindowImplBase) -DUI_ON_MSGTYPE(DUI_MSGTYPE_CLICK,OnClick) -DUI_END_MESSAGE_MAP() - -MessageBoxWhd::MessageBoxWhd(MsgType type, UINT code, CDuiString msg) -{ - m_uType = type; - m_uMsgCode = code; - m_dstrExMsg = msg; -} - -MessageBoxWhd::~MessageBoxWhd(void) -{ -} - -void MessageBoxWhd::InitWindow() -{ - CLabelUI* pLbl = NULL; - CControlUI* pCtl = NULL; - if (m_uType == Info) - { - pLbl = static_cast (m_PaintManager.FindControl(_T("lab_msg_info"))); - pCtl = static_cast (m_PaintManager.FindControl(_T("ctl_msg_info"))); - } - else if (m_uType == Warn) - { - pLbl = static_cast (m_PaintManager.FindControl(_T("lab_msg_warn"))); - pCtl = static_cast (m_PaintManager.FindControl(_T("ctl_msg_warn"))); - } - else if (m_uType == Error) - { - pLbl = static_cast (m_PaintManager.FindControl(_T("lab_msg_error"))); - pCtl = static_cast (m_PaintManager.FindControl(_T("ctl_msg_error"))); - } - pLbl->SetVisible(true); - pCtl->SetVisible(true); - - std::stringstream ss; - ss<<"lbl_msg_"< (m_PaintManager.FindControl(Base::CharacterSet::ANSIToUnicode(ss.str()).c_str())); - if (pTextUI) - { - pTextUI->SetVisible(true); - if (!m_dstrExMsg.IsEmpty()) - { - CDuiString theMsg = pTextUI->GetText(); - theMsg.Replace(_T("$"), m_dstrExMsg); - pTextUI->SetText(theMsg); - } - } -} - -LPCTSTR MessageBoxWhd::GetWindowClassName() const -{ - return _T("MessageBoxWhd"); -} - -UINT MessageBoxWhd::GetClassStyle() const -{ - return UI_CLASSSTYLE_DIALOG; -} - - -void MessageBoxWhd::OnFinalMessage( HWND hWnd) -{ - delete this; -} - -DuiLib::CDuiString MessageBoxWhd::GetSkinFolder() -{ - return _T("skin\\"); -} - -DuiLib::CDuiString MessageBoxWhd::GetSkinFile() -{ - return _T("MessageBox.xml"); -} - -DuiLib::UILIB_RESOURCETYPE MessageBoxWhd::GetResourceType() const -{ - return UILIB_FILE; -} - -void MessageBoxWhd::OnClick( TNotifyUI& msg ) -{ - if (msg.pSender->GetName() == _T("btn_msg_ok")) - { - Close(); - } - if (msg.pSender->GetName() == _T("closebtn")) - { - Close(); - } +#include "stdafx.h" +#include "MessageBoxWhd.h" +#include +#include "Base/CharacterSet.h" + +DUI_BEGIN_MESSAGE_MAP(MessageBoxWhd, WindowImplBase) +DUI_ON_MSGTYPE(DUI_MSGTYPE_CLICK,OnClick) +DUI_END_MESSAGE_MAP() + +MessageBoxWhd::MessageBoxWhd(MsgType type, UINT code, CDuiString msg) +{ + m_uType = type; + m_uMsgCode = code; + m_dstrExMsg = msg; +} + +MessageBoxWhd::~MessageBoxWhd(void) +{ +} + +void MessageBoxWhd::InitWindow() +{ + CLabelUI* pLbl = NULL; + CControlUI* pCtl = NULL; + if (m_uType == Info) + { + pLbl = static_cast (m_PaintManager.FindControl(_T("lab_msg_info"))); + pCtl = static_cast (m_PaintManager.FindControl(_T("ctl_msg_info"))); + } + else if (m_uType == Warn) + { + pLbl = static_cast (m_PaintManager.FindControl(_T("lab_msg_warn"))); + pCtl = static_cast (m_PaintManager.FindControl(_T("ctl_msg_warn"))); + } + else if (m_uType == Error) + { + pLbl = static_cast (m_PaintManager.FindControl(_T("lab_msg_error"))); + pCtl = static_cast (m_PaintManager.FindControl(_T("ctl_msg_error"))); + } + pLbl->SetVisible(true); + pCtl->SetVisible(true); + + std::stringstream ss; + ss<<"lbl_msg_"< (m_PaintManager.FindControl(Base::CharacterSet::ANSIToUnicode(ss.str()).c_str())); + if (pTextUI) + { + pTextUI->SetVisible(true); + if (!m_dstrExMsg.IsEmpty()) + { + CDuiString theMsg = pTextUI->GetText(); + theMsg.Replace(_T("$"), m_dstrExMsg); + pTextUI->SetText(theMsg); + } + } +} + +LPCTSTR MessageBoxWhd::GetWindowClassName() const +{ + return _T("MessageBoxWhd"); +} + +UINT MessageBoxWhd::GetClassStyle() const +{ + return UI_CLASSSTYLE_DIALOG; +} + + +void MessageBoxWhd::OnFinalMessage( HWND hWnd) +{ + delete this; +} + +DuiLib::CDuiString MessageBoxWhd::GetSkinFolder() +{ + return _T("skin\\"); +} + +DuiLib::CDuiString MessageBoxWhd::GetSkinFile() +{ + return _T("MessageBox.xml"); +} + +DuiLib::UILIB_RESOURCETYPE MessageBoxWhd::GetResourceType() const +{ + return UILIB_FILE; +} + +void MessageBoxWhd::OnClick( TNotifyUI& msg ) +{ + if (msg.pSender->GetName() == _T("btn_msg_ok")) + { + Close(); + } + if (msg.pSender->GetName() == _T("closebtn")) + { + Close(); + } } \ No newline at end of file diff --git a/RedisStudio/MessageBoxWhd.h b/RedisStudio/MessageBoxWhd.h index 0c88eb1..249f6d9 100644 --- a/RedisStudio/MessageBoxWhd.h +++ b/RedisStudio/MessageBoxWhd.h @@ -1,40 +1,40 @@ -#pragma once - -class MessageBoxWhd : public WindowImplBase -{ -public: - enum MsgType - { - Info, - Warn, - Error - }; - -public: - MessageBoxWhd(MsgType type, UINT code, CDuiString msg); - - ~MessageBoxWhd(void); - - void InitWindow(); - - LPCTSTR GetWindowClassName() const; - - UINT GetClassStyle() const; - - void OnFinalMessage(HWND hWnd);; - - virtual CDuiString GetSkinFolder(); - - virtual CDuiString GetSkinFile(); - - virtual UILIB_RESOURCETYPE GetResourceType() const; - - DUI_DECLARE_MESSAGE_MAP() - - virtual void OnClick(TNotifyUI& msg); - -private: - MsgType m_uType; - CDuiString m_dstrExMsg; - UINT m_uMsgCode; -}; +#pragma once + +class MessageBoxWhd : public WindowImplBase +{ +public: + enum MsgType + { + Info, + Warn, + Error + }; + +public: + MessageBoxWhd(MsgType type, UINT code, CDuiString msg); + + ~MessageBoxWhd(void); + + void InitWindow(); + + LPCTSTR GetWindowClassName() const; + + UINT GetClassStyle() const; + + void OnFinalMessage(HWND hWnd);; + + virtual CDuiString GetSkinFolder(); + + virtual CDuiString GetSkinFile(); + + virtual UILIB_RESOURCETYPE GetResourceType() const; + + DUI_DECLARE_MESSAGE_MAP() + + virtual void OnClick(TNotifyUI& msg); + +private: + MsgType m_uType; + CDuiString m_dstrExMsg; + UINT m_uMsgCode; +}; diff --git a/RedisStudio/Redis/AbstractRedisModel.h b/RedisStudio/Redis/AbstractRedisModel.h index 2f1482e..5fa533f 100644 --- a/RedisStudio/Redis/AbstractRedisModel.h +++ b/RedisStudio/Redis/AbstractRedisModel.h @@ -1,31 +1,29 @@ -#ifndef AbstractRedisModel_INCLUDED -#define AbstractRedisModel_INCLUDED - -#include "RedisResult.h" -#include "RedisClient.h" - -class AbstractRedisModel -{ -public: - AbstractRedisModel(RedisClient* client) : m_pClient(client) {} - - virtual bool GetData(const std::string& key, RedisResult& results) = 0; - - virtual bool UpdateData(const std::string& key, - const std::string& oldValue, - const std::string& newValue, - int idx = 0, - const std::string& field="") = 0; - - - - RedisClient* GetClient() - { - return m_pClient; - } - -private: - RedisClient* m_pClient; -}; - -#endif +#ifndef AbstractRedisModel_INCLUDED +#define AbstractRedisModel_INCLUDED + +#include "RedisResult.h" +#include "RedisClient.h" + +class AbstractRedisModel +{ +public: + AbstractRedisModel(RedisClient* client) : m_pClient(client) {} + + virtual bool GetData(const std::string& key, RedisResult& results) = 0; + + virtual bool UpdateData(const std::string& key, + const std::string& oldValue, + const std::string& newValue, + int idx = 0, + const std::string& field="") = 0; + + RedisClient* GetClient() + { + return m_pClient; + } + +private: + RedisClient* m_pClient; +}; + +#endif diff --git a/RedisStudio/Redis/RedisClient.cpp b/RedisStudio/Redis/RedisClient.cpp index c66a44f..f569e61 100644 --- a/RedisStudio/Redis/RedisClient.cpp +++ b/RedisStudio/Redis/RedisClient.cpp @@ -1,318 +1,357 @@ -#include "StdAfx.h" -#include "RedisClient.h" -#include -#include "../Base/CharacterSet.h" -#include "RedisResult.h" -#include "AbstractRedisModel.h" - -RedisClient::RedisClient() : m_bReConnect(true),m_isConnected(false), -m_pClient(NULL) -{ - m_ModelFactory.reset(new RedisModelFactory(this)); -} - - -RedisClient::~RedisClient() -{ - -} - - -RedisClient& RedisClient::GetInstance() -{ - static RedisClient client; - return client; -} - -void RedisClient::SetServerInfo( const CDuiString& name, const string& ip, int port,const string& auth ) -{ - m_strName = name; - m_strIP = ip; - m_iPort = port; - m_strAuth = auth; -} - -bool RedisClient::Connect() -{ - if (IsConnected()) - { - Quit(); - } - if (m_strName.IsEmpty()) return false; - struct timeval timeout = { 5, 500000 }; - m_pClient = redisConnectWithTimeout((char*)m_strIP.c_str(), - m_iPort, - timeout); - if (m_pClient->err) { - SetLastError(m_pClient->errstr); - m_fnDisConnect(GetLastError()); - return false; - } - if (!m_strAuth.empty()) - { - redisReply* reply = Command("AUTH %s", m_strAuth.c_str()); - if (!(reply && reply->type==REDIS_REPLY_STATUS)) - { - SetLastError(reply->str); - return false; - } - } - m_isConnected = true; - if (m_isConnected && DatabasesNum(m_Databases)) return true; - return false; -} - - -bool RedisClient::IsConnected() -{ - //redisReply* reply = Command("ping"); - //if (reply->type == REDIS_REPLY_STATUS) - //{ - // return true; - //} - //return false; - return m_isConnected; -} - -void RedisClient::NeedReConnect() -{ - m_bReConnect = true; -} - - -bool RedisClient::Info(std::string& results) -{ - bool retVal = false; - - if (!IsConnected()) return retVal; - redisReply* reply = Command("info"); - if (!reply) return retVal; - - if (reply->type == REDIS_REPLY_STRING) - { - retVal = true; - results = reply->str; - } - freeReplyObject(reply); - - return retVal; -} - -bool RedisClient::keys(TSeqArrayResults& results) -{ - bool retVal = false; - - if (!IsConnected()) return retVal; - - redisReply* reply = Command("KEYS *"); - if (!reply) return retVal; - - if (reply->type == REDIS_REPLY_ARRAY) - { - retVal = true; - std::size_t i = 0; - redisReply* tmpReply ; - while (i < reply->elements) - { - tmpReply = reply->element[i]; - results.push_back(tmpReply->str); - i++; - } - } - results.sort(); - freeReplyObject(reply); - return retVal; -} - -bool RedisClient::Exists(const std::string& key) -{ - ScopedRedisReply reply(Command("EXISTS %s", key.c_str())); - if (reply.IsNull() || reply->type!=REDIS_REPLY_INTEGER || reply->integer==0) return false; - return true; -} - -bool RedisClient::Type(const std::string& key, string& type) -{ - bool retVal = false; - redisReply* reply = Command("TYPE %s", key.c_str()); - if (!reply) return retVal; - if (reply->type == REDIS_REPLY_STATUS) - { - type = reply->str; - retVal = true; - } - freeReplyObject(reply); - return true; -} - -void RedisClient::Quit() -{ - Command("quit"); - m_isConnected = false; -} - -redisReply* RedisClient::Command( const char* fmt, ... ) -{ - if (!m_pClient) NULL; - Base::Mutex::ScopedLock scopedLock(m_mutex); - redisReply* reply = NULL; - va_list ap; - va_start(ap, fmt); - reply = (redisReply*) redisvCommand(m_pClient, fmt, ap); - va_end(ap); - if (reply && reply->type == REDIS_REPLY_ERROR) - { - SetLastError(reply->str); - } - if (reply==NULL || reply->type==REDIS_REPLY_ERROR) - { - if (reply != NULL) { - m_fnDisConnect(GetLastError()); - } - m_isConnected = false; - } - - return reply; -} - -void RedisClient::SetLastError( const std::string& err ) -{ - m_StrErr = Base::CharacterSet::ANSIToUnicode(err).c_str(); -} - -DuiLib::CDuiString RedisClient::GetLastError() -{ - return m_StrErr; -} - -DuiLib::CDuiString RedisClient::GetName() -{ - return m_strName; -} - -bool RedisClient::DatabasesNum(int& num) -{ - bool retVal = false; - redisReply* reply = Command("config get databases"); - if (!reply) return retVal; - - if (reply->type == REDIS_REPLY_ARRAY && reply->elements>1 ) - { - retVal = true; - num = atoi(reply->element[1]->str); - } - - return retVal; -} - -int RedisClient::DatabasesNum() -{ - return m_Databases; -} - -bool RedisClient::SelectDB( int dbindex ) -{ - redisReply* reply = Command("SELECT %d", dbindex); - if (!reply) return false; - if (reply->type != REDIS_REPLY_STATUS) - { - freeReplyObject(reply); - return false; - } - freeReplyObject(reply); - return true; -} - -bool RedisClient::GetConfig(TDicConfig& dicConfig) -{ - dicConfig.clear(); - redisReply* reply = Command("CONFIG GET *"); - if (!reply) return false; - if (reply->type != REDIS_REPLY_ARRAY) - { - freeReplyObject(reply); - return false; - } - std::size_t i = 0; - std::string configKey , configValue; - redisReply* tmpReply ; - while (i < reply->elements) - { - tmpReply = reply->element[i++]; - configKey.assign(tmpReply->str, tmpReply->len); - tmpReply = reply->element[i++]; - configValue.assign(tmpReply->str, tmpReply->len); - dicConfig.insert(std::make_pair(configKey, configValue)); - } - freeReplyObject(reply); - return true; -} - -bool RedisClient::SetConfig(const TDicConfig& dicConfig) -{ - TDicConfig::const_iterator it = dicConfig.begin(); - TDicConfig::const_iterator itend = dicConfig.end(); - - for (; it!=itend; ++it) - { - std::string key = it->first; - std::string val = it->second; - redisReply* reply = Command("CONFIG SET %s %s", key.c_str(), val.c_str()); - if (!reply) return false; - if (reply->type != REDIS_REPLY_STATUS) - { - freeReplyObject(reply); - return false; - } - freeReplyObject(reply); - } - - return true; -} - -bool RedisClient::ReWriteConfig() -{ - redisReply* reply = Command("CONFIG REWRITE"); - if (!reply) return false; - - if (reply->type != REDIS_REPLY_STATUS) - { - freeReplyObject(reply); - return false; - } - freeReplyObject(reply); - return true; -} - -bool RedisClient::GetData( const std::string& key, std::string& type, RedisResult& results ) -{ - redisReply* reply = NULL; - if (!Type(key, type)) return false; - - if (type == "none") return false; - return m_ModelFactory->GetRedisModel(type)->GetData(key, results); -} - -bool RedisClient::DelKey( const std::string& key ) -{ - ScopedRedisReply reply(Command("DEL %s", key.c_str())); - if (reply.IsNull() || reply->type != REDIS_REPLY_INTEGER || reply->integer == 0) - { - return false; - } - return true; -} - -bool RedisClient::UpdateData( const std::string& key, - const std::string& oldValue, - const std::string& newValue, - int idx, - const std::string& field) -{ - redisReply* reply = NULL; - std::string type; - if (!Type(key, type)) return false; - - if (type == "none") return false; - return m_ModelFactory->GetRedisModel(type)->UpdateData(key, oldValue, newValue, idx, field); -} +#include "StdAfx.h" +#include "RedisClient.h" +#include +#include "../Base/CharacterSet.h" +#include "RedisResult.h" +#include "AbstractRedisModel.h" + +RedisClient::RedisClient() : m_bReConnect(true),m_isConnected(false), +m_pClient(NULL) +{ + m_ModelFactory.reset(new RedisModelFactory(this)); +} + + +RedisClient::~RedisClient() +{ + +} + +RedisClient& RedisClient::GetInstance() +{ + static RedisClient client; + return client; +} + +void RedisClient::SetServerInfo( const CDuiString& name, const string& ip, int port,const string& auth ) +{ + m_strName = name; + m_strIP = ip; + m_iPort = port; + m_strAuth = auth; +} + +bool RedisClient::Connect() +{ + if (IsConnected()) + { + Quit(); + } + if (m_strName.IsEmpty()) return false; + struct timeval timeout = { 5, 500000 }; + m_pClient = redisConnectWithTimeout((char*)m_strIP.c_str(), + m_iPort, + timeout); + if (m_pClient->err) { + SetLastError(m_pClient->errstr); + m_fnDisConnect(GetLastError()); + return false; + } + if (!m_strAuth.empty()) + { + redisReply* reply = Command("AUTH %s", m_strAuth.c_str()); + if (!(reply && reply->type==REDIS_REPLY_STATUS)) + { + SetLastError(reply->str); + return false; + } + } + m_isConnected = true; + if (m_isConnected && DatabasesNum(m_Databases)) return true; + return false; +} + + +bool RedisClient::IsConnected() +{ + //redisReply* reply = Command("ping"); + //if (reply->type == REDIS_REPLY_STATUS) + //{ + // return true; + //} + //return false; + return m_isConnected; +} + +void RedisClient::NeedReConnect() +{ + m_bReConnect = true; +} + + +bool RedisClient::Info(std::string& results) +{ + bool retVal = false; + + if (!IsConnected()) return retVal; + redisReply* reply = Command("info"); + if (!reply) return retVal; + + if (reply->type == REDIS_REPLY_STRING) + { + retVal = true; + results = reply->str; + } + freeReplyObject(reply); + + return retVal; +} + +bool RedisClient::keys(const std::string& matchstr, TSeqArrayResults& results) +{ + bool retVal = false; + + if (!IsConnected()) return retVal; + + redisReply* reply = Command("KEYS %s", matchstr.c_str()); + if (!reply) return retVal; + + if (reply->type == REDIS_REPLY_ARRAY) + { + retVal = true; + std::size_t i = 0; + redisReply* tmpReply ; + while (i < reply->elements) + { + tmpReply = reply->element[i]; + results.push_back(tmpReply->str); + i++; + } + } + results.sort(); + freeReplyObject(reply); + return retVal; +} + +bool RedisClient::Exists(const std::string& key) +{ + ScopedRedisReply reply(Command("EXISTS %s", key.c_str())); + if (reply.IsNull() || reply->type!=REDIS_REPLY_INTEGER || reply->integer==0) return false; + return true; +} + +bool RedisClient::Type(const std::string& key, string& type) +{ + bool retVal = false; + redisReply* reply = Command("TYPE %s", key.c_str()); + if (!reply) return retVal; + if (reply->type == REDIS_REPLY_STATUS) + { + type = reply->str; + retVal = true; + } + freeReplyObject(reply); + return true; +} + +long long RedisClient::TTL(const std::string& key) +{ + long long ttl = 0; + ScopedRedisReply reply(Command("TTL %s", key.c_str())); + if (!reply.IsNull() && reply->type == REDIS_REPLY_INTEGER) + { + ttl = reply->integer; + } + return ttl; +} + +void RedisClient::Quit() +{ + Command("quit"); + m_isConnected = false; +} + +redisReply* RedisClient::Command( const char* fmt, ... ) +{ + if (!m_pClient) NULL; + Base::Mutex::ScopedLock scopedLock(m_mutex); + redisReply* reply = NULL; + va_list ap; + va_start(ap, fmt); + reply = (redisReply*) redisvCommand(m_pClient, fmt, ap); + va_end(ap); + if (reply && reply->type == REDIS_REPLY_ERROR) + { + SetLastError(reply->str); + } + if (reply==NULL) + { + if (reply != NULL) { + m_fnDisConnect(GetLastError()); + } + m_isConnected = false; + } + + return reply; +} + +void RedisClient::SetLastError( const std::string& err ) +{ + m_StrErr = Base::CharacterSet::ANSIToUnicode(err).c_str(); +} + +DuiLib::CDuiString RedisClient::GetLastError() +{ + return m_StrErr; +} + +DuiLib::CDuiString RedisClient::GetName() +{ + return m_strName; +} + +bool RedisClient::DatabasesNum(int& num) +{ + bool retVal = false; + redisReply* reply = Command("config get databases"); + if (!reply) { + return retVal; + } + + if (reply->type == REDIS_REPLY_ARRAY && reply->elements>1 ) + { + retVal = true; + num = atoi(reply->element[1]->str); + freeReplyObject(reply); + } else { + freeReplyObject(reply); + for (int idx = 0; idx<16; ++idx) { + reply = Command("SELECT %d", idx); + if (!reply) return false; + + if (reply->type == REDIS_REPLY_STATUS) + { + retVal = true; + num = idx + 1; + freeReplyObject(reply); + } else { + freeReplyObject(reply); + break; + } + } + } + return retVal; +} + +int RedisClient::DatabasesNum() +{ + return m_Databases; +} + +bool RedisClient::SelectDB( int dbindex ) +{ + redisReply* reply = Command("SELECT %d", dbindex); + if (!reply) return false; + if (reply->type != REDIS_REPLY_STATUS) + { + freeReplyObject(reply); + return false; + } + freeReplyObject(reply); + return true; +} + +long long RedisClient::DbSize() +{ + long long dbsize = 0; + ScopedRedisReply reply(Command("DBSIZE")); + if (!reply.IsNull() && reply->type == REDIS_REPLY_INTEGER) + { + dbsize = reply->integer; + } + return dbsize; +} + +bool RedisClient::GetConfig(TDicConfig& dicConfig) +{ + dicConfig.clear(); + redisReply* reply = Command("CONFIG GET *"); + if (!reply) return false; + if (reply->type != REDIS_REPLY_ARRAY) + { + freeReplyObject(reply); + return false; + } + std::size_t i = 0; + std::string configKey , configValue; + redisReply* tmpReply ; + while (i < reply->elements) + { + tmpReply = reply->element[i++]; + configKey.assign(tmpReply->str, tmpReply->len); + tmpReply = reply->element[i++]; + configValue.assign(tmpReply->str, tmpReply->len); + dicConfig.insert(std::make_pair(configKey, configValue)); + } + freeReplyObject(reply); + return true; +} + +bool RedisClient::SetConfig(const TDicConfig& dicConfig) +{ + TDicConfig::const_iterator it = dicConfig.begin(); + TDicConfig::const_iterator itend = dicConfig.end(); + + for (; it!=itend; ++it) + { + std::string key = it->first; + std::string val = it->second; + redisReply* reply = Command("CONFIG SET %s %s", key.c_str(), val.c_str()); + if (!reply) return false; + if (reply->type != REDIS_REPLY_STATUS) + { + freeReplyObject(reply); + return false; + } + freeReplyObject(reply); + } + + return true; +} + +bool RedisClient::ReWriteConfig() +{ + redisReply* reply = Command("CONFIG REWRITE"); + if (!reply) return false; + + if (reply->type != REDIS_REPLY_STATUS) + { + freeReplyObject(reply); + return false; + } + freeReplyObject(reply); + return true; +} + +bool RedisClient::GetData( const std::string& key, std::string& type, RedisResult& results ) +{ + redisReply* reply = NULL; + if (!Type(key, type)) return false; + + if (type == "none") return false; + return m_ModelFactory->GetRedisModel(type)->GetData(key, results); +} + +bool RedisClient::DelKey( const std::string& key ) +{ + ScopedRedisReply reply(Command("DEL %s", key.c_str())); + if (reply.IsNull() || reply->type != REDIS_REPLY_INTEGER || reply->integer == 0) + { + return false; + } + return true; +} + +bool RedisClient::UpdateData( const std::string& key, + const std::string& oldValue, + const std::string& newValue, + int idx, + const std::string& field) +{ + redisReply* reply = NULL; + std::string type; + if (!Type(key, type)) return false; + + if (type == "none") return false; + return m_ModelFactory->GetRedisModel(type)->UpdateData(key, oldValue, newValue, idx, field); +} diff --git a/RedisStudio/Redis/RedisClient.h b/RedisStudio/Redis/RedisClient.h index fddde33..598ff22 100644 --- a/RedisStudio/Redis/RedisClient.h +++ b/RedisStudio/Redis/RedisClient.h @@ -1,4 +1,6 @@ -#pragma once +#ifndef RedisClient_INCLUDED +#define RedisClient_INCLUDED + #include "hiredis/hiredis.h" #include #include @@ -9,9 +11,9 @@ typedef void (* callback)(const CDuiString& ); - class RedisResult; +/// ĵĵпع class RedisClient { public: @@ -36,18 +38,22 @@ class RedisClient bool Info(std::string& results); - bool keys(TSeqArrayResults& results); + bool keys(const std::string &, TSeqArrayResults& results); bool Exists(const std::string& key); bool Type(const std::string& key, string& type); + long long TTL(const std::string& key); + bool DatabasesNum(int& num); int DatabasesNum(); bool SelectDB(int dbindex); + long long DbSize(); + bool GetConfig(TDicConfig& dicConfig); bool SetConfig(const TDicConfig& dicConfig); @@ -91,4 +97,6 @@ class RedisClient Base::Mutex m_mutex; std::auto_ptr m_ModelFactory; -}; \ No newline at end of file +}; + +#endif diff --git a/RedisStudio/Redis/RedisHashModel.cpp b/RedisStudio/Redis/RedisHashModel.cpp index 16352c8..14bdaef 100644 --- a/RedisStudio/Redis/RedisHashModel.cpp +++ b/RedisStudio/Redis/RedisHashModel.cpp @@ -1,60 +1,60 @@ -#include "StdAfx.h" -#include "RedisHashModel.h" - -RedisHashModel::RedisHashModel( RedisClient* client ) : AbstractRedisModel(client) -{ - -} - -bool RedisHashModel::GetData( const std::string& key, RedisResult& results ) -{ - bool retVal = false; - redisReply* reply = GetClient()->Command("HKEYS %s", key.c_str()); - if (!reply) return retVal; - results.NewColumn("Field "); - results.NewColumn("Value"); - if (reply->type == REDIS_REPLY_ARRAY) - { - std::size_t i = 0; - redisReply* tmpReply ; - bool isOK = true; - while (i < reply->elements) - { - tmpReply = reply->element[i]; - redisReply* theReply = GetClient()->Command("HGET %s %s", key.c_str(), tmpReply->str); - if (!theReply) break; - if (theReply->type != REDIS_REPLY_STRING) - { - isOK = false; - freeReplyObject(theReply); - break; - } - results.NewRow(); - - string& myFiled = results.Value(results.RowSize()-1, 0) ; - myFiled.assign(tmpReply->str, tmpReply->len); - - string& myvalue = results.Value(results.RowSize()-1, 1) ; - myvalue.assign(theReply->str, theReply->len); - freeReplyObject(theReply); - i++; - } - if (isOK) - retVal = true; - } - freeReplyObject(reply); - return retVal; -} - -bool RedisHashModel::UpdateData( const std::string& key, - const std::string& oldValue, - const std::string& newValue, - int idx, - const std::string& field) -{ - /// ϣ field ѾҾֵѱֵǣ 0 - ScopedRedisReply reply(GetClient()->Command("HSET %s %s %s", key.c_str(), field.c_str(), newValue.c_str())); - if(reply.IsNull() || reply->type != REDIS_REPLY_INTEGER || reply->integer!=0) - return false; - return true; -} +#include "StdAfx.h" +#include "RedisHashModel.h" + +RedisHashModel::RedisHashModel( RedisClient* client ) : AbstractRedisModel(client) +{ + +} + +bool RedisHashModel::GetData( const std::string& key, RedisResult& results ) +{ + bool retVal = false; + redisReply* reply = GetClient()->Command("HKEYS %s", key.c_str()); + if (!reply) return retVal; + results.NewColumn("Field "); + results.NewColumn("Value"); + if (reply->type == REDIS_REPLY_ARRAY) + { + std::size_t i = 0; + redisReply* tmpReply ; + bool isOK = true; + while (i < reply->elements) + { + tmpReply = reply->element[i]; + redisReply* theReply = GetClient()->Command("HGET %s %s", key.c_str(), tmpReply->str); + if (!theReply) break; + if (theReply->type != REDIS_REPLY_STRING) + { + isOK = false; + freeReplyObject(theReply); + break; + } + results.NewRow(); + + string& myFiled = results.Value(results.RowSize()-1, 0) ; + myFiled.assign(tmpReply->str, tmpReply->len); + + string& myvalue = results.Value(results.RowSize()-1, 1) ; + myvalue.assign(theReply->str, theReply->len); + freeReplyObject(theReply); + i++; + } + if (isOK) + retVal = true; + } + freeReplyObject(reply); + return retVal; +} + +bool RedisHashModel::UpdateData( const std::string& key, + const std::string& oldValue, + const std::string& newValue, + int idx, + const std::string& field) +{ + /// 如果哈希表中域 field 已经存在且旧值已被新值覆盖,返回 0 。 + ScopedRedisReply reply(GetClient()->Command("HSET %s %s %s", key.c_str(), field.c_str(), newValue.c_str())); + if(reply.IsNull() || reply->type != REDIS_REPLY_INTEGER || reply->integer!=0) + return false; + return true; +} diff --git a/RedisStudio/Redis/RedisHashModel.h b/RedisStudio/Redis/RedisHashModel.h index 3c27cf4..489cc6e 100644 --- a/RedisStudio/Redis/RedisHashModel.h +++ b/RedisStudio/Redis/RedisHashModel.h @@ -1,20 +1,20 @@ -#ifndef RedisHashModel_INCLUDED -#define RedisHashModel_INCLUDED - -#include "AbstractRedisModel.h" - -class RedisHashModel : public AbstractRedisModel -{ -public: - RedisHashModel(RedisClient* client); - - virtual bool GetData(const std::string& key, RedisResult& results); - - virtual bool UpdateData(const std::string& key, - const std::string& oldValue, - const std::string& newValue, - int idx, - const std::string& field=""); -}; - -#endif +#ifndef RedisHashModel_INCLUDED +#define RedisHashModel_INCLUDED + +#include "AbstractRedisModel.h" + +class RedisHashModel : public AbstractRedisModel +{ +public: + RedisHashModel(RedisClient* client); + + virtual bool GetData(const std::string& key, RedisResult& results); + + virtual bool UpdateData(const std::string& key, + const std::string& oldValue, + const std::string& newValue, + int idx, + const std::string& field=""); +}; + +#endif diff --git a/RedisStudio/Redis/RedisListModel.cpp b/RedisStudio/Redis/RedisListModel.cpp index 3979d06..7f64e99 100644 --- a/RedisStudio/Redis/RedisListModel.cpp +++ b/RedisStudio/Redis/RedisListModel.cpp @@ -1,44 +1,44 @@ -#include "StdAfx.h" -#include "RedisListModel.h" - -RedisListModel::RedisListModel( RedisClient* client ) : AbstractRedisModel(client) -{ - -} - -bool RedisListModel::GetData( const std::string& key, RedisResult& results ) -{ - bool retVal = false; - redisReply* reply = GetClient()->Command("LRANGE %s %d %d", key.c_str(), 0, -1); - if (!reply) return retVal; - results.NewColumn("Value"); - if (reply->type == REDIS_REPLY_ARRAY) - { - std::size_t i = 0; - redisReply* tmpReply ; - while (i < reply->elements) - { - tmpReply = reply->element[i]; - results.NewRow(); - string& myvalue = results.Value(results.RowSize()-1, 0); - myvalue.assign(tmpReply->str, tmpReply->len); - i++; - } - retVal = true; - } - freeReplyObject(reply); - - return retVal; -} - -bool RedisListModel::UpdateData( const std::string& key, - const std::string& oldValue, - const std::string& newValue, - int idx, - const std::string& field) -{ - ScopedRedisReply reply(GetClient()->Command("LSET %s %d %s", key.c_str(), idx, newValue.c_str())); - - if (reply.IsNull() || reply->type != REDIS_REPLY_STATUS) return false; - return true; -} +#include "StdAfx.h" +#include "RedisListModel.h" + +RedisListModel::RedisListModel( RedisClient* client ) : AbstractRedisModel(client) +{ + +} + +bool RedisListModel::GetData( const std::string& key, RedisResult& results ) +{ + bool retVal = false; + redisReply* reply = GetClient()->Command("LRANGE %s %d %d", key.c_str(), 0, -1); + if (!reply) return retVal; + results.NewColumn("Value"); + if (reply->type == REDIS_REPLY_ARRAY) + { + std::size_t i = 0; + redisReply* tmpReply ; + while (i < reply->elements) + { + tmpReply = reply->element[i]; + results.NewRow(); + string& myvalue = results.Value(results.RowSize()-1, 0); + myvalue.assign(tmpReply->str, tmpReply->len); + i++; + } + retVal = true; + } + freeReplyObject(reply); + + return retVal; +} + +bool RedisListModel::UpdateData( const std::string& key, + const std::string& oldValue, + const std::string& newValue, + int idx, + const std::string& field) +{ + ScopedRedisReply reply(GetClient()->Command("LSET %s %d %s", key.c_str(), idx, newValue.c_str())); + + if (reply.IsNull() || reply->type != REDIS_REPLY_STATUS) return false; + return true; +} diff --git a/RedisStudio/Redis/RedisModelFactory.h b/RedisStudio/Redis/RedisModelFactory.h index ec4cf75..ac6edcd 100644 --- a/RedisStudio/Redis/RedisModelFactory.h +++ b/RedisStudio/Redis/RedisModelFactory.h @@ -1,25 +1,25 @@ -#ifndef RedisModelFactory_INCLUDED -#define RedisModelFactory_INCLUDED -#include - -class RedisClient; -class AbstractRedisModel; - -class RedisModelFactory -{ -public: - RedisModelFactory(RedisClient* client); - - ~RedisModelFactory(); - - void Register(const std::string& type, AbstractRedisModel* p); - - void UnregisterModel(const std::string& type); - - AbstractRedisModel* GetRedisModel(const std::string& type); -private: - typedef std::map TDicModels; - TDicModels m_oModels; -}; - -#endif +#ifndef RedisModelFactory_INCLUDED +#define RedisModelFactory_INCLUDED +#include + +class RedisClient; +class AbstractRedisModel; + +class RedisModelFactory +{ +public: + RedisModelFactory(RedisClient* client); + + ~RedisModelFactory(); + + void Register(const std::string& type, AbstractRedisModel* p); + + void UnregisterModel(const std::string& type); + + AbstractRedisModel* GetRedisModel(const std::string& type); +private: + typedef std::map TDicModels; + TDicModels m_oModels; +}; + +#endif diff --git a/RedisStudio/Redis/RedisResult.cpp b/RedisStudio/Redis/RedisResult.cpp index 9442508..1656823 100644 --- a/RedisStudio/Redis/RedisResult.cpp +++ b/RedisStudio/Redis/RedisResult.cpp @@ -1,70 +1,70 @@ -#include "stdafx.h" -#include "RedisResult.h" - - -RedisResult::RedisResult(void) -{ -} - -RedisResult::~RedisResult(void) -{ -} - - -void RedisResult::Clear() -{ - m_ResultTable.clear(); - m_ResultName.clear(); -} - -void RedisResult::NewColumn( const string& name ) -{ - m_ResultName.push_back(name); - if (ColumnSize() > 0) - { - m_ResultTable.resize(ColumnSize()); - m_ResultTable[ColumnSize()-1].resize(RowSize()); - } - else - { - m_ResultTable.resize(ColumnSize()); - } -} - -void RedisResult::NewRow() -{ - TSeqResultTable::iterator it = m_ResultTable.begin(); - TSeqResultTable::iterator itend = m_ResultTable.end(); - - for (; it!=itend; ++it) - { - it->push_back(NullString); - } -} - -std::size_t RedisResult::ColumnSize() -{ - return m_ResultName.size(); -} - -std::size_t RedisResult::RowSize() -{ - if (!m_ResultName.empty()) - return m_ResultTable[0].size(); - - return 0; -} - -const std::string& RedisResult::ColumnName( std::size_t idx ) -{ - if (idx < m_ResultName.size()) - { - return m_ResultName[idx]; - } - return NullString; -} - -std::string& RedisResult::Value( std::size_t rowidx, std::size_t colidx ) -{ - return m_ResultTable[colidx][rowidx]; -} +#include "stdafx.h" +#include "RedisResult.h" + + +RedisResult::RedisResult(void) +{ +} + +RedisResult::~RedisResult(void) +{ +} + + +void RedisResult::Clear() +{ + m_ResultTable.clear(); + m_ResultName.clear(); +} + +void RedisResult::NewColumn( const string& name ) +{ + m_ResultName.push_back(name); + if (ColumnSize() > 0) + { + m_ResultTable.resize(ColumnSize()); + m_ResultTable[ColumnSize()-1].resize(RowSize()); + } + else + { + m_ResultTable.resize(ColumnSize()); + } +} + +void RedisResult::NewRow() +{ + TSeqResultTable::iterator it = m_ResultTable.begin(); + TSeqResultTable::iterator itend = m_ResultTable.end(); + + for (; it!=itend; ++it) + { + it->push_back(NullString); + } +} + +std::size_t RedisResult::ColumnSize() +{ + return m_ResultName.size(); +} + +std::size_t RedisResult::RowSize() +{ + if (!m_ResultName.empty()) + return m_ResultTable[0].size(); + + return 0; +} + +const std::string& RedisResult::ColumnName( std::size_t idx ) +{ + if (idx < m_ResultName.size()) + { + return m_ResultName[idx]; + } + return NullString; +} + +std::string& RedisResult::Value( std::size_t rowidx, std::size_t colidx ) +{ + return m_ResultTable[colidx][rowidx]; +} diff --git a/RedisStudio/Redis/RedisResult.h b/RedisStudio/Redis/RedisResult.h index c382392..20c72ac 100644 --- a/RedisStudio/Redis/RedisResult.h +++ b/RedisStudio/Redis/RedisResult.h @@ -1,37 +1,37 @@ -#pragma once - -#include -#include - - -class RedisResult -{ -public: - const string NullString; - typedef std::vector TSeqResultName; - typedef std::vector TSeqResultColumn; - typedef std::vector< TSeqResultColumn > TSeqResultTable; - -public: - RedisResult(void); - - ~RedisResult(void); - - void Clear(); - - void NewColumn(const string& name); - - void NewRow(); - - std::size_t ColumnSize(); - - std::size_t RowSize(); - - const std::string& ColumnName(std::size_t idx); - - std::string& Value(std::size_t rowidx, std::size_t colidx); - -private: - TSeqResultName m_ResultName; - TSeqResultTable m_ResultTable; -}; +#pragma once + +#include +#include + + +class RedisResult +{ +public: + const string NullString; + typedef std::vector TSeqResultName; + typedef std::vector TSeqResultColumn; + typedef std::vector< TSeqResultColumn > TSeqResultTable; + +public: + RedisResult(void); + + ~RedisResult(void); + + void Clear(); + + void NewColumn(const string& name); + + void NewRow(); + + std::size_t ColumnSize(); + + std::size_t RowSize(); + + const std::string& ColumnName(std::size_t idx); + + std::string& Value(std::size_t rowidx, std::size_t colidx); + +private: + TSeqResultName m_ResultName; + TSeqResultTable m_ResultTable; +}; diff --git a/RedisStudio/Redis/RedisSetModel.cpp b/RedisStudio/Redis/RedisSetModel.cpp index 77990aa..542f280 100644 --- a/RedisStudio/Redis/RedisSetModel.cpp +++ b/RedisStudio/Redis/RedisSetModel.cpp @@ -1,48 +1,48 @@ -#include "StdAfx.h" -#include "RedisSetModel.h" - -RedisSetModel::RedisSetModel( RedisClient* client ) : AbstractRedisModel(client) -{ - -} - -bool RedisSetModel::GetData( const std::string& key, RedisResult& results ) -{ - bool retVal = false; - redisReply* reply = GetClient()->Command("SMEMBERS %s", key.c_str()); - if (!reply) return retVal; - results.NewColumn("Value"); - if (reply->type == REDIS_REPLY_ARRAY) - { - std::size_t i = 0; - redisReply* tmpReply ; - while (i < reply->elements) - { - tmpReply = reply->element[i]; - results.NewRow(); - string& myvalue = results.Value(results.RowSize()-1, 0); - myvalue.assign(tmpReply->str, tmpReply->len); - i++; - } - retVal = true; - - } - freeReplyObject(reply); - return retVal; -} - -bool RedisSetModel::UpdateData( const std::string& key, - const std::string& oldValue, - const std::string& newValue, - int idx, - const std::string& field ) -{ - ScopedRedisReply reply(GetClient()->Command("SREM %s %s", key.c_str(), oldValue.c_str())); - if(reply.IsNull() || reply->type != REDIS_REPLY_INTEGER || reply->integer==0) - return false; - - ScopedRedisReply addReply(GetClient()->Command("SADD %s %s", key.c_str(), newValue.c_str())); - if (addReply.IsNull() || addReply->type != REDIS_REPLY_INTEGER || reply->integer==0) - return false; - return true; -} +#include "StdAfx.h" +#include "RedisSetModel.h" + +RedisSetModel::RedisSetModel( RedisClient* client ) : AbstractRedisModel(client) +{ + +} + +bool RedisSetModel::GetData( const std::string& key, RedisResult& results ) +{ + bool retVal = false; + redisReply* reply = GetClient()->Command("SMEMBERS %s", key.c_str()); + if (!reply) return retVal; + results.NewColumn("Value"); + if (reply->type == REDIS_REPLY_ARRAY) + { + std::size_t i = 0; + redisReply* tmpReply ; + while (i < reply->elements) + { + tmpReply = reply->element[i]; + results.NewRow(); + string& myvalue = results.Value(results.RowSize()-1, 0); + myvalue.assign(tmpReply->str, tmpReply->len); + i++; + } + retVal = true; + + } + freeReplyObject(reply); + return retVal; +} + +bool RedisSetModel::UpdateData( const std::string& key, + const std::string& oldValue, + const std::string& newValue, + int idx, + const std::string& field ) +{ + ScopedRedisReply reply(GetClient()->Command("SREM %s %s", key.c_str(), oldValue.c_str())); + if(reply.IsNull() || reply->type != REDIS_REPLY_INTEGER || reply->integer==0) + return false; + + ScopedRedisReply addReply(GetClient()->Command("SADD %s %s", key.c_str(), newValue.c_str())); + if (addReply.IsNull() || addReply->type != REDIS_REPLY_INTEGER || reply->integer==0) + return false; + return true; +} diff --git a/RedisStudio/Redis/RedisSetModel.h b/RedisStudio/Redis/RedisSetModel.h index 8f608ba..0288514 100644 --- a/RedisStudio/Redis/RedisSetModel.h +++ b/RedisStudio/Redis/RedisSetModel.h @@ -1,20 +1,20 @@ -#ifndef RedisSetModel_INCLUDED -#define RedisSetModel_INCLUDED - -#include "AbstractRedisModel.h" - -class RedisSetModel : public AbstractRedisModel -{ -public: - RedisSetModel(RedisClient* client); - - virtual bool GetData(const std::string& key, RedisResult& results); - - virtual bool UpdateData(const std::string& key, - const std::string& oldValue, - const std::string& newValue, - int idx, - const std::string& field=""); -}; - -#endif +#ifndef RedisSetModel_INCLUDED +#define RedisSetModel_INCLUDED + +#include "AbstractRedisModel.h" + +class RedisSetModel : public AbstractRedisModel +{ +public: + RedisSetModel(RedisClient* client); + + virtual bool GetData(const std::string& key, RedisResult& results); + + virtual bool UpdateData(const std::string& key, + const std::string& oldValue, + const std::string& newValue, + int idx, + const std::string& field=""); +}; + +#endif diff --git a/RedisStudio/Redis/RedisStringModel.cpp b/RedisStudio/Redis/RedisStringModel.cpp index c158ae3..c47087d 100644 --- a/RedisStudio/Redis/RedisStringModel.cpp +++ b/RedisStudio/Redis/RedisStringModel.cpp @@ -1,36 +1,36 @@ -#include "StdAfx.h" -#include "RedisStringModel.h" - -RedisStringModel::RedisStringModel( RedisClient* client ) : AbstractRedisModel(client) -{ - -} - -bool RedisStringModel::GetData( const std::string& key, RedisResult& results ) -{ - bool retVal = false; - redisReply* reply = GetClient()->Command("GET %s", key.c_str()); - if (!reply) return retVal; - results.NewColumn("Value"); - if (reply->type == REDIS_REPLY_STRING) - { - results.NewRow(); - string& myvalue = results.Value(results.RowSize()-1, 0); - myvalue.assign(reply->str, reply->len); - retVal = true; - } - freeReplyObject(reply); - return retVal; -} - -bool RedisStringModel::UpdateData( const std::string& key, - const std::string& oldValue, - const std::string& newValue, - int idx, - const std::string& field ) -{ - ScopedRedisReply reply(GetClient()->Command("SET %s %s", key.c_str(), newValue.c_str())); - if (reply.IsNull() || reply->type != REDIS_REPLY_STATUS) return false; - return true; -} - +#include "StdAfx.h" +#include "RedisStringModel.h" + +RedisStringModel::RedisStringModel( RedisClient* client ) : AbstractRedisModel(client) +{ + +} + +bool RedisStringModel::GetData( const std::string& key, RedisResult& results ) +{ + bool retVal = false; + redisReply* reply = GetClient()->Command("GET %s", key.c_str()); + if (!reply) return retVal; + results.NewColumn("Value"); + if (reply->type == REDIS_REPLY_STRING) + { + results.NewRow(); + string& myvalue = results.Value(results.RowSize()-1, 0); + myvalue.assign(reply->str, reply->len); + retVal = true; + } + freeReplyObject(reply); + return retVal; +} + +bool RedisStringModel::UpdateData( const std::string& key, + const std::string& oldValue, + const std::string& newValue, + int idx, + const std::string& field ) +{ + ScopedRedisReply reply(GetClient()->Command("SET %s %s", key.c_str(), newValue.c_str())); + if (reply.IsNull() || reply->type != REDIS_REPLY_STATUS) return false; + return true; +} + diff --git a/RedisStudio/Redis/RedisStringModel.h b/RedisStudio/Redis/RedisStringModel.h index 1ae9516..1fead5b 100644 --- a/RedisStudio/Redis/RedisStringModel.h +++ b/RedisStudio/Redis/RedisStringModel.h @@ -1,20 +1,20 @@ -#ifndef RedisStringModel_INCLUDED -#define RedisStringModel_INCLUDED - -#include "AbstractRedisModel.h" - -class RedisStringModel : public AbstractRedisModel -{ -public: - RedisStringModel(RedisClient* client); - - virtual bool GetData(const std::string& key, RedisResult& results); - - virtual bool UpdateData(const std::string& key, - const std::string& oldValue, - const std::string& newValue, - int idx, - const std::string& field=""); -}; - -#endif +#ifndef RedisStringModel_INCLUDED +#define RedisStringModel_INCLUDED + +#include "AbstractRedisModel.h" + +class RedisStringModel : public AbstractRedisModel +{ +public: + RedisStringModel(RedisClient* client); + + virtual bool GetData(const std::string& key, RedisResult& results); + + virtual bool UpdateData(const std::string& key, + const std::string& oldValue, + const std::string& newValue, + int idx, + const std::string& field=""); +}; + +#endif diff --git a/RedisStudio/Redis/RedisZSetModel.cpp b/RedisStudio/Redis/RedisZSetModel.cpp index c37c6c0..2431257 100644 --- a/RedisStudio/Redis/RedisZSetModel.cpp +++ b/RedisStudio/Redis/RedisZSetModel.cpp @@ -1,58 +1,58 @@ -#include "StdAfx.h" -#include "RedisZSetModel.h" - -RedisZSetModel::RedisZSetModel( RedisClient* client ) : AbstractRedisModel(client) -{ - -} - -bool RedisZSetModel::GetData( const std::string& key, RedisResult& results ) -{ - bool retVal = false; - redisReply* reply = GetClient()->Command("ZREVRANGE %s %d %d WITHSCORES", key.c_str(), 0, -1); - if (!reply) return retVal; - - results.NewColumn("Score"); - results.NewColumn("Value"); - if (reply->type == REDIS_REPLY_ARRAY) - { - std::size_t i = 0; - redisReply* tmpReply ; - while (i < reply->elements) - { - tmpReply = reply->element[i]; - if (i%2 == 0) - { - results.NewRow(); - - string& myvalue = results.Value(results.RowSize()-1, 1); - myvalue.assign(tmpReply->str, tmpReply->len); - } - else - { - string& myvalue = results.Value(results.RowSize()-1, 0); - myvalue.assign(tmpReply->str, tmpReply->len); - } - i++; - } - retVal = true; - } - freeReplyObject(reply); - return retVal; -} - -bool RedisZSetModel::UpdateData(const std::string& key, - const std::string& oldValue, - const std::string& newValue, - int idx, - const std::string& field) -{ - ScopedRedisReply reply(GetClient()->Command("ZREM %s %s", key.c_str(), oldValue.c_str())); - if(reply.IsNull() || reply->type != REDIS_REPLY_INTEGER || reply->integer==0) - return false; - - ScopedRedisReply addReply(GetClient()->Command("ZADD %s %s %s", key.c_str(), field.c_str(), newValue.c_str())); - if (addReply.IsNull() || addReply->type != REDIS_REPLY_INTEGER || reply->integer==0) - return false; - return true; -} +#include "StdAfx.h" +#include "RedisZSetModel.h" + +RedisZSetModel::RedisZSetModel( RedisClient* client ) : AbstractRedisModel(client) +{ + +} + +bool RedisZSetModel::GetData( const std::string& key, RedisResult& results ) +{ + bool retVal = false; + redisReply* reply = GetClient()->Command("ZREVRANGE %s %d %d WITHSCORES", key.c_str(), 0, -1); + if (!reply) return retVal; + + results.NewColumn("Score"); + results.NewColumn("Value"); + if (reply->type == REDIS_REPLY_ARRAY) + { + std::size_t i = 0; + redisReply* tmpReply ; + while (i < reply->elements) + { + tmpReply = reply->element[i]; + if (i%2 == 0) + { + results.NewRow(); + + string& myvalue = results.Value(results.RowSize()-1, 1); + myvalue.assign(tmpReply->str, tmpReply->len); + } + else + { + string& myvalue = results.Value(results.RowSize()-1, 0); + myvalue.assign(tmpReply->str, tmpReply->len); + } + i++; + } + retVal = true; + } + freeReplyObject(reply); + return retVal; +} + +bool RedisZSetModel::UpdateData(const std::string& key, + const std::string& oldValue, + const std::string& newValue, + int idx, + const std::string& field) +{ + ScopedRedisReply reply(GetClient()->Command("ZREM %s %s", key.c_str(), oldValue.c_str())); + if(reply.IsNull() || reply->type != REDIS_REPLY_INTEGER || reply->integer==0) + return false; + + ScopedRedisReply addReply(GetClient()->Command("ZADD %s %s %s", key.c_str(), field.c_str(), newValue.c_str())); + if (addReply.IsNull() || addReply->type != REDIS_REPLY_INTEGER || reply->integer==0) + return false; + return true; +} diff --git a/RedisStudio/Redis/RedisZSetModel.h b/RedisStudio/Redis/RedisZSetModel.h index 2e1cd3c..4739e47 100644 --- a/RedisStudio/Redis/RedisZSetModel.h +++ b/RedisStudio/Redis/RedisZSetModel.h @@ -1,20 +1,20 @@ -#ifndef RedisZSetModel_INCLUDED -#define RedisZSetModel_INCLUDED - -#include "AbstractRedisModel.h" - -class RedisZSetModel : public AbstractRedisModel -{ -public: - RedisZSetModel(RedisClient* client); - - virtual bool GetData(const std::string& key, RedisResult& results); - - virtual bool UpdateData(const std::string& key, - const std::string& oldValue, - const std::string& newValue, - int idx, - const std::string& field=""); -}; - -#endif +#ifndef RedisZSetModel_INCLUDED +#define RedisZSetModel_INCLUDED + +#include "AbstractRedisModel.h" + +class RedisZSetModel : public AbstractRedisModel +{ +public: + RedisZSetModel(RedisClient* client); + + virtual bool GetData(const std::string& key, RedisResult& results); + + virtual bool UpdateData(const std::string& key, + const std::string& oldValue, + const std::string& newValue, + int idx, + const std::string& field=""); +}; + +#endif diff --git a/RedisStudio/Redis/ScopedRedisReply.h b/RedisStudio/Redis/ScopedRedisReply.h index 0a0c5e9..d867d28 100644 --- a/RedisStudio/Redis/ScopedRedisReply.h +++ b/RedisStudio/Redis/ScopedRedisReply.h @@ -1,37 +1,34 @@ -#ifndef ScopedRedisReply_INCLUDED -#define ScopedRedisReply_INCLUDED - -#include "hiredis/hiredis.h" - -class ScopedRedisReply -{ -public: - ScopedRedisReply(redisReply* reply) : m_pReply(reply){} - - ~ScopedRedisReply() - { - if (m_pReply) freeReplyObject(m_pReply); - } - - bool IsNull() - { - if (m_pReply) return false; - return true; - } - - redisReply* operator -> () - { - if (m_pReply) - return m_pReply; - else - throw std::exception("NullPointer"); - } - -private: - redisReply* m_pReply; -}; - - - - -#endif +#ifndef ScopedRedisReply_INCLUDED +#define ScopedRedisReply_INCLUDED + +#include "hiredis/hiredis.h" + +class ScopedRedisReply +{ +public: + ScopedRedisReply(redisReply* reply) : m_pReply(reply){} + + ~ScopedRedisReply() + { + if (m_pReply) freeReplyObject(m_pReply); + } + + bool IsNull() + { + if (m_pReply) return false; + return true; + } + + redisReply* operator -> () + { + if (m_pReply) + return m_pReply; + else + throw std::exception("NullPointer"); + } + +private: + redisReply* m_pReply; +}; + +#endif diff --git a/RedisStudio/RedisConfigUI.cpp b/RedisStudio/RedisConfigUI.cpp index 3829f4f..1679a8e 100644 --- a/RedisStudio/RedisConfigUI.cpp +++ b/RedisStudio/RedisConfigUI.cpp @@ -1,183 +1,183 @@ -#include "stdafx.h" -#include "RedisConfigUI.h" -#include "Redis/RedisClient.h" -#include "Base/CharacterSet.h" - -DUI_BEGIN_MESSAGE_MAP(RedisConfigUI, CNotifyPump) -DUI_ON_MSGTYPE(DUI_MSGTYPE_CLICK,OnClick) -DUI_ON_MSGTYPE(DUI_MSGTYPE_SELECTCHANGED,OnSelectChanged) -DUI_ON_MSGTYPE(DUI_MSGTYPE_ITEMCLICK,OnItemClick) -DUI_ON_MSGTYPE(DUI_MSGTYPE_ITEMACTIVATE,OnItemActive) -DUI_END_MESSAGE_MAP() - -RedisConfigUI::RedisConfigUI(const CDuiString& strXML, CPaintManagerUI* pm ):AbstraceUI(pm) -{ - CDialogBuilder builder; - // 봫m_PaintManagerȻXMLʹĬϹϢ - CControlUI* pContainer = builder.Create(strXML.GetData(), NULL, NULL, GetPaintMgr(), NULL); - if( pContainer ) { - this->Add(pContainer); - } - else { - this->RemoveAll(); - return; - } -} - -RedisConfigUI::~RedisConfigUI(void) -{ -} - -void RedisConfigUI::Initialize() -{ -} - -DuiLib::CDuiString RedisConfigUI::GetVirtualwndName() -{ - return _T("RedisConfig"); -} - -void RedisConfigUI::RefreshWnd() -{ - if (GetConfig()) - { - DoFillData(); - } -} - -int RedisConfigUI::GetIndex() -{ - return 3; -} - -void RedisConfigUI::OnClick(TNotifyUI& msg) -{ - if (msg.pSender->GetName() == _T("btn_config_submit")) - { - DoApplyData(); - } - else if (msg.pSender->GetName() == _T("btn_config_sync")) - { - RedisClient::GetInstance().ReWriteConfig(); - } -} - -void RedisConfigUI::OnSelectChanged( TNotifyUI &msg ) -{ - -} - -void RedisConfigUI::OnItemClick( TNotifyUI &msg ) -{ - -} - -void RedisConfigUI::OnItemActive( TNotifyUI &msg ) -{ - -} - -bool RedisConfigUI::GetConfig() -{ - if (!RedisClient::GetInstance().GetConfig(m_dicConfig)) return false; - return true; -} - -bool RedisConfigUI::SetConfig(const RedisClient::TDicConfig& config) -{ - return RedisClient::GetInstance().SetConfig(config); -} - -void RedisConfigUI::DoFillData() -{ - CEditUI exampleEditUI; - CComboUI exampleComboUI; - - RedisClient::TDicConfig::const_iterator it = m_dicConfig.begin(); - RedisClient::TDicConfig::const_iterator itend = m_dicConfig.end(); - - for ( ; it!=itend; ++it) - { - CDuiString name = _T("redisconfig_"); - CDuiString key = Base::CharacterSet::ANSIToUnicode(it->first).c_str(); - CDuiString val = Base::CharacterSet::ANSIToUnicode(it->second).c_str(); - name.Append(key); - CControlUI* pCtl = GetPaintMgr()->FindControl(name); - - /// xmlδø - if (pCtl == NULL) continue; - - if (pCtl->GetClass() == exampleEditUI.GetClass()) - { - CEditUI* pEdit = static_cast (pCtl); - pEdit->SetText(val); - } - else if (pCtl->GetClass() == exampleComboUI.GetClass()) - { - CComboUI* pCombo = static_cast (pCtl); - int idx = 0; - if (val == _T("yes")) idx = 0; - else if (val == _T("no")) idx = 1; - else if (it->first == "loglevel") - { - string loglevel = it->second; - if (loglevel == "debug") idx = 0; - else if (loglevel == "verbose") idx = 1; - else if (loglevel == "notice") idx = 2; - else if (loglevel == "warning") idx = 3; - } - pCombo->SetInternVisible(true); - pCombo->SelectItem(idx); - pCombo->SetFocus(); - } - } -} - -void RedisConfigUI::DoApplyData() -{ - CEditUI exampleEditUI; - CComboUI exampleComboUI; - - RedisClient::TDicConfig::const_iterator it = m_dicConfig.begin(); - RedisClient::TDicConfig::const_iterator itend = m_dicConfig.end(); - RedisClient::TDicConfig config; - for ( ; it!=itend; ++it) - { - CDuiString name = _T("redisconfig_"); - CDuiString key = Base::CharacterSet::ANSIToUnicode(it->first).c_str(); - name.Append(key); - CControlUI* pCtl = GetPaintMgr()->FindControl(name); - if (pCtl == NULL) continue; - string val ; - if (pCtl->GetClass() == exampleEditUI.GetClass()) - { - CEditUI* pEdit = static_cast (pCtl); - val = Base::CharacterSet::UnicodeToANSI(pEdit->GetText().GetData()); - } - else if (pCtl->GetClass() == exampleComboUI.GetClass()) - { - CComboUI* pCombo = static_cast (pCtl); - int idx = pCombo->GetCurSel(); - if (it->first == "loglevel") - { - if (idx == 0) val = "debug"; - else if (idx == 1) val = "verbose"; - else if (idx == 2) val = "notice"; - else if (idx == 3) val = "warning"; - } - else - { - if (idx == 0) val = "yes"; - else if (idx == 1) val = "no"; - } - } - if (val != it->second) - { - config.insert(std::make_pair(it->first, val)); - } - } - if (SetConfig(config) && GetConfig()) - { - DoFillData(); - } -} +#include "stdafx.h" +#include "RedisConfigUI.h" +#include "Redis/RedisClient.h" +#include "Base/CharacterSet.h" + +DUI_BEGIN_MESSAGE_MAP(RedisConfigUI, CNotifyPump) +DUI_ON_MSGTYPE(DUI_MSGTYPE_CLICK,OnClick) +DUI_ON_MSGTYPE(DUI_MSGTYPE_SELECTCHANGED,OnSelectChanged) +DUI_ON_MSGTYPE(DUI_MSGTYPE_ITEMCLICK,OnItemClick) +DUI_ON_MSGTYPE(DUI_MSGTYPE_ITEMACTIVATE,OnItemActive) +DUI_END_MESSAGE_MAP() + +RedisConfigUI::RedisConfigUI(const CDuiString& strXML, CPaintManagerUI* pm ):AbstraceUI(pm) +{ + CDialogBuilder builder; + // 这里必须传入m_PaintManager,不然子XML不能使用默认滚动条等信息。 + CControlUI* pContainer = builder.Create(strXML.GetData(), NULL, NULL, GetPaintMgr(), NULL); + if( pContainer ) { + this->Add(pContainer); + } + else { + this->RemoveAll(); + return; + } +} + +RedisConfigUI::~RedisConfigUI(void) +{ +} + +void RedisConfigUI::Initialize() +{ +} + +DuiLib::CDuiString RedisConfigUI::GetVirtualwndName() +{ + return _T("RedisConfig"); +} + +void RedisConfigUI::RefreshWnd() +{ + if (GetConfig()) + { + DoFillData(); + } +} + +int RedisConfigUI::GetIndex() +{ + return 3; +} + +void RedisConfigUI::OnClick(TNotifyUI& msg) +{ + if (msg.pSender->GetName() == _T("btn_config_submit")) + { + DoApplyData(); + } + else if (msg.pSender->GetName() == _T("btn_config_sync")) + { + RedisClient::GetInstance().ReWriteConfig(); + } +} + +void RedisConfigUI::OnSelectChanged( TNotifyUI &msg ) +{ + +} + +void RedisConfigUI::OnItemClick( TNotifyUI &msg ) +{ + +} + +void RedisConfigUI::OnItemActive( TNotifyUI &msg ) +{ + +} + +bool RedisConfigUI::GetConfig() +{ + if (!RedisClient::GetInstance().GetConfig(m_dicConfig)) return false; + return true; +} + +bool RedisConfigUI::SetConfig(const RedisClient::TDicConfig& config) +{ + return RedisClient::GetInstance().SetConfig(config); +} + +void RedisConfigUI::DoFillData() +{ + CEditUI exampleEditUI; + CComboUI exampleComboUI; + + RedisClient::TDicConfig::const_iterator it = m_dicConfig.begin(); + RedisClient::TDicConfig::const_iterator itend = m_dicConfig.end(); + + for ( ; it!=itend; ++it) + { + CDuiString name = _T("redisconfig_"); + CDuiString key = Base::CharacterSet::ANSIToUnicode(it->first).c_str(); + CDuiString val = Base::CharacterSet::ANSIToUnicode(it->second).c_str(); + name.Append(key); + CControlUI* pCtl = GetPaintMgr()->FindControl(name); + + /// xml中未配置该项 + if (pCtl == NULL) continue; + + if (pCtl->GetClass() == exampleEditUI.GetClass()) + { + CEditUI* pEdit = static_cast (pCtl); + pEdit->SetText(val); + } + else if (pCtl->GetClass() == exampleComboUI.GetClass()) + { + CComboUI* pCombo = static_cast (pCtl); + int idx = 0; + if (val == _T("yes")) idx = 0; + else if (val == _T("no")) idx = 1; + else if (it->first == "loglevel") + { + string loglevel = it->second; + if (loglevel == "debug") idx = 0; + else if (loglevel == "verbose") idx = 1; + else if (loglevel == "notice") idx = 2; + else if (loglevel == "warning") idx = 3; + } + pCombo->SetInternVisible(true); + pCombo->SelectItem(idx); + pCombo->SetFocus(); + } + } +} + +void RedisConfigUI::DoApplyData() +{ + CEditUI exampleEditUI; + CComboUI exampleComboUI; + + RedisClient::TDicConfig::const_iterator it = m_dicConfig.begin(); + RedisClient::TDicConfig::const_iterator itend = m_dicConfig.end(); + RedisClient::TDicConfig config; + for ( ; it!=itend; ++it) + { + CDuiString name = _T("redisconfig_"); + CDuiString key = Base::CharacterSet::ANSIToUnicode(it->first).c_str(); + name.Append(key); + CControlUI* pCtl = GetPaintMgr()->FindControl(name); + if (pCtl == NULL) continue; + string val ; + if (pCtl->GetClass() == exampleEditUI.GetClass()) + { + CEditUI* pEdit = static_cast (pCtl); + val = Base::CharacterSet::UnicodeToANSI(pEdit->GetText().GetData()); + } + else if (pCtl->GetClass() == exampleComboUI.GetClass()) + { + CComboUI* pCombo = static_cast (pCtl); + int idx = pCombo->GetCurSel(); + if (it->first == "loglevel") + { + if (idx == 0) val = "debug"; + else if (idx == 1) val = "verbose"; + else if (idx == 2) val = "notice"; + else if (idx == 3) val = "warning"; + } + else + { + if (idx == 0) val = "yes"; + else if (idx == 1) val = "no"; + } + } + if (val != it->second) + { + config.insert(std::make_pair(it->first, val)); + } + } + if (SetConfig(config) && GetConfig()) + { + DoFillData(); + } +} diff --git a/RedisStudio/RedisConfigUI.h b/RedisStudio/RedisConfigUI.h index a00ca57..679eab6 100644 --- a/RedisStudio/RedisConfigUI.h +++ b/RedisStudio/RedisConfigUI.h @@ -1,44 +1,44 @@ -#pragma once - -#include "AbstractUI.h" - -#include "Redis/RedisClient.h" - -class RedisConfigUI : public AbstraceUI -{ -public: - RedisConfigUI(const CDuiString& strXML, CPaintManagerUI* pm ); - - ~RedisConfigUI(void); - - void Initialize(); - - virtual CDuiString GetVirtualwndName(); - - virtual void RefreshWnd(); - - virtual int GetIndex(); - - DUI_DECLARE_MESSAGE_MAP() - -public: - virtual void OnClick(TNotifyUI& msg); - - virtual void OnSelectChanged( TNotifyUI &msg ); - - virtual void OnItemClick( TNotifyUI &msg ); - - virtual void OnItemActive( TNotifyUI &msg ); - -private: - bool GetConfig(); - - bool SetConfig(const RedisClient::TDicConfig& config); - - void DoFillData(); - - void DoApplyData(); - -private: - RedisClient::TDicConfig m_dicConfig; -}; +#pragma once + +#include "AbstractUI.h" + +#include "Redis/RedisClient.h" + +class RedisConfigUI : public AbstraceUI +{ +public: + RedisConfigUI(const CDuiString& strXML, CPaintManagerUI* pm ); + + ~RedisConfigUI(void); + + void Initialize(); + + virtual CDuiString GetVirtualwndName(); + + virtual void RefreshWnd(); + + virtual int GetIndex(); + + DUI_DECLARE_MESSAGE_MAP() + +public: + virtual void OnClick(TNotifyUI& msg); + + virtual void OnSelectChanged( TNotifyUI &msg ); + + virtual void OnItemClick( TNotifyUI &msg ); + + virtual void OnItemActive( TNotifyUI &msg ); + +private: + bool GetConfig(); + + bool SetConfig(const RedisClient::TDicConfig& config); + + void DoFillData(); + + void DoApplyData(); + +private: + RedisClient::TDicConfig m_dicConfig; +}; diff --git a/RedisStudio/RedisDataUI.cpp b/RedisStudio/RedisDataUI.cpp index 7af23d1..f1621f1 100644 --- a/RedisStudio/RedisDataUI.cpp +++ b/RedisStudio/RedisDataUI.cpp @@ -1,783 +1,965 @@ -#include "stdafx.h" -#include "RedisDataUI.h" -#include "Base/String.h" -#include "UserMessage.h" -#include "Base/CharacterSet.h" -#include "Redis/RedisResult.h" -#include "Redis/RedisClient.h" -#include "rapidjson/reader.h" -#include "rapidjson/reader.h" -#include "rapidjson/prettywriter.h" // for stringify JSON -#include "rapidjson/stringbuffer.h" - -#include "DuiEx/UIMenu.h" - -using namespace rapidjson; - -static const TCHAR* kDefaultText = _T(""); -static const TCHAR* kKeyEditName = _T("redisdata_key"); -static const TCHAR* kDataTypeName = _T("redisdata_type"); -static const TCHAR* kDataSizeName = _T("redisdata_size"); -static const TCHAR* kRichEditName = _T("redisdata_value_rich"); -static const TCHAR* kDataListName = _T("redisdata_value"); -static const TCHAR* kKeysTreeName = _T("redisdata_treenode"); -static const TCHAR* kPageName = _T("redisdata_page"); -static const TCHAR* kPageFristName= _T("redisdata_pagefrist"); -static const TCHAR* kPageNextName = _T("redisdata_pagenext"); -static const TCHAR* kPageCurName = _T("redisdata_curpage"); -static const TCHAR* kPageTotalName= _T("redisdata_totalpage"); -static const TCHAR* kPageLastName = _T("redisdata_pagelast"); -static const TCHAR* kPageFinalName= _T("redisdata_pagefinal"); -static const TCHAR* kCommitBtnName= _T("redisdata_commit"); -static const TCHAR* kDataFomatName= _T("redisdata_format_combo"); - -static const TCHAR* kDBOperatorReloadMenuName = _T("menu_keys_reload"); -static const TCHAR* kKeyOperatorDelMenuName = _T("menu_key_del"); - - - -DUI_BEGIN_MESSAGE_MAP(RedisDataUI, CNotifyPump) -DUI_ON_MSGTYPE(DUI_MSGTYPE_CLICK,OnClick) -DUI_ON_MSGTYPE(DUI_MSGTYPE_ITEMCLICK,OnItemClick) -DUI_ON_MSGTYPE(DUI_MSGTYPE_ITEMRCLICK, OnMenuWakeup) -DUI_ON_MSGTYPE(DUI_MSGTYPE_ITEMACTIVATE,OnItemActive) -DUI_END_MESSAGE_MAP() - - -RedisDataUI::RedisDataUI( const CDuiString& strXML, CPaintManagerUI* pm ):AbstraceUI(pm),m_oEventListHeader(true),m_oEventKey(true) -{ - CDialogBuilder builder; - CControlUI* pContainer = builder.Create(strXML.GetData(), NULL, NULL, GetPaintMgr(), NULL); - if( pContainer ) { - this->Add(pContainer); - } - else - { - this->RemoveAll(); - return; - } -} - -void RedisDataUI::Initialize() -{ - m_pList = dynamic_cast(GetPaintMgr()->FindControl(kDataListName)); - m_pRichEdit = dynamic_cast(GetPaintMgr()->FindControl(kRichEditName)); - m_pKeyEdit = dynamic_cast(GetPaintMgr()->FindControl(kKeyEditName)); - m_PTypeEdit = dynamic_cast(GetPaintMgr()->FindControl(kDataTypeName)); - m_pDataSizeEdit = dynamic_cast(GetPaintMgr()->FindControl(kDataSizeName)); - m_pHorizontalLayout = dynamic_cast(GetPaintMgr()->FindControl(kPageName)); - - m_pPageCur = dynamic_cast(GetPaintMgr()->FindControl(kPageCurName)); - m_pPageTotal = dynamic_cast(GetPaintMgr()->FindControl(kPageTotalName)); - m_pPageFrist = dynamic_cast(GetPaintMgr()->FindControl(kPageFristName)); - m_pPageLast = dynamic_cast(GetPaintMgr()->FindControl(kPageLastName)); - m_pPageNext = dynamic_cast(GetPaintMgr()->FindControl(kPageNextName)); - m_pPageFinal = dynamic_cast(GetPaintMgr()->FindControl(kPageFinalName)); - m_pCommit = dynamic_cast(GetPaintMgr()->FindControl(kCommitBtnName)); - m_pComboFormat = dynamic_cast(GetPaintMgr()->FindControl(kDataFomatName)); -} - -int RedisDataUI::GetIndex() -{ - return 2; -} - -CDuiString RedisDataUI::GetVirtualwndName() -{ - return _T("RedisData"); -} - -void RedisDataUI::RefreshWnd() -{ - CTreeNodeUI* pKeyNode = dynamic_cast(GetPaintMgr()->FindControl(kKeysTreeName)); - static CDuiString oldTitle = pKeyNode->GetItemText(); - DelChildNode(pKeyNode); - int databases = RedisClient::GetInstance().DatabasesNum(); - m_UpdateDbs.clear(); - for (int i=0; iSetItemText(newTitle); - //pNode->SetBkImage(pNodelist->GetBkImage()); - pNode->SetFixedHeight(20); - pNode->SetContextMenuUsed(true); - - //pNode->SetIndex(myIdx--); - /// ˴tagȴtreelevel(δʵ) - - pNode->SetTag(i+1); - pNode->SetAttribute(_T("itemattr"), _T("valign=\"vcenter\" font=\"5\" textpadding=\"5,3,0,0\"")); - pNode->SetAttribute(_T("folderattr"), _T("padding=\"0,3,0,0\" width=\"16\" height=\"16\" selectedimage=\"file='1_close.png' source='0,0,0,0'\" normalimage=\"file='1_open.png' source='0,0,0,0'\"")); - - pKeyNode->AddChildNode(pNode); - } - - DoRefreshKeysWork(); -} - -bool RedisDataUI::CanChange() -{ - if (m_Thread.isRunning()) { - return false; - } - return true; -} - -LRESULT RedisDataUI::HandleCustomMessage( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled ) -{ - bHandled = TRUE; - LRESULT lRes = TRUE; - switch (uMsg) - { - case WM_USER_DATAADD: - lRes = OnDataAdd(GetHWND(), wParam, lParam); - break; - case WM_USER_TREEADD: - lRes = OnKeyAdd(GetHWND(), wParam, lParam); - break; - case WM_USER_DATAVERBOSE: - lRes = OnDataVerbose(GetHWND(), wParam, lParam); - break; - case WM_USER_MENU_KEYDEL: - lRes = OnKeyDel(GetHWND(), wParam, lParam); - break; - default: - bHandled = FALSE; - lRes = FALSE; - break; - } - return lRes; -} - -void RedisDataUI::OnClick( TNotifyUI& msg ) -{ - if (m_Thread.isRunning()) return; - - if (msg.pSender == m_pPageFinal || - msg.pSender == m_pPageLast || - msg.pSender == m_pPageNext || - msg.pSender == m_pPageFrist) - { - OnPaginate(msg); - } - else if (msg.pSender == m_pCommit) - { - OnCommit(msg); - } - -} - -void RedisDataUI::OnItemClick( TNotifyUI &msg ) -{ - CDuiString name = msg.pSender->GetClass(); - CListTextElementUI listTextElementUI ; - CTreeNodeUI treeNodeUI; - - if (name == listTextElementUI.GetClass()) - { - OnItemActiveForList(msg); - } - else if (name == treeNodeUI.GetClass()) - { - OnItemActiveForTree(msg); - } -} - -void RedisDataUI::OnItemActive( TNotifyUI &msg ) -{ - -} - -void RedisDataUI::OnMenuWakeup( TNotifyUI &msg ) -{ - CTreeNodeUI* pTreeNodeUI = dynamic_cast (msg.pSender); - if (!pTreeNodeUI) return; - - bool needMenu = false; - STRINGorID res(_T("")); - /// ڵ - if (pTreeNodeUI->GetTag() > 0) - { - STRINGorID xml(_T("DBOperatorMenu.xml")); - res = xml; - } - else if (!pTreeNodeUI->IsHasChild()) - { - STRINGorID xml(_T("KeyOperatorMenu.xml")); - res = xml; - } - CDuiString resStr = res.m_lpstr; - m_pAssistNode = pTreeNodeUI; - if (resStr.GetLength()) - { - CMenuWnd* pMenu = new CMenuWnd(GetHWND()); - pMenu->OnClick += MakeDelegate(this, &RedisDataUI::OnMenuClick); - CPoint point = msg.ptMouse; - ClientToScreen(GetHWND(), &point); - pMenu->Init(NULL, res, _T("xml"), point); - } -} - -void RedisDataUI::OnItemActiveForTree( TNotifyUI &msg ) -{ - CTreeNodeUI* pActiveNode = dynamic_cast(msg.pSender); - if (!pActiveNode) return; - /// Ҷӽڵ㲻 - if (pActiveNode->IsHasChild()) return ; - /// ײdbڵ - if (pActiveNode->GetTag() > 0) return; - if (m_Thread.isRunning()) - { - UserMessageBox(GetHWND(), 10012, NULL, MB_ICONINFORMATION); - return ; - } - - int dbNum = -1; - CTreeNodeUI* pDBNode = pActiveNode->GetParentNode(); - while (pDBNode) - { - if (pDBNode->GetTag()>0) - { - dbNum = pDBNode->GetTag()-1; - break; - } - pDBNode = pDBNode->GetParentNode(); - } - if (dbNum < 0) return ; - m_RedisData.db = dbNum; - GetResult().Clear(); - std::string key = Base::CharacterSet::UnicodeToANSI(pActiveNode->GetItemText().GetData()); - m_pKeyEdit->SetText(Base::CharacterSet::ANSIToUnicode(key).c_str()); - m_PTypeEdit->SetText(kDefaultText); - m_pRichEdit->SetText(kDefaultText); - m_pDataSizeEdit->SetText(kDefaultText); - m_pPageCur->SetText(_T("1")); - m_pPageTotal->SetText(_T("1")); - m_pList->RemoveAll(); - m_pList->GetHeader()->RemoveAll(); - m_pHorizontalLayout->SetVisible(false); - DoRefreshValuesWork(); -} - -void RedisDataUI::OnItemActiveForList( TNotifyUI &msg ) -{ - CListTextElementUI* pListElement = dynamic_cast(msg.pSender); - ///LPCTSTR pstr; - ///if ((pstr = pListElement->GetText(1)) == NULL) - ///{ - /// pstr = pListElement->GetText(0); - ///} - ///std::string text = Base::CharacterSet::UnicodeToANSI(pstr); - - std::size_t curPage = atoi(Base::CharacterSet::UnicodeToANSI(m_pPageCur->GetText().GetData()).c_str()); - - int curCel = m_pList->GetItemIndex(pListElement); - /// why ? - ///std::size_t curIndex = m_pList->GetCurSel(); - int realIndex = (curPage-1)*m_PageSize + curCel; - int colIdx = m_pList->GetHeader()->GetCount() > 1 ? 1 : 0 ; - string myValue = GetResult().Value(realIndex, colIdx); - CDuiString myDuiStr = Base::CharacterSet::UTF8ToUnicode(myValue).c_str(); - /// - if (myValue.size() !=0 && myDuiStr.GetLength()==0) - { - TryHexFormat(myValue); - myDuiStr = Base::CharacterSet::UTF8ToUnicode(myValue).c_str(); - } - std::string text = Base::CharacterSet::UnicodeToANSI(myDuiStr.GetData()); - SetRichEditText(text); -} - -void RedisDataUI::OnPaginate(TNotifyUI& msg) -{ - std::size_t curPage = atoi(Base::CharacterSet::UnicodeToANSI(m_pPageCur->GetText().GetData()).c_str()); - - if (msg.pSender == m_pPageNext) - { - curPage += 1; - } - else if (msg.pSender == m_pPageLast) - { - curPage -= 1; - } - else if (msg.pSender == m_pPageFrist) - { - curPage = 1; - } - else if (msg.pSender == m_pPageFinal) - { - curPage = GetMaxPage(); - } - else - { - return; - } - - if (curPage==0 || curPage>GetMaxPage()) - { - return; - } - m_pList->RemoveAll(); - CDuiString pageStr, totalpageStr ; - pageStr.Format(_T("%u"), curPage); - totalpageStr.Format(_T("%u"), GetMaxPage()); - m_pPageCur->SetText(pageStr.GetData()); - m_pPageTotal->SetText(totalpageStr.GetData()); - DoPaginateWork(); -} - -void RedisDataUI::OnCommit(TNotifyUI& msg) -{ - if (m_pList->GetCurSel() < 0) - { - UserMessageBox(GetHWND(), 20002, NULL, MB_ICONINFORMATION); - return; - } - CListTextElementUI* textElement = dynamic_cast(m_pList->GetItemAt(m_pList->GetCurSel())); - std::string curPageStr = Base::CharacterSet::UnicodeToANSI(m_pPageCur->GetText().GetData()); - int curPage = atoi(curPageStr.c_str()); - int idx = (curPage-1)*m_PageSize + m_pList->GetCurSel(); - std::string key = Base::CharacterSet::UnicodeToANSI(m_pKeyEdit->GetText().GetData()); - std::string oldValue = Base::CharacterSet::UnicodeToANSI(textElement->GetText(0)); - std::string field; - if (m_pList->GetHeader()->GetCount() > 1) - { - field = Base::CharacterSet::UnicodeToANSI(textElement->GetText(0)); - oldValue = Base::CharacterSet::UnicodeToANSI(textElement->GetText(1)); - } - std::string newValue = Base::CharacterSet::UnicodeToANSI(m_pRichEdit->GetText().GetData()); - if (!RedisClient::GetInstance().UpdateData(key, oldValue, newValue, idx, field)) - { - /// todo ˴Ӧʾ - UserMessageBox(GetHWND(), 10031, RedisClient::GetInstance().GetLastError().GetData() , MB_ICONERROR); - return; - } - - int valueIdx = m_pList->GetHeader()->GetCount() > 1 ? 1 : 0 ; - textElement->SetText(valueIdx, m_pRichEdit->GetText().GetData()); -} - -void RedisDataUI::DoPaginateWork() -{ - m_pWork.reset(new Base::RunnableAdapter(*this, &RedisDataUI::SetPageValues)); - try - { - m_Thread.start(*m_pWork); - } - catch (std::exception& ex) - { - /// who care ? - (void)(ex); - } -} - -void RedisDataUI::DoRefreshKeysWork() -{ - m_pWork.reset(new Base::RunnableAdapter(*this, &RedisDataUI::BackgroundWorkForRefreshKeys)); - try - { - m_Thread.start(*m_pWork); - } - catch (std::exception& ex) - { - /// who care ? - (void)(ex); - } -} - -void RedisDataUI::DoRefreshValuesWork() -{ - m_pWork.reset(new Base::RunnableAdapter(*this, &RedisDataUI::BackgroundWorkForRefreshValues)); - try - { - m_Thread.start(*m_pWork); - } - catch (std::exception& ex) - { - /// who care ? - (void)(ex); - } -} - -std::size_t RedisDataUI::GetMaxPage() -{ - std::size_t maxPage = GetResult().RowSize()%m_PageSize ? (GetResult().RowSize()/m_PageSize)+1 : GetResult().RowSize()/m_PageSize; - return maxPage; -} - -RedisResult& RedisDataUI::GetResult() -{ - return m_RedisData.result; -} - -void RedisDataUI::BackgroundWorkForRefreshKeys(void) -{ - if (!RedisClient::GetInstance().IsConnected()) return; - - CTreeNodeUI* pParentNode = static_cast(GetPaintMgr()->FindControl(kKeysTreeName)); - for (int nodeIdx=0; nodeIdxGetCountChild(); ++nodeIdx) - { - CTreeNodeUI *pKeyNode = (CTreeNodeUI*) pParentNode->GetChildNode(nodeIdx); - - if (m_UpdateDbs.find(nodeIdx) == m_UpdateDbs.end()) continue; - DelChildNode(pKeyNode); - if (!RedisClient::GetInstance().SelectDB(nodeIdx)) continue; - - RedisClient::TSeqArrayResults results; - //results.sort(); - if (!RedisClient::GetInstance().keys(results)) return; - RedisClient::TSeqArrayResults::const_iterator it = results.begin(); - RedisClient::TSeqArrayResults::const_iterator itend = results.end(); - - for (; it!=itend; ++it) - { - std::string theValue = *it; - CTreeNodeUI* pPNode = pKeyNode; - /* - if (results.size() > 10000) { - TreeKeyContactData* pData = new TreeKeyContactData; - pData->pPNode = pPNode; - pData->pNode = NewNode(theValue, true); - ::PostMessage(GetHWND(), WM_USER_TREEADD, (WPARAM)pData, NULL); - m_oEventKey.wait(); - continue; - } - */ - Base::String::TSeqStr seq; - Base::String::Split(theValue, ":", seq); - seq[seq.size()-1] = theValue; - - for (std::size_t idx=0; idxGetCountChild(); ++j) - { - CTreeNodeUI* pTempNode = pPNode->GetChildNode(j); - if (pTempNode->GetItemText() == duiStr && pTempNode->IsHasChild()) - { - pPNode = pTempNode; - hasFind = true; - break; - } - } - if (hasFind) - { - continue; - } - else - { - CTreeNodeUI* pnode = NewNode(seq[idx]); - TreeKeyContactData* pData = new TreeKeyContactData; - pData->pPNode = pPNode; - pData->pNode = pnode; - ::PostMessage(GetHWND(), WM_USER_TREEADD, (WPARAM)pData, NULL); - m_oEventKey.wait(); - pPNode = pnode; - } - } - TreeKeyContactData* pData = new TreeKeyContactData; - pData->pPNode = pPNode; - pData->pNode = NewNode(theValue, true); - ::PostMessage(GetHWND(), WM_USER_TREEADD, (WPARAM)pData, NULL); - m_oEventKey.wait(); - } - } -} - -void RedisDataUI::BackgroundWorkForRefreshValues(void) -{ - RedisClient::GetInstance().SelectDB(m_RedisData.db); - std::string key, type; - CEditUI* pKeyEdit = static_cast(GetPaintMgr()->FindControl(kKeyEditName)); - key = Base::CharacterSet::UnicodeToANSI(pKeyEdit->GetText().GetData()); - if (!RedisClient::GetInstance().Exists(key)) - { - /// üѾڣʾû¼ - ::PostMessage(GetHWND(), WM_USER_DATAVERBOSE, 10030, NULL); - return; - } - m_RedisData.key = Base::CharacterSet::ANSIToUnicode(key).c_str(); - - if (!RedisClient::GetInstance().GetData(key, type, GetResult())) return; - m_RedisData.type = Base::CharacterSet::ANSIToUnicode(type).c_str(); - m_RedisData.size.Format(_T("%u"),GetResult().RowSize() ); - /// Ԥʾ͵Ϣ - ::PostMessage(GetHWND(), WM_USER_DATAVERBOSE, NULL, NULL); - - for (std::size_t idx=0; idxSetText(Base::CharacterSet::ANSIToUnicode(GetResult().ColumnName(idx)).c_str()); - pHeaderItem->SetHotImage(_T("file='list_header_hot.png'")); - pHeaderItem->SetPushedImage(_T("file='list_header_pushed.png'")); - pHeaderItem->SetSepImage(_T("file='list_header_sep.png'")); - pHeaderItem->SetSepWidth(1); - - /// listڲֵʱlistheadӦжϣҪheadȫupdateٲֵ - LPARAM lparam = 0; - if (idx+1 == GetResult().ColumnSize()) lparam = 1; - ::PostMessage(GetHWND(), WM_USER_DATAADD, (WPARAM)pHeaderItem, lparam); - } - m_oEventListHeader.wait(); - SetPageValues(); -} - -void RedisDataUI::SetPageValues( ) -{ - const std::size_t pagesize = m_PageSize; - std::string pageStr = Base::CharacterSet::UnicodeToANSI(m_pPageCur->GetText().GetData()); - const std::size_t cur = atoi(pageStr.c_str()); - if (cur<=0 || cur>GetMaxPage()) - { - return ; - } - - std::size_t maxIndex = cur*pagesize>GetResult().RowSize() ? GetResult().RowSize(): cur*pagesize; - int ipos = 0; - for (std::size_t idx= (cur-1)*pagesize; idxSetOwner(m_pList); - pListTextElement->SetTag(idx); - for (std::size_t colidx=0; colidx 50) - { - myDuiStr = myDuiStr.Left(50); - myDuiStr.Append(_T("...")); - } - pListTextElement->SetText(colidx, myDuiStr.GetData()); - } - ::PostMessage(GetHWND(), WM_USER_DATAADD, (WPARAM)pListTextElement, NULL); - } -} - -LRESULT RedisDataUI::OnDataAdd( HWND hwnd, WPARAM wParam, LPARAM lParam ) -{ - CControlUI* pListElement = reinterpret_cast (wParam); - pListElement->NeedUpdate(); - m_pList->Add(pListElement); - m_pList->NeedUpdate(); - if (lParam != NULL) m_oEventListHeader.set(); - return TRUE; -} - -LRESULT RedisDataUI::OnKeyAdd( HWND hwnd, WPARAM wParam, LPARAM lParam ) -{ - std::auto_ptr pData(reinterpret_cast(wParam)); - CTreeNodeUI* pPNode = pData->pPNode; - CTreeNodeUI* pNode = pData->pNode; - pPNode->AddChildNode(pNode); - /// ߾ȹTreeViewĬϲչڵ - pPNode->GetFolderButton()->Selected(true); - pPNode->GetTreeView()->SetItemExpand(false, pPNode); - pPNode->NeedUpdate(); - m_oEventKey.set(); - return TRUE; -} - -LRESULT RedisDataUI::OnKeyDel( HWND hwnd, WPARAM wParam, LPARAM lParam ) -{ - CTreeNodeUI* pNode = reinterpret_cast(wParam); - CTreeNodeUI* pPNode; - CDuiString a = pNode->GetItemText(); - std::string key = Base::CharacterSet::UnicodeToANSI(pNode->GetItemText().GetData()); - /// ʱͬɾʱп - if (!RedisClient::GetInstance().DelKey(key)) return FALSE; - while (pNode) - { - if (pNode->IsHasChild() || pNode->GetTag()>0) break; - pPNode = pNode->GetParentNode(); - pPNode->Remove(pNode); - pNode = pPNode; - } - return TRUE; -} - -LRESULT RedisDataUI::OnDataVerbose( HWND hwnd, WPARAM wParam, LPARAM lParam ) -{ - if (wParam != 0) - { - UserMessageBox(GetHWND(), 10030, NULL, MB_ICONERROR); - return FALSE; - } - m_pKeyEdit->SetText(m_RedisData.key.GetData()); - m_PTypeEdit->SetText(m_RedisData.type.GetData()); - m_pDataSizeEdit->SetText(m_RedisData.size.GetData()); - m_pRichEdit->SetText(kDefaultText); - /// ǵԪ(string)һֱӸµı - if (GetResult().RowSize() == 1 && GetResult().ColumnSize()==1) - { - string myValue = GetResult().Value(0, 0); - CDuiString myDuiStr = Base::CharacterSet::UTF8ToUnicode(myValue).c_str(); - /// - if (myValue.size() !=0 && myDuiStr.GetLength()==0) - { - TryHexFormat(myValue); - myDuiStr = Base::CharacterSet::UTF8ToUnicode(myValue).c_str(); - } - std::string text = Base::CharacterSet::UnicodeToANSI(myDuiStr.GetData()); - SetRichEditText(text); - } - - if (GetResult().RowSize() > m_PageSize) - { - /// ҳ - CDuiString totalpageStr; - totalpageStr.Format(_T("%u"), GetMaxPage()); - m_pPageTotal->SetText(totalpageStr.GetData()); - m_pHorizontalLayout->SetVisible(true); - } - return TRUE; -} - -bool RedisDataUI::OnMenuClick( void* param ) -{ - if (m_Thread.isRunning()) - { - UserMessageBox(GetHWND(), 10012, NULL, MB_ICONINFORMATION); - return false; - } - TEventUI* pTEventUI = static_cast (param); - CDuiString name = pTEventUI->pSender->GetName(); - if (name == kDBOperatorReloadMenuName) - { - m_UpdateDbs.clear(); - m_UpdateDbs.insert(m_pAssistNode->GetTag() - 1); - DoRefreshKeysWork(); - } - else if (name == kKeyOperatorDelMenuName) - { - ::PostMessage(GetHWND(), WM_USER_MENU_KEYDEL, (WPARAM)(m_pAssistNode), NULL); - } - return true; -} - -void RedisDataUI::SetRichEditText(const std::string& text) -{ - enum DataFomat - { - kAutoFomat = 0, - kNormalFormat = 1, - kJsonFormat = 2, - kXMLFormat = 3, - kHexFormat = 4 - }; - std::string styleText = text; - int curSel = m_pComboFormat->GetCurSel(); - - /// ûҪģʽֱif else㶨ֱ - if ( curSel == kAutoFomat ) - { - if (TryJsonFomat(styleText) || TryXMLFormat(styleText)) {} - } - else if (curSel == kJsonFormat) - { - TryJsonFomat(styleText); - } - else if (curSel == kXMLFormat) - { - TryXMLFormat(styleText); - } - else if (curSel == kHexFormat) - { - TryHexFormat(styleText); - } - m_pRichEdit->SetText(Base::CharacterSet::ANSIToUnicode(styleText).c_str()); -} - -bool RedisDataUI::TryJsonFomat( std::string& text ) -{ - std::string& styleText = text; - - StringStream s(styleText.c_str()); - StringBuffer buffer; - PrettyWriter writer(buffer); - Reader reader; - if (reader.Parse<0>(s, writer)) - { - styleText = buffer.GetString(); - return true; - } - return false; -} - -bool RedisDataUI::TryXMLFormat( std::string& text ) -{ - return true; -} - -bool RedisDataUI::TryHexFormat( std::string& text ) -{ - std::string styleText; - std::string::const_iterator it = text.begin(); - std::string::const_iterator itend = text.end(); - for ( ;it!=itend; ++it) - { - styleText+=Base::String::Chrtos(*it); - } - text = styleText; - return true; -} - -CTreeNodeUI* RedisDataUI::NewNode(const string& text, bool isLeaf) -{ - CTreeNodeUI* pNodeTmp = new CTreeNodeUI; - pNodeTmp->SetItemTextColor(0XFF000000); - pNodeTmp->SetItemHotTextColor(0XFF000000); - pNodeTmp->SetSelItemTextColor(0XFF000000); - pNodeTmp->SetItemText(Base::CharacterSet::ANSIToUnicode(text).c_str()); - pNodeTmp->SetAttribute(_T("height"), _T("22")); - pNodeTmp->SetAttribute(_T("inset"), _T("0,0,0,0")); - if (isLeaf) - { - pNodeTmp->SetAttribute(_T("itemattr"), _T("valign=\"left\" font=\"5\" textpadding=\"5,3,0,0\"")); - pNodeTmp->SetAttribute(_T("folderattr"), _T("padding=\"21,3,0,0\" width=\"16\" height=\"16\" selectedimage=\"file='TreeStandard.png' source='112,32,128,48'\" normalimage=\"file='TreeStandard.png' source='112,32,128,48'\"")); - } - else - { - pNodeTmp->SetAttribute(_T("folderattr"), _T("padding=\"0,3,0,0\" width=\"16\" height=\"16\" selectedimage=\"file='tree_expand.png' source='0,0,16,16'\" normalimage=\"file='tree_expand.png' source='16,0,32,16'\"")); - pNodeTmp->SetAttribute(_T("itemattr"), _T("bkimage=\"file='TreeStandard.png' source='112,0,128,16' dest='5,3,21,19'\" valign=\"left\" font=\"5\" textpadding=\"25,3,0,0\"")); - } - - // if (isLeaf) pNodeTmp->SetAttribute(_T("folderattr"), _T("padding=\"0,3,0,0\" width=\"16\" height=\"16\" selectedimage=\"file='TreeStandard.png' source='112,32,128,48'\" normalimage=\"file='TreeStandard.png' source='112,32,128,48'\"")); - // else pNodeTmp->SetAttribute(_T("folderattr"), _T("padding=\"0,3,0,0\" width=\"16\" height=\"16\" selectedimage=\"file='TreeStandard.png' source='112,0,128,16'\" normalimage=\"file='TreeStandard.png' source='112,16,128,32'\"")); - return pNodeTmp; -} - - void RedisDataUI::DelChildNode( CTreeNodeUI* pNode ) - { - /// nm,ַʽɾ - //pNodelist->SetDelayedDestroy(false); - //pNodelist->RemoveAll(); - //int cs = pNodelist->GetCountChild(); - //for (int i=0; iRemove(pNodelist->GetChildNode(i)); - //} - //cs = pNodelist->GetCountChild(); - /// ɾнڵ - CStdPtrArray myArray = pNode->GetTreeNodes(); - for (int i=0; iRemoveAt((CTreeNodeUI*)myArray[i]); - } +#include "stdafx.h" +#include "RedisDataUI.h" +#include "Base/String.h" +#include "UserMessage.h" +#include "Base/CharacterSet.h" +#include "Redis/RedisResult.h" +#include "Redis/RedisClient.h" +#include "rapidjson/reader.h" +#include "rapidjson/reader.h" +#include "rapidjson/prettywriter.h" // for stringify JSON +#include "rapidjson/stringbuffer.h" + +#include "DuiEx/UIMenu.h" + +using namespace rapidjson; + +static const TCHAR* kDefaultText = _T(""); +static const TCHAR* kKeyEditName = _T("redisdata_key"); +static const TCHAR* kDataTypeName = _T("redisdata_type"); +static const TCHAR* kDataSizeName = _T("redisdata_size"); +static const TCHAR* kDataTTLName = _T("redisdata_ttl"); + +static const TCHAR* kRichEditName = _T("redisdata_value_rich"); +static const TCHAR* kDataListName = _T("redisdata_value"); +static const TCHAR* kKeysTreeName = _T("redisdata_treenode"); +static const TCHAR* kPageName = _T("redisdata_page"); +static const TCHAR* kPageFristName= _T("redisdata_pagefrist"); +static const TCHAR* kPageNextName = _T("redisdata_pagenext"); +static const TCHAR* kPageCurName = _T("redisdata_curpage"); +static const TCHAR* kPageTotalName= _T("redisdata_totalpage"); +static const TCHAR* kPageLastName = _T("redisdata_pagelast"); +static const TCHAR* kPageFinalName= _T("redisdata_pagefinal"); +static const TCHAR* kCommitBtnName= _T("redisdata_commit"); +static const TCHAR* kDataFomatName= _T("redisdata_format_combo"); + +static const TCHAR* kDBOperatorReloadMenuName = _T("menu_keys_reload"); +static const TCHAR* kKeyOperatorDelMenuName = _T("menu_key_del"); + + + +DUI_BEGIN_MESSAGE_MAP(RedisDataUI, CNotifyPump) +DUI_ON_MSGTYPE(DUI_MSGTYPE_CLICK, OnClick) +DUI_ON_MSGTYPE(DUI_MSGTYPE_ITEMDBCLICK, OnItemDBClick) +DUI_ON_MSGTYPE(DUI_MSGTYPE_ITEMCLICK, OnItemClick) +DUI_ON_MSGTYPE(DUI_MSGTYPE_ITEMRCLICK, OnMenuWakeup) +DUI_ON_MSGTYPE(DUI_MSGTYPE_ITEMACTIVATE, OnItemActive) +DUI_END_MESSAGE_MAP() + + +RedisDataUI::RedisDataUI( const CDuiString& strXML, CPaintManagerUI* pm ):AbstraceUI(pm),m_oEventListHeader(true),m_oEventKey(true),m_bIsKeyRender(false) +{ + CDialogBuilder builder; + CControlUI* pContainer = builder.Create(strXML.GetData(), NULL, NULL, GetPaintMgr(), NULL); + if( pContainer ) { + this->Add(pContainer); + } + else + { + this->RemoveAll(); + return; + } +} + +RedisDataUI::~RedisDataUI() +{ + for (size_t idx = 0; idx < m_oObjPool.size(); ++idx) + { + ReleaseObject(idx); + } +} + +void RedisDataUI::Initialize() +{ + m_pList = dynamic_cast(GetPaintMgr()->FindControl(kDataListName)); + m_pRichEdit = dynamic_cast(GetPaintMgr()->FindControl(kRichEditName)); + m_pKeyEdit = dynamic_cast(GetPaintMgr()->FindControl(kKeyEditName)); + m_PTypeEdit = dynamic_cast(GetPaintMgr()->FindControl(kDataTypeName)); + m_pDataSizeEdit = dynamic_cast(GetPaintMgr()->FindControl(kDataSizeName)); + m_pTTLEdit = dynamic_cast(GetPaintMgr()->FindControl(kDataTTLName)); + m_pHorizontalLayout = dynamic_cast(GetPaintMgr()->FindControl(kPageName)); + + m_pPageCur = dynamic_cast(GetPaintMgr()->FindControl(kPageCurName)); + m_pPageTotal = dynamic_cast(GetPaintMgr()->FindControl(kPageTotalName)); + m_pPageFrist = dynamic_cast(GetPaintMgr()->FindControl(kPageFristName)); + m_pPageLast = dynamic_cast(GetPaintMgr()->FindControl(kPageLastName)); + m_pPageNext = dynamic_cast(GetPaintMgr()->FindControl(kPageNextName)); + m_pPageFinal = dynamic_cast(GetPaintMgr()->FindControl(kPageFinalName)); + m_pCommit = dynamic_cast(GetPaintMgr()->FindControl(kCommitBtnName)); + m_pComboFormat = dynamic_cast(GetPaintMgr()->FindControl(kDataFomatName)); + + m_pRootNode = dynamic_cast(GetPaintMgr()->FindControl(kKeysTreeName)); +} + +int RedisDataUI::GetIndex() +{ + return 2; +} + +CDuiString RedisDataUI::GetVirtualwndName() +{ + return _T("RedisData"); +} + +void RedisDataUI::RefreshWnd() +{ + CDuiString redisName = RedisClient::GetInstance().GetName(); + /// 用户是否已经连接其它server + if (redisName != m_sCurRedisName) + { + m_sCurRedisName = redisName; + m_UpdateDbs.clear(); + } + + if (!m_UpdateDbs.empty()) { + return; + } + CTreeNodeUI* pKeyNode = m_pRootNode; + static CDuiString oldTitle = pKeyNode->GetItemText(); + DelChildNode(pKeyNode); + int databases = RedisClient::GetInstance().DatabasesNum(); + m_UpdateDbs.clear(); + m_oKeyRoot.clear(); + for (std::size_t idx = 0; idx < m_oObjPool.size(); ++idx) + { + ReleaseObject(idx); + } + m_oObjPool.clear(); + for (int i=0; iSetItemText(newTitle); + //pNode->SetBkImage(pNodelist->GetBkImage()); + pNode->SetFixedHeight(20); + pNode->SetContextMenuUsed(true); + + //pNode->SetIndex(myIdx--); + /// 此处用tag先代替treelevel(还未实现) + + pNode->SetTag(i+1); + pNode->SetAttribute(_T("itemattr"), _T("valign=\"vcenter\" font=\"5\" textpadding=\"5,3,0,0\"")); + pNode->SetAttribute(_T("folderattr"), _T("padding=\"0,3,0,0\" width=\"16\" height=\"16\" selectedimage=\"file='1_close.png' source='0,0,0,0'\" normalimage=\"file='1_open.png' source='0,0,0,0'\"")); + /// 设置为收缩并禁用 + m_bIsKeyRender = true; + pNode->GetFolderButton()->Selected(true); + pNode->GetFolderButton()->SetEnabled(false); + m_bIsKeyRender = false; + pKeyNode->AddChildNode(pNode); + } + m_oObjPool.resize(databases); + m_oKeyRoot.resize(databases); + DoRefreshKeysWork(); +} + +bool RedisDataUI::CanChange() +{ + if (m_Thread.isRunning()) { + return false; + } + return true; +} + +LRESULT RedisDataUI::HandleCustomMessage( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled ) +{ + bHandled = TRUE; + LRESULT lRes = TRUE; + switch (uMsg) + { + case WM_USER_DATAADD: + lRes = OnDataAdd(GetHWND(), wParam, lParam); + break; + case WM_USER_TREEADD: + lRes = OnKeyAdd(GetHWND(), wParam, lParam); + break; + case WM_USER_TREEVERBOSE: + lRes = OnKeyVerbose(GetHWND(), wParam, lParam); + break; + case WM_USER_DATAVERBOSE: + lRes = OnDataVerbose(GetHWND(), wParam, lParam); + break; + case WM_USER_MENU_KEYDEL: + lRes = OnKeyDel(GetHWND(), wParam, lParam); + break; + default: + bHandled = FALSE; + lRes = FALSE; + break; + } + return lRes; +} + +void RedisDataUI::OnClick( TNotifyUI& msg ) +{ + if (m_Thread.isRunning()) return; + + if (msg.pSender == m_pPageFinal || + msg.pSender == m_pPageLast || + msg.pSender == m_pPageNext || + msg.pSender == m_pPageFrist) + { + OnPaginate(msg); + } + else if (msg.pSender == m_pCommit) + { + OnCommit(msg); + } + +} + +void RedisDataUI::OnItemDBClick(TNotifyUI &msg) +{ + CDuiString name = msg.pSender->GetClass(); + CTreeNodeUI treeNodeUI; + if (name != treeNodeUI.GetClass()) + { + return; + } + + CTreeNodeUI* pActiveNode = dynamic_cast(msg.pSender); + if (!pActiveNode) return; + + if (m_bIsKeyRender) return; + + /// 非叶子节点并未加载子节点,则加载子节点 + if (pActiveNode->GetTag() != 0 && !pActiveNode->IsHasChild()) { + if (m_Thread.isRunning()) { + UserMessageBox(GetHWND(), 10012, NULL, MB_ICONINFORMATION); + return; + } + m_pAssistNode = pActiveNode; + m_pWork.reset(new Base::RunnableAdapter(*this, &RedisDataUI::BackgroudWorkForRenderLevel)); + try + { + m_Thread.start(*m_pWork); + } + catch (std::exception& ex) + { + (void)(ex); + } + return; + } +} + +void RedisDataUI::OnItemClick( TNotifyUI &msg ) +{ + CDuiString name = msg.pSender->GetClass(); + CListTextElementUI listTextElementUI ; + CTreeNodeUI treeNodeUI; + + if (name == listTextElementUI.GetClass()) + { + OnItemActiveForList(msg); + } + else if (name == treeNodeUI.GetClass()) + { + OnItemActiveForTree(msg); + } +} + +void RedisDataUI::OnItemActive( TNotifyUI &msg ) +{ + +} + +void RedisDataUI::OnMenuWakeup( TNotifyUI &msg ) +{ + CTreeNodeUI* pTreeNodeUI = dynamic_cast (msg.pSender); + if (!pTreeNodeUI) return; + + bool needMenu = false; + STRINGorID res(_T("")); + /// 父节点 + if (pTreeNodeUI->GetParentNode() == m_pRootNode) + { + STRINGorID xml(_T("DBOperatorMenu.xml")); + res = xml; + } + else if (!pTreeNodeUI->IsHasChild()) + { + STRINGorID xml(_T("KeyOperatorMenu.xml")); + res = xml; + } + CDuiString resStr = res.m_lpstr; + m_pAssistNode = pTreeNodeUI; + if (resStr.GetLength()) + { + CMenuWnd* pMenu = new CMenuWnd(GetHWND()); + pMenu->OnClick += MakeDelegate(this, &RedisDataUI::OnMenuClick); + CPoint point = msg.ptMouse; + ClientToScreen(GetHWND(), &point); + pMenu->Init(NULL, res, _T("xml"), point); + } +} + +void RedisDataUI::OnItemActiveForTree( TNotifyUI &msg ) +{ + CTreeNodeUI* pActiveNode = dynamic_cast(msg.pSender); + if (!pActiveNode) return; + + if (m_Thread.isRunning()) + { + UserMessageBox(GetHWND(), 10012, NULL, MB_ICONINFORMATION); + return ; + } + + /// 首层db节点 + if (pActiveNode->GetParentNode() == m_pRootNode) return; + + /// 非叶子节点并已加载子节点 + if (pActiveNode->GetTag() != 0 && pActiveNode->IsHasChild()) { + return ; + } + + if (pActiveNode->GetTag() != 0) + { + return; + } + + int dbNum = -1; + CTreeNodeUI* pDBNode = pActiveNode->GetParentNode(); + + while (pDBNode) + { + if (pDBNode->GetParentNode() == m_pRootNode) + { + dbNum = pDBNode->GetTag()-1; + break; + } + pDBNode = pDBNode->GetParentNode(); + } + if (dbNum < 0) return ; + m_RedisData.db = dbNum; + GetResult().Clear(); + std::string key = Base::CharacterSet::UnicodeToANSI(pActiveNode->GetItemText().GetData()); + m_pKeyEdit->SetText(Base::CharacterSet::ANSIToUnicode(key).c_str()); + m_PTypeEdit->SetText(kDefaultText); + m_pRichEdit->SetText(kDefaultText); + m_pDataSizeEdit->SetText(kDefaultText); + m_pPageCur->SetText(_T("1")); + m_pPageTotal->SetText(_T("1")); + m_pList->RemoveAll(); + m_pList->GetHeader()->RemoveAll(); + m_pHorizontalLayout->SetVisible(false); + DoRefreshValuesWork(); +} + +void RedisDataUI::OnItemActiveForList( TNotifyUI &msg ) +{ + CListTextElementUI* pListElement = dynamic_cast(msg.pSender); + if (pListElement == NULL) return; + + std::size_t curPage = atoi(Base::CharacterSet::UnicodeToANSI(m_pPageCur->GetText().GetData()).c_str()); + + int curCel = m_pList->GetItemIndex(pListElement); + /// why ? 行数不对 + ///std::size_t curIndex = m_pList->GetCurSel(); + int realIndex = (curPage-1)*m_PageSize + curCel; + int colIdx = m_pList->GetHeader()->GetCount() > 1 ? 1 : 0 ; + string myValue = GetResult().Value(realIndex, colIdx); + CDuiString myDuiStr = Base::CharacterSet::UTF8ToUnicode(myValue).c_str(); + /// 特殊的数据 + if (myValue.size() !=0 && myDuiStr.GetLength()==0) + { + TryHexFormat(myValue); + myDuiStr = Base::CharacterSet::UTF8ToUnicode(myValue).c_str(); + } + std::string text = Base::CharacterSet::UnicodeToANSI(myDuiStr.GetData()); + SetRichEditText(text); +} + +void RedisDataUI::OnPaginate(TNotifyUI& msg) +{ + std::size_t curPage = atoi(Base::CharacterSet::UnicodeToANSI(m_pPageCur->GetText().GetData()).c_str()); + + if (msg.pSender == m_pPageNext) + { + curPage += 1; + } + else if (msg.pSender == m_pPageLast) + { + curPage -= 1; + } + else if (msg.pSender == m_pPageFrist) + { + curPage = 1; + } + else if (msg.pSender == m_pPageFinal) + { + curPage = GetMaxPage(); + } + else + { + return; + } + + if (curPage==0 || curPage>GetMaxPage()) + { + return; + } + m_pList->RemoveAll(); + CDuiString pageStr, totalpageStr ; + pageStr.Format(_T("%u"), curPage); + totalpageStr.Format(_T("%u"), GetMaxPage()); + m_pPageCur->SetText(pageStr.GetData()); + m_pPageTotal->SetText(totalpageStr.GetData()); + DoPaginateWork(); +} + +void RedisDataUI::OnCommit(TNotifyUI& msg) +{ + if (m_pList->GetCurSel() < 0) + { + UserMessageBox(GetHWND(), 20002, NULL, MB_ICONINFORMATION); + return; + } + CListTextElementUI* textElement = dynamic_cast(m_pList->GetItemAt(m_pList->GetCurSel())); + std::string curPageStr = Base::CharacterSet::UnicodeToANSI(m_pPageCur->GetText().GetData()); + int curPage = atoi(curPageStr.c_str()); + int idx = (curPage-1)*m_PageSize + m_pList->GetCurSel(); + std::string key = Base::CharacterSet::UnicodeToANSI(m_pKeyEdit->GetText().GetData()); + std::string oldValue = Base::CharacterSet::UnicodeToANSI(textElement->GetText(0)); + std::string field; + if (m_pList->GetHeader()->GetCount() > 1) + { + field = Base::CharacterSet::UnicodeToANSI(textElement->GetText(0)); + oldValue = Base::CharacterSet::UnicodeToANSI(textElement->GetText(1)); + } + std::string newValue = Base::CharacterSet::UnicodeToANSI(m_pRichEdit->GetText().GetData()); + if (!RedisClient::GetInstance().UpdateData(key, oldValue, newValue, idx, field)) + { + /// todo 此处应该提示错误详情 + UserMessageBox(GetHWND(), 10031, RedisClient::GetInstance().GetLastError().GetData() , MB_ICONERROR); + return; + } + + int valueIdx = m_pList->GetHeader()->GetCount() > 1 ? 1 : 0 ; + textElement->SetText(valueIdx, m_pRichEdit->GetText().GetData()); +} + +void RedisDataUI::DoPaginateWork() +{ + m_pWork.reset(new Base::RunnableAdapter(*this, &RedisDataUI::SetPageValues)); + try + { + m_Thread.start(*m_pWork); + } + catch (std::exception& ex) + { + /// who care ? + (void)(ex); + } +} + +void RedisDataUI::DoRefreshKeysWork() +{ + if (m_Thread.isRunning()) return; + + m_pWork.reset(new Base::RunnableAdapter(*this, &RedisDataUI::BackgroundWorkForRefreshKeys)); + try + { + m_Thread.start(*m_pWork); + } + catch (std::exception& ex) + { + /// who care ? + (void)(ex); + } +} + +void RedisDataUI::DoRefreshValuesWork() +{ + if (m_Thread.isRunning()) return; + + m_pWork.reset(new Base::RunnableAdapter(*this, &RedisDataUI::BackgroundWorkForRefreshValues)); + try + { + m_Thread.start(*m_pWork); + } + catch (std::exception& ex) + { + /// who care ? + (void)(ex); + } +} + +std::size_t RedisDataUI::GetMaxPage() +{ + std::size_t maxPage = GetResult().RowSize()%m_PageSize ? (GetResult().RowSize()/m_PageSize)+1 : GetResult().RowSize()/m_PageSize; + return maxPage; +} + +RedisResult& RedisDataUI::GetResult() +{ + return m_RedisData.result; +} + +void RedisDataUI::BackgroudWorkForRenderLevel(void) +{ + /// 在OnKeyAdd pNode->GetFolderButton()->Selected(true) 会自动触发dbclick事件 所以此处要屏蔽自动产生的 + int dbNum = 0; + + /// 加载首层 + if (m_pAssistNode->GetParentNode() == m_pRootNode) + { + dbNum = m_pAssistNode->GetTag() - 1; + TkeyTree::const_iterator treeit = m_oKeyRoot[dbNum].begin(); + TkeyTree::const_iterator treeitend = m_oKeyRoot[dbNum].end(); + for (; treeit != treeitend; ++treeit) + { + if (treeit->second != NULL) continue; + + std::string theValue = treeit->first; + CTreeNodeUI* pPNode = m_pAssistNode; + + CTreeNodeUI* pnode = NewNode(theValue, treeit->second == NULL); + pnode->SetTag(treeit->second == NULL ? 0 : 1); + TreeKeyContactData* pData = new TreeKeyContactData; + pData->pPNode = pPNode; + pData->pNode = pnode; + ::PostMessage(GetHWND(), WM_USER_TREEADD, (WPARAM)pData, NULL); + } + treeit = m_oKeyRoot[dbNum].begin(); + for (; treeit != treeitend; ++treeit) + { + if (treeit->second == NULL) continue; + std::string theValue = treeit->first; + CTreeNodeUI* pPNode = m_pAssistNode; + + CTreeNodeUI* pnode = NewNode(theValue, treeit->second == NULL); + pnode->SetTag(treeit->second == NULL ? 0 : 1); + TreeKeyContactData* pData = new TreeKeyContactData; + pData->pPNode = pPNode; + pData->pNode = pnode; + ::PostMessage(GetHWND(), WM_USER_TREEADD, (WPARAM)pData, NULL); + } + } else + { + CTreeNodeUI* pPNode = m_pAssistNode; + std::vector vec; + while (pPNode) + { + if (pPNode->GetParentNode() == m_pRootNode) + { + dbNum = pPNode->GetTag() - 1; + break; + } + std::string key = Base::CharacterSet::UnicodeToANSI(pPNode->GetItemText().GetData()); + vec.push_back(key); + pPNode = pPNode->GetParentNode(); + } + TkeyTree *item = &m_oKeyRoot[dbNum]; + for (int idx = vec.size() -1; idx >=0 ; --idx) + { + item = static_cast(item->find(vec[idx])->second); + } + TkeyTree::const_iterator it = item->begin(); + TkeyTree::const_iterator itend = item->end(); + /// 先加载叶子节点 + for ( ; it != itend; ++it) + { + if (it->second != NULL) continue; + + CTreeNodeUI* pnode = NewNode(it->first, it->second == NULL); + /// 如果是叶子节点,则tag为0 + pnode->SetTag(it->second == NULL ? 0 : 1); + TreeKeyContactData* pData = new TreeKeyContactData; + pData->pPNode = m_pAssistNode; + pData->pNode = pnode; + ::PostMessage(GetHWND(), WM_USER_TREEADD, (WPARAM)pData, NULL); + } + /// 加载目录节点 + it = item->begin(); + for ( ; it != itend; ++it) + { + if (it->second == NULL) continue; + CTreeNodeUI* pnode = NewNode(it->first, it->second == NULL); + /// 如果是叶子节点,则tag为0 + pnode->SetTag(it->second == NULL ? 0 : 1); + TreeKeyContactData* pData = new TreeKeyContactData; + pData->pPNode = m_pAssistNode; + pData->pNode = pnode; + ::PostMessage(GetHWND(), WM_USER_TREEADD, (WPARAM)pData, NULL); + } + } + /// 该层加载完成,通知允许展开节点 + ::PostMessage(GetHWND(), WM_USER_TREEVERBOSE, NULL, NULL); +} + +void RedisDataUI::BackgroundWorkForRefreshKeys(void) +{ + if (!RedisClient::GetInstance().IsConnected()) return; + + CTreeNodeUI* pParentNode = m_pRootNode; + + for (int nodeIdx=0; nodeIdxGetCountChild(); ++nodeIdx) + { + CTreeNodeUI *pKeyNode = (CTreeNodeUI*) pParentNode->GetChildNode(nodeIdx); + + if (m_UpdateDbs.find(nodeIdx) == m_UpdateDbs.end()) continue; + + DelChildNode(pKeyNode); + if (!RedisClient::GetInstance().SelectDB(nodeIdx)) continue; + /// 重新填充dbsize + long long dbsize = RedisClient::GetInstance().DbSize();; + CDuiString theIndex; + theIndex.Format(_T("%d (%lld)"), nodeIdx, dbsize); + CDuiString newTitle = pParentNode->GetItemText(); + newTitle.Replace(_T("$"), theIndex.GetData()); + pKeyNode->SetItemText(newTitle); + + RedisClient::TSeqArrayResults results; + + if (!RedisClient::GetInstance().keys("*", results)) return; + RedisClient::TSeqArrayResults::const_iterator it = results.begin(); + RedisClient::TSeqArrayResults::const_iterator itend = results.end(); + m_oKeyRoot[nodeIdx].clear(); + ReleaseObject(nodeIdx); + for (; it != itend; ++it) + { + std::string theValue = *it; + Base::String::TSeqStr seq; + Base::String::Split(theValue, ":", seq); + seq[seq.size()-1] = theValue; + TkeyTree* curnode = &m_oKeyRoot[nodeIdx]; + for (std::size_t idx=0; idx < seq.size()-1; ++idx) + { + TkeyTree::iterator it = curnode->find(seq[idx]); + if (it == curnode->end()) { + TkeyTree *item = new TkeyTree; + m_oObjPool[nodeIdx].push_back(item); + curnode->insert(std::pair(seq[idx], item)); + curnode = item; + } else { + curnode = static_cast(it->second); + } + } + TkeyTree *item = NULL; + curnode->insert(std::pair(seq[seq.size()-1], item)); + } + } +} + +void RedisDataUI::BackgroundWorkForRefreshValues(void) +{ + RedisClient::GetInstance().SelectDB(m_RedisData.db); + std::string key, type; + CEditUI* pKeyEdit = static_cast(GetPaintMgr()->FindControl(kKeyEditName)); + key = Base::CharacterSet::UnicodeToANSI(pKeyEdit->GetText().GetData()); + if (!RedisClient::GetInstance().Exists(key)) + { + /// 如果该键已经不存在,则提示用户重新加载 + ::PostMessage(GetHWND(), WM_USER_DATAVERBOSE, 10030, NULL); + return; + } + m_RedisData.key = Base::CharacterSet::ANSIToUnicode(key).c_str(); + + if (!RedisClient::GetInstance().GetData(key, type, GetResult())) return; + m_RedisData.type = Base::CharacterSet::ANSIToUnicode(type).c_str(); + m_RedisData.size.Format(_T("%u"), GetResult().RowSize() ); + m_RedisData.ttl.Format(_T("%lld"), RedisClient::GetInstance().TTL(key)); + /// 预先显示数据类型等信息 + ::PostMessage(GetHWND(), WM_USER_DATAVERBOSE, NULL, NULL); + + for (std::size_t idx=0; idxSetText(Base::CharacterSet::ANSIToUnicode(GetResult().ColumnName(idx)).c_str()); + pHeaderItem->SetHotImage(_T("file='list_header_hot.png'")); + pHeaderItem->SetPushedImage(_T("file='list_header_pushed.png'")); + pHeaderItem->SetSepImage(_T("file='list_header_sep.png'")); + pHeaderItem->SetSepWidth(1); + + /// list在插入值时会根据listhead来作响应判断,所以需要在head完全update后再插入值 + LPARAM lparam = 0; + if (idx+1 == GetResult().ColumnSize()) lparam = 1; + ::PostMessage(GetHWND(), WM_USER_DATAADD, (WPARAM)pHeaderItem, lparam); + } + m_oEventListHeader.wait(); + SetPageValues(); +} + +void RedisDataUI::SetPageValues( ) +{ + const std::size_t pagesize = m_PageSize; + std::string pageStr = Base::CharacterSet::UnicodeToANSI(m_pPageCur->GetText().GetData()); + const std::size_t cur = atoi(pageStr.c_str()); + if (cur<=0 || cur>GetMaxPage()) + { + return ; + } + + std::size_t maxIndex = cur*pagesize>GetResult().RowSize() ? GetResult().RowSize(): cur*pagesize; + int ipos = 0; + for (std::size_t idx= (cur-1)*pagesize; idxSetOwner(m_pList); + pListTextElement->SetTag(idx); + for (std::size_t colidx=0; colidx 50) + { + myDuiStr = myDuiStr.Left(50); + myDuiStr.Append(_T("...")); + } + pListTextElement->SetText(colidx, myDuiStr.GetData()); + } + ::PostMessage(GetHWND(), WM_USER_DATAADD, (WPARAM)pListTextElement, NULL); + } +} + +LRESULT RedisDataUI::OnDataAdd( HWND hwnd, WPARAM wParam, LPARAM lParam ) +{ + CControlUI* pListElement = reinterpret_cast (wParam); + pListElement->NeedUpdate(); + m_pList->Add(pListElement); + m_pList->NeedUpdate(); + if (lParam != NULL) m_oEventListHeader.set(); + return TRUE; +} + +LRESULT RedisDataUI::OnKeyAdd( HWND hwnd, WPARAM wParam, LPARAM lParam ) +{ + std::auto_ptr pData(reinterpret_cast(wParam)); + CTreeNodeUI* pPNode = pData->pPNode; + CTreeNodeUI* pNode = pData->pNode; + + m_bIsKeyRender = true; + if (pNode->GetTag() != 0) + { + pNode->GetFolderButton()->Selected(true); + } + pPNode->AddChildNode(pNode); + m_bIsKeyRender = false; + return TRUE; +} + +LRESULT RedisDataUI::OnKeyDel( HWND hwnd, WPARAM wParam, LPARAM lParam ) +{ + CTreeNodeUI* pNode = reinterpret_cast(wParam); + CTreeNodeUI* pPNode; + CDuiString a = pNode->GetItemText(); + std::string key = Base::CharacterSet::UnicodeToANSI(pNode->GetItemText().GetData()); + /// 暂时用同步方法删除,大数据时会有卡顿 + if (!RedisClient::GetInstance().DelKey(key)) return FALSE; + while (pNode) + { + if (pNode->IsHasChild() || pNode->GetTag()>0) break; + pPNode = pNode->GetParentNode(); + pPNode->Remove(pNode); + pNode = pPNode; + } + return TRUE; +} + +LRESULT RedisDataUI::OnKeyVerbose(HWND hwnd, WPARAM wParam, LPARAM lParam) +{ + m_bIsKeyRender = true; + m_pAssistNode->GetFolderButton()->Selected(false); + m_pAssistNode->GetFolderButton()->SetEnabled(true); + m_bIsKeyRender = false; + return TRUE; +} + +LRESULT RedisDataUI::OnDataVerbose( HWND hwnd, WPARAM wParam, LPARAM lParam ) +{ + if (wParam != 0) + { + UserMessageBox(GetHWND(), 10030, NULL, MB_ICONERROR); + return FALSE; + } + m_pKeyEdit->SetText(m_RedisData.key.GetData()); + m_PTypeEdit->SetText(m_RedisData.type.GetData()); + m_pDataSizeEdit->SetText(m_RedisData.size.GetData()); + m_pTTLEdit->SetText(m_RedisData.ttl.GetData()); + m_pRichEdit->SetText(kDefaultText); + /// 如果是单元素(如string),则一并直接更新到富文本框内 + if (GetResult().RowSize() == 1 && GetResult().ColumnSize()==1) + { + string myValue = GetResult().Value(0, 0); + CDuiString myDuiStr = Base::CharacterSet::UTF8ToUnicode(myValue).c_str(); + /// 特殊的数据 + if (myValue.size() !=0 && myDuiStr.GetLength()==0) + { + TryHexFormat(myValue); + myDuiStr = Base::CharacterSet::UTF8ToUnicode(myValue).c_str(); + } + std::string text = Base::CharacterSet::UnicodeToANSI(myDuiStr.GetData()); + SetRichEditText(text); + } + + if (GetResult().RowSize() > m_PageSize) + { + /// 设置总页数 + CDuiString totalpageStr; + totalpageStr.Format(_T("%u"), GetMaxPage()); + m_pPageTotal->SetText(totalpageStr.GetData()); + m_pHorizontalLayout->SetVisible(true); + } + return TRUE; +} + +bool RedisDataUI::OnMenuClick( void* param ) +{ + if (m_Thread.isRunning()) + { + UserMessageBox(GetHWND(), 10012, NULL, MB_ICONINFORMATION); + return false; + } + TEventUI* pTEventUI = static_cast (param); + CDuiString name = pTEventUI->pSender->GetName(); + if (name == kDBOperatorReloadMenuName) + { + m_UpdateDbs.clear(); + m_UpdateDbs.insert(m_pAssistNode->GetTag() - 1); + CTreeNodeUI* pParentNode = m_pRootNode; + CTreeNodeUI *pKeyNode = (CTreeNodeUI*) pParentNode->GetChildNode(m_pAssistNode->GetTag() - 1); + /// 同步删除,数据量大时会卡顿 + DelChildNode(pKeyNode); + m_bIsKeyRender = true; + pKeyNode->GetFolderButton()->Selected(true); + pKeyNode->GetFolderButton()->SetEnabled(false); + m_bIsKeyRender = false; + DoRefreshKeysWork(); + } + else if (name == kKeyOperatorDelMenuName) + { + ::PostMessage(GetHWND(), WM_USER_MENU_KEYDEL, (WPARAM)(m_pAssistNode), NULL); + } + return true; +} + +void RedisDataUI::SetRichEditText(const std::string& text) +{ + enum DataFomat + { + kAutoFomat = 0, + kNormalFormat = 1, + kJsonFormat = 2, + kXMLFormat = 3, + kHexFormat = 4 + }; + std::string styleText = text; + int curSel = m_pComboFormat->GetCurSel(); + + /// 必要时重构 + if ( curSel == kAutoFomat ) + { + if (TryJsonFomat(styleText) || TryXMLFormat(styleText)) {} + } + else if (curSel == kJsonFormat) + { + TryJsonFomat(styleText); + } + else if (curSel == kXMLFormat) + { + TryXMLFormat(styleText); + } + else if (curSel == kHexFormat) + { + TryHexFormat(styleText); + } + m_pRichEdit->SetText(Base::CharacterSet::ANSIToUnicode(styleText).c_str()); +} + +bool RedisDataUI::TryJsonFomat( std::string& text ) +{ + std::string& styleText = text; + + StringStream s(styleText.c_str()); + StringBuffer buffer; + PrettyWriter writer(buffer); + Reader reader; + if (reader.Parse<0>(s, writer)) + { + styleText = buffer.GetString(); + return true; + } + return false; +} + +bool RedisDataUI::TryXMLFormat( std::string& text ) +{ + return true; +} + +bool RedisDataUI::TryHexFormat( std::string& text ) +{ + std::string styleText; + std::string::const_iterator it = text.begin(); + std::string::const_iterator itend = text.end(); + for ( ;it!=itend; ++it) + { + styleText+=Base::String::Chrtos(*it); + } + text = styleText; + return true; +} + +void RedisDataUI::ReleaseObject(std::size_t idx) +{ + if (m_oObjPool.size() > idx) + { + std::list::const_iterator it = m_oObjPool[idx].begin(); + std::list::const_iterator itend = m_oObjPool[idx].end(); + for ( ; it != itend; ++it) + { + delete (TkeyTree*)*it; + } + m_oObjPool[idx].clear(); + } +} + +CTreeNodeUI* RedisDataUI::NewNode(const string& text, bool isLeaf) +{ + CTreeNodeUI* pNodeTmp = new CTreeNodeUI; + pNodeTmp->SetItemTextColor(0XFF000000); + pNodeTmp->SetItemHotTextColor(0XFF000000); + pNodeTmp->SetSelItemTextColor(0XFF000000); + pNodeTmp->SetItemText(Base::CharacterSet::ANSIToUnicode(text).c_str()); + pNodeTmp->SetAttribute(_T("height"), _T("22")); + pNodeTmp->SetAttribute(_T("inset"), _T("0,0,0,0")); + if (isLeaf) + { + pNodeTmp->SetAttribute(_T("itemattr"), _T("valign=\"left\" font=\"5\" textpadding=\"5,3,0,0\"")); + pNodeTmp->SetAttribute(_T("folderattr"), _T("padding=\"21,3,0,0\" width=\"16\" height=\"16\" selectedimage=\"file='TreeStandard.png' source='112,32,128,48'\" normalimage=\"file='TreeStandard.png' source='112,32,128,48'\"")); + } + else + { + pNodeTmp->SetAttribute(_T("folderattr"), _T("padding=\"0,3,0,0\" width=\"16\" height=\"16\" selectedimage=\"file='tree_expand.png' source='0,0,16,16'\" normalimage=\"file='tree_expand.png' source='16,0,32,16'\"")); + pNodeTmp->SetAttribute(_T("itemattr"), _T("bkimage=\"file='TreeStandard.png' source='112,0,128,16' dest='5,3,21,19'\" valign=\"left\" font=\"5\" textpadding=\"25,3,0,0\"")); + } + pNodeTmp->GetFolderButton()->SetEnabled(false); + // if (isLeaf) pNodeTmp->SetAttribute(_T("folderattr"), _T("padding=\"0,3,0,0\" width=\"16\" height=\"16\" selectedimage=\"file='TreeStandard.png' source='112,32,128,48'\" normalimage=\"file='TreeStandard.png' source='112,32,128,48'\"")); + // else pNodeTmp->SetAttribute(_T("folderattr"), _T("padding=\"0,3,0,0\" width=\"16\" height=\"16\" selectedimage=\"file='TreeStandard.png' source='112,0,128,16'\" normalimage=\"file='TreeStandard.png' source='112,16,128,32'\"")); + return pNodeTmp; +} + + void RedisDataUI::DelChildNode( CTreeNodeUI* pNode ) + { + /// 删除所有节点 + CStdPtrArray myArray = pNode->GetTreeNodes(); + for (int i=0; iRemoveAt((CTreeNodeUI*)myArray[i]); + } } \ No newline at end of file diff --git a/RedisStudio/RedisDataUI.h b/RedisStudio/RedisDataUI.h index deeb204..979b00b 100644 --- a/RedisStudio/RedisDataUI.h +++ b/RedisStudio/RedisDataUI.h @@ -1,8 +1,9 @@ -#pragma once +#pragma once #include "stdafx.h" #include #include +#include #include "Base/Event.h" #include "Base/Thread.h" @@ -24,17 +25,22 @@ struct TreeKeyContactData class RedisDataUI : public AbstraceUI { public: + typedef std::map< std::string, void * > TkeyTree; + struct RedisDataStruct { int db; CDuiString key; CDuiString type; CDuiString size; + CDuiString ttl; RedisResult result; }; RedisDataUI(const CDuiString& strXML, CPaintManagerUI* pm); + ~RedisDataUI(); + void Initialize(); int GetIndex(); @@ -53,6 +59,8 @@ class RedisDataUI : public AbstraceUI virtual void OnItemClick( TNotifyUI &msg ); + virtual void OnItemDBClick( TNotifyUI &msg ); + virtual void OnItemActive( TNotifyUI &msg ); virtual void OnMenuWakeup( TNotifyUI &msg ); @@ -71,6 +79,8 @@ class RedisDataUI : public AbstraceUI LRESULT OnKeyDel(HWND hwnd, WPARAM wParam, LPARAM lParam); + LRESULT OnKeyVerbose(HWND hwnd, WPARAM wParam, LPARAM lParam); + LRESULT OnDataVerbose(HWND hwnd, WPARAM wParam, LPARAM lParam); bool OnMenuClick( void* param ); @@ -96,11 +106,15 @@ class RedisDataUI : public AbstraceUI void DoRefreshValuesWork(); + void BackgroudWorkForRenderLevel(void); + void BackgroundWorkForRefreshKeys(void); void BackgroundWorkForRefreshValues(void); private: + void ReleaseObject(std::size_t idx); + CTreeNodeUI* NewNode(const string& text, bool isLeaf=false); void DelChildNode(CTreeNodeUI* pNode); @@ -111,9 +125,10 @@ class RedisDataUI : public AbstraceUI CEditUI* m_pKeyEdit; CEditUI* m_PTypeEdit; CEditUI* m_pDataSizeEdit; + CEditUI* m_pTTLEdit; CEditUI* m_pPageCur; - CEditUI* m_pPageTotal; + CEditUI* m_pPageTotal; CButtonUI* m_pPageFrist; CButtonUI* m_pPageLast; CButtonUI* m_pPageNext; @@ -127,9 +142,14 @@ class RedisDataUI : public AbstraceUI Base::Event m_oEventListHeader; Base::Event m_oEventKey; - static const std::size_t m_PageSize = 100; + bool m_bIsKeyRender; - CTreeNodeUI* m_pAssistNode; // key treeҼ˵ֵΪǰҼĽڵ + CDuiString m_sCurRedisName; + static const std::size_t m_PageSize = 100; + std::vector> m_oObjPool; + std::vector m_oKeyRoot; + CTreeNodeUI* m_pRootNode; + CTreeNodeUI* m_pAssistNode; RedisDataStruct m_RedisData; Base::Thread m_Thread; std::set m_UpdateDbs; diff --git a/RedisStudio/RedisHelpUI.cpp b/RedisStudio/RedisHelpUI.cpp index 77385ba..116749c 100644 --- a/RedisStudio/RedisHelpUI.cpp +++ b/RedisStudio/RedisHelpUI.cpp @@ -1,60 +1,60 @@ -#include "stdafx.h" -#include "RedisHelpUI.h" - -DUI_BEGIN_MESSAGE_MAP(RedisHelpUI, CNotifyPump) -DUI_ON_MSGTYPE(DUI_MSGTYPE_CLICK,OnClick) -DUI_END_MESSAGE_MAP() - -RedisHelpUI::RedisHelpUI(const CDuiString& strXML, CPaintManagerUI* pm) : AbstraceUI(pm) -{ - CDialogBuilder builder; - // 봫m_PaintManagerȻXMLʹĬϹϢ - CControlUI* pContainer = builder.Create(strXML.GetData(), NULL, NULL, GetPaintMgr(), NULL); - if( pContainer ) { - this->Add(pContainer); - } - else { - this->RemoveAll(); - return; - } -} - -RedisHelpUI::~RedisHelpUI(void) -{ -} - -void RedisHelpUI::Initialize() -{ - CActiveXUI* pActiveXUI = static_cast(GetPaintMgr()->FindControl(_T("ie"))); - if( pActiveXUI ) { - IWebBrowser2* pWebBrowser = NULL; - pActiveXUI->GetControl(IID_IWebBrowser2, (void**)&pWebBrowser); - // js - pWebBrowser->put_Silent(true); - if( pWebBrowser != NULL ) { - pWebBrowser->Navigate(L"http://redis.io/commands",NULL,NULL,NULL,NULL); - //pWebBrowser->Navigate(L"about:blank",NULL,NULL,NULL,NULL); - pWebBrowser->Release(); - } - } -} - -int RedisHelpUI::GetIndex() -{ - return 5; -} - -DuiLib::CDuiString RedisHelpUI::GetVirtualwndName() -{ - return _T("RedisHelp"); -} - -void RedisHelpUI::RefreshWnd() -{ - -} - -void RedisHelpUI::OnClick( TNotifyUI& msg ) -{ - -} +#include "stdafx.h" +#include "RedisHelpUI.h" + +DUI_BEGIN_MESSAGE_MAP(RedisHelpUI, CNotifyPump) +DUI_ON_MSGTYPE(DUI_MSGTYPE_CLICK,OnClick) +DUI_END_MESSAGE_MAP() + +RedisHelpUI::RedisHelpUI(const CDuiString& strXML, CPaintManagerUI* pm) : AbstraceUI(pm) +{ + CDialogBuilder builder; + // 这里必须传入m_PaintManager,不然子XML不能使用默认滚动条等信息。 + CControlUI* pContainer = builder.Create(strXML.GetData(), NULL, NULL, GetPaintMgr(), NULL); + if( pContainer ) { + this->Add(pContainer); + } + else { + this->RemoveAll(); + return; + } +} + +RedisHelpUI::~RedisHelpUI(void) +{ +} + +void RedisHelpUI::Initialize() +{ + CActiveXUI* pActiveXUI = static_cast(GetPaintMgr()->FindControl(_T("ie"))); + if( pActiveXUI ) { + IWebBrowser2* pWebBrowser = NULL; + pActiveXUI->GetControl(IID_IWebBrowser2, (void**)&pWebBrowser); + // 忽略js错误 + pWebBrowser->put_Silent(true); + if( pWebBrowser != NULL ) { + pWebBrowser->Navigate(L"http://redis.io/commands",NULL,NULL,NULL,NULL); + //pWebBrowser->Navigate(L"about:blank",NULL,NULL,NULL,NULL); + pWebBrowser->Release(); + } + } +} + +int RedisHelpUI::GetIndex() +{ + return 5; +} + +DuiLib::CDuiString RedisHelpUI::GetVirtualwndName() +{ + return _T("RedisHelp"); +} + +void RedisHelpUI::RefreshWnd() +{ + +} + +void RedisHelpUI::OnClick( TNotifyUI& msg ) +{ + +} diff --git a/RedisStudio/RedisHelpUI.h b/RedisStudio/RedisHelpUI.h index 8dbfbef..e4c7e96 100644 --- a/RedisStudio/RedisHelpUI.h +++ b/RedisStudio/RedisHelpUI.h @@ -1,23 +1,23 @@ -#pragma once - -#include "AbstractUI.h" - -class RedisHelpUI : public AbstraceUI -{ -public: - RedisHelpUI(const CDuiString& strXML, CPaintManagerUI* pm); - - ~RedisHelpUI(void); - - void Initialize(); - - int GetIndex(); - - CDuiString GetVirtualwndName(); - - void RefreshWnd(); - - DUI_DECLARE_MESSAGE_MAP() - - void OnClick(TNotifyUI& msg); -}; +#pragma once + +#include "AbstractUI.h" + +class RedisHelpUI : public AbstraceUI +{ +public: + RedisHelpUI(const CDuiString& strXML, CPaintManagerUI* pm); + + ~RedisHelpUI(void); + + void Initialize(); + + int GetIndex(); + + CDuiString GetVirtualwndName(); + + void RefreshWnd(); + + DUI_DECLARE_MESSAGE_MAP() + + void OnClick(TNotifyUI& msg); +}; diff --git a/RedisStudio/RedisInfoUI.cpp b/RedisStudio/RedisInfoUI.cpp index b0d2c75..f9ad3b9 100644 --- a/RedisStudio/RedisInfoUI.cpp +++ b/RedisStudio/RedisInfoUI.cpp @@ -1,163 +1,163 @@ -#include "stdafx.h" -#include -#include "Base/CharacterSet.h" -#include "RedisInfoUI.h" -#include "Redis/RedisClient.h" -#include "UserMessage.h" - -static const TCHAR* kKeyStartButtonName = _T("btn_refreshinfo_start"); -static const TCHAR* kKeyStopButtonName = _T("btn_refreshinfo_stop"); - -DUI_BEGIN_MESSAGE_MAP(RedisInfoUI, CNotifyPump) -DUI_ON_MSGTYPE(DUI_MSGTYPE_CLICK,OnClick) -DUI_ON_MSGTYPE(DUI_MSGTYPE_SELECTCHANGED,OnSelectChanged) -DUI_ON_MSGTYPE(DUI_MSGTYPE_ITEMCLICK,OnItemClick) -DUI_END_MESSAGE_MAP() - -RedisInfoUI::RedisInfoUI( const CDuiString& strXML, CPaintManagerUI* pm ):AbstraceUI(pm),m_bIsRefresh(false) -{ - CDialogBuilder builder; - CControlUI* pContainer = builder.Create(strXML.GetData(), NULL, NULL, GetPaintMgr(), NULL); // 봫m_PaintManagerȻXMLʹĬϹϢ - if( pContainer ) { - this->Add(pContainer); - } - else { - this->RemoveAll(); - return; - } -} - -RedisInfoUI::~RedisInfoUI() -{ -} - -void RedisInfoUI::Initialize() -{ - m_RefreshStart = static_cast(GetPaintMgr()->FindControl(kKeyStartButtonName)); - m_RefreshStop = static_cast(GetPaintMgr()->FindControl(kKeyStopButtonName)); -} - - -int RedisInfoUI::GetIndex() -{ - return 1; -} - -CDuiString RedisInfoUI::GetVirtualwndName() -{ - return _T("RedisInfo"); -} - -void RedisInfoUI::RefreshWnd() -{ - if (!m_Thread.isRunning()) DoRefreshWork(); -} - -LRESULT RedisInfoUI::HandleCustomMessage( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled ) -{ - bHandled = TRUE; - LRESULT lRes = TRUE; - switch(uMsg) - { - case WM_USER_INFOUPDATE: lRes = OnInfoRefresh(GetHWND(), wParam, lParam); - break; - default: - lRes = FALSE; - bHandled= FALSE; - break; - } - return lRes; -} - -void RedisInfoUI::OnClick( TNotifyUI& msg ) -{ - if (msg.pSender == m_RefreshStart) - { - m_bIsRefresh = true; - DoRefreshWork(); - m_RefreshStop->SetVisible(true); - m_RefreshStart->SetVisible(false); - } - else if (msg.pSender == m_RefreshStop) - { - m_bIsRefresh = false; - m_RefreshStop->SetVisible(false); - m_RefreshStart->SetVisible(true); - } -} - -void RedisInfoUI::OnSelectChanged( TNotifyUI &msg ) -{ - -} - -void RedisInfoUI::OnItemClick( TNotifyUI &msg ) -{ - -} - -void RedisInfoUI::DoRefreshWork() -{ - m_pWork.reset(new Base::RunnableAdapter(*this, &RedisInfoUI::BackgroundWork)); - try - { - m_Thread.start(*m_pWork); - } - catch (std::exception& ex) - { - /// who care ? - (void)(ex); - } -} - -void RedisInfoUI::RefreshInfo() -{ - if (!RedisClient::GetInstance().IsConnected()) return; - - string info ; - if (!RedisClient::GetInstance().Info(info)) return; - - if (info.empty()) return; - std::string* pInfo = new std::string(info); - PostMessage(GetHWND(), WM_USER_INFOUPDATE, (WPARAM)pInfo, NULL); -} - -void RedisInfoUI::BackgroundWork() -{ - const int sleepTime = 1000; /// ms - do - { - RefreshInfo(); - - /// ڿӦ - for (int i=0; m_bIsRefresh && i (GetPaintMgr()->FindControl(controlName.c_str())); - if (p) - { - p->SetText(ControlText.c_str()); - p->NeedUpdate(); - } - } - delete pInfo; - return TRUE; -} +#include "stdafx.h" +#include +#include "Base/CharacterSet.h" +#include "RedisInfoUI.h" +#include "Redis/RedisClient.h" +#include "UserMessage.h" + +static const TCHAR* kKeyStartButtonName = _T("btn_refreshinfo_start"); +static const TCHAR* kKeyStopButtonName = _T("btn_refreshinfo_stop"); + +DUI_BEGIN_MESSAGE_MAP(RedisInfoUI, CNotifyPump) +DUI_ON_MSGTYPE(DUI_MSGTYPE_CLICK,OnClick) +DUI_ON_MSGTYPE(DUI_MSGTYPE_SELECTCHANGED,OnSelectChanged) +DUI_ON_MSGTYPE(DUI_MSGTYPE_ITEMCLICK,OnItemClick) +DUI_END_MESSAGE_MAP() + +RedisInfoUI::RedisInfoUI( const CDuiString& strXML, CPaintManagerUI* pm ):AbstraceUI(pm),m_bIsRefresh(false) +{ + CDialogBuilder builder; + CControlUI* pContainer = builder.Create(strXML.GetData(), NULL, NULL, GetPaintMgr(), NULL); // 这里必须传入m_PaintManager,不然子XML不能使用默认滚动条等信息。 + if( pContainer ) { + this->Add(pContainer); + } + else { + this->RemoveAll(); + return; + } +} + +RedisInfoUI::~RedisInfoUI() +{ +} + +void RedisInfoUI::Initialize() +{ + m_RefreshStart = static_cast(GetPaintMgr()->FindControl(kKeyStartButtonName)); + m_RefreshStop = static_cast(GetPaintMgr()->FindControl(kKeyStopButtonName)); +} + + +int RedisInfoUI::GetIndex() +{ + return 1; +} + +CDuiString RedisInfoUI::GetVirtualwndName() +{ + return _T("RedisInfo"); +} + +void RedisInfoUI::RefreshWnd() +{ + if (!m_Thread.isRunning()) DoRefreshWork(); +} + +LRESULT RedisInfoUI::HandleCustomMessage( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled ) +{ + bHandled = TRUE; + LRESULT lRes = TRUE; + switch(uMsg) + { + case WM_USER_INFOUPDATE: lRes = OnInfoRefresh(GetHWND(), wParam, lParam); + break; + default: + lRes = FALSE; + bHandled= FALSE; + break; + } + return lRes; +} + +void RedisInfoUI::OnClick( TNotifyUI& msg ) +{ + if (msg.pSender == m_RefreshStart) + { + m_bIsRefresh = true; + DoRefreshWork(); + m_RefreshStop->SetVisible(true); + m_RefreshStart->SetVisible(false); + } + else if (msg.pSender == m_RefreshStop) + { + m_bIsRefresh = false; + m_RefreshStop->SetVisible(false); + m_RefreshStart->SetVisible(true); + } +} + +void RedisInfoUI::OnSelectChanged( TNotifyUI &msg ) +{ + +} + +void RedisInfoUI::OnItemClick( TNotifyUI &msg ) +{ + +} + +void RedisInfoUI::DoRefreshWork() +{ + m_pWork.reset(new Base::RunnableAdapter(*this, &RedisInfoUI::BackgroundWork)); + try + { + m_Thread.start(*m_pWork); + } + catch (std::exception& ex) + { + /// who care ? + (void)(ex); + } +} + +void RedisInfoUI::RefreshInfo() +{ + if (!RedisClient::GetInstance().IsConnected()) return; + + string info ; + if (!RedisClient::GetInstance().Info(info)) return; + + if (info.empty()) return; + std::string* pInfo = new std::string(info); + PostMessage(GetHWND(), WM_USER_INFOUPDATE, (WPARAM)pInfo, NULL); +} + +void RedisInfoUI::BackgroundWork() +{ + const int sleepTime = 1000; /// ms + do + { + RefreshInfo(); + + /// 便于快速响应 + for (int i=0; m_bIsRefresh && i (GetPaintMgr()->FindControl(controlName.c_str())); + if (p) + { + p->SetText(ControlText.c_str()); + p->NeedUpdate(); + } + } + delete pInfo; + return TRUE; +} diff --git a/RedisStudio/RedisInfoUI.h b/RedisStudio/RedisInfoUI.h index c79102a..b271c03 100644 --- a/RedisStudio/RedisInfoUI.h +++ b/RedisStudio/RedisInfoUI.h @@ -1,54 +1,54 @@ -#pragma once - -#include "stdafx.h" -#include "AbstractUI.h" - -#include "Base/RunnableAdapter.h" -#include "Base/Thread.h" - -class CTreeView; - -class RedisInfoUI : public AbstraceUI -{ -public: - RedisInfoUI(const CDuiString& strXML, CPaintManagerUI* pm); - - ~RedisInfoUI(); - - void Initialize(); - - int GetIndex(); - - CDuiString GetVirtualwndName(); - - void RefreshWnd(); - - DUI_DECLARE_MESSAGE_MAP() - - virtual LRESULT HandleCustomMessage( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled ); - - virtual void OnClick(TNotifyUI& msg); - - virtual void OnSelectChanged( TNotifyUI &msg ); - - virtual void OnItemClick( TNotifyUI &msg ); - -public: - LRESULT OnInfoRefresh(HWND hwnd, WPARAM wParam, LPARAM lParam); - -public: - void DoRefreshWork(); - - void BackgroundWork(); - -private: - void RefreshInfo(); - -private: - CButtonUI* m_RefreshStart; - CButtonUI* m_RefreshStop; - CTreeNodeUI* m_pServerInfoNode; - bool m_bIsRefresh; - Base::Thread m_Thread; - std::auto_ptr< Base::RunnableAdapter > m_pWork; +#pragma once + +#include "stdafx.h" +#include "AbstractUI.h" + +#include "Base/RunnableAdapter.h" +#include "Base/Thread.h" + +class CTreeView; + +class RedisInfoUI : public AbstraceUI +{ +public: + RedisInfoUI(const CDuiString& strXML, CPaintManagerUI* pm); + + ~RedisInfoUI(); + + void Initialize(); + + int GetIndex(); + + CDuiString GetVirtualwndName(); + + void RefreshWnd(); + + DUI_DECLARE_MESSAGE_MAP() + + virtual LRESULT HandleCustomMessage( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled ); + + virtual void OnClick(TNotifyUI& msg); + + virtual void OnSelectChanged( TNotifyUI &msg ); + + virtual void OnItemClick( TNotifyUI &msg ); + +public: + LRESULT OnInfoRefresh(HWND hwnd, WPARAM wParam, LPARAM lParam); + +public: + void DoRefreshWork(); + + void BackgroundWork(); + +private: + void RefreshInfo(); + +private: + CButtonUI* m_RefreshStart; + CButtonUI* m_RefreshStop; + CTreeNodeUI* m_pServerInfoNode; + bool m_bIsRefresh; + Base::Thread m_Thread; + std::auto_ptr< Base::RunnableAdapter > m_pWork; }; \ No newline at end of file diff --git a/RedisStudio/RedisMgrUI.cpp b/RedisStudio/RedisMgrUI.cpp index 2bb1f9f..8d57532 100644 --- a/RedisStudio/RedisMgrUI.cpp +++ b/RedisStudio/RedisMgrUI.cpp @@ -1,49 +1,49 @@ -#include "stdafx.h" -#include "RedisMgrUI.h" - -DUI_BEGIN_MESSAGE_MAP(RedisMgrUI, CNotifyPump) -DUI_ON_MSGTYPE(DUI_MSGTYPE_CLICK,OnClick) -DUI_END_MESSAGE_MAP() - -RedisMgrUI::RedisMgrUI(const CDuiString& strXML, CPaintManagerUI* pm) : AbstraceUI(pm) -{ - CDialogBuilder builder; - // 봫m_PaintManagerȻXMLʹĬϹϢ - CControlUI* pContainer = builder.Create(strXML.GetData(), NULL, NULL, GetPaintMgr(), NULL); - if( pContainer ) { - this->Add(pContainer); - } - else { - this->RemoveAll(); - return; - } -} - -RedisMgrUI::~RedisMgrUI(void) -{ -} - -void RedisMgrUI::Initialize() -{ - -} - -int RedisMgrUI::GetIndex() -{ - return 4; -} - -DuiLib::CDuiString RedisMgrUI::GetVirtualwndName() -{ - return _T("RedisMgr"); -} - -void RedisMgrUI::RefreshWnd() -{ - -} - -void RedisMgrUI::OnClick( TNotifyUI& msg ) -{ - -} +#include "stdafx.h" +#include "RedisMgrUI.h" + +DUI_BEGIN_MESSAGE_MAP(RedisMgrUI, CNotifyPump) +DUI_ON_MSGTYPE(DUI_MSGTYPE_CLICK,OnClick) +DUI_END_MESSAGE_MAP() + +RedisMgrUI::RedisMgrUI(const CDuiString& strXML, CPaintManagerUI* pm) : AbstraceUI(pm) +{ + CDialogBuilder builder; + // 这里必须传入m_PaintManager,不然子XML不能使用默认滚动条等信息。 + CControlUI* pContainer = builder.Create(strXML.GetData(), NULL, NULL, GetPaintMgr(), NULL); + if( pContainer ) { + this->Add(pContainer); + } + else { + this->RemoveAll(); + return; + } +} + +RedisMgrUI::~RedisMgrUI(void) +{ +} + +void RedisMgrUI::Initialize() +{ + +} + +int RedisMgrUI::GetIndex() +{ + return 4; +} + +DuiLib::CDuiString RedisMgrUI::GetVirtualwndName() +{ + return _T("RedisMgr"); +} + +void RedisMgrUI::RefreshWnd() +{ + +} + +void RedisMgrUI::OnClick( TNotifyUI& msg ) +{ + +} diff --git a/RedisStudio/RedisMgrUI.h b/RedisStudio/RedisMgrUI.h index 9b2f245..4756b3f 100644 --- a/RedisStudio/RedisMgrUI.h +++ b/RedisStudio/RedisMgrUI.h @@ -1,23 +1,23 @@ -#pragma once - -#include "AbstractUI.h" - -class RedisMgrUI : public AbstraceUI -{ -public: - RedisMgrUI(const CDuiString& strXML, CPaintManagerUI* pm); - - ~RedisMgrUI(void); - - void Initialize(); - - int GetIndex(); - - CDuiString GetVirtualwndName(); - - void RefreshWnd(); - - DUI_DECLARE_MESSAGE_MAP() - - void OnClick(TNotifyUI& msg); -}; +#pragma once + +#include "AbstractUI.h" + +class RedisMgrUI : public AbstraceUI +{ +public: + RedisMgrUI(const CDuiString& strXML, CPaintManagerUI* pm); + + ~RedisMgrUI(void); + + void Initialize(); + + int GetIndex(); + + CDuiString GetVirtualwndName(); + + void RefreshWnd(); + + DUI_DECLARE_MESSAGE_MAP() + + void OnClick(TNotifyUI& msg); +}; diff --git a/RedisStudio/RedisStudio.vcxproj b/RedisStudio/RedisStudio.vcxproj index 66afca0..d492334 100644 --- a/RedisStudio/RedisStudio.vcxproj +++ b/RedisStudio/RedisStudio.vcxproj @@ -89,6 +89,8 @@ AllRules.ruleset + false + false @@ -303,6 +305,7 @@ del "$(SolutionDir)bin\skin\*.psd" + @@ -342,6 +345,7 @@ del "$(SolutionDir)bin\skin\*.psd" + @@ -373,6 +377,7 @@ del "$(SolutionDir)bin\skin\*.psd" + diff --git a/RedisStudio/RedisStudio.vcxproj.filters b/RedisStudio/RedisStudio.vcxproj.filters index e1588d6..3dbadf4 100644 --- a/RedisStudio/RedisStudio.vcxproj.filters +++ b/RedisStudio/RedisStudio.vcxproj.filters @@ -1,231 +1,240 @@ - - - - - {51b03c78-7536-46fd-912f-e8e33f529f85} - cpp;c;cxx;rc;def;r;odl;idl;hpj;bat - - - {9b5de401-14e6-43ea-a052-c30134f7a6e5} - h;hpp;hxx;hm;inl - - - {db597cb6-b6bc-4461-8971-1e3607e14396} - - - {1a0cf2f1-2884-4c15-8897-e9c15a1fde7b} - - - {436f8d9b-8fa5-4b10-b5f3-2d9e968b3218} - - - {1b75613b-6acb-4502-8fa9-ae25a5953fbf} - - - {453cb08d-1ed7-4d36-93cb-cebc15a95382} - - - {7b20847b-78f3-422a-87e1-9c59073aa1ef} - - - {697f197a-6e73-41bf-895d-ffdfabe56a90} - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files\Base - - - Source Files\Base - - - Source Files\Base - - - Source Files\DuiEx - - - Source Files\Redis - - - Source Files\Redis - - - Source Files\Redis - - - Source Files\Redis - - - Source Files\Redis - - - Source Files\Redis - - - Source Files\Redis - - - Source Files\Redis - - - Source Files\Base - - - Source Files\Base - - - Source Files\Base - - - Source Files - - - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Resource Files - - - Header Files\DuiEx - - - Header Files\DuiEx - - - Header Files\Base - - - Header Files\Base - - - Header Files\Base - - - Header Files\Base - - - Header Files\Redis - - - Header Files\Redis - - - Header Files\Redis - - - Header Files\Redis - - - Header Files\Redis - - - Header Files\Redis - - - Header Files\Redis - - - Header Files\Redis - - - Header Files\Redis - - - Header Files\Redis - - - Header Files\Base - - - Header Files\Base - - - Header Files\Base - - - Header Files\Base - - - Header Files - - - - - Resource Files - - - - - Resource Files - - + + + + + {51b03c78-7536-46fd-912f-e8e33f529f85} + cpp;c;cxx;rc;def;r;odl;idl;hpj;bat + + + {9b5de401-14e6-43ea-a052-c30134f7a6e5} + h;hpp;hxx;hm;inl + + + {db597cb6-b6bc-4461-8971-1e3607e14396} + + + {1a0cf2f1-2884-4c15-8897-e9c15a1fde7b} + + + {436f8d9b-8fa5-4b10-b5f3-2d9e968b3218} + + + {1b75613b-6acb-4502-8fa9-ae25a5953fbf} + + + {453cb08d-1ed7-4d36-93cb-cebc15a95382} + + + {7b20847b-78f3-422a-87e1-9c59073aa1ef} + + + {697f197a-6e73-41bf-895d-ffdfabe56a90} + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files\Base + + + Source Files\Base + + + Source Files\Base + + + Source Files\DuiEx + + + Source Files\Redis + + + Source Files\Redis + + + Source Files\Redis + + + Source Files\Redis + + + Source Files\Redis + + + Source Files\Redis + + + Source Files\Redis + + + Source Files\Redis + + + Source Files\Base + + + Source Files\Base + + + Source Files\Base + + + Source Files + + + Source Files\Base + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Resource Files + + + Header Files\DuiEx + + + Header Files\DuiEx + + + Header Files\Base + + + Header Files\Base + + + Header Files\Base + + + Header Files\Base + + + Header Files\Redis + + + Header Files\Redis + + + Header Files\Redis + + + Header Files\Redis + + + Header Files\Redis + + + Header Files\Redis + + + Header Files\Redis + + + Header Files\Redis + + + Header Files\Redis + + + Header Files\Redis + + + Header Files\Base + + + Header Files\Base + + + Header Files\Base + + + Header Files\Base + + + Header Files + + + Header Files + + + Header Files\Base + + + + + Resource Files + + + + + Resource Files + + \ No newline at end of file diff --git a/RedisStudio/StdAfx.cpp b/RedisStudio/StdAfx.cpp index 7cb3b45..1a5df3a 100644 --- a/RedisStudio/StdAfx.cpp +++ b/RedisStudio/StdAfx.cpp @@ -1,15 +1,15 @@ -// stdafx.cpp : source file that includes just the standard includes -// App.pch will be the pre-compiled header -// stdafx.obj will contain the pre-compiled type information - -#include "stdafx.h" - -#if defined _M_IX86 -#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"") -#elif defined _M_IA64 -#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"") -#elif defined _M_X64 -#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"") -#else -#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") -#endif +// stdafx.cpp : source file that includes just the standard includes +// App.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + +#if defined _M_IX86 +#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"") +#elif defined _M_IA64 +#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"") +#elif defined _M_X64 +#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"") +#else +#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") +#endif diff --git a/RedisStudio/StdAfx.h b/RedisStudio/StdAfx.h index 4f6a281..a28fd5c 100644 --- a/RedisStudio/StdAfx.h +++ b/RedisStudio/StdAfx.h @@ -1,35 +1,35 @@ - -#if !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_) -#define AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_ - -#pragma once - -#define WIN32_LEAN_AND_MEAN -#define _CRT_SECURE_NO_DEPRECATE - -#include -#include -#include - -#include "..\DuiLib\UIlib.h" - -using namespace DuiLib; - -//#ifdef _DEBUG -//# ifdef _UNICODE -//# pragma comment(lib, "..\\bin\\DuiLib.lib") -//# else -//# pragma comment(lib, "..\\bin\\DuiLib.lib") -//# endif -//#else -//# ifdef _UNICODE -//# pragma comment(lib, "..\\bin\\DuiLib.lib") -//# else -//# pragma comment(lib, "..\\bin\\DuiLib.lib") -//# endif -//#endif - -//{{AFX_INSERT_LOCATION}} -// Microsoft Visual C++ will insert additional declarations immediately before the previous line. - -#endif // !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_) + +#if !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_) +#define AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_ + +#pragma once + +#define WIN32_LEAN_AND_MEAN +#define _CRT_SECURE_NO_DEPRECATE + +#include +#include +#include + +#include "..\DuiLib\UIlib.h" + +using namespace DuiLib; + +//#ifdef _DEBUG +//# ifdef _UNICODE +//# pragma comment(lib, "..\\bin\\DuiLib.lib") +//# else +//# pragma comment(lib, "..\\bin\\DuiLib.lib") +//# endif +//#else +//# ifdef _UNICODE +//# pragma comment(lib, "..\\bin\\DuiLib.lib") +//# else +//# pragma comment(lib, "..\\bin\\DuiLib.lib") +//# endif +//#endif + +//{{AFX_INSERT_LOCATION}} +// Microsoft Visual C++ will insert additional declarations immediately before the previous line. + +#endif // !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_) diff --git a/RedisStudio/UserMessage.cpp b/RedisStudio/UserMessage.cpp index 509c0a5..389b8b4 100644 --- a/RedisStudio/UserMessage.cpp +++ b/RedisStudio/UserMessage.cpp @@ -1,22 +1,21 @@ -#include "StdAfx.h" -#include "UserMessage.h" - -#include "MessageBoxWhd.h" - -void UserMessageBox(HWND hWnd, - UINT ErrorCode, - LPCTSTR lpExMsg, - UINT uType) -{ - MessageBoxWhd::MsgType type = MessageBoxWhd::Info; - if (uType == MB_ICONWARNING) type = MessageBoxWhd::Warn; - else if (uType == MB_ICONERROR) type = MessageBoxWhd::Error; - else if (uType == MB_ICONINFORMATION) type = MessageBoxWhd::Info; - - MessageBoxWhd* pWhd = new MessageBoxWhd(type, ErrorCode, lpExMsg); - if( pWhd == NULL ) { return; } - pWhd->Create(hWnd, NULL, UI_CLASSSTYLE_DIALOG, 0, 0, 0, 0, 0, NULL); - pWhd->CenterWindow(); - pWhd->ShowModal(); - +#include "StdAfx.h" +#include "UserMessage.h" + +#include "MessageBoxWhd.h" + +void UserMessageBox(HWND hWnd, + UINT ErrorCode, + LPCTSTR lpExMsg, + UINT uType) +{ + MessageBoxWhd::MsgType type = MessageBoxWhd::Info; + if (uType == MB_ICONWARNING) type = MessageBoxWhd::Warn; + else if (uType == MB_ICONERROR) type = MessageBoxWhd::Error; + else if (uType == MB_ICONINFORMATION) type = MessageBoxWhd::Info; + + MessageBoxWhd* pWhd = new MessageBoxWhd(type, ErrorCode, lpExMsg); + if( pWhd == NULL ) { return; } + pWhd->Create(hWnd, NULL, UI_CLASSSTYLE_DIALOG, 0, 0, 0, 0, 0, NULL); + pWhd->CenterWindow(); + pWhd->ShowModal(); } \ No newline at end of file diff --git a/RedisStudio/UserMessage.h b/RedisStudio/UserMessage.h index d5eaaa2..7758414 100644 --- a/RedisStudio/UserMessage.h +++ b/RedisStudio/UserMessage.h @@ -1,22 +1,25 @@ -#pragma once - -#define WM_USER_CONNECTED WM_USER + 1 // ɹ -#define WM_USER_UNCONNECT WM_USER + 2 // ʧ -#define WM_USER_CONNECTING WM_USER + 3 // ʧ - - -#define WM_USER_INFOUPDATE WM_USER + 5 // info get - - -#define WM_USER_TREEADD WM_USER + 10 // -#define WM_USER_DATAADD WM_USER + 11 // - -#define WM_USER_DATAVERBOSE WM_USER + 21 - -#define WM_USER_MENU_KEYDEL WM_USER + 31 -#define WM_USER_MENU_KEYRENAME WM_USER + 32 - -void UserMessageBox(HWND hWnd, - UINT ErrorCode, - LPCTSTR lpExMsg, +#pragma once + +#define WM_USER_UPDATE WM_USER + 1 + +#define WM_USER_CONNECTED WM_USER + 11 // 成功连接 +#define WM_USER_UNCONNECT WM_USER + 12 // 失败连接 +#define WM_USER_CONNECTING WM_USER + 13 // 失败连接 + + +#define WM_USER_INFOUPDATE WM_USER + 15 // info get + + +#define WM_USER_TREEADD WM_USER + 20 // +#define WM_USER_DATAADD WM_USER + 21 // + +#define WM_USER_TREEVERBOSE WM_USER + 30 +#define WM_USER_DATAVERBOSE WM_USER + 31 + +#define WM_USER_MENU_KEYDEL WM_USER + 41 +#define WM_USER_MENU_KEYRENAME WM_USER + 42 + +void UserMessageBox(HWND hWnd, + UINT ErrorCode, + LPCTSTR lpExMsg, UINT uType); \ No newline at end of file diff --git a/RedisStudio/Version.h b/RedisStudio/Version.h new file mode 100644 index 0000000..30142c8 --- /dev/null +++ b/RedisStudio/Version.h @@ -0,0 +1,3 @@ +#pragma once + +#define VERSION "0.1.2" diff --git a/RedisStudio/resource.h b/RedisStudio/resource.h index 68d771b..0148308 100644 --- a/RedisStudio/resource.h +++ b/RedisStudio/resource.h @@ -1,16 +1,16 @@ -//{{NO_DEPENDENCIES}} -// Microsoft Visual C++ generated include file. -// Used by RedisStudio.rc -// -#define IDI_ICON1 101 - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 102 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1001 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by RedisStudio.rc +// +#define IDI_ICON1 101 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 102 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1001 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/Skin/skin-en/MessageBox.xml b/Skin/skin-en/MessageBox.xml index 59981c9..3b3eb16 100644 --- a/Skin/skin-en/MessageBox.xml +++ b/Skin/skin-en/MessageBox.xml @@ -1,7 +1,7 @@ - + - + - - + diff --git a/Skin/skin-en/RedisData.xml b/Skin/skin-en/RedisData.xml index 28e18dd..ab260f2 100644 --- a/Skin/skin-en/RedisData.xml +++ b/Skin/skin-en/RedisData.xml @@ -38,7 +38,13 @@ - + + + + + + + diff --git a/Skin/skin-en/skin.xml b/Skin/skin-en/skin.xml index bb2eee3..91655ed 100644 --- a/Skin/skin-en/skin.xml +++ b/Skin/skin-en/skin.xml @@ -71,7 +71,7 @@ - + diff --git a/Skin/skin-zh/RedisData.xml b/Skin/skin-zh/RedisData.xml index 489c427..ab9d43b 100644 --- a/Skin/skin-zh/RedisData.xml +++ b/Skin/skin-zh/RedisData.xml @@ -38,6 +38,13 @@ + + + + + + + diff --git a/package/redis.png b/docs/redis.png similarity index 100% rename from package/redis.png rename to docs/redis.png diff --git a/package/RedisStudio-V0.1.0.zip b/package/RedisStudio-V0.1.0.zip deleted file mode 100644 index 5fcb330..0000000 Binary files a/package/RedisStudio-V0.1.0.zip and /dev/null differ