summaryrefslogtreecommitdiff
path: root/plugins/updater/popups.cpp
diff options
context:
space:
mode:
authorVadim Dashevskiy <watcherhd@gmail.com>2012-05-15 10:38:20 +0000
committerVadim Dashevskiy <watcherhd@gmail.com>2012-05-15 10:38:20 +0000
commit48540940b6c28bb4378abfeb500ec45a625b37b6 (patch)
tree2ef294c0763e802f91d868bdef4229b6868527de /plugins/updater/popups.cpp
parent5c350913f011e119127baeb32a6aedeb4f0d33bc (diff)
initial commit
git-svn-id: http://svn.miranda-ng.org/main/trunk@2 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/updater/popups.cpp')
-rw-r--r--plugins/updater/popups.cpp212
1 files changed, 212 insertions, 0 deletions
diff --git a/plugins/updater/popups.cpp b/plugins/updater/popups.cpp
new file mode 100644
index 0000000000..079254b8ae
--- /dev/null
+++ b/plugins/updater/popups.cpp
@@ -0,0 +1,212 @@
+#include "common.h"
+#include "popups.h"
+
+HWND hwndPop;
+HANDLE hEventPop;
+bool pop_cancelled;
+bool bPopupsEnabled;
+
+typedef struct
+{
+ unsigned flags;
+ HICON hIcon;
+} PopupDataType;
+
+
+LRESULT CALLBACK NullWindowProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
+{
+ switch( message ) {
+ case UM_INITPOPUP:
+ {
+ PopupDataType* popup = (PopupDataType*)CallService(MS_POPUP_GETPLUGINDATA, (WPARAM)hWnd,0);
+ if (popup->flags & POPFLAG_SAVEHWND) hwndPop = hWnd;
+ }
+ return 0;
+ case WMU_CLOSEPOP:
+ SetEvent(hEventPop);
+ PUDeletePopUp( hWnd );
+ return TRUE;
+
+ case WM_COMMAND:
+ {
+ PopupDataType* popup = (PopupDataType*)CallService(MS_POPUP_GETPLUGINDATA, (WPARAM)hWnd,0);
+ if (popup->flags & POPFLAG_SAVEHWND) pop_cancelled = false;
+ }
+ SetEvent(hEventPop);
+ PUDeletePopUp( hWnd );
+ return TRUE;
+
+ case WM_CONTEXTMENU:
+ {
+ PopupDataType* popup = (PopupDataType*)CallService(MS_POPUP_GETPLUGINDATA, (WPARAM)hWnd,0);
+ if (popup->flags & POPFLAG_SAVEHWND) pop_cancelled = true;
+ }
+ SetEvent(hEventPop);
+ PUDeletePopUp( hWnd );
+ return TRUE;
+
+ case UM_FREEPLUGINDATA: {
+ PopupDataType* popup = (PopupDataType*)CallService(MS_POPUP_GETPLUGINDATA, (WPARAM)hWnd, 0);
+ if ((INT_PTR)popup != CALLSERVICE_NOTFOUND)
+ {
+ if (popup->flags & POPFLAG_SAVEHWND) hwndPop = 0;
+ if (popup->hIcon) ReleaseIconEx(popup->hIcon);
+ mir_free(popup);
+ }
+ return TRUE;
+ }
+ }
+
+ return DefWindowProc(hWnd, message, wParam, lParam);
+}
+
+void __stdcall sttPopupProc( void* dwParam )
+{
+ POPUPDATAT* ppd = ( POPUPDATAT* )dwParam;
+ CallService( MS_POPUP_ADDPOPUPT, ( WPARAM )ppd, 0 );
+ mir_free( ppd );
+}
+
+void ShowPopup( HANDLE hContact, const TCHAR* line1, const TCHAR* line2, int flags, int timeout )
+{
+ if(CallService(MS_SYSTEM_TERMINATED, 0, 0)) return;
+
+ if ( !ServiceExists( MS_POPUP_ADDPOPUPT )) {
+ TCHAR title[256];
+ mir_sntprintf(title, SIZEOF(title), _T("%s Message"), _T(MODULE));
+
+ if(line1 && line2) {
+ size_t len = _tcslen(line1) + _tcslen(line2) + 1;
+ TCHAR *message = (TCHAR*)alloca(len * sizeof(TCHAR)); // newline and null terminator
+ mir_sntprintf(message, len, _T("%s\n%s"), line1, line2);
+ MessageBox( NULL, message, title, MB_OK | MB_ICONINFORMATION );
+ } else if(line1) {
+ MessageBox( NULL, line1, title, MB_OK | MB_ICONINFORMATION );
+ } else if(line2) {
+ MessageBox( NULL, line2, title, MB_OK | MB_ICONINFORMATION );
+ }
+ return;
+ }
+
+ SetEvent(hEventPop);
+ ResetEvent(hEventPop);
+
+ if(ServiceExists(MS_POPUP_ADDPOPUPCLASS))
+ {
+ POPUPDATACLASS d = {sizeof(d), "updaterpopups"};
+ d.ptszTitle = line1;
+ d.ptszText = line2;
+ d.PluginData = mir_calloc(sizeof(PopupDataType));
+ ((PopupDataType*)d.PluginData)->flags = flags;
+ CallService(MS_POPUP_ADDPOPUPCLASS, 0, (LPARAM)&d);
+ }
+ else
+ {
+ POPUPDATAT* ppd = ( POPUPDATAT* )mir_calloc( sizeof( POPUPDATAT ));
+
+ ppd->lchContact = hContact;
+ ppd->lchIcon = LoadIconEx(I_CHKUPD);
+
+ if (line1 && line2)
+ {
+ _tcscpy( ppd->lptzContactName, line1 );
+ _tcscpy( ppd->lptzText, line2 );
+ }
+ else if (line1)
+ _tcscpy( ppd->lptzText, line1 );
+ else if (line2)
+ _tcscpy( ppd->lptzText, line2 );
+
+ if (options.set_colours)
+ {
+ ppd->colorBack = options.bkCol;
+ ppd->colorText = options.textCol;
+ }
+ else
+ {
+ //ppd->colorText = 0x00FFFFFF;
+ ppd->colorText = 0;
+ //ppd->colorBack = POPUP_USE_SKINNED_BG;
+ ppd->colorBack = 0;
+ }
+
+ ppd->iSeconds = timeout;
+
+ ppd->PluginWindowProc = ( WNDPROC )NullWindowProc;
+ ppd->PluginData = mir_calloc(sizeof(PopupDataType));
+ ((PopupDataType*)ppd->PluginData)->flags = flags;
+ ((PopupDataType*)ppd->PluginData)->hIcon = ppd->lchIcon;
+
+ CallFunctionAsync( sttPopupProc , ppd );
+ }
+}
+
+void ShowWarning(TCHAR *msg)
+{
+ static const TCHAR title[512] = _T(MODULE) _T(" Warning");
+
+ if(ServiceExists(MS_POPUP_SHOWMESSAGE))
+ {
+ TCHAR message[1024];
+ mir_sntprintf(message, SIZEOF(message), _T("%s: %s"), _T(MODULE), msg);
+ ShowPopup(0, title, message, 0, 10);
+ //PUShowMessage(message, SM_WARNING);
+ }
+ else
+ MessageBox(0, msg, title, MB_OK | MB_ICONWARNING);
+}
+
+void ShowError(TCHAR *msg)
+{
+ static const TCHAR title[512] = _T(MODULE) _T(" Error");
+ NLog(msg);
+
+ if(ServiceExists(MS_POPUP_SHOWMESSAGE))
+ {
+ TCHAR message[1024];
+ mir_sntprintf(message, SIZEOF(message), _T("%s: %s"), _T(MODULE), msg);
+ //PUShowMessage(message, SM_WARNING);
+ ShowPopup(0, title, message, 0, 10);
+ }
+ else
+ MessageBox(0, msg, title, MB_OK | MB_ICONERROR);
+}
+
+void ChangePopupText(HWND hwnd, TCHAR *text)
+{
+ CallService(MS_POPUP_CHANGETEXTT, (WPARAM)hwnd, (LPARAM)text);
+}
+
+bool ArePopupsEnabled()
+{
+ return bPopupsEnabled;
+}
+
+HICON hPopupIcon;
+void InitPopups() {
+ bPopupsEnabled = ServiceExists(MS_POPUP_ADDPOPUPT) != 0;
+
+ hEventPop = CreateEvent( NULL, TRUE, FALSE, NULL );
+
+ if (ServiceExists(MS_POPUP_REGISTERCLASS))
+ {
+ hPopupIcon = LoadIconEx(I_CHKUPD);
+ POPUPCLASS test = {0};
+ test.cbSize = sizeof(test);
+ test.flags = PCF_TCHAR;
+ test.hIcon = hPopupIcon;
+ test.iSeconds = -1;
+ test.ptszDescription = TranslateT(MODULE);
+ test.pszName = "updaterpopups";
+ test.PluginWindowProc = NullWindowProc;
+ CallService(MS_POPUP_REGISTERCLASS, 0, (WPARAM)&test);
+ }
+}
+
+void DeinitPopups()
+{
+ CloseHandle(hEventPop);
+ ReleaseIconEx(hPopupIcon);
+}
+
+