diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 000000000..080ddc987 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,95 @@ +# Notes: +# - Minimal appveyor.yml file is an empty file. All sections are optional. +# - Indent each level of configuration with 2 spaces. Do not use tabs! +# - All section names are case-sensitive. +# - Section names should be unique on each level. + +#---------------------------------# +# general configuration # +#---------------------------------# + +# version format +version: 2.0.2.{build} + +# you can use {branch} name in version format too +# version: 1.0.{build}-{branch} + +# branches to build +branches: + # whitelist + only: + - master + + # blacklist + except: + - gh-pages + +# Do not build on tags (GitHub only) +skip_tags: true + +#---------------------------------# +# environment configuration # +#---------------------------------# + +# Operating system (build VM template) +os: Windows Server 2012 + +image: + - Visual Studio 2017 +# - Visual Studio 2015 + +# scripts that are called at very beginning, before repo cloning +init: + - git config --global core.autocrlf input + +#---------------------------------# +# build configuration # +#---------------------------------# + +# build platform, i.e. x86, x64, Any CPU. This setting is optional. +#platform: Any CPU + +# to add several platforms to build matrix: +platform: + - Win32 + - x64 + +# build Configuration, i.e. Debug, Release, etc. +#configuration: Release + +# to add several configurations to build matrix: +configuration: + - Release +# - Debug + +build: + project: Notepad3.sln + parallel: true + verbosity: minimal +test: off + +# Artifact paths are relative to C:\projects\notepad2-mod\ +artifacts: + - path: bin\**\*.* +# - name: All + +matrix: + fast_finish: true + +#deploy: +# - provider: S3 +# access_key_id: XXXXXXXXXXXXXXXXXXXX +# secret_access_key: +# secure: --------------------------------------------------------- +# region: us-west-2 +# bucket: notepad3 +# artifact: All +# set_public: true +# encrypt: true +#notifications: +#- provider: Email +# to: +# - rizonesoft+github@gmail.com +# on_build_success: true +# on_build_failure: true +# on_build_status_changed: true diff --git a/crypto/crypto.c b/crypto/crypto.c index d1d7055bc..689169b9a 100644 --- a/crypto/crypto.c +++ b/crypto/crypto.c @@ -12,6 +12,16 @@ optionally with master key see ecryption-doc.txt for details */ +#if !defined(WINVER) +#define WINVER 0x601 /*_WIN32_WINNT_WIN7*/ +#endif +#if !defined(_WIN32_WINNT) +#define _WIN32_WINNT 0x601 /*_WIN32_WINNT_WIN7*/ +#endif +#if !defined(NTDDI_VERSION) +#define NTDDI_VERSION 0x06010000 /*NTDDI_WIN7*/ +#endif +#define VC_EXTRALEAN 1 #include #include #include diff --git a/crypto/rijndael-api-fst.c b/crypto/rijndael-api-fst.c index 60a805a10..a65e135c9 100644 --- a/crypto/rijndael-api-fst.c +++ b/crypto/rijndael-api-fst.c @@ -40,6 +40,17 @@ have been tweaked for compatibility with the local environment. */ +#if !defined(WINVER) +#define WINVER 0x601 /*_WIN32_WINNT_WIN7*/ +#endif +#if !defined(_WIN32_WINNT) +#define _WIN32_WINNT 0x601 /*_WIN32_WINNT_WIN7*/ +#endif +#if !defined(NTDDI_VERSION) +#define NTDDI_VERSION 0x06010000 /*NTDDI_WIN7*/ +#endif +#define VC_EXTRALEAN 1 +#define WIN32_LEAN_AND_MEAN 1 #include //#include "helpers.h" //#include "appreg.h" diff --git a/doc/KeyboardShortcuts.txt b/doc/KeyboardShortcuts.txt new file mode 100644 index 000000000..195e7f7f4 --- /dev/null +++ b/doc/KeyboardShortcuts.txt @@ -0,0 +1,300 @@ +Keyboard Shortcuts for Notepad3 + + File + + Ctrl+N New file. + Ctrl+F4 Close file, identical with Ctrl+N. + Ctrl+O Open file. + F5 Reload file. + F8 Reload file without encoding detection. + Ctrl+F8 Reload file with Unicode detection toggled. + Shift+F8 Reload file with ANSI/UTF-8 defaults toggled. + Alt+F8 Reload file without file variable parsing. + Ctrl+S Save file. + F6 Save file as. + Ctrl+F6 Save file copy. + Ctrl+P Print file. + Alt+H Open recent file. + + Tools + + Alt+N Open document in new window. + Alt+0 Open new empty window. + Ctrl+M Run metapath file browser plugin. + Ctrl+L Launch document. + Alt+L Open with. + Ctrl+R Run command. + + Favorites + + Alt+I Open favorites. + Alt+K Add to favorites. + F9 Manage favorites. + + Edit + + Ctrl+Z Undo. + Ctrl+Shift+Z Redo. + Alt+Backspace Undo. + Ctrl+Y Redo. + Ctrl+Shift+Y Undo. + Ctrl+X Cut selection / Cut current line, if no selection. + Shift+Del Cut. + Ctrl+C Copy selection / Copy current line, if no selection . + Alt+C Copy all. + Ctrl+E Copy add. + Ctrl+V Paste. + Shift+Ins Paste. + Ctrl+K Swap. + Del Clear. + Ctrl+A Select all. + Alt+Shift+Arrows Rectangular selection. + Ctrl+Shift+Enter New line with toggled auto indent option. (orig-NP2: Ctrl+Enter) + Ctrl+PgUp/PgDn Goto previous/next block. + Ctrl+Shift+PgUp/PgDn Select to previous/next block. + + Char, Word + + Ctrl+Space Select word (or line). + Ctrl+Backspace Delete word before/left. + Ctrl+Del Delete word after/right. + Ctrl+Tab Insert tabulator. + + Lines + + Ctrl+Shift+Space Select line. + Ctrl+Shift+Up Move line (block) up. + Ctrl+Shift+Down Move line (block) down. + Ctrl+D Duplicate line. + Ctrl+Shift+X Cut line. + Ctrl+Shift+C Copy line. + Ctrl+Shift+D Delete line. + Ctrl+Shift+Backspace Delete line left. + Ctrl+Shift+Del Delete line right. + Ctrl+Shift+W Column wrap. + Ctrl+I Split lines. + Ctrl+J Join lines. + Ctrl+Shift+J Join paragraphs. + + Block + + Tab Indent selected block. + Shift+Tab Unindent selected block. + Alt+Q Enclose selection. + Alt+D Duplicate selection. + Alt+B Pad with spaces. + Alt+Z Strip first character. + Alt+U Strip last character. + Alt+W Strip trailing blanks. + Alt+P Compress whitespace. + Alt+R Remove blank lines. + Alt+M Modify lines. + Alt+O Sort lines. + + Convert + + Ctrl+Shift+U Make uppercase. + Ctrl+U Make lowercase. + Ctrl+Alt+I Invert case. + Ctrl+Alt+T Title case. + Ctrl+Alt+S Sentence case. + Ctrl+Shift+S Convert tabs to spaces. + Ctrl+Shift+T Convert spaces to tabs. + Ctrl+Shift+A Convert to ANSI. + Ctrl+Shift+O Convert to OEM. + + Insert + + Alt+X HTML/XML tag. + Ctrl+F5 Time/date (short form). + Ctrl+Shift+F5 Time/date (long form). + Ctrl+F9 Filename. + Ctrl+Shift+F9 Path and filename. + Ctrl+Shift+. Insert GUID. + + Special + + Ctrl+Q Block comment (toggle). + Ctrl+Shift+Q Stream comment. + Ctrl+Shift+E URL Encode. + Ctrl+Shift+R URL Decode. + Ctrl+Alt+E Escape C Special Chars. + Ctrl+Alt+U Unescape C Special Chars. + Ctrl+B Find matching brace. + Ctrl+Shift+B Select to matching brace. + Ctrl+1 Enclose within ''. + Ctrl+2 Enclose within "". + Ctrl+3 Enclose within (). + Ctrl+4 Enclose within []. + Ctrl+5 Enclose within {}. + Ctrl+6 Enclose within ``. + Shift+F5 Update timestamps. + Ctrl+, Jump to selection start. + Ctrl+. Jump to selection end. + + Find, Replace + + Ctrl+F Find. + Alt+F3 Save find text. + F3 Find next. + Shift+F3 Find previous. + Ctrl+F3 Find next word or selection. + Ctrl+Shift+F3 Find previous word or selection. + Ctrl+Alt+F2 Expand selection to next match. (orig-NP2: F2) + Ctrl+Alt+Shift+F2 Expand selection to previous match. (orig-NP2: Shift+F2) + Ctrl+H Replace. + F4 Replace next. + Ctrl+G Jump to line. + + Bookmarks + + F2 Jump to next bookmark. + Shift+F2 Jump to previous bookmark. + Ctrl+F2 Toggle bookmark. + Alt+F2 Clear all. + + Syntax scheme, Font + + F12 Select syntax scheme. + Shift+F12 Select 2nd default syntax scheme. + Ctrl+F12 Customize syntax schemes. + Alt+F12 Select default font. + F11 Select default text syntax scheme. + Ctrl+F11 Select web source code syntax scheme. + Shift+F11 Select XML document syntax scheme. + + View + + Ctrl+W Toggle word wrap. + Ctrl+Shift+L Show long line marker. + Ctrl+Shift+G Show indentation guides. + Ctrl+Shift+N Show line numbers. + Ctrl+Shift+M Show selection margin. + Ctrl+Shift+8 Show whitespace. + Ctrl+Shift+9 Show line endings. + Ctrl+Shift+0 Show wrap symbols. + Ctrl+Shift+V Toggle visual brace matching. + Ctrl+Shift+I Highlight current line. + Ctrl+Shift+Alt+F Activate/Deactivate code folding. + Ctrl+Shift+F Toggle all folds. + + Zoom + + Ctrl++ Zoom in. + Ctrl+- Zoom out. + Ctrl+0 Reset zoom. + + Settings + + Ctrl+T Tab settings. + Alt++ Increase limit for long lines. + Alt+- Decrease limit for long lines. + Ctrl+Shift+H Toggle auto close HTML/XML. + Alt+T Always on top. + Ctrl+Numpad_* Transparent mode. + Ctrl+9 Display text excerpt in title. + F7 Save settings now. + Ctrl+F7 Jump to ini-file. + + Misc. + + Esc Optionally minimize or exit Notepad2. + Shift+Esc Save file and exit Notepad2. + F1 Display version info. + + +Regular Expression Syntax + + . Matches any character + + \( This marks the start of a region for tagging a match. + + \) This marks the end of a tagged region. + + \n Where n is 1 through 9 refers to the first through ninth + tagged region when replacing. For example, if the search + string was Fred\([1-9]\)XXX and the replace string was + Sam\1YYY, when applied to Fred2XXX this would generate + Sam2YYY. + + \< This matches the start of a word. + + \> This matches the end of a word. + + \x This allows you to use a character x that would otherwise + have a special meaning. For example, \[ would be interpreted + as [ and not as the start of a character set. + + [...] This indicates a set of characters, for example, [abc] means + any of the characters a, b or c. You can also use ranges, for + example [a-z] for any lower case character. + + [^...] The complement of the characters in the set. For example, + [^A-Za-z] means any character except an alphabetic character. + + ^ This matches the start of a line (unless used inside a set, + see above). + + $ This matches the end of a line. + + * This matches 0 or more times. For example, Sa*m matches Sm, + Sam, Saam, Saaam and so on. + + + This matches 1 or more times. For example, Sa+m matches Sam, + Saam, Saaam and so on. + + \d Any decimal digit. + \D Any character that is not a decimal digit. + + \s Any whitespace character. + \S Any character that is not a whitespace character. + + \w Any "word" character. + \W Any "non-word" character. + + \xHH Character with hex code HH. + + -----> Examples (don't use quotes) + - Quote lines: find "^" replace with "> " + - Unquote lines: find "^> " replace with "" + - Remove line numbers: find "^[0-9]+" replace with "" + - Convert tabs to double spaces: find "\t" replace with " " + + +Command Line Switches + + Notepad2.exe [(encoding)] [(line ending mode)] [/g ln[,col]] + [/m[-][r|b] text] [/q] [/s ext] [/d] [/h] [/x] [/c] + [/b] [/n|/ns] [/r|/rs] + [/p x,y,cx,cy[,max]|/p0|/ps|/pf,l,t,r,b,m] + [/t title] [/i] [/f ini|/f0] [/?] [+|-] [file] ... + + file File to open, can be a relative pathname, or a shell link. + Must be the last argument, no quoted spaces by default. + + Accept multiple file arguments (with quoted spaces). + - Accept single file argument (without quoted spaces). + ... Desired file encoding (can be one of /ansi, /unicode, + /unicodebe, /utf8 or /utf8sig). + ... Desired line ending mode (either /crlf, /lf, or /cr). + /g Jump to specified position, /g -1 means end of file. + /m Match specified text (/m- last, /mr regex, /mb backslash). + /q Force creation of new files without prompt. + /s Select syntax scheme associated with specified extension. + /d Select default text scheme. + /h Select Web Source Code scheme. + /x Select XML Document scheme. + /c Open a new Notepad2 window and paste the clipboard contents. + /b Open a new Notepad2 paste board to collect clipboard entries. + /n Always open a new Notepad2 window (/ns single file instance). + /r Reuse Notepad2 window (/rs single file instance). + /p Set window position to x,y with size cx,cy, optional max set + to nonzero to zoom; /p0 system, /ps internal defaults; + /p(f)ull,(l)eft,(t)op,(r)ight,(b)ottom,(m)argin. + /t Set window title. + /i Start as tray icon. + /f Specify ini-file; /f0 use no ini-file (don't save settings). + /v Print file and quit. + /vd Print file, but show Printer config dialog. + /z Skip next (Registry based Notepad replacement) + /? Display a brief summary about command line parameters. + diff --git a/doc/Notepad3.txt b/doc/Notepad3.txt new file mode 100644 index 000000000..895cc5d0d --- /dev/null +++ b/doc/Notepad3.txt @@ -0,0 +1,823 @@ +======================================================================= += = += = += Notepad3 - light-weight Scintilla-based text editor for Windows = += = += (c) Rizonesoft 2008-2016 = += https://rizonesoft.com = += = += forked from Notepad2-mod = += maintained by XhmikosR = += https://xhmikosr.github.io/notepad2-mod = += based on: = += Notepad2 4.2.25 = += (c) Florian Balmer 2004-2011 = += http://www.flos-freeware.ch = += = += = +======================================================================= + +Notepad3 is based on code from Florian Balmer's Notepad2 and +XhmikosR's Notepad2-mod. MiniPath is based on code from +Florian Balmer's metapath. + +Changes in Notepad3 compared to original Notepad2 + + + Notepad3: + - Restore selection on undo/redo operations + - Text file encryption/decryption support + - Improved RegExp search n' replace engine (multiline support) + - Syntax highlighting support for MATLAB + - New program icon and other small cosmetic changes + - New toolbar icons based on Yusuke Kamiyaman's Fugue Icons + Purchased by Rizonesoft + - Countinuously updated Scintilla component + - Other various minor changes and tweaks + . Accelerated word navigation + . Scitilla's Direct Write support + . improved encoding and codepage handling + . Insert GUID + + + Notepad2-mod: + - Code folding + - Support for bookmarks + - Option to mark all occurrences of a word + - Updated Scintilla component + - Word auto-completion + - Syntax highlighting support for AutoHotkey, AutoIt3, AviSynth, + Bash, CMake, CoffeeScript, Inno Setup, LaTeX, Lua, Markdown, NSIS, + Ruby, Tcl, YAML and VHDL scripts + - Improved support for NFO ANSI art + - Support for replacing Windows Notepad using a clean, unintrusive + registry-based method + + +Changes in MiniPath compared to metapath + + - Project upgraded to Visual C++ 2017 + - 64-bit version + - New toolbar icons based on Yusuke Kamiyaman's Fugue Icons + Purchased by Rizonesoft + - Installation bundled with Notepad3 + - Minor cosmetic changes + +Supported Operating Systems + + Windows 7, 8, 8.1, 10 both 32-bit and 64-bit + +Contributors: + + - Florian Balmer ( http://www.flos-freeware.ch ) + - XhmikosR ( http://xhmikosr.github.io/notepad2-mod/ ) + - Kai Liu ( http://code.kliu.org/misc/notepad2/ ) + - RL Vision + - Aleksandar Lekov + - Bruno Barbieri + - RaiKoHoff + + +More information: +* Binaries: https://www.rizonesoft.com/downloads/notepad3 +* Source code: https://github.com/rizonesoft/Notepad3 +* https://github.com/XhmikosR/notepad2-mod +* Official Notepad2 website: http://www.flos-freeware.ch/notepad2.html +* Code folding usage guide: https://github.com/XhmikosR/notepad2-mod/wiki/Code-Folding-Usage +* Kai Liu's website: http://code.kliu.org/misc/notepad2/ +* Bookmark Edition website: http://www.rlvision.com/notepad2/about.asp + + +Changed keyboard shortcuts compared to Notepad2: + +Ctrl+C (no selection) Copy current line. +Ctrl+X (no selection) Cut current line. +Ctrl+Shift+. Insert GUID. +Ctrl+0 Reset zoom. +Ctrl+NK_* Toggle transparency + +F2 Go to next bookmark. +Shift+F2 Go to privious bookmark. +Ctrl+F2 Set/Reset bookmark. +Alt+F2 Clear all. + +Ctrl+Shift+Alt+F Activate/Deactivate code folding. +Ctrl+Shift+F Toggle all folds. + +Ctrl+Alt+F2 Expand selection to next match. +Ctrl+Alt+Shift+F2 Expand selection to previous match. +Ctrl+Shift+Enter New line with toggled auto indent option. + + +Changed command Line Switches compared to Notepad2: + + /v Print specified document and leave + /vd Print specified document, but open Print dialog before + + +Hidden .ini-File parameters: + +[Settings2] +StickyWindowPosition= 0/1 (BOOL) - get/set by Notepad3 +DefaultExtension= txt (string) - get/set by Notepad3 +DefaultDirectory= dir (string) - open/save file dialog +FileDlgFilters= filter (string) - open/save file dialog filter +FileCheckInverval= 2000 [ms] - ... +AutoReloadTimeout= 2000 [ms] - ... +SciDirectWriteTech= -1,0,1,2,3 - Scintilla's Direct Write Technology +SciFontQuality= 0,1,2,3 - default,none,standard,cleartype + (if not defined by 'smoothing:xxx' in Style Schema) +MarkOccurrencesMaxCount= 2000 - max count of marked word occurences + + +======================================================================= += = += = += Notepad3's Encryption / Decryption feature = += = += Prototype enduser documentation = += taken from NotepadCrypt (Dave Dyer) = += = += http://www.andromeda.com/people/ddyer/notepad/NotepadCrypt.html = += = += = +======================================================================= + +NotepadCrypt is a simple text editor which can optionally encrypt the +text files it edits. NotepadCrypt was designed to fill a requirement to +encrypt configuration files which had to be edited by humans but read by +programs, without the hazard that would obviously exist if editing +required the human editor to make a temporary unencrypted file. I needed +an editor which could read and write an encrypted file, for which the +encrypted format was documented and assessable to C and Perl programs. +To my surprise, none existed. + +NotepadCrypt was constructed using open source software, including a low +level implementation of AES encryption and Sha256 hashing; and Notepad2 +a really nice open source replacement for Notepad. None of this software +had to be changed in any substantial way, but the file format and key +management had to be designed and implemented to stitch it all together. +The requirement that a program be able to read the encrypted file led to +a design which included a master key, which I think is extremely useful +to anyone using NotepadCrypt to encrypt their own confidential files. + +Source code: + +Sha256 hashing implementation (used to convert passphrases to encryption +keys) based on an implementation by Christoper Devine. This file is +available from many sources on the web. AES encryption, for which there +are many open source implementations. Notepad2 editor, which also +requires the Scintilla editing widget. NotepadCrypt version 4.2.25 Full +Sources: This zip includes the as-modified source code for all of the +above, VC.net projects for NotepadCrypt and a simple command line tool +which uses the same file format. There are a couple of "extras" - a test +program that uses tcsh and a java program that can read NotepadCrypt's +file format. Unless you are a programmer, you're probably better off +getting the binary only distribution for NotepadCrypt and Notepad3CL + +Technical Details For NotepadCrypt + +Overall Design: Sha256 hash is used to convert an ascii pass phrase to a +256 bit encryption key. Pseudorandom data is used as an initialization +vector for AES-256 encryption. Optionally, a the encryption key (NOT the +passphrase) is encrypted using a second master key, and included in the +file header. This master key can be used as an emergency data recovery +key, or as a second key to be used by programs to read encrypted files. + +Overall File Format: +Consists of a preamble, the encrypted data, and some padding at the end. + +Encrypted files start with an 8 byte preamble, the first 4 bytes are a +"magic number" to identify the file type (currently 0x04030201) and a 4 +byte sub-file type, (currently either 0x00000001 or 0x00000002 if the +file has a master key). + +The next 16 bytes of the preamble are the initialization vector for the +AES engine, to be used with the file key. Each file gets a unique 16 +bytes of pseudo random noise. + +Next, for master keyed files, is a 16 byte IV for the master key, +followed by a 32 byte block containing the file key, encrypted with the +master key, using the master key IV and CBC block chaining. + +Next, is the actual file data, encrypted using the file key and the IV, +and CBC block chaining. + +Finally, are 1-16 bytes of padding to round out the last AES block. Note +that there are never 0 bytes of padding. + +Passphrase Management: 256 bit encryption keys are generated from the +ascii passphrase by passing the passphrase through a SHA256 hash. The +passphrase itself is never stored anywhere except in the dynamic memory +of the encrypting program. + +Key management over file generations: If the file is opened using a file +passphrase, the passphrase is retained and used as the default for the +passphrase dialog. If the file is opened using a master passphrase, the +recovered file key is used as the default encryption for new files. This +allows an editor who does not know the file passphrase to propogate a +file key he could not create. If the file contains a master key, and +neither the file or master passphrase is changed, then the retained, +master-encrypted file key is copied into the next file generation (It is +still valid). This allows an editor who knows only the file passphrase +to propogate a master key he could not create. + +======================================================================= += = += Notepad3 encryption - prototype enduser documentation = += = +======================================================================= + +If you open a file which was encrypted by this program, you'll be +prompted to supply a passphrase. This passphrase becomes +the default to be used when saving files. The passphrase is not the +actual encryption key, but is used to generate a 256 bit +encryption key called the file key. + +Master Keys + +An Encrypted file can optionally contain a copy of its own file key, +encrypted with a master key, derived from a master +passphrase. This allows anyone who knows the master passphrase to decode +any file encrypted with any file key which uses this +master key structure. As long as the file passphrase is not changed, the +master key can be propogated to new versions of the +file without typing the master phrase again. + + +Why use a master key? + +#1) Data recovery. It is not generally a good idea to use the same +passphrase for all files, or to continue using the same passphrase +forever. The principle hazard is that if even one key is revealed, every +encrypted file you have ever created can also be read. Consequently, +different keys should be used for different files, and over time, those +keys should change. Since the keys change, they are subject to being +lost or forgotton, resulting in lost data - it's still there, but no one +can decode it. If you use a master key, and you have misplaced the file +key, you can still recover your data. Since master key is not routinely +used to decrypt the file, and never needs to be shared with anyone, is +is much less likely to be compromised, so it is reasonable for a good +master key to be used for a very long time in a lot of different files. + +Recommendation: Use a master passphrase that will be very hard for +anyone to guess and very hard for you to forget. For example: + "My Favorite movie is Gone with the Wind" + "When it rains in New York, even Chicago is a better place to be" +Never tell anyone what it is or write it down. It's an EMERGENCY measure +to prevent catastrophic data loss, so treat it that way. Never use it to +read or open any encrypted file except for testing, or if you have +really lost the file passphrase. + +#2) Trapdoor access. Sometimes it is desirable to allow a second party +to decode the file without knowing the encryption passphrase - a good +example is where an automated program is intended to read an encrypted +file that is prepared by a human. The program has to have the passphrase +or the key embedded in it somewhere. It's possible for a dedicated +attacker to find it, but it's much more likely that the source of +compromise will be clumsy humans. Allowing the program to use the master +key and humans to use the ordinary file keys will allow the routine-use +keys to be changed as often as necesary, while still letting the program +read the files without being told the new key. + + +Technical Details: +(http://www.andromeda.com/people/ddyer/notepad/NotepadCrypt-technotes.html) + +Passphrase Management: +256 bit encryption keys are geneated from ascii passphrases by +passing the passphrase through a SHA256 hash. Passphrases are never +Stored anywhere except in the dynamic memory of the encrypting program. + +Key management over file generations: If the file is opened +using a file passphrase, the passphrase is retained and used +as the default for the passphrase dialog. + +If the file is opened using a master passphrase, the recovered +file key is used as the default encryption for new files. This +allows an editor who does not know the file passphrase to propogate +a file key he could not create. + +If the file contains a master key, and neither the file or master +passphrase is changed, then the retained, master-encrypted file +key is copied into the next file generation. (It is still valid). +This allows an editor who knows only the file passphrase to propogate +a master key he could not create. + +Encrypted files start with an 8 byte preable, the first 4 bytes are +a "magic number" to identify the file type (currently 0x04030201) +and a 4 byte subfile type, (currently either 0x00000001 or 0x00000002) + +The next 16 bytes are the initialization vector for the AES engine, +to be used with the file key. Each file gets a unique 16 bytes of +pseudorandom noise. + +Next, for master keyed files, is a 16 byte IV for the master key, +followed by a 32 byte block containing the file key, encrypted +with the master key, using the master key IV and CBC block chaining. + +Next, is the actual file data, encrypted using the file key and the IV, +and CBC block chaining. + +Finally, are 1-16 bytes of padding to round out the AES block. +Note that there are never 0 bytes of padding. + + +A Word about pass phrases and overall security. + +While this encryption scheme uses high quality AES encryption and quite +long 256 bit keys, that is almost irrelevant to the overall security of +the system. It's like having a very expensive lock on your front door. +Thieves won't go to great lengths to pick your lock; they will simply +break a window instead. The weak link in this encryption scheme is YOU +and your selection of pass phrases. If your encrypted files are +compromised, the most likely, by far, method is the simplest; (1) they +ask, you tell. or (2) they find the scrap of paper where you wrote the +passphrase or (3) some key logger watches you type the passphrase. The +only other likely method is a dictionary-type attack using a program to +try lots of possible passphrases. Any short, word-like passphrase CAN be +compromised using a few days of computer time. + +Finally, consider the suitablility of this encryption scheme for your +purpose. + + If your goal is to prevent your wife from reading your girlfriend's + phone number in your address book: definitely. + + If your goal is to prevent disclosure of sensitive data if your laptop + is stolen: most likely. + + If your goal is to prevent fishing by the IRS, should they ever become + curious about you: don't count on it. + They'll throw you in jail until you tell them the password, or install + a key logger and wait for you to tell them voluntarily. + + If your goal is to keep secrets people who are definitely out to get + you, and are willing to shove bamboo splints under you fingernails + until you talk: don't even think about it. + + + +======================================================================= += = += = += Notepad2 - light-weight Scintilla-based text editor for Windows = += = += = += Notepad2 4.2.25 = += (c) Florian Balmer 2004-2011 = += http://www.flos-freeware.ch = += = += = +======================================================================= + + +Description + + Notepad2 is a light-weight, free and open source Notepad-like text + editor with syntax highlighting for a few commonly used languages. + It's based on the Scintilla source code editing component and works + on NT-based versions of Windows. + + +Features + + - Syntax highlighting: HTML, XML, PHP, ASP (JS, VBS), CSS, + JavaScript, VBScript, C/C++, C#, Resource Script, Makefiles, Java, + Visual Basic, Pascal, Assembly, SQL, Perl, Python, Configuration + Files, Apache Config Files, PowerShell, Batch Files, Diff Files + - Drag & drop text editing inside and outside Notepad2 + - Basic regular expression search and replace + - Useful word, line and block editing shortcuts + - Rectangular selection (Alt+Mouse) + - Brace matching, auto indent, long line marker, zoom functions + - Support for Unicode, UTF-8, Unix and Mac text files + - Open shell links + - Mostly adjustable + +Installation and Uninstallation + + Just put a copy of Notepad2.exe and Notepad2.ini to any directory on + your computer. To uninstall Notepad2, simply delete these two files. + Notepad2 does not create any registry entries on your computer. + +The Notepad2 Source Code + + This package contains the full source code of Notepad2 4.2.25 for + Windows. Project files for Visual C++ 7.0 are included. Chances are + that Notepad2 can be rebuilt with other development tools, including + the free Visual C++ Express Edition, but I haven't tested this. + + +Rebuilding from the Source Code + + Notepad2 4.2.25 is based on Scintilla 2.24 [1]. + + [1] http://www.scintilla.org + + To be able to rebuild Notepad2, the source code of the Scintilla + editing component has to be unzipped to the "scintilla" subdirectory + of the Notepad2 source code directory. + + Many of the Scintilla lexing modules are not used by Notepad2. Run + LinkLex.js to adapt the list (in "scintilla/src/Catalogue.cxx") and + make linking work properly. + + +Creating a Compact Executable Program File + + Linking to the system CRT slightly improves disk footprint, memory + usage and startup because the pages for the system CRT are already + loaded and shared in memory. To achieve this, the release version of + Notepad2.exe is built using the Windows Driver Kit (WDK) 7.1.0 tools, + available as a free download from Microsoft. The appropriate build + scripts can be found in the "wdkbuild" subdirectory. Set %WDKBASEDIR% + to the directory of the WDK tools on your system. + + +How to add or modify Syntax Schemes + + The Scintilla documentation has an overview of syntax highlighting, + and how to write your own lexing module, in case the language you + would like to add is not currently supported by Scintilla. + + Add your own lexer data structs to the global pLexArray (Styles.c), + then adjust NUMLEXERS (Styles.h) to the new total number of syntax + schemes. Include the "scintilla/lexers/Lex*.cxx" file required for + your language into your project. Ensure the new module is initialized + (in "scintilla/src/Catalogue.cxx"), either by manually uncommenting + the corresponding LINK_LEXER() macro call, or by updating and + re-running LinkLex.js. + + +Keyboard Shortcuts for Notepad2 + + File + + Ctrl+N New file. + Ctrl+F4 Close file, identical with Ctrl+N. + Ctrl+O Open file. + F5 Reload file. + F8 Recode file. + Ctrl+Shift+F Recode file as default encoding. + Ctrl+Shift+A Recode file as system default ANSI. + Ctrl+Shift+O Recode file as system default OEM. + Shift+F8 Recode 7-bit ASCII file as UTF-8. + Alt+F8 Reload file without file variable parsing. + Ctrl+S Save file. + F6 Save file as. + Ctrl+F6 Save file copy. + Ctrl+P Print file. + Alt+H Open recent file. + + Tools + + Alt+N Open document in new window. + Alt+0 Open new empty window. + Ctrl+M Run metapath file browser plugin. + Ctrl+L Launch document. + Alt+L Open with. + Ctrl+R Run command. + + Favorites + + Alt+I Open favorites. + Alt+K Add to favorites. + Alt+F9 Manage favorites. + + Edit + + Ctrl+Z Undo. + Ctrl+Shift+Z Redo. + Alt+Backspace Undo. + Ctrl+Y Redo. + Ctrl+Shift+Y Undo. + Ctrl+X Cut. + Shift+Del Cut. + Ctrl+C Copy. + Alt+C Copy all. + Ctrl+E Copy add. + Ctrl+V Paste. + Shift+Ins Paste. + Ctrl+K Swap. + Del Clear. + Ctrl+A Select all. + Alt+Shift+Arrows Rectangular selection. + Ctrl+Enter New line with toggled auto indent option. + Ctrl+PgUp/PgDn Goto previous/next block. + Ctrl+Shift+PgUp/PgDn Select to previous/next block. + + Char, Word + + Ctrl+Space Select word (or line). + Ctrl+Backspace Delete word before/left. + Ctrl+Del Delete word after/right. + Ctrl+Tab Insert tabulator. + + Lines + + Ctrl+Shift+Space Select line. + Ctrl+Shift+Up Move line (block) up. + Ctrl+Shift+Down Move line (block) down. + Ctrl+D Duplicate line. + Ctrl+Shift+X Cut line. + Ctrl+Shift+C Copy line. + Ctrl+Shift+D Delete line. + Ctrl+Shift+Backspace Delete line left. + Ctrl+Shift+Del Delete line right. + Ctrl+Shift+W Column wrap. + Ctrl+I Split lines. + Ctrl+J Join lines. + Ctrl+Shift+J Join paragraphs. + + Block + + Tab Indent selected block. + Shift+Tab Unindent selected block. + Alt+Q Enclose selection. + Alt+D Duplicate selection. + Alt+B Pad with spaces. + Alt+Z Strip first character. + Alt+U Strip last character. + Alt+W Strip trailing blanks. + Alt+P Compress whitespace. + Alt+Y Merge blank lines. + Alt+R Remove blank lines. + Alt+M Modify lines. + Alt+J Align lines. + Alt+O Sort lines. + + Convert + + Ctrl+Shift+U Make uppercase. + Ctrl+U Make lowercase. + Ctrl+Alt+U Invert case. + Ctrl+Alt+I Title case. + Ctrl+Alt+O Sentence case. + Ctrl+Shift+S Convert tabs to spaces. + Ctrl+Shift+T Convert spaces to tabs. + Ctrl+Alt+S Convert indenting tabs to spaces. + Ctrl+Alt+T Convert indenting spaces to tabs. + + Insert + + Alt+X HTML/XML tag. + Ctrl+F8 Encoding identifier. + Ctrl+F5 Time/date (short form). + Ctrl+Shift+F5 Time/date (long form). + Ctrl+F9 Filename. + Ctrl+Shift+F9 Path and filename. + + Special + + Ctrl+Q Block comment (toggle). + Ctrl+Shift+Q Stream comment. + Ctrl+Shift+E URL Encode. + Ctrl+Shift+R URL Decode. + Ctrl+Alt+E Escape C Special Chars. + Ctrl+Alt+R Unescape C Special Chars. + Ctrl+Alt+X Convert character to hex code. + Ctrl+Alt+C Convert hex code to character. + Ctrl+B Find matching brace. + Ctrl+Shift+B Select to matching brace. + F2 Expand selection to next match. + Shift+F2 Expand selection to previous match. + Ctrl+1 Enclose within ''. + Ctrl+2 Enclose within "". + Ctrl+3 Enclose within (). + Ctrl+4 Enclose within []. + Ctrl+5 Enclose within {}. + Ctrl+6 Enclose within ``. + Shift+F5 Update timestamps. + Ctrl+Alt++ Increase number. + Ctrl+Alt+- Decrease number. + Ctrl+, Jump to selection start. + Ctrl+. Jump to selection end. + + Find, Replace + + Ctrl+F Find. + Alt+F3 Save find text. + F3 Find next. + Shift+F3 Find previous. + Ctrl+F3 Find next word or selection. + Ctrl+Shift+F3 Find previous word or selection. + Ctrl+H Replace. + F4 Replace next. + Ctrl+G Jump to line. + + Syntax scheme, Font + + F12 Select syntax scheme. + Shift+F12 Select 2nd default syntax scheme. + Ctrl+F12 Customize syntax schemes. + Alt+F12 Select default font. + F11 Select default text syntax scheme. + Ctrl+F11 Select web source code syntax scheme. + Shift+F11 Select XML document syntax scheme. + + View + + Ctrl+W Toggle word wrap. + Ctrl+Shift+L Show long line marker. + Ctrl+Shift+G Show indentation guides. + Ctrl+Shift+N Show line numbers. + Ctrl+Shift+M Show selection margin. + Ctrl+Shift+8 Show whitespace. + Ctrl+Shift+9 Show line endings. + Ctrl+Shift+0 Show wrap symbols. + Ctrl+Shift+V Toggle visual brace matching. + Ctrl+Shift+I Highlight current line. + + Zoom + + Ctrl++ Zoom in. + Ctrl+- Zoom out. + Ctrl+/ Reset zoom. + + Settings + + Ctrl+T Tab settings. + Alt++ Increase limit for long lines. + Alt+- Decrease limit for long lines. + Ctrl+Shift+H Toggle auto close HTML/XML. + Alt+T Always on top. + Ctrl+0 Transparent mode. + Alt+F5 File change notification settings. + Ctrl+9 Display text excerpt in title. + F7 Save settings now. + Ctrl+F7 Jump to ini-file. + + Misc. + + Shift+F9 Copy pathname to clipboard. + Ctrl+Shift+K Copy window position to clipboard. + Ctrl+Shift+P Move window to default position. + Esc Optionally minimize or exit Notepad2. + Shift+Esc Save file and exit Notepad2. + F1 Display version info. + + +Regular Expression Syntax + + Note: the Scintilla source code editing component supports only a + basic subset of regular expression syntax, and searches are limited + to single lines. + + . Matches any character. + + (...) This marks a region for tagging a match. + + \n Where n is 1 through 9 refers to the first through ninth + tagged region when replacing. For example, if the search + string was Fred([1-9])XXX and the replace string was Sam\1YYY, + when applied to Fred2XXX this would generate Sam2YYY. + + \< This matches the start of a word. + + \> This matches the end of a word. + + \x This allows you to use a character x that would otherwise + have a special meaning. For example, \[ would be interpreted + as [ and not as the start of a character set. + + [...] This indicates a set of characters, for example, [abc] means + any of the characters a, b or c. You can also use ranges, for + example [a-z] for any lower case character. + + [^...] The complement of the characters in the set. For example, + [^A-Za-z] means any character except an alphabetic character. + + ^ This matches the start of a line (unless used inside a set, + see above). + + $ This matches the end of a line. + + ? This matches 0 or 1 times. For example, a?b matches ab and b. + + * This matches 0 or more times. For example, Sa*m matches Sm, + Sam, Saam, Saaam and so on. + + + This matches 1 or more times. For example, Sa+m matches Sam, + Saam, Saaam and so on. + + *? Causes * and + to behave non-greedy. For example, <.+> matches + +? all HTML tags on a line, whereas <.+?> matches only one tag. + + \d Any decimal digit. + \D Any character that is not a decimal digit. + + \s Any whitespace character. + \S Any character that is not a whitespace character. + + \w Any "word" character. + \W Any "non-word" character. + + \xHH Character with hex code HH. + + -----> Examples (don't use quotes) + - Quote lines: find "^" replace with "> " + - Unquote lines: find "^> " replace with "" + - Remove line numbers: find "^[0-9]+" replace with "" + - Convert tabs to double spaces: find "\t" replace with " " + - Remove NULL bytes: find "\x00" replace with "" + + +Command Line Switches + + Notepad2.exe [encoding] [line-ending-mode] [/e id] [/g ln[,col]] + [/m[-][r|b] text] [/l|/l0] [/q] [/s ext] [/d] [/h] [/x] + [/c] [/b] [/n|/ns] [/r|/rs] + [/p x,y,cx,cy[,max]|/p0|/ps|/p[f|l|t|r|b|m]] + [/t title] [/i] [/o|/o0] [/f ini|/f0] [/u] [/z ...] [/?] + [+|-] [file] ... + + file File to open, can be a relative pathname, or a shell link. + Must be the last argument, no quoted spaces by default. + + Accept multiple file arguments (with quoted spaces). + - Accept single file argument (without quoted spaces). + ... Desired file encoding (can be one of /ansi, /unicode, + /unicodebe, /utf8 or /utf8sig). + ... Desired line ending mode (either /crlf, /lf, or /cr). + /e Specify file source encoding. + /g Jump to specified position, /g -1 means end of file. + /m Match specified text (/m- last, /mr regex, /mb backslash). + /l Auto-reload modified files; /l0 disable change notification. + /q Force creation of new files without prompt. + /s Select syntax scheme associated with specified extension. + /d Select default text scheme. + /h Select Web Source Code scheme. + /x Select XML Document scheme. + /c Open a new Notepad2 window and paste the clipboard contents. + /b Open a new Notepad2 paste board to collect clipboard entries. + /n Always open a new Notepad2 window (/ns single file instance). + /r Reuse Notepad2 window (/rs single file instance). + /p Set window position to x,y with size cx,cy, optional max set + to nonzero to zoom; /p0 system, /ps internal defaults; + /p(f)ull,(l)eft,(t)op,(r)ight,(b)ottom,(m)argin. + /t Set window title. + /i Start as tray icon. + /o Keep window on top; /o0 do not keep window on top. + /f Specify ini-file; /f0 use no ini-file (don't save settings). + /u Launch with elevated privileges. + /z Skip next (usable for registry-based Notepad replacement). + /? Display a brief summary about command line parameters. + + +Source Code + + Notepad2 is based on the Scintilla source code editing component: + http://www.scintilla.org + + The full Notepad2 source code can be found at: + http://www.flos-freeware.ch + + +More Information and Resources + + For more information on Notepad2 features, how to replace Windows + Notepad, and answers to the most frequently asked questions (FAQ), + please visit the Notepad2 website: + http://www.flos-freeware.ch + + +Feature Requests + + Thank you very much for the overwhelming feedback about Notepad2! + Feature requests are always welcome, but please keep in mind that + Notepad2 has been designed as a compact Notepad replacement. + + +Credits and Special Thanks + + Here I would like to say "THANK YOU" to the developers of the great + Scintilla source code editing component [1], which is the core of + Notepad2. Without Scintilla, the rich features found in Notepad2 + wouldn't have been possible! + + [1] http://www.scintilla.org + + Many thanks to everybody for sending me bug reports and useful hints. + A special thank goes to Roland Weigelt [2] for his helpful thoughts + and comments about Notepad2 features and usability in early develop- + ment stages. I'd also like to express my thanks to Timo Kunze [3], + Kai Liu [4], Moritz Kroll, Seunghun Thomas Lee [5] and Shawn + Brenneman for sending detailed bug reports and ready-to-use patches. + + [2] http://www.roland-weigelt.de + [3] http://www.TimoSoft-Software.de + [4] http://code.kliu.org/misc/notepad2/ + [5] stlee42@gmail.com + + +Copyright + + Notepad2 is FREE SOFTWARE and may be used and distributed freely. + Please do not charge any distribution or download fees for this + program, except for the cost of the distribution medium. The use of + this software is AT YOUR OWN RISK. See License.txt for full details. + + If you have comments or questions, please drop me a note: + florian.balmer@gmail.com + + (c) Florian Balmer 2004-2011 + +### diff --git a/scintilla/Scintilla.vcxproj.filters b/scintilla/Scintilla.vcxproj.filters index 2e980ef83..f8a0e4e85 100644 --- a/scintilla/Scintilla.vcxproj.filters +++ b/scintilla/Scintilla.vcxproj.filters @@ -255,6 +255,12 @@ lexers + + src + + + lexlib + @@ -428,6 +434,12 @@ src + + src + + + lexlib + diff --git a/src/Dialogs.c b/src/Dialogs.c index 58c1084f6..e2a9fae20 100644 --- a/src/Dialogs.c +++ b/src/Dialogs.c @@ -12,9 +12,18 @@ * * * * *******************************************************************************/ +#if !defined(WINVER) +#define WINVER 0x601 /*_WIN32_WINNT_WIN7*/ +#endif #if !defined(_WIN32_WINNT) -#define _WIN32_WINNT 0x501 +#define _WIN32_WINNT 0x601 /*_WIN32_WINNT_WIN7*/ +#endif +#if !defined(NTDDI_VERSION) +#define NTDDI_VERSION 0x06010000 /*NTDDI_WIN7*/ #endif +#define VC_EXTRALEAN 1 +#define WIN32_LEAN_AND_MEAN 1 + #include #include #include @@ -399,8 +408,8 @@ INT_PTR CALLBACK RunDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam) ExpandEnvironmentStringsEx(arg1,COUNTOF(arg1)); ExtractFirstArgument(arg1,arg1,arg2,MAX_PATH); - if (lstrcmpi(arg1,L"notepad3") == 0 || - lstrcmpi(arg1,L"notepad3.exe") == 0) { + if (StringCchCompareIN(arg1,COUNTOF(arg1),L"notepad3",-1) == 0 || + StringCchCompareIN(arg1,COUNTOF(arg1),L"notepad3.exe",-1) == 0) { GetModuleFileName(NULL,arg1,COUNTOF(arg1)); bQuickExit = TRUE; } @@ -410,7 +419,8 @@ INT_PTR CALLBACK RunDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam) PathRemoveFileSpec(wchDirectory); } - SHELLEXECUTEINFO sei = { 0 }; + SHELLEXECUTEINFO sei; + ZeroMemory(&sei,sizeof(SHELLEXECUTEINFO)); sei.cbSize = sizeof(SHELLEXECUTEINFO); sei.fMask = 0; sei.hwnd = hwnd; @@ -421,13 +431,14 @@ INT_PTR CALLBACK RunDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam) sei.nShow = SW_SHOWNORMAL; if (bQuickExit) { - sei.fMask |= /*SEE_MASK_NOZONECHECKS*/0x00800000; + sei.fMask |= SEE_MASK_NOZONECHECKS; EndDialog(hwnd,IDOK); + CoInitializeEx(NULL,COINIT_APARTMENTTHREADED | COINIT_SPEED_OVER_MEMORY); ShellExecuteEx(&sei); } else { - + CoInitializeEx(NULL,COINIT_APARTMENTTHREADED | COINIT_SPEED_OVER_MEMORY); if (ShellExecuteEx(&sei)) EndDialog(hwnd,IDOK); @@ -628,6 +639,7 @@ INT_PTR CALLBACK OpenWithDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam // BOOL OpenWithDlg(HWND hwnd,LPCWSTR lpstrFile) { + BOOL result = FALSE; DLITEM dliOpenWith; dliOpenWith.mask = DLI_FILENAME; @@ -643,7 +655,8 @@ BOOL OpenWithDlg(HWND hwnd,LPCWSTR lpstrFile) PathRemoveFileSpec(wchDirectory); } - SHELLEXECUTEINFO sei = { 0 }; + SHELLEXECUTEINFO sei; + ZeroMemory(&sei,sizeof(SHELLEXECUTEINFO)); sei.cbSize = sizeof(SHELLEXECUTEINFO); sei.fMask = 0; sei.hwnd = hwnd; @@ -659,12 +672,11 @@ BOOL OpenWithDlg(HWND hwnd,LPCWSTR lpstrFile) //GetShortPathName(szParam,szParam,sizeof(WCHAR)*COUNTOF(szParam)); PathQuoteSpaces(szParam); - ShellExecuteEx(&sei); - - return(TRUE); + CoInitializeEx(NULL,COINIT_APARTMENTTHREADED | COINIT_SPEED_OVER_MEMORY); + result = ShellExecuteEx(&sei); } - return(FALSE); + return result; } diff --git a/src/Dlapi.c b/src/Dlapi.c index 3603cbc56..297a0b2a9 100644 --- a/src/Dlapi.c +++ b/src/Dlapi.c @@ -12,9 +12,17 @@ * * * * *******************************************************************************/ +#if !defined(WINVER) +#define WINVER 0x601 /*_WIN32_WINNT_WIN7*/ +#endif #if !defined(_WIN32_WINNT) -#define _WIN32_WINNT 0x501 +#define _WIN32_WINNT 0x601 /*_WIN32_WINNT_WIN7*/ +#endif +#if !defined(NTDDI_VERSION) +#define NTDDI_VERSION 0x06010000 /*NTDDI_WIN7*/ #endif +#define VC_EXTRALEAN 1 + #include #include #include @@ -932,7 +940,7 @@ BOOL DirList_SelectItem(HWND hwnd,LPCWSTR lpszDisplayName,LPCWSTR lpszFullPath) DirList_GetItem(hwnd,i,&dli); GetShortPathName(dli.szFileName,dli.szFileName,MAX_PATH); - if (!lstrcmpi(dli.szFileName,szShortPath)) + if (!StringCchCompareI(dli.szFileName,szShortPath)) { ListView_SetItemState(hwnd,i,LVIS_FLAGS,LVIS_FLAGS); ListView_EnsureVisible(hwnd,i,FALSE); @@ -964,7 +972,7 @@ void DirList_CreateFilter(PDL_FILTER pdlf,LPCWSTR lpszFileSpec, StringCchCopyN(pdlf->tFilterBuf,COUNTOF(pdlf->tFilterBuf),lpszFileSpec,DL_FILTER_BUFSIZE); pdlf->bExcludeFilter = bExcludeFilter; - if (!lstrcmp(lpszFileSpec,L"*.*") || !StringCchLenN(lpszFileSpec,DL_FILTER_BUFSIZE)) + if (!StringCchCompareX(lpszFileSpec,L"*.*") || !StringCchLenN(lpszFileSpec,DL_FILTER_BUFSIZE)) return; pdlf->nCount = 1; diff --git a/src/Edit.c b/src/Edit.c index e47ac2f10..54a082216 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -13,9 +13,17 @@ * * *******************************************************************************/ +#if !defined(WINVER) +#define WINVER 0x601 /*_WIN32_WINNT_WIN7*/ +#endif #if !defined(_WIN32_WINNT) -#define _WIN32_WINNT 0x501 +#define _WIN32_WINNT 0x601 /*_WIN32_WINNT_WIN7*/ +#endif +#if !defined(NTDDI_VERSION) +#define NTDDI_VERSION 0x06010000 /*NTDDI_WIN7*/ #endif +#define VC_EXTRALEAN 1 + #include #include #include @@ -67,6 +75,7 @@ extern BOOL bLoadASCIIasUTF8; extern BOOL bLoadNFOasOEM; extern BOOL bAccelWordNavigation; +extern int iMarkOccurrencesMaxCount; #define DELIM_BUFFER 258 char DelimChars[DELIM_BUFFER] = { '\0' }; @@ -75,83 +84,104 @@ char PunctuationCharsDefault[DELIM_BUFFER] = { '\0' }; char WhiteSpaceCharsAccelerated[DELIM_BUFFER] = { '\0' }; char PunctuationCharsAccelerated[DELIM_BUFFER] = { '\0' }; +enum AlignMask { + ALIGN_LEFT = 0, + ALIGN_RIGHT = 1, + ALIGN_CENTER = 2, + ALIGN_JUSTIFY = 3, + ALIGN_JUSTIFY_EX = 4 +}; + +enum SortOrderMask { + SORT_ASCENDING = 0, + SORT_DESCENDING = 1, + SORT_SHUFFLE = 2, + SORT_MERGEDUP = 4, + SORT_UNIQDUP = 8, + SORT_UNIQUNIQ = 16, + SORT_NOCASE = 32, + SORT_LOGICAL = 64, + SORT_COLUMN = 128 +}; + int g_DOSEncoding; // Supported Encodings -WCHAR wchANSI[8] = L""; -WCHAR wchOEM [8] = L""; +WCHAR wchANSI[8] = { L'\0'}; +WCHAR wchSYS[8] = { L'\0' }; +WCHAR wchOEM[8] = { L'\0' }; NP2ENCODING mEncoding[] = { - { NCP_ANSI|NCP_RECODE, CP_ACP, "ansi,ansi,ascii,", 61000, L"" }, - { NCP_8BIT|NCP_RECODE, CP_OEMCP, "oem,oem,", 61001, L"" }, - { NCP_UNICODE|NCP_UNICODE_BOM, CP_UTF8, "", 61002, L"" }, - { NCP_UNICODE|NCP_UNICODE_REVERSE|NCP_UNICODE_BOM, CP_UTF8, "", 61003, L"" }, - { NCP_UNICODE|NCP_RECODE, CP_UTF8, "utf-16,utf16,unicode,", 61004, L"" }, - { NCP_UNICODE|NCP_UNICODE_REVERSE|NCP_RECODE, CP_UTF8, "utf-16be,utf16be,unicodebe,", 61005, L"" }, - { NCP_UTF8|NCP_RECODE, CP_UTF8, "utf-8,utf8,", 61006, L"" }, - { NCP_UTF8|NCP_UTF8_SIGN, CP_UTF8, "utf-8,utf8,", 61007, L"" }, - { NCP_8BIT|NCP_RECODE, CP_UTF7, "utf-7,utf7,", 61008, L"" }, - { NCP_8BIT|NCP_RECODE, 720, "DOS-720,dos720,", 61009, L"" }, - { NCP_8BIT|NCP_RECODE, 28596, "iso-8859-6,iso88596,arabic,csisolatinarabic,ecma114,isoir127,", 61010, L"" }, - { NCP_8BIT|NCP_RECODE, 10004, "x-mac-arabic,xmacarabic,", 61011, L"" }, - { NCP_8BIT|NCP_RECODE, 1256, "windows-1256,windows1256,cp1256", 61012, L"" }, - { NCP_8BIT|NCP_RECODE, 775, "ibm775,ibm775,cp500,", 61013, L"" }, - { NCP_8BIT|NCP_RECODE, 28594, "iso-8859-4,iso88594,csisolatin4,isoir110,l4,latin4,", 61014, L"" }, - { NCP_8BIT|NCP_RECODE, 1257, "windows-1257,windows1257,", 61015, L"" }, - { NCP_8BIT|NCP_RECODE, 852, "ibm852,ibm852,cp852,", 61016, L"" }, - { NCP_8BIT|NCP_RECODE, 28592, "iso-8859-2,iso88592,csisolatin2,isoir101,latin2,l2,", 61017, L"" }, - { NCP_8BIT|NCP_RECODE, 10029, "x-mac-ce,xmacce,", 61018, L"" }, - { NCP_8BIT|NCP_RECODE, 1250, "windows-1250,windows1250,xcp1250,", 61019, L"" }, - { NCP_8BIT|NCP_RECODE, 936, "gb2312,gb2312,chinese,cngb,csgb2312,csgb231280,gb231280,gbk,", 61020, L"" }, - { NCP_8BIT|NCP_RECODE, 10008, "x-mac-chinesesimp,xmacchinesesimp,", 61021, L"" }, - { NCP_8BIT|NCP_RECODE, 950, "big5,big5,cnbig5,csbig5,xxbig5,", 61022, L"" }, - { NCP_8BIT|NCP_RECODE, 10002, "x-mac-chinesetrad,xmacchinesetrad,", 61023, L"" }, - { NCP_8BIT|NCP_RECODE, 10082, "x-mac-croatian,xmaccroatian,", 61024, L"" }, - { NCP_8BIT|NCP_RECODE, 866, "cp866,cp866,ibm866,", 61025, L"" }, - { NCP_8BIT|NCP_RECODE, 28595, "iso-8859-5,iso88595,csisolatin5,csisolatincyrillic,cyrillic,isoir144,", 61026, L"" }, - { NCP_8BIT|NCP_RECODE, 20866, "koi8-r,koi8r,cskoi8r,koi,koi8,", 61027, L"" }, - { NCP_8BIT|NCP_RECODE, 21866, "koi8-u,koi8u,koi8ru,", 61028, L"" }, - { NCP_8BIT|NCP_RECODE, 10007, "x-mac-cyrillic,xmaccyrillic,", 61029, L"" }, - { NCP_8BIT|NCP_RECODE, 1251, "windows-1251,windows1251,xcp1251,", 61030, L"" }, - { NCP_8BIT|NCP_RECODE, 28603, "iso-8859-13,iso885913,", 61031, L"" }, - { NCP_8BIT|NCP_RECODE, 863, "ibm863,ibm863,", 61032, L"" }, - { NCP_8BIT|NCP_RECODE, 737, "ibm737,ibm737,", 61033, L"" }, - { NCP_8BIT|NCP_RECODE, 28597, "iso-8859-7,iso88597,csisolatingreek,ecma118,elot928,greek,greek8,isoir126,", 61034, L"" }, - { NCP_8BIT|NCP_RECODE, 10006, "x-mac-greek,xmacgreek,", 61035, L"" }, - { NCP_8BIT|NCP_RECODE, 1253, "windows-1253,windows1253,", 61036, L"" }, - { NCP_8BIT|NCP_RECODE, 869, "ibm869,ibm869,", 61037, L"" }, - { NCP_8BIT|NCP_RECODE, 862, "DOS-862,dos862,", 61038, L"" }, - { NCP_8BIT|NCP_RECODE, 38598, "iso-8859-8-i,iso88598i,logical,", 61039, L"" }, - { NCP_8BIT|NCP_RECODE, 28598, "iso-8859-8,iso88598,csisolatinhebrew,hebrew,isoir138,visual,", 61040, L"" }, - { NCP_8BIT|NCP_RECODE, 10005, "x-mac-hebrew,xmachebrew,", 61041, L"" }, - { NCP_8BIT|NCP_RECODE, 1255, "windows-1255,windows1255,", 61042, L"" }, - { NCP_8BIT|NCP_RECODE, 861, "ibm861,ibm861,", 61043, L"" }, - { NCP_8BIT|NCP_RECODE, 10079, "x-mac-icelandic,xmacicelandic,", 61044, L"" }, - { NCP_8BIT|NCP_RECODE, 10001, "x-mac-japanese,xmacjapanese,", 61045, L"" }, - { NCP_8BIT|NCP_RECODE, 932, "shift_jis,shiftjis,shiftjs,csshiftjis,cswindows31j,mskanji,xmscp932,xsjis,", 61046, L"" }, - { NCP_8BIT|NCP_RECODE, 10003, "x-mac-korean,xmackorean,", 61047, L"" }, - { NCP_8BIT|NCP_RECODE, 949, "windows-949,windows949,ksc56011987,csksc5601,euckr,isoir149,korean,ksc56011989", 61048, L"" }, - { NCP_8BIT|NCP_RECODE, 28593, "iso-8859-3,iso88593,latin3,isoir109,l3,", 61049, L"" }, - { NCP_8BIT|NCP_RECODE, 28605, "iso-8859-15,iso885915,latin9,l9,", 61050, L"" }, - { NCP_8BIT|NCP_RECODE, 865, "ibm865,ibm865,", 61051, L"" }, - { NCP_8BIT|NCP_RECODE, 437, "ibm437,ibm437,437,cp437,cspc8,codepage437,", 61052, L"" }, - { NCP_8BIT|NCP_RECODE, 858, "ibm858,ibm858,ibm00858,", 61053, L"" }, - { NCP_8BIT|NCP_RECODE, 860, "ibm860,ibm860,", 61054, L"" }, - { NCP_8BIT|NCP_RECODE, 10010, "x-mac-romanian,xmacromanian,", 61055, L"" }, - { NCP_8BIT|NCP_RECODE, 10021, "x-mac-thai,xmacthai,", 61056, L"" }, - { NCP_8BIT|NCP_RECODE, 874, "windows-874,windows874,dos874,iso885911,tis620,", 61057, L"" }, - { NCP_8BIT|NCP_RECODE, 857, "ibm857,ibm857,", 61058, L"" }, - { NCP_8BIT|NCP_RECODE, 28599, "iso-8859-9,iso88599,latin5,isoir148,l5,", 61059, L"" }, - { NCP_8BIT|NCP_RECODE, 10081, "x-mac-turkish,xmacturkish,", 61060, L"" }, - { NCP_8BIT|NCP_RECODE, 1254, "windows-1254,windows1254,", 61061, L"" }, - { NCP_8BIT|NCP_RECODE, 10017, "x-mac-ukrainian,xmacukrainian,", 61062, L"" }, - { NCP_8BIT|NCP_RECODE, 1258, "windows-1258,windows-258,", 61063, L"" }, - { NCP_8BIT|NCP_RECODE, 850, "ibm850,ibm850,", 61064, L"" }, - { NCP_8BIT|NCP_RECODE, 28591, "iso-8859-1,iso88591,cp819,latin1,ibm819,isoir100,latin1,l1,", 61065, L"" }, - { NCP_8BIT|NCP_RECODE, 10000, "macintosh,macintosh,", 61066, L"" }, - { NCP_8BIT|NCP_RECODE, 1252, "windows-1252,windows1252,cp367,cp819,ibm367,us,xansi,", 61067, L"" }, - { NCP_8BIT|NCP_RECODE, 37, "ebcdic-cp-us,ebcdiccpus,ebcdiccpca,ebcdiccpwt,ebcdiccpnl,ibm037,cp037,", 61068, L"" }, - { NCP_8BIT|NCP_RECODE, 500, "x-ebcdic-international,xebcdicinternational,", 61069, L"" }, + { NCP_ANSI | NCP_RECODE, CP_ACP, "ansi,system,ascii,", 61000, L"" }, + { NCP_8BIT | NCP_RECODE, CP_OEMCP, "oem,oem,", 61001, L"" }, + { NCP_UNICODE | NCP_UNICODE_BOM, CP_UTF8, "", 61002, L"" }, + { NCP_UNICODE | NCP_UNICODE_REVERSE | NCP_UNICODE_BOM, CP_UTF8, "", 61003, L"" }, + { NCP_UNICODE | NCP_RECODE, CP_UTF8, "utf-16,utf16,unicode,", 61004, L"" }, + { NCP_UNICODE | NCP_UNICODE_REVERSE | NCP_RECODE, CP_UTF8, "utf-16be,utf16be,unicodebe,", 61005, L"" }, + { NCP_UTF8 | NCP_RECODE, CP_UTF8, "utf-8,utf8,", 61006, L"" }, + { NCP_UTF8 | NCP_UTF8_SIGN, CP_UTF8, "utf-8,utf8,", 61007, L"" }, + { NCP_8BIT | NCP_RECODE, CP_UTF7, "utf-7,utf7,", 61008, L"" }, + { NCP_8BIT | NCP_RECODE, 720, "DOS-720,dos720,", 61009, L"" }, + { NCP_8BIT | NCP_RECODE, 28596, "iso-8859-6,iso88596,arabic,csisolatinarabic,ecma114,isoir127,", 61010, L"" }, + { NCP_8BIT | NCP_RECODE, 10004, "x-mac-arabic,xmacarabic,", 61011, L"" }, + { NCP_8BIT | NCP_RECODE, 1256, "windows-1256,windows1256,cp1256", 61012, L"" }, + { NCP_8BIT | NCP_RECODE, 775, "ibm775,ibm775,cp500,", 61013, L"" }, + { NCP_8BIT | NCP_RECODE, 28594, "iso-8859-4,iso88594,csisolatin4,isoir110,l4,latin4,", 61014, L"" }, + { NCP_8BIT | NCP_RECODE, 1257, "windows-1257,windows1257,", 61015, L"" }, + { NCP_8BIT | NCP_RECODE, 852, "ibm852,ibm852,cp852,", 61016, L"" }, + { NCP_8BIT | NCP_RECODE, 28592, "iso-8859-2,iso88592,csisolatin2,isoir101,latin2,l2,", 61017, L"" }, + { NCP_8BIT | NCP_RECODE, 10029, "x-mac-ce,xmacce,", 61018, L"" }, + { NCP_8BIT | NCP_RECODE, 1250, "windows-1250,windows1250,xcp1250,", 61019, L"" }, + { NCP_8BIT | NCP_RECODE, 936, "gb2312,gb2312,chinese,cngb,csgb2312,csgb231280,gb231280,gbk,", 61020, L"" }, + { NCP_8BIT | NCP_RECODE, 10008, "x-mac-chinesesimp,xmacchinesesimp,", 61021, L"" }, + { NCP_8BIT | NCP_RECODE, 950, "big5,big5,cnbig5,csbig5,xxbig5,", 61022, L"" }, + { NCP_8BIT | NCP_RECODE, 10002, "x-mac-chinesetrad,xmacchinesetrad,", 61023, L"" }, + { NCP_8BIT | NCP_RECODE, 10082, "x-mac-croatian,xmaccroatian,", 61024, L"" }, + { NCP_8BIT | NCP_RECODE, 866, "cp866,cp866,ibm866,", 61025, L"" }, + { NCP_8BIT | NCP_RECODE, 28595, "iso-8859-5,iso88595,csisolatin5,csisolatincyrillic,cyrillic,isoir144,", 61026, L"" }, + { NCP_8BIT | NCP_RECODE, 20866, "koi8-r,koi8r,cskoi8r,koi,koi8,", 61027, L"" }, + { NCP_8BIT | NCP_RECODE, 21866, "koi8-u,koi8u,koi8ru,", 61028, L"" }, + { NCP_8BIT | NCP_RECODE, 10007, "x-mac-cyrillic,xmaccyrillic,", 61029, L"" }, + { NCP_8BIT | NCP_RECODE, 1251, "windows-1251,windows1251,xcp1251,", 61030, L"" }, + { NCP_8BIT | NCP_RECODE, 28603, "iso-8859-13,iso885913,", 61031, L"" }, + { NCP_8BIT | NCP_RECODE, 863, "ibm863,ibm863,", 61032, L"" }, + { NCP_8BIT | NCP_RECODE, 737, "ibm737,ibm737,", 61033, L"" }, + { NCP_8BIT | NCP_RECODE, 28597, "iso-8859-7,iso88597,csisolatingreek,ecma118,elot928,greek,greek8,isoir126,", 61034, L"" }, + { NCP_8BIT | NCP_RECODE, 10006, "x-mac-greek,xmacgreek,", 61035, L"" }, + { NCP_8BIT | NCP_RECODE, 1253, "windows-1253,windows1253,", 61036, L"" }, + { NCP_8BIT | NCP_RECODE, 869, "ibm869,ibm869,", 61037, L"" }, + { NCP_8BIT | NCP_RECODE, 862, "DOS-862,dos862,", 61038, L"" }, + { NCP_8BIT | NCP_RECODE, 38598, "iso-8859-8-i,iso88598i,logical,", 61039, L"" }, + { NCP_8BIT | NCP_RECODE, 28598, "iso-8859-8,iso88598,csisolatinhebrew,hebrew,isoir138,visual,", 61040, L"" }, + { NCP_8BIT | NCP_RECODE, 10005, "x-mac-hebrew,xmachebrew,", 61041, L"" }, + { NCP_8BIT | NCP_RECODE, 1255, "windows-1255,windows1255,", 61042, L"" }, + { NCP_8BIT | NCP_RECODE, 861, "ibm861,ibm861,", 61043, L"" }, + { NCP_8BIT | NCP_RECODE, 10079, "x-mac-icelandic,xmacicelandic,", 61044, L"" }, + { NCP_8BIT | NCP_RECODE, 10001, "x-mac-japanese,xmacjapanese,", 61045, L"" }, + { NCP_8BIT | NCP_RECODE, 932, "shift_jis,shiftjis,shiftjs,csshiftjis,cswindows31j,mskanji,xmscp932,xsjis,", 61046, L"" }, + { NCP_8BIT | NCP_RECODE, 10003, "x-mac-korean,xmackorean,", 61047, L"" }, + { NCP_8BIT | NCP_RECODE, 949, "windows-949,windows949,ksc56011987,csksc5601,euckr,isoir149,korean,ksc56011989", 61048, L"" }, + { NCP_8BIT | NCP_RECODE, 28593, "iso-8859-3,iso88593,latin3,isoir109,l3,", 61049, L"" }, + { NCP_8BIT | NCP_RECODE, 28605, "iso-8859-15,iso885915,latin9,l9,", 61050, L"" }, + { NCP_8BIT | NCP_RECODE, 865, "ibm865,ibm865,", 61051, L"" }, + { NCP_8BIT | NCP_RECODE, 437, "ibm437,ibm437,437,cp437,cspc8,codepage437,", 61052, L"" }, + { NCP_8BIT | NCP_RECODE, 858, "ibm858,ibm858,ibm00858,", 61053, L"" }, + { NCP_8BIT | NCP_RECODE, 860, "ibm860,ibm860,", 61054, L"" }, + { NCP_8BIT | NCP_RECODE, 10010, "x-mac-romanian,xmacromanian,", 61055, L"" }, + { NCP_8BIT | NCP_RECODE, 10021, "x-mac-thai,xmacthai,", 61056, L"" }, + { NCP_8BIT | NCP_RECODE, 874, "windows-874,windows874,dos874,iso885911,tis620,", 61057, L"" }, + { NCP_8BIT | NCP_RECODE, 857, "ibm857,ibm857,", 61058, L"" }, + { NCP_8BIT | NCP_RECODE, 28599, "iso-8859-9,iso88599,latin5,isoir148,l5,", 61059, L"" }, + { NCP_8BIT | NCP_RECODE, 10081, "x-mac-turkish,xmacturkish,", 61060, L"" }, + { NCP_8BIT | NCP_RECODE, 1254, "windows-1254,windows1254,", 61061, L"" }, + { NCP_8BIT | NCP_RECODE, 10017, "x-mac-ukrainian,xmacukrainian,", 61062, L"" }, + { NCP_8BIT | NCP_RECODE, 1258, "windows-1258,windows-258,", 61063, L"" }, + { NCP_8BIT | NCP_RECODE, 850, "ibm850,ibm850,", 61064, L"" }, + { NCP_8BIT | NCP_RECODE, 28591, "iso-8859-1,iso88591,cp819,latin1,ibm819,isoir100,latin1,l1,", 61065, L"" }, + { NCP_8BIT | NCP_RECODE, 10000, "macintosh,macintosh,", 61066, L"" }, + { NCP_8BIT | NCP_RECODE, 1252, "windows-1252,windows1252,cp367,cp819,ibm367,us,xansi,", 61067, L"" }, + { NCP_8BIT | NCP_RECODE, 37, "ebcdic-cp-us,ebcdiccpus,ebcdiccpca,ebcdiccpwt,ebcdiccpnl,ibm037,cp037,", 61068, L"" }, + { NCP_8BIT | NCP_RECODE, 500, "x-ebcdic-international,xebcdicinternational,", 61069, L"" }, /*{ NCP_8BIT|NCP_RECODE, 870, "CP870,cp870,ebcdiccproece,ebcdiccpyu,csibm870,ibm870,", 00000, L"" }, // IBM EBCDIC (Multilingual Latin-2) */ { NCP_8BIT|NCP_RECODE, 875, "x-EBCDIC-GreekModern,xebcdicgreekmodern,", 61070, L"" }, { NCP_8BIT|NCP_RECODE, 1026, "CP1026,cp1026,csibm1026,ibm1026,", 61071, L"" }, @@ -346,7 +376,7 @@ void EditSetNewText(HWND hwnd,char* lpstrText,DWORD cbText) SendMessage(hwnd,SCI_CANCEL,0,0); SendMessage(hwnd,SCI_SETUNDOCOLLECTION,0,0); - SendMessage(hwnd,SCI_EMPTYUNDOBUFFER,0,0); + UndoRedoSelectionMap(-1,NULL); SendMessage(hwnd,SCI_CLEARALL,0,0); SendMessage(hwnd,SCI_MARKERDELETEALL,(WPARAM)-1,0); SendMessage(hwnd,SCI_SETSCROLLWIDTH,2048,0); @@ -358,8 +388,7 @@ void EditSetNewText(HWND hwnd,char* lpstrText,DWORD cbText) SendMessage(hwnd,SCI_ADDTEXT,cbText,(LPARAM)lpstrText); SendMessage(hwnd,SCI_SETUNDOCOLLECTION,1,0); - SendMessage(hwnd,EM_EMPTYUNDOBUFFER,0,0); - UndoRedoSelectionMap(-1,NULL); + //SendMessage(hwnd,EM_EMPTYUNDOBUFFER,0,0); // deprecated SendMessage(hwnd,SCI_SETSAVEPOINT,0,0); SendMessage(hwnd,SCI_GOTOPOS,0,0); SendMessage(hwnd,SCI_CHOOSECARETX,0,0); @@ -390,13 +419,12 @@ BOOL EditConvertText(HWND hwnd,int encSource,int encDest,BOOL bSetSavePoint) if (length == 0) { SendMessage(hwnd,SCI_CANCEL,0,0); SendMessage(hwnd,SCI_SETUNDOCOLLECTION,0,0); - SendMessage(hwnd,SCI_EMPTYUNDOBUFFER,0,0); + UndoRedoSelectionMap(-1,NULL); SendMessage(hwnd,SCI_CLEARALL,0,0); SendMessage(hwnd,SCI_MARKERDELETEALL,(WPARAM)-1,0); Encoding_SciSetCodePage(hwnd,encDest); - SendMessage(hwnd,SCI_SETUNDOCOLLECTION,1,0); - SendMessage(hwnd,EM_EMPTYUNDOBUFFER,0,0); - UndoRedoSelectionMap(-1,NULL); + SendMessage(hwnd,SCI_SETUNDOCOLLECTION,(WPARAM)1,0); + //SendMessage(hwnd,EM_EMPTYUNDOBUFFER,0,0); // deprecated SendMessage(hwnd,SCI_GOTOPOS,0,0); SendMessage(hwnd,SCI_CHOOSECARETX,0,0); @@ -428,13 +456,12 @@ BOOL EditConvertText(HWND hwnd,int encSource,int encDest,BOOL bSetSavePoint) SendMessage(hwnd,SCI_CANCEL,0,0); SendMessage(hwnd,SCI_SETUNDOCOLLECTION,0,0); - SendMessage(hwnd,SCI_EMPTYUNDOBUFFER,0,0); + UndoRedoSelectionMap(-1,NULL); SendMessage(hwnd,SCI_CLEARALL,0,0); SendMessage(hwnd,SCI_MARKERDELETEALL,(WPARAM)-1,0); Encoding_SciSetCodePage(hwnd,encDest); SendMessage(hwnd,SCI_ADDTEXT,cbText,(LPARAM)pchText); - SendMessage(hwnd,SCI_EMPTYUNDOBUFFER,0,0); - SendMessage(hwnd,SCI_SETUNDOCOLLECTION,1,0); + SendMessage(hwnd,SCI_SETUNDOCOLLECTION,(WPARAM)1,0); SendMessage(hwnd,SCI_GOTOPOS,0,0); SendMessage(hwnd,SCI_CHOOSECARETX,0,0); @@ -489,12 +516,49 @@ BOOL EditSetNewEncoding(HWND hwnd,int iCurrentEncoding,int iNewEncoding,BOOL bNo return(FALSE); } +//============================================================================= +// +// EditIsRecodingNeeded() +// +BOOL EditIsRecodingNeeded(WCHAR* pszText, int cchLen) +{ + const UINT uCodePageExcept[20] = { + 42, // (Symbol) + 50220,50221,50222,50225,50227,50229, + 54936, // (GB18030) + 57002,57003,57004,57005,57006,57007,57008,57009,57010,57011, + 65000, // (UTF-7) + 65001 // (UTF-8) + }; + + UINT codepage = mEncoding[Encoding_Current(CPI_GET)].uCodePage; + + DWORD dwFlags = WC_NO_BEST_FIT_CHARS; + for (int i = 0; i < COUNTOF(uCodePageExcept); i++) { + if (codepage == uCodePageExcept[i]) { + dwFlags = 0; + break; + } + } + + BOOL bSuccess = TRUE; + BOOL bHasForeignChars = FALSE; + if ((codepage != CP_UTF7) && (codepage != CP_UTF8)) { + bSuccess = (BOOL)WideCharToMultiByte(codepage,dwFlags,pszText,cchLen,NULL,0,NULL,&bHasForeignChars); + } + + return (!bSuccess || bHasForeignChars); +} + //============================================================================= // // EditGetClipboardText() // -char* EditGetClipboardText(HWND hwnd) { + +static char Empty[2] = { '\0', '\0' }; + +char* EditGetClipboardText(HWND hwnd,BOOL bCheckEncoding) { HANDLE hmem; WCHAR *pwch; char *pmch; @@ -504,34 +568,32 @@ char* EditGetClipboardText(HWND hwnd) { int eolmode; if (!IsClipboardFormatAvailable(CF_UNICODETEXT) || !OpenClipboard(GetParent(hwnd))) - return(NULL); + return &Empty[0]; hmem = GetClipboardData(CF_UNICODETEXT); pwch = GlobalLock(hmem); wlen = lstrlenW(pwch); - // check for clipboard chars not in Current-Codepage and perform new encoding ... - codepage = mEncoding[Encoding_Current(CPI_GET)].uCodePage; - if (codepage < 50000U && codepage != 42) { - BOOL bHasForeignChars = FALSE; - int bSuccess = WideCharToMultiByte(codepage,WC_NO_BEST_FIT_CHARS,pwch,wlen + 2,NULL,0,NULL,&bHasForeignChars); - if (!bSuccess || bHasForeignChars) { - int iPos = (int)SendMessage(hwnd,SCI_GETCURRENTPOS,0,0); - int iAnchor = (int)SendMessage(hwnd,SCI_GETANCHOR,0,0); + if (bCheckEncoding && EditIsRecodingNeeded(pwch,wlen + 2)) + { + int iPos = (int)SendMessage(hwnd,SCI_GETCURRENTPOS,0,0); + int iAnchor = (int)SendMessage(hwnd,SCI_GETANCHOR,0,0); - SendMessage(hwndMain,WM_COMMAND,MAKELONG(IDM_ENCODING_UTF8,1),0); + // switch encoding to universal UTF-8 codepage + SendMessage(hwndMain,WM_COMMAND,(WPARAM)MAKELONG(IDM_ENCODING_UTF8,1),0); - if (iPos > iAnchor) { - SendMessage(hwndEdit,SCI_SETSEL,iAnchor,iPos); - } - else { - SendMessage(hwndEdit,SCI_SETSEL,iPos,iAnchor); - } - EditFixPositions(hwndEdit); + // restore and adjust selection + if (iPos > iAnchor) { + SendMessage(hwnd,SCI_SETSEL,(WPARAM)iAnchor,(LPARAM)iPos); + } + else { + SendMessage(hwnd,SCI_SETSEL,(WPARAM)iPos,(LPARAM)iAnchor); + } + EditFixPositions(hwnd); - if (Encoding_Current(CPI_GET) != CPI_UTF8) { - return(NULL); - } + // check expected recoding + if (Encoding_Current(CPI_GET) != CPI_UTF8) { + return (NULL); } } @@ -771,14 +833,15 @@ BOOL Encoding_HasChanged(int iOriginalEncoding) } -void Encoding_InitDefaults() { +void Encoding_InitDefaults() +{ mEncoding[CPI_ANSI_DEFAULT].uCodePage = GetACP(); StringCchPrintf(wchANSI,COUNTOF(wchANSI),L" (%u)",mEncoding[CPI_ANSI_DEFAULT].uCodePage); + mEncoding[CPI_OEM].uCodePage = GetOEMCP(); StringCchPrintf(wchOEM,COUNTOF(wchOEM),L" (%u)",mEncoding[CPI_OEM].uCodePage); g_DOSEncoding = CPI_OEM; - // Try to set the DOS encoding to DOS-437 if the default OEMCP is not DOS-437 if (mEncoding[g_DOSEncoding].uCodePage != 437) { @@ -1145,9 +1208,11 @@ int Encoding_SciMappedCodePage(int iEncoding) void Encoding_SciSetCodePage(HWND hwnd, int iEncoding) { - int charset = SC_CHARSET_ANSI; int cp = Encoding_SciMappedCodePage(iEncoding); - + SendMessage(hwnd,SCI_SETCODEPAGE,(WPARAM)cp,0); + // charsets can be changed via styles schema + /* + int charset = SC_CHARSET_ANSI; switch (cp) { case 932: charset = SC_CHARSET_SHIFTJIS; @@ -1165,8 +1230,8 @@ void Encoding_SciSetCodePage(HWND hwnd, int iEncoding) charset = iDefaultCharSet; break; } - SendMessage(hwnd,SCI_SETCODEPAGE,(WPARAM)cp,0); SendMessage(hwnd,SCI_STYLESETCHARACTERSET,(WPARAM)STYLE_DEFAULT,(LPARAM)charset); + */ } @@ -1488,7 +1553,7 @@ BOOL EditLoadFile( if (bLoadNFOasOEM) { PCWSTR pszExt = pszFile + StringCchLenN(pszFile,MAX_PATH) - 4; - if (pszExt >= pszFile && !(lstrcmpi(pszExt, L".nfo") && lstrcmpi(pszExt, L".diz"))) + if (pszExt >= pszFile && !(StringCchCompareIX(pszExt,L".nfo") && StringCchCompareIX(pszExt,L".diz"))) bPreferOEM = TRUE; } @@ -4790,17 +4855,17 @@ void EditSortLines(HWND hwnd,int iSortFlags) if (!bIsRectangular) { if (iAnchorPos > iCurPos) { iCurPos = iSelStart; - iAnchorPos = iSelStart + StringCchLenNA(pmszResult,lenRes); + iAnchorPos = iSelStart + _StringCchLenNA(pmszResult,lenRes); } else { iAnchorPos = iSelStart; - iCurPos = iSelStart + StringCchLenNA(pmszResult,lenRes); + iCurPos = iSelStart + _StringCchLenNA(pmszResult,lenRes); } } SendMessage(hwnd,SCI_SETTARGETSTART,(WPARAM)SendMessage(hwnd,SCI_POSITIONFROMLINE,(WPARAM)iLineStart,0),0); SendMessage(hwnd,SCI_SETTARGETEND,(WPARAM)SendMessage(hwnd,SCI_POSITIONFROMLINE,(WPARAM)iLineEnd+1,0),0); - SendMessage(hwnd,SCI_REPLACETARGET,(WPARAM)StringCchLenNA(pmszResult,lenRes),(LPARAM)pmszResult); + SendMessage(hwnd,SCI_REPLACETARGET,(WPARAM)_StringCchLenNA(pmszResult,lenRes),(LPARAM)pmszResult); SendMessage(hwnd,SCI_ENDUNDOACTION,0,0); LocalFree(pmszResult); @@ -5079,18 +5144,18 @@ INT_PTR CALLBACK EditFindReplaceDlgProcW(HWND hwnd,UINT umsg,WPARAM wParam,LPARA SendMessage(lpefr->hwnd,SCI_GETSELTEXT,0,(LPARAM)lpszSelection); // First time you bring up find/replace dialog, copy content from clipboard to find box (but only if nothing is selected in the editor) - if (lstrcmpA( lpszSelection , "" ) == 0 && bFirstTime ) + if (StringCchCompareNA(lpszSelection,cchSelection + 2,"",-1) == 0 && bFirstTime ) { - char *pClip = EditGetClipboardText(hwndEdit); - - int len = lstrlenA(pClip); - if( len > 0 && len < FNDRPL_BUFFER) - { + char* pClip = EditGetClipboardText(hwnd,FALSE); + if (pClip) { + int len = lstrlenA(pClip); + if (len > 0 && len < FNDRPL_BUFFER) { GlobalFree(lpszSelection); - lpszSelection = GlobalAlloc(GPTR,len+2); - StringCchCopyNA(lpszSelection,len+2,pClip,len); + lpszSelection = GlobalAlloc(GPTR,len + 2); + StringCchCopyNA(lpszSelection,len + 2,pClip,len); + } + LocalFree(pClip); } - LocalFree(pClip); } bFirstTime = FALSE; @@ -5736,25 +5801,26 @@ BOOL EditReplace(HWND hwnd,LPCEDITFINDREPLACE lpefr) if( lpefr->bWildcardSearch ) EscapeWildcards( szFind2 , lpefr ); - if (lstrcmpA(lpefr->szReplace,"^c") == 0) { + if (StringCchCompareNA(lpefr->szReplace,FNDRPL_BUFFER,"^c",-1) == 0) { iReplaceMsg = SCI_REPLACETARGET; - pszReplace2 = EditGetClipboardText(hwnd); + pszReplace2 = EditGetClipboardText(hwnd,TRUE); } else { //lstrcpyA(szReplace2,lpefr->szReplace); pszReplace2 = StrDupA(lpefr->szReplace); + if (!pszReplace2) + pszReplace2 = StrDupA(""); if (lpefr->bTransformBS) TransformBackslashes(pszReplace2,(lpefr->fuFlags & SCFIND_REGEXP),Encoding_SciGetCodePage(hwnd)); } if (!pszReplace2) - pszReplace2 = StrDupA(""); + return FALSE; // recoding canceled iSelStart = (int)SendMessage(hwnd,SCI_GETSELECTIONSTART,0,0); - iSelEnd = (int)SendMessage(hwnd,SCI_GETSELECTIONEND,0,0); + iSelEnd = (int)SendMessage(hwnd,SCI_GETSELECTIONEND,0,0); ZeroMemory(&ttf,sizeof(ttf)); - ttf.chrg.cpMin = (int)SendMessage(hwnd,SCI_GETSELECTIONSTART,0,0); // Start! ttf.chrg.cpMax = (int)SendMessage(hwnd,SCI_GETLENGTH,0,0); ttf.lpstrText = szFind2; @@ -5868,7 +5934,7 @@ void CompleteWord(HWND hwnd, BOOL autoInsert) { pRoot = LocalAlloc(LPTR,cnt); StringCchCopyNA(pRoot,cnt,pLine + iStartWordPos,cnt-1); LocalFree(pLine); - iRootLen = StringCchLenNA(pRoot,cnt); + iRootLen = _StringCchLenNA(pRoot,cnt); iDocLen = (int)SendMessage(hwnd, SCI_GETLENGTH, 0, 0); @@ -5900,8 +5966,8 @@ void CompleteWord(HWND hwnd, BOOL autoInsert) { SendMessage(hwnd, SCI_GETTEXTRANGE, 0, (LPARAM)&tr); while(p) { - int cmp = lstrcmpA(pWord, p->word); - if (!cmp) { + int cmp = StringCchCompareNA(pWord,wordLength + 2, p->word,-1); + if (cmp == 0) { found = TRUE; break; } else if (cmp < 0) { @@ -5922,7 +5988,7 @@ void CompleteWord(HWND hwnd, BOOL autoInsert) { } iNumWords++; - iWListSize += StringCchLenNA(pWord,wordLength + 2) + 1; + iWListSize += _StringCchLenNA(pWord,wordLength + 2) + 1; } LocalFree(pWord); } @@ -5972,7 +6038,6 @@ void EditMarkAll(HWND hwnd, int iMarkOccurrences, BOOL bMarkOccurrencesMatchCase int iSelEnd; int iSelLength; int iSelCount; - int iMatchesCount; // feature is off if (!iMarkOccurrences) @@ -6029,11 +6094,11 @@ void EditMarkAll(HWND hwnd, int iMarkOccurrences, BOOL bMarkOccurrencesMatchCase SendMessage(hwnd, SCI_INDICSETFORE, 1, 0xff << ((iMarkOccurrences - 1) << 3)); SendMessage(hwnd, SCI_INDICSETSTYLE, 1, INDIC_ROUNDBOX); - iMatchesCount = 0; + int iMatchesCount = 0; while ((iPos = (int)SendMessage(hwnd, SCI_FINDTEXT, (bMarkOccurrencesMatchCase ? SCFIND_MATCHCASE : 0) | (bMarkOccurrencesMatchWords ? SCFIND_WHOLEWORD : 0), (LPARAM)&ttf)) != -1 - && ++iMatchesCount < 2000) + && ++iMatchesCount < iMarkOccurrencesMaxCount) { // mark this match SendMessage(hwnd, SCI_INDICATORFILLRANGE, iPos, iSelCount); @@ -6085,24 +6150,27 @@ BOOL EditReplaceAll(HWND hwnd,LPCEDITFINDREPLACE lpefr,BOOL bShowInfo) (szFind2[0] == '^'); bRegexStartOrEndOfLine = (lpefr->fuFlags & SCFIND_REGEXP && - (!lstrcmpA(szFind2,"$") || !lstrcmpA(szFind2,"^") || !lstrcmpA(szFind2,"^$"))); + (!StringCchCompareNA(szFind2,FNDRPL_BUFFER,"$",-1) || + !StringCchCompareNA(szFind2,FNDRPL_BUFFER,"^",-1) || + !StringCchCompareNA(szFind2,FNDRPL_BUFFER,"^$",-1))); - if (lstrcmpA(lpefr->szReplace,"^c") == 0) { + if (StringCchCompareNA(lpefr->szReplace,FNDRPL_BUFFER,"^c",-1) == 0) { iReplaceMsg = SCI_REPLACETARGET; - pszReplace2 = EditGetClipboardText(hwnd); + pszReplace2 = EditGetClipboardText(hwnd,TRUE); } else { //lstrcpyA(szReplace2,lpefr->szReplace); pszReplace2 = StrDupA(lpefr->szReplace); + if (!pszReplace2) + pszReplace2 = StrDupA(""); if (lpefr->bTransformBS) TransformBackslashes(pszReplace2,(lpefr->fuFlags & SCFIND_REGEXP),Encoding_SciGetCodePage(hwnd)); } if (!pszReplace2) - pszReplace2 = StrDupA(""); + return FALSE; // recoding canceled ZeroMemory(&ttf,sizeof(ttf)); - ttf.chrg.cpMin = 0; ttf.chrg.cpMax = (int)SendMessage(hwnd,SCI_GETLENGTH,0,0); ttf.lpstrText = szFind2; @@ -6211,24 +6279,27 @@ BOOL EditReplaceAllInSelection(HWND hwnd,LPCEDITFINDREPLACE lpefr,BOOL bShowInfo bRegexStartOfLine = (szFind2[0] == '^'); bRegexStartOrEndOfLine = (lpefr->fuFlags & SCFIND_REGEXP && - (!lstrcmpA(szFind2,"$") || !lstrcmpA(szFind2,"^") || !lstrcmpA(szFind2,"^$"))); + (!StringCchCompareNA(szFind2,FNDRPL_BUFFER,"$",-1) || + !StringCchCompareNA(szFind2,FNDRPL_BUFFER,"^",-1) || + !StringCchCompareNA(szFind2,FNDRPL_BUFFER,"^$",-1))); - if (lstrcmpA(lpefr->szReplace,"^c") == 0) { + if (StringCchCompareNA(lpefr->szReplace,FNDRPL_BUFFER,"^c",-1) == 0) { iReplaceMsg = SCI_REPLACETARGET; - pszReplace2 = EditGetClipboardText(hwnd); + pszReplace2 = EditGetClipboardText(hwnd,TRUE); } else { //lstrcpyA(szReplace2,lpefr->szReplace); pszReplace2 = StrDupA(lpefr->szReplace); + if (!pszReplace2) + pszReplace2 = StrDupA(""); if (lpefr->bTransformBS) TransformBackslashes(pszReplace2,(lpefr->fuFlags & SCFIND_REGEXP),Encoding_SciGetCodePage(hwnd)); } if (!pszReplace2) - pszReplace2 = StrDupA(""); + return FALSE; // recoding canceled ZeroMemory(&ttf,sizeof(ttf)); - ttf.chrg.cpMin = (int)SendMessage(hwnd,SCI_GETSELECTIONSTART,0,0); ttf.chrg.cpMax = (int)SendMessage(hwnd,SCI_GETLENGTH,0,0); ttf.lpstrText = szFind2; @@ -6854,15 +6925,15 @@ INT_PTR CALLBACK EditInsertTagDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM l wchIns[cchIns] = L'\0'; if (cchIns > 3 && - lstrcmpi(wchIns,L"") && - lstrcmpi(wchIns,L"") && - lstrcmpi(wchIns,L"
") && - lstrcmpi(wchIns,L"") && - lstrcmpi(wchIns,L"") && - lstrcmpi(wchIns,L"") && - lstrcmpi(wchIns,L"") && - lstrcmpi(wchIns,L"") && - lstrcmpi(wchIns,L"")) { + StringCchCompareIN(wchIns,COUNTOF(wchIns),L"",-1) && + StringCchCompareIN(wchIns,COUNTOF(wchIns),L"",-1) && + StringCchCompareIN(wchIns,COUNTOF(wchIns),L"
",-1) && + StringCchCompareIN(wchIns,COUNTOF(wchIns),L"",-1) && + StringCchCompareIN(wchIns,COUNTOF(wchIns),L"",-1) && + StringCchCompareIN(wchIns,COUNTOF(wchIns),L"",-1) && + StringCchCompareIN(wchIns,COUNTOF(wchIns),L"",-1) && + StringCchCompareIN(wchIns,COUNTOF(wchIns),L"",-1) && + StringCchCompareIN(wchIns,COUNTOF(wchIns),L"",-1)) { SetDlgItemTextW(hwnd,101,wchIns); bClear = FALSE; @@ -7383,8 +7454,8 @@ BOOL FileVars_ParseStr(char* pszData,char* pszName,char* pszValue,int cchValue) // BOOL FileVars_IsUTF8(LPFILEVARS lpfv) { if (lpfv->mask & FV_ENCODING) { - if (lstrcmpiA(lpfv->tchEncoding,"utf-8") == 0 || - lstrcmpiA(lpfv->tchEncoding,"utf8") == 0) + if (StringCchCompareINA(lpfv->tchEncoding,COUNTOF(lpfv->tchEncoding),"utf-8",-1) == 0 || + StringCchCompareINA(lpfv->tchEncoding,COUNTOF(lpfv->tchEncoding),"utf8",-1) == 0) return(TRUE); } return(FALSE); @@ -7398,8 +7469,8 @@ BOOL FileVars_IsUTF8(LPFILEVARS lpfv) { BOOL FileVars_IsNonUTF8(LPFILEVARS lpfv) { if (lpfv->mask & FV_ENCODING) { if (StringCchLenA(lpfv->tchEncoding) && - lstrcmpiA(lpfv->tchEncoding,"utf-8") != 0 && - lstrcmpiA(lpfv->tchEncoding,"utf8") != 0) + StringCchCompareINA(lpfv->tchEncoding,COUNTOF(lpfv->tchEncoding),"utf-8",-1) != 0 && + StringCchCompareINA(lpfv->tchEncoding,COUNTOF(lpfv->tchEncoding),"utf8",-1) != 0) return(TRUE); } return(FALSE); diff --git a/src/Edit.h b/src/Edit.h index a2bab3198..d439037b7 100644 --- a/src/Edit.h +++ b/src/Edit.h @@ -44,34 +44,13 @@ typedef struct _editfindreplace #define IDMSG_SWITCHTOFIND 300 #define IDMSG_SWITCHTOREPLACE 301 -enum AlignMask -{ - ALIGN_LEFT = 0, - ALIGN_RIGHT = 1, - ALIGN_CENTER = 2, - ALIGN_JUSTIFY = 3, - ALIGN_JUSTIFY_EX = 4 -}; - -enum SortOrderMask -{ - SORT_ASCENDING = 0, - SORT_DESCENDING = 1, - SORT_SHUFFLE = 2, - SORT_MERGEDUP = 4, - SORT_UNIQDUP = 8, - SORT_UNIQUNIQ = 16, - SORT_NOCASE = 32, - SORT_LOGICAL = 64, - SORT_COLUMN = 128 -}; - HWND EditCreate(HWND); void EditInitWordDelimiter(HWND); void EditSetNewText(HWND,char*,DWORD); BOOL EditConvertText(HWND,int,int,BOOL); BOOL EditSetNewEncoding(HWND,int,int,BOOL,BOOL); -char* EditGetClipboardText(HWND); +BOOL EditIsRecodingNeeded(WCHAR*,int); +char* EditGetClipboardText(HWND,BOOL); BOOL EditCopyAppend(HWND); int EditDetectEOLMode(HWND,char*,DWORD); BOOL EditLoadFile(HWND,LPCWSTR,BOOL,int*,int*,BOOL*,BOOL*); diff --git a/src/Helpers.c b/src/Helpers.c index fdea29efc..631041434 100644 --- a/src/Helpers.c +++ b/src/Helpers.c @@ -15,9 +15,17 @@ * * *******************************************************************************/ +#if !defined(WINVER) +#define WINVER 0x601 /*_WIN32_WINNT_WIN7*/ +#endif #if !defined(_WIN32_WINNT) -#define _WIN32_WINNT 0x501 +#define _WIN32_WINNT 0x601 /*_WIN32_WINNT_WIN7*/ +#endif +#if !defined(NTDDI_VERSION) +#define NTDDI_VERSION 0x06010000 /*NTDDI_WIN7*/ #endif +#define VC_EXTRALEAN 1 + #include #include #include @@ -172,7 +180,7 @@ HRESULT PrivateSetCurrentProcessExplicitAppUserModelID(PCWSTR AppID) if (lstrlen(AppID) == 0) return(S_OK); - if (lstrcmpi(AppID,L"(default)") == 0) + if (StringCchCompareIX(AppID,L"(default)") == 0) return(S_OK); pfnSetCurrentProcessExplicitAppUserModelID = @@ -422,7 +430,7 @@ BOOL SetWindowTitle(HWND hwnd,UINT uIDAppName,BOOL bIsElevated,UINT uIDUntitled, { if (iFormat < 2 && !PathIsRoot(lpszFile)) { - if (lstrcmp(szCachedFile,lpszFile) != 0) { + if (StringCchCompareN(szCachedFile,COUNTOF(szCachedFile),lpszFile,MAX_PATH) != 0) { SHFILEINFO shfi; StringCchCopy(szCachedFile,COUNTOF(szCachedFile),lpszFile); if (SHGetFileInfo2(lpszFile,0,&shfi,sizeof(SHFILEINFO),SHGFI_DISPLAYNAME)) @@ -1062,44 +1070,22 @@ void PathAbsoluteFromApp(LPWSTR lpszSrc,LPWSTR lpszDest,int cchDest,BOOL bExpand // // Name: PathIsLnkFile() // -// Purpose: Determine wheter pszPath is a Windows Shell Link File by +// Purpose: Determine whether pszPath is a Windows Shell Link File by // comparing the filename extension with L".lnk" // // Manipulates: // BOOL PathIsLnkFile(LPCWSTR pszPath) { - - //WCHAR *pszExt; - - WCHAR tchResPath[256] = { L'\0' }; + WCHAR tchResPath[MAX_PATH] = { L'\0' }; if (!pszPath || !*pszPath) return FALSE; -/*pszExt = StrRChr(pszPath,NULL,L'.'); - - if (!pszExt) + if (StringCchCompareIX(PathFindExtension(pszPath),L".lnk")) return FALSE; - - if (!lstrcmpi(pszExt,L".lnk")) - return TRUE; - - else - return FALSE;*/ - - //if (!lstrcmpi(PathFindExtension(pszPath),L".lnk")) - // return TRUE; - - //else - // return FALSE; - - if (lstrcmpi(PathFindExtension(pszPath),L".lnk")) - return FALSE; - else return PathGetLnkPath(pszPath,tchResPath,COUNTOF(tchResPath)); - } @@ -1385,6 +1371,7 @@ BOOL ExtractFirstArgument(LPCWSTR lpArgs,LPWSTR lpArg1,LPWSTR lpArg2,int len) BOOL bQuoted = FALSE; StringCchCopy(lpArg1,len,lpArgs); + if (lpArg2) *lpArg2 = L'\0'; @@ -1401,7 +1388,7 @@ BOOL ExtractFirstArgument(LPCWSTR lpArgs,LPWSTR lpArg1,LPWSTR lpArg2,int len) if (bQuoted) psz = StrChr(lpArg1,L'\"'); else - psz = StrChr(lpArg1,L' ');; + psz = StrChr(lpArg1,L' '); if (psz) { @@ -1490,7 +1477,6 @@ void ExpandEnvironmentStringsEx(LPWSTR lpSrc,DWORD dwSrc) void PathCanonicalizeEx(LPWSTR lpszPath,int len) { WCHAR szDst[FILE_ARG_BUF] = { L'\0' }; - if (PathCanonicalize(szDst,lpszPath)) StringCchCopy(lpszPath,len,szDst); } @@ -1521,7 +1507,7 @@ DWORD GetLongPathNameEx(LPWSTR lpszPath,DWORD cchBuffer) DWORD NormalizePathEx(LPWSTR lpszPath,int len) { PathCanonicalizeEx(lpszPath,len); - return GetLongPathNameEx(lpszPath,len); + return GetLongPathNameEx(lpszPath,(DWORD)len); } @@ -1674,8 +1660,8 @@ LPMRULIST MRU_Create(LPCWSTR pszRegKey,int iFlags,int iSize) { return(pmru); } -BOOL MRU_Destroy(LPMRULIST pmru) { - +BOOL MRU_Destroy(LPMRULIST pmru) +{ int i; for (i = 0; i < pmru->iSize; i++) { if (pmru->pszItems[i]) @@ -1686,16 +1672,16 @@ BOOL MRU_Destroy(LPMRULIST pmru) { return(1); } -int MRU_Compare(LPMRULIST pmru,LPCWSTR psz1,LPCWSTR psz2) { - +int MRU_Compare(LPMRULIST pmru,LPCWSTR psz1,LPCWSTR psz2) +{ if (pmru->iFlags & MRU_NOCASE) - return(lstrcmpi(psz1,psz2)); + return(StringCchCompareIX(psz1,psz2)); else - return(lstrcmp(psz1,psz2)); + return(StringCchCompareX(psz1,psz2)); } -BOOL MRU_Add(LPMRULIST pmru,LPCWSTR pszNew) { - +BOOL MRU_Add(LPMRULIST pmru,LPCWSTR pszNew) +{ int i; for (i = 0; i < pmru->iSize; i++) { if (MRU_Compare(pmru,pmru->pszItems[i],pszNew) == 0) { @@ -1714,17 +1700,17 @@ BOOL MRU_AddFile(LPMRULIST pmru,LPCWSTR pszFile,BOOL bRelativePath,BOOL bUnexpan int i; for (i = 0; i < pmru->iSize; i++) { - if (lstrcmpi(pmru->pszItems[i],pszFile) == 0) { - LocalFree(pmru->pszItems[i]); + if (pmru->pszItems[i] == NULL) { break; } - else if (pmru->pszItems[i] == NULL) { + else if (StringCchCompareIX(pmru->pszItems[i],pszFile) == 0) { + LocalFree(pmru->pszItems[i]); break; } else { WCHAR wchItem[MAX_PATH] = { L'\0' }; PathAbsoluteFromApp(pmru->pszItems[i],wchItem,COUNTOF(wchItem),TRUE); - if (lstrcmpi(wchItem,pszFile) == 0) { + if (StringCchCompareIN(wchItem,COUNTOF(wchItem),pszFile,-1) == 0) { LocalFree(pmru->pszItems[i]); break; } @@ -1770,7 +1756,7 @@ BOOL MRU_DeleteFileFromStore(LPMRULIST pmru,LPCWSTR pszFile) { while (MRU_Enum(pmruStore,i,wchItem,COUNTOF(wchItem)) != -1) { PathAbsoluteFromApp(wchItem,wchItem,COUNTOF(wchItem),TRUE); - if (lstrcmpi(wchItem,pszFile) == 0) + if (StringCchCompareIN(wchItem,COUNTOF(wchItem),pszFile,-1) == 0) MRU_Delete(pmruStore,i); else i++; diff --git a/src/Helpers.h b/src/Helpers.h index a74294396..1144adbcd 100644 --- a/src/Helpers.h +++ b/src/Helpers.h @@ -260,20 +260,70 @@ VOID MinimizeWndToTray(HWND hWnd); VOID RestoreWndFromTray(HWND hWnd); -//==== StrSafe strlen() ======================================================= -inline int StringCchLenNA(LPCSTR s,size_t n) { size_t len; HRESULT hr = StringCchLengthA(s,n,&len); return (SUCCEEDED(hr) ? (int)len : 0); } -#define StringCchLenA(s) StringCchLenNA((s),COUNTOF(s)) -inline int StringCchLenNW(LPCWSTR s, size_t n) { size_t len; HRESULT hr = StringCchLengthW(s,n,&len); return (SUCCEEDED(hr) ? (int)len : 0); } -#define StringCchLenW(s) StringCchLenNW((s),COUNTOF(s)) +//==== StrSafe lstrlen() ======================================================= +inline int _StringCchLenNA(LPCSTR s,size_t n) { size_t len; HRESULT hr = StringCchLengthA(s,n,&len); return (SUCCEEDED(hr) ? (int)len : 0); } +#define StringCchLenA(s) _StringCchLenNA((s),COUNTOF(s)) +inline int _StringCchLenNW(LPCWSTR s,size_t n) { size_t len; HRESULT hr = StringCchLengthW(s,n,&len); return (SUCCEEDED(hr) ? (int)len : 0); } +#define StringCchLenW(s) _StringCchLenNW((s),COUNTOF(s)) #if defined(UNICODE) || defined(_UNICODE) -#define StringCchLen(s) StringCchLenNW((s),COUNTOF(s)) -#define StringCchLenN(s,n) StringCchLenNW((s),(n)) +#define StringCchLen(s) _StringCchLenNW((s),COUNTOF(s)) +#define StringCchLenN(s,n) _StringCchLenNW((s),(n)) #else -#define StringCchLen(s) StringCchLenNA((s),COUNTOF(s)) -#define StringCchLenN(s,n) StringCchLenNA((s),(n)) +#define StringCchLen(s) _StringCchLenNA((s),COUNTOF(s)) +#define StringCchLenN(s,n) _StringCchLenNA((s),(n)) #endif +//==== StrSafe lstrcmp(),lstrcmpi() ============================================= +inline int _StringCchCmpNA(PCNZCH s1,int l1,PCNZCH s2,int l2) +{ + return (CompareStringA(LOCALE_INVARIANT,0,s1,(l1 >= 0 ? _StringCchLenNA(s1,l1) : -1), + s2,(l2 >= 0 ? _StringCchLenNA(s2,l2) : -1)) - CSTR_EQUAL); +} +#define StringCchCompareA(s1,s2) _StringCchCmpNA((s1),COUNTOF(s1),(s2),COUNTOF(s2)) +#define StringCchCompareNA(s1,l1,s2,l2) _StringCchCmpNA((s1),(l1),(s2),(l2)) +#define StringCchCompareXA(s1,s2) _StringCchCmpNA((s1),-1,(s2),-1) + +inline int _StringCchCmpINA(PCNZCH s1,int l1,PCNZCH s2,int l2) +{ + return (CompareStringA(LOCALE_INVARIANT,NORM_IGNORECASE,s1,(l1 >= 0 ? _StringCchLenNA(s1,l1) : -1), + s2,(l2 >= 0 ? _StringCchLenNA(s2,l2) : -1)) - CSTR_EQUAL); +} +#define StringCchCompareIA(s1,s2) _StringCchCmpINA((s1),COUNTOF(s1),(s2),COUNTOF(s2)) +#define StringCchCompareINA(s1,l1,s2,l2) _StringCchCmpINA((s1),(l1),(s2),(l2)) +#define StringCchCompareIXA(s1,s2) _StringCchCmpINA((s1),-1,(s2),-1) + +inline int _StringCchCmpNW(PCNZWCH s1,int l1,PCNZWCH s2,int l2) { + return (CompareStringW(LOCALE_INVARIANT,0,s1,(l1 >= 0 ? _StringCchLenNW(s1,l1) : -1), + s2,(l2 >= 0 ? _StringCchLenNW(s2,l2) : -1)) - CSTR_EQUAL); +} +#define StringCchCompareW(s1,s2) _StringCchCmpNW((s1),COUNTOF(s1),(s2),COUNTOF(s2)) +#define StringCchCompareNW(s1,l1,s2,l2) _StringCchCmpNW((s1),(l1),(s2),(l2)) +#define StringCchCompareXW(s1,s2) _StringCchCmpNW((s1),-1,(s2),-1) + +inline int _StringCchCmpINW(PCNZWCH s1,int l1,PCNZWCH s2,int l2) { + return (CompareStringW(LOCALE_INVARIANT,NORM_IGNORECASE,s1,(l1 >= 0 ? _StringCchLenNW(s1,l1) : -1), + s2,(l2 >= 0 ? _StringCchLenNW(s2,l2) : -1)) - CSTR_EQUAL); +} +#define StringCchCompareIW(s1,s2) _StringCchCmpINW((s1),COUNTOF(s1),(s2),COUNTOF(s2)) +#define StringCchCompareINW(s1,l1,s2,l2) _StringCchCmpINW((s1),(l1),(s2),(l2)) +#define StringCchCompareIXW(s1,s2) _StringCchCmpINW((s1),-1,(s2),-1) + +#if defined(UNICODE) || defined(_UNICODE) +#define StringCchCompare(s1,s2) StringCchCompareW((s1),(s2)) +#define StringCchCompareN(s1,l1,s2,l2) StringCchCompareNW((s1),(l1),(s2),(l2)) +#define StringCchCompareX(s1,s2) StringCchCompareXW((s1),(s2)) +#define StringCchCompareI(s1,s2) StringCchCompareIW((s1),(s2)) +#define StringCchCompareIN(s1,l1,s2,l2) StringCchCompareINW((s1),(l1),(s2),(l2)) +#define StringCchCompareIX(s1,s2) StringCchCompareIXW((s1),(s2)) +#else +#define StringCchCompare(s1,s2) StringCchCompareA((s1),(s2)) +#define StringCchCompareN(s1,l1,s2,l2) StringCchCompareNA((s1),(l1),(s2),(l2)) +#define StringCchCompareX(s1,s2) StringCchCompareXA((s1),(s2)) +#define StringCchCompareI(s1,s2) StringCchCompareIA((s1),(s2)) +#define StringCchCompareIN(s1,l1,s2,l2) StringCchCompareINA((s1),(l1),(s2),(l2)) +#define StringCchCompareIX(s1,s2) StringCchCompareIXA((s1),(s2)) +#endif #endif //_NP3_HELPERS_H_ diff --git a/src/Notepad3.c b/src/Notepad3.c index 0b1c90f9e..d1db9c675 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -13,13 +13,17 @@ * * *******************************************************************************/ +#if !defined(WINVER) +#define WINVER 0x601 /*_WIN32_WINNT_WIN7*/ +#endif #if !defined(_WIN32_WINNT) -#define _WIN32_WINNT 0x501 /*_WIN32_WINNT_WINXP*/ +#define _WIN32_WINNT 0x601 /*_WIN32_WINNT_WIN7*/ #endif - #if !defined(NTDDI_VERSION) -#define NTDDI_VERSION 0x05010100 /*NTDDI_WINXPSP1*/ +#define NTDDI_VERSION 0x06010000 /*NTDDI_WIN7*/ #endif +#define VC_EXTRALEAN 1 +#define WIN32_LEAN_AND_MEAN 1 #include #include @@ -97,6 +101,7 @@ TBBUTTON tbbMainWnd[] = { {0,IDT_FILE_NEW,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0}, WCHAR szIniFile[MAX_PATH] = { L'\0' }; WCHAR szIniFile2[MAX_PATH] = { L'\0' }; +WCHAR szBufferFile[MAX_PATH] = { L'\0' }; BOOL bSaveSettings; BOOL bEnableSaveSettings; BOOL bSaveRecentFiles; @@ -141,6 +146,7 @@ int iWrapCol = 0; BOOL bShowSelectionMargin; BOOL bShowLineNumbers; int iMarkOccurrences; +int iMarkOccurrencesMaxCount; BOOL bMarkOccurrencesMatchCase; BOOL bMarkOccurrencesMatchWords; BOOL bAutoCompleteWords; @@ -291,7 +297,7 @@ WCHAR wchWndClass[16] = WC_NOTEPAD3; HINSTANCE g_hInstance; HANDLE g_hScintilla; WCHAR g_wchAppUserModelID[32] = { L'\0' }; -WCHAR g_wchWorkingDirectory[MAX_PATH] = { L'\0' }; +WCHAR g_wchWorkingDirectory[MAX_PATH+2] = { L'\0' }; // undo / redo selections @@ -393,7 +399,7 @@ int flagUseSystemMRU = 0; int flagRelaunchElevated = 0; int flagDisplayHelp = 0; int flagPrintFileAndLeave = 0; - +int flagBufferFile = 0; //============================================================================== @@ -595,16 +601,21 @@ int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,LPSTR lpCmdLine,int n HACCEL hAccFindReplace; INITCOMMONCONTROLSEX icex; //HMODULE hSciLexer; - WCHAR wchWorkingDirectory[MAX_PATH] = { L'\0' }; + WCHAR wchAppDir[2*MAX_PATH+4] = { L'\0' }; // Set global variable g_hInstance g_hInstance = hInstance; + GetModuleFileName(NULL,wchAppDir,COUNTOF(wchAppDir)); + PathRemoveFileSpec(wchAppDir); + PathCanonicalizeEx(wchAppDir,COUNTOF(wchAppDir)); + + if (!GetCurrentDirectory(COUNTOF(g_wchWorkingDirectory),g_wchWorkingDirectory)) { + StringCchCopy(g_wchWorkingDirectory,COUNTOF(g_wchWorkingDirectory),wchAppDir); + } + // Don't keep working directory locked - GetCurrentDirectory(COUNTOF(g_wchWorkingDirectory),g_wchWorkingDirectory); - GetModuleFileName(NULL,wchWorkingDirectory,COUNTOF(wchWorkingDirectory)); - PathRemoveFileSpec(wchWorkingDirectory); - SetCurrentDirectory(wchWorkingDirectory); + SetCurrentDirectory(wchAppDir); SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOOPENFILEERRORBOX); @@ -655,7 +666,7 @@ int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,LPSTR lpCmdLine,int n StringCchCat(wchWndClass,COUNTOF(wchWndClass),L"B"); // Relaunch with elevated privileges - if (RelaunchElevated()) + if (RelaunchElevated(NULL)) return(0); // Try to run multiple instances @@ -887,19 +898,38 @@ HWND InitInstance(HINSTANCE hInstance,LPSTR pszCmdLine,int nCmdShow) Encoding_Source(Encoding_MatchW(lpEncodingArg)); // Pathname parameter - if (lpFileArg /*&& !flagNewFromClipboard*/) + if (flagBufferFile || (lpFileArg /*&& !flagNewFromClipboard*/)) { BOOL bOpened = FALSE; // Open from Directory - if (PathIsDirectory(lpFileArg)) { + if (!flagBufferFile && PathIsDirectory(lpFileArg)) { WCHAR tchFile[MAX_PATH] = { L'\0' }; if (OpenFileDlg(hwndMain,tchFile,COUNTOF(tchFile),lpFileArg)) bOpened = FileLoad(FALSE,FALSE,FALSE,FALSE,tchFile); } else { - bOpened = FileLoad(FALSE, FALSE, FALSE, FALSE, lpFileArg); + LPCWSTR lpFileToOpen = flagBufferFile ? szBufferFile : lpFileArg; + bOpened = FileLoad(FALSE,FALSE,FALSE,FALSE,lpFileToOpen); if (bOpened) { + if (flagBufferFile) { + if (lpFileArg) { + InstallFileWatching(NULL); // Terminate file watching + StringCchCopy(szCurFile,COUNTOF(szCurFile),lpFileArg); + InstallFileWatching(szCurFile); + } + if (!flagLexerSpecified) + Style_SetLexerFromFile(hwndEdit,szCurFile); + bModified = TRUE; + if (lpFileArg) + SetWindowTitle(hwndMain,uidsAppTitle,fIsElevated,IDS_UNTITLED,lpFileArg, + iPathNameFormat,bModified,IDS_READONLY,bReadOnly,szTitleExcerpt); + + // check for temp file and delete + if (fIsElevated && PathFileExists(szBufferFile)) { + DeleteFile(szBufferFile); + } + } if (flagJumpTo) { // Jump to position EditJumpTo(hwndEdit,iInitialLine,iInitialColumn); EditEnsureSelectionVisible(hwndEdit); @@ -921,7 +951,6 @@ HWND InitInstance(HINSTANCE hInstance,LPSTR pszCmdLine,int nCmdShow) } } } - else { if (Encoding_Source(CPI_GET) != CPI_NONE) { Encoding_Current(Encoding_Source(CPI_GET)); @@ -1484,9 +1513,9 @@ LRESULT CALLBACK MainWndProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lParam) } else if (SendMessage(hwndEdit,SCI_GETLENGTH,0,0) >= 4) { - char tch[5] = ""; + char tch[5] = { '\0' }; SendMessage(hwndEdit,SCI_GETTEXT,5,(LPARAM)tch); - if (lstrcmpiA(tch,".LOG") != 0) { + if (StringCchCompareXA(tch,".LOG") != 0) { int iNewTopLine; SendMessage(hwndEdit,SCI_SETSEL,iAnchorPos,iCurPos); SendMessage(hwndEdit,SCI_ENSUREVISIBLE,(WPARAM)iDocTopLine,0); @@ -2425,9 +2454,9 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) if (FileLoad(TRUE,FALSE,TRUE,FALSE,tchCurFile2)) { if (SendMessage(hwndEdit,SCI_GETLENGTH,0,0) >= 4) { - char tch[5] = ""; + char tch[5] = { '\0' }; SendMessage(hwndEdit,SCI_GETTEXT,5,(LPARAM)tch); - if (lstrcmpiA(tch,".LOG") != 0) { + if (StringCchCompareXA(tch,".LOG") != 0) { int iNewTopLine; SendMessage(hwndEdit,SCI_SETSEL,iAnchorPos,iCurPos); SendMessage(hwndEdit,SCI_ENSUREVISIBLE,(WPARAM)iDocTopLine,0); @@ -2521,7 +2550,8 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) StringCchCat(tchParam,COUNTOF(tchParam),tchTemp); } - SHELLEXECUTEINFO sei = { 0 }; + SHELLEXECUTEINFO sei; + ZeroMemory(&sei,sizeof(SHELLEXECUTEINFO)); sei.cbSize = sizeof(SHELLEXECUTEINFO); sei.fMask = SEE_MASK_FLAG_NO_UI | SEE_MASK_NOZONECHECKS; sei.hwnd = hwnd; @@ -2530,7 +2560,7 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) sei.lpParameters = tchParam; sei.lpDirectory = NULL; sei.nShow = SW_SHOWNORMAL; - + CoInitializeEx(NULL,COINIT_APARTMENTTHREADED | COINIT_SPEED_OVER_MEMORY); ShellExecuteEx(&sei); if ((INT_PTR)sei.hInstApp < 32) @@ -2605,7 +2635,8 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) StringCchCat(szParameters,COUNTOF(szParameters),szFileName); } - SHELLEXECUTEINFO sei = { 0 }; + SHELLEXECUTEINFO sei; + ZeroMemory(&sei,sizeof(SHELLEXECUTEINFO)); sei.cbSize = sizeof(SHELLEXECUTEINFO); sei.fMask = SEE_MASK_NOASYNC | SEE_MASK_NOZONECHECKS; sei.hwnd = hwnd; @@ -2635,7 +2666,8 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) PathRemoveFileSpec(wchDirectory); } - SHELLEXECUTEINFO sei = { 0 }; + SHELLEXECUTEINFO sei; + ZeroMemory(&sei,sizeof(SHELLEXECUTEINFO)); sei.cbSize = sizeof(SHELLEXECUTEINFO); sei.fMask = 0; sei.hwnd = hwnd; @@ -2644,7 +2676,7 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) sei.lpParameters = NULL; sei.lpDirectory = wchDirectory; sei.nShow = SW_SHOWNORMAL; - + CoInitializeEx(NULL,COINIT_APARTMENTTHREADED | COINIT_SPEED_OVER_MEMORY); ShellExecuteEx(&sei); } break; @@ -2705,14 +2737,15 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) if (StringCchLen(szCurFile) == 0) break; - SHELLEXECUTEINFO sei = { 0 }; + SHELLEXECUTEINFO sei; + ZeroMemory(&sei,sizeof(SHELLEXECUTEINFO)); sei.cbSize = sizeof(SHELLEXECUTEINFO); sei.fMask = SEE_MASK_INVOKEIDLIST; sei.hwnd = hwnd; sei.lpVerb = L"properties"; sei.lpFile = szCurFile; sei.nShow = SW_SHOWNORMAL; - + CoInitializeEx(NULL,COINIT_APARTMENTTHREADED | COINIT_SPEED_OVER_MEMORY); ShellExecuteEx(&sei); } break; @@ -2763,7 +2796,8 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) case IDM_FILE_MANAGEFAV: { - SHELLEXECUTEINFO sei = { 0 }; + SHELLEXECUTEINFO sei; + ZeroMemory(&sei,sizeof(SHELLEXECUTEINFO)); sei.cbSize = sizeof(SHELLEXECUTEINFO); sei.fMask = 0; sei.hwnd = hwnd; @@ -2772,8 +2806,8 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) sei.lpParameters = NULL; sei.lpDirectory = NULL; sei.nShow = SW_SHOWNORMAL; - // Run favorites directory + CoInitializeEx(NULL,COINIT_APARTMENTTHREADED | COINIT_SPEED_OVER_MEMORY); ShellExecuteEx(&sei); } break; @@ -2964,7 +2998,9 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) bSwapClipBoard = TRUE; case IDM_EDIT_PASTE: { - char *pClip = EditGetClipboardText(hwndEdit); + char *pClip = EditGetClipboardText(hwndEdit,TRUE); + if (!pClip) + break; // recoding canceled int iPos = (int)SendMessage(hwndEdit,SCI_GETCURRENTPOS,0,0); int iAnchor = (int)SendMessage(hwndEdit,SCI_GETANCHOR,0,0); @@ -4854,7 +4890,8 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) PathRemoveFileSpec(wchDirectory); } - SHELLEXECUTEINFO sei = { 0 }; + SHELLEXECUTEINFO sei; + ZeroMemory(&sei,sizeof(SHELLEXECUTEINFO)); sei.cbSize = sizeof(SHELLEXECUTEINFO); sei.fMask = SEE_MASK_NOZONECHECKS; sei.hwnd = NULL; @@ -4863,7 +4900,7 @@ LRESULT MsgCommand(HWND hwnd,WPARAM wParam,LPARAM lParam) sei.lpParameters = lpszArgs; sei.lpDirectory = wchDirectory; sei.nShow = SW_SHOWNORMAL; - + CoInitializeEx(NULL,COINIT_APARTMENTTHREADED | COINIT_SPEED_OVER_MEMORY); ShellExecuteEx(&sei); GlobalFree(lpszCommand); @@ -5496,7 +5533,7 @@ LRESULT MsgNotify(HWND hwnd,WPARAM wParam,LPARAM lParam) //int iLexer = (int)SendMessage(hwndEdit,SCI_GETLEXER,0,0); if (/*iLexer == SCLEX_HTML || iLexer == SCLEX_XML*/ 1) { - char tchBuf[512] = { 0 }; + char tchBuf[512] = { '\0' }; char tchIns[516] = " 3 && - lstrcmpiA(tchIns,"") && - lstrcmpiA(tchIns,"") && - lstrcmpiA(tchIns,"
") && - lstrcmpiA(tchIns,"") && - lstrcmpiA(tchIns,"") && - lstrcmpiA(tchIns,"") && - lstrcmpiA(tchIns,"") && - lstrcmpiA(tchIns,"") && - lstrcmpiA(tchIns,"")) + StringCchCompareINA(tchIns,COUNTOF(tchIns),"",-1) && + StringCchCompareINA(tchIns,COUNTOF(tchIns),"",-1) && + StringCchCompareINA(tchIns,COUNTOF(tchIns),"
",-1) && + StringCchCompareINA(tchIns,COUNTOF(tchIns),"",-1) && + StringCchCompareINA(tchIns,COUNTOF(tchIns),"",-1) && + StringCchCompareINA(tchIns,COUNTOF(tchIns),"",-1) && + StringCchCompareINA(tchIns,COUNTOF(tchIns),"",-1) && + StringCchCompareINA(tchIns,COUNTOF(tchIns),"",-1) && + StringCchCompareINA(tchIns,COUNTOF(tchIns),"",-1)) { int token = BeginSelUndoAction(); SendMessage(hwndEdit,SCI_REPLACESEL,0,(LPARAM)tchIns); @@ -6007,6 +6044,9 @@ void LoadSettings() iSciFontQuality = IniSectionGetInt(pIniSection,L"SciFontQuality",0); iSciFontQuality = max(min(iSciFontQuality,3),0); + iMarkOccurrencesMaxCount = IniSectionGetInt(pIniSection,L"MarkOccurrencesMaxCount",2000); + iMarkOccurrencesMaxCount = max(min(iMarkOccurrencesMaxCount,100000),2); + LoadIniSection(L"Toolbar Images",pIniSection,cchIniSection); IniSectionGetString(pIniSection,L"BitmapDefault",L"", @@ -6284,12 +6324,12 @@ void ParseCommandLine() { // options - if (!bIsFileArg && lstrcmp(lp1,L"+") == 0) { + if (!bIsFileArg && (StringCchCompareN(lp1,len,L"+",-1) == 0)) { flagMultiFileArg = 2; bIsFileArg = TRUE; } - else if (!bIsFileArg && lstrcmp(lp1,L"-") == 0) { + else if (!bIsFileArg && (StringCchCompareN(lp1,len,L"-",-1) == 0)) { flagMultiFileArg = 1; bIsFileArg = TRUE; } @@ -6301,25 +6341,25 @@ void ParseCommandLine() StrLTrim(lp1,L"-/"); // Encoding - if (lstrcmpi(lp1,L"ANSI") == 0 || lstrcmpi(lp1,L"A") == 0 || lstrcmpi(lp1,L"MBCS") == 0) + if (StringCchCompareIX(lp1,L"ANSI") == 0 || StringCchCompareIX(lp1,L"A") == 0 || StringCchCompareIX(lp1,L"MBCS") == 0) flagSetEncoding = IDM_ENCODING_ANSI-IDM_ENCODING_ANSI + 1; - else if (lstrcmpi(lp1,L"UNICODE") == 0 || lstrcmpi(lp1,L"W") == 0) + else if (StringCchCompareIX(lp1,L"UNICODE") == 0 || StringCchCompareIX(lp1,L"W") == 0) flagSetEncoding = IDM_ENCODING_UNICODE-IDM_ENCODING_ANSI + 1; - else if (lstrcmpi(lp1,L"UNICODEBE") == 0 || lstrcmpi(lp1,L"UNICODE-BE") == 0) + else if (StringCchCompareIX(lp1,L"UNICODEBE") == 0 || StringCchCompareIX(lp1,L"UNICODE-BE") == 0) flagSetEncoding = IDM_ENCODING_UNICODEREV-IDM_ENCODING_ANSI + 1; - else if (lstrcmpi(lp1,L"UTF8") == 0 || lstrcmpi(lp1,L"UTF-8") == 0) + else if (StringCchCompareIX(lp1,L"UTF8") == 0 || StringCchCompareIX(lp1,L"UTF-8") == 0) flagSetEncoding = IDM_ENCODING_UTF8-IDM_ENCODING_ANSI + 1; - else if (lstrcmpi(lp1,L"UTF8SIG") == 0 || lstrcmpi(lp1,L"UTF-8SIG") == 0 || - lstrcmpi(lp1,L"UTF8SIGNATURE") == 0 || lstrcmpi(lp1,L"UTF-8SIGNATURE") == 0 || - lstrcmpi(lp1,L"UTF8-SIGNATURE") == 0 || lstrcmpi(lp1,L"UTF-8-SIGNATURE") == 0) + else if (StringCchCompareIX(lp1,L"UTF8SIG") == 0 || StringCchCompareIX(lp1,L"UTF-8SIG") == 0 || + StringCchCompareIX(lp1,L"UTF8SIGNATURE") == 0 || StringCchCompareIX(lp1,L"UTF-8SIGNATURE") == 0 || + StringCchCompareIX(lp1,L"UTF8-SIGNATURE") == 0 || StringCchCompareIX(lp1,L"UTF-8-SIGNATURE") == 0) flagSetEncoding = IDM_ENCODING_UTF8SIGN-IDM_ENCODING_ANSI + 1; // EOL Mode - else if (lstrcmpi(lp1,L"CRLF") == 0 || lstrcmpi(lp1,L"CR+LF") == 0) + else if (StringCchCompareIX(lp1,L"CRLF") == 0 || StringCchCompareIX(lp1,L"CR+LF") == 0) flagSetEOLMode = IDM_LINEENDINGS_CRLF-IDM_LINEENDINGS_CRLF + 1; - else if (lstrcmpi(lp1,L"LF") == 0) + else if (StringCchCompareIX(lp1,L"LF") == 0) flagSetEOLMode = IDM_LINEENDINGS_LF-IDM_LINEENDINGS_CRLF + 1; - else if (lstrcmpi(lp1,L"CR") == 0) + else if (StringCchCompareIX(lp1,L"CR") == 0) flagSetEOLMode = IDM_LINEENDINGS_CR-IDM_LINEENDINGS_CRLF + 1; // Shell integration @@ -6330,6 +6370,7 @@ void ParseCommandLine() if (StringCchLen(g_wchAppUserModelID) == 0) StringCchCopy(g_wchAppUserModelID,COUNTOF(g_wchAppUserModelID),L"Notepad3"); } + else if (StrCmpNI(lp1,L"sysmru=",CSTRLEN(L"sysmru=")) == 0) { WCHAR wch[16]; StringCchCopyN(wch,COUNTOF(wch),lp1 + CSTRLEN(L"sysmru="),COUNTOF(wch)); @@ -6340,6 +6381,16 @@ void ParseCommandLine() flagUseSystemMRU = 1; } + // Relaunch elevated + else if (StrCmpNI(lp1,L"tmpfbuf=",CSTRLEN(L"tmpfbuf=")) == 0) { + StringCchCopyN(szBufferFile,COUNTOF(szBufferFile), + lp1 + CSTRLEN(L"tmpfbuf="),len - CSTRLEN(L"tmpfbuf=")); + TrimString(szBufferFile); + PathUnquoteSpaces(szBufferFile); + NormalizePathEx(szBufferFile,COUNTOF(szBufferFile)); + flagBufferFile = 1; + } + else switch (*CharUpper(lp1)) { @@ -6784,7 +6835,7 @@ int FindIniFile() { GetModuleFileName(NULL,tchModule,COUNTOF(tchModule)); if (StringCchLen(szIniFile)) { - if (lstrcmpi(szIniFile,L"*?") == 0) + if (StringCchCompareIX(szIniFile,L"*?") == 0) return(0); else { if (!CheckIniFile(szIniFile,tchModule)) { @@ -6828,7 +6879,7 @@ int FindIniFile() { int TestIniFile() { - if (lstrcmpi(szIniFile,L"*?") == 0) { + if (StringCchCompareIX(szIniFile,L"*?") == 0) { StringCchCopy(szIniFile2,COUNTOF(szIniFile2),L""); StringCchCopy(szIniFile,COUNTOF(szIniFile),L""); return(0); @@ -7219,6 +7270,7 @@ int UndoRedoSelectionMap(int token, UndoRedoSelection_t* selection) if (selection == NULL) { // reset / clear + SendMessage(hwndEdit,SCI_EMPTYUNDOBUFFER,0,0); if (UndoRedoSelectionUTArray != NULL) { utarray_clear(UndoRedoSelectionUTArray); utarray_init(UndoRedoSelectionUTArray,&UndoRedoSelection_icd); @@ -7227,6 +7279,10 @@ int UndoRedoSelectionMap(int token, UndoRedoSelection_t* selection) return -1; } + if (!(BOOL)SendMessage(hwndEdit,SCI_GETUNDOCOLLECTION,0,0)) { + return -1; + } + // get or set map item request ? if (token >= 0 && utoken < iTokenCnt) { if (selection->anchorPos_undo < 0) { @@ -7404,7 +7460,8 @@ BOOL FileLoad(BOOL bDontSave,BOOL bNew,BOOL bReload,BOOL bNoEncDetect,LPCWSTR lp else { int fileEncoding = Encoding_Current(CPI_GET); fSuccess = FileIO(TRUE,szFileName,bNoEncDetect,&fileEncoding,&iEOLMode,&bUnicodeErr,&bFileTooBig,NULL,FALSE); - Encoding_Current(fileEncoding); // load may change encoding + if (fSuccess) + Encoding_Current(fileEncoding); // load may change encoding } if (fSuccess) { StringCchCopy(szCurFile,COUNTOF(szCurFile),szFileName); @@ -7435,7 +7492,7 @@ BOOL FileLoad(BOOL bDontSave,BOOL bNew,BOOL bReload,BOOL bNoEncDetect,LPCWSTR lp if (SendMessage(hwndEdit,SCI_GETLENGTH,0,0) >= 4) { char tchLog[5] = ""; SendMessage(hwndEdit,SCI_GETTEXT,5,(LPARAM)tchLog); - if (lstrcmpA(tchLog,".LOG") == 0) { + if (StringCchCompareXA(tchLog,".LOG") == 0) { EditJumpTo(hwndEdit,-1,0); SendMessage(hwndEdit,SCI_BEGINUNDOACTION,0,0); SendMessage(hwndEdit,SCI_NEWLINE,0,0); @@ -7449,7 +7506,7 @@ BOOL FileLoad(BOOL bDontSave,BOOL bNew,BOOL bReload,BOOL bNoEncDetect,LPCWSTR lp } // consistent settings file handling (if loaded in editor) - bEnableSaveSettings = (lstrcmpi(szCurFile, szIniFile) == 0) ? FALSE : TRUE; + bEnableSaveSettings = (StringCchCompareI(szCurFile, szIniFile) == 0) ? FALSE : TRUE; UpdateSettingsCmds(); // Show warning: Unicode file loaded as ANSI @@ -7542,7 +7599,7 @@ BOOL FileSave(BOOL bSaveAlways,BOOL bAsk,BOOL bSaveAs,BOOL bSaveCopy) { int fileEncoding = Encoding_Current(CPI_GET); fSuccess = FileIO(FALSE, tchFile, FALSE, &fileEncoding, &iEOLMode, NULL, NULL, &bCancelDataLoss, bSaveCopy); - //~Encoding_Current(fileEncoding); // save should not change encoding + //~if (fSuccess) Encoding_Current(fileEncoding); // save should not change encoding if (fSuccess) { if (!bSaveCopy) @@ -7561,6 +7618,49 @@ BOOL FileSave(BOOL bSaveAlways,BOOL bAsk,BOOL bSaveAs,BOOL bSaveCopy) PathRemoveFileSpec(tchLastSaveCopyDir); } } +#if 0 + else if (!bCancelDataLoss) { + // relaunch elevated ? + if (!fIsElevated && dwLastIOError == ERROR_ACCESS_DENIED) { + if (IDYES == MsgBox(MBYESNOWARN,IDS_ERR_ACCESSDENIED,tchFile)) { + WCHAR lpTempPathBuffer[MAX_PATH]; + WCHAR szTempFileName[MAX_PATH]; + + if (GetTempPath(MAX_PATH,lpTempPathBuffer) && + GetTempFileName(lpTempPathBuffer,TEXT("N2"),0,szTempFileName)) { + int fEnc = Encoding_Current(CPI_GET); + if (FileIO(FALSE,szTempFileName,FALSE,&fEnc,&iEOLMode,NULL,NULL,&bCancelDataLoss,TRUE)) { + //~Encoding_Current(fEnc); // save should not change encoding + + WCHAR szArguments[2 * MAX_PATH + 64] = { L'\0' }; + LPWSTR lpCmdLine = GetCommandLine(); + int wlen = lstrlen(lpCmdLine) + 2; + LPWSTR lpExe = LocalAlloc(LPTR,sizeof(WCHAR)*wlen); + LPWSTR lpArgs = LocalAlloc(LPTR,sizeof(WCHAR)*wlen); + ExtractFirstArgument(lpCmdLine,lpExe,lpArgs,wlen); + + StringCchPrintf(szArguments,COUNTOF(szArguments),L"/u -tmpfbuf=\"%s\" %s",szTempFileName,lpArgs); + if (StringCchLen(tchFile)) { + if (!StrStrI(szArguments,tchFile)) { + StringCchPrintf(szArguments,COUNTOF(szArguments),L"%s \"%s\"",szArguments,tchFile); + } + } + + flagRelaunchElevated = 1; + if (RelaunchElevated(szArguments)) { + LocalFree(lpExe); + LocalFree(lpArgs); + // set no change and quit + Encoding_HasChanged(Encoding_Current(CPI_GET)); + bModified = FALSE; + PostMessage(hwndMain,WM_CLOSE,0,0); + } + } + } + } + } + } +#endif } else return FALSE; @@ -7569,8 +7669,9 @@ BOOL FileSave(BOOL bSaveAlways,BOOL bAsk,BOOL bSaveAs,BOOL bSaveCopy) else { int fileEncoding = Encoding_Current(CPI_GET); fSuccess = FileIO(FALSE,szCurFile,FALSE,&fileEncoding,&iEOLMode,NULL,NULL,&bCancelDataLoss,FALSE); - //~Encoding_Current(fileEncoding); // save should not change encoding + //~if (fSuccess) Encoding_Current(fileEncoding); // save should not change encoding } + if (fSuccess) { if (!bSaveCopy) @@ -7593,16 +7694,56 @@ BOOL FileSave(BOOL bSaveAlways,BOOL bAsk,BOOL bSaveAs,BOOL bSaveCopy) else if (!bCancelDataLoss) { - if (StringCchLen(szCurFile) != 0) + if (StringCchLen(szCurFile) != 0) { StringCchCopy(tchFile,COUNTOF(tchFile),szCurFile); + } - SetWindowTitle(hwndMain,uidsAppTitle,fIsElevated,IDS_UNTITLED,szCurFile, - iPathNameFormat,bModified || Encoding_HasChanged(CPI_GET), - IDS_READONLY,bReadOnly,szTitleExcerpt); + if (!fIsElevated && dwLastIOError == ERROR_ACCESS_DENIED) { + if (IDYES == MsgBox(MBYESNOWARN,IDS_ERR_ACCESSDENIED,tchFile)) { + WCHAR lpTempPathBuffer[MAX_PATH]; + WCHAR szTempFileName[MAX_PATH]; + + if (GetTempPath(MAX_PATH,lpTempPathBuffer) && + GetTempFileName(lpTempPathBuffer,TEXT("N2"),0,szTempFileName)) { + int fileEncoding = Encoding_Current(CPI_GET); + if (FileIO(FALSE,szTempFileName,FALSE,&fileEncoding,&iEOLMode,NULL,NULL,&bCancelDataLoss,TRUE)) { + //~Encoding_Current(fileEncoding); // save should not change encoding + + WCHAR szArguments[2 * MAX_PATH + 64] = { L'\0' }; + LPWSTR lpCmdLine = GetCommandLine(); + int wlen = lstrlen(lpCmdLine) + 2; + LPWSTR lpExe = LocalAlloc(LPTR,sizeof(WCHAR)*wlen); + LPWSTR lpArgs = LocalAlloc(LPTR,sizeof(WCHAR)*wlen); + ExtractFirstArgument(lpCmdLine,lpExe,lpArgs,wlen); + + StringCchPrintf(szArguments,COUNTOF(szArguments),L"/u -tmpfbuf=\"%s\" %s",szTempFileName,lpArgs); + if (StringCchLen(tchFile)) { + if (!StrStrI(szArguments,tchFile)) { + StringCchPrintf(szArguments,COUNTOF(szArguments),L"%s \"%s\"",szArguments,tchFile); + } + } - MsgBox(MBWARN,IDS_ERR_SAVEFILE,tchFile); - } + flagRelaunchElevated = 1; + if (RelaunchElevated(szArguments)) { + LocalFree(lpExe); + LocalFree(lpArgs); + // set no change and quit + Encoding_HasChanged(Encoding_Current(CPI_GET)); + bModified = FALSE; + PostMessage(hwndMain,WM_CLOSE,0,0); + } + } + } + } + } + else { + SetWindowTitle(hwndMain,uidsAppTitle,fIsElevated,IDS_UNTITLED,szCurFile, + iPathNameFormat,bModified || Encoding_HasChanged(CPI_GET), + IDS_READONLY,bReadOnly,szTitleExcerpt); + MsgBox(MBWARN,IDS_ERR_SAVEFILE,tchFile); + } + } return(fSuccess); } @@ -7733,7 +7874,7 @@ BOOL CALLBACK EnumWndProc(HWND hwnd,LPARAM lParam) if (GetClassName(hwnd,szClassName,COUNTOF(szClassName))) - if (lstrcmpi(szClassName,wchWndClass) == 0) { + if (StringCchCompareI(szClassName,wchWndClass) == 0) { DWORD dwReuseLock = GetDlgItemInt(hwnd,IDC_REUSELOCK,NULL,FALSE); if (GetTickCount() - dwReuseLock >= REUSEWINDOWLOCKTIMEOUT) { @@ -7754,7 +7895,7 @@ BOOL CALLBACK EnumWndProc2(HWND hwnd,LPARAM lParam) if (GetClassName(hwnd,szClassName,COUNTOF(szClassName))) - if (lstrcmpi(szClassName,wchWndClass) == 0) { + if (StringCchCompareI(szClassName,wchWndClass) == 0) { DWORD dwReuseLock = GetDlgItemInt(hwnd,IDC_REUSELOCK,NULL,FALSE); if (GetTickCount() - dwReuseLock >= REUSEWINDOWLOCKTIMEOUT) { @@ -7765,7 +7906,7 @@ BOOL CALLBACK EnumWndProc2(HWND hwnd,LPARAM lParam) bContinue = FALSE; GetDlgItemText(hwnd,IDC_FILENAME,tchFileName,COUNTOF(tchFileName)); - if (lstrcmpi(tchFileName,lpFileArg) == 0) + if (StringCchCompareIN(tchFileName,COUNTOF(tchFileName),lpFileArg,-1) == 0) *(HWND*)lParam = hwnd; else bContinue = TRUE; @@ -8053,46 +8194,55 @@ BOOL RelaunchMultiInst() { // RelaunchElevated() // // -BOOL RelaunchElevated() { - - if (!IsVista() || fIsElevated || !flagRelaunchElevated || flagDisplayHelp) - return(FALSE); - - else { - - LPWSTR lpCmdLine; - LPWSTR lpArg1, lpArg2; - STARTUPINFO si; +BOOL RelaunchElevated(LPWSTR lpArgs) { - si.cb = sizeof(STARTUPINFO); - GetStartupInfo(&si); + BOOL result = FALSE; - lpCmdLine = GetCommandLine(); - int len = lstrlen(lpCmdLine) + 1; - lpArg1 = LocalAlloc(LPTR,sizeof(WCHAR)*len); - lpArg2 = LocalAlloc(LPTR,sizeof(WCHAR)*len); - ExtractFirstArgument(lpCmdLine,lpArg1,lpArg2,len); - - if (StringCchLenN(lpArg1,len)) { + if (!IsVista() || fIsElevated || !flagRelaunchElevated || flagDisplayHelp) + return result; - SHELLEXECUTEINFO sei = { 0 }; - sei.cbSize = sizeof(SHELLEXECUTEINFO); - sei.fMask = SEE_MASK_FLAG_NO_UI | /*SEE_MASK_NOASYNC*/0x00000100 | /*SEE_MASK_NOZONECHECKS*/0x00800000; - sei.hwnd = GetForegroundWindow(); - sei.lpVerb = L"runas"; - sei.lpFile = lpArg1; - sei.lpParameters = lpArg2; - sei.lpDirectory = g_wchWorkingDirectory; - sei.nShow = si.wShowWindow; + STARTUPINFO si; + si.cb = sizeof(STARTUPINFO); + GetStartupInfo(&si); - ShellExecuteEx(&sei); - } + LPWSTR lpCmdLine = GetCommandLine(); + int wlen = lstrlen(lpCmdLine) + 2; + + LPWSTR lpExe1 = NULL; + WCHAR lpExe2[MAX_PATH + 2] = { L'\0' }; + GetModuleFileName(NULL,lpExe2,COUNTOF(lpExe2)); + NormalizePathEx(lpExe2,MAX_PATH + 2); + + BOOL bShouldFree = FALSE; + if (!lpArgs) { + lpExe1 = LocalAlloc(LPTR,sizeof(WCHAR)*wlen); + lpArgs = LocalAlloc(LPTR,sizeof(WCHAR)*wlen); + bShouldFree = TRUE; + ExtractFirstArgument(lpCmdLine,lpExe1,lpArgs,wlen); + NormalizePathEx(lpExe1,wlen); + } - LocalFree(lpArg1); - LocalFree(lpArg2); + if (lstrlen(lpArgs)) { + SHELLEXECUTEINFO sei; + ZeroMemory(&sei,sizeof(SHELLEXECUTEINFO)); + sei.cbSize = sizeof(SHELLEXECUTEINFO); + sei.fMask = SEE_MASK_FLAG_NO_UI | SEE_MASK_NOASYNC | SEE_MASK_NOZONECHECKS; + sei.hwnd = GetForegroundWindow(); + sei.lpVerb = L"runas"; + sei.lpFile = (lpExe1 ? lpExe1 : lpExe2); + sei.lpParameters = lpArgs; + sei.lpDirectory = g_wchWorkingDirectory; + sei.nShow = si.wShowWindow ? si.wShowWindow : SW_SHOWNORMAL; + CoInitializeEx(NULL,COINIT_APARTMENTTHREADED | COINIT_SPEED_OVER_MEMORY); + result = ShellExecuteEx(&sei); + } - return(TRUE); + if (bShouldFree) { + LocalFree(lpArgs); + LocalFree(lpExe1); } + + return result; } diff --git a/src/Notepad3.h b/src/Notepad3.h index 79fb7b516..a4751c025 100644 --- a/src/Notepad3.h +++ b/src/Notepad3.h @@ -112,7 +112,7 @@ BOOL InitApplication(HINSTANCE); HWND InitInstance(HINSTANCE,LPSTR,int); BOOL ActivatePrevInst(); BOOL RelaunchMultiInst(); -BOOL RelaunchElevated(); +BOOL RelaunchElevated(LPWSTR); void SnapToDefaultPos(HWND); void ShowNotifyIcon(HWND,BOOL); void SetNotifyIconTitle(HWND); diff --git a/src/Notepad3.rc b/src/Notepad3.rc index 444a7d1b9..5aa742bdb 100644 Binary files a/src/Notepad3.rc and b/src/Notepad3.rc differ diff --git a/src/Notepad3.vcxproj b/src/Notepad3.vcxproj index 293462138..82fcb8592 100644 --- a/src/Notepad3.vcxproj +++ b/src/Notepad3.vcxproj @@ -19,7 +19,6 @@
- $(VCTargetsPath11) Win32Proj {BAAD32AB-CD47-12FD-873C-0BBC204B7641} Notepad3 diff --git a/src/Print.cpp b/src/Print.cpp index 147ea81b1..3a23c6c05 100644 --- a/src/Print.cpp +++ b/src/Print.cpp @@ -14,9 +14,17 @@ * * *******************************************************************************/ +#if !defined(WINVER) +#define WINVER 0x601 /*_WIN32_WINNT_WIN7*/ +#endif #if !defined(_WIN32_WINNT) -#define _WIN32_WINNT 0x501 +#define _WIN32_WINNT 0x601 /*_WIN32_WINNT_WIN7*/ +#endif +#if !defined(NTDDI_VERSION) +#define NTDDI_VERSION 0x06010000 /*NTDDI_WIN7*/ #endif +#define VC_EXTRALEAN 1 + #include #include #include diff --git a/src/Styles.c b/src/Styles.c index 0679a33f0..6621d152e 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -13,9 +13,17 @@ * * * * *******************************************************************************/ +#if !defined(WINVER) +#define WINVER 0x601 /*_WIN32_WINNT_WIN7*/ +#endif #if !defined(_WIN32_WINNT) -#define _WIN32_WINNT 0x501 +#define _WIN32_WINNT 0x601 /*_WIN32_WINNT_WIN7*/ +#endif +#if !defined(NTDDI_VERSION) +#define NTDDI_VERSION 0x06010000 /*NTDDI_WIN7*/ #endif +#define VC_EXTRALEAN 1 + #include #include #include @@ -3424,7 +3432,7 @@ PEDITLEXER __fastcall Style_MatchLexer(LPCWSTR lpszMatch,BOOL bCheckNames) else p2 = StrEnd(p1); StrTrim(p1,L" ."); - if (lstrcmpi(p1,lpszMatch) == 0) + if (StringCchCompareIX(p1,lpszMatch) == 0) return(pLexArray[i]); p1 = p2+1; } @@ -3468,14 +3476,15 @@ void Style_SetLexerFromFile(HWND hwnd,LPCWSTR lpszFile) UINT cp = Encoding_SciGetCodePage(hwnd); MultiByteToWideCharStrg(cp,fvCurFile.tchMode,wchMode); - if (!fNoCGIGuess && (lstrcmpi(wchMode,L"cgi") == 0 || lstrcmpi(wchMode,L"fcgi") == 0)) { + if (!fNoCGIGuess && (StringCchCompareIN(wchMode,COUNTOF(wchMode),L"cgi",-1) == 0 || + StringCchCompareIN(wchMode,COUNTOF(wchMode),L"fcgi",-1) == 0)) { char tchText[256] = { L'\0' }; SendMessage(hwnd,SCI_GETTEXT,(WPARAM)COUNTOF(tchText)-1,(LPARAM)tchText); StrTrimA(tchText," \t\n\r"); pLexSniffed = Style_SniffShebang(tchText); if (pLexSniffed) { if (Encoding_Current(CPI_GET) != g_DOSEncoding || pLexSniffed != &lexDefault || ( - lstrcmpi(lpszExt,L"nfo") && lstrcmpi(lpszExt,L"diz"))) { + StringCchCompareIX(lpszExt,L"nfo") && StringCchCompareIX(lpszExt,L"diz"))) { // Although .nfo and .diz were removed from the default lexer's // default extensions list, they may still presist in the user's INI pLexNew = pLexSniffed; @@ -3506,7 +3515,7 @@ void Style_SetLexerFromFile(HWND hwnd,LPCWSTR lpszFile) if (*lpszExt == L'.') lpszExt++; - if (!fNoCGIGuess && (lstrcmpi(lpszExt,L"cgi") == 0 || lstrcmpi(lpszExt,L"fcgi") == 0)) { + if (!fNoCGIGuess && (StringCchCompareIX(lpszExt,L"cgi") == 0 || StringCchCompareIX(lpszExt,L"fcgi") == 0)) { char tchText[256] = { L'\0' }; SendMessage(hwnd,SCI_GETTEXT,(WPARAM)COUNTOF(tchText)-1,(LPARAM)tchText); StrTrimA(tchText," \t\n\r"); @@ -3517,7 +3526,7 @@ void Style_SetLexerFromFile(HWND hwnd,LPCWSTR lpszFile) } } - if (!bFound && lstrcmpi(PathFindFileName(lpszFile),L"cmakelists.txt") == 0) { + if (!bFound && StringCchCompareIX(PathFindFileName(lpszFile),L"cmakelists.txt") == 0) { pLexNew = &lexCmake; bFound = TRUE; } @@ -3533,19 +3542,19 @@ void Style_SetLexerFromFile(HWND hwnd,LPCWSTR lpszFile) } if (!bFound && bAutoSelect && - lstrcmpi(PathFindFileName(lpszFile),L"makefile") == 0) { + StringCchCompareIX(PathFindFileName(lpszFile),L"makefile") == 0) { pLexNew = &lexMAK; bFound = TRUE; } if (!bFound && bAutoSelect && - lstrcmpi(PathFindFileName(lpszFile),L"rakefile") == 0) { + StringCchCompareIX(PathFindFileName(lpszFile),L"rakefile") == 0) { pLexNew = &lexRUBY; bFound = TRUE; } if (!bFound && bAutoSelect && - lstrcmpi(PathFindFileName(lpszFile),L"mozconfig") == 0) { + StringCchCompareIX(PathFindFileName(lpszFile),L"mozconfig") == 0) { pLexNew = &lexBASH; bFound = TRUE; } @@ -3738,7 +3747,7 @@ BOOL Style_StrGetFont(LPCWSTR lpszStyle,LPWSTR lpszFont,int cchFont) *p = L'\0'; TrimString(tch); - if (lstrcmpi(tch,L"Default") == 0) + if (StringCchCompareIN(tch,COUNTOF(tch),L"Default",-1) == 0) { if (fIsConsolasAvailable) StringCchCopyN(lpszFont,cchFont,L"Consolas",cchFont); @@ -3771,10 +3780,10 @@ BOOL Style_StrGetFontQuality(LPCWSTR lpszStyle,LPWSTR lpszQuality,int cchQuality if (p) *p = L'\0'; TrimString(tch); - if (lstrcmpi(tch,L"none") == 0 || - lstrcmpi(tch,L"standard") == 0 || - lstrcmpi(tch,L"cleartype") == 0 || - lstrcmpi(tch,L"default") == 0) { + if (StringCchCompareIN(tch,COUNTOF(tch),L"none",-1) == 0 || + StringCchCompareIN(tch,COUNTOF(tch),L"standard",-1) == 0 || + StringCchCompareIN(tch,COUNTOF(tch),L"cleartype",-1) == 0 || + StringCchCompareIN(tch,COUNTOF(tch),L"default",-1) == 0) { StringCchCopyN(lpszQuality,cchQuality,tch,COUNTOF(tch)); return TRUE; } @@ -4277,25 +4286,25 @@ void Style_SetFontQuality(HWND hwnd,LPCWSTR lpszStyle) { WCHAR tch[64] = { L'\0' }; if (Style_StrGetFontQuality(lpszStyle,tch,COUNTOF(tch))) { - if (lstrcmpi(tch,L"default") == 0) + if (StringCchCompareIN(tch,COUNTOF(tch),L"default",-1) == 0) wQuality = SC_EFF_QUALITY_DEFAULT; - else if (lstrcmpi(tch,L"none") == 0) + else if (StringCchCompareIN(tch,COUNTOF(tch),L"none",-1) == 0) wQuality = SC_EFF_QUALITY_NON_ANTIALIASED; - else if (lstrcmpi(tch,L"standard") == 0) + else if (StringCchCompareIN(tch,COUNTOF(tch),L"standard",-1) == 0) wQuality = SC_EFF_QUALITY_ANTIALIASED; - else if (lstrcmpi(tch,L"cleartype") == 0) + else if (StringCchCompareIN(tch,COUNTOF(tch),L"cleartype",-1) == 0) wQuality = SC_EFF_QUALITY_LCD_OPTIMIZED; } else { // undefined, use general settings, except for special fonts if (Style_StrGetFont(lpszStyle,tch,COUNTOF(tch))) { - if (lstrcmpi(tch,L"Calibri") == 0 || - lstrcmpi(tch,L"Cambria") == 0 || - lstrcmpi(tch,L"Candara") == 0 || - lstrcmpi(tch,L"Consolas") == 0 || - lstrcmpi(tch,L"Constantia") == 0 || - lstrcmpi(tch,L"Corbel") == 0 || - lstrcmpi(tch,L"Segoe UI") == 0 || - lstrcmpi(tch,L"Source Code Pro") == 0) + if (StringCchCompareIN(tch,COUNTOF(tch),L"Calibri",-1) == 0 || + StringCchCompareIN(tch,COUNTOF(tch),L"Cambria",-1) == 0 || + StringCchCompareIN(tch,COUNTOF(tch),L"Candara",-1) == 0 || + StringCchCompareIN(tch,COUNTOF(tch),L"Consolas",-1) == 0 || + StringCchCompareIN(tch,COUNTOF(tch),L"Constantia",-1) == 0 || + StringCchCompareIN(tch,COUNTOF(tch),L"Corbel",-1) == 0 || + StringCchCompareIN(tch,COUNTOF(tch),L"Segoe UI",-1) == 0 || + StringCchCompareIN(tch,COUNTOF(tch),L"Source Code Pro",-1) == 0) wQuality = SC_EFF_QUALITY_LCD_OPTIMIZED; } } @@ -4323,8 +4332,6 @@ int Style_GetLexerIconId(PEDITLEXER plex) WCHAR *pszExtensions; WCHAR *pszFile; - SHFILEINFO shfi = { 0 }; - if (StringCchLen(plex->szExtensions)) pszExtensions = plex->szExtensions; else @@ -4343,6 +4350,9 @@ int Style_GetLexerIconId(PEDITLEXER plex) if (StringCchLenN(pszFile,MAX_PATH) < 3) StringCchCat(pszFile,len,L"txt"); + SHFILEINFO shfi; + ZeroMemory(&shfi,sizeof(SHFILEINFO)); + SHGetFileInfo(pszFile,FILE_ATTRIBUTE_NORMAL,&shfi,sizeof(SHFILEINFO), SHGFI_SMALLICON | SHGFI_SYSICONINDEX | SHGFI_USEFILEATTRIBUTES); @@ -4446,7 +4456,7 @@ INT_PTR CALLBACK Style_ConfigDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lP int i; SHFILEINFO shfi; LOGFONT lf; - HTREEITEM currentLex = { 0 }; + HTREEITEM currentLex = NULL; int found = 0; hwndTV = GetDlgItem(hwnd,IDC_STYLELIST); @@ -4459,7 +4469,7 @@ INT_PTR CALLBACK Style_ConfigDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lP // Add lexers for (i = 0; i < COUNTOF(pLexArray); i++) { - if (!found && lstrcmp(pLexArray[i]->pszName,pLexCurrent->pszName) == 0) + if (!found && (StringCchCompareX(pLexArray[i]->pszName,pLexCurrent->pszName) == 0)) { found = 1; currentLex = Style_AddLexerToTreeView(hwndTV,pLexArray[i]); @@ -4757,8 +4767,8 @@ INT_PTR CALLBACK Style_ConfigDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPARAM lP WCHAR tch[256] = { L'\0' }; GetDlgItemText(hwnd,IDC_STYLEEDIT,tch,COUNTOF(tch)); if (Style_SelectFont(hwnd,tch,COUNTOF(tch), - lstrcmpi(pCurrentStyle->pszName,L"Default Style") == 0 || - lstrcmpi(pCurrentStyle->pszName,L"2nd Default Style") == 0)) { + StringCchCompareIX(pCurrentStyle->pszName,L"Default Style") == 0 || + StringCchCompareIX(pCurrentStyle->pszName,L"2nd Default Style") == 0)) { SetDlgItemText(hwnd,IDC_STYLEEDIT,tch); //CheckDlgButton(hwnd,IDC_STYLEBOLD,(Style_StrGetAttribute(tch,L"bold") ? BST_CHECKED : BST_UNCHECKED)); //CheckDlgButton(hwnd,IDC_STYLEITALIC,(Style_StrGetAttribute(tch,L"italic") ? BST_CHECKED : BST_UNCHECKED)); @@ -5097,7 +5107,7 @@ INT_PTR CALLBACK Style_SelectLexerDlgProc(HWND hwnd,UINT umsg,WPARAM wParam,LPAR for (i = 0; i < lvItems; i++) { lvi.iItem = i; ListView_GetItem(hwndLV,&lvi);; - if (lstrcmp(((PEDITLEXER)lvi.lParam)->pszName,pLexCurrent->pszName) == 0) { + if (StringCchCompareX(((PEDITLEXER)lvi.lParam)->pszName,pLexCurrent->pszName) == 0) { ListView_SetItemState(hwndLV,i,LVIS_FOCUSED|LVIS_SELECTED,LVIS_FOCUSED|LVIS_SELECTED); ListView_EnsureVisible(hwndLV,i,FALSE); if (iDefaultLexer == i) { diff --git a/src/resource.h b/src/resource.h index 84d9d55f8..5c33cbdf6 100644 --- a/src/resource.h +++ b/src/resource.h @@ -451,6 +451,7 @@ #define IDS_WRITEINI_FAIL 50038 #define IDS_SETTINGSNOTSAVED 50039 #define IDS_EXPORT_FAIL 50040 +#define IDS_ERR_ACCESSDENIED 50041 #define IDS_CMDLINEHELP 60000 #define IDM_EDIT_INSERT_GUID 60001 #define IDC_STATIC -1