|
1 | | -//this file is part of notepad++ |
2 | | -//Copyright (C)2003 Don HO ( [email protected] ) |
| 1 | +// This file is part of Notepad++ project |
| 2 | +// Copyright (C)2003 Don HO <[email protected]> |
3 | 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. |
| 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 | 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. |
| 9 | +// Note that the GPL places important restrictions on "derived works", yet |
| 10 | +// it does not provide a detailed definition of that term. To avoid |
| 11 | +// misunderstandings, we consider an application to constitute a |
| 12 | +// "derivative work" for the purpose of this license if it does any of the |
| 13 | +// following: |
| 14 | +// 1. Integrates source code from Notepad++. |
| 15 | +// 2. Integrates/includes/aggregates Notepad++ into a proprietary executable |
| 16 | +// installer, such as those produced by InstallShield. |
| 17 | +// 3. Links to a library or executes a program that does any of the above. |
13 | 18 | // |
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> |
| 19 | +// This program is distributed in the hope that it will be useful, |
| 20 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | +// GNU General Public License for more details. |
| 23 | +// |
| 24 | +// You should have received a copy of the GNU General Public License |
| 25 | +// along with this program; if not, write to the Free Software |
| 26 | +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 27 | +#pragma once |
23 | 28 | #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 | | -}; |
| 29 | +#include <string> |
| 30 | +#include <sstream> |
| 31 | +#include <windows.h> |
| 32 | +#include <iso646.h> |
| 33 | +#include <cstdint> |
| 34 | + |
| 35 | + |
| 36 | +const bool dirUp = true; |
| 37 | +const bool dirDown = false; |
| 38 | + |
| 39 | +#define NPP_CP_WIN_1252 1252 |
| 40 | +#define NPP_CP_DOS_437 437 |
| 41 | +#define NPP_CP_BIG5 950 |
| 42 | + |
| 43 | +#define LINKTRIGGERED WM_USER+555 |
| 44 | + |
| 45 | +#define BCKGRD_COLOR (RGB(255,102,102)) |
| 46 | +#define TXT_COLOR (RGB(255,255,255)) |
| 47 | + |
| 48 | +#define generic_strtol wcstol |
| 49 | +#define generic_strncpy wcsncpy |
| 50 | +#define generic_stricmp wcsicmp |
| 51 | +#define generic_strncmp wcsncmp |
| 52 | +#define generic_strnicmp wcsnicmp |
| 53 | +#define generic_strncat wcsncat |
| 54 | +#define generic_strchr wcschr |
| 55 | +#define generic_atoi _wtoi |
| 56 | +#define generic_itoa _itow |
| 57 | +#define generic_atof _wtof |
| 58 | +#define generic_strtok wcstok |
| 59 | +#define generic_strftime wcsftime |
| 60 | +#define generic_fprintf fwprintf |
| 61 | +#define generic_sprintf swprintf |
| 62 | +#define generic_sscanf swscanf |
| 63 | +#define generic_fopen _wfopen |
| 64 | +#define generic_fgets fgetws |
| 65 | +#define generic_stat _wstat |
| 66 | +#define COPYDATA_FILENAMES COPYDATA_FILENAMESW |
| 67 | + |
| 68 | +typedef std::basic_string<TCHAR> generic_string; |
| 69 | +typedef std::basic_stringstream<TCHAR> generic_stringstream; |
| 70 | + |
| 71 | +generic_string folderBrowser(HWND parent, const generic_string & title = TEXT(""), int outputCtrlID = 0, const TCHAR *defaultStr = NULL); |
| 72 | +generic_string getFolderName(HWND parent, const TCHAR *defaultDir = NULL); |
88 | 73 |
|
89 | | -void systemMessage(const TCHAR *title); |
90 | | -//DWORD ShortToLongPathName(LPCTSTR lpszShortPath, LPTSTR lpszLongPath, DWORD cchBuffer); |
91 | 74 | void printInt(int int2print); |
92 | 75 | void printStr(const TCHAR *str2print); |
| 76 | +generic_string commafyInt(size_t n); |
93 | 77 |
|
94 | 78 | void writeLog(const TCHAR *logFileName, const char *log2write); |
95 | 79 | 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); |
| 80 | +generic_string purgeMenuItemString(const TCHAR * menuItemStr, bool keepAmpersand = false); |
| 81 | +std::vector<generic_string> tokenizeString(const generic_string & tokenString, const char delim); |
99 | 82 |
|
100 | 83 | void ClientRectToScreenRect(HWND hWnd, RECT* rect); |
101 | 84 | void ScreenRectToClientRect(HWND hWnd, RECT* rect); |
102 | 85 |
|
103 | 86 | std::wstring string2wstring(const std::string & rString, UINT codepage); |
104 | 87 | std::string wstring2string(const std::wstring & rwString, UINT codepage); |
| 88 | +bool isInList(const TCHAR *token, const TCHAR *list); |
| 89 | +generic_string BuildMenuFileName(int filenameLen, unsigned int pos, const generic_string &filename); |
105 | 90 |
|
106 | | -TCHAR *BuildMenuFileName(TCHAR *buffer, int len, int pos, const TCHAR *filename); |
| 91 | +std::string getFileContent(const TCHAR *file2read); |
| 92 | +generic_string relativeFilePathToFullFilePath(const TCHAR *relativeFilePath); |
| 93 | +void writeFileContent(const TCHAR *file2write, const char *content2write); |
| 94 | +bool matchInList(const TCHAR *fileName, const std::vector<generic_string> & patterns); |
107 | 95 |
|
108 | | -class WcharMbcsConvertor { |
| 96 | +class WcharMbcsConvertor final |
| 97 | +{ |
109 | 98 | public: |
110 | | - static WcharMbcsConvertor * getInstance() {return _pSelf;}; |
111 | | - static void destroyInstance() {delete _pSelf;}; |
| 99 | + static WcharMbcsConvertor * getInstance() {return _pSelf;} |
| 100 | + static void destroyInstance() {delete _pSelf;} |
| 101 | + |
| 102 | + const wchar_t * char2wchar(const char *mbStr, UINT codepage, int lenIn=-1, int *pLenOut=NULL, int *pBytesNotProcessed=NULL); |
| 103 | + const wchar_t * char2wchar(const char *mbcs2Convert, UINT codepage, int *mstart, int *mend); |
| 104 | + const char * wchar2char(const wchar_t *wcStr, UINT codepage, int lenIn = -1, int *pLenOut = NULL); |
| 105 | + const char * wchar2char(const wchar_t *wcStr, UINT codepage, long *mstart, long *mend); |
112 | 106 |
|
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); |
| 107 | + const char * encode(UINT fromCodepage, UINT toCodepage, const char *txt2Encode, int lenIn=-1, int *pLenOut=NULL, int *pBytesNotProcessed=NULL) |
| 108 | + { |
| 109 | + int lenWc = 0; |
| 110 | + const wchar_t * strW = char2wchar(txt2Encode, fromCodepage, lenIn, &lenWc, pBytesNotProcessed); |
| 111 | + return wchar2char(strW, toCodepage, lenWc, pLenOut); |
| 112 | + } |
117 | 113 |
|
118 | 114 | protected: |
119 | | - WcharMbcsConvertor() : _multiByteStr(NULL), _wideCharStr(NULL), _multiByteAllocLen(0), _wideCharAllocLen(0), initSize(1024) { |
| 115 | + WcharMbcsConvertor() {} |
| 116 | + ~WcharMbcsConvertor() {} |
| 117 | + |
| 118 | + // Since there's no public ctor, we need to void the default assignment operator and copy ctor. |
| 119 | + // Since these are marked as deleted does not matter under which access specifier are kept |
| 120 | + WcharMbcsConvertor(const WcharMbcsConvertor&) = delete; |
| 121 | + WcharMbcsConvertor& operator= (const WcharMbcsConvertor&) = delete; |
| 122 | + |
| 123 | + static WcharMbcsConvertor* _pSelf; |
| 124 | + |
| 125 | + template <class T> |
| 126 | + class StringBuffer final |
| 127 | + { |
| 128 | + public: |
| 129 | + ~StringBuffer() { if(_allocLen) delete[] _str; } |
| 130 | + |
| 131 | + void sizeTo(size_t size) |
| 132 | + { |
| 133 | + if (_allocLen < size) |
| 134 | + { |
| 135 | + if (_allocLen) |
| 136 | + delete[] _str; |
| 137 | + _allocLen = max(size, initSize); |
| 138 | + _str = new T[_allocLen]; |
| 139 | + } |
| 140 | + } |
| 141 | + |
| 142 | + void empty() |
| 143 | + { |
| 144 | + static T nullStr = 0; // routines may return an empty string, with null terminator, without allocating memory; a pointer to this null character will be returned in that case |
| 145 | + if (_allocLen == 0) |
| 146 | + _str = &nullStr; |
| 147 | + else |
| 148 | + _str[0] = 0; |
| 149 | + } |
| 150 | + |
| 151 | + operator T* () { return _str; } |
| 152 | + operator const T* () const { return _str; } |
| 153 | + |
| 154 | + protected: |
| 155 | + static const int initSize = 1024; |
| 156 | + size_t _allocLen = 0; |
| 157 | + T* _str = nullptr; |
120 | 158 | }; |
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 | | - |
| 159 | + |
| 160 | + StringBuffer<char> _multiByteStr; |
| 161 | + StringBuffer<wchar_t> _wideCharStr; |
135 | 162 | }; |
136 | 163 |
|
137 | 164 |
|
138 | | -#endif //M30_IDE_COMMUN_H |
| 165 | + |
| 166 | +#define MACRO_RECORDING_IN_PROGRESS 1 |
| 167 | +#define MACRO_RECORDING_HAS_STOPPED 2 |
| 168 | + |
| 169 | +#define REBARBAND_SIZE sizeof(REBARBANDINFO) |
| 170 | + |
| 171 | +generic_string PathRemoveFileSpec(generic_string & path); |
| 172 | +generic_string PathAppend(generic_string &strDest, const generic_string & str2append); |
| 173 | +COLORREF getCtrlBgColor(HWND hWnd); |
| 174 | +generic_string stringToUpper(generic_string strToConvert); |
| 175 | +generic_string stringToLower(generic_string strToConvert); |
| 176 | +generic_string stringReplace(generic_string subject, const generic_string& search, const generic_string& replace); |
| 177 | +std::vector<generic_string> stringSplit(const generic_string& input, const generic_string& delimiter); |
| 178 | +generic_string stringJoin(const std::vector<generic_string>& strings, const generic_string& separator); |
| 179 | +generic_string stringTakeWhileAdmissable(const generic_string& input, const generic_string& admissable); |
| 180 | +double stodLocale(const generic_string& str, _locale_t loc, size_t* idx = NULL); |
| 181 | + |
| 182 | +int OrdinalIgnoreCaseCompareStrings(LPCTSTR sz1, LPCTSTR sz2); |
| 183 | + |
| 184 | +bool str2Clipboard(const generic_string &str2cpy, HWND hwnd); |
| 185 | + |
| 186 | +generic_string GetLastErrorAsString(DWORD errorCode = 0); |
| 187 | + |
| 188 | +generic_string intToString(int val); |
| 189 | +generic_string uintToString(unsigned int val); |
| 190 | + |
| 191 | +HWND CreateToolTip(int toolID, HWND hDlg, HINSTANCE hInst, const PTSTR pszText); |
| 192 | + |
| 193 | +bool isCertificateValidated(const generic_string & fullFilePath, const generic_string & subjectName2check); |
| 194 | +bool isAssoCommandExisting(LPCTSTR FullPathName); |
0 commit comments