diff options
author | Dioksin <dioksin@ua.fm> | 2016-10-28 10:26:18 +0300 |
---|---|---|
committer | Dioksin <dioksin@ua.fm> | 2016-10-28 10:26:18 +0300 |
commit | 90f21502c21e0cff38ee961b1bc7c4d96edba461 (patch) | |
tree | eeb316a387de62aff88757bf209a3dee848b79c7 /plugins/Quotes/src | |
parent | fc47883d5726ae724d764a8600fbfd56c79893e0 (diff) |
Chart was added to Quotes plugin
Diffstat (limited to 'plugins/Quotes/src')
-rw-r--r-- | plugins/Quotes/src/Forex.cpp | 1 | ||||
-rw-r--r-- | plugins/Quotes/src/QuoteChart.cpp | 395 | ||||
-rw-r--r-- | plugins/Quotes/src/QuoteChart.h | 4 | ||||
-rw-r--r-- | plugins/Quotes/src/resource.h | 9 | ||||
-rw-r--r-- | plugins/Quotes/src/stdafx.h | 1 | ||||
-rw-r--r-- | plugins/Quotes/src/version.h | 2 |
6 files changed, 72 insertions, 340 deletions
diff --git a/plugins/Quotes/src/Forex.cpp b/plugins/Quotes/src/Forex.cpp index 6e353f15e6..bedd6e2e14 100644 --- a/plugins/Quotes/src/Forex.cpp +++ b/plugins/Quotes/src/Forex.cpp @@ -146,7 +146,6 @@ void InitMenu() #ifdef CHART_IMPLEMENT
SET_UID(mi, 0x65da7256, 0x43a2, 0x4857, 0xac, 0x52, 0x1c, 0xb7, 0xff, 0xd7, 0x96, 0xfa);
mi.name.w = LPGENW("Chart...");
- mi.popupPosition = 2;
mi.hIcolibItem = NULL;
mi.pszService = "Quotes/Chart";
g_hMenuChart = Menu_AddContactMenuItem(&mi, QUOTES_PROTOCOL_NAME);
diff --git a/plugins/Quotes/src/QuoteChart.cpp b/plugins/Quotes/src/QuoteChart.cpp index 7075b0c5b6..16c6bfc1da 100644 --- a/plugins/Quotes/src/QuoteChart.cpp +++ b/plugins/Quotes/src/QuoteChart.cpp @@ -2,360 +2,99 @@ #ifdef CHART_IMPLEMENT
-#define WINDOW_PREFIX "Quotes Chart_"
-#define CHART_CTRL_CLASS L"DioksinChart"
-
-struct CTimeConvert
+namespace
{
- static double Convert(const boost::posix_time::time_duration& v)
- {
- return boost::numeric_cast<double>(v.ticks());
- }
-
- static tstring ToString(const boost::posix_time::ptime& v)
+ class CMyJob : private boost::noncopyable
{
- tostringstream k;
- k.imbue(std::locale(GetSystemLocale(), new ttime_facet(L"%d/%m/%y %H:%M:%S")));
- k << v;
- return k.str();
- }
-};
-
-typedef CChart<boost::posix_time::ptime, double, CTimeConvert> TChart;
-
-inline TChart* get_chart_ptr(HWND hWnd)
-{
- TChart* pChart = reinterpret_cast<TChart*>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
- return pChart;
-}
-
-bool read_log_file(MCONTACT hContact, TChart& rChart)
-{
- tstring sLogFileName = GetContactLogFileName(hContact);
- if (false == sLogFileName.empty()) {
- std::locale loc(GetSystemLocale(), new ttime_input_facet(L"%d.%m.%y %H:%M:%S"));
- boost::posix_time::ptime oDateTime;
- double dRate;
-
- tifstream file(sLogFileName.c_str());
- file.imbue(loc);
- while ((false == file.fail()) && (false == file.eof())) {
- tstring sLine;
- std::getline(file, sLine);
-
- tistringstream line(sLine);
- line.imbue(loc);
-
- tstring sName;
- std::getline(line, sName, '\t');
- line >> oDateTime >> dRate;
- if ((false == line.fail()) && (true == line.eof())) {
- rChart.AddValue(oDateTime, dRate);
- }
- }
-
- return true;
- }
- return false;
-}
-
-
-enum
-{
- ID_CHART = 0x1969,
-
- srcLogFile = 0,
- srcHistory = 1,
-
- filterAll = 0,
- filterLastDay = 1,
- filterLastWeek = 2,
- filterLastMonth = 3,
- filterLastYear = 4,
- filterUserDefined = 5,
-
- CHART_SET_SOURCE = WM_USER + 1,
- CHART_SET_FILTER = WM_USER + 2,
-};
-
-LRESULT CALLBACK ChartWndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
-{
- switch (msg) {
- case WM_CREATE:
+ private:
+ CMyJob(LPCTSTR pszName = nullptr): m_hJob(::CreateJobObject(nullptr,pszName))
{
- CREATESTRUCT* pCS = reinterpret_cast<CREATESTRUCT*>(lp);
- MCONTACT hContact = reinterpret_cast<HANDLE>(pCS->lpCreateParams);
-
- TChart* pChart = new TChart;
- read_log_file(hContact, *pChart);
+ if(m_hJob)
+ {
+ JOBOBJECT_EXTENDED_LIMIT_INFORMATION jeli = { 0 };
+ jeli.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
+ if(0 == ::SetInformationJobObject(m_hJob,JobObjectExtendedLimitInformation,&jeli,sizeof(jeli)))
+ {
+#ifdef OUTPUT_TO_DEBUG_VIEWER
+ ::OutputDebugString(_T("Error occurred during the job initialization\n"));
+#endif
+ }
+ }
- ::SetWindowLongPtr(hWnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(pChart));
}
- return 0;
-
- case CHART_SET_SOURCE:
- break;
-
- case CHART_SET_FILTER:
- break;
-
- case WM_SIZE:
+ ~CMyJob()
{
- TChart* pChart = get_chart_ptr(hWnd);
- pChart->SetRect(0, 0, LOWORD(lp), HIWORD(lp));
- }
- return 0;
-
- case WM_PAINT:
- if (TRUE == ::GetUpdateRect(hWnd, NULL, FALSE)) {
- PAINTSTRUCT ps;
- HDC hdc = ::BeginPaint(hWnd, &ps);
- if (NULL != hdc) {
- TChart* pChart = get_chart_ptr(hWnd);
- pChart->Draw(hdc);
- ::EndPaint(hWnd, &ps);
+ if(m_hJob)
+ {
+ ::CloseHandle(m_hJob);
}
}
- return 0;
- case WM_DESTROY:
+ public:
+ static CMyJob& GetInstance()
{
- TChart* pChart = get_chart_ptr(hWnd);
- ::SetWindowLongPtr(hWnd, GWLP_USERDATA, 0);
- delete pChart;
+ static CMyJob g_job(_T("MirandaJob_E12D5E9C_00E7_4FFA_9831_F35E45C6EBDA"));
+ return g_job;
}
- break;
- }
-
- return ::DefWindowProc(hWnd, msg, wp, lp);
-}
-
-void register_chart_control()
-{
- static bool g_bRegister = false;
- if (g_bRegister) {
- return;
- }
-
- WNDCLASS wc;
-
- wc.style = CS_HREDRAW | CS_VREDRAW;
- wc.lpfnWndProc = ChartWndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = CModuleInfo::GetInstance().GetModuleHandle();
- wc.hIcon = NULL;
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = static_cast<HBRUSH>(::GetStockObject(WHITE_BRUSH));
- wc.lpszMenuName = NULL;
- wc.lpszClassName = CHART_CTRL_CLASS;
-
- if (RegisterClass(&wc)) {
- g_bRegister = true;
- }
-}
-
-
-bool screen_2_client(HWND hWnd, LPRECT pRect)
-{
- POINT pt;
- pt.x = pRect->left;
- pt.y = pRect->top;
- bool bResult = TRUE == ::ScreenToClient(hWnd, &pt);
- pRect->left = pt.x;
- pRect->top = pt.y;
- pt.x = pRect->right;
- pt.y = pRect->bottom;
- bResult |= TRUE == ::ScreenToClient(hWnd, &pt);
- pRect->right = pt.x;
- pRect->bottom = pt.y;
- return bResult;
-}
-inline HANDLE get_contact(HWND hWnd)
-{
- MCONTACT hContact = reinterpret_cast<HANDLE>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
- return hContact;
-}
-
-void update_filter_controls(HWND hDlg)
-{
- int nSel = ::SendDlgItemMessage(hDlg, IDC_COMBO_FILTER, CB_GETCURSEL, 0, 0);
-
- ::ShowWindow(::GetDlgItem(hDlg, IDC_EDIT_FROM), (filterUserDefined == nSel) ? SW_SHOW : SW_HIDE);
- ::ShowWindow(::GetDlgItem(hDlg, IDC_EDIT_TO), (filterUserDefined == nSel) ? SW_SHOW : SW_HIDE);
-}
-
-INT_PTR CALLBACK ChartDlgProc(HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
-{
- switch (msg) {
- case WM_INITDIALOG:
- TranslateDialogDefault(hDlg);
- {
- MCONTACT hContact = reinterpret_cast<HANDLE>(lp);
-
- tstring sName = get_window_text(hDlg);
- sName += L" - ";
- sName += GetContactName(hContact);
- ::SetWindowText(hDlg, sName.c_str());
-
- HANDLE hWL = CModuleInfo::GetInstance().GetWindowList(WINDOW_PREFIX, false);
- assert(hWL);
- WindowList_Add(hWL, hDlg, hContact);
-
- ::SetWindowLongPtr(hDlg, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(hContact));
-
- static LPCTSTR szSources[] = { LPGENW("Log File"), LPGENW("Miranda's History") };
- static LPCTSTR szFilters[] = { LPGENW("All"), LPGENW("Last Day"), LPGENW("Last Week"), LPGENW("Last Month"), LPGENW("Last Year"), LPGENW("User-Defined") };
-
- for (int i = 0; i < sizeof(szSources) / sizeof(szSources[0]); ++i) {
- LPCTSTR p = TranslateW(szSources[i]);
- ::SendDlgItemMessage(hDlg, IDC_COMBO_DATA_SOURCE, CB_INSERTSTRING, -1, reinterpret_cast<LPARAM>(p));
- }
-
- int nSel = db_get_b(hContact, QUOTES_PROTOCOL_NAME, "Chart_Source", srcLogFile);
- ::SendDlgItemMessage(hDlg, IDC_COMBO_DATA_SOURCE, CB_SETCURSEL, nSel, 0);
-
- for (int i = 0; i < sizeof(szFilters) / sizeof(szFilters[0]); ++i) {
- LPCTSTR p = TranslateW(szSources[i]);
- ::SendDlgItemMessage(hDlg, IDC_COMBO_FILTER, CB_INSERTSTRING, -1, reinterpret_cast<LPARAM>(szFilters[i]));
- }
-
- nSel = db_get_b(hContact, QUOTES_PROTOCOL_NAME, "Chart_Filter", filterAll);
- ::SendDlgItemMessage(hDlg, IDC_COMBO_FILTER, CB_SETCURSEL, nSel, 0);
-
- update_filter_controls(hDlg);
-
- register_chart_control();
- HWND hwndImage = ::GetDlgItem(hDlg, IDC_STATIC_IMAGE);
- RECT rcImage;
- ::GetWindowRect(hwndImage, &rcImage);
- screen_2_client(hDlg, &rcImage);
- //BOOL bResult = ShowWindow(hwndImage,SW_HIDE);
- //assert(bResult);
-
- HWND hChart = ::CreateWindowEx(0L, CHART_CTRL_CLASS, NULL, WS_CHILDWINDOW | WS_VISIBLE,
- rcImage.left, rcImage.top, rcImage.right - rcImage.left, rcImage.bottom - rcImage.top,
- hDlg, reinterpret_cast<HMENU>(ID_CHART), CModuleInfo::GetInstance().GetModuleHandle(), hContact);
- assert(NULL != hChart);
-
- Utils_RestoreWindowPosition(hDlg, hContact, QUOTES_MODULE_NAME, WINDOW_PREFIX);
- BOOL bResult = ::ShowWindow(hDlg, SW_SHOW);
- assert(bResult);
- }
- return (TRUE);
- case WM_CLOSE:
+ bool AssignProcess(HANDLE hProcess)
{
- MCONTACT hContact = get_contact(hDlg);
- SetWindowLongPtr(hDlg, GWLP_USERDATA, 0);
-
- // save_options(hDlg,hContact);
-
- HANDLE hWL = CModuleInfo::GetInstance().GetWindowList(WINDOW_PREFIX, false);
- assert(hWL);
- WindowList_Remove(hWL, hDlg);
- Utils_SaveWindowPosition(hDlg, hContact, QUOTES_MODULE_NAME, WINDOW_PREFIX);
-
- HWND hwndChart = ::GetDlgItem(hDlg, ID_CHART);
- BOOL bResult = ::DestroyWindow(hwndChart);
- assert(bResult);
-
- ::EndDialog(hDlg, 0);
- }
- return (TRUE);
-
- case WM_COMMAND:
- switch (LOWORD(wp)) {
- case IDCANCEL:
- SendMessage(hDlg, WM_CLOSE, 0, 0);
- return (TRUE);
-
- case IDC_COMBO_FILTER:
- if (CBN_SELCHANGE == HIWORD(wp)) {
- ::SendDlgItemMessage(hDlg, ID_CHART, CHART_SET_FILTER, ::SendDlgItemMessage(hDlg, IDC_COMBO_FILTER, CB_GETCURSEL, 0, 0), 0);
- update_filter_controls(hDlg);
+ if(m_hJob && hProcess)
+ {
+ auto b = (TRUE == ::AssignProcessToJobObject(m_hJob,hProcess));
+ return b;
}
- break;
- case IDC_COMBO_DATA_SOURCE:
- if (CBN_SELCHANGE == HIWORD(wp))
- ::SendDlgItemMessage(hDlg, ID_CHART, CHART_SET_SOURCE, ::SendDlgItemMessage(hDlg, IDC_COMBO_DATA_SOURCE, CB_GETCURSEL, 0, 0), 0);
- break;
- }
- return (FALSE);
- case WM_NOTIFY:
- {
- LPNMHDR pNMHDR = reinterpret_cast<LPNMHDR>(lp);
- switch (pNMHDR->code) {
- case NM_CLICK:
- if (IDC_SYSLINK_PROVIDER == wp) {
- PNMLINK pNMLink = reinterpret_cast<PNMLINK>(pNMHDR);
- ::ShellExecute(hDlg, L"open", pNMLink->item.szUrl, NULL, NULL, SW_SHOWNORMAL);
- }
- break;
- }
+ return false;
}
- break;
-
- case WM_SIZE:
- {
- enum { INDENT = 7 };
-
- int nWidth = LOWORD(lp);
- int nHeight = HIWORD(lp);
-
- HWND hwndChart = GetDlgItem(hDlg, ID_CHART);
- HWND hwndLink = GetDlgItem(hDlg, IDC_SYSLINK_PROVIDER);
- HWND hwndClose = GetDlgItem(hDlg, IDCANCEL);
- RECT rcDlg;
- GetClientRect(hDlg, &rcDlg);
+ private:
+ HANDLE m_hJob;
+ };
- RECT rcChart;
- GetWindowRect(hwndChart, &rcChart);
- screen_2_client(hDlg, &rcChart);
-
- RECT rcLink;
- GetWindowRect(hwndLink, &rcLink);
- screen_2_client(hDlg, &rcLink);
- SetWindowPos(hwndLink, NULL, rcDlg.left + INDENT,
- rcDlg.bottom - INDENT - (rcLink.bottom - rcLink.top),
- 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
-
- RECT rcClose;
- GetWindowRect(hwndClose, &rcClose);
- screen_2_client(hDlg, &rcClose);
- SetWindowPos(hwndClose, NULL, rcDlg.right - INDENT - (rcClose.right - rcClose.left),
- rcDlg.bottom - INDENT - (rcClose.bottom - rcClose.top),
- 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
-
- SetWindowPos(hwndChart, NULL, rcDlg.left + INDENT,
- rcChart.top,
- (nWidth - INDENT * 2),
- nHeight - (rcClose.bottom - rcClose.top) - INDENT * 2 - rcChart.top,
- SWP_NOZORDER | SWP_NOACTIVATE);
-
- }
- break;
- }
- return (FALSE);
}
-INT_PTR QuotesMenu_Chart(WPARAM wp, LPARAM lp)
+INT_PTR QuotesMenu_Chart(WPARAM wp, LPARAM /*lp*/)
{
- MCONTACT hContact = reinterpret_cast<HANDLE>(wp);
+#ifdef _UNICODE
+ MCONTACT hContact = static_cast<MCONTACT>(wp);
if (NULL == hContact)
return 0;
- HANDLE hWL = CModuleInfo::GetInstance().GetWindowList(WINDOW_PREFIX, true);
- assert(hWL);
- HWND hWnd = WindowList_Find(hWL, hContact);
- if (NULL != hWnd) {
- SetForegroundWindow(hWnd);
- SetFocus(hWnd);
+ auto sLogFileName = GetContactLogFileName(hContact);
+
+ if(auto hWnd = ::FindWindow(nullptr,_T("Miranda Quotes Chart")))
+ {
+ COPYDATASTRUCT copydata_struct;
+ copydata_struct.cbData = static_cast<DWORD>(sLogFileName.size()*sizeof(TCHAR));
+ copydata_struct.lpData = const_cast<void*>(static_cast<const void*>(sLogFileName.c_str()));
+ copydata_struct.dwData = 0x1945;
+
+ SendMessage(hWnd,WM_COPYDATA,0,reinterpret_cast<LPARAM>(©data_struct));
}
- else CreateDialogParam(CModuleInfo::GetModuleHandle(), MAKEINTRESOURCE(IDD_DUKASCOPY_CHART), NULL, ChartDlgProc, reinterpret_cast<LPARAM>(hContact));
+ else
+ {
+ STARTUPINFO si;
+ PROCESS_INFORMATION pi;
+ ZeroMemory(&si, sizeof(si));
+ si.cb = sizeof(si);
+ si.dwFlags = STARTF_USESHOWWINDOW;
+ si.wShowWindow = SW_SHOWNORMAL;
+ ZeroMemory(&pi, sizeof(pi));
+
+ auto sCmdLine = CreateFilePath(_T("QuotesChart.exe"));
+ sCmdLine += _T(" \"");
+ sCmdLine += sLogFileName;
+ sCmdLine += _T("\"");
+ if(::CreateProcess(nullptr,const_cast<LPTSTR>(sCmdLine.c_str()),nullptr,nullptr,FALSE,0,nullptr,nullptr,&si,&pi))
+ {
+ CMyJob::GetInstance().AssignProcess(pi.hProcess);
+ ::CloseHandle(pi.hThread);
+ ::CloseHandle(pi.hProcess);
+ }
+ }
+#endif
return 0;
}
diff --git a/plugins/Quotes/src/QuoteChart.h b/plugins/Quotes/src/QuoteChart.h index bbbc473b7b..baaf6826b8 100644 --- a/plugins/Quotes/src/QuoteChart.h +++ b/plugins/Quotes/src/QuoteChart.h @@ -1,10 +1,10 @@ #ifndef __39BE8775_A837_494f_925C_0ABF7910F238_QuoteChart_h__
#define __39BE8775_A837_494f_925C_0ABF7910F238_QuoteChart_h__
-#ifdef CHART_IMPLEMENT
-
#pragma once
+#ifdef CHART_IMPLEMENT
+
INT_PTR QuotesMenu_Chart(WPARAM wp, LPARAM lp);
#endif
diff --git a/plugins/Quotes/src/resource.h b/plugins/Quotes/src/resource.h index 883d45b747..d1c78c3a60 100644 --- a/plugins/Quotes/src/resource.h +++ b/plugins/Quotes/src/resource.h @@ -1,6 +1,6 @@ //{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
-// Used by C:\Code\My code\Miranda NG\plugins\Quotes\res\Forex.rc
+// Used by C:\Code\My code\MirandaNG\plugins\Quotes\res\Forex.rc
//
#define IDD_DIALOG_ECONOMIC_RATES 101
#define IDI_ICON_MAIN 102
@@ -14,8 +14,6 @@ #define IDI_ICON_NOTCHANGED 116
#define IDD_CURRENCY_CONVERTER 116
#define IDI_ICON_CURRENCY_CONVERTER 117
-#define IDD_DUKASCOPY_CHART 117
-#define IDD_CHART 117
#define IDD_DIALOG_QUOTE_INFO_1 118
#define IDI_ICON_REFRESH 118
#define IDD_DIALOG_OPT_FINANCE 119
@@ -71,7 +69,6 @@ #define IDC_BUTTON_LOG_FILE_DESCRIPTION2 1037
#define IDC_BUTTON_POPUP_FORMAT_DESCRIPTION 1037
#define IDC_EDIT_RESULT 1039
-#define IDC_STATIC_IMAGE 1056
#define IDC_EDIT_QUOTE 1059
#define IDC_BUTTON_SWAP 1060
#define IDC_BUTTON_ADVANCED_SETTINGS 1061
@@ -83,11 +80,7 @@ #define IDC_MFCCOLORBUTTON1 1066
#define IDC_CHECK1 1067
#define IDC_CHECK_DONT_USE_POPUPHISTORY 1067
-#define IDC_COMBO_DATA_SOURCE 1068
-#define IDC_COMBO_FILTER 1069
-#define IDC_EDIT_FROM 1070
#define IDC_EDIT_FROM2 1071
-#define IDC_EDIT_TO 1071
#define IDC_STATIC_PROVIDER_NAME 1071
#define IDC_DELAY 1072
#define IDC_EDIT1 1072
diff --git a/plugins/Quotes/src/stdafx.h b/plugins/Quotes/src/stdafx.h index fe0bde6b88..838c01b6e9 100644 --- a/plugins/Quotes/src/stdafx.h +++ b/plugins/Quotes/src/stdafx.h @@ -105,6 +105,7 @@ inline tstring quotes_a2t(const char* s) #include "QuotesProviderVisitorFormater.h"
#include "QuotesProviderVisitorTendency.h"
#include "QuotesProviderVisitorFormatSpecificator.h"
+#define CHART_IMPLEMENT
#ifdef CHART_IMPLEMENT
#include "QuoteChart.h"
#include "Chart.h"
diff --git a/plugins/Quotes/src/version.h b/plugins/Quotes/src/version.h index d70663520b..d4a5f05be4 100644 --- a/plugins/Quotes/src/version.h +++ b/plugins/Quotes/src/version.h @@ -1,7 +1,7 @@ #define __MAJOR_VERSION 0
#define __MINOR_VERSION 1
#define __RELEASE_NUM 0
-#define __BUILD_NUM 1
+#define __BUILD_NUM 101
#include <stdver.h>
|