|
| 1 | +//this file is part of notepad++ |
| 2 | +//Copyright (C)2003 Don HO ( [email protected] ) |
| 3 | +// |
| 4 | +//This program is free software; you can redistribute it and/or |
| 5 | +//modify it under the terms of the GNU General Public License |
| 6 | +//as published by the Free Software Foundation; either |
| 7 | +//version 2 of the License, or (at your option) any later version. |
| 8 | +// |
| 9 | +//This program is distributed in the hope that it will be useful, |
| 10 | +//but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +//GNU General Public License for more details. |
| 13 | +// |
| 14 | +//You should have received a copy of the GNU General Public License |
| 15 | +//along with this program; if not, write to the Free Software |
| 16 | +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 17 | + |
| 18 | +#ifndef M30_IDE_COMMUN_H |
| 19 | +#define M30_IDE_COMMUN_H |
| 20 | + |
| 21 | +#include <windows.h> |
| 22 | +#include <string> |
| 23 | +#include <vector> |
| 24 | +#include <time.h> |
| 25 | +#include <Shlobj.h> |
| 26 | + |
| 27 | +#ifdef UNICODE |
| 28 | +#include <wchar.h> |
| 29 | +#endif |
| 30 | + |
| 31 | +#define CP_ANSI_LATIN_1 1252 |
| 32 | +#define CP_BIG5 950 |
| 33 | + |
| 34 | +#ifdef UNICODE |
| 35 | + #define NppMainEntry wWinMain |
| 36 | + #define generic_strtol wcstol |
| 37 | + #define generic_strncpy wcsncpy |
| 38 | + #define generic_stricmp wcsicmp |
| 39 | + #define generic_strncmp wcsncmp |
| 40 | + #define generic_strnicmp wcsnicmp |
| 41 | + #define generic_strncat wcsncat |
| 42 | + #define generic_strchr wcschr |
| 43 | + #define generic_atoi _wtoi |
| 44 | + #define generic_itoa _itow |
| 45 | + #define generic_atof _wtof |
| 46 | + #define generic_strtok wcstok |
| 47 | + #define generic_strftime wcsftime |
| 48 | + #define generic_fprintf fwprintf |
| 49 | + #define generic_sscanf swscanf |
| 50 | + #define generic_fopen _wfopen |
| 51 | + #define generic_fgets fgetws |
| 52 | + #define generic_stat _wstat |
| 53 | + #define generic_string wstring |
| 54 | + #define COPYDATA_FILENAMES COPYDATA_FILENAMESW |
| 55 | +#else |
| 56 | + #define NppMainEntry WinMain |
| 57 | + #define generic_strtol strtol |
| 58 | + #define generic_strncpy strncpy |
| 59 | + #define generic_stricmp stricmp |
| 60 | + #define generic_strncmp strncmp |
| 61 | + #define generic_strnicmp strnicmp |
| 62 | + #define generic_strncat strncat |
| 63 | + #define generic_strchr strchr |
| 64 | + #define generic_atoi atoi |
| 65 | + #define generic_itoa itoa |
| 66 | + #define generic_atof atof |
| 67 | + #define generic_strtok strtok |
| 68 | + #define generic_strftime strftime |
| 69 | + #define generic_fprintf fprintf |
| 70 | + #define generic_sscanf sscanf |
| 71 | + #define generic_fopen fopen |
| 72 | + #define generic_fgets fgets |
| 73 | + #define generic_stat _stat |
| 74 | + #define generic_string string |
| 75 | + #define COPYDATA_FILENAMES COPYDATA_FILENAMESA |
| 76 | +#endif |
| 77 | + |
| 78 | +void folderBrowser(HWND parent, int outputCtrlID, const TCHAR *defaultStr = NULL); |
| 79 | + |
| 80 | +// Set a call back with the handle after init to set the path. |
| 81 | +// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/callbackfunctions/browsecallbackproc.asp |
| 82 | +static int __stdcall BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM, LPARAM pData) |
| 83 | +{ |
| 84 | + if (uMsg == BFFM_INITIALIZED) |
| 85 | + ::SendMessage(hwnd, BFFM_SETSELECTION, TRUE, pData); |
| 86 | + return 0; |
| 87 | +}; |
| 88 | + |
| 89 | +void systemMessage(const TCHAR *title); |
| 90 | +//DWORD ShortToLongPathName(LPCTSTR lpszShortPath, LPTSTR lpszLongPath, DWORD cchBuffer); |
| 91 | +void printInt(int int2print); |
| 92 | +void printStr(const TCHAR *str2print); |
| 93 | + |
| 94 | +void writeLog(const TCHAR *logFileName, const char *log2write); |
| 95 | +int filter(unsigned int code, struct _EXCEPTION_POINTERS *ep); |
| 96 | +int getCpFromStringValue(const char * encodingStr); |
| 97 | +std::generic_string purgeMenuItemString(const TCHAR * menuItemStr, bool keepAmpersand = false); |
| 98 | +std::vector<std::generic_string> tokenizeString(const std::generic_string & tokenString, const char delim); |
| 99 | + |
| 100 | +void ClientRectToScreenRect(HWND hWnd, RECT* rect); |
| 101 | +void ScreenRectToClientRect(HWND hWnd, RECT* rect); |
| 102 | + |
| 103 | +std::wstring string2wstring(const std::string & rString, UINT codepage); |
| 104 | +std::string wstring2string(const std::wstring & rwString, UINT codepage); |
| 105 | + |
| 106 | +TCHAR *BuildMenuFileName(TCHAR *buffer, int len, int pos, const TCHAR *filename); |
| 107 | + |
| 108 | +class WcharMbcsConvertor { |
| 109 | +public: |
| 110 | + static WcharMbcsConvertor * getInstance() {return _pSelf;}; |
| 111 | + static void destroyInstance() {delete _pSelf;}; |
| 112 | + |
| 113 | + const wchar_t * char2wchar(const char* mbStr, UINT codepage); |
| 114 | + const wchar_t * char2wchar(const char * mbcs2Convert, UINT codepage, int *mstart, int *mend); |
| 115 | + const char * wchar2char(const wchar_t* wcStr, UINT codepage); |
| 116 | + const char * wchar2char(const wchar_t * wcStr, UINT codepage, long *mstart, long *mend); |
| 117 | + |
| 118 | +protected: |
| 119 | + WcharMbcsConvertor() : _multiByteStr(NULL), _wideCharStr(NULL), _multiByteAllocLen(0), _wideCharAllocLen(0), initSize(1024) { |
| 120 | + }; |
| 121 | + ~WcharMbcsConvertor() { |
| 122 | + if (_multiByteStr) |
| 123 | + delete [] _multiByteStr; |
| 124 | + if (_wideCharStr) |
| 125 | + delete [] _wideCharStr; |
| 126 | + }; |
| 127 | + static WcharMbcsConvertor * _pSelf; |
| 128 | + |
| 129 | + const int initSize; |
| 130 | + char *_multiByteStr; |
| 131 | + size_t _multiByteAllocLen; |
| 132 | + wchar_t *_wideCharStr; |
| 133 | + size_t _wideCharAllocLen; |
| 134 | + |
| 135 | +}; |
| 136 | + |
| 137 | + |
| 138 | +#endif //M30_IDE_COMMUN_H |
0 commit comments