From a9580df150d799246eaecbf3c1fb5cecf9f8ab49 Mon Sep 17 00:00:00 2001 From: Vadim Dashevskiy Date: Mon, 23 Jul 2012 13:49:28 +0000 Subject: SecureIM, SeenPlugin, SendSS, Sessions: changed folder structure git-svn-id: http://svn.miranda-ng.org/main/trunk@1122 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/SendScreenshotPlus/src/CSend.cpp | 416 +++++++ plugins/SendScreenshotPlus/src/CSend.h | 113 ++ plugins/SendScreenshotPlus/src/CSendEmail.cpp | 221 ++++ plugins/SendScreenshotPlus/src/CSendEmail.h | 63 ++ plugins/SendScreenshotPlus/src/CSendFTPFile.cpp | 99 ++ plugins/SendScreenshotPlus/src/CSendFTPFile.h | 59 + plugins/SendScreenshotPlus/src/CSendFile.cpp | 53 + plugins/SendScreenshotPlus/src/CSendFile.h | 55 + plugins/SendScreenshotPlus/src/CSendHTTPServer.cpp | 140 +++ plugins/SendScreenshotPlus/src/CSendHTTPServer.h | 67 ++ plugins/SendScreenshotPlus/src/CSendImageShack.cpp | 299 +++++ plugins/SendScreenshotPlus/src/CSendImageShack.h | 77 ++ plugins/SendScreenshotPlus/src/DevKey.h | 3 + plugins/SendScreenshotPlus/src/Main.cpp | 364 ++++++ plugins/SendScreenshotPlus/src/Main.h | 65 ++ plugins/SendScreenshotPlus/src/UAboutForm.cpp | 212 ++++ plugins/SendScreenshotPlus/src/UAboutForm.h | 69 ++ plugins/SendScreenshotPlus/src/UMainForm.cpp | 1180 ++++++++++++++++++++ plugins/SendScreenshotPlus/src/UMainForm.h | 157 +++ plugins/SendScreenshotPlus/src/Utils.cpp | 579 ++++++++++ plugins/SendScreenshotPlus/src/Utils.h | 81 ++ plugins/SendScreenshotPlus/src/ctrl_button.cpp | 699 ++++++++++++ plugins/SendScreenshotPlus/src/ctrl_button.h | 43 + plugins/SendScreenshotPlus/src/dlg_msgbox.cpp | 854 ++++++++++++++ plugins/SendScreenshotPlus/src/dlg_msgbox.h | 108 ++ plugins/SendScreenshotPlus/src/global.h | 189 ++++ plugins/SendScreenshotPlus/src/icons.h | 112 ++ plugins/SendScreenshotPlus/src/mir_icolib.cpp | 382 +++++++ plugins/SendScreenshotPlus/src/mir_icolib.h | 139 +++ plugins/SendScreenshotPlus/src/mir_string.cpp | 179 +++ plugins/SendScreenshotPlus/src/mir_string.h | 107 ++ plugins/SendScreenshotPlus/src/resource.h | 102 ++ plugins/SendScreenshotPlus/src/version.h | 45 + 33 files changed, 7331 insertions(+) create mode 100644 plugins/SendScreenshotPlus/src/CSend.cpp create mode 100644 plugins/SendScreenshotPlus/src/CSend.h create mode 100644 plugins/SendScreenshotPlus/src/CSendEmail.cpp create mode 100644 plugins/SendScreenshotPlus/src/CSendEmail.h create mode 100644 plugins/SendScreenshotPlus/src/CSendFTPFile.cpp create mode 100644 plugins/SendScreenshotPlus/src/CSendFTPFile.h create mode 100644 plugins/SendScreenshotPlus/src/CSendFile.cpp create mode 100644 plugins/SendScreenshotPlus/src/CSendFile.h create mode 100644 plugins/SendScreenshotPlus/src/CSendHTTPServer.cpp create mode 100644 plugins/SendScreenshotPlus/src/CSendHTTPServer.h create mode 100644 plugins/SendScreenshotPlus/src/CSendImageShack.cpp create mode 100644 plugins/SendScreenshotPlus/src/CSendImageShack.h create mode 100644 plugins/SendScreenshotPlus/src/DevKey.h create mode 100644 plugins/SendScreenshotPlus/src/Main.cpp create mode 100644 plugins/SendScreenshotPlus/src/Main.h create mode 100644 plugins/SendScreenshotPlus/src/UAboutForm.cpp create mode 100644 plugins/SendScreenshotPlus/src/UAboutForm.h create mode 100644 plugins/SendScreenshotPlus/src/UMainForm.cpp create mode 100644 plugins/SendScreenshotPlus/src/UMainForm.h create mode 100644 plugins/SendScreenshotPlus/src/Utils.cpp create mode 100644 plugins/SendScreenshotPlus/src/Utils.h create mode 100644 plugins/SendScreenshotPlus/src/ctrl_button.cpp create mode 100644 plugins/SendScreenshotPlus/src/ctrl_button.h create mode 100644 plugins/SendScreenshotPlus/src/dlg_msgbox.cpp create mode 100644 plugins/SendScreenshotPlus/src/dlg_msgbox.h create mode 100644 plugins/SendScreenshotPlus/src/global.h create mode 100644 plugins/SendScreenshotPlus/src/icons.h create mode 100644 plugins/SendScreenshotPlus/src/mir_icolib.cpp create mode 100644 plugins/SendScreenshotPlus/src/mir_icolib.h create mode 100644 plugins/SendScreenshotPlus/src/mir_string.cpp create mode 100644 plugins/SendScreenshotPlus/src/mir_string.h create mode 100644 plugins/SendScreenshotPlus/src/resource.h create mode 100644 plugins/SendScreenshotPlus/src/version.h (limited to 'plugins/SendScreenshotPlus/src') diff --git a/plugins/SendScreenshotPlus/src/CSend.cpp b/plugins/SendScreenshotPlus/src/CSend.cpp new file mode 100644 index 0000000000..4e48ecb2b4 --- /dev/null +++ b/plugins/SendScreenshotPlus/src/CSend.cpp @@ -0,0 +1,416 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* +Copyright 2000-2009 Miranda ICQ/IM project, + +This file is part of Send Screenshot Plus, a Miranda IM plugin. +Copyright (c) 2010 Ing.U.Horn + +Parts of this file based on original sorce code +(c) 2004-2006 Srgio Vieira Rolanski (portet from Borland C++) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +File name : $HeadURL: http://merlins-miranda.googlecode.com/svn/trunk/miranda/plugins/SendSSPlus/CSend.cpp $ +Revision : $Revision: 19 $ +Last change on : $Date: 2010-04-09 03:24:04 +0400 (Пт, 09 апр 2010) $ +Last change by : $Author: ing.u.horn $ + +*/ + +#include "CSend.h" + +//--------------------------------------------------------------------------- +CSend::CSend(HWND Owner, HANDLE hContact, bool bFreeOnExit) { + m_hWndO = Owner; + m_bFreeOnExit = bFreeOnExit; + m_pszFile = NULL; + m_pszFileDesc = NULL; + m_pszProto = NULL; + m_ChatRoom = NULL; + m_PFflag = NULL; + m_hContact = NULL; + if (hContact) SetContact(hContact); + m_hOnSend = NULL; + m_szEventMsg = NULL; + m_szEventMsgT = NULL; + m_pszSendTyp = NULL; + + m_ErrorMsg = NULL; + m_ErrorTitle = NULL; +} + +CSend::~CSend(){ + mir_free(m_pszFile); + mir_free(m_pszFileDesc); + mir_free(m_szEventMsg); + mir_free(m_szEventMsgT); + mir_free(m_ErrorMsg); + mir_free(m_ErrorTitle); + if (m_hOnSend) UnhookEvent(m_hOnSend); +} + +//--------------------------------------------------------------------------- +void CSend::SetContact(HANDLE hContact) { + m_hContact = hContact; + m_pszProto = (char*)CallService(MS_PROTO_GETCONTACTBASEPROTO,(WPARAM)hContact,0); + m_ChatRoom = DBGetContactSettingByte(hContact, m_pszProto, "ChatRoom", 0); + m_PFflag = hasCap(PF1_URLSEND); + m_PFflag = hasCap(PF1_CHAT); + m_PFflag = hasCap(PF1_IMSEND); +} + +//--------------------------------------------------------------------------- +bool CSend::hasCap(unsigned int Flag) { + return (Flag & CallContactService(m_hContact, PS_GETCAPS, (WPARAM)PFLAGNUM_1, NULL)) == Flag; +} + +//--------------------------------------------------------------------------- +void CSend::svcSendMsg(const char* szMessage) { + mir_freeAndNil(m_szEventMsg); + m_cbEventMsg=lstrlenA(szMessage)+1; + m_szEventMsg=(char*)mir_realloc(m_szEventMsg, sizeof(char)*m_cbEventMsg); + ZeroMemory(m_szEventMsg, m_cbEventMsg); + lstrcpyA(m_szEventMsg,szMessage); + if (m_pszFileDesc && m_pszFileDesc[0] != NULL) { + char *temp = mir_t2a(m_pszFileDesc); + mir_stradd(m_szEventMsg, "\r\n"); + mir_stradd(m_szEventMsg, temp); + m_cbEventMsg = lstrlenA(m_szEventMsg)+1; + mir_free(temp); + } + //create a HookEventObj on ME_PROTO_ACK + if (!m_hOnSend) { + int (__cdecl CSend::*hookProc)(WPARAM, LPARAM); + hookProc = &CSend::OnSend; + m_hOnSend = HookEventObj(ME_PROTO_ACK, (MIRANDAHOOKOBJ)*(void **)&hookProc, this); + } + //start PSS_MESSAGE service + m_hSend = (HANDLE)CallContactService(m_hContact, PSS_MESSAGE, NULL, (LPARAM)m_szEventMsg); + // check we actually got an ft handle back from the protocol + if (!m_hSend) { + Unhook(); + Error(SS_ERR_INIT, m_pszSendTyp); + Exit(ACKRESULT_FAILED); + } +} + +void CSend::svcSendUrl(const char* url) { +//szMessage should be encoded as the URL followed by the description, the +//separator being a single nul (\0). If there is no description, do not forget +//to end the URL with two nuls. + mir_freeAndNil(m_szEventMsg) + m_cbEventMsg=lstrlenA(url)+2; + m_szEventMsg=(char*)mir_realloc(m_szEventMsg, m_cbEventMsg); + ZeroMemory(m_szEventMsg, m_cbEventMsg); + lstrcpyA(m_szEventMsg,url); + if (m_pszFileDesc && m_pszFileDesc[0] != NULL) { + char *temp = mir_t2a(m_pszFileDesc); + m_cbEventMsg += lstrlenA(temp); + m_szEventMsg=(char*)mir_realloc(m_szEventMsg, sizeof(char)*m_cbEventMsg); + lstrcpyA(m_szEventMsg+lstrlenA(url)+1,temp); + m_szEventMsg[m_cbEventMsg-1] = 0; + mir_free(temp); + } + //create a HookEventObj on ME_PROTO_ACK + if (!m_hOnSend) { + int (__cdecl CSend::*hookProc)(WPARAM, LPARAM); + hookProc = &CSend::OnSend; + m_hOnSend = HookEventObj(ME_PROTO_ACK, (MIRANDAHOOKOBJ)*(void **)&hookProc, this); + } + //start PSS_URL service + m_hSend = (HANDLE)CallContactService(m_hContact, PSS_URL, NULL, (LPARAM)m_szEventMsg); + // check we actually got an ft handle back from the protocol + if (!m_hSend) { + //SetFtStatus(hwndDlg, LPGENT("Unable to initiate transfer."), FTS_TEXT); + //dat->waitingForAcceptance=0; + Unhook(); + } +} + +void CSend::svcSendChat() { + LPTSTR dirtyFix = NULL; + GC_INFO gci = {0}; + GCDEST gcd = {0}; + GCEVENT gce = {0}; + int res = GC_RESULT_NOSESSION; + int cnt = (int)CallService(MS_GC_GETSESSIONCOUNT, 0, (LPARAM)m_pszProto); + + //loop on all gc session to get the right (save) ptszID for the chatroom from m_hContact + gci.pszModule = m_pszProto; + for (int i = 0; i < cnt ; i++ ) { + gci.iItem = i; + gci.Flags = BYINDEX | HCONTACT | ID; //need dirty fix + CallService(MS_GC_GETINFO, 0, (LPARAM)(GC_INFO *) &gci); + if (gci.hContact == m_hContact) { + gcd.pszModule = m_pszProto; + gcd.iType = GC_EVENT_SENDMESSAGE; //GC_EVENT_MESSAGE ???; +#ifdef _UNICODE + gcd.ptszID = gci.pszID; +#else //dirty fix coz MS_GC_GETINFO dont know if caller is ansi or unicode. + //result from MS_GC_GETINFO only depend on type of chat.dll and not of caller type + if (mir_is_unicode()) { + dirtyFix = mir_u2t((wchar_t*)gci.pszID); + } + else { + dirtyFix = mir_tstrdup(gci.pszID); + } + gcd.ptszID = dirtyFix; //fixed gci.pszID; +#endif + gce.cbSize = sizeof(GCEVENT); + gce.pDest = &gcd; + gce.bIsMe = TRUE; + gce.dwFlags = GC_TCHAR|GCEF_ADDTOLOG; + gce.ptszText = m_szEventMsgT; + gce.time = time(NULL); + + //* returns 0 on success or error code on failure + res = 200 + (int)CallService(MS_GC_EVENT, 0, (LPARAM)(GCEVENT *) &gce); + mir_freeAndNil(dirtyFix); + break; + } + } + Exit(res); +} + +void CSend::svcSendChat(const char* szMessage) { + if (!m_ChatRoom) { + svcSendMsg(szMessage); + return; + } + mir_freeAndNil(m_szEventMsgT); + m_szEventMsgT = mir_a2t(szMessage); + if (m_pszFileDesc) { + mir_tcsadd(m_szEventMsgT, _T("\r\n")); + mir_tcsadd(m_szEventMsgT, m_pszFileDesc); + } + svcSendChat(); +} + +void CSend::svcSendFile() { +//szMessage should be encoded as the File followed by the description, the +//separator being a single nul (\0). If there is no description, do not forget +//to end the File with two nuls. + mir_freeAndNil(m_szEventMsg) + char *szFile = mir_t2a(m_pszFile); + m_cbEventMsg=lstrlenA(szFile)+2; + m_szEventMsg=(char*)mir_realloc(m_szEventMsg, sizeof(char)*m_cbEventMsg); + ZeroMemory(m_szEventMsg, m_cbEventMsg); + lstrcpyA(m_szEventMsg,szFile); + if (m_pszFileDesc && m_pszFileDesc[0] != NULL) { + char* temp = mir_t2a(m_pszFileDesc); + m_cbEventMsg += lstrlenA(temp); + m_szEventMsg=(char*)mir_realloc(m_szEventMsg, sizeof(char)*m_cbEventMsg); + lstrcpyA(m_szEventMsg+lstrlenA(szFile)+1,temp); + m_szEventMsg[m_cbEventMsg-1] = 0; + mir_freeAndNil(temp); + } + mir_freeAndNil(szFile); + + //create a HookEventObj on ME_PROTO_ACK + if (!m_hOnSend) { + int (__cdecl CSend::*hookProc)(WPARAM, LPARAM); + hookProc = &CSend::OnSend; + m_hOnSend = HookEventObj(ME_PROTO_ACK, (MIRANDAHOOKOBJ)*(void **)&hookProc, this); + } + // Start miranda PSS_FILE based on mir ver (T) + if ((CallService(MS_SYSTEM_GETVERSION,0,0) >= 0x090000) && mir_is_unicode()) { + TCHAR *ppFile[2]={0,0}; + TCHAR *pDesc = mir_tstrdup(m_pszFileDesc); + ppFile[0] = mir_tstrdup (m_pszFile); +/* #if defined( _UNICODE ) + TCHAR *ppFile[2]={0,0}; + TCHAR *pDesc = mir_tstrdup(m_pszFileDesc); + ppFile[0] = mir_tstrdup (m_pszFile); + #else + wchar_t *ppFile[2]={0,0}; + wchar_t *pDesc = mir_t2u (m_pszFileDesc); + ppFile[0] = mir_t2u (m_pszFile); + #endif */ + ppFile[1] = NULL; + m_hSend = (HANDLE)CallContactService(m_hContact, PSS_FILET, (WPARAM)pDesc, (LPARAM)ppFile); + mir_free(pDesc); + mir_free(ppFile[0]); + } + else { + char *pDesc = mir_t2a(m_pszFileDesc); + char *ppFile[2]={0}; + ppFile[0] = mir_t2a(m_pszFile); + ppFile[1] = NULL; + m_hSend = (HANDLE)CallContactService(m_hContact, PSS_FILE, (WPARAM)pDesc, (LPARAM)ppFile); + mir_free(pDesc); + mir_free(ppFile[0]); + } + // check we actually got an ft handle back from the protocol + if (!m_hSend) { + Unhook(); + Error(SS_ERR_INIT, m_pszSendTyp); + Exit(ACKRESULT_FAILED); + } +} + +//--------------------------------------------------------------------------- +int __cdecl CSend::OnSend(WPARAM wParam, LPARAM lParam){ + ACKDATA *ack=(ACKDATA*)lParam; + if(ack->hProcess!= m_hSend) return 0; + /* if(dat->waitingForAcceptance) { + SetTimer(hwndDlg,1,1000,NULL); + dat->waitingForAcceptance=0; + } + */ + + switch(ack->result) { + case ACKRESULT_INITIALISING: //SetFtStatus(hwndDlg, LPGENT("Initialising..."), FTS_TEXT); break; + case ACKRESULT_CONNECTING: //SetFtStatus(hwndDlg, LPGENT("Connecting..."), FTS_TEXT); break; + case ACKRESULT_CONNECTPROXY: //SetFtStatus(hwndDlg, LPGENT("Connecting to proxy..."), FTS_TEXT); break; + case ACKRESULT_LISTENING: //SetFtStatus(hwndDlg, LPGENT("Waiting for connection..."), FTS_TEXT); break; + case ACKRESULT_CONNECTED: //SetFtStatus(hwndDlg, LPGENT("Connected"), FTS_TEXT); break; + case ACKRESULT_SENTREQUEST: //SetFtStatus(hwndDlg, LPGENT("Decision sent"), FTS_TEXT); break; + case ACKRESULT_NEXTFILE: //SetFtStatus(hwndDlg, LPGENT("Moving to next file..."), FTS_TEXT); + case ACKRESULT_FILERESUME: // + case ACKRESULT_DATA: //transfer is on progress + break; + case ACKRESULT_DENIED: + Unhook(); + Exit(ack->result); + break; + case ACKRESULT_FAILED: + Unhook(); + Exit(ack->result); + //type=ACKTYPE_MESSAGE, result=success/failure, (char*)lParam=error message or NULL. + //type=ACKTYPE_URL, result=success/failure, (char*)lParam=error message or NULL. + //type=ACKTYPE_FILE, result=ACKRESULT_FAILED then lParam=(LPARAM)(const char*)szReason + break; + case ACKRESULT_SUCCESS: + Unhook(); + switch(ack->type) { + case ACKTYPE_CHAT: + break; + case ACKTYPE_MESSAGE: + DB_EventAdd((WORD)EVENTTYPE_MESSAGE); + break; + case ACKTYPE_URL: + DB_EventAdd((WORD)EVENTTYPE_URL); + break; + case ACKTYPE_FILE: + //MS_DB_EVENT_ADD need 4byte extra at the beginning of m_szEventMsg for ACKTYPE_FILE + m_szEventMsg = (char*) mir_realloc(m_szEventMsg, sizeof(DWORD) + m_cbEventMsg); + //memmove_s(m_szEventMsg+sizeof(DWORD), m_cbEventMsg, m_szEventMsg, m_cbEventMsg); + memmove(m_szEventMsg+sizeof(DWORD), m_szEventMsg, m_cbEventMsg); + m_cbEventMsg += sizeof(DWORD); + DB_EventAdd((WORD)EVENTTYPE_FILE); + break; + default: + break; + } + Exit(ack->result); + break; + default: + return 0; + break; + } + return 0; +} + +void CSend::DB_EventAdd(WORD EventType) { + DBEVENTINFO dbei={0}; + dbei.cbSize = sizeof(dbei); + dbei.szModule = m_pszProto; + dbei.eventType = EventType; + dbei.flags = DBEF_SENT; + dbei.timestamp = time(NULL); + #if defined( _UNICODE ) + dbei.flags |= DBEF_UTF; + #endif + dbei.cbBlob= m_cbEventMsg; + dbei.pBlob=(PBYTE)m_szEventMsg; + + CallService(MS_DB_EVENT_ADD,(WPARAM)m_hContact,(LPARAM)&dbei); +} + +//--------------------------------------------------------------------------- +void CSend::AfterSendDelete() { + if (m_pszFile && m_bDeleteAfterSend && (m_EnableItem & SS_DLG_DELETEAFTERSSEND) == SS_DLG_DELETEAFTERSSEND) { + DeleteFile(m_pszFile); + } +} + +//--------------------------------------------------------------------------- +void CSend::Exit(unsigned int Result) { + bool err = true; + if (m_hWndO && IsWindow(m_hWndO)){ + ; + } + switch(Result) { + case ACKRESULT_SUCCESS: + case GC_RESULT_SUCCESS: + SkinPlaySound("FileDone"); + err = false; + break; + case ACKRESULT_DENIED: + SkinPlaySound("FileDenied"); + Error(_T("%s (%i):\nFile transfer denied."),TranslateTS(m_pszSendTyp),Result); + MsgBoxService(NULL, (LPARAM)&m_box); + err = false; + break; + case GC_RESULT_WRONGVER: //.You appear to be using the wrong version of GC API. + Error(_T("%s (%i):\nYou appear to be using the wrong version of GC API"),TranslateT("GCHAT error"),Result); + break; + case GC_RESULT_ERROR: // An internal GC error occurred. + Error(_T("%s (%i):\nAn internal GC error occurred."),TranslateT("GCHAT error"),Result); + break; + case GC_RESULT_NOSESSION: // contact has no open GC session + Error(_T("%s (%i):\nContact has no open GC session."),TranslateT("GCHAT error"),Result); + break; + case ACKRESULT_FAILED: + default: + break; + } + if (err){ + SkinPlaySound("FileFailed"); + if(m_ErrorMsg && m_ErrorMsg[0] != 0) MsgBoxService(NULL, (LPARAM)&m_box); + else MsgErr(NULL, LPGENT("An unknown error has occured.")); + } + + AfterSendDelete(); + if(m_bFreeOnExit) delete this; +} + +void CSend::Error(LPCTSTR pszFormat, ...) { + if(!pszFormat) return; + + TCHAR tszTemp[MAX_SECONDLINE]; + va_list vl; + + mir_sntprintf(tszTemp, SIZEOF(tszTemp),_T("%s - %s") ,_T(MODNAME), TranslateT("Error")); + mir_freeAndNil(m_ErrorTitle); + m_ErrorTitle = mir_tstrdup(tszTemp); + + va_start(vl, pszFormat); + mir_vsntprintf(tszTemp, SIZEOF(tszTemp), TranslateTS(pszFormat), vl); + va_end(vl); + mir_freeAndNil(m_ErrorMsg); + m_ErrorMsg = mir_tstrdup(tszTemp); + + ZeroMemory(&m_box, sizeof(m_box)); + m_box.cbSize = sizeof(MSGBOX); + m_box.hParent = NULL; + m_box.hiLogo = IcoLib_GetIcon(ICO_PLUG_SSWINDOW1); + m_box.hiMsg = NULL; + m_box.ptszTitle = m_ErrorTitle; + m_box.ptszMsg = m_ErrorMsg; + m_box.uType = MB_OK|MB_ICON_ERROR; +} + diff --git a/plugins/SendScreenshotPlus/src/CSend.h b/plugins/SendScreenshotPlus/src/CSend.h new file mode 100644 index 0000000000..082f3e961a --- /dev/null +++ b/plugins/SendScreenshotPlus/src/CSend.h @@ -0,0 +1,113 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* +Copyright 2000-2009 Miranda ICQ/IM project, + +This file is part of Send Screenshot Plus, a Miranda IM plugin. +Copyright (c) 2010 Ing.U.Horn + +Parts of this file based on original sorce code +(c) 2004-2006 Srgio Vieira Rolanski (portet from Borland C++) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +File name : $HeadURL: http://merlins-miranda.googlecode.com/svn/trunk/miranda/plugins/SendSSPlus/CSend.h $ +Revision : $Revision: 17 $ +Last change on : $Date: 2010-04-03 18:01:11 +0400 (Сб, 03 апр 2010) $ +Last change by : $Author: ing.u.horn $ + +*/ + +#ifndef _CSEND_H +#define _CSEND_H + +//--------------------------------------------------------------------------- +#include "global.h" +#include "Utils.h" +#include "dlg_msgbox.h" + + +//--------------------------------------------------------------------------- +#define SS_AUTOSEND 1 +#define SS_DELETEAFTERSSEND 2 + +#define SS_DLG_AUTOSEND 1 //Button_Enable(GetDlgItem(Owner, ID_chkEmulateClick), TRUE); +#define SS_DLG_DELETEAFTERSSEND 2 //Button_Enable(GetDlgItem(Owner, ID_btnDeleteAfterSend), TRUE); +#define SS_DLG_DESCRIPTION 4 //Button_Enable(GetDlgItem(Owner, ID_btnDesc), TRUE); + +#define GC_RESULT_SUCCESS 200 +#define GC_RESULT_WRONGVER 201 +#define GC_RESULT_ERROR 202 +#define GC_RESULT_NOSESSION 209 + +#define SS_ERR_INIT _T("Unable to initiate %s.") +#define SS_ERR_MAPI _T("MAPI error (%i):\n%s.") + +//--------------------------------------------------------------------------- +class CSend { + public: + CSend(HWND Owner, HANDLE hContact, bool bFreeOnExit); // oder (TfrmMain & Owner) + virtual ~CSend(); + + virtual void Send() = 0; + void SendSync(bool Sync) {m_SendSync = Sync;}; + bool m_bFreeOnExit; // need to "delete object;" on exit ? + void SetContact(HANDLE hContact); + BYTE GetEnableItem() {return m_EnableItem;}; + LPTSTR GetErrorMsg() {return m_ErrorMsg;}; + + LPTSTR m_pszFile; + LPTSTR m_pszFileDesc; + + BOOL m_bDeleteAfterSend; + + private: + + protected: + LPTSTR m_pszSendTyp; //hold string for error mess + HWND m_hWndO; //window handle of caller + HANDLE m_hContact; //Contact handle + char* m_pszProto; //Contact Proto Modul + BYTE m_EnableItem; //hold flag for send type + void AfterSendDelete(); + BYTE m_ChatRoom; //is Contact chatroom + bool m_SendSync; //send sync / async + + bool hasCap(unsigned int Flag); + unsigned int m_PFflag; + + void svcSendFile(); + void svcSendUrl (const char* url); + void svcSendMsg (const char* szMessage); + void svcSendChat(); //main GC service + void svcSendChat(const char* szMessage); //GC ansi wrapper + + DWORD m_cbEventMsg; //sizeof EventMsg(T) buffer + char* m_szEventMsg; //EventMsg char* + LPTSTR m_szEventMsgT; //EventMsg TCHAR* + HANDLE m_hSend; //protocol send handle + HANDLE m_hOnSend; //HookEventObj on ME_PROTO_ACK + int __cdecl OnSend(WPARAM wParam, LPARAM lParam); + void Unhook(){if(m_hOnSend) {UnhookEvent(m_hOnSend);m_hOnSend = NULL;}} + void DB_EventAdd(WORD EventType); + void Exit(unsigned int Result); + + MSGBOX m_box; + LPTSTR m_ErrorMsg; + LPTSTR m_ErrorTitle; + void Error(LPCTSTR pszFormat, ...); +}; + +#endif diff --git a/plugins/SendScreenshotPlus/src/CSendEmail.cpp b/plugins/SendScreenshotPlus/src/CSendEmail.cpp new file mode 100644 index 0000000000..14e539ea0d --- /dev/null +++ b/plugins/SendScreenshotPlus/src/CSendEmail.cpp @@ -0,0 +1,221 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* +Copyright 2000-2009 Miranda ICQ/IM project, + +This file is part of Send Screenshot Plus, a Miranda IM plugin. +Copyright (c) 2010 Ing.U.Horn + +Parts of this file based on original sorce code +(c) 2004-2006 Srgio Vieira Rolanski (portet from Borland C++) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +File name : $HeadURL: http://merlins-miranda.googlecode.com/svn/trunk/miranda/plugins/SendSSPlus/CSendEmail.cpp $ +Revision : $Revision: 13 $ +Last change on : $Date: 2010-04-02 02:54:30 +0400 (Пт, 02 апр 2010) $ +Last change by : $Author: ing.u.horn $ + +*/ + +//--------------------------------------------------------------------------- +#include "CSendEmail.h" + +//--------------------------------------------------------------------------- +CSendEmail::CSendEmail(HWND Owner, HANDLE hContact, bool bFreeOnExit) +: CSend(Owner, hContact, bFreeOnExit){ + m_EnableItem = SS_DLG_DELETEAFTERSSEND | SS_DLG_DESCRIPTION; // SS_DLG_AUTOSEND | ; + m_pszSendTyp = _T("Email transfer"); + m_pszFileA = NULL; + m_pszFileName = NULL; + m_Email = NULL; + m_FriendlyName = NULL; + m_Subject = NULL; +} + +CSendEmail::~CSendEmail(){ + mir_free(m_pszFileA); + mir_free(m_pszFileName); + mir_free(m_Email); + mir_free(m_FriendlyName); + mir_free(m_Subject); +} + +//--------------------------------------------------------------------------- +void CSendEmail::Send() { + + mir_freeAndNil(m_pszFileName); + m_pszFileName = (LPSTR)GetFileName(m_pszFile, DBVT_ASCIIZ); + + mir_freeAndNil(m_pszFileA); + m_pszFileA = mir_t2a(m_pszFile); + + +// AnsiString Email, Subject, FriendlyName; + CONTACTINFO ci={0}; + ci.cbSize = sizeof(ci); + ci.hContact = m_hContact; + ci.szProto = m_pszProto; + //ci.dwFlag = CNF_TCHAR; + + ci.dwFlag = CNF_EMAIL | CNF_TCHAR; + CallService(MS_CONTACT_GETCONTACTINFO,(WPARAM)0,(LPARAM)&ci); + m_Email = mir_t2a(ci.pszVal); + + ci.dwFlag = CNF_DISPLAY | CNF_TCHAR; + CallService(MS_CONTACT_GETCONTACTINFO,(WPARAM)0,(LPARAM)&ci); + m_FriendlyName = mir_t2a(ci.pszVal); + + mir_free(ci.pszVal); + + m_Subject = mir_t2a(m_pszFileDesc); + + //SendByEmail(m_pszFileA, "", m_FriendlyName, m_Email, m_Subject); + + //start Send thread + m_bFreeOnExit = TRUE; + mir_forkthread(&CSendEmail::SendThreadWrapper, this); +} + +void CSendEmail::SendThread() { + //This code based on SentTo.exe application. + //The default mail client for Simple MAPI or MAPI calls is defined by the + //HKLM\Software\Clients\Mail::(default) registry value. + + LPTSTR err = NULL; + MapiFileDesc arrfileDesc[1]; + + typedef ULONG (FAR PASCAL *MAPIFUNC)(LHANDLE,ULONG,lpMapiMessage,FLAGS,ULONG); + MapiMessage Msg; + MAPIFUNC lpMAPISendMail; + + HINSTANCE hMAPILib = ::LoadLibrary(_T("MAPI32.DLL")); + if (hMAPILib == NULL) { + //return -1; + Error(SS_ERR_INIT, m_pszSendTyp); + Exit(ACKRESULT_FAILED); + } + + lpMAPISendMail = (MAPIFUNC)GetProcAddress(hMAPILib, "MAPISendMail"); + if (lpMAPISendMail == NULL) { + ::FreeLibrary(hMAPILib); + //return -2; + Error(SS_ERR_INIT, m_pszSendTyp); + Exit(ACKRESULT_FAILED); + } + + memset(&Msg, 0, sizeof(Msg)); + + arrfileDesc[0].ulReserved = 0; + arrfileDesc[0].flFlags = 0; + arrfileDesc[0].lpFileType = NULL; + arrfileDesc[0].nPosition = -1; + arrfileDesc[0].lpszPathName = m_pszFileA; + arrfileDesc[0].lpszFileName = NULL; + + Msg.nFileCount = 1; + Msg.lpFiles = arrfileDesc; + Msg.lpszNoteText = ""; //body + Msg.lpszSubject = m_Subject; //subject + + Msg.nRecipCount = 1; + MapiRecipDesc recip; + recip.ulReserved = 0; + recip.ulRecipClass = MAPI_TO; + + if (m_FriendlyName && m_FriendlyName[0]!= NULL) { + recip.lpszName = m_FriendlyName; //friendly name set to contact's name + } + else { + recip.lpszName = m_Email; //friendly name set to contact's email + } + + recip.lpszAddress = m_Email; //email + recip.ulEIDSize = 0; + recip.lpEntryID = NULL; + Msg.lpRecips = &recip; + + try { + int res = lpMAPISendMail(NULL, NULL, &Msg, MAPI_LOGON_UI|MAPI_DIALOG, 0); + ::FreeLibrary(hMAPILib); + + switch (res) { + case SUCCESS_SUCCESS: + //The call succeeded and the message was sent. + Exit(ACKRESULT_SUCCESS); + return; + + // No message was sent + case MAPI_E_AMBIGUOUS_RECIPIENT: + err = _T("A recipient matched more than one of the recipient descriptor structures and MAPI_DIALOG was not set"); + break; + case MAPI_E_ATTACHMENT_NOT_FOUND: + err = _T("The specified attachment was not found"); + break; + case MAPI_E_ATTACHMENT_OPEN_FAILURE: + err = _T("The specified attachment could not be opened"); + break; + case MAPI_E_BAD_RECIPTYPE: + err = _T("The type of a recipient was not MAPI_TO, MAPI_CC, or MAPI_BCC"); + break; + case MAPI_E_FAILURE: + err = _T("One or more unspecified errors occurred"); + break; + case MAPI_E_INSUFFICIENT_MEMORY: + err = _T("There was insufficient memory to proceed"); + break; + case MAPI_E_INVALID_RECIPS: + err = _T("One or more recipients were invalid or did not resolve to any address"); + break; + case MAPI_E_LOGIN_FAILURE: + err = _T("There was no default logon, and the user failed to log on successfully when the logon dialog box was displayed"); + break; + case MAPI_E_TEXT_TOO_LARGE: + err = _T("The text in the message was too large"); + break; + case MAPI_E_TOO_MANY_FILES: + err = _T("There were too many file attachments"); + break; + case MAPI_E_TOO_MANY_RECIPIENTS: + err = _T("There were too many recipients"); + break; + case MAPI_E_UNKNOWN_RECIPIENT: + err = _T("A recipient did not appear in the address list"); + break; + case MAPI_E_USER_ABORT: + err = _T("The user canceled one of the dialog boxes"); + break; + default: + err = _T("Unknown Error"); + break; + } + Error(SS_ERR_MAPI, res, err); + Exit(ACKRESULT_FAILED); + + } catch (...) { + ::FreeLibrary(hMAPILib); + Error(SS_ERR_INIT, m_pszSendTyp); + Exit(ACKRESULT_FAILED); + //return -3; + return; + } +} + +void CSendEmail::SendThreadWrapper(void * Obj) { + reinterpret_cast(Obj)->SendThread(); +} + +//--------------------------------------------------------------------------- + diff --git a/plugins/SendScreenshotPlus/src/CSendEmail.h b/plugins/SendScreenshotPlus/src/CSendEmail.h new file mode 100644 index 0000000000..940558b0d6 --- /dev/null +++ b/plugins/SendScreenshotPlus/src/CSendEmail.h @@ -0,0 +1,63 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* +Copyright 2000-2009 Miranda ICQ/IM project, + +This file is part of Send Screenshot Plus, a Miranda IM plugin. +Copyright (c) 2010 Ing.U.Horn + +Parts of this file based on original sorce code +(c) 2004-2006 Srgio Vieira Rolanski (portet from Borland C++) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +File name : $HeadURL: http://merlins-miranda.googlecode.com/svn/trunk/miranda/plugins/SendSSPlus/CSendEmail.h $ +Revision : $Revision: 13 $ +Last change on : $Date: 2010-04-02 02:54:30 +0400 (Пт, 02 апр 2010) $ +Last change by : $Author: ing.u.horn $ + +*/ + +#ifndef _CSEND_EMAIL_H +#define _CSEND_EMAIL_H + +//--------------------------------------------------------------------------- +#include "global.h" +#include "CSend.h" +#include + +//--------------------------------------------------------------------------- +class CSendEmail : public CSend { + public: + // Deklaration Standardkonstruktor/Standarddestructor + CSendEmail(HWND Owner, HANDLE hContact, bool bFreeOnExit); + ~CSendEmail(); + + void Send(); + + protected: + LPSTR m_pszFileA; + LPSTR m_pszFileName; + LPSTR m_Email; + LPSTR m_FriendlyName; + LPSTR m_Subject; + void SendThread(); + static void SendThreadWrapper(void * Obj); + +}; + +//--------------------------------------------------------------------------- + +#endif diff --git a/plugins/SendScreenshotPlus/src/CSendFTPFile.cpp b/plugins/SendScreenshotPlus/src/CSendFTPFile.cpp new file mode 100644 index 0000000000..d7512d2fe6 --- /dev/null +++ b/plugins/SendScreenshotPlus/src/CSendFTPFile.cpp @@ -0,0 +1,99 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* +Copyright 2000-2009 Miranda ICQ/IM project, + +This file is part of Send Screenshot Plus, a Miranda IM plugin. +Copyright (c) 2010 Ing.U.Horn + +Parts of this file based on original sorce code +(c) 2004-2006 Srgio Vieira Rolanski (portet from Borland C++) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +File name : $HeadURL: http://merlins-miranda.googlecode.com/svn/trunk/miranda/plugins/SendSSPlus/CSendFTPFile.cpp $ +Revision : $Revision: 13 $ +Last change on : $Date: 2010-04-02 02:54:30 +0400 (Пт, 02 апр 2010) $ +Last change by : $Author: ing.u.horn $ + +*/ + +//--------------------------------------------------------------------------- +#include "CSendFTPFile.h" + + +//--------------------------------------------------------------------------- +CSendFTPFile::CSendFTPFile(HWND Owner, HANDLE hContact, bool bFreeOnExit) +: CSend(Owner, hContact, bFreeOnExit){ + m_EnableItem = NULL ; //SS_DLG_DESCRIPTION| SS_DLG_AUTOSEND | SS_DLG_DELETEAFTERSSEND; + m_pszSendTyp = _T("FTPFile transfer"); + m_pszFileName = NULL; + m_URL = NULL; +} + +CSendFTPFile::~CSendFTPFile(){ + mir_free(m_pszFileName); + mir_free(m_URL); +} + +//--------------------------------------------------------------------------- +void CSendFTPFile::Send() { + + /********************************************************************************************* + * Send file (files) to the FTP server and copy file URL + * to message log or clipboard (according to plugin setting) + * wParam = (HANDLE)hContact + * lParam = (char *)filename + * Filename format is same as GetOpenFileName (OPENFILENAME.lpstrFile) returns, + * see http://msdn2.microsoft.com/en-us/library/ms646839.aspx + * Returns 0 on success or nonzero on failure + * if (!wParam || !lParam) return 1 + ********************************************************************************************/ + mir_freeAndNil(m_pszFileName); + m_pszFileName = (LPSTR)GetFileName(m_pszFile, DBVT_ASCIIZ); + size_t size = sizeof(char)*(strlen(m_pszFileName)+2); + m_pszFileName = (LPSTR) mir_realloc(m_pszFileName, size); + m_pszFileName[size-1] = NULL; + + //start Send thread + m_bFreeOnExit = TRUE; + mir_forkthread(&CSendFTPFile::SendThreadWrapper, this); +} + +void CSendFTPFile::SendThread() { + int ret; + mir_freeAndNil(m_URL); + + ret = (int)CallService(MS_FTPFILE_SHAREFILE, (WPARAM)m_hContact, (LPARAM)m_pszFileName); + if (ret != 0) { + Error(_T("%s (%i):\nCould not add a share to the FTP File plugin."),TranslateTS(m_pszSendTyp),ret); + Exit(ret); + } + + //Can't delete the file since FTP File plugin will use it + m_bDeleteAfterSend = false; + + if (m_URL && m_URL[0]!= NULL) { + m_ChatRoom ? svcSendChat(m_URL) : svcSendMsg(m_URL); + return; + } +} + +void CSendFTPFile::SendThreadWrapper(void * Obj) { + reinterpret_cast(Obj)->SendThread(); +} + +//--------------------------------------------------------------------------- + diff --git a/plugins/SendScreenshotPlus/src/CSendFTPFile.h b/plugins/SendScreenshotPlus/src/CSendFTPFile.h new file mode 100644 index 0000000000..6012f76232 --- /dev/null +++ b/plugins/SendScreenshotPlus/src/CSendFTPFile.h @@ -0,0 +1,59 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* +Copyright 2000-2009 Miranda ICQ/IM project, + +This file is part of Send Screenshot Plus, a Miranda IM plugin. +Copyright (c) 2010 Ing.U.Horn + +Parts of this file based on original sorce code +(c) 2004-2006 Srgio Vieira Rolanski (portet from Borland C++) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +File name : $HeadURL: http://merlins-miranda.googlecode.com/svn/trunk/miranda/plugins/SendSSPlus/CSendFTPFile.h $ +Revision : $Revision: 13 $ +Last change on : $Date: 2010-04-02 02:54:30 +0400 (Пт, 02 апр 2010) $ +Last change by : $Author: ing.u.horn $ + +*/ + +#ifndef _CSEND_FTP_FILE_H +#define _CSEND_FTP_FILE_H + +//--------------------------------------------------------------------------- +#include "global.h" +#include "CSend.h" + +//--------------------------------------------------------------------------- +class CSendFTPFile : public CSend { + public: + // Deklaration Standardkonstruktor/Standarddestructor + CSendFTPFile(HWND Owner, HANDLE hContact, bool bFreeOnExit); + ~CSendFTPFile(); + + void Send(); + + protected: + LPSTR m_pszFileName; + LPSTR m_URL; + void SendThread(); + static void SendThreadWrapper(void * Obj); + +}; + +//--------------------------------------------------------------------------- + +#endif diff --git a/plugins/SendScreenshotPlus/src/CSendFile.cpp b/plugins/SendScreenshotPlus/src/CSendFile.cpp new file mode 100644 index 0000000000..1884c8307f --- /dev/null +++ b/plugins/SendScreenshotPlus/src/CSendFile.cpp @@ -0,0 +1,53 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* +Copyright 2000-2009 Miranda ICQ/IM project, + +This file is part of Send Screenshot Plus, a Miranda IM plugin. +Copyright (c) 2010 Ing.U.Horn + +Parts of this file based on original sorce code +(c) 2004-2006 Srgio Vieira Rolanski (portet from Borland C++) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +File name : $HeadURL: http://merlins-miranda.googlecode.com/svn/trunk/miranda/plugins/SendSSPlus/CSendFile.cpp $ +Revision : $Revision: 13 $ +Last change on : $Date: 2010-04-02 02:54:30 +0400 (Пт, 02 апр 2010) $ +Last change by : $Author: ing.u.horn $ + +*/ + +//--------------------------------------------------------------------------- +#include "CSendFile.h" + +//--------------------------------------------------------------------------- +CSendFile::CSendFile(HWND Owner, HANDLE hContact, bool bFreeOnExit) +: CSend(Owner, hContact, bFreeOnExit){ + m_EnableItem = SS_DLG_AUTOSEND | SS_DLG_DELETEAFTERSSEND | SS_DLG_DESCRIPTION; + m_pszSendTyp = _T("File transfer"); +} + +CSendFile::~CSendFile(){ + ; +} + +//--------------------------------------------------------------------------- +void CSendFile::Send() { + m_bFreeOnExit = TRUE; + svcSendFile(); +} + +//--------------------------------------------------------------------------- diff --git a/plugins/SendScreenshotPlus/src/CSendFile.h b/plugins/SendScreenshotPlus/src/CSendFile.h new file mode 100644 index 0000000000..edbb49822d --- /dev/null +++ b/plugins/SendScreenshotPlus/src/CSendFile.h @@ -0,0 +1,55 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* +Copyright 2000-2009 Miranda ICQ/IM project, + +This file is part of Send Screenshot Plus, a Miranda IM plugin. +Copyright (c) 2010 Ing.U.Horn + +Parts of this file based on original sorce code +(c) 2004-2006 Srgio Vieira Rolanski (portet from Borland C++) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +File name : $HeadURL: http://merlins-miranda.googlecode.com/svn/trunk/miranda/plugins/SendSSPlus/CSendFile.h $ +Revision : $Revision: 13 $ +Last change on : $Date: 2010-04-02 02:54:30 +0400 (Пт, 02 апр 2010) $ +Last change by : $Author: ing.u.horn $ + +*/ + +#ifndef _CSEND_FILE_H +#define _CSEND_FILE_H + +//--------------------------------------------------------------------------- +#include "global.h" +#include "CSend.h" + +//--------------------------------------------------------------------------- +class CSendFile : public CSend { + public: + // Deklaration Standardkonstruktor/Standarddestructor + CSendFile(HWND Owner, HANDLE hContact, bool bFreeOnExit); + ~CSendFile(); + + void Send(); + + protected: + +}; + +//---------------------------------------------------------------------------*/ + +#endif diff --git a/plugins/SendScreenshotPlus/src/CSendHTTPServer.cpp b/plugins/SendScreenshotPlus/src/CSendHTTPServer.cpp new file mode 100644 index 0000000000..788ebca4d1 --- /dev/null +++ b/plugins/SendScreenshotPlus/src/CSendHTTPServer.cpp @@ -0,0 +1,140 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* +Copyright 2000-2009 Miranda ICQ/IM project, + +This file is part of Send Screenshot Plus, a Miranda IM plugin. +Copyright (c) 2010 Ing.U.Horn + +Parts of this file based on original sorce code +(c) 2004-2006 Srgio Vieira Rolanski (portet from Borland C++) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +File name : $HeadURL: http://merlins-miranda.googlecode.com/svn/trunk/miranda/plugins/SendSSPlus/CSendHTTPServer.cpp $ +Revision : $Revision: 13 $ +Last change on : $Date: 2010-04-02 02:54:30 +0400 (Пт, 02 апр 2010) $ +Last change by : $Author: ing.u.horn $ + +*/ + +//--------------------------------------------------------------------------- +#include "CSendHTTPServer.h" +INT_PTR (*g_MirCallService)(const char *, WPARAM, LPARAM)=NULL; +//INT_PTR (*CallService)(const char *,WPARAM,LPARAM); + + +//--------------------------------------------------------------------------- +CSendHTTPServer::CSendHTTPServer(HWND Owner, HANDLE hContact, bool bFreeOnExit) +: CSend(Owner, hContact, bFreeOnExit){ + m_EnableItem = SS_DLG_DESCRIPTION ; //| SS_DLG_AUTOSEND | SS_DLG_DELETEAFTERSSEND; + m_pszSendTyp = _T("HTTPServer transfer"); + m_pszFileName = NULL; + m_URL = NULL; + m_fsi_pszSrvPath = NULL; + m_fsi_pszRealPath = NULL; +} + +CSendHTTPServer::~CSendHTTPServer(){ + mir_free(m_pszFileName); + mir_free(m_URL); + mir_free(m_fsi_pszSrvPath); + mir_free(m_fsi_pszRealPath); +} + +//--------------------------------------------------------------------------- +void CSendHTTPServer::Send() { + + if (CallService(MS_HTTP_ACCEPT_CONNECTIONS, (WPARAM)true, (LPARAM)0) != 0) { + Error(NULL, _T("Could not start the HTTP Server plugin.")); + return; + } + + if (!m_pszFileName) { + m_pszFileName = (LPSTR)GetFileName(m_pszFile, DBVT_ASCIIZ); + } + mir_freeAndNil(m_fsi_pszSrvPath); + mir_stradd(m_fsi_pszSrvPath, "/"); + mir_stradd(m_fsi_pszSrvPath, m_pszFileName); + + mir_freeAndNil(m_fsi_pszRealPath); + m_fsi_pszRealPath = mir_t2a(m_pszFile); + + ZeroMemory(&m_fsi, sizeof(m_fsi)); + m_fsi.lStructSize = sizeof(STFileShareInfo); + m_fsi.pszSrvPath = m_fsi_pszSrvPath; + m_fsi.nMaxDownloads = -1; // -1 = infinite + m_fsi.pszRealPath = m_fsi_pszRealPath; + //m_fsi.dwOptions = NULL; //OPT_SEND_LINK only work on single chat; + + //start Send thread + m_bFreeOnExit = TRUE; + mir_forkthread(&CSendHTTPServer::SendThreadWrapper, this); +} + +void CSendHTTPServer::SendThread() { + int ret; + mir_freeAndNil(m_URL); + + if (ServiceExists(MS_HTTP_GET_LINK)) { + //patched plugin version + ret = (int)CallService(MS_HTTP_ADD_CHANGE_REMOVE, (WPARAM)m_hContact, (LPARAM)&m_fsi); + if (!ret) { + m_URL = (LPSTR)CallService(MS_HTTP_GET_LINK, (WPARAM)m_fsi.pszSrvPath, NULL); + } + } + else { + //original plugin + m_fsi.dwOptions = OPT_SEND_LINK; + + //send DATA and wait for reply + ret = (int)CallService(MS_HTTP_ADD_CHANGE_REMOVE, (WPARAM)m_hContact, (LPARAM)&m_fsi); + } + + if (ret != 0) { + Error(_T("%s (%i):\nCould not add a share to the HTTP Server plugin."),TranslateTS(m_pszSendTyp),ret); + Exit(ret); + } + + //Share the file by HTTP Server plugin, SendSS does not own the file anymore = auto-delete won't work + m_bDeleteAfterSend = false; + + if (m_URL && m_URL[0]!= NULL) { + m_ChatRoom ? svcSendChat(m_URL) : svcSendMsg(m_URL); + return; + } + Exit(ACKRESULT_FAILED); +} + +void CSendHTTPServer::SendThreadWrapper(void * Obj) { + reinterpret_cast(Obj)->SendThread(); +} + +//--------------------------------------------------------------------------- +CSendHTTPServer::CContactMapping CSendHTTPServer::_CContactMapping; + +INT_PTR CSendHTTPServer::MyCallService(const char *name, WPARAM wParam, LPARAM lParam) { + CContactMapping::iterator Contact(_CContactMapping.end()); +/* + if ( wParam == m_hContact && ( + (strcmp(name, MS_MSG_SENDMESSAGE)== 0) || + (strcmp(name, "SRMsg/LaunchMessageWindow")== 0) )) + { + m_URL= mir_strdup((char*)lParam); + return 0; + }*/ + return g_MirCallService(name, wParam, lParam); +} + diff --git a/plugins/SendScreenshotPlus/src/CSendHTTPServer.h b/plugins/SendScreenshotPlus/src/CSendHTTPServer.h new file mode 100644 index 0000000000..129153e0c6 --- /dev/null +++ b/plugins/SendScreenshotPlus/src/CSendHTTPServer.h @@ -0,0 +1,67 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* +Copyright 2000-2009 Miranda ICQ/IM project, + +This file is part of Send Screenshot Plus, a Miranda IM plugin. +Copyright (c) 2010 Ing.U.Horn + +Parts of this file based on original sorce code +(c) 2004-2006 Srgio Vieira Rolanski (portet from Borland C++) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +File name : $HeadURL: http://merlins-miranda.googlecode.com/svn/trunk/miranda/plugins/SendSSPlus/CSendHTTPServer.h $ +Revision : $Revision: 13 $ +Last change on : $Date: 2010-04-02 02:54:30 +0400 (Пт, 02 апр 2010) $ +Last change by : $Author: ing.u.horn $ + +*/ + +#ifndef _CSEND_HTTP_SERVER_H +#define _CSEND_HTTP_SERVER_H + +//--------------------------------------------------------------------------- +#include "global.h" +#include "CSend.h" + +//--------------------------------------------------------------------------- +class CSendHTTPServer : public CSend { + public: + // Deklaration Standardkonstruktor/Standarddestructor + CSendHTTPServer(HWND Owner, HANDLE hContact, bool bFreeOnExit); + ~CSendHTTPServer(); + + void Send(); + + protected: + LPSTR m_pszFileName; + LPSTR m_URL; + STFileShareInfo m_fsi; + LPSTR m_fsi_pszSrvPath; + LPSTR m_fsi_pszRealPath; + void SendThread(); + static void SendThreadWrapper(void * Obj); + + typedef std::map CContactMapping; + static CContactMapping _CContactMapping; + + static INT_PTR MyCallService(const char *name, WPARAM wParam, LPARAM lParam); + +}; + +//--------------------------------------------------------------------------- + +#endif diff --git a/plugins/SendScreenshotPlus/src/CSendImageShack.cpp b/plugins/SendScreenshotPlus/src/CSendImageShack.cpp new file mode 100644 index 0000000000..a27b4f5273 --- /dev/null +++ b/plugins/SendScreenshotPlus/src/CSendImageShack.cpp @@ -0,0 +1,299 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* +Copyright 2000-2009 Miranda ICQ/IM project, + +This file is part of Send Screenshot Plus, a Miranda IM plugin. +Copyright (c) 2010 Ing.U.Horn + +Parts of this file based on original sorce code +(c) 2004-2006 Srgio Vieira Rolanski (portet from Borland C++) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +File name : $HeadURL: http://merlins-miranda.googlecode.com/svn/trunk/miranda/plugins/SendSSPlus/CSendImageShack.cpp $ +Revision : $Revision: 13 $ +Last change on : $Date: 2010-04-02 02:54:30 +0400 (Пт, 02 апр 2010) $ +Last change by : $Author: ing.u.horn $ + +*/ + +//--------------------------------------------------------------------------- +#include +#include +#include + +#include "CSendImageShack.h" +#include "DevKey.h" + +//--------------------------------------------------------------------------- +CSendImageShack::CSendImageShack(HWND Owner, HANDLE hContact, bool bFreeOnExit) +: CSend(Owner, hContact, bFreeOnExit) { + m_EnableItem = SS_DLG_AUTOSEND | SS_DLG_DELETEAFTERSSEND | SS_DLG_DESCRIPTION; + m_pszSendTyp = _T("Image upload"); + m_pszFileName = NULL; + m_pszContentType = NULL; + m_MFDRboundary = NULL; + m_nlreply = NULL; + m_SendSync = false; + m_Url = NULL; +} + +CSendImageShack::~CSendImageShack(){ + mir_free(m_pszFileName); + mir_free(m_MFDRboundary); + // FREEHTTPREQUESTSTRUCT* + if (m_nlreply) CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM) m_nlreply); + mir_free(m_Url); +}; + +//--------------------------------------------------------------------------- +void CSendImageShack::Send() { + // check Netlib + if( !hNetlibUser ) { + //PrintError(1,TRUE); + return; + } + if (!m_pszFileName) { + m_pszFileName = (LPSTR)GetFileName(m_pszFile, DBVT_ASCIIZ); + } + if (!m_pszContentType) GetContentType(); + + // create new boundary + MFDR_Reset(); + + // initialize the netlib request + ZeroMemory(&m_nlhr, sizeof(m_nlhr)); + m_nlhr.cbSize = sizeof(m_nlhr); + m_nlhr.requestType = REQUEST_POST; + m_nlhr.flags = NLHRF_HTTP11; //NLHRF_DUMPASTEXT; + m_nlhr.szUrl = "http://www.imageshack.us/upload_api.php"; + m_nlhr.headersCount = 6; + { //NETLIBHTTPHEADER start + m_nlhr.headers=(NETLIBHTTPHEADER*)mir_alloc(sizeof(NETLIBHTTPHEADER)*m_nlhr.headersCount); + m_nlhr.headers[0].szName = "Referer"; + m_nlhr.headers[0].szValue = "http://www.imageshack.us/upload_api.php"; + m_nlhr.headers[1].szName = "Connection"; + m_nlhr.headers[1].szValue = "Keep-alive"; + m_nlhr.headers[2].szName = "AcceptLanguage"; + m_nlhr.headers[2].szValue = "en-us, pt-br"; + m_nlhr.headers[3].szName = "Host"; + m_nlhr.headers[3].szValue = "imageshack.us"; + m_nlhr.headers[4].szName = "User-Agent"; + m_nlhr.headers[4].szValue = __USER_AGENT_STRING; //szAgent; /; + //nlhr.headers[x].szName = "Authorization"; + //nlhr.headers[x].szValue = auth; //Basic base-64-authorization + + //$header .= "Content-type: multipart/form-data; boundary=" . part::getBoundary() . "\r\n"; + sprintf(m_nlheader_ContentType, "multipart/form-data; boundary=%s", m_MFDRboundary); + m_nlhr.headers[m_nlhr.headersCount-1].szName = "Content-Type"; + m_nlhr.headers[m_nlhr.headersCount-1].szValue = m_nlheader_ContentType; + } //NETLIBHTTPHEADER end + +//POST DATA file-header, init DATA with MultipartFormDataRequest + //$params[] = new filepart('fileupload', $file, basename($file), $contentType, 'iso-8859-1'); + //($this->sendStart($h);) + AppendToData("--"); + AppendToData(m_MFDRboundary); + AppendToData("\r\n"); + //($this->sendDispositionHeader($h);) + AppendToData("Content-Disposition: form-data; name=\""); + AppendToData("fileupload"); + AppendToData("\"; filename=\""); + AppendToData(m_pszFileName); + AppendToData("\""); + AppendToData("\r\n"); + //($this->sendContentTypeHeader($h);) + AppendToData("Content-Type: "); + AppendToData(m_pszContentType); + AppendToData("; charset="); + AppendToData("iso-8859-1"); + //($this->sendEndOfHeader($h);) + AppendToData("\r\n"); + AppendToData("\r\n"); + //Now we add the file binary ($this->sendData($h)) + FILE * fileId = _tfsopen(m_pszFile, _T("rb"), _SH_DENYWR ); + if( !fileId) { + //PrintError(1,TRUE); + return; + } + fseek(fileId, NULL, SEEK_END); + size_t lenFile = ftell(fileId); + size_t sizeDest = sizeof(char)*(m_nlhr.dataLength + lenFile + 1); + m_nlhr.pData = (char *) mir_realloc(m_nlhr.pData, sizeDest); + fseek(fileId, NULL, SEEK_SET ); + int i; + int ch = fgetc( fileId ); + for( i=0; (i < (int)lenFile ) && ( feof( fileId ) == 0 ); i++ ) { + m_nlhr.pData[m_nlhr.dataLength+i] = (char)ch; + ch = fgetc( fileId ); + } + m_nlhr.pData[sizeDest-1] = 0; //NULL Termination for binary data + m_nlhr.dataLength = (int)sizeDest - 1; + fclose(fileId); + //($this->sendEnd($h);) + AppendToData("\r\n"); + +//POST DATA footer (for "optimage", 1) +//POST DATA footer (for "optsize", optsize) + +//POST DATA footer (for "tags", tags) +//POST DATA footer (for "rembar", "yes" : "no") +//POST DATA footer (for "public", "yes" : "no") +//POST DATA footer (for "cookie", cookie) + +//POST DATA footer (for "key", DEVKEY_IMAGESHACK) + //($this->sendStart($h);) + AppendToData("--"); + AppendToData(m_MFDRboundary); + AppendToData("\r\n"); + //($this->sendDispositionHeader($h);) + AppendToData("Content-Disposition: form-data; name=\""); + AppendToData("key"); + AppendToData("\""); + //($this->sendTransferEncodingHeader($h); ) + AppendToData("\r\n"); + AppendToData("Content-Transfer-Encoding: "); + AppendToData("8bit"); //??"binary" + //($this->sendEndOfHeader($h);) + AppendToData("\r\n"); + AppendToData("\r\n"); + //($this->sendData($h);) + AppendToData(DEVKEY_IMAGESHACK); + //($this->sendEnd($h);) + AppendToData("\r\n"); + +//POST DATA Exit + //$postdata = "--" . part::getBoundary() . "--\r\n"; + AppendToData("--"); + AppendToData(m_MFDRboundary); + AppendToData("--\r\n"); + +//start upload thread + if (m_SendSync) { + m_bFreeOnExit = FALSE; + SendThread(); + return; + } + m_bFreeOnExit = TRUE; + mir_forkthread(&CSendImageShack::SendThreadWrapper, this); +} + +void CSendImageShack::SendThread() { + //send DATA and wait for m_nlreply + m_nlreply = (NETLIBHTTPREQUEST *) CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM) hNetlibUser, (LPARAM) &m_nlhr); + mir_freeAndNil(m_nlhr.pData); + mir_freeAndNil(m_nlhr.headers); + if(m_nlreply){ + if( m_nlreply->resultCode >= 200 && m_nlreply->resultCode < 300 ){ + m_nlreply->pData[m_nlreply->dataLength] = 0;// make sure its null terminated + const char* URL = NULL; + LPTSTR err = NULL; + URL = GetTagContent(m_nlreply->pData, "", ""); + if (URL && URL[0]!= NULL) { + m_Url = mir_strdup(URL); + if(m_SendSync) { + Exit(ACKRESULT_SUCCESS); + return; + } + m_ChatRoom ? svcSendChat(URL) : svcSendMsg(URL); + return; + } + else{ //check error mess from server + err = mir_a2t(GetTagContent(m_nlreply->pData, "")); + if (err && err[0]!= NULL) { //parsed err messege + Error(NULL, err); + } + else{ //fallback to server response mess + mir_freeAndNil(err); + err = mir_a2t(m_nlreply->pData); + } + mir_free(err); + } + } + else { + Error(NULL, _T("Upload server did not respond timely.")); + } + CallService(MS_NETLIB_FREEHTTPREQUESTSTRUCT, 0, (LPARAM) m_nlreply); + m_nlreply = NULL; + } + else { + Error(SS_ERR_INIT, m_pszSendTyp); + } + Exit(ACKRESULT_FAILED); +} + +void CSendImageShack::SendThreadWrapper(void * Obj) { + reinterpret_cast(Obj)->SendThread(); +} + +//--------------------------------------------------------------------------- +void CSendImageShack::MFDR_Reset() { + char Temp[64]; + DWORD dwBoundaryRand1 = GetTickCount(); + DWORD dwBoundaryRand2 = rand(); + + mir_freeAndNil(m_MFDRboundary); + sprintf(Temp, "B-O-U-N-D-A-R-Y%u%u", dwBoundaryRand1, dwBoundaryRand2); + mir_stradd(m_MFDRboundary,Temp); +} + +void CSendImageShack::GetContentType() { + if (m_pszContentType) mir_freeAndNil(m_pszContentType); + LPSTR FileExtension = (LPSTR)GetFileExt(m_pszFile, DBVT_ASCIIZ); + + if ((strcmp(FileExtension, ".jpeg")==0) || (strcmp(FileExtension, ".jpe")==0) || (strcmp(FileExtension ,".jpg")==0)) + m_pszContentType="image/jpeg"; + else if (strcmp(FileExtension, ".bmp")==0) + m_pszContentType="image/bmp"; + else if (strcmp(FileExtension, ".png")==0) + m_pszContentType="image/png"; + else if (strcmp(FileExtension, ".gif")==0) + m_pszContentType="image/gif"; + else if ((strcmp(FileExtension, ".tif")==0) || (strcmp(FileExtension, ".tiff")==0)) + m_pszContentType="image/tiff"; + else + m_pszContentType="application/octet-stream"; + + mir_free(FileExtension); + return; +} + +void CSendImageShack::AppendToData(const char *pszVal) { + if (!m_nlhr.pData) { + m_nlhr.pData = mir_strdup(pszVal); + m_nlhr.dataLength = (int)strlen(pszVal); + } + else { + size_t lenVal = strlen(pszVal); + size_t sizeNew = sizeof(char)*(m_nlhr.dataLength + lenVal + 1); + m_nlhr.pData = (char*) mir_realloc(m_nlhr.pData, sizeNew); + + strcpy(m_nlhr.pData + sizeof(char)*m_nlhr.dataLength, pszVal); + m_nlhr.pData[sizeNew-1] = 0; + m_nlhr.dataLength = (int)sizeNew -1; + } +} + +//--------------------------------------------------------------------------- +const char * CSendImageShack::GetTagContent(char * pszSource, const char * pszTagStart, const char * pszTagEnd) { + char * b = strstr(pszSource, pszTagStart); + if (!b) return NULL; + b += strlen(pszTagStart); + char * e = strstr(b, pszTagEnd); + if (e) *e = 0; + return b; +} + diff --git a/plugins/SendScreenshotPlus/src/CSendImageShack.h b/plugins/SendScreenshotPlus/src/CSendImageShack.h new file mode 100644 index 0000000000..eae406aca9 --- /dev/null +++ b/plugins/SendScreenshotPlus/src/CSendImageShack.h @@ -0,0 +1,77 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* +Copyright 2000-2009 Miranda ICQ/IM project, + +This file is part of Send Screenshot Plus, a Miranda IM plugin. +Copyright (c) 2010 Ing.U.Horn + +Parts of this file based on original sorce code +(c) 2004-2006 Srgio Vieira Rolanski (portet from Borland C++) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +File name : $HeadURL: http://merlins-miranda.googlecode.com/svn/trunk/miranda/plugins/SendSSPlus/CSendImageShack.h $ +Revision : $Revision: 13 $ +Last change on : $Date: 2010-04-02 02:54:30 +0400 (Пт, 02 апр 2010) $ +Last change by : $Author: ing.u.horn $ + +*/ + +#ifndef _CSEND_IMAGESHACK_H +#define _CSEND_IMAGESHACK_H + +//--------------------------------------------------------------------------- +#include "global.h" +#include "Utils.h" +#include "CSend.h" + +//--------------------------------------------------------------------------- +class CSendImageShack : public CSend { + public: + // Deklaration Standardkonstruktor/Standarddestructor + CSendImageShack(HWND Owner, HANDLE hContact, bool bFreeOnExit); + ~CSendImageShack(); + + void Send(); + void SendSync(bool Sync) {m_SendSync = Sync;}; + LPSTR GetURL(){return m_Url;}; + LPSTR GetError(){return mir_t2a(m_ErrorMsg);}; + + protected: + LPSTR m_pszFileName; + NETLIBHTTPREQUEST m_nlhr; + NETLIBHTTPREQUEST* m_nlreply; + NETLIBHTTPHEADER* m_nlheader; + char m_nlheader_ContentType[64]; + LPSTR m_Url; + + void AppendToData(const char *pszVal); //append to netlib DATA + LPSTR m_pszContentType; //hold mimeType (does not need free) + void GetContentType(); //get mimeType + const char * GetTagContent(char * pszSource, const char * pszTagStart, const char * pszTagEnd); + + char* m_MFDRboundary; + void MFDR_Reset(); + + bool m_SendSync; + void SendThread(); + static void SendThreadWrapper(void * Obj); + +}; + +//--------------------------------------------------------------------------- + +#endif diff --git a/plugins/SendScreenshotPlus/src/DevKey.h b/plugins/SendScreenshotPlus/src/DevKey.h new file mode 100644 index 0000000000..2999f74466 --- /dev/null +++ b/plugins/SendScreenshotPlus/src/DevKey.h @@ -0,0 +1,3 @@ +#ifndef DEVKEY_IMAGESHACK +#define DEVKEY_IMAGESHACK "IA5ZRTV6fb6256ccbc3c38650bdce6e6dcfc9e55" /*Test DevKey*/ +#endif diff --git a/plugins/SendScreenshotPlus/src/Main.cpp b/plugins/SendScreenshotPlus/src/Main.cpp new file mode 100644 index 0000000000..75e5655ac5 --- /dev/null +++ b/plugins/SendScreenshotPlus/src/Main.cpp @@ -0,0 +1,364 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* +Copyright 2000-2009 Miranda ICQ/IM project, + +This file is part of Send Screenshot Plus, a Miranda IM plugin. +Copyright (c) 2010 Ing.U.Horn + +Parts of this file based on original sorce code +(c) 2004-2006 Srgio Vieira Rolanski (portet from Borland C++) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +File name : $HeadURL: http://merlins-miranda.googlecode.com/svn/trunk/miranda/plugins/SendSSPlus/Main.cpp $ +Revision : $Revision: 22 $ +Last change on : $Date: 2010-05-02 21:25:02 +0400 (Вс, 02 май 2010) $ +Last change by : $Author: ing.u.horn $ + +*/ + +//--------------------------------------------------------------------------- +#include "main.h" + +// Prototypes /////////////////////////////////////////////////////////////////////////// +//LIST_INTERFACE li; +FI_INTERFACE *FIP = 0; +HINSTANCE hInst; //!< Global reference to the application +MGLOBAL myGlobals; +int hLangpack; + + +//Information gathered by Miranda, displayed in the plugin pane of the Option Dialog +PLUGININFOEX pluginInfo={ + sizeof(PLUGININFOEX), + __PLUGIN_NAME, // altered here and on file listing, so as not to match original + PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM), + __DESC, + __AUTHOR, + __AUTHOREMAIL, + __COPYRIGHT, + __AUTHORWEB, + UNICODE_AWARE, //doesn't replace anything built-in + MIID_PLUGIN +}; + +//static char szSendSS[]=SZ_SENDSS; + +HANDLE hsvc_SendScreenshot=0; +HANDLE hsvc_SendDesktop=0; +HANDLE hsvc_EditBitmap=0; +HANDLE hsvc_Send2ImageShack=0; + +HANDLE hNetlibUser = 0; //!< Netlib Register User +HANDLE hFolderScreenshot=0; + +HANDLE hhook_ModulesLoad=0; +HANDLE hhook_SystemPShutdown=0; + + +// Functions //////////////////////////////////////////////////////////////////////////// + +/*--------------------------------------------------------------------------- +* DLL entry point - Required to store the instance handle +*/ +extern "C" BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { + hInst = hinstDLL; + // Freeing some unneeded resources + DisableThreadLibraryCalls(GetModuleHandle(_T("sendss.dll"))); + + return TRUE; +} + +/*--------------------------------------------------------------------------- +* Called by Miranda to get the information associated to this plugin. +* It only returns the PLUGININFO structure, without any test on the version +* @param mirandaVersion The version of the application calling this function +*/ +extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion) { + pluginInfo.cbSize = sizeof(PLUGININFOEX); + myGlobals.mirandaVersion = mirandaVersion; + return &pluginInfo; +} + +extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = { MIID_PLUGIN, MIID_LAST }; + +/*--------------------------------------------------------------------------- +* Initializes the services provided and the link to those needed +* Called when the plugin is loaded into Miranda +*/ +extern "C" int __declspec(dllexport) Load(void) { + mir_getLP(&pluginInfo); + INT_PTR result = CALLSERVICE_NOTFOUND; + + if(ServiceExists(MS_IMG_GETINTERFACE)) + result = CallService(MS_IMG_GETINTERFACE, FI_IF_VERSION, (LPARAM)&FIP); + + if(FIP == NULL || result != S_OK) { + MessageBoxEx(NULL, TranslateT("Fatal error, image services not found. Send Screenshot will be disabled."), _T("Error"), MB_OK | MB_ICONERROR | MB_APPLMODAL, 0); + return 1; + } + + // load icon library (use UserInfoEx icon Pack) + IcoLib_LoadModule(); + + hhook_ModulesLoad = HookEvent(ME_SYSTEM_MODULESLOADED, hook_ModulesLoaded); + //hhook_options_init = HookEvent(ME_OPT_INITIALISE, hook_options_init); + //hhook_OkToExit = HookEvent(ME_SYSTEM_OKTOEXIT, hook_OkToExit); + hhook_SystemPShutdown = HookEvent(ME_SYSTEM_PRESHUTDOWN, hook_SystemPShutdown); + + AddMenuItems(); + RegisterServices(); + + return 0; +} + +int hook_ModulesLoaded(WPARAM, LPARAM) { + + myGlobals.PopUpExist = ServiceExists(MS_POPUP_ADDPOPUP); + myGlobals.PopUpActionsExist = ServiceExists(MS_POPUP_REGISTERACTIONS); + myGlobals.PluginHTTPExist = ServiceExists(MS_HTTP_ACCEPT_CONNECTIONS); + myGlobals.PluginFTPExist = ServiceExists(MS_FTPFILE_SHAREFILE); +// myGlobals.PluginUserinfoEx = ServiceExists(MS_USERINFO_VCARD_EXPORT); + + // Netlib register + if (!NetlibInit()){ + ; + } + + // load my button class + if(!ServiceExists("UserInfo/vCard/Export")) { + CtrlButtonLoadModule(); + } + + // Folders plugin support + if (ServiceExists(MS_FOLDERS_REGISTER_PATH)) { + hFolderScreenshot = (HANDLE) FoldersRegisterCustomPathT("SendSS", "Screenshots", + _T(PROFILE_PATH)_T("\\")_T(CURRENT_PROFILE)_T("\\Screenshots")); + } + + return 0; +} + +/*--------------------------------------------------------------------------- +* Prepare the plugin to stop +* Called by Miranda when it will exit or when the plugin gets deselected +*/ +extern "C" int __declspec(dllexport) Unload(void) { + UnhookEvent(hhook_SystemPShutdown); + + DestroyServiceFunction(MS_SENDSS_OPENDIALOG); + DestroyServiceFunction(MS_SENDSS_EDITBITMAP); + DestroyServiceFunction(MS_SENDSS_SENDDESKTOP); + DestroyServiceFunction(MS_SENDSS_SEND2IMAGESHACK); + return 0; +} + +int hook_SystemPShutdown(WPARAM wParam, LPARAM lParam) { + UnhookEvent(hhook_ModulesLoad); + + // Netlib unregister + NetlibClose(); + + // uninitialize classes + CtrlButtonUnloadModule(); + + return 0; +} + +//--------------------------------------------------------------------------- +// Netlib +HANDLE NetlibInit(void) { + NETLIBUSER nlu = {0}; + nlu.cbSize = sizeof(nlu); + nlu.szSettingsModule = (char*)PLUGNAME; + nlu.szDescriptiveName = Translate("SendSS HTTP connections"); + nlu.flags = NUF_OUTGOING|NUF_HTTPCONNS; //|NUF_NOHTTPSOPTION; + hNetlibUser = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nlu); + return hNetlibUser; +} + +void NetlibClose(void) { + Netlib_CloseHandle(hNetlibUser); +} + + +//--------------------------------------------------------------------------- +// Callback function of service +// 1. Send a screenshot of the desktop to the selected contact +// wParam = contact handle +// lParam = 0 +// 2. Open the capture dialog in take screenshot only mode (it will not be sent) +// wParam = 0 +// lParam = anything but 0 +INT_PTR service_CaptureAndSendDesktop(WPARAM wParam, LPARAM lParam) { + LPTSTR pszPath = NULL; + LPSTR pszProto = NULL; + bool bChatRoom; + + TfrmMain *frmMain=new TfrmMain(); + if (!frmMain) { + MessageBoxEx(NULL, TranslateT("Could not create main dialog."), TranslateT("Error"), MB_OK | MB_ICONERROR | MB_APPLMODAL, 0); + return -1; + } + pszPath = GetCustomPath(); + + pszProto = (LPSTR)CallService(MS_PROTO_GETCONTACTBASEPROTO,wParam,0); + bChatRoom = DBGetContactSettingByte((HANDLE)wParam, pszProto, "ChatRoom", 0) != 0; + frmMain->m_opt_chkTimed = false; + frmMain->m_opt_tabCapture = 1; + frmMain->m_opt_cboxDesktop = 0; + frmMain->m_opt_chkEditor = false; + frmMain->m_opt_cboxSendBy = bChatRoom ? SS_IMAGESHACK:SS_FILESEND; + frmMain->Init(pszPath, (HANDLE)wParam); // this method create the window hidden. + frmMain->btnCaptureClick(); // this method will call Close() + mir_free(pszPath); + return 0; +} + +//--------------------------------------------------------------------------- +// Callback function of service for contact menu and main menu +// wParam = contact handle +// lParam = 0 +INT_PTR service_OpenCaptureDialog(WPARAM wParam, LPARAM lParam) { + LPTSTR pszPath = NULL; + + TfrmMain *frmMain=new TfrmMain(); + if (!frmMain) { + MessageBoxEx(NULL, TranslateT("Could not create main dialog."), TranslateT("Error"), MB_OK | MB_ICONERROR | MB_APPLMODAL, 0); + return -1; + } + + pszPath = GetCustomPath(); + frmMain->Init(pszPath, (HANDLE)wParam); + mir_free(pszPath); + frmMain->Show(); + return 0; +} + +//--------------------------------------------------------------------------- +// Edit a in-memory bitmap on the edit window +// wParam = (SENDSSCB) callback function address to call when editing is done +// lParam = (HBITMAP) bitmap handle, a copy is made so the calling function can free this handle after the service function returns +// Returns: +INT_PTR service_EditBitmap(WPARAM wParam, LPARAM lParam) { +/* TfrmEdit *frmEdit=new TfrmEdit(NULL); + if (!frmEdit) + return -1; + + Graphics::TBitmap *bitmap=new Graphics::TBitmap(); + if (!bitmap) + return -2; + + bitmap->Handle = (void*)lParam; + frmEdit->InitEditor(bitmap); // a copy of the bitmap is made inside this function + frmEdit->Show(); + delete bitmap; +*/ + return 0; +} + +//--------------------------------------------------------------------------- +// Callback function of service for sending image to imageshack.us +// wParam = (char*)filename +// lParam = (HANDLE)contact (can be null) +INT_PTR service_Send2ImageShack(WPARAM wParam, LPARAM lParam) { + LPSTR result = NULL; + CSendImageShack* cSend = new CSendImageShack(NULL, (HANDLE)lParam, false); + cSend->m_pszFile = mir_a2t((char*)wParam); + cSend->m_bDeleteAfterSend = FALSE; + if (lParam != NULL) { + cSend->Send(); + return 0; + } + cSend->SendSync(TRUE); + cSend->Send(); + if (cSend->GetURL()) { + result = mir_strdup(cSend->GetURL()); + } + else { + result = cSend->GetError(); + } + delete cSend; + return (INT_PTR)result; +} + +//--------------------------------------------------------------------------- +// Add SendSS menu item in contact menu +void AddMenuItems(void) { + CLISTMENUITEM mi={0}; + + // Common + mi.cbSize = sizeof(mi); + // support new genmenu style + mi.flags = CMIF_ROOTHANDLE|CMIF_UNICODE; + mi.hParentMenu = HGENMENU_ROOT; + + // Add item to contact menu + mi.position = 1000000; + mi.ptszName = LPGENT("Send Screenshot"); + mi.hIcon = IcoLib_GetIcon(ICO_PLUG_SSWINDOW2); + mi.pszService = MS_SENDSS_OPENDIALOG; + Menu_AddContactMenuItem(&mi); + + // Add item to contact menu + mi.position = 1000001; + mi.ptszName = LPGENT("Send desktop screenshot"); + mi.hIcon = IcoLib_GetIcon(ICO_PLUG_SSWINDOW2); + mi.pszService = MS_SENDSS_SENDDESKTOP; + Menu_AddContactMenuItem(&mi); + + // Add item to main menu + mi.position = 1000001; + mi.ptszName = LPGENT("Take a screenshot"); + mi.hIcon = IcoLib_GetIcon(ICO_PLUG_SSWINDOW2); + mi.pszService = MS_SENDSS_OPENDIALOG; + Menu_AddMainMenuItem(&mi); +} + +//--------------------------------------------------------------------------- +// Register Send screenshot services +int RegisterServices(void) { + hsvc_SendScreenshot = CreateServiceFunction(MS_SENDSS_OPENDIALOG, service_OpenCaptureDialog); + if (!hsvc_SendScreenshot) + MessageBoxEx(NULL, TranslateT("Could not register miranda service."), _T("MS_SENDSS_OPENDIALOG"), MB_OK | MB_ICONERROR | MB_APPLMODAL, 0); + + hsvc_SendDesktop = CreateServiceFunction(MS_SENDSS_SENDDESKTOP, service_CaptureAndSendDesktop); + if (!hsvc_SendDesktop) + MessageBoxEx(NULL, TranslateT("Could not register miranda service."), _T("MS_SENDSS_SENDDESKTOP"), MB_OK | MB_ICONERROR | MB_APPLMODAL, 0); + + hsvc_EditBitmap = CreateServiceFunction(MS_SENDSS_EDITBITMAP, service_EditBitmap); + if (!hsvc_EditBitmap) + MessageBoxEx(NULL, TranslateT("Could not register miranda service."), _T("MS_SENDSS_EDITBITMAP"), MB_OK | MB_ICONERROR | MB_APPLMODAL, 0); + + hsvc_Send2ImageShack = CreateServiceFunction(MS_SENDSS_SEND2IMAGESHACK, service_Send2ImageShack); + if (!hsvc_Send2ImageShack) + MessageBoxEx(NULL, TranslateT("Could not register miranda service."), _T("MS_SENDSS_SEND2IMAGESHACK"), MB_OK | MB_ICONERROR | MB_APPLMODAL, 0); + + return 0; +} + +//--------------------------------------------------------------------------- +LPTSTR GetCustomPath() { + LPTSTR pszPath = NULL; + pszPath = Utils_ReplaceVarsT(_T("%miranda_userdata%\\Screenshots")); + if (hFolderScreenshot) { + TCHAR szPath[1024] = {'\0'}; + FoldersGetCustomPathT(hFolderScreenshot, szPath, 1024, pszPath); + mir_freeAndNil(pszPath); + pszPath = mir_tstrdup(szPath); + } + return pszPath; +} diff --git a/plugins/SendScreenshotPlus/src/Main.h b/plugins/SendScreenshotPlus/src/Main.h new file mode 100644 index 0000000000..67059fb73c --- /dev/null +++ b/plugins/SendScreenshotPlus/src/Main.h @@ -0,0 +1,65 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* +Copyright 2000-2009 Miranda ICQ/IM project, + +This file is part of Send Screenshot Plus, a Miranda IM plugin. +Copyright (c) 2010 Ing.U.Horn + +Parts of this file based on original sorce code +(c) 2004-2006 Srgio Vieira Rolanski (portet from Borland C++) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +File name : $HeadURL: http://merlins-miranda.googlecode.com/svn/trunk/miranda/plugins/SendSSPlus/Main.h $ +Revision : $Revision: 22 $ +Last change on : $Date: 2010-05-02 21:25:02 +0400 (Вс, 02 май 2010) $ +Last change by : $Author: ing.u.horn $ + +*/ + +#ifndef MainH +#define MainH + +//--------------------------------------------------------------------------- +#include "global.h" +#include "UMainForm.h" +//#include "UEditForm.h" + +extern HANDLE hNetlibUser; + +//--------------------------------------------------------------------------- + +HANDLE NetlibInit(void); +void NetlibClose(void); + +void IcoLib_LoadModule(void); +void AddMenuItems(void); +int RegisterServices(void); + +int hook_ModulesLoaded(WPARAM, LPARAM); +int hook_SystemPShutdown(WPARAM wParam, LPARAM lParam); + +INT_PTR service_CaptureAndSendDesktop(WPARAM wParam, LPARAM lParam); +INT_PTR service_OpenCaptureDialog(WPARAM wParam, LPARAM lParam); +INT_PTR service_EditBitmap(WPARAM wParam, LPARAM lParam); +INT_PTR service_Send2ImageShack(WPARAM wParam, LPARAM lParam); + +int OnSendScreenShot(WPARAM wParam, LPARAM lParam); + +LPTSTR GetCustomPath(); + +//--------------------------------------------------------------------------- +#endif diff --git a/plugins/SendScreenshotPlus/src/UAboutForm.cpp b/plugins/SendScreenshotPlus/src/UAboutForm.cpp new file mode 100644 index 0000000000..f4ea2b6bc2 --- /dev/null +++ b/plugins/SendScreenshotPlus/src/UAboutForm.cpp @@ -0,0 +1,212 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* +Copyright 2000-2009 Miranda ICQ/IM project, + +This file is part of Send Screenshot Plus, a Miranda IM plugin. +Copyright (c) 2010 Ing.U.Horn + +Parts of this file based on original sorce code +(c) 2004-2006 Srgio Vieira Rolanski (portet from Borland C++) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +File name : $HeadURL: http://merlins-miranda.googlecode.com/svn/trunk/miranda/plugins/SendSSPlus/UAboutForm.cpp $ +Revision : $Revision: 22 $ +Last change on : $Date: 2010-05-02 21:25:02 +0400 (Вс, 02 май 2010) $ +Last change by : $Author: ing.u.horn $ + +*/ + +#include "UAboutForm.h" + +//--------------------------------------------------------------------------- +TfrmAbout::CHandleMapping TfrmAbout::_HandleMapping; + +LRESULT CALLBACK TfrmAbout::DlgTfrmAbout(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + if (msg == WM_CTLCOLOREDIT || msg == WM_CTLCOLORSTATIC) { + switch ( GetWindowLongPtr(( HWND )lParam, GWL_ID )) { + case IDC_WHITERECT: + case IDC_BUILDTIME: + case IDC_CREDIT: + case IDC_LICENSE: + SetTextColor((HDC)wParam,GetSysColor(COLOR_WINDOWTEXT)); + break; + default: + return FALSE; + } + SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW)); + return (LRESULT)GetStockObject(WHITE_BRUSH); //GetSysColorBrush(COLOR_WINDOW); + } + + CHandleMapping::iterator wnd(_HandleMapping.end()); + if (msg == WM_INITDIALOG) { + wnd = _HandleMapping.insert(CHandleMapping::value_type(hWnd, reinterpret_cast(lParam))).first; + reinterpret_cast(lParam)->m_hWnd = hWnd; + return wnd->second->wmInitdialog(wParam, lParam); + } + else { + wnd = _HandleMapping.find(hWnd); + } + if (wnd == _HandleMapping.end()) { // something screwed up + return FALSE; //dialog! do not use ::DefWindowProc(hWnd, msg, wParam, lParam); + } + + switch (msg) + { + // case WM_INITDIALOG: done on top + case WM_COMMAND: + return wnd->second->wmCommand(wParam, lParam); + break; + case WM_CLOSE: + return wnd->second->wmClose(wParam, lParam); + break; + case WM_DESTROY: + delete wnd->second; + break; + } + return FALSE; +} + +//--------------------------------------------------------------------------- +//WM_INITDIALOG: +LRESULT TfrmAbout::wmInitdialog(WPARAM wParam, LPARAM lParam) { + char* pszMsg = NULL; + HRSRC hResInfo; + DWORD ResSize; + TCHAR oldTitle[256], newTitle[256]; + LPTSTR temp = NULL; + LPTSTR pszTitle = NULL; + // Headerbar + LPTSTR pszPlug = mir_a2t(__PLUGIN_NAME); + LPTSTR pszVer = mir_a2t(__VERSION_STRING_DOT); + GetDlgItemText( m_hWnd, IDC_HEADERBAR, oldTitle, SIZEOF( oldTitle )); + mir_sntprintf( newTitle, SIZEOF(newTitle), oldTitle, pszPlug, pszVer ); + mir_freeAndNil(pszPlug); + mir_freeAndNil(pszVer); + SetDlgItemText( m_hWnd, IDC_HEADERBAR, newTitle ); + SendMessage(GetDlgItem(m_hWnd, IDC_HEADERBAR), WM_SETICON, 0, (WPARAM)IcoLib_GetIcon(ICO_PLUG_SSWINDOW1, true)); + + //Buildtime + mir_sntprintf(newTitle,SIZEOF(newTitle),TranslateT("Built %s %s"),_T(__DATE__),_T(__TIME__)); + SetDlgItemText(m_hWnd,IDC_BUILDTIME,newTitle); + + //License + { mir_tcsadd(pszTitle ,_T(__COPYRIGHT)); + mir_tcsadd(pszTitle ,_T("\r\n\r\n")); + + hResInfo = FindResource(hInst,MAKEINTRESOURCE(IDR_LICENSE),_T("TEXT")); + ResSize = SizeofResource(hInst,hResInfo); + pszMsg = (char*)LockResource(LoadResource(hInst,hResInfo)); + temp = mir_a2t(pszMsg); + temp [ResSize] = 0; //LockResource is not NULL terminatet !! + mir_tcsadd(pszTitle ,temp); + mir_freeAndNil(temp); + SetDlgItemText(m_hWnd,IDC_LICENSE, pszTitle); + mir_freeAndNil(pszTitle); + } + + //Credit + { + hResInfo = FindResource(hInst,MAKEINTRESOURCE(IDR_CREDIT),_T("TEXT")); + ResSize = SizeofResource(hInst,hResInfo); + pszMsg = (char*)LockResource(LoadResource(hInst,hResInfo)); + temp = mir_a2t(pszMsg); + temp [ResSize] = 0; //LockResource is not NULL terminatet !! + mir_tcsadd(pszTitle ,temp); + mir_freeAndNil(temp); + SetDlgItemText(m_hWnd,IDC_CREDIT, pszTitle); + mir_freeAndNil(pszTitle); + } + + SendMessage(m_hWnd, WM_SETICON, ICON_BIG, (LPARAM)IcoLib_GetIcon(ICO_PLUG_SSWINDOW1, true)); + SendMessage(m_hWnd, WM_SETICON, ICON_SMALL, (LPARAM)IcoLib_GetIcon(ICO_PLUG_SSWINDOW2)); + + //init controls + btnPageClick(); + SendMessage(GetDlgItem(m_hWnd, IDA_CONTRIBLINK), BUTTONSETDEFAULT, (WPARAM)1, NULL); + + TranslateDialogDefault(m_hWnd); + return FALSE; +} + +//WM_COMMAND: +LRESULT TfrmAbout::wmCommand(WPARAM wParam, LPARAM lParam) { + //--------------------------------------------------------------------------- + if (HIWORD(wParam) == BN_CLICKED) { + int IDControl = LOWORD(wParam); + HWND hCtrl = (HWND)lParam; + switch(IDControl) { + case IDCANCEL: + case IDCLOSE: + break; + case IDA_btnClose: + Close(); + break; + case IDA_CONTRIBLINK: + m_Page = m_Page ? 0 : 1; + btnPageClick(); + break; + default: + break; + } + } + return FALSE; +} + +//WM_CLOSE: +LRESULT TfrmAbout::wmClose(WPARAM wParam, LPARAM lParam) { + SendMessage(m_hWndOwner,UM_CLOSING, (WPARAM)m_hWnd, (LPARAM)IDD_UAboutForm); + DestroyWindow(m_hWnd); + return FALSE; +} + +//--------------------------------------------------------------------------- +// Standard konstruktor/destruktor +TfrmAbout::TfrmAbout(HWND Owner) { + m_hWndOwner = Owner; + // create window + m_hWnd = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_UAboutForm),0, (DLGPROC)DlgTfrmAbout,(LPARAM)this); + //register object + _HandleMapping.insert(CHandleMapping::value_type(m_hWnd, this)); + //init page + m_Page = 1; +} + +TfrmAbout::~TfrmAbout() { + _HandleMapping.erase(m_hWnd); +} + +//--------------------------------------------------------------------------- +void TfrmAbout::btnPageClick() { + HWND hCtrl = GetDlgItem(m_hWnd, IDA_CONTRIBLINK); + if(!m_Page) { + ShowWindow(GetDlgItem(m_hWnd, IDC_CREDIT), SW_HIDE); + ShowWindow(GetDlgItem(m_hWnd, IDC_LICENSE), SW_SHOW); + SendDlgItemMessage(m_hWnd, IDA_CONTRIBLINK, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Credits >"), MBF_TCHAR); + HICON hIcon = IcoLib_GetIcon(ICO_PLUG_ARROWR); + SendMessage(hCtrl, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon); + SetWindowText(hCtrl, hIcon ? TranslateT("Credits") : TranslateT("Credits >")); + } + else { + ShowWindow(GetDlgItem(m_hWnd, IDC_CREDIT), SW_SHOW); + ShowWindow(GetDlgItem(m_hWnd, IDC_LICENSE), SW_HIDE); + SendDlgItemMessage(m_hWnd, IDA_CONTRIBLINK, BUTTONADDTOOLTIP, (WPARAM)TranslateT("< Copyright"), MBF_TCHAR); + HICON hIcon = IcoLib_GetIcon(ICO_PLUG_ARROWL); + SendMessage(hCtrl, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon); + SetWindowText(hCtrl, hIcon ? TranslateT("Copyright") : TranslateT("< Copyright")); + } +} diff --git a/plugins/SendScreenshotPlus/src/UAboutForm.h b/plugins/SendScreenshotPlus/src/UAboutForm.h new file mode 100644 index 0000000000..d9d598aeb6 --- /dev/null +++ b/plugins/SendScreenshotPlus/src/UAboutForm.h @@ -0,0 +1,69 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* +Copyright 2000-2009 Miranda ICQ/IM project, + +This file is part of Send Screenshot Plus, a Miranda IM plugin. +Copyright (c) 2010 Ing.U.Horn + +Parts of this file based on original sorce code +(c) 2004-2006 Srgio Vieira Rolanski (portet from Borland C++) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +File name : $HeadURL: http://merlins-miranda.googlecode.com/svn/trunk/miranda/plugins/SendSSPlus/UAboutForm.h $ +Revision : $Revision: 19 $ +Last change on : $Date: 2010-04-09 03:24:04 +0400 (Пт, 09 апр 2010) $ +Last change by : $Author: ing.u.horn $ + +*/ + +#ifndef UAboutFormH +#define UAboutFormH +//--------------------------------------------------------------------------- +#include "global.h" + +//--------------------------------------------------------------------------- +class TfrmAbout{ + + public: + // Deklaration Standardkonstruktor/Standarddestructor + TfrmAbout(HWND Owner); + ~TfrmAbout(); + + HWND m_hWndOwner; + void Show(){ShowWindow(m_hWnd,SW_SHOW);} + void Hide(){ShowWindow(m_hWnd,SW_HIDE);} + void Close(){SendMessage(m_hWnd,WM_CLOSE,0,0);} + + private: + HWND m_hWnd; + + protected: + UINT m_Page; + typedef std::map CHandleMapping; + static CHandleMapping _HandleMapping; + static LRESULT CALLBACK DlgTfrmAbout(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); + + LRESULT wmInitdialog(WPARAM wParam, LPARAM lParam); + LRESULT wmCommand(WPARAM wParam, LPARAM lParam); + LRESULT wmClose(WPARAM wParam, LPARAM lParam); + + void btnPageClick(); + +}; + +//--------------------------------------------------------------------------- +#endif diff --git a/plugins/SendScreenshotPlus/src/UMainForm.cpp b/plugins/SendScreenshotPlus/src/UMainForm.cpp new file mode 100644 index 0000000000..2061f80d83 --- /dev/null +++ b/plugins/SendScreenshotPlus/src/UMainForm.cpp @@ -0,0 +1,1180 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* +Copyright 2000-2009 Miranda ICQ/IM project, + +This file is part of Send Screenshot Plus, a Miranda IM plugin. +Copyright (c) 2010 Ing.U.Horn + +Parts of this file based on original sorce code +(c) 2004-2006 Srgio Vieira Rolanski (portet from Borland C++) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +File name : $HeadURL: http://merlins-miranda.googlecode.com/svn/trunk/miranda/plugins/SendSSPlus/UMainForm.cpp $ +Revision : $Revision: 22 $ +Last change on : $Date: 2010-05-02 21:25:02 +0400 (Вс, 02 май 2010) $ +Last change by : $Author: ing.u.horn $ + +*/ + +#include "UMainForm.h" +#include "UAboutForm.h" +//#include "UEditForm.h" + +//--------------------------------------------------------------------------- +INT_PTR CALLBACK TfrmMain::DlgProc_CaptureWindow(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { +// main message handling is done inside TfrmMain::DlgTfrmMain + switch (uMsg) { + case WM_INITDIALOG: + Static_SetIcon(GetDlgItem(hDlg, ID_imgTarget), IcoLib_GetIcon(ICO_PLUG_SSTARGET)); + SetDlgItemText(hDlg, ID_edtCaption, _T("Drag&&Drop the target on the desired window.")); + TranslateDialogDefault(hDlg); + break; + case WM_CTLCOLOREDIT: //ctrl is NOT read-only or disabled + case WM_CTLCOLORSTATIC: //ctrl is read-only or disabled + // make the rectangle on the top white + switch (GetWindowLongPtr((HWND)lParam, GWL_ID)) { + case IDC_WHITERECT: + case ID_chkClientArea: + case ID_lblDropInfo: + case ID_edtCaption: + case ID_edtCaptionLabel: + case ID_edtSize: + case ID_edtSizeLabel: + case ID_bvlTarget: + case ID_imgTarget: + SetBkColor((HDC)wParam,GetSysColor(COLOR_WINDOW)); + SetTextColor((HDC)wParam,GetSysColor(COLOR_WINDOWTEXT)); + + //SetBkMode((HDC)wParam,OPAQUE); + //return (INT_PTR)GetSysColorBrush(COLOR_WINDOW); + return (LRESULT)GetStockObject(WHITE_BRUSH); + break; + default: + SetBkMode((HDC)wParam, TRANSPARENT); + return (LRESULT)GetStockObject(NULL_BRUSH); + break; + } + break; //this return false + case WM_COMMAND: + SendMessage(GetParent(hDlg), uMsg, wParam, lParam); + break; + case WM_MOUSEMOVE: + SendMessage(GetParent(hDlg), UM_TAB1, uMsg, 0); + break; + case WM_NOTIFY: + SendMessage(GetParent(hDlg), uMsg, wParam, lParam); + break; + case WM_DESTROY: + break; + } + return FALSE; +} + +//--------------------------------------------------------------------------- +INT_PTR CALLBACK TfrmMain::DlgProc_CaptureDesktop(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { +// main message handling is done inside TfrmMain::DlgTfrmMain + switch (uMsg) { + case WM_INITDIALOG: + Static_SetIcon(GetDlgItem(hDlg, ID_imgTarget), IcoLib_GetIcon(ICO_PLUG_SSMONITOR)); + break; + case WM_CTLCOLOREDIT: + case WM_CTLCOLORSTATIC: + // make the rectangle on the top white + switch (GetWindowLongPtr((HWND)lParam, GWL_ID)) { + case IDC_WHITERECT: + case ID_lblDropInfo: + case ID_edtCaption: + case ID_edtCaptionLabel: + case ID_edtSize: + case ID_edtSizeLabel: + case ID_bvlTarget: + case ID_imgTarget: + SetBkColor((HDC)wParam,GetSysColor(COLOR_WINDOW)); + SetTextColor((HDC)wParam,GetSysColor(COLOR_WINDOWTEXT)); + return (LRESULT)GetStockObject(WHITE_BRUSH); + break; + default: + SetBkMode((HDC)wParam, TRANSPARENT); + return (LRESULT)GetStockObject(NULL_BRUSH); + break; + } + break; + case WM_COMMAND: + SendMessage(GetParent(hDlg), uMsg, wParam, lParam); + break; + case WM_NOTIFY: + SendMessage(GetParent(hDlg), uMsg, wParam, lParam); + break; + case WM_DESTROY: + break; + } + return FALSE; +} + +//--------------------------------------------------------------------------- + +TfrmMain::CHandleMapping TfrmMain::_HandleMapping; + +LRESULT CALLBACK TfrmMain::DlgTfrmMain(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + if (msg == WM_CTLCOLOREDIT || msg == WM_CTLCOLORSTATIC) { + switch ( GetWindowLongPtr(( HWND )lParam, GWL_ID )) { + /* case IDC_WHITERECT:*/ + case IDC_HEADERBAR: + SetTextColor((HDC)wParam,GetSysColor(COLOR_WINDOWTEXT)); + break; + default: + return FALSE; + } + SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW)); + return (LRESULT)GetStockObject(WHITE_BRUSH); //GetSysColorBrush(COLOR_WINDOW); + } + + CHandleMapping::iterator wnd(_HandleMapping.end()); + if (msg == WM_INITDIALOG) { + wnd = _HandleMapping.insert(CHandleMapping::value_type(hWnd, reinterpret_cast(lParam))).first; + reinterpret_cast(lParam)->m_hWnd = hWnd; + return wnd->second->wmInitdialog(wParam, lParam); + } + else { + wnd = _HandleMapping.find(hWnd); + } + if (wnd == _HandleMapping.end()) { // something screwed up + return FALSE; //dialog! do not use ::DefWindowProc(hWnd, msg, wParam, lParam); + } + + switch (msg) + { + // case WM_INITDIALOG: done on top + case WM_COMMAND: + return wnd->second->wmCommand(wParam, lParam); + break; + case WM_CLOSE: + return wnd->second->wmClose(wParam, lParam); + break; + case WM_DESTROY: + delete wnd->second; + break; + case UM_TAB1: + return wnd->second->UMTab1(wParam, lParam); + break; + case WM_NOTIFY: + return wnd->second->wmNotify(wParam, lParam); + break; + case WM_TIMER: + return wnd->second->wmTimer(wParam, lParam); + break; + case UM_CLOSING: + return wnd->second->UMClosing(wParam, lParam); + break; + case UM_EVENT: + return wnd->second->UMevent(wParam, lParam); + break; + } + return FALSE; +} + +//--------------------------------------------------------------------------- +//WM_INITDIALOG: +LRESULT TfrmMain::wmInitdialog(WPARAM wParam, LPARAM lParam) { + HWND hCtrl; + //Taskbar and Window icon + SendMessage(m_hWnd, WM_SETICON, ICON_BIG, (LPARAM)IcoLib_GetIcon(ICO_PLUG_SSWINDOW1, true)); + SendMessage(m_hWnd, WM_SETICON, ICON_SMALL, (LPARAM)IcoLib_GetIcon(ICO_PLUG_SSWINDOW2)); + LPTSTR pt = mir_a2t(__PLUGIN_NAME); + SetWindowText(m_hWnd, pt); + mir_freeAndNil(pt); + + // Headerbar + pt = mir_tstrdup((LPTSTR)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, (WPARAM)m_hContact, (LPARAM)GCDNF_TCHAR)); + if (pt && (m_hContact != 0)) { + LPTSTR lptString = NULL; + mir_tcsadd(lptString , TranslateT("Send screenshot to\n")); + mir_tcsadd(lptString , pt); + SetDlgItemText(m_hWnd, IDC_HEADERBAR, lptString); + mir_free(lptString); + } + mir_freeAndNil(pt); + + SendMessage(GetDlgItem(m_hWnd, IDC_HEADERBAR), WM_SETICON, 0, (WPARAM)IcoLib_GetIcon(ICO_PLUG_SSWINDOW1, true)); + + //Timed controls + CheckDlgButton(m_hWnd,ID_chkTimed, m_opt_chkTimed ? BST_CHECKED : BST_UNCHECKED); + SetDlgItemInt (m_hWnd,ID_edtTimed, (UINT)m_opt_edtTimed, FALSE); + SendDlgItemMessage(m_hWnd, ID_upTimed, UDM_SETRANGE, 0, (LPARAM)MAKELONG(250, 1)); + chkTimedClick(); //enable disable Timed controls + + //create Image list for tab control + if(m_himlTab == 0){ + //m_himlTab = ImageList_Create(16, 16, PluginConfig.m_bIsXP ? ILC_COLOR32 | ILC_MASK : ILC_COLOR8 | ILC_MASK, 2, 0); + m_himlTab = ImageList_Create(16, 16, ILC_COLOR32 | ILC_MASK, 2, 0); + ImageList_AddIcon(m_himlTab, IcoLib_GetIcon(ICO_PLUG_SSWINDOW2)); + ImageList_AddIcon(m_himlTab, IcoLib_GetIcon(ICO_PLUG_SSWINDOW2)); + } + + //create the tab control. + { + TAB_INFO itab; + RECT rcClient, rcTab; + m_hwndTab = GetDlgItem(m_hWnd, IDC_CAPTURETAB); + TabCtrl_SetItemExtra(m_hwndTab, sizeof(TAB_INFO) - sizeof(TCITEMHEADER)); + + ZeroMemory(&itab, sizeof(itab)); + itab.hwndMain = m_hWnd; + itab.hwndTab = m_hwndTab; + + GetWindowRect(m_hwndTab, &rcTab); + GetWindowRect(m_hWnd, &rcClient); + + TabCtrl_SetImageList(m_hwndTab, m_himlTab); + + // Add a tab for each of the three child dialog boxes. + itab.tcih.mask = TCIF_PARAM|TCIF_TEXT|TCIF_IMAGE; + + itab.tcih.pszText = TranslateT("Window"); + itab.tcih.iImage = 0; + itab.hwndTabPage = CreateDialog(hInst,MAKEINTRESOURCE(IDD_UMain_CaptureWindow), m_hWnd,(DLGPROC)DlgProc_CaptureWindow); + TabCtrl_InsertItem(m_hwndTab, 0, &itab); + MoveWindow(itab.hwndTabPage, (rcTab.left - rcClient.left)+2, (rcTab.top - rcClient.top), (rcTab.right - rcTab.left) - 2*5, (rcTab.bottom - rcTab.top) - 2*20, TRUE); + ShowWindow(itab.hwndTabPage, SW_HIDE); + CheckDlgButton(itab.hwndTabPage, ID_chkClientArea, m_opt_chkClientArea ? BST_CHECKED : BST_UNCHECKED); + + itab.tcih.pszText = TranslateT("Desktop"); + itab.tcih.iImage = 1; + itab.hwndTabPage = CreateDialog(hInst,MAKEINTRESOURCE(IDD_UMain_CaptureDesktop), m_hWnd, DlgProc_CaptureDesktop); + TabCtrl_InsertItem(m_hwndTab, 1, &itab); + MoveWindow(itab.hwndTabPage, (rcTab.left - rcClient.left)+2, (rcTab.top - rcClient.top), (rcTab.right - rcTab.left) - 2*5, (rcTab.bottom - rcTab.top) - 2*20, TRUE); + ShowWindow(itab.hwndTabPage, SW_HIDE); + + hCtrl = GetDlgItem(itab.hwndTabPage, ID_edtCaption); + ComboBox_ResetContent(hCtrl); + ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("")) ,(DWORD)0); + ComboBox_SetCurSel (hCtrl,0); + if(m_MonitorCount >1) { + TCHAR tszTemp[120]; + for (size_t i = 0; i < m_MonitorCount; ++i) { + mir_sntprintf(tszTemp, SIZEOF(tszTemp),_T("%i. %s%s"), + i+1, + TranslateT("Monitor"), + (m_Monitors[i].dwFlags & MONITORINFOF_PRIMARY) ? TranslateT(" (primary)") : _T("") + ); + ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, (LPCTSTR)tszTemp) , i+1); + } + ComboBox_SelectItemData (hCtrl, -1, m_opt_cboxDesktop); //use Workaround for MS bug ComboBox_SelectItemData + } + PostMessage(m_hWnd, WM_COMMAND, MAKEWPARAM(ID_edtCaption, CBN_SELCHANGE),(LPARAM)hCtrl); + + //select tab and set m_hwndTabPage + TabCtrl_SetCurSel(m_hwndTab, m_opt_tabCapture); + ZeroMemory(&itab, sizeof(itab)); + itab.tcih.mask = TCIF_PARAM; + TabCtrl_GetItem(m_hwndTab,TabCtrl_GetCurSel(m_hwndTab),&itab); + ShowWindow(itab.hwndTabPage,SW_SHOW); + m_hwndTabPage = itab.hwndTabPage; + } + //init Format combo box + { + hCtrl = GetDlgItem(m_hWnd, ID_cboxFormat); + ComboBox_ResetContent(hCtrl); + ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, _T("PNG")),0); + ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, _T("JPG")),1); + ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, _T("BMP")),2); + ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, _T("TIF")),3); + ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, _T("GIF")),4); + ComboBox_SelectItemData (hCtrl, -1, m_opt_cboxFormat); //use Workaround for MS bug ComboBox_SelectItemData + } + //init SendBy combo box + { + hCtrl = GetDlgItem(m_hWnd, ID_cboxSendBy); + ComboBox_ResetContent(hCtrl); + ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("")) ,SS_JUSTSAVE); + if (m_hContact) { + ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("File Transfer")),SS_FILESEND); + } + else if(m_opt_cboxSendBy == SS_FILESEND) { + m_opt_cboxSendBy = SS_IMAGESHACK; + } + ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("E-mail")) ,SS_EMAIL); + if (myGlobals.PluginHTTPExist) { + ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, _T("HTTP Server")) ,SS_HTTPSERVER); + } + else if(m_opt_cboxSendBy == SS_HTTPSERVER) { + m_opt_cboxSendBy = SS_IMAGESHACK; + } + if (myGlobals.PluginFTPExist) { + ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("FTP File")) ,SS_FTPFILE); + } + else if(m_opt_cboxSendBy == SS_FTPFILE) { + m_opt_cboxSendBy = SS_IMAGESHACK; + } + ComboBox_SetItemData(hCtrl, ComboBox_AddString(hCtrl, TranslateT("ImageShack")) ,(BYTE)SS_IMAGESHACK); + ComboBox_SelectItemData (hCtrl, -1, m_opt_cboxSendBy); //use Workaround for MS bug ComboBox_SelectItemData + cboxSendByChange(); //enable disable controls + } + //init footer options + CheckDlgButton(m_hWnd,ID_chkOpenAgain, m_opt_chkOpenAgain ? BST_CHECKED : BST_UNCHECKED); + + if (hCtrl = GetDlgItem(m_hWnd, ID_btnAbout)) { + SendDlgItemMessage(m_hWnd, ID_btnAbout, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Information"), MBF_TCHAR); + HICON hIcon = IcoLib_GetIcon(ICO_PLUG_SSHELP); + SendMessage(hCtrl, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon); + SetWindowText(hCtrl, hIcon ? _T("") : _T("?")); + } + + if (hCtrl = GetDlgItem(m_hWnd, ID_btnExplore)) { + SendDlgItemMessage(m_hWnd, ID_btnExplore, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Open Folder"), MBF_TCHAR); + HICON hIcon = IcoLib_GetIcon(ICO_PLUG_SSFOLDERO); + SendMessage(hCtrl, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon); + SetWindowText(hCtrl, hIcon ? _T("") : _T("...")); + } + + if (hCtrl = GetDlgItem(m_hWnd, ID_btnDesc)) { + SendDlgItemMessage(m_hWnd, ID_btnDesc, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Fill description textbox."), MBF_TCHAR); + HICON hIcon = IcoLib_GetIcon(m_opt_btnDesc ? ICO_PLUG_SSDESKON : ICO_PLUG_SSDESKOFF); + SendMessage(hCtrl, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon); + SetWindowText(hCtrl, hIcon ? _T("") : _T("D")); + SendMessage(hCtrl, BM_SETCHECK, m_opt_btnDesc ? BST_CHECKED : BST_UNCHECKED, NULL); + } + + if (hCtrl = GetDlgItem(m_hWnd, ID_btnDeleteAfterSend)) { + SendDlgItemMessage(m_hWnd, ID_btnDeleteAfterSend, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Delete after send"), MBF_TCHAR); + HICON hIcon = IcoLib_GetIcon(m_opt_btnDeleteAfterSend ? ICO_PLUG_SSDELON : ICO_PLUG_SSDELOFF); + SendMessage(hCtrl, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon); + SetWindowText(hCtrl, hIcon ? _T("") : _T("X")); + SendMessage(hCtrl, BM_SETCHECK, m_opt_btnDeleteAfterSend ? BST_CHECKED : BST_UNCHECKED, NULL); + } + + if (hCtrl = GetDlgItem(m_hWnd, ID_btnCapture)) { + SendDlgItemMessage(m_hWnd, ID_btnCapture, BUTTONADDTOOLTIP, (WPARAM)TranslateT("Capture"), MBF_TCHAR); + HICON hIcon = IcoLib_GetIcon(ICO_BTN_OK); + SendMessage(hCtrl, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon); + SetWindowText(hCtrl, TranslateT("&Capture")); + SendMessage(hCtrl, BUTTONSETDEFAULT, (WPARAM)1, NULL); + } + +// CheckDlgButton(m_hWnd,ID_chkEditor, m_opt_chkEditor ? BST_CHECKED : BST_UNCHECKED); + TranslateDialogDefault(m_hWnd); + return FALSE; +} + +//WM_COMMAND: +LRESULT TfrmMain::wmCommand(WPARAM wParam, LPARAM lParam) { + //--------------------------------------------------------------------------- + int IDControl = LOWORD(wParam); + switch (HIWORD(wParam)) { + case BN_CLICKED: //Button controls + switch(IDControl) { + case IDCANCEL: + case IDCLOSE: + break; + + case ID_chkTimed: + m_opt_chkTimed = (BYTE)Button_GetCheck((HWND)lParam); + TfrmMain::chkTimedClick(); + break; + case ID_chkClientArea: + m_opt_chkClientArea = (BYTE)Button_GetCheck((HWND)lParam); + if(m_hTargetWindow) + edtSizeUpdate(m_hTargetWindow, m_opt_chkClientArea, GetParent((HWND)lParam), ID_edtSize); + break; + case ID_chkOpenAgain: + m_opt_chkOpenAgain = (BYTE)Button_GetCheck((HWND)lParam); + break; + case ID_chkEditor: + m_opt_chkEditor = (BYTE)Button_GetCheck((HWND)lParam); + break; + + case ID_btnAbout: + TfrmMain::btnAboutClick(); + break; + case ID_btnExplore: + TfrmMain::btnExploreClick(); + break; + case ID_btnDesc: + { + m_opt_btnDesc = (m_opt_btnDesc == 0); + HICON hIcon = IcoLib_GetIcon(m_opt_btnDesc ? ICO_PLUG_SSDESKON : ICO_PLUG_SSDESKOFF); + SendMessage((HWND)lParam, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon); + } + break; + case ID_btnDeleteAfterSend: + { + m_opt_btnDeleteAfterSend = (m_opt_btnDeleteAfterSend == 0); + HICON hIcon = IcoLib_GetIcon(m_opt_btnDeleteAfterSend ? ICO_PLUG_SSDELON : ICO_PLUG_SSDELOFF); + SendMessage((HWND)lParam, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon); + if(m_cSend) m_cSend->m_bDeleteAfterSend = m_opt_btnDeleteAfterSend; + } + break; + case ID_btnCapture: + TfrmMain::btnCaptureClick(); + break; + default: + break; + } + break; + case CBN_SELCHANGE: //ComboBox controls + switch(IDControl) { + //lParam = Handle to the control + case ID_cboxFormat: //not finish + m_opt_cboxFormat = (BYTE)ComboBox_GetItemData((HWND)lParam, ComboBox_GetCurSel((HWND)lParam)); + break; + case ID_cboxSendBy: + m_opt_cboxSendBy = (BYTE)ComboBox_GetItemData((HWND)lParam, ComboBox_GetCurSel((HWND)lParam)); + cboxSendByChange(); + break; + case ID_edtCaption: //cboxDesktopChange + m_opt_cboxDesktop = (BYTE)ComboBox_GetItemData((HWND)lParam, ComboBox_GetCurSel((HWND)lParam)); + m_hTargetWindow = 0; + if (m_opt_cboxDesktop > 0) { + edtSizeUpdate(m_Monitors[m_opt_cboxDesktop-1].rcMonitor, GetParent((HWND)lParam), ID_edtSize); + } + else { + edtSizeUpdate(m_VirtualScreen, GetParent((HWND)lParam), ID_edtSize); + } + break; + default: + break; + } + break; + case EN_CHANGE: //Edit controls + switch(IDControl) { + //lParam = Handle to the control + case ID_edtQuality: + m_opt_edtQuality = (BYTE)GetDlgItemInt(m_hWnd, ID_edtQuality, NULL, FALSE); + break; + case ID_edtTimed: + m_opt_edtTimed = (BYTE)GetDlgItemInt(m_hWnd, ID_edtTimed, NULL, FALSE); + break; + default: + break; + } + break; + default: + break; + } + return FALSE; +} + +//WM_CLOSE: +LRESULT TfrmMain::wmClose(WPARAM wParam, LPARAM lParam) { + DestroyWindow(m_hWnd); + return FALSE; +} + +//WM_TIMER: +LRESULT TfrmMain::wmTimer(WPARAM wParam, LPARAM lParam) { + if (wParam == ID_bvlTarget) { // Timer for Target selector + if (m_hCursor) { //imgTarget is activ + //LmouseButton = false + if (!GetLmouse()) { + TfrmMain::imgTargetMouseUp(); + return FALSE; + } + //Timer action if LmouseButton = true + m_hLastWin = m_hTargetWindow; + POINT point={0}; + GetCursorPos(&point); + HWND hCurrentWin = WindowFromPoint(point); + while (GetParent(hCurrentWin)) { + hCurrentWin = GetParent(hCurrentWin); + } + if (m_hLastWin != hCurrentWin) { + LPTSTR lpTitle = NULL; + if (m_hLastWin) { + DrawBorderInverted(m_hLastWin); + } + int Count = GetWindowTextLength(hCurrentWin)+1; + if(Count > 1){ + lpTitle = (LPTSTR)mir_alloc(Count*sizeof(TCHAR)); + GetWindowText(hCurrentWin, lpTitle, Count); + } + else { + //no WindowText present, use WindowClass + lpTitle = (LPTSTR)mir_alloc(MAX_PATH*sizeof(TCHAR)); + RealGetWindowClass(hCurrentWin, lpTitle, MAX_PATH); + } + SetDlgItemText(m_hwndTabPage, ID_edtCaption, lpTitle); + mir_free(lpTitle); + edtSizeUpdate(hCurrentWin, m_opt_chkClientArea, m_hwndTabPage, ID_edtSize); + DrawBorderInverted(hCurrentWin); + m_hTargetWindow = hCurrentWin; + } + return FALSE; + } + //imgTarget is not activ (check if cursor is over ID_bvlTarget control) + RECT rc; + POINT pt; + GetWindowRect(GetDlgItem(m_hwndTabPage, wParam),&rc); + GetCursorPos(&pt); + //check Mouse cursor + if(!PtInRect(&rc,pt)) { // mouse must be gone, trigger mouse leave + //PostMessage(m_hWnd,WM_MOUSELEAVE,wParam,lParam); + KillTimer(m_hWnd,wParam); + } + else if (GetLmouse() && !m_hCursor) { //mouse hover + LButton + TfrmMain::imgTargetMouseDown(); + } + } + if (wParam == ID_chkTimed) { // Timer for Screenshot + #ifdef _DEBUG + OutputDebugStringA("SS Bitmap Timer Start\r\n" ); + #endif + if(!m_bCapture) { //only start once + if (m_Screenshot) { + FIP->FI_Unload(m_Screenshot); + m_Screenshot = NULL; + } + m_bCapture = true; + switch (m_opt_tabCapture) { + case 0: + m_Screenshot = CaptureWindow(m_hTargetWindow, (BOOL)m_opt_chkClientArea); + break; + case 1: + m_Screenshot = CaptureMonitor((m_opt_cboxDesktop > 0) ? m_Monitors[m_opt_cboxDesktop-1].szDevice : NULL); + break; + default: + KillTimer(m_hWnd,wParam); + m_bCapture = false; + #ifdef _DEBUG + OutputDebugStringA("SS Bitmap Timer Stop (no tabCapture)\r\n" ); + #endif + return FALSE; + } + if (!m_Screenshot) m_bCapture = false; + } + if (m_Screenshot) { + KillTimer(m_hWnd,wParam); + m_bCapture = false; + #ifdef _DEBUG + OutputDebugStringA("SS Bitmap Timer Stop (CaptureDone)\r\n" ); + #endif + SendMessage(m_hWnd,UM_EVENT, (WPARAM)0, (LPARAM)EVT_CaptureDone); + } + } + return FALSE; +} + +//WM_NOTIFY: +LRESULT TfrmMain::wmNotify(WPARAM wParam, LPARAM lParam) { + switch(((LPNMHDR)lParam)->idFrom) { + case IDC_CAPTURETAB: //TabControl IDC_CAPTURETAB + switch (((LPNMHDR)lParam)->code) { + // HWND hwndFrom; = member is handle to the tab control + // UINT_PTR idFrom; = member is the child window identifier of the tab control. + // UINT code; = member is TCN_SELCHANGE + case TCN_SELCHANGING: + { + TAB_INFO itab; + ZeroMemory(&itab, sizeof(itab)); + itab.tcih.mask = TCIF_PARAM; + TabCtrl_GetItem(m_hwndTab,TabCtrl_GetCurSel(m_hwndTab),&itab); + ShowWindow(itab.hwndTabPage,SW_HIDE); + m_hwndTabPage = NULL; + } + break; + + case TCN_SELCHANGE: + { + TAB_INFO itab; + ZeroMemory(&itab, sizeof(itab)); + itab.tcih.mask = TCIF_PARAM; + m_opt_tabCapture = TabCtrl_GetCurSel(m_hwndTab); + TabCtrl_GetItem(m_hwndTab, m_opt_tabCapture, &itab); + ShowWindow(itab.hwndTabPage, SW_SHOW); + m_hwndTabPage = itab.hwndTabPage; + } + break; + default: + break; + } + break; + default: + break; + } + return FALSE; +} + +//UM_CLOSING: +LRESULT TfrmMain::UMClosing(WPARAM wParam, LPARAM lParam) { + HWND hWnd = (HWND)wParam; + switch (lParam) { + case IDD_UAboutForm: + btnAboutOnCloseWindow(hWnd); + break; + case IDD_UEditForm: + ; + break; + default: + break; + } + return FALSE; +} + +//UM_TAB1: +LRESULT TfrmMain::UMTab1(WPARAM wParam, LPARAM lParam) { + switch (wParam) { + case WM_MOUSEMOVE: + if (m_opt_tabCapture == 0) { + // Call timer, used to start cheesy TrackMouseEvent faker + SetTimer(m_hWnd,ID_bvlTarget,BUTTON_POLLDELAY,NULL); + } + break; + default: + break; + } + return FALSE; +} + +//UM_EVENT: +LRESULT TfrmMain::UMevent(WPARAM wParam, LPARAM lParam) { + //HWND hWnd = (HWND)wParam; + switch (lParam) { + case EVT_CaptureDone: + if (!m_Screenshot) { + TCHAR *err = TranslateT("Cant create a Screenshot"); + MessageBox(m_hWnd,err,ERROR_TITLE,MB_OK|MB_ICONWARNING); + Show(); + return FALSE; + } + if (m_opt_chkEditor) { + /* TfrmEdit *frmEdit=new TfrmEdit(this); + m_bFormEdit = true; + + frmEdit->mniClose->Enabled = !chkJustSaveIt->Checked; + frmEdit->mniCloseSend->Enabled = frmEdit->mniClose->Enabled; + frmEdit->OnClose = OnCloseEditWindow; + frmEdit->InitEditor(Screenshot); // Screenshot is copied to another in-memory bitmap inside this method + frmEdit->Show(); + delete Screenshot; // This way we can delete it after the method returns + Screenshot = NULL; + */ + return FALSE; + } + else { + FormClose(); + } + break; + case EVT_SendFileDone: + break; + case EVT_CheckOpenAgain: + if (m_opt_chkOpenAgain) { + if (m_Screenshot) { + FIP->FI_Unload(m_Screenshot); + m_Screenshot = NULL; + } + m_hTargetWindow = m_hLastWin = NULL; + Show(); + } + else { + // Saving Options and close + SaveOptions(); + Close(); + } + break; + default: + break; + } + return FALSE; +} + +//--------------------------------------------------------------------------- +// Standard konstruktor/destruktor +TfrmMain::TfrmMain() { + m_hWnd = NULL; + m_hContact = NULL; + m_hTargetWindow = NULL; + m_hCursor = NULL; + m_Screenshot = NULL; + m_pszFile = m_pszFileDesc = m_FDestFolder = NULL; + m_bFormAbout = m_bFormEdit = m_bDeleteAfterSend = m_bSelectingWindow = false; + m_cSend = NULL; + m_bOnExitSave = TRUE; + LoadOptions(); + m_bCapture = false; + m_himlTab = NULL; + m_Monitors = NULL; + m_MonitorCount = MonitorInfoEnum(m_Monitors, m_VirtualScreen); + +} + +TfrmMain::~TfrmMain() { + _HandleMapping.erase(m_hWnd); + mir_free(m_pszFile); + mir_free(m_FDestFolder); + mir_free(m_pszFileDesc); + mir_free(m_Monitors); + if (m_Screenshot) FIP->FI_Unload(m_Screenshot); + if (m_cSend) delete m_cSend; +} + +//--------------------------------------------------------------------------- +// Load / Saving options from miranda's database +void TfrmMain::LoadOptions(void) { + DWORD rgb = DBGetContactSettingDword(NULL, SZ_SENDSS, "AlphaColor", 16777215); + m_AlphaColor.rgbRed = GetRValue(rgb); + m_AlphaColor.rgbGreen = GetGValue(rgb); + m_AlphaColor.rgbBlue = GetBValue(rgb); + m_AlphaColor.rgbReserved = 0; + +// m_opt_chkEmulateClick = DBGetContactSettingByte(NULL, SZ_SENDSS, "AutoSend", 1); + m_opt_edtQuality = DBGetContactSettingByte(NULL, SZ_SENDSS, "JpegQuality", 75); + + m_opt_tabCapture = DBGetContactSettingByte(NULL, SZ_SENDSS, "Capture", 0); + m_opt_chkClientArea = DBGetContactSettingByte(NULL, SZ_SENDSS, "ClientArea", 0); + m_opt_cboxDesktop = DBGetContactSettingByte(NULL, SZ_SENDSS, "Desktop", 0); + + m_opt_chkTimed = DBGetContactSettingByte(NULL, SZ_SENDSS, "TimedCap", 0); + m_opt_edtTimed = DBGetContactSettingByte(NULL, SZ_SENDSS, "CapTime", 3); + m_opt_cboxFormat = DBGetContactSettingByte(NULL, SZ_SENDSS, "OutputFormat", 3); + m_opt_cboxSendBy = DBGetContactSettingByte(NULL, SZ_SENDSS, "SendBy", 0); + + m_opt_chkEditor = DBGetContactSettingByte(NULL, SZ_SENDSS, "Preview", 0); + m_opt_btnDesc = DBGetContactSettingByte(NULL, SZ_SENDSS, "AutoDescription", 1); + m_opt_btnDeleteAfterSend = DBGetContactSettingByte(NULL, SZ_SENDSS, "DelAfterSend", 1); + m_opt_chkOpenAgain = DBGetContactSettingByte(NULL, SZ_SENDSS, "OpenAgain", 0); +} + +void TfrmMain::SaveOptions(void) { + if(m_bOnExitSave) { + DBWriteContactSettingDword(NULL, SZ_SENDSS, "AlphaColor", + (DWORD)RGB(m_AlphaColor.rgbRed, m_AlphaColor.rgbGreen, m_AlphaColor.rgbBlue)); + +// DBWriteContactSettingByte(NULL, SZ_SENDSS, "AutoSend", m_opt_chkEmulateClick); + DBWriteContactSettingByte(NULL, SZ_SENDSS, "JpegQuality", m_opt_edtQuality); + + DBWriteContactSettingByte(NULL, SZ_SENDSS, "Capture", m_opt_tabCapture); + DBWriteContactSettingByte(NULL, SZ_SENDSS, "ClientArea", m_opt_chkClientArea); + DBWriteContactSettingByte(NULL, SZ_SENDSS, "Desktop", m_opt_cboxDesktop); + + DBWriteContactSettingByte(NULL, SZ_SENDSS, "TimedCap", m_opt_chkTimed); + DBWriteContactSettingByte(NULL, SZ_SENDSS, "CapTime", m_opt_edtTimed); + DBWriteContactSettingByte(NULL, SZ_SENDSS, "OutputFormat", m_opt_cboxFormat); + DBWriteContactSettingByte(NULL, SZ_SENDSS, "SendBy", m_opt_cboxSendBy); + + DBWriteContactSettingByte(NULL, SZ_SENDSS, "AutoDescription", m_opt_btnDesc); + DBWriteContactSettingByte(NULL, SZ_SENDSS, "DelAfterSend", m_opt_btnDeleteAfterSend); + DBWriteContactSettingByte(NULL, SZ_SENDSS, "OpenAgain", m_opt_chkOpenAgain); + DBWriteContactSettingByte(NULL, SZ_SENDSS, "Preview", m_opt_chkEditor); + } +} + +//--------------------------------------------------------------------------- +void TfrmMain::Init(LPTSTR DestFolder, HANDLE Contact) { + m_FDestFolder = mir_tstrdup(DestFolder); + m_hContact = Contact; + if(!m_hContact) m_opt_cboxSendBy = SS_JUSTSAVE; + + // create window + m_hWnd = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_UMainForm),0, (DLGPROC)DlgTfrmMain,(LPARAM)this); + //register object + _HandleMapping.insert(CHandleMapping::value_type(m_hWnd, this)); + + //check Contact + if(m_cSend) m_cSend->SetContact(Contact); +} + +//--------------------------------------------------------------------------- +void TfrmMain::btnCaptureClick() { + m_bFormEdit = false; //until UEditForm is includet + + if (m_opt_tabCapture == 0 && m_hTargetWindow == 0) { + TCHAR *err = TranslateT("Select a target window."); + MessageBox(m_hWnd,err,ERROR_TITLE,MB_OK|MB_ICONWARNING); + return; + } + TfrmMain::Hide(); + + if (!m_hTargetWindow) m_hTargetWindow = GetDesktopWindow(); + + if (m_opt_chkTimed) { + SetTimer(m_hWnd, ID_chkTimed, m_opt_edtTimed ? m_opt_edtTimed*1000 : 500, NULL); + } + else if (m_opt_tabCapture == 1){ + //desktop need always time to update from TfrmMain::Hide() + SetTimer(m_hWnd, ID_chkTimed, 500, NULL); + } + else { + m_Screenshot = CaptureWindow(m_hTargetWindow, (BOOL)(m_opt_chkClientArea)); + SendMessage(m_hWnd,UM_EVENT, (WPARAM)0, (LPARAM)EVT_CaptureDone); + } +} + +//--------------------------------------------------------------------------- +void TfrmMain::chkTimedClick() { + Button_Enable(GetDlgItem(m_hWnd, ID_edtTimedLabel), (BOOL)m_opt_chkTimed); + Button_Enable(GetDlgItem(m_hWnd, ID_edtTimed), (BOOL)m_opt_chkTimed); + Button_Enable(GetDlgItem(m_hWnd, ID_upTimed), (BOOL)m_opt_chkTimed); +} + +//--------------------------------------------------------------------------- +void TfrmMain::imgTargetMouseDown() { + //if (Button != mbLeft) return; + m_hCursor = CopyCursor(GetCursor()); //backup cursor + //SetSystemCursor need a copy coz it destroy the handle + SetSystemCursor(CopyCursor(IcoLib_GetIcon(ICO_PLUG_SSTARGET)),OCR_NORMAL); + m_bSelectingWindow = true; + m_hTargetWindow = NULL; + Hide(); + SetCapture(m_hWnd); +} + +//--------------------------------------------------------------------------- +void TfrmMain::imgTargetMouseUp() { + //if (Button == mbLeft && m_bSelectingWindow && TimerCheckFocus->Enabled) + if (m_bSelectingWindow && m_hCursor) { + Show(); + ReleaseCapture(); + SetSystemCursor(m_hCursor, OCR_NORMAL); + m_hCursor = NULL; + if (m_hTargetWindow){ + DrawBorderInverted(m_hTargetWindow); + } + m_bSelectingWindow = false; + } +} + +//--------------------------------------------------------------------------- +void TfrmMain::cboxSendByChange() { + BOOL bState; + HICON hIcon; + BYTE itemFlag = SS_DLG_DESCRIPTION; //SS_DLG_AUTOSEND | SS_DLG_DELETEAFTERSSEND | + if (m_cSend && !m_cSend->m_bFreeOnExit) { + delete m_cSend; + m_cSend = NULL; + } + switch(m_opt_cboxSendBy) { + case SS_FILESEND: //"File Transfer" + m_cSend = new CSendFile(m_hWnd, m_hContact, false); + break; + case SS_EMAIL: //"E-mail" + m_cSend = new CSendEmail(m_hWnd, m_hContact, false); + break; + case SS_HTTPSERVER: //"HTTP Server" + m_cSend = new CSendHTTPServer(m_hWnd, m_hContact, false); + break; + case SS_FTPFILE: //"FTP File" + m_cSend = new CSendFTPFile(m_hWnd, m_hContact, false); + break; + case SS_IMAGESHACK: //"ImageShack" + m_cSend = new CSendImageShack(m_hWnd, m_hContact, false); + break; + default: //SS_JUSTSAVE - "Just save it " + m_cSend = NULL; + break; + } + if(m_cSend){ + itemFlag = m_cSend->GetEnableItem(); + m_cSend->m_bDeleteAfterSend = m_opt_btnDeleteAfterSend; + } + bState = ((itemFlag & SS_DLG_DELETEAFTERSSEND) == SS_DLG_DELETEAFTERSSEND); + hIcon = IcoLib_GetIcon(m_opt_btnDeleteAfterSend ? ICO_PLUG_SSDELON : ICO_PLUG_SSDELOFF); + SendMessage(GetDlgItem(m_hWnd, ID_btnDeleteAfterSend), BM_SETIMAGE, IMAGE_ICON, (LPARAM)(bState ? hIcon : 0)); + Button_Enable(GetDlgItem(m_hWnd, ID_btnDeleteAfterSend), bState); + + bState = ((itemFlag & SS_DLG_DESCRIPTION) == SS_DLG_DESCRIPTION); + hIcon = IcoLib_GetIcon(m_opt_btnDesc ? ICO_PLUG_SSDESKON : ICO_PLUG_SSDESKOFF); + SendMessage(GetDlgItem(m_hWnd, ID_btnDesc), BM_SETIMAGE, IMAGE_ICON, (LPARAM)(bState ? hIcon : 0)); + Button_Enable(GetDlgItem(m_hWnd, ID_btnDesc), bState); +} + +//--------------------------------------------------------------------------- +void TfrmMain::btnAboutClick() { + if (m_bFormAbout) return; + + TfrmAbout *frmAbout=new TfrmAbout(m_hWnd); + frmAbout->Show(); + m_bFormAbout = true; +} + +// Edit window call this event before it closes +void TfrmMain::btnAboutOnCloseWindow(HWND hWnd) { + m_bFormAbout = false; +} + +//--------------------------------------------------------------------------- +void TfrmMain::btnExploreClick() { + if (m_FDestFolder) + ShellExecute(NULL, _T("explore"), m_FDestFolder, NULL, NULL, SW_SHOW); +} + +//--------------------------------------------------------------------------- +void TfrmMain::edtSizeUpdate(HWND hWnd, BOOL ClientArea, HWND hTarget, UINT Ctrl) { + // get window dimensions + RECT rect = {0}; + RECT cliRect = {0}; + TCHAR B[33], H[16]; + GetWindowRect(hWnd, &rect); + if (ClientArea) { + POINT pt = {0}; + GetClientRect(hWnd, &cliRect); + pt.x = cliRect.left; + pt.y = cliRect.top; + ClientToScreen(hWnd, &pt); + pt.x = pt.x - rect.left; //offset x for client area + pt.y = pt.y - rect.top; //offset y for client area + rect = cliRect; + } +// _itot_s(rect.right - rect.left, B, 33, 10); + _itot(rect.right - rect.left, B, 10); +// _itot_s(rect.bottom - rect.top, H, 16, 10); + _itot(rect.bottom - rect.top, H, 10); + mir_tcsncat(B, _T("x"), 33); + mir_tcsncat(B, H, 33); + SetDlgItemText(hTarget, Ctrl, B); +} + +void TfrmMain::edtSizeUpdate(RECT rect, HWND hTarget, UINT Ctrl) { + TCHAR B[33], H[16]; +// _itot_s(ABS(rect.right - rect.left), B, 33, 10); + _itot(ABS(rect.right - rect.left), B, 10); +// _itot_s(ABS(rect.bottom - rect.top), H, 16, 10); + _itot(ABS(rect.bottom - rect.top), H, 10); + mir_tcsncat(B, _T("x"), 33); + mir_tcsncat(B, H, 33); + SetDlgItemText(hTarget, Ctrl, B); +} + +//--------------------------------------------------------------------------- +INT_PTR TfrmMain::SaveScreenshot(FIBITMAP* dib) { + //generate File name + FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; + LPTSTR ret = NULL; + LPTSTR path = NULL; + LPTSTR pszFilename = NULL; + LPTSTR pszFileDesc = NULL; + if (!dib) return 1; //error + + //Generate FileName + mir_tcsadd(path, m_FDestFolder); + if (path[_tcslen(path)-1] != _T('\\')) mir_tcsadd(path, _T("\\")); + mir_tcsadd(path, _T("shot%.5ld")); + int FileNumber=DBGetContactSettingDword(NULL, SZ_SENDSS, "FileNumber", 0) + 1; + // '00000'-'%.5ld'=0 (add more or less len if differ from 5 + size_t len = (_tcslen(path)+0+1); + pszFilename = (LPTSTR)mir_alloc(sizeof(TCHAR)*(len)); + mir_sntprintf(pszFilename, len, path, FileNumber); + mir_free(path); + + //Generate a description according to the screenshot + TCHAR winText[1024]; + mir_tcsadd(pszFileDesc, _T("Screenshot ")); + if (m_opt_tabCapture == 0 && m_opt_chkClientArea) { + mir_tcsadd(pszFileDesc, _T("for Client area ")); + } + mir_tcsadd(pszFileDesc, _T("of \"")); + GetDlgItemText(m_hwndTabPage, ID_edtCaption, winText, 1024); + mir_tcsadd(pszFileDesc, winText); + mir_tcsadd(pszFileDesc, _T("\" Window")); + + // convert to 32Bits (make shure it is 32bit) + FIBITMAP *dib_new = FIP->FI_ConvertTo32Bits(dib); + //RGBQUAD appColor = { 245, 0, 254, 0 }; //bgr0 schwarz + //FIP->FI_SetBackgroundColor(dib_new, &appColor); + FIP->FI_SetTransparent(dib_new,TRUE); + + // Investigates the color type of the bitmap (test for RGB or CMYK colour space) + switch (FREE_IMAGE_COLOR_TYPE ColTye=FIP->FI_GetColorType(dib_new)) { + case FIC_MINISBLACK: + //Monochrome bitmap (1-bit) : first palette entry is black. + //Palletised bitmap (4 or 8-bit) and single channel non standard bitmap: the bitmap has a greyscale palette + case FIC_MINISWHITE: + //Monochrome bitmap (1-bit) : first palette entry is white. + //Palletised bitmap (4 or 8-bit) : the bitmap has an inverted greyscale palette + case FIC_PALETTE: + //Palettized bitmap (1, 4 or 8 bit) + case FIC_RGB: + //High-color bitmap (16, 24 or 32 bit), RGB16 or RGBF + case FIC_RGBALPHA: + //High-color bitmap with an alpha channel (32 bit bitmap, RGBA16 or RGBAF) + case FIC_CMYK: + //CMYK bitmap (32 bit only) + default: + break; + } + + + if ((FIP->FI_GetICCProfile(dib_new)->flags & FIICC_COLOR_IS_CMYK) == FIICC_COLOR_IS_CMYK) { + // we are in CMYK colour space + bool bDummy = false; + } + else { + // we are in RGB colour space + bool bDummy = true; + } + + FIBITMAP *dib32 = NULL; + FIBITMAP *dib24 = NULL; + HWND hwndCombo = GetDlgItem(m_hWnd, ID_cboxFormat); + switch (ComboBox_GetItemData(hwndCombo, ComboBox_GetCurSel(hwndCombo))) { + case 0: //PNG + ret = SaveImage(fif,dib_new, pszFilename, _T("png")); + break; + + case 1: //JPG + /* + #define JPEG_QUALITYSUPERB 0x80 // save with superb quality (100:1) + #define JPEG_QUALITYGOOD 0x0100 // save with good quality (75:1) + #define JPEG_QUALITYNORMAL 0x0200 // save with normal quality (50:1) + #define JPEG_QUALITYAVERAGE 0x0400 // save with average quality (25:1) + #define JPEG_QUALITYBAD 0x0800 // save with bad quality (10:1) + #define JPEG_PROGRESSIVE 0x2000 // save as a progressive-JPEG (use | to combine with other save flags) + */ + dib32 = FIP->FI_Composite(dib_new,FALSE,&m_AlphaColor,NULL); + dib24 = FIP->FI_ConvertTo24Bits(dib32); + FIP->FI_Unload(dib32); dib32 = NULL; + ret = SaveImage(fif,dib24, pszFilename, _T("jpg")); + FIP->FI_Unload(dib24); dib24 = NULL; + break; + + case 2: //BMP + // ret = SaveImage(FIF_BMP,dib_new, pszFilename, _T("bmp")); //32bit alpha BMP + dib32 = FIP->FI_Composite(dib_new,FALSE,&m_AlphaColor,NULL); + dib24 = FIP->FI_ConvertTo24Bits(dib32); + FIP->FI_Unload(dib32); dib32 = NULL; + ret = SaveImage(FIF_BMP,dib24, pszFilename, _T("bmp")); + FIP->FI_Unload(dib24); dib24 = NULL; + break; + + case 3: //TIFF (miranda freeimage interface do not support save tiff, we udse GDI+) + { + LPTSTR pszFile = NULL; + mir_tcsadd(pszFile, pszFilename); + mir_tcsadd(pszFile, _T(".tif")); + + dib32 = FIP->FI_Composite(dib_new,FALSE,&m_AlphaColor,NULL); + dib24 = FIP->FI_ConvertTo24Bits(dib32); + FIP->FI_Unload(dib32); dib32 = NULL; + + HBITMAP hBmp = FIP->FI_CreateHBITMAPFromDIB(dib24); + FIP->FI_Unload(dib24); dib24 = NULL; + ret = SaveTIF(hBmp, pszFile) ? NULL : pszFile; + DeleteObject(hBmp); + } + break; + + case 4: //GIF + { + //dib24 = FIP->FI_ConvertTo8Bits(dib_new); + //ret = SaveImage(FIF_GIF,dib24, pszFilename, _T("gif")); + //FIP->FI_Unload(dib24); dib24 = NULL; + LPTSTR pszFile = NULL; + mir_tcsadd(pszFile, pszFilename); + mir_tcsadd(pszFile, _T(".gif")); + HBITMAP hBmp = FIP->FI_CreateHBITMAPFromDIB(dib_new); + SaveGIF(hBmp, pszFile); + ret = pszFile; + DeleteObject(hBmp); + } + break; + + default: + break; + } +/* //load PNG and save file in user format (if differ) + //this get better result for transparent aereas + //LPTSTR pszFormat = (LPTSTR)ComboBox_GetItemData(hwndCombo, ComboBox_GetCurSel(hwndCombo)); + TCHAR pszFormat[6]; + ComboBox_GetText(hwndCombo, pszFormat, 6); + if(ret && (_tcsicmp (pszFormat,_T("png")) != 0)) { + #if defined(_UNICODE) + fif = FIP->FI_GetFIFFromFilenameU(ret); + dib_new = FIP->FI_LoadU(fif, ret,0); + #else + fif = FIP->FI_GetFIFFromFilenameU(ret); + dib_new = FIP->FI_Load(fif, ret,0); + #endif + + if(dib_new) { + DeleteFile(ret); + mir_freeAndNil(ret); + FIBITMAP *dib_save = FIP->FI_ConvertTo24Bits(dib_new); + ret = SaveImage(FIF_UNKNOWN,dib_save, pszFilename, pszFormat); + FIP->FI_Unload(dib_new); dib_new = NULL; + FIP->FI_Unload(dib_save); dib_save = NULL; + } + }*/ + FIP->FI_Unload(dib_new); dib_new = NULL; + mir_freeAndNil(pszFilename); + + if (ret) { + DBWriteContactSettingDword(NULL, SZ_SENDSS, "FileNumber", (DWORD)FileNumber); + mir_freeAndNil(m_pszFile); + mir_freeAndNil(m_pszFileDesc); + m_pszFile = ret; + if (IsWindowEnabled(GetDlgItem(m_hWnd, ID_btnDesc)) && m_opt_btnDesc) { + m_pszFileDesc = pszFileDesc; + } + else { + mir_tcsadd(m_pszFileDesc, _T("")); + } + + if(m_cSend) { + mir_freeAndNil(m_cSend->m_pszFile); + mir_freeAndNil(m_cSend->m_pszFileDesc); + m_cSend->m_pszFile = mir_tstrdup(m_pszFile); + m_cSend->m_pszFileDesc = mir_tstrdup(m_pszFileDesc); + } + return 0; //OK + } + mir_freeAndNil(ret); + mir_freeAndNil(pszFileDesc); + return 1; //error +} + +//--------------------------------------------------------------------------- +void TfrmMain::FormClose() { + + // Saving the screenshot + if (SaveScreenshot(m_Screenshot)) { + Show(); // Error from SaveScreenshot + return; + } + + if (m_cSend && m_pszFile && m_hContact && !m_bFormEdit) { + m_cSend->Send(); + if (m_cSend->m_bFreeOnExit) cboxSendByChange(); +// Not finish delete this if events from m_opt_cboxSendBy implementet + SendMessage(m_hWnd,UM_EVENT, (WPARAM)0, (LPARAM)EVT_CheckOpenAgain); + } + else { + SendMessage(m_hWnd,UM_EVENT, (WPARAM)0, (LPARAM)EVT_CheckOpenAgain); + } +} + +//--------------------------------------------------------------------------- +/*/ Edit window call this event before it closes +void TfrmMain::OnCloseEditWindow(TObject *Sender, TCloseAction &Action) { + TfrmEdit *form=dynamic_cast(Sender); + form->Hide(); + + // delete the form automatically,after this event returns + Action = caFree; + + // This will saves settings, free resources, ... + form->CallBeforeClose(Action); + + // User selected "Capture" on action menu of edit window + if (form->ModalResult == mrCancel) { + this->Show(); + } else { + Screenshot = form->Screen; + bFormEdit = form->DontSend; + this->Close(); + } +}*/ + +//--------------------------------------------------------------------------- diff --git a/plugins/SendScreenshotPlus/src/UMainForm.h b/plugins/SendScreenshotPlus/src/UMainForm.h new file mode 100644 index 0000000000..a7fdcdc643 --- /dev/null +++ b/plugins/SendScreenshotPlus/src/UMainForm.h @@ -0,0 +1,157 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* +Copyright 2000-2009 Miranda ICQ/IM project, + +This file is part of Send Screenshot Plus, a Miranda IM plugin. +Copyright (c) 2010 Ing.U.Horn + +Parts of this file based on original sorce code +(c) 2004-2006 Srgio Vieira Rolanski (portet from Borland C++) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +File name : $HeadURL: http://merlins-miranda.googlecode.com/svn/trunk/miranda/plugins/SendSSPlus/UMainForm.h $ +Revision : $Revision: 22 $ +Last change on : $Date: 2010-05-02 21:25:02 +0400 (Вс, 02 май 2010) $ +Last change by : $Author: ing.u.horn $ + +*/ + +#ifndef UMainFormH +#define UMainFormH +//--------------------------------------------------------------------------- +#include "global.h" +#include "Utils.h" +#include "CSend.h" +#include "CSendFile.h" +#include "CSendImageShack.h" +#include "CSendHTTPServer.h" +#include "CSendFTPFile.h" +#include "CSendEmail.h" + +#define SS_JUSTSAVE 0 +#define SS_FILESEND 1 +#define SS_EMAIL 2 +#define SS_HTTPSERVER 3 +#define SS_FTPFILE 4 +#define SS_IMAGESHACK 5 + +// Used for our own cheap TrackMouseEvent +#define BUTTON_POLLDELAY 50 + +// User Events +#define EVT_CaptureDone 1 +#define EVT_SendFileDone 2 +#define EVT_CheckOpenAgain 3 + +extern FI_INTERFACE *FIP; + +typedef struct MyTabData { + TCITEMHEADER tcih; + HWND hwndMain; //main window + HWND hwndTab; //tab control + HWND hwndTabPage; //current child dialog box +}TAB_INFO; + +//--------------------------------------------------------------------------- +class TfrmMain{ + + public: + // Deklaration Standardkonstruktor/Standarddestructor + TfrmMain(); + ~TfrmMain(); + + BYTE m_opt_tabCapture; //capure tab page + BYTE m_opt_btnDesc; //TCheckBox *chkDesc; + BYTE m_opt_cboxDesktop; //TRadioButton *rbtnDesktop; + BYTE m_opt_chkEditor; //TCheckBox *chkEditor; + BYTE m_opt_chkTimed; //TCheckBox *chkTimed; + BYTE m_opt_cboxSendBy; //TComboBox *cboxSendBy; + bool m_bOnExitSave; + + void Show(){ShowWindow(m_hWnd,SW_SHOW);} + void Hide(){ShowWindow(m_hWnd,SW_HIDE);} + void Close(){SendMessage(m_hWnd,WM_CLOSE,0,0);} + void Init(LPTSTR DestFolder, HANDLE Contact); + void btnCaptureClick(); + void cboxSendByChange(); + + private: + HWND m_hWnd; + HANDLE m_hContact; + bool m_bSelectingWindow, m_bDeleteAfterSend; + bool m_bFormAbout, m_bFormEdit; + HWND m_hTargetWindow, m_hLastWin; + LPTSTR m_FDestFolder; + LPTSTR m_pszFile; + LPTSTR m_pszFileDesc; + FIBITMAP* m_Screenshot; //Graphics::TBitmap *Screenshot; + RGBQUAD m_AlphaColor; // + HCURSOR m_hCursor; + CSend* m_cSend; + + void chkTimedClick(); + void imgTargetMouseDown(); + void imgTargetMouseUp(); + void btnAboutClick(); + void btnAboutOnCloseWindow(HWND hWnd); + void btnExploreClick(); + void LoadOptions(void); + void SaveOptions(void); + INT_PTR SaveScreenshot(FIBITMAP* dib); + void FormClose(); + static void edtSizeUpdate(HWND hWnd, BOOL ClientArea, HWND hTarget, UINT Ctrl); + static void edtSizeUpdate(RECT rect, HWND hTarget, UINT Ctrl); + + protected: + size_t m_MonitorCount; + MONITORINFOEX* m_Monitors; + RECT m_VirtualScreen; + + BYTE m_opt_chkOpenAgain; //TCheckBox *chkOpenAgain; + BYTE m_opt_chkClientArea; //TCheckBox *chkClientArea; + BYTE m_opt_edtQuality; //TLabeledEdit *edtQuality; + BYTE m_opt_btnDeleteAfterSend; //TCheckBox *chkDeleteAfterSend; + BYTE m_opt_cboxFormat; //TComboBox *cboxFormat; + BYTE m_opt_edtTimed; //TLabeledEdit *edtTimed; + bool m_bCapture; //is capture activ + + typedef std::map CHandleMapping; + static CHandleMapping _HandleMapping; + static LRESULT CALLBACK DlgTfrmMain(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); + + LRESULT wmInitdialog(WPARAM wParam, LPARAM lParam); + LRESULT wmCommand(WPARAM wParam, LPARAM lParam); + LRESULT wmClose(WPARAM wParam, LPARAM lParam); + LRESULT wmNotify(WPARAM wParam, LPARAM lParam); + LRESULT wmTimer(WPARAM wParam, LPARAM lParam); + + LRESULT UMevent(WPARAM wParam, LPARAM lParam); + LRESULT UMClosing(WPARAM wParam, LPARAM lParam); + LRESULT UMTab1(WPARAM wParam, LPARAM lParam); + + HWND m_hwndTab; //TabControl handle + HWND m_hwndTabPage; //TabControl activ page handle + HIMAGELIST m_himlTab; //TabControl imagelist + static INT_PTR CALLBACK DlgProc_CaptureWindow (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); + static INT_PTR CALLBACK DlgProc_CaptureDesktop(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); +// LRESULT CALLBACK DlgProc_UseLastFile (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); + +}; + +//--------------------------------------------------------------------------- + +#endif diff --git a/plugins/SendScreenshotPlus/src/Utils.cpp b/plugins/SendScreenshotPlus/src/Utils.cpp new file mode 100644 index 0000000000..f1b7251fd7 --- /dev/null +++ b/plugins/SendScreenshotPlus/src/Utils.cpp @@ -0,0 +1,579 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* +Copyright 2000-2009 Miranda ICQ/IM project, + +This file is part of Send Screenshot Plus, a Miranda IM plugin. +Copyright (c) 2010 Ing.U.Horn + +Parts of this file based on original sorce code +(c) 2004-2006 Srgio Vieira Rolanski (portet from Borland C++) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +File name : $HeadURL: http://merlins-miranda.googlecode.com/svn/trunk/miranda/plugins/SendSSPlus/Utils.cpp $ +Revision : $Revision: 22 $ +Last change on : $Date: 2010-05-02 21:25:02 +0400 (Вс, 02 май 2010) $ +Last change by : $Author: ing.u.horn $ + +*/ + +#include "Utils.h" + +//--------------------------------------------------------------------------- +extern HINSTANCE hInst; + +//--------------------------------------------------------------------------- +//Workaround for MS bug ComboBox_SelectItemData +int ComboBox_SelectItemData(HWND hwndCtl, int indexStart, LPARAM data) { + int i = 0; + for ( i ; i < ComboBox_GetCount(hwndCtl); i++) { + if(data == ComboBox_GetItemData(hwndCtl, i)) { + ComboBox_SetCurSel (hwndCtl,i); + return i; + } + } + return CB_ERR; +} + +//--------------------------------------------------------------------------- +// MonitorInfoEnum +size_t MonitorInfoEnum(MONITORINFOEX* & myMonitors, RECT & virtualScreen) { + MONITORS tmp = {0,0}; + if (EnumDisplayMonitors(NULL, NULL, MonitorInfoEnumProc, (LPARAM)&tmp)){ + myMonitors = tmp.info; + memset(&virtualScreen, 0, sizeof(virtualScreen)); + for (size_t i = 0; i < tmp.count; ++i) { + UnionRect(&virtualScreen, &virtualScreen, &tmp.info[i].rcMonitor); + } + return tmp.count; + } + else { + if (tmp.info) mir_free(tmp.info); + } + return 0; +} + +// MonitorInfoEnumProc - CALLBACK for MonitorInfoEnum +BOOL CALLBACK MonitorInfoEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) { + MONITORS* monitors = (MONITORS*)dwData; + monitors->count++; + monitors->info = (MONITORINFOEX*)mir_realloc(monitors->info, sizeof(MONITORINFOEX)*monitors->count); + monitors->info[monitors->count-1].cbSize = sizeof(MONITORINFOEX); + if(!GetMonitorInfo(hMonitor, (LPMONITORINFO)(monitors->info + monitors->count-1))) { + return FALSE; // stop enumeration if error + } + return TRUE; +} + +//--------------------------------------------------------------------------- +// capture window as FIBITMAP - caller must FIP->FI_Unload(dib) +FIBITMAP* CaptureWindow (HWND hCapture, BOOL ClientArea) { + FIBITMAP *dib = NULL; + HWND hForegroundWin = NULL; + HDC hScrDC; // screen DC + RECT rect= {0}; // screen RECT + SIZE size; // DIB width and height = window resolution + + if (!hCapture || !IsWindow(hCapture)) return 0; + hForegroundWin = GetForegroundWindow(); //Saving foreground window + BringWindowToTop(hCapture); // This window bring the target window to the top of all others + SetForegroundWindow(hCapture); // Make sure the target window is the foreground one + // redraw window to prevent runtime artefact in picture + UpdateWindow(hCapture); + + hScrDC = GetWindowDC(hCapture); + + // get window resolution + GetWindowRect(hCapture, &rect); + size.cx = ABS(rect.right - rect.left); + size.cy = ABS(rect.bottom - rect.top); + + //capture window and get FIBITMAP + dib = CaptureScreen(hScrDC, size, hCapture); + + if(ClientArea) { + RECT rectCA = {0}; + POINT pt = {0}; + GetClientRect (hCapture, &rectCA); + ClientToScreen(hCapture, &pt); + //crop the window to ClientArea + FIBITMAP* dibClient = FIP->FI_Copy(dib, + pt.x - rect.left, + pt.y - rect.top, + pt.x - rect.left + rectCA.right -1, + pt.y - rect.top + rectCA.bottom -1); + FIP->FI_Unload(dib); + dib = dibClient; + } + + ReleaseDC(NULL, hScrDC); + + // Restoring foreground window + if (hForegroundWin) { + SetForegroundWindow(hForegroundWin); + } + + return dib; +} + +FIBITMAP* CaptureMonitor (LPTSTR szDevice) { + SIZE size; + HDC hScrDC; + FIBITMAP *dib = NULL; + // get screen resolution + if(!szDevice) { + hScrDC = GetDC(NULL); /*Get full virtualscreen*/ + size.cx = GetSystemMetrics(SM_CXVIRTUALSCREEN); + size.cy = GetSystemMetrics(SM_CYVIRTUALSCREEN); + } + else { + hScrDC = CreateDC(szDevice, NULL, NULL, NULL); + size.cx = GetDeviceCaps(hScrDC, HORZRES); + size.cy = GetDeviceCaps(hScrDC, VERTRES); + } + dib = CaptureScreen (hScrDC, size); + ReleaseDC(NULL, hScrDC); + return dib; +} + +FIBITMAP* CaptureScreen (HDC hDC, SIZE size, HWND hCapture) { +//HDC GetDC (NULL) entire desktp +//HDC GetDC (HWND hWnd) client area of the specified window. +//HDC GetWindowDC (HWND hWnd) entire window. + FIBITMAP *dib = NULL; + HBITMAP hBitmap; // handles to device-dependent bitmaps + HDC hScrDC, hMemDC; // screen DC and memory DC + + // create a DC for the screen and create + // a memory DC compatible to screen DC + hScrDC = hDC ? hDC : GetDC(NULL/*Get full screen*/); + hMemDC = CreateCompatibleDC(hScrDC); + // create a bitmap compatible with the screen DC + hBitmap = CreateCompatibleBitmap(hScrDC, size.cx, size.cy); + + // select new bitmap into memory DC + HBITMAP hOld = (HBITMAP) SelectObject(hMemDC, hBitmap); + + if(hCapture) { + PrintWindow(hCapture, hMemDC, 0/*PW_CLIENTONLY is buggy*/); + } + else { + // bitblt screen DC to memory DC + BitBlt(hMemDC, 0, 0, size.cx, size.cy, hScrDC, 0, 0, CAPTUREBLT|SRCCOPY); + } + + dib = FIP->FI_CreateDIBFromHBITMAP(hBitmap); + + //alpha channel from window is always wrong, + //coz GDI do not draw all in alpha mode. + //we have to create our own new alpha channel. + bool bFixAlpha = true; + bool bInvert = false; + + // Create monochrome (1 bit) B+W mask bitmap. + HBITMAP hMask = CreateBitmap(size.cx,size.cy, 1, 1, NULL); + HDC hMaskDC = CreateCompatibleDC(0); + SelectBitmap(hMaskDC, hMask); + + //Create a SolidBrush object for non transparent area + HBRUSH hBr = CreateSolidBrush(RGB(255,255,255)); + + HRGN hrgn = NULL; + int regionType; + if(hCapture) { + hrgn = CreateRectRgn(0,0,0,0); + regionType = GetWindowRgn(hCapture, hrgn); + if (regionType != ERROR) { + // not layerd - fill the window region + FillRgn(hMaskDC, hrgn, hBr); + } + else { //layerd window (WS_EX_LAYERED) + BYTE bAlpha= 0; + COLORREF crKey=0; //0x00bbggrr + DWORD dwFlags=0; + if(GetLayeredWindowAttributes(hCapture,&crKey,&bAlpha,&dwFlags)) { + //per window transparency (like fading in a whole window). + if((dwFlags & LWA_ALPHA) == LWA_ALPHA) { + //Use bAlpha to determine the opacity of the layered window. + bFixAlpha = false; + } + if((dwFlags & LWA_COLORKEY) == LWA_COLORKEY) { + //Use crKey as the transparency color. + SetBkColor(hMemDC, crKey); + BitBlt(hMaskDC, 0, 0, size.cx, size.cy, hMemDC, 0, 0, SRCCOPY); + bInvert = true; + bFixAlpha = true; + } + } + else { + //per-pixel transparency (won't use the WM_PAINT ) + bFixAlpha = false; + } + } + } + else { //fill the desktop region + hrgn = CreateRectRgn(0,0,size.cx,size.cy); + FillRgn(hMaskDC, hrgn, hBr); + } + + if(bFixAlpha) { + FIBITMAP* dibMask = FIP->FI_CreateDIBFromHBITMAP(hMask); + if(bInvert) FIP->FI_Invert(dibMask); + FIBITMAP* dib8 = FIP->FI_ConvertTo8Bits(dibMask); + + //copy the dib8 alpha mask to dib32 main bitmap + FIP->FI_SetChannel(dib,dib8,FICC_ALPHA); + FIP->FI_Unload(dibMask); + FIP->FI_Unload(dib8); + } + + //clean up + DeleteObject(hBr); + if(hrgn) DeleteObject(hrgn); + DeleteDC(hMaskDC); + DeleteObject(hMask); + SelectObject(hMemDC, hOld); + DeleteDC(hMemDC); + if(!hDC) ReleaseDC(NULL, hScrDC); + DeleteObject(hBitmap); + + #ifdef _DEBUG + switch (FIP->FI_GetImageType(dib)){ + case FIT_UNKNOWN: + OutputDebugStringA("FIBITMAP Typ: FIT_UNKNOWN\r\n" ); + break; + case FIT_BITMAP: + OutputDebugStringA("FIBITMAP Typ: FIT_BITMAP\r\n" ); + break; + case FIT_UINT16: + OutputDebugStringA("FIBITMAP Typ: FIT_UINT16\r\n" ); + break; + case FIT_INT16: + OutputDebugStringA("FIBITMAP Typ: FIT_INT16\r\n" ); + break; + case FIT_UINT32: + OutputDebugStringA("FIBITMAP Typ: FIT_UINT32\r\n" ); + break; + case FIT_INT32: + OutputDebugStringA("FIBITMAP Typ: FIT_INT32\r\n" ); + break; + case FIT_FLOAT: + OutputDebugStringA("FIBITMAP Typ: FIT_FLOAT\r\n" ); + break; + case FIT_DOUBLE: + OutputDebugStringA("FIBITMAP Typ: FIT_DOUBLE\r\n" ); + break; + case FIT_COMPLEX: + OutputDebugStringA("FIBITMAP Typ: FIT_COMPLEX\r\n" ); + break; + case FIT_RGB16: + OutputDebugStringA("FIBITMAP Typ: FIT_RGB16\r\n" ); + break; + case FIT_RGBA16: + OutputDebugStringA("FIBITMAP Typ: FIT_RGBA16\r\n" ); + break; + case FIT_RGBF: + OutputDebugStringA("FIBITMAP Typ: FIT_RGBF\r\n" ); + break; + case FIT_RGBAF: + OutputDebugStringA("FIBITMAP Typ: FIT_RGBAF\r\n" ); + break; + default: + OutputDebugStringA("FIBITMAP Typ: nicht feststellbar\r\n" ); + break; + } + BOOL inf = FIP->FI_IsTransparent(dib); + OutputDebugStringA(inf ? "FIBITMAP Transparent: true\r\n" : "FIBITMAP Transparent: fase\r\n"); + #endif + + return dib; +} + +FIBITMAP* CaptureDesktop/*emulate print screen*/() { + FIBITMAP *dib = NULL; + HBITMAP hBitmap; // handles to device-dependent bitmaps + BOOL bBitmap = false; + int i = 0; + keybd_event(VK_SNAPSHOT, 0x45, KEYEVENTF_EXTENDEDKEY, 0); + keybd_event(VK_SNAPSHOT, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0); + do {//Clipboard need time to get bitmap from keybd_event, + i++; //we use a counter to get this time. + bBitmap = IsClipboardFormatAvailable(CF_BITMAP); + if(i == 500) return (FIBITMAP*)0; //emergency exit if something go wrong + } while (!bBitmap); + #ifdef _DEBUG + char mess[120] = {0}; + LPSTR pszMess = mess; + mir_snprintf(pszMess,120,"SS Bitmap counter: %i\r\n",i); + OutputDebugStringA( pszMess ); + #endif + //get clipboard data + OpenClipboard(NULL); + hBitmap = (HBITMAP)GetClipboardData(CF_BITMAP); + + //create FIBITMAP * from HBITMAP + FIP->FI_CorrectBitmap32Alpha(hBitmap, FALSE); + dib = FIP->FI_CreateDIBFromHBITMAP(hBitmap); + CloseClipboard(); + + return dib; +} + +LPTSTR SaveImage(FREE_IMAGE_FORMAT fif, FIBITMAP* dib, LPTSTR pszFilename, LPTSTR pszExt, int flag) { + int ret=0; + LPTSTR pszFile = NULL; + LPTSTR FileExt = (LPTSTR)GetFileExt (pszFilename, DBVT_TCHAR); + if(!FileExt) { + if(!pszExt) return NULL; + mir_tcsadd(pszFile, pszFilename); + mir_tcsadd(pszFile, _T(".")); + mir_tcsadd(pszFile, pszExt); + } + else { + mir_tcsadd(pszFile, pszFilename); + } + + if(fif==FIF_UNKNOWN) { + #if defined(_UNICODE) + fif = FIP->FI_GetFIFFromFilenameU(pszFile); + #else + fif = FIP->FI_GetFIFFromFilename(pszFile); + #endif + } + if(FIP->FI_FIFSupportsICCProfiles(fif)) { + bool bDummy = true; + } + + #if defined(_UNICODE) + ret = FIP->FI_SaveU(fif, dib, pszFile, flag); + #else + ret = FIP->FI_Save(fif, dib, pszFile, flag); + #endif + + mir_free(FileExt); + + if(ret) return pszFile; + mir_free(pszFile); + return NULL; +} + +//--------------------------------------------------------------------------- +//Draws a selection border on the window under cursor +void DrawBorderInverted(HWND hWindow) { + if (!hWindow){ + return; + } + HDC hDC=GetWindowDC(hWindow); + RECT rect={0}; + GetWindowRect(hWindow, &rect); + + int dcSave = SaveDC(hDC); + + SetROP2(hDC, R2_NOT); + + HPEN hPen=0; + hPen = CreatePen(PS_SOLID, 10, RGB(0, 0, 0)); + + SelectObject(hDC, &hPen); + SelectObject(hDC, GetStockObject(NULL_BRUSH)); + + Rectangle(hDC, 0, 0, rect.right-rect.left, rect.bottom-rect.top); + Rectangle(hDC, 1, 1, rect.right-rect.left-1, rect.bottom-rect.top-1); + Rectangle(hDC, 2, 2, rect.right-rect.left-2, rect.bottom-rect.top-2); + + RestoreDC(hDC, dcSave); +} + +//--------------------------------------------------------------------------- +//is left mouse button down +BOOL GetLmouse() { + SHORT temp = GetAsyncKeyState((GetSystemMetrics(SM_SWAPBUTTON)) ? VK_RBUTTON : VK_LBUTTON); + if ((temp & 0x8000) == 0x8000) { // LBUTTON down + return TRUE; + } + return FALSE; +} + +//--------------------------------------------------------------------------- +//is miranda unicode +BOOL mir_is_unicode() { + char ver[1024]; + CallService(MS_SYSTEM_GETVERSIONTEXT, (WPARAM) sizeof(ver), (LPARAM) ver); + return strstr(ver, "Unicode") != NULL; +} + +//--------------------------------------------------------------------------- +INT_PTR GetFileName(LPTSTR pszPath, UINT typ) { + /*DBVT_ASCIIZ, DBVT_WCHAR, DBVT_TCHAR*/ + LPTSTR slash = _tcsrchr(pszPath,_T('\\')); + if (slash) { + switch (typ) { + case DBVT_ASCIIZ: + return (INT_PTR)mir_t2a(slash+1); + case DBVT_WCHAR: + return (INT_PTR)mir_t2u(slash+1); + default: + return 0; + } + } + else { + switch (typ) { + case DBVT_ASCIIZ: + return (INT_PTR)mir_t2a(pszPath); + case DBVT_WCHAR: + return (INT_PTR)mir_t2u(pszPath); + default: + return 0; + } + } +} + +INT_PTR GetFileExt (LPTSTR pszPath, UINT typ) { + /*DBVT_ASCIIZ, DBVT_WCHAR, DBVT_TCHAR*/ + LPTSTR slash = _tcsrchr(pszPath,_T('.')); + if (slash) { + switch (typ) { + case DBVT_ASCIIZ: + return (INT_PTR)mir_t2a(slash); + case DBVT_WCHAR: + return (INT_PTR)mir_t2u(slash); + default: + return 0; + } + } + else { + return NULL; + } +} + +//--------------------------------------------------------------------------- +BOOL GetEncoderClsid(wchar_t *wchMimeType, CLSID& clsidEncoder) { + UINT uiNum = 0; + UINT uiSize = 0; + BOOL bOk = FALSE; + Gdiplus::ImageCodecInfo* pImageCodecInfo = NULL; + Gdiplus::GetImageEncodersSize(&uiNum, &uiSize); + if( uiSize > 0 ) { + pImageCodecInfo = (Gdiplus::ImageCodecInfo *)new char[uiSize]; + if( pImageCodecInfo ) { + Gdiplus::GetImageEncoders(uiNum, uiSize, pImageCodecInfo); + for( UINT i = 0; i < uiNum; i++ ) { + if( wcscmp(pImageCodecInfo[i].MimeType, wchMimeType) == 0 ) { + clsidEncoder = pImageCodecInfo[i].Clsid; + bOk = TRUE; + } + } + } + delete pImageCodecInfo; + } + return bOk; +} + +INT_PTR SavePNG(HBITMAP hBmp, LPTSTR szFilename) { + Gdiplus::GdiplusStartupInput gdiplusStartupInput; + ULONG_PTR gdiplusToken; + Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); + + Gdiplus::Bitmap *pBitmap = Gdiplus::Bitmap::FromHBITMAP(hBmp, (HPALETTE)GetStockObject(DEFAULT_PALETTE) ); + if( pBitmap ) { + // Get the CLSID of the PNG encoder. + CLSID clsidEncoder; + if( GetEncoderClsid(L"image/png", clsidEncoder)) { + LPWSTR pswFile = mir_t2u(szFilename); + pBitmap->Save((const WCHAR*)pswFile, &clsidEncoder, NULL); + mir_free(pswFile); + } + delete pBitmap; + } + Gdiplus::GdiplusShutdown(gdiplusToken); + return 0; +} + +INT_PTR SaveGIF(HBITMAP hBmp, LPTSTR szFilename) { + Gdiplus::GdiplusStartupInput gdiplusStartupInput; + ULONG_PTR gdiplusToken; + Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); + + Gdiplus::Bitmap *pBitmap = Gdiplus::Bitmap::FromHBITMAP(hBmp, (HPALETTE)GetStockObject(DEFAULT_PALETTE) ); + if( pBitmap ) { + // Get the CLSID of the GIF encoder. + CLSID clsidEncoder; + if( GetEncoderClsid(L"image/gif", clsidEncoder)) { + LPWSTR pswFile = mir_t2u(szFilename); + pBitmap->Save((const WCHAR*)pswFile, &clsidEncoder, NULL); + mir_free(pswFile); + } + delete pBitmap; + } + Gdiplus::GdiplusShutdown(gdiplusToken); + return 0; +} + +INT_PTR SaveTIF(HBITMAP hBmp, LPTSTR szFilename) { +//http://www.codeproject.com/Messages/1406708/How-to-reduce-the-size-of-an-Image-using-GDIplus.aspx + ULONG_PTR gdiplusToken; + Gdiplus::GdiplusStartupInput gdiplusStartupInput; + Gdiplus::Status stat; + Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); + + Gdiplus::Bitmap *pBitmap = Gdiplus::Bitmap::FromHBITMAP(hBmp, (HPALETTE)GetStockObject(DEFAULT_PALETTE) ); + if( pBitmap ) { + // Get the CLSID of the GIF encoder. + CLSID EncCLSID; + if( GetEncoderClsid(L"image/tiff", EncCLSID)) { + //--- Create a 2-parameter array, for Compression and for Color Bit depth + Gdiplus::EncoderParameters* EncParams = (Gdiplus::EncoderParameters*) malloc(sizeof(Gdiplus::EncoderParameters) + 1 * sizeof(Gdiplus::EncoderParameter)); + // Gdiplus::EncoderParameters pEncoderParameters; + //--- Use LZW Compression instead of Group 4, since it works for color and G4 doesn't + ULONG ulCompression = Gdiplus::EncoderValueCompressionLZW ; + ULONG ulColorDepth = 24L ; + + EncParams->Count = 2 ; + EncParams->Parameter[0].Guid = Gdiplus::EncoderCompression ; + EncParams->Parameter[0].Type = Gdiplus::EncoderParameterValueTypeLong ; + EncParams->Parameter[0].NumberOfValues = 1 ; + EncParams->Parameter[0].Value = &ulCompression ; + EncParams->Parameter[1].Guid = Gdiplus::EncoderColorDepth ; + EncParams->Parameter[1].Type = Gdiplus::EncoderParameterValueTypeLong ; + EncParams->Parameter[1].NumberOfValues = 1 ; + EncParams->Parameter[1].Value = &ulColorDepth ; + + LPWSTR pswFile = mir_t2u(szFilename); + stat = pBitmap->Save((const WCHAR*)pswFile, &EncCLSID, EncParams); + mir_free(pswFile); + free(EncParams); + } + delete pBitmap; + } + Gdiplus::GdiplusShutdown(gdiplusToken); + return 0; +} + +//--------------------------------------------------------------------------- +/* Old stuff from Borland C++ */ +//--------------------------------------------------------------------------- +/*/Popup +void ShowPopUp(char *title, char *text) { + POPUPDATAEX pude={0}; + + strcpy(pude.lpzText, text); + strcpy(pude.lpzContactName, title); + pude.lchIcon = LoadIcon(g_hAppInstance, MAKEINTRESOURCE(MAIN)); + pude.colorBack = POPUP_USE_SKINNED_BG; + + CallService(MS_POPUP_ADDPOPUP, (WPARAM)&pude, 0); +}*/ + diff --git a/plugins/SendScreenshotPlus/src/Utils.h b/plugins/SendScreenshotPlus/src/Utils.h new file mode 100644 index 0000000000..2934391a8b --- /dev/null +++ b/plugins/SendScreenshotPlus/src/Utils.h @@ -0,0 +1,81 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* +Copyright 2000-2009 Miranda ICQ/IM project, + +This file is part of Send Screenshot Plus, a Miranda IM plugin. +Copyright (c) 2010 Ing.U.Horn + +Parts of this file based on original sorce code +(c) 2004-2006 Srgio Vieira Rolanski (portet from Borland C++) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +File name : $HeadURL: http://merlins-miranda.googlecode.com/svn/trunk/miranda/plugins/SendSSPlus/Utils.h $ +Revision : $Revision: 22 $ +Last change on : $Date: 2010-05-02 21:25:02 +0400 (Вс, 02 май 2010) $ +Last change by : $Author: ing.u.horn $ + +*/ + +#ifndef UTILSH +#define UTILSH + +#include "global.h" +//#include +//#include +#define SPP_USERPANE 1 + +extern FI_INTERFACE *FIP; + +#define ABS(x) ((x)<0?-(x):(x)) + +typedef struct TEnumDataTemp { +size_t count; +MONITORINFOEX* info; +}MONITORS; + +extern HWND g_hCapture; +extern HBITMAP g_hBitmap, g_hbmMask; + +//--------------------------------------------------------------------------- +int ComboBox_SelectItemData(HWND hwndCtl, int indexStart, LPARAM data); + +size_t MonitorInfoEnum(MONITORINFOEX* & myMonitors, RECT & virtualScreen); +BOOL CALLBACK MonitorInfoEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData); + +FIBITMAP* CaptureWindow(HWND hCapture, BOOL ClientArea); +FIBITMAP* CaptureMonitor(LPTSTR szDevice); +FIBITMAP* CaptureScreen(HDC hDC, SIZE size, HWND hCapture=0); +FIBITMAP* CaptureDesktop(); /*emulate print screen (not used)*/ +LPTSTR SaveImage(FREE_IMAGE_FORMAT fif, FIBITMAP* dib, LPTSTR pszFilename, LPTSTR pszExt, int flag=0); + +void DrawBorderInverted(HWND hWindow); +BOOL GetLmouse(); +BOOL mir_is_unicode(); +INT_PTR GetFileName(LPTSTR pszPath, UINT typ); +INT_PTR GetFileExt (LPTSTR pszPath, UINT typ); + +BOOL GetEncoderClsid(wchar_t *wchMimeType, CLSID& clsidEncoder); +INT_PTR SavePNG(HBITMAP hBmp, LPTSTR szFilename); +INT_PTR SaveGIF(HBITMAP hBmp, LPTSTR szFilename); +INT_PTR SaveTIF(HBITMAP hBmp, LPTSTR szFilename); + +//--------------------------------------------------------------------------- +/* Old stuff from Borland C++ +//void ShowPopUp(char *title, char *text); + +*/ +#endif diff --git a/plugins/SendScreenshotPlus/src/ctrl_button.cpp b/plugins/SendScreenshotPlus/src/ctrl_button.cpp new file mode 100644 index 0000000000..ad8e542fa3 --- /dev/null +++ b/plugins/SendScreenshotPlus/src/ctrl_button.cpp @@ -0,0 +1,699 @@ +/* +Miranda IM +Copyright (C) 2002 Robert Rainwater + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ +#include "global.h" + +// Used for our own cheap TrackMouseEvent +#define BUTTON_POLLID 100 +#define BUTTON_POLLDELAY 50 + +#define MGPROC(x) GetProcAddress(themeAPIHandle,x) + +typedef struct TMBCtrl{ + HWND hwnd; + HANDLE hThemeButton; + HANDLE hThemeToolbar; + + HICON hIcon; + HICON arrow; // uses down arrow + HBITMAP hBitmap; + HFONT hFont; // font + + DWORD dwStyle; + BOOLEAN bFocus; + + INT stateId; // button state + INT defbutton; // default button + INT pbState; + TCHAR cHot; +} BTNCTRL, *LPBTNCTRL; + +// External theme methods and properties +CRITICAL_SECTION csTips; +HWND hwndToolTips = NULL; +HMODULE themeAPIHandle = NULL; + +// theme procedures +HANDLE (WINAPI *OpenThemeData)(HWND,LPCWSTR); +HRESULT (WINAPI *CloseThemeData)(HANDLE); +BOOL (WINAPI *IsThemeBackgroundPartiallyTransparent)(HANDLE,INT,INT); +HRESULT (WINAPI *DrawThemeParentBackground)(HWND,HDC,RECT *); +HRESULT (WINAPI *DrawThemeBackground)(HANDLE,HDC,INT,INT,const RECT *,const RECT *); +HRESULT (WINAPI *DrawThemeText)(HANDLE,HDC,INT,INT,LPCWSTR,INT,DWORD,DWORD,const RECT *); +HRESULT (WINAPI *GetThemeTextExtent)(HANDLE,HDC,INT,INT,LPCWSTR,INT,DWORD,OPTIONAL const RECT*, RECT *); +HRESULT (WINAPI *GetThemeBackgroundRegion)(HANDLE,HDC,INT,INT,const RECT *,HRGN *); + +/** + * name: ThemeSupport + * desc: Loads the uxtheme functions, if supported by the os + * param: none + * return: TRUE if themes are supported, FALSE if not + **/ +BOOLEAN __fastcall ThemeSupport() { + if (IsWinVerXPPlus()) { + if (!themeAPIHandle) { + themeAPIHandle = GetModuleHandleA("uxtheme"); + if (themeAPIHandle) { + OpenThemeData = (HANDLE (WINAPI *)(HWND,LPCWSTR))MGPROC("OpenThemeData"); + CloseThemeData = (HRESULT (WINAPI *)(HANDLE))MGPROC("CloseThemeData"); + IsThemeBackgroundPartiallyTransparent = (BOOL (WINAPI *)(HANDLE,INT,INT))MGPROC("IsThemeBackgroundPartiallyTransparent"); + DrawThemeParentBackground = (HRESULT (WINAPI *)(HWND,HDC,RECT *))MGPROC("DrawThemeParentBackground"); + DrawThemeBackground = (HRESULT (WINAPI *)(HANDLE,HDC,INT,INT,const RECT *,const RECT *))MGPROC("DrawThemeBackground"); + DrawThemeText = (HRESULT (WINAPI *)(HANDLE,HDC,INT,INT,LPCWSTR,INT,DWORD,DWORD,const RECT *))MGPROC("DrawThemeText"); + GetThemeTextExtent = (HRESULT (WINAPI *)(HANDLE,HDC,INT,INT,LPCWSTR,INT,DWORD,OPTIONAL const RECT*, RECT *))MGPROC("GetThemeTextExtent"); + GetThemeBackgroundRegion = (HRESULT (WINAPI *)(HANDLE,HDC,INT,INT,const RECT *,HRGN *))MGPROC("GetThemeBackgroundRegion"); + } + } + // Make sure all of these methods are valid (i would hope either all or none work) + if (OpenThemeData + && CloseThemeData + && IsThemeBackgroundPartiallyTransparent + && DrawThemeParentBackground + && DrawThemeBackground + && DrawThemeText + && GetThemeTextExtent) + { + return TRUE; + } + } + return FALSE; +} + +/** + * name: DestroyTheme + * desc: destroys theme data for buttons + * param: ctl - BTNCTRL structure with the information about the theme to close + * return: nothing + **/ +static VOID __fastcall DestroyTheme(BTNCTRL *ctl) { + if (ctl->hThemeButton) { + CloseThemeData(ctl->hThemeButton); + ctl->hThemeButton = NULL; + } + if (ctl->hThemeToolbar) { + CloseThemeData(ctl->hThemeToolbar); + ctl->hThemeToolbar = NULL; + } +} + +/** + * name: LoadTheme + * desc: load theme data for buttons if supported by os + * param: ctl - BTNCTRL structure with the information about the theme to load + * return: nothing + **/ +static VOID __fastcall LoadTheme(BTNCTRL *ctl) { + if (ThemeSupport()) { + DestroyTheme(ctl); + ctl->hThemeButton = OpenThemeData(ctl->hwnd,L"BUTTON"); + ctl->hThemeToolbar = OpenThemeData(ctl->hwnd,L"TOOLBAR"); + } +} + +/** + * name: TBStateConvert2Flat + * desc: convert button stateIDs + * param: state - state id for the normal theme button + * return: stateID for the flat theme button + **/ +static INT __fastcall TBStateConvert2Flat(INT state) { + switch (state) { + case PBS_NORMAL: return TS_NORMAL; + case PBS_HOT: return TS_HOT; + case PBS_PRESSED: return TS_PRESSED; + case PBS_DISABLED: return TS_DISABLED; + case PBS_DEFAULTED: return TS_NORMAL; + } + return TS_NORMAL; +} + +/** + * name: PaintIcon + * desc: Draws the Icon of the button + * param: ctl - BTNCTRL structure for the button + * hdcMem - device context to draw to + * ccText - character count of the text of the button + * rcClient - rectangle of the whole button + * rcText - rectangle of the text to draw later on + * return: nothing + **/ +static VOID __fastcall PaintIcon(BTNCTRL *ctl, HDC hdcMem, LPWORD ccText, LPRECT rcClient, LPRECT rcText) +{ + RECT rcImage; + + // draw icon on the left of the button + if (ctl->hIcon) { + rcImage.right = GetSystemMetrics(SM_CXSMICON); + rcImage.bottom = GetSystemMetrics(SM_CYSMICON); + rcImage.left = (rcClient->right - rcClient->left) / 2 - ((rcImage.right + rcText->right + (*ccText > 0 ? 4 : 0) + (ctl->arrow ? rcImage.right : 0)) / 2); + rcImage.top = (rcClient->bottom - rcClient->top - rcImage.bottom) / 2; + rcImage.right += rcImage.left; + rcImage.bottom += rcImage.top; + + OffsetRect(rcText, rcImage.right + 4, 0); + if (ctl->stateId == PBS_PRESSED) OffsetRect(&rcImage, 1, 1); + + DrawState(hdcMem, NULL, NULL, (LPARAM)ctl->hIcon, 0, + rcImage.left, rcImage.top, + rcImage.right - rcImage.left, rcImage.bottom - rcImage.top, + IsWindowEnabled(ctl->hwnd) ? DST_ICON | DSS_NORMAL : DST_ICON | DSS_DISABLED); + } + + // draw arrow on the right of the button + if (ctl->arrow) { + rcImage.right = GetSystemMetrics(SM_CXSMICON); + rcImage.left = (*ccText > 0 || ctl->hIcon) + ? rcClient->right - GetSystemMetrics(SM_CXSMICON) + : (rcClient->right - rcClient->left - rcImage.right) / 2; + rcImage.right += rcImage.left; + rcImage.bottom = GetSystemMetrics(SM_CYSMICON); + rcImage.top = (rcClient->bottom - rcClient->top - rcImage.bottom) / 2; + if (ctl->stateId == PBS_PRESSED) OffsetRect(&rcImage, 1, 1); + + DrawState(hdcMem, NULL, NULL, (LPARAM)ctl->arrow, 0, + rcImage.left, rcImage.top, + rcImage.right - rcImage.left, rcImage.bottom - rcImage.top, + IsWindowEnabled(ctl->hwnd) ? DST_ICON | DSS_NORMAL : DST_ICON | DSS_DISABLED); + } +} + +/** + * name: PaintThemeButton + * desc: Draws the themed button + * param: ctl - BTNCTRL structure for the button + * hdcMem - device context to draw to + * rcClient - rectangle of the whole button + * return: nothing + **/ +static VOID __fastcall PaintThemeButton(BTNCTRL *ctl, HDC hdcMem, LPRECT rcClient) +{ + RECT rcText = { 0, 0, 0, 0 }; + WCHAR wszText[MAX_PATH] = { 0 }; + WORD ccText; + + // Draw the flat button + if ((ctl->dwStyle & MBS_FLAT) && ctl->hThemeToolbar) { + INT state = IsWindowEnabled(ctl->hwnd) + ? (ctl->stateId == PBS_NORMAL && ctl->defbutton + ? PBS_DEFAULTED + : ctl->stateId) + : PBS_DISABLED; + if (IsThemeBackgroundPartiallyTransparent(ctl->hThemeToolbar, TP_BUTTON, TBStateConvert2Flat(state))) { + if (SUCCEEDED(DrawThemeParentBackground(ctl->hwnd, hdcMem, rcClient))) + DrawThemeParentBackground(GetParent(ctl->hwnd), hdcMem, rcClient); + } + DrawThemeBackground(ctl->hThemeToolbar, hdcMem, TP_BUTTON, TBStateConvert2Flat(state), rcClient, rcClient); + } + else { + // draw themed button background + if (ctl->hThemeButton) { + INT state = IsWindowEnabled(ctl->hwnd) + ? (ctl->stateId == PBS_NORMAL && ctl->defbutton + ? PBS_DEFAULTED + : ctl->stateId) + : PBS_DISABLED; + if (IsThemeBackgroundPartiallyTransparent(ctl->hThemeButton, BP_PUSHBUTTON, state)) { + if (SUCCEEDED(DrawThemeParentBackground(ctl->hwnd, hdcMem, rcClient))) + DrawThemeParentBackground(GetParent(ctl->hwnd), hdcMem, rcClient); + } + DrawThemeBackground(ctl->hThemeButton, hdcMem, BP_PUSHBUTTON, state, rcClient, rcClient); + } + } + + // calculate text rect + { + RECT sizeText; + HFONT hOldFont; + + ccText = GetWindowTextW(ctl->hwnd, wszText, sizeof(wszText) / sizeof(WCHAR)); + + if (ccText > 0) { + hOldFont = (HFONT)SelectObject(hdcMem, ctl->hFont); + + GetThemeTextExtent( + ctl->hThemeButton, + hdcMem, + BP_PUSHBUTTON, + IsWindowEnabled(ctl->hwnd) ? ctl->stateId : PBS_DISABLED, + wszText, + ccText, + DST_PREFIXTEXT, + NULL, + &sizeText); + + if (ctl->cHot) { + RECT rcHot; + + GetThemeTextExtent(ctl->hThemeButton, + hdcMem, + BP_PUSHBUTTON, + IsWindowEnabled(ctl->hwnd) ? ctl->stateId : PBS_DISABLED, + L"&", + 1, + DST_PREFIXTEXT, + NULL, + &rcHot); + + sizeText.right -= (rcHot.right - rcHot.left); + } + SelectObject(hdcMem, hOldFont); + + rcText.left = (ctl->hIcon) ? 0 : (rcClient->right - rcClient->left - (sizeText.right - sizeText.left)) / 2; + rcText.top = (rcClient->bottom - rcClient->top - (sizeText.bottom - sizeText.top)) / 2; + rcText.right = rcText.left + (sizeText.right - sizeText.left); + rcText.bottom = rcText.top + (sizeText.bottom - sizeText.top); + if (ctl->stateId == PBS_PRESSED) { + OffsetRect(&rcText, 1, 1); + } + } + } + PaintIcon(ctl, hdcMem, &ccText, rcClient, &rcText); + // draw text + if (ccText > 0 && ctl->hThemeButton) { + HFONT hOldFont = (HFONT)SelectObject(hdcMem, ctl->hFont); + DrawThemeText(ctl->hThemeButton, hdcMem, BP_PUSHBUTTON, IsWindowEnabled(ctl->hwnd) ? ctl->stateId : PBS_DISABLED, wszText, ccText, DST_PREFIXTEXT, 0, &rcText); + SelectObject(hdcMem, hOldFont); + } +} + +/** + * name: PaintThemeButton + * desc: Draws the none themed button + * param: ctl - BTNCTRL structure for the button + * hdcMem - device context to draw to + * rcClient - rectangle of the whole button + * return: nothing + **/ +static VOID __fastcall PaintButton(BTNCTRL *ctl, HDC hdcMem, LPRECT rcClient) +{ + RECT rcText = { 0, 0, 0, 0 }; + TCHAR szText[MAX_PATH] = { 0 }; + WORD ccText; + + // Draw the flat button + if (ctl->dwStyle & MBS_FLAT) { + HBRUSH hbr = NULL; + + if (ctl->stateId == PBS_PRESSED || ctl->stateId == PBS_HOT) + hbr = GetSysColorBrush(COLOR_3DLIGHT); + else { + HDC dc; + HWND hwndParent; + + hwndParent = GetParent(ctl->hwnd); + if (dc = GetDC(hwndParent)) { + hbr = (HBRUSH)SendMessage(hwndParent, WM_CTLCOLORDLG, (WPARAM)dc, (LPARAM)hwndParent); + ReleaseDC(hwndParent, dc); + } + } + if (hbr) { + FillRect(hdcMem, rcClient, hbr); + DeleteObject(hbr); + } + if (ctl->stateId == PBS_HOT || ctl->bFocus) { + if (ctl->pbState) DrawEdge(hdcMem, rcClient, EDGE_ETCHED, BF_RECT|BF_SOFT); + else DrawEdge(hdcMem, rcClient, BDR_RAISEDOUTER, BF_RECT|BF_SOFT|BF_FLAT); + } + else + if (ctl->stateId == PBS_PRESSED) + DrawEdge(hdcMem, rcClient, BDR_SUNKENOUTER, BF_RECT|BF_SOFT); + } + else { + UINT uState = DFCS_BUTTONPUSH|((ctl->stateId == PBS_HOT) ? DFCS_HOT : 0)|((ctl->stateId == PBS_PRESSED) ? DFCS_PUSHED : 0); + if (ctl->defbutton&&ctl->stateId==PBS_NORMAL) uState |= DLGC_DEFPUSHBUTTON; + DrawFrameControl(hdcMem, rcClient, DFC_BUTTON, uState); + // Draw focus rectangle if button has focus + if (ctl->bFocus) { + RECT focusRect = *rcClient; + InflateRect(&focusRect, -3, -3); + DrawFocusRect(hdcMem, &focusRect); + } + } + // calculate text rect + { + SIZE sizeText; + HFONT hOldFont; + + ccText = GetWindowText(ctl->hwnd, szText, SIZEOF(szText)); + + if (ccText > 0) { + hOldFont = (HFONT)SelectObject(hdcMem, ctl->hFont); + GetTextExtentPoint32(hdcMem, szText, ccText, &sizeText); + if (ctl->cHot) { + SIZE sizeHot; + + GetTextExtentPoint32A(hdcMem, "&", 1, &sizeHot); + sizeText.cx -= sizeHot.cx; + } + SelectObject(hdcMem, hOldFont); + + rcText.left = (ctl->hIcon) ? 0 : (rcClient->right - rcClient->left - sizeText.cx) / 2; + rcText.top = (rcClient->bottom - rcClient->top - sizeText.cy) / 2; + rcText.right = rcText.left + sizeText.cx; + rcText.bottom = rcText.top + sizeText.cy; + if (ctl->stateId == PBS_PRESSED) + OffsetRect(&rcText, 1, 1); + } + } + PaintIcon(ctl, hdcMem, &ccText, rcClient, &rcText); + + // draw text + if (ccText > 0) { + HFONT hOldFont; + + hOldFont = (HFONT)SelectObject(hdcMem, ctl->hFont); + + SetBkMode(hdcMem, TRANSPARENT); + SetTextColor(hdcMem, + IsWindowEnabled(ctl->hwnd) || !ctl->hThemeButton + ? ctl->stateId == PBS_HOT + ? GetSysColor(COLOR_HOTLIGHT) + : GetSysColor(COLOR_BTNTEXT) + : GetSysColor(COLOR_GRAYTEXT)); + + DrawState(hdcMem, NULL, NULL, (LPARAM)szText, 0, + rcText.left, rcText.top, rcText.right - rcText.left, rcText.bottom - rcText.top, + IsWindowEnabled(ctl->hwnd) || ctl->hThemeButton ? DST_PREFIXTEXT | DSS_NORMAL : DST_PREFIXTEXT | DSS_DISABLED); + SelectObject(hdcMem, hOldFont); + } +} + +/** + * name: Button_WndProc + * desc: window procedure for the button class + * param: hwndBtn - window handle to the button + * uMsg - message to handle + * wParam - message specific parameter + * lParam - message specific parameter + * return: message specific + **/ +static LRESULT CALLBACK Button_WndProc(HWND hwndBtn, UINT uMsg, WPARAM wParam, LPARAM lParam) { + LPBTNCTRL bct = (LPBTNCTRL)GetWindowLongPtr(hwndBtn, 0); + + switch (uMsg) { + case WM_NCCREATE: + { + LPCREATESTRUCT cs = (LPCREATESTRUCT)lParam; + + cs->style |= BS_OWNERDRAW; + if (!(bct = (LPBTNCTRL)malloc(sizeof(BTNCTRL)))) + return FALSE; + ZeroMemory(bct, sizeof(BTNCTRL)); + bct->hwnd = hwndBtn; + bct->stateId = PBS_NORMAL; + bct->hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT); + bct->dwStyle = cs->style; + if (cs->style & MBS_DOWNARROW) + bct->arrow = IcoLib_GetIcon(ICO_BTN_DOWNARROW); + LoadTheme(bct); + SetWindowLongPtr(hwndBtn, 0, (LONG_PTR)bct); + if (cs->lpszName) SetWindowText(hwndBtn, cs->lpszName); + return TRUE; + } + case WM_DESTROY: + if (bct) { + EnterCriticalSection(&csTips); + if (hwndToolTips) { + TOOLINFO ti; + + ZeroMemory(&ti, sizeof(ti)); + ti.cbSize = sizeof(ti); + ti.uFlags = TTF_IDISHWND; + ti.hwnd = bct->hwnd; + ti.uId = (UINT)bct->hwnd; + if (SendMessage(hwndToolTips, TTM_GETTOOLINFO, 0, (LPARAM)&ti)) { + SendMessage(hwndToolTips, TTM_DELTOOL, 0, (LPARAM)&ti); + } + if (SendMessage(hwndToolTips, TTM_GETTOOLCOUNT, 0, (LPARAM)&ti) == 0) { + DestroyWindow(hwndToolTips); + hwndToolTips = NULL; + } + } + LeaveCriticalSection(&csTips); + DestroyTheme(bct); + free(bct); + } + SetWindowLongPtr(hwndBtn, 0, NULL); + break; + case WM_SETTEXT: + bct->cHot = 0; + if ((LPTSTR)lParam) { + LPTSTR tmp = (LPTSTR)lParam; + + while (*tmp) { + if (*tmp=='&' && *(tmp+1)) { + bct->cHot = _totlower(*(tmp+1)); + break; + } + tmp++; + } + InvalidateRect(bct->hwnd, NULL, TRUE); + } + break; + case WM_SYSKEYUP: + if (bct->stateId != PBS_DISABLED && bct->cHot && bct->cHot == _totlower((TCHAR)wParam)) { + if (bct->dwStyle & MBS_PUSHBUTTON) { + if (bct->pbState) bct->pbState = 0; + else bct->pbState = 1; + InvalidateRect(bct->hwnd, NULL, TRUE); + } + else + SetFocus(hwndBtn); + SendMessage(GetParent(hwndBtn), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndBtn), BN_CLICKED), (LPARAM)hwndBtn); + return 0; + } + break; + case WM_THEMECHANGED: + { + // themed changed, reload theme object + LoadTheme(bct); + InvalidateRect(bct->hwnd, NULL, TRUE); // repaint it + break; + } + case WM_SETFONT: // remember the font so we can use it later + bct->hFont = (HFONT)wParam; // maybe we should redraw? + break; + case WM_NCPAINT: + case WM_PAINT: + { + PAINTSTRUCT ps; + HDC hdcPaint; + HDC hdcMem; + HBITMAP hbmMem; + HDC hOld; + RECT rcClient; + + if (hdcPaint = BeginPaint(hwndBtn, &ps)) { + GetClientRect(bct->hwnd, &rcClient); + hdcMem = CreateCompatibleDC(hdcPaint); + hbmMem = CreateCompatibleBitmap(hdcPaint, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top); + hOld = (HDC)SelectObject(hdcMem, hbmMem); + + // If its a push button, check to see if it should stay pressed + if ((bct->dwStyle & MBS_PUSHBUTTON) && bct->pbState) bct->stateId = PBS_PRESSED; + + if ((bct->dwStyle & MBS_FLAT) && bct->hThemeToolbar || bct->hThemeButton) + PaintThemeButton(bct, hdcMem, &rcClient); + else + PaintButton(bct, hdcMem, &rcClient); + + BitBlt(hdcPaint, 0, 0, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, hdcMem, 0, 0, SRCCOPY); + SelectObject(hdcMem, hOld); + DeleteObject(hbmMem); + DeleteDC(hdcMem); + EndPaint(hwndBtn, &ps); + } + return 0; + } + case BM_SETIMAGE: + if (wParam == IMAGE_ICON) { + bct->hIcon = (HICON)lParam; + bct->hBitmap = NULL; + InvalidateRect(bct->hwnd, NULL, TRUE); + } + else if (wParam == IMAGE_BITMAP) { + bct->hIcon = NULL; + bct->hBitmap = (HBITMAP)lParam; + InvalidateRect(bct->hwnd, NULL, TRUE); + } + else if (wParam == NULL && lParam == NULL) { + bct->hIcon = NULL; + bct->hBitmap = NULL; + InvalidateRect(bct->hwnd, NULL, TRUE); + } + break; + case BM_SETCHECK: + if (!(bct->dwStyle & MBS_PUSHBUTTON)) break; + if (wParam == BST_CHECKED) { + bct->pbState = 1; + bct->stateId = PBS_PRESSED; + } + else if (wParam == BST_UNCHECKED) { + bct->pbState = 0; + bct->stateId = PBS_NORMAL; + } + InvalidateRect(bct->hwnd, NULL, TRUE); + break; + case BM_GETCHECK: + if (bct->dwStyle & MBS_PUSHBUTTON) return bct->pbState ? BST_CHECKED : BST_UNCHECKED; + return 0; + case BUTTONSETDEFAULT: + bct->defbutton = wParam ? 1 : 0; + InvalidateRect(bct->hwnd, NULL, TRUE); + break; + case BUTTONADDTOOLTIP: + { + if (!wParam) break; + EnterCriticalSection(&csTips); + if (!hwndToolTips) { + hwndToolTips = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, WS_POPUP, 0, 0, 0, 0, NULL, NULL, GetModuleHandle(NULL), NULL); + } + + if (lParam == MBF_UNICODE) { + TOOLINFOW ti; + + ZeroMemory(&ti, sizeof(TOOLINFOW)); + ti.cbSize = sizeof(TOOLINFOW); + ti.uFlags = TTF_IDISHWND; + ti.hwnd = bct->hwnd; + ti.uId = (UINT)bct->hwnd; + if (SendMessage(hwndToolTips, TTM_GETTOOLINFOW, 0, (LPARAM)&ti)) { + SendMessage(hwndToolTips, TTM_DELTOOLW, 0, (LPARAM)&ti); + } + ti.uFlags = TTF_IDISHWND|TTF_SUBCLASS; + ti.uId = (UINT)bct->hwnd; + ti.lpszText=(LPWSTR)wParam; + SendMessage(hwndToolTips, TTM_ADDTOOLW, 0, (LPARAM)&ti); + } + else { + TOOLINFOA ti; + + ZeroMemory(&ti, sizeof(TOOLINFOA)); + ti.cbSize = sizeof(TOOLINFOA); + ti.uFlags = TTF_IDISHWND; + ti.hwnd = bct->hwnd; + ti.uId = (UINT)bct->hwnd; + if (SendMessage(hwndToolTips, TTM_GETTOOLINFOA, 0, (LPARAM)&ti)) { + SendMessage(hwndToolTips, TTM_DELTOOLA, 0, (LPARAM)&ti); + } + ti.uFlags = TTF_IDISHWND|TTF_SUBCLASS; + ti.uId = (UINT)bct->hwnd; + ti.lpszText=(LPSTR)wParam; + SendMessage(hwndToolTips, TTM_ADDTOOLA, 0, (LPARAM)&ti); + } + LeaveCriticalSection(&csTips); + break; + } + case BUTTONTRANSLATE: + { + TCHAR szButton[MAX_PATH]; + GetWindowText(bct->hwnd, szButton, MAX_PATH); + SetWindowText(bct->hwnd, TranslateTS(szButton)); + break; + } + case WM_SETFOCUS: // set keybord bFocus and redraw + bct->bFocus = 1; + InvalidateRect(bct->hwnd, NULL, TRUE); + break; + case WM_KILLFOCUS: // kill bFocus and redraw + bct->bFocus = 0; + InvalidateRect(bct->hwnd, NULL, TRUE); + break; + case WM_WINDOWPOSCHANGED: + InvalidateRect(bct->hwnd, NULL, TRUE); + break; + case WM_ENABLE: // windows tells us to enable/disable + bct->stateId = wParam ? PBS_NORMAL : PBS_DISABLED; + InvalidateRect(bct->hwnd, NULL, TRUE); + break; + case WM_MOUSELEAVE: // faked by the WM_TIMER + if (bct->stateId != PBS_DISABLED) { // don't change states if disabled + bct->stateId = PBS_NORMAL; + InvalidateRect(bct->hwnd, NULL, TRUE); + } + break; + case WM_LBUTTONDOWN: + if (bct->stateId != PBS_DISABLED) { // don't change states if disabled + bct->stateId = PBS_PRESSED; + InvalidateRect(bct->hwnd, NULL, TRUE); + } + break; + case WM_LBUTTONUP: + if (bct->stateId != PBS_DISABLED) { // don't change states if disabled + BOOLEAN bPressed = bct->stateId == PBS_PRESSED; + + if (bct->dwStyle & MBS_PUSHBUTTON) { + if (bct->pbState) bct->pbState = 0; + else bct->pbState = 1; + } + bct->stateId = PBS_HOT; + + // Tell your daddy you got clicked, if mouse is still over the button. + if ((bct->dwStyle & MBS_PUSHBUTTON) || bPressed) + SendMessage(GetParent(hwndBtn), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndBtn), BN_CLICKED), (LPARAM)hwndBtn); + InvalidateRect(bct->hwnd, NULL, TRUE); + } + break; + case WM_MOUSEMOVE: + if (bct->stateId == PBS_NORMAL) { + bct->stateId = PBS_HOT; + InvalidateRect(bct->hwnd, NULL, TRUE); + } + // Call timer, used to start cheesy TrackMouseEvent faker + SetTimer(hwndBtn, BUTTON_POLLID, BUTTON_POLLDELAY, NULL); + break; + case WM_TIMER: // use a timer to check if they have did a mouseout + if (wParam == BUTTON_POLLID) { + RECT rc; + POINT pt; + + GetWindowRect(hwndBtn, &rc); + GetCursorPos(&pt); + if (!PtInRect(&rc, pt)) { // mouse must be gone, trigger mouse leave + PostMessage(hwndBtn, WM_MOUSELEAVE, 0, 0L); + KillTimer(hwndBtn, BUTTON_POLLID); + } + } + break; + case WM_ERASEBKGND: + return 1; + } + return DefWindowProc(hwndBtn, uMsg, wParam, lParam); +} + +VOID CtrlButtonUnloadModule() +{ + DeleteCriticalSection(&csTips); + UnregisterClass(UINFOBUTTONCLASS, hInst); +} + +VOID CtrlButtonLoadModule() +{ + WNDCLASSEX wc; + + ZeroMemory(&wc, sizeof(wc)); + wc.cbSize = sizeof(wc); + wc.lpszClassName = UINFOBUTTONCLASS; + wc.lpfnWndProc = Button_WndProc; + wc.hCursor = LoadCursor(NULL, IDC_ARROW); + wc.cbWndExtra = sizeof(LPBTNCTRL); + wc.style = CS_GLOBALCLASS; + RegisterClassEx(&wc); + InitializeCriticalSection(&csTips); +} + diff --git a/plugins/SendScreenshotPlus/src/ctrl_button.h b/plugins/SendScreenshotPlus/src/ctrl_button.h new file mode 100644 index 0000000000..dc77334b05 --- /dev/null +++ b/plugins/SendScreenshotPlus/src/ctrl_button.h @@ -0,0 +1,43 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* + +Copyright 2000-2009 Miranda ICQ/IM project, +all portions of this codebase are copyrighted to the people +listed in contributors.txt. + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +aLONG with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ +#ifndef _UINFOEX_BOTTONS_H_INCLUDED_ +#define _UINFOEX_BOTTONS_H_INCLUDED_ 1 + +// theme procedures +extern HANDLE (WINAPI *OpenThemeData)(HWND,LPCWSTR); +extern HRESULT (WINAPI *CloseThemeData)(HANDLE); +extern BOOL (WINAPI *IsThemeBackgroundPartiallyTransparent)(HANDLE,INT,INT); +extern HRESULT (WINAPI *DrawThemeParentBackground)(HWND,HDC,RECT *); +extern HRESULT (WINAPI *DrawThemeBackground)(HANDLE,HDC,INT,INT,const RECT *,const RECT *); +extern HRESULT (WINAPI *DrawThemeText)(HANDLE,HDC,INT,INT,LPCWSTR,INT,DWORD,DWORD,const RECT *); +extern HRESULT (WINAPI *GetThemeTextExtent)(HANDLE,HDC,INT,INT,LPCWSTR,INT,DWORD,OPTIONAL const RECT*, RECT *); +extern HRESULT (WINAPI *GetThemeBackgroundRegion)(HANDLE,HDC,INT,INT,const RECT *,HRGN *); + + +VOID CtrlButtonLoadModule(); +VOID CtrlButtonUnloadModule(); + +BOOLEAN __fastcall ThemeSupport(); + +#endif /* _UINFOEX_BOTTONS_H_INCLUDED_ */ \ No newline at end of file diff --git a/plugins/SendScreenshotPlus/src/dlg_msgbox.cpp b/plugins/SendScreenshotPlus/src/dlg_msgbox.cpp new file mode 100644 index 0000000000..f1b1535802 --- /dev/null +++ b/plugins/SendScreenshotPlus/src/dlg_msgbox.cpp @@ -0,0 +1,854 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* + +Copyright 2000-2009 Miranda ICQ/IM project, +all portions of this codebase are copyrighted to the people +listed in contributors.txt. + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +aLONG with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +File name : $HeadURL: https://userinfoex.googlecode.com/svn/trunk/dlg_msgbox.cpp $ +Revision : $Revision: 164 $ +Last change on : $Date: 2009-12-02 21:24:35 +0100 (Mi, 02. Dez 2009) $ +Last change by : $Author: ing.u.horn $ + +*/ + +#include "dlg_msgbox.h" + +typedef struct _MSGPOPUPDATA +{ + POPUPACTION pa[3]; + HWND hDialog; +} +MSGPOPUPDATA, *LPMSGPOPUPDATA; + +/** + * This helper function moves and resizes a dialog box's control element. + * + * @param hDlg - the dialog box's window handle + * @param idCtrl - the identication number of the control to move + * @param dx -number of pixels to horizontal move the control + * @param dy - number of pixels to vertical move the control + * @param dw - number of pixels to horizontal resize the control + * @param dh - number of pixels to vertical resize the control + * + * @return nothing + **/ +static FORCEINLINE VOID MoveCtrl(HWND hDlg, INT idCtrl, INT dx, INT dy, INT dw, INT dh) +{ + RECT ws; + HWND hCtrl = GetDlgItem(hDlg, idCtrl); + GetWindowRect(hCtrl, &ws); + OffsetRect(&ws, dx, dy); + MoveWindow(hCtrl, ws.left, ws.top, ws.right - ws.left + dw, ws.bottom - ws.top + dh, FALSE); +} + +/** + * This function loads the icon to display for the current message. + * + * @param pMsgBox - pointer to a MSGBOX structure, with information about the message to display. + * + * @retval HICON - The function returns an icon to display with the message. + * @retval NULL - There is no icon for the message. + **/ +HICON MsgLoadIcon(LPMSGBOX pMsgBox) +{ + HICON hIcon; + + // load the desired status icon + switch (pMsgBox->uType & MB_ICONMASK) + { + + // custom icon defined by caller function + case MB_ICON_OTHER: + { + hIcon = pMsgBox->hiMsg; + } + break; + + // default windows icons + case MB_ICON_ERROR: + case MB_ICON_QUESTION: + case MB_ICON_WARNING: + case MB_ICON_INFO: + { + LPCTSTR ico[] = { 0, IDI_ERROR, IDI_QUESTION, IDI_WARNING, IDI_INFORMATION }; + hIcon = LoadIcon(NULL, ico[MB_ICON_INDEX(pMsgBox->uType)]); + } + break; + + // no icon + default: + { + hIcon = NULL; + } + } + return hIcon; +} + +/** + * This function fills a given POPUPACTION structure with the data of a given message id, + * which is normally used by the message box. This is required to let the user interact + * with a popup in the same way as with a normal message dialog box. + * + * @param pa - reference to a POPUPACTION structure to fill + * @param id - the message id + * @param result - This parameter is passed to the POPUPACTION structure as is. + * + * @return nothing + **/ +void MakePopupAction(POPUPACTION &pa, INT id) +{ + pa.cbSize = sizeof(POPUPACTION); + pa.flags = PAF_ENABLED; + pa.wParam = MAKEWORD(id, BN_CLICKED); + pa.lParam = 0; + + switch (id) + { + case IDOK: + { + pa.lchIcon = IcoLib_GetIcon(ICO_BTN_OK); + mir_strcpy(pa.lpzTitle, MODNAME"/Ok"); + } + break; + + case IDCLOSE: + case IDCANCEL: + { + pa.lchIcon = IcoLib_GetIcon(ICO_BTN_CANCEL); + mir_strcpy(pa.lpzTitle, MODNAME"/Cancel"); + } + break; + + case IDABORT: + { + pa.lchIcon = IcoLib_GetIcon(ICO_BTN_CANCEL); + mir_strcpy(pa.lpzTitle, MODNAME"/Abort"); + } + break; + + case IDRETRY: + { + pa.lchIcon = IcoLib_GetIcon(ICO_BTN_UPDATE); + mir_strcpy(pa.lpzTitle, MODNAME"/Retry"); + } + break; + + case IDIGNORE: + { + pa.lchIcon = IcoLib_GetIcon(ICO_BTN_OK); + mir_strcpy(pa.lpzTitle, MODNAME"/Ignore"); + } + break; + + case IDYES: + { + pa.lchIcon = IcoLib_GetIcon(ICO_BTN_OK); + mir_strcpy(pa.lpzTitle, MODNAME"/Yes"); + } + break; + + case IDNO: + { + pa.lchIcon = IcoLib_GetIcon(ICO_BTN_CANCEL); + mir_strcpy(pa.lpzTitle, MODNAME"/No"); + } + break; + + case IDHELP: + { + pa.lchIcon = IcoLib_GetIcon(ICO_BTN_CANCEL); + mir_strcpy(pa.lpzTitle, MODNAME"/Help"); + } + break; + + case IDALL: + { + pa.lchIcon = IcoLib_GetIcon(ICO_BTN_OK); + mir_strcpy(pa.lpzTitle, MODNAME"/All"); + } + break; + + case IDNONE: + { + pa.lchIcon = IcoLib_GetIcon(ICO_BTN_CANCEL); + mir_strcpy(pa.lpzTitle, MODNAME"/None"); + } + } +} + +/** + * This is the message procedure for my nice looking message box + * + * @param hDlg - window handle + * @param uMsg - message to handle + * @param wParam - message specific parameter + * @param lParam - message specific parameter + * + * @return TRUE, FALSE, IDOK, IDYES, IDALL, IDNO or IDCANCEL + **/ +INT_PTR CALLBACK MsgBoxProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + static INT retOk = IDOK; + static INT retAll = IDALL; + static INT retNon = IDNONE; + static INT retCancel = IDCANCEL; + + switch (uMsg) + { + case WM_INITDIALOG: + { + LPMSGBOX pMsgBox = (LPMSGBOX)lParam; + + if (PtrIsValid(pMsgBox)) + { + INT icoWidth = 0; + INT InfoBarHeight = 0; + HFONT hNormalFont; + + hNormalFont = (HFONT)SendDlgItemMessage(hDlg, TXT_NAME, WM_GETFONT, 0, 0); + if (pMsgBox->uType & MB_INFOBAR) + { + LOGFONT lf; + + // set bold font for name in description area + GetObject(hNormalFont, sizeof(lf), &lf); + lf.lfWeight = FW_BOLD; + hNormalFont = CreateFontIndirect(&lf); + + // set infobar's textfont + SendDlgItemMessage(hDlg, TXT_NAME, WM_SETFONT, (WPARAM)hNormalFont, 0); + + // set infobar's logo icon + SendDlgItemMessage(hDlg, ICO_DLGLOGO, STM_SETIMAGE, IMAGE_ICON, + (LPARAM)((pMsgBox->hiLogo) ? pMsgBox->hiLogo : IcoLib_GetIcon(ICO_DLG_DETAILS))); + + // anable headerbar + ShowWindow(GetDlgItem(hDlg, TXT_NAME), SW_SHOW); + ShowWindow(GetDlgItem(hDlg, ICO_DLGLOGO), SW_SHOW); + } + else + { + RECT rc; + GetClientRect(GetDlgItem(hDlg, TXT_NAME), &rc); + InfoBarHeight = rc.bottom; + + if (pMsgBox->hiLogo) + { + SendMessage(hDlg, WM_SETICON, ICON_BIG, (LPARAM)pMsgBox->hiLogo); + } + } + + // draw the desired status icon + HICON hIcon = MsgLoadIcon(pMsgBox); + if (hIcon) + { + SendDlgItemMessage(hDlg, ICO_MSGDLG, STM_SETIMAGE, IMAGE_ICON, (LPARAM)hIcon); + } + else + { + RECT ws; + GetWindowRect(GetDlgItem(hDlg, ICO_MSGDLG), &ws); + icoWidth = ws.right - ws.left; + ShowWindow(GetDlgItem(hDlg, ICO_MSGDLG), SW_HIDE); + } + + // resize the messagebox and reorganize the buttons + if (HDC hDC = GetDC(hDlg)) + { + POINT mpt = {0,0}; + RECT ws = {0,0,0,0}; + INT txtWidth, + txtHeight, + needX, needY; + RECT rcDlg; + SIZE ts; + LPTSTR h, rs; + + SelectObject(hDC, hNormalFont); + + for (rs = h = pMsgBox->ptszMsg, txtHeight = 0, txtWidth = 0; h; h++) + { + if (*h == '\n' || *h == '\0') + { + GetTextExtentPoint32(hDC, rs, h - rs, &ts); + if (ts.cx > txtWidth) + { + txtWidth = ts.cx; + } + txtHeight += ts.cy; + if (*h == '\0') + { + break; + } + rs = h + 1; + } + } + ReleaseDC(hDlg, hDC); + + // calc new dialog size + GetWindowRect(hDlg, &rcDlg); + GetWindowRect(GetDlgItem(hDlg, TXT_MESSAGE), &ws); + needX = txtWidth - (ws.right - ws.left) - icoWidth; + needY = max(0, txtHeight - (ws.bottom - ws.top) + 5); + rcDlg.left -= needX/2; rcDlg.right += needX/2; + rcDlg.top -= (needY-InfoBarHeight)/2; rcDlg.bottom += (needY-InfoBarHeight)/2; + + // resize dialog window + MoveWindow(hDlg, + rcDlg.left, rcDlg.top, + rcDlg.right - rcDlg.left, + rcDlg.bottom - rcDlg.top, + FALSE); + ClientToScreen(hDlg, &mpt); + + MoveCtrl(hDlg, STATIC_WHITERECT, -mpt.x, -mpt.y, needX, needY - InfoBarHeight); + MoveCtrl(hDlg, TXT_NAME, -mpt.x, -mpt.y, needX, 0); + MoveCtrl(hDlg, ICO_DLGLOGO, -mpt.x + needX, -mpt.y, 0, 0); + MoveCtrl(hDlg, ICO_MSGDLG, -mpt.x, -mpt.y - InfoBarHeight, 0, 0); + MoveCtrl(hDlg, TXT_MESSAGE, -mpt.x - icoWidth, -mpt.y - InfoBarHeight, needX, needY); + MoveCtrl(hDlg, STATIC_LINE2, -mpt.x, -mpt.y + needY - InfoBarHeight, needX, 0); + + // + // Do pushbutton positioning + // + { + RECT rcOk, rcAll, rcNone, rcCancel; + LONG okWidth, caWidth, allWidth, noneWidth, dlgMid; + + // get button rectangles + GetWindowRect(GetDlgItem(hDlg, IDOK), &rcOk); + OffsetRect(&rcOk, -mpt.x, -mpt.y + needY - InfoBarHeight); + + GetWindowRect(GetDlgItem(hDlg, IDALL), &rcAll); + OffsetRect(&rcAll, -mpt.x, -mpt.y + needY - InfoBarHeight); + + GetWindowRect(GetDlgItem(hDlg, IDNONE), &rcNone); + OffsetRect(&rcNone, -mpt.x, -mpt.y + needY - InfoBarHeight); + + GetWindowRect(GetDlgItem(hDlg, IDCANCEL), &rcCancel); + OffsetRect(&rcCancel, -mpt.x, -mpt.y + needY - InfoBarHeight); + + okWidth = rcOk.right - rcOk.left; + allWidth = rcAll.right - rcAll.left; + noneWidth = rcNone.right - rcNone.left; + caWidth = rcCancel.right - rcCancel.left; + dlgMid = (rcDlg.right - rcDlg.left) / 2; + + // load button configuration + switch (MB_TYPE(pMsgBox->uType)) + { + + case MB_OK: + { + rcOk.left = dlgMid - (okWidth / 2); + rcOk.right = rcOk.left + okWidth; + ShowWindow(GetDlgItem(hDlg, IDOK), SW_SHOW); + } + break; + + case MB_OKCANCEL: + { + retOk = IDRETRY; + SetDlgItemText(hDlg, IDOK, LPGENT("OK")); + retCancel = IDCANCEL; + SetDlgItemText(hDlg, IDCANCEL, LPGENT("Cancel")); + rcOk.left = dlgMid - okWidth - 10; + rcOk.right = rcOk.left + okWidth; + rcCancel.left = dlgMid + 10; + rcCancel.right = rcCancel.left + caWidth; + ShowWindow(GetDlgItem(hDlg, IDOK), SW_SHOW); + ShowWindow(GetDlgItem(hDlg, IDCANCEL), SW_SHOW); + } + break; + + case MB_RETRYCANCEL: + { + retOk = IDRETRY; + SetDlgItemText(hDlg, IDOK, LPGENT("Retry")); + retCancel = IDCANCEL; + SetDlgItemText(hDlg, IDCANCEL, LPGENT("Cancel")); + rcOk.left = dlgMid - okWidth - 10; + rcOk.right = rcOk.left + okWidth; + rcCancel.left = dlgMid + 10; + rcCancel.right = rcCancel.left + caWidth; + ShowWindow(GetDlgItem(hDlg, IDOK), SW_SHOW); + ShowWindow(GetDlgItem(hDlg, IDCANCEL), SW_SHOW); + } + break; + + case MB_YESNO: + { + retOk = IDYES; + SetDlgItemText(hDlg, IDOK, LPGENT("Yes")); + retCancel = IDNO; + SetDlgItemText(hDlg, IDCANCEL, LPGENT("No")); + rcOk.left = dlgMid - okWidth - 10; + rcOk.right = rcOk.left + okWidth; + rcCancel.left = dlgMid + 10; + rcCancel.right = rcCancel.left + caWidth; + ShowWindow(GetDlgItem(hDlg, IDOK), SW_SHOW); + ShowWindow(GetDlgItem(hDlg, IDCANCEL), SW_SHOW); + } + break; + + case MB_ABORTRETRYIGNORE: + { + retOk = IDABORT; + SetDlgItemText(hDlg, IDOK, LPGENT("Abord")); + retAll = IDABORT; + SetDlgItemText(hDlg, IDALL, LPGENT("Retry")); + retCancel = IDCANCEL; + SetDlgItemText(hDlg, IDCANCEL, LPGENT("Ignore")); + rcAll.left = dlgMid - (allWidth / 2); + rcAll.right = rcAll.left + allWidth; + rcOk.left = rcAll.left - okWidth - 5; + rcOk.right = rcOk.left + okWidth; + rcCancel.left = rcAll.right + 5; + rcCancel.right = rcCancel.left + caWidth; + ShowWindow(GetDlgItem(hDlg, IDOK), SW_SHOW); + ShowWindow(GetDlgItem(hDlg, IDALL), SW_SHOW); + ShowWindow(GetDlgItem(hDlg, IDCANCEL), SW_SHOW); + } + break; + + case MB_YESNOCANCEL: + { + retOk = IDYES; + SetDlgItemText(hDlg, IDOK, LPGENT("Yes")); + retAll = IDNO; + SetDlgItemText(hDlg, IDALL, LPGENT("No")); + retCancel = IDCANCEL; + SetDlgItemText(hDlg, IDCANCEL, LPGENT("Cancel")); + rcAll.left = dlgMid - (allWidth / 2); + rcAll.right = rcAll.left + allWidth; + rcOk.left = rcAll.left - okWidth - 5; + rcOk.right = rcOk.left + okWidth; + rcCancel.left = rcAll.right + 5; + rcCancel.right = rcCancel.left + caWidth; + ShowWindow(GetDlgItem(hDlg, IDOK), SW_SHOW); + ShowWindow(GetDlgItem(hDlg, IDALL), SW_SHOW); + ShowWindow(GetDlgItem(hDlg, IDCANCEL), SW_SHOW); + } + break; + + case MB_YESALLNO: + { + retOk = IDYES; + SetDlgItemText(hDlg, IDOK, LPGENT("Yes")); + retAll = IDALL; + SetDlgItemText(hDlg, IDALL, LPGENT("All")); + //retNon = IDNONE; + SetDlgItemText(hDlg, IDNONE, LPGENT("None")); + retCancel = IDNO; + SetDlgItemText(hDlg, IDCANCEL, LPGENT("No")); + rcCancel.right = rcDlg.right - rcDlg.left - 10; + rcCancel.left = rcCancel.right - caWidth; + rcNone.right = rcCancel.left - 5; + rcNone.left = rcNone.right - noneWidth; + rcAll.right = rcNone.left - 5; + rcAll.left = rcAll.right - allWidth; + rcOk.right = rcAll.left - 5; + rcOk.left = rcOk.right - okWidth; + // show buttons + ShowWindow(GetDlgItem(hDlg, IDOK), SW_SHOW); + ShowWindow(GetDlgItem(hDlg, IDALL), SW_SHOW); + ShowWindow(GetDlgItem(hDlg, IDNONE), SW_SHOW); + ShowWindow(GetDlgItem(hDlg, IDCANCEL), SW_SHOW); + } + break; + + default: + { + rcOk.left = dlgMid - (okWidth / 2); + rcOk.right = rcOk.left + okWidth; + } + } + // move ok button + MoveWindow(GetDlgItem(hDlg, IDOK), + rcOk.left, rcOk.top, + rcOk.right - rcOk.left, rcOk.bottom - rcOk.top, + FALSE); + // move all button + MoveWindow(GetDlgItem(hDlg, IDALL), + rcAll.left, rcAll.top, + rcAll.right - rcAll.left, rcAll.bottom - rcAll.top, + FALSE); + // move none button + MoveWindow(GetDlgItem(hDlg, IDNONE), + rcNone.left, rcNone.top, + rcNone.right - rcNone.left, rcNone.bottom - rcNone.top, + FALSE); + // move cancel button + MoveWindow(GetDlgItem(hDlg, IDCANCEL), + rcCancel.left, rcCancel.top, + rcCancel.right - rcCancel.left, rcCancel.bottom - rcCancel.top, + FALSE); + } // end* Do pushbutton positioning + } // end* resize the messagebox and reorganize the buttons + + TranslateDialogDefault(hDlg); + + // set text's + SetWindowText(hDlg, pMsgBox->ptszTitle); + SetDlgItemText(hDlg, TXT_NAME, pMsgBox->ptszInfoText); + SetDlgItemText(hDlg, TXT_MESSAGE, pMsgBox->ptszMsg); + + return TRUE; + } // end* PtrIsValid(pMsgBox) + } // end* WM_INITDIALOG: + break; + + case WM_CTLCOLORSTATIC: + { + switch (GetWindowLong((HWND)lParam, GWL_ID)) + { + case STATIC_WHITERECT: + case ICO_DLGLOGO: + case ICO_MSGDLG: + case TXT_MESSAGE: + case TXT_NAME: + { + SetTextColor((HDC)wParam, GetSysColor(COLOR_WINDOWTEXT)); + return GetSysColor(COLOR_WINDOW); + } + } + } + break; + + case WM_COMMAND: + { + switch (LOWORD(wParam)) + { + case IDOK: + EndDialog(hDlg, retOk); + break; + case IDCANCEL: + EndDialog(hDlg, retCancel); + break; + case IDALL: + EndDialog(hDlg, retAll); + break; + case IDNONE: + EndDialog(hDlg, retNon); + } + } + break; + + case WM_DESTROY: + { + DeleteObject((HFONT)SendDlgItemMessage(hDlg, TXT_NAME, WM_GETFONT, 0, 0)); + } + break; + } + return FALSE; +} + + +/** + * Dummi modal MsgBox for popup, + * this set call function in wait stait and do not freece miranda main thread + * the window is outside the desktop + */ +INT_PTR CALLBACK MsgBoxPop(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + switch (uMsg) + { + case WM_INITDIALOG: + { + POPUPDATAT_V2 pd; + LPMSGPOPUPDATA pmpd; + LPMSGBOX pMsgBox = (LPMSGBOX)lParam; + + MoveWindow(hDlg,-10,-10,0,0,FALSE); + pmpd = (LPMSGPOPUPDATA)mir_alloc(sizeof(MSGPOPUPDATA)); + if (pmpd) + { + ZeroMemory(&pd, sizeof(pd)); + pd.cbSize = sizeof(POPUPDATAT); + pd.lchContact = NULL; //(HANDLE)wParam; + // icon + pd.lchIcon = MsgLoadIcon(pMsgBox); + mir_tcsncpy(pd.lptzContactName, pMsgBox->ptszTitle, SIZEOF(pd.lptzContactName)); + mir_tcsncpy(pd.lptzText, pMsgBox->ptszMsg, SIZEOF(pd.lptzText)); + + // CALLBAC Proc + pd.PluginWindowProc = (WNDPROC)PopupProc; + // + pd.PluginData = pmpd; + + pd.iSeconds = -1; + + pd.hNotification = NULL; + pd.lpActions = pmpd->pa; + + // set color of popup + switch (pMsgBox->uType & MB_ICONMASK) + { + case MB_ICON_ERROR: + { + pd.colorBack = RGB(200, 10, 0); + pd.colorText = RGB(255, 255, 255); + } + break; + + case MB_ICON_WARNING: + { + pd.colorBack = RGB(200, 100, 0); + pd.colorText = RGB(255, 255, 255); + } + break; + + default: + { + if (pMsgBox->uType & MB_CUSTOMCOLOR) + { + pd.colorBack = pMsgBox->colorBack; + pd.colorText = pMsgBox->colorText; + } + } + } + + // handle for MakePopupAction + pmpd->hDialog = hDlg; + + // active buttons + switch (MB_TYPE(pMsgBox->uType)) + { + case MB_OK: + { + MakePopupAction(pmpd->pa[pd.actionCount++], IDOK); + } + break; + + case MB_OKCANCEL: + { + MakePopupAction(pmpd->pa[pd.actionCount++], IDOK); + MakePopupAction(pmpd->pa[pd.actionCount++], IDCANCEL); + } + break; + + case MB_RETRYCANCEL: + { + MakePopupAction(pmpd->pa[pd.actionCount++], IDRETRY); + MakePopupAction(pmpd->pa[pd.actionCount++], IDCANCEL); + } + break; + + case MB_YESNO: + { + MakePopupAction(pmpd->pa[pd.actionCount++], IDYES); + MakePopupAction(pmpd->pa[pd.actionCount++], IDNO); + } + break; + + case MB_ABORTRETRYIGNORE: + { + MakePopupAction(pmpd->pa[pd.actionCount++], IDABORT); + MakePopupAction(pmpd->pa[pd.actionCount++], IDRETRY); + MakePopupAction(pmpd->pa[pd.actionCount++], IDIGNORE); + } + break; + + case MB_YESNOCANCEL: + { + MakePopupAction(pmpd->pa[pd.actionCount++], IDYES); + MakePopupAction(pmpd->pa[pd.actionCount++], IDNO); + MakePopupAction(pmpd->pa[pd.actionCount++], IDCANCEL); + } + break; + + case MB_YESALLNO: + { + MakePopupAction(pmpd->pa[pd.actionCount++], IDYES); + MakePopupAction(pmpd->pa[pd.actionCount++], IDALL); + MakePopupAction(pmpd->pa[pd.actionCount++], IDNO); + } + break; + + } // end* switch + + // create popup + CallService(MS_POPUP_ADDPOPUPT, (WPARAM) &pd, APF_NEWDATA); + if (MB_TYPE(pMsgBox->uType) == MB_OK) + { + EndDialog(hDlg, IDOK); + } + } // end*if (pmpd) + break; + } // end* WM_INITDIALOG: + } // end* switch (uMsg) + return FALSE; +} + +/** + * This is the message procedure for popup + * + * @param hDlg - window handle + * @param uMsg - message to handle + * @param wParam - message specific parameter + * @param lParam - message specific parameter + * + * @return TRUE, FALSE, IDOK, IDYES, IDALL, IDNO or IDCANCEL + **/ +INT_PTR CALLBACK PopupProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + switch (uMsg) + { + case UM_POPUPACTION: + { + if (HIWORD(wParam) == BN_CLICKED) + { + LPMSGPOPUPDATA pmpd = (LPMSGPOPUPDATA)PUGetPluginData(hDlg); + + if (pmpd) + { + switch (LOWORD(wParam)) + { + case IDOK: + case IDCANCEL: + case IDABORT: + case IDRETRY: + case IDIGNORE: + case IDYES: + case IDNO: + case IDALL: + case IDNONE: + { + if (IsWindow(pmpd->hDialog)) + EndDialog(pmpd->hDialog, LOWORD(wParam)); + } + break; + + default: + { + if (IsWindow(pmpd->hDialog)) + EndDialog(pmpd->hDialog, IDCANCEL); + } + } + } + PUDeletePopUp(hDlg); + } + } + break; + + case UM_FREEPLUGINDATA: + { + LPMSGPOPUPDATA pmpd = (LPMSGPOPUPDATA)PUGetPluginData(hDlg); + if (pmpd > 0) { + mir_freeAndNil(pmpd); + } + return TRUE; //TRUE or FALSE is the same, it gets ignored. + } + break; + + default: + break; + } + return DefWindowProc(hDlg, uMsg, wParam, lParam); +} + +/** + * This is the service function for external plugins to use the nice messagebox + * + * @param wParam - HANDLE hContact which can display an avatar for popups + * @param lParam - MSGBOX structure holding parameters + * + * @return The function returns the ID of the clicked button (IDOK, IDCANCEL, ...) + * or -1 on error. + **/ +INT_PTR MsgBoxService(WPARAM wParam, LPARAM lParam) +{ + INT rc = -1; + LPMSGBOX pMsgBox = (LPMSGBOX)lParam; + + // check input + if (PtrIsValid(pMsgBox) && pMsgBox->cbSize == sizeof(MSGBOX)) + { + // Shall the MessageBox displayed as popup? + if (!(pMsgBox->uType & (MB_INFOBAR|MB_NOPOPUP)) && // message box can be a popup? + ServiceExists(MS_POPUP_ADDPOPUPT) && // popups exist? + myGlobals.PopUpActionsExist == 1 && // popup support ext stuct? + (DBGetContactSettingDword(NULL, "PopUp","Actions", 0) & 1) && // popup++ actions on? + DBGetContactSettingByte(NULL, MODNAME, SET_POPUPMSGBOX, DEFVAL_POPUPMSGBOX) // user likes popups? + ) + { + rc = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_MSGBOXDUMMI), pMsgBox->hParent, (DLGPROC)MsgBoxPop, lParam); + } + else + { + rc = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_MSGBOX), pMsgBox->hParent, (DLGPROC)MsgBoxProc, lParam); + } + } + return rc; +} + +/** + * name: MsgBox + * desc: calls a messagebox + * param: + **/ +INT_PTR MsgBox(HWND hParent, UINT uType, LPTSTR pszTitle, LPTSTR pszInfo, LPTSTR pszFormat, ...) +{ + MSGBOX mb = {0}; + TCHAR tszMsg[MAX_SECONDLINE]; + va_list vl; + + va_start(vl, pszFormat); + mir_vsntprintf(tszMsg, SIZEOF(tszMsg), TranslateTS(pszFormat), vl); + va_end(vl); + + mb.cbSize = sizeof(MSGBOX); + mb.hParent = hParent; + mb.hiLogo = LoadIcon(hInst, MAKEINTRESOURCE(IDI_PLUG_MAIN)); + mb.hiMsg = NULL; + mb.ptszTitle = TranslateTS(pszTitle); + mb.ptszInfoText = TranslateTS(pszInfo); + mb.ptszMsg = tszMsg; + mb.uType = uType; + return MsgBoxService(NULL, (LPARAM)&mb); +} + +/** + * name: MsgErr + * desc: calls a messagebox + * param: + **/ +INT_PTR MsgErr(HWND hParent, LPCTSTR pszFormat, ...) +{ + if(!pszFormat) return -1; + MSGBOX mb = {0}; + TCHAR tszTitle[MAX_SECONDLINE]; + TCHAR tszMsg[MAX_SECONDLINE]; + va_list vl; + + mir_sntprintf(tszTitle, SIZEOF(tszMsg),_T("%s - %s") ,_T(MODNAME), TranslateT("Error")); + + va_start(vl, pszFormat); + mir_vsntprintf(tszMsg, SIZEOF(tszMsg), TranslateTS(pszFormat), vl); + va_end(vl); + + mb.cbSize = sizeof(MSGBOX); + mb.hParent = hParent; + mb.hiLogo = LoadIcon(hInst, MAKEINTRESOURCE(IDI_PLUG_MAIN)); + mb.hiMsg = NULL; + mb.ptszTitle = tszTitle; + mb.ptszMsg = tszMsg; + mb.uType = MB_OK|MB_ICON_ERROR; + return MsgBoxService(NULL, (LPARAM)&mb); +} diff --git a/plugins/SendScreenshotPlus/src/dlg_msgbox.h b/plugins/SendScreenshotPlus/src/dlg_msgbox.h new file mode 100644 index 0000000000..a6cd04c6b7 --- /dev/null +++ b/plugins/SendScreenshotPlus/src/dlg_msgbox.h @@ -0,0 +1,108 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* + +Copyright 2000-2009 Miranda ICQ/IM project, +all portions of this codebase are copyrighted to the people +listed in contributors.txt. + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +aLONG with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +File name : $HeadURL: https://userinfoex.googlecode.com/svn/trunk/dlg_msgbox.h $ +Revision : $Revision: 164 $ +Last change on : $Date: 2009-12-02 21:24:35 +0100 (Mi, 02. Dez 2009) $ +Last change by : $Author: ing.u.horn $ + +*/ + +#ifndef _DLG_MSGBOX +#define _DLG_MSGBOX 1 + +//--------------------------------------------------------------------------- +#include "global.h" + +//--------------------------------------------------------------------------- +#define SET_POPUPMSGBOX "PopupMsgBox" +#define DEFVAL_POPUPMSGBOX TRUE //FALSE + +/* UserInfo/MsgBox v0.1.0.3+ +Some little changed message box for nicer look of miranda's messages or questions :-) +wParam=hContact - can be null +lParam=(_MSGBOX*)pMsg - structure that holds information about the look of the message dialog +uType member of _MSGBOX can be a combination of the following values, where most of them are defined in winuser.h: +MB_OK +MB_OKCANCEL +MB_YESALLNO +MB_YESNO +For valid icon values use one of the following MB_ICON_... +Funktion returns: IDOK, IDYES, IDALL, IDNO or IDCANCEL +*/ + +/* + Defined in winuser.h + ******************** + +#define MB_OK 0x00000000L +#define MB_OKCANCEL 0x00000001L +#define MB_ABORTRETRYIGNORE 0x00000002L +#define MB_YESNOCANCEL 0x00000003L +#define MB_YESNO 0x00000004L +#define MB_RETRYCANCEL 0x00000005L +*/ +#define MB_YESALLNO 0x00000007L +#define MB_TYPE(p) ((p)&MB_TYPEMASK) + +/* +valid predefined icon values +*/ +#define MB_ICON_NONE 0x00000000L // 0 - no icon +#define MB_ICON_ERROR 0x00000010L // 16 - error icon +#define MB_ICON_QUESTION 0x00000020L // 32 - question mark +#define MB_ICON_WARNING 0x00000030L // 48 - warning +#define MB_ICON_INFO 0x00000040L // 64 - info +#define MB_ICON_OTHER 0x00000080L // 240 - use icon _MSGBOX->hiMsg +#define MB_ICON_INDEX(p) (((p)&MB_ICONMASK)>>4) + +/* +flags +*/ +#define MB_INFOBAR 0x00000100L +#define MB_NOPOPUP 0x00000200L +#define MB_CUSTOMCOLOR 0x00000300L + +typedef struct _MSGBOX +{ + UINT cbSize; // size of this structure + UINT uType; // parameters + HICON hiLogo; // right upper icon of the info bar + HICON hiMsg; // icon left next to the message text + LPTSTR ptszTitle; + LPTSTR ptszInfoText; + LPTSTR ptszMsg; + HWND hParent; // parent window for the messagebox + COLORREF colorBack; // valid if MB_CUSTOMCOLOR is set + COLORREF colorText; // valid if MB_CUSTOMCOLOR is set +} MSGBOX, *LPMSGBOX; + + +INT_PTR CALLBACK MsgBoxProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); +INT_PTR CALLBACK MsgBoxPop (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); +INT_PTR CALLBACK PopupProc (HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); + +INT_PTR MsgBoxService(WPARAM wParam, LPARAM lParam); +INT_PTR MsgBox(HWND hParent, UINT uType, LPTSTR pszTitle, LPTSTR pszInfo, LPTSTR pszFormat, ...); +INT_PTR MsgErr(HWND hParent, LPCTSTR pszFormat, ...); + +#endif /* _DLG_MSGBOX */ \ No newline at end of file diff --git a/plugins/SendScreenshotPlus/src/global.h b/plugins/SendScreenshotPlus/src/global.h new file mode 100644 index 0000000000..48586f83d3 --- /dev/null +++ b/plugins/SendScreenshotPlus/src/global.h @@ -0,0 +1,189 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* +Copyright 2000-2009 Miranda ICQ/IM project, + +This file is part of Send Screenshot Plus, a Miranda IM plugin. +Copyright (c) 2010 Ing.U.Horn + +Parts of this file based on original sorce code +(c) 2004-2006 Srgio Vieira Rolanski (portet from Borland C++) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +File name : $HeadURL: http://merlins-miranda.googlecode.com/svn/trunk/miranda/plugins/SendSSPlus/global.h $ +Revision : $Revision: 22 $ +Last change on : $Date: 2010-05-02 21:25:02 +0400 (Вс, 02 май 2010) $ +Last change by : $Author: ing.u.horn $ + +*/ + +#ifndef _GLOBAL_H_ +#define _GLOBAL_H_ + +#define WINVER 0x0700 +#define _WIN32_WINNT 0x0700 +#define _WIN32_IE 0x0601 + +#define OEMRESOURCE +#define MIRANDA_VER 0x0A00 + +// Windows includes +#include +#include + +// Standard includes +#include +//#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +// Miranda IM SDK includes +#include +#include +#include +#include // This must be included first +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// plugins SDK +#include +#include +#include +#include +#include "icons.h" //from uiex icon pack + +// Project resources +#include "m_sendss.h" +#include "mir_string.h" +#include "mir_icolib.h" +#include "ctrl_button.h" +#include "dlg_msgbox.h" +#include "resource.h" +#include "version.h" + +#ifdef ComboBox_SelectItemData + // use Workaround for MS bug ComboBox_SelectItemData; + #undef ComboBox_SelectItemData +#endif + +#define UM_CLOSING WM_USER+1 +#define UM_EVENT WM_USER+2 +#define UM_TAB1 WM_USER+11 + +// Generic Message Box for Errors +#define MSGERROR(text) MessageBox(NULL, text, _T("SendSS"), MB_OK | MB_ICONERROR) +#define MSGINFO (text) MessageBox(NULL, text, _T("SendSS"), MB_OK | MB_ICONINFORMATION) + +typedef struct _MGLOBAL { + DWORD mirandaVersion; // mirandaVersion + BOOLEAN PopUpExist : 1; // Popup or MS_POPUP_ADDPOPUP exist + BOOLEAN PopUpActionsExist : 1; // Popup++ or MS_POPUP_REGISTERACTIONS exist + BOOLEAN PluginHTTPExist : 1; // HTTPServer or MS_HTTP_ACCEPT_CONNECTIONS exist + BOOLEAN PluginFTPExist : 1; // FTPFile or MS_FTPFILE_SHAREFILE exist + +} MGLOBAL, *LPMGLOBAL; + +//--------------------------------------------------------------------------- +#define ERROR_TITLE _T("SendScreenshot - Error") + +// Miranda Database Key +#define SZ_SENDSS "SendSS" +#define MODNAME "SendSS" + +extern HINSTANCE hInst; +extern MGLOBAL myGlobals; +extern HANDLE hNetlibUser; + +#define PtrIsValid(p) (((p)!=0)&&(((HANDLE)(p))!=INVALID_HANDLE_VALUE)) + +template +std::basic_string<_Elem> replace(const std::basic_string<_Elem> & Origninal, const std::basic_string<_Elem> & What, const std::basic_string<_Elem> & With) +{ + std::basic_string<_Elem> res; + size_t l = 0; + size_t p = 0; + + for (size_t p = Origninal.find(What.c_str(), 0); p != std::basic_string<_Elem>::npos; p = Origninal.find(What.c_str(), l)) + { + if (l != p) + res.append(Origninal.c_str() + l, p - l); + res.append(With); + l = p + What.length(); + } + if (l < Origninal.length()) + res.append(Origninal.c_str() + l); + + return res; +} + +#endif + +/************************************************************* + * Uinfobuttonclass module + */ + +// button styles +#define MBS_DEFBUTTON 0x00001000L // default button +#define MBS_PUSHBUTTON 0x00002000L // toggle button +#define MBS_FLAT 0x00004000L // flat button +#define MBS_DOWNARROW 0x00008000L // has arrow on the right + +#define MBF_UNICODE 1 +#ifdef _UNICODE + #define MBF_TCHAR MBF_UNICODE +#else + #define MBF_TCHAR 0 +#endif + +// BUTTONADDTOOLTIP +// use lParam=MBF_UNICODE to set unicode tooltips +// for lParam=0 the string is interpreted as ansi + +// message to explicitly translate the buttons text, +// as it is not done by default translation routine +// wParam=lParam=NULL +#define BUTTONTRANSLATE (WM_USER+6) + +/* UserInfo/MsgBox v0.1.0.4+ +Slightly modified version of MButtonClass, to draw both text and icon in a button control +*/ +#define UINFOBUTTONCLASS _T("UInfoButtonClass") + diff --git a/plugins/SendScreenshotPlus/src/icons.h b/plugins/SendScreenshotPlus/src/icons.h new file mode 100644 index 0000000000..46871836bd --- /dev/null +++ b/plugins/SendScreenshotPlus/src/icons.h @@ -0,0 +1,112 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by uinfoex_icons.rc +// +#define IDI_FIRST_ICON 101 + +// dialog inforbar +#define IDI_DLG_DETAILS 101 +#define IDI_DLG_PHONE 102 +#define IDI_DLG_EMAIL 103 + +// dialog infobar & buttons +#define IDI_ANNIVERSARY 104 +#define IDI_EXPORT 105 +#define IDI_IMPORT 106 +#define IDI_SEARCH 107 + +// common icons of details dialog pages +#define IDI_MIRANDA 108 +#define IDI_PASSWORD 109 +#define IDI_FEMALE 110 +#define IDI_MALE 111 +#define IDI_CLOCK 112 +#define IDI_MARITAL 113 + +// commonly used buttons +#define IDI_BTN_UPDATE 114 +#define IDI_BTN_OK 115 +#define IDI_BTN_CLOSE 116 +#define IDI_BTN_APPLY 117 +#define IDI_BTN_GOTO 118 +#define IDI_BTN_PHONE 119 +#define IDI_BTN_FAX 120 +#define IDI_BTN_CELLULAR 121 +#define IDI_BTN_CUSTOMPHONE 122 +#define IDI_BTN_EMAIL 123 +#define IDI_BTN_DOWNARROW 124 +#define IDI_BTN_ADD 125 +#define IDI_BTN_EDIT 126 +#define IDI_BTN_DELETE 127 +#define IDI_BTN_EXIMPORT 128 +#define IDI_BTN_BIRTHDAY_BACKUP 129 + +// details treeview icons +#define IDI_TREE_GENERAL 130 +#define IDI_TREE_ADVANCED 131 +#define IDI_TREE_COMPANY 132 +#define IDI_TREE_CONTACT 133 +#define IDI_TREE_ABOUT 134 +#define IDI_TREE_PHOTO 135 +#define IDI_TREE_ADDRESS 136 +#define IDI_TREE_NOTES 137 +#define IDI_TREE_PROFILE 138 + +// export: choose modules +#define IDI_LST_MODULES 139 +#define IDI_LST_FOLDER 140 + +// zodiac icons +#define IDI_ZOD_AQUARIUS 141 +#define IDI_ZOD_ARIES 142 +#define IDI_ZOD_CANCER 143 +#define IDI_ZOD_CAPRICORN 144 +#define IDI_ZOD_GEMINI 145 +#define IDI_ZOD_LEO 146 +#define IDI_ZOD_LIBRA 147 +#define IDI_ZOD_PISCES 148 +#define IDI_ZOD_SAGITTARIUS 149 +#define IDI_ZOD_SCORPIO 150 +#define IDI_ZOD_TAURUS 151 +#define IDI_ZOD_VIRGO 152 + +// reminder +#define IDI_BIRTHDAY 153 +#define IDI_RMD_DTB0 154 +#define IDI_RMD_DTB1 155 +#define IDI_RMD_DTB2 156 +#define IDI_RMD_DTB3 157 +#define IDI_RMD_DTB4 158 +#define IDI_RMD_DTB5 159 +#define IDI_RMD_DTB6 160 +#define IDI_RMD_DTB7 161 +#define IDI_RMD_DTB8 162 +#define IDI_RMD_DTB9 163 +#define IDI_RMD_DTBX 164 +#define IDI_RMD_DTA0 165 +#define IDI_RMD_DTA1 166 +#define IDI_RMD_DTA2 167 +#define IDI_RMD_DTA3 168 +#define IDI_RMD_DTA4 169 +#define IDI_RMD_DTA5 170 +#define IDI_RMD_DTA6 171 +#define IDI_RMD_DTA7 172 +#define IDI_RMD_DTA8 173 +#define IDI_RMD_DTA9 174 +#define IDI_RMD_DTAX 175 + +#define IDI_LASTICON 175 + +// version text +#define IDS_ICOPACKVERSION 1001 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 1002 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1000 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/plugins/SendScreenshotPlus/src/mir_icolib.cpp b/plugins/SendScreenshotPlus/src/mir_icolib.cpp new file mode 100644 index 0000000000..33718faf98 --- /dev/null +++ b/plugins/SendScreenshotPlus/src/mir_icolib.cpp @@ -0,0 +1,382 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* + +Copyright 2000-2009 Miranda ICQ/IM project, +all portions of this codebase are copyrighted to the people +listed in contributors.txt. + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +aLONG with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +this file is taken from UserinfoEx plugin and support UserinfoEx icon pack !!!! + +*/ + +#include "global.h" + + +typedef struct _ICODESC +{ + LPSTR pszName; + LPSTR pszDesc; + LPSTR pszSection; + BOOL bfromIconPack; + WORD idResource; + BYTE size; +} ICODESC; + +HICON ghDefIcon = NULL; + +//IDI_PLUG_MAIN must be the first icon from Plugin.dll, all other icon must be IDI_PLUG_MAIN+n +static ICODESC icoDesc[] = +{ + // common + { ICO_PLUG_SSWINDOW1, "Screenshot Icon1", SECT_COMMON, 0, IDI_PLUG_MAIN, -1 }, + { ICO_PLUG_SSWINDOW2, "Screenshot Icon2", SECT_COMMON, 0, IDI_PLUG_ICON1, 0 }, + { ICO_PLUG_SSTARGET, "Target Cursor", SECT_COMMON, 0, IDI_PLUG_ICON2, 1 }, + { ICO_PLUG_SSMONITOR, "Target Desktop", SECT_COMMON, 0, IDI_PLUG_ICON3, 1 }, + { ICO_PLUG_SSDEFAULT, "Default", SECT_COMMON, 0, IDI_PLUG_DEFAULT, 0 }, + + // overlays + { ICO_PLUG_OVERLAYON, "overlay on", SECT_OVERLAY, 0, IDI_PLUG_OVERLAYON, 0 }, + { ICO_PLUG_OVERLAYOFF, "overlay off", SECT_OVERLAY, 0, IDI_PLUG_OVERLAYOFF,0 }, + + // dialogs +// { ICO_DLG_DETAILS, "Details Infobar", SECT_DLG, 1, IDI_DLG_DETAILS, 48 }, +// { ICO_DLG_PHONE, "Phone Infobar", SECT_DLG, 1, IDI_DLG_PHONE, 1 }, +// { ICO_DLG_EMAIL, "E-Mail Infobar", SECT_DLG, 1, IDI_DLG_EMAIL, 1 }, + + // button icons + { ICO_PLUG_SSHELP, "Help", SECT_BUTTONS, 0, IDI_PLUG_HELP, 0 }, + { ICO_PLUG_SSFOLDERO, "Open Folder", SECT_BUTTONS, 0, IDI_PLUG_FOLDERO, 0 }, + { ICO_PLUG_SSDESKOFF, "description off", SECT_BUTTONS, 0, IDI_PLUG_DESKOFF, 0 }, + { ICO_PLUG_SSDESKON, "description on", SECT_BUTTONS, 0, IDI_PLUG_DESKON, 0 }, + { ICO_PLUG_SSDELOFF, "delete off", SECT_BUTTONS, 0, IDI_PLUG_DELOFF, 0 }, + { ICO_PLUG_SSDELON, "delete on", SECT_BUTTONS, 0, IDI_PLUG_DELON, 0 }, + { ICO_PLUG_ARROWL, "Prev", SECT_BUTTONS, 0, IDI_PLUG_ARROWL, 0 }, + { ICO_PLUG_ARROWR, "Next", SECT_BUTTONS, 0, IDI_PLUG_ARROWR, 0 }, + + { ICO_BTN_UPDATE, "Update", SECT_BUTTONS, 1, IDI_BTN_UPDATE, 0 }, + { ICO_BTN_OK, "Ok", SECT_BUTTONS, 1, IDI_BTN_OK, 0 }, + { ICO_BTN_CANCEL, "Cancel", SECT_BUTTONS, 1, IDI_BTN_CLOSE, 0 }, + { ICO_BTN_APPLY, "Apply", SECT_BUTTONS, 1, IDI_BTN_APPLY, 0 }, +// { ICO_BTN_GOTO, "Goto", SECT_BUTTONS, 1, IDI_BTN_GOTO, 0 }, +// { ICO_BTN_EMAIL, "e-mail", SECT_BUTTONS, 1, IDI_BTN_EMAIL, 0 }, +// { ICO_BTN_DOWNARROW, "Down arrow", SECT_BUTTONS, 1, IDI_BTN_DOWNARROW, 0 }, +// { ICO_BTN_ADD, "Add", SECT_BUTTONS, 1, IDI_BTN_ADD, 0 }, + { ICO_BTN_EDIT, "Edit", SECT_BUTTONS, 1, IDI_BTN_EDIT, 0 }, +// { ICO_BTN_DELETE, "Delete", SECT_BUTTONS, 1, IDI_BTN_DELETE, 0 }, +// { ICO_BTN_SEARCH, "Search", SECT_BUTTONS, 1, IDI_SEARCH, 0 }, +// { ICO_BTN_YES, "Yes", SECT_BUTTONS, 1, IDI_BTN_YES, 0 }, +// { ICO_BTN_NO, "No", SECT_BUTTONS, 1, IDI_BTN_NO, 0 }, +// { ICO_BTN_IGNORE, "Ignore", SECT_BUTTONS, 1, IDI_BTN_IGNORE, 0 }, + +}; + +/** + * This function finds the default iconpack file and return its path. + * + * @param - none + * + * @return This function returns the relative path to an existing icon pack. + **/ +LPTSTR IcoLib_GetDefaultIconFileName() +{ + static LPTSTR path[] = { + _T("Icons\\uinfoex_icons.dll"), + _T("Plugins\\uinfoex_icons.dll"), + _T("Customize\\Icons\\uinfoex_icons.dll") + }; + TCHAR absolute[MAX_PATH]; + + for (INT i = 0; i < SIZEOF(path); i++) + { + CallService(MS_UTILS_PATHTOABSOLUTET, (WPARAM)path[i], (LPARAM)absolute); + if (PathFileExists(absolute)) + { + return path[i]; + } + } + return NULL; +} + +/** + * This function checks the version of an iconpack. + * If the icon pack's version differs from the desired one, + * dialog with a warning is displayed. + * + * @param szIconPack - This is the path to the icon pack. + * It can be absolute or relative. + * + * @return nothing + **/ +static VOID IcoLib_CheckIconPackVersion(LPTSTR szIconPack) +{ + //if (DB::Setting::GetByte(SET_ICONS_CHECKFILEVERSION, TRUE)) + if (DBGetContactSettingByte(NULL,MODNAME,SET_ICONS_CHECKFILEVERSION, TRUE)) + { + if (szIconPack) + { + TCHAR szAbsolutePath[MAX_PATH]; + HMODULE hIconDll; + + CallService(MS_UTILS_PATHTOABSOLUTET, (WPARAM)szIconPack, (LPARAM)szAbsolutePath); + + hIconDll = LoadLibrary(szAbsolutePath); + if (hIconDll) + { + CHAR szFileVersion[64]; + + if (!LoadStringA(hIconDll, IDS_ICOPACKVERSION, szFileVersion, sizeof(szFileVersion)) || + mir_strcmp(szFileVersion, "__UserInfoEx_IconPack_1.2__")) + { + MsgErr(NULL, LPGENT("Warning: Your current IconPack's version differs from the one UserInfoEx is designed for.\nSome icons may not be displayed correctly")); + } + FreeLibrary(hIconDll); + } + } + else + { + MsgErr(NULL, LPGENT("Warning: No IconPack found in one of the following directories: 'customize\\icons', 'icons' or 'plugins'!")); + } + } +} + +/** + * Returns a icon, identified by a name + * + * @param pszIcon - name of the icon + * + * @return: HICON if the icon is loaded, NULL otherwise + **/ +HICON IcoLib_GetIcon(LPCSTR pszIcon, bool big) +{ + return (pszIcon) ? (HICON)CallService(MS_SKIN2_GETICON, (WPARAM)big, (LPARAM) pszIcon) : NULL; +} + +/** + * Returns a icon, identified by a name + * + * @param hIconItem - this is the pointer to an IconItem structure in icolib. + * + * @return: HICON if the icon is loaded, NULL otherwise + **/ +HICON IcoLib_GetIconByHandle(HANDLE hIconItem, bool big) +{ + return (HICON)CallService(MS_SKIN2_GETICONBYHANDLE, (WPARAM)big, (LPARAM) hIconItem); +} + +/** + * Set the icon of each control in the list + * + * @param hDlg - handle to the dialog control, that owns the controls + * @param pCtrl - list to all controls and its icon names + * @param numCtrls - number of elements in the pCtrl list + * + * @return nothing + **/ +VOID IcoLib_SetCtrlIcons(HWND hDlg, const ICONCTRL* pCtrl, BYTE numCtrls) +{ + HICON hIcon; + BYTE i; + HWND hCtrl; + + for (i = 0; i < numCtrls; i++) + { + hIcon = IcoLib_GetIcon(pCtrl[i].pszIcon); + if (pCtrl[i].idCtrl) + { + hCtrl = GetDlgItem(hDlg, pCtrl[i].idCtrl); + switch (pCtrl[i].Message) + { + case STM_SETICON: + case STM_SETIMAGE: + { + ShowWindow(hCtrl, hIcon ? SW_SHOW : SW_HIDE); + } + case BM_SETIMAGE: + { + SendMessage(hCtrl, pCtrl[i].Message, IMAGE_ICON, (LPARAM) hIcon); + } + } + } + else + { + SendMessage(hDlg, pCtrl[i].Message, ICON_BIG, (LPARAM) hIcon); + } + } +} + +/** + * This function manually registers a single icon from the default icon library. + * + * @param szIconID - This is the uniquely identifying string for an icon. + * This string is the setting name in the database and should + * only use ASCII characters. + * @param szDescription - This is the description displayed in the options dialog. + * @param szSection - This is the subsection, where the icon is organized in the options dialog. + * @param szDefaultFile - This is the validated path to the default icon file. + * @param idIcon - This is the ResourceID of the icon in the default file. + * @param Size - This is the desired size of the icon to load. + * 0: default size for small icons (16x16) + * 1: default size for normal icons (32x32) + * @param hDefIcon - This is the default icon to use if the default icon + * file does not exist and no custom icon is set up in the config. + * + * @return This function returns the HANDLE of the icon item. + **/ +static HANDLE IcoLib_RegisterIconHandleEx(LPSTR szIconID, LPSTR szDescription, LPSTR szSection, LPTSTR szDefaultFile, INT idIcon, INT Size, HICON hDefIcon) +{ + HANDLE hIconHandle = NULL; + + if (szIconID && szDescription && szSection) + { + SKINICONDESC sid; + + ZeroMemory(&sid, sizeof(sid)); + sid.cbSize = sizeof(sid); + sid.flags = SIDF_ALL_TCHAR; + sid.pszName = szIconID; + sid.ptszDescription = mir_a2t(szDescription); + sid.ptszSection = mir_a2t(szSection); + + if (sid.ptszDescription && sid.ptszSection) + { + switch (Size) + { + // small and big icons + case -1: + { + sid.cx = sid.cy = 0; + break; + } + // small icons (16x16) + case 0: + { + sid.cx = GetSystemMetrics(SM_CXSMICON); + sid.cy = GetSystemMetrics(SM_CYSMICON); + break; + } + // normal icons (32x32) + case 1: + { + sid.cx = GetSystemMetrics(SM_CXICON); + sid.cy = GetSystemMetrics(SM_CYICON); + break; + } + // custom icon size + default: + { + sid.cx = sid.cy = Size; + break; + } + } + + sid.ptszDefaultFile = szDefaultFile; + if (sid.ptszDefaultFile && sid.ptszDefaultFile[0]) + { + if(idIcon < IDI_FIRST_ICON || idIcon > IDI_LASTICON) { + // Icon from Plugin.dll + sid.iDefaultIndex = idIcon - IDI_PLUG_MAIN; + } + else{ + //UserinfoEx Icon pack + sid.iDefaultIndex = ICONINDEX(idIcon); + } + } + else + { + sid.hDefaultIcon = hDefIcon; + sid.iDefaultIndex = -1; + } + hIconHandle = Skin_AddIcon(&sid); + } + mir_freeAndNil(sid.ptszDescription); + mir_freeAndNil(sid.ptszSection); + } + return hIconHandle; +} + +/** + * This function manually registers a single icon from the default icon library. + * + * @param szIconID - This is the uniquely identifying string for an icon. + * This string is the setting name in the database and should + * only use ASCII characters. + * @param szDescription - This is the description displayed in the options dialog. + * @param szSection - This is the subsection, where the icon is organized in the options dialog. + * @param idIcon - This is the ResourceID of the icon in the default file + * @param Size - This is the desired size of the icon to load. + * 0: default size for small icons (16x16) + * 1: default size for normal icons (32x32) + * + * @return This function returns the HANDLE of the icon item. + **/ +HANDLE IcoLib_RegisterIconHandle(LPSTR szIconID, LPSTR szDescription, LPSTR szSection, INT idIcon, INT Size) +{ + return IcoLib_RegisterIconHandleEx(szIconID, szDescription, szSection, IcoLib_GetDefaultIconFileName(), idIcon, Size, ghDefIcon); +} + +/** + * This function manually registers a single icon from the default icon library. + * + * @param szIconID - This is the uniquely identifying string for an icon. + * This string is the setting name in the database and should + * only use ASCII characters. + * @param szDescription - This is the description displayed in the options dialog. + * @param szSection - This is the subsection, where the icon is organized in the options dialog. + * @param idIcon - This is the ResourceID of the icon in the default file + * @param Size - This is the desired size of the icon to load. + * 0: default size for small icons (16x16) + * 1: default size for normal icons (32x32) + * + * @return This function returns the HICON of the icon itself. + **/ +HICON IcoLib_RegisterIcon(LPSTR szIconID, LPSTR szDescription, LPSTR szSection, INT idIcon, INT Size) +{ + return IcoLib_GetIconByHandle(IcoLib_RegisterIconHandle(szIconID, szDescription, szSection, idIcon, Size)); +} + +/** + * Add default icons to the skin library or load customized icons + * + * @param none + * + * @return nothing + **/ +VOID IcoLib_LoadModule() +{ + LPTSTR szDefaultFile; + LPTSTR szPluginFile; + INT_PTR i; + + // search for default icon file + szDefaultFile = IcoLib_GetDefaultIconFileName(); + IcoLib_CheckIconPackVersion(szDefaultFile); + + szPluginFile = _T("Plugins\\")_T(__FILENAME); + + // load default icon if required + ghDefIcon = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_PLUG_DEFAULT), IMAGE_ICON, + GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0); + + for (i = 0; i < SIZEOF(icoDesc); i++) + { + IcoLib_RegisterIconHandleEx( + icoDesc[i].pszName, icoDesc[i].pszDesc, icoDesc[i].pszSection, + icoDesc[i].bfromIconPack ? szDefaultFile : szPluginFile, icoDesc[i].idResource, icoDesc[i].size, ghDefIcon); + } +} + diff --git a/plugins/SendScreenshotPlus/src/mir_icolib.h b/plugins/SendScreenshotPlus/src/mir_icolib.h new file mode 100644 index 0000000000..b80c014a07 --- /dev/null +++ b/plugins/SendScreenshotPlus/src/mir_icolib.h @@ -0,0 +1,139 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* + +Copyright 2000-2009 Miranda ICQ/IM project, +all portions of this codebase are copyrighted to the people +listed in contributors.txt. + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +aLONG with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ +#ifndef _UINFOEX_ICONS_H_INCLUDED_ +#define _UINFOEX_ICONS_H_INCLUDED_ 1 + +#include "m_icolib.h" + +// sections +#define SECT_COMMON MODNAME +#define SECT_DLG MODNAME"/Dialogs" +#define SECT_BUTTONS MODNAME"/Buttons" +#define SECT_OVERLAY MODNAME"/overlays" +#define SECT_TOOLBAR "ToolBar" // global toolbar section as used by modern clist + +// icons +#define ICO_PLUG_SSWINDOW1 MODNAME"_plug_SSwindow1" +#define ICO_PLUG_SSWINDOW2 MODNAME"_plug_SSwindow2" +#define ICO_PLUG_SSMONITOR MODNAME"_plug_SSmonitor" +#define ICO_PLUG_SSDEFAULT MODNAME"_plug_SSdefault" +#define ICO_PLUG_SSTARGET MODNAME"_plug_SSTarget" +#define ICO_PLUG_SSHELP MODNAME"_plug_SSHelp" +#define ICO_PLUG_SSFOLDERO MODNAME"_plug_SSFolderOpen" +#define ICO_PLUG_ARROWL MODNAME"_plug_SSArrowL" +#define ICO_PLUG_ARROWR MODNAME"_plug_SSArrowR" +#define ICO_PLUG_SSDESKOFF MODNAME"_plug_SSDeskOff" +#define ICO_PLUG_SSDESKON MODNAME"_plug_SSDeskOn" +#define ICO_PLUG_SSDELOFF MODNAME"_plug_SSDelOff" +#define ICO_PLUG_SSDELON MODNAME"_plug_SSDelOn" + +#define ICO_PLUG_OVERLAYOFF MODNAME"_plug_SSOverlayOff" +#define ICO_PLUG_OVERLAYON MODNAME"_plug_SSOverlayOn" + +#define ICO_COMMON_IM MODNAME"_common_im" +#define ICO_COMMON_FEMALE MODNAME"_common_female" +#define ICO_COMMON_MALE MODNAME"_common_male" +#define ICO_COMMON_CLOCK MODNAME"_common_clock" +#define ICO_COMMON_MARITAL MODNAME"_common_marital" +#define ICO_COMMON_PASSWORD MODNAME"_common_password" +#define ICO_COMMON_ADDRESS MODNAME"_common_address" +#define ICO_TREE_DEFAULT MODNAME"_tree_default" +#define ICO_DLG_DETAILS MODNAME"_dlg_details" +#define ICO_DLG_PHONE MODNAME"_dlg_phone" +#define ICO_DLG_EMAIL MODNAME"_dlg_email" +#define ICO_DLG_EXPORT MODNAME"_dlg_export" +#define ICO_DLG_IMPORT MODNAME"_dlg_import" +#define ICO_DLG_SEARCH MODNAME"_dlg_search" +#define ICO_LST_MODULES MODNAME"_lst_modules" +#define ICO_LST_FOLDER MODNAME"_lst_folder" +#define ICO_BTN_UPDATE MODNAME"_btn_update" +#define ICO_BTN_OK MODNAME"_btn_ok" +#define ICO_BTN_CANCEL MODNAME"_btn_cancel" +#define ICO_BTN_APPLY MODNAME"_btn_apply" +#define ICO_BTN_GOTO MODNAME"_btn_goto" +#define ICO_BTN_ADD MODNAME"_btn_add" +#define ICO_BTN_EDIT MODNAME"_btn_edit" +#define ICO_BTN_DELETE MODNAME"_btn_delete" +#define ICO_BTN_IMPORT MODNAME"_btn_import" +#define ICO_BTN_EXPORT MODNAME"_btn_export" +#define ICO_BTN_NOTES MODNAME"_btn_notes" +#define ICO_BTN_ABOUT MODNAME"_btn_about" +#define ICO_BTN_PROFILE MODNAME"_btn_profile" +#define ICO_BTN_DOWNARROW MODNAME"_btn_downarrow" +#define ICO_BTN_PHONE MODNAME"_btn_phone" +#define ICO_BTN_FAX MODNAME"_btn_fax" +#define ICO_BTN_CELLULAR MODNAME"_btn_cellular" +#define ICO_BTN_EMAIL MODNAME"_btn_email" +#define ICO_BTN_SEARCH MODNAME"_btn_search" +#define ICO_BTN_YES MODNAME"_btn_yes" +#define ICO_BTN_NO MODNAME"_btn_no" +#define ICO_BTN_IGNORE MODNAME"_btn_ignore" + +#define ICO_RMD_DTB0 MODNAME"_rmd_dtb0" +#define ICO_RMD_DTB1 MODNAME"_rmd_dtb1" +#define ICO_RMD_DTB2 MODNAME"_rmd_dtb2" +#define ICO_RMD_DTB3 MODNAME"_rmd_dtb3" +#define ICO_RMD_DTB4 MODNAME"_rmd_dtb4" +#define ICO_RMD_DTB5 MODNAME"_rmd_dtb5" +#define ICO_RMD_DTB6 MODNAME"_rmd_dtb6" +#define ICO_RMD_DTB7 MODNAME"_rmd_dtb7" +#define ICO_RMD_DTB8 MODNAME"_rmd_dtb8" +#define ICO_RMD_DTB9 MODNAME"_rmd_dtb9" +#define ICO_RMD_DTBX MODNAME"_rmd_dtbx" + +#define ICO_RMD_DTA0 MODNAME"_rmd_dta0" +#define ICO_RMD_DTA1 MODNAME"_rmd_dta1" +#define ICO_RMD_DTA2 MODNAME"_rmd_dta2" +#define ICO_RMD_DTA3 MODNAME"_rmd_dta3" +#define ICO_RMD_DTA4 MODNAME"_rmd_dta4" +#define ICO_RMD_DTA5 MODNAME"_rmd_dta5" +#define ICO_RMD_DTA6 MODNAME"_rmd_dta6" +#define ICO_RMD_DTA7 MODNAME"_rmd_dta7" +#define ICO_RMD_DTA8 MODNAME"_rmd_dta8" +#define ICO_RMD_DTA9 MODNAME"_rmd_dta9" +#define ICO_RMD_DTAX MODNAME"_rmd_dtax" + +#define SET_ICONS_CHECKFILEVERSION "CheckIconPackVersion" +#define SET_ICONS_BUTTONS "ButtonIcons" + +#define ICONINDEX(id) max((min((id), IDI_LASTICON)) - IDI_FIRST_ICON, 0) + +typedef struct TIconCtrl +{ + LPCSTR pszIcon; + UINT Message; + WORD idCtrl; +} ICONCTRL, *LPICONCTRL; + +LPTSTR IcoLib_GetDefaultIconFileName(); +VOID IcoLib_SetCtrlIcons(HWND hDlg, const ICONCTRL* pCtrl, BYTE numCtrls); + +HANDLE IcoLib_RegisterIconHandle(LPSTR szName, LPSTR szDescription, LPSTR szSection, INT idIcon, INT Size); +HICON IcoLib_RegisterIcon(LPSTR szName, LPSTR szDescription, LPSTR szSection, INT idIcon, INT Size); +HICON IcoLib_GetIcon(LPCSTR pszIcon, bool big = false); +HICON IcoLib_GetIconByHandle(HANDLE hIconItem, bool big = false); + +VOID IcoLib_LoadModule(); + +#endif /* _UINFOEX_ICONS_H_INCLUDED_ */ diff --git a/plugins/SendScreenshotPlus/src/mir_string.cpp b/plugins/SendScreenshotPlus/src/mir_string.cpp new file mode 100644 index 0000000000..0ee154b7b9 --- /dev/null +++ b/plugins/SendScreenshotPlus/src/mir_string.cpp @@ -0,0 +1,179 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* + +Copyright 2000-2009 Miranda ICQ/IM project, + +This file is part of Send Screenshot Plus, a Miranda IM plugin. +Copyright (c) 2010 Ing.U.Horn + +Parts of this file based on original sorce code +from UserInfoEx Plugin + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +File name : $HeadURL: http://merlins-miranda.googlecode.com/svn/trunk/miranda/plugins/SendSSPlus/mir_string.cpp $ +Revision : $Revision: 13 $ +Last change on : $Date: 2010-04-02 02:54:30 +0400 (Пт, 02 апр 2010) $ +Last change by : $Author: ing.u.horn $ + +*/ + +#include "global.h" +#include "mir_string.h" + +char *mir_strncpy(char *pszDest, const char *pszSrc, const size_t cchDest) +{ + if (!pszDest || !pszSrc || !cchDest) + return NULL; + pszDest = strncpy(pszDest, pszSrc, cchDest-1); + pszDest[cchDest-1] = 0; + return pszDest; +} + +wchar_t *mir_wcsncpy(wchar_t *pszDest, const wchar_t *pszSrc, const size_t cchDest) +{ + if (!pszDest || !pszSrc || !cchDest) + return NULL; + pszDest = wcsncpy(pszDest, pszSrc, cchDest-1); + pszDest[cchDest-1] = 0; + return pszDest; +} + +char *mir_strncat(char *pszDest, const char *pszSrc, const size_t cchDest) +{ + if (!pszDest || !pszSrc || !cchDest) + return NULL; + strncat(pszDest, pszSrc, cchDest-1); + pszDest[cchDest-1] = 0; + return pszDest; +} + +wchar_t *mir_wcsncat(wchar_t *pszDest, const wchar_t *pszSrc, const size_t cchDest) +{ + if (!pszDest || !pszSrc || !cchDest) + return NULL; + pszDest = wcsncat(pszDest, pszSrc, cchDest-1); + pszDest[cchDest-1] = 0; + return pszDest; +} + +char *mir_strncat_c(char *pszDest, const char cSrc) { + size_t lenNew = strlen(pszDest) + 2; + if (!pszDest) + pszDest = (char *) mir_alloc(sizeof(char) * lenNew); + else + pszDest = (char *) mir_realloc(pszDest, sizeof(char) * lenNew); + pszDest[lenNew-2] = cSrc; + pszDest[lenNew-1] = 0; + return pszDest; +} + +wchar_t *mir_wcsncat_c(wchar_t *pwszDest, const wchar_t wcSrc) { + size_t lenNew = wcslen(pwszDest) + 2; + if (!pwszDest) + pwszDest = (wchar_t *) mir_alloc(sizeof(wchar_t) * lenNew); + else + pwszDest = (wchar_t *) mir_realloc(pwszDest, sizeof(wchar_t) * lenNew); + pwszDest[lenNew-2] = wcSrc; + pwszDest[lenNew-1] = 0; + return pwszDest; +} + +char *mir_strnerase(char *pszDest, size_t sizeFrom, size_t sizeTo) { + char *pszReturn = NULL; + size_t sizeNew, sizeLen = strlen(pszDest); + if (sizeFrom >= 0 && sizeFrom < sizeLen && sizeTo >= 0 && sizeTo <= sizeLen && sizeFrom < sizeTo) { + sizeNew = sizeLen - (sizeTo - sizeFrom); + size_t sizeCopy = sizeNew - sizeFrom; + pszReturn = (char *) mir_alloc(sizeNew + 1); + memcpy(pszReturn, pszDest, sizeFrom); + memcpy(pszReturn + sizeFrom, pszDest + sizeTo, sizeCopy); + pszReturn[sizeNew] = 0; + } + + pszDest = (char *) mir_realloc(pszDest, sizeNew + 1); + pszDest = mir_strcpy(pszDest, pszReturn); + mir_free(pszReturn); + return pszDest; +} + +size_t mir_vsnwprintf(wchar_t *pszDest, const size_t cchDest, const wchar_t *pszFormat, va_list& argList) +{ + size_t iRet, cchMax; + + if (!pszDest || !pszFormat || !*pszFormat) + return -1; + + cchMax = cchDest - 1; + iRet = _vsnwprintf(pszDest, cchMax, pszFormat, argList); + if (iRet < 0) pszDest[0] = 0; + else if (iRet >= cchMax) { + pszDest[cchMax] = 0; + iRet = cchMax; + } + return iRet; +} + +size_t mir_snwprintf(wchar_t *pszDest, const size_t cchDest, const wchar_t *pszFormat, ...) +{ + size_t iRet; + va_list argList; + + va_start(argList, pszFormat); + iRet = mir_vsnwprintf(pszDest, cchDest, pszFormat, argList); + va_end(argList); + return iRet; +} + +//--------------------------------------------------------------------------- +void mir_stradd(char* &pszDest, const char *pszSrc) +{ + if(!pszSrc) { + return; + } + else if(!pszDest) { + pszDest = mir_strdup(pszSrc); + } + else { + size_t lenDest = strlen(pszDest); + size_t lenSrc = strlen(pszSrc); + size_t lenNew = lenDest + lenSrc + 1; + pszDest = (char *) mir_realloc(pszDest, sizeof(char)* lenNew); + + strcpy(pszDest + lenDest, pszSrc); + pszDest[lenNew-1] = 0; + } +} + +void mir_wcsadd(wchar_t* &pszDest, const wchar_t *pszSrc) +{ + if(!pszSrc) { + return; + } + else if(!pszDest) { + pszDest = mir_wstrdup(pszSrc); + } + else { + size_t lenDest = wcslen(pszDest); + size_t lenSrc = wcslen(pszSrc); + size_t lenNew = lenDest + lenSrc + 1; + pszDest = (wchar_t *) mir_realloc(pszDest, sizeof(wchar_t)*lenNew); + + wcscpy(pszDest + lenDest, pszSrc); + pszDest[lenNew-1] = 0; + } +} + diff --git a/plugins/SendScreenshotPlus/src/mir_string.h b/plugins/SendScreenshotPlus/src/mir_string.h new file mode 100644 index 0000000000..882cd38896 --- /dev/null +++ b/plugins/SendScreenshotPlus/src/mir_string.h @@ -0,0 +1,107 @@ +/* + +Miranda IM: the free IM client for Microsoft* Windows* +Copyright 2000-2009 Miranda ICQ/IM project, + +This file is part of Send Screenshot Plus, a Miranda IM plugin. +Copyright (c) 2010 Ing.U.Horn + +Parts of this file based on original sorce code +from UserInfoEx Plugin + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +File name : $HeadURL: http://merlins-miranda.googlecode.com/svn/trunk/miranda/plugins/SendSSPlus/mir_string.h $ +Revision : $Revision: 13 $ +Last change on : $Date: 2010-04-02 02:54:30 +0400 (Пт, 02 апр 2010) $ +Last change by : $Author: ing.u.horn $ + +*/ + +#ifndef _MIR_STRING_H_INCLUDED_ +#define _MIR_STRING_H_INCLUDED_ + +#define mir_wcsdup mir_wstrdup + +#ifdef _UNICODE + #define mir_tcslen mir_wcslen + #define mir_tcscpy mir_wcscpy + #define mir_tcsncpy mir_wcsncpy + #define mir_tcsncat mir_wcsncat + #define mir_tcsdup mir_wcsdup + #define mir_tcscmp mir_wcscmp + #define mir_tcsncmp mir_wcsncmp + #define mir_tcsicmp mir_wcsicmp + #define mir_tcsnicmp mir_wcsnicmp + #define mir_tcschr mir_wcschr + #define mir_tcsrchr mir_wcsrchr + #define mir_tcsncat_c mir_wcsncat_c + #define mir_tcsadd mir_wcsadd +#else + #define mir_tcslen mir_strlen + #define mir_tcscpy mir_strcpy + #define mir_tcsncpy mir_strncpy + #define mir_tcsncat mir_strncat + #define mir_tcsdup mir_strdup + #define mir_tcscmp mir_strcmp + #define mir_tcsncmp mir_strncmp + #define mir_tcsicmp mir_stricmp + #define mir_tcsnicmp mir_strnicmp + #define mir_tcschr mir_strchr + #define mir_tcsrchr mir_strrchr + #define mir_tcsncat_c mir_strncat_c + #define mir_tcsadd mir_stradd +#endif + + +#define mir_strlen(s) (((s)!=0)?strlen(s):0) +#define mir_strcpy(d,s) (((s)!=0&&(d)!=0)?strcpy(d,s):0) +#define mir_strcmp(s1,s2) ((s1)==0||(s2)==0||strcmp((s1),(s2))) +#define mir_strncmp(s1,s2,n) ((s1)==0||(s2)==0||strncmp((s1),(s2),(n))) +#define mir_stricmp(s1,s2) ((s1)==0||(s2)==0||_stricmp((s1),(s2))) +#define mir_strnicmp(s1,s2,n) ((s1)==0||(s2)==0||_strnicmp((s1),(s2),(n))) +#define mir_strchr(s,c) (((s)!=0)?strchr((s),(c)):0) +#define mir_strrchr(s,c) (((s)!=0)?strrchr((s),(c)):0) + +#define mir_wcslen(s) (((s)!=0)?wcslen(s):0) +#define mir_wcscpy(d,s) (((s)!=0&&(d)!=0)?wcscpy(d,s):0) +#define mir_wcscmp(s1,s2) ((s1)==0||(s2)==0||wcscmp((s1),(s2))) +#define mir_wcsncmp(s1,s2,n) ((s1)==0||(s2)==0||wcsncmp((s1),(s2),(n))) +#define mir_wcsicmp(s1,s2) ((s1)==0||(s2)==0||_wcsicmp((s1),(s2))) +#define mir_wcsnicmp(s1,s2,n) ((s1)==0||(s2)==0||_wcsnicmp((s1),(s2),(n))) +#define mir_wcschr(s,c) (((s)!=0)?wcschr((s),(c)):0) +#define mir_wcsrchr(s,c) (((s)!=0)?wcsrchr((s),(c)):0) + +//#define mir_free(ptr) (if (x) mmi.free(x); *(&(x)) = 0;} +#define mir_freeAndNil(ptr) {if(ptr) mir_free(ptr); ptr = NULL;} + +char * mir_strncpy(char *pszDest, const char *pszSrc, const size_t cchDest); +wchar_t * mir_wcsncpy(wchar_t *pszDest, const wchar_t *pszSrc, const size_t cchDest); + +char * mir_strncat(char *pszDest, const char *pszSrc, const size_t cchDest); +wchar_t * mir_wcsncat(wchar_t *pszDest, const wchar_t *pszSrc, const size_t cchDest); + +char * mir_strncat_c(char *pszDest, const char cSrc); +char * mir_wcsncat_c(char *pszDest, const char cSrc); + +size_t mir_vsnwprintf(wchar_t *pszDest, const size_t cchDest, const wchar_t *pszFormat, va_list& argList); +size_t mir_snwprintf(wchar_t *pszDest, const size_t cchDest, const wchar_t *pszFormat, ...); + +char * mir_strnerase(char *pszDest, size_t sizeFrom, size_t sizeTo); + +void mir_stradd(char * &pszDest, const char *pszSrc); +void mir_wcsadd(wchar_t * &pszDest, const wchar_t *pszSrc); + +#endif /* _MIR_STRING_H_INCLUDED_ */ \ No newline at end of file diff --git a/plugins/SendScreenshotPlus/src/resource.h b/plugins/SendScreenshotPlus/src/resource.h new file mode 100644 index 0000000000..6818f5b23f --- /dev/null +++ b/plugins/SendScreenshotPlus/src/resource.h @@ -0,0 +1,102 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by resource.rc +// +#define IDOK 1 +#define IDA_btnClose 1 +#define IDCANCEL 2 +#define IDB_Bmp1 2 +#define IDABORT 3 +#define IDB_Bmp2 3 +#define IDRETRY 4 +#define IDIGNORE 5 +#define IDYES 6 +#define IDNO 7 +#define IDCLOSE 8 +#define IDHELP 9 +#define IDTRYAGAIN 10 +#define IDCONTINUE 11 +#define IDALL 21 +#define IDD_UMainForm 101 +#define MAIN 102 +#define IDR_LICENSE 103 +#define IDD_UMain_CaptureWindow 107 +#define IDD_CAPTURE 111 +#define IDR_CREDIT 116 +#define IDI_PLUG_MAIN 190 +#define IDI_PLUG_DEFAULT 191 +#define IDI_PLUG_ICON1 192 +#define IDI_PLUG_ICON2 193 +#define IDI_PLUG_ICON3 194 +#define IDI_PLUG_HELP 195 +#define IDI_PLUG_FOLDERO 196 +#define IDI_PLUG_ARROWL 197 +#define IDI_PLUG_ARROWR 198 +#define IDI_PLUG_OVERLAYON 199 +#define IDI_PLUG_OVERLAYOFF 200 +#define IDD_UAboutForm 201 +#define IDI_PLUG_DESKOFF 201 +#define IDI_PLUG_DESKON 202 +#define IDI_PLUG_DELOFF 203 +#define IDI_PLUG_DELON 204 +#define IDD_UEditForm 301 +#define IDC_CAPTURETAB 1005 +#define IDD_MSGBOX 1008 +#define IDC_CREDIT 1009 +#define IDD_MSGBOXDUMMI 1024 +#define IDD_UMain_CaptureDesktop 1025 +#define STATIC_WHITERECT 1100 +#define STATIC_LINE2 1103 +#define ICO_DLGLOGO 1105 +#define ICO_MSGDLG 1106 +#define IDC_BUILDTIME 1108 +#define TXT_NAME 1114 +#define TXT_MESSAGE 1126 +#define ID_edtCaption 1201 +#define ID_edtSize 1202 +#define ID_edtQuality 1203 +#define ID_upQuality 1204 +#define ID_edtTimed 1205 +#define ID_upTimed 1206 +#define IDC_WHITERECT 1221 +#define ID_cboxFormat 1301 +#define ID_cboxSendBy 1302 +#define ID_lblFmtInfo 1501 +#define IDE_Image 1501 +#define ID_lblSendBy 1502 +#define IDE_imgSelection 1502 +#define ID_bvlTarget 1503 +#define IDC_COPYRIGHT 1503 +#define ID_lblDropInfo 1504 +#define ID_imgTarget 1505 +#define ID_edtCaptionLabel 1506 +#define ID_edtSizeLabel 1507 +#define ID_edtQualityLabel 1508 +#define ID_edtTimedLabel 1509 +#define IDNONE 1565 +#define IDA_CONTRIBLINK 1586 +#define IDC_LICENSE 1589 +#define ID_gboxAreaToTake 1602 +#define ID_gboxOptions 1603 +#define ID_chkEditor 1701 +#define ID_chkClientArea 1704 +#define ID_chkTimed 1708 +#define ID_chkOpenAgain 1710 +#define IDC_HEADERBAR 1734 +#define ID_btnAbout 2001 +#define ID_btnExplore 2002 +#define ID_btnDesc 2003 +#define ID_btnDeleteAfterSend 2004 +#define ID_btnCapture 2005 +#define IDE_StatusBar 2501 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 123 +#define _APS_NEXT_COMMAND_VALUE 40002 +#define _APS_NEXT_CONTROL_VALUE 1011 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/plugins/SendScreenshotPlus/src/version.h b/plugins/SendScreenshotPlus/src/version.h new file mode 100644 index 0000000000..a97e7aff37 --- /dev/null +++ b/plugins/SendScreenshotPlus/src/version.h @@ -0,0 +1,45 @@ +#define PLUGNAME "Send Screenshot+" +#define __MAJOR_VERSION 0 +#define __MINOR_VERSION 8 +#define __RELEASE_NUM 0 +#define __BUILD_NUM 0 + +#define __STRINGIFY(x) #x +#define __STRINGIFY2(x) __STRINGIFY(x) +#define __FILEVERSION_STRING __MAJOR_VERSION,__MINOR_VERSION,__RELEASE_NUM,__BUILD_NUM +#define __FILEVERSION_STRING_DOTS __MAJOR_VERSION.__MINOR_VERSION.__RELEASE_NUM.__BUILD_NUM + +#define __VERSION_STRING __STRINGIFY2(__FILEVERSION_STRING) +#define __VERSION_STRING_DOT __STRINGIFY2(__FILEVERSION_STRING_DOTS) + +#define __FILENAME "SendSS.dll" +#define __DESC "Take a screenshot and send it to a contact." +#define __AUTHOR "Merlin" +#define __AUTHOREMAIL "ing.u.horn@googlemail.com" +#define __COPYRIGHT " 2010 Merlin, 2004-2006 Sergio Vieira Rolanski" +#define __AUTHORWEB "http://code.google.com/p/merlins-miranda" + +#ifndef MIID_PLUGIN // {ED39AF7C-BECD-404e-9499-4D04F711B9CB} +#define MIID_PLUGIN { 0xed39af7c, 0xbecd, 0x404e, { 0x94, 0x99, 0x4d, 0x04, 0xf7, 0x11, 0xb9, 0xcb } } +#endif + +#ifdef _UNICODE +#define __PLUGIN_NAME "Send Screenshot+ (Unicode)" +#define __FLVersionURL "http://nightly.miranda.im/" +#define __FLVersionPrefix "SendSS (Unicode) " +#define __FLUpdateURL "http://nightly.miranda.im/x32/sendss.zip" +#define __BetaUpdateURL "http://nightly.miranda.im/x32/sendss.zip" +#else +#define __PLUGIN_NAME "Send Screenshot+ (2in1)" +#define __FLVersionURL "http://nightly.miranda.im/" +#define __FLVersionPrefix "SendSS (2in1) " +#define __FLUpdateURL "http://nightly.miranda.im/x32/sendss.zip" +#define __BetaUpdateURL "http://nightly.miranda.im/x32/sendss.zip" +#endif + +#define __BetaVersionURL "http://merlins-miranda.googlecode.com/svn/trunk/miranda/plugins/SendSS/changelog.txt" +#define __BetaVersionPrefix "SendSS Plus: " +#define __BetaChangelogURL "http://merlins-miranda.googlecode.com/svn/trunk/miranda/plugins/SendSS/changelog.txt" + +#define __USER_AGENT_STRING __PLUGIN_NAME##" v"##__VERSION_STRING_DOT + -- cgit v1.2.3