diff --git a/PowerEditor/bin/change.log b/PowerEditor/bin/change.log new file mode 100644 index 00000000..2a0e740c --- /dev/null +++ b/PowerEditor/bin/change.log @@ -0,0 +1,29 @@ +Notepad++ v5.3.1 new features and fixed bugs (from v5.3) : + +1. Fix inaccurate replace bug. +2. Increase Find what and replace with fields to 2047 characters. +3. Stop the indicator highlighting while the line change marker margin is hidden. +4. SConstruct and SConscript are recognized as python file. + +Included plugins (Unicode): + +1. TextFX v0.26 +2. NppExec v0.3 RC1 +3. Spell Checker v1.3.2 +4. MIME Tools v1.5 +5. FTP_synchronize v0.9.6 +6. NppExport v0.2.8 +7. Doc Monitor v2.2 +8. NppNetNote v0.1 + +Included plugins (ANSI): + +1. TextFX v0.25 +2. NppExec v0.3 RC1 +3. Spell Checker v1.3.1 +4. MIME Tools v1.5 +5. FTP_synchronize v0.9.6 +6. NppExport v0.2.8 +7. Light Explorer v1.5 +8. Doc Monitor v2.2 +9. NppNetNote v0.1 diff --git a/PowerEditor/bin/license.txt b/PowerEditor/bin/license.txt new file mode 100644 index 00000000..ba835c30 --- /dev/null +++ b/PowerEditor/bin/license.txt @@ -0,0 +1,88 @@ +GNU GENERAL PUBLIC LICENSE +Version 2, June 1991 + +Copyright (C) 1989, 1991 Free Software Foundation, Inc. +59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + +Everyone is permitted to copy and distribute verbatim copies +of this license document, but changing it is not allowed. + +Preamble +The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. + +When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. + +To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. + +For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. + +We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. + +Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. + +Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. + +The precise terms and conditions for copying, distribution and modification follow. + +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION +0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. + +1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. + +You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. + +2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: + + +a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. + +b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. + +c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) +These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. +Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. + +3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: + +a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, + +b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, + +c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) +The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. +If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. + +4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. + +5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. + +6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. + +7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. + +This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. + +8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. + +9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. + +10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. + +NO WARRANTY + +11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + + +END OF TERMS AND CONDITIONS diff --git a/PowerEditor/bin/npp.pdb b/PowerEditor/bin/npp.pdb new file mode 100644 index 00000000..c1bcafa9 Binary files /dev/null and b/PowerEditor/bin/npp.pdb differ diff --git a/PowerEditor/bin/readme.txt b/PowerEditor/bin/readme.txt new file mode 100644 index 00000000..1ae069ba --- /dev/null +++ b/PowerEditor/bin/readme.txt @@ -0,0 +1,45 @@ +Notepad++ release Note : + +What is Notepad++? +****************** + +Notepad++ is a generic source editor (it tries to be anyway) and Notepad replacement written in C++ with the win32 API. The aim of Notepad++ is to offer a slim and efficient binary with a totally customizable GUI. This project is under the GPL Licence (http://www.gnu.org/copyleft/gpl.html). + + +Why another source editor? +************************** + +I worked for a big smart card company as an engineer developer. On 2003, I took charge of looking for an alternative solution for an internal tool coded in Java. The internal tool needed an edit component, and I discovered Scintilla (which allows me to develop in C++) on the Internet. I began my conception and development on this project. + +In the mean time, the company where I worked began to use a new development environment, and a proprietary language as well, to re-develop all internal tools. All the developers were forced to use this unstable and uncomfortable IDE and the incoherent proprietary language. This project was unfortunately abandoned (or on the contrary?). + +As a C++/Java developer, I decided to continue the project in my spare time. The prototype of project was already done, I removed the components which depend on the specification of the abandoned project - It made a generic code editor. Then I made it available on sourceforge : that's the beginning of Notepad++. + +Time moves on, and I continue to improve Notepad++. Two things make me continue this project : my need to work on a coherent project by using my beloved language C++ and the encouragement from Notepad++ users. So you asked me "Why another source editor", the answer that I can give you is : "Why not? Since I enjoy myself doing it." + + +How to install : +**************** + +From the installer : + Just follow the install wizard. +From the zip : + just unzip all the files into a directory you want then launch it. + + +Project web sites : +******************* + +Notepad++ official site : + http://notepad-plus.sourceforge.net/ + + Here you can find all the informations about Notepad++, such as FAQ/tutorial, plugins/extension download, news, shops, etc... + +Notepad++ project site : + http://sourceforge.net/projects/notepad-plus/ + + It is Notepad++ project site. The source codes and binaries are distributed here. You can do your feature requests or bug reports by using the trackers, you can ask your question regarding Notepad++ in the divers forums as well. + + +Don HO +********************** diff --git a/PowerEditor/gcc/delete.bat b/PowerEditor/gcc/delete.bat new file mode 100644 index 00000000..f984df76 --- /dev/null +++ b/PowerEditor/gcc/delete.bat @@ -0,0 +1,4 @@ +@echo off +FOR /F "tokens=*" %%G IN ('dir /b /s ..\src\*.o') DO del "%%G" +del resources.res +@echo on \ No newline at end of file diff --git a/PowerEditor/gcc/include/eh.h b/PowerEditor/gcc/include/eh.h new file mode 100644 index 00000000..783ad7f7 --- /dev/null +++ b/PowerEditor/gcc/include/eh.h @@ -0,0 +1,7 @@ +#ifndef EH_H + +typedef void (*exFunc)(unsigned int, EXCEPTION_POINTERS *); + +void _set_se_translator(exFunc) {}; + +#endif //EH_H diff --git a/PowerEditor/gcc/include/various.h b/PowerEditor/gcc/include/various.h new file mode 100644 index 00000000..10f04502 --- /dev/null +++ b/PowerEditor/gcc/include/various.h @@ -0,0 +1,51 @@ +//this file contains definitions not available in gcc 3.4.5, +//but are needed for Notepad++ +//the makefile will automatically include this header file + +//GetLongPathName = 410 +//Multimonitor: 410 +#define _WIN32_WINDOWS 0x0410 +//Toolbar imagelist = 300 +//TCS_BOTTOM = 300 +//LVS_EX_BORDERSELECT = 500 +//TBSTYLE_EX_HIDECLIPPEDBUTTONS = 501 +#define _WIN32_IE 0x501 +//Theme (uxtheme) +#define _WIN32_WINNT 0x0501 + +//#include + +#if (_WIN32_IE >= 0x0400) +#define TCN_GETOBJECT (TCN_FIRST - 3) +#endif + +#if (_WIN32_IE >= 0x0500) +#define RBN_CHEVRONPUSHED (RBN_FIRST - 10) +#endif // _WIN32_IE >= 0x0500 +/* +#ifndef max +#define max(a,b) (((a) > (b)) ? (a) : (b)) +#endif + +#ifndef min +#define min(a,b) (((a) < (b)) ? (a) : (b)) +#endif +*/ + +static inline int max(unsigned int a, unsigned int b) { + return (((a) > (b)) ? (a) : (b)); +} + +static inline int min(unsigned int a, unsigned int b) { + return (((a) < (b)) ? (a) : (b)); +} + +//__try and __except dont work in gcc, so heres some defines to take em out +#define __try +#define __except(x) if(false) + +#define GetExceptionCode() 0 +#define GetExceptionInformation() NULL + +//Missing unicode CRT funcs +double _wtof(const wchar_t * string); diff --git a/PowerEditor/gcc/makefile b/PowerEditor/gcc/makefile new file mode 100644 index 00000000..440fec33 --- /dev/null +++ b/PowerEditor/gcc/makefile @@ -0,0 +1,203 @@ +# this file is part of notepad++ +# Copyright (C)2008 Harry Bruin +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +# Directories: +NPP_DIR = ../src +SCI_DIR = ../../scintilla/include +GCC_DIR = . +GCCINCLUDE_DIR = $(GCC_DIR)/include + +#MISC: +MISC_DIR = $(NPP_DIR)/MISC + COMMON_DIR = $(MISC_DIR)/Common + EXCEPTION_DIR = $(MISC_DIR)/Exception + PLUGINS_DIR = $(MISC_DIR)/PluginsManager + PROCESS_DIR = $(MISC_DIR)/Process + REGEXT_DIR = $(MISC_DIR)/RegExt + +#ScintillaComponent: +SCINT_DIR = $(NPP_DIR)/ScitillaComponent + +#TinyXml +TIXML_DIR = $(NPP_DIR)/TinyXml + +#WinControls +WIN_DIR = $(NPP_DIR)/WinControls + ABOUT_DIR = $(WIN_DIR)/AboutDlg + CONTEXT_DIR = $(WIN_DIR)/ContextMenu + COLOUR_DIR = $(WIN_DIR)/ColourPicker + DOCKING_DIR = $(WIN_DIR)/DockingWnd + GRID_DIR = $(WIN_DIR)/Grid + IMLIST_DIR = $(WIN_DIR)/ImageListSet + OPENSAVE_DIR = $(WIN_DIR)/OpenSaveFileDialog + # PANNER_DIR = $(WIN_DIR)/Panner + PREFERENCE_DIR = $(WIN_DIR)/Preference + SHORTCUT_DIR = $(WIN_DIR)/shortcut + SPLITTER_DIR = $(WIN_DIR)/SplitterContainer + STATICDLG_DIR = $(WIN_DIR)/StaticDialog + RUNDLG_DIR = $(STATICDLG_DIR)/RunDlg + STATUSBAR_DIR = $(WIN_DIR)/StatusBar + TABBAR_DIR = $(WIN_DIR)/TabBar + TASKLIST_DIR = $(WIN_DIR)/TaskList + TOOLBAR_DIR = $(WIN_DIR)/ToolBar + TOOLTIP_DIR = $(WIN_DIR)/ToolTip + TRAYICON_DIR = $(WIN_DIR)/TrayIcon + TREEVIEW_DIR = $(WIN_DIR)/TreeView + WINDOWSDLG_DIR = $(WIN_DIR)/WindowsDlg + + +# Sources: +SRC_NPP = $(wildcard $(NPP_DIR)/*.cpp) +SRC_GCCINCLUDE = $(wildcard $(GCCINCLUDE_DIR)/*.cpp) + +#MISC +SRC_MISC = $(wildcard $(MISC_DIR)/*.cpp) + SRC_COMMON = $(wildcard $(COMMON_DIR)/*.cpp) + SRC_EXCEPTION = $(wildcard $(EXCEPTION_DIR)/*.cpp) + SRC_PLUGINS = $(wildcard $(PLUGINS_DIR)/*.cpp) + SRC_PROCESS = $(wildcard $(PROCESS_DIR)/*.cpp) + SRC_REGEXT = $(wildcard $(REGEXT_DIR)/*.cpp) + +#ScintillaComponent +SRC_SCINT = $(wildcard $(SCINT_DIR)/*.cpp) + +#TinyXml +SRC_TIXML = $(wildcard $(TIXML_DIR)/*.cpp) + +#WinControls +SRC_WIN = $(wildcard $(WIN_DIR)/*.cpp) + SRC_ABOUT = $(wildcard $(ABOUT_DIR)/*.cpp) + SRC_CONTEXT = $(wildcard $(CONTEXT_DIR)/*.cpp) + SRC_COLOUR = $(wildcard $(COLOUR_DIR)/*.cpp) + SRC_DOCKING = $(wildcard $(DOCKING_DIR)/*.cpp) + SRC_GRID = $(wildcard $(GRID_DIR)/*.cpp) + SRC_IMLIST = $(wildcard $(IMLIST_DIR)/*.cpp) + SRC_OPENSAVE = $(wildcard $(OPENSAVE_DIR)/*.cpp) + SRC_PREFERENCE = $(wildcard $(PREFERENCE_DIR)/*.cpp) + SRC_SHORTCUT = $(wildcard $(SHORTCUT_DIR)/*.cpp) + SRC_SPLITTER = $(wildcard $(SPLITTER_DIR)/*.cpp) + SRC_STATICDLG = $(wildcard $(STATICDLG_DIR)/*.cpp) + SRC_RUNDLG = $(wildcard $(RUNDLG_DIR)/*.cpp) + SRC_STATUSBAR = $(wildcard $(STATUSBAR_DIR)/*.cpp) + SRC_TABBAR = $(wildcard $(TABBAR_DIR)/*.cpp) + SRC_TASKLIST = $(wildcard $(TASKLIST_DIR)/*.cpp) + SRC_TOOLBAR = $(wildcard $(TOOLBAR_DIR)/*.cpp) + SRC_TOOLTIP = $(wildcard $(TOOLTIP_DIR)/*.cpp) + SRC_TRAYICON = $(wildcard $(TRAYICON_DIR)/*.cpp) + SRC_TREEVIEW = $(wildcard $(TREEVIEW_DIR)/*.cpp) + SRC_WINDOWSDLG = $(wildcard $(WINDOWSDLG_DIR)/*.cpp) + +# Objects: +OBJ_NPP = $(patsubst %.cpp,%.o,$(SRC_NPP)) +OBJ_GCCINCLUDE = $(patsubst %.cpp,%.o,$(SRC_GCCINCLUDE)) + +#MISC +OBJ_MISC = $(patsubst %.cpp,%.o,$(SRC_MISC)) + OBJ_COMMON = $(patsubst %.cpp,%.o,$(SRC_COMMON)) + OBJ_EXCEPTION = $(patsubst %.cpp,%.o,$(SRC_EXCEPTION)) + OBJ_PLUGINS = $(patsubst %.cpp,%.o,$(SRC_PLUGINS)) + OBJ_PROCESS = $(patsubst %.cpp,%.o,$(SRC_PROCESS)) + OBJ_REGEXT = $(patsubst %.cpp,%.o,$(SRC_REGEXT)) + +#ScintillaComponent +OBJ_SCINT = $(patsubst %.cpp,%.o,$(SRC_SCINT)) + +#TinyXml +OBJ_TIXML = $(patsubst %.cpp,%.o,$(SRC_TIXML)) + +#WinControls +OBJ_WIN = $(patsubst %.cpp,%.o,$(SRC_WIN)) + OBJ_ABOUT = $(patsubst %.cpp,%.o,$(SRC_ABOUT)) + OBJ_CONTEXT = $(patsubst %.cpp,%.o,$(SRC_CONTEXT)) + OBJ_COLOUR = $(patsubst %.cpp,%.o,$(SRC_COLOUR)) + OBJ_DOCKING = $(patsubst %.cpp,%.o,$(SRC_DOCKING)) + OBJ_GRID = $(patsubst %.cpp,%.o,$(SRC_GRID)) + OBJ_IMLIST = $(patsubst %.cpp,%.o,$(SRC_IMLIST)) + OBJ_OPENSAVE = $(patsubst %.cpp,%.o,$(SRC_OPENSAVE)) + OBJ_PREFERENCE = $(patsubst %.cpp,%.o,$(SRC_PREFERENCE)) + OBJ_SHORTCUT = $(patsubst %.cpp,%.o,$(SRC_SHORTCUT)) + OBJ_SPLITTER = $(patsubst %.cpp,%.o,$(SRC_SPLITTER)) + OBJ_STATICDLG = $(patsubst %.cpp,%.o,$(SRC_STATICDLG)) + OBJ_RUNDLG = $(patsubst %.cpp,%.o,$(SRC_RUNDLG)) + OBJ_STATUSBAR = $(patsubst %.cpp,%.o,$(SRC_STATUSBAR)) + OBJ_TABBAR = $(patsubst %.cpp,%.o,$(SRC_TABBAR)) + OBJ_TASKLIST = $(patsubst %.cpp,%.o,$(SRC_TASKLIST)) + OBJ_TOOLBAR = $(patsubst %.cpp,%.o,$(SRC_TOOLBAR)) + OBJ_TOOLTIP = $(patsubst %.cpp,%.o,$(SRC_TOOLTIP)) + OBJ_TRAYICON = $(patsubst %.cpp,%.o,$(SRC_TRAYICON)) + OBJ_TREEVIEW = $(patsubst %.cpp,%.o,$(SRC_TREEVIEW)) + OBJ_WINDOWSDLG = $(patsubst %.cpp,%.o,$(SRC_WINDOWSDLG)) + +# Collections +DIRS_WIN = $(WIN_DIR) $(ABOUT_DIR) $(CONTEXT_DIR) $(COLOUR_DIR) $(DOCKING_DIR) $(GRID_DIR) $(IMLIST_DIR) $(OPENSAVE_DIR) $(PREFERENCE_DIR) $(SHORTCUT_DIR) $(SPLITTER_DIR) $(STATICDLG_DIR) $(RUNDLG_DIR) $(STATUSBAR_DIR) $(TABBAR_DIR) $(TASKLIST_DIR) $(TOOLBAR_DIR) $(TOOLTIP_DIR) $(TRAYICON_DIR) $(TREEVIEW_DIR) $(WINDOWSDLG_DIR) +DIRS_TIXML = $(TIXML_DIR) +DIRS_SCINT = $(SCINT_DIR) +DIRS_MISC = $(MISC_DIR) $(COMMON_DIR) $(EXCEPTION_DIR) $(PLUGINS_DIR) $(PROCESS_DIR) $(REGEXT_DIR) +DIRS = $(NPP_DIR) $(DIRS_WIN) $(DIRS_TIXML) $(DIRS_SCINT) $(DIRS_MISC) $(SCI_DIR) + +SRCS_WIN = $(SRC_WIN) $(SRC_ABOUT) $(SRC_CONTEXT) $(SRC_COLOUR) $(SRC_DOCKING) $(SRC_GRID) $(SRC_IMLIST) $(SRC_OPENSAVE) $(SRC_PREFERENCE) $(SRC_SHORTCUT) $(SRC_SPLITTER) $(SRC_STATICDLG) $(SRC_RUNDLG) $(SRC_STATUSBAR) $(SRC_TABBAR) $(SRC_TASKLIST) $(SRC_TOOLBAR) $(SRC_TOOLTIP) $(SRC_TRAYICON) $(SRC_TREEVIEW) $(SRC_WINDOWSDLG) +SRCS_TIXML = $(SRC_TIXML) +SRCS_SCINT = $(SRC_SCINT) +SRCS_MISC = $(SRC_MISC) $(SRC_COMMON) $(SRC_EXCEPTION) $(SRC_PLUGINS) $(SRC_PROCESS) $(SRC_REGEXT) +SRCS = $(SRC_NPP) $(SRCS_WIN) $(SRCS_TIXML) $(SRCS_SCINT) $(SRCS_MISC) $(SRC_GCCINCLUDE) + +OBJS_WIN = $(OBJ_WIN) $(OBJ_ABOUT) $(OBJ_CONTEXT) $(OBJ_COLOUR) $(OBJ_DOCKING) $(OBJ_GRID) $(OBJ_IMLIST) $(OBJ_OPENSAVE) $(OBJ_PREFERENCE) $(OBJ_SHORTCUT) $(OBJ_SPLITTER) $(OBJ_STATICDLG) $(OBJ_RUNDLG) $(OBJ_STATUSBAR) $(OBJ_TABBAR) $(OBJ_TASKLIST) $(OBJ_TOOLBAR) $(OBJ_TOOLTIP) $(OBJ_TRAYICON) $(OBJ_TREEVIEW) $(OBJ_WINDOWSDLG) +OBJS_TIXML = $(OBJ_TIXML) +OBJS_SCINT = $(OBJ_SCINT) +OBJS_MISC = $(OBJ_MISC) $(OBJ_COMMON) $(OBJ_EXCEPTION) $(OBJ_PLUGINS) $(OBJ_PROCESS) $(OBJ_REGEXT) +OBJS = $(OBJ_NPP) $(OBJS_WIN) $(OBJS_TIXML) $(OBJS_SCINT) $(OBJS_MISC) $(OBJ_GCCINCLUDE) + +# Main resource file +SRC_RES = ./resources.rc +OBJ_RES = $(patsubst %.rc,%.res,$(SRC_RES)) + +# Parameters +INCLUDESPECIAL = -include./include/various.h -includeCommon.h +# Comment this out for ANSI build +UNICODE = -DUNICODE -D_UNICODE + +CXX = g++ +#CXXFLAGS = -O2 $(INCLUDESPECIAL) +CXXFLAGS = $(INCLUDESPECIAL) -DTIXML_USE_STL $(UNICODE) +INCLUDES = $(patsubst %,-I%,$(DIRS)) -I./include +LDFLAGS = -Wl,--subsystem,windows +LIBS = -lcomdlg32 -lcomctl32 -lgdi32 -lole32 -loleacc -lshell32 -lshlwapi + +RC = windres + +OUT_NPP = NotepadPP.exe + +EXEC = ../bin/$(OUT_NPP) + +all: NotepadPP + +# Main Notepad++ rule +NotepadPP: $(OBJS) $(OBJ_RES) + $(CXX) $(CXXFLAGS) $(INCLUDES) $(LDFLAGS) $(OBJS) $(OBJ_RES) -o $(EXEC) $(LIBS) + +NotepadPPUnicode: $(OBJS) $(OBJ_RES) + $(CXX) $(CXXFLAGS) $(INCLUDES) $(LDFLAGS) $(OBJS) $(OBJ_RES) -o $(EXEC) $(LIBS) + +%.o: %.cpp + $(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@ + +%.res: %.rc + $(RC) $(INCLUDES) $(UNICODE) --input=$< --output=$@ --input-format=rc --output-format=coff + +# Cleanup +clean: + @delete.bat diff --git a/PowerEditor/gcc/readme.txt b/PowerEditor/gcc/readme.txt new file mode 100644 index 00000000..26b20b6a --- /dev/null +++ b/PowerEditor/gcc/readme.txt @@ -0,0 +1,5 @@ +makefile was renewed after the v5.0 release. +It was testing with a MingW distribution containing +gcc (GCC) 3.4.5 (mingw-vista special r3) +The default make rule should suffice for building Notepad++, +the clean rule call batch file with commands to remove .o files and resource file \ No newline at end of file diff --git a/PowerEditor/gcc/resources.rc b/PowerEditor/gcc/resources.rc new file mode 100644 index 00000000..c39177f0 --- /dev/null +++ b/PowerEditor/gcc/resources.rc @@ -0,0 +1,19 @@ +#include "./include/various.h" + +#define TEXT(quote) quote + +#include "../src/ScitillaComponent/columnEditor.rc" +#include "../src/ScitillaComponent/FindReplaceDlg.rc" +#include "../src/ScitillaComponent/UserDefineDialog.rc" +#include "../src/MISC/RegExt/regExtDlg.rc" +#include "../src/WinControls/ColourPicker/ColourPopup.rc" +#include "../src/WinControls/ColourPicker/WordStyleDlg.rc" +#include "../src/WinControls/DockingWnd/DockingGUIWidget.rc" +#include "../src/WinControls/Grid/ShortcutMapper.rc" +#include "../src/WinControls/Preference/preference.rc" +#include "../src/WinControls/shortcut/RunMacroDlg.rc" +#include "../src/WinControls/shortcut/shortcut.rc" +#include "../src/WinControls/TaskList/TaskListDlg.rc" +#include "../src/WinControls/StaticDialog/RunDlg/RunDlg.rc" +#include "../src/WinControls/WindowsDlg/WindowsDlg.rc" +#include "../src/Notepad_plus.rc" diff --git a/PowerEditor/installer/bin/xmlUpdater.exe b/PowerEditor/installer/bin/xmlUpdater.exe new file mode 100644 index 00000000..8f65ebb3 Binary files /dev/null and b/PowerEditor/installer/bin/xmlUpdater.exe differ diff --git a/PowerEditor/installer/configModel.xml b/PowerEditor/installer/configModel.xml new file mode 100644 index 00000000..bcef6f65 --- /dev/null +++ b/PowerEditor/installer/configModel.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/PowerEditor/installer/externalTools/md5summer.exe b/PowerEditor/installer/externalTools/md5summer.exe new file mode 100644 index 00000000..d33cbcc6 Binary files /dev/null and b/PowerEditor/installer/externalTools/md5summer.exe differ diff --git a/PowerEditor/installer/images/header.bmp b/PowerEditor/installer/images/header.bmp new file mode 100644 index 00000000..f49d7def Binary files /dev/null and b/PowerEditor/installer/images/header.bmp differ diff --git a/PowerEditor/installer/images/headerLeft.bmp b/PowerEditor/installer/images/headerLeft.bmp new file mode 100644 index 00000000..903d555e Binary files /dev/null and b/PowerEditor/installer/images/headerLeft.bmp differ diff --git a/PowerEditor/installer/images/headerRight.bmp b/PowerEditor/installer/images/headerRight.bmp new file mode 100644 index 00000000..eb1879a5 Binary files /dev/null and b/PowerEditor/installer/images/headerRight.bmp differ diff --git a/PowerEditor/installer/images/npp_inst.ico b/PowerEditor/installer/images/npp_inst.ico new file mode 100644 index 00000000..2cfff11c Binary files /dev/null and b/PowerEditor/installer/images/npp_inst.ico differ diff --git a/PowerEditor/installer/images/splash.bmp b/PowerEditor/installer/images/splash.bmp new file mode 100644 index 00000000..aba252a0 Binary files /dev/null and b/PowerEditor/installer/images/splash.bmp differ diff --git a/PowerEditor/installer/images/wizard.bmp b/PowerEditor/installer/images/wizard.bmp new file mode 100644 index 00000000..5c2f11d4 Binary files /dev/null and b/PowerEditor/installer/images/wizard.bmp differ diff --git a/PowerEditor/installer/langsModel.xml b/PowerEditor/installer/langsModel.xml new file mode 100644 index 00000000..ba690cfa --- /dev/null +++ b/PowerEditor/installer/langsModel.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/PowerEditor/installer/nppSetup.nsi b/PowerEditor/installer/nppSetup.nsi new file mode 100644 index 00000000..1fe18599 --- /dev/null +++ b/PowerEditor/installer/nppSetup.nsi @@ -0,0 +1,1011 @@ +;this file is part of installer for Notepad++ +;Copyright (C)2006 Don HO +; +;This program is free software; you can redistribute it and/or +;modify it under the terms of the GNU General Public License +;as published by the Free Software Foundation; either +;version 2 of the License, or (at your option) any later version. +; +;This program is distributed in the hope that it will be useful, +;but WITHOUT ANY WARRANTY; without even the implied warranty of +;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;GNU General Public License for more details. +; +;You should have received a copy of the GNU General Public License +;along with this program; if not, write to the Free Software +;Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +; Define the application name +!define APPNAME "Notepad++" +!define APPVERSION "5.3.1" +!define APPNAMEANDVERSION "Notepad++ v5.3.1" +!define APPWEBSITE "http://notepad-plus.sourceforge.net/" + +!define VERSION_MAJOR 5 +!define VERSION_MINOR 31 + +; Main Install settings +Name "${APPNAMEANDVERSION}" +InstallDir "$PROGRAMFILES\Notepad++" +InstallDirRegKey HKLM "Software\${APPNAME}" "" +OutFile "..\bin\npp.5.3.1.Installer.exe" + +; GetWindowsVersion + ; + ; Based on Yazno's function, http://yazno.tripod.com/powerpimpit/ + ; Updated by Joost Verburg + ; + ; Returns on top of stack + ; + ; Windows Version (95, 98, ME, NT x.x, 2000, XP, 2003, Vista) + ; or + ; '' (Unknown Windows Version) + ; + ; Usage: + ; Call GetWindowsVersion + ; Pop $R0 + ; ; at this point $R0 is "NT 4.0" or whatnot + +Function GetWindowsVersion + + Push $R0 + Push $R1 + + ClearErrors + + ReadRegStr $R0 HKLM \ + "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion + + IfErrors 0 lbl_winnt + + ; we are not NT + ReadRegStr $R0 HKLM \ + "SOFTWARE\Microsoft\Windows\CurrentVersion" VersionNumber + + StrCpy $R1 $R0 1 + StrCmp $R1 '4' 0 lbl_error + + StrCpy $R1 $R0 3 + + StrCmp $R1 '4.0' lbl_win32_95 + StrCmp $R1 '4.9' lbl_win32_ME lbl_win32_98 + + lbl_win32_95: + StrCpy $R0 '95' + Goto lbl_done + + lbl_win32_98: + StrCpy $R0 '98' + Goto lbl_done + + lbl_win32_ME: + StrCpy $R0 'ME' + Goto lbl_done + + lbl_winnt: + + StrCpy $R1 $R0 1 + + StrCmp $R1 '3' lbl_winnt_x + StrCmp $R1 '4' lbl_winnt_x + + StrCpy $R1 $R0 3 + + StrCmp $R1 '5.0' lbl_winnt_2000 + StrCmp $R1 '5.1' lbl_winnt_XP + StrCmp $R1 '5.2' lbl_winnt_2003 + StrCmp $R1 '6.0' lbl_winnt_vista lbl_error + + lbl_winnt_x: + StrCpy $R0 "NT $R0" 6 + Goto lbl_done + + lbl_winnt_2000: + Strcpy $R0 '2000' + Goto lbl_done + + lbl_winnt_XP: + Strcpy $R0 'XP' + Goto lbl_done + + lbl_winnt_2003: + Strcpy $R0 '2003' + Goto lbl_done + + lbl_winnt_vista: + Strcpy $R0 'Vista' + Goto lbl_done + + lbl_error: + Strcpy $R0 '' + lbl_done: + + Pop $R1 + Exch $R0 + +FunctionEnd + +Function LaunchNpp + Exec '"$INSTDIR\notepad++.exe" "$INSTDIR\change.log" ' +FunctionEnd + +; Modern interface settings +!include "MUI.nsh" +!include "x64.nsh" + +!define MUI_ICON ".\images\npp_inst.ico" + +!define MUI_WELCOMEFINISHPAGE_BITMAP ".\images\wizard.bmp" +!define MUI_WELCOMEFINISHPAGE_BITMAP_NOSTRETCH + +!define MUI_HEADERIMAGE +;!define MUI_HEADERIMAGE_RIGHT +;!define MUI_HEADERIMAGE_BITMAP ".\images\headerRight.bmp" ; optional +!define MUI_HEADERIMAGE_BITMAP ".\images\headerLeft.bmp" ; optional +!define MUI_ABORTWARNING + + + +!insertmacro MUI_PAGE_WELCOME +!insertmacro MUI_PAGE_LICENSE "..\license.txt" +!insertmacro MUI_PAGE_DIRECTORY +!insertmacro MUI_PAGE_COMPONENTS +!insertmacro MUI_PAGE_INSTFILES + +!define MUI_FINISHPAGE_RUN +;!define MUI_FINISHPAGE_RUN_TEXT "Run Npp" +!define MUI_FINISHPAGE_RUN_FUNCTION "LaunchNpp" +!insertmacro MUI_PAGE_FINISH + +!insertmacro MUI_UNPAGE_CONFIRM +!insertmacro MUI_UNPAGE_INSTFILES + +; Set languages (first is default language) +;!insertmacro MUI_LANGUAGE "English" + +;Languages + + !insertmacro MUI_LANGUAGE "English" + !insertmacro MUI_LANGUAGE "French" + !insertmacro MUI_LANGUAGE "TradChinese" + !insertmacro MUI_LANGUAGE "Spanish" + !insertmacro MUI_LANGUAGE "Hungarian" + !insertmacro MUI_LANGUAGE "Russian" + !insertmacro MUI_LANGUAGE "German" + !insertmacro MUI_LANGUAGE "Dutch" + !insertmacro MUI_LANGUAGE "SimpChinese" + !insertmacro MUI_LANGUAGE "Italian" + !insertmacro MUI_LANGUAGE "Danish" + !insertmacro MUI_LANGUAGE "Polish" + !insertmacro MUI_LANGUAGE "Czech" + !insertmacro MUI_LANGUAGE "Slovenian" + !insertmacro MUI_LANGUAGE "Slovak" + !insertmacro MUI_LANGUAGE "Swedish" + !insertmacro MUI_LANGUAGE "Norwegian" + !insertmacro MUI_LANGUAGE "PortugueseBR" + !insertmacro MUI_LANGUAGE "Ukrainian" + !insertmacro MUI_LANGUAGE "Turkish" + !insertmacro MUI_LANGUAGE "Catalan" + !insertmacro MUI_LANGUAGE "Arabic" + !insertmacro MUI_LANGUAGE "Lithuanian" + !insertmacro MUI_LANGUAGE "Finnish" + !insertmacro MUI_LANGUAGE "Greek" + !insertmacro MUI_LANGUAGE "Romanian" + !insertmacro MUI_LANGUAGE "Korean" + !insertmacro MUI_LANGUAGE "Hebrew" + !insertmacro MUI_LANGUAGE "Portuguese" + !insertmacro MUI_LANGUAGE "Farsi" + !insertmacro MUI_LANGUAGE "Bulgarian" + !insertmacro MUI_LANGUAGE "Indonesian" + !insertmacro MUI_LANGUAGE "Japanese" + !insertmacro MUI_LANGUAGE "Croatian" + !insertmacro MUI_LANGUAGE "Serbian" + !insertmacro MUI_LANGUAGE "Thai" + !insertmacro MUI_LANGUAGE "NorwegianNynorsk" + !insertmacro MUI_LANGUAGE "Belarusian" + !insertmacro MUI_LANGUAGE "Albanian" + !insertmacro MUI_LANGUAGE "Malay" + !insertmacro MUI_LANGUAGE "Galician" + !insertmacro MUI_LANGUAGE "Basque" + !insertmacro MUI_LANGUAGE "Luxembourgish" + + ;!insertmacro MUI_LANGUAGE "Latvian" + ;!insertmacro MUI_LANGUAGE "Macedonian" + ;!insertmacro MUI_LANGUAGE "Estonian" + ; !insertmacro MUI_LANGUAGE "Mongolian" + ;!insertmacro MUI_LANGUAGE "Breton" + ;!insertmacro MUI_LANGUAGE "Icelandic" + ;!insertmacro MUI_LANGUAGE "Bosnian" + ;!insertmacro MUI_LANGUAGE "Kurdish" + ;!insertmacro MUI_LANGUAGE "Irish" + ;!insertmacro MUI_LANGUAGE "Uzbek" + ;!insertmacro MUI_LANGUAGE "Afrikaans" + +!insertmacro MUI_RESERVEFILE_LANGDLL + +;Installer Functions + + +Function .onInit + + ;Test if window9x + Call GetWindowsVersion + Pop $R0 + + StrCmp $R0 "95" 0 +3 + MessageBox MB_OK "The installer contains only Unicode version of Notepad++, which is not compatible with your Windows 95.$\nPlease use ANSI version in zipped package, which you can download here :$\nhttps://sourceforge.net/project/showfiles.php?group_id=95717&package_id=102072" + Abort + + StrCmp $R0 "98" 0 +3 + MessageBox MB_OK "The installer contains only Unicode version of Notepad++, which is not compatible with your Windows 98.$\nPlease use ANSI version in zipped package, which you can download here :$\nhttps://sourceforge.net/project/showfiles.php?group_id=95717&package_id=102072" + Abort + + StrCmp $R0 "ME" 0 +3 + MessageBox MB_OK "The installer contains only Unicode version of Notepad++,, which is not compatible with your Windows ME.$\nPlease use ANSI version in zipped package, which you can download here :$\nhttps://sourceforge.net/project/showfiles.php?group_id=95717&package_id=102072" + Abort + + !insertmacro MUI_LANGDLL_DISPLAY + # the plugins dir is automatically deleted when the installer exits + ;InitPluginsDir + ;File /oname=$PLUGINSDIR\splash.bmp ".\images\splash.bmp" + #optional + #File /oname=$PLUGINSDIR\splash.wav "C:\myprog\sound.wav" + + ;splash::show 1000 $PLUGINSDIR\splash + + ;Pop $0 ; $0 has '1' if the user closed the splash screen early, + ; '0' if everything closed normally, and '-1' if some error occurred. + +FunctionEnd + +LangString langFileName ${LANG_ENGLISH} "english.xml" +LangString langFileName ${LANG_FRENCH} "french.xml" +LangString langFileName ${LANG_TRADCHINESE} "chinese.xml" +LangString langFileName ${LANG_GERMAN} "german.xml" +LangString langFileName ${LANG_SPANISH} "spanish.xml" +LangString langFileName ${LANG_HUNGARIAN} "hungarian.xml" +LangString langFileName ${LANG_RUSSIAN} "russian.xml" +LangString langFileName ${LANG_DUTCH} "dutch.xml" +LangString langFileName ${LANG_SIMPCHINESE} "chineseSimplified.xml" +LangString langFileName ${LANG_ITALIAN} "italian.xml" +LangString langFileName ${LANG_DANISH} "danish.xml" +LangString langFileName ${LANG_POLISH} "polish.xml" +LangString langFileName ${LANG_CZECH} "czech.xml" +LangString langFileName ${LANG_SLOVENIAN} "slovenian.xml" +LangString langFileName ${LANG_SLOVAK} "slovak.xml" +LangString langFileName ${LANG_SWEDISH} "swedish.xml" +LangString langFileName ${LANG_NORWEGIAN} "norwegian.xml" +LangString langFileName ${LANG_PORTUGUESEBR} "brazilian_portuguese.xml" +LangString langFileName ${LANG_UKRAINIAN} "ukrainian.xml" +LangString langFileName ${LANG_TURKISH} "turkish.xml" +LangString langFileName ${LANG_CATALAN} "catalan.xml" +LangString langFileName ${LANG_ARABIC} "arabic.xml" +LangString langFileName ${LANG_LITHUANIAN} "lithuanian.xml" +LangString langFileName ${LANG_FINNISH} "finnish.xml" +LangString langFileName ${LANG_GREEK} "greek.xml" +LangString langFileName ${LANG_ROMANIAN} "romanian.xml" +LangString langFileName ${LANG_KOREAN} "korean.xml" +LangString langFileName ${LANG_HEBREW} "hebrew.xml" +LangString langFileName ${LANG_PORTUGUESE} "portuguese.xml" +LangString langFileName ${LANG_FARSI} "farsi.xml" +LangString langFileName ${LANG_BULGARIAN} "bulgarian.xml" +LangString langFileName ${LANG_INDONESIAN} "indonesian.xml" +LangString langFileName ${LANG_JAPANESE} "japanese.xml" +LangString langFileName ${LANG_CROATIAN} "croatian.xml" +LangString langFileName ${LANG_SERBIAN} "serbian.xml" +LangString langFileName ${LANG_THAI} "thai.xml" +LangString langFileName ${LANG_NORWEGIANNYNORSK} "nynorsk.xml" +LangString langFileName ${LANG_BELARUSIAN} "belarusian.xml" +LangString langFileName ${LANG_ALBANIAN} "albanian.xml" +LangString langFileName ${LANG_MALAY} "malay.xml" +LangString langFileName ${LANG_GALICIAN} "galician.xml" +LangString langFileName ${LANG_BASQUE} "basque.xml" +LangString langFileName ${LANG_LUXEMBOURGISH} "luxembourgish.xml" + + +;-------------------------------- +;Variables + Var IS_LOCAL +;-------------------------------- + +Section /o "Don't use %APPDATA%" makeLocal + StrCpy $IS_LOCAL "1" +SectionEnd + +Var UPDATE_PATH + +Section -"Notepad++" mainSection + + ; Set Section properties + SetOverwrite on + + StrCpy $UPDATE_PATH $INSTDIR + + ;SetOutPath "$TEMP\" + File /oname=$TEMP\xmlUpdater.exe ".\bin\xmlUpdater.exe" + + SetOutPath "$INSTDIR\" + + ; if isLocal -> copy file "doLocalConf.xml" + StrCmp $IS_LOCAL "1" 0 IS_NOT_LOCAL + File "..\bin\doLocalConf.xml" + goto GLOBAL_INST + +IS_NOT_LOCAL: + IfFileExists $INSTDIR\doLocalConf.xml 0 +2 + Delete $INSTDIR\doLocalConf.xml + + StrCpy $UPDATE_PATH "$APPDATA\Notepad++" + CreateDirectory $UPDATE_PATH\plugins\config + +GLOBAL_INST: + SetOutPath "$TEMP\" + File "langsModel.xml" + File "configModel.xml" + File "stylesModel.xml" + + File "..\bin\langs.model.xml" + File "..\bin\config.model.xml" + File "..\bin\stylers.model.xml" + File "..\bin\stylers_remove.xml" + + ;UPGRATE $INSTDIR\langs.xml + nsExec::ExecToStack '"$TEMP\xmlUpdater.exe" "$TEMP\langsModel.xml" "$TEMP\langs.model.xml" "$INSTDIR\langs.xml"' + nsExec::ExecToStack '"$TEMP\xmlUpdater.exe" "$TEMP\configModel.xml" "$TEMP\config.model.xml" "$UPDATE_PATH\config.xml"' + nsExec::ExecToStack '"$TEMP\xmlUpdater.exe" "$TEMP\stylesModel.xml" "$TEMP\stylers_remove.xml" "$UPDATE_PATH\stylers.xml"' + nsExec::ExecToStack '"$TEMP\xmlUpdater.exe" "$TEMP\stylesModel.xml" "$TEMP\stylers.model.xml" "$UPDATE_PATH\stylers.xml"' + + SetOutPath "$INSTDIR\" + File "..\bin\langs.model.xml" + File "..\bin\config.model.xml" + File "..\bin\stylers.model.xml" + File "..\bin\stylers_remove.xml" + + SetOverwrite off + File /oname=$INSTDIR\langs.xml "..\bin\langs.model.xml" + File "..\bin\contextMenu.xml" + File "..\bin\shortcuts.xml" + + ; Set Section Files and Shortcuts + + SetOverwrite on + File "..\license.txt" + File "..\bin\LINEDRAW.TTF" + File "..\bin\SciLexer.dll" + File "..\bin\change.log" + File "..\bin\notepad++.exe" + File "..\bin\readme.txt" + File "..\bin\NppHelp.chm" + + SetOutPath "$INSTDIR\localization\" + File ".\nativeLang\" + + IfFileExists "$UPDATE_PATH\nativeLang.xml" 0 +2 + Delete "$UPDATE_PATH\nativeLang.xml" + + IfFileExists "$INSTDIR\nativeLang.xml" 0 +2 + Delete "$INSTDIR\nativeLang.xml" + + StrCmp $LANGUAGE ${LANG_ENGLISH} +2 0 + CopyFiles "$INSTDIR\localization\$(langFileName)" "$INSTDIR\nativeLang.xml" + + ; remove all the npp shortcuts from current user + Delete "$DESKTOP\Notepad++.lnk" + Delete "$SMPROGRAMS\Notepad++\Notepad++.lnk" + Delete "$SMPROGRAMS\Notepad++\readme.lnk" + Delete "$SMPROGRAMS\Notepad++\Uninstall.lnk" + CreateDirectory "$SMPROGRAMS\Notepad++" + CreateShortCut "$SMPROGRAMS\Notepad++\Uninstall.lnk" "$INSTDIR\uninstall.exe" + + + ;clean + Delete "$INSTDIR\plugins\NPPTextFX\AsciiToEBCDIC.bin" + Delete "$INSTDIR\plugins\NPPTextFX\libTidy.dll" + Delete "$INSTDIR\plugins\NPPTextFX\TIDYCFG.INI" + Delete "$INSTDIR\plugins\NPPTextFX\W3C-CSSValidator.htm" + Delete "$INSTDIR\plugins\NPPTextFX\W3C-HTMLValidator.htm" + RMDir "$INSTDIR\plugins\NPPTextFX\" + + ; remove unstable plugins + IfFileExists "$INSTDIR\plugins\HexEditorPlugin.dll" 0 +3 + MessageBox MB_OK "Due to the problem of compability with this version,$\nHexEditorPlugin.dll is about to be deleted." + Delete "$INSTDIR\plugins\HexEditorPlugin.dll" + + IfFileExists "$INSTDIR\plugins\HexEditor.dll" 0 +3 + MessageBox MB_OK "Due to the problem of compability with this version,$\nHexEditor.dll is about to be deleted.$\nYou can download it via menu $\"?->Get more plugins$\" if you really need it." + Delete "$INSTDIR\plugins\HexEditor.dll" + + IfFileExists "$INSTDIR\plugins\MultiClipboard.dll" 0 +3 + MessageBox MB_OK "Due to the problem of compability with this version,$\nMultiClipboard.dll is about to be deleted.$\nYou can download it via menu $\"?->Get more plugins$\" if you really need it." + Delete "$INSTDIR\plugins\MultiClipboard.dll" + + Delete "$INSTDIR\plugins\NppDocShare.dll" + + IfFileExists "$INSTDIR\plugins\FunctionList.dll" 0 +3 + MessageBox MB_OK "Due to the problem of compability with this version,$\nFunctionList.dll is about to be deleted.$\nYou can download it via menu $\"?->Get more plugins$\" if you really need it." + Delete "$INSTDIR\plugins\FunctionList.dll" + + IfFileExists "$INSTDIR\plugins\NPPTextFX.ini" 0 +2 + Delete "$INSTDIR\plugins\NPPTextFX.ini" + + IfFileExists "$INSTDIR\plugins\NppAutoIndent.dll" 0 +3 + MessageBox MB_OK "Due to the stabilty issue,$\nNppAutoIndent.dll is about to be deleted.$\nYou can download it via menu $\"?->Get more plugins$\" if you really need it." + Delete "$INSTDIR\plugins\NppAutoIndent.dll" + + IfFileExists "$INSTDIR\plugins\ComparePlugin.dll" 0 +3 + MessageBox MB_OK "Due to the problem of compability with this version,$\nComparePlugin.dll is about to be deleted.$\nYou can download it via menu $\"?->Get more plugins$\" if you really need it." + Delete "$INSTDIR\plugins\ComparePlugin.dll" + + ; detect the right of + UserInfo::GetAccountType + Pop $1 + StrCmp $1 "Admin" 0 +2 + + SetShellVarContext all + ; add all the npp shortcuts for all user or current user + CreateDirectory "$SMPROGRAMS\Notepad++" + CreateShortCut "$DESKTOP\Notepad++.lnk" "$INSTDIR\notepad++.exe" + CreateShortCut "$SMPROGRAMS\Notepad++\Notepad++.lnk" "$INSTDIR\notepad++.exe" + CreateShortCut "$SMPROGRAMS\Notepad++\readme.lnk" "$INSTDIR\readme.txt" + SetShellVarContext current + WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\notepad++.exe" "" "$INSTDIR\notepad++.exe" +SectionEnd + +Section "Context Menu Entry" explorerContextMenu + SetOverwrite try + SetOutPath "$INSTDIR\" + ${If} ${RunningX64} + File /oname=$INSTDIR\nppcm.dll "..\bin\nppcm64.dll" + ${Else} + File "..\bin\nppcm.dll" + ${EndIf} + + Exec 'regsvr32 /s "$INSTDIR\nppcm.dll"' + Exec 'regsvr32 /u /s "$INSTDIR\nppshellext.dll"' + Delete "$INSTDIR\nppshellext.dll" +SectionEnd + +SubSection "Auto-completion Files" autoCompletionComponent + SetOverwrite off + + Section C + SetOutPath "$INSTDIR\plugins\APIs" + File "..\bin\plugins\APIs\c.xml" + SectionEnd + + Section C++ + SetOutPath "$INSTDIR\plugins\APIs" + File "..\bin\plugins\APIs\cpp.xml" + SectionEnd + + Section Java + SetOutPath "$INSTDIR\plugins\APIs" + File "..\bin\plugins\APIs\java.xml" + SectionEnd + + Section C# + SetOutPath "$INSTDIR\plugins\APIs" + File "..\bin\plugins\APIs\cs.xml" + SectionEnd + + Section HTML + SetOutPath "$INSTDIR\plugins\APIs" + File "..\bin\plugins\APIs\html.xml" + SectionEnd + + Section RC + SetOutPath "$INSTDIR\plugins\APIs" + File "..\bin\plugins\APIs\rc.xml" + SectionEnd + + Section SQL + SetOutPath "$INSTDIR\plugins\APIs" + File "..\bin\plugins\APIs\sql.xml" + SectionEnd + + Section PHP + SetOutPath "$INSTDIR\plugins\APIs" + File "..\bin\plugins\APIs\php.xml" + SectionEnd + + Section CSS + SetOutPath "$INSTDIR\plugins\APIs" + File "..\bin\plugins\APIs\css.xml" + SectionEnd + + Section VB + SetOutPath "$INSTDIR\plugins\APIs" + File "..\bin\plugins\APIs\vb.xml" + SectionEnd + + Section Perl + SetOutPath "$INSTDIR\plugins\APIs" + File "..\bin\plugins\APIs\perl.xml" + SectionEnd + + Section JavaScript + SetOutPath "$INSTDIR\plugins\APIs" + File "..\bin\plugins\APIs\javascript.xml" + SectionEnd + + Section Python + SetOutPath "$INSTDIR\plugins\APIs" + File "..\bin\plugins\APIs\python.xml" + SectionEnd + + Section ActionScript + SetOutPath "$INSTDIR\plugins\APIs" + File "..\bin\plugins\APIs\actionscript.xml" + SectionEnd + + Section LISP + SetOutPath "$INSTDIR\plugins\APIs" + File "..\bin\plugins\APIs\lisp.xml" + SectionEnd + + Section VHDL + SetOutPath "$INSTDIR\plugins\APIs" + File "..\bin\plugins\APIs\vhdl.xml" + SectionEnd + + Section TeX + SetOutPath "$INSTDIR\plugins\APIs" + File "..\bin\plugins\APIs\tex.xml" + SectionEnd + + Section DocBook + SetOutPath "$INSTDIR\plugins\APIs" + File "..\bin\plugins\APIs\xml.xml" + SectionEnd + + Section NSIS + SetOutPath "$INSTDIR\plugins\APIs" + File "..\bin\plugins\APIs\nsis.xml" + SectionEnd + + Section AWK + SetOutPath "$INSTDIR\plugins\APIs" + File "..\bin\plugins\APIs\awk.xml" + SectionEnd +SubSectionEnd + +SubSection "Plugins" Plugins + + SetOverwrite on + + Section "NPPTextFX" NPPTextFX + SetOutPath "$INSTDIR\plugins" + File "..\bin\plugins\NPPTextFX.dll" + + SetOutPath "$INSTDIR\plugins\Config\tidy" + File "..\bin\plugins\Config\tidy\AsciiToEBCDIC.bin" + File "..\bin\plugins\Config\tidy\libTidy.dll" + File "..\bin\plugins\Config\tidy\TIDYCFG.INI" + File "..\bin\plugins\Config\tidy\W3C-CSSValidator.htm" + File "..\bin\plugins\Config\tidy\W3C-HTMLValidator.htm" + + SetOutPath "$INSTDIR\plugins\doc" + File "..\bin\plugins\doc\NPPTextFXdemo.TXT" + SectionEnd + + + Section "NppNetNote" NppNetNote + Delete "$INSTDIR\plugins\NppNetNote.dll" + SetOutPath "$INSTDIR\plugins" + File "..\bin\plugins\NppNetNote.dll" + SectionEnd + + + Section "Spell-Checker" SpellChecker + Delete "$INSTDIR\plugins\SpellChecker.dll" + SetOutPath "$INSTDIR\plugins" + File "..\bin\plugins\SpellChecker.dll" + SectionEnd + + Section "NppExec" NppExec + Delete "$INSTDIR\plugins\NppExec.dll" + SetOutPath "$INSTDIR\plugins" + File "..\bin\plugins\NppExec.dll" + SetOutPath "$INSTDIR\plugins\doc" + File "..\bin\plugins\doc\NppExec.txt" + File "..\bin\plugins\doc\NppExec_Guide.txt" + File "..\bin\plugins\doc\NppExec_TechInfo.txt" + SectionEnd + + Section "MIME Tools" MIMETools + Delete "$INSTDIR\plugins\NppTools.dll" + Delete "$INSTDIR\plugins\mimeTools.dll" + SetOutPath "$INSTDIR\plugins" + File "..\bin\plugins\mimeTools.dll" + SectionEnd + + Section "FTP synchronize" FTP_synchronize + Delete "$INSTDIR\plugins\FTP_synchronizeA.dll" + SetOutPath "$INSTDIR\plugins" + File "..\bin\plugins\FTP_synchronize.dll" + SetOutPath "$INSTDIR\plugins\doc" + File "..\bin\plugins\doc\FTP_synchonize.ReadMe.txt" + SectionEnd + + Section "NppExport" NppExport + Delete "$INSTDIR\plugins\NppExport.dll" + SetOutPath "$INSTDIR\plugins" + File "..\bin\plugins\NppExport.dll" + SectionEnd +/* + Section "ComparePlugin" ComparePlugin + Delete "$INSTDIR\plugins\ComparePlugin.dll" + SetOutPath "$INSTDIR\plugins" + File "..\bin\plugins\ComparePlugin.dll" + SectionEnd + + + Section "NppAutoIndent" NppAutoIndent + Delete "$INSTDIR\plugins\NppAutoIndent.dll" + SetOutPath "$INSTDIR\plugins" + File "..\bin\plugins\NppAutoIndent.dll" + + StrCmp $IS_LOCAL "1" 0 NOT_LOCAL + SetOutPath "$INSTDIR\plugins\Config\" + goto LOCAL + NOT_LOCAL: + SetOutPath "$APPDATA\Notepad++\plugins\Config\" + LOCAL: + File "..\bin\plugins\Config\NppAutoIndent.ini" + + SectionEnd +*/ + Section "Document Monitor" DocMonitor + Delete "$INSTDIR\plugins\docMonitor.dll" + SetOutPath "$INSTDIR\plugins" + File "..\bin\plugins\docMonitor.dll" + SectionEnd +SubSectionEnd + +Section /o "As default html viewer" htmlViewer + SetOutPath "$INSTDIR\" + File "..\bin\nppIExplorerShell.exe" + WriteRegStr HKLM "SOFTWARE\Microsoft\Internet Explorer\View Source Editor\Editor Name" "" "$INSTDIR\nppIExplorerShell.exe" +SectionEnd + +InstType "o" + +Section "Auto-Updater" AutoUpdater + SetOutPath "$INSTDIR\updater" + File "..\bin\updater\GUP.exe" + File "..\bin\updater\libcurl.dll" + File "..\bin\updater\gup.xml" + File "..\bin\updater\License.txt" + File "..\bin\updater\gpl.txt" + File "..\bin\updater\readme.txt" + File "..\bin\updater\getDownLoadUrl.php" +SectionEnd + +;-------------------------------- +;Descriptions + + ;Language strings + + ;Assign language strings to sections + !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN + !insertmacro MUI_DESCRIPTION_TEXT ${makeLocal} 'Enable this option to make Notepad++ load/write the configuration files from/to its install directory. Check it if you use Notepad++ in an USB device.' + !insertmacro MUI_DESCRIPTION_TEXT ${explorerContextMenu} 'Explorer context menu entry for Notepad++ : Open whatever you want in Notepad++ from Windows Explorer.' + !insertmacro MUI_DESCRIPTION_TEXT ${autoCompletionComponent} 'Install the API files you need for the auto-completion feature (Ctrl+Space).' + !insertmacro MUI_DESCRIPTION_TEXT ${Plugins} 'You may need those plugins to extend the capacity of Notepad++.' + !insertmacro MUI_DESCRIPTION_TEXT ${htmlViewer} 'Open the html file in Notepad++ while you choose from IE.' + !insertmacro MUI_DESCRIPTION_TEXT ${AutoUpdater} 'Keep your Notepad++ update: Check this option to install an update module which searches Notepad++ update on Internet and install it for you.' + !insertmacro MUI_FUNCTION_DESCRIPTION_END + +;-------------------------------- + +Section -FinishSection + + WriteRegStr HKLM "Software\${APPNAME}" "" "$INSTDIR" + WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "DisplayName" "${APPNAME}" + WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "UninstallString" "$INSTDIR\uninstall.exe" + WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "DisplayIcon" "$INSTDIR\notepad++.exe" + WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "DisplayVersion" "${APPVERSION}" + WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" "URLInfoAbout" "${APPWEBSITE}" + WriteUninstaller "$INSTDIR\uninstall.exe" + +SectionEnd + + +;Uninstall section + +SubSection un.autoCompletionComponent + Section un.PHP + Delete "$INSTDIR\plugins\APIs\php.xml" + RMDir "$INSTDIR\plugins\APIs\" + SectionEnd + + Section un.CSS + Delete "$INSTDIR\plugins\APIs\css.xml" + RMDir "$INSTDIR\plugins\APIs\" + SectionEnd + + Section un.HTML + Delete "$INSTDIR\plugins\APIs\html.xml" + RMDir "$INSTDIR\plugins\APIs\" + SectionEnd + + Section un.SQL + Delete "$INSTDIR\plugins\APIs\sql.xml" + RMDir "$INSTDIR\plugins\APIs\" + SectionEnd + + Section un.RC + Delete "$INSTDIR\plugins\APIs\rc.xml" + RMDir "$INSTDIR\plugins\APIs\" + SectionEnd + + Section un.VB + Delete "$INSTDIR\plugins\APIs\vb.xml" + RMDir "$INSTDIR\plugins\APIs\" + SectionEnd + + Section un.Perl + Delete "$INSTDIR\plugins\APIs\perl.xml" + RMDir "$INSTDIR\plugins\APIs\" + SectionEnd + + Section un.C + Delete "$INSTDIR\plugins\APIs\c.xml" + RMDir "$INSTDIR\plugins\APIs\" + SectionEnd + + Section un.C++ + Delete "$INSTDIR\plugins\APIs\cpp.xml" + RMDir "$INSTDIR\plugins\APIs\" + SectionEnd + + Section un.Java + Delete "$INSTDIR\plugins\APIs\java.xml" + RMDir "$INSTDIR\plugins\APIs\" + SectionEnd + + Section un.C# + Delete "$INSTDIR\plugins\APIs\cs.xml" + RMDir "$INSTDIR\plugins\APIs\" + SectionEnd + + Section un.JavaScript + Delete "$INSTDIR\plugins\APIs\javascript.xml" + RMDir "$INSTDIR\plugins\APIs\" + SectionEnd + + Section un.Python + Delete "$INSTDIR\plugins\APIs\python.xml" + RMDir "$INSTDIR\plugins\APIs\" + SectionEnd + + Section un.ActionScript + Delete "$INSTDIR\plugins\APIs\actionscript.xml" + RMDir "$INSTDIR\plugins\APIs\" + SectionEnd + + Section un.LISP + Delete "$INSTDIR\plugins\APIs\lisp.xml" + RMDir "$INSTDIR\plugins\APIs\" + SectionEnd + + Section un.VHDL + Delete "$INSTDIR\plugins\APIs\vhdl.xml" + RMDir "$INSTDIR\plugins\APIs\" + SectionEnd + + Section un.TeX + Delete "$INSTDIR\plugins\APIs\tex.xml" + RMDir "$INSTDIR\plugins\APIs\" + SectionEnd + + Section un.DocBook + Delete "$INSTDIR\plugins\APIs\xml.xml" + RMDir "$INSTDIR\plugins\APIs\" + SectionEnd + + Section un.NSIS + Delete "$INSTDIR\plugins\APIs\nsis.xml" + RMDir "$INSTDIR\plugins\APIs\" + SectionEnd + + Section un.AWK + Delete "$INSTDIR\plugins\APIs\awk.xml" + RMDir "$INSTDIR\plugins\APIs\" + SectionEnd + +SubSectionEnd + +SubSection un.Plugins + Section un.NPPTextFX + Delete "$INSTDIR\plugins\NPPTextFX.dll" + Delete "$INSTDIR\plugins\NPPTextFX.ini" + Delete "$APPDATA\Notepad++\NPPTextFX.ini" + Delete "$INSTDIR\plugins\doc\NPPTextFXdemo.TXT" + Delete "$INSTDIR\plugins\Config\tidy\AsciiToEBCDIC.bin" + Delete "$INSTDIR\plugins\Config\tidy\libTidy.dll" + Delete "$INSTDIR\plugins\Config\tidy\TIDYCFG.INI" + Delete "$INSTDIR\plugins\Config\tidy\W3C-CSSValidator.htm" + Delete "$INSTDIR\plugins\Config\tidy\W3C-HTMLValidator.htm" + RMDir "$INSTDIR\plugins\tidy\" + RMDir "$INSTDIR\plugins\" + SectionEnd + + Section un.NppNetNote + Delete "$INSTDIR\plugins\NppNetNote.dll" + Delete "$INSTDIR\plugins\Config\NppNetNote.ini" + RMDir "$INSTDIR\plugins\" + SectionEnd + + Section un.NppAutoIndent + Delete "$INSTDIR\plugins\NppAutoIndent.dll" + Delete "$INSTDIR\plugins\Config\NppAutoIndent.ini" + RMDir "$INSTDIR\plugins\" + SectionEnd + + Section un.MIMETools + Delete "$INSTDIR\plugins\NppTools.dll" + Delete "$INSTDIR\plugins\mimeTools.dll" + RMDir "$INSTDIR\plugins\" + SectionEnd + + Section un.FTP_synchronize + Delete "$INSTDIR\plugins\FTP_synchronize.dll" + Delete "$INSTDIR\plugins\Config\FTP_synchronize.ini" + Delete "$INSTDIR\plugins\doc\FTP_synchonize.ReadMe.txt" + RMDir "$INSTDIR\plugins\" + SectionEnd + + Section un.NppExport + Delete "$INSTDIR\plugins\NppExport.dll" + RMDir "$INSTDIR\plugins\" + SectionEnd + + Section un.DocMonitor + Delete "$INSTDIR\plugins\docMonitor.dll" + Delete "$INSTDIR\plugins\Config\docMonitor.ini" + RMDir "$INSTDIR\plugins\" + SectionEnd + + + + + Section un.FileBrowserLite + Delete "$INSTDIR\plugins\LightExplorer.dll" + Delete "$INSTDIR\lightExplorer.ini" + RMDir "$INSTDIR\plugins\" + SectionEnd + Section un.HexEditor + Delete "$INSTDIR\plugins\HexEditor.dll" + RMDir "$INSTDIR\plugins\" + SectionEnd + Section un.ConvertExt + Delete "$INSTDIR\plugins\ConvertExt.dll" + Delete "$APPDATA\Notepad++\ConvertExt.ini" + Delete "$APPDATA\Notepad++\ConvertExt.enc" + Delete "$APPDATA\Notepad++\ConvertExt.lng" + Delete "$INSTDIR\ConvertExt.ini" + Delete "$INSTDIR\ConvertExt.enc" + Delete "$INSTDIR\ConvertExt.lng" + RMDir "$INSTDIR\plugins\" + SectionEnd + Section un.SpellChecker + Delete "$INSTDIR\plugins\SpellChecker.dll" + RMDir "$INSTDIR\plugins\" + SectionEnd + Section un.NppExec + Delete "$INSTDIR\plugins\NppExec.dll" + Delete "$INSTDIR\plugins\doc\NppExec.txt" + Delete "$INSTDIR\plugins\doc\NppExec_TechInfo.txt" + Delete "$INSTDIR\plugins\Config\NppExec.ini" + RMDir "$INSTDIR\plugins\" + RMDir "$INSTDIR\plugins\doc\" + SectionEnd + Section un.QuickText + Delete "$INSTDIR\plugins\QuickText.dll" + Delete "$INSTDIR\QuickText.ini" + Delete "$INSTDIR\plugins\doc\quickText_README.txt" + RMDir "$INSTDIR\plugins\" + SectionEnd + Section un.ComparePlugin + Delete "$INSTDIR\plugins\ComparePlugin.dll" + RMDir "$INSTDIR\plugins\" + SectionEnd +SubSectionEnd + +Section un.htmlViewer + DeleteRegKey HKLM "SOFTWARE\Microsoft\Internet Explorer\View Source Editor" + Delete "$INSTDIR\nppIExplorerShell.exe" +SectionEnd + +Section un.AutoUpdater + Delete "$INSTDIR\updater\GUP.exe" + Delete "$INSTDIR\updater\libcurl.dll" + Delete "$INSTDIR\updater\gup.xml" + Delete "$INSTDIR\updater\License.txt" + Delete "$INSTDIR\updater\gpl.txt" + Delete "$INSTDIR\updater\readme.txt" + Delete "$INSTDIR\updater\getDownLoadUrl.php" + RMDir "$INSTDIR\updater\" +SectionEnd + +Section un.explorerContextMenu + Exec 'regsvr32 /u /s "$INSTDIR\nppcm.dll"' + Delete "$INSTDIR\nppcm.dll" +SectionEnd + +Section Uninstall + ;Remove from registry... + DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" + DeleteRegKey HKLM "SOFTWARE\${APPNAME}" + DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\notepad++.exe" + + ; Delete self + Delete "$INSTDIR\uninstall.exe" + + ; Delete Shortcuts + Delete "$SMPROGRAMS\Notepad++\Uninstall.lnk" + RMDir "$SMPROGRAMS\Notepad++" + + UserInfo::GetAccountType + Pop $1 + StrCmp $1 "Admin" 0 +2 + SetShellVarContext all + + Delete "$DESKTOP\Notepad++.lnk" + Delete "$SMPROGRAMS\Notepad++\Notepad++.lnk" + Delete "$SMPROGRAMS\Notepad++\readme.lnk" + + + ; Clean up Notepad++ + Delete "$INSTDIR\LINEDRAW.TTF" + Delete "$INSTDIR\SciLexer.dll" + Delete "$INSTDIR\change.log" + Delete "$INSTDIR\license.txt" + + Delete "$INSTDIR\notepad++.exe" + Delete "$INSTDIR\readme.txt" + + + Delete "$INSTDIR\config.xml" + Delete "$INSTDIR\config.model.xml" + Delete "$INSTDIR\langs.xml" + Delete "$INSTDIR\langs.model.xml" + Delete "$INSTDIR\stylers.xml" + Delete "$INSTDIR\stylers.model.xml" + Delete "$INSTDIR\stylers_remove.xml" + Delete "$INSTDIR\contextMenu.xml" + Delete "$INSTDIR\shortcuts.xml" + Delete "$INSTDIR\nativeLang.xml" + Delete "$INSTDIR\session.xml" + + SetShellVarContext current + Delete "$APPDATA\Notepad++\config.xml" + Delete "$APPDATA\Notepad++\stylers.xml" + Delete "$APPDATA\Notepad++\contextMenu.xml" + Delete "$APPDATA\Notepad++\shortcuts.xml" + Delete "$APPDATA\Notepad++\nativeLang.xml" + Delete "$APPDATA\Notepad++\session.xml" + Delete "$APPDATA\Notepad++\insertExt.ini" + + RMDir "$APPDATA\Notepad++" + + StrCmp $1 "Admin" 0 +2 + SetShellVarContext all + + ; Remove remaining directories + RMDir "$SMPROGRAMS\Notepad++" + RMDir "$INSTDIR\" + RMDir "$APPDATA\Notepad++" + +SectionEnd + +Function un.onInit + + !insertmacro MUI_UNGETLANGUAGE + +FunctionEnd + +BrandingText "Don HO" + +; eof diff --git a/PowerEditor/installer/packageAll.bat b/PowerEditor/installer/packageAll.bat new file mode 100644 index 00000000..f31835dc --- /dev/null +++ b/PowerEditor/installer/packageAll.bat @@ -0,0 +1,48 @@ +copy /Y ".\nativeLang\*.*" ..\bin\localization +cd ..\bin\ + +del /F /S /Q .\zipped.package.release\unicode\*.* +copy /Y license.txt .\zipped.package.release\unicode\ +copy /Y readme.txt .\zipped.package.release\unicode\ +copy /Y NppHelp.chm .\zipped.package.release\unicode\ +copy /Y change.log .\zipped.package.release\unicode\ +copy /Y config.model.xml .\zipped.package.release\unicode\ +copy /Y langs.model.xml .\zipped.package.release\unicode\ +copy /Y stylers.model.xml .\zipped.package.release\unicode\ +copy /Y contextMenu.xml .\zipped.package.release\unicode\ +copy /Y shortcuts.xml .\zipped.package.release\unicode\ +copy /Y doLocalConf.xml .\zipped.package.release\unicode\ +copy /Y LINEDRAW.TTF .\zipped.package.release\unicode\ +copy /Y "notepad++.exe" .\zipped.package.release\unicode\ +copy /Y SciLexer.dll .\zipped.package.release\unicode\ +copy /Y ".\plugins\*.*" .\zipped.package.release\unicode\plugins\ +copy /Y ".\plugins\APIs\*.xml" .\zipped.package.release\unicode\plugins\APIs +copy /Y ".\plugins\doc\*.*" .\zipped.package.release\unicode\plugins\doc +copy /Y ".\plugins\Config\tidy\*.*" .\zipped.package.release\unicode\plugins\Config\tidy +copy /Y ".\localization\*.*" .\zipped.package.release\unicode\localization + + +del /F /S /Q .\zipped.package.release\ansi\config.xml +del /F /S /Q .\zipped.package.release\ansi\langs.xml +del /F /S /Q .\zipped.package.release\ansi\stylers.xml +del /F /S /Q .\zipped.package.release\ansi\session.xml +copy /Y SciLexer.dll .\zipped.package.release\ansi\ +copy /Y license.txt .\zipped.package.release\ansi\ +copy /Y readme.txt .\zipped.package.release\ansi\ +copy /Y NppHelp.chm .\zipped.package.release\ansi\ +copy /Y change.log .\zipped.package.release\ansi\ +copy /Y config.model.xml .\zipped.package.release\ansi\ +copy /Y langs.model.xml .\zipped.package.release\ansi\ +copy /Y stylers.model.xml .\zipped.package.release\ansi\ +copy /Y contextMenu.xml .\zipped.package.release\ansi\ +copy /Y shortcuts.xml .\zipped.package.release\ansi\ +copy /Y doLocalConf.xml .\zipped.package.release\ansi\ +copy /Y LINEDRAW.TTF .\zipped.package.release\ansi\ +copy /Y ".\plugins\Config\tidy\*.*" .\zipped.package.release\ansi\plugins\Config\tidy + +"C:\Program Files\7-Zip\7z.exe" a -tzip -r npp.bin.zip .\zipped.package.release\* +"C:\Program Files\7-Zip\7z.exe" a -r npp.bin.7z .\zipped.package.release\* +"C:\Program Files\NSIS\makensis.exe" ..\installer\nppSetup.nsi + +cd ..\installer\ + diff --git a/PowerEditor/installer/stylesGlobalModel.xml b/PowerEditor/installer/stylesGlobalModel.xml new file mode 100644 index 00000000..67054406 --- /dev/null +++ b/PowerEditor/installer/stylesGlobalModel.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/PowerEditor/installer/stylesLexerModel.xml b/PowerEditor/installer/stylesLexerModel.xml new file mode 100644 index 00000000..cb4a9ce5 --- /dev/null +++ b/PowerEditor/installer/stylesLexerModel.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/PowerEditor/license.txt b/PowerEditor/license.txt new file mode 100644 index 00000000..ba835c30 --- /dev/null +++ b/PowerEditor/license.txt @@ -0,0 +1,88 @@ +GNU GENERAL PUBLIC LICENSE +Version 2, June 1991 + +Copyright (C) 1989, 1991 Free Software Foundation, Inc. +59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + +Everyone is permitted to copy and distribute verbatim copies +of this license document, but changing it is not allowed. + +Preamble +The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. + +When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. + +To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. + +For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. + +We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. + +Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. + +Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. + +The precise terms and conditions for copying, distribution and modification follow. + +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION +0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. + +1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. + +You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. + +2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: + + +a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. + +b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. + +c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) +These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. +Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. + +3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: + +a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, + +b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, + +c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) +The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. +If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. + +4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. + +5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. + +6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. + +7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. + +This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. + +8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. + +9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. + +10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. + +NO WARRANTY + +11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + + +END OF TERMS AND CONDITIONS diff --git a/PowerEditor/src/CMakeLists.txt b/PowerEditor/src/CMakeLists.txt new file mode 100644 index 00000000..02acdb45 --- /dev/null +++ b/PowerEditor/src/CMakeLists.txt @@ -0,0 +1,182 @@ +# @file:/CMakeLists.txt + +# TODO +# - Move defs XX_INCLUDE_DIR, XX_LIBRARIES, XX_LIBRARY_DIRS to the subdirector?es' +# scripts. I could not find a way to export a variables defined in a subscript +# so as a workaround, I define the variables myself in the top script. This is +# not optimal. + +# + +PROJECT(Notepad++) + +SET(projIncludDir ../../scintilla/include/ + ./ + ./ScitillaComponent/ + ./WinControls/ + ./WinControls/AboutDlg/ + ./WinControls/ColourPicker/ + ./WinControls/ContextMenu/ + ./WinControls/DockingWnd/ + ./WinControls/Grid/ + ./WinControls/ImageListSet/ + ./WinControls/OpenSaveFileDialog/ + ./WinControls/Preference/ + ./WinControls/shortcut/ + ./WinControls/SplitterContainer/ + ./WinControls/StaticDialog/ + ./WinControls/StaticDialog/RunDlg + ./WinControls/StatusBar/ + ./WinControls/TabBar/ + ./WinControls/TaskList/ + ./WinControls/ToolBar/ + ./WinControls/TrayIcon/ + ./WinControls/TreeView/ + ./WinControls/WindowsDlg/ + ./MISC/ + ./MISC/PluginsManager/ + ./MISC/RegExt/ + ./MISC/SysMsg/ + ./TinyXml/) + +set(parameters ./Parameters.h ./Parameters.cpp) + +set(scintilla ./ScitillaComponent/ScintillaEditView.h ./ScitillaComponent/ScintillaEditView.cpp) +set(buffer ./ScitillaComponent/ScintillaEditView.h ./ScitillaComponent/ScintillaEditView.cpp) + +set(tinystr ./TinyXml/tinystr.h ./TinyXml/tinystr.cpp) +set(tinyxml ./TinyXml/tinyxml.h ./TinyXml/tinyxml.cpp) +set(tinyxmlerror ./TinyXml/tinyxmlerror.cpp) +set(tinyxmlparser ./TinyXml/tinyxmlparser.cpp) +SET (tinyxmlObjs ${tinystr} ${tinyxml} ${tinyxmlerror} ${tinyxmlparser}) + +SET(objs ./winmain.cpp + ./Notepad_plus.cpp + ./Notepad_plus.h + + ./UniConversion.cpp + ./UniConversion.h + ./Utf8_16.cpp + ./Utf8_16.h + + + + ./ScitillaComponent/DocTabView.cpp + ./ScitillaComponent/DocTabView.h + ./ScitillaComponent/FindReplaceDlg.cpp + ./ScitillaComponent/FindReplaceDlg.h + ./ScitillaComponent/GoToLineDlg.cpp + ./ScitillaComponent/GoToLineDlg.h + ./ScitillaComponent/Printer.cpp + ./ScitillaComponent/Printer.h + ./ScitillaComponent/UserDefineDialog.cpp + ./ScitillaComponent/UserDefineDialog.h + ./WinControls/AboutDlg/AboutDlg.cpp + ./WinControls/AboutDlg/AboutDlg.h + ./WinControls/AboutDlg/URLCtrl.cpp + ./WinControls/AboutDlg/URLCtrl.h + ./WinControls/ColourPicker/ColourPicker.cpp + ./WinControls/ColourPicker/ColourPicker.h + ./WinControls/ColourPicker/ColourPopup.cpp + ./WinControls/ColourPicker/ColourPopup.h + #./WinControls/ColourPicker/FontPreviewCombo.cpp + ./WinControls/ColourPicker/WordStyleDlg.cpp + ./WinControls/ColourPicker/WordStyleDlg.h + ./WinControls/DockingWnd/DockingCont.cpp + ./WinControls/DockingWnd/DockingCont.h + ./WinControls/DockingWnd/DockingManager.cpp + ./WinControls/DockingWnd/DockingManager.h + ./WinControls/DockingWnd/DockingSplitter.cpp + ./WinControls/DockingWnd/DockingSplitter.h + #./WinControls/DockingWnd/DropData.cpp + ./WinControls/DockingWnd/Gripper.cpp + ./WinControls/DockingWnd/Gripper.h + ./WinControls/DockingWnd/common_func.cpp + ./WinControls/DockingWnd/common_func.h + ./WinControls/Grid/BabyGrid.cpp + ./WinControls/Grid/BabyGrid.h + ./WinControls/Grid/BabyGridWrapper.cpp + ./WinControls/Grid/BabyGridWrapper.h + ./WinControls/Grid/ShortcutMapper.cpp + ./WinControls/Grid/ShortcutMapper.h + ./WinControls/ImageListSet/ImageListSet.cpp + ./WinControls/ImageListSet/ImageListSet.h + ./WinControls/OpenSaveFileDialog/FileDialog.cpp + ./WinControls/OpenSaveFileDialog/FileDialog.h + ./WinControls/Preference/preferenceDlg.cpp + ./WinControls/Preference/preferenceDlg.h + ./WinControls/shortcut/shortcut.cpp + ./WinControls/shortcut/shortcut.h + ./WinControls/shortcut/RunMacroDlg.cpp + ./WinControls/shortcut/RunMacroDlg.h + ./WinControls/SplitterContainer/Splitter.cpp + ./WinControls/SplitterContainer/Splitter.h + ./WinControls/SplitterContainer/SplitterContainer.cpp + ./WinControls/SplitterContainer/SplitterContainer.h + ./WinControls/StaticDialog/StaticDialog.cpp + ./WinControls/StaticDialog/StaticDialog.h + ./WinControls/StaticDialog/RunDlg/RunDlg.cpp + ./WinControls/StaticDialog/RunDlg/RunDlg.h + ./WinControls/StatusBar/StatusBar.cpp + ./WinControls/StatusBar/StatusBar.h + ./WinControls/TabBar/TabBar.cpp + ./WinControls/TabBar/TabBar.h + ./WinControls/TabBar/ControlsTab.cpp + ./WinControls/TabBar/ControlsTab.h + ./WinControls/TaskList/TaskList.cpp + ./WinControls/TaskList/TaskList.h + ./WinControls/ToolBar/ToolBar.cpp + ./WinControls/ToolBar/ToolBar.h + ./WinControls/TrayIcon/trayIconControler.cpp + ./WinControls/TrayIcon/trayIconControler.h + ./WinControls/TreeView/TreeView.cpp + ./WinControls/TreeView/TreeView.h + ./WinControls/WindowsDlg/SizeableDlg.cpp + ./WinControls/WindowsDlg/SizeableDlg.h + ./WinControls/WindowsDlg/WindowsDlg.cpp + ./WinControls/WindowsDlg/WindowsDlg.h + ./WinControls/WindowsDlg/WinMgr.cpp + ./WinControls/WindowsDlg/WinMgr.h + ./WinControls/WindowsDlg/WinRect.cpp + ./MISC/PluginsManager/PluginsManager.cpp + ./MISC/PluginsManager/PluginsManager.h + ./MISC/RegExt/regExtDlg.cpp + ./MISC/RegExt/regExtDlg.h + ./MISC/SysMsg/SysMsg.cpp + ./MISC/SysMsg/SysMsg.h + ${tinyxmlObjs} + +) + + +SET(rcFiles ./Notepad_plus.rc + ./ScitillaComponent/FindReplaceDlg.rc + ./ScitillaComponent/UserDefineDialog.rc + ./WinControls/ColourPicker/ColourPopup.rc + ./WinControls/ColourPicker/WordStyleDlg.rc + ./WinControls/DockingWnd/DockingGUIWidget.rc + ./WinControls/Grid/ShortcutMapper.rc + ./WinControls/Preference/preference.rc + ./WinControls/shortcut/RunMacroDlg.rc + ./WinControls/shortcut/shortcut.rc + ./WinControls/StaticDialog/RunDlg/RunDlg.rc + ./WinControls/TaskList/TaskListDlg.rc + ./WinControls/WindowsDlg/WindowsDlg.rc + +) +SET(vendorIncludDir ../../../vendor/Gemalto/Current/SDK_IASAPI/Output/include) + +IF (${CMAKE_SYSTEM_NAME} STREQUAL "Windows") + SET(option WIN32) + SET(win32_LIBRARIES comctl32.lib shlwapi.lib shell32.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib) + #SET(defs -DUNICODE -D_UNICODE) +ENDIF (${CMAKE_SYSTEM_NAME} STREQUAL "Windows") + +#ADD_DEFINITIONS(${defs}) + +INCLUDE_DIRECTORIES(${projIncludDir}) + +ADD_EXECUTABLE(notepad++ ${option} ${objs} ${rcFiles}) + +TARGET_LINK_LIBRARIES (notepad++ ${win32_LIBRARIES}) + diff --git a/PowerEditor/src/MISC/Common/Common.cpp b/PowerEditor/src/MISC/Common/Common.cpp new file mode 100644 index 00000000..34407a3b --- /dev/null +++ b/PowerEditor/src/MISC/Common/Common.cpp @@ -0,0 +1,377 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +//#include "Common.h" //use force include +#include +#include +#include "Common.h" + + +WcharMbcsConvertor * WcharMbcsConvertor::_pSelf = new WcharMbcsConvertor; + +void systemMessage(const TCHAR *title) +{ + LPVOID lpMsgBuf; + FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + ::GetLastError(), + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language + (LPTSTR) &lpMsgBuf, + 0, + NULL );// Process any inserts in lpMsgBuf. + MessageBox( NULL, (LPTSTR)lpMsgBuf, title, MB_OK | MB_ICONSTOP); + ::LocalFree(lpMsgBuf); +} + +void printInt(int int2print) +{ + TCHAR str[32]; + wsprintf(str, TEXT("%d"), int2print); + ::MessageBox(NULL, str, TEXT(""), MB_OK); +}; + +void printStr(const TCHAR *str2print) +{ + ::MessageBox(NULL, str2print, TEXT(""), MB_OK); +}; + +void writeLog(const TCHAR *logFileName, const char *log2write) +{ + FILE *f = generic_fopen(logFileName, TEXT("a+")); + fwrite(log2write, sizeof(log2write[0]), strlen(log2write), f); + fputc('\n', f); + fflush(f); + fclose(f); +} + +void folderBrowser(HWND parent, int outputCtrlID, const TCHAR *defaultStr) +{ + // This code was copied and slightly modifed from: + // http://www.bcbdev.com/faqs/faq62.htm + + // SHBrowseForFolder returns a PIDL. The memory for the PIDL is + // allocated by the shell. Eventually, we will need to free this + // memory, so we need to get a pointer to the shell malloc COM + // object that will free the PIDL later on. + LPMALLOC pShellMalloc = 0; + if (::SHGetMalloc(&pShellMalloc) == NO_ERROR) + { + // If we were able to get the shell malloc object, + // then proceed by initializing the BROWSEINFO stuct + BROWSEINFO info; + memset(&info, 0, sizeof(info)); + info.hwndOwner = parent; + info.pidlRoot = NULL; + TCHAR szDisplayName[MAX_PATH]; + info.pszDisplayName = szDisplayName; + info.lpszTitle = TEXT("Select a folder to search from"); + info.ulFlags = 0; + info.lpfn = BrowseCallbackProc; + TCHAR directory[MAX_PATH]; + ::GetDlgItemText(parent, outputCtrlID, directory, sizeof(directory)); + if (!directory[0] && defaultStr) + info.lParam = reinterpret_cast(defaultStr); + else + info.lParam = reinterpret_cast(directory); + + // Execute the browsing dialog. + LPITEMIDLIST pidl = ::SHBrowseForFolder(&info); + + // pidl will be null if they cancel the browse dialog. + // pidl will be not null when they select a folder. + if (pidl) + { + // Try to convert the pidl to a display generic_string. + // Return is true if success. + TCHAR szDir[MAX_PATH]; + if (::SHGetPathFromIDList(pidl, szDir)) + // Set edit control to the directory path. + ::SetDlgItemText(parent, outputCtrlID, szDir); + pShellMalloc->Free(pidl); + } + pShellMalloc->Release(); + } +} + +void ClientRectToScreenRect(HWND hWnd, RECT* rect) +{ + POINT pt; + + pt.x = rect->left; + pt.y = rect->top; + ::ClientToScreen( hWnd, &pt ); + rect->left = pt.x; + rect->top = pt.y; + + pt.x = rect->right; + pt.y = rect->bottom; + ::ClientToScreen( hWnd, &pt ); + rect->right = pt.x; + rect->bottom = pt.y; +}; + +std::vector tokenizeString(const std::generic_string & tokenString, const char delim) { + //Vector is created on stack and copied on return + std::vector tokens; + + // Skip delimiters at beginning. + std::string::size_type lastPos = tokenString.find_first_not_of(delim, 0); + // Find first "non-delimiter". + std::string::size_type pos = tokenString.find_first_of(delim, lastPos); + + while (pos != std::string::npos || lastPos != std::string::npos) + { + // Found a token, add it to the vector. + tokens.push_back(tokenString.substr(lastPos, pos - lastPos)); + // Skip delimiters. Note the "not_of" + lastPos = tokenString.find_first_not_of(delim, pos); + // Find next "non-delimiter" + pos = tokenString.find_first_of(delim, lastPos); + } + return tokens; +} + +void ScreenRectToClientRect(HWND hWnd, RECT* rect) +{ + POINT pt; + + pt.x = rect->left; + pt.y = rect->top; + ::ScreenToClient( hWnd, &pt ); + rect->left = pt.x; + rect->top = pt.y; + + pt.x = rect->right; + pt.y = rect->bottom; + ::ScreenToClient( hWnd, &pt ); + rect->right = pt.x; + rect->bottom = pt.y; +}; + +int filter(unsigned int code, struct _EXCEPTION_POINTERS *ep) +{ + if (code == EXCEPTION_ACCESS_VIOLATION) + return EXCEPTION_EXECUTE_HANDLER; + + return EXCEPTION_CONTINUE_SEARCH; +} + +int getCpFromStringValue(const char * encodingStr) +{ + if (!encodingStr) + return CP_ACP; + + if (stricmp("windows-1250", encodingStr) == 0) + return 1250; + if (stricmp("windows-1251", encodingStr) == 0) + return 1251; + if (stricmp("windows-1252", encodingStr) == 0) + return 1252; + if (stricmp("windows-1253", encodingStr) == 0) + return 1253; + if (stricmp("windows-1254", encodingStr) == 0) + return 1254; + if (stricmp("windows-1255", encodingStr) == 0) + return 1255; + if (stricmp("windows-1256", encodingStr) == 0) + return 1256; + if (stricmp("windows-1257", encodingStr) == 0) + return 1257; + if (stricmp("windows-1258", encodingStr) == 0) + return 1258; + + if (stricmp("big5", encodingStr) == 0) + return 950; + if (stricmp("gb2312", encodingStr) == 0) + return 936; + if (stricmp("shift_jis", encodingStr) == 0) + return 932; + if (stricmp("euc-kr", encodingStr) == 0) + return 51949; + if (stricmp("tis-620", encodingStr) == 0) + return 874; + + if (stricmp("iso-8859-8", encodingStr) == 0) + return 28598; + + if (stricmp("utf-8", encodingStr) == 0) + return 65001; + + return CP_ACP; +} + +std::generic_string purgeMenuItemString(const TCHAR * menuItemStr, bool keepAmpersand) +{ + TCHAR cleanedName[64] = TEXT(""); + size_t j = 0; + size_t menuNameLen = lstrlen(menuItemStr); + for(size_t k = 0 ; k < menuNameLen ; k++) + { + if (menuItemStr[k] == '\t') + { + cleanedName[k] = 0; + break; + } + else if (menuItemStr[k] == '&') + { + if (keepAmpersand) + cleanedName[j++] = menuItemStr[k]; + //else skip + } + else + { + cleanedName[j++] = menuItemStr[k]; + } + } + cleanedName[j] = 0; + return cleanedName; +}; + +const wchar_t * WcharMbcsConvertor::char2wchar(const char * mbcs2Convert, UINT codepage) +{ + if (!_wideCharStr) + { + _wideCharStr = new wchar_t[initSize]; + _wideCharAllocLen = initSize; + } + + int len = MultiByteToWideChar(codepage, 0, mbcs2Convert, -1, _wideCharStr, 0); + if (len > 0) + { + if (len > int(_wideCharAllocLen)) + { + delete [] _wideCharStr; + _wideCharAllocLen = len; + _wideCharStr = new wchar_t[_wideCharAllocLen]; + } + MultiByteToWideChar(codepage, 0, mbcs2Convert, -1, _wideCharStr, len); + } + else + _wideCharStr[0] = 0; + + return _wideCharStr; +} + +// "mstart" and "mend" are pointers to indexes in mbcs2Convert, +// which are converted to the corresponding indexes in the returned wchar_t string. +const wchar_t * WcharMbcsConvertor::char2wchar(const char * mbcs2Convert, UINT codepage, int *mstart, int *mend) +{ + if (!_wideCharStr) + { + _wideCharStr = new wchar_t[initSize]; + _wideCharAllocLen = initSize; + } + + int len = MultiByteToWideChar(codepage, 0, mbcs2Convert, -1, _wideCharStr, 0); + if (len > 0) + { + if (len > int(_wideCharAllocLen)) + { + delete [] _wideCharStr; + _wideCharAllocLen = len; + _wideCharStr = new wchar_t[_wideCharAllocLen]; + } + MultiByteToWideChar(codepage, 0, mbcs2Convert, -1, _wideCharStr, len); + *mstart = MultiByteToWideChar(codepage, 0, mbcs2Convert, *mstart, _wideCharStr, 0); + *mend = MultiByteToWideChar(codepage, 0, mbcs2Convert, *mend, _wideCharStr, 0); + } + else + { + _wideCharStr[0] = 0; + *mstart = 0; + *mend = 0; + } + return _wideCharStr; +} + +const char * WcharMbcsConvertor::wchar2char(const wchar_t * wcharStr2Convert, UINT codepage) +{ + if (!_multiByteStr) + { + _multiByteStr = new char[initSize]; + _multiByteAllocLen = initSize; + } + + int len = WideCharToMultiByte(codepage, 0, wcharStr2Convert, -1, _multiByteStr, 0, NULL, NULL); + if (len > 0) + { + if (len > int(_multiByteAllocLen)) + { + delete [] _multiByteStr; + _multiByteAllocLen = len; + _multiByteStr = new char[_multiByteAllocLen]; + } + WideCharToMultiByte(codepage, 0, wcharStr2Convert, -1, _multiByteStr, len, NULL, NULL); + } + else + _multiByteStr[0] = 0; + + return _multiByteStr; +} + +const char * WcharMbcsConvertor::wchar2char(const wchar_t * wcharStr2Convert, UINT codepage, long *mstart, long *mend) +{ + if (!_multiByteStr) + { + _multiByteStr = new char[initSize]; + _multiByteAllocLen = initSize; + } + + int len = WideCharToMultiByte(codepage, 0, wcharStr2Convert, -1, _multiByteStr, 0, NULL, NULL); + if (len > 0) + { + if (len > int(_multiByteAllocLen)) + { + delete [] _multiByteStr; + _multiByteAllocLen = len; + _multiByteStr = new char[_multiByteAllocLen]; + } + WideCharToMultiByte(codepage, 0, wcharStr2Convert, -1, _multiByteStr, len, NULL, NULL); + *mstart = WideCharToMultiByte(codepage, 0, wcharStr2Convert, *mstart, _multiByteStr, 0, NULL, NULL); + *mend = WideCharToMultiByte(codepage, 0, wcharStr2Convert, *mend, _multiByteStr, 0, NULL, NULL); + } + else + _multiByteStr[0] = 0; + + return _multiByteStr; +} + +std::wstring string2wstring(const std::string & rString, UINT codepage) +{ + int len = MultiByteToWideChar(codepage, 0, rString.c_str(), -1, NULL, 0); + if(len > 0) + { + std::vector vw(len); + MultiByteToWideChar(codepage, 0, rString.c_str(), -1, &vw[0], len); + return &vw[0]; + } + else + return L""; +} + +std::string wstring2string(const std::wstring & rwString, UINT codepage) +{ + int len = WideCharToMultiByte(codepage, 0, rwString.c_str(), -1, NULL, 0, NULL, NULL); + if(len > 0) + { + std::vector vw(len); + WideCharToMultiByte(codepage, 0, rwString.c_str(), -1, &vw[0], len, NULL, NULL); + return &vw[0]; + } + else + return ""; +} diff --git a/PowerEditor/src/MISC/Common/Common.h b/PowerEditor/src/MISC/Common/Common.h new file mode 100644 index 00000000..3b25eb90 --- /dev/null +++ b/PowerEditor/src/MISC/Common/Common.h @@ -0,0 +1,136 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef M30_IDE_COMMUN_H +#define M30_IDE_COMMUN_H + +#include +#include +#include +#include +#include + +#ifdef UNICODE +#include +#endif + +#define CP_ANSI_LATIN_1 1252 +#define CP_BIG5 950 + +#ifdef UNICODE + #define NppMainEntry wWinMain + #define generic_strtol wcstol + #define generic_strncpy wcsncpy + #define generic_stricmp wcsicmp + #define generic_strncmp wcsncmp + #define generic_strnicmp wcsnicmp + #define generic_strncat wcsncat + #define generic_strchr wcschr + #define generic_atoi _wtoi + #define generic_itoa _itow + #define generic_atof _wtof + #define generic_strtok wcstok + #define generic_strftime wcsftime + #define generic_fprintf fwprintf + #define generic_sscanf swscanf + #define generic_fopen _wfopen + #define generic_fgets fgetws + #define generic_stat _wstat + #define generic_string wstring + #define COPYDATA_FILENAMES COPYDATA_FILENAMESW +#else + #define NppMainEntry WinMain + #define generic_strtol strtol + #define generic_strncpy strncpy + #define generic_stricmp stricmp + #define generic_strncmp strncmp + #define generic_strnicmp strnicmp + #define generic_strncat strncat + #define generic_strchr strchr + #define generic_atoi atoi + #define generic_itoa itoa + #define generic_atof atof + #define generic_strtok strtok + #define generic_strftime strftime + #define generic_fprintf fprintf + #define generic_sscanf sscanf + #define generic_fopen fopen + #define generic_fgets fgets + #define generic_stat _stat + #define generic_string string + #define COPYDATA_FILENAMES COPYDATA_FILENAMESA +#endif + +void folderBrowser(HWND parent, int outputCtrlID, const TCHAR *defaultStr = NULL); + +// Set a call back with the handle after init to set the path. +// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/callbackfunctions/browsecallbackproc.asp +static int __stdcall BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM, LPARAM pData) +{ + if (uMsg == BFFM_INITIALIZED) + ::SendMessage(hwnd, BFFM_SETSELECTION, TRUE, pData); + return 0; +}; + +void systemMessage(const TCHAR *title); +//DWORD ShortToLongPathName(LPCTSTR lpszShortPath, LPTSTR lpszLongPath, DWORD cchBuffer); +void printInt(int int2print); +void printStr(const TCHAR *str2print); + +void writeLog(const TCHAR *logFileName, const char *log2write); +int filter(unsigned int code, struct _EXCEPTION_POINTERS *ep); +int getCpFromStringValue(const char * encodingStr); +std::generic_string purgeMenuItemString(const TCHAR * menuItemStr, bool keepAmpersand = false); +std::vector tokenizeString(const std::generic_string & tokenString, const char delim); + +void ClientRectToScreenRect(HWND hWnd, RECT* rect); +void ScreenRectToClientRect(HWND hWnd, RECT* rect); + +std::wstring string2wstring(const std::string & rString, UINT codepage); +std::string wstring2string(const std::wstring & rwString, UINT codepage); + +class WcharMbcsConvertor { +public: + static WcharMbcsConvertor * getInstance() {return _pSelf;}; + static void destroyInstance() {delete _pSelf;}; + + const wchar_t * char2wchar(const char* mbStr, UINT codepage); + const wchar_t * char2wchar(const char * mbcs2Convert, UINT codepage, int *mstart, int *mend); + const char * wchar2char(const wchar_t* wcStr, UINT codepage); + const char * wchar2char(const wchar_t * wcStr, UINT codepage, long *mstart, long *mend); + +protected: + WcharMbcsConvertor() : _multiByteStr(NULL), _wideCharStr(NULL), _multiByteAllocLen(0), _wideCharAllocLen(0), initSize(1024) { + }; + ~WcharMbcsConvertor() { + if (_multiByteStr) + delete [] _multiByteStr; + if (_wideCharStr) + delete [] _wideCharStr; + }; + static WcharMbcsConvertor * _pSelf; + + const int initSize; + char *_multiByteStr; + size_t _multiByteAllocLen; + wchar_t *_wideCharStr; + size_t _wideCharAllocLen; + +}; + + +#endif //M30_IDE_COMMUN_H diff --git a/PowerEditor/src/MISC/Exception/MiniDumper.cpp b/PowerEditor/src/MISC/Exception/MiniDumper.cpp new file mode 100644 index 00000000..ca6a79fb --- /dev/null +++ b/PowerEditor/src/MISC/Exception/MiniDumper.cpp @@ -0,0 +1,82 @@ +#include "MiniDumper.h" +//#include "Common.h" +#include + +LPCTSTR msgTitle = TEXT("Notepad++ crash analysis"); + +MiniDumper::MiniDumper() +{ +} + +bool MiniDumper::writeDump(EXCEPTION_POINTERS * pExceptionInfo) +{ + TCHAR szDumpPath[MAX_PATH]; + TCHAR szScratch[MAX_PATH]; + LPCTSTR szResult = NULL; + bool retval = false; + + HMODULE hDll = ::LoadLibrary( TEXT("DBGHELP.DLL") ); //that wont work on older windows version than XP, #care :) + + if (hDll) + { + MINIDUMPWRITEDUMP pDump = (MINIDUMPWRITEDUMP)::GetProcAddress( hDll, "MiniDumpWriteDump" ); + if (pDump) + { + //lstrcpy(szDumpPath, TEXT("C:\\N++RECOV\\NppDump.dmp")); + ::GetModuleFileName(NULL, szDumpPath, MAX_PATH); + ::PathRemoveFileSpec(szDumpPath); + lstrcat(szDumpPath, TEXT("\\NppDump.dmp")); + + // ask the user if they want to save a dump file + int msgret = ::MessageBox(NULL, TEXT("Do you want to save a dump file?\r\nDoing so can aid in developing Notepad++."), msgTitle, MB_YESNO); + if (msgret == IDYES) + { + // create the file + HANDLE hFile = ::CreateFile( szDumpPath, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, + FILE_ATTRIBUTE_NORMAL, NULL ); + + if (hFile!=INVALID_HANDLE_VALUE) + { + _MINIDUMP_EXCEPTION_INFORMATION ExInfo; + + ExInfo.ThreadId = ::GetCurrentThreadId(); + ExInfo.ExceptionPointers = pExceptionInfo; + ExInfo.ClientPointers = NULL; + + // write the dump + BOOL bOK = pDump( GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpNormal, &ExInfo, NULL, NULL ); + if (bOK) + { + wsprintf( szScratch, TEXT("Saved dump file to '%s'"), szDumpPath ); + szResult = szScratch; + retval = true; + } + else + { + wsprintf( szScratch, TEXT("Failed to save dump file to '%s' (error %d)"), szDumpPath, GetLastError() ); + szResult = szScratch; + } + ::CloseHandle(hFile); + } + else + { + wsprintf( szScratch, TEXT("Failed to create dump file '%s' (error %d)"), szDumpPath, GetLastError() ); + szResult = szScratch; + } + } + } + else + { + szResult = TEXT("The debugging DLL is outdated,\r\nfind a recent copy of dbghelp.dll and install it."); + } + } + else + { + szResult = TEXT("Unable to load the debugging DLL,\r\nfind a recent copy of dbghelp.dll and install it."); + } + + if (szResult) + ::MessageBox(NULL, szResult, msgTitle, MB_OK); + + return retval; +} diff --git a/PowerEditor/src/MISC/Exception/MiniDumper.h b/PowerEditor/src/MISC/Exception/MiniDumper.h new file mode 100644 index 00000000..31b5ec30 --- /dev/null +++ b/PowerEditor/src/MISC/Exception/MiniDumper.h @@ -0,0 +1,22 @@ +//Adapted from http://www.codeproject.com/KB/debug/postmortemdebug_standalone1.aspx#_Reading_a_Minidump_with%20Visual%20Stud +//Modified for use by Npp +#ifndef MDUMP_H +#define MDUMP_H + +#include +#include "dbghelp.h" + +// based on dbghelp.h +typedef BOOL (WINAPI *MINIDUMPWRITEDUMP)(HANDLE hProcess, DWORD dwPid, HANDLE hFile, MINIDUMP_TYPE DumpType, + const PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam, + const PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam, + const PMINIDUMP_CALLBACK_INFORMATION CallbackParam + ); + +class MiniDumper { +public: + MiniDumper(); + bool writeDump(EXCEPTION_POINTERS * pExceptionInfo); +}; + +#endif //MDUMP_H \ No newline at end of file diff --git a/PowerEditor/src/MISC/Exception/Win32Exception.cpp b/PowerEditor/src/MISC/Exception/Win32Exception.cpp new file mode 100644 index 00000000..cb129c32 --- /dev/null +++ b/PowerEditor/src/MISC/Exception/Win32Exception.cpp @@ -0,0 +1,49 @@ +//This code was retrieved from +//http://www.thunderguy.com/semicolon/2002/08/15/visual-c-exception-handling/3/ +//(Visual C++ exception handling) +//By Bennett +//Formatting Slightly modified for N++ + +#include "Win32Exception.h" +#include "eh.h" + +Win32Exception::Win32Exception(EXCEPTION_POINTERS * info) { + _location = info->ExceptionRecord->ExceptionAddress; + _code = info->ExceptionRecord->ExceptionCode; + _info = info; + switch (_code) { + case EXCEPTION_ACCESS_VIOLATION: + _event = "Access violation"; + break; + case EXCEPTION_FLT_DIVIDE_BY_ZERO: + case EXCEPTION_INT_DIVIDE_BY_ZERO: + _event = "Division by zero"; + break; + default: + _event = "Unlisted exception"; + } +} + +void Win32Exception::installHandler() { + _set_se_translator(Win32Exception::translate); +} + +void Win32Exception::removeHandler() { + _set_se_translator(NULL); +} + +void Win32Exception::translate(unsigned code, EXCEPTION_POINTERS * info) { + // Windows guarantees that *(info->ExceptionRecord) is valid + switch (code) { + case EXCEPTION_ACCESS_VIOLATION: + throw Win32AccessViolation(info); + break; + default: + throw Win32Exception(info); + } +} + +Win32AccessViolation::Win32AccessViolation(EXCEPTION_POINTERS * info) : Win32Exception(info) { + _isWrite = info->ExceptionRecord->ExceptionInformation[0] == 1; + _badAddress = reinterpret_cast(info->ExceptionRecord->ExceptionInformation[1]); +} diff --git a/PowerEditor/src/MISC/Exception/Win32Exception.h b/PowerEditor/src/MISC/Exception/Win32Exception.h new file mode 100644 index 00000000..47dc2846 --- /dev/null +++ b/PowerEditor/src/MISC/Exception/Win32Exception.h @@ -0,0 +1,46 @@ +//This code was retrieved from +//http://www.thunderguy.com/semicolon/2002/08/15/visual-c-exception-handling/3/ +//(Visual C++ exception handling) +//By Bennett +//Formatting Slightly modified for N++ + +#include "windows.h" +#include + +typedef const void* ExceptionAddress; // OK on Win32 platform + +class Win32Exception : public std::exception +{ +public: + static void installHandler(); + static void removeHandler(); + virtual const char* what() const throw() { return _event; }; + ExceptionAddress where() const { return _location; }; + unsigned int code() const { return _code; }; + EXCEPTION_POINTERS* info() const { return _info; }; + +protected: + Win32Exception(EXCEPTION_POINTERS * info); //Constructor only accessible by exception handler + static void translate(unsigned code, EXCEPTION_POINTERS * info); + +private: + const char * _event; + ExceptionAddress _location; + unsigned int _code; + + EXCEPTION_POINTERS * _info; +}; + +class Win32AccessViolation: public Win32Exception +{ +public: + bool isWrite() const { return _isWrite; }; + ExceptionAddress badAddress() const { return _badAddress; }; +private: + Win32AccessViolation(EXCEPTION_POINTERS * info); + + bool _isWrite; + ExceptionAddress _badAddress; + + friend void Win32Exception::translate(unsigned code, EXCEPTION_POINTERS* info); +}; diff --git a/PowerEditor/src/MISC/FileNameStringSplitter.h b/PowerEditor/src/MISC/FileNameStringSplitter.h new file mode 100644 index 00000000..b787f5b7 --- /dev/null +++ b/PowerEditor/src/MISC/FileNameStringSplitter.h @@ -0,0 +1,92 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef FILENAME_STRING_SPLITTER_H +#define FILENAME_STRING_SPLITTER_H + +typedef std::vector stringVector; + +class FileNameStringSplitter +{ +public : + FileNameStringSplitter(const TCHAR *fileNameStr) { + //if (!fileNameStr) return; + TCHAR *pStr = NULL; + bool isInsideQuotes = false; + TCHAR str[MAX_PATH]; + int i = 0; + bool fini = false; + for (pStr = (TCHAR *)fileNameStr ; !fini ; ) + { + switch (*pStr) + { + case '"' : + if (isInsideQuotes) + { + str[i] = '\0'; + if (str[0]) + _fileNames.push_back(std::generic_string(str)); + i = 0; + } + isInsideQuotes = !isInsideQuotes; + pStr++; + break; + + case ' ' : + if (isInsideQuotes) + { + str[i] = *pStr; + i++; + } + else + { + str[i] = '\0'; + if (str[0]) + _fileNames.push_back(std::generic_string(str)); + i = 0; + } + pStr++; + break; + + case '\0' : + str[i] = *pStr; + if (str[0]) + _fileNames.push_back(std::generic_string(str)); + fini = true; + break; + + default : + str[i] = *pStr; + i++; pStr++; + break; + } + } + }; + + const TCHAR * getFileName(int index) const { + return _fileNames[index].c_str(); + }; + + int size() const { + return int(_fileNames.size()); + }; + +private : + stringVector _fileNames; +}; + +#endif //FILENAME_STRING_SPLITTER_H diff --git a/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h new file mode 100644 index 00000000..22812aae --- /dev/null +++ b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h @@ -0,0 +1,428 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef NOTEPAD_PLUS_MSGS_H +#define NOTEPAD_PLUS_MSGS_H + +//#include "menuCmdID.h" + +enum LangType {L_TXT, L_PHP , L_C, L_CPP, L_CS, L_OBJC, L_JAVA, L_RC,\ + L_HTML, L_XML, L_MAKEFILE, L_PASCAL, L_BATCH, L_INI, L_NFO, L_USER,\ + L_ASP, L_SQL, L_VB, L_JS, L_CSS, L_PERL, L_PYTHON, L_LUA,\ + L_TEX, L_FORTRAN, L_BASH, L_FLASH, L_NSIS, L_TCL, L_LISP, L_SCHEME,\ + L_ASM, L_DIFF, L_PROPS, L_PS, L_RUBY, L_SMALLTALK, L_VHDL, L_KIX, L_AU3,\ + L_CAML, L_ADA, L_VERILOG, L_MATLAB, L_HASKELL, L_INNO, L_SEARCHRESULT,\ + L_CMAKE, L_YAML,\ + // The end of enumated language type, so it should be always at the end + L_EXTERNAL}; +enum winVer{WV_UNKNOWN, WV_WIN32S, WV_95, WV_98, WV_ME, WV_NT, WV_W2K, WV_XP, WV_S2003, WV_XPX64, WV_VISTA}; + + +//#include "deprecatedSymbols.h" + +//Here you can find how to use these messages : http://notepad-plus.sourceforge.net/uk/plugins-HOWTO.php +#define NPPMSG (WM_USER + 1000) + + #define NPPM_GETCURRENTSCINTILLA (NPPMSG + 4) + #define NPPM_GETCURRENTLANGTYPE (NPPMSG + 5) + #define NPPM_SETCURRENTLANGTYPE (NPPMSG + 6) + + #define NPPM_GETNBOPENFILES (NPPMSG + 7) + #define ALL_OPEN_FILES 0 + #define PRIMARY_VIEW 1 + #define SECOND_VIEW 2 + + #define NPPM_GETOPENFILENAMES (NPPMSG + 8) + + + #define NPPM_MODELESSDIALOG (NPPMSG + 12) + #define MODELESSDIALOGADD 0 + #define MODELESSDIALOGREMOVE 1 + + #define NPPM_GETNBSESSIONFILES (NPPMSG + 13) + #define NPPM_GETSESSIONFILES (NPPMSG + 14) + #define NPPM_SAVESESSION (NPPMSG + 15) + #define NPPM_SAVECURRENTSESSION (NPPMSG + 16) + + struct sessionInfo { + TCHAR* sessionFilePathName; + int nbFile; + TCHAR** files; + }; + + #define NPPM_GETOPENFILENAMESPRIMARY (NPPMSG + 17) + #define NPPM_GETOPENFILENAMESSECOND (NPPMSG + 18) + + #define NPPM_CREATESCINTILLAHANDLE (NPPMSG + 20) + #define NPPM_DESTROYSCINTILLAHANDLE (NPPMSG + 21) + #define NPPM_GETNBUSERLANG (NPPMSG + 22) + + #define NPPM_GETCURRENTDOCINDEX (NPPMSG + 23) + #define MAIN_VIEW 0 + #define SUB_VIEW 1 + + #define NPPM_SETSTATUSBAR (NPPMSG + 24) + #define STATUSBAR_DOC_TYPE 0 + #define STATUSBAR_DOC_SIZE 1 + #define STATUSBAR_CUR_POS 2 + #define STATUSBAR_EOF_FORMAT 3 + #define STATUSBAR_UNICODE_TYPE 4 + #define STATUSBAR_TYPING_MODE 5 + + #define NPPM_GETMENUHANDLE (NPPMSG + 25) + #define NPPPLUGINMENU 0 + + #define NPPM_ENCODESCI (NPPMSG + 26) + //ascii file to unicode + //int NPPM_ENCODESCI(MAIN_VIEW/SUB_VIEW, 0) + //return new unicodeMode + + #define NPPM_DECODESCI (NPPMSG + 27) + //unicode file to ascii + //int NPPM_DECODESCI(MAIN_VIEW/SUB_VIEW, 0) + //return old unicodeMode + + #define NPPM_ACTIVATEDOC (NPPMSG + 28) + //void NPPM_ACTIVATEDOC(int view, int index2Activate) + + #define NPPM_LAUNCHFINDINFILESDLG (NPPMSG + 29) + //void NPPM_LAUNCHFINDINFILESDLG(TCHAR * dir2Search, TCHAR * filtre) + + #define NPPM_DMMSHOW (NPPMSG + 30) + #define NPPM_DMMHIDE (NPPMSG + 31) + #define NPPM_DMMUPDATEDISPINFO (NPPMSG + 32) + //void NPPM_DMMxxx(0, tTbData->hClient) + + #define NPPM_DMMREGASDCKDLG (NPPMSG + 33) + //void NPPM_DMMREGASDCKDLG(0, &tTbData) + + #define NPPM_LOADSESSION (NPPMSG + 34) + //void NPPM_LOADSESSION(0, const TCHAR* file name) + + #define NPPM_DMMVIEWOTHERTAB (NPPMSG + 35) + //void WM_DMM_VIEWOTHERTAB(0, tTbData->pszName) + + #define NPPM_RELOADFILE (NPPMSG + 36) + //BOOL NPPM_RELOADFILE(BOOL withAlert, TCHAR *filePathName2Reload) + + #define NPPM_SWITCHTOFILE (NPPMSG + 37) + //BOOL NPPM_SWITCHTOFILE(0, TCHAR *filePathName2switch) + + #define NPPM_SAVECURRENTFILE (NPPMSG + 38) + //BOOL WM_SWITCHTOFILE(0, 0) + + #define NPPM_SAVEALLFILES (NPPMSG + 39) + //BOOL NPPM_SAVEALLFILES(0, 0) + + #define NPPM_SETMENUITEMCHECK (NPPMSG + 40) + //void WM_PIMENU_CHECK(UINT funcItem[X]._cmdID, TRUE/FALSE) + + #define NPPM_ADDTOOLBARICON (NPPMSG + 41) + //void WM_ADDTOOLBARICON(UINT funcItem[X]._cmdID, toolbarIcons icon) + struct toolbarIcons { + HBITMAP hToolbarBmp; + HICON hToolbarIcon; + }; + + #define NPPM_GETWINDOWSVERSION (NPPMSG + 42) + //winVer NPPM_GETWINDOWSVERSION(0, 0) + + #define NPPM_DMMGETPLUGINHWNDBYNAME (NPPMSG + 43) + //HWND WM_DMM_GETPLUGINHWNDBYNAME(const TCHAR *windowName, const TCHAR *moduleName) + // if moduleName is NULL, then return value is NULL + // if windowName is NULL, then the first found window handle which matches with the moduleName will be returned + + #define NPPM_MAKECURRENTBUFFERDIRTY (NPPMSG + 44) + //BOOL NPPM_MAKECURRENTBUFFERDIRTY(0, 0) + + #define NPPM_GETENABLETHEMETEXTUREFUNC (NPPMSG + 45) + //BOOL NPPM_GETENABLETHEMETEXTUREFUNC(0, 0) + + #define NPPM_GETPLUGINSCONFIGDIR (NPPMSG + 46) + //void NPPM_GETPLUGINSCONFIGDIR(int strLen, TCHAR *str) + + #define NPPM_MSGTOPLUGIN (NPPMSG + 47) + //BOOL NPPM_MSGTOPLUGIN(TCHAR *destModuleName, CommunicationInfo *info) + // return value is TRUE when the message arrive to the destination plugins. + // if destModule or info is NULL, then return value is FALSE + struct CommunicationInfo { + long internalMsg; + const TCHAR * srcModuleName; + void * info; // defined by plugin + }; + + #define NPPM_MENUCOMMAND (NPPMSG + 48) + //void NPPM_MENUCOMMAND(0, int cmdID) + // uncomment //#include "menuCmdID.h" + // in the beginning of this file then use the command symbols defined in "menuCmdID.h" file + // to access all the Notepad++ menu command items + + #define NPPM_TRIGGERTABBARCONTEXTMENU (NPPMSG + 49) + //void NPPM_TRIGGERTABBARCONTEXTMENU(int view, int index2Activate) + + #define NPPM_GETNPPVERSION (NPPMSG + 50) + // int NPPM_GETNPPVERSION(0, 0) + // return version + // ex : v4.6 + // HIWORD(version) == 4 + // LOWORD(version) == 6 + + #define NPPM_HIDETABBAR (NPPMSG + 51) + // BOOL NPPM_HIDETABBAR(0, BOOL hideOrNot) + // if hideOrNot is set as TRUE then tab bar will be hidden + // otherwise it'll be shown. + // return value : the old status value + + #define NPPM_ISTABBARHIDDEN (NPPMSG + 52) + // BOOL NPPM_ISTABBARHIDDEN(0, 0) + // returned value : TRUE if tab bar is hidden, otherwise FALSE + + #define NPPM_GETPOSFROMBUFFERID (NPPMSG + 57) + // INT NPPM_GETPOSFROMBUFFERID(INT bufferID, 0) + // Return VIEW|INDEX from a buffer ID. -1 if the bufferID non existing + // + // VIEW takes 2 highest bits and INDEX (0 based) takes the rest (30 bits) + // Here's the values for the view : + // MAIN_VIEW 0 + // SUB_VIEW 1 + + #define NPPM_GETFULLPATHFROMBUFFERID (NPPMSG + 58) + // INT NPPM_GETFULLPATHFROMBUFFERID(INT bufferID, TCHAR *fullFilePath) + // Get full path file name from a bufferID. + // Return -1 if the bufferID non existing, otherwise the number of TCHAR copied/to copy + // User should call it with fullFilePath be NULL to get the number of TCHAR (not including the nul character), + // allocate fullFilePath with the return values + 1, then call it again to get full path file name + + #define NPPM_GETBUFFERIDFROMPOS (NPPMSG + 59) + //wParam: Position of document + //lParam: View to use, 0 = Main, 1 = Secondary + //Returns 0 if invalid + + #define NPPM_GETCURRENTBUFFERID (NPPMSG + 60) + //Returns active Buffer + + #define NPPM_RELOADBUFFERID (NPPMSG + 61) + //Reloads Buffer + //wParam: Buffer to reload + //lParam: 0 if no alert, else alert + + + #define NPPM_GETBUFFERLANGTYPE (NPPMSG + 64) + //wParam: BufferID to get LangType from + //lParam: 0 + //Returns as int, see LangType. -1 on error + + #define NPPM_SETBUFFERLANGTYPE (NPPMSG + 65) + //wParam: BufferID to set LangType of + //lParam: LangType + //Returns TRUE on success, FALSE otherwise + //use int, see LangType for possible values + //L_USER and L_EXTERNAL are not supported + + #define NPPM_GETBUFFERENCODING (NPPMSG + 66) + //wParam: BufferID to get encoding from + //lParam: 0 + //returns as int, see UniMode. -1 on error + + #define NPPM_SETBUFFERENCODING (NPPMSG + 67) + //wParam: BufferID to set encoding of + //lParam: format + //Returns TRUE on success, FALSE otherwise + //use int, see UniMode + //Can only be done on new, unedited files + + #define NPPM_GETBUFFERFORMAT (NPPMSG + 68) + //wParam: BufferID to get format from + //lParam: 0 + //returns as int, see formatType. -1 on error + + #define NPPM_SETBUFFERFORMAT (NPPMSG + 69) + //wParam: BufferID to set format of + //lParam: format + //Returns TRUE on success, FALSE otherwise + //use int, see formatType + +/* + #define NPPM_ADDREBAR (NPPMSG + 57) + // BOOL NPPM_ADDREBAR(0, REBARBANDINFO *) + // Returns assigned ID in wID value of struct pointer + #define NPPM_UPDATEREBAR (NPPMSG + 58) + // BOOL NPPM_ADDREBAR(INT ID, REBARBANDINFO *) + //Use ID assigned with NPPM_ADDREBAR + #define NPPM_REMOVEREBAR (NPPMSG + 59) + // BOOL NPPM_ADDREBAR(INT ID, 0) + //Use ID assigned with NPPM_ADDREBAR +*/ + #define NPPM_HIDETOOLBAR (NPPMSG + 70) + // BOOL NPPM_HIDETOOLBAR(0, BOOL hideOrNot) + // if hideOrNot is set as TRUE then tool bar will be hidden + // otherwise it'll be shown. + // return value : the old status value + + #define NPPM_ISTOOLBARHIDDEN (NPPMSG + 71) + // BOOL NPPM_ISTOOLBARHIDDEN(0, 0) + // returned value : TRUE if tool bar is hidden, otherwise FALSE + + #define NPPM_HIDEMENU (NPPMSG + 72) + // BOOL NPPM_HIDEMENU(0, BOOL hideOrNot) + // if hideOrNot is set as TRUE then menu will be hidden + // otherwise it'll be shown. + // return value : the old status value + + #define NPPM_ISMENUHIDDEN (NPPMSG + 73) + // BOOL NPPM_ISMENUHIDDEN(0, 0) + // returned value : TRUE if menu is hidden, otherwise FALSE + + #define NPPM_HIDESTATUSBAR (NPPMSG + 74) + // BOOL NPPM_HIDESTATUSBAR(0, BOOL hideOrNot) + // if hideOrNot is set as TRUE then STATUSBAR will be hidden + // otherwise it'll be shown. + // return value : the old status value + + #define NPPM_ISSTATUSBARHIDDEN (NPPMSG + 75) + // BOOL NPPM_ISSTATUSBARHIDDEN(0, 0) + // returned value : TRUE if STATUSBAR is hidden, otherwise FALSE + + #define NPPM_GETSHORTCUTBYCMDID (NPPMSG + 76) + // BOOL NPPM_GETSHORTCUTBYCMDID(int cmdID, ShortcutKey *sk) + // get your plugin command current mapped shortcut into sk via cmdID + // You may need it after getting NPPN_READY notification + // returned value : TRUE if this function call is successful and shorcut is enable, otherwise FALSE + + #define NPPM_DOOPEN (NPPMSG + 77) + // BOOL NPPM_DOOPEN(0, const TCHAR *fullPathName2Open) + // fullPathName2Open indicates the full file path name to be opened. + // The return value is TRUE (1) if the operation is successful, otherwise FALSE (0). + +#define RUNCOMMAND_USER (WM_USER + 3000) + #define NPPM_GETFULLCURRENTPATH (RUNCOMMAND_USER + FULL_CURRENT_PATH) + #define NPPM_GETCURRENTDIRECTORY (RUNCOMMAND_USER + CURRENT_DIRECTORY) + #define NPPM_GETFILENAME (RUNCOMMAND_USER + FILE_NAME) + #define NPPM_GETNAMEPART (RUNCOMMAND_USER + NAME_PART) + #define NPPM_GETEXTPART (RUNCOMMAND_USER + EXT_PART) + #define NPPM_GETCURRENTWORD (RUNCOMMAND_USER + CURRENT_WORD) + #define NPPM_GETNPPDIRECTORY (RUNCOMMAND_USER + NPP_DIRECTORY) + // BOOL NPPM_GETXXXXXXXXXXXXXXXX(size_t strLen, TCHAR *str) + // where str is the allocated TCHAR array, + // strLen is the allocated array size + // The return value is TRUE when get generic_string operation success + // Otherwise (allocated array size is too small) FALSE + + #define NPPM_GETCURRENTLINE (RUNCOMMAND_USER + CURRENT_LINE) + // INT NPPM_GETCURRENTLINE(0, 0) + // return the caret current position line + #define NPPM_GETCURRENTCOLUMN (RUNCOMMAND_USER + CURRENT_COLUMN) + // INT NPPM_GETCURRENTCOLUMN(0, 0) + // return the caret current position column + + #define VAR_NOT_RECOGNIZED 0 + #define FULL_CURRENT_PATH 1 + #define CURRENT_DIRECTORY 2 + #define FILE_NAME 3 + #define NAME_PART 4 + #define EXT_PART 5 + #define CURRENT_WORD 6 + #define NPP_DIRECTORY 7 + #define CURRENT_LINE 8 + #define CURRENT_COLUMN 9 + + +// Notification code +#define NPPN_FIRST 1000 + #define NPPN_READY (NPPN_FIRST + 1) // To notify plugins that all the procedures of launchment of notepad++ are done. + //scnNotification->nmhdr.code = NPPN_READY; + //scnNotification->nmhdr.hwndFrom = hwndNpp; + //scnNotification->nmhdr.idFrom = 0; + + #define NPPN_TBMODIFICATION (NPPN_FIRST + 2) // To notify plugins that toolbar icons can be registered + //scnNotification->nmhdr.code = NPPN_TB_MODIFICATION; + //scnNotification->nmhdr.hwndFrom = hwndNpp; + //scnNotification->nmhdr.idFrom = 0; + + #define NPPN_FILEBEFORECLOSE (NPPN_FIRST + 3) // To notify plugins that the current file is about to be closed + //scnNotification->nmhdr.code = NPPN_FILEBEFORECLOSE; + //scnNotification->nmhdr.hwndFrom = hwndNpp; + //scnNotification->nmhdr.idFrom = BufferID; + + #define NPPN_FILEOPENED (NPPN_FIRST + 4) // To notify plugins that the current file is just opened + //scnNotification->nmhdr.code = NPPN_FILEOPENED; + //scnNotification->nmhdr.hwndFrom = hwndNpp; + //scnNotification->nmhdr.idFrom = BufferID; + + #define NPPN_FILECLOSED (NPPN_FIRST + 5) // To notify plugins that the current file is just closed + //scnNotification->nmhdr.code = NPPN_FILECLOSED; + //scnNotification->nmhdr.hwndFrom = hwndNpp; + //scnNotification->nmhdr.idFrom = BufferID; + + #define NPPN_FILEBEFOREOPEN (NPPN_FIRST + 6) // To notify plugins that the current file is about to be opened + //scnNotification->nmhdr.code = NPPN_FILEBEFOREOPEN; + //scnNotification->nmhdr.hwndFrom = hwndNpp; + //scnNotification->nmhdr.idFrom = BufferID; + + #define NPPN_FILEBEFORESAVE (NPPN_FIRST + 7) // To notify plugins that the current file is about to be saved + //scnNotification->nmhdr.code = NPPN_FILEBEFOREOPEN; + //scnNotification->nmhdr.hwndFrom = hwndNpp; + //scnNotification->nmhdr.idFrom = BufferID; + + #define NPPN_FILESAVED (NPPN_FIRST + 8) // To notify plugins that the current file is just saved + //scnNotification->nmhdr.code = NPPN_FILECLOSED; + //scnNotification->nmhdr.hwndFrom = hwndNpp; + //scnNotification->nmhdr.idFrom = BufferID; + + #define NPPN_SHUTDOWN (NPPN_FIRST + 9) // To notify plugins that Notepad++ is about to be shutdowned. + //scnNotification->nmhdr.code = NPPN_SHUTDOWN; + //scnNotification->nmhdr.hwndFrom = hwndNpp; + //scnNotification->nmhdr.idFrom = 0; + + #define NPPN_BUFFERACTIVATED (NPPN_FIRST + 10) // To notify plugins that a buffer was activated (put to foreground). + //scnNotification->nmhdr.code = NPPN_BUFFERACTIVATED; + //scnNotification->nmhdr.hwndFrom = hwndNpp; + //scnNotification->nmhdr.idFrom = activatedBufferID; + + #define NPPN_LANGCHANGED (NPPN_FIRST + 11) // To notify plugins that the language in the current doc is just changed. + //scnNotification->nmhdr.code = NPPN_LANGCHANGED; + //scnNotification->nmhdr.hwndFrom = hwndNpp; + //scnNotification->nmhdr.idFrom = currentBufferID; + + #define NPPN_WORDSTYLESUPDATED (NPPN_FIRST + 12) // To notify plugins that user initiated a WordStyleDlg change. + //scnNotification->nmhdr.code = NPPN_WORDSTYLESUPDATED; + //scnNotification->nmhdr.hwndFrom = hwndNpp; + //scnNotification->nmhdr.idFrom = currentBufferID; + + #define NPPN_SHORTCUTREMAPPED (NPPN_FIRST + 13) // To notify plugins that plugin command shortcut is remapped. + //scnNotification->nmhdr.code = NPPN_SHORTCUTSREMAPPED; + //scnNotification->nmhdr.hwndFrom = ShortcutKeyStructurePointer; + //scnNotification->nmhdr.idFrom = cmdID; + //where ShortcutKeyStructurePointer is pointer of struct ShortcutKey: + //struct ShortcutKey { + // bool _isCtrl; + // bool _isAlt; + // bool _isShift; + // UCHAR _key; + //}; + + #define NPPN_FILEBEFORELOAD (NPPN_FIRST + 14) // To notify plugins that the current file is about to be loaded + //scnNotification->nmhdr.code = NPPN_FILEBEFOREOPEN; + //scnNotification->nmhdr.hwndFrom = hwndNpp; + //scnNotification->nmhdr.idFrom = NULL; + + #define NPPN_FILELOADFAILED (NPPN_FIRST + 15) // To notify plugins that file open operation failed + //scnNotification->nmhdr.code = NPPN_FILEOPENFAILED; + //scnNotification->nmhdr.hwndFrom = hwndNpp; + //scnNotification->nmhdr.idFrom = BufferID; + +#endif //NOTEPAD_PLUS_MSGS_H diff --git a/PowerEditor/src/MISC/PluginsManager/PluginInterface.h b/PowerEditor/src/MISC/PluginsManager/PluginInterface.h new file mode 100644 index 00000000..ddc5bd08 --- /dev/null +++ b/PowerEditor/src/MISC/PluginsManager/PluginInterface.h @@ -0,0 +1,69 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef PLUGININTERFACE_H +#define PLUGININTERFACE_H + +#include +#include "Scintilla.h" +#include "Notepad_plus_msgs.h" + +const int nbChar = 64; + +typedef const TCHAR * (__cdecl * PFUNCGETNAME)(); + +struct NppData { + HWND _nppHandle; + HWND _scintillaMainHandle; + HWND _scintillaSecondHandle; +}; + +typedef void (__cdecl * PFUNCSETINFO)(NppData); +typedef void (__cdecl * PFUNCPLUGINCMD)(); +typedef void (__cdecl * PBENOTIFIED)(SCNotification *); +typedef LRESULT (__cdecl * PMESSAGEPROC)(UINT Message, WPARAM wParam, LPARAM lParam); + + +struct ShortcutKey { + bool _isCtrl; + bool _isAlt; + bool _isShift; + UCHAR _key; +}; + +struct FuncItem { + TCHAR _itemName[nbChar]; + PFUNCPLUGINCMD _pFunc; + int _cmdID; + bool _init2Check; + ShortcutKey *_pShKey; +}; + +typedef FuncItem * (__cdecl * PFUNCGETFUNCSARRAY)(int *); + +// You should implement (or define an empty function body) those functions which are called by Notepad++ plugin manager +extern "C" __declspec(dllexport) void setInfo(NppData); +extern "C" __declspec(dllexport) const TCHAR * getName(); +extern "C" __declspec(dllexport) FuncItem * getFuncsArray(int *); +extern "C" __declspec(dllexport) void beNotified(SCNotification *); +extern "C" __declspec(dllexport) LRESULT messageProc(UINT Message, WPARAM wParam, LPARAM lParam); + +#ifdef UNICODE +extern "C" __declspec(dllexport) BOOL isUnicode(); +#endif //UNICODE + +#endif //PLUGININTERFACE_H diff --git a/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp b/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp new file mode 100644 index 00000000..f70bdb18 --- /dev/null +++ b/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp @@ -0,0 +1,301 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#include +#include "PluginsManager.h" + +const TCHAR * USERMSG = TEXT("This plugin is not compatible with current version of Notepad++.\n\n\ +Do you want to remove this plugin from plugins directory to prevent this message from the next launch time?"); + +bool PluginsManager::loadPlugins(const TCHAR *dir) +{ + if (_isDisabled) + return false; + + vector dllNames; + vector dll2Remove; + const TCHAR *pNppPath = (NppParameters::getInstance())->getNppPath(); + + generic_string pluginsFullPathFilter = (dir && dir[0])?dir:pNppPath; + + pluginsFullPathFilter += TEXT("\\plugins\\*.dll"); + + WIN32_FIND_DATA foundData; + HANDLE hFindFile = ::FindFirstFile(pluginsFullPathFilter.c_str(), &foundData); + if (hFindFile != INVALID_HANDLE_VALUE) + { + generic_string plugins1stFullPath = (dir && dir[0])?dir:pNppPath; + plugins1stFullPath += TEXT("\\plugins\\"); + plugins1stFullPath += foundData.cFileName; + dllNames.push_back(plugins1stFullPath); + + while (::FindNextFile(hFindFile, &foundData)) + { + generic_string fullPath = (dir && dir[0])?dir:pNppPath; + fullPath += TEXT("\\plugins\\"); + fullPath += foundData.cFileName; + dllNames.push_back(fullPath); + } + ::FindClose(hFindFile); + + size_t i = 0; + + for ( ; i < dllNames.size() ; i++) + { + PluginInfo *pi = new PluginInfo; + try { + TCHAR tmpStr[MAX_PATH]; + lstrcpy(tmpStr, dllNames[i].c_str()); + lstrcpy(pi->_moduleName, PathFindFileName(tmpStr)); + + pi->_hLib = ::LoadLibrary(dllNames[i].c_str()); + if (!pi->_hLib) + throw generic_string(TEXT("Load Library is failed.\nMake \"Runtime Library\" setting of this project as \"Multi-threaded(/MT)\" may cure this problem.")); + + pi->_pFuncIsUnicode = (PFUNCISUNICODE)GetProcAddress(pi->_hLib, "isUnicode"); +#ifdef UNICODE + if (!pi->_pFuncIsUnicode || !pi->_pFuncIsUnicode()) + throw generic_string(TEXT("This ANSI plugin is not compatible with your Unicode Notepad++.")); +#else + if (pi->_pFuncIsUnicode) + throw generic_string(TEXT("This Unicode plugin is not compatible with your ANSI mode Notepad++.")); +#endif + + pi->_pFuncSetInfo = (PFUNCSETINFO)GetProcAddress(pi->_hLib, "setInfo"); + + if (!pi->_pFuncSetInfo) + throw generic_string(TEXT("Missing \"setInfo\" function")); + + pi->_pFuncGetName = (PFUNCGETNAME)GetProcAddress(pi->_hLib, "getName"); + if (!pi->_pFuncGetName) + throw generic_string(TEXT("Missing \"getName\" function")); + + pi->_pBeNotified = (PBENOTIFIED)GetProcAddress(pi->_hLib, "beNotified"); + if (!pi->_pBeNotified) + throw generic_string(TEXT("Missing \"beNotified\" function")); + + pi->_pMessageProc = (PMESSAGEPROC)GetProcAddress(pi->_hLib, "messageProc"); + if (!pi->_pMessageProc) + throw generic_string(TEXT("Missing \"messageProc\" function")); + + pi->_pFuncSetInfo(_nppData); + + pi->_pFuncGetFuncsArray = (PFUNCGETFUNCSARRAY)GetProcAddress(pi->_hLib, "getFuncsArray"); + if (!pi->_pFuncGetFuncsArray) + throw generic_string(TEXT("Missing \"getFuncsArray\" function")); + + pi->_funcItems = pi->_pFuncGetFuncsArray(&pi->_nbFuncItem); + + if ((!pi->_funcItems) || (pi->_nbFuncItem <= 0)) + throw generic_string(TEXT("Missing \"FuncItems\" array, or the nb of Function Item is not set correctly")); + + pi->_pluginMenu = ::CreateMenu(); + + GetLexerCountFn GetLexerCount = (GetLexerCountFn)::GetProcAddress(pi->_hLib, "GetLexerCount"); + // it's a lexer plugin + if (GetLexerCount) + { + GetLexerNameFn GetLexerName = (GetLexerNameFn)::GetProcAddress(pi->_hLib, "GetLexerName"); + if (!GetLexerName) + throw generic_string(TEXT("Loading GetLexerName function failed.")); + + GetLexerStatusTextFn GetLexerStatusText = (GetLexerStatusTextFn)::GetProcAddress(pi->_hLib, "GetLexerStatusText"); + + if (!GetLexerStatusText) + throw generic_string(TEXT("Loading GetLexerStatusText function failed.")); + + // Assign a buffer for the lexer name. + char lexName[MAX_EXTERNAL_LEXER_NAME_LEN]; + lexName[0] = '\0'; + TCHAR lexDesc[MAX_EXTERNAL_LEXER_DESC_LEN]; + lstrcpy(lexDesc, TEXT("")); + + int numLexers = GetLexerCount(); + + NppParameters * nppParams = NppParameters::getInstance(); + + ExternalLangContainer *containers[30]; +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); +#endif + for (int x = 0; x < numLexers; x++) + { + GetLexerName(x, lexName, MAX_EXTERNAL_LEXER_NAME_LEN); + GetLexerStatusText(x, lexDesc, MAX_EXTERNAL_LEXER_DESC_LEN); +#ifdef UNICODE + const TCHAR *pLexerName = wmc->char2wchar(lexName, CP_ACP); +#else + const TCHAR *pLexerName = lexName; +#endif + if (!nppParams->isExistingExternalLangName(pLexerName) && nppParams->ExternalLangHasRoom()) + containers[x] = new ExternalLangContainer(pLexerName, lexDesc); + else + containers[x] = NULL; + } + + TCHAR xmlPath[MAX_PATH]; + lstrcpy(xmlPath, nppParams->getNppPath()); + PathAppend(xmlPath, TEXT("plugins\\Config")); + PathAppend(xmlPath, pi->_moduleName); + PathRemoveExtension(xmlPath); + PathAddExtension(xmlPath, TEXT(".xml")); + + if (!PathFileExists(xmlPath)) + { + lstrcpyn( xmlPath, TEXT("\0"), MAX_PATH ); + lstrcpy( xmlPath, nppParams->getAppDataNppDir() ); + PathAppend(xmlPath, TEXT("plugins\\Config")); + PathAppend( xmlPath, pi->_moduleName ); + PathRemoveExtension( xmlPath ); + PathAddExtension( xmlPath, TEXT(".xml") ); + + if (! PathFileExists( xmlPath ) ) + { + throw generic_string(generic_string(xmlPath) + TEXT(" is missing.")); + } + } + + TiXmlDocument *_pXmlDoc = new TiXmlDocument(xmlPath); + + if (!_pXmlDoc->LoadFile()) + { + delete _pXmlDoc; + _pXmlDoc = NULL; + throw generic_string(generic_string(xmlPath) + TEXT(" failed to load.")); + } + + for (int x = 0; x < numLexers; x++) // postpone adding in case the xml is missing/corrupt + if (containers[x] != NULL) + nppParams->addExternalLangToEnd(containers[x]); + + nppParams->getExternalLexerFromXmlTree(_pXmlDoc); + nppParams->getExternalLexerDoc()->push_back(_pXmlDoc); +#ifdef UNICODE + const char *pDllName = wmc->wchar2char(dllNames[i].c_str(), CP_ACP); +#else + const char *pDllName = dllNames[i].c_str(); +#endif + ::SendMessage(_nppData._scintillaMainHandle, SCI_LOADLEXERLIBRARY, 0, (LPARAM)pDllName); + } + _pluginInfos.push_back(pi); + } + catch(generic_string s) + { + s += TEXT("\n\n"); + s += USERMSG; + if (::MessageBox(NULL, s.c_str(), dllNames[i].c_str(), MB_YESNO) == IDYES) + { + dll2Remove.push_back(dllNames[i]); + } + delete pi; + } + catch(...) + { + generic_string msg = TEXT("Fail loaded"); + msg += TEXT("\n\n"); + msg += USERMSG; + if (::MessageBox(NULL, msg.c_str(), dllNames[i].c_str(), MB_YESNO) == IDYES) + { + dll2Remove.push_back(dllNames[i]); + } + delete pi; + } + } + } + + for (size_t j = 0 ; j < dll2Remove.size() ; j++) + ::DeleteFile(dll2Remove[j].c_str()); + + return true; +} + +// return true if cmdID found and its shortcut is enable +// false otherwise +bool PluginsManager::getShortcutByCmdID(int cmdID, ShortcutKey *sk) +{ + if (cmdID == 0 || !sk) + return false; + + const vector & pluginCmdSCList = (NppParameters::getInstance())->getPluginCommandList(); + + for (size_t i = 0 ; i < pluginCmdSCList.size() ; i++) + { + if (pluginCmdSCList[i].getID() == cmdID) + { + const KeyCombo & kc = pluginCmdSCList[i].getKeyCombo(); + if (kc._key == 0x00) + return false; + + sk->_isAlt = kc._isAlt; + sk->_isCtrl = kc._isCtrl; + sk->_isShift = kc._isShift; + sk->_key = kc._key; + return true; + } + } + return false; +} + +void PluginsManager::setMenu(HMENU hMenu, const TCHAR *menuName) +{ + if (hasPlugins()) + { + vector & pluginCmdSCList = (NppParameters::getInstance())->getPluginCommandList(); + const TCHAR *nom_menu = (menuName && menuName[0])?menuName:TEXT("Plugins"); + + _hPluginsMenu = ::CreateMenu(); + ::InsertMenu(hMenu, 9, MF_BYPOSITION | MF_POPUP, (UINT_PTR)_hPluginsMenu, nom_menu); + + for (size_t i = 0 ; i < _pluginInfos.size() ; i++) + { + ::InsertMenu(_hPluginsMenu, i, MF_BYPOSITION | MF_POPUP, (UINT_PTR)_pluginInfos[i]->_pluginMenu, _pluginInfos[i]->_pFuncGetName()); + + for (int j = 0 ; j < _pluginInfos[i]->_nbFuncItem ; j++) + { + if (_pluginInfos[i]->_funcItems[j]._pFunc == NULL) + { + ::InsertMenu(_pluginInfos[i]->_pluginMenu, j, MF_BYPOSITION | MF_SEPARATOR, 0, TEXT("")); + continue; + } + + _pluginsCommands.push_back(PluginCommand(_pluginInfos[i]->_moduleName, j, _pluginInfos[i]->_funcItems[j]._pFunc)); + + int cmdID = ID_PLUGINS_CMD + (_pluginsCommands.size() - 1); + _pluginInfos[i]->_funcItems[j]._cmdID = cmdID; + generic_string itemName = _pluginInfos[i]->_funcItems[j]._itemName; + + if (_pluginInfos[i]->_funcItems[j]._pShKey) + { + ShortcutKey & sKey = *(_pluginInfos[i]->_funcItems[j]._pShKey); + PluginCmdShortcut pcs(Shortcut(itemName.c_str(), sKey._isCtrl, sKey._isAlt, sKey._isShift, sKey._key), cmdID, _pluginInfos[i]->_moduleName, j); + pluginCmdSCList.push_back(pcs); + itemName += TEXT("\t"); + itemName += pcs.toString(); + } + else + { //no ShortcutKey is provided, add an disabled shortcut (so it can still be mapped, Paramaters class can still index any changes and the toolbar wont funk out + PluginCmdShortcut pcs(Shortcut(itemName.c_str(), false, false, false, 0x00), cmdID, _pluginInfos[i]->_moduleName, j); //VK_NULL and everything disabled, the menu name is left alone + pluginCmdSCList.push_back(pcs); + } + ::InsertMenu(_pluginInfos[i]->_pluginMenu, j, MF_BYPOSITION, cmdID, itemName.c_str()); + + if (_pluginInfos[i]->_funcItems[j]._init2Check) + ::CheckMenuItem(_hPluginsMenu, cmdID, MF_BYCOMMAND | MF_CHECKED); + } + } + } +} diff --git a/PowerEditor/src/MISC/PluginsManager/PluginsManager.h b/PowerEditor/src/MISC/PluginsManager/PluginsManager.h new file mode 100644 index 00000000..66770e09 --- /dev/null +++ b/PowerEditor/src/MISC/PluginsManager/PluginsManager.h @@ -0,0 +1,155 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef PLUGINSMANAGER_H +#define PLUGINSMANAGER_H + +#include "resource.h" +#include "Parameters.h" +#include "PluginInterface.h" + +typedef BOOL (__cdecl * PFUNCISUNICODE)(); + +struct PluginCommand { + TCHAR _pluginName[64]; + int _funcID; + PFUNCPLUGINCMD _pFunc; + PluginCommand(const TCHAR *pluginName, int funcID, PFUNCPLUGINCMD pFunc): _funcID(funcID), _pFunc(pFunc){ + lstrcpy(_pluginName, pluginName); + }; +}; + +struct PluginInfo { + PluginInfo() :_hLib(NULL), _pluginMenu(NULL), _pFuncSetInfo(NULL),\ + _pFuncGetFuncsArray(NULL), _pFuncGetName(NULL), _funcItems(NULL),\ + _nbFuncItem(0){}; + ~PluginInfo(){ + if (_pluginMenu) + ::DestroyMenu(_pluginMenu); + + if (_hLib) + ::FreeLibrary(_hLib); + }; + + HINSTANCE _hLib; + HMENU _pluginMenu; + + PFUNCSETINFO _pFuncSetInfo; + PFUNCGETNAME _pFuncGetName; + PBENOTIFIED _pBeNotified; + PFUNCGETFUNCSARRAY _pFuncGetFuncsArray; + PMESSAGEPROC _pMessageProc; + PFUNCISUNICODE _pFuncIsUnicode; + + FuncItem *_funcItems; + int _nbFuncItem; + TCHAR _moduleName[64]; +}; + +class PluginsManager { +public: + PluginsManager() : _hPluginsMenu(NULL), _isDisabled(false) {}; + ~PluginsManager() { + + for (size_t i = 0 ; i < _pluginInfos.size() ; i++) + delete _pluginInfos[i]; + + if (_hPluginsMenu) + DestroyMenu(_hPluginsMenu); + }; + void init(const NppData & nppData) { + _nppData = nppData; + }; + bool loadPlugins(const TCHAR *dir = NULL); + + void runPluginCommand(size_t i) { + if (i < _pluginsCommands.size()) + if (_pluginsCommands[i]._pFunc != NULL) + _pluginsCommands[i]._pFunc(); + }; + + void runPluginCommand(const TCHAR *pluginName, int commandID) { + for (size_t i = 0 ; i < _pluginsCommands.size() ; i++) + { + if (!generic_stricmp(_pluginsCommands[i]._pluginName, pluginName)) + { + if (_pluginsCommands[i]._funcID == commandID) + _pluginsCommands[i]._pFunc(); + } + } + }; + + void setMenu(HMENU hMenu, const TCHAR *menuName); + bool getShortcutByCmdID(int cmdID, ShortcutKey *sk); + + void notify(SCNotification *notification) { + for (size_t i = 0 ; i < _pluginInfos.size() ; i++) + { + // To avoid the plugin change the data in SCNotification + // Each notification to pass to a plugin is a copy of SCNotification instance + SCNotification scNotif = *notification; + _pluginInfos[i]->_pBeNotified(&scNotif); + } + }; + + void relayNppMessages(UINT Message, WPARAM wParam, LPARAM lParam) { + for (size_t i = 0 ; i < _pluginInfos.size() ; i++) + { + _pluginInfos[i]->_pMessageProc(Message, wParam, lParam); + } + }; + + bool relayPluginMessages(UINT Message, WPARAM wParam, LPARAM lParam) { + const TCHAR * moduleName = (const TCHAR *)wParam; + if (!moduleName || !moduleName[0] || !lParam) + return false; + + for (size_t i = 0 ; i < _pluginInfos.size() ; i++) + { + if (generic_stricmp(_pluginInfos[i]->_moduleName, moduleName) == 0) + { + _pluginInfos[i]->_pMessageProc(Message, wParam, lParam); + return true; + } + } + return false; + }; + + HMENU getMenuHandle() { + return _hPluginsMenu; + }; + + void disable() {_isDisabled = true;}; + bool hasPlugins(){return (_pluginInfos.size()!= 0);}; + +private: + NppData _nppData; + HMENU _hPluginsMenu; + + vector _pluginInfos; + vector _pluginsCommands; + bool _isDisabled; +}; + +#define EXT_LEXER_DECL __stdcall + +// External Lexer function definitions... +typedef int (EXT_LEXER_DECL *GetLexerCountFn)(); +typedef void (EXT_LEXER_DECL *GetLexerNameFn)(unsigned int Index, char *name, int buflength); +typedef void (EXT_LEXER_DECL *GetLexerStatusTextFn)(unsigned int Index, TCHAR *desc, int buflength); + +#endif //PLUGINSMANAGER_H diff --git a/PowerEditor/src/MISC/PluginsManager/deprecatedSymbols.h b/PowerEditor/src/MISC/PluginsManager/deprecatedSymbols.h new file mode 100644 index 00000000..7fe8dc71 --- /dev/null +++ b/PowerEditor/src/MISC/PluginsManager/deprecatedSymbols.h @@ -0,0 +1,68 @@ +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +// +#define NOTEPADPLUS_USER (WM_USER + 1000) + +#define WM_GETCURRENTSCINTILLA (NOTEPADPLUS_USER + 4) +#define WM_GETCURRENTLANGTYPE (NOTEPADPLUS_USER + 5) +#define WM_SETCURRENTLANGTYPE (NOTEPADPLUS_USER + 6) +#define WM_NBOPENFILES (NOTEPADPLUS_USER + 7) +#define WM_GETOPENFILENAMES (NOTEPADPLUS_USER + 8) + +#define WM_MODELESSDIALOG (NOTEPADPLUS_USER + 12) +#define WM_NBSESSIONFILES (NOTEPADPLUS_USER + 13) +#define WM_GETSESSIONFILES (NOTEPADPLUS_USER + 14) +#define WM_SAVESESSION (NOTEPADPLUS_USER + 15) +#define WM_SAVECURRENTSESSION (NOTEPADPLUS_USER + 16) +#define WM_GETOPENFILENAMES_PRIMARY (NOTEPADPLUS_USER + 17) +#define WM_GETOPENFILENAMES_SECOND (NOTEPADPLUS_USER + 18) + +#define WM_CREATESCINTILLAHANDLE (NOTEPADPLUS_USER + 20) +#define WM_DESTROYSCINTILLAHANDLE (NOTEPADPLUS_USER + 21) +#define WM_GETNBUSERLANG (NOTEPADPLUS_USER + 22) +#define WM_GETCURRENTDOCINDEX (NOTEPADPLUS_USER + 23) +#define WM_SETSTATUSBAR (NOTEPADPLUS_USER + 24) +#define WM_GETMENUHANDLE (NOTEPADPLUS_USER + 25) +#define WM_ENCODE_SCI (NOTEPADPLUS_USER + 26) +#define WM_DECODE_SCI (NOTEPADPLUS_USER + 27) +#define WM_ACTIVATE_DOC (NOTEPADPLUS_USER + 28) +#define WM_LAUNCH_FINDINFILESDLG (NOTEPADPLUS_USER + 29) +#define WM_DMM_SHOW (NOTEPADPLUS_USER + 30) +#define WM_DMM_HIDE (NOTEPADPLUS_USER + 31) +#define WM_DMM_UPDATEDISPINFO (NOTEPADPLUS_USER + 32) +#define WM_DMM_REGASDCKDLG (NOTEPADPLUS_USER + 33) +#define WM_LOADSESSION (NOTEPADPLUS_USER + 34) +#define WM_DMM_VIEWOTHERTAB (NOTEPADPLUS_USER + 35) +#define WM_RELOADFILE (NOTEPADPLUS_USER + 36) +#define WM_SWITCHTOFILE (NOTEPADPLUS_USER + 37) +#define WM_SAVECURRENTFILE (NOTEPADPLUS_USER + 38) +#define WM_SAVEALLFILES (NOTEPADPLUS_USER + 39) +#define WM_PIMENU_CHECK (NOTEPADPLUS_USER + 40) +#define WM_ADDTOOLBARICON (NOTEPADPLUS_USER + 41) +#define WM_GETWINDOWSVERSION (NOTEPADPLUS_USER + 42) +#define WM_DMM_GETPLUGINHWNDBYNAME (NOTEPADPLUS_USER + 43) + + + +#define RUNCOMMAND_USER_ (WM_USER + 3000) + +#define WM_GET_FULLCURRENTPATH (RUNCOMMAND_USER_ + FULL_CURRENT_PATH) +#define WM_GET_CURRENTDIRECTORY (RUNCOMMAND_USER_ + CURRENT_DIRECTORY) +#define WM_GET_FILENAME (RUNCOMMAND_USER_ + FILE_NAME) +#define WM_GET_NAMEPART (RUNCOMMAND_USER_ + NAME_PART) +#define WM_GET_EXTPART (RUNCOMMAND_USER_ + EXT_PART) +#define WM_GET_CURRENTWORD (RUNCOMMAND_USER_ + CURRENT_WORD) +#define WM_GET_NPPDIRECTORY (RUNCOMMAND_USER_ + NPP_DIRECTORY) diff --git a/PowerEditor/src/MISC/Process/Process.cpp b/PowerEditor/src/MISC/Process/Process.cpp new file mode 100644 index 00000000..5b13582f --- /dev/null +++ b/PowerEditor/src/MISC/Process/Process.cpp @@ -0,0 +1,301 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#include "process.h" + +BOOL Process::run() +{ + BOOL result = TRUE; + + // stdout & stderr pipes for process to write + HANDLE hPipeOutW = NULL; + HANDLE hPipeErrW = NULL; + + HANDLE hListenerStdOutThread = NULL; + HANDLE hListenerStdErrThread = NULL; + + HANDLE hWaitForProcessEndThread = NULL; + + HANDLE hListenerEvent[2]; + hListenerEvent[0] = NULL; + hListenerEvent[1] = NULL; + + SECURITY_ATTRIBUTES sa = {sizeof(SECURITY_ATTRIBUTES), NULL, TRUE }; // inheritable handle + + try { + // Create stdout pipe + if (!::CreatePipe(&_hPipeOutR, &hPipeOutW, &sa, 0)) + error(TEXT("CreatePipe"), result, 1000); + + // Create stderr pipe + if (!::CreatePipe(&_hPipeErrR, &hPipeErrW, &sa, 0)) + error(TEXT("CreatePipe"), result, 1001); + + STARTUPINFO startup; + PROCESS_INFORMATION procinfo; + ::ZeroMemory(&startup, sizeof(startup)); + startup.cb = sizeof(startup); + startup.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES; + startup.wShowWindow = (_type == WIN32_PROG)?SW_SHOW:SW_HIDE; // hidden console window + startup.hStdInput = NULL; // not used + startup.hStdOutput = hPipeOutW; + startup.hStdError = hPipeErrW; + + generic_string cmd = TEXT("\""); + cmd += _command; + cmd += TEXT("\""); + + if (_args[0]) + { + cmd += TEXT(" "); + cmd += _args; + } + BOOL started = ::CreateProcess(NULL, // command is part of input generic_string + (TCHAR *)cmd.c_str(), // (writeable) command generic_string + NULL, // process security + NULL, // thread security + TRUE, // inherit handles flag + (_type == WIN32_PROG)?NULL:CREATE_SUSPENDED, // flags + NULL, // inherit environment + _curDir, // inherit directory + &startup, // STARTUPINFO + &procinfo); // PROCESS_INFORMATION + + _hProcess = procinfo.hProcess; + _hProcessThread = procinfo.hThread; + + if(!started) + error(TEXT("CreateProcess"), result, 1002); + + if (_type == CONSOLE_PROG) + { + hListenerEvent[0] = ::CreateEvent(NULL, FALSE, FALSE, TEXT("listenerEvent")); + if(!hListenerEvent[0]) + error(TEXT("CreateEvent"), result, 1003); + + hListenerEvent[1] = ::CreateEvent(NULL, FALSE, FALSE, TEXT("listenerStdErrEvent")); + if(!hListenerEvent[1]) + error(TEXT("CreateEvent"), result, 1004); + + + // The process is running so we set this to FALSE + _bProcessEnd = FALSE; + + hWaitForProcessEndThread = ::CreateThread(NULL, 0, staticWaitForProcessEnd, this, 0, NULL); + if (!hWaitForProcessEndThread) + error(TEXT("CreateThread"), result, 1005); + + hListenerStdOutThread = ::CreateThread(NULL, 0, staticListenerStdOut, this, 0, NULL); + if (!hListenerStdOutThread) + error(TEXT("CreateThread"), result, 1006); + + hListenerStdErrThread = ::CreateThread(NULL, 0, staticListenerStdErr, this, 0, NULL); + if (!hListenerStdErrThread) + error(TEXT("CreateThread"), result, 1007); + + // We wait until the process is over + // TO DO: This should be a bit secured in case something happen and the + // _bProcessEnd variable never gets set to TRUE... (by checking process + // state as well for instance to see if it is still running...) + while (!_bProcessEnd) + { + MSG msg; + while( ::PeekMessage( &msg, NULL, 0, 0, PM_REMOVE)) + { + if( msg.message == WM_QUIT) + { + ::PostQuitMessage(0); + // We do not exit but simply break in order to close + // handles properly + _bProcessEnd = TRUE; + break; + } + else + { + ::TranslateMessage( &msg); + ::DispatchMessage( &msg); + } + } + } + } + } catch (int coderr){ + TCHAR str[10]; + wsprintf(str, TEXT("%d"), coderr); + ::MessageBox(NULL, str, TEXT("Exception :"), MB_OK); + } + + // on va fermer toutes les handles + if (hPipeOutW) + ::CloseHandle(hPipeOutW); + if (hPipeErrW) + ::CloseHandle(hPipeErrW); + if (_hPipeOutR) + ::CloseHandle(_hPipeOutR); + if (_hPipeErrR) + ::CloseHandle(_hPipeErrR); + if (hListenerStdOutThread) + ::CloseHandle(hListenerStdOutThread); + if (hListenerStdErrThread) + ::CloseHandle(hListenerStdErrThread); + if (hWaitForProcessEndThread) + ::CloseHandle(hWaitForProcessEndThread); + if (hListenerEvent[0]) + ::CloseHandle(hListenerEvent[0]); + if (hListenerEvent[1]) + ::CloseHandle(hListenerEvent[1]); + + return result; +} + + +#define MAX_LINE_LENGTH 1024 + +void Process::listenerStdOut() +{ + //BOOL Result = 0; + //DWORD size = 0; + DWORD bytesAvail = 0; + BOOL result = 0; + HANDLE hListenerEvent = ::OpenEvent(EVENT_ALL_ACCESS, FALSE, TEXT("listenerEvent")); + //FILE *fp = NULL; + + int taille = 0; + TCHAR bufferOut[MAX_LINE_LENGTH + 1]; + //TCHAR bufferErr[MAX_LINE_LENGTH + 1]; + + int nExitCode = STILL_ACTIVE; + + DWORD outbytesRead; + + ::ResumeThread(_hProcessThread); + + while (true) + { // got data + memset(bufferOut,0x00,MAX_LINE_LENGTH + 1); + //memset(bufferErr,0x00,MAX_LINE_LENGTH + 1); + taille = sizeof(bufferOut) - sizeof(TCHAR); + + Sleep(50); + + if (!::PeekNamedPipe(_hPipeOutR, bufferOut, taille, &outbytesRead, &bytesAvail, NULL)) + { + bytesAvail = 0; + break; + } + + if(outbytesRead) + { + result = :: ReadFile(_hPipeOutR, bufferOut, taille, &outbytesRead, NULL); + if ((!result) && (outbytesRead == 0)) + break; + } + //outbytesRead = lstrlen(bufferOut); + bufferOut[outbytesRead] = '\0'; + generic_string s; + s.assign(bufferOut); + _stdoutStr += s; + + if (::GetExitCodeProcess(_hProcess, (unsigned long*)&nExitCode)) + { + if (nExitCode != STILL_ACTIVE) + break; // EOF condition + } + //else + //break; + } + _exitCode = nExitCode; + + if(!::SetEvent(hListenerEvent)) + { + systemMessage(TEXT("Thread listenerStdOut")); + } +} + +void Process::listenerStdErr() +{ + //BOOL Result = 0; + //DWORD size = 0; + DWORD bytesAvail = 0; + BOOL result = 0; + HANDLE hListenerEvent = ::OpenEvent(EVENT_ALL_ACCESS, FALSE, TEXT("listenerStdErrEvent")); + + int taille = 0; + //TCHAR bufferOut[MAX_LINE_LENGTH + 1]; + TCHAR bufferErr[MAX_LINE_LENGTH + 1]; + + int nExitCode = STILL_ACTIVE; + + DWORD errbytesRead; + + ::ResumeThread(_hProcessThread); + + while (true) + { // got data + memset(bufferErr, 0x00, MAX_LINE_LENGTH + 1); + taille = sizeof(bufferErr) - sizeof(TCHAR); + + Sleep(50); + + if (!::PeekNamedPipe(_hPipeErrR, bufferErr, taille, &errbytesRead, &bytesAvail, NULL)) + { + bytesAvail = 0; + break; + } + + if(errbytesRead) + { + result = :: ReadFile(_hPipeErrR, bufferErr, taille, &errbytesRead, NULL); + if ((!result) && (errbytesRead == 0)) + break; + } + //outbytesRead = lstrlen(bufferOut); + bufferErr[errbytesRead] = '\0'; + generic_string s; + s.assign(bufferErr); + _stderrStr += s; + + if (::GetExitCodeProcess(_hProcess, (unsigned long*)&nExitCode)) + { + if (nExitCode != STILL_ACTIVE) + break; // EOF condition + } + } + + if(!::SetEvent(hListenerEvent)) + { + systemMessage(TEXT("Thread stdout listener")); + } +} + +void Process::waitForProcessEnd() +{ + HANDLE hListenerEvent[2]; + hListenerEvent[0] = ::OpenEvent(EVENT_ALL_ACCESS, FALSE, TEXT("listenerEvent")); + hListenerEvent[1] = ::OpenEvent(EVENT_ALL_ACCESS, FALSE, TEXT("listenerStdErrEvent")); + + ::WaitForSingleObject(_hProcess, INFINITE); + ::WaitForMultipleObjects(2, hListenerEvent, TRUE, INFINITE); + + _bProcessEnd = TRUE; +} + +void Process::error(const TCHAR *txt2display, BOOL & returnCode, int errCode) +{ + systemMessage(txt2display); + returnCode = FALSE; + throw int(errCode); +} diff --git a/PowerEditor/src/MISC/Process/Process.h b/PowerEditor/src/MISC/Process/Process.h new file mode 100644 index 00000000..c89be3d2 --- /dev/null +++ b/PowerEditor/src/MISC/Process/Process.h @@ -0,0 +1,111 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef PROCESSUS_H +#define PROCESSUS_H + +#include +#include +#include "Common.h" + +using namespace std; + +enum progType {WIN32_PROG, CONSOLE_PROG}; + +class Process +{ +public: + Process(progType pt = WIN32_PROG) : _type(pt) {}; + Process(const TCHAR *cmd, const TCHAR *args, const TCHAR *cDir, progType pt = WIN32_PROG) + : _type(pt), _stdoutStr(TEXT("")), _stderrStr(TEXT("")), _hPipeOutR(NULL), + _hPipeErrR(NULL), _hProcess(NULL), _hProcessThread(NULL) { + + lstrcpy(_command, cmd); + lstrcpy(_args, args); + lstrcpy(_curDir, cDir); + //_pid = id; + + _bProcessEnd = TRUE; + }; + + BOOL run(); + + const TCHAR * getStdout() const { + return _stdoutStr.c_str(); + }; + + const TCHAR * getStderr() const { + return _stderrStr.c_str(); + }; + + int getExitCode() const { + return _exitCode; + }; + + bool hasStdout() { + return (_stdoutStr.compare(TEXT("")) != 0); + }; + + bool hasStderr() { + return (_stderrStr.compare(TEXT("")) != 0); + }; + +protected: + progType _type; + + // LES ENTREES + TCHAR _command[MAX_PATH]; + TCHAR _args[MAX_PATH]; + TCHAR _curDir[MAX_PATH]; + + // LES SORTIES + generic_string _stdoutStr; + generic_string _stderrStr; + int _exitCode; + + // LES HANDLES + HANDLE _hPipeOutR; + HANDLE _hPipeErrR; + HANDLE _hProcess; + HANDLE _hProcessThread; + + BOOL _bProcessEnd; + + //UINT _pid; // process ID assigned by caller + + static DWORD WINAPI staticListenerStdOut(void * myself){ + ((Process *)myself)->listenerStdOut(); + return 0; + }; + static DWORD WINAPI staticListenerStdErr(void * myself) { + ((Process *)myself)->listenerStdErr(); + return 0; + }; + static DWORD WINAPI staticWaitForProcessEnd(void * myself) { + ((Process *)myself)->waitForProcessEnd(); + return 0; + }; + + void listenerStdOut(); + void listenerStdErr(); + void waitForProcessEnd(); + + void error(const TCHAR *txt2display, BOOL & returnCode, int errCode); +}; + +#endif //PROCESSUS_H + diff --git a/PowerEditor/src/MISC/Process/ProcessAvecThread/Process.cpp b/PowerEditor/src/MISC/Process/ProcessAvecThread/Process.cpp new file mode 100644 index 00000000..9141287e --- /dev/null +++ b/PowerEditor/src/MISC/Process/ProcessAvecThread/Process.cpp @@ -0,0 +1,243 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#include "process.h" +#include "SysMsg.h" + +BOOL Process::run() +{ + BOOL result = TRUE; + + // stdout & stderr pipes for process to write + HANDLE hPipeOutW = NULL; + HANDLE hPipeErrW = NULL; + + HANDLE hListenerStdOutThread = NULL; + HANDLE hListenerStdErrThread = NULL; + + HANDLE hListenerEvent[2]; + hListenerEvent[0] = NULL; + hListenerEvent[1] = NULL; + + SECURITY_ATTRIBUTES sa = {sizeof(SECURITY_ATTRIBUTES), NULL, TRUE }; // inheritable handle + + try { + // Create stdout pipe + if (!::CreatePipe(&_hPipeOutR, &hPipeOutW, &sa, 0)) + error("CreatePipe", result, 1000); + + // Create stderr pipe + if (!::CreatePipe(&_hPipeErrR, &hPipeErrW, &sa, 0)) + error("CreatePipe", result, 1001); + + STARTUPINFO startup; + PROCESS_INFORMATION procinfo; + ::ZeroMemory(&startup, sizeof(startup)); + startup.cb = sizeof(startup); + startup.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES; + startup.wShowWindow = SW_HIDE; // hidden console window + startup.hStdInput = NULL; // not used + startup.hStdOutput = hPipeOutW; + startup.hStdError = hPipeErrW; + + BOOL started = ::CreateProcess(NULL, // command is part of input string + _command, // (writeable) command string + NULL, // process security + NULL, // thread security + TRUE, // inherit handles flag + CREATE_SUSPENDED, // flags + NULL, // inherit environment + _curDir, // inherit directory + &startup, // STARTUPINFO + &procinfo); // PROCESS_INFORMATION + + _hProcess = procinfo.hProcess; + _hProcessThread = procinfo.hThread; + + if(!started) + error("CreateProcess", result, 1002); + + hListenerEvent[0] = ::CreateEvent(NULL, FALSE, FALSE, "listenerEvent"); + if(!hListenerEvent[0]) + error("CreateEvent", result, 1003); + + hListenerEvent[1] = ::CreateEvent(NULL, FALSE, FALSE, "listenerStdErrEvent"); + if(!hListenerEvent[1]) + error("CreateEvent", result, 1004); + + hListenerStdOutThread = ::CreateThread(NULL, 0, staticListenerStdOut, this, 0, NULL); + if (!hListenerStdOutThread) + error("CreateThread", result, 1005); + + hListenerStdErrThread = ::CreateThread(NULL, 0, staticListenerStdErr, this, 0, NULL); + if (!hListenerStdErrThread) + error("CreateThread", result, 1006); + + ::WaitForSingleObject(_hProcess, INFINITE); + ::WaitForMultipleObjects(2, hListenerEvent, TRUE, INFINITE); + } catch (int coderr){} + + // on va fermer toutes les handles + if (hPipeOutW) + ::CloseHandle(hPipeOutW); + if (hPipeErrW) + ::CloseHandle(hPipeErrW); + if (_hPipeOutR) + ::CloseHandle(_hPipeOutR); + if (_hPipeErrR) + ::CloseHandle(_hPipeErrR); + if (hListenerStdOutThread) + ::CloseHandle(hListenerStdOutThread); + if (hListenerStdErrThread) + ::CloseHandle(hListenerStdErrThread); + if (hListenerEvent[0]) + ::CloseHandle(hListenerEvent[0]); + if (hListenerEvent[1]) + ::CloseHandle(hListenerEvent[1]); + + return result; +} + + +#define MAX_LINE_LENGTH 1024 + +void Process::listenerStdOut() +{ + BOOL Result = 0; + DWORD size = 0; + DWORD bytesAvail = 0; + BOOL result = 0; + HANDLE hListenerEvent = ::OpenEvent(EVENT_ALL_ACCESS, FALSE, "listenerEvent"); + //FILE *fp = NULL; + + int taille = 0; + TCHAR bufferOut[MAX_LINE_LENGTH + 1]; + //TCHAR bufferErr[MAX_LINE_LENGTH + 1]; + + int nExitCode = STILL_ACTIVE; + + DWORD outbytesRead; + + ::ResumeThread(_hProcessThread); + + while (true) + { // got data + memset(bufferOut,0x00,MAX_LINE_LENGTH + 1); + //memset(bufferErr,0x00,MAX_LINE_LENGTH + 1); + taille = sizeof(bufferOut) - sizeof(TCHAR); + + Sleep(50); + + if (!::PeekNamedPipe(_hPipeOutR, bufferOut, taille, &outbytesRead, &bytesAvail, NULL)) + { + bytesAvail = 0; + break; + } + + if(outbytesRead) + { + result = :: ReadFile(_hPipeOutR, bufferOut, taille, &outbytesRead, NULL); + if ((!result) && (outbytesRead == 0)) + break; + } + //outbytesRead = strlen(bufferOut); + bufferOut[outbytesRead] = '\0'; + string s; + s.assign(bufferOut); + _stdoutStr += s; + + if (::GetExitCodeProcess(_hProcess, (unsigned long*)&nExitCode)) + { + if (nExitCode != STILL_ACTIVE) + break; // EOF condition + } + //else + //break; + } + _exitCode = nExitCode; + + if(!::SetEvent(hListenerEvent)) + { + systemMessage("Thread listenerStdOut"); + } +} + +void Process::listenerStdErr() +{ + BOOL Result = 0; + DWORD size = 0; + DWORD bytesAvail = 0; + BOOL result = 0; + HANDLE hListenerEvent = ::OpenEvent(EVENT_ALL_ACCESS, FALSE, "listenerStdErrEvent"); + + int taille = 0; + //TCHAR bufferOut[MAX_LINE_LENGTH + 1]; + TCHAR bufferErr[MAX_LINE_LENGTH + 1]; + + int nExitCode = STILL_ACTIVE; + + DWORD errbytesRead; + + ::ResumeThread(_hProcessThread); + + while (true) + { // got data + memset(bufferErr, 0x00, MAX_LINE_LENGTH + 1); + taille = sizeof(bufferErr) - sizeof(TCHAR); + + Sleep(50); + + if (!::PeekNamedPipe(_hPipeErrR, bufferErr, taille, &errbytesRead, &bytesAvail, NULL)) + { + bytesAvail = 0; + break; + } + + if(errbytesRead) + { + result = :: ReadFile(_hPipeErrR, bufferErr, taille, &errbytesRead, NULL); + if ((!result) && (errbytesRead == 0)) + break; + } + //outbytesRead = strlen(bufferOut); + bufferErr[errbytesRead] = '\0'; + string s; + s.assign(bufferErr); + _stderrStr += s; + + if (::GetExitCodeProcess(_hProcess, (unsigned long*)&nExitCode)) + { + if (nExitCode != STILL_ACTIVE) + break; // EOF condition + } + //else + //break; + } + //_exitCode = nExitCode; + + if(!::SetEvent(hListenerEvent)) + { + systemMessage("Thread stdout listener"); + } +} + +void Process::error(const char *txt2display, BOOL & returnCode, int errCode) +{ + systemMessage(txt2display); + returnCode = FALSE; + throw int(errCode); +} diff --git a/PowerEditor/src/MISC/Process/ProcessAvecThread/Process.h b/PowerEditor/src/MISC/Process/ProcessAvecThread/Process.h new file mode 100644 index 00000000..3da6e62e --- /dev/null +++ b/PowerEditor/src/MISC/Process/ProcessAvecThread/Process.h @@ -0,0 +1,92 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef PROCESSUS_H +#define PROCESSUS_H + +#include +#include +using namespace std; + +class Process +{ +public: + Process() {}; + Process(const char *cmd, const char *cDir/*, unsigned int id = 0*/) + : _stdoutStr(""), _stderrStr(""), _hPipeOutR(NULL), + _hPipeErrR(NULL), _hProcess(NULL), _hProcessThread(NULL) { + + strcpy(_command, cmd); + strcpy(_curDir, cDir); + //_pid = id; + }; + + BOOL run(); + + const char * getStdout() const { + return _stdoutStr.c_str(); + }; + + const char * getStderr() const { + return _stderrStr.c_str(); + }; + + int getExitCode() const { + return _exitCode; + }; + + bool hasStdout() { + return _stdoutStr.compare(""); + }; + + bool hasStderr() { + return _stderrStr.compare(""); + }; + +protected: + // LES ENTREES + char _command[256]; + char _curDir[256]; + + // LES SORTIES + string _stdoutStr; + string _stderrStr; + int _exitCode; + + // LES HANDLES + HANDLE _hPipeOutR; + HANDLE _hPipeErrR; + HANDLE _hProcess; + HANDLE _hProcessThread; + + //UINT _pid; // process ID assigned by caller + + static DWORD WINAPI staticListenerStdOut(void * myself){ + ((Process *)myself)->listenerStdOut(); + return 0; + }; + static DWORD WINAPI staticListenerStdErr(void * myself) { + ((Process *)myself)->listenerStdErr(); + return 0; + }; + void listenerStdOut(); + void listenerStdErr(); + void error(const char *txt2display, BOOL & returnCode, int errCode); +}; + +#endif //PROCESSUS_H + diff --git a/PowerEditor/src/MISC/Process/ProcessAvecThread/ProcessThread.h b/PowerEditor/src/MISC/Process/ProcessAvecThread/ProcessThread.h new file mode 100644 index 00000000..c2abfc26 --- /dev/null +++ b/PowerEditor/src/MISC/Process/ProcessAvecThread/ProcessThread.h @@ -0,0 +1,85 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef PROCESS_THREAD_H +#define PROCESS_THREAD_H + +#include "process.h" + +class ProcessThread +{ +public : + ProcessThread(const char *appName, const char *cmd, const char *cDir, HWND hwnd) : _hwnd(hwnd) { + strcpy(_appName, appName); + strcpy(_command, cmd); + strcpy(_curDir, cDir); + }; + + BOOL run(){ + HANDLE hEvent = ::CreateEvent(NULL, FALSE, FALSE, "localVarProcessEvent"); + + _hProcessThread = ::CreateThread(NULL, 0, staticLauncher, this, 0, NULL); + + ::WaitForSingleObject(hEvent, INFINITE); + + ::CloseHandle(hEvent); + return TRUE; + }; + +protected : + // ENTREES + char _appName[256]; + char _command[256]; + char _curDir[256]; + HWND _hwnd; + HANDLE _hProcessThread; + + static DWORD WINAPI staticLauncher(void *myself) { + ((ProcessThread *)myself)->launch(); + return TRUE; + }; + + bool launch() { + HANDLE hEvent = ::OpenEvent(EVENT_ALL_ACCESS, FALSE, "localVarProcessEvent"); + HWND hwnd = _hwnd; + char appName[256]; + strcpy(appName, _appName); + HANDLE hMyself = _hProcessThread; + + Process process(_command, _curDir); + + if(!::SetEvent(hEvent)) + { + systemMessage("Thread launcher"); + } + + process.run(); + + int code = process.getExitCode(); + char codeStr[256]; + sprintf(codeStr, "%s : %0.4X", appName, code); + ::MessageBox(hwnd, (char *)process.getStdout(), codeStr, MB_OK); + + if (process.hasStderr()) + ::MessageBox(hwnd, (char *)process.getStderr(), codeStr, MB_OK); + + ::CloseHandle(hMyself); + return true; + }; +}; + +#endif PROCESS_THREAD_H diff --git a/PowerEditor/src/MISC/RegExt/regExtDlg.cpp b/PowerEditor/src/MISC/RegExt/regExtDlg.cpp new file mode 100644 index 00000000..c32a6654 --- /dev/null +++ b/PowerEditor/src/MISC/RegExt/regExtDlg.cpp @@ -0,0 +1,388 @@ +/* +this file is part of notepad++ +Copyright (C)2003 Don HO ( donho@altern.org ) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ +#include +#include "regExtDlg.h" +#include "resource.h" +#include "Common.h" + +const TCHAR *nppName = TEXT("Notepad++_file"); +const TCHAR *nppBackup = TEXT("Notepad++_backup"); +const TCHAR *nppDoc = TEXT("Notepad++ Document"); + +const int nbSupportedLang = 9; +const int nbExtMax = 10; +const int extNameMax = 18; + +TCHAR defExtArray[nbSupportedLang][nbExtMax][extNameMax] = { + {TEXT("Notepad"), TEXT(".txt"), TEXT(".log"), TEXT(".ini")}, + {TEXT("c, c++, objc"), TEXT(".h"), TEXT(".hpp"), TEXT(".hxx"), TEXT(".c"), TEXT(".cpp"), TEXT(".cxx"), TEXT(".cc"), TEXT(".m")}, + {TEXT("java, c#, pascal"), TEXT(".java"), TEXT(".cs"), TEXT(".pas"), TEXT(".inc")}, + {TEXT("web(html) script"), TEXT(".html"), TEXT(".htm"), TEXT(".php"), TEXT(".phtml"), TEXT(".js"), TEXT(".jsp"), TEXT(".asp"), TEXT(".css"), TEXT(".xml")}, + {TEXT("public script"), TEXT(".sh"), TEXT(".bsh"), TEXT(".nsi"), TEXT(".nsh"), TEXT(".lua"), TEXT(".pl"), TEXT(".pm"), TEXT(".py")}, + {TEXT("property script"), TEXT(".rc"), TEXT(".as"), TEXT(".mx"), TEXT(".vb"), TEXT(".vbs")}, + {TEXT("fortran, TeX, SQL"), TEXT(".f"), TEXT(".for"), TEXT(".f90"), TEXT(".f95"), TEXT(".f2k"), TEXT(".tex"), TEXT(".sql")}, + {TEXT("misc"), TEXT(".nfo"), TEXT(".mak")}, + {TEXT("customize")} +}; + +void RegExtDlg::doDialog(bool isRTL) +{ + if (isRTL) + { + DLGTEMPLATE *pMyDlgTemplate = NULL; + HGLOBAL hMyDlgTemplate = makeRTLResource(IDD_REGEXT_BOX, &pMyDlgTemplate); + ::DialogBoxIndirectParam(_hInst, pMyDlgTemplate, _hParent, (DLGPROC)dlgProc, (LPARAM)this); + ::GlobalFree(hMyDlgTemplate); + } + else + ::DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_REGEXT_BOX), _hParent, (DLGPROC)dlgProc, (LPARAM)this); +}; + +BOOL CALLBACK RegExtDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam) +{ + switch (Message) + { + case WM_INITDIALOG : + { + getRegisteredExts(); + getDefSupportedExts(); + //goToCenter(); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_ADDFROMLANGEXT_BUTTON), false); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_REMOVEEXT_BUTTON), false); + ::SendDlgItemMessage(_hSelf, IDC_CUSTOMEXT_EDIT, EM_SETLIMITTEXT, extNameMax-1, 0); + + return TRUE; + } + + case WM_DRAWITEM : + { + HICON hIcon = ::LoadIcon(_hInst, MAKEINTRESOURCE(IDI_DELETE_ICON)); + DRAWITEMSTRUCT *pdis = (DRAWITEMSTRUCT *)lParam; + ::DrawIcon(pdis->hDC, 0, 0, hIcon); + return TRUE; + } + + case WM_COMMAND : + { + switch (wParam) + { + case IDC_ADDFROMLANGEXT_BUTTON : + { + writeNppPath(); + + TCHAR ext2Add[extNameMax] = TEXT(""); + if (!_isCustomize) + { + int index2Add = ::SendDlgItemMessage(_hSelf, IDC_REGEXT_LANGEXT_LIST, LB_GETCURSEL, 0, 0); + ::SendDlgItemMessage(_hSelf, IDC_REGEXT_LANGEXT_LIST, LB_GETTEXT, index2Add, (LPARAM)ext2Add); + addExt(ext2Add); + ::SendDlgItemMessage(_hSelf, IDC_REGEXT_LANGEXT_LIST, LB_DELETESTRING, index2Add, 0); + } + else + { + ::SendDlgItemMessage(_hSelf, IDC_CUSTOMEXT_EDIT, WM_GETTEXT, extNameMax, (LPARAM)ext2Add); + int i = ::SendDlgItemMessage(_hSelf, IDC_REGEXT_REGISTEREDEXTS_LIST, LB_FINDSTRINGEXACT, 0, (LPARAM)ext2Add); + if (i != LB_ERR) + return TRUE; + addExt(ext2Add); + ::SendDlgItemMessage(_hSelf, IDC_CUSTOMEXT_EDIT, WM_SETTEXT, 0, (LPARAM)TEXT("")); + } + ::SendDlgItemMessage(_hSelf, IDC_REGEXT_REGISTEREDEXTS_LIST, LB_ADDSTRING, 0, (LPARAM)ext2Add); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_ADDFROMLANGEXT_BUTTON), false); + return TRUE; + } + + case IDC_REMOVEEXT_BUTTON : + { + TCHAR ext2Sup[extNameMax] = TEXT(""); + int index2Sup = ::SendDlgItemMessage(_hSelf, IDC_REGEXT_REGISTEREDEXTS_LIST, LB_GETCURSEL, 0, 0); + ::SendDlgItemMessage(_hSelf, IDC_REGEXT_REGISTEREDEXTS_LIST, LB_GETTEXT, index2Sup, (LPARAM)ext2Sup); + if (deleteExts(ext2Sup)) + ::SendDlgItemMessage(_hSelf, IDC_REGEXT_REGISTEREDEXTS_LIST, LB_DELETESTRING, index2Sup, 0); + int langIndex = ::SendDlgItemMessage(_hSelf, IDC_REGEXT_LANG_LIST, LB_GETCURSEL, 0, 0); + + ::EnableWindow(::GetDlgItem(_hSelf, IDC_REMOVEEXT_BUTTON), false); + + if (langIndex != LB_ERR) + { + for (int i = 1 ; i < nbExtMax ; i++) + { + if (!generic_stricmp(ext2Sup, defExtArray[langIndex][i])) + { + ::SendDlgItemMessage(_hSelf, IDC_REGEXT_LANGEXT_LIST, LB_ADDSTRING, 0, (LPARAM)ext2Sup); + return TRUE; + } + } + } + return TRUE; + } + + case IDCANCEL : + ::EndDialog(_hSelf, 0); + return TRUE; + + } + + if (HIWORD(wParam) == EN_CHANGE) + { + TCHAR text[extNameMax] = TEXT(""); + ::SendDlgItemMessage(_hSelf, IDC_CUSTOMEXT_EDIT, WM_GETTEXT, extNameMax, (LPARAM)text); + if ((lstrlen(text) == 1) && (text[0] != '.')) + { + text[1] = text[0]; + text[0] = '.'; + text[2] = '\0'; + ::SendDlgItemMessage(_hSelf, IDC_CUSTOMEXT_EDIT, WM_SETTEXT, 0, (LPARAM)text); + ::SendDlgItemMessage(_hSelf, IDC_CUSTOMEXT_EDIT, EM_SETSEL, 2, 2); + } + ::EnableWindow(::GetDlgItem(_hSelf, IDC_ADDFROMLANGEXT_BUTTON), (lstrlen(text) > 1)); + return TRUE; + } + + if (HIWORD(wParam) == LBN_SELCHANGE) + { + int i = ::SendDlgItemMessage(_hSelf, LOWORD(wParam), LB_GETCURSEL, 0, 0); + if (LOWORD(wParam) == IDC_REGEXT_LANG_LIST) + { + if (i != LB_ERR) + { + TCHAR itemName[32]; + ::SendDlgItemMessage(_hSelf, LOWORD(wParam), LB_GETTEXT, i, (LPARAM)itemName); + + if (!generic_stricmp(defExtArray[nbSupportedLang-1][0], itemName)) + { + ::ShowWindow(::GetDlgItem(_hSelf, IDC_REGEXT_LANGEXT_LIST), SW_HIDE); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_CUSTOMEXT_EDIT), SW_SHOW); + _isCustomize = true; + } + else + { + if (_isCustomize) + { + ::ShowWindow(::GetDlgItem(_hSelf, IDC_REGEXT_LANGEXT_LIST), SW_SHOW); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_CUSTOMEXT_EDIT), SW_HIDE); + + _isCustomize = false; + } + int count = ::SendDlgItemMessage(_hSelf, IDC_REGEXT_LANGEXT_LIST, LB_GETCOUNT, 0, 0); + for (count -= 1 ; count >= 0 ; count--) + ::SendDlgItemMessage(_hSelf, IDC_REGEXT_LANGEXT_LIST, LB_DELETESTRING, count, 0); + + for (int j = 1 ; j < nbExtMax ; j++) + if (lstrcmp(TEXT(""), defExtArray[i][j])) + { + int index = ::SendDlgItemMessage(_hSelf, IDC_REGEXT_REGISTEREDEXTS_LIST, LB_FINDSTRINGEXACT, 0, (LPARAM)defExtArray[i][j]); + if (index == -1) + ::SendDlgItemMessage(_hSelf, IDC_REGEXT_LANGEXT_LIST, LB_ADDSTRING, 0, (LPARAM)defExtArray[i][j]); + } + } + + ::EnableWindow(::GetDlgItem(_hSelf, IDC_ADDFROMLANGEXT_BUTTON), false); + } + } + + else if (LOWORD(wParam) == IDC_REGEXT_LANGEXT_LIST) + { + if (i != LB_ERR) + ::EnableWindow(::GetDlgItem(_hSelf, IDC_ADDFROMLANGEXT_BUTTON), true); + + } + + else if (LOWORD(wParam) == IDC_REGEXT_REGISTEREDEXTS_LIST) + { + if (i != LB_ERR) + ::EnableWindow(::GetDlgItem(_hSelf, IDC_REMOVEEXT_BUTTON), true); + } + } + } + default : + return FALSE; + } + //return FALSE; +} + +void RegExtDlg::getRegisteredExts() +{ + int nbRegisteredKey = getNbSubKey(HKEY_CLASSES_ROOT); + for (int i = 0 ; i < nbRegisteredKey ; i++) + { + TCHAR extName[extNameLen]; + //FILETIME fileTime; + int extNameActualLen = extNameLen; + int res = ::RegEnumKeyEx(HKEY_CLASSES_ROOT, i, extName, (LPDWORD)&extNameActualLen, NULL, NULL, NULL, NULL); + if ((res == ERROR_SUCCESS) && (extName[0] == '.')) + { + //TCHAR valName[extNameLen]; + TCHAR valData[extNameLen]; + int valDataLen = extNameLen * sizeof(TCHAR); + int valType; + HKEY hKey2Check; + extNameActualLen = extNameLen; + ::RegOpenKeyEx(HKEY_CLASSES_ROOT, extName, 0, KEY_ALL_ACCESS, &hKey2Check); + ::RegQueryValueEx(hKey2Check, TEXT(""), NULL, (LPDWORD)&valType, (LPBYTE)valData, (LPDWORD)&valDataLen); + //::RegEnumValue(hKey2Check, 0, valName, (LPDWORD)&extNameActualLen, NULL, (LPDWORD)&valType, (LPBYTE)valData, (LPDWORD)&valDataLen); + if ((valType == REG_SZ) && (!lstrcmp(valData, nppName))) + ::SendDlgItemMessage(_hSelf, IDC_REGEXT_REGISTEREDEXTS_LIST, LB_ADDSTRING, 0, (LPARAM)extName); + ::RegCloseKey(hKey2Check); + } + } +} + +void RegExtDlg::getDefSupportedExts() +{ + for (int i = 0 ; i < nbSupportedLang ; i++) + ::SendDlgItemMessage(_hSelf, IDC_REGEXT_LANG_LIST, LB_ADDSTRING, 0, (LPARAM)defExtArray[i][0]); +} + + +void RegExtDlg::addExt(TCHAR *ext) +{ + HKEY hKey; + DWORD dwDisp; + long nRet; + + nRet = ::RegCreateKeyEx(HKEY_CLASSES_ROOT, + ext, + 0, + NULL, + 0, + KEY_ALL_ACCESS, + NULL, + &hKey, + &dwDisp); + + if (nRet == ERROR_SUCCESS) + { + TCHAR valData[MAX_PATH]; + int valDataLen = MAX_PATH * sizeof(TCHAR); + + if (dwDisp == REG_OPENED_EXISTING_KEY) + { + int res = ::RegQueryValueEx(hKey, TEXT(""), NULL, NULL, (LPBYTE)valData, (LPDWORD)&valDataLen); + if (res == ERROR_SUCCESS) + ::RegSetValueEx(hKey, nppBackup, 0, REG_SZ, (LPBYTE)valData, valDataLen); + } + ::RegSetValueEx(hKey, NULL, 0, REG_SZ, (LPBYTE)nppName, (lstrlen(nppName)+1)*sizeof(TCHAR)); + + ::RegCloseKey(hKey); + } +} + +bool RegExtDlg::deleteExts(const TCHAR *ext2Delete) +{ + HKEY hKey; + ::RegOpenKeyEx(HKEY_CLASSES_ROOT, ext2Delete, 0, KEY_ALL_ACCESS, &hKey); + + int nbValue = getNbSubValue(hKey); + int nbSubkey = getNbSubKey(hKey); + + if ((nbValue <= 1) && (!nbSubkey)) + { + TCHAR subKey[32] = TEXT("\\"); + lstrcat(subKey, ext2Delete); + ::RegDeleteKey(HKEY_CLASSES_ROOT, subKey); + } + else + { + TCHAR valData[extNameLen]; + int valDataLen = extNameLen*sizeof(TCHAR); + int valType; + int res = ::RegQueryValueEx(hKey, nppBackup, NULL, (LPDWORD)&valType, (LPBYTE)valData, (LPDWORD)&valDataLen); + + if (res == ERROR_SUCCESS) + { + ::RegSetValueEx(hKey, NULL, 0, valType, (LPBYTE)valData, valDataLen); + ::RegDeleteValue(hKey, nppBackup); + } + else + ::RegDeleteValue(hKey, NULL); + } + + return true; +} + +void RegExtDlg::writeNppPath() +{ + HKEY hKey, hRootKey; + DWORD dwDisp; + long nRet; + TCHAR regStr[MAX_PATH] = TEXT(""); + lstrcat(lstrcat(regStr, nppName), TEXT("\\shell\\open\\command")); + + nRet = ::RegCreateKeyEx( + HKEY_CLASSES_ROOT, + regStr, + 0, + NULL, + 0, + KEY_ALL_ACCESS, + NULL, + &hKey, + &dwDisp); + + + if (nRet == ERROR_SUCCESS) + { + //if (dwDisp == REG_CREATED_NEW_KEY) + { + // Write the value for new document + ::RegOpenKeyEx(HKEY_CLASSES_ROOT, nppName, 0, KEY_ALL_ACCESS, &hRootKey); + ::RegSetValueEx(hRootKey, NULL, 0, REG_SZ, (LPBYTE)nppDoc, (lstrlen(nppDoc)+1)*sizeof(TCHAR)); + RegCloseKey(hRootKey); + + TCHAR nppPath[MAX_PATH]; + ::GetModuleFileName(_hInst, nppPath, MAX_PATH); + + TCHAR nppPathParam[256] = TEXT("\""); + lstrcat(lstrcat(nppPathParam, nppPath), TEXT("\" \"%1\"")); + + ::RegSetValueEx(hKey, NULL, 0, REG_SZ, (LPBYTE)nppPathParam, (lstrlen(nppPathParam)+1)*sizeof(TCHAR)); + } + RegCloseKey(hKey); + } + + //Set default icon value + lstrcpy(regStr, nppName); + lstrcat(regStr, TEXT("\\DefaultIcon")); + nRet = ::RegCreateKeyEx( + HKEY_CLASSES_ROOT, + regStr, + 0, + NULL, + 0, + KEY_ALL_ACCESS, + NULL, + &hKey, + &dwDisp); + + if (nRet == ERROR_SUCCESS) + { + //if (dwDisp == REG_CREATED_NEW_KEY) + { + TCHAR nppPath[MAX_PATH]; + ::GetModuleFileName(_hInst, nppPath, MAX_PATH); + + TCHAR nppPathParam[256] = TEXT("\""); + lstrcat(lstrcat(nppPathParam, nppPath), TEXT("\",0")); + + ::RegSetValueEx(hKey, NULL, 0, REG_SZ, (LPBYTE)nppPathParam, (lstrlen(nppPathParam)+1)*sizeof(TCHAR)); + } + RegCloseKey(hKey); + } +} diff --git a/PowerEditor/src/MISC/RegExt/regExtDlg.h b/PowerEditor/src/MISC/RegExt/regExtDlg.h new file mode 100644 index 00000000..11bc30db --- /dev/null +++ b/PowerEditor/src/MISC/RegExt/regExtDlg.h @@ -0,0 +1,60 @@ +/* +this file is part of notepad++ +Copyright (C)2003 Don HO ( donho@altern.org ) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef REG_EXT_DLG_H +#define REG_EXT_DLG_H + +#include "StaticDialog.h" +#include "regExtDlgRc.h" + +const int extNameLen = 32; + +class RegExtDlg : public StaticDialog +{ +public : + RegExtDlg() : _isCustomize(false){}; + ~RegExtDlg(){}; + void doDialog(bool isRTL = false); + + +private : + bool _isCustomize; + + BOOL CALLBACK run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam); + + void getRegisteredExts(); + void getDefSupportedExts(); + void addExt(TCHAR *ext); + bool deleteExts(const TCHAR *ext2Delete); + void writeNppPath(); + + int getNbSubKey(HKEY hKey) const { + int nbSubKey; + long result = ::RegQueryInfoKey(hKey, NULL, NULL, NULL, (LPDWORD)&nbSubKey, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + return (result == ERROR_SUCCESS)?nbSubKey:0; + }; + + int getNbSubValue(HKEY hKey) const { + int nbSubValue; + long result = ::RegQueryInfoKey(hKey, NULL, NULL, NULL, NULL, NULL, NULL, (LPDWORD)&nbSubValue, NULL, NULL, NULL, NULL); + return (result == ERROR_SUCCESS)?nbSubValue:0; + }; +}; + +#endif //REG_EXT_DLG_H diff --git a/PowerEditor/src/MISC/RegExt/regExtDlg.rc b/PowerEditor/src/MISC/RegExt/regExtDlg.rc new file mode 100644 index 00000000..fc3b653e --- /dev/null +++ b/PowerEditor/src/MISC/RegExt/regExtDlg.rc @@ -0,0 +1,39 @@ +/* +this file is part of notepad++ +Copyright (C)2003 Don HO ( donho@altern.org ) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include +#include "regExtDlgRc.h" + + +IDD_REGEXT_BOX DIALOGEX 0, 0, 370, 180 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD +FONT 8, TEXT("MS Shell Dlg"), 0, 0, 0x1 +BEGIN + LISTBOX IDC_REGEXT_LANGEXT_LIST,141,31,29,122,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_HSCROLL | WS_TABSTOP + LISTBOX IDC_REGEXT_REGISTEREDEXTS_LIST,211,30,48,123,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP + PUSHBUTTON "->",IDC_ADDFROMLANGEXT_BUTTON,178,87,26,14 + EDITTEXT IDC_CUSTOMEXT_EDIT,141,87,30,14,ES_AUTOHSCROLL | NOT WS_VISIBLE + PUSHBUTTON "->",IDC_REMOVEEXT_BUTTON,266,86,26,14 + CONTROL "",IDC_POUPELLE_STATIC,"Static",SS_OWNERDRAW,301,82,20,20 + LTEXT "Supported exts :",IDC_SUPPORTEDEXTS_STATIC,73,18,77,8 + LTEXT "Registered exts :",IDC_REGISTEREDEXTS_STATIC,212,18,72,8 + LISTBOX IDC_REGEXT_LANG_LIST,73,31,63,122,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_HSCROLL | WS_TABSTOP +END + + diff --git a/PowerEditor/src/MISC/RegExt/regExtDlgRc.h b/PowerEditor/src/MISC/RegExt/regExtDlgRc.h new file mode 100644 index 00000000..acc9189e --- /dev/null +++ b/PowerEditor/src/MISC/RegExt/regExtDlgRc.h @@ -0,0 +1,35 @@ +/* +this file is part of notepad++ +Copyright (C)2003 Don HO ( donho@altern.org ) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ +#ifndef REGEXTDLGRC_H +#define REGEXTDLGRC_H + +#define IDD_REGEXT_BOX 4000 + + #define IDC_REGEXT_LANG_LIST (IDD_REGEXT_BOX + 1) + #define IDC_REGEXT_LANGEXT_LIST (IDD_REGEXT_BOX + 2) + #define IDC_REGEXT_REGISTEREDEXTS_LIST (IDD_REGEXT_BOX + 3) + #define IDC_ADDFROMLANGEXT_BUTTON (IDD_REGEXT_BOX + 4) + #define IDI_POUPELLE_ICON (IDD_REGEXT_BOX + 5) + #define IDC_CUSTOMEXT_EDIT (IDD_REGEXT_BOX + 6) + #define IDC_REMOVEEXT_BUTTON (IDD_REGEXT_BOX + 7) + #define IDC_POUPELLE_STATIC (IDD_REGEXT_BOX + 8) + #define IDC_SUPPORTEDEXTS_STATIC (IDD_REGEXT_BOX + 9) + #define IDC_REGISTEREDEXTS_STATIC (IDD_REGEXT_BOX + 10) + +#endif //REGEXTDLGRC_H diff --git a/PowerEditor/src/MISC/crc16/Crc16.h b/PowerEditor/src/MISC/crc16/Crc16.h new file mode 100644 index 00000000..be71e239 --- /dev/null +++ b/PowerEditor/src/MISC/crc16/Crc16.h @@ -0,0 +1,112 @@ + +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +#ifndef _CRC16_H_ +#define _CRC16_H_ +#include + +class CRC16_ISO_3309 +{ +public : + CRC16_ISO_3309(unsigned short polynom = 0x1021, unsigned short initVal = 0xFFFF) + :_polynom(polynom), _initVal(initVal) {}; + ~CRC16_ISO_3309(){}; + + void set(unsigned short polynom, unsigned short initVal) { + _polynom = polynom; + _initVal = initVal; + }; + + unsigned short calculate(unsigned char *data, unsigned short count) + { + unsigned short fcs = _initVal; + unsigned short d, i, k; + for (i=0; i(data[i]); + + // calculate CRC : by default polynom = 0x1021, init val = 0xFFFF) + unsigned short wordResult = CRC16_ISO_3309::calculate(pBuffer, count); + + // Reverse the WORD bits + wordResult = reverseByte(wordResult); + + // XOR FFFF + wordResult ^= 0xFFFF; + + // Invert MSB/LSB + wordResult = wordResult << 8 | wordResult >> 8 ; + + delete [] pBuffer; + + return wordResult; + }; + +private: + template + IntType reverseByte(IntType val2Reverses) + { + IntType reversedValue = 0; + long mask = 1; + int nBits = sizeof(val2Reverses) * 8; + for (int i = 0 ; i < nBits ; i++) + if ((mask << i) & val2Reverses) + reversedValue += (mask << (nBits - 1 - i)); + + return reversedValue; + }; +}; + +#endif \ No newline at end of file diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp new file mode 100644 index 00000000..85631312 --- /dev/null +++ b/PowerEditor/src/Notepad_plus.cpp @@ -0,0 +1,9885 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#ifndef _WIN32_IE +#define _WIN32_IE 0x500 +#endif + +//#define INCLUDE_DEPRECATED_FEATURES 1 + +#include +//#include "dbghelp.h" + +#include "Notepad_plus.h" +#include "FileDialog.h" +#include "resource.h" +#include "printer.h" +#include "FileNameStringSplitter.h" +#include "lesDlgs.h" +#include "Utf8_16.h" +#include "regExtDlg.h" +#include "RunDlg.h" +#include "ShortcutMapper.h" +#include "preferenceDlg.h" +#include "TaskListDlg.h" +#include +#include "xmlMatchedTagsHighlighter.h" + +const TCHAR Notepad_plus::_className[32] = TEXT("Notepad++"); +HWND Notepad_plus::gNppHWND = NULL; +const char *urlHttpRegExpr = "http://[a-z0-9_\\-\\+.:?&@=/%#]*"; + +int docTabIconIDs[] = {IDI_SAVED_ICON, IDI_UNSAVED_ICON, IDI_READONLY_ICON}; +enum tb_stat {tb_saved, tb_unsaved, tb_ro}; + +#define DIR_LEFT true +#define DIR_RIGHT false + +struct SortTaskListPred +{ + DocTabView *_views[2]; + + SortTaskListPred(DocTabView &p, DocTabView &s) + { + _views[MAIN_VIEW] = &p; + _views[SUB_VIEW] = &s; + } + + bool operator()(const TaskLstFnStatus &l, const TaskLstFnStatus &r) const { + BufferID lID = _views[l._iView]->getBufferByIndex(l._docIndex); + BufferID rID = _views[r._iView]->getBufferByIndex(r._docIndex); + Buffer * bufL = MainFileManager->getBufferByID(lID); + Buffer * bufR = MainFileManager->getBufferByID(rID); + return bufL->getRecentTag() > bufR->getRecentTag(); + } +}; + +Notepad_plus::Notepad_plus(): Window(), _mainWindowStatus(0), _pDocTab(NULL), _pEditView(NULL), + _pMainSplitter(NULL), + _recordingMacro(false), _pTrayIco(NULL), _isUDDocked(false), _isRTL(false), + _linkTriggered(true), _isDocModifing(false), _isHotspotDblClicked(false), _sysMenuEntering(false), + _autoCompleteMain(&_mainEditView), _autoCompleteSub(&_subEditView), _smartHighlighter(&_findReplaceDlg), + _nativeLangEncoding(CP_ACP), _isFileOpening(false) +{ + + ZeroMemory(&_prevSelectedRange, sizeof(_prevSelectedRange)); + _winVersion = (NppParameters::getInstance())->getWinVersion(); + + TiXmlDocumentA *nativeLangDocRootA = (NppParameters::getInstance())->getNativeLangA(); + + if (nativeLangDocRootA) + { + + _nativeLangA = nativeLangDocRootA->FirstChild("NotepadPlus"); + if (_nativeLangA) + { + _nativeLangA = _nativeLangA->FirstChild("Native-Langue"); + if (_nativeLangA) + { + TiXmlElementA *element = _nativeLangA->ToElement(); + const char *rtl = element->Attribute("RTL"); + if (rtl) + _isRTL = (strcmp(rtl, "yes") == 0); + + // get encoding + TiXmlDeclarationA *declaration = _nativeLangA->GetDocument()->FirstChild()->ToDeclaration(); + if (declaration) + { + const char * encodingStr = declaration->Encoding(); + _nativeLangEncoding = getCpFromStringValue(encodingStr); + } + } + } + } + else + _nativeLangA = NULL; + + TiXmlDocument *toolIconsDocRoot = (NppParameters::getInstance())->getToolIcons(); + if (toolIconsDocRoot) + { + _toolIcons = toolIconsDocRoot->FirstChild(TEXT("NotepadPlus")); + if (_toolIcons) + { + if ((_toolIcons = _toolIcons->FirstChild(TEXT("ToolBarIcons")))) + { + if ((_toolIcons = _toolIcons->FirstChild(TEXT("Theme")))) + { + const TCHAR *themeDir = (_toolIcons->ToElement())->Attribute(TEXT("pathPrefix")); + + for (TiXmlNode *childNode = _toolIcons->FirstChildElement(TEXT("Icon")); + childNode ; + childNode = childNode->NextSibling(TEXT("Icon"))) + { + int iIcon; + const TCHAR *res = (childNode->ToElement())->Attribute(TEXT("id"), &iIcon); + if (res) + { + TiXmlNode *grandChildNode = childNode->FirstChildElement(TEXT("normal")); + if (grandChildNode) + { + TiXmlNode *valueNode = grandChildNode->FirstChild(); + //putain, enfin!!! + if (valueNode) + { + generic_string locator = themeDir?themeDir:TEXT(""); + + locator += valueNode->Value(); + _customIconVect.push_back(iconLocator(0, iIcon, locator)); + } + } + + grandChildNode = childNode->FirstChildElement(TEXT("hover")); + if (grandChildNode) + { + TiXmlNode *valueNode = grandChildNode->FirstChild(); + //putain, enfin!!! + if (valueNode) + { + generic_string locator = themeDir?themeDir:TEXT(""); + + locator += valueNode->Value(); + _customIconVect.push_back(iconLocator(1, iIcon, locator)); + } + } + + grandChildNode = childNode->FirstChildElement(TEXT("disabled")); + if (grandChildNode) + { + TiXmlNode *valueNode = grandChildNode->FirstChild(); + //putain, enfin!!! + if (valueNode) + { + generic_string locator = themeDir?themeDir:TEXT(""); + + locator += valueNode->Value(); + _customIconVect.push_back(iconLocator(2, iIcon, locator)); + } + } + } + } + } + } + } + } + else + _toolIcons = NULL; +} + +// ATTENTION : the order of the destruction is very important +// because if the parent's window hadle is destroyed before +// the destruction of its childrens' windows handle, +// its childrens' windows handle will be destroyed automatically! +Notepad_plus::~Notepad_plus() +{ + (NppParameters::getInstance())->destroyInstance(); + MainFileManager->destroyInstance(); + (WcharMbcsConvertor::getInstance())->destroyInstance(); + if (_pTrayIco) + delete _pTrayIco; +} + +void Notepad_plus::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLine, CmdLineParams *cmdLineParams) +{ + Window::init(hInst, parent); + WNDCLASS nppClass; + + nppClass.style = CS_BYTEALIGNWINDOW | CS_DBLCLKS; + nppClass.lpfnWndProc = Notepad_plus_Proc; + nppClass.cbClsExtra = 0; + nppClass.cbWndExtra = 0; + nppClass.hInstance = _hInst; + nppClass.hIcon = ::LoadIcon(_hInst, MAKEINTRESOURCE(IDI_M30ICON)); + nppClass.hCursor = ::LoadCursor(NULL, IDC_ARROW); + nppClass.hbrBackground = ::CreateSolidBrush(::GetSysColor(COLOR_MENU)); + nppClass.lpszMenuName = MAKEINTRESOURCE(IDR_M30_MENU); + nppClass.lpszClassName = _className; + + if (!::RegisterClass(&nppClass)) + { + systemMessage(TEXT("System Err")); + throw int(98); + } + + RECT workAreaRect; + ::SystemParametersInfo(SPI_GETWORKAREA, 0, &workAreaRect, 0); + + NppParameters *pNppParams = NppParameters::getInstance(); + const NppGUI & nppGUI = pNppParams->getNppGUI(); + + if (cmdLineParams->_isNoPlugin) + _pluginsManager.disable(); + + _hSelf = ::CreateWindowEx( + WS_EX_ACCEPTFILES | (_isRTL?WS_EX_LAYOUTRTL:0),\ + _className,\ + TEXT("Notepad++"),\ + WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,\ + // CreateWindowEx bug : set all 0 to walk arround the pb + 0, 0, 0, 0,\ + _hParent,\ + NULL,\ + _hInst,\ + (LPVOID)this); // pass the ptr of this instantiated object + // for retrive it in Notepad_plus_Proc from + // the CREATESTRUCT.lpCreateParams afterward. + + if (!_hSelf) + { + systemMessage(TEXT("System Err")); + throw int(777); + } + + gNppHWND = _hSelf; + + // In setting the startup window position, take into account that the last-saved + // position might have assumed a second monitor that's no longer available. + POINT newUpperLeft; + newUpperLeft.x = nppGUI._appPos.left + workAreaRect.left; + newUpperLeft.y = nppGUI._appPos.top + workAreaRect.top; + + // GetSystemMetrics does not support the multi-monitor values on Windows NT and Windows 95. + if ((_winVersion != WV_95) && (_winVersion != WV_NT)) + { + int margin = ::GetSystemMetrics(SM_CYSMCAPTION); + if (newUpperLeft.x > ::GetSystemMetrics(SM_CXVIRTUALSCREEN)-margin) + newUpperLeft.x = workAreaRect.right - nppGUI._appPos.right; + if (newUpperLeft.x + nppGUI._appPos.right < ::GetSystemMetrics(SM_XVIRTUALSCREEN)+margin) + newUpperLeft.x = workAreaRect.left; + if (newUpperLeft.y > ::GetSystemMetrics(SM_CYVIRTUALSCREEN)-margin) + newUpperLeft.y = workAreaRect.bottom - nppGUI._appPos.bottom; + if (newUpperLeft.y + nppGUI._appPos.bottom < ::GetSystemMetrics(SM_YVIRTUALSCREEN)+margin) + newUpperLeft.y = workAreaRect.top; + } + if (cmdLineParams->isPointValid()) + ::MoveWindow(_hSelf, cmdLineParams->_point.x, cmdLineParams->_point.y, nppGUI._appPos.right, nppGUI._appPos.bottom, TRUE); + else + ::MoveWindow(_hSelf, newUpperLeft.x, newUpperLeft.y, nppGUI._appPos.right, nppGUI._appPos.bottom, TRUE); + + ::GetModuleFileName(NULL, _nppPath, MAX_PATH); + + if (nppGUI._tabStatus & TAB_MULTILINE) + ::SendMessage(_hSelf, WM_COMMAND, IDM_VIEW_DRAWTABBAR_MULTILINE, 0); + + if (!nppGUI._menuBarShow) + ::SetMenu(_hSelf, NULL); + + if (cmdLineParams->_isNoTab || (nppGUI._tabStatus & TAB_HIDE)) + { + ::SendMessage(_hSelf, NPPM_HIDETABBAR, 0, TRUE); + } + + if (nppGUI._rememberLastSession && !cmdLineParams->_isNoSession) + { + loadLastSession(); + } + + if (cmdLineParams->isPointValid()) + ::ShowWindow(_hSelf, SW_SHOW); + else + ::ShowWindow(_hSelf, nppGUI._isMaximized?SW_MAXIMIZE:SW_SHOW); + + if (cmdLine) + { + loadCommandlineParams(cmdLine, cmdLineParams); + } + + vector fileNames; + vector patterns; + patterns.push_back(TEXT("*.xml")); + + TCHAR tmp[MAX_PATH]; + lstrcpy(tmp, _nppPath); + ::PathRemoveFileSpec(tmp); + +#ifdef UNICODE + LocalizationSwitcher & localizationSwitcher = pNppParams->getLocalizationSwitcher(); + wstring localizationDir = tmp; + + localizationDir += TEXT("\\localization\\"); + getMatchedFileNames(localizationDir.c_str(), patterns, fileNames, false, false); + for (size_t i = 0 ; i < fileNames.size() ; i++) + { + localizationSwitcher.addLanguageFromXml(fileNames[i].c_str()); + } +#endif + + fileNames.clear(); + ThemeSwitcher & themeSwitcher = pNppParams->getThemeSwitcher(); + + // Get themes from both npp install themes dir and app data themes dir with the per user + // overriding default themes of the same name. + generic_string themeDir(pNppParams->getAppDataNppDir()); + themeDir.append(TEXT("\\themes\\")); + + getMatchedFileNames(themeDir.c_str(), patterns, fileNames, false, false); + for (size_t i = 0 ; i < fileNames.size() ; i++) + { + themeSwitcher.addThemeFromXml(fileNames[i].c_str()); + } + + fileNames.clear(); + themeDir.clear(); + themeDir.assign(tmp); + themeDir.append(TEXT("\\themes\\")); + getMatchedFileNames(themeDir.c_str(), patterns, fileNames, false, false); + for (size_t i = 0 ; i < fileNames.size() ; i++) + { + generic_string themeName( themeSwitcher.getThemeFromXmlFileName(fileNames[i].c_str()) ); + if (! themeSwitcher.themeNameExists(themeName.c_str()) ) + { + themeSwitcher.addThemeFromXml(fileNames[i].c_str()); + } + } + + // Notify plugins that Notepad++ is ready + SCNotification scnN; + scnN.nmhdr.code = NPPN_READY; + scnN.nmhdr.hwndFrom = _hSelf; + scnN.nmhdr.idFrom = 0; + _pluginsManager.notify(&scnN); +} + + + +void Notepad_plus::killAllChildren() +{ + _toolBar.destroy(); + _rebarTop.destroy(); + _rebarBottom.destroy(); + + if (_pMainSplitter) + { + _pMainSplitter->destroy(); + delete _pMainSplitter; + } + + _mainDocTab.destroy(); + _subDocTab.destroy(); + + _mainEditView.destroy(); + _subEditView.destroy(); + _invisibleEditView.destroy(); + + _subSplitter.destroy(); + _statusBar.destroy(); + + _scintillaCtrls4Plugins.destroy(); + _dockingManager.destroy(); +} + + +void Notepad_plus::destroy() +{ + ::DestroyWindow(_hSelf); +} + +bool Notepad_plus::saveGUIParams() +{ + NppGUI & nppGUI = (NppGUI &)(NppParameters::getInstance())->getNppGUI(); + nppGUI._statusBarShow = _statusBar.isVisible(); + nppGUI._toolbarShow = _rebarTop.getIDVisible(REBAR_BAR_TOOLBAR); + nppGUI._toolBarStatus = _toolBar.getState(); + + nppGUI._tabStatus = (TabBarPlus::doDragNDropOrNot()?TAB_DRAWTOPBAR:0) | \ + (TabBarPlus::drawTopBar()?TAB_DRAGNDROP:0) | \ + (TabBarPlus::drawInactiveTab()?TAB_DRAWINACTIVETAB:0) | \ + (_toReduceTabBar?TAB_REDUCE:0) | \ + (TabBarPlus::drawTabCloseButton()?TAB_CLOSEBUTTON:0) | \ + (TabBarPlus::isDbClk2Close()?TAB_DBCLK2CLOSE:0) | \ + (TabBarPlus::isVertical() ? TAB_VERTICAL:0) | \ + (TabBarPlus::isMultiLine() ? TAB_MULTILINE:0) |\ + (nppGUI._tabStatus & TAB_HIDE); + nppGUI._splitterPos = _subSplitter.isVertical()?POS_VERTICAL:POS_HORIZOTAL; + UserDefineDialog *udd = _pEditView->getUserDefineDlg(); + bool b = udd->isDocked(); + nppGUI._userDefineDlgStatus = (b?UDD_DOCKED:0) | (udd->isVisible()?UDD_SHOW:0); + + // Save the position + + WINDOWPLACEMENT posInfo; + + posInfo.length = sizeof(WINDOWPLACEMENT); + ::GetWindowPlacement(_hSelf, &posInfo); + + nppGUI._appPos.left = posInfo.rcNormalPosition.left; + nppGUI._appPos.top = posInfo.rcNormalPosition.top; + nppGUI._appPos.right = posInfo.rcNormalPosition.right - posInfo.rcNormalPosition.left; + nppGUI._appPos.bottom = posInfo.rcNormalPosition.bottom - posInfo.rcNormalPosition.top; + nppGUI._isMaximized = (IsZoomed(_hSelf) || (posInfo.flags & WPF_RESTORETOMAXIMIZED)); + + saveDockingParams(); + + return (NppParameters::getInstance())->writeGUIParams(); +} + +void Notepad_plus::saveDockingParams() +{ + NppGUI & nppGUI = (NppGUI &)(NppParameters::getInstance())->getNppGUI(); + + // Save the docking information + nppGUI._dockingData._leftWidth = _dockingManager.getDockedContSize(CONT_LEFT); + nppGUI._dockingData._rightWidth = _dockingManager.getDockedContSize(CONT_RIGHT); + nppGUI._dockingData._topHeight = _dockingManager.getDockedContSize(CONT_TOP); + nppGUI._dockingData._bottomHight = _dockingManager.getDockedContSize(CONT_BOTTOM); + + // clear the conatainer tab information (active tab) + nppGUI._dockingData._containerTabInfo.clear(); + + // create a vector to save the current information + vector vPluginDockInfo; + vector vFloatingWindowInfo; + + // save every container + vector vCont = _dockingManager.getContainerInfo(); + + for (size_t i = 0 ; i < vCont.size() ; i++) + { + // save at first the visible Tb's + vector vDataVis = vCont[i]->getDataOfVisTb(); + + for (size_t j = 0 ; j < vDataVis.size() ; j++) + { + if (vDataVis[j]->pszName && vDataVis[j]->pszName[0]) + { + PlugingDlgDockingInfo pddi(vDataVis[j]->pszModuleName, vDataVis[j]->dlgID, i, vDataVis[j]->iPrevCont, true); + vPluginDockInfo.push_back(pddi); + } + } + + // save the hidden Tb's + vector vDataAll = vCont[i]->getDataOfAllTb(); + + for (size_t j = 0 ; j < vDataAll.size() ; j++) + { + if ((vDataAll[j]->pszName && vDataAll[j]->pszName[0]) && (!vCont[i]->isTbVis(vDataAll[j]))) + { + PlugingDlgDockingInfo pddi(vDataAll[j]->pszModuleName, vDataAll[j]->dlgID, i, vDataAll[j]->iPrevCont, false); + vPluginDockInfo.push_back(pddi); + } + } + + // save the position, when container is a floated one + if (i >= DOCKCONT_MAX) + { + RECT rc; + vCont[i]->getWindowRect(rc); + FloatingWindowInfo fwi(i, rc.left, rc.top, rc.right, rc.bottom); + vFloatingWindowInfo.push_back(fwi); + } + + // save the active tab + ContainerTabInfo act(i, vCont[i]->getActiveTb()); + nppGUI._dockingData._containerTabInfo.push_back(act); + } + + // add the missing information and store it in nppGUI + UCHAR floatContArray[50]; + memset(floatContArray, 0, 50); + + for (size_t i = 0 ; i < nppGUI._dockingData._pluginDockInfo.size() ; i++) + { + BOOL isStored = FALSE; + for (size_t j = 0; j < vPluginDockInfo.size(); j++) + { + if (nppGUI._dockingData._pluginDockInfo[i] == vPluginDockInfo[j]) + { + isStored = TRUE; + break; + } + } + + if (isStored == FALSE) + { + int floatCont = 0; + + if (nppGUI._dockingData._pluginDockInfo[i]._currContainer >= DOCKCONT_MAX) + floatCont = nppGUI._dockingData._pluginDockInfo[i]._currContainer; + else + floatCont = nppGUI._dockingData._pluginDockInfo[i]._prevContainer; + + if (floatContArray[floatCont] == 0) + { + RECT *pRc = nppGUI._dockingData.getFloatingRCFrom(floatCont); + if (pRc) + vFloatingWindowInfo.push_back(FloatingWindowInfo(floatCont, pRc->left, pRc->top, pRc->right, pRc->bottom)); + floatContArray[floatCont] = 1; + } + + vPluginDockInfo.push_back(nppGUI._dockingData._pluginDockInfo[i]); + } + } + + nppGUI._dockingData._pluginDockInfo = vPluginDockInfo; + nppGUI._dockingData._flaotingWindowInfo = vFloatingWindowInfo; +} + +// return true if all the session files are loaded +// return false if one or more sessions files fail to load (and session is modify to remove invalid files) +bool Notepad_plus::loadSession(Session & session) +{ + bool allSessionFilesLoaded = true; + BufferID lastOpened = BUFFER_INVALID; + size_t i = 0; + showView(MAIN_VIEW); + switchEditViewTo(MAIN_VIEW); //open files in main + for ( ; i < session.nbMainFiles() ; ) + { + const TCHAR *pFn = session._mainViewFiles[i]._fileName.c_str(); + if (isFileSession(pFn)) { + vector::iterator posIt = session._mainViewFiles.begin() + i; + session._mainViewFiles.erase(posIt); + continue; //skip session files, not supporting recursive sessions + } + if (PathFileExists(pFn)) { + lastOpened = doOpen(pFn); + } else { + lastOpened = BUFFER_INVALID; + } + if (lastOpened != BUFFER_INVALID) + { + showView(MAIN_VIEW); + const TCHAR *pLn = session._mainViewFiles[i]._langName.c_str(); + int id = getLangFromMenuName(pLn); + LangType typeToSet = L_TXT; + if (id != 0 && lstrcmp(pLn, TEXT("User Defined")) != 0) + typeToSet = menuID2LangType(id); + if (typeToSet == L_EXTERNAL ) + typeToSet = (LangType)(id - IDM_LANG_EXTERNAL + L_EXTERNAL); + + Buffer * buf = MainFileManager->getBufferByID(lastOpened); + buf->setPosition(session._mainViewFiles[i], &_mainEditView); + buf->setLangType(typeToSet, pLn); + + //Force in the document so we can add the markers + //Dont use default methods because of performance + Document prevDoc = _mainEditView.execute(SCI_GETDOCPOINTER); + _mainEditView.execute(SCI_SETDOCPOINTER, 0, buf->getDocument()); + for (size_t j = 0 ; j < session._mainViewFiles[i].marks.size() ; j++) + { + _mainEditView.execute(SCI_MARKERADD, session._mainViewFiles[i].marks[j], MARK_BOOKMARK); + } + _mainEditView.execute(SCI_SETDOCPOINTER, 0, prevDoc); + i++; + } + else + { + vector::iterator posIt = session._mainViewFiles.begin() + i; + session._mainViewFiles.erase(posIt); + allSessionFilesLoaded = false; + } + } + + size_t k = 0; + showView(SUB_VIEW); + switchEditViewTo(SUB_VIEW); //open files in sub + for ( ; k < session.nbSubFiles() ; ) + { + const TCHAR *pFn = session._subViewFiles[k]._fileName.c_str(); + if (isFileSession(pFn)) { + vector::iterator posIt = session._subViewFiles.begin() + k; + session._subViewFiles.erase(posIt); + continue; //skip session files, not supporting recursive sessions + } + if (PathFileExists(pFn)) { + lastOpened = doOpen(pFn); + //check if already open in main. If so, clone + if (_mainDocTab.getIndexByBuffer(lastOpened) != -1) { + loadBufferIntoView(lastOpened, SUB_VIEW); + } + } else { + lastOpened = BUFFER_INVALID; + } + if (lastOpened != BUFFER_INVALID) + { + showView(SUB_VIEW); + if (canHideView(MAIN_VIEW)) + hideView(MAIN_VIEW); + const TCHAR *pLn = session._subViewFiles[k]._langName.c_str(); + int id = getLangFromMenuName(pLn); + LangType typeToSet = L_TXT; + if (id != 0) + typeToSet = menuID2LangType(id); + if (typeToSet == L_EXTERNAL ) + typeToSet = (LangType)(id - IDM_LANG_EXTERNAL + L_EXTERNAL); + + Buffer * buf = MainFileManager->getBufferByID(lastOpened); + buf->setPosition(session._subViewFiles[k], &_subEditView); + if (typeToSet == L_USER) { + if (!lstrcmp(pLn, TEXT("User Defined"))) { + pLn = TEXT(""); //default user defined + } + } + buf->setLangType(typeToSet, pLn); + + //Force in the document so we can add the markers + //Dont use default methods because of performance + Document prevDoc = _subEditView.execute(SCI_GETDOCPOINTER); + _subEditView.execute(SCI_SETDOCPOINTER, 0, buf->getDocument()); + for (size_t j = 0 ; j < session._subViewFiles[k].marks.size() ; j++) + { + _subEditView.execute(SCI_MARKERADD, session._subViewFiles[k].marks[j], MARK_BOOKMARK); + } + _subEditView.execute(SCI_SETDOCPOINTER, 0, prevDoc); + + k++; + } + else + { + vector::iterator posIt = session._subViewFiles.begin() + k; + session._subViewFiles.erase(posIt); + allSessionFilesLoaded = false; + } + } + + _mainEditView.restoreCurrentPos(); + _subEditView.restoreCurrentPos(); + + if (session._activeMainIndex < (size_t)_mainDocTab.nbItem())//session.nbMainFiles()) + activateBuffer(_mainDocTab.getBufferByIndex(session._activeMainIndex), MAIN_VIEW); + + if (session._activeSubIndex < (size_t)_subDocTab.nbItem())//session.nbSubFiles()) + activateBuffer(_subDocTab.getBufferByIndex(session._activeSubIndex), SUB_VIEW); + + if ((session.nbSubFiles() > 0) && (session._activeView == MAIN_VIEW || session._activeView == SUB_VIEW)) + switchEditViewTo(session._activeView); + else + switchEditViewTo(MAIN_VIEW); + + if (canHideView(otherView())) + hideView(otherView()); + else if (canHideView(currentView())) + hideView(currentView()); + return allSessionFilesLoaded; +} + +BufferID Notepad_plus::doOpen(const TCHAR *fileName, bool isReadOnly) +{ + TCHAR longFileName[MAX_PATH]; + + ::GetFullPathName(fileName, MAX_PATH, longFileName, NULL); + ::GetLongPathName(longFileName, longFileName, MAX_PATH); + + _lastRecentFileList.remove(longFileName); + + const TCHAR * fileName2Find; + generic_string gs_fileName = fileName; + size_t res = gs_fileName.find_first_of(UNTITLED_STR); + + if (res != string::npos && res == 0) + { + fileName2Find = fileName; + } + else + { + fileName2Find = longFileName; + } + + BufferID test = MainFileManager->getBufferFromName(fileName2Find); + if (test != BUFFER_INVALID) + { + //switchToFile(test); + //Dont switch, not responsibility of doOpen, but of caller + if (_pTrayIco) + { + if (_pTrayIco->isInTray()) + { + ::ShowWindow(_hSelf, SW_SHOW); + _pTrayIco->doTrayIcon(REMOVE); + ::SendMessage(_hSelf, WM_SIZE, 0, 0); + } + } + return test; + } + + if (isFileSession(longFileName) && PathFileExists(longFileName)) + { + fileLoadSession(longFileName); + return BUFFER_INVALID; + } + + + + if (!PathFileExists(longFileName)) + { + TCHAR str2display[MAX_PATH*2]; + TCHAR longFileDir[MAX_PATH]; + + lstrcpy(longFileDir, longFileName); + PathRemoveFileSpec(longFileDir); + + if (PathFileExists(longFileDir)) + { + wsprintf(str2display, TEXT("%s doesn't exist. Create it?"), longFileName); + + if (::MessageBox(_hSelf, str2display, TEXT("Create new file"), MB_YESNO) == IDYES) + { + bool res = MainFileManager->createEmptyFile(longFileName); + if (!res) + { + wsprintf(str2display, TEXT("Cannot create the file \"%s\""), longFileName); + ::MessageBox(_hSelf, str2display, TEXT("Create new file"), MB_OK); + return BUFFER_INVALID; + } + } + else + { + return BUFFER_INVALID; + } + } + else + { + return BUFFER_INVALID; + } + } + + // Notify plugins that current file is about to load + // Plugins can should use this notification to filter SCN_MODIFIED + SCNotification scnN; + scnN.nmhdr.code = NPPN_FILEBEFORELOAD; + scnN.nmhdr.hwndFrom = _hSelf; + scnN.nmhdr.idFrom = NULL; + _pluginsManager.notify(&scnN); + + BufferID buffer = MainFileManager->loadFile(longFileName); + if (buffer != BUFFER_INVALID) + { + _isFileOpening = true; + + Buffer * buf = MainFileManager->getBufferByID(buffer); + // if file is read only, we set the view read only + if (isReadOnly) + buf->setUserReadOnly(true); + + // Notify plugins that current file is about to open + scnN.nmhdr.code = NPPN_FILEBEFOREOPEN; + scnN.nmhdr.idFrom = (uptr_t)buffer; + _pluginsManager.notify(&scnN); + + + loadBufferIntoView(buffer, currentView()); + + if (_pTrayIco) + { + if (_pTrayIco->isInTray()) + { + ::ShowWindow(_hSelf, SW_SHOW); + _pTrayIco->doTrayIcon(REMOVE); + ::SendMessage(_hSelf, WM_SIZE, 0, 0); + } + } + PathRemoveFileSpec(longFileName); + _linkTriggered = true; + _isDocModifing = false; + + _isFileOpening = false; + + // Notify plugins that current file is just opened + scnN.nmhdr.code = NPPN_FILEOPENED; + _pluginsManager.notify(&scnN); + + return buffer; + } + else + { + if (::PathIsDirectory(fileName)) + { + //::MessageBox(_hSelf, fileName, TEXT("Dir"), MB_OK); + vector fileNames; + vector patterns; + patterns.push_back(TEXT("*.*")); + + generic_string fileNameStr = fileName; + if (fileName[lstrlen(fileName) - 1] != '\\') + fileNameStr += TEXT("\\"); + + getMatchedFileNames(fileNameStr.c_str(), patterns, fileNames, true, false); + for (size_t i = 0 ; i < fileNames.size() ; i++) + { + //::MessageBox(_hSelf, fileNames[i].c_str(), TEXT("Dir"), MB_OK); + doOpen(fileNames[i].c_str()); + } + } + else + { + TCHAR msg[MAX_PATH + 100]; + lstrcpy(msg, TEXT("Can not open file \"")); + //lstrcat(msg, fullPath); + lstrcat(msg, longFileName); + lstrcat(msg, TEXT("\".")); + ::MessageBox(_hSelf, msg, TEXT("ERR"), MB_OK); + _isFileOpening = false; + + scnN.nmhdr.code = NPPN_FILELOADFAILED; + _pluginsManager.notify(&scnN); + } + return BUFFER_INVALID; + } +} + + +bool Notepad_plus::doReload(BufferID id, bool alert) +{ + + /* + //No activation when reloading, defer untill document is actually visible + if (alert) { + switchToFile(id); + } + */ + if (alert) + { + if (::MessageBox(_hSelf, TEXT("Are you sure you want to reload the current file and lose the changes made in Notepad++?"), TEXT("Reload"), MB_YESNO | MB_ICONEXCLAMATION | MB_APPLMODAL) != IDYES) + return false; + } + + //In order to prevent Scintilla from restyling the entire document, + //an empty Document is inserted during reload if needed. + bool mainVisisble = (_mainEditView.getCurrentBufferID() == id); + bool subVisisble = (_subEditView.getCurrentBufferID() == id); + if (mainVisisble) { + _mainEditView.saveCurrentPos(); + _mainEditView.execute(SCI_SETDOCPOINTER, 0, 0); + } + if (subVisisble) { + _subEditView.saveCurrentPos(); + _subEditView.execute(SCI_SETDOCPOINTER, 0, 0); + } + + if (!mainVisisble && !subVisisble) { + return MainFileManager->reloadBufferDeferred(id); + } + + bool res = MainFileManager->reloadBuffer(id); + Buffer * pBuf = MainFileManager->getBufferByID(id); + if (mainVisisble) { + _mainEditView.execute(SCI_SETDOCPOINTER, 0, pBuf->getDocument()); + _mainEditView.restoreCurrentPos(); + } + if (subVisisble) { + _subEditView.execute(SCI_SETDOCPOINTER, 0, pBuf->getDocument()); + _subEditView.restoreCurrentPos(); + } + return res; +} + +bool Notepad_plus::doSave(BufferID id, const TCHAR * filename, bool isCopy) +{ + SCNotification scnN; + // Notify plugins that current file is about to be saved + if (!isCopy) + { + + scnN.nmhdr.code = NPPN_FILEBEFORESAVE; + scnN.nmhdr.hwndFrom = _hSelf; + scnN.nmhdr.idFrom = (uptr_t)id; + _pluginsManager.notify(&scnN); + } + + bool res = MainFileManager->saveBuffer(id, filename, isCopy); + + if (!isCopy) + { + scnN.nmhdr.code = NPPN_FILESAVED; + _pluginsManager.notify(&scnN); + } + + if (!res) + ::MessageBox(_hSelf, TEXT("Please check whether if this file is opened in another program"), TEXT("Save failed"), MB_OK); + return res; +} + +void Notepad_plus::doClose(BufferID id, int whichOne) { + Buffer * buf = MainFileManager->getBufferByID(id); + + // Notify plugins that current file is about to be closed + SCNotification scnN; + scnN.nmhdr.code = NPPN_FILEBEFORECLOSE; + scnN.nmhdr.hwndFrom = _hSelf; + scnN.nmhdr.idFrom = (uptr_t)id; + _pluginsManager.notify(&scnN); + + //add to recent files if its an existing file + if (!buf->isUntitled() && PathFileExists(buf->getFullPathName())) + { + _lastRecentFileList.add(buf->getFullPathName()); + } + + int nrDocs = whichOne==MAIN_VIEW?(_mainDocTab.nbItem()):(_subDocTab.nbItem()); + + //Do all the works + removeBufferFromView(id, whichOne); + if (nrDocs == 1 && canHideView(whichOne)) + { //close the view if both visible + hideView(whichOne); + } + + // Notify plugins that current file is closed + scnN.nmhdr.code = NPPN_FILECLOSED; + _pluginsManager.notify(&scnN); + + return; +} +void Notepad_plus::fileNew() +{ + BufferID newBufID = MainFileManager->newEmptyDocument(); + loadBufferIntoView(newBufID, currentView(), true); //true, because we want multiple new files if possible + activateBuffer(newBufID, currentView()); +} + +bool Notepad_plus::fileReload() +{ + BufferID buf = _pEditView->getCurrentBufferID(); + return doReload(buf, buf->isDirty()); +} + +generic_string exts2Filters(generic_string exts) { + const TCHAR *extStr = exts.c_str(); + TCHAR aExt[MAX_PATH]; + generic_string filters(TEXT("")); + + int j = 0; + bool stop = false; + for (size_t i = 0 ; i < exts.length() ; i++) + { + if (extStr[i] == ' ') + { + if (!stop) + { + aExt[j] = '\0'; + stop = true; + + if (aExt[0]) + { + filters += TEXT("*."); + filters += aExt; + filters += TEXT(";"); + } + j = 0; + } + } + else + { + aExt[j] = extStr[i]; + stop = false; + j++; + } + } + + if (j > 0) + { + aExt[j] = '\0'; + if (aExt[0]) + { + filters += TEXT("*."); + filters += aExt; + filters += TEXT(";"); + } + } + + // remove the last ';' + filters = filters.substr(0, filters.length()-1); + return filters; +}; + +void Notepad_plus::setFileOpenSaveDlgFilters(FileDialog & fDlg) +{ + NppParameters *pNppParam = NppParameters::getInstance(); + NppGUI & nppGUI = (NppGUI & )pNppParam->getNppGUI(); + + int i = 0; + Lang *l = NppParameters::getInstance()->getLangFromIndex(i++); + LangType curl = _pEditView->getCurrentBuffer()->getLangType(); + + while (l) + { + LangType lid = l->getLangID(); + + bool inExcludedList = false; + + for (size_t j = 0 ; j < nppGUI._excludedLangList.size() ; j++) + { + if (lid == nppGUI._excludedLangList[j]._langType) + { + inExcludedList = true; + break; + } + } + + if (!inExcludedList) + { + const TCHAR *defList = l->getDefaultExtList(); + const TCHAR *userList = NULL; + + LexerStylerArray &lsa = (NppParameters::getInstance())->getLStylerArray(); + const TCHAR *lName = l->getLangName(); + LexerStyler *pLS = lsa.getLexerStylerByName(lName); + + if (pLS) + userList = pLS->getLexerUserExt(); + + std::generic_string list(TEXT("")); + if (defList) + list += defList; + if (userList) + { + list += TEXT(" "); + list += userList; + } + + generic_string stringFilters = exts2Filters(list); + const TCHAR *filters = stringFilters.c_str(); + if (filters[0]) + { + int nbExt = fDlg.setExtsFilter(getLangDesc(lid, true).c_str(), filters); + } + } + l = (NppParameters::getInstance())->getLangFromIndex(i++); + } +} + +void Notepad_plus::fileOpen() +{ + FileDialog fDlg(_hSelf, _hInst); + fDlg.setExtFilter(TEXT("All types"), TEXT(".*"), NULL); + + setFileOpenSaveDlgFilters(fDlg); + + BufferID lastOpened = BUFFER_INVALID; + if (stringVector *pfns = fDlg.doOpenMultiFilesDlg()) + { + size_t sz = pfns->size(); + for (size_t i = 0 ; i < sz ; i++) { + BufferID test = doOpen(pfns->at(i).c_str(), fDlg.isReadOnly()); + if (test != BUFFER_INVALID) + lastOpened = test; + } + } + if (lastOpened != BUFFER_INVALID) { + switchToFile(lastOpened); + } +} + +bool Notepad_plus::isFileSession(const TCHAR * filename) { + // if file2open matches the ext of user defined session file ext, then it'll be opened as a session + const TCHAR *definedSessionExt = NppParameters::getInstance()->getNppGUI()._definedSessionExt.c_str(); + if (*definedSessionExt != '\0') + { + TCHAR fncp[MAX_PATH]; + lstrcpy(fncp, filename); + TCHAR *pExt = PathFindExtension(fncp); + generic_string usrSessionExt = TEXT(""); + if (*definedSessionExt != '.') + { + usrSessionExt += TEXT("."); + } + usrSessionExt += definedSessionExt; + + if (!generic_stricmp(pExt, usrSessionExt.c_str())) + { + return true; + } + } + return false; +} + +bool Notepad_plus::fileSave(BufferID id) +{ + BufferID bufferID = id; + if (id == BUFFER_INVALID) + bufferID = _pEditView->getCurrentBufferID(); + Buffer * buf = MainFileManager->getBufferByID(bufferID); + + if (!buf->getFileReadOnly() && buf->isDirty()) //cannot save if readonly + { + const TCHAR *fn = buf->getFullPathName(); + if (buf->isUntitled()) + { + return fileSaveAs(id); + } + else + { + const NppGUI & nppgui = (NppParameters::getInstance())->getNppGUI(); + BackupFeature backup = nppgui._backup; + if (backup == bak_simple) + { + //copy fn to fn.backup + generic_string fn_bak(fn); + if ((nppgui._useDir) && (nppgui._backupDir[0] != '\0')) + { + TCHAR path[MAX_PATH]; + TCHAR *name; + + lstrcpy(path, fn); + name = ::PathFindFileName(path); + fn_bak = nppgui._backupDir; + fn_bak += TEXT("\\"); + fn_bak += name; + } + else + { + fn_bak = fn; + } + fn_bak += TEXT(".bak"); + ::CopyFile(fn, fn_bak.c_str(), FALSE); + } + else if (backup == bak_verbose) + { + TCHAR path[MAX_PATH]; + TCHAR *name; + generic_string fn_dateTime_bak; + + lstrcpy(path, fn); + + name = ::PathFindFileName(path); + ::PathRemoveFileSpec(path); + + if ((nppgui._useDir) && (nppgui._backupDir[0] != '\0')) + { + fn_dateTime_bak = nppgui._backupDir; + fn_dateTime_bak += TEXT("\\"); + } + else + { + const TCHAR *bakDir = TEXT("nppBackup"); + fn_dateTime_bak = path; + fn_dateTime_bak += TEXT("\\"); + fn_dateTime_bak += bakDir; + fn_dateTime_bak += TEXT("\\"); + + if (!::PathFileExists(fn_dateTime_bak.c_str())) + { + ::CreateDirectory(fn_dateTime_bak.c_str(), NULL); + } + } + + fn_dateTime_bak += name; + + const int temBufLen = 32; + TCHAR tmpbuf[temBufLen]; + time_t ltime = time(0); + struct tm *today; + + today = localtime(<ime); + generic_strftime(tmpbuf, temBufLen, TEXT("%Y-%m-%d_%H%M%S"), today); + + fn_dateTime_bak += TEXT("."); + fn_dateTime_bak += tmpbuf; + fn_dateTime_bak += TEXT(".bak"); + + ::CopyFile(fn, fn_dateTime_bak.c_str(), FALSE); + } + return doSave(bufferID, buf->getFullPathName(), false); + } + } + return false; +} + +bool Notepad_plus::fileSaveAll() { + if (viewVisible(MAIN_VIEW)) { + for(int i = 0; i < _mainDocTab.nbItem(); i++) { + BufferID idToSave = _mainDocTab.getBufferByIndex(i); + fileSave(idToSave); + } + } + + if (viewVisible(SUB_VIEW)) { + for(int i = 0; i < _subDocTab.nbItem(); i++) { + BufferID idToSave = _subDocTab.getBufferByIndex(i); + fileSave(idToSave); + } + } + return true; +} + +bool Notepad_plus::fileSaveAs(BufferID id, bool isSaveCopy) +{ + BufferID bufferID = id; + if (id == BUFFER_INVALID) + bufferID = _pEditView->getCurrentBufferID(); + Buffer * buf = MainFileManager->getBufferByID(bufferID); + + FileDialog fDlg(_hSelf, _hInst); + + fDlg.setExtFilter(TEXT("All types"), TEXT(".*"), NULL); + setFileOpenSaveDlgFilters(fDlg); + + fDlg.setDefFileName(buf->getFileName()); + TCHAR *pfn = fDlg.doSaveDlg(); + + if (pfn) + { + BufferID other = _pNonDocTab->findBufferByName(pfn); + if (other == BUFFER_INVALID) //can save, other view doesnt contain buffer + { + bool res = doSave(bufferID, pfn, isSaveCopy); + //buf->setNeedsLexing(true); //commented to fix wrapping being removed after save as (due to SCI_CLEARSTYLE or something, seems to be Scintilla bug) + //Changing lexer after save seems to work properly + return res; + } + else //cannot save, other view has buffer already open, activate it + { + ::MessageBox(_hSelf, TEXT("The file is already opened in the Notepad++."), TEXT("ERROR"), MB_OK | MB_ICONSTOP); + switchToFile(other); + return false; + } + } + else // cancel button is pressed + { + checkModifiedDocument(); + return false; + } +} + +bool Notepad_plus::fileRename(BufferID id, int curView) +{ + BufferID bufferID = id; + if (id == BUFFER_INVALID) + bufferID = _pEditView->getCurrentBufferID(); + Buffer * buf = MainFileManager->getBufferByID(bufferID); + + FileDialog fDlg(_hSelf, _hInst); + + fDlg.setExtFilter(TEXT("All types"), TEXT(".*"), NULL); + setFileOpenSaveDlgFilters(fDlg); + + fDlg.setDefFileName(buf->getFileName()); + TCHAR *pfn = fDlg.doSaveDlg(); + + if (pfn) + { + MainFileManager->moveFile(bufferID, pfn); + } + return false; +} + + +bool Notepad_plus::fileDelete(BufferID id, int curView) +{ + BufferID bufferID = id; + if (id == BUFFER_INVALID) + bufferID = _pEditView->getCurrentBufferID(); + + Buffer * buf = MainFileManager->getBufferByID(bufferID); + const TCHAR *fileNamePath = buf->getFullPathName(); + + if (doDeleteOrNot(fileNamePath) == IDYES) + { + if (!MainFileManager->deleteFile(bufferID)) + { + ::MessageBox(_hSelf, TEXT("Delete File failed"), TEXT("Delete File"), MB_OK); + return false; + } + doClose(bufferID, MAIN_VIEW); + doClose(bufferID, SUB_VIEW); + return true; + } + return false; +} + +bool Notepad_plus::fileClose(BufferID id, int curView) +{ + BufferID bufferID = id; + if (id == BUFFER_INVALID) + bufferID = _pEditView->getCurrentBufferID(); + Buffer * buf = MainFileManager->getBufferByID(bufferID); + + int res; + + //process the fileNamePath into LRF + const TCHAR *fileNamePath = buf->getFullPathName(); + + if (buf->isUntitled() && buf->docLength() == 0) + { + // Do nothing + } + else if (buf->isDirty()) + { + + res = doSaveOrNot(fileNamePath); + if (res == IDYES) + { + if (!fileSave(id)) // the cancel button of savedialog is pressed, aborts closing + return false; + } + else if (res == IDCANCEL) + { + return false; //cancel aborts closing + } + else + { + // else IDNO we continue + } + } + + int viewToClose = currentView(); + if (curView != -1) + viewToClose = curView; + //first check amount of documents, we dont want the view to hide if we closed a secondary doc with primary being empty + //int nrDocs = _pDocTab->nbItem(); + doClose(bufferID, viewToClose); + return true; +} + +bool Notepad_plus::fileCloseAll() +{ + //closes all documents, makes the current view the only one visible + + //first check if we need to save any file + for(int i = 0; i < _mainDocTab.nbItem(); i++) + { + BufferID id = _mainDocTab.getBufferByIndex(i); + Buffer * buf = MainFileManager->getBufferByID(id); + if (buf->isUntitled() && buf->docLength() == 0) + { + // Do nothing + } + else if (buf->isDirty()) + { + int res = doSaveOrNot(buf->getFullPathName()); + if (res == IDYES) + { + if (!fileSave(id)) + return false; //abort entire procedure + } + else if (res == IDCANCEL) + { + return false; + } + } + } + for(int i = 0; i < _subDocTab.nbItem(); i++) + { + BufferID id = _subDocTab.getBufferByIndex(i); + Buffer * buf = MainFileManager->getBufferByID(id); + if (buf->isUntitled() && buf->docLength() == 0) + { + // Do nothing + } + else if (buf->isDirty()) + { + int res = doSaveOrNot(buf->getFullPathName()); + if (res == IDYES) + { + if (!fileSave(id)) + return false; //abort entire procedure + } + else if (res == IDCANCEL) + { + return false; + //otherwise continue (IDNO) + } + } + } + + //Then start closing, inactive view first so the active is left open + if (bothActive()) + { //first close all docs in non-current view, which gets closed automatically + //Set active tab to the last one closed. + activateBuffer(_pNonDocTab->getBufferByIndex(0), otherView()); + for(int i = _pNonDocTab->nbItem() - 1; i >= 0; i--) { //close all from right to left + doClose(_pNonDocTab->getBufferByIndex(i), otherView()); + } + //hideView(otherView()); + } + + activateBuffer(_pDocTab->getBufferByIndex(0), currentView()); + for(int i = _pDocTab->nbItem() - 1; i >= 0; i--) { //close all from right to left + doClose(_pDocTab->getBufferByIndex(i), currentView()); + } + return true; +} + +bool Notepad_plus::fileCloseAllButCurrent() +{ + BufferID current = _pEditView->getCurrentBufferID(); + int active = _pDocTab->getCurrentTabIndex(); + //closes all documents, makes the current view the only one visible + + //first check if we need to save any file + for(int i = 0; i < _mainDocTab.nbItem(); i++) { + BufferID id = _mainDocTab.getBufferByIndex(i); + if (id == current) + continue; + Buffer * buf = MainFileManager->getBufferByID(id); + if (buf->isUntitled() && buf->docLength() == 0) + { + // Do nothing + } + else if (buf->isDirty()) + { + int res = doSaveOrNot(buf->getFullPathName()); + if (res == IDYES) + { + if (!fileSave(id)) + return false; //abort entire procedure + } + else if (res == IDCANCEL) + { + return false; + } + } + } + for(int i = 0; i < _subDocTab.nbItem(); i++) + { + BufferID id = _subDocTab.getBufferByIndex(i); + Buffer * buf = MainFileManager->getBufferByID(id); + if (id == current) + continue; + if (buf->isUntitled() && buf->docLength() == 0) + { + // Do nothing + } + else if (buf->isDirty()) + { + int res = doSaveOrNot(buf->getFullPathName()); + if (res == IDYES) + { + if (!fileSave(id)) + return false; //abort entire procedure + } + else if (res == IDCANCEL) + { + return false; + } + } + } + + //Then start closing, inactive view first so the active is left open + if (bothActive()) + { //first close all docs in non-current view, which gets closed automatically + //Set active tab to the last one closed. + activateBuffer(_pNonDocTab->getBufferByIndex(0), otherView()); + for(int i = _pNonDocTab->nbItem() - 1; i >= 0; i--) { //close all from right to left + doClose(_pNonDocTab->getBufferByIndex(i), otherView()); + } + //hideView(otherView()); + } + + activateBuffer(_pDocTab->getBufferByIndex(0), currentView()); + for(int i = _pDocTab->nbItem() - 1; i >= 0; i--) { //close all from right to left + if (i == active) { //dont close active index + continue; + } + doClose(_pDocTab->getBufferByIndex(i), currentView()); + } + return true; +} + +bool Notepad_plus::replaceAllFiles() { + + ScintillaEditView *pOldView = _pEditView; + _pEditView = &_invisibleEditView; + Document oldDoc = _invisibleEditView.execute(SCI_GETDOCPOINTER); + Buffer * oldBuf = _invisibleEditView.getCurrentBuffer(); //for manually setting the buffer, so notifications can be handled properly + + Buffer * pBuf = NULL; + + int nbTotal = 0; + const bool isEntireDoc = true; + + if (_mainWindowStatus & WindowMainActive) + { + for (int i = 0 ; i < _mainDocTab.nbItem() ; i++) + { + pBuf = MainFileManager->getBufferByID(_mainDocTab.getBufferByIndex(i)); + if (pBuf->isReadOnly()) + continue; + _invisibleEditView.execute(SCI_SETDOCPOINTER, 0, pBuf->getDocument()); + _invisibleEditView.execute(SCI_SETCODEPAGE, pBuf->getUnicodeMode() == uni8Bit ? 0 : SC_CP_UTF8); + _invisibleEditView._currentBuffer = pBuf; + _invisibleEditView.execute(SCI_BEGINUNDOACTION); + nbTotal += _findReplaceDlg.processAll(ProcessReplaceAll, NULL, NULL, isEntireDoc, NULL); + _invisibleEditView.execute(SCI_ENDUNDOACTION); + } + } + + if (_mainWindowStatus & WindowSubActive) + { + for (int i = 0 ; i < _subDocTab.nbItem() ; i++) + { + pBuf = MainFileManager->getBufferByID(_subDocTab.getBufferByIndex(i)); + if (pBuf->isReadOnly()) + continue; + _invisibleEditView.execute(SCI_SETDOCPOINTER, 0, pBuf->getDocument()); + _invisibleEditView.execute(SCI_SETCODEPAGE, pBuf->getUnicodeMode() == uni8Bit ? 0 : SC_CP_UTF8); + _invisibleEditView._currentBuffer = pBuf; + _invisibleEditView.execute(SCI_BEGINUNDOACTION); + nbTotal += _findReplaceDlg.processAll(ProcessReplaceAll, NULL, NULL, isEntireDoc, NULL); + _invisibleEditView.execute(SCI_ENDUNDOACTION); + } + } + + _invisibleEditView.execute(SCI_SETDOCPOINTER, 0, oldDoc); + _invisibleEditView._currentBuffer = oldBuf; + _pEditView = pOldView; + + TCHAR result[64]; + if (nbTotal < 0) + lstrcpy(result, TEXT("The regular expression to search is formed badly")); + else + wsprintf(result, TEXT("%d occurrences replaced."), nbTotal); + + ::printStr(result); + + return true; +} + +bool Notepad_plus::matchInList(const TCHAR *fileName, const vector & patterns) +{ + for (size_t i = 0 ; i < patterns.size() ; i++) + { + if (PathMatchSpec(fileName, patterns[i].c_str())) + return true; + } + return false; +} + +void Notepad_plus::saveFindHistory() +{ + _findReplaceDlg.saveFindHistory(); + (NppParameters::getInstance())->writeFindHistory(); +} + +void Notepad_plus::saveUserDefineLangs() +{ + if (ScintillaEditView::getUserDefineDlg()->isDirty()) + (NppParameters::getInstance())->writeUserDefinedLang(); +} + +void Notepad_plus::saveShortcuts() +{ + NppParameters::getInstance()->writeShortcuts(); +} + +void Notepad_plus::saveSession(const Session & session) +{ + (NppParameters::getInstance())->writeSession(session); +} + +void Notepad_plus::doTrimTrailing() +{ + _pEditView->execute(SCI_BEGINUNDOACTION); + int nbLines = _pEditView->execute(SCI_GETLINECOUNT); + for (int line = 0 ; line < nbLines ; line++) + { + int lineStart = _pEditView->execute(SCI_POSITIONFROMLINE,line); + int lineEnd = _pEditView->execute(SCI_GETLINEENDPOSITION,line); + int i = lineEnd - 1; + char c = (char)_pEditView->execute(SCI_GETCHARAT,i); + + for ( ; (i >= lineStart) && (c == ' ') || (c == '\t') ; c = (char)_pEditView->execute(SCI_GETCHARAT,i)) + i--; + + if (i < (lineEnd - 1)) + _pEditView->replaceTarget(TEXT(""), i + 1, lineEnd); + } + _pEditView->execute(SCI_ENDUNDOACTION); +} + +void Notepad_plus::loadLastSession() +{ + Session lastSession = (NppParameters::getInstance())->getSession(); + loadSession(lastSession); +} + +void Notepad_plus::getMatchedFileNames(const TCHAR *dir, const vector & patterns, vector & fileNames, bool isRecursive, bool isInHiddenDir) +{ + generic_string dirFilter(dir); + dirFilter += TEXT("*.*"); + WIN32_FIND_DATA foundData; + + HANDLE hFile = ::FindFirstFile(dirFilter.c_str(), &foundData); + + if (hFile != INVALID_HANDLE_VALUE) + { + + if (foundData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + { + if (!isInHiddenDir && (foundData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)) + { + // branles rien + } + else if (isRecursive) + { + if ((lstrcmp(foundData.cFileName, TEXT("."))) && (lstrcmp(foundData.cFileName, TEXT("..")))) + { + generic_string pathDir(dir); + pathDir += foundData.cFileName; + pathDir += TEXT("\\"); + getMatchedFileNames(pathDir.c_str(), patterns, fileNames, isRecursive, isInHiddenDir); + } + } + } + else + { + if (matchInList(foundData.cFileName, patterns)) + { + generic_string pathFile(dir); + pathFile += foundData.cFileName; + fileNames.push_back(pathFile.c_str()); + } + } + } + while (::FindNextFile(hFile, &foundData)) + { + if (foundData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + { + if (!isInHiddenDir && (foundData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)) + { + // branles rien + } + else if (isRecursive) + { + if ((lstrcmp(foundData.cFileName, TEXT("."))) && (lstrcmp(foundData.cFileName, TEXT("..")))) + { + generic_string pathDir(dir); + pathDir += foundData.cFileName; + pathDir += TEXT("\\"); + getMatchedFileNames(pathDir.c_str(), patterns, fileNames, isRecursive, isInHiddenDir); + } + } + } + else + { + if (matchInList(foundData.cFileName, patterns)) + { + generic_string pathFile(dir); + pathFile += foundData.cFileName; + fileNames.push_back(pathFile.c_str()); + } + } + } + ::FindClose(hFile); +} + +DWORD WINAPI AsyncCancelFindInFiles(LPVOID NppHWND) +{ + MessageBox((HWND) NULL, TEXT("Searching...\nPress Enter to Cancel"), TEXT("Find In Files"), MB_OK); + PostMessage((HWND) NppHWND, NPPM_INTERNAL_CANCEL_FIND_IN_FILES, 0, 0); + return 0; +} + +bool Notepad_plus::replaceInFiles() +{ + const TCHAR *dir2Search = _findReplaceDlg.getDir2Search(); + if (!dir2Search[0] || !::PathFileExists(dir2Search)) + { + return false; + } + + bool isRecursive = _findReplaceDlg.isRecursive(); + bool isInHiddenDir = _findReplaceDlg.isInHiddenDir(); + int nbTotal = 0; + + ScintillaEditView *pOldView = _pEditView; + _pEditView = &_invisibleEditView; + Document oldDoc = _invisibleEditView.execute(SCI_GETDOCPOINTER); + Buffer * oldBuf = _invisibleEditView.getCurrentBuffer(); //for manually setting the buffer, so notifications can be handled properly + Buffer * pBuf = NULL; + HANDLE CancelThreadHandle = NULL; + + vector patterns2Match; + _findReplaceDlg.getPatterns(patterns2Match); + if (patterns2Match.size() == 0) + { + _findReplaceDlg.setFindInFilesDirFilter(NULL, TEXT("*.*")); + _findReplaceDlg.getPatterns(patterns2Match); + } + vector fileNames; + + getMatchedFileNames(dir2Search, patterns2Match, fileNames, isRecursive, isInHiddenDir); + + if (fileNames.size() > 1) + CancelThreadHandle = ::CreateThread(NULL, 0, AsyncCancelFindInFiles, _hSelf, 0, NULL); + + bool dontClose = false; + for (size_t i = 0 ; i < fileNames.size() ; i++) + { + MSG msg; + if (PeekMessage(&msg, _hSelf, NPPM_INTERNAL_CANCEL_FIND_IN_FILES, NPPM_INTERNAL_CANCEL_FIND_IN_FILES, PM_REMOVE)) break; + + BufferID id = MainFileManager->getBufferFromName(fileNames.at(i).c_str()); + if (id != BUFFER_INVALID) + { + dontClose = true; + } + else + { + id = MainFileManager->loadFile(fileNames.at(i).c_str()); + dontClose = false; + } + + if (id != BUFFER_INVALID) + { + Buffer * pBuf = MainFileManager->getBufferByID(id); + _invisibleEditView.execute(SCI_SETDOCPOINTER, 0, pBuf->getDocument()); + _invisibleEditView.execute(SCI_SETCODEPAGE, pBuf->getUnicodeMode() == uni8Bit ? 0 : SC_CP_UTF8); + _invisibleEditView._currentBuffer = pBuf; + + int nbReplaced = _findReplaceDlg.processAll(ProcessReplaceAll, NULL, NULL, true, fileNames.at(i).c_str()); + nbTotal += nbReplaced; + if (nbReplaced) + { + MainFileManager->saveBuffer(id, pBuf->getFullPathName()); + } + + if (!dontClose) + MainFileManager->closeBuffer(id, _pEditView); + } + } + + if (CancelThreadHandle) + TerminateThread(CancelThreadHandle, 0); + + _invisibleEditView.execute(SCI_SETDOCPOINTER, 0, oldDoc); + _invisibleEditView._currentBuffer = oldBuf; + _pEditView = pOldView; + + TCHAR msg[128]; + wsprintf(msg, TEXT("%d occurences replaced"), nbTotal); + printStr(msg); + + return true; +} + +bool Notepad_plus::findInFiles() +{ + const TCHAR *dir2Search = _findReplaceDlg.getDir2Search(); + + if (!dir2Search[0] || !::PathFileExists(dir2Search)) + { + return false; + } + + bool isRecursive = _findReplaceDlg.isRecursive(); + bool isInHiddenDir = _findReplaceDlg.isInHiddenDir(); + int nbTotal = 0; + ScintillaEditView *pOldView = _pEditView; + _pEditView = &_invisibleEditView; + Document oldDoc = _invisibleEditView.execute(SCI_GETDOCPOINTER); + HANDLE CancelThreadHandle = NULL; + + vector patterns2Match; + _findReplaceDlg.getPatterns(patterns2Match); + if (patterns2Match.size() == 0) + { + _findReplaceDlg.setFindInFilesDirFilter(NULL, TEXT("*.*")); + _findReplaceDlg.getPatterns(patterns2Match); + } + vector fileNames; + getMatchedFileNames(dir2Search, patterns2Match, fileNames, isRecursive, isInHiddenDir); + + if (fileNames.size() > 1) + CancelThreadHandle = ::CreateThread(NULL, 0, AsyncCancelFindInFiles, _hSelf, 0, NULL); + + _findReplaceDlg.beginNewFilesSearch(); + + bool dontClose = false; + for (size_t i = 0 ; i < fileNames.size() ; i++) + { + MSG msg; + if (PeekMessage(&msg, _hSelf, NPPM_INTERNAL_CANCEL_FIND_IN_FILES, NPPM_INTERNAL_CANCEL_FIND_IN_FILES, PM_REMOVE)) break; + + BufferID id = MainFileManager->getBufferFromName(fileNames.at(i).c_str()); + if (id != BUFFER_INVALID) + { + dontClose = true; + } + else + { + id = MainFileManager->loadFile(fileNames.at(i).c_str()); + dontClose = false; + } + + if (id != BUFFER_INVALID) + { + Buffer * pBuf = MainFileManager->getBufferByID(id); + _invisibleEditView.execute(SCI_SETDOCPOINTER, 0, pBuf->getDocument()); + _invisibleEditView.execute(SCI_SETCODEPAGE, pBuf->getUnicodeMode() == uni8Bit ? 0 : SC_CP_UTF8); + + nbTotal += _findReplaceDlg.processAll(ProcessFindAll, NULL, NULL, true, fileNames.at(i).c_str()); + if (!dontClose) + MainFileManager->closeBuffer(id, _pEditView); + } + } + + if (CancelThreadHandle) + TerminateThread(CancelThreadHandle, 0); + + _findReplaceDlg.finishFilesSearch(nbTotal); + + _invisibleEditView.execute(SCI_SETDOCPOINTER, 0, oldDoc); + _pEditView = pOldView; + + _findReplaceDlg.putFindResult(nbTotal); + + FindHistory & findHistory = (NppParameters::getInstance())->getFindHistory(); + if (nbTotal && !findHistory._isDlgAlwaysVisible) + _findReplaceDlg.display(false); + return true; +} + + +bool Notepad_plus::findInOpenedFiles() +{ + int nbTotal = 0; + ScintillaEditView *pOldView = _pEditView; + _pEditView = &_invisibleEditView; + Document oldDoc = _invisibleEditView.execute(SCI_GETDOCPOINTER); + + Buffer * pBuf = NULL; + + const bool isEntireDoc = true; + + _findReplaceDlg.beginNewFilesSearch(); + + if (_mainWindowStatus & WindowMainActive) + { + for (int i = 0 ; i < _mainDocTab.nbItem() ; i++) + { + pBuf = MainFileManager->getBufferByID(_mainDocTab.getBufferByIndex(i)); + _invisibleEditView.execute(SCI_SETDOCPOINTER, 0, pBuf->getDocument()); + _invisibleEditView.execute(SCI_SETCODEPAGE, pBuf->getUnicodeMode() == uni8Bit ? 0 : SC_CP_UTF8); + nbTotal += _findReplaceDlg.processAll(ProcessFindAll, NULL, NULL, isEntireDoc, pBuf->getFullPathName()); + } + } + + if (_mainWindowStatus & WindowSubActive) + { + for (int i = 0 ; i < _subDocTab.nbItem() ; i++) + { + pBuf = MainFileManager->getBufferByID(_subDocTab.getBufferByIndex(i)); + _invisibleEditView.execute(SCI_SETDOCPOINTER, 0, pBuf->getDocument()); + _invisibleEditView.execute(SCI_SETCODEPAGE, pBuf->getUnicodeMode() == uni8Bit ? 0 : SC_CP_UTF8); + nbTotal += _findReplaceDlg.processAll(ProcessFindAll, NULL, NULL, isEntireDoc, pBuf->getFullPathName()); + } + } + + _findReplaceDlg.finishFilesSearch(nbTotal); + + _invisibleEditView.execute(SCI_SETDOCPOINTER, 0, oldDoc); + _pEditView = pOldView; + + _findReplaceDlg.putFindResult(nbTotal); + + FindHistory & findHistory = (NppParameters::getInstance())->getFindHistory(); + if (nbTotal && !findHistory._isDlgAlwaysVisible) + _findReplaceDlg.display(false); + return true; +} + + +bool Notepad_plus::findInCurrentFile() +{ + int nbTotal = 0; + Buffer * pBuf = _pEditView->getCurrentBuffer(); + ScintillaEditView *pOldView = _pEditView; + _pEditView = &_invisibleEditView; + Document oldDoc = _invisibleEditView.execute(SCI_GETDOCPOINTER); + + const bool isEntireDoc = true; + + _findReplaceDlg.beginNewFilesSearch(); + + _invisibleEditView.execute(SCI_SETDOCPOINTER, 0, pBuf->getDocument()); + _invisibleEditView.execute(SCI_SETCODEPAGE, pBuf->getUnicodeMode() == uni8Bit ? 0 : SC_CP_UTF8); + nbTotal += _findReplaceDlg.processAll(ProcessFindAll, NULL, NULL, isEntireDoc, pBuf->getFullPathName()); + + _findReplaceDlg.finishFilesSearch(nbTotal); + + _invisibleEditView.execute(SCI_SETDOCPOINTER, 0, oldDoc); + _pEditView = pOldView; + + _findReplaceDlg.putFindResult(nbTotal); + + FindHistory & findHistory = (NppParameters::getInstance())->getFindHistory(); + if (nbTotal && !findHistory._isDlgAlwaysVisible) + _findReplaceDlg.display(false); + return true; +} + +void Notepad_plus::filePrint(bool showDialog) +{ + Printer printer; + + int startPos = int(_pEditView->execute(SCI_GETSELECTIONSTART)); + int endPos = int(_pEditView->execute(SCI_GETSELECTIONEND)); + + printer.init(_hInst, _hSelf, _pEditView, showDialog, startPos, endPos); + printer.doPrint(); +} + +void Notepad_plus::enableCommand(int cmdID, bool doEnable, int which) const +{ + if (which & MENU) + { + enableMenu(cmdID, doEnable); + } + if (which & TOOLBAR) + { + _toolBar.enable(cmdID, doEnable); + } +} + +void Notepad_plus::checkClipboard() +{ + bool hasSelection = _pEditView->execute(SCI_GETSELECTIONSTART) != _pEditView->execute(SCI_GETSELECTIONEND); + bool canPaste = (_pEditView->execute(SCI_CANPASTE) != 0); + enableCommand(IDM_EDIT_CUT, hasSelection, MENU | TOOLBAR); + enableCommand(IDM_EDIT_COPY, hasSelection, MENU | TOOLBAR); + enableCommand(IDM_EDIT_PASTE, canPaste, MENU | TOOLBAR); + enableCommand(IDM_EDIT_DELETE, hasSelection, MENU | TOOLBAR); + enableCommand(IDM_EDIT_UPPERCASE, hasSelection, MENU); + enableCommand(IDM_EDIT_LOWERCASE, hasSelection, MENU); + enableCommand(IDM_EDIT_BLOCK_COMMENT, hasSelection, MENU); + enableCommand(IDM_EDIT_BLOCK_COMMENT_SET, hasSelection, MENU); + enableCommand(IDM_EDIT_BLOCK_UNCOMMENT, hasSelection, MENU); + enableCommand(IDM_EDIT_STREAM_COMMENT, hasSelection, MENU); +} + +void Notepad_plus::checkDocState() +{ + Buffer * curBuf = _pEditView->getCurrentBuffer(); + + bool isCurrentDirty = curBuf->isDirty(); + bool isSeveralDirty = isCurrentDirty; + bool isFileExisting = PathFileExists(curBuf->getFullPathName()) != FALSE; + if (!isCurrentDirty) + { + for(int i = 0; i < MainFileManager->getNrBuffers(); i++) + { + if (MainFileManager->getBufferByIndex(i)->isDirty()) + { + isSeveralDirty = true; + break; + } + } + } + + bool isCurrentUntitled = curBuf->isUntitled(); + enableCommand(IDM_FILE_SAVE, isCurrentDirty, MENU | TOOLBAR); + enableCommand(IDM_FILE_SAVEALL, isSeveralDirty, MENU | TOOLBAR); + enableCommand(IDM_VIEW_GOTO_NEW_INSTANCE, !(isCurrentDirty || isCurrentUntitled), MENU); + enableCommand(IDM_VIEW_LOAD_IN_NEW_INSTANCE, !(isCurrentDirty || isCurrentUntitled), MENU); + + bool isSysReadOnly = curBuf->getFileReadOnly(); + if (isSysReadOnly) + { + ::CheckMenuItem(_mainMenuHandle, IDM_EDIT_SETREADONLY, MF_BYCOMMAND | MF_UNCHECKED); + enableCommand(IDM_EDIT_SETREADONLY, false, MENU); + enableCommand(IDM_EDIT_CLEARREADONLY, true, MENU); + } + else + { + enableCommand(IDM_EDIT_SETREADONLY, true, MENU); + enableCommand(IDM_EDIT_CLEARREADONLY, false, MENU); + bool isUserReadOnly = curBuf->getUserReadOnly(); + ::CheckMenuItem(_mainMenuHandle, IDM_EDIT_SETREADONLY, MF_BYCOMMAND | (isUserReadOnly?MF_CHECKED:MF_UNCHECKED)); + } + enableCommand(IDM_FILE_DELETE, isFileExisting, MENU); + enableCommand(IDM_FILE_RENAME, isFileExisting, MENU); + + enableConvertMenuItems(curBuf->getFormat()); + checkUnicodeMenuItems(curBuf->getUnicodeMode()); + checkLangsMenu(-1); +} + +void Notepad_plus::checkUndoState() +{ + enableCommand(IDM_EDIT_UNDO, _pEditView->execute(SCI_CANUNDO) != 0, MENU | TOOLBAR); + enableCommand(IDM_EDIT_REDO, _pEditView->execute(SCI_CANREDO) != 0, MENU | TOOLBAR); +} + +void Notepad_plus::checkMacroState() +{ + enableCommand(IDM_MACRO_STARTRECORDINGMACRO, !_recordingMacro, MENU | TOOLBAR); + enableCommand(IDM_MACRO_STOPRECORDINGMACRO, _recordingMacro, MENU | TOOLBAR); + enableCommand(IDM_MACRO_PLAYBACKRECORDEDMACRO, !_macro.empty() && !_recordingMacro, MENU | TOOLBAR); + enableCommand(IDM_MACRO_SAVECURRENTMACRO, !_macro.empty() && !_recordingMacro, MENU | TOOLBAR); + + enableCommand(IDM_MACRO_RUNMULTIMACRODLG, (!_macro.empty() && !_recordingMacro) || !((NppParameters::getInstance())->getMacroList()).empty(), MENU | TOOLBAR); +} + +void Notepad_plus::checkSyncState() +{ + bool canDoSync = viewVisible(MAIN_VIEW) && viewVisible(SUB_VIEW); + if (!canDoSync) + { + _syncInfo._isSynScollV = false; + _syncInfo._isSynScollH = false; + checkMenuItem(IDM_VIEW_SYNSCROLLV, false); + checkMenuItem(IDM_VIEW_SYNSCROLLH, false); + _toolBar.setCheck(IDM_VIEW_SYNSCROLLV, false); + _toolBar.setCheck(IDM_VIEW_SYNSCROLLH, false); + } + enableCommand(IDM_VIEW_SYNSCROLLV, canDoSync, MENU | TOOLBAR); + enableCommand(IDM_VIEW_SYNSCROLLH, canDoSync, MENU | TOOLBAR); +} + +void Notepad_plus::checkLangsMenu(int id) const +{ + Buffer * curBuf = _pEditView->getCurrentBuffer(); + if (id == -1) + { + id = (NppParameters::getInstance())->langTypeToCommandID(curBuf->getLangType()); + if (id == IDM_LANG_USER) + { + if (curBuf->isUserDefineLangExt()) + { + const TCHAR *userLangName = curBuf->getUserDefineLangName(); + TCHAR menuLangName[16]; + + for (int i = IDM_LANG_USER + 1 ; i <= IDM_LANG_USER_LIMIT ; i++) + { + if (::GetMenuString(_mainMenuHandle, i, menuLangName, sizeof(menuLangName), MF_BYCOMMAND)) + if (!lstrcmp(userLangName, menuLangName)) + { + ::CheckMenuRadioItem(_mainMenuHandle, IDM_LANG_C, IDM_LANG_USER_LIMIT, i, MF_BYCOMMAND); + return; + } + } + } + } + } + ::CheckMenuRadioItem(_mainMenuHandle, IDM_LANG_C, IDM_LANG_USER_LIMIT, id, MF_BYCOMMAND); +} + +generic_string Notepad_plus::getLangDesc(LangType langType, bool shortDesc) +{ + + if ((langType >= L_EXTERNAL) && (langType < NppParameters::getInstance()->L_END)) + { + ExternalLangContainer & elc = NppParameters::getInstance()->getELCFromIndex(langType - L_EXTERNAL); + if (shortDesc) + return generic_string(elc._name); + else + return generic_string(elc._desc); + } + + generic_string str2Show = ScintillaEditView::langNames[langType].longName; + + if (langType == L_USER) + { + Buffer * currentBuf = _pEditView->getCurrentBuffer(); + if (currentBuf->isUserDefineLangExt()) + { + str2Show += TEXT(" - "); + str2Show += currentBuf->getUserDefineLangName(); + } + } + return str2Show; +} + +BOOL Notepad_plus::notify(SCNotification *notification) +{ + //Important, keep track of which element generated the message + bool isFromPrimary = (_mainEditView.getHSelf() == notification->nmhdr.hwndFrom || _mainDocTab.getHSelf() == notification->nmhdr.hwndFrom); + bool isFromSecondary = !isFromPrimary && (_subEditView.getHSelf() == notification->nmhdr.hwndFrom || _subDocTab.getHSelf() == notification->nmhdr.hwndFrom); + ScintillaEditView * notifyView = isFromPrimary?&_mainEditView:&_subEditView; + DocTabView *notifyDocTab = isFromPrimary?&_mainDocTab:&_subDocTab; + TBHDR * tabNotification = (TBHDR*) notification; + switch (notification->nmhdr.code) + { + case SCN_MODIFIED: + { + static bool prevWasEdit = false; + if (notification->modificationType & (SC_MOD_DELETETEXT | SC_MOD_INSERTTEXT)) + { + prevWasEdit = true; + _linkTriggered = true; + _isDocModifing = true; + ::InvalidateRect(notifyView->getHSelf(), NULL, TRUE); + } + + if (notification->modificationType & SC_MOD_CHANGEFOLD) + { + if (prevWasEdit) { + notifyView->foldChanged(notification->line, + notification->foldLevelNow, notification->foldLevelPrev); + prevWasEdit = false; + } + } + else if (!(notification->modificationType & (SC_MOD_DELETETEXT | SC_MOD_INSERTTEXT))) + { + prevWasEdit = false; + } +/* + if (!_isFileOpening && (isFromPrimary || isFromSecondary) && _pEditView->hasMarginShowed(ScintillaEditView::_SC_MARGE_MODIFMARKER)) + { + bool isProcessed = false; + + int fromLine = _pEditView->execute(SCI_LINEFROMPOSITION, notification->position); + pair undolevel = _pEditView->getLineUndoState(fromLine); + + if ((notification->modificationType & (SC_MOD_DELETETEXT | SC_MOD_INSERTTEXT)) && + (notification->modificationType & SC_PERFORMED_USER)) + { + //printStr(TEXT("user type")); + + _pEditView->setLineUndoState(fromLine, undolevel.first+1); + + _pEditView->execute(SCI_MARKERADD, fromLine, MARK_LINEMODIFIEDUNSAVED); + _pEditView->execute(undolevel.second?SCI_MARKERADD:SCI_MARKERDELETE, fromLine, MARK_LINEMODIFIEDSAVED); + + + if (notification->linesAdded > 0) + { + for (int i = 0 ; i < notification->linesAdded ; i++) + { + ++fromLine; + _pEditView->execute(SCI_MARKERADD, fromLine, MARK_LINEMODIFIEDUNSAVED); + pair modifInfo = _pEditView->getLineUndoState(fromLine); + _pEditView->execute(modifInfo.second?SCI_MARKERADD:SCI_MARKERDELETE, fromLine, MARK_LINEMODIFIEDSAVED); + } + } + } + + if ((notification->modificationType & (SC_MOD_DELETETEXT | SC_MOD_INSERTTEXT)) && + (notification->modificationType & SC_PERFORMED_REDO) && + (notification->modificationType & SC_MULTISTEPUNDOREDO)) + { + //printStr(TEXT("redo multiple")); + isProcessed = true; + + _pEditView->setLineUndoState(fromLine, undolevel.first+1); + + _pEditView->execute(SCI_MARKERADD, fromLine, MARK_LINEMODIFIEDUNSAVED); + if (notification->linesAdded > 0) + { + for (int i = 0 ; i < notification->linesAdded ; i++) + { + ++fromLine; + _pEditView->execute(SCI_MARKERADD, fromLine, MARK_LINEMODIFIEDUNSAVED); + pair modifInfo = _pEditView->getLineUndoState(fromLine); + _pEditView->execute(modifInfo.second?SCI_MARKERADD:SCI_MARKERDELETE, fromLine, MARK_LINEMODIFIEDSAVED); + } + } + } + + if ((notification->modificationType & (SC_MOD_DELETETEXT | SC_MOD_INSERTTEXT)) && + (notification->modificationType & SC_PERFORMED_UNDO) && + (notification->modificationType & SC_MULTISTEPUNDOREDO)) + { + //printStr(TEXT("undo multiple")); + isProcessed = true; + + --undolevel.first; + if (undolevel.first == 0) + { + _pEditView->execute(SCI_MARKERDELETE, fromLine, MARK_LINEMODIFIEDUNSAVED); + } + else + { + _pEditView->execute(SCI_MARKERADD, fromLine, MARK_LINEMODIFIEDUNSAVED); + } + _pEditView->execute(undolevel.second?SCI_MARKERADD:SCI_MARKERDELETE, fromLine, MARK_LINEMODIFIEDSAVED); + _pEditView->setLineUndoState(fromLine, undolevel.first); + + if (notification->linesAdded > 0) + { + for (int i = fromLine + 1 ; i < fromLine + notification->linesAdded ; i++) + { + pair level = _pEditView->getLineUndoState(i); + if (level.first > 0) + _pEditView->execute(SCI_MARKERADD, i, MARK_LINEMODIFIEDUNSAVED); + _pEditView->execute(level.second?SCI_MARKERADD:SCI_MARKERDELETE, fromLine, MARK_LINEMODIFIEDSAVED); + } + } + } + + if ((notification->modificationType & (SC_MOD_DELETETEXT | SC_MOD_INSERTTEXT)) && + (notification->modificationType & SC_PERFORMED_REDO) && + (notification->modificationType & SC_LASTSTEPINUNDOREDO) && !isProcessed) + { + //printStr(TEXT("redo LASTO")); + _pEditView->setLineUndoState(fromLine, undolevel.first+1); + + _pEditView->execute(SCI_MARKERADD, fromLine, MARK_LINEMODIFIEDUNSAVED); + _pEditView->execute(undolevel.second?SCI_MARKERADD:SCI_MARKERDELETE, fromLine, MARK_LINEMODIFIEDSAVED); + + if (notification->linesAdded > 0) + { + for (int i = 0 ; i < notification->linesAdded ; i++) + { + ++fromLine; + _pEditView->execute(SCI_MARKERADD, fromLine, MARK_LINEMODIFIEDUNSAVED); + pair modifInfo = _pEditView->getLineUndoState(fromLine); + _pEditView->execute(modifInfo.second?SCI_MARKERADD:SCI_MARKERDELETE, fromLine, MARK_LINEMODIFIEDSAVED); + } + } + } + + if ((notification->modificationType & (SC_MOD_DELETETEXT | SC_MOD_INSERTTEXT)) && + (notification->modificationType & SC_PERFORMED_UNDO) && + (notification->modificationType & SC_LASTSTEPINUNDOREDO) && !isProcessed) + { + //printStr(TEXT("undo LASTO")); + --undolevel.first; + if (undolevel.first == 0) + { + _pEditView->execute(SCI_MARKERDELETE, fromLine, MARK_LINEMODIFIEDUNSAVED); + } + else + { + _pEditView->execute(SCI_MARKERADD, fromLine, MARK_LINEMODIFIEDUNSAVED); + } + _pEditView->execute(undolevel.second?SCI_MARKERADD:SCI_MARKERDELETE, fromLine, MARK_LINEMODIFIEDSAVED); + _pEditView->setLineUndoState(fromLine, undolevel.first); + + if (notification->linesAdded > 0) + { + for (int i = fromLine + 1 ; i < fromLine + notification->linesAdded ; i++) + { + pair level = _pEditView->getLineUndoState(i); + if (level.first > 0) + _pEditView->execute(SCI_MARKERADD, i, MARK_LINEMODIFIEDUNSAVED); + _pEditView->execute(level.second?SCI_MARKERADD:SCI_MARKERDELETE, fromLine, MARK_LINEMODIFIEDSAVED); + } + } + } + } + */ + } + break; + + case SCN_SAVEPOINTREACHED: + case SCN_SAVEPOINTLEFT: + { + Buffer * buf = 0; + if (isFromPrimary) { + buf = _mainEditView.getCurrentBuffer(); + } else if (isFromSecondary) { + buf = _subEditView.getCurrentBuffer(); + } else { + //Done by invisibleEditView? + BufferID id = BUFFER_INVALID; + if (notification->nmhdr.hwndFrom == _invisibleEditView.getHSelf()) { + id = MainFileManager->getBufferFromDocument(_invisibleEditView.execute(SCI_GETDOCPOINTER)); + } else if (notification->nmhdr.hwndFrom == _fileEditView.getHSelf()) { + id = MainFileManager->getBufferFromDocument(_fileEditView.execute(SCI_GETDOCPOINTER)); + } else { + break; //wrong scintilla + } + if (id != BUFFER_INVALID) { + buf = MainFileManager->getBufferByID(id); + } else { + break; + } + } + buf->setDirty(notification->nmhdr.code == SCN_SAVEPOINTLEFT); + break; } + + case SCN_MODIFYATTEMPTRO : + // on fout rien + break; + + case SCN_KEY: + break; + + case TCN_TABDROPPEDOUTSIDE: + case TCN_TABDROPPED: + { + TabBarPlus *sender = reinterpret_cast(notification->nmhdr.idFrom); + bool isInCtrlStat = (::GetKeyState(VK_LCONTROL) & 0x80000000) != 0; + if (notification->nmhdr.code == TCN_TABDROPPEDOUTSIDE) + { + POINT p = sender->getDraggingPoint(); + + //It's the coordinate of screen, so we can call + //"WindowFromPoint" function without converting the point + HWND hWin = ::WindowFromPoint(p); + if (hWin == _pEditView->getHSelf()) // In the same view group + { + if (!_tabPopupDropMenu.isCreated()) + { + TCHAR goToView[32] = TEXT("Move to other view"); + TCHAR cloneToView[32] = TEXT("Clone to other View"); + vector itemUnitArray; + itemUnitArray.push_back(MenuItemUnit(IDM_VIEW_GOTO_ANOTHER_VIEW, goToView)); + itemUnitArray.push_back(MenuItemUnit(IDM_VIEW_CLONE_TO_ANOTHER_VIEW, cloneToView)); + _tabPopupDropMenu.create(_hSelf, itemUnitArray); + changeLangTabDrapContextMenu(); + } + _tabPopupDropMenu.display(p); + } + else if ((hWin == _pNonDocTab->getHSelf()) || + (hWin == _pNonEditView->getHSelf())) // In the another view group + { + docGotoAnotherEditView(isInCtrlStat?TransferClone:TransferMove); + } + + else + { + RECT nppZone; + ::GetWindowRect(_hSelf, &nppZone); + bool isInNppZone = (((p.x >= nppZone.left) && (p.x <= nppZone.right)) && (p.y >= nppZone.top) && (p.y <= nppZone.bottom)); + if (isInNppZone) + { + // Do nothing + return TRUE; + } + generic_string quotFileName = TEXT("\""); + quotFileName += _pEditView->getCurrentBuffer()->getFullPathName(); + quotFileName += TEXT("\""); + COPYDATASTRUCT fileNamesData; + fileNamesData.dwData = COPYDATA_FILENAMES; + fileNamesData.lpData = (void *)quotFileName.c_str(); + fileNamesData.cbData = long(quotFileName.length() + 1)*(sizeof(TCHAR)); + + HWND hWinParent = ::GetParent(hWin); + TCHAR className[MAX_PATH]; + ::GetClassName(hWinParent,className, sizeof(className)); + if (lstrcmp(className, _className) == 0 && hWinParent != _hSelf) // another Notepad++ + { + int index = _pDocTab->getCurrentTabIndex(); + BufferID bufferToClose = notifyDocTab->getBufferByIndex(index); + Buffer * buf = MainFileManager->getBufferByID(bufferToClose); + int iView = isFromPrimary?MAIN_VIEW:SUB_VIEW; + if (buf->isDirty()) + { + ::MessageBox(_hSelf, TEXT("Document is modified, save it then try again."), TEXT("Move to new Notepad++ Instance"), MB_OK); + } + else + { + ::SendMessage(hWinParent, NPPM_INTERNAL_SWITCHVIEWFROMHWND, 0, (LPARAM)hWin); + ::SendMessage(hWinParent, WM_COPYDATA, (WPARAM)_hInst, (LPARAM)&fileNamesData); + if (!isInCtrlStat) + { + fileClose(bufferToClose, iView); + if (noOpenedDoc()) + ::SendMessage(_hSelf, WM_CLOSE, 0, 0); + } + } + } + else // Not Notepad++, we open it here + { + docOpenInNewInstance(isInCtrlStat?TransferClone:TransferMove, p.x, p.y); + } + } + } + //break; + return TRUE; + } + + case TCN_TABDELETE: + { + int index = tabNotification->tabOrigin; + BufferID bufferToClose = notifyDocTab->getBufferByIndex(index); + Buffer * buf = MainFileManager->getBufferByID(bufferToClose); + int iView = isFromPrimary?MAIN_VIEW:SUB_VIEW; + if (buf->isDirty()) { //activate and use fileClose() (for save and abort) + activateBuffer(bufferToClose, iView); + fileClose(bufferToClose, iView); + break; + } + int open = 1; + if (isFromPrimary || isFromSecondary) + open = notifyDocTab->nbItem(); + doClose(bufferToClose, iView); + //if (open == 1 && canHideView(iView)) + // hideView(iView); + break; + + } + + case TCN_SELCHANGE: + { + int iView = -1; + if (notification->nmhdr.hwndFrom == _mainDocTab.getHSelf()) + { + iView = MAIN_VIEW; + } + else if (notification->nmhdr.hwndFrom == _subDocTab.getHSelf()) + { + iView = SUB_VIEW; + } + else + { + break; + } + + switchEditViewTo(iView); + BufferID bufid = _pDocTab->getBufferByIndex(_pDocTab->getCurrentTabIndex()); + if (bufid != BUFFER_INVALID) + activateBuffer(bufid, iView); + + break; + } + + case NM_CLICK : + { + if (notification->nmhdr.hwndFrom == _statusBar.getHSelf()) + { + LPNMMOUSE lpnm = (LPNMMOUSE)notification; + if (lpnm->dwItemSpec == DWORD(STATUSBAR_TYPING_MODE)) + { + bool isOverTypeMode = (_pEditView->execute(SCI_GETOVERTYPE) != 0); + _pEditView->execute(SCI_SETOVERTYPE, !isOverTypeMode); + _statusBar.setText((_pEditView->execute(SCI_GETOVERTYPE))?TEXT("OVR"):TEXT("INS"), STATUSBAR_TYPING_MODE); + } + } + else if (notification->nmhdr.hwndFrom == _mainDocTab.getHSelf()) + { + switchEditViewTo(MAIN_VIEW); + } + else if (notification->nmhdr.hwndFrom == _subDocTab.getHSelf()) + { + switchEditViewTo(SUB_VIEW); + } + + break; + } + + case NM_DBLCLK : + { + if (notification->nmhdr.hwndFrom == _statusBar.getHSelf()) + { + LPNMMOUSE lpnm = (LPNMMOUSE)notification; + if (lpnm->dwItemSpec == DWORD(STATUSBAR_CUR_POS)) + { + bool isFirstTime = !_goToLineDlg.isCreated(); + _goToLineDlg.doDialog(_isRTL); + if (isFirstTime) + changeDlgLang(_goToLineDlg.getHSelf(), "GoToLine"); + } + } + break; + } + + case NM_RCLICK : + { + if (notification->nmhdr.hwndFrom == _mainDocTab.getHSelf()) + { + switchEditViewTo(MAIN_VIEW); + } + else if (notification->nmhdr.hwndFrom == _subDocTab.getHSelf()) + { + switchEditViewTo(SUB_VIEW); + } + else // From tool bar or Status Bar + return TRUE; + //break; + + POINT p; + ::GetCursorPos(&p); + + if (!_tabPopupMenu.isCreated()) + { + vector itemUnitArray; + itemUnitArray.push_back(MenuItemUnit(IDM_FILE_CLOSE, TEXT("Close me"))); + itemUnitArray.push_back(MenuItemUnit(IDM_FILE_CLOSEALL_BUT_CURRENT, TEXT("Close all but me"))); + itemUnitArray.push_back(MenuItemUnit(IDM_FILE_SAVE, TEXT("Save me"))); + itemUnitArray.push_back(MenuItemUnit(IDM_FILE_SAVEAS, TEXT("Save me As..."))); + itemUnitArray.push_back(MenuItemUnit(IDM_FILE_RENAME, TEXT("Rename me"))); + itemUnitArray.push_back(MenuItemUnit(IDM_FILE_DELETE, TEXT("Delete me"))); + itemUnitArray.push_back(MenuItemUnit(IDM_FILE_PRINT, TEXT("Print me"))); + itemUnitArray.push_back(MenuItemUnit(0, NULL)); + itemUnitArray.push_back(MenuItemUnit(IDM_EDIT_SETREADONLY, TEXT("Read only"))); + itemUnitArray.push_back(MenuItemUnit(IDM_EDIT_CLEARREADONLY, TEXT("Clear read only flag"))); + itemUnitArray.push_back(MenuItemUnit(0, NULL)); + itemUnitArray.push_back(MenuItemUnit(IDM_EDIT_FULLPATHTOCLIP, TEXT("Full file path to Clipboard"))); + itemUnitArray.push_back(MenuItemUnit(IDM_EDIT_FILENAMETOCLIP, TEXT("File name to Clipboard"))); + itemUnitArray.push_back(MenuItemUnit(IDM_EDIT_CURRENTDIRTOCLIP, TEXT("Current dir path to Clipboard"))); + itemUnitArray.push_back(MenuItemUnit(0, NULL)); + itemUnitArray.push_back(MenuItemUnit(IDM_VIEW_GOTO_ANOTHER_VIEW, TEXT("Move to other view"))); + itemUnitArray.push_back(MenuItemUnit(IDM_VIEW_CLONE_TO_ANOTHER_VIEW, TEXT("Clone to other view"))); + itemUnitArray.push_back(MenuItemUnit(IDM_VIEW_GOTO_NEW_INSTANCE, TEXT("Move to new instance"))); + itemUnitArray.push_back(MenuItemUnit(IDM_VIEW_LOAD_IN_NEW_INSTANCE, TEXT("Open in new instance"))); + + _tabPopupMenu.create(_hSelf, itemUnitArray); + changeLangTabContextMenu(); + } + + bool isEnable = ((::GetMenuState(_mainMenuHandle, IDM_FILE_SAVE, MF_BYCOMMAND)&MF_DISABLED) == 0); + _tabPopupMenu.enableItem(IDM_FILE_SAVE, isEnable); + + Buffer * buf = _pEditView->getCurrentBuffer(); + bool isUserReadOnly = buf->getUserReadOnly(); + _tabPopupMenu.checkItem(IDM_EDIT_SETREADONLY, isUserReadOnly); + + bool isSysReadOnly = buf->getFileReadOnly(); + _tabPopupMenu.enableItem(IDM_EDIT_SETREADONLY, !isSysReadOnly); + _tabPopupMenu.enableItem(IDM_EDIT_CLEARREADONLY, isSysReadOnly); + + bool isFileExisting = PathFileExists(buf->getFullPathName()) != FALSE; + _tabPopupMenu.enableItem(IDM_FILE_DELETE, isFileExisting); + _tabPopupMenu.enableItem(IDM_FILE_RENAME, isFileExisting); + + bool isDirty = buf->isDirty(); + bool isUntitled = buf->isUntitled(); + _tabPopupMenu.enableItem(IDM_VIEW_GOTO_NEW_INSTANCE, !(isDirty||isUntitled)); + _tabPopupMenu.enableItem(IDM_VIEW_LOAD_IN_NEW_INSTANCE, !(isDirty||isUntitled)); + + _tabPopupMenu.display(p); + return TRUE; + } + + + case SCN_MARGINCLICK: + { + if (notification->nmhdr.hwndFrom == _mainEditView.getHSelf()) + switchEditViewTo(MAIN_VIEW); + + else if (notification->nmhdr.hwndFrom == _subEditView.getHSelf()) + switchEditViewTo(SUB_VIEW); + + if (notification->margin == ScintillaEditView::_SC_MARGE_FOLDER) + { + _pEditView->marginClick(notification->position, notification->modifiers); + } + else if ((notification->margin == ScintillaEditView::_SC_MARGE_SYBOLE) && !notification->modifiers) + { + + int lineClick = int(_pEditView->execute(SCI_LINEFROMPOSITION, notification->position)); + if (!_pEditView->markerMarginClick(lineClick)) + bookmarkToggle(lineClick); + + } + break; + } + + case SCN_CHARADDED: + { + charAdded(static_cast(notification->ch)); + + AutoCompletion * autoC = isFromPrimary?&_autoCompleteMain:&_autoCompleteSub; + + autoC->update(notification->ch); + + break; + } + + case SCN_DOUBLECLICK : + { + if (_isHotspotDblClicked) + { + int pos = notifyView->execute(SCI_GETCURRENTPOS); + notifyView->execute(SCI_SETCURRENTPOS, pos); + notifyView->execute(SCI_SETANCHOR, pos); + _isHotspotDblClicked = false; + } + } + break; + + case SCN_UPDATEUI: + { + NppParameters *nppParam = NppParameters::getInstance(); + + // if it's searching/replacing, then do nothing + if (nppParam->_isFindReplacing) + break; + + if (notification->nmhdr.hwndFrom != _pEditView->getHSelf()) + break; + + braceMatch(); + + const NppGUI & nppGui = nppParam->getNppGUI(); + + if (nppGui._enableTagsMatchHilite) + { + XmlMatchedTagsHighlighter xmlTagMatchHiliter(_pEditView); + xmlTagMatchHiliter.tagMatch(nppGui._enableTagAttrsHilite); + } + + if (nppGui._enableSmartHilite) + _smartHighlighter.highlightView(notifyView); + + updateStatusBar(); + AutoCompletion * autoC = isFromPrimary?&_autoCompleteMain:&_autoCompleteSub; + autoC->update(0); + break; + } + + case SCN_SCROLLED: + { + const NppGUI & nppGUI = (NppParameters::getInstance())->getNppGUI(); + if (nppGUI._enableSmartHilite) + _smartHighlighter.highlightView(notifyView); + break; + } + + case TTN_GETDISPINFO: + { + LPTOOLTIPTEXT lpttt; + + lpttt = (LPTOOLTIPTEXT)notification; + lpttt->hinst = _hInst; + + POINT p; + ::GetCursorPos(&p); + ::ScreenToClient(_hSelf, &p); + HWND hWin = ::RealChildWindowFromPoint(_hSelf, p); + + static generic_string tip; + int id = int(lpttt->hdr.idFrom); + + if (hWin == _rebarTop.getHSelf()) + { + getNameStrFromCmd(id, tip); + } + else if (hWin == _mainDocTab.getHSelf()) + { + BufferID idd = _mainDocTab.getBufferByIndex(id); + Buffer * buf = MainFileManager->getBufferByID(idd); + tip = buf->getFullPathName(); + } + else if (hWin == _subDocTab.getHSelf()) + { + BufferID idd = _subDocTab.getBufferByIndex(id); + Buffer * buf = MainFileManager->getBufferByID(idd); + tip = buf->getFullPathName(); + } + else + break; + + lpttt->lpszText = (TCHAR *)tip.c_str(); + } + break; + + case SCN_ZOOM: + break; + + case SCN_MACRORECORD: + _macro.push_back(recordedMacroStep(notification->message, notification->wParam, notification->lParam)); + break; + + case SCN_PAINTED: + { + notifyView->updateLineNumberWidth(); + if (_syncInfo.doSync()) + doSynScorll(HWND(notification->nmhdr.hwndFrom)); + + NppParameters *nppParam = NppParameters::getInstance(); + + // if it's searching/replacing, then do nothing + if (_linkTriggered && !nppParam->_isFindReplacing) + { + int urlAction = (NppParameters::getInstance())->getNppGUI()._styleURL; + if ((urlAction == 1) || (urlAction == 2)) + addHotSpot(_isDocModifing); + _linkTriggered = false; + _isDocModifing = false; + } + break; + } + + case SCN_HOTSPOTDOUBLECLICK : + { + notifyView->execute(SCI_SETWORDCHARS, 0, (LPARAM)"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-+.:?&@=/%#"); + + int pos = notifyView->execute(SCI_GETCURRENTPOS); + int startPos = static_cast(notifyView->execute(SCI_WORDSTARTPOSITION, pos, false)); + int endPos = static_cast(notifyView->execute(SCI_WORDENDPOSITION, pos, false)); + + notifyView->execute(SCI_SETTARGETSTART, startPos); + notifyView->execute(SCI_SETTARGETEND, endPos); + + int posFound = notifyView->execute(SCI_SEARCHINTARGET, strlen(urlHttpRegExpr), (LPARAM)urlHttpRegExpr); + if (posFound != -1) + { + startPos = int(notifyView->execute(SCI_GETTARGETSTART)); + endPos = int(notifyView->execute(SCI_GETTARGETEND)); + } + + TCHAR currentWord[MAX_PATH*2]; + notifyView->getGenericText(currentWord, startPos, endPos); + + ::ShellExecute(_hSelf, TEXT("open"), currentWord, NULL, NULL, SW_SHOW); + _isHotspotDblClicked = true; + notifyView->execute(SCI_SETCHARSDEFAULT); + break; + } + + case SCN_NEEDSHOWN : + { + int begin = notifyView->execute(SCI_LINEFROMPOSITION, notification->position); + int end = notifyView->execute(SCI_LINEFROMPOSITION, notification->position + notification->length); + int firstLine = begin < end ? begin : end; + int lastLine = begin > end ? begin : end; + for (int line = firstLine; line <= lastLine; line++) { + notifyView->execute(SCI_ENSUREVISIBLE, line, 0); + } + break; + } + + case SCN_CALLTIPCLICK: + { + AutoCompletion * autoC = isFromPrimary?&_autoCompleteMain:&_autoCompleteSub; + autoC->callTipClick(notification->position); + break; + } + + case RBN_HEIGHTCHANGE: + { + SendMessage(_hSelf, WM_SIZE, 0, 0); + break; + } + case RBN_CHEVRONPUSHED: + { + NMREBARCHEVRON * lpnm = (NMREBARCHEVRON*) notification; + ReBar * notifRebar = &_rebarTop; + if (_rebarBottom.getHSelf() == lpnm->hdr.hwndFrom) + notifRebar = &_rebarBottom; + //If N++ ID, use proper object + switch(lpnm->wID) { + case REBAR_BAR_TOOLBAR: { + POINT pt; + pt.x = lpnm->rc.left; + pt.y = lpnm->rc.bottom; + ClientToScreen(notifRebar->getHSelf(), &pt); + _toolBar.doPopop(pt); + return TRUE; + break; } + } + //Else forward notification to window of rebarband + REBARBANDINFO rbBand; + rbBand.cbSize = sizeof(rbBand); + rbBand.fMask = RBBIM_CHILD; + ::SendMessage(notifRebar->getHSelf(), RB_GETBANDINFO, lpnm->uBand, (LPARAM)&rbBand); + ::SendMessage(rbBand.hwndChild, WM_NOTIFY, 0, (LPARAM)lpnm); + break; + } + + default : + break; + + } + return FALSE; +} + +void Notepad_plus::findMatchingBracePos(int & braceAtCaret, int & braceOpposite) +{ + int caretPos = int(_pEditView->execute(SCI_GETCURRENTPOS)); + braceAtCaret = -1; + braceOpposite = -1; + TCHAR charBefore = '\0'; + //TCHAR styleBefore = '\0'; + int lengthDoc = int(_pEditView->execute(SCI_GETLENGTH)); + + if ((lengthDoc > 0) && (caretPos > 0)) + { + charBefore = TCHAR(_pEditView->execute(SCI_GETCHARAT, caretPos - 1, 0)); + } + // Priority goes to character before caret + if (charBefore && generic_strchr(TEXT("[](){}"), charBefore)) + { + braceAtCaret = caretPos - 1; + } + + if (lengthDoc > 0 && (braceAtCaret < 0)) + { + // No brace found so check other side + TCHAR charAfter = TCHAR(_pEditView->execute(SCI_GETCHARAT, caretPos, 0)); + if (charAfter && generic_strchr(TEXT("[](){}"), charAfter)) + { + braceAtCaret = caretPos; + } + } + if (braceAtCaret >= 0) + braceOpposite = int(_pEditView->execute(SCI_BRACEMATCH, braceAtCaret, 0)); +} + + +void Notepad_plus::braceMatch() +{ + int braceAtCaret = -1; + int braceOpposite = -1; + findMatchingBracePos(braceAtCaret, braceOpposite); + + if ((braceAtCaret != -1) && (braceOpposite == -1)) + { + _pEditView->execute(SCI_BRACEBADLIGHT, braceAtCaret); + _pEditView->execute(SCI_SETHIGHLIGHTGUIDE); + } + else + { + _pEditView->execute(SCI_BRACEHIGHLIGHT, braceAtCaret, braceOpposite); + + if (_pEditView->isShownIndentGuide()) + { + int columnAtCaret = int(_pEditView->execute(SCI_GETCOLUMN, braceAtCaret)); + int columnOpposite = int(_pEditView->execute(SCI_GETCOLUMN, braceOpposite)); + _pEditView->execute(SCI_SETHIGHLIGHTGUIDE, (columnAtCaret < columnOpposite)?columnAtCaret:columnOpposite); + } + } + + enableCommand(IDM_SEARCH_GOTOMATCHINGBRACE, (braceAtCaret != -1) && (braceOpposite != -1), MENU | TOOLBAR); +} + +void Notepad_plus::charAdded(TCHAR chAdded) +{ + bool indentMaintain = NppParameters::getInstance()->getNppGUI()._maitainIndent; + if (indentMaintain) + MaintainIndentation(chAdded); +} + +void Notepad_plus::addHotSpot(bool docIsModifing) +{ + //bool docIsModifing = true; + int posBegin2style = 0; + if (docIsModifing) + posBegin2style = _pEditView->execute(SCI_GETCURRENTPOS); + + int endStyle = _pEditView->execute(SCI_GETENDSTYLED); + if (docIsModifing) + { + + posBegin2style = _pEditView->execute(SCI_GETCURRENTPOS); + if (posBegin2style > 0) posBegin2style--; + UCHAR ch = (UCHAR)_pEditView->execute(SCI_GETCHARAT, posBegin2style); + + // determinating the type of EOF to make sure how many steps should we be back + if ((ch == 0x0A) || (ch == 0x0D)) + { + int eolMode = _pEditView->execute(SCI_GETEOLMODE); + + if ((eolMode == SC_EOL_CRLF) && (posBegin2style > 1)) + posBegin2style -= 2; + else if (posBegin2style > 0) + posBegin2style -= 1; + } + + ch = (UCHAR)_pEditView->execute(SCI_GETCHARAT, posBegin2style); + while ((posBegin2style > 0) && ((ch != 0x0A) && (ch != 0x0D))) + { + ch = (UCHAR)_pEditView->execute(SCI_GETCHARAT, posBegin2style--); + } + } + int style_hotspot = 30; + + int startPos = 0; + int endPos = _pEditView->execute(SCI_GETTEXTLENGTH); + + _pEditView->execute(SCI_SETSEARCHFLAGS, SCFIND_REGEXP|SCFIND_POSIX); + + _pEditView->execute(SCI_SETTARGETSTART, startPos); + _pEditView->execute(SCI_SETTARGETEND, endPos); + + vector > hotspotStylers; + + int posFound = _pEditView->execute(SCI_SEARCHINTARGET, strlen(urlHttpRegExpr), (LPARAM)urlHttpRegExpr); + + while (posFound != -1) + { + int start = int(_pEditView->execute(SCI_GETTARGETSTART)); + int end = int(_pEditView->execute(SCI_GETTARGETEND)); + int foundTextLen = end - start; + int idStyle = _pEditView->execute(SCI_GETSTYLEAT, posFound); + + if (end < posBegin2style - 1) + { + if (style_hotspot > 1) + style_hotspot--; + } + else + { + int fs = -1; + for (size_t i = 0 ; i < hotspotStylers.size() ; i++) + { + if (hotspotStylers[i].second == idStyle) + { + fs = hotspotStylers[i].first; + break; + } + } + + if (fs != -1) + { + _pEditView->execute(SCI_STARTSTYLING, start, 0xFF); + _pEditView->execute(SCI_SETSTYLING, foundTextLen, fs); + + } + else + { + pair p(style_hotspot, idStyle); + hotspotStylers.push_back(p); + int activeFG = 0xFF0000; + + //TCHAR fontName[256]; + Style hotspotStyle; + + hotspotStyle._styleID = style_hotspot; + //_pEditView->execute(SCI_STYLEGETFONT, idStyle, (LPARAM)fontName); + hotspotStyle._fgColor = _pEditView->execute(SCI_STYLEGETFORE, idStyle); + hotspotStyle._bgColor = _pEditView->execute(SCI_STYLEGETBACK, idStyle); + hotspotStyle._fontSize = _pEditView->execute(SCI_STYLEGETSIZE, idStyle); + + int isBold = _pEditView->execute(SCI_STYLEGETBOLD, idStyle); + int isItalic = _pEditView->execute(SCI_STYLEGETITALIC, idStyle); + int isUnderline = _pEditView->execute(SCI_STYLEGETUNDERLINE, idStyle); + hotspotStyle._fontStyle = (isBold?FONTSTYLE_BOLD:0) | (isItalic?FONTSTYLE_ITALIC:0) | (isUnderline?FONTSTYLE_UNDERLINE:0); + + int fontStyle = (isBold?FONTSTYLE_BOLD:0) | (isItalic?FONTSTYLE_ITALIC:0) | (isUnderline?FONTSTYLE_UNDERLINE:0); + int urlAction = (NppParameters::getInstance())->getNppGUI()._styleURL; + if (urlAction == 2) + hotspotStyle._fontStyle |= FONTSTYLE_UNDERLINE; + + _pEditView->setStyle(hotspotStyle); + + _pEditView->execute(SCI_STYLESETHOTSPOT, style_hotspot, TRUE); + _pEditView->execute(SCI_SETHOTSPOTACTIVEFORE, TRUE, activeFG); + _pEditView->execute(SCI_SETHOTSPOTSINGLELINE, style_hotspot, 0); + _pEditView->execute(SCI_STARTSTYLING, start, 0x1F); + _pEditView->execute(SCI_SETSTYLING, foundTextLen, style_hotspot); + if (style_hotspot > 1) + style_hotspot--; + } + } + + _pEditView->execute(SCI_SETTARGETSTART, posFound + foundTextLen); + _pEditView->execute(SCI_SETTARGETEND, endPos); + + + posFound = _pEditView->execute(SCI_SEARCHINTARGET, strlen(urlHttpRegExpr), (LPARAM)urlHttpRegExpr); + } + + + _pEditView->execute(SCI_STARTSTYLING, endStyle, 0xFF); + _pEditView->execute(SCI_SETSTYLING, 0, 0); +} + + + +void Notepad_plus::MaintainIndentation(TCHAR ch) +{ + int eolMode = int(_pEditView->execute(SCI_GETEOLMODE)); + int curLine = int(_pEditView->getCurrentLineNumber()); + int lastLine = curLine - 1; + int indentAmount = 0; + + if (((eolMode == SC_EOL_CRLF || eolMode == SC_EOL_LF) && ch == '\n') || + (eolMode == SC_EOL_CR && ch == '\r')) + { + while (lastLine >= 0 && _pEditView->getLineLength(lastLine) == 0) + lastLine--; + + if (lastLine >= 0) { + indentAmount = _pEditView->getLineIndent(lastLine); + } + if (indentAmount > 0) { + _pEditView->setLineIndent(curLine, indentAmount); + } + } +} +void Notepad_plus::specialCmd(int id, int param) +{ + if ((param != 1) && (param != 2)) return; + + NppParameters *pNppParam = NppParameters::getInstance(); + ScintillaEditView *pEditView = (param == 1)?&_mainEditView:&_subEditView; + + switch (id) + { + case IDM_VIEW_LINENUMBER: + case IDM_VIEW_SYMBOLMARGIN: + //case IDM_VIEW_DOCCHANGEMARGIN: + case IDM_VIEW_FOLDERMAGIN: + { + int margin; + if (id == IDM_VIEW_LINENUMBER) + margin = ScintillaEditView::_SC_MARGE_LINENUMBER; + else if (id == IDM_VIEW_SYMBOLMARGIN) + margin = ScintillaEditView::_SC_MARGE_SYBOLE; + /* + else if (id == IDM_VIEW_DOCCHANGEMARGIN) + { + margin = ScintillaEditView::_SC_MARGE_MODIFMARKER; + } + */ + else + margin = ScintillaEditView::_SC_MARGE_FOLDER; + + if (pEditView->hasMarginShowed(margin)) + pEditView->showMargin(margin, false); + else + pEditView->showMargin(margin); + + break; + } + + case IDM_VIEW_FOLDERMAGIN_SIMPLE: + case IDM_VIEW_FOLDERMAGIN_ARROW: + case IDM_VIEW_FOLDERMAGIN_CIRCLE: + case IDM_VIEW_FOLDERMAGIN_BOX: + { + int checkedID = getFolderMarginStyle(); + if (checkedID == id) return; + folderStyle fStyle = (id == IDM_VIEW_FOLDERMAGIN_SIMPLE)?FOLDER_STYLE_SIMPLE:\ + ((id == IDM_VIEW_FOLDERMAGIN_ARROW)?FOLDER_STYLE_ARROW:\ + ((id == IDM_VIEW_FOLDERMAGIN_CIRCLE)?FOLDER_STYLE_CIRCLE:FOLDER_STYLE_BOX)); + pEditView->setMakerStyle(fStyle); + break; + } + + case IDM_VIEW_CURLINE_HILITING: + { + COLORREF colour = pNppParam->getCurLineHilitingColour(); + pEditView->setCurrentLineHiLiting(!_pEditView->isCurrentLineHiLiting(), colour); + break; + } + + case IDM_VIEW_EDGEBACKGROUND: + case IDM_VIEW_EDGELINE: + case IDM_VIEW_EDGENONE: + { + int mode; + switch (id) + { + case IDM_VIEW_EDGELINE: + { + mode = EDGE_LINE; + break; + } + case IDM_VIEW_EDGEBACKGROUND: + { + mode = EDGE_BACKGROUND; + break; + } + default : + mode = EDGE_NONE; + } + pEditView->execute(SCI_SETEDGEMODE, mode); + break; + } + + case IDM_SETTING_EDGE_SIZE : + { + ValueDlg nbColumnEdgeDlg; + ScintillaViewParams & svp = (ScintillaViewParams &)pNppParam->getSVP(param == 1?SCIV_PRIMARY:SCIV_SECOND); + nbColumnEdgeDlg.init(_hInst, _preference.getHSelf(), svp._edgeNbColumn, TEXT("Nb of column:")); + nbColumnEdgeDlg.setNBNumber(3); + + POINT p; + ::GetCursorPos(&p); + ::ScreenToClient(_hParent, &p); + int size = nbColumnEdgeDlg.doDialog(p, _isRTL); + + if (size != -1) + { + svp._edgeNbColumn = size; + pEditView->execute(SCI_SETEDGECOLUMN, size); + } + break; + } + } +} + +void Notepad_plus::command(int id) +{ + NppParameters *pNppParam = NppParameters::getInstance(); + switch (id) + { + case IDM_FILE_NEW: + { + fileNew(); + } + break; + + case IDM_FILE_OPEN: + fileOpen(); + break; + + case IDM_FILE_RELOAD: + fileReload(); + break; + + case IDM_FILE_CLOSE: + fileClose(); + break; + + case IDM_FILE_DELETE: + fileDelete(); + break; + + case IDM_FILE_RENAME: + fileRename(); + break; + + case IDM_FILE_CLOSEALL: + fileCloseAll(); + break; + + case IDM_FILE_CLOSEALL_BUT_CURRENT : + fileCloseAllButCurrent(); + break; + + case IDM_FILE_SAVE : + fileSave(); + break; + + case IDM_FILE_SAVEALL : + fileSaveAll(); + break; + + case IDM_FILE_SAVEAS : + fileSaveAs(); + break; + + case IDM_FILE_SAVECOPYAS : + fileSaveAs(BUFFER_INVALID, true); + break; + + case IDM_FILE_LOADSESSION: + fileLoadSession(); + break; + + case IDM_FILE_SAVESESSION: + fileSaveSession(); + break; + + case IDM_FILE_PRINTNOW : + filePrint(false); + break; + + case IDM_FILE_PRINT : + filePrint(true); + break; + + case IDM_FILE_EXIT: + ::SendMessage(_hSelf, WM_CLOSE, 0, 0); + break; + + case IDM_EDIT_UNDO: + _pEditView->execute(WM_UNDO); + checkClipboard(); + checkUndoState(); + break; + + case IDM_EDIT_REDO: + _pEditView->execute(SCI_REDO); + checkClipboard(); + checkUndoState(); + break; + + case IDM_EDIT_CUT: + _pEditView->execute(WM_CUT); + checkClipboard(); + break; + + case IDM_EDIT_COPY: + _pEditView->execute(WM_COPY); + checkClipboard(); + break; + + case IDM_EDIT_PASTE: + { + int eolMode = int(_pEditView->execute(SCI_GETEOLMODE)); + _pEditView->execute(SCI_PASTE); + _pEditView->execute(SCI_CONVERTEOLS, eolMode); + } + break; + + case IDM_EDIT_DELETE: + _pEditView->execute(WM_CLEAR); + break; + + case IDM_MACRO_STARTRECORDINGMACRO: + case IDM_MACRO_STOPRECORDINGMACRO: + case IDC_EDIT_TOGGLEMACRORECORDING: + { + //static HCURSOR originalCur; + + if (_recordingMacro) + { + // STOP !!! + _mainEditView.execute(SCI_STOPRECORD); + //_mainEditView.execute(SCI_ENDUNDOACTION); + _subEditView.execute(SCI_STOPRECORD); + //_subEditView.execute(SCI_ENDUNDOACTION); + + //::SetCursor(originalCur); + _mainEditView.execute(SCI_SETCURSOR, (LPARAM)SC_CURSORNORMAL); + _subEditView.execute(SCI_SETCURSOR, (LPARAM)SC_CURSORNORMAL); + + _recordingMacro = false; + _runMacroDlg.initMacroList(); + } + else + { + //originalCur = ::LoadCursor(_hInst, MAKEINTRESOURCE(IDC_MACRO_RECORDING)); + //::SetCursor(originalCur); + _mainEditView.execute(SCI_SETCURSOR, 9); + _subEditView.execute(SCI_SETCURSOR, 9); + _macro.clear(); + + // START !!! + _mainEditView.execute(SCI_STARTRECORD); + //_mainEditView.execute(SCI_BEGINUNDOACTION); + + _subEditView.execute(SCI_STARTRECORD); + //_subEditView.execute(SCI_BEGINUNDOACTION); + _recordingMacro = true; + } + checkMacroState(); + break; + } + + case IDM_MACRO_PLAYBACKRECORDEDMACRO: + if (!_recordingMacro) // if we're not currently recording, then playback the recorded keystrokes + { + _pEditView->execute(SCI_BEGINUNDOACTION); + + for (Macro::iterator step = _macro.begin(); step != _macro.end(); step++) + step->PlayBack(this, _pEditView); + + _pEditView->execute(SCI_ENDUNDOACTION); + } + break; + + case IDM_MACRO_RUNMULTIMACRODLG : + { + if (!_recordingMacro) // if we're not currently recording, then playback the recorded keystrokes + { + bool isFirstTime = !_runMacroDlg.isCreated(); + _runMacroDlg.doDialog(_isRTL); + + if (isFirstTime) + { + changeDlgLang(_runMacroDlg.getHSelf(), "MultiMacro"); + } + break; + + } + } + break; + + case IDM_MACRO_SAVECURRENTMACRO : + { + if (addCurrentMacro()) + _runMacroDlg.initMacroList(); + break; + } + case IDM_EDIT_FULLPATHTOCLIP : + case IDM_EDIT_CURRENTDIRTOCLIP : + case IDM_EDIT_FILENAMETOCLIP : + { + Buffer * buf = _pEditView->getCurrentBuffer(); + if (id == IDM_EDIT_FULLPATHTOCLIP) { + str2Cliboard(buf->getFullPathName()); + } else if (id == IDM_EDIT_CURRENTDIRTOCLIP) { + TCHAR dir[MAX_PATH]; + lstrcpy(dir, buf->getFullPathName()); + PathRemoveFileSpec((TCHAR *)dir); + str2Cliboard(dir); + } else if (id == IDM_EDIT_FILENAMETOCLIP) { + str2Cliboard(buf->getFileName()); + } + } + break; + + case IDM_SEARCH_FIND : + case IDM_SEARCH_REPLACE : + { + const int strSize = FINDREPLACE_MAXLENGTH; + TCHAR str[strSize]; + + bool isFirstTime = !_findReplaceDlg.isCreated(); + + _findReplaceDlg.doDialog((id == IDM_SEARCH_FIND)?FIND_DLG:REPLACE_DLG, _isRTL); + + _pEditView->getGenericSelectedText(str, strSize); + _findReplaceDlg.setSearchText(str); + setFindReplaceFolderFilter(NULL, NULL); + + if (isFirstTime) + changeFindReplaceDlgLang(); + break; + } + + case IDM_SEARCH_FINDINFILES : + { + ::SendMessage(_hSelf, NPPM_LAUNCHFINDINFILESDLG, 0, 0); + break; + } + case IDM_SEARCH_FINDINCREMENT : + { + const int strSize = FINDREPLACE_MAXLENGTH; + TCHAR str[strSize]; + + _pEditView->getGenericSelectedText(str, strSize); + _incrementFindDlg.setSearchText(str, _pEditView->getCurrentBuffer()->getUnicodeMode() != uni8Bit); + + _incrementFindDlg.display(); + } + break; + + case IDM_SEARCH_FINDNEXT : + case IDM_SEARCH_FINDPREV : + { + if (!_findReplaceDlg.isCreated()) + return; + + FindOption op = _findReplaceDlg.getCurrentOptions(); + op._whichDirection = (id == IDM_SEARCH_FINDNEXT?DIR_DOWN:DIR_UP); + generic_string s = _findReplaceDlg.getText2search(); + + _findReplaceDlg.processFindNext(s.c_str(), &op); + break; + } + break; + + case NPPM_INTERNAL_SEARCH_GOTONEXTFOUND: + { + _findReplaceDlg.gotoNextFoundResult(); + break; + } + case NPPM_INTERNAL_SEARCH_GOTOPREVFOUND: + { + _findReplaceDlg.gotoNextFoundResult(-1); + break; + } + case NPPM_INTERNAL_FOCUS_ON_FOUND_RESULTS: + { + if (GetFocus() == _findReplaceDlg.getHFindResults()) + // focus already on found results, switch to current edit view + switchEditViewTo(currentView()); + else + _findReplaceDlg.focusOnFinder(); + break; + } + case IDM_SEARCH_VOLATILE_FINDNEXT : + case IDM_SEARCH_VOLATILE_FINDPREV : + { + TCHAR text2Find[MAX_PATH]; + _pEditView->getGenericSelectedText(text2Find, MAX_PATH); + + FindOption op; + op._isWholeWord = false; + op._whichDirection = (id == IDM_SEARCH_VOLATILE_FINDNEXT?DIR_DOWN:DIR_UP); + _findReplaceDlg.processFindNext(text2Find, &op); + break; + } + + case IDM_SEARCH_MARKALLEXT1 : + case IDM_SEARCH_MARKALLEXT2 : + case IDM_SEARCH_MARKALLEXT3 : + case IDM_SEARCH_MARKALLEXT4 : + case IDM_SEARCH_MARKALLEXT5 : + { + int styleID; + if (id == IDM_SEARCH_MARKALLEXT1) + styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT1; + else if (id == IDM_SEARCH_MARKALLEXT2) + styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT2; + else if (id == IDM_SEARCH_MARKALLEXT3) + styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT3; + else if (id == IDM_SEARCH_MARKALLEXT4) + styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT4; + else // (id == IDM_SEARCH_MARKALLEXT5) + styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT5; + + const int strSize = FINDREPLACE_MAXLENGTH; + TCHAR text2Find[strSize]; + _pEditView->getGenericSelectedText(text2Find, strSize); + + _findReplaceDlg.markAll(text2Find, styleID); + + break; + } + case IDM_SEARCH_UNMARKALLEXT1 : + case IDM_SEARCH_UNMARKALLEXT2 : + case IDM_SEARCH_UNMARKALLEXT3 : + case IDM_SEARCH_UNMARKALLEXT4 : + case IDM_SEARCH_UNMARKALLEXT5 : + { + int styleID; + if (id == IDM_SEARCH_UNMARKALLEXT1) + styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT1; + else if (id == IDM_SEARCH_UNMARKALLEXT2) + styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT2; + else if (id == IDM_SEARCH_UNMARKALLEXT3) + styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT3; + else if (id == IDM_SEARCH_UNMARKALLEXT4) + styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT4; + else // (id == IDM_SEARCH_UNMARKALLEXT5) + styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT5; + + _pEditView->clearIndicator(styleID); + break; + } + + case IDM_SEARCH_CLEARALLMARKS : + { + _pEditView->clearIndicator(SCE_UNIVERSAL_FOUND_STYLE_EXT1); + _pEditView->clearIndicator(SCE_UNIVERSAL_FOUND_STYLE_EXT2); + _pEditView->clearIndicator(SCE_UNIVERSAL_FOUND_STYLE_EXT3); + _pEditView->clearIndicator(SCE_UNIVERSAL_FOUND_STYLE_EXT4); + _pEditView->clearIndicator(SCE_UNIVERSAL_FOUND_STYLE_EXT5); + break; + } + + case IDM_SEARCH_GOTOLINE : + { + bool isFirstTime = !_goToLineDlg.isCreated(); + _goToLineDlg.doDialog(_isRTL); + if (isFirstTime) + changeDlgLang(_goToLineDlg.getHSelf(), "GoToLine"); + break; + } + + case IDM_EDIT_COLUMNMODE : + { + bool isFirstTime = !_colEditorDlg.isCreated(); + _colEditorDlg.doDialog(_isRTL); + if (isFirstTime) + changeDlgLang(_colEditorDlg.getHSelf(), "ColumnEditor"); + break; + } + + case IDM_SEARCH_GOTOMATCHINGBRACE : + { + int braceAtCaret = -1; + int braceOpposite = -1; + findMatchingBracePos(braceAtCaret, braceOpposite); + + if (braceOpposite != -1) + _pEditView->execute(SCI_GOTOPOS, braceOpposite); + break; + } + + case IDM_SEARCH_TOGGLE_BOOKMARK : + bookmarkToggle(-1); + break; + + case IDM_SEARCH_NEXT_BOOKMARK: + bookmarkNext(true); + break; + + case IDM_SEARCH_PREV_BOOKMARK: + bookmarkNext(false); + break; + + case IDM_SEARCH_CLEAR_BOOKMARKS: + bookmarkClearAll(); + break; + + case IDM_VIEW_USER_DLG : + { + bool isUDDlgVisible = false; + + UserDefineDialog *udd = _pEditView->getUserDefineDlg(); + + if (!udd->isCreated()) + { + _pEditView->doUserDefineDlg(true, _isRTL); + changeUserDefineLang(); + if (_isUDDocked) + ::SendMessage(udd->getHSelf(), WM_COMMAND, IDC_DOCK_BUTTON, 0); + + } + else + { + isUDDlgVisible = udd->isVisible(); + bool isUDDlgDocked = udd->isDocked(); + + if ((isUDDlgDocked)&&(isUDDlgVisible)) + { + ::ShowWindow(_pMainSplitter->getHSelf(), SW_HIDE); + + if (bothActive()) + _pMainWindow = &_subSplitter; + else + _pMainWindow = _pDocTab; + + ::SendMessage(_hSelf, WM_SIZE, 0, 0); + + udd->display(false); + _mainWindowStatus &= ~WindowUserActive; + } + else if ((isUDDlgDocked)&&(!isUDDlgVisible)) + { + if (!_pMainSplitter) + { + _pMainSplitter = new SplitterContainer; + _pMainSplitter->init(_hInst, _hSelf); + + Window *pWindow; + if (bothActive()) + pWindow = &_subSplitter; + else + pWindow = _pDocTab; + + _pMainSplitter->create(pWindow, ScintillaEditView::getUserDefineDlg(), 8, RIGHT_FIX, 45); + } + + _pMainWindow = _pMainSplitter; + + _pMainSplitter->setWin0((bothActive())?(Window *)&_subSplitter:(Window *)_pDocTab); + + ::SendMessage(_hSelf, WM_SIZE, 0, 0); + _pMainWindow->display(); + + _mainWindowStatus |= WindowUserActive; + } + else if ((!isUDDlgDocked)&&(isUDDlgVisible)) + { + udd->display(false); + } + else //((!isUDDlgDocked)&&(!isUDDlgVisible)) + udd->display(); + } + checkMenuItem(IDM_VIEW_USER_DLG, !isUDDlgVisible); + _toolBar.setCheck(IDM_VIEW_USER_DLG, !isUDDlgVisible); + + break; + } + + case IDM_EDIT_SELECTALL: + _pEditView->execute(SCI_SELECTALL); + checkClipboard(); + break; + + case IDM_EDIT_INS_TAB: + _pEditView->execute(SCI_TAB); + break; + + case IDM_EDIT_RMV_TAB: + _pEditView->execute(SCI_BACKTAB); + break; + + case IDM_EDIT_DUP_LINE: + _pEditView->execute(SCI_LINEDUPLICATE); + break; + + case IDM_EDIT_SPLIT_LINES: + _pEditView->execute(SCI_TARGETFROMSELECTION); + _pEditView->execute(SCI_LINESSPLIT); + break; + + case IDM_EDIT_JOIN_LINES: + _pEditView->execute(SCI_TARGETFROMSELECTION); + _pEditView->execute(SCI_LINESJOIN); + break; + + case IDM_EDIT_LINE_UP: + _pEditView->currentLineUp(); + break; + + case IDM_EDIT_LINE_DOWN: + _pEditView->currentLineDown(); + break; + + case IDM_EDIT_UPPERCASE: + _pEditView->convertSelectedTextToUpperCase(); + break; + + case IDM_EDIT_LOWERCASE: + _pEditView->convertSelectedTextToLowerCase(); + break; + + case IDM_EDIT_BLOCK_COMMENT: + doBlockComment(cm_toggle); + break; + + case IDM_EDIT_BLOCK_COMMENT_SET: + doBlockComment(cm_comment); + break; + + case IDM_EDIT_BLOCK_UNCOMMENT: + doBlockComment(cm_uncomment); + break; + + case IDM_EDIT_STREAM_COMMENT: + doStreamComment(); + break; + + case IDM_EDIT_TRIMTRAILING: + doTrimTrailing(); + break; + + case IDM_EDIT_SETREADONLY: + { + Buffer * buf = _pEditView->getCurrentBuffer(); + buf->setUserReadOnly(!buf->getUserReadOnly()); + } + break; + + case IDM_EDIT_CLEARREADONLY: + { + Buffer * buf = _pEditView->getCurrentBuffer(); + + DWORD dwFileAttribs = ::GetFileAttributes(buf->getFullPathName()); + dwFileAttribs ^= FILE_ATTRIBUTE_READONLY; + + ::SetFileAttributes(buf->getFullPathName(), dwFileAttribs); + + buf->setFileReadOnly(false); + } + break; + + case IDM_SEARCH_CUTMARKEDLINES : + cutMarkedLines(); + break; + + case IDM_SEARCH_COPYMARKEDLINES : + copyMarkedLines(); + break; + + case IDM_SEARCH_PASTEMARKEDLINES : + pasteToMarkedLines(); + break; + + case IDM_SEARCH_DELETEMARKEDLINES : + deleteMarkedLines(); + break; + + case IDM_VIEW_FULLSCREENTOGGLE : + fullScreenToggle(); + break; + + case IDM_VIEW_ALWAYSONTOP: + { + int check = (::GetMenuState(_mainMenuHandle, id, MF_BYCOMMAND) == MF_CHECKED)?MF_UNCHECKED:MF_CHECKED; + ::CheckMenuItem(_mainMenuHandle, id, MF_BYCOMMAND | check); + SetWindowPos(_hSelf, check == MF_CHECKED?HWND_TOPMOST:HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); + } + break; + + + case IDM_VIEW_FOLD_CURRENT : + case IDM_VIEW_UNFOLD_CURRENT : + _pEditView->foldCurrentPos((id==IDM_VIEW_FOLD_CURRENT)?fold_collapse:fold_uncollapse); + break; + + case IDM_VIEW_TOGGLE_FOLDALL: + case IDM_VIEW_TOGGLE_UNFOLDALL: + { + _pEditView->foldAll((id==IDM_VIEW_TOGGLE_FOLDALL)?fold_collapse:fold_uncollapse); + } + break; + + case IDM_VIEW_FOLD_1: + case IDM_VIEW_FOLD_2: + case IDM_VIEW_FOLD_3: + case IDM_VIEW_FOLD_4: + case IDM_VIEW_FOLD_5: + case IDM_VIEW_FOLD_6: + case IDM_VIEW_FOLD_7: + case IDM_VIEW_FOLD_8: + _pEditView->collapse(id - IDM_VIEW_FOLD - 1, fold_collapse); + break; + + case IDM_VIEW_UNFOLD_1: + case IDM_VIEW_UNFOLD_2: + case IDM_VIEW_UNFOLD_3: + case IDM_VIEW_UNFOLD_4: + case IDM_VIEW_UNFOLD_5: + case IDM_VIEW_UNFOLD_6: + case IDM_VIEW_UNFOLD_7: + case IDM_VIEW_UNFOLD_8: + _pEditView->collapse(id - IDM_VIEW_UNFOLD - 1, fold_uncollapse); + break; + + + case IDM_VIEW_TOOLBAR_REDUCE: + { + toolBarStatusType state = _toolBar.getState(); + + if (state != TB_SMALL) + { + _toolBar.reduce(); + changeToolBarIcons(); + } + } + break; + + case IDM_VIEW_TOOLBAR_ENLARGE: + { + toolBarStatusType state = _toolBar.getState(); + + if (state != TB_LARGE) + { + _toolBar.enlarge(); + changeToolBarIcons(); + } + } + break; + + case IDM_VIEW_TOOLBAR_STANDARD: + { + toolBarStatusType state = _toolBar.getState(); + + if (state != TB_STANDARD) + { + _toolBar.setToUglyIcons(); + } + } + break; + + case IDM_VIEW_REDUCETABBAR : + { + _toReduceTabBar = !_toReduceTabBar; + + //Resize the icon + int iconSize = _toReduceTabBar?12:18; + + //Resize the tab height + int tabHeight = _toReduceTabBar?20:25; + TabCtrl_SetItemSize(_mainDocTab.getHSelf(), 45, tabHeight); + TabCtrl_SetItemSize(_subDocTab.getHSelf(), 45, tabHeight); + _docTabIconList.setIconSize(iconSize); + + //change the font + int stockedFont = _toReduceTabBar?DEFAULT_GUI_FONT:SYSTEM_FONT; + HFONT hf = (HFONT)::GetStockObject(stockedFont); + + if (hf) + { + ::SendMessage(_mainDocTab.getHSelf(), WM_SETFONT, (WPARAM)hf, MAKELPARAM(TRUE, 0)); + ::SendMessage(_subDocTab.getHSelf(), WM_SETFONT, (WPARAM)hf, MAKELPARAM(TRUE, 0)); + } + + ::SendMessage(_hSelf, WM_SIZE, 0, 0); + break; + } + + case IDM_VIEW_REFRESHTABAR : + { + ::SendMessage(_hSelf, WM_SIZE, 0, 0); + break; + } + case IDM_VIEW_LOCKTABBAR: + { + bool isDrag = TabBarPlus::doDragNDropOrNot(); + TabBarPlus::doDragNDrop(!isDrag); + //checkMenuItem(IDM_VIEW_LOCKTABBAR, isDrag); + break; + } + + + case IDM_VIEW_DRAWTABBAR_INACIVETAB: + { + TabBarPlus::setDrawInactiveTab(!TabBarPlus::drawInactiveTab()); + //TabBarPlus::setDrawInactiveTab(!TabBarPlus::drawInactiveTab(), _subDocTab.getHSelf()); + break; + } + case IDM_VIEW_DRAWTABBAR_TOPBAR: + { + TabBarPlus::setDrawTopBar(!TabBarPlus::drawTopBar()); + break; + } + + case IDM_VIEW_DRAWTABBAR_CLOSEBOTTUN : + { + TabBarPlus::setDrawTabCloseButton(!TabBarPlus::drawTabCloseButton()); + + // This part is just for updating (redraw) the tabs + { + int tabHeight = TabBarPlus::drawTabCloseButton()?21:20; + TabCtrl_SetItemSize(_mainDocTab.getHSelf(), 45, tabHeight); + TabCtrl_SetItemSize(_subDocTab.getHSelf(), 45, tabHeight); + } + ::SendMessage(_hSelf, WM_SIZE, 0, 0); + break; + } + + case IDM_VIEW_DRAWTABBAR_DBCLK2CLOSE : + { + TabBarPlus::setDbClk2Close(!TabBarPlus::isDbClk2Close()); + break; + } + + case IDM_VIEW_DRAWTABBAR_VERTICAL : + { + TabBarPlus::setVertical(!TabBarPlus::isVertical()); + ::SendMessage(_hSelf, WM_SIZE, 0, 0); + break; + } + + case IDM_VIEW_DRAWTABBAR_MULTILINE : + { + TabBarPlus::setMultiLine(!TabBarPlus::isMultiLine()); + ::SendMessage(_hSelf, WM_SIZE, 0, 0); + break; + } + + case IDM_VIEW_POSTIT : + { + postItToggle(); + } + break; + + case IDM_VIEW_TAB_SPACE: + { + bool isChecked = !(::GetMenuState(_mainMenuHandle, IDM_VIEW_TAB_SPACE, MF_BYCOMMAND) == MF_CHECKED); + ::CheckMenuItem(_mainMenuHandle, IDM_VIEW_EOL, MF_BYCOMMAND | MF_UNCHECKED); + ::CheckMenuItem(_mainMenuHandle, IDM_VIEW_ALL_CHARACTERS, MF_BYCOMMAND | MF_UNCHECKED); + ::CheckMenuItem(_mainMenuHandle, IDM_VIEW_TAB_SPACE, MF_BYCOMMAND | (isChecked?MF_CHECKED:MF_UNCHECKED)); + _toolBar.setCheck(IDM_VIEW_ALL_CHARACTERS, false); + _pEditView->showEOL(false); + _pEditView->showWSAndTab(isChecked); + break; + } + case IDM_VIEW_EOL: + { + bool isChecked = !(::GetMenuState(_mainMenuHandle, IDM_VIEW_EOL, MF_BYCOMMAND) == MF_CHECKED); + ::CheckMenuItem(_mainMenuHandle, IDM_VIEW_TAB_SPACE, MF_BYCOMMAND | MF_UNCHECKED); + ::CheckMenuItem(_mainMenuHandle, IDM_VIEW_EOL, MF_BYCOMMAND | (isChecked?MF_CHECKED:MF_UNCHECKED)); + ::CheckMenuItem(_mainMenuHandle, IDM_VIEW_ALL_CHARACTERS, MF_BYCOMMAND | MF_UNCHECKED); + _toolBar.setCheck(IDM_VIEW_ALL_CHARACTERS, false); + _pEditView->showEOL(isChecked); + _pEditView->showWSAndTab(false); + break; + } + case IDM_VIEW_ALL_CHARACTERS: + { + bool isChecked = !(::GetMenuState(_mainMenuHandle, id, MF_BYCOMMAND) == MF_CHECKED); + ::CheckMenuItem(_mainMenuHandle, IDM_VIEW_EOL, MF_BYCOMMAND | MF_UNCHECKED); + ::CheckMenuItem(_mainMenuHandle, IDM_VIEW_TAB_SPACE, MF_BYCOMMAND | MF_UNCHECKED); + ::CheckMenuItem(_mainMenuHandle, IDM_VIEW_ALL_CHARACTERS, MF_BYCOMMAND | (isChecked?MF_CHECKED:MF_UNCHECKED)); + _pEditView->showInvisibleChars(isChecked); + _toolBar.setCheck(IDM_VIEW_ALL_CHARACTERS, isChecked); + break; + } + + case IDM_VIEW_INDENT_GUIDE: + { + _pEditView->showIndentGuideLine(!_pEditView->isShownIndentGuide()); + _toolBar.setCheck(IDM_VIEW_INDENT_GUIDE, _pEditView->isShownIndentGuide()); + checkMenuItem(IDM_VIEW_INDENT_GUIDE, _pEditView->isShownIndentGuide()); + break; + } + + case IDM_VIEW_WRAP: + { + bool isWraped = !_pEditView->isWrap(); + _pEditView->wrap(isWraped); + _toolBar.setCheck(IDM_VIEW_WRAP, isWraped); + checkMenuItem(IDM_VIEW_WRAP, isWraped); + break; + } + case IDM_VIEW_WRAP_SYMBOL: + { + _pEditView->showWrapSymbol(!_pEditView->isWrapSymbolVisible()); + checkMenuItem(IDM_VIEW_WRAP_SYMBOL, _pEditView->isWrapSymbolVisible()); + break; + } + + case IDM_VIEW_HIDELINES: + { + _pEditView->hideLines(); + break; + } + + case IDM_VIEW_ZOOMIN: + { + _pEditView->execute(SCI_ZOOMIN); + break; + } + case IDM_VIEW_ZOOMOUT: + _pEditView->execute(SCI_ZOOMOUT); + break; + + case IDM_VIEW_ZOOMRESTORE: + //Zoom factor of 0 points means default view + _pEditView->execute(SCI_SETZOOM, 0);//_zoomOriginalValue); + break; + + case IDM_VIEW_SYNSCROLLV: + { + _syncInfo._isSynScollV = !_syncInfo._isSynScollV; + checkMenuItem(IDM_VIEW_SYNSCROLLV, _syncInfo._isSynScollV); + _toolBar.setCheck(IDM_VIEW_SYNSCROLLV, _syncInfo._isSynScollV); + + if (_syncInfo._isSynScollV) + { + int mainCurrentLine = _mainEditView.execute(SCI_GETFIRSTVISIBLELINE); + int subCurrentLine = _subEditView.execute(SCI_GETFIRSTVISIBLELINE); + _syncInfo._line = mainCurrentLine - subCurrentLine; + } + + } + break; + + case IDM_VIEW_SYNSCROLLH: + { + _syncInfo._isSynScollH = !_syncInfo._isSynScollH; + checkMenuItem(IDM_VIEW_SYNSCROLLH, _syncInfo._isSynScollH); + _toolBar.setCheck(IDM_VIEW_SYNSCROLLH, _syncInfo._isSynScollH); + + if (_syncInfo._isSynScollH) + { + int mxoffset = _mainEditView.execute(SCI_GETXOFFSET); + int pixel = int(_mainEditView.execute(SCI_TEXTWIDTH, STYLE_DEFAULT, (LPARAM)"P")); + int mainColumn = mxoffset/pixel; + + int sxoffset = _subEditView.execute(SCI_GETXOFFSET); + pixel = int(_subEditView.execute(SCI_TEXTWIDTH, STYLE_DEFAULT, (LPARAM)"P")); + int subColumn = sxoffset/pixel; + _syncInfo._column = mainColumn - subColumn; + } + } + break; + + case IDM_EXECUTE: + { + bool isFirstTime = !_runDlg.isCreated(); + _runDlg.doDialog(_isRTL); + if (isFirstTime) + changeDlgLang(_runDlg.getHSelf(), "Run"); + + break; + } + + case IDM_FORMAT_TODOS : + case IDM_FORMAT_TOUNIX : + case IDM_FORMAT_TOMAC : + { + Buffer * buf = _pEditView->getCurrentBuffer(); + + int f = int((id == IDM_FORMAT_TODOS)?SC_EOL_CRLF:(id == IDM_FORMAT_TOUNIX)?SC_EOL_LF:SC_EOL_CR); + + buf->setFormat((formatType)f); + _pEditView->execute(SCI_CONVERTEOLS, buf->getFormat()); + break; + } + + case IDM_FORMAT_ANSI : + case IDM_FORMAT_UTF_8 : + case IDM_FORMAT_UCS_2BE : + case IDM_FORMAT_UCS_2LE : + case IDM_FORMAT_AS_UTF_8 : + { + Buffer * buf = _pEditView->getCurrentBuffer(); + + UniMode um; + bool shoulBeDirty = true; + switch (id) + { + case IDM_FORMAT_AS_UTF_8: + shoulBeDirty = buf->getUnicodeMode() != uni8Bit; + um = uniCookie; + break; + + case IDM_FORMAT_UTF_8: + um = uniUTF8; + break; + + case IDM_FORMAT_UCS_2BE: + um = uni16BE; + break; + + case IDM_FORMAT_UCS_2LE: + um = uni16LE; + break; + + default : // IDM_FORMAT_ANSI + shoulBeDirty = buf->getUnicodeMode() != uniCookie; + um = uni8Bit; + } + + if (buf->getUnicodeMode() != um) + { + buf->setUnicodeMode(um); + if (shoulBeDirty) + buf->setDirty(true); + } + break; + } + + case IDM_FORMAT_CONV2_ANSI: + case IDM_FORMAT_CONV2_AS_UTF_8: + case IDM_FORMAT_CONV2_UTF_8: + case IDM_FORMAT_CONV2_UCS_2BE: + case IDM_FORMAT_CONV2_UCS_2LE: + { + int idEncoding = -1; + UniMode um = _pEditView->getCurrentBuffer()->getUnicodeMode(); + + switch(id) + { + case IDM_FORMAT_CONV2_ANSI: + { + if (um == uni8Bit) + return; + + idEncoding = IDM_FORMAT_ANSI; + break; + } + case IDM_FORMAT_CONV2_AS_UTF_8: + { + idEncoding = IDM_FORMAT_AS_UTF_8; + if (um == uniCookie) + return; + + if (um != uni8Bit) + { + ::SendMessage(_hSelf, WM_COMMAND, idEncoding, 0); + _pEditView->execute(SCI_EMPTYUNDOBUFFER); + return; + } + + break; + } + case IDM_FORMAT_CONV2_UTF_8: + { + idEncoding = IDM_FORMAT_UTF_8; + if (um == uniUTF8) + return; + + if (um != uni8Bit) + { + ::SendMessage(_hSelf, WM_COMMAND, idEncoding, 0); + _pEditView->execute(SCI_EMPTYUNDOBUFFER); + return; + } + break; + } + + case IDM_FORMAT_CONV2_UCS_2BE: + { + idEncoding = IDM_FORMAT_UCS_2BE; + if (um == uni16BE) + return; + + if (um != uni8Bit) + { + ::SendMessage(_hSelf, WM_COMMAND, idEncoding, 0); + _pEditView->execute(SCI_EMPTYUNDOBUFFER); + return; + } + break; + } + + case IDM_FORMAT_CONV2_UCS_2LE: + { + idEncoding = IDM_FORMAT_UCS_2LE; + if (um == uni16LE) + return; + if (um != uni8Bit) + { + ::SendMessage(_hSelf, WM_COMMAND, idEncoding, 0); + _pEditView->execute(SCI_EMPTYUNDOBUFFER); + return; + } + break; + } + } + + if (idEncoding != -1) + { + // Save the current clipboard content + ::OpenClipboard(_hSelf); + HANDLE clipboardData = ::GetClipboardData(CF_TEXT); + int len = ::GlobalSize(clipboardData); + LPVOID clipboardDataPtr = ::GlobalLock(clipboardData); + + HANDLE allocClipboardData = ::GlobalAlloc(GMEM_MOVEABLE, len); + LPVOID clipboardData2 = ::GlobalLock(allocClipboardData); + + ::memcpy(clipboardData2, clipboardDataPtr, len); + ::GlobalUnlock(clipboardData); + ::GlobalUnlock(allocClipboardData); + ::CloseClipboard(); + + _pEditView->saveCurrentPos(); + + // Cut all text + int docLen = _pEditView->getCurrentDocLen(); + _pEditView->execute(SCI_COPYRANGE, 0, docLen); + _pEditView->execute(SCI_CLEARALL); + + // Change to the proper buffer, save buffer status + + ::SendMessage(_hSelf, WM_COMMAND, idEncoding, 0); + + // Paste the texte, restore buffer status + _pEditView->execute(SCI_PASTE); + _pEditView->restoreCurrentPos(); + + // Restore the previous clipboard data + ::OpenClipboard(_hSelf); + ::EmptyClipboard(); + ::SetClipboardData(CF_TEXT, clipboardData2); + ::CloseClipboard(); + + //Do not free anything, EmptyClipboard does that + _pEditView->execute(SCI_EMPTYUNDOBUFFER); + } + break; + } + + case IDM_SETTING_TAB_REPLCESPACE: + { + NppGUI & nppgui = (NppGUI &)(pNppParam->getNppGUI()); + nppgui._tabReplacedBySpace = !nppgui._tabReplacedBySpace; + _pEditView->execute(SCI_SETUSETABS, !nppgui._tabReplacedBySpace); + //checkMenuItem(IDM_SETTING_TAB_REPLCESPACE, nppgui._tabReplacedBySpace); + break; + } + + case IDM_SETTING_TAB_SIZE: + { + ValueDlg tabSizeDlg; + NppGUI & nppgui = (NppGUI &)(pNppParam->getNppGUI()); + tabSizeDlg.init(_hInst, _preference.getHSelf(), nppgui._tabSize, TEXT("Tab Size : ")); + POINT p; + ::GetCursorPos(&p); + ::ScreenToClient(_hParent, &p); + int size = tabSizeDlg.doDialog(p, _isRTL); + if (size != -1) + { + nppgui._tabSize = size; + _pEditView->execute(SCI_SETTABWIDTH, nppgui._tabSize); + } + + break; + } + + case IDM_SETTING_AUTOCNBCHAR: + { + const int NB_MIN_CHAR = 1; + const int NB_MAX_CHAR = 9; + + ValueDlg valDlg; + NppGUI & nppGUI = (NppGUI &)((NppParameters::getInstance())->getNppGUI()); + valDlg.init(_hInst, _preference.getHSelf(), nppGUI._autocFromLen, TEXT("Nb char : ")); + POINT p; + ::GetCursorPos(&p); + ::ScreenToClient(_hParent, &p); + int size = valDlg.doDialog(p, _isRTL); + + if (size != -1) + { + if (size > NB_MAX_CHAR) + size = NB_MAX_CHAR; + else if (size < NB_MIN_CHAR) + size = NB_MIN_CHAR; + + nppGUI._autocFromLen = size; + } + break; + } + + case IDM_SETTING_HISTORY_SIZE : + { + ValueDlg nbHistoryDlg; + NppParameters *pNppParam = NppParameters::getInstance(); + nbHistoryDlg.init(_hInst, _preference.getHSelf(), pNppParam->getNbMaxFile(), TEXT("Max File : ")); + POINT p; + ::GetCursorPos(&p); + ::ScreenToClient(_hParent, &p); + int size = nbHistoryDlg.doDialog(p, _isRTL); + + if (size != -1) + { + if (size > NB_MAX_LRF_FILE) + size = NB_MAX_LRF_FILE; + pNppParam->setNbMaxFile(size); + _lastRecentFileList.setUserMaxNbLRF(size); + } + break; + } + + case IDM_SETTING_FILEASSOCIATION_DLG : + { + RegExtDlg regExtDlg; + regExtDlg.init(_hInst, _hSelf); + regExtDlg.doDialog(_isRTL); + break; + } + + case IDM_SETTING_SHORTCUT_MAPPER : + { + ShortcutMapper shortcutMapper; + shortcutMapper.init(_hInst, _hSelf); + changeShortcutmapperLang(&shortcutMapper); + shortcutMapper.doDialog(_isRTL); + shortcutMapper.destroy(); + break; + } + + case IDM_SETTING_PREFERECE : + { + bool isFirstTime = !_preference.isCreated(); + _preference.doDialog(_isRTL); + + if (isFirstTime) + { + changePrefereceDlgLang(); + } + break; + } + + case IDM_VIEW_GOTO_ANOTHER_VIEW: + docGotoAnotherEditView(TransferMove); + checkSyncState(); + break; + + case IDM_VIEW_CLONE_TO_ANOTHER_VIEW: + docGotoAnotherEditView(TransferClone); + checkSyncState(); + break; + + case IDM_VIEW_GOTO_NEW_INSTANCE : + docOpenInNewInstance(TransferMove); + break; + + case IDM_VIEW_LOAD_IN_NEW_INSTANCE: + docOpenInNewInstance(TransferClone); + break; + + case IDM_VIEW_SWITCHTO_OTHER_VIEW: + { + int view_to_focus; + HWND wnd = GetFocus(); + if (_pEditView->getHSelf() == wnd) + { + view_to_focus = otherView(); + if (!viewVisible(view_to_focus)) view_to_focus = _activeView; + } + else + { + view_to_focus = currentView(); + } + switchEditViewTo(view_to_focus); + break; + } + + case IDM_ABOUT: + { + bool isFirstTime = !_aboutDlg.isCreated(); + _aboutDlg.doDialog(); + if (isFirstTime && _nativeLangA) + { + const char *lang = (_nativeLangA->ToElement())->Attribute("name"); + + if (_nativeLangEncoding == CP_BIG5) + { + char *authorName = "«J¤µ§^"; + HWND hItem = ::GetDlgItem(_aboutDlg.getHSelf(), IDC_AUTHOR_NAME); +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + const wchar_t *authorNameW = wmc->char2wchar(authorName, CP_BIG5); + ::SetWindowText(hItem, authorNameW); +#else + ::SetWindowText(hItem, authorName); +#endif + } + } + break; + } + + case IDM_HELP : + { + TCHAR tmp[MAX_PATH]; + lstrcpy(tmp, _nppPath); + ::PathRemoveFileSpec(tmp); + + generic_string nppHelpPath = tmp; + nppHelpPath += TEXT("\\NppHelp.chm"); + if (::PathFileExists(nppHelpPath.c_str())) + ::ShellExecute(NULL, TEXT("open"), nppHelpPath.c_str(), NULL, NULL, SW_SHOWNORMAL); + else + { + generic_string msg = nppHelpPath; + msg += TEXT("\rdoesn't exist. Please download it on Notepad++ site."); + ::MessageBox(_hSelf, msg.c_str(), TEXT("File does not exist"), MB_OK); + } + } + break; + + case IDM_HOMESWEETHOME : + { + ::ShellExecute(NULL, TEXT("open"), TEXT("http://notepad-plus.sourceforge.net/"), NULL, NULL, SW_SHOWNORMAL); + break; + } + case IDM_PROJECTPAGE : + { + ::ShellExecute(NULL, TEXT("open"), TEXT("http://sourceforge.net/projects/notepad-plus/"), NULL, NULL, SW_SHOWNORMAL); + break; + } + + case IDM_ONLINEHELP: + { + ::ShellExecute(NULL, TEXT("open"), TEXT("http://notepad-plus.sourceforge.net/uk/generalFAQ.php"), NULL, NULL, SW_SHOWNORMAL); + break; + } + + case IDM_WIKIFAQ: + { + ::ShellExecute(NULL, TEXT("open"), TEXT("http://notepad-plus.wiki.sourceforge.net/FAQ"), NULL, NULL, SW_SHOWNORMAL); + break; + } + + case IDM_FORUM: + { + ::ShellExecute(NULL, TEXT("open"), TEXT("http://sourceforge.net/forum/?group_id=95717"), NULL, NULL, SW_SHOWNORMAL); + break; + } + + case IDM_PLUGINSHOME: + { + ::ShellExecute(NULL, TEXT("open"), TEXT("https://sourceforge.net/projects/npp-plugins/"), NULL, NULL, SW_SHOWNORMAL); + break; + } + + case IDM_UPDATE_NPP : + { + generic_string updaterDir = pNppParam->getNppPath(); + updaterDir += TEXT("\\updater\\"); + generic_string updaterFullPath = updaterDir + TEXT("gup.exe"); + generic_string param = TEXT("-verbose -v"); + param += VERSION_VALUE; + Process updater(updaterFullPath.c_str(), param.c_str(), updaterDir.c_str()); + updater.run(); + break; + } + + case IDM_EDIT_AUTOCOMPLETE : + showAutoComp(); + break; + + case IDM_EDIT_AUTOCOMPLETE_CURRENTFILE : + autoCompFromCurrentFile(); + break; + + case IDM_EDIT_FUNCCALLTIP : + showFunctionComp(); + break; + + case IDM_LANGSTYLE_CONFIG_DLG : + { + bool isFirstTime = !_configStyleDlg.isCreated(); + _configStyleDlg.doDialog(_isRTL); + if (isFirstTime) + changeConfigLang(); + break; + } + + case IDM_LANG_C : + case IDM_LANG_CPP : + case IDM_LANG_JAVA : + case IDM_LANG_CS : + case IDM_LANG_HTML : + case IDM_LANG_XML : + case IDM_LANG_JS : + case IDM_LANG_PHP : + case IDM_LANG_ASP : + case IDM_LANG_CSS : + case IDM_LANG_LUA : + case IDM_LANG_PERL : + case IDM_LANG_PYTHON : + case IDM_LANG_PASCAL : + case IDM_LANG_BATCH : + case IDM_LANG_OBJC : + case IDM_LANG_VB : + case IDM_LANG_SQL : + case IDM_LANG_ASCII : + case IDM_LANG_TEXT : + case IDM_LANG_RC : + case IDM_LANG_MAKEFILE : + case IDM_LANG_INI : + case IDM_LANG_TEX : + case IDM_LANG_FORTRAN : + case IDM_LANG_SH : + case IDM_LANG_FLASH : + case IDM_LANG_NSIS : + case IDM_LANG_TCL : + case IDM_LANG_LISP : + case IDM_LANG_SCHEME : + case IDM_LANG_ASM : + case IDM_LANG_DIFF : + case IDM_LANG_PROPS : + case IDM_LANG_PS: + case IDM_LANG_RUBY: + case IDM_LANG_SMALLTALK: + case IDM_LANG_VHDL : + case IDM_LANG_KIX : + case IDM_LANG_CAML : + case IDM_LANG_ADA : + case IDM_LANG_VERILOG : + case IDM_LANG_MATLAB : + case IDM_LANG_HASKELL : + case IDM_LANG_AU3 : + case IDM_LANG_INNO : + case IDM_LANG_CMAKE : + case IDM_LANG_YAML : + case IDM_LANG_USER : + { + setLanguage(id, menuID2LangType(id)); + } + break; + + case IDC_PREV_DOC : + case IDC_NEXT_DOC : + { + int nbDoc = viewVisible(MAIN_VIEW)?_mainDocTab.nbItem():0; + nbDoc += viewVisible(SUB_VIEW)?_subDocTab.nbItem():0; + + bool doTaskList = ((NppParameters::getInstance())->getNppGUI())._doTaskList; + if (nbDoc > 1) + { + bool direction = (id == IDC_NEXT_DOC)?dirDown:dirUp; + + if (!doTaskList) + { + activateNextDoc(direction); + } + else + { + TaskListDlg tld; + HIMAGELIST hImgLst = _docTabIconList.getHandle(); + tld.init(_hInst, _hSelf, hImgLst, direction); + tld.doDialog(); + } + } + _linkTriggered = true; + } + break; + + case IDM_OPEN_ALL_RECENT_FILE : { + BufferID lastOne = BUFFER_INVALID; + int size = _lastRecentFileList.getSize(); + for (int i = size - 1; i >= 0; i--) + { + BufferID test = doOpen(_lastRecentFileList.getIndex(i).c_str()); + if (test != BUFFER_INVALID) + lastOne = test; + } + if (lastOne != BUFFER_INVALID) { + switchToFile(lastOne); + } + break; } + + case IDM_CLEAN_RECENT_FILE_LIST : + _lastRecentFileList.clear(); + break; + + case IDM_EDIT_RTL : + case IDM_EDIT_LTR : + { + long exStyle = ::GetWindowLongPtr(_pEditView->getHSelf(), GWL_EXSTYLE); + exStyle = (id == IDM_EDIT_RTL)?exStyle|WS_EX_LAYOUTRTL:exStyle&(~WS_EX_LAYOUTRTL); + ::SetWindowLongPtr(_pEditView->getHSelf(), GWL_EXSTYLE, exStyle); + _pEditView->redraw(); + } + break; + + case IDM_WINDOW_WINDOWS : + { + WindowsDlg _windowsDlg; + _windowsDlg.init(_hInst, _hSelf, _pDocTab); + + TiXmlNodeA *dlgNode = NULL; + if (_nativeLangA) + { + dlgNode = _nativeLangA->FirstChild("Dialog"); + if (dlgNode) + dlgNode = searchDlgNode(dlgNode, "Window"); + } + _windowsDlg.doDialog(dlgNode); + } + break; + + default : + if (id > IDM_FILEMENU_LASTONE && id < (IDM_FILEMENU_LASTONE + _lastRecentFileList.getMaxNbLRF() + 1)) + { + BufferID lastOpened = doOpen(_lastRecentFileList.getItem(id).c_str()); + if (lastOpened != BUFFER_INVALID) { + switchToFile(lastOpened); + } + } + else if ((id > IDM_LANG_USER) && (id < IDM_LANG_USER_LIMIT)) + { + TCHAR langName[langNameLenMax]; + ::GetMenuString(_mainMenuHandle, id, langName, langNameLenMax, MF_BYCOMMAND); + _pEditView->getCurrentBuffer()->setLangType(L_USER, langName); + } + else if ((id >= IDM_LANG_EXTERNAL) && (id <= IDM_LANG_EXTERNAL_LIMIT)) + { + setLanguage(id, (LangType)(id - IDM_LANG_EXTERNAL + L_EXTERNAL)); + } + else if ((id >= ID_MACRO) && (id < ID_MACRO_LIMIT)) + { + int i = id - ID_MACRO; + vector & theMacros = pNppParam->getMacroList(); + Macro macro = theMacros[i].getMacro(); + _pEditView->execute(SCI_BEGINUNDOACTION); + + for (Macro::iterator step = macro.begin(); step != macro.end(); step++) + step->PlayBack(this, _pEditView); + + _pEditView->execute(SCI_ENDUNDOACTION); + + } + else if ((id >= ID_USER_CMD) && (id < ID_USER_CMD_LIMIT)) + { + int i = id - ID_USER_CMD; + vector & theUserCommands = pNppParam->getUserCommandList(); + UserCommand ucmd = theUserCommands[i]; + + Command cmd(ucmd.getCmd()); + cmd.run(_hSelf); + } + else if ((id >= ID_PLUGINS_CMD) && (id < ID_PLUGINS_CMD_LIMIT)) + { + int i = id - ID_PLUGINS_CMD; + _pluginsManager.runPluginCommand(i); + } + else if ((id >= IDM_WINDOW_MRU_FIRST) && (id <= IDM_WINDOW_MRU_LIMIT)) + { + activateDoc(id-IDM_WINDOW_MRU_FIRST); + } + } + + if (_recordingMacro) + switch (id) + { + case IDM_FILE_NEW : + case IDM_FILE_CLOSE : + case IDM_FILE_CLOSEALL : + case IDM_FILE_CLOSEALL_BUT_CURRENT : + case IDM_FILE_SAVE : + case IDM_FILE_SAVEALL : + case IDM_EDIT_UNDO: + case IDM_EDIT_REDO: + case IDM_EDIT_CUT: + case IDM_EDIT_COPY: + //case IDM_EDIT_PASTE: + case IDM_EDIT_DELETE: + case IDM_SEARCH_FINDNEXT : + case IDM_SEARCH_FINDPREV : + case IDM_SEARCH_GOTOMATCHINGBRACE : + case IDM_SEARCH_TOGGLE_BOOKMARK : + case IDM_SEARCH_NEXT_BOOKMARK: + case IDM_SEARCH_PREV_BOOKMARK: + case IDM_SEARCH_CLEAR_BOOKMARKS: + case IDM_EDIT_SELECTALL: + case IDM_EDIT_INS_TAB: + case IDM_EDIT_RMV_TAB: + case IDM_EDIT_DUP_LINE: + case IDM_EDIT_TRANSPOSE_LINE: + case IDM_EDIT_SPLIT_LINES: + case IDM_EDIT_JOIN_LINES: + case IDM_EDIT_LINE_UP: + case IDM_EDIT_LINE_DOWN: + case IDM_EDIT_UPPERCASE: + case IDM_EDIT_LOWERCASE: + case IDM_EDIT_BLOCK_COMMENT: + case IDM_EDIT_BLOCK_COMMENT_SET: + case IDM_EDIT_BLOCK_UNCOMMENT: + case IDM_EDIT_STREAM_COMMENT: + case IDM_EDIT_TRIMTRAILING: + case IDM_EDIT_SETREADONLY : + case IDM_EDIT_FULLPATHTOCLIP : + case IDM_EDIT_FILENAMETOCLIP : + case IDM_EDIT_CURRENTDIRTOCLIP : + case IDM_EDIT_CLEARREADONLY : + case IDM_EDIT_RTL : + case IDM_EDIT_LTR : + case IDM_VIEW_FULLSCREENTOGGLE : + case IDM_VIEW_ALWAYSONTOP : + case IDM_VIEW_WRAP : + case IDM_VIEW_FOLD_CURRENT : + case IDM_VIEW_UNFOLD_CURRENT : + case IDM_VIEW_TOGGLE_FOLDALL: + case IDM_VIEW_TOGGLE_UNFOLDALL: + case IDM_VIEW_FOLD_1: + case IDM_VIEW_FOLD_2: + case IDM_VIEW_FOLD_3: + case IDM_VIEW_FOLD_4: + case IDM_VIEW_FOLD_5: + case IDM_VIEW_FOLD_6: + case IDM_VIEW_FOLD_7: + case IDM_VIEW_FOLD_8: + case IDM_VIEW_UNFOLD_1: + case IDM_VIEW_UNFOLD_2: + case IDM_VIEW_UNFOLD_3: + case IDM_VIEW_UNFOLD_4: + case IDM_VIEW_UNFOLD_5: + case IDM_VIEW_UNFOLD_6: + case IDM_VIEW_UNFOLD_7: + case IDM_VIEW_UNFOLD_8: + case IDM_VIEW_GOTO_ANOTHER_VIEW: + case IDM_VIEW_SYNSCROLLV: + case IDM_VIEW_SYNSCROLLH: + case IDC_PREV_DOC : + case IDC_NEXT_DOC : + _macro.push_back(recordedMacroStep(id)); + break; + } + +} + +void Notepad_plus::setLanguage(int id, LangType langType) { + //Add logic to prevent changing a language when a document is shared between two views + //If so, release one document + bool reset = false; + Document prev = 0; + if (bothActive()) { + if (_mainEditView.getCurrentBufferID() == _subEditView.getCurrentBufferID()) { + reset = true; + _subEditView.saveCurrentPos(); + prev = _subEditView.execute(SCI_GETDOCPOINTER); + _subEditView.execute(SCI_SETDOCPOINTER, 0, 0); + } + } + if (reset) { + _mainEditView.getCurrentBuffer()->setLangType(langType); + } else { + _pEditView->getCurrentBuffer()->setLangType(langType); + } + + if (reset) { + _subEditView.execute(SCI_SETDOCPOINTER, 0, prev); + _subEditView.restoreCurrentPos(); + } +}; + +enum LangType Notepad_plus::menuID2LangType(int cmdID) +{ + switch (cmdID) + { + case IDM_LANG_C : + return L_C; + case IDM_LANG_CPP : + return L_CPP; + case IDM_LANG_JAVA : + return L_JAVA; + case IDM_LANG_CS : + return L_CS; + case IDM_LANG_HTML : + return L_HTML; + case IDM_LANG_XML : + return L_XML; + case IDM_LANG_JS : + return L_JS; + case IDM_LANG_PHP : + return L_PHP; + case IDM_LANG_ASP : + return L_ASP; + case IDM_LANG_CSS : + return L_CSS; + case IDM_LANG_LUA : + return L_LUA; + case IDM_LANG_PERL : + return L_PERL; + case IDM_LANG_PYTHON : + return L_PYTHON; + case IDM_LANG_PASCAL : + return L_PASCAL; + case IDM_LANG_BATCH : + return L_BATCH; + case IDM_LANG_OBJC : + return L_OBJC; + case IDM_LANG_VB : + return L_VB; + case IDM_LANG_SQL : + return L_SQL; + case IDM_LANG_ASCII : + return L_NFO; + case IDM_LANG_TEXT : + return L_TXT; + case IDM_LANG_RC : + return L_RC; + case IDM_LANG_MAKEFILE : + return L_MAKEFILE; + case IDM_LANG_INI : + return L_INI; + case IDM_LANG_TEX : + return L_TEX; + case IDM_LANG_FORTRAN : + return L_FORTRAN; + case IDM_LANG_SH : + return L_BASH; + case IDM_LANG_FLASH : + return L_FLASH; + case IDM_LANG_NSIS : + return L_NSIS; + case IDM_LANG_TCL : + return L_TCL; + case IDM_LANG_LISP : + return L_LISP; + case IDM_LANG_SCHEME : + return L_SCHEME; + case IDM_LANG_ASM : + return L_ASM; + case IDM_LANG_DIFF : + return L_DIFF; + case IDM_LANG_PROPS : + return L_PROPS; + case IDM_LANG_PS: + return L_PS; + case IDM_LANG_RUBY: + return L_RUBY; + case IDM_LANG_SMALLTALK: + return L_SMALLTALK; + case IDM_LANG_VHDL : + return L_VHDL; + case IDM_LANG_KIX : + return L_KIX; + case IDM_LANG_CAML : + return L_CAML; + case IDM_LANG_ADA : + return L_ADA; + case IDM_LANG_VERILOG : + return L_VERILOG; + case IDM_LANG_MATLAB : + return L_MATLAB; + case IDM_LANG_HASKELL : + return L_HASKELL; + case IDM_LANG_AU3 : + return L_AU3; + case IDM_LANG_INNO : + return L_INNO; + case IDM_LANG_CMAKE : + return L_CMAKE; + case IDM_LANG_YAML : + return L_YAML; + case IDM_LANG_USER : + return L_USER; + default: { + if (cmdID >= IDM_LANG_USER && cmdID <= IDM_LANG_USER_LIMIT) { + return L_USER; + } + break; } + } + return L_EXTERNAL; +} + +void Notepad_plus::setTitle() +{ + const NppGUI & nppGUI = NppParameters::getInstance()->getNppGUI(); + //Get the buffer + Buffer * buf = _pEditView->getCurrentBuffer(); + + generic_string result = TEXT(""); + if (buf->isDirty()) + { + result += TEXT("*"); + } + + if (nppGUI._shortTitlebar) + { + result += buf->getFileName(); + } + else + { + result += buf->getFullPathName(); + } + result += TEXT(" - "); + result += _className; + //::SetWindowText(_hSelf, title); + ::SendMessage(_hSelf, WM_SETTEXT, 0, (LPARAM)result.c_str()); + +} + +void Notepad_plus::activateNextDoc(bool direction) +{ + int nbDoc = _pDocTab->nbItem(); + + int curIndex = _pDocTab->getCurrentTabIndex(); + curIndex += (direction == dirUp)?-1:1; + + if (curIndex >= nbDoc) + { + if (viewVisible(otherView())) + switchEditViewTo(otherView()); + curIndex = 0; + } + else if (curIndex < 0) + { + if (viewVisible(otherView())) + { + switchEditViewTo(otherView()); + nbDoc = _pDocTab->nbItem(); + } + curIndex = nbDoc - 1; + } + + BufferID id = _pDocTab->getBufferByIndex(curIndex); + activateBuffer(id, currentView()); +} + +void Notepad_plus::activateDoc(int pos) +{ + int nbDoc = _pDocTab->nbItem(); + if (pos == _pDocTab->getCurrentTabIndex()) + { + Buffer * buf = _pEditView->getCurrentBuffer(); + buf->increaseRecentTag(); + return; + } + + if (pos >= 0 && pos < nbDoc) + { + BufferID id = _pDocTab->getBufferByIndex(pos); + activateBuffer(id, currentView()); + } +} + +void Notepad_plus::updateStatusBar() +{ + Buffer * buf = _pEditView->getCurrentBuffer(); + TCHAR strLnCol[64]; + wsprintf(strLnCol, TEXT("Ln : %d Col : %d Sel : %d"),\ + (_pEditView->getCurrentLineNumber() + 1), \ + (_pEditView->getCurrentColumnNumber() + 1),\ + (_pEditView->getSelectedByteNumber())); + + _statusBar.setText(strLnCol, STATUSBAR_CUR_POS); + + TCHAR strDonLen[64]; + wsprintf(strDonLen, TEXT("nb char : %d"), _pEditView->getCurrentDocLen()); + _statusBar.setText(strDonLen, STATUSBAR_DOC_SIZE); + _statusBar.setText(_pEditView->execute(SCI_GETOVERTYPE) ? TEXT("OVR") : TEXT("INS"), STATUSBAR_TYPING_MODE); +} + + +void Notepad_plus::dropFiles(HDROP hdrop) +{ + if (hdrop) + { + // Determinate in which view the file(s) is (are) dropped + POINT p; + ::DragQueryPoint(hdrop, &p); + HWND hWin = ::RealChildWindowFromPoint(_hSelf, p); + if (!hWin) return; + + if ((_mainEditView.getHSelf() == hWin) || (_mainDocTab.getHSelf() == hWin)) + switchEditViewTo(MAIN_VIEW); + else if ((_subEditView.getHSelf() == hWin) || (_subDocTab.getHSelf() == hWin)) + switchEditViewTo(SUB_VIEW); + else + { + ::SendMessage(hWin, WM_DROPFILES, (WPARAM)hdrop, 0); + return; + } + + int filesDropped = ::DragQueryFile(hdrop, 0xffffffff, NULL, 0); + BufferID lastOpened = BUFFER_INVALID; + for (int i = 0 ; i < filesDropped ; ++i) + { + TCHAR pathDropped[MAX_PATH]; + ::DragQueryFile(hdrop, i, pathDropped, MAX_PATH); + BufferID test = doOpen(pathDropped); + if (test != BUFFER_INVALID) + lastOpened = test; + //setLangStatus(_pEditView->getCurrentDocType()); + } + if (lastOpened != BUFFER_INVALID) { + switchToFile(lastOpened); + } + ::DragFinish(hdrop); + // Put Notepad_plus to forefront + // May not work for Win2k, but OK for lower versions + // Note: how to drop a file to an iconic window? + // Actually, it is the Send To command that generates a drop. + if (::IsIconic(_hSelf)) + { + ::ShowWindow(_hSelf, SW_RESTORE); + } + ::SetForegroundWindow(_hSelf); + } +} + +void Notepad_plus::checkModifiedDocument() +{ + //this will trigger buffer updates. If the status changes, Notepad++ will be informed and can do its magic + MainFileManager->checkFilesystemChanges(); +} + +void Notepad_plus::getMainClientRect(RECT &rc) const +{ + getClientRect(rc); + rc.top += _rebarTop.getHeight(); + rc.bottom -= rc.top + _rebarBottom.getHeight() + _statusBar.getHeight(); +} + +void Notepad_plus::showView(int whichOne) { + if (viewVisible(whichOne)) //no use making visible view visible + return; + + if (_mainWindowStatus & WindowUserActive) { + _pMainSplitter->setWin0(&_subSplitter); + _pMainWindow = _pMainSplitter; + } else { + _pMainWindow = &_subSplitter; + } + + if (whichOne == MAIN_VIEW) { + _mainEditView.display(true); + _mainDocTab.display(true); + } else if (whichOne == SUB_VIEW) { + _subEditView.display(true); + _subDocTab.display(true); + } + _pMainWindow->display(true); + + _mainWindowStatus |= (whichOne==MAIN_VIEW)?WindowMainActive:WindowSubActive; + + //Send sizing info to make windows fit + ::SendMessage(_hSelf, WM_SIZE, 0, 0); +} + +bool Notepad_plus::viewVisible(int whichOne) { + int viewToCheck = (whichOne == SUB_VIEW?WindowSubActive:WindowMainActive); + return (_mainWindowStatus & viewToCheck) != 0; +} + +void Notepad_plus::hideCurrentView() +{ + hideView(currentView()); +} + +void Notepad_plus::hideView(int whichOne) +{ + if (!(bothActive())) //cannot close if not both views visible + return; + + Window * windowToSet = (whichOne == MAIN_VIEW)?&_subDocTab:&_mainDocTab; + if (_mainWindowStatus & WindowUserActive) + { + _pMainSplitter->setWin0(windowToSet); + } + else // otherwise the main window is the spltter container that we just created + _pMainWindow = windowToSet; + + _subSplitter.display(false); //hide splitter + //hide scintilla and doctab + if (whichOne == MAIN_VIEW) { + _mainEditView.display(false); + _mainDocTab.display(false); + } else if (whichOne == SUB_VIEW) { + _subEditView.display(false); + _subDocTab.display(false); + } + + // resize the main window + ::SendMessage(_hSelf, WM_SIZE, 0, 0); + + switchEditViewTo(otherFromView(whichOne)); + int viewToDisable = (whichOne == SUB_VIEW?WindowSubActive:WindowMainActive); + _mainWindowStatus &= ~viewToDisable; +} + +bool Notepad_plus::loadStyles() +{ + NppParameters *pNppParam = NppParameters::getInstance(); + return pNppParam->reloadStylers(); +} + +bool Notepad_plus::reloadLang() +{ + NppParameters *pNppParam = NppParameters::getInstance(); + + if (!pNppParam->reloadLang()) + { + return false; + } + + TiXmlDocumentA *nativeLangDocRootA = pNppParam->getNativeLangA(); + if (!nativeLangDocRootA) + { + return false; + } + _nativeLangA = nativeLangDocRootA->FirstChild("NotepadPlus"); + if (!_nativeLangA) + { + return false; + } + _nativeLangA = _nativeLangA->FirstChild("Native-Langue"); + if (!_nativeLangA) + { + return false; + } + TiXmlElementA *element = _nativeLangA->ToElement(); + const char *rtl = element->Attribute("RTL"); + if (rtl) + _isRTL = (strcmp(rtl, "yes") == 0); + + // get encoding + TiXmlDeclarationA *declaration = _nativeLangA->GetDocument()->FirstChild()->ToDeclaration(); + if (declaration) + { + const char * encodingStr = declaration->Encoding(); + _nativeLangEncoding = getCpFromStringValue(encodingStr); + } + + pNppParam->reloadContextMenuFromXmlTree(_mainMenuHandle); + + generic_string pluginsTrans, windowTrans; + changeMenuLang(pluginsTrans, windowTrans); + + int indexWindow = ::GetMenuItemCount(_mainMenuHandle) - 3; + + if (_pluginsManager.hasPlugins() && pluginsTrans != TEXT("")) + { + ::ModifyMenu(_mainMenuHandle, indexWindow - 1, MF_BYPOSITION, 0, pluginsTrans.c_str()); + } + + if (windowTrans != TEXT("")) + { + ::ModifyMenu(_mainMenuHandle, indexWindow, MF_BYPOSITION, 0, windowTrans.c_str()); + windowTrans += TEXT("..."); + ::ModifyMenu(_mainMenuHandle, IDM_WINDOW_WINDOWS, MF_BYCOMMAND, IDM_WINDOW_WINDOWS, windowTrans.c_str()); + } + // Update scintilla context menu strings + vector & tmp = pNppParam->getContextMenuItems(); + size_t len = tmp.size(); + TCHAR menuName[64]; + for (size_t i = 0 ; i < len ; i++) + { + if (tmp[i]._itemName == TEXT("")) + { + ::GetMenuString(_mainMenuHandle, tmp[i]._cmdID, menuName, 64, MF_BYCOMMAND); + tmp[i]._itemName = purgeMenuItemString(menuName); + } + } + + vector & shortcuts = pNppParam->getUserShortcuts(); + len = shortcuts.size(); + + for(size_t i = 0; i < len; i++) + { + CommandShortcut & csc = shortcuts[i]; + ::GetMenuString(_mainMenuHandle, csc.getID(), menuName, 64, MF_BYCOMMAND); + csc.setName(purgeMenuItemString(menuName, true).c_str()); + } + _accelerator.updateFullMenu(); + + _scintaccelerator.updateKeys(); + + + if (_tabPopupMenu.isCreated()) + { + changeLangTabContextMenu(); + } + if (_tabPopupDropMenu.isCreated()) + { + changeLangTabDrapContextMenu(); + } + + if (_preference.isCreated()) + { + changePrefereceDlgLang(); + } + + if (_configStyleDlg.isCreated()) + { + changeConfigLang(); + } + + if (_findReplaceDlg.isCreated()) + { + changeFindReplaceDlgLang(); + } + + if (_goToLineDlg.isCreated()) + { + changeDlgLang(_goToLineDlg.getHSelf(), "GoToLine"); + } + + if (_runDlg.isCreated()) + { + changeDlgLang(_runDlg.getHSelf(), "Run"); + } + + if (_runMacroDlg.isCreated()) + { + changeDlgLang(_runMacroDlg.getHSelf(), "MultiMacro"); + } + + if (_goToLineDlg.isCreated()) + { + changeDlgLang(_goToLineDlg.getHSelf(), "GoToLine"); + } + + if (_colEditorDlg.isCreated()) + { + changeDlgLang(_colEditorDlg.getHSelf(), "ColumnEditor"); + } + + UserDefineDialog *udd = _pEditView->getUserDefineDlg(); + if (udd->isCreated()) + { + changeUserDefineLang(); + } + + return true; +} + +bool Notepad_plus::canHideView(int whichOne) +{ + if (!viewVisible(whichOne)) + return false; //cannot hide hidden view + if (!bothActive()) + return false; //cannot hide only window + DocTabView * tabToCheck = (whichOne == MAIN_VIEW)?&_mainDocTab:&_subDocTab; + Buffer * buf = MainFileManager->getBufferByID(tabToCheck->getBufferByIndex(0)); + bool canHide = ((tabToCheck->nbItem() == 1) && !buf->isDirty() && buf->isUntitled()); + return canHide; +} + +void Notepad_plus::loadBufferIntoView(BufferID id, int whichOne, bool dontClose) { + DocTabView * tabToOpen = (whichOne == MAIN_VIEW)?&_mainDocTab:&_subDocTab; + ScintillaEditView * viewToOpen = (whichOne == MAIN_VIEW)?&_mainEditView:&_subEditView; + + //check if buffer exists + int index = tabToOpen->getIndexByBuffer(id); + if (index != -1) //already open, done + return; + + BufferID idToClose = BUFFER_INVALID; + //Check if the tab has a single clean buffer. Close it if so + if (!dontClose && tabToOpen->nbItem() == 1) { + idToClose = tabToOpen->getBufferByIndex(0); + Buffer * buf = MainFileManager->getBufferByID(idToClose); + if (buf->isDirty() || !buf->isUntitled()) { + idToClose = BUFFER_INVALID; + } + } + + MainFileManager->addBufferReference(id, viewToOpen); + + if (idToClose != BUFFER_INVALID) { //close clean doc. Use special logic to prevent flicker of tab showing then hiding + tabToOpen->setBuffer(0, id); //index 0 since only one open + activateBuffer(id, whichOne); //activate. DocTab already activated but not a problem + MainFileManager->closeBuffer(idToClose, viewToOpen); //delete the buffer + } else { + tabToOpen->addBuffer(id); + } +} + +void Notepad_plus::removeBufferFromView(BufferID id, int whichOne) { + DocTabView * tabToClose = (whichOne == MAIN_VIEW)?&_mainDocTab:&_subDocTab; + ScintillaEditView * viewToClose = (whichOne == MAIN_VIEW)?&_mainEditView:&_subEditView; + + //check if buffer exists + int index = tabToClose->getIndexByBuffer(id); + if (index == -1) //doesnt exist, done + return; + + Buffer * buf = MainFileManager->getBufferByID(id); + + //Cannot close doc if last and clean + if (tabToClose->nbItem() == 1) { + if (!buf->isDirty() && buf->isUntitled()) { + return; //done + } + } + + int active = tabToClose->getCurrentTabIndex(); + if (active == index) { //need an alternative (close real doc, put empty one back + if (tabToClose->nbItem() == 1) { //need alternative doc, add new one. Use special logic to prevent flicker of adding new tab then closing other + BufferID newID = MainFileManager->newEmptyDocument(); + MainFileManager->addBufferReference(newID, viewToClose); + tabToClose->setBuffer(0, newID); //can safely use id 0, last (only) tab open + activateBuffer(newID, whichOne); //activate. DocTab already activated but not a problem + } else { + int toActivate = 0; + //activate next doc, otherwise prev if not possible + if (active == tabToClose->nbItem() - 1) { //prev + toActivate = active - 1; + } else { + toActivate = active; //activate the 'active' index. Since we remove the tab first, the indices shift (on the right side) + } + tabToClose->deletItemAt(index); //delete first + activateBuffer(tabToClose->getBufferByIndex(toActivate), whichOne); //then activate. The prevent jumpy tab behaviour + } + } else { + tabToClose->deletItemAt(index); + } + + MainFileManager->closeBuffer(id, viewToClose); +} + +int Notepad_plus::switchEditViewTo(int gid) +{ + if (currentView() == gid) { //make sure focus is ok, then leave + _pEditView->getFocus(); //set the focus + return gid; + } + if (!viewVisible(gid)) + return currentView(); //cannot activate invisible view + int oldView = currentView(); + int newView = otherView(); + + _activeView = newView; + //Good old switcheroo + DocTabView * tempTab = _pDocTab; + _pDocTab = _pNonDocTab; + _pNonDocTab = tempTab; + ScintillaEditView * tempView = _pEditView; + _pEditView = _pNonEditView; + _pNonEditView = tempView; + + _pEditView->beSwitched(); + _pEditView->getFocus(); //set the focus + + notifyBufferActivated(_pEditView->getCurrentBufferID(), currentView()); + return oldView; +} + +void Notepad_plus::dockUserDlg() +{ + if (!_pMainSplitter) + { + _pMainSplitter = new SplitterContainer; + _pMainSplitter->init(_hInst, _hSelf); + + Window *pWindow; + if (_mainWindowStatus & (WindowMainActive | WindowSubActive)) + pWindow = &_subSplitter; + else + pWindow = _pDocTab; + + _pMainSplitter->create(pWindow, ScintillaEditView::getUserDefineDlg(), 8, RIGHT_FIX, 45); + } + + if (bothActive()) + _pMainSplitter->setWin0(&_subSplitter); + else + _pMainSplitter->setWin0(_pDocTab); + + _pMainSplitter->display(); + + _mainWindowStatus |= WindowUserActive; + _pMainWindow = _pMainSplitter; + + ::SendMessage(_hSelf, WM_SIZE, 0, 0); +} + +void Notepad_plus::undockUserDlg() +{ + // a cause de surchargement de "display" + ::ShowWindow(_pMainSplitter->getHSelf(), SW_HIDE); + + if (bothActive()) + _pMainWindow = &_subSplitter; + else + _pMainWindow = _pDocTab; + + ::SendMessage(_hSelf, WM_SIZE, 0, 0); + + _mainWindowStatus &= ~WindowUserActive; + (ScintillaEditView::getUserDefineDlg())->display(); +} + +void Notepad_plus::docOpenInNewInstance(FileTransferMode mode, int x, int y) +{ + BufferID bufferID = _pEditView->getCurrentBufferID(); + Buffer * buf = MainFileManager->getBufferByID(bufferID); + if (buf->isUntitled() || buf->isDirty()) + return; + + TCHAR nppName[MAX_PATH]; + ::GetModuleFileName(NULL, nppName, MAX_PATH); + std::generic_string command = TEXT("\""); + command += nppName; + command += TEXT("\""); + + command += TEXT(" \"$(FULL_CURRENT_PATH)\" -multiInst -nosession -x"); + TCHAR pX[10], pY[10]; + generic_itoa(x, pX, 10); + generic_itoa(y, pY, 10); + + command += pX; + command += TEXT(" -y"); + command += pY; + + Command cmd(command); + cmd.run(_hSelf); + if (mode == TransferMove) + { + doClose(bufferID, currentView()); + if (noOpenedDoc()) + ::SendMessage(_hSelf, WM_CLOSE, 0, 0); + } +} + +void Notepad_plus::docGotoAnotherEditView(FileTransferMode mode) +{ + //First put the doc in the other view if not present (if it is, activate it). + //Then if needed close in the original tab + BufferID current = _pEditView->getCurrentBufferID(); + int viewToGo = otherView(); + int indexFound = _pNonDocTab->getIndexByBuffer(current); + if (indexFound != -1) //activate it + { + activateBuffer(current, otherView()); + } + else //open the document, also copying the position + { + loadBufferIntoView(current, viewToGo); + Buffer * buf = MainFileManager->getBufferByID(current); + _pEditView->saveCurrentPos(); //allow copying of position + buf->setPosition(buf->getPosition(_pEditView), _pNonEditView); + _pNonEditView->restoreCurrentPos(); //set position + activateBuffer(current, otherView()); + } + + //Open the view if it was hidden + int viewToOpen = (viewToGo == SUB_VIEW?WindowSubActive:WindowMainActive); + if (!(_mainWindowStatus & viewToOpen)) { + showView(viewToGo); + } + + //Close the document if we transfered the document instead of cloning it + if (mode == TransferMove) + { + //just close the activate document, since thats the one we moved (no search) + doClose(_pEditView->getCurrentBufferID(), currentView()); + if (noOpenedDoc()) + ::SendMessage(_hSelf, WM_CLOSE, 0, 0); + } // else it was cone, so leave it + + //Activate the other view since thats where the document went + switchEditViewTo(viewToGo); + + //_linkTriggered = true; +} + +bool Notepad_plus::activateBuffer(BufferID id, int whichOne) +{ + //scnN.nmhdr.code = NPPN_DOCSWITCHINGOFF; //superseeded by NPPN_BUFFERACTIVATED + + Buffer * pBuf = MainFileManager->getBufferByID(id); + bool reload = pBuf->getNeedReload(); + if (reload) + { + MainFileManager->reloadBuffer(id); + pBuf->setNeedReload(false); + } + if (whichOne == MAIN_VIEW) + { + if (_mainDocTab.activateBuffer(id)) //only activate if possible + _mainEditView.activateBuffer(id); + else + return false; + } + else + { + if (_subDocTab.activateBuffer(id)) + _subEditView.activateBuffer(id); + else + return false; + } + + if (reload) + { + performPostReload(whichOne); + } + notifyBufferActivated(id, whichOne); + + //scnN.nmhdr.code = NPPN_DOCSWITCHINGIN; //superseeded by NPPN_BUFFERACTIVATED + return true; +} + +void Notepad_plus::performPostReload(int whichOne) { + NppParameters *pNppParam = NppParameters::getInstance(); + const NppGUI & nppGUI = pNppParam->getNppGUI(); + bool toEnd = (nppGUI._fileAutoDetection == cdAutoUpdateGo2end) || (nppGUI._fileAutoDetection == cdGo2end); + if (!toEnd) + return; + if (whichOne == MAIN_VIEW) { + _mainEditView.execute(SCI_GOTOLINE, _mainEditView.execute(SCI_GETLINECOUNT) -1); + } else { + _subEditView.execute(SCI_GOTOLINE, _subEditView.execute(SCI_GETLINECOUNT) -1); + } +} + +void Notepad_plus::bookmarkNext(bool forwardScan) +{ + int lineno = _pEditView->getCurrentLineNumber(); + int sci_marker = SCI_MARKERNEXT; + int lineStart = lineno + 1; //Scan starting from next line + int lineRetry = 0; //If not found, try from the beginning + if (!forwardScan) + { + lineStart = lineno - 1; //Scan starting from previous line + lineRetry = int(_pEditView->execute(SCI_GETLINECOUNT)); //If not found, try from the end + sci_marker = SCI_MARKERPREVIOUS; + } + int nextLine = int(_pEditView->execute(sci_marker, lineStart, 1 << MARK_BOOKMARK)); + if (nextLine < 0) + nextLine = int(_pEditView->execute(sci_marker, lineRetry, 1 << MARK_BOOKMARK)); + + if (nextLine < 0) + return; + + _pEditView->execute(SCI_ENSUREVISIBLEENFORCEPOLICY, nextLine); + _pEditView->execute(SCI_GOTOLINE, nextLine); +} + +void Notepad_plus::dynamicCheckMenuAndTB() const +{ + // Visibility of 3 margins + checkMenuItem(IDM_VIEW_LINENUMBER, _pEditView->hasMarginShowed(ScintillaEditView::_SC_MARGE_LINENUMBER)); + checkMenuItem(IDM_VIEW_SYMBOLMARGIN, _pEditView->hasMarginShowed(ScintillaEditView::_SC_MARGE_SYBOLE)); + checkMenuItem(IDM_VIEW_FOLDERMAGIN, _pEditView->hasMarginShowed(ScintillaEditView::_SC_MARGE_FOLDER)); + + // Folder margin style + checkFolderMarginStyleMenu(getFolderMaginStyleIDFrom(_pEditView->getFolderStyle())); + + // Visibility of invisible characters + bool wsTabShow = _pEditView->isInvisibleCharsShown(); + bool eolShow = _pEditView->isEolVisible(); + + bool onlyWS = false; + bool onlyEOL = false; + bool bothWSEOL = false; + if (wsTabShow) + { + if (eolShow) + { + bothWSEOL = true; + } + else + { + onlyWS = true; + } + } + else if (eolShow) + { + onlyEOL = true; + } + + checkMenuItem(IDM_VIEW_TAB_SPACE, onlyWS); + checkMenuItem(IDM_VIEW_EOL, onlyEOL); + checkMenuItem(IDM_VIEW_ALL_CHARACTERS, bothWSEOL); + _toolBar.setCheck(IDM_VIEW_ALL_CHARACTERS, bothWSEOL); + + // Visibility of the indentation guide line + bool b = _pEditView->isShownIndentGuide(); + checkMenuItem(IDM_VIEW_INDENT_GUIDE, b); + _toolBar.setCheck(IDM_VIEW_INDENT_GUIDE, b); + + // Edge Line + int mode = int(_pEditView->execute(SCI_GETEDGEMODE)); + checkMenuItem(IDM_VIEW_EDGEBACKGROUND, (MF_BYCOMMAND | ((mode == EDGE_NONE)||(mode == EDGE_LINE))?MF_UNCHECKED:MF_CHECKED) != 0); + checkMenuItem(IDM_VIEW_EDGELINE, (MF_BYCOMMAND | ((mode == EDGE_NONE)||(mode == EDGE_BACKGROUND))?MF_UNCHECKED:MF_CHECKED) != 0); + + // Current Line Highlighting + checkMenuItem(IDM_VIEW_CURLINE_HILITING, _pEditView->isCurrentLineHiLiting()); + + // Wrap + b = _pEditView->isWrap(); + checkMenuItem(IDM_VIEW_WRAP, b); + _toolBar.setCheck(IDM_VIEW_WRAP, b); + checkMenuItem(IDM_VIEW_WRAP_SYMBOL, _pEditView->isWrapSymbolVisible()); + + //Format conversion + enableConvertMenuItems(_pEditView->getCurrentBuffer()->getFormat()); + checkUnicodeMenuItems(_pEditView->getCurrentBuffer()->getUnicodeMode()); + + //Syncronized scrolling +} + +void Notepad_plus::checkUnicodeMenuItems(UniMode um) const +{ + int id = -1; + switch (um) + { + case uniUTF8 : id = IDM_FORMAT_UTF_8; break; + case uni16BE : id = IDM_FORMAT_UCS_2BE; break; + case uni16LE : id = IDM_FORMAT_UCS_2LE; break; + case uniCookie : id = IDM_FORMAT_AS_UTF_8; break; + default : + id = IDM_FORMAT_ANSI; + } + ::CheckMenuRadioItem(_mainMenuHandle, IDM_FORMAT_ANSI, IDM_FORMAT_AS_UTF_8, id, MF_BYCOMMAND); +} + +void Notepad_plus::showAutoComp() { + bool isFromPrimary = _pEditView == &_mainEditView; + AutoCompletion * autoC = isFromPrimary?&_autoCompleteMain:&_autoCompleteSub; + autoC->showAutoComplete(); +} + +void Notepad_plus::autoCompFromCurrentFile(bool autoInsert) { + bool isFromPrimary = _pEditView == &_mainEditView; + AutoCompletion * autoC = isFromPrimary?&_autoCompleteMain:&_autoCompleteSub; + autoC->showWordComplete(autoInsert); +} + +void Notepad_plus::showFunctionComp() { + bool isFromPrimary = _pEditView == &_mainEditView; + AutoCompletion * autoC = isFromPrimary?&_autoCompleteMain:&_autoCompleteSub; + autoC->showFunctionComplete(); +} + +void Notepad_plus::changeMenuLang(generic_string & pluginsTrans, generic_string & windowTrans) +{ + if (!_nativeLangA) return; + TiXmlNodeA *mainMenu = _nativeLangA->FirstChild("Menu"); + if (!mainMenu) return; + mainMenu = mainMenu->FirstChild("Main"); + if (!mainMenu) return; + TiXmlNodeA *entriesRoot = mainMenu->FirstChild("Entries"); + if (!entriesRoot) return; + const char *idName = NULL; + +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); +#endif + + for (TiXmlNodeA *childNode = entriesRoot->FirstChildElement("Item"); + childNode ; + childNode = childNode->NextSibling("Item") ) + { + TiXmlElementA *element = childNode->ToElement(); + int id; + if (element->Attribute("id", &id)) + { + const char *name = element->Attribute("name"); + +#ifdef UNICODE + const wchar_t *nameW = wmc->char2wchar(name, _nativeLangEncoding); + ::ModifyMenu(_mainMenuHandle, id, MF_BYPOSITION, 0, nameW); +#else + ::ModifyMenu(_mainMenuHandle, id, MF_BYPOSITION, 0, name); +#endif + } + else if (idName = element->Attribute("idName")) + { + const char *name = element->Attribute("name"); + if (!strcmp(idName, "Plugins")) + { +#ifdef UNICODE + const wchar_t *nameW = wmc->char2wchar(name, _nativeLangEncoding); + pluginsTrans = nameW; +#else + pluginsTrans = name; +#endif + } + else if (!strcmp(idName, "Window")) + { +#ifdef UNICODE + const wchar_t *nameW = wmc->char2wchar(name, _nativeLangEncoding); + windowTrans = nameW; +#else + windowTrans = name; +#endif + } + } + } + + TiXmlNodeA *menuCommandsRoot = mainMenu->FirstChild("Commands"); + for (TiXmlNodeA *childNode = menuCommandsRoot->FirstChildElement("Item"); + childNode ; + childNode = childNode->NextSibling("Item") ) + { + TiXmlElementA *element = childNode->ToElement(); + int id; + element->Attribute("id", &id); + const char *name = element->Attribute("name"); + +#ifdef UNICODE + const wchar_t *nameW = wmc->char2wchar(name, _nativeLangEncoding); + ::ModifyMenu(_mainMenuHandle, id, MF_BYCOMMAND, id, nameW); +#else + ::ModifyMenu(_mainMenuHandle, id, MF_BYCOMMAND, id, name); +#endif + } + + TiXmlNodeA *subEntriesRoot = mainMenu->FirstChild("SubEntries"); + + for (TiXmlNodeA *childNode = subEntriesRoot->FirstChildElement("Item"); + childNode ; + childNode = childNode->NextSibling("Item") ) + { + TiXmlElementA *element = childNode->ToElement(); + int x, y; + element->Attribute("posX", &x); + element->Attribute("posY", &y); + const char *name = element->Attribute("name"); +#ifdef UNICODE + const wchar_t *nameW = wmc->char2wchar(name, _nativeLangEncoding); + ::ModifyMenu(::GetSubMenu(_mainMenuHandle, x), y, MF_BYPOSITION, 0, nameW); +#else + ::ModifyMenu(::GetSubMenu(_mainMenuHandle, x), y, MF_BYPOSITION, 0, name); +#endif + } + ::DrawMenuBar(_hSelf); +} + +void Notepad_plus::changeLangTabContextMenu() +{ + const int POS_CLOSE = 0; + const int POS_CLOSEBUT = 1; + const int POS_SAVE = 2; + const int POS_SAVEAS = 3; + const int POS_RENAME = 4; + const int POS_REMOVE = 5; + const int POS_PRINT = 6; + //------7 + const int POS_READONLY = 8; + const int POS_CLEARREADONLY = 9; + //------10 + const int POS_CLIPFULLPATH = 11; + const int POS_CLIPFILENAME = 12; + const int POS_CLIPCURRENTDIR = 13; + //------14 + const int POS_GO2VIEW = 15; + const int POS_CLONE2VIEW = 16; + const int POS_GO2NEWINST = 17; + const int POS_OPENINNEWINST = 18; + + const char *pClose = NULL; + const char *pCloseBut = NULL; + const char *pSave = NULL; + const char *pSaveAs = NULL; + const char *pPrint = NULL; + const char *pReadOnly = NULL; + const char *pClearReadOnly = NULL; + const char *pGoToView = NULL; + const char *pCloneToView = NULL; + const char *pGoToNewInst = NULL; + const char *pOpenInNewInst = NULL; + const char *pCilpFullPath = NULL; + const char *pCilpFileName = NULL; + const char *pCilpCurrentDir = NULL; + const char *pRename = NULL; + const char *pRemove = NULL; + if (_nativeLangA) + { + TiXmlNodeA *tabBarMenu = _nativeLangA->FirstChild("Menu"); + if (tabBarMenu) + { + tabBarMenu = tabBarMenu->FirstChild("TabBar"); + if (tabBarMenu) + { + for (TiXmlNodeA *childNode = tabBarMenu->FirstChildElement("Item"); + childNode ; + childNode = childNode->NextSibling("Item") ) + { + TiXmlElementA *element = childNode->ToElement(); + int ordre; + element->Attribute("order", &ordre); + switch (ordre) + { + case 0 : + pClose = element->Attribute("name"); break; + case 1 : + pCloseBut = element->Attribute("name"); break; + case 2 : + pSave = element->Attribute("name"); break; + case 3 : + pSaveAs = element->Attribute("name"); break; + case 4 : + pPrint = element->Attribute("name"); break; + case 5 : + pGoToView = element->Attribute("name"); break; + case 6 : + pCloneToView = element->Attribute("name"); break; + case 7 : + pCilpFullPath = element->Attribute("name"); break; + case 8 : + pCilpFileName = element->Attribute("name"); break; + case 9 : + pCilpCurrentDir = element->Attribute("name"); break; + case 10 : + pRename = element->Attribute("name"); break; + case 11 : + pRemove = element->Attribute("name"); break; + case 12 : + pReadOnly = element->Attribute("name"); break; + case 13 : + pClearReadOnly = element->Attribute("name"); break; + case 14 : + pGoToNewInst = element->Attribute("name"); break; + case 15 : + pOpenInNewInst = element->Attribute("name"); break; + } + } + } + } + } + HMENU hCM = _tabPopupMenu.getMenuHandle(); + +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + if (pGoToView && pGoToView[0]) + { + const wchar_t *goToViewG = wmc->char2wchar(pGoToView, _nativeLangEncoding); + int cmdID = ::GetMenuItemID(hCM, POS_GO2VIEW); + ::ModifyMenu(hCM, POS_GO2VIEW, MF_BYPOSITION, cmdID, goToViewG); + } + if (pCloneToView && pCloneToView[0]) + { + const wchar_t *cloneToViewG = wmc->char2wchar(pCloneToView, _nativeLangEncoding); + int cmdID = ::GetMenuItemID(hCM, POS_CLONE2VIEW); + ::ModifyMenu(hCM, POS_CLONE2VIEW, MF_BYPOSITION, cmdID, cloneToViewG); + } + if (pGoToNewInst && pGoToNewInst[0]) + { + const wchar_t *goToNewInstG = wmc->char2wchar(pGoToNewInst, _nativeLangEncoding); + int cmdID = ::GetMenuItemID(hCM, POS_GO2NEWINST); + ::ModifyMenu(hCM, POS_GO2NEWINST, MF_BYPOSITION, cmdID, goToNewInstG); + } + if (pOpenInNewInst && pOpenInNewInst[0]) + { + const wchar_t *openInNewInstG = wmc->char2wchar(pOpenInNewInst, _nativeLangEncoding); + int cmdID = ::GetMenuItemID(hCM, POS_OPENINNEWINST); + ::ModifyMenu(hCM, POS_OPENINNEWINST, MF_BYPOSITION, cmdID, openInNewInstG); + } + if (pClose && pClose[0]) + { + const wchar_t *closeG = wmc->char2wchar(pClose, _nativeLangEncoding); + int cmdID = ::GetMenuItemID(hCM, POS_CLOSE); + ::ModifyMenu(hCM, POS_CLOSE, MF_BYPOSITION, cmdID, closeG); + } + if (pCloseBut && pCloseBut[0]) + { + const wchar_t *closeButG = wmc->char2wchar(pCloseBut, _nativeLangEncoding); + int cmdID = ::GetMenuItemID(hCM, POS_CLOSEBUT); + ::ModifyMenu(hCM, POS_CLOSEBUT, MF_BYPOSITION, cmdID, closeButG); + } + if (pSave && pSave[0]) + { + const wchar_t *saveG = wmc->char2wchar(pSave, _nativeLangEncoding); + int cmdID = ::GetMenuItemID(hCM, POS_SAVE); + ::ModifyMenu(hCM, POS_SAVE, MF_BYPOSITION, cmdID, saveG); + } + if (pSaveAs && pSaveAs[0]) + { + const wchar_t *saveAsG = wmc->char2wchar(pSaveAs, _nativeLangEncoding); + int cmdID = ::GetMenuItemID(hCM, POS_SAVEAS); + ::ModifyMenu(hCM, POS_SAVEAS, MF_BYPOSITION, cmdID, saveAsG); + } + if (pPrint && pPrint[0]) + { + const wchar_t *printG = wmc->char2wchar(pPrint, _nativeLangEncoding); + int cmdID = ::GetMenuItemID(hCM, POS_PRINT); + ::ModifyMenu(hCM, POS_PRINT, MF_BYPOSITION, cmdID, printG); + } + if (pReadOnly && pReadOnly[0]) + { + const wchar_t *readOnlyG = wmc->char2wchar(pReadOnly, _nativeLangEncoding); + int cmdID = ::GetMenuItemID(hCM, POS_READONLY); + ::ModifyMenu(hCM, POS_READONLY, MF_BYPOSITION, cmdID, readOnlyG); + } + if (pClearReadOnly && pClearReadOnly[0]) + { + const wchar_t *clearReadOnlyG = wmc->char2wchar(pClearReadOnly, _nativeLangEncoding); + int cmdID = ::GetMenuItemID(hCM, POS_CLEARREADONLY); + ::ModifyMenu(hCM, POS_CLEARREADONLY, MF_BYPOSITION, cmdID, clearReadOnlyG); + } + if (pCilpFullPath && pCilpFullPath[0]) + { + const wchar_t *cilpFullPathG = wmc->char2wchar(pCilpFullPath, _nativeLangEncoding); + int cmdID = ::GetMenuItemID(hCM, POS_CLIPFULLPATH); + ::ModifyMenu(hCM, POS_CLIPFULLPATH, MF_BYPOSITION, cmdID, cilpFullPathG); + } + if (pCilpFileName && pCilpFileName[0]) + { + const wchar_t *cilpFileNameG = wmc->char2wchar(pCilpFileName, _nativeLangEncoding); + int cmdID = ::GetMenuItemID(hCM, POS_CLIPFILENAME); + ::ModifyMenu(hCM, POS_CLIPFILENAME, MF_BYPOSITION, cmdID, cilpFileNameG); + } + if (pCilpCurrentDir && pCilpCurrentDir[0]) + { + const wchar_t * cilpCurrentDirG= wmc->char2wchar(pCilpCurrentDir, _nativeLangEncoding); + int cmdID = ::GetMenuItemID(hCM, POS_CLIPCURRENTDIR); + ::ModifyMenu(hCM, POS_CLIPCURRENTDIR, MF_BYPOSITION, cmdID, cilpCurrentDirG); + } + if (pRename && pRename[0]) + { + const wchar_t *renameG = wmc->char2wchar(pRename, _nativeLangEncoding); + int cmdID = ::GetMenuItemID(hCM, POS_RENAME); + ::ModifyMenu(hCM, POS_RENAME, MF_BYPOSITION, cmdID, renameG); + } + if (pRemove && pRemove[0]) + { + const wchar_t *removeG = wmc->char2wchar(pRemove, _nativeLangEncoding); + int cmdID = ::GetMenuItemID(hCM, POS_REMOVE); + ::ModifyMenu(hCM, POS_REMOVE, MF_BYPOSITION, cmdID, removeG); + } +#else + if (pGoToView && pGoToView[0]) + { + int cmdID = ::GetMenuItemID(hCM, POS_GO2VIEW); + ::ModifyMenu(hCM, POS_GO2VIEW, MF_BYPOSITION, cmdID, pGoToView); + } + if (pCloneToView && pCloneToView[0]) + { + int cmdID = ::GetMenuItemID(hCM, POS_CLONE2VIEW); + ::ModifyMenu(hCM, POS_CLONE2VIEW, MF_BYPOSITION, cmdID, pCloneToView); + } + if (pGoToNewInst && pGoToNewInst[0]) + { + int cmdID = ::GetMenuItemID(hCM, POS_GO2NEWINST); + ::ModifyMenu(hCM, POS_GO2NEWINST, MF_BYPOSITION, cmdID, pGoToNewInst); + } + if (pOpenInNewInst && pOpenInNewInst[0]) + { + int cmdID = ::GetMenuItemID(hCM, POS_OPENINNEWINST); + ::ModifyMenu(hCM, POS_OPENINNEWINST, MF_BYPOSITION, cmdID, pOpenInNewInst); + } + if (pClose && pClose[0]) + { + int cmdID = ::GetMenuItemID(hCM, POS_CLOSE); + ::ModifyMenu(hCM, POS_CLOSE, MF_BYPOSITION, cmdID, pClose); + } + if (pCloseBut && pCloseBut[0]) + { + int cmdID = ::GetMenuItemID(hCM, POS_CLOSEBUT); + ::ModifyMenu(hCM, POS_CLOSEBUT, MF_BYPOSITION, cmdID, pCloseBut); + } + if (pSave && pSave[0]) + { + int cmdID = ::GetMenuItemID(hCM, POS_SAVE); + ::ModifyMenu(hCM, POS_SAVE, MF_BYPOSITION, cmdID, pSave); + } + if (pSaveAs && pSaveAs[0]) + { + int cmdID = ::GetMenuItemID(hCM, POS_SAVEAS); + ::ModifyMenu(hCM, POS_SAVEAS, MF_BYPOSITION, cmdID, pSaveAs); + } + if (pPrint && pPrint[0]) + { + int cmdID = ::GetMenuItemID(hCM, POS_PRINT); + ::ModifyMenu(hCM, POS_PRINT, MF_BYPOSITION, cmdID, pPrint); + } + if (pClearReadOnly && pClearReadOnly[0]) + { + int cmdID = ::GetMenuItemID(hCM, POS_CLEARREADONLY); + ::ModifyMenu(hCM, POS_CLEARREADONLY, MF_BYPOSITION, cmdID, pClearReadOnly); + } + if (pReadOnly && pReadOnly[0]) + { + int cmdID = ::GetMenuItemID(hCM, POS_READONLY); + ::ModifyMenu(hCM, POS_READONLY, MF_BYPOSITION, cmdID, pReadOnly); + } + if (pCilpFullPath && pCilpFullPath[0]) + { + int cmdID = ::GetMenuItemID(hCM, POS_CLIPFULLPATH); + ::ModifyMenu(hCM, POS_CLIPFULLPATH, MF_BYPOSITION, cmdID, pCilpFullPath); + } + if (pCilpFileName && pCilpFileName[0]) + { + int cmdID = ::GetMenuItemID(hCM, POS_CLIPFILENAME); + ::ModifyMenu(hCM, POS_CLIPFILENAME, MF_BYPOSITION, cmdID, pCilpFileName); + } + if (pCilpCurrentDir && pCilpCurrentDir[0]) + { + int cmdID = ::GetMenuItemID(hCM, POS_CLIPCURRENTDIR); + ::ModifyMenu(hCM, POS_CLIPCURRENTDIR, MF_BYPOSITION, cmdID, pCilpCurrentDir); + } + if (pRename && pRename[0]) + { + int cmdID = ::GetMenuItemID(hCM, POS_RENAME); + ::ModifyMenu(hCM, POS_RENAME, MF_BYPOSITION, cmdID, pRename); + } + if (pRemove && pRemove[0]) + { + int cmdID = ::GetMenuItemID(hCM, POS_REMOVE); + ::ModifyMenu(hCM, POS_REMOVE, MF_BYPOSITION, cmdID, pRemove); + } +#endif +} + +void Notepad_plus::changeLangTabDrapContextMenu() +{ + const int POS_GO2VIEW = 0; + const int POS_CLONE2VIEW = 1; + const char *goToViewA = NULL; + const char *cloneToViewA = NULL; + + if (_nativeLangA) + { + TiXmlNodeA *tabBarMenu = _nativeLangA->FirstChild("Menu"); + if (tabBarMenu) + tabBarMenu = tabBarMenu->FirstChild("TabBar"); + if (tabBarMenu) + { + for (TiXmlNodeA *childNode = tabBarMenu->FirstChildElement("Item"); + childNode ; + childNode = childNode->NextSibling("Item") ) + { + TiXmlElementA *element = childNode->ToElement(); + int ordre; + element->Attribute("order", &ordre); + if (ordre == 5) + goToViewA = element->Attribute("name"); + else if (ordre == 6) + cloneToViewA = element->Attribute("name"); + } + } + HMENU hCM = _tabPopupDropMenu.getMenuHandle(); +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + if (goToViewA && goToViewA[0]) + { + const wchar_t *goToViewG = wmc->char2wchar(goToViewA, _nativeLangEncoding); + int cmdID = ::GetMenuItemID(hCM, POS_GO2VIEW); + ::ModifyMenu(hCM, POS_GO2VIEW, MF_BYPOSITION|MF_STRING, cmdID, goToViewG); + } + if (cloneToViewA && cloneToViewA[0]) + { + const wchar_t *cloneToViewG = wmc->char2wchar(cloneToViewA, _nativeLangEncoding); + int cmdID = ::GetMenuItemID(hCM, POS_CLONE2VIEW); + ::ModifyMenu(hCM, POS_CLONE2VIEW, MF_BYPOSITION|MF_STRING, cmdID, cloneToViewG); + } +#else + if (goToViewA && goToViewA[0]) + { + int cmdID = ::GetMenuItemID(hCM, POS_GO2VIEW); + ::ModifyMenu(hCM, POS_GO2VIEW, MF_BYPOSITION, cmdID, goToViewA); + } + if (cloneToViewA && cloneToViewA[0]) + { + int cmdID = ::GetMenuItemID(hCM, POS_CLONE2VIEW); + ::ModifyMenu(hCM, POS_CLONE2VIEW, MF_BYPOSITION, cmdID, cloneToViewA); + } +#endif + } +} + +void Notepad_plus::changeConfigLang() +{ + if (!_nativeLangA) return; + + TiXmlNodeA *styleConfDlgNode = _nativeLangA->FirstChild("Dialog"); + if (!styleConfDlgNode) return; + + styleConfDlgNode = styleConfDlgNode->FirstChild("StyleConfig"); + if (!styleConfDlgNode) return; + + HWND hDlg = _configStyleDlg.getHSelf(); + +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); +#endif + + // Set Title + const char *titre = (styleConfDlgNode->ToElement())->Attribute("title"); + + if ((titre && titre[0]) && hDlg) + { +#ifdef UNICODE + const wchar_t *nameW = wmc->char2wchar(titre, _nativeLangEncoding); + ::SetWindowText(hDlg, nameW); +#else + ::SetWindowText(hDlg, titre); +#endif + } + for (TiXmlNodeA *childNode = styleConfDlgNode->FirstChildElement("Item"); + childNode ; + childNode = childNode->NextSibling("Item") ) + { + TiXmlElementA *element = childNode->ToElement(); + int id; + const char *sentinel = element->Attribute("id", &id); + const char *name = element->Attribute("name"); + if (sentinel && (name && name[0])) + { + HWND hItem = ::GetDlgItem(hDlg, id); + if (hItem) + { +#ifdef UNICODE + const wchar_t *nameW = wmc->char2wchar(name, _nativeLangEncoding); + ::SetWindowText(hItem, nameW); +#else + ::SetWindowText(hItem, name); +#endif + } + } + } + hDlg = _configStyleDlg.getHSelf(); + styleConfDlgNode = styleConfDlgNode->FirstChild("SubDialog"); + + for (TiXmlNodeA *childNode = styleConfDlgNode->FirstChildElement("Item"); + childNode ; + childNode = childNode->NextSibling("Item") ) + { + TiXmlElementA *element = childNode->ToElement(); + int id; + const char *sentinel = element->Attribute("id", &id); + const char *name = element->Attribute("name"); + if (sentinel && (name && name[0])) + { + HWND hItem = ::GetDlgItem(hDlg, id); + if (hItem) + { +#ifdef UNICODE + const wchar_t *nameW = wmc->char2wchar(name, _nativeLangEncoding); + ::SetWindowText(hItem, nameW); +#else + ::SetWindowText(hItem, name); +#endif + } + } + } +} + + +void Notepad_plus::changeStyleCtrlsLang(HWND hDlg, int *idArray, const char **translatedText) +{ + const int iColorStyle = 0; + const int iUnderline = 8; + + HWND hItem; + for (int i = iColorStyle ; i < (iUnderline + 1) ; i++) + { + if (translatedText[i] && translatedText[i][0]) + { + hItem = ::GetDlgItem(hDlg, idArray[i]); + if (hItem) + { +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + const wchar_t *nameW = wmc->char2wchar(translatedText[i], _nativeLangEncoding); + ::SetWindowText(hItem, nameW); +#else + ::SetWindowText(hItem, translatedText[i]); +#endif + + } + } + } +} + +void Notepad_plus::changeUserDefineLang() +{ + if (!_nativeLangA) return; + + TiXmlNodeA *userDefineDlgNode = _nativeLangA->FirstChild("Dialog"); + if (!userDefineDlgNode) return; + + userDefineDlgNode = userDefineDlgNode->FirstChild("UserDefine"); + if (!userDefineDlgNode) return; + + UserDefineDialog *userDefineDlg = _pEditView->getUserDefineDlg(); + + HWND hDlg = userDefineDlg->getHSelf(); +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); +#endif + + // Set Title + const char *titre = (userDefineDlgNode->ToElement())->Attribute("title"); + if (titre && titre[0]) + { +#ifdef UNICODE + const wchar_t *nameW = wmc->char2wchar(titre, _nativeLangEncoding); + ::SetWindowText(hDlg, nameW); +#else + ::SetWindowText(hDlg, titre); +#endif + } + // pour ses propres controls + const int nbControl = 9; + const char *translatedText[nbControl]; + for (int i = 0 ; i < nbControl ; i++) + translatedText[i] = NULL; + + for (TiXmlNodeA *childNode = userDefineDlgNode->FirstChildElement("Item"); + childNode ; + childNode = childNode->NextSibling("Item") ) + { + TiXmlElementA *element = childNode->ToElement(); + int id; + const char *sentinel = element->Attribute("id", &id); + const char *name = element->Attribute("name"); + + if (sentinel && (name && name[0])) + { + if (id > 30) + { + HWND hItem = ::GetDlgItem(hDlg, id); + if (hItem) + { +#ifdef UNICODE + const wchar_t *nameW = wmc->char2wchar(name, _nativeLangEncoding); + ::SetWindowText(hItem, nameW); +#else + ::SetWindowText(hItem, name); +#endif + } + } + else + { + switch(id) + { + case 0: case 1: case 2: case 3: case 4: + case 5: case 6: case 7: case 8: + translatedText[id] = name; break; + } + } + } + } + + const int nbDlg = 4; + HWND hDlgArrary[nbDlg]; + hDlgArrary[0] = userDefineDlg->getFolderHandle(); + hDlgArrary[1] = userDefineDlg->getKeywordsHandle(); + hDlgArrary[2] = userDefineDlg->getCommentHandle(); + hDlgArrary[3] = userDefineDlg->getSymbolHandle(); + + const int nbGrpFolder = 3; + int folderID[nbGrpFolder][nbControl] = {\ + {IDC_DEFAULT_COLORSTYLEGROUP_STATIC, IDC_DEFAULT_FG_STATIC, IDC_DEFAULT_BG_STATIC, IDC_DEFAULT_FONTSTYLEGROUP_STATIC, IDC_DEFAULT_FONTNAME_STATIC, IDC_DEFAULT_FONTSIZE_STATIC, IDC_DEFAULT_BOLD_CHECK, IDC_DEFAULT_ITALIC_CHECK, IDC_DEFAULT_UNDERLINE_CHECK},\ + {IDC_FOLDEROPEN_COLORSTYLEGROUP_STATIC, IDC_FOLDEROPEN_FG_STATIC, IDC_FOLDEROPEN_BG_STATIC, IDC_FOLDEROPEN_FONTSTYLEGROUP_STATIC, IDC_FOLDEROPEN_FONTNAME_STATIC, IDC_FOLDEROPEN_FONTSIZE_STATIC, IDC_FOLDEROPEN_BOLD_CHECK, IDC_FOLDEROPEN_ITALIC_CHECK, IDC_FOLDEROPEN_UNDERLINE_CHECK},\ + {IDC_FOLDERCLOSE_COLORSTYLEGROUP_STATIC, IDC_FOLDERCLOSE_FG_STATIC, IDC_FOLDERCLOSE_BG_STATIC, IDC_FOLDERCLOSE_FONTSTYLEGROUP_STATIC, IDC_FOLDERCLOSE_FONTNAME_STATIC, IDC_FOLDERCLOSE_FONTSIZE_STATIC, IDC_FOLDERCLOSE_BOLD_CHECK, IDC_FOLDERCLOSE_ITALIC_CHECK, IDC_FOLDERCLOSE_UNDERLINE_CHECK}\ + }; + + const int nbGrpKeywords = 4; + int keywordsID[nbGrpKeywords][nbControl] = {\ + {IDC_KEYWORD1_COLORSTYLEGROUP_STATIC, IDC_KEYWORD1_FG_STATIC, IDC_KEYWORD1_BG_STATIC, IDC_KEYWORD1_FONTSTYLEGROUP_STATIC, IDC_KEYWORD1_FONTNAME_STATIC, IDC_KEYWORD1_FONTSIZE_STATIC, IDC_KEYWORD1_BOLD_CHECK, IDC_KEYWORD1_ITALIC_CHECK, IDC_KEYWORD1_UNDERLINE_CHECK},\ + {IDC_KEYWORD2_COLORSTYLEGROUP_STATIC, IDC_KEYWORD2_FG_STATIC, IDC_KEYWORD2_BG_STATIC, IDC_KEYWORD2_FONTSTYLEGROUP_STATIC, IDC_KEYWORD2_FONTNAME_STATIC, IDC_KEYWORD2_FONTSIZE_STATIC, IDC_KEYWORD2_BOLD_CHECK, IDC_KEYWORD2_ITALIC_CHECK, IDC_KEYWORD2_UNDERLINE_CHECK},\ + {IDC_KEYWORD3_COLORSTYLEGROUP_STATIC, IDC_KEYWORD3_FG_STATIC, IDC_KEYWORD3_BG_STATIC, IDC_KEYWORD3_FONTSTYLEGROUP_STATIC, IDC_KEYWORD3_FONTNAME_STATIC, IDC_KEYWORD3_FONTSIZE_STATIC, IDC_KEYWORD3_BOLD_CHECK, IDC_KEYWORD3_ITALIC_CHECK, IDC_KEYWORD3_UNDERLINE_CHECK},\ + {IDC_KEYWORD4_COLORSTYLEGROUP_STATIC, IDC_KEYWORD4_FG_STATIC, IDC_KEYWORD4_BG_STATIC, IDC_KEYWORD4_FONTSTYLEGROUP_STATIC, IDC_KEYWORD4_FONTNAME_STATIC, IDC_KEYWORD4_FONTSIZE_STATIC, IDC_KEYWORD4_BOLD_CHECK, IDC_KEYWORD4_ITALIC_CHECK, IDC_KEYWORD4_UNDERLINE_CHECK}\ + }; + + const int nbGrpComment = 3; + int commentID[nbGrpComment][nbControl] = {\ + {IDC_COMMENT_COLORSTYLEGROUP_STATIC, IDC_COMMENT_FG_STATIC, IDC_COMMENT_BG_STATIC, IDC_COMMENT_FONTSTYLEGROUP_STATIC, IDC_COMMENT_FONTNAME_STATIC, IDC_COMMENT_FONTSIZE_STATIC, IDC_COMMENT_BOLD_CHECK, IDC_COMMENT_ITALIC_CHECK, IDC_COMMENT_UNDERLINE_CHECK},\ + {IDC_NUMBER_COLORSTYLEGROUP_STATIC, IDC_NUMBER_FG_STATIC, IDC_NUMBER_BG_STATIC, IDC_NUMBER_FONTSTYLEGROUP_STATIC, IDC_NUMBER_FONTNAME_STATIC, IDC_NUMBER_FONTSIZE_STATIC, IDC_NUMBER_BOLD_CHECK, IDC_NUMBER_ITALIC_CHECK, IDC_NUMBER_UNDERLINE_CHECK},\ + {IDC_COMMENTLINE_COLORSTYLEGROUP_STATIC, IDC_COMMENTLINE_FG_STATIC, IDC_COMMENTLINE_BG_STATIC, IDC_COMMENTLINE_FONTSTYLEGROUP_STATIC, IDC_COMMENTLINE_FONTNAME_STATIC, IDC_COMMENTLINE_FONTSIZE_STATIC, IDC_COMMENTLINE_BOLD_CHECK, IDC_COMMENTLINE_ITALIC_CHECK, IDC_COMMENTLINE_UNDERLINE_CHECK}\ + }; + + const int nbGrpOperator = 3; + int operatorID[nbGrpOperator][nbControl] = {\ + {IDC_SYMBOL_COLORSTYLEGROUP_STATIC, IDC_SYMBOL_FG_STATIC, IDC_SYMBOL_BG_STATIC, IDC_SYMBOL_FONTSTYLEGROUP_STATIC, IDC_SYMBOL_FONTNAME_STATIC, IDC_SYMBOL_FONTSIZE_STATIC, IDC_SYMBOL_BOLD_CHECK, IDC_SYMBOL_ITALIC_CHECK, IDC_SYMBOL_UNDERLINE_CHECK},\ + {IDC_SYMBOL_COLORSTYLEGROUP2_STATIC, IDC_SYMBOL_FG2_STATIC, IDC_SYMBOL_BG2_STATIC, IDC_SYMBOL_FONTSTYLEGROUP2_STATIC, IDC_SYMBOL_FONTNAME2_STATIC, IDC_SYMBOL_FONTSIZE2_STATIC, IDC_SYMBOL_BOLD2_CHECK, IDC_SYMBOL_ITALIC2_CHECK, IDC_SYMBOL_UNDERLINE2_CHECK},\ + {IDC_SYMBOL_COLORSTYLEGROUP3_STATIC, IDC_SYMBOL_FG3_STATIC, IDC_SYMBOL_BG3_STATIC, IDC_SYMBOL_FONTSTYLEGROUP3_STATIC, IDC_SYMBOL_FONTNAME3_STATIC, IDC_SYMBOL_FONTSIZE3_STATIC, IDC_SYMBOL_BOLD3_CHECK, IDC_SYMBOL_ITALIC3_CHECK, IDC_SYMBOL_UNDERLINE3_CHECK} + }; + + int nbGpArray[nbDlg] = {nbGrpFolder, nbGrpKeywords, nbGrpComment, nbGrpOperator}; + const char nodeNameArray[nbDlg][16] = {"Folder", "Keywords", "Comment", "Operator"}; + + for (int i = 0 ; i < nbDlg ; i++) + { + + for (int j = 0 ; j < nbGpArray[i] ; j++) + { + switch (i) + { + case 0 : changeStyleCtrlsLang(hDlgArrary[i], folderID[j], translatedText); break; + case 1 : changeStyleCtrlsLang(hDlgArrary[i], keywordsID[j], translatedText); break; + case 2 : changeStyleCtrlsLang(hDlgArrary[i], commentID[j], translatedText); break; + case 3 : changeStyleCtrlsLang(hDlgArrary[i], operatorID[j], translatedText); break; + } + } + TiXmlNodeA *node = userDefineDlgNode->FirstChild(nodeNameArray[i]); + + if (node) + { + // Set Title + titre = (node->ToElement())->Attribute("title"); + if (titre &&titre[0]) + { +#ifdef UNICODE + const wchar_t *nameW = wmc->char2wchar(titre, _nativeLangEncoding); + userDefineDlg->setTabName(i, nameW); +#else + userDefineDlg->setTabName(i, titre); +#endif + } + for (TiXmlNodeA *childNode = node->FirstChildElement("Item"); + childNode ; + childNode = childNode->NextSibling("Item") ) + { + TiXmlElementA *element = childNode->ToElement(); + int id; + const char *sentinel = element->Attribute("id", &id); + const char *name = element->Attribute("name"); + if (sentinel && (name && name[0])) + { + HWND hItem = ::GetDlgItem(hDlgArrary[i], id); + if (hItem) + { +#ifdef UNICODE + const wchar_t *nameW = wmc->char2wchar(name, _nativeLangEncoding); + ::SetWindowText(hItem, nameW); +#else + ::SetWindowText(hItem, name); +#endif + } + } + } + } + } +} + +void Notepad_plus::changeFindReplaceDlgLang() +{ + if (_nativeLangA) + { + TiXmlNodeA *dlgNode = _nativeLangA->FirstChild("Dialog"); + if (dlgNode) + { + NppParameters *pNppParam = NppParameters::getInstance(); + dlgNode = searchDlgNode(dlgNode, "Find"); + if (dlgNode) + { + const char *titre1 = (dlgNode->ToElement())->Attribute("titleFind"); + const char *titre2 = (dlgNode->ToElement())->Attribute("titleReplace"); + const char *titre3 = (dlgNode->ToElement())->Attribute("titleFindInFiles"); + if (titre1 && titre2 && titre3) + { +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + + basic_string nameW = wmc->char2wchar(titre1, _nativeLangEncoding); + pNppParam->getFindDlgTabTitiles()._find = nameW; + + nameW = wmc->char2wchar(titre2, _nativeLangEncoding); + pNppParam->getFindDlgTabTitiles()._replace = nameW; + + nameW = wmc->char2wchar(titre3, _nativeLangEncoding); + pNppParam->getFindDlgTabTitiles()._findInFiles = nameW; +#else + pNppParam->getFindDlgTabTitiles()._find = titre1; + pNppParam->getFindDlgTabTitiles()._replace = titre2; + pNppParam->getFindDlgTabTitiles()._findInFiles = titre3; +#endif + } + } + + _findReplaceDlg.changeTabName(FIND_DLG, pNppParam->getFindDlgTabTitiles()._find.c_str()); + _findReplaceDlg.changeTabName(REPLACE_DLG, pNppParam->getFindDlgTabTitiles()._replace.c_str()); + _findReplaceDlg.changeTabName(FINDINFILES_DLG, pNppParam->getFindDlgTabTitiles()._findInFiles.c_str()); + } + } + changeDlgLang(_findReplaceDlg.getHSelf(), "Find"); +} + +void Notepad_plus::changePrefereceDlgLang() +{ + changeDlgLang(_preference.getHSelf(), "Preference"); + + char titre[128]; + +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); +#endif + + changeDlgLang(_preference._barsDlg.getHSelf(), "Global", titre); + if (*titre) + { +#ifdef UNICODE + const wchar_t *nameW = wmc->char2wchar(titre, _nativeLangEncoding); + _preference._ctrlTab.renameTab(TEXT("Global"), nameW); +#else + _preference._ctrlTab.renameTab("Global", titre); +#endif + } + changeDlgLang(_preference._marginsDlg.getHSelf(), "Scintillas", titre); + if (*titre) + { +#ifdef UNICODE + const wchar_t *nameW = wmc->char2wchar(titre, _nativeLangEncoding); + _preference._ctrlTab.renameTab(TEXT("Scintillas"), nameW); +#else + _preference._ctrlTab.renameTab("Scintillas", titre); +#endif + } + + changeDlgLang(_preference._defaultNewDocDlg.getHSelf(), "NewDoc", titre); + if (*titre) + { +#ifdef UNICODE + const wchar_t *nameW = wmc->char2wchar(titre, _nativeLangEncoding); + _preference._ctrlTab.renameTab(TEXT("NewDoc"), nameW); +#else + _preference._ctrlTab.renameTab("NewDoc", titre); +#endif + } + + changeDlgLang(_preference._fileAssocDlg.getHSelf(), "FileAssoc", titre); + if (*titre) + { +#ifdef UNICODE + const wchar_t *nameW = wmc->char2wchar(titre, _nativeLangEncoding); + _preference._ctrlTab.renameTab(TEXT("FileAssoc"), nameW); +#else + _preference._ctrlTab.renameTab("FileAssoc", titre); +#endif + } + + changeDlgLang(_preference._langMenuDlg.getHSelf(), "LangMenu", titre); + if (*titre) + { +#ifdef UNICODE + const wchar_t *nameW = wmc->char2wchar(titre, _nativeLangEncoding); + _preference._ctrlTab.renameTab(TEXT("LangMenu"), nameW); +#else + _preference._ctrlTab.renameTab("LangMenu", titre); +#endif + } + + changeDlgLang(_preference._printSettingsDlg.getHSelf(), "Print1", titre); + if (*titre) + { +#ifdef UNICODE + const wchar_t *nameW = wmc->char2wchar(titre, _nativeLangEncoding); + _preference._ctrlTab.renameTab(TEXT("Print1"), nameW); +#else + _preference._ctrlTab.renameTab("Print1", titre); +#endif + } + changeDlgLang(_preference._printSettings2Dlg.getHSelf(), "Print2", titre); + if (*titre) + { +#ifdef UNICODE + const wchar_t *nameW = wmc->char2wchar(titre, _nativeLangEncoding); + _preference._ctrlTab.renameTab(TEXT("Print2"), nameW); +#else + _preference._ctrlTab.renameTab("Print2", titre); +#endif + } + changeDlgLang(_preference._settingsDlg.getHSelf(), "MISC", titre); + if (*titre) + { +#ifdef UNICODE + const wchar_t *nameW = wmc->char2wchar(titre, _nativeLangEncoding); + _preference._ctrlTab.renameTab(TEXT("MISC"), nameW); +#else + _preference._ctrlTab.renameTab("MISC", titre); +#endif + } + changeDlgLang(_preference._backupDlg.getHSelf(), "Backup", titre); + if (*titre) + { +#ifdef UNICODE + const wchar_t *nameW = wmc->char2wchar(titre, _nativeLangEncoding); + _preference._ctrlTab.renameTab(TEXT("Backup"), nameW); +#else + _preference._ctrlTab.renameTab("Backup", titre); +#endif + } +} + +void Notepad_plus::changeShortcutLang() +{ + if (!_nativeLangA) return; + + NppParameters * pNppParam = NppParameters::getInstance(); + vector & mainshortcuts = pNppParam->getUserShortcuts(); + vector & scinshortcuts = pNppParam->getScintillaKeyList(); + int mainSize = (int)mainshortcuts.size(); + int scinSize = (int)scinshortcuts.size(); + + TiXmlNodeA *shortcuts = _nativeLangA->FirstChild("Shortcuts"); + if (!shortcuts) return; + + shortcuts = shortcuts->FirstChild("Main"); + if (!shortcuts) return; + + TiXmlNodeA *entriesRoot = shortcuts->FirstChild("Entries"); + if (!entriesRoot) return; + + for (TiXmlNodeA *childNode = entriesRoot->FirstChildElement("Item"); + childNode ; + childNode = childNode->NextSibling("Item") ) + { + TiXmlElementA *element = childNode->ToElement(); + int index, id; + if (element->Attribute("index", &index) && element->Attribute("id", &id)) + { + if (index > -1 && index < mainSize) { //valid index only + const char *name = element->Attribute("name"); + CommandShortcut & csc = mainshortcuts[index]; + if (csc.getID() == id) + { +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + const wchar_t * nameW = wmc->char2wchar(name, _nativeLangEncoding); + csc.setName(nameW); +#else + csc.setName(name); +#endif + } + } + } + } + + //Scintilla + shortcuts = _nativeLangA->FirstChild("Shortcuts"); + if (!shortcuts) return; + + shortcuts = shortcuts->FirstChild("Scintilla"); + if (!shortcuts) return; + + entriesRoot = shortcuts->FirstChild("Entries"); + if (!entriesRoot) return; + + for (TiXmlNodeA *childNode = entriesRoot->FirstChildElement("Item"); + childNode ; + childNode = childNode->NextSibling("Item") ) + { + TiXmlElementA *element = childNode->ToElement(); + int index; + if (element->Attribute("index", &index)) + { + if (index > -1 && index < scinSize) { //valid index only + const char *name = element->Attribute("name"); + ScintillaKeyMap & skm = scinshortcuts[index]; +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + const wchar_t * nameW = wmc->char2wchar(name, _nativeLangEncoding); + skm.setName(nameW); +#else + skm.setName(name); +#endif + } + } + } + +} + +void Notepad_plus::changeShortcutmapperLang(ShortcutMapper * sm) +{ + if (!_nativeLangA) return; + + TiXmlNodeA *shortcuts = _nativeLangA->FirstChild("Dialog"); + if (!shortcuts) return; + + shortcuts = shortcuts->FirstChild("ShortcutMapper"); + if (!shortcuts) return; + + for (TiXmlNodeA *childNode = shortcuts->FirstChildElement("Item"); + childNode ; + childNode = childNode->NextSibling("Item") ) + { + TiXmlElementA *element = childNode->ToElement(); + int index; + if (element->Attribute("index", &index)) + { + if (index > -1 && index < 5) //valid index only + { + const char *name = element->Attribute("name"); + +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + const wchar_t * nameW = wmc->char2wchar(name, _nativeLangEncoding); + sm->translateTab(index, nameW); +#else + sm->translateTab(index, name); +#endif + } + } + } +} + + +TiXmlNodeA * searchDlgNode(TiXmlNodeA *node, const char *dlgTagName) +{ + TiXmlNodeA *dlgNode = node->FirstChild(dlgTagName); + if (dlgNode) return dlgNode; + for (TiXmlNodeA *childNode = node->FirstChildElement(); + childNode ; + childNode = childNode->NextSibling() ) + { + dlgNode = searchDlgNode(childNode, dlgTagName); + if (dlgNode) return dlgNode; + } + return NULL; +} + +bool Notepad_plus::changeDlgLang(HWND hDlg, const char *dlgTagName, char *title) +{ + if (title) + title[0] = '\0'; + + if (!_nativeLangA) return false; + + TiXmlNodeA *dlgNode = _nativeLangA->FirstChild("Dialog"); + if (!dlgNode) return false; + + dlgNode = searchDlgNode(dlgNode, dlgTagName); + if (!dlgNode) return false; + +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); +#endif + + // Set Title + const char *titre = (dlgNode->ToElement())->Attribute("title"); + if ((titre && titre[0]) && hDlg) + { +#ifdef UNICODE + const wchar_t *nameW = wmc->char2wchar(titre, _nativeLangEncoding); + ::SetWindowText(hDlg, nameW); +#else + ::SetWindowText(hDlg, titre); +#endif + if (title) + strcpy(title, titre); + } + + // Set the text of child control + for (TiXmlNodeA *childNode = dlgNode->FirstChildElement("Item"); + childNode ; + childNode = childNode->NextSibling("Item") ) + { + TiXmlElementA *element = childNode->ToElement(); + int id; + const char *sentinel = element->Attribute("id", &id); + const char *name = element->Attribute("name"); + if (sentinel && (name && name[0])) + { + HWND hItem = ::GetDlgItem(hDlg, id); + if (hItem) + { +#ifdef UNICODE + const wchar_t *nameW = wmc->char2wchar(name, _nativeLangEncoding); + ::SetWindowText(hItem, nameW); +#else + ::SetWindowText(hItem, name); +#endif + } + } + } + return true; +} + +static generic_string extractSymbol(TCHAR prefix, const TCHAR *str2extract) +{ + bool found = false; + TCHAR extracted[128] = TEXT(""); + + for (int i = 0, j = 0 ; i < lstrlen(str2extract) ; i++) + { + if (found) + { + if (!str2extract[i] || str2extract[i] == ' ') + { + extracted[j] = '\0'; + return generic_string(extracted); + } + extracted[j++] = str2extract[i]; + + } + else + { + if (!str2extract[i]) + return TEXT(""); + + if (str2extract[i] == prefix) + found = true; + } + } + return generic_string(extracted); +}; + +bool Notepad_plus::doBlockComment(comment_mode currCommentMode) +{ + const TCHAR *commentLineSybol; + generic_string symbol; + + Buffer * buf = _pEditView->getCurrentBuffer(); + if (buf->getLangType() == L_USER) + { + UserLangContainer * userLangContainer = NppParameters::getInstance()->getULCFromName(buf->getUserDefineLangName()); + if (!userLangContainer) + return false; + + symbol = extractSymbol('0', userLangContainer->_keywordLists[4]); + commentLineSybol = symbol.c_str(); + } + else + commentLineSybol = buf->getCommentLineSymbol(); + + + if ((!commentLineSybol) || (!commentLineSybol[0])) + return false; + + generic_string comment(commentLineSybol); + comment += TEXT(" "); + + const int linebufferSize = 1000; + TCHAR linebuf[linebufferSize]; + size_t comment_length = comment.length(); + size_t selectionStart = _pEditView->execute(SCI_GETSELECTIONSTART); + size_t selectionEnd = _pEditView->execute(SCI_GETSELECTIONEND); + size_t caretPosition = _pEditView->execute(SCI_GETCURRENTPOS); + // checking if caret is located in _beginning_ of selected block + bool move_caret = caretPosition < selectionEnd; + int selStartLine = _pEditView->execute(SCI_LINEFROMPOSITION, selectionStart); + int selEndLine = _pEditView->execute(SCI_LINEFROMPOSITION, selectionEnd); + int lines = selEndLine - selStartLine; + size_t firstSelLineStart = _pEditView->execute(SCI_POSITIONFROMLINE, selStartLine); + // "caret return" is part of the last selected line + if ((lines > 0) && (selectionEnd == static_cast(_pEditView->execute(SCI_POSITIONFROMLINE, selEndLine)))) + selEndLine--; + _pEditView->execute(SCI_BEGINUNDOACTION); + + for (int i = selStartLine; i <= selEndLine; i++) + { + int lineStart = _pEditView->execute(SCI_POSITIONFROMLINE, i); + int lineIndent = lineStart; + int lineEnd = _pEditView->execute(SCI_GETLINEENDPOSITION, i); + if ((lineEnd - lineIndent) >= linebufferSize) // Avoid buffer size problems + continue; + + lineIndent = _pEditView->execute(SCI_GETLINEINDENTPOSITION, i); + _pEditView->getGenericText(linebuf, lineIndent, lineEnd); + + generic_string linebufStr = linebuf; + + // empty lines are not commented + if (lstrlen(linebuf) < 1) + continue; + if (currCommentMode != cm_comment) + { + if (linebufStr.substr(0, comment_length - 1) == comment.substr(0, comment_length - 1)) + { + int len = (linebufStr.substr(0, comment_length) == comment)?comment_length:comment_length - 1; + + _pEditView->execute(SCI_SETSEL, lineIndent, lineIndent + len); + _pEditView->replaceSelWith(""); + + if (i == selStartLine) // is this the first selected line? + selectionStart -= len; + selectionEnd -= len; // every iteration + continue; + } + } + if ((currCommentMode == cm_toggle) || (currCommentMode == cm_comment)) + { + if (i == selStartLine) // is this the first selected line? + selectionStart += comment_length; + selectionEnd += comment_length; // every iteration + _pEditView->insertGenericTextFrom(lineIndent, comment.c_str()); + } + } + // after uncommenting selection may promote itself to the lines + // before the first initially selected line; + // another problem - if only comment symbol was selected; + if (selectionStart < firstSelLineStart) + { + if (selectionStart >= selectionEnd - (comment_length - 1)) + selectionEnd = firstSelLineStart; + selectionStart = firstSelLineStart; + } + if (move_caret) + { + // moving caret to the beginning of selected block + _pEditView->execute(SCI_GOTOPOS, selectionEnd); + _pEditView->execute(SCI_SETCURRENTPOS, selectionStart); + } + else + { + _pEditView->execute(SCI_SETSEL, selectionStart, selectionEnd); + } + _pEditView->execute(SCI_ENDUNDOACTION); + return true; +} + +bool Notepad_plus::doStreamComment() +{ + const TCHAR *commentStart; + const TCHAR *commentEnd; + + generic_string symbolStart; + generic_string symbolEnd; + + Buffer * buf = _pEditView->getCurrentBuffer(); + if (buf->getLangType() == L_USER) + { + UserLangContainer * userLangContainer = NppParameters::getInstance()->getULCFromName(buf->getUserDefineLangName()); + + if (!userLangContainer) + return false; + + symbolStart = extractSymbol('1', userLangContainer->_keywordLists[4]); + commentStart = symbolStart.c_str(); + symbolEnd = extractSymbol('2', userLangContainer->_keywordLists[4]); + commentEnd = symbolEnd.c_str(); + } + else + { + commentStart = buf->getCommentStart(); + commentEnd = buf->getCommentEnd(); + } + + if ((!commentStart) || (!commentStart[0])) + return false; + if ((!commentEnd) || (!commentEnd[0])) + return false; + + generic_string start_comment(commentStart); + generic_string end_comment(commentEnd); + generic_string white_space(TEXT(" ")); + + start_comment += white_space; + white_space += end_comment; + end_comment = white_space; + size_t start_comment_length = start_comment.length(); + size_t selectionStart = _pEditView->execute(SCI_GETSELECTIONSTART); + size_t selectionEnd = _pEditView->execute(SCI_GETSELECTIONEND); + size_t caretPosition = _pEditView->execute(SCI_GETCURRENTPOS); + // checking if caret is located in _beginning_ of selected block + bool move_caret = caretPosition < selectionEnd; + // if there is no selection? + if (selectionEnd - selectionStart <= 0) + { + int selLine = _pEditView->execute(SCI_LINEFROMPOSITION, selectionStart); + int lineIndent = _pEditView->execute(SCI_GETLINEINDENTPOSITION, selLine); + int lineEnd = _pEditView->execute(SCI_GETLINEENDPOSITION, selLine); + + TCHAR linebuf[1000]; + _pEditView->getGenericText(linebuf, lineIndent, lineEnd); + + int caret = _pEditView->execute(SCI_GETCURRENTPOS); + int line = _pEditView->execute(SCI_LINEFROMPOSITION, caret); + int lineStart = _pEditView->execute(SCI_POSITIONFROMLINE, line); + int current = caret - lineStart; + // checking if we are not inside a word + + int startword = current; + int endword = current; + int start_counter = 0; + int end_counter = 0; + while (startword > 0)// && wordCharacters.contains(linebuf[startword - 1])) + { + start_counter++; + startword--; + } + // checking _beginning_ of the word + if (startword == current) + return true; // caret is located _before_ a word + while (linebuf[endword + 1] != '\0') // && wordCharacters.contains(linebuf[endword + 1])) + { + end_counter++; + endword++; + } + selectionStart -= start_counter; + selectionEnd += (end_counter + 1); + } + _pEditView->execute(SCI_BEGINUNDOACTION); + _pEditView->insertGenericTextFrom(selectionStart, start_comment.c_str()); + selectionEnd += start_comment_length; + selectionStart += start_comment_length; + _pEditView->insertGenericTextFrom(selectionEnd, end_comment.c_str()); + if (move_caret) + { + // moving caret to the beginning of selected block + _pEditView->execute(SCI_GOTOPOS, selectionEnd); + _pEditView->execute(SCI_SETCURRENTPOS, selectionStart); + } + else + { + _pEditView->execute(SCI_SETSEL, selectionStart, selectionEnd); + } + _pEditView->execute(SCI_ENDUNDOACTION); + return true; +} + +bool Notepad_plus::saveScintillaParams(bool whichOne) +{ + ScintillaViewParams svp; + ScintillaEditView *pView = (whichOne == SCIV_PRIMARY)?&_mainEditView:&_subEditView; + + svp._lineNumberMarginShow = pView->hasMarginShowed(ScintillaEditView::_SC_MARGE_LINENUMBER); + svp._bookMarkMarginShow = pView->hasMarginShowed(ScintillaEditView::_SC_MARGE_SYBOLE); + //svp._docChangeStateMarginShow = pView->hasMarginShowed(ScintillaEditView::_SC_MARGE_MODIFMARKER); + svp._indentGuideLineShow = pView->isShownIndentGuide(); + svp._folderStyle = pView->getFolderStyle(); + svp._currentLineHilitingShow = pView->isCurrentLineHiLiting(); + svp._wrapSymbolShow = pView->isWrapSymbolVisible(); + svp._doWrap = pView->isWrap(); + svp._edgeMode = int(pView->execute(SCI_GETEDGEMODE)); + svp._edgeNbColumn = int(pView->execute(SCI_GETEDGECOLUMN)); + svp._zoom = int(pView->execute(SCI_GETZOOM)); + svp._whiteSpaceShow = pView->isInvisibleCharsShown(); + svp._eolShow = pView->isEolVisible(); + + return (NppParameters::getInstance())->writeScintillaParams(svp, whichOne); +} + +bool Notepad_plus::addCurrentMacro() +{ + vector & theMacros = (NppParameters::getInstance())->getMacroList(); + + int nbMacro = theMacros.size(); + + int cmdID = ID_MACRO + nbMacro; + MacroShortcut ms(Shortcut(), _macro, cmdID); + ms.init(_hInst, _hSelf); + + if (ms.doDialog() != -1) + { + HMENU hMacroMenu = ::GetSubMenu(_mainMenuHandle, MENUINDEX_MACRO); + int const posBase = 6; //separator at index 5 + if (nbMacro == 0) + { + ::InsertMenu(hMacroMenu, posBase-1, MF_BYPOSITION, (unsigned int)-1, 0); //no separator yet, add one + } + + theMacros.push_back(ms); + ::InsertMenu(hMacroMenu, posBase + nbMacro, MF_BYPOSITION, cmdID, ms.toMenuItemString().c_str()); + _accelerator.updateShortcuts(); + return true; + } + return false; +} + +void Notepad_plus::changeToolBarIcons() +{ + if (!_toolIcons) + return; + for (int i = 0 ; i < int(_customIconVect.size()) ; i++) + _toolBar.changeIcons(_customIconVect[i].listIndex, _customIconVect[i].iconIndex, (_customIconVect[i].iconLocation).c_str()); +} + +bool Notepad_plus::switchToFile(BufferID id) +{ + int i = 0; + int iView = currentView(); + if (id == BUFFER_INVALID) + return false; + + if ((i = _pDocTab->getIndexByBuffer(id)) != -1) + { + iView = currentView(); + } + else if ((i = _pNonDocTab->getIndexByBuffer(id)) != -1) + { + iView = otherView(); + } + + if (i != -1) + { + switchEditViewTo(iView); + //_pDocTab->activateAt(i); + activateBuffer(id, currentView()); + return true; + } + return false; +} + +ToolBarButtonUnit toolBarIcons[] = { + {IDM_FILE_NEW, IDI_NEW_OFF_ICON, IDI_NEW_ON_ICON, IDI_NEW_OFF_ICON, IDR_FILENEW}, + {IDM_FILE_OPEN, IDI_OPEN_OFF_ICON, IDI_OPEN_ON_ICON, IDI_NEW_OFF_ICON, IDR_FILEOPEN}, + {IDM_FILE_SAVE, IDI_SAVE_OFF_ICON, IDI_SAVE_ON_ICON, IDI_SAVE_DISABLE_ICON, IDR_FILESAVE}, + {IDM_FILE_SAVEALL, IDI_SAVEALL_OFF_ICON, IDI_SAVEALL_ON_ICON, IDI_SAVEALL_DISABLE_ICON, IDR_SAVEALL}, + {IDM_FILE_CLOSE, IDI_CLOSE_OFF_ICON, IDI_CLOSE_ON_ICON, IDI_CLOSE_OFF_ICON, IDR_CLOSEFILE}, + {IDM_FILE_CLOSEALL, IDI_CLOSEALL_OFF_ICON, IDI_CLOSEALL_ON_ICON, IDI_CLOSEALL_OFF_ICON, IDR_CLOSEALL}, + {IDM_FILE_PRINTNOW, IDI_PRINT_OFF_ICON, IDI_PRINT_ON_ICON, IDI_PRINT_OFF_ICON, IDR_PRINT}, + + //-------------------------------------------------------------------------------------// + {0, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON}, + //-------------------------------------------------------------------------------------// + + {IDM_EDIT_CUT, IDI_CUT_OFF_ICON, IDI_CUT_ON_ICON, IDI_CUT_DISABLE_ICON, IDR_CUT}, + {IDM_EDIT_COPY, IDI_COPY_OFF_ICON, IDI_COPY_ON_ICON, IDI_COPY_DISABLE_ICON, IDR_COPY}, + {IDM_EDIT_PASTE, IDI_PASTE_OFF_ICON, IDI_PASTE_ON_ICON, IDI_PASTE_DISABLE_ICON, IDR_PASTE}, + + //-------------------------------------------------------------------------------------// + {0, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON}, + //-------------------------------------------------------------------------------------// + + {IDM_EDIT_UNDO, IDI_UNDO_OFF_ICON, IDI_UNDO_ON_ICON, IDI_UNDO_DISABLE_ICON, IDR_UNDO}, + {IDM_EDIT_REDO, IDI_REDO_OFF_ICON, IDI_REDO_ON_ICON, IDI_REDO_DISABLE_ICON, IDR_REDO}, + //-------------------------------------------------------------------------------------// + {0, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON}, + //-------------------------------------------------------------------------------------// + + {IDM_SEARCH_FIND, IDI_FIND_OFF_ICON, IDI_FIND_ON_ICON, IDI_FIND_OFF_ICON, IDR_FIND}, + {IDM_SEARCH_REPLACE, IDI_REPLACE_OFF_ICON, IDI_REPLACE_ON_ICON, IDI_REPLACE_OFF_ICON, IDR_REPLACE}, + + //-------------------------------------------------------------------------------------// + {0, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON}, + //-------------------------------------------------------------------------------------// + {IDM_VIEW_ZOOMIN, IDI_ZOOMIN_OFF_ICON, IDI_ZOOMIN_ON_ICON, IDI_ZOOMIN_OFF_ICON, IDR_ZOOMIN}, + {IDM_VIEW_ZOOMOUT, IDI_ZOOMOUT_OFF_ICON, IDI_ZOOMOUT_ON_ICON, IDI_ZOOMOUT_OFF_ICON, IDR_ZOOMOUT}, + + //-------------------------------------------------------------------------------------// + {0, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON}, + //-------------------------------------------------------------------------------------// + {IDM_VIEW_SYNSCROLLV, IDI_SYNCV_OFF_ICON, IDI_SYNCV_ON_ICON, IDI_SYNCV_DISABLE_ICON, IDR_SYNCV}, + {IDM_VIEW_SYNSCROLLH, IDI_SYNCH_OFF_ICON, IDI_SYNCH_ON_ICON, IDI_SYNCH_DISABLE_ICON, IDR_SYNCH}, + + //-------------------------------------------------------------------------------------// + {0, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON}, + //-------------------------------------------------------------------------------------// + {IDM_VIEW_WRAP, IDI_VIEW_WRAP_OFF_ICON, IDI_VIEW_WRAP_ON_ICON, IDI_VIEW_WRAP_OFF_ICON, IDR_WRAP}, + {IDM_VIEW_ALL_CHARACTERS, IDI_VIEW_ALL_CHAR_OFF_ICON, IDI_VIEW_ALL_CHAR_ON_ICON, IDI_VIEW_ALL_CHAR_OFF_ICON, IDR_INVISIBLECHAR}, + {IDM_VIEW_INDENT_GUIDE, IDI_VIEW_INDENT_OFF_ICON, IDI_VIEW_INDENT_ON_ICON, IDI_VIEW_INDENT_OFF_ICON, IDR_INDENTGUIDE}, + {IDM_VIEW_USER_DLG, IDI_VIEW_UD_DLG_OFF_ICON, IDI_VIEW_UD_DLG_ON_ICON, IDI_VIEW_UD_DLG_OFF_ICON, IDR_SHOWPANNEL}, + + //-------------------------------------------------------------------------------------// + {0, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON}, + //-------------------------------------------------------------------------------------// + + {IDM_MACRO_STARTRECORDINGMACRO, IDI_STARTRECORD_OFF_ICON, IDI_STARTRECORD_ON_ICON, IDI_STARTRECORD_DISABLE_ICON, IDR_STARTRECORD}, + {IDM_MACRO_STOPRECORDINGMACRO, IDI_STOPRECORD_OFF_ICON, IDI_STOPRECORD_ON_ICON, IDI_STOPRECORD_DISABLE_ICON, IDR_STOPRECORD}, + {IDM_MACRO_PLAYBACKRECORDEDMACRO, IDI_PLAYRECORD_OFF_ICON, IDI_PLAYRECORD_ON_ICON, IDI_PLAYRECORD_DISABLE_ICON, IDR_PLAYRECORD}, + {IDM_MACRO_RUNMULTIMACRODLG, IDI_MMPLAY_OFF_ICON, IDI_MMPLAY_ON_ICON, IDI_MMPLAY_DIS_ICON, IDR_M_PLAYRECORD}, + {IDM_MACRO_SAVECURRENTMACRO, IDI_SAVERECORD_OFF_ICON, IDI_SAVERECORD_ON_ICON, IDI_SAVERECORD_DISABLE_ICON, IDR_SAVERECORD} + +}; + +void Notepad_plus::getTaskListInfo(TaskListInfo *tli) +{ + size_t currentNbDoc = _pDocTab->nbItem(); + size_t nonCurrentNbDoc = _pNonDocTab->nbItem(); + + tli->_currentIndex = 0; + + if (!viewVisible(otherView())) + nonCurrentNbDoc = 0; + + for (size_t i = 0 ; i < currentNbDoc ; i++) + { + BufferID bufID = _pDocTab->getBufferByIndex(i); + Buffer * b = MainFileManager->getBufferByID(bufID); + int status = b->isReadOnly()?tb_ro:(b->isDirty()?tb_unsaved:tb_saved); + tli->_tlfsLst.push_back(TaskLstFnStatus(currentView(), i, b->getFullPathName(), status)); + } + for (size_t i = 0 ; i < nonCurrentNbDoc ; i++) + { + BufferID bufID = _pNonDocTab->getBufferByIndex(i); + Buffer * b = MainFileManager->getBufferByID(bufID); + int status = b->isReadOnly()?tb_ro:(b->isDirty()?tb_unsaved:tb_saved); + tli->_tlfsLst.push_back(TaskLstFnStatus(otherView(), i, b->getFullPathName(), status)); + } +} + +LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) +{ + LRESULT result = FALSE; + + NppParameters *pNppParam = NppParameters::getInstance(); + switch (Message) + { + case WM_NCACTIVATE: + { + // Note: lParam is -1 to prevent endless loops of calls + ::SendMessage(_dockingManager.getHSelf(), WM_NCACTIVATE, wParam, (LPARAM)-1); + return ::DefWindowProc(hwnd, Message, wParam, lParam); + } + case WM_CREATE: + { + NppGUI & nppGUI = (NppGUI &)pNppParam->getNppGUI(); + + // Menu + _mainMenuHandle = ::GetMenu(_hSelf); + int langPos2BeRemoved = MENUINDEX_LANGUAGE+1; + if (nppGUI._isLangMenuCompact) + langPos2BeRemoved = MENUINDEX_LANGUAGE; + ::RemoveMenu(_mainMenuHandle, langPos2BeRemoved, MF_BYPOSITION); + + //Views + _pDocTab = &_mainDocTab; + _pEditView = &_mainEditView; + _pNonDocTab = &_subDocTab; + _pNonEditView = &_subEditView; + + _mainEditView.init(_hInst, hwnd); + _subEditView.init(_hInst, hwnd); + + _fileEditView.init(_hInst, hwnd); + MainFileManager->init(this, &_fileEditView); //get it up and running asap. + + pNppParam->setFontList(hwnd); + + + _mainWindowStatus = WindowMainActive; + _activeView = MAIN_VIEW; + + const ScintillaViewParams & svp1 = pNppParam->getSVP(SCIV_PRIMARY); + const ScintillaViewParams & svp2 = pNppParam->getSVP(SCIV_SECOND); + + int tabBarStatus = nppGUI._tabStatus; + _toReduceTabBar = ((tabBarStatus & TAB_REDUCE) != 0); + _docTabIconList.create(_toReduceTabBar?13:20, _hInst, docTabIconIDs, sizeof(docTabIconIDs)/sizeof(int)); + + _mainDocTab.init(_hInst, hwnd, &_mainEditView, &_docTabIconList); + _subDocTab.init(_hInst, hwnd, &_subEditView, &_docTabIconList); + + _mainEditView.display(); + + _invisibleEditView.init(_hInst, hwnd); + _invisibleEditView.execute(SCI_SETUNDOCOLLECTION); + _invisibleEditView.execute(SCI_EMPTYUNDOBUFFER); + + // Configuration of 2 scintilla views + _mainEditView.showMargin(ScintillaEditView::_SC_MARGE_LINENUMBER, svp1._lineNumberMarginShow); + _subEditView.showMargin(ScintillaEditView::_SC_MARGE_LINENUMBER, svp2._lineNumberMarginShow); + _mainEditView.showMargin(ScintillaEditView::_SC_MARGE_SYBOLE, svp1._bookMarkMarginShow); + _subEditView.showMargin(ScintillaEditView::_SC_MARGE_SYBOLE, svp2._bookMarkMarginShow); + //_mainEditView.showMargin(ScintillaEditView::_SC_MARGE_MODIFMARKER, svp1._docChangeStateMarginShow); + //_subEditView.showMargin(ScintillaEditView::_SC_MARGE_MODIFMARKER, svp2._docChangeStateMarginShow); + + _mainEditView.showIndentGuideLine(svp1._indentGuideLineShow); + _subEditView.showIndentGuideLine(svp2._indentGuideLineShow); + + ::SendMessage(hwnd, NPPM_INTERNAL_SETCARETWIDTH, 0, 0); + ::SendMessage(hwnd, NPPM_INTERNAL_SETCARETBLINKRATE, 0, 0); + + _configStyleDlg.init(_hInst, _hSelf); + _preference.init(_hInst, _hSelf); + + //Marker Margin config + _mainEditView.setMakerStyle(svp1._folderStyle); + _subEditView.setMakerStyle(svp2._folderStyle); + + _mainEditView.execute(SCI_SETCARETLINEVISIBLE, svp1._currentLineHilitingShow); + _subEditView.execute(SCI_SETCARETLINEVISIBLE, svp2._currentLineHilitingShow); + + _mainEditView.execute(SCI_SETCARETLINEVISIBLEALWAYS, true); + _subEditView.execute(SCI_SETCARETLINEVISIBLEALWAYS, true); + + _mainEditView.wrap(svp1._doWrap); + _subEditView.wrap(svp2._doWrap); + + _mainEditView.execute(SCI_SETEDGECOLUMN, svp1._edgeNbColumn); + _mainEditView.execute(SCI_SETEDGEMODE, svp1._edgeMode); + _subEditView.execute(SCI_SETEDGECOLUMN, svp2._edgeNbColumn); + _subEditView.execute(SCI_SETEDGEMODE, svp2._edgeMode); + + _mainEditView.showEOL(svp1._eolShow); + _subEditView.showEOL(svp2._eolShow); + + _mainEditView.showWSAndTab(svp1._whiteSpaceShow); + _subEditView.showWSAndTab(svp2._whiteSpaceShow); + + _mainEditView.showWrapSymbol(svp1._wrapSymbolShow); + _subEditView.showWrapSymbol(svp2._wrapSymbolShow); + + _mainEditView.performGlobalStyles(); + _subEditView.performGlobalStyles(); + + _zoomOriginalValue = _pEditView->execute(SCI_GETZOOM); + _mainEditView.execute(SCI_SETZOOM, svp1._zoom); + _subEditView.execute(SCI_SETZOOM, svp2._zoom); + + TabBarPlus::doDragNDrop(true); + + if (_toReduceTabBar) + { + HFONT hf = (HFONT)::GetStockObject(DEFAULT_GUI_FONT); + + if (hf) + { + ::SendMessage(_mainDocTab.getHSelf(), WM_SETFONT, (WPARAM)hf, MAKELPARAM(TRUE, 0)); + ::SendMessage(_subDocTab.getHSelf(), WM_SETFONT, (WPARAM)hf, MAKELPARAM(TRUE, 0)); + } + TabCtrl_SetItemSize(_mainDocTab.getHSelf(), 45, 20); + TabCtrl_SetItemSize(_subDocTab.getHSelf(), 45, 20); + } + _mainDocTab.display(); + + + TabBarPlus::doDragNDrop((tabBarStatus & TAB_DRAGNDROP) != 0); + TabBarPlus::setDrawTopBar((tabBarStatus & TAB_DRAWTOPBAR) != 0); + TabBarPlus::setDrawInactiveTab((tabBarStatus & TAB_DRAWINACTIVETAB) != 0); + TabBarPlus::setDrawTabCloseButton((tabBarStatus & TAB_CLOSEBUTTON) != 0); + TabBarPlus::setDbClk2Close((tabBarStatus & TAB_DBCLK2CLOSE) != 0); + TabBarPlus::setVertical((tabBarStatus & TAB_VERTICAL) != 0); + drawTabbarColoursFromStylerArray(); + + //--Splitter Section--// + bool isVertical = (nppGUI._splitterPos == POS_VERTICAL); + + _subSplitter.init(_hInst, _hSelf); + _subSplitter.create(&_mainDocTab, &_subDocTab, 8, DYNAMIC, 50, isVertical); + + //--Status Bar Section--// + bool willBeShown = nppGUI._statusBarShow; + _statusBar.init(_hInst, hwnd, 6); + _statusBar.setPartWidth(STATUSBAR_DOC_SIZE, 180); + _statusBar.setPartWidth(STATUSBAR_CUR_POS, 250); + _statusBar.setPartWidth(STATUSBAR_EOF_FORMAT, 80); + _statusBar.setPartWidth(STATUSBAR_UNICODE_TYPE, 100); + _statusBar.setPartWidth(STATUSBAR_TYPING_MODE, 30); + _statusBar.display(willBeShown); + + _pMainWindow = &_mainDocTab; + + _dockingManager.init(_hInst, hwnd, &_pMainWindow); + + if (nppGUI._isMinimizedToTray) + _pTrayIco = new trayIconControler(_hSelf, IDI_M30ICON, IDC_MINIMIZED_TRAY, ::LoadIcon(_hInst, MAKEINTRESOURCE(IDI_M30ICON)), TEXT("")); + + checkSyncState(); + + // Plugin Manager + NppData nppData; + nppData._nppHandle = _hSelf; + nppData._scintillaMainHandle = _mainEditView.getHSelf(); + nppData._scintillaSecondHandle = _subEditView.getHSelf(); + + _scintillaCtrls4Plugins.init(_hInst, hwnd); + _pluginsManager.init(nppData); + _pluginsManager.loadPlugins(); + const TCHAR *appDataNpp = pNppParam->getAppDataNppDir(); + if (appDataNpp[0]) + _pluginsManager.loadPlugins(appDataNpp); + + // ------------ // + // Menu Section // + // ------------ // + + // Macro Menu + std::vector & macros = pNppParam->getMacroList(); + HMENU hMacroMenu = ::GetSubMenu(_mainMenuHandle, MENUINDEX_MACRO); + size_t const posBase = 6; + size_t nbMacro = macros.size(); + if (nbMacro >= 1) + ::InsertMenu(hMacroMenu, posBase - 1, MF_BYPOSITION, (unsigned int)-1, 0); + for (size_t i = 0 ; i < nbMacro ; i++) + { + ::InsertMenu(hMacroMenu, posBase + i, MF_BYPOSITION, ID_MACRO + i, macros[i].toMenuItemString().c_str()); + } + // Run Menu + std::vector & userCommands = pNppParam->getUserCommandList(); + HMENU hRunMenu = ::GetSubMenu(_mainMenuHandle, MENUINDEX_RUN); + int const runPosBase = 2; + size_t nbUserCommand = userCommands.size(); + if (nbUserCommand >= 1) + ::InsertMenu(hRunMenu, runPosBase - 1, MF_BYPOSITION, (unsigned int)-1, 0); + for (size_t i = 0 ; i < nbUserCommand ; i++) + { + ::InsertMenu(hRunMenu, runPosBase + i, MF_BYPOSITION, ID_USER_CMD + i, userCommands[i].toMenuItemString().c_str()); + } + + // Updater menu item + if (!nppGUI._doesExistUpdater) + { + //::MessageBox(NULL, TEXT("pas de updater"), TEXT(""), MB_OK); + ::DeleteMenu(_mainMenuHandle, IDM_UPDATE_NPP, MF_BYCOMMAND); + ::DrawMenuBar(hwnd); + } + //Languages Menu + HMENU hLangMenu = ::GetSubMenu(_mainMenuHandle, MENUINDEX_LANGUAGE); + + // Add external languages to menu + for (int i = 0 ; i < pNppParam->getNbExternalLang() ; i++) + { + ExternalLangContainer & externalLangContainer = pNppParam->getELCFromIndex(i); + + int numLangs = ::GetMenuItemCount(hLangMenu); + const int bufferSize = 100; + TCHAR buffer[bufferSize]; + + int x; + for(x = 0; (x == 0 || lstrcmp(externalLangContainer._name, buffer) > 0) && x < numLangs; x++) + { + ::GetMenuString(hLangMenu, x, buffer, bufferSize, MF_BYPOSITION); + } + + ::InsertMenu(hLangMenu, x-1, MF_BYPOSITION, IDM_LANG_EXTERNAL + i, externalLangContainer._name); + } + + if (nppGUI._excludedLangList.size() > 0) + { + for (size_t i = 0 ; i < nppGUI._excludedLangList.size() ; i++) + { + int cmdID = pNppParam->langTypeToCommandID(nppGUI._excludedLangList[i]._langType); + const int itemSize = 256; + TCHAR itemName[itemSize]; + ::GetMenuString(hLangMenu, cmdID, itemName, itemSize, MF_BYCOMMAND); + nppGUI._excludedLangList[i]._cmdID = cmdID; + nppGUI._excludedLangList[i]._langName = itemName; + ::DeleteMenu(hLangMenu, cmdID, MF_BYCOMMAND); + DrawMenuBar(_hSelf); + } + } + + // Add User Define Languages Entry + int udlpos = ::GetMenuItemCount(hLangMenu) - 1; + + for (int i = 0 ; i < pNppParam->getNbUserLang() ; i++) + { + UserLangContainer & userLangContainer = pNppParam->getULCFromIndex(i); + ::InsertMenu(hLangMenu, udlpos + i, MF_BYPOSITION, IDM_LANG_USER + i + 1, userLangContainer.getName()); + } + + //Add recent files + HMENU hFileMenu = ::GetSubMenu(_mainMenuHandle, MENUINDEX_FILE); + int nbLRFile = pNppParam->getNbLRFile(); + int pos = IDM_FILEMENU_LASTONE - IDM_FILE + 2; + + _lastRecentFileList.initMenu(hFileMenu, IDM_FILEMENU_LASTONE + 1, pos); + for (int i = 0 ; i < nbLRFile ; i++) + { + generic_string * stdStr = pNppParam->getLRFile(i); + if (nppGUI._checkHistoryFiles) + { + if (PathFileExists(stdStr->c_str())) + { + _lastRecentFileList.add(stdStr->c_str()); + } + } + else + { + _lastRecentFileList.add(stdStr->c_str()); + } + } + + //Plugin menu + _pluginsManager.setMenu(_mainMenuHandle, NULL); + + //Main menu is loaded, now load context menu items + pNppParam->getContextMenuFromXmlTree(_mainMenuHandle); + + if (pNppParam->hasCustomContextMenu()) + { + _mainEditView.execute(SCI_USEPOPUP, FALSE); + _subEditView.execute(SCI_USEPOPUP, FALSE); + } + + generic_string pluginsTrans, windowTrans; + changeMenuLang(pluginsTrans, windowTrans); + + if (_pluginsManager.hasPlugins() && pluginsTrans != TEXT("")) + { + ::ModifyMenu(_mainMenuHandle, MENUINDEX_PLUGINS, MF_BYPOSITION, 0, pluginsTrans.c_str()); + } + //Windows menu + _windowsMenu.init(_hInst, _mainMenuHandle, windowTrans.c_str()); + + // Update context menu strings + vector & tmp = pNppParam->getContextMenuItems(); + size_t len = tmp.size(); + TCHAR menuName[64]; + for (size_t i = 0 ; i < len ; i++) + { + if (tmp[i]._itemName == TEXT("")) + { + ::GetMenuString(_mainMenuHandle, tmp[i]._cmdID, menuName, 64, MF_BYCOMMAND); + tmp[i]._itemName = purgeMenuItemString(menuName); + } + } + + //Input all the menu item names into shortcut list + //This will automatically do all translations, since menu translation has been done already + vector & shortcuts = pNppParam->getUserShortcuts(); + len = shortcuts.size(); + + for(size_t i = 0; i < len; i++) + { + CommandShortcut & csc = shortcuts[i]; + if (!csc.getName()[0]) + { //no predefined name, get name from menu and use that + ::GetMenuString(_mainMenuHandle, csc.getID(), menuName, 64, MF_BYCOMMAND); + csc.setName(purgeMenuItemString(menuName, true).c_str()); + } + } + //Translate non-menu shortcuts + changeShortcutLang(); + + //Update plugin shortcuts, all plugin commands should be available now + pNppParam->reloadPluginCmds(); + + // Shortcut Accelerator : should be the last one since it will capture all the shortcuts + _accelerator.init(_mainMenuHandle, _hSelf); + pNppParam->setAccelerator(&_accelerator); + + // Scintilla key accelerator + vector scints; + scints.push_back(_mainEditView.getHSelf()); + scints.push_back(_subEditView.getHSelf()); + _scintaccelerator.init(&scints, _mainMenuHandle, _hSelf); + + pNppParam->setScintillaAccelerator(&_scintaccelerator); + _scintaccelerator.updateKeys(); + + ::DrawMenuBar(_hSelf); + + + //-- Tool Bar Section --// + toolBarStatusType tbStatus = nppGUI._toolBarStatus; + willBeShown = nppGUI._toolbarShow; + + // To notify plugins that toolbar icons can be registered + SCNotification scnN; + scnN.nmhdr.code = NPPN_TBMODIFICATION; + scnN.nmhdr.hwndFrom = _hSelf; + scnN.nmhdr.idFrom = 0; + _pluginsManager.notify(&scnN); + + _toolBar.init(_hInst, hwnd, tbStatus, toolBarIcons, sizeof(toolBarIcons)/sizeof(ToolBarButtonUnit)); + + changeToolBarIcons(); + + _rebarTop.init(_hInst, hwnd); + _rebarBottom.init(_hInst, hwnd); + _toolBar.addToRebar(&_rebarTop); + _rebarTop.setIDVisible(REBAR_BAR_TOOLBAR, willBeShown); + + //--Init dialogs--// + _findReplaceDlg.init(_hInst, hwnd, &_pEditView); + _incrementFindDlg.init(_hInst, hwnd, &_findReplaceDlg, _isRTL); + _incrementFindDlg.addToRebar(&_rebarBottom); + _goToLineDlg.init(_hInst, hwnd, &_pEditView); + _colEditorDlg.init(_hInst, hwnd, &_pEditView); + _aboutDlg.init(_hInst, hwnd); + _runDlg.init(_hInst, hwnd); + _runMacroDlg.init(_hInst, hwnd); + + //--User Define Dialog Section--// + int uddStatus = nppGUI._userDefineDlgStatus; + UserDefineDialog *udd = _pEditView->getUserDefineDlg(); + + bool uddShow = false; + switch (uddStatus) + { + case UDD_SHOW : // show & undocked + udd->doDialog(true, _isRTL); + changeUserDefineLang(); + uddShow = true; + break; + case UDD_DOCKED : { // hide & docked + _isUDDocked = true; + break;} + case (UDD_SHOW | UDD_DOCKED) : // show & docked + udd->doDialog(true, _isRTL); + changeUserDefineLang(); + ::SendMessage(udd->getHSelf(), WM_COMMAND, IDC_DOCK_BUTTON, 0); + uddShow = true; + break; + + default : // hide & undocked + break; + } + // UserDefine Dialog + + checkMenuItem(IDM_VIEW_USER_DLG, uddShow); + _toolBar.setCheck(IDM_VIEW_USER_DLG, uddShow); + + //launch the plugin dlg memorized at the last session + DockingManagerData &dmd = nppGUI._dockingData; + + _dockingManager.setDockedContSize(CONT_LEFT , nppGUI._dockingData._leftWidth); + _dockingManager.setDockedContSize(CONT_RIGHT , nppGUI._dockingData._rightWidth); + _dockingManager.setDockedContSize(CONT_TOP , nppGUI._dockingData._topHeight); + _dockingManager.setDockedContSize(CONT_BOTTOM, nppGUI._dockingData._bottomHight); + + for (size_t i = 0 ; i < dmd._pluginDockInfo.size() ; i++) + { + PlugingDlgDockingInfo & pdi = dmd._pluginDockInfo[i]; + + if (pdi._isVisible) + _pluginsManager.runPluginCommand(pdi._name, pdi._internalID); + } + + for (size_t i = 0 ; i < dmd._containerTabInfo.size() ; i++) + { + ContainerTabInfo & cti = dmd._containerTabInfo[i]; + _dockingManager.setActiveTab(cti._cont, cti._activeTab); + } + //Load initial docs into doctab + loadBufferIntoView(_mainEditView.getCurrentBufferID(), MAIN_VIEW); + loadBufferIntoView(_subEditView.getCurrentBufferID(), SUB_VIEW); + activateBuffer(_mainEditView.getCurrentBufferID(), MAIN_VIEW); + activateBuffer(_subEditView.getCurrentBufferID(), SUB_VIEW); + MainFileManager->increaseDocNr(); //so next doc starts at 2 + + ::SetFocus(_mainEditView.getHSelf()); + result = TRUE; + } + break; + + case WM_DRAWITEM : + { + DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lParam; + if (dis->CtlType == ODT_TAB) + { + return ::SendMessage(dis->hwndItem, WM_DRAWITEM, wParam, lParam); + } + } + + case WM_DOCK_USERDEFINE_DLG: + { + dockUserDlg(); + return TRUE; + } + + case WM_UNDOCK_USERDEFINE_DLG: + { + undockUserDlg(); + return TRUE; + } + + case WM_REMOVE_USERLANG: + { + TCHAR name[256]; + lstrcpy(name, (TCHAR *)lParam); + //loop through buffers and reset the language (L_USER, TEXT("")) if (L_USER, name) + Buffer * buf; + for(int i = 0; i < MainFileManager->getNrBuffers(); i++) { + buf = MainFileManager->getBufferByIndex(i); + if (buf->getLangType() == L_USER && !lstrcmp(buf->getUserDefineLangName(), name)) + buf->setLangType(L_USER, TEXT("")); + } + return TRUE; + } + + case WM_RENAME_USERLANG: + { + TCHAR oldName[256]; + TCHAR newName[256]; + lstrcpy(oldName, (TCHAR *)lParam); + lstrcpy(newName, (TCHAR *)wParam); + //loop through buffers and reset the language (L_USER, newName) if (L_USER, oldName) + Buffer * buf; + for(int i = 0; i < MainFileManager->getNrBuffers(); i++) { + buf = MainFileManager->getBufferByIndex(i); + if (buf->getLangType() == L_USER && !lstrcmp(buf->getUserDefineLangName(), oldName)) + buf->setLangType(L_USER, newName); + } + return TRUE; + } + + case WM_CLOSE_USERDEFINE_DLG : + { + checkMenuItem(IDM_VIEW_USER_DLG, false); + _toolBar.setCheck(IDM_VIEW_USER_DLG, false); + return TRUE; + } + + case WM_REPLACEALL_INOPENEDDOC : + { + replaceAllFiles(); + return TRUE; + } + + case WM_FINDALL_INOPENEDDOC : + { + findInOpenedFiles(); + return TRUE; + } + + case WM_FINDALL_INCURRENTDOC : + { + findInCurrentFile(); + return TRUE; + } + + case WM_FINDINFILES : + { + return findInFiles(); + } + + case WM_REPLACEINFILES : + { + replaceInFiles(); + return TRUE; + } + case NPPM_LAUNCHFINDINFILESDLG : + { + const int strSize = FINDREPLACE_MAXLENGTH; + TCHAR str[strSize]; + + bool isFirstTime = !_findReplaceDlg.isCreated(); + _findReplaceDlg.doDialog(FIND_DLG, _isRTL); + + _pEditView->getGenericSelectedText(str, strSize); + _findReplaceDlg.setSearchText(str); + if (isFirstTime) + changeDlgLang(_findReplaceDlg.getHSelf(), "Find"); + _findReplaceDlg.launchFindInFilesDlg(); + setFindReplaceFolderFilter((const TCHAR*) wParam, (const TCHAR*) lParam); + return TRUE; + } + + case NPPM_DOOPEN: + case WM_DOOPEN: + { + BufferID id = doOpen((const TCHAR *)lParam); + if (id != BUFFER_INVALID) + { + return switchToFile(id); + } + } + break; + + case NPPM_INTERNAL_SETFILENAME: + { + if (!lParam && !wParam) + return FALSE; + BufferID id = (BufferID)wParam; + Buffer * b = MainFileManager->getBufferByID(id); + if (b && b->getStatus() == DOC_UNNAMED) { + b->setFileName((const TCHAR*)lParam); + return TRUE; + } + return FALSE; + } + break; + + case NPPM_GETBUFFERLANGTYPE: + { + if (!wParam) + return -1; + BufferID id = (BufferID)wParam; + Buffer * b = MainFileManager->getBufferByID(id); + return b->getLangType(); + } + break; + + case NPPM_SETBUFFERLANGTYPE: + { + if (!wParam) + return FALSE; + if (lParam < L_TXT || lParam >= L_EXTERNAL || lParam == L_USER) + return FALSE; + + BufferID id = (BufferID)wParam; + Buffer * b = MainFileManager->getBufferByID(id); + b->setLangType((LangType)lParam); + return TRUE; + } + break; + + case NPPM_GETBUFFERENCODING: + { + if (!wParam) + return -1; + BufferID id = (BufferID)wParam; + Buffer * b = MainFileManager->getBufferByID(id); + return b->getUnicodeMode(); + } + break; + + case NPPM_SETBUFFERENCODING: + { + if (!wParam) + return FALSE; + if (lParam < uni8Bit || lParam >= uniEnd) + return FALSE; + + BufferID id = (BufferID)wParam; + Buffer * b = MainFileManager->getBufferByID(id); + if (b->getStatus() != DOC_UNNAMED || b->isDirty()) //do not allow to change the encoding if the file has any content + return FALSE; + b->setUnicodeMode((UniMode)lParam); + return TRUE; + } + break; + + case NPPM_GETBUFFERFORMAT: + { + if (!wParam) + return -1; + BufferID id = (BufferID)wParam; + Buffer * b = MainFileManager->getBufferByID(id); + return b->getFormat(); + } + break; + + case NPPM_SETBUFFERFORMAT: + { + if (!wParam) + return FALSE; + if (lParam < WIN_FORMAT || lParam >= UNIX_FORMAT) + return FALSE; + + BufferID id = (BufferID)wParam; + Buffer * b = MainFileManager->getBufferByID(id); + b->setFormat((formatType)lParam); + return TRUE; + } + break; + + case NPPM_GETBUFFERIDFROMPOS: + { + DocTabView * pView = NULL; + if (lParam == MAIN_VIEW) { + pView = &_mainDocTab; + } else if (lParam == SUB_VIEW) { + pView = &_subDocTab; + } else { + return (LRESULT)BUFFER_INVALID; + } + if ((int)wParam < pView->nbItem()) { + return (LRESULT)(pView->getBufferByIndex((int)wParam)); + } + return (LRESULT)BUFFER_INVALID; + } + break; + + case NPPM_GETCURRENTBUFFERID: + { + return (LRESULT)(_pEditView->getCurrentBufferID()); + } + break; + + case NPPM_RELOADBUFFERID: + { + if (!wParam) + return FALSE; + return doReload((BufferID)wParam, lParam != 0); + } + break; + + case NPPM_RELOADFILE: + { + BufferID id = MainFileManager->getBufferFromName((const TCHAR *)lParam); + if (id != BUFFER_INVALID) + doReload(id, wParam != 0); + } + break; + + case NPPM_SWITCHTOFILE : + { + BufferID id = MainFileManager->getBufferFromName((const TCHAR *)lParam); + if (id != BUFFER_INVALID) + return switchToFile(id); + return false; + } + + case NPPM_SAVECURRENTFILE: + { + return fileSave(); + } + break; + + case NPPM_SAVEALLFILES: + { + return fileSaveAll(); + } + break; + + case WM_SIZE: + { + RECT rc; + getClientRect(rc); + if (lParam == 0) { + lParam = MAKELPARAM(rc.right - rc.left, rc.bottom - rc.top); + } + + ::MoveWindow(_rebarTop.getHSelf(), 0, 0, rc.right, _rebarTop.getHeight(), TRUE); + _statusBar.adjustParts(rc.right); + ::SendMessage(_statusBar.getHSelf(), WM_SIZE, wParam, lParam); + + int rebarBottomHeight = _rebarBottom.getHeight(); + int statusBarHeight = _statusBar.getHeight(); + ::MoveWindow(_rebarBottom.getHSelf(), 0, rc.bottom - rebarBottomHeight - statusBarHeight, rc.right, rebarBottomHeight, TRUE); + + getMainClientRect(rc); + _dockingManager.reSizeTo(rc); + + result = TRUE; + } + break; + + case WM_MOVE: + { + result = TRUE; + } + break; + + case WM_MOVING: + { + result = FALSE; + } + break; + + case WM_SIZING: + { + result = FALSE; + } + break; + + case WM_COPYDATA : + { + COPYDATASTRUCT *pCopyData = (COPYDATASTRUCT *)lParam; + + switch (pCopyData->dwData) + { + case COPYDATA_PARAMS : + { + pNppParam->setCmdlineParam(*((CmdLineParams *)pCopyData->lpData)); + break; + } + + case COPYDATA_FILENAMESA : + { + char *fileNamesA = (char *)pCopyData->lpData; + CmdLineParams & cmdLineParams = pNppParam->getCmdLineParams(); +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + const wchar_t *fileNamesW = wmc->char2wchar(fileNamesA, CP_ACP); + loadCommandlineParams(fileNamesW, &cmdLineParams); +#else + loadCommandlineParams(fileNamesA, &cmdLineParams); +#endif + break; + } + + case COPYDATA_FILENAMESW : + { + wchar_t *fileNamesW = (wchar_t *)pCopyData->lpData; + CmdLineParams & cmdLineParams = pNppParam->getCmdLineParams(); + +#ifdef UNICODE + loadCommandlineParams(fileNamesW, &cmdLineParams); +#else + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + const char *fileNamesA = wmc->wchar2char(fileNamesW, CP_ACP); + loadCommandlineParams(fileNamesA, &cmdLineParams); +#endif + break; + } + } + + return TRUE; + } + + case WM_COMMAND: + if (HIWORD(wParam) == SCEN_SETFOCUS) + { + HWND hMain = _mainEditView.getHSelf(), hSec = _subEditView.getHSelf(); + HWND hFocus = (HWND)lParam; + if (hMain == hFocus) + switchEditViewTo(MAIN_VIEW); + else if (hSec == hFocus) + switchEditViewTo(SUB_VIEW); + else { + //Other Scintilla, ignore + } + return TRUE; + } + else + { + if ((lParam == 1) || (lParam == 2)) + { + specialCmd(LOWORD(wParam), lParam); + } + else + command(LOWORD(wParam)); + } + return TRUE; + + case NPPM_INTERNAL_RELOADNATIVELANG: + { + reloadLang(); + } + return TRUE; + + case NPPM_INTERNAL_RELOADSTYLERS: + { + loadStyles(); + } + return TRUE; + + case NPPM_INTERNAL_PLUGINSHORTCUTMOTIFIED: + { + SCNotification scnN; + scnN.nmhdr.code = NPPN_SHORTCUTREMAPPED; + scnN.nmhdr.hwndFrom = (void *)lParam; // ShortcutKey structure + scnN.nmhdr.idFrom = (uptr_t)wParam; // cmdID + _pluginsManager.notify(&scnN); + } + return TRUE; + + case NPPM_GETSHORTCUTBYCMDID: + { + int cmdID = wParam; // cmdID + ShortcutKey *sk = (ShortcutKey *)lParam; // ShortcutKey structure + + return _pluginsManager.getShortcutByCmdID(cmdID, sk); + } + + case NPPM_MENUCOMMAND : + command(lParam); + return TRUE; + + case NPPM_GETFULLCURRENTPATH : + case NPPM_GETCURRENTDIRECTORY : + case NPPM_GETFILENAME : + case NPPM_GETNAMEPART : + case NPPM_GETEXTPART : + { + TCHAR str[MAX_PATH]; + // par defaut : NPPM_GETCURRENTDIRECTORY + TCHAR *fileStr = lstrcpy(str, _pEditView->getCurrentBuffer()->getFullPathName()); + + if (Message == NPPM_GETCURRENTDIRECTORY) + PathRemoveFileSpec(str); + else if (Message == NPPM_GETFILENAME) + fileStr = PathFindFileName(str); + else if (Message == NPPM_GETNAMEPART) + { + fileStr = PathFindFileName(str); + PathRemoveExtension(fileStr); + } + else if (Message == NPPM_GETEXTPART) + fileStr = PathFindExtension(str); + + // For the compability reason, if wParam is 0, then we assume the size of generic_string buffer (lParam) is large enough. + // otherwise we check if the generic_string buffer size is enough for the generic_string to copy. + if (wParam != 0) + { + if (lstrlen(fileStr) >= int(wParam)) + { + ::MessageBox(_hSelf, TEXT("Allocated buffer size is not enough to copy the string."), TEXT("NPPM error"), MB_OK); + return FALSE; + } + } + + lstrcpy((TCHAR *)lParam, fileStr); + return TRUE; + } + + case NPPM_GETCURRENTWORD : + { + const int strSize = CURRENTWORD_MAXLENGTH; + TCHAR str[strSize]; + + _pEditView->getGenericSelectedText((TCHAR *)str, strSize); + // For the compability reason, if wParam is 0, then we assume the size of generic_string buffer (lParam) is large enough. + // otherwise we check if the generic_string buffer size is enough for the generic_string to copy. + if (wParam != 0) + { + if (lstrlen(str) >= int(wParam)) //buffer too small + { + ::MessageBox(_hSelf, TEXT("Allocated buffer size is not enough to copy the string."), TEXT("NPPM_GETCURRENTWORD error"), MB_OK); + return FALSE; + } + else //buffer large enough, perform safe copy + { + lstrcpyn((TCHAR *)lParam, str, wParam); + return TRUE; + } + } + + lstrcpy((TCHAR *)lParam, str); + return TRUE; + } + + case NPPM_GETNPPDIRECTORY : + { + const int strSize = MAX_PATH; + TCHAR str[strSize]; + + ::GetModuleFileName(NULL, str, strSize); + PathRemoveFileSpec(str); + + // For the compability reason, if wParam is 0, then we assume the size of generic_string buffer (lParam) is large enough. + // otherwise we check if the generic_string buffer size is enough for the generic_string to copy. + if (wParam != 0) + { + if (lstrlen(str) >= int(wParam)) + { + ::MessageBox(_hSelf, TEXT("Allocated buffer size is not enough to copy the string."), TEXT("NPPM_GETNPPDIRECTORY error"), MB_OK); + return FALSE; + } + } + + lstrcpy((TCHAR *)lParam, str); + return TRUE; + } + + case NPPM_GETCURRENTLINE : + { + return _pEditView->getCurrentLineNumber(); + } + + case NPPM_GETCURRENTCOLUMN : + { + return _pEditView->getCurrentColumnNumber(); + } + + case NPPM_GETCURRENTSCINTILLA : + { + if (_pEditView == &_mainEditView) + *((int *)lParam) = MAIN_VIEW; + else if (_pEditView == &_subEditView) + *((int *)lParam) = SUB_VIEW; + else + *((int *)lParam) = -1; + return TRUE; + } + + case NPPM_GETCURRENTLANGTYPE : + { + *((LangType *)lParam) = _pEditView->getCurrentBuffer()->getLangType(); + return TRUE; + } + + case NPPM_SETCURRENTLANGTYPE : + { + _pEditView->getCurrentBuffer()->setLangType((LangType)lParam); + return TRUE; + } + + case NPPM_GETNBOPENFILES : + { + int nbDocPrimary = _mainDocTab.nbItem(); + int nbDocSecond = _subDocTab.nbItem(); + if (lParam == ALL_OPEN_FILES) + return nbDocPrimary + nbDocSecond; + else if (lParam == PRIMARY_VIEW) + return nbDocPrimary; + else if (lParam == SECOND_VIEW) + return nbDocSecond; + } + + case NPPM_GETOPENFILENAMESPRIMARY : + case NPPM_GETOPENFILENAMESSECOND : + case NPPM_GETOPENFILENAMES : + { + if (!wParam) return 0; + + TCHAR **fileNames = (TCHAR **)wParam; + int nbFileNames = lParam; + + int j = 0; + if (Message != NPPM_GETOPENFILENAMESSECOND) { + for (int i = 0 ; i < _mainDocTab.nbItem() && j < nbFileNames ; i++) + { + BufferID id = _mainDocTab.getBufferByIndex(i); + Buffer * buf = MainFileManager->getBufferByID(id); + lstrcpy(fileNames[j++], buf->getFullPathName()); + } + } + if (Message != NPPM_GETOPENFILENAMESPRIMARY) { + for (int i = 0 ; i < _subDocTab.nbItem() && j < nbFileNames ; i++) + { + BufferID id = _subDocTab.getBufferByIndex(i); + Buffer * buf = MainFileManager->getBufferByID(id); + lstrcpy(fileNames[j++], buf->getFullPathName()); + } + } + return j; + } + + case WM_GETTASKLISTINFO : + { + if (!wParam) return 0; + TaskListInfo * tli = (TaskListInfo *)wParam; + getTaskListInfo(tli); + + if (NppParameters::getInstance()->getNppGUI()._styleMRU) + { + tli->_currentIndex = 0; + std::sort(tli->_tlfsLst.begin(),tli->_tlfsLst.end(),SortTaskListPred(_mainDocTab,_subDocTab)); + } + else + { + for(int idx = 0; idx < (int)tli->_tlfsLst.size(); ++idx) + { + if(tli->_tlfsLst[idx]._iView == currentView() && + tli->_tlfsLst[idx]._docIndex == _pDocTab->getCurrentTabIndex()) + { + tli->_currentIndex = idx; + break; + } + } + } + return TRUE; + } + + case WM_MOUSEWHEEL : + { + if (LOWORD(wParam) & MK_RBUTTON) + { + // redirect to the IDC_PREV_DOC or IDC_NEXT_DOC so that we have the unified process + + pNppParam->_isTaskListRBUTTONUP_Active = true; + short zDelta = (short) HIWORD(wParam); + return ::SendMessage(_hSelf, WM_COMMAND, zDelta>0?IDC_PREV_DOC:IDC_NEXT_DOC, 0); + } + return TRUE; + } + + case WM_APPCOMMAND : + { + switch(GET_APPCOMMAND_LPARAM(lParam)) + { + case APPCOMMAND_BROWSER_BACKWARD : + case APPCOMMAND_BROWSER_FORWARD : + int nbDoc = viewVisible(MAIN_VIEW)?_mainDocTab.nbItem():0; + nbDoc += viewVisible(SUB_VIEW)?_subDocTab.nbItem():0; + if (nbDoc > 1) + activateNextDoc((GET_APPCOMMAND_LPARAM(lParam) == APPCOMMAND_BROWSER_FORWARD)?dirDown:dirUp); + _linkTriggered = true; + } + return ::DefWindowProc(hwnd, Message, wParam, lParam); + } + + case NPPM_GETNBSESSIONFILES : + { + const TCHAR *sessionFileName = (const TCHAR *)lParam; + if ((!sessionFileName) || (sessionFileName[0] == '\0')) return 0; + Session session2Load; + if (pNppParam->loadSession(session2Load, sessionFileName)) + { + return session2Load.nbMainFiles() + session2Load.nbSubFiles(); + } + return 0; + } + + case NPPM_GETSESSIONFILES : + { + const TCHAR *sessionFileName = (const TCHAR *)lParam; + TCHAR **sessionFileArray = (TCHAR **)wParam; + + if ((!sessionFileName) || (sessionFileName[0] == '\0')) return FALSE; + + Session session2Load; + if (pNppParam->loadSession(session2Load, sessionFileName)) + { + size_t i = 0; + for ( ; i < session2Load.nbMainFiles() ; ) + { + const TCHAR *pFn = session2Load._mainViewFiles[i]._fileName.c_str(); + lstrcpy(sessionFileArray[i++], pFn); + } + + for (size_t j = 0 ; j < session2Load.nbSubFiles() ; j++) + { + const TCHAR *pFn = session2Load._subViewFiles[j]._fileName.c_str(); + lstrcpy(sessionFileArray[i++], pFn); + } + return TRUE; + } + return FALSE; + } + + case NPPM_DECODESCI: + { + // convert to ASCII + Utf8_16_Write UnicodeConvertor; + UINT length = 0; + char* buffer = NULL; + ScintillaEditView *pSci; + + if (wParam == MAIN_VIEW) + pSci = &_mainEditView; + else if (wParam == SUB_VIEW) + pSci = &_subEditView; + else + return -1; + + + // get text of current scintilla + length = pSci->execute(SCI_GETTEXTLENGTH, 0, 0) + 1; + buffer = new char[length]; + pSci->execute(SCI_GETTEXT, length, (LPARAM)buffer); + + // convert here + UniMode unicodeMode = pSci->getCurrentBuffer()->getUnicodeMode(); + UnicodeConvertor.setEncoding(unicodeMode); + length = UnicodeConvertor.convert(buffer, length-1); + + // set text in target + pSci->execute(SCI_CLEARALL); + pSci->addText(length, UnicodeConvertor.getNewBuf()); + pSci->execute(SCI_EMPTYUNDOBUFFER); + + pSci->execute(SCI_SETCODEPAGE); + + // set cursor position + pSci->execute(SCI_GOTOPOS); + + // clean buffer + delete [] buffer; + + return unicodeMode; + } + + case NPPM_ENCODESCI: + { + // convert + Utf8_16_Read UnicodeConvertor; + UINT length = 0; + char* buffer = NULL; + ScintillaEditView *pSci; + + if (wParam == MAIN_VIEW) + pSci = &_mainEditView; + else if (wParam == SUB_VIEW) + pSci = &_subEditView; + else + return -1; + + // get text of current scintilla + length = pSci->execute(SCI_GETTEXTLENGTH, 0, 0) + 1; + buffer = new char[length]; + pSci->execute(SCI_GETTEXT, length, (LPARAM)buffer); + + length = UnicodeConvertor.convert(buffer, length-1); + + // set text in target + pSci->execute(SCI_CLEARALL); + pSci->addText(length, UnicodeConvertor.getNewBuf()); + + + + pSci->execute(SCI_EMPTYUNDOBUFFER); + + // set cursor position + pSci->execute(SCI_GOTOPOS); + + // clean buffer + delete [] buffer; + + // set new encoding if BOM was changed by other programms + UniMode um = UnicodeConvertor.getEncoding(); + (pSci->getCurrentBuffer())->setUnicodeMode(um); + (pSci->getCurrentBuffer())->setDirty(true); + return um; + } + + case NPPM_ACTIVATEDOC : + case NPPM_TRIGGERTABBARCONTEXTMENU: + { + // similar to NPPM_ACTIVEDOC + int whichView = ((wParam != MAIN_VIEW) && (wParam != SUB_VIEW))?currentView():wParam; + int index = lParam; + + switchEditViewTo(whichView); + activateDoc(index); + + if (Message == NPPM_TRIGGERTABBARCONTEXTMENU) + { + // open here tab menu + NMHDR nmhdr; + nmhdr.code = NM_RCLICK; + + nmhdr.hwndFrom = (whichView == MAIN_VIEW)?_mainDocTab.getHSelf():_subDocTab.getHSelf(); + + nmhdr.idFrom = ::GetDlgCtrlID(nmhdr.hwndFrom); + ::SendMessage(_hSelf, WM_NOTIFY, nmhdr.idFrom, (LPARAM)&nmhdr); + } + return TRUE; + } + + case NPPM_GETNPPVERSION: + { + const TCHAR * verStr = VERSION_VALUE; + TCHAR mainVerStr[16]; + TCHAR auxVerStr[16]; + bool isDot = false; + int j =0; + int k = 0; + for (int i = 0 ; verStr[i] ; i++) + { + if (verStr[i] == '.') + isDot = true; + else + { + if (!isDot) + mainVerStr[j++] = verStr[i]; + else + auxVerStr[k++] = verStr[i]; + } + } + mainVerStr[j] = '\0'; + auxVerStr[k] = '\0'; + + int mainVer, auxVer = 0; + if (mainVerStr) + mainVer = generic_atoi(mainVerStr); + if (auxVerStr) + auxVer = generic_atoi(auxVerStr); + + return MAKELONG(auxVer, mainVer); + } + + case WM_ISCURRENTMACRORECORDED : + return (!_macro.empty() && !_recordingMacro); + + case WM_MACRODLGRUNMACRO: + { + if (!_recordingMacro) // if we're not currently recording, then playback the recorded keystrokes + { + int times = 1; + if (_runMacroDlg.getMode() == RM_RUN_MULTI) + { + times = _runMacroDlg.getTimes(); + } + else if (_runMacroDlg.getMode() == RM_RUN_EOF) + { + times = -1; + } + else + { + break; + } + + int counter = 0; + int lastLine = int(_pEditView->execute(SCI_GETLINECOUNT)) - 1; + int currLine = _pEditView->getCurrentLineNumber(); + int indexMacro = _runMacroDlg.getMacro2Exec(); + int deltaLastLine = 0; + int deltaCurrLine = 0; + + Macro m = _macro; + + if (indexMacro != -1) + { + vector & ms = pNppParam->getMacroList(); + m = ms[indexMacro].getMacro(); + } + + _pEditView->execute(SCI_BEGINUNDOACTION); + while (true) + { + for (Macro::iterator step = m.begin(); step != m.end(); step++) + step->PlayBack(this, _pEditView); + + counter++; + if ( times >= 0 ) + { + if ( counter >= times ) break; + } + else // run until eof + { + bool cursorMovedUp = deltaCurrLine < 0; + deltaLastLine = int(_pEditView->execute(SCI_GETLINECOUNT)) - 1 - lastLine; + deltaCurrLine = _pEditView->getCurrentLineNumber() - currLine; + + if (( deltaCurrLine == 0 ) // line no. not changed? + && (deltaLastLine >= 0)) // and no lines removed? + break; // exit + + // Update the line count, but only if the number of lines remaining is shrinking. + // Otherwise, the macro playback may never end. + if (deltaLastLine < deltaCurrLine) + lastLine += deltaLastLine; + + // save current line + currLine += deltaCurrLine; + + // eof? + if ((currLine >= lastLine) || (currLine < 0) + || ((deltaCurrLine == 0) && (currLine == 0) && ((deltaLastLine >= 0) || cursorMovedUp))) + break; + } + } + _pEditView->execute(SCI_ENDUNDOACTION); + } + } + break; + + case NPPM_CREATESCINTILLAHANDLE : + { + return (LRESULT)_scintillaCtrls4Plugins.createSintilla((lParam == NULL?_hSelf:(HWND)lParam)); + } + + case NPPM_DESTROYSCINTILLAHANDLE : + { + return _scintillaCtrls4Plugins.destroyScintilla((HWND)lParam); + } + + case NPPM_GETNBUSERLANG : + { + if (lParam) + *((int *)lParam) = IDM_LANG_USER; + return pNppParam->getNbUserLang(); + } + + case NPPM_GETCURRENTDOCINDEX : + { + if (lParam == SUB_VIEW) + { + if (!viewVisible(SUB_VIEW)) + return -1; + return _subDocTab.getCurrentTabIndex(); + } + else //MAIN_VIEW + { + if (!viewVisible(MAIN_VIEW)) + return -1; + return _mainDocTab.getCurrentTabIndex(); + } + } + + case NPPM_SETSTATUSBAR : + { + TCHAR *str2set = (TCHAR *)lParam; + if (!str2set || !str2set[0]) + return FALSE; + + switch (wParam) + { + case STATUSBAR_DOC_TYPE : + case STATUSBAR_DOC_SIZE : + case STATUSBAR_CUR_POS : + case STATUSBAR_EOF_FORMAT : + case STATUSBAR_UNICODE_TYPE : + case STATUSBAR_TYPING_MODE : + _statusBar.setText(str2set, wParam); + return TRUE; + default : + return FALSE; + } + } + + case NPPM_GETMENUHANDLE : + { + if (wParam == NPPPLUGINMENU) + return (LRESULT)_pluginsManager.getMenuHandle(); + else + return NULL; + } + + case NPPM_LOADSESSION : + { + fileLoadSession((const TCHAR *)lParam); + return TRUE; + } + + case NPPM_SAVECURRENTSESSION : + { + return (LRESULT)fileSaveSession(0, NULL, (const TCHAR *)lParam); + } + + case NPPM_SAVESESSION : + { + sessionInfo *pSi = (sessionInfo *)lParam; + return (LRESULT)fileSaveSession(pSi->nbFile, pSi->files, pSi->sessionFilePathName); + } + + case NPPM_INTERNAL_CLEARSCINTILLAKEY : + { + _mainEditView.execute(SCI_CLEARCMDKEY, wParam); + _subEditView.execute(SCI_CLEARCMDKEY, wParam); + return TRUE; + } + case NPPM_INTERNAL_BINDSCINTILLAKEY : + { + _mainEditView.execute(SCI_ASSIGNCMDKEY, wParam, lParam); + _subEditView.execute(SCI_ASSIGNCMDKEY, wParam, lParam); + + return TRUE; + } + case NPPM_INTERNAL_CMDLIST_MODIFIED : + { + //changeMenuShortcut(lParam, (const TCHAR *)wParam); + ::DrawMenuBar(_hSelf); + return TRUE; + } + + case NPPM_INTERNAL_MACROLIST_MODIFIED : + { + return TRUE; + } + + case NPPM_INTERNAL_USERCMDLIST_MODIFIED : + { + return TRUE; + } + + case NPPM_INTERNAL_SETCARETWIDTH : + { + NppGUI & nppGUI = (NppGUI &)pNppParam->getNppGUI(); + + if (nppGUI._caretWidth < 4) + { + _mainEditView.execute(SCI_SETCARETSTYLE, CARETSTYLE_LINE); + _subEditView.execute(SCI_SETCARETSTYLE, CARETSTYLE_LINE); + _mainEditView.execute(SCI_SETCARETWIDTH, nppGUI._caretWidth); + _subEditView.execute(SCI_SETCARETWIDTH, nppGUI._caretWidth); + } + else + { + _mainEditView.execute(SCI_SETCARETWIDTH, 1); + _subEditView.execute(SCI_SETCARETWIDTH, 1); + _mainEditView.execute(SCI_SETCARETSTYLE, CARETSTYLE_BLOCK); + _subEditView.execute(SCI_SETCARETSTYLE, CARETSTYLE_BLOCK); + } + return TRUE; + } + + case NPPM_INTERNAL_SETCARETBLINKRATE : + { + NppGUI & nppGUI = (NppGUI &)pNppParam->getNppGUI(); + _mainEditView.execute(SCI_SETCARETPERIOD, nppGUI._caretBlinkRate); + _subEditView.execute(SCI_SETCARETPERIOD, nppGUI._caretBlinkRate); + return TRUE; + } + + case NPPM_INTERNAL_ISTABBARREDUCED : + { + return _toReduceTabBar?TRUE:FALSE; + } + + // ADD: success->hwnd; failure->NULL + // REMOVE: success->NULL; failure->hwnd + case NPPM_MODELESSDIALOG : + { + if (wParam == MODELESSDIALOGADD) + { + for (size_t i = 0 ; i < _hModelessDlgs.size() ; i++) + if (_hModelessDlgs[i] == (HWND)lParam) + return NULL; + _hModelessDlgs.push_back((HWND)lParam); + return lParam; + } + else if (wParam == MODELESSDIALOGREMOVE) + { + for (size_t i = 0 ; i < _hModelessDlgs.size() ; i++) + if (_hModelessDlgs[i] == (HWND)lParam) + { + vector::iterator hDlg = _hModelessDlgs.begin() + i; + _hModelessDlgs.erase(hDlg); + return NULL; + } + return lParam; + } + return TRUE; + } + + case WM_CONTEXTMENU : + { + if (pNppParam->_isTaskListRBUTTONUP_Active) + { + pNppParam->_isTaskListRBUTTONUP_Active = false; + } + else + { + if ((HWND(wParam) == _mainEditView.getHSelf()) || (HWND(wParam) == _subEditView.getHSelf())) + { + if ((HWND(wParam) == _mainEditView.getHSelf())) { + switchEditViewTo(MAIN_VIEW); + } else { + switchEditViewTo(SUB_VIEW); + } + POINT p; + ::GetCursorPos(&p); + ContextMenu scintillaContextmenu; + vector & tmp = pNppParam->getContextMenuItems(); + vector isEnable; + for (size_t i = 0 ; i < tmp.size() ; i++) + { + isEnable.push_back((::GetMenuState(_mainMenuHandle, tmp[i]._cmdID, MF_BYCOMMAND)&MF_DISABLED) == 0); + } + scintillaContextmenu.create(_hSelf, tmp); + for (size_t i = 0 ; i < isEnable.size() ; i++) + scintillaContextmenu.enableItem(tmp[i]._cmdID, isEnable[i]); + + scintillaContextmenu.display(p); + return TRUE; + } + } + + return ::DefWindowProc(hwnd, Message, wParam, lParam); + } + + case WM_NOTIFY: + { + checkClipboard(); + checkUndoState(); + checkMacroState(); + _pluginsManager.notify(reinterpret_cast(lParam)); + return notify(reinterpret_cast(lParam)); + } + + case NPPM_INTERNAL_CHECKDOCSTATUS : + case WM_ACTIVATEAPP : + { + if (wParam == TRUE) // if npp is about to be activated + { + const NppGUI & nppgui = pNppParam->getNppGUI(); + if (LOWORD(wParam) && (nppgui._fileAutoDetection != cdDisabled)) + { + _activeAppInf._isActivated = true; + checkModifiedDocument(); + return FALSE; + } + } + break; + } + + case NPPM_INTERNAL_GETCHECKDOCOPT : + { + return (LRESULT)((NppGUI &)(pNppParam->getNppGUI()))._fileAutoDetection; + } + + case NPPM_INTERNAL_SETCHECKDOCOPT : + { + // If nothing is changed by user, then we allow to set this value + if (((NppGUI &)(pNppParam->getNppGUI()))._fileAutoDetection == ((NppGUI &)(pNppParam->getNppGUI()))._fileAutoDetectionOriginalValue) + ((NppGUI &)(pNppParam->getNppGUI()))._fileAutoDetection = (ChangeDetect)wParam; + return TRUE; + } + + case NPPM_GETPOSFROMBUFFERID : + { + int i; + + if ((i = _mainDocTab.getIndexByBuffer((BufferID)wParam)) != -1) + { + long view = MAIN_VIEW; + view <<= 30; + return view|i; + } + if ((i = _subDocTab.getIndexByBuffer((BufferID)wParam)) != -1) + { + long view = SUB_VIEW; + view <<= 30; + return view|i; + } + return -1; + } + + case NPPM_GETFULLPATHFROMBUFFERID : + { + return MainFileManager->getFileNameFromBuffer((BufferID)wParam, (TCHAR *)lParam); + } + + case NPPM_INTERNAL_ENABLECHECKDOCOPT: + { + NppGUI & nppgui = (NppGUI &)(pNppParam->getNppGUI()); + if (wParam == CHECKDOCOPT_NONE) + nppgui._fileAutoDetection = cdDisabled; + else if (wParam == CHECKDOCOPT_UPDATESILENTLY) + nppgui._fileAutoDetection = cdAutoUpdate; + else if (wParam == CHECKDOCOPT_UPDATEGO2END) + nppgui._fileAutoDetection = cdGo2end; + else if (wParam == (CHECKDOCOPT_UPDATESILENTLY | CHECKDOCOPT_UPDATEGO2END)) + nppgui._fileAutoDetection = cdAutoUpdateGo2end; + + return TRUE; + } + + case WM_ACTIVATE : + _pEditView->getFocus(); + return TRUE; + + case WM_DROPFILES: + { + dropFiles(reinterpret_cast(wParam)); + return TRUE; + } + + case WM_UPDATESCINTILLAS: + { + //reset styler for change in Stylers.xml + _mainEditView.defineDocType(_mainEditView.getCurrentBuffer()->getLangType()); + _subEditView.defineDocType(_subEditView.getCurrentBuffer()->getLangType()); + _mainEditView.performGlobalStyles(); + _subEditView.performGlobalStyles(); + _findReplaceDlg.updateFinderScintilla(); + + drawTabbarColoursFromStylerArray(); + + // Notify plugins of update to styles xml + SCNotification scnN; + scnN.nmhdr.code = NPPN_WORDSTYLESUPDATED; + scnN.nmhdr.hwndFrom = _hSelf; + scnN.nmhdr.idFrom = (uptr_t) _pEditView->getCurrentBufferID(); + _pluginsManager.notify(&scnN); + return TRUE; + } + + case WM_QUERYENDSESSION: + case WM_CLOSE: + { + const NppGUI & nppgui = pNppParam->getNppGUI(); + + Session currentSession; + if (nppgui._rememberLastSession) + { + getCurrentOpenedFiles(currentSession); + //Lock the recent file list so it isnt populated with opened files + //Causing them to show on restart even though they are loaded by session + _lastRecentFileList.setLock(true); //only lock when the session is remembered + } + + bool allClosed = fileCloseAll(); //try closing files before doing anything else + + if (nppgui._rememberLastSession) + { + _lastRecentFileList.setLock(false); //only lock when the session is remembered + } + + if (!allClosed) + { + //User cancelled the shutdown + return FALSE; + } + + if (_beforeSpecialView.isFullScreen) //closing, return to windowed mode + fullScreenToggle(); + if (_beforeSpecialView.isPostIt) //closing, return to windowed mode + postItToggle(); + + if (_configStyleDlg.isCreated() && ::IsWindowVisible(_configStyleDlg.getHSelf())) + _configStyleDlg.restoreGlobalOverrideValues(); + + SCNotification scnN; + scnN.nmhdr.code = NPPN_SHUTDOWN; + scnN.nmhdr.hwndFrom = _hSelf; + scnN.nmhdr.idFrom = 0; + _pluginsManager.notify(&scnN); + + saveFindHistory(); + + _lastRecentFileList.saveLRFL(); + saveScintillaParams(SCIV_PRIMARY); + saveScintillaParams(SCIV_SECOND); + saveGUIParams(); + saveUserDefineLangs(); + saveShortcuts(); + if (nppgui._rememberLastSession) + saveSession(currentSession); + + //Sends WM_DESTROY, Notepad++ will end + ::DestroyWindow(hwnd); + + return TRUE; + } + + case WM_DESTROY: + { + killAllChildren(); + ::PostQuitMessage(0); + gNppHWND = NULL; + return TRUE; + } + + case WM_SYSCOMMAND: + { + NppGUI & nppgui = (NppGUI &)(pNppParam->getNppGUI()); + if ((nppgui._isMinimizedToTray) && (wParam == SC_MINIMIZE)) + { + if (!_pTrayIco) + _pTrayIco = new trayIconControler(_hSelf, IDI_M30ICON, IDC_MINIMIZED_TRAY, ::LoadIcon(_hInst, MAKEINTRESOURCE(IDI_M30ICON)), TEXT("")); + + _pTrayIco->doTrayIcon(ADD); + ::ShowWindow(hwnd, SW_HIDE); + return TRUE; + } + + if (wParam == SC_KEYMENU && lParam == VK_SPACE) + { + _sysMenuEntering = true; + } + else if (wParam == 0xF093) //it should be SC_MOUSEMENU. A bug? + { + _sysMenuEntering = true; + } + + return ::DefWindowProc(hwnd, Message, wParam, lParam); + } + + case WM_LBUTTONDBLCLK: + { + ::SendMessage(_hSelf, WM_COMMAND, IDM_FILE_NEW, 0); + return TRUE; + } + + case IDC_MINIMIZED_TRAY: + { + switch (lParam) + { + //case WM_LBUTTONDBLCLK: + case WM_LBUTTONUP : + _pEditView->getFocus(); + ::ShowWindow(_hSelf, SW_SHOW); + _pTrayIco->doTrayIcon(REMOVE); + ::SendMessage(_hSelf, WM_SIZE, 0, 0); + return TRUE; +/* + case WM_RBUTTONUP: + { + POINT p; + GetCursorPos(&p); + TrackPopupMenu(hTrayIconMenu, TPM_LEFTALIGN, p.x, p.y, 0, hwnd, NULL); + return TRUE; + } +*/ + } + return TRUE; + } + + case NPPM_DMMSHOW: + { + _dockingManager.showDockableDlg((HWND)lParam, SW_SHOW); + return TRUE; + } + + case NPPM_DMMHIDE: + { + _dockingManager.showDockableDlg((HWND)lParam, SW_HIDE); + return TRUE; + } + + case NPPM_DMMUPDATEDISPINFO: + { + if (::IsWindowVisible((HWND)lParam)) + _dockingManager.updateContainerInfo((HWND)lParam); + return TRUE; + } + + case NPPM_DMMREGASDCKDLG: + { + tTbData *pData = (tTbData *)lParam; + int iCont = -1; + bool isVisible = false; + + getIntegralDockingData(*pData, iCont, isVisible); + _dockingManager.createDockableDlg(*pData, iCont, isVisible); + return TRUE; + } + + case NPPM_DMMVIEWOTHERTAB: + { + _dockingManager.showDockableDlg((TCHAR*)lParam, SW_SHOW); + return TRUE; + } + + case NPPM_DMMGETPLUGINHWNDBYNAME : //(const TCHAR *windowName, const TCHAR *moduleName) + { + if (!lParam) return NULL; + + TCHAR *moduleName = (TCHAR *)lParam; + TCHAR *windowName = (TCHAR *)wParam; + vector dockContainer = _dockingManager.getContainerInfo(); + for (size_t i = 0 ; i < dockContainer.size() ; i++) + { + vector tbData = dockContainer[i]->getDataOfAllTb(); + for (size_t j = 0 ; j < tbData.size() ; j++) + { + if (generic_stricmp(moduleName, tbData[j]->pszModuleName) == 0) + { + if (!windowName) + return (LRESULT)tbData[j]->hClient; + else if (generic_stricmp(windowName, tbData[j]->pszName) == 0) + return (LRESULT)tbData[j]->hClient; + } + } + } + return NULL; + } + + case NPPM_ADDTOOLBARICON: + { + _toolBar.registerDynBtn((UINT)wParam, (toolbarIcons*)lParam); + return TRUE; + } + + case NPPM_SETMENUITEMCHECK: + { + ::CheckMenuItem(_mainMenuHandle, (UINT)wParam, MF_BYCOMMAND | ((BOOL)lParam ? MF_CHECKED : MF_UNCHECKED)); + _toolBar.setCheck((int)wParam, bool(lParam != 0)); + return TRUE; + } + + case NPPM_GETWINDOWSVERSION: + { + return _winVersion; + } + + case NPPM_MAKECURRENTBUFFERDIRTY : + { + _pEditView->getCurrentBuffer()->setDirty(true); + return TRUE; + } + + case NPPM_GETENABLETHEMETEXTUREFUNC : + { + return (LRESULT)pNppParam->getEnableThemeDlgTexture(); + } + + case NPPM_GETPLUGINSCONFIGDIR : + { + if (!lParam || !wParam) + return FALSE; + + const TCHAR *pluginsConfigDirPrefix = pNppParam->getAppDataNppDir(); + + if (!pluginsConfigDirPrefix[0]) + pluginsConfigDirPrefix = pNppParam->getNppPath(); + + const TCHAR *secondPart = TEXT("plugins\\Config"); + + int len = wParam; + if (len < lstrlen(pluginsConfigDirPrefix) + lstrlen(secondPart)) + return FALSE; + + TCHAR *pluginsConfigDir = (TCHAR *)lParam; + lstrcpy(pluginsConfigDir, pluginsConfigDirPrefix); + + ::PathAppend(pluginsConfigDir, secondPart); + return TRUE; + } + + case NPPM_MSGTOPLUGIN : + { + return _pluginsManager.relayPluginMessages(Message, wParam, lParam); + } + + case NPPM_HIDETABBAR : + { + bool hide = (lParam != 0); + bool oldVal = DocTabView::getHideTabBarStatus(); + if (hide == oldVal) return oldVal; + + DocTabView::setHideTabBarStatus(hide); + ::SendMessage(_hSelf, WM_SIZE, 0, 0); + + NppGUI & nppGUI = (NppGUI &)((NppParameters::getInstance())->getNppGUI()); + if (hide) + nppGUI._tabStatus |= TAB_HIDE; + else + nppGUI._tabStatus &= ~TAB_HIDE; + + return oldVal; + } + case NPPM_ISTABBARHIDDEN : + { + return _mainDocTab.getHideTabBarStatus(); + } + + + case NPPM_HIDETOOLBAR : + { + bool show = (lParam != TRUE); + bool currentStatus = _rebarTop.getIDVisible(REBAR_BAR_TOOLBAR); + if (show != currentStatus) + _rebarTop.setIDVisible(REBAR_BAR_TOOLBAR, show); + return currentStatus; + } + case NPPM_ISTOOLBARHIDDEN : + { + return !_rebarTop.getIDVisible(REBAR_BAR_TOOLBAR); + } + + case NPPM_HIDEMENU : + { + bool hide = (lParam == TRUE); + bool isHidden = ::GetMenu(_hSelf) == NULL; + if (hide == isHidden) + return isHidden; + + NppGUI & nppGUI = (NppGUI &)pNppParam->getNppGUI(); + nppGUI._menuBarShow = !hide; + if (nppGUI._menuBarShow) + ::SetMenu(_hSelf, _mainMenuHandle); + else + ::SetMenu(_hSelf, NULL); + + return isHidden; + } + case NPPM_ISMENUHIDDEN : + { + return (::GetMenu(_hSelf) == NULL); + } + + case NPPM_HIDESTATUSBAR: + { + bool show = (lParam != TRUE); + NppGUI & nppGUI = (NppGUI &)pNppParam->getNppGUI(); + bool oldVal = nppGUI._statusBarShow; + if (show == oldVal) + { + return oldVal; + } + RECT rc; + getClientRect(rc); + + nppGUI._statusBarShow = show; + _statusBar.display(nppGUI._statusBarShow); + ::SendMessage(_hSelf, WM_SIZE, SIZE_RESTORED, MAKELONG(rc.bottom, rc.right)); + return oldVal; + } + + case NPPM_ISSTATUSBARHIDDEN : + { + NppGUI & nppGUI = (NppGUI &)pNppParam->getNppGUI(); + return !nppGUI._statusBarShow; + } + +/* + case NPPM_ADDREBAR : + { + if (!lParam) + return FALSE; + _rebarTop.addBand((REBARBANDINFO*)lParam, false); + return TRUE; + } + + case NPPM_UPDATEREBAR : + { + if (!lParam || wParam < REBAR_BAR_EXTERNAL) + return FALSE; + _rebarTop.reNew((int)wParam, (REBARBANDINFO*)lParam); + return TRUE; + } + + case NPPM_REMOVEREBAR : + { + if (wParam < REBAR_BAR_EXTERNAL) + return FALSE; + _rebarTop.removeBand((int)wParam); + return TRUE; + } +*/ + case NPPM_INTERNAL_ISFOCUSEDTAB : + { + HWND hTabToTest = (currentView() == MAIN_VIEW)?_mainDocTab.getHSelf():_subDocTab.getHSelf(); + return (HWND)lParam == hTabToTest; + } + + case NPPM_INTERNAL_GETMENU : + { + return (LRESULT)_mainMenuHandle; + } + + case NPPM_INTERNAL_CLEARINDICATOR : + { + _pEditView->clearIndicator(SCE_UNIVERSAL_FOUND_STYLE_2); + return TRUE; + } + case NPPM_INTERNAL_CLEARINDICATORTAGMATCH : + { + _pEditView->clearIndicator(SCE_UNIVERSAL_TAGMATCH); + _pEditView->clearIndicator(SCE_UNIVERSAL_TAGATTR); + return TRUE; + } + case NPPM_INTERNAL_CLEARINDICATORTAGATTR : + { + _pEditView->clearIndicator(SCE_UNIVERSAL_TAGATTR); + return TRUE; + } + + case NPPM_INTERNAL_SWITCHVIEWFROMHWND : + { + HWND handle = (HWND)lParam; + if (_mainEditView.getHSelf() == handle || _mainDocTab.getHSelf() == handle) + { + switchEditViewTo(MAIN_VIEW); + } + else if (_subEditView.getHSelf() == handle || _subDocTab.getHSelf() == handle) + { + switchEditViewTo(SUB_VIEW); + } + return TRUE; + } + + case NPPM_INTERNAL_UPDATETITLEBAR : + { + setTitle(); + return TRUE; + } + + case WM_INITMENUPOPUP: + { + _windowsMenu.initPopupMenu((HMENU)wParam, _pDocTab); + return TRUE; + } + + case WM_ENTERMENULOOP: + { + NppGUI & nppgui = (NppGUI &)(pNppParam->getNppGUI()); + if (!nppgui._menuBarShow && !wParam && !_sysMenuEntering) + ::SetMenu(_hSelf, _mainMenuHandle); + + return TRUE; + } + + case WM_EXITMENULOOP: + { + NppGUI & nppgui = (NppGUI &)(pNppParam->getNppGUI()); + if (!nppgui._menuBarShow && !wParam && !_sysMenuEntering) + ::SetMenu(_hSelf, NULL); + _sysMenuEntering = false; + return FALSE; + } + + default: + { + if (Message == WDN_NOTIFY) + { + NMWINDLG* nmdlg = (NMWINDLG*)lParam; + switch (nmdlg->type) + { + case WDT_ACTIVATE: + activateDoc(nmdlg->curSel); + nmdlg->processed = TRUE; + break; + case WDT_SAVE: + { + //loop through nmdlg->nItems, get index and save it + for (int i = 0; i < (int)nmdlg->nItems; i++) { + fileSave(_pDocTab->getBufferByIndex(i)); + } + nmdlg->processed = TRUE; + } + break; + case WDT_CLOSE: + { + //loop through nmdlg->nItems, get index and close it + for (int i = 0; i < (int)nmdlg->nItems; i++) { + fileClose(_pDocTab->getBufferByIndex(nmdlg->Items[i]), currentView()); + UINT pos = nmdlg->Items[i]; + nmdlg->Items[i] = 0xFFFFFFFF; // indicate file was closed + + for (int j=i+1; j<(int)nmdlg->nItems; ++j) + if (nmdlg->Items[j] > pos) + --nmdlg->Items[j]; + } + nmdlg->processed = TRUE; + } + break; + case WDT_SORT: + if (nmdlg->nItems != _pDocTab->nbItem()) //sanity check, if mismatch just abort + break; + //Collect all buffers + std::vector tempBufs; + for(int i = 0; i < (int)nmdlg->nItems; i++) { + tempBufs.push_back(_pDocTab->getBufferByIndex(i)); + } + //Reset buffers + for(int i = 0; i < (int)nmdlg->nItems; i++) { + _pDocTab->setBuffer(i, tempBufs[nmdlg->Items[i]]); + } + activateBuffer(_pDocTab->getBufferByIndex(_pDocTab->getCurrentTabIndex()), currentView()); + break; + } + return TRUE; + } + + return ::DefWindowProc(hwnd, Message, wParam, lParam); + } + } + + _pluginsManager.relayNppMessages(Message, wParam, lParam); + return result; +} + +LRESULT CALLBACK Notepad_plus::Notepad_plus_Proc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) +{ + + static bool isFirstGetMinMaxInfoMsg = true; + + switch(Message) + { + case WM_NCCREATE : // First message we get the ptr of instantiated object + // then stock it into GWL_USERDATA index in order to retrieve afterward + { + Notepad_plus *pM30ide = (Notepad_plus *)(((LPCREATESTRUCT)lParam)->lpCreateParams); + pM30ide->_hSelf = hwnd; + ::SetWindowLongPtr(hwnd, GWL_USERDATA, (LONG)pM30ide); + + return TRUE; + } + + default : + { + return ((Notepad_plus *)::GetWindowLongPtr(hwnd, GWL_USERDATA))->runProc(hwnd, Message, wParam, lParam); + } + } +} + +void Notepad_plus::fullScreenToggle() +{ + if (!_beforeSpecialView.isFullScreen) //toggle fullscreen on + { + _beforeSpecialView._winPlace.length = sizeof(_beforeSpecialView._winPlace); + ::GetWindowPlacement(_hSelf, &_beforeSpecialView._winPlace); + + RECT fullscreenArea; //RECT used to calculate window fullscreen size + //Preset view area, in case something fails, primary monitor values + fullscreenArea.top = 0; + fullscreenArea.left = 0; + fullscreenArea.right = GetSystemMetrics(SM_CXSCREEN); + fullscreenArea.bottom = GetSystemMetrics(SM_CYSCREEN); + + //if (_winVersion != WV_NT) + { + HMONITOR currentMonitor; //Handle to monitor where fullscreen should go + MONITORINFO mi; //Info of that monitor + //Caution, this will not work on windows 95, so probably add some checking of some sorts like Unicode checks, IF 95 were to be supported + currentMonitor = ::MonitorFromWindow(_hSelf, MONITOR_DEFAULTTONEAREST); //should always be valid monitor handle + mi.cbSize = sizeof(MONITORINFO); + if (::GetMonitorInfo(currentMonitor, &mi) != FALSE) + { + fullscreenArea = mi.rcMonitor; + fullscreenArea.right -= fullscreenArea.left; + fullscreenArea.bottom -= fullscreenArea.top; + } + } + + //Setup GUI + if (!_beforeSpecialView.isPostIt) + { + //only change the GUI if not already done by postit + _beforeSpecialView.isMenuShown = ::SendMessage(_hSelf, NPPM_ISMENUHIDDEN, 0, 0) != TRUE; + if (_beforeSpecialView.isMenuShown) + ::SendMessage(_hSelf, NPPM_HIDEMENU, 0, TRUE); + + //Hide rebar + _rebarTop.display(false); + _rebarBottom.display(false); + } + + //Hide window so windows can properly update it + ::ShowWindow(_hSelf, SW_HIDE); + + //Set popup style for fullscreen window and store the old style + if (!_beforeSpecialView.isPostIt) + { + _beforeSpecialView.preStyle = ::SetWindowLongPtr( _hSelf, GWL_STYLE, WS_POPUP ); + if (!_beforeSpecialView.preStyle) { //something went wrong, use default settings + _beforeSpecialView.preStyle = WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN; + } + } + + //Set fullscreen window, highest non-top z-order, show the window and redraw it (refreshing the windowmanager cache aswell) + ::ShowWindow(_hSelf, SW_SHOW); + ::SetWindowPos(_hSelf, HWND_TOP, fullscreenArea.left, fullscreenArea.top, fullscreenArea.right, fullscreenArea.bottom, SWP_NOZORDER|SWP_DRAWFRAME|SWP_FRAMECHANGED); + ::SetForegroundWindow(_hSelf); + } + else //toggle fullscreen off + { + //Hide window for updating, restore style and menu then restore position and Z-Order + ::ShowWindow(_hSelf, SW_HIDE); + + //Setup GUI + if (!_beforeSpecialView.isPostIt) + { + //only change the GUI if postit isnt active + if (_beforeSpecialView.isMenuShown) + ::SendMessage(_hSelf, NPPM_HIDEMENU, 0, FALSE); + + //Show rebar + _rebarTop.display(true); + _rebarBottom.display(true); + } + + //Set old style if not fullscreen + if (!_beforeSpecialView.isPostIt) + { + ::SetWindowLongPtr( _hSelf, GWL_STYLE, _beforeSpecialView.preStyle); + //Redraw the window and refresh windowmanager cache, dont do anything else, sizing is done later on + ::SetWindowPos(_hSelf, HWND_TOP,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_DRAWFRAME|SWP_FRAMECHANGED); + ::ShowWindow(_hSelf, SW_SHOW); + } + + if (_beforeSpecialView._winPlace.length) + { + if (_beforeSpecialView._winPlace.showCmd == SW_SHOWMAXIMIZED) + { + //::ShowWindow(_hSelf, SW_RESTORE); + ::ShowWindow(_hSelf, SW_SHOWMAXIMIZED); + } + else + { + ::SetWindowPlacement(_hSelf, &_beforeSpecialView._winPlace); + } + } + else //fallback + { + ::ShowWindow(_hSelf, SW_SHOW); + } + } + //::SetForegroundWindow(_hSelf); + _beforeSpecialView.isFullScreen = !_beforeSpecialView.isFullScreen; + ::SendMessage(_hSelf, WM_SIZE, 0, 0); +} + +void Notepad_plus::postItToggle() +{ + NppParameters * pNppParam = NppParameters::getInstance(); + if (!_beforeSpecialView.isPostIt) // PostIt disabled, enable it + { + NppGUI & nppGUI = (NppGUI &)pNppParam->getNppGUI(); + // get current status before switch to postIt + //check these always + { + _beforeSpecialView.isAlwaysOnTop = ::GetMenuState(_mainMenuHandle, IDM_VIEW_ALWAYSONTOP, MF_BYCOMMAND) == MF_CHECKED; + _beforeSpecialView.isTabbarShown = ::SendMessage(_hSelf, NPPM_ISTABBARHIDDEN, 0, 0) != TRUE; + _beforeSpecialView.isStatusbarShown = nppGUI._statusBarShow; + if (nppGUI._statusBarShow) + ::SendMessage(_hSelf, NPPM_HIDESTATUSBAR, 0, TRUE); + if (_beforeSpecialView.isTabbarShown) + ::SendMessage(_hSelf, NPPM_HIDETABBAR, 0, TRUE); + if (!_beforeSpecialView.isAlwaysOnTop) + ::SendMessage(_hSelf, WM_COMMAND, IDM_VIEW_ALWAYSONTOP, 0); + } + //Only check these if not fullscreen + if (!_beforeSpecialView.isFullScreen) + { + _beforeSpecialView.isMenuShown = ::SendMessage(_hSelf, NPPM_ISMENUHIDDEN, 0, 0) != TRUE; + if (_beforeSpecialView.isMenuShown) + ::SendMessage(_hSelf, NPPM_HIDEMENU, 0, TRUE); + + //Hide rebar + _rebarTop.display(false); + _rebarBottom.display(false); + } + + // PostIt! + + //Set popup style for fullscreen window and store the old style + if (!_beforeSpecialView.isFullScreen) + { + //Hide window so windows can properly update it + ::ShowWindow(_hSelf, SW_HIDE); + _beforeSpecialView.preStyle = ::SetWindowLongPtr( _hSelf, GWL_STYLE, WS_POPUP ); + if (!_beforeSpecialView.preStyle) { //something went wrong, use default settings + _beforeSpecialView.preStyle = WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN; + } + //Redraw the window and refresh windowmanager cache, dont do anything else, sizing is done later on + ::SetWindowPos(_hSelf, HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_DRAWFRAME|SWP_FRAMECHANGED); + ::ShowWindow(_hSelf, SW_SHOW); + } + } + else //PostIt enabled, disable it + { + //Setup GUI + if (!_beforeSpecialView.isFullScreen) + { + //only change the these parts of GUI if not already done by fullscreen + if (_beforeSpecialView.isMenuShown) + ::SendMessage(_hSelf, NPPM_HIDEMENU, 0, FALSE); + + //Show rebar + _rebarTop.display(true); + _rebarBottom.display(true); + } + //Do this GUI config always + if (_beforeSpecialView.isStatusbarShown) + ::SendMessage(_hSelf, NPPM_HIDESTATUSBAR, 0, FALSE); + if (_beforeSpecialView.isTabbarShown) + ::SendMessage(_hSelf, NPPM_HIDETABBAR, 0, FALSE); + if (!_beforeSpecialView.isAlwaysOnTop) + ::SendMessage(_hSelf, WM_COMMAND, IDM_VIEW_ALWAYSONTOP, 0); + + //restore window style if not fullscreen + if (!_beforeSpecialView.isFullScreen) + { + //dwStyle |= (WS_CAPTION | WS_SIZEBOX); + ::ShowWindow(_hSelf, SW_HIDE); + ::SetWindowLongPtr(_hSelf, GWL_STYLE, _beforeSpecialView.preStyle); + + //Redraw the window and refresh windowmanager cache, dont do anything else, sizing is done later on + ::SetWindowPos(_hSelf, HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_DRAWFRAME|SWP_FRAMECHANGED); + ::ShowWindow(_hSelf, SW_SHOW); + } + } + + _beforeSpecialView.isPostIt = !_beforeSpecialView.isPostIt; + ::SendMessage(_hSelf, WM_SIZE, 0, 0); +} + +void Notepad_plus::doSynScorll(HWND whichView) +{ + int column = 0; + int line = 0; + ScintillaEditView *pView; + + // var for Line + int mainCurrentLine, subCurrentLine; + + // var for Column + int mxoffset, sxoffset; + int pixel; + int mainColumn, subColumn; + + if (whichView == _mainEditView.getHSelf()) + { + if (_syncInfo._isSynScollV) + { + // Compute for Line + mainCurrentLine = _mainEditView.execute(SCI_GETFIRSTVISIBLELINE); + subCurrentLine = _subEditView.execute(SCI_GETFIRSTVISIBLELINE); + line = mainCurrentLine - _syncInfo._line - subCurrentLine; + } + if (_syncInfo._isSynScollH) + { + // Compute for Column + mxoffset = _mainEditView.execute(SCI_GETXOFFSET); + pixel = int(_mainEditView.execute(SCI_TEXTWIDTH, STYLE_DEFAULT, (LPARAM)"P")); + mainColumn = mxoffset/pixel; + + sxoffset = _subEditView.execute(SCI_GETXOFFSET); + pixel = int(_subEditView.execute(SCI_TEXTWIDTH, STYLE_DEFAULT, (LPARAM)"P")); + subColumn = sxoffset/pixel; + column = mainColumn - _syncInfo._column - subColumn; + } + pView = &_subEditView; + } + else if (whichView == _subEditView.getHSelf()) + { + if (_syncInfo._isSynScollV) + { + // Compute for Line + mainCurrentLine = _mainEditView.execute(SCI_GETFIRSTVISIBLELINE); + subCurrentLine = _subEditView.execute(SCI_GETFIRSTVISIBLELINE); + line = subCurrentLine + _syncInfo._line - mainCurrentLine; + } + if (_syncInfo._isSynScollH) + { + // Compute for Column + mxoffset = _mainEditView.execute(SCI_GETXOFFSET); + pixel = int(_mainEditView.execute(SCI_TEXTWIDTH, STYLE_DEFAULT, (LPARAM)"P")); + mainColumn = mxoffset/pixel; + + sxoffset = _subEditView.execute(SCI_GETXOFFSET); + pixel = int(_subEditView.execute(SCI_TEXTWIDTH, STYLE_DEFAULT, (LPARAM)"P")); + subColumn = sxoffset/pixel; + column = subColumn + _syncInfo._column - mainColumn; + } + pView = &_mainEditView; + } + else + return; + + pView->scroll(column, line); +} + +bool Notepad_plus::getIntegralDockingData(tTbData & dockData, int & iCont, bool & isVisible) +{ + DockingManagerData & dockingData = (DockingManagerData &)(NppParameters::getInstance())->getNppGUI()._dockingData; + + for (size_t i = 0 ; i < dockingData._pluginDockInfo.size() ; i++) + { + const PlugingDlgDockingInfo & pddi = dockingData._pluginDockInfo[i]; + + if (!generic_stricmp(pddi._name, dockData.pszModuleName) && (pddi._internalID == dockData.dlgID)) + { + iCont = pddi._currContainer; + isVisible = pddi._isVisible; + dockData.iPrevCont = pddi._prevContainer; + + if (dockData.iPrevCont != -1) + { + int cont = (pddi._currContainer < DOCKCONT_MAX ? pddi._prevContainer : pddi._currContainer); + RECT *pRc = dockingData.getFloatingRCFrom(cont); + if (pRc) + dockData.rcFloat = *pRc; + } + return true; + } + } + return false; +} + + +void Notepad_plus::getCurrentOpenedFiles(Session & session) +{ + _mainEditView.saveCurrentPos(); //save position so itll be correct in the session + _subEditView.saveCurrentPos(); //both views + session._activeView = currentView(); + session._activeMainIndex = _mainDocTab.getCurrentTabIndex(); + session._activeSubIndex = _subDocTab.getCurrentTabIndex(); + + //Use _invisibleEditView to temporarily open documents to retrieve markers + //Buffer * mainBuf = _mainEditView.getCurrentBuffer(); + //Buffer * subBuf = _subEditView.getCurrentBuffer(); + Document oldDoc = _invisibleEditView.execute(SCI_GETDOCPOINTER); + + for (int i = 0 ; i < _mainDocTab.nbItem() ; i++) + { + BufferID bufID = _mainDocTab.getBufferByIndex(i); + Buffer * buf = MainFileManager->getBufferByID(bufID); + if (!buf->isUntitled() && PathFileExists(buf->getFullPathName())) + { + generic_string languageName = getLangFromMenu( buf ); + const TCHAR *langName = languageName.c_str(); + + sessionFileInfo sfi(buf->getFullPathName(), langName, buf->getPosition(&_mainEditView)); + + //_mainEditView.activateBuffer(buf->getID()); + _invisibleEditView.execute(SCI_SETDOCPOINTER, 0, buf->getDocument()); + int maxLine = _invisibleEditView.execute(SCI_GETLINECOUNT); + for (int j = 0 ; j < maxLine ; j++) + { + if ((_invisibleEditView.execute(SCI_MARKERGET, j)&(1 << MARK_BOOKMARK)) != 0) + { + sfi.marks.push_back(j); + } + } + session._mainViewFiles.push_back(sfi); + } + } + + for (int i = 0 ; i < _subDocTab.nbItem() ; i++) + { + BufferID bufID = _subDocTab.getBufferByIndex(i); + Buffer * buf = MainFileManager->getBufferByID(bufID); + if (!buf->isUntitled() && PathFileExists(buf->getFullPathName())) + { + generic_string languageName = getLangFromMenu( buf ); + const TCHAR *langName = languageName.c_str(); + + sessionFileInfo sfi(buf->getFullPathName(), langName, buf->getPosition(&_subEditView)); + + _invisibleEditView.execute(SCI_SETDOCPOINTER, 0, buf->getDocument()); + int maxLine = _invisibleEditView.execute(SCI_GETLINECOUNT); + for (int j = 0 ; j < maxLine ; j++) + { + if ((_invisibleEditView.execute(SCI_MARKERGET, j)&(1 << MARK_BOOKMARK)) != 0) + { + sfi.marks.push_back(j); + } + } + session._subViewFiles.push_back(sfi); + } + } + + //_mainEditView.activateBuffer(mainBuf->getID()); //restore buffer + //_subEditView.activateBuffer(subBuf->getID()); //restore buffer + //_mainEditView.execute(SCI_SETDOCPOINTER, 0, mainBuf->getDocument()); + //_mainEditView.restoreCurrentPos(); + //_subEditView.execute(SCI_SETDOCPOINTER, 0, subBuf->getDocument()); + //_subEditView.restoreCurrentPos(); + + _invisibleEditView.execute(SCI_SETDOCPOINTER, 0, oldDoc); +} + +bool Notepad_plus::fileLoadSession(const TCHAR *fn) +{ + bool result = false; + const TCHAR *sessionFileName = NULL; + if (fn == NULL) + { + FileDialog fDlg(_hSelf, _hInst); + fDlg.setExtFilter(TEXT("All types"), TEXT(".*"), NULL); + const TCHAR *ext = NppParameters::getInstance()->getNppGUI()._definedSessionExt.c_str(); + generic_string sessionExt = TEXT(""); + if (*ext != '\0') + { + if (*ext != '.') + sessionExt += TEXT("."); + sessionExt += ext; + fDlg.setExtFilter(TEXT("Session file"), sessionExt.c_str(), NULL); + } + sessionFileName = fDlg.doOpenSingleFileDlg(); + } + else + { + if (PathFileExists(fn)) + sessionFileName = fn; + } + + if (sessionFileName) + { + bool isAllSuccessful = true; + Session session2Load; + + if ((NppParameters::getInstance())->loadSession(session2Load, sessionFileName)) + { + isAllSuccessful = loadSession(session2Load); + result = true; + } + if (!isAllSuccessful) + (NppParameters::getInstance())->writeSession(session2Load, sessionFileName); + } + return result; +} + + +const TCHAR * Notepad_plus::fileSaveSession(size_t nbFile, TCHAR ** fileNames, const TCHAR *sessionFile2save) +{ + if (sessionFile2save) + { + Session currentSession; + if ((nbFile) && (!fileNames)) + { + for (size_t i = 0 ; i < nbFile ; i++) + { + if (PathFileExists(fileNames[i])) + currentSession._mainViewFiles.push_back(generic_string(fileNames[i])); + } + } + else + getCurrentOpenedFiles(currentSession); + + (NppParameters::getInstance())->writeSession(currentSession, sessionFile2save); + return sessionFile2save; + } + return NULL; +} + +const TCHAR * Notepad_plus::fileSaveSession(size_t nbFile, TCHAR ** fileNames) +{ + const TCHAR *sessionFileName = NULL; + + FileDialog fDlg(_hSelf, _hInst); + const TCHAR *ext = NppParameters::getInstance()->getNppGUI()._definedSessionExt.c_str(); + + fDlg.setExtFilter(TEXT("All types"), TEXT(".*"), NULL); + generic_string sessionExt = TEXT(""); + if (*ext != '\0') + { + if (*ext != '.') + sessionExt += TEXT("."); + sessionExt += ext; + fDlg.setExtFilter(TEXT("Session file"), sessionExt.c_str(), NULL); + } + sessionFileName = fDlg.doSaveDlg(); + + return fileSaveSession(nbFile, fileNames, sessionFileName); +} + + +bool Notepad_plus::str2Cliboard(const TCHAR *str2cpy) +{ + if (!str2cpy) + return false; + + int len2Allocate = lstrlen(str2cpy) + 1; + len2Allocate *= sizeof(TCHAR); + unsigned int cilpboardFormat = CF_TEXT; + +#ifdef UNICODE + cilpboardFormat = CF_UNICODETEXT; +#endif + + HGLOBAL hglbCopy = ::GlobalAlloc(GMEM_MOVEABLE, len2Allocate); + if (hglbCopy == NULL) + { + return false; + } + + if (!::OpenClipboard(_hSelf)) + return false; + + ::EmptyClipboard(); + + // Lock the handle and copy the text to the buffer. + TCHAR *pStr = (TCHAR *)::GlobalLock(hglbCopy); + lstrcpy(pStr, str2cpy); + ::GlobalUnlock(hglbCopy); + + // Place the handle on the clipboard. + ::SetClipboardData(cilpboardFormat, hglbCopy); + ::CloseClipboard(); + return true; +} + +//ONLY CALL IN CASE OF EMERGENCY: EXCEPTION +//This function is destructive +bool Notepad_plus::emergency(generic_string emergencySavedDir) +{ + bool filestatus = false; + bool dumpstatus = false; + do { + if (::CreateDirectory(emergencySavedDir.c_str(), NULL) == FALSE && ::GetLastError() != ERROR_ALREADY_EXISTS) { + break; + } + + filestatus = dumpFiles(emergencySavedDir.c_str(), TEXT("File")); + + } while (false); + + bool status = filestatus;// && dumpstatus; + return status; +} + +bool Notepad_plus::dumpFiles(const TCHAR * outdir, const TCHAR * fileprefix) { + //start dumping unsaved files to recovery directory + bool somethingsaved = false; + bool somedirty = false; + TCHAR savePath[MAX_PATH] = {0}; + + //rescue primary + for(int i = 0; i < MainFileManager->getNrBuffers(); i++) { + Buffer * docbuf = MainFileManager->getBufferByIndex(i); + if (!docbuf->isDirty()) //skip saved documents + continue; + else + somedirty = true; + + const TCHAR * unitext = (docbuf->getUnicodeMode() != uni8Bit)?TEXT("_utf8"):TEXT(""); + wsprintf(savePath, TEXT("%s\\%s%03d%s.dump"), outdir, fileprefix, i, unitext); + + bool res = MainFileManager->saveBuffer(docbuf->getID(), savePath); + + somethingsaved |= res; + } + + return somethingsaved || !somedirty; +} + +void Notepad_plus::drawTabbarColoursFromStylerArray() +{ + Style *stActText = getStyleFromName(TABBAR_ACTIVETEXT); + if (stActText && stActText->_fgColor != -1) + TabBarPlus::setColour(stActText->_fgColor, TabBarPlus::activeText); + + Style *stActfocusTop = getStyleFromName(TABBAR_ACTIVEFOCUSEDINDCATOR); + if (stActfocusTop && stActfocusTop->_fgColor != -1) + TabBarPlus::setColour(stActfocusTop->_fgColor, TabBarPlus::activeFocusedTop); + + Style *stActunfocusTop = getStyleFromName(TABBAR_ACTIVEUNFOCUSEDINDCATOR); + if (stActunfocusTop && stActunfocusTop->_fgColor != -1) + TabBarPlus::setColour(stActunfocusTop->_fgColor, TabBarPlus::activeUnfocusedTop); + + Style *stInact = getStyleFromName(TABBAR_INACTIVETEXT); + if (stInact && stInact->_fgColor != -1) + TabBarPlus::setColour(stInact->_fgColor, TabBarPlus::inactiveText); + if (stInact && stInact->_bgColor != -1) + TabBarPlus::setColour(stInact->_bgColor, TabBarPlus::inactiveBg); +} + +void Notepad_plus::notifyBufferChanged(Buffer * buffer, int mask) { + NppParameters *pNppParam = NppParameters::getInstance(); + const NppGUI & nppGUI = pNppParam->getNppGUI(); + + _mainEditView.bufferUpdated(buffer, mask); + _subEditView.bufferUpdated(buffer, mask); + _mainDocTab.bufferUpdated(buffer, mask); + _subDocTab.bufferUpdated(buffer, mask); + + bool mainActive = (_mainEditView.getCurrentBuffer() == buffer); + bool subActive = (_subEditView.getCurrentBuffer() == buffer); + + //Only event that applies to non-active Buffers + if (mask & BufferChangeStatus) { //reload etc + bool didDialog = false; + switch(buffer->getStatus()) { + case DOC_UNNAMED: //nothing todo + { + break; + } + case DOC_REGULAR: //nothing todo + { + break; + } + case DOC_MODIFIED: //ask for reloading + { + bool autoUpdate = (nppGUI._fileAutoDetection == cdAutoUpdate) || (nppGUI._fileAutoDetection == cdAutoUpdateGo2end); + if (!autoUpdate || buffer->isDirty()) + { + didDialog = true; + if (doReloadOrNot(buffer->getFullPathName(), buffer->isDirty()) != IDYES) + break; //abort + } + //activateBuffer(buffer->getID(), iView); //activate the buffer in the first view possible + doReload(buffer->getID(), false); + if (mainActive || subActive) + { + performPostReload(mainActive?MAIN_VIEW:SUB_VIEW); + } + break; + } + case DOC_DELETED: //ask for keep + { + int index = _pDocTab->getIndexByBuffer(buffer->getID()); + int iView = currentView(); + if (index == -1) + iView = otherView(); + //activateBuffer(buffer->getID(), iView); //activate the buffer in the first view possible + didDialog = true; + if (doCloseOrNot(buffer->getFullPathName()) == IDNO) + { + //close in both views, doing current view last since that has to remain opened + doClose(buffer->getID(), otherView()); + doClose(buffer->getID(), currentView()); + } + break; + } + } + + if (didDialog) + { + int curPos = _pEditView->execute(SCI_GETCURRENTPOS); + ::PostMessage(_pEditView->getHSelf(), WM_LBUTTONUP, 0, 0); + ::PostMessage(_pEditView->getHSelf(), SCI_SETSEL, curPos, curPos); + } + } + + if (!mainActive && !subActive) + { + return; + } + + if (mask & (BufferChangeLanguage)) + { + if (mainActive) + _autoCompleteMain.setLanguage(buffer->getLangType()); + if (subActive) + _autoCompleteSub.setLanguage(buffer->getLangType()); + } + + if ((currentView() == MAIN_VIEW) && !mainActive) + return; + + if ((currentView() == SUB_VIEW) && !subActive) + return; + + if (mask & (BufferChangeDirty|BufferChangeFilename)) + { + checkDocState(); + setTitle(); + TCHAR dir[MAX_PATH]; + lstrcpy(dir, buffer->getFullPathName()); + PathRemoveFileSpec(dir); + setWorkingDir(dir); + } + + if (mask & (BufferChangeLanguage)) + { + checkLangsMenu(-1); //let N++ do search for the item + setLangStatus(buffer->getLangType()); + if (_mainEditView.getCurrentBuffer() == buffer) + _autoCompleteMain.setLanguage(buffer->getLangType()); + else if (_subEditView.getCurrentBuffer() == buffer) + _autoCompleteSub.setLanguage(buffer->getLangType()); + + SCNotification scnN; + scnN.nmhdr.code = NPPN_LANGCHANGED; + scnN.nmhdr.hwndFrom = _hSelf; + scnN.nmhdr.idFrom = (uptr_t)_pEditView->getCurrentBufferID(); + _pluginsManager.notify(&scnN); + } + + if (mask & (BufferChangeFormat|BufferChangeLanguage|BufferChangeUnicode)) + { + updateStatusBar(); + checkUnicodeMenuItems(buffer->getUnicodeMode()); + setUniModeText(buffer->getUnicodeMode()); + setDisplayFormat(buffer->getFormat()); + enableConvertMenuItems(buffer->getFormat()); + } + + if (mask & (BufferChangeReadonly)) + { + checkDocState(); + } +} + +void Notepad_plus::notifyBufferActivated(BufferID bufid, int view) { + Buffer * buf = MainFileManager->getBufferByID(bufid); + buf->increaseRecentTag(); + + if (view == MAIN_VIEW) { + _autoCompleteMain.setLanguage(buf->getLangType()); + } else if (view == SUB_VIEW) { + _autoCompleteSub.setLanguage(buf->getLangType()); + } + + if (view != currentView()) { + return; //dont care if another view did something + } + + checkDocState(); + dynamicCheckMenuAndTB(); + setLangStatus(buf->getLangType()); + updateStatusBar(); + checkUnicodeMenuItems(buf->getUnicodeMode()); + setUniModeText(buf->getUnicodeMode()); + setDisplayFormat(buf->getFormat()); + enableConvertMenuItems(buf->getFormat()); + TCHAR dir[MAX_PATH]; + lstrcpy(dir, buf->getFullPathName()); + PathRemoveFileSpec(dir); + setWorkingDir(dir); + setTitle(); + //Make sure the colors of the tab controls match + ::InvalidateRect(_mainDocTab.getHSelf(), NULL, FALSE); + ::InvalidateRect(_subDocTab.getHSelf(), NULL, FALSE); + + SCNotification scnN; + scnN.nmhdr.code = NPPN_BUFFERACTIVATED; + scnN.nmhdr.hwndFrom = _hSelf; + scnN.nmhdr.idFrom = (uptr_t)bufid; + _pluginsManager.notify(&scnN); + + _linkTriggered = true; +} + +void Notepad_plus::loadCommandlineParams(const TCHAR * commandLine, CmdLineParams * pCmdParams) { + if (!commandLine || ! pCmdParams) + return; + + FileNameStringSplitter fnss(commandLine); + const TCHAR *pFn = NULL; + + LangType lt = pCmdParams->_langType;//LangType(pCopyData->dwData & LASTBYTEMASK); + int ln = pCmdParams->_line2go; + int cn = pCmdParams->_column2go; + + bool readOnly = pCmdParams->_isReadOnly; + + BufferID lastOpened = BUFFER_INVALID; + for (int i = 0 ; i < fnss.size() ; i++) + { + pFn = fnss.getFileName(i); + BufferID bufID = doOpen(pFn, readOnly); + if (bufID == BUFFER_INVALID) //cannot open file + continue; + + lastOpened = bufID; + + if (lt != L_EXTERNAL) + { + Buffer * pBuf = MainFileManager->getBufferByID(bufID); + pBuf->setLangType(lt); + } + + if (ln != -1) + { //we have to move the cursor manually + int iView = currentView(); //store view since fileswitch can cause it to change + switchToFile(bufID); //switch to the file. No deferred loading, but this way we can easily move the cursor to the right position + + if (cn == -1) + _pEditView->execute(SCI_GOTOLINE, ln-1); + else + { + int pos = _pEditView->execute(SCI_FINDCOLUMN, ln-1, cn-1); + _pEditView->execute(SCI_GOTOPOS, pos); + } + switchEditViewTo(iView); //restore view + } + } + if (lastOpened != BUFFER_INVALID) + { + switchToFile(lastOpened); + } +} + +void Notepad_plus::setFindReplaceFolderFilter(const TCHAR *dir, const TCHAR *filter) +{ + generic_string fltr; + NppParameters *pNppParam = NppParameters::getInstance(); + FindHistory & findHistory = pNppParam->getFindHistory(); + + // get current directory in case it's not provided. + if (!dir && findHistory._isFolderFollowDoc) + { + dir = pNppParam->getWorkingDir(); + } + + // get current language file extensions in case it's not provided. + if (!filter && findHistory._isFilterFollowDoc) + { + // Get current language file extensions + const TCHAR *ext = NULL; + LangType lt = _pEditView->getCurrentBuffer()->getLangType(); + + if (lt == L_USER) + { + Buffer * buf = _pEditView->getCurrentBuffer(); + UserLangContainer * userLangContainer = pNppParam->getULCFromName(buf->getUserDefineLangName()); + if (userLangContainer) + ext = userLangContainer->getExtention(); + } + else + { + ext = NppParameters::getInstance()->getLangExtFromLangType(lt); + } + + if (ext && ext[0]) + { + fltr = TEXT(""); + vector vStr; + cutString(ext, vStr); + for (size_t i = 0; i < vStr.size(); i++) + { + fltr += TEXT("*."); + fltr += vStr[i] + TEXT(" "); + } + } + else + { + fltr = TEXT("*.*"); + } + filter = fltr.c_str(); + } + _findReplaceDlg.setFindInFilesDirFilter(dir, filter); +} diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h new file mode 100644 index 00000000..4a20d116 --- /dev/null +++ b/PowerEditor/src/Notepad_plus.h @@ -0,0 +1,839 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef NOTEPAD_PLUS_H +#define NOTEPAD_PLUS_H +#include +#include "Window.h" +#include "ScintillaEditView.h" +#include "ToolBar.h" +#include "ImageListSet.h" +#include "DocTabView.h" + +#include "StaticDialog.h" +#include "SplitterContainer.h" +#include "FindReplaceDlg.h" +#include "AboutDlg.h" +#include "RunDlg.h" +#include "UserDefineDialog.h" +#include "StatusBar.h" +#include "Parameters.h" +#include "lastRecentFileList.h" +#include "GoToLineDlg.h" +#include "columnEditor.h" +#include "WordStyleDlg.h" +//#include "constant.h" +#include "trayIconControler.h" +#include "ContextMenu.h" +#include "PluginsManager.h" +#include "Notepad_plus_msgs.h" +#include "preferenceDlg.h" +#include "WindowsDlg.h" +#include "RunMacroDlg.h" +#include "DockingManager.h" +#include "Process.h" +#include "AutoCompletion.h" +#include "Buffer.h" +#include "SmartHighlighter.h" + +#define MENU 0x01 +#define TOOLBAR 0x02 + +enum FileTransferMode { + TransferClone = 0x01, + TransferMove = 0x02 +}; + +enum WindowStatus { //bitwise mask + WindowMainActive = 0x01, + WindowSubActive = 0x02, + WindowBothActive = 0x03, //little helper shortcut + WindowUserActive = 0x04, + WindowMask = 0x07 +}; + +/* +//Plugins rely on #define's +enum Views { + MAIN_VIEW = 0x00, + SUB_VIEW = 0x01 +}; +*/ + +struct TaskListInfo; +static TiXmlNodeA * searchDlgNode(TiXmlNodeA *node, const char *dlgTagName); + +struct iconLocator { + int listIndex; + int iconIndex; + std::generic_string iconLocation; + + iconLocator(int iList, int iIcon, const std::generic_string iconLoc) + : listIndex(iList), iconIndex(iIcon), iconLocation(iconLoc){}; +}; + +struct VisibleGUIConf { + bool isPostIt; + bool isFullScreen; + + //Used by both views + bool isMenuShown; + //bool isToolbarShown; //toolbar forcefully hidden by hiding rebar + DWORD_PTR preStyle; + + //used by postit only + bool isTabbarShown; + bool isAlwaysOnTop; + bool isStatusbarShown; + + //used by fullscreen only + WINDOWPLACEMENT _winPlace; + + VisibleGUIConf() : isPostIt(false), isFullScreen(false), + isAlwaysOnTop(false), isMenuShown(true), isTabbarShown(true), + isStatusbarShown(true), preStyle(WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN) + { + _winPlace.length = 0; + }; +}; + +class FileDialog; + +class Notepad_plus : public Window { + enum comment_mode {cm_comment, cm_uncomment, cm_toggle}; +public: + Notepad_plus(); + virtual inline ~Notepad_plus(); + void init(HINSTANCE, HWND, const TCHAR *cmdLine, CmdLineParams *cmdLineParams); + inline void killAllChildren(); + virtual inline void destroy(); + + static const TCHAR * Notepad_plus::getClassName() { + return _className; + }; + + void setTitle(); + void getTaskListInfo(TaskListInfo *tli); + + // For filtering the modeless Dialog message + inline bool isDlgsMsg(MSG *msg, bool unicodeSupported) const { + for (size_t i = 0; i < _hModelessDlgs.size(); i++) + { + if (unicodeSupported?(::IsDialogMessageW(_hModelessDlgs[i], msg)):(::IsDialogMessageA(_hModelessDlgs[i], msg))) + return true; + } + return false; + }; + +// fileOperations + //The doXXX functions apply to a single buffer and dont need to worry about views, with the excpetion of doClose, since closing one view doesnt have to mean the document is gone + BufferID doOpen(const TCHAR *fileName, bool isReadOnly = false); + bool doReload(BufferID id, bool alert = true); + bool doSave(BufferID, const TCHAR * filename, bool isSaveCopy = false); + void doClose(BufferID, int whichOne); + //bool doDelete(const TCHAR *fileName) const {return ::DeleteFile(fileName) != 0;}; + + inline void fileNew(); + void fileOpen(); + inline bool fileReload(); + bool fileClose(BufferID id = BUFFER_INVALID, int curView = -1); //use curView to override view to close from + bool fileCloseAll(); + bool fileCloseAllButCurrent(); + bool fileSave(BufferID id = BUFFER_INVALID); + bool fileSaveAll(); + bool fileSaveAs(BufferID id = BUFFER_INVALID, bool isSaveCopy = false); + bool fileDelete(BufferID id = BUFFER_INVALID, int curView = -1); + bool fileRename(BufferID id = BUFFER_INVALID, int curView = -1); + + bool addBufferToView(BufferID id, int whichOne); + bool moveBuffer(BufferID id, int whereTo); //assumes whereFrom is otherView(whereTo) + bool switchToFile(BufferID buffer); //find buffer in active view then in other view. +// end fileOperations + + bool isFileSession(const TCHAR * filename); + void filePrint(bool showDialog); + bool saveScintillaParams(bool whichOne); + + inline bool saveGUIParams(); + + inline void saveDockingParams(); + + inline void saveUserDefineLangs(); + + inline void saveShortcuts(); + + inline void saveSession(const Session & session); + + inline void saveFindHistory(); + + void getCurrentOpenedFiles(Session & session); + + bool fileLoadSession(const TCHAR *fn = NULL); + const TCHAR * fileSaveSession(size_t nbFile, TCHAR ** fileNames, const TCHAR *sessionFile2save); + const TCHAR * fileSaveSession(size_t nbFile = 0, TCHAR ** fileNames = NULL); + + bool changeDlgLang(HWND hDlg, const char *dlgTagName, char *title = NULL); + void changeFindReplaceDlgLang(); + void changeConfigLang(); + void changeUserDefineLang(); + void changeMenuLang(generic_string & pluginsTrans, generic_string & windowTrans); + void changeLangTabContextMenu(); + void changeLangTabDrapContextMenu(); + void changePrefereceDlgLang(); + void changeShortcutLang(); + void changeShortcutmapperLang(ShortcutMapper * sm); + + const TCHAR * getNativeTip(int btnID); + void changeToolBarIcons(); + + bool doBlockComment(comment_mode currCommentMode); + bool doStreamComment(); + inline void doTrimTrailing(); + + inline HACCEL getAccTable() const{ + return _accelerator.getAccTable(); + }; + + bool addCurrentMacro(); + inline void loadLastSession(); + bool loadSession(Session & session); + winVer getWinVersion() const {return _winVersion;}; + + bool emergency(generic_string emergencySavedDir); + + void notifyBufferChanged(Buffer * buffer, int mask); + bool findInFiles(); + bool replaceInFiles(); + void setFindReplaceFolderFilter(const TCHAR *dir, const TCHAR *filters); + + static HWND gNppHWND; //static handle to Notepad++ window, NULL if non-existant +private: + static const TCHAR _className[32]; + TCHAR _nppPath[MAX_PATH]; + Window *_pMainWindow; + DockingManager _dockingManager; + + AutoCompletion _autoCompleteMain; + AutoCompletion _autoCompleteSub; //each Scintilla has its own autoComplete + + SmartHighlighter _smartHighlighter; + + TiXmlNode *_toolIcons; + TiXmlNodeA *_nativeLangA; + + int _nativeLangEncoding; + + DocTabView _mainDocTab; + DocTabView _subDocTab; + DocTabView *_pDocTab; + DocTabView *_pNonDocTab; + + ScintillaEditView _subEditView; + ScintillaEditView _mainEditView; + ScintillaEditView _invisibleEditView; //for searches + ScintillaEditView _fileEditView; //for FileManager + + ScintillaEditView *_pEditView; + ScintillaEditView *_pNonEditView; + + SplitterContainer *_pMainSplitter; + SplitterContainer _subSplitter; + + ContextMenu _tabPopupMenu, _tabPopupDropMenu; + + ToolBar _toolBar; + IconList _docTabIconList; + + StatusBar _statusBar; + bool _toReduceTabBar; + ReBar _rebarTop; + ReBar _rebarBottom; + + // Dialog + FindReplaceDlg _findReplaceDlg; + FindIncrementDlg _incrementFindDlg; + AboutDlg _aboutDlg; + RunDlg _runDlg; + GoToLineDlg _goToLineDlg; + ColumnEditorDlg _colEditorDlg; + WordStyleDlg _configStyleDlg; + PreferenceDlg _preference; + + // a handle list of all the Notepad++ dialogs + vector _hModelessDlgs; + + LastRecentFileList _lastRecentFileList; + + vector _customIconVect; + + WindowsMenu _windowsMenu; + HMENU _mainMenuHandle; + HMENU _menuLang; + HMENU _menuLangCompact; + + bool _sysMenuEntering; + + // For FullScreen/PostIt features + VisibleGUIConf _beforeSpecialView; + void fullScreenToggle(); + void postItToggle(); + + // Keystroke macro recording and playback + Macro _macro; + bool _recordingMacro; + RunMacroDlg _runMacroDlg; + + // For hotspot + bool _linkTriggered; + bool _isDocModifing; + bool _isHotspotDblClicked; + + //For Dynamic selection highlight + CharacterRange _prevSelectedRange; + + struct ActivateAppInfo { + bool _isActivated; + int _x; + int _y; + ActivateAppInfo() : _isActivated(false), _x(0), _y(0){}; + } _activeAppInf; + + //Synchronized Scolling + + struct SyncInfo { + int _line; + int _column; + bool _isSynScollV; + bool _isSynScollH; + SyncInfo():_line(0), _column(0), _isSynScollV(false), _isSynScollH(false){}; + bool doSync() const {return (_isSynScollV || _isSynScollH); }; + } _syncInfo; + + bool _isUDDocked; + + trayIconControler *_pTrayIco; + int _zoomOriginalValue; + + Accelerator _accelerator; + ScintillaAccelerator _scintaccelerator; + + PluginsManager _pluginsManager; + + bool _isRTL; + winVer _winVersion; + + bool _isFileOpening; + + class ScintillaCtrls { + public : + //ScintillaCtrls(); + void init(HINSTANCE hInst, HWND hNpp) { + _hInst = hInst; + _hParent = hNpp; + }; + + HWND createSintilla(HWND hParent) { + _hParent = hParent; + + ScintillaEditView *scint = new ScintillaEditView; + scint->init(_hInst, _hParent); + _scintVector.push_back(scint); + return scint->getHSelf(); + }; + bool destroyScintilla(HWND handle2Destroy) { + for (size_t i = 0 ; i < _scintVector.size() ; i++) + { + if (_scintVector[i]->getHSelf() == handle2Destroy) + { + _scintVector[i]->destroy(); + delete _scintVector[i]; + + vector::iterator it2delete = _scintVector.begin()+ i; + _scintVector.erase(it2delete); + return true; + } + } + return false; + }; + void destroy() { + for (size_t i = 0 ; i < _scintVector.size() ; i++) + { + _scintVector[i]->destroy(); + delete _scintVector[i]; + } + }; + private: + vector _scintVector; + HINSTANCE _hInst; + HWND _hParent; + } _scintillaCtrls4Plugins; + + vector > _hideLinesMarks; + + static LRESULT CALLBACK Notepad_plus_Proc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam); + LRESULT runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam); + + BOOL notify(SCNotification *notification); + void specialCmd(int id, int param); + void command(int id); + +//Document management + UCHAR _mainWindowStatus; //For 2 views and user dialog if docked + int _activeView; + + //User dialog docking + void dockUserDlg(); + void undockUserDlg(); + + //View visibility + void showView(int whichOne); + bool viewVisible(int whichOne); + void hideView(int whichOne); + void hideCurrentView(); + bool bothActive() { return (_mainWindowStatus & WindowBothActive) == WindowBothActive; }; + bool reloadLang(); + bool loadStyles(); + + int currentView(){ + return _activeView; + }; + int otherView(){ + return (_activeView == MAIN_VIEW?SUB_VIEW:MAIN_VIEW); + }; + int otherFromView(int whichOne){ + return (whichOne == MAIN_VIEW?SUB_VIEW:MAIN_VIEW); + }; + bool canHideView(int whichOne); //true if view can safely be hidden (no open docs etc) + + int switchEditViewTo(int gid); //activate other view (set focus etc) + + void docGotoAnotherEditView(FileTransferMode mode); //TransferMode + void docOpenInNewInstance(FileTransferMode mode, int x = 0, int y = 0); + + void loadBufferIntoView(BufferID id, int whichOne, bool dontClose = false); //Doesnt _activate_ the buffer + void removeBufferFromView(BufferID id, int whichOne); //Activates alternative of possible, or creates clean document if not clean already + + bool activateBuffer(BufferID id, int whichOne); //activate buffer in that view if found + void notifyBufferActivated(BufferID bufid, int view); + void performPostReload(int whichOne); +//END: Document management + + int doSaveOrNot(const TCHAR *fn) { + TCHAR pattern[64] = TEXT("Save file \"%s\" ?"); + TCHAR phrase[512]; + wsprintf(phrase, pattern, fn); + return doActionOrNot(TEXT("Save"), phrase, MB_YESNOCANCEL | MB_ICONQUESTION | MB_APPLMODAL); + }; + + int doReloadOrNot(const TCHAR *fn, bool dirty) { + TCHAR* pattern = TEXT("%s\r\rThis file has been modified by another program.\rDo you want to reload it%s?"); + TCHAR* lose_info_str = dirty ? TEXT(" and lose the changes made in Notepad++") : TEXT(""); + TCHAR phrase[512]; + wsprintf(phrase, pattern, fn, lose_info_str); + int icon = dirty ? MB_ICONEXCLAMATION : MB_ICONQUESTION; + return doActionOrNot(TEXT("Reload"), phrase, MB_YESNO | MB_APPLMODAL | icon); + }; + + int doCloseOrNot(const TCHAR *fn) { + TCHAR pattern[128] = TEXT("The file \"%s\" doesn't exist anymore.\rKeep this file in editor?"); + TCHAR phrase[512]; + wsprintf(phrase, pattern, fn); + return doActionOrNot(TEXT("Keep non existing file"), phrase, MB_YESNO | MB_ICONQUESTION | MB_APPLMODAL); + }; + + int doDeleteOrNot(const TCHAR *fn) { + TCHAR pattern[128] = TEXT("The file \"%s\"\rwill be deleted from your disk and this document will be closed.\rContinue?"); + TCHAR phrase[512]; + wsprintf(phrase, pattern, fn); + return doActionOrNot(TEXT("Delete file"), phrase, MB_YESNO | MB_ICONQUESTION | MB_APPLMODAL); + }; + + int doActionOrNot(const TCHAR *title, const TCHAR *displayText, int type) { + return ::MessageBox(_hSelf, displayText, title, type); + }; + void enableMenu(int cmdID, bool doEnable) const { + int flag = doEnable?MF_ENABLED | MF_BYCOMMAND:MF_DISABLED | MF_GRAYED | MF_BYCOMMAND; + ::EnableMenuItem(_mainMenuHandle, cmdID, flag); + } + void enableCommand(int cmdID, bool doEnable, int which) const; + void checkClipboard(); + void checkDocState(); + void checkUndoState(); + void checkMacroState(); + void checkSyncState(); + void dropFiles(HDROP hdrop); + void checkModifiedDocument(); + + void getMainClientRect(RECT & rc) const; + + void dynamicCheckMenuAndTB() const; + + void enableConvertMenuItems(formatType f) const { + enableCommand(IDM_FORMAT_TODOS, (f != WIN_FORMAT), MENU); + enableCommand(IDM_FORMAT_TOUNIX, (f != UNIX_FORMAT), MENU); + enableCommand(IDM_FORMAT_TOMAC, (f != MAC_FORMAT), MENU); + }; + + void checkUnicodeMenuItems(UniMode um) const; + + generic_string getLangDesc(LangType langType, bool shortDesc = false); + + void setLangStatus(LangType langType){ + _statusBar.setText(getLangDesc(langType).c_str(), STATUSBAR_DOC_TYPE); + }; + + void setDisplayFormat(formatType f) { + std::generic_string str; + switch (f) + { + case MAC_FORMAT : + str = TEXT("MAC"); + break; + case UNIX_FORMAT : + str = TEXT("UNIX"); + break; + default : + str = TEXT("Dos\\Windows"); + } + _statusBar.setText(str.c_str(), STATUSBAR_EOF_FORMAT); + }; + + void setUniModeText(UniMode um) + { + TCHAR *uniModeText; + switch (um) + { + case uniUTF8: + uniModeText = TEXT("UTF-8"); break; + case uni16BE: + uniModeText = TEXT("UCS-2 Big Endian"); break; + case uni16LE: + uniModeText = TEXT("UCS-2 little Endian"); break; + case uniCookie: + uniModeText = TEXT("ANSI as UTF-8"); break; + default : + uniModeText = TEXT("ANSI"); + } + _statusBar.setText(uniModeText, STATUSBAR_UNICODE_TYPE); + }; + + void checkLangsMenu(int id) const ; + + void setLanguage(int id, LangType langType); + + enum LangType menuID2LangType(int cmdID); + + int getFolderMarginStyle() const { + if (::GetMenuState(_mainMenuHandle, IDM_VIEW_FOLDERMAGIN_SIMPLE, MF_BYCOMMAND) == MF_CHECKED) + return IDM_VIEW_FOLDERMAGIN_SIMPLE; + + if (::GetMenuState(_mainMenuHandle, IDM_VIEW_FOLDERMAGIN_ARROW, MF_BYCOMMAND) == MF_CHECKED) + return IDM_VIEW_FOLDERMAGIN_ARROW; + + if (::GetMenuState(_mainMenuHandle, IDM_VIEW_FOLDERMAGIN_CIRCLE, MF_BYCOMMAND) == MF_CHECKED) + return IDM_VIEW_FOLDERMAGIN_CIRCLE; + + if (::GetMenuState(_mainMenuHandle, IDM_VIEW_FOLDERMAGIN_BOX, MF_BYCOMMAND) == MF_CHECKED) + return IDM_VIEW_FOLDERMAGIN_BOX; + + return 0; + }; + + void checkFolderMarginStyleMenu(int id2Check) const { + ::CheckMenuRadioItem(_mainMenuHandle, IDM_VIEW_FOLDERMAGIN_SIMPLE, IDM_VIEW_FOLDERMAGIN_BOX, id2Check, MF_BYCOMMAND); + }; + + int getFolderMaginStyleIDFrom(folderStyle fStyle) const { + switch (fStyle) + { + case FOLDER_STYLE_SIMPLE : return IDM_VIEW_FOLDERMAGIN_SIMPLE; + case FOLDER_STYLE_ARROW : return IDM_VIEW_FOLDERMAGIN_ARROW; + case FOLDER_STYLE_CIRCLE : return IDM_VIEW_FOLDERMAGIN_CIRCLE; + case FOLDER_STYLE_BOX : return IDM_VIEW_FOLDERMAGIN_BOX; + default : return FOLDER_TYPE; + } + //return + }; + + void checkMenuItem(int itemID, bool willBeChecked) const { + ::CheckMenuItem(_mainMenuHandle, itemID, MF_BYCOMMAND | (willBeChecked?MF_CHECKED:MF_UNCHECKED)); + }; + void charAdded(TCHAR chAdded); + void MaintainIndentation(TCHAR ch); + + void addHotSpot(bool docIsModifing = false); + + void bookmarkAdd(int lineno) const { + if (lineno == -1) + lineno = _pEditView->getCurrentLineNumber(); + if (!bookmarkPresent(lineno)) + _pEditView->execute(SCI_MARKERADD, lineno, MARK_BOOKMARK); + }; + void bookmarkDelete(int lineno) const { + if (lineno == -1) + lineno = _pEditView->getCurrentLineNumber(); + if ( bookmarkPresent(lineno)) + _pEditView->execute(SCI_MARKERDELETE, lineno, MARK_BOOKMARK); + }; + bool bookmarkPresent(int lineno) const { + if (lineno == -1) + lineno = _pEditView->getCurrentLineNumber(); + LRESULT state = _pEditView->execute(SCI_MARKERGET, lineno); + return ((state & (1 << MARK_BOOKMARK)) != 0); + }; + void bookmarkToggle(int lineno) const { + if (lineno == -1) + lineno = _pEditView->getCurrentLineNumber(); + + if (bookmarkPresent(lineno)) + bookmarkDelete(lineno); + else + bookmarkAdd(lineno); + }; + void bookmarkNext(bool forwardScan); + void bookmarkClearAll() const { + _pEditView->execute(SCI_MARKERDELETEALL, MARK_BOOKMARK); + }; + + + void copyMarkedLines() { + int lastLine = _pEditView->lastZeroBasedLineNumber(); + generic_string globalStr = TEXT(""); + for (int i = lastLine ; i >= 0 ; i--) + { + if (bookmarkPresent(i)) + { + generic_string currentStr = getMarkedLine(i) + globalStr; + globalStr = currentStr; + } + } + str2Cliboard(globalStr.c_str()); + }; + + void cutMarkedLines() { + int lastLine = _pEditView->lastZeroBasedLineNumber(); + generic_string globalStr = TEXT(""); + + _pEditView->execute(SCI_BEGINUNDOACTION); + for (int i = lastLine ; i >= 0 ; i--) + { + if (bookmarkPresent(i)) + { + generic_string currentStr = getMarkedLine(i) + globalStr; + globalStr = currentStr; + + deleteMarkedline(i); + } + } + _pEditView->execute(SCI_ENDUNDOACTION); + str2Cliboard(globalStr.c_str()); + }; + + void deleteMarkedLines() { + int lastLine = _pEditView->lastZeroBasedLineNumber(); + + _pEditView->execute(SCI_BEGINUNDOACTION); + for (int i = lastLine ; i >= 0 ; i--) + { + if (bookmarkPresent(i)) + deleteMarkedline(i); + } + _pEditView->execute(SCI_ENDUNDOACTION); + }; + + void pasteToMarkedLines() { + int clipFormat; + #ifdef UNICODE + clipFormat = CF_UNICODETEXT; + #else + clipFormat = CF_TEXT; + #endif + BOOL canPaste = ::IsClipboardFormatAvailable(clipFormat); + if (!canPaste) + return; + int lastLine = _pEditView->lastZeroBasedLineNumber(); + + ::OpenClipboard(_hSelf); + HANDLE clipboardData = ::GetClipboardData(clipFormat); + int len = ::GlobalSize(clipboardData); + LPVOID clipboardDataPtr = ::GlobalLock(clipboardData); + + generic_string clipboardStr = (const TCHAR *)clipboardDataPtr; + + ::GlobalUnlock(clipboardData); + ::CloseClipboard(); + + _pEditView->execute(SCI_BEGINUNDOACTION); + for (int i = lastLine ; i >= 0 ; i--) + { + if (bookmarkPresent(i)) + { + replaceMarkedline(i, clipboardStr.c_str()); + } + } + _pEditView->execute(SCI_ENDUNDOACTION); + }; + + void deleteMarkedline(int ln) { + int lineLen = _pEditView->execute(SCI_LINELENGTH, ln); + int lineBegin = _pEditView->execute(SCI_POSITIONFROMLINE, ln); + + bookmarkDelete(ln); + TCHAR emptyString[2] = TEXT(""); + _pEditView->replaceTarget(emptyString, lineBegin, lineBegin + lineLen); + }; + + void replaceMarkedline(int ln, const TCHAR *str) { + int lineBegin = _pEditView->execute(SCI_POSITIONFROMLINE, ln); + int lineEnd = _pEditView->execute(SCI_GETLINEENDPOSITION, ln); + + _pEditView->replaceTarget(str, lineBegin, lineEnd); + }; + + generic_string getMarkedLine(int ln) { + int lineLen = _pEditView->execute(SCI_LINELENGTH, ln); + int lineBegin = _pEditView->execute(SCI_POSITIONFROMLINE, ln); + + TCHAR * buf = new TCHAR[lineLen+1]; + _pEditView->getGenericText(buf, lineBegin, lineBegin + lineLen); + generic_string line = buf; + delete [] buf; + + return line; + }; + + void findMatchingBracePos(int & braceAtCaret, int & braceOpposite); + void braceMatch(); + + void activateNextDoc(bool direction); + void activateDoc(int pos); + + void updateStatusBar(); + + void showAutoComp(); + void autoCompFromCurrentFile(bool autoInsert = true); + void showFunctionComp(); + + void changeStyleCtrlsLang(HWND hDlg, int *idArray, const char **translatedText); + bool replaceAllFiles(); + bool findInOpenedFiles(); + bool findInCurrentFile(); + + bool matchInList(const TCHAR *fileName, const vector & patterns); + void getMatchedFileNames(const TCHAR *dir, const vector & patterns, vector & fileNames, bool isRecursive, bool isInHiddenDir); + + void doSynScorll(HWND hW); + void setWorkingDir(TCHAR *dir) { + NppParameters * params = NppParameters::getInstance(); + if (params->getNppGUI()._openSaveDir == dir_last) + return; + if (params->getNppGUI()._openSaveDir == dir_userDef) + { + params->setWorkingDir(NULL); + } + else if (dir && PathIsDirectory(dir)) + { + params->setWorkingDir(dir); + } + } + bool str2Cliboard(const TCHAR *str2cpy); + bool bin2Cliboard(const UCHAR *uchar2cpy, size_t length); + + bool getIntegralDockingData(tTbData & dockData, int & iCont, bool & isVisible); + + int getLangFromMenuName(const TCHAR * langName) { + int id = 0; + const int menuSize = 64; + TCHAR menuLangName[menuSize]; + + for ( int i = IDM_LANG_C; i <= IDM_LANG_USER; i++ ) + if ( ::GetMenuString( _mainMenuHandle, i, menuLangName, menuSize, MF_BYCOMMAND ) ) + if ( !lstrcmp( langName, menuLangName ) ) + { + id = i; + break; + } + + if ( id == 0 ) + { + for ( int i = IDM_LANG_USER + 1; i <= IDM_LANG_USER_LIMIT; i++ ) + if ( ::GetMenuString( _mainMenuHandle, i, menuLangName, menuSize, MF_BYCOMMAND ) ) + if ( !lstrcmp( langName, menuLangName ) ) + { + id = i; + break; + } + } + + return id; + }; + + generic_string getLangFromMenu(const Buffer * buf) { + int id; + const TCHAR * userLangName; + TCHAR menuLangName[32]; + + id = (NppParameters::getInstance())->langTypeToCommandID( buf->getLangType() ); + + if ( ( id != IDM_LANG_USER ) || !( buf->isUserDefineLangExt() ) ) + { + ( ::GetMenuString( _mainMenuHandle, id, menuLangName, sizeof( menuLangName ), MF_BYCOMMAND ) ); + userLangName = (TCHAR *)menuLangName; + } + else + { + userLangName = buf->getUserDefineLangName(); + } + return userLangName; + }; + + void setFileOpenSaveDlgFilters(FileDialog & fDlg); + void markSelectedTextInc(bool enable); + + Style * getStyleFromName(const TCHAR *styleName) { + StyleArray & stylers = (NppParameters::getInstance())->getMiscStylerArray(); + + int i = stylers.getStylerIndexByName(styleName); + Style * st = NULL; + if (i != -1) + { + Style & style = stylers.getStyler(i); + st = &style; + } + return st; + }; + + bool dumpFiles(const TCHAR * outdir, const TCHAR * fileprefix = TEXT("")); //helper func + void drawTabbarColoursFromStylerArray(); + + void loadCommandlineParams(const TCHAR * commandLine, CmdLineParams * pCmdParams); + + bool noOpenedDoc() const { + if (_mainDocTab.isVisible() && _subDocTab.isVisible()) + return false; + if (_pDocTab->nbItem() == 1) + { + BufferID buffer = _pDocTab->getBufferByIndex(0); + Buffer * buf = MainFileManager->getBufferByID(buffer); + if (!buf->isDirty() && buf->isUntitled()) + return true; + } + return false; + }; +}; + +#endif //NOTEPAD_PLUS_H diff --git a/PowerEditor/src/Notepad_plus.rc b/PowerEditor/src/Notepad_plus.rc new file mode 100644 index 00000000..0dca6778 --- /dev/null +++ b/PowerEditor/src/Notepad_plus.rc @@ -0,0 +1,622 @@ + /* +this file is part of notepad++ +Copyright (C)2003 Don HO ( donho@altern.org ) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include +#include "resource.h" +#include "menuCmdID.h" + +VS_VERSION_INFO VERSIONINFO +FILEVERSION VERSION_DIGITALVALUE +PRODUCTVERSION VERSION_DIGITALVALUE +FILEFLAGSMASK 0x3fL +FILEFLAGS 0 +FILEOS VOS_NT_WINDOWS32 +FILETYPE VFT_APP +FILESUBTYPE VFT2_UNKNOWN +BEGIN + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "CompanyName", "Don HO don.h@free.fr\0" + VALUE "FileDescription", "Notepad++ : a free (GNU) source code editor\0" + VALUE "FileVersion", VERSION_VALUE + VALUE "InternalName", "npp.exe\0" + VALUE "LegalCopyright", "Copyleft 1998-2006 by Don HO\0" + VALUE "OriginalFilename", "Notepad++.exe\0" + VALUE "ProductName", "Notepad++\0" + VALUE "ProductVersion", VERSION_VALUE + END + END +END + +// Icon with lowest ID value placed first to ensure application icon +// remains consistent on all systems. +IDI_M30ICON ICON "icons\\npp.ico" +IDI_NEW_OFF_ICON ICON "icons\\new_off.ico" +IDI_OPEN_OFF_ICON ICON "icons\\open_off.ico" +IDI_SAVE_OFF_ICON ICON "icons\\save_off.ico" +IDI_SAVEALL_OFF_ICON ICON "icons\\saveall_off.ico" +IDI_CLOSE_OFF_ICON ICON "icons\\supp_off.ico" +IDI_CLOSEALL_OFF_ICON ICON "icons\\suppall_off.ico" +IDI_CUT_OFF_ICON ICON "icons\\cut_off.ico" +IDI_COPY_OFF_ICON ICON "icons\\dupli_off.ico" +IDI_PASTE_OFF_ICON ICON "icons\\paste_off.ico" +IDI_UNDO_OFF_ICON ICON "icons\\undo_off.ico" +IDI_REDO_OFF_ICON ICON "icons\\redo_off.ico" +IDI_FIND_OFF_ICON ICON "icons\\find_off.ico" +IDI_REPLACE_OFF_ICON ICON "icons\\findrep_off.ico" +IDI_ZOOMIN_OFF_ICON ICON "icons\\zoomIn_off.ico" +IDI_ZOOMOUT_OFF_ICON ICON "icons\\zoomOut_off.ico" +IDI_VIEW_UD_DLG_OFF_ICON ICON "icons\\userDefineDlg_off.ico" +IDI_VIEW_ALL_CHAR_OFF_ICON ICON "icons\\allChars_off.ico" +IDI_VIEW_INDENT_OFF_ICON ICON "icons\\indentGuide_off.ico" +IDI_VIEW_WRAP_OFF_ICON ICON "icons\\wrap_off.ico" +IDI_PRINT_OFF_ICON ICON "icons\\imprim_off.ico" + +IDI_NEW_ON_ICON ICON "icons\\new_on.ico" +IDI_OPEN_ON_ICON ICON "icons\\open_on.ico" +IDI_SAVE_ON_ICON ICON "icons\\save_on.ico" +IDI_SAVEALL_ON_ICON ICON "icons\\saveall_on.ico" +IDI_CLOSE_ON_ICON ICON "icons\\supp_on.ico" +IDI_CLOSEALL_ON_ICON ICON "icons\\suppall_on.ico" +IDI_CUT_ON_ICON ICON "icons\\cut_on.ico" +IDI_COPY_ON_ICON ICON "icons\\dupli_on.ico" +IDI_PASTE_ON_ICON ICON "icons\\paste_on.ico" +IDI_UNDO_ON_ICON ICON "icons\\undo_on.ico" +IDI_REDO_ON_ICON ICON "icons\\redo_on.ico" +IDI_FIND_ON_ICON ICON "icons\\find_on.ico" +IDI_REPLACE_ON_ICON ICON "icons\\findrep_on.ico" +IDI_ZOOMIN_ON_ICON ICON "icons\\zoomIn_on.ico" +IDI_ZOOMOUT_ON_ICON ICON "icons\\zoomOut_on.ico" +IDI_VIEW_UD_DLG_ON_ICON ICON "icons\\userDefineDlg_on.ico" +IDI_VIEW_ALL_CHAR_ON_ICON ICON "icons\\allChars_on.ico" +IDI_VIEW_INDENT_ON_ICON ICON "icons\\indentGuide_on.ico" +IDI_VIEW_WRAP_ON_ICON ICON "icons\\wrap_on.ico" +IDI_PRINT_ON_ICON ICON "icons\\imprim_on.ico" + +IDI_SAVE_DISABLE_ICON ICON "icons\\save_dis.ico" +IDI_SAVEALL_DISABLE_ICON ICON "icons\\saveall_dis.ico" +IDI_CUT_DISABLE_ICON ICON "icons\\cut_dis.ico" +IDI_COPY_DISABLE_ICON ICON "icons\\dupli_dis.ico" +IDI_PASTE_DISABLE_ICON ICON "icons\\paste_dis.ico" +IDI_UNDO_DISABLE_ICON ICON "icons\\undo_dis.ico" +IDI_REDO_DISABLE_ICON ICON "icons\\redo_dis.ico" +// +IDI_SAVED_ICON ICON "icons\\saved.ico" +IDI_UNSAVED_ICON ICON "icons\\unsaved.ico" +IDI_READONLY_ICON ICON "icons\\readonly.ico" +IDI_DELETE_ICON ICON "icons\\delete.ico" + +IDI_FIND_RESULT_ICON ICON "icons\\findResult.ico" + +IDC_DRAG_TAB CURSOR "cursors\\drag.cur" +IDC_DRAG_INTERDIT_TAB CURSOR "cursors\\drag_interdit.cur" +IDC_DRAG_PLUS_TAB CURSOR "cursors\\drag_plus.cur" +IDC_DRAG_OUT_TAB CURSOR "cursors\\drag_out.cur" + +IDR_FILENEW BITMAP "icons\\newFile.bmp" +IDR_FILEOPEN BITMAP "icons\\openFile.bmp" +IDR_FILESAVE BITMAP "icons\\saveFile.bmp" +IDR_SAVEALL BITMAP "icons\\saveAll.bmp" +IDR_CLOSEFILE BITMAP "icons\\closeFile.bmp" +IDR_CLOSEALL BITMAP "icons\\closeAll.bmp" +IDR_FIND BITMAP "icons\\find.bmp" +IDR_REPLACE BITMAP "icons\\findReplace.bmp" +IDR_ZOOMIN BITMAP "icons\\zoomIn.bmp" +IDR_ZOOMOUT BITMAP "icons\\zoomOut.bmp" +IDR_WRAP BITMAP "icons\\wrap.bmp" +IDR_INVISIBLECHAR BITMAP "icons\\invisibleChar.bmp" +IDR_INDENTGUIDE BITMAP "icons\\indentGuide.bmp" +IDR_SHOWPANNEL BITMAP "icons\\showPannel.bmp" +IDR_STARTRECORD BITMAP "icons\\startRecord.bmp" +IDR_STOPRECORD BITMAP "icons\\stopRecord.bmp" +IDR_PLAYRECORD BITMAP "icons\\playRecord.bmp" +IDR_M_PLAYRECORD BITMAP "icons\\playRecord_m.bmp" +IDR_SAVERECORD BITMAP "icons\\saveRecord.bmp" +IDR_CUT BITMAP "icons\\cut.bmp" +IDR_COPY BITMAP "icons\\copy.bmp" +IDR_PASTE BITMAP "icons\\paste.bmp" +IDR_UNDO BITMAP "icons\\undo.bmp" +IDR_REDO BITMAP "icons\\redo.bmp" + +IDR_SYNCV BITMAP "icons\\syncV.bmp" +IDR_SYNCH BITMAP "icons\\syncH.bmp" +IDR_PRINT BITMAP "icons\\print.bmp" +IDR_CLOSETAB BITMAP "icons\\closeTabButton.bmp" +IDR_CLOSETAB_INACT BITMAP "icons\\closeTabButton_inact.bmp" +IDR_CLOSETAB_HOVER BITMAP "icons\\closeTabButton_hover.bmp" +IDR_CLOSETAB_PUSH BITMAP "icons\\closeTabButton_push.bmp" + +IDI_STARTRECORD_OFF_ICON ICON "icons\\startrecord_off.ico" +IDI_STARTRECORD_ON_ICON ICON "icons\\startrecord_on.ico" +IDI_STARTRECORD_DISABLE_ICON ICON "icons\\startrecord_dis.ico" +IDI_STOPRECORD_OFF_ICON ICON "icons\\stoprecord_off.ico" +IDI_STOPRECORD_ON_ICON ICON "icons\\stoprecord_on.ico" +IDI_STOPRECORD_DISABLE_ICON ICON "icons\\stoprecord_dis.ico" +IDI_PLAYRECORD_OFF_ICON ICON "icons\\playrecord_off.ico" +IDI_PLAYRECORD_ON_ICON ICON "icons\\playrecord_on.ico" +IDI_PLAYRECORD_DISABLE_ICON ICON "icons\\playrecord_dis.ico" +IDI_SAVERECORD_OFF_ICON ICON "icons\\saverecord_off.ico" +IDI_SAVERECORD_ON_ICON ICON "icons\\saverecord_on.ico" +IDI_SAVERECORD_DISABLE_ICON ICON "icons\\saverecord_dis.ico" + +IDI_SYNCV_OFF_ICON ICON "icons\\syncV_off.ico" +IDI_SYNCV_ON_ICON ICON "icons\\syncV_on.ico" +IDI_SYNCV_DISABLE_ICON ICON "icons\\syncV_dis.ico" +IDI_SYNCH_OFF_ICON ICON "icons\\syncH_off.ico" +IDI_SYNCH_ON_ICON ICON "icons\\syncH_on.ico" +IDI_SYNCH_DISABLE_ICON ICON "icons\\syncH_dis.ico" + +// multi run macro +IDI_MMPLAY_DIS_ICON ICON "icons\\playrecord_m_dis.ico" +IDI_MMPLAY_OFF_ICON ICON "icons\\playrecord_m_off.ico" +IDI_MMPLAY_ON_ICON ICON "icons\\playrecord_m_on.ico" + +IDR_M30_MENU MENU +BEGIN + POPUP "&File" + BEGIN + MENUITEM "&New", IDM_FILE_NEW + MENUITEM "&Open...", IDM_FILE_OPEN + MENUITEM "Re&load from Disk", IDM_FILE_RELOAD + MENUITEM "&Save", IDM_FILE_SAVE + MENUITEM "Save &As...", IDM_FILE_SAVEAS + MENUITEM "Save a Copy As...", IDM_FILE_SAVECOPYAS + MENUITEM "Sav&e All", IDM_FILE_SAVEALL + MENUITEM "Rename...", IDM_FILE_RENAME + MENUITEM "&Close", IDM_FILE_CLOSE + MENUITEM "Cl&ose All", IDM_FILE_CLOSEALL + MENUITEM "Close All but Active Document", IDM_FILE_CLOSEALL_BUT_CURRENT + MENUITEM "Delete from Disk", IDM_FILE_DELETE + MENUITEM SEPARATOR + MENUITEM "Load Session...", IDM_FILE_LOADSESSION + MENUITEM "Save Session...", IDM_FILE_SAVESESSION + MENUITEM SEPARATOR + MENUITEM "Print...", IDM_FILE_PRINT + MENUITEM "Print Now!", IDM_FILE_PRINTNOW + MENUITEM SEPARATOR + MENUITEM "E&xit", IDM_FILE_EXIT + END + + POPUP "&Edit" + BEGIN + MENUITEM "&Undo", IDM_EDIT_UNDO + MENUITEM "&Redo", IDM_EDIT_REDO + MENUITEM SEPARATOR + MENUITEM "Cu&t", IDM_EDIT_CUT + MENUITEM "&Copy", IDM_EDIT_COPY + MENUITEM "&Paste", IDM_EDIT_PASTE + MENUITEM "Select A&ll", IDM_EDIT_SELECTALL + MENUITEM SEPARATOR + POPUP "Copy to clipboard" + BEGIN + MENUITEM "Current full file path to Clipboard", IDM_EDIT_FULLPATHTOCLIP + MENUITEM "Current file name to Clipboard", IDM_EDIT_FILENAMETOCLIP + MENUITEM "Current dir path to Clipboard", IDM_EDIT_CURRENTDIRTOCLIP + END + POPUP "Indent" + BEGIN + MENUITEM "Increase Line Indent", IDM_EDIT_INS_TAB + MENUITEM "Decrease Line Indent", IDM_EDIT_RMV_TAB + END + POPUP "Convert case" + BEGIN + MENUITEM "to &UPPERCASE", IDM_EDIT_UPPERCASE + MENUITEM "to &lowercase", IDM_EDIT_LOWERCASE + END + POPUP "Line operations" + BEGIN + MENUITEM "Duplicate current line", IDM_EDIT_DUP_LINE + MENUITEM "Split lines", IDM_EDIT_SPLIT_LINES + MENUITEM "Join lines", IDM_EDIT_JOIN_LINES + MENUITEM "Move Up current line", IDM_EDIT_LINE_UP + MENUITEM "Move Down current line", IDM_EDIT_LINE_DOWN + END + POPUP "Comment/Uncomment" + BEGIN + MENUITEM "Toggle block comment", IDM_EDIT_BLOCK_COMMENT + MENUITEM "Block comment", IDM_EDIT_BLOCK_COMMENT_SET + MENUITEM "Block uncomment", IDM_EDIT_BLOCK_UNCOMMENT + MENUITEM "Stream comment", IDM_EDIT_STREAM_COMMENT + END + POPUP "Auto-completion" + BEGIN + MENUITEM "Function completion", IDM_EDIT_AUTOCOMPLETE + MENUITEM "Word completion", IDM_EDIT_AUTOCOMPLETE_CURRENTFILE + MENUITEM "Function parameters hint", IDM_EDIT_FUNCCALLTIP + END + MENUITEM "Trim Trailing Space", IDM_EDIT_TRIMTRAILING + MENUITEM SEPARATOR + MENUITEM "Column Editor...", IDM_EDIT_COLUMNMODE + MENUITEM SEPARATOR + MENUITEM "Set Read Only", IDM_EDIT_SETREADONLY + MENUITEM "Clear Read Only Flag", IDM_EDIT_CLEARREADONLY + //MENUITEM SEPARATOR + END + + POPUP "&Search" + BEGIN + MENUITEM "&Find...", IDM_SEARCH_FIND + MENUITEM "Find in files...", IDM_SEARCH_FINDINFILES + MENUITEM "Find &Next", IDM_SEARCH_FINDNEXT + MENUITEM "Find &Previous", IDM_SEARCH_FINDPREV + MENUITEM "Find (volatile) Next", IDM_SEARCH_VOLATILE_FINDNEXT + MENUITEM "Find (volatile) Previous", IDM_SEARCH_VOLATILE_FINDPREV + MENUITEM "&Replace...", IDM_SEARCH_REPLACE + MENUITEM "&Incremental Search...", IDM_SEARCH_FINDINCREMENT + MENUITEM "&Go to...", IDM_SEARCH_GOTOLINE + MENUITEM "Go to matching brace", IDM_SEARCH_GOTOMATCHINGBRACE + MENUITEM SEPARATOR + + POPUP "Mark all" + BEGIN + MENUITEM "Using 1st style", IDM_SEARCH_MARKALLEXT1 + MENUITEM "Using 2nd style", IDM_SEARCH_MARKALLEXT2 + MENUITEM "Using 3rd style", IDM_SEARCH_MARKALLEXT3 + MENUITEM "Using 4th style", IDM_SEARCH_MARKALLEXT4 + MENUITEM "Using 5th style", IDM_SEARCH_MARKALLEXT5 + END + POPUP "Unmark all" + BEGIN + MENUITEM "Clear 1st style", IDM_SEARCH_UNMARKALLEXT1 + MENUITEM "Clear 2nd style", IDM_SEARCH_UNMARKALLEXT2 + MENUITEM "Clear 3rd style", IDM_SEARCH_UNMARKALLEXT3 + MENUITEM "Clear 4th style", IDM_SEARCH_UNMARKALLEXT4 + MENUITEM "Clear 5th style", IDM_SEARCH_UNMARKALLEXT5 + MENUITEM "Clear all styles", IDM_SEARCH_CLEARALLMARKS + END + + + MENUITEM SEPARATOR + MENUITEM "Toggle Bookmark" , IDM_SEARCH_TOGGLE_BOOKMARK + MENUITEM "Next Bookmark", IDM_SEARCH_NEXT_BOOKMARK + MENUITEM "Previous Bookmark", IDM_SEARCH_PREV_BOOKMARK + MENUITEM "Clear all Bookmarks", IDM_SEARCH_CLEAR_BOOKMARKS + MENUITEM "Cut bookmarked lines", IDM_SEARCH_CUTMARKEDLINES + MENUITEM "Copy bookmarked lines", IDM_SEARCH_COPYMARKEDLINES + MENUITEM "Paste to (Replace) bookmarked lines", IDM_SEARCH_PASTEMARKEDLINES + MENUITEM "Delete bookmarked lines", IDM_SEARCH_DELETEMARKEDLINES + END + + POPUP "&View" + BEGIN + MENUITEM "Always on top", IDM_VIEW_ALWAYSONTOP + MENUITEM "Toggle Full Screen Mode", IDM_VIEW_FULLSCREENTOGGLE + MENUITEM "Post-it", IDM_VIEW_POSTIT + + MENUITEM SEPARATOR + POPUP "Show Symbol" + BEGIN + MENUITEM "Show White Space and TAB", IDM_VIEW_TAB_SPACE + MENUITEM "Show End Of Line", IDM_VIEW_EOL + MENUITEM "Show all characters", IDM_VIEW_ALL_CHARACTERS + MENUITEM SEPARATOR + MENUITEM "Show Indent guide", IDM_VIEW_INDENT_GUIDE + MENUITEM "Show wrap symbol", IDM_VIEW_WRAP_SYMBOL + END + POPUP "Zoom" + BEGIN + MENUITEM "Zoom &in", IDM_VIEW_ZOOMIN + MENUITEM "Zoom &out", IDM_VIEW_ZOOMOUT + MENUITEM "Restore default zoom", IDM_VIEW_ZOOMRESTORE + END + POPUP "Move/Clone current document" + BEGIN + MENUITEM "Move to other view", IDM_VIEW_GOTO_ANOTHER_VIEW + MENUITEM "Clone to other view", IDM_VIEW_CLONE_TO_ANOTHER_VIEW + MENUITEM "Move to new instance", IDM_VIEW_GOTO_NEW_INSTANCE + MENUITEM "Open in new instance", IDM_VIEW_LOAD_IN_NEW_INSTANCE + END + MENUITEM "Word wrap", IDM_VIEW_WRAP + MENUITEM "Focus on other view", IDM_VIEW_SWITCHTO_OTHER_VIEW + MENUITEM "Hide lines", IDM_VIEW_HIDELINES + MENUITEM "User Define Dialog...", IDM_VIEW_USER_DLG + MENUITEM SEPARATOR + MENUITEM "Fold all", IDM_VIEW_TOGGLE_FOLDALL + MENUITEM "Unfold all", IDM_VIEW_TOGGLE_UNFOLDALL + MENUITEM "Collapse current level", IDM_VIEW_FOLD_CURRENT + MENUITEM "Uncollapse current level", IDM_VIEW_UNFOLD_CURRENT + POPUP "Collapse level" + BEGIN + MENUITEM "1" , IDM_VIEW_FOLD_1 + MENUITEM "2", IDM_VIEW_FOLD_2 + MENUITEM "3", IDM_VIEW_FOLD_3 + MENUITEM "4", IDM_VIEW_FOLD_4 + MENUITEM "5" , IDM_VIEW_FOLD_5 + MENUITEM "6", IDM_VIEW_FOLD_6 + MENUITEM "7", IDM_VIEW_FOLD_7 + MENUITEM "8", IDM_VIEW_FOLD_8 + END + POPUP "Uncollapse level" + BEGIN + MENUITEM "1" , IDM_VIEW_UNFOLD_1 + MENUITEM "2", IDM_VIEW_UNFOLD_2 + MENUITEM "3", IDM_VIEW_UNFOLD_3 + MENUITEM "4", IDM_VIEW_UNFOLD_4 + MENUITEM "5" , IDM_VIEW_UNFOLD_5 + MENUITEM "6", IDM_VIEW_UNFOLD_6 + MENUITEM "7", IDM_VIEW_UNFOLD_7 + MENUITEM "8", IDM_VIEW_UNFOLD_8 + END + + MENUITEM SEPARATOR + MENUITEM "Synchronize Vertical Scrolling", IDM_VIEW_SYNSCROLLV + MENUITEM "Synchronize Horizontal Scrolling", IDM_VIEW_SYNSCROLLH + MENUITEM SEPARATOR + MENUITEM "Text Direction RTL", IDM_EDIT_RTL + MENUITEM "Text Direction LTR", IDM_EDIT_LTR + END + + POPUP "For&mat" + BEGIN + MENUITEM "Convert to Windows Format", IDM_FORMAT_TODOS + MENUITEM "Convert to UNIX Format", IDM_FORMAT_TOUNIX + MENUITEM "Convert to Mac Format", IDM_FORMAT_TOMAC + MENUITEM SEPARATOR + MENUITEM "Encode in ANSI", IDM_FORMAT_ANSI + MENUITEM "Encode in UTF-8 without BOM", IDM_FORMAT_AS_UTF_8 + MENUITEM "Encode in UTF-8", IDM_FORMAT_UTF_8 + MENUITEM "Encode in UCS-2 Big Endian", IDM_FORMAT_UCS_2BE + MENUITEM "Encode in UCS-2 Little Endian", IDM_FORMAT_UCS_2LE + MENUITEM SEPARATOR + MENUITEM "Convert to ANSI", IDM_FORMAT_CONV2_ANSI + MENUITEM "Convert to UTF-8 without BOM", IDM_FORMAT_CONV2_AS_UTF_8 + MENUITEM "Convert to UTF-8", IDM_FORMAT_CONV2_UTF_8 + MENUITEM "Convert to UCS-2 Big Endian", IDM_FORMAT_CONV2_UCS_2BE + MENUITEM "Convert to UCS-2 Little Endian", IDM_FORMAT_CONV2_UCS_2LE + END + + POPUP "&Language" + BEGIN + + MENUITEM "Ada", IDM_LANG_ADA + MENUITEM "ASP", IDM_LANG_ASP + MENUITEM "Assembly", IDM_LANG_ASM + MENUITEM "AutoIt", IDM_LANG_AU3 + MENUITEM "Batch", IDM_LANG_BATCH + MENUITEM "C", IDM_LANG_C + MENUITEM "C#", IDM_LANG_CS + MENUITEM "C++", IDM_LANG_CPP + MENUITEM "Caml", IDM_LANG_CAML + MENUITEM "Cmake", IDM_LANG_CMAKE + MENUITEM "CSS", IDM_LANG_CSS + MENUITEM "Diff", IDM_LANG_DIFF + MENUITEM "Flash actionscript", IDM_LANG_FLASH + MENUITEM "Fortran", IDM_LANG_FORTRAN + MENUITEM "Haskell", IDM_LANG_HASKELL + MENUITEM "HTML", IDM_LANG_HTML + MENUITEM "INNO", IDM_LANG_INNO + MENUITEM "Java", IDM_LANG_JAVA + MENUITEM "Javascript", IDM_LANG_JS + MENUITEM "KIXtart", IDM_LANG_KIX + MENUITEM "LISP", IDM_LANG_LISP + MENUITEM "Lua", IDM_LANG_LUA + MENUITEM "Makefile", IDM_LANG_MAKEFILE + MENUITEM "Matlab", IDM_LANG_MATLAB + MENUITEM "MS INI file", IDM_LANG_INI + MENUITEM "MS-DOS Style", IDM_LANG_ASCII + MENUITEM "Normal Text", IDM_LANG_TEXT + MENUITEM "NSIS", IDM_LANG_NSIS + MENUITEM "Objective-C", IDM_LANG_OBJC + MENUITEM "Pascal", IDM_LANG_PASCAL + MENUITEM "Perl", IDM_LANG_PERL + MENUITEM "PHP", IDM_LANG_PHP + MENUITEM "Postscript", IDM_LANG_PS + MENUITEM "Properties", IDM_LANG_PROPS + MENUITEM "Python", IDM_LANG_PYTHON + MENUITEM "rc resource file", IDM_LANG_RC + MENUITEM "Ruby", IDM_LANG_RUBY + MENUITEM "Shell", IDM_LANG_SH + MENUITEM "Scheme", IDM_LANG_SCHEME + MENUITEM "Smalltalk", IDM_LANG_SMALLTALK + MENUITEM "SQL", IDM_LANG_SQL + MENUITEM "TCL", IDM_LANG_TCL + MENUITEM "TeX", IDM_LANG_TEX + MENUITEM "VB", IDM_LANG_VB + MENUITEM "VHDL", IDM_LANG_VHDL + MENUITEM "Verilog", IDM_LANG_VERILOG + MENUITEM "XML", IDM_LANG_XML + MENUITEM "YAML", IDM_LANG_YAML + MENUITEM SEPARATOR + MENUITEM "User Defined", IDM_LANG_USER + END + POPUP "&Language" + BEGIN + POPUP "A" + BEGIN + MENUITEM "Ada", IDM_LANG_ADA + MENUITEM "ASP", IDM_LANG_ASP + MENUITEM "Assembly", IDM_LANG_ASM + MENUITEM "AutoIt", IDM_LANG_AU3 + END + MENUITEM "Batch", IDM_LANG_BATCH + POPUP "C" + BEGIN + MENUITEM "C", IDM_LANG_C + MENUITEM "C#", IDM_LANG_CS + MENUITEM "C++", IDM_LANG_CPP + MENUITEM "Caml", IDM_LANG_CAML + MENUITEM "Cmake", IDM_LANG_CMAKE + MENUITEM "CSS", IDM_LANG_CSS + END + MENUITEM "Diff", IDM_LANG_DIFF + POPUP "F" + BEGIN + MENUITEM "Flash actionscript", IDM_LANG_FLASH + MENUITEM "Fortran", IDM_LANG_FORTRAN + END + POPUP "H" + BEGIN + MENUITEM "Haskell", IDM_LANG_HASKELL + MENUITEM "HTML", IDM_LANG_HTML + END + MENUITEM "INNO", IDM_LANG_INNO + POPUP "J" + BEGIN + MENUITEM "Java", IDM_LANG_JAVA + MENUITEM "Javascript", IDM_LANG_JS + END + MENUITEM "KIXtart", IDM_LANG_KIX + POPUP "L" + BEGIN + MENUITEM "LISP", IDM_LANG_LISP + MENUITEM "Lua", IDM_LANG_LUA + END + POPUP "M" + BEGIN + MENUITEM "Makefile", IDM_LANG_MAKEFILE + MENUITEM "Matlab", IDM_LANG_MATLAB + MENUITEM "MS INI file", IDM_LANG_INI + MENUITEM "MS-DOS Style", IDM_LANG_ASCII + END + POPUP "N" + BEGIN + MENUITEM "Normal Text", IDM_LANG_TEXT + MENUITEM "NSIS", IDM_LANG_NSIS + END + MENUITEM "Objective-C", IDM_LANG_OBJC + POPUP "P" + BEGIN + MENUITEM "Pascal", IDM_LANG_PASCAL + MENUITEM "Perl", IDM_LANG_PERL + MENUITEM "PHP", IDM_LANG_PHP + MENUITEM "Postscript", IDM_LANG_PS + MENUITEM "Properties", IDM_LANG_PROPS + MENUITEM "Python", IDM_LANG_PYTHON + END + POPUP "R" + BEGIN + MENUITEM "rc resource file", IDM_LANG_RC + MENUITEM "Ruby", IDM_LANG_RUBY + END + POPUP "S" + BEGIN + MENUITEM "Shell", IDM_LANG_SH + MENUITEM "Scheme", IDM_LANG_SCHEME + MENUITEM "Smalltalk", IDM_LANG_SMALLTALK + MENUITEM "SQL", IDM_LANG_SQL + END + POPUP "T" + BEGIN + MENUITEM "TCL", IDM_LANG_TCL + MENUITEM "TeX", IDM_LANG_TEX + END + POPUP "V" + BEGIN + MENUITEM "VB", IDM_LANG_VB + MENUITEM "VHDL", IDM_LANG_VHDL + MENUITEM "Verilog", IDM_LANG_VERILOG + END + MENUITEM "XML", IDM_LANG_XML + MENUITEM "YAML", IDM_LANG_YAML + MENUITEM SEPARATOR + MENUITEM "User Defined", IDM_LANG_USER + END + + POPUP "Se&ttings" + BEGIN + MENUITEM "Preferences...", IDM_SETTING_PREFERECE + MENUITEM "Styler Configurator...", IDM_LANGSTYLE_CONFIG_DLG + MENUITEM "Shortcut Mapper...", IDM_SETTING_SHORTCUT_MAPPER + END + + POPUP "Macro" + BEGIN + MENUITEM "Start Re&cording", IDM_MACRO_STARTRECORDINGMACRO + MENUITEM "S&top Recording", IDM_MACRO_STOPRECORDINGMACRO + MENUITEM "&Playback", IDM_MACRO_PLAYBACKRECORDEDMACRO + MENUITEM "&Save current recorded macro...", IDM_MACRO_SAVECURRENTMACRO + MENUITEM "&Run a macro multiple times...", IDM_MACRO_RUNMULTIMACRODLG + END + + POPUP "Run" + BEGIN + MENUITEM "&Run...", IDM_EXECUTE + END + + POPUP "&?" + BEGIN + MENUITEM "Help content", IDM_HELP + MENUITEM SEPARATOR + MENUITEM "Notepad++ Home", IDM_HOMESWEETHOME + MENUITEM "Notepad++ Project Page", IDM_PROJECTPAGE + MENUITEM "Online help", IDM_ONLINEHELP + MENUITEM "Wiki FAQ", IDM_WIKIFAQ + MENUITEM "Forum", IDM_FORUM + MENUITEM "Get more plugins", IDM_PLUGINSHOME + MENUITEM SEPARATOR + MENUITEM "Update Notepad++", IDM_UPDATE_NPP + MENUITEM "About Notepad++", IDM_ABOUT + END + + MENUITEM "X", IDM_FILE_CLOSE, HELP +END + +IDD_ABOUTBOX DIALOGEX 0, 0, 271, 240 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_BORDER | WS_SYSMENU +FONT 8, TEXT("MS Shell Dlg"), 0, 0, 0x1 +BEGIN + LTEXT NOTEPAD_PLUS_VERSION, IDC_STATIC,50,16,65,11 + LTEXT UNICODE_ANSI_MODE, IDC_STATIC,120,16,65,11 + GROUPBOX "GNU General Public Licence",IDC_STATIC,19,75,231,131,BS_CENTER + DEFPUSHBUTTON "Ok",IDOK,106,215,50,14,BS_FLAT,WS_EX_STATICEDGE + LTEXT "Author :",IDC_STATIC,21,41,31,8 + LTEXT "Don HO",IDC_AUTHOR_NAME,78,41,25,8 + LTEXT "Home Page :",IDC_STATIC,21,54,47,8 + LTEXT "http://notepad-plus.sourceforge.net/",IDC_HOME_ADDR,78,54,126,8 + EDITTEXT IDC_LICENCE_EDIT,31,99,209,96,ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY | NOT WS_BORDER | WS_VSCROLL + EDITTEXT IDC_BUILD_DATETIME,150,2,150,10, ES_READONLY | NOT WS_BORDER + CONTROL "",IDI_M30ICON,"Static",SS_OWNERDRAW,21,10,20,20 +END + +IDD_GOLINE DIALOGEX 26, 41, 261, 88 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU +EXSTYLE WS_EX_TOOLWINDOW | WS_EX_WINDOWEDGE +CAPTION "Go To..." +FONT 8, TEXT("MS Shell Dlg"), 0, 0, 0x0 +BEGIN + CONTROL "&Line",IDC_RADIO_GOTOLINE,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,5,9,80,10 + CONTROL "&Offset",IDC_RADIO_GOTOOFFSET,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,98,9,80,10 + LTEXT "You are here :",ID_URHERE_STATIC,5,34,95,8,NOT WS_GROUP + LTEXT "0123456789",ID_CURRLINE,100,34,45,8,NOT WS_GROUP + LTEXT "You want to &go :",ID_UGO_STATIC,5,51,95,8 + EDITTEXT ID_GOLINE_EDIT,98,49,71,12,ES_NUMBER + LTEXT "You can't go further than :",ID_NOMORETHAN_STATIC,5,68,92,8,NOT WS_GROUP + LTEXT "0123456789",ID_LASTLINE,100,68,45,8,NOT WS_GROUP + DEFPUSHBUTTON "Go !",IDOK,181,48,70,14,BS_NOTIFY + PUSHBUTTON "I'm going nowhere",IDCANCEL,181,66,70,14,BS_NOTIFY +END + +IDD_VALUE_DLG DIALOGEX 0, 0, 74, 17 +STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | + WS_SYSMENU +EXSTYLE WS_EX_TOOLWINDOW +FONT 8, TEXT("MS Shell Dlg"), 0, 0, 0x1 +BEGIN + LTEXT "STATIC :",IDC_VALUE_STATIC,6,4,45,8 + EDITTEXT IDC_VALUE_EDIT,49,2,18,14,ES_NUMBER,WS_EX_DLGMODALFRAME +END + +// xp style +1 RT_MANIFEST "notepad++.exe.manifest" diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp new file mode 100644 index 00000000..8ed58df1 --- /dev/null +++ b/PowerEditor/src/Parameters.cpp @@ -0,0 +1,4722 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#include "Parameters.h" +#include "FileDialog.h" +#include "ScintillaEditView.h" +#include + +#include "keys.h" + +struct WinMenuKeyDefinition { //more or less matches accelerator table definition, easy copy/paste + //const TCHAR * name; //name retrieved from menu? + int vKey; + int functionId; + bool isCtrl; + bool isAlt; + bool isShift; + TCHAR * specialName; //Used when no real menu name exists (in case of toggle for example) +}; + + +struct ScintillaKeyDefinition { + const TCHAR * name; + int functionId; + bool isCtrl; + bool isAlt; + bool isShift; + int vKey; + int redirFunctionId; //this gets set when a function is being redirected through Notepad++ if Scintilla doesnt do it properly :) +}; + +WinMenuKeyDefinition winKeyDefs[] = { //array of accelerator keys for all std menu items, values can be 0 for vKey, which means its unused + {VK_N, IDM_FILE_NEW, true, false, false, NULL}, + {VK_O, IDM_FILE_OPEN, true, false, false, NULL}, + {VK_NULL, IDM_FILE_RELOAD, false, false, false, NULL}, + {VK_S, IDM_FILE_SAVE, true, false, false, NULL}, + {VK_S, IDM_FILE_SAVEAS, true, true, false, NULL}, + {VK_NULL, IDM_FILE_SAVECOPYAS, false, false, false, NULL}, + {VK_S, IDM_FILE_SAVEALL, true, false, true, NULL}, + {VK_W, IDM_FILE_CLOSE, true, false, false, NULL}, + {VK_NULL, IDM_FILE_CLOSEALL, false, false, false, NULL}, + {VK_NULL, IDM_FILE_CLOSEALL_BUT_CURRENT, false, false, false, NULL}, + {VK_NULL, IDM_FILE_DELETE, false, false, false, NULL}, + {VK_NULL, IDM_FILE_RENAME, false, false, false, NULL}, + {VK_NULL, IDM_FILE_LOADSESSION, false, false, false, NULL}, + {VK_NULL, IDM_FILE_SAVESESSION, false, false, false, NULL}, + {VK_P, IDM_FILE_PRINT, true, false, false, NULL}, + {VK_NULL, IDM_FILE_PRINTNOW, false, false, false, NULL}, + {VK_F4, IDM_FILE_EXIT, false, true, false, NULL}, + +// {VK_NULL, IDM_EDIT_UNDO, false, false, false, NULL}, +// {VK_NULL, IDM_EDIT_REDO, false, false, false, NULL}, +// {VK_NULL, IDM_EDIT_CUT, false, false, false, NULL}, +// {VK_NULL, IDM_EDIT_COPY, false, false, false, NULL}, +// {VK_NULL, IDM_EDIT_PASTE, false, false, false, NULL}, +// {VK_NULL, IDM_EDIT_DELETE, false, false, false, NULL}, +// {VK_NULL, IDM_EDIT_SELECTALL, false, false, false, NULL}, + + {VK_NULL, IDM_EDIT_SETREADONLY, false, false, false, NULL}, + {VK_NULL, IDM_EDIT_CLEARREADONLY, false, false, false, NULL}, + {VK_NULL, IDM_EDIT_FULLPATHTOCLIP, false, false, false, NULL}, + {VK_NULL, IDM_EDIT_FILENAMETOCLIP, false, false, false, NULL}, + {VK_NULL, IDM_EDIT_CURRENTDIRTOCLIP, false, false, false, NULL}, +// {VK_NULL, IDM_EDIT_INS_TAB, false, false, false, NULL}, +// {VK_NULL, IDM_EDIT_RMV_TAB, false, false, false, NULL}, +// {VK_NULL, IDM_EDIT_DUP_LINE, false, false, false, NULL}, + {VK_I, IDM_EDIT_SPLIT_LINES, true, false, false, NULL}, + {VK_J, IDM_EDIT_JOIN_LINES, true, false, false, NULL}, + {VK_UP, IDM_EDIT_LINE_UP, true, false, true, NULL}, + {VK_DOWN, IDM_EDIT_LINE_DOWN, true, false, true, NULL}, + {VK_NULL, IDM_EDIT_TRIMTRAILING, false, false, false, NULL}, + {VK_C, IDM_EDIT_COLUMNMODE, false, true, false, NULL}, + {VK_U, IDM_EDIT_UPPERCASE, true, false, true, NULL}, + {VK_U, IDM_EDIT_LOWERCASE, true, false, false, NULL}, + {VK_Q, IDM_EDIT_BLOCK_COMMENT, true, false, false, NULL}, + {VK_K, IDM_EDIT_BLOCK_COMMENT_SET, true, false, false, NULL}, + {VK_K, IDM_EDIT_BLOCK_UNCOMMENT, true, false, true, NULL}, + {VK_Q, IDM_EDIT_STREAM_COMMENT, true, false, true, NULL}, + {VK_SPACE, IDM_EDIT_AUTOCOMPLETE, true, false, false, NULL}, + {VK_RETURN, IDM_EDIT_AUTOCOMPLETE_CURRENTFILE, true, false, false, NULL}, + {VK_SPACE, IDM_EDIT_FUNCCALLTIP, true, false, true, NULL}, + {VK_R, IDM_EDIT_RTL, true, true, false, NULL}, + {VK_L, IDM_EDIT_LTR, true, true, false, NULL}, + + {VK_F, IDM_SEARCH_FIND, true, false, false, NULL}, + {VK_F, IDM_SEARCH_FINDINFILES, true, false, true, NULL}, + {VK_F3, IDM_SEARCH_FINDNEXT, false, false, false, NULL}, + {VK_F3, IDM_SEARCH_FINDPREV, false, false, true, NULL}, + {VK_F3, IDM_SEARCH_VOLATILE_FINDNEXT, true, false, false, NULL}, + {VK_F3, IDM_SEARCH_VOLATILE_FINDPREV, true, false, true, NULL}, + {VK_F4, NPPM_INTERNAL_SEARCH_GOTONEXTFOUND, false, false, false, TEXT("Goto next found result")}, + {VK_F4, NPPM_INTERNAL_SEARCH_GOTOPREVFOUND, false, false, true, TEXT("Goto previous found result")}, + {VK_H, IDM_SEARCH_REPLACE, true, false, false, NULL}, + {VK_I, IDM_SEARCH_FINDINCREMENT, true, true, false, NULL}, + {VK_G, IDM_SEARCH_GOTOLINE, true, false, false, NULL}, + {VK_B, IDM_SEARCH_GOTOMATCHINGBRACE, true, false, false, NULL}, + {VK_F2, IDM_SEARCH_TOGGLE_BOOKMARK, true, false, false, NULL}, + {VK_F2, IDM_SEARCH_NEXT_BOOKMARK, false, false, false, NULL}, + {VK_F2, IDM_SEARCH_PREV_BOOKMARK, false, false, true, NULL}, + {VK_NULL, IDM_SEARCH_CLEAR_BOOKMARKS, false, false, false, NULL}, + {VK_NULL, IDM_SEARCH_CUTMARKEDLINES, false, false, false, NULL}, + {VK_NULL, IDM_SEARCH_COPYMARKEDLINES, false, false, false, NULL}, + {VK_NULL, IDM_SEARCH_PASTEMARKEDLINES, false, false, false, NULL}, + {VK_NULL, IDM_SEARCH_DELETEMARKEDLINES, false, false, false, NULL}, + {VK_F7, NPPM_INTERNAL_FOCUS_ON_FOUND_RESULTS,false, false, false, TEXT("Switch to found results window")}, + + {VK_F11, IDM_VIEW_FULLSCREENTOGGLE, false, false, false, NULL}, + {VK_NULL, IDM_VIEW_ALWAYSONTOP, false, false, false, NULL}, + {VK_F12, IDM_VIEW_POSTIT, false, false, false, NULL}, + {VK_NULL, IDM_VIEW_TAB_SPACE, false, false, false, NULL}, + {VK_NULL, IDM_VIEW_EOL, false, false, false, NULL}, + {VK_NULL, IDM_VIEW_ALL_CHARACTERS, false, false, false, NULL}, + {VK_NULL, IDM_VIEW_INDENT_GUIDE, false, false, false, NULL}, + {VK_NULL, IDM_VIEW_WRAP, false, false, false, NULL}, + {VK_NULL, IDM_VIEW_WRAP_SYMBOL, false, false, false, NULL}, + {VK_NULL, IDM_VIEW_USER_DLG, false, false, false, NULL}, + //{VK_NULL, IDM_VIEW_ZOOMIN, false, false, false, NULL}, + //{VK_NULL, IDM_VIEW_ZOOMOUT, false, false, false, NULL}, + //{VK_NULL, IDM_VIEW_ZOOMRESTORE, false, false, false, NULL}, + {VK_0, IDM_VIEW_TOGGLE_FOLDALL, false, true, false, NULL}, + {VK_F, IDM_VIEW_FOLD_CURRENT, true, true, false, NULL}, + {VK_1, IDM_VIEW_FOLD_1, false, true, false, NULL}, + {VK_2, IDM_VIEW_FOLD_2, false, true, false, NULL}, + {VK_3, IDM_VIEW_FOLD_3, false, true, false, NULL}, + {VK_4, IDM_VIEW_FOLD_4, false, true, false, NULL}, + {VK_5, IDM_VIEW_FOLD_5, false, true, false, NULL}, + {VK_6, IDM_VIEW_FOLD_6, false, true, false, NULL}, + {VK_7, IDM_VIEW_FOLD_7, false, true, false, NULL}, + {VK_8, IDM_VIEW_FOLD_8, false, true, false, NULL}, + {VK_F, IDM_VIEW_UNFOLD_CURRENT, true, true, true, NULL}, + {VK_1, IDM_VIEW_UNFOLD_1, false, true, true, NULL}, + {VK_2, IDM_VIEW_UNFOLD_2, false, true, true, NULL}, + {VK_3, IDM_VIEW_UNFOLD_3, false, true, true, NULL}, + {VK_4, IDM_VIEW_UNFOLD_4, false, true, true, NULL}, + {VK_5, IDM_VIEW_UNFOLD_5, false, true, true, NULL}, + {VK_6, IDM_VIEW_UNFOLD_6, false, true, true, NULL}, + {VK_7, IDM_VIEW_UNFOLD_7, false, true, true, NULL}, + {VK_8, IDM_VIEW_UNFOLD_8, false, true, true, NULL}, + {VK_0, IDM_VIEW_TOGGLE_UNFOLDALL, false, true, true, NULL}, + {VK_H, IDM_VIEW_HIDELINES, false, true, false, NULL}, + {VK_NULL, IDM_VIEW_GOTO_ANOTHER_VIEW, false, false, false, NULL}, + {VK_NULL, IDM_VIEW_CLONE_TO_ANOTHER_VIEW, false, false, false, NULL}, + {VK_NULL, IDM_VIEW_SYNSCROLLV, false, false, false, NULL}, + {VK_NULL, IDM_VIEW_SYNSCROLLH, false, false, false, NULL}, + {VK_F8, IDM_VIEW_SWITCHTO_OTHER_VIEW, false, false, false, NULL}, + + {VK_NULL, IDM_FORMAT_TODOS, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_TOUNIX, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_TOMAC, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_ANSI, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_UTF_8, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_AS_UTF_8, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_UCS_2BE, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_UCS_2LE, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_CONV2_ANSI, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_CONV2_AS_UTF_8, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_CONV2_UTF_8, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_CONV2_UCS_2BE, false, false, false, NULL}, + {VK_NULL, IDM_FORMAT_CONV2_UCS_2LE, false, false, false, NULL}, + + {VK_NULL, IDM_SETTING_PREFERECE, false, false, false, NULL}, + {VK_NULL, IDM_LANGSTYLE_CONFIG_DLG, false, false, false, NULL}, + {VK_NULL, IDM_SETTING_SHORTCUT_MAPPER, false, false, false, NULL}, + + {VK_R, IDC_EDIT_TOGGLEMACRORECORDING, true, false, true, TEXT("Toggle macro record")}, + {VK_P, IDM_MACRO_PLAYBACKRECORDEDMACRO, true, false, true, NULL}, + {VK_NULL, IDM_MACRO_SAVECURRENTMACRO, false, false, false, NULL}, + {VK_NULL, IDM_MACRO_RUNMULTIMACRODLG, false, false, false, NULL}, + + {VK_F5, IDM_EXECUTE, false, false, false, NULL}, + + {VK_NULL, IDM_HOMESWEETHOME, false, false, false, NULL}, + {VK_NULL, IDM_PROJECTPAGE, false, false, false, NULL}, + {VK_NULL, IDM_ONLINEHELP, false, false, false, NULL}, + {VK_NULL, IDM_FORUM, false, false, false, NULL}, + {VK_NULL, IDM_PLUGINSHOME, false, false, false, NULL}, + {VK_F1, IDM_ABOUT, false, false, false, NULL}, + {VK_F1, IDM_HELP, false, false, true, NULL}, + + {VK_TAB, IDC_PREV_DOC, true, false, true, TEXT("Switch to previous document")}, + {VK_TAB, IDC_NEXT_DOC, true, false, false, TEXT("Switch to next document")}, +}; + + +ScintillaKeyDefinition scintKeyDefs[] = { //array of accelerator keys for all possible scintilla functions, values can be 0 for vKey, which means its unused + {TEXT("SCI_CUT"), SCI_CUT, true, false, false, VK_X, IDM_EDIT_CUT}, + {TEXT(""), SCI_CUT, false, false, true, VK_DELETE, 0}, + {TEXT("SCI_COPY"), SCI_COPY, true, false, false, VK_C, IDM_EDIT_COPY}, + {TEXT(""), SCI_COPY, true, false, false, VK_INSERT, 0}, + {TEXT("SCI_PASTE"), SCI_PASTE, true, false, false, VK_V, IDM_EDIT_PASTE}, + {TEXT(""), SCI_PASTE, false, false, true, VK_INSERT, 0}, + {TEXT("SCI_SELECTALL"), SCI_SELECTALL, true, false, false, VK_A, IDM_EDIT_SELECTALL}, + {TEXT("SCI_CLEAR"), SCI_CLEAR, false, false, false, VK_DELETE, IDM_EDIT_DELETE}, + {TEXT("SCI_CLEARALL"), SCI_CLEARALL, false, false, false, 0, 0}, + {TEXT("SCI_UNDO"), SCI_UNDO, true, false, false, VK_Z, IDM_EDIT_UNDO}, + {TEXT(""), SCI_UNDO, false, true, false, VK_BACK, 0}, + {TEXT("SCI_REDO"), SCI_REDO, true, false, false, VK_Y, IDM_EDIT_REDO}, + {TEXT("SCI_NEWLINE"), SCI_NEWLINE, false, false, false, VK_RETURN, 0}, + {TEXT(""), SCI_NEWLINE, false, false, true, VK_RETURN, 0}, + {TEXT("SCI_TAB"), SCI_TAB, false, false, false, VK_TAB, IDM_EDIT_INS_TAB}, + {TEXT("SCI_BACKTAB"), SCI_BACKTAB, false, false, true, VK_TAB, IDM_EDIT_RMV_TAB}, + {TEXT("SCI_FORMFEED"), SCI_FORMFEED, false, false, false, 0, 0}, + {TEXT("SCI_ZOOMIN"), SCI_ZOOMIN, true, false, false, VK_ADD, IDM_VIEW_ZOOMIN}, + {TEXT("SCI_ZOOMOUT"), SCI_ZOOMOUT, true, false, false, VK_SUBTRACT,IDM_VIEW_ZOOMOUT}, + {TEXT("SCI_SETZOOM"), SCI_SETZOOM, true, false, false, VK_DIVIDE, IDM_VIEW_ZOOMRESTORE}, + {TEXT("SCI_SELECTIONDUPLICATE"), SCI_SELECTIONDUPLICATE, true, false, false, VK_D, IDM_EDIT_DUP_LINE}, + {TEXT("SCI_LINESJOIN"), SCI_LINESJOIN, false, false, false, 0, 0}, + {TEXT("SCI_SCROLLCARET"), SCI_SCROLLCARET, false, false, false, 0, 0}, + {TEXT("SCI_EDITTOGGLEOVERTYPE"), SCI_EDITTOGGLEOVERTYPE, false, false, false, VK_INSERT, 0}, + {TEXT("SCI_MOVECARETINSIDEVIEW"), SCI_MOVECARETINSIDEVIEW, false, false, false, 0, 0}, + {TEXT("SCI_LINEDOWN"), SCI_LINEDOWN, false, false, false, VK_DOWN, 0}, + {TEXT("SCI_LINEDOWNEXTEND"), SCI_LINEDOWNEXTEND, false, false, true, VK_DOWN, 0}, + {TEXT("SCI_LINEDOWNRECTEXTEND"), SCI_LINEDOWNRECTEXTEND, false, true, true, VK_DOWN, 0}, + {TEXT("SCI_LINESCROLLDOWN"), SCI_LINESCROLLDOWN, true, false, false, VK_DOWN, 0}, + {TEXT("SCI_LINEUP"), SCI_LINEUP, false, false, false, VK_UP, 0}, + {TEXT("SCI_LINEUPEXTEND"), SCI_LINEUPEXTEND, false, false, true, VK_UP, 0}, + {TEXT("SCI_LINEUPRECTEXTEND"), SCI_LINEUPRECTEXTEND, false, true, true, VK_UP, 0}, + {TEXT("SCI_LINESCROLLUP"), SCI_LINESCROLLUP, true, false, false, VK_UP, 0}, + {TEXT("SCI_PARADOWN"), SCI_PARADOWN, true, false, false, VK_OEM_6, 0}, + {TEXT("SCI_PARADOWNEXTEND"), SCI_PARADOWNEXTEND, true, false, true, VK_OEM_6, 0}, + {TEXT("SCI_PARAUP"), SCI_PARAUP, true, false, false, VK_OEM_4, 0}, + {TEXT("SCI_PARAUPEXTEND"), SCI_PARAUPEXTEND, true, false, true, VK_OEM_4, 0}, + {TEXT("SCI_CHARLEFT"), SCI_CHARLEFT, false, false, false, VK_LEFT, 0}, + {TEXT("SCI_CHARLEFTEXTEND"), SCI_CHARLEFTEXTEND, false, false, true, VK_LEFT, 0}, + {TEXT("SCI_CHARLEFTRECTEXTEND"), SCI_CHARLEFTRECTEXTEND, false, true, true, VK_LEFT, 0}, + {TEXT("SCI_CHARRIGHT"), SCI_CHARRIGHT, false, false, false, VK_RIGHT, 0}, + {TEXT("SCI_CHARRIGHTEXTEND"), SCI_CHARRIGHTEXTEND, false, false, true, VK_RIGHT, 0}, + {TEXT("SCI_CHARRIGHTRECTEXTEND"), SCI_CHARRIGHTRECTEXTEND, false, true, true, VK_RIGHT, 0}, + {TEXT("SCI_WORDLEFT"), SCI_WORDLEFT, true, false, false, VK_LEFT, 0}, + {TEXT("SCI_WORDLEFTEXTEND"), SCI_WORDLEFTEXTEND, true, false, true, VK_LEFT, 0}, + {TEXT("SCI_WORDRIGHT"), SCI_WORDRIGHT, true, false, false, VK_RIGHT, 0}, + {TEXT("SCI_WORDRIGHTEXTEND"), SCI_WORDRIGHTEXTEND, false, false, false, 0, 0}, + {TEXT("SCI_WORDLEFTEND"), SCI_WORDLEFTEND, false, false, false, 0, 0}, + {TEXT("SCI_WORDLEFTENDEXTEND"), SCI_WORDLEFTENDEXTEND, false, false, false, 0, 0}, + {TEXT("SCI_WORDRIGHTEND"), SCI_WORDRIGHTEND, false, false, false, 0, 0}, + {TEXT("SCI_WORDRIGHTENDEXTEND"), SCI_WORDRIGHTENDEXTEND, true, false, true, VK_RIGHT, 0}, + {TEXT("SCI_WORDPARTLEFT"), SCI_WORDPARTLEFT, true, false, false, VK_OEM_2, 0}, + {TEXT("SCI_WORDPARTLEFTEXTEND"), SCI_WORDPARTLEFTEXTEND, true, false, true, VK_OEM_2, 0}, + {TEXT("SCI_WORDPARTRIGHT"), SCI_WORDPARTRIGHT, true, false, false, VK_OEM_5, 0}, + {TEXT("SCI_WORDPARTRIGHTEXTEND"), SCI_WORDPARTRIGHTEXTEND, true, false, true, VK_OEM_5, 0}, + {TEXT("SCI_HOME"), SCI_HOME, false, false, false, 0, 0}, + {TEXT("SCI_HOMEEXTEND"), SCI_HOMEEXTEND, false, false, false, 0, 0}, + {TEXT("SCI_HOMERECTEXTEND"), SCI_HOMERECTEXTEND, false, false, false, 0, 0}, + {TEXT("SCI_HOMEDISPLAY"), SCI_HOMEDISPLAY, false, true, false, VK_HOME, 0}, + {TEXT("SCI_HOMEDISPLAYEXTEND"), SCI_HOMEDISPLAYEXTEND, false, false, false, 0, 0}, + {TEXT("SCI_HOMEWRAP"), SCI_HOMEWRAP, false, false, false, 0, 0}, + {TEXT("SCI_HOMEWRAPEXTEND"), SCI_HOMEWRAPEXTEND, false, false, false, 0, 0}, + {TEXT("SCI_VCHOME"), SCI_VCHOME, false, false, false, 0, 0}, + {TEXT("SCI_VCHOMEEXTEND"), SCI_VCHOMEEXTEND, false, false, true, VK_HOME, 0}, + {TEXT("SCI_VCHOMERECTEXTEND"), SCI_VCHOMERECTEXTEND, false, true, true, VK_HOME, 0}, + {TEXT("SCI_VCHOMEWRAP"), SCI_VCHOMEWRAP, false, false, false, VK_HOME, 0}, + {TEXT("SCI_VCHOMEWRAPEXTEND"), SCI_VCHOMEWRAPEXTEND, false, false, false, 0, 0}, + {TEXT("SCI_LINEEND"), SCI_LINEEND, false, false, false, 0, 0}, + {TEXT("SCI_LINEENDEXTEND"), SCI_LINEENDEXTEND, false, false, true, VK_END, 0}, + {TEXT("SCI_LINEENDRECTEXTEND"), SCI_LINEENDRECTEXTEND, false, true, true, VK_END, 0}, + {TEXT("SCI_LINEENDDISPLAY"), SCI_LINEENDDISPLAY, false, true, false, VK_END, 0}, + {TEXT("SCI_LINEENDDISPLAYEXTEND"), SCI_LINEENDDISPLAYEXTEND, false, false, false, 0, 0}, + {TEXT("SCI_LINEENDWRAP"), SCI_LINEENDWRAP, false, false, false, VK_END, 0}, + {TEXT("SCI_LINEENDWRAPEXTEND"), SCI_LINEENDWRAPEXTEND, false, false, false, 0, 0}, + {TEXT("SCI_DOCUMENTSTART"), SCI_DOCUMENTSTART, true, false, false, VK_HOME, 0}, + {TEXT("SCI_DOCUMENTSTARTEXTEND"), SCI_DOCUMENTSTARTEXTEND, true, false, true, VK_HOME, 0}, + {TEXT("SCI_DOCUMENTEND"), SCI_DOCUMENTEND, true, false, false, VK_END, 0}, + {TEXT("SCI_DOCUMENTENDEXTEND"), SCI_DOCUMENTENDEXTEND, true, false, true, VK_END, 0}, + {TEXT("SCI_PAGEUP"), SCI_PAGEUP, false, false, false, VK_PRIOR, 0}, + {TEXT("SCI_PAGEUPEXTEND"), SCI_PAGEUPEXTEND, false, false, true, VK_PRIOR, 0}, + {TEXT("SCI_PAGEUPRECTEXTEND"), SCI_PAGEUPRECTEXTEND, false, true, true, VK_PRIOR, 0}, + {TEXT("SCI_PAGEDOWN"), SCI_PAGEDOWN, false, false, false, VK_NEXT, 0}, + {TEXT("SCI_PAGEDOWNEXTEND"), SCI_PAGEDOWNEXTEND, false, false, true, VK_NEXT, 0}, + {TEXT("SCI_PAGEDOWNRECTEXTEND"), SCI_PAGEDOWNRECTEXTEND, false, true, true, VK_NEXT, 0}, + {TEXT("SCI_STUTTEREDPAGEUP"), SCI_STUTTEREDPAGEUP, false, false, false, 0, 0}, + {TEXT("SCI_STUTTEREDPAGEUPEXTEND"), SCI_STUTTEREDPAGEUPEXTEND, false, false, false, 0, 0}, + {TEXT("SCI_STUTTEREDPAGEDOWN"), SCI_STUTTEREDPAGEDOWN, false, false, false, 0, 0}, + {TEXT("SCI_STUTTEREDPAGEDOWNEXTEND"), SCI_STUTTEREDPAGEDOWNEXTEND,false, false, false, 0, 0}, + {TEXT("SCI_DELETEBACK"), SCI_DELETEBACK, false, false, false, VK_BACK, 0}, + {TEXT(""), SCI_DELETEBACK, false, false, true, VK_BACK, 0}, + {TEXT("SCI_DELETEBACKNOTLINE"), SCI_DELETEBACKNOTLINE, false, false, false, 0, 0}, + {TEXT("SCI_DELWORDLEFT"), SCI_DELWORDLEFT, true, false, false, VK_BACK, 0}, + {TEXT("SCI_DELWORDRIGHT"), SCI_DELWORDRIGHT, true, false, false, VK_DELETE, 0}, + {TEXT("SCI_DELLINELEFT"), SCI_DELLINELEFT, true, false, true, VK_BACK, 0}, + {TEXT("SCI_DELLINERIGHT"), SCI_DELLINERIGHT, true, false, true, VK_DELETE, 0}, + {TEXT("SCI_LINEDELETE"), SCI_LINEDELETE, true, false, true, VK_L, 0}, + {TEXT("SCI_LINECUT"), SCI_LINECUT, true, false, false, VK_L, 0}, + {TEXT("SCI_LINECOPY"), SCI_LINECOPY, true, false, true, VK_T, 0}, + {TEXT("SCI_LINETRANSPOSE"), SCI_LINETRANSPOSE, true, false, false, VK_T, 0}, + {TEXT("SCI_LINEDUPLICATE"), SCI_LINEDUPLICATE, false, false, false, 0, 0}, + {TEXT("SCI_CANCEL"), SCI_CANCEL, false, false, false, VK_ESCAPE, 0} + //{TEXT("SCI_EMPTYUNDOBUFFER"), SCI_EMPTYUNDOBUFFER, false, false, false, 0, 0}, + //{TEXT("SCI_TOGGLECARETSTICKY"), SCI_TOGGLECARETSTICKY, false, false, false, 0, 0}, + //{TEXT("SCI_CALLTIPCANCEL"), SCI_CALLTIPCANCEL, false, false, false, 0, 0}, + //{TEXT("SCI_SETSAVEPOINT"), SCI_SETSAVEPOINT, false, false, false, 0, 0}, + //{TEXT("SCI_CLEARDOCUMENTSTYLE"), SCI_CLEARDOCUMENTSTYLE, false, false, false, 0, 0}, + // + // + //{TEXT("SCI_CHOOSECARETX"), SCI_CHOOSECARETX, false, false, false, 0, 0}, + //{TEXT("SCI_AUTOCCOMPLETE"), SCI_AUTOCCOMPLETE, false, false, false, 0, 0}, + //{TEXT("SCI_AUTOCCANCEL"), SCI_AUTOCCANCEL, false, false, false, 0, 0}, + //{TEXT("SCI_CLEARREGISTEREDIMAGES"), SCI_CLEARREGISTEREDIMAGES, false, false, false, 0, 0}, + //{TEXT("SCI_HOMEDISPLAYEXTEND"), SCI_HOMEDISPLAYEXTEND, false, true, true, VK_HOME, 0}, + //{TEXT("SCI_LINEENDDISPLAYEXTEND"), SCI_LINEENDDISPLAYEXTEND, false, true, true, VK_END, 0}, + // + //{TEXT("SCI_DELWORDRIGHTEND"), SCI_DELWORDRIGHTEND, false, false, false, 0, 0}, + //{TEXT("SCI_LOWERCASE"), SCI_LOWERCASE, false, false, false, 0, 0}, + //{TEXT("SCI_UPPERCASE"), SCI_UPPERCASE, false, false, false, 0, 0}, + //{TEXT("SCI_LOWERCASE"), SCI_LOWERCASE, true, false, false, VK_U, 0}, + //{TEXT("SCI_UPPERCASE"), SCI_UPPERCASE, true, false, true, VK_U, 0}, + // + //{TEXT("SCI_FORMFEED"), SCI_FORMFEED, true, false, false, VK_L, 0}, + //{TEXT("SCI_CLEARALLCMDKEYS"), SCI_CLEARALLCMDKEYS, false, false, false, 0, 0}, + //{TEXT("SCI_STARTRECORD"), SCI_STARTRECORD, false, false, false, 0, 0}, + //{TEXT("SCI_STOPRECORD"), SCI_STOPRECORD, false, false, false, 0, 0}, + //{TEXT("SCI_SEARCHANCHOR"), SCI_SEARCHANCHOR, false, false, false, 0, 0}, + //{TEXT("SCI_TARGETFROMSELECTION"), SCI_TARGETFROMSELECTION, false, false, false, 0, 0}, + //{TEXT("SCI_STYLERESETDEFAULT"), SCI_STYLERESETDEFAULT, false, false, false, 0, 0}, + //{TEXT("SCI_STYLECLEARALL"), SCI_STYLECLEARALL, false, false, false, 0, 0}, + // +}; +#ifdef UNICODE +#include "localizationString.h" + +wstring LocalizationSwitcher::getLangFromXmlFileName(wchar_t *fn) const +{ + size_t nbItem = sizeof(localizationDefs)/sizeof(LocalizationSwitcher::LocalizationDefinition); + for (size_t i = 0 ; i < nbItem ; i++) + { + if (wcsicmp(fn, localizationDefs[i]._xmlFileName) == 0) + return localizationDefs[i]._langName; + } + return TEXT(""); +} + +wstring LocalizationSwitcher::getXmlFilePathFromLangName(wchar_t *langName) const +{ + for (size_t i = 0 ; i < _localizationList.size() ; i++) + { + if (wcsicmp(langName, _localizationList[i].first.c_str()) == 0) + return _localizationList[i].second; + } + return TEXT(""); +} + +bool LocalizationSwitcher::addLanguageFromXml(wstring xmlFullPath) +{ + wchar_t * fn = ::PathFindFileNameW(xmlFullPath.c_str()); + wstring foundLang = getLangFromXmlFileName(fn); + if (foundLang != TEXT("")) + { + _localizationList.push_back(pair(foundLang, xmlFullPath)); + return true; + } + return false; +} + +bool LocalizationSwitcher::switchToLang(wchar_t *lang2switch) const +{ + wstring langPath = getXmlFilePathFromLangName(lang2switch); + if (langPath == TEXT("")) + return false; + + return ::CopyFileW(langPath.c_str(), _nativeLangPath.c_str(), FALSE) != FALSE; +} + +#endif + + +generic_string ThemeSwitcher::getThemeFromXmlFileName(const TCHAR *xmlFullPath) const +{ + if (xmlFullPath == TEXT("")) return xmlFullPath; + TCHAR fn[MAX_PATH]; + lstrcpy(fn, ::PathFindFileName(xmlFullPath)); + PathRemoveExtension(fn); + generic_string themeName = fn; + return themeName; +} + +typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO); + +winVer getWindowsVersion() +{ + OSVERSIONINFOEX osvi; + SYSTEM_INFO si; + PGNSI pGNSI; + BOOL bOsVersionInfoEx; + + ZeroMemory(&si, sizeof(SYSTEM_INFO)); + ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); + + osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); + + if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) ) + { + osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); + if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) ) + return WV_UNKNOWN; + } + + pGNSI = (PGNSI) GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetNativeSystemInfo"); + if(pGNSI != NULL) + pGNSI(&si); + else + GetSystemInfo(&si); + + switch (osvi.dwPlatformId) + { + case VER_PLATFORM_WIN32_NT: + { + if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 0 ) + { + return WV_VISTA; + } + + if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 ) + { + if (osvi.wProductType == VER_NT_WORKSTATION && + si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64) + { + return WV_XPX64; + } + return WV_S2003; + } + + if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 ) + return WV_XP; + + if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 ) + return WV_W2K; + + if ( osvi.dwMajorVersion <= 4 ) + return WV_NT; + } + break; + + // Test for the Windows Me/98/95. + case VER_PLATFORM_WIN32_WINDOWS: + { + if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0) + { + return WV_95; + } + + if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10) + { + return WV_98; + } + + if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90) + { + return WV_ME; + } + } + break; + + case VER_PLATFORM_WIN32s: + return WV_WIN32S; + + default : + return WV_UNKNOWN; + } + return WV_UNKNOWN; +} + +NppParameters * NppParameters::_pSelf = new NppParameters; +int FileDialog::_dialogFileBoxId = (NppParameters::getInstance())->getWinVersion() < WV_W2K?edt1:cmb13; + +NppParameters::NppParameters() : _pXmlDoc(NULL),_pXmlUserDoc(NULL), _pXmlUserStylerDoc(NULL),\ + _pXmlUserLangDoc(NULL), /*_pXmlNativeLangDoc(NULL), */_pXmlNativeLangDocA(NULL),\ + _nbLang(0), _nbFile(0), _nbMaxFile(10), _pXmlToolIconsDoc(NULL),\ + _pXmlShortcutDoc(NULL), _pXmlContextMenuDoc(NULL), _pXmlSessionDoc(NULL),\ + _nbUserLang(0), _nbExternalLang(0), _hUser32(NULL), _hUXTheme(NULL),\ + _transparentFuncAddr(NULL), _enableThemeDialogTextureFuncAddr(NULL),\ + _isTaskListRBUTTONUP_Active(false), _fileSaveDlgFilterIndex(-1), _asNotepadStyle(false), _isFindReplacing(false) +{ + _findHistory._nbFindHistoryPath = 0; + _findHistory._nbFindHistoryFilter = 0; + _findHistory._nbFindHistoryFind = 0; + _findHistory._nbFindHistoryReplace = 0; + + //Get windows version + _winVersion = getWindowsVersion(); + + // Prepare for default path + TCHAR nppPath[MAX_PATH]; + ::GetModuleFileName(NULL, nppPath, MAX_PATH); + + PathRemoveFileSpec(nppPath); + lstrcpy(_nppPath, nppPath); + + //Initialize current directory to startup directory + ::GetCurrentDirectory(MAX_PATH, _currentDirectory); + + _appdataNppDir[0] = '\0'; + TCHAR notepadStylePath[MAX_PATH]; + lstrcpy(notepadStylePath, _nppPath); + PathAppend(notepadStylePath, notepadStyleFile); + + _asNotepadStyle = (PathFileExists(notepadStylePath) == TRUE); + ::AddFontResource(LINEDRAW_FONT); + + //Load initial accelerator key definitions + initMenuKeys(); + initScintillaKeys(); +} + +NppParameters::~NppParameters() +{ + for (int i = 0 ; i < _nbLang ; i++) + delete _langList[i]; + for (int i = 0 ; i < _nbFile ; i++) + delete _LRFileList[i]; + for (int i = 0 ; i < _nbUserLang ; i++) + delete _userLangArray[i]; + if (_hUser32) + FreeLibrary(_hUser32); + if (_hUXTheme) + FreeLibrary(_hUXTheme); + + ::RemoveFontResource(LINEDRAW_FONT); +} +void cutString(const TCHAR *str2cut, vector & patternVect) +{ + TCHAR str2scan[MAX_PATH]; + lstrcpy(str2scan, str2cut); + size_t len = lstrlen(str2scan); + bool isProcessing = false; + TCHAR *pBegin = NULL; + for (size_t i = 0 ; i <= len ; i++) + { + switch(str2scan[i]) + { + case ' ': + case '\0': + { + if (isProcessing) + { + str2scan[i] = '\0'; + patternVect.push_back(pBegin); + isProcessing = false; + } + break; + } + + default : + if (!isProcessing) + { + isProcessing = true; + pBegin = str2scan+i; + } + } + } +} + +bool NppParameters::reloadStylers(TCHAR *stylePath) +{ + if (_pXmlUserStylerDoc) + delete _pXmlUserStylerDoc; + + _pXmlUserStylerDoc = new TiXmlDocument(stylePath?stylePath:_stylerPath); + bool loadOkay = _pXmlUserStylerDoc->LoadFile(); + if (!loadOkay) + { + ::MessageBox(NULL, TEXT("Load stylers.xml failed!"), TEXT("Configurator"),MB_OK); + delete _pXmlUserStylerDoc; + _pXmlUserStylerDoc = NULL; + return false; + } + _lexerStylerArray.eraseAll(); + _widgetStyleArray.setNbStyler( 0 ); + + return getUserStylersFromXmlTree(); +} + +bool NppParameters::reloadLang() +{ + TCHAR nativeLangPath[MAX_PATH]; + lstrcpy(nativeLangPath, _userPath); + PathAppend(nativeLangPath, TEXT("nativeLang.xml")); + + if (!PathFileExists(nativeLangPath)) + { + return false; + } + + if (_pXmlNativeLangDocA) + delete _pXmlNativeLangDocA; + + _pXmlNativeLangDocA = new TiXmlDocumentA(); + + bool loadOkay = _pXmlNativeLangDocA->LoadUnicodeFilePath(nativeLangPath); + if (!loadOkay) + { + delete _pXmlNativeLangDocA; + _pXmlNativeLangDocA = NULL; + return false; + } + return loadOkay; +} + +bool NppParameters::load() +{ + L_END = L_EXTERNAL; + bool isAllLaoded = true; + for (int i = 0 ; i < NB_LANG ; _langList[i] = NULL, i++); + + // Make localConf.xml path + TCHAR localConfPath[MAX_PATH]; + lstrcpy(localConfPath, _nppPath); + PathAppend(localConfPath, localConfFile); + + // Test if localConf.xml exist + bool isLocal = (PathFileExists(localConfPath) == TRUE); + + if (isLocal) + { + lstrcpy(_userPath, _nppPath); + } + else + { + ITEMIDLIST *pidl; + SHGetSpecialFolderLocation(NULL, CSIDL_APPDATA, &pidl); + SHGetPathFromIDList(pidl, _userPath); + + PathAppend(_userPath, TEXT("Notepad++")); + + lstrcpy(_appdataNppDir, _userPath); + + if (!PathFileExists(_userPath)) + { + ::CreateDirectory(_userPath, NULL); + } + } + + //-------------------------------------// + // Transparent function for w2k and xp // + //-------------------------------------// + _hUser32 = ::GetModuleHandle(TEXT("User32")); + if (_hUser32) + _transparentFuncAddr = (WNDPROC)::GetProcAddress(_hUser32, "SetLayeredWindowAttributes"); + + //---------------------------------------------// + // Dlg theme texture function for xp and vista // + //---------------------------------------------// + _hUXTheme = ::LoadLibrary(TEXT("uxtheme.dll")); + if (_hUXTheme) + _enableThemeDialogTextureFuncAddr = (WNDPROC)::GetProcAddress(_hUXTheme, "EnableThemeDialogTexture"); + + //---------------------------------------// + // langs.xml : for every user statically // + //---------------------------------------// + TCHAR langs_xml_path[MAX_PATH]; + lstrcpy(langs_xml_path, _nppPath); + + PathAppend(langs_xml_path, TEXT("langs.xml")); + if (!PathFileExists(langs_xml_path)) + { + TCHAR srcLangsPath[MAX_PATH]; + lstrcpy(srcLangsPath, _nppPath); + PathAppend(srcLangsPath, TEXT("langs.model.xml")); + + ::CopyFile(srcLangsPath, langs_xml_path, TRUE); + } + + _pXmlDoc = new TiXmlDocument(langs_xml_path); + bool loadOkay = _pXmlDoc->LoadFile(); + if (!loadOkay) + { + ::MessageBox(NULL, TEXT("Load langs.xml failed!"), TEXT("Configurator"),MB_OK); + delete _pXmlDoc; + _pXmlDoc = NULL; + isAllLaoded = false; + } + else + getLangKeywordsFromXmlTree(); + + //---------------------------// + // config.xml : for per user // + //---------------------------// + TCHAR configPath[MAX_PATH]; + lstrcpy(configPath, _userPath); + PathAppend(configPath, TEXT("config.xml")); + + TCHAR srcConfigPath[MAX_PATH]; + lstrcpy(srcConfigPath, _nppPath); + PathAppend(srcConfigPath, TEXT("config.model.xml")); + + if (!::PathFileExists(configPath)) + ::CopyFile(srcConfigPath, configPath, FALSE); + + _pXmlUserDoc = new TiXmlDocument(configPath); + loadOkay = _pXmlUserDoc->LoadFile(); + if (!loadOkay) + { + int res = ::MessageBox(NULL, TEXT("Load config.xml failed!\rDo you want to recover your config.xml?"), TEXT("Configurator"),MB_YESNO); + if (res ==IDYES) + { + ::CopyFile(srcConfigPath, configPath, FALSE); + + loadOkay = _pXmlUserDoc->LoadFile(); + if (!loadOkay) + { + ::MessageBox(NULL, TEXT("Recover config.xml failed!"), TEXT("Configurator"),MB_OK); + delete _pXmlUserDoc; + _pXmlUserDoc = NULL; + isAllLaoded = false; + } + else + getUserParametersFromXmlTree(); + } + else + { + delete _pXmlUserDoc; + _pXmlUserDoc = NULL; + isAllLaoded = false; + } + } + else + getUserParametersFromXmlTree(); + + //----------------------------// + // stylers.xml : for per user // + //----------------------------// + + lstrcpy(_stylerPath, _userPath); + PathAppend(_stylerPath, TEXT("stylers.xml")); + + if (!PathFileExists(_stylerPath)) + { + TCHAR srcStylersPath[MAX_PATH]; + lstrcpy(srcStylersPath, _nppPath); + PathAppend(srcStylersPath, TEXT("stylers.model.xml")); + + ::CopyFile(srcStylersPath, _stylerPath, TRUE); + } + + if ( _nppGUI._themeName.empty() || (!PathFileExists(_nppGUI._themeName.c_str())) ) + { + _nppGUI._themeName.assign(_stylerPath); + } + + _pXmlUserStylerDoc = new TiXmlDocument(_nppGUI._themeName.c_str()); + + loadOkay = _pXmlUserStylerDoc->LoadFile(); + if (!loadOkay) + { + ::MessageBox(NULL, TEXT("Load stylers.xml failed!"), TEXT("Configurator"),MB_OK); + delete _pXmlUserStylerDoc; + _pXmlUserStylerDoc = NULL; + isAllLaoded = false; + } + else + getUserStylersFromXmlTree(); + + _themeSwitcher._stylesXmlPath = _stylerPath; + // Firstly, add the default theme + _themeSwitcher.addDefaultThemeFromXml(_stylerPath); + + //-----------------------------------// + // userDefineLang.xml : for per user // + //-----------------------------------// + lstrcpy(_userDefineLangPath, _userPath); + PathAppend(_userDefineLangPath, TEXT("userDefineLang.xml")); + + _pXmlUserLangDoc = new TiXmlDocument(_userDefineLangPath); + loadOkay = _pXmlUserLangDoc->LoadFile(); + if (!loadOkay) + { + delete _pXmlUserLangDoc; + _pXmlUserLangDoc = NULL; + isAllLaoded = false; + } + else + getUserDefineLangsFromXmlTree(); + + //----------------------------------------------// + // nativeLang.xml : for per user // + // In case of absence of user's nativeLang.xml, // + // We'll look in the Notepad++ Dir. // + //----------------------------------------------// + TCHAR nativeLangPath[MAX_PATH]; + lstrcpy(nativeLangPath, _userPath); + PathAppend(nativeLangPath, TEXT("nativeLang.xml")); + + if (!PathFileExists(nativeLangPath)) + { + lstrcpy(nativeLangPath, _nppPath); + PathAppend(nativeLangPath, TEXT("nativeLang.xml")); + } + + _pXmlNativeLangDocA = new TiXmlDocumentA(); + + loadOkay = _pXmlNativeLangDocA->LoadUnicodeFilePath(nativeLangPath); + if (!loadOkay) + { + delete _pXmlNativeLangDocA; + _pXmlNativeLangDocA = NULL; + isAllLaoded = false; + } +#ifdef UNICODE + _localizationSwitcher._nativeLangPath = nativeLangPath; +#endif + //---------------------------------// + // toolbarIcons.xml : for per user // + //---------------------------------// + TCHAR toolbarIconsPath[MAX_PATH]; + lstrcpy(toolbarIconsPath, _userPath); + PathAppend(toolbarIconsPath, TEXT("toolbarIcons.xml")); + + _pXmlToolIconsDoc = new TiXmlDocument(toolbarIconsPath); + loadOkay = _pXmlToolIconsDoc->LoadFile(); + if (!loadOkay) + { + delete _pXmlToolIconsDoc; + _pXmlToolIconsDoc = NULL; + isAllLaoded = false; + } + + //------------------------------// + // shortcuts.xml : for per user // + //------------------------------// + lstrcpy(_shortcutsPath, _userPath); + PathAppend(_shortcutsPath, TEXT("shortcuts.xml")); + + if (!PathFileExists(_shortcutsPath)) + { + TCHAR srcShortcutsPath[MAX_PATH]; + lstrcpy(srcShortcutsPath, _nppPath); + PathAppend(srcShortcutsPath, TEXT("shortcuts.xml")); + + ::CopyFile(srcShortcutsPath, _shortcutsPath, TRUE); + } + + _pXmlShortcutDoc = new TiXmlDocument(_shortcutsPath); + loadOkay = _pXmlShortcutDoc->LoadFile(); + if (!loadOkay) + { + delete _pXmlShortcutDoc; + _pXmlShortcutDoc = NULL; + isAllLaoded = false; + } + else + { + getShortcutsFromXmlTree(); + getMacrosFromXmlTree(); + getUserCmdsFromXmlTree(); + + // fill out _scintillaModifiedKeys : + // those user defined Scintilla key will be used remap Scintilla Key Array + getScintKeysFromXmlTree(); + } + + //---------------------------------// + // contextMenu.xml : for per user // + //---------------------------------// + lstrcpy(_contextMenuPath, _userPath); + PathAppend(_contextMenuPath, TEXT("contextMenu.xml")); + + if (!PathFileExists(_contextMenuPath)) + { + TCHAR srcContextMenuPath[MAX_PATH]; + lstrcpy(srcContextMenuPath, _nppPath); + PathAppend(srcContextMenuPath, TEXT("contextMenu.xml")); + + ::CopyFile(srcContextMenuPath, _contextMenuPath, TRUE); + } + + _pXmlContextMenuDoc = new TiXmlDocument(_contextMenuPath); + loadOkay = _pXmlContextMenuDoc->LoadFile(); + if (!loadOkay) + { + delete _pXmlContextMenuDoc; + _pXmlContextMenuDoc = NULL; + isAllLaoded = false; + } + //else + //getContextMenuFromXmlTree(); + + //----------------------------// + // session.xml : for per user // + //----------------------------// + lstrcpy(_sessionPath, _userPath); + PathAppend(_sessionPath, TEXT("session.xml")); + + // Don't load session.xml if not required in order to speed up!! + const NppGUI & nppGUI = (NppParameters::getInstance())->getNppGUI(); + if (nppGUI._rememberLastSession) + { + _pXmlSessionDoc = new TiXmlDocument(_sessionPath); + loadOkay = _pXmlSessionDoc->LoadFile(); + if (!loadOkay) + isAllLaoded = false; + else + getSessionFromXmlTree(); + + delete _pXmlSessionDoc; + for (size_t i = 0 ; i < _pXmlExternalLexerDoc.size() ; i++) + if (_pXmlExternalLexerDoc[i]) + delete _pXmlExternalLexerDoc[i]; + + _pXmlSessionDoc = NULL; + } + return isAllLaoded; +} + +void NppParameters::destroyInstance() +{ + if (_pXmlDoc != NULL) + { + delete _pXmlDoc; + } + + if (_pXmlUserDoc != NULL) + { + _pXmlUserDoc->SaveFile(); + delete _pXmlUserDoc; + } + if (_pXmlUserStylerDoc) + delete _pXmlUserStylerDoc; + + if (_pXmlUserLangDoc) + delete _pXmlUserLangDoc; + + if (_pXmlNativeLangDocA) + delete _pXmlNativeLangDocA; + + if (_pXmlToolIconsDoc) + delete _pXmlToolIconsDoc; + + if (_pXmlShortcutDoc) + delete _pXmlShortcutDoc; + + if (_pXmlContextMenuDoc) + delete _pXmlContextMenuDoc; + + if (_pXmlSessionDoc) + delete _pXmlSessionDoc; + + delete _pSelf; +} + +void NppParameters::setFontList(HWND hWnd) +{ + //---------------// + // Sys font list // + //---------------// + + LOGFONT lf; + _fontlist.clear(); + _fontlist.push_back(TEXT("")); + + lf.lfCharSet = DEFAULT_CHARSET; + lf.lfFaceName[0]='\0'; + lf.lfPitchAndFamily = 0; + HDC hDC = ::GetDC(hWnd); + + ::EnumFontFamiliesEx(hDC, + &lf, + (FONTENUMPROC) EnumFontFamExProc, + (LPARAM) &_fontlist, 0); +} + +void NppParameters::getLangKeywordsFromXmlTree() +{ + TiXmlNode *root = _pXmlDoc->FirstChild(TEXT("NotepadPlus")); + if (!root) return; + feedKeyWordsParameters(root); +} + +void NppParameters::getExternalLexerFromXmlTree(TiXmlDocument *doc) +{ + TiXmlNode *root = doc->FirstChild(TEXT("NotepadPlus")); + if (!root) return; + feedKeyWordsParameters(root); + feedStylerArray(root); +} + +int NppParameters::addExternalLangToEnd(ExternalLangContainer * externalLang) +{ + _externalLangArray[_nbExternalLang] = externalLang; + _nbExternalLang++; + L_END++; + return _nbExternalLang-1; +} + +bool NppParameters::getUserStylersFromXmlTree() +{ + TiXmlNode *root = _pXmlUserStylerDoc->FirstChild(TEXT("NotepadPlus")); + if (!root) return false; + return feedStylerArray(root); +} + +bool NppParameters::getUserParametersFromXmlTree() +{ + if (!_pXmlUserDoc) + return false; + + TiXmlNode *root = _pXmlUserDoc->FirstChild(TEXT("NotepadPlus")); + if (!root) return false; + + // GUI + feedGUIParameters(root); + + //History + feedFileListParameters(root); + + // Raser tout + TiXmlNode *node = root->FirstChildElement(TEXT("History")); + root->RemoveChild(node); + + // Repartir de zero + TiXmlElement HistoryNode(TEXT("History")); + + root->InsertEndChild(HistoryNode); + + //Find history + feedFindHistoryParameters(root); + + return true; +} + +bool NppParameters::getUserDefineLangsFromXmlTree() +{ + if (!_pXmlUserLangDoc) + return false; + + TiXmlNode *root = _pXmlUserLangDoc->FirstChild(TEXT("NotepadPlus")); + if (!root) + return false; + + feedUserLang(root); + return true; +} + +bool NppParameters::getShortcutsFromXmlTree() +{ + if (!_pXmlShortcutDoc) + return false; + + TiXmlNode *root = _pXmlShortcutDoc->FirstChild(TEXT("NotepadPlus")); + if (!root) + return false; + + feedShortcut(root); + return true; +} + +bool NppParameters::getMacrosFromXmlTree() +{ + if (!_pXmlShortcutDoc) + return false; + + TiXmlNode *root = _pXmlShortcutDoc->FirstChild(TEXT("NotepadPlus")); + if (!root) + return false; + + feedMacros(root); + return true; +} + +bool NppParameters::getUserCmdsFromXmlTree() +{ + if (!_pXmlShortcutDoc) + return false; + + TiXmlNode *root = _pXmlShortcutDoc->FirstChild(TEXT("NotepadPlus")); + if (!root) + return false; + + feedUserCmds(root); + return true; +} + + +bool NppParameters::getPluginCmdsFromXmlTree() +{ + if (!_pXmlShortcutDoc) + return false; + + TiXmlNode *root = _pXmlShortcutDoc->FirstChild(TEXT("NotepadPlus")); + if (!root) + return false; + + feedPluginCustomizedCmds(root); + return true; +} + + +bool NppParameters::getScintKeysFromXmlTree() +{ + if (!_pXmlShortcutDoc) + return false; + + TiXmlNode *root = _pXmlShortcutDoc->FirstChild(TEXT("NotepadPlus")); + if (!root) + return false; + + feedScintKeys(root); + return true; +} + +void NppParameters::initMenuKeys() +{ + int nrCommands = sizeof(winKeyDefs)/sizeof(WinMenuKeyDefinition); + WinMenuKeyDefinition wkd; + for(int i = 0; i < nrCommands; i++) + { + wkd = winKeyDefs[i]; + Shortcut sc( (wkd.specialName?wkd.specialName:TEXT("")), wkd.isCtrl, wkd.isAlt, wkd.isShift, wkd.vKey); + _shortcuts.push_back( CommandShortcut(sc, wkd.functionId) ); + } +} + +void NppParameters::initScintillaKeys() { + + int nrCommands = sizeof(scintKeyDefs)/sizeof(ScintillaKeyDefinition); + + //Warning! Matching function have to be consecutive + ScintillaKeyDefinition skd; + size_t prevIndex = -1; + int prevID = -1; + for(int i = 0; i < nrCommands; i++) { + skd = scintKeyDefs[i]; + if (skd.functionId == prevID) { + KeyCombo kc; + kc._isCtrl = skd.isCtrl; + kc._isAlt = skd.isAlt; + kc._isShift = skd.isShift; + kc._key = skd.vKey; + _scintillaKeyCommands[prevIndex].addKeyCombo(kc); + } else { + _scintillaKeyCommands.push_back(ScintillaKeyMap(Shortcut(skd.name, skd.isCtrl, skd.isAlt, skd.isShift, skd.vKey), skd.functionId, skd.redirFunctionId)); + prevIndex++; + } + prevID = skd.functionId; + } +} +bool NppParameters::reloadContextMenuFromXmlTree(HMENU mainMenuHadle) +{ + _contextMenuItems.clear(); + return getContextMenuFromXmlTree(mainMenuHadle); +} + +bool NppParameters::getContextMenuFromXmlTree(HMENU mainMenuHadle) +{ + if (!_pXmlContextMenuDoc) + return false; + TiXmlNode *root = _pXmlContextMenuDoc->FirstChild(TEXT("NotepadPlus")); + if (!root) + return false; + TiXmlNode *contextMenuRoot = root->FirstChildElement(TEXT("ScintillaContextMenu")); + if (contextMenuRoot) + { + for (TiXmlNode *childNode = contextMenuRoot->FirstChildElement(TEXT("Item")); + childNode ; + childNode = childNode->NextSibling(TEXT("Item")) ) + { + int id; + const TCHAR *idStr = (childNode->ToElement())->Attribute(TEXT("id"), &id); + if (idStr) + { + _contextMenuItems.push_back(MenuItemUnit(id, TEXT(""))); + } + else + { + const TCHAR *menuEntryName = (childNode->ToElement())->Attribute(TEXT("MenuEntryName")); + const TCHAR *menuItemName = (childNode->ToElement())->Attribute(TEXT("MenuItemName")); + if (menuEntryName && menuItemName) + { + int nbMenuEntry = ::GetMenuItemCount(mainMenuHadle); + for (int i = 0 ; i < nbMenuEntry ; i++) + { + TCHAR menuEntryString[64]; + ::GetMenuString(mainMenuHadle, i, menuEntryString, 64, MF_BYPOSITION); + if (generic_stricmp(menuEntryName, purgeMenuItemString(menuEntryString).c_str()) == 0) + { + HMENU subMenu = ::GetSubMenu(mainMenuHadle, i); + int nbSubMenuCmd = ::GetMenuItemCount(subMenu); + for (int j = 0 ; j < nbSubMenuCmd ; j++) + { + TCHAR cmdStr[256]; + ::GetMenuString(subMenu, j, cmdStr, 256, MF_BYPOSITION); + if (generic_stricmp(menuItemName, purgeMenuItemString(cmdStr).c_str()) == 0) + { + int cmdId = ::GetMenuItemID(subMenu, j); + _contextMenuItems.push_back(MenuItemUnit(cmdId, TEXT(""))); + break; + } + } + break; + } + } + } + else + { + const TCHAR *pluginName = (childNode->ToElement())->Attribute(TEXT("PluginEntryName")); + const TCHAR *pluginCmdName = (childNode->ToElement())->Attribute(TEXT("pluginCommandItemName")); + if (pluginName && pluginCmdName) + { + HMENU pluginsMenu = ::GetSubMenu(mainMenuHadle, MENUINDEX_PLUGINS); + int nbPlugins = ::GetMenuItemCount(pluginsMenu); + for (int i = 0 ; i < nbPlugins ; i++) + { + TCHAR menuItemString[256]; + ::GetMenuString(pluginsMenu, i, menuItemString, 256, MF_BYPOSITION); + if (generic_stricmp(pluginName, purgeMenuItemString(menuItemString).c_str()) == 0) + { + HMENU pluginMenu = ::GetSubMenu(pluginsMenu, i); + int nbPluginCmd = ::GetMenuItemCount(pluginMenu); + for (int j = 0 ; j < nbPluginCmd ; j++) + { + TCHAR pluginCmdStr[256]; + ::GetMenuString(pluginMenu, j, pluginCmdStr, 256, MF_BYPOSITION); + if (generic_stricmp(pluginCmdName, purgeMenuItemString(pluginCmdStr).c_str()) == 0) + { + int pluginCmdId = ::GetMenuItemID(pluginMenu, j); + _contextMenuItems.push_back(MenuItemUnit(pluginCmdId, TEXT(""))); + break; + } + } + break; + } + } + } + } + } + } + } + return true; +} + +void NppParameters::setWorkingDir(const TCHAR * newPath) +{ + if (newPath && newPath[0]) + { + lstrcpyn(_currentDirectory, newPath, MAX_PATH); //dont use sizeof + } + else + { + if (PathFileExists(_nppGUI._defaultDirExp)) + { + lstrcpyn(_currentDirectory, _nppGUI._defaultDirExp, MAX_PATH); + } + else + { + lstrcpyn(_currentDirectory, _nppPath, MAX_PATH); + } + } +} + +bool NppParameters::loadSession(Session & session, const TCHAR *sessionFileName) +{ + TiXmlDocument *pXmlSessionDocument = new TiXmlDocument(sessionFileName); + bool loadOkay = pXmlSessionDocument->LoadFile(); + if (loadOkay) + loadOkay = getSessionFromXmlTree(pXmlSessionDocument, &session); + + delete pXmlSessionDocument; + return loadOkay; +} + +bool NppParameters::getSessionFromXmlTree(TiXmlDocument *pSessionDoc, Session *pSession) +{ + if ((pSessionDoc) && (!pSession)) + return false; + + TiXmlDocument **ppSessionDoc = &_pXmlSessionDoc; + Session *ptrSession = &_session; + + if (pSessionDoc) + { + ppSessionDoc = &pSessionDoc; + ptrSession = pSession; + } + + if (!*ppSessionDoc) + return false; + + TiXmlNode *root = (*ppSessionDoc)->FirstChild(TEXT("NotepadPlus")); + if (!root) + return false; + + TiXmlNode *sessionRoot = root->FirstChildElement(TEXT("Session")); + if (!sessionRoot) + return false; + + + TiXmlElement *actView = sessionRoot->ToElement(); + size_t index; + const TCHAR *str = actView->Attribute(TEXT("activeView"), (int *)&index); + if (str) + { + (*ptrSession)._activeView = index; + } + + + TiXmlNode *mainviewRoot = sessionRoot->FirstChildElement(TEXT("mainView")); + if (mainviewRoot) + { + TiXmlElement *actIndex = mainviewRoot->ToElement(); + str = actIndex->Attribute(TEXT("activeIndex"), (int *)&index); + if (str) + { + (*ptrSession)._activeMainIndex = index; + } + for (TiXmlNode *childNode = mainviewRoot->FirstChildElement(TEXT("File")); + childNode ; + childNode = childNode->NextSibling(TEXT("File")) ) + { + const TCHAR *fileName = (childNode->ToElement())->Attribute(TEXT("filename")); + if (fileName) + { + Position position; + (childNode->ToElement())->Attribute(TEXT("firstVisibleLine"), &position._firstVisibleLine); + (childNode->ToElement())->Attribute(TEXT("xOffset"), &position._xOffset); + (childNode->ToElement())->Attribute(TEXT("startPos"), &position._startPos); + (childNode->ToElement())->Attribute(TEXT("endPos"), &position._endPos); + (childNode->ToElement())->Attribute(TEXT("selMode"), &position._selMode); + (childNode->ToElement())->Attribute(TEXT("scrollWidth"), &position._scrollWidth); + + const TCHAR *langName; + langName = (childNode->ToElement())->Attribute(TEXT("lang")); + sessionFileInfo sfi( fileName, langName, position ); + + for (TiXmlNode *markNode = childNode->FirstChildElement(TEXT("Mark")); + markNode ; + markNode = markNode->NextSibling(TEXT("Mark"))) + { + int lineNumber; + const TCHAR *lineNumberStr = (markNode->ToElement())->Attribute(TEXT("line"), &lineNumber); + if (lineNumberStr) + { + sfi.marks.push_back(lineNumber); + } + } + (*ptrSession)._mainViewFiles.push_back(sfi); + } + } + } + + TiXmlNode *subviewRoot = sessionRoot->FirstChildElement(TEXT("subView")); + if (subviewRoot) + { + TiXmlElement *actIndex = subviewRoot->ToElement(); + str = actIndex->Attribute(TEXT("activeIndex"), (int *)&index); + if (str) + { + (*ptrSession)._activeSubIndex = index; + } + for (TiXmlNode *childNode = subviewRoot->FirstChildElement(TEXT("File")); + childNode ; + childNode = childNode->NextSibling(TEXT("File")) ) + { + const TCHAR *fileName = (childNode->ToElement())->Attribute(TEXT("filename")); + if (fileName) + { + + Position position; + (childNode->ToElement())->Attribute(TEXT("firstVisibleLine"), &position._firstVisibleLine); + (childNode->ToElement())->Attribute(TEXT("xOffset"), &position._xOffset); + (childNode->ToElement())->Attribute(TEXT("startPos"), &position._startPos); + (childNode->ToElement())->Attribute(TEXT("endPos"), &position._endPos); + (childNode->ToElement())->Attribute(TEXT("selMode"), &position._selMode); + (childNode->ToElement())->Attribute(TEXT("scrollWidth"), &position._scrollWidth); + + const TCHAR *langName; + langName = (childNode->ToElement())->Attribute(TEXT("lang")); + sessionFileInfo sfi( fileName, langName, position ); + + for (TiXmlNode *markNode = childNode->FirstChildElement(TEXT("Mark")); + markNode ; + markNode = markNode->NextSibling(TEXT("Mark"))) + { + int lineNumber; + const TCHAR *lineNumberStr = (markNode->ToElement())->Attribute(TEXT("line"), &lineNumber); + if (lineNumberStr) + { + sfi.marks.push_back(lineNumber); + } + } + (*ptrSession)._subViewFiles.push_back(sfi); + } + } + } + + + return true; +} +void NppParameters::feedFileListParameters(TiXmlNode *node) +{ + _nbMaxFile = 10; + + TiXmlNode *historyRoot = node->FirstChildElement(TEXT("History")); + if (!historyRoot) return; + + (historyRoot->ToElement())->Attribute(TEXT("nbMaxFile"), &_nbMaxFile); + if ((_nbMaxFile < 0) || (_nbMaxFile > 30)) + return; + + for (TiXmlNode *childNode = historyRoot->FirstChildElement(TEXT("File")); + childNode && (_nbFile < NB_MAX_LRF_FILE); + childNode = childNode->NextSibling(TEXT("File")) ) + { + const TCHAR *filePath = (childNode->ToElement())->Attribute(TEXT("filename")); + if (filePath) + { + _LRFileList[_nbFile] = new generic_string(filePath); + _nbFile++; + } + } +} + +void NppParameters::feedFindHistoryParameters(TiXmlNode *node) +{ + TiXmlNode *findHistoryRoot = node->FirstChildElement(TEXT("FindHistory")); + if (!findHistoryRoot) return; + + (findHistoryRoot->ToElement())->Attribute(TEXT("nbMaxFindHistoryPath"), &_findHistory._nbMaxFindHistoryPath); + if ((_findHistory._nbMaxFindHistoryPath > 0) && (_findHistory._nbMaxFindHistoryPath <= NB_MAX_FINDHISTORY_PATH)) + { + for (TiXmlNode *childNode = findHistoryRoot->FirstChildElement(TEXT("Path")); + childNode && (_findHistory._nbFindHistoryPath < NB_MAX_FINDHISTORY_PATH); + childNode = childNode->NextSibling(TEXT("Path")) ) + { + const TCHAR *filePath = (childNode->ToElement())->Attribute(TEXT("name")); + if (filePath) + { + _findHistory._pFindHistoryPath[_findHistory._nbFindHistoryPath++] = new generic_string(filePath); + } + } + } + + (findHistoryRoot->ToElement())->Attribute(TEXT("nbMaxFindHistoryFilter"), &_findHistory._nbMaxFindHistoryFilter); + if ((_findHistory._nbMaxFindHistoryFilter > 0) && (_findHistory._nbMaxFindHistoryFilter <= NB_MAX_FINDHISTORY_FILTER)) + { + for (TiXmlNode *childNode = findHistoryRoot->FirstChildElement(TEXT("Filter")); + childNode && (_findHistory._nbFindHistoryFilter < NB_MAX_FINDHISTORY_FILTER); + childNode = childNode->NextSibling(TEXT("Filter"))) + { + const TCHAR *fileFilter = (childNode->ToElement())->Attribute(TEXT("name")); + if (fileFilter) + { + _findHistory._pFindHistoryFilter[_findHistory._nbFindHistoryFilter++] = new generic_string(fileFilter); + } + } + } + + (findHistoryRoot->ToElement())->Attribute(TEXT("nbMaxFindHistoryFind"), &_findHistory._nbMaxFindHistoryFind); + if ((_findHistory._nbMaxFindHistoryFind > 0) && (_findHistory._nbMaxFindHistoryFind <= NB_MAX_FINDHISTORY_FIND)) + { + for (TiXmlNode *childNode = findHistoryRoot->FirstChildElement(TEXT("Find")); + childNode && (_findHistory._nbFindHistoryFind < NB_MAX_FINDHISTORY_FIND); + childNode = childNode->NextSibling(TEXT("Find"))) + { + const TCHAR *fileFind = (childNode->ToElement())->Attribute(TEXT("name")); + if (fileFind) + { + _findHistory._pFindHistoryFind[_findHistory._nbFindHistoryFind++] = new generic_string(fileFind); + } + } + } + + (findHistoryRoot->ToElement())->Attribute(TEXT("nbMaxFindHistoryReplace"), &_findHistory._nbMaxFindHistoryReplace); + if ((_findHistory._nbMaxFindHistoryReplace > 0) && (_findHistory._nbMaxFindHistoryReplace <= NB_MAX_FINDHISTORY_REPLACE)) + { + for (TiXmlNode *childNode = findHistoryRoot->FirstChildElement(TEXT("Replace")); + childNode && (_findHistory._nbFindHistoryReplace < NB_MAX_FINDHISTORY_REPLACE); + childNode = childNode->NextSibling(TEXT("Replace"))) + { + const TCHAR *fileReplace = (childNode->ToElement())->Attribute(TEXT("name")); + if (fileReplace) + { + _findHistory._pFindHistoryReplace[_findHistory._nbFindHistoryReplace++] = new generic_string(fileReplace); + } + } + } + + const TCHAR *boolStr = (findHistoryRoot->ToElement())->Attribute(TEXT("matchWord")); + if (boolStr) + _findHistory._isMatchWord = !lstrcmp(TEXT("yes"), boolStr); + + boolStr = (findHistoryRoot->ToElement())->Attribute(TEXT("matchCase")); + if (boolStr) + _findHistory._isMatchCase = !lstrcmp(TEXT("yes"), boolStr); + + boolStr = (findHistoryRoot->ToElement())->Attribute(TEXT("wrap")); + if (boolStr) + _findHistory._isWrap = !lstrcmp(TEXT("yes"), boolStr); + + boolStr = (findHistoryRoot->ToElement())->Attribute(TEXT("directionDown")); + if (boolStr) + _findHistory._isDirectionDown = !lstrcmp(TEXT("yes"), boolStr); + + boolStr = (findHistoryRoot->ToElement())->Attribute(TEXT("fifRecuisive")); + if (boolStr) + _findHistory._isFifRecuisive = !lstrcmp(TEXT("yes"), boolStr); + + boolStr = (findHistoryRoot->ToElement())->Attribute(TEXT("fifInHiddenFolder")); + if (boolStr) + _findHistory._isFifInHiddenFolder = !lstrcmp(TEXT("yes"), boolStr); + + boolStr = (findHistoryRoot->ToElement())->Attribute(TEXT("dlgAlwaysVisible")); + if (boolStr) + _findHistory._isDlgAlwaysVisible = !lstrcmp(TEXT("yes"), boolStr); + + boolStr = (findHistoryRoot->ToElement())->Attribute(TEXT("fifFilterFollowsDoc")); + if (boolStr) + _findHistory._isFilterFollowDoc = !lstrcmp(TEXT("yes"), boolStr); + + boolStr = (findHistoryRoot->ToElement())->Attribute(TEXT("fifFolderFollowsDoc")); + if (boolStr) + _findHistory._isFolderFollowDoc = !lstrcmp(TEXT("yes"), boolStr); + + int mode = 0; + boolStr = (findHistoryRoot->ToElement())->Attribute(TEXT("searchMode"), &mode); + if (boolStr) + _findHistory._searchMode = (FindHistory::searchMode)mode; + + boolStr = (findHistoryRoot->ToElement())->Attribute(TEXT("transparencyMode"), &mode); + if (boolStr) + _findHistory._transparencyMode = (FindHistory::transparencyMode)mode; + + (findHistoryRoot->ToElement())->Attribute(TEXT("transparency"), &_findHistory._transparency); + if (_findHistory._transparency <= 0 || _findHistory._transparency > 200) + _findHistory._transparency = 150; +} + +void NppParameters::feedShortcut(TiXmlNode *node) +{ + TiXmlNode *shortcutsRoot = node->FirstChildElement(TEXT("InternalCommands")); + if (!shortcutsRoot) return; + + for (TiXmlNode *childNode = shortcutsRoot->FirstChildElement(TEXT("Shortcut")); + childNode ; + childNode = childNode->NextSibling(TEXT("Shortcut")) ) + { + int id; + const TCHAR *idStr = (childNode->ToElement())->Attribute(TEXT("id"), &id); + if (idStr) + { + //find the commandid that matches this Shortcut sc and alter it, push back its index in the modified list, if not present + int len = (int)_shortcuts.size(); + for(int i = 0; i < len; i++) + { + if (_shortcuts[i].getID() == id) + { //found our match + getShortcuts(childNode, _shortcuts[i]); + addUserModifiedIndex(i); + } + } + } + } +} + +void NppParameters::feedMacros(TiXmlNode *node) +{ + TiXmlNode *macrosRoot = node->FirstChildElement(TEXT("Macros")); + if (!macrosRoot) return; + + for (TiXmlNode *childNode = macrosRoot->FirstChildElement(TEXT("Macro")); + childNode ; + childNode = childNode->NextSibling(TEXT("Macro")) ) + { + Shortcut sc; + if (getShortcuts(childNode, sc))// && sc.isValid()) + { + Macro macro; + getActions(childNode, macro); + int cmdID = ID_MACRO + _macros.size(); + MacroShortcut ms(sc, macro, cmdID); + //if (ms.isValid()) + _macros.push_back(ms); + } + } +} + + +void NppParameters::getActions(TiXmlNode *node, Macro & macro) +{ + for (TiXmlNode *childNode = node->FirstChildElement(TEXT("Action")); + childNode ; + childNode = childNode->NextSibling(TEXT("Action")) ) + { + int type; + const TCHAR *typeStr = (childNode->ToElement())->Attribute(TEXT("type"), &type); + if ((!typeStr) || (type > 2)) + continue; + + int msg = 0; + const TCHAR *msgStr = (childNode->ToElement())->Attribute(TEXT("message"), &msg); + + int wParam = 0; + const TCHAR *wParamStr = (childNode->ToElement())->Attribute(TEXT("wParam"), &wParam); + + int lParam = 0; + const TCHAR *lParamStr = (childNode->ToElement())->Attribute(TEXT("lParam"), &lParam); + + const TCHAR *sParam = (childNode->ToElement())->Attribute(TEXT("sParam")); + if (!sParam) + sParam = TEXT(""); + recordedMacroStep step(type, msg, wParam, lParam, sParam); + if (step.isValid()) + macro.push_back(step); + + } +} + +void NppParameters::feedUserCmds(TiXmlNode *node) +{ + TiXmlNode *userCmdsRoot = node->FirstChildElement(TEXT("UserDefinedCommands")); + if (!userCmdsRoot) return; + + for (TiXmlNode *childNode = userCmdsRoot->FirstChildElement(TEXT("Command")); + childNode ; + childNode = childNode->NextSibling(TEXT("Command")) ) + { + Shortcut sc; + if (getShortcuts(childNode, sc))// && sc.isValid()) + { + TiXmlNode *aNode = childNode->FirstChild(); + if (aNode) + { + const TCHAR *cmdStr = aNode->Value(); + if (cmdStr) + { + int cmdID = ID_USER_CMD + _userCommands.size(); + UserCommand uc(sc, cmdStr, cmdID); + //if (uc.isValid()) + _userCommands.push_back(uc); + } + } + } + } +} + +void NppParameters::feedPluginCustomizedCmds(TiXmlNode *node) +{ + TiXmlNode *pluginCustomizedCmdsRoot = node->FirstChildElement(TEXT("PluginCommands")); + if (!pluginCustomizedCmdsRoot) return; + + for (TiXmlNode *childNode = pluginCustomizedCmdsRoot->FirstChildElement(TEXT("PluginCommand")); + childNode ; + childNode = childNode->NextSibling(TEXT("PluginCommand")) ) + { + const TCHAR *moduleName = (childNode->ToElement())->Attribute(TEXT("moduleName")); + if (!moduleName) + continue; + + int internalID = -1; + const TCHAR *internalIDStr = (childNode->ToElement())->Attribute(TEXT("internalID"), &internalID); + + if (!internalIDStr) + continue; + + //Find the corresponding plugincommand and alter it, put the index in the list + int len = (int)_pluginCommands.size(); + for(int i = 0; i < len; i++) + { + PluginCmdShortcut & pscOrig = _pluginCommands[i]; + if (!generic_strnicmp(pscOrig.getModuleName(), moduleName, lstrlen(moduleName)) && pscOrig.getInternalID() == internalID) + { + //Found matching command + getShortcuts(childNode, _pluginCommands[i]); + addPluginModifiedIndex(i); + break; + } + } + } +} + +void NppParameters::feedScintKeys(TiXmlNode *node) +{ + TiXmlNode *scintKeysRoot = node->FirstChildElement(TEXT("ScintillaKeys")); + if (!scintKeysRoot) return; + + for (TiXmlNode *childNode = scintKeysRoot->FirstChildElement(TEXT("ScintKey")); + childNode ; + childNode = childNode->NextSibling(TEXT("ScintKey")) ) + { + int scintKey; + const TCHAR *keyStr = (childNode->ToElement())->Attribute(TEXT("ScintID"), &scintKey); + if (!keyStr) + continue; + + int menuID; + keyStr = (childNode->ToElement())->Attribute(TEXT("menuCmdID"), &menuID); + if (!keyStr) + continue; + + //Find the corresponding scintillacommand and alter it, put the index in the list + size_t len = _scintillaKeyCommands.size(); + for(size_t i = 0; i < len; i++) + { + ScintillaKeyMap & skmOrig = _scintillaKeyCommands[i]; + if (skmOrig.getScintillaKeyID() == scintKey &&skmOrig.getMenuCmdID() == menuID) + { + //Found matching command + _scintillaKeyCommands[i].clearDups(); + getShortcuts(childNode, _scintillaKeyCommands[i]); + _scintillaKeyCommands[i].setKeyComboByIndex(0, _scintillaKeyCommands[i].getKeyCombo()); + addScintillaModifiedIndex(i); + KeyCombo kc; + for (TiXmlNode *nextNode = childNode->FirstChildElement(TEXT("NextKey")); + nextNode ; + nextNode = childNode->NextSibling(TEXT("NextKey")) ) + { + const TCHAR *str = (nextNode->ToElement())->Attribute(TEXT("Ctrl")); + if (!str) + continue; + kc._isCtrl = !lstrcmp(TEXT("yes"), str); + + str = (nextNode->ToElement())->Attribute(TEXT("Alt")); + if (!str) + continue; + kc._isAlt = !lstrcmp(TEXT("yes"), str); + + str = (nextNode->ToElement())->Attribute(TEXT("Shift")); + if (!str) + continue; + kc._isShift = !lstrcmp(TEXT("yes"), str); + + int key; + str = (nextNode->ToElement())->Attribute(TEXT("Key"), &key); + if (!str) + continue; + kc._key = key; + _scintillaKeyCommands[i].addKeyCombo(kc); + } + break; + } + } + } +} + +bool NppParameters::getShortcuts(TiXmlNode *node, Shortcut & sc) +{ + if (!node) return false; + + const TCHAR *name = (node->ToElement())->Attribute(TEXT("name")); + if (!name) + name = TEXT(""); + + bool isCtrl = false; + const TCHAR *isCtrlStr = (node->ToElement())->Attribute(TEXT("Ctrl")); + if (isCtrlStr) + isCtrl = !lstrcmp(TEXT("yes"), isCtrlStr); + + bool isAlt = false; + const TCHAR *isAltStr = (node->ToElement())->Attribute(TEXT("Alt")); + if (isAltStr) + isAlt = !lstrcmp(TEXT("yes"), isAltStr); + + bool isShift = false; + const TCHAR *isShiftStr = (node->ToElement())->Attribute(TEXT("Shift")); + if (isShiftStr) + isShift = !lstrcmp(TEXT("yes"), isShiftStr); + + int key; + const TCHAR *keyStr = (node->ToElement())->Attribute(TEXT("Key"), &key); + if (!keyStr) + return false; + + sc = Shortcut(name, isCtrl, isAlt, isShift, key); + return true; +} + + +const int loadFailed = 100; +const int missingName = 101; +void NppParameters::feedUserLang(TiXmlNode *node) +{ + for (TiXmlNode *childNode = node->FirstChildElement(TEXT("UserLang")); + childNode && (_nbUserLang < NB_MAX_USER_LANG); + childNode = childNode->NextSibling(TEXT("UserLang")) ) + { + const TCHAR *name = (childNode->ToElement())->Attribute(TEXT("name")); + const TCHAR *ext = (childNode->ToElement())->Attribute(TEXT("ext")); + try { + if (!name || !name[0] || !ext) throw int(missingName); + + _userLangArray[_nbUserLang] = new UserLangContainer(name, ext); + _nbUserLang++; + + TiXmlNode *settingsRoot = childNode->FirstChildElement(TEXT("Settings")); + if (!settingsRoot) throw int(loadFailed); + feedUserSettings(settingsRoot); + + TiXmlNode *keywordListsRoot = childNode->FirstChildElement(TEXT("KeywordLists")); + if (!keywordListsRoot) throw int(loadFailed); + feedUserKeywordList(keywordListsRoot); + + TiXmlNode *stylesRoot = childNode->FirstChildElement(TEXT("Styles")); + if (!stylesRoot) throw int(loadFailed); + feedUserStyles(stylesRoot); + + } catch (int e) { + if (e == loadFailed) + delete _userLangArray[--_nbUserLang]; + } + } +} + +void NppParameters::writeUserDefinedLang() +{ + if (!_pXmlUserLangDoc) + { + //do the treatment + _pXmlUserLangDoc = new TiXmlDocument(_userDefineLangPath); + } + + //before remove the branch, we allocate and copy the TCHAR * which will be destroyed + stylerStrOp(DUP); + + TiXmlNode *root = _pXmlUserLangDoc->FirstChild(TEXT("NotepadPlus")); + if (root) + { + _pXmlUserLangDoc->RemoveChild(root); + } + + _pXmlUserLangDoc->InsertEndChild(TiXmlElement(TEXT("NotepadPlus"))); + + root = _pXmlUserLangDoc->FirstChild(TEXT("NotepadPlus")); + + for (int i = 0 ; i < _nbUserLang ; i++) + { + insertUserLang2Tree(root, _userLangArray[i]); + } + _pXmlUserLangDoc->SaveFile(); + stylerStrOp(FREE); +} + +void NppParameters::insertCmd(TiXmlNode *shortcutsRoot, const CommandShortcut & cmd) +{ + const KeyCombo & key = cmd.getKeyCombo(); + TiXmlNode *sc = shortcutsRoot->InsertEndChild(TiXmlElement(TEXT("Shortcut"))); + sc->ToElement()->SetAttribute(TEXT("id"), cmd.getID()); + sc->ToElement()->SetAttribute(TEXT("Ctrl"), key._isCtrl?TEXT("yes"):TEXT("no")); + sc->ToElement()->SetAttribute(TEXT("Alt"), key._isAlt?TEXT("yes"):TEXT("no")); + sc->ToElement()->SetAttribute(TEXT("Shift"), key._isShift?TEXT("yes"):TEXT("no")); + sc->ToElement()->SetAttribute(TEXT("Key"), key._key); +} + +void NppParameters::insertMacro(TiXmlNode *macrosRoot, const MacroShortcut & macro) +{ + const KeyCombo & key = macro.getKeyCombo(); + TiXmlNode *macroRoot = macrosRoot->InsertEndChild(TiXmlElement(TEXT("Macro"))); + macroRoot->ToElement()->SetAttribute(TEXT("name"), macro.getMenuName()); + macroRoot->ToElement()->SetAttribute(TEXT("Ctrl"), key._isCtrl?TEXT("yes"):TEXT("no")); + macroRoot->ToElement()->SetAttribute(TEXT("Alt"), key._isAlt?TEXT("yes"):TEXT("no")); + macroRoot->ToElement()->SetAttribute(TEXT("Shift"), key._isShift?TEXT("yes"):TEXT("no")); + macroRoot->ToElement()->SetAttribute(TEXT("Key"), key._key); + for (size_t i = 0 ; i < macro._macro.size() ; i++) + { + TiXmlNode *actionNode = macroRoot->InsertEndChild(TiXmlElement(TEXT("Action"))); + const recordedMacroStep & action = macro._macro[i]; + actionNode->ToElement()->SetAttribute(TEXT("type"), action.MacroType); + actionNode->ToElement()->SetAttribute(TEXT("message"), action.message); + actionNode->ToElement()->SetAttribute(TEXT("wParam"), action.wParameter); + actionNode->ToElement()->SetAttribute(TEXT("lParam"), action.lParameter); + actionNode->ToElement()->SetAttribute(TEXT("sParam"), action.sParameter.c_str()); + } +} + +void NppParameters::insertUserCmd(TiXmlNode *userCmdRoot, const UserCommand & userCmd) +{ + const KeyCombo & key = userCmd.getKeyCombo(); + TiXmlNode *cmdRoot = userCmdRoot->InsertEndChild(TiXmlElement(TEXT("Command"))); + cmdRoot->ToElement()->SetAttribute(TEXT("name"), userCmd.getMenuName()); + cmdRoot->ToElement()->SetAttribute(TEXT("Ctrl"), key._isCtrl?TEXT("yes"):TEXT("no")); + cmdRoot->ToElement()->SetAttribute(TEXT("Alt"), key._isAlt?TEXT("yes"):TEXT("no")); + cmdRoot->ToElement()->SetAttribute(TEXT("Shift"), key._isShift?TEXT("yes"):TEXT("no")); + cmdRoot->ToElement()->SetAttribute(TEXT("Key"), key._key); + cmdRoot->InsertEndChild(TiXmlText(userCmd._cmd.c_str())); +} + +void NppParameters::insertPluginCmd(TiXmlNode *pluginCmdRoot, const PluginCmdShortcut & pluginCmd) +{ + const KeyCombo & key = pluginCmd.getKeyCombo(); + TiXmlNode *pluginCmdNode = pluginCmdRoot->InsertEndChild(TiXmlElement(TEXT("PluginCommand"))); + pluginCmdNode->ToElement()->SetAttribute(TEXT("moduleName"), pluginCmd.getModuleName()); + pluginCmdNode->ToElement()->SetAttribute(TEXT("internalID"), pluginCmd.getInternalID()); + pluginCmdNode->ToElement()->SetAttribute(TEXT("Ctrl"), key._isCtrl?TEXT("yes"):TEXT("no")); + pluginCmdNode->ToElement()->SetAttribute(TEXT("Alt"), key._isAlt?TEXT("yes"):TEXT("no")); + pluginCmdNode->ToElement()->SetAttribute(TEXT("Shift"), key._isShift?TEXT("yes"):TEXT("no")); + pluginCmdNode->ToElement()->SetAttribute(TEXT("Key"), key._key); +} + +void NppParameters::insertScintKey(TiXmlNode *scintKeyRoot, const ScintillaKeyMap & scintKeyMap) +{ + TiXmlNode *keyRoot = scintKeyRoot->InsertEndChild(TiXmlElement(TEXT("ScintKey"))); + keyRoot->ToElement()->SetAttribute(TEXT("ScintID"), scintKeyMap.getScintillaKeyID()); + keyRoot->ToElement()->SetAttribute(TEXT("menuCmdID"), scintKeyMap.getMenuCmdID()); + + //Add main shortcut + KeyCombo key = scintKeyMap.getKeyComboByIndex(0); + keyRoot->ToElement()->SetAttribute(TEXT("Ctrl"), key._isCtrl?TEXT("yes"):TEXT("no")); + keyRoot->ToElement()->SetAttribute(TEXT("Alt"), key._isAlt?TEXT("yes"):TEXT("no")); + keyRoot->ToElement()->SetAttribute(TEXT("Shift"), key._isShift?TEXT("yes"):TEXT("no")); + keyRoot->ToElement()->SetAttribute(TEXT("Key"), key._key); + + //Add additional shortcuts + size_t size = scintKeyMap.getSize(); + if (size > 1) { + TiXmlNode * keyNext; + for(size_t i = 1; i < size; i++) { + keyNext = keyRoot->InsertEndChild(TiXmlElement(TEXT("NextKey"))); + key = scintKeyMap.getKeyComboByIndex(i); + keyNext->ToElement()->SetAttribute(TEXT("Ctrl"), key._isCtrl?TEXT("yes"):TEXT("no")); + keyNext->ToElement()->SetAttribute(TEXT("Alt"), key._isAlt?TEXT("yes"):TEXT("no")); + keyNext->ToElement()->SetAttribute(TEXT("Shift"), key._isShift?TEXT("yes"):TEXT("no")); + keyNext->ToElement()->SetAttribute(TEXT("Key"), key._key); + } + } +} + +void NppParameters::writeSession(const Session & session, const TCHAR *fileName) +{ + const TCHAR *pathName = fileName?fileName:_sessionPath; + + _pXmlSessionDoc = new TiXmlDocument(pathName); + TiXmlNode *root = _pXmlSessionDoc->InsertEndChild(TiXmlElement(TEXT("NotepadPlus"))); + + if (root) + { + TiXmlNode *sessionNode = root->InsertEndChild(TiXmlElement(TEXT("Session"))); + (sessionNode->ToElement())->SetAttribute(TEXT("activeView"), (int)session._activeView); + + TiXmlNode *mainViewNode = sessionNode->InsertEndChild(TiXmlElement(TEXT("mainView"))); + (mainViewNode->ToElement())->SetAttribute(TEXT("activeIndex"), (int)session._activeMainIndex); + for (size_t i = 0 ; i < session._mainViewFiles.size() ; i++) + { + TiXmlNode *fileNameNode = mainViewNode->InsertEndChild(TiXmlElement(TEXT("File"))); + + (fileNameNode->ToElement())->SetAttribute(TEXT("firstVisibleLine"), session._mainViewFiles[i]._firstVisibleLine); + (fileNameNode->ToElement())->SetAttribute(TEXT("xOffset"), session._mainViewFiles[i]._xOffset); + (fileNameNode->ToElement())->SetAttribute(TEXT("scrollWidth"), session._mainViewFiles[i]._scrollWidth); + (fileNameNode->ToElement())->SetAttribute(TEXT("startPos"), session._mainViewFiles[i]._startPos); + (fileNameNode->ToElement())->SetAttribute(TEXT("endPos"), session._mainViewFiles[i]._endPos); + (fileNameNode->ToElement())->SetAttribute(TEXT("selMode"), session._mainViewFiles[i]._selMode); + (fileNameNode->ToElement())->SetAttribute(TEXT("lang"), session._mainViewFiles[i]._langName.c_str()); + (fileNameNode->ToElement())->SetAttribute(TEXT("filename"), session._mainViewFiles[i]._fileName.c_str()); + + for (size_t j = 0 ; j < session._mainViewFiles[i].marks.size() ; j++) + { + size_t markLine = session._mainViewFiles[i].marks[j]; + TiXmlNode *markNode = fileNameNode->InsertEndChild(TiXmlElement(TEXT("Mark"))); + markNode->ToElement()->SetAttribute(TEXT("line"), markLine); + } + } + + TiXmlNode *subViewNode = sessionNode->InsertEndChild(TiXmlElement(TEXT("subView"))); + (subViewNode->ToElement())->SetAttribute(TEXT("activeIndex"), (int)session._activeSubIndex); + for (size_t i = 0 ; i < session._subViewFiles.size() ; i++) + { + TiXmlNode *fileNameNode = subViewNode->InsertEndChild(TiXmlElement(TEXT("File"))); + + (fileNameNode->ToElement())->SetAttribute(TEXT("firstVisibleLine"), session._subViewFiles[i]._firstVisibleLine); + (fileNameNode->ToElement())->SetAttribute(TEXT("xOffset"), session._subViewFiles[i]._xOffset); + (fileNameNode->ToElement())->SetAttribute(TEXT("scrollWidth"), session._subViewFiles[i]._scrollWidth); + (fileNameNode->ToElement())->SetAttribute(TEXT("startPos"), session._subViewFiles[i]._startPos); + (fileNameNode->ToElement())->SetAttribute(TEXT("endPos"), session._subViewFiles[i]._endPos); + (fileNameNode->ToElement())->SetAttribute(TEXT("selMode"), session._subViewFiles[i]._selMode); + (fileNameNode->ToElement())->SetAttribute(TEXT("lang"), session._subViewFiles[i]._langName.c_str()); + (fileNameNode->ToElement())->SetAttribute(TEXT("filename"), session._subViewFiles[i]._fileName.c_str()); + + for (size_t j = 0 ; j < session._subViewFiles[i].marks.size() ; j++) + { + size_t markLine = session._subViewFiles[i].marks[j]; + TiXmlNode *markNode = fileNameNode->InsertEndChild(TiXmlElement(TEXT("Mark"))); + markNode->ToElement()->SetAttribute(TEXT("line"), markLine); + } + } + } + _pXmlSessionDoc->SaveFile(); + +} + +void NppParameters::writeShortcuts() +{ + if (!_pXmlShortcutDoc) + { + //do the treatment + _pXmlShortcutDoc = new TiXmlDocument(_shortcutsPath); + } + + TiXmlNode *root = _pXmlShortcutDoc->FirstChild(TEXT("NotepadPlus")); + if (!root) + { + root = _pXmlShortcutDoc->InsertEndChild(TiXmlElement(TEXT("NotepadPlus"))); + } + + TiXmlNode *cmdRoot = root->FirstChild(TEXT("InternalCommands")); + if (cmdRoot) + root->RemoveChild(cmdRoot); + + cmdRoot = root->InsertEndChild(TiXmlElement(TEXT("InternalCommands"))); + for (size_t i = 0 ; i < _customizedShortcuts.size() ; i++) + { + int index = _customizedShortcuts[i]; + CommandShortcut csc = _shortcuts[index]; + insertCmd(cmdRoot, csc); + } + + TiXmlNode *macrosRoot = root->FirstChild(TEXT("Macros")); + if (macrosRoot) + root->RemoveChild(macrosRoot); + + macrosRoot = root->InsertEndChild(TiXmlElement(TEXT("Macros"))); + + for (size_t i = 0 ; i < _macros.size() ; i++) + { + insertMacro(macrosRoot, _macros[i]); + } + + TiXmlNode *userCmdRoot = root->FirstChild(TEXT("UserDefinedCommands")); + if (userCmdRoot) + root->RemoveChild(userCmdRoot); + + userCmdRoot = root->InsertEndChild(TiXmlElement(TEXT("UserDefinedCommands"))); + + for (size_t i = 0 ; i < _userCommands.size() ; i++) + { + insertUserCmd(userCmdRoot, _userCommands[i]); + } + + TiXmlNode *pluginCmdRoot = root->FirstChild(TEXT("PluginCommands")); + if (pluginCmdRoot) + root->RemoveChild(pluginCmdRoot); + + pluginCmdRoot = root->InsertEndChild(TiXmlElement(TEXT("PluginCommands"))); + for (size_t i = 0 ; i < _pluginCustomizedCmds.size() ; i++) + { + insertPluginCmd(pluginCmdRoot, _pluginCommands[_pluginCustomizedCmds[i]]); + } + + TiXmlNode *scitillaKeyRoot = root->FirstChild(TEXT("ScintillaKeys")); + if (scitillaKeyRoot) + root->RemoveChild(scitillaKeyRoot); + + scitillaKeyRoot = root->InsertEndChild(TiXmlElement(TEXT("ScintillaKeys"))); + for (size_t i = 0 ; i < _scintillaModifiedKeyIndices.size() ; i++) + { + insertScintKey(scitillaKeyRoot, _scintillaKeyCommands[_scintillaModifiedKeyIndices[i]]); + } + _pXmlShortcutDoc->SaveFile(); +} + +int NppParameters::addUserLangToEnd(const UserLangContainer & userLang, const TCHAR *newName) +{ + if (isExistingUserLangName(newName)) + return -1; + _userLangArray[_nbUserLang] = new UserLangContainer(); + *(_userLangArray[_nbUserLang]) = userLang; + _userLangArray[_nbUserLang]->_name = newName; + _nbUserLang++; + return _nbUserLang-1; +} + +void NppParameters::removeUserLang(int index) +{ + if (index >= _nbUserLang ) + return; + delete _userLangArray[index]; + for (int i = index ; i < (_nbUserLang - 1) ; i++) + _userLangArray[i] = _userLangArray[i+1]; + _nbUserLang--; +} + +int NppParameters::getIndexFromKeywordListName(const TCHAR *name) +{ + if (!name) return -1; + if (!lstrcmp(name, TEXT("Folder+"))) return 1; + else if (!lstrcmp(name, TEXT("Folder-"))) return 2; + else if (!lstrcmp(name, TEXT("Operators")))return 3; + else if (!lstrcmp(name, TEXT("Comment"))) return 4; + else if (!lstrcmp(name, TEXT("Words1"))) return 5; + else if (!lstrcmp(name, TEXT("Words2"))) return 6; + else if (!lstrcmp(name, TEXT("Words3"))) return 7; + else if (!lstrcmp(name, TEXT("Words4"))) return 8; + else if (!lstrcmp(name, TEXT("Delimiters"))) return 0; + else return -1; +} +void NppParameters::feedUserSettings(TiXmlNode *settingsRoot) +{ + const TCHAR *boolStr; + TiXmlNode *globalSettingNode = settingsRoot->FirstChildElement(TEXT("Global")); + if (globalSettingNode) + { + boolStr = (globalSettingNode->ToElement())->Attribute(TEXT("caseIgnored")); + if (boolStr) + _userLangArray[_nbUserLang - 1]->_isCaseIgnored = !lstrcmp(TEXT("yes"), boolStr); + } + TiXmlNode *treatAsSymbolNode = settingsRoot->FirstChildElement(TEXT("TreatAsSymbol")); + if (treatAsSymbolNode) + { + boolStr = (treatAsSymbolNode->ToElement())->Attribute(TEXT("comment")); + if (boolStr) + _userLangArray[_nbUserLang - 1]->_isCommentSymbol = !lstrcmp(TEXT("yes"), boolStr); + + boolStr = (treatAsSymbolNode->ToElement())->Attribute(TEXT("commentLine")); + if (boolStr) + _userLangArray[_nbUserLang - 1]->_isCommentLineSymbol = !lstrcmp(TEXT("yes"), boolStr); + } + TiXmlNode *prefixNode = settingsRoot->FirstChildElement(TEXT("Prefix")); + if (prefixNode) + { + TCHAR names[nbPrefixListAllowed][7] = {TEXT("words1"), TEXT("words2"), TEXT("words3"), TEXT("words4")}; + for (int i = 0 ; i < nbPrefixListAllowed ; i++) + { + boolStr = (prefixNode->ToElement())->Attribute(names[i]); + if (boolStr) + _userLangArray[_nbUserLang - 1]->_isPrefix[i] = !lstrcmp(TEXT("yes"), boolStr); + } + } +} + +void NppParameters::feedUserKeywordList(TiXmlNode *node) +{ + for (TiXmlNode *childNode = node->FirstChildElement(TEXT("Keywords")); + childNode ; + childNode = childNode->NextSibling(TEXT("Keywords"))) + { + const TCHAR *keywordsName = (childNode->ToElement())->Attribute(TEXT("name")); + int i = getIndexFromKeywordListName(keywordsName); + if (i != -1) + { + TiXmlNode *valueNode = childNode->FirstChild(); + if (valueNode) + { + const TCHAR *kwl = (valueNode)?valueNode->Value():(lstrcmp(keywordsName, TEXT("Delimiters"))?TEXT(""):TEXT("000000")); + lstrcpy(_userLangArray[_nbUserLang - 1]->_keywordLists[i], kwl); + } + } + } +} + +void NppParameters::feedUserStyles(TiXmlNode *node) +{ + for (TiXmlNode *childNode = node->FirstChildElement(TEXT("WordsStyle")); + childNode ; + childNode = childNode->NextSibling(TEXT("WordsStyle"))) + { + int id; + const TCHAR *styleIDStr = (childNode->ToElement())->Attribute(TEXT("styleID"), &id); + if (styleIDStr) + { + _userLangArray[_nbUserLang - 1]->_styleArray.addStyler(id, childNode); + } + } +} + +bool NppParameters::feedStylerArray(TiXmlNode *node) +{ + TiXmlNode *styleRoot = node->FirstChildElement(TEXT("LexerStyles")); + if (!styleRoot) return false; + + // For each lexer + for (TiXmlNode *childNode = styleRoot->FirstChildElement(TEXT("LexerType")); + childNode ; + childNode = childNode->NextSibling(TEXT("LexerType")) ) + { + if (!_lexerStylerArray.hasEnoughSpace()) return false; + + TiXmlElement *element = childNode->ToElement(); + const TCHAR *lexerName = element->Attribute(TEXT("name")); + const TCHAR *lexerDesc = element->Attribute(TEXT("desc")); + const TCHAR *lexerUserExt = element->Attribute(TEXT("ext")); + const TCHAR *lexerExcluded = element->Attribute(TEXT("excluded")); + if (lexerName) + { + _lexerStylerArray.addLexerStyler(lexerName, lexerDesc, lexerUserExt, childNode); + if (lexerExcluded != NULL && !lstrcmp(lexerExcluded, TEXT("yes"))) + { + int index = getExternalLangIndexFromName(lexerName); + if (index != -1) + _nppGUI._excludedLangList.push_back(LangMenuItem((LangType)(index + L_EXTERNAL))); + } + } + } + + // The global styles for all lexers + TiXmlNode *globalStyleRoot = node->FirstChildElement(TEXT("GlobalStyles")); + if (!globalStyleRoot) return false; + + for (TiXmlNode *childNode = globalStyleRoot->FirstChildElement(TEXT("WidgetStyle")); + childNode ; + childNode = childNode->NextSibling(TEXT("WidgetStyle")) ) + { + if (!_widgetStyleArray.hasEnoughSpace()) return false; + + TiXmlElement *element = childNode->ToElement(); + const TCHAR *styleIDStr = element->Attribute(TEXT("styleID")); + + int styleID = -1; + if ((styleID = decStrVal(styleIDStr)) != -1) + { + _widgetStyleArray.addStyler(styleID, childNode); + } + } + return true; +} + +void LexerStylerArray::addLexerStyler(const TCHAR *lexerName, const TCHAR *lexerDesc, const TCHAR *lexerUserExt , TiXmlNode *lexerNode) +{ + LexerStyler & ls = _lexerStylerArray[_nbLexerStyler++]; + ls.setLexerName(lexerName); + if (lexerDesc) + ls.setLexerDesc(lexerDesc); + + if (lexerUserExt) + ls.setLexerUserExt(lexerUserExt); + + for (TiXmlNode *childNode = lexerNode->FirstChildElement(TEXT("WordsStyle")); + childNode ; + childNode = childNode->NextSibling(TEXT("WordsStyle")) ) + { + + if (!ls.hasEnoughSpace()) return; + + TiXmlElement *element = childNode->ToElement(); + const TCHAR *styleIDStr = element->Attribute(TEXT("styleID")); + + if (styleIDStr) + { + int styleID = -1; + if ((styleID = decStrVal(styleIDStr)) != -1) + { + ls.addStyler(styleID, childNode); + } + } + } +} + +void LexerStylerArray::eraseAll() +{ + + for (int i = 0 ; i < _nbLexerStyler ; i++) + { + _lexerStylerArray[i].setNbStyler( 0 ); + } + + _nbLexerStyler = 0; +} + +void StyleArray::addStyler(int styleID, TiXmlNode *styleNode) +{ + _styleArray[_nbStyler]._styleID = styleID; + + if (styleNode) + { + TiXmlElement *element = styleNode->ToElement(); + + // Pour _fgColor, _bgColor : + // RGB() | (result & 0xFF000000) c'est pour le cas de -1 (0xFFFFFFFF) + // retourné par hexStrVal(str) + const TCHAR *str = element->Attribute(TEXT("name")); + if (str) + { + _styleArray[_nbStyler]._styleDesc = str; + } + + str = element->Attribute(TEXT("fgColor")); + if (str) + { + unsigned long result = hexStrVal(str); + _styleArray[_nbStyler]._fgColor = (RGB((result >> 16) & 0xFF, (result >> 8) & 0xFF, result & 0xFF)) | (result & 0xFF000000); + + } + + str = element->Attribute(TEXT("bgColor")); + if (str) + { + unsigned long result = hexStrVal(str); + _styleArray[_nbStyler]._bgColor = (RGB((result >> 16) & 0xFF, (result >> 8) & 0xFF, result & 0xFF)) | (result & 0xFF000000); + } + + str = element->Attribute(TEXT("colorStyle")); + if (str) + { + _styleArray[_nbStyler]._colorStyle = decStrVal(str); + } + + str = element->Attribute(TEXT("fontName")); + _styleArray[_nbStyler]._fontName = str; + + str = element->Attribute(TEXT("fontStyle")); + if (str) + { + _styleArray[_nbStyler]._fontStyle = decStrVal(str); + } + + str = element->Attribute(TEXT("fontSize")); + if (str) + { + _styleArray[_nbStyler]._fontSize = decStrVal(str); + } + + str = element->Attribute(TEXT("keywordClass")); + if (str) + { + _styleArray[_nbStyler]._keywordClass = getKwClassFromName(str); + } + + TiXmlNode *v = styleNode->FirstChild(); + if (v) + { + _styleArray[_nbStyler]._keywords = new generic_string(v->Value()); + } + } + _nbStyler++; +} + +bool NppParameters::writeHistory(const TCHAR *fullpath) +{ + TiXmlNode *nppRoot = _pXmlUserDoc->FirstChild(TEXT("NotepadPlus")); + if (!nppRoot) return false; + + TiXmlNode *historyNode = nppRoot->FirstChildElement(TEXT("History")); + if (!historyNode) return false; + + TiXmlElement recentFileNode(TEXT("File")); + (recentFileNode.ToElement())->SetAttribute(TEXT("filename"), fullpath); + + (historyNode->ToElement())->InsertEndChild(recentFileNode); + return true; +} + +TiXmlNode * NppParameters::getChildElementByAttribut(TiXmlNode *pere, const TCHAR *childName,\ + const TCHAR *attributName, const TCHAR *attributVal) const +{ + for (TiXmlNode *childNode = pere->FirstChildElement(childName); + childNode ; + childNode = childNode->NextSibling(childName)) + { + TiXmlElement *element = childNode->ToElement(); + const TCHAR *val = element->Attribute(attributName); + if (val) + { + if (!lstrcmp(val, attributVal)) + return childNode; + } + } + return NULL; +} + +// 2 restes : L_H, L_USER +LangType NppParameters::getLangIDFromStr(const TCHAR *langName) +{ + int lang = (int)L_TXT; + for(; lang < L_EXTERNAL; lang++) { + const TCHAR * name = ScintillaEditView::langNames[lang].lexerName; + if (!lstrcmp(name, langName)) { //found lang? + return (LangType)lang; + } + } + + //Cannot find language, check if its an external one + + LangType l = (LangType)lang; + if (l == L_EXTERNAL) { //try find external lexer + int id = _pSelf->getExternalLangIndexFromName(langName); + if (id != -1) return (LangType)(id + L_EXTERNAL); + } + + return L_TXT; +} + +void NppParameters::feedKeyWordsParameters(TiXmlNode *node) +{ + + TiXmlNode *langRoot = node->FirstChildElement(TEXT("Languages")); + if (!langRoot) return; + + for (TiXmlNode *langNode = langRoot->FirstChildElement(TEXT("Language")); + langNode ; + langNode = langNode->NextSibling(TEXT("Language")) ) + { + if (_nbLang < NB_LANG) + { + TiXmlElement *element = langNode->ToElement(); + const TCHAR *name = element->Attribute(TEXT("name")); + if (name) + { + _langList[_nbLang] = new Lang(getLangIDFromStr(name), name); + _langList[_nbLang]->setDefaultExtList(element->Attribute(TEXT("ext"))); + _langList[_nbLang]->setCommentLineSymbol(element->Attribute(TEXT("commentLine"))); + _langList[_nbLang]->setCommentStart(element->Attribute(TEXT("commentStart"))); + _langList[_nbLang]->setCommentEnd(element->Attribute(TEXT("commentEnd"))); + + for (TiXmlNode *kwNode = langNode->FirstChildElement(TEXT("Keywords")); + kwNode ; + kwNode = kwNode->NextSibling(TEXT("Keywords")) ) + { + const TCHAR *indexName = (kwNode->ToElement())->Attribute(TEXT("name")); + TiXmlNode *kwVal = kwNode->FirstChild(); + const TCHAR *keyWords = TEXT(""); + if ((indexName) && (kwVal)) + keyWords = kwVal->Value(); + + int i = getKwClassFromName(indexName); + + if (i >= 0 && i <= KEYWORDSET_MAX) + _langList[_nbLang]->setWords(keyWords, i); + } + _nbLang++; + } + } + } +} + +extern "C" { +typedef DWORD (WINAPI * EESFUNC) (LPCTSTR, LPTSTR, DWORD); +} + +void NppParameters::feedGUIParameters(TiXmlNode *node) +{ + TiXmlNode *GUIRoot = node->FirstChildElement(TEXT("GUIConfigs")); + if (!GUIRoot) return; + + for (TiXmlNode *childNode = GUIRoot->FirstChildElement(TEXT("GUIConfig")); + childNode ; + childNode = childNode->NextSibling(TEXT("GUIConfig")) ) + { + TiXmlElement *element = childNode->ToElement(); + const TCHAR *nm = element->Attribute(TEXT("name")); + if (!nm) continue; + + const TCHAR *val; + + if (!lstrcmp(nm, TEXT("ToolBar"))) + { + val = element->Attribute(TEXT("visible")); + if (val) + { + if (!lstrcmp(val, TEXT("no"))) + _nppGUI._toolbarShow = false; + else// if (!lstrcmp(val, TEXT("yes"))) + _nppGUI._toolbarShow = true; + } + TiXmlNode *n = childNode->FirstChild(); + if (n) + { + val = n->Value(); + if (val) + { + if (!lstrcmp(val, TEXT("small"))) + _nppGUI._toolBarStatus = TB_SMALL; + else if (!lstrcmp(val, TEXT("large"))) + _nppGUI._toolBarStatus = TB_LARGE; + else// if (!lstrcmp(val, TEXT("standard"))) //assume standard in all other cases + _nppGUI._toolBarStatus = TB_STANDARD; + } + } + } + else if (!lstrcmp(nm, TEXT("StatusBar"))) + { + TiXmlNode *n = childNode->FirstChild(); + if (n) + { + val = n->Value(); + if (val) + { + if (!lstrcmp(val, TEXT("hide"))) + _nppGUI._statusBarShow = false; + else if (!lstrcmp(val, TEXT("show"))) + _nppGUI._statusBarShow = true; + } + } + } + else if (!lstrcmp(nm, TEXT("MenuBar"))) + { + TiXmlNode *n = childNode->FirstChild(); + if (n) + { + val = n->Value(); + if (val) + { + if (!lstrcmp(val, TEXT("hide"))) + _nppGUI._menuBarShow = false; + else if (!lstrcmp(val, TEXT("show"))) + _nppGUI._menuBarShow = true; + } + } + } + else if (!lstrcmp(nm, TEXT("TabBar"))) + { + bool isFailed = false; + int oldValue = _nppGUI._tabStatus; + val = element->Attribute(TEXT("dragAndDrop")); + if (val) + { + if (!lstrcmp(val, TEXT("yes"))) + _nppGUI._tabStatus = TAB_DRAGNDROP; + else if (!lstrcmp(val, TEXT("no"))) + _nppGUI._tabStatus = 0; + else + isFailed = true; + } + + val = element->Attribute(TEXT("drawTopBar")); + if (val) + { + if (!lstrcmp(val, TEXT("yes"))) + _nppGUI._tabStatus |= TAB_DRAWTOPBAR; + else if (!lstrcmp(val, TEXT("no"))) + _nppGUI._tabStatus |= 0; + else + isFailed = true; + } + + val = element->Attribute(TEXT("drawInactiveTab")); + if (val) + { + if (!lstrcmp(val, TEXT("yes"))) + _nppGUI._tabStatus |= TAB_DRAWINACTIVETAB; + else if (!lstrcmp(val, TEXT("no"))) + _nppGUI._tabStatus |= 0; + else + isFailed = true; + } + + val = element->Attribute(TEXT("reduce")); + if (val) + { + if (!lstrcmp(val, TEXT("yes"))) + _nppGUI._tabStatus |= TAB_REDUCE; + else if (!lstrcmp(val, TEXT("no"))) + _nppGUI._tabStatus |= 0; + else + isFailed = true; + } + + val = element->Attribute(TEXT("closeButton")); + if (val) + { + if (!lstrcmp(val, TEXT("yes"))) + _nppGUI._tabStatus |= TAB_CLOSEBUTTON; + else if (!lstrcmp(val, TEXT("no"))) + _nppGUI._tabStatus |= 0; + else + isFailed = true; + } + + val = element->Attribute(TEXT("doubleClick2Close")); + if (val) + { + if (!lstrcmp(val, TEXT("yes"))) + _nppGUI._tabStatus |= TAB_DBCLK2CLOSE; + else if (!lstrcmp(val, TEXT("no"))) + _nppGUI._tabStatus |= 0; + else + isFailed = true; + } + val = element->Attribute(TEXT("vertical")); + if (val) + { + if (!lstrcmp(val, TEXT("yes"))) + _nppGUI._tabStatus |= TAB_VERTICAL; + else if (!lstrcmp(val, TEXT("no"))) + _nppGUI._tabStatus |= 0; + else + isFailed = true; + } + + val = element->Attribute(TEXT("multiLine")); + if (val) + { + if (!lstrcmp(val, TEXT("yes"))) + _nppGUI._tabStatus |= TAB_MULTILINE; + else if (!lstrcmp(val, TEXT("no"))) + _nppGUI._tabStatus |= 0; + else + isFailed = true; + } + val = element->Attribute(TEXT("hide")); + if (val) + { + if (!lstrcmp(val, TEXT("yes"))) + _nppGUI._tabStatus |= TAB_HIDE; + else if (!lstrcmp(val, TEXT("no"))) + _nppGUI._tabStatus |= 0; + else + isFailed = true; + } + if (isFailed) + _nppGUI._tabStatus = oldValue; + + + } + else if (!lstrcmp(nm, TEXT("Auto-detection"))) + { + TiXmlNode *n = childNode->FirstChild(); + if (n) + { + val = n->Value(); + if (val) + { + if (!lstrcmp(val, TEXT("yes"))) + _nppGUI._fileAutoDetection = cdEnabled; + else if (!lstrcmp(val, TEXT("auto"))) + _nppGUI._fileAutoDetection = cdAutoUpdate; + else if (!lstrcmp(val, TEXT("Update2End"))) + _nppGUI._fileAutoDetection = cdGo2end; + else if (!lstrcmp(val, TEXT("autoUpdate2End"))) + _nppGUI._fileAutoDetection = cdAutoUpdateGo2end; + else //(!lstrcmp(val, TEXT("no"))) + _nppGUI._fileAutoDetection = cdDisabled; + + _nppGUI._fileAutoDetectionOriginalValue = _nppGUI._fileAutoDetection; + } + } + } + + else if (!lstrcmp(nm, TEXT("TrayIcon"))) + { + TiXmlNode *n = childNode->FirstChild(); + if (n) + { + val = n->Value(); + if (val) + { + if (!lstrcmp(val, TEXT("yes"))) + _nppGUI._isMinimizedToTray = true; + } + } + } + else if (!lstrcmp(nm, TEXT("RememberLastSession"))) + { + TiXmlNode *n = childNode->FirstChild(); + if (n) + { + val = n->Value(); + if (val) + { + if (!lstrcmp(val, TEXT("yes"))) + _nppGUI._rememberLastSession = true; + else + _nppGUI._rememberLastSession = false; + } + } + } + + else if (!lstrcmp(nm, TEXT("MaitainIndent"))) + { + TiXmlNode *n = childNode->FirstChild(); + if (n) + { + val = n->Value(); + if (val) + { + if (!lstrcmp(val, TEXT("yes"))) + _nppGUI._maitainIndent = true; + else + _nppGUI._maitainIndent = false; + } + } + } + + else if (!lstrcmp(nm, TEXT("SmartHighLight"))) + { + TiXmlNode *n = childNode->FirstChild(); + if (n) + { + val = n->Value(); + if (val) + { + if (!lstrcmp(val, TEXT("yes"))) + _nppGUI._enableSmartHilite = true; + else + _nppGUI._enableSmartHilite = false; + } + } + } + + else if (!lstrcmp(nm, TEXT("TagsMatchHighLight"))) + { + TiXmlNode *n = childNode->FirstChild(); + if (n) + { + val = n->Value(); + if (val) + { + _nppGUI._enableTagsMatchHilite = !lstrcmp(val, TEXT("yes")); + const TCHAR *tahl = element->Attribute(TEXT("TagAttrHighLight")); + if (tahl) + _nppGUI._enableTagAttrsHilite = !lstrcmp(tahl, TEXT("yes")); + + tahl = element->Attribute(TEXT("HighLightNonHtmlZone")); + if (tahl) + _nppGUI._enableHiliteNonHTMLZone = !lstrcmp(tahl, TEXT("yes")); + } + } + } + + else if (!lstrcmp(nm, TEXT("TaskList"))) + { + TiXmlNode *n = childNode->FirstChild(); + if (n) + { + val = n->Value(); + if (val) + { + _nppGUI._doTaskList = (!lstrcmp(val, TEXT("yes")))?true:false; + } + } + } + + else if (!lstrcmp(nm, TEXT("MRU"))) + { + TiXmlNode *n = childNode->FirstChild(); + if (n) + { + val = n->Value(); + if (val) + { + _nppGUI._styleMRU = (!lstrcmp(val, TEXT("yes")))?true:false; + } + } + } + + else if (!lstrcmp(nm, TEXT("URL"))) + { + TiXmlNode *n = childNode->FirstChild(); + if (n) + { + val = n->Value(); + if (val) + { + if (!lstrcmp(val, TEXT("1"))) + _nppGUI._styleURL = 1; + else if (!lstrcmp(val, TEXT("2"))) + _nppGUI._styleURL = 2; + else + _nppGUI._styleURL = 0; + } + } + } + + else if (!lstrcmp(nm, TEXT("CheckHistoryFiles"))) + { + TiXmlNode *n = childNode->FirstChild(); + if (n) + { + val = n->Value(); + if (val) + { + if (!lstrcmp(val, TEXT("no"))) + _nppGUI._checkHistoryFiles = false; + } + } + } + else if (!lstrcmp(nm, TEXT("ScintillaViewsSplitter"))) + { + TiXmlNode *n = childNode->FirstChild(); + if (n) + { + val = n->Value(); + if (val) + { + if (!lstrcmp(val, TEXT("vertical"))) + _nppGUI._splitterPos = POS_VERTICAL; + else if (!lstrcmp(val, TEXT("horizontal"))) + _nppGUI._splitterPos = POS_HORIZOTAL; + } + } + } + else if (!lstrcmp(nm, TEXT("UserDefineDlg"))) + { + bool isFailed = false; + int oldValue = _nppGUI._userDefineDlgStatus; + + TiXmlNode *n = childNode->FirstChild(); + if (n) + { + val = n->Value(); + if (val) + { + if (!lstrcmp(val, TEXT("hide"))) + _nppGUI._userDefineDlgStatus = 0; + else if (!lstrcmp(val, TEXT("show"))) + _nppGUI._userDefineDlgStatus = UDD_SHOW; + else + isFailed = true; + } + } + val = element->Attribute(TEXT("position")); + if (val) + { + if (!lstrcmp(val, TEXT("docked"))) + _nppGUI._userDefineDlgStatus |= UDD_DOCKED; + else if (!lstrcmp(val, TEXT("undocked"))) + _nppGUI._userDefineDlgStatus |= 0; + else + isFailed = true; + } + if (isFailed) + _nppGUI._userDefineDlgStatus = oldValue; + } + else if (!lstrcmp(nm, TEXT("TabSetting"))) + { + int i; + val = element->Attribute(TEXT("size"), &i); + if (val) + _nppGUI._tabSize = i; + + if ((_nppGUI._tabSize == -1) || (_nppGUI._tabSize == 0)) + _nppGUI._tabSize = 8; + + val = element->Attribute(TEXT("replaceBySpace")); + if (val) + _nppGUI._tabReplacedBySpace = (!lstrcmp(val, TEXT("yes"))); + } + + else if (!lstrcmp(nm, TEXT("Caret"))) + { + int i; + val = element->Attribute(TEXT("width"), &i); + if (val) + _nppGUI._caretWidth = i; + + val = element->Attribute(TEXT("blinkRate"), &i); + if (val) + _nppGUI._caretBlinkRate = i; + } + + else if (!lstrcmp(nm, TEXT("AppPosition"))) + { + RECT oldRect = _nppGUI._appPos; + bool fuckUp = true; + int i; + + if (element->Attribute(TEXT("x"), &i)) + { + _nppGUI._appPos.left = i; + + if (element->Attribute(TEXT("y"), &i)) + { + _nppGUI._appPos.top = i; + + if (element->Attribute(TEXT("width"), &i)) + { + _nppGUI._appPos.right = i; + + if (element->Attribute(TEXT("height"), &i)) + { + _nppGUI._appPos.bottom = i; + fuckUp = false; + } + } + } + } + if (fuckUp) + _nppGUI._appPos = oldRect; + + + if (val = element->Attribute(TEXT("isMaximized"))) + { + _nppGUI._isMaximized = (lstrcmp(val, TEXT("yes")) == 0); + } + } + else if (!lstrcmp(nm, TEXT("NewDocDefaultSettings"))) + { + int i; + if (element->Attribute(TEXT("format"), &i)) + _nppGUI._newDocDefaultSettings._format = (formatType)i; + + if (element->Attribute(TEXT("encoding"), &i)) + _nppGUI._newDocDefaultSettings._encoding = (UniMode)i; + + if (element->Attribute(TEXT("lang"), &i)) + _nppGUI._newDocDefaultSettings._lang = (LangType)i; + + if (val = element->Attribute(TEXT("openAnsiAsUTF8"))) + _nppGUI._newDocDefaultSettings._openAnsiAsUtf8 = (lstrcmp(val, TEXT("yes")) == 0); + + } + else if (!lstrcmp(nm, TEXT("langsExcluded"))) + { + int g0 = 0; // up to 8 + int g1 = 0; // up to 16 + int g2 = 0; // up to 24 + int g3 = 0; // up to 32 + int g4 = 0; // up to 40 + int g5 = 0; // up to 48 + int g6 = 0; // up to 56 + int g7 = 0; // up to 64 + const int nbMax = 64; + + int i; + if (element->Attribute(TEXT("gr0"), &i)) + if (i <= 255) + g0 = i; + if (element->Attribute(TEXT("gr1"), &i)) + if (i <= 255) + g1 = i; + if (element->Attribute(TEXT("gr2"), &i)) + if (i <= 255) + g2 = i; + if (element->Attribute(TEXT("gr3"), &i)) + if (i <= 255) + g3 = i; + if (element->Attribute(TEXT("gr4"), &i)) + if (i <= 255) + g4 = i; + if (element->Attribute(TEXT("gr5"), &i)) + if (i <= 255) + g5 = i; + if (element->Attribute(TEXT("gr6"), &i)) + if (i <= 255) + g6 = i; + if (element->Attribute(TEXT("gr7"), &i)) + if (i <= 255) + g7 = i; + + bool langArray[nbMax]; + for (int i = 0 ; i < nbMax ; i++) langArray[i] = false; + + UCHAR mask = 1; + for (int i = 0 ; i < 8 ; i++) + { + if (mask & g0) + _nppGUI._excludedLangList.push_back(LangMenuItem((LangType)i)); + mask <<= 1; + } + + mask = 1; + for (int i = 8 ; i < 16 ; i++) + { + if (mask & g1) + _nppGUI._excludedLangList.push_back(LangMenuItem((LangType)i)); + mask <<= 1; + } + + mask = 1; + for (int i = 16 ; i < 24 ; i++) + { + if (mask & g2) + _nppGUI._excludedLangList.push_back(LangMenuItem((LangType)i)); + mask <<= 1; + } + + mask = 1; + for (int i = 24 ; i < 32 ; i++) + { + if (mask & g3) + _nppGUI._excludedLangList.push_back(LangMenuItem((LangType)i)); + mask <<= 1; + } + + mask = 1; + for (int i = 32 ; i < 40 ; i++) + { + if (mask & g4) + _nppGUI._excludedLangList.push_back(LangMenuItem((LangType)i)); + mask <<= 1; + } + + mask = 1; + for (int i = 40 ; i < 48 ; i++) + { + if (mask & g5) + _nppGUI._excludedLangList.push_back(LangMenuItem((LangType)i)); + mask <<= 1; + } + + mask = 1; + for (int i = 48 ; i < 56 ; i++) + { + if (mask & g6) + _nppGUI._excludedLangList.push_back(LangMenuItem((LangType)i)); + mask <<= 1; + } + + mask = 1; + for (int i = 56 ; i < 64 ; i++) + { + if (mask & g7) + _nppGUI._excludedLangList.push_back(LangMenuItem((LangType)i)); + mask <<= 1; + } + + val = element->Attribute(TEXT("langMenuCompact")); + if (val) + _nppGUI._isLangMenuCompact = (!lstrcmp(val, TEXT("yes"))); + } + + else if (!lstrcmp(nm, TEXT("Print"))) + { + val = element->Attribute(TEXT("lineNumber")); + if (val) + _nppGUI._printSettings._printLineNumber = (!lstrcmp(val, TEXT("yes"))); + + int i; + if (element->Attribute(TEXT("printOption"), &i)) + _nppGUI._printSettings._printOption = i; + + val = element->Attribute(TEXT("headerLeft")); + if (val) + _nppGUI._printSettings._headerLeft = val; + + val = element->Attribute(TEXT("headerMiddle")); + if (val) + _nppGUI._printSettings._headerMiddle = val; + + val = element->Attribute(TEXT("headerRight")); + if (val) + _nppGUI._printSettings._headerRight = val; + + + val = element->Attribute(TEXT("footerLeft")); + if (val) + _nppGUI._printSettings._footerLeft = val; + + val = element->Attribute(TEXT("footerMiddle")); + if (val) + _nppGUI._printSettings._footerMiddle = val; + + val = element->Attribute(TEXT("footerRight")); + if (val) + _nppGUI._printSettings._footerRight = val; + + + val = element->Attribute(TEXT("headerFontName")); + if (val) + _nppGUI._printSettings._headerFontName = val; + + val = element->Attribute(TEXT("footerFontName")); + if (val) + _nppGUI._printSettings._footerFontName = val; + + if (element->Attribute(TEXT("headerFontStyle"), &i)) + _nppGUI._printSettings._headerFontStyle = i; + + if (element->Attribute(TEXT("footerFontStyle"), &i)) + _nppGUI._printSettings._footerFontStyle = i; + + if (element->Attribute(TEXT("headerFontSize"), &i)) + _nppGUI._printSettings._headerFontSize = i; + + if (element->Attribute(TEXT("footerFontSize"), &i)) + _nppGUI._printSettings._footerFontSize = i; + + + if (element->Attribute(TEXT("margeLeft"), &i)) + _nppGUI._printSettings._marge.left = i; + + if (element->Attribute(TEXT("margeTop"), &i)) + _nppGUI._printSettings._marge.top = i; + + if (element->Attribute(TEXT("margeRight"), &i)) + _nppGUI._printSettings._marge.right = i; + + if (element->Attribute(TEXT("margeBottom"), &i)) + _nppGUI._printSettings._marge.bottom = i; + } + + else if (!lstrcmp(nm, TEXT("ScintillaPrimaryView"))) + { + feedScintillaParam(SCIV_PRIMARY, element); + } + else if (!lstrcmp(nm, TEXT("ScintillaSecondaryView"))) + { + feedScintillaParam(SCIV_SECOND, element); + } + else if (!lstrcmp(nm, TEXT("Backup"))) + { + int i; + if (element->Attribute(TEXT("action"), &i)) + _nppGUI._backup = (BackupFeature)i; + + const TCHAR *bDir = element->Attribute(TEXT("useCustumDir")); + if (bDir && !lstrcmp(bDir, TEXT("yes"))) + { + _nppGUI._useDir = true; + } + const TCHAR *pDir = element->Attribute(TEXT("dir")); + if (pDir) + lstrcpy(_nppGUI._backupDir, pDir); + } + else if (!lstrcmp(nm, TEXT("DockingManager"))) + { + feedDockingManager(element); + } + + else if (!lstrcmp(nm, TEXT("globalOverride"))) + { + const TCHAR *bDir = element->Attribute(TEXT("fg")); + if (bDir && !lstrcmp(bDir, TEXT("yes"))) + { + _nppGUI._globalOverride.enableFg = true; + } + + bDir = element->Attribute(TEXT("bg")); + if (bDir && !lstrcmp(bDir, TEXT("yes"))) + { + _nppGUI._globalOverride.enableBg = true; + } + + bDir = element->Attribute(TEXT("font")); + if (bDir && !lstrcmp(bDir, TEXT("yes"))) + { + _nppGUI._globalOverride.enableFont = true; + } + + bDir = element->Attribute(TEXT("fontSize")); + if (bDir && !lstrcmp(bDir, TEXT("yes"))) + { + _nppGUI._globalOverride.enableFontSize = true; + } + + bDir = element->Attribute(TEXT("bold")); + if (bDir && !lstrcmp(bDir, TEXT("yes"))) + { + _nppGUI._globalOverride.enableBold = true; + } + + bDir = element->Attribute(TEXT("italic")); + if (bDir && !lstrcmp(bDir, TEXT("yes"))) + { + _nppGUI._globalOverride.enableItalic = true; + } + + bDir = element->Attribute(TEXT("underline")); + if (bDir && !lstrcmp(bDir, TEXT("yes"))) + { + _nppGUI._globalOverride.enableUnderLine = true; + } + } + else if (!lstrcmp(nm, TEXT("auto-completion"))) + { + int i; + if (element->Attribute(TEXT("autoCAction"), &i)) + _nppGUI._autocStatus = (NppGUI::AutocStatus)i; + + if (element->Attribute(TEXT("triggerFromNbChar"), &i)) + _nppGUI._autocFromLen = i; + + const TCHAR * funcParams = element->Attribute(TEXT("funcParams")); + if (funcParams && !lstrcmp(funcParams, TEXT("yes"))) + { + _nppGUI._funcParams = true; + } + } + else if (!lstrcmp(nm, TEXT("sessionExt"))) + { + TiXmlNode *n = childNode->FirstChild(); + if (n) + { + val = n->Value(); + if (val) + _nppGUI._definedSessionExt = val; + } + } + else if (!lstrcmp(nm, TEXT("noUpdate"))) + { + TiXmlNode *n = childNode->FirstChild(); + if (n) + { + val = n->Value(); + if (val) + { + _nppGUI._neverUpdate = (!lstrcmp(val, TEXT("yes")))?true:false; + } + } + } + else if (!lstrcmp(nm, TEXT("openSaveDir"))) + { + const TCHAR * value = element->Attribute(TEXT("value")); + if (value && value[0]) + { + if (lstrcmp(value, TEXT("1")) == 0) + _nppGUI._openSaveDir = dir_last; + else if (lstrcmp(value, TEXT("2")) == 0) + _nppGUI._openSaveDir = dir_userDef; + else + _nppGUI._openSaveDir = dir_followCurrent; + } + const TCHAR * path = element->Attribute(TEXT("defaultDirPath")); + if (path && path[0]) + { + lstrcpyn(_nppGUI._defaultDir, path, MAX_PATH); + ::ExpandEnvironmentStrings(_nppGUI._defaultDir, _nppGUI._defaultDirExp, 500); + } + } + else if (!lstrcmp(nm, TEXT("titleBar"))) + { + const TCHAR * value = element->Attribute(TEXT("short")); + _nppGUI._shortTitlebar = false; //default state + if (value && value[0]) + { + if (lstrcmp(value, TEXT("yes")) == 0) + _nppGUI._shortTitlebar = true; + else if (lstrcmp(value, TEXT("no")) == 0) + _nppGUI._shortTitlebar = false; + } + } + else if (!lstrcmp(nm, TEXT("stylerTheme"))) + { + const TCHAR *themePath = element->Attribute(TEXT("path")); + if (themePath != NULL && themePath != TEXT("")) + _nppGUI._themeName.assign(themePath); + } + } +} + +void NppParameters::feedScintillaParam(bool whichOne, TiXmlNode *node) +{ + TiXmlElement *element = node->ToElement(); + + // Line Number Margin + const TCHAR *nm = element->Attribute(TEXT("lineNumberMargin")); + if (nm) + { + if (!lstrcmp(nm, TEXT("show"))) + _svp[whichOne]._lineNumberMarginShow = true; + else if (!lstrcmp(nm, TEXT("hide"))) + _svp[whichOne]._lineNumberMarginShow = false; + } + + // Bookmark Margin + nm = element->Attribute(TEXT("bookMarkMargin")); + if (nm) + { + + if (!lstrcmp(nm, TEXT("show"))) + _svp[whichOne]._bookMarkMarginShow = true; + else if (!lstrcmp(nm, TEXT("hide"))) + _svp[whichOne]._bookMarkMarginShow = false; + } +/* + // doc change state Margin + nm = element->Attribute(TEXT("docChangeStateMargin")); + if (nm) + { + + if (!lstrcmp(nm, TEXT("show"))) + _svp[whichOne]._docChangeStateMarginShow = true; + else if (!lstrcmp(nm, TEXT("hide"))) + _svp[whichOne]._docChangeStateMarginShow = false; + } +*/ + // Indent GuideLine + nm = element->Attribute(TEXT("indentGuideLine")); + if (nm) + { + if (!lstrcmp(nm, TEXT("show"))) + _svp[whichOne]._indentGuideLineShow = true; + else if (!lstrcmp(nm, TEXT("hide"))) + _svp[whichOne]._indentGuideLineShow= false; + } + + // Folder Mark Style + nm = element->Attribute(TEXT("folderMarkStyle")); + if (nm) + { + if (!lstrcmp(nm, TEXT("box"))) + _svp[whichOne]._folderStyle = FOLDER_STYLE_BOX; + else if (!lstrcmp(nm, TEXT("circle"))) + _svp[whichOne]._folderStyle = FOLDER_STYLE_CIRCLE; + else if (!lstrcmp(nm, TEXT("arrow"))) + _svp[whichOne]._folderStyle = FOLDER_STYLE_ARROW; + else if (!lstrcmp(nm, TEXT("simple"))) + _svp[whichOne]._folderStyle = FOLDER_STYLE_SIMPLE; + } + + // Current Line Highlighting State + nm = element->Attribute(TEXT("currentLineHilitingShow")); + if (nm) + { + if (!lstrcmp(nm, TEXT("show"))) + _svp[whichOne]._currentLineHilitingShow = true; + else if (!lstrcmp(nm, TEXT("hide"))) + _svp[whichOne]._currentLineHilitingShow = false; + } + + // Current wrap symbol visibility State + nm = element->Attribute(TEXT("wrapSymbolShow")); + if (nm) + { + if (!lstrcmp(nm, TEXT("show"))) + _svp[whichOne]._wrapSymbolShow = true; + else if (!lstrcmp(nm, TEXT("hide"))) + _svp[whichOne]._wrapSymbolShow = false; + } + + // Do Wrap + nm = element->Attribute(TEXT("Wrap")); + if (nm) + { + if (!lstrcmp(nm, TEXT("yes"))) + _svp[whichOne]._doWrap = true; + else if (!lstrcmp(nm, TEXT("no"))) + _svp[whichOne]._doWrap = false; + } + + // Do Edge + nm = element->Attribute(TEXT("edge")); + if (nm) + { + if (!lstrcmp(nm, TEXT("background"))) + _svp[whichOne]._edgeMode = EDGE_BACKGROUND; + else if (!lstrcmp(nm, TEXT("line"))) + _svp[whichOne]._edgeMode = EDGE_LINE; + else + _svp[whichOne]._edgeMode = EDGE_NONE; + } + + int val; + nm = element->Attribute(TEXT("edgeNbColumn"), &val); + if (nm) + { + _svp[whichOne]._edgeNbColumn = val; + } + + nm = element->Attribute(TEXT("zoom"), &val); + if (nm) + { + _svp[whichOne]._zoom = val; + } + + // White Space visibility State + nm = element->Attribute(TEXT("whiteSpaceShow")); + if (nm) + { + if (!lstrcmp(nm, TEXT("show"))) + _svp[whichOne]._whiteSpaceShow = true; + else if (!lstrcmp(nm, TEXT("hide"))) + _svp[whichOne]._whiteSpaceShow = false; + } + + // EOL visibility State + nm = element->Attribute(TEXT("eolShow")); + if (nm) + { + if (!lstrcmp(nm, TEXT("show"))) + _svp[whichOne]._eolShow = true; + else if (!lstrcmp(nm, TEXT("hide"))) + _svp[whichOne]._eolShow = false; + } +} + + +void NppParameters::feedDockingManager(TiXmlNode *node) +{ + TiXmlElement *element = node->ToElement(); + + int i; + if (element->Attribute(TEXT("leftWidth"), &i)) + _nppGUI._dockingData._leftWidth = i; + + if (element->Attribute(TEXT("rightWidth"), &i)) + _nppGUI._dockingData._rightWidth = i; + + if (element->Attribute(TEXT("topHeight"), &i)) + _nppGUI._dockingData._topHeight = i; + + if (element->Attribute(TEXT("bottomHeight"), &i)) + _nppGUI._dockingData._bottomHight = i; + + + + for (TiXmlNode *childNode = node->FirstChildElement(TEXT("FloatingWindow")); + childNode ; + childNode = childNode->NextSibling(TEXT("FloatingWindow")) ) + { + TiXmlElement *floatElement = childNode->ToElement(); + int cont; + if (floatElement->Attribute(TEXT("cont"), &cont)) + { + int x = 0; + int y = 0; + int w = 100; + int h = 100; + + floatElement->Attribute(TEXT("x"), &x); + floatElement->Attribute(TEXT("y"), &y); + floatElement->Attribute(TEXT("width"), &w); + floatElement->Attribute(TEXT("height"), &h); + _nppGUI._dockingData._flaotingWindowInfo.push_back(FloatingWindowInfo(cont, x, y, w, h)); + } + } + + for (TiXmlNode *childNode = node->FirstChildElement(TEXT("PluginDlg")); + childNode ; + childNode = childNode->NextSibling(TEXT("PluginDlg")) ) + { + TiXmlElement *dlgElement = childNode->ToElement(); + const TCHAR *name = dlgElement->Attribute(TEXT("pluginName")); + + int id; + const TCHAR *idStr = dlgElement->Attribute(TEXT("id"), &id); + if (name && idStr) + { + int curr = 0; // on left + int prev = 0; // on left + + dlgElement->Attribute(TEXT("curr"), &curr); + dlgElement->Attribute(TEXT("prev"), &prev); + + bool isVisible = false; + const TCHAR *val = NULL; + if (val = dlgElement->Attribute(TEXT("isVisible"))) + { + isVisible = (lstrcmp(val, TEXT("yes")) == 0); + } + + _nppGUI._dockingData._pluginDockInfo.push_back(PlugingDlgDockingInfo(name, id, curr, prev, isVisible)); + } + } + + for (TiXmlNode *childNode = node->FirstChildElement(TEXT("ActiveTabs")); + childNode ; + childNode = childNode->NextSibling(TEXT("ActiveTabs")) ) + { + TiXmlElement *dlgElement = childNode->ToElement(); + + int cont; + if (dlgElement->Attribute(TEXT("cont"), &cont)) + { + int activeTab = 0; + dlgElement->Attribute(TEXT("activeTab"), &activeTab); + _nppGUI._dockingData._containerTabInfo.push_back(ContainerTabInfo(cont, activeTab)); + } + } +} + +bool NppParameters::writeScintillaParams(const ScintillaViewParams & svp, bool whichOne) +{ + if (!_pXmlUserDoc) return false; + + const TCHAR *pViewName = (whichOne == SCIV_PRIMARY)?TEXT("ScintillaPrimaryView"):TEXT("ScintillaSecondaryView"); + TiXmlNode *nppRoot = _pXmlUserDoc->FirstChild(TEXT("NotepadPlus")); + if (!nppRoot) return false; + + TiXmlNode *configsRoot = nppRoot->FirstChildElement(TEXT("GUIConfigs")); + if (!configsRoot) return false; + + TiXmlNode *scintNode = getChildElementByAttribut(configsRoot, TEXT("GUIConfig"), TEXT("name"), pViewName); + if (!scintNode) return false; + + (scintNode->ToElement())->SetAttribute(TEXT("lineNumberMargin"), svp._lineNumberMarginShow?TEXT("show"):TEXT("hide")); + (scintNode->ToElement())->SetAttribute(TEXT("bookMarkMargin"), svp._bookMarkMarginShow?TEXT("show"):TEXT("hide")); + //(scintNode->ToElement())->SetAttribute(TEXT("docChangeStateMargin"), svp._docChangeStateMarginShow?TEXT("show"):TEXT("hide")); + (scintNode->ToElement())->SetAttribute(TEXT("indentGuideLine"), svp._indentGuideLineShow?TEXT("show"):TEXT("hide")); + const TCHAR *pFolderStyleStr = (svp._folderStyle == FOLDER_STYLE_SIMPLE)?TEXT("simple"): + (svp._folderStyle == FOLDER_STYLE_ARROW)?TEXT("arrow"): + (svp._folderStyle == FOLDER_STYLE_CIRCLE)?TEXT("circle"):TEXT("box"); + (scintNode->ToElement())->SetAttribute(TEXT("folderMarkStyle"), pFolderStyleStr); + (scintNode->ToElement())->SetAttribute(TEXT("currentLineHilitingShow"), svp._currentLineHilitingShow?TEXT("show"):TEXT("hide")); + (scintNode->ToElement())->SetAttribute(TEXT("wrapSymbolShow"), svp._wrapSymbolShow?TEXT("show"):TEXT("hide")); + (scintNode->ToElement())->SetAttribute(TEXT("Wrap"), svp._doWrap?TEXT("yes"):TEXT("no")); + TCHAR *edgeStr = NULL; + if (svp._edgeMode == EDGE_NONE) + edgeStr = TEXT("no"); + else if (svp._edgeMode == EDGE_LINE) + edgeStr = TEXT("line"); + else + edgeStr = TEXT("background"); + (scintNode->ToElement())->SetAttribute(TEXT("edge"), edgeStr); + (scintNode->ToElement())->SetAttribute(TEXT("edgeNbColumn"), svp._edgeNbColumn); + (scintNode->ToElement())->SetAttribute(TEXT("zoom"), svp._zoom); + (scintNode->ToElement())->SetAttribute(TEXT("whiteSpaceShow"), svp._whiteSpaceShow?TEXT("show"):TEXT("hide")); + (scintNode->ToElement())->SetAttribute(TEXT("eolShow"), svp._eolShow?TEXT("show"):TEXT("hide")); + + return true; +} + +bool NppParameters::writeGUIParams() +{ + if (!_pXmlUserDoc) return false; + + TiXmlNode *nppRoot = _pXmlUserDoc->FirstChild(TEXT("NotepadPlus")); + if (!nppRoot) return false; + + TiXmlNode *GUIRoot = nppRoot->FirstChildElement(TEXT("GUIConfigs")); + if (!GUIRoot) return false; + + bool autoDetectionExist = false; + bool checkHistoryFilesExist = false; + bool trayIconExist = false; + bool rememberLastSessionExist = false; + bool newDocDefaultSettingsExist = false; + bool langsExcludedLstExist = false; + bool printSettingExist = false; + bool doTaskListExist = false; + bool maitainIndentExist = false; + bool MRUExist = false; + bool backExist = false; + bool saveOpenFileInSameDirExist = false; + bool URLExist = false; + bool globalOverrideExist = false; + bool autocExist = false; + bool sessionExtExist = false; + bool noUpdateExist = false; + bool menuBarExist = false; + bool smartHighLightExist = false; + bool tagsMatchHighLightExist = false; + bool caretExist = false; + bool openSaveDirExist = false; + bool titleBarExist = false; + bool stylerThemeExist = false; + + TiXmlNode *dockingParamNode = NULL; + + for (TiXmlNode *childNode = GUIRoot->FirstChildElement(TEXT("GUIConfig")); + childNode ; + childNode = childNode->NextSibling(TEXT("GUIConfig"))) + { + TiXmlElement *element = childNode->ToElement(); + const TCHAR *nm = element->Attribute(TEXT("name")); + if (!nm) continue; + + if (!lstrcmp(nm, TEXT("ToolBar"))) + { + const TCHAR *pStr = (_nppGUI._toolbarShow)?TEXT("yes"):TEXT("no"); + element->SetAttribute(TEXT("visible"), pStr); + + pStr = _nppGUI._toolBarStatus == TB_SMALL?TEXT("small"):(_nppGUI._toolBarStatus == TB_STANDARD?TEXT("standard"):TEXT("large")); + TiXmlNode *n = childNode->FirstChild(); + if (n) + n->SetValue(pStr); + else + childNode->InsertEndChild(TiXmlText(pStr)); + } + else if (!lstrcmp(nm, TEXT("StatusBar"))) + { + const TCHAR *pStr = _nppGUI._statusBarShow?TEXT("show"):TEXT("hide"); + TiXmlNode *n = childNode->FirstChild(); + if (n) + n->SetValue(pStr); + else + childNode->InsertEndChild(TiXmlText(pStr)); + } + else if (!lstrcmp(nm, TEXT("MenuBar"))) + { + const TCHAR *pStr = _nppGUI._menuBarShow?TEXT("show"):TEXT("hide"); + TiXmlNode *n = childNode->FirstChild(); + if (n) + n->SetValue(pStr); + else + childNode->InsertEndChild(TiXmlText(pStr)); + + menuBarExist = true; + } + else if (!lstrcmp(nm, TEXT("TabBar"))) + { + const TCHAR *pStr = (_nppGUI._tabStatus & TAB_DRAWTOPBAR)?TEXT("yes"):TEXT("no"); + element->SetAttribute(TEXT("dragAndDrop"), pStr); + + pStr = (_nppGUI._tabStatus & TAB_DRAGNDROP)?TEXT("yes"):TEXT("no"); + element->SetAttribute(TEXT("drawTopBar"), pStr); + + pStr = (_nppGUI._tabStatus & TAB_DRAWINACTIVETAB)?TEXT("yes"):TEXT("no"); + element->SetAttribute(TEXT("drawInactiveTab"), pStr); + + pStr = (_nppGUI._tabStatus & TAB_REDUCE)?TEXT("yes"):TEXT("no"); + element->SetAttribute(TEXT("reduce"), pStr); + + pStr = (_nppGUI._tabStatus & TAB_CLOSEBUTTON)?TEXT("yes"):TEXT("no"); + element->SetAttribute(TEXT("closeButton"), pStr); + + pStr = (_nppGUI._tabStatus & TAB_DBCLK2CLOSE)?TEXT("yes"):TEXT("no"); + element->SetAttribute(TEXT("doubleClick2Close"), pStr); + + pStr = (_nppGUI._tabStatus & TAB_VERTICAL)?TEXT("yes"):TEXT("no"); + element->SetAttribute(TEXT("vertical"), pStr); + + pStr = (_nppGUI._tabStatus & TAB_MULTILINE)?TEXT("yes"):TEXT("no"); + element->SetAttribute(TEXT("multiLine"), pStr); + + pStr = (_nppGUI._tabStatus & TAB_HIDE)?TEXT("yes"):TEXT("no"); + element->SetAttribute(TEXT("hide"), pStr); + + } + else if (!lstrcmp(nm, TEXT("ScintillaViewsSplitter"))) + { + const TCHAR *pStr = _nppGUI._splitterPos == POS_VERTICAL?TEXT("vertical"):TEXT("horizontal"); + TiXmlNode *n = childNode->FirstChild(); + if (n) + n->SetValue(pStr); + else + childNode->InsertEndChild(TiXmlText(pStr)); + } + else if (!lstrcmp(nm, TEXT("UserDefineDlg"))) + { + const TCHAR *pStr = _nppGUI._userDefineDlgStatus & UDD_SHOW?TEXT("show"):TEXT("hide"); + TiXmlNode *n = childNode->FirstChild(); + if (n) + n->SetValue(pStr); + else + childNode->InsertEndChild(TiXmlText(pStr)); + + pStr = (_nppGUI._userDefineDlgStatus & UDD_DOCKED)?TEXT("docked"):TEXT("undocked"); + element->SetAttribute(TEXT("position"), pStr); + } + else if (!lstrcmp(nm, TEXT("TabSetting"))) + { + const TCHAR *pStr = _nppGUI._tabReplacedBySpace?TEXT("yes"):TEXT("no"); + element->SetAttribute(TEXT("replaceBySpace"), pStr); + element->SetAttribute(TEXT("size"), _nppGUI._tabSize); + } + else if (!lstrcmp(nm, TEXT("Caret"))) + { + caretExist = true; + element->SetAttribute(TEXT("width"), _nppGUI._caretWidth); + element->SetAttribute(TEXT("blinkRate"), _nppGUI._caretBlinkRate); + } + else if (!lstrcmp(nm, TEXT("Auto-detection"))) + { + autoDetectionExist = true; + const TCHAR *pStr = TEXT("no"); + switch (_nppGUI._fileAutoDetection) + { + case cdEnabled: + pStr = TEXT("yes"); + break; + case cdAutoUpdate: + pStr = TEXT("auto"); + break; + case cdGo2end: + pStr = TEXT("Update2End"); + break; + case cdAutoUpdateGo2end: + pStr = TEXT("autoUpdate2End"); + break; + } + TiXmlNode *n = childNode->FirstChild(); + if (n) + n->SetValue(pStr); + else + childNode->InsertEndChild(TiXmlText(pStr)); + } + else if (!lstrcmp(nm, TEXT("TrayIcon"))) + { + trayIconExist = true; + const TCHAR *pStr = _nppGUI._isMinimizedToTray?TEXT("yes"):TEXT("no"); + TiXmlNode *n = childNode->FirstChild(); + if (n) + n->SetValue(pStr); + else + childNode->InsertEndChild(TiXmlText(pStr)); + } + else if (!lstrcmp(nm, TEXT("RememberLastSession"))) + { + rememberLastSessionExist = true; + const TCHAR *pStr = _nppGUI._rememberLastSession?TEXT("yes"):TEXT("no"); + TiXmlNode *n = childNode->FirstChild(); + if (n) + n->SetValue(pStr); + else + childNode->InsertEndChild(TiXmlText(pStr)); + } + + else if (!lstrcmp(nm, TEXT("MaitainIndent"))) + { + maitainIndentExist = true; + const TCHAR *pStr = _nppGUI._maitainIndent?TEXT("yes"):TEXT("no"); + TiXmlNode *n = childNode->FirstChild(); + if (n) + n->SetValue(pStr); + else + childNode->InsertEndChild(TiXmlText(pStr)); + } + else if (!lstrcmp(nm, TEXT("SmartHighLight"))) + { + smartHighLightExist = true; + const TCHAR *pStr = _nppGUI._enableSmartHilite?TEXT("yes"):TEXT("no"); + TiXmlNode *n = childNode->FirstChild(); + if (n) + n->SetValue(pStr); + else + childNode->InsertEndChild(TiXmlText(pStr)); + } + + else if (!lstrcmp(nm, TEXT("TagsMatchHighLight"))) + { + tagsMatchHighLightExist = true; + const TCHAR *pStr = _nppGUI._enableTagsMatchHilite?TEXT("yes"):TEXT("no"); + TiXmlNode *n = childNode->FirstChild(); + if (n) + n->SetValue(pStr); + else + childNode->InsertEndChild(TiXmlText(pStr)); + + (childNode->ToElement())->SetAttribute(TEXT("TagAttrHighLight"), _nppGUI._enableTagAttrsHilite?TEXT("yes"):TEXT("no")); + (childNode->ToElement())->SetAttribute(TEXT("HighLightNonHtmlZone"), _nppGUI._enableHiliteNonHTMLZone?TEXT("yes"):TEXT("no")); + } + + else if (!lstrcmp(nm, TEXT("TaskList"))) + { + doTaskListExist = true; + const TCHAR *pStr = _nppGUI._doTaskList?TEXT("yes"):TEXT("no"); + + TiXmlNode *n = childNode->FirstChild(); + if (n) + n->SetValue(pStr); + else + childNode->InsertEndChild(TiXmlText(pStr)); + } + else if (!lstrcmp(nm, TEXT("CheckHistoryFiles"))) + { + checkHistoryFilesExist = true; + const TCHAR *pStr = _nppGUI._checkHistoryFiles?TEXT("yes"):TEXT("no"); + + TiXmlNode *n = childNode->FirstChild(); + if (n) + n->SetValue(pStr); + else + childNode->InsertEndChild(TiXmlText(pStr)); + } + else if (!lstrcmp(nm, TEXT("AppPosition"))) + { + element->SetAttribute(TEXT("x"), _nppGUI._appPos.left); + element->SetAttribute(TEXT("y"), _nppGUI._appPos.top); + element->SetAttribute(TEXT("width"), _nppGUI._appPos.right); + element->SetAttribute(TEXT("height"), _nppGUI._appPos.bottom); + element->SetAttribute(TEXT("isMaximized"), _nppGUI._isMaximized?TEXT("yes"):TEXT("no")); + } + else if (!lstrcmp(nm, TEXT("NewDocDefaultSettings"))) + { + element->SetAttribute(TEXT("format"), _nppGUI._newDocDefaultSettings._format); + element->SetAttribute(TEXT("encoding"), _nppGUI._newDocDefaultSettings._encoding); + element->SetAttribute(TEXT("lang"), _nppGUI._newDocDefaultSettings._lang); + element->SetAttribute(TEXT("openAnsiAsUTF8"), _nppGUI._newDocDefaultSettings._openAnsiAsUtf8?TEXT("yes"):TEXT("no")); + newDocDefaultSettingsExist = true; + } + else if (!lstrcmp(nm, TEXT("langsExcluded"))) + { + writeExcludedLangList(element); + element->SetAttribute(TEXT("langMenuCompact"), _nppGUI._isLangMenuCompact?TEXT("yes"):TEXT("no")); + langsExcludedLstExist = true; + } + else if (!lstrcmp(nm, TEXT("Print"))) + { + writePrintSetting(element); + printSettingExist = true; + } + else if (!lstrcmp(nm, TEXT("Backup"))) + { + element->SetAttribute(TEXT("action"), _nppGUI._backup); + element->SetAttribute(TEXT("useCustumDir"), _nppGUI._useDir?TEXT("yes"):TEXT("no")); + element->SetAttribute(TEXT("dir"), _nppGUI._backupDir); + backExist = true; + } + else if (!lstrcmp(nm, TEXT("MRU"))) + { + MRUExist = true; + const TCHAR *pStr = _nppGUI._styleMRU?TEXT("yes"):TEXT("no"); + + TiXmlNode *n = childNode->FirstChild(); + if (n) + n->SetValue(pStr); + else + childNode->InsertEndChild(TiXmlText(pStr)); + } + else if (!lstrcmp(nm, TEXT("URL"))) + { + URLExist = true; + const TCHAR *pStr = TEXT("0"); + if (_nppGUI._styleURL == 1) + pStr = TEXT("1"); + else if (_nppGUI._styleURL == 2) + pStr = TEXT("2"); + + TiXmlNode *n = childNode->FirstChild(); + if (n) + n->SetValue(pStr); + else + childNode->InsertEndChild(TiXmlText(pStr)); + } + else if (!lstrcmp(nm, TEXT("DockingManager"))) + { + dockingParamNode = childNode; + } + else if (!lstrcmp(nm, TEXT("globalOverride"))) + { + globalOverrideExist = true; + const TCHAR *pStr = _nppGUI._globalOverride.enableFg?TEXT("yes"):TEXT("no"); + element->SetAttribute(TEXT("fg"), pStr); + + pStr = (_nppGUI._globalOverride.enableBg)?TEXT("yes"):TEXT("no"); + element->SetAttribute(TEXT("bg"), pStr); + + pStr = _nppGUI._globalOverride.enableFont?TEXT("yes"):TEXT("no"); + element->SetAttribute(TEXT("font"), pStr); + + pStr = _nppGUI._globalOverride.enableFontSize?TEXT("yes"):TEXT("no"); + element->SetAttribute(TEXT("fontSize"), pStr); + + pStr = _nppGUI._globalOverride.enableBold?TEXT("yes"):TEXT("no"); + element->SetAttribute(TEXT("bold"), pStr); + + pStr = _nppGUI._globalOverride.enableItalic?TEXT("yes"):TEXT("no"); + element->SetAttribute(TEXT("italic"), pStr); + + pStr = _nppGUI._globalOverride.enableUnderLine?TEXT("yes"):TEXT("no"); + element->SetAttribute(TEXT("underline"), pStr); + } + else if (!lstrcmp(nm, TEXT("auto-completion"))) + { + autocExist = true; + element->SetAttribute(TEXT("autoCAction"), _nppGUI._autocStatus); + element->SetAttribute(TEXT("triggerFromNbChar"), _nppGUI._autocFromLen); + const TCHAR * pStr = _nppGUI._funcParams?TEXT("yes"):TEXT("no"); + element->SetAttribute(TEXT("funcParams"), pStr); + } + else if (!lstrcmp(nm, TEXT("sessionExt"))) + { + sessionExtExist = true; + TiXmlNode *n = childNode->FirstChild(); + if (n) + n->SetValue(_nppGUI._definedSessionExt.c_str()); + else + childNode->InsertEndChild(TiXmlText(_nppGUI._definedSessionExt.c_str())); + } + else if (!lstrcmp(nm, TEXT("noUpdate"))) + { + noUpdateExist = true; + const TCHAR *pStr = _nppGUI._neverUpdate?TEXT("yes"):TEXT("no"); + + TiXmlNode *n = childNode->FirstChild(); + if (n) + n->SetValue(pStr); + else + childNode->InsertEndChild(TiXmlText(pStr)); + } + else if (!lstrcmp(nm, TEXT("openSaveDir"))) + { + openSaveDirExist = true; + element->SetAttribute(TEXT("value"), _nppGUI._openSaveDir); + element->SetAttribute(TEXT("defaultDirPath"), _nppGUI._defaultDir); + } + else if (!lstrcmp(nm, TEXT("titleBar"))) + { + titleBarExist = true; + const TCHAR *pStr = (_nppGUI._shortTitlebar)?TEXT("yes"):TEXT("no"); + element->SetAttribute(TEXT("short"), pStr); + + //pStr = (_nppGUI._showDirty)?TEXT("yes"):TEXT("no"); + //element->SetAttribute(TEXT("showDirty"), pStr); + } + else if (!lstrcmp(nm, TEXT("stylerTheme"))) + { + stylerThemeExist = true; + element->SetAttribute(TEXT("path"), _nppGUI._themeName.c_str()); + } + } + + if (!noUpdateExist) + { + insertGUIConfigBoolNode(GUIRoot, TEXT("noUpdate"), _nppGUI._neverUpdate); + } + + if (!autoDetectionExist) + { + const TCHAR *pStr = TEXT("no"); + switch (_nppGUI._fileAutoDetection) + { + case cdEnabled: + pStr = TEXT("yes"); + break; + case cdAutoUpdate: + pStr = TEXT("auto"); + break; + case cdGo2end: + pStr = TEXT("Update2End"); + break; + case cdAutoUpdateGo2end: + pStr = TEXT("autoUpdate2End"); + break; + } + TiXmlElement *GUIConfigElement = (GUIRoot->InsertEndChild(TiXmlElement(TEXT("GUIConfig"))))->ToElement(); + GUIConfigElement->SetAttribute(TEXT("name"), TEXT("Auto-detection")); + GUIConfigElement->InsertEndChild(TiXmlText(pStr)); + } + if (!checkHistoryFilesExist) + { + insertGUIConfigBoolNode(GUIRoot, TEXT("CheckHistoryFiles"), _nppGUI._checkHistoryFiles); + } + if (!trayIconExist) + { + insertGUIConfigBoolNode(GUIRoot, TEXT("TrayIcon"), _nppGUI._isMinimizedToTray); + } + + if (!maitainIndentExist) + { + insertGUIConfigBoolNode(GUIRoot, TEXT("MaitainIndent"), _nppGUI._maitainIndent); + } + + if (!smartHighLightExist) + { + insertGUIConfigBoolNode(GUIRoot, TEXT("SmartHighLight"), _nppGUI._enableSmartHilite); + } + if (!tagsMatchHighLightExist) + { + TiXmlElement * ele = insertGUIConfigBoolNode(GUIRoot, TEXT("TagsMatchHighLight"), _nppGUI._enableTagsMatchHilite); + ele->SetAttribute(TEXT("TagAttrHighLight"), _nppGUI._enableTagAttrsHilite?TEXT("yes"):TEXT("no")); + ele->SetAttribute(TEXT("HighLightNonHtmlZone"), _nppGUI._enableHiliteNonHTMLZone?TEXT("yes"):TEXT("no")); + } + if (!rememberLastSessionExist) + { + insertGUIConfigBoolNode(GUIRoot, TEXT("RememberLastSession"), _nppGUI._rememberLastSession); + } + + if (!newDocDefaultSettingsExist) + { + TiXmlElement *GUIConfigElement = (GUIRoot->InsertEndChild(TiXmlElement(TEXT("GUIConfig"))))->ToElement(); + GUIConfigElement->SetAttribute(TEXT("name"), TEXT("NewDocDefaultSettings")); + GUIConfigElement->SetAttribute(TEXT("format"), _nppGUI._newDocDefaultSettings._format); + GUIConfigElement->SetAttribute(TEXT("encoding"), _nppGUI._newDocDefaultSettings._encoding); + GUIConfigElement->SetAttribute(TEXT("lang"), _nppGUI._newDocDefaultSettings._lang); + GUIConfigElement->SetAttribute(TEXT("openAnsiAsUTF8"), _nppGUI._newDocDefaultSettings._openAnsiAsUtf8?TEXT("yes"):TEXT("no")); + } + + if (!langsExcludedLstExist) + { + TiXmlElement *GUIConfigElement = (GUIRoot->InsertEndChild(TiXmlElement(TEXT("GUIConfig"))))->ToElement(); + GUIConfigElement->SetAttribute(TEXT("name"), TEXT("langsExcluded")); + writeExcludedLangList(GUIConfigElement); + GUIConfigElement->SetAttribute(TEXT("langMenuCompact"), _nppGUI._isLangMenuCompact?TEXT("yes"):TEXT("no")); + } + + if (!printSettingExist) + { + TiXmlElement *GUIConfigElement = (GUIRoot->InsertEndChild(TiXmlElement(TEXT("GUIConfig"))))->ToElement(); + GUIConfigElement->SetAttribute(TEXT("name"), TEXT("Print")); + writePrintSetting(GUIConfigElement); + } + if (!backExist) + { + TiXmlElement *GUIConfigElement = (GUIRoot->InsertEndChild(TiXmlElement(TEXT("GUIConfig"))))->ToElement(); + GUIConfigElement->SetAttribute(TEXT("name"), TEXT("Backup")); + GUIConfigElement->SetAttribute(TEXT("action"), _nppGUI._backup); + GUIConfigElement->SetAttribute(TEXT("useCustumDir"), _nppGUI._useDir?TEXT("yes"):TEXT("no")); + GUIConfigElement->SetAttribute(TEXT("dir"), _nppGUI._backupDir); + } + + if (!doTaskListExist) + { + insertGUIConfigBoolNode(GUIRoot, TEXT("TaskList"), _nppGUI._doTaskList); + } + + if (!MRUExist) + { + insertGUIConfigBoolNode(GUIRoot, TEXT("MRU"), _nppGUI._styleMRU); + } + + if (!URLExist) + { + const TCHAR *pStr = TEXT("0"); + if (_nppGUI._styleURL == 1) + pStr = TEXT("1"); + else if (_nppGUI._styleURL == 2) + pStr = TEXT("2"); + + TiXmlElement *GUIConfigElement = (GUIRoot->InsertEndChild(TiXmlElement(TEXT("GUIConfig"))))->ToElement(); + GUIConfigElement->SetAttribute(TEXT("name"), TEXT("URL")); + GUIConfigElement->InsertEndChild(TiXmlText(pStr)); + } + + if (!globalOverrideExist) + { + TiXmlElement *GUIConfigElement = (GUIRoot->InsertEndChild(TiXmlElement(TEXT("GUIConfig"))))->ToElement(); + GUIConfigElement->SetAttribute(TEXT("name"), TEXT("globalOverride")); + GUIConfigElement->SetAttribute(TEXT("fg"), _nppGUI._globalOverride.enableFg?TEXT("yes"):TEXT("no")); + GUIConfigElement->SetAttribute(TEXT("bg"), _nppGUI._globalOverride.enableBg?TEXT("yes"):TEXT("no")); + GUIConfigElement->SetAttribute(TEXT("font"), _nppGUI._globalOverride.enableFont?TEXT("yes"):TEXT("no")); + GUIConfigElement->SetAttribute(TEXT("fontSize"), _nppGUI._globalOverride.enableFontSize?TEXT("yes"):TEXT("no")); + GUIConfigElement->SetAttribute(TEXT("bold"), _nppGUI._globalOverride.enableBold?TEXT("yes"):TEXT("no")); + GUIConfigElement->SetAttribute(TEXT("italic"), _nppGUI._globalOverride.enableItalic?TEXT("yes"):TEXT("no")); + GUIConfigElement->SetAttribute(TEXT("underline"), _nppGUI._globalOverride.enableUnderLine?TEXT("yes"):TEXT("no")); + } + + if (!autocExist) + { + TiXmlElement *GUIConfigElement = (GUIRoot->InsertEndChild(TiXmlElement(TEXT("GUIConfig"))))->ToElement(); + GUIConfigElement->SetAttribute(TEXT("name"), TEXT("auto-completion")); + GUIConfigElement->SetAttribute(TEXT("autoCAction"), _nppGUI._autocStatus); + GUIConfigElement->SetAttribute(TEXT("triggerFromNbChar"), _nppGUI._autocFromLen); + const TCHAR * pStr = _nppGUI._funcParams?TEXT("yes"):TEXT("no"); + GUIConfigElement->SetAttribute(TEXT("funcParams"), pStr); + autocExist = true; + } + + if (dockingParamNode) + { + // Rase tout + GUIRoot->RemoveChild(dockingParamNode); + } + + if (!sessionExtExist) + { + TiXmlElement *GUIConfigElement = (GUIRoot->InsertEndChild(TiXmlElement(TEXT("GUIConfig"))))->ToElement(); + GUIConfigElement->SetAttribute(TEXT("name"), TEXT("sessionExt")); + GUIConfigElement->InsertEndChild(TiXmlText(_nppGUI._definedSessionExt.c_str())); + } + + if (!menuBarExist) + { + TiXmlElement *GUIConfigElement = (GUIRoot->InsertEndChild(TiXmlElement(TEXT("GUIConfig"))))->ToElement(); + GUIConfigElement->SetAttribute(TEXT("name"), TEXT("MenuBar")); + GUIConfigElement->InsertEndChild(TiXmlText(_nppGUI._menuBarShow?TEXT("show"):TEXT("hide"))); + } + + if (!caretExist) + { + TiXmlElement *GUIConfigElement = (GUIRoot->InsertEndChild(TiXmlElement(TEXT("GUIConfig"))))->ToElement(); + GUIConfigElement->SetAttribute(TEXT("name"), TEXT("Caret")); + GUIConfigElement->SetAttribute(TEXT("width"), _nppGUI._caretWidth); + GUIConfigElement->SetAttribute(TEXT("blinkRate"), _nppGUI._caretBlinkRate); + } + + if (!openSaveDirExist) + { + TiXmlElement *GUIConfigElement = (GUIRoot->InsertEndChild(TiXmlElement(TEXT("GUIConfig"))))->ToElement(); + GUIConfigElement->SetAttribute(TEXT("name"), TEXT("openSaveDir")); + GUIConfigElement->SetAttribute(TEXT("value"), _nppGUI._openSaveDir); + GUIConfigElement->SetAttribute(TEXT("defaultDirPath"), _nppGUI._defaultDir); + } + + if (!titleBarExist) + { + TiXmlElement *GUIConfigElement = (GUIRoot->InsertEndChild(TiXmlElement(TEXT("GUIConfig"))))->ToElement(); + GUIConfigElement->SetAttribute(TEXT("name"), TEXT("titleBar")); + const TCHAR *pStr = (_nppGUI._shortTitlebar)?TEXT("yes"):TEXT("no"); + GUIConfigElement->SetAttribute(TEXT("short"), pStr); + } + if (!stylerThemeExist) + { + TiXmlElement *GUIConfigElement = (GUIRoot->InsertEndChild(TiXmlElement(TEXT("GUIConfig"))))->ToElement(); + GUIConfigElement->SetAttribute(TEXT("name"), TEXT("stylerTheme")); + GUIConfigElement->SetAttribute(TEXT("path"), _nppGUI._themeName.c_str()); + } + + insertDockingParamNode(GUIRoot); + return true; +} + +bool NppParameters::writeFindHistory() +{ + if (!_pXmlUserDoc) return false; + + TiXmlNode *nppRoot = _pXmlUserDoc->FirstChild(TEXT("NotepadPlus")); + if (!nppRoot) return false; + + TiXmlNode *findHistoryRoot = nppRoot->FirstChildElement(TEXT("FindHistory")); + if (!findHistoryRoot) + { + TiXmlElement element(TEXT("FindHistory")); + findHistoryRoot = nppRoot->InsertEndChild(element); + } + + int i; + + findHistoryRoot->Clear(); + + (findHistoryRoot->ToElement())->SetAttribute(TEXT("nbMaxFindHistoryPath"), _findHistory._nbMaxFindHistoryPath); + (findHistoryRoot->ToElement())->SetAttribute(TEXT("nbMaxFindHistoryFilter"), _findHistory._nbMaxFindHistoryFilter); + (findHistoryRoot->ToElement())->SetAttribute(TEXT("nbMaxFindHistoryFind"), _findHistory._nbMaxFindHistoryFind); + (findHistoryRoot->ToElement())->SetAttribute(TEXT("nbMaxFindHistoryReplace"), _findHistory._nbMaxFindHistoryReplace); + + (findHistoryRoot->ToElement())->SetAttribute(TEXT("matchWord"), _findHistory._isMatchWord?TEXT("yes"):TEXT("no")); + (findHistoryRoot->ToElement())->SetAttribute(TEXT("matchCase"), _findHistory._isMatchCase?TEXT("yes"):TEXT("no")); + (findHistoryRoot->ToElement())->SetAttribute(TEXT("wrap"), _findHistory._isWrap?TEXT("yes"):TEXT("no")); + (findHistoryRoot->ToElement())->SetAttribute(TEXT("directionDown"), _findHistory._isDirectionDown?TEXT("yes"):TEXT("no")); + + (findHistoryRoot->ToElement())->SetAttribute(TEXT("fifRecuisive"), _findHistory._isFifRecuisive?TEXT("yes"):TEXT("no")); + (findHistoryRoot->ToElement())->SetAttribute(TEXT("fifInHiddenFolder"), _findHistory._isFifInHiddenFolder?TEXT("yes"):TEXT("no")); + (findHistoryRoot->ToElement())->SetAttribute(TEXT("dlgAlwaysVisible"), _findHistory._isDlgAlwaysVisible?TEXT("yes"):TEXT("no")); + (findHistoryRoot->ToElement())->SetAttribute(TEXT("fifFilterFollowsDoc"), _findHistory._isFilterFollowDoc?TEXT("yes"):TEXT("no")); + (findHistoryRoot->ToElement())->SetAttribute(TEXT("fifFolderFollowsDoc"), _findHistory._isFolderFollowDoc?TEXT("yes"):TEXT("no")); + + (findHistoryRoot->ToElement())->SetAttribute(TEXT("searchMode"), _findHistory._searchMode); + (findHistoryRoot->ToElement())->SetAttribute(TEXT("transparencyMode"), _findHistory._transparencyMode); + (findHistoryRoot->ToElement())->SetAttribute(TEXT("transparency"), _findHistory._transparency); + + TiXmlElement hist_element(TEXT("")); + + hist_element.SetValue(TEXT("Path")); + for (i = 0; i < _findHistory._nbFindHistoryPath; i++) + { + (hist_element.ToElement())->SetAttribute(TEXT("name"), _findHistory._pFindHistoryPath[i]->c_str()); + findHistoryRoot->InsertEndChild(hist_element); + } + + hist_element.SetValue(TEXT("Filter")); + for (i = 0; i < _findHistory._nbFindHistoryFilter; i++) + { + (hist_element.ToElement())->SetAttribute(TEXT("name"), _findHistory._pFindHistoryFilter[i]->c_str()); + findHistoryRoot->InsertEndChild(hist_element); + } + + hist_element.SetValue(TEXT("Find")); + for (i = 0; i < _findHistory._nbFindHistoryFind; i++) + { + (hist_element.ToElement())->SetAttribute(TEXT("name"), _findHistory._pFindHistoryFind[i]->c_str()); + findHistoryRoot->InsertEndChild(hist_element); + } + + hist_element.SetValue(TEXT("Replace")); + for (i = 0; i < _findHistory._nbFindHistoryReplace; i++) + { + (hist_element.ToElement())->SetAttribute(TEXT("name"), _findHistory._pFindHistoryReplace[i]->c_str()); + findHistoryRoot->InsertEndChild(hist_element); + } + + return true; +} + +void NppParameters::insertDockingParamNode(TiXmlNode *GUIRoot) +{ + TiXmlElement DMNode(TEXT("GUIConfig")); + DMNode.SetAttribute(TEXT("name"), TEXT("DockingManager")); + DMNode.SetAttribute(TEXT("leftWidth"), _nppGUI._dockingData._leftWidth); + DMNode.SetAttribute(TEXT("rightWidth"), _nppGUI._dockingData._rightWidth); + DMNode.SetAttribute(TEXT("topHeight"), _nppGUI._dockingData._topHeight); + DMNode.SetAttribute(TEXT("bottomHeight"), _nppGUI._dockingData._bottomHight); + + for (size_t i = 0 ; i < _nppGUI._dockingData._flaotingWindowInfo.size() ; i++) + { + FloatingWindowInfo & fwi = _nppGUI._dockingData._flaotingWindowInfo[i]; + TiXmlElement FWNode(TEXT("FloatingWindow")); + FWNode.SetAttribute(TEXT("cont"), fwi._cont); + FWNode.SetAttribute(TEXT("x"), fwi._pos.left); + FWNode.SetAttribute(TEXT("y"), fwi._pos.top); + FWNode.SetAttribute(TEXT("width"), fwi._pos.right); + FWNode.SetAttribute(TEXT("height"), fwi._pos.bottom); + + DMNode.InsertEndChild(FWNode); + } + + for (size_t i = 0 ; i < _nppGUI._dockingData._pluginDockInfo.size() ; i++) + { + PlugingDlgDockingInfo & pdi = _nppGUI._dockingData._pluginDockInfo[i]; + TiXmlElement PDNode(TEXT("PluginDlg")); + PDNode.SetAttribute(TEXT("pluginName"), pdi._name); + PDNode.SetAttribute(TEXT("id"), pdi._internalID); + PDNode.SetAttribute(TEXT("curr"), pdi._currContainer); + PDNode.SetAttribute(TEXT("prev"), pdi._prevContainer); + PDNode.SetAttribute(TEXT("isVisible"), pdi._isVisible?TEXT("yes"):TEXT("no")); + + DMNode.InsertEndChild(PDNode); + } + + for (size_t i = 0 ; i < _nppGUI._dockingData._containerTabInfo.size() ; i++) + { + ContainerTabInfo & cti = _nppGUI._dockingData._containerTabInfo[i]; + TiXmlElement CTNode(TEXT("ActiveTabs")); + CTNode.SetAttribute(TEXT("cont"), cti._cont); + CTNode.SetAttribute(TEXT("activeTab"), cti._activeTab); + DMNode.InsertEndChild(CTNode); + } + + GUIRoot->InsertEndChild(DMNode); +} + +void NppParameters::writePrintSetting(TiXmlElement *element) +{ + const TCHAR *pStr = _nppGUI._printSettings._printLineNumber?TEXT("yes"):TEXT("no"); + element->SetAttribute(TEXT("lineNumber"), pStr); + + element->SetAttribute(TEXT("printOption"), _nppGUI._printSettings._printOption); + + element->SetAttribute(TEXT("headerLeft"), _nppGUI._printSettings._headerLeft.c_str()); + element->SetAttribute(TEXT("headerMiddle"), _nppGUI._printSettings._headerMiddle.c_str()); + element->SetAttribute(TEXT("headerRight"), _nppGUI._printSettings._headerRight.c_str()); + element->SetAttribute(TEXT("footerLeft"), _nppGUI._printSettings._footerLeft.c_str()); + element->SetAttribute(TEXT("footerMiddle"), _nppGUI._printSettings._footerMiddle.c_str()); + element->SetAttribute(TEXT("footerRight"), _nppGUI._printSettings._footerRight.c_str()); + + element->SetAttribute(TEXT("headerFontName"), _nppGUI._printSettings._headerFontName.c_str()); + element->SetAttribute(TEXT("headerFontStyle"), _nppGUI._printSettings._headerFontStyle); + element->SetAttribute(TEXT("headerFontSize"), _nppGUI._printSettings._headerFontSize); + element->SetAttribute(TEXT("footerFontName"), _nppGUI._printSettings._footerFontName.c_str()); + element->SetAttribute(TEXT("footerFontStyle"), _nppGUI._printSettings._footerFontStyle); + element->SetAttribute(TEXT("footerFontSize"), _nppGUI._printSettings._footerFontSize); + + element->SetAttribute(TEXT("margeLeft"), _nppGUI._printSettings._marge.left); + element->SetAttribute(TEXT("margeRight"), _nppGUI._printSettings._marge.right); + element->SetAttribute(TEXT("margeTop"), _nppGUI._printSettings._marge.top); + element->SetAttribute(TEXT("margeBottom"), _nppGUI._printSettings._marge.bottom); +} + +void NppParameters::writeExcludedLangList(TiXmlElement *element) +{ + int g0 = 0; // up to 8 + int g1 = 0; // up to 16 + int g2 = 0; // up to 24 + int g3 = 0; // up to 32 + int g4 = 0; // up to 40 + int g5 = 0; // up to 48 + int g6 = 0; // up to 56 + int g7 = 0; // up to 64 + + for (size_t i = 0 ; i < _nppGUI._excludedLangList.size() ; i++) + { + LangType langType = _nppGUI._excludedLangList[i]._langType; + if (langType >= L_EXTERNAL && langType < L_END) + continue; + + int nGrp = langType / 8; + int nMask = 1 << langType % 8; + + + switch (nGrp) + { + case 0 : + g0 |= nMask; + break; + case 1 : + g1 |= nMask; + break; + case 2 : + g2 |= nMask; + break; + case 3 : + g3 |= nMask; + break; + case 4 : + g4 |= nMask; + break; + case 5 : + g5 |= nMask; + break; + case 6 : + g6 |= nMask; + break; + case 7 : + g7 |= nMask; + break; + } + } + + element->SetAttribute(TEXT("gr0"), g0); + element->SetAttribute(TEXT("gr1"), g1); + element->SetAttribute(TEXT("gr2"), g2); + element->SetAttribute(TEXT("gr3"), g3); + element->SetAttribute(TEXT("gr4"), g4); + element->SetAttribute(TEXT("gr5"), g5); + element->SetAttribute(TEXT("gr6"), g6); + element->SetAttribute(TEXT("gr7"), g7); +} + +TiXmlElement * NppParameters::insertGUIConfigBoolNode(TiXmlNode *r2w, const TCHAR *name, bool bVal) +{ + const TCHAR *pStr = bVal?TEXT("yes"):TEXT("no"); + TiXmlElement *GUIConfigElement = (r2w->InsertEndChild(TiXmlElement(TEXT("GUIConfig"))))->ToElement(); + GUIConfigElement->SetAttribute(TEXT("name"), name); + GUIConfigElement->InsertEndChild(TiXmlText(pStr)); + return GUIConfigElement; +} + +int RGB2int(COLORREF color) { + return (((((DWORD)color) & 0x0000FF) << 16) | ((((DWORD)color) & 0x00FF00)) | ((((DWORD)color) & 0xFF0000) >> 16)); +} + +int NppParameters::langTypeToCommandID(LangType lt) const +{ + int id; + switch (lt) + { + case L_C : + id = IDM_LANG_C; break; + case L_CPP : + id = IDM_LANG_CPP; break; + case L_JAVA : + id = IDM_LANG_JAVA; break; + case L_CS : + id = IDM_LANG_CS; break; + case L_OBJC : + id = IDM_LANG_OBJC; break; + case L_HTML : + id = IDM_LANG_HTML; break; + case L_XML : + id = IDM_LANG_XML; break; + case L_JS : + id = IDM_LANG_JS; break; + case L_PHP : + id = IDM_LANG_PHP; break; + case L_ASP : + id = IDM_LANG_ASP; break; + case L_CSS : + id = IDM_LANG_CSS; break; + case L_LUA : + id = IDM_LANG_LUA; break; + case L_PERL : + id = IDM_LANG_PERL; break; + case L_PYTHON : + id = IDM_LANG_PYTHON; break; + case L_BATCH : + id = IDM_LANG_BATCH; break; + case L_PASCAL : + id = IDM_LANG_PASCAL; break; + case L_MAKEFILE : + id = IDM_LANG_MAKEFILE; break; + case L_INI : + id = IDM_LANG_INI; break; + case L_NFO : + id = IDM_LANG_ASCII; break; + case L_RC : + id = IDM_LANG_RC; break; + case L_TEX : + id = IDM_LANG_TEX; break; + case L_FORTRAN : + id = IDM_LANG_FORTRAN; break; + case L_BASH : + id = IDM_LANG_SH; break; + case L_FLASH : + id = IDM_LANG_FLASH; break; + case L_NSIS : + id = IDM_LANG_NSIS; break; + case L_USER : + id = IDM_LANG_USER; break; + case L_SQL : + id = IDM_LANG_SQL; break; + case L_VB : + id = IDM_LANG_VB; break; + case L_TCL : + id = IDM_LANG_TCL; break; + + case L_LISP : + id = IDM_LANG_LISP; break; + case L_SCHEME : + id = IDM_LANG_SCHEME; break; + case L_ASM : + id = IDM_LANG_ASM; break; + case L_DIFF : + id = IDM_LANG_DIFF; break; + case L_PROPS : + id = IDM_LANG_PROPS; break; + case L_PS : + id = IDM_LANG_PS; break; + case L_RUBY : + id = IDM_LANG_RUBY; break; + case L_SMALLTALK : + id = IDM_LANG_SMALLTALK; break; + case L_VHDL : + id = IDM_LANG_VHDL; break; + + case L_ADA : + id = IDM_LANG_ADA; break; + case L_MATLAB : + id = IDM_LANG_MATLAB; break; + + case L_HASKELL : + id = IDM_LANG_HASKELL; break; + + case L_KIX : + id = IDM_LANG_KIX; break; + case L_AU3 : + id = IDM_LANG_AU3; break; + case L_VERILOG : + id = IDM_LANG_VERILOG; break; + case L_CAML : + id = IDM_LANG_CAML; break; + + case L_INNO : + id = IDM_LANG_INNO; break; + + case L_CMAKE : + id = IDM_LANG_CMAKE; break; + + case L_YAML : + id = IDM_LANG_YAML; break; + + case L_SEARCHRESULT : + id = -1; break; + + case L_TXT : + id = IDM_LANG_TEXT; break; + + default : + if(lt >= L_EXTERNAL && lt < L_END) + id = lt - L_EXTERNAL + IDM_LANG_EXTERNAL; + else + id = IDM_LANG_TEXT; + } + return id; +} + +void NppParameters::writeStyles(LexerStylerArray & lexersStylers, StyleArray & globalStylers) +{ + TiXmlNode *lexersRoot = (_pXmlUserStylerDoc->FirstChild(TEXT("NotepadPlus")))->FirstChildElement(TEXT("LexerStyles")); + for (TiXmlNode *childNode = lexersRoot->FirstChildElement(TEXT("LexerType")); + childNode ; + childNode = childNode->NextSibling(TEXT("LexerType"))) + { + TiXmlElement *element = childNode->ToElement(); + const TCHAR *nm = element->Attribute(TEXT("name")); + + LexerStyler *pLs = _lexerStylerArray.getLexerStylerByName(nm); + LexerStyler *pLs2 = lexersStylers.getLexerStylerByName(nm); + + if (pLs) + { + const TCHAR *extStr = pLs->getLexerUserExt(); + element->SetAttribute(TEXT("ext"), extStr); + for (TiXmlNode *grChildNode = childNode->FirstChildElement(TEXT("WordsStyle")); + grChildNode ; + grChildNode = grChildNode->NextSibling(TEXT("WordsStyle"))) + { + TiXmlElement *grElement = grChildNode->ToElement(); + const TCHAR *styleName = grElement->Attribute(TEXT("name")); + + int i = pLs->getStylerIndexByName(styleName); + if (i != -1) + { + Style & style = pLs->getStyler(i); + Style & style2Sync = pLs2->getStyler(i); + + writeStyle2Element(style, style2Sync, grElement); + } + } + } + } + + for(size_t x = 0; x < _pXmlExternalLexerDoc.size(); x++) + { + TiXmlNode *lexersRoot = ( _pXmlExternalLexerDoc[x]->FirstChild(TEXT("NotepadPlus")))->FirstChildElement(TEXT("LexerStyles")); + for (TiXmlNode *childNode = lexersRoot->FirstChildElement(TEXT("LexerType")); + childNode ; + childNode = childNode->NextSibling(TEXT("LexerType"))) + { + TiXmlElement *element = childNode->ToElement(); + const TCHAR *nm = element->Attribute(TEXT("name")); + + LexerStyler *pLs = _lexerStylerArray.getLexerStylerByName(nm); + LexerStyler *pLs2 = lexersStylers.getLexerStylerByName(nm); + + if (pLs) + { + const TCHAR *extStr = pLs->getLexerUserExt(); + element->SetAttribute(TEXT("ext"), extStr); + + for (TiXmlNode *grChildNode = childNode->FirstChildElement(TEXT("WordsStyle")); + grChildNode ; + grChildNode = grChildNode->NextSibling(TEXT("WordsStyle"))) + { + TiXmlElement *grElement = grChildNode->ToElement(); + const TCHAR *styleName = grElement->Attribute(TEXT("name")); + + int i = pLs->getStylerIndexByName(styleName); + if (i != -1) + { + Style & style = pLs->getStyler(i); + Style & style2Sync = pLs2->getStyler(i); + + writeStyle2Element(style, style2Sync, grElement); + } + } + } + } + _pXmlExternalLexerDoc[x]->SaveFile(); + } + + TiXmlNode *globalStylesRoot = (_pXmlUserStylerDoc->FirstChild(TEXT("NotepadPlus")))->FirstChildElement(TEXT("GlobalStyles")); + + for (TiXmlNode *childNode = globalStylesRoot->FirstChildElement(TEXT("WidgetStyle")); + childNode ; + childNode = childNode->NextSibling(TEXT("WidgetStyle"))) + { + TiXmlElement *pElement = childNode->ToElement(); + const TCHAR *styleName = pElement->Attribute(TEXT("name")); + int i = _widgetStyleArray.getStylerIndexByName(styleName); + + if (i != -1) + { + Style & style = _widgetStyleArray.getStyler(i); + Style & style2Sync = globalStylers.getStyler(i); + + writeStyle2Element(style, style2Sync, pElement); + } + } + + _pXmlUserStylerDoc->SaveFile(); +} + +void NppParameters::writeStyle2Element(Style & style2Wite, Style & style2Sync, TiXmlElement *element) +{ + const TCHAR *styleName = element->Attribute(TEXT("name")); + + if (HIBYTE(HIWORD(style2Wite._fgColor)) != 0xFF) + { + int rgbVal = RGB2int(style2Wite._fgColor); + TCHAR fgStr[7]; + wsprintf(fgStr, TEXT("%.6X"), rgbVal); + element->SetAttribute(TEXT("fgColor"), fgStr); + } + + if (HIBYTE(HIWORD(style2Wite._bgColor)) != 0xFF) + { + int rgbVal = RGB2int(style2Wite._bgColor); + TCHAR bgStr[7]; + wsprintf(bgStr, TEXT("%.6X"), rgbVal); + element->SetAttribute(TEXT("bgColor"), bgStr); + } + + if (style2Wite._colorStyle != COLORSTYLE_ALL) + { + element->SetAttribute(TEXT("colorStyle"), style2Wite._colorStyle); + } + + if (style2Wite._fontName) + { + const TCHAR *oldFontName = element->Attribute(TEXT("fontName")); + if (lstrcmp(oldFontName, style2Wite._fontName)) + { + element->SetAttribute(TEXT("fontName"), style2Wite._fontName); + style2Sync._fontName = style2Wite._fontName = element->Attribute(TEXT("fontName")); + } + } + + if (style2Wite._fontSize != -1) + { + if (!style2Wite._fontSize) + element->SetAttribute(TEXT("fontSize"), TEXT("")); + else + element->SetAttribute(TEXT("fontSize"), style2Wite._fontSize); + } + + if (style2Wite._fontStyle != -1) + { + element->SetAttribute(TEXT("fontStyle"), style2Wite._fontStyle); + } + + + if (style2Wite._keywords) + { + TiXmlNode *teteDeNoeud = element->LastChild(); + + if (teteDeNoeud) + teteDeNoeud->SetValue(style2Wite._keywords->c_str()); + else + element->InsertEndChild(TiXmlText(style2Wite._keywords->c_str())); + } +} + +void NppParameters::insertUserLang2Tree(TiXmlNode *node, UserLangContainer *userLang) +{ + TiXmlElement *rootElement = (node->InsertEndChild(TiXmlElement(TEXT("UserLang"))))->ToElement(); + + rootElement->SetAttribute(TEXT("name"), userLang->_name); + rootElement->SetAttribute(TEXT("ext"), userLang->_ext); + TiXmlElement *settingsElement = (rootElement->InsertEndChild(TiXmlElement(TEXT("Settings"))))->ToElement(); + { + TiXmlElement *globalElement = (settingsElement->InsertEndChild(TiXmlElement(TEXT("Global"))))->ToElement(); + globalElement->SetAttribute(TEXT("caseIgnored"), userLang->_isCaseIgnored?TEXT("yes"):TEXT("no")); + + TiXmlElement *treatAsSymbolElement = (settingsElement->InsertEndChild(TiXmlElement(TEXT("TreatAsSymbol"))))->ToElement(); + treatAsSymbolElement->SetAttribute(TEXT("comment"), userLang->_isCommentSymbol?TEXT("yes"):TEXT("no")); + treatAsSymbolElement->SetAttribute(TEXT("commentLine"), userLang->_isCommentLineSymbol?TEXT("yes"):TEXT("no")); + + TiXmlElement *prefixElement = (settingsElement->InsertEndChild(TiXmlElement(TEXT("Prefix"))))->ToElement(); + TCHAR names[nbPrefixListAllowed][7] = {TEXT("words1"), TEXT("words2"), TEXT("words3"), TEXT("words4")}; + for (int i = 0 ; i < nbPrefixListAllowed ; i++) + prefixElement->SetAttribute(names[i], userLang->_isPrefix[i]?TEXT("yes"):TEXT("no")); + } + + TiXmlElement *kwlElement = (rootElement->InsertEndChild(TiXmlElement(TEXT("KeywordLists"))))->ToElement(); + + const int nbKWL = 9; + TCHAR kwn[nbKWL][16] = {TEXT("Delimiters"), TEXT("Folder+"), TEXT("Folder-"), TEXT("Operators"), TEXT("Comment"), TEXT("Words1"), TEXT("Words2"), TEXT("Words3"), TEXT("Words4")}; + for (int i = 0 ; i < nbKWL ; i++) + { + TiXmlElement *kwElement = (kwlElement->InsertEndChild(TiXmlElement(TEXT("Keywords"))))->ToElement(); + kwElement->SetAttribute(TEXT("name"), kwn[i]); + kwElement->InsertEndChild(TiXmlText(userLang->_keywordLists[i])); + } + + TiXmlElement *styleRootElement = (rootElement->InsertEndChild(TiXmlElement(TEXT("Styles"))))->ToElement(); + + for (int i = 0 ; i < userLang->_styleArray.getNbStyler() ; i++) + { + TiXmlElement *styleElement = (styleRootElement->InsertEndChild(TiXmlElement(TEXT("WordsStyle"))))->ToElement(); + Style style2Wite = userLang->_styleArray.getStyler(i); + + styleElement->SetAttribute(TEXT("name"), style2Wite._styleDesc); + + styleElement->SetAttribute(TEXT("styleID"), style2Wite._styleID); + + //if (HIBYTE(HIWORD(style2Wite._fgColor)) != 0xFF) + { + int rgbVal = RGB2int(style2Wite._fgColor); + TCHAR fgStr[7]; + wsprintf(fgStr, TEXT("%.6X"), rgbVal); + styleElement->SetAttribute(TEXT("fgColor"), fgStr); + } + + //if (HIBYTE(HIWORD(style2Wite._bgColor)) != 0xFF) + { + int rgbVal = RGB2int(style2Wite._bgColor); + TCHAR bgStr[7]; + wsprintf(bgStr, TEXT("%.6X"), rgbVal); + styleElement->SetAttribute(TEXT("bgColor"), bgStr); + } + + if (style2Wite._colorStyle != COLORSTYLE_ALL) + { + styleElement->SetAttribute(TEXT("colorStyle"), style2Wite._colorStyle); + } + + if (style2Wite._fontName) + { + styleElement->SetAttribute(TEXT("fontName"), style2Wite._fontName); + } + + if (style2Wite._fontStyle == -1) + { + styleElement->SetAttribute(TEXT("fontStyle"), TEXT("0")); + } + else + { + styleElement->SetAttribute(TEXT("fontStyle"), style2Wite._fontStyle); + } + + if (style2Wite._fontSize != -1) + { + if (!style2Wite._fontSize) + styleElement->SetAttribute(TEXT("fontSize"), TEXT("")); + else + styleElement->SetAttribute(TEXT("fontSize"), style2Wite._fontSize); + } + } +} + +void NppParameters::stylerStrOp(bool op) +{ + for (int i = 0 ; i < _nbUserLang ; i++) + { + int nbStyler = _userLangArray[i]->_styleArray.getNbStyler(); + for (int j = 0 ; j < nbStyler ; j++) + { + Style & style = _userLangArray[i]->_styleArray.getStyler(j); + + if (op == DUP) + { + TCHAR *str = new TCHAR[lstrlen(style._styleDesc) + 1]; + style._styleDesc = lstrcpy(str, style._styleDesc); + if (style._fontName) + { + str = new TCHAR[lstrlen(style._fontName) + 1]; + style._fontName = lstrcpy(str, style._fontName); + } + else + { + str = new TCHAR[2]; + str[0] = str[1] = '\0'; + style._fontName = str; + } + } + else + { + delete [] style._styleDesc; + delete [] style._fontName; + } + } + } +} + +void NppParameters::addUserModifiedIndex(int index) +{ + size_t len = _customizedShortcuts.size(); + bool found = false; + for(size_t i = 0; i < len; i++) + { + if (_customizedShortcuts[i] == index) + { + found = true; + break; + } + } + if (!found) + { + _customizedShortcuts.push_back(index); + } +} + +void NppParameters::addPluginModifiedIndex(int index) +{ + size_t len = _pluginCustomizedCmds.size(); + bool found = false; + for(size_t i = 0; i < len; i++) + { + if (_pluginCustomizedCmds[i] == index) + { + found = true; + break; + } + } + if (!found) + { + _pluginCustomizedCmds.push_back(index); + } +} + +void NppParameters::addScintillaModifiedIndex(int index) +{ + size_t len = _scintillaModifiedKeyIndices.size(); + bool found = false; + for(size_t i = 0; i < len; i++) + { + if (_scintillaModifiedKeyIndices[i] == index) + { + found = true; + break; + } + } + if (!found) + { + _scintillaModifiedKeyIndices.push_back(index); + } +} diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h new file mode 100644 index 00000000..76f4414c --- /dev/null +++ b/PowerEditor/src/Parameters.h @@ -0,0 +1,1418 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef PARAMETERS_H +#define PARAMETERS_H + +#include +#include +#include "tinyxmlA.h" +#include "tinyxml.h" + +//#include "ScintillaEditView.h" +#include "Scintilla.h" +#include "ScintillaRef.h" +#include "ToolBar.h" +#include "UserDefineLangReference.h" +#include "colors.h" +#include "shortcut.h" +#include "ContextMenu.h" + +using namespace std; + +const bool POS_VERTICAL = true; +const bool POS_HORIZOTAL = false; + +const int UDD_SHOW = 1; // 0000 0001 +const int UDD_DOCKED = 2; // 0000 0010 + +// 0 : 0000 0000 hide & undocked +// 1 : 0000 0001 show & undocked +// 2 : 0000 0010 hide & docked +// 3 : 0000 0011 show & docked + +const int TAB_DRAWTOPBAR = 1; // 0000 0001 +const int TAB_DRAWINACTIVETAB = 2; // 0000 0010 +const int TAB_DRAGNDROP = 4; // 0000 0100 +const int TAB_REDUCE = 8; // 0000 1000 +const int TAB_CLOSEBUTTON = 16; // 0001 0000 +const int TAB_DBCLK2CLOSE = 32; // 0010 0000 +const int TAB_VERTICAL = 64; // 0100 0000 +const int TAB_MULTILINE = 128; // 1000 0000 +const int TAB_HIDE = 256; //1 0000 0000 + +enum formatType {WIN_FORMAT, MAC_FORMAT, UNIX_FORMAT}; +enum UniMode {uni8Bit=0, uniUTF8=1, uni16BE=2, uni16LE=3, uniCookie=4, uni7Bit=5, uniEnd}; +enum ChangeDetect {cdDisabled=0, cdEnabled=1, cdAutoUpdate=2, cdGo2end=3, cdAutoUpdateGo2end=4}; +enum BackupFeature {bak_none = 0, bak_simple = 1, bak_verbose = 2}; +enum OpenSaveDirSetting {dir_followCurrent = 0, dir_last = 1, dir_userDef = 2}; + +const int LANG_INDEX_INSTR = 0; +const int LANG_INDEX_INSTR2 = 1; +const int LANG_INDEX_TYPE = 2; +const int LANG_INDEX_TYPE2 = 3; +const int LANG_INDEX_TYPE3 = 4; +const int LANG_INDEX_TYPE4 = 5; +const int LANG_INDEX_TYPE5 = 6; + +const int COPYDATA_PARAMS = 0; +const int COPYDATA_FILENAMESA = 1; +const int COPYDATA_FILENAMESW = 2; + + +const bool SCIV_PRIMARY = false; +const bool SCIV_SECOND = true; + +const TCHAR fontSizeStrs[][3] = {TEXT(""), TEXT("8"), TEXT("9"), TEXT("10"), TEXT("11"), TEXT("12"), TEXT("14"), TEXT("16"), TEXT("18"), TEXT("20"), TEXT("22"), TEXT("24"), TEXT("26"), TEXT("28")}; + +const TCHAR LINEDRAW_FONT[] = TEXT("LINEDRAW.TTF"); +const TCHAR localConfFile[] = TEXT("doLocalConf.xml"); +const TCHAR notepadStyleFile[] = TEXT("asNotepad.xml"); + +void cutString(const TCHAR *str2cut, vector & patternVect); +/* +struct HeaderLineState { + HeaderLineState() : _headerLineNumber(0), _isCollapsed(false){}; + HeaderLineState(int lineNumber, bool isFoldUp) : _headerLineNumber(lineNumber), _isCollapsed(isFoldUp){}; + int _headerLineNumber; + bool _isCollapsed; +}; +*/ +struct Position +{ + int _firstVisibleLine; + int _startPos; + int _endPos; + int _xOffset; + int _selMode; + int _scrollWidth; + Position() : _firstVisibleLine(0), _startPos(0), _endPos(0), _xOffset(0), _scrollWidth(1), _selMode(0) {}; +}; + +struct sessionFileInfo : public Position { + sessionFileInfo(const TCHAR *fn) { + if (fn) _fileName = fn; + }; + sessionFileInfo(const TCHAR *fn, const TCHAR *ln, Position pos) : Position(pos) { + if (fn) _fileName = fn; + if (ln) _langName = ln; + }; + + sessionFileInfo(generic_string fn) : _fileName(fn){}; + sessionFileInfo(generic_string fn, Position pos) : Position(pos), _fileName(fn){}; + + generic_string _fileName; + generic_string _langName; + vector marks; +}; + +struct Session { + size_t nbMainFiles() const {return _mainViewFiles.size();}; + size_t nbSubFiles() const {return _subViewFiles.size();}; + size_t _activeView; + size_t _activeMainIndex; + size_t _activeSubIndex; + vector _mainViewFiles; + vector _subViewFiles; +}; + +struct CmdLineParams { + bool _isNoPlugin; + bool _isReadOnly; + bool _isNoSession; + bool _isNoTab; + + int _line2go; + int _column2go; + + POINT _point; + bool _isPointXValid; + bool _isPointYValid; + bool isPointValid() { + return _isPointXValid && _isPointXValid; + }; + + LangType _langType; + CmdLineParams() : _isNoPlugin(false), _isReadOnly(false), _isNoSession(false), _isNoTab(false),\ + _line2go(-1), _column2go(-1), _langType(L_EXTERNAL), _isPointXValid(false), _isPointYValid(false) + { + _point.x = 0; + _point.y = 0; + } +}; + +struct FloatingWindowInfo { + int _cont; + RECT _pos; + FloatingWindowInfo(int cont, int x, int y, int w, int h) : _cont(cont) { + _pos.left = x; + _pos.top = y; + _pos.right = w; + _pos.bottom = h; + }; +}; + +struct PlugingDlgDockingInfo { + TCHAR _name[MAX_PATH]; + int _internalID; + + int _currContainer; + int _prevContainer; + bool _isVisible; + + PlugingDlgDockingInfo(const TCHAR *pluginName, int id, int curr, int prev, bool isVis) : _internalID(id), _currContainer(curr), _prevContainer(prev), _isVisible(isVis){ + lstrcpy(_name, pluginName); + }; + + friend inline const bool operator==(const PlugingDlgDockingInfo & a, const PlugingDlgDockingInfo & b) { + if ((lstrcmp(a._name, b._name) == 0) && (a._internalID == b._internalID)) + return true; + else + return false; + }; +}; + +struct ContainerTabInfo { + int _cont; + int _activeTab; + + ContainerTabInfo(int cont, int activeTab) : _cont(cont), _activeTab(activeTab) {}; +}; + +struct DockingManagerData { + int _leftWidth; + int _rightWidth; + int _topHeight; + int _bottomHight; + + DockingManagerData() : _leftWidth(200), _rightWidth(200), _topHeight(200), _bottomHight(200) {}; + + vector _flaotingWindowInfo; + vector _pluginDockInfo; + vector _containerTabInfo; + + RECT * getFloatingRCFrom(int floatCont) { + for (size_t i = 0 ; i < _flaotingWindowInfo.size() ; i++) + { + if (_flaotingWindowInfo[i]._cont == floatCont) + return &(_flaotingWindowInfo[i]._pos); + } + return NULL; + } +}; + +static int strVal(const TCHAR *str, int base) { + if (!str) return -1; + if (!str[0]) return 0; + + TCHAR *finStr; + int result = generic_strtol(str, &finStr, base); + if (*finStr != '\0') + return -1; + return result; +}; + +static int decStrVal(const TCHAR *str) { + return strVal(str, 10); +}; + +static int hexStrVal(const TCHAR *str) { + return strVal(str, 16); +}; + + +static int getKwClassFromName(const TCHAR *str) { + if (!lstrcmp(TEXT("instre1"), str)) return LANG_INDEX_INSTR; + if (!lstrcmp(TEXT("instre2"), str)) return LANG_INDEX_INSTR2; + if (!lstrcmp(TEXT("type1"), str)) return LANG_INDEX_TYPE; + if (!lstrcmp(TEXT("type2"), str)) return LANG_INDEX_TYPE2; + if (!lstrcmp(TEXT("type3"), str)) return LANG_INDEX_TYPE3; + if (!lstrcmp(TEXT("type4"), str)) return LANG_INDEX_TYPE4; + if (!lstrcmp(TEXT("type5"), str)) return LANG_INDEX_TYPE5; + + if ((str[1] == '\0') && (str[0] >= '0') && (str[0] <= '8')) // up to KEYWORDSET_MAX + return str[0] - '0'; + + return -1; +}; + +const int FONTSTYLE_BOLD = 1; +const int FONTSTYLE_ITALIC = 2; +const int FONTSTYLE_UNDERLINE = 4; + +const int COLORSTYLE_FOREGROUND = 0x01; +const int COLORSTYLE_BACKGROUND = 0x02; +const int COLORSTYLE_ALL = COLORSTYLE_FOREGROUND|COLORSTYLE_BACKGROUND; + +struct Style +{ + int _styleID; + const TCHAR *_styleDesc; + + COLORREF _fgColor; + COLORREF _bgColor; + int _colorStyle; + const TCHAR *_fontName; + int _fontStyle; + int _fontSize; + + int _keywordClass; + generic_string *_keywords; + + Style():_styleID(-1), _fgColor(COLORREF(-1)), _bgColor(COLORREF(-1)), _colorStyle(COLORSTYLE_ALL), _fontName(NULL), _fontStyle(-1), _fontSize(-1), _keywordClass(-1), _keywords(NULL){}; + + ~Style(){ + if (_keywords) + delete _keywords; + }; + + Style(const Style & style) + { + _styleID = style._styleID; + _styleDesc = style._styleDesc; + _fgColor = style._fgColor; + _bgColor = style._bgColor; + _colorStyle = style._colorStyle; + _fontName = style._fontName; + _fontSize = style._fontSize; + _fontStyle = style._fontStyle; + _keywordClass = style._keywordClass; + if (style._keywords) + _keywords = new generic_string(*(style._keywords)); + else + _keywords = NULL; + }; + + Style & operator=(const Style & style) { + if (this != &style) + { + this->_styleID = style._styleID; + this->_styleDesc = style._styleDesc; + this->_fgColor = style._fgColor; + this->_bgColor = style._bgColor; + this->_colorStyle = style._colorStyle; + this->_fontName = style._fontName; + this->_fontSize = style._fontSize; + this->_fontStyle = style._fontStyle; + this->_keywordClass = style._keywordClass; + + if (!(this->_keywords) && style._keywords) + this->_keywords = new generic_string(*(style._keywords)); + else if (this->_keywords && style._keywords) + this->_keywords->assign(*(style._keywords)); + else if (this->_keywords && !(style._keywords)) + { + delete (this->_keywords); + this->_keywords = NULL; + } + } + return *this; + }; + + void setKeywords(const TCHAR *str) { + if (!_keywords) + _keywords = new generic_string(str); + else + *_keywords = str; + }; +}; + +struct GlobalOverride +{ + bool isEnable() const {return (enableFg || enableBg || enableFont || enableFontSize || enableBold || enableItalic || enableUnderLine);}; + bool enableFg; + bool enableBg; + bool enableFont; + bool enableFontSize; + bool enableBold; + bool enableItalic; + bool enableUnderLine; + GlobalOverride():enableFg(false), enableBg(false), enableFont(false), enableFontSize(false), enableBold(false), enableItalic(false), enableUnderLine(false) {}; +}; + +const int MAX_STYLE = 30; + +struct StyleArray +{ +public: + StyleArray() : _nbStyler(0){}; + + StyleArray & operator=(const StyleArray & sa) + { + if (this != &sa) + { + this->_nbStyler = sa._nbStyler; + for (int i = 0 ; i < _nbStyler ; i++) + { + this->_styleArray[i] = sa._styleArray[i]; + } + } + return *this; + } + + int getNbStyler() const {return _nbStyler;}; + void setNbStyler(int nb) {_nbStyler = nb;}; + + Style & getStyler(int index) {return _styleArray[index];}; + + bool hasEnoughSpace() {return (_nbStyler < MAX_STYLE);}; + void addStyler(int styleID, TiXmlNode *styleNode); + + void addStyler(int styleID, TCHAR *styleName) { + //ZeroMemory(&_styleArray[_nbStyler], sizeof(Style));; + _styleArray[_nbStyler]._styleID = styleID; + _styleArray[_nbStyler]._styleDesc = styleName; + _styleArray[_nbStyler]._fgColor = black; + _styleArray[_nbStyler]._bgColor = white; + _nbStyler++; + }; + + int getStylerIndexByID(int id) { + for (int i = 0 ; i < _nbStyler ; i++) + if (_styleArray[i]._styleID == id) + return i; + return -1; + }; + + int getStylerIndexByName(const TCHAR *name) const { + if (!name) + return -1; + for (int i = 0 ; i < _nbStyler ; i++) + if (!lstrcmp(_styleArray[i]._styleDesc, name)) + return i; + return -1; + }; + +protected: + Style _styleArray[MAX_STYLE]; + int _nbStyler; +}; + +struct LexerStyler : public StyleArray +{ +public : + LexerStyler():StyleArray(){}; + + LexerStyler & operator=(const LexerStyler & ls) + { + if (this != &ls) + { + *((StyleArray *)this) = ls; + lstrcpy(this->_lexerName, ls._lexerName); + lstrcpy(this->_lexerDesc, ls._lexerDesc); + lstrcpy(this->_lexerUserExt, ls._lexerUserExt); + } + return *this; + } + + void setLexerName(const TCHAR *lexerName) { + lstrcpy(_lexerName, lexerName); + }; + + void setLexerDesc(const TCHAR *lexerDesc) { + lstrcpy(_lexerDesc, lexerDesc); + }; + + void setLexerUserExt(const TCHAR *lexerUserExt) { + lstrcpy(_lexerUserExt, lexerUserExt); + }; + + const TCHAR * getLexerName() const {return _lexerName;}; + const TCHAR * getLexerDesc() const {return _lexerDesc;}; + const TCHAR * getLexerUserExt() const {return _lexerUserExt;}; + +private : + TCHAR _lexerName[16]; + TCHAR _lexerDesc[32]; + TCHAR _lexerUserExt[256]; +}; + +const int MAX_LEXER_STYLE = 80; + +struct LexerStylerArray +{ +public : + LexerStylerArray() : _nbLexerStyler(0){}; + + LexerStylerArray & operator=(const LexerStylerArray & lsa) + { + if (this != &lsa) + { + this->_nbLexerStyler = lsa._nbLexerStyler; + for (int i = 0 ; i < this->_nbLexerStyler ; i++) + this->_lexerStylerArray[i] = lsa._lexerStylerArray[i]; + } + return *this; + } + + int getNbLexer() const {return _nbLexerStyler;}; + + LexerStyler & getLexerFromIndex(int index) + { + return _lexerStylerArray[index]; + }; + + const TCHAR * getLexerNameFromIndex(int index) const {return _lexerStylerArray[index].getLexerName();} + const TCHAR * getLexerDescFromIndex(int index) const {return _lexerStylerArray[index].getLexerDesc();} + + LexerStyler * getLexerStylerByName(const TCHAR *lexerName) { + if (!lexerName) return NULL; + for (int i = 0 ; i < _nbLexerStyler ; i++) + { + if (!lstrcmp(_lexerStylerArray[i].getLexerName(), lexerName)) + return &(_lexerStylerArray[i]); + } + return NULL; + }; + bool hasEnoughSpace() {return (_nbLexerStyler < MAX_LEXER_STYLE);}; + void addLexerStyler(const TCHAR *lexerName, const TCHAR *lexerDesc, const TCHAR *lexerUserExt, TiXmlNode *lexerNode); + void eraseAll(); +private : + LexerStyler _lexerStylerArray[MAX_LEXER_STYLE]; + int _nbLexerStyler; +}; + +struct NewDocDefaultSettings +{ + formatType _format; + UniMode _encoding; + bool _openAnsiAsUtf8; + LangType _lang; + NewDocDefaultSettings():_format(WIN_FORMAT), _encoding(uni8Bit), _openAnsiAsUtf8(false), _lang(L_TXT){}; +}; + +struct LangMenuItem { + LangType _langType; + int _cmdID; + generic_string _langName; + + LangMenuItem(LangType lt, int cmdID = 0, generic_string langName = TEXT("")): + _langType(lt), _cmdID(cmdID), _langName(langName){}; +}; + +struct PrintSettings { + bool _printLineNumber; + int _printOption; + + generic_string _headerLeft; + generic_string _headerMiddle; + generic_string _headerRight; + generic_string _headerFontName; + int _headerFontStyle; + int _headerFontSize; + + generic_string _footerLeft; + generic_string _footerMiddle; + generic_string _footerRight; + generic_string _footerFontName; + int _footerFontStyle; + int _footerFontSize; + + RECT _marge; + + PrintSettings() : _printLineNumber(true), _printOption(SC_PRINT_NORMAL), _headerLeft(TEXT("")), _headerMiddle(TEXT("")), _headerRight(TEXT("")),\ + _headerFontName(TEXT("")), _headerFontStyle(0), _headerFontSize(0), _footerLeft(TEXT("")), _footerMiddle(TEXT("")), _footerRight(TEXT("")),\ + _footerFontName(TEXT("")), _footerFontStyle(0), _footerFontSize(0) { + _marge.left = 0; _marge.top = 0; _marge.right = 0; _marge.bottom = 0; + }; + + bool isHeaderPresent() const { + return ((_headerLeft != TEXT("")) || (_headerMiddle != TEXT("")) || (_headerRight != TEXT(""))); + }; + + bool isFooterPresent() const { + return ((_footerLeft != TEXT("")) || (_footerMiddle != TEXT("")) || (_footerRight != TEXT(""))); + }; + + bool isUserMargePresent() const { + return ((_marge.left != 0) || (_marge.top != 0) || (_marge.right != 0) || (_marge.bottom != 0)); + }; +}; + +struct NppGUI +{ + NppGUI() : _toolBarStatus(TB_LARGE), _toolbarShow(true), _statusBarShow(true), _menuBarShow(true),\ + _tabStatus(TAB_DRAWTOPBAR | TAB_DRAWINACTIVETAB | TAB_DRAGNDROP), _splitterPos(POS_HORIZOTAL),\ + _userDefineDlgStatus(UDD_DOCKED), _tabSize(8), _tabReplacedBySpace(false), _fileAutoDetection(cdEnabled), _fileAutoDetectionOriginalValue(_fileAutoDetection),\ + _checkHistoryFiles(true) ,_enableSmartHilite(true), _enableTagsMatchHilite(true), _enableTagAttrsHilite(true), _enableHiliteNonHTMLZone(false),\ + _isMaximized(false), _isMinimizedToTray(false), _rememberLastSession(true), _backup(bak_none), _useDir(false),\ + _doTaskList(true), _maitainIndent(true), _openSaveDir(dir_followCurrent), _styleMRU(true), _styleURL(0),\ + _autocStatus(autoc_none), _autocFromLen(1), _funcParams(false), _definedSessionExt(TEXT("")), _neverUpdate(false),\ + _doesExistUpdater(false), _caretBlinkRate(250), _caretWidth(1), _shortTitlebar(false), _themeName(TEXT("")), _isLangMenuCompact(false) { + _appPos.left = 0; + _appPos.top = 0; + _appPos.right = 700; + _appPos.bottom = 500; + + _backupDir[0] = '\0'; + _defaultDir[0] = 0; + _defaultDirExp[0] = 0; + }; + toolBarStatusType _toolBarStatus; // small, large ou standard + bool _toolbarShow; + bool _statusBarShow; // show ou hide + bool _menuBarShow; + + // 1st bit : draw top bar; + // 2nd bit : draw inactive tabs + // 3rd bit : enable drag & drop + // 4th bit : reduce the height + // 5th bit : enable vertical + // 6th bit : enable multiline + + // 0:don't draw; 1:draw top bar 2:draw inactive tabs 3:draw both 7:draw both+drag&drop + int _tabStatus; + + bool _splitterPos; // horizontal ou vertical + int _userDefineDlgStatus; // (hide||show) && (docked||undocked) + + int _tabSize; + bool _tabReplacedBySpace; + + ChangeDetect _fileAutoDetection; + ChangeDetect _fileAutoDetectionOriginalValue; + bool _checkHistoryFiles; + + RECT _appPos; + + bool _isMaximized; + bool _isMinimizedToTray; + bool _rememberLastSession; + bool _doTaskList; + bool _maitainIndent; + bool _enableSmartHilite; + bool _enableTagsMatchHilite; + bool _enableTagAttrsHilite; + bool _enableHiliteNonHTMLZone; + bool _styleMRU; + + // 0 : do nothing + // 1 : don't draw underline + // 2 : draw underline + int _styleURL; + + NewDocDefaultSettings _newDocDefaultSettings; + void setTabReplacedBySpace(bool b) {_tabReplacedBySpace = b;}; + const NewDocDefaultSettings & getNewDocDefaultSettings() const {return _newDocDefaultSettings;}; + vector _excludedLangList; + bool _isLangMenuCompact; + + PrintSettings _printSettings; + BackupFeature _backup; + bool _useDir; + TCHAR _backupDir[MAX_PATH]; + DockingManagerData _dockingData; + GlobalOverride _globalOverride; + enum AutocStatus{autoc_none, autoc_func, autoc_word}; + AutocStatus _autocStatus; + size_t _autocFromLen; + bool _funcParams; + + generic_string _definedSessionExt; + bool _neverUpdate; + bool _doesExistUpdater; + int _caretBlinkRate; + int _caretWidth; + + bool _shortTitlebar; + + OpenSaveDirSetting _openSaveDir; + TCHAR _defaultDir[MAX_PATH]; + TCHAR _defaultDirExp[MAX_PATH]; //expanded environment variables + generic_string _themeName; +}; + +struct ScintillaViewParams +{ + ScintillaViewParams() : _lineNumberMarginShow(true), _bookMarkMarginShow(true),\ + _folderStyle(FOLDER_STYLE_BOX), _indentGuideLineShow(true),\ + _currentLineHilitingShow(true), _wrapSymbolShow(false), _doWrap(false),\ + _zoom(0), _whiteSpaceShow(false), _eolShow(false){}; + bool _lineNumberMarginShow; + bool _bookMarkMarginShow; + //bool _docChangeStateMarginShow; + folderStyle _folderStyle; //"simple", TEXT("arrow"), TEXT("circle") and "box" + bool _indentGuideLineShow; + bool _currentLineHilitingShow; + bool _wrapSymbolShow; + bool _doWrap; + int _edgeMode; + int _edgeNbColumn; + int _zoom; + bool _whiteSpaceShow; + bool _eolShow; + +}; + +const int NB_LIST = 20; +const int NB_MAX_LRF_FILE = 30; +const int NB_MAX_USER_LANG = 30; +const int NB_MAX_EXTERNAL_LANG = 30; +const int LANG_NAME_LEN = 32; + +const int NB_MAX_FINDHISTORY_FIND = 30; +const int NB_MAX_FINDHISTORY_REPLACE = 30; +const int NB_MAX_FINDHISTORY_PATH = 30; +const int NB_MAX_FINDHISTORY_FILTER = 20; + +struct Lang +{ + LangType _langID; + TCHAR _langName[LANG_NAME_LEN]; + const TCHAR *_defaultExtList; + const TCHAR *_langKeyWordList[NB_LIST]; + const TCHAR *_pCommentLineSymbol; + const TCHAR *_pCommentStart; + const TCHAR *_pCommentEnd; + + Lang() {for (int i = 0 ; i < NB_LIST ; _langKeyWordList[i] = NULL ,i++);}; + Lang(LangType langID, const TCHAR *name) : _langID(langID){ + _langName[0] = '\0'; + if (name) + lstrcpy(_langName, name); + for (int i = 0 ; i < NB_LIST ; _langKeyWordList[i] = NULL ,i++); + }; + ~Lang() {}; + void setDefaultExtList(const TCHAR *extLst){ + _defaultExtList = extLst; + }; + + void setCommentLineSymbol(const TCHAR *commentLine){ + _pCommentLineSymbol = commentLine; + }; + + void setCommentStart(const TCHAR *commentStart){ + _pCommentStart = commentStart; + }; + + void setCommentEnd(const TCHAR *commentEnd){ + _pCommentEnd = commentEnd; + }; + + const TCHAR * getDefaultExtList() const { + return _defaultExtList; + }; + + void setWords(const TCHAR *words, int index) { + _langKeyWordList[index] = words; + }; + + const TCHAR * getWords(int index) const { + return _langKeyWordList[index]; + }; + + LangType getLangID() const {return _langID;}; + const TCHAR * getLangName() const {return _langName;}; +}; + +class UserLangContainer +{ +friend class Notepad_plus; +friend class ScintillaEditView; +friend class NppParameters; + +friend class SharedParametersDialog; +friend class FolderStyleDialog; +friend class KeyWordsStyleDialog; +friend class CommentStyleDialog; +friend class SymbolsStyleDialog; +friend class UserDefineDialog; + +public : + UserLangContainer(){ + _name = TEXT("new user define"); + _ext = TEXT(""); + + // Keywords list of Delimiters (index 0) + lstrcpy(_keywordLists[0], TEXT("000000")); + for (int i = 1 ; i < nbKeywodList ; i++) + *_keywordLists[i] = '\0'; + }; + UserLangContainer(const TCHAR *name, const TCHAR *ext) : _name(name), _ext(ext) { + // Keywords list of Delimiters (index 0) + lstrcpy(_keywordLists[0], TEXT("000000")); + for (int j = 1 ; j < nbKeywodList ; j++) + *_keywordLists[j] = '\0'; + }; + + UserLangContainer & operator=(const UserLangContainer & ulc) { + if (this != &ulc) + { + this->_name = ulc._name; + this->_ext = ulc._ext; + this->_isCaseIgnored = ulc._isCaseIgnored; + this->_styleArray = ulc._styleArray; + int nbStyler = this->_styleArray.getNbStyler(); + for (int i = 0 ; i < nbStyler ; i++) + { + Style & st = this->_styleArray.getStyler(i); + if (st._bgColor == COLORREF(-1)) + st._bgColor = white; + if (st._fgColor == COLORREF(-1)) + st._fgColor = black; + } + for (int i = 0 ; i < nbKeywodList ; i++) + lstrcpy(this->_keywordLists[i], ulc._keywordLists[i]); + } + return *this; + }; + + int getNbKeywordList() {return nbKeywodList;}; + const TCHAR * getName() {return _name.c_str();}; + const TCHAR * getExtention() {return _ext.c_str();}; + +private: + generic_string _name; + generic_string _ext; + + StyleArray _styleArray; + TCHAR _keywordLists[nbKeywodList][max_char]; + + bool _isCaseIgnored; + bool _isCommentLineSymbol; + bool _isCommentSymbol; + bool _isPrefix[nbPrefixListAllowed]; +}; + +#define MAX_EXTERNAL_LEXER_NAME_LEN 16 +#define MAX_EXTERNAL_LEXER_DESC_LEN 32 + +class ExternalLangContainer +{ +public: + TCHAR _name[MAX_EXTERNAL_LEXER_NAME_LEN]; + TCHAR _desc[MAX_EXTERNAL_LEXER_DESC_LEN]; + + ExternalLangContainer(const TCHAR *name, const TCHAR *desc) { + generic_strncpy(_name, name, MAX_EXTERNAL_LEXER_NAME_LEN); + generic_strncpy(_desc, desc, MAX_EXTERNAL_LEXER_DESC_LEN); + }; +}; + +struct FindHistory { + enum searchMode{normal, extended, regExpr}; + enum transparencyMode{none, onLossingFocus, persistant}; + + FindHistory() : _nbMaxFindHistoryPath(10), _nbMaxFindHistoryFilter(10), _nbMaxFindHistoryFind(10), _nbMaxFindHistoryReplace(10),\ + _nbFindHistoryPath(0), _nbFindHistoryFilter(0),_nbFindHistoryFind(0), _nbFindHistoryReplace(0),\ + _isMatchWord(false), _isMatchCase(false),_isWrap(true),_isDirectionDown(true),\ + _isFifRecuisive(true), _isFifInHiddenFolder(false), _isDlgAlwaysVisible(false),\ + _isFilterFollowDoc(false), _isFolderFollowDoc(false),\ + _searchMode(normal), _transparencyMode(onLossingFocus), _transparency(150) + + {}; + int _nbMaxFindHistoryPath; + int _nbMaxFindHistoryFilter; + int _nbMaxFindHistoryFind; + int _nbMaxFindHistoryReplace; + + int _nbFindHistoryPath; + int _nbFindHistoryFilter; + int _nbFindHistoryFind; + int _nbFindHistoryReplace; + + generic_string *_pFindHistoryPath[NB_MAX_FINDHISTORY_PATH]; + generic_string *_pFindHistoryFilter[NB_MAX_FINDHISTORY_FILTER]; + generic_string *_pFindHistoryFind[NB_MAX_FINDHISTORY_FIND]; + generic_string *_pFindHistoryReplace[NB_MAX_FINDHISTORY_REPLACE]; + + bool _isMatchWord; + bool _isMatchCase; + bool _isWrap; + bool _isDirectionDown; + + bool _isFifRecuisive; + bool _isFifInHiddenFolder; + + searchMode _searchMode; + transparencyMode _transparencyMode; + int _transparency; + + bool _isDlgAlwaysVisible; + bool _isFilterFollowDoc; + bool _isFolderFollowDoc; +}; + + +#ifdef UNICODE + +class LocalizationSwitcher { +friend class NppParameters; +public : + LocalizationSwitcher() {}; + + struct LocalizationDefinition { + wchar_t *_langName; + wchar_t *_xmlFileName; + }; + + bool addLanguageFromXml(wstring xmlFullPath); + wstring getLangFromXmlFileName(wchar_t *fn) const; + + wstring getXmlFilePathFromLangName(wchar_t *langName) const; + bool switchToLang(wchar_t *lang2switch) const; + + size_t size() const { + return _localizationList.size(); + }; + + pair getElementFromIndex(size_t index) { + if (index >= _localizationList.size()) + return pair(TEXT(""), TEXT("")); + return _localizationList[index]; + }; + +private : + vector< pair< wstring, wstring > > _localizationList; + wstring _nativeLangPath; +}; +#endif + +class ThemeSwitcher { +friend class NppParameters; + +public : + ThemeSwitcher(){}; + + struct ThemeDefinition { + TCHAR *_themeName; + TCHAR *_xmlFileName; + }; + + void addThemeFromXml(generic_string xmlFullPath) { + _themeList.push_back(pair(getThemeFromXmlFileName(xmlFullPath.c_str()), xmlFullPath)); + }; + + void addDefaultThemeFromXml(generic_string xmlFullPath) { + _themeList.push_back(pair(TEXT("Default"), xmlFullPath)); + }; + + generic_string getThemeFromXmlFileName(const TCHAR *fn) const; + + generic_string getXmlFilePathFromThemeName(const TCHAR *themeName) const { + if (!themeName || themeName[0]) + return TEXT(""); + generic_string themePath = _stylesXmlPath; + return themePath; + }; + + bool themeNameExists(const TCHAR *themeName) { + for (size_t i = 0; i < _themeList.size(); i++ ) + { + if (! (getElementFromIndex(i)).first.compare(themeName) ) return true; + } + return false; + } + + size_t size() const { + return _themeList.size(); + }; + + + pair & getElementFromIndex(size_t index) { + //if (index >= _themeList.size()) + //return pair(TEXT(""), TEXT("")); + return _themeList[index]; + }; + +private : + vector< pair< generic_string, generic_string > > _themeList; + generic_string _stylesXmlPath; +}; + +const int NB_LANG = 80; + +const bool DUP = true; +const bool FREE = false; + +class NppParameters +{ +public: + static NppParameters * getInstance() {return _pSelf;}; + static LangType getLangIDFromStr(const TCHAR *langName); + bool load(); + bool reloadLang(); + bool reloadStylers(TCHAR *stylePath = NULL); + void destroyInstance(); + + bool _isTaskListRBUTTONUP_Active; + int L_END; + + const NppGUI & getNppGUI() const { + return _nppGUI; + }; + + const TCHAR * getWordList(LangType langID, int typeIndex) const { + Lang *pLang = getLangFromID(langID); + if (!pLang) return NULL; + + return pLang->getWords(typeIndex); + }; + + Lang * getLangFromID(LangType langID) const { + for (int i = 0 ; i < _nbLang ; i++) + { + if ((_langList[i]->_langID == langID) || (!_langList[i])) + return _langList[i]; + } + return NULL; + }; + + Lang * getLangFromIndex(int i) const { + if (i >= _nbLang) return NULL; + return _langList[i]; + }; + + int getNbLang() const {return _nbLang;}; + + const TCHAR * getLangExtFromName(const TCHAR *langName) const { + for (int i = 0 ; i < _nbLang ; i++) + { + if (!lstrcmp(_langList[i]->_langName, langName)) + return _langList[i]->_defaultExtList; + } + return NULL; + }; + + const TCHAR * getLangExtFromLangType(LangType langType) const { + for (int i = 0 ; i < _nbLang ; i++) + { + if (_langList[i]->_langID == langType) + return _langList[i]->_defaultExtList; + } + return NULL; + }; + + int getNbLRFile() const {return _nbFile;}; + + generic_string *getLRFile(int index) const { + return _LRFileList[index]; + }; + + void setNbMaxFile(int nb) { + _nbMaxFile = nb; + }; + + int getNbMaxFile() const {return _nbMaxFile;}; + + const ScintillaViewParams & getSVP(bool whichOne) const { + return _svp[whichOne]; + }; + + bool writeNbHistoryFile(int nb) { + if (!_pXmlUserDoc) return false; + + TiXmlNode *nppRoot = _pXmlUserDoc->FirstChild(TEXT("NotepadPlus")); + if (!nppRoot) return false; + + TiXmlNode *historyNode = nppRoot->FirstChildElement(TEXT("History")); + if (!historyNode) return false; + + (historyNode->ToElement())->SetAttribute(TEXT("nbMaxFile"), nb); + return true; + }; + + bool writeHistory(const TCHAR *fullpath); + + TiXmlNode * getChildElementByAttribut(TiXmlNode *pere, const TCHAR *childName,\ + const TCHAR *attributName, const TCHAR *attributVal) const; + + bool writeScintillaParams(const ScintillaViewParams & svp, bool whichOne); + + bool writeGUIParams(); + + void writeStyles(LexerStylerArray & lexersStylers, StyleArray & globalStylers); + + LexerStylerArray & getLStylerArray() {return _lexerStylerArray;}; + StyleArray & getGlobalStylers() {return _widgetStyleArray;}; + + StyleArray & getMiscStylerArray() {return _widgetStyleArray;}; + GlobalOverride & getGlobalOverrideStyle() {return _nppGUI._globalOverride;}; + + COLORREF getCurLineHilitingColour() { + int i = _widgetStyleArray.getStylerIndexByName(TEXT("Current line background colour")); + if (i == -1) return i; + Style & style = _widgetStyleArray.getStyler(i); + return style._bgColor; + }; + void setCurLineHilitingColour(COLORREF colour2Set) { + int i = _widgetStyleArray.getStylerIndexByName(TEXT("Current line background colour")); + if (i == -1) return; + Style & style = _widgetStyleArray.getStyler(i); + style._bgColor = colour2Set; + }; + + void setFontList(HWND hWnd); + const vector & getFontList() const {return _fontlist;}; + + int getNbUserLang() const {return _nbUserLang;}; + UserLangContainer & getULCFromIndex(int i) {return *_userLangArray[i];}; + UserLangContainer * getULCFromName(const TCHAR *userLangName) { + for (int i = 0 ; i < _nbUserLang ; i++) + if (!lstrcmp(userLangName, _userLangArray[i]->_name.c_str())) + return _userLangArray[i]; + //qui doit etre jamais passer + return NULL; + }; + + int getNbExternalLang() const {return _nbExternalLang;}; + int getExternalLangIndexFromName(const TCHAR *externalLangName) const { + for (int i = 0 ; i < _nbExternalLang ; i++) + { + if (!lstrcmp(externalLangName, _externalLangArray[i]->_name)) + return i; + } + return -1; + }; + ExternalLangContainer & getELCFromIndex(int i) {return *_externalLangArray[i];}; + + bool ExternalLangHasRoom() const {return _nbExternalLang < NB_MAX_EXTERNAL_LANG;}; + + void getExternalLexerFromXmlTree(TiXmlDocument *doc); + vector * getExternalLexerDoc() { return &_pXmlExternalLexerDoc;}; + + void writeUserDefinedLang(); + void writeShortcuts(); + void writeSession(const Session & session, const TCHAR *fileName = NULL); + bool writeFindHistory(); + + + bool isExistingUserLangName(const TCHAR *newName) const { + if ((!newName) || (!newName[0])) + return true; + + for (int i = 0 ; i < _nbUserLang ; i++) + { + if (!lstrcmp(_userLangArray[i]->_name.c_str(), newName)) + return true; + } + return false; + }; + + const TCHAR * getUserDefinedLangNameFromExt(TCHAR *ext) { + if ((!ext) || (!ext[0])) + return NULL; + + for (int i = 0 ; i < _nbUserLang ; i++) + { + vector extVect; + cutString(_userLangArray[i]->_ext.c_str(), extVect); + for (size_t j = 0 ; j < extVect.size() ; j++) + if (!generic_stricmp(extVect[j].c_str(), ext)) + return _userLangArray[i]->_name.c_str(); + } + return NULL; + }; + + int addUserLangToEnd(const UserLangContainer & userLang, const TCHAR *newName); + void removeUserLang(int index); + + bool isExistingExternalLangName(const TCHAR *newName) const { + if ((!newName) || (!newName[0])) + return true; + + for (int i = 0 ; i < _nbExternalLang ; i++) + { + if (!lstrcmp(_externalLangArray[i]->_name, newName)) + return true; + } + return false; + }; + + int addExternalLangToEnd(ExternalLangContainer * externalLang); + + //TiXmlDocument * getNativeLang() const {return _pXmlNativeLangDoc;}; + + TiXmlDocumentA * getNativeLangA() const {return _pXmlNativeLangDocA;}; + + TiXmlDocument * getToolIcons() const {return _pXmlToolIconsDoc;}; + + bool isTransparentAvailable() const { + return (_transparentFuncAddr != NULL); + }; + + void SetTransparent(HWND hwnd, int percent) { + if (!_transparentFuncAddr) return; + ::SetWindowLongPtr(hwnd, GWL_EXSTYLE, ::GetWindowLongPtr(hwnd, GWL_EXSTYLE) | 0x00080000); + _transparentFuncAddr(hwnd, 0, percent, 0x00000002); + }; + + void removeTransparent(HWND hwnd) { + ::SetWindowLongPtr(hwnd, GWL_EXSTYLE, ::GetWindowLongPtr(hwnd, GWL_EXSTYLE) & ~0x00080000); + }; + + void setCmdlineParam(const CmdLineParams & cmdLineParams) { + _cmdLineParams = cmdLineParams; + }; + CmdLineParams & getCmdLineParams() {return _cmdLineParams;}; + + void setFileSaveDlgFilterIndex(int ln) {_fileSaveDlgFilterIndex = ln;}; + int getFileSaveDlgFilterIndex() const {return _fileSaveDlgFilterIndex;}; + + bool isRemappingShortcut() const {return _shortcuts.size() != 0;}; + + vector & getUserShortcuts() {return _shortcuts;}; + vector & getUserModifiedShortcuts() {return _customizedShortcuts;}; + void addUserModifiedIndex(int index); + + vector & getMacroList() {return _macros;}; + vector & getUserCommandList() {return _userCommands;}; + vector & getPluginCommandList() {return _pluginCommands;}; + vector & getPluginModifiedKeyIndices() {return _pluginCustomizedCmds;}; + void addPluginModifiedIndex(int index); + + vector & getScintillaKeyList() {return _scintillaKeyCommands;}; + vector & getScintillaModifiedKeyIndices() {return _scintillaModifiedKeyIndices;}; + void addScintillaModifiedIndex(int index); + + vector & getContextMenuItems() {return _contextMenuItems;}; + const Session & getSession() const {return _session;}; + bool hasCustomContextMenu() const {return !_contextMenuItems.empty();}; + + void setAccelerator(Accelerator *pAccel) {_pAccelerator = pAccel;}; + Accelerator * getAccelerator() {return _pAccelerator;}; + void setScintillaAccelerator(ScintillaAccelerator *pScintAccel) {_pScintAccelerator = pScintAccel;}; + ScintillaAccelerator * getScintillaAccelerator() {return _pScintAccelerator;}; + + const TCHAR * getNppPath() const {return _nppPath;}; + const TCHAR * getAppDataNppDir() const {return _appdataNppDir;}; + const TCHAR * getWorkingDir() const {return _currentDirectory;}; + void setWorkingDir(const TCHAR * newPath); + + bool loadSession(Session & session, const TCHAR *sessionFileName); + int langTypeToCommandID(LangType lt) const; + WNDPROC getEnableThemeDlgTexture() const {return _enableThemeDialogTextureFuncAddr;}; + + struct FindDlgTabTitiles { + generic_string _find; + generic_string _replace; + generic_string _findInFiles; + FindDlgTabTitiles() : _find(TEXT("")), _replace(TEXT("")), _findInFiles(TEXT("")) {}; + bool isWellFilled() { + return (lstrcmp(_find.c_str(), TEXT("")) != 0 && lstrcmp(_replace.c_str(), TEXT("")) && lstrcmp(_findInFiles.c_str(), TEXT(""))); + }; + }; + + FindDlgTabTitiles & getFindDlgTabTitiles() { return _findDlgTabTitiles;}; + + const char * getNativeLangMenuStringA(int itemID) { + if (!_pXmlNativeLangDocA) + return NULL; + + TiXmlNodeA * node = _pXmlNativeLangDocA->FirstChild("NotepadPlus"); + if (!node) return NULL; + + node = node->FirstChild("Native-Langue"); + if (!node) return NULL; + + node = node->FirstChild("Menu"); + if (!node) return NULL; + + node = node->FirstChild("Main"); + if (!node) return NULL; + + node = node->FirstChild("Commands"); + if (!node) return NULL; + + for (TiXmlNodeA *childNode = node->FirstChildElement("Item"); + childNode ; + childNode = childNode->NextSibling("Item") ) + { + TiXmlElementA *element = childNode->ToElement(); + int id; + if (element->Attribute("id", &id) && (id == itemID)) + { + return element->Attribute("name"); + } + } + return NULL; + }; + + bool asNotepadStyle() const {return _asNotepadStyle;}; + + bool reloadPluginCmds() { + return getPluginCmdsFromXmlTree(); + } + + bool getContextMenuFromXmlTree(HMENU mainMenuHadle); + bool reloadContextMenuFromXmlTree(HMENU mainMenuHadle); + winVer getWinVersion() { return _winVersion;}; + FindHistory & getFindHistory() {return _findHistory;}; + bool _isFindReplacing; // an on the fly variable for find/replace functions + +#ifdef UNICODE + LocalizationSwitcher & getLocalizationSwitcher() { + return _localizationSwitcher; + }; +#endif + ThemeSwitcher & getThemeSwitcher() { + return _themeSwitcher; + }; + +private: + NppParameters(); + ~NppParameters(); + + static NppParameters *_pSelf; + + TiXmlDocument *_pXmlDoc, *_pXmlUserDoc, *_pXmlUserStylerDoc, *_pXmlUserLangDoc,\ + *_pXmlToolIconsDoc, *_pXmlShortcutDoc, *_pXmlContextMenuDoc, *_pXmlSessionDoc; + + TiXmlDocumentA *_pXmlNativeLangDocA; + //TiXmlDocumentA *_pXmlEnglishDocA; + + vector _pXmlExternalLexerDoc; + + NppGUI _nppGUI; + ScintillaViewParams _svp[2]; + Lang *_langList[NB_LANG]; + int _nbLang; + + generic_string *_LRFileList[NB_MAX_LRF_FILE]; + int _nbFile; + int _nbMaxFile; + + FindHistory _findHistory; + + UserLangContainer *_userLangArray[NB_MAX_USER_LANG]; + int _nbUserLang; + TCHAR _userDefineLangPath[MAX_PATH]; + ExternalLangContainer *_externalLangArray[NB_MAX_EXTERNAL_LANG]; + int _nbExternalLang; + + CmdLineParams _cmdLineParams; + + int _fileSaveDlgFilterIndex; + + // All Styles (colours & fonts) + LexerStylerArray _lexerStylerArray; + StyleArray _widgetStyleArray; + + vector _fontlist; + + HMODULE _hUser32; + HMODULE _hUXTheme; + + WNDPROC _transparentFuncAddr; + WNDPROC _enableThemeDialogTextureFuncAddr; + + + vector _shortcuts; //main menu shortuts. Static size + vector _customizedShortcuts; //altered main menu shortcuts. Indices static. Needed when saving alterations + vector _macros; //macro shortcuts, dynamic size, defined on loading macros and adding/deleting them + vector _userCommands; //run shortcuts, dynamic size, defined on loading run commands and adding/deleting them + vector _pluginCommands; //plugin commands, dynamic size, defined on loading plugins + vector _pluginCustomizedCmds; //plugincommands that have been altered. Indices determined after loading ALL plugins. Needed when saving alterations + + vector _scintillaKeyCommands; //scintilla keycommands. Static size + vector _scintillaModifiedKeyIndices; //modified scintilla keys. Indices static, determined by searching for commandId. Needed when saving alterations +#ifdef UNICODE + LocalizationSwitcher _localizationSwitcher; +#endif + ThemeSwitcher _themeSwitcher; + + //vector _noMenuCmdNames; + vector _contextMenuItems; + Session _session; + + TCHAR _shortcutsPath[MAX_PATH]; + TCHAR _contextMenuPath[MAX_PATH]; + TCHAR _sessionPath[MAX_PATH]; + TCHAR _nppPath[MAX_PATH]; + TCHAR _userPath[MAX_PATH]; + TCHAR _stylerPath[MAX_PATH]; + TCHAR _appdataNppDir[MAX_PATH]; // sentinel of the absence of "doLocalConf.xml" : (_appdataNppDir == TEXT(""))?"doLocalConf.xml present":"doLocalConf.xml absent" + TCHAR _currentDirectory[MAX_PATH]; + + Accelerator *_pAccelerator; + ScintillaAccelerator * _pScintAccelerator; + + FindDlgTabTitiles _findDlgTabTitiles; + bool _asNotepadStyle; + + winVer _winVersion; + + static int CALLBACK EnumFontFamExProc(ENUMLOGFONTEX *lpelfe, NEWTEXTMETRICEX *lpntme, int FontType, LPARAM lParam) { + vector *pStrVect = (vector *)lParam; + size_t vectSize = pStrVect->size(); + + //Search through all the fonts, EnumFontFamiliesEx never states anything about order + //Start at the end though, that's the most likely place to find a duplicate + for(int i = vectSize - 1 ; i >= 0 ; i--) { + if ( !lstrcmp((*pStrVect)[i].c_str(), (const TCHAR *)lpelfe->elfLogFont.lfFaceName) ) + return 1; //we already have seen this typeface, ignore it + } + //We can add the font + //Add the face name and not the full name, we do not care about any styles + pStrVect->push_back((TCHAR *)lpelfe->elfLogFont.lfFaceName); + return 1; // I want to get all fonts + }; + + void getLangKeywordsFromXmlTree(); + bool getUserParametersFromXmlTree(); + bool getUserStylersFromXmlTree(); + bool getUserDefineLangsFromXmlTree(); + bool getShortcutsFromXmlTree(); + + bool getMacrosFromXmlTree(); + bool getUserCmdsFromXmlTree(); + bool getPluginCmdsFromXmlTree(); + bool getScintKeysFromXmlTree(); + bool getSessionFromXmlTree(TiXmlDocument *pSessionDoc = NULL, Session *session = NULL); + + void feedGUIParameters(TiXmlNode *node); + void feedKeyWordsParameters(TiXmlNode *node); + void feedFileListParameters(TiXmlNode *node); + void feedScintillaParam(bool whichOne, TiXmlNode *node); + void feedDockingManager(TiXmlNode *node); + void feedFindHistoryParameters(TiXmlNode *node); + + bool feedStylerArray(TiXmlNode *node); + void getAllWordStyles(TCHAR *lexerName, TiXmlNode *lexerNode); + + void feedUserLang(TiXmlNode *node); + int getIndexFromKeywordListName(const TCHAR *name); + void feedUserStyles(TiXmlNode *node); + void feedUserKeywordList(TiXmlNode *node); + void feedUserSettings(TiXmlNode *node); + + void feedShortcut(TiXmlNode *node); + void feedMacros(TiXmlNode *node); + void feedUserCmds(TiXmlNode *node); + void feedPluginCustomizedCmds(TiXmlNode *node); + void feedScintKeys(TiXmlNode *node); + + void getActions(TiXmlNode *node, Macro & macro); + bool getShortcuts(TiXmlNode *node, Shortcut & sc); + + void writeStyle2Element(Style & style2Wite, Style & style2Sync, TiXmlElement *element); + void insertUserLang2Tree(TiXmlNode *node, UserLangContainer *userLang); + void insertCmd(TiXmlNode *cmdRoot, const CommandShortcut & cmd); + void insertMacro(TiXmlNode *macrosRoot, const MacroShortcut & macro); + void insertUserCmd(TiXmlNode *userCmdRoot, const UserCommand & userCmd); + void insertScintKey(TiXmlNode *scintKeyRoot, const ScintillaKeyMap & scintKeyMap); + void insertPluginCmd(TiXmlNode *pluginCmdRoot, const PluginCmdShortcut & pluginCmd); + void stylerStrOp(bool op); + TiXmlElement * insertGUIConfigBoolNode(TiXmlNode *r2w, const TCHAR *name, bool bVal); + void insertDockingParamNode(TiXmlNode *GUIRoot); + void writeExcludedLangList(TiXmlElement *element); + void writePrintSetting(TiXmlElement *element); + void initMenuKeys(); //initialise menu keys and scintilla keys. Other keys are initialized on their own + void initScintillaKeys(); //these functions have to be called first before any modifications are loaded +}; + +#endif //PARAMETERS_H diff --git a/PowerEditor/src/ScitillaComponent/AutoCompletion.cpp b/PowerEditor/src/ScitillaComponent/AutoCompletion.cpp new file mode 100644 index 00000000..ad14a07a --- /dev/null +++ b/PowerEditor/src/ScitillaComponent/AutoCompletion.cpp @@ -0,0 +1,306 @@ +//this file is part of Notepad++ +//Copyright (C)2008 Harry Bruin +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#include "AutoCompletion.h" +#include "Notepad_plus_msgs.h" +#include + +static bool isInList(generic_string word, const vector & wordArray) +{ + for (size_t i = 0 ; i < wordArray.size() ; i++) + if (wordArray[i] == word) + return true; + return false; +}; + +AutoCompletion::AutoCompletion(ScintillaEditView * pEditView) : _funcCompletionActive(false), _pEditView(pEditView), _funcCalltip(pEditView), + _curLang(L_TXT), _XmlFile(TEXT("")), _activeCompletion(CompletionNone), + _pXmlKeyword(NULL), _ignoreCase(true), _keyWords(TEXT("")) +{ + //Do not load any language yet +} + +bool AutoCompletion::showAutoComplete() { + if (!_funcCompletionActive) + return false; + + int curPos = int(_pEditView->execute(SCI_GETCURRENTPOS)); + int line = _pEditView->getCurrentLineNumber(); + int startLinePos = int(_pEditView->execute(SCI_POSITIONFROMLINE, line )); + int startWordPos = startLinePos; + + int len = curPos-startLinePos; + char * lineBuffer = new char[len+1]; + _pEditView->getText(lineBuffer, startLinePos, curPos); + + int offset = len-1; + int nrChars = 0; + char c; + while (offset>=0) + { + c = lineBuffer[offset]; + if (isalnum(c) || c == '_') { + nrChars++; + } else { + break; + } + offset--; + + } + startWordPos = curPos-nrChars; + + _pEditView->execute(SCI_AUTOCSETSEPARATOR, WPARAM('\n')); + _pEditView->execute(SCI_AUTOCSETIGNORECASE, _ignoreCase); + _pEditView->showAutoComletion(curPos - startWordPos, _keyWords.c_str()); + + _activeCompletion = CompletionAuto; + return true; +} + +bool AutoCompletion::showWordComplete(bool autoInsert) +{ + int curPos = int(_pEditView->execute(SCI_GETCURRENTPOS)); + int startPos = int(_pEditView->execute(SCI_WORDSTARTPOSITION, curPos, true)); + + if (curPos == startPos) + return false; + + const size_t bufSize = 256; + size_t len = (curPos > startPos)?(curPos - startPos):(startPos - curPos); + if (len >= bufSize) + return false; + + TCHAR beginChars[bufSize]; + + _pEditView->getGenericText(beginChars, startPos, curPos); + + generic_string expr(TEXT("\\<")); + expr += beginChars; + expr += TEXT("[^ \\t.,;:\"()=<>'+!\\[\\]]*"); + + int docLength = int(_pEditView->execute(SCI_GETLENGTH)); + + int flags = SCFIND_WORDSTART | SCFIND_MATCHCASE | SCFIND_REGEXP | SCFIND_POSIX; + + _pEditView->execute(SCI_SETSEARCHFLAGS, flags); + vector wordArray; + int posFind = _pEditView->searchInTarget(expr.c_str(), 0, docLength); + + while (posFind != -1) + { + int wordStart = int(_pEditView->execute(SCI_GETTARGETSTART)); + int wordEnd = int(_pEditView->execute(SCI_GETTARGETEND)); + + size_t foundTextLen = wordEnd - wordStart; + + if (foundTextLen < bufSize) + { + TCHAR w[bufSize]; + _pEditView->getGenericText(w, wordStart, wordEnd); + + if (lstrcmp(w, beginChars)) + if (!isInList(w, wordArray)) + wordArray.push_back(w); + } + posFind = _pEditView->searchInTarget(expr.c_str(), wordEnd, docLength); + } + if (wordArray.size() == 0) return false; + + if (wordArray.size() == 1 && autoInsert) + { + _pEditView->replaceTargetRegExMode(wordArray[0].c_str(), startPos, curPos); + _pEditView->execute(SCI_GOTOPOS, startPos + wordArray[0].length()); + return true; + } + + sort(wordArray.begin(), wordArray.end()); + generic_string words(TEXT("")); + + for (size_t i = 0 ; i < wordArray.size() ; i++) + { + words += wordArray[i]; + if (i != wordArray.size()-1) + words += TEXT(" "); + } + + // UNICODE TO DO + _pEditView->execute(SCI_AUTOCSETSEPARATOR, WPARAM(' ')); + _pEditView->execute(SCI_AUTOCSETIGNORECASE, _ignoreCase); + _pEditView->showAutoComletion(curPos - startPos, words.c_str()); + + _activeCompletion = CompletionWord; + return true; +} + +bool AutoCompletion::showFunctionComplete() { + if (!_funcCompletionActive) + return false; + + if (_funcCalltip.updateCalltip(0, true)) { + _activeCompletion = CompletionFunc; + return true; + } + return false; +} + +void AutoCompletion::update(int character) +{ + const NppGUI & nppGUI = NppParameters::getInstance()->getNppGUI(); + if (!_funcCompletionActive && nppGUI._autocStatus == nppGUI.autoc_func) + return; + + if (nppGUI._funcParams || _funcCalltip.isVisible()) { + if (_funcCalltip.updateCalltip(character)) { //calltip visible because triggered by autocomplete, set mode + _activeCompletion = CompletionFunc; + return; //only return in case of success, else autocomplete + } + } + + if (!character) + return; + + //If autocomplete already active, let Scintilla handle it + if (_pEditView->execute(SCI_AUTOCACTIVE) != 0) + return; + + const int wordSize = 64; + TCHAR s[wordSize]; + _pEditView->getWordToCurrentPos(s, wordSize); + + if (lstrlen(s) >= int(nppGUI._autocFromLen)) + { + if (nppGUI._autocStatus == nppGUI.autoc_word) + showWordComplete(false); + else if (nppGUI._autocStatus == nppGUI.autoc_func) + showAutoComplete(); + } +} + +void AutoCompletion::callTipClick(int direction) { + if (!_funcCompletionActive) + return; + + if (direction == 1) { + _funcCalltip.showPrevOverload(); + } else if (direction == 2) { + _funcCalltip.showNextOverload(); + } +} + +bool AutoCompletion::setLanguage(LangType language) { + if (_curLang == language) + return true; + _curLang = language; + + TCHAR path[MAX_PATH]; + ::GetModuleFileName(NULL, path, MAX_PATH); + PathRemoveFileSpec(path); + lstrcat(path, TEXT("\\plugins\\APIs\\")); + lstrcat(path, getApiFileName()); + lstrcat(path, TEXT(".xml")); + + _XmlFile = TiXmlDocument(path); + _funcCompletionActive = _XmlFile.LoadFile(); + + TiXmlNode * pAutoNode = NULL; + if (_funcCompletionActive) { + _funcCompletionActive = false; //safety + TiXmlNode * pNode = _XmlFile.FirstChild(TEXT("NotepadPlus")); + if (!pNode) + return false; + pAutoNode = pNode = pNode->FirstChildElement(TEXT("AutoComplete")); + if (!pNode) + return false; + pNode = pNode->FirstChildElement(TEXT("KeyWord")); + if (!pNode) + return false; + _pXmlKeyword = reinterpret_cast(pNode); + if (!_pXmlKeyword) + return false; + _funcCompletionActive = true; + } + + if(_funcCompletionActive) { //try setting up environment + //setup defaults + _ignoreCase = true; + _funcCalltip._start = '('; + _funcCalltip._stop = ')'; + _funcCalltip._param = ','; + _funcCalltip._terminal = ';'; + _funcCalltip._ignoreCase = true; + + TiXmlElement * pElem = pAutoNode->FirstChildElement(TEXT("Environment")); + if (pElem) { + const TCHAR * val = 0; + val = pElem->Attribute(TEXT("ignoreCase")); + if (val && !lstrcmp(val, TEXT("no"))) { + _ignoreCase = false; + _funcCalltip._ignoreCase = false; + } + val = pElem->Attribute(TEXT("startFunc")); + if (val && val[0]) + _funcCalltip._start = val[0]; + val = pElem->Attribute(TEXT("stopFunc")); + if (val && val[0]) + _funcCalltip._stop = val[0]; + val = pElem->Attribute(TEXT("paramSeparator")); + if (val && val[0]) + _funcCalltip._param = val[0]; + val = pElem->Attribute(TEXT("terminal")); + if (val && val[0]) + _funcCalltip._terminal = val[0]; + } + } + + if (_funcCompletionActive) { + _funcCalltip.setLanguageXML(_pXmlKeyword); + } else { + _funcCalltip.setLanguageXML(NULL); + } + + _keyWords = TEXT(""); + if (_funcCompletionActive) { //Cache the keywords + //Iterate through all keywords + TiXmlElement *funcNode = _pXmlKeyword; + const TCHAR * name = NULL; + for (; funcNode; funcNode = funcNode->NextSiblingElement(TEXT("KeyWord")) ) { + name = funcNode->Attribute(TEXT("name")); + if (!name) //malformed node + continue; + _keyWords.append(name); + _keyWords.append(TEXT("\n")); + } + } + return _funcCompletionActive; +} + +const TCHAR * AutoCompletion::getApiFileName() { + if (_curLang == L_USER) + { + Buffer * currentBuf = _pEditView->getCurrentBuffer(); + if (currentBuf->isUserDefineLangExt()) + { + return currentBuf->getUserDefineLangName(); + } + } + + if (_curLang >= L_EXTERNAL && _curLang < NppParameters::getInstance()->L_END) + return NppParameters::getInstance()->getELCFromIndex(_curLang - L_EXTERNAL)._name; + + return ScintillaEditView::langNames[_curLang].lexerName; + +} diff --git a/PowerEditor/src/ScitillaComponent/AutoCompletion.h b/PowerEditor/src/ScitillaComponent/AutoCompletion.h new file mode 100644 index 00000000..86b32d6c --- /dev/null +++ b/PowerEditor/src/ScitillaComponent/AutoCompletion.h @@ -0,0 +1,57 @@ +//this file is part of Notepad++ +//Copyright (C)2008 Harry Bruin +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef AUTOCOMPLETION_H +#define AUTOCOMPLETION_H + +#include "ScintillaEditView.h" +#include "FunctionCallTip.h" +#include "tinyxml.h" + +class AutoCompletion { +public: + enum ActiveCompletion {CompletionNone = 0, CompletionAuto, CompletionWord, CompletionFunc}; + AutoCompletion(ScintillaEditView * pEditView); + bool setLanguage(LangType language); + + //AutoComplete from the list + bool showAutoComplete(); + //WordCompletion from the current file + bool showWordComplete(bool autoInsert); //autoInsert true if completion should fill in the word on a single match + //Parameter display from the list + bool showFunctionComplete(); + + void update(int character); + void callTipClick(int direction); + +private: + bool _funcCompletionActive; + ScintillaEditView * _pEditView; + LangType _curLang; + TiXmlDocument _XmlFile; + TiXmlElement * _pXmlKeyword; + ActiveCompletion _activeCompletion; + + bool _ignoreCase; + + std::generic_string _keyWords; + + FunctionCallTip _funcCalltip; + const TCHAR * getApiFileName(); +}; + +#endif //AUTOCOMPLETION_H diff --git a/PowerEditor/src/ScitillaComponent/Buffer.cpp b/PowerEditor/src/ScitillaComponent/Buffer.cpp new file mode 100644 index 00000000..a83b4855 --- /dev/null +++ b/PowerEditor/src/ScitillaComponent/Buffer.cpp @@ -0,0 +1,723 @@ +#include "Buffer.h" + +#include +#include +#include +#include "Scintilla.h" +#include "Parameters.h" + + +#include "Notepad_plus.h" +#include "ScintillaEditView.h" + +FileManager * FileManager::_pSelf = new FileManager(); + +const int blockSize = 128 * 1024 + 4; + +// Ordre important!! Ne le changes pas! +//SC_EOL_CRLF (0), SC_EOL_CR (1), or SC_EOL_LF (2). + +const int CR = 0x0D; +const int LF = 0x0A; + +static bool isInList(const TCHAR *token, const TCHAR *list) { + if ((!token) || (!list)) + return false; + TCHAR word[64]; + int i = 0; + int j = 0; + for (; i <= int(lstrlen(list)) ; i++) + { + if ((list[i] == ' ')||(list[i] == '\0')) + { + if (j != 0) + { + word[j] = '\0'; + j = 0; + + if (!generic_stricmp(token, word)) + return true; + } + } + else + { + word[j] = list[i]; + j++; + } + } + return false; +}; + +void Buffer::determinateFormat(const char *data) { + _format = WIN_FORMAT; + size_t len = strlen(data); + for (size_t i = 0 ; i < len ; i++) + { + if (data[i] == CR) + { + if (data[i+1] == LF) + { + _format = WIN_FORMAT; + break; + } + else + { + _format = MAC_FORMAT; + break; + } + } + if (data[i] == LF) + { + _format = UNIX_FORMAT; + break; + } + } + + doNotify(BufferChangeFormat); + return; +}; + +long Buffer::_recentTagCtr = 0; + +void Buffer::updateTimeStamp() { + struct _stat buf; + time_t timeStamp = (generic_stat(_fullPathName, &buf)==0)?buf.st_mtime:0; + + if (timeStamp != _timeStamp) { + _timeStamp = timeStamp; + doNotify(BufferChangeTimestamp); + } +}; + +// Set full path file name in buffer object, +// and determinate its language by its extension. +// If the ext is not in the list, the defaultLang passed as argument will be set. +void Buffer::setFileName(const TCHAR *fn, LangType defaultLang) +{ + NppParameters *pNppParamInst = NppParameters::getInstance(); + if (!lstrcmpi(fn, _fullPathName)) { + updateTimeStamp(); + doNotify(BufferChangeTimestamp); + return; + } + lstrcpy(_fullPathName, fn); + _fileName = PathFindFileName(_fullPathName); + + // for _lang + LangType newLang = defaultLang; + TCHAR *ext = PathFindExtension(_fullPathName); + if (*ext == '.') { //extension found + ext += 1; + + // Define User Lang firstly + const TCHAR *langName = NULL; + if ((langName = pNppParamInst->getUserDefinedLangNameFromExt(ext))) + { + newLang = L_USER; + lstrcpy(_userLangExt, langName); + } + else // if it's not user lang, then check if it's supported lang + { + _userLangExt[0] = '\0'; + newLang = getLangFromExt(ext); + } + } + + if (newLang == defaultLang || newLang == L_TXT) //language can probably be refined + { + if ((!generic_stricmp(_fileName, TEXT("makefile"))) || (!generic_stricmp(_fileName, TEXT("GNUmakefile")))) + newLang = L_MAKEFILE; + else if (!generic_stricmp(_fileName, TEXT("CmakeLists.txt"))) + newLang = L_CMAKE; + else if ((!generic_stricmp(_fileName, TEXT("SConstruct"))) || (!generic_stricmp(_fileName, TEXT("SConscript")))) + newLang = L_PYTHON; + + } + + updateTimeStamp(); + if (newLang != _lang || _lang == L_USER) { + _lang = newLang; + doNotify(BufferChangeFilename | BufferChangeLanguage | BufferChangeTimestamp); + return; + } + + doNotify(BufferChangeFilename | BufferChangeTimestamp); +} + +bool Buffer::checkFileState() { //returns true if the status has been changed (it can change into DOC_REGULAR too). false otherwise + struct _stat buf; + + if (_currentStatus == DOC_UNNAMED) //unsaved document cannot change by environment + return false; + + if (_currentStatus != DOC_DELETED && !PathFileExists(_fullPathName)) //document has been deleted + { + _currentStatus = DOC_DELETED; + _isFileReadOnly = false; + _isDirty = true; //dirty sicne no match with filesystem + _timeStamp = 0; + doNotify(BufferChangeStatus | BufferChangeReadonly | BufferChangeTimestamp); + return true; + } + + if (_currentStatus == DOC_DELETED && PathFileExists(_fullPathName)) + { //document has returned from its grave + + if (!generic_stat(_fullPathName, &buf)) + { + _isFileReadOnly = (bool)(!(buf.st_mode & _S_IWRITE)); + + _currentStatus = DOC_MODIFIED; + _timeStamp = buf.st_mtime; + doNotify(BufferChangeStatus | BufferChangeReadonly | BufferChangeTimestamp); + return true; + } + } + + if (!generic_stat(_fullPathName, &buf)) + { + int mask = 0; //status always 'changes', even if from modified to modified + bool isFileReadOnly = (bool)(!(buf.st_mode & _S_IWRITE)); + if (isFileReadOnly != _isFileReadOnly) { + _isFileReadOnly = isFileReadOnly; + mask |= BufferChangeReadonly; + } + + if (_timeStamp != buf.st_mtime) { + _timeStamp = buf.st_mtime; + mask |= BufferChangeTimestamp; + _currentStatus = DOC_MODIFIED; + mask |= BufferChangeStatus; //status always 'changes', even if from modified to modified + } + + if (mask != 0) { + doNotify(mask); + return true; + } + + return false; + } + + return false; +} + +void Buffer::setPosition(const Position & pos, ScintillaEditView * identifier) { + int index = indexOfReference(identifier); + if (index == -1) + return; + _positions[index] = pos; +} + +Position & Buffer::getPosition(ScintillaEditView * identifier) { + int index = indexOfReference(identifier); + return _positions.at(index); +} + +void Buffer::setHeaderLineState(const std::vector & folds, ScintillaEditView * identifier) { + int index = indexOfReference(identifier); + if (index == -1) + return; + //deep copy + std::vector & local = _foldStates[index]; + local.clear(); + size_t size = folds.size(); + for(size_t i = 0; i < size; i++) { + local.push_back(folds[i]); + } +} + +std::vector & Buffer::getHeaderLineState(ScintillaEditView * identifier) { + int index = indexOfReference(identifier); + return _foldStates.at(index); +} + +LangType Buffer::getLangFromExt(const TCHAR *ext) +{ + NppParameters *pNppParam = NppParameters::getInstance(); + int i = pNppParam->getNbLang(); + i--; + while (i >= 0) + { + Lang *l = pNppParam->getLangFromIndex(i--); + + const TCHAR *defList = l->getDefaultExtList(); + const TCHAR *userList = NULL; + + LexerStylerArray &lsa = pNppParam->getLStylerArray(); + const TCHAR *lName = l->getLangName(); + LexerStyler *pLS = lsa.getLexerStylerByName(lName); + + if (pLS) + userList = pLS->getLexerUserExt(); + + std::generic_string list(TEXT("")); + if (defList) + list += defList; + if (userList) + { + list += TEXT(" "); + list += userList; + } + if (isInList(ext, list.c_str())) + return l->getLangID(); + } + return L_TXT; +} + +Lang * Buffer::getCurrentLang() const { + NppParameters *pNppParam = NppParameters::getInstance(); + int i = 0; + Lang *l = pNppParam->getLangFromIndex(i++); + while (l) + { + if (l->_langID == _lang) + return l; + + l = pNppParam->getLangFromIndex(i++); + } + return NULL; +}; + +int Buffer::indexOfReference(ScintillaEditView * identifier) const { + int size = (int)_referees.size(); + for(int i = 0; i < size; i++) { + if (_referees[i] == identifier) + return i; + } + return -1; //not found +} + +int Buffer::addReference(ScintillaEditView * identifier) { + if (indexOfReference(identifier) != -1) + return _references; + _referees.push_back(identifier); + _positions.push_back(Position()); + _foldStates.push_back(std::vector()); + _references++; + return _references; +} + +int Buffer::removeReference(ScintillaEditView * identifier) { + int indexToPop = indexOfReference(identifier); + if (indexToPop == -1) + return _references; + _referees.erase(_referees.begin() + indexToPop); + _positions.erase(_positions.begin() + indexToPop); + _foldStates.erase(_foldStates.begin() + indexToPop); + _references--; + return _references; +} + +void Buffer::setHideLineChanged(bool isHide, int location) { + //First run through all docs without removing markers + for(int i = 0; i < _references; i++) { + _referees.at(i)->notifyMarkers(this, isHide, location, false);//(i == _references-1)); + } + + if (!isHide) { //no deleting if hiding lines + //Then all docs to remove markers. + for(int i = 0; i < _references; i++) { + _referees.at(i)->notifyMarkers(this, isHide, location, true); + } + } +} +void Buffer::setDeferredReload() { //triggers a reload on the next Document access + _isDirty = false; //when reloading, just set to false, since it sohuld be marked as clean + _needReloading = true; + doNotify(BufferChangeDirty); +} + +/* +pair Buffer::getLineUndoState(size_t currentLine) const +{ + for (size_t i = 0 ; i < _linesUndoState.size() ; i++) + { + if (_linesUndoState[i].first == currentLine) + return _linesUndoState[i].second; + } + return pair(0, false); +} + +void Buffer::setLineUndoState(size_t currentLine, size_t undoLevel, bool isSaved) +{ + bool found = false; + for (size_t i = 0 ; i < _linesUndoState.size() ; i++) + { + if (_linesUndoState[i].first == currentLine) + { + _linesUndoState[i].second.first = undoLevel; + _linesUndoState[i].second.second = isSaved; + } + } + if (!found) + { + _linesUndoState.push_back(pair >(currentLine, pair(undoLevel, false))); + } +} +*/ + +//filemanager + + +void FileManager::init(Notepad_plus * pNotepadPlus, ScintillaEditView * pscratchTilla) +{ + _pNotepadPlus = pNotepadPlus; + _pscratchTilla = pscratchTilla; + _pscratchTilla->execute(SCI_SETUNDOCOLLECTION, false); //dont store any undo information + _scratchDocDefault = (Document)_pscratchTilla->execute(SCI_GETDOCPOINTER); + _pscratchTilla->execute(SCI_ADDREFDOCUMENT, 0, _scratchDocDefault); +} + +void FileManager::checkFilesystemChanges() { + for(size_t i = 0; i < _nrBufs; i++) { + if (_buffers[i]->checkFileState()){} //something has changed. Triggers update automatically + } +} + +int FileManager::getBufferIndexByID(BufferID id) { + for(size_t i = 0; i < _nrBufs; i++) { + if (_buffers[i]->_id == id) + return (int)i; + } + return -1; +} + +Buffer * FileManager::getBufferByIndex(int index) { + return _buffers.at(index); +} + +void FileManager::beNotifiedOfBufferChange(Buffer * theBuf, int mask) { + _pNotepadPlus->notifyBufferChanged(theBuf, mask); +}; + +void FileManager::addBufferReference(BufferID buffer, ScintillaEditView * identifier) { + Buffer * buf = getBufferByID(buffer); + buf->addReference(identifier); +} + +void FileManager::closeBuffer(BufferID id, ScintillaEditView * identifier) { + int index = getBufferIndexByID(id); + Buffer * buf = getBufferByIndex(index); + + int oldRefs = buf->_references; + int refs = buf->removeReference(identifier); + + if (!refs) { //buffer can be deallocated + _pscratchTilla->execute(SCI_RELEASEDOCUMENT, 0, buf->_doc); //release for FileManager, Document is now gone + _buffers.erase(_buffers.begin() + index); + delete buf; + _nrBufs--; + } +} + +BufferID FileManager::loadFile(const TCHAR * filename, Document doc) { + bool ownDoc = false; + if (doc == NULL) + { + doc = (Document)_pscratchTilla->execute(SCI_CREATEDOCUMENT); + ownDoc = true; + } + + TCHAR fullpath[MAX_PATH]; + ::GetFullPathName(filename, MAX_PATH, fullpath, NULL); + ::GetLongPathName(fullpath, fullpath, MAX_PATH); + Utf8_16_Read UnicodeConvertor; //declare here so we can get information after loading is done + bool res = loadFileData(doc, fullpath, &UnicodeConvertor, L_TXT); + if (res) + { + Buffer * newBuf = new Buffer(this, _nextBufferID, doc, DOC_REGULAR, fullpath); + BufferID id = (BufferID) newBuf; + newBuf->_id = id; + _buffers.push_back(newBuf); + _nrBufs++; + Buffer * buf = _buffers.at(_nrBufs - 1); + + // 3 formats : WIN_FORMAT, UNIX_FORMAT and MAC_FORMAT + if (UnicodeConvertor.getNewBuf()) + { + buf->determinateFormat(UnicodeConvertor.getNewBuf()); + } + else + { + buf->determinateFormat(""); + } + + UniMode encoding = UnicodeConvertor.getEncoding(); + if (encoding == uni7Bit) + { + NppParameters *pNppParamInst = NppParameters::getInstance(); + const NewDocDefaultSettings & ndds = (pNppParamInst->getNppGUI()).getNewDocDefaultSettings(); + if (ndds._openAnsiAsUtf8) + { + encoding = uniCookie; + } + else + { + encoding = uni8Bit; + } + } + buf->setUnicodeMode(encoding); + + //determine buffer properties + BufferID retval = _nextBufferID++; + return id; + } else { //failed loading, release document + if (ownDoc) + _pscratchTilla->execute(SCI_RELEASEDOCUMENT, 0, doc); //Failure, so release document + return BUFFER_INVALID; + } +} + +bool FileManager::reloadBuffer(BufferID id) { + Buffer * buf = getBufferByID(id); + Document doc = buf->getDocument(); + Utf8_16_Read UnicodeConvertor; + buf->_canNotify = false; //disable notify during file load, we dont want dirty to be triggered + bool res = loadFileData(doc, buf->getFullPathName(), &UnicodeConvertor, buf->getLangType()); + buf->_canNotify = true; + if (res) { + if (UnicodeConvertor.getNewBuf()) { + buf->determinateFormat(UnicodeConvertor.getNewBuf()); + } else { + buf->determinateFormat(""); + } + buf->setUnicodeMode(UnicodeConvertor.getEncoding()); + // buf->setNeedsLexing(true); + } + return res; +} + +bool FileManager::reloadBufferDeferred(BufferID id) { + Buffer * buf = getBufferByID(id); + buf->setDeferredReload(); + return true; +} + +bool FileManager::deleteFile(BufferID id) +{ + Buffer * buf = getBufferByID(id); + const TCHAR *fileNamePath = buf->getFullPathName(); + if (!PathFileExists(fileNamePath)) + return false; + return ::DeleteFile(fileNamePath) != 0; +} + +bool FileManager::moveFile(BufferID id, const TCHAR * newFileName) +{ + Buffer * buf = getBufferByID(id); + const TCHAR *fileNamePath = buf->getFullPathName(); + if (!PathFileExists(fileNamePath)) + return false; + + if (::MoveFile(fileNamePath, newFileName) == 0) + return false; + + buf->setFileName(newFileName); + return true; +} + +bool FileManager::saveBuffer(BufferID id, const TCHAR * filename, bool isCopy) { + Buffer * buffer = getBufferByID(id); + bool isHidden = false; + bool isSys = false; + DWORD attrib; + + TCHAR fullpath[MAX_PATH]; + ::GetFullPathName(filename, MAX_PATH, fullpath, NULL); + ::GetLongPathName(fullpath, fullpath, MAX_PATH); + if (PathFileExists(fullpath)) + { + attrib = ::GetFileAttributes(fullpath); + + if (attrib != INVALID_FILE_ATTRIBUTES) + { + isHidden = (attrib & FILE_ATTRIBUTE_HIDDEN) != 0; + if (isHidden) + ::SetFileAttributes(filename, attrib & ~FILE_ATTRIBUTE_HIDDEN); + + isSys = (attrib & FILE_ATTRIBUTE_SYSTEM) != 0; + if (isSys) + ::SetFileAttributes(filename, attrib & ~FILE_ATTRIBUTE_SYSTEM); + } + } + + UniMode mode = buffer->getUnicodeMode(); + if (mode == uniCookie) + mode = uni8Bit; //set the mode to ANSI to prevent converter from adding BOM and performing conversions, Scintilla's data can be copied directly + + Utf8_16_Write UnicodeConvertor; + UnicodeConvertor.setEncoding(mode); + + FILE *fp = UnicodeConvertor.fopen(fullpath, TEXT("wb")); + if (fp) + { + _pscratchTilla->execute(SCI_SETDOCPOINTER, 0, buffer->_doc); //generate new document + + char data[blockSize + 1]; + int lengthDoc = _pscratchTilla->getCurrentDocLen(); + for (int i = 0; i < lengthDoc; i += blockSize) + { + int grabSize = lengthDoc - i; + if (grabSize > blockSize) + grabSize = blockSize; + + _pscratchTilla->getText(data, i, i + grabSize); + UnicodeConvertor.fwrite(data, grabSize); + } + UnicodeConvertor.fclose(); + + if (isHidden) + ::SetFileAttributes(fullpath, attrib | FILE_ATTRIBUTE_HIDDEN); + + if (isSys) + ::SetFileAttributes(fullpath, attrib | FILE_ATTRIBUTE_SYSTEM); + + if (isCopy) { + _pscratchTilla->execute(SCI_SETDOCPOINTER, 0, _scratchDocDefault); + return true; //all done + } + + buffer->setFileName(fullpath); + buffer->setDirty(false); + buffer->setStatus(DOC_REGULAR); + buffer->checkFileState(); + _pscratchTilla->execute(SCI_SETSAVEPOINT); + //_pscratchTilla->markSavedLines(); + _pscratchTilla->execute(SCI_SETDOCPOINTER, 0, _scratchDocDefault); + + return true; + } + return false; +} + +BufferID FileManager::newEmptyDocument() +{ + TCHAR newTitle[10]; + lstrcpy(newTitle, UNTITLED_STR); + wsprintf(newTitle+4, TEXT("%d"), _nextNewNumber); + _nextNewNumber++; + Document doc = (Document)_pscratchTilla->execute(SCI_CREATEDOCUMENT); //this already sets a reference for filemanager + Buffer * newBuf = new Buffer(this, _nextBufferID, doc, DOC_UNNAMED, newTitle); + BufferID id = (BufferID)newBuf; + newBuf->_id = id; + _buffers.push_back(newBuf); + _nrBufs++; + BufferID retval = _nextBufferID++; + return id; +} + +BufferID FileManager::bufferFromDocument(Document doc, bool dontIncrease, bool dontRef) +{ + TCHAR newTitle[10]; + lstrcpy(newTitle, UNTITLED_STR); + wsprintf(newTitle+4, TEXT("%d"), _nextNewNumber); + if (!dontRef) + _pscratchTilla->execute(SCI_ADDREFDOCUMENT, 0, doc); //set reference for FileManager + Buffer * newBuf = new Buffer(this, _nextBufferID, doc, DOC_UNNAMED, newTitle); + BufferID id = (BufferID)newBuf; + newBuf->_id = id; + _buffers.push_back(newBuf); + _nrBufs++; + BufferID retval = _nextBufferID; + if (!dontIncrease) + _nextBufferID++; + return id; +} + +bool FileManager::loadFileData(Document doc, const TCHAR * filename, Utf8_16_Read * UnicodeConvertor, LangType language) +{ + const int blockSize = 128 * 1024; //128 kB + char data[blockSize]; + FILE *fp = generic_fopen(filename, TEXT("rb")); + if (!fp) + return false; + + //Setup scratchtilla for new filedata + _pscratchTilla->execute(SCI_SETDOCPOINTER, 0, doc); + bool ro = _pscratchTilla->execute(SCI_GETREADONLY) != 0; + if (ro) { + _pscratchTilla->execute(SCI_SETREADONLY, false); + } + _pscratchTilla->execute(SCI_CLEARALL); + if (language < L_EXTERNAL) { + _pscratchTilla->execute(SCI_SETLEXER, ScintillaEditView::langNames[language].lexerID); + } else { + int id = language - L_EXTERNAL; + TCHAR * name = NppParameters::getInstance()->getELCFromIndex(id)._name; +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + const char *pName = wmc->wchar2char(name, CP_ACP); +#else + const char *pName = name; +#endif + _pscratchTilla->execute(SCI_SETLEXERLANGUAGE, 0, (LPARAM)pName); + } + + bool success = true; + __try { + size_t lenFile = 0; + size_t lenConvert = 0; //just in case conversion results in 0, but file not empty + do { + lenFile = fread(data, 1, blockSize, fp); + lenConvert = UnicodeConvertor->convert(data, lenFile); + _pscratchTilla->execute(SCI_APPENDTEXT, lenConvert, (LPARAM)(UnicodeConvertor->getNewBuf())); + } while (lenFile > 0); + } __except(filter(GetExceptionCode(), GetExceptionInformation())) { + printStr(TEXT("File is too big to be opened by Notepad++")); + success = false; + } + + fclose(fp); + + _pscratchTilla->execute(SCI_EMPTYUNDOBUFFER); + _pscratchTilla->execute(SCI_SETSAVEPOINT); + if (ro) { + _pscratchTilla->execute(SCI_SETREADONLY, true); + } + _pscratchTilla->execute(SCI_SETDOCPOINTER, 0, _scratchDocDefault); + return success; +} + +BufferID FileManager::getBufferFromName(const TCHAR * name) { + TCHAR fullpath[MAX_PATH]; + ::GetFullPathName(name, MAX_PATH, fullpath, NULL); + ::GetLongPathName(fullpath, fullpath, MAX_PATH); + for(size_t i = 0; i < _buffers.size(); i++) { + if (!lstrcmpi(name, _buffers.at(i)->getFullPathName())) + return _buffers.at(i)->getID(); + } + return BUFFER_INVALID; +} + +BufferID FileManager::getBufferFromDocument(Document doc) { + for(size_t i = 0; i < _nrBufs; i++) { + if (_buffers[i]->_doc == doc) + return _buffers[i]->_id; + } + return BUFFER_INVALID; +} + +bool FileManager::createEmptyFile(const TCHAR * path) { + FILE * file = generic_fopen(path, TEXT("wb")); + if (!file) + return false; + fclose(file); + return true; +} + +int FileManager::getFileNameFromBuffer(BufferID id, TCHAR * fn2copy) { + if (getBufferIndexByID(id) == -1) + return -1; + Buffer * buf = getBufferByID(id); + if (fn2copy) + lstrcpy(fn2copy, buf->getFullPathName()); + return lstrlen(buf->getFullPathName()); +} + +int FileManager::docLength(Buffer * buffer) const +{ + _pscratchTilla->execute(SCI_SETDOCPOINTER, 0, buffer->_doc); + int docLen = _pscratchTilla->getCurrentDocLen(); + _pscratchTilla->execute(SCI_SETDOCPOINTER, 0, _scratchDocDefault); + return docLen; +} diff --git a/PowerEditor/src/ScitillaComponent/Buffer.h b/PowerEditor/src/ScitillaComponent/Buffer.h new file mode 100644 index 00000000..8a19a355 --- /dev/null +++ b/PowerEditor/src/ScitillaComponent/Buffer.h @@ -0,0 +1,386 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO < donho@altern.org > +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef BUFFER_H +#define BUFFER_H + +#include "Utf8_16.h" + +class Buffer; +typedef Buffer * BufferID; //each buffer has unique ID by which it can be retrieved +#define BUFFER_INVALID (BufferID)0 + +typedef sptr_t Document; + +enum DocFileStatus{ + DOC_REGULAR = 0x01, //should not be combined with anything + DOC_UNNAMED = 0x02, //not saved (new ##) + DOC_DELETED = 0x04, //doesnt exist in environment anymore, but not DOC_UNNAMED + DOC_MODIFIED = 0x08 //File in environment has changed +}; + +enum BufferStatusInfo { + BufferChangeLanguage = 0x001, //Language was altered + BufferChangeDirty = 0x002, //Buffer has changed dirty state + BufferChangeFormat = 0x004, //EOL type was changed + BufferChangeUnicode = 0x008, //Unicode type was changed + BufferChangeReadonly = 0x010, //Readonly state was changed, can be both file and user + BufferChangeStatus = 0x020, //Filesystem Status has changed + BufferChangeTimestamp = 0x040, //Timestamp was changed + BufferChangeFilename = 0x080, //Filename was changed + BufferChangeRecentTag = 0x100, //Recent tag has changed + BufferChangeLexing = 0x200, //Document needs lexing + BufferChangeMask = 0x3FF //Mask: covers all changes +}; + +struct HeaderLineState { + HeaderLineState() : _headerLineNumber(0), _isExpanded(true){}; + HeaderLineState(int lineNumber, bool isExpanded) : _headerLineNumber(lineNumber), _isExpanded(isExpanded){}; + int _headerLineNumber; + bool _isExpanded; +}; + +const int userLangNameMax = 16; +const TCHAR UNTITLED_STR[] = TEXT("new "); + +//File manager class maintains all buffers +class Buffer; +class FileManager { +public: + void init(Notepad_plus * pNotepadPlus, ScintillaEditView * pscratchTilla); + + //void activateBuffer(int index); + void checkFilesystemChanges(); + + int getNrBuffers() { return _nrBufs; }; + int getBufferIndexByID(BufferID id); + Buffer * getBufferByIndex(int index); //generates exception if index is invalid + Buffer * getBufferByID(BufferID id) {return (Buffer*)id;} + + void beNotifiedOfBufferChange(Buffer * theBuf, int mask); + + void closeBuffer(BufferID, ScintillaEditView * identifer); //called by Notepad++ + + void addBufferReference(BufferID id, ScintillaEditView * identifer); //called by Scintilla etc indirectly + + BufferID loadFile(const TCHAR * filename, Document doc = NULL); //ID == BUFFER_INVALID on failure. If Doc == NULL, a new file is created, otherwise data is loaded in given document + BufferID newEmptyDocument(); + //create Buffer from existing Scintilla, used from new Scintillas. If dontIncrease = true, then the new document number isnt increased afterwards. + //usefull for temporary but neccesary docs + //If dontRef = false, then no extra reference is added for the doc. Its the responsibility of the caller to do so + BufferID bufferFromDocument(Document doc, bool dontIncrease = false, bool dontRef = false); + + BufferID getBufferFromName(const TCHAR * name); + BufferID getBufferFromDocument(Document doc); + + bool reloadBuffer(BufferID id); + bool reloadBufferDeferred(BufferID id); + bool saveBuffer(BufferID id, const TCHAR * filename, bool isCopy = false); + bool deleteFile(BufferID id); + bool moveFile(BufferID id, const TCHAR * newFilename); + + bool createEmptyFile(const TCHAR * path); + + static FileManager * getInstance() {return _pSelf;}; + void destroyInstance() { delete _pSelf; }; + + void increaseDocNr() {_nextNewNumber++;}; + + int getFileNameFromBuffer(BufferID id, TCHAR * fn2copy); + + int docLength(Buffer * buffer) const; + +private: + FileManager() : _nextNewNumber(1), _nextBufferID(0), _pNotepadPlus(NULL), _nrBufs(0), _pscratchTilla(NULL){}; + ~FileManager(){}; + static FileManager *_pSelf; + + Notepad_plus * _pNotepadPlus; + ScintillaEditView * _pscratchTilla; + Document _scratchDocDefault; + + int _nextNewNumber; + + std::vector _buffers; + BufferID _nextBufferID; + size_t _nrBufs; + + bool loadFileData(Document doc, const TCHAR * filename, Utf8_16_Read * UnicodeConvertor, LangType language); +}; + +#define MainFileManager FileManager::getInstance() + +class Buffer +{ +friend class FileManager; +public : + //Loading a document: + //constructor with ID. + //Set a reference (pointer to a container mostly, like DocTabView or ScintillaEditView) + //Set the position manually if needed + //Load the document into Scintilla/add to TabBar + //The entire lifetime if the buffer, the Document has reference count of _atleast_ one + //Destructor makes sure its purged + Buffer(FileManager * pManager, BufferID id, Document doc, DocFileStatus type, const TCHAR *fileName) //type must be either DOC_REGULAR or DOC_UNNAMED + : _pManager(pManager), _id(id), _isDirty(false), _doc(doc), _isFileReadOnly(false), _isUserReadOnly(false), _recentTag(-1), _references(0), + _canNotify(false), _timeStamp(0), _needReloading(false) + { + NppParameters *pNppParamInst = NppParameters::getInstance(); + const NewDocDefaultSettings & ndds = (pNppParamInst->getNppGUI()).getNewDocDefaultSettings(); + _format = ndds._format; + _unicodeMode = ndds._encoding; + + _userLangExt[0] = 0; + _fullPathName[0] = 0; + _fileName = NULL; + setFileName(fileName, ndds._lang); + updateTimeStamp(); + checkFileState(); + _currentStatus = type; + _isDirty = false; + + _needLexer = false; //new buffers do not need lexing, Scintilla takes care of that + _canNotify = true; + }; + + LangType getLangFromExt(const TCHAR *ext); + + // this method 1. copies the file name + // 2. determinates the language from the ext of file name + // 3. gets the last modified time + void setFileName(const TCHAR *fn, LangType defaultLang = L_TXT); + + const TCHAR * getFullPathName() const { + return _fullPathName; + }; + + const TCHAR * getFileName() const { return _fileName; }; + + BufferID getID() const { + return _id; + }; + + void increaseRecentTag() { + _recentTag = ++_recentTagCtr; + doNotify(BufferChangeRecentTag); + }; + + long getRecentTag() const { + return _recentTag; + }; + + bool checkFileState(); + + bool isDirty() const { + return _isDirty; + }; + + bool isReadOnly() const { + return (_isUserReadOnly || _isFileReadOnly); + }; + + bool isUntitled() const { + return (_currentStatus == DOC_UNNAMED); + }; + + bool getFileReadOnly() const { + return _isFileReadOnly; + }; + + void setFileReadOnly(bool ro) { + _isFileReadOnly = ro; + doNotify(BufferChangeReadonly); + }; + + bool getUserReadOnly() const { + return _isUserReadOnly; + }; + + void setUserReadOnly(bool ro) { + _isUserReadOnly = ro; + doNotify(BufferChangeReadonly); + }; + + formatType getFormat() const { + return _format; + }; + + void setFormat(formatType format) { + _format = format; + doNotify(BufferChangeFormat); + }; + + LangType getLangType() const { + return _lang; + }; + + void setLangType(LangType lang, const TCHAR * userLangName = TEXT("")) { + if (lang == _lang && lang != L_USER) + return; + _lang = lang; + if (_lang == L_USER) { + lstrcpy(_userLangExt, userLangName); + } + _needLexer = true; //change of lang means lexern eeds updating + doNotify(BufferChangeLanguage|BufferChangeLexing); + }; + + UniMode getUnicodeMode() const { + return _unicodeMode; + }; + + void setUnicodeMode(UniMode mode) { + _unicodeMode = mode; + //_isDirty = true; //set to dirty if change unicode mode + doNotify(BufferChangeUnicode | BufferChangeDirty); + }; + DocFileStatus getStatus() const { + return _currentStatus; + }; + + Document getDocument() { + return _doc; + }; + + void setDirty(bool dirty) { + _isDirty = dirty; + doNotify(BufferChangeDirty); + }; + + void setPosition(const Position & pos, ScintillaEditView * identifier); + Position & getPosition(ScintillaEditView * identifier); + + void setHeaderLineState(const std::vector & folds, ScintillaEditView * identifier); + std::vector & getHeaderLineState(ScintillaEditView * identifier); + + void determinateFormat(const char *data); + + bool isUserDefineLangExt() const { + return (_userLangExt[0] != '\0'); + }; + + const TCHAR * getUserDefineLangName() const { + return _userLangExt; + }; + + const TCHAR * getCommentLineSymbol() const { + Lang *l = getCurrentLang(); + if (!l) + return NULL; + return l->_pCommentLineSymbol; + + }; + + const TCHAR * getCommentStart() const { + Lang *l = getCurrentLang(); + if (!l) + return NULL; + return l->_pCommentStart; + }; + + const TCHAR * getCommentEnd() const { + Lang *l = getCurrentLang(); + if (!l) + return NULL; + return l->_pCommentEnd; + }; + + bool getNeedsLexing() const { + return _needLexer; + }; + + void setNeedsLexing(bool lex) { + _needLexer = lex; + doNotify(BufferChangeLexing); + }; + + //these two return reference count after operation + int addReference(ScintillaEditView * identifier); //if ID not registered, creates a new Position for that ID and new foldstate + int removeReference(ScintillaEditView * identifier); //reduces reference. If zero, Document is purged + + void setHideLineChanged(bool isHide, int location); + + void setDeferredReload(); + + bool getNeedReload() { + return _needReloading; + } + + void setNeedReload(bool reload) { + _needReloading = reload; + } + + /* + pair getLineUndoState(size_t currentLine) const; + void setLineUndoState(size_t currentLine, size_t undoLevel, bool isSaved = false); + */ + + int docLength() const { + return _pManager->docLength(_id); + }; + +private : + FileManager * _pManager; + bool _canNotify; + int _references; //if no references file inaccessible, can be closed + BufferID _id; + + //document properties + Document _doc; //invariable + LangType _lang; + TCHAR _userLangExt[userLangNameMax]; // it's useful if only (_lang == L_USER) + bool _isDirty; + formatType _format; + UniMode _unicodeMode; + bool _isUserReadOnly; + bool _needLexer; //initially true + //these properties have to be duplicated because of multiple references + //All the vectors must have the same size at all times + vector< ScintillaEditView * > _referees; + vector< Position > _positions; + vector< vector > _foldStates; + + //vector< pair > > _linesUndoState; + + //Environment properties + DocFileStatus _currentStatus; + time_t _timeStamp; // 0 if it's a new doc + bool _isFileReadOnly; + TCHAR _fullPathName[MAX_PATH]; + TCHAR * _fileName; //points to filename part in _fullPathName + bool _needReloading; //True if Buffer needs to be reloaded on activation + + long _recentTag; + static long _recentTagCtr; + + void updateTimeStamp(); + Lang * getCurrentLang() const; + + int indexOfReference(ScintillaEditView * identifier) const; + + void setStatus(DocFileStatus status) { + _currentStatus = status; + doNotify(BufferChangeStatus); + } + + void doNotify(int mask) { + if (_canNotify) + _pManager->beNotifiedOfBufferChange(this, mask); + }; +}; + +#endif //BUFFER_H diff --git a/PowerEditor/src/ScitillaComponent/DocTabView.cpp b/PowerEditor/src/ScitillaComponent/DocTabView.cpp new file mode 100644 index 00000000..c97cca42 --- /dev/null +++ b/PowerEditor/src/ScitillaComponent/DocTabView.cpp @@ -0,0 +1,146 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#include "DocTabView.h" + +#ifndef _WIN32_IE +#define _WIN32_IE 0x0600 +#endif //_WIN32_IE + +#include +#include + +bool DocTabView::_hideTabBarStatus = false; + +void DocTabView::addBuffer(BufferID buffer) { + if (buffer == BUFFER_INVALID) //valid only + return; + if (this->getIndexByBuffer(buffer) != -1) //no duplicates + return; + Buffer * buf = MainFileManager->getBufferByID(buffer); + TCITEM tie; + tie.mask = TCIF_TEXT | TCIF_IMAGE | TCIF_PARAM; + + int index = -1; + if (_hasImgLst) + index = 0; + tie.iImage = index; + tie.pszText = (TCHAR *)buf->getFileName(); + tie.lParam = (LPARAM)buffer; + ::SendMessage(_hSelf, TCM_INSERTITEM, _nbItem++, reinterpret_cast(&tie)); + bufferUpdated(buf, BufferChangeMask); + + ::SendMessage(_hParent, WM_SIZE, 0, 0); +} + +void DocTabView::closeBuffer(BufferID buffer) { + int indexToClose = getIndexByBuffer(buffer); + deletItemAt(indexToClose); + + ::SendMessage(_hParent, WM_SIZE, 0, 0); +} + +bool DocTabView::activateBuffer(BufferID buffer) { + int indexToActivate = getIndexByBuffer(buffer); + if (indexToActivate == -1) + return false; //cannot activate + activateAt(indexToActivate); + return true; +} + +BufferID DocTabView::activeBuffer() { + int index = getCurrentTabIndex(); + return (BufferID)getBufferByIndex(index); +} + +BufferID DocTabView::findBufferByName(const TCHAR * fullfilename) { //-1 if not found, something else otherwise + TCITEM tie; + tie.lParam = -1; + tie.mask = TCIF_PARAM; + for(size_t i = 0; i < _nbItem; i++) { + ::SendMessage(_hSelf, TCM_GETITEM, i, reinterpret_cast(&tie)); + BufferID id = (BufferID)tie.lParam; + Buffer * buf = MainFileManager->getBufferByID(id); + if (!lstrcmp(fullfilename, buf->getFullPathName())) { + return id; + } + } + return BUFFER_INVALID; +} + +int DocTabView::getIndexByBuffer(BufferID id) { + TCITEM tie; + tie.lParam = -1; + tie.mask = TCIF_PARAM; + for(int i = 0; i < (int)_nbItem; i++) { + ::SendMessage(_hSelf, TCM_GETITEM, i, reinterpret_cast(&tie)); + if ((BufferID)tie.lParam == id) + return i; + } + return -1; +} + +BufferID DocTabView::getBufferByIndex(int index) { + TCITEM tie; + tie.lParam = -1; + tie.mask = TCIF_PARAM; + ::SendMessage(_hSelf, TCM_GETITEM, index, reinterpret_cast(&tie)); + + return (BufferID)tie.lParam; +} + +void DocTabView::bufferUpdated(Buffer * buffer, int mask) { + int index = getIndexByBuffer(buffer->getID()); + if (index == -1) + return; + + TCITEM tie; + tie.lParam = -1; + tie.mask = 0; + + + if (mask & BufferChangeReadonly || mask & BufferChangeDirty) { + tie.mask |= TCIF_IMAGE; + tie.iImage = buffer->isDirty()?UNSAVED_IMG_INDEX:SAVED_IMG_INDEX; + if (buffer->isReadOnly()) { + tie.iImage = REDONLY_IMG_INDEX; + } + } + + if (mask & BufferChangeFilename) { + tie.mask |= TCIF_TEXT; + tie.pszText = (TCHAR *)buffer->getFileName(); + } + + ::SendMessage(_hSelf, TCM_SETITEM, index, reinterpret_cast(&tie)); + + ::SendMessage(_hParent, WM_SIZE, 0, 0); +} + +void DocTabView::setBuffer(int index, BufferID id) { + if (index < 0 || index >= (int)_nbItem) + return; + + TCITEM tie; + tie.lParam = (LPARAM)id; + tie.mask = TCIF_PARAM; + ::SendMessage(_hSelf, TCM_SETITEM, index, reinterpret_cast(&tie)); + + bufferUpdated(MainFileManager->getBufferByID(id), BufferChangeMask); //update tab, everything has changed + + ::SendMessage(_hParent, WM_SIZE, 0, 0); +} diff --git a/PowerEditor/src/ScitillaComponent/DocTabView.h b/PowerEditor/src/ScitillaComponent/DocTabView.h new file mode 100644 index 00000000..3f04836c --- /dev/null +++ b/PowerEditor/src/ScitillaComponent/DocTabView.h @@ -0,0 +1,92 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef DOCTABVIEW_H +#define DOCTABVIEW_H + +#include "TabBar.h" +#include "ScintillaEditView.h" +#include "ImageListSet.h" + +const int SAVED_IMG_INDEX = 0; +const int UNSAVED_IMG_INDEX = 1; +const int REDONLY_IMG_INDEX = 2; + +class DocTabView : public TabBarPlus +{ +public : + DocTabView():TabBarPlus(), _pView(NULL) {}; + virtual ~DocTabView(){}; + + virtual void destroy() { + TabBarPlus::destroy(); + }; + + void init(HINSTANCE hInst, HWND parent, ScintillaEditView * pView, IconList *pIconList = NULL) + { + TabBarPlus::init(hInst, parent); + _pView = pView; + if (pIconList) + TabBar::setImageList(pIconList->getHandle()); + return; + }; + + void addBuffer(BufferID buffer); + void closeBuffer(BufferID buffer); + void bufferUpdated(Buffer * buffer, int mask); + + bool activateBuffer(BufferID buffer); + + BufferID activeBuffer(); + BufferID findBufferByName(const TCHAR * fullfilename); //-1 if not found, something else otherwise + + int getIndexByBuffer(BufferID id); + BufferID getBufferByIndex(int index); + + void setBuffer(int index, BufferID id); + + static bool setHideTabBarStatus(bool hideOrNot) { + bool temp = _hideTabBarStatus; + _hideTabBarStatus = hideOrNot; + return temp; + }; + + static bool getHideTabBarStatus() { + return _hideTabBarStatus; + }; + + virtual void reSizeTo(RECT & rc) { + if (_hideTabBarStatus) + { + RECT rcTmp = rc; + + TabBar::reSizeTo(rcTmp); + _pView->reSizeTo(rc); + } + else + { + TabBar::reSizeTo(rc); + _pView->reSizeTo(rc); + } + }; + +private : + ScintillaEditView *_pView; + static bool _hideTabBarStatus; +}; + +#endif //DOCTABVIEW_H diff --git a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp new file mode 100644 index 00000000..e6a710d1 --- /dev/null +++ b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp @@ -0,0 +1,1975 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#include "FindReplaceDlg.h" +#include "ScintillaEditView.h" +#include "Notepad_plus_msgs.h" +//#include "constant.h" +#include "UniConversion.h" + +int Searching::convertExtendedToString(const TCHAR * query, TCHAR * result, int length) { //query may equal to result, since it always gets smaller + int i = 0, j = 0; + int charLeft = length; + bool isGood = true; + TCHAR current; + while(i < length) { //because the backslash escape quences always reduce the size of the generic_string, no overflow checks have to be made for target, assuming parameters are correct + current = query[i]; + charLeft--; + if (current == '\\' && charLeft) { //possible escape sequence + i++; + charLeft--; + current = query[i]; + switch(current) { + case 'r': + result[j] = '\r'; + break; + case 'n': + result[j] = '\n'; + break; + case '0': + result[j] = '\0'; + break; + case 't': + result[j] = '\t'; + break; + case '\\': + result[j] = '\\'; + break; + case 'b': + case 'd': + case 'o': + case 'x': { + int size = 0, base = 0; + if (current == 'b') { //11111111 + size = 8, base = 2; + } else if (current == 'o') { //377 + size = 3, base = 8; + } else if (current == 'd') { //255 + size = 3, base = 10; + } else if (current == 'x') { //0xFF + size = 2, base = 16; + } + if (charLeft >= size) { + int res = 0; + if (Searching::readBase(query+(i+1), &res, base, size)) { + result[j] = (TCHAR)res; + i+=size; + break; + } + } + //not enough chars to make parameter, use default method as fallback + } + default: { //unknown sequence, treat as regular text + result[j] = '\\'; + j++; + result[j] = current; + isGood = false; + break; + } + } + } else { + result[j] = query[i]; + } + i++; + j++; + } + result[j] = 0; + return j; +} + +bool Searching::readBase(const TCHAR * str, int * value, int base, int size) { + int i = 0, temp = 0; + *value = 0; + TCHAR max = '0' + base - 1; + TCHAR current; + while(i < size) { + current = str[i]; + if (current >= '0' && current <= max) { + temp *= base; + temp += (current - '0'); + } else { + return false; + } + i++; + } + *value = temp; + return true; +} + +void Searching::displaySectionCentered(int posStart, int posEnd, ScintillaEditView * pEditView, bool isDownwards) +{ + // to make sure the found result is visible + //When searching up, the beginning of the (possible multiline) result is important, when scrolling down the end + int testPos = (isDownwards)?posEnd:posStart; + pEditView->execute(SCI_SETCURRENTPOS, testPos); + int currentlineNumberDoc = (int)pEditView->execute(SCI_LINEFROMPOSITION, testPos); + int currentlineNumberVis = (int)pEditView->execute(SCI_VISIBLEFROMDOCLINE, currentlineNumberDoc); + pEditView->execute(SCI_ENSUREVISIBLE, currentlineNumberDoc); // make sure target line is unfolded + + int firstVisibleLineVis = (int)pEditView->execute(SCI_GETFIRSTVISIBLELINE); + int linesVisible = (int)pEditView->execute(SCI_LINESONSCREEN) - 1; //-1 for the scrollbar + int lastVisibleLineVis = (int)linesVisible + firstVisibleLineVis; + + //if out of view vertically, scroll line into (center of) view + int linesToScroll = 0; + if (currentlineNumberVis < firstVisibleLineVis) + { + linesToScroll = currentlineNumberVis - firstVisibleLineVis; + //use center + linesToScroll -= linesVisible/2; + } + else if (currentlineNumberVis > lastVisibleLineVis) + { + linesToScroll = currentlineNumberVis - lastVisibleLineVis; + //use center + linesToScroll += linesVisible/2; + } + pEditView->scroll(0, linesToScroll); + + //Make sure the caret is visible, scroll horizontally (this will also fix wrapping problems) + pEditView->execute(SCI_GOTOPOS, posStart); + pEditView->execute(SCI_GOTOPOS, posEnd); + + pEditView->execute(SCI_SETANCHOR, posStart); +} + +LONG FindReplaceDlg::originalFinderProc = NULL; + +void FindReplaceDlg::addText2Combo(const TCHAR * txt2add, HWND hCombo, bool isUTF8) +{ + if (!hCombo) return; + if (!lstrcmp(txt2add, TEXT(""))) return; + + int i = 0; + +#ifdef UNICODE + i = ::SendMessage(hCombo, CB_FINDSTRINGEXACT, -1, (LPARAM)txt2add); + if (i != CB_ERR) // found + { + ::SendMessage(hCombo, CB_DELETESTRING, i, 0); + } + + i = ::SendMessage(hCombo, CB_INSERTSTRING, 0, (LPARAM)txt2add); + +#else + TCHAR text[FINDREPLACE_MAXLENGTH]; + bool isWin9x = _winVer <= WV_ME; + wchar_t wchars2Add[FINDREPLACE_MAXLENGTH]; + wchar_t textW[FINDREPLACE_MAXLENGTH]; + int count = ::SendMessage(hCombo, CB_GETCOUNT, 0, 0); + + if (isUTF8) + ::MultiByteToWideChar(CP_UTF8, 0, txt2add, -1, wchars2Add, FINDREPLACE_MAXLENGTH - 1); + + for ( ; i < count ; i++) + { + if (isUTF8) + { + if (!isWin9x) + ::SendMessageW(hCombo, CB_GETLBTEXT, i, (LPARAM)textW); + + else + { + ::SendMessageA(hCombo, CB_GETLBTEXT, i, (LPARAM)text); + ::MultiByteToWideChar(CP_ACP, 0, text, -1, textW, FINDREPLACE_MAXLENGTH - 1); + } + + if (!wcscmp(wchars2Add, textW)) + { + ::SendMessage(hCombo, CB_DELETESTRING, i, 0); + break; + } + } + else + { + ::SendMessage(hCombo, CB_GETLBTEXT, i, (LPARAM)text); + if (!strcmp(txt2add, text)) + { + ::SendMessage(hCombo, CB_DELETESTRING, i, 0); + break; + } + } + } + + if (!isUTF8) + i = ::SendMessage(hCombo, CB_INSERTSTRING, 0, (LPARAM)txt2add); + + else + { + if (!isWin9x) + i = ::SendMessageW(hCombo, CB_INSERTSTRING, 0, (LPARAM)wchars2Add); + else + { + ::WideCharToMultiByte(CP_ACP, 0, wchars2Add, -1, text, FINDREPLACE_MAXLENGTH - 1, NULL, NULL); + i = ::SendMessageA(hCombo, CB_INSERTSTRING, 0, (LPARAM)text); + } + } +#endif + ::SendMessage(hCombo, CB_SETCURSEL, i, 0); +} + +generic_string FindReplaceDlg::getTextFromCombo(HWND hCombo, bool isUnicode) const +{ + TCHAR str[FINDREPLACE_MAXLENGTH]; +#ifdef UNICODE + ::SendMessage(hCombo, WM_GETTEXT, FINDREPLACE_MAXLENGTH - 1, (LPARAM)str); +#else + bool isWin9x = _winVer <= WV_ME; + if (isUnicode) + { + wchar_t wchars[FINDREPLACE_MAXLENGTH]; + if ( !isWin9x ) + { + ::SendMessageW(hCombo, WM_GETTEXT, FINDREPLACE_MAXLENGTH - 1, (LPARAM)wchars); + } + else + { + char achars[FINDREPLACE_MAXLENGTH]; + ::SendMessageA(hCombo, WM_GETTEXT, FINDREPLACE_MAXLENGTH - 1, (LPARAM)achars); + ::MultiByteToWideChar(CP_ACP, 0, achars, -1, wchars, FINDREPLACE_MAXLENGTH - 1); + } + ::WideCharToMultiByte(CP_UTF8, 0, wchars, -1, str, FINDREPLACE_MAXLENGTH - 1, NULL, NULL); + } + else + { + ::SendMessage(hCombo, WM_GETTEXT, FINDREPLACE_MAXLENGTH - 1, (LPARAM)str); + } + +#endif + return generic_string(str); +} + + +// important : to activate all styles +const int STYLING_MASK = 255; + +void FindReplaceDlg::create(int dialogID, bool isRTL) +{ + StaticDialog::create(dialogID, isRTL); + fillFindHistory(); + _currentStatus = REPLACE_DLG; + initOptionsFromDlg(); + + RECT rect; + //::GetWindowRect(_hSelf, &rect); + getClientRect(rect); + _tab.init(_hInst, _hSelf, false, false, true); + _tab.setFont(TEXT("Tahoma"), 13); + + const TCHAR *find = TEXT("Find"); + const TCHAR *replace = TEXT("Replace"); + const TCHAR *findInFiles = TEXT("Find in files"); + + NppParameters::FindDlgTabTitiles & fdTitles = NppParameters::getInstance()->getFindDlgTabTitiles(); + + if (fdTitles.isWellFilled()) + { + find = fdTitles._find.c_str(); + replace = fdTitles._replace.c_str(); + findInFiles = fdTitles._findInFiles.c_str(); + } + _tab.insertAtEnd(find); + _tab.insertAtEnd(replace); + _tab.insertAtEnd(findInFiles); + + _tab.reSizeTo(rect); + _tab.display(); + + ETDTProc enableDlgTheme = (ETDTProc)::SendMessage(_hParent, NPPM_GETENABLETHEMETEXTUREFUNC, 0, 0); + if (enableDlgTheme) + enableDlgTheme(_hSelf, ETDT_ENABLETAB); + + goToCenter(); +} + +void FindReplaceDlg::fillFindHistory() +{ + NppParameters *nppParams = NppParameters::getInstance(); + + FindHistory& findHistory = nppParams->getFindHistory(); + + fillComboHistory(IDD_FINDINFILES_DIR_COMBO, findHistory._nbFindHistoryPath, findHistory._pFindHistoryPath); + fillComboHistory(IDD_FINDINFILES_FILTERS_COMBO, findHistory._nbFindHistoryFilter, findHistory._pFindHistoryFilter); + fillComboHistory(IDFINDWHAT, findHistory._nbFindHistoryFind, findHistory._pFindHistoryFind); + fillComboHistory(IDREPLACEWITH, findHistory._nbFindHistoryReplace, findHistory._pFindHistoryReplace); + + ::SendDlgItemMessage(_hSelf, IDWRAP, BM_SETCHECK, findHistory._isWrap, 0); + ::SendDlgItemMessage(_hSelf, IDWHOLEWORD, BM_SETCHECK, findHistory._isMatchWord, 0); + ::SendDlgItemMessage(_hSelf, IDMATCHCASE, BM_SETCHECK, findHistory._isMatchCase, 0); + + ::SendDlgItemMessage(_hSelf, IDDIRECTIONUP, BM_SETCHECK, !findHistory._isDirectionDown, 0); + ::SendDlgItemMessage(_hSelf, IDDIRECTIONDOWN, BM_SETCHECK, findHistory._isDirectionDown, 0); + + ::SendDlgItemMessage(_hSelf, IDD_FINDINFILES_INHIDDENDIR_CHECK, BM_SETCHECK, findHistory._isFifInHiddenFolder, 0); + ::SendDlgItemMessage(_hSelf, IDD_FINDINFILES_RECURSIVE_CHECK, BM_SETCHECK, findHistory._isFifRecuisive, 0); + + ::SendDlgItemMessage(_hSelf, IDNORMAL, BM_SETCHECK, findHistory._searchMode == FindHistory::normal, 0); + ::SendDlgItemMessage(_hSelf, IDEXTENDED, BM_SETCHECK, findHistory._searchMode == FindHistory::extended, 0); + ::SendDlgItemMessage(_hSelf, IDREGEXP, BM_SETCHECK, findHistory._searchMode == FindHistory::regExpr, 0); + if (findHistory._searchMode == FindHistory::regExpr) + { + //regex doesnt allow wholeword + ::SendDlgItemMessage(_hSelf, IDWHOLEWORD, BM_SETCHECK, BST_UNCHECKED, 0); + ::EnableWindow(::GetDlgItem(_hSelf, IDWHOLEWORD), (BOOL)false); + + //regex doesnt allow upward search + ::SendDlgItemMessage(_hSelf, IDDIRECTIONDOWN, BM_SETCHECK, BST_CHECKED, 0); + ::SendDlgItemMessage(_hSelf, IDDIRECTIONUP, BM_SETCHECK, BST_UNCHECKED, 0); + ::EnableWindow(::GetDlgItem(_hSelf, IDDIRECTIONUP), (BOOL)false); + } + + if (nppParams->isTransparentAvailable()) + { + ::ShowWindow(::GetDlgItem(_hSelf, IDC_TRANSPARENT_CHECK), SW_SHOW); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_TRANSPARENT_GRPBOX), SW_SHOW); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_TRANSPARENT_LOSSFOCUS_RADIO), SW_SHOW); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_TRANSPARENT_ALWAYS_RADIO), SW_SHOW); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_PERCENTAGE_SLIDER), SW_SHOW); + + ::SendDlgItemMessage(_hSelf, IDC_PERCENTAGE_SLIDER, TBM_SETRANGE, FALSE, MAKELONG(20, 200)); + ::SendDlgItemMessage(_hSelf, IDC_PERCENTAGE_SLIDER, TBM_SETPOS, TRUE, findHistory._transparency); + + if (findHistory._transparencyMode == FindHistory::none) + { + ::EnableWindow(::GetDlgItem(_hSelf, IDC_TRANSPARENT_GRPBOX), FALSE); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_TRANSPARENT_LOSSFOCUS_RADIO), FALSE); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_TRANSPARENT_ALWAYS_RADIO), FALSE); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_PERCENTAGE_SLIDER), FALSE); + } + else + { + ::SendDlgItemMessage(_hSelf, IDC_TRANSPARENT_CHECK, BM_SETCHECK, TRUE, 0); + + int id; + if (findHistory._transparencyMode == FindHistory::onLossingFocus) + { + id = IDC_TRANSPARENT_LOSSFOCUS_RADIO; + } + else + { + id = IDC_TRANSPARENT_ALWAYS_RADIO; + (NppParameters::getInstance())->SetTransparent(_hSelf, findHistory._transparency); + + } + ::SendDlgItemMessage(_hSelf, id, BM_SETCHECK, TRUE, 0); + } + } +} + +void FindReplaceDlg::fillComboHistory(int id, int count, generic_string **pStrings) +{ + int i; + bool isUnicode = false; + HWND hCombo; + + hCombo = ::GetDlgItem(_hSelf, id); + for (i = count -1 ; i >= 0 ; i--) + { + addText2Combo(pStrings[i]->c_str(), hCombo, isUnicode); + } + ::SendMessage(hCombo, CB_SETCURSEL, 0, 0); // select first item +} + + +void FindReplaceDlg::saveFindHistory() +{ + if (! isCreated()) return; + FindHistory& findHistory = (NppParameters::getInstance())->getFindHistory(); + + saveComboHistory(IDD_FINDINFILES_DIR_COMBO, findHistory._nbMaxFindHistoryPath, findHistory._nbFindHistoryPath, findHistory._pFindHistoryPath); + saveComboHistory(IDD_FINDINFILES_FILTERS_COMBO, findHistory._nbMaxFindHistoryFilter, findHistory._nbFindHistoryFilter, findHistory._pFindHistoryFilter); + saveComboHistory(IDFINDWHAT, findHistory._nbMaxFindHistoryFind, findHistory._nbFindHistoryFind, findHistory._pFindHistoryFind); + saveComboHistory(IDREPLACEWITH, findHistory._nbMaxFindHistoryReplace, findHistory._nbFindHistoryReplace, findHistory._pFindHistoryReplace); +} + +void FindReplaceDlg::saveComboHistory(int id, int maxcount, int & oldcount, generic_string **pStrings) +{ + int i, count; + bool isUnicode = false; + HWND hCombo; + TCHAR text[FINDREPLACE_MAXLENGTH]; + + hCombo = ::GetDlgItem(_hSelf, id); + count = ::SendMessage(hCombo, CB_GETCOUNT, 0, 0); + count = min(count, maxcount); + for (i = 0; i < count; i++) + { + ::SendMessage(hCombo, CB_GETLBTEXT, i, (LPARAM) text); + if (i < oldcount) + *pStrings[i] = text; + else + pStrings[i] = new generic_string(text); + } + for (; i < oldcount; i++) delete pStrings[i]; + oldcount = count; +} + +void FindReplaceDlg::updateCombos() +{ + updateCombo(IDREPLACEWITH); + updateCombo(IDFINDWHAT); +} + +FoundInfo Finder::EmptyFoundInfo(0, 0, TEXT("")); +SearchResultMarking Finder::EmptySearchResultMarking; + +bool Finder::notify(SCNotification *notification) +{ + static bool isDoubleClicked = false; + + switch (notification->nmhdr.code) + { + case SCN_MARGINCLICK: + if (notification->margin == ScintillaEditView::_SC_MARGE_FOLDER) + { + _scintView.marginClick(notification->position, notification->modifiers); + } + break; + + case SCN_DOUBLECLICK: + { + // remove selection from the finder + isDoubleClicked = true; + int pos = notification->position; + if (pos == INVALID_POSITION) + pos = _scintView.execute(SCI_GETLINEENDPOSITION, notification->line); + _scintView.execute(SCI_SETSEL, pos, pos); + + GotoFoundLine(); + } + break; + + case SCN_PAINTED : + if (isDoubleClicked) + { + (*_ppEditView)->getFocus(); + isDoubleClicked = false; + } + break; + } + return false; +} + + +void Finder::GotoFoundLine() +{ + int currentPos = _scintView.execute(SCI_GETCURRENTPOS); + int lno = _scintView.execute(SCI_LINEFROMPOSITION, currentPos); + int start = _scintView.execute(SCI_POSITIONFROMLINE, lno); + int end = _scintView.execute(SCI_GETLINEENDPOSITION, lno); + if (start + 2 >= end) return; // avoid empty lines + + if (_scintView.execute(SCI_GETFOLDLEVEL, lno) & SC_FOLDLEVELHEADERFLAG) + { + _scintView.execute(SCI_TOGGLEFOLD, lno); + return; + } + + const FoundInfo fInfo = *(_pMainFoundInfos->begin() + lno); + + // Switch to another document + ::SendMessage(::GetParent(_hParent), WM_DOOPEN, 0, (LPARAM)fInfo._fullPath.c_str()); + Searching::displaySectionCentered(fInfo._start, fInfo._end, *_ppEditView); + + // Then we colourise the double clicked line + setFinderStyle(); + _scintView.execute(SCI_SETLEXER, SCLEX_NULL); // yniq - this line causes a bug!!! (last line suddenly belongs to file header level (?) instead of having level=0x400) + // later it affects DeleteResult and gotoNextFoundResult (assertions) + // fixed by calling setFinderStyle() in DeleteResult() + _scintView.execute(SCI_STYLESETEOLFILLED, SCE_SEARCHRESULT_HIGHLIGHT_LINE, true); + _scintView.execute(SCI_STARTSTYLING, start, STYLING_MASK); + _scintView.execute(SCI_SETSTYLING, end - start + 2, SCE_SEARCHRESULT_HIGHLIGHT_LINE); + _scintView.execute(SCI_COLOURISE, start, end + 1); +} + +void Finder::DeleteResult() +{ + int currentPos = _scintView.execute(SCI_GETCURRENTPOS); // yniq - add handling deletion of multiple lines? + + int lno = _scintView.execute(SCI_LINEFROMPOSITION, currentPos); + int start = _scintView.execute(SCI_POSITIONFROMLINE, lno); + int end = _scintView.execute(SCI_GETLINEENDPOSITION, lno); + if (start + 2 >= end) return; // avoid empty lines + + _scintView.setLexer(SCLEX_SEARCHRESULT, L_SEARCHRESULT, 0); // Restore searchResult lexer in case the lexer was changed to SCLEX_NULL in GotoFoundLine() + + if (_scintView.execute(SCI_GETFOLDLEVEL, lno) & SC_FOLDLEVELHEADERFLAG) // delete a folder + { + int endline = _scintView.execute(SCI_GETLASTCHILD, lno, -1) + 1; + assert((size_t) endline <= _pMainFoundInfos->size()); + + _pMainFoundInfos->erase(_pMainFoundInfos->begin() + lno, _pMainFoundInfos->begin() + endline); // remove found info + _pMainMarkings->erase(_pMainMarkings->begin() + lno, _pMainMarkings->begin() + endline); + + int end = _scintView.execute(SCI_POSITIONFROMLINE, endline); + _scintView.execute(SCI_SETSEL, start, end); + setFinderReadOnly(false); + _scintView.execute(SCI_CLEAR); + setFinderReadOnly(true); + } + else // delete one line + { + assert((size_t) lno < _pMainFoundInfos->size()); + + _pMainFoundInfos->erase(_pMainFoundInfos->begin() + lno); // remove found info + _pMainMarkings->erase(_pMainMarkings->begin() + lno); + + setFinderReadOnly(false); + _scintView.execute(SCI_LINEDELETE); + setFinderReadOnly(true); + } + _MarkingsStruct._length = _pMainMarkings->size(); + + assert(_pMainFoundInfos->size() == _pMainMarkings->size()); + assert(_scintView.execute(SCI_GETLINECOUNT) == _pMainFoundInfos->size() + 1); +} + +void Finder::gotoNextFoundResult(int direction) +{ + int increment = direction < 0 ? -1 : 1; + int currentPos = _scintView.execute(SCI_GETCURRENTPOS); + int lno = _scintView.execute(SCI_LINEFROMPOSITION, currentPos); + int total_lines = _scintView.execute(SCI_GETLINECOUNT); + if (total_lines <= 1) return; + + if (lno == total_lines - 1) lno--; // last line doesn't belong to any search, use last search + + int init_lno = lno; + int max_lno = _scintView.execute(SCI_GETLASTCHILD, lno, searchHeaderLevel); + + assert(max_lno <= total_lines - 2); + + // get the line number of the current search (searchHeaderLevel) + int level = _scintView.execute(SCI_GETFOLDLEVEL, lno) & SC_FOLDLEVELNUMBERMASK; + int min_lno = lno; + while (level-- >= fileHeaderLevel) + { + min_lno = _scintView.execute(SCI_GETFOLDPARENT, min_lno); + assert(min_lno >= 0); + } + + if (min_lno < 0) min_lno = lno; // when lno is a search header line + + assert(min_lno <= max_lno); + + lno += increment; + + if (lno > max_lno) lno = min_lno; + else if (lno < min_lno) lno = max_lno; + + while (_scintView.execute(SCI_GETFOLDLEVEL, lno) & SC_FOLDLEVELHEADERFLAG) + { + lno += increment; + if (lno > max_lno) lno = min_lno; + else if (lno < min_lno) lno = max_lno; + if (lno == init_lno) break; + } + + if ((_scintView.execute(SCI_GETFOLDLEVEL, lno) & SC_FOLDLEVELHEADERFLAG) == 0) + { + int start = _scintView.execute(SCI_POSITIONFROMLINE, lno); + _scintView.execute(SCI_SETSEL, start, start); + _scintView.execute(SCI_ENSUREVISIBLE, lno); + _scintView.execute(SCI_SCROLLCARET); + + GotoFoundLine(); + } +} + +BOOL CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) +{ + switch (message) + { + case WM_INITDIALOG : + { + RECT arc; + ::GetWindowRect(::GetDlgItem(_hSelf, IDCANCEL), &arc); + _findInFilesClosePos.bottom = _replaceClosePos.bottom = _findClosePos.bottom = arc.bottom - arc.top; + _findInFilesClosePos.right = _replaceClosePos.right = _findClosePos.right = arc.right - arc.left; + + POINT p; + p.x = arc.left; + p.y = arc.top; + ::ScreenToClient(_hSelf, &p); + + _replaceClosePos.left = p.x; + _replaceClosePos.top = p.y; + + p = getLeftTopPoint(::GetDlgItem(_hSelf, IDREPLACEALL)); + _findInFilesClosePos.left = p.x; + _findInFilesClosePos.top = p.y; + + p = getLeftTopPoint(::GetDlgItem(_hSelf, IDCANCEL)); + _findClosePos.left = p.x; + _findClosePos.top = p.y + 10; + + return TRUE; + } + + case WM_HSCROLL : + { + if ((HWND)lParam == ::GetDlgItem(_hSelf, IDC_PERCENTAGE_SLIDER)) + { + int percent = ::SendDlgItemMessage(_hSelf, IDC_PERCENTAGE_SLIDER, TBM_GETPOS, 0, 0); + FindHistory & findHistory = (NppParameters::getInstance())->getFindHistory(); + findHistory._transparency = percent; + if (isCheckedOrNot(IDC_TRANSPARENT_ALWAYS_RADIO)) + { + (NppParameters::getInstance())->SetTransparent(_hSelf, percent); + } + } + return TRUE; + } + + case WM_NOTIFY: + { + NMHDR *nmhdr = (NMHDR *)lParam; + if (nmhdr->code == TCN_SELCHANGE) + { + HWND tabHandle = _tab.getHSelf(); + if (nmhdr->hwndFrom == tabHandle) + { + int indexClicked = int(::SendMessage(tabHandle, TCM_GETCURSEL, 0, 0)); + doDialog((DIALOG_TYPE)indexClicked); + } + return TRUE; + } + break; + } + + case WM_ACTIVATE : + { + if (LOWORD(wParam) == WA_ACTIVE || LOWORD(wParam) == WA_CLICKACTIVE) + { + CharacterRange cr = (*_ppEditView)->getSelection(); + int nbSelected = cr.cpMax - cr.cpMin; + + int checkVal; + if (nbSelected <= 1024) + { + checkVal = BST_UNCHECKED; + _isInSelection = false; + } + else + { + checkVal = BST_CHECKED; + _isInSelection = true; + } + + // Searching/replacing in column selection is not allowed + if ((*_ppEditView)->execute(SCI_GETSELECTIONMODE) == SC_SEL_RECTANGLE) + { + checkVal = BST_UNCHECKED; + _isInSelection = false; + nbSelected = 0; + } + ::EnableWindow(::GetDlgItem(_hSelf, IDC_IN_SELECTION_CHECK), nbSelected); + ::SendDlgItemMessage(_hSelf, IDC_IN_SELECTION_CHECK, BM_SETCHECK, checkVal, 0); + } + + if (isCheckedOrNot(IDC_TRANSPARENT_LOSSFOCUS_RADIO)) + { + if (LOWORD(wParam) == WA_INACTIVE) + { + int percent = ::SendDlgItemMessage(_hSelf, IDC_PERCENTAGE_SLIDER, TBM_GETPOS, 0, 0); + (NppParameters::getInstance())->SetTransparent(_hSelf, percent); + } + else + { + (NppParameters::getInstance())->removeTransparent(_hSelf); + } + } + return TRUE; + } + + case NPPM_MODELESSDIALOG : + return ::SendMessage(_hParent, NPPM_MODELESSDIALOG, wParam, lParam); + + case WM_COMMAND : + { + NppParameters *nppParamInst = NppParameters::getInstance(); + FindHistory & findHistory = nppParamInst->getFindHistory(); + switch (wParam) + { + case IDCANCEL : // Close + display(false); + return TRUE; + +//Single actions + case IDOK : // Find Next : only for FIND_DLG and REPLACE_DLG + { + bool isUnicode = (*_ppEditView)->getCurrentBuffer()->getUnicodeMode() != uni8Bit; + + HWND hFindCombo = ::GetDlgItem(_hSelf, IDFINDWHAT); + generic_string str2Search = getTextFromCombo(hFindCombo, isUnicode); + updateCombo(IDFINDWHAT); + + nppParamInst->_isFindReplacing = true; + processFindNext(str2Search.c_str()); + nppParamInst->_isFindReplacing = false; + } + return TRUE; + + case IDREPLACE : + { + if (_currentStatus == REPLACE_DLG) + { + bool isUnicode = (*_ppEditView)->getCurrentBuffer()->getUnicodeMode() != uni8Bit; + HWND hFindCombo = ::GetDlgItem(_hSelf, IDFINDWHAT); + HWND hReplaceCombo = ::GetDlgItem(_hSelf, IDREPLACEWITH); + generic_string str2Search = getTextFromCombo(hFindCombo, isUnicode); + generic_string str2Replace = getTextFromCombo(hReplaceCombo, isUnicode); + updateCombos(); + + nppParamInst->_isFindReplacing = true; + processReplace(str2Search.c_str(), str2Replace.c_str()); + nppParamInst->_isFindReplacing = false; + } + } + return TRUE; +//Process actions + case IDC_FINDALL_OPENEDFILES : + { + if (_currentStatus == FIND_DLG) + { + updateCombo(IDFINDWHAT); + + nppParamInst->_isFindReplacing = true; + findAllIn(ALL_OPEN_DOCS); + nppParamInst->_isFindReplacing = false; + } + } + return TRUE; + + case IDC_FINDALL_CURRENTFILE : + { + updateCombo(IDFINDWHAT); + + nppParamInst->_isFindReplacing = true; + findAllIn(CURRENT_DOC); + nppParamInst->_isFindReplacing = false; + } + return TRUE; + + case IDD_FINDINFILES_FIND_BUTTON : + { + const int filterSize = 256; + TCHAR filters[filterSize]; + TCHAR directory[MAX_PATH]; + ::GetDlgItemText(_hSelf, IDD_FINDINFILES_FILTERS_COMBO, filters, filterSize); + addText2Combo(filters, ::GetDlgItem(_hSelf, IDD_FINDINFILES_FILTERS_COMBO)); + _filters = filters; + + ::GetDlgItemText(_hSelf, IDD_FINDINFILES_DIR_COMBO, directory, MAX_PATH); + addText2Combo(directory, ::GetDlgItem(_hSelf, IDD_FINDINFILES_DIR_COMBO)); + _directory = directory; + + if ((lstrlen(directory) > 0) && (directory[lstrlen(directory)-1] != '\\')) + _directory += TEXT("\\"); + + updateCombo(IDFINDWHAT); + + nppParamInst->_isFindReplacing = true; + findAllIn(FILES_IN_DIR); + nppParamInst->_isFindReplacing = false; + } + return TRUE; + + case IDD_FINDINFILES_REPLACEINFILES : + { + const int filterSize = 256; + TCHAR filters[filterSize]; + TCHAR directory[MAX_PATH]; + ::GetDlgItemText(_hSelf, IDD_FINDINFILES_FILTERS_COMBO, filters, filterSize); + addText2Combo(filters, ::GetDlgItem(_hSelf, IDD_FINDINFILES_FILTERS_COMBO)); + _filters = filters; + + ::GetDlgItemText(_hSelf, IDD_FINDINFILES_DIR_COMBO, directory, MAX_PATH); + addText2Combo(directory, ::GetDlgItem(_hSelf, IDD_FINDINFILES_DIR_COMBO)); + _directory = directory; + + if ((lstrlen(directory) > 0) && (directory[lstrlen(directory)-1] != '\\')) + _directory += TEXT("\\"); + + generic_string msg = TEXT("Are you sure you want to replace all occurances in :\r"); + msg += _directory; + msg += TEXT("\rfor file type : "); + msg += _filters[0]?_filters:TEXT("*.*"); + + if (::MessageBox(_hSelf, msg.c_str(), TEXT("Are you sure?"), MB_OKCANCEL) == IDOK) + { + updateCombo(IDFINDWHAT); + updateCombo(IDREPLACEWITH); + + nppParamInst->_isFindReplacing = true; + ::SendMessage(_hParent, WM_REPLACEINFILES, 0, 0); + nppParamInst->_isFindReplacing = false; + } + } + return TRUE; + + case IDC_REPLACE_OPENEDFILES : + { + if (_currentStatus == REPLACE_DLG) + { + updateCombos(); + + nppParamInst->_isFindReplacing = true; + replaceAllInOpenedDocs(); + nppParamInst->_isFindReplacing = false; + } + } + return TRUE; + + case IDREPLACEALL : + { + if (_currentStatus == REPLACE_DLG) + { + updateCombos(); + + nppParamInst->_isFindReplacing = true; + (*_ppEditView)->execute(SCI_BEGINUNDOACTION); + int nbReplaced = processAll(ProcessReplaceAll, NULL, NULL); + (*_ppEditView)->execute(SCI_ENDUNDOACTION); + nppParamInst->_isFindReplacing = false; + + TCHAR result[64]; + if (nbReplaced < 0) + lstrcpy(result, TEXT("The regular expression to search is formed badly")); + else + wsprintf(result, TEXT("%d occurrences were replaced."), nbReplaced); + ::MessageBox(_hSelf, result, TEXT("Replace All"), MB_OK); + } + } + return TRUE; + + case IDCCOUNTALL : + { + if (_currentStatus == FIND_DLG) + { + int nbCounted = processAll(ProcessCountAll, NULL, NULL); + TCHAR result[128]; + if (nbCounted < 0) + lstrcpy(result, TEXT("The regular expression to search is formed badly.\r\nIs it resulting in nothing?")); + else + wsprintf(result, TEXT("%d match(es) to occurrence(s)"), nbCounted); + ::MessageBox(_hSelf, result, TEXT("Count"), MB_OK); + } + } + return TRUE; + + case IDCMARKALL : + { + if (_currentStatus == FIND_DLG) + { + updateCombo(IDFINDWHAT); + + nppParamInst->_isFindReplacing = true; + int nbMarked = processAll(ProcessMarkAll, NULL, NULL); + nppParamInst->_isFindReplacing = false; + TCHAR result[128]; + if (nbMarked < 0) + lstrcpy(result, TEXT("The regular expression to search is formed badly.\r\nIs it resulting in nothing?")); + else + wsprintf(result, TEXT("%d match(es) to occurrence(s)"), nbMarked); + ::MessageBox(_hSelf, result, TEXT("Mark"), MB_OK); + } + } + return TRUE; + + case IDC_CLEAR_ALL : + { + if (_currentStatus == FIND_DLG) + { + (*_ppEditView)->clearIndicator(SCE_UNIVERSAL_FOUND_STYLE); + (*_ppEditView)->execute(SCI_MARKERDELETEALL, MARK_BOOKMARK); + } + } + return TRUE; +//Option actions + case IDWHOLEWORD : + findHistory._isMatchWord = _options._isWholeWord = isCheckedOrNot(IDWHOLEWORD); + return TRUE; + + case IDMATCHCASE : + findHistory._isMatchCase = _options._isMatchCase = isCheckedOrNot(IDMATCHCASE); + return TRUE; + + case IDNORMAL: + case IDEXTENDED: + case IDREGEXP : { + if (isCheckedOrNot(IDREGEXP)) + { + _options._searchType = FindRegex; + findHistory._searchMode = FindHistory::regExpr; + } + else if (isCheckedOrNot(IDEXTENDED)) + { + _options._searchType = FindExtended; + findHistory._searchMode = FindHistory::extended; + } + else + { + _options._searchType = FindNormal; + findHistory._searchMode = FindHistory::normal; + } + + bool isRegex = (_options._searchType == FindRegex); + if (isRegex) + { + //regex doesnt allow whole word + _options._isWholeWord = false; + ::SendDlgItemMessage(_hSelf, IDWHOLEWORD, BM_SETCHECK, _options._isWholeWord?BST_CHECKED:BST_UNCHECKED, 0); + + //regex doesnt allow upward search + ::SendDlgItemMessage(_hSelf, IDDIRECTIONDOWN, BM_SETCHECK, BST_CHECKED, 0); + ::SendDlgItemMessage(_hSelf, IDDIRECTIONUP, BM_SETCHECK, BST_UNCHECKED, 0); + _options._whichDirection = DIR_DOWN; + } + + ::EnableWindow(::GetDlgItem(_hSelf, IDWHOLEWORD), (BOOL)!isRegex); + ::EnableWindow(::GetDlgItem(_hSelf, IDDIRECTIONUP), (BOOL)!isRegex); + return TRUE; } + + case IDWRAP : + findHistory._isWrap = _options._isWrapAround = isCheckedOrNot(IDWRAP); + return TRUE; + + case IDDIRECTIONUP : + case IDDIRECTIONDOWN : + _options._whichDirection = (BST_CHECKED == ::SendMessage(::GetDlgItem(_hSelf, IDDIRECTIONDOWN), BM_GETCHECK, BST_CHECKED, 0)); + findHistory._isDirectionDown = _options._whichDirection == DIR_DOWN; + return TRUE; + + case IDC_PURGE_CHECK : + { + if (_currentStatus == FIND_DLG) + _doPurge = isCheckedOrNot(IDC_PURGE_CHECK); + } + return TRUE; + + case IDC_MARKLINE_CHECK : + { + if (_currentStatus == FIND_DLG) + { + _doMarkLine = isCheckedOrNot(IDC_MARKLINE_CHECK); + ::EnableWindow(::GetDlgItem(_hSelf, IDCMARKALL), (_doMarkLine || _doStyleFoundToken)); + } + } + return TRUE; + + case IDC_STYLEFOUND_CHECK : + { + if (_currentStatus == FIND_DLG) + { + _doStyleFoundToken = isCheckedOrNot(IDC_STYLEFOUND_CHECK); + ::EnableWindow(::GetDlgItem(_hSelf, IDCMARKALL), (_doMarkLine || _doStyleFoundToken)); + } + } + return TRUE; + + case IDC_IN_SELECTION_CHECK : + { + if (_currentStatus == REPLACE_DLG) + _isInSelection = isCheckedOrNot(IDC_IN_SELECTION_CHECK); + } + return TRUE; + + case IDC_TRANSPARENT_CHECK : + { + bool isChecked = isCheckedOrNot(IDC_TRANSPARENT_CHECK); + + ::EnableWindow(::GetDlgItem(_hSelf, IDC_TRANSPARENT_GRPBOX), isChecked); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_TRANSPARENT_LOSSFOCUS_RADIO), isChecked); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_TRANSPARENT_ALWAYS_RADIO), isChecked); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_PERCENTAGE_SLIDER), isChecked); + + if (isChecked) + { + ::SendDlgItemMessage(_hSelf, IDC_TRANSPARENT_LOSSFOCUS_RADIO, BM_SETCHECK, BST_CHECKED, 0); + findHistory._transparencyMode = FindHistory::onLossingFocus; + } + else + { + ::SendDlgItemMessage(_hSelf, IDC_TRANSPARENT_LOSSFOCUS_RADIO, BM_SETCHECK, BST_UNCHECKED, 0); + ::SendDlgItemMessage(_hSelf, IDC_TRANSPARENT_ALWAYS_RADIO, BM_SETCHECK, BST_UNCHECKED, 0); + (NppParameters::getInstance())->removeTransparent(_hSelf); + findHistory._transparencyMode = FindHistory::none; + } + + return TRUE; + } + + case IDC_TRANSPARENT_ALWAYS_RADIO : + { + int percent = ::SendDlgItemMessage(_hSelf, IDC_PERCENTAGE_SLIDER, TBM_GETPOS, 0, 0); + (NppParameters::getInstance())->SetTransparent(_hSelf, percent); + findHistory._transparencyMode = FindHistory::persistant; + } + return TRUE; + + case IDC_TRANSPARENT_LOSSFOCUS_RADIO : + { + (NppParameters::getInstance())->removeTransparent(_hSelf); + findHistory._transparencyMode = FindHistory::onLossingFocus; + } + return TRUE; + + // + // Find in Files + // + case IDD_FINDINFILES_RECURSIVE_CHECK : + { + if (_currentStatus == FINDINFILES_DLG) + findHistory._isFifRecuisive = _isRecursive = isCheckedOrNot(IDD_FINDINFILES_RECURSIVE_CHECK); + + } + return TRUE; + + case IDD_FINDINFILES_INHIDDENDIR_CHECK : + { + if (_currentStatus == FINDINFILES_DLG) + findHistory._isFifInHiddenFolder = _isInHiddenDir = isCheckedOrNot(IDD_FINDINFILES_INHIDDENDIR_CHECK); + + } + return TRUE; + case IDD_FINDINFILES_BROWSE_BUTTON : + { + if (_currentStatus == FINDINFILES_DLG) + folderBrowser(_hSelf, IDD_FINDINFILES_DIR_COMBO, _directory.c_str()); + } + return TRUE; + + default : + break; + } + break; + } + } + return FALSE; +} + +// return value : +// true : the text2find is found +// false : the text2find is not found +bool FindReplaceDlg::processFindNext(const TCHAR *txt2find, FindOption *options) +{ + if (!txt2find || !txt2find[0]) + return false; + + FindOption *pOptions = options?options:&_options; + + int stringSizeFind = lstrlen(txt2find); + TCHAR *pText = new TCHAR[stringSizeFind + 1]; + lstrcpy(pText, txt2find); + + if (pOptions->_searchType == FindExtended) { + stringSizeFind = Searching::convertExtendedToString(txt2find, pText, stringSizeFind); + } + + int docLength = int((*_ppEditView)->execute(SCI_GETLENGTH)); + CharacterRange cr = (*_ppEditView)->getSelection(); + + //The search "zone" is relative to the selection, so search happens 'outside' + int startPosition = cr.cpMax; + int endPosition = docLength; + + if (pOptions->_whichDirection == DIR_UP) + { + //When searching upwards, start is the lower part, end the upper, for backwards search + startPosition = cr.cpMin - 1; + endPosition = 0; + } + + if (pOptions->_isIncremental) + { + startPosition = 0; + endPosition = docLength; + } + + bool isRegExp = pOptions->_searchType == FindRegex; + int flags = Searching::buildSearchFlags(pOptions); + + (*_ppEditView)->execute(SCI_SETSEARCHFLAGS, flags); + //::SendMessageA(_hParent, WM_SETTEXT, 0, (LPARAM)pText); + int posFind = (*_ppEditView)->searchInTarget(pText, startPosition, endPosition); + if (posFind == -1) //no match found in target, check if a new target should be used + { + if (pOptions->_isWrapAround) + { + //when wrapping, use the rest of the document (entire document is usable) + if (pOptions->_whichDirection == DIR_DOWN) + { + startPosition = 0; + endPosition = docLength; + } + else + { + startPosition = docLength; + endPosition = 0; + } + + //new target, search again + posFind = (*_ppEditView)->searchInTarget(pText, startPosition, endPosition); + } + if (posFind == -1) + { + //failed, or failed twice with wrap + if (!pOptions->_isIncremental) //incremental search doesnt trigger messages + { + generic_string msg = TEXT("Can't find the text:\r\n\""); + msg += pText; + msg += TEXT("\""); + ::MessageBox(_hSelf, msg.c_str(), TEXT("Find"), MB_OK); + // if the dialog is not shown, pass the focus to his parent(ie. Notepad++) + if (!::IsWindowVisible(_hSelf)) + { + ::SetFocus((*_ppEditView)->getHSelf()); + } + else + { + ::SetFocus(::GetDlgItem(_hSelf, IDFINDWHAT)); + } + } + delete [] pText; + return false; + } + } + + int start = posFind;//int((*_ppEditView)->execute(SCI_GETTARGETSTART)); + int end = int((*_ppEditView)->execute(SCI_GETTARGETEND)); + + // to make sure the found result is visible + Searching::displaySectionCentered(start, end, *_ppEditView, pOptions->_whichDirection == DIR_DOWN); + + + delete [] pText; + return true; +} + +// return value : +// true : the text is replaced, and find the next occurrence +// false : the text2find is not found, so the text is NOT replace +// || the text is replaced, and do NOT find the next occurrence +bool FindReplaceDlg::processReplace(const TCHAR *txt2find, const TCHAR *txt2replace, FindOption *options) +{ + if (!txt2find || !txt2find[0] || !txt2replace) + return false; + + FindOption *pOptions = options?options:&_options; + + if ((*_ppEditView)->getCurrentBuffer()->isReadOnly()) return false; + + int stringSizeFind = lstrlen(txt2find); + int stringSizeReplace = lstrlen(txt2replace); + TCHAR *pTextFind = new TCHAR[stringSizeFind + 1]; + TCHAR *pTextReplace = new TCHAR[stringSizeReplace + 1]; + lstrcpy(pTextFind, txt2find); + lstrcpy(pTextReplace, txt2replace); + + if (pOptions->_searchType == FindExtended) { + stringSizeFind = Searching::convertExtendedToString(txt2find, pTextFind, stringSizeFind); + stringSizeReplace = Searching::convertExtendedToString(txt2replace, pTextReplace, stringSizeReplace); + } + + bool isRegExp = pOptions->_searchType == FindRegex; + int flags = Searching::buildSearchFlags(pOptions); + CharacterRange cr = (*_ppEditView)->getSelection(); + + (*_ppEditView)->execute(SCI_SETSEARCHFLAGS, flags); + int posFind = (*_ppEditView)->searchInTarget(pTextFind, cr.cpMin, cr.cpMax); + if (posFind != -1) + { + if (isRegExp) + { + //For the rare re exp case. ex: replace ^ by AAA + int start = int((*_ppEditView)->execute(SCI_GETTARGETSTART)); + int end = int((*_ppEditView)->execute(SCI_GETTARGETEND)); + int foundTextLen = (end >= start)?end - start:start - end; + + int replacedLen = (*_ppEditView)->replaceTargetRegExMode(pTextReplace); + + //if (!foundTextLen) + (*_ppEditView)->execute(SCI_SETSEL, start, start + replacedLen); + } + else + { + int start = int((*_ppEditView)->execute(SCI_GETTARGETSTART)); + int replacedLen = (*_ppEditView)->replaceTarget(pTextReplace); + (*_ppEditView)->execute(SCI_SETSEL, start, start + replacedLen); + } + } + + delete [] pTextFind; + delete [] pTextReplace; + return processFindNext(txt2find); //after replacing, find the next section for selection +} + + +int FindReplaceDlg::markAll(const TCHAR *txt2find, int styleID) +{ + _doStyleFoundToken = true; + FindOption opt; + opt._isMatchCase = true; + opt._isWholeWord = false; + + int nbFound = processAll(ProcessMarkAllExt, txt2find, NULL, true, NULL, &opt, styleID); + return nbFound; +} + +int FindReplaceDlg::markAll2(const TCHAR *txt2find) +{ + FindOption opt; + opt._isMatchCase = false; + opt._isWholeWord = true; + int nbFound = processAll(ProcessMarkAll_2, txt2find, NULL, true, NULL, &opt); + return nbFound; +} + + + +int FindReplaceDlg::markAllInc(const TCHAR *txt2find, FindOption *opt) +{ + int nbFound = processAll(ProcessMarkAll_IncSearch, txt2find, NULL, true, NULL, opt); + return nbFound; +} + +int FindReplaceDlg::processAll(ProcessOperation op, const TCHAR *txt2find, const TCHAR *txt2replace, bool isEntire, const TCHAR *fileName, FindOption *opt, int colourStyleID) +{ + FindOption *pOptions = opt?opt:&_options; + + CharacterRange cr = (*_ppEditView)->getSelection(); + int docLength = int((*_ppEditView)->execute(SCI_GETLENGTH)); + + // Default : + // direction : down + // begin at : 0 + // end at : end of doc + int startPosition = 0; + int endPosition = docLength; + + bool direction = pOptions->_whichDirection; + + //first try limiting scope by direction + if (direction == DIR_UP) + { + startPosition = 0; + endPosition = cr.cpMax; + } + else + { + startPosition = cr.cpMin; + endPosition = docLength; + } + + //then adjust scope if the full document needs to be changed + if (pOptions->_isWrapAround || isEntire || (op == ProcessCountAll)) //entire document needs to be scanned + { + startPosition = 0; + endPosition = docLength; + } + + //then readjust scope if the selection override is active and allowed + if ((_isInSelection) && ((op == ProcessMarkAll) || ((op == ProcessReplaceAll) && (!isEntire)))) //if selection limiter and either mark all or replace all w/o entire document override + { + startPosition = cr.cpMin; + endPosition = cr.cpMax; + } + + if (ProcessMarkAllExt && colourStyleID != -1) + { + startPosition = 0; + endPosition = docLength; + } + + return processRange(op, txt2find, txt2replace, startPosition, endPosition, fileName, opt, colourStyleID); +} + +int FindReplaceDlg::processRange(ProcessOperation op, const TCHAR *txt2find, const TCHAR *txt2replace, int startRange, int endRange, const TCHAR *fileName, FindOption *opt, int colourStyleID) +{ + int nbProcessed = 0; + + if (!isCreated() && !txt2find) + return nbProcessed; + + if ((op == ProcessReplaceAll) && (*_ppEditView)->getCurrentBuffer()->isReadOnly()) + return nbProcessed; + + if (startRange == endRange) + return nbProcessed; + + if (!fileName) + fileName = TEXT(""); + + FindOption *pOptions = opt?opt:&_options; + //bool isUnicode = (*_ppEditView)->getCurrentBuffer()->getUnicodeMode() != uni8Bit; + bool isUnicode = ((*_ppEditView)->execute(SCI_GETCODEPAGE) == SC_CP_UTF8); + + int stringSizeFind = 0; + int stringSizeReplace = 0; + + TCHAR *pTextFind = NULL;//new TCHAR[stringSizeFind + 1]; + if (!txt2find) + { + HWND hFindCombo = ::GetDlgItem(_hSelf, IDFINDWHAT); + generic_string str2Search = getTextFromCombo(hFindCombo, isUnicode); + stringSizeFind = str2Search.length(); + pTextFind = new TCHAR[stringSizeFind + 1]; + lstrcpy(pTextFind, str2Search.c_str()); + } + else + { + stringSizeFind = lstrlen(txt2find); + pTextFind = new TCHAR[stringSizeFind + 1]; + lstrcpy(pTextFind, txt2find); + } + + if (!pTextFind[0]) + { + delete [] pTextFind; + return nbProcessed; + } + + TCHAR *pTextReplace = NULL; + if (op == ProcessReplaceAll) + { + if (!txt2replace) + { + HWND hReplaceCombo = ::GetDlgItem(_hSelf, IDREPLACEWITH); + generic_string str2Replace = getTextFromCombo(hReplaceCombo, isUnicode); + stringSizeReplace = str2Replace.length(); + pTextReplace = new TCHAR[stringSizeReplace + 1]; + lstrcpy(pTextReplace, str2Replace.c_str()); + } + else + { + stringSizeReplace = lstrlen(txt2replace); + pTextReplace = new TCHAR[stringSizeReplace + 1]; + lstrcpy(pTextReplace, txt2replace); + } + } + + if (pOptions->_searchType == FindExtended) { + stringSizeFind = Searching::convertExtendedToString(pTextFind, pTextFind, stringSizeFind); + if (op == ProcessReplaceAll) + stringSizeReplace = Searching::convertExtendedToString(pTextReplace, pTextReplace, stringSizeReplace); + } + + bool isRegExp = pOptions->_searchType == FindRegex; + int flags = Searching::buildSearchFlags(pOptions); + + + + if (op == ProcessMarkAll && colourStyleID == -1) //if marking, check if purging is needed + { + if (_doPurge) { + if (_doMarkLine) + (*_ppEditView)->execute(SCI_MARKERDELETEALL, MARK_BOOKMARK); + + if (_doStyleFoundToken) + (*_ppEditView)->clearIndicator(SCE_UNIVERSAL_FOUND_STYLE); + } + } + + int targetStart = 0; + int targetEnd = 0; + + //Initial range for searching + (*_ppEditView)->execute(SCI_SETSEARCHFLAGS, flags); + targetStart = (*_ppEditView)->searchInTarget(pTextFind, startRange, endRange); + + if ((targetStart != -1) && (op == ProcessFindAll)) //add new filetitle if this file results in hits + { + _pFinder->addFileNameTitle(fileName); + } + while (targetStart != -1) + { + //int posFindBefore = posFind; + targetStart = int((*_ppEditView)->execute(SCI_GETTARGETSTART)); + targetEnd = int((*_ppEditView)->execute(SCI_GETTARGETEND)); + if (targetEnd > endRange) { //we found a result but outside our range, therefore do not process it + break; + } + int foundTextLen = targetEnd - targetStart; + int replaceDelta = 0; + + // Search resulted in empty token, possible with RE + if (!foundTextLen) { + delete [] pTextFind; + delete [] pTextReplace; + return -1; + } + + switch (op) + { + case ProcessFindAll: + { + int lineNumber = (*_ppEditView)->execute(SCI_LINEFROMPOSITION, targetStart); + int lend = (*_ppEditView)->execute(SCI_GETLINEENDPOSITION, lineNumber); + int lstart = (*_ppEditView)->execute(SCI_POSITIONFROMLINE, lineNumber); + int nbChar = lend - lstart; + + // use the static buffer + TCHAR lineBuf[1024]; + + if (nbChar > 1024 - 3) + lend = lstart + 1020; + + int start_mark = targetStart - lstart; + int end_mark = targetEnd - lstart; + + (*_ppEditView)->getGenericText(lineBuf, lstart, lend, &start_mark, &end_mark); + generic_string line; +#ifdef UNICODE + line = lineBuf; +#else + UINT cp = (*_ppEditView)->execute(SCI_GETCODEPAGE); + if (cp != SC_CP_UTF8) + { + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + const wchar_t *pTextW = wmc->char2wchar(lineBuf, ::GetACP()); + const char *pTextA = wmc->wchar2char(pTextW, SC_CP_UTF8); + line = pTextA; + } + else + line = lineBuf; +#endif + line += TEXT("\r\n"); + SearchResultMarking srm; + srm._start = start_mark; + srm._end = end_mark; + _pFinder->add(FoundInfo(targetStart, targetEnd, fileName), srm, line.c_str(), lineNumber + 1); + + break; + } + + case ProcessReplaceAll: + { + int replacedLength; + if (isRegExp) + replacedLength = (*_ppEditView)->replaceTargetRegExMode(pTextReplace); + else + replacedLength = (*_ppEditView)->replaceTarget(pTextReplace); + + replaceDelta = replacedLength - foundTextLen; + break; + } + + case ProcessMarkAll: + { + if (_doStyleFoundToken) + { + (*_ppEditView)->execute(SCI_SETINDICATORCURRENT, SCE_UNIVERSAL_FOUND_STYLE); + (*_ppEditView)->execute(SCI_INDICATORFILLRANGE, targetStart, foundTextLen); + } + + if (_doMarkLine) + { + int lineNumber = (*_ppEditView)->execute(SCI_LINEFROMPOSITION, targetStart); + int state = (*_ppEditView)->execute(SCI_MARKERGET, lineNumber); + + if (!(state & (1 << MARK_BOOKMARK))) + (*_ppEditView)->execute(SCI_MARKERADD, lineNumber, MARK_BOOKMARK); + } + break; + } + + case ProcessMarkAllExt: + { + (*_ppEditView)->execute(SCI_SETINDICATORCURRENT, colourStyleID); + (*_ppEditView)->execute(SCI_INDICATORFILLRANGE, targetStart, foundTextLen); + break; + } + + case ProcessMarkAll_2: + { + (*_ppEditView)->execute(SCI_SETINDICATORCURRENT, SCE_UNIVERSAL_FOUND_STYLE_2); + (*_ppEditView)->execute(SCI_INDICATORFILLRANGE, targetStart, foundTextLen); + break; + } + + case ProcessMarkAll_IncSearch: + { + (*_ppEditView)->execute(SCI_SETINDICATORCURRENT, SCE_UNIVERSAL_FOUND_STYLE_INC); + (*_ppEditView)->execute(SCI_INDICATORFILLRANGE, targetStart, foundTextLen); + break; + } + + case ProcessCountAll: + { + //Nothing to do + break; + } + + default: + { + delete [] pTextFind; + delete [] pTextReplace; + return nbProcessed; + } + + } + + startRange = targetStart + foundTextLen + replaceDelta; //search from result onwards + endRange += replaceDelta; //adjust end of range in case of replace + + nbProcessed++; + + //::SendMessageA(_hParent, WM_SETTEXT, 0, (LPARAM)pTextFind); + targetStart = (*_ppEditView)->searchInTarget(pTextFind, startRange, endRange); + } + delete [] pTextFind; + delete [] pTextReplace; + + if (nbProcessed > 0 && op == ProcessFindAll) + _pFinder->addFileHitCount(nbProcessed); + + return nbProcessed; +} + +void FindReplaceDlg::replaceAllInOpenedDocs() +{ + ::SendMessage(_hParent, WM_REPLACEALL_INOPENEDDOC, 0, 0); +} + +void FindReplaceDlg::findAllIn(InWhat op) +{ + //HANDLE hEvent = ::OpenEvent(EVENT_ALL_ACCESS, FALSE, TEXT("findInFilesEvent")); + if (!_pFinder) + { + _pFinder = new Finder(); + _pFinder->init(_hInst, _hSelf, _ppEditView); + + tTbData data = {0}; + _pFinder->create(&data, false); + ::SendMessage(_hParent, NPPM_MODELESSDIALOG, MODELESSDIALOGREMOVE, (WPARAM)_pFinder->getHSelf()); + // define the default docking behaviour + data.uMask = DWS_DF_CONT_BOTTOM | DWS_ICONTAB | DWS_ADDINFO; + data.hIconTab = (HICON)::LoadImage(_hInst, MAKEINTRESOURCE(IDI_FIND_RESULT_ICON), IMAGE_ICON, 0, 0, LR_LOADMAP3DCOLORS | LR_LOADTRANSPARENT); + data.pszAddInfo = _findAllResultStr; + + data.pszModuleName = TEXT("dummy"); + + // the dlgDlg should be the index of funcItem where the current function pointer is + // in this case is DOCKABLE_DEMO_INDEX + data.dlgID = 0; + ::SendMessage(_hParent, NPPM_DMMREGASDCKDLG, 0, (LPARAM)&data); + + _pFinder->_scintView.init(_hInst, _pFinder->getHSelf()); + + // Subclass the ScintillaEditView for the Finder (Scintilla doesn't notify all key presses) + originalFinderProc = SetWindowLong( _pFinder->_scintView.getHSelf(), GWL_WNDPROC, (LONG) finderProc); + + _pFinder->setFinderReadOnly(true); + _pFinder->_scintView.execute(SCI_SETCODEPAGE, SC_CP_UTF8); + _pFinder->_scintView.execute(SCI_USEPOPUP, FALSE); + _pFinder->_scintView.execute(SCI_SETUNDOCOLLECTION, false); //dont store any undo information + _pFinder->_scintView.execute(SCI_SETCARETLINEVISIBLE, 1); + _pFinder->_scintView.execute(SCI_SETCARETWIDTH, 0); + _pFinder->_scintView.showMargin(ScintillaEditView::_SC_MARGE_FOLDER, true); + //_pFinder->_scintView.execute(SCI_SETEOLMODE, SC_EOL_CRLF); // yniq - needed? + + // Send the address of _MarkingsStruct to the lexer + char ptrword[sizeof(void*)*2+1]; + sprintf(ptrword, "%p", &_pFinder->_MarkingsStruct); + _pFinder->_scintView.execute(SCI_SETKEYWORDS, 0, (LPARAM) ptrword); + + // get the width of FindDlg + RECT findRect; + ::GetWindowRect(_pFinder->getHSelf(), &findRect); + + // overwrite some default settings + _pFinder->_scintView.showMargin(ScintillaEditView::_SC_MARGE_SYBOLE, false); + _pFinder->_scintView.setMakerStyle(FOLDER_STYLE_SIMPLE); + + _pFinder->_scintView.display(); + _pFinder->display(); + } + _pFinder->setFinderStyle(); + + ::SendMessage(_pFinder->getHSelf(), WM_SIZE, 0, 0); + + int cmdid = 0; + if (op == ALL_OPEN_DOCS) + cmdid = WM_FINDALL_INOPENEDDOC; + else if (op == FILES_IN_DIR) + cmdid = WM_FINDINFILES; + else if (op == CURRENT_DOC) + cmdid = WM_FINDALL_INCURRENTDOC; + + if (!cmdid) return; + + if (::SendMessage(_hParent, cmdid, 0, 0)) + { + wsprintf(_findAllResultStr, TEXT("%d hits"), _findAllResult); + if (_findAllResult) + { + focusOnFinder(); + } + else + getFocus(); // no hits + } + else // error - search folder doesn't exist + ::SendMessage(_hSelf, WM_NEXTDLGCTL, (WPARAM)::GetDlgItem(_hSelf, IDD_FINDINFILES_DIR_COMBO), TRUE); +} + +void FindReplaceDlg::enableReplaceFunc(bool isEnable) +{ + _currentStatus = isEnable?REPLACE_DLG:FIND_DLG; + int hideOrShow = isEnable?SW_SHOW:SW_HIDE; + RECT *pClosePos = isEnable?&_replaceClosePos:&_findClosePos; + + enableFindInFilesControls(false); + + // replce controls + ::ShowWindow(::GetDlgItem(_hSelf, ID_STATICTEXT_REPLACE),hideOrShow); + ::ShowWindow(::GetDlgItem(_hSelf, IDREPLACE),hideOrShow); + ::ShowWindow(::GetDlgItem(_hSelf, IDREPLACEWITH),hideOrShow); + ::ShowWindow(::GetDlgItem(_hSelf, IDREPLACEALL),hideOrShow); + ::ShowWindow(::GetDlgItem(_hSelf, IDREPLACEINSEL),hideOrShow); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_REPLACE_OPENEDFILES),hideOrShow); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_REPLACEINSELECTION),hideOrShow); + + // find controls + ::ShowWindow(::GetDlgItem(_hSelf, IDC_FINDALL_OPENEDFILES), !hideOrShow); + ::ShowWindow(::GetDlgItem(_hSelf, IDCCOUNTALL),!hideOrShow); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_FINDALL_STATIC),!hideOrShow); + ::ShowWindow(::GetDlgItem(_hSelf, IDCMARKALL),!hideOrShow); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_MARKLINE_CHECK),!hideOrShow); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_STYLEFOUND_CHECK),!hideOrShow); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_PURGE_CHECK),!hideOrShow); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_CLEAR_ALL),!hideOrShow); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_FINDALL_CURRENTFILE),!hideOrShow); + + gotoCorrectTab(); + + ::MoveWindow(::GetDlgItem(_hSelf, IDCANCEL), pClosePos->left, pClosePos->top, pClosePos->right, pClosePos->bottom, TRUE); + + TCHAR label[MAX_PATH]; + _tab.getCurrentTitle(label, MAX_PATH); + ::SetWindowText(_hSelf, label); + + setDefaultButton(IDOK); +} + +void FindReplaceDlg::enableFindInFilesControls(bool isEnable) +{ + // Hide Items + ::ShowWindow(::GetDlgItem(_hSelf, IDWRAP), isEnable?SW_HIDE:SW_SHOW); + ::ShowWindow(::GetDlgItem(_hSelf, IDCCOUNTALL), isEnable?SW_HIDE:SW_SHOW); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_FINDALL_OPENEDFILES), isEnable?SW_HIDE:SW_SHOW); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_FINDALL_CURRENTFILE), isEnable?SW_HIDE:SW_SHOW); + ::ShowWindow(::GetDlgItem(_hSelf, IDOK), isEnable?SW_HIDE:SW_SHOW); + + ::ShowWindow(::GetDlgItem(_hSelf, IDC_FINDALL_STATIC), isEnable?SW_HIDE:SW_SHOW); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_MARKLINE_CHECK), isEnable?SW_HIDE:SW_SHOW); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_STYLEFOUND_CHECK), isEnable?SW_HIDE:SW_SHOW); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_PURGE_CHECK), isEnable?SW_HIDE:SW_SHOW); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_IN_SELECTION_CHECK), isEnable?SW_HIDE:SW_SHOW); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_CLEAR_ALL), isEnable?SW_HIDE:SW_SHOW); + ::ShowWindow(::GetDlgItem(_hSelf, IDCMARKALL), isEnable?SW_HIDE:SW_SHOW); + + ::ShowWindow(::GetDlgItem(_hSelf, IDC_DIR_STATIC), isEnable?SW_HIDE:SW_SHOW); + ::ShowWindow(::GetDlgItem(_hSelf, IDDIRECTIONUP), isEnable?SW_HIDE:SW_SHOW); + ::ShowWindow(::GetDlgItem(_hSelf, IDDIRECTIONDOWN), isEnable?SW_HIDE:SW_SHOW); + ::ShowWindow(::GetDlgItem(_hSelf, IDREPLACE), isEnable?SW_HIDE:SW_SHOW); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_REPLACEINSELECTION), isEnable?SW_HIDE:SW_SHOW); + ::ShowWindow(::GetDlgItem(_hSelf, IDREPLACEALL), isEnable?SW_HIDE:SW_SHOW); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_REPLACE_OPENEDFILES), isEnable?SW_HIDE:SW_SHOW); + + // Show Items + if (isEnable) + { + ::ShowWindow(::GetDlgItem(_hSelf, ID_STATICTEXT_REPLACE), SW_SHOW); + ::ShowWindow(::GetDlgItem(_hSelf, IDREPLACEWITH), SW_SHOW); + } + ::ShowWindow(::GetDlgItem(_hSelf, IDD_FINDINFILES_REPLACEINFILES), isEnable?SW_SHOW:SW_HIDE); + ::ShowWindow(::GetDlgItem(_hSelf, IDD_FINDINFILES_FILTERS_STATIC), isEnable?SW_SHOW:SW_HIDE); + ::ShowWindow(::GetDlgItem(_hSelf, IDD_FINDINFILES_FILTERS_COMBO), isEnable?SW_SHOW:SW_HIDE); + ::ShowWindow(::GetDlgItem(_hSelf, IDD_FINDINFILES_DIR_STATIC), isEnable?SW_SHOW:SW_HIDE); + ::ShowWindow(::GetDlgItem(_hSelf, IDD_FINDINFILES_DIR_COMBO), isEnable?SW_SHOW:SW_HIDE); + ::ShowWindow(::GetDlgItem(_hSelf, IDD_FINDINFILES_BROWSE_BUTTON), isEnable?SW_SHOW:SW_HIDE); + ::ShowWindow(::GetDlgItem(_hSelf, IDD_FINDINFILES_FIND_BUTTON), isEnable?SW_SHOW:SW_HIDE); + ::ShowWindow(::GetDlgItem(_hSelf, IDD_FINDINFILES_GOBACK_BUTTON), isEnable?SW_SHOW:SW_HIDE); + ::ShowWindow(::GetDlgItem(_hSelf, IDD_FINDINFILES_RECURSIVE_CHECK), isEnable?SW_SHOW:SW_HIDE); + ::ShowWindow(::GetDlgItem(_hSelf, IDD_FINDINFILES_INHIDDENDIR_CHECK), isEnable?SW_SHOW:SW_HIDE); +} + +void FindReplaceDlg::getPatterns(vector & patternVect) +{ + cutString(_filters.c_str(), patternVect); +} + +void Finder::setFinderStyle() +{ + // Set global styles for the finder + _scintView.performGlobalStyles(); + + // Set current line background color for the finder + const TCHAR * lexerName = ScintillaEditView::langNames[L_SEARCHRESULT].lexerName; + LexerStyler *pStyler = (_scintView._pParameter->getLStylerArray()).getLexerStylerByName(lexerName); + if (pStyler) + { + int i = pStyler->getStylerIndexByID(SCE_SEARCHRESULT_CURRENT_LINE); + if (i != -1) + { + Style & style = pStyler->getStyler(i); + _scintView.execute(SCI_SETCARETLINEBACK, style._bgColor); + } + } + + _scintView.setSearchResultLexer(); + _scintView.execute(SCI_COLOURISE, 0, -1); +} + +BOOL CALLBACK Finder::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) +{ + switch (message) + { + case WM_COMMAND : + { + switch (wParam) + { + case NPPM_INTERNAL_SCINTILLAFINFERCOLLAPSE : + { + _scintView.foldAll(fold_collapse); + return TRUE; + } + + case NPPM_INTERNAL_SCINTILLAFINFERUNCOLLAPSE : + { + _scintView.foldAll(fold_uncollapse); + return TRUE; + } + + case NPPM_INTERNAL_SCINTILLAFINFERCOPY : + { + _scintView.execute(SCI_COPY); + return TRUE; + } + + case NPPM_INTERNAL_SCINTILLAFINFERSELECTALL : + { + _scintView.execute(SCI_SELECTALL); + return TRUE; + } + + case NPPM_INTERNAL_SCINTILLAFINFERCLEARALL: + { + removeAll(); + return TRUE; + } + + default : + { + return FALSE; + } + } + } + + case WM_CONTEXTMENU : + { + if (HWND(wParam) == _scintView.getHSelf()) + { + POINT p; + ::GetCursorPos(&p); + ContextMenu scintillaContextmenu; + vector tmp; + tmp.push_back(MenuItemUnit(NPPM_INTERNAL_SCINTILLAFINFERCOLLAPSE, TEXT("Collapse all"))); + tmp.push_back(MenuItemUnit(NPPM_INTERNAL_SCINTILLAFINFERUNCOLLAPSE, TEXT("Uncollapse all"))); + tmp.push_back(MenuItemUnit(0, TEXT("Separator"))); + tmp.push_back(MenuItemUnit(NPPM_INTERNAL_SCINTILLAFINFERCOPY, TEXT("Copy"))); + tmp.push_back(MenuItemUnit(NPPM_INTERNAL_SCINTILLAFINFERSELECTALL, TEXT("Select All"))); + tmp.push_back(MenuItemUnit(NPPM_INTERNAL_SCINTILLAFINFERCLEARALL, TEXT("Clear All"))); + + scintillaContextmenu.create(_hSelf, tmp); + + scintillaContextmenu.display(p); + return TRUE; + } + return ::DefWindowProc(_hSelf, message, wParam, lParam); + } + + case WM_SIZE : + { + RECT rc; + getClientRect(rc); + _scintView.reSizeTo(rc); + break; + } + + case WM_NOTIFY: + { + notify(reinterpret_cast(lParam)); + return FALSE; + } + default : + return DockingDlgInterface::run_dlgProc(message, wParam, lParam); + } + return FALSE; +} + +void FindIncrementDlg::destroy() +{ + if (_pRebar) + { + _pRebar->removeBand(_rbBand.wID); + _pRebar = NULL; + } +} + +void FindIncrementDlg::display(bool toShow) const +{ + if (!_pRebar) + { + Window::display(toShow); + return; + } + if (toShow) + ::SetFocus(::GetDlgItem(_hSelf, IDC_INCFINDTEXT)); + _pRebar->setIDVisible(_rbBand.wID, toShow); +} + +BOOL CALLBACK FindIncrementDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) +{ + switch (message) + { + case WM_COMMAND : + { + bool isUnicode = (*(_pFRDlg->_ppEditView))->getCurrentBuffer()->getUnicodeMode() != uni8Bit; + switch (LOWORD(wParam)) + { + case IDCANCEL : + (*(_pFRDlg->_ppEditView))->clearIndicator(SCE_UNIVERSAL_FOUND_STYLE_INC); + ::SetFocus((*(_pFRDlg->_ppEditView))->getHSelf()); + + display(false); + return TRUE; + + case IDC_INCFINDPREVOK : + case IDC_INCFINDNXTOK : + { + FindOption fo; + fo._isWholeWord = false; + fo._isMatchCase = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_INCFINDMATCHCASE, BM_GETCHECK, 0, 0)); + if (LOWORD(wParam) == IDC_INCFINDPREVOK) + fo._whichDirection = DIR_UP; + + generic_string str2Search = _pFRDlg->getTextFromCombo(::GetDlgItem(_hSelf, IDC_INCFINDTEXT), isUnicode); + _pFRDlg->processFindNext(str2Search.c_str(), &fo); + } + return TRUE; + + case IDC_INCFINDMATCHCASE: + case IDC_INCFINDTEXT : + case IDC_INCFINDHILITEALL : + { + if (_doSearchFromBegin) + { + FindOption fo; + fo._isWholeWord = false; + fo._isIncremental = true; + fo._isMatchCase = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_INCFINDMATCHCASE, BM_GETCHECK, 0, 0)); + + generic_string str2Search = _pFRDlg->getTextFromCombo(::GetDlgItem(_hSelf, IDC_INCFINDTEXT), isUnicode); + bool isFound = _pFRDlg->processFindNext(str2Search.c_str(), &fo); + if (!isFound) + { + CharacterRange range = (*(_pFRDlg->_ppEditView))->getSelection(); + (*(_pFRDlg->_ppEditView))->execute(SCI_SETSEL, -1, range.cpMin); + } + + bool isHiLieAll = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_INCFINDHILITEALL, BM_GETCHECK, 0, 0)); + if (str2Search == TEXT("")) + isHiLieAll = false; + + markSelectedTextInc(isHiLieAll, &fo); + } + else + _doSearchFromBegin = true; + } + return TRUE; + + } + } + + case WM_ERASEBKGND: + { + HWND hParent = ::GetParent(_hSelf); + HDC winDC = (HDC)wParam; + //RTL handling + POINT pt = {0, 0}, ptOrig = {0, 0}; + ::MapWindowPoints(_hSelf, hParent, &pt, 1); + ::OffsetWindowOrgEx((HDC)wParam, pt.x, pt.y, &ptOrig); + LRESULT lResult = SendMessage(hParent, WM_ERASEBKGND,(WPARAM)winDC, 0); + ::SetWindowOrgEx(winDC, ptOrig.x, ptOrig.y, NULL); + return (BOOL)lResult; + break; + } + + case WM_MOVE: + { + ::InvalidateRect(_hSelf, NULL, TRUE); //when moving, force background redraw + return FALSE; + break; + } + } + return FALSE; +} + +void FindIncrementDlg::markSelectedTextInc(bool enable, FindOption *opt) +{ + (*(_pFRDlg->_ppEditView))->clearIndicator(SCE_UNIVERSAL_FOUND_STYLE_INC); + + if (!enable) + return; + + //Get selection + CharacterRange range = (*(_pFRDlg->_ppEditView))->getSelection(); + + //If nothing selected, dont mark anything + if (range.cpMin == range.cpMax) + return; + + TCHAR text2Find[FINDREPLACE_MAXLENGTH]; + (*(_pFRDlg->_ppEditView))->getGenericSelectedText(text2Find, FINDREPLACE_MAXLENGTH, false); //do not expand selection (false) + _pFRDlg->markAllInc(text2Find, opt); +} + +void FindIncrementDlg::addToRebar(ReBar * rebar) { + if(_pRebar) + return; + HWND hRebar = rebar->getHSelf(); + _pRebar = rebar; + RECT client; + getClientRect(client); + + ZeroMemory(&_rbBand, sizeof(REBARBANDINFO)); + _rbBand.cbSize = sizeof(REBARBANDINFO); + _rbBand.fMask = RBBIM_STYLE | RBBIM_CHILD | RBBIM_CHILDSIZE | + RBBIM_SIZE | RBBIM_ID; + + _rbBand.fStyle = RBBS_HIDDEN; + _rbBand.hwndChild = getHSelf(); + _rbBand.wID = REBAR_BAR_SEARCH; //ID REBAR_BAR_SEARCH for search dialog + _rbBand.cxMinChild = 0; + _rbBand.cyIntegral = 1; + _rbBand.cyMinChild = _rbBand.cyMaxChild = client.bottom-client.top; + _rbBand.cxIdeal = _rbBand.cx = client.right-client.left; + + _pRebar->addBand(&_rbBand, true); +} diff --git a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.h b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.h new file mode 100644 index 00000000..bb34c13a --- /dev/null +++ b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.h @@ -0,0 +1,594 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef FIND_REPLACE_DLG_H +#define FIND_REPLACE_DLG_H + +#include "StaticDialog.h" +#include "FindReplaceDlg_rc.h" +#include "Buffer.h" +#include "ScintillaEditView.h" +#include "StatusBar.h" +#include "DockingDlgInterface.h" + + +#define FIND_RECURSIVE 1 +#define FIND_INHIDDENDIR 2 + +#define FINDREPLACE_MAXLENGTH 2048 + +enum DIALOG_TYPE {FIND_DLG, REPLACE_DLG, FINDINFILES_DLG}; + +#define DIR_DOWN true +#define DIR_UP false + +//#define FIND_REPLACE_STR_MAX 256 + +enum InWhat{ALL_OPEN_DOCS, FILES_IN_DIR, CURRENT_DOC}; + +struct FoundInfo { + FoundInfo(int start, int end, const TCHAR *fullPath) + : _start(start), _end(end), _fullPath(fullPath) {}; + int _start; + int _end; + std::generic_string _fullPath; +}; + +struct TargetRange { + int targetStart; + int targetEnd; +}; + +enum SearchType { FindNormal, FindExtended, FindRegex }; +enum ProcessOperation { ProcessFindAll, ProcessReplaceAll, ProcessCountAll, ProcessMarkAll, ProcessMarkAll_2, ProcessMarkAll_IncSearch, ProcessMarkAllExt }; + +struct FindOption { + bool _isWholeWord; + bool _isMatchCase; + bool _isWrapAround; + bool _whichDirection; + bool _isIncremental; + SearchType _searchType; + FindOption() :_isWholeWord(true), _isMatchCase(true), _searchType(FindNormal),\ + _isWrapAround(true), _whichDirection(DIR_DOWN), _isIncremental(false){}; +}; + +//This class contains generic search functions as static functions for easy access +class Searching { +public: + static int convertExtendedToString(const TCHAR * query, TCHAR * result, int length); + static TargetRange t; + static int buildSearchFlags(FindOption * option) { + return (option->_isWholeWord ? SCFIND_WHOLEWORD : 0) | + (option->_isMatchCase ? SCFIND_MATCHCASE : 0) | + (option->_searchType == FindRegex ? SCFIND_REGEXP|SCFIND_POSIX : 0); + }; + static void displaySectionCentered(int posStart, int posEnd, ScintillaEditView * pEditView, bool isDownwards = true); + +private: + static bool readBase(const TCHAR * str, int * value, int base, int size); + +}; + +//Finder: Dockable window that contains search results +class Finder : public DockingDlgInterface { +friend class FindReplaceDlg; +public: + Finder() : DockingDlgInterface(IDD_FINDRESULT), _pMainFoundInfos(&_foundInfos1), _pMainMarkings(&_markings1) { + _MarkingsStruct._length = 0; + _MarkingsStruct._markings = NULL; + }; + + ~Finder() { + _scintView.destroy(); + } + void init(HINSTANCE hInst, HWND hPere, ScintillaEditView **ppEditView) { + DockingDlgInterface::init(hInst, hPere); + _ppEditView = ppEditView; + }; + + void addSearchLine(const TCHAR *searchName) { + generic_string str = TEXT("Search \""); + str += searchName; + str += TEXT("\"\r\n"); + + setFinderReadOnly(false); + _scintView.addGenericText(str.c_str()); + setFinderReadOnly(true); + _lastSearchHeaderPos = _scintView.execute(SCI_GETCURRENTPOS) - 2; + + _pMainFoundInfos->push_back(EmptyFoundInfo); + _pMainMarkings->push_back(EmptySearchResultMarking); + }; + + void addFileNameTitle(const TCHAR * fileName) { + generic_string str = TEXT(" "); + str += fileName; + str += TEXT("\r\n"); + + setFinderReadOnly(false); + _scintView.addGenericText(str.c_str()); + setFinderReadOnly(true); + _lastFileHeaderPos = _scintView.execute(SCI_GETCURRENTPOS) - 2; + + _pMainFoundInfos->push_back(EmptyFoundInfo); + _pMainMarkings->push_back(EmptySearchResultMarking); + }; + + void addFileHitCount(int count) { + TCHAR text[20]; + wsprintf(text, TEXT(" (%i hits)"), count); + setFinderReadOnly(false); + _scintView.insertGenericTextFrom(_lastFileHeaderPos, text); + setFinderReadOnly(true); + nFoundFiles++; + }; + + void addSearchHitCount(int count) { + TCHAR text[50]; + wsprintf(text, TEXT(" (%i hits in %i files)"), count, nFoundFiles); + setFinderReadOnly(false); + _scintView.insertGenericTextFrom(_lastSearchHeaderPos, text); + setFinderReadOnly(true); + }; + + + void add(FoundInfo fi, SearchResultMarking mi, const TCHAR* foundline, int lineNb) { + _pMainFoundInfos->push_back(fi); + std::generic_string str = TEXT("\tLine "); + + TCHAR lnb[16]; + wsprintf(lnb, TEXT("%d"), lineNb); + str += lnb; + str += TEXT(": "); + mi._start += str.length(); + mi._end += str.length(); + str += foundline; + + if (str.length() >= SC_SEARCHRESULT_LINEBUFFERMAXLENGTH) + { + const TCHAR * endOfLongLine = TEXT("...\r\n"); + str = str.substr(0, SC_SEARCHRESULT_LINEBUFFERMAXLENGTH - lstrlen(endOfLongLine) - 1); + str += endOfLongLine; + } + setFinderReadOnly(false); + _scintView.addGenericText(str.c_str(), &mi._start, &mi._end); + setFinderReadOnly(true); + _pMainMarkings->push_back(mi); + }; + + void setFinderStyle(); + + void removeAll() { + _pMainFoundInfos->clear(); + _pMainMarkings->clear(); + setFinderReadOnly(false); + _scintView.execute(SCI_CLEARALL); + setFinderReadOnly(true); + }; + + void beginNewFilesSearch() { + _scintView.execute(SCI_SETLEXER, SCLEX_NULL); + + _scintView.execute(SCI_SETCURRENTPOS, 0); + _pMainFoundInfos = _pMainFoundInfos == &_foundInfos1 ? &_foundInfos2 : &_foundInfos1; + _pMainMarkings = _pMainMarkings == &_markings1 ? &_markings2 : &_markings1; + nFoundFiles = 0; + + // fold all old searches (1st level only) + _scintView.collapse(searchHeaderLevel - SC_FOLDLEVELBASE, fold_collapse); + }; + + void finishFilesSearch(int count) { + std::vector* _pOldFoundInfos; + std::vector* _pOldMarkings; + _pOldFoundInfos = _pMainFoundInfos == &_foundInfos1 ? &_foundInfos2 : &_foundInfos1; + _pOldMarkings = _pMainMarkings == &_markings1 ? &_markings2 : &_markings1; + + _pOldFoundInfos->insert(_pOldFoundInfos->begin(), _pMainFoundInfos->begin(), _pMainFoundInfos->end()); + _pOldMarkings->insert(_pOldMarkings->begin(), _pMainMarkings->begin(), _pMainMarkings->end()); + _pMainFoundInfos->clear(); + _pMainMarkings->clear(); + _pMainFoundInfos = _pOldFoundInfos; + _pMainMarkings = _pOldMarkings; + + _MarkingsStruct._length = _pMainMarkings->size(); + _MarkingsStruct._markings = &((*_pMainMarkings)[0]); + + addSearchHitCount(count); + _scintView.execute(SCI_SETSEL, 0, 0); + + _scintView.execute(SCI_SETLEXER, SCLEX_SEARCHRESULT); + }; + + + void gotoNextFoundResult(int direction); + void GotoFoundLine(); + void DeleteResult(); + +protected : + virtual BOOL CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam); + bool notify(SCNotification *notification); + +private: + + enum { searchHeaderLevel = SC_FOLDLEVELBASE + 1, fileHeaderLevel, resultLevel }; + + ScintillaEditView **_ppEditView; + std::vector _foundInfos1; + std::vector _foundInfos2; + std::vector* _pMainFoundInfos; + std::vector _markings1; + std::vector _markings2; + std::vector* _pMainMarkings; + SearchResultMarkings _MarkingsStruct; + + ScintillaEditView _scintView; + unsigned int nFoundFiles; + + int _lastFileHeaderPos; + int _lastSearchHeaderPos; + + void setFinderReadOnly(bool isReadOnly) { + _scintView.execute(SCI_SETREADONLY, isReadOnly); + }; + + static FoundInfo EmptyFoundInfo; + static SearchResultMarking EmptySearchResultMarking; +}; + +//FindReplaceDialog: standard find/replace window +class FindReplaceDlg : public StaticDialog +{ +friend class FindIncrementDlg; +public : + FindReplaceDlg() : StaticDialog(), _pFinder(NULL), _isRTL(false), _isRecursive(true),_isInHiddenDir(false),\ + _fileNameLenMax(1024) { + _uniFileName = new char[(_fileNameLenMax + 3) * 2]; + _winVer = (NppParameters::getInstance())->getWinVersion(); + }; + ~FindReplaceDlg() { + _tab.destroy(); + if (_pFinder) + delete _pFinder; + delete [] _uniFileName; + }; + + void init(HINSTANCE hInst, HWND hPere, ScintillaEditView **ppEditView) { + Window::init(hInst, hPere); + if (!ppEditView) + throw int(9900); + _ppEditView = ppEditView; + }; + + virtual void create(int dialogID, bool isRTL = false); + + void initOptionsFromDlg() { + _options._isWholeWord = isCheckedOrNot(IDWHOLEWORD); + _options._isMatchCase = isCheckedOrNot(IDMATCHCASE); + _options._searchType = isCheckedOrNot(IDREGEXP)?FindRegex:isCheckedOrNot(IDEXTENDED)?FindExtended:FindNormal; + _options._isWrapAround = isCheckedOrNot(IDWRAP); + _isInSelection = isCheckedOrNot(IDC_IN_SELECTION_CHECK); + + // Set Direction : Down by default + _options._whichDirection = DIR_DOWN; + ::SendMessage(::GetDlgItem(_hSelf, IDDIRECTIONDOWN), BM_SETCHECK, BST_CHECKED, 0); + + _doPurge = isCheckedOrNot(IDC_PURGE_CHECK); + _doMarkLine = isCheckedOrNot(IDC_MARKLINE_CHECK); + _doStyleFoundToken = isCheckedOrNot(IDC_STYLEFOUND_CHECK); + + ::EnableWindow(::GetDlgItem(_hSelf, IDCMARKALL), (_doMarkLine || _doStyleFoundToken)); + }; + + void doDialog(DIALOG_TYPE whichType, bool isRTL = false) { + if (!isCreated()) + { + create(IDD_FIND_REPLACE_DLG, isRTL); + _isRTL = isRTL; + } + + if (whichType == FINDINFILES_DLG) + enableFindInFilesFunc(); + else + enableReplaceFunc(whichType == REPLACE_DLG); + + ::SetFocus(::GetDlgItem(_hSelf, IDFINDWHAT)); + display(); + }; + bool processFindNext(const TCHAR *txt2find, FindOption *options = NULL); + bool processReplace(const TCHAR *txt2find, const TCHAR *txt2replace, FindOption *options = NULL); + + int markAll(const TCHAR *txt2find, int styleID); + int markAll2(const TCHAR *str2find); + int markAllInc(const TCHAR *str2find, FindOption *opt); + + + int processAll(ProcessOperation op, const TCHAR *txt2find, const TCHAR *txt2replace, bool isEntire = false, const TCHAR *fileName = NULL, FindOption *opt = NULL, int colourStyleID = -1); + int processRange(ProcessOperation op, const TCHAR *txt2find, const TCHAR *txt2replace, int startRange, int endRange, const TCHAR *fileName = NULL, FindOption *opt = NULL, int colourStyleID = -1); + void replaceAllInOpenedDocs(); + void findAllIn(InWhat op); + + void setSearchText(TCHAR * txt2find) { + HWND hCombo = ::GetDlgItem(_hSelf, IDFINDWHAT); + if (txt2find && txt2find[0]) + { + // We got a valid search string + ::SendMessage(hCombo, CB_SETCURSEL, -1, 0); // remove selection - to allow using down arrow to get to last searched word + ::SetDlgItemText(_hSelf, IDFINDWHAT, txt2find); + } + ::SendMessage(hCombo, CB_SETEDITSEL, 0, MAKELPARAM(0, -1)); // select all text - fast edit + } + void gotoNextFoundResult(int direction = 0) {if (_pFinder) _pFinder->gotoNextFoundResult(direction);}; + + void putFindResult(int result) { + _findAllResult = result; + }; + const TCHAR * getDir2Search() const {return _directory.c_str();}; + + void getPatterns(vector & patternVect); + + void launchFindInFilesDlg() { + doDialog(FINDINFILES_DLG); + }; + + void setFindInFilesDirFilter(const TCHAR *dir, const TCHAR *filters) { + if (dir) + { + _directory = dir; + ::SetDlgItemText(_hSelf, IDD_FINDINFILES_DIR_COMBO, dir); + } + if (filters) + { + _filters = filters; + ::SetDlgItemText(_hSelf, IDD_FINDINFILES_FILTERS_COMBO, filters); + } + }; + + generic_string getText2search() const { + return getTextFromCombo(::GetDlgItem(_hSelf, IDFINDWHAT)); + }; + + const generic_string & getFilters() const {return _filters;}; + const generic_string & getDirectory() const {return _directory;}; + const FindOption & getCurrentOptions() const {return _options;}; + bool isRecursive() const { return _isRecursive; }; + bool isInHiddenDir() const { return _isInHiddenDir; }; + void saveFindHistory(); + void changeTabName(DIALOG_TYPE index, const TCHAR *name2change) { + TCITEM tie; + tie.mask = TCIF_TEXT; + tie.pszText = (TCHAR *)name2change; + TabCtrl_SetItem(_tab.getHSelf(), index, &tie); + } + void beginNewFilesSearch() + { + _pFinder->beginNewFilesSearch(); + bool isUnicode = (*_ppEditView)->getCurrentBuffer()->getUnicodeMode() != uni8Bit; + _pFinder->addSearchLine(getText2search().c_str()); + } + + void finishFilesSearch(int count) + { + _pFinder->finishFilesSearch(count); + } + + void focusOnFinder() { + // Show finder and set focus + if (_pFinder) + { + ::SendMessage(_hParent, NPPM_DMMSHOW, 0, (LPARAM)_pFinder->getHSelf()); + _pFinder->_scintView.getFocus(); + } + }; + + HWND getHFindResults() { + if (_pFinder) + return _pFinder->_scintView.getHSelf(); + return NULL; + } + + void updateFinderScintilla() { + if (_pFinder && _pFinder->isCreated() && _pFinder->isVisible()) + { + _pFinder->setFinderStyle(); + } + }; + +protected : + virtual BOOL CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam); + void addText2Combo(const TCHAR * txt2add, HWND comboID, bool isUTF8 = false); + generic_string getTextFromCombo(HWND hCombo, bool isUnicode = false) const; + static LONG originalFinderProc; + + // Window procedure for the finder + static LRESULT FAR PASCAL finderProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) + { + if (message == WM_KEYDOWN && (wParam == VK_DELETE || wParam == VK_RETURN)) + { + ScintillaEditView *pScint = (ScintillaEditView *)(::GetWindowLongPtr(hwnd, GWL_USERDATA)); + Finder *pFinder = (Finder *)(::GetWindowLongPtr(pScint->getHParent(), GWL_USERDATA)); + if (wParam == VK_RETURN) + pFinder->GotoFoundLine(); + else // VK_DELETE + pFinder->DeleteResult(); + return 0; + } + else + // Call default (original) window procedure + return CallWindowProc((WNDPROC) originalFinderProc, hwnd, message, wParam, lParam); + } + +private : + DIALOG_TYPE _currentStatus; + FindOption _options; + + bool _doPurge; + bool _doMarkLine; + bool _doStyleFoundToken; + bool _isInSelection; + + + RECT _findClosePos, _replaceClosePos, _findInFilesClosePos; + + ScintillaEditView **_ppEditView; + Finder *_pFinder; + bool _isRTL; + + int _findAllResult; + TCHAR _findAllResultStr[1024]; + + generic_string _filters; + generic_string _directory; + bool _isRecursive; + bool _isInHiddenDir; + + int _fileNameLenMax; + char *_uniFileName; + + TabBar _tab; + winVer _winVer; + + void enableReplaceFunc(bool isEnable); + void enableFindInFilesControls(bool isEnable = true); + void enableFindInFilesFunc() { + enableFindInFilesControls(); + + _currentStatus = FINDINFILES_DLG; + gotoCorrectTab(); + ::MoveWindow(::GetDlgItem(_hSelf, IDCANCEL), _findInFilesClosePos.left, _findInFilesClosePos.top, _findInFilesClosePos.right, _findInFilesClosePos.bottom, TRUE); + + TCHAR label[MAX_PATH]; + _tab.getCurrentTitle(label, MAX_PATH); + ::SetWindowText(_hSelf, label); + + setDefaultButton(IDD_FINDINFILES_FIND_BUTTON); + }; + + ////////////////// + + void setDefaultButton(int nID) + { +#if 0 + // There is a problem when you: + // 1. open the find dialog + // 2. press the "close" buttom + // 3. open it again + // 4. search for a non existing text + // 5. when the "Can't find the text:" messagebox appears, hit "OK" + // 6. now, the "Close" button looks like the default button. (but it only looks like that) + // if you hit "Enter" the "Find" button will be "pressed". + // I thought this code might fix this but it doesn't + // See: http://msdn.microsoft.com/en-us/library/ms645413(VS.85).aspx + + HWND pButton; + DWORD dwDefInfo = SendMessage(_hSelf, DM_GETDEFID, 0, 0L); + if (HIWORD(dwDefInfo) == DC_HASDEFID && (int)LOWORD(dwDefInfo) != nID) + { + // Reset 'DefButton' style + pButton = GetDlgItem(_hSelf, (int)LOWORD(dwDefInfo)); + if (pButton) + SendMessage(pButton, BM_SETSTYLE, LOWORD(BS_PUSHBUTTON | BS_RIGHT ), MAKELPARAM(TRUE, 0)); + } + + SendMessage(_hSelf, DM_SETDEFID, (WPARAM)nID, 0L); + pButton = GetDlgItem(_hSelf, nID); + if (pButton) + { + SendMessage(pButton, BM_SETSTYLE, LOWORD(BS_DEFPUSHBUTTON), MAKELPARAM(TRUE, 0)); + } +#endif + SendMessage(_hSelf, DM_SETDEFID, (WPARAM)nID, 0L); + } + //////////////////////// + + void gotoCorrectTab() { + int currentIndex = _tab.getCurrentTabIndex(); + if (currentIndex != _currentStatus) + _tab.activateAt(_currentStatus); + }; + + bool isCheckedOrNot(int checkControlID) const { + return (BST_CHECKED == ::SendMessage(::GetDlgItem(_hSelf, checkControlID), BM_GETCHECK, 0, 0)); + }; + + void updateCombos(); + void updateCombo(int comboID) { + bool isUnicode = (*_ppEditView)->getCurrentBuffer()->getUnicodeMode() != uni8Bit; + HWND hCombo = ::GetDlgItem(_hSelf, comboID); + addText2Combo(getTextFromCombo(hCombo, isUnicode).c_str(), hCombo, isUnicode); + }; + void fillFindHistory(); + void fillComboHistory(int id, int count, generic_string **pStrings); + void saveComboHistory(int id, int maxcount, int& oldcount, generic_string **pStrings); +}; + +//FindIncrementDlg: incremental search dialog, docked in rebar +class FindIncrementDlg : public StaticDialog +{ +public : + FindIncrementDlg() : _pFRDlg(NULL), _pRebar(NULL) {}; + void init(HINSTANCE hInst, HWND hPere, FindReplaceDlg *pFRDlg, bool isRTL = false) { + Window::init(hInst, hPere); + if (!pFRDlg) + throw int(9910); + _pFRDlg = pFRDlg; + create(IDD_INCREMENT_FIND, isRTL); + _isRTL = isRTL; + }; + virtual void destroy(); + virtual void display(bool toShow = true) const; + + void setSearchText(const TCHAR * txt2find, bool isUTF8 = false) { + _doSearchFromBegin = false; +#ifdef UNICODE + ::SendDlgItemMessage(_hSelf, IDC_INCFINDTEXT, WM_SETTEXT, 0, (LPARAM)txt2find); +#else + if (!isUTF8) + { + ::SendDlgItemMessage(_hSelf, IDC_INCFINDTEXT, WM_SETTEXT, 0, (LPARAM)txt2find); + return; + } + const int wideBufferSize = 256; + WCHAR wchars[wideBufferSize]; + ::MultiByteToWideChar(CP_UTF8, 0, txt2find, -1, wchars, wideBufferSize); + winVer winVersion = NppParameters::getInstance()->getWinVersion(); + if (winVersion <= WV_ME) { + //Cannot simply take txt2find since its UTF8 + char ansiBuffer[wideBufferSize]; //Assuming no more than 2 bytes for each wchar (SBCS or DBCS, no UTF8 and sorts) + ::WideCharToMultiByte(CP_ACP, 0, wchars, -1, ansiBuffer, wideBufferSize, NULL, NULL); + ::SendDlgItemMessageA(_hSelf, IDC_INCFINDTEXT, WM_SETTEXT, 0, (LPARAM)ansiBuffer); + } else { + ::SendDlgItemMessageW(_hSelf, IDC_INCFINDTEXT, WM_SETTEXT, 0, (LPARAM)wchars); + } +#endif + } + + void addToRebar(ReBar * rebar); +private : + bool _isRTL; + FindReplaceDlg *_pFRDlg; + + ReBar * _pRebar; + REBARBANDINFO _rbBand; + + bool _doSearchFromBegin; + virtual BOOL CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam); + void markSelectedTextInc(bool enable, FindOption *opt = NULL); +}; + +#endif //FIND_REPLACE_DLG_H diff --git a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.rc b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.rc new file mode 100644 index 00000000..fbcb5d15 --- /dev/null +++ b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.rc @@ -0,0 +1,100 @@ +/* +this file is part of notepad++ +Copyright (C)2003 Don HO + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef FIND_REPLACE_DLG_RC +#define FIND_REPLACE_DLG_RC +#include +#include "FindReplaceDlg_rc.h" + +IDD_FIND_REPLACE_DLG DIALOGEX 36, 44, 317, 182 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU +EXSTYLE WS_EX_TOOLWINDOW +CAPTION "Replace" +FONT 8, "MS Shell Dlg", 0, 0, 0x0 +BEGIN + RTEXT "&Find what :",IDFINDWHAT_STATIC,6,22,75,8 + COMBOBOX IDFINDWHAT,83,20,125,150,CBS_DROPDOWN | CBS_AUTOHSCROLL | WS_TABSTOP + RTEXT "Rep&lace with :",ID_STATICTEXT_REPLACE,6,40,75,8 + COMBOBOX IDREPLACEWITH,83,38,125,50,CBS_DROPDOWN | CBS_AUTOHSCROLL | WS_TABSTOP + CONTROL "&Mark Line",IDC_MARKLINE_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,13,40,88,10 + CONTROL "Style found to&ken",IDC_STYLEFOUND_CHECK,"Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,13,52,100,15 + GROUPBOX "",IDC_FINDALL_STATIC,6,31,204,54 + CONTROL "Purge for each search",IDC_PURGE_CHECK,"Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,13,66,99,16 + PUSHBUTTON "Find &All",IDCMARKALL,146,38,59,14 + GROUPBOX "",IDC_REPLACEINSELECTION,141,50,170,23 + CONTROL "In select&ion",IDC_IN_SELECTION_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,146,58,59,10 + PUSHBUTTON "Clear",IDC_CLEAR_ALL,146,71,59,11 + RTEXT "Filter&s :",IDD_FINDINFILES_FILTERS_STATIC,27,58,53,8 + COMBOBOX IDD_FINDINFILES_FILTERS_COMBO,83,56,125,150,CBS_DROPDOWN | CBS_AUTOHSCROLL | WS_TABSTOP + RTEXT "Dir&ectory :",IDD_FINDINFILES_DIR_STATIC,7,76,40,8 + COMBOBOX IDD_FINDINFILES_DIR_COMBO,49,74,141,150,CBS_DROPDOWN | CBS_AUTOHSCROLL | WS_TABSTOP + PUSHBUTTON "...",IDD_FINDINFILES_BROWSE_BUTTON,193,74,15,13 + CONTROL "In all su&b-folders",IDD_FINDINFILES_RECURSIVE_CHECK, "Button", BS_AUTOCHECKBOX | WS_TABSTOP,218,73,94,15 + CONTROL "In &hidden folders",IDD_FINDINFILES_INHIDDENDIR_CHECK, "Button", BS_AUTOCHECKBOX | WS_TABSTOP,218,87,94,15 + CONTROL "Match &whole word only",IDWHOLEWORD,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,6,88,140,15 + CONTROL "Match &case",IDMATCHCASE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,6,100,140,15 + CONTROL "Wra&p around",IDWRAP,"Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,6,112,110,15 + GROUPBOX "Search mode",IDC_MODE_STATIC,6,126,138,48 + CONTROL "&Normal",IDNORMAL,"Button",BS_AUTORADIOBUTTON | WS_GROUP,12,138,126,10 + CONTROL "E&xtended (\\n, \\r, \\t, \\0, \\x...)",IDEXTENDED, "Button",BS_AUTORADIOBUTTON,12,150,126,10 + CONTROL "Re&gular expression",IDREGEXP,"Button",BS_AUTORADIOBUTTON,12,162,126,10 + CONTROL "&Up",IDDIRECTIONUP,"Button",BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP,155,138,45,12 + CONTROL "&Down",IDDIRECTIONDOWN,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,155,150,45,12 + GROUPBOX "Direction",IDC_DIR_STATIC,150,126,60,48,WS_GROUP + PUSHBUTTON "Find Next",IDOK,217,20,90,14,WS_GROUP + PUSHBUTTON "Coun&t",IDCCOUNTALL,217,38,90,14 + PUSHBUTTON "Find all in all &opened documents",IDC_FINDALL_OPENEDFILES,217,56,90,21,BS_MULTILINE + PUSHBUTTON "Find all in current document",IDC_FINDALL_CURRENTFILE,217,80,90,21,BS_MULTILINE + PUSHBUTTON "&Replace",IDREPLACE,217,38,90,14 + PUSHBUTTON "Replace &All",IDREPLACEALL,217,56,90,14 + PUSHBUTTON "Replace all in all &opened documents",IDC_REPLACE_OPENEDFILES,217,74,90,21,BS_MULTILINE + PUSHBUTTON "Find All",IDD_FINDINFILES_FIND_BUTTON,217,20,90,14,WS_GROUP + PUSHBUTTON "&Replace in files",IDD_FINDINFILES_REPLACEINFILES,217,38,90,14 + PUSHBUTTON "Close",IDCANCEL,217,98,90,14 + GROUPBOX "",IDC_TRANSPARENT_GRPBOX,222,126,85,48 + CONTROL "Transparenc&y",IDC_TRANSPARENT_CHECK,"Button",BS_AUTOCHECKBOX | NOT WS_VISIBLE | WS_TABSTOP,218,126,80,10 + CONTROL "On lose focus",IDC_TRANSPARENT_LOSSFOCUS_RADIO,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,232,138,70,10 + CONTROL "Always",IDC_TRANSPARENT_ALWAYS_RADIO,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,232,150,70,10 + CONTROL "",IDC_PERCENTAGE_SLIDER,"msctls_trackbar32",TBS_BOTH | TBS_NOTICKS | NOT WS_VISIBLE | WS_TABSTOP,235,161,53,10 +END + +IDD_INCREMENT_FIND DIALOGEX 0, 0, 400, 20 +STYLE DS_SYSMODAL | DS_CONTROL | DS_FIXEDSYS | WS_CHILD | WS_CLIPCHILDREN +//EXSTYLE WS_EX_TRANSPARENT +FONT 8, TEXT("MS Shell Dlg") +BEGIN + PUSHBUTTON "X",IDCANCEL,2,3,16,14 + RTEXT "Find :",IDC_INCSTATIC,20,6,25,12 + EDITTEXT IDC_INCFINDTEXT,45,4,175,12,ES_AUTOHSCROLL | ES_WANTRETURN | NOT WS_BORDER,WS_EX_STATICEDGE + PUSHBUTTON "<",IDC_INCFINDPREVOK,223,3,16,14 + DEFPUSHBUTTON ">",IDC_INCFINDNXTOK,243,3,16,14 + CONTROL "Highlight all", IDC_INCFINDHILITEALL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,270,5,65,12 + CONTROL "Match case", IDC_INCFINDMATCHCASE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,335,5,60,12 +END + +IDD_FINDRESULT DIALOGEX 26, 41, 223, 67 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU +EXSTYLE WS_EX_TOOLWINDOW | WS_EX_WINDOWEDGE +CAPTION "Find result" +FONT 8, TEXT("MS Shell Dlg"), 0, 0, 0x0 +BEGIN +DEFPUSHBUTTON ">",IDC_INCFINDNXTOK,243,0,16,14, NOT WS_VISIBLE +END + +#endif //FIND_REPLACE_DLG_RC diff --git a/PowerEditor/src/ScitillaComponent/FindReplaceDlg_rc.h b/PowerEditor/src/ScitillaComponent/FindReplaceDlg_rc.h new file mode 100644 index 00000000..6c93f6a9 --- /dev/null +++ b/PowerEditor/src/ScitillaComponent/FindReplaceDlg_rc.h @@ -0,0 +1,74 @@ + + +#define IDD_FIND_REPLACE_DLG 1600 +#define IDFINDWHAT 1601 +#define IDREPLACEWITH 1602 +#define IDWHOLEWORD 1603 +#define IDMATCHCASE 1604 + +#define IDC_MODE_STATIC 1624 +#define IDNORMAL 1625 +#define IDEXTENDED 1626 + +#define IDREGEXP 1605 + +#define IDWRAP 1606 +#define IDUNSLASH 1607 +#define IDREPLACE 1608 +#define IDREPLACEALL 1609 +#define IDREPLACEINSEL 1610 +#define ID_STATICTEXT_REPLACE 1611 +#define IDDIRECTIONUP 1612 +#define IDDIRECTIONDOWN 1613 +#define IDCCOUNTALL 1614 +#define IDCMARKALL 1615 +#define IDC_MARKLINE_CHECK 1616 +#define IDC_STYLEFOUND_CHECK 1617 +#define IDC_PURGE_CHECK 1618 +#define IDC_FINDALL_STATIC 1619 +#define IDFINDWHAT_STATIC 1620 +#define IDC_DIR_STATIC 1621 + +#define IDC_PERCENTAGE_SLIDER 1622 +#define IDC_TRANSPARENT_GRPBOX 1623 + +#define IDC_FIND_IN_STATIC 1628 +//#define IDC_CURRENT_FILE_RADIO 1629 +//#define IDC_OPENED_FILES_RADIO 1630 +//#define IDC_FILES_RADIO 1631 +#define IDC_IN_SELECTION_CHECK 1632 +#define IDC_CLEAR_ALL 1633 +#define IDC_REPLACEINSELECTION 1634 +#define IDC_REPLACE_OPENEDFILES 1635 +#define IDC_FINDALL_OPENEDFILES 1636 +//#define IDC_FINDINFILES 1637 +#define IDC_FINDINFILES_LAUNCH 1638 +#define IDC_GETCURRENTDOCTYPE 1639 +#define IDC_FINDALL_CURRENTFILE 1641 +//#define IDSWITCH 1640 + +#define IDD_FINDINFILES_DLG 1650 +#define IDD_FINDINFILES_BROWSE_BUTTON 1651 +#define IDD_FINDINFILES_FILTERS_COMBO 1652 +#define IDD_FINDINFILES_DIR_COMBO 1653 +#define IDD_FINDINFILES_FILTERS_STATIC 1654 +#define IDD_FINDINFILES_DIR_STATIC 1655 +#define IDD_FINDINFILES_FIND_BUTTON 1656 +#define IDD_FINDINFILES_GOBACK_BUTTON 1657 +#define IDD_FINDINFILES_RECURSIVE_CHECK 1658 +#define IDD_FINDINFILES_INHIDDENDIR_CHECK 1659 +#define IDD_FINDINFILES_REPLACEINFILES 1660 + +#define IDD_FINDRESULT 1670 + +#define IDD_INCREMENT_FIND 1680 +#define IDC_INCSTATIC 1681 +#define IDC_INCFINDTEXT 1682 +#define IDC_INCFINDPREVOK 1683 +#define IDC_INCFINDNXTOK 1684 +#define IDC_INCFINDMATCHCASE 1685 +#define IDC_INCFINDHILITEALL 1686 + +#define IDC_TRANSPARENT_CHECK 1686 +#define IDC_TRANSPARENT_LOSSFOCUS_RADIO 1687 +#define IDC_TRANSPARENT_ALWAYS_RADIO 1688 diff --git a/PowerEditor/src/ScitillaComponent/FunctionCallTip.cpp b/PowerEditor/src/ScitillaComponent/FunctionCallTip.cpp new file mode 100644 index 00000000..9f6c4aee --- /dev/null +++ b/PowerEditor/src/ScitillaComponent/FunctionCallTip.cpp @@ -0,0 +1,416 @@ +//this file is part of Notepad++ +//Copyright (C)2008 Harry Bruin +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#include "FunctionCallTip.h" + + +struct Token { + TCHAR * token; + int length; + bool isIdentifier; + Token(TCHAR * tok, int len, bool isID) : token(tok), length(len), isIdentifier(isID) {}; +}; + +struct FunctionValues { + int lastIdentifier; + int lastFunctionIdentifier; + int param; + int scopeLevel; + FunctionValues() : lastIdentifier(-1), lastFunctionIdentifier(-1), param(0), scopeLevel(-1) {}; +}; + +inline bool lower(TCHAR c) { + return (c >= 'a' && c <= 'z'); +} + +inline bool match(TCHAR c1, TCHAR c2) { + if (c1 == c2) return true; + if (lower(c1)) + return ((c1-32) == c2); + if (lower(c2)) + return ((c2-32) == c1); + return false; +} + +//test string case insensitive ala Scintilla +//0 if equal, <0 of before, >0 if after (name1 that is) +int testNameNoCase(const TCHAR * name1, const TCHAR * name2, int len = -1) { + if (len == -1) { + len = 1024; //magic value, but it probably fails way before it reaches this + } + int i = 0; + while(match(name1[i], name2[i])) { + if (name1[i] == 0 || i == len) { + return 0; //equal + } + i++; + } + + int subs1 = lower(name1[i])?32:0; + int subs2 = lower(name2[i])?32:0; + + return ( (name1[i]-subs1) - (name2[i]-subs2) ); +} + +void FunctionCallTip::setLanguageXML(TiXmlElement * pXmlKeyword) { + if (isVisible()) + close(); + _pXmlKeyword = pXmlKeyword; +} + +bool FunctionCallTip::updateCalltip(int ch, bool needShown) { + if (!needShown && ch != _start && !isVisible()) //must be already visible + return false; + + _curPos = _pEditView->execute(SCI_GETCURRENTPOS); + + //recalculate everything + if (!getCursorFunction()) { //cannot display calltip (anymore) + close(); + return false; + } + showCalltip(); + return true; +} + +void FunctionCallTip::showNextOverload() { + if (!isVisible()) + return; + _currentOverload = (_currentOverload+1) % _currentNrOverloads; + showCalltip(); +} + +void FunctionCallTip::showPrevOverload() { + if (!isVisible()) + return; + _currentOverload = _currentOverload > 0?(_currentOverload-1) : _currentNrOverloads-1; + showCalltip(); +} + +void FunctionCallTip::close() { + if (!isVisible()) { + return; + } + + _pEditView->execute(SCI_CALLTIPCANCEL); + _currentOverload = 0; +} + +bool FunctionCallTip::getCursorFunction() { + int line = _pEditView->execute(SCI_LINEFROMPOSITION, _curPos); + int startpos = _pEditView->execute(SCI_POSITIONFROMLINE, line); + int endpos = _pEditView->execute(SCI_GETLINEENDPOSITION, line); + int len = endpos - startpos + 3; //also take CRLF in account, even if not there + int offset = _curPos - startpos; //offset is cursor location, only stuff before cursor has influence + const int maxLen = 128; + + if ((offset < 2) || (len >= maxLen)) + { + reset(); + return false; //cannot be a func, need name and separator + } + + TCHAR lineData[maxLen] = TEXT(""); + + _pEditView->getLine(line, lineData, len); + + //line aquired, find the functionname + //first split line into tokens to parse + //token is identifier or some expression, whitespace is ignored + std::vector< Token > tokenVector; + int tokenLen = 0; + TCHAR ch; + for (int i = 0; i < offset; i++) { //we dont care about stuff after the offset + //tokenVector.push_back(pair(lineData+i, len)); + ch = lineData[i]; + if (ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z' || ch >= '0' && ch <= '9' || ch == '_') { //part of identifier + tokenLen = 0; + TCHAR * begin = lineData+i; + while ( (ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z' || ch >= '0' && ch <= '9' || ch == '_') && i < offset) { + tokenLen++; + i++; + ch = lineData[i]; + } + tokenVector.push_back(Token(begin, tokenLen, true)); + i--; //correct overshooting of while loop + } else { + if (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r') { //whitespace + //do nothing + } else { + tokenLen = 1; + tokenVector.push_back(Token(lineData+i, tokenLen, false)); + } + } + } + + size_t vsize = tokenVector.size(); + //mind nested funcs, like |blblb a (x, b(), c);| + //therefore, use stack + std::vector valueVec; + + FunctionValues curValue, newValue; + int scopeLevel = 0; + for (size_t i = 0; i < vsize; i++) { + Token & curToken = tokenVector.at(i); + if (curToken.isIdentifier) { + curValue.lastIdentifier = i; + } else { + if (curToken.token[0] == _start) { + scopeLevel++; + newValue = curValue; + valueVec.push_back(newValue); //store the current settings, so when this new function doesnt happen to be the 'real' one, we can restore everything + + curValue.scopeLevel = scopeLevel; + if (i > 0 && curValue.lastIdentifier == i-1) { //identifier must be right before (, else we have some expression like "( x + y() )" + curValue.lastFunctionIdentifier = curValue.lastIdentifier; + curValue.param = 0; + } else { //some expression + curValue.lastFunctionIdentifier = -1; + } + } else if (curToken.token[0] == _param && curValue.lastFunctionIdentifier > -1) { + curValue.param++; + } else if (curToken.token[0] == _stop) { + if (scopeLevel) //scope cannot go below -1 + scopeLevel--; + if (valueVec.size() > 0) { //only pop level if scope was of actual function + curValue = valueVec.back(); + valueVec.pop_back(); + } else { + //invalidate curValue + curValue = FunctionValues(); + } + } else if (curToken.token[0] == _terminal) { + //invalidate everything + valueVec.clear(); + curValue = FunctionValues(); + } + } + } + + bool res = false; + + if (curValue.lastFunctionIdentifier == -1) { //not in direct function. Start popping the stack untill we empty it, or a func IS found + while(curValue.lastFunctionIdentifier == -1 && valueVec.size() > 0) { + curValue = valueVec.back(); + valueVec.pop_back(); + } + } + if (curValue.lastFunctionIdentifier > -1) { + Token funcToken = tokenVector.at(curValue.lastFunctionIdentifier); + funcToken.token[funcToken.length] = 0; + _currentParam = curValue.param; + + bool same = false; + if (_funcName) { + if(_ignoreCase) + same = testNameNoCase(_funcName, funcToken.token, lstrlen(_funcName)) == 0; + else + same = generic_strncmp(_funcName, funcToken.token, lstrlen(_funcName)) == 0; + } + if (!same) { //check if we need to reload data + if (_funcName) { + delete [] _funcName; + } + _funcName = new TCHAR[funcToken.length+1]; + lstrcpy(_funcName, funcToken.token); + res = loadFunction(); + } else { + res = true; + } + } + return res; +} + +/* +Find function in XML structure and parse it +*/ +bool FunctionCallTip::loadFunction() { + reset(); //set everything back to 0 + //The functions should be ordered, but linear search because we cant access like array + _curFunction = NULL; + //Iterate through all keywords and find the correct function keyword + TiXmlElement *funcNode = _pXmlKeyword; + const TCHAR * name = NULL; + for (; funcNode; funcNode = funcNode->NextSiblingElement(TEXT("KeyWord")) ) { + name = funcNode->Attribute(TEXT("name")); + if (!name) //malformed node + continue; + int compVal = 0; + if (_ignoreCase) + compVal = testNameNoCase(name, _funcName); //lstrcmpi doesnt work in this case + else + compVal = lstrcmp(name, _funcName); + if (!compVal) { //found it? + const TCHAR * val = funcNode->Attribute(TEXT("func")); + if (val) + { + if (!lstrcmp(val, TEXT("yes"))) { + //what we've been looking for + _curFunction = funcNode; + break; + } else { + //name matches, but not a function, abort the entire procedure + return false; + } + } + } else if (compVal > 0) { //too far, abort + return false; + } + } + + //Nothing found + if (!_curFunction) + return false; + + stringVec paramVec; + + TiXmlElement *overloadNode = _curFunction->FirstChildElement(TEXT("Overload")); + TiXmlElement *paramNode = NULL; + for (; overloadNode ; overloadNode = overloadNode->NextSiblingElement(TEXT("Overload")) ) { + const TCHAR * retVal = overloadNode->Attribute(TEXT("retVal")); + if (!retVal) + continue; //malformed node + _retVals.push_back(retVal); + + const TCHAR * description = overloadNode->Attribute(TEXT("descr")); + if (description) + _descriptions.push_back(description); + else + _descriptions.push_back(TEXT("")); //"no description available" + + paramNode = overloadNode->FirstChildElement(TEXT("Param")); + for (; paramNode ; paramNode = paramNode->NextSiblingElement(TEXT("Param")) ) { + const TCHAR * param = paramNode->Attribute(TEXT("name")); + if (!param) + continue; //malformed node + paramVec.push_back(param); + } + _overloads.push_back(paramVec); + paramVec.clear(); + + _currentNrOverloads++; + } + + _currentNrOverloads = (int)_overloads.size(); + + if (_currentNrOverloads == 0) //malformed node + return false; + + return true; +} + +void FunctionCallTip::showCalltip() { + if (_currentNrOverloads == 0) { + //ASSERT + return; + } + + //Check if the current overload still holds. If the current param exceeds amounti n overload, see if another one fits better (enough params) + stringVec & params = _overloads.at(_currentOverload); + size_t psize = params.size()+1, osize; + if ((size_t)_currentParam >= psize) { + osize = _overloads.size(); + for(size_t i = 0; i < osize; i++) { + psize = _overloads.at(i).size()+1; + if ((size_t)_currentParam < psize) { + _currentOverload = i; + break; + } + } + } + const TCHAR * curRetValText = _retVals.at(_currentOverload); + const TCHAR * curDescriptionText = _descriptions.at(_currentOverload); + bool hasDescr = true; + if (!curDescriptionText[0]) + hasDescr = false; + + int bytesNeeded = lstrlen(curRetValText) + lstrlen(_funcName) + 5;//'retval funcName (params)\0' + if (hasDescr) + bytesNeeded += lstrlen(curDescriptionText); + + size_t nrParams = params.size(); + for(size_t i = 0; i < nrParams; i++) { + bytesNeeded += lstrlen(params.at(i)) + 2; //'param, ' + } + + if (_currentNrOverloads > 1) { + bytesNeeded += 24; // /\00001 of 00003\/ + } + + const int maxLen = 512; + if (bytesNeeded >= maxLen) + return; + + TCHAR textBuffer[maxLen]; + textBuffer[0] = 0; + + if (_currentNrOverloads > 1) { + wsprintf(textBuffer, TEXT("\001%u of %u\002"), _currentOverload+1, _currentNrOverloads); + } + + lstrcat(textBuffer, curRetValText); + lstrcat(textBuffer, TEXT(" ")); + lstrcat(textBuffer, _funcName); + lstrcat(textBuffer, TEXT(" (")); + + int highlightstart = 0; + int highlightend = 0; + for(size_t i = 0; i < nrParams; i++) { + if (i == _currentParam) { + highlightstart = lstrlen(textBuffer); + highlightend = highlightstart + lstrlen(params.at(i)); + } + lstrcat(textBuffer, params.at(i)); + if (i < nrParams-1) + lstrcat(textBuffer, TEXT(", ")); + } + + lstrcat(textBuffer, TEXT(")")); + if (hasDescr) { + lstrcat(textBuffer, TEXT("\n")); + lstrcat(textBuffer, curDescriptionText); + } + + if (isVisible()) + _pEditView->execute(SCI_CALLTIPCANCEL); + else + _startPos = _curPos; + _pEditView->showCallTip(_startPos, textBuffer); + + if (highlightstart != highlightend) { + _pEditView->execute(SCI_CALLTIPSETHLT, highlightstart, highlightend); + } +} + +void FunctionCallTip::reset() { + _currentOverload = 0; + _currentParam = 0; + //_curPos = 0; + _startPos = 0; + _overloads.clear(); + _currentNrOverloads = 0; + _retVals.clear(); + _descriptions.clear(); +} + +void FunctionCallTip::cleanup() { + reset(); + if (_funcName) + delete [] _funcName; + _funcName = 0; + _pEditView = NULL; +} diff --git a/PowerEditor/src/ScitillaComponent/FunctionCallTip.h b/PowerEditor/src/ScitillaComponent/FunctionCallTip.h new file mode 100644 index 00000000..96ace095 --- /dev/null +++ b/PowerEditor/src/ScitillaComponent/FunctionCallTip.h @@ -0,0 +1,71 @@ +//this file is part of Notepad++ +//Copyright (C)2008 Harry Bruin +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef FUNCTIONCALLTIP_H +#define FUNCTIONCALLTIP_H + +#include "ScintillaEditView.h" + +typedef std::vector stringVec; + +class FunctionCallTip { + friend class AutoCompletion; +public: + FunctionCallTip(ScintillaEditView * pEditView) : _pEditView(pEditView), _pXmlKeyword(NULL), _curPos(0), _startPos(0), + _curFunction(NULL), _currentNrOverloads(0), _currentOverload(0), + _currentParam(0), _funcName(NULL), + _start('('), _stop(')'), _param(','), _terminal(';'), _ignoreCase(true) + {}; + ~FunctionCallTip() {/* cleanup(); */}; + void setLanguageXML(TiXmlElement * pXmlKeyword); //set calltip keyword node + bool updateCalltip(int ch, bool needShown = false); //Ch is character typed, or 0 if another event occured. NeedShown is true if calltip should be attempted to displayed. Return true if calltip was made visible + void showNextOverload(); //show next overlaoded parameters + void showPrevOverload(); //show prev overlaoded parameters + bool isVisible() { return _pEditView?_pEditView->execute(SCI_CALLTIPACTIVE) == TRUE:false; }; //true if calltip visible + void close(); //Close calltip if visible + +private: + ScintillaEditView * _pEditView; //Scintilla to display calltip in + TiXmlElement * _pXmlKeyword; //current keyword node (first one) + + int _curPos; //cursor position + int _startPos; //display start position + + TiXmlElement * _curFunction; //current function element + //cache some XML values n stuff + TCHAR * _funcName; //name of function + stringVec _retVals; //vector of overload return values/types + vector _overloads; //vector of overload params (=vector) + stringVec _descriptions; //vecotr of function descriptions + int _currentNrOverloads; //current amount of overloads + int _currentOverload; //current chosen overload + int _currentParam; //current highlighted param + + TCHAR _start; + TCHAR _stop; + TCHAR _param; + TCHAR _terminal; + bool _ignoreCase; + + bool getCursorFunction(); //retrieve data about function at cursor. Returns true if a function was found. Calls loaddata if needed + bool loadFunction(); //returns true if the function can be found + void showCalltip(); //display calltip based on current variables + void reset(); //reset all vars in case function is invalidated + void cleanup(); //delete any leftovers +}; + +#endif// FUNCTIONCALLTIP_H diff --git a/PowerEditor/src/ScitillaComponent/GoToLineDlg.cpp b/PowerEditor/src/ScitillaComponent/GoToLineDlg.cpp new file mode 100644 index 00000000..9d35027e --- /dev/null +++ b/PowerEditor/src/ScitillaComponent/GoToLineDlg.cpp @@ -0,0 +1,104 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#include "GoToLineDlg.h" + + +BOOL CALLBACK GoToLineDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) +{ + switch (message) + { + case WM_INITDIALOG : + { + ::SendDlgItemMessage(_hSelf, IDC_RADIO_GOTOLINE, BM_SETCHECK, TRUE, 0); + goToCenter(); + return TRUE; + } + case WM_COMMAND : + { + switch (wParam) + { + case IDCANCEL : // Close + display(false); + cleanLineEdit(); + return TRUE; + + case IDOK : + { + int line = getLine(); + if (line != -1) + { + display(false); + cleanLineEdit(); + if (_mode == go2line) { + (*_ppEditView)->execute(SCI_ENSUREVISIBLE, line-1); + (*_ppEditView)->execute(SCI_GOTOLINE, line-1); + } else { + int sci_line = (*_ppEditView)->execute(SCI_LINEFROMPOSITION, line); + (*_ppEditView)->execute(SCI_ENSUREVISIBLE, sci_line); + (*_ppEditView)->execute(SCI_GOTOPOS, line); + } + } + (*_ppEditView)->getFocus(); + return TRUE; + } + + case IDC_RADIO_GOTOLINE : + case IDC_RADIO_GOTOOFFSET : + { + + bool isLine, isOffset; + if (wParam == IDC_RADIO_GOTOLINE) + { + isLine = true; + isOffset = false; + _mode = go2line; + } + else + { + isLine = false; + isOffset = true; + _mode = go2offsset; + } + ::SendDlgItemMessage(_hSelf, IDC_RADIO_GOTOLINE, BM_SETCHECK, isLine, 0); + ::SendDlgItemMessage(_hSelf, IDC_RADIO_GOTOOFFSET, BM_SETCHECK, isOffset, 0); + updateLinesNumbers(); + return TRUE; + } + default : + { + switch (HIWORD(wParam)) + { + case EN_SETFOCUS : + case BN_SETFOCUS : + updateLinesNumbers(); + return TRUE; + default : + return TRUE; + } + break; + } + } + } + + default : + return FALSE; + } + return FALSE; +} + + diff --git a/PowerEditor/src/ScitillaComponent/GoToLineDlg.h b/PowerEditor/src/ScitillaComponent/GoToLineDlg.h new file mode 100644 index 00000000..5de43885 --- /dev/null +++ b/PowerEditor/src/ScitillaComponent/GoToLineDlg.h @@ -0,0 +1,93 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef GOTILINE_DLG_H +#define GOTILINE_DLG_H + +#include "StaticDialog.h" +#include "..\resource.h" + +#include "ScintillaEditView.h" + +class GoToLineDlg : public StaticDialog +{ +public : + GoToLineDlg() : StaticDialog(), _mode(go2line) {}; + + void init(HINSTANCE hInst, HWND hPere, ScintillaEditView **ppEditView) { + Window::init(hInst, hPere); + if (!ppEditView) + throw int(9900); + _ppEditView = ppEditView; + }; + + virtual void create(int dialogID, bool isRTL = false) { + StaticDialog::create(dialogID, isRTL); + }; + + void doDialog(bool isRTL = false) { + if (!isCreated()) + create(IDD_GOLINE, isRTL); + display(); + }; + + virtual void display(bool toShow = true) const { + Window::display(toShow); + if (toShow) + ::SetFocus(::GetDlgItem(_hSelf, ID_GOLINE_EDIT)); + }; + +protected : + enum mode {go2line, go2offsset}; + mode _mode; + virtual BOOL CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam); + +private : + + ScintillaEditView **_ppEditView; + + void updateLinesNumbers() const { + unsigned int current = 0; + unsigned int limit = 0; + + if (_mode == go2line) + { + current = (unsigned int)((*_ppEditView)->getCurrentLineNumber() + 1); + limit = (unsigned int)((*_ppEditView)->execute(SCI_GETLINECOUNT)); + } + else + { + current = (unsigned int)(*_ppEditView)->execute(SCI_GETCURRENTPOS); + limit = (unsigned int)((*_ppEditView)->getCurrentDocLen() - 1); + } + ::SetDlgItemInt(_hSelf, ID_CURRLINE, current, FALSE); + ::SetDlgItemInt(_hSelf, ID_LASTLINE, limit, FALSE); + }; + + void cleanLineEdit() const { + ::SetDlgItemText(_hSelf, ID_GOLINE_EDIT, TEXT("")); + }; + + int getLine() const { + BOOL isSuccessful; + int line = ::GetDlgItemInt(_hSelf, ID_GOLINE_EDIT, &isSuccessful, FALSE); + return (isSuccessful?line:-1); + }; + +}; + +#endif //GOTILINE_DLG_H diff --git a/PowerEditor/src/ScitillaComponent/Printer.cpp b/PowerEditor/src/ScitillaComponent/Printer.cpp new file mode 100644 index 00000000..59e6c157 --- /dev/null +++ b/PowerEditor/src/ScitillaComponent/Printer.cpp @@ -0,0 +1,502 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#include "Printer.h" + +void replaceStr(generic_string & str, generic_string str2BeReplaced, generic_string replacement) +{ + size_t pos = str.find(str2BeReplaced); + + if (pos != str.npos) + str.replace(pos, str2BeReplaced.length(), replacement); +} + +void Printer::init(HINSTANCE hInst, HWND hwnd, ScintillaEditView *pSEView, bool showDialog, int startPos, int endPos) +{ + _pSEView = pSEView; + _startPos = startPos; + _endPos = endPos; + _pdlg.lStructSize = sizeof(PRINTDLG); + _pdlg.hwndOwner = hwnd; + _pdlg.hInstance = hInst; + _pdlg.Flags = PD_USEDEVMODECOPIES | PD_ALLPAGES | PD_RETURNDC; + _pdlg.nFromPage = 1; + _pdlg.nToPage = 1; + _pdlg.nMinPage = 1; + _pdlg.nMaxPage = 0xffffU; // We do not know how many pages in the + // document until the printer is selected and the paper size is known. + _pdlg.nCopies = 1; + _pdlg.hDC = 0; + _pdlg.hDevMode = NULL; + _pdlg.hDevNames = NULL; + _pdlg.lCustData = 0; + _pdlg.lpfnPrintHook = NULL; + _pdlg.lpfnSetupHook = NULL; + _pdlg.lpPrintTemplateName = NULL; + _pdlg.lpSetupTemplateName = NULL; + _pdlg.hPrintTemplate = NULL; + _pdlg.hSetupTemplate = NULL; + + // See if a range has been selected + _pdlg.Flags |= (_startPos != _endPos)?PD_SELECTION:PD_NOSELECTION; + + if (!showDialog) + { + // Don't display dialog box, just use the default printer and options + _pdlg.Flags |= PD_RETURNDEFAULT; + } +} + + + +size_t Printer::doPrint(bool justDoIt) +{/* + if (!::PrintDlg(&_pdlg)) + return 0; +*/ + + const NppGUI & nppGUI = (NppParameters::getInstance())->getNppGUI(); + + POINT ptPage; + POINT ptDpi; + + RECT rectMargins; + RECT rectPhysMargins; + RECT userMargins; + + // Get printer resolution + ptDpi.x = GetDeviceCaps(_pdlg.hDC, LOGPIXELSX); // dpi in X direction + ptDpi.y = GetDeviceCaps(_pdlg.hDC, LOGPIXELSY); // dpi in Y direction + + // Start by getting the physical page size (in device units). + ptPage.x = GetDeviceCaps(_pdlg.hDC, PHYSICALWIDTH); // device units + ptPage.y = GetDeviceCaps(_pdlg.hDC, PHYSICALHEIGHT); // device units + + // Get the dimensions of the unprintable + // part of the page (in device units). + rectPhysMargins.left = GetDeviceCaps(_pdlg.hDC, PHYSICALOFFSETX); + rectPhysMargins.top = GetDeviceCaps(_pdlg.hDC, PHYSICALOFFSETY); + + // To get the right and lower unprintable area, + // we take the entire width and height of the paper and + // subtract everything else. + rectPhysMargins.right = ptPage.x // total paper width + - GetDeviceCaps(_pdlg.hDC, HORZRES) // printable width + - rectPhysMargins.left; // left unprintable margin + + rectPhysMargins.bottom = ptPage.y // total paper height + - GetDeviceCaps(_pdlg.hDC, VERTRES) // printable height + - rectPhysMargins.top; // right unprintable margin + if (nppGUI._printSettings.isUserMargePresent()) + { + userMargins.left = MulDiv(nppGUI._printSettings._marge.left*100, ptDpi.x, 2540); + userMargins.top = MulDiv(nppGUI._printSettings._marge.top*100, ptDpi.y, 2540); + userMargins.right = MulDiv(nppGUI._printSettings._marge.right*100, ptDpi.x, 2540); + userMargins.bottom = MulDiv(nppGUI._printSettings._marge.bottom*100, ptDpi.y, 2540); + + rectMargins.left = max(rectPhysMargins.left, userMargins.left); + rectMargins.top = max(rectPhysMargins.top, userMargins.top); + rectMargins.right = max(rectPhysMargins.right, userMargins.right); + rectMargins.bottom = max(rectPhysMargins.bottom, userMargins.bottom); + } + else + { + rectMargins.left = rectPhysMargins.left; + rectMargins.top = rectPhysMargins.top; + rectMargins.right = rectPhysMargins.right; + rectMargins.bottom = rectPhysMargins.bottom; + } + // Convert device coordinates into logical coordinates + DPtoLP(_pdlg.hDC, (LPPOINT)&rectMargins, 2); + DPtoLP(_pdlg.hDC, (LPPOINT)&rectPhysMargins, 2); + + // Convert page size to logical units and we're done! + DPtoLP(_pdlg.hDC, &ptPage, 1); + + TEXTMETRIC tm; + + int fontSize = nppGUI._printSettings._headerFontSize?nppGUI._printSettings._headerFontSize:9; + int fontWeight = nppGUI._printSettings._headerFontStyle & FONTSTYLE_BOLD?FW_BOLD:FW_NORMAL; + int isFontItalic = nppGUI._printSettings._headerFontStyle & FONTSTYLE_ITALIC?TRUE:FALSE; + const TCHAR *fontFace = (nppGUI._printSettings._headerFontName != TEXT(""))?nppGUI._printSettings._headerFontName.c_str():TEXT("Arial"); + + int headerLineHeight = ::MulDiv(fontSize, ptDpi.y, 72); + //TCHAR toto[10]; + //::MessageBox(NULL, itoa(nppGUI._printSettings._headerFontStyle, toto, 10), TEXT("header"), MB_OK); + + HFONT fontHeader = ::CreateFont(headerLineHeight, + 0, 0, 0, + fontWeight, + isFontItalic, + FALSE, + 0, 0, 0, + 0, 0, 0, + fontFace); + + ::SelectObject(_pdlg.hDC, fontHeader); + ::GetTextMetrics(_pdlg.hDC, &tm); + headerLineHeight = tm.tmHeight + tm.tmExternalLeading; + + fontSize = nppGUI._printSettings._footerFontSize?nppGUI._printSettings._footerFontSize:9; + fontWeight = nppGUI._printSettings._footerFontStyle & FONTSTYLE_BOLD?FW_BOLD:FW_NORMAL; + isFontItalic = nppGUI._printSettings._footerFontStyle & FONTSTYLE_ITALIC?TRUE:FALSE; + fontFace = (nppGUI._printSettings._footerFontName != TEXT(""))?nppGUI._printSettings._footerFontName.c_str():TEXT("Arial"); + //::MessageBox(NULL, itoa(nppGUI._printSettings._footerFontStyle, , 10), TEXT("footer"), MB_OK); + + int footerLineHeight = ::MulDiv(fontSize, ptDpi.y, 72); + HFONT fontFooter = ::CreateFont(footerLineHeight, + 0, 0, 0, + fontWeight, + isFontItalic, + FALSE, + 0, 0, 0, + 0, 0, 0, + fontFace); + + ::SelectObject(_pdlg.hDC, fontFooter); + ::GetTextMetrics(_pdlg.hDC, &tm); + footerLineHeight = tm.tmHeight + tm.tmExternalLeading; + + + ::GetTextMetrics(_pdlg.hDC, &tm); + int printMarge = tm.tmHeight + tm.tmExternalLeading; + printMarge = printMarge + printMarge / 2; + + DOCINFO docInfo; + docInfo.cbSize = sizeof(DOCINFO); + docInfo.lpszDocName = _pSEView->getCurrentBuffer()->getFullPathName(); + docInfo.lpszOutput = NULL; + + if (::StartDoc(_pdlg.hDC, &docInfo) < 0) + { + MessageBox(NULL, TEXT("Can not start printer document."), 0, MB_OK); + return 0; + } + + // By default, we will print all the document + long lengthPrinted = 0; + long lengthDoc = _pSEView->getCurrentDocLen(); + long lengthDocMax = lengthDoc; + + // In the case that the print dialog was launched and that there's a range of selection + // We print the range of selection + if ((!(_pdlg.Flags & PD_RETURNDEFAULT)) && (_pdlg.Flags & PD_SELECTION)) + { + if (_startPos > _endPos) + { + lengthPrinted = _endPos; + lengthDoc = _startPos; + } + else + { + lengthPrinted = _startPos; + lengthDoc = _endPos; + } + + if (lengthPrinted < 0) + lengthPrinted = 0; + if (lengthDoc > lengthDocMax) + lengthDoc = lengthDocMax; + } + + RangeToFormat frPrint; + frPrint.hdc = _pdlg.hDC; + frPrint.hdcTarget = _pdlg.hDC; + frPrint.rc.left = rectMargins.left - rectPhysMargins.left; + frPrint.rc.top = rectMargins.top - rectPhysMargins.top; + frPrint.rc.right = ptPage.x - rectMargins.right - rectPhysMargins.left; + frPrint.rc.bottom = ptPage.y - rectMargins.bottom - rectPhysMargins.top; + frPrint.rcPage.left = 0; + frPrint.rcPage.top = 0; + frPrint.rcPage.right = ptPage.x - rectPhysMargins.left - rectPhysMargins.right - 1; + frPrint.rcPage.bottom = ptPage.y - rectPhysMargins.top - rectPhysMargins.bottom - 1; + + frPrint.rc.top += printMarge; + frPrint.rc.bottom -= printMarge; + frPrint.rc.left += printMarge; + frPrint.rc.right -= printMarge; + + const int headerSize = 256; + TCHAR headerL[headerSize] = TEXT(""); + TCHAR headerM[headerSize] = TEXT(""); + TCHAR headerR[headerSize] = TEXT(""); + TCHAR footerL[headerSize] = TEXT(""); + TCHAR footerM[headerSize] = TEXT(""); + TCHAR footerR[headerSize] = TEXT(""); + + + const TCHAR shortDateVar[] = TEXT("$(SHORT_DATE)"); + const TCHAR longDateVar[] = TEXT("$(LONG_DATE)"); + const TCHAR timeVar[] = TEXT("$(TIME)"); + + const int bufferSize = 64; + TCHAR shortDate[bufferSize]; + TCHAR longDate[bufferSize]; + TCHAR time[bufferSize]; + + SYSTEMTIME st; + ::GetLocalTime(&st); + ::GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &st, NULL, shortDate, bufferSize); + ::GetDateFormat(LOCALE_USER_DEFAULT, DATE_LONGDATE, &st, NULL, longDate, bufferSize); + ::GetTimeFormat(LOCALE_USER_DEFAULT, TIME_NOSECONDS, &st, NULL, time, bufferSize); + + if (nppGUI._printSettings.isHeaderPresent()) + { + frPrint.rc.top += headerLineHeight + headerLineHeight / 2; + + generic_string headerLeftPart = nppGUI._printSettings._headerLeft; + if (headerLeftPart != TEXT("")) + { + replaceStr(headerLeftPart, shortDateVar, shortDate); + replaceStr(headerLeftPart, longDateVar, longDate); + replaceStr(headerLeftPart, timeVar, time); + expandNppEnvironmentStrs(headerLeftPart.c_str(), headerL, headerSize, _pdlg.hwndOwner); + } + + generic_string headerMiddlePart = nppGUI._printSettings._headerMiddle; + if (headerMiddlePart != TEXT("")) + { + replaceStr(headerMiddlePart, shortDateVar, shortDate); + replaceStr(headerMiddlePart, longDateVar, longDate); + replaceStr(headerMiddlePart, timeVar, time); + expandNppEnvironmentStrs(headerMiddlePart.c_str(), headerM, headerSize, _pdlg.hwndOwner); + } + + generic_string headerRightPart = nppGUI._printSettings._headerRight; + if (headerRightPart != TEXT("")) + { + replaceStr(headerRightPart, shortDateVar, shortDate); + replaceStr(headerRightPart, longDateVar, longDate); + replaceStr(headerRightPart, timeVar, time); + expandNppEnvironmentStrs(headerRightPart.c_str(), headerR, headerSize, _pdlg.hwndOwner); + } + + } + + if (nppGUI._printSettings.isFooterPresent()) + { + frPrint.rc.bottom -= footerLineHeight + footerLineHeight / 2; + + generic_string footerLeftPart = nppGUI._printSettings._footerLeft; + if (footerLeftPart != TEXT("")) + { + replaceStr(footerLeftPart, shortDateVar, shortDate); + replaceStr(footerLeftPart, longDateVar, longDate); + replaceStr(footerLeftPart, timeVar, time); + expandNppEnvironmentStrs(footerLeftPart.c_str(), footerL, headerSize, _pdlg.hwndOwner); + } + + generic_string footerMiddlePart = nppGUI._printSettings._footerMiddle; + if (footerMiddlePart != TEXT("")) + { + replaceStr(footerMiddlePart, shortDateVar, shortDate); + replaceStr(footerMiddlePart, longDateVar, longDate); + replaceStr(footerMiddlePart, timeVar, time); + expandNppEnvironmentStrs(footerMiddlePart.c_str(), footerM, headerSize, _pdlg.hwndOwner); + } + + generic_string footerRightPart = nppGUI._printSettings._footerRight; + if (footerRightPart != TEXT("")) + { + replaceStr(footerRightPart, shortDateVar, shortDate); + replaceStr(footerRightPart, longDateVar, longDate); + replaceStr(footerRightPart, timeVar, time); + expandNppEnvironmentStrs(footerRightPart.c_str(), footerR, headerSize, _pdlg.hwndOwner); + } + } + + + bool isShown = _pSEView->hasMarginShowed(ScintillaEditView::_SC_MARGE_LINENUMBER); + if (!nppGUI._printSettings._printLineNumber) + _pSEView->showMargin(ScintillaEditView::_SC_MARGE_LINENUMBER, false); + + size_t pageNum = 1; + bool printPage; + const TCHAR pageVar[] = TEXT("$(CURRENT_PRINTING_PAGE)"); + + while (lengthPrinted < lengthDoc) + { + printPage = (!(_pdlg.Flags & PD_PAGENUMS) || + (pageNum >= _pdlg.nFromPage) && (pageNum <= _pdlg.nToPage)); + + if (!justDoIt) + printPage = false; + + TCHAR pageString[32]; + wsprintf(pageString, TEXT("%0d"), pageNum); + + if (printPage) + { + ::StartPage(_pdlg.hDC); + + if (nppGUI._printSettings.isHeaderPresent()) + { + ::SelectObject(_pdlg.hDC, fontHeader); + + ::SetTextColor(_pdlg.hDC, RGB(0, 0, 0)); + ::SetBkColor(_pdlg.hDC, RGB(255, 255, 255)); + + UINT oldTASettings = ::SetTextAlign(_pdlg.hDC, TA_BOTTOM); + RECT rcw = {frPrint.rc.left, frPrint.rc.top - headerLineHeight - headerLineHeight / 2, + frPrint.rc.right, frPrint.rc.top - headerLineHeight / 2}; + rcw.bottom = rcw.top + headerLineHeight; + + + SIZE size; + + // Left part + if (headerL[0] != '\0') + { + generic_string headerLeft(headerL); + size_t pos = headerLeft.find(pageVar); + + if (pos != headerLeft.npos) + headerLeft.replace(pos, lstrlen(pageVar), pageString); + + ::ExtTextOut(_pdlg.hDC, frPrint.rc.left + 5, frPrint.rc.top - headerLineHeight / 2, + ETO_OPAQUE, &rcw, headerLeft.c_str(), static_cast(headerLeft.length()), NULL); + } + + // Middle part + if (headerM != '\0') + { + generic_string headerMiddle(headerM); + size_t pos = headerMiddle.find(pageVar); + if (pos != headerMiddle.npos) + headerMiddle.replace(pos, lstrlen(pageVar), pageString); + + ::GetTextExtentPoint32(_pdlg.hDC, headerMiddle.c_str(), static_cast(headerMiddle.length()), &size); + ::ExtTextOut(_pdlg.hDC, ((frPrint.rc.right - frPrint.rc.left)/2 + frPrint.rc.left) - (size.cx/2), frPrint.rc.top - headerLineHeight / 2, + ETO_CLIPPED, &rcw, headerMiddle.c_str(), static_cast(headerMiddle.length()), NULL); + } + // Right part + if (headerR != '\0') + { + generic_string headerRight(headerR); + size_t pos = headerRight.find(pageVar); + if (pos != headerRight.npos) + headerRight.replace(pos, lstrlen(pageVar), pageString); + + ::GetTextExtentPoint32(_pdlg.hDC, headerRight.c_str(), static_cast(headerRight.length()), &size); + ::ExtTextOut(_pdlg.hDC, frPrint.rc.right - size.cx, frPrint.rc.top - headerLineHeight / 2, + ETO_CLIPPED, &rcw, headerRight.c_str(), static_cast(headerRight.length()), NULL); + } + + ::SetTextAlign(_pdlg.hDC, oldTASettings); + HPEN pen = ::CreatePen(0, 1, 0x00000000); + HPEN penOld = static_cast(::SelectObject(_pdlg.hDC, pen)); + ::MoveToEx(_pdlg.hDC, frPrint.rc.left, frPrint.rc.top - headerLineHeight / 4, NULL); + ::LineTo(_pdlg.hDC, frPrint.rc.right, frPrint.rc.top - headerLineHeight / 4); + ::SelectObject(_pdlg.hDC, penOld); + ::DeleteObject(pen); + } + } + + frPrint.chrg.cpMin = lengthPrinted; + frPrint.chrg.cpMax = lengthDoc; + _pSEView->execute(SCI_SETPRINTCOLOURMODE, nppGUI._printSettings._printOption); + lengthPrinted = long(_pSEView->execute(SCI_FORMATRANGE, printPage, reinterpret_cast(&frPrint))); + + if (printPage) + { + if (nppGUI._printSettings.isFooterPresent()) + { + ::SelectObject(_pdlg.hDC, fontFooter); + + ::SetTextColor(_pdlg.hDC, RGB(0, 0, 0)); + ::SetBkColor(_pdlg.hDC, RGB(255, 255, 255)); + + UINT oldta = ::SetTextAlign(_pdlg.hDC, TA_TOP); + RECT rcw = {frPrint.rc.left, frPrint.rc.bottom + footerLineHeight / 2, + frPrint.rc.right, frPrint.rc.bottom + footerLineHeight + footerLineHeight / 2}; + + SIZE size; + + // Left part + if (footerL[0] != '\0') + { + generic_string footerLeft(footerL); + size_t pos = footerLeft.find(pageVar); + if (pos != footerLeft.npos) + footerLeft.replace(pos, lstrlen(pageVar), pageString); + + ::ExtTextOut(_pdlg.hDC, frPrint.rc.left + 5, frPrint.rc.bottom + footerLineHeight / 2, + ETO_OPAQUE, &rcw, footerLeft.c_str(), static_cast(footerLeft.length()), NULL); + } + + // Middle part + if (footerM[0] != '\0') + { + generic_string footerMiddle(footerM); + size_t pos = footerMiddle.find(pageVar); + if (pos != footerMiddle.npos) + footerMiddle.replace(pos, lstrlen(pageVar), pageString); + + ::GetTextExtentPoint32(_pdlg.hDC, footerMiddle.c_str(), static_cast(footerMiddle.length()), &size); + ::ExtTextOut(_pdlg.hDC, ((frPrint.rc.right - frPrint.rc.left)/2 + frPrint.rc.left) - (size.cx/2), frPrint.rc.bottom + footerLineHeight / 2, + ETO_CLIPPED, &rcw, footerMiddle.c_str(), static_cast(footerMiddle.length()), NULL); + } + // Right part + if (footerR[0] != '\0') + { + generic_string footerRight(footerR); + size_t pos = footerRight.find(pageVar); + if (pos != footerRight.npos) + footerRight.replace(pos, lstrlen(pageVar), pageString); + ::GetTextExtentPoint32(_pdlg.hDC, footerRight.c_str(), static_cast(footerRight.length()), &size); + ::ExtTextOut(_pdlg.hDC, frPrint.rc.right - size.cx, frPrint.rc.bottom + footerLineHeight / 2, + ETO_CLIPPED, &rcw, footerRight.c_str(), static_cast(footerRight.length()), NULL); + } + + ::SetTextAlign(_pdlg.hDC, oldta); + HPEN pen = ::CreatePen(0, 1, 0x00000000); + HPEN penOld = static_cast(::SelectObject(_pdlg.hDC, pen)); + + ::MoveToEx(_pdlg.hDC, frPrint.rc.left, frPrint.rc.bottom + footerLineHeight / 4, NULL); + ::LineTo(_pdlg.hDC, frPrint.rc.right, frPrint.rc.bottom + footerLineHeight / 4); + ::SelectObject(_pdlg.hDC, penOld); + ::DeleteObject(pen); + } + + ::EndPage(_pdlg.hDC); + } + + pageNum++; + + if ((_pdlg.Flags & PD_PAGENUMS) && (pageNum > _pdlg.nToPage)) + break; + } + + //TCHAR toto[10]; + //::MessageBox(NULL, itoa(pageNum, toto, 10), TEXT("page total"), MB_OK); + if (!nppGUI._printSettings._printLineNumber) + _pSEView->showMargin(ScintillaEditView::_SC_MARGE_LINENUMBER, isShown); + + _pSEView->execute(SCI_FORMATRANGE, FALSE, 0); + ::EndDoc(_pdlg.hDC); + ::DeleteDC(_pdlg.hDC); + + if (fontHeader) + ::DeleteObject(fontHeader); + + if (fontFooter) + ::DeleteObject(fontFooter); + + return (pageNum - 1); +} + + diff --git a/PowerEditor/src/ScitillaComponent/Printer.h b/PowerEditor/src/ScitillaComponent/Printer.h new file mode 100644 index 00000000..461fedca --- /dev/null +++ b/PowerEditor/src/ScitillaComponent/Printer.h @@ -0,0 +1,55 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef PRINTER_H +#define PRINTER_H + +#include +#include "ScintillaEditView.h" +#include "RunDlg.h" +#include "Parameters.h" + +struct RangeToFormat { + HDC hdc; + HDC hdcTarget; + RECT rc; + RECT rcPage; + CharacterRange chrg; +}; + +class Printer +{ +public : + Printer(){}; + void init(HINSTANCE hInst, HWND hwnd, ScintillaEditView *pSEView, bool showDialog, int startPos, int endPos); + size_t Printer::doPrint() { + if (!::PrintDlg(&_pdlg)) + return 0; + + return doPrint(true); + }; + size_t doPrint(bool justDoIt); + +private : + PRINTDLG _pdlg; + ScintillaEditView *_pSEView; + size_t _startPos; + size_t _endPos; + size_t _nbPageTotal; +}; + +#endif //PRINTER_H diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp new file mode 100644 index 00000000..1df138ed --- /dev/null +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp @@ -0,0 +1,2486 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +#include +#include +#include "ScintillaEditView.h" +#include "Parameters.h" + + +// initialize the static variable +HINSTANCE ScintillaEditView::_hLib = ::LoadLibrary(TEXT("SciLexer.DLL")); +int ScintillaEditView::_refCount = 0; +UserDefineDialog ScintillaEditView::_userDefineDlg; + +const int ScintillaEditView::_SC_MARGE_LINENUMBER = 0; +const int ScintillaEditView::_SC_MARGE_SYBOLE = 1; +const int ScintillaEditView::_SC_MARGE_FOLDER = 2; +//const int ScintillaEditView::_SC_MARGE_MODIFMARKER = 3; + +WNDPROC ScintillaEditView::_scintillaDefaultProc = NULL; +/* +SC_MARKNUM_* | Arrow Plus/minus Circle tree Box tree +------------------------------------------------------------------------------------------------------------- +FOLDEROPEN | SC_MARK_ARROWDOWN SC_MARK_MINUS SC_MARK_CIRCLEMINUS SC_MARK_BOXMINUS +FOLDER | SC_MARK_ARROW SC_MARK_PLUS SC_MARK_CIRCLEPLUS SC_MARK_BOXPLUS +FOLDERSUB | SC_MARK_EMPTY SC_MARK_EMPTY SC_MARK_VLINE SC_MARK_VLINE +FOLDERTAIL | SC_MARK_EMPTY SC_MARK_EMPTY SC_MARK_LCORNERCURVE SC_MARK_LCORNER +FOLDEREND | SC_MARK_EMPTY SC_MARK_EMPTY SC_MARK_CIRCLEPLUSCONNECTED SC_MARK_BOXPLUSCONNECTED +FOLDEROPENMID | SC_MARK_EMPTY SC_MARK_EMPTY SC_MARK_CIRCLEMINUSCONNECTED SC_MARK_BOXMINUSCONNECTED +FOLDERMIDTAIL | SC_MARK_EMPTY SC_MARK_EMPTY SC_MARK_TCORNERCURVE SC_MARK_TCORNER +*/ + +const int ScintillaEditView::_markersArray[][NB_FOLDER_STATE] = { + {SC_MARKNUM_FOLDEROPEN, SC_MARKNUM_FOLDER, SC_MARKNUM_FOLDERSUB, SC_MARKNUM_FOLDERTAIL, SC_MARKNUM_FOLDEREND, SC_MARKNUM_FOLDEROPENMID, SC_MARKNUM_FOLDERMIDTAIL}, + {SC_MARK_MINUS, SC_MARK_PLUS, SC_MARK_EMPTY, SC_MARK_EMPTY, SC_MARK_EMPTY, SC_MARK_EMPTY, SC_MARK_EMPTY}, + {SC_MARK_ARROWDOWN, SC_MARK_ARROW, SC_MARK_EMPTY, SC_MARK_EMPTY, SC_MARK_EMPTY, SC_MARK_EMPTY, SC_MARK_EMPTY}, + {SC_MARK_CIRCLEMINUS, SC_MARK_CIRCLEPLUS,SC_MARK_VLINE, SC_MARK_LCORNERCURVE, SC_MARK_CIRCLEPLUSCONNECTED, SC_MARK_CIRCLEMINUSCONNECTED, SC_MARK_TCORNERCURVE}, + {SC_MARK_BOXMINUS, SC_MARK_BOXPLUS, SC_MARK_VLINE, SC_MARK_LCORNER, SC_MARK_BOXPLUSCONNECTED, SC_MARK_BOXMINUSCONNECTED, SC_MARK_TCORNER} +}; + +//Array with all the names of all languages +LanguageName ScintillaEditView::langNames[L_EXTERNAL+1] = { +{TEXT("normal"), TEXT("Normal text"), TEXT("Normal text file"), L_TXT, SCLEX_NULL}, +{TEXT("php"), TEXT("PHP"), TEXT("PHP Hypertext Preprocessor file"), L_PHP, SCLEX_HTML}, +{TEXT("c"), TEXT("C"), TEXT("C source file"), L_C, SCLEX_CPP}, +{TEXT("cpp"), TEXT("C++"), TEXT("C++ source file"), L_CPP, SCLEX_CPP}, +{TEXT("cs"), TEXT("C#"), TEXT("C# source file"), L_CS, }, +{TEXT("objc"), TEXT("Objective-C"), TEXT("Objective-C source file"), L_OBJC, }, +{TEXT("java"), TEXT("Java"), TEXT("Java source file"), L_JAVA, SCLEX_CPP}, +{TEXT("rc"), TEXT("RC"), TEXT("Windows Resource file"), L_RC, SCLEX_CPP}, +{TEXT("html"), TEXT("HTML"), TEXT("Hyper Text Markup Language file"), L_HTML, SCLEX_HTML}, +{TEXT("xml"), TEXT("XML"), TEXT("eXtensible Markup Language file"), L_XML, SCLEX_XML}, +{TEXT("makefile"), TEXT("Makefile"), TEXT("Makefile"), L_MAKEFILE, SCLEX_MAKEFILE}, +{TEXT("pascal"), TEXT("Pascal"), TEXT("Pascal source file"), L_PASCAL, SCLEX_PASCAL}, +{TEXT("batch"), TEXT("Batch"), TEXT("Batch file"), L_BATCH, SCLEX_BATCH}, +{TEXT("ini"), TEXT("ini"), TEXT("MS ini file"), L_INI, SCLEX_PROPERTIES}, +{TEXT("nfo"), TEXT("NFO"), TEXT("MSDOS Style/ASCII Art"), L_NFO, SCLEX_NULL}, +{TEXT("udf"), TEXT("udf"), TEXT("User Define File"), L_USER, SCLEX_USER}, +{TEXT("asp"), TEXT("ASP"), TEXT("Active Server Pages script file"), L_ASP, SCLEX_HTML}, +{TEXT("sql"), TEXT("SQL"), TEXT("Structured Query Language file"), L_SQL, SCLEX_SQL}, +{TEXT("vb"), TEXT("VB"), TEXT("Visual Basic file"), L_VB, SCLEX_VB}, +{TEXT("javascript"), TEXT("JavaScript"), TEXT("JavaScript file"), L_JS, SCLEX_CPP}, +{TEXT("css"), TEXT("CSS"), TEXT("Cascade Style Sheets File"), L_CSS, SCLEX_CSS}, +{TEXT("perl"), TEXT("Perl"), TEXT("Perl source file"), L_PERL, SCLEX_PERL}, +{TEXT("python"), TEXT("Python"), TEXT("Python file"), L_PYTHON, SCLEX_PYTHON}, +{TEXT("lua"), TEXT("Lua"), TEXT("Lua source File"), L_LUA, SCLEX_LUA}, +{TEXT("tex"), TEXT("TeX"), TEXT("TeX file"), L_TEX, SCLEX_TEX}, +{TEXT("fortran"), TEXT("Fortran"), TEXT("Fortran source file"), L_FORTRAN, SCLEX_FORTRAN}, +{TEXT("bash"), TEXT("Shell"), TEXT("Unix script file"), L_BASH, SCLEX_BASH}, +{TEXT("actionscript"), TEXT("Flash Action"), TEXT("Flash Action script file"), L_FLASH, SCLEX_OBJC}, //WARNING, was "flash" +{TEXT("nsis"), TEXT("NSIS"), TEXT("Nullsoft Scriptable Install System script file"), L_NSIS, SCLEX_NSIS}, +{TEXT("tcl"), TEXT("TCL"), TEXT("Tool Command Language file"), L_TCL, SCLEX_TCL}, +{TEXT("lisp"), TEXT("Lisp"), TEXT("List Processing language file"), L_LISP, SCLEX_LISP}, +{TEXT("scheme"), TEXT("Scheme"), TEXT("Scheme file"), L_SCHEME, SCLEX_LISP}, +{TEXT("asm"), TEXT("Assembly"), TEXT("Assembly language source file"), L_ASM, SCLEX_ASM}, +{TEXT("diff"), TEXT("Diff"), TEXT("Diff file"), L_DIFF, SCLEX_DIFF}, +{TEXT("props"), TEXT("Properties file"), TEXT("Properties file"), L_PROPS, SCLEX_PROPERTIES}, +{TEXT("postscript"), TEXT("Postscript"), TEXT("Postscript file"), L_PS, SCLEX_PS}, +{TEXT("ruby"), TEXT("Ruby"), TEXT("Ruby file"), L_RUBY, SCLEX_RUBY}, +{TEXT("smalltalk"), TEXT("Smalltalk"), TEXT("Smalltalk file"), L_SMALLTALK, SCLEX_SMALLTALK}, +{TEXT("vhdl"), TEXT("VHDL"), TEXT("VHSIC Hardware Description Language file"), L_VHDL, SCLEX_VHDL}, +{TEXT("kix"), TEXT("KiXtart"), TEXT("KiXtart file"), L_KIX, SCLEX_KIX}, +{TEXT("autoit"), TEXT("AutoIt"), TEXT("AutoIt"), L_AU3, SCLEX_AU3}, +{TEXT("caml"), TEXT("CAML"), TEXT("Categorical Abstract Machine Language"), L_CAML, SCLEX_CAML}, +{TEXT("ada"), TEXT("Ada"), TEXT("Ada file"), L_ADA, SCLEX_ADA}, +{TEXT("verilog"), TEXT("Verilog"), TEXT("Verilog file"), L_VERILOG, SCLEX_VERILOG}, +{TEXT("matlab"), TEXT("MATLAB"), TEXT("MATrix LABoratory"), L_MATLAB, SCLEX_MATLAB}, +{TEXT("haskell"), TEXT("Haskell"), TEXT("Haskell"), L_HASKELL, SCLEX_HASKELL}, +{TEXT("inno"), TEXT("Inno"), TEXT("Inno Setup script"), L_INNO, SCLEX_INNOSETUP}, +{TEXT("searchResult"), TEXT("Internal Search"), TEXT("Internal Search"), L_SEARCHRESULT, SCLEX_SEARCHRESULT}, +{TEXT("cmake"), TEXT("CMAKEFILE"), TEXT("CMAKEFILE"), L_CMAKE, SCLEX_CMAKE}, +{TEXT("yaml"), TEXT("YAML"), TEXT("YAML Ain't Markup Language"), L_YAML, SCLEX_YAML}, +{TEXT("ext"), TEXT("External"), TEXT("External"), L_EXTERNAL, SCLEX_NULL} +}; + +//const int MASK_RED = 0xFF0000; +//const int MASK_GREEN = 0x00FF00; +//const int MASK_BLUE = 0x0000FF; + +void ScintillaEditView::init(HINSTANCE hInst, HWND hPere) +{ + if (!_hLib) + { + MessageBox( NULL, TEXT("Can not load the dynamic library"), TEXT("SCINTILLA ERROR : "), MB_OK | MB_ICONSTOP); + throw int(106901); + } + + Window::init(hInst, hPere); + _hSelf = ::CreateWindowEx( + WS_EX_CLIENTEDGE,\ + TEXT("Scintilla"),\ + TEXT("Notepad++"),\ + WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_CLIPCHILDREN | WS_EX_RTLREADING,\ + 0, 0, 100, 100,\ + _hParent,\ + NULL,\ + _hInst,\ + NULL); + + if (!_hSelf) + { + systemMessage(TEXT("System Error")); + throw int(106901); + } + + _pScintillaFunc = (SCINTILLA_FUNC)::SendMessage(_hSelf, SCI_GETDIRECTFUNCTION, 0, 0); + _pScintillaPtr = (SCINTILLA_PTR)::SendMessage(_hSelf, SCI_GETDIRECTPOINTER, 0, 0); + + _userDefineDlg.init(_hInst, _hParent, this); + + if (!_pScintillaFunc || !_pScintillaPtr) + { + systemMessage(TEXT("System Err")); + throw int(106901); + } + + execute(SCI_SETMARGINMASKN, _SC_MARGE_FOLDER, SC_MASK_FOLDERS); + showMargin(_SC_MARGE_FOLDER, true); + + execute(SCI_SETMARGINMASKN, _SC_MARGE_SYBOLE, (1<("fold"), reinterpret_cast("1")); + execute(SCI_SETPROPERTY, reinterpret_cast("fold.compact"), reinterpret_cast("0")); + + execute(SCI_SETPROPERTY, reinterpret_cast("fold.html"), reinterpret_cast("1")); + execute(SCI_SETPROPERTY, reinterpret_cast("fold.comment"), reinterpret_cast("1")); + execute(SCI_SETPROPERTY, reinterpret_cast("fold.preprocessor"), reinterpret_cast("1")); + execute(SCI_SETFOLDFLAGS, 16); + execute(SCI_SETSCROLLWIDTHTRACKING, true); + execute(SCI_SETSCROLLWIDTH, 1); //default empty document: override default width of 2000 + + // smart hilighting + execute(SCI_INDICSETSTYLE, SCE_UNIVERSAL_FOUND_STYLE_2, INDIC_ROUNDBOX); + execute(SCI_INDICSETSTYLE, SCE_UNIVERSAL_FOUND_STYLE, INDIC_ROUNDBOX); + execute(SCI_INDICSETSTYLE, SCE_UNIVERSAL_FOUND_STYLE_INC, INDIC_ROUNDBOX); + execute(SCI_INDICSETSTYLE, SCE_UNIVERSAL_TAGMATCH, INDIC_ROUNDBOX); + execute(SCI_INDICSETSTYLE, SCE_UNIVERSAL_TAGATTR, INDIC_ROUNDBOX); + execute(SCI_INDICSETSTYLE, SCE_UNIVERSAL_FOUND_STYLE_EXT1, INDIC_ROUNDBOX); + execute(SCI_INDICSETSTYLE, SCE_UNIVERSAL_FOUND_STYLE_EXT2, INDIC_ROUNDBOX); + execute(SCI_INDICSETSTYLE, SCE_UNIVERSAL_FOUND_STYLE_EXT3, INDIC_ROUNDBOX); + execute(SCI_INDICSETSTYLE, SCE_UNIVERSAL_FOUND_STYLE_EXT4, INDIC_ROUNDBOX); + execute(SCI_INDICSETSTYLE, SCE_UNIVERSAL_FOUND_STYLE_EXT5, INDIC_ROUNDBOX); + + execute(SCI_INDICSETALPHA, SCE_UNIVERSAL_FOUND_STYLE_2, 100); + execute(SCI_INDICSETALPHA, SCE_UNIVERSAL_FOUND_STYLE, 100); + execute(SCI_INDICSETALPHA, SCE_UNIVERSAL_FOUND_STYLE_INC, 100); + execute(SCI_INDICSETALPHA, SCE_UNIVERSAL_TAGMATCH, 100); + execute(SCI_INDICSETALPHA, SCE_UNIVERSAL_TAGATTR, 100); + execute(SCI_INDICSETALPHA, SCE_UNIVERSAL_FOUND_STYLE_EXT1, 100); + execute(SCI_INDICSETALPHA, SCE_UNIVERSAL_FOUND_STYLE_EXT2, 100); + execute(SCI_INDICSETALPHA, SCE_UNIVERSAL_FOUND_STYLE_EXT3, 100); + execute(SCI_INDICSETALPHA, SCE_UNIVERSAL_FOUND_STYLE_EXT4, 100); + execute(SCI_INDICSETALPHA, SCE_UNIVERSAL_FOUND_STYLE_EXT5, 100); + + execute(SCI_INDICSETUNDER, SCE_UNIVERSAL_FOUND_STYLE_2, true); + execute(SCI_INDICSETUNDER, SCE_UNIVERSAL_FOUND_STYLE, true); + execute(SCI_INDICSETUNDER, SCE_UNIVERSAL_FOUND_STYLE_INC, true); + execute(SCI_INDICSETUNDER, SCE_UNIVERSAL_TAGMATCH, true); + execute(SCI_INDICSETUNDER, SCE_UNIVERSAL_TAGATTR, true); + execute(SCI_INDICSETUNDER, SCE_UNIVERSAL_FOUND_STYLE_EXT1, true); + execute(SCI_INDICSETUNDER, SCE_UNIVERSAL_FOUND_STYLE_EXT2, true); + execute(SCI_INDICSETUNDER, SCE_UNIVERSAL_FOUND_STYLE_EXT3, true); + execute(SCI_INDICSETUNDER, SCE_UNIVERSAL_FOUND_STYLE_EXT4, true); + execute(SCI_INDICSETUNDER, SCE_UNIVERSAL_FOUND_STYLE_EXT5, true); + _pParameter = NppParameters::getInstance(); + + _codepage = ::GetACP(); + _oemCodepage = ::GetOEMCP(); + + //Use either Unicode or ANSI setwindowlong, depending on environment + if (::IsWindowUnicode(_hSelf)) + { + ::SetWindowLongPtrW(_hSelf, GWL_USERDATA, reinterpret_cast(this)); + _callWindowProc = CallWindowProcW; + _scintillaDefaultProc = reinterpret_cast(::SetWindowLongPtrW(_hSelf, GWL_WNDPROC, reinterpret_cast(scintillaStatic_Proc))); + } + else + { + ::SetWindowLongPtrA(_hSelf, GWL_USERDATA, reinterpret_cast(this)); + _callWindowProc = CallWindowProcA; + _scintillaDefaultProc = reinterpret_cast(::SetWindowLongPtrA(_hSelf, GWL_WNDPROC, reinterpret_cast(scintillaStatic_Proc))); + } + + //Get the startup document and make a buffer for it so it can be accessed like a file + attachDefaultDoc(); +} + +LRESULT ScintillaEditView::scintillaNew_Proc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) +{ + switch (Message) + { + case WM_CHAR : + { + if (execute(SCI_SELECTIONISRECTANGLE) && !(::GetKeyState(VK_LCONTROL) & 0x80000000)) + { + if (wParam != VK_ESCAPE) + { + execute(SCI_BEGINUNDOACTION); + + ColumnModeInfo colInfos = getColumnModeSelectInfo(); + generic_string str(1, (TCHAR)wParam); + columnReplace(colInfos, str.c_str()); + + int selStart = execute(SCI_GETSELECTIONSTART)+1; + int selEnd = execute(SCI_GETSELECTIONEND); + execute(SCI_SETSELECTIONSTART, selStart); + execute(SCI_SETSELECTIONEND, selEnd); + + execute(SCI_ENDUNDOACTION); + execute(SCI_SETCURRENTPOS,colInfos[colInfos.size()-1].second); + } + else + { + int pos = execute(SCI_GETSELECTIONSTART); + execute(SCI_SETSEL, pos, pos); + } + return TRUE; + } + break; + } + + case WM_MOUSEHWHEEL : + { + ::CallWindowProc(_scintillaDefaultProc, hwnd, WM_HSCROLL, ((short)HIWORD(wParam) > 0)?SB_LINERIGHT:SB_LINELEFT, NULL); + break; + } + + case WM_MOUSEWHEEL : + { + if (LOWORD(wParam) & MK_RBUTTON) + { + ::SendMessage(_hParent, Message, wParam, lParam); + return TRUE; + } + + //Have to perform the scroll first, because the first/last line do not get updated untill after the scroll has been parsed + LRESULT scrollResult = ::CallWindowProc(_scintillaDefaultProc, hwnd, Message, wParam, lParam); + return scrollResult; + break; + } + + case WM_IME_REQUEST: + { + + if (wParam == IMR_RECONVERTSTRING) + { + int textLength; + int selectSize; + char smallTextBuffer[128]; + char * selectedStr = smallTextBuffer; + RECONVERTSTRING * reconvert = (RECONVERTSTRING *)lParam; + + // does nothing with a rectangular selection + if (execute(SCI_SELECTIONISRECTANGLE, 0, 0)) + return 0; + + // get the codepage of the text + + unsigned int codepage = execute(SCI_GETCODEPAGE); + + // get the current text selection + + CharacterRange range = getSelection(); + if (range.cpMax == range.cpMin) + { + // no selection: select the current word instead + + expandWordSelection(); + range = getSelection(); + } + selectSize = range.cpMax - range.cpMin; + + // does nothing if still no luck with the selection + + if (selectSize == 0) + return 0; + + if (selectSize + 1 > sizeof(smallTextBuffer)) + selectedStr = new char[selectSize + 1]; + getText(selectedStr, range.cpMin, range.cpMax); + + if (reconvert == NULL) + { + // convert the selection to Unicode, and get the number + // of bytes required for the converted text + textLength = sizeof(WCHAR) * ::MultiByteToWideChar(codepage, 0, selectedStr, selectSize, NULL, 0); + } + else + { + // convert the selection to Unicode, and store it at the end of the structure. + // Beware: For a Unicode IME, dwStrLen , dwCompStrLen, and dwTargetStrLen + // are TCHAR values, that is, character counts. The members dwStrOffset, + // dwCompStrOffset, and dwTargetStrOffset specify byte counts. + + textLength = ::MultiByteToWideChar( codepage, 0, + selectedStr, selectSize, + (LPWSTR)((LPSTR)reconvert + sizeof(RECONVERTSTRING)), + reconvert->dwSize - sizeof(RECONVERTSTRING)); + + // fill the structure + reconvert->dwVersion = 0; + reconvert->dwStrLen = textLength; + reconvert->dwStrOffset = sizeof(RECONVERTSTRING); + reconvert->dwCompStrLen = textLength; + reconvert->dwCompStrOffset = 0; + reconvert->dwTargetStrLen = reconvert->dwCompStrLen; + reconvert->dwTargetStrOffset = reconvert->dwCompStrOffset; + + textLength *= sizeof(WCHAR); + } + + if (selectedStr != smallTextBuffer) + delete [] selectedStr; + + // return the total length of the structure + return sizeof(RECONVERTSTRING) + textLength; + } + break; + } + + case WM_VSCROLL : + { + break; + } + } + return _callWindowProc(_scintillaDefaultProc, hwnd, Message, wParam, lParam); +} + + +void ScintillaEditView::setSpecialStyle(Style & styleToSet) +{ + int styleID = styleToSet._styleID; + if ( styleToSet._colorStyle & COLORSTYLE_FOREGROUND ) + execute(SCI_STYLESETFORE, styleID, styleToSet._fgColor); + + if ( styleToSet._colorStyle & COLORSTYLE_BACKGROUND ) + execute(SCI_STYLESETBACK, styleID, styleToSet._bgColor); + + if ((!styleToSet._fontName)||(lstrcmp(styleToSet._fontName, TEXT("")))) + { +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + const char * fontNameA = wmc->wchar2char(styleToSet._fontName, CP_ACP); + execute(SCI_STYLESETFONT, (WPARAM)styleID, (LPARAM)fontNameA); +#else + execute(SCI_STYLESETFONT, (WPARAM)styleID, (LPARAM)styleToSet._fontName); +#endif + } + int fontStyle = styleToSet._fontStyle; + if (fontStyle != -1) + { + execute(SCI_STYLESETBOLD, (WPARAM)styleID, fontStyle & FONTSTYLE_BOLD); + execute(SCI_STYLESETITALIC, (WPARAM)styleID, fontStyle & FONTSTYLE_ITALIC); + execute(SCI_STYLESETUNDERLINE, (WPARAM)styleID, fontStyle & FONTSTYLE_UNDERLINE); + } + + if (styleToSet._fontSize > 0) + execute(SCI_STYLESETSIZE, styleID, styleToSet._fontSize); +} + +void ScintillaEditView::setStyle(Style styleToSet) +{ + GlobalOverride & go = _pParameter->getGlobalOverrideStyle(); + //go.enableBg = true; + + if (go.isEnable()) + { + StyleArray & stylers = _pParameter->getMiscStylerArray(); + int i = stylers.getStylerIndexByName(TEXT("Global override")); + if (i != -1) + { + Style & style = stylers.getStyler(i); + + if (go.enableFg) { + if (style._colorStyle & COLORSTYLE_FOREGROUND) { + styleToSet._colorStyle |= COLORSTYLE_FOREGROUND; + styleToSet._fgColor = style._fgColor; + } else { + if (styleToSet._styleID == STYLE_DEFAULT) { //if global is set to transparent, use default style color + styleToSet._colorStyle |= COLORSTYLE_FOREGROUND; + } else { + styleToSet._colorStyle &= ~COLORSTYLE_FOREGROUND; + } + } + } + if (go.enableBg) { + if (style._colorStyle & COLORSTYLE_BACKGROUND) { + styleToSet._colorStyle |= COLORSTYLE_BACKGROUND; + styleToSet._bgColor = style._bgColor; + } else { + if (styleToSet._styleID == STYLE_DEFAULT) { //if global is set to transparent, use default style color + styleToSet._colorStyle |= COLORSTYLE_BACKGROUND; + } else { + styleToSet._colorStyle &= ~COLORSTYLE_BACKGROUND; + } + } + } + if (go.enableFont && style._fontName && style._fontName[0]) + styleToSet._fontName = style._fontName; + if (go.enableFontSize && (style._fontSize > 0)) + styleToSet._fontSize = style._fontSize; + + if (style._fontStyle != -1) + { + if (go.enableBold) + { + if (style._fontStyle & FONTSTYLE_BOLD) + styleToSet._fontStyle |= FONTSTYLE_BOLD; + else + styleToSet._fontStyle &= ~FONTSTYLE_BOLD; + } + if (go.enableItalic) + { + if (style._fontStyle & FONTSTYLE_ITALIC) + styleToSet._fontStyle |= FONTSTYLE_ITALIC; + else + styleToSet._fontStyle &= ~FONTSTYLE_ITALIC; + } + if (go.enableUnderLine) + { + if (style._fontStyle & FONTSTYLE_UNDERLINE) + styleToSet._fontStyle |= FONTSTYLE_UNDERLINE; + else + styleToSet._fontStyle &= ~FONTSTYLE_UNDERLINE; + } + } + } + } + setSpecialStyle(styleToSet); +} + + +void ScintillaEditView::setXmlLexer(LangType type) +{ + if (type == L_XML) + { + execute(SCI_SETLEXER, SCLEX_XML); + for (int i = 0 ; i < 4 ; i++) + execute(SCI_SETKEYWORDS, i, reinterpret_cast(TEXT(""))); + + makeStyle(type); + } + else if ((type == L_HTML) || (type == L_PHP) || (type == L_ASP)) + { + execute(SCI_SETLEXER, SCLEX_HTML); + const TCHAR *htmlKeyWords_generic =_pParameter->getWordList(L_HTML, LANG_INDEX_INSTR); + +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + const char *htmlKeyWords = wmc->wchar2char(htmlKeyWords_generic, CP_ACP); + execute(SCI_SETKEYWORDS, 0, reinterpret_cast(htmlKeyWords?htmlKeyWords:"")); +#else + execute(SCI_SETKEYWORDS, 0, reinterpret_cast(htmlKeyWords_generic?htmlKeyWords_generic:"")); +#endif + makeStyle(L_HTML); + + setEmbeddedJSLexer(); + setPhpEmbeddedLexer(); + setEmbeddedAspLexer(); + } +} + +void ScintillaEditView::setEmbeddedJSLexer() +{ + const TCHAR *pKwArray[10] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; + makeStyle(L_JS, pKwArray); + + basic_string keywordList(""); + if (pKwArray[LANG_INDEX_INSTR]) + { +#ifdef UNICODE + basic_string kwlW = pKwArray[LANG_INDEX_INSTR]; + keywordList = wstring2string(kwlW, CP_ACP); +#else + keywordList = pKwArray[LANG_INDEX_INSTR]; +#endif + } + + execute(SCI_SETKEYWORDS, 1, (LPARAM)getCompleteKeywordList(keywordList, L_JS, LANG_INDEX_INSTR)); + execute(SCI_STYLESETEOLFILLED, SCE_HJ_DEFAULT, true); + execute(SCI_STYLESETEOLFILLED, SCE_HJ_COMMENT, true); + execute(SCI_STYLESETEOLFILLED, SCE_HJ_COMMENTDOC, true); +} + +void ScintillaEditView::setPhpEmbeddedLexer() +{ + const TCHAR *pKwArray[10] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; + makeStyle(L_PHP, pKwArray); + + basic_string keywordList(""); + if (pKwArray[LANG_INDEX_INSTR]) + { +#ifdef UNICODE + basic_string kwlW = pKwArray[LANG_INDEX_INSTR]; + keywordList = wstring2string(kwlW, CP_ACP); +#else + keywordList = pKwArray[LANG_INDEX_INSTR]; +#endif + } + + execute(SCI_SETKEYWORDS, 4, (LPARAM)getCompleteKeywordList(keywordList, L_PHP, LANG_INDEX_INSTR)); + + execute(SCI_STYLESETEOLFILLED, SCE_HPHP_DEFAULT, true); + execute(SCI_STYLESETEOLFILLED, SCE_HPHP_COMMENT, true); +} + +void ScintillaEditView::setEmbeddedAspLexer() +{ + const TCHAR *pKwArray[10] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; + makeStyle(L_ASP, pKwArray); + + basic_string keywordList(""); + if (pKwArray[LANG_INDEX_INSTR]) + { +#ifdef UNICODE + basic_string kwlW = pKwArray[LANG_INDEX_INSTR]; + keywordList = wstring2string(kwlW, CP_ACP); +#else + keywordList = pKwArray[LANG_INDEX_INSTR]; +#endif + } + + execute(SCI_SETKEYWORDS, 2, (LPARAM)getCompleteKeywordList(keywordList, L_VB, LANG_INDEX_INSTR)); + + execute(SCI_STYLESETEOLFILLED, SCE_HBA_DEFAULT, true); +} + +void ScintillaEditView::setUserLexer(const TCHAR *userLangName) +{ + execute(SCI_SETLEXER, SCLEX_USER); + + UserLangContainer * userLangContainer = userLangName?NppParameters::getInstance()->getULCFromName(userLangName):_userDefineDlg._pCurrentUserLang; + + if (!userLangContainer) + return; + + execute(SCI_SETPROPERTY, (WPARAM)"userDefine.ignoreCase", (LPARAM)(userLangContainer->_isCaseIgnored?"1":"0")); + execute(SCI_SETPROPERTY, (WPARAM)"userDefine.commentLineSymbol", (LPARAM)(userLangContainer->_isCommentLineSymbol?"1":"0")); + execute(SCI_SETPROPERTY, (WPARAM)"userDefine.commentSymbol", (LPARAM)(userLangContainer->_isCommentSymbol?"1":"0")); + + const char strArray[4][20] = {"userDefine.g1Prefix", "userDefine.g2Prefix", "userDefine.g3Prefix", "userDefine.g4Prefix"}; + for (int i = 0 ; i < 4 ; i++) + execute(SCI_SETPROPERTY, (WPARAM)strArray[i], (LPARAM)(userLangContainer->_isPrefix[i]?"1":"0")); + + for (int i = 0 ; i < userLangContainer->getNbKeywordList() ; i++) + { +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + const char * keyWords_char = wmc->wchar2char(userLangContainer->_keywordLists[i], CP_ACP); + execute(SCI_SETKEYWORDS, i, reinterpret_cast(keyWords_char)); +#else + execute(SCI_SETKEYWORDS, i, reinterpret_cast(userLangContainer->_keywordLists[i])); +#endif + } + + for (int i = 0 ; i < userLangContainer->_styleArray.getNbStyler() ; i++) + { + Style & style = userLangContainer->_styleArray.getStyler(i); + setStyle(style); + } +} + +void ScintillaEditView::setExternalLexer(LangType typeDoc) +{ + int id = typeDoc - L_EXTERNAL; + TCHAR * name = NppParameters::getInstance()->getELCFromIndex(id)._name; + +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + const char *pName = wmc->wchar2char(name, CP_ACP); +#else + const char *pName = name; +#endif + execute(SCI_SETLEXERLANGUAGE, 0, (LPARAM)pName); + + LexerStyler *pStyler = (_pParameter->getLStylerArray()).getLexerStylerByName(name); + if (pStyler) + { + for (int i = 0 ; i < pStyler->getNbStyler() ; i++) + { + Style & style = pStyler->getStyler(i); + + setStyle(style); + + if (style._keywordClass >= 0 && style._keywordClass <= KEYWORDSET_MAX) + { + basic_string keywordList(""); + if (style._keywords) + { +#ifdef UNICODE + keywordList = wstring2string(*(style._keywords), CP_ACP); +#else + keywordList = *(style._keywords); +#endif + } + execute(SCI_SETKEYWORDS, style._keywordClass, (LPARAM)getCompleteKeywordList(keywordList, typeDoc, style._keywordClass)); + } + } + } +} + +void ScintillaEditView::setCppLexer(LangType langType) +{ + const char *cppInstrs; + const char *cppTypes; + const TCHAR *doxygenKeyWords = _pParameter->getWordList(L_CPP, LANG_INDEX_TYPE2); + + const TCHAR *lexerName = ScintillaEditView::langNames[langType].lexerName; + + execute(SCI_SETLEXER, SCLEX_CPP); + if (isCJK()) + { + int charSet = codepage2CharSet(); + if (charSet) + execute(SCI_STYLESETCHARACTERSET, SCE_C_STRING, charSet); + } + + if ((langType != L_RC) && (langType != L_JS)) + { + if (doxygenKeyWords) + { +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + const char * doxygenKeyWords_char = wmc->wchar2char(doxygenKeyWords, CP_ACP); + execute(SCI_SETKEYWORDS, 2, (LPARAM)doxygenKeyWords_char); +#else + execute(SCI_SETKEYWORDS, 2, (LPARAM)doxygenKeyWords); +#endif + } + } + + if (langType == L_JS) + { + LexerStyler *pStyler = (_pParameter->getLStylerArray()).getLexerStylerByName(lexerName); + if (pStyler) + { + for (int i = 0 ; i < pStyler->getNbStyler() ; i++) + { + Style style = pStyler->getStyler(i); //not by reference, but copy + int cppID = style._styleID; + switch (style._styleID) + { + case SCE_HJ_DEFAULT : cppID = SCE_C_DEFAULT; break; + case SCE_HJ_WORD : cppID = SCE_C_IDENTIFIER; break; + case SCE_HJ_SYMBOLS : cppID = SCE_C_OPERATOR; break; + case SCE_HJ_COMMENT : cppID = SCE_C_COMMENT; break; + case SCE_HJ_COMMENTLINE : cppID = SCE_C_COMMENTLINE; break; + case SCE_HJ_COMMENTDOC : cppID = SCE_C_COMMENTDOC; break; + case SCE_HJ_NUMBER : cppID = SCE_C_NUMBER; break; + case SCE_HJ_KEYWORD : cppID = SCE_C_WORD; break; + case SCE_HJ_DOUBLESTRING : cppID = SCE_C_STRING; break; + case SCE_HJ_SINGLESTRING : cppID = SCE_C_CHARACTER; break; + case SCE_HJ_REGEX : cppID = SCE_C_REGEX; break; + } + style._styleID = cppID; + setStyle(style); + } + } + execute(SCI_STYLESETEOLFILLED, SCE_C_DEFAULT, true); + execute(SCI_STYLESETEOLFILLED, SCE_C_COMMENTLINE, true); + execute(SCI_STYLESETEOLFILLED, SCE_C_COMMENT, true); + execute(SCI_STYLESETEOLFILLED, SCE_C_COMMENTDOC, true); + } + + const TCHAR *pKwArray[10] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; + makeStyle(langType, pKwArray); + + basic_string keywordListInstruction(""); + basic_string keywordListType(""); + if (pKwArray[LANG_INDEX_INSTR]) + { +#ifdef UNICODE + basic_string kwlW = pKwArray[LANG_INDEX_INSTR]; + keywordListInstruction = wstring2string(kwlW, CP_ACP); +#else + keywordListInstruction = pKwArray[LANG_INDEX_INSTR]; +#endif + } + cppInstrs = getCompleteKeywordList(keywordListInstruction, langType, LANG_INDEX_INSTR); + + if (pKwArray[LANG_INDEX_TYPE]) + { +#ifdef UNICODE + basic_string kwlW = pKwArray[LANG_INDEX_TYPE]; + keywordListType = wstring2string(kwlW, CP_ACP); +#else + keywordListType = pKwArray[LANG_INDEX_TYPE]; +#endif + } + cppTypes = getCompleteKeywordList(keywordListType, langType, LANG_INDEX_TYPE); + + execute(SCI_SETKEYWORDS, 0, (LPARAM)cppInstrs); + execute(SCI_SETKEYWORDS, 1, (LPARAM)cppTypes); + +} + +//used by Objective-C and Actionscript +void ScintillaEditView::setObjCLexer(LangType langType) +{ + execute(SCI_SETLEXER, SCLEX_OBJC); + + const TCHAR *pKwArray[10] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; + + makeStyle(langType, pKwArray); + + basic_string objcInstr1Kwl(""); + if (pKwArray[LANG_INDEX_INSTR]) + { +#ifdef UNICODE + objcInstr1Kwl = wstring2string(pKwArray[LANG_INDEX_INSTR], CP_ACP); +#else + objcInstr1Kwl = pKwArray[LANG_INDEX_INSTR]; +#endif + } + const char *objcInstrs = getCompleteKeywordList(objcInstr1Kwl, langType, LANG_INDEX_INSTR); + + basic_string objcInstr2Kwl(""); + if (pKwArray[LANG_INDEX_INSTR2]) + { +#ifdef UNICODE + objcInstr2Kwl = wstring2string(pKwArray[LANG_INDEX_INSTR2], CP_ACP); +#else + objcInstr2Kwl = pKwArray[LANG_INDEX_INSTR2]; +#endif + } + const char *objCDirective = getCompleteKeywordList(objcInstr2Kwl, langType, LANG_INDEX_INSTR2); + + basic_string objcTypeKwl(""); + if (pKwArray[LANG_INDEX_TYPE]) + { +#ifdef UNICODE + objcTypeKwl = wstring2string(pKwArray[LANG_INDEX_TYPE], CP_ACP); +#else + objcTypeKwl = pKwArray[LANG_INDEX_TYPE]; +#endif + } + const char *objcTypes = getCompleteKeywordList(objcTypeKwl, langType, LANG_INDEX_TYPE); + + + basic_string objcType2Kwl(""); + if (pKwArray[LANG_INDEX_TYPE2]) + { +#ifdef UNICODE + objcType2Kwl = wstring2string(pKwArray[LANG_INDEX_TYPE2], CP_ACP); +#else + objcType2Kwl = pKwArray[LANG_INDEX_TYPE2]; +#endif + } + const char *objCQualifier = getCompleteKeywordList(objcType2Kwl, langType, LANG_INDEX_TYPE2); + + const TCHAR *doxygenKeyWords_generic = _pParameter->getWordList(L_CPP, LANG_INDEX_TYPE2); + const char * doxygenKeyWords; + basic_string doxygenKeyWordsString(""); +#ifdef UNICODE + doxygenKeyWordsString = wstring2string(doxygenKeyWords_generic, CP_ACP); + doxygenKeyWords = doxygenKeyWordsString.c_str(); +#else + doxygenKeyWords = doxygenKeyWords_generic; +#endif + execute(SCI_SETKEYWORDS, 0, (LPARAM)objcInstrs); + execute(SCI_SETKEYWORDS, 1, (LPARAM)objcTypes); + execute(SCI_SETKEYWORDS, 2, (LPARAM)doxygenKeyWords); + execute(SCI_SETKEYWORDS, 3, (LPARAM)objCDirective); + execute(SCI_SETKEYWORDS, 4, (LPARAM)objCQualifier); +} + +void ScintillaEditView::setKeywords(LangType langType, const char *keywords, int index) +{ + std::basic_string wordList; + wordList = (keywords)?keywords:""; + execute(SCI_SETKEYWORDS, index, (LPARAM)getCompleteKeywordList(wordList, langType, index)); +} + +void ScintillaEditView::setLexer(int lexerID, LangType langType, int whichList) +{ + execute(SCI_SETLEXER, lexerID); + + const TCHAR *pKwArray[10] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; + + makeStyle(langType, pKwArray); + +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); +#endif + + if (whichList & LIST_0) + { +#ifdef UNICODE + const char * keyWords_char = wmc->wchar2char(pKwArray[LANG_INDEX_INSTR], CP_ACP); + setKeywords(langType, keyWords_char, LANG_INDEX_INSTR); +#else + setKeywords(langType, pKwArray[LANG_INDEX_INSTR], LANG_INDEX_INSTR); +#endif + } + + if (whichList & LIST_1) + { +#ifdef UNICODE + const char * keyWords_char = wmc->wchar2char(pKwArray[LANG_INDEX_INSTR2], CP_ACP); + setKeywords(langType, keyWords_char, LANG_INDEX_INSTR2); +#else + setKeywords(langType, pKwArray[LANG_INDEX_INSTR2], LANG_INDEX_INSTR2); +#endif + } + + if (whichList & LIST_2) + { +#ifdef UNICODE + const char * keyWords_char = wmc->wchar2char(pKwArray[LANG_INDEX_TYPE], CP_ACP); + setKeywords(langType, keyWords_char, LANG_INDEX_TYPE); +#else + setKeywords(langType, pKwArray[LANG_INDEX_TYPE], LANG_INDEX_TYPE); +#endif + } + + if (whichList & LIST_3) + { +#ifdef UNICODE + const char * keyWords_char = wmc->wchar2char(pKwArray[LANG_INDEX_TYPE2], CP_ACP); + setKeywords(langType, keyWords_char, LANG_INDEX_TYPE2); +#else + setKeywords(langType, pKwArray[LANG_INDEX_TYPE2], LANG_INDEX_TYPE2); +#endif + } + + if (whichList & LIST_4) + { +#ifdef UNICODE + const char * keyWords_char = wmc->wchar2char(pKwArray[LANG_INDEX_TYPE3], CP_ACP); + setKeywords(langType, keyWords_char, LANG_INDEX_TYPE3); +#else + setKeywords(langType, pKwArray[LANG_INDEX_TYPE3], LANG_INDEX_TYPE3); +#endif + } + + if (whichList & LIST_5) + { +#ifdef UNICODE + const char * keyWords_char = wmc->wchar2char(pKwArray[LANG_INDEX_TYPE4], CP_ACP); + setKeywords(langType, keyWords_char, LANG_INDEX_TYPE4); +#else + setKeywords(langType, pKwArray[LANG_INDEX_TYPE4], LANG_INDEX_TYPE4); +#endif + } + + if (whichList & LIST_6) + { +#ifdef UNICODE + const char * keyWords_char = wmc->wchar2char(pKwArray[LANG_INDEX_TYPE5], CP_ACP); + setKeywords(langType, keyWords_char, LANG_INDEX_TYPE5); +#else + setKeywords(langType, pKwArray[LANG_INDEX_TYPE5], LANG_INDEX_TYPE5); +#endif + } +} + +void ScintillaEditView::makeStyle(LangType language, const TCHAR **keywordArray) +{ + const TCHAR * lexerName = ScintillaEditView::langNames[language].lexerName; + LexerStyler *pStyler = (_pParameter->getLStylerArray()).getLexerStylerByName(lexerName); + if (pStyler) + { + for (int i = 0 ; i < pStyler->getNbStyler() ; i++) + { + Style & style = pStyler->getStyler(i); + setStyle(style); + if (keywordArray) + { + if ((style._keywordClass != -1) && (style._keywords)) + keywordArray[style._keywordClass] = style._keywords->c_str(); + } + } + } +} + +void ScintillaEditView::defineDocType(LangType typeDoc) +{ + StyleArray & stylers = _pParameter->getMiscStylerArray(); + int iStyleDefault = stylers.getStylerIndexByID(STYLE_DEFAULT); + if (iStyleDefault != -1) + { + Style & styleDefault = stylers.getStyler(iStyleDefault); + styleDefault._colorStyle = COLORSTYLE_ALL; //override transparency + setStyle(styleDefault); + } + + execute(SCI_STYLECLEARALL); + int oldBits = execute(SCI_GETSTYLEBITSNEEDED); + + Style *pStyle; + Style defaultIndicatorStyle; + + defaultIndicatorStyle._styleID = SCE_UNIVERSAL_FOUND_STYLE; + defaultIndicatorStyle._bgColor = red; + pStyle = &defaultIndicatorStyle; + int iFind = stylers.getStylerIndexByID(SCE_UNIVERSAL_FOUND_STYLE); + if (iFind != -1) + { + pStyle = &(stylers.getStyler(iFind)); + } + setSpecialIndicator(*pStyle); + + defaultIndicatorStyle._styleID = SCE_UNIVERSAL_FOUND_STYLE_2; + defaultIndicatorStyle._bgColor = liteGreen; + pStyle = &defaultIndicatorStyle; + iFind = stylers.getStylerIndexByID(SCE_UNIVERSAL_FOUND_STYLE_2); + if (iFind != -1) + { + pStyle = &(stylers.getStyler(iFind)); + } + setSpecialIndicator(*pStyle); + + defaultIndicatorStyle._styleID = SCE_UNIVERSAL_FOUND_STYLE_INC; + defaultIndicatorStyle._bgColor = blue; + pStyle = &defaultIndicatorStyle; + iFind = stylers.getStylerIndexByID(SCE_UNIVERSAL_FOUND_STYLE_INC); + if (iFind != -1) + { + pStyle = &(stylers.getStyler(iFind)); + } + setSpecialIndicator(*pStyle); + + defaultIndicatorStyle._styleID = SCE_UNIVERSAL_TAGMATCH; + defaultIndicatorStyle._bgColor = RGB(0x80, 0x00, 0xFF); + pStyle = &defaultIndicatorStyle; + iFind = stylers.getStylerIndexByID(SCE_UNIVERSAL_TAGMATCH); + if (iFind != -1) + { + pStyle = &(stylers.getStyler(iFind)); + } + setSpecialIndicator(*pStyle); + + defaultIndicatorStyle._styleID = SCE_UNIVERSAL_TAGATTR; + defaultIndicatorStyle._bgColor = yellow; + pStyle = &defaultIndicatorStyle; + iFind = stylers.getStylerIndexByID(SCE_UNIVERSAL_TAGATTR); + if (iFind != -1) + { + pStyle = &(stylers.getStyler(iFind)); + } + setSpecialIndicator(*pStyle); + + + defaultIndicatorStyle._styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT1; + defaultIndicatorStyle._bgColor = cyan; + pStyle = &defaultIndicatorStyle; + iFind = stylers.getStylerIndexByID(SCE_UNIVERSAL_FOUND_STYLE_EXT1); + if (iFind != -1) + { + pStyle = &(stylers.getStyler(iFind)); + } + setSpecialIndicator(*pStyle); + + defaultIndicatorStyle._styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT2; + defaultIndicatorStyle._bgColor = orange; + pStyle = &defaultIndicatorStyle; + iFind = stylers.getStylerIndexByID(SCE_UNIVERSAL_FOUND_STYLE_EXT2); + if (iFind != -1) + { + pStyle = &(stylers.getStyler(iFind)); + } + setSpecialIndicator(*pStyle); + + defaultIndicatorStyle._styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT3; + defaultIndicatorStyle._bgColor = yellow; + pStyle = &defaultIndicatorStyle; + iFind = stylers.getStylerIndexByID(SCE_UNIVERSAL_FOUND_STYLE_EXT3); + if (iFind != -1) + { + pStyle = &(stylers.getStyler(iFind)); + } + setSpecialIndicator(*pStyle); + + defaultIndicatorStyle._styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT4; + defaultIndicatorStyle._bgColor = purple; + pStyle = &defaultIndicatorStyle; + iFind = stylers.getStylerIndexByID(SCE_UNIVERSAL_FOUND_STYLE_EXT4); + if (iFind != -1) + { + pStyle = &(stylers.getStyler(iFind)); + } + setSpecialIndicator(*pStyle); + + defaultIndicatorStyle._styleID = SCE_UNIVERSAL_FOUND_STYLE_EXT5; + defaultIndicatorStyle._bgColor = darkGreen; + pStyle = &defaultIndicatorStyle; + iFind = stylers.getStylerIndexByID(SCE_UNIVERSAL_FOUND_STYLE_EXT5); + if (iFind != -1) + { + pStyle = &(stylers.getStyler(iFind)); + } + setSpecialIndicator(*pStyle); + int caretWidth = 1; + + // Il faut surtout faire un test ici avant d'exécuter SCI_SETCODEPAGE + // Sinon y'aura un soucis de performance! + if (isCJK()) + { + if (getCurrentBuffer()->getUnicodeMode() == uni8Bit) + { + if (typeDoc != L_CSS || typeDoc != L_CAML || typeDoc != L_ASM || typeDoc != L_MATLAB) + execute(SCI_SETCODEPAGE, _codepage); + else + execute(SCI_SETCODEPAGE, CP_ACP); + } + } + + showMargin(_SC_MARGE_FOLDER, isNeededFolderMarge(typeDoc)); + switch (typeDoc) + { + case L_C : + case L_CPP : + case L_JS: + case L_JAVA : + case L_RC : + case L_CS : + case L_TCL : + setCppLexer(typeDoc); break; + + case L_FLASH : + case L_OBJC : + setObjCLexer(typeDoc); break; + + case L_PHP : + case L_ASP : + case L_HTML : + case L_XML : + setXmlLexer(typeDoc); break; + + case L_CSS : + setCssLexer(); break; + + case L_LUA : + setLuaLexer(); break; + + case L_MAKEFILE : + setMakefileLexer(); break; + + case L_INI : + setIniLexer(); break; + + case L_USER : { + const TCHAR * langExt = _currentBuffer->getUserDefineLangName(); + if (langExt[0]) + setUserLexer(langExt); + else + setUserLexer(); + break; } + + case L_NFO : + { + LexerStyler *pStyler = (_pParameter->getLStylerArray()).getLexerStylerByName(TEXT("nfo")); + COLORREF bg = black; + COLORREF fg = liteGrey; + Style nfoStyle; + nfoStyle._styleID = STYLE_DEFAULT; + nfoStyle._fontName = TEXT("MS LineDraw"); + + if (pStyler) + { + int i = pStyler->getStylerIndexByName(TEXT("DEFAULT")); + if (i != -1) + { + Style & style = pStyler->getStyler(i); + nfoStyle._bgColor = style._bgColor; + nfoStyle._fgColor = style._fgColor; + nfoStyle._colorStyle = style._colorStyle; + } + } + setStyle(nfoStyle); + execute(SCI_STYLECLEARALL); + + } + break; + + case L_SQL : + setSqlLexer(); break; + + case L_VB : + setVBLexer(); break; + + case L_PASCAL : + setPascalLexer(); break; + + case L_PERL : + setPerlLexer(); break; + + case L_PYTHON : + setPythonLexer(); break; + + case L_BATCH : + setBatchLexer(); break; + + case L_TEX : + setTeXLexer(); break; + + case L_NSIS : + setNsisLexer(); break; + + case L_BASH : + setBashLexer(); break; + + case L_FORTRAN : + setFortranLexer(); break; + + case L_LISP : + setLispLexer(); break; + + case L_SCHEME : + setSchemeLexer(); break; + + case L_ASM : + setAsmLexer(); break; + + case L_DIFF : + setDiffLexer(); break; + + case L_PROPS : + setPropsLexer(); break; + + case L_PS : + setPostscriptLexer(); break; + + case L_RUBY : + setRubyLexer(); break; + + case L_SMALLTALK : + setSmalltalkLexer(); break; + + case L_VHDL : + setVhdlLexer(); break; + + case L_KIX : + setKixLexer(); break; + + case L_CAML : + setCamlLexer(); break; + + case L_ADA : + setAdaLexer(); break; + + case L_VERILOG : + setVerilogLexer(); break; + + case L_AU3 : + setAutoItLexer(); break; + + case L_MATLAB : + setMatlabLexer(); break; + + case L_HASKELL : + setHaskellLexer(); break; + + case L_INNO : + setInnoLexer(); break; + + case L_CMAKE : + setCmakeLexer(); break; + + case L_YAML : + setYamlLexer(); break; + + case L_TXT : + default : + if (typeDoc >= L_EXTERNAL && typeDoc < NppParameters::getInstance()->L_END) + setExternalLexer(typeDoc); + else + execute(SCI_SETLEXER, (_codepage == CP_CHINESE_TRADITIONAL)?SCLEX_MAKEFILE:SCLEX_NULL); + break; + + } + //All the global styles should put here + int indexOfIndentGuide = stylers.getStylerIndexByID(STYLE_INDENTGUIDE); + if (indexOfIndentGuide != -1) + { + Style & styleIG = stylers.getStyler(indexOfIndentGuide); + setStyle(styleIG); + } + int indexOfBraceLight = stylers.getStylerIndexByID(STYLE_BRACELIGHT); + if (indexOfBraceLight != -1) + { + Style & styleBL = stylers.getStyler(indexOfBraceLight); + setStyle(styleBL); + } + //setStyle(STYLE_CONTROLCHAR, liteGrey); + int indexBadBrace = stylers.getStylerIndexByID(STYLE_BRACEBAD); + if (indexBadBrace != -1) + { + Style & styleBB = stylers.getStyler(indexBadBrace); + setStyle(styleBB); + } + int indexLineNumber = stylers.getStylerIndexByID(STYLE_LINENUMBER); + if (indexLineNumber != -1) + { + Style & styleLN = stylers.getStyler(indexLineNumber); + setSpecialStyle(styleLN); + } + execute(SCI_SETTABWIDTH, ((NppParameters::getInstance())->getNppGUI())._tabSize); + execute(SCI_SETUSETABS, !((NppParameters::getInstance())->getNppGUI())._tabReplacedBySpace); + int bitsNeeded = execute(SCI_GETSTYLEBITSNEEDED); + execute(SCI_SETSTYLEBITS, bitsNeeded); +} + +BufferID ScintillaEditView::attachDefaultDoc() +{ + // get the doc pointer attached (by default) on the view Scintilla + Document doc = execute(SCI_GETDOCPOINTER, 0, 0); + execute(SCI_ADDREFDOCUMENT, 0, doc); + BufferID id = MainFileManager->bufferFromDocument(doc, false, true);//true, true); //keep counter on 1 + Buffer * buf = MainFileManager->getBufferByID(id); + + MainFileManager->addBufferReference(id, this); //add a reference. Notepad only shows the buffer in tabbar + + _currentBufferID = id; + _currentBuffer = buf; + bufferUpdated(buf, BufferChangeMask); //make sure everything is in sync with the buffer, since no reference exists + + return id; +} + +void ScintillaEditView::saveCurrentPos() +{ + //Save data so, that the current topline becomes visible again after restoring. + int displayedLine = static_cast(execute(SCI_GETFIRSTVISIBLELINE)); + int docLine = execute(SCI_DOCLINEFROMVISIBLE, displayedLine); //linenumber of the line displayed in the top + //int offset = displayedLine - execute(SCI_VISIBLEFROMDOCLINE, docLine); //use this to calc offset of wrap. If no wrap this should be zero + + Buffer * buf = MainFileManager->getBufferByID(_currentBufferID); + + Position pos; + // the correct visible line number + pos._firstVisibleLine = docLine; + pos._startPos = static_cast(execute(SCI_GETANCHOR)); + pos._endPos = static_cast(execute(SCI_GETCURRENTPOS)); + pos._xOffset = static_cast(execute(SCI_GETXOFFSET)); + pos._selMode = execute(SCI_GETSELECTIONMODE); + pos._scrollWidth = execute(SCI_GETSCROLLWIDTH); + + buf->setPosition(pos, this); +} + +void ScintillaEditView::restoreCurrentPos() +{ + Buffer * buf = MainFileManager->getBufferByID(_currentBufferID); + Position & pos = buf->getPosition(this); + + execute(SCI_GOTOPOS, 0); //make sure first line visible by setting caret there, will scroll to top of document + + execute(SCI_SETSELECTIONMODE, pos._selMode); //enable + execute(SCI_SETANCHOR, pos._startPos); + execute(SCI_SETCURRENTPOS, pos._endPos); + execute(SCI_CANCEL); //disable + if (!isWrap()) { //only offset if not wrapping, otherwise the offset isnt needed at all + execute(SCI_SETSCROLLWIDTH, pos._scrollWidth); + execute(SCI_SETXOFFSET, pos._xOffset); + } + execute(SCI_CHOOSECARETX); // choose current x position + + int lineToShow = execute(SCI_VISIBLEFROMDOCLINE, pos._firstVisibleLine); + scroll(0, lineToShow); +} + +void ScintillaEditView::restyleBuffer() { + //int end = execute(SCI_GETENDSTYLED); //style up to the last styled byte. + //if (end == 0) + // return; + execute(SCI_CLEARDOCUMENTSTYLE); + execute(SCI_COLOURISE, 0, -1); + _currentBuffer->setNeedsLexing(false); +} + +void ScintillaEditView::styleChange() { + defineDocType(_currentBuffer->getLangType()); + restyleBuffer(); +} + +void ScintillaEditView::activateBuffer(BufferID buffer) +{ + if (buffer == BUFFER_INVALID) + return; + if (buffer == _currentBuffer) + return; + Buffer * newBuf = MainFileManager->getBufferByID(buffer); + + // before activating another document, we get the current position + // from the Scintilla view then save it to the current document + saveCurrentPos(); + + // get foldStateInfo of current doc + std::vector lineStateVector; + + int maxLine = execute(SCI_GETLINECOUNT); + + for (int line = 0; line < maxLine; line++) + { + int level = execute(SCI_GETFOLDLEVEL, line); + if (level & SC_FOLDLEVELHEADERFLAG) + { + bool expanded = (execute(SCI_GETFOLDEXPANDED, line) != 0); + lineStateVector.push_back(HeaderLineState(line, expanded)); + } + } + + // put the state into the future ex buffer + _currentBuffer->setHeaderLineState(lineStateVector, this); + + _currentBufferID = buffer; //the magical switch happens here + _currentBuffer = newBuf; + // change the doc, this operation will decrease + // the ref count of old current doc and increase the one of the new doc. FileManager should manage the rest + // Note that the actual reference in the Buffer itself is NOT decreased, Notepad_plus does that if neccessary + execute(SCI_SETDOCPOINTER, 0, _currentBuffer->getDocument()); + + // Due to execute(SCI_CLEARDOCUMENTSTYLE); in defineDocType() function + // defineDocType() function should be called here, but not be after the fold info loop + defineDocType(_currentBuffer->getLangType()); + + if (_currentBuffer->getNeedsLexing()) { + restyleBuffer(); + } + + // restore the collapsed info + std::vector & lineStateVectorNew = newBuf->getHeaderLineState(this); + int nbLineState = lineStateVectorNew.size(); + for (int i = 0 ; i < nbLineState ; i++) + { + HeaderLineState & hls = lineStateVectorNew.at(i); + bool expanded = (execute(SCI_GETFOLDEXPANDED, hls._headerLineNumber) != 0); + // set line to state folded + if (hls._isExpanded != expanded) + execute(SCI_TOGGLEFOLD, hls._headerLineNumber); + } + + restoreCurrentPos(); + + bufferUpdated(_currentBuffer, (BufferChangeMask & ~BufferChangeLanguage)); //everything should be updated, but the language (which undoes some operations done here like folding) + + //setup line number margin + int numLines = execute(SCI_GETLINECOUNT); + + char numLineStr[32]; + itoa(numLines, numLineStr, 10); + int nbDigit = strlen(numLineStr); + + runMarkers(true, 0, true, false); + return; //all done +} +void ScintillaEditView::bufferUpdated(Buffer * buffer, int mask) { + //actually only care about language and lexing etc + if (buffer == _currentBuffer) + { + if (mask & BufferChangeLanguage) + { + defineDocType(buffer->getLangType()); + foldAll(fold_uncollapse); + } + + if (mask & BufferChangeLexing) + { + if (buffer->getNeedsLexing()) + { + restyleBuffer(); //sets to false, this will apply to any other view aswell + } //else nothing, otherwise infinite loop + } + + if (mask & BufferChangeFormat) + { + execute(SCI_SETEOLMODE, _currentBuffer->getFormat()); + } + if (mask & BufferChangeReadonly) + { + execute(SCI_SETREADONLY, _currentBuffer->isReadOnly()); + } + if (mask & BufferChangeUnicode) + { + if (buffer->getUnicodeMode() == uni8Bit) + { //either 0 or CJK codepage + LangType typeDoc = buffer->getLangType(); + if (isCJK() && (typeDoc != L_CSS || typeDoc != L_CAML || typeDoc != L_ASM || typeDoc != L_MATLAB)) + { + execute(SCI_SETCODEPAGE, _codepage); //you may also want to set charsets here, not yet implemented + } + else + execute(SCI_SETCODEPAGE, 0); + } + else //CP UTF8 for all unicode + execute(SCI_SETCODEPAGE, SC_CP_UTF8); + } + } +} + +void ScintillaEditView::collapse(int level2Collapse, bool mode) +{ + // The following code is needed : + execute(SCI_COLOURISE, 0, -1); + // according to the Scitilla document : + // This requests the current lexer or the container (if the lexer is set to SCLEX_CONTAINER) + // to style the document between startPos and endPos. If endPos is -1, the document is styled from startPos to the end. + // If the "fold" property is set to "1" and your lexer or container supports folding, fold levels are also set. + // This message causes a redraw. + + int maxLine = execute(SCI_GETLINECOUNT); + + for (int line = 0; line < maxLine; line++) + { + int level = execute(SCI_GETFOLDLEVEL, line); + if (level & SC_FOLDLEVELHEADERFLAG) + { + level -= SC_FOLDLEVELBASE; + if (level2Collapse == (level & SC_FOLDLEVELNUMBERMASK)) + if ((execute(SCI_GETFOLDEXPANDED, line) != 0) != mode) + execute(SCI_TOGGLEFOLD, line); + } + } + + runMarkers(true, 0, true, false); +} + +void ScintillaEditView::foldCurrentPos(bool mode) +{ + // The following code is needed : + execute(SCI_COLOURISE, 0, -1); + // according to the Scitilla document : + // This requests the current lexer or the container (if the lexer is set to SCLEX_CONTAINER) + // to style the document between startPos and endPos. If endPos is -1, the document is styled from startPos to the end. + // If the "fold" property is set to "1" and your lexer or container supports folding, fold levels are also set. + // This message causes a redraw. + + int currentLine = this->getCurrentLineNumber(); + + int headerLine; + int level = execute(SCI_GETFOLDLEVEL, currentLine); + + if (level & SC_FOLDLEVELHEADERFLAG) + headerLine = currentLine; + else + { + headerLine = execute(SCI_GETFOLDPARENT, currentLine); + if (headerLine == -1) + return; + } + if ((execute(SCI_GETFOLDEXPANDED, headerLine) != 0) != mode) + execute(SCI_TOGGLEFOLD, headerLine); + +} + +void ScintillaEditView::foldAll(bool mode) +{ + // The following code is needed : + execute(SCI_COLOURISE, 0, -1); + // according to the Scitilla document : + // This requests the current lexer or the container (if the lexer is set to SCLEX_CONTAINER) + // to style the document between startPos and endPos. If endPos is -1, the document is styled from startPos to the end. + // If the "fold" property is set to "1" and your lexer or container supports folding, fold levels are also set. + // This message causes a redraw. + + int maxLine = execute(SCI_GETLINECOUNT); + + for (int line = 0; line < maxLine; line++) + { + int level = execute(SCI_GETFOLDLEVEL, line); + if (level & SC_FOLDLEVELHEADERFLAG) + if ((execute(SCI_GETFOLDEXPANDED, line) != 0) != mode) + execute(SCI_TOGGLEFOLD, line); + } +} + +void ScintillaEditView::getText(char *dest, int start, int end) const +{ + TextRange tr; + tr.chrg.cpMin = start; + tr.chrg.cpMax = end; + tr.lpstrText = dest; + execute(SCI_GETTEXTRANGE, 0, reinterpret_cast(&tr)); +} + +void ScintillaEditView::getGenericText(TCHAR *dest, int start, int end) const +{ +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + char *destA = new char[end - start + 1]; + getText(destA, start, end); + unsigned int cp = execute(SCI_GETCODEPAGE); + const TCHAR *destW = wmc->char2wchar(destA, cp); + lstrcpy(dest, destW); + delete [] destA; +#else + getText(dest, start, end); +#endif +} + +// "mstart" and "mend" are pointers to indexes in the read string, +// which are converted to the corresponding indexes in the returned TCHAR string. +void ScintillaEditView::getGenericText(TCHAR *dest, int start, int end, int *mstart, int *mend) const +{ +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + char *destA = new char[end - start + 1]; + getText(destA, start, end); + unsigned int cp = execute(SCI_GETCODEPAGE); + const TCHAR *destW = wmc->char2wchar(destA, cp, mstart, mend); + lstrcpy(dest, destW); + delete [] destA; +#else + getText(dest, start, end); +#endif +} + +void ScintillaEditView::insertGenericTextFrom(int position, const TCHAR *text2insert) const +{ +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + unsigned int cp = execute(SCI_GETCODEPAGE); + const char *text2insertA = wmc->wchar2char(text2insert, cp); + execute(SCI_INSERTTEXT, position, (WPARAM)text2insertA); +#else + execute(SCI_INSERTTEXT, position, (WPARAM)text2insert); +#endif +} + +void ScintillaEditView::replaceSelWith(const char * replaceText) +{ + execute(SCI_REPLACESEL, 0, (WPARAM)replaceText); +} + +char * ScintillaEditView::getSelectedText(char * txt, int size, bool expand) +{ + if (!size) + return NULL; + CharacterRange range = getSelection(); + if (range.cpMax == range.cpMin && expand) + { + expandWordSelection(); + range = getSelection(); + } + if (!(size > (range.cpMax - range.cpMin))) //there must be atleast 1 byte left for zero terminator + { + range.cpMax = range.cpMin+size-1; //keep room for zero terminator + } + getText(txt, range.cpMin, range.cpMax); + return txt; +} + +TCHAR * ScintillaEditView::getGenericSelectedText(TCHAR * txt, int size, bool expand) +{ + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + unsigned int cp = execute(SCI_GETCODEPAGE); +#ifdef UNICODE + char *txtA = new char[size + 1]; + getSelectedText(txtA, size, expand); + + const TCHAR * txtW = wmc->char2wchar(txtA, cp); + lstrcpy(txt, txtW); + delete [] txtA; + return txt; +#else + return getSelectedText(txt, size, expand); +#endif +} + +int ScintillaEditView::searchInTarget(const TCHAR * text2Find, int fromPos, int toPos) const +{ + execute(SCI_SETTARGETSTART, fromPos); + execute(SCI_SETTARGETEND, toPos); +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + unsigned int cp = execute(SCI_GETCODEPAGE); + const char *text2FindA = wmc->wchar2char(text2Find, cp); + int targetFound = execute(SCI_SEARCHINTARGET, (WPARAM)strlen(text2FindA), (LPARAM)text2FindA); + return targetFound; +#else + return execute(SCI_SEARCHINTARGET, (WPARAM)strlen(text2Find), (LPARAM)text2Find); +#endif +} + +void ScintillaEditView::appandGenericText(const TCHAR * text2Append) const +{ +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + unsigned int cp = execute(SCI_GETCODEPAGE); + const char *text2AppendA =wmc->wchar2char(text2Append, cp); + execute(SCI_APPENDTEXT, strlen(text2AppendA), (LPARAM)text2AppendA); +#else + execute(SCI_APPENDTEXT, strlen(text2Append), (LPARAM)text2Append); +#endif +} + +void ScintillaEditView::addGenericText(const TCHAR * text2Append) const +{ +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + unsigned int cp = execute(SCI_GETCODEPAGE); + const char *text2AppendA =wmc->wchar2char(text2Append, cp); + execute(SCI_ADDTEXT, strlen(text2AppendA), (LPARAM)text2AppendA); +#else + execute(SCI_ADDTEXT, strlen(text2Append), (LPARAM)text2Append); +#endif +} + +void ScintillaEditView::addGenericText(const TCHAR * text2Append, long *mstart, long *mend) const +{ +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + unsigned int cp = execute(SCI_GETCODEPAGE); + const char *text2AppendA =wmc->wchar2char(text2Append, cp, mstart, mend); + execute(SCI_ADDTEXT, strlen(text2AppendA), (LPARAM)text2AppendA); +#else + execute(SCI_ADDTEXT, strlen(text2Append), (LPARAM)text2Append); +#endif +} + +int ScintillaEditView::replaceTarget(const TCHAR * str2replace, int fromTargetPos, int toTargetPos) const +{ + if (fromTargetPos != -1 || toTargetPos != -1) + { + execute(SCI_SETTARGETSTART, fromTargetPos); + execute(SCI_SETTARGETEND, toTargetPos); + } +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + unsigned int cp = execute(SCI_GETCODEPAGE); + const char *str2replaceA = wmc->wchar2char(str2replace, cp); + return execute(SCI_REPLACETARGET, -1, (LPARAM)str2replaceA); +#else + return execute(SCI_REPLACETARGET, -1, (LPARAM)str2replace); +#endif +} + +int ScintillaEditView::replaceTargetRegExMode(const TCHAR * re, int fromTargetPos, int toTargetPos) const +{ + if (fromTargetPos != -1 || toTargetPos != -1) + { + execute(SCI_SETTARGETSTART, fromTargetPos); + execute(SCI_SETTARGETEND, toTargetPos); + } +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + unsigned int cp = execute(SCI_GETCODEPAGE); + const char *reA = wmc->wchar2char(re, cp); + return execute(SCI_REPLACETARGETRE, -1, (LPARAM)reA); +#else + return execute(SCI_REPLACETARGETRE, -1, (LPARAM)re); +#endif +} + +void ScintillaEditView::showAutoComletion(int lenEntered, const TCHAR * list) +{ +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + unsigned int cp = execute(SCI_GETCODEPAGE); + const char *listA = wmc->wchar2char(list, cp); + execute(SCI_AUTOCSHOW, lenEntered, WPARAM(listA)); +#else + execute(SCI_AUTOCSHOW, lenEntered, WPARAM(list)); +#endif +} + +void ScintillaEditView::showCallTip(int startPos, const TCHAR * def) +{ +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + unsigned int cp = execute(SCI_GETCODEPAGE); + const char *defA = wmc->wchar2char(def, cp); + execute(SCI_CALLTIPSHOW, startPos, LPARAM(defA)); +#else + execute(SCI_CALLTIPSHOW, startPos, (LPARAM)def); +#endif +} + + +void ScintillaEditView::getLine(int lineNumber, TCHAR * line, int lineBufferLen) +{ +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + unsigned int cp = execute(SCI_GETCODEPAGE); + char *lineA = new char[lineBufferLen]; + execute(SCI_GETLINE, lineNumber, (LPARAM)lineA); + const TCHAR *lineW = wmc->char2wchar(lineA, cp); + lstrcpy(line, lineW); + delete [] lineA; +#else + execute(SCI_GETLINE, lineNumber, (LPARAM)line); +#endif +} + + +void ScintillaEditView::addText(int length, const char *buf) +{ + execute(SCI_ADDTEXT, length, (LPARAM)buf); +} + +void ScintillaEditView::marginClick(int position, int modifiers) +{ + int lineClick = int(execute(SCI_LINEFROMPOSITION, position, 0)); + int levelClick = int(execute(SCI_GETFOLDLEVEL, lineClick, 0)); + if (levelClick & SC_FOLDLEVELHEADERFLAG) + { + if (modifiers & SCMOD_SHIFT) + { + // Ensure all children visible + execute(SCI_SETFOLDEXPANDED, lineClick, 1); + expand(lineClick, true, true, 100, levelClick); + } + else if (modifiers & SCMOD_CTRL) + { + if (execute(SCI_GETFOLDEXPANDED, lineClick, 0)) + { + // Contract this line and all children + execute(SCI_SETFOLDEXPANDED, lineClick, 0); + expand(lineClick, false, true, 0, levelClick); + } + else + { + // Expand this line and all children + execute(SCI_SETFOLDEXPANDED, lineClick, 1); + expand(lineClick, true, true, 100, levelClick); + } + } + else + { + // Toggle this line + execute(SCI_TOGGLEFOLD, lineClick, 0); + runMarkers(true, lineClick, true, false); + } + } +} + +void ScintillaEditView::expand(int &line, bool doExpand, bool force, int visLevels, int level) +{ + int lineMaxSubord = int(execute(SCI_GETLASTCHILD, line, level & SC_FOLDLEVELNUMBERMASK)); + line++; + while (line <= lineMaxSubord) + { + if (force) + { + if (visLevels > 0) + execute(SCI_SHOWLINES, line, line); + else + execute(SCI_HIDELINES, line, line); + } + else + { + if (doExpand) + execute(SCI_SHOWLINES, line, line); + } + int levelLine = level; + if (levelLine == -1) + levelLine = int(execute(SCI_GETFOLDLEVEL, line, 0)); + if (levelLine & SC_FOLDLEVELHEADERFLAG) + { + if (force) + { + if (visLevels > 1) + execute(SCI_SETFOLDEXPANDED, line, 1); + else + execute(SCI_SETFOLDEXPANDED, line, 0); + expand(line, doExpand, force, visLevels - 1); + } + else + { + if (doExpand) + { + if (!execute(SCI_GETFOLDEXPANDED, line, 0)) + execute(SCI_SETFOLDEXPANDED, line, 1); + + expand(line, true, force, visLevels - 1); + } + else + { + expand(line, false, force, visLevels - 1); + } + } + } + else + { + line++; + } + } + + runMarkers(true, 0, true, false); +} + +void ScintillaEditView::performGlobalStyles() +{ + StyleArray & stylers = _pParameter->getMiscStylerArray(); + + int i = stylers.getStylerIndexByName(TEXT("Current line background colour")); + if (i != -1) + { + Style & style = stylers.getStyler(i); + execute(SCI_SETCARETLINEBACK, style._bgColor); + } +/* + i = stylers.getStylerIndexByName(TEXT("Mark colour")); + if (i != -1) + { + Style & style = stylers.getStyler(i); + execute(SCI_MARKERSETFORE, 1, style._fgColor); + execute(SCI_MARKERSETBACK, 1, style._bgColor); + } +*/ + COLORREF selectColorBack = grey; + + i = stylers.getStylerIndexByName(TEXT("Selected text colour")); + if (i != -1) + { + Style & style = stylers.getStyler(i); + selectColorBack = style._bgColor; + } + execute(SCI_SETSELBACK, 1, selectColorBack); + + COLORREF caretColor = black; + i = stylers.getStylerIndexByID(SCI_SETCARETFORE); + if (i != -1) + { + Style & style = stylers.getStyler(i); + caretColor = style._fgColor; + } + execute(SCI_SETCARETFORE, caretColor); + + COLORREF edgeColor = liteGrey; + i = stylers.getStylerIndexByName(TEXT("Edge colour")); + if (i != -1) + { + Style & style = stylers.getStyler(i); + edgeColor = style._fgColor; + } + execute(SCI_SETEDGECOLOUR, edgeColor); + + COLORREF foldMarginColor = grey; + COLORREF foldMarginHiColor = white; + i = stylers.getStylerIndexByName(TEXT("Fold margin")); + if (i != -1) + { + Style & style = stylers.getStyler(i); + foldMarginHiColor = style._fgColor; + foldMarginColor = style._bgColor; + } + execute(SCI_SETFOLDMARGINCOLOUR, true, foldMarginColor); + execute(SCI_SETFOLDMARGINHICOLOUR, true, foldMarginHiColor); + + COLORREF foldfgColor = white; + COLORREF foldbgColor = grey; + i = stylers.getStylerIndexByName(TEXT("Fold")); + + if (i != -1) + { + Style & style = stylers.getStyler(i); + foldfgColor = style._bgColor; + foldbgColor = style._fgColor; + } + for (int j = 0 ; j < NB_FOLDER_STATE ; j++) + defineMarker(_markersArray[FOLDER_TYPE][j], _markersArray[_folderStyle][j], foldfgColor, foldbgColor); +/* + COLORREF unsavedChangebgColor = liteRed; + i = stylers.getStylerIndexByName(TEXT("Unsaved change marker")); + if (i != -1) + { + Style & style = stylers.getStyler(i); + unsavedChangebgColor = style._bgColor; + } + execute(SCI_MARKERSETBACK, MARK_LINEMODIFIEDUNSAVED, unsavedChangebgColor); + + COLORREF savedChangebgColor = liteBlueGreen; + i = stylers.getStylerIndexByName(TEXT("Saved change marker")); + if (i != -1) + { + Style & style = stylers.getStyler(i); + savedChangebgColor = style._bgColor; + } + execute(SCI_MARKERSETBACK, MARK_LINEMODIFIEDSAVED, savedChangebgColor); +*/ + COLORREF wsSymbolFgColor = black; + i = stylers.getStylerIndexByName(TEXT("White space symbol")); + if (i != -1) + { + Style & style = stylers.getStyler(i); + wsSymbolFgColor = style._fgColor; + } + execute(SCI_SETWHITESPACEFORE, true, wsSymbolFgColor); +} + +void ScintillaEditView::setLineIndent(int line, int indent) const { + if (indent < 0) + return; + CharacterRange crange = getSelection(); + int posBefore = execute(SCI_GETLINEINDENTPOSITION, line); + execute(SCI_SETLINEINDENTATION, line, indent); + int posAfter = execute(SCI_GETLINEINDENTPOSITION, line); + int posDifference = posAfter - posBefore; + if (posAfter > posBefore) { + // Move selection on + if (crange.cpMin >= posBefore) { + crange.cpMin += posDifference; + } + if (crange.cpMax >= posBefore) { + crange.cpMax += posDifference; + } + } else if (posAfter < posBefore) { + // Move selection back + if (crange.cpMin >= posAfter) { + if (crange.cpMin >= posBefore) + crange.cpMin += posDifference; + else + crange.cpMin = posAfter; + } + if (crange.cpMax >= posAfter) { + if (crange.cpMax >= posBefore) + crange.cpMax += posDifference; + else + crange.cpMax = posAfter; + } + } + execute(SCI_SETSEL, crange.cpMin, crange.cpMax); +} + +const char * ScintillaEditView::getCompleteKeywordList(std::basic_string & kwl, LangType langType, int keywordIndex) +{ + kwl += " "; + const TCHAR *defKwl_generic = _pParameter->getWordList(langType, keywordIndex); + +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + const char * defKwl = wmc->wchar2char(defKwl_generic, CP_ACP); + kwl += defKwl?defKwl:""; +#else + kwl += defKwl_generic?defKwl_generic:""; +#endif + + return kwl.c_str(); +} + + +void ScintillaEditView::convertSelectedTextTo(bool Case) +{ + unsigned int codepage = _codepage; + UniMode um = getCurrentBuffer()->getUnicodeMode(); + if (um != uni8Bit) + codepage = CP_UTF8; + + if (execute(SCI_SELECTIONISRECTANGLE)) + { + execute(SCI_BEGINUNDOACTION); + + int selStart = execute(SCI_GETSELECTIONSTART); + int selEnd = execute(SCI_GETSELECTIONEND); + + ColumnModeInfo cmi = getColumnModeSelectInfo(); + const int len = cmi[0].second - cmi[0].first; + char *srcStr = new char[len+1]; + wchar_t *destStr = new wchar_t[len+3]; + for (size_t i = 0 ; i < cmi.size() ; i++) + { + int start = cmi[i].first; + int end = cmi[i].second; + getText(srcStr, start, end); + + int nbChar = ::MultiByteToWideChar(codepage, 0, srcStr, len, destStr, len); + + for (int j = 0 ; j < nbChar ; j++) + { + if (Case == UPPERCASE) + destStr[j] = (wchar_t)::CharUpperW((LPWSTR)destStr[j]); + else + destStr[j] = (wchar_t)::CharLowerW((LPWSTR)destStr[j]); + } + ::WideCharToMultiByte(codepage, 0, destStr, len, srcStr, len, NULL, NULL); + + execute(SCI_SETTARGETSTART, start); + execute(SCI_SETTARGETEND, end); + execute(SCI_REPLACETARGET, -1, (LPARAM)srcStr); + } + + delete [] srcStr; + delete [] destStr; + + execute(SCI_SETSELECTIONSTART, selStart); + execute(SCI_SETSELECTIONEND, selEnd); + + execute(SCI_ENDUNDOACTION); + return; + } + + size_t selectionStart = execute(SCI_GETSELECTIONSTART); + size_t selectionEnd = execute(SCI_GETSELECTIONEND); + + int strSize = ((selectionEnd > selectionStart)?(selectionEnd - selectionStart):(selectionStart - selectionEnd))+1; + if (strSize) + { + char *selectedStr = new char[strSize+1]; + int strWSize = strSize * 2; + wchar_t *selectedStrW = new wchar_t[strWSize+3]; + + execute(SCI_GETSELTEXT, 0, (LPARAM)selectedStr); + + int nbChar = ::MultiByteToWideChar(codepage, 0, selectedStr, strSize, selectedStrW, strWSize); + + for (int i = 0 ; i < nbChar ; i++) + { + if (Case == UPPERCASE) + selectedStrW[i] = (WCHAR)::CharUpperW((LPWSTR)selectedStrW[i]); + else + selectedStrW[i] = (WCHAR)::CharLowerW((LPWSTR)selectedStrW[i]); + } + ::WideCharToMultiByte(codepage, 0, selectedStrW, strWSize, selectedStr, strSize, NULL, NULL); + + execute(SCI_REPLACESEL, strSize, (LPARAM)selectedStr); + execute(SCI_SETSEL, selectionStart, selectionEnd); + delete [] selectedStr; + delete [] selectedStrW; + } +} + + +bool ScintillaEditView::expandWordSelection() +{ + int caretPos = execute(SCI_GETCURRENTPOS, 0, 0); + int startPos = static_cast(execute(SCI_WORDSTARTPOSITION, caretPos, true)); + int endPos = static_cast(execute(SCI_WORDENDPOSITION, caretPos, true)); + if (startPos != endPos) { + execute(SCI_SETSELECTIONSTART, startPos); + execute(SCI_SETSELECTIONEND, endPos); + return true; + } + return false; +} + +TCHAR * int2str(TCHAR *str, int strLen, int number, int base, int nbChiffre, bool isZeroLeading) +{ + if (nbChiffre >= strLen) return NULL; + TCHAR f[64]; + TCHAR fStr[2] = TEXT("d"); + if (base == 16) + fStr[0] = 'X'; + else if (base == 8) + fStr[0] = 'o'; + else if (base == 2) + { + const unsigned int MASK_ULONG_BITFORT = 0x80000000; + int nbBits = sizeof(unsigned int) * 8; + int nbBit2Shift = (nbChiffre >= nbBits)?nbBits:(nbBits - nbChiffre); + unsigned long mask = MASK_ULONG_BITFORT >> nbBit2Shift; + int i = 0; + for (; mask > 0 ; i++) + { + str[i] = (mask & number)?'1':'0'; + mask >>= 1; + } + str[i] = '\0'; + } + + if (!isZeroLeading) + { + if (base == 2) + { + TCHAR *j = str; + for ( ; *j != '\0' ; j++) + if (*j == '1') + break; + lstrcpy(str, j); + } + else + { + wsprintf(f, TEXT("%%%s"), fStr); + wsprintf(str, f, number); + } + int i = lstrlen(str); + for ( ; i < nbChiffre ; i++) + str[i] = ' '; + str[i] = '\0'; + } + else + { + if (base != 2) + { + wsprintf(f, TEXT("%%.%d%s"), nbChiffre, fStr); + wsprintf(str, f, number); + } + // else already done. + } + return str; +} + +ColumnModeInfo ScintillaEditView::getColumnModeSelectInfo() +{ + ColumnModeInfo columnModeInfo; + if (execute(SCI_SELECTIONISRECTANGLE)) + { + int selStartAbsPos = execute(SCI_GETSELECTIONSTART); + int selEndAbsPos = execute(SCI_GETSELECTIONEND); + + int startCol = execute(SCI_GETCOLUMN, selStartAbsPos); + int endCol = execute(SCI_GETCOLUMN, selEndAbsPos); + + int startLine = execute(SCI_LINEFROMPOSITION, selStartAbsPos); + int endLine = execute(SCI_LINEFROMPOSITION, selEndAbsPos); + + if (endCol < startCol)// another way of selection + { + int tmp = startCol; + startCol = endCol; + endCol = tmp; + + selStartAbsPos = execute(SCI_FINDCOLUMN, startLine, startCol); + selEndAbsPos = execute(SCI_FINDCOLUMN, endLine, endCol); + } + + bool zeroCharSelMode = true; + for (int i = startLine ; i <= endLine ; i++) + { + int absPosSelStartPerLine = execute(SCI_FINDCOLUMN, i, startCol); + int absPosSelEndPerLine = execute(SCI_FINDCOLUMN, i, endCol); + + if (absPosSelStartPerLine != absPosSelEndPerLine) + { + zeroCharSelMode = false; + } + columnModeInfo.push_back(pair(absPosSelStartPerLine, absPosSelEndPerLine)); + } + + if (!zeroCharSelMode) + { + for (int i = columnModeInfo.size() - 1 ; i >= 0 ; i--) + { + ColumnModeInfo::iterator it = columnModeInfo.begin() + i; + if (it->first == it->second) + columnModeInfo.erase(it); + } + } + } + return columnModeInfo; +} + +void ScintillaEditView::columnReplace(ColumnModeInfo & cmi, const TCHAR *str) +{ + //for (int i = (int)cmi.size() - 1 ; i >= 0 ; i--) + int totalDiff = 0; + for (size_t i = 0 ; i < cmi.size() ; i++) + { + int len2beReplace = cmi[i].second - cmi[i].first; + int diff = lstrlen(str) - len2beReplace; + + cmi[i].first += totalDiff; + cmi[i].second += totalDiff; + + execute(SCI_SETTARGETSTART, cmi[i].first); + execute(SCI_SETTARGETEND, cmi[i].second); +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + unsigned int cp = execute(SCI_GETCODEPAGE); + const char *strA = wmc->wchar2char(str, cp); + execute(SCI_REPLACETARGET, -1, (LPARAM)strA); +#else + execute(SCI_REPLACETARGET, -1, (LPARAM)str); +#endif + totalDiff += diff; + cmi[i].second += diff; + } +} + + +void ScintillaEditView::columnReplace(ColumnModeInfo & cmi, int initial, int incr, UCHAR format) +{ + // 0000 00 00 : Dec BASE_10 + // 0000 00 01 : Hex BASE_16 + // 0000 00 10 : Oct BASE_08 + // 0000 00 11 : Bin BASE_02 + + // 0000 01 00 : 0 leading + + //Defined in ScintillaEditView.h : + //const UCHAR MASK_FORMAT = 0x03; + //const UCHAR MASK_ZERO_LEADING = 0x04; + + UCHAR f = format & MASK_FORMAT; + bool isZeroLeading = (MASK_ZERO_LEADING & format) != 0; + + int base = 10; + if (f == BASE_16) + base = 16; + else if (f == BASE_08) + base = 8; + else if (f == BASE_02) + base = 2; + + int endNumber = initial + incr * (cmi.size() - 1); + int nbEnd = getNbChiffre(endNumber, base); + int nbInit = getNbChiffre(initial, base); + int nb = max(nbInit, nbEnd); + + const int stringSize = 512; + TCHAR str[stringSize]; + + int totalDiff = 0; + for (size_t i = 0 ; i < cmi.size() ; i++) + { + int len2beReplace = cmi[i].second - cmi[i].first; + int diff = nb - len2beReplace; + + cmi[i].first += totalDiff; + cmi[i].second += totalDiff; + + int2str(str, stringSize, initial, base, nb, isZeroLeading); + + execute(SCI_SETTARGETSTART, cmi[i].first); + execute(SCI_SETTARGETEND, cmi[i].second); +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + unsigned int cp = execute(SCI_GETCODEPAGE); + const char *strA = wmc->wchar2char(str, cp); + execute(SCI_REPLACETARGET, -1, (LPARAM)strA); +#else + execute(SCI_REPLACETARGET, -1, (LPARAM)str); +#endif + initial += incr; + totalDiff += diff; + cmi[i].second += diff; + } +} + + +void ScintillaEditView::foldChanged(int line, int levelNow, int levelPrev) +{ + if (levelNow & SC_FOLDLEVELHEADERFLAG) //line can be folded + { + if (!(levelPrev & SC_FOLDLEVELHEADERFLAG)) //but previously couldnt + { + // Adding a fold point. + execute(SCI_SETFOLDEXPANDED, line, 1); + expand(line, true, false, 0, levelPrev); + } + } + else if (levelPrev & SC_FOLDLEVELHEADERFLAG) + { + if (!execute(SCI_GETFOLDEXPANDED, line)) + { + // Removing the fold from one that has been contracted so should expand + // otherwise lines are left invisible with no way to make them visible + execute(SCI_SETFOLDEXPANDED, line, 1); + expand(line, true, false, 0, levelPrev); + } + } + else if (!(levelNow & SC_FOLDLEVELWHITEFLAG) && + ((levelPrev & SC_FOLDLEVELNUMBERMASK) > (levelNow & SC_FOLDLEVELNUMBERMASK))) + { + // See if should still be hidden + int parentLine = execute(SCI_GETFOLDPARENT, line); + if ((parentLine < 0) || (execute(SCI_GETFOLDEXPANDED, parentLine) && execute(SCI_GETLINEVISIBLE, parentLine))) + execute(SCI_SHOWLINES, line, line); + } +} + +void ScintillaEditView::hideLines() { + //Folding can screw up hide lines badly if it unfolds a hidden section. + //Adding runMarkers(hide, foldstart) directly (folding on single document) can help + + //Special func on buffer. If markers are added, create notification with location of start, and hide bool set to true + int startLine = execute(SCI_LINEFROMPOSITION, execute(SCI_GETSELECTIONSTART)); + int endLine = execute(SCI_LINEFROMPOSITION, execute(SCI_GETSELECTIONEND)); + //perform range check: cannot hide very first and very last lines + //Offset them one off the edges, and then check if they are within the reasonable + int nrLines = execute(SCI_GETLINECOUNT); + if (nrLines < 3) + return; //cannot possibly hide anything + if (!startLine) + startLine++; + if (endLine == (nrLines-1)) + endLine--; + + if (startLine > endLine) + return; //tried to hide line at edge + + //Hide the lines. We add marks on the outside of the hidden section and hide the lines + //execute(SCI_HIDELINES, startLine, endLine); + //Add markers + execute(SCI_MARKERADD, startLine-1, MARK_HIDELINESBEGIN); + execute(SCI_MARKERADD, endLine+1, MARK_HIDELINESEND); + + //remove any markers in between + int scope = 0; + for(int i = startLine; i <= endLine; i++) { + int state = execute(SCI_MARKERGET, i); + bool closePresent = ((state & (1 << MARK_HIDELINESEND)) != 0); //check close first, then open, since close closes scope + bool openPresent = ((state & (1 << MARK_HIDELINESBEGIN)) != 0); + if (closePresent) { + execute(SCI_MARKERDELETE, i, MARK_HIDELINESEND); + if (scope > 0) scope--; + } + if (openPresent) { + execute(SCI_MARKERDELETE, i, MARK_HIDELINESBEGIN); + scope++; + } + } + if (scope != 0) { //something went wrong + //Someone managed to make overlapping hidelines sections. + //We cant do anything since this isnt supposed to happen + } + + _currentBuffer->setHideLineChanged(true, startLine-1); +} + +void ScintillaEditView::setHiLiteResultWords(const TCHAR *keywords) +{ +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + const char * word2search = wmc->wchar2char(keywords, CP_ACP); + setKeywords(L_SEARCHRESULT, word2search, 0); +#else + setKeywords(L_SEARCHRESULT, keywords, 0); +#endif +} + +bool ScintillaEditView::markerMarginClick(int lineNumber) { + + int state = execute(SCI_MARKERGET, lineNumber); + bool openPresent = ((state & (1 << MARK_HIDELINESBEGIN)) != 0); + bool closePresent = ((state & (1 << MARK_HIDELINESEND)) != 0); + + if (!openPresent && !closePresent) + return false; + + //Special func on buffer. First call show with location of opening marker. Then remove the marker manually + if (openPresent) { + _currentBuffer->setHideLineChanged(false, lineNumber); + } + if (closePresent) { + openPresent = false; + for(lineNumber--; lineNumber >= 0 && !openPresent; lineNumber--) { + state = execute(SCI_MARKERGET, lineNumber); + openPresent = ((state & (1 << MARK_HIDELINESBEGIN)) != 0); + } + if (openPresent) { + _currentBuffer->setHideLineChanged(false, lineNumber); + } + } + + return true; +} + +void ScintillaEditView::notifyMarkers(Buffer * buf, bool isHide, int location, bool del) { + if (buf != _currentBuffer) //if not visible buffer dont do a thing + return; + runMarkers(isHide, location, false, del); +} +//Run through full document. When switching in or opening folding +//hide is false only when user click on margin +void ScintillaEditView::runMarkers(bool doHide, int searchStart, bool endOfDoc, bool doDelete) { + //Removes markers if opening + /* + AllLines = (start,ENDOFDOCUMENT) + Hide: + Run through all lines. + Find open hiding marker: + set hiding start + Find closing: + if (hiding): + Hide lines between now and start + if (endOfDoc = false) + return + else + search for other hidden sections + + Show: + Run through all lines + Find open hiding marker + set last start + Find closing: + Show from last start. Stop. + Find closed folding header: + Show from last start to folding header + Skip to LASTCHILD + Set last start to lastchild + */ + int maxLines = execute(SCI_GETLINECOUNT); + if (doHide) { + int startHiding = searchStart; + bool isInSection = false; + for(int i = searchStart; i < maxLines; i++) { + int state = execute(SCI_MARKERGET, i); + if ( ((state & (1 << MARK_HIDELINESEND)) != 0) ) { + if (isInSection) { + execute(SCI_HIDELINES, startHiding, i-1); + if (!endOfDoc) { + return; //done, only single section requested + } //otherwise keep going + } + isInSection = false; + } + if ( ((state & (1 << MARK_HIDELINESBEGIN)) != 0) ) { + isInSection = true; + startHiding = i+1; + } + + } + } else { + int startShowing = searchStart; + bool isInSection = false; + for(int i = searchStart; i < maxLines; i++) { + int state = execute(SCI_MARKERGET, i); + if ( ((state & (1 << MARK_HIDELINESEND)) != 0) ) { + if (doDelete) + execute(SCI_MARKERDELETE, i, MARK_HIDELINESEND); + else if (isInSection) { + if (startShowing >= i) { //because of fold skipping, we passed the close tag. In that case we cant do anything + if (!endOfDoc) { + return; + } else { + continue; + } + } + execute(SCI_SHOWLINES, startShowing, i-1); + if (!endOfDoc) { + return; //done, only single section requested + } //otherwise keep going + isInSection = false; + } + } + if ( ((state & (1 << MARK_HIDELINESBEGIN)) != 0) ) { + if (doDelete) + execute(SCI_MARKERDELETE, i, MARK_HIDELINESBEGIN); + else { + isInSection = true; + startShowing = i+1; + } + } + + int levelLine = execute(SCI_GETFOLDLEVEL, i, 0); + if (levelLine & SC_FOLDLEVELHEADERFLAG) { //fold section. Dont show lines if fold is closed + if (isInSection && execute(SCI_GETFOLDEXPANDED, i) == 0) { + execute(SCI_SHOWLINES, startShowing, i); + startShowing = execute(SCI_GETLASTCHILD, i, (levelLine & SC_FOLDLEVELNUMBERMASK)); + } + } + } + } +} diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h new file mode 100644 index 00000000..a1ba1388 --- /dev/null +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h @@ -0,0 +1,821 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef SCINTILLA_EDIT_VIEW_H +#define SCINTILLA_EDIT_VIEW_H + +#include +#include "Window.h" +#include "Scintilla.h" +#include "ScintillaRef.h" +#include "SciLexer.h" +#include "Buffer.h" +#include "colors.h" +#include "UserDefineDialog.h" +#include "xpm_icons.h" +#include "resource.h" + +#ifndef WM_MOUSEWHEEL +#define WM_MOUSEWHEEL 0x020A +#endif //WM_MOUSEWHEEL + +#ifndef WM_MOUSEHWHEEL +#define WM_MOUSEHWHEEL 0x020E +#endif //WM_MOUSEHWHEEL + +#ifndef WM_APPCOMMAND +#define WM_APPCOMMAND 0x0319 +#define APPCOMMAND_BROWSER_BACKWARD 1 +#define APPCOMMAND_BROWSER_FORWARD 2 +#define FAPPCOMMAND_MASK 0xF000 +#define GET_APPCOMMAND_LPARAM(lParam) ((short)(HIWORD(lParam) & ~FAPPCOMMAND_MASK)) +#endif //WM_APPCOMMAND + +class NppParameters; + +#define NB_WORD_LIST 4 +#define WORD_LIST_LEN 256 + +typedef int (* SCINTILLA_FUNC) (void*, int, int, int); +typedef void * SCINTILLA_PTR; + +#define WM_DOCK_USERDEFINE_DLG (SCINTILLA_USER + 1) +#define WM_UNDOCK_USERDEFINE_DLG (SCINTILLA_USER + 2) +#define WM_CLOSE_USERDEFINE_DLG (SCINTILLA_USER + 3) +#define WM_REMOVE_USERLANG (SCINTILLA_USER + 4) +#define WM_RENAME_USERLANG (SCINTILLA_USER + 5) +#define WM_REPLACEALL_INOPENEDDOC (SCINTILLA_USER + 6) +#define WM_FINDALL_INOPENEDDOC (SCINTILLA_USER + 7) +#define WM_DOOPEN (SCINTILLA_USER + 8) +#define WM_FINDINFILES (SCINTILLA_USER + 9) +#define WM_REPLACEINFILES (SCINTILLA_USER + 10) +#define WM_FINDALL_INCURRENTDOC (SCINTILLA_USER + 11) + +const int NB_FOLDER_STATE = 7; + +// Codepage +const int CP_CHINESE_TRADITIONAL = 950; +const int CP_CHINESE_SIMPLIFIED = 936; +const int CP_JAPANESE = 932; +const int CP_KOREAN = 949; +const int CP_GREEK = 1253; + +//wordList +#define LIST_NONE 0 +#define LIST_0 1 +#define LIST_1 2 +#define LIST_2 4 +#define LIST_3 8 +#define LIST_4 16 +#define LIST_5 32 +#define LIST_6 64 + +const bool fold_uncollapse = true; +const bool fold_collapse = false; + +const bool UPPERCASE = true; +const bool LOWERCASE = false; + +typedef vector > ColumnModeInfo; +const UCHAR MASK_FORMAT = 0x03; +const UCHAR MASK_ZERO_LEADING = 0x04; +const UCHAR BASE_10 = 0x00; // Dec +const UCHAR BASE_16 = 0x01; // Hex +const UCHAR BASE_08 = 0x02; // Oct +const UCHAR BASE_02 = 0x03; // Bin + + +const int MARK_BOOKMARK = 24; +const int MARK_HIDELINESBEGIN = 23; +const int MARK_HIDELINESEND = 22; +//const int MARK_LINEMODIFIEDUNSAVED = 21; +//const int MARK_LINEMODIFIEDSAVED = 20; +// 24 - 16 reserved for Notepad++ internal used +// 15 - 0 are free to use for plugins + + +static int getNbChiffre(int aNum, int base) +{ + int nbChiffre = 1; + int diviseur = base; + + for (;;) + { + int result = aNum / diviseur; + if (!result) + break; + else + { + diviseur *= base; + nbChiffre++; + } + } + if ((base == 16) && (nbChiffre % 2 != 0)) + nbChiffre += 1; + + return nbChiffre; +}; + +TCHAR * int2str(TCHAR *str, int strLen, int number, int base, int nbChiffre, bool isZeroLeading); + +typedef LRESULT (WINAPI *CallWindowProcFunc) (WNDPROC,HWND,UINT,WPARAM,LPARAM); + +struct LanguageName { + const TCHAR * lexerName; + const TCHAR * shortName; + const TCHAR * longName; + LangType LangID; + int lexerID; +}; + +class ScintillaEditView : public Window +{ + friend class Notepad_plus; + friend class Finder; +public: + ScintillaEditView() + : Window(), _pScintillaFunc(NULL),_pScintillaPtr(NULL), + _folderStyle(FOLDER_STYLE_BOX), _lineNumbersShown(false), _wrapRestoreNeeded(false) + { + ++_refCount; + }; + + virtual ~ScintillaEditView() + { + --_refCount; + + if ((!_refCount)&&(_hLib)) + { + ::FreeLibrary(_hLib); + } + }; + virtual void destroy() + { + ::DestroyWindow(_hSelf); + _hSelf = NULL; + }; + + virtual void init(HINSTANCE hInst, HWND hPere); + + LRESULT execute(UINT Msg, WPARAM wParam=0, LPARAM lParam=0) const { + return _pScintillaFunc(_pScintillaPtr, static_cast(Msg), static_cast(wParam), static_cast(lParam)); + }; + + void activateBuffer(BufferID buffer); + + void getText(char *dest, int start, int end) const; + void getGenericText(TCHAR *dest, int start, int end) const; + void getGenericText(TCHAR *dest, int start, int end, int *mstart, int *mend) const; + void insertGenericTextFrom(int position, const TCHAR *text2insert) const; + void replaceSelWith(const char * replaceText); + + int getSelectedTextCount() { + CharacterRange range = getSelection(); + return (range.cpMax - range.cpMin); + }; + + char * getSelectedText(char * txt, int size, bool expand = true); + TCHAR * getGenericSelectedText(TCHAR * txt, int size, bool expand = true); + int searchInTarget(const TCHAR * Text2Find, int fromPos, int toPos) const; + void appandGenericText(const TCHAR * text2Append) const; + void addGenericText(const TCHAR * text2Append) const; + void addGenericText(const TCHAR * text2Append, long *mstart, long *mend) const; + int replaceTarget(const TCHAR * str2replace, int fromTargetPos = -1, int toTargetPos = -1) const; + int replaceTargetRegExMode(const TCHAR * re, int fromTargetPos = -1, int toTargetPos = -1) const; + void showAutoComletion(int lenEntered, const TCHAR * list); + void showCallTip(int startPos, const TCHAR * def); + void getLine(int lineNumber, TCHAR * line, int lineBufferLen); + void addText(int length, const char *buf); + + void saveCurrentPos(); + void restoreCurrentPos(); + void saveCurrentFold(); + void restoreCurrentFold(); + + int getCurrentDocLen() const { + return int(execute(SCI_GETLENGTH)); + }; + + CharacterRange getSelection() const { + CharacterRange crange; + crange.cpMin = long(execute(SCI_GETSELECTIONSTART)); + crange.cpMax = long(execute(SCI_GETSELECTIONEND)); + return crange; + }; + + void getWordToCurrentPos(TCHAR * str, int strLen) const { + int caretPos = execute(SCI_GETCURRENTPOS); + int startPos = static_cast(execute(SCI_WORDSTARTPOSITION, caretPos, true)); + + str[0] = '\0'; + if ((caretPos - startPos) < strLen) + getGenericText(str, startPos, caretPos); + }; + + void doUserDefineDlg(bool willBeShown = true, bool isRTL = false) { + _userDefineDlg.doDialog(willBeShown, isRTL); + }; + + static UserDefineDialog * getUserDefineDlg() {return &_userDefineDlg;}; + + void setCaretColorWidth(int color, int width = 1) const { + execute(SCI_SETCARETFORE, color); + execute(SCI_SETCARETWIDTH, width); + }; + + void beSwitched() { + _userDefineDlg.setScintilla(this); + }; + + //Marge member and method + static const int _SC_MARGE_LINENUMBER; + static const int _SC_MARGE_SYBOLE; + static const int _SC_MARGE_FOLDER; + //static const int _SC_MARGE_MODIFMARKER; + + void showMargin(int whichMarge, bool willBeShowed = true) { + if (whichMarge == _SC_MARGE_LINENUMBER) + showLineNumbersMargin(willBeShowed); + else + { + int width = 3; + if (whichMarge == _SC_MARGE_SYBOLE || whichMarge == _SC_MARGE_FOLDER) + width = 14; + execute(SCI_SETMARGINWIDTHN, whichMarge, willBeShowed?width:0); + } + }; + + bool hasMarginShowed(int witchMarge) { + return (execute(SCI_GETMARGINWIDTHN, witchMarge, 0) != 0); + }; + + void marginClick(int position, int modifiers); + + void setMakerStyle(folderStyle style) { + if (_folderStyle == style) + return; + _folderStyle = style; + for (int i = 0 ; i < NB_FOLDER_STATE ; i++) + defineMarker(_markersArray[FOLDER_TYPE][i], _markersArray[style][i], white, grey); + }; + + folderStyle getFolderStyle() {return _folderStyle;}; + + void showWSAndTab(bool willBeShowed = true) { + execute(SCI_SETVIEWWS, willBeShowed?SCWS_VISIBLEALWAYS:SCWS_INVISIBLE); + }; + + void showEOL(bool willBeShowed = true) { + execute(SCI_SETVIEWEOL, willBeShowed); + }; + + bool isEolVisible() { + return (execute(SCI_GETVIEWEOL) != 0); + }; + void showInvisibleChars(bool willBeShowed = true) { + showWSAndTab(willBeShowed); + showEOL(willBeShowed); + }; + + bool isInvisibleCharsShown() { + return (execute(SCI_GETVIEWWS) != 0); + }; + + void showIndentGuideLine(bool willBeShowed = true) { + execute(SCI_SETINDENTATIONGUIDES, (WPARAM)willBeShowed); + }; + + bool isShownIndentGuide() const { + return (execute(SCI_GETINDENTATIONGUIDES) != 0); + }; + + void wrap(bool willBeWrapped = true) { + execute(SCI_SETWRAPMODE, (WPARAM)willBeWrapped); + }; + + bool isWrap() const { + return (execute(SCI_GETWRAPMODE) == SC_WRAP_WORD); + }; + + bool isWrapSymbolVisible() const { + return (execute(SCI_GETWRAPVISUALFLAGS) != SC_WRAPVISUALFLAG_NONE); + }; + + void showWrapSymbol(bool willBeShown = true) { + execute(SCI_SETWRAPVISUALFLAGSLOCATION, SC_WRAPVISUALFLAGLOC_END_BY_TEXT); + execute(SCI_SETWRAPVISUALFLAGS, willBeShown?SC_WRAPVISUALFLAG_END:SC_WRAPVISUALFLAG_NONE); + }; + + long getCurrentLineNumber()const { + return long(execute(SCI_LINEFROMPOSITION, execute(SCI_GETCURRENTPOS))); + }; + + long lastZeroBasedLineNumber() const { + int endPos = execute(SCI_GETLENGTH); + return execute(SCI_LINEFROMPOSITION, endPos); + }; + + long getCurrentXOffset()const{ + return long(execute(SCI_GETXOFFSET)); + }; + + void setCurrentXOffset(long xOffset){ + execute(SCI_SETXOFFSET,xOffset); + }; + + void scroll(int column, int line){ + execute(SCI_LINESCROLL, column, line); + }; + + long getCurrentPointX()const{ + return long (execute(SCI_POINTXFROMPOSITION, 0, execute(SCI_GETCURRENTPOS))); + }; + + long getCurrentPointY()const{ + return long (execute(SCI_POINTYFROMPOSITION, 0, execute(SCI_GETCURRENTPOS))); + }; + + long getTextHeight()const{ + return long(execute(SCI_TEXTHEIGHT)); + }; + + void gotoLine(int line){ + if (line < execute(SCI_GETLINECOUNT)) + execute(SCI_GOTOLINE,line); + }; + + long getCurrentColumnNumber() const { + return long(execute(SCI_GETCOLUMN, execute(SCI_GETCURRENTPOS))); + }; + + long getSelectedByteNumber() const { + long start = long(execute(SCI_GETSELECTIONSTART)); + long end = long(execute(SCI_GETSELECTIONEND)); + return (start < end)?end-start:start-end; + }; + + long getLineLength(int line) const { + return long(execute(SCI_GETLINEENDPOSITION, line) - execute(SCI_POSITIONFROMLINE, line)); + }; + + long getLineIndent(int line) const { + return long(execute(SCI_GETLINEINDENTATION, line)); + }; + + void setLineIndent(int line, int indent) const; + + void showLineNumbersMargin(bool show){ + if (show == _lineNumbersShown) return; + _lineNumbersShown = show; + if (show) + { + updateLineNumberWidth(); + } + else + { + execute(SCI_SETMARGINWIDTHN, _SC_MARGE_LINENUMBER, 0); + } + } + + void updateLineNumberWidth() { + if (_lineNumbersShown) + { + int linesVisible = (int) execute(SCI_LINESONSCREEN); + if (linesVisible) + { + int firstVisibleLineVis = (int) execute(SCI_GETFIRSTVISIBLELINE); + int lastVisibleLineVis = linesVisible + firstVisibleLineVis + 1; + int i = 0; + while (lastVisibleLineVis) + { + lastVisibleLineVis /= 10; + i++; + } + i = max(i, 3); + { + int pixelWidth = int(8 + i * execute(SCI_TEXTWIDTH, STYLE_LINENUMBER, (LPARAM)"8")); + execute(SCI_SETMARGINWIDTHN, _SC_MARGE_LINENUMBER, pixelWidth); + } + } + } + }; + + void setCurrentLineHiLiting(bool isHiliting, COLORREF bgColor) const { + execute(SCI_SETCARETLINEVISIBLE, isHiliting); + if (!isHiliting) + return; + execute(SCI_SETCARETLINEBACK, bgColor); + }; + + bool isCurrentLineHiLiting() const { + return (execute(SCI_GETCARETLINEVISIBLE) != 0); + }; + + void performGlobalStyles(); + + void expand(int &line, bool doExpand, bool force = false, int visLevels = 0, int level = -1); + + void currentLineUp() const { + int currentLine = getCurrentLineNumber(); + if (currentLine != 0) + { + execute(SCI_BEGINUNDOACTION); + currentLine--; + execute(SCI_LINETRANSPOSE); + execute(SCI_GOTOLINE, currentLine); + execute(SCI_ENDUNDOACTION); + } + }; + + void currentLineDown() const { + int currentLine = getCurrentLineNumber(); + if (currentLine != (execute(SCI_GETLINECOUNT) - 1)) + { + execute(SCI_BEGINUNDOACTION); + currentLine++; + execute(SCI_GOTOLINE, currentLine); + execute(SCI_LINETRANSPOSE); + execute(SCI_ENDUNDOACTION); + } + }; + + void convertSelectedTextTo(bool Case); + + void convertSelectedTextToLowerCase() { + // if system is w2k or xp + if ((NppParameters::getInstance())->isTransparentAvailable()) + convertSelectedTextTo(LOWERCASE); + else + execute(SCI_LOWERCASE); + }; + + void convertSelectedTextToUpperCase() { + // if system is w2k or xp + if ((NppParameters::getInstance())->isTransparentAvailable()) + convertSelectedTextTo(UPPERCASE); + else + execute(SCI_UPPERCASE); + }; + + void collapse(int level2Collapse, bool mode); + void foldAll(bool mode); + void foldCurrentPos(bool mode); + int getCodepage() const {return _codepage;}; + + NppParameters * getParameter() { + return _pParameter; + }; + + ColumnModeInfo getColumnModeSelectInfo(); + + void columnReplace(ColumnModeInfo & cmi, const TCHAR *str); + void columnReplace(ColumnModeInfo & cmi, int initial, int incr, UCHAR format); + + void foldChanged(int line, int levelNow, int levelPrev); + void clearIndicator(int indicatorNumber) { + int docStart = 0; + int docEnd = getCurrentDocLen(); + execute(SCI_SETINDICATORCURRENT, indicatorNumber); + execute(SCI_INDICATORCLEARRANGE, docStart, docEnd-docStart); + }; + + static LanguageName ScintillaEditView::langNames[L_EXTERNAL+1]; + + void bufferUpdated(Buffer * buffer, int mask); + BufferID getCurrentBufferID() { return _currentBufferID; }; + Buffer * getCurrentBuffer() { return _currentBuffer; }; + void styleChange(); + + void hideLines(); + + bool markerMarginClick(int lineNumber); //true if it did something + void notifyMarkers(Buffer * buf, bool isHide, int location, bool del); + void runMarkers(bool doHide, int searchStart, bool endOfDoc, bool doDelete); + + bool isSelecting() const { + static CharacterRange previousSelRange = getSelection(); + CharacterRange currentSelRange = getSelection(); + + if (currentSelRange.cpMin == currentSelRange.cpMax) + { + previousSelRange = currentSelRange; + return false; + } + + if ((previousSelRange.cpMin == currentSelRange.cpMin) || (previousSelRange.cpMax == currentSelRange.cpMax)) + { + previousSelRange = currentSelRange; + return true; + } + + previousSelRange = currentSelRange; + return false; + }; + void setHiLiteResultWords(const TCHAR *keywords); +/* + pair getLineUndoState(size_t currentLine) { + Buffer * buf = getCurrentBuffer(); + return buf->getLineUndoState(currentLine); + }; + void setLineUndoState(size_t currentLine, size_t undoLevel, bool isSaved = false) { + Buffer * buf = getCurrentBuffer(); + buf->setLineUndoState(currentLine, undoLevel, isSaved); + }; + + void markSavedLines() { + for (int i = 0 ; i <= lastZeroBasedLineNumber() ; i++) + { + if ((execute(SCI_MARKERGET, i) & (1 << MARK_LINEMODIFIEDUNSAVED)) != 0) + { + execute(SCI_MARKERDELETE, i, MARK_LINEMODIFIEDUNSAVED); + execute(SCI_MARKERADD, i, MARK_LINEMODIFIEDSAVED); + //pair st = getLineUndoState(i); + setLineUndoState(i, 0, true); + } + } + }; +*/ +protected: + static HINSTANCE _hLib; + static int _refCount; + + static UserDefineDialog _userDefineDlg; + + static const int _markersArray[][NB_FOLDER_STATE]; + + static LRESULT CALLBACK scintillaStatic_Proc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { + ScintillaEditView *pScint = (ScintillaEditView *)(::GetWindowLongPtr(hwnd, GWL_USERDATA)); + // + if (Message == WM_MOUSEWHEEL || Message == WM_MOUSEHWHEEL) + { + POINT pt; + POINTS pts = MAKEPOINTS(lParam); + POINTSTOPOINT(pt, pts); + HWND hwndOnMouse = WindowFromPoint(pt); + ScintillaEditView *pScintillaOnMouse = (ScintillaEditView *)(::GetWindowLongPtr(hwndOnMouse, GWL_USERDATA)); + if (pScintillaOnMouse != pScint) + return ::SendMessage(hwndOnMouse, Message, wParam, lParam); + } + if (pScint) + return (pScint->scintillaNew_Proc(hwnd, Message, wParam, lParam)); + else + return ::DefWindowProc(hwnd, Message, wParam, lParam); + // + }; + + LRESULT scintillaNew_Proc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam); + + SCINTILLA_FUNC _pScintillaFunc; + SCINTILLA_PTR _pScintillaPtr; + + static WNDPROC _scintillaDefaultProc; + CallWindowProcFunc _callWindowProc; + + BufferID attachDefaultDoc(); + + //Store the current buffer so it can be retrieved later + BufferID _currentBufferID; + Buffer * _currentBuffer; + + folderStyle _folderStyle; + + NppParameters *_pParameter; + + int _codepage; + int _oemCodepage; + + bool _lineNumbersShown; + + bool _wrapRestoreNeeded; + +//Lexers and Styling + void defineDocType(LangType typeDoc); //setup stylers for active document + void restyleBuffer(); + const char * getCompleteKeywordList(std::basic_string & kwl, LangType langType, int keywordIndex); + void setKeywords(LangType langType, const char *keywords, int index); + void setLexer(int lexerID, LangType langType, int whichList); + inline void makeStyle(LangType langType, const TCHAR **keywordArray = NULL); + void setStyle(Style styleToSet); //NOT by reference (style edited) + void setSpecialStyle(Style & styleToSet); //by reference + void setSpecialIndicator(Style & styleToSet) { + execute(SCI_INDICSETFORE, styleToSet._styleID, styleToSet._bgColor); + }; + + //Complex lexers (same lexer, different language) + void setXmlLexer(LangType type); + void setCppLexer(LangType type); + void setObjCLexer(LangType type); + void setUserLexer(const TCHAR *userLangName = NULL); + void setExternalLexer(LangType typeDoc); + void setEmbeddedJSLexer(); + void setPhpEmbeddedLexer(); + void setEmbeddedAspLexer(); + //Simple lexers + void setCssLexer() { + setLexer(SCLEX_CSS, L_CSS, LIST_0 | LIST_1); + }; + + void setLuaLexer() { + setLexer(SCLEX_LUA, L_LUA, LIST_0 | LIST_1 | LIST_2 | LIST_3); + }; + + void setMakefileLexer() { + execute(SCI_SETLEXER, SCLEX_MAKEFILE); + makeStyle(L_MAKEFILE); + }; + + void setIniLexer() { + execute(SCI_SETLEXER, SCLEX_PROPERTIES); + execute(SCI_STYLESETEOLFILLED, SCE_PROPS_SECTION, true); + makeStyle(L_INI); + }; + + + void setSqlLexer() { + setLexer(SCLEX_SQL, L_SQL, LIST_0); + }; + + void setBashLexer() { + setLexer(SCLEX_BASH, L_BASH, LIST_0); + }; + + void setVBLexer() { + setLexer(SCLEX_VB, L_VB, LIST_0); + }; + + void setPascalLexer() { + setLexer(SCLEX_PASCAL, L_PASCAL, LIST_0); + }; + + void setPerlLexer() { + setLexer(SCLEX_PERL, L_PERL, LIST_0); + }; + + void setPythonLexer() { + setLexer(SCLEX_PYTHON, L_PYTHON, LIST_0); + }; + + void setBatchLexer() { + setLexer(SCLEX_BATCH, L_BATCH, LIST_0); + }; + + void setTeXLexer() { + for (int i = 0 ; i < 4 ; i++) + execute(SCI_SETKEYWORDS, i, reinterpret_cast(TEXT(""))); + setLexer(SCLEX_TEX, L_TEX, 0); + }; + + void setNsisLexer() { + setLexer(SCLEX_NSIS, L_NSIS, LIST_0 | LIST_1 | LIST_2 | LIST_3); + }; + + void setFortranLexer() { + setLexer(SCLEX_F77, L_FORTRAN, LIST_0 | LIST_1 | LIST_2); + }; + + void setLispLexer(){ + setLexer(SCLEX_LISP, L_LISP, LIST_0); + }; + + void setSchemeLexer(){ + setLexer(SCLEX_LISP, L_SCHEME, LIST_0); + }; + + void setAsmLexer(){ + setLexer(SCLEX_ASM, L_ASM, LIST_0 | LIST_1 | LIST_2 | LIST_3 | LIST_4 | LIST_5); + }; + + void setDiffLexer(){ + setLexer(SCLEX_DIFF, L_DIFF, LIST_NONE); + }; + + void setPropsLexer(){ + setLexer(SCLEX_PROPERTIES, L_PROPS, LIST_NONE); + }; + + void setPostscriptLexer(){ + setLexer(SCLEX_PS, L_PS, LIST_0 | LIST_1 | LIST_2 | LIST_3); + }; + + void setRubyLexer(){ + setLexer(SCLEX_RUBY, L_RUBY, LIST_0); + execute(SCI_STYLESETEOLFILLED, SCE_RB_POD, true); + }; + + void setSmalltalkLexer(){ + setLexer(SCLEX_SMALLTALK, L_SMALLTALK, LIST_0); + }; + + void setVhdlLexer(){ + setLexer(SCLEX_VHDL, L_VHDL, LIST_0 | LIST_1 | LIST_2 | LIST_3 | LIST_4 | LIST_5 | LIST_6); + }; + + void setKixLexer(){ + setLexer(SCLEX_KIX, L_KIX, LIST_0 | LIST_1 | LIST_2); + }; + + void setAutoItLexer(){ + setLexer(SCLEX_AU3, L_AU3, LIST_0 | LIST_1 | LIST_2 | LIST_3 | LIST_4 | LIST_5 | LIST_6); + }; + + void setCamlLexer(){ + setLexer(SCLEX_CAML, L_CAML, LIST_0 | LIST_1 | LIST_2); + }; + + void setAdaLexer(){ + setLexer(SCLEX_ADA, L_ADA, LIST_0); + }; + + void setVerilogLexer(){ + setLexer(SCLEX_VERILOG, L_VERILOG, LIST_0 | LIST_1); + }; + + void setMatlabLexer(){ + setLexer(SCLEX_MATLAB, L_MATLAB, LIST_0); + }; + + void setHaskellLexer(){ + setLexer(SCLEX_HASKELL, L_HASKELL, LIST_0); + }; + + void setInnoLexer() { + setLexer(SCLEX_INNOSETUP, L_INNO, LIST_0 | LIST_1 | LIST_2 | LIST_3 | LIST_4 | LIST_5); + }; + + void setCmakeLexer() { + setLexer(SCLEX_CMAKE, L_CMAKE, LIST_0 | LIST_1 | LIST_2); + }; + + void setYamlLexer() { + setLexer(SCLEX_YAML, L_YAML, LIST_0); + }; + + void setSearchResultLexer() { + execute(SCI_STYLESETEOLFILLED, SCE_SEARCHRESULT_FILE_HEADER, true); + execute(SCI_STYLESETEOLFILLED, SCE_SEARCHRESULT_SEARCH_HEADER, true); + setLexer(SCLEX_SEARCHRESULT, L_SEARCHRESULT, 0); + }; + + bool isNeededFolderMarge(LangType typeDoc) const { + switch (typeDoc) + { + case L_NFO: + case L_BATCH: + case L_TXT: + case L_MAKEFILE: + case L_SQL: + case L_ASM: + //case L_TEX: + case L_HASKELL: + case L_PROPS: + case L_SMALLTALK: + case L_KIX: + case L_ADA: + return false; + default: + return true; + } + }; +//END: Lexers and Styling + + void defineMarker(int marker, int markerType, COLORREF fore, COLORREF back) { + execute(SCI_MARKERDEFINE, marker, markerType); + execute(SCI_MARKERSETFORE, marker, fore); + execute(SCI_MARKERSETBACK, marker, back); + }; + + bool isCJK() const { + return ((_codepage == CP_CHINESE_TRADITIONAL) || (_codepage == CP_CHINESE_SIMPLIFIED) || + (_codepage == CP_JAPANESE) || (_codepage == CP_KOREAN) || (_codepage == CP_GREEK)); + }; + + int codepage2CharSet() const { + switch (_codepage) + { + case CP_CHINESE_TRADITIONAL : return SC_CHARSET_CHINESEBIG5; + case CP_CHINESE_SIMPLIFIED : return SC_CHARSET_GB2312; + case CP_KOREAN : return SC_CHARSET_HANGUL; + case CP_JAPANESE : return SC_CHARSET_SHIFTJIS; + case CP_GREEK : return SC_CHARSET_GREEK; + default : return 0; + } + }; + + bool expandWordSelection(); +}; + +#endif //SCINTILLA_EDIT_VIEW_H diff --git a/PowerEditor/src/ScitillaComponent/ScintillaRef.h b/PowerEditor/src/ScitillaComponent/ScintillaRef.h new file mode 100644 index 00000000..0581e045 --- /dev/null +++ b/PowerEditor/src/ScitillaComponent/ScintillaRef.h @@ -0,0 +1,6 @@ +#ifndef SCINTILLA_REF_H +#define SCINTILLA_REF_H + +enum folderStyle {FOLDER_TYPE, FOLDER_STYLE_SIMPLE, FOLDER_STYLE_ARROW, FOLDER_STYLE_CIRCLE, FOLDER_STYLE_BOX}; + +#endif //SCINTILLA_REF_H diff --git a/PowerEditor/src/ScitillaComponent/SmartHighlighter.cpp b/PowerEditor/src/ScitillaComponent/SmartHighlighter.cpp new file mode 100644 index 00000000..938f2b39 --- /dev/null +++ b/PowerEditor/src/ScitillaComponent/SmartHighlighter.cpp @@ -0,0 +1,177 @@ +//this file is part of notepad++ +//Copyright (C)2003 Harry +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#include "SmartHighlighter.h" +//#include "Parameters.h" + +#define MAXLINEHIGHLIGHT 400 //prevent highlighter from doing too much work when a lot is visible + +SmartHighlighter::SmartHighlighter(FindReplaceDlg * pFRDlg) +: _pFRDlg(pFRDlg) +{ + //Nothing to do +} + +void SmartHighlighter::highlightView(ScintillaEditView * pHighlightView) +{ + //Get selection + CharacterRange range = pHighlightView->getSelection(); + + //Clear marks + pHighlightView->clearIndicator(SCE_UNIVERSAL_FOUND_STYLE_2); + + //If nothing selected, dont mark anything + if (range.cpMin == range.cpMax) + { + return; + } + + int textlen = range.cpMax - range.cpMin + 1; + + char * text2Find = new char[textlen]; + pHighlightView->getSelectedText(text2Find, textlen, false); //do not expand selection (false) + + bool valid = true; + //The word has to consist if wordChars only, and the characters before and after something else + if (!isQualifiedWord(text2Find)) + valid = false; + else + { + UCHAR c = (UCHAR)pHighlightView->execute(SCI_GETCHARAT, range.cpMax); + if (c) + { + if (isWordChar(char(c))) + valid = false; + } + c = (UCHAR)pHighlightView->execute(SCI_GETCHARAT, range.cpMin-1); + if (c) + { + if (isWordChar(char(c))) + valid = false; + } + } + if (!valid) { + delete [] text2Find; + return; + } + + // save target locations for other search functions + int originalStartPos = (int)pHighlightView->execute(SCI_GETTARGETSTART); + int originalEndPos = (int)pHighlightView->execute(SCI_GETTARGETEND); + + // Get the range of text visible and highlight everything in it + int firstLine = (int)pHighlightView->execute(SCI_GETFIRSTVISIBLELINE); + int nrLines = min((int)pHighlightView->execute(SCI_LINESONSCREEN), MAXLINEHIGHLIGHT ) + 1; + int lastLine = firstLine+nrLines; + int startPos = 0;//(int)pHighlightView->execute(SCI_POSITIONFROMLINE, firstLine); + int endPos = 0;//(int)pHighlightView->execute(SCI_POSITIONFROMLINE, lastLine); + //if (endPos == -1) { //past EOF + // endPos = (int)pHighlightView->getCurrentDocLen() - 1; + //} + int currentLine = firstLine; + int prevDocLineChecked = -1; //invalid start + + FindOption fo; + fo._isMatchCase = false; + fo._isWholeWord = true; + + const TCHAR * searchText = NULL; +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + unsigned int cp = pHighlightView->execute(SCI_GETCODEPAGE); + const TCHAR * text2FindW = wmc->char2wchar(text2Find, cp); + searchText = text2FindW; +#else + searchText = text2Find; +#endif + + for(; currentLine < lastLine; currentLine++) { + int docLine = (int)pHighlightView->execute(SCI_DOCLINEFROMVISIBLE, currentLine); + if (docLine == prevDocLineChecked) + continue; //still on same line (wordwrap) + prevDocLineChecked = docLine; + startPos = (int)pHighlightView->execute(SCI_POSITIONFROMLINE, docLine); + endPos = (int)pHighlightView->execute(SCI_POSITIONFROMLINE, docLine+1); + if (endPos == -1) { //past EOF + endPos = (int)pHighlightView->getCurrentDocLen() - 1; + _pFRDlg->processRange(ProcessMarkAll_2, searchText, NULL, startPos, endPos, NULL, &fo); + break; + } else { + _pFRDlg->processRange(ProcessMarkAll_2, searchText, NULL, startPos, endPos, NULL, &fo); + } + } + + // restore the original targets to avoid conflicts with the search/replace functions + pHighlightView->execute(SCI_SETTARGETSTART, originalStartPos); + pHighlightView->execute(SCI_SETTARGETEND, originalEndPos); +} + +bool SmartHighlighter::isQualifiedWord(const char *str) const +{ + for (size_t i = 0 ; i < strlen(str) ; i++) + { + if (!isWordChar(str[i])) + return false; + } + return true; +}; + +bool SmartHighlighter::isWordChar(char ch) const +{ + if ((UCHAR)ch < 0x20) + return false; + + switch(ch) + { + case ' ': + case ' ': + case '\n': + case '\r': + case '.': + case ',': + case '?': + case ';': + case ':': + case '!': + case '(': + case ')': + case '[': + case ']': + case '+': + case '-': + case '*': + case '/': + case '#': + case '@': + case '^': + case '%': + case '$': + case '"': + case '\'': + case '~': + case '&': + case '{': + case '}': + case '|': + case '=': + case '<': + case '>': + case '\\': + return false; + } + return true; +}; diff --git a/PowerEditor/src/ScitillaComponent/SmartHighlighter.h b/PowerEditor/src/ScitillaComponent/SmartHighlighter.h new file mode 100644 index 00000000..fe72055d --- /dev/null +++ b/PowerEditor/src/ScitillaComponent/SmartHighlighter.h @@ -0,0 +1,35 @@ +//this file is part of notepad++ +//Copyright (C)2003 Harry +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef SMARTHIGHLIGHTER_H +#define SMARTHIGHLIGHTER_H + +#include "ScintillaEditView.h" +#include "FindReplaceDlg.h" + +class SmartHighlighter { +public: + SmartHighlighter(FindReplaceDlg * pFRDlg); + void highlightView(ScintillaEditView * pHighlightView); +private: + FindReplaceDlg * _pFRDlg; + + bool isQualifiedWord(const char *str) const; + bool isWordChar(char ch) const; +}; + +#endif //SMARTHIGHLIGHTER_H \ No newline at end of file diff --git a/PowerEditor/src/ScitillaComponent/UserDefineDialog.cpp b/PowerEditor/src/ScitillaComponent/UserDefineDialog.cpp new file mode 100644 index 00000000..8ae03652 --- /dev/null +++ b/PowerEditor/src/ScitillaComponent/UserDefineDialog.cpp @@ -0,0 +1,1611 @@ +//this file is part of Notepad++ +//Copyright (C)2003 Don HO +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#include "UserDefineDialog.h" +#include "ScintillaEditView.h" +#include "Parameters.h" +#include "resource.h" +#include "Notepad_plus_msgs.h" + +UserLangContainer * SharedParametersDialog::_pUserLang = NULL; +ScintillaEditView * SharedParametersDialog::_pScintilla = NULL; + +void SharedParametersDialog::initControls() +{ + NppParameters *pNppParam = NppParameters::getInstance(); + for (int i = 0 ; i < _nbGroup ; i++) + { + HWND hFgColourStaticText = ::GetDlgItem(_hSelf, _fgStatic[i]); + HWND hBgColourStaticText = ::GetDlgItem(_hSelf, _bgStatic[i]); + + _pFgColour[i] = new ColourPicker; + _pFgColour[i]->init(_hInst, _hSelf); + _pFgColour[i]->setColour(black); + + _pBgColour[i] = new ColourPicker; + _pBgColour[i]->init(_hInst, _hSelf); + _pBgColour[i]->setColour(white); + + POINT p1, p2; + + alignWith(hFgColourStaticText, _pFgColour[i]->getHSelf(), ALIGNPOS_RIGHT, p1); + alignWith(hBgColourStaticText, _pBgColour[i]->getHSelf(), ALIGNPOS_RIGHT, p2); + + p1.x = p2.x = ((p1.x > p2.x)?p1.x:p2.x) + 10; + p1.y -= 4; p2.y -= 4; + + ::MoveWindow(_pFgColour[i]->getHSelf(), p1.x, p1.y, 25, 25, TRUE); + ::MoveWindow(_pBgColour[i]->getHSelf(), p2.x, p2.y, 25, 25, TRUE); + _pFgColour[i]->display(); + _pBgColour[i]->display(); + + //for the font size combos + for(int j = 0 ; j < int(sizeof(fontSizeStrs))/(3*sizeof(TCHAR)) ; j++) + { + ::SendDlgItemMessage(_hSelf, _fontSizeCombo[i], CB_ADDSTRING, 0, (LPARAM)fontSizeStrs[j]); + } + + //for the font name combos + HWND hFontNameCombo = ::GetDlgItem(_hSelf, _fontNameCombo[i]); + + const std::vector & fontlist = pNppParam->getFontList(); + for (int j = 0 ; j < int(fontlist.size()) ; j++) + { + int k = ::SendMessage(hFontNameCombo, CB_ADDSTRING, 0, (LPARAM)fontlist[j].c_str()); + ::SendMessage(hFontNameCombo, CB_SETITEMDATA, k, (LPARAM)fontlist[j].c_str()); + } +/* + ETDTProc enableDlgTheme = (ETDTProc)pNppParam->getEnableThemeDlgTexture(); + if (enableDlgTheme) + { + enableDlgTheme(_hSelf, ETDT_ENABLETAB); + redraw(); + } +*/ + } +} + +bool SharedParametersDialog::setPropertyByCheck(HWND hwnd, WPARAM id, bool & bool2set) +{ + bool2set = (BST_CHECKED == ::SendMessage(::GetDlgItem(hwnd, id), BM_GETCHECK, 0, 0)); + + if (_pScintilla->getCurrentBuffer()->getLangType() == L_USER) + _pScintilla->styleChange(); + return TRUE; +} + +void SharedParametersDialog::styleUpdate(const Style & style, ColourPicker *pFgColourPicker, ColourPicker *pBgColourPicker, + int fontComboId, int fontSizeComboId, int boldCheckId, int italicCheckId, int underlineCheckId) +{ + pFgColourPicker->setColour((style._fgColor == COLORREF(-1))?black:style._fgColor); + pFgColourPicker->setEnabled((style._colorStyle & COLORSTYLE_FOREGROUND) != 0); + pFgColourPicker->redraw(); + pBgColourPicker->setColour((style._bgColor == COLORREF(-1))?white:style._bgColor); + pBgColourPicker->setEnabled((style._colorStyle & COLORSTYLE_BACKGROUND) != 0); + pBgColourPicker->redraw(); + + HWND hFontCombo = ::GetDlgItem(_hSelf, fontComboId); + int i = ::SendMessage(hFontCombo, CB_FINDSTRINGEXACT, (WPARAM)-1, (LPARAM)style._fontName); + if (i == CB_ERR) + i = 0; + ::SendMessage(hFontCombo, CB_SETCURSEL, i, 0); + + TCHAR size[10]; + if (style._fontSize == -1) + size[0] = '\0'; + else + wsprintf(size, TEXT("%d"), style._fontSize); + + hFontCombo = ::GetDlgItem(_hSelf, fontSizeComboId); + i = ::SendMessage(hFontCombo, CB_FINDSTRINGEXACT, (WPARAM)-1, (LPARAM)size); + if (i != CB_ERR) + ::SendMessage(hFontCombo, CB_SETCURSEL, i, 0); + int isBold = 0; + int isItalic = 0; + int isUnderline = 0; + if (style._fontStyle != -1) + { + isBold = (style._fontStyle & FONTSTYLE_BOLD)?BST_CHECKED:BST_UNCHECKED; + isItalic = (style._fontStyle & FONTSTYLE_ITALIC)?BST_CHECKED:BST_UNCHECKED; + isUnderline = (style._fontStyle & FONTSTYLE_UNDERLINE)?BST_CHECKED:BST_UNCHECKED; + } + ::SendDlgItemMessage(_hSelf, boldCheckId, BM_SETCHECK, isBold, 0); + ::SendDlgItemMessage(_hSelf, italicCheckId, BM_SETCHECK, isItalic, 0); + ::SendDlgItemMessage(_hSelf, underlineCheckId, BM_SETCHECK, isUnderline, 0); +} + +int fgStatic[] = {IDC_DEFAULT_FG_STATIC, IDC_FOLDEROPEN_FG_STATIC, IDC_FOLDERCLOSE_FG_STATIC}; +int bgStatic[] = {IDC_DEFAULT_BG_STATIC, IDC_FOLDEROPEN_BG_STATIC, IDC_FOLDERCLOSE_BG_STATIC}; +int fontSizeCombo[] = {IDC_DEFAULT_FONTSIZE_COMBO, IDC_FOLDEROPEN_FONTSIZE_COMBO, IDC_FOLDERCLOSE_FONTSIZE_COMBO}; +int fontNameCombo[] = {IDC_DEFAULT_FONT_COMBO, IDC_FOLDEROPEN_FONT_COMBO, IDC_FOLDERCLOSE_FONT_COMBO}; + +FolderStyleDialog::FolderStyleDialog() : SharedParametersDialog(3) +{ + memcpy(_fgStatic, fgStatic, sizeof(fgStatic)); + memcpy(_bgStatic, bgStatic, sizeof(bgStatic)); + memcpy(_fontSizeCombo, fontSizeCombo, sizeof(fontSizeCombo)); + memcpy(_fontNameCombo, fontNameCombo, sizeof(fontNameCombo)); +} + +void FolderStyleDialog::setKeywords2List(int ctrlID) +{ + int index; + if (ctrlID == IDC_FOLDEROPEN_EDIT) + index = 1; + else if (ctrlID == IDC_FOLDERCLOSE_EDIT) + index = 2; + else + index = -1; + + if (index != -1) + ::GetDlgItemText(_hSelf, ctrlID, _pUserLang->_keywordLists[index], max_char); +} + +BOOL CALLBACK SharedParametersDialog::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam) +{ + switch (Message) + { + case WM_INITDIALOG : + { + initControls(); + return TRUE; + } + + case WM_COMMAND : + { + if (HIWORD(wParam) == EN_CHANGE) + { + setKeywords2List(LOWORD(wParam)); + + if (_pScintilla->getCurrentBuffer()->getLangType() == L_USER) + _pScintilla->styleChange(); + + return TRUE; + } + else if (HIWORD(wParam) == CBN_SELCHANGE) + { + bool isFontSize; + int k = getGroupIndexFromCombo(LOWORD(wParam), isFontSize); + + if (k != -1) + { + int i = ::SendDlgItemMessage(_hSelf, LOWORD(wParam), CB_GETCURSEL, 0, 0); + Style & style = _pUserLang->_styleArray.getStyler(k); + if (isFontSize) + { + TCHAR intStr[5]; + if (i != 0) + { + ::SendDlgItemMessage(_hSelf, LOWORD(wParam), CB_GETLBTEXT, i, (LPARAM)intStr); + if ((!intStr) || (!intStr[0])) + style._fontSize = -1; + else + { + TCHAR *finStr; + style._fontSize = generic_strtol(intStr, &finStr, 10); + if (*finStr != '\0') + style._fontSize = -1; + } + } + } + else + { + style._fontName = (TCHAR *)::SendDlgItemMessage(_hSelf, LOWORD(wParam), CB_GETITEMDATA, i, 0); + } + if (_pScintilla->getCurrentBuffer()->getLangType() == L_USER) + _pScintilla->styleChange(); + return TRUE; + } + } + else if (HIWORD(wParam) == CPN_COLOURPICKED) + { + bool isFG; + ColourPicker *pCP; + int index = getStylerIndexFromCP((HWND)lParam, isFG, &pCP); + if (index != -1) + { + Style & style = _pUserLang->_styleArray.getStyler(index); + if (isFG) { + style._fgColor = pCP->getColour(); + if (pCP->isEnabled()) + style._colorStyle |= COLORSTYLE_FOREGROUND; + else + style._colorStyle &= ~COLORSTYLE_FOREGROUND; + } else { + style._bgColor = pCP->getColour(); + if (pCP->isEnabled()) + style._colorStyle |= COLORSTYLE_BACKGROUND; + else + style._colorStyle &= ~COLORSTYLE_BACKGROUND; + } + } + // A cause de "#define CPN_COLOURPICKED (BN_CLICKED)" + // Nous sommes obligés de mettre ce bloc ici !!! + // A modifier !!! + else + { + int fontStyleMask; + int k = getGroupeIndexFromCheck(wParam, fontStyleMask); + + if (k != -1) + { + Style & style = _pUserLang->_styleArray.getStyler(k); + if (style._fontStyle == -1) + style._fontStyle = 0; + style._fontStyle ^= fontStyleMask; + //::MessageBox(NULL, TEXT("Bingo!!!"), TEXT(""), MB_OK); + } + } + if (_pScintilla->getCurrentBuffer()->getLangType() == L_USER) + _pScintilla->styleChange(); + return TRUE; + } + return FALSE; + } + /* + case WM_SIZE : + { + redraw(); + return TRUE; + } + */ + case WM_DESTROY: + { + for (int i = 0 ; i < _nbGroup ; i++) + { + _pFgColour[i]->destroy(); + _pBgColour[i]->destroy(); + + delete _pFgColour[i]; + delete _pBgColour[i]; + } + return TRUE; + } + } + return FALSE; +} + +void FolderStyleDialog::updateDlg() +{ + ::SendDlgItemMessage(_hSelf, IDC_FOLDEROPEN_EDIT, WM_SETTEXT, 0, (LPARAM)(_pUserLang->_keywordLists[KWL_FOLDER_OPEN_INDEX])); + ::SendDlgItemMessage(_hSelf, IDC_FOLDERCLOSE_EDIT, WM_SETTEXT, 0, (LPARAM)(_pUserLang->_keywordLists[KWL_FOLDER_CLOSE_INDEX])); + + Style & defaultStyle = _pUserLang->_styleArray.getStyler(STYLE_DEFAULT_INDEX); + styleUpdate(defaultStyle, _pFgColour[0], _pBgColour[0], IDC_DEFAULT_FONT_COMBO, IDC_DEFAULT_FONTSIZE_COMBO, + IDC_DEFAULT_BOLD_CHECK, IDC_DEFAULT_ITALIC_CHECK, IDC_DEFAULT_UNDERLINE_CHECK); + + Style & foStyle = _pUserLang->_styleArray.getStyler(STYLE_BLOCK_OPEN_INDEX); + styleUpdate(foStyle, _pFgColour[1], _pBgColour[1], IDC_FOLDEROPEN_FONT_COMBO, IDC_FOLDEROPEN_FONTSIZE_COMBO, + IDC_FOLDEROPEN_BOLD_CHECK, IDC_FOLDEROPEN_ITALIC_CHECK, IDC_FOLDEROPEN_UNDERLINE_CHECK); + + Style & fcStyle = _pUserLang->_styleArray.getStyler(STYLE_BLOCK_CLOSE_INDEX); + styleUpdate(fcStyle, _pFgColour[2], _pBgColour[2], IDC_FOLDERCLOSE_FONT_COMBO, IDC_FOLDERCLOSE_FONTSIZE_COMBO, + IDC_FOLDERCLOSE_BOLD_CHECK, IDC_FOLDERCLOSE_ITALIC_CHECK, IDC_FOLDERCLOSE_UNDERLINE_CHECK); +} + +int FolderStyleDialog::getStylerIndexFromCP(HWND hWnd, bool & isFG, ColourPicker **ppCP) const +{ + for (int i = 0 ; i < _nbGroup ; i++) + { + if (hWnd == _pFgColour[i]->getHSelf()) + { + *ppCP = _pFgColour[i]; + isFG = true; + return i; + } + if (hWnd == _pBgColour[i]->getHSelf()) + { + *ppCP = _pBgColour[i]; + isFG = false; + return i; + } + } + return -1; +} + +int FolderStyleDialog::getGroupeIndexFromCheck(int ctrlID, int & fontStyleMask) const +{ + switch (ctrlID) + { + case IDC_DEFAULT_BOLD_CHECK : + fontStyleMask = FONTSTYLE_BOLD; + return STYLE_DEFAULT_INDEX; + + case IDC_DEFAULT_ITALIC_CHECK : + fontStyleMask = FONTSTYLE_ITALIC; + return STYLE_DEFAULT_INDEX; + + case IDC_DEFAULT_UNDERLINE_CHECK : + fontStyleMask = FONTSTYLE_UNDERLINE; + return STYLE_DEFAULT_INDEX; + + case IDC_FOLDEROPEN_BOLD_CHECK : + fontStyleMask = FONTSTYLE_BOLD; + return STYLE_BLOCK_OPEN_INDEX; + + case IDC_FOLDEROPEN_ITALIC_CHECK : + fontStyleMask = FONTSTYLE_ITALIC; + return STYLE_BLOCK_OPEN_INDEX; + + case IDC_FOLDEROPEN_UNDERLINE_CHECK : + fontStyleMask = FONTSTYLE_UNDERLINE; + return STYLE_BLOCK_OPEN_INDEX; + + case IDC_FOLDERCLOSE_BOLD_CHECK : + fontStyleMask = FONTSTYLE_BOLD; + return STYLE_BLOCK_CLOSE_INDEX; + + case IDC_FOLDERCLOSE_ITALIC_CHECK : + fontStyleMask = FONTSTYLE_ITALIC; + return STYLE_BLOCK_CLOSE_INDEX; + + case IDC_FOLDERCLOSE_UNDERLINE_CHECK : + fontStyleMask = FONTSTYLE_UNDERLINE; + return STYLE_BLOCK_CLOSE_INDEX; + + default : + return -1; + } +} + +int fgStatic2[] = {IDC_KEYWORD1_FG_STATIC, IDC_KEYWORD2_FG_STATIC, IDC_KEYWORD3_FG_STATIC, IDC_KEYWORD4_FG_STATIC}; +int bgStatic2[] = {IDC_KEYWORD1_BG_STATIC, IDC_KEYWORD2_BG_STATIC, IDC_KEYWORD3_BG_STATIC, IDC_KEYWORD4_BG_STATIC}; +int fontSizeCombo2[] = {IDC_KEYWORD1_FONTSIZE_COMBO, IDC_KEYWORD2_FONTSIZE_COMBO, IDC_KEYWORD3_FONTSIZE_COMBO, IDC_KEYWORD4_FONTSIZE_COMBO}; +int fontNameCombo2[] = {IDC_KEYWORD1_FONT_COMBO, IDC_KEYWORD2_FONT_COMBO, IDC_KEYWORD3_FONT_COMBO, IDC_KEYWORD4_FONT_COMBO}; + +KeyWordsStyleDialog::KeyWordsStyleDialog() : SharedParametersDialog(4) +{ + memcpy(_fgStatic, fgStatic2, sizeof(fgStatic2)); + memcpy(_bgStatic, bgStatic2, sizeof(bgStatic2)); + memcpy(_fontSizeCombo, fontSizeCombo2, sizeof(fontSizeCombo2)); + memcpy(_fontNameCombo, fontNameCombo2, sizeof(fontNameCombo2)); +} + + +BOOL CALLBACK KeyWordsStyleDialog::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam) +{ + switch (Message) + { + + case WM_COMMAND : + { + switch (wParam) + { + case IDC_KEYWORD1_PREFIX_CHECK : + return setPropertyByCheck(_hSelf, wParam, _pUserLang->_isPrefix[0]); + + case IDC_KEYWORD2_PREFIX_CHECK : + return setPropertyByCheck(_hSelf, wParam, _pUserLang->_isPrefix[1]); + + case IDC_KEYWORD3_PREFIX_CHECK : + return setPropertyByCheck(_hSelf, wParam, _pUserLang->_isPrefix[2]); + + case IDC_KEYWORD4_PREFIX_CHECK : + return setPropertyByCheck(_hSelf, wParam, _pUserLang->_isPrefix[3]); + } + } + default : + return SharedParametersDialog::run_dlgProc(Message, wParam, lParam); + } +} + +void KeyWordsStyleDialog::setKeywords2List(int id) +{ + int index; + switch (id) + { + case IDC_KEYWORD1_EDIT : index = 5; break; + case IDC_KEYWORD2_EDIT : index = 6; break; + case IDC_KEYWORD3_EDIT : index = 7; break; + case IDC_KEYWORD4_EDIT : index = 8; break; + default : index = -1; + } + if (index != -1) + ::GetDlgItemText(_hSelf, id, _pUserLang->_keywordLists[index], max_char); +} + +int KeyWordsStyleDialog::getStylerIndexFromCP(HWND hWnd, bool & isFG, ColourPicker **ppCP) const +{ + for (int i = 0 ; i < _nbGroup ; i++) + { + if (hWnd == _pFgColour[i]->getHSelf()) + { + *ppCP = _pFgColour[i]; + isFG = true; + return i+3; + } + if (hWnd == _pBgColour[i]->getHSelf()) + { + *ppCP = _pBgColour[i]; + isFG = false; + return i+3; + } + } + return -1; +} + +int KeyWordsStyleDialog::getGroupeIndexFromCheck(int ctrlID, int & fontStyleMask) const +{ + switch (ctrlID) + { + case IDC_KEYWORD1_BOLD_CHECK : + fontStyleMask = FONTSTYLE_BOLD; + return STYLE_WORD1_INDEX; + + case IDC_KEYWORD1_ITALIC_CHECK : + fontStyleMask = FONTSTYLE_ITALIC; + return STYLE_WORD1_INDEX; + + case IDC_KEYWORD1_UNDERLINE_CHECK : + fontStyleMask = FONTSTYLE_UNDERLINE; + return STYLE_WORD1_INDEX; + + case IDC_KEYWORD2_BOLD_CHECK : + fontStyleMask = FONTSTYLE_BOLD; + return STYLE_WORD2_INDEX; + + case IDC_KEYWORD2_ITALIC_CHECK : + fontStyleMask = FONTSTYLE_ITALIC; + return STYLE_WORD2_INDEX; + + case IDC_KEYWORD2_UNDERLINE_CHECK : + fontStyleMask = FONTSTYLE_UNDERLINE; + return STYLE_WORD2_INDEX; + + case IDC_KEYWORD3_BOLD_CHECK : + fontStyleMask = FONTSTYLE_BOLD; + return STYLE_WORD3_INDEX; + + case IDC_KEYWORD3_ITALIC_CHECK : + fontStyleMask = FONTSTYLE_ITALIC; + return STYLE_WORD3_INDEX; + + case IDC_KEYWORD3_UNDERLINE_CHECK : + fontStyleMask = FONTSTYLE_UNDERLINE; + return STYLE_WORD3_INDEX; + + case IDC_KEYWORD4_BOLD_CHECK : + fontStyleMask = FONTSTYLE_BOLD; + return STYLE_WORD4_INDEX; + + case IDC_KEYWORD4_ITALIC_CHECK : + fontStyleMask = FONTSTYLE_ITALIC; + return STYLE_WORD4_INDEX; + + case IDC_KEYWORD4_UNDERLINE_CHECK : + fontStyleMask = FONTSTYLE_UNDERLINE; + return STYLE_WORD4_INDEX; + + default : + return -1; + } +} + +void KeyWordsStyleDialog::updateDlg() +{ + ::SendDlgItemMessage(_hSelf, IDC_KEYWORD1_EDIT, WM_SETTEXT, 0, (LPARAM)(_pUserLang->_keywordLists[KWL_KW1_INDEX])); + ::SendDlgItemMessage(_hSelf, IDC_KEYWORD2_EDIT, WM_SETTEXT, 0, (LPARAM)(_pUserLang->_keywordLists[KWL_KW2_INDEX])); + ::SendDlgItemMessage(_hSelf, IDC_KEYWORD3_EDIT, WM_SETTEXT, 0, (LPARAM)(_pUserLang->_keywordLists[KWL_KW3_INDEX])); + ::SendDlgItemMessage(_hSelf, IDC_KEYWORD4_EDIT, WM_SETTEXT, 0, (LPARAM)(_pUserLang->_keywordLists[KWL_KW4_INDEX])); + + Style & w1Style = _pUserLang->_styleArray.getStyler(STYLE_WORD1_INDEX); + styleUpdate(w1Style, _pFgColour[0], _pBgColour[0], IDC_KEYWORD1_FONT_COMBO, IDC_KEYWORD1_FONTSIZE_COMBO, + IDC_KEYWORD1_BOLD_CHECK, IDC_KEYWORD1_ITALIC_CHECK, IDC_KEYWORD1_UNDERLINE_CHECK); + + Style & w2Style = _pUserLang->_styleArray.getStyler(STYLE_WORD2_INDEX); + styleUpdate(w2Style, _pFgColour[1], _pBgColour[1], IDC_KEYWORD2_FONT_COMBO, IDC_KEYWORD2_FONTSIZE_COMBO, + IDC_KEYWORD2_BOLD_CHECK, IDC_KEYWORD2_ITALIC_CHECK, IDC_KEYWORD2_UNDERLINE_CHECK); + + Style & w3Style = _pUserLang->_styleArray.getStyler(STYLE_WORD3_INDEX); + styleUpdate(w3Style, _pFgColour[2], _pBgColour[2], IDC_KEYWORD3_FONT_COMBO, IDC_KEYWORD3_FONTSIZE_COMBO, + IDC_KEYWORD3_BOLD_CHECK, IDC_KEYWORD3_BOLD_CHECK, IDC_KEYWORD3_UNDERLINE_CHECK); + + Style & w4Style = _pUserLang->_styleArray.getStyler(STYLE_WORD4_INDEX); + styleUpdate(w4Style, _pFgColour[3], _pBgColour[3], IDC_KEYWORD4_FONT_COMBO, IDC_KEYWORD4_FONTSIZE_COMBO, + IDC_KEYWORD4_BOLD_CHECK, IDC_KEYWORD4_ITALIC_CHECK, IDC_KEYWORD4_UNDERLINE_CHECK); + + ::SendDlgItemMessage(_hSelf, IDC_KEYWORD1_PREFIX_CHECK, BM_SETCHECK, _pUserLang->_isPrefix[0], 0); + ::SendDlgItemMessage(_hSelf, IDC_KEYWORD2_PREFIX_CHECK, BM_SETCHECK, _pUserLang->_isPrefix[1], 0); + ::SendDlgItemMessage(_hSelf, IDC_KEYWORD3_PREFIX_CHECK, BM_SETCHECK, _pUserLang->_isPrefix[2], 0); + ::SendDlgItemMessage(_hSelf, IDC_KEYWORD4_PREFIX_CHECK, BM_SETCHECK, _pUserLang->_isPrefix[3], 0); +} + +int fgStatic3[] = {IDC_COMMENT_FG_STATIC, IDC_COMMENTLINE_FG_STATIC, IDC_NUMBER_FG_STATIC}; +int bgStatic3[] = {IDC_COMMENT_BG_STATIC, IDC_COMMENTLINE_BG_STATIC, IDC_NUMBER_BG_STATIC}; +int fontSizeCombo3[] = {IDC_COMMENT_FONTSIZE_COMBO, IDC_COMMENTLINE_FONTSIZE_COMBO, IDC_NUMBER_FONTSIZE_COMBO}; +int fontNameCombo3[] = {IDC_COMMENT_FONT_COMBO, IDC_COMMENTLINE_FONT_COMBO, IDC_NUMBER_FONT_COMBO}; + +CommentStyleDialog::CommentStyleDialog() : SharedParametersDialog(3) +{ + memcpy(_fgStatic, fgStatic3, sizeof(fgStatic3)); + memcpy(_bgStatic, bgStatic3, sizeof(bgStatic3)); + memcpy(_fontSizeCombo, fontSizeCombo3, sizeof(fontSizeCombo3)); + memcpy(_fontNameCombo, fontNameCombo3, sizeof(fontNameCombo3)); +} + +BOOL CALLBACK CommentStyleDialog::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam) +{ + switch (Message) + { + case WM_COMMAND : + { + switch (wParam) + { + case IDC_COMMENTLINESYMBOL_CHECK : + return setPropertyByCheck(_hSelf, wParam, _pUserLang->_isCommentLineSymbol);; + + case IDC_COMMENTSYMBOL_CHECK : + return setPropertyByCheck(_hSelf, wParam, _pUserLang->_isCommentSymbol);; + + } + } + default : + return SharedParametersDialog::run_dlgProc(Message, wParam, lParam); + } +} + + +void CommentStyleDialog::setKeywords2List(int id) +{ + int i; + switch (id) + { + case IDC_COMMENTOPEN_EDIT : + case IDC_COMMENTCLOSE_EDIT : + case IDC_COMMENTLINE_EDIT : + i = 4; + break; + default : i = -1; + } + if (i != -1) + { + TCHAR commentOpen[max_char]; + TCHAR commentClose[max_char]; + TCHAR commentLine[max_char]; + TCHAR newList[max_char] = TEXT(""); + ::GetDlgItemText(_hSelf, IDC_COMMENTOPEN_EDIT, commentOpen, max_char); + ::GetDlgItemText(_hSelf, IDC_COMMENTCLOSE_EDIT, commentClose, max_char); + ::GetDlgItemText(_hSelf, IDC_COMMENTLINE_EDIT, commentLine, max_char); + convertTo(newList, commentOpen, '1'); + convertTo(newList, commentClose, '2'); + convertTo(newList, commentLine, '0'); + lstrcpy(_pUserLang->_keywordLists[i], newList); + } +} + +int CommentStyleDialog::getStylerIndexFromCP(HWND hWnd, bool & isFG, ColourPicker **ppCP) const +{ + for (int i = 0 ; i < _nbGroup ; i++) + { + if (hWnd == _pFgColour[i]->getHSelf()) + { + *ppCP = _pFgColour[i]; + isFG = true; + return i+7; + } + if (hWnd == _pBgColour[i]->getHSelf()) + { + *ppCP = _pBgColour[i]; + isFG = false; + return i+7; + } + } + return -1; +} +int CommentStyleDialog::getGroupeIndexFromCheck(int ctrlID, int & fontStyleMask) const +{ + switch (ctrlID) + { + case IDC_COMMENT_BOLD_CHECK : + fontStyleMask = FONTSTYLE_BOLD; + return STYLE_COMMENT_INDEX; + + case IDC_COMMENT_ITALIC_CHECK : + fontStyleMask = FONTSTYLE_ITALIC; + return STYLE_COMMENT_INDEX; + + case IDC_COMMENT_UNDERLINE_CHECK : + fontStyleMask = FONTSTYLE_UNDERLINE; + return STYLE_COMMENT_INDEX; + + case IDC_COMMENTLINE_BOLD_CHECK : + fontStyleMask = FONTSTYLE_BOLD; + return STYLE_COMMENTLINE_INDEX; + + case IDC_COMMENTLINE_ITALIC_CHECK : + fontStyleMask = FONTSTYLE_ITALIC; + return STYLE_COMMENTLINE_INDEX; + + case IDC_COMMENTLINE_UNDERLINE_CHECK : + fontStyleMask = FONTSTYLE_UNDERLINE; + return STYLE_COMMENTLINE_INDEX; + + case IDC_NUMBER_BOLD_CHECK : + fontStyleMask = FONTSTYLE_BOLD; + return STYLE_NUMBER_INDEX; + + case IDC_NUMBER_ITALIC_CHECK : + fontStyleMask = FONTSTYLE_ITALIC; + return STYLE_NUMBER_INDEX; + + case IDC_NUMBER_UNDERLINE_CHECK : + fontStyleMask = FONTSTYLE_UNDERLINE; + return STYLE_NUMBER_INDEX; + + default : + return -1; + } +} + +void CommentStyleDialog::convertTo(TCHAR *dest, const TCHAR *toConvert, TCHAR prefix) const +{ + int index = lstrlen(dest); + dest[index++] = ' '; + dest[index++] = prefix; + for (int i = 0 ; i < int(lstrlen(toConvert)) ; i++) + { + if (toConvert[i] == ' ') + { + if (toConvert[i+1] != ' ') + { + dest[index++] = ' '; + dest[index++] = prefix; + } + } + else + { + dest[index++] = toConvert[i]; + } + } + dest[index] = '\0'; +} + +void CommentStyleDialog::retrieve(TCHAR *dest, const TCHAR *toRetrieve, TCHAR prefix) const +{ + int j = 0; + bool begin2Copy = false; + + for (int i = 0 ; i < int(lstrlen(toRetrieve)) ; i++) + { + if (((i == 0) || toRetrieve[i-1] == ' ') && (toRetrieve[i] == prefix)) + { + begin2Copy = true; + continue; + } + else if (((toRetrieve[i] == ' ') && begin2Copy == true)) + { + dest[j++] = toRetrieve[i]; + begin2Copy = false; + } + if (begin2Copy) + dest[j++] = toRetrieve[i]; + } + dest[j++] = '\0'; +} + +void CommentStyleDialog::updateDlg() +{ + TCHAR commentOpen[256] = TEXT(""); + TCHAR commentClose[256] = TEXT(""); + TCHAR commentLine[256] = TEXT(""); + + retrieve(commentOpen, _pUserLang->_keywordLists[KWL_COMMENT_INDEX], '1'); + retrieve(commentClose, _pUserLang->_keywordLists[KWL_COMMENT_INDEX], '2'); + retrieve(commentLine, _pUserLang->_keywordLists[KWL_COMMENT_INDEX], '0'); + + ::SendDlgItemMessage(_hSelf, IDC_COMMENTOPEN_EDIT, WM_SETTEXT, 0, (LPARAM)commentOpen); + ::SendDlgItemMessage(_hSelf, IDC_COMMENTCLOSE_EDIT, WM_SETTEXT, 0, (LPARAM)commentClose); + ::SendDlgItemMessage(_hSelf, IDC_COMMENTLINE_EDIT, WM_SETTEXT, 0, (LPARAM)commentLine); + + Style & commentStyle = _pUserLang->_styleArray.getStyler(STYLE_COMMENT_INDEX); + styleUpdate(commentStyle, _pFgColour[0], _pBgColour[0], IDC_COMMENT_FONT_COMBO, IDC_COMMENT_FONTSIZE_COMBO, + IDC_COMMENT_BOLD_CHECK, IDC_COMMENT_ITALIC_CHECK, IDC_COMMENT_UNDERLINE_CHECK); + + Style & commentLineStyle = _pUserLang->_styleArray.getStyler(STYLE_COMMENTLINE_INDEX); + styleUpdate(commentLineStyle, _pFgColour[1], _pBgColour[1], IDC_COMMENTLINE_FONT_COMBO, IDC_COMMENTLINE_FONTSIZE_COMBO, + IDC_COMMENTLINE_BOLD_CHECK, IDC_COMMENTLINE_ITALIC_CHECK, IDC_COMMENTLINE_UNDERLINE_CHECK); + + Style & numberStyle = _pUserLang->_styleArray.getStyler(STYLE_NUMBER_INDEX); + styleUpdate(numberStyle, _pFgColour[2], _pBgColour[2], IDC_NUMBER_FONT_COMBO, IDC_NUMBER_FONTSIZE_COMBO, + IDC_NUMBER_BOLD_CHECK, IDC_NUMBER_ITALIC_CHECK, IDC_NUMBER_UNDERLINE_CHECK); + + ::SendDlgItemMessage(_hSelf, IDC_COMMENTLINESYMBOL_CHECK, BM_SETCHECK, _pUserLang->_isCommentLineSymbol, 0); + ::SendDlgItemMessage(_hSelf, IDC_COMMENTSYMBOL_CHECK, BM_SETCHECK, _pUserLang->_isCommentSymbol, 0); +} + +TCHAR symbolesArray[] = TEXT("+-*/.?!:;,%^$&\"'(_)=}]@\\`|[{#~<>"); +const bool SymbolsStyleDialog::ADD = true; +const bool SymbolsStyleDialog::REMOVE = false; + +int fgStatic4[] = {IDC_SYMBOL_FG_STATIC, IDC_SYMBOL_FG2_STATIC, IDC_SYMBOL_FG3_STATIC}; +int bgStatic4[] = {IDC_SYMBOL_BG_STATIC, IDC_SYMBOL_BG2_STATIC, IDC_SYMBOL_BG3_STATIC}; +int fontSizeCombo4[] = {IDC_SYMBOL_FONTSIZE_COMBO, IDC_SYMBOL_FONTSIZE2_COMBO, IDC_SYMBOL_FONTSIZE3_COMBO}; +int fontNameCombo4[] = {IDC_SYMBOL_FONT_COMBO, IDC_SYMBOL_FONT2_COMBO, IDC_SYMBOL_FONT3_COMBO}; + +// 2 static const TCHAR * to have the compatibility with the old xml +const TCHAR *SymbolsStyleDialog::_delimTag1 = TEXT("DELIMINER1"); +const TCHAR *SymbolsStyleDialog::_delimTag2 = TEXT("DELIMINER2"); + +SymbolsStyleDialog::SymbolsStyleDialog() : SharedParametersDialog(3) +{ + memcpy(_fgStatic, fgStatic4, sizeof(fgStatic4)); + memcpy(_bgStatic, bgStatic4, sizeof(bgStatic4)); + memcpy(_fontSizeCombo, fontSizeCombo4, sizeof(fontSizeCombo4)); + memcpy(_fontNameCombo, fontNameCombo4, sizeof(fontNameCombo4)); +} + +int SymbolsStyleDialog::getStylerIndexFromCP(HWND hWnd, bool & isFG, ColourPicker **ppCP) const +{ + for (int i = 0 ; i < _nbGroup ; i++) + { + if (hWnd == _pFgColour[i]->getHSelf()) + { + *ppCP = _pFgColour[i]; + isFG = true; + return i+10; + } + if (hWnd == _pBgColour[i]->getHSelf()) + { + *ppCP = _pBgColour[i]; + isFG = false; + return i+10; + } + } + return -1; +} +void SymbolsStyleDialog::symbolAction(bool action) +{ + int id2Add, id2Remove; + int idButton2Disable, idButton2Enable; + if (action == ADD) + { + id2Add = IDC_ACTIVATED_SYMBOL_LIST; + id2Remove = IDC_AVAILABLE_SYMBOLS_LIST; + idButton2Enable = IDC_REMOVE_BUTTON; + idButton2Disable = IDC_ADD_BUTTON; + + } + else + { + id2Add = IDC_AVAILABLE_SYMBOLS_LIST; + id2Remove = IDC_ACTIVATED_SYMBOL_LIST; + idButton2Enable = IDC_ADD_BUTTON; + idButton2Disable = IDC_REMOVE_BUTTON; + } + int i = ::SendDlgItemMessage(_hSelf, id2Remove, LB_GETCURSEL, 0, 0); + TCHAR s[2]; + ::SendDlgItemMessage(_hSelf, id2Remove, LB_GETTEXT, i, (LPARAM)s); + + ::SendDlgItemMessage(_hSelf, id2Add, LB_ADDSTRING, 0, (LPARAM)s); + ::SendDlgItemMessage(_hSelf, id2Remove, LB_DELETESTRING, i, 0); + int count = ::SendDlgItemMessage(_hSelf, id2Remove, LB_GETCOUNT, 0, 0); + if (i == count) + i -= 1; + + ::SendDlgItemMessage(_hSelf, id2Remove, LB_SETCURSEL, i, 0); + count = ::SendDlgItemMessage(_hSelf, id2Remove, LB_GETCOUNT, 0, 0); + + // If there's no symbol, we activate another side + if (!count) + { + ::SendDlgItemMessage(_hSelf, id2Add, LB_SETCURSEL, 0, 0); + ::EnableWindow(::GetDlgItem(_hSelf, idButton2Enable), TRUE); + ::EnableWindow(::GetDlgItem(_hSelf, idButton2Disable), FALSE); + } + + // Get the operators list + count = ::SendDlgItemMessage(_hSelf, IDC_ACTIVATED_SYMBOL_LIST, LB_GETCOUNT, 0, 0); + + int j = 0; + for (int i = 0 ; i < count ; i++) + { + ::SendDlgItemMessage(_hSelf, IDC_ACTIVATED_SYMBOL_LIST, LB_GETTEXT, i, (LPARAM)s); + _pUserLang->_keywordLists[3][j++] = s[0]; + _pUserLang->_keywordLists[3][j++] = ' '; + } + _pUserLang->_keywordLists[3][--j] = '\0'; + + if (_pScintilla->getCurrentBuffer()->getLangType() == L_USER) + _pScintilla->styleChange(); +} + +void SymbolsStyleDialog::listboxsRemoveAll() +{ + int count = ::SendDlgItemMessage(_hSelf, IDC_AVAILABLE_SYMBOLS_LIST, LB_GETCOUNT, 0, 0); + for (int i = count-1 ; i >= 0 ; i--) + { + ::SendDlgItemMessage(_hSelf, IDC_AVAILABLE_SYMBOLS_LIST, LB_DELETESTRING, i, 0); + } + count = ::SendDlgItemMessage(_hSelf, IDC_ACTIVATED_SYMBOL_LIST, LB_GETCOUNT, 0, 0); + for (int i = count-1 ; i >= 0 ; i--) + { + ::SendDlgItemMessage(_hSelf, IDC_ACTIVATED_SYMBOL_LIST, LB_DELETESTRING, i, 0); + } +} +void SymbolsStyleDialog::updateDlg() +{ + listboxsReInit(); + + const TCHAR *symbols = _pUserLang->_keywordLists[KWL_OPERATOR_INDEX]; + + for (int i = 0 ; i < int(lstrlen(symbols)) ; i++) + { + if (symbols[i] != ' ') + { + TCHAR s[2]; + s[0] = symbols[i]; + s[1] = '\0'; + int index = ::SendDlgItemMessage(_hSelf, IDC_AVAILABLE_SYMBOLS_LIST, LB_FINDSTRING, (WPARAM)-1, (LPARAM)s); + if (index == LB_ERR) + continue; + + int id2Add = IDC_ACTIVATED_SYMBOL_LIST; + int id2Remove = IDC_AVAILABLE_SYMBOLS_LIST; + int idButton2Enable = IDC_REMOVE_BUTTON; + int idButton2Disable = IDC_ADD_BUTTON; + + ::SendDlgItemMessage(_hSelf, id2Add, LB_ADDSTRING, 0, (LPARAM)s); + ::SendDlgItemMessage(_hSelf, id2Remove, LB_DELETESTRING, index, 0); + int count = ::SendDlgItemMessage(_hSelf, id2Remove, LB_GETCOUNT, 0, 0); + if (index == count) + index -= 1; + + ::SendDlgItemMessage(_hSelf, id2Remove, LB_SETCURSEL, index, 0); + count = ::SendDlgItemMessage(_hSelf, id2Remove, LB_GETCOUNT, 0, 0); + + // If there's no symbol, we activate another side + if (!count) + { + ::SendDlgItemMessage(_hSelf, id2Add, LB_SETCURSEL, 0, 0); + ::EnableWindow(::GetDlgItem(_hSelf, idButton2Enable), TRUE); + ::EnableWindow(::GetDlgItem(_hSelf, idButton2Disable), FALSE); + } + } + } + + const TCHAR *delims = _pUserLang->_keywordLists[KWL_DELIM_INDEX]; + // ICI LE TRAITEMENT POUR REMPLIR LES 4 COMBO BOX + TCHAR dOpen1[2], dClose1[2], dOpen2[2], dClose2[2], dOpen3[2], dClose3[2]; + dOpen1[0] = dClose1[0] = dOpen2[0] = dClose2[0] = dOpen3[0] = dClose3[0] = '\0'; + dOpen1[1] = dClose1[1] = dOpen2[1] = dClose2[1] = dOpen3[1] = dClose3[1] = '\0'; + if (lstrlen(delims) >= 6) + { + if (delims[0] != '0') + dOpen1[0] = delims[0]; + + int i = ::SendDlgItemMessage(_hSelf, IDC_SYMBOL_BO2_COMBO, CB_FINDSTRINGEXACT, (WPARAM)-1, (LPARAM)dOpen1); + if (i == CB_ERR) + i = 0; + ::SendDlgItemMessage(_hSelf, IDC_SYMBOL_BO2_COMBO,CB_SETCURSEL, i, 0); + + if (delims[1] != '0') + dOpen2[0] = delims[1]; + + i = ::SendDlgItemMessage(_hSelf, IDC_SYMBOL_BO3_COMBO, CB_FINDSTRINGEXACT, (WPARAM)-1, (LPARAM)dOpen2); + if (i == CB_ERR) + i = 0; + ::SendDlgItemMessage(_hSelf, IDC_SYMBOL_BO3_COMBO,CB_SETCURSEL, i, 0); + + //if (delims[2] != '0') + //dOpen3 = delims[2]; + if (delims[3] != '0') + dClose1[0] = delims[3]; + + i = ::SendDlgItemMessage(_hSelf, IDC_SYMBOL_BC2_COMBO, CB_FINDSTRINGEXACT, (WPARAM)-1, (LPARAM)dClose1); + if (i == CB_ERR) + i = 0; + ::SendDlgItemMessage(_hSelf, IDC_SYMBOL_BC2_COMBO,CB_SETCURSEL, i, 0); + + if (delims[4] != '0') + dClose2[0] = delims[4]; + + i = ::SendDlgItemMessage(_hSelf, IDC_SYMBOL_BC3_COMBO, CB_FINDSTRINGEXACT, (WPARAM)-1, (LPARAM)dClose2); + if (i == CB_ERR) + i = 0; + ::SendDlgItemMessage(_hSelf, IDC_SYMBOL_BC3_COMBO,CB_SETCURSEL, i, 0); + //if (delims[5] != '0') + //dClose3 = delims[5]; + } + + + Style & opStyle = _pUserLang->_styleArray.getStyler(STYLE_OPERATOR_INDEX); + + styleUpdate(opStyle, _pFgColour[0], _pBgColour[0], IDC_SYMBOL_FONT_COMBO, IDC_SYMBOL_FONTSIZE_COMBO, + IDC_SYMBOL_BOLD_CHECK, IDC_SYMBOL_ITALIC_CHECK, IDC_SYMBOL_UNDERLINE_CHECK); + + Style & delim2Style = _pUserLang->_styleArray.getStyler(STYLE_DELIM2_INDEX); + + // the compatibility with the old xml + if (delim2Style._styleID = -1) + { + delim2Style._styleID = SCE_USER_DELIMITER1; + delim2Style._styleDesc = SymbolsStyleDialog::_delimTag1; + } + styleUpdate(delim2Style, _pFgColour[1], _pBgColour[1], IDC_SYMBOL_FONT2_COMBO, IDC_SYMBOL_FONTSIZE2_COMBO, + IDC_SYMBOL_BOLD2_CHECK, IDC_SYMBOL_ITALIC2_CHECK, IDC_SYMBOL_UNDERLINE2_CHECK); + + Style & delim3Style = _pUserLang->_styleArray.getStyler(STYLE_DELIM3_INDEX); + + // the compatibility with the old xml + if (delim3Style._styleID = -1) + { + delim3Style._styleID = SCE_USER_DELIMITER2; + delim3Style._styleDesc = SymbolsStyleDialog::_delimTag2; + } + styleUpdate(delim3Style, _pFgColour[2], _pBgColour[2], IDC_SYMBOL_FONT3_COMBO, IDC_SYMBOL_FONTSIZE3_COMBO, + IDC_SYMBOL_BOLD3_CHECK, IDC_SYMBOL_ITALIC3_CHECK, IDC_SYMBOL_UNDERLINE3_CHECK); + + // the compatibility with the old xml + if (_pUserLang->_styleArray.getNbStyler() < 13) + _pUserLang->_styleArray.setNbStyler(13); +} + +void SymbolsStyleDialog::listboxsInit() +{ + ::SendDlgItemMessage(_hSelf, IDC_SYMBOL_BO2_COMBO, CB_ADDSTRING, 0, (LPARAM)TEXT("")); + ::SendDlgItemMessage(_hSelf, IDC_SYMBOL_BC2_COMBO, CB_ADDSTRING, 0, (LPARAM)TEXT("")); + ::SendDlgItemMessage(_hSelf, IDC_SYMBOL_BO3_COMBO, CB_ADDSTRING, 0, (LPARAM)TEXT("")); + ::SendDlgItemMessage(_hSelf, IDC_SYMBOL_BC3_COMBO, CB_ADDSTRING, 0, (LPARAM)TEXT("")); + + for (int i = 0 ; i < int((sizeof(symbolesArray)/sizeof(TCHAR))-1) ; i++) + { + TCHAR s[2]; + s[0] = symbolesArray[i]; + s[1] = '\0'; + ::SendDlgItemMessage(_hSelf, IDC_AVAILABLE_SYMBOLS_LIST, LB_ADDSTRING, 0, (LPARAM)s); + ::SendDlgItemMessage(_hSelf, IDC_SYMBOL_BO2_COMBO, CB_ADDSTRING, 0, (LPARAM)s); + ::SendDlgItemMessage(_hSelf, IDC_SYMBOL_BC2_COMBO, CB_ADDSTRING, 0, (LPARAM)s); + ::SendDlgItemMessage(_hSelf, IDC_SYMBOL_BO3_COMBO, CB_ADDSTRING, 0, (LPARAM)s); + ::SendDlgItemMessage(_hSelf, IDC_SYMBOL_BC3_COMBO, CB_ADDSTRING, 0, (LPARAM)s); + } +} + +BOOL CALLBACK SymbolsStyleDialog::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam) +{ + switch (Message) + { + case WM_INITDIALOG : + { + // 2 listBoxes et 4 combobox + listboxsInit(); + + ::SendDlgItemMessage(_hSelf, IDC_AVAILABLE_SYMBOLS_LIST, LB_SETCURSEL, 0, 0); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_REMOVE_BUTTON), FALSE); + + return SharedParametersDialog::run_dlgProc(Message, wParam, lParam); + } + + case WM_COMMAND : + { + //int toto = HIWORD(wParam); + if ((wParam == IDC_ADD_BUTTON) || (wParam == IDC_REMOVE_BUTTON)) + { + symbolAction((wParam == IDC_ADD_BUTTON)?ADD:REMOVE); + if (_pScintilla->getCurrentBuffer()->getLangType() == L_USER) + _pScintilla->styleChange(); + return TRUE; + } + // car LBN_SELCHANGE == CBN_SELCHANGE == 1 + else if ((HIWORD(wParam) == LBN_SELCHANGE) ||(HIWORD(wParam) == CBN_SELCHANGE)) + { + if ((LOWORD(wParam) == IDC_ACTIVATED_SYMBOL_LIST) || (LOWORD(wParam) == IDC_AVAILABLE_SYMBOLS_LIST)) + { + int idButton2Enable; + int idButton2Disable; + + if (LOWORD(wParam) == IDC_AVAILABLE_SYMBOLS_LIST) + { + idButton2Enable = IDC_ADD_BUTTON; + idButton2Disable = IDC_REMOVE_BUTTON; + } + else + { + idButton2Enable = IDC_REMOVE_BUTTON; + idButton2Disable = IDC_ADD_BUTTON; + } + + int i = ::SendDlgItemMessage(_hSelf, LOWORD(wParam), LB_GETCURSEL, 0, 0); + if (i != LB_ERR) + { + ::EnableWindow(::GetDlgItem(_hSelf, idButton2Enable), TRUE); + int idListbox2Disable = (LOWORD(wParam)== IDC_AVAILABLE_SYMBOLS_LIST)?IDC_ACTIVATED_SYMBOL_LIST:IDC_AVAILABLE_SYMBOLS_LIST; + ::SendDlgItemMessage(_hSelf, idListbox2Disable, LB_SETCURSEL, (WPARAM)-1, 0); + ::EnableWindow(::GetDlgItem(_hSelf, idButton2Disable), FALSE); + } + return TRUE; + } + else if ((LOWORD(wParam) == IDC_SYMBOL_BO2_COMBO) || (LOWORD(wParam) == IDC_SYMBOL_BC2_COMBO) || + (LOWORD(wParam) == IDC_SYMBOL_BO3_COMBO) || (LOWORD(wParam) == IDC_SYMBOL_BC3_COMBO)) + { + TCHAR charStr[5] = TEXT(""); + int i = ::SendDlgItemMessage(_hSelf, LOWORD(wParam), CB_GETCURSEL, 0, 0); + ::SendDlgItemMessage(_hSelf, LOWORD(wParam), CB_GETLBTEXT, i, (LPARAM)charStr); + int symbIndex; + + if (LOWORD(wParam) == IDC_SYMBOL_BO2_COMBO) + symbIndex = 0; + else if (LOWORD(wParam) == IDC_SYMBOL_BO3_COMBO) + symbIndex = 1; + else if (LOWORD(wParam) == IDC_SYMBOL_BC2_COMBO) + symbIndex = 3; + else // (LOWORD(wParam) == IDC_SYMBOL_BC3_COMBO) + symbIndex = 4; + + TCHAR *delims = _pUserLang->_keywordLists[KWL_DELIM_INDEX]; + delims[symbIndex] = charStr[0]?charStr[0]:'0'; + + if (_pScintilla->getCurrentBuffer()->getLangType() == L_USER) + _pScintilla->styleChange(); + return TRUE; + } + else + return SharedParametersDialog::run_dlgProc(Message, wParam, lParam); + } + } + default : + return SharedParametersDialog::run_dlgProc(Message, wParam, lParam); + } + return FALSE; +} + +int SymbolsStyleDialog::getGroupeIndexFromCheck(int ctrlID, int & fontStyleMask) const +{ + switch (ctrlID) + { + case IDC_SYMBOL_BOLD_CHECK : + { + fontStyleMask = FONTSTYLE_BOLD; + return STYLE_OPERATOR_INDEX; + } + case IDC_SYMBOL_ITALIC_CHECK : + { + fontStyleMask = FONTSTYLE_ITALIC; + return STYLE_OPERATOR_INDEX; + } + case IDC_SYMBOL_UNDERLINE_CHECK : + { + fontStyleMask = FONTSTYLE_UNDERLINE; + return STYLE_OPERATOR_INDEX; + } + + case IDC_SYMBOL_BOLD2_CHECK : + { + fontStyleMask = FONTSTYLE_BOLD; + return STYLE_DELIM2_INDEX; + } + case IDC_SYMBOL_ITALIC2_CHECK : + { + fontStyleMask = FONTSTYLE_ITALIC; + return STYLE_DELIM2_INDEX; + } + case IDC_SYMBOL_UNDERLINE2_CHECK : + { + fontStyleMask = FONTSTYLE_UNDERLINE; + return STYLE_DELIM2_INDEX; + } + + case IDC_SYMBOL_BOLD3_CHECK : + { + fontStyleMask = FONTSTYLE_BOLD; + return STYLE_DELIM3_INDEX; + } + case IDC_SYMBOL_ITALIC3_CHECK : + { + fontStyleMask = FONTSTYLE_ITALIC; + return STYLE_DELIM3_INDEX; + } + case IDC_SYMBOL_UNDERLINE3_CHECK : + { + fontStyleMask = FONTSTYLE_UNDERLINE; + return STYLE_DELIM3_INDEX; + } + + default : + return -1; + } +} + +TCHAR styleName[][32] = {TEXT("DEFAULT"), TEXT("FOLDEROPEN"), TEXT("FOLDERCLOSE"), TEXT("KEYWORD1"), TEXT("KEYWORD2"), TEXT("KEYWORD3"), TEXT("KEYWORD4"), TEXT("COMMENT"), TEXT("COMMENT LINE"), TEXT("NUMBER"), TEXT("OPERATOR"), TEXT("DELIMINER1"), TEXT("DELIMINER2"), TEXT("DELIMINER3")}; + + +UserDefineDialog::UserDefineDialog(): SharedParametersDialog(), _status(UNDOCK), _yScrollPos(0), _prevHightVal(0), _isDirty(false) +{ + _pCurrentUserLang = new UserLangContainer(); + + // @REF #01 NE CHANGER PAS D'ORDRE !!! + _pCurrentUserLang->_styleArray.addStyler(SCE_USER_IDENTIFIER, styleName[0]); + _pCurrentUserLang->_styleArray.addStyler(SCE_USER_BLOCK_OPERATOR_OPEN, styleName[1]); + _pCurrentUserLang->_styleArray.addStyler(SCE_USER_BLOCK_OPERATOR_CLOSE, styleName[2]); + _pCurrentUserLang->_styleArray.addStyler(SCE_USER_WORD1, styleName[3]); + _pCurrentUserLang->_styleArray.addStyler(SCE_USER_WORD2, styleName[4]); + _pCurrentUserLang->_styleArray.addStyler(SCE_USER_WORD3, styleName[5]); + _pCurrentUserLang->_styleArray.addStyler(SCE_USER_WORD4, styleName[6]); + _pCurrentUserLang->_styleArray.addStyler(SCE_USER_COMMENT, styleName[7]); + _pCurrentUserLang->_styleArray.addStyler(SCE_USER_COMMENTLINE, styleName[8]); + _pCurrentUserLang->_styleArray.addStyler(SCE_USER_NUMBER, styleName[9]); + _pCurrentUserLang->_styleArray.addStyler(SCE_USER_OPERATOR, styleName[10]); + _pCurrentUserLang->_styleArray.addStyler(SCE_USER_DELIMITER1, styleName[11]); + _pCurrentUserLang->_styleArray.addStyler(SCE_USER_DELIMITER2, styleName[12]); + _pCurrentUserLang->_styleArray.addStyler(SCE_USER_DELIMITER3, styleName[13]); +} + +UserDefineDialog::~UserDefineDialog() +{ + delete _pCurrentUserLang; +} + +void UserDefineDialog::changeStyle() +{ + display(false); + _status = !_status; + ::SetDlgItemText(_hSelf, IDC_DOCK_BUTTON, (_status == DOCK)?TEXT("Undock"):TEXT("Dock")); + + long style = ::GetWindowLongPtr(_hSelf, GWL_STYLE); + if (!style) + ::MessageBox(NULL, TEXT("echou GetWindowLongPtr"), TEXT(""), MB_OK); + + style = (_status == DOCK)? + ((style & ~WS_POPUP) & ~DS_MODALFRAME & ~WS_CAPTION) | WS_CHILD : + (style & ~WS_CHILD) | WS_POPUP | DS_MODALFRAME | WS_CAPTION; + + long result = ::SetWindowLongPtr(_hSelf, GWL_STYLE, style); + if (!result) + ::MessageBox(NULL, TEXT("echou SetWindowLongPtr"), TEXT(""), MB_OK); + + if (_status == DOCK) + getActualPosSize(); + else + restorePosSize(); + + ::SetWindowPos(_hSelf, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOOWNERZORDER | SWP_FRAMECHANGED | SWP_NOREPOSITION); + ::SetParent(_hSelf, (_status == DOCK)?_hParent:NULL); +} + +void UserDefineDialog::enableLangAndControlsBy(int index) +{ + _pUserLang = (index == 0)?_pCurrentUserLang:&((NppParameters::getInstance())->getULCFromIndex(index - 1)); + if (index != 0) + ::SetWindowText(::GetDlgItem(_hSelf, IDC_EXT_EDIT), _pUserLang->_ext.c_str()); + + ::ShowWindow(::GetDlgItem(_hSelf, IDC_EXT_STATIC), (index == 0)?SW_HIDE:SW_SHOW); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_EXT_EDIT), (index == 0)?SW_HIDE:SW_SHOW); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_RENAME_BUTTON), (index == 0)?SW_HIDE:SW_SHOW); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_REMOVELANG_BUTTON), (index == 0)?SW_HIDE:SW_SHOW); +} + +void UserDefineDialog::updateDlg() +{ + if (!_isDirty) + { + int i = ::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_GETCURSEL, 0, 0); + if (i > 0) + _isDirty = true; + } + ::SendDlgItemMessage(_hSelf, IDC_LANGNAME_IGNORECASE_CHECK, BM_SETCHECK, _pUserLang->_isCaseIgnored, 0); + _folderStyleDlg.updateDlg(); + _keyWordsStyleDlg.updateDlg(); + _commentStyleDlg.updateDlg(); + _symbolsStyleDlg.updateDlg(); +} + +BOOL CALLBACK UserDefineDialog::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) +{ + NppParameters *pNppParam = NppParameters::getInstance(); + switch (message) + { + case WM_INITDIALOG : + { + _ctrlTab.init(_hInst, _hSelf, false); + _ctrlTab.setFont(TEXT("Tahoma"), 13); + + _folderStyleDlg.init(_hInst, _hSelf); + _folderStyleDlg.create(IDD_FOLDER_STYLE_DLG); + _folderStyleDlg.display(); + + _keyWordsStyleDlg.init(_hInst, _hSelf); + _keyWordsStyleDlg.create(IDD_KEYWORD_STYLE_DLG); + _keyWordsStyleDlg.display(false); + + _commentStyleDlg.init(_hInst, _hSelf); + _commentStyleDlg.create(IDD_COMMENT_STYLE_DLG); + _commentStyleDlg.display(false); + + _symbolsStyleDlg.init(_hInst, _hSelf); + _symbolsStyleDlg.create(IDD_SYMBOL_STYLE_DLG); + _symbolsStyleDlg.display(false); + + _wVector.push_back(DlgInfo(&_folderStyleDlg, TEXT("Folder && Default"))); + _wVector.push_back(DlgInfo(&_keyWordsStyleDlg, TEXT("Keywords Lists"))); + _wVector.push_back(DlgInfo(&_commentStyleDlg, TEXT("Comment && Number"))); + _wVector.push_back(DlgInfo(&_symbolsStyleDlg, TEXT("Operators"))); + + _ctrlTab.createTabs(_wVector); + _ctrlTab.display(); + + RECT arc; + ::GetWindowRect(::GetDlgItem(_hSelf, IDC_ADDNEW_BUTTON), &arc); + + POINT p; + p.x = arc.left; + p.y = arc.bottom; + ::ScreenToClient(_hSelf, &p); + + RECT rc; + getClientRect(rc); + rc.top = p.y + 10; + rc.bottom -= 100; + _ctrlTab.reSizeTo(rc); + + _folderStyleDlg.reSizeTo(rc); + _keyWordsStyleDlg.reSizeTo(rc); + _commentStyleDlg.reSizeTo(rc); + _symbolsStyleDlg.reSizeTo(rc); + + ::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_ADDSTRING, 0, (LPARAM)TEXT("User Define Language")); + for (int i = 0 ; i < pNppParam->getNbUserLang() ; i++) + { + UserLangContainer & userLangContainer = pNppParam->getULCFromIndex(i); + ::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_ADDSTRING, 0, (LPARAM)userLangContainer.getName()); + } + ::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_SETCURSEL, 0, 0); + enableLangAndControlsBy(0); + + _pUserLang = _pCurrentUserLang; + + if (pNppParam->isTransparentAvailable()) + { + ::ShowWindow(::GetDlgItem(_hSelf, IDC_UD_TRANSPARENT_CHECK), SW_SHOW); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_UD_PERCENTAGE_SLIDER), SW_SHOW); + + ::SendDlgItemMessage(_hSelf, IDC_UD_PERCENTAGE_SLIDER, TBM_SETRANGE, FALSE, MAKELONG(20, 200)); + ::SendDlgItemMessage(_hSelf, IDC_UD_PERCENTAGE_SLIDER, TBM_SETPOS, TRUE, 150); + if (!(BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_UD_PERCENTAGE_SLIDER, BM_GETCHECK, 0, 0))) + ::EnableWindow(::GetDlgItem(_hSelf, IDC_UD_PERCENTAGE_SLIDER), FALSE); + } + SCROLLINFO si; + si.cbSize = sizeof(si); + si.fMask = SIF_RANGE; //| SIF_PAGE; + si.nMin = 0; + si.nMax = 0; + //si.nPage = _currentHight; + //si.nPos = 0; + ::SetScrollInfo(_hSelf, SB_VERT, &si, TRUE); + + ETDTProc enableDlgTheme = (ETDTProc)pNppParam->getEnableThemeDlgTexture(); + if (enableDlgTheme) + { + //enableDlgTheme(_hSelf, ETDT_ENABLETAB); + } + + return TRUE; + } + + case WM_NOTIFY : + { + NMHDR *nmhdr = (NMHDR *)lParam; + if (nmhdr->code == TCN_SELCHANGE) + { + if (nmhdr->hwndFrom == _ctrlTab.getHSelf()) + { + _ctrlTab.clickedUpdate(); + return TRUE; + } + } + break; + } + + case WM_HSCROLL : + { + if ((HWND)lParam == ::GetDlgItem(_hSelf, IDC_UD_PERCENTAGE_SLIDER)) + { + int percent = ::SendDlgItemMessage(_hSelf, IDC_UD_PERCENTAGE_SLIDER, TBM_GETPOS, 0, 0); + pNppParam->SetTransparent(_hSelf, percent/*HIWORD(wParam)*/); + } + return TRUE; + } + + case WM_COMMAND : + { + if (HIWORD(wParam) == EN_CHANGE) + { + TCHAR ext[extsLenMax]; + ::SendDlgItemMessage(_hSelf, IDC_EXT_EDIT, WM_GETTEXT, extsLenMax, (LPARAM)ext); + _pUserLang->_ext = ext; + return TRUE; + } + else if (HIWORD(wParam) == CBN_SELCHANGE) + { + if (LOWORD(wParam) == IDC_LANGNAME_COMBO) + { + int i = ::SendDlgItemMessage(_hSelf, LOWORD(wParam), CB_GETCURSEL, 0, 0); + enableLangAndControlsBy(i); + updateDlg(); + } + return TRUE; + } + else + { + switch (wParam) + { + case IDC_DOCK_BUTTON : + { + int msg = WM_UNDOCK_USERDEFINE_DLG; + + if (_status == UNDOCK) + { + if (pNppParam->isTransparentAvailable()) + { + pNppParam->removeTransparent(_hSelf); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_UD_TRANSPARENT_CHECK), SW_HIDE); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_UD_PERCENTAGE_SLIDER), SW_HIDE); + } + msg = WM_DOCK_USERDEFINE_DLG; + } + + changeStyle(); + + if (_status == UNDOCK) + { + if (pNppParam->isTransparentAvailable()) + { + bool isChecked = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_UD_TRANSPARENT_CHECK, BM_GETCHECK, 0, 0)); + if (isChecked) + { + int percent = ::SendDlgItemMessage(_hSelf, IDC_UD_PERCENTAGE_SLIDER, TBM_GETPOS, 0, 0); + pNppParam->SetTransparent(_hSelf, percent); + } + ::ShowWindow(::GetDlgItem(_hSelf, IDC_UD_TRANSPARENT_CHECK), SW_SHOW); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_UD_PERCENTAGE_SLIDER), SW_SHOW); + } + } + ::SendMessage(_hParent, msg, 0, 0); + return TRUE; + } + case IDCANCEL : + ::SendMessage(_hParent, WM_CLOSE_USERDEFINE_DLG, 0, 0); + display(false); + return TRUE; + + case IDC_REMOVELANG_BUTTON : + { + int result = ::MessageBox(_hSelf, TEXT("Are you sure?"), TEXT("Remove the current language"), MB_YESNO); + if (result == IDYES) + { + int i = ::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_GETCURSEL, 0, 0); + TCHAR langName[256]; + ::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_GETLBTEXT, i, (LPARAM)langName); + + //remove current language from combobox + ::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_DELETESTRING, i, 0); + ::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_SETCURSEL, i-1, 0); + ::SendMessage(_hSelf, WM_COMMAND, MAKELONG(IDC_LANGNAME_COMBO, CBN_SELCHANGE), (LPARAM)::GetDlgItem(_hSelf, IDC_LANGNAME_COMBO)); + + //remove current language from userLangArray + pNppParam->removeUserLang(i-1); + + //remove current language from langMenu + HWND hNpp = ::GetParent(_hSelf); + ::RemoveMenu(::GetSubMenu((HMENU)::SendMessage(hNpp, NPPM_INTERNAL_GETMENU, 0, 0), MENUINDEX_LANGUAGE), IDM_LANG_USER + i, MF_BYCOMMAND); + ::DrawMenuBar(hNpp); + ::SendMessage(_hParent, WM_REMOVE_USERLANG, 0, (LPARAM)langName); + } + return TRUE; + } + case IDC_RENAME_BUTTON : + { + TCHAR langName[256]; + int i = ::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_GETCURSEL, 0, 0); + ::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_GETLBTEXT, i, (LPARAM)langName); + + StringDlg strDlg; + strDlg.init(_hInst, _hSelf, TEXT("Rename Current Language Name"), TEXT("Name : "), langName, langNameLenMax-1); + + TCHAR *newName = (TCHAR *)strDlg.doDialog(); + + if (newName) + { + if (pNppParam->isExistingUserLangName(newName)) + { + ::MessageBox(_hSelf, TEXT("This name is used by another language,\rplease give another one."), TEXT("Err"), MB_OK); + ::PostMessage(_hSelf, WM_COMMAND, IDC_RENAME_BUTTON, 0); + return TRUE; + } + //rename current language name in combobox + ::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_DELETESTRING, i, 0); + ::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_INSERTSTRING, i, (LPARAM)newName); + ::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_SETCURSEL, i, 0); + + //rename current language name in userLangArray + UserLangContainer & userLangContainer = pNppParam->getULCFromIndex(i-1); + userLangContainer._name = newName; + + //rename current language name in langMenu + HWND hNpp = ::GetParent(_hSelf); + ::ModifyMenu(::GetSubMenu((HMENU)::SendMessage(hNpp, NPPM_INTERNAL_GETMENU, 0, 0), MENUINDEX_LANGUAGE), IDM_LANG_USER + i, MF_BYCOMMAND, IDM_LANG_USER + i, newName); + ::DrawMenuBar(hNpp); + ::SendMessage(_hParent, WM_RENAME_USERLANG, (WPARAM)newName, (LPARAM)langName); + } + + return TRUE; + } + + case IDC_ADDNEW_BUTTON : + case IDC_SAVEAS_BUTTON : + { + //TCHAR langName[256]; + int i = ::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_GETCURSEL, 0, 0); + //::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_GETLBTEXT, i, (LPARAM)langName); + if (i == 0) + wParam = IDC_ADDNEW_BUTTON; + + StringDlg strDlg; + if (wParam == IDC_SAVEAS_BUTTON) + strDlg.init(_hInst, _hSelf, TEXT("Save Current Language Name As..."), TEXT("Name : "), TEXT(""), langNameLenMax-1); + else + strDlg.init(_hInst, _hSelf, TEXT("Create New Language..."), TEXT("Name : "), TEXT(""), langNameLenMax-1); + + TCHAR *tmpName = (TCHAR *)strDlg.doDialog(); + //const TCHAR *newName = newNameString.c_str(); + + if (tmpName) + { + generic_string newNameString(tmpName); + const TCHAR *newName = newNameString.c_str(); + + if (pNppParam->isExistingUserLangName(newName)) + { + ::MessageBox(_hSelf, TEXT("This name is used by another language,\rplease give another one."), TEXT("Err"), MB_OK); + ::PostMessage(_hSelf, WM_COMMAND, IDC_RENAME_BUTTON, 0); + return TRUE; + } + //add current language in userLangArray at the end as a new lang + UserLangContainer & userLang = (wParam == IDC_SAVEAS_BUTTON)?pNppParam->getULCFromIndex(i-1):*_pCurrentUserLang; + int newIndex = pNppParam->addUserLangToEnd(userLang, newName); + + //add new language name in combobox + ::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_ADDSTRING, 0, LPARAM(newName)); + ::SendDlgItemMessage(_hSelf, IDC_LANGNAME_COMBO, CB_SETCURSEL, newIndex + 1, 0); + ::SendMessage(_hSelf, WM_COMMAND, MAKELONG(IDC_LANGNAME_COMBO, CBN_SELCHANGE), (LPARAM)::GetDlgItem(_hSelf, IDC_LANGNAME_COMBO)); + + //add new language name in langMenu + HWND hNpp = ::GetParent(_hSelf); + ::InsertMenu(::GetSubMenu((HMENU)::SendMessage(hNpp, NPPM_INTERNAL_GETMENU, 0, 0), MENUINDEX_LANGUAGE), IDM_LANG_USER + newIndex /*+ 1*/, MF_BYCOMMAND, IDM_LANG_USER + newIndex + 1, newName); + ::DrawMenuBar(hNpp); + } + + return TRUE; + } + + case IDC_UD_TRANSPARENT_CHECK : + { + bool isChecked = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_UD_TRANSPARENT_CHECK, BM_GETCHECK, 0, 0)); + if (isChecked) + { + int percent = ::SendDlgItemMessage(_hSelf, IDC_UD_PERCENTAGE_SLIDER, TBM_GETPOS, 0, 0); + pNppParam->SetTransparent(_hSelf, percent); + } + else + pNppParam->removeTransparent(_hSelf); + + ::EnableWindow(::GetDlgItem(_hSelf, IDC_UD_PERCENTAGE_SLIDER), isChecked); + return TRUE; + } + + case IDC_LANGNAME_IGNORECASE_CHECK : + return setPropertyByCheck(_hSelf, wParam, _pUserLang->_isCaseIgnored); + + default : + break; + } + } + return FALSE; + } + + case WM_DESTROY: + { + _folderStyleDlg.destroy(); + _keyWordsStyleDlg.destroy(); + _commentStyleDlg.destroy(); + _symbolsStyleDlg.destroy(); + + _ctrlTab.destroy(); + return TRUE; + } + + case WM_SIZE: + { + int originalHight = _dlgPos.bottom; //- ((_status == DOCK)?_dlgPos.top:0); + _currentHight = HIWORD (lParam); + + int diff = _currentHight - _prevHightVal; + _prevHightVal = _currentHight; + + int maxPos = originalHight - _currentHight; + // Set the vertical scrolling range and page size + SCROLLINFO si; + si.cbSize = sizeof(si); + si.fMask = SIF_RANGE | SIF_PAGE; + si.nMin = 0; + si.nMax = (_status == UNDOCK)?0:originalHight; + si.nPage = _currentHight; + //si.nPos = 0; + ::SetScrollInfo(_hSelf, SB_VERT, &si, TRUE); + + if ((_yScrollPos >= maxPos) && (_currentHight < originalHight)) + { + //int nDelta = min(max(maxPos/10,5), maxPos - _yScrollPos); + if (_yScrollPos > 0) + { + _yScrollPos -= diff; + ::SetScrollPos(_hSelf, SB_VERT, _yScrollPos, TRUE); + ::ScrollWindow(_hSelf, 0, diff, NULL, NULL); + } + } + return TRUE; + } + + case WM_VSCROLL : + { + int originalHight = _dlgPos.bottom; + int oldy = _yScrollPos; + int maxPos = originalHight - _currentHight; + + switch (LOWORD (wParam)) + { + // user clicked the top arrow + case SB_LINEUP: + if (_yScrollPos <= 0) + return FALSE; + _yScrollPos = 0; + break; + + // user clicked the bottom arrow + case SB_LINEDOWN: + if (_yScrollPos >= maxPos) + return FALSE; + _yScrollPos = maxPos; + break; + + case SB_PAGEDOWN: + if (_yScrollPos >= maxPos) + return FALSE; + _yScrollPos = maxPos; + break; + + case SB_PAGEUP: + if (_yScrollPos <= 0) + return FALSE; + _yScrollPos = 0; + break; + + case SB_THUMBTRACK: + case SB_THUMBPOSITION: + _yScrollPos = (int)HIWORD(wParam); + break; + + default : + return FALSE; + } + ::SetScrollPos(_hSelf, SB_VERT, _yScrollPos, TRUE); + ::ScrollWindow(_hSelf, 0, oldy-_yScrollPos, NULL, NULL); + } + case NPPM_MODELESSDIALOG : + return ::SendMessage(_hParent, NPPM_MODELESSDIALOG, wParam, lParam); + } + + return FALSE; +} diff --git a/PowerEditor/src/ScitillaComponent/UserDefineDialog.h b/PowerEditor/src/ScitillaComponent/UserDefineDialog.h new file mode 100644 index 00000000..ba4cef97 --- /dev/null +++ b/PowerEditor/src/ScitillaComponent/UserDefineDialog.h @@ -0,0 +1,505 @@ +/* +this file is part of Notepad++ +Copyright (C)2003 Don HO + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef USER_DEFINE_H +#define USER_DEFINE_H + +#include +#include + +#include "UserDefineResource.h" +#include "ControlsTab.h" +#include "ColourPicker.h" +#include "UserDefineLangReference.h" +//#include "Parameters.h" + +#ifdef __GNUC__ + +static int min(int a, int b) { + return (ab)?a:b; +}; + +#endif //__GNUC__ +class ScintillaEditView; +class UserLangContainer; +struct Style; + +#define WL_LEN_MAX 1024 + +#define BOLD_MASK 1 +#define ITALIC_MASK 2 + +const int nbWordList = 4; +const int nbBlockColor = 5; +const int nbBoolean = 5; + +const bool DOCK = true; +const bool UNDOCK = false; + +const int maxNbGroup = 10; + +const int KWL_FOLDER_OPEN_INDEX = 1; +const int KWL_FOLDER_CLOSE_INDEX = 2; +const int KWL_OPERATOR_INDEX = 3; +const int KWL_COMMENT_INDEX = 4; +const int KWL_KW1_INDEX = 5; +const int KWL_KW2_INDEX = 6; +const int KWL_KW3_INDEX = 7; +const int KWL_KW4_INDEX = 8; +const int KWL_DELIM_INDEX = 0; + +const int STYLE_DEFAULT_INDEX = 0; +const int STYLE_BLOCK_OPEN_INDEX = 1; +const int STYLE_BLOCK_CLOSE_INDEX = 2; +const int STYLE_WORD1_INDEX = 3; +const int STYLE_WORD2_INDEX = 4; +const int STYLE_WORD3_INDEX = 5; +const int STYLE_WORD4_INDEX = 6; +const int STYLE_COMMENT_INDEX = 7; +const int STYLE_COMMENTLINE_INDEX = 8; +const int STYLE_NUMBER_INDEX = 9; +const int STYLE_OPERATOR_INDEX = 10; +const int STYLE_DELIM2_INDEX = 11; +const int STYLE_DELIM3_INDEX = 12; + + + +class SharedParametersDialog : public StaticDialog +{ +public: + SharedParametersDialog() {}; + SharedParametersDialog(int nbGroup) : _nbGroup(nbGroup) {}; + virtual void updateDlg() = 0; + + +protected : + //Shared data + static UserLangContainer *_pUserLang; + static ScintillaEditView *_pScintilla; + + //data for per object + int _nbGroup; + ColourPicker *_pFgColour[maxNbGroup]; + ColourPicker *_pBgColour[maxNbGroup]; + int _fgStatic[maxNbGroup]; + int _bgStatic[maxNbGroup]; + int _fontSizeCombo[maxNbGroup]; + int _fontNameCombo[maxNbGroup]; + + BOOL CALLBACK run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam); + void initControls(); + void styleUpdate(const Style & style, ColourPicker *pFgColourPicker, ColourPicker *pBgColourPicker, + int fontComboId, int fontSizeComboId, int boldCheckId, int italicCheckId, int underlineCheckId); + + bool setPropertyByCheck(HWND hwnd, WPARAM id, bool & bool2set); + virtual void setKeywords2List(int ctrlID) = 0; + virtual int getGroupIndexFromCombo(int ctrlID, bool & isFontSize) const = 0; + virtual int getStylerIndexFromCP(HWND hWnd, bool & isFG, ColourPicker **ppCP) const = 0; + virtual int getGroupeIndexFromCheck(int ctrlID, int & fontStyleMask) const = 0; + + +}; + +class FolderStyleDialog : public SharedParametersDialog +{ +public: + FolderStyleDialog(); + void updateDlg(); +protected : + void setKeywords2List(int ctrlID); + + int getGroupIndexFromCombo(int ctrlID, bool & isFontSize) const { + switch (ctrlID) + { + case IDC_DEFAULT_FONT_COMBO : + isFontSize = false; + return STYLE_DEFAULT_INDEX; + + case IDC_DEFAULT_FONTSIZE_COMBO : + isFontSize = true; + return STYLE_DEFAULT_INDEX; + + case IDC_FOLDEROPEN_FONT_COMBO : + isFontSize = false; + return STYLE_BLOCK_OPEN_INDEX; + + case IDC_FOLDEROPEN_FONTSIZE_COMBO : + isFontSize = true; + return STYLE_BLOCK_OPEN_INDEX; + + case IDC_FOLDERCLOSE_FONT_COMBO : + isFontSize = false; + return STYLE_BLOCK_CLOSE_INDEX; + + case IDC_FOLDERCLOSE_FONTSIZE_COMBO : + isFontSize = true; + return STYLE_BLOCK_CLOSE_INDEX; + + default : + return -1; + } + }; + int getStylerIndexFromCP(HWND hWnd, bool & isFG, ColourPicker **ppCP) const; + int getGroupeIndexFromCheck(int ctrlID, int & fontStyleMask) const; +}; + +class KeyWordsStyleDialog : public SharedParametersDialog +{ +public: + KeyWordsStyleDialog() ; + void updateDlg(); + +protected : + BOOL CALLBACK run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam); + void setKeywords2List(int id); + + // SEE @REF #01 + int getGroupIndexFromCombo(int ctrlID, bool & isFontSize) const { + switch (ctrlID) + { + case IDC_KEYWORD1_FONT_COMBO : + isFontSize = false; + return STYLE_WORD1_INDEX; + + case IDC_KEYWORD1_FONTSIZE_COMBO : + isFontSize = true; + return STYLE_WORD1_INDEX; + + case IDC_KEYWORD2_FONT_COMBO : + isFontSize = false; + return STYLE_WORD2_INDEX; + + case IDC_KEYWORD2_FONTSIZE_COMBO : + isFontSize = true; + return STYLE_WORD2_INDEX; + + case IDC_KEYWORD3_FONT_COMBO : + isFontSize = false; + return STYLE_WORD3_INDEX; + + case IDC_KEYWORD3_FONTSIZE_COMBO : + isFontSize = true; + return STYLE_WORD3_INDEX; + + case IDC_KEYWORD4_FONT_COMBO : + isFontSize = false; + return STYLE_WORD4_INDEX; + + case IDC_KEYWORD4_FONTSIZE_COMBO : + isFontSize = true; + return STYLE_WORD4_INDEX; + + default : + return -1; + } + }; + int getStylerIndexFromCP(HWND hWnd, bool & isFG, ColourPicker **ppCP) const; + int getGroupeIndexFromCheck(int ctrlID, int & fontStyleMask) const; +}; + +class CommentStyleDialog : public SharedParametersDialog +{ +public : + CommentStyleDialog(); + void updateDlg(); +protected : + + BOOL CALLBACK run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam); + + void setKeywords2List(int id); + int getGroupIndexFromCombo(int ctrlID, bool & isFontSize) const { + switch (ctrlID) + { + case IDC_COMMENT_FONT_COMBO : + isFontSize = false; + return STYLE_COMMENT_INDEX; + + case IDC_COMMENT_FONTSIZE_COMBO : + isFontSize = true; + return STYLE_COMMENT_INDEX; + + case IDC_COMMENTLINE_FONT_COMBO : + isFontSize = false; + return STYLE_COMMENTLINE_INDEX; + + case IDC_COMMENTLINE_FONTSIZE_COMBO : + isFontSize = true; + return STYLE_COMMENTLINE_INDEX; + + case IDC_NUMBER_FONT_COMBO : + isFontSize = false; + return STYLE_NUMBER_INDEX; + + case IDC_NUMBER_FONTSIZE_COMBO : + isFontSize = true; + return STYLE_NUMBER_INDEX; + + + default : + return -1; + } + }; + + int getStylerIndexFromCP(HWND hWnd, bool & isFG, ColourPicker **ppCP) const; + int getGroupeIndexFromCheck(int ctrlID, int & fontStyleMask) const; + +private : + void convertTo(TCHAR *dest, const TCHAR *toConvert, TCHAR prefix) const; + void retrieve(TCHAR *dest, const TCHAR *toRetrieve, TCHAR prefix) const; +}; + +class SymbolsStyleDialog : public SharedParametersDialog +{ +public : + static const bool ADD; + static const bool REMOVE; + SymbolsStyleDialog(); + void updateDlg(); +protected : + BOOL CALLBACK run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam); + void setKeywords2List(int ctrlID) {}; + int getGroupIndexFromCombo(int ctrlID, bool & isFontSize) const { + switch (ctrlID) + { + case IDC_SYMBOL_FONT_COMBO : + isFontSize = false; + return STYLE_OPERATOR_INDEX; + + case IDC_SYMBOL_FONTSIZE_COMBO : + isFontSize = true; + return STYLE_OPERATOR_INDEX; + + case IDC_SYMBOL_FONT2_COMBO : + isFontSize = false; + return STYLE_DELIM2_INDEX; + + case IDC_SYMBOL_FONTSIZE2_COMBO : + isFontSize = true; + return STYLE_DELIM2_INDEX; + + case IDC_SYMBOL_FONT3_COMBO : + isFontSize = false; + return STYLE_DELIM3_INDEX; + + case IDC_SYMBOL_FONTSIZE3_COMBO : + isFontSize = true; + return STYLE_DELIM3_INDEX; + + default : + return -1; + } + }; + int getStylerIndexFromCP(HWND hWnd, bool & isFG, ColourPicker **ppCP) const; + int getGroupeIndexFromCheck(int ctrlID, int & fontStyleMask) const; + +private : + // 2 static const TCHAR * to have the compatibility with the old xml + static const TCHAR *_delimTag1; + static const TCHAR *_delimTag2; + + void symbolAction(bool action); + void listboxsRemoveAll(); + void listboxsInit(); + void listboxsReInit() { + listboxsRemoveAll(); + listboxsInit(); + }; +}; + +class UserDefineDialog : public SharedParametersDialog +{ +friend class ScintillaEditView; +public : + UserDefineDialog(); + ~UserDefineDialog(); + + void init(HINSTANCE hInst, HWND hPere, ScintillaEditView *pSev) { + if (!_pScintilla) + { + Window::init(hInst, hPere); + _pScintilla = pSev; + } + }; + + void setScintilla(ScintillaEditView *pScinView) { + _pScintilla = pScinView; + }; + + virtual void create(int dialogID, bool isRTL = false) { + StaticDialog::create(dialogID, isRTL); + } + + void destroy() { + // A Ajouter les fils... + }; + int getWidth() const { + return _dlgPos.right; + }; + + int getHeight() const { + return _dlgPos.bottom; + }; + void doDialog(bool willBeShown = true, bool isRTL = false) { + if (!isCreated()) + create(IDD_GLOBAL_USERDEFINE_DLG, isRTL); + display(willBeShown); + }; + + virtual void reSizeTo(RECT & rc) // should NEVER be const !!! + { + Window::reSizeTo(rc); + display(false); + display(); + }; + + void changeStyle(); + bool isDocked() const {return _status == DOCK;}; + void setDockStatus(bool isDocked) {_status = isDocked;}; + + int getNbKeywordList() {return nbKeywodList;}; + bool isDirty() const {return _isDirty;}; + HWND getFolderHandle() const { + return _folderStyleDlg.getHSelf(); + }; + + HWND getKeywordsHandle() const { + return _keyWordsStyleDlg.getHSelf(); + }; + + HWND getCommentHandle() const { + return _commentStyleDlg.getHSelf(); + }; + + HWND getSymbolHandle() const { + return _symbolsStyleDlg.getHSelf(); + }; + + void setTabName(int index, const TCHAR *name2set) { + _ctrlTab.renameTab(index, name2set); + }; +protected : + virtual BOOL CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam); + +private : + ControlsTab _ctrlTab; + WindowVector _wVector; + UserLangContainer *_pCurrentUserLang; + + FolderStyleDialog _folderStyleDlg; + KeyWordsStyleDialog _keyWordsStyleDlg; + CommentStyleDialog _commentStyleDlg; + SymbolsStyleDialog _symbolsStyleDlg; + + bool _status; + RECT _dlgPos; + int _currentHight; + int _yScrollPos; + int _prevHightVal; + + bool _isDirty; + void getActualPosSize() { + ::GetWindowRect(_hSelf, &_dlgPos); + _dlgPos.right -= _dlgPos.left; + _dlgPos.bottom -= _dlgPos.top; + }; + void restorePosSize(){reSizeTo(_dlgPos);}; + void enableLangAndControlsBy(int index); + +protected : + void setKeywords2List(int ctrlID){}; + int getGroupIndexFromCombo(int ctrlID, bool & isFontSize) const {return -1;}; + int getStylerIndexFromCP(HWND hWnd, bool & isFG, ColourPicker **ppCP) const {return -1;}; + int getGroupeIndexFromCheck(int ctrlID, int & fontStyleMask) const {return -1;}; + void updateDlg(); +}; + +class StringDlg : public StaticDialog +{ +public : + StringDlg() : StaticDialog() {}; + void init(HINSTANCE hInst, HWND parent, TCHAR *title, TCHAR *staticName, TCHAR *text2Set, int txtLen = 0) { + Window::init(hInst, parent); + lstrcpy(_title, title); + lstrcpy(_static, staticName); + lstrcpy(_textValue, text2Set); + _txtLen = txtLen; + }; + + long doDialog() { + return long(::DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_STRING_DLG), _hParent, (DLGPROC)dlgProc, (LPARAM)this)); + }; + + virtual void destroy() {}; + +protected : + BOOL CALLBACK run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam) + { + + switch (Message) + { + case WM_INITDIALOG : + { + ::SetWindowText(_hSelf, _title); + ::SetDlgItemText(_hSelf, IDC_STRING_STATIC, _static); + ::SetDlgItemText(_hSelf, IDC_STRING_EDIT, _textValue); + if (_txtLen) + ::SendDlgItemMessage(_hSelf, IDC_STRING_EDIT, EM_SETLIMITTEXT, _txtLen, 0); + + return TRUE; + } + + case WM_COMMAND : + { + switch (wParam) + { + case IDOK : + { + ::GetDlgItemText(_hSelf, IDC_STRING_EDIT, _textValue, 256); + ::EndDialog(_hSelf, int(_textValue)); + return TRUE; + } + + case IDCANCEL : + ::EndDialog(_hSelf, 0); + return TRUE; + + default: + return FALSE; + } + } + default : + return FALSE; + } + + return FALSE; + } + +private : + TCHAR _title[64]; + TCHAR _textValue[256]; + TCHAR _static[32]; + int _txtLen; +}; + + +#endif //USER_DEFINE_H diff --git a/PowerEditor/src/ScitillaComponent/UserDefineDialog.rc b/PowerEditor/src/ScitillaComponent/UserDefineDialog.rc new file mode 100644 index 00000000..1d1b302a --- /dev/null +++ b/PowerEditor/src/ScitillaComponent/UserDefineDialog.rc @@ -0,0 +1,270 @@ +/* +this file is part of notepad++ +Copyright (C)2003 Don HO < donho@altern.org > + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef USERDEFINEDIALOG_RC +#define USERDEFINEDIALOG_RC + +#include +#include "UserDefineResource.h" +IDD_FOLDER_STYLE_DLG DIALOGEX 36, 44, 320, 460 +STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | WS_CHILD +FONT 8, TEXT("MS Shell Dlg"), 0, 0, 0x0 +BEGIN + GROUPBOX "Folder Open Keywords Setting", IDC_FOLDEROPEN_DESCGROUP_STATIC,5,114,300,127,BS_CENTER + LTEXT "Foreground color",IDC_FOLDEROPEN_FG_STATIC,27,144,58,8, 0,WS_EX_RIGHT + LTEXT "Background color",IDC_FOLDEROPEN_BG_STATIC,27,168,58,8, 0,WS_EX_RIGHT + COMBOBOX IDC_FOLDEROPEN_FONT_COMBO,185,140,104,78, CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | CBS_SORT | WS_VSCROLL | WS_TABSTOP + COMBOBOX IDC_FOLDEROPEN_FONTSIZE_COMBO,249,162,40,82, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + CONTROL "Bold",IDC_FOLDEROPEN_BOLD_CHECK,"Button", BS_AUTOCHECKBOX | WS_TABSTOP,141,166,46,10 + CONTROL "Italic",IDC_FOLDEROPEN_ITALIC_CHECK,"Button", BS_AUTOCHECKBOX | WS_TABSTOP,141,179,47,10 + GROUPBOX "Font style",IDC_FOLDEROPEN_FONTSTYLEGROUP_STATIC,133, 125,164,71 + GROUPBOX "Colour style",IDC_FOLDEROPEN_COLORSTYLEGROUP_STATIC,15, 125,111,71 + LTEXT "Font Name :",IDC_FOLDEROPEN_FONTNAME_STATIC,138,142,44, 8,0,WS_EX_RIGHT + LTEXT "Font size :",IDC_FOLDEROPEN_FONTSIZE_STATIC,212,164,35, 8,0,WS_EX_RIGHT + EDITTEXT IDC_FOLDEROPEN_EDIT,15,203,282,28,ES_MULTILINE | WS_VSCROLL + GROUPBOX "Folder Close Keywords Setting", IDC_FOLDERCLOSE_DESCGROUP_STATIC,5,246,300,125,BS_CENTER + LTEXT "Foreground color",IDC_FOLDERCLOSE_FG_STATIC,27,277,58,8,0,WS_EX_RIGHT + LTEXT "Background color",IDC_FOLDERCLOSE_BG_STATIC,27,301,58,8,0,WS_EX_RIGHT + COMBOBOX IDC_FOLDERCLOSE_FONT_COMBO,185,272,104,78,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | CBS_SORT | WS_VSCROLL | WS_TABSTOP + COMBOBOX IDC_FOLDERCLOSE_FONTSIZE_COMBO,249,292,40,82, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + CONTROL "Bold",IDC_FOLDERCLOSE_BOLD_CHECK,"Button", BS_AUTOCHECKBOX | WS_TABSTOP,141,298,45,10 + CONTROL "Italic",IDC_FOLDERCLOSE_ITALIC_CHECK,"Button", BS_AUTOCHECKBOX | WS_TABSTOP,141,312,46,10 + GROUPBOX "Font style",IDC_FOLDERCLOSE_FONTSTYLEGROUP_STATIC,133,257,164,69 + GROUPBOX "Colour style",IDC_FOLDERCLOSE_COLORSTYLEGROUP_STATIC,15,257,111,69 + LTEXT "Font Name :",IDC_FOLDERCLOSE_FONTNAME_STATIC,138,273,45,8,0,WS_EX_RIGHT + LTEXT "Font size :",IDC_FOLDERCLOSE_FONTSIZE_STATIC,212,294,35, 8,0,WS_EX_RIGHT + EDITTEXT IDC_FOLDERCLOSE_EDIT,15,334,282,28,ES_MULTILINE | WS_VSCROLL + GROUPBOX "Default Style Setting",IDC_DEFAULT_DESCGROUP_STATIC,5,7, 300,92,BS_CENTER + LTEXT "Foreground color",IDC_DEFAULT_FG_STATIC,27,38,59,8,0, WS_EX_RIGHT + LTEXT "Background color",IDC_DEFAULT_BG_STATIC,27,62,59,8,0, WS_EX_RIGHT + COMBOBOX IDC_DEFAULT_FONT_COMBO,185,33,104,78,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | CBS_SORT | WS_VSCROLL | WS_TABSTOP + COMBOBOX IDC_DEFAULT_FONTSIZE_COMBO,249,55,40,82,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + CONTROL "Bold",IDC_DEFAULT_BOLD_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,141,59,45,10 + CONTROL "Italic",IDC_DEFAULT_ITALIC_CHECK,"Button", BS_AUTOCHECKBOX | WS_TABSTOP,141,73,46,10 + GROUPBOX "Font style",IDC_DEFAULT_FONTSTYLEGROUP_STATIC,133,17, 164,73 + GROUPBOX "Colour style",IDC_DEFAULT_COLORSTYLEGROUP_STATIC,15,17, 111,73 + LTEXT "Font Name :",IDC_DEFAULT_FONTNAME_STATIC,137,34,47,8,0, WS_EX_RIGHT + LTEXT "Font size :",IDC_DEFAULT_FONTSIZE_STATIC,212,57,36,8,0, WS_EX_RIGHT + CONTROL "Underline",IDC_DEFAULT_UNDERLINE_CHECK,"Button", BS_AUTOCHECKBOX | WS_TABSTOP,214,73,59,10 + CONTROL "Underline",IDC_FOLDEROPEN_UNDERLINE_CHECK,"Button", BS_AUTOCHECKBOX | WS_TABSTOP,213,179,59,10 + CONTROL "Underline",IDC_FOLDERCLOSE_UNDERLINE_CHECK,"Button", BS_AUTOCHECKBOX | WS_TABSTOP,212,312,59,10 +END + +IDD_KEYWORD_STYLE_DLG DIALOGEX 36, 44, 320, 460 +STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | WS_CHILD +FONT 8, TEXT("MS Shell Dlg"), 0, 0, 0x0 +BEGIN + LTEXT "Foreground color",IDC_KEYWORD1_FG_STATIC,26,25,56,8,0, WS_EX_RIGHT + LTEXT "Background color",IDC_KEYWORD1_BG_STATIC,26,45,56,8,0,WS_EX_RIGHT + COMBOBOX IDC_KEYWORD1_FONT_COMBO,184,26,104,78,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | CBS_SORT | WS_VSCROLL | WS_TABSTOP + COMBOBOX IDC_KEYWORD1_FONTSIZE_COMBO,248,42,40,82,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + CONTROL "Bold",IDC_KEYWORD1_BOLD_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,140,44,45,10 + CONTROL "Italic",IDC_KEYWORD1_ITALIC_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,140,59,41,10 + GROUPBOX "Font style",IDC_KEYWORD1_FONTSTYLEGROUP_STATIC,132,13,164,61 + GROUPBOX "Colour style",IDC_KEYWORD1_COLORSTYLEGROUP_STATIC,14,13,111,49 + LTEXT "Font Name :",IDC_KEYWORD1_FONTNAME_STATIC,136,27,44,8,0,WS_EX_RIGHT + LTEXT "Font size :",IDC_KEYWORD1_FONTSIZE_STATIC,212,44,34,8,0,WS_EX_RIGHT + EDITTEXT IDC_KEYWORD1_EDIT,14,78,282,28,ES_MULTILINE | WS_VSCROLL + GROUPBOX "1st Group",IDC_KEYWORD1_DESCGROUP_STATIC,4,3,300,109,BS_CENTER | BS_FLAT + LTEXT "Foreground color",IDC_KEYWORD2_FG_STATIC,26,136,56,8,0,WS_EX_RIGHT + LTEXT "Background color",IDC_KEYWORD2_BG_STATIC,26,157,56,8,0,WS_EX_RIGHT + COMBOBOX IDC_KEYWORD2_FONT_COMBO,184,138,104,78,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | CBS_SORT | WS_VSCROLL | WS_TABSTOP + COMBOBOX IDC_KEYWORD2_FONTSIZE_COMBO,248,154,40,82,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + CONTROL "Bold",IDC_KEYWORD2_BOLD_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,140,156,46,10 + CONTROL "Italic",IDC_KEYWORD2_ITALIC_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,140,172,43,10 + GROUPBOX "Font style",IDC_KEYWORD2_FONTSTYLEGROUP_STATIC,132,125,164,62 + GROUPBOX "Colour style",IDC_KEYWORD2_COLORSTYLEGROUP_STATIC,14,125,111,49 + LTEXT "Font Name :",IDC_KEYWORD2_FONTNAME_STATIC,136,139,44,8,0,WS_EX_RIGHT + LTEXT "Font size :",IDC_KEYWORD2_FONTSIZE_STATIC,212,156,34,8,0,WS_EX_RIGHT + EDITTEXT IDC_KEYWORD2_EDIT,14,192,282,28,ES_MULTILINE | WS_VSCROLL + GROUPBOX "2nd Group",IDC_KEYWORD2_DESCGROUP_STATIC,4,115,300,110,BS_CENTER | BS_FLAT + LTEXT "Foreground color",IDC_KEYWORD3_FG_STATIC,26,248,56,8,0,WS_EX_RIGHT + LTEXT "Background color",IDC_KEYWORD3_BG_STATIC,26,269,56,8,0,WS_EX_RIGHT + COMBOBOX IDC_KEYWORD3_FONT_COMBO,184,250,104,78,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | CBS_SORT | WS_VSCROLL | WS_TABSTOP + COMBOBOX IDC_KEYWORD3_FONTSIZE_COMBO,248,266,40,82,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + CONTROL "Bold",IDC_KEYWORD3_BOLD_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,140,268,45,10 + CONTROL "Italic",IDC_KEYWORD3_ITALIC_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,140,283,44,10 + GROUPBOX "Font style",IDC_KEYWORD3_FONTSTYLEGROUP_STATIC,132,237,164,61 + GROUPBOX "Colour style",IDC_KEYWORD3_COLORSTYLEGROUP_STATIC,14,237,111,49 + LTEXT "Font Name :",IDC_KEYWORD3_FONTNAME_STATIC,136,251,44,8,0,WS_EX_RIGHT + LTEXT "Font size :",IDC_KEYWORD3_FONTSIZE_STATIC,212,268,34,8,0,WS_EX_RIGHT + EDITTEXT IDC_KEYWORD3_EDIT,14,303,282,28,ES_MULTILINE | WS_VSCROLL + GROUPBOX "3rd Group",IDC_KEYWORD3_DESCGROUP_STATIC,4,227,300,110,BS_CENTER | BS_FLAT + LTEXT "Foreground color",IDC_KEYWORD4_FG_STATIC,26,362,57,8,0,WS_EX_RIGHT + LTEXT "Background color",IDC_KEYWORD4_BG_STATIC,26,383,57,8,0,WS_EX_RIGHT + COMBOBOX IDC_KEYWORD4_FONT_COMBO,184,363,104,78,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | CBS_SORT | WS_VSCROLL | WS_TABSTOP + COMBOBOX IDC_KEYWORD4_FONTSIZE_COMBO,248,379,40,82,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + CONTROL "Bold",IDC_KEYWORD4_BOLD_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,140,381,44,10 + CONTROL "Italic",IDC_KEYWORD4_ITALIC_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,140,396,44,10 + GROUPBOX "Font style",IDC_KEYWORD4_FONTSTYLEGROUP_STATIC,132,350,164,60 + GROUPBOX "Colour style",IDC_KEYWORD4_COLORSTYLEGROUP_STATIC,14, 350,111,50 + LTEXT "Font Name :",IDC_KEYWORD4_FONTNAME_STATIC,136,364,44,8, 0,WS_EX_RIGHT + LTEXT "Font size :",IDC_KEYWORD4_FONTSIZE_STATIC,212,381,34,8, 0,WS_EX_RIGHT + EDITTEXT IDC_KEYWORD4_EDIT,14,416,282,28,ES_MULTILINE | WS_VSCROLL + GROUPBOX "4th Group",IDC_KEYWORD4_DESCGROUP_STATIC,4,340,300,111, BS_CENTER | BS_FLAT + CONTROL "Prefix mode",IDC_KEYWORD1_PREFIX_CHECK,"Button", BS_AUTOCHECKBOX | WS_TABSTOP,14,67,64,10 + CONTROL "Prefix mode",IDC_KEYWORD2_PREFIX_CHECK,"Button", BS_AUTOCHECKBOX | WS_TABSTOP,14,180,64,10 + CONTROL "Prefix mode",IDC_KEYWORD3_PREFIX_CHECK,"Button", BS_AUTOCHECKBOX | WS_TABSTOP,14,291,64,10 + CONTROL "Prefix mode",IDC_KEYWORD4_PREFIX_CHECK,"Button", BS_AUTOCHECKBOX | WS_TABSTOP,14,404,64,10 + CONTROL "Underline",IDC_KEYWORD4_UNDERLINE_CHECK,"Button", BS_AUTOCHECKBOX | WS_TABSTOP,211,396,58,10 + CONTROL "Underline",IDC_KEYWORD3_UNDERLINE_CHECK,"Button", BS_AUTOCHECKBOX | WS_TABSTOP,211,283,61,10 + CONTROL "Underline",IDC_KEYWORD1_UNDERLINE_CHECK,"Button", BS_AUTOCHECKBOX | WS_TABSTOP,211,59,59,10 + CONTROL "Underline",IDC_KEYWORD2_UNDERLINE_CHECK,"Button", BS_AUTOCHECKBOX | WS_TABSTOP,211,172,59,10 +END + +IDD_COMMENT_STYLE_DLG DIALOGEX 36, 44, 320, 460 +STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | WS_CHILD +FONT 8, TEXT("MS Shell Dlg"), 0, 0, 0x0 +BEGIN + LTEXT "Foreground color ",IDC_COMMENTLINE_FG_STATIC,24,31,58,8,0,WS_EX_RIGHT + LTEXT "Background color",IDC_COMMENTLINE_BG_STATIC,24,52,58,8,0,WS_EX_RIGHT + COMBOBOX IDC_COMMENTLINE_FONT_COMBO,184,32,104,78,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | CBS_SORT | WS_VSCROLL | WS_TABSTOP + COMBOBOX IDC_COMMENTLINE_FONTSIZE_COMBO,248,48,40,82,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + CONTROL "Bold",IDC_COMMENTLINE_BOLD_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,140,50,43,10 + CONTROL "Italic",IDC_COMMENTLINE_ITALIC_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,140,65,43,10 + GROUPBOX "Font style",IDC_COMMENTLINE_FONTSTYLEGROUP_STATIC,132,19,164,63 + GROUPBOX "Colour style",IDC_COMMENTLINE_COLORSTYLEGROUP_STATIC,14,19,111,50 + LTEXT "Font Name :",IDC_COMMENTLINE_FONTNAME_STATIC,140,33,40,8,0,WS_EX_RIGHT + LTEXT "Font size :",IDC_COMMENTLINE_FONTSIZE_STATIC,212,50,34,8,0,WS_EX_RIGHT + EDITTEXT IDC_COMMENTLINE_EDIT,14,90,282,28,ES_MULTILINE | WS_VSCROLL + GROUPBOX "Comment Line",IDC_COMMENTLINE_DESCGROUP_STATIC,4,7,300,119,BS_CENTER + LTEXT "Foreground color",IDC_NUMBER_FG_STATIC,24,302,58,8,0,WS_EX_RIGHT + LTEXT "Background color",IDC_NUMBER_BG_STATIC,24,325,58,8,0,WS_EX_RIGHT + COMBOBOX IDC_NUMBER_FONT_COMBO,183,300,104,78,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | CBS_SORT | WS_VSCROLL | WS_TABSTOP + COMBOBOX IDC_NUMBER_FONTSIZE_COMBO,247,316,40,82,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + CONTROL "Bold",IDC_NUMBER_BOLD_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,139,317,44,10 + CONTROL "Italic",IDC_NUMBER_ITALIC_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,139,333,44,10 + GROUPBOX "Font style",IDC_NUMBER_FONTSTYLEGROUP_STATIC,131,288,164,60 + GROUPBOX "Colour style",IDC_NUMBER_COLORSTYLEGROUP_STATIC,13,288,111,60 + LTEXT "Font Name :",IDC_NUMBER_FONTNAME_STATIC,139,301,40,8,0,WS_EX_RIGHT + LTEXT "Font size :",IDC_NUMBER_FONTSIZE_STATIC,211,317,34,8,0,WS_EX_RIGHT + GROUPBOX "Number",IDC_NUMBER_DESCGROUP_STATIC,3,274,300,85,BS_CENTER + LTEXT "Foreground color",IDC_COMMENT_FG_STATIC,24,158,57,8,0,WS_EX_RIGHT + LTEXT "Background color",IDC_COMMENT_BG_STATIC,24,179,57,8,0,WS_EX_RIGHT + COMBOBOX IDC_COMMENT_FONT_COMBO,184,159,104,78,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | CBS_SORT | WS_VSCROLL | WS_TABSTOP + COMBOBOX IDC_COMMENT_FONTSIZE_COMBO,248,175,40,82,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + CONTROL "Bold",IDC_COMMENT_BOLD_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,140,177,44,10 + CONTROL "Italic",IDC_COMMENT_ITALIC_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,140,193,43,10 + GROUPBOX "Font style",IDC_COMMENT_FONTSTYLEGROUP_STATIC,132,146,164,64 + GROUPBOX "Colour style",IDC_COMMENT_COLORSTYLEGROUP_STATIC,14,146,111,50 + LTEXT "Font Name :",IDC_COMMENT_FONTNAME_STATIC,140,160,40,8,0,WS_EX_RIGHT + LTEXT "Font size :",IDC_COMMENT_FONTSIZE_STATIC,212,177,34,8,0,WS_EX_RIGHT + EDITTEXT IDC_COMMENTOPEN_EDIT,14,229,133,28,ES_MULTILINE | WS_VSCROLL + GROUPBOX "Comment Block",IDC_COMMENT_DESCGROUP_STATIC,4,133,300,132,BS_CENTER + EDITTEXT IDC_COMMENTCLOSE_EDIT,157,229,139,28,ES_MULTILINE | WS_VSCROLL + LTEXT "Comment Open :",IDC_COMMENTOPEN_STATIC,17,218,90,8 + LTEXT "Comment Close :",IDC_COMMENTCLOSE_STATIC,158,218,88,8 + CONTROL "Treat keyword as symbol",IDC_COMMENTLINESYMBOL_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,78,112,10 + CONTROL "Treat keywords as symbols",IDC_COMMENTSYMBOL_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,14,203,112,10 + CONTROL "Underline",IDC_COMMENT_UNDERLINE_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,211,193,59,10 + CONTROL "Underline",IDC_COMMENTLINE_UNDERLINE_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,212,65,59,10 + CONTROL "Underline",IDC_NUMBER_UNDERLINE_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,211,332,59,10 +END + +IDD_SYMBOL_STYLE_DLG DIALOGEX 36, 44, 320, 460 +STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | WS_CHILD +FONT 8, TEXT("MS Shell Dlg"), 0, 0, 0x0 +BEGIN + LISTBOX IDC_AVAILABLE_SYMBOLS_LIST,68,33,41,116,LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP + PUSHBUTTON "->",IDC_ADD_BUTTON,127,65,50,14 + PUSHBUTTON "<-",IDC_REMOVE_BUTTON,127,94,50,14 + LISTBOX IDC_ACTIVATED_SYMBOL_LIST,195,33,41,115,LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP + LTEXT "Activated Operators",IDC_ACTIVATED_SYMBOL_STATIC,182,18,86,8 + LTEXT "Available Symbols",IDC_AVAILABLE_SYMBOLS_STATIC,59,18,90,8 + LTEXT "Foreground color",IDC_SYMBOL_FG_STATIC,25,169,57,8,0,WS_EX_RIGHT + LTEXT "Background color",IDC_SYMBOL_BG_STATIC,25,192,57,8,0,WS_EX_RIGHT + COMBOBOX IDC_SYMBOL_FONT_COMBO,183,168,104,78,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | CBS_SORT | WS_VSCROLL | WS_TABSTOP + COMBOBOX IDC_SYMBOL_FONTSIZE_COMBO,247,184,40,82,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + CONTROL "Bold",IDC_SYMBOL_BOLD_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,139,185,44,10 + CONTROL "Italic",IDC_SYMBOL_ITALIC_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,139,199,44,10 + GROUPBOX "Font style",IDC_SYMBOL_FONTSTYLEGROUP_STATIC,131,155,164,59 + GROUPBOX "Colour style",IDC_SYMBOL_COLORSTYLEGROUP_STATIC,13,155,111,59 + LTEXT "Font Name :",IDC_SYMBOL_FONTNAME_STATIC,135,169,44,8,0,WS_EX_RIGHT + LTEXT "Font size :",IDC_SYMBOL_FONTSIZE_STATIC,211,185,34,8,0,WS_EX_RIGHT + GROUPBOX "Operator",IDC_SYMBOL_DESCGROUP_STATIC,3,5,300,216,BS_CENTER + CONTROL "Underline",IDC_SYMBOL_UNDERLINE_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,211,199,59,10 + LTEXT "Foreground color",IDC_SYMBOL_FG2_STATIC,26,268,56,8,0,WS_EX_RIGHT + LTEXT "Background color",IDC_SYMBOL_BG2_STATIC,26,289,56,8,0,WS_EX_RIGHT + COMBOBOX IDC_SYMBOL_FONT2_COMBO,184,266,104,78,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | CBS_SORT | WS_VSCROLL | WS_TABSTOP + COMBOBOX IDC_SYMBOL_BO2_COMBO,85,237,40,82,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + CONTROL "Bold",IDC_SYMBOL_BOLD2_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,140,284,45,10 + CONTROL "Italic",IDC_SYMBOL_ITALIC2_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,140,299,41,10 + GROUPBOX "Font style",IDC_SYMBOL_FONTSTYLEGROUP2_STATIC,132,253,164,60 + GROUPBOX "Colour style",IDC_SYMBOL_COLORSTYLEGROUP2_STATIC,14,253,111,60 + LTEXT "Font Name :",IDC_SYMBOL_FONTNAME2_STATIC,136,267,44,8,0,WS_EX_RIGHT + LTEXT "Boundary open :",IDC_SYMBOL_BO2_STATIC,9,239,74,8,0,WS_EX_RIGHT + CONTROL "Underline",IDC_SYMBOL_UNDERLINE2_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,211,299,59,10 + COMBOBOX IDC_SYMBOL_BC2_COMBO,256,237,40,82,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + LTEXT "Boundary close :",IDC_SYMBOL_BC2_STATIC,168,239,86,8,0,WS_EX_RIGHT + GROUPBOX "Delimiter 1",IDC_SYMBOL_DELIMGROUP1_STATIC,3,227,300,93,BS_CENTER | BS_FLAT + LTEXT "Foreground color",IDC_SYMBOL_FG3_STATIC,26,369,56,8,0,WS_EX_RIGHT + LTEXT "Background color",IDC_SYMBOL_BG3_STATIC,26,390,56,8,0,WS_EX_RIGHT + COMBOBOX IDC_SYMBOL_FONT3_COMBO,184,367,104,78,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | CBS_SORT | WS_VSCROLL | WS_TABSTOP + COMBOBOX IDC_SYMBOL_BO3_COMBO,85,339,40,82,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + CONTROL "Bold",IDC_SYMBOL_BOLD3_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,140,385,45,10 + CONTROL "Italic",IDC_SYMBOL_ITALIC3_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,140,400,41,10 + GROUPBOX "Font style",IDC_SYMBOL_FONTSTYLEGROUP3_STATIC,132,355,164,60 + GROUPBOX "Colour style",IDC_SYMBOL_COLORSTYLEGROUP3_STATIC,14,355,111,60 + LTEXT "Font Name :",IDC_SYMBOL_FONTNAME3_STATIC,136,368,44,8,0,WS_EX_RIGHT + LTEXT "Boundary open :",IDC_SYMBOL_BO3_STATIC,9,340,74,8,0,WS_EX_RIGHT + CONTROL "Underline",IDC_SYMBOL_UNDERLINE3_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,211,400,59,10 + COMBOBOX IDC_SYMBOL_BC3_COMBO,256,339,40,82,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + LTEXT "Boundary close :",IDC_SYMBOL_BC3_STATIC,168,340,86,8,0,WS_EX_RIGHT + GROUPBOX "Delimiter 2",IDC_SYMBOL_DELIMGROUP2_STATIC,3,328,300,93,BS_CENTER | BS_FLAT + COMBOBOX IDC_SYMBOL_FONTSIZE2_COMBO,248,283,40,82,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + LTEXT "Font size :",IDC_SYMBOL_FONTSIZE2_STATIC,212,285,34,8,0,WS_EX_RIGHT + COMBOBOX IDC_SYMBOL_FONTSIZE3_COMBO,248,384,40,82,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + LTEXT "Font size :",IDC_SYMBOL_FONTSIZE3_STATIC,212,386,34,8,0,WS_EX_RIGHT +END + +IDD_GLOBAL_USERDEFINE_DLG DIALOGEX 36, 44, 340, 550 +STYLE DS_SETFONT | DS_MODALFRAME | DS_3DLOOK | DS_FIXEDSYS | WS_POPUP | + WS_CAPTION | WS_VSCROLL | WS_SYSMENU +EXSTYLE WS_EX_TOOLWINDOW +CAPTION "User Define" +FONT 8, TEXT("MS Shell Dlg"), 0, 0, 0x0 +BEGIN + PUSHBUTTON "Rename",IDC_RENAME_BUTTON,174,40,62,14 + PUSHBUTTON "Create New...",IDC_ADDNEW_BUTTON,34,40,62,14 + PUSHBUTTON "Dock",IDC_DOCK_BUTTON,275,1,50,14,BS_FLAT + COMBOBOX IDC_LANGNAME_COMBO,71,23,95,58,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | WS_VSCROLL | WS_TABSTOP + PUSHBUTTON "Remove",IDC_REMOVELANG_BUTTON,243,40,62,14 + PUSHBUTTON "Save As...",IDC_SAVEAS_BUTTON,104,40,62,14 + LTEXT "User Language : ",IDC_LANGNAME_STATIC,5,24,63,8,0,WS_EX_RIGHT + EDITTEXT IDC_EXT_EDIT,291,23,33,14,ES_AUTOHSCROLL + RTEXT "Ext :",IDC_EXT_STATIC,257,25,33,8,0,WS_EX_RIGHT + CONTROL "Transparency",IDC_UD_TRANSPARENT_CHECK,"Button",BS_AUTOCHECKBOX | NOT WS_VISIBLE | WS_TABSTOP,150,3,66,10 + CONTROL "",IDC_UD_PERCENTAGE_SLIDER,"msctls_trackbar32",TBS_BOTH | TBS_NOTICKS | NOT WS_VISIBLE | WS_TABSTOP,209,3,53,10 + CONTROL "Ignore case",IDC_LANGNAME_IGNORECASE_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,175,24,76,10 +END + +IDD_STRING_DLG DIALOGEX 0, 0, 151, 52 +STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | + WS_SYSMENU +EXSTYLE WS_EX_TOOLWINDOW +FONT 8, TEXT("MS Shell Dlg"), 0, 0, 0x1 +BEGIN + LTEXT "STATIC :",IDC_STRING_STATIC,6,4,42,8,0,WS_EX_RIGHT + EDITTEXT IDC_STRING_EDIT,49,2,88,14 + PUSHBUTTON "OK",IDOK,20,26,50,14 + PUSHBUTTON "Cancel",IDCANCEL,87,26,50,14 +END + +#endif //USERDEFINEDIALOG_RC + diff --git a/PowerEditor/src/ScitillaComponent/UserDefineLangReference.h b/PowerEditor/src/ScitillaComponent/UserDefineLangReference.h new file mode 100644 index 00000000..0975ea28 --- /dev/null +++ b/PowerEditor/src/ScitillaComponent/UserDefineLangReference.h @@ -0,0 +1,36 @@ +/* +this file is part of Notepad++ +Copyright (C)2003 Don HO + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef USER_DEFINE_LANG_REFERENCE_H + +#define USER_DEFINE_LANG_REFERENCE_H + +const int langNameLenMax = 16; +const int extsLenMax = 256; + +const int nbKeywodList = 9; +//const int max_char = 4096; +const int max_char = 1024*30; + +const int nbPrefixListAllowed = 4; + + +#endif //USER_DEFINE_LANG_REFERENCE_H + + diff --git a/PowerEditor/src/ScitillaComponent/UserDefineResource.h b/PowerEditor/src/ScitillaComponent/UserDefineResource.h new file mode 100644 index 00000000..73fda5f5 --- /dev/null +++ b/PowerEditor/src/ScitillaComponent/UserDefineResource.h @@ -0,0 +1,265 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef USERDEFINE_RC_H +#define USERDEFINE_RC_H + +#define IDD_GLOBAL_USERDEFINE_DLG 20000 + #define IDC_DOCK_BUTTON (IDD_GLOBAL_USERDEFINE_DLG + 1) + #define IDC_RENAME_BUTTON (IDD_GLOBAL_USERDEFINE_DLG + 2) + #define IDC_ADDNEW_BUTTON (IDD_GLOBAL_USERDEFINE_DLG + 3) + #define IDC_REMOVELANG_BUTTON (IDD_GLOBAL_USERDEFINE_DLG + 4) + #define IDC_SAVEAS_BUTTON (IDD_GLOBAL_USERDEFINE_DLG + 5) + #define IDC_LANGNAME_COMBO (IDD_GLOBAL_USERDEFINE_DLG + 6) + #define IDC_LANGNAME_STATIC (IDD_GLOBAL_USERDEFINE_DLG + 7) + #define IDC_EXT_EDIT (IDD_GLOBAL_USERDEFINE_DLG + 8) + #define IDC_EXT_STATIC (IDD_GLOBAL_USERDEFINE_DLG + 9) + + #define IDC_UD_PERCENTAGE_SLIDER (IDD_GLOBAL_USERDEFINE_DLG + 10) + #define IDC_UD_TRANSPARENT_CHECK (IDD_GLOBAL_USERDEFINE_DLG + 11) + #define IDC_LANGNAME_IGNORECASE_CHECK (IDD_GLOBAL_USERDEFINE_DLG + 12) + #define IDC_AUTOCOMPLET_EDIT (IDD_GLOBAL_USERDEFINE_DLG + 13) + #define IDC_AUTOCOMPLET_STATIC (IDD_GLOBAL_USERDEFINE_DLG + 14) + +#define IDD_FOLDER_STYLE_DLG 21000 + + #define IDC_DEFAULT (IDD_FOLDER_STYLE_DLG + 100) + #define IDC_DEFAULT_DESCGROUP_STATIC (IDC_DEFAULT+ 1) + #define IDC_DEFAULT_FG_STATIC (IDC_DEFAULT+ 2) + #define IDC_DEFAULT_BG_STATIC (IDC_DEFAULT + 3) + #define IDC_DEFAULT_FONT_COMBO (IDC_DEFAULT+ 4) + #define IDC_DEFAULT_FONTSIZE_COMBO (IDC_DEFAULT + 5) + #define IDC_DEFAULT_BOLD_CHECK (IDC_DEFAULT + 6) + #define IDC_DEFAULT_ITALIC_CHECK (IDC_DEFAULT + 7) + #define IDC_DEFAULT_FONTSTYLEGROUP_STATIC (IDC_DEFAULT+ 8) + #define IDC_DEFAULT_COLORSTYLEGROUP_STATIC (IDC_DEFAULT + 9) + #define IDC_DEFAULT_FONTNAME_STATIC (IDC_DEFAULT + 10) + #define IDC_DEFAULT_FONTSIZE_STATIC (IDC_DEFAULT+ 11) + #define IDC_DEFAULT_EDIT (IDC_DEFAULT+ 12) + #define IDC_DEFAULT_UNDERLINE_CHECK (IDC_DEFAULT + 13) + + #define IDC_FOLDEROPEN (IDD_FOLDER_STYLE_DLG + 200) + #define IDC_FOLDEROPEN_DESCGROUP_STATIC (IDC_FOLDEROPEN + 1) + #define IDC_FOLDEROPEN_FG_STATIC (IDC_FOLDEROPEN + 2) + #define IDC_FOLDEROPEN_BG_STATIC (IDC_FOLDEROPEN + 3) + #define IDC_FOLDEROPEN_FONT_COMBO (IDC_FOLDEROPEN + 4) + #define IDC_FOLDEROPEN_FONTSIZE_COMBO (IDC_FOLDEROPEN + 5) + #define IDC_FOLDEROPEN_BOLD_CHECK (IDC_FOLDEROPEN + 6) + #define IDC_FOLDEROPEN_ITALIC_CHECK (IDC_FOLDEROPEN + 7) + #define IDC_FOLDEROPEN_FONTSTYLEGROUP_STATIC (IDC_FOLDEROPEN + 8) + #define IDC_FOLDEROPEN_COLORSTYLEGROUP_STATIC (IDC_FOLDEROPEN + 9) + #define IDC_FOLDEROPEN_FONTNAME_STATIC (IDC_FOLDEROPEN + 10) + #define IDC_FOLDEROPEN_FONTSIZE_STATIC (IDC_FOLDEROPEN + 11) + #define IDC_FOLDEROPEN_EDIT (IDC_FOLDEROPEN + 12) + #define IDC_FOLDEROPEN_UNDERLINE_CHECK (IDC_FOLDEROPEN + 13) + + #define IDC_FOLDERCLOSE (IDD_FOLDER_STYLE_DLG + 300) + #define IDC_FOLDERCLOSE_DESCGROUP_STATIC (IDC_FOLDERCLOSE + 1) + #define IDC_FOLDERCLOSE_FG_STATIC (IDC_FOLDERCLOSE + 2) + #define IDC_FOLDERCLOSE_BG_STATIC (IDC_FOLDERCLOSE + 3) + #define IDC_FOLDERCLOSE_FONT_COMBO (IDC_FOLDERCLOSE + 4) + #define IDC_FOLDERCLOSE_FONTSIZE_COMBO (IDC_FOLDERCLOSE + 5) + #define IDC_FOLDERCLOSE_BOLD_CHECK (IDC_FOLDERCLOSE + 6) + #define IDC_FOLDERCLOSE_ITALIC_CHECK (IDC_FOLDERCLOSE + 7) + #define IDC_FOLDERCLOSE_FONTSTYLEGROUP_STATIC (IDC_FOLDERCLOSE + 8) + #define IDC_FOLDERCLOSE_COLORSTYLEGROUP_STATIC (IDC_FOLDERCLOSE + 9) + #define IDC_FOLDERCLOSE_FONTNAME_STATIC (IDC_FOLDERCLOSE + 10) + #define IDC_FOLDERCLOSE_FONTSIZE_STATIC (IDC_FOLDERCLOSE + 11) + #define IDC_FOLDERCLOSE_EDIT (IDC_FOLDERCLOSE + 12) + #define IDC_FOLDERCLOSE_UNDERLINE_CHECK (IDC_FOLDERCLOSE + 13) + +#define IDD_KEYWORD_STYLE_DLG 22000 //(IDD_GLOBAL_USERDEFINE_DLG + 2000) + + #define IDC_KEYWORD1 (IDD_KEYWORD_STYLE_DLG + 100) + #define IDC_KEYWORD1_DESCGROUP_STATIC (IDC_KEYWORD1 + 1) + #define IDC_KEYWORD1_FG_STATIC (IDC_KEYWORD1 + 2) + #define IDC_KEYWORD1_BG_STATIC (IDC_KEYWORD1 + 3) + #define IDC_KEYWORD1_FONT_COMBO (IDC_KEYWORD1 + 4) + #define IDC_KEYWORD1_FONTSIZE_COMBO (IDC_KEYWORD1 + 5) + #define IDC_KEYWORD1_BOLD_CHECK (IDC_KEYWORD1 + 6) + #define IDC_KEYWORD1_ITALIC_CHECK (IDC_KEYWORD1 + 7) + #define IDC_KEYWORD1_FONTSTYLEGROUP_STATIC (IDC_KEYWORD1 + 8) + #define IDC_KEYWORD1_COLORSTYLEGROUP_STATIC (IDC_KEYWORD1 + 9) + #define IDC_KEYWORD1_FONTNAME_STATIC (IDC_KEYWORD1 + 10) + #define IDC_KEYWORD1_FONTSIZE_STATIC (IDC_KEYWORD1 + 11) + #define IDC_KEYWORD1_EDIT (IDC_KEYWORD1 + 12) + #define IDC_KEYWORD1_PREFIX_CHECK (IDC_KEYWORD1 + 13) + #define IDC_KEYWORD1_UNDERLINE_CHECK (IDC_KEYWORD1 + 14) + + #define IDC_KEYWORD2 (IDD_KEYWORD_STYLE_DLG + 200) + #define IDC_KEYWORD2_DESCGROUP_STATIC (IDC_KEYWORD2 + 1) + #define IDC_KEYWORD2_FG_STATIC (IDC_KEYWORD2 + 2) + #define IDC_KEYWORD2_BG_STATIC (IDC_KEYWORD2 + 3) + #define IDC_KEYWORD2_FONT_COMBO (IDC_KEYWORD2 + 4) + #define IDC_KEYWORD2_FONTSIZE_COMBO (IDC_KEYWORD2 + 5) + #define IDC_KEYWORD2_BOLD_CHECK (IDC_KEYWORD2 + 6) + #define IDC_KEYWORD2_ITALIC_CHECK (IDC_KEYWORD2 + 7) + #define IDC_KEYWORD2_FONTSTYLEGROUP_STATIC (IDC_KEYWORD2 + 8) + #define IDC_KEYWORD2_COLORSTYLEGROUP_STATIC (IDC_KEYWORD2 + 9) + #define IDC_KEYWORD2_FONTNAME_STATIC (IDC_KEYWORD2 + 10) + #define IDC_KEYWORD2_FONTSIZE_STATIC (IDC_KEYWORD2 + 11) + #define IDC_KEYWORD2_EDIT (IDC_KEYWORD2 + 12) + #define IDC_KEYWORD2_PREFIX_CHECK (IDC_KEYWORD2 + 13) + #define IDC_KEYWORD2_UNDERLINE_CHECK (IDC_KEYWORD2 + 14) + + #define IDC_KEYWORD3 (IDD_KEYWORD_STYLE_DLG + 300) + #define IDC_KEYWORD3_DESCGROUP_STATIC (IDC_KEYWORD3 + 1) + #define IDC_KEYWORD3_FG_STATIC (IDC_KEYWORD3 + 2) + #define IDC_KEYWORD3_BG_STATIC (IDC_KEYWORD3 + 3) + #define IDC_KEYWORD3_FONT_COMBO (IDC_KEYWORD3 + 4) + #define IDC_KEYWORD3_FONTSIZE_COMBO (IDC_KEYWORD3 + 5) + #define IDC_KEYWORD3_BOLD_CHECK (IDC_KEYWORD3 + 6) + #define IDC_KEYWORD3_ITALIC_CHECK (IDC_KEYWORD3 + 7) + #define IDC_KEYWORD3_FONTSTYLEGROUP_STATIC (IDC_KEYWORD3 + 8) + #define IDC_KEYWORD3_COLORSTYLEGROUP_STATIC (IDC_KEYWORD3 + 9) + #define IDC_KEYWORD3_FONTNAME_STATIC (IDC_KEYWORD3 + 10) + #define IDC_KEYWORD3_FONTSIZE_STATIC (IDC_KEYWORD3 + 11) + #define IDC_KEYWORD3_EDIT (IDC_KEYWORD3 + 12) + #define IDC_KEYWORD3_PREFIX_CHECK (IDC_KEYWORD3 + 13) + #define IDC_KEYWORD3_UNDERLINE_CHECK (IDC_KEYWORD3 + 14) + + #define IDC_KEYWORD4 (IDD_KEYWORD_STYLE_DLG + 400) + #define IDC_KEYWORD4_DESCGROUP_STATIC (IDC_KEYWORD4 + 1) + #define IDC_KEYWORD4_FG_STATIC (IDC_KEYWORD4 + 2) + #define IDC_KEYWORD4_BG_STATIC (IDC_KEYWORD4 + 3) + #define IDC_KEYWORD4_FONT_COMBO (IDC_KEYWORD4 + 4) + #define IDC_KEYWORD4_FONTSIZE_COMBO (IDC_KEYWORD4 + 5) + #define IDC_KEYWORD4_BOLD_CHECK (IDC_KEYWORD4 + 6) + #define IDC_KEYWORD4_ITALIC_CHECK (IDC_KEYWORD4 + 7) + #define IDC_KEYWORD4_FONTSTYLEGROUP_STATIC (IDC_KEYWORD4 + 8) + #define IDC_KEYWORD4_COLORSTYLEGROUP_STATIC (IDC_KEYWORD4 + 9) + #define IDC_KEYWORD4_FONTNAME_STATIC (IDC_KEYWORD4 + 10) + #define IDC_KEYWORD4_FONTSIZE_STATIC (IDC_KEYWORD4 + 11) + #define IDC_KEYWORD4_EDIT (IDC_KEYWORD4 + 12) + #define IDC_KEYWORD4_PREFIX_CHECK (IDC_KEYWORD4 + 13) + #define IDC_KEYWORD4_UNDERLINE_CHECK (IDC_KEYWORD4 + 14) + + #define IDC_KEYWORD_SCROLLBAR (IDD_KEYWORD_STYLE_DLG + 500) + +#define IDD_COMMENT_STYLE_DLG 23000 //(IDD_GLOBAL_USERDEFINE_DLG + 3000) + + #define IDC_COMMENT (IDD_COMMENT_STYLE_DLG + 100) + #define IDC_COMMENT_DESCGROUP_STATIC (IDC_COMMENT + 1) + #define IDC_COMMENT_FG_STATIC (IDC_COMMENT + 2) + #define IDC_COMMENT_BG_STATIC (IDC_COMMENT+ 3) + #define IDC_COMMENT_FONT_COMBO (IDC_COMMENT + 4) + #define IDC_COMMENT_FONTSIZE_COMBO (IDC_COMMENT+ 5) + #define IDC_COMMENT_BOLD_CHECK (IDC_COMMENT+ 6) + #define IDC_COMMENT_ITALIC_CHECK (IDC_COMMENT+ 7) + #define IDC_COMMENT_FONTSTYLEGROUP_STATIC (IDC_COMMENT+ 8) + #define IDC_COMMENT_COLORSTYLEGROUP_STATIC (IDC_COMMENT+ 9) + #define IDC_COMMENT_FONTNAME_STATIC (IDC_COMMENT+ 10) + #define IDC_COMMENT_FONTSIZE_STATIC (IDC_COMMENT+ 11) + #define IDC_COMMENTOPEN_EDIT (IDC_COMMENT+ 12) + #define IDC_COMMENTOPEN_STATIC (IDC_COMMENT+ 13) + #define IDC_COMMENTCLOSE_EDIT (IDC_COMMENT + 14) + #define IDC_COMMENTCLOSE_STATIC (IDC_COMMENT + 15) + #define IDC_COMMENTLINESYMBOL_CHECK (IDC_COMMENT + 16) + #define IDC_COMMENTSYMBOL_CHECK (IDC_COMMENT + 17) + #define IDC_COMMENT_UNDERLINE_CHECK (IDC_NUMBER + 18) + + #define IDC_NUMBER (IDD_COMMENT_STYLE_DLG + 200) + #define IDC_NUMBER_DESCGROUP_STATIC (IDC_NUMBER+ 1) + #define IDC_NUMBER_FG_STATIC (IDC_NUMBER+ 2) + #define IDC_NUMBER_BG_STATIC (IDC_NUMBER + 3) + #define IDC_NUMBER_FONT_COMBO (IDC_NUMBER+ 4) + #define IDC_NUMBER_FONTSIZE_COMBO (IDC_NUMBER + 5) + #define IDC_NUMBER_BOLD_CHECK (IDC_NUMBER + 6) + #define IDC_NUMBER_ITALIC_CHECK (IDC_NUMBER + 7) + #define IDC_NUMBER_FONTSTYLEGROUP_STATIC (IDC_NUMBER + 8) + #define IDC_NUMBER_COLORSTYLEGROUP_STATIC (IDC_NUMBER + 9) + #define IDC_NUMBER_FONTNAME_STATIC (IDC_NUMBER + 10) + #define IDC_NUMBER_FONTSIZE_STATIC (IDC_NUMBER + 11) + #define IDC_NUMBER_UNDERLINE_CHECK (IDC_NUMBER + 12) + + #define IDC_COMMENTLINE (IDD_COMMENT_STYLE_DLG + 300) + #define IDC_COMMENTLINE_DESCGROUP_STATIC (IDC_COMMENTLINE + 1) + #define IDC_COMMENTLINE_FG_STATIC (IDC_COMMENTLINE + 2) + #define IDC_COMMENTLINE_BG_STATIC (IDC_COMMENTLINE + 3) + #define IDC_COMMENTLINE_FONT_COMBO (IDC_COMMENTLINE + 4) + #define IDC_COMMENTLINE_FONTSIZE_COMBO (IDC_COMMENTLINE + 5) + #define IDC_COMMENTLINE_BOLD_CHECK (IDC_COMMENTLINE + 6) + #define IDC_COMMENTLINE_ITALIC_CHECK (IDC_COMMENTLINE + 7) + #define IDC_COMMENTLINE_FONTSTYLEGROUP_STATIC (IDC_COMMENTLINE + 8) + #define IDC_COMMENTLINE_COLORSTYLEGROUP_STATIC (IDC_COMMENTLINE + 9) + #define IDC_COMMENTLINE_FONTNAME_STATIC (IDC_COMMENTLINE + 10) + #define IDC_COMMENTLINE_FONTSIZE_STATIC (IDC_COMMENTLINE + 11) + #define IDC_COMMENTLINE_EDIT (IDC_COMMENTLINE + 12) + #define IDC_COMMENTLINE_UNDERLINE_CHECK (IDC_COMMENTLINE + 13) + +#define IDD_SYMBOL_STYLE_DLG 24000 //IDD_GLOBAL_USERDEFINE_DLG + 4000 + #define IDC_SYMBOL (IDD_SYMBOL_STYLE_DLG + 100) + #define IDC_ACTIVATED_SYMBOL_STATIC (IDC_SYMBOL + 1) + #define IDC_ACTIVATED_SYMBOL_LIST (IDC_SYMBOL + 2) + #define IDC_AVAILABLE_SYMBOLS_STATIC (IDC_SYMBOL + 3) + #define IDC_AVAILABLE_SYMBOLS_LIST (IDC_SYMBOL + 4) + #define IDC_ADD_BUTTON (IDC_SYMBOL + 5) + #define IDC_REMOVE_BUTTON (IDC_SYMBOL + 6) + #define IDC_SYMBOL_DESCGROUP_STATIC (IDC_SYMBOL+ 7) + #define IDC_SYMBOL_FG_STATIC (IDC_SYMBOL + 8) + #define IDC_SYMBOL_BG_STATIC (IDC_SYMBOL + 9) + #define IDC_SYMBOL_FONT_COMBO (IDC_SYMBOL + 10) + #define IDC_SYMBOL_FONTSIZE_COMBO (IDC_SYMBOL + 11) + #define IDC_SYMBOL_BOLD_CHECK (IDC_SYMBOL+ 12) + #define IDC_SYMBOL_ITALIC_CHECK (IDC_SYMBOL + 13) + #define IDC_SYMBOL_FONTSTYLEGROUP_STATIC (IDC_SYMBOL + 14) + #define IDC_SYMBOL_COLORSTYLEGROUP_STATIC ( IDC_SYMBOL + 15) + #define IDC_SYMBOL_FONTNAME_STATIC (IDC_SYMBOL + 16) + #define IDC_SYMBOL_FONTSIZE_STATIC (IDC_SYMBOL + 17) + #define IDC_SYMBOL_UNDERLINE_CHECK (IDC_SYMBOL + 18) + + #define IDC_SYMBOL2 (IDD_SYMBOL_STYLE_DLG + 200) + #define IDC_SYMBOL_DELIMGROUP1_STATIC (IDC_SYMBOL2 + 1) + #define IDC_SYMBOL_COLORSTYLEGROUP2_STATIC (IDC_SYMBOL2 + 2) + #define IDC_SYMBOL_FONTSTYLEGROUP2_STATIC (IDC_SYMBOL2 + 3) + #define IDC_SYMBOL_FG2_STATIC (IDC_SYMBOL2 + 4) + #define IDC_SYMBOL_BG2_STATIC (IDC_SYMBOL2 + 5) + #define IDC_SYMBOL_FONTNAME2_STATIC (IDC_SYMBOL2 + 6) + #define IDC_SYMBOL_BOLD2_CHECK (IDC_SYMBOL2 + 7) + #define IDC_SYMBOL_ITALIC2_CHECK (IDC_SYMBOL2 + 8) + #define IDC_SYMBOL_FONT2_COMBO (IDC_SYMBOL2 + 9) + #define IDC_SYMBOL_UNDERLINE2_CHECK (IDC_SYMBOL2 + 10) + #define IDC_SYMBOL_BO2_STATIC (IDC_SYMBOL2 + 11) + #define IDC_SYMBOL_BO2_COMBO (IDC_SYMBOL2 + 12) + #define IDC_SYMBOL_BC2_COMBO (IDC_SYMBOL2 + 13) + #define IDC_SYMBOL_BC2_STATIC (IDC_SYMBOL2 + 14) + #define IDC_SYMBOL_FONTSIZE2_COMBO (IDC_SYMBOL2 + 15) + #define IDC_SYMBOL_FONTSIZE2_STATIC (IDC_SYMBOL2 + 16) + + #define IDC_SYMBOL3 (IDD_SYMBOL_STYLE_DLG + 300) + #define IDC_SYMBOL_DELIMGROUP2_STATIC (IDC_SYMBOL3 + 1) + #define IDC_SYMBOL_FG3_STATIC (IDC_SYMBOL3 + 2) + #define IDC_SYMBOL_BG3_STATIC (IDC_SYMBOL3 + 3) + #define IDC_SYMBOL_FONT3_COMBO (IDC_SYMBOL3 + 4) + #define IDC_SYMBOL_BO3_COMBO (IDC_SYMBOL3 + 5) + #define IDC_SYMBOL_BOLD3_CHECK (IDC_SYMBOL3 + 6) + #define IDC_SYMBOL_ITALIC3_CHECK (IDC_SYMBOL3 + 7) + #define IDC_SYMBOL_FONTSTYLEGROUP3_STATIC (IDC_SYMBOL3 + 8) + #define IDC_SYMBOL_COLORSTYLEGROUP3_STATIC (IDC_SYMBOL3 + 9) + #define IDC_SYMBOL_FONTNAME3_STATIC (IDC_SYMBOL3 + 10) + #define IDC_SYMBOL_BO3_STATIC (IDC_SYMBOL3 + 11) + #define IDC_SYMBOL_UNDERLINE3_CHECK (IDC_SYMBOL3 + 12) + #define IDC_SYMBOL_BC3_COMBO (IDC_SYMBOL3 + 13) + #define IDC_SYMBOL_BC3_STATIC (IDC_SYMBOL3 + 14) + #define IDC_SYMBOL_FONTSIZE3_COMBO (IDC_SYMBOL3 + 15) + #define IDC_SYMBOL_FONTSIZE3_STATIC (IDC_SYMBOL3 + 16) + +#define IDD_STRING_DLG 25000 + #define IDC_STRING_STATIC (IDD_STRING_DLG + 1) + #define IDC_STRING_EDIT (IDD_STRING_DLG + 2) +#endif //USERDEFIN_RC_H + diff --git a/PowerEditor/src/ScitillaComponent/colors.h b/PowerEditor/src/ScitillaComponent/colors.h new file mode 100644 index 00000000..158c6dff --- /dev/null +++ b/PowerEditor/src/ScitillaComponent/colors.h @@ -0,0 +1,62 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef COLORS_H +#define COLORS_H + +#include + +const COLORREF red = RGB(0xFF, 0, 0); +const COLORREF darkRed = RGB(0x80, 0, 0); +const COLORREF offWhite = RGB(0xFF, 0xFB, 0xF0); +const COLORREF darkGreen = RGB(0, 0x80, 0); +const COLORREF liteGreen = RGB(0, 0xFF, 0); +const COLORREF blueGreen = RGB(0, 0x80, 0x80); +const COLORREF liteRed = RGB(0xFF, 0xAA, 0xAA); +const COLORREF liteBlueGreen = RGB(0xAA, 0xFF, 0xC8); + +const COLORREF liteBlue = RGB(0xA6, 0xCA, 0xF0); +const COLORREF veryLiteBlue = RGB(0xC4, 0xF9, 0xFD); +const COLORREF extremeLiteBlue = RGB(0xF2, 0xF4, 0xFF); + +const COLORREF darkBlue = RGB(0, 0, 0x80); +const COLORREF blue = RGB(0, 0, 0xFF); +const COLORREF black = RGB(0, 0, 0); +const COLORREF white = RGB(0xFF, 0xFF, 0xFF); +const COLORREF darkGrey = RGB(64, 64, 64); +const COLORREF grey = RGB(128, 128, 128); +const COLORREF liteGrey = RGB(192, 192, 192); +const COLORREF veryLiteGrey = RGB(224, 224, 224); +const COLORREF brown = RGB(128, 64, 0); +//const COLORREF greenBlue = RGB(192, 128, 64); +const COLORREF darkYellow = RGB(0xFF, 0xC0, 0); +const COLORREF yellow = RGB(0xFF, 0xFF, 0); +const COLORREF cyan = RGB(0, 0xFF, 0xFF); +const COLORREF orange = RGB(0xFF, 0x80, 0x00); +const COLORREF purple = RGB(0x80, 0x00, 0xFF); +const COLORREF deepPurple = RGB(0x87, 0x13, 0x97); + +const COLORREF extremeLitePurple = RGB(0xF8, 0xE8, 0xFF); +const COLORREF veryLitePurple = RGB(0xE7, 0xD8, 0xE9); +const COLORREF liteBerge = RGB(0xFE, 0xFC, 0xF5); +const COLORREF berge = RGB(0xFD, 0xF8, 0xE3); +/* +#define RGB2int(color) + (((((long)color) & 0x0000FF) << 16) | ((((long)color) & 0x00FF00)) | ((((long)color) & 0xFF0000) >> 16)) +*/ +#endif //COLORS_H + diff --git a/PowerEditor/src/ScitillaComponent/columnEditor.cpp b/PowerEditor/src/ScitillaComponent/columnEditor.cpp new file mode 100644 index 00000000..e1899988 --- /dev/null +++ b/PowerEditor/src/ScitillaComponent/columnEditor.cpp @@ -0,0 +1,255 @@ +/* +this file is part of notepad++ +Copyright (C)2003 Don HO ( donho@altern.org ) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "columnEditor.h" + +BOOL CALLBACK ColumnEditorDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) +{ + switch (message) + { + case WM_INITDIALOG : + { + switchTo(activeText); + ::SendDlgItemMessage(_hSelf, IDC_COL_DEC_RADIO, BM_SETCHECK, TRUE, 0); + goToCenter(); + + NppParameters *pNppParam = NppParameters::getInstance(); + ETDTProc enableDlgTheme = (ETDTProc)pNppParam->getEnableThemeDlgTexture(); + if (enableDlgTheme) + { + enableDlgTheme(_hSelf, ETDT_ENABLETAB); + redraw(); + } + return TRUE; + } + case WM_COMMAND : + { + switch (wParam) + { + case IDCANCEL : // Close + display(false); + return TRUE; + + case IDOK : + { + (*_ppEditView)->execute(SCI_BEGINUNDOACTION); + + const int stringSize = 1024; + TCHAR str[stringSize]; + + bool isTextMode = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_COL_TEXT_RADIO, BM_GETCHECK, 0, 0)); + + if (isTextMode) + { + ::SendDlgItemMessage(_hSelf, IDC_COL_TEXT_EDIT, WM_GETTEXT, stringSize, (LPARAM)str); + + display(false); + + if ((*_ppEditView)->execute(SCI_SELECTIONISRECTANGLE)) + { + ColumnModeInfo colInfos = (*_ppEditView)->getColumnModeSelectInfo(); + (*_ppEditView)->columnReplace(colInfos, str); + (*_ppEditView)->execute(SCI_SETCURRENTPOS,colInfos[colInfos.size()-1].second); + + //(*_ppEditView)->execute(SCI_SETSEL, colInfos[0].first, colInfos[colInfos.size()-1].second); + //(*_ppEditView)->execute(SCI_SETSELECTIONMODE, 1); + } + else + { + int cursorPos = (*_ppEditView)->execute(SCI_GETCURRENTPOS); + int cursorCol = (*_ppEditView)->execute(SCI_GETCOLUMN, cursorPos); + int cursorLine = (*_ppEditView)->execute(SCI_LINEFROMPOSITION, cursorPos); + int endPos = (*_ppEditView)->execute(SCI_GETLENGTH); + int endLine = (*_ppEditView)->execute(SCI_LINEFROMPOSITION, endPos); + + int lineAllocatedLen = 1024; + TCHAR *line = new TCHAR[lineAllocatedLen]; + + for (int i = cursorLine ; i <= endLine ; i++) + { + int lineBegin = (*_ppEditView)->execute(SCI_POSITIONFROMLINE, i); + int lineEnd = (*_ppEditView)->execute(SCI_GETLINEENDPOSITION, i); + + int lineEndCol = (*_ppEditView)->execute(SCI_GETCOLUMN, lineEnd); + int lineLen = lineEnd - lineBegin + 1; + + if (lineLen > lineAllocatedLen) + { + delete [] line; + line = new TCHAR[lineLen]; + } + (*_ppEditView)->getGenericText(line, lineBegin, lineEnd); + generic_string s2r(line); + + if (lineEndCol < cursorCol) + { + generic_string s_space(cursorCol - lineEndCol, ' '); + s2r.append(s_space); + s2r.append(str); + } + else + { + int posAbs2Start = (*_ppEditView)->execute(SCI_FINDCOLUMN, i, cursorCol); + int posRelative2Start = posAbs2Start - lineBegin; + s2r.insert(posRelative2Start, str); + } + (*_ppEditView)->replaceTarget(s2r.c_str(), lineBegin, lineEnd); + } + delete [] line; + } + } + else + { + int initialNumber = ::GetDlgItemInt(_hSelf, IDC_COL_INITNUM_EDIT, NULL, TRUE); + int increaseNumber = ::GetDlgItemInt(_hSelf, IDC_COL_INCREASENUM_EDIT, NULL, TRUE); + UCHAR format = getFormat(); + display(false); + + if ((*_ppEditView)->execute(SCI_SELECTIONISRECTANGLE)) + { + ColumnModeInfo colInfos = (*_ppEditView)->getColumnModeSelectInfo(); + (*_ppEditView)->columnReplace(colInfos, initialNumber, increaseNumber, format); + (*_ppEditView)->execute(SCI_SETCURRENTPOS,colInfos[colInfos.size()-1].second); + } + else + { + int cursorPos = (*_ppEditView)->execute(SCI_GETCURRENTPOS); + int cursorCol = (*_ppEditView)->execute(SCI_GETCOLUMN, cursorPos); + int cursorLine = (*_ppEditView)->execute(SCI_LINEFROMPOSITION, cursorPos); + int endPos = (*_ppEditView)->execute(SCI_GETLENGTH); + int endLine = (*_ppEditView)->execute(SCI_LINEFROMPOSITION, endPos); + + int lineAllocatedLen = 1024; + TCHAR *line = new TCHAR[lineAllocatedLen]; + + + UCHAR f = format & MASK_FORMAT; + bool isZeroLeading = (MASK_ZERO_LEADING & format) != 0; + + int base = 10; + if (f == BASE_16) + base = 16; + else if (f == BASE_08) + base = 8; + else if (f == BASE_02) + base = 2; + + int nbLine = endLine - cursorLine + 1; + int endNumber = initialNumber + increaseNumber * (nbLine - 1); + int nbEnd = getNbChiffre(endNumber, base); + int nbInit = getNbChiffre(initialNumber, base); + int nb = max(nbInit, nbEnd); + + + for (int i = cursorLine ; i <= endLine ; i++) + { + int lineBegin = (*_ppEditView)->execute(SCI_POSITIONFROMLINE, i); + int lineEnd = (*_ppEditView)->execute(SCI_GETLINEENDPOSITION, i); + + int lineEndCol = (*_ppEditView)->execute(SCI_GETCOLUMN, lineEnd); + int lineLen = lineEnd - lineBegin + 1; + + if (lineLen > lineAllocatedLen) + { + delete [] line; + line = new TCHAR[lineLen]; + } + (*_ppEditView)->getGenericText(line, lineBegin, lineEnd); + generic_string s2r(line); + + /* + Calcule generic_string + */ + int2str(str, stringSize, initialNumber, base, nb, isZeroLeading); + initialNumber += increaseNumber; + + if (lineEndCol < cursorCol) + { + generic_string s_space(cursorCol - lineEndCol, ' '); + s2r.append(s_space); + s2r.append(str); + } + else + { + int posAbs2Start = (*_ppEditView)->execute(SCI_FINDCOLUMN, i, cursorCol); + int posRelative2Start = posAbs2Start - lineBegin; + s2r.insert(posRelative2Start, str); + } + + (*_ppEditView)->replaceTarget(s2r.c_str(), lineBegin, lineEnd); + } + delete [] line; + } + } + (*_ppEditView)->execute(SCI_ENDUNDOACTION); + (*_ppEditView)->getFocus(); + return TRUE; + } + case IDC_COL_TEXT_RADIO : + case IDC_COL_NUM_RADIO : + { + switchTo((wParam == IDC_COL_TEXT_RADIO)? activeText : activeNumeric); + return TRUE; + } + + default : + { + switch (HIWORD(wParam)) + { + case EN_SETFOCUS : + case BN_SETFOCUS : + //updateLinesNumbers(); + return TRUE; + default : + return TRUE; + } + break; + } + } + } + + default : + return FALSE; + } + return FALSE; +} + +void ColumnEditorDlg::switchTo(bool toText) +{ + HWND hText = ::GetDlgItem(_hSelf, IDC_COL_TEXT_EDIT); + ::EnableWindow(hText, toText); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_COL_TEXT_GRP_STATIC), toText); + ::SendDlgItemMessage(_hSelf, IDC_COL_TEXT_RADIO, BM_SETCHECK, toText, 0); + + HWND hNum = ::GetDlgItem(_hSelf, IDC_COL_INITNUM_EDIT); + ::SendDlgItemMessage(_hSelf, IDC_COL_NUM_RADIO, BM_SETCHECK, !toText, 0); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_COL_NUM_GRP_STATIC), !toText); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_COL_INITNUM_STATIC), !toText); + ::EnableWindow(hNum, !toText); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_COL_INCRNUM_STATIC), !toText); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_COL_INCREASENUM_EDIT), !toText); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_COL_FORMAT_GRP_STATIC), !toText); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_COL_DEC_RADIO), !toText); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_COL_HEX_RADIO), !toText); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_COL_OCT_RADIO), !toText); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_COL_BIN_RADIO), !toText); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_COL_LEADZERO_CHECK), !toText); + + ::SetFocus(toText?hText:hNum); +} \ No newline at end of file diff --git a/PowerEditor/src/ScitillaComponent/columnEditor.h b/PowerEditor/src/ScitillaComponent/columnEditor.h new file mode 100644 index 00000000..aebcde90 --- /dev/null +++ b/PowerEditor/src/ScitillaComponent/columnEditor.h @@ -0,0 +1,83 @@ +/* +this file is part of notepad++ +Copyright (C)2003 Don HO ( donho@altern.org ) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef COLUMNEDITOR_H +#define COLUMNEDITOR_H + +#include "columnEditor_rc.h" +#include "StaticDialog.h" +#include "ScintillaEditView.h" + +const bool activeText = true; +const bool activeNumeric = false; + +class ColumnEditorDlg : public StaticDialog +{ +public : + ColumnEditorDlg() : StaticDialog() {}; + + void init(HINSTANCE hInst, HWND hPere, ScintillaEditView **ppEditView) { + Window::init(hInst, hPere); + if (!ppEditView) + throw int(9900); + _ppEditView = ppEditView; + }; + + virtual void create(int dialogID, bool isRTL = false) { + StaticDialog::create(dialogID, isRTL); + }; + + void doDialog(bool isRTL = false) { + if (!isCreated()) + create(IDD_COLUMNEDIT, isRTL); + bool isTextMode = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_COL_TEXT_RADIO, BM_GETCHECK, 0, 0)); + display(); + ::SetFocus(::GetDlgItem(_hSelf, isTextMode?IDC_COL_TEXT_EDIT:IDC_COL_INITNUM_EDIT)); + }; + + virtual void display(bool toShow = true) const { + Window::display(toShow); + if (toShow) + ::SetFocus(::GetDlgItem(_hSelf, ID_GOLINE_EDIT)); + }; + + void switchTo(bool toText); + + UCHAR getFormat() { + bool isLeadingZeros = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_COL_LEADZERO_CHECK, BM_GETCHECK, 0, 0)); + UCHAR f = 0; // Dec by default + if (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_COL_HEX_RADIO, BM_GETCHECK, 0, 0)) + f = 1; + else if (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_COL_OCT_RADIO, BM_GETCHECK, 0, 0)) + f = 2; + else if (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_COL_BIN_RADIO, BM_GETCHECK, 0, 0)) + f = 3; + return (f | (isLeadingZeros?MASK_ZERO_LEADING:0)); + }; + +protected : + virtual BOOL CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam); + +private : + + ScintillaEditView **_ppEditView; + + +}; +#endif// COLUMNEDITOR_H diff --git a/PowerEditor/src/ScitillaComponent/columnEditor.rc b/PowerEditor/src/ScitillaComponent/columnEditor.rc new file mode 100644 index 00000000..61eb79b2 --- /dev/null +++ b/PowerEditor/src/ScitillaComponent/columnEditor.rc @@ -0,0 +1,49 @@ +/* +this file is part of notepad++ +Copyright (C)2003 Don HO ( donho@altern.org ) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include +#include "columnEditor_rc.h" + + +IDD_COLUMNEDIT DIALOGEX 26, 41, 223, 206 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU +EXSTYLE WS_EX_TOOLWINDOW | WS_EX_WINDOWEDGE + CAPTION "Column Editor" +FONT 8, TEXT("MS Shell Dlg"), 0, 0, 0x0 +BEGIN + GROUPBOX "Text to insert",IDC_COL_TEXT_GRP_STATIC,12,10,124,54 + GROUPBOX "Number to insert",IDC_COL_NUM_GRP_STATIC,12,75,204,119 + CONTROL "",IDC_COL_TEXT_RADIO,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP | WS_GROUP,7,10,8,9 + CONTROL "",IDC_COL_NUM_RADIO,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP | WS_GROUP, 7,75,8,9 + EDITTEXT IDC_COL_TEXT_EDIT,25,32,97,14,ES_AUTOHSCROLL + RTEXT "Initial number :",IDC_COL_INITNUM_STATIC,15,91,76,8 + EDITTEXT IDC_COL_INITNUM_EDIT,95,89,38,12,ES_NUMBER + + RTEXT "Increase by :",IDC_COL_INCRNUM_STATIC,16,112,75,8 + EDITTEXT IDC_COL_INCREASENUM_EDIT,95,110,38,12,ES_NUMBER + CONTROL "Leading zeros", IDC_COL_LEADZERO_CHECK,"Button", BS_AUTOCHECKBOX | WS_TABSTOP,140,112,70,10 + + CONTROL "Dec",IDC_COL_DEC_RADIO,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,30,148,50,10 + CONTROL "Hex",IDC_COL_HEX_RADIO,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,124,148,50,10 + CONTROL "Oct",IDC_COL_OCT_RADIO,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,30,167,50,10 + CONTROL "Bin",IDC_COL_BIN_RADIO,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,124,167,50,10 + GROUPBOX "Format",IDC_COL_FORMAT_GRP_STATIC,20,132,188,54,BS_CENTER + DEFPUSHBUTTON "OK",IDOK,145,13,70,14,BS_NOTIFY + PUSHBUTTON "Cancel",IDCANCEL,145,36,70,14,BS_NOTIFY +END diff --git a/PowerEditor/src/ScitillaComponent/columnEditor_rc.h b/PowerEditor/src/ScitillaComponent/columnEditor_rc.h new file mode 100644 index 00000000..01fa7588 --- /dev/null +++ b/PowerEditor/src/ScitillaComponent/columnEditor_rc.h @@ -0,0 +1,39 @@ +/* +this file is part of notepad++ +Copyright (C)2003 Don HO ( donho@altern.org ) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ +#ifndef COLUMNEDITOR_RC_H +#define COLUMNEDITOR_RC_H + +#define IDD_COLUMNEDIT 2020 + #define IDC_COL_INITNUM_EDIT (IDD_COLUMNEDIT + 1) + #define IDC_COL_INCREASENUM_EDIT (IDD_COLUMNEDIT + 2) + #define IDC_COL_TEXT_GRP_STATIC (IDD_COLUMNEDIT + 3) + #define IDC_COL_DEC_RADIO (IDD_COLUMNEDIT + 4) + #define IDC_COL_OCT_RADIO (IDD_COLUMNEDIT + 5) + #define IDC_COL_HEX_RADIO (IDD_COLUMNEDIT + 6) + #define IDC_COL_BIN_RADIO (IDD_COLUMNEDIT + 7) + #define IDC_COL_TEXT_RADIO (IDD_COLUMNEDIT + 8) + #define IDC_COL_NUM_RADIO (IDD_COLUMNEDIT + 9) + #define IDC_COL_INITNUM_STATIC (IDD_COLUMNEDIT + 10) + #define IDC_COL_INCRNUM_STATIC (IDD_COLUMNEDIT + 11) + #define IDC_COL_FORMAT_GRP_STATIC (IDD_COLUMNEDIT + 12) + #define IDC_COL_NUM_GRP_STATIC (IDD_COLUMNEDIT + 13) + #define IDC_COL_TEXT_EDIT (IDD_COLUMNEDIT + 14) + #define IDC_COL_LEADZERO_CHECK (IDD_COLUMNEDIT + 15) + +#endif// COLUMNEDITOR_RC_H diff --git a/PowerEditor/src/ScitillaComponent/xmlMatchedTagsHighlighter.cpp b/PowerEditor/src/ScitillaComponent/xmlMatchedTagsHighlighter.cpp new file mode 100644 index 00000000..517f5cfb --- /dev/null +++ b/PowerEditor/src/ScitillaComponent/xmlMatchedTagsHighlighter.cpp @@ -0,0 +1,492 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#include "xmlMatchedTagsHighlighter.h" +#include "ScintillaEditView.h" + +int XmlMatchedTagsHighlighter::getFirstTokenPosFrom(int targetStart, int targetEnd, const char *token, pair & foundPos) +{ + //int start = currentPos; + //int end = (direction == DIR_LEFT)?0:_pEditView->getCurrentDocLen(); + + _pEditView->execute(SCI_SETTARGETSTART, targetStart); + _pEditView->execute(SCI_SETTARGETEND, targetEnd); + _pEditView->execute(SCI_SETSEARCHFLAGS, SCFIND_REGEXP|SCFIND_POSIX); + int posFind = _pEditView->execute(SCI_SEARCHINTARGET, (WPARAM)strlen(token), (LPARAM)token); + if (posFind != -1) + { + foundPos.first = _pEditView->execute(SCI_GETTARGETSTART); + foundPos.second = _pEditView->execute(SCI_GETTARGETEND); + } + return posFind; +} + +TagCateg XmlMatchedTagsHighlighter::getTagCategory(XmlMatchedTagsPos & tagsPos, int curPos) +{ + pair foundPos; + + int docLen = _pEditView->getCurrentDocLen(); + + int gtPos = getFirstTokenPosFrom(curPos, 0, ">", foundPos); + int ltPos = getFirstTokenPosFrom(curPos, 0, "<", foundPos); + if (ltPos != -1) + { + if ((gtPos != -1) && (ltPos < gtPos)) + return outOfTag; + + // Now we are sure about that we are inside of tag + // We'll try to determinate the tag category : + // tagOpen : , + // tagClose : + // tagSigle : , + int charAfterLt = _pEditView->execute(SCI_GETCHARAT, ltPos+1); + if (!charAfterLt) + return unknownPb; + + if ((char)charAfterLt == ' ') + return invalidTag; + + // so now we are sure we have tag sign '<' + // We'll see on the right + int gtPosOnR = getFirstTokenPosFrom(curPos, docLen, ">", foundPos); + int ltPosOnR = getFirstTokenPosFrom(curPos, docLen, "<", foundPos); + + if (gtPosOnR == -1) + return invalidTag; + + if ((ltPosOnR != -1) && (ltPosOnR < gtPosOnR)) + return invalidTag; + + if ((char)charAfterLt == '/') + { + int char2AfterLt = _pEditView->execute(SCI_GETCHARAT, ltPos+1+1); + + if (!char2AfterLt) + return unknownPb; + + if ((char)char2AfterLt == ' ') + return invalidTag; + + tagsPos.tagCloseStart = ltPos; + tagsPos.tagCloseEnd = gtPosOnR + 1; + return tagClose; + } + else + { + // it's sure for not being a tagClose + // So we determinate if it's tagSingle or tagOpen + tagsPos.tagOpenStart = ltPos; + tagsPos.tagOpenEnd = gtPosOnR + 1; + + int charBeforeLt = _pEditView->execute(SCI_GETCHARAT, gtPosOnR-1); + if ((char)charBeforeLt == '/') + return inSingleTag; + + return tagOpen; + } + } + + return outOfTag; +} + +bool XmlMatchedTagsHighlighter::getMatchedTagPos(int searchStart, int searchEnd, const char *tag2find, const char *oppositeTag2find, vector oppositeTagFound, XmlMatchedTagsPos & tagsPos) +{ + const bool search2Left = false; + const bool search2Right = true; + + bool direction = searchEnd > searchStart; + + pair foundPos; + int ltPosOnR = getFirstTokenPosFrom(searchStart, searchEnd, tag2find, foundPos); + if (ltPosOnR == -1) + return false; + + // if the tag is found in non html zone, we skip it + const NppGUI & nppGUI = (NppParameters::getInstance())->getNppGUI(); + int idStyle = _pEditView->execute(SCI_GETSTYLEAT, ltPosOnR); + if (idStyle >= SCE_HJ_START && !nppGUI._enableHiliteNonHTMLZone) + { + int start = (direction == search2Left)?foundPos.first:foundPos.second; + int end = searchEnd; + return getMatchedTagPos(start, end, tag2find, oppositeTag2find, oppositeTagFound, tagsPos); + } + + TagCateg tc = outOfTag; + if (direction == search2Left) + { + tc = getTagCategory(tagsPos, ltPosOnR+2); + + if (tc != tagOpen && tc != inSingleTag) + return false; + if (tc == inSingleTag) + { + int start = foundPos.first; + int end = searchEnd; + return getMatchedTagPos(start, end, tag2find, oppositeTag2find, oppositeTagFound, tagsPos); + } + } + + pair oppositeTagPos; + int s = foundPos.first; + int e = tagsPos.tagOpenEnd; + if (direction == search2Left) + { + s = foundPos.second; + e = tagsPos.tagCloseStart; + } + + int ltTag = getFirstTokenPosFrom(s, e, oppositeTag2find, oppositeTagPos); + + if (ltTag == -1) + { + if (direction == search2Left) + { + return true; + } + else + { + tagsPos.tagCloseStart = foundPos.first; + tagsPos.tagCloseEnd = foundPos.second; + return true; + } + } + else + { + // RegExpr is "]", found tag could be a openTag or singleTag + // so we should make sure if it's a singleTag + XmlMatchedTagsPos pos; + if (direction == search2Right && getTagCategory(pos,ltTag+1) == inSingleTag) + { + while (true) + { + ltTag = getFirstTokenPosFrom(ltTag, e, oppositeTag2find, oppositeTagPos); + + if (ltTag == -1) + { + tagsPos.tagCloseStart = foundPos.first; + tagsPos.tagCloseEnd = foundPos.second; + return true; + } + else + { + if (getTagCategory(pos,ltTag+1) == inSingleTag) + { + continue; + } + + if (!isInList(ltTag, oppositeTagFound)) + { + oppositeTagFound.push_back(ltTag); + break; + } + } + } + return getMatchedTagPos(foundPos.second, searchEnd, tag2find, oppositeTag2find, oppositeTagFound, tagsPos); + } + + + if (isInList(ltTag, oppositeTagFound)) + { + while (true) + { + ltTag = getFirstTokenPosFrom(ltTag, e, oppositeTag2find, oppositeTagPos); + if (ltTag == -1) + { + if (direction == search2Left) + { + return true; + } + else + { + tagsPos.tagCloseStart = foundPos.first; + tagsPos.tagCloseEnd = foundPos.second; + } + return true; + } + else if (!isInList(ltTag, oppositeTagFound)) + { + oppositeTagFound.push_back(ltTag); + break; + } + else + { + if (direction == search2Left) + { + XmlMatchedTagsPos tmpTagsPos; + getTagCategory(tmpTagsPos, ltTag+1); + ltTag = tmpTagsPos.tagCloseEnd; + } + } + } + } + else + { + oppositeTagFound.push_back(ltTag); + } + } + int start, end; + if (direction == search2Left) + { + start = foundPos.first; + end = searchEnd; + } + else + { + start = foundPos.second; + end = searchEnd; + } + + return getMatchedTagPos(start, end, tag2find, oppositeTag2find, oppositeTagFound, tagsPos); +} + + +bool XmlMatchedTagsHighlighter::getXmlMatchedTagsPos(XmlMatchedTagsPos & tagsPos) +{ + // get word where caret is on + int caretPos = _pEditView->execute(SCI_GETCURRENTPOS); + + // if the tag is found in non html zone, then quit + const NppGUI & nppGUI = (NppParameters::getInstance())->getNppGUI(); + int idStyle = _pEditView->execute(SCI_GETSTYLEAT, caretPos); + if (!nppGUI._enableHiliteNonHTMLZone && idStyle >= SCE_HJ_START) + return false; + + int docLen = _pEditView->getCurrentDocLen(); + + // determinate the nature of current word : tagOpen, tagClose or outOfTag + TagCateg tagCateg = getTagCategory(tagsPos, caretPos); + + static const char tagNameChars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-_:"; + + switch (tagCateg) + { + case tagOpen : // if tagOpen search right + { + _pEditView->execute(SCI_SETWORDCHARS, 0, (LPARAM)tagNameChars); + int startPos = _pEditView->execute(SCI_WORDSTARTPOSITION, tagsPos.tagOpenStart+1, true); + int endPos = _pEditView->execute(SCI_WORDENDPOSITION, tagsPos.tagOpenStart+1, true); + tagsPos.tagNameEnd = endPos; + + _pEditView->execute(SCI_SETCHARSDEFAULT); + char * tagName = new char[endPos-startPos+1]; + + _pEditView->getText(tagName, startPos, endPos); + + basic_string closeTag = ""; + + basic_string openTag = "<"; + openTag += tagName; + openTag += "[ >]"; + + delete [] tagName; + + vector passedTagList; + return getMatchedTagPos(tagsPos.tagOpenEnd, docLen, closeTag.c_str(), openTag.c_str(), passedTagList, tagsPos); + } + + case tagClose : // if tagClose search left + { + _pEditView->execute(SCI_SETWORDCHARS, 0, (LPARAM)tagNameChars); + int startPos = _pEditView->execute(SCI_WORDSTARTPOSITION, tagsPos.tagCloseStart+2, true); + int endPos = _pEditView->execute(SCI_WORDENDPOSITION, tagsPos.tagCloseStart+2, true); + + _pEditView->execute(SCI_SETCHARSDEFAULT); + char * tagName = new char[endPos-startPos+1]; + _pEditView->getText(tagName, startPos, endPos); + + basic_string openTag = "<"; + openTag += tagName; + openTag += "[ >]"; + + basic_string closeTag = ""; + + delete [] tagName; + + vector passedTagList; + bool isFound = getMatchedTagPos(tagsPos.tagCloseStart, 0, openTag.c_str(), closeTag.c_str(), passedTagList, tagsPos); + if (isFound) + tagsPos.tagNameEnd = tagsPos.tagOpenStart + 1 + (endPos - startPos); + + return isFound; + } + + case inSingleTag : // if in single tag + { + _pEditView->execute(SCI_SETWORDCHARS, 0, (LPARAM)tagNameChars); + int endPos = _pEditView->execute(SCI_WORDENDPOSITION, tagsPos.tagOpenStart+1, true); + tagsPos.tagNameEnd = endPos; + _pEditView->execute(SCI_SETCHARSDEFAULT); + + tagsPos.tagCloseStart = -1; + tagsPos.tagCloseEnd = -1; + return true; + } + default: // if outOfTag, just quit + return false; + + } + return false; +} + +vector< pair > XmlMatchedTagsHighlighter::getAttributesPos(int start, int end) +{ + vector< pair > attributes; + + int bufLen = end - start + 1; + char *buf = new char[bufLen+1]; + _pEditView->getText(buf, start, end); + + enum {\ + attr_invalid,\ + attr_key,\ + attr_pre_assign,\ + attr_assign,\ + attr_string,\ + attr_value,\ + attr_valid\ + } state = attr_invalid; + + int startPos = -1; + int oneMoreChar = 1; + int i = 0; + for (; i < bufLen ; i++) + { + switch (buf[i]) + { + case ' ': + case '\t': + case '\n': + case '\r': + { + if (state == attr_key) + state = attr_pre_assign; + else if (state == attr_value) + { + state = attr_valid; + oneMoreChar = 0; + } + } + break; + + case '=': + { + if (state == attr_key || state == attr_pre_assign) + state = attr_assign; + else if (state == attr_assign || state == attr_value) + state = attr_invalid; + } + break; + + case '"': + { + if (state == attr_string) + { + state = attr_valid; + oneMoreChar = 1; + } + else if (state == attr_key || state == attr_pre_assign || state == attr_value) + state = attr_invalid; + else if (state == attr_assign) + state = attr_string; + } + break; + + default: + { + if (state == attr_invalid) + { + state = attr_key; + startPos = i; + } + else if (state == attr_pre_assign) + state = attr_invalid; + else if (state == attr_assign) + state = attr_value; + } + } + + if (state == attr_valid) + { + attributes.push_back(pair(start+startPos, start+i+oneMoreChar)); + state = attr_invalid; + } + } + if (state == attr_value) + attributes.push_back(pair(start+startPos, start+i-1)); + + delete [] buf; + return attributes; +} + + + +void XmlMatchedTagsHighlighter::tagMatch(bool doHiliteAttr) +{ + // Clean up all marks of previous action + _pEditView->clearIndicator(SCE_UNIVERSAL_TAGMATCH); + _pEditView->clearIndicator(SCE_UNIVERSAL_TAGATTR); + + // Detect the current lang type. It works only with html and xml + LangType lang = (_pEditView->getCurrentBuffer())->getLangType(); + + if (lang != L_XML && lang != L_HTML && lang != L_PHP && lang != L_ASP) + return; + + // Get the original targets and search options to restore after tag matching operation + int originalStartPos = _pEditView->execute(SCI_GETTARGETSTART); + int originalEndPos = _pEditView->execute(SCI_GETTARGETEND); + int originalSearchFlags = _pEditView->execute(SCI_GETSEARCHFLAGS); + + // Detect if it's a xml/html tag. If yes, Colour it! + XmlMatchedTagsPos xmlTags; + if (getXmlMatchedTagsPos(xmlTags)) + { + _pEditView->execute(SCI_SETINDICATORCURRENT, SCE_UNIVERSAL_TAGMATCH); + + int openTagTailLen = 2; + // We colourise the close tag firstly + if ((xmlTags.tagCloseStart != -1) && (xmlTags.tagCloseEnd != -1)) + { + _pEditView->execute(SCI_INDICATORFILLRANGE, xmlTags.tagCloseStart, xmlTags.tagCloseEnd - xmlTags.tagCloseStart); + // tag close is present, so it's not single tag + openTagTailLen = 1; + } + + // Now the open tag and its attributs + _pEditView->execute(SCI_INDICATORFILLRANGE, xmlTags.tagOpenStart, xmlTags.tagNameEnd - xmlTags.tagOpenStart); + _pEditView->execute(SCI_INDICATORFILLRANGE, xmlTags.tagOpenEnd - openTagTailLen, openTagTailLen); + + if (doHiliteAttr) + { + vector< pair > attributes = getAttributesPos(xmlTags.tagNameEnd, xmlTags.tagOpenEnd - openTagTailLen); + _pEditView->execute(SCI_SETINDICATORCURRENT, SCE_UNIVERSAL_TAGATTR); + for (size_t i = 0 ; i < attributes.size() ; i++) + { + _pEditView->execute(SCI_INDICATORFILLRANGE, attributes[i].first, attributes[i].second - attributes[i].first); + } + } + } + + // restore the original targets and search options to avoid the conflit with search/replace function + _pEditView->execute(SCI_SETTARGETSTART, originalStartPos); + _pEditView->execute(SCI_SETTARGETEND, originalEndPos); + _pEditView->execute(SCI_SETSEARCHFLAGS, originalSearchFlags); +} diff --git a/PowerEditor/src/ScitillaComponent/xmlMatchedTagsHighlighter.h b/PowerEditor/src/ScitillaComponent/xmlMatchedTagsHighlighter.h new file mode 100644 index 00000000..70b9566d --- /dev/null +++ b/PowerEditor/src/ScitillaComponent/xmlMatchedTagsHighlighter.h @@ -0,0 +1,61 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef XMLMATCHEDTAGSHIGHLIGHTER_H +#define XMLMATCHEDTAGSHIGHLIGHTER_H + +#include +#include + +using namespace std; + +class ScintillaEditView; + +enum TagCateg {tagOpen, tagClose, inSingleTag, outOfTag, invalidTag, unknownPb}; + +class XmlMatchedTagsHighlighter { +public: + XmlMatchedTagsHighlighter(ScintillaEditView *pEditView):_pEditView(pEditView){}; + void tagMatch(bool doHiliteAttr); + +private: + struct XmlMatchedTagsPos { + int tagOpenStart; + int tagNameEnd; + int tagOpenEnd; + + int tagCloseStart; + int tagCloseEnd; + }; + + ScintillaEditView *_pEditView; + + int getFirstTokenPosFrom(int targetStart, int targetEnd, const char *token, std::pair & foundPos); + TagCateg getTagCategory(XmlMatchedTagsPos & tagsPos, int curPos); + bool getMatchedTagPos(int searchStart, int searchEnd, const char *tag2find, const char *oppositeTag2find, vector oppositeTagFound, XmlMatchedTagsPos & tagsPos); + bool getXmlMatchedTagsPos(XmlMatchedTagsPos & tagsPos); + vector< pair > getAttributesPos(int start, int end); + bool isInList(int element, vector elementList) { + for (size_t i = 0 ; i < elementList.size() ; i++) + if (element == elementList[i]) + return true; + return false; + }; +}; + +#endif //XMLMATCHEDTAGSHIGHLIGHTER_H + diff --git a/PowerEditor/src/StaticControl.h b/PowerEditor/src/StaticControl.h new file mode 100644 index 00000000..eb7c5c0b --- /dev/null +++ b/PowerEditor/src/StaticControl.h @@ -0,0 +1,35 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +#ifndef STATIC_CONTROL_H +#define STATIC_CONTROL_H + +#include "Window.h" +class StaticControl : public Window +{ +public : + StaticControl() : Window() {}; + ~StaticControl(){}; + void init(HINSTANCE hInst, HWND parent, int ctrlID) { + Window::init(hInst, parent); + //_hSelf = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_LUNA_DIALOG), NULL, cryptoGUI_dlgProc); + }; + +} + +#endif //STATIC_CONTROL_H \ No newline at end of file diff --git a/PowerEditor/src/TinyXml/tinyXmlA/tinystrA.cpp b/PowerEditor/src/TinyXml/tinyXmlA/tinystrA.cpp new file mode 100644 index 00000000..ab4acdac --- /dev/null +++ b/PowerEditor/src/TinyXml/tinyXmlA/tinystrA.cpp @@ -0,0 +1,303 @@ +/* +www.sourceforge.net/projects/tinyxml +Original file by Yves Berquin. + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + +#include "tinyxmlA.h" + +#ifndef TIXMLA_USE_STL + + +#include +#include +#include + +#include "tinystrA.h" + +// TiXmlStringA constructor, based on a C string +TiXmlStringA::TiXmlStringA (const char* instring) +{ + unsigned newlen; + char * newstring; + + if (!instring) + { + allocated = 0; + cstring = NULL; + current_length = 0; + return; + } + newlen = strlen (instring) + 1; + newstring = new char [newlen]; + memcpy (newstring, instring, newlen); + // strcpy (newstring, instring); + allocated = newlen; + cstring = newstring; + current_length = newlen - 1; +} + +// TiXmlStringA copy constructor +TiXmlStringA::TiXmlStringA (const TiXmlStringA& copy) +{ + unsigned newlen; + char * newstring; + + // Prevent copy to self! + if ( © == this ) + return; + + if (! copy . allocated) + { + allocated = 0; + cstring = NULL; + current_length = 0; + return; + } + newlen = copy . length () + 1; + newstring = new char [newlen]; + // strcpy (newstring, copy . cstring); + memcpy (newstring, copy . cstring, newlen); + allocated = newlen; + cstring = newstring; + current_length = newlen - 1; +} + +// TiXmlStringA = operator. Safe when assign own content +void TiXmlStringA ::operator = (const char * content) +{ + unsigned newlen; + char * newstring; + + if (! content) + { + empty_it (); + return; + } + newlen = strlen (content) + 1; + newstring = new char [newlen]; + // strcpy (newstring, content); + memcpy (newstring, content, newlen); + empty_it (); + allocated = newlen; + cstring = newstring; + current_length = newlen - 1; +} + +// = operator. Safe when assign own content +void TiXmlStringA ::operator = (const TiXmlStringA & copy) +{ + unsigned newlen; + char * newstring; + + if (! copy . length ()) + { + empty_it (); + return; + } + newlen = copy . length () + 1; + newstring = new char [newlen]; + // strcpy (newstring, copy . c_str ()); + memcpy (newstring, copy . c_str (), newlen); + empty_it (); + allocated = newlen; + cstring = newstring; + current_length = newlen - 1; +} + + +//// Checks if a TiXmlStringA contains only whitespace (same rules as isspace) +//bool TiXmlStringA::isblank () const +//{ +// char * lookup; +// for (lookup = cstring; * lookup; lookup++) +// if (! isspace (* lookup)) +// return false; +// return true; +//} + +// append a const char * to an existing TiXmlStringA +void TiXmlStringA::append( const char* str, int len ) +{ + char * new_string; + unsigned new_alloc, new_size, size_suffix; + + size_suffix = strlen (str); + if (len < (int) size_suffix) + size_suffix = len; + if (! size_suffix) + return; + + new_size = length () + size_suffix + 1; + // check if we need to expand + if (new_size > allocated) + { + // compute new size + new_alloc = assign_new_size (new_size); + + // allocate new buffer + new_string = new char [new_alloc]; + new_string [0] = 0; + + // copy the previous allocated buffer into this one + if (allocated && cstring) + // strcpy (new_string, cstring); + memcpy (new_string, cstring, length ()); + + // append the suffix. It does exist, otherwize we wouldn't be expanding + // strncat (new_string, str, len); + memcpy (new_string + length (), + str, + size_suffix); + + // return previsously allocated buffer if any + if (allocated && cstring) + delete [] cstring; + + // update member variables + cstring = new_string; + allocated = new_alloc; + } + else + { + // we know we can safely append the new string + // strncat (cstring, str, len); + memcpy (cstring + length (), + str, + size_suffix); + } + current_length = new_size - 1; + cstring [current_length] = 0; +} + + +// append a const char * to an existing TiXmlStringA +void TiXmlStringA::append( const char * suffix ) +{ + char * new_string; + unsigned new_alloc, new_size; + + new_size = length () + strlen (suffix) + 1; + // check if we need to expand + if (new_size > allocated) + { + // compute new size + new_alloc = assign_new_size (new_size); + + // allocate new buffer + new_string = new char [new_alloc]; + new_string [0] = 0; + + // copy the previous allocated buffer into this one + if (allocated && cstring) + memcpy (new_string, cstring, 1 + length ()); + // strcpy (new_string, cstring); + + // append the suffix. It does exist, otherwize we wouldn't be expanding + // strcat (new_string, suffix); + memcpy (new_string + length (), + suffix, + strlen (suffix) + 1); + + // return previsously allocated buffer if any + if (allocated && cstring) + delete [] cstring; + + // update member variables + cstring = new_string; + allocated = new_alloc; + } + else + { + // we know we can safely append the new string + // strcat (cstring, suffix); + memcpy (cstring + length (), + suffix, + strlen (suffix) + 1); + } + current_length = new_size - 1; +} + +// Check for TiXmlStringA equuivalence +//bool TiXmlStringA::operator == (const TiXmlStringA & compare) const +//{ +// return (! strcmp (c_str (), compare . c_str ())); +//} + +//unsigned TiXmlStringA::length () const +//{ +// if (allocated) +// // return strlen (cstring); +// return current_length; +// return 0; +//} + + +unsigned TiXmlStringA::find (char tofind, unsigned offset) const +{ + char * lookup; + + if (offset >= length ()) + return (unsigned) notfound; + for (lookup = cstring + offset; * lookup; lookup++) + if (* lookup == tofind) + return lookup - cstring; + return (unsigned) notfound; +} + + +bool TiXmlStringA::operator == (const TiXmlStringA & compare) const +{ + if ( allocated && compare.allocated ) + { + assert( cstring ); + assert( compare.cstring ); + return ( strcmp( cstring, compare.cstring ) == 0 ); + } + return false; +} + + +bool TiXmlStringA::operator < (const TiXmlStringA & compare) const +{ + if ( allocated && compare.allocated ) + { + assert( cstring ); + assert( compare.cstring ); + return ( strcmp( cstring, compare.cstring ) > 0 ); + } + return false; +} + + +bool TiXmlStringA::operator > (const TiXmlStringA & compare) const +{ + if ( allocated && compare.allocated ) + { + assert( cstring ); + assert( compare.cstring ); + return ( strcmp( cstring, compare.cstring ) < 0 ); + } + return false; +} + + +#endif // TIXMLA_USE_STL diff --git a/PowerEditor/src/TinyXml/tinyXmlA/tinystrA.h b/PowerEditor/src/TinyXml/tinyXmlA/tinystrA.h new file mode 100644 index 00000000..dca746e0 --- /dev/null +++ b/PowerEditor/src/TinyXml/tinyXmlA/tinystrA.h @@ -0,0 +1,236 @@ +/* +www.sourceforge.net/projects/tinyxml +Original file by Yves Berquin. + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + +#include "tinyxmlA.h" + + +#ifndef TIXMLA_USE_STL + +#ifndef _INCLUDED +#define TIXMLA_STRING_INCLUDED + +#pragma warning( disable : 4514 ) + +#include + +/* + TiXmlStringA is an emulation of the std::string template. + Its purpose is to allow compiling TinyXML on compilers with no or poor STL support. + Only the member functions relevant to the TinyXML project have been implemented. + The buffer allocation is made by a simplistic power of 2 like mechanism : if we increase + a string and there's no more room, we allocate a buffer twice as big as we need. +*/ +class TiXmlStringA +{ + public : + // TiXmlStringA constructor, based on a string + TiXmlStringA (const char * instring); + + // TiXmlStringA empty constructor + TiXmlStringA () + { + allocated = 0; + cstring = NULL; + current_length = 0; + } + + // TiXmlStringA copy constructor + TiXmlStringA (const TiXmlStringA& copy); + + // TiXmlStringA destructor + ~ TiXmlStringA () + { + empty_it (); + } + + // Convert a TiXmlStringA into a classical char * + const char * c_str () const + { + if (allocated) + return cstring; + return ""; + } + + // Return the length of a TiXmlStringA + unsigned length () const + { + return ( allocated ) ? current_length : 0; + } + + // TiXmlStringA = operator + void operator = (const char * content); + + // = operator + void operator = (const TiXmlStringA & copy); + + // += operator. Maps to append + TiXmlStringA& operator += (const char * suffix) + { + append (suffix); + return *this; + } + + // += operator. Maps to append + TiXmlStringA& operator += (char single) + { + append (single); + return *this; + } + + // += operator. Maps to append + TiXmlStringA& operator += (TiXmlStringA & suffix) + { + append (suffix); + return *this; + } + bool operator == (const TiXmlStringA & compare) const; + bool operator < (const TiXmlStringA & compare) const; + bool operator > (const TiXmlStringA & compare) const; + + // Checks if a TiXmlStringA is empty + bool empty () const + { + return length () ? false : true; + } + + // Checks if a TiXmlStringA contains only whitespace (same rules as isspace) + // Not actually used in tinyxml. Conflicts with a C macro, "isblank", + // which is a problem. Commenting out. -lee +// bool isblank () const; + + // single char extraction + const char& at (unsigned index) const + { + assert( index < length ()); + return cstring [index]; + } + + // find a char in a string. Return TiXmlStringA::notfound if not found + unsigned find (char lookup) const + { + return find (lookup, 0); + } + + // find a char in a string from an offset. Return TiXmlStringA::notfound if not found + unsigned find (char tofind, unsigned offset) const; + + /* Function to reserve a big amount of data when we know we'll need it. Be aware that this + function clears the content of the TiXmlStringA if any exists. + */ + void reserve (unsigned size) + { + empty_it (); + if (size) + { + allocated = size; + TIXMLA_STRING cstring = new char [size]; + cstring [0] = 0; + current_length = 0; + } + } + + // [] operator + char& operator [] (unsigned index) const + { + assert( index < length ()); + return cstring [index]; + } + + // Error value for find primitive + enum { notfound = 0xffffffff, + npos = notfound }; + + void append (const char *str, int len ); + + protected : + + // The base string + char * cstring; + // Number of chars allocated + unsigned allocated; + // Current string size + unsigned current_length; + + // New size computation. It is simplistic right now : it returns twice the amount + // we need + unsigned assign_new_size (unsigned minimum_to_allocate) + { + return minimum_to_allocate * 2; + } + + // Internal function that clears the content of a TiXmlStringA + void empty_it () + { + if (cstring) + delete [] cstring; + cstring = NULL; + allocated = 0; + current_length = 0; + } + + void append (const char *suffix ); + + // append function for another TiXmlStringA + void append (const TiXmlStringA & suffix) + { + append (suffix . c_str ()); + } + + // append for a single char. This could be improved a lot if needed + void append (char single) + { + char smallstr [2]; + smallstr [0] = single; + smallstr [1] = 0; + append (smallstr); + } + +} ; + +/* + TiXmlOutStreamA is an emulation of std::ostream. It is based on TiXmlStringA. + Only the operators that we need for TinyXML have been developped. +*/ +class TiXmlOutStreamA : public TiXmlStringA +{ +public : + TiXmlOutStreamA () : TiXmlStringA () {} + + // TiXmlOutStreamA << operator. Maps to TiXmlStringA::append + TiXmlOutStreamA & operator << (const char * in) + { + append (in); + return (* this); + } + + // TiXmlOutStreamA << operator. Maps to TiXmlStringA::append + TiXmlOutStreamA & operator << (const TiXmlStringA & in) + { + append (in . c_str ()); + return (* this); + } +} ; + +#endif // TIXMLA_STRING_INCLUDED +#endif // TIXMLA_USE_STL diff --git a/PowerEditor/src/TinyXml/tinyXmlA/tinyxmlA.cpp b/PowerEditor/src/TinyXml/tinyXmlA/tinyxmlA.cpp new file mode 100644 index 00000000..3f9ad06a --- /dev/null +++ b/PowerEditor/src/TinyXml/tinyXmlA/tinyxmlA.cpp @@ -0,0 +1,1316 @@ +/* +www.sourceforge.net/projects/tinyxml +Original code (2.0 and earlier )copyright (c) 2000-2002 Lee Thomason (www.grinninglizard.com) + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + +#include +#include "tinyxmlA.h" + +#ifdef TIXMLA_USE_STL +#include +#endif + +bool TiXmlBaseA::condenseWhiteSpace = true; + +void TiXmlBaseA::PutString( const TIXMLA_STRING& str, TIXMLA_OSTREAM* stream ) +{ + TIXMLA_STRING buffer; + PutString( str, &buffer ); + (*stream) << buffer; +} + +void TiXmlBaseA::PutString( const TIXMLA_STRING& str, TIXMLA_STRING* outString ) +{ + int i=0; + + while( i<(int)str.length() ) + { + int c = str[i]; + + if ( c == '&' + && i < ( (int)str.length() - 2 ) + && str[i+1] == '#' + && str[i+2] == 'x' ) + { + // Hexadecimal character reference. + // Pass through unchanged. + // © -- copyright symbol, for example. + while ( i<(int)str.length() ) + { + outString->append( str.c_str() + i, 1 ); + ++i; + if ( str[i] == ';' ) + break; + } + } + else if ( c == '&' ) + { + outString->append( entity[0].str, entity[0].strLength ); + ++i; + } + else if ( c == '<' ) + { + outString->append( entity[1].str, entity[1].strLength ); + ++i; + } + else if ( c == '>' ) + { + outString->append( entity[2].str, entity[2].strLength ); + ++i; + } + else if ( c == '\"' ) + { + outString->append( entity[3].str, entity[3].strLength ); + ++i; + } + else if ( c == '\'' ) + { + outString->append( entity[4].str, entity[4].strLength ); + ++i; + } + else if ( c < 32 || c > 126 ) + { + // Easy pass at non-alpha/numeric/symbol + // 127 is the delete key. Below 32 is symbolic. + char buf[ 32 ]; + sprintf( buf, "&#x%02X;", (unsigned) ( c & 0xff ) ); + outString->append( buf, strlen( buf ) ); + ++i; + } + else + { + char realc = (char) c; + outString->append( &realc, 1 ); + ++i; + } + } +} + + +// <-- Strange class for a bug fix. Search for STL_STRING_BUG +TiXmlBaseA::StringToBuffer::StringToBuffer( const TIXMLA_STRING& str ) +{ + buffer = new char[ str.length()+1 ]; + if ( buffer ) + { + strcpy( buffer, str.c_str() ); + } +} + + +TiXmlBaseA::StringToBuffer::~StringToBuffer() +{ + delete [] buffer; +} +// End strange bug fix. --> + + +TiXmlNodeA::TiXmlNodeA( NodeType _type ) +{ + parent = 0; + type = _type; + firstChild = 0; + lastChild = 0; + prev = 0; + next = 0; + userData = 0; +} + + +TiXmlNodeA::~TiXmlNodeA() +{ + TiXmlNodeA* node = firstChild; + TiXmlNodeA* temp = 0; + + while ( node ) + { + temp = node; + node = node->next; + delete temp; + } +} + + +void TiXmlNodeA::Clear() +{ + TiXmlNodeA* node = firstChild; + TiXmlNodeA* temp = 0; + + while ( node ) + { + temp = node; + node = node->next; + delete temp; + } + + firstChild = 0; + lastChild = 0; +} + + +TiXmlNodeA* TiXmlNodeA::LinkEndChild( TiXmlNodeA* node ) +{ + node->parent = this; + + node->prev = lastChild; + node->next = 0; + + if ( lastChild ) + lastChild->next = node; + else + firstChild = node; // it was an empty list. + + lastChild = node; + return node; +} + + +TiXmlNodeA* TiXmlNodeA::InsertEndChild( const TiXmlNodeA& addThis ) +{ + TiXmlNodeA* node = addThis.Clone(); + if ( !node ) + return 0; + + return LinkEndChild( node ); +} + + +TiXmlNodeA* TiXmlNodeA::InsertBeforeChild( TiXmlNodeA* beforeThis, const TiXmlNodeA& addThis ) +{ + if ( !beforeThis || beforeThis->parent != this ) + return 0; + + TiXmlNodeA* node = addThis.Clone(); + if ( !node ) + return 0; + node->parent = this; + + node->next = beforeThis; + node->prev = beforeThis->prev; + if ( beforeThis->prev ) + { + beforeThis->prev->next = node; + } + else + { + assert( firstChild == beforeThis ); + firstChild = node; + } + beforeThis->prev = node; + return node; +} + + +TiXmlNodeA* TiXmlNodeA::InsertAfterChild( TiXmlNodeA* afterThis, const TiXmlNodeA& addThis ) +{ + if ( !afterThis || afterThis->parent != this ) + return 0; + + TiXmlNodeA* node = addThis.Clone(); + if ( !node ) + return 0; + node->parent = this; + + node->prev = afterThis; + node->next = afterThis->next; + if ( afterThis->next ) + { + afterThis->next->prev = node; + } + else + { + assert( lastChild == afterThis ); + lastChild = node; + } + afterThis->next = node; + return node; +} + + +TiXmlNodeA* TiXmlNodeA::ReplaceChild( TiXmlNodeA* replaceThis, const TiXmlNodeA& withThis ) +{ + if ( replaceThis->parent != this ) + return 0; + + TiXmlNodeA* node = withThis.Clone(); + if ( !node ) + return 0; + + node->next = replaceThis->next; + node->prev = replaceThis->prev; + + if ( replaceThis->next ) + replaceThis->next->prev = node; + else + lastChild = node; + + if ( replaceThis->prev ) + replaceThis->prev->next = node; + else + firstChild = node; + + delete replaceThis; + node->parent = this; + return node; +} + + +bool TiXmlNodeA::RemoveChild( TiXmlNodeA* removeThis ) +{ + if ( removeThis->parent != this ) + { + assert( 0 ); + return false; + } + + if ( removeThis->next ) + removeThis->next->prev = removeThis->prev; + else + lastChild = removeThis->prev; + + if ( removeThis->prev ) + removeThis->prev->next = removeThis->next; + else + firstChild = removeThis->next; + + delete removeThis; + return true; +} + +TiXmlNodeA* TiXmlNodeA::FirstChild( const char * _value ) const +{ + TiXmlNodeA* node; + for ( node = firstChild; node; node = node->next ) + { + if ( node->SValue() == TIXMLA_STRING( _value )) + return node; + } + return 0; +} + +TiXmlNodeA* TiXmlNodeA::LastChild( const char * _value ) const +{ + TiXmlNodeA* node; + for ( node = lastChild; node; node = node->prev ) + { + if ( node->SValue() == TIXMLA_STRING (_value)) + return node; + } + return 0; +} + +TiXmlNodeA* TiXmlNodeA::IterateChildren( TiXmlNodeA* previous ) const +{ + if ( !previous ) + { + return FirstChild(); + } + else + { + assert( previous->parent == this ); + return previous->NextSibling(); + } +} + +TiXmlNodeA* TiXmlNodeA::IterateChildren( const char * val, TiXmlNodeA* previous ) const +{ + if ( !previous ) + { + return FirstChild( val ); + } + else + { + assert( previous->parent == this ); + return previous->NextSibling( val ); + } +} + +TiXmlNodeA* TiXmlNodeA::NextSibling( const char * _value ) const +{ + TiXmlNodeA* node; + for ( node = next; node; node = node->next ) + { + if ( node->SValue() == TIXMLA_STRING (_value)) + return node; + } + return 0; +} + + +TiXmlNodeA* TiXmlNodeA::PreviousSibling( const char * _value ) const +{ + TiXmlNodeA* node; + for ( node = prev; node; node = node->prev ) + { + if ( node->SValue() == TIXMLA_STRING (_value)) + return node; + } + return 0; +} + +void TiXmlElementA::RemoveAttribute( const char * name ) +{ + TiXmlAttributeA* node = attributeSet.Find( name ); + if ( node ) + { + attributeSet.Remove( node ); + delete node; + } +} + +TiXmlElementA* TiXmlNodeA::FirstChildElement() const +{ + TiXmlNodeA* node; + + for ( node = FirstChild(); + node; + node = node->NextSibling() ) + { + if ( node->ToElement() ) + return node->ToElement(); + } + return 0; +} + +TiXmlElementA* TiXmlNodeA::FirstChildElement( const char * _value ) const +{ + TiXmlNodeA* node; + + for ( node = FirstChild( _value ); + node; + node = node->NextSibling( _value ) ) + { + if ( node->ToElement() ) + return node->ToElement(); + } + return 0; +} + + +TiXmlElementA* TiXmlNodeA::NextSiblingElement() const +{ + TiXmlNodeA* node; + + for ( node = NextSibling(); + node; + node = node->NextSibling() ) + { + if ( node->ToElement() ) + return node->ToElement(); + } + return 0; +} + +TiXmlElementA* TiXmlNodeA::NextSiblingElement( const char * _value ) const +{ + TiXmlNodeA* node; + + for ( node = NextSibling( _value ); + node; + node = node->NextSibling( _value ) ) + { + if ( node->ToElement() ) + return node->ToElement(); + } + return 0; +} + + + +TiXmlDocumentA* TiXmlNodeA::GetDocument() const +{ + const TiXmlNodeA* node; + + for( node = this; node; node = node->parent ) + { + if ( node->ToDocument() ) + return node->ToDocument(); + } + return 0; +} + + +TiXmlElementA::TiXmlElementA (const char * _value) +: TiXmlNodeA( TiXmlNodeA::ELEMENT ) +{ + firstChild = lastChild = 0; + value = _value; +} + +TiXmlElementA::~TiXmlElementA() +{ + while( attributeSet.First() ) + { + TiXmlAttributeA* node = attributeSet.First(); + attributeSet.Remove( node ); + delete node; + } +} + +const char * TiXmlElementA::Attribute( const char * name ) const +{ + TiXmlAttributeA* node = attributeSet.Find( name ); + + if ( node ) + return node->Value(); + + return 0; +} + + +const char * TiXmlElementA::Attribute( const char * name, int* i ) const +{ + const char * s = Attribute( name ); + if ( i ) + { + if ( s ) + *i = atoi( s ); + else + *i = 0; + } + return s; +} + + +const char * TiXmlElementA::Attribute( const char * name, double* d ) const +{ + const char * s = Attribute( name ); + if ( d ) + { + if ( s ) + *d = atof( s ); + else + *d = 0; + } + return s; +} + + +int TiXmlElementA::QueryIntAttribute( const char* name, int* ival ) const +{ + TiXmlAttributeA* node = attributeSet.Find( name ); + if ( !node ) + return TIXMLA_NO_ATTRIBUTE; + + return node->QueryIntValue( ival ); +} + + +int TiXmlElementA::QueryDoubleAttribute( const char* name, double* dval ) const +{ + TiXmlAttributeA* node = attributeSet.Find( name ); + if ( !node ) + return TIXMLA_NO_ATTRIBUTE; + + return node->QueryDoubleValue( dval ); +} + + +void TiXmlElementA::SetAttribute( const char * name, int val ) +{ + char buf[64]; + sprintf( buf, "%d", val ); + SetAttribute( name, buf ); +} + + +void TiXmlElementA::SetAttribute( const char * name, const char * _value ) +{ + TiXmlAttributeA* node = attributeSet.Find( name ); + if ( node ) + { + node->SetValue( _value ); + return; + } + + TiXmlAttributeA* attrib = new TiXmlAttributeA( name, _value ); + if ( attrib ) + { + attributeSet.Add( attrib ); + } + else + { + TiXmlDocumentA* document = GetDocument(); + if ( document ) document->SetError( TIXMLA_ERROR_OUT_OF_MEMORY, 0, 0 ); + } +} + +void TiXmlElementA::Print( FILE* cfile, int depth ) const +{ + int i; + for ( i=0; iNext() ) + { + fprintf( cfile, " " ); + attrib->Print( cfile, depth ); + } + + // There are 3 different formatting approaches: + // 1) An element without children is printed as a node + // 2) An element with only a text child is printed as text + // 3) An element with children is printed on multiple lines. + TiXmlNodeA* node; + if ( !firstChild ) + { + fprintf( cfile, " />" ); + } + else if ( firstChild == lastChild && firstChild->ToText() ) + { + fprintf( cfile, ">" ); + firstChild->Print( cfile, depth + 1 ); + fprintf( cfile, "", value.c_str() ); + } + else + { + fprintf( cfile, ">" ); + + for ( node = firstChild; node; node=node->NextSibling() ) + { + if ( !node->ToText() ) + { + fprintf( cfile, "\n" ); + } + node->Print( cfile, depth+1 ); + } + fprintf( cfile, "\n" ); + for( i=0; i", value.c_str() ); + } +} + +void TiXmlElementA::StreamOut( TIXMLA_OSTREAM * stream ) const +{ + (*stream) << "<" << value; + + TiXmlAttributeA* attrib; + for ( attrib = attributeSet.First(); attrib; attrib = attrib->Next() ) + { + (*stream) << " "; + attrib->StreamOut( stream ); + } + + // If this node has children, give it a closing tag. Else + // make it an empty tag. + TiXmlNodeA* node; + if ( firstChild ) + { + (*stream) << ">"; + + for ( node = firstChild; node; node=node->NextSibling() ) + { + node->StreamOut( stream ); + } + (*stream) << ""; + } + else + { + (*stream) << " />"; + } +} + +TiXmlNodeA* TiXmlElementA::Clone() const +{ + TiXmlElementA* clone = new TiXmlElementA( Value() ); + if ( !clone ) + return 0; + + CopyToClone( clone ); + + // Clone the attributes, then clone the children. + TiXmlAttributeA* attribute = 0; + for( attribute = attributeSet.First(); + attribute; + attribute = attribute->Next() ) + { + clone->SetAttribute( attribute->Name(), attribute->Value() ); + } + + TiXmlNodeA* node = 0; + for ( node = firstChild; node; node = node->NextSibling() ) + { + clone->LinkEndChild( node->Clone() ); + } + return clone; +} + + +TiXmlDocumentA::TiXmlDocumentA() : TiXmlNodeA( TiXmlNodeA::DOCUMENT ) +{ + tabsize = 4; + ClearError(); +} + +TiXmlDocumentA::TiXmlDocumentA( const char * documentName ) : TiXmlNodeA( TiXmlNodeA::DOCUMENT ) +{ + tabsize = 4; + value = documentName; + ClearError(); +} + +bool TiXmlDocumentA::LoadFile() +{ + // See STL_STRING_BUG below. + StringToBuffer buf( value ); + + if ( buf.buffer && LoadFile( buf.buffer ) ) + return true; + + return false; +} + + +bool TiXmlDocumentA::SaveFile() const +{ + // See STL_STRING_BUG below. + StringToBuffer buf( value ); + + if ( buf.buffer && SaveFile( buf.buffer ) ) + return true; + + return false; +} + +bool TiXmlDocumentA::LoadFile( const char* filename ) +{ + // Delete the existing data: + Clear(); + location.Clear(); + + // There was a really terrifying little bug here. The code: + // value = filename + // in the STL case, cause the assignment method of the std::string to + // be called. What is strange, is that the std::string had the same + // address as it's c_str() method, and so bad things happen. Looks + // like a bug in the Microsoft STL implementation. + // See STL_STRING_BUG above. + // Fixed with the StringToBuffer class. + value = filename; + + FILE* file = fopen( value.c_str (), "r" ); + + if ( file ) + { + // Get the file size, so we can pre-allocate the string. HUGE speed impact. + long length = 0; + fseek( file, 0, SEEK_END ); + length = ftell( file ); + fseek( file, 0, SEEK_SET ); + + // Strange case, but good to handle up front. + if ( length == 0 ) + { + fclose( file ); + return false; + } + + // If we have a file, assume it is all one big XML file, and read it in. + // The document parser may decide the document ends sooner than the entire file, however. + TIXMLA_STRING data; + data.reserve( length ); + + const int BUF_SIZE = 2048; + char buf[BUF_SIZE]; + + while( fgets( buf, BUF_SIZE, file ) ) + { + data += buf; + } + fclose( file ); + + Parse( data.c_str(), 0 ); + + if ( Error() ) + return false; + else + return true; + } + SetError( TIXMLA_ERROR_OPENING_FILE, 0, 0 ); + return false; +} + +bool TiXmlDocumentA::LoadUnicodeFilePath( const TCHAR* filename ) +{ + + // Delete the existing data: + Clear(); + location.Clear(); + + // There was a really terrifying little bug here. The code: + // value = filename + // in the STL case, cause the assignment method of the std::generic_string to + // be called. What is strange, is that the std::generic_string had the same + // address as it's c_str() method, and so bad things happen. Looks + // like a bug in the Microsoft STL implementation. + // See STL_STRING_BUG above. + // Fixed with the StringToBuffer class. + + FILE* file = generic_fopen(filename, TEXT("r")); + + if ( file ) + { + // Get the file size, so we can pre-allocate the generic_string. HUGE speed impact. + long length = 0; + fseek( file, 0, SEEK_END ); + length = ftell( file ); + fseek( file, 0, SEEK_SET ); + + // Strange case, but good to handle up front. + if ( length == 0 ) + { + fclose( file ); + return false; + } + + // If we have a file, assume it is all one big XML file, and read it in. + // The document parser may decide the document ends sooner than the entire file, however. + TIXMLA_STRING data; + data.reserve( length ); + + const int BUF_SIZE = 2048; + char buf[BUF_SIZE]; + + while( fgets( buf, BUF_SIZE, file ) ) + { + data += buf; + } + fclose( file ); + + Parse( data.c_str(), 0 ); + + if ( Error() ) + return false; + else + return true; + } + SetError( TIXMLA_ERROR_OPENING_FILE, 0, 0 ); + return false; +} + +bool TiXmlDocumentA::SaveFile( const char * filename ) const +{ + // The old c stuff lives on... + FILE* fp = fopen( filename, "w" ); + if ( fp ) + { + Print( fp, 0 ); + fclose( fp ); + return true; + } + return false; +} + + +TiXmlNodeA* TiXmlDocumentA::Clone() const +{ + TiXmlDocumentA* clone = new TiXmlDocumentA(); + if ( !clone ) + return 0; + + CopyToClone( clone ); + clone->error = error; + clone->errorDesc = errorDesc.c_str (); + + TiXmlNodeA* node = 0; + for ( node = firstChild; node; node = node->NextSibling() ) + { + clone->LinkEndChild( node->Clone() ); + } + return clone; +} + + +void TiXmlDocumentA::Print( FILE* cfile, int depth ) const +{ + TiXmlNodeA* node; + for ( node=FirstChild(); node; node=node->NextSibling() ) + { + node->Print( cfile, depth ); + fprintf( cfile, "\n" ); + } +} + +void TiXmlDocumentA::StreamOut( TIXMLA_OSTREAM * out ) const +{ + TiXmlNodeA* node; + for ( node=FirstChild(); node; node=node->NextSibling() ) + { + node->StreamOut( out ); + + // Special rule for streams: stop after the root element. + // The stream in code will only read one element, so don't + // write more than one. + if ( node->ToElement() ) + break; + } +} + + +TiXmlAttributeA* TiXmlAttributeA::Next() const +{ + // We are using knowledge of the sentinel. The sentinel + // have a value or name. + if ( next->value.empty() && next->name.empty() ) + return 0; + return next; +} + + +TiXmlAttributeA* TiXmlAttributeA::Previous() const +{ + // We are using knowledge of the sentinel. The sentinel + // have a value or name. + if ( prev->value.empty() && prev->name.empty() ) + return 0; + return prev; +} + + +void TiXmlAttributeA::Print( FILE* cfile, int /*depth*/ ) const +{ + TIXMLA_STRING n, v; + + PutString( Name(), &n ); + PutString( Value(), &v ); + + if (value.find ('\"') == TIXMLA_STRING::npos) + fprintf (cfile, "%s=\"%s\"", n.c_str(), v.c_str() ); + else + fprintf (cfile, "%s='%s'", n.c_str(), v.c_str() ); +} + + +void TiXmlAttributeA::StreamOut( TIXMLA_OSTREAM * stream ) const +{ + if (value.find( '\"' ) != TIXMLA_STRING::npos) + { + PutString( name, stream ); + (*stream) << "=" << "'"; + PutString( value, stream ); + (*stream) << "'"; + } + else + { + PutString( name, stream ); + (*stream) << "=" << "\""; + PutString( value, stream ); + (*stream) << "\""; + } +} + +int TiXmlAttributeA::QueryIntValue( int* ival ) const +{ + if ( sscanf( value.c_str(), "%d", ival ) == 1 ) + return TIXMLA_SUCCESS; + return TIXMLA_WRONG_TYPE; +} + +int TiXmlAttributeA::QueryDoubleValue( double* dval ) const +{ + if ( sscanf( value.c_str(), "%lf", dval ) == 1 ) + return TIXMLA_SUCCESS; + return TIXMLA_WRONG_TYPE; +} + +void TiXmlAttributeA::SetIntValue( int _value ) +{ + char buf [64]; + sprintf (buf, "%d", _value); + SetValue (buf); +} + +void TiXmlAttributeA::SetDoubleValue( double _value ) +{ + char buf [64]; + sprintf (buf, "%lf", _value); + SetValue (buf); +} + +const int TiXmlAttributeA::IntValue() const +{ + return atoi (value.c_str ()); +} + +const double TiXmlAttributeA::DoubleValue() const +{ + return atof (value.c_str ()); +} + +void TiXmlCommentA::Print( FILE* cfile, int depth ) const +{ + for ( int i=0; i", value.c_str() ); +} + +void TiXmlCommentA::StreamOut( TIXMLA_OSTREAM * stream ) const +{ + (*stream) << ""; +} + +TiXmlNodeA* TiXmlCommentA::Clone() const +{ + TiXmlCommentA* clone = new TiXmlCommentA(); + + if ( !clone ) + return 0; + + CopyToClone( clone ); + return clone; +} + + +void TiXmlTextA::Print( FILE* cfile, int /*depth*/ ) const +{ + TIXMLA_STRING buffer; + PutString( value, &buffer ); + fprintf( cfile, "%s", buffer.c_str() ); +} + + +void TiXmlTextA::StreamOut( TIXMLA_OSTREAM * stream ) const +{ + PutString( value, stream ); +} + + +TiXmlNodeA* TiXmlTextA::Clone() const +{ + TiXmlTextA* clone = 0; + clone = new TiXmlTextA( "" ); + + if ( !clone ) + return 0; + + CopyToClone( clone ); + return clone; +} + + +TiXmlDeclarationA::TiXmlDeclarationA( const char * _version, + const char * _encoding, + const char * _standalone ) +: TiXmlNodeA( TiXmlNodeA::DECLARATION ) +{ + version = _version; + encoding = _encoding; + standalone = _standalone; +} + + +void TiXmlDeclarationA::Print( FILE* cfile, int /*depth*/ ) const +{ + fprintf (cfile, ""); +} + +void TiXmlDeclarationA::StreamOut( TIXMLA_OSTREAM * stream ) const +{ + (*stream) << ""; +} + +TiXmlNodeA* TiXmlDeclarationA::Clone() const +{ + TiXmlDeclarationA* clone = new TiXmlDeclarationA(); + + if ( !clone ) + return 0; + + CopyToClone( clone ); + clone->version = version; + clone->encoding = encoding; + clone->standalone = standalone; + return clone; +} + + +void TiXmlUnknownA::Print( FILE* cfile, int depth ) const +{ + for ( int i=0; i"; // Don't use entities hear! It is unknown. +} + +TiXmlNodeA* TiXmlUnknownA::Clone() const +{ + TiXmlUnknownA* clone = new TiXmlUnknownA(); + + if ( !clone ) + return 0; + + CopyToClone( clone ); + return clone; +} + + +TiXmlAttributeSetA::TiXmlAttributeSetA() +{ + sentinel.next = &sentinel; + sentinel.prev = &sentinel; +} + + +TiXmlAttributeSetA::~TiXmlAttributeSetA() +{ + assert( sentinel.next == &sentinel ); + assert( sentinel.prev == &sentinel ); +} + + +void TiXmlAttributeSetA::Add( TiXmlAttributeA* addMe ) +{ + assert( !Find( addMe->Name() ) ); // Shouldn't be multiply adding to the set. + + addMe->next = &sentinel; + addMe->prev = sentinel.prev; + + sentinel.prev->next = addMe; + sentinel.prev = addMe; +} + +void TiXmlAttributeSetA::Remove( TiXmlAttributeA* removeMe ) +{ + TiXmlAttributeA* node; + + for( node = sentinel.next; node != &sentinel; node = node->next ) + { + if ( node == removeMe ) + { + node->prev->next = node->next; + node->next->prev = node->prev; + node->next = 0; + node->prev = 0; + return; + } + } + assert( 0 ); // we tried to remove a non-linked attribute. +} + +TiXmlAttributeA* TiXmlAttributeSetA::Find( const char * name ) const +{ + TiXmlAttributeA* node; + + for( node = sentinel.next; node != &sentinel; node = node->next ) + { + if ( node->name == name ) + return node; + } + return 0; +} + + +#ifdef TIXMLA_USE_STL +TIXMLA_ISTREAM & operator >> (TIXMLA_ISTREAM & in, TiXmlNodeA & base) +{ + TIXMLA_STRING tag; + tag.reserve( 8 * 1000 ); + base.StreamIn( &in, &tag ); + + base.Parse( tag.c_str(), 0 ); + return in; +} +#endif + + +TIXMLA_OSTREAM & operator<< (TIXMLA_OSTREAM & out, const TiXmlNodeA & base) +{ + base.StreamOut (& out); + return out; +} + + +#ifdef TIXMLA_USE_STL +std::string & operator<< (std::string& out, const TiXmlNodeA& base ) +{ + std::ostringstream os_stream( std::ostringstream::out ); + base.StreamOut( &os_stream ); + + out.append( os_stream.str() ); + return out; +} +#endif + + +TiXmlHandleA TiXmlHandleA::FirstChild() const +{ + if ( node ) + { + TiXmlNodeA* child = node->FirstChild(); + if ( child ) + return TiXmlHandleA( child ); + } + return TiXmlHandleA( 0 ); +} + + +TiXmlHandleA TiXmlHandleA::FirstChild( const char * value ) const +{ + if ( node ) + { + TiXmlNodeA* child = node->FirstChild( value ); + if ( child ) + return TiXmlHandleA( child ); + } + return TiXmlHandleA( 0 ); +} + + +TiXmlHandleA TiXmlHandleA::FirstChildElement() const +{ + if ( node ) + { + TiXmlElementA* child = node->FirstChildElement(); + if ( child ) + return TiXmlHandleA( child ); + } + return TiXmlHandleA( 0 ); +} + + +TiXmlHandleA TiXmlHandleA::FirstChildElement( const char * value ) const +{ + if ( node ) + { + TiXmlElementA* child = node->FirstChildElement( value ); + if ( child ) + return TiXmlHandleA( child ); + } + return TiXmlHandleA( 0 ); +} + +TiXmlHandleA TiXmlHandleA::Child( int count ) const +{ + if ( node ) + { + int i; + TiXmlNodeA* child = node->FirstChild(); + for ( i=0; + child && iNextSibling(), ++i ) + { + // nothing + } + if ( child ) + return TiXmlHandleA( child ); + } + return TiXmlHandleA( 0 ); +} + + +TiXmlHandleA TiXmlHandleA::Child( const char* value, int count ) const +{ + if ( node ) + { + int i; + TiXmlNodeA* child = node->FirstChild( value ); + for ( i=0; + child && iNextSibling( value ), ++i ) + { + // nothing + } + if ( child ) + return TiXmlHandleA( child ); + } + return TiXmlHandleA( 0 ); +} + + +TiXmlHandleA TiXmlHandleA::ChildElement( int count ) const +{ + if ( node ) + { + int i; + TiXmlElementA* child = node->FirstChildElement(); + for ( i=0; + child && iNextSiblingElement(), ++i ) + { + // nothing + } + if ( child ) + return TiXmlHandleA( child ); + } + return TiXmlHandleA( 0 ); +} + + +TiXmlHandleA TiXmlHandleA::ChildElement( const char* value, int count ) const +{ + if ( node ) + { + int i; + TiXmlElementA* child = node->FirstChildElement( value ); + for ( i=0; + child && iNextSiblingElement( value ), ++i ) + { + // nothing + } + if ( child ) + return TiXmlHandleA( child ); + } + return TiXmlHandleA( 0 ); +} diff --git a/PowerEditor/src/TinyXml/tinyXmlA/tinyxmlA.h b/PowerEditor/src/TinyXml/tinyXmlA/tinyxmlA.h new file mode 100644 index 00000000..50cd395a --- /dev/null +++ b/PowerEditor/src/TinyXml/tinyXmlA/tinyxmlA.h @@ -0,0 +1,1263 @@ +/* +www.sourceforge.net/projects/tinyxml +Original code (2.0 and earlier )copyright (c) 2000-2002 Lee Thomason (www.grinninglizard.com) + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + + +#ifndef TINYXMLA_INCLUDED +#define TINYXMLA_INCLUDED + +#ifdef _MSC_VER +#pragma warning( disable : 4530 ) +#pragma warning( disable : 4786 ) +#endif + +#include +#include +#include +#include +#include +#include +#include "Common.h" + +// Help out windows: +#if defined( _DEBUG ) && !defined( DEBUG ) +#define DEBUG +#endif + +#if defined( DEBUG ) && defined( _MSC_VER ) +#include +#define TIXMLA_LOG OutputDebugString +#else +#define TIXMLA_LOG printf +#endif + +#ifdef TIXMLA_USE_STL + #include + #include + //#include + #define TIXMLA_STRING std::string + #define TIXMLA_ISTREAM std::istream + #define TIXMLA_OSTREAM std::ostream +#else + #include "tinystrA.h" + #define TIXMLA_STRING TiXmlStringA + #define TIXMLA_OSTREAM TiXmlOutStreamA +#endif + +class TiXmlDocumentA; +class TiXmlElementA; +class TiXmlCommentA; +class TiXmlUnknownA; +class TiXmlAttributeA; +class TiXmlTextA; +class TiXmlDeclarationA; + +class TiXmlParsingDataA; + +/* Internal structure for tracking location of items + in the XML file. +*/ +struct TiXmlCursorA +{ + TiXmlCursorA() { Clear(); } + void Clear() { row = col = -1; } + + int row; // 0 based. + int col; // 0 based. +}; + + +// Only used by Attribute::Query functions +enum +{ + TIXMLA_SUCCESS, + TIXMLA_NO_ATTRIBUTE, + TIXMLA_WRONG_TYPE +}; + +/** TiXmlBaseA is a base class for every class in TinyXml. + It does little except to establish that TinyXml classes + can be printed and provide some utility functions. + + In XML, the document and elements can contain + other elements and other types of nodes. + + @verbatim + A Document can contain: Element (container or leaf) + Comment (leaf) + Unknown (leaf) + Declaration( leaf ) + + An Element can contain: Element (container or leaf) + Text (leaf) + Attributes (not on tree) + Comment (leaf) + Unknown (leaf) + + A Decleration contains: Attributes (not on tree) + @endverbatim +*/ +class TiXmlBaseA +{ + friend class TiXmlNodeA; + friend class TiXmlElementA; + friend class TiXmlDocumentA; + +public: + TiXmlBaseA() {} + virtual ~TiXmlBaseA() {} + + /** All TinyXml classes can print themselves to a filestream. + This is a formatted print, and will insert tabs and newlines. + + (For an unformatted stream, use the << operator.) + */ + virtual void Print( FILE* cfile, int depth ) const = 0; + + /** The world does not agree on whether white space should be kept or + not. In order to make everyone happy, these global, static functions + are provided to set whether or not TinyXml will condense all white space + into a single space or not. The default is to condense. Note changing this + values is not thread safe. + */ + static void SetCondenseWhiteSpace( bool condense ) { condenseWhiteSpace = condense; } + + /// Return the current white space setting. + static bool IsWhiteSpaceCondensed() { return condenseWhiteSpace; } + + /** Return the position, in the original source file, of this node or attribute. + The row and column are 1-based. (That is the first row and first column is + 1,1). If the returns values are 0 or less, then the parser does not have + a row and column value. + + Generally, the row and column value will be set when the TiXmlDocumentA::Load(), + TiXmlDocumentA::LoadFile(), or any TiXmlNodeA::Parse() is called. It will NOT be set + when the DOM was created from operator>>. + + The values reflect the initial load. Once the DOM is modified programmatically + (by adding or changing nodes and attributes) the new values will NOT update to + reflect changes in the document. + + There is a minor performance cost to computing the row and column. Computation + can be disabled if TiXmlDocumentA::SetTabSize() is called with 0 as the value. + + @sa TiXmlDocumentA::SetTabSize() + */ + int Row() const { return location.row + 1; } + int Column() const { return location.col + 1; } ///< See Row() + +protected: + // See STL_STRING_BUG + // Utility class to overcome a bug. + class StringToBuffer + { + public: + StringToBuffer( const TIXMLA_STRING& str ); + ~StringToBuffer(); + char* buffer; + }; + + static const char* SkipWhiteSpace( const char* ); + inline static bool IsWhiteSpace( int c ) { return ( isspace( c ) || c == '\n' || c == '\r' ); } + + virtual void StreamOut (TIXMLA_OSTREAM *) const = 0; + + #ifdef TIXMLA_USE_STL + static bool StreamWhiteSpace( TIXMLA_ISTREAM * in, TIXMLA_STRING * tag ); + static bool StreamTo( TIXMLA_ISTREAM * in, int character, TIXMLA_STRING * tag ); + #endif + + /* Reads an XML name into the string provided. Returns + a pointer just past the last character of the name, + or 0 if the function has an error. + */ + static const char* ReadName( const char* p, TIXMLA_STRING* name ); + + /* Reads text. Returns a pointer past the given end tag. + Wickedly complex options, but it keeps the (sensitive) code in one place. + */ + static const char* ReadText( const char* in, // where to start + TIXMLA_STRING* text, // the string read + bool ignoreWhiteSpace, // whether to keep the white space + const char* endTag, // what ends this text + bool ignoreCase ); // whether to ignore case in the end tag + + virtual const char* Parse( const char* p, TiXmlParsingDataA* data ) = 0; + + // If an entity has been found, transform it into a character. + static const char* GetEntity( const char* in, char* value ); + + // Get a character, while interpreting entities. + inline static const char* GetChar( const char* p, char* _value ) + { + assert( p ); + if ( *p == '&' ) + { + return GetEntity( p, _value ); + } + else + { + *_value = *p; + return p+1; + } + } + + // Puts a string to a stream, expanding entities as it goes. + // Note this should not contian the '<', '>', etc, or they will be transformed into entities! + static void PutString( const TIXMLA_STRING& str, TIXMLA_OSTREAM* out ); + + static void PutString( const TIXMLA_STRING& str, TIXMLA_STRING* out ); + + // Return true if the next characters in the stream are any of the endTag sequences. + static bool StringEqual( const char* p, + const char* endTag, + bool ignoreCase ); + + + enum + { + TIXMLA_NO_ERROR = 0, + TIXMLA_ERROR, + TIXMLA_ERROR_OPENING_FILE, + TIXMLA_ERROR_OUT_OF_MEMORY, + TIXMLA_ERROR_PARSING_ELEMENT, + TIXMLA_ERROR_FAILED_TO_READ_ELEMENT_NAME, + TIXMLA_ERROR_READING_ELEMENT_VALUE, + TIXMLA_ERROR_READING_ATTRIBUTES, + TIXMLA_ERROR_PARSING_EMPTY, + TIXMLA_ERROR_READING_END_TAG, + TIXMLA_ERROR_PARSING_UNKNOWN, + TIXMLA_ERROR_PARSING_COMMENT, + TIXMLA_ERROR_PARSING_DECLARATION, + TIXMLA_ERROR_DOCUMENT_EMPTY, + + TIXMLA_ERROR_STRING_COUNT + }; + static const char* errorString[ TIXMLA_ERROR_STRING_COUNT ]; + + TiXmlCursorA location; + +private: + struct Entity + { + const char* str; + unsigned int strLength; + char chr; + }; + enum + { + NUM_ENTITY = 5, + MAX_ENTITY_LENGTH = 6 + + }; + static Entity entity[ NUM_ENTITY ]; + static bool condenseWhiteSpace; +}; + + +/** The parent class for everything in the Document Object Model. + (Except for attributes). + Nodes have siblings, a parent, and children. A node can be + in a document, or stand on its own. The type of a TiXmlNodeA + can be queried, and it can be cast to its more defined type. +*/ +class TiXmlNodeA : public TiXmlBaseA +{ + friend class TiXmlDocumentA; + friend class TiXmlElementA; + +public: + #ifdef TIXMLA_USE_STL + + /** An input stream operator, for every class. Tolerant of newlines and + formatting, but doesn't expect them. + */ + friend std::istream& operator >> (std::istream& in, TiXmlNodeA& base); + + /** An output stream operator, for every class. Note that this outputs + without any newlines or formatting, as opposed to Print(), which + includes tabs and new lines. + + The operator<< and operator>> are not completely symmetric. Writing + a node to a stream is very well defined. You'll get a nice stream + of output, without any extra whitespace or newlines. + + But reading is not as well defined. (As it always is.) If you create + a TiXmlElementA (for example) and read that from an input stream, + the text needs to define an element or junk will result. This is + true of all input streams, but it's worth keeping in mind. + + A TiXmlDocumentA will read nodes until it reads a root element, and + all the children of that root element. + */ + friend std::ostream& operator<< (std::ostream& out, const TiXmlNodeA& base); + + /// Appends the XML node or attribute to a std::string. + friend std::string& operator<< (std::string& out, const TiXmlNodeA& base ); + + #else + // Used internally, not part of the public API. + friend TIXMLA_OSTREAM& operator<< (TIXMLA_OSTREAM& out, const TiXmlNodeA& base); + #endif + + /** The types of XML nodes supported by TinyXml. (All the + unsupported types are picked up by UNKNOWN.) + */ + enum NodeType + { + DOCUMENT, + ELEMENT, + COMMENT, + UNKNOWN, + TEXT, + DECLARATION, + TYPECOUNT + }; + + virtual ~TiXmlNodeA(); + + /** The meaning of 'value' changes for the specific type of + TiXmlNodeA. + @verbatim + Document: filename of the xml file + Element: name of the element + Comment: the comment text + Unknown: the tag contents + Text: the text string + @endverbatim + + The subclasses will wrap this function. + */ + const char * Value() const { return value.c_str (); } + + /** Changes the value of the node. Defined as: + @verbatim + Document: filename of the xml file + Element: name of the element + Comment: the comment text + Unknown: the tag contents + Text: the text string + @endverbatim + */ + void SetValue(const char * _value) { value = _value;} + + #ifdef TIXMLA_USE_STL + /// STL std::string form. + void SetValue( const std::string& _value ) + { + StringToBuffer buf( _value ); + SetValue( buf.buffer ? buf.buffer : "" ); + } + #endif + + /// Delete all the children of this node. Does not affect 'this'. + void Clear(); + + /// One step up the DOM. + TiXmlNodeA* Parent() const { return parent; } + + TiXmlNodeA* FirstChild() const { return firstChild; } ///< The first child of this node. Will be null if there are no children. + TiXmlNodeA* FirstChild( const char * value ) const; ///< The first child of this node with the matching 'value'. Will be null if none found. + + TiXmlNodeA* LastChild() const { return lastChild; } /// The last child of this node. Will be null if there are no children. + TiXmlNodeA* LastChild( const char * value ) const; /// The last child of this node matching 'value'. Will be null if there are no children. + + #ifdef TIXMLA_USE_STL + TiXmlNodeA* FirstChild( const std::string& _value ) const { return FirstChild (_value.c_str ()); } ///< STL std::string form. + TiXmlNodeA* LastChild( const std::string& _value ) const { return LastChild (_value.c_str ()); } ///< STL std::string form. + #endif + + /** An alternate way to walk the children of a node. + One way to iterate over nodes is: + @verbatim + for( child = parent->FirstChild(); child; child = child->NextSibling() ) + @endverbatim + + IterateChildren does the same thing with the syntax: + @verbatim + child = 0; + while( child = parent->IterateChildren( child ) ) + @endverbatim + + IterateChildren takes the previous child as input and finds + the next one. If the previous child is null, it returns the + first. IterateChildren will return null when done. + */ + TiXmlNodeA* IterateChildren( TiXmlNodeA* previous ) const; + + /// This flavor of IterateChildren searches for children with a particular 'value' + TiXmlNodeA* IterateChildren( const char * value, TiXmlNodeA* previous ) const; + + #ifdef TIXMLA_USE_STL + TiXmlNodeA* IterateChildren( const std::string& _value, TiXmlNodeA* previous ) const { return IterateChildren (_value.c_str (), previous); } ///< STL std::string form. + #endif + + /** Add a new node related to this. Adds a child past the LastChild. + Returns a pointer to the new object or NULL if an error occured. + */ + TiXmlNodeA* InsertEndChild( const TiXmlNodeA& addThis ); + + + /** Add a new node related to this. Adds a child past the LastChild. + + NOTE: the node to be added is passed by pointer, and will be + henceforth owned (and deleted) by tinyXml. This method is efficient + and avoids an extra copy, but should be used with care as it + uses a different memory model than the other insert functions. + + @sa InsertEndChild + */ + TiXmlNodeA* LinkEndChild( TiXmlNodeA* addThis ); + + /** Add a new node related to this. Adds a child before the specified child. + Returns a pointer to the new object or NULL if an error occured. + */ + TiXmlNodeA* InsertBeforeChild( TiXmlNodeA* beforeThis, const TiXmlNodeA& addThis ); + + /** Add a new node related to this. Adds a child after the specified child. + Returns a pointer to the new object or NULL if an error occured. + */ + TiXmlNodeA* InsertAfterChild( TiXmlNodeA* afterThis, const TiXmlNodeA& addThis ); + + /** Replace a child of this node. + Returns a pointer to the new object or NULL if an error occured. + */ + TiXmlNodeA* ReplaceChild( TiXmlNodeA* replaceThis, const TiXmlNodeA& withThis ); + + /// Delete a child of this node. + bool RemoveChild( TiXmlNodeA* removeThis ); + + /// Navigate to a sibling node. + TiXmlNodeA* PreviousSibling() const { return prev; } + + /// Navigate to a sibling node. + TiXmlNodeA* PreviousSibling( const char * ) const; + + #ifdef TIXMLA_USE_STL + TiXmlNodeA* PreviousSibling( const std::string& _value ) const { return PreviousSibling (_value.c_str ()); } ///< STL std::string form. + TiXmlNodeA* NextSibling( const std::string& _value) const { return NextSibling (_value.c_str ()); } ///< STL std::string form. + #endif + + /// Navigate to a sibling node. + TiXmlNodeA* NextSibling() const { return next; } + + /// Navigate to a sibling node with the given 'value'. + TiXmlNodeA* NextSibling( const char * ) const; + + /** Convenience function to get through elements. + Calls NextSibling and ToElement. Will skip all non-Element + nodes. Returns 0 if there is not another element. + */ + TiXmlElementA* NextSiblingElement() const; + + /** Convenience function to get through elements. + Calls NextSibling and ToElement. Will skip all non-Element + nodes. Returns 0 if there is not another element. + */ + TiXmlElementA* NextSiblingElement( const char * ) const; + + #ifdef TIXMLA_USE_STL + TiXmlElementA* NextSiblingElement( const std::string& _value) const { return NextSiblingElement (_value.c_str ()); } ///< STL std::string form. + #endif + + /// Convenience function to get through elements. + TiXmlElementA* FirstChildElement() const; + + /// Convenience function to get through elements. + TiXmlElementA* FirstChildElement( const char * value ) const; + + #ifdef TIXMLA_USE_STL + TiXmlElementA* FirstChildElement( const std::string& _value ) const { return FirstChildElement (_value.c_str ()); } ///< STL std::string form. + #endif + + /** Query the type (as an enumerated value, above) of this node. + The possible types are: DOCUMENT, ELEMENT, COMMENT, + UNKNOWN, TEXT, and DECLARATION. + */ + virtual int Type() const { return type; } + + /** Return a pointer to the Document this node lives in. + Returns null if not in a document. + */ + TiXmlDocumentA* GetDocument() const; + + /// Returns true if this node has no children. + bool NoChildren() const { return !firstChild; } + + TiXmlDocumentA* ToDocument() const { return ( this && type == DOCUMENT ) ? (TiXmlDocumentA*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. + TiXmlElementA* ToElement() const { return ( this && type == ELEMENT ) ? (TiXmlElementA*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. + TiXmlCommentA* ToComment() const { return ( this && type == COMMENT ) ? (TiXmlCommentA*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. + TiXmlUnknownA* ToUnknown() const { return ( this && type == UNKNOWN ) ? (TiXmlUnknownA*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. + TiXmlTextA* ToText() const { return ( this && type == TEXT ) ? (TiXmlTextA*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. + TiXmlDeclarationA* ToDeclaration() const { return ( this && type == DECLARATION ) ? (TiXmlDeclarationA*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. + + virtual TiXmlNodeA* Clone() const = 0; + + void SetUserData( void* user ) { userData = user; } + void* GetUserData() { return userData; } + +protected: + TiXmlNodeA( NodeType type ); + + #ifdef TIXMLA_USE_STL + // The real work of the input operator. + virtual void StreamIn( TIXMLA_ISTREAM* in, TIXMLA_STRING* tag ) = 0; + #endif + + // Figure out what is at *p, and parse it. Returns null if it is not an xml node. + TiXmlNodeA* Identify( const char* start ); + void CopyToClone( TiXmlNodeA* target ) const { target->SetValue (value.c_str() ); + target->userData = userData; } + + // Internal Value function returning a TIXMLA_STRING + TIXMLA_STRING SValue() const { return value ; } + + TiXmlNodeA* parent; + NodeType type; + + TiXmlNodeA* firstChild; + TiXmlNodeA* lastChild; + + TIXMLA_STRING value; + + TiXmlNodeA* prev; + TiXmlNodeA* next; + void* userData; +}; + + +/** An attribute is a name-value pair. Elements have an arbitrary + number of attributes, each with a unique name. + + @note The attributes are not TiXmlNodes, since they are not + part of the tinyXML document object model. There are other + suggested ways to look at this problem. +*/ +class TiXmlAttributeA : public TiXmlBaseA +{ + friend class TiXmlAttributeSetA; + +public: + /// Construct an empty attribute. + TiXmlAttributeA() + { + document = 0; + prev = next = 0; + } + + #ifdef TIXMLA_USE_STL + /// std::string constructor. + TiXmlAttributeA( const std::string& _name, const std::string& _value ) + { + name = _name; + value = _value; + document = 0; + prev = next = 0; + } + #endif + + /// Construct an attribute with a name and value. + TiXmlAttributeA( const char * _name, const char * _value ) + { + name = _name; + value = _value; + document = 0; + prev = next = 0; + } + + const char* Name() const { return name.c_str (); } ///< Return the name of this attribute. + const char* Value() const { return value.c_str (); } ///< Return the value of this attribute. + const int IntValue() const; ///< Return the value of this attribute, converted to an integer. + const double DoubleValue() const; ///< Return the value of this attribute, converted to a double. + + /** QueryIntValue examines the value string. It is an alternative to the + IntValue() method with richer error checking. + If the value is an integer, it is stored in 'value' and + the call returns TIXMLA_SUCCESS. If it is not + an integer, it returns TIXMLA_WRONG_TYPE. + + A specialized but useful call. Note that for success it returns 0, + which is the opposite of almost all other TinyXml calls. + */ + int QueryIntValue( int* value ) const; + /// QueryDoubleValue examines the value string. See QueryIntValue(). + int QueryDoubleValue( double* value ) const; + + void SetName( const char* _name ) { name = _name; } ///< Set the name of this attribute. + void SetValue( const char* _value ) { value = _value; } ///< Set the value. + + void SetIntValue( int value ); ///< Set the value from an integer. + void SetDoubleValue( double value ); ///< Set the value from a double. + + #ifdef TIXMLA_USE_STL + /// STL std::string form. + void SetName( const std::string& _name ) + { + StringToBuffer buf( _name ); + SetName ( buf.buffer ? buf.buffer : "error" ); + } + /// STL std::string form. + void SetValue( const std::string& _value ) + { + StringToBuffer buf( _value ); + SetValue( buf.buffer ? buf.buffer : "error" ); + } + #endif + + /// Get the next sibling attribute in the DOM. Returns null at end. + TiXmlAttributeA* Next() const; + /// Get the previous sibling attribute in the DOM. Returns null at beginning. + TiXmlAttributeA* Previous() const; + + bool operator==( const TiXmlAttributeA& rhs ) const { return rhs.name == name; } + bool operator<( const TiXmlAttributeA& rhs ) const { return name < rhs.name; } + bool operator>( const TiXmlAttributeA& rhs ) const { return name > rhs.name; } + + /* [internal use] + Attribtue parsing starts: first letter of the name + returns: the next char after the value end quote + */ + virtual const char* Parse( const char* p, TiXmlParsingDataA* data ); + + // [internal use] + virtual void Print( FILE* cfile, int depth ) const; + + virtual void StreamOut( TIXMLA_OSTREAM * out ) const; + // [internal use] + // Set the document pointer so the attribute can report errors. + void SetDocument( TiXmlDocumentA* doc ) { document = doc; } + +private: + TiXmlDocumentA* document; // A pointer back to a document, for error reporting. + TIXMLA_STRING name; + TIXMLA_STRING value; + TiXmlAttributeA* prev; + TiXmlAttributeA* next; +}; + + +/* A class used to manage a group of attributes. + It is only used internally, both by the ELEMENT and the DECLARATION. + + The set can be changed transparent to the Element and Declaration + classes that use it, but NOT transparent to the Attribute + which has to implement a next() and previous() method. Which makes + it a bit problematic and prevents the use of STL. + + This version is implemented with circular lists because: + - I like circular lists + - it demonstrates some independence from the (typical) doubly linked list. +*/ +class TiXmlAttributeSetA +{ +public: + TiXmlAttributeSetA(); + ~TiXmlAttributeSetA(); + + void Add( TiXmlAttributeA* attribute ); + void Remove( TiXmlAttributeA* attribute ); + + TiXmlAttributeA* First() const { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; } + TiXmlAttributeA* Last() const { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; } + TiXmlAttributeA* Find( const char * name ) const; + +private: + TiXmlAttributeA sentinel; +}; + + +/** The element is a container class. It has a value, the element name, + and can contain other elements, text, comments, and unknowns. + Elements also contain an arbitrary number of attributes. +*/ +class TiXmlElementA : public TiXmlNodeA +{ +public: + /// Construct an element. + TiXmlElementA (const char * in_value); + + #ifdef TIXMLA_USE_STL + /// std::string constructor. + TiXmlElementA( const std::string& _value ) : TiXmlNodeA( TiXmlNodeA::ELEMENT ) + { + firstChild = lastChild = 0; + value = _value; + } + #endif + + virtual ~TiXmlElementA(); + + /** Given an attribute name, Attribute() returns the value + for the attribute of that name, or null if none exists. + */ + const char* Attribute( const char* name ) const; + + /** Given an attribute name, Attribute() returns the value + for the attribute of that name, or null if none exists. + If the attribute exists and can be converted to an integer, + the integer value will be put in the return 'i', if 'i' + is non-null. + */ + const char* Attribute( const char* name, int* i ) const; + + /** Given an attribute name, Attribute() returns the value + for the attribute of that name, or null if none exists. + If the attribute exists and can be converted to an double, + the double value will be put in the return 'd', if 'd' + is non-null. + */ + const char* Attribute( const char* name, double* d ) const; + + /** QueryIntAttribute examines the attribute - it is an alternative to the + Attribute() method with richer error checking. + If the attribute is an integer, it is stored in 'value' and + the call returns TIXMLA_SUCCESS. If it is not + an integer, it returns TIXMLA_WRONG_TYPE. If the attribute + does not exist, then TIXMLA_NO_ATTRIBUTE is returned. + */ + int QueryIntAttribute( const char* name, int* value ) const; + /// QueryDoubleAttribute examines the attribute - see QueryIntAttribute(). + int QueryDoubleAttribute( const char* name, double* value ) const; + + /** Sets an attribute of name to a given value. The attribute + will be created if it does not exist, or changed if it does. + */ + void SetAttribute( const char* name, const char * value ); + + #ifdef TIXMLA_USE_STL + const char* Attribute( const std::string& name ) const { return Attribute( name.c_str() ); } + const char* Attribute( const std::string& name, int* i ) const { return Attribute( name.c_str(), i ); } + + /// STL std::string form. + void SetAttribute( const std::string& name, const std::string& _value ) + { + StringToBuffer n( name ); + StringToBuffer v( _value ); + if ( n.buffer && v.buffer ) + SetAttribute (n.buffer, v.buffer ); + } + ///< STL std::string form. + void SetAttribute( const std::string& name, int _value ) + { + StringToBuffer n( name ); + if ( n.buffer ) + SetAttribute (n.buffer, _value); + } + #endif + + /** Sets an attribute of name to a given value. The attribute + will be created if it does not exist, or changed if it does. + */ + void SetAttribute( const char * name, int value ); + + /** Deletes an attribute with the given name. + */ + void RemoveAttribute( const char * name ); + #ifdef TIXMLA_USE_STL + void RemoveAttribute( const std::string& name ) { RemoveAttribute (name.c_str ()); } ///< STL std::string form. + #endif + + TiXmlAttributeA* FirstAttribute() const { return attributeSet.First(); } ///< Access the first attribute in this element. + TiXmlAttributeA* LastAttribute() const { return attributeSet.Last(); } ///< Access the last attribute in this element. + + // [internal use] Creates a new Element and returs it. + virtual TiXmlNodeA* Clone() const; + // [internal use] + + virtual void Print( FILE* cfile, int depth ) const; + +protected: + + // Used to be public [internal use] + #ifdef TIXMLA_USE_STL + virtual void StreamIn( TIXMLA_ISTREAM * in, TIXMLA_STRING * tag ); + #endif + virtual void StreamOut( TIXMLA_OSTREAM * out ) const; + + /* [internal use] + Attribtue parsing starts: next char past '<' + returns: next char past '>' + */ + virtual const char* Parse( const char* p, TiXmlParsingDataA* data ); + + /* [internal use] + Reads the "value" of the element -- another element, or text. + This should terminate with the current end tag. + */ + const char* ReadValue( const char* in, TiXmlParsingDataA* prevData ); + +private: + TiXmlAttributeSetA attributeSet; +}; + + +/** An XML comment. +*/ +class TiXmlCommentA : public TiXmlNodeA +{ +public: + /// Constructs an empty comment. + TiXmlCommentA() : TiXmlNodeA( TiXmlNodeA::COMMENT ) {} + virtual ~TiXmlCommentA() {} + + // [internal use] Creates a new Element and returs it. + virtual TiXmlNodeA* Clone() const; + // [internal use] + virtual void Print( FILE* cfile, int depth ) const; +protected: + // used to be public + #ifdef TIXMLA_USE_STL + virtual void StreamIn( TIXMLA_ISTREAM * in, TIXMLA_STRING * tag ); + #endif + virtual void StreamOut( TIXMLA_OSTREAM * out ) const; + /* [internal use] + Attribtue parsing starts: at the ! of the !-- + returns: next char past '>' + */ + virtual const char* Parse( const char* p, TiXmlParsingDataA* data ); +}; + + +/** XML text. Contained in an element. +*/ +class TiXmlTextA : public TiXmlNodeA +{ + friend class TiXmlElementA; +public: + /// Constructor. + TiXmlTextA (const char * initValue) : TiXmlNodeA (TiXmlNodeA::TEXT) + { + SetValue( initValue ); + } + virtual ~TiXmlTextA() {} + + #ifdef TIXMLA_USE_STL + /// Constructor. + TiXmlTextA( const std::string& initValue ) : TiXmlNodeA (TiXmlNodeA::TEXT) + { + SetValue( initValue ); + } + #endif + + // [internal use] + virtual void Print( FILE* cfile, int depth ) const; + +protected : + // [internal use] Creates a new Element and returns it. + virtual TiXmlNodeA* Clone() const; + virtual void StreamOut ( TIXMLA_OSTREAM * out ) const; + // [internal use] + bool Blank() const; // returns true if all white space and new lines + /* [internal use] + Attribtue parsing starts: First char of the text + returns: next char past '>' + */ + virtual const char* Parse( const char* p, TiXmlParsingDataA* data ); + // [internal use] + #ifdef TIXMLA_USE_STL + virtual void StreamIn( TIXMLA_ISTREAM * in, TIXMLA_STRING * tag ); + #endif +}; + + +/** In correct XML the declaration is the first entry in the file. + @verbatim + + @endverbatim + + TinyXml will happily read or write files without a declaration, + however. There are 3 possible attributes to the declaration: + version, encoding, and standalone. + + Note: In this version of the code, the attributes are + handled as special cases, not generic attributes, simply + because there can only be at most 3 and they are always the same. +*/ +class TiXmlDeclarationA : public TiXmlNodeA +{ +public: + /// Construct an empty declaration. + TiXmlDeclarationA() : TiXmlNodeA( TiXmlNodeA::DECLARATION ) {} + +#ifdef TIXMLA_USE_STL + /// Constructor. + TiXmlDeclarationA( const std::string& _version, + const std::string& _encoding, + const std::string& _standalone ) + : TiXmlNodeA( TiXmlNodeA::DECLARATION ) + { + version = _version; + encoding = _encoding; + standalone = _standalone; + } +#endif + + /// Construct. + TiXmlDeclarationA( const char* _version, + const char* _encoding, + const char* _standalone ); + + virtual ~TiXmlDeclarationA() {} + + /// Version. Will return empty if none was found. + const char * Version() const { return version.c_str (); } + /// Encoding. Will return empty if none was found. + const char * Encoding() const { return encoding.c_str (); } + /// Is this a standalone document? + const char * Standalone() const { return standalone.c_str (); } + + // [internal use] Creates a new Element and returs it. + virtual TiXmlNodeA* Clone() const; + // [internal use] + virtual void Print( FILE* cfile, int depth ) const; + +protected: + // used to be public + #ifdef TIXMLA_USE_STL + virtual void StreamIn( TIXMLA_ISTREAM * in, TIXMLA_STRING * tag ); + #endif + virtual void StreamOut ( TIXMLA_OSTREAM * out) const; + // [internal use] + // Attribtue parsing starts: next char past '<' + // returns: next char past '>' + + virtual const char* Parse( const char* p, TiXmlParsingDataA* data ); + +private: + TIXMLA_STRING version; + TIXMLA_STRING encoding; + TIXMLA_STRING standalone; +}; + + +/** Any tag that tinyXml doesn't recognize is saved as an + unknown. It is a tag of text, but should not be modified. + It will be written back to the XML, unchanged, when the file + is saved. +*/ +class TiXmlUnknownA : public TiXmlNodeA +{ +public: + TiXmlUnknownA() : TiXmlNodeA( TiXmlNodeA::UNKNOWN ) {} + virtual ~TiXmlUnknownA() {} + + // [internal use] + virtual TiXmlNodeA* Clone() const; + // [internal use] + virtual void Print( FILE* cfile, int depth ) const; +protected: + #ifdef TIXMLA_USE_STL + virtual void StreamIn( TIXMLA_ISTREAM * in, TIXMLA_STRING * tag ); + #endif + virtual void StreamOut ( TIXMLA_OSTREAM * out ) const; + /* [internal use] + Attribute parsing starts: First char of the text + returns: next char past '>' + */ + virtual const char* Parse( const char* p, TiXmlParsingDataA* data ); +}; + + +/** Always the top level node. A document binds together all the + XML pieces. It can be saved, loaded, and printed to the screen. + The 'value' of a document node is the xml file name. +*/ +class TiXmlDocumentA : public TiXmlNodeA +{ +public: + /// Create an empty document, that has no name. + TiXmlDocumentA(); + /// Create a document with a name. The name of the document is also the filename of the xml. + TiXmlDocumentA( const char * documentName ); + + #ifdef TIXMLA_USE_STL + /// Constructor. + TiXmlDocumentA( const std::string& documentName ) : + TiXmlNodeA( TiXmlNodeA::DOCUMENT ) + { + value = documentName; + error = false; + } + #endif + + virtual ~TiXmlDocumentA() {} + + /** Load a file using the current document value. + Returns true if successful. Will delete any existing + document data before loading. + */ + bool LoadFile(); + /// Save a file using the current document value. Returns true if successful. + bool SaveFile() const; + /// Load a file using the given filename. Returns true if successful. + bool LoadFile( const char * filename ); + /// Save a file using the given filename. Returns true if successful. + bool SaveFile( const char * filename ) const; + + bool LoadUnicodeFilePath(const TCHAR* filename); + + #ifdef TIXMLA_USE_STL + bool LoadFile( const std::string& filename ) ///< STL std::string version. + { + StringToBuffer f( filename ); + return ( f.buffer && LoadFile( f.buffer )); + } + bool SaveFile( const std::string& filename ) const ///< STL std::string version. + { + StringToBuffer f( filename ); + return ( f.buffer && SaveFile( f.buffer )); + } + #endif + + /** Parse the given null terminated block of xml data. + */ + virtual const char* Parse( const char* p, TiXmlParsingDataA* data = 0 ); + + /** Get the root element -- the only top level element -- of the document. + In well formed XML, there should only be one. TinyXml is tolerant of + multiple elements at the document level. + */ + TiXmlElementA* RootElement() const { return FirstChildElement(); } + + /** If an error occurs, Error will be set to true. Also, + - The ErrorId() will contain the integer identifier of the error (not generally useful) + - The ErrorDesc() method will return the name of the error. (very useful) + - The ErrorRow() and ErrorCol() will return the location of the error (if known) + */ + bool Error() const { return error; } + + /// Contains a textual (english) description of the error if one occurs. + const char * ErrorDesc() const { return errorDesc.c_str (); } + + /** Generally, you probably want the error string ( ErrorDesc() ). But if you + prefer the ErrorId, this function will fetch it. + */ + const int ErrorId() const { return errorId; } + + /** Returns the location (if known) of the error. The first column is column 1, + and the first row is row 1. A value of 0 means the row and column wasn't applicable + (memory errors, for example, have no row/column) or the parser lost the error. (An + error in the error reporting, in that case.) + + @sa SetTabSize, Row, Column + */ + int ErrorRow() { return errorLocation.row+1; } + int ErrorCol() { return errorLocation.col+1; } ///< The column where the error occured. See ErrorRow() + + /** By calling this method, with a tab size + greater than 0, the row and column of each node and attribute is stored + when the file is loaded. Very useful for tracking the DOM back in to + the source file. + + The tab size is required for calculating the location of nodes. If not + set, the default of 4 is used. The tabsize is set per document. Setting + the tabsize to 0 disables row/column tracking. + + Note that row and column tracking is not supported when using operator>>. + + The tab size needs to be enabled before the parse or load. Correct usage: + @verbatim + TiXmlDocumentA doc; + doc.SetTabSize( 8 ); + doc.Load( "myfile.xml" ); + @endverbatim + + @sa Row, Column + */ + void SetTabSize( int _tabsize ) { tabsize = _tabsize; } + + int TabSize() const { return tabsize; } + + /** If you have handled the error, it can be reset with this call. The error + state is automatically cleared if you Parse a new XML block. + */ + void ClearError() { error = false; + errorId = 0; + errorDesc = ""; + errorLocation.row = errorLocation.col = 0; + //errorLocation.last = 0; + } + + /** Dump the document to standard out. */ + void Print() const { Print( stdout, 0 ); } + + // [internal use] + virtual void Print( FILE* cfile, int depth = 0 ) const; + // [internal use] + void SetError( int err, const char* errorLocation, TiXmlParsingDataA* prevData ); + +protected : + virtual void StreamOut ( TIXMLA_OSTREAM * out) const; + // [internal use] + virtual TiXmlNodeA* Clone() const; + #ifdef TIXMLA_USE_STL + virtual void StreamIn( TIXMLA_ISTREAM * in, TIXMLA_STRING * tag ); + #endif + +private: + bool error; + int errorId; + TIXMLA_STRING errorDesc; + int tabsize; + TiXmlCursorA errorLocation; +}; + + +/** + A TiXmlHandleA is a class that wraps a node pointer with null checks; this is + an incredibly useful thing. Note that TiXmlHandleA is not part of the TinyXml + DOM structure. It is a separate utility class. + + Take an example: + @verbatim + + + + + + + @endverbatim + + Assuming you want the value of "attributeB" in the 2nd "Child" element, it's very + easy to write a *lot* of code that looks like: + + @verbatim + TiXmlElementA* root = document.FirstChildElement( "Document" ); + if ( root ) + { + TiXmlElementA* element = root->FirstChildElement( "Element" ); + if ( element ) + { + TiXmlElementA* child = element->FirstChildElement( "Child" ); + if ( child ) + { + TiXmlElementA* child2 = child->NextSiblingElement( "Child" ); + if ( child2 ) + { + // Finally do something useful. + @endverbatim + + And that doesn't even cover "else" cases. TiXmlHandleA addresses the verbosity + of such code. A TiXmlHandleA checks for null pointers so it is perfectly safe + and correct to use: + + @verbatim + TiXmlHandleA docHandle( &document ); + TiXmlElementA* child2 = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", 1 ).Element(); + if ( child2 ) + { + // do something useful + @endverbatim + + Which is MUCH more concise and useful. + + It is also safe to copy handles - internally they are nothing more than node pointers. + @verbatim + TiXmlHandleA handleCopy = handle; + @endverbatim + + What they should not be used for is iteration: + + @verbatim + int i=0; + while ( true ) + { + TiXmlElementA* child = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", i ).Element(); + if ( !child ) + break; + // do something + ++i; + } + @endverbatim + + It seems reasonable, but it is in fact two embedded while loops. The Child method is + a linear walk to find the element, so this code would iterate much more than it needs + to. Instead, prefer: + + @verbatim + TiXmlElementA* child = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).FirstChild( "Child" ).Element(); + + for( child; child; child=child->NextSiblingElement() ) + { + // do something + } + @endverbatim +*/ +class TiXmlHandleA +{ +public: + /// Create a handle from any node (at any depth of the tree.) This can be a null pointer. + TiXmlHandleA( TiXmlNodeA* node ) { this->node = node; } + /// Copy constructor + TiXmlHandleA( const TiXmlHandleA& ref ) { this->node = ref.node; } + + /// Return a handle to the first child node. + TiXmlHandleA FirstChild() const; + /// Return a handle to the first child node with the given name. + TiXmlHandleA FirstChild( const char * value ) const; + /// Return a handle to the first child element. + TiXmlHandleA FirstChildElement() const; + /// Return a handle to the first child element with the given name. + TiXmlHandleA FirstChildElement( const char * value ) const; + + /** Return a handle to the "index" child with the given name. + The first child is 0, the second 1, etc. + */ + TiXmlHandleA Child( const char* value, int index ) const; + /** Return a handle to the "index" child. + The first child is 0, the second 1, etc. + */ + TiXmlHandleA Child( int index ) const; + /** Return a handle to the "index" child element with the given name. + The first child element is 0, the second 1, etc. Note that only TiXmlElements + are indexed: other types are not counted. + */ + TiXmlHandleA ChildElement( const char* value, int index ) const; + /** Return a handle to the "index" child element. + The first child element is 0, the second 1, etc. Note that only TiXmlElements + are indexed: other types are not counted. + */ + TiXmlHandleA ChildElement( int index ) const; + + #ifdef TIXMLA_USE_STL + TiXmlHandleA FirstChild( const std::string& _value ) const { return FirstChild( _value.c_str() ); } + TiXmlHandleA FirstChildElement( const std::string& _value ) const { return FirstChildElement( _value.c_str() ); } + + TiXmlHandleA Child( const std::string& _value, int index ) const { return Child( _value.c_str(), index ); } + TiXmlHandleA ChildElement( const std::string& _value, int index ) const { return ChildElement( _value.c_str(), index ); } + #endif + + /// Return the handle as a TiXmlNodeA. This may return null. + TiXmlNodeA* Node() const { return node; } + /// Return the handle as a TiXmlElementA. This may return null. + TiXmlElementA* Element() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); } + /// Return the handle as a TiXmlTextA. This may return null. + TiXmlTextA* Text() const { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); } + +private: + TiXmlNodeA* node; +}; + + +#endif + diff --git a/PowerEditor/src/TinyXml/tinyXmlA/tinyxmlerrorA.cpp b/PowerEditor/src/TinyXml/tinyXmlA/tinyxmlerrorA.cpp new file mode 100644 index 00000000..2efeeb4e --- /dev/null +++ b/PowerEditor/src/TinyXml/tinyXmlA/tinyxmlerrorA.cpp @@ -0,0 +1,50 @@ +/* +www.sourceforge.net/projects/tinyxml +Original code (2.0 and earlier )copyright (c) 2000-2002 Lee Thomason (www.grinninglizard.com) + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + +#include "tinyxmlA.h" + +// The goal of the seperate error file is to make the first +// step towards localization. tinyxml (currently) only supports +// latin-1, but at least the error messages could now be translated. +// +// It also cleans up the code a bit. +// + +const char* TiXmlBaseA::errorString[ TIXMLA_ERROR_STRING_COUNT ] = +{ + "No error", + "Error", + "Failed to open file", + "Memory allocation failed.", + "Error parsing Element.", + "Failed to read Element name", + "Error reading Element value.", + "Error reading Attributes.", + "Error: empty tag.", + "Error reading end tag.", + "Error parsing Unknown.", + "Error parsing Comment.", + "Error parsing Declaration.", + "Error document empty." +}; diff --git a/PowerEditor/src/TinyXml/tinyXmlA/tinyxmlparserA.cpp b/PowerEditor/src/TinyXml/tinyXmlA/tinyxmlparserA.cpp new file mode 100644 index 00000000..1a13817d --- /dev/null +++ b/PowerEditor/src/TinyXml/tinyXmlA/tinyxmlparserA.cpp @@ -0,0 +1,1157 @@ +/* +www.sourceforge.net/projects/tinyxml +Original code (2.0 and earlier )copyright (c) 2000-2002 Lee Thomason (www.grinninglizard.com) + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + +#include "tinyxmlA.h" +#include + +//#define DEBUG_PARSER + +// Note tha "PutString" hardcodes the same list. This +// is less flexible than it appears. Changing the entries +// or order will break putstring. +TiXmlBaseA::Entity TiXmlBaseA::entity[ NUM_ENTITY ] = +{ + { "&", 5, '&' }, + { "<", 4, '<' }, + { ">", 4, '>' }, + { """, 6, '\"' }, + { "'", 6, '\'' } +}; + + +class TiXmlParsingDataA +{ + friend class TiXmlDocumentA; + public: + //TiXmlParsingDataA( const char* now, const TiXmlParsingDataA* prevData ); + void Stamp( const char* now ); + + const TiXmlCursorA& Cursor() { return cursor; } + //void Update( const char* now ); + + private: + // Only used by the document! + TiXmlParsingDataA( const char* start, int _tabsize, int row, int col ) + { + assert( start ); + stamp = start; + tabsize = _tabsize; + cursor.row = row; + cursor.col = col; + } + + TiXmlCursorA cursor; + const char* stamp; + int tabsize; +}; + + +void TiXmlParsingDataA::Stamp( const char* now ) +{ + assert( now ); + + // Do nothing if the tabsize is 0. + if ( tabsize < 1 ) + { + return; + } + + // Get the current row, column. + int row = cursor.row; + int col = cursor.col; + const char* p = stamp; + assert( p ); + + while ( p < now ) + { + // Code contributed by Fletcher Dunn: (modified by lee) + switch (*p) { + case 0: + // We *should* never get here, but in case we do, don't + // advance past the terminating null character, ever + return; + + case '\r': + // bump down to the next line + ++row; + col = 0; + // Eat the character + ++p; + + // Check for \r\n sequence, and treat this as a single character + if (*p == '\n') { + ++p; + } + break; + + case '\n': + // bump down to the next line + ++row; + col = 0; + + // Eat the character + ++p; + + // Check for \n\r sequence, and treat this as a single + // character. (Yes, this bizarre thing does occur still + // on some arcane platforms...) + if (*p == '\r') { + ++p; + } + break; + + case '\t': + // Eat the character + ++p; + + // Skip to next tab stop + col = (col / tabsize + 1) * tabsize; + break; + + default: + // Eat the character + ++p; + + // Normal char - just advance one column + ++col; + break; + } + } + cursor.row = row; + cursor.col = col; + assert( cursor.row >= -1 ); + assert( cursor.col >= -1 ); + stamp = p; + assert( stamp ); +} + + +const char* TiXmlBaseA::SkipWhiteSpace( const char* p ) +{ + if ( !p || !*p ) + { + return 0; + } + while ( p && *p ) + { + if ( isspace( *p ) || *p == '\n' || *p =='\r' ) // Still using old rules for white space. + ++p; + else + break; + } + + return p; +} + +#ifdef TIXMLA_USE_STL +/*static*/ bool TiXmlBaseA::StreamWhiteSpace( TIXMLA_ISTREAM * in, TIXMLA_STRING * tag ) +{ + for( ;; ) + { + if ( !in->good() ) return false; + + int c = in->peek(); + if ( !IsWhiteSpace( c ) ) + return true; + *tag += in->get(); + } +} + +/*static*/ bool TiXmlBaseA::StreamTo( TIXMLA_ISTREAM * in, int character, TIXMLA_STRING * tag ) +{ + while ( in->good() ) + { + int c = in->peek(); + if ( c == character ) + return true; + + in->get(); + *tag += c; + } + return false; +} +#endif + +const char* TiXmlBaseA::ReadName( const char* p, TIXMLA_STRING * name ) +{ + *name = ""; + assert( p ); + + // Names start with letters or underscores. + // After that, they can be letters, underscores, numbers, + // hyphens, or colons. (Colons are valid ony for namespaces, + // but tinyxml can't tell namespaces from names.) + if ( p && *p + && ( isalpha( (unsigned char) *p ) || *p == '_' ) ) + { + while( p && *p + && ( isalnum( (unsigned char ) *p ) + || *p == '_' + || *p == '-' + || *p == '.' + || *p == ':' ) ) + { + (*name) += *p; + ++p; + } + return p; + } + return 0; +} + +const char* TiXmlBaseA::GetEntity( const char* p, char* value ) +{ + // Presume an entity, and pull it out. + TIXMLA_STRING ent; + int i; + + // Handle the &#x entities. + if ( strncmp( "&#x", p, 3 ) == 0 + && *(p+3) + && *(p+4) + && ( *(p+4) == ';' || *(p+5) == ';' ) + ) + { + *value = 0; + + if ( *(p+4) == ';' ) + { + // Short, one value entity. + if ( isalpha( *(p+3) ) ) *value += ( tolower( *(p+3) ) - 'a' + 10 ); + else *value += ( *(p+3) - '0' ); + + return p+5; + } + else + { + // two value entity + if ( isalpha( *(p+3) ) ) *value += ( tolower( *(p+3) ) - 'a' + 10 ) * 16; + else *value += ( *(p+3) - '0' ) * 16; + + if ( isalpha( *(p+4) ) ) *value += ( tolower( *(p+4) ) - 'a' + 10 ); + else *value += ( *(p+4) - '0' ); + + return p+6; + } + } + + // Now try to match it. + for( i=0; i" so the + // sub-tag can orient itself. + + if ( !StreamTo( in, '<', tag ) ) + { + SetError( TIXMLA_ERROR_PARSING_EMPTY, 0, 0 ); + return; + } + + while ( in->good() ) + { + int tagIndex = tag->length(); + while ( in->good() && in->peek() != '>' ) + { + int c = in->get(); + (*tag) += (char) c; + } + + if ( in->good() ) + { + // We now have something we presume to be a node of + // some sort. Identify it, and call the node to + // continue streaming. + TiXmlNodeA* node = Identify( tag->c_str() + tagIndex ); + + if ( node ) + { + node->StreamIn( in, tag ); + bool isElement = node->ToElement() != 0; + delete node; + node = 0; + + // If this is the root element, we're done. Parsing will be + // done by the >> operator. + if ( isElement ) + { + return; + } + } + else + { + SetError( TIXMLA_ERROR, 0, 0 ); + return; + } + } + } + // We should have returned sooner. + SetError( TIXMLA_ERROR, 0, 0 ); +} + +#endif + +const char* TiXmlDocumentA::Parse( const char* p, TiXmlParsingDataA* prevData ) +{ + ClearError(); + + // Parse away, at the document level. Since a document + // contains nothing but other tags, most of what happens + // here is skipping white space. + if ( !p || !*p ) + { + SetError( TIXMLA_ERROR_DOCUMENT_EMPTY, 0, 0 ); + return 0; + } + + // Note that, for a document, this needs to come + // before the while space skip, so that parsing + // starts from the pointer we are given. + location.Clear(); + if ( prevData ) + { + location.row = prevData->cursor.row; + location.col = prevData->cursor.col; + } + else + { + location.row = 0; + location.col = 0; + } + TiXmlParsingDataA data( p, TabSize(), location.row, location.col ); + location = data.Cursor(); + + p = SkipWhiteSpace( p ); + if ( !p ) + { + SetError( TIXMLA_ERROR_DOCUMENT_EMPTY, 0, 0 ); + return 0; + } + + while ( p && *p ) + { + TiXmlNodeA* node = Identify( p ); + if ( node ) + { + p = node->Parse( p, &data ); + LinkEndChild( node ); + } + else + { + break; + } + p = SkipWhiteSpace( p ); + } + + // All is well. + return p; +} + +void TiXmlDocumentA::SetError( int err, const char* pError, TiXmlParsingDataA* data ) +{ + // The first error in a chain is more accurate - don't set again! + if ( error ) + return; + + assert( err > 0 && err < TIXMLA_ERROR_STRING_COUNT ); + error = true; + errorId = err; + errorDesc = errorString[ errorId ]; + + errorLocation.Clear(); + if ( pError && data ) + { + //TiXmlParsingDataA data( pError, prevData ); + data->Stamp( pError ); + errorLocation = data->Cursor(); + } +} + + +TiXmlNodeA* TiXmlNodeA::Identify( const char* p ) +{ + TiXmlNodeA* returnNode = 0; + + p = SkipWhiteSpace( p ); + if( !p || !*p || *p != '<' ) + { + return 0; + } + + TiXmlDocumentA* doc = GetDocument(); + p = SkipWhiteSpace( p ); + + if ( !p || !*p ) + { + return 0; + } + + // What is this thing? + // - Elements start with a letter or underscore, but xml is reserved. + // - Comments: "; + + if ( !StringEqual( p, startTag, false ) ) + { + document->SetError( TIXMLA_ERROR_PARSING_COMMENT, p, data ); + return 0; + } + p += strlen( startTag ); + p = ReadText( p, &value, false, endTag, false ); + return p; +} + + +const char* TiXmlAttributeA::Parse( const char* p, TiXmlParsingDataA* data ) +{ + p = SkipWhiteSpace( p ); + if ( !p || !*p ) return 0; + + int tabsize = 4; + if ( document ) + tabsize = document->TabSize(); + +// TiXmlParsingDataA data( p, prevData ); + if ( data ) + { + data->Stamp( p ); + location = data->Cursor(); + } + // Read the name, the '=' and the value. + const char* pErr = p; + p = ReadName( p, &name ); + if ( !p || !*p ) + { + if ( document ) document->SetError( TIXMLA_ERROR_READING_ATTRIBUTES, pErr, data ); + return 0; + } + p = SkipWhiteSpace( p ); + if ( !p || !*p || *p != '=' ) + { + if ( document ) document->SetError( TIXMLA_ERROR_READING_ATTRIBUTES, p, data ); + return 0; + } + + ++p; // skip '=' + p = SkipWhiteSpace( p ); + if ( !p || !*p ) + { + if ( document ) document->SetError( TIXMLA_ERROR_READING_ATTRIBUTES, p, data ); + return 0; + } + + const char* end; + + if ( *p == '\'' ) + { + ++p; + end = "\'"; + p = ReadText( p, &value, false, end, false ); + } + else if ( *p == '"' ) + { + ++p; + end = "\""; + p = ReadText( p, &value, false, end, false ); + } + else + { + // All attribute values should be in single or double quotes. + // But this is such a common error that the parser will try + // its best, even without them. + value = ""; + while ( p && *p // existence + && !isspace( *p ) && *p != '\n' && *p != '\r' // whitespace + && *p != '/' && *p != '>' ) // tag end + { + value += *p; + ++p; + } + } + return p; +} + +#ifdef TIXMLA_USE_STL +void TiXmlTextA::StreamIn( TIXMLA_ISTREAM * in, TIXMLA_STRING * tag ) +{ + while ( in->good() ) + { + int c = in->peek(); + if ( c == '<' ) + return; + + (*tag) += c; + in->get(); + } +} +#endif + +const char* TiXmlTextA::Parse( const char* p, TiXmlParsingDataA* data ) +{ + value = ""; +// TiXmlParsingDataA data( p, prevData ); + if ( data ) + { + data->Stamp( p ); + location = data->Cursor(); + } + bool ignoreWhite = true; + + const char* end = "<"; + p = ReadText( p, &value, ignoreWhite, end, false ); + if ( p ) + return p-1; // don't truncate the '<' + return 0; +} + +#ifdef TIXMLA_USE_STL +void TiXmlDeclarationA::StreamIn( TIXMLA_ISTREAM * in, TIXMLA_STRING * tag ) +{ + while ( in->good() ) + { + int c = in->get(); + (*tag) += c; + + if ( c == '>' ) + { + // All is well. + return; + } + } +} +#endif + +const char* TiXmlDeclarationA::Parse( const char* p, TiXmlParsingDataA* data ) +{ + p = SkipWhiteSpace( p ); + // Find the beginning, find the end, and look for + // the stuff in-between. + TiXmlDocumentA* document = GetDocument(); + if ( !p || !*p || !StringEqual( p, "SetError( TIXMLA_ERROR_PARSING_DECLARATION, 0, 0 ); + return 0; + } +// TiXmlParsingDataA data( p, prevData ); + if ( data ) + { + data->Stamp( p ); + location = data->Cursor(); + } + p += 5; + + version = ""; + encoding = ""; + standalone = ""; + + while ( p && *p ) + { + if ( *p == '>' ) + { + ++p; + return p; + } + + p = SkipWhiteSpace( p ); + if ( StringEqual( p, "version", true ) ) + { + TiXmlAttributeA attrib; + p = attrib.Parse( p, data ); + version = attrib.Value(); + } + else if ( StringEqual( p, "encoding", true ) ) + { + TiXmlAttributeA attrib; + p = attrib.Parse( p, data ); + encoding = attrib.Value(); + } + else if ( StringEqual( p, "standalone", true ) ) + { + TiXmlAttributeA attrib; + p = attrib.Parse( p, data ); + standalone = attrib.Value(); + } + else + { + // Read over whatever it is. + while( p && *p && *p != '>' && !isspace( *p ) ) + ++p; + } + } + return 0; +} + +bool TiXmlTextA::Blank() const +{ + for ( unsigned i=0; i +#include +#include + +#include "tinystr.h" + +// TiXmlString constructor, based on a C generic_string +TiXmlString::TiXmlString (const TCHAR* instring) +{ + unsigned newlen; + TCHAR * newstring; + + if (!instring) + { + allocated = 0; + cstring = NULL; + current_length = 0; + return; + } + newlen = lstrlen (instring) + 1; + newstring = new TCHAR [newlen]; + memcpy (newstring, instring, newlen); + // lstrcpy (newstring, instring); + allocated = newlen; + cstring = newstring; + current_length = newlen - 1; +} + +// TiXmlString copy constructor +TiXmlString::TiXmlString (const TiXmlString& copy) +{ + unsigned newlen; + TCHAR * newstring; + + // Prevent copy to self! + if ( © == this ) + return; + + if (! copy . allocated) + { + allocated = 0; + cstring = NULL; + current_length = 0; + return; + } + newlen = copy . length () + 1; + newstring = new TCHAR [newlen]; + // lstrcpy (newstring, copy . cstring); + memcpy (newstring, copy . cstring, newlen); + allocated = newlen; + cstring = newstring; + current_length = newlen - 1; +} + +// TiXmlString = operator. Safe when assign own content +void TiXmlString ::operator = (const TCHAR * content) +{ + unsigned newlen; + TCHAR * newstring; + + if (! content) + { + empty_it (); + return; + } + newlen = lstrlen (content) + 1; + newstring = new TCHAR [newlen]; + // lstrcpy (newstring, content); + memcpy (newstring, content, newlen); + empty_it (); + allocated = newlen; + cstring = newstring; + current_length = newlen - 1; +} + +// = operator. Safe when assign own content +void TiXmlString ::operator = (const TiXmlString & copy) +{ + unsigned newlen; + TCHAR * newstring; + + if (! copy . length ()) + { + empty_it (); + return; + } + newlen = copy . length () + 1; + newstring = new TCHAR [newlen]; + // lstrcpy (newstring, copy . c_str ()); + memcpy (newstring, copy . c_str (), newlen); + empty_it (); + allocated = newlen; + cstring = newstring; + current_length = newlen - 1; +} + + +//// Checks if a TiXmlString contains only whitespace (same rules as isspace) +//bool TiXmlString::isblank () const +//{ +// TCHAR * lookup; +// for (lookup = cstring; * lookup; lookup++) +// if (! isspace (* lookup)) +// return false; +// return true; +//} + +// append a const TCHAR * to an existing TiXmlString +void TiXmlString::append( const TCHAR* str, int len ) +{ + TCHAR * new_string; + unsigned new_alloc, new_size, size_suffix; + + size_suffix = lstrlen (str); + if (len < (int) size_suffix) + size_suffix = len; + if (! size_suffix) + return; + + new_size = length () + size_suffix + 1; + // check if we need to expand + if (new_size > allocated) + { + // compute new size + new_alloc = assign_new_size (new_size); + + // allocate new buffer + new_string = new TCHAR [new_alloc]; + new_string [0] = 0; + + // copy the previous allocated buffer into this one + if (allocated && cstring) + // lstrcpy (new_string, cstring); + memcpy (new_string, cstring, length ()); + + // append the suffix. It does exist, otherwize we wouldn't be expanding + // strncat (new_string, str, len); + memcpy (new_string + length (), + str, + size_suffix); + + // return previsously allocated buffer if any + if (allocated && cstring) + delete [] cstring; + + // update member variables + cstring = new_string; + allocated = new_alloc; + } + else + { + // we know we can safely append the new generic_string + // strncat (cstring, str, len); + memcpy (cstring + length (), + str, + size_suffix); + } + current_length = new_size - 1; + cstring [current_length] = 0; +} + + +// append a const TCHAR * to an existing TiXmlString +void TiXmlString::append( const TCHAR * suffix ) +{ + TCHAR * new_string; + unsigned new_alloc, new_size; + + new_size = length () + lstrlen (suffix) + 1; + // check if we need to expand + if (new_size > allocated) + { + // compute new size + new_alloc = assign_new_size (new_size); + + // allocate new buffer + new_string = new TCHAR [new_alloc]; + new_string [0] = 0; + + // copy the previous allocated buffer into this one + if (allocated && cstring) + memcpy (new_string, cstring, 1 + length ()); + // lstrcpy (new_string, cstring); + + // append the suffix. It does exist, otherwize we wouldn't be expanding + // lstrcat (new_string, suffix); + memcpy (new_string + length (), + suffix, + lstrlen (suffix) + 1); + + // return previsously allocated buffer if any + if (allocated && cstring) + delete [] cstring; + + // update member variables + cstring = new_string; + allocated = new_alloc; + } + else + { + // we know we can safely append the new generic_string + // lstrcat (cstring, suffix); + memcpy (cstring + length (), + suffix, + lstrlen (suffix) + 1); + } + current_length = new_size - 1; +} + +// Check for TiXmlString equuivalence +//bool TiXmlString::operator == (const TiXmlString & compare) const +//{ +// return (! lstrcmp (c_str (), compare . c_str ())); +//} + +//unsigned TiXmlString::length () const +//{ +// if (allocated) +// // return lstrlen (cstring); +// return current_length; +// return 0; +//} + + +unsigned TiXmlString::find (TCHAR tofind, unsigned offset) const +{ + TCHAR * lookup; + + if (offset >= length ()) + return (unsigned) notfound; + for (lookup = cstring + offset; * lookup; lookup++) + if (* lookup == tofind) + return lookup - cstring; + return (unsigned) notfound; +} + + +bool TiXmlString::operator == (const TiXmlString & compare) const +{ + if ( allocated && compare.allocated ) + { + assert( cstring ); + assert( compare.cstring ); + return ( lstrcmp( cstring, compare.cstring ) == 0 ); + } + return false; +} + + +bool TiXmlString::operator < (const TiXmlString & compare) const +{ + if ( allocated && compare.allocated ) + { + assert( cstring ); + assert( compare.cstring ); + return ( lstrcmp( cstring, compare.cstring ) > 0 ); + } + return false; +} + + +bool TiXmlString::operator > (const TiXmlString & compare) const +{ + if ( allocated && compare.allocated ) + { + assert( cstring ); + assert( compare.cstring ); + return ( lstrcmp( cstring, compare.cstring ) < 0 ); + } + return false; +} + + +#endif // TIXML_USE_STL diff --git a/PowerEditor/src/TinyXml/tinystr.h b/PowerEditor/src/TinyXml/tinystr.h new file mode 100644 index 00000000..aeddbaae --- /dev/null +++ b/PowerEditor/src/TinyXml/tinystr.h @@ -0,0 +1,237 @@ +/* +www.sourceforge.net/projects/tinyxml +Original file by Yves Berquin. + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + +#include "tinyxml.h" + + +#ifndef TIXML_USE_STL + +#ifndef TIXML_STRING_INCLUDED +#define TIXML_STRING_INCLUDED + +#pragma warning( disable : 4514 ) + +#include +#include + +/* + TiXmlString is an emulation of the std::generic_string template. + Its purpose is to allow compiling TinyXML on compilers with no or poor STL support. + Only the member functions relevant to the TinyXML project have been implemented. + The buffer allocation is made by a simplistic power of 2 like mechanism : if we increase + a generic_string and there's no more room, we allocate a buffer twice as big as we need. +*/ +class TiXmlString +{ + public : + // TiXmlString constructor, based on a generic_string + TiXmlString (const TCHAR * instring); + + // TiXmlString empty constructor + TiXmlString () + { + allocated = 0; + cstring = NULL; + current_length = 0; + } + + // TiXmlString copy constructor + TiXmlString (const TiXmlString& copy); + + // TiXmlString destructor + ~ TiXmlString () + { + empty_it (); + } + + // Convert a TiXmlString into a classical TCHAR * + const TCHAR * c_str () const + { + if (allocated) + return cstring; + return TEXT(""); + } + + // Return the length of a TiXmlString + unsigned length () const + { + return ( allocated ) ? current_length : 0; + } + + // TiXmlString = operator + void operator = (const TCHAR * content); + + // = operator + void operator = (const TiXmlString & copy); + + // += operator. Maps to append + TiXmlString& operator += (const TCHAR * suffix) + { + append (suffix); + return *this; + } + + // += operator. Maps to append + TiXmlString& operator += (TCHAR single) + { + append (single); + return *this; + } + + // += operator. Maps to append + TiXmlString& operator += (TiXmlString & suffix) + { + append (suffix); + return *this; + } + bool operator == (const TiXmlString & compare) const; + bool operator < (const TiXmlString & compare) const; + bool operator > (const TiXmlString & compare) const; + + // Checks if a TiXmlString is empty + bool empty () const + { + return length () ? false : true; + } + + // Checks if a TiXmlString contains only whitespace (same rules as isspace) + // Not actually used in tinyxml. Conflicts with a C macro, TEXT("isblank"), + // which is a problem. Commenting out. -lee +// bool isblank () const; + + // single TCHAR extraction + const TCHAR& at (unsigned index) const + { + assert( index < length ()); + return cstring [index]; + } + + // find a TCHAR in a generic_string. Return TiXmlString::notfound if not found + unsigned find (TCHAR lookup) const + { + return find (lookup, 0); + } + + // find a TCHAR in a generic_string from an offset. Return TiXmlString::notfound if not found + unsigned find (TCHAR tofind, unsigned offset) const; + + /* Function to reserve a big amount of data when we know we'll need it. Be aware that this + function clears the content of the TiXmlString if any exists. + */ + void reserve (unsigned size) + { + empty_it (); + if (size) + { + allocated = size; + cstring = new TCHAR [size]; + cstring [0] = 0; + current_length = 0; + } + } + + // [] operator + TCHAR& operator [] (unsigned index) const + { + assert( index < length ()); + return cstring [index]; + } + + // Error value for find primitive + enum { notfound = 0xffffffff, + npos = notfound }; + + void append (const TCHAR *str, int len ); + + protected : + + // The base generic_string + TCHAR * cstring; + // Number of chars allocated + unsigned allocated; + // Current generic_string size + unsigned current_length; + + // New size computation. It is simplistic right now : it returns twice the amount + // we need + unsigned assign_new_size (unsigned minimum_to_allocate) + { + return minimum_to_allocate * 2; + } + + // Internal function that clears the content of a TiXmlString + void empty_it () + { + if (cstring) + delete [] cstring; + cstring = NULL; + allocated = 0; + current_length = 0; + } + + void append (const TCHAR *suffix ); + + // append function for another TiXmlString + void append (const TiXmlString & suffix) + { + append (suffix . c_str ()); + } + + // append for a single TCHAR. This could be improved a lot if needed + void append (TCHAR single) + { + TCHAR smallstr [2]; + smallstr [0] = single; + smallstr [1] = 0; + append (smallstr); + } + +} ; + +/* + TiXmlOutStream is an emulation of std::ostream. It is based on TiXmlString. + Only the operators that we need for TinyXML have been developped. +*/ +class TiXmlOutStream : public TiXmlString +{ +public : + TiXmlOutStream () : TiXmlString () {} + + // TiXmlOutStream << operator. Maps to TiXmlString::append + TiXmlOutStream & operator << (const TCHAR * in) + { + append (in); + return (* this); + } + + // TiXmlOutStream << operator. Maps to TiXmlString::append + TiXmlOutStream & operator << (const TiXmlString & in) + { + append (in . c_str ()); + return (* this); + } +} ; + +#endif // TIXML_STRING_INCLUDED +#endif // TIXML_USE_STL diff --git a/PowerEditor/src/TinyXml/tinyxml.cpp b/PowerEditor/src/TinyXml/tinyxml.cpp new file mode 100644 index 00000000..7e18d3da --- /dev/null +++ b/PowerEditor/src/TinyXml/tinyxml.cpp @@ -0,0 +1,1260 @@ +/* +www.sourceforge.net/projects/tinyxml +Original code (2.0 and earlier )copyright (c) 2000-2002 Lee Thomason (www.grinninglizard.com) + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + +#include +#include "tinyxml.h" + +#ifdef TIXML_USE_STL +#include +#endif + +bool TiXmlBase::condenseWhiteSpace = true; + +void TiXmlBase::PutString( const TIXML_STRING& str, TIXML_OSTREAM* stream ) +{ + TIXML_STRING buffer; + PutString( str, &buffer ); + (*stream) << buffer; +} + +void TiXmlBase::PutString( const TIXML_STRING& str, TIXML_STRING* outString ) +{ + int i=0; + + while( i<(int)str.length() ) + { + int c = str[i]; + + if ( c == '&' + && i < ( (int)str.length() - 2 ) + && str[i+1] == '#' + && str[i+2] == 'x' ) + { + // Hexadecimal character reference. + // Pass through unchanged. + // © -- copyright symbol, for example. + while ( i<(int)str.length() ) + { + outString->append( str.c_str() + i, 1 ); + ++i; + if ( str[i] == ';' ) + break; + } + } + else if ( c == '&' ) + { + outString->append( entity[0].str, entity[0].strLength ); + ++i; + } + else if ( c == '<' ) + { + outString->append( entity[1].str, entity[1].strLength ); + ++i; + } + else if ( c == '>' ) + { + outString->append( entity[2].str, entity[2].strLength ); + ++i; + } + else if ( c == '\"' ) + { + outString->append( entity[3].str, entity[3].strLength ); + ++i; + } + else if ( c == '\'' ) + { + outString->append( entity[4].str, entity[4].strLength ); + ++i; + } + else if ( c < 32 || c > 126 ) + { + // Easy pass at non-alpha/numeric/symbol + // 127 is the delete key. Below 32 is symbolic. + TCHAR buf[ 32 ]; + wsprintf( buf, TEXT("&#x%04X;"), (unsigned) ( c & 0xffff ) ); + outString->append( buf, lstrlen( buf ) ); + ++i; + } + else + { + TCHAR realc = (TCHAR) c; + outString->append( &realc, 1 ); + ++i; + } + } +} + + +// <-- Strange class for a bug fix. Search for STL_STRING_BUG +TiXmlBase::StringToBuffer::StringToBuffer( const TIXML_STRING& str ) +{ + buffer = new TCHAR[ str.length()+1 ]; + if ( buffer ) + { + lstrcpy( buffer, str.c_str() ); + } +} + + +TiXmlBase::StringToBuffer::~StringToBuffer() +{ + delete [] buffer; +} +// End strange bug fix. --> + + +TiXmlNode::TiXmlNode( NodeType _type ) +{ + parent = 0; + type = _type; + firstChild = 0; + lastChild = 0; + prev = 0; + next = 0; + userData = 0; +} + + +TiXmlNode::~TiXmlNode() +{ + TiXmlNode* node = firstChild; + TiXmlNode* temp = 0; + + while ( node ) + { + temp = node; + node = node->next; + delete temp; + } +} + + +void TiXmlNode::Clear() +{ + TiXmlNode* node = firstChild; + TiXmlNode* temp = 0; + + while ( node ) + { + temp = node; + node = node->next; + delete temp; + } + + firstChild = 0; + lastChild = 0; +} + + +TiXmlNode* TiXmlNode::LinkEndChild( TiXmlNode* node ) +{ + node->parent = this; + + node->prev = lastChild; + node->next = 0; + + if ( lastChild ) + lastChild->next = node; + else + firstChild = node; // it was an empty list. + + lastChild = node; + return node; +} + + +TiXmlNode* TiXmlNode::InsertEndChild( const TiXmlNode& addThis ) +{ + TiXmlNode* node = addThis.Clone(); + if ( !node ) + return 0; + + return LinkEndChild( node ); +} + + +TiXmlNode* TiXmlNode::InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis ) +{ + if ( !beforeThis || beforeThis->parent != this ) + return 0; + + TiXmlNode* node = addThis.Clone(); + if ( !node ) + return 0; + node->parent = this; + + node->next = beforeThis; + node->prev = beforeThis->prev; + if ( beforeThis->prev ) + { + beforeThis->prev->next = node; + } + else + { + assert( firstChild == beforeThis ); + firstChild = node; + } + beforeThis->prev = node; + return node; +} + + +TiXmlNode* TiXmlNode::InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis ) +{ + if ( !afterThis || afterThis->parent != this ) + return 0; + + TiXmlNode* node = addThis.Clone(); + if ( !node ) + return 0; + node->parent = this; + + node->prev = afterThis; + node->next = afterThis->next; + if ( afterThis->next ) + { + afterThis->next->prev = node; + } + else + { + assert( lastChild == afterThis ); + lastChild = node; + } + afterThis->next = node; + return node; +} + + +TiXmlNode* TiXmlNode::ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis ) +{ + if ( replaceThis->parent != this ) + return 0; + + TiXmlNode* node = withThis.Clone(); + if ( !node ) + return 0; + + node->next = replaceThis->next; + node->prev = replaceThis->prev; + + if ( replaceThis->next ) + replaceThis->next->prev = node; + else + lastChild = node; + + if ( replaceThis->prev ) + replaceThis->prev->next = node; + else + firstChild = node; + + delete replaceThis; + node->parent = this; + return node; +} + + +bool TiXmlNode::RemoveChild( TiXmlNode* removeThis ) +{ + if ( removeThis->parent != this ) + { + assert( 0 ); + return false; + } + + if ( removeThis->next ) + removeThis->next->prev = removeThis->prev; + else + lastChild = removeThis->prev; + + if ( removeThis->prev ) + removeThis->prev->next = removeThis->next; + else + firstChild = removeThis->next; + + delete removeThis; + return true; +} + +TiXmlNode* TiXmlNode::FirstChild( const TCHAR * _value ) const +{ + TiXmlNode* node; + for ( node = firstChild; node; node = node->next ) + { + if ( node->SValue() == TIXML_STRING( _value )) + return node; + } + return 0; +} + +TiXmlNode* TiXmlNode::LastChild( const TCHAR * _value ) const +{ + TiXmlNode* node; + for ( node = lastChild; node; node = node->prev ) + { + if ( node->SValue() == TIXML_STRING (_value)) + return node; + } + return 0; +} + +TiXmlNode* TiXmlNode::IterateChildren( TiXmlNode* previous ) const +{ + if ( !previous ) + { + return FirstChild(); + } + else + { + assert( previous->parent == this ); + return previous->NextSibling(); + } +} + +TiXmlNode* TiXmlNode::IterateChildren( const TCHAR * val, TiXmlNode* previous ) const +{ + if ( !previous ) + { + return FirstChild( val ); + } + else + { + assert( previous->parent == this ); + return previous->NextSibling( val ); + } +} + +TiXmlNode* TiXmlNode::NextSibling( const TCHAR * _value ) const +{ + TiXmlNode* node; + for ( node = next; node; node = node->next ) + { + if ( node->SValue() == TIXML_STRING (_value)) + return node; + } + return 0; +} + + +TiXmlNode* TiXmlNode::PreviousSibling( const TCHAR * _value ) const +{ + TiXmlNode* node; + for ( node = prev; node; node = node->prev ) + { + if ( node->SValue() == TIXML_STRING (_value)) + return node; + } + return 0; +} + +void TiXmlElement::RemoveAttribute( const TCHAR * name ) +{ + TiXmlAttribute* node = attributeSet.Find( name ); + if ( node ) + { + attributeSet.Remove( node ); + delete node; + } +} + +TiXmlElement* TiXmlNode::FirstChildElement() const +{ + TiXmlNode* node; + + for ( node = FirstChild(); + node; + node = node->NextSibling() ) + { + if ( node->ToElement() ) + return node->ToElement(); + } + return 0; +} + +TiXmlElement* TiXmlNode::FirstChildElement( const TCHAR * _value ) const +{ + TiXmlNode* node; + + for ( node = FirstChild( _value ); + node; + node = node->NextSibling( _value ) ) + { + if ( node->ToElement() ) + return node->ToElement(); + } + return 0; +} + + +TiXmlElement* TiXmlNode::NextSiblingElement() const +{ + TiXmlNode* node; + + for ( node = NextSibling(); + node; + node = node->NextSibling() ) + { + if ( node->ToElement() ) + return node->ToElement(); + } + return 0; +} + +TiXmlElement* TiXmlNode::NextSiblingElement( const TCHAR * _value ) const +{ + TiXmlNode* node; + + for ( node = NextSibling( _value ); + node; + node = node->NextSibling( _value ) ) + { + if ( node->ToElement() ) + return node->ToElement(); + } + return 0; +} + + + +TiXmlDocument* TiXmlNode::GetDocument() const +{ + const TiXmlNode* node; + + for( node = this; node; node = node->parent ) + { + if ( node->ToDocument() ) + return node->ToDocument(); + } + return 0; +} + + +TiXmlElement::TiXmlElement (const TCHAR * _value) +: TiXmlNode( TiXmlNode::ELEMENT ) +{ + firstChild = lastChild = 0; + value = _value; +} + +TiXmlElement::~TiXmlElement() +{ + while( attributeSet.First() ) + { + TiXmlAttribute* node = attributeSet.First(); + attributeSet.Remove( node ); + delete node; + } +} + +const TCHAR * TiXmlElement::Attribute( const TCHAR * name ) const +{ + TiXmlAttribute* node = attributeSet.Find( name ); + + if ( node ) + return node->Value(); + + return 0; +} + + +const TCHAR * TiXmlElement::Attribute( const TCHAR * name, int* i ) const +{ + const TCHAR * s = Attribute( name ); + if ( i ) + { + if ( s ) + *i = generic_atoi( s ); + else + *i = 0; + } + return s; +} + + +const TCHAR * TiXmlElement::Attribute( const TCHAR * name, double* d ) const +{ + const TCHAR * s = Attribute( name ); + if ( d ) + { + if ( s ) + *d = generic_atof( s ); + else + *d = 0; + } + return s; +} + + +int TiXmlElement::QueryIntAttribute( const TCHAR* name, int* ival ) const +{ + TiXmlAttribute* node = attributeSet.Find( name ); + if ( !node ) + return TIXML_NO_ATTRIBUTE; + + return node->QueryIntValue( ival ); +} + + +int TiXmlElement::QueryDoubleAttribute( const TCHAR* name, double* dval ) const +{ + TiXmlAttribute* node = attributeSet.Find( name ); + if ( !node ) + return TIXML_NO_ATTRIBUTE; + + return node->QueryDoubleValue( dval ); +} + + +void TiXmlElement::SetAttribute( const TCHAR * name, int val ) +{ + TCHAR buf[64]; + wsprintf( buf, TEXT("%d"), val ); + SetAttribute( name, buf ); +} + + +void TiXmlElement::SetAttribute( const TCHAR * name, const TCHAR * _value ) +{ + TiXmlAttribute* node = attributeSet.Find( name ); + if ( node ) + { + node->SetValue( _value ); + return; + } + + TiXmlAttribute* attrib = new TiXmlAttribute( name, _value ); + if ( attrib ) + { + attributeSet.Add( attrib ); + } + else + { + TiXmlDocument* document = GetDocument(); + if ( document ) document->SetError( TIXML_ERROR_OUT_OF_MEMORY, 0, 0 ); + } +} + +void TiXmlElement::Print( FILE* cfile, int depth ) const +{ + int i; + for ( i=0; iNext() ) + { + generic_fprintf( cfile, TEXT(" ") ); + attrib->Print( cfile, depth ); + } + + // There are 3 different formatting approaches: + // 1) An element without children is printed as a node + // 2) An element with only a text child is printed as text + // 3) An element with children is printed on multiple lines. + TiXmlNode* node; + if ( !firstChild ) + { + generic_fprintf( cfile, TEXT(" />") ); + } + else if ( firstChild == lastChild && firstChild->ToText() ) + { + generic_fprintf( cfile, TEXT(">") ); + firstChild->Print( cfile, depth + 1 ); + generic_fprintf( cfile, TEXT(""), value.c_str() ); + } + else + { + generic_fprintf( cfile, TEXT(">") ); + + for ( node = firstChild; node; node=node->NextSibling() ) + { + if ( !node->ToText() ) + { + generic_fprintf( cfile, TEXT("\n") ); + } + node->Print( cfile, depth+1 ); + } + generic_fprintf( cfile, TEXT("\n") ); + for( i=0; i"), value.c_str() ); + } +} + +void TiXmlElement::StreamOut( TIXML_OSTREAM * stream ) const +{ + (*stream) << TEXT("<") << value; + + TiXmlAttribute* attrib; + for ( attrib = attributeSet.First(); attrib; attrib = attrib->Next() ) + { + (*stream) << TEXT(" "); + attrib->StreamOut( stream ); + } + + // If this node has children, give it a closing tag. Else + // make it an empty tag. + TiXmlNode* node; + if ( firstChild ) + { + (*stream) << TEXT(">"); + + for ( node = firstChild; node; node=node->NextSibling() ) + { + node->StreamOut( stream ); + } + (*stream) << TEXT(""); + } + else + { + (*stream) << TEXT(" />"); + } +} + +TiXmlNode* TiXmlElement::Clone() const +{ + TiXmlElement* clone = new TiXmlElement( Value() ); + if ( !clone ) + return 0; + + CopyToClone( clone ); + + // Clone the attributes, then clone the children. + TiXmlAttribute* attribute = 0; + for( attribute = attributeSet.First(); + attribute; + attribute = attribute->Next() ) + { + clone->SetAttribute( attribute->Name(), attribute->Value() ); + } + + TiXmlNode* node = 0; + for ( node = firstChild; node; node = node->NextSibling() ) + { + clone->LinkEndChild( node->Clone() ); + } + return clone; +} + + +TiXmlDocument::TiXmlDocument() : TiXmlNode( TiXmlNode::DOCUMENT ) +{ + tabsize = 4; + ClearError(); +} + +TiXmlDocument::TiXmlDocument( const TCHAR * documentName ) : TiXmlNode( TiXmlNode::DOCUMENT ) +{ + tabsize = 4; + value = documentName; + ClearError(); +} + +bool TiXmlDocument::LoadFile() +{ + // See STL_STRING_BUG below. + StringToBuffer buf( value ); + + if ( buf.buffer && LoadFile( buf.buffer ) ) + return true; + + return false; +} + + +bool TiXmlDocument::SaveFile() const +{ + // See STL_STRING_BUG below. + StringToBuffer buf( value ); + + if ( buf.buffer && SaveFile( buf.buffer ) ) + return true; + + return false; +} + +bool TiXmlDocument::LoadFile( const TCHAR* filename ) +{ + // Delete the existing data: + Clear(); + location.Clear(); + + // There was a really terrifying little bug here. The code: + // value = filename + // in the STL case, cause the assignment method of the std::generic_string to + // be called. What is strange, is that the std::generic_string had the same + // address as it's c_str() method, and so bad things happen. Looks + // like a bug in the Microsoft STL implementation. + // See STL_STRING_BUG above. + // Fixed with the StringToBuffer class. + value = filename; + + FILE* file = generic_fopen( value.c_str (), TEXT("r") ); + + if ( file ) + { + // Get the file size, so we can pre-allocate the generic_string. HUGE speed impact. + long length = 0; + fseek( file, 0, SEEK_END ); + length = ftell( file ); + fseek( file, 0, SEEK_SET ); + + // Strange case, but good to handle up front. + if ( length == 0 ) + { + fclose( file ); + return false; + } + + // If we have a file, assume it is all one big XML file, and read it in. + // The document parser may decide the document ends sooner than the entire file, however. + TIXML_STRING data; + data.reserve( length ); + + const int BUF_SIZE = 2048; + TCHAR buf[BUF_SIZE]; + + while( generic_fgets( buf, BUF_SIZE, file ) ) + { + data += buf; + } + fclose( file ); + + Parse( data.c_str(), 0 ); + + if ( Error() ) + return false; + else + return true; + } + SetError( TIXML_ERROR_OPENING_FILE, 0, 0 ); + return false; +} + +bool TiXmlDocument::SaveFile( const TCHAR * filename ) const +{ + // The old c stuff lives on... + FILE* fp = generic_fopen( filename, TEXT("w") ); + if ( fp ) + { + Print( fp, 0 ); + fclose( fp ); + return true; + } + return false; +} + + +TiXmlNode* TiXmlDocument::Clone() const +{ + TiXmlDocument* clone = new TiXmlDocument(); + if ( !clone ) + return 0; + + CopyToClone( clone ); + clone->error = error; + clone->errorDesc = errorDesc.c_str (); + + TiXmlNode* node = 0; + for ( node = firstChild; node; node = node->NextSibling() ) + { + clone->LinkEndChild( node->Clone() ); + } + return clone; +} + + +void TiXmlDocument::Print( FILE* cfile, int depth ) const +{ + TiXmlNode* node; + for ( node=FirstChild(); node; node=node->NextSibling() ) + { + node->Print( cfile, depth ); + generic_fprintf( cfile, TEXT("\n") ); + } +} + +void TiXmlDocument::StreamOut( TIXML_OSTREAM * out ) const +{ + TiXmlNode* node; + for ( node=FirstChild(); node; node=node->NextSibling() ) + { + node->StreamOut( out ); + + // Special rule for streams: stop after the root element. + // The stream in code will only read one element, so don't + // write more than one. + if ( node->ToElement() ) + break; + } +} + + +TiXmlAttribute* TiXmlAttribute::Next() const +{ + // We are using knowledge of the sentinel. The sentinel + // have a value or name. + if ( next->value.empty() && next->name.empty() ) + return 0; + return next; +} + + +TiXmlAttribute* TiXmlAttribute::Previous() const +{ + // We are using knowledge of the sentinel. The sentinel + // have a value or name. + if ( prev->value.empty() && prev->name.empty() ) + return 0; + return prev; +} + + +void TiXmlAttribute::Print( FILE* cfile, int /*depth*/ ) const +{ + TIXML_STRING n, v; + + PutString( Name(), &n ); + PutString( Value(), &v ); + + if (value.find ('\"') == TIXML_STRING::npos) + generic_fprintf (cfile, TEXT("%s=\"%s\""), n.c_str(), v.c_str() ); + else + generic_fprintf (cfile, TEXT("%s='%s'"), n.c_str(), v.c_str() ); +} + + +void TiXmlAttribute::StreamOut( TIXML_OSTREAM * stream ) const +{ + if (value.find( '\"' ) != TIXML_STRING::npos) + { + PutString( name, stream ); + (*stream) << TEXT("=") << TEXT("'"); + PutString( value, stream ); + (*stream) << TEXT("'"); + } + else + { + PutString( name, stream ); + (*stream) << TEXT("=") << TEXT("\""); + PutString( value, stream ); + (*stream) << TEXT("\""); + } +} + +int TiXmlAttribute::QueryIntValue( int* ival ) const +{ + if ( generic_sscanf( value.c_str(), TEXT("%d"), ival ) == 1 ) + return TIXML_SUCCESS; + return TIXML_WRONG_TYPE; +} + +int TiXmlAttribute::QueryDoubleValue( double* dval ) const +{ + if ( generic_sscanf( value.c_str(), TEXT("%lf"), dval ) == 1 ) + return TIXML_SUCCESS; + return TIXML_WRONG_TYPE; +} + +void TiXmlAttribute::SetIntValue( int _value ) +{ + TCHAR buf [64]; + wsprintf (buf, TEXT("%d"), _value); + SetValue (buf); +} + +void TiXmlAttribute::SetDoubleValue( double _value ) +{ + TCHAR buf [64]; + wsprintf (buf, TEXT("%lf"), _value); + SetValue (buf); +} + +const int TiXmlAttribute::IntValue() const +{ + return generic_atoi (value.c_str ()); +} + +const double TiXmlAttribute::DoubleValue() const +{ + return generic_atof (value.c_str ()); +} + +void TiXmlComment::Print( FILE* cfile, int depth ) const +{ + for ( int i=0; i"), value.c_str() ); +} + +void TiXmlComment::StreamOut( TIXML_OSTREAM * stream ) const +{ + (*stream) << TEXT(""); +} + +TiXmlNode* TiXmlComment::Clone() const +{ + TiXmlComment* clone = new TiXmlComment(); + + if ( !clone ) + return 0; + + CopyToClone( clone ); + return clone; +} + + +void TiXmlText::Print( FILE* cfile, int /*depth*/ ) const +{ + TIXML_STRING buffer; + PutString( value, &buffer ); + generic_fprintf( cfile, TEXT("%s"), buffer.c_str() ); +} + + +void TiXmlText::StreamOut( TIXML_OSTREAM * stream ) const +{ + PutString( value, stream ); +} + + +TiXmlNode* TiXmlText::Clone() const +{ + TiXmlText* clone = 0; + clone = new TiXmlText( TEXT("") ); + + if ( !clone ) + return 0; + + CopyToClone( clone ); + return clone; +} + + +TiXmlDeclaration::TiXmlDeclaration( const TCHAR * _version, + const TCHAR * _encoding, + const TCHAR * _standalone ) +: TiXmlNode( TiXmlNode::DECLARATION ) +{ + version = _version; + encoding = _encoding; + standalone = _standalone; +} + + +void TiXmlDeclaration::Print( FILE* cfile, int /*depth*/ ) const +{ + generic_fprintf (cfile, TEXT("")); +} + +void TiXmlDeclaration::StreamOut( TIXML_OSTREAM * stream ) const +{ + (*stream) << TEXT(""); +} + +TiXmlNode* TiXmlDeclaration::Clone() const +{ + TiXmlDeclaration* clone = new TiXmlDeclaration(); + + if ( !clone ) + return 0; + + CopyToClone( clone ); + clone->version = version; + clone->encoding = encoding; + clone->standalone = standalone; + return clone; +} + + +void TiXmlUnknown::Print( FILE* cfile, int depth ) const +{ + for ( int i=0; i"); // Don't use entities hear! It is unknown. +} + +TiXmlNode* TiXmlUnknown::Clone() const +{ + TiXmlUnknown* clone = new TiXmlUnknown(); + + if ( !clone ) + return 0; + + CopyToClone( clone ); + return clone; +} + + +TiXmlAttributeSet::TiXmlAttributeSet() +{ + sentinel.next = &sentinel; + sentinel.prev = &sentinel; +} + + +TiXmlAttributeSet::~TiXmlAttributeSet() +{ + assert( sentinel.next == &sentinel ); + assert( sentinel.prev == &sentinel ); +} + + +void TiXmlAttributeSet::Add( TiXmlAttribute* addMe ) +{ + assert( !Find( addMe->Name() ) ); // Shouldn't be multiply adding to the set. + + addMe->next = &sentinel; + addMe->prev = sentinel.prev; + + sentinel.prev->next = addMe; + sentinel.prev = addMe; +} + +void TiXmlAttributeSet::Remove( TiXmlAttribute* removeMe ) +{ + TiXmlAttribute* node; + + for( node = sentinel.next; node != &sentinel; node = node->next ) + { + if ( node == removeMe ) + { + node->prev->next = node->next; + node->next->prev = node->prev; + node->next = 0; + node->prev = 0; + return; + } + } + assert( 0 ); // we tried to remove a non-linked attribute. +} + +TiXmlAttribute* TiXmlAttributeSet::Find( const TCHAR * name ) const +{ + TiXmlAttribute* node; + + for( node = sentinel.next; node != &sentinel; node = node->next ) + { + if ( node->name == name ) + return node; + } + return 0; +} + + +#ifdef TIXML_USE_STL +TIXML_ISTREAM & operator >> (TIXML_ISTREAM & in, TiXmlNode & base) +{ + TIXML_STRING tag; + tag.reserve( 8 * 1000 ); + base.StreamIn( &in, &tag ); + + base.Parse( tag.c_str(), 0 ); + return in; +} +#endif + + +TIXML_OSTREAM & operator<< (TIXML_OSTREAM & out, const TiXmlNode & base) +{ + base.StreamOut (& out); + return out; +} + + +#ifdef TIXML_USE_STL +std::generic_string & operator<< (std::generic_string& out, const TiXmlNode& base ) +{ + + //std::ostringstream os_stream( std::ostringstream::out ); + std::basic_ostringstream os_stream( std::ostringstream::out ); + base.StreamOut( &os_stream ); + + out.append( os_stream.str() ); + return out; +} +#endif + + +TiXmlHandle TiXmlHandle::FirstChild() const +{ + if ( node ) + { + TiXmlNode* child = node->FirstChild(); + if ( child ) + return TiXmlHandle( child ); + } + return TiXmlHandle( 0 ); +} + + +TiXmlHandle TiXmlHandle::FirstChild( const TCHAR * value ) const +{ + if ( node ) + { + TiXmlNode* child = node->FirstChild( value ); + if ( child ) + return TiXmlHandle( child ); + } + return TiXmlHandle( 0 ); +} + + +TiXmlHandle TiXmlHandle::FirstChildElement() const +{ + if ( node ) + { + TiXmlElement* child = node->FirstChildElement(); + if ( child ) + return TiXmlHandle( child ); + } + return TiXmlHandle( 0 ); +} + + +TiXmlHandle TiXmlHandle::FirstChildElement( const TCHAR * value ) const +{ + if ( node ) + { + TiXmlElement* child = node->FirstChildElement( value ); + if ( child ) + return TiXmlHandle( child ); + } + return TiXmlHandle( 0 ); +} + +TiXmlHandle TiXmlHandle::Child( int count ) const +{ + if ( node ) + { + int i; + TiXmlNode* child = node->FirstChild(); + for ( i=0; + child && iNextSibling(), ++i ) + { + // nothing + } + if ( child ) + return TiXmlHandle( child ); + } + return TiXmlHandle( 0 ); +} + + +TiXmlHandle TiXmlHandle::Child( const TCHAR* value, int count ) const +{ + if ( node ) + { + int i; + TiXmlNode* child = node->FirstChild( value ); + for ( i=0; + child && iNextSibling( value ), ++i ) + { + // nothing + } + if ( child ) + return TiXmlHandle( child ); + } + return TiXmlHandle( 0 ); +} + + +TiXmlHandle TiXmlHandle::ChildElement( int count ) const +{ + if ( node ) + { + int i; + TiXmlElement* child = node->FirstChildElement(); + for ( i=0; + child && iNextSiblingElement(), ++i ) + { + // nothing + } + if ( child ) + return TiXmlHandle( child ); + } + return TiXmlHandle( 0 ); +} + + +TiXmlHandle TiXmlHandle::ChildElement( const TCHAR* value, int count ) const +{ + if ( node ) + { + int i; + TiXmlElement* child = node->FirstChildElement( value ); + for ( i=0; + child && iNextSiblingElement( value ), ++i ) + { + // nothing + } + if ( child ) + return TiXmlHandle( child ); + } + return TiXmlHandle( 0 ); +} diff --git a/PowerEditor/src/TinyXml/tinyxml.h b/PowerEditor/src/TinyXml/tinyxml.h new file mode 100644 index 00000000..f6e7d803 --- /dev/null +++ b/PowerEditor/src/TinyXml/tinyxml.h @@ -0,0 +1,1265 @@ +/* +www.sourceforge.net/projects/tinyxml +Original code (2.0 and earlier )copyright (c) 2000-2002 Lee Thomason (www.grinninglizard.com) + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + + +#ifndef TINYXML_INCLUDED +#define TINYXML_INCLUDED + +#ifdef _MSC_VER +#pragma warning( disable : 4530 ) +#pragma warning( disable : 4786 ) +#endif + +#include +#include +#include +#include +#include +#include +#include "Common.h" + +// Help out windows: +#if defined( _DEBUG ) && !defined( DEBUG ) +#define DEBUG +#endif + +#if defined( DEBUG ) && defined( _MSC_VER ) + +#define TIXML_LOG OutputDebugString +#else +#define TIXML_LOG printf +#endif + +#ifdef TIXML_USE_STL + #include + #include + //#include + #define TIXML_STRING std::generic_string + //#define TIXML_ISTREAM std::istream + //#define TIXML_OSTREAM std::ostream + #define TIXML_ISTREAM std::basic_istream + #define TIXML_OSTREAM std::basic_ostream + + +#else + #include "tinystr.h" + #define TIXML_STRING TiXmlString + #define TIXML_OSTREAM TiXmlOutStream +#endif + +class TiXmlDocument; +class TiXmlElement; +class TiXmlComment; +class TiXmlUnknown; +class TiXmlAttribute; +class TiXmlText; +class TiXmlDeclaration; + +class TiXmlParsingData; + +/* Internal structure for tracking location of items + in the XML file. +*/ +struct TiXmlCursor +{ + TiXmlCursor() { Clear(); } + void Clear() { row = col = -1; } + + int row; // 0 based. + int col; // 0 based. +}; + + +// Only used by Attribute::Query functions +enum +{ + TIXML_SUCCESS, + TIXML_NO_ATTRIBUTE, + TIXML_WRONG_TYPE +}; + +/** TiXmlBase is a base class for every class in TinyXml. + It does little except to establish that TinyXml classes + can be printed and provide some utility functions. + + In XML, the document and elements can contain + other elements and other types of nodes. + + @verbatim + A Document can contain: Element (container or leaf) + Comment (leaf) + Unknown (leaf) + Declaration( leaf ) + + An Element can contain: Element (container or leaf) + Text (leaf) + Attributes (not on tree) + Comment (leaf) + Unknown (leaf) + + A Decleration contains: Attributes (not on tree) + @endverbatim +*/ +class TiXmlBase +{ + friend class TiXmlNode; + friend class TiXmlElement; + friend class TiXmlDocument; + +public: + TiXmlBase() {} + virtual ~TiXmlBase() {} + + /** All TinyXml classes can print themselves to a filestream. + This is a formatted print, and will insert tabs and newlines. + + (For an unformatted stream, use the << operator.) + */ + virtual void Print( FILE* cfile, int depth ) const = 0; + + /** The world does not agree on whether white space should be kept or + not. In order to make everyone happy, these global, static functions + are provided to set whether or not TinyXml will condense all white space + into a single space or not. The default is to condense. Note changing this + values is not thread safe. + */ + static void SetCondenseWhiteSpace( bool condense ) { condenseWhiteSpace = condense; } + + /// Return the current white space setting. + static bool IsWhiteSpaceCondensed() { return condenseWhiteSpace; } + + /** Return the position, in the original source file, of this node or attribute. + The row and column are 1-based. (That is the first row and first column is + 1,1). If the returns values are 0 or less, then the parser does not have + a row and column value. + + Generally, the row and column value will be set when the TiXmlDocument::Load(), + TiXmlDocument::LoadFile(), or any TiXmlNode::Parse() is called. It will NOT be set + when the DOM was created from operator>>. + + The values reflect the initial load. Once the DOM is modified programmatically + (by adding or changing nodes and attributes) the new values will NOT update to + reflect changes in the document. + + There is a minor performance cost to computing the row and column. Computation + can be disabled if TiXmlDocument::SetTabSize() is called with 0 as the value. + + @sa TiXmlDocument::SetTabSize() + */ + int Row() const { return location.row + 1; } + int Column() const { return location.col + 1; } ///< See Row() + +protected: + // See STL_STRING_BUG + // Utility class to overcome a bug. + class StringToBuffer + { + public: + StringToBuffer( const TIXML_STRING& str ); + ~StringToBuffer(); + TCHAR* buffer; + }; + + static const TCHAR* SkipWhiteSpace( const TCHAR* ); + inline static bool IsWhiteSpace( int c ) { return ( isspace( c ) || c == '\n' || c == '\r' ); } + + virtual void StreamOut (TIXML_OSTREAM *) const = 0; + + #ifdef TIXML_USE_STL + static bool StreamWhiteSpace( TIXML_ISTREAM * in, TIXML_STRING * tag ); + static bool StreamTo( TIXML_ISTREAM * in, int character, TIXML_STRING * tag ); + #endif + + /* Reads an XML name into the generic_string provided. Returns + a pointer just past the last character of the name, + or 0 if the function has an error. + */ + static const TCHAR* ReadName( const TCHAR* p, TIXML_STRING* name ); + + /* Reads text. Returns a pointer past the given end tag. + Wickedly complex options, but it keeps the (sensitive) code in one place. + */ + static const TCHAR* ReadText( const TCHAR* in, // where to start + TIXML_STRING* text, // the generic_string read + bool ignoreWhiteSpace, // whether to keep the white space + const TCHAR* endTag, // what ends this text + bool ignoreCase ); // whether to ignore case in the end tag + + virtual const TCHAR* Parse( const TCHAR* p, TiXmlParsingData* data ) = 0; + + // If an entity has been found, transform it into a character. + static const TCHAR* GetEntity( const TCHAR* in, TCHAR* value ); + + // Get a character, while interpreting entities. + inline static const TCHAR* GetChar( const TCHAR* p, TCHAR* _value ) + { + assert( p ); + if ( *p == '&' ) + { + return GetEntity( p, _value ); + } + else + { + *_value = *p; + return p+1; + } + } + + // Puts a generic_string to a stream, expanding entities as it goes. + // Note this should not contian the '<', '>', etc, or they will be transformed into entities! + static void PutString( const TIXML_STRING& str, TIXML_OSTREAM* out ); + + static void PutString( const TIXML_STRING& str, TIXML_STRING* out ); + + // Return true if the next characters in the stream are any of the endTag sequences. + static bool StringEqual( const TCHAR* p, + const TCHAR* endTag, + bool ignoreCase ); + + + enum + { + TIXML_NO_ERROR = 0, + TIXML_ERROR, + TIXML_ERROR_OPENING_FILE, + TIXML_ERROR_OUT_OF_MEMORY, + TIXML_ERROR_PARSING_ELEMENT, + TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME, + TIXML_ERROR_READING_ELEMENT_VALUE, + TIXML_ERROR_READING_ATTRIBUTES, + TIXML_ERROR_PARSING_EMPTY, + TIXML_ERROR_READING_END_TAG, + TIXML_ERROR_PARSING_UNKNOWN, + TIXML_ERROR_PARSING_COMMENT, + TIXML_ERROR_PARSING_DECLARATION, + TIXML_ERROR_DOCUMENT_EMPTY, + + TIXML_ERROR_STRING_COUNT + }; + static const TCHAR* errorString[ TIXML_ERROR_STRING_COUNT ]; + + TiXmlCursor location; + +private: + struct Entity + { + const TCHAR* str; + unsigned int strLength; + TCHAR chr; + }; + enum + { + NUM_ENTITY = 5, + MAX_ENTITY_LENGTH = 6 + + }; + static Entity entity[ NUM_ENTITY ]; + static bool condenseWhiteSpace; +}; + + +/** The parent class for everything in the Document Object Model. + (Except for attributes). + Nodes have siblings, a parent, and children. A node can be + in a document, or stand on its own. The type of a TiXmlNode + can be queried, and it can be cast to its more defined type. +*/ +class TiXmlNode : public TiXmlBase +{ + friend class TiXmlDocument; + friend class TiXmlElement; + +public: + #ifdef TIXML_USE_STL + + /** An input stream operator, for every class. Tolerant of newlines and + formatting, but doesn't expect them. + */ + friend std::basic_istream& operator >> (std::basic_istream& in, TiXmlNode& base); + + /** An output stream operator, for every class. Note that this outputs + without any newlines or formatting, as opposed to Print(), which + includes tabs and new lines. + + The operator<< and operator>> are not completely symmetric. Writing + a node to a stream is very well defined. You'll get a nice stream + of output, without any extra whitespace or newlines. + + But reading is not as well defined. (As it always is.) If you create + a TiXmlElement (for example) and read that from an input stream, + the text needs to define an element or junk will result. This is + true of all input streams, but it's worth keeping in mind. + + A TiXmlDocument will read nodes until it reads a root element, and + all the children of that root element. + */ + friend std::basic_ostream& operator<< (std::basic_ostream& out, const TiXmlNode& base); + + /// Appends the XML node or attribute to a std::generic_string. + friend std::generic_string& operator<< (std::generic_string& out, const TiXmlNode& base ); + + #else + // Used internally, not part of the public API. + friend TIXML_OSTREAM& operator<< (TIXML_OSTREAM& out, const TiXmlNode& base); + #endif + + /** The types of XML nodes supported by TinyXml. (All the + unsupported types are picked up by UNKNOWN.) + */ + enum NodeType + { + DOCUMENT, + ELEMENT, + COMMENT, + UNKNOWN, + TEXT, + DECLARATION, + TYPECOUNT + }; + + virtual ~TiXmlNode(); + + /** The meaning of 'value' changes for the specific type of + TiXmlNode. + @verbatim + Document: filename of the xml file + Element: name of the element + Comment: the comment text + Unknown: the tag contents + Text: the text generic_string + @endverbatim + + The subclasses will wrap this function. + */ + const TCHAR * Value() const { return value.c_str (); } + + /** Changes the value of the node. Defined as: + @verbatim + Document: filename of the xml file + Element: name of the element + Comment: the comment text + Unknown: the tag contents + Text: the text generic_string + @endverbatim + */ + void SetValue(const TCHAR * _value) { value = _value;} + + #ifdef TIXML_USE_STL + /// STL std::generic_string form. + void SetValue( const std::generic_string& _value ) + { + StringToBuffer buf( _value ); + SetValue( buf.buffer ? buf.buffer : TEXT("") ); + } + #endif + + /// Delete all the children of this node. Does not affect 'this'. + void Clear(); + + /// One step up the DOM. + TiXmlNode* Parent() const { return parent; } + + TiXmlNode* FirstChild() const { return firstChild; } ///< The first child of this node. Will be null if there are no children. + TiXmlNode* FirstChild( const TCHAR * value ) const; ///< The first child of this node with the matching 'value'. Will be null if none found. + + TiXmlNode* LastChild() const { return lastChild; } /// The last child of this node. Will be null if there are no children. + TiXmlNode* LastChild( const TCHAR * value ) const; /// The last child of this node matching 'value'. Will be null if there are no children. + + #ifdef TIXML_USE_STL + TiXmlNode* FirstChild( const std::generic_string& _value ) const { return FirstChild (_value.c_str ()); } ///< STL std::generic_string form. + TiXmlNode* LastChild( const std::generic_string& _value ) const { return LastChild (_value.c_str ()); } ///< STL std::generic_string form. + #endif + + /** An alternate way to walk the children of a node. + One way to iterate over nodes is: + @verbatim + for( child = parent->FirstChild(); child; child = child->NextSibling() ) + @endverbatim + + IterateChildren does the same thing with the syntax: + @verbatim + child = 0; + while( child = parent->IterateChildren( child ) ) + @endverbatim + + IterateChildren takes the previous child as input and finds + the next one. If the previous child is null, it returns the + first. IterateChildren will return null when done. + */ + TiXmlNode* IterateChildren( TiXmlNode* previous ) const; + + /// This flavor of IterateChildren searches for children with a particular 'value' + TiXmlNode* IterateChildren( const TCHAR * value, TiXmlNode* previous ) const; + + #ifdef TIXML_USE_STL + TiXmlNode* IterateChildren( const std::generic_string& _value, TiXmlNode* previous ) const { return IterateChildren (_value.c_str (), previous); } ///< STL std::generic_string form. + #endif + + /** Add a new node related to this. Adds a child past the LastChild. + Returns a pointer to the new object or NULL if an error occured. + */ + TiXmlNode* InsertEndChild( const TiXmlNode& addThis ); + + + /** Add a new node related to this. Adds a child past the LastChild. + + NOTE: the node to be added is passed by pointer, and will be + henceforth owned (and deleted) by tinyXml. This method is efficient + and avoids an extra copy, but should be used with care as it + uses a different memory model than the other insert functions. + + @sa InsertEndChild + */ + TiXmlNode* LinkEndChild( TiXmlNode* addThis ); + + /** Add a new node related to this. Adds a child before the specified child. + Returns a pointer to the new object or NULL if an error occured. + */ + TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis ); + + /** Add a new node related to this. Adds a child after the specified child. + Returns a pointer to the new object or NULL if an error occured. + */ + TiXmlNode* InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis ); + + /** Replace a child of this node. + Returns a pointer to the new object or NULL if an error occured. + */ + TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis ); + + /// Delete a child of this node. + bool RemoveChild( TiXmlNode* removeThis ); + + /// Navigate to a sibling node. + TiXmlNode* PreviousSibling() const { return prev; } + + /// Navigate to a sibling node. + TiXmlNode* PreviousSibling( const TCHAR * ) const; + + #ifdef TIXML_USE_STL + TiXmlNode* PreviousSibling( const std::generic_string& _value ) const { return PreviousSibling (_value.c_str ()); } ///< STL std::generic_string form. + TiXmlNode* NextSibling( const std::generic_string& _value) const { return NextSibling (_value.c_str ()); } ///< STL std::generic_string form. + #endif + + /// Navigate to a sibling node. + TiXmlNode* NextSibling() const { return next; } + + /// Navigate to a sibling node with the given 'value'. + TiXmlNode* NextSibling( const TCHAR * ) const; + + /** Convenience function to get through elements. + Calls NextSibling and ToElement. Will skip all non-Element + nodes. Returns 0 if there is not another element. + */ + TiXmlElement* NextSiblingElement() const; + + /** Convenience function to get through elements. + Calls NextSibling and ToElement. Will skip all non-Element + nodes. Returns 0 if there is not another element. + */ + TiXmlElement* NextSiblingElement( const TCHAR * ) const; + + #ifdef TIXML_USE_STL + TiXmlElement* NextSiblingElement( const std::generic_string& _value) const { return NextSiblingElement (_value.c_str ()); } ///< STL std::generic_string form. + #endif + + /// Convenience function to get through elements. + TiXmlElement* FirstChildElement() const; + + /// Convenience function to get through elements. + TiXmlElement* FirstChildElement( const TCHAR * value ) const; + + #ifdef TIXML_USE_STL + TiXmlElement* FirstChildElement( const std::generic_string& _value ) const { return FirstChildElement (_value.c_str ()); } ///< STL std::generic_string form. + #endif + + /** Query the type (as an enumerated value, above) of this node. + The possible types are: DOCUMENT, ELEMENT, COMMENT, + UNKNOWN, TEXT, and DECLARATION. + */ + virtual int Type() const { return type; } + + /** Return a pointer to the Document this node lives in. + Returns null if not in a document. + */ + TiXmlDocument* GetDocument() const; + + /// Returns true if this node has no children. + bool NoChildren() const { return !firstChild; } + + TiXmlDocument* ToDocument() const { return ( this && type == DOCUMENT ) ? (TiXmlDocument*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. + TiXmlElement* ToElement() const { return ( this && type == ELEMENT ) ? (TiXmlElement*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. + TiXmlComment* ToComment() const { return ( this && type == COMMENT ) ? (TiXmlComment*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. + TiXmlUnknown* ToUnknown() const { return ( this && type == UNKNOWN ) ? (TiXmlUnknown*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. + TiXmlText* ToText() const { return ( this && type == TEXT ) ? (TiXmlText*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. + TiXmlDeclaration* ToDeclaration() const { return ( this && type == DECLARATION ) ? (TiXmlDeclaration*) this : 0; } ///< Cast to a more defined type. Will return null not of the requested type. + + virtual TiXmlNode* Clone() const = 0; + + void SetUserData( void* user ) { userData = user; } + void* GetUserData() { return userData; } + +protected: + TiXmlNode( NodeType type ); + + #ifdef TIXML_USE_STL + // The real work of the input operator. + virtual void StreamIn( TIXML_ISTREAM* in, TIXML_STRING* tag ) = 0; + #endif + + // Figure out what is at *p, and parse it. Returns null if it is not an xml node. + TiXmlNode* Identify( const TCHAR* start ); + void CopyToClone( TiXmlNode* target ) const { target->SetValue (value.c_str() ); + target->userData = userData; } + + // Internal Value function returning a TIXML_STRING + TIXML_STRING SValue() const { return value ; } + + TiXmlNode* parent; + NodeType type; + + TiXmlNode* firstChild; + TiXmlNode* lastChild; + + TIXML_STRING value; + + TiXmlNode* prev; + TiXmlNode* next; + void* userData; +}; + + +/** An attribute is a name-value pair. Elements have an arbitrary + number of attributes, each with a unique name. + + @note The attributes are not TiXmlNodes, since they are not + part of the tinyXML document object model. There are other + suggested ways to look at this problem. +*/ +class TiXmlAttribute : public TiXmlBase +{ + friend class TiXmlAttributeSet; + +public: + /// Construct an empty attribute. + TiXmlAttribute() + { + document = 0; + prev = next = 0; + } + + #ifdef TIXML_USE_STL + /// std::generic_string constructor. + TiXmlAttribute( const std::generic_string& _name, const std::generic_string& _value ) + { + name = _name; + value = _value; + document = 0; + prev = next = 0; + } + #endif + + /// Construct an attribute with a name and value. + TiXmlAttribute( const TCHAR * _name, const TCHAR * _value ) + { + name = _name; + value = _value; + document = 0; + prev = next = 0; + } + + const TCHAR* Name() const { return name.c_str (); } ///< Return the name of this attribute. + const TCHAR* Value() const { return value.c_str (); } ///< Return the value of this attribute. + const int IntValue() const; ///< Return the value of this attribute, converted to an integer. + const double DoubleValue() const; ///< Return the value of this attribute, converted to a double. + + /** QueryIntValue examines the value generic_string. It is an alternative to the + IntValue() method with richer error checking. + If the value is an integer, it is stored in 'value' and + the call returns TIXML_SUCCESS. If it is not + an integer, it returns TIXML_WRONG_TYPE. + + A specialized but useful call. Note that for success it returns 0, + which is the opposite of almost all other TinyXml calls. + */ + int QueryIntValue( int* value ) const; + /// QueryDoubleValue examines the value generic_string. See QueryIntValue(). + int QueryDoubleValue( double* value ) const; + + void SetName( const TCHAR* _name ) { name = _name; } ///< Set the name of this attribute. + void SetValue( const TCHAR* _value ) { value = _value; } ///< Set the value. + + void SetIntValue( int value ); ///< Set the value from an integer. + void SetDoubleValue( double value ); ///< Set the value from a double. + + #ifdef TIXML_USE_STL + /// STL std::generic_string form. + void SetName( const std::generic_string& _name ) + { + StringToBuffer buf( _name ); + SetName ( buf.buffer ? buf.buffer : TEXT("error") ); + } + /// STL std::generic_string form. + void SetValue( const std::generic_string& _value ) + { + StringToBuffer buf( _value ); + SetValue( buf.buffer ? buf.buffer : TEXT("error") ); + } + #endif + + /// Get the next sibling attribute in the DOM. Returns null at end. + TiXmlAttribute* Next() const; + /// Get the previous sibling attribute in the DOM. Returns null at beginning. + TiXmlAttribute* Previous() const; + + bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; } + bool operator<( const TiXmlAttribute& rhs ) const { return name < rhs.name; } + bool operator>( const TiXmlAttribute& rhs ) const { return name > rhs.name; } + + /* [internal use] + Attribtue parsing starts: first letter of the name + returns: the next TCHAR after the value end quote + */ + virtual const TCHAR* Parse( const TCHAR* p, TiXmlParsingData* data ); + + // [internal use] + virtual void Print( FILE* cfile, int depth ) const; + + virtual void StreamOut( TIXML_OSTREAM * out ) const; + // [internal use] + // Set the document pointer so the attribute can report errors. + void SetDocument( TiXmlDocument* doc ) { document = doc; } + +private: + TiXmlDocument* document; // A pointer back to a document, for error reporting. + TIXML_STRING name; + TIXML_STRING value; + TiXmlAttribute* prev; + TiXmlAttribute* next; +}; + + +/* A class used to manage a group of attributes. + It is only used internally, both by the ELEMENT and the DECLARATION. + + The set can be changed transparent to the Element and Declaration + classes that use it, but NOT transparent to the Attribute + which has to implement a next() and previous() method. Which makes + it a bit problematic and prevents the use of STL. + + This version is implemented with circular lists because: + - I like circular lists + - it demonstrates some independence from the (typical) doubly linked list. +*/ +class TiXmlAttributeSet +{ +public: + TiXmlAttributeSet(); + ~TiXmlAttributeSet(); + + void Add( TiXmlAttribute* attribute ); + void Remove( TiXmlAttribute* attribute ); + + TiXmlAttribute* First() const { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; } + TiXmlAttribute* Last() const { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; } + TiXmlAttribute* Find( const TCHAR * name ) const; + +private: + TiXmlAttribute sentinel; +}; + + +/** The element is a container class. It has a value, the element name, + and can contain other elements, text, comments, and unknowns. + Elements also contain an arbitrary number of attributes. +*/ +class TiXmlElement : public TiXmlNode +{ +public: + /// Construct an element. + TiXmlElement (const TCHAR * in_value); + + #ifdef TIXML_USE_STL + /// std::generic_string constructor. + TiXmlElement( const std::generic_string& _value ) : TiXmlNode( TiXmlNode::ELEMENT ) + { + firstChild = lastChild = 0; + value = _value; + } + #endif + + virtual ~TiXmlElement(); + + /** Given an attribute name, Attribute() returns the value + for the attribute of that name, or null if none exists. + */ + const TCHAR* Attribute( const TCHAR* name ) const; + + /** Given an attribute name, Attribute() returns the value + for the attribute of that name, or null if none exists. + If the attribute exists and can be converted to an integer, + the integer value will be put in the return 'i', if 'i' + is non-null. + */ + const TCHAR* Attribute( const TCHAR* name, int* i ) const; + + /** Given an attribute name, Attribute() returns the value + for the attribute of that name, or null if none exists. + If the attribute exists and can be converted to an double, + the double value will be put in the return 'd', if 'd' + is non-null. + */ + const TCHAR* Attribute( const TCHAR* name, double* d ) const; + + /** QueryIntAttribute examines the attribute - it is an alternative to the + Attribute() method with richer error checking. + If the attribute is an integer, it is stored in 'value' and + the call returns TIXML_SUCCESS. If it is not + an integer, it returns TIXML_WRONG_TYPE. If the attribute + does not exist, then TIXML_NO_ATTRIBUTE is returned. + */ + int QueryIntAttribute( const TCHAR* name, int* value ) const; + /// QueryDoubleAttribute examines the attribute - see QueryIntAttribute(). + int QueryDoubleAttribute( const TCHAR* name, double* value ) const; + + /** Sets an attribute of name to a given value. The attribute + will be created if it does not exist, or changed if it does. + */ + void SetAttribute( const TCHAR* name, const TCHAR * value ); + + #ifdef TIXML_USE_STL + const TCHAR* Attribute( const std::generic_string& name ) const { return Attribute( name.c_str() ); } + const TCHAR* Attribute( const std::generic_string& name, int* i ) const { return Attribute( name.c_str(), i ); } + + /// STL std::generic_string form. + void SetAttribute( const std::generic_string& name, const std::generic_string& _value ) + { + StringToBuffer n( name ); + StringToBuffer v( _value ); + if ( n.buffer && v.buffer ) + SetAttribute (n.buffer, v.buffer ); + } + ///< STL std::generic_string form. + void SetAttribute( const std::generic_string& name, int _value ) + { + StringToBuffer n( name ); + if ( n.buffer ) + SetAttribute (n.buffer, _value); + } + #endif + + /** Sets an attribute of name to a given value. The attribute + will be created if it does not exist, or changed if it does. + */ + void SetAttribute( const TCHAR * name, int value ); + + /** Deletes an attribute with the given name. + */ + void RemoveAttribute( const TCHAR * name ); + #ifdef TIXML_USE_STL + void RemoveAttribute( const std::generic_string& name ) { RemoveAttribute (name.c_str ()); } ///< STL std::generic_string form. + #endif + + TiXmlAttribute* FirstAttribute() const { return attributeSet.First(); } ///< Access the first attribute in this element. + TiXmlAttribute* LastAttribute() const { return attributeSet.Last(); } ///< Access the last attribute in this element. + + // [internal use] Creates a new Element and returs it. + virtual TiXmlNode* Clone() const; + // [internal use] + + virtual void Print( FILE* cfile, int depth ) const; + +protected: + + // Used to be public [internal use] + #ifdef TIXML_USE_STL + virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag ); + #endif + virtual void StreamOut( TIXML_OSTREAM * out ) const; + + /* [internal use] + Attribtue parsing starts: next TCHAR past '<' + returns: next TCHAR past '>' + */ + virtual const TCHAR* Parse( const TCHAR* p, TiXmlParsingData* data ); + + /* [internal use] + Reads the "value" of the element -- another element, or text. + This should terminate with the current end tag. + */ + const TCHAR* ReadValue( const TCHAR* in, TiXmlParsingData* prevData ); + +private: + TiXmlAttributeSet attributeSet; +}; + + +/** An XML comment. +*/ +class TiXmlComment : public TiXmlNode +{ +public: + /// Constructs an empty comment. + TiXmlComment() : TiXmlNode( TiXmlNode::COMMENT ) {} + virtual ~TiXmlComment() {} + + // [internal use] Creates a new Element and returs it. + virtual TiXmlNode* Clone() const; + // [internal use] + virtual void Print( FILE* cfile, int depth ) const; +protected: + // used to be public + #ifdef TIXML_USE_STL + virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag ); + #endif + virtual void StreamOut( TIXML_OSTREAM * out ) const; + /* [internal use] + Attribtue parsing starts: at the ! of the !-- + returns: next TCHAR past '>' + */ + virtual const TCHAR* Parse( const TCHAR* p, TiXmlParsingData* data ); +}; + + +/** XML text. Contained in an element. +*/ +class TiXmlText : public TiXmlNode +{ + friend class TiXmlElement; +public: + /// Constructor. + TiXmlText (const TCHAR * initValue) : TiXmlNode (TiXmlNode::TEXT) + { + SetValue( initValue ); + } + virtual ~TiXmlText() {} + + #ifdef TIXML_USE_STL + /// Constructor. + TiXmlText( const std::generic_string& initValue ) : TiXmlNode (TiXmlNode::TEXT) + { + SetValue( initValue ); + } + #endif + + // [internal use] + virtual void Print( FILE* cfile, int depth ) const; + +protected : + // [internal use] Creates a new Element and returns it. + virtual TiXmlNode* Clone() const; + virtual void StreamOut ( TIXML_OSTREAM * out ) const; + // [internal use] + bool Blank() const; // returns true if all white space and new lines + /* [internal use] + Attribtue parsing starts: First TCHAR of the text + returns: next TCHAR past '>' + */ + virtual const TCHAR* Parse( const TCHAR* p, TiXmlParsingData* data ); + // [internal use] + #ifdef TIXML_USE_STL + virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag ); + #endif +}; + + +/** In correct XML the declaration is the first entry in the file. + @verbatim + + @endverbatim + + TinyXml will happily read or write files without a declaration, + however. There are 3 possible attributes to the declaration: + version, encoding, and standalone. + + Note: In this version of the code, the attributes are + handled as special cases, not generic attributes, simply + because there can only be at most 3 and they are always the same. +*/ +class TiXmlDeclaration : public TiXmlNode +{ +public: + /// Construct an empty declaration. + TiXmlDeclaration() : TiXmlNode( TiXmlNode::DECLARATION ) {} + +#ifdef TIXML_USE_STL + /// Constructor. + TiXmlDeclaration( const std::generic_string& _version, + const std::generic_string& _encoding, + const std::generic_string& _standalone ) + : TiXmlNode( TiXmlNode::DECLARATION ) + { + version = _version; + encoding = _encoding; + standalone = _standalone; + } +#endif + + /// Construct. + TiXmlDeclaration( const TCHAR* _version, + const TCHAR* _encoding, + const TCHAR* _standalone ); + + virtual ~TiXmlDeclaration() {} + + /// Version. Will return empty if none was found. + const TCHAR * Version() const { return version.c_str (); } + /// Encoding. Will return empty if none was found. + const TCHAR * Encoding() const { return encoding.c_str (); } + /// Is this a standalone document? + const TCHAR * Standalone() const { return standalone.c_str (); } + + // [internal use] Creates a new Element and returs it. + virtual TiXmlNode* Clone() const; + // [internal use] + virtual void Print( FILE* cfile, int depth ) const; + +protected: + // used to be public + #ifdef TIXML_USE_STL + virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag ); + #endif + virtual void StreamOut ( TIXML_OSTREAM * out) const; + // [internal use] + // Attribtue parsing starts: next TCHAR past '<' + // returns: next TCHAR past '>' + + virtual const TCHAR* Parse( const TCHAR* p, TiXmlParsingData* data ); + +private: + TIXML_STRING version; + TIXML_STRING encoding; + TIXML_STRING standalone; +}; + + +/** Any tag that tinyXml doesn't recognize is saved as an + unknown. It is a tag of text, but should not be modified. + It will be written back to the XML, unchanged, when the file + is saved. +*/ +class TiXmlUnknown : public TiXmlNode +{ +public: + TiXmlUnknown() : TiXmlNode( TiXmlNode::UNKNOWN ) {} + virtual ~TiXmlUnknown() {} + + // [internal use] + virtual TiXmlNode* Clone() const; + // [internal use] + virtual void Print( FILE* cfile, int depth ) const; +protected: + #ifdef TIXML_USE_STL + virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag ); + #endif + virtual void StreamOut ( TIXML_OSTREAM * out ) const; + /* [internal use] + Attribute parsing starts: First TCHAR of the text + returns: next TCHAR past '>' + */ + virtual const TCHAR* Parse( const TCHAR* p, TiXmlParsingData* data ); +}; + + +/** Always the top level node. A document binds together all the + XML pieces. It can be saved, loaded, and printed to the screen. + The 'value' of a document node is the xml file name. +*/ +class TiXmlDocument : public TiXmlNode +{ +public: + /// Create an empty document, that has no name. + TiXmlDocument(); + /// Create a document with a name. The name of the document is also the filename of the xml. + TiXmlDocument( const TCHAR * documentName ); + + #ifdef TIXML_USE_STL + /// Constructor. + TiXmlDocument( const std::generic_string& documentName ) : + TiXmlNode( TiXmlNode::DOCUMENT ) + { + value = documentName; + error = false; + } + #endif + + virtual ~TiXmlDocument() {} + + /** Load a file using the current document value. + Returns true if successful. Will delete any existing + document data before loading. + */ + bool LoadFile(); + /// Save a file using the current document value. Returns true if successful. + bool SaveFile() const; + /// Load a file using the given filename. Returns true if successful. + bool LoadFile( const TCHAR * filename ); + /// Save a file using the given filename. Returns true if successful. + bool SaveFile( const TCHAR * filename ) const; + + #ifdef TIXML_USE_STL + bool LoadFile( const std::generic_string& filename ) ///< STL std::generic_string version. + { + StringToBuffer f( filename ); + return ( f.buffer && LoadFile( f.buffer )); + } + bool SaveFile( const std::generic_string& filename ) const ///< STL std::generic_string version. + { + StringToBuffer f( filename ); + return ( f.buffer && SaveFile( f.buffer )); + } + #endif + + /** Parse the given null terminated block of xml data. + */ + virtual const TCHAR* Parse( const TCHAR* p, TiXmlParsingData* data = 0 ); + + /** Get the root element -- the only top level element -- of the document. + In well formed XML, there should only be one. TinyXml is tolerant of + multiple elements at the document level. + */ + TiXmlElement* RootElement() const { return FirstChildElement(); } + + /** If an error occurs, Error will be set to true. Also, + - The ErrorId() will contain the integer identifier of the error (not generally useful) + - The ErrorDesc() method will return the name of the error. (very useful) + - The ErrorRow() and ErrorCol() will return the location of the error (if known) + */ + bool Error() const { return error; } + + /// Contains a textual (english) description of the error if one occurs. + const TCHAR * ErrorDesc() const { return errorDesc.c_str (); } + + /** Generally, you probably want the error generic_string ( ErrorDesc() ). But if you + prefer the ErrorId, this function will fetch it. + */ + const int ErrorId() const { return errorId; } + + /** Returns the location (if known) of the error. The first column is column 1, + and the first row is row 1. A value of 0 means the row and column wasn't applicable + (memory errors, for example, have no row/column) or the parser lost the error. (An + error in the error reporting, in that case.) + + @sa SetTabSize, Row, Column + */ + int ErrorRow() { return errorLocation.row+1; } + int ErrorCol() { return errorLocation.col+1; } ///< The column where the error occured. See ErrorRow() + + /** By calling this method, with a tab size + greater than 0, the row and column of each node and attribute is stored + when the file is loaded. Very useful for tracking the DOM back in to + the source file. + + The tab size is required for calculating the location of nodes. If not + set, the default of 4 is used. The tabsize is set per document. Setting + the tabsize to 0 disables row/column tracking. + + Note that row and column tracking is not supported when using operator>>. + + The tab size needs to be enabled before the parse or load. Correct usage: + @verbatim + TiXmlDocument doc; + doc.SetTabSize( 8 ); + doc.Load( "myfile.xml" ); + @endverbatim + + @sa Row, Column + */ + void SetTabSize( int _tabsize ) { tabsize = _tabsize; } + + int TabSize() const { return tabsize; } + + /** If you have handled the error, it can be reset with this call. The error + state is automatically cleared if you Parse a new XML block. + */ + void ClearError() { error = false; + errorId = 0; + errorDesc = TEXT(""); + errorLocation.row = errorLocation.col = 0; + //errorLocation.last = 0; + } + + /** Dump the document to standard out. */ + void Print() const { Print( stdout, 0 ); } + + // [internal use] + virtual void Print( FILE* cfile, int depth = 0 ) const; + // [internal use] + void SetError( int err, const TCHAR* errorLocation, TiXmlParsingData* prevData ); + +protected : + virtual void StreamOut ( TIXML_OSTREAM * out) const; + // [internal use] + virtual TiXmlNode* Clone() const; + #ifdef TIXML_USE_STL + virtual void StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag ); + #endif + +private: + bool error; + int errorId; + TIXML_STRING errorDesc; + int tabsize; + TiXmlCursor errorLocation; +}; + + +/** + A TiXmlHandle is a class that wraps a node pointer with null checks; this is + an incredibly useful thing. Note that TiXmlHandle is not part of the TinyXml + DOM structure. It is a separate utility class. + + Take an example: + @verbatim + + + + + + + @endverbatim + + Assuming you want the value of "attributeB" in the 2nd "Child" element, it's very + easy to write a *lot* of code that looks like: + + @verbatim + TiXmlElement* root = document.FirstChildElement( "Document" ); + if ( root ) + { + TiXmlElement* element = root->FirstChildElement( "Element" ); + if ( element ) + { + TiXmlElement* child = element->FirstChildElement( "Child" ); + if ( child ) + { + TiXmlElement* child2 = child->NextSiblingElement( "Child" ); + if ( child2 ) + { + // Finally do something useful. + @endverbatim + + And that doesn't even cover "else" cases. TiXmlHandle addresses the verbosity + of such code. A TiXmlHandle checks for null pointers so it is perfectly safe + and correct to use: + + @verbatim + TiXmlHandle docHandle( &document ); + TiXmlElement* child2 = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", 1 ).Element(); + if ( child2 ) + { + // do something useful + @endverbatim + + Which is MUCH more concise and useful. + + It is also safe to copy handles - internally they are nothing more than node pointers. + @verbatim + TiXmlHandle handleCopy = handle; + @endverbatim + + What they should not be used for is iteration: + + @verbatim + int i=0; + while ( true ) + { + TiXmlElement* child = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", i ).Element(); + if ( !child ) + break; + // do something + ++i; + } + @endverbatim + + It seems reasonable, but it is in fact two embedded while loops. The Child method is + a linear walk to find the element, so this code would iterate much more than it needs + to. Instead, prefer: + + @verbatim + TiXmlElement* child = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).FirstChild( "Child" ).Element(); + + for( child; child; child=child->NextSiblingElement() ) + { + // do something + } + @endverbatim +*/ +class TiXmlHandle +{ +public: + /// Create a handle from any node (at any depth of the tree.) This can be a null pointer. + TiXmlHandle( TiXmlNode* node ) { this->node = node; } + /// Copy constructor + TiXmlHandle( const TiXmlHandle& ref ) { this->node = ref.node; } + + /// Return a handle to the first child node. + TiXmlHandle FirstChild() const; + /// Return a handle to the first child node with the given name. + TiXmlHandle FirstChild( const TCHAR * value ) const; + /// Return a handle to the first child element. + TiXmlHandle FirstChildElement() const; + /// Return a handle to the first child element with the given name. + TiXmlHandle FirstChildElement( const TCHAR * value ) const; + + /** Return a handle to the "index" child with the given name. + The first child is 0, the second 1, etc. + */ + TiXmlHandle Child( const TCHAR* value, int index ) const; + /** Return a handle to the "index" child. + The first child is 0, the second 1, etc. + */ + TiXmlHandle Child( int index ) const; + /** Return a handle to the "index" child element with the given name. + The first child element is 0, the second 1, etc. Note that only TiXmlElements + are indexed: other types are not counted. + */ + TiXmlHandle ChildElement( const TCHAR* value, int index ) const; + /** Return a handle to the "index" child element. + The first child element is 0, the second 1, etc. Note that only TiXmlElements + are indexed: other types are not counted. + */ + TiXmlHandle ChildElement( int index ) const; + + #ifdef TIXML_USE_STL + TiXmlHandle FirstChild( const std::generic_string& _value ) const { return FirstChild( _value.c_str() ); } + TiXmlHandle FirstChildElement( const std::generic_string& _value ) const { return FirstChildElement( _value.c_str() ); } + + TiXmlHandle Child( const std::generic_string& _value, int index ) const { return Child( _value.c_str(), index ); } + TiXmlHandle ChildElement( const std::generic_string& _value, int index ) const { return ChildElement( _value.c_str(), index ); } + #endif + + /// Return the handle as a TiXmlNode. This may return null. + TiXmlNode* Node() const { return node; } + /// Return the handle as a TiXmlElement. This may return null. + TiXmlElement* Element() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); } + /// Return the handle as a TiXmlText. This may return null. + TiXmlText* Text() const { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); } + +private: + TiXmlNode* node; +}; + + +#endif + diff --git a/PowerEditor/src/TinyXml/tinyxmlerror.cpp b/PowerEditor/src/TinyXml/tinyxmlerror.cpp new file mode 100644 index 00000000..0f9c9e20 --- /dev/null +++ b/PowerEditor/src/TinyXml/tinyxmlerror.cpp @@ -0,0 +1,51 @@ +/* +www.sourceforge.net/projects/tinyxml +Original code (2.0 and earlier )copyright (c) 2000-2002 Lee Thomason (www.grinninglizard.com) + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + +#include "tinyxml.h" +//#include "tchar.h" + +// The goal of the seperate error file is to make the first +// step towards localization. tinyxml (currently) only supports +// latin-1, but at least the error messages could now be translated. +// +// It also cleans up the code a bit. +// + +const TCHAR* TiXmlBase::errorString[ TIXML_ERROR_STRING_COUNT ] = +{ + TEXT("No error"), + TEXT("Error"), + TEXT("Failed to open file"), + TEXT("Memory allocation failed."), + TEXT("Error parsing Element."), + TEXT("Failed to read Element name"), + TEXT("Error reading Element value."), + TEXT("Error reading Attributes."), + TEXT("Error: empty tag."), + TEXT("Error reading end tag."), + TEXT("Error parsing Unknown."), + TEXT("Error parsing Comment."), + TEXT("Error parsing Declaration."), + TEXT("Error document empty.") +}; diff --git a/PowerEditor/src/TinyXml/tinyxmlparser.cpp b/PowerEditor/src/TinyXml/tinyxmlparser.cpp new file mode 100644 index 00000000..d177d057 --- /dev/null +++ b/PowerEditor/src/TinyXml/tinyxmlparser.cpp @@ -0,0 +1,1141 @@ +/* +www.sourceforge.net/projects/tinyxml +Original code (2.0 and earlier )copyright (c) 2000-2002 Lee Thomason (www.grinninglizard.com) + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + +#include "tinyxml.h" +#include + +//#define DEBUG_PARSER + +// Note tha "PutString" hardcodes the same list. This +// is less flexible than it appears. Changing the entries +// or order will break putstring. +TiXmlBase::Entity TiXmlBase::entity[ NUM_ENTITY ] = +{ + { TEXT("&"), 5, '&' }, + { TEXT("<"), 4, '<' }, + { TEXT(">"), 4, '>' }, + { TEXT("""), 6, '\"' }, + { TEXT("'"), 6, '\'' } +}; + + +class TiXmlParsingData +{ + friend class TiXmlDocument; + public: + //TiXmlParsingData( const TCHAR* now, const TiXmlParsingData* prevData ); + void Stamp( const TCHAR* now ); + + const TiXmlCursor& Cursor() { return cursor; } + //void Update( const TCHAR* now ); + + private: + // Only used by the document! + TiXmlParsingData( const TCHAR* start, int _tabsize, int row, int col ) + { + assert( start ); + stamp = start; + tabsize = _tabsize; + cursor.row = row; + cursor.col = col; + } + + TiXmlCursor cursor; + const TCHAR* stamp; + int tabsize; +}; + + +void TiXmlParsingData::Stamp( const TCHAR* now ) +{ + assert( now ); + + // Do nothing if the tabsize is 0. + if ( tabsize < 1 ) + { + return; + } + + // Get the current row, column. + int row = cursor.row; + int col = cursor.col; + const TCHAR* p = stamp; + assert( p ); + + while ( p < now ) + { + // Code contributed by Fletcher Dunn: (modified by lee) + switch (*p) { + case 0: + // We *should* never get here, but in case we do, don't + // advance past the terminating null character, ever + return; + + case '\r': + // bump down to the next line + ++row; + col = 0; + // Eat the character + ++p; + + // Check for \r\n sequence, and treat this as a single character + if (*p == '\n') { + ++p; + } + break; + + case '\n': + // bump down to the next line + ++row; + col = 0; + + // Eat the character + ++p; + + // Check for \n\r sequence, and treat this as a single + // character. (Yes, this bizarre thing does occur still + // on some arcane platforms...) + if (*p == '\r') { + ++p; + } + break; + + case '\t': + // Eat the character + ++p; + + // Skip to next tab stop + col = (col / tabsize + 1) * tabsize; + break; + + default: + // Eat the character + ++p; + + // Normal TCHAR - just advance one column + ++col; + break; + } + } + cursor.row = row; + cursor.col = col; + assert( cursor.row >= -1 ); + assert( cursor.col >= -1 ); + stamp = p; + assert( stamp ); +} + + +const TCHAR* TiXmlBase::SkipWhiteSpace( const TCHAR* p ) +{ + if ( !p || !*p ) + { + return 0; + } + while ( p && *p ) + { + if ( isspace( *p ) || *p == '\n' || *p =='\r' ) // Still using old rules for white space. + ++p; + else + break; + } + + return p; +} + +#ifdef TIXML_USE_STL +/*static*/ bool TiXmlBase::StreamWhiteSpace( TIXML_ISTREAM * in, TIXML_STRING * tag ) +{ + for( ;; ) + { + if ( !in->good() ) return false; + + int c = in->peek(); + if ( !IsWhiteSpace( c ) ) + return true; + *tag += in->get(); + } +} + +/*static*/ bool TiXmlBase::StreamTo( TIXML_ISTREAM * in, int character, TIXML_STRING * tag ) +{ + while ( in->good() ) + { + int c = in->peek(); + if ( c == character ) + return true; + + in->get(); + *tag += c; + } + return false; +} +#endif + +const TCHAR* TiXmlBase::ReadName( const TCHAR* p, TIXML_STRING * name ) +{ + *name = TEXT(""); + assert( p ); + + // Names start with letters or underscores. + // After that, they can be letters, underscores, numbers, + // hyphens, or colons. (Colons are valid ony for namespaces, + // but tinyxml can't tell namespaces from names.) + if ( p && *p + && ( isalpha( (UCHAR) *p ) || *p == '_' ) ) + { + while( p && *p + && ( isalnum( (UCHAR ) *p ) + || *p == '_' + || *p == '-' + || *p == '.' + || *p == ':' ) ) + { + (*name) += *p; + ++p; + } + return p; + } + return 0; +} + +const TCHAR* TiXmlBase::GetEntity( const TCHAR* p, TCHAR* value ) +{ + // Presume an entity, and pull it out. + int i; + + // Handle the &#x entities. + if (generic_strncmp( TEXT("&#x"), p, 3 ) == 0) + { + const TCHAR* end = generic_strchr(p+3, TEXT(';')); + if (end && end - p <= 3 + 4) + { + int val; + if (generic_sscanf(p+3, TEXT("%x"), &val) == 1) + { + *value = val; + return end + 1; + } + } + } + + // Now try to match it. + for( i=0; i" so the + // sub-tag can orient itself. + + if ( !StreamTo( in, '<', tag ) ) + { + SetError( TIXML_ERROR_PARSING_EMPTY, 0, 0 ); + return; + } + + while ( in->good() ) + { + int tagIndex = tag->length(); + while ( in->good() && in->peek() != '>' ) + { + int c = in->get(); + (*tag) += (TCHAR) c; + } + + if ( in->good() ) + { + // We now have something we presume to be a node of + // some sort. Identify it, and call the node to + // continue streaming. + TiXmlNode* node = Identify( tag->c_str() + tagIndex ); + + if ( node ) + { + node->StreamIn( in, tag ); + bool isElement = node->ToElement() != 0; + delete node; + node = 0; + + // If this is the root element, we're done. Parsing will be + // done by the >> operator. + if ( isElement ) + { + return; + } + } + else + { + SetError( TIXML_ERROR, 0, 0 ); + return; + } + } + } + // We should have returned sooner. + SetError( TIXML_ERROR, 0, 0 ); +} + +#endif + +const TCHAR* TiXmlDocument::Parse( const TCHAR* p, TiXmlParsingData* prevData ) +{ + ClearError(); + + // Parse away, at the document level. Since a document + // contains nothing but other tags, most of what happens + // here is skipping white space. + if ( !p || !*p ) + { + SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0 ); + return 0; + } + + // Note that, for a document, this needs to come + // before the while space skip, so that parsing + // starts from the pointer we are given. + location.Clear(); + if ( prevData ) + { + location.row = prevData->cursor.row; + location.col = prevData->cursor.col; + } + else + { + location.row = 0; + location.col = 0; + } + TiXmlParsingData data( p, TabSize(), location.row, location.col ); + location = data.Cursor(); + + p = SkipWhiteSpace( p ); + if ( !p ) + { + SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0 ); + return 0; + } + + while ( p && *p ) + { + TiXmlNode* node = Identify( p ); + if ( node ) + { + p = node->Parse( p, &data ); + LinkEndChild( node ); + } + else + { + break; + } + p = SkipWhiteSpace( p ); + } + + // All is well. + return p; +} + +void TiXmlDocument::SetError( int err, const TCHAR* pError, TiXmlParsingData* data ) +{ + // The first error in a chain is more accurate - don't set again! + if ( error ) + return; + + assert( err > 0 && err < TIXML_ERROR_STRING_COUNT ); + error = true; + errorId = err; + errorDesc = errorString[ errorId ]; + + errorLocation.Clear(); + if ( pError && data ) + { + //TiXmlParsingData data( pError, prevData ); + data->Stamp( pError ); + errorLocation = data->Cursor(); + } +} + + +TiXmlNode* TiXmlNode::Identify( const TCHAR* p ) +{ + TiXmlNode* returnNode = 0; + + p = SkipWhiteSpace( p ); + if( !p || !*p || *p != '<' ) + { + return 0; + } + + TiXmlDocument* doc = GetDocument(); + p = SkipWhiteSpace( p ); + + if ( !p || !*p ) + { + return 0; + } + + // What is this thing? + // - Elements start with a letter or underscore, but xml is reserved. + // - Comments: "); + + if ( !StringEqual( p, startTag, false ) ) + { + document->SetError( TIXML_ERROR_PARSING_COMMENT, p, data ); + return 0; + } + p += lstrlen( startTag ); + p = ReadText( p, &value, false, endTag, false ); + return p; +} + + +const TCHAR* TiXmlAttribute::Parse( const TCHAR* p, TiXmlParsingData* data ) +{ + p = SkipWhiteSpace( p ); + if ( !p || !*p ) return 0; + + int tabsize = 4; + if ( document ) + tabsize = document->TabSize(); + +// TiXmlParsingData data( p, prevData ); + if ( data ) + { + data->Stamp( p ); + location = data->Cursor(); + } + // Read the name, the '=' and the value. + const TCHAR* pErr = p; + p = ReadName( p, &name ); + if ( !p || !*p ) + { + if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, pErr, data ); + return 0; + } + p = SkipWhiteSpace( p ); + if ( !p || !*p || *p != '=' ) + { + if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data ); + return 0; + } + + ++p; // skip '=' + p = SkipWhiteSpace( p ); + if ( !p || !*p ) + { + if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data ); + return 0; + } + + const TCHAR* end; + + if ( *p == '\'' ) + { + ++p; + end = TEXT("\'"); + p = ReadText( p, &value, false, end, false ); + } + else if ( *p == '"' ) + { + ++p; + end = TEXT("\""); + p = ReadText( p, &value, false, end, false ); + } + else + { + // All attribute values should be in single or double quotes. + // But this is such a common error that the parser will try + // its best, even without them. + value = TEXT(""); + while ( p && *p // existence + && !isspace( *p ) && *p != '\n' && *p != '\r' // whitespace + && *p != '/' && *p != '>' ) // tag end + { + value += *p; + ++p; + } + } + return p; +} + +#ifdef TIXML_USE_STL +void TiXmlText::StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag ) +{ + while ( in->good() ) + { + int c = in->peek(); + if ( c == '<' ) + return; + + (*tag) += c; + in->get(); + } +} +#endif + +const TCHAR* TiXmlText::Parse( const TCHAR* p, TiXmlParsingData* data ) +{ + value = TEXT(""); +// TiXmlParsingData data( p, prevData ); + if ( data ) + { + data->Stamp( p ); + location = data->Cursor(); + } + bool ignoreWhite = true; + + const TCHAR* end = TEXT("<"); + p = ReadText( p, &value, ignoreWhite, end, false ); + if ( p ) + return p-1; // don't truncate the '<' + return 0; +} + +#ifdef TIXML_USE_STL +void TiXmlDeclaration::StreamIn( TIXML_ISTREAM * in, TIXML_STRING * tag ) +{ + while ( in->good() ) + { + int c = in->get(); + (*tag) += c; + + if ( c == '>' ) + { + // All is well. + return; + } + } +} +#endif + +const TCHAR* TiXmlDeclaration::Parse( const TCHAR* p, TiXmlParsingData* data ) +{ + p = SkipWhiteSpace( p ); + // Find the beginning, find the end, and look for + // the stuff in-between. + TiXmlDocument* document = GetDocument(); + if ( !p || !*p || !StringEqual( p, TEXT("SetError( TIXML_ERROR_PARSING_DECLARATION, 0, 0 ); + return 0; + } +// TiXmlParsingData data( p, prevData ); + if ( data ) + { + data->Stamp( p ); + location = data->Cursor(); + } + p += 5; + + version = TEXT(""); + encoding = TEXT(""); + standalone = TEXT(""); + + while ( p && *p ) + { + if ( *p == '>' ) + { + ++p; + return p; + } + + p = SkipWhiteSpace( p ); + if ( StringEqual( p, TEXT("version"), true ) ) + { + TiXmlAttribute attrib; + p = attrib.Parse( p, data ); + version = attrib.Value(); + } + else if ( StringEqual( p, TEXT("encoding"), true ) ) + { + TiXmlAttribute attrib; + p = attrib.Parse( p, data ); + encoding = attrib.Value(); + } + else if ( StringEqual( p, TEXT("standalone"), true ) ) + { + TiXmlAttribute attrib; + p = attrib.Parse( p, data ); + standalone = attrib.Value(); + } + else + { + // Read over whatever it is. + while( p && *p && *p != '>' && !isspace( *p ) ) + ++p; + } + } + return 0; +} + +bool TiXmlText::Blank() const +{ + for ( unsigned i=0; i +// The License.txt file describes the conditions under which this software may be distributed. + +#include +#include +#include "UniConversion.h" + +unsigned int UTF8Length(const wchar_t *uptr, unsigned int tlen) { + unsigned int len = 0; + for (unsigned int i = 0; i < tlen && uptr[i]; i++) { + unsigned int uch = uptr[i]; + if (uch < 0x80) + len++; + else if (uch < 0x800) + len += 2; + else + len +=3; + } + return len; +} + +void UTF8FromUCS2(const wchar_t *uptr, unsigned int tlen, char *putf, unsigned int len) { + int k = 0; + for (unsigned int i = 0; i < tlen && uptr[i]; i++) { + unsigned int uch = uptr[i]; + if (uch < 0x80) { + putf[k++] = static_cast(uch); + } else if (uch < 0x800) { + putf[k++] = static_cast(0xC0 | (uch >> 6)); + putf[k++] = static_cast(0x80 | (uch & 0x3f)); + } else { + putf[k++] = static_cast(0xE0 | (uch >> 12)); + putf[k++] = static_cast(0x80 | ((uch >> 6) & 0x3f)); + putf[k++] = static_cast(0x80 | (uch & 0x3f)); + } + } + putf[len] = '\0'; +} + +unsigned int UCS2Length(const char *s, unsigned int len) { + unsigned int ulen = 0; + for (unsigned int i=0;i(s[i]); + if ((ch < 0x80) || (ch > (0x80 + 0x40))) + ulen++; + } + return ulen; +} + +unsigned int UCS2FromUTF8(const char *s, unsigned int len, wchar_t *tbuf, unsigned int tlen) +{ + unsigned int ui=0; + const UCHAR *us = reinterpret_cast(s); + unsigned int i=0; + while ((i((ch & 0x1F) << 6); + ch = us[i++]; + tbuf[ui] = static_cast(tbuf[ui] + (ch & 0x7F)); + } else { + tbuf[ui] = static_cast((ch & 0xF) << 12); + ch = us[i++]; + tbuf[ui] = static_cast(tbuf[ui] + ((ch & 0x7F) << 6)); + ch = us[i++]; + tbuf[ui] = static_cast(tbuf[ui] + (ch & 0x7F)); + } + ui++; + } + return ui; +} + + +unsigned int ascii_to_utf8(const char * pszASCII, unsigned int lenASCII, char * pszUTF8) +{ + // length of pszUTF8 must be enough; + // its maximum is (lenASCII*3 + 1) + + if (!lenASCII || !pszASCII) + { + pszUTF8[0] = 0; + return 0; + } + + unsigned int lenUCS2; + unsigned int lenUTF8; + wchar_t *pszUCS2 = new wchar_t[lenASCII * 3 + 1]; + if (!pszUCS2) + { + pszUTF8[0] = 0; + return 0; + } + + lenUCS2 = ::MultiByteToWideChar(CP_ACP, 0, pszASCII, lenASCII, pszUCS2, lenASCII + 1); + lenUTF8 = UTF8Length(pszUCS2, lenUCS2); + // length of pszUTF8 must be >= (lenUTF8 + 1) + UTF8FromUCS2(pszUCS2, lenUCS2, pszUTF8, lenUTF8); + delete [] pszUCS2; + return lenUTF8; +} + +int utf8_to_ascii(const char * pszUTF8, unsigned int lenUTF8, char * pszASCII) +{ + // length of pszASCII must be enough; + // its maximum is (lenUTF8 + 1) + + if (!lenUTF8 || !pszUTF8) + { + pszASCII[0] = 0; + return 0; + } + + unsigned int lenUCS2; + wchar_t* pszUCS2; + + pszUCS2 = new wchar_t[lenUTF8 + 1]; + if (!pszUCS2) + { + pszASCII[0] = 0; + return 0; + } + + lenUCS2 = UCS2FromUTF8(pszUTF8, lenUTF8, pszUCS2, lenUTF8); + pszUCS2[lenUCS2] = 0; + // length of pszASCII must be >= (lenUCS2 + 1) + int nbByte = ::WideCharToMultiByte(CP_ACP, 0, pszUCS2, lenUCS2, pszASCII, lenUCS2 + 1, NULL, NULL); + delete [] pszUCS2; + return nbByte; +} + diff --git a/PowerEditor/src/UniConversion.h b/PowerEditor/src/UniConversion.h new file mode 100644 index 00000000..c959087c --- /dev/null +++ b/PowerEditor/src/UniConversion.h @@ -0,0 +1,13 @@ +// Scintilla source code edit control +/** @file UniConversion.h + ** Functions to handle UFT-8 and UCS-2 strings. + **/ +// Copyright 1998-2001 by Neil Hodgson +// The License.txt file describes the conditions under which this software may be distributed. + +unsigned int UTF8Length(const wchar_t * uptr, unsigned int tlen); +void UTF8FromUCS2(const wchar_t * uptr, unsigned int tlen, char * putf, unsigned int len); +unsigned int UCS2Length(const char * s, unsigned int len); +unsigned int UCS2FromUTF8(const char * s, unsigned int len, wchar_t * tbuf, unsigned int tlen); +unsigned int ascii_to_utf8(const char * pszASCII, unsigned int lenASCII, char * pszUTF8); +int utf8_to_ascii(const char * pszUTF8, unsigned int lenUTF8, char * pszASCII); diff --git a/PowerEditor/src/Utf8_16.cpp b/PowerEditor/src/Utf8_16.cpp new file mode 100644 index 00000000..ad2357a3 --- /dev/null +++ b/PowerEditor/src/Utf8_16.cpp @@ -0,0 +1,527 @@ +// Utf8_16.cxx +// Copyright (C) 2002 Scott Kirkwood +// +// Permission to use, copy, modify, distribute and sell this code +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies or +// any derived copies. Scott Kirkwood makes no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +//////////////////////////////////////////////////////////////////////////////// +// +// Modificated 2006 Jens Lorenz +// +// - Clean up the sources +// - Removing UCS-Bug in Utf8_Iter +// - Add convert function in Utf8_16_Write +//////////////////////////////////////////////////////////////////////////////// + +#include "Utf8_16.h" + +#include +#include +#include "PluginInterface.h" + +const Utf8_16::utf8 Utf8_16::k_Boms[][3] = { + {0x00, 0x00, 0x00}, // Unknown + {0xEF, 0xBB, 0xBF}, // UTF8 + {0xFE, 0xFF, 0x00}, // Big endian + {0xFF, 0xFE, 0x00}, // Little endian +}; + + +// ================================================================== + +Utf8_16_Read::Utf8_16_Read() { + m_eEncoding = uni8Bit; + m_nBufSize = 0; + m_pNewBuf = NULL; + m_bFirstRead = true; +} + +Utf8_16_Read::~Utf8_16_Read() +{ + if ((m_eEncoding == uni16BE) || (m_eEncoding == uni16LE)) + { + delete [] m_pNewBuf; + m_pNewBuf = NULL; + } +} + +// Returned value : +// 0 : utf8 +// 1 : 7bits +// 2 : 8bits +u78 Utf8_16_Read::utf8_7bits_8bits() +{ + int rv = 1; + int ASCII7only = 1; + utf8 *sx = (utf8 *)m_pBuf; + utf8 *endx = sx + m_nLen; + + while (sx=endx-1) + break; + if (!(*sx & 0x1F) || (sx[1]&(0x80+0x40)) != 0x80) { + rv=0; break; + } + sx+=2; + } + else if (*sx < (0x80 + 0x40 + 0x20 + 0x10)) + { // 1110qqqq 10xxxxvv 10nnnnnn If it begins with E, it is 16 bit + ASCII7only=0; + if (sx>=endx-2) + break; + if (!(*sx & 0xF) || (sx[1]&(0x80+0x40)) != 0x80 || (sx[2]&(0x80+0x40)) != 0x80) { + rv=0; break; + } + sx+=3; + } + else + { // more than 16 bits are not allowed here + ASCII7only=0; + rv=0; + break; + } + } + if (ASCII7only) + return ascii7bits; + if (rv) + return utf8NoBOM; + return ascii8bits; +} + +size_t Utf8_16_Read::convert(char* buf, size_t len) +{ + // bugfix by Jens Lorenz + static size_t nSkip = 0; + + size_t ret = 0; + + m_pBuf = (ubyte*)buf; + m_nLen = len; + + if (m_bFirstRead == true) + { + determineEncoding(); + nSkip = m_nSkip; + m_bFirstRead = false; + } + + switch (m_eEncoding) + { + case uni7Bit: + case uni8Bit: + case uniCookie: { + // Do nothing, pass through + m_nBufSize = 0; + m_pNewBuf = m_pBuf; + ret = len; + break; + } + case uniUTF8: { + // Pass through after BOM + m_nBufSize = 0; + m_pNewBuf = m_pBuf + nSkip; + ret = len - nSkip; + break; + } + case uni16BE: + case uni16LE: { + size_t newSize = len + len / 2 + 1; + + if (m_nBufSize != newSize) + { + if (m_pNewBuf) + delete [] m_pNewBuf; + m_pNewBuf = NULL; + m_pNewBuf = new ubyte[newSize]; + m_nBufSize = newSize; + } + + ubyte* pCur = m_pNewBuf; + + m_Iter16.set(m_pBuf + nSkip, len - nSkip, m_eEncoding); + + for (; m_Iter16; ++m_Iter16) + { + *pCur++ = m_Iter16.get(); + } + ret = pCur - m_pNewBuf; + break; + } + default: + break; + } + + // necessary for second calls and more + nSkip = 0; + + return ret; +} + + +void Utf8_16_Read::determineEncoding() +{ + m_eEncoding = uni8Bit; + m_nSkip = 0; + + if (m_nLen > 1 && m_pBuf[0] == k_Boms[uni16BE][0] && m_pBuf[1] == k_Boms[uni16BE][1]) + { + m_eEncoding = uni16BE; + m_nSkip = 2; + } + else if (m_nLen > 1 && m_pBuf[0] == k_Boms[uni16LE][0] && m_pBuf[1] == k_Boms[uni16LE][1]) + { + m_eEncoding = uni16LE; + m_nSkip = 2; + } + else if (m_nLen > 2 && m_pBuf[0] == k_Boms[uniUTF8][0] && + m_pBuf[1] == k_Boms[uniUTF8][1] && m_pBuf[2] == k_Boms[uniUTF8][2]) + { + m_eEncoding = uniUTF8; + m_nSkip = 3; + } + else + { + u78 detectedEncoding = utf8_7bits_8bits(); + if (detectedEncoding == utf8NoBOM) + m_eEncoding = uniCookie; + else if (detectedEncoding == ascii7bits) + m_eEncoding = uni7Bit; + else //(detectedEncoding == ascii8bits) + m_eEncoding = uni8Bit; + m_nSkip = 0; + } +} + + +// ================================================================== + +Utf8_16_Write::Utf8_16_Write() +{ + m_eEncoding = uni8Bit; + m_pFile = NULL; + m_pBuf = NULL; + m_pNewBuf = NULL; + m_bFirstWrite = true; + m_nBufSize = 0; +} + +Utf8_16_Write::~Utf8_16_Write() +{ + fclose(); +} + +FILE * Utf8_16_Write::fopen(const TCHAR *_name, const TCHAR *_type) +{ + m_pFile = ::generic_fopen(_name, _type); + + m_bFirstWrite = true; + + return m_pFile; +} + +size_t Utf8_16_Write::fwrite(const void* p, size_t _size) +{ + // no file open + if (!m_pFile) + { + return 0; + } + + size_t ret = 0; + + if (m_bFirstWrite) + { + switch (m_eEncoding) + { + case uniUTF8: { + ::fwrite(k_Boms[m_eEncoding], 3, 1, m_pFile); + break; + } + case uni16BE: + case uni16LE: + ::fwrite(k_Boms[m_eEncoding], 2, 1, m_pFile); + break; + default: + // nothing to do + break; + } + m_bFirstWrite = false; + } + + switch (m_eEncoding) + { + case uni7Bit: + case uni8Bit: + case uniCookie: + case uniUTF8: { + // Normal write + ret = ::fwrite(p, _size, 1, m_pFile); + break; + } + case uni16BE: + case uni16LE: { + if (_size > m_nBufSize) + { + m_nBufSize = _size; + if (m_pBuf != NULL) + delete [] m_pBuf; + m_pBuf = NULL; + m_pBuf = new utf16[_size + 1]; + } + + Utf8_Iter iter8; + iter8.set(static_cast(p), _size, m_eEncoding); + + utf16* pCur = m_pBuf; + + for (; iter8; ++iter8) { + if (iter8.canGet()) { + *pCur++ = iter8.get(); + } + } + ret = ::fwrite(m_pBuf, (const char*)pCur - (const char*)m_pBuf, 1, m_pFile); + break; + } + default: + break; + } + + return ret; +} + + +size_t Utf8_16_Write::convert(char* p, size_t _size) +{ + if (m_pNewBuf) + { + delete [] m_pNewBuf; + } + + switch (m_eEncoding) + { + case uni7Bit: + case uni8Bit: + case uniCookie: { + // Normal write + m_nBufSize = _size; + m_pNewBuf = (ubyte*)new ubyte[m_nBufSize]; + memcpy(m_pNewBuf, p, _size); + break; + } + case uniUTF8: { + m_nBufSize = _size + 3; + m_pNewBuf = (ubyte*)new ubyte[m_nBufSize]; + memcpy(m_pNewBuf, k_Boms[m_eEncoding], 3); + memcpy(&m_pNewBuf[3], p, _size); + break; + } + case uni16BE: + case uni16LE: { + m_pNewBuf = (ubyte*)new ubyte[sizeof(utf16) * (_size + 1)]; + + if (m_eEncoding == uni16BE || m_eEncoding == uni16LE) { + // Write the BOM + memcpy(m_pNewBuf, k_Boms[m_eEncoding], 2); + } + + Utf8_Iter iter8; + iter8.set(reinterpret_cast(p), _size, m_eEncoding); + + utf16* pCur = (utf16*)&m_pNewBuf[2]; + + for (; iter8; ++iter8) { + if (iter8.canGet()) { + *pCur++ = iter8.get(); + } + } + m_nBufSize = (const char*)pCur - (const char*)m_pNewBuf; + } + default: + break; + } + + return m_nBufSize; +} + + +void Utf8_16_Write::setEncoding(UniMode eType) +{ + m_eEncoding = eType; +} + + +void Utf8_16_Write::fclose() +{ + if (m_pNewBuf) + delete [] m_pNewBuf; + + if (m_pFile) + ::fclose(m_pFile); +} + + +//================================================================= +Utf8_Iter::Utf8_Iter() +{ + reset(); +} + +void Utf8_Iter::reset() +{ + m_pBuf = NULL; + m_pRead = NULL; + m_pEnd = NULL; + m_eState = eStart; + m_nCur = 0; + m_eEncoding = uni8Bit; +} + +void Utf8_Iter::set(const ubyte* pBuf, size_t nLen, UniMode eEncoding) +{ + m_pBuf = pBuf; + m_pRead = pBuf; + m_pEnd = pBuf + nLen; + m_eEncoding = eEncoding; + operator++(); + // Note: m_eState, m_nCur not set +} + +// Go to the next byte. +void Utf8_Iter::operator++() +{ + switch (m_eState) + { + case eStart: + if (*m_pRead < 0x80) { + m_nCur = *m_pRead; + toStart(); + } else if (*m_pRead < 0xE0) { + m_nCur = static_cast((0x1F & *m_pRead) << 6); + m_eState = e2Bytes_Byte2; + } else { + m_nCur = static_cast((0xF & *m_pRead) << 12); + m_eState = e3Bytes_Byte2; + } + break; + case e2Bytes_Byte2: + case e3Bytes_Byte3: + m_nCur |= static_cast(0x3F & *m_pRead); + toStart(); + break; + case e3Bytes_Byte2: + m_nCur |= static_cast((0x3F & *m_pRead) << 6); + m_eState = e3Bytes_Byte3; + break; + } + ++m_pRead; +} + +void Utf8_Iter::toStart() +{ + m_eState = eStart; + if (m_eEncoding == uni16BE) + { + swap(); + } +} + +void Utf8_Iter::swap() +{ + utf8* p = reinterpret_cast(&m_nCur); + utf8 swapbyte = *p; + *p = *(p + 1); + *(p + 1) = swapbyte; +} + +//================================================== +Utf16_Iter::Utf16_Iter() +{ + reset(); +} + +void Utf16_Iter::reset() +{ + m_pBuf = NULL; + m_pRead = NULL; + m_pEnd = NULL; + m_eState = eStart; + m_nCur = 0; + m_nCur16 = 0; + m_eEncoding = uni8Bit; +} + +void Utf16_Iter::set(const ubyte* pBuf, size_t nLen, UniMode eEncoding) +{ + m_pBuf = pBuf; + m_pRead = pBuf; + m_pEnd = pBuf + nLen; + m_eEncoding = eEncoding; + m_eState = eStart; + operator++(); + // Note: m_eState, m_nCur, m_nCur16 not reinitalized. +} + +// Goes to the next byte. +// Not the next symbol which you might expect. +// This way we can continue from a partial buffer that doesn't align +void Utf16_Iter::operator++() +{ + switch (m_eState) + { + case eStart: + if (m_eEncoding == uni16LE) { + m_nCur16 = *m_pRead++; + m_nCur16 |= static_cast(*m_pRead << 8); + } else { + m_nCur16 = static_cast(*m_pRead++ << 8); + m_nCur16 |= *m_pRead; + } + ++m_pRead; + + if (m_nCur16 < 0x80) { + m_nCur = static_cast(m_nCur16 & 0xFF); + m_eState = eStart; + } else if (m_nCur16 < 0x800) { + m_nCur = static_cast(0xC0 | m_nCur16 >> 6); + m_eState = e2Bytes2; + } else { + m_nCur = static_cast(0xE0 | m_nCur16 >> 12); + m_eState = e3Bytes2; + } + break; + case e2Bytes2: + case e3Bytes3: + m_nCur = static_cast(0x80 | m_nCur16 & 0x3F); + m_eState = eStart; + break; + case e3Bytes2: + m_nCur = static_cast(0x80 | ((m_nCur16 >> 6) & 0x3F)); + m_eState = e3Bytes3; + break; + } +} + + diff --git a/PowerEditor/src/Utf8_16.h b/PowerEditor/src/Utf8_16.h new file mode 100644 index 00000000..2c4f9497 --- /dev/null +++ b/PowerEditor/src/Utf8_16.h @@ -0,0 +1,153 @@ +// Utf8_16.h +// Copyright (C) 2002 Scott Kirkwood +// +// Permission to use, copy, modify, distribute and sell this code +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies or +// any derived copies. Scott Kirkwood makes no representations +// about the suitability of this software for any purpose. +// It is provided "as is" without express or implied warranty. +// +// Notes: Used the UTF information I found at: +// http://www.cl.cam.ac.uk/~mgk25/unicode.html +//////////////////////////////////////////////////////////////////////////////// +// +// Modificated 2006 Jens Lorenz +// +// - Clean up the sources +// - Removing UCS-Bug in Utf8_Iter +// - Add convert function in Utf8_16_Write +//////////////////////////////////////////////////////////////////////////////// +#pragma once + +#include +#include +#include "Parameters.h" + +#ifdef _MSC_VER +#pragma warning(disable: 4514) // nreferenced inline function has been removed +#endif + +class Utf8_16 { +public: + typedef unsigned short utf16; // 16 bits + typedef UCHAR utf8; // 8 bits + typedef UCHAR ubyte; + static const utf8 k_Boms[uniEnd][3]; +}; + +// Reads UTF-16 and outputs UTF-8 +class Utf16_Iter : public Utf8_16 { +public: + enum eState { + eStart, + e2Bytes2, + e3Bytes2, + e3Bytes3 + }; + + Utf16_Iter(); + void reset(); + void set(const ubyte* pBuf, size_t nLen, UniMode eEncoding); + utf8 get() const { return m_nCur; }; + void operator++(); + eState getState() { return m_eState; }; + operator bool() { return m_pRead <= m_pEnd; }; + +protected: + void toStart(); // Put to start state, swap bytes if necessary + +protected: + UniMode m_eEncoding; + eState m_eState; + utf8 m_nCur; + utf16 m_nCur16; + const ubyte* m_pBuf; + const ubyte* m_pRead; + const ubyte* m_pEnd; +}; + +// Reads UTF-8 and outputs UTF-16 +class Utf8_Iter : public Utf8_16 { +public: + Utf8_Iter(); + void reset(); + void set(const ubyte* pBuf, size_t nLen, UniMode eEncoding); + utf16 get() const { +#ifdef _DEBUG + assert(m_eState == eStart); +#endif + return m_nCur; + } + bool canGet() const { return m_eState == eStart; } + void operator++(); + operator bool() { return m_pRead <= m_pEnd; } + +protected: + void swap(); + void toStart(); // Put to start state, swap bytes if necessary + enum eState { + eStart, + e2Bytes_Byte2, + e3Bytes_Byte2, + e3Bytes_Byte3 + }; +protected: + UniMode m_eEncoding; + eState m_eState; + utf16 m_nCur; + const ubyte* m_pBuf; + const ubyte* m_pRead; + const ubyte* m_pEnd; +}; + +// Reads UTF16 and outputs UTF8 +enum u78 {utf8NoBOM=0, ascii7bits=1, ascii8bits=2}; +class Utf8_16_Read : public Utf8_16 { +public: + Utf8_16_Read(); + ~Utf8_16_Read(); + + size_t convert(char* buf, size_t len); + char* getNewBuf() { return reinterpret_cast(m_pNewBuf); } + + UniMode getEncoding() const { return m_eEncoding; } + size_t calcCurPos(size_t pos); +protected: + void determineEncoding(); + u78 utf8_7bits_8bits(); +private: + UniMode m_eEncoding; + ubyte* m_pBuf; + ubyte* m_pNewBuf; + size_t m_nBufSize; + size_t m_nSkip; + bool m_bFirstRead; + size_t m_nLen; + Utf16_Iter m_Iter16; +}; + +// Read in a UTF-8 buffer and write out to UTF-16 or UTF-8 +class Utf8_16_Write : public Utf8_16 { +public: + Utf8_16_Write(); + ~Utf8_16_Write(); + + void setEncoding(UniMode eType); + + FILE * fopen(const TCHAR *_name, const TCHAR *_type); + size_t fwrite(const void* p, size_t _size); + void fclose(); + + size_t convert(char* p, size_t _size); + char* getNewBuf() { return reinterpret_cast(m_pNewBuf); } + size_t calcCurPos(size_t pos); + +protected: + UniMode m_eEncoding; + FILE* m_pFile; + utf16* m_pBuf; + ubyte* m_pNewBuf; + size_t m_nBufSize; + bool m_bFirstWrite; +}; diff --git a/PowerEditor/src/WinControls/AboutDlg/AboutDlg.cpp b/PowerEditor/src/WinControls/AboutDlg/AboutDlg.cpp new file mode 100644 index 00000000..a89139ee --- /dev/null +++ b/PowerEditor/src/WinControls/AboutDlg/AboutDlg.cpp @@ -0,0 +1,107 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#include "AboutDlg.h" +#include "Parameters.h" + +BOOL CALLBACK AboutDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) +{ + switch (message) + { + case WM_INITDIALOG : + { + HWND compileDateHandle = ::GetDlgItem(_hSelf, IDC_BUILD_DATETIME); + generic_string buildTime = TEXT("Build time : "); + +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + buildTime += wmc->char2wchar(__DATE__, CP_ACP); + buildTime += TEXT(" - "); + buildTime += wmc->char2wchar(__TIME__, CP_ACP); + +#else + buildTime += __DATE__; + buildTime += TEXT(" - "); + buildTime += __TIME__; +#endif + ::SendMessage(compileDateHandle, WM_SETTEXT, 0, (LPARAM)buildTime.c_str()); + ::EnableWindow(compileDateHandle, FALSE); + + HWND licenceEditHandle = ::GetDlgItem(_hSelf, IDC_LICENCE_EDIT); + ::SendMessage(licenceEditHandle, WM_SETTEXT, 0, (LPARAM)LICENCE_TXT); + + _emailLink.init(_hInst, _hSelf); + _emailLink.create(::GetDlgItem(_hSelf, IDC_AUTHOR_NAME), TEXT("mailto:don.h@free.fr")); + + _pageLink.init(_hInst, _hSelf); + _pageLink.create(::GetDlgItem(_hSelf, IDC_HOME_ADDR), TEXT("http://notepad-plus.sourceforge.net/")); + + //_onLineHelp.init(_hInst, _hSelf); + //_onLineHelp.create(::GetDlgItem(_hSelf, IDC_ONLINEHELP_ADDR), TEXT("http://notepad-plus.sourceforge.net/uk/generalFAQ.php")); + + getClientRect(_rc); + + NppParameters *pNppParam = NppParameters::getInstance(); + ETDTProc enableDlgTheme = (ETDTProc)pNppParam->getEnableThemeDlgTexture(); + if (enableDlgTheme) + { + enableDlgTheme(_hSelf, ETDT_ENABLETAB); + redraw(); + } + + return TRUE; + } + + case WM_DRAWITEM : + { + HICON hIcon = ::LoadIcon(_hInst, MAKEINTRESOURCE(IDI_M30ICON)); + DRAWITEMSTRUCT *pdis = (DRAWITEMSTRUCT *)lParam; + ::DrawIcon(pdis->hDC, 0, 0, hIcon); + return TRUE; + } + + case WM_COMMAND : + { + switch (wParam) + { + case IDCANCEL : + case IDOK : + display(false); + return TRUE; + + default : + break; + } + } + + case WM_DESTROY : + { + return TRUE; + } + } + return FALSE; +} + +void AboutDlg::doDialog() +{ + if (!isCreated()) + create(IDD_ABOUTBOX); + + // Adjust the position of AboutBox + goToCenter(); +}; + diff --git a/PowerEditor/src/WinControls/AboutDlg/AboutDlg.h b/PowerEditor/src/WinControls/AboutDlg/AboutDlg.h new file mode 100644 index 00000000..97535ef5 --- /dev/null +++ b/PowerEditor/src/WinControls/AboutDlg/AboutDlg.h @@ -0,0 +1,63 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef ABOUT_DLG_H +#define ABOUT_DLG_H + +#include "URLCtrl.h" +#include "StaticDialog.h" +#include "ColourPicker.h" +#include "..\\..\\resource.h" + +#define LICENCE_TXT \ +TEXT("This program is free software; you can redistribute it and/or \ +modify it under the terms of the GNU General Public License \ +as published by the Free Software Foundation; either \ +version 2 of the License, or (at your option) any later version.\r\n\ +\r\n\ +This program is distributed in the hope that it will be useful, \ +but WITHOUT ANY WARRANTY; without even the implied warranty of \ +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \ +GNU General Public License for more details. \r\n\ +\r\n\ +You should have received a copy of the GNU General Public License \ +along with this program; if not, write to the Free Software \ +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.") + + + +class AboutDlg : public StaticDialog +{ +public : + AboutDlg() : StaticDialog() {}; + + void doDialog(); + + virtual void destroy() { + _emailLink.destroy(); + _pageLink.destroy(); + }; + +protected : + virtual BOOL CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam); + +private : + URLCtrl _emailLink; + URLCtrl _pageLink; +}; + +#endif //ABOUT_DLG_H diff --git a/PowerEditor/src/WinControls/AboutDlg/URLCtrl.cpp b/PowerEditor/src/WinControls/AboutDlg/URLCtrl.cpp new file mode 100644 index 00000000..3be03a5b --- /dev/null +++ b/PowerEditor/src/WinControls/AboutDlg/URLCtrl.cpp @@ -0,0 +1,277 @@ +#include "URLCtrl.h" + +static BYTE XORMask[128] = +{ + 0xff, 0xff, 0xff, 0xff, + 0xf9, 0xff, 0xff, 0xff, + 0xf0, 0xff, 0xff, 0xff, + 0xf0, 0xff, 0xff, 0xff, + 0xf0, 0xff, 0xff, 0xff, + 0xf0, 0xff, 0xff, 0xff, + 0xf0, 0x24, 0xff, 0xff, + 0xf0, 0x00, 0x7f, 0xff, + 0xc0, 0x00, 0x7f, 0xff, + 0x80, 0x00, 0x7f, 0xff, + 0x80, 0x00, 0x7f, 0xff, + 0x80, 0x00, 0x7f, 0xff, + 0x80, 0x00, 0x7f, 0xff, + 0x80, 0x00, 0x7f, 0xff, + 0xc0, 0x00, 0x7f, 0xff, + 0xe0, 0x00, 0x7f, 0xff, + 0xf0, 0x00, 0xff, 0xff, + 0xf0, 0x00, 0xff, 0xff, + 0xf0, 0x00, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, +}; + +/* AND mask for hand cursor */ +/* Generated by HexEdit */ +static BYTE ANDMask[128] = +{ + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, + 0x06, 0x00, 0x00, 0x00, + 0x06, 0xdb, 0x00, 0x00, + 0x06, 0xdb, 0x00, 0x00, + 0x36, 0xdb, 0x00, 0x00, + 0x36, 0xdb, 0x00, 0x00, + 0x37, 0xff, 0x00, 0x00, + 0x3f, 0xff, 0x00, 0x00, + 0x3f, 0xff, 0x00, 0x00, + 0x1f, 0xff, 0x00, 0x00, + 0x0f, 0xff, 0x00, 0x00, + 0x07, 0xfe, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, +}; + +static COLORREF getParentDlgBkColor(HWND hWnd) +{ + COLORREF crRet = CLR_INVALID; + if (hWnd && IsWindow(hWnd)) + { + HWND hWndParent = GetParent(hWnd); + if (hWndParent) + { + RECT rc; + if (GetClientRect(hWndParent, &rc)) + { + HDC hDC = GetDC(hWndParent); + if (hDC) + { + HDC hdcMem = CreateCompatibleDC(hDC); + if (hdcMem) + { + HBITMAP hBmp = CreateCompatibleBitmap(hDC, + rc.right, rc.bottom); + if (hBmp) + { + HGDIOBJ hOld = SelectObject(hdcMem, hBmp); + if (hOld) + { + if (SendMessage(hWndParent, WM_ERASEBKGND, (WPARAM)hdcMem, 0)) + { + crRet = GetPixel(hdcMem, 0, 0); + } + SelectObject(hdcMem, hOld); + } + DeleteObject(hBmp); + } + DeleteDC(hdcMem); + } + ReleaseDC(hWndParent, hDC); + } + } + } + } + return crRet; +} + +void URLCtrl::create(HWND itemHandle, TCHAR * link, COLORREF linkColor) +{ + // turn on notify style + ::SetWindowLongPtr(itemHandle, GWL_STYLE, ::GetWindowLongPtr(itemHandle, GWL_STYLE) | SS_NOTIFY); + + // set the URL text (not the display text) + if (link) + lstrcpy(_URL, link); + + // set the hyperlink colour + _linkColor = linkColor; + + // set the visited colour + _visitedColor = RGB(128,0,128); + + // subclass the static control + _oldproc = (WNDPROC)::SetWindowLongPtr(itemHandle, GWL_WNDPROC, (LONG)URLCtrlProc); + + // associate the URL structure with the static control + ::SetWindowLongPtr(itemHandle, GWL_USERDATA, (LONG)this); + +} +void URLCtrl::create(HWND itemHandle, int cmd, HWND msgDest) +{ + // turn on notify style + ::SetWindowLongPtr(itemHandle, GWL_STYLE, ::GetWindowLongPtr(itemHandle, GWL_STYLE) | SS_NOTIFY); + + _cmdID = cmd; + _msgDest = msgDest; + + // set the hyperlink colour + _linkColor = RGB(0,0,255); + + // subclass the static control + _oldproc = (WNDPROC)::SetWindowLongPtr(itemHandle, GWL_WNDPROC, (LONG)URLCtrlProc); + + // associate the URL structure with the static control + ::SetWindowLongPtr(itemHandle, GWL_USERDATA, (LONG)this); +} +LRESULT URLCtrl::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) +{ + switch(Message) + { + // Free up the structure we allocated + case WM_NCDESTROY: + //HeapFree(GetProcessHeap(), 0, url); + break; + + // Paint the static control using our custom + // colours, and with an underline text style + case WM_PAINT: + { + DWORD dwStyle = ::GetWindowLongPtr(hwnd, GWL_STYLE); + DWORD dwDTStyle = DT_SINGLELINE; + + //Test if centered horizontally or vertically + if(dwStyle & SS_CENTER) dwDTStyle |= DT_CENTER; + if(dwStyle & SS_RIGHT) dwDTStyle |= DT_RIGHT; + if(dwStyle & SS_CENTERIMAGE) dwDTStyle |= DT_VCENTER; + + RECT rect; + ::GetClientRect(hwnd, &rect); + + PAINTSTRUCT ps; + HDC hdc = ::BeginPaint(hwnd, &ps); + + ::SetTextColor(hdc, _linkColor); + + ::SetBkColor(hdc, getParentDlgBkColor(hwnd)); ///*::GetSysColor(COLOR_3DFACE)*/); + + // Create an underline font + if(_hfUnderlined == 0) + { + // Get the default GUI font + LOGFONT lf; + HFONT hf = (HFONT)::GetStockObject(DEFAULT_GUI_FONT); + + // Add UNDERLINE attribute + GetObject(hf, sizeof lf, &lf); + lf.lfUnderline = TRUE; + + // Create a new font + _hfUnderlined = ::CreateFontIndirect(&lf); + } + + HANDLE hOld = SelectObject(hdc, _hfUnderlined); + + // Draw the text! + TCHAR szWinText[MAX_PATH]; + ::GetWindowText(hwnd, szWinText, MAX_PATH); + ::DrawText(hdc, szWinText, -1, &rect, dwDTStyle); + + ::SelectObject(hdc, hOld); + + ::EndPaint(hwnd, &ps); + + return 0; + } + + case WM_SETTEXT: + { + LRESULT ret = ::CallWindowProc(_oldproc, hwnd, Message, wParam, lParam); + ::InvalidateRect(hwnd, 0, 0); + return ret; + } + // Provide a hand cursor when the mouse moves over us + //case WM_SETCURSOR: + case WM_MOUSEMOVE: + { + if (_hCursor == 0) + _hCursor = ::CreateCursor(::GetModuleHandle(0), 5, 2, 32, 32, XORMask, ANDMask); + + SetCursor(_hCursor); + return TRUE; + } + + case WM_LBUTTONDOWN: + _clicking = true; + break; + + case WM_LBUTTONUP: + if(_clicking) + { + _clicking = false; + if (_cmdID) + { + ::SendMessage(_msgDest?_msgDest:_hParent, WM_COMMAND, _cmdID, 0); + } + else + { + _linkColor = _visitedColor; + + ::InvalidateRect(hwnd, 0, 0); + ::UpdateWindow(hwnd); + + // Open a browser + if(_URL[0]) + { + ::ShellExecute(NULL, TEXT("open"), _URL, NULL, NULL, SW_SHOWNORMAL); + } + else + { + TCHAR szWinText[MAX_PATH]; + ::GetWindowText(hwnd, szWinText, MAX_PATH); + ::ShellExecute(NULL, TEXT("open"), szWinText, NULL, NULL, SW_SHOWNORMAL); + } + } + } + + break; + + // A standard static control returns HTTRANSPARENT here, which + // prevents us from receiving any mouse messages. So, return + // HTCLIENT instead. + case WM_NCHITTEST: + return HTCLIENT; + } + return ::CallWindowProc(_oldproc, hwnd, Message, wParam, lParam); +} diff --git a/PowerEditor/src/WinControls/AboutDlg/URLCtrl.h b/PowerEditor/src/WinControls/AboutDlg/URLCtrl.h new file mode 100644 index 00000000..5a93a011 --- /dev/null +++ b/PowerEditor/src/WinControls/AboutDlg/URLCtrl.h @@ -0,0 +1,43 @@ +#ifndef URLCTRL_INCLUDED +#define URLCTRL_INCLUDED + +//#include +#include + +/* XOR mask for hand cursor */ +/* Generated by HexEdit */ + +class URLCtrl : public Window { +public: + URLCtrl():_hfUnderlined(0),_hCursor(0), _msgDest(NULL), _cmdID(0), _oldproc(NULL), \ + _linkColor(), _visitedColor(), _clicking(false) {_URL[0] = '\0';}; + + void create(HWND itemHandle, TCHAR * link, COLORREF linkColor = RGB(0,0,255)); + void create(HWND itemHandle, int cmd, HWND msgDest = NULL); + void destroy(){ + if(_hfUnderlined) + ::DeleteObject(_hfUnderlined); + if(_hCursor) + ::DestroyCursor(_hCursor); + }; + +protected : + TCHAR _URL[MAX_PATH]; + HFONT _hfUnderlined; + HCURSOR _hCursor; + + HWND _msgDest; + unsigned long _cmdID; + + WNDPROC _oldproc; + COLORREF _linkColor; + COLORREF _visitedColor; + bool _clicking; + + static LRESULT CALLBACK URLCtrlProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam){ + return ((URLCtrl *)(::GetWindowLongPtr(hwnd, GWL_USERDATA)))->runProc(hwnd, Message, wParam, lParam); + }; + LRESULT runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam); +}; + +#endif //URLCTRL_INCLUDED diff --git a/PowerEditor/src/WinControls/ColourPicker/ColourPicker.cpp b/PowerEditor/src/WinControls/ColourPicker/ColourPicker.cpp new file mode 100644 index 00000000..623c6001 --- /dev/null +++ b/PowerEditor/src/WinControls/ColourPicker/ColourPicker.cpp @@ -0,0 +1,181 @@ +/* +this file is part of notepad++ +Copyright (C)2003 Don HO < donho@altern.org > + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "ColourPicker.h" +#include "Common.h" + + +void ColourPicker::init(HINSTANCE hInst, HWND parent) +{ + Window::init(hInst, parent); + + _hSelf = ::CreateWindowEx( + 0, + TEXT("Button"), + TEXT("F"), + WS_CHILD | WS_VISIBLE, + 0, 0, 25, 25, + _hParent, + NULL, + _hInst, + (LPVOID)0); + if (!_hSelf) + { + systemMessage(TEXT("System Err")); + throw int(6969); + } + + + ::SetWindowLongPtr(_hSelf, GWL_USERDATA, reinterpret_cast(this)); + _buttonDefaultProc = reinterpret_cast(::SetWindowLongPtr(_hSelf, GWL_WNDPROC, reinterpret_cast(staticWinProc))); + +} + +void ColourPicker::drawBackground(HDC hDC) +{ + RECT rc; + HBRUSH hbrush; + + if(!hDC) + return; + + getClientRect(rc); + hbrush = ::CreateSolidBrush(_currentColour); + HGDIOBJ oldObj = ::SelectObject(hDC, hbrush); + ::Rectangle(hDC, 0, 0, rc.right, rc.bottom); + ::SelectObject(hDC, oldObj); + //FillRect(hDC, &rc, hbrush); + ::DeleteObject(hbrush); +} + +void ColourPicker::drawForeground(HDC hDC) +{ + RECT rc; + HBRUSH hbrush; + + if(!hDC || _isEnabled) + return; + + int oldMode = ::SetBkMode(hDC, TRANSPARENT); + getClientRect(rc); + COLORREF strikeOut = RGB(0,0,0); + if ((((_currentColour ) & 0xFF) + + ((_currentColour >> 8) & 0xFF) + + ((_currentColour >> 16) & 0xFF)) < 200) //check if the color is too dark, if so, use white strikeout + strikeOut = RGB(0xFF,0xFF,0xFF); + if (!_isEnabled) + hbrush = ::CreateHatchBrush(HS_FDIAGONAL, strikeOut); + HGDIOBJ oldObj = ::SelectObject(hDC, hbrush); + ::Rectangle(hDC, 0, 0, rc.right, rc.bottom); + ::SelectObject(hDC, oldObj); + //FillRect(hDC, &rc, hbrush); + ::DeleteObject(hbrush); + ::SetBkMode(hDC, oldMode); +} + +LRESULT ColourPicker::runProc(UINT Message, WPARAM wParam, LPARAM lParam) +{ + switch (Message) + { + case WM_LBUTTONDBLCLK : + case WM_LBUTTONDOWN : + { + if (!_pColourPopup) + { + RECT rc; + POINT p; + + Window::getClientRect(rc); + ::InflateRect(&rc, -2, -2); + p.x = rc.left; + p.y = rc.top + rc.bottom; + + ::ClientToScreen(_hSelf, &p); + _pColourPopup = new ColourPopup(_currentColour); + _pColourPopup->init(_hInst, _hSelf); + _pColourPopup->doDialog(p); + } + return TRUE; + } + case WM_RBUTTONDOWN: + { + _isEnabled = !_isEnabled; + redraw(); + ::SendMessage(_hParent, WM_COMMAND, MAKELONG(0, CPN_COLOURPICKED), (LPARAM)_hSelf); + break; + } + + case WM_ERASEBKGND: + { + HDC dc = (HDC)wParam; + drawBackground(dc); + return TRUE; + break; + } + + case WM_PAINT : + { + PAINTSTRUCT ps; + HDC dc = ::BeginPaint(_hSelf, &ps); + drawForeground(dc); + ::EndPaint(_hSelf, &ps); + return TRUE; + } + + case WM_PICKUP_COLOR : + { + _currentColour = (COLORREF)wParam; + redraw(); + + _pColourPopup->destroy(); + delete _pColourPopup; + _pColourPopup = NULL; + ::SendMessage(_hParent, WM_COMMAND, MAKELONG(0, CPN_COLOURPICKED), (LPARAM)_hSelf); + return TRUE; + } + + case WM_ENABLE : + { + if ((BOOL)wParam == FALSE) + { + _currentColour = ::GetSysColor(COLOR_3DFACE); + redraw(); + } + return TRUE; + } + + case WM_PICKUP_CANCEL : + case WM_DESTROY : + { + if (_pColourPopup) + { + _pColourPopup->destroy(); + delete _pColourPopup; + _pColourPopup = NULL; + + return TRUE; + } + break; + } + + default : + return ::CallWindowProc(_buttonDefaultProc, _hSelf, Message, wParam, lParam); + } + return FALSE; +} diff --git a/PowerEditor/src/WinControls/ColourPicker/ColourPicker.h b/PowerEditor/src/WinControls/ColourPicker/ColourPicker.h new file mode 100644 index 00000000..37cae49c --- /dev/null +++ b/PowerEditor/src/WinControls/ColourPicker/ColourPicker.h @@ -0,0 +1,62 @@ +/* +this file is part of notepad++ +Copyright (C)2003 Don HO < donho@altern.org > + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef COLOUR_PICKER_H +#define COLOUR_PICKER_H + +#include "Window.h" +#include "ColourPopup.h" + +//#define CP_CLASS_NAME "colourPickerButton" +#define CPN_COLOURPICKED (BN_CLICKED) + +class ColourPicker : public Window +{ +public : + ColourPicker() : Window(), _currentColour(RGB(0xFF, 0x00, 0x00)), _pColourPopup(NULL), _isEnabled(true) {}; + ~ColourPicker(){}; + virtual void init(HINSTANCE hInst, HWND parent); + virtual void destroy() { + DestroyWindow(_hSelf); + }; + void setColour(COLORREF c) { + _currentColour = c; + //drawSelf(); + }; + + COLORREF getColour() const {return _currentColour;}; + + bool isEnabled() {return _isEnabled;}; + void setEnabled(bool enabled) {_isEnabled = enabled;}; + +private : + COLORREF _currentColour; + WNDPROC _buttonDefaultProc; + ColourPopup *_pColourPopup; + bool _isEnabled; + + static LRESULT CALLBACK staticWinProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { + return (((ColourPicker *)(::GetWindowLongPtr(hwnd, GWL_USERDATA)))->runProc(Message, wParam, lParam)); + }; + LRESULT runProc(UINT Message, WPARAM wParam, LPARAM lParam); + void drawForeground(HDC hDC); + void drawBackground(HDC hDC); +}; + +#endif // COLOUR_PICKER_H diff --git a/PowerEditor/src/WinControls/ColourPicker/ColourPopup.cpp b/PowerEditor/src/WinControls/ColourPicker/ColourPopup.cpp new file mode 100644 index 00000000..ba94cb5d --- /dev/null +++ b/PowerEditor/src/WinControls/ColourPicker/ColourPopup.cpp @@ -0,0 +1,240 @@ +/* +this file is part of notepad++ +Copyright (C)2003 Don HO < donho@altern.org > + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "ColourPopup.h" +#include "Common.h" + +DWORD colourItems[] = { + RGB( 0, 0, 0), RGB( 64, 0, 0), RGB(128, 0, 0), RGB(128, 64, 64), RGB(255, 0, 0), RGB(255, 128, 128), + RGB(255, 255, 128), RGB(255, 255, 0), RGB(255, 128, 64), RGB(255, 128, 0), RGB(128, 64, 0), RGB(128, 128, 0), + RGB(128, 128, 64), RGB( 0, 64, 0), RGB( 0, 128, 0), RGB( 0, 255, 0), RGB(128, 255, 0), RGB(128, 255, 128), + RGB( 0, 255, 128), RGB( 0, 255, 64), RGB( 0, 128, 128), RGB( 0, 128, 64), RGB( 0, 64, 64), RGB(128, 128, 128), + RGB( 64, 128, 128), RGB( 0, 0, 128), RGB( 0, 0, 255), RGB( 0, 64, 128), RGB( 0, 255, 255), RGB(128, 255, 255), + RGB( 0, 128, 255), RGB( 0, 128, 192), RGB(128, 128, 255), RGB( 0, 0, 160), RGB( 0, 0, 64), RGB(192, 192, 192), + RGB( 64, 0, 64), RGB( 64, 0, 64), RGB(128, 0, 128), RGB(128, 0, 64), RGB(128, 128, 192), RGB(255, 128, 192), + RGB(255, 128, 255), RGB(255, 0, 255), RGB(255, 0, 128), RGB(128, 0, 255), RGB( 64, 0, 128), RGB(255, 255, 255), +}; + +void ColourPopup::create(int dialogID) +{ + _hSelf = ::CreateDialogParam(_hInst, MAKEINTRESOURCE(dialogID), _hParent, (DLGPROC)dlgProc, (LPARAM)this); + + if (!_hSelf) + { + systemMessage(TEXT("ColourPopup")); + throw int(696); + } + Window::getClientRect(_rc); + display(); +} + +BOOL CALLBACK ColourPopup::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + switch (message) + { + case WM_MEASUREITEM: + { + RECT rc; + LPMEASUREITEMSTRUCT lpmis = (LPMEASUREITEMSTRUCT) lParam; + ::GetWindowRect(::GetDlgItem(hwnd, lpmis->CtlID), &rc); + lpmis->itemHeight = (rc.bottom-rc.top)/6; + lpmis->itemWidth = (rc.right-rc.left)/8; + return TRUE; + } + + case WM_INITDIALOG : + { + ColourPopup *pColourPopup = (ColourPopup *)(lParam); + pColourPopup->_hSelf = hwnd; + ::SetWindowLongPtr(hwnd, GWL_USERDATA, (long)lParam); + pColourPopup->run_dlgProc(message, wParam, lParam); + return TRUE; + } + + default : + { + ColourPopup *pColourPopup = reinterpret_cast(::GetWindowLongPtr(hwnd, GWL_USERDATA)); + if (!pColourPopup) + return FALSE; + return pColourPopup->run_dlgProc(message, wParam, lParam); + } + } +} + +BOOL CALLBACK ColourPopup::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) +{ + + switch (message) + { + case WM_INITDIALOG: + { + int nColor; + for (nColor = 0 ; nColor < int(sizeof(colourItems)/sizeof(DWORD)) ; nColor++) + { + ::SendDlgItemMessage(_hSelf, IDC_COLOUR_LIST, LB_ADDSTRING, nColor, (LPARAM) ""); + ::SendDlgItemMessage(_hSelf, IDC_COLOUR_LIST, LB_SETITEMDATA , nColor, (LPARAM) colourItems[nColor]); + //if (g_bgColor == colourItems[nColor]) + //::SendDlgItemMessage(_hSelf, IDC_COLOUR_LIST, LB_SETCURSEL, nColor, 0); + } + //::SetCapture(_hSelf); + return TRUE; + } + + case WM_CTLCOLORLISTBOX: + return (LRESULT) CreateSolidBrush(GetSysColor(COLOR_3DFACE)); + + case WM_DRAWITEM: + { + HDC hdc; + COLORREF cr; + HBRUSH hbrush; + + DRAWITEMSTRUCT *pdis = (DRAWITEMSTRUCT *)lParam; + hdc = pdis->hDC; + RECT rc = pdis->rcItem; + + // Transparent. + SetBkMode(hdc,TRANSPARENT); + + // NULL object + if (pdis->itemID == UINT(-1)) return 0; + + switch (pdis->itemAction) + { + case ODA_DRAWENTIRE: + switch (pdis->CtlID) + { + case IDC_COLOUR_LIST: + rc = pdis->rcItem; + cr = (COLORREF) pdis->itemData; + InflateRect(&rc, -3, -3); + hbrush = CreateSolidBrush((COLORREF)cr); + FillRect(hdc, &rc, hbrush); + DeleteObject(hbrush); + FrameRect(hdc, &rc, (HBRUSH) GetStockObject(GRAY_BRUSH)); + break; + } + // *** FALL THROUGH *** + case ODA_SELECT: + rc = pdis->rcItem; + if (pdis->itemState & ODS_SELECTED) + { + rc.bottom --; + rc.right --; + // Draw the lighted side. + HPEN hpen = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_BTNSHADOW)); + HPEN holdPen = (HPEN)SelectObject(hdc, hpen); + MoveToEx(hdc, rc.left, rc.bottom, NULL); + LineTo(hdc, rc.left, rc.top); + LineTo(hdc, rc.right, rc.top); + SelectObject(hdc, holdPen); + DeleteObject(hpen); + // Draw the darkened side. + hpen = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_BTNHIGHLIGHT)); + holdPen = (HPEN)SelectObject(hdc, hpen); + LineTo(hdc, rc.right, rc.bottom); + LineTo(hdc, rc.left, rc.bottom); + SelectObject(hdc, holdPen); + DeleteObject(hpen); + } + else + { + hbrush = CreateSolidBrush(GetSysColor(COLOR_3DFACE)); + FrameRect(hdc, &rc, hbrush); + DeleteObject(hbrush); + } + break; + case ODA_FOCUS: + rc = pdis->rcItem; + InflateRect(&rc, -2, -2); + DrawFocusRect(hdc, &rc); + break; + default: + break; + } + return TRUE; + } + + case WM_COMMAND: + switch (LOWORD(wParam)) + { + case IDOK : + { + isColourChooserLaunched = true; + CHOOSECOLOR cc; // common dialog box structure + static COLORREF acrCustClr[16] = { + RGB(0xFF,0xFF,0xFF),RGB(0xFF,0xFF,0xFF),RGB(0xFF,0xFF,0xFF),RGB(0xFF,0xFF,0xFF),\ + RGB(0xFF,0xFF,0xFF),RGB(0xFF,0xFF,0xFF),RGB(0xFF,0xFF,0xFF),RGB(0xFF,0xFF,0xFF),\ + RGB(0xFF,0xFF,0xFF),RGB(0xFF,0xFF,0xFF),RGB(0xFF,0xFF,0xFF),RGB(0xFF,0xFF,0xFF),\ + RGB(0xFF,0xFF,0xFF),RGB(0xFF,0xFF,0xFF),RGB(0xFF,0xFF,0xFF),RGB(0xFF,0xFF,0xFF),\ + }; // array of custom colors + + // Initialize CHOOSECOLOR + ::ZeroMemory(&cc, sizeof(cc)); + cc.lStructSize = sizeof(cc); + cc.hwndOwner = _hParent; + + cc.lpCustColors = (LPDWORD) acrCustClr; + cc.rgbResult = _colour; + cc.Flags = CC_FULLOPEN | CC_RGBINIT; + + display(false); + + if (ChooseColor(&cc)==TRUE) + { + ::SendMessage(_hParent, WM_PICKUP_COLOR, cc.rgbResult, 0); + } + else + { + ::SendMessage(_hParent, WM_PICKUP_CANCEL, 0, 0); + } + + return TRUE; + } + + case IDC_COLOUR_LIST : + { + if (HIWORD(wParam) == LBN_SELCHANGE) + { + int i = ::SendMessage((HWND)lParam, LB_GETCURSEL, 0L, 0L); + _colour = ::SendMessage((HWND)lParam, LB_GETITEMDATA, i, 0L); + + ::SendMessage(_hParent, WM_PICKUP_COLOR, _colour, 0); + return TRUE; + } + } + + default : + return FALSE; + } + + case WM_ACTIVATE : + { + if (LOWORD(wParam) == WA_INACTIVE) + if (!isColourChooserLaunched) + ::SendMessage(_hParent, WM_PICKUP_CANCEL, 0, 0); + return TRUE; + } + + } + return FALSE; +} + + + diff --git a/PowerEditor/src/WinControls/ColourPicker/ColourPopup.h b/PowerEditor/src/WinControls/ColourPicker/ColourPopup.h new file mode 100644 index 00000000..76686b76 --- /dev/null +++ b/PowerEditor/src/WinControls/ColourPicker/ColourPopup.h @@ -0,0 +1,68 @@ +/* +this file is part of notepad++ +Copyright (C)2003 Don HO < donho@altern.org > + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef COLOUR_POPUP_H +#define COLOUR_POPUP_H + +#include "Window.h" +#include "ColourPopupResource.h" +#include "resource.h" + +#define WM_PICKUP_COLOR (COLOURPOPUP_USER + 1) +#define WM_PICKUP_CANCEL (COLOURPOPUP_USER + 2) + +class ColourPopup : public Window +{ +public : + ColourPopup() : Window(), isColourChooserLaunched(false) {}; + ColourPopup(COLORREF defaultColor) : Window(), isColourChooserLaunched(false), _colour(defaultColor) {}; + ~ColourPopup(){}; + + bool isCreated() const { + return (_hSelf != NULL); + }; + + void create(int dialogID); + + void doDialog(POINT p) { + if (!isCreated()) + create(IDD_COLOUR_POPUP); + ::SetWindowPos(_hSelf, HWND_TOP, p.x, p.y, _rc.right - _rc.left, _rc.bottom - _rc.top, SWP_SHOWWINDOW); + }; + + virtual void destroy() { + ::DestroyWindow(_hSelf); + }; + COLORREF getSelColour(){return _colour;}; + +private : + RECT _rc; + COLORREF _colour; + bool isColourChooserLaunched; + + static BOOL CALLBACK dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); + BOOL CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam); + + + +}; + +#endif //COLOUR_POPUP_H + + diff --git a/PowerEditor/src/WinControls/ColourPicker/ColourPopup.rc b/PowerEditor/src/WinControls/ColourPicker/ColourPopup.rc new file mode 100644 index 00000000..1f5884e0 --- /dev/null +++ b/PowerEditor/src/WinControls/ColourPicker/ColourPopup.rc @@ -0,0 +1,32 @@ +/* +this file is part of notepad++ +Copyright (C)2003 Don HO < donho@altern.org > + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + + +#include +#include "ColourPopupResource.h" + +IDD_COLOUR_POPUP DIALOGEX 0, 0, 132, 113 +STYLE DS_SETFONT | WS_POPUP | DS_MODALFRAME +FONT 8, TEXT("MS Shell Dlg"), 0, 0, 0x0 +BEGIN + LISTBOX IDC_COLOUR_LIST,7,7,117,79, + LBS_OWNERDRAWFIXED | LBS_NOINTEGRALHEIGHT | + LBS_MULTICOLUMN | NOT WS_BORDER | WS_TABSTOP + DEFPUSHBUTTON "More Colours...",IDOK,39,92,55,14 +END diff --git a/PowerEditor/src/WinControls/ColourPicker/ColourPopupResource.h b/PowerEditor/src/WinControls/ColourPicker/ColourPopupResource.h new file mode 100644 index 00000000..c4b964c0 --- /dev/null +++ b/PowerEditor/src/WinControls/ColourPicker/ColourPopupResource.h @@ -0,0 +1,3 @@ +#define IDD_COLOUR_POPUP 2100 + +#define IDC_COLOUR_LIST (IDD_COLOUR_POPUP + 1) diff --git a/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.cpp b/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.cpp new file mode 100644 index 00000000..02943f92 --- /dev/null +++ b/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.cpp @@ -0,0 +1,824 @@ +/* +this file is part of notepad++ +Copyright (C)2003 Don HO < donho@altern.org > + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "WordStyleDlg.h" +#include "ScintillaEditView.h" + +BOOL CALLBACK ColourStaticTextHooker::colourStaticProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) +{ + switch(Message) + { + case WM_PAINT: + { + RECT rect; + ::GetClientRect(hwnd, &rect); + + PAINTSTRUCT ps; + HDC hdc = ::BeginPaint(hwnd, &ps); + + ::SetTextColor(hdc, _colour); + + // Get the default GUI font + HFONT hf = (HFONT)::GetStockObject(DEFAULT_GUI_FONT); + + HANDLE hOld = SelectObject(hdc, hf); + + // Draw the text! + TCHAR text[MAX_PATH]; + ::GetWindowText(hwnd, text, MAX_PATH); + ::DrawText(hdc, text, -1, &rect, DT_LEFT); + + ::SelectObject(hdc, hOld); + + ::EndPaint(hwnd, &ps); + + return TRUE; + } + } + return ::CallWindowProc(_oldProc, hwnd, Message, wParam, lParam); +} +void WordStyleDlg::updateGlobalOverrideCtrls() +{ + const NppGUI & nppGUI = (NppParameters::getInstance())->getNppGUI(); + ::SendDlgItemMessage(_hSelf, IDC_GLOBAL_FG_CHECK, BM_SETCHECK, nppGUI._globalOverride.enableFg, 0); + ::SendDlgItemMessage(_hSelf, IDC_GLOBAL_BG_CHECK, BM_SETCHECK, nppGUI._globalOverride.enableBg, 0); + ::SendDlgItemMessage(_hSelf, IDC_GLOBAL_FONT_CHECK, BM_SETCHECK, nppGUI._globalOverride.enableFont, 0); + ::SendDlgItemMessage(_hSelf, IDC_GLOBAL_FONTSIZE_CHECK, BM_SETCHECK, nppGUI._globalOverride.enableFontSize, 0); + ::SendDlgItemMessage(_hSelf, IDC_GLOBAL_BOLD_CHECK, BM_SETCHECK, nppGUI._globalOverride.enableBold, 0); + ::SendDlgItemMessage(_hSelf, IDC_GLOBAL_ITALIC_CHECK, BM_SETCHECK, nppGUI._globalOverride.enableItalic, 0); + ::SendDlgItemMessage(_hSelf, IDC_GLOBAL_UNDERLINE_CHECK, BM_SETCHECK, nppGUI._globalOverride.enableUnderLine, 0); +} + +BOOL CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam) +{ + switch (Message) + { + case WM_INITDIALOG : + { + NppParameters *nppParamInst = NppParameters::getInstance(); + + _hCheckBold = ::GetDlgItem(_hSelf, IDC_BOLD_CHECK); + _hCheckItalic = ::GetDlgItem(_hSelf, IDC_ITALIC_CHECK); + _hCheckUnderline = ::GetDlgItem(_hSelf, IDC_UNDERLINE_CHECK); + _hFontNameCombo = ::GetDlgItem(_hSelf, IDC_FONT_COMBO); + _hFontSizeCombo = ::GetDlgItem(_hSelf, IDC_FONTSIZE_COMBO); + _hSwitch2ThemeCombo = ::GetDlgItem(_hSelf, IDC_SWITCH2THEME_COMBO); + + _hFgColourStaticText = ::GetDlgItem(_hSelf, IDC_FG_STATIC); + _hBgColourStaticText = ::GetDlgItem(_hSelf, IDC_BG_STATIC); + _hFontNameStaticText = ::GetDlgItem(_hSelf, IDC_FONTNAME_STATIC); + _hFontSizeStaticText = ::GetDlgItem(_hSelf, IDC_FONTSIZE_STATIC); + _hStyleInfoStaticText = ::GetDlgItem(_hSelf, IDC_STYLEDESCRIPTION_STATIC); + + colourHooker.setColour(RGB(0xFF, 0x00, 0x00)); + colourHooker.hookOn(_hStyleInfoStaticText); + + _currentThemeIndex = -1; + int defaultThemeIndex = 0; + ThemeSwitcher & themeSwitcher = nppParamInst->getThemeSwitcher(); + for(size_t i = 0 ; i < themeSwitcher.size() ; i++) + { + pair & themeInfo = themeSwitcher.getElementFromIndex(i); + int j = ::SendMessage(_hSwitch2ThemeCombo, CB_ADDSTRING, 0, (LPARAM)themeInfo.first.c_str()); + ::SendMessage(_hSwitch2ThemeCombo, CB_SETITEMDATA, j, (LPARAM)themeInfo.second.c_str()); + if (! themeInfo.second.compare( nppParamInst->getNppGUI()._themeName ) ) + { + _currentThemeIndex = j; + } + if (! themeInfo.first.compare(TEXT("Default")) ) + { + defaultThemeIndex = j; + } + } + if (_currentThemeIndex == -1) + { + _currentThemeIndex = defaultThemeIndex; + } + ::SendMessage(_hSwitch2ThemeCombo, CB_SETCURSEL, _currentThemeIndex, 0); + + for(int i = 0 ; i < sizeof(fontSizeStrs)/(3*sizeof(TCHAR)) ; i++) + ::SendMessage(_hFontSizeCombo, CB_ADDSTRING, 0, (LPARAM)fontSizeStrs[i]); + + const std::vector & fontlist = (NppParameters::getInstance())->getFontList(); + for (size_t i = 0 ; i < fontlist.size() ; i++) + { + int j = ::SendMessage(_hFontNameCombo, CB_ADDSTRING, 0, (LPARAM)fontlist[i].c_str()); + ::SendMessage(_hFontNameCombo, CB_SETITEMDATA, j, (LPARAM)fontlist[i].c_str()); + } + + _pFgColour = new ColourPicker; + _pBgColour = new ColourPicker; + _pFgColour->init(_hInst, _hSelf); + _pBgColour->init(_hInst, _hSelf); + + POINT p1, p2; + + alignWith(_hFgColourStaticText, _pFgColour->getHSelf(), ALIGNPOS_RIGHT, p1); + alignWith(_hBgColourStaticText, _pBgColour->getHSelf(), ALIGNPOS_RIGHT, p2); + + p1.x = p2.x = ((p1.x > p2.x)?p1.x:p2.x) + 10; + p1.y -= 4; p2.y -= 4; + + ::MoveWindow((HWND)_pFgColour->getHSelf(), p1.x, p1.y, 25, 25, TRUE); + ::MoveWindow((HWND)_pBgColour->getHSelf(), p2.x, p2.y, 25, 25, TRUE); + _pFgColour->display(); + _pBgColour->display(); + + + ::EnableWindow(::GetDlgItem(_hSelf, IDOK), _isDirty); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_SAVECLOSE_BUTTON), FALSE/*!_isSync*/); + + ETDTProc enableDlgTheme = (ETDTProc)nppParamInst->getEnableThemeDlgTexture(); + if (enableDlgTheme) + { + enableDlgTheme(_hSelf, ETDT_ENABLETAB); + redraw(); + } + + updateGlobalOverrideCtrls(); + setVisualFromStyleList(); + goToCenter(); + + loadLangListFromNppParam(); + + return TRUE; + } + + case WM_DESTROY: + { + _pFgColour->destroy(); + _pBgColour->destroy(); + delete _pFgColour; + delete _pBgColour; + return TRUE; + } + + case WM_HSCROLL : + { + if ((HWND)lParam == ::GetDlgItem(_hSelf, IDC_SC_PERCENTAGE_SLIDER)) + { + int percent = ::SendDlgItemMessage(_hSelf, IDC_SC_PERCENTAGE_SLIDER, TBM_GETPOS, 0, 0); + (NppParameters::getInstance())->SetTransparent(_hSelf, percent); + } + return TRUE; + } + + case WM_COMMAND : + { + if (HIWORD(wParam) == EN_CHANGE) + { + int editID = LOWORD(wParam); + if (editID == IDC_USER_KEYWORDS_EDIT) + { + updateUserKeywords(); + notifyDataModified(); + apply(); + } + else if (editID == IDC_USER_EXT_EDIT) + { + updateExtension(); + notifyDataModified(); + } + } + else + { + switch (wParam) + { + case IDC_BOLD_CHECK : + updateFontStyleStatus(BOLD_STATUS); + notifyDataModified(); + apply(); + break; + + case IDC_ITALIC_CHECK : + updateFontStyleStatus(ITALIC_STATUS); + notifyDataModified(); + apply(); + break; + + case IDC_UNDERLINE_CHECK : + updateFontStyleStatus(UNDERLINE_STATUS); + notifyDataModified(); + apply(); + break; + + case IDCANCEL : + //::MessageBox(NULL, TEXT("cancel"), TEXT(""), MB_OK); + if (_isDirty) + { + NppParameters *nppParamInst = NppParameters::getInstance(); + if (_restoreInvalid) + { + generic_string str( nppParamInst->getNppGUI()._themeName ); + nppParamInst->reloadStylers( &str[0] ); + } + + LexerStylerArray & lsArray = nppParamInst->getLStylerArray(); + StyleArray & globalStyles = nppParamInst->getGlobalStylers(); + + if (_restoreInvalid) + { + _lsArray = _styles2restored = lsArray; + _globalStyles = _gstyles2restored = globalStyles; + } + else + { + globalStyles = _globalStyles = _gstyles2restored; + lsArray = _lsArray = _styles2restored; + } + + restoreGlobalOverrideValues(); + + _restoreInvalid = false; + _isDirty = false; + _isThemeDirty = false; + setVisualFromStyleList(); + + + //(nppParamInst->getNppGUI())._themeName + ::SendMessage(_hSwitch2ThemeCombo, CB_SETCURSEL, _currentThemeIndex, 0); + ::SendMessage(_hParent, WM_UPDATESCINTILLAS, 0, 0); + } + ::EnableWindow(::GetDlgItem(_hSelf, IDC_SAVECLOSE_BUTTON), FALSE/*!_isSync*/); + display(false); + return TRUE; + + case IDC_SAVECLOSE_BUTTON : + { + if (_isDirty) + { + LexerStylerArray & lsa = (NppParameters::getInstance())->getLStylerArray(); + StyleArray & globalStyles = (NppParameters::getInstance())->getGlobalStylers(); + + _lsArray = lsa; + _globalStyles = globalStyles; + updateThemeName(_themeName); + _restoreInvalid = false; + + _currentThemeIndex = ::SendMessage(_hSwitch2ThemeCombo, CB_GETCURSEL, 0, 0); + ::EnableWindow(::GetDlgItem(_hSelf, IDOK), FALSE); + _isDirty = false; + } + _isThemeDirty = false; + (NppParameters::getInstance())->writeStyles(_lsArray, _globalStyles); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_SAVECLOSE_BUTTON), FALSE); + //_isSync = true; + display(false); + ::SendMessage(_hParent, WM_UPDATESCINTILLAS, 0, 0); + return TRUE; + } + + case IDC_SC_TRANSPARENT_CHECK : + { + bool isChecked = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_SC_TRANSPARENT_CHECK, BM_GETCHECK, 0, 0)); + if (isChecked) + { + int percent = ::SendDlgItemMessage(_hSelf, IDC_SC_PERCENTAGE_SLIDER, TBM_GETPOS, 0, 0); + (NppParameters::getInstance())->SetTransparent(_hSelf, percent); + } + else + (NppParameters::getInstance())->removeTransparent(_hSelf); + + ::EnableWindow(::GetDlgItem(_hSelf, IDC_SC_PERCENTAGE_SLIDER), isChecked); + return TRUE; + } + + case IDC_GLOBAL_FG_CHECK : + { + GlobalOverride & glo = (NppParameters::getInstance())->getGlobalOverrideStyle(); + glo.enableFg = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, wParam, BM_GETCHECK, 0, 0)); + notifyDataModified(); + apply(); + return TRUE; + } + + case IDC_GLOBAL_BG_CHECK: + { + GlobalOverride & glo = (NppParameters::getInstance())->getGlobalOverrideStyle(); + glo.enableBg = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, wParam, BM_GETCHECK, 0, 0)); + notifyDataModified(); + apply(); + return TRUE; + } + + case IDC_GLOBAL_FONT_CHECK : + { + GlobalOverride & glo = (NppParameters::getInstance())->getGlobalOverrideStyle(); + glo.enableFont = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, wParam, BM_GETCHECK, 0, 0)); + notifyDataModified(); + apply(); + return TRUE; + } + case IDC_GLOBAL_FONTSIZE_CHECK : + { + GlobalOverride & glo = (NppParameters::getInstance())->getGlobalOverrideStyle(); + glo.enableFontSize = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, wParam, BM_GETCHECK, 0, 0)); + notifyDataModified(); + apply(); + return TRUE; + } + case IDC_GLOBAL_BOLD_CHECK : + { + GlobalOverride & glo = (NppParameters::getInstance())->getGlobalOverrideStyle(); + glo.enableBold = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, wParam, BM_GETCHECK, 0, 0)); + notifyDataModified(); + apply(); + return TRUE; + } + + case IDC_GLOBAL_ITALIC_CHECK : + { + GlobalOverride & glo = (NppParameters::getInstance())->getGlobalOverrideStyle(); + glo.enableItalic = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, wParam, BM_GETCHECK, 0, 0)); + notifyDataModified(); + apply(); + return TRUE; + } + case IDC_GLOBAL_UNDERLINE_CHECK : + { + GlobalOverride & glo = (NppParameters::getInstance())->getGlobalOverrideStyle(); + glo.enableUnderLine = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, wParam, BM_GETCHECK, 0, 0)); + notifyDataModified(); + apply(); + return TRUE; + } + + default: + switch (HIWORD(wParam)) + { + case CBN_SELCHANGE : // == case LBN_SELCHANGE : + { + switch (LOWORD(wParam)) + { + case IDC_FONT_COMBO : + updateFontName(); + notifyDataModified(); + apply(); + break; + case IDC_FONTSIZE_COMBO : + updateFontSize(); + notifyDataModified(); + apply(); + break; + case IDC_LANGUAGES_LIST : + { + int i = ::SendDlgItemMessage(_hSelf, LOWORD(wParam), LB_GETCURSEL, 0, 0); + if (i != LB_ERR) + { + bool prevThemeState = _isThemeDirty; + setStyleListFromLexer(i); + _isThemeDirty = prevThemeState; + } + break; + } + case IDC_STYLES_LIST : + setVisualFromStyleList(); + break; + + case IDC_SWITCH2THEME_COMBO : + switchToTheme(); + setVisualFromStyleList(); + notifyDataModified(); + _isThemeDirty = false; + apply(); + break; + } + return TRUE; + } + + case CPN_COLOURPICKED: + { + if ((HWND)lParam == _pFgColour->getHSelf()) + { + updateColour(C_FOREGROUND); + notifyDataModified(); + int tabColourIndex; + if ((tabColourIndex = whichTabColourIndex()) != -1) + { + //::SendMessage(_hParent, WM_UPDATETABBARCOLOUR, tabColourIndex, _pFgColour->getColour()); + TabBarPlus::setColour(_pFgColour->getColour(), (TabBarPlus::tabColourIndex)tabColourIndex); + return TRUE; + } + apply(); + return TRUE; + } + else if ((HWND)lParam == _pBgColour->getHSelf()) + { + updateColour(C_BACKGROUND); + notifyDataModified(); + int tabColourIndex; + if ((tabColourIndex = whichTabColourIndex()) != -1) + { + tabColourIndex = (int)tabColourIndex == TabBarPlus::inactiveText? TabBarPlus::inactiveBg : tabColourIndex; + TabBarPlus::setColour(_pBgColour->getColour(), (TabBarPlus::tabColourIndex)tabColourIndex); + return TRUE; + } + + apply(); + return TRUE; + } + else + return FALSE; + } + + default : + { + return FALSE; + } + } + return TRUE; + } + } + + } + default : + return FALSE; + } + return FALSE; +} + +void WordStyleDlg::loadLangListFromNppParam() +{ + NppParameters *nppParamInst = NppParameters::getInstance(); + _lsArray = nppParamInst->getLStylerArray(); + _globalStyles = nppParamInst->getGlobalStylers(); + + // Clean up Language List + ::SendDlgItemMessage(_hSelf, IDC_LANGUAGES_LIST, LB_RESETCONTENT, 0, 0); + + ::SendDlgItemMessage(_hSelf, IDC_LANGUAGES_LIST, LB_ADDSTRING, 0, (LPARAM)TEXT("Global Styles")); + // All the lexers + for (int i = 0 ; i < _lsArray.getNbLexer() ; i++) + { + ::SendDlgItemMessage(_hSelf, IDC_LANGUAGES_LIST, LB_ADDSTRING, 0, (LPARAM)_lsArray.getLexerDescFromIndex(i)); + } + + const int index2Begin = 0; + ::SendDlgItemMessage(_hSelf, IDC_LANGUAGES_LIST, LB_SETCURSEL, 0, index2Begin); + setStyleListFromLexer(index2Begin); +} + +void WordStyleDlg::updateThemeName(generic_string themeName) +{ + NppParameters *pNppParam = NppParameters::getInstance(); + NppGUI & nppGUI = (NppGUI & )pNppParam->getNppGUI(); + nppGUI._themeName.assign( themeName ); +} + +void WordStyleDlg::updateColour(bool which) +{ + Style & style = getCurrentStyler(); + if (which == C_FOREGROUND) + { + style._fgColor = _pFgColour->getColour(); + if (_pFgColour->isEnabled()) + style._colorStyle |= COLORSTYLE_FOREGROUND; + else + style._colorStyle &= ~COLORSTYLE_FOREGROUND; + } + else //(which == C_BACKGROUND) + { + style._bgColor = _pBgColour->getColour(); + if (_pBgColour->isEnabled()) + style._colorStyle |= COLORSTYLE_BACKGROUND; + else + style._colorStyle &= ~COLORSTYLE_BACKGROUND; + } +} + +void WordStyleDlg::updateFontSize() +{ + Style & style = getCurrentStyler(); + int iFontSizeSel = ::SendMessage(_hFontSizeCombo, CB_GETCURSEL, 0, 0); + + TCHAR intStr[5]; + if (iFontSizeSel != 0) + { + ::SendMessage(_hFontSizeCombo, CB_GETLBTEXT, iFontSizeSel, (LPARAM)intStr); + if ((!intStr) || (!intStr[0])) + style._fontSize = -1; + else + { + TCHAR *finStr; + style._fontSize = generic_strtol(intStr, &finStr, 10); + if (*finStr != '\0') + style._fontSize = -1; + } + } + else + style._fontSize = 0; +} + +void WordStyleDlg::updateExtension() +{ + const int NB_MAX = 256; + TCHAR ext[NB_MAX]; + ::SendDlgItemMessage(_hSelf, IDC_USER_EXT_EDIT, WM_GETTEXT, NB_MAX, (LPARAM)ext); + _lsArray.getLexerFromIndex(_currentLexerIndex - 1).setLexerUserExt(ext); +} + +void WordStyleDlg::updateUserKeywords() +{ + Style & style = getCurrentStyler(); + //const int NB_MAX = 2048; + //TCHAR kw[NB_MAX]; + int len = ::SendDlgItemMessage(_hSelf, IDC_USER_KEYWORDS_EDIT, WM_GETTEXTLENGTH, 0, 0); + len +=1; + TCHAR *kw = new TCHAR[len]; + ::SendDlgItemMessage(_hSelf, IDC_USER_KEYWORDS_EDIT, WM_GETTEXT, len, (LPARAM)kw); + style.setKeywords(kw); + + delete [] kw; +} + +void WordStyleDlg::updateFontName() +{ + Style & style = getCurrentStyler(); + int iFontSel = ::SendMessage(_hFontNameCombo, CB_GETCURSEL, 0, 0); + TCHAR *fnStr = (TCHAR *)::SendMessage(_hFontNameCombo, CB_GETITEMDATA, iFontSel, 0); + style._fontName = fnStr; +} + +void WordStyleDlg::updateFontStyleStatus(fontStyleType whitchStyle) +{ + Style & style = getCurrentStyler(); + if (style._fontStyle == -1) + style._fontStyle = 0; + + int fontStyle = FONTSTYLE_UNDERLINE; + HWND hWnd = _hCheckUnderline; + + if (whitchStyle == BOLD_STATUS) + { + fontStyle = FONTSTYLE_BOLD; + hWnd = _hCheckBold; + } + if (whitchStyle == ITALIC_STATUS) + { + fontStyle = FONTSTYLE_ITALIC; + hWnd = _hCheckItalic; + } + + int isChecked = ::SendMessage(hWnd, BM_GETCHECK, 0, 0); + if (isChecked != BST_INDETERMINATE) + { + if (isChecked == BST_CHECKED) + style._fontStyle |= fontStyle; + else + style._fontStyle &= ~fontStyle; + } +} + +void WordStyleDlg::switchToTheme() +{ + int iSel = ::SendMessage(_hSwitch2ThemeCombo, CB_GETCURSEL, 0, 0); + + generic_string prevThemeName(_themeName); + _themeName.clear(); + _themeName.assign( (TCHAR *)::SendMessage(_hSwitch2ThemeCombo, CB_GETITEMDATA, iSel, 0) ); + + //if (!_themeName.compare(prevThemeName) ) return; + + if ( _isThemeDirty ) { + TCHAR themeFileName[MAX_PATH]; + lstrcpy(themeFileName, prevThemeName.c_str()); + PathStripPath( themeFileName ); + PathRemoveExtension( themeFileName ); + int mb_response = + ::MessageBox( _hSelf, + TEXT(" Unsaved changes are about to be discarded!\n") + TEXT(" Do you want to save your changes before switching themes?"), + themeFileName, + MB_ICONWARNING | MB_YESNO | MB_APPLMODAL | MB_SETFOREGROUND ); + if ( mb_response == IDYES ) (NppParameters::getInstance())->writeStyles(_lsArray, _globalStyles); + } + + + NppParameters *nppParamInst = NppParameters::getInstance(); + nppParamInst->reloadStylers(&_themeName[0]); + + loadLangListFromNppParam(); + _restoreInvalid = true; + +} + +void WordStyleDlg::setStyleListFromLexer(int index) +{ + _currentLexerIndex = index; + + // Fill out Styles listbox + // Before filling out, we clean it + ::SendDlgItemMessage(_hSelf, IDC_STYLES_LIST, LB_RESETCONTENT, 0, 0); + + if (index) + { + const TCHAR *langName = _lsArray.getLexerNameFromIndex(index - 1); + const TCHAR *ext = NppParameters::getInstance()->getLangExtFromName(langName); + const TCHAR *userExt = (_lsArray.getLexerStylerByName(langName))->getLexerUserExt(); + ::SendDlgItemMessage(_hSelf, IDC_DEF_EXT_EDIT, WM_SETTEXT, 0, (LPARAM)(ext)); + ::SendDlgItemMessage(_hSelf, IDC_USER_EXT_EDIT, WM_SETTEXT, 0, (LPARAM)(userExt)); + } + ::ShowWindow(::GetDlgItem(_hSelf, IDC_DEF_EXT_EDIT), index?SW_SHOW:SW_HIDE); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_DEF_EXT_STATIC), index?SW_SHOW:SW_HIDE); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_USER_EXT_EDIT), index?SW_SHOW:SW_HIDE); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_USER_EXT_STATIC), index?SW_SHOW:SW_HIDE); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_PLUSSYMBOL2_STATIC), index?SW_SHOW:SW_HIDE); + + StyleArray & lexerStyler = index?_lsArray.getLexerFromIndex(index-1):_globalStyles; + + for (int i = 0 ; i < lexerStyler.getNbStyler() ; i++) + { + Style & style = lexerStyler.getStyler(i); + ::SendDlgItemMessage(_hSelf, IDC_STYLES_LIST, LB_ADDSTRING, 0, (LPARAM)style._styleDesc); + } + ::SendDlgItemMessage(_hSelf, IDC_STYLES_LIST, LB_SETCURSEL, 0, 0); + setVisualFromStyleList(); +} + +void WordStyleDlg::setVisualFromStyleList() +{ + showGlobalOverrideCtrls(false); + + Style & style = getCurrentStyler(); + + // Global override style + if (lstrcmp(style._styleDesc, TEXT("Global override")) == 0) + { + showGlobalOverrideCtrls(true); + } + + //--Warning text + //bool showWarning = ((_currentLexerIndex == 0) && (style._styleID == STYLE_DEFAULT));//?SW_SHOW:SW_HIDE; + + COLORREF c = c = RGB(0x00, 0x00, 0xFF); + TCHAR str[256]; + + str[0] = '\0'; + + int i = ::SendDlgItemMessage(_hSelf, IDC_LANGUAGES_LIST, LB_GETCURSEL, 0, 0); + if (i == LB_ERR) + return; + ::SendDlgItemMessage(_hSelf, IDC_LANGUAGES_LIST, LB_GETTEXT, i, (LPARAM)str); + + i = ::SendDlgItemMessage(_hSelf, IDC_STYLES_LIST, LB_GETCURSEL, 0, 0); + if (i == LB_ERR) + return; + TCHAR styleName[64]; + ::SendDlgItemMessage(_hSelf, IDC_STYLES_LIST, LB_GETTEXT, i, (LPARAM)styleName); + + lstrcat(lstrcat(str, TEXT(" : ")), styleName); + + // PAD for fix a display glitch + lstrcat(str, TEXT(" ")); + colourHooker.setColour(c); + ::SetWindowText(_hStyleInfoStaticText, str); + + //-- 2 couleurs : fg et bg + bool isEnable = false; + if (HIBYTE(HIWORD(style._fgColor)) != 0xFF) + { + _pFgColour->setColour(style._fgColor); + _pFgColour->setEnabled((style._colorStyle & COLORSTYLE_FOREGROUND) != 0); + isEnable = true; + } + enableFg(isEnable); + + isEnable = false; + if (HIBYTE(HIWORD(style._bgColor)) != 0xFF) + { + _pBgColour->setColour(style._bgColor); + _pBgColour->setEnabled((style._colorStyle & COLORSTYLE_BACKGROUND) != 0); + isEnable = true; + } + enableBg(isEnable); + + //-- font name + isEnable = false; + int iFontName; + if (style._fontName != NULL) + { + iFontName = ::SendMessage(_hFontNameCombo, CB_FINDSTRING, 1, (LPARAM)style._fontName); + if (iFontName == CB_ERR) + iFontName = 0; + isEnable = true; + } + else + { + iFontName = 0; + } + ::SendMessage(_hFontNameCombo, CB_SETCURSEL, iFontName, 0); + enableFontName(isEnable); + + //-- font size + isEnable = false; + TCHAR intStr[5] = TEXT(""); + int iFontSize = 0; + if (style._fontSize != -1) + { + wsprintf(intStr, TEXT("%d"), style._fontSize); + iFontSize = ::SendMessage(_hFontSizeCombo, CB_FINDSTRING, 1, (LPARAM)intStr); + isEnable = true; + } + ::SendMessage(_hFontSizeCombo, CB_SETCURSEL, iFontSize, 0); + enableFontSize(isEnable); + + //-- font style : bold et italic + isEnable = false; + int isBold, isItalic, isUnderline; + if (style._fontStyle != -1) + { + isBold = (style._fontStyle & FONTSTYLE_BOLD)?BST_CHECKED:BST_UNCHECKED; + isItalic = (style._fontStyle & FONTSTYLE_ITALIC)?BST_CHECKED:BST_UNCHECKED; + isUnderline = (style._fontStyle & FONTSTYLE_UNDERLINE)?BST_CHECKED:BST_UNCHECKED; + ::SendMessage(_hCheckBold, BM_SETCHECK, isBold, 0); + ::SendMessage(_hCheckItalic, BM_SETCHECK, isItalic, 0); + ::SendMessage(_hCheckUnderline, BM_SETCHECK, isUnderline, 0); + isEnable = true; + } + else // -1 est comme 0 + { + ::SendMessage(_hCheckBold, BM_SETCHECK, BST_UNCHECKED, 0); + ::SendMessage(_hCheckItalic, BM_SETCHECK, BST_UNCHECKED, 0); + ::SendMessage(_hCheckUnderline, BM_SETCHECK, BST_UNCHECKED, 0); + } + + enableFontStyle(isEnable); + + + //-- Default Keywords + bool shouldBeDisplayed = style._keywordClass != -1; + if (shouldBeDisplayed) + { + LexerStyler & lexerStyler = _lsArray.getLexerFromIndex(_currentLexerIndex - 1); + + NppParameters *pNppParams = NppParameters::getInstance(); + LangType lType = pNppParams->getLangIDFromStr(lexerStyler.getLexerName()); + if (lType == L_TXT) + { + generic_string str = lexerStyler.getLexerName(); + str += TEXT(" is not defined in NppParameters::getLangIDFromStr()"); + printStr(str.c_str()); + } + const TCHAR *kws = pNppParams->getWordList(lType, style._keywordClass); + if (!kws) + kws = TEXT(""); + ::SendDlgItemMessage(_hSelf, IDC_DEF_KEYWORDS_EDIT, WM_SETTEXT, 0, (LPARAM)(kws)); + + const TCHAR *ckwStr = (style._keywords)?style._keywords->c_str():TEXT(""); + ::SendDlgItemMessage(_hSelf, IDC_USER_KEYWORDS_EDIT, WM_SETTEXT, 0, (LPARAM)(ckwStr)); + } + int showOption = shouldBeDisplayed?SW_SHOW:SW_HIDE; + ::ShowWindow(::GetDlgItem(_hSelf, IDC_DEF_KEYWORDS_EDIT), showOption); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_USER_KEYWORDS_EDIT),showOption); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_DEF_KEYWORDS_STATIC), showOption); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_USER_KEYWORDS_STATIC),showOption); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_PLUSSYMBOL_STATIC),showOption); + + redraw(); +} + +void WordStyleDlg::create(int dialogID, bool isRTL) +{ + StaticDialog::create(dialogID, isRTL); + + if ((NppParameters::getInstance())->isTransparentAvailable()) + { + ::ShowWindow(::GetDlgItem(_hSelf, IDC_SC_TRANSPARENT_CHECK), SW_SHOW); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_SC_PERCENTAGE_SLIDER), SW_SHOW); + + ::SendDlgItemMessage(_hSelf, IDC_SC_PERCENTAGE_SLIDER, TBM_SETRANGE, FALSE, MAKELONG(20, 200)); + ::SendDlgItemMessage(_hSelf, IDC_SC_PERCENTAGE_SLIDER, TBM_SETPOS, TRUE, 150); + if (!(BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_SC_PERCENTAGE_SLIDER, BM_GETCHECK, 0, 0))) + ::EnableWindow(::GetDlgItem(_hSelf, IDC_SC_PERCENTAGE_SLIDER), FALSE); + } +} + +void WordStyleDlg::apply() +{ + LexerStylerArray & lsa = (NppParameters::getInstance())->getLStylerArray(); + StyleArray & globalStyles = (NppParameters::getInstance())->getGlobalStylers(); + + lsa = _lsArray; + globalStyles = _globalStyles; + + ::EnableWindow(::GetDlgItem(_hSelf, IDOK), FALSE); + //_isDirty = false; + //_isSync = false; + ::SendMessage(_hParent, WM_UPDATESCINTILLAS, 0, 0); +} diff --git a/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.h b/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.h new file mode 100644 index 00000000..fd82ef45 --- /dev/null +++ b/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.h @@ -0,0 +1,249 @@ +/* +this file is part of notepad++ +Copyright (C)2003 Don HO < donho@altern.org > + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef WORD_STYLE_H +#define WORD_STYLE_H + +#include "Window.h" +#include "ColourPicker.h" +#include "StaticDialog.h" +#include "WordStyleDlgRes.h" +#include "TabBar.h" +#include "Parameters.h" +#include "resource.h" + +#define WM_UPDATESCINTILLAS (WORDSTYLE_USER + 1) //GlobalStyleDlg's msg 2 send 2 its parent + +enum fontStyleType {BOLD_STATUS, ITALIC_STATUS, UNDERLINE_STATUS}; + +const bool C_FOREGROUND = false; +const bool C_BACKGROUND = true; + + +class ColourStaticTextHooker { +public : + ColourStaticTextHooker() : _colour(RGB(0x00, 0x00, 0x00))/*, _hFont(NULL)*/ {}; + + COLORREF setColour(COLORREF colour2Set) { + COLORREF oldColour = _colour; + _colour = colour2Set; + return oldColour; + }; + void hookOn(HWND staticHandle) { + ::SetWindowLongPtr(staticHandle, GWL_USERDATA, (LONG)this); + _oldProc = (WNDPROC)::SetWindowLongPtr(staticHandle, GWL_WNDPROC, (LONG)staticProc); + }; +private : + COLORREF _colour; + WNDPROC _oldProc; + + static BOOL CALLBACK staticProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){ + ColourStaticTextHooker *pColourStaticTextHooker = reinterpret_cast(::GetWindowLongPtr(hwnd, GWL_USERDATA)); + return pColourStaticTextHooker->colourStaticProc(hwnd, message, wParam, lParam); + }; + BOOL CALLBACK colourStaticProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam); +}; + +class WordStyleDlg : public StaticDialog +{ +public : + WordStyleDlg():_isDirty(false), _isThemeDirty(false), _restoreInvalid(false), /*_isSync(true),*/ _isShownGOCtrls(false){}; + + void init(HINSTANCE hInst, HWND parent) { + Window::init(hInst, parent); + }; + + virtual void create(int dialogID, bool isRTL = false); + + void doDialog(bool isRTL = false) { + if (!isCreated()) + { + create(IDD_STYLER_DLG, isRTL); + prepare2Cancel(); + } + + if (!::IsWindowVisible(_hSelf)) + { + prepare2Cancel(); + } + display(); + }; + + + + void prepare2Cancel() { + _styles2restored = (NppParameters::getInstance())->getLStylerArray(); + _gstyles2restored = (NppParameters::getInstance())->getGlobalStylers(); + _gOverride2restored = (NppParameters::getInstance())->getGlobalOverrideStyle(); + }; + + virtual void redraw() const { + _pFgColour->redraw(); + _pBgColour->redraw(); + ::InvalidateRect(_hStyleInfoStaticText, NULL, TRUE); + ::UpdateWindow(_hStyleInfoStaticText); + }; + + void restoreGlobalOverrideValues() { + GlobalOverride & gOverride = (NppParameters::getInstance())->getGlobalOverrideStyle(); + gOverride = _gOverride2restored; + }; + + void apply(); + + + +private : + ColourPicker *_pFgColour; + ColourPicker *_pBgColour; + + int _currentLexerIndex; + int _currentThemeIndex; + + HWND _hCheckBold; + HWND _hCheckItalic; + HWND _hCheckUnderline; + HWND _hFontNameCombo; + HWND _hFontSizeCombo; + HWND _hSwitch2ThemeCombo; + + HWND _hFgColourStaticText; + HWND _hBgColourStaticText; + HWND _hFontNameStaticText; + HWND _hFontSizeStaticText; + HWND _hStyleInfoStaticText; + //TCHAR _originalWarning[256]; + + LexerStylerArray _lsArray; + StyleArray _globalStyles; + generic_string _themeName; + + LexerStylerArray _styles2restored; + StyleArray _gstyles2restored; + GlobalOverride _gOverride2restored; + bool _restoreInvalid; + + ColourStaticTextHooker colourHooker; + + bool _isDirty; + bool _isThemeDirty; + //bool _isSync; + bool _isShownGOCtrls; + + BOOL CALLBACK run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam); + + + Style & getCurrentStyler() { + int styleIndex = ::SendDlgItemMessage(_hSelf, IDC_STYLES_LIST, LB_GETCURSEL, 0, 0); + if (_currentLexerIndex == 0) + return _globalStyles.getStyler(styleIndex); + else + { + LexerStyler & lexerStyler = _lsArray.getLexerFromIndex(_currentLexerIndex - 1); + return lexerStyler.getStyler(styleIndex); + } + }; + + int whichTabColourIndex() { + int i = ::SendDlgItemMessage(_hSelf, IDC_STYLES_LIST, LB_GETCURSEL, 0, 0); + if (i == LB_ERR) + return -1; + TCHAR styleName[128]; + ::SendDlgItemMessage(_hSelf, IDC_STYLES_LIST, LB_GETTEXT, i, (LPARAM)styleName); + + if (lstrcmp(styleName, TABBAR_ACTIVEFOCUSEDINDCATOR) == 0) + return (int)TabBarPlus::activeFocusedTop; + + if (lstrcmp(styleName, TABBAR_ACTIVEUNFOCUSEDINDCATOR) == 0) + return (int)TabBarPlus::activeUnfocusedTop; + + if (lstrcmp(styleName, TABBAR_ACTIVETEXT) == 0) + return (int)TabBarPlus::activeText; + + if (lstrcmp(styleName, TABBAR_INACTIVETEXT) == 0) + return (int)TabBarPlus::inactiveText; + + return -1; + }; + + void updateColour(bool which); + void updateFontStyleStatus(fontStyleType whitchStyle); + void updateExtension(); + void updateFontName(); + void updateFontSize(); + void updateUserKeywords(); + void switchToTheme(); + void updateThemeName(generic_string themeName); + + void loadLangListFromNppParam(); + + void enableFg(bool isEnable) { + ::EnableWindow(_pFgColour->getHSelf(), isEnable); + ::EnableWindow(_hFgColourStaticText, isEnable); + }; + + void enableBg(bool isEnable) { + ::EnableWindow(_pBgColour->getHSelf(), isEnable); + ::EnableWindow(_hBgColourStaticText, isEnable); + }; + + void enableFontName(bool isEnable) { + ::EnableWindow(_hFontNameCombo, isEnable); + ::EnableWindow(_hFontNameStaticText, isEnable); + }; + + void enableFontSize(bool isEnable) { + ::EnableWindow(_hFontSizeCombo, isEnable); + ::EnableWindow(_hFontSizeStaticText, isEnable); + }; + + void enableFontStyle(bool isEnable) { + ::EnableWindow(_hCheckBold, isEnable); + ::EnableWindow(_hCheckItalic, isEnable); + ::EnableWindow(_hCheckUnderline, isEnable); + }; + long notifyDataModified() { + _isDirty = true; + _isThemeDirty = true; + ::EnableWindow(::GetDlgItem(_hSelf, IDC_SAVECLOSE_BUTTON), TRUE); + return TRUE; + } + void setStyleListFromLexer(int index); + void setVisualFromStyleList(); + + void updateGlobalOverrideCtrls(); + + void showGlobalOverrideCtrls(bool show) + { + if (show) + { + updateGlobalOverrideCtrls(); + } + ::ShowWindow(::GetDlgItem(_hSelf, IDC_GLOBAL_FG_CHECK), show?SW_SHOW:SW_HIDE); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_GLOBAL_BG_CHECK), show?SW_SHOW:SW_HIDE); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_GLOBAL_FONT_CHECK), show?SW_SHOW:SW_HIDE); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_GLOBAL_FONTSIZE_CHECK), show?SW_SHOW:SW_HIDE); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_GLOBAL_BOLD_CHECK), show?SW_SHOW:SW_HIDE); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_GLOBAL_ITALIC_CHECK), show?SW_SHOW:SW_HIDE); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_GLOBAL_UNDERLINE_CHECK), show?SW_SHOW:SW_HIDE); + _isShownGOCtrls = show; + } +}; + +#endif //WORD_STYLE_H diff --git a/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.rc b/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.rc new file mode 100644 index 00000000..206f04c9 --- /dev/null +++ b/PowerEditor/src/WinControls/ColourPicker/WordStyleDlg.rc @@ -0,0 +1,82 @@ +/* +this file is part of notepad++ +Copyright (C)2003 Don HO < donho@altern.org > + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "windows.h" +#include "wordstyledlgres.h" + +#ifndef IDC_STATIC +#define IDC_STATIC -1 +#endif + +IDD_STYLER_DLG DIALOGEX 36, 44, 500, 246 +STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU +EXSTYLE WS_EX_TOOLWINDOW +CAPTION "Style Configurator" +FONT 8, "MS Shell Dlg", 0, 0, 0x0 +BEGIN + LTEXT "Switch to theme : ",IDC_SWITCH2THEME_STATIC,6,9,83,8,0,WS_EX_RIGHT + COMBOBOX IDC_SWITCH2THEME_COMBO,95,7,104,78,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | CBS_SORT | WS_VSCROLL | WS_TABSTOP + LTEXT "Foreground color",IDC_FG_STATIC,203,72,59,8,0,WS_EX_RIGHT + LTEXT "Background color",IDC_BG_STATIC,203,99,59,8,0,WS_EX_RIGHT + COMBOBOX IDC_FONT_COMBO,371,68,104,78,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | CBS_SORT | WS_VSCROLL | WS_TABSTOP + COMBOBOX IDC_FONTSIZE_COMBO,442,95,33,82,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + CONTROL "Bold",IDC_BOLD_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,327,88,63,10 + CONTROL "Italic",IDC_ITALIC_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,327,100,62,10 + GROUPBOX "Font style",IDC_FONTGROUP_STATIC,311,52,169,77 + GROUPBOX "Colour style",IDC_COLOURGROUP_STATIC,191,52,111,77 + LTEXT "Font Name :",IDC_FONTNAME_STATIC,315,71,52,8,0,WS_EX_RIGHT + LTEXT "Font size :",IDC_FONTSIZE_STATIC,388,97,51,8,0,WS_EX_RIGHT + LTEXT "Style :",IDC_STYLEDESC_STATIC,87,34,68,8 + LTEXT " ",IDC_STYLEDESCRIPTION_STATIC,190,30,295,22 + EDITTEXT IDC_DEF_EXT_EDIT,17,215,61,14,ES_AUTOHSCROLL | ES_READONLY + LTEXT "Default ext : ",IDC_DEF_EXT_STATIC,20,203,61,8 + EDITTEXT IDC_USER_EXT_EDIT,93,215,71,14,ES_AUTOHSCROLL + LTEXT "User ext :",IDC_USER_EXT_STATIC,95,204,71,8 + CONTROL "Underline",IDC_UNDERLINE_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,327,112,80,10 + EDITTEXT IDC_DEF_KEYWORDS_EDIT,191,151,136,43,ES_MULTILINE | ES_READONLY | WS_VSCROLL + EDITTEXT IDC_USER_KEYWORDS_EDIT,347,150,134,43,ES_MULTILINE | WS_VSCROLL + LTEXT "Default keywords",IDC_DEF_KEYWORDS_STATIC,193,141,122,8 + LTEXT "User Define keywords",IDC_USER_KEYWORDS_STATIC,349,140,126,8 + LTEXT "+",IDC_PLUSSYMBOL_STATIC,335,166,8,8 + PUSHBUTTON "Cancel",IDCANCEL,332,222,57,14 + PUSHBUTTON "Save && Close",IDC_SAVECLOSE_BUTTON,255,222,69,14 + CONTROL "",IDC_SC_PERCENTAGE_SLIDER,"msctls_trackbar32",TBS_BOTH | TBS_NOTICKS | NOT WS_VISIBLE | WS_TABSTOP,441,235,53,10 + CONTROL "Transparency",IDC_SC_TRANSPARENT_CHECK,"Button",BS_AUTOCHECKBOX | NOT WS_VISIBLE | WS_TABSTOP,431,221,63,10 + LISTBOX IDC_LANGUAGES_LIST,17,46,59,146,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP + LISTBOX IDC_STYLES_LIST,87,46,76,146,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_HSCROLL | WS_TABSTOP + GROUPBOX "",IDC_STATIC,7,24,166,212 + LTEXT "Language :",IDC_LANGDESC_STATIC,19,34,61,8 + GROUPBOX "",IDC_STATIC,181,24,310,184 + LTEXT "+",IDC_PLUSSYMBOL2_STATIC,83,217,8,8 + CONTROL "Enable global foreground color",IDC_GLOBAL_FG_CHECK, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,191,138,132,10 + CONTROL "Enable global background color",IDC_GLOBAL_BG_CHECK, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,191,153,131,10 + CONTROL "Enable global font",IDC_GLOBAL_FONT_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,327,134,153,10 + CONTROL "Enable global font size",IDC_GLOBAL_FONTSIZE_CHECK, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,327,149,135,10 + CONTROL "Enable global bold font style",IDC_GLOBAL_BOLD_CHECK, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,328,164,135,10 + CONTROL "Enable global Italic font style",IDC_GLOBAL_ITALIC_CHECK, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,328,179,135,10 + CONTROL "Enable global underline font style",IDC_GLOBAL_UNDERLINE_CHECK, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,328,194,135,10 + +END + diff --git a/PowerEditor/src/WinControls/ColourPicker/WordStyleDlgRes.h b/PowerEditor/src/WinControls/ColourPicker/WordStyleDlgRes.h new file mode 100644 index 00000000..bb624a07 --- /dev/null +++ b/PowerEditor/src/WinControls/ColourPicker/WordStyleDlgRes.h @@ -0,0 +1,65 @@ +/* +this file is part of notepad++ +Copyright (C)2003 Don HO < donho@altern.org > + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#define IDD_STYLER_DLG 2200 + + //#define IDC_STYLETYPE_COMBO (IDD_STYLER_DLG + 1) + #define IDC_FONT_COMBO (IDD_STYLER_DLG + 2) + #define IDC_FONTSIZE_COMBO (IDD_STYLER_DLG + 3) + #define IDC_BOLD_CHECK (IDD_STYLER_DLG + 4) + #define IDC_ITALIC_CHECK (IDD_STYLER_DLG + 5) + #define IDC_FG_STATIC (IDD_STYLER_DLG + 6) + #define IDC_BG_STATIC (IDD_STYLER_DLG + 7) + #define IDC_FONTNAME_STATIC (IDD_STYLER_DLG + 8) + #define IDC_FONTSIZE_STATIC (IDD_STYLER_DLG + 9) + //#define IDC_STYLEDEFAULT_WARNING_STATIC (IDD_STYLER_DLG + 10) for the sake of compablity of traslation xml files, this number (2210) don't be use anymore by Notepad++ + #define IDC_STYLEDESC_STATIC (IDD_STYLER_DLG + 11) + #define IDC_COLOURGROUP_STATIC (IDD_STYLER_DLG + 12) + #define IDC_FONTGROUP_STATIC (IDD_STYLER_DLG + 13) + + #define IDC_DEF_EXT_STATIC (IDD_STYLER_DLG + 14) + #define IDC_DEF_EXT_EDIT (IDD_STYLER_DLG + 15) + #define IDC_USER_EXT_STATIC (IDD_STYLER_DLG + 16) + #define IDC_USER_EXT_EDIT (IDD_STYLER_DLG + 17) + #define IDC_UNDERLINE_CHECK (IDD_STYLER_DLG + 18) + #define IDC_DEF_KEYWORDS_STATIC (IDD_STYLER_DLG + 19) + #define IDC_DEF_KEYWORDS_EDIT (IDD_STYLER_DLG + 20) + #define IDC_USER_KEYWORDS_STATIC (IDD_STYLER_DLG + 21) + #define IDC_USER_KEYWORDS_EDIT (IDD_STYLER_DLG + 22) + #define IDC_PLUSSYMBOL_STATIC (IDD_STYLER_DLG + 23) + #define IDC_PLUSSYMBOL2_STATIC (IDD_STYLER_DLG + 24) + #define IDC_LANGDESC_STATIC (IDD_STYLER_DLG + 25) + + #define IDC_GLOBAL_FG_CHECK (IDD_STYLER_DLG + 26) + #define IDC_GLOBAL_BG_CHECK (IDD_STYLER_DLG + 27) + #define IDC_GLOBAL_FONT_CHECK (IDD_STYLER_DLG + 28) + #define IDC_GLOBAL_FONTSIZE_CHECK (IDD_STYLER_DLG + 29) + #define IDC_GLOBAL_BOLD_CHECK (IDD_STYLER_DLG + 30) + #define IDC_GLOBAL_ITALIC_CHECK (IDD_STYLER_DLG + 31) + #define IDC_GLOBAL_UNDERLINE_CHECK (IDD_STYLER_DLG + 32) + #define IDC_STYLEDESCRIPTION_STATIC (IDD_STYLER_DLG + 33) + +# define IDD_GLOBAL_STYLER_DLG 2300 + #define IDC_SAVECLOSE_BUTTON (IDD_GLOBAL_STYLER_DLG + 1) + #define IDC_SC_PERCENTAGE_SLIDER (IDD_GLOBAL_STYLER_DLG + 2) + #define IDC_SC_TRANSPARENT_CHECK (IDD_GLOBAL_STYLER_DLG + 3) + #define IDC_LANGUAGES_LIST (IDD_GLOBAL_STYLER_DLG + 4) + #define IDC_STYLES_LIST (IDD_GLOBAL_STYLER_DLG + 5) + #define IDC_SWITCH2THEME_STATIC (IDD_GLOBAL_STYLER_DLG + 6) + #define IDC_SWITCH2THEME_COMBO (IDD_GLOBAL_STYLER_DLG + 7) diff --git a/PowerEditor/src/WinControls/ContextMenu/ContextMenu.h b/PowerEditor/src/WinControls/ContextMenu/ContextMenu.h new file mode 100644 index 00000000..12aca7ae --- /dev/null +++ b/PowerEditor/src/WinControls/ContextMenu/ContextMenu.h @@ -0,0 +1,82 @@ +/* +this file is part of notepad++ +Copyright (C)2003 Don HO ( donho@altern.org ) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef CONTEXTMENU +#define CONTEXTMENU + +#include +#include + +using namespace std; + +struct MenuItemUnit { + unsigned long _cmdID; + generic_string _itemName; + MenuItemUnit() : _cmdID(0), _itemName(TEXT("")) {}; + MenuItemUnit(unsigned long cmdID, generic_string itemName) : _cmdID(cmdID), _itemName(itemName) {}; + MenuItemUnit(unsigned long cmdID, const TCHAR *itemName) : _cmdID(cmdID){ + if (!itemName) + _itemName = TEXT(""); + else + _itemName = itemName; + }; +}; + +class ContextMenu { +public: + ContextMenu() : _hParent(NULL), _hMenu(NULL) {}; + ~ContextMenu() { + if (isCreated()) + ::DestroyMenu(_hMenu); + }; + void create(HWND hParent, const vector & menuItemArray) { + _hParent = hParent; + _hMenu = ::CreatePopupMenu(); + for (size_t i = 0 ; i < menuItemArray.size() ; i++) + { + unsigned int flag = MF_BYPOSITION | ((menuItemArray[i]._cmdID == 0)?MF_SEPARATOR:0); + ::InsertMenu(_hMenu, i, flag, menuItemArray[i]._cmdID, menuItemArray[i]._itemName.c_str()); + } + }; + bool isCreated() const {return _hMenu != NULL;}; + + void display(const POINT & p) const { + ::TrackPopupMenu(_hMenu, TPM_LEFTALIGN, p.x, p.y, 0, _hParent, NULL); + }; + + void enableItem(int cmdID, bool doEnable) const { + int flag = doEnable?MF_ENABLED | MF_BYCOMMAND:MF_DISABLED | MF_GRAYED | MF_BYCOMMAND; + ::EnableMenuItem(_hMenu, cmdID, flag); + }; + + void checkItem(int cmdID, bool doCheck) const { + ::CheckMenuItem(_hMenu, cmdID, MF_BYCOMMAND | (doCheck?MF_CHECKED:MF_UNCHECKED)); + }; + + HMENU getMenuHandle() { + return _hMenu; + }; + +private: + HWND _hParent; + HMENU _hMenu; + +}; + +#endif //CONTEXTMENU diff --git a/PowerEditor/src/WinControls/DockingWnd/CloseDown.bmp b/PowerEditor/src/WinControls/DockingWnd/CloseDown.bmp new file mode 100644 index 00000000..da11fcd4 Binary files /dev/null and b/PowerEditor/src/WinControls/DockingWnd/CloseDown.bmp differ diff --git a/PowerEditor/src/WinControls/DockingWnd/CloseUp.bmp b/PowerEditor/src/WinControls/DockingWnd/CloseUp.bmp new file mode 100644 index 00000000..42aec33c Binary files /dev/null and b/PowerEditor/src/WinControls/DockingWnd/CloseUp.bmp differ diff --git a/PowerEditor/src/WinControls/DockingWnd/Docking.h b/PowerEditor/src/WinControls/DockingWnd/Docking.h new file mode 100644 index 00000000..6e095757 --- /dev/null +++ b/PowerEditor/src/WinControls/DockingWnd/Docking.h @@ -0,0 +1,79 @@ +/* +this file is part of Function List Plugin for Notepad++ +Copyright (C)2005 Jens Lorenz + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef DOCKING_H +#define DOCKING_H + +#include "windows.h" +// ATTENTION : It's a part of interface header, so don't include the others header here + +// styles for containers +#define CAPTION_TOP TRUE +#define CAPTION_BOTTOM FALSE + +// defines for docking manager +#define CONT_LEFT 0 +#define CONT_RIGHT 1 +#define CONT_TOP 2 +#define CONT_BOTTOM 3 +#define DOCKCONT_MAX 4 + +// mask params for plugins of internal dialogs +#define DWS_ICONTAB 0x00000001 // Icon for tabs are available +#define DWS_ICONBAR 0x00000002 // Icon for icon bar are available (currently not supported) +#define DWS_ADDINFO 0x00000004 // Additional information are in use +#define DWS_PARAMSALL (DWS_ICONTAB|DWS_ICONBAR|DWS_ADDINFO) + +// default docking values for first call of plugin +#define DWS_DF_CONT_LEFT (CONT_LEFT << 28) // default docking on left +#define DWS_DF_CONT_RIGHT (CONT_RIGHT << 28) // default docking on right +#define DWS_DF_CONT_TOP (CONT_TOP << 28) // default docking on top +#define DWS_DF_CONT_BOTTOM (CONT_BOTTOM << 28) // default docking on bottom +#define DWS_DF_FLOATING 0x80000000 // default state is floating + + +typedef struct { + HWND hClient; // client Window Handle + TCHAR *pszName; // name of plugin (shown in window) + int dlgID; // a funcItem provides the function pointer to start a dialog. Please parse here these ID + + // user modifications + UINT uMask; // mask params: look to above defines + HICON hIconTab; // icon for tabs + TCHAR *pszAddInfo; // for plugin to display additional informations + + // internal data, do not use !!! + RECT rcFloat; // floating position + int iPrevCont; // stores the privious container (toggling between float and dock) + const TCHAR* pszModuleName; // it's the plugin file name. It's used to identify the plugin +} tTbData; + + +typedef struct { + HWND hWnd; // the docking manager wnd + RECT rcRegion[DOCKCONT_MAX]; // position of docked dialogs +} tDockMgr; + + +#define HIT_TEST_THICKNESS 20 + +#define SPLITTER_WIDTH 4 + + +#endif // DOCKING_H diff --git a/PowerEditor/src/WinControls/DockingWnd/DockingCont.cpp b/PowerEditor/src/WinControls/DockingWnd/DockingCont.cpp new file mode 100644 index 00000000..c9b5a869 --- /dev/null +++ b/PowerEditor/src/WinControls/DockingWnd/DockingCont.cpp @@ -0,0 +1,1408 @@ +//this file is part of docking functionality for Notepad++ +//Copyright (C)2006 Jens Lorenz +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#include "dockingResource.h" +#include "math.h" +#include "Docking.h" +#include "DockingCont.h" +#include "DropData.h" +#include "SplitterContainer.h" +#include "WindowInterface.h" +#include "ToolTip.h" +#include +#include "Parameters.h" +#include "Common.h" + +#ifndef WH_MOUSE_LL +#define WH_MOUSE_LL 14 +#endif + +static HWND hWndServer = NULL; +static HHOOK hookMouse = NULL; + +static LRESULT CALLBACK hookProcMouse(UINT nCode, WPARAM wParam, LPARAM lParam) +{ + if(nCode < 0) + { + ::CallNextHookEx(hookMouse, nCode, wParam, lParam); + return 0; + } + + switch (wParam) + { + case WM_MOUSEMOVE: + case WM_NCMOUSEMOVE: + ::PostMessage(hWndServer, wParam, 0, 0); + break; + case WM_LBUTTONUP: + case WM_NCLBUTTONUP: + ::PostMessage(hWndServer, wParam, 0, 0); + break; + default: + break; + } + + return ::CallNextHookEx(hookMouse, nCode, wParam, lParam); +} + + +DockingCont::DockingCont(void) +{ + _isMouseOver = FALSE; + _isMouseClose = FALSE; + _isMouseDown = FALSE; + _isFloating = false; + _isTopCaption = CAPTION_TOP; + _dragFromTab = FALSE; + _hContTab = NULL; + _hDefaultTabProc = NULL; + _beginDrag = FALSE; + _prevItem = 0; + _hFont = NULL; + _bTabTTHover = FALSE; + _bCaptionTT = FALSE; + _bCapTTHover = FALSE; + _hoverMPos = posClose; + _bDrawOgLine = TRUE; + _vTbData.clear(); +} + +DockingCont::~DockingCont() +{ + ::DeleteObject(_hFont); +} + + +void DockingCont::doDialog(bool willBeShown, bool isFloating) +{ + if (!isCreated()) + { + create(IDD_CONTAINER_DLG); + + _isFloating = isFloating; + + if (_isFloating) + { + ::SetWindowLongPtr(_hSelf, GWL_STYLE, POPUP_STYLES); + ::SetWindowLongPtr(_hSelf, GWL_EXSTYLE, POPUP_EXSTYLES); + ::ShowWindow(_hCaption, SW_HIDE); + } + else + { + ::SetWindowLongPtr(_hSelf, GWL_STYLE, CHILD_STYLES); + ::SetWindowLongPtr(_hSelf, GWL_EXSTYLE, CHILD_EXSTYLES); + ::ShowWindow(_hCaption, SW_SHOW); + } + + //If you want defualt GUI font + _hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT); + } + + display(willBeShown); +} + + +tTbData* DockingCont::createToolbar(tTbData data, Window **ppWin) +{ + tTbData *pTbData = new tTbData; + + *pTbData = data; + + // force window style of client window + ::SetWindowLongPtr(pTbData->hClient, GWL_STYLE, CHILD_STYLES); + ::SetWindowLongPtr(pTbData->hClient, GWL_EXSTYLE, CHILD_EXSTYLES); + + // restore position if plugin is in floating state + if ((_isFloating) && (::SendMessage(_hContTab, TCM_GETITEMCOUNT, 0, 0) == 0)) + { + reSizeToWH(pTbData->rcFloat); + } + + // set attached child window + ::SetParent(pTbData->hClient, ::GetDlgItem(_hSelf, IDC_CLIENT_TAB)); + + // set names for captions and view toolbar + viewToolbar(pTbData); + + // attach to list + _vTbData.push_back(pTbData); + + return pTbData; +} + + +void DockingCont::removeToolbar(tTbData TbData) +{ + INT iItemCnt = 0; + + // remove from list + for (size_t iTb = 0; iTb < _vTbData.size(); iTb++) + { + if (_vTbData[iTb]->hClient == TbData.hClient) + { + // remove tab + removeTab(_vTbData[iTb]); + + // free resources + delete _vTbData[iTb]; + vector::iterator itr = _vTbData.begin() + iTb; + _vTbData.erase(itr); + } + } +} + + +tTbData* DockingCont::findToolbarByWnd(HWND hClient) +{ + tTbData* pTbData = NULL; + + // find entry by handle + for (size_t iTb = 0; iTb < _vTbData.size(); iTb++) + { + if (hClient == _vTbData[iTb]->hClient) + { + pTbData = _vTbData[iTb]; + } + } + return pTbData; +} + +tTbData* DockingCont::findToolbarByName(TCHAR* pszName) +{ + tTbData* pTbData = NULL; + + // find entry by handle + for (size_t iTb = 0; iTb < _vTbData.size(); iTb++) + { + if (lstrcmp(pszName, _vTbData[iTb]->pszName) == 0) + { + pTbData = _vTbData[iTb]; + } + } + return pTbData; +} + +void DockingCont::setActiveTb(tTbData* pTbData) +{ + INT iItem = SearchPosInTab(pTbData); + setActiveTb(iItem); +} + +void DockingCont::setActiveTb(INT iItem) +{ + //if ((iItem != -1) && (iItem < ::SendMessage(_hContTab, TCM_GETITEMCOUNT, 0, 0))) + if (iItem < ::SendMessage(_hContTab, TCM_GETITEMCOUNT, 0, 0)) + { + SelectTab(iItem); + } +} + +INT DockingCont::getActiveTb(void) +{ + return ::SendMessage(_hContTab, TCM_GETCURSEL, 0, 0); +} + +tTbData* DockingCont::getDataOfActiveTb(void) +{ + tTbData* pTbData = NULL; + INT iItem = getActiveTb(); + + if (iItem != -1) + { + TCITEM tcItem = {0}; + + tcItem.mask = TCIF_PARAM; + ::SendMessage(_hContTab, TCM_GETITEM, iItem, (LPARAM)&tcItem); + pTbData = (tTbData*)tcItem.lParam; + } + + return pTbData; +} + +vector DockingCont::getDataOfVisTb(void) +{ + vector vTbData; + TCITEM tcItem = {0}; + INT iItemCnt = ::SendMessage(_hContTab, TCM_GETITEMCOUNT, 0, 0); + + tcItem.mask = TCIF_PARAM; + + for(INT iItem = 0; iItem < iItemCnt; iItem++) + { + ::SendMessage(_hContTab, TCM_GETITEM, iItem, (LPARAM)&tcItem); + vTbData.push_back((tTbData*)tcItem.lParam); + } + return vTbData; +} + +bool DockingCont::isTbVis(tTbData* data) +{ + bool bRet = false; + TCITEM tcItem = {0}; + INT iItemCnt = ::SendMessage(_hContTab, TCM_GETITEMCOUNT, 0, 0); + + tcItem.mask = TCIF_PARAM; + + for(INT iItem = 0; iItem < iItemCnt; iItem++) + { + ::SendMessage(_hContTab, TCM_GETITEM, iItem, (LPARAM)&tcItem); + if (((tTbData*)tcItem.lParam) == data) + { + bRet = true; + break; + } + } + return bRet; +} + + +// +// Process function of caption bar +// +LRESULT DockingCont::runProcCaption(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) +{ + static ToolTip toolTip; + + switch (Message) + { + case WM_LBUTTONDOWN: + { + _isMouseDown = TRUE; + + if (isInRect(hwnd, LOWORD(lParam), HIWORD(lParam)) == posClose) + { + _isMouseClose = TRUE; + _isMouseOver = TRUE; + + // start hooking + hWndServer = _hCaption; + winVer ver = (NppParameters::getInstance())->getWinVersion(); + hookMouse = ::SetWindowsHookEx(ver >= WV_W2K?WH_MOUSE_LL:WH_MOUSE, (HOOKPROC)hookProcMouse, _hInst, 0); + + if (!hookMouse) + { + DWORD dwError = ::GetLastError(); + TCHAR str[128]; + ::wsprintf(str, TEXT("GetLastError() returned %lu"), dwError); + ::MessageBox(NULL, str, TEXT("SetWindowsHookEx(MOUSE) failed"), MB_OK | MB_ICONERROR); + } + ::RedrawWindow(hwnd, NULL, NULL, TRUE); + } + + focusClient(); + return TRUE; + } + case WM_LBUTTONUP: + { + _isMouseDown = FALSE; + if (_isMouseClose == TRUE) + { + // end hooking + ::UnhookWindowsHookEx(hookMouse); + + if (_isMouseOver == TRUE) + { + doClose(); + } + _isMouseClose = FALSE; + _isMouseOver = FALSE; + } + + focusClient(); + return TRUE; + } + case WM_LBUTTONDBLCLK: + { + if (isInRect(hwnd, LOWORD(lParam), HIWORD(lParam)) == posCaption) + ::SendMessage(_hParent, DMM_FLOATALL, 0, (LPARAM)this); + + focusClient(); + return TRUE; + } + case WM_MOUSEMOVE: + { + POINT pt = {0}; + + // get correct cursor position + ::GetCursorPos(&pt); + ::ScreenToClient(_hCaption, &pt); + + if (_isMouseDown == TRUE) + { + if (_isMouseClose == FALSE) + { + // keep sure that button is still down and within caption + if ((wParam == MK_LBUTTON) && (isInRect(hwnd, pt.x, pt.y) == posCaption)) + { + _dragFromTab = FALSE; + NotifyParent(DMM_MOVE); + _isMouseDown = FALSE; + } + else + { + _isMouseDown = FALSE; + } + } + else + { + BOOL isMouseOver = _isMouseOver; + _isMouseOver = (isInRect(hwnd, pt.x, pt.y) == posClose ? TRUE : FALSE); + + // if state is changed draw new + if (_isMouseOver != isMouseOver) + { + ::SetFocus(NULL); + ::RedrawWindow(hwnd, NULL, NULL, TRUE); + } + } + } + else if (_bCapTTHover == FALSE) + { + _hoverMPos = isInRect(hwnd, LOWORD(lParam), HIWORD(lParam)); + + if ((_bCaptionTT == TRUE) || (_hoverMPos == posClose)) + { + TRACKMOUSEEVENT tme; + tme.cbSize = sizeof(tme); + tme.hwndTrack = hwnd; + tme.dwFlags = TME_LEAVE | TME_HOVER; + tme.dwHoverTime = 1000; + _bCapTTHover = _TrackMouseEvent(&tme); + } + } + else if ((_bCapTTHover == TRUE) && + (_hoverMPos != isInRect(hwnd, LOWORD(lParam), HIWORD(lParam)))) + { + toolTip.destroy(); + _bCapTTHover = FALSE; + } + return TRUE; + } + case WM_MOUSEHOVER: + { + RECT rc = {0}; + POINT pt = {0}; + + + // get mouse position + ::GetCursorPos(&pt); + + toolTip.init(_hInst, hwnd); + if (_hoverMPos == posCaption) + { + toolTip.Show(rc, _pszCaption, pt.x, pt.y + 20); + } + else + { + toolTip.Show(rc, TEXT("Close"), pt.x, pt.y + 20); + } + return TRUE; + } + case WM_MOUSELEAVE: + { + toolTip.destroy(); + _bCapTTHover = FALSE; + return TRUE; + } + case WM_SIZE: + { + ::GetWindowRect(hwnd, &_rcCaption); + ScreenRectToClientRect(hwnd, &_rcCaption); + break; + } + case WM_SETTEXT: + { + ::RedrawWindow(hwnd, NULL, NULL, TRUE); + return TRUE; + } + default: + break; + } + + return ::CallWindowProc(_hDefaultCaptionProc, hwnd, Message, wParam, lParam); +} + +void DockingCont::drawCaptionItem(DRAWITEMSTRUCT *pDrawItemStruct) +{ + HBRUSH bgbrush = NULL; + HFONT hOldFont = NULL; + RECT rc = pDrawItemStruct->rcItem; + HDC hDc = pDrawItemStruct->hDC; + HPEN hPen = ::CreatePen(PS_SOLID, 1, ::GetSysColor(COLOR_BTNSHADOW)); + BITMAP bmp = {0}; + HBITMAP hBmpCur = NULL; + HBITMAP hBmpOld = NULL; + HBITMAP hBmpNew = NULL; + UINT length = lstrlen(_pszCaption); + + INT nSavedDC = ::SaveDC(hDc); + + // begin with paint + ::SetBkMode(hDc, TRANSPARENT); + + if (_isActive == TRUE) { + bgbrush = ::CreateSolidBrush(::GetSysColor(COLOR_ACTIVECAPTION)); + ::SetTextColor(hDc, ::GetSysColor(COLOR_CAPTIONTEXT)); + } else { + bgbrush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE)); + } + + // set text and/or caption grid + if (_isTopCaption == TRUE) + { + if (_isActive == TRUE) + { + // fill background + ::FillRect(hDc, &rc, bgbrush); + rc.right -= 1; + rc.bottom -= 1; + } + else + { + // fill background + rc.right -= 1; + rc.bottom -= 1; + ::FillRect(hDc, &rc, bgbrush); + + // draw grid lines + HPEN hOldPen = (HPEN)::SelectObject(hDc, hPen); + + MoveToEx(hDc, rc.left , rc.top , NULL); + LineTo (hDc, rc.right, rc.top ); + LineTo (hDc, rc.right, rc.bottom ); + LineTo (hDc, rc.left , rc.bottom ); + LineTo (hDc, rc.left , rc.top); + } + + // draw text + rc.left += 2; + rc.top += 1; + rc.right -= 16; + hOldFont = (HFONT)::SelectObject(hDc, _hFont); + ::DrawText(hDc, _pszCaption, length, &rc, DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS | DT_NOPREFIX); + + // calculate text size and if its trankated... + SIZE size = {0}; + GetTextExtentPoint32(hDc, _pszCaption, length, &size); + _bCaptionTT = (((rc.right - rc.left) < size.cx) ? TRUE : FALSE); + + ::SelectObject(hDc, hOldFont); + } + else + { + // create local font for vertical draw + HFONT hFont; + + if (_isActive == TRUE) + { + // fill background + ::FillRect(hDc, &rc, bgbrush); + rc.right -= 1; + rc.bottom -= 1; + } + else + { + // fill background + rc.right -= 1; + rc.bottom -= 1; + ::FillRect(hDc, &rc, bgbrush); + + // draw grid lines + HPEN hOldPen = (HPEN)::SelectObject(hDc, hPen); + + MoveToEx(hDc, rc.left , rc.top , NULL); + LineTo (hDc, rc.right, rc.top ); + LineTo (hDc, rc.right, rc.bottom ); + LineTo (hDc, rc.left , rc.bottom ); + LineTo (hDc, rc.left , rc.top); + } + + // draw text + rc.left += 1; + rc.top += HIGH_CAPTION; + // to make ellipsis working + rc.right = rc.bottom - rc.top; + rc.bottom += 14; + + hFont = ::CreateFont(12, 0, 90 * 10, 0, + FW_NORMAL, FALSE, FALSE, FALSE, + ANSI_CHARSET, OUT_DEFAULT_PRECIS, + CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, + DEFAULT_PITCH | FF_ROMAN, + TEXT("MS Shell Dlg")); + + hOldFont = (HFONT)::SelectObject(hDc, hFont); + ::DrawText(hDc, _pszCaption, length, &rc, DT_BOTTOM | DT_SINGLELINE | DT_END_ELLIPSIS | DT_NOPREFIX); + + // calculate text size and if its trankated... + SIZE size = {0}; + GetTextExtentPoint32(hDc, _pszCaption, length, &size); + _bCaptionTT = (((rc.bottom - rc.top) < size.cy) ? TRUE : FALSE); + + ::SelectObject(hDc, hOldFont); + ::DeleteObject(hFont); + } + ::DeleteObject(hPen); + ::DeleteObject(bgbrush); + + // draw button + HDC dcMem = ::CreateCompatibleDC(NULL); + + // select correct bitmap + if ((_isMouseOver == TRUE) && (_isMouseDown == TRUE)) + hBmpCur = ::LoadBitmap(_hInst, MAKEINTRESOURCE(IDB_CLOSE_DOWN)); + else + hBmpCur = ::LoadBitmap(_hInst, MAKEINTRESOURCE(IDB_CLOSE_UP)); + + // blit bitmap into the destination + ::GetObject(hBmpCur, sizeof(bmp), &bmp); + hBmpOld = (HBITMAP)::SelectObject(dcMem, hBmpCur); + hBmpNew = ::CreateCompatibleBitmap(dcMem, bmp.bmWidth, bmp.bmHeight); + + rc = pDrawItemStruct->rcItem; + ::SelectObject(hDc, hBmpNew); + + if (_isTopCaption == TRUE) + ::BitBlt(hDc, rc.right-bmp.bmWidth-CLOSEBTN_POS_LEFT, CLOSEBTN_POS_TOP, bmp.bmWidth, bmp.bmHeight, dcMem, 0, 0, SRCCOPY); + else + ::BitBlt(hDc, CLOSEBTN_POS_LEFT, CLOSEBTN_POS_LEFT, bmp.bmWidth, bmp.bmHeight, dcMem, 0, 0, SRCCOPY); + + ::SelectObject(dcMem, hBmpOld); + ::DeleteObject(hBmpCur); + ::DeleteObject(hBmpNew); + ::DeleteDC(dcMem); + + ::RestoreDC(hDc, nSavedDC); +} + +eMousePos DockingCont::isInRect(HWND hwnd, INT x, INT y) +{ + RECT rc; + eMousePos ret = posOutside; + + ::GetWindowRect(hwnd, &rc); + ScreenRectToClientRect(hwnd, &rc); + + if (_isTopCaption == TRUE) + { + if ((x > rc.left) && (x < rc.right-HIGH_CAPTION) && (y > rc.top) && (y < rc.bottom)) + { + ret = posCaption; + } + else if ((x > rc.right-(12+CLOSEBTN_POS_LEFT)) && (x < (rc.right-CLOSEBTN_POS_LEFT)) && + (y > (rc.top+CLOSEBTN_POS_TOP)) && (y < (rc.bottom-CLOSEBTN_POS_TOP))) + { + ret = posClose; + } + } + else + { + if ((x > rc.left) && (x < rc.right) && (y > rc.top+HIGH_CAPTION) && (y < rc.bottom)) + { + ret = posCaption; + } + else if ((x > rc.left+CLOSEBTN_POS_LEFT) && (x < rc.right-CLOSEBTN_POS_LEFT) && + (y > (rc.top+CLOSEBTN_POS_TOP)) && (y < (rc.top+(12+CLOSEBTN_POS_LEFT)))) + { + ret = posClose; + } + } + + return ret; +} + + +//---------------------------------------------------------- +// Process function of tab +// +LRESULT DockingCont::runProcTab(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) +{ + static ToolTip toolTip; + + switch (Message) + { + case WM_LBUTTONDOWN: + { + _beginDrag = TRUE; + return TRUE; + } + case WM_LBUTTONUP: + { + INT iItem = 0; + TCHITTESTINFO info = {0}; + + // get selected sub item + info.pt.x = LOWORD(lParam); + info.pt.y = HIWORD(lParam); + iItem = ::SendMessage(hwnd, TCM_HITTEST, 0, (LPARAM)&info); + + SelectTab(iItem); + _beginDrag = FALSE; + return TRUE; + } + case WM_LBUTTONDBLCLK: + { + NotifyParent((_isFloating == true)?DMM_DOCK:DMM_FLOAT); + return TRUE; + } + case WM_MBUTTONUP: + { + INT iItem = 0; + TCITEM tcItem = {0}; + TCHITTESTINFO info = {0}; + + // get selected sub item + info.pt.x = LOWORD(lParam); + info.pt.y = HIWORD(lParam); + iItem = ::SendMessage(hwnd, TCM_HITTEST, 0, (LPARAM)&info); + + SelectTab(iItem); + + // get data and hide toolbar + tcItem.mask = TCIF_PARAM; + ::SendMessage(hwnd, TCM_GETITEM, iItem, (LPARAM)&tcItem); + + // notify child windows + if (NotifyParent(DMM_CLOSE) == 0) + { + hideToolbar((tTbData*)tcItem.lParam); + } + return TRUE; + } + case WM_MOUSEMOVE: + { + INT iItem = 0; + TCHITTESTINFO info = {0}; + + // get selected sub item + info.pt.x = LOWORD(lParam); + info.pt.y = HIWORD(lParam); + iItem = ::SendMessage(hwnd, TCM_HITTEST, 0, (LPARAM)&info); + + if ((_beginDrag == TRUE) && (wParam == MK_LBUTTON)) + { + + SelectTab(iItem); + + // send moving message to parent window + _dragFromTab = TRUE; + NotifyParent(DMM_MOVE); + _beginDrag = FALSE; + } + else + { + INT iItemSel = ::SendMessage(hwnd, TCM_GETCURSEL, 0, 0); + + if ((_bTabTTHover == FALSE) && (iItem != iItemSel)) + { + TRACKMOUSEEVENT tme; + tme.cbSize = sizeof(tme); + tme.hwndTrack = hwnd; + tme.dwFlags = TME_LEAVE | TME_HOVER; + tme.dwHoverTime = 1000; + _bTabTTHover = _TrackMouseEvent(&tme); + } + else + { + if (iItem == iItemSel) + { + toolTip.destroy(); + _bTabTTHover = FALSE; + } + else if (iItem != _iLastHovered) + { + TCITEM tcItem = {0}; + RECT rc = {0}; + + // destroy old tooltip + toolTip.destroy(); + + // recalc mouse position + ::ClientToScreen(hwnd, &info.pt); + + // get text of toolbar + tcItem.mask = TCIF_PARAM; + ::SendMessage(hwnd, TCM_GETITEM, iItem, (LPARAM)&tcItem); + + toolTip.init(_hInst, hwnd); + toolTip.Show(rc, ((tTbData*)tcItem.lParam)->pszName, info.pt.x, info.pt.y + 20); + } + } + + // save last hovered item + _iLastHovered = iItem; + + _beginDrag = FALSE; + } + return TRUE; + } + case WM_MOUSEHOVER: + { + INT iItem = 0; + TCITEM tcItem = {0}; + RECT rc = {0}; + TCHITTESTINFO info = {0}; + + // get selected sub item + info.pt.x = LOWORD(lParam); + info.pt.y = HIWORD(lParam); + iItem = ::SendMessage(hwnd, TCM_HITTEST, 0, (LPARAM)&info); + + // recalc mouse position + ::ClientToScreen(hwnd, &info.pt); + + // get text of toolbar + tcItem.mask = TCIF_PARAM; + ::SendMessage(hwnd, TCM_GETITEM, iItem, (LPARAM)&tcItem); + + toolTip.init(_hInst, hwnd); + toolTip.Show(rc, ((tTbData*)tcItem.lParam)->pszName, info.pt.x, info.pt.y + 20); + return TRUE; + } + case WM_MOUSELEAVE: + { + toolTip.destroy(); + _bTabTTHover = FALSE; + return TRUE; + } + case WM_NOTIFY: + { + LPNMHDR lpnmhdr = (LPNMHDR)lParam; + + if ((lpnmhdr->hwndFrom == _hContTab) && (lpnmhdr->code == TCN_GETOBJECT)) + { + INT iItem = 0; + TCHITTESTINFO info = {0}; + + // get selected sub item + info.pt.x = LOWORD(lParam); + info.pt.y = HIWORD(lParam); + iItem = ::SendMessage(hwnd, TCM_HITTEST, 0, (LPARAM)&info); + + SelectTab(iItem); + } + break; + } + default: + break; + } + + return ::CallWindowProc(_hDefaultTabProc, hwnd, Message, wParam, lParam); +} + +void DockingCont::drawTabItem(DRAWITEMSTRUCT *pDrawItemStruct) +{ + TCITEM tcItem = {0}; + RECT rc = pDrawItemStruct->rcItem; + + INT nTab = pDrawItemStruct->itemID; + bool isSelected = (nTab == getActiveTb()); + + // get current selected item + tcItem.mask = TCIF_PARAM; + ::SendMessage(_hContTab, TCM_GETITEM, nTab, (LPARAM)&tcItem); + + TCHAR* text = ((tTbData*)tcItem.lParam)->pszName; + INT length = lstrlen(((tTbData*)tcItem.lParam)->pszName); + + + // get drawing context + HDC hDc = pDrawItemStruct->hDC; + + INT nSavedDC = ::SaveDC(hDc); + + // For some bizarre reason the rcItem you get extends above the actual + // drawing area. We have to workaround this "feature". + rc.top += ::GetSystemMetrics(SM_CYEDGE); + + ::SetBkMode(hDc, TRANSPARENT); + HBRUSH hBrush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE)); + ::FillRect(hDc, &rc, hBrush); + ::DeleteObject((HGDIOBJ)hBrush); + + // draw orange bar + if ((_bDrawOgLine == TRUE) && (isSelected)) + { + RECT barRect = rc; + barRect.top += rc.bottom - 4; + + hBrush = ::CreateSolidBrush(RGB(250, 170, 60)); + ::FillRect(hDc, &barRect, hBrush); + ::DeleteObject((HGDIOBJ)hBrush); + + } + + // draw icon if enabled + if (((tTbData*)tcItem.lParam)->uMask & DWS_ICONTAB) + { + HIMAGELIST hImageList = (HIMAGELIST)::SendMessage(_hParent, DMM_GETIMAGELIST, 0, 0); + INT iPosImage = ::SendMessage(_hParent, DMM_GETICONPOS, 0, (LPARAM)((tTbData*)tcItem.lParam)->hClient); + + if ((hImageList != NULL) && (iPosImage >= 0)) + { + // Get height of image so we + IMAGEINFO info = {0}; + RECT & imageRect = info.rcImage; + + ImageList_GetImageInfo(hImageList, iPosImage, &info); + ImageList_Draw(hImageList, iPosImage, hDc, rc.left + 3, 2, ILD_NORMAL); + + if (isSelected == true) + { + rc.left += imageRect.right - imageRect.left + 5; + } + } + } + + if (isSelected == true) + { + COLORREF _unselectedColor = RGB(0, 0, 0); + ::SetTextColor(hDc, _unselectedColor); + + // draw text + rc.top -= ::GetSystemMetrics(SM_CYEDGE); + ::SelectObject(hDc, _hFont); + ::DrawText(hDc, text, length, &rc, DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX); + } + + ::RestoreDC(hDc, nSavedDC); +} + + +//---------------------------------------------- +// Process function of dialog +// +BOOL CALLBACK DockingCont::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam) +{ + switch (Message) + { + case WM_NCACTIVATE: + { + // Note: lParam to identify the trigger window + if ((INT)lParam != -1) + { + ::SendMessage(_hParent, WM_NCACTIVATE, wParam, 0); + } + break; + } + case WM_INITDIALOG: + { + _hContTab = ::GetDlgItem(_hSelf, IDC_TAB_CONT); + _hCaption = ::GetDlgItem(_hSelf, IDC_BTN_CAPTION); + + // intial subclassing of caption + ::SetWindowLongPtr(_hCaption, GWL_USERDATA, reinterpret_cast(this)); + _hDefaultCaptionProc = reinterpret_cast(::SetWindowLongPtr(_hCaption, GWL_WNDPROC, reinterpret_cast(wndCaptionProc))); + + // intial subclassing of tab + ::SetWindowLongPtr(_hContTab, GWL_USERDATA, reinterpret_cast(this)); + _hDefaultTabProc = reinterpret_cast(::SetWindowLongPtr(_hContTab, GWL_WNDPROC, reinterpret_cast(wndTabProc))); + + // set min tab width + ::SendMessage(_hContTab, TCM_SETMINTABWIDTH, 0, (LPARAM)MIN_TABWIDTH); + break; + } + case WM_NCCALCSIZE: + case WM_SIZE: + { + onSize(); + break; + } + case WM_DRAWITEM : + { + // draw tab or caption + if (((DRAWITEMSTRUCT *)lParam)->CtlID == IDC_TAB_CONT) + { + drawTabItem((DRAWITEMSTRUCT *)lParam); + return TRUE; + } + else + { + drawCaptionItem((DRAWITEMSTRUCT *)lParam); + return TRUE; + } + break; + } + case WM_NCLBUTTONDBLCLK : + { + RECT rcWnd = {0}; + RECT rcClient = {0}; + POINT pt = {HIWORD(lParam), LOWORD(lParam)}; + + getWindowRect(rcWnd); + getClientRect(rcClient); + ClientRectToScreenRect(_hSelf, &rcClient); + rcWnd.bottom = rcClient.top; + + // if in caption + if ((rcWnd.top < pt.x) && (rcWnd.bottom > pt.x) && + (rcWnd.left < pt.y) && (rcWnd.right > pt.y)) + { + NotifyParent(DMM_DOCKALL); + return TRUE; + } + break; + } + case WM_SYSCOMMAND : + { + switch (wParam & 0xfff0) + { + case SC_MOVE: + NotifyParent(DMM_MOVE); + return TRUE; + default: + break; + } + return FALSE; + } + case WM_COMMAND : + { + switch (LOWORD(wParam)) + { + case IDCANCEL: + doClose(); + return TRUE; + default : + break; + } + break; + } + default: + break; + } + + return FALSE; +} + +void DockingCont::onSize(void) +{ + TCITEM tcItem = {0}; + RECT rc = {0}; + RECT rcTemp = {0}; + UINT iItemCnt = ::SendMessage(_hContTab, TCM_GETITEMCOUNT, 0, 0); + UINT iTabOff = 0; + + getClientRect(rc); + + if (iItemCnt >= 1) + { + // resize to docked window + if (_isFloating == false) + { + // draw caption + if (_isTopCaption == TRUE) + { + ::SetWindowPos(_hCaption, NULL, rc.left, rc.top, rc.right, HIGH_CAPTION, SWP_NOZORDER | SWP_NOACTIVATE); + rc.top += HIGH_CAPTION; + rc.bottom -= HIGH_CAPTION; + } + else + { + ::SetWindowPos(_hCaption, NULL, rc.left, rc.top, HIGH_CAPTION, rc.bottom, SWP_NOZORDER | SWP_NOACTIVATE); + rc.left += HIGH_CAPTION; + rc.right -= HIGH_CAPTION; + } + + if (iItemCnt >= 2) + { + // resize tab and plugin control if tabs exceeds one + // resize tab + rcTemp = rc; + rcTemp.top = (rcTemp.bottom + rcTemp.top) - (HIGH_TAB+CAPTION_GAP); + rcTemp.bottom = HIGH_TAB; + iTabOff = HIGH_TAB; + + ::SetWindowPos(_hContTab, NULL, + rcTemp.left, rcTemp.top, rcTemp.right, rcTemp.bottom, + SWP_NOZORDER | SWP_SHOWWINDOW | SWP_NOACTIVATE); + } + + // resize client area for plugin + rcTemp = rc; + if (_isTopCaption == TRUE) + { + rcTemp.top += CAPTION_GAP; + rcTemp.bottom -= (iTabOff + CAPTION_GAP); + } + else + { + rcTemp.left += CAPTION_GAP; + rcTemp.right -= CAPTION_GAP; + rcTemp.bottom -= iTabOff; + } + + // set position of client area + ::SetWindowPos(::GetDlgItem(_hSelf, IDC_CLIENT_TAB), NULL, + rcTemp.left, rcTemp.top, rcTemp.right, rcTemp.bottom, + SWP_NOZORDER | SWP_NOACTIVATE); + } + // resize to float window + else + { + // update floating size + if (_isFloating == true) + { + for (size_t iTb = 0; iTb < _vTbData.size(); iTb++) + { + getWindowRect(_vTbData[iTb]->rcFloat); + } + } + + // draw caption + if (iItemCnt >= 2) + { + // resize tab if size of elements exceeds one + rcTemp = rc; + rcTemp.top = rcTemp.bottom - (HIGH_TAB+CAPTION_GAP); + rcTemp.bottom = HIGH_TAB; + + ::SetWindowPos(_hContTab, NULL, + rcTemp.left, rcTemp.top, rcTemp.right, rcTemp.bottom, + SWP_NOZORDER | SWP_SHOWWINDOW); + } + + // resize client area for plugin + rcTemp = rc; + rcTemp.bottom -= ((iItemCnt == 1)?0:HIGH_TAB); + + ::SetWindowPos(::GetDlgItem(_hSelf, IDC_CLIENT_TAB), NULL, + rcTemp.left, rcTemp.top, rcTemp.right, rcTemp.bottom, + SWP_NOZORDER | SWP_NOACTIVATE); + } + + + // get active item data + UINT iItemCnt = ::SendMessage(_hContTab, TCM_GETITEMCOUNT, 0, 0); + + // resize visible plugin windows + for (UINT iItem = 0; iItem < iItemCnt; iItem++) + { + tcItem.mask = TCIF_PARAM; + ::SendMessage(_hContTab, TCM_GETITEM, iItem, (LPARAM)&tcItem); + + ::SetWindowPos(((tTbData*)tcItem.lParam)->hClient, NULL, + 0, 0, rcTemp.right, rcTemp.bottom, + SWP_NOZORDER); + } + } +} + +void DockingCont::doClose(void) +{ + INT iItemOff = 0; + INT iItemCnt = ::SendMessage(_hContTab, TCM_GETITEMCOUNT, 0, 0); + + for (INT iItem = 0; iItem < iItemCnt; iItem++) + { + TCITEM tcItem = {0}; + + // get item data + SelectTab(iItemOff); + tcItem.mask = TCIF_PARAM; + ::SendMessage(_hContTab, TCM_GETITEM, iItemOff, (LPARAM)&tcItem); + + // notify child windows + if (NotifyParent(DMM_CLOSE) == 0) + { + // delete tab + hideToolbar((tTbData*)tcItem.lParam); + } + else + { + iItemOff++; + } + } + + if (iItemOff == 0) + { + // hide dialog first + this->doDialog(false); + ::SendMessage(_hParent, WM_SIZE, 0, 0); + } +} + +void DockingCont::showToolbar(tTbData* pTbData, BOOL state) +{ + if (state == SW_SHOW) + { + viewToolbar(pTbData); + } + else + { + hideToolbar(pTbData); + } +} + +INT DockingCont::hideToolbar(tTbData *pTbData, BOOL hideClient) +{ + INT iItem = SearchPosInTab(pTbData); + + // delete item + if (TRUE == ::SendMessage(_hContTab, TCM_DELETEITEM, iItem, 0)) + { + UINT iItemCnt = ::SendMessage(_hContTab, TCM_GETITEMCOUNT, 0, 0); + + if (iItemCnt != 0) + { + TCITEM tcItem = {0}; + + tcItem.mask = TCIF_PARAM; + + if (iItem == iItemCnt) + { + iItem--; + } + + // activate new selected item and view plugin dialog + _prevItem = iItem; + SelectTab(iItem); + + // hide tabs if only one element + if (iItemCnt == 1) + { + ::ShowWindow(_hContTab, SW_HIDE); + } + } + else + { + // hide dialog + this->doDialog(false); + + // send message to docking manager for resize + if (!_isFloating) + { + ::SendMessage(_hParent, WM_SIZE, 0, 0); + } + } + + // keep sure, that client is hide!!! + if (hideClient == TRUE) + { + ::ShowWindow(pTbData->hClient, SW_HIDE); + } + } + onSize(); + + return iItem; +} + +void DockingCont::viewToolbar(tTbData *pTbData) +{ + TCITEM tcItem = {0}; + INT iItemCnt = ::SendMessage(_hContTab, TCM_GETITEMCOUNT, 0, 0); + + if (iItemCnt > 0) + { + UINT iItem = getActiveTb(); + + tcItem.mask = TCIF_PARAM; + ::SendMessage(_hContTab, TCM_GETITEM, iItem, (LPARAM)&tcItem); + + // hide active dialog + ::ShowWindow(((tTbData*)tcItem.lParam)->hClient, SW_HIDE); + } + + // create new tab if it not exists + INT iTabPos = SearchPosInTab(pTbData); + if (iTabPos == -1) + { + // set only params and text even if icon available + tcItem.mask = TCIF_PARAM; + tcItem.lParam = (LPARAM)pTbData; + ::SendMessage(_hContTab, TCM_INSERTITEM, iItemCnt, (LPARAM)&tcItem); + SelectTab(iItemCnt); + } + // if exists select it and update data + else + { + tcItem.mask = TCIF_PARAM; + tcItem.lParam = (LPARAM)pTbData; + ::SendMessage(_hContTab, TCM_SETITEM, iTabPos, (LPARAM)&tcItem); + SelectTab(iTabPos); + } + + // show dialog and notify parent to update dialog view + if (isVisible() == false) + { + this->doDialog(); + ::SendMessage(_hParent, WM_SIZE, 0, 0); + } + + // set position of client + onSize(); +} + +INT DockingCont::SearchPosInTab(tTbData* pTbData) +{ + TCITEM tcItem = {0}; + INT iItemCnt = ::SendMessage(_hContTab, TCM_GETITEMCOUNT, 0, 0); + INT ret = -1; + + tcItem.mask = TCIF_PARAM; + + for (INT iItem = 0; iItem < iItemCnt; iItem++) + { + ::SendMessage(_hContTab, TCM_GETITEM, iItem, (LPARAM)&tcItem); + + if (((tTbData*)tcItem.lParam)->hClient == pTbData->hClient) + { + ret = iItem; + break; + } + } + return ret; +} + +void DockingCont::SelectTab(INT iTab) +{ + if (iTab != -1) + { + TCHAR *pszMaxTxt = NULL; + TCITEM tcItem = {0}; + SIZE size = {0}; + INT maxWidth = 0; + INT iItemCnt = ::SendMessage(_hContTab, TCM_GETITEMCOUNT, 0, 0); + + // get data of new active dialog + tcItem.mask = TCIF_PARAM; + ::SendMessage(_hContTab, TCM_GETITEM, iTab, (LPARAM)&tcItem); + + // show active dialog + ::ShowWindow(((tTbData*)tcItem.lParam)->hClient, SW_SHOW); + ::SetFocus(((tTbData*)tcItem.lParam)->hClient); + + if (iTab != _prevItem) + { + // hide previous dialog + ::SendMessage(_hContTab, TCM_GETITEM, _prevItem, (LPARAM)&tcItem); + ::ShowWindow(((tTbData*)tcItem.lParam)->hClient, SW_HIDE); + } + + // resize tab item + + // get at first largest item ... + HDC hDc = ::GetDC(_hContTab); + SelectObject(hDc, _hFont); + + for (INT iItem = 0; iItem < iItemCnt; iItem++) + { + TCHAR *pszTabTxt = NULL; + + ::SendMessage(_hContTab, TCM_GETITEM, iItem, (LPARAM)&tcItem); + pszTabTxt = ((tTbData*)tcItem.lParam)->pszName; + + // get current font width + GetTextExtentPoint32(hDc, pszTabTxt, lstrlen(pszTabTxt), &size); + + if (maxWidth < size.cx) + { + maxWidth = size.cx; + pszMaxTxt = pszTabTxt; + } + } + ::ReleaseDC(_hSelf, hDc); + + tcItem.mask = TCIF_TEXT; + for (INT iItem = 0; iItem < iItemCnt; iItem++) + { + if (iItem == iTab) + { + // fake here an icon before text ... + TCHAR szText[64]; + + lstrcpy(szText, TEXT(" ")); + lstrcat(szText, pszMaxTxt); + tcItem.pszText = szText; + tcItem.cchTextMax = lstrlen(szText); + } + else + { + // ... and resize old and new item + tcItem.pszText = TEXT(""); + tcItem.cchTextMax = lstrlen(TEXT("")); + } + ::SendMessage(_hContTab, TCM_SETITEM, iItem, (LPARAM)&tcItem); + } + + // selects the pressed tab and store previous tab + ::SendMessage(_hContTab, TCM_SETCURSEL, iTab, 0); + _prevItem = iTab; + + // update caption text + updateCaption(); + + onSize(); + } +} + +void DockingCont::updateCaption(void) +{ + if (!_hContTab) + return; + + TCITEM tcItem = {0}; + INT iItem = getActiveTb(); + + if (iItem < 0) + return; + + // get data of new active dialog + tcItem.mask = TCIF_PARAM; + ::SendMessage(_hContTab, TCM_GETITEM, iItem, (LPARAM)&tcItem); + + // update caption text + lstrcpy(_pszCaption, ((tTbData*)tcItem.lParam)->pszName); + + // test if additional information are available + if ((((tTbData*)tcItem.lParam)->uMask & DWS_ADDINFO) && + (lstrlen(((tTbData*)tcItem.lParam)->pszAddInfo) != 0)) + { + lstrcat(_pszCaption, TEXT(" - ")); + lstrcat(_pszCaption, ((tTbData*)tcItem.lParam)->pszAddInfo); + } + + if (_isFloating == true) + { + ::SetWindowText(_hSelf, _pszCaption); + } + else + { + ::SetWindowText(_hCaption, _pszCaption); + } +} + +void DockingCont::focusClient(void) +{ + TCITEM tcItem = {0}; + INT iItem = getActiveTb(); + + if (iItem != -1) + { + // get data of new active dialog + tcItem.mask = TCIF_PARAM; + ::SendMessage(_hContTab, TCM_GETITEM, iItem, (LPARAM)&tcItem); + + // set focus + ::SetFocus(((tTbData*)tcItem.lParam)->hClient); + } +} + +LPARAM DockingCont::NotifyParent(UINT message) +{ + return ::SendMessage(_hParent, message, 0, (LPARAM)this); +} + diff --git a/PowerEditor/src/WinControls/DockingWnd/DockingCont.h b/PowerEditor/src/WinControls/DockingWnd/DockingCont.h new file mode 100644 index 00000000..2daae843 --- /dev/null +++ b/PowerEditor/src/WinControls/DockingWnd/DockingCont.h @@ -0,0 +1,234 @@ +// this file is part of docking functionality for Notepad++ +// Copyright (C)2005 Jens Lorenz +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +#ifndef DOCKINGCONT +#define DOCKINGCONT + +#include "StaticDialog.h" +#include "Resource.h" +#include "Docking.h" +#include +#include +#include +#include + +using namespace std; + + +// window styles +#define POPUP_STYLES (WS_POPUP|WS_CLIPSIBLINGS|WS_CAPTION|WS_SYSMENU|WS_THICKFRAME|WS_MAXIMIZEBOX) +#define POPUP_EXSTYLES (WS_EX_CONTROLPARENT|WS_EX_WINDOWEDGE|WS_EX_TOOLWINDOW) +#define CHILD_STYLES (WS_CHILD) +#define CHILD_EXSTYLES (0x00000000L) + +#define MIN_TABWIDTH 24 + + +enum eMousePos { + posOutside, + posCaption, + posClose +}; + +// some fix modify values for GUI +#define HIGH_CAPTION 18 +#define HIGH_TAB 20 +#define CAPTION_GAP 2 +#define CLOSEBTN_POS_LEFT 3 +#define CLOSEBTN_POS_TOP 3 + + + + +class DockingCont : public StaticDialog +{ +public: + DockingCont(); + ~DockingCont(); + + HWND getTabWnd(void) { + return _hContTab; + }; + HWND getCaptionWnd(void) { + if (_isFloating == false) + return _hCaption; + else + return _hSelf; + }; + + tTbData* createToolbar(tTbData data, Window **ppWin); + void removeToolbar(tTbData data); + tTbData* findToolbarByWnd(HWND hClient); + tTbData* findToolbarByName(TCHAR* pszName); + + void showToolbar(tTbData *pTbData, BOOL state); + + BOOL updateInfo(HWND hClient) { + for (size_t iTb = 0; iTb < _vTbData.size(); iTb++) + { + if (_vTbData[iTb]->hClient == hClient) + { + updateCaption(); + return TRUE; + } + } + return FALSE; + }; + + void setActiveTb(tTbData* pTbData); + void setActiveTb(INT iItem); + INT getActiveTb(void); + tTbData* getDataOfActiveTb(void); + vector getDataOfAllTb(void) { + return _vTbData; + }; + vector getDataOfVisTb(void); + bool isTbVis(tTbData* data); + + void doDialog(bool willBeShown = true, bool isFloating = false); + + bool isFloating(void) { + return _isFloating; + } + + INT getElementCnt(void) { + return _vTbData.size(); + } + + // interface function for gripper + BOOL startMovingFromTab(void) { + BOOL dragFromTabTemp = _dragFromTab; + _dragFromTab = FALSE; + return dragFromTabTemp; + }; + + void setCaptionTop(BOOL isTopCaption) { + _isTopCaption = (isTopCaption == CAPTION_TOP); + onSize(); + }; + + void focusClient(void); + + void SetActive(BOOL bState) { + _isActive = bState; + updateCaption(); + }; + + void setTabStyle(const BOOL & bDrawOgLine) { + _bDrawOgLine = bDrawOgLine; + RedrawWindow(_hContTab, NULL, NULL, 0); + }; + + virtual void destroy() { + for (INT iTb = _vTbData.size(); iTb > 0; iTb--) + { + delete _vTbData[iTb-1]; + } + ::DestroyWindow(_hSelf); + }; + +protected : + + // Subclassing caption + LRESULT runProcCaption(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam); + static LRESULT CALLBACK wndCaptionProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { + return (((DockingCont *)(::GetWindowLongPtr(hwnd, GWL_USERDATA)))->runProcCaption(hwnd, Message, wParam, lParam)); + }; + + // Subclassing tab + LRESULT runProcTab(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam); + static LRESULT CALLBACK wndTabProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { + return (((DockingCont *)(::GetWindowLongPtr(hwnd, GWL_USERDATA)))->runProcTab(hwnd, Message, wParam, lParam)); + }; + + virtual BOOL CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam); + + // drawing functions + void drawCaptionItem(DRAWITEMSTRUCT *pDrawItemStruct); + void drawTabItem(DRAWITEMSTRUCT *pDrawItemStruct); + void onSize(void); + + // functions for caption handling and drawing + eMousePos isInRect(HWND hwnd, INT x, INT y); + + // handling of toolbars + void doClose(void); + + // return new item + INT SearchPosInTab(tTbData* pTbData); + void SelectTab(INT iTab); + + INT hideToolbar(tTbData* pTbData, BOOL hideClient = TRUE); + void viewToolbar(tTbData *pTbData); + INT removeTab(tTbData* pTbData) { + return hideToolbar(pTbData, FALSE); + }; + + void updateCaption(void); + LPARAM NotifyParent(UINT message); + +private: + // handles + BOOL _isActive; + bool _isFloating; + HWND _hCaption; + HWND _hContTab; + + // horizontal font for caption and tab + HFONT _hFont; + + // caption params + BOOL _isTopCaption; + TCHAR _pszCaption[256]; + BOOL _isMouseDown; + BOOL _isMouseClose; + BOOL _isMouseOver; + RECT _rcCaption; + + // tab style + BOOL _bDrawOgLine; + + // Important value for DlgMoving class + BOOL _dragFromTab; + + // subclassing handle for caption + WNDPROC _hDefaultCaptionProc; + + // subclassing handle for tab + WNDPROC _hDefaultTabProc; + + // for moving and reordering + UINT _prevItem; + BOOL _beginDrag; + HIMAGELIST _hImageList; + + // Is tooltip + BOOL _bTabTTHover; + INT _iLastHovered; + + BOOL _bCaptionTT; + BOOL _bCapTTHover; + eMousePos _hoverMPos; + + // data of added windows + vector _vTbData; +}; + + + +#endif // DOCKINGCONT diff --git a/PowerEditor/src/WinControls/DockingWnd/DockingDlgInterface.h b/PowerEditor/src/WinControls/DockingWnd/DockingDlgInterface.h new file mode 100644 index 00000000..8be2d245 --- /dev/null +++ b/PowerEditor/src/WinControls/DockingWnd/DockingDlgInterface.h @@ -0,0 +1,136 @@ +/* +this file is part of Function List Plugin for Notepad++ +Copyright (C)2005 Jens Lorenz + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef DOCKINGDLGINTERFACE_H +#define DOCKINGDLGINTERFACE_H + +#include "StaticDialog.h" +#include "dockingResource.h" +#include "Docking.h" +#include + + +class DockingDlgInterface : public StaticDialog +{ +public: + DockingDlgInterface(): StaticDialog() {}; + DockingDlgInterface(int dlgID): StaticDialog(), + _dlgID(dlgID), _isFloating(TRUE), _iDockedPos(0) {}; + + virtual void init(HINSTANCE hInst, HWND parent) + { + StaticDialog::init(hInst, parent); + ::GetModuleFileName((HMODULE)hInst, _moduleName, MAX_PATH); + lstrcpy(_moduleName, PathFindFileName(_moduleName)); + } + + void create(tTbData * data, bool isRTL = false){ + StaticDialog::create(_dlgID, isRTL); + ::GetWindowText(_hSelf, _pluginName, MAX_PATH); + + // user information + data->hClient = _hSelf; + data->pszName = _pluginName; + + // supported features by plugin + data->uMask = 0; + + // icons + //data->hIconBar = ::LoadIcon(hInst, IDB_CLOSE_DOWN); + //data->hIconTab = ::LoadIcon(hInst, IDB_CLOSE_DOWN); + + // additional info + data->pszAddInfo = NULL; + + _data = data; + + }; + + virtual void updateDockingDlg(void) { + ::SendMessage(_hParent, NPPM_DMMUPDATEDISPINFO, 0, (LPARAM)_hSelf); + } + + virtual void destroy() { + }; + + virtual void display(bool toShow = true) const { + ::SendMessage(_hParent, toShow?NPPM_DMMSHOW:NPPM_DMMHIDE, 0, (LPARAM)_hSelf); + }; + + const TCHAR * getPluginFileName() const { + return _moduleName; + }; + +protected : + virtual BOOL CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) + { + switch (message) + { + + case WM_NOTIFY: + { + LPNMHDR pnmh = (LPNMHDR)lParam; + + if (pnmh->hwndFrom == _hParent) + { + switch (LOWORD(pnmh->code)) + { + case DMN_CLOSE: + { + //::MessageBox(_hSelf, TEXT("Close Dialog"), TEXT("Plugin Message"), MB_OK); + break; + } + case DMN_FLOAT: + { + //::MessageBox(_hSelf, TEXT("Float Dialog"), TEXT("Plugin Message"), MB_OK); + _isFloating = true; + break; + } + case DMN_DOCK: + { + //TCHAR test[256]; + //wsprintf(test, TEXT("Dock Dialog to %d"), HIWORD(pnmh->code)); + //::MessageBox(_hSelf, test, TEXT("Plugin Message"), MB_OK); + _iDockedPos = HIWORD(pnmh->code); + _isFloating = false; + break; + } + default: + break; + } + } + break; + } + default: + break; + } + return FALSE; + }; + + // Handles + HWND _HSource; + tTbData* _data; + int _dlgID; + bool _isFloating; + int _iDockedPos; + TCHAR _moduleName[MAX_PATH]; + TCHAR _pluginName[MAX_PATH]; +}; + +#endif // DOCKINGDLGINTERFACE_H diff --git a/PowerEditor/src/WinControls/DockingWnd/DockingGUIWidget.rc b/PowerEditor/src/WinControls/DockingWnd/DockingGUIWidget.rc new file mode 100644 index 00000000..64e4e167 --- /dev/null +++ b/PowerEditor/src/WinControls/DockingWnd/DockingGUIWidget.rc @@ -0,0 +1,22 @@ + +#include +#include "dockingResource.h" + +IDD_CONTAINER_DLG DIALOGEX 0, 0, 186, 103 +STYLE DS_SETFONT | DS_SETFOREGROUND | WS_MAXIMIZEBOX | WS_POPUP | + WS_CLIPCHILDREN | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME +EXSTYLE WS_EX_TOOLWINDOW +CAPTION "Selected Tab" +FONT 8, TEXT("MS Shell Dlg"), 0, 0, 0x1 +BEGIN + CONTROL "Caption",IDC_BTN_CAPTION,"Button",BS_OWNERDRAW | NOT + WS_VISIBLE,0,0,186,10 + LTEXT "",IDC_CLIENT_TAB,16,28,156,50,NOT WS_GROUP + CONTROL "Tab1",IDC_TAB_CONT,"SysTabControl32",TCS_BOTTOM | + TCS_OWNERDRAWFIXED | NOT WS_VISIBLE,0,14,185,88 +END + + +IDB_CLOSE_DOWN BITMAP "CloseDown.bmp" +IDB_CLOSE_UP BITMAP "CloseUp.bmp" + diff --git a/PowerEditor/src/WinControls/DockingWnd/DockingManager.cpp b/PowerEditor/src/WinControls/DockingWnd/DockingManager.cpp new file mode 100644 index 00000000..4311ffc8 --- /dev/null +++ b/PowerEditor/src/WinControls/DockingWnd/DockingManager.cpp @@ -0,0 +1,876 @@ +//this file is part of docking functionality for Notepad++ +//Copyright (C)2006 Jens Lorenz +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +#include "DockingCont.h" +#include "DockingManager.h" +#include "Gripper.h" +#include +#include + + +BOOL DockingManager::_isRegistered = FALSE; + +//Window of event handling DockingManager (can only be one) +static HWND hWndServer = NULL; +//Next hook in line +static HHOOK gWinCallHook = NULL; +LRESULT CALLBACK FocusWndProc(int nCode, WPARAM wParam, LPARAM lParam); + +/* Callback function that handles messages (to test focus) */ +LRESULT CALLBACK FocusWndProc(int nCode, WPARAM wParam, LPARAM lParam) { + if (nCode == HC_ACTION && hWndServer) { + DockingManager *pDockingManager = (DockingManager *)::GetWindowLongPtr(hWndServer, GWL_USERDATA); + if (pDockingManager) { + vector & vcontainer = pDockingManager->getContainerInfo(); + CWPSTRUCT * pCwp = (CWPSTRUCT*)lParam; + if (pCwp->message == WM_KILLFOCUS) { + for (int i = 0; i < DOCKCONT_MAX; i++) + { + vcontainer[i]->SetActive(FALSE); //deactivate all containers + } + } else if (pCwp->message == WM_SETFOCUS) { + for (int i = 0; i < DOCKCONT_MAX; i++) + { + vcontainer[i]->SetActive(IsChild(vcontainer[i]->getHSelf(), pCwp->hwnd)); //activate the container that contains the window with focus, this can be none + } + } + } + } + return CallNextHookEx(gWinCallHook, nCode, wParam, lParam); +} + +DockingManager::DockingManager() +{ + _isInitialized = FALSE; + _hImageList = NULL; + memset(_iContMap, -1, CONT_MAP_MAX); + + _iContMap[0] = CONT_LEFT; + _iContMap[1] = CONT_RIGHT; + _iContMap[2] = CONT_TOP; + _iContMap[3] = CONT_BOTTOM; + + /* create four containers with splitters */ + for (int i = 0; i < DOCKCONT_MAX; i++) + { + DockingCont* _pDockCont = new DockingCont; + _vContainer.push_back(_pDockCont); + + DockingSplitter* _pSplitter = new DockingSplitter; + _vSplitter.push_back(_pSplitter); + } +} + + +void DockingManager::init(HINSTANCE hInst, HWND hWnd, Window ** ppWin) +{ + Window::init(hInst, hWnd); + + if (!_isRegistered) + { + WNDCLASS clz; + + clz.style = 0; + clz.lpfnWndProc = staticWinProc; + clz.cbClsExtra = 0; + clz.cbWndExtra = 0; + clz.hInstance = _hInst; + clz.hIcon = NULL; + clz.hCursor = ::LoadCursor(NULL, IDC_ARROW); + clz.hbrBackground = NULL; + clz.lpszMenuName = NULL; + clz.lpszClassName = DSPC_CLASS_NAME; + + if (!::RegisterClass(&clz)) + { + systemMessage(TEXT("System Err")); + throw int(98); + } + _isRegistered = TRUE; + } + + _hSelf = ::CreateWindowEx( + 0, + DSPC_CLASS_NAME, + TEXT(""), + WS_CHILD | WS_CLIPCHILDREN, + CW_USEDEFAULT, CW_USEDEFAULT, + CW_USEDEFAULT, CW_USEDEFAULT, + _hParent, + NULL, + _hInst, + (LPVOID)this); + + if (!_hSelf) + { + systemMessage(TEXT("System Err")); + throw int(777); + } + + setClientWnd(ppWin); + + /* create docking container */ + for (int iCont = 0; iCont < DOCKCONT_MAX; iCont++) + { + _vContainer[iCont]->init(_hInst, _hSelf); + _vContainer[iCont]->doDialog(false); + ::SetParent(_vContainer[iCont]->getHSelf(), _hParent); + + if ((iCont == CONT_TOP) || (iCont == CONT_BOTTOM)) + _vSplitter[iCont]->init(_hInst, _hParent, _hSelf, DMS_HORIZONTAL); + else + _vSplitter[iCont]->init(_hInst, _hParent, _hSelf, DMS_VERTICAL); + } + /* register window event hooking */ + if (!hWndServer) + hWndServer = _hSelf; + CoInitialize(NULL); + if (!gWinCallHook) //only set if not already done + gWinCallHook = SetWindowsHookEx(WH_CALLWNDPROC, FocusWndProc, hInst, GetCurrentThreadId()); + + if (!gWinCallHook) + { + systemMessage(TEXT("System Err")); + throw int(1000); + } + + _dockData.hWnd = _hSelf; + + _isInitialized = TRUE; +} + +LRESULT CALLBACK DockingManager::staticWinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + DockingManager *pDockingManager = NULL; + switch (message) + { + case WM_NCCREATE : + pDockingManager = (DockingManager *)(((LPCREATESTRUCT)lParam)->lpCreateParams); + pDockingManager->_hSelf = hwnd; + ::SetWindowLongPtr(hwnd, GWL_USERDATA, reinterpret_cast(pDockingManager)); + return TRUE; + + default : + pDockingManager = (DockingManager *)::GetWindowLongPtr(hwnd, GWL_USERDATA); + if (!pDockingManager) + return ::DefWindowProc(hwnd, message, wParam, lParam); + return pDockingManager->runProc(hwnd, message, wParam, lParam); + } +} + +LRESULT DockingManager::runProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + switch (message) + { + case WM_NCACTIVATE: + { + /* activate/deactivate titlebar of toolbars */ + for (size_t iCont = DOCKCONT_MAX; iCont < _vContainer.size(); iCont++) + { + ::SendMessage(_vContainer[iCont]->getHSelf(), WM_NCACTIVATE, wParam, (LPARAM)-1); + } + + if ((int)lParam != -1) + { + ::SendMessage(_hParent, WM_NCACTIVATE, wParam, (LPARAM)-1); + } + break; + } + case WM_MOVE: + case WM_SIZE: + { + onSize(); + break; + } + case WM_DESTROY: + { + /* unregister window event hooking BEFORE EVERYTHING ELSE */ + if (hWndServer == hwnd) { + UnhookWindowsHookEx(gWinCallHook); + gWinCallHook = NULL; + hWndServer = NULL; + } + + /* destroy imagelist if it exists */ + if (_hImageList != NULL) + { + ::ImageList_Destroy(_hImageList); + } + + /* destroy containers */ + for (int i = _vContainer.size(); i > 0; i--) + { + _vContainer[i-1]->destroy(); + delete _vContainer[i-1]; + } + CoUninitialize(); + break; + } + case DMM_LBUTTONUP: //is this message still relevant? + { + if (::GetActiveWindow() != _hParent) + break; + + /* set respective activate state */ + for (int i = 0; i < DOCKCONT_MAX; i++) + { + _vContainer[i]->SetActive(IsChild(_vContainer[i]->getHSelf(), ::GetFocus())); + } + return TRUE; + } + case DMM_MOVE: + { + Gripper* pGripper = new Gripper; + pGripper->init(_hInst, _hParent); + pGripper->startGrip((DockingCont*)lParam, this, pGripper); + break; + } + case DMM_MOVE_SPLITTER: + { + INT offset = (INT)wParam; + + for (int iCont = 0; iCont < DOCKCONT_MAX; iCont++) + { + if (_vSplitter[iCont]->getHSelf() == (HWND)lParam) + { + switch (iCont) + { + case CONT_TOP: + _dockData.rcRegion[iCont].bottom -= offset; + if (_dockData.rcRegion[iCont].bottom < 0) + { + _dockData.rcRegion[iCont].bottom = 0; + } + if ((_rcWork.bottom < (-SPLITTER_WIDTH)) && (offset < 0)) + { + _dockData.rcRegion[iCont].bottom += offset; + } + break; + case CONT_BOTTOM: + _dockData.rcRegion[iCont].bottom += offset; + if (_dockData.rcRegion[iCont].bottom < 0) + { + _dockData.rcRegion[iCont].bottom = 0; + } + if ((_rcWork.bottom < (-SPLITTER_WIDTH)) && (offset > 0)) + { + _dockData.rcRegion[iCont].bottom -= offset; + } + break; + case CONT_LEFT: + _dockData.rcRegion[iCont].right -= offset; + if (_dockData.rcRegion[iCont].right < 0) + { + _dockData.rcRegion[iCont].right = 0; + } + if ((_rcWork.right < SPLITTER_WIDTH) && (offset < 0)) + { + _dockData.rcRegion[iCont].right += offset; + } + break; + case CONT_RIGHT: + _dockData.rcRegion[iCont].right += offset; + if (_dockData.rcRegion[iCont].right < 0) + { + _dockData.rcRegion[iCont].right = 0; + } + if ((_rcWork.right < SPLITTER_WIDTH) && (offset > 0)) + { + _dockData.rcRegion[iCont].right -= offset; + } + break; + } + onSize(); + break; + } + } + break; + } + case DMM_DOCK: + case DMM_FLOAT: + { + toggleActiveTb((DockingCont*)lParam, message); + return FALSE; + } + case DMM_CLOSE: + { + tTbData TbData = *((DockingCont*)lParam)->getDataOfActiveTb(); + return SendNotify(TbData.hClient, DMN_CLOSE); + } + case DMM_FLOATALL: + { + toggleVisTb((DockingCont*)lParam, DMM_FLOAT); + return FALSE; + } + case DMM_DOCKALL: + { + toggleVisTb((DockingCont*)lParam, DMM_DOCK); + return FALSE; + } + case DMM_GETIMAGELIST: + { + return (LPARAM)_hImageList; + } + case DMM_GETICONPOS: + { + for (UINT uImageCnt = 0; uImageCnt < _vImageList.size(); uImageCnt++) + { + if ((HWND)lParam == _vImageList[uImageCnt]) + { + return uImageCnt; + } + } + return -1; + } + default : + break; + } + + return ::DefWindowProc(_hSelf, message, wParam, lParam); +} + +void DockingManager::onSize() +{ + reSizeTo(_rect); +} + +void DockingManager::reSizeTo(RECT & rc) +{ + // store current size of client area + _rect = rc; + + // prepare size of work area + _rcWork = rc; + + if (_isInitialized == FALSE) + return; + + // set top container + _dockData.rcRegion[CONT_TOP].left = rc.left; + _dockData.rcRegion[CONT_TOP].top = rc.top; + _dockData.rcRegion[CONT_TOP].right = rc.right-rc.left; + + _vSplitter[CONT_TOP]->display(false); + + if (_vContainer[CONT_TOP]->isVisible()) + { + _rcWork.top += _dockData.rcRegion[CONT_TOP].bottom + SPLITTER_WIDTH; + _rcWork.bottom -= _dockData.rcRegion[CONT_TOP].bottom + SPLITTER_WIDTH; + + // set size of splitter + RECT rc = {_dockData.rcRegion[CONT_TOP].left , + _dockData.rcRegion[CONT_TOP].top + _dockData.rcRegion[CONT_TOP].bottom, + _dockData.rcRegion[CONT_TOP].right , + SPLITTER_WIDTH}; + _vSplitter[CONT_TOP]->reSizeTo(rc); + } + + // set bottom container + _dockData.rcRegion[CONT_BOTTOM].left = rc.left; + _dockData.rcRegion[CONT_BOTTOM].top = rc.top + rc.bottom - _dockData.rcRegion[CONT_BOTTOM].bottom; + _dockData.rcRegion[CONT_BOTTOM].right = rc.right-rc.left; + + // create temporary rect for bottom container + RECT rcBottom = _dockData.rcRegion[CONT_BOTTOM]; + + _vSplitter[CONT_BOTTOM]->display(false); + + if (_vContainer[CONT_BOTTOM]->isVisible()) + { + _rcWork.bottom -= _dockData.rcRegion[CONT_BOTTOM].bottom + SPLITTER_WIDTH; + + // correct the visibility of bottom container when height is NULL + if (_rcWork.bottom < rc.top) + { + rcBottom.top = _rcWork.top + rc.top + SPLITTER_WIDTH; + rcBottom.bottom += _rcWork.bottom - rc.top; + _rcWork.bottom = rc.top; + } + if ((rcBottom.bottom + SPLITTER_WIDTH) < 0) + { + _rcWork.bottom = rc.bottom - _dockData.rcRegion[CONT_TOP].bottom; + } + + // set size of splitter + RECT rc = {rcBottom.left, + rcBottom.top - SPLITTER_WIDTH, + rcBottom.right, + SPLITTER_WIDTH}; + _vSplitter[CONT_BOTTOM]->reSizeTo(rc); + } + + // set left container + _dockData.rcRegion[CONT_LEFT].left = rc.left; + _dockData.rcRegion[CONT_LEFT].top = _rcWork.top; + _dockData.rcRegion[CONT_LEFT].bottom = _rcWork.bottom; + + _vSplitter[CONT_LEFT]->display(false); + + if (_vContainer[CONT_LEFT]->isVisible()) + { + _rcWork.left += _dockData.rcRegion[CONT_LEFT].right + SPLITTER_WIDTH; + _rcWork.right -= _dockData.rcRegion[CONT_LEFT].right + SPLITTER_WIDTH; + + // set size of splitter + RECT rc = {_dockData.rcRegion[CONT_LEFT].right, + _dockData.rcRegion[CONT_LEFT].top, + SPLITTER_WIDTH, + _dockData.rcRegion[CONT_LEFT].bottom}; + _vSplitter[CONT_LEFT]->reSizeTo(rc); + } + + // set right container + _dockData.rcRegion[CONT_RIGHT].left = rc.right - _dockData.rcRegion[CONT_RIGHT].right; + _dockData.rcRegion[CONT_RIGHT].top = _rcWork.top; + _dockData.rcRegion[CONT_RIGHT].bottom = _rcWork.bottom; + + // create temporary rect for right container + RECT rcRight = _dockData.rcRegion[CONT_RIGHT]; + + _vSplitter[CONT_RIGHT]->display(false); + if (_vContainer[CONT_RIGHT]->isVisible()) + { + _rcWork.right -= _dockData.rcRegion[CONT_RIGHT].right + SPLITTER_WIDTH; + + // correct the visibility of right container when width is NULL + if (_rcWork.right < 15) + { + rcRight.left = _rcWork.left + 15 + SPLITTER_WIDTH; + rcRight.right += _rcWork.right - 15; + _rcWork.right = 15; + } + + // set size of splitter + RECT rc = {rcRight.left - SPLITTER_WIDTH, + rcRight.top, + SPLITTER_WIDTH, + rcRight.bottom}; + _vSplitter[CONT_RIGHT]->reSizeTo(rc); + } + + // set window positions of container + if (_vContainer[CONT_BOTTOM]->isVisible()) + { + ::SetWindowPos(_vContainer[CONT_BOTTOM]->getHSelf(), NULL, + rcBottom.left , + rcBottom.top , + rcBottom.right , + rcBottom.bottom, + SWP_NOZORDER); + _vSplitter[CONT_BOTTOM]->display(); + } + + if (_vContainer[CONT_TOP]->isVisible()) + { + ::SetWindowPos(_vContainer[CONT_TOP]->getHSelf(), NULL, + _dockData.rcRegion[CONT_TOP].left , + _dockData.rcRegion[CONT_TOP].top , + _dockData.rcRegion[CONT_TOP].right , + _dockData.rcRegion[CONT_TOP].bottom, + SWP_NOZORDER); + _vSplitter[CONT_TOP]->display(); + } + + if (_vContainer[CONT_RIGHT]->isVisible()) + { + ::SetWindowPos(_vContainer[CONT_RIGHT]->getHSelf(), NULL, + rcRight.left , + rcRight.top , + rcRight.right , + rcRight.bottom, + SWP_NOZORDER); + _vSplitter[CONT_RIGHT]->display(); + } + + if (_vContainer[CONT_LEFT]->isVisible()) + { + ::SetWindowPos(_vContainer[CONT_LEFT]->getHSelf(), NULL, + _dockData.rcRegion[CONT_LEFT].left , + _dockData.rcRegion[CONT_LEFT].top , + _dockData.rcRegion[CONT_LEFT].right , + _dockData.rcRegion[CONT_LEFT].bottom, + SWP_NOZORDER); + _vSplitter[CONT_LEFT]->display(); + } + (*_ppMainWindow)->reSizeTo(_rcWork); +} + +void DockingManager::createDockableDlg(tTbData data, int iCont, bool isVisible) +{ + /* add icons */ + if (data.uMask & DWS_ICONTAB) + { + /* create image list if not exist */ + if (_hImageList == NULL) + { + _hImageList = ::ImageList_Create(14,14,ILC_COLOR8, 0, 0); + } + + /* add icon */ + ::ImageList_AddIcon(_hImageList, data.hIconTab); + + /* do the reference here to find later the correct position */ + _vImageList.push_back(data.hClient); + } + + /* create additional containers if necessary */ + RECT rc = {0,0,0,0}; + DockingCont* pCont = NULL; + + /* if floated rect not set */ + if (memcmp(&data.rcFloat, &rc, sizeof(RECT)) == 0) + { + /* set default rect state */ + ::GetWindowRect(data.hClient, &data.rcFloat); + + /* test if dialog is first time created */ + if (iCont == -1) + { + /* set default visible state */ + isVisible = (::IsWindowVisible(data.hClient) == TRUE); + + if (data.uMask & DWS_DF_FLOATING) + { + /* create new container */ + pCont = new DockingCont; + _vContainer.push_back(pCont); + + /* initialize */ + pCont->init(_hInst, _hSelf); + pCont->doDialog(isVisible, true); + + /* get previous position and set container id */ + data.iPrevCont = (data.uMask & 0x30000000) >> 28; + iCont = _vContainer.size()-1; + } + else + { + /* set position */ + iCont = (data.uMask & 0x30000000) >> 28; + + /* previous container is not selected */ + data.iPrevCont = -1; + } + } + } + /* if one of the container was not created before */ + else if ((iCont >= DOCKCONT_MAX) || (data.iPrevCont >= DOCKCONT_MAX)) + { + /* test if current container is in floating state */ + if (iCont >= DOCKCONT_MAX) + { + /* no mapping for available store mapping */ + if (_iContMap[iCont] == -1) + { + /* create new container */ + pCont = new DockingCont; + _vContainer.push_back(pCont); + + /* initialize and map container id */ + pCont->init(_hInst, _hSelf); + pCont->doDialog(isVisible, true); + _iContMap[iCont] = _vContainer.size()-1; + } + + /* get current container from map */ + iCont = _iContMap[iCont]; + } + /* previous container is in floating state */ + else + { + /* no mapping for available store mapping */ + if (_iContMap[data.iPrevCont] == -1) + { + /* create new container */ + pCont = new DockingCont; + _vContainer.push_back(pCont); + + /* initialize and map container id */ + pCont->init(_hInst, _hSelf); + pCont->doDialog(false, true); + pCont->reSizeToWH(data.rcFloat); + _iContMap[data.iPrevCont] = _vContainer.size()-1; + } + data.iPrevCont = _iContMap[data.iPrevCont]; + } + } + + /* attach toolbar */ + _vContainer[iCont]->createToolbar(data, _ppMainWindow); + + /* notify client app */ + if (iCont < DOCKCONT_MAX) + SendNotify(data.hClient, MAKELONG(DMN_DOCK, iCont)); + else + SendNotify(data.hClient, MAKELONG(DMN_FLOAT, iCont)); +} + +void DockingManager::setActiveTab(int iCont, int iItem) +{ + if ((iCont == -1) || (_iContMap[iCont] == -1)) + return; + + _vContainer[_iContMap[iCont]]->setActiveTb(iItem); +} + +DockingCont* DockingManager::toggleActiveTb(DockingCont* pContSrc, UINT message, BOOL bNew, LPRECT prcFloat) +{ + tTbData TbData = *pContSrc->getDataOfActiveTb(); + int iContSrc = GetContainer(pContSrc); + int iContPrev = TbData.iPrevCont; + BOOL isCont = ContExists(iContPrev); + DockingCont* pContTgt = NULL; + + /* if new float position is given */ + if (prcFloat != NULL) + { + TbData.rcFloat = *prcFloat; + } + + if ((isCont == FALSE) || (bNew == TRUE)) + { + /* find an empty container */ + int iContNew = FindEmptyContainer(); + + if (iContNew == -1) + { + /* if no free container is available create a new one */ + pContTgt = new DockingCont; + pContTgt->init(_hInst, _hSelf); + pContTgt->doDialog(true, true); + + /* change only on toggling */ + if ((bNew == FALSE) || (!pContSrc->isFloating())) + TbData.iPrevCont = iContSrc; + + pContTgt->createToolbar(TbData, _ppMainWindow); + _vContainer.push_back(pContTgt); + } + else + { + /* set new target */ + pContTgt = _vContainer[iContNew]; + + /* change only on toggling */ + if ((pContSrc->isFloating()) != (pContTgt->isFloating())) + TbData.iPrevCont = iContSrc; + + pContTgt->createToolbar(TbData, _ppMainWindow); + } + } + else + { + /* set new target */ + pContTgt = _vContainer[iContPrev]; + + /* change data normaly */ + TbData.iPrevCont = iContSrc; + pContTgt->createToolbar(TbData, _ppMainWindow); + } + + /* notify client app */ + SendNotify(TbData.hClient, MAKELONG(message==DMM_DOCK?DMN_DOCK:DMN_FLOAT, GetContainer(pContTgt))); + + /* remove toolbar from source */ + _vContainer[iContSrc]->removeToolbar(TbData); + + return pContTgt; +} + +DockingCont* DockingManager::toggleVisTb(DockingCont* pContSrc, UINT message, LPRECT prcFloat) +{ + vector vTbData = pContSrc->getDataOfVisTb(); + tTbData* pTbData = pContSrc->getDataOfActiveTb(); + + int iContSrc = GetContainer(pContSrc); + int iContPrev = pTbData->iPrevCont; + BOOL isCont = ContExists(iContPrev); + DockingCont* pContTgt = NULL; + + /* at first hide container and resize */ + pContSrc->doDialog(false); + onSize(); + + for (size_t iTb = 0; iTb < vTbData.size(); iTb++) + { + /* get data one by another */ + tTbData TbData = *vTbData[iTb]; + + /* if new float position is given */ + if (prcFloat != NULL) + { + TbData.rcFloat = *prcFloat; + } + + if (isCont == FALSE) + { + /* create new container */ + pContTgt = new DockingCont; + pContTgt->init(_hInst, _hSelf); + pContTgt->doDialog(true, true); + + TbData.iPrevCont = iContSrc; + pContTgt->createToolbar(TbData, _ppMainWindow); + _vContainer.push_back(pContTgt); + + /* now container exists */ + isCont = TRUE; + iContPrev = GetContainer(pContTgt); + } + else + { + /* set new target */ + pContTgt = _vContainer[iContPrev]; + + TbData.iPrevCont = iContSrc; + pContTgt->createToolbar(TbData, _ppMainWindow); + } + + SendNotify(TbData.hClient, MAKELONG(message==DMM_DOCK?DMN_DOCK:DMN_FLOAT, GetContainer(pContTgt))); + + /* remove toolbar from anywhere */ + _vContainer[iContSrc]->removeToolbar(TbData); + } + + _vContainer[iContPrev]->setActiveTb(pTbData); + return pContTgt; +} + +void DockingManager::toggleActiveTb(DockingCont* pContSrc, DockingCont* pContTgt) +{ + tTbData TbData = *pContSrc->getDataOfActiveTb(); + + toggleTb(pContSrc, pContTgt, TbData); +} + +void DockingManager::toggleVisTb(DockingCont* pContSrc, DockingCont* pContTgt) +{ + vector vTbData = pContSrc->getDataOfVisTb(); + tTbData* pTbData = pContSrc->getDataOfActiveTb(); + + /* at first hide container and resize */ + pContSrc->doDialog(false); + onSize(); + + for (size_t iTb = 0; iTb < vTbData.size(); iTb++) + { + /* get data one by another */ + tTbData TbData = *vTbData[iTb]; + toggleTb(pContSrc, pContTgt, TbData); + } + pContTgt->setActiveTb(pTbData); +} + +void DockingManager::toggleTb(DockingCont* pContSrc, DockingCont* pContTgt, tTbData TbData) +{ + int iContSrc = GetContainer(pContSrc); + int iContTgt = GetContainer(pContTgt); + + /* test if container state changes from docking to floating or vice versa */ + if (((iContSrc < DOCKCONT_MAX) && (iContTgt >= DOCKCONT_MAX)) || + ((iContSrc >= DOCKCONT_MAX) && (iContTgt < DOCKCONT_MAX))) + { + /* change states */ + TbData.iPrevCont = iContSrc; + } + + /* notify client app */ + if (iContTgt < DOCKCONT_MAX) + SendNotify(TbData.hClient, MAKELONG(DMN_DOCK, iContTgt)); + else + SendNotify(TbData.hClient, MAKELONG(DMN_FLOAT, iContTgt)); + + /* create new toolbar */ + pContTgt->createToolbar(TbData, _ppMainWindow); + + /* remove toolbar from source */ + _vContainer[iContSrc]->removeToolbar(TbData); +} + +BOOL DockingManager::ContExists(size_t iCont) +{ + BOOL bRet = FALSE; + + if (iCont < _vContainer.size()) + { + bRet = TRUE; + } + + return bRet; +} + +int DockingManager::GetContainer(DockingCont* pCont) +{ + int iRet = -1; + + for (size_t iCont = 0; iCont < _vContainer.size(); iCont++) + { + if (_vContainer[iCont] == pCont) + { + iRet = iCont; + break; + } + } + + return iRet; +} + +int DockingManager::FindEmptyContainer(void) +{ + int iRetCont = -1; + BOOL* pPrevDockList = (BOOL*) new BOOL[_vContainer.size()+1]; + BOOL* pArrayPos = &pPrevDockList[1]; + + /* delete all entries */ + for (size_t iCont = 0; iCont < _vContainer.size()+1; iCont++) + { + pPrevDockList[iCont] = FALSE; + } + + /* search for used floated containers */ + for (size_t iCont = 0; iCont < DOCKCONT_MAX; iCont++) + { + vector vTbData = _vContainer[iCont]->getDataOfAllTb(); + + for (size_t iTb = 0; iTb < vTbData.size(); iTb++) + { + pArrayPos[vTbData[iTb]->iPrevCont] = TRUE; + } + } + + /* find free container */ + for (size_t iCont = DOCKCONT_MAX; iCont < _vContainer.size(); iCont++) + { + if (pArrayPos[iCont] == FALSE) + { + /* and test if container is hidden */ + if (!_vContainer[iCont]->isVisible()) + { + iRetCont = iCont; + break; + } + } + } + + delete [] pPrevDockList; + + /* search for empty arrays */ + return iRetCont; +} + + diff --git a/PowerEditor/src/WinControls/DockingWnd/DockingManager.h b/PowerEditor/src/WinControls/DockingWnd/DockingManager.h new file mode 100644 index 00000000..eef88c1b --- /dev/null +++ b/PowerEditor/src/WinControls/DockingWnd/DockingManager.h @@ -0,0 +1,213 @@ +//this file is part of docking functionality for Notepad++ +//Copyright (C)2006 Jens Lorenz +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef DOCKINGMANAGER_H +#define DOCKINGMANAGER_H + +#include "Docking.h" +#include "Window.h" +#include "DockingCont.h" +#include "DockingSplitter.h" +#include +#include +#include "SplitterContainer.h" +#include "dockingResource.h" +#include "Parameters.h" + +#define DSPC_CLASS_NAME TEXT("dockingManager") + +using namespace std; + + +#define CONT_MAP_MAX 50 + + +class DockingManager : public Window +{ +public : + DockingManager(); + ~DockingManager(){ + // delete 4 splitters + for (int i = 0; i < DOCKCONT_MAX; i++) + { + delete _vSplitter[i]; + } + }; + + void init(HINSTANCE hInst, HWND hWnd, Window ** ppWin); + virtual void reSizeTo(RECT & rc); + + void setClientWnd(Window ** ppWin) { + _ppWindow = ppWin; + _ppMainWindow = ppWin; + }; + + void showContainer(HWND hCont, BOOL view = TRUE) { + for (size_t iCont = 0; iCont < _vContainer.size(); iCont++) + { + if (_vContainer[iCont]->getHSelf() == hCont) + showContainer(iCont, view); + } + } + + void showContainer(UINT uCont, BOOL view = TRUE) { + _vContainer[uCont]->doDialog((view == TRUE)); + onSize(); + } + + void updateContainerInfo(HWND hClient) { + for (size_t iCont = 0; iCont < _vContainer.size(); iCont++) + { + if (_vContainer[iCont]->updateInfo(hClient) == TRUE) + { + break; + } + } + }; + + void createDockableDlg(tTbData data, int iCont = CONT_LEFT, bool isVisible = false); + void setActiveTab(int iCont, int iItem); + + void showDockableDlg(HWND hDlg, BOOL view) { + tTbData* pTbData = NULL; + + for (size_t i = 0; i < _vContainer.size(); i++) + { + pTbData = _vContainer[i]->findToolbarByWnd(hDlg); + if (pTbData != NULL) + { + _vContainer[i]->showToolbar(pTbData, view); + return; + } + } + }; + + void showDockableDlg(TCHAR* pszName, BOOL view) { + tTbData* pTbData = NULL; + + for (size_t i = 0; i < _vContainer.size(); i++) + { + pTbData = _vContainer[i]->findToolbarByName(pszName); + if (pTbData != NULL) + { + _vContainer[i]->showToolbar(pTbData, view); + return; + } + } + }; + + DockingCont* toggleActiveTb(DockingCont* pContSrc, UINT message, BOOL bNew = FALSE, LPRECT rcFloat = NULL); + DockingCont* toggleVisTb(DockingCont* pContSrc, UINT message, LPRECT rcFloat = NULL); + void toggleActiveTb(DockingCont* pContSrc, DockingCont* pContTgt); + void toggleVisTb(DockingCont* pContSrc, DockingCont* pContTgt); + + /* get number of container */ + int GetContainer(DockingCont* pCont); + + /* get all container in vector */ + vector & getContainerInfo(void) { + return _vContainer; + }; + /* get dock data (sized areas) */ + void getDockInfo(tDockMgr *pDockData) { + *pDockData = _dockData; + }; + + /* setting styles of docking */ + void setStyleCaption(BOOL captionOnTop) { + _vContainer[CONT_TOP]->setCaptionTop(captionOnTop); + _vContainer[CONT_BOTTOM]->setCaptionTop(captionOnTop); + }; + + void setTabStyle(BOOL orangeLine) { + for (size_t i = 0; i < _vContainer.size(); i++) + _vContainer[i]->setTabStyle(orangeLine); + }; + + int getDockedContSize(int iCont) + { + if ((iCont == CONT_TOP) || (iCont == CONT_BOTTOM)) + return _dockData.rcRegion[iCont].bottom; + else if ((iCont == CONT_LEFT) || (iCont == CONT_RIGHT)) + return _dockData.rcRegion[iCont].right; + else + return -1; + }; + + void setDockedContSize(int iCont, int iSize) + { + if ((iCont == CONT_TOP) || (iCont == CONT_BOTTOM)) + _dockData.rcRegion[iCont].bottom = iSize; + else if ((iCont == CONT_LEFT) || (iCont == CONT_RIGHT)) + _dockData.rcRegion[iCont].right = iSize; + else + return; + onSize(); + }; + + virtual void destroy() { + ::DestroyWindow(_hSelf); + }; + +private : + + static LRESULT CALLBACK staticWinProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam); + LRESULT runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam); + void onSize(void); + + void toggleTb(DockingCont* pContSrc, DockingCont* pContTgt, tTbData TbData); + + /* test if container exists */ + BOOL ContExists(size_t iCont); + int FindEmptyContainer(void); + + LRESULT SendNotify(HWND hWnd, UINT message) { + NMHDR nmhdr; + + nmhdr.code = message; + nmhdr.hwndFrom = _hParent; + nmhdr.idFrom = ::GetDlgCtrlID(_hParent); + ::SendMessage(hWnd, WM_NOTIFY, nmhdr.idFrom, (LPARAM)&nmhdr); + return ::GetWindowLongPtr(hWnd, DWL_MSGRESULT); + }; + +private: + /* Handles */ + Window **_ppWindow; + + RECT _rcWork; + RECT _rect; + Window **_ppMainWindow; + + /* handles all the icons */ + vector _vImageList; + HIMAGELIST _hImageList; + + vector _vContainer; + tDockMgr _dockData; + + static BOOL _isRegistered; + BOOL _isInitialized; + + /* container map for startup (restore settings) */ + int _iContMap[CONT_MAP_MAX]; + + /* splitter data */ + vector _vSplitter; +}; + +#endif //DOCKINGMANAGER_H diff --git a/PowerEditor/src/WinControls/DockingWnd/DockingSplitter.cpp b/PowerEditor/src/WinControls/DockingWnd/DockingSplitter.cpp new file mode 100644 index 00000000..c93d0153 --- /dev/null +++ b/PowerEditor/src/WinControls/DockingWnd/DockingSplitter.cpp @@ -0,0 +1,207 @@ +//this file is part of docking functionality for Notepad++ +//Copyright (C)2006 Jens Lorenz +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +#include "DockingSplitter.h" +#include "Common.h" +#include "Notepad_plus_msgs.h" +#include "Parameters.h" + +BOOL DockingSplitter::_isVertReg = FALSE; +BOOL DockingSplitter::_isHoriReg = FALSE; + +static HWND hWndMouse = NULL; +static HHOOK hookMouse = NULL; + +#ifndef WH_MOUSE_LL +#define WH_MOUSE_LL 14 +#endif + +static LRESULT CALLBACK hookProcMouse(UINT nCode, WPARAM wParam, LPARAM lParam) +{ + if(nCode >= 0) + { + switch (wParam) + { + case WM_MOUSEMOVE: + case WM_NCMOUSEMOVE: + ::PostMessage(hWndMouse, wParam, 0, 0); + break; + case WM_LBUTTONUP: + case WM_NCLBUTTONUP: + ::PostMessage(hWndMouse, wParam, 0, 0); + return TRUE; + default: + break; + } + } + + return ::CallNextHookEx(hookMouse, nCode, wParam, lParam); +} + +void DockingSplitter::init(HINSTANCE hInst, HWND hWnd, HWND hMessage, UINT flags) +{ + Window::init(hInst, hWnd); + _hMessage = hMessage; + _flags = flags; + + WNDCLASS wc; + + if (flags & DMS_HORIZONTAL) + { + //double sided arrow pointing north-south as cursor + wc.hCursor = ::LoadCursor(NULL,IDC_SIZENS); + wc.lpszClassName = TEXT("nsdockspliter"); + } + else + { + // double sided arrow pointing east-west as cursor + wc.hCursor = ::LoadCursor(NULL,IDC_SIZEWE); + wc.lpszClassName = TEXT("wedockspliter"); + } + + if (((_isHoriReg == FALSE) && (flags & DMS_HORIZONTAL)) || + ((_isVertReg == FALSE) && (flags & DMS_VERTICAL))) + { + wc.style = CS_HREDRAW | CS_VREDRAW; + wc.lpfnWndProc = staticWinProc; + wc.cbClsExtra = 0; + wc.cbWndExtra = 0; + wc.hInstance = _hInst; + wc.hIcon = NULL; + wc.hbrBackground = (HBRUSH)(COLOR_3DFACE+1); + wc.lpszMenuName = NULL; + + if (!::RegisterClass(&wc)) + { + systemMessage(TEXT("System Err")); + throw int(98); + } + else if (flags & DMS_HORIZONTAL) + { + _isHoriReg = TRUE; + } + else + { + _isVertReg = TRUE; + } + } + + /* create splitter windows and initialize it */ + _hSelf = ::CreateWindowEx( 0, wc.lpszClassName, TEXT(""), WS_CHILD | WS_VISIBLE, + CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, + _hParent, NULL, _hInst, (LPVOID)this); + + if (!_hSelf) + { + systemMessage(TEXT("System Err")); + throw int(777); + } +} + + + +LRESULT CALLBACK DockingSplitter::staticWinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + DockingSplitter *pDockingSplitter = NULL; + switch (message) + { + case WM_NCCREATE : + pDockingSplitter = (DockingSplitter *)(((LPCREATESTRUCT)lParam)->lpCreateParams); + pDockingSplitter->_hSelf = hwnd; + ::SetWindowLongPtr(hwnd, GWL_USERDATA, reinterpret_cast(pDockingSplitter)); + return TRUE; + + default : + pDockingSplitter = (DockingSplitter *)::GetWindowLongPtr(hwnd, GWL_USERDATA); + if (!pDockingSplitter) + return ::DefWindowProc(hwnd, message, wParam, lParam); + return pDockingSplitter->runProc(hwnd, message, wParam, lParam); + } +} + + +LRESULT DockingSplitter::runProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + switch (message) + { + case WM_LBUTTONDOWN: + { + hWndMouse = hwnd; + + winVer ver = (NppParameters::getInstance())->getWinVersion(); + hookMouse = ::SetWindowsHookEx(ver >= WV_W2K?WH_MOUSE_LL:WH_MOUSE, (HOOKPROC)hookProcMouse, _hInst, 0); + + + if (!hookMouse) + { + DWORD dwError = ::GetLastError(); + TCHAR str[128]; + ::wsprintf(str, TEXT("GetLastError() returned %lu"), dwError); + ::MessageBox(NULL, str, TEXT("SetWindowsHookEx(MOUSE) failed"), MB_OK | MB_ICONERROR); + } + else + { + ::SetCapture(_hSelf); + ::GetCursorPos(&_ptOldPos); + _isLeftButtonDown = TRUE; + } + break; + } + case WM_LBUTTONUP: + case WM_NCLBUTTONUP: + { + /* end hooking */ + if (hookMouse) + { + ::UnhookWindowsHookEx(hookMouse); + ::SetCapture(NULL); + hookMouse = NULL; + } + _isLeftButtonDown = FALSE; + break; + } + case WM_MOUSEMOVE: + case WM_NCMOUSEMOVE: + { + if (_isLeftButtonDown == TRUE) + { + POINT pt; + + ::GetCursorPos(&pt); + + if ((_flags & DMS_HORIZONTAL) && (_ptOldPos.y != pt.y)) + { + ::SendMessage(_hMessage, DMM_MOVE_SPLITTER, (WPARAM)_ptOldPos.y - pt.y, (LPARAM)_hSelf); + } + else if (_ptOldPos.x != pt.x) + { + ::SendMessage(_hMessage, DMM_MOVE_SPLITTER, (WPARAM)_ptOldPos.x - pt.x, (LPARAM)_hSelf); + } + _ptOldPos = pt; + } + break; + } + default : + break; + } + return ::DefWindowProc(hwnd, message, wParam, lParam); +} + + + + diff --git a/PowerEditor/src/WinControls/DockingWnd/DockingSplitter.h b/PowerEditor/src/WinControls/DockingWnd/DockingSplitter.h new file mode 100644 index 00000000..7aa047c5 --- /dev/null +++ b/PowerEditor/src/WinControls/DockingWnd/DockingSplitter.h @@ -0,0 +1,59 @@ +//this file is part of docking functionality for Notepad++ +//Copyright (C)2006 Jens Lorenz +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +#ifndef DOCKINGSPLITTER_H +#define DOCKINGSPLITTER_H + +#include "Docking.h" +#include "dockingResource.h" +#include "window.h" + + +#define DMS_VERTICAL 0x00000001 +#define DMS_HORIZONTAL 0x00000002 + + + +class DockingSplitter : public Window +{ +public : + DockingSplitter() : _isLeftButtonDown(FALSE), _hMessage(NULL) {}; + ~DockingSplitter(){}; + + virtual void destroy() {}; + +public: + void init(HINSTANCE hInst, HWND hWnd, HWND hMessage, UINT flags); + +protected: + + static LRESULT CALLBACK staticWinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); + LRESULT runProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); + +private: + HWND _hMessage; + + BOOL _isLeftButtonDown; + POINT _ptOldPos; + UINT _flags; + + static BOOL _isVertReg; + static BOOL _isHoriReg; +}; + +#endif // DOCKINGSPLITTER_H diff --git a/PowerEditor/src/WinControls/DockingWnd/DropData.cpp.bak b/PowerEditor/src/WinControls/DockingWnd/DropData.cpp.bak new file mode 100644 index 00000000..bf820039 --- /dev/null +++ b/PowerEditor/src/WinControls/DockingWnd/DropData.cpp.bak @@ -0,0 +1,214 @@ +//this file is part of docking functionality for Notepad++ +//Copyright (C)2006 Jens Lorenz +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#include "DropData.h" +#include +#include +#include "dockingResource.h" + +DropData::DropData(HWND hWnd, DockingCont* pCont) +{ + _lRefCount = 1; + _pCont = pCont; + _hWnd = hWnd; + _pAreasData = NULL; + _hTab = _pCont->getTabWnd(); + _hCaption = _pCont->getCaptionWnd(); +} + +DropData::~DropData() +{ + if (_pAreasData != NULL) + { + delete [] _pAreasData; + } +} + +HRESULT __stdcall DropData::QueryInterface (REFIID iid, void ** ppvObject) +{ + if(iid == IID_IDropTarget || iid == IID_IUnknown) + { + AddRef(); + *ppvObject = this; + return S_OK; + } + else + { + *ppvObject = 0; + return E_NOINTERFACE; + } +} + +ULONG __stdcall DropData::AddRef(void) +{ + return InterlockedIncrement(&_lRefCount); +} + +ULONG __stdcall DropData::Release(void) +{ + LONG count = InterlockedDecrement(&_lRefCount); + + if(count == 0) + { + delete this; + return 0; + } + else + { + return count; + } +} + +DWORD DropData::DropEffect(DWORD grfKeyState, POINTL ptl, DWORD dwAllowed) +{ + DWORD dwEffect = DROPEFFECT_NONE; + POINT pt = {ptl.x, ptl.y}; + + for (int iElem = 0; iElem < _iElemCnt; iElem++) + { + /* test if cursor points in a rect */ + if (::PtInRect(&_pAreasData[iElem].rcDropArea, pt) == TRUE) + { + dwEffect = DROPEFFECT_COPY; + break; + } + } + + return dwEffect; +} + +HRESULT __stdcall DropData::DragEnter(IDataObject * pDataObject, DWORD grfKeyState, POINTL ptl, DWORD * pdwEffect) +{ + int iItem = 0; + int iItemCnt = 0; + TCITEM tcItem = {0}; + + /* initial element count */ + _iElemCnt = 0; + + /* get amount of element in tab and add caption */ + iItemCnt = ::SendMessage(_hTab, TCM_GETITEMCOUNT, 0, 0) + 1; + + /* allocate resources */ + _pAreasData = (tAreaData*) new tAreaData[iItemCnt]; + + /* get allowed areas */ + tcItem.mask = TCIF_PARAM; + + if (::IsWindowVisible(_hTab) == TRUE) + { + /* get possible areas for all tabs */ + for (iItem = 0; iItem < (iItemCnt - 1); iItem++) + { + ::SendMessage(_hTab, TCM_GETITEM, iItem, (LPARAM)&tcItem); + + if (((tTbData*)tcItem.lParam)->uMask & DWS_ACCEPTDATA) + { + if (pDataObject->QueryGetData(((tTbData*)tcItem.lParam)->pFETC) == S_OK) + { + _pAreasData[_iElemCnt].targetWnd = ((tTbData*)tcItem.lParam)->hClient; + ::SendMessage(_hTab, TCM_GETITEMRECT, iItem, (LPARAM)&_pAreasData[_iElemCnt].rcDropArea); + ClientToScreen(_hTab, &_pAreasData[_iElemCnt++].rcDropArea); + } + } + } + } + + /* get caption area when current selected tab allowes data drop */ + iItem = ::SendMessage(_hTab, TCM_GETCURSEL, 0, 0); + ::SendMessage(_hTab, TCM_GETITEM, iItem, (LPARAM)&tcItem); + if (((tTbData*)tcItem.lParam)->uMask & DWS_ACCEPTDATA) + { + if (pDataObject->QueryGetData(((tTbData*)tcItem.lParam)->pFETC) == S_OK) + { + _pAreasData[_iElemCnt].targetWnd = ((tTbData*)tcItem.lParam)->hClient; + + if (_pCont->isFloating()) + { + _pCont->getWindowRect(_pAreasData[_iElemCnt].rcDropArea); + _pAreasData[_iElemCnt].rcDropArea.bottom = _pAreasData[_iElemCnt].rcDropArea.top + 24; + } + else + { + ::GetWindowRect(_hCaption, &_pAreasData[_iElemCnt].rcDropArea); + } + _iElemCnt++; + } + } + + *pdwEffect = DropEffect(grfKeyState, ptl, *pdwEffect); + + return S_OK; +} + +HRESULT __stdcall DropData::DragOver(DWORD grfKeyState, POINTL ptl, DWORD * pdwEffect) +{ + *pdwEffect = DropEffect(grfKeyState, ptl, *pdwEffect); + + return S_OK; +} + +HRESULT __stdcall DropData::DragLeave(void) +{ + return S_OK; +} + +HRESULT __stdcall DropData::Drop(IDataObject * pDataObject, DWORD grfKeyState, POINTL ptl, DWORD * pdwEffect) +{ + POINT pt = {ptl.x, ptl.y}; + + /* initial elements */ + *pdwEffect = DROPEFFECT_NONE; + + for (int iElem = 0; iElem < _iElemCnt; iElem++) + { + /* test if cursor points in a rect */ + if (::PtInRect(&_pAreasData[iElem].rcDropArea, (POINT)pt) == TRUE) + { + /* notify child windows */ + ::SendMessage(_pAreasData[iElem].targetWnd, LMM_DROPDATA, 0, (LPARAM)pDataObject); + + *pdwEffect = DROPEFFECT_COPY; + break; + } + } + + return S_OK; +} + +void RegisterDropWindow(HWND hwnd, DockingCont* pCont, IDropTarget **ppDropTarget) +{ + DropData *pDropTarget = new DropData(hwnd, pCont); + + // tell OLE that the window is a drop target + ::RegisterDragDrop(hwnd, pDropTarget); + + *ppDropTarget = pDropTarget; +} + +void UnregisterDropWindow(HWND hwnd, IDropTarget *pDropTarget) +{ + // remove drag+drop + ::RevokeDragDrop(hwnd); + + // remove the strong lock + CoLockObjectExternal(pDropTarget, FALSE, TRUE); + + // release our own reference + pDropTarget->Release(); +} + diff --git a/PowerEditor/src/WinControls/DockingWnd/DropData.h b/PowerEditor/src/WinControls/DockingWnd/DropData.h new file mode 100644 index 00000000..4f4a264b --- /dev/null +++ b/PowerEditor/src/WinControls/DockingWnd/DropData.h @@ -0,0 +1,74 @@ +//this file is part of docking functionality for Notepad++ +//Copyright (C)2006 Jens Lorenz +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +#ifndef DROP_TARGET_H +#define DROP_TARGET_H + +#include "DockingCont.h" +#include + + +void RegisterDropWindow(HWND hwnd, DockingCont* pCont, IDropTarget **ppDropTarget); +void UnregisterDropWindow(HWND hwnd, IDropTarget *pDropTarget); + + +typedef struct { + HWND targetWnd; + RECT rcDropArea; +} tAreaData; + + +class DropData : public IDropTarget +{ +public: + /* IUnknown implementation */ + HRESULT __stdcall QueryInterface(REFIID iid, void** ppvObject); + ULONG __stdcall AddRef(void); + ULONG __stdcall Release(void); + + /* IDropTarget implementation */ + HRESULT __stdcall DragEnter(IDataObject* pDataObject, DWORD grfKeyState, POINTL pt, DWORD* pdwEffect); + HRESULT __stdcall DragOver(DWORD grfKeyState, POINTL pt, DWORD* pdwEffect); + HRESULT __stdcall DragLeave(void); + HRESULT __stdcall Drop(IDataObject* pDataObject, DWORD grfKeyState, POINTL pt, DWORD* pdwEffect); + + // Constructor + DropData(HWND hwnd, DockingCont* pCont); + ~DropData(); + +private: + /* internal helper function */ + DWORD DropEffect(DWORD grfKeyState, POINTL pt, DWORD dwAllowed); + bool QueryDataObject(IDataObject *pDataObject); + + +private: + LONG _lRefCount; + + HWND _hWnd; + HWND _hCaption; + HWND _hTab; + + DockingCont* _pCont; + + tAreaData* _pAreasData; + int _iElemCnt; +}; + + +#endif // DROP_TARGET_H \ No newline at end of file diff --git a/PowerEditor/src/WinControls/DockingWnd/Gripper.cpp b/PowerEditor/src/WinControls/DockingWnd/Gripper.cpp new file mode 100644 index 00000000..214b8088 --- /dev/null +++ b/PowerEditor/src/WinControls/DockingWnd/Gripper.cpp @@ -0,0 +1,793 @@ +//this file is part of docking functionality for Notepad++ +//Copyright (C)2006 Jens Lorenz +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +#include "dockingResource.h" +#include "math.h" +#include "Docking.h" +#include "Gripper.h" + +#ifndef WH_KEYBOARD_LL +#define WH_KEYBOARD_LL 13 +#endif + +#ifndef WH_MOUSE_LL +#define WH_MOUSE_LL 14 +#endif + + +BOOL Gripper::_isRegistered = FALSE; + +static HWND hWndServer = NULL; +static HHOOK hookMouse = NULL; +static HHOOK hookKeyboard = NULL; + +static LRESULT CALLBACK hookProcMouse(INT nCode, WPARAM wParam, LPARAM lParam) +{ + if (nCode >= 0) + { + switch (wParam) + { + case WM_MOUSEMOVE: + case WM_NCMOUSEMOVE: + //::PostMessage(hWndServer, wParam, 0, 0); + ::SendMessage(hWndServer, wParam, 0, 0); + break; + case WM_LBUTTONUP: + case WM_NCLBUTTONUP: + //::PostMessage(hWndServer, wParam, 0, 0); + ::SendMessage(hWndServer, wParam, 0, 0); + return TRUE; + default: + break; + } + } + return ::CallNextHookEx(hookMouse, nCode, wParam, lParam); +} + +static LRESULT CALLBACK hookProcKeyboard(INT nCode, WPARAM wParam, LPARAM lParam) +{ + if (nCode >= 0) + { + if (wParam == VK_ESCAPE) + { + ::PostMessage(hWndServer, DMM_CANCEL_MOVE, 0, 0); + return FALSE; + } + } + + return ::CallNextHookEx(hookKeyboard, nCode, wParam, lParam); +} + +Gripper::Gripper(void) +{ + _hInst = NULL; + _hParent = NULL; + _hSelf = NULL; + + _pDockMgr = NULL; + _pCont = NULL; + + _ptOffset.x = 0; + _ptOffset.y = 0; + + _ptOld.x = 0; + _ptOld.y = 0; + _bPtOldValid = FALSE; + + _hTab = NULL; + _hTabSource = NULL; + _startMovingFromTab = FALSE; + _iItem = 0; + + _hdc = NULL; + _hbm = NULL; + _hbrush = NULL; + + + memset(&_rcItem, 0, sizeof(RECT)); + memset(&_tcItem, 0, sizeof(TCITEM)); + memset(&_dockData, 0, sizeof(tDockMgr)); +} + + +void Gripper::startGrip(DockingCont* pCont, DockingManager* pDockMgr, void* pRes) +{ + MSG msg = {0}; + BOOL bIsRel = FALSE; + HWND hWnd = NULL; + + _pDockMgr = pDockMgr; + _pCont = pCont; + _pRes = pRes; + + _pDockMgr->getDockInfo(&_dockData); + + if (!_isRegistered) + { + WNDCLASS clz; + + clz.style = 0; + clz.lpfnWndProc = staticWinProc; + clz.cbClsExtra = 0; + clz.cbWndExtra = 0; + clz.hInstance = _hInst; + clz.hIcon = NULL; + clz.hCursor = ::LoadCursor(NULL, IDC_ARROW); + + clz.hbrBackground = NULL; + clz.lpszMenuName = NULL; + clz.lpszClassName = MDLG_CLASS_NAME; + + if (!::RegisterClass(&clz)) + { + systemMessage(TEXT("System Err")); + throw int(98); + } + _isRegistered = TRUE; + } + + _hSelf = ::CreateWindowEx( + 0, + MDLG_CLASS_NAME, + TEXT(""), 0, + CW_USEDEFAULT, CW_USEDEFAULT, + CW_USEDEFAULT, CW_USEDEFAULT, + NULL, + NULL, + _hInst, + (LPVOID)this); + hWndServer = _hSelf; + + if (!_hSelf) + { + systemMessage(TEXT("System Err")); + throw int(777); + } +} + + +LRESULT CALLBACK Gripper::staticWinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + Gripper *pDlgMoving = NULL; + switch (message) + { + case WM_NCCREATE : + pDlgMoving = (Gripper *)(((LPCREATESTRUCT)lParam)->lpCreateParams); + pDlgMoving->_hSelf = hwnd; + ::SetWindowLongPtr(hwnd, GWL_USERDATA, reinterpret_cast(pDlgMoving)); + return TRUE; + + default : + pDlgMoving = (Gripper *)::GetWindowLongPtr(hwnd, GWL_USERDATA); + if (!pDlgMoving) + return ::DefWindowProc(hwnd, message, wParam, lParam); + return pDlgMoving->runProc(message, wParam, lParam); + } +} + +LRESULT Gripper::runProc(UINT message, WPARAM wParam, LPARAM lParam) +{ + switch (message) + { + case WM_CREATE: + { + create(); + break; + } + case WM_MOUSEMOVE: + case WM_NCMOUSEMOVE: + { + onMove(); + return TRUE; + } + case WM_LBUTTONUP: + case WM_NCLBUTTONUP: + { + /* end hooking */ + if (hookMouse) + { + ::UnhookWindowsHookEx(hookMouse); + ::UnhookWindowsHookEx(hookKeyboard); + hookMouse = NULL; + hookKeyboard = NULL; + } + + onButtonUp(); + + ::DestroyWindow(_hSelf); + return TRUE; + } + case DMM_CANCEL_MOVE: + { + POINT pt = {0,0}; + POINT ptBuf = {0,0}; + RECT rc = {0}; + + ::GetCursorPos(&pt); + getMousePoints(&pt, &ptBuf); + + /* erase last drawn rectangle */ + drawRectangle(ptBuf); + + /* end hooking */ + ::UnhookWindowsHookEx(hookMouse); + ::UnhookWindowsHookEx(hookKeyboard); + + ::DestroyWindow(_hSelf); + return FALSE; + } + case WM_DESTROY: + { + mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); + ::SetWindowPos(_hParent, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE); + _pCont->focusClient(); + delete _pRes; + break; + } + default: + break; + } + + return ::DefWindowProc(_hSelf, message, wParam, lParam); +} + + +void Gripper::create(void) +{ + RECT rc = {0}; + POINT pt = {0}; + + // start hooking + ::SetWindowPos(_pCont->getHSelf(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE); + ::SetCapture(_hSelf); + winVer ver = (NppParameters::getInstance())->getWinVersion(); + hookMouse = ::SetWindowsHookEx(ver >= WV_W2K?WH_MOUSE_LL:WH_MOUSE, (HOOKPROC)hookProcMouse, _hInst, 0); + + if (!hookMouse) + { + DWORD dwError = ::GetLastError(); + TCHAR str[128]; + ::wsprintf(str, TEXT("GetLastError() returned %lu"), dwError); + ::MessageBox(NULL, str, TEXT("SetWindowsHookEx(MOUSE) failed"), MB_OK | MB_ICONERROR); + } + + if (ver < WV_VISTA) + { + hookKeyboard = ::SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC)hookProcKeyboard, _hInst, 0); + if (!hookKeyboard) + { + DWORD dwError = ::GetLastError(); + TCHAR str[128]; + ::wsprintf(str, TEXT("GetLastError() returned %lu"), dwError); + ::MessageBox(NULL, str, TEXT("SetWindowsHookEx(KEYBOARD) failed"), MB_OK | MB_ICONERROR); + } + } +// Removed regarding W9x systems +// mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); + + // calculate the mouse pt within dialog + ::GetCursorPos(&pt); + + // get tab informations + initTabInformation(pt); + + if (_pCont->isFloating() == true) + { + ::GetWindowRect(_pCont->getHSelf(), &rc); + } + else + { + _pCont->getClientRect(rc); + ::ScreenToClient(_pCont->getHSelf(), &pt); + } + + _ptOffset.x = pt.x - rc.left; + _ptOffset.y = pt.y - rc.top; +} + + +void Gripper::onMove(void) +{ + POINT pt = {0,0}; + POINT ptBuf = {0,0}; + + ::GetCursorPos(&pt); + getMousePoints(&pt, &ptBuf); + + /* On first time: Do not erase previous rect, because it dosn't exist */ + if (_bPtOldValid == TRUE) + drawRectangle(ptBuf); + + /* tab reordering only when tab was selected */ + if (_startMovingFromTab == TRUE) + { + doTabReordering(pt); + } + + drawRectangle(pt); + _bPtOldValid = TRUE; +} + + +void Gripper::onButtonUp(void) +{ + POINT pt = {0,0}; + POINT ptBuf = {0,0}; + RECT rc = {0}; + RECT rcCorr = {0}; + DockingCont* pContMove = NULL; + + ::GetCursorPos(&pt); + getMousePoints(&pt, &ptBuf); + + /* do nothing, when old point is not valid */ + if (_bPtOldValid == FALSE) + return; + + /* erase last drawn rectangle */ + drawRectangle(ptBuf); + + /* look if current position is within dockable area */ + DockingCont* pDockCont = contHitTest(pt); + + if (pDockCont == NULL) + { + pDockCont = workHitTest(pt); + } + + /* add dependency to other container class */ + if (pDockCont == NULL) + { + /* calculate new position */ + rc = _pCont->getDataOfActiveTb()->rcFloat; + _pCont->getClientRect(rcCorr); + + CalcRectToScreen(_dockData.hWnd, &rc); + CalcRectToScreen(_dockData.hWnd, &rcCorr); + + rc.left = pt.x - _ptOffset.x; + rc.top = pt.y - _ptOffset.y; + + /* correct rectangle position when mouse is not within */ + DoCalcGripperRect(&rc, rcCorr, pt); + + /* change location of toolbars */ + if (_startMovingFromTab == TRUE) + { + /* when tab is moved */ + if ((!_pCont->isFloating()) || + ((_pCont->isFloating()) && (::SendMessage(_hTabSource, TCM_GETITEMCOUNT, 0, 0) > 1))) + { + pContMove = _pDockMgr->toggleActiveTb(_pCont, DMM_FLOAT, TRUE, &rc); + } + } + else if (!_pCont->isFloating()) + { + /* when all windows are moved */ + pContMove = _pDockMgr->toggleVisTb(_pCont, DMM_FLOAT, &rc); + } + + /* set moving container */ + if (pContMove == NULL) + { + pContMove = _pCont; + } + + /* update window position */ + ::MoveWindow(pContMove->getHSelf(), rc.left, rc.top, rc.right, rc.bottom, TRUE); + ::SendMessage(pContMove->getHSelf(), WM_SIZE, 0, 0); + } + else if (_pCont != pDockCont) + { + /* change location of toolbars */ + if ((_startMovingFromTab == TRUE) && (::SendMessage(_hTabSource, TCM_GETITEMCOUNT, 0, 0) != 1)) + { + /* when tab is moved */ + _pDockMgr->toggleActiveTb(_pCont, pDockCont); + } + else + { + /* when all windows are moved */ + _pDockMgr->toggleVisTb(_pCont, pDockCont); + } + } +} + + +void Gripper::doTabReordering(POINT pt) +{ + vector vCont = _pDockMgr->getContainerInfo(); + BOOL inTab = FALSE; + HWND hTab = NULL; + HWND hTabOld = _hTab; + int iItem = -1; + int iItemOld = _iItem; + + /* search for every tab entry */ + for (size_t iCont = 0; iCont < vCont.size(); iCont++) + { + hTab = vCont[iCont]->getTabWnd(); + + /* search only if container is visible */ + if (::IsWindowVisible(hTab) == TRUE) + { + RECT rc = {0}; + + ::GetWindowRect(hTab, &rc); + + /* test if cursor points in tab window */ + if (::PtInRect(&rc, pt) == TRUE) + { + TCHITTESTINFO info = {0}; + TCITEM tcItem = {0}; + + if (_hTab == NULL) + { + initTabInformation(pt); + hTabOld = _hTab; + iItemOld = _iItem; + } + + /* get pointed tab item */ + info.pt = pt; + ::ScreenToClient(hTab, &info.pt); + iItem = ::SendMessage(hTab, TCM_HITTEST, 0, (LPARAM)&info); + + if (iItem != -1) + { + /* prevent flickering of tabs with different sizes */ + ::SendMessage(hTab, TCM_GETITEMRECT, iItem, (LPARAM)&rc); + ClientRectToScreenRect(hTab, &rc); + + if ((rc.left + (_rcItem.right - _rcItem.left)) < pt.x) + { + return; + } + + _iItem = iItem; + } + else if ((hTab != _hTab) || (_iItem == -1)) + { + /* test if cusor points after last tab */ + int iLastItem = ::SendMessage(hTab, TCM_GETITEMCOUNT, 0, 0) - 1; + + ::SendMessage(hTab, TCM_GETITEMRECT, iLastItem, (LPARAM)&rc); + if ((rc.left + rc.right) < pt.x) + { + _iItem = iLastItem + 1; + } + } + + _hTab = hTab; + inTab = TRUE; + break; + } + } + } + + /* set and remove tabs correct */ + if ((inTab == TRUE) && (iItemOld != _iItem)) + { + if (_hTab == _hTabSource) + { + /* delete item if switching back to source tab */ + int iSel = ::SendMessage(_hTab, TCM_GETCURSEL, 0, 0); + ::SendMessage(_hTab, TCM_DELETEITEM, iSel, 0); + } + else if (_hTab == hTabOld) + { + /* delete item on switch between tabs */ + ::SendMessage(_hTab, TCM_DELETEITEM, iItemOld, 0); + } + else + { + if (_hTab == hTabOld) + { + /* delete item on switch between tabs */ + ::SendMessage(_hTab, TCM_DELETEITEM, iItemOld, 0); + } + } + } + else if (inTab == FALSE) + { + if (hTabOld != _hTabSource) + { + ::SendMessage(hTabOld, TCM_DELETEITEM, iItemOld, 0); + } + _iItem = -1; + } + + /* insert new entry when mouse doesn't point to current hovered tab */ + if ((_hTab != hTabOld) || (_iItem != iItemOld)) + { + _tcItem.mask = TCIF_PARAM | (_hTab == _hTabSource ? TCIF_TEXT : 0); + ::SendMessage(_hTab, TCM_INSERTITEM, _iItem, (LPARAM)&_tcItem); + } + + /* select the tab only in source tab window */ + if ((_hTab == _hTabSource) && (_iItem != -1)) + { + ::SendMessage(_hTab, TCM_SETCURSEL, _iItem, 0); + } + +#if 0 + extern HWND g_hMainWnd; + TCHAR str[128]; + wsprintf(str, TEXT("Size: %i"), vCont.size()); + ::SetWindowText(g_hMainWnd, str); +#endif + + ::UpdateWindow(_hParent); +} + + +void Gripper::drawRectangle(POINT pt) +{ + HANDLE hbrushOrig = NULL; + RECT rc = {0}; + + if (!_hdc) + _hdc = ::GetDC(NULL); + + // Create a brush with the appropriate bitmap pattern to draw our drag rectangle + if (!_hbm) + _hbm = ::CreateBitmap(8, 8, 1, 1, DotPattern); + if (!_hbrush) + _hbrush = ::CreatePatternBrush(_hbm); + + + // Determine whether to draw a solid drag rectangle or checkered + getMovingRect(pt, &rc); + + ::SetBrushOrgEx(_hdc, rc.left, rc.top, 0); + hbrushOrig = ::SelectObject(_hdc, _hbrush); + + // line: left + ::PatBlt(_hdc, rc.left, rc.top, 3, rc.bottom - 3, PATINVERT); + // line: top + ::PatBlt(_hdc, rc.left + 3, rc.top, rc.right - 3, 3, PATINVERT); + // line: right + ::PatBlt(_hdc, rc.left + rc.right - 3, rc.top + 3, 3, rc.bottom - 3, PATINVERT); + // line: bottom + ::PatBlt(_hdc, rc.left, rc.top + rc.bottom - 3, rc.right - 3, 3, PATINVERT); + + // destroy resources + ::SelectObject(_hdc, hbrushOrig); + +} + + +void Gripper::getMousePoints(POINT* pt, POINT* ptPrev) +{ + *ptPrev = _ptOld; + _ptOld = *pt; +} + + +void Gripper::getMovingRect(POINT pt, RECT *rc) +{ + RECT rcCorr = {0}; + DockingCont* pContHit = NULL; + + /* test if mouse hits a container */ + pContHit = contHitTest(pt); + + if (pContHit != NULL) + { + /* get rect of client */ + ::GetWindowRect(pContHit->getHSelf(), rc); + + /* get rect for correction */ + if (_pCont->isFloating() == TRUE) + rcCorr = _pCont->getDataOfActiveTb()->rcFloat; + else + _pCont->getClientRect(rcCorr); + + ShrinkRcToSize(rc); + ShrinkRcToSize(&rcCorr); + + /* correct rectangle position when mouse is not within */ + DoCalcGripperRect(rc, rcCorr, pt); + } + else + { + /* test if mouse is within work area */ + pContHit = workHitTest(pt, rc); + + /* calcutlates the rect and its position */ + if (pContHit == NULL) + { + /* calcutlates the rect and draws it */ + if (!_pCont->isFloating()) + *rc = _pCont->getDataOfActiveTb()->rcFloat; + else + _pCont->getWindowRect(*rc); + _pCont->getClientRect(rcCorr); + + CalcRectToScreen(_dockData.hWnd, rc); + CalcRectToScreen(_dockData.hWnd, &rcCorr); + + rc->left = pt.x - _ptOffset.x; + rc->top = pt.y - _ptOffset.y; + + /* correct rectangle position when mouse is not within */ + DoCalcGripperRect(rc, rcCorr, pt); + } + } +} + + +DockingCont* Gripper::contHitTest(POINT pt) +{ + vector vCont = _pDockMgr->getContainerInfo(); + HWND hWnd = ::WindowFromPoint(pt); + + for (UINT iCont = 0; iCont < vCont.size(); iCont++) + { + /* test if within caption */ + if (hWnd == vCont[iCont]->getCaptionWnd()) + { + if (vCont[iCont]->isFloating()) + { + RECT rc = {0}; + + vCont[iCont]->getWindowRect(rc); + if ((rc.top < pt.y) && (pt.y < (rc.top + 24))) + { + /* when it is the same container start moving immediately */ + if (vCont[iCont] == _pCont) + { + return NULL; + } + else + { + return vCont[iCont]; + } + } + } + else + { + return vCont[iCont]; + } + } + + /* test only tabs that are visible */ + if (::IsWindowVisible(vCont[iCont]->getTabWnd())) + { + /* test if within tab (rect test is used, because of drag and drop behaviour) */ + RECT rc = {0}; + + ::GetWindowRect(vCont[iCont]->getTabWnd(), &rc); + if (::PtInRect(&rc, pt)) + { + return vCont[iCont]; + } + } + } + + /* doesn't hit a container */ + return NULL; +} + + +DockingCont* Gripper::workHitTest(POINT pt, RECT *rc) +{ + RECT rcCont = {0}; + vector vCont = _pDockMgr->getContainerInfo(); + + /* at first test if cursor points into a visible container */ + for (size_t iCont = 0; iCont < vCont.size(); iCont++) + { + if (vCont[iCont]->isVisible()) + { + vCont[iCont]->getWindowRect(rcCont); + + if (::PtInRect(&rcCont, pt) == TRUE) + { + /* when it does, return with non found docking area */ + return NULL; + } + } + } + + /* now search if cusor hits a possible docking area */ + for (int iWork = 0; iWork < DOCKCONT_MAX; iWork++) + { + if (!vCont[iWork]->isVisible()) + { + rcCont = _dockData.rcRegion[iWork]; + rcCont.right += rcCont.left; + rcCont.bottom += rcCont.top; + + if (rc != NULL) + { + *rc = rcCont; + } + + /* set fix hit test with */ + switch(iWork) + { + case CONT_LEFT: + rcCont.right = rcCont.left + HIT_TEST_THICKNESS; + rcCont.left -= HIT_TEST_THICKNESS; + break; + case CONT_RIGHT: + rcCont.left = rcCont.right - HIT_TEST_THICKNESS; + rcCont.right += HIT_TEST_THICKNESS; + break; + case CONT_TOP: + rcCont.bottom = rcCont.top + HIT_TEST_THICKNESS; + rcCont.top -= HIT_TEST_THICKNESS; + break; + case CONT_BOTTOM: + rcCont.top = rcCont.bottom - HIT_TEST_THICKNESS; + rcCont.bottom += HIT_TEST_THICKNESS; + break; + default: + break; + } + ClientRectToScreenRect(_dockData.hWnd, &rcCont); + + if (::PtInRect(&rcCont, pt) == TRUE) + { + if (rc != NULL) + { + ClientRectToScreenRect(_dockData.hWnd, rc); + rc->right -= rc->left; + rc->bottom -= rc->top; + } + return vCont[iWork]; + } + } + } + + /* no docking area found */ + return NULL; +} + + +void Gripper::initTabInformation(POINT pt) +{ + /* for tab reordering */ + + /* remember handle */ + _hTabSource = _pCont->getTabWnd(); + _startMovingFromTab = _pCont->startMovingFromTab(); + if ((_startMovingFromTab == FALSE) && (::SendMessage(_hTabSource, TCM_GETITEMCOUNT, 0, 0) == 1)) + { + _startMovingFromTab = TRUE; + _iItem = 0; + } + else + { + /* get active tab item */ + _iItem = ::SendMessage(_hTabSource, TCM_GETCURSEL, 0, 0); + } + + /* get size of item */ + _hTab = _hTabSource; + ::SendMessage(_hTabSource, TCM_GETITEMRECT, _iItem, (LPARAM)&_rcItem); + + /* store item data */ + static TCHAR szText[64]; + _tcItem.mask = TCIF_PARAM | TCIF_TEXT; + _tcItem.pszText = szText; + _tcItem.cchTextMax = 64; + ::SendMessage(_hTabSource, TCM_GETITEM, _iItem, (LPARAM)&_tcItem); +} + diff --git a/PowerEditor/src/WinControls/DockingWnd/Gripper.h b/PowerEditor/src/WinControls/DockingWnd/Gripper.h new file mode 100644 index 00000000..d542e80d --- /dev/null +++ b/PowerEditor/src/WinControls/DockingWnd/Gripper.h @@ -0,0 +1,138 @@ +//this file is part of docking functionality for Notepad++ +//Copyright (C)2006 Jens Lorenz +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef GRIPPER_H +#define GRIPPER_H + +#include "Resource.h" +#include "Docking.h" +#include "DockingCont.h" +#include "DockingManager.h" +#include "commctrl.h" + + +// Used by getRectAndStyle() to draw the drag rectangle +static const WORD DotPattern[] = +{ + 0x00aa, 0x0055, 0x00aa, 0x0055, 0x00aa, 0x0055, 0x00aa, 0x0055 +}; + + +#define MDLG_CLASS_NAME TEXT("moveDlg") + + +class Gripper +{ +public: + Gripper(); + + void init(HINSTANCE hInst, HWND hParent) { + _hInst = hInst; + _hParent = hParent; + }; + + void startGrip(DockingCont* pCont, DockingManager* pDockMgr, void* pRes); + + ~Gripper() + { + if (_hdc) + {::ReleaseDC(0, _hdc);} + if (_hbm) + {::DeleteObject(_hbm);} + if (_hbrush) + {::DeleteObject(_hbrush);} + + } + +protected : + + void create(void); + + static LRESULT CALLBACK staticWinProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam); + LRESULT runProc(UINT Message, WPARAM wParam, LPARAM lParam); + + void onMove(void); + void onButtonUp(void); + + void doTabReordering(POINT pt); + void drawRectangle(POINT pt); + void getMousePoints(POINT* pt, POINT* ptPrev); + void getMovingRect(POINT pt, RECT *rc); + DockingCont* contHitTest(POINT pt); + DockingCont* workHitTest(POINT pt, RECT *rcCont = NULL); + + void initTabInformation(POINT pt); + + void CalcRectToScreen(HWND hWnd, RECT *rc) { + ClientRectToScreenRect(hWnd, rc); + ShrinkRcToSize(rc); + }; + void CalcRectToClient(HWND hWnd, RECT *rc) { + ScreenRectToClientRect(hWnd, rc); + ShrinkRcToSize(rc); + }; + void ShrinkRcToSize(RECT *rc) { + rc->right -= rc->left; + rc->bottom -= rc->top; + }; + void DoCalcGripperRect(RECT* rc, RECT rcCorr, POINT pt) { + if ((rc->left + rc->right) < pt.x) + rc->left = pt.x - 20; + if ((rc->top + rc->bottom) < pt.y) + rc->top += rcCorr.bottom - rc->bottom; + }; + +private: + /* Handle */ + HINSTANCE _hInst; + HWND _hParent; + HWND _hSelf; + + /* data of container */ + tDockMgr _dockData; + DockingManager* _pDockMgr; + DockingCont* _pCont; + + /* mouse offset in moving rectangle */ + POINT _ptOffset; + + /* remembers old mouse point */ + POINT _ptOld; + BOOL _bPtOldValid; + + /* for sorting tabs */ + HWND _hTab; + HWND _hTabSource; + BOOL _startMovingFromTab; + int _iItem; + RECT _rcItem; + TCITEM _tcItem; + + /* resource pointer of THIS class */ + void* _pRes; + + HDC _hdc; + HBITMAP _hbm; + HBRUSH _hbrush; + + /* is class registered */ + static BOOL _isRegistered; +}; + + + +#endif // GRIPPER_H \ No newline at end of file diff --git a/PowerEditor/src/WinControls/DockingWnd/dockingResource.h b/PowerEditor/src/WinControls/DockingWnd/dockingResource.h new file mode 100644 index 00000000..c3370066 --- /dev/null +++ b/PowerEditor/src/WinControls/DockingWnd/dockingResource.h @@ -0,0 +1,46 @@ +#ifndef DOCKING_RESOURCE_H +#define DOCKING_RESOURCE_H + +#define IDD_PLUGIN_DLG 103 +#define IDC_EDIT1 1000 + + +#define IDB_CLOSE_DOWN 137 +#define IDB_CLOSE_UP 138 +#define IDD_CONTAINER_DLG 139 + +#define IDC_TAB_CONT 1027 +#define IDC_CLIENT_TAB 1028 +#define IDC_BTN_CAPTION 1050 + +#define DMM_MSG 0x5000 + #define DMM_CLOSE (DMM_MSG + 1) + #define DMM_DOCK (DMM_MSG + 2) + #define DMM_FLOAT (DMM_MSG + 3) + #define DMM_DOCKALL (DMM_MSG + 4) + #define DMM_FLOATALL (DMM_MSG + 5) + #define DMM_MOVE (DMM_MSG + 6) + #define DMM_UPDATEDISPINFO (DMM_MSG + 7) + #define DMM_GETIMAGELIST (DMM_MSG + 8) + #define DMM_GETICONPOS (DMM_MSG + 9) + #define DMM_DROPDATA (DMM_MSG + 10) + #define DMM_MOVE_SPLITTER (DMM_MSG + 11) + #define DMM_CANCEL_MOVE (DMM_MSG + 12) + #define DMM_LBUTTONUP (DMM_MSG + 13) + +#define DMN_FIRST 1050 + #define DMN_CLOSE (DMN_FIRST + 1) + //nmhdr.code = DWORD(DMN_CLOSE, 0)); + //nmhdr.hwndFrom = hwndNpp; + //nmhdr.idFrom = ctrlIdNpp; + + #define DMN_DOCK (DMN_FIRST + 2) + #define DMN_FLOAT (DMN_FIRST + 3) + //nmhdr.code = DWORD(DMN_XXX, int newContainer); + //nmhdr.hwndFrom = hwndNpp; + //nmhdr.idFrom = ctrlIdNpp; + + + +#endif //DOCKING_RESOURCE_H + diff --git a/PowerEditor/src/WinControls/Grid/BabyGrid.cpp b/PowerEditor/src/WinControls/Grid/BabyGrid.cpp new file mode 100644 index 00000000..a2ec08fe --- /dev/null +++ b/PowerEditor/src/WinControls/Grid/BabyGrid.cpp @@ -0,0 +1,3268 @@ +//BABYGRID code is copyrighted (C) 20002 by David Hillard +// +//This code must retain this copyright message +// +//Printed BABYGRID message reference and tutorial available. +//email: mudcat@mis.net for more information. + +/* +Add WM_MOUSEWHEEL, WM_LBUTTONDBLCLK and WM_RBUTTONUP events +Modified by Don HO +*/ + +#include "babygrid.h" +#include "Common.h" + +#define MAX_GRIDS 20 + +#define MAX_ROWS 32000 +#define MAX_COLS 256 + + +//global variables + + + +HFONT hfontbody,hfontheader,hfonttitle; + +HFONT holdfont; + +struct _gridhandlestruct + { + UINT gridmenu; + HWND hlist1; + TCHAR protect[2]; + TCHAR title[305]; + TCHAR editstring[305]; + TCHAR editstringdisplay[305]; + int rows; + int cols; + int gridwidth; + int gridheight; + int homerow; + int homecol; + int rowheight; + int leftvisiblecol; + int rightvisiblecol; + int topvisiblerow; + int bottomvisiblerow; + int headerrowheight; + int cursorrow; + int cursorcol; + int ownerdrawitem; + int visiblecolumns; + int titleheight; + int fontascentheight; + COLORREF cursorcolor; + COLORREF protectcolor; + COLORREF unprotectcolor; + COLORREF textcolor; + COLORREF highlightcolor; + COLORREF gridlinecolor; + COLORREF highlighttextcolor; + BOOL DRAWHIGHLIGHT; + BOOL ADVANCEROW; + BOOL CURRENTCELLPROTECTED; + BOOL GRIDHASFOCUS; + BOOL AUTOROW; + RECT activecellrect; + HFONT hfont; + HFONT hcolumnheadingfont; + HFONT htitlefont; + BOOL ROWSNUMBERED; + BOOL COLUMNSNUMBERED; + BOOL EDITABLE; + BOOL EDITING; + BOOL EXTENDLASTCOLUMN; + BOOL HSCROLL; + BOOL VSCROLL; + BOOL SHOWINTEGRALROWS; + BOOL SIZING; + BOOL ELLIPSIS; + BOOL COLAUTOWIDTH; + BOOL COLUMNSIZING; + BOOL ALLOWCOLUMNRESIZING; + int columntoresize; + int columntoresizeinitsize; + int columntoresizeinitx; + int cursortype; + int columnwidths[MAX_COLS+1]; + BOOL REMEMBERINTEGRALROWS; + int wannabeheight; + int wannabewidth; + + } BGHS[MAX_GRIDS]; + + +_BGCELL BGcell,*LPBGcell; + +int BG_GridIndex; +int FindResult; +TCHAR data[1000]; + + + + + + + +CREATESTRUCT cs,*lpcs; + + +int AddGrid(UINT); +int FindGrid(UINT); +void ShowVscroll(HWND,int); +void ShowHscroll(HWND,int); +int BinarySearchListBox(HWND,TCHAR*); +void DisplayEditString(HWND ,int ,TCHAR*); +int CountGrids(void); + + + + +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// +int HomeColumnNthVisible(int SI) + { + int j,hc,count; + count=0; + hc=BGHS[SI].homecol; + for(j=1;j<=hc;j++) + { + if(BGHS[SI].columnwidths[j]>0) + { + count++; + } + } + return count; + } + + +void RefreshGrid(HWND hWnd) + { + RECT rect; + int SI; + GetClientRect(hWnd,&rect); + InvalidateRect(hWnd,&rect,FALSE); + SI=FindGrid((UINT)GetMenu(hWnd)); + if(BGHS[SI].EDITING) + { + DisplayEditString(hWnd, SI, TEXT("")); + } + + } + +int GetNextColWithWidth(int SI, int startcol, int direction) + { + //calls with direction == 1 for right, direction == -1 for left + //returns 0 if no more cols in that direction, else column number + int j; + int ReturnValue; + j=startcol; + if(direction == 1){j++;} + if(direction != 1){j--;} + + while((BGHS[SI].columnwidths[j] == 0)&&(j<=BGHS[SI].cols)&&(j>0)) + { + if(direction == 1){j++;} + if(direction != 1){j--;} + } + if((BGHS[SI].columnwidths[j] > 0)&&(j<=BGHS[SI].cols)) + { + ReturnValue = j; + } + else + { + ReturnValue = 0; + } + return ReturnValue; + } + + +int GetRowOfMouse(int SI,int y) + { + int ReturnValue; + if(y<=(BGHS[SI].titleheight)) + { + return -1; + } + if((y>=BGHS[SI].titleheight)&&(y<=BGHS[SI].headerrowheight + BGHS[SI].titleheight)) + { + return 0; + } + + + y=y-(BGHS[SI].headerrowheight + BGHS[SI].titleheight); + y=y/BGHS[SI].rowheight; + ReturnValue = BGHS[SI].homerow + y; + if(ReturnValue > BGHS[SI].rows){ReturnValue = -1;} + return ReturnValue; + } + + +int GetColOfMouse(int SI,int x) + { + int ReturnValue; + int j; + if(x<=BGHS[SI].columnwidths[0]) + { + return 0; + } + + x-=BGHS[SI].columnwidths[0]; + + j=BGHS[SI].homecol; + while(x>0) + { + x-=BGHS[SI].columnwidths[j]; + j++; + } + j--; + + ReturnValue = j; + if(BGHS[SI].EXTENDLASTCOLUMN) + { + if(j>BGHS[SI].cols){ReturnValue = BGHS[SI].cols;} + } + else + { + if(j>BGHS[SI].cols){ReturnValue = -1;} + } + return ReturnValue; + } + +BOOL OutOfRange(_BGCELL *cell) + { + if((cell->row > MAX_ROWS)||(cell->col > MAX_COLS)) + {return TRUE;} + else + {return FALSE;} + } + +void SetCell(_BGCELL *cell,int row, int col) + { + cell->row = row; + cell->col = col; + } +/* +int DetermineDataType(TCHAR* data) + { + //return values: + // 1 = Text or Alpha + // 2 = Numeric + // 3 = Boolean TRUE + // 4 = Boolean FALSE + // 5 = Graphic - user drawn (cell text begins with ~) + int j,k,numberofperiods,numberofpositives,numberofnegatives; + TCHAR tbuffer[1000]; + BOOL DIGIT,ALPHA,PERIOD,WHITESPACE,SYMBOL,POSITIVE,NEGATIVE; + lstrcpy(tbuffer,data); + k=lstrlen(tbuffer); + strupr(tbuffer); + //is it boolean? + if(!lstrcmp(tbuffer,"TRUE")) + { + return 3; + } + if(!lstrcmp(tbuffer,"FALSE")) + { + return 4; + } + //is it graphic (~) + if(tbuffer[0]=='~') + { + return 5; + } + DIGIT=FALSE; + ALPHA=FALSE; + PERIOD=FALSE; + WHITESPACE=FALSE; + SYMBOL=FALSE; + POSITIVE=FALSE; + NEGATIVE=FALSE; + + numberofperiods=0; + numberofpositives=0; + numberofnegatives=0; + for(j=0;j0){ALPHA=TRUE;}} + if(tbuffer[j]=='-'){if(j>0){ALPHA=TRUE;}} + } + if((ALPHA)||(WHITESPACE)) + { + return 1; + } + if((DIGIT)&&(!ALPHA)&&(!WHITESPACE)) + { + if(numberofperiods>1) + { + return 1; + } + else + { + return 2; + } + } + return 1; + } +*/ + +void CalcVisibleCellBoundaries(int SelfIndex) +{ + int gridx,gridy; + int j; + gridx=BGHS[SelfIndex].gridwidth; + gridy=BGHS[SelfIndex].gridheight; + + + + j= BGHS[SelfIndex].homecol; + BGHS[SelfIndex].leftvisiblecol = BGHS[SelfIndex].homecol; + BGHS[SelfIndex].topvisiblerow = BGHS[SelfIndex].homerow; + //calc columns visible + //first subtract the width of col 0; + gridx = gridx - BGHS[SelfIndex].columnwidths[0]; + do + { + gridx = gridx - BGHS[SelfIndex].columnwidths[j]; + j++; + }while ((gridx >= 0)&&(jBGHS[SelfIndex].cols){j=BGHS[SelfIndex].cols;} + BGHS[SelfIndex].rightvisiblecol = j; + + + + + //calc rows visible; + gridy = gridy - BGHS[SelfIndex].headerrowheight; + j= BGHS[SelfIndex].homerow; + do + { + gridy = gridy - BGHS[SelfIndex].rowheight; + j++; + }while ((gridy > 0)&&(jBGHS[SelfIndex].rows){j=BGHS[SelfIndex].rows;} + BGHS[SelfIndex].bottomvisiblerow = j; +} + + +RECT GetCellRect(HWND hWnd,int SI, int r, int c) + { + RECT rect; + int offset; + int j; + //c and r must be greater than zero + + //get column offset + //first get col 0 width + offset=BGHS[SI].columnwidths[0]; + for(j=BGHS[SI].homecol;j BGHS[SI].columnwidths[c]) + { + rect.right = offset + (trect.right - rect.left); + } + } + } + + //now get the top and bottom of the rect + offset = BGHS[SI].headerrowheight+BGHS[SI].titleheight; + for(j=BGHS[SI].homerow;j0) + { + int high,low; + high = ((c-1)/26); + low = c % 26; + if(high == 0){high = 32;}else{high+=64;} + if(low == 0){low=26;} + low += 64; + wsprintf(buffer, TEXT("%c%c"), high,low); + } + } + rectsave=rect; + DrawEdge(gdc,&rect,EDGE_ETCHED,BF_MIDDLE|BF_RECT|BF_ADJUST); + DrawTextEx(gdc,buffer,-1,&rect,DT_END_ELLIPSIS|DT_CENTER|DT_WORDBREAK|DT_NOPREFIX,NULL); + rect=rectsave; + + r=BGHS[SI].topvisiblerow; + //set font for grid body + SelectObject(gdc,hfont); + while(r<=BGHS[SI].bottomvisiblerow) + { + + //try to set cursor row to different display color + if((r==BGHS[SI].cursorrow)&&(c>0)&&(BGHS[SI].DRAWHIGHLIGHT)) + { + if(BGHS[SI].GRIDHASFOCUS) + { + SetTextColor(gdc,BGHS[SI].highlighttextcolor); + } + else + { + SetTextColor(gdc,RGB(0,0,0));//set black text for nonfocus grid hilight + } + } + else + { + SetTextColor(gdc,RGB(0,0,0)); + } + + rect.top = rect.bottom; + rect.bottom = rect.top + BGHS[SI].rowheight; + rectsave=rect; + SetCell(&BGcell,r,c); + lstrcpy(buffer, TEXT("")); + SendMessage(hWnd,BGM_GETCELLDATA,(WPARAM)&BGcell,(LPARAM)buffer); + if((c==0)&&(BGHS[SI].ROWSNUMBERED)) + { + wsprintf(buffer, TEXT("%d"), r); + } + if(c==0) + { + DrawEdge(gdc,&rect,EDGE_ETCHED,BF_MIDDLE|BF_RECT|BF_ADJUST); + + } + else + { + HBRUSH hbrush,holdbrush; + HPEN hpen,holdpen; + iProtection=SendMessage(hWnd,BGM_GETPROTECTION,(WPARAM)&BGcell,0); + if(BGHS[SI].DRAWHIGHLIGHT)//highlight on + { + if(r==BGHS[SI].cursorrow) + { + if(BGHS[SI].GRIDHASFOCUS) + { + hbrush=CreateSolidBrush(BGHS[SI].highlightcolor); + } + else + { + hbrush=CreateSolidBrush(RGB(200,200,200)); + } + } + + else + { + if(iProtection == 1) + { + hbrush=CreateSolidBrush(BGHS[SI].protectcolor); + } + else + { + hbrush=CreateSolidBrush(BGHS[SI].unprotectcolor); + } + } + } + else + { + if(iProtection == 1) + { + hbrush=CreateSolidBrush(BGHS[SI].protectcolor); + } + else + { + hbrush=CreateSolidBrush(BGHS[SI].unprotectcolor); + } + + } + hpen=CreatePen(PS_SOLID,1,BGHS[SI].gridlinecolor); + holdbrush=(HBRUSH)SelectObject(gdc,hbrush); + holdpen=(HPEN)SelectObject(gdc,hpen); + Rectangle(gdc,rect.left,rect.top,rect.right,rect.bottom); + SelectObject(gdc,holdbrush); + SelectObject(gdc,holdpen); + DeleteObject(hbrush); + DeleteObject(hpen); + } + rect.right -= 2; + rect.left += 2; + + iDataType=SendMessage(hWnd,BGM_GETTYPE,(WPARAM)&BGcell,0); + if((iDataType < 1)||(iDataType > 5)) + { + iDataType = 1;//default to alphanumeric data type.. can't happen + } + if(c==0){iDataType = 2;} + + if(iDataType == 1)//ALPHA + { + if(BGHS[SI].ELLIPSIS) + { + DrawTextEx(gdc,buffer,-1,&rect,DT_END_ELLIPSIS|DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_NOPREFIX,NULL); + } + else + { + DrawTextEx(gdc,buffer,-1,&rect,DT_LEFT|DT_WORDBREAK|DT_EDITCONTROL|DT_NOPREFIX,NULL); + } + } + + if(iDataType == 2)//NUMERIC + { + DrawTextEx(gdc,buffer,-1,&rect,DT_END_ELLIPSIS|DT_RIGHT|DT_VCENTER|DT_SINGLELINE|DT_NOPREFIX,NULL); + } + + if(iDataType == 3)//BOOLEAN TRUE + { + int k,excess; + k=2; + rect.top +=k; + rect.bottom -=k; + rect.left +=0; + rect.right -=0; + if((rect.bottom - rect.top)>24) + { + excess=(rect.bottom - rect.top)-16; + rect.top += (int)(excess/2); + rect.bottom -= (int)(excess/2); + } + DrawFrameControl(gdc,&rect,DFC_BUTTON,DFCS_BUTTONCHECK|DFCS_CHECKED); + } + + if(iDataType == 4)//BOOLEAN FALSE + { + int k,excess; + k=2; + rect.top +=k; + rect.bottom -=k; + rect.left +=0; + rect.right -=0; + if((rect.bottom - rect.top)>24) + { + excess=(rect.bottom - rect.top)-16; + rect.top += (int)(excess/2); + rect.bottom -= (int)(excess/2); + } + + + DrawFrameControl(gdc,&rect,DFC_BUTTON,DFCS_BUTTONCHECK); + } + + if(iDataType == 5) //user drawn graphic + { + WPARAM wParam; + buffer[0]=0x20; + BGHS[SI].ownerdrawitem = generic_atoi(buffer); + wParam=MAKEWPARAM((UINT)::GetMenu(hWnd),BGN_OWNERDRAW); + SendMessage(GetParent(hWnd),WM_COMMAND,wParam,(LPARAM)&rect); + } + + if(BGHS[SI].EDITING) + { + DisplayEditString(hWnd, SI, TEXT("")); + } + + rect=rectsave; + r++; + }//end while r<=bottomvisiblerow + + { + //repaint bottom of grid + RECT trect; + HBRUSH holdbrush; + HPEN holdpen; + GetClientRect(hWnd,&trect); + trect.top = rect.bottom; + trect.left = rect.left; + trect.right = rect.right; + + holdbrush=(HBRUSH)SelectObject(gdc,GetStockObject(GRAY_BRUSH)); + holdpen=(HPEN)SelectObject(gdc,GetStockObject(NULL_PEN)); + + Rectangle(gdc,trect.left,trect.top,trect.right+1,trect.bottom+1); + + SelectObject(gdc,holdbrush); + SelectObject(gdc,holdpen); + + } + + + SelectObject(gdc,holdfont); + DeleteObject(holdfont); + ReleaseDC(hWnd,gdc); + + + +} + + + + + +void DrawCursor(HWND hWnd,int SI) + { + RECT rect,rectwhole; + HDC gdc; + HPEN hpen,holdpen; + int rop; + if(BGHS[SI].rows == 0){return;} + GetClientRect(hWnd,&rect); + //if active cell has scrolled off the top, don't draw a focus rectangle + if(BGHS[SI].cursorrow < BGHS[SI].homerow){return;} + //if active cell has scrolled off to the left, don't draw a focus rectangle + if(BGHS[SI].cursorcol < BGHS[SI].homecol){return;} + + rect = GetCellRect(hWnd,SI,BGHS[SI].cursorrow,BGHS[SI].cursorcol); + rectwhole=rect; + gdc=GetDC(hWnd); + BGHS[SI].activecellrect = rect; + rop=GetROP2(gdc); + SetROP2(gdc,R2_XORPEN); + SelectObject(gdc,(HBRUSH)GetStockObject(NULL_BRUSH)); + hpen=CreatePen(PS_SOLID,3,BGHS[SI].cursorcolor); //width of 3 + holdpen=(HPEN)SelectObject(gdc,hpen); + Rectangle(gdc,rect.left,rect.top,rect.right,rect.bottom); + SelectObject(gdc,holdpen); + DeleteObject(hpen); + SetROP2(gdc,rop); + ReleaseDC(hWnd,gdc); + } + +void SetCurrentCellStatus(HWND hWnd,int SelfIndex) + { + SetCell(&BGcell,BGHS[SelfIndex].cursorrow,BGHS[SelfIndex].cursorcol); + if(SendMessage(hWnd,BGM_GETPROTECTION,(WPARAM)&BGcell,0)) + { + BGHS[SelfIndex].CURRENTCELLPROTECTED = TRUE; + } + else + { + BGHS[SelfIndex].CURRENTCELLPROTECTED = FALSE; + } + + } + + + +TCHAR GetASCII(WPARAM wParam, LPARAM lParam) + { + int returnvalue; + TCHAR mbuffer[100]; + int result; + BYTE keys[256]; + WORD dwReturnedValue; + GetKeyboardState(keys); + result=ToAscii(wParam,(lParam >> 16) && 0xff,keys,&dwReturnedValue,0); + returnvalue = (TCHAR) dwReturnedValue; + if(returnvalue < 0){returnvalue = 0;} + wsprintf(mbuffer, TEXT("return value = %d"), returnvalue); + if(result!=1){returnvalue = 0;} + return (TCHAR)returnvalue; + + } + + + +void SetHomeRow(HWND hWnd,int SI,int row,int col) + { + RECT gridrect,cellrect; + //get rect of grid window + GetClientRect(hWnd,&gridrect); + //get rect of current cell + cellrect=GetCellRect(hWnd,SI,row,col); + if((cellrect.bottom > gridrect.bottom)&&((cellrect.bottom - cellrect.top)<(gridrect.bottom-(BGHS[SI].headerrowheight+BGHS[SI].titleheight)))) + { + while(cellrect.bottom > gridrect.bottom) + { + BGHS[SI].homerow ++; + if(row==BGHS[SI].rows) + { + gridrect.top = gridrect.bottom - (BGHS[SI].rowheight); + InvalidateRect(hWnd,&gridrect,TRUE); + } + else + { + InvalidateRect(hWnd,&gridrect,FALSE); + } + cellrect=GetCellRect(hWnd,SI,row,col); + } + } + else + { + if((cellrect.bottom - cellrect.top)>=(gridrect.bottom - (BGHS[SI].headerrowheight+BGHS[SI].titleheight))) + { + BGHS[SI].homerow++; + } + } + cellrect=GetCellRect(hWnd,SI,row,col); + { + while((row < BGHS[SI].homerow)) + { + BGHS[SI].homerow --; + InvalidateRect(hWnd,&gridrect,FALSE); + cellrect=GetCellRect(hWnd,SI,row,col); + } + } + //set the vertical scrollbar position + SetScrollPos(hWnd,SB_VERT,BGHS[SI].homerow,TRUE); + } + + + +void SetHomeCol(HWND hWnd,int SI,int row,int col) + { + RECT gridrect,cellrect; + BOOL LASTCOLVISIBLE; + //get rect of grid window + GetClientRect(hWnd,&gridrect); + //get rect of current cell + cellrect = GetCellRect(hWnd,SI,row,col); + //determine if scroll left or right is needed + while((cellrect.right > gridrect.right)&&(cellrect.left != BGHS[SI].columnwidths[0])) + { + //scroll right is needed + BGHS[SI].homecol++; + //see if last column is visible + cellrect = GetCellRect(hWnd,SI,row,BGHS[SI].cols); + if(cellrect.right <= gridrect.right) + { + LASTCOLVISIBLE=TRUE; + } + else + { + LASTCOLVISIBLE=FALSE; + } + cellrect = GetCellRect(hWnd,SI,row,col); + InvalidateRect(hWnd,&gridrect,FALSE); + } + cellrect = GetCellRect(hWnd,SI,row,col); + while((BGHS[SI].cursorcol < BGHS[SI].homecol)&&(BGHS[SI].homecol > 1)) + + { + //scroll left is needed + BGHS[SI].homecol--; + //see if last column is visible + cellrect = GetCellRect(hWnd,SI,row,BGHS[SI].cols); + if(cellrect.right <= gridrect.right) + { + LASTCOLVISIBLE=TRUE; + } + else + { + LASTCOLVISIBLE=FALSE; + } + + cellrect = GetCellRect(hWnd,SI,row,col); + InvalidateRect(hWnd,&gridrect,FALSE); + } + { + int k; + k=HomeColumnNthVisible(SI); + SetScrollPos(hWnd,SB_HORZ,k,TRUE); + } + } + + + +void ShowVscroll(HWND hWnd,int SI) + { + //if more rows than can be visible on grid, display vertical scrollbar + //otherwise, hide it. + RECT gridrect; + int totalpixels; + int rowsvisibleonscreen; + GetClientRect(hWnd,&gridrect); + totalpixels = gridrect.bottom; + totalpixels -= BGHS[SI].titleheight; + totalpixels -= BGHS[SI].headerrowheight; + totalpixels -= (BGHS[SI].rowheight * BGHS[SI].rows); + rowsvisibleonscreen = (gridrect.bottom - (BGHS[SI].headerrowheight+BGHS[SI].titleheight)) / BGHS[SI].rowheight; + if(totalpixels < 0) + { + //show vscrollbar + ShowScrollBar(hWnd,SB_VERT,TRUE); + SetScrollRange(hWnd,SB_VERT,1,(BGHS[SI].rows-rowsvisibleonscreen)+1,TRUE); + BGHS[SI].VSCROLL = TRUE; + } + else + { + //hide vscrollbar + ShowScrollBar(hWnd,SB_VERT,FALSE); + BGHS[SI].VSCROLL = FALSE; + } + + } + +void ShowHscroll(HWND hWnd,int SI) + { + //if more rows than can be visible on grid, display vertical scrollbar + //otherwise, hide it. + RECT gridrect; + int totalpixels; + int colswithwidth; + int j; + GetClientRect(hWnd,&gridrect); + totalpixels = gridrect.right; + totalpixels -= BGHS[SI].columnwidths[0]; + colswithwidth = 0; + for(j=1;j<=BGHS[SI].cols;j++) + { + totalpixels -= BGHS[SI].columnwidths[j]; + if(BGHS[SI].columnwidths[j]>0) + { + colswithwidth++; + } + } + if(totalpixels < 0) + { + //show hscrollbar + ShowScrollBar(hWnd,SB_HORZ,TRUE); + SetScrollRange(hWnd,SB_HORZ,1,colswithwidth,TRUE); + BGHS[SI].HSCROLL = TRUE; + } + else + { + //hide hscrollbar + ShowScrollBar(hWnd,SB_HORZ,FALSE); + BGHS[SI].HSCROLL = FALSE; + } + + } + + + +void NotifyRowChanged(HWND hWnd,int SI) + { + WPARAM wParam; + LPARAM lParam; + lParam = MAKELPARAM(BGHS[SI].cursorrow,BGHS[SI].cursorcol); + wParam=MAKEWPARAM((UINT)BGHS[SI].gridmenu,BGN_ROWCHANGED); + SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam); + wParam=MAKEWPARAM((UINT)BGHS[SI].gridmenu,BGN_SELCHANGE); + SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam); + } + + +void NotifyColChanged(HWND hWnd,int SI) + { + WPARAM wParam; + LPARAM lParam; + lParam = MAKELPARAM(BGHS[SI].cursorrow,BGHS[SI].cursorcol); + wParam=MAKEWPARAM((UINT)BGHS[SI].gridmenu,BGN_COLCHANGED); + SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam); + wParam=MAKEWPARAM((UINT)BGHS[SI].gridmenu,BGN_SELCHANGE); + SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam); + + } + + +void NotifyEndEdit(HWND hWnd,int SI) + { + WPARAM wParam; + LPARAM lParam; + lParam = MAKELPARAM(BGHS[SI].cursorrow,BGHS[SI].cursorcol); + wParam=MAKEWPARAM((UINT)BGHS[SI].gridmenu,BGN_EDITEND); + SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam); + + } + + +void NotifyDelete(HWND hWnd,int SI) + { + WPARAM wParam; + LPARAM lParam; + lParam = MAKELPARAM(BGHS[SI].cursorrow,BGHS[SI].cursorcol); + wParam=MAKEWPARAM((UINT)BGHS[SI].gridmenu,BGN_DELETECELL); + SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam); + + } + + +void NotifyEditBegin(HWND hWnd,int SI) + { + WPARAM wParam; + LPARAM lParam; + lParam = MAKELPARAM(BGHS[SI].cursorrow,BGHS[SI].cursorcol); + wParam=MAKEWPARAM((UINT)BGHS[SI].gridmenu,BGN_EDITBEGIN); + SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam); + + } + +void NotifyEditEnd(HWND hWnd,int SI) + { + WPARAM wParam; + LPARAM lParam; + lParam = MAKELPARAM(BGHS[SI].cursorrow,BGHS[SI].cursorcol); + wParam=MAKEWPARAM((UINT)BGHS[SI].gridmenu,BGN_EDITEND); + SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam); + + } + +/* +void NotifyF1(HWND hWnd,int SI) + { + WPARAM wParam; + LPARAM lParam; + lParam = MAKELPARAM(BGHS[SI].cursorrow,BGHS[SI].cursorcol); + wParam=MAKEWPARAM((UINT)BGHS[SI].gridmenu,BGN_F1); + SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam); + + } + +void NotifyF2(HWND hWnd,int SI) + { + WPARAM wParam; + LPARAM lParam; + lParam = MAKELPARAM(BGHS[SI].cursorrow,BGHS[SI].cursorcol); + wParam=MAKEWPARAM((UINT)BGHS[SI].gridmenu,BGN_F2); + SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam); + + } + +void NotifyF3(HWND hWnd,int SI) + { + WPARAM wParam; + LPARAM lParam; + lParam = MAKELPARAM(BGHS[SI].cursorrow,BGHS[SI].cursorcol); + wParam=MAKEWPARAM((UINT)BGHS[SI].gridmenu,BGN_F3); + SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam); + + } + +void NotifyF4(HWND hWnd,int SI) + { + WPARAM wParam; + LPARAM lParam; + lParam = MAKELPARAM(BGHS[SI].cursorrow,BGHS[SI].cursorcol); + wParam=MAKEWPARAM((UINT)BGHS[SI].gridmenu,BGN_F4); + SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam); + + } + +void NotifyF5(HWND hWnd,int SI) + { + WPARAM wParam; + LPARAM lParam; + lParam = MAKELPARAM(BGHS[SI].cursorrow,BGHS[SI].cursorcol); + wParam=MAKEWPARAM((UINT)BGHS[SI].gridmenu,BGN_F5); + SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam); + + } + +void NotifyF6(HWND hWnd,int SI) + { + WPARAM wParam; + LPARAM lParam; + lParam = MAKELPARAM(BGHS[SI].cursorrow,BGHS[SI].cursorcol); + wParam=MAKEWPARAM((UINT)BGHS[SI].gridmenu,BGN_F6); + SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam); + + } + +void NotifyF7(HWND hWnd,int SI) + { + WPARAM wParam; + LPARAM lParam; + lParam = MAKELPARAM(BGHS[SI].cursorrow,BGHS[SI].cursorcol); + wParam=MAKEWPARAM((UINT)BGHS[SI].gridmenu,BGN_F7); + SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam); + + } + +void NotifyF8(HWND hWnd,int SI) + { + WPARAM wParam; + LPARAM lParam; + lParam = MAKELPARAM(BGHS[SI].cursorrow,BGHS[SI].cursorcol); + wParam=MAKEWPARAM((UINT)BGHS[SI].gridmenu,BGN_F8); + SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam); + + } + +void NotifyF9(HWND hWnd,int SI) + { + WPARAM wParam; + LPARAM lParam; + lParam = MAKELPARAM(BGHS[SI].cursorrow,BGHS[SI].cursorcol); + wParam=MAKEWPARAM((UINT)BGHS[SI].gridmenu,BGN_F9); + SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam); + + } + +void NotifyF10(HWND hWnd,int SI) + { + WPARAM wParam; + LPARAM lParam; + lParam = MAKELPARAM(BGHS[SI].cursorrow,BGHS[SI].cursorcol); + wParam=MAKEWPARAM((UINT)BGHS[SI].gridmenu,BGN_F10); + SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam); + + } + +void NotifyF11(HWND hWnd,int SI) + { + WPARAM wParam; + LPARAM lParam; + lParam = MAKELPARAM(BGHS[SI].cursorrow,BGHS[SI].cursorcol); + wParam=MAKEWPARAM((UINT)BGHS[SI].gridmenu,BGN_F11); + SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam); + + } + +void NotifyF12(HWND hWnd,int SI) + { + WPARAM wParam; + LPARAM lParam; + lParam = MAKELPARAM(BGHS[SI].cursorrow,BGHS[SI].cursorcol); + wParam=MAKEWPARAM((UINT)BGHS[SI].gridmenu,BGN_F12); + SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam); + + } +*/ +void NotifyCellClicked(HWND hWnd,int SI) + { + WPARAM wParam; + LPARAM lParam; + lParam = MAKELPARAM(BGHS[SI].cursorrow,BGHS[SI].cursorcol); + wParam=MAKEWPARAM((UINT)BGHS[SI].gridmenu,BGN_CELLCLICKED); + SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam); + + } + +void NotifyCellDbClicked(HWND hWnd,int SI) + { + WPARAM wParam; + LPARAM lParam; + lParam = MAKELPARAM(BGHS[SI].cursorrow,BGHS[SI].cursorcol); + wParam=MAKEWPARAM((UINT)BGHS[SI].gridmenu,BGN_CELLDBCLICKED); + SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam); + } + +void NotifyCellRClicked(HWND hWnd,int SI) + { + WPARAM wParam; + LPARAM lParam; + lParam = MAKELPARAM(BGHS[SI].cursorrow,BGHS[SI].cursorcol); + wParam=MAKEWPARAM((UINT)BGHS[SI].gridmenu,BGN_CELLRCLICKED); + SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam); + } +void GetVisibleColumns(HWND hWnd,int SI) + { + int j; + int value; + value=0; + for(j=1;j<=BGHS[SI].cols;j++) + { + if(BGHS[SI].columnwidths[j] > 0) + { + value++; + } + } + BGHS[SI].visiblecolumns = value; + SetScrollRange(hWnd,SB_HORZ,1,value,TRUE); + } + +int GetNthVisibleColumn(HWND hWnd,int SI,int n) + { + int j,count; + int value; + j=1; + count=0; + value = n-1; + while(j<=BGHS[SI].cols) + { + if(BGHS[SI].columnwidths[j]>0) + { + count++; + if(count==n) + { + value = j; + } + } + j++; + } + return value; + } + + +void CloseEdit(HWND hWnd,int SI) + { + int r,c; + _BGCELL cell; + r=BGHS[SI].cursorrow; + c=BGHS[SI].cursorcol; + cell.row = r; + cell.col = c; + SendMessage(hWnd,BGM_SETCELLDATA,(WPARAM)&cell,(LPARAM)BGHS[SI].editstring); + lstrcpy(BGHS[SI].editstring, TEXT("")); + RefreshGrid(hWnd); + BGHS[SI].EDITING = FALSE; + HideCaret(hWnd); + NotifyEditEnd(hWnd,SI); + } + +void DisplayEditString(HWND hWnd,int SI,TCHAR* tstring) + { + int r,c; + HFONT holdfont; + RECT rt; + HDC cdc; + r=BGHS[SI].cursorrow; + c=BGHS[SI].cursorcol; + ShowCaret(hWnd); + if((rcx > longest) + { + longest=size->cx; + } + p = generic_strtok('\0', TEXT("\n")); + } + return longest; + } + + +LRESULT CALLBACK GridProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + int wmId, wmEvent; + PAINTSTRUCT ps; + HDC hdc; + TCHAR buffer[1000]; + int SelfIndex; + int ReturnValue; + UINT SelfMenu; + HINSTANCE hInst; + int iDataType; + static int ASCII; + + + SelfIndex=FindGrid((UINT)GetMenu(hWnd)); + SelfMenu=BGHS[SelfIndex].gridmenu; + + //update the grid width and height variable + { + RECT rect; + + GetClientRect(hWnd,&rect); + BGHS[SelfIndex].gridwidth = rect.right - rect.left; + BGHS[SelfIndex].gridheight = rect.bottom - rect.top; + + } + + ReturnValue = 0; + + switch (message) + { + case WM_COMMAND: + wmId = LOWORD(wParam); + wmEvent = HIWORD(wParam); + // Parse the menu selections: + switch (wmId) + { + case 1: + default: + return DefWindowProc(hWnd, message, wParam, lParam); + } + break; + + case WM_PAINT: + hdc = BeginPaint(hWnd, &ps); + RECT rt; + GetClientRect(hWnd, &rt); + CalcVisibleCellBoundaries(SelfIndex); + //display title + DisplayTitle(hWnd,SelfIndex,BGHS[SelfIndex].htitlefont); + //display column 0; + + DisplayColumn(hWnd,SelfIndex,0,0,BGHS[SelfIndex].hfont,BGHS[SelfIndex].hcolumnheadingfont); + { + int c,j,k,offset; + offset = BGHS[SelfIndex].columnwidths[0]; + j=BGHS[SelfIndex].leftvisiblecol; + k=BGHS[SelfIndex].rightvisiblecol; + for(c=j;c<=k;c++) + { + DisplayColumn(hWnd,SelfIndex,c,offset,BGHS[SelfIndex].hfont,BGHS[SelfIndex].hcolumnheadingfont); + offset+=BGHS[SelfIndex].columnwidths[c]; + } + + } + EndPaint(hWnd, &ps); + // + if(GetFocus()==hWnd) + { + PostMessage(hWnd,BGM_DRAWCURSOR,(UINT)SelfIndex,0); + } + + + break; + + + case BGM_PAINTGRID: + { + RECT rect; + GetClientRect(hWnd, &rect); + InvalidateRect(hWnd,&rect,TRUE); + UpdateWindow(hWnd); + MessageBeep(0); + } + break; + case WM_SETTEXT: + { + int j,linecount; + SIZE size; + HDC gdc; + HFONT holdfont; + if(lstrlen((TCHAR*)lParam)>300) + { + lstrcpy(BGHS[SelfIndex].title, TEXT("Title too long (300 chars max)")); + } + else + { + lstrcpy(BGHS[SelfIndex].title,(TCHAR*)lParam); + } + + gdc=GetDC(hWnd); + //get linecount of title; + if(lstrlen(BGHS[SelfIndex].title) > 0) + { + linecount=1; + for(j=0;j<(int)lstrlen(BGHS[SelfIndex].title);j++) + { + if(BGHS[SelfIndex].title[j]=='\n') + { + linecount++; + } + + } + holdfont=(HFONT)SelectObject(gdc,BGHS[SelfIndex].htitlefont); + GetTextExtentPoint32(gdc,BGHS[SelfIndex].title,lstrlen(BGHS[SelfIndex].title),&size); + SelectObject(gdc,holdfont); + BGHS[SelfIndex].titleheight = (int)((size.cy*1.2) * linecount); + } + else + { + //no title + BGHS[SelfIndex].titleheight = 0; + } + ReleaseDC(hWnd,gdc); + + + RefreshGrid(hWnd); + SizeGrid(hWnd,SelfIndex); + + } + break; + case BGM_GETROWS: + ReturnValue = BGHS[SelfIndex].rows; + break; + + case BGM_GETCOLS: + ReturnValue = BGHS[SelfIndex].cols; + break; + + case BGM_GETCOLWIDTH: + ReturnValue = BGHS[SelfIndex].columnwidths[wParam]; + break; + + case BGM_GETROWHEIGHT: + ReturnValue = BGHS[SelfIndex].rowheight; + break; + + case BGM_GETHEADERROWHEIGHT: + ReturnValue = BGHS[SelfIndex].headerrowheight; + break; + + case BGM_GETOWNERDRAWITEM: + ReturnValue = BGHS[SelfIndex].ownerdrawitem; + break; + + case BGM_DRAWCURSOR: + DrawCursor(hWnd,wParam); + break; + case BGM_SETCURSORPOS: + DrawCursor(hWnd,SelfIndex); + if((((int)wParam <= BGHS[SelfIndex].rows)&&((int)wParam > 0))&& + (((int)lParam <= BGHS[SelfIndex].cols)&&((int)lParam > 0))) + { + BGHS[SelfIndex].cursorrow=wParam; + BGHS[SelfIndex].cursorcol=lParam; + } + else + { + DrawCursor(hWnd,SelfIndex); + break; + } + SetHomeRow(hWnd,SelfIndex,BGHS[SelfIndex].cursorrow,BGHS[SelfIndex].cursorcol); + SetHomeCol(hWnd,SelfIndex,BGHS[SelfIndex].cursorrow,BGHS[SelfIndex].cursorcol); + DrawCursor(hWnd,SelfIndex); + RefreshGrid(hWnd); + + break; + case BGM_SHOWHILIGHT: + BGHS[SelfIndex].DRAWHIGHLIGHT = (BOOL)wParam; + RefreshGrid(hWnd); + break; + case BGM_EXTENDLASTCOLUMN: + BGHS[SelfIndex].EXTENDLASTCOLUMN = (BOOL)wParam; + RefreshGrid(hWnd); + break; + + case BGM_SHOWINTEGRALROWS: + BGHS[SelfIndex].SHOWINTEGRALROWS = (BOOL)wParam; + SizeGrid(hWnd,SelfIndex); + RefreshGrid(hWnd); + break; + + case BGM_SETCOLAUTOWIDTH: + BGHS[SelfIndex].COLAUTOWIDTH = (BOOL)wParam; + break; + + case BGM_SETALLOWCOLRESIZE: + BGHS[SelfIndex].ALLOWCOLUMNRESIZING = (BOOL)wParam; + break; + + case BGM_PROTECTCELL: + LPBGcell=(_BGCELL*)wParam; + if(OutOfRange(LPBGcell)) + { + wParam=MAKEWPARAM((UINT)GetMenu(hWnd),BGN_OUTOFRANGE); + lParam = 0; + SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam); + ReturnValue = -1; + break; + } + wsprintf(buffer, TEXT("%05d-%03d"), LPBGcell->row,LPBGcell->col); + //see if that cell is already loaded + FindResult = BinarySearchListBox(BGHS[SelfIndex].hlist1,buffer); + if(FindResult != LB_ERR) + { + //it was found, get the text, modify text delete it from list, add modified to list + SendMessage(BGHS[SelfIndex].hlist1,LB_GETTEXT,FindResult,(LPARAM)buffer); + if((BOOL)lParam) + { + buffer[10] = 'P'; + } + else + { + buffer[10] = 'U'; + } + SendMessage(BGHS[SelfIndex].hlist1,LB_DELETESTRING,FindResult,0); + SendMessage(BGHS[SelfIndex].hlist1,LB_ADDSTRING,FindResult,(LPARAM)buffer); + } + else + { + //protecting or unprotecting a cell that isn't in the list + //add it as blank; + lstrcat(buffer, TEXT("|")); + if((BOOL)lParam) + { + lstrcat(buffer, TEXT("PA")); + } + else + { + lstrcat(buffer, TEXT("UA")); + } + lstrcat(buffer, TEXT("|")); + SendMessage(BGHS[SelfIndex].hlist1,LB_ADDSTRING,FindResult,(LPARAM)buffer); + } + + break; + case BGM_NOTIFYROWCHANGED: + NotifyRowChanged(hWnd,SelfIndex); + break; + case BGM_NOTIFYCOLCHANGED: + NotifyColChanged(hWnd,SelfIndex); + break; + case BGM_SETPROTECT: + if((BOOL)wParam) + { + lstrcpy(BGHS[SelfIndex].protect, TEXT("P")); + } + else + { + lstrcpy(BGHS[SelfIndex].protect, TEXT("U")); + } + break; + + case BGM_AUTOROW: + if((BOOL)wParam) + { + BGHS[SelfIndex].AUTOROW = TRUE; + } + else + { + BGHS[SelfIndex].AUTOROW = FALSE; + } + break; + case BGM_SETEDITABLE: + if((BOOL)wParam) + { + BGHS[SelfIndex].EDITABLE = TRUE; + } + else + { + BGHS[SelfIndex].EDITABLE = FALSE; + } + break; + + case BGM_SETCELLDATA: + LPBGcell=(_BGCELL*)wParam; + if(OutOfRange(LPBGcell)) + { + wParam=MAKEWPARAM((UINT)GetMenu(hWnd),BGN_OUTOFRANGE); + lParam = 0; + SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam); + ReturnValue = -1; + break; + } + wsprintf(buffer, TEXT("%05d-%03d"), LPBGcell->row,LPBGcell->col); + //see if that cell is already loaded + FindResult = BinarySearchListBox(BGHS[SelfIndex].hlist1,buffer); + if(FindResult != LB_ERR) + { + //it was found, delete it + SendMessage(BGHS[SelfIndex].hlist1,LB_DELETESTRING,FindResult,0); + } + //now add it + lstrcat(buffer, TEXT("|")); + lstrcat(buffer,BGHS[SelfIndex].protect); + //determine data type (text,numeric, or boolean)(1,2,3) + //iDataType=DetermineDataType((TCHAR*)lParam); + + iDataType = 1; + if(iDataType==1){lstrcat(buffer, TEXT("A"));} + if(iDataType==2){lstrcat(buffer, TEXT("N"));} + if(iDataType==3){lstrcat(buffer, TEXT("T"));} + if(iDataType==4){lstrcat(buffer, TEXT("F"));} + if(iDataType==5){lstrcat(buffer, TEXT("G"));} + + lstrcat(buffer, TEXT("|")); + lstrcat(buffer, (TCHAR*)lParam); + FindResult=SendMessage(BGHS[SelfIndex].hlist1,LB_ADDSTRING,0,(LPARAM)buffer); + + if(FindResult==LB_ERR) + { + MessageBeep(0); + } + { + RECT rect; + rect=GetCellRect(hWnd,SelfIndex,LPBGcell->row,LPBGcell->col); + InvalidateRect(hWnd,&rect,FALSE); + } + //get the last line and adjust grid dimmensions + if(BGHS[SelfIndex].AUTOROW) + { + int j; + j=SendMessage(BGHS[SelfIndex].hlist1,LB_GETCOUNT,0,0); + if(j>0) + { + SendMessage(BGHS[SelfIndex].hlist1,LB_GETTEXT,j-1,(LPARAM)buffer); + buffer[5]=0x00; + j=generic_atoi(buffer); + if(j>SendMessage(hWnd,BGM_GETROWS,0,0)) + { + SendMessage(hWnd,BGM_SETGRIDDIM,j,BGHS[SelfIndex].cols); + } + } + else + { + //no items in the list + SendMessage(hWnd,BGM_SETGRIDDIM,j,BGHS[SelfIndex].cols); + } + } + + //adjust the column width if COLAUTOWIDTH==TRUE + if((BGHS[SelfIndex].COLAUTOWIDTH)||(LPBGcell->row == 0)) + { + HDC hdc; + SIZE size; + int required_width; + int current_width; + int required_height = 30; + int current_height; + int longestline; + HFONT holdfont; + hdc=GetDC(hWnd); + if(LPBGcell->row == 0) + { + holdfont=(HFONT)SelectObject(hdc,BGHS[SelfIndex].hcolumnheadingfont); + } + else + { + holdfont=(HFONT)SelectObject(hdc,BGHS[SelfIndex].hfont); + } + //if there are \n codes in the generic_string, find the longest line + longestline=FindLongestLine(hdc,(TCHAR*)lParam,&size); + //GetTextExtentPoint32(hdc,(TCHAR*)lParam,lstrlen((TCHAR*)lParam),&size); + required_width = longestline+15; + required_height = size.cy; + //count lines + { + int count=1; + TCHAR tbuffer[255]; + lstrcpy(tbuffer,(TCHAR*)lParam); + for(int j=0;j<(int)lstrlen(tbuffer);j++) + { + if(tbuffer[j]=='\n'){count++;} + } + if((!BGHS[SelfIndex].ELLIPSIS)||(LPBGcell->row == 0)) + { + required_height *= count; + } + required_height +=5; + } + SelectObject(hdc,holdfont); + ReleaseDC(hWnd,hdc); + current_width = BGHS[SelfIndex].columnwidths[LPBGcell->col]; + if(LPBGcell->row == 0) + { + current_height = BGHS[SelfIndex].headerrowheight; + if(required_height > current_height) + { + SendMessage(hWnd,BGM_SETHEADERROWHEIGHT,required_height,0); + } + } + else + { + current_height = BGHS[SelfIndex].rowheight; + if(required_height > current_height) + { + SendMessage(hWnd, BGM_SETROWHEIGHT, /*required_height*/20, 0); + } + + } + if(required_width > current_width) + { + SendMessage(hWnd,BGM_SETCOLWIDTH,LPBGcell->col,required_width); + } + ReleaseDC(hWnd,hdc); + } + + break; + + case BGM_GETCELLDATA: + LPBGcell=(_BGCELL*)wParam; + if(OutOfRange(LPBGcell)) + { + wParam=MAKEWPARAM((UINT)GetMenu(hWnd),BGN_OUTOFRANGE); + lParam = 0; + SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam); + ReturnValue = -1; + break; + } + wsprintf(buffer, TEXT("%05d-%03d"),LPBGcell->row,LPBGcell->col); + //see if that cell is already loaded + FindResult = BinarySearchListBox(BGHS[SelfIndex].hlist1,buffer); + if(FindResult != LB_ERR) + { + int j,k,c; + TCHAR tbuffer[1000]; + //it was found, get it + SendMessage(BGHS[SelfIndex].hlist1,LB_GETTEXT,FindResult,(long)lParam); + lstrcpy(tbuffer,(TCHAR*)lParam); + k=lstrlen(tbuffer); + c=0; + for(j=13;jrow,LPBGcell->col); + //see if that cell is already loaded + FindResult = BinarySearchListBox(BGHS[SelfIndex].hlist1,buffer); + if(FindResult != LB_ERR) + { + //it was found, delete it + SendMessage(BGHS[SelfIndex].hlist1,LB_DELETESTRING,FindResult,0); + NotifyEndEdit(hWnd,SelfIndex); + } + break; + case BGM_SETGRIDDIM: + if((wParam>=0)&&(wParam<=MAX_ROWS)) + { + BGHS[SelfIndex].rows = wParam; + } + else + { + if(wParam<0) + { + BGHS[SelfIndex].rows = 0; + } + else + { + BGHS[SelfIndex].rows = MAX_ROWS; + } + } + + if((lParam>0)&&(lParam<=MAX_COLS)) + { + BGHS[SelfIndex].cols = lParam; + } + else + { + if(lParam <= 0) + { + BGHS[SelfIndex].cols = 1; + } + else + { + BGHS[SelfIndex].cols = MAX_COLS; + } + } + {RECT rect; + GetClientRect(hWnd,&rect); + InvalidateRect(hWnd,&rect,TRUE); + } + GetVisibleColumns(hWnd,SelfIndex); + break; + + + case BGM_SETCOLWIDTH: + if((wParam <= MAX_COLS)&&(wParam >= 0) && (lParam >= 0)) + { + RECT rect; + BGHS[SelfIndex].columnwidths[wParam] = lParam; + GetClientRect(hWnd,&rect); + InvalidateRect(hWnd,&rect,FALSE); + GetVisibleColumns(hWnd,SelfIndex); + } + break; + case BGM_SETHEADERROWHEIGHT: + if(wParam >= 0) + { + RECT rect; + BGHS[SelfIndex].headerrowheight = wParam; + SizeGrid(hWnd,SelfIndex); + GetClientRect(hWnd,&rect); + InvalidateRect(hWnd,&rect,FALSE); + } + break; + + case BGM_GETROW: + ReturnValue = BGHS[SelfIndex].cursorrow; + break; + case BGM_GETCOL: + ReturnValue = BGHS[SelfIndex].cursorcol; + break; + + case BGM_GETTYPE: + LPBGcell=(_BGCELL*)wParam; + if(OutOfRange(LPBGcell)) + { + wParam=MAKEWPARAM((UINT)GetMenu(hWnd),BGN_OUTOFRANGE); + lParam = 0; + SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam); + ReturnValue = -1; + break; + } + wsprintf(buffer, TEXT("%05d-%03d"),LPBGcell->row,LPBGcell->col); + //see if that cell is already loaded + FindResult = BinarySearchListBox(BGHS[SelfIndex].hlist1,buffer); + if(FindResult != LB_ERR) + { + //it was found, get it + SendMessage(BGHS[SelfIndex].hlist1,LB_GETTEXT,FindResult,(LPARAM)buffer); + switch (buffer[11]) + { + case 'A':ReturnValue=1;break; + case 'N':ReturnValue=2;break; + case 'T':ReturnValue=3;break; + case 'F':ReturnValue=4;break; + case 'G':ReturnValue=5;break; + default: ReturnValue =1;break; + } + } + break; + case BGM_GETPROTECTION: + LPBGcell=(_BGCELL*)wParam; + if(OutOfRange(LPBGcell)) + { + wParam=MAKEWPARAM((UINT)GetMenu(hWnd),BGN_OUTOFRANGE); + lParam = 0; + SendMessage(GetParent(hWnd),WM_COMMAND,wParam,lParam); + ReturnValue = -1; + break; + } + wsprintf(buffer, TEXT("%05d-%03d"),LPBGcell->row,LPBGcell->col); + //see if that cell is already loaded + ReturnValue = 0; + FindResult = BinarySearchListBox(BGHS[SelfIndex].hlist1,buffer); + if(FindResult != LB_ERR) + { + //it was found, get it + SendMessage(BGHS[SelfIndex].hlist1,LB_GETTEXT,FindResult,(LPARAM)buffer); + switch (buffer[10]) + { + case 'U':ReturnValue=0;break; + case 'P':ReturnValue=1;break; + default: ReturnValue =0;break; + } + } + + break; + case BGM_SETROWHEIGHT: + if(wParam <1){wParam=1;} + BGHS[SelfIndex].rowheight = wParam; + SetHomeRow(hWnd,SelfIndex,BGHS[SelfIndex].cursorrow,BGHS[SelfIndex].cursorcol); + SetHomeCol(hWnd,SelfIndex,BGHS[SelfIndex].cursorrow,BGHS[SelfIndex].cursorcol); + SizeGrid(hWnd,SelfIndex); + + { + RECT rect; + GetClientRect(hWnd,&rect); + InvalidateRect(hWnd,&rect,FALSE); + } + break; + + case BGM_SETTITLEHEIGHT: + if(wParam<0){wParam =0;} + BGHS[SelfIndex].titleheight = wParam; + SetHomeRow(hWnd,SelfIndex,BGHS[SelfIndex].cursorrow,BGHS[SelfIndex].cursorcol); + SetHomeCol(hWnd,SelfIndex,BGHS[SelfIndex].cursorrow,BGHS[SelfIndex].cursorcol); + { + RECT rect; + GetClientRect(hWnd,&rect); + InvalidateRect(hWnd,&rect,FALSE); + } + break; + case BGM_SETGRIDLINECOLOR: + DrawCursor(hWnd,SelfIndex); + BGHS[SelfIndex].gridlinecolor = (COLORREF)wParam; + DrawCursor(hWnd,SelfIndex); + RefreshGrid(hWnd); + break; + + case BGM_SETCURSORCOLOR: + DrawCursor(hWnd,SelfIndex); + BGHS[SelfIndex].cursorcolor = (COLORREF)wParam; + DrawCursor(hWnd,SelfIndex); + RefreshGrid(hWnd); + break; + + case BGM_SETHILIGHTTEXTCOLOR: + BGHS[SelfIndex].highlighttextcolor = (COLORREF)wParam; + { + RECT rect; + GetClientRect(hWnd,&rect); + InvalidateRect(hWnd,&rect,FALSE); + } + break; + + case BGM_SETHILIGHTCOLOR: + BGHS[SelfIndex].highlightcolor = (COLORREF)wParam; + { + RECT rect; + GetClientRect(hWnd,&rect); + InvalidateRect(hWnd,&rect,FALSE); + } + break; + + + case BGM_SETPROTECTCOLOR: + BGHS[SelfIndex].protectcolor = (COLORREF)wParam; + { + RECT rect; + GetClientRect(hWnd,&rect); + InvalidateRect(hWnd,&rect,FALSE); + } + break; + case BGM_SETUNPROTECTCOLOR: + BGHS[SelfIndex].unprotectcolor = (COLORREF)wParam; + { + RECT rect; + GetClientRect(hWnd,&rect); + InvalidateRect(hWnd,&rect,FALSE); + } + break; + + case BGM_SETELLIPSIS: + BGHS[SelfIndex].ELLIPSIS = (BOOL)wParam; + { + RECT rect; + GetClientRect(hWnd,&rect); + InvalidateRect(hWnd,&rect,FALSE); + } + + break; + + + case BGM_SETTITLEFONT: + BGHS[SelfIndex].htitlefont = (HFONT)wParam; + { + RECT rect; + GetClientRect(hWnd,&rect); + InvalidateRect(hWnd,&rect,FALSE); + } + + break; + + case BGM_SETHEADINGFONT: + BGHS[SelfIndex].hcolumnheadingfont = (HFONT)wParam; + { + RECT rect; + GetClientRect(hWnd,&rect); + InvalidateRect(hWnd,&rect,FALSE); + } + + break; + + + + + case BGM_SETROWSNUMBERED: + BGHS[SelfIndex].ROWSNUMBERED = (BOOL)wParam; + { + RECT rect; + GetClientRect(hWnd,&rect); + InvalidateRect(hWnd,&rect,FALSE); + } + + break; + + case BGM_SETCOLSNUMBERED: + BGHS[SelfIndex].COLUMNSNUMBERED = (BOOL)wParam; + { + RECT rect; + GetClientRect(hWnd,&rect); + InvalidateRect(hWnd,&rect,FALSE); + } + + break; + + case WM_ENABLE: + if(wParam == FALSE) + { + BGHS[SelfIndex].textcolor = RGB(120,120,120); + } + else + { + BGHS[SelfIndex].textcolor = RGB(0,0,0); + } + + case WM_MOUSEMOVE: + int x,y,r,c,t,z; + x=LOWORD(lParam); + y=HIWORD(lParam); + r=GetRowOfMouse(SelfIndex,y); + c=GetColOfMouse(SelfIndex,x); + t=GetColOfMouse(SelfIndex,x+10); + z=GetColOfMouse(SelfIndex,x-10); + + if(BGHS[SelfIndex].COLUMNSIZING) + { + int dx,nx,cr; + dx=x-BGHS[SelfIndex].columntoresizeinitx; + nx=BGHS[SelfIndex].columntoresizeinitsize + dx; + if(nx<=0){nx=0;} + cr=BGHS[SelfIndex].columntoresize; + SendMessage(hWnd,BGM_SETCOLWIDTH,cr,nx); + + } + if((r==0)&&(c>=-1)&&((t!=c)||(z!=c))&&(!BGHS[SelfIndex].COLUMNSIZING)) + { + if((BGHS[SelfIndex].cursortype != 2)&&(BGHS[SelfIndex].ALLOWCOLUMNRESIZING)) + { + BGHS[SelfIndex].cursortype = 2; + SetCursor(LoadCursor(NULL, IDC_SIZEWE)); + } + + } + else + { + if((BGHS[SelfIndex].cursortype != 1)&&(!BGHS[SelfIndex].COLUMNSIZING)) + { + BGHS[SelfIndex].cursortype = 1; + SetCursor(LoadCursor(NULL, IDC_ARROW)); + } + } + break; + + case WM_LBUTTONUP: + if(BGHS[SelfIndex].COLUMNSIZING) + { + BGHS[SelfIndex].COLUMNSIZING = FALSE; + SetCursor(LoadCursor(NULL, IDC_ARROW)); + BGHS[SelfIndex].cursortype = 1; + BGHS[SelfIndex].SHOWINTEGRALROWS=BGHS[SelfIndex].REMEMBERINTEGRALROWS; + SizeGrid(hWnd,SelfIndex); + } + break; + + case WM_RBUTTONUP : + case WM_LBUTTONDBLCLK : + case WM_LBUTTONDOWN: + { + int x,y,r,c; + //check for column sizing + if(BGHS[SelfIndex].cursortype == 2) + { + int c,x,t,z; + //start column sizing + if(!BGHS[SelfIndex].COLUMNSIZING) + { + BGHS[SelfIndex].REMEMBERINTEGRALROWS = BGHS[SelfIndex].SHOWINTEGRALROWS; + } + BGHS[SelfIndex].COLUMNSIZING = TRUE; + BGHS[SelfIndex].SHOWINTEGRALROWS = FALSE; + x=LOWORD(lParam); + BGHS[SelfIndex].columntoresizeinitx=x; + t=GetColOfMouse(SelfIndex,x+10); + z=GetColOfMouse(SelfIndex,x-10); + c=GetColOfMouse(SelfIndex,x); + if(t!=c) + { + //resizing column c + BGHS[SelfIndex].columntoresize = c; + } + if(z!=c) + { + //resizing hidden column to the left of cursor + if(c==-1) + { + c=SendMessage(hWnd,BGM_GETCOLS,0,0); + } + else + { + c-=1; + } + BGHS[SelfIndex].columntoresize = c; + } + + BGHS[SelfIndex].columntoresizeinitsize = BGHS[SelfIndex].columnwidths[c]; + } + + if(BGHS[SelfIndex].EDITING) + { + CloseEdit(hWnd,SelfIndex); + } + else + { + + SetFocus(hWnd); + } + BOOL NRC,NCC; + NRC=FALSE; + NCC=FALSE; + + if(GetFocus()==hWnd) + { + + x=LOWORD(lParam); + y=HIWORD(lParam); + r=GetRowOfMouse(SelfIndex,y); + c=GetColOfMouse(SelfIndex,x); + DrawCursor(hWnd,SelfIndex); + if((r>0)&&(c>0)) + { + if(r != BGHS[SelfIndex].cursorrow) + { + BGHS[SelfIndex].cursorrow = r; + NRC=TRUE; + } + else + { + BGHS[SelfIndex].cursorrow = r; + } + if(c != BGHS[SelfIndex].cursorcol) + { + BGHS[SelfIndex].cursorcol = c; + NCC=TRUE; + } + else + { + BGHS[SelfIndex].cursorcol = c; + } + + } + if(NRC){NotifyRowChanged(hWnd,SelfIndex);} + if(NCC){NotifyColChanged(hWnd,SelfIndex);} + + DrawCursor(hWnd,SelfIndex); + SetCurrentCellStatus(hWnd,SelfIndex); + SetHomeRow(hWnd,SelfIndex,BGHS[SelfIndex].cursorrow,BGHS[SelfIndex].cursorcol); + SetHomeCol(hWnd,SelfIndex,BGHS[SelfIndex].cursorrow,BGHS[SelfIndex].cursorcol); + RefreshGrid(hWnd); + + if (message == WM_LBUTTONDOWN) + NotifyCellClicked(hWnd,SelfIndex); + else if (message == WM_LBUTTONDBLCLK) + NotifyCellDbClicked(hWnd,SelfIndex); + else // (message == WM_RBUTTONUP) + NotifyCellRClicked(hWnd,SelfIndex); + } + else + { + SetFocus(hWnd); + } + } + break; + + case WM_ERASEBKGND: + return TRUE; + break; + + case WM_GETDLGCODE: + + ReturnValue = DLGC_WANTARROWS|DLGC_WANTCHARS|DLGC_DEFPUSHBUTTON; + if(wParam == 13) + { + //same as arrow down + if(BGHS[SelfIndex].EDITING) + { + CloseEdit(hWnd,SelfIndex); + } + DrawCursor(hWnd,SelfIndex); + BGHS[SelfIndex].cursorrow ++; + if(BGHS[SelfIndex].cursorrow > BGHS[SelfIndex].rows) + { + BGHS[SelfIndex].cursorrow = BGHS[SelfIndex].rows; + } + else + { + NotifyRowChanged(hWnd,SelfIndex); + } + DrawCursor(hWnd,SelfIndex); + SetCurrentCellStatus(hWnd,SelfIndex); + SetHomeRow(hWnd,SelfIndex,BGHS[SelfIndex].cursorrow,BGHS[SelfIndex].cursorcol); + RefreshGrid(hWnd); + BGHS[SelfIndex].EDITING = FALSE; + break; + } + + if(wParam == VK_ESCAPE) + { + if(BGHS[SelfIndex].EDITING) + { + BGHS[SelfIndex].EDITING = FALSE; + lstrcpy(BGHS[SelfIndex].editstring, TEXT("")); + HideCaret(hWnd); + RefreshGrid(hWnd); + NotifyEditEnd(hWnd,SelfIndex); + } + else + { + ReturnValue = 0; + } + break; + } + break; + case WM_KEYDOWN: + + if(wParam == VK_ESCAPE) + { + if(BGHS[SelfIndex].EDITING) + { + BGHS[SelfIndex].EDITING = FALSE; + lstrcpy(BGHS[SelfIndex].editstring, TEXT("")); + HideCaret(hWnd); + RefreshGrid(hWnd); + NotifyEditEnd(hWnd,SelfIndex); + } + break; + } +/* + if(wParam == VK_F1) + { + NotifyF1(hWnd,SelfIndex); + break; + } + + if(wParam == VK_F2) + { + NotifyF2(hWnd,SelfIndex); + break; + } + if(wParam == VK_F3) + { + NotifyF3(hWnd,SelfIndex); + break; + } + if(wParam == VK_F4) + { + NotifyF4(hWnd,SelfIndex); + break; + } + if(wParam == VK_F5) + { + NotifyF5(hWnd,SelfIndex); + break; + } + if(wParam == VK_F6) + { + NotifyF6(hWnd,SelfIndex); + break; + } + if(wParam == VK_F7) + { + NotifyF7(hWnd,SelfIndex); + break; + } + if(wParam == VK_F8) + { + NotifyF8(hWnd,SelfIndex); + break; + } + if(wParam == VK_F9) + { + NotifyF9(hWnd,SelfIndex); + break; + } + if(wParam == VK_F10) + { + NotifyF10(hWnd,SelfIndex); + break; + } + if(wParam == VK_F11) + { + NotifyF11(hWnd,SelfIndex); + break; + } + if(wParam == VK_F12) + { + NotifyF12(hWnd,SelfIndex); + break; + } +*/ + if(wParam == VK_DELETE) + { + NotifyDelete(hWnd,SelfIndex); + break; + } + if(wParam == VK_TAB) + { + SetFocus(GetParent(hWnd)); + break; + } + if(wParam == VK_NEXT) + { + RECT gridrect; + int rpp; + if(BGHS[SelfIndex].EDITING) + { + CloseEdit(hWnd,SelfIndex); + } + + if(BGHS[SelfIndex].rows == 0){break;} + if(BGHS[SelfIndex].cursorrow == BGHS[SelfIndex].rows){break;} + //get rows per page + GetClientRect(hWnd,&gridrect); + rpp = (gridrect.bottom - (BGHS[SelfIndex].headerrowheight+BGHS[SelfIndex].titleheight))/BGHS[SelfIndex].rowheight; + DrawCursor(hWnd,SelfIndex); + BGHS[SelfIndex].cursorrow += rpp; + + if(BGHS[SelfIndex].cursorrow > BGHS[SelfIndex].rows) + { + BGHS[SelfIndex].cursorrow = BGHS[SelfIndex].rows; + } + NotifyRowChanged(hWnd,SelfIndex); + DrawCursor(hWnd,SelfIndex); + SetCurrentCellStatus(hWnd,SelfIndex); + SetHomeRow(hWnd,SelfIndex,BGHS[SelfIndex].cursorrow,BGHS[SelfIndex].cursorcol); + SetHomeCol(hWnd,SelfIndex,BGHS[SelfIndex].cursorrow,BGHS[SelfIndex].cursorcol); + RefreshGrid(hWnd); + break; + + } + if(wParam == VK_PRIOR) + { + RECT gridrect; + int rpp; + if(BGHS[SelfIndex].EDITING) + { + CloseEdit(hWnd,SelfIndex); + } + + if(BGHS[SelfIndex].rows == 0){break;} + if(BGHS[SelfIndex].cursorrow == 1){break;} + //get rows per page + GetClientRect(hWnd,&gridrect); + rpp = (gridrect.bottom - (BGHS[SelfIndex].headerrowheight+BGHS[SelfIndex].titleheight))/BGHS[SelfIndex].rowheight; + DrawCursor(hWnd,SelfIndex); + BGHS[SelfIndex].cursorrow -= rpp; + if(BGHS[SelfIndex].cursorrow < 1) + { + BGHS[SelfIndex].cursorrow = 1; + } + NotifyRowChanged(hWnd,SelfIndex); + DrawCursor(hWnd,SelfIndex); + SetCurrentCellStatus(hWnd,SelfIndex); + SetHomeRow(hWnd,SelfIndex,BGHS[SelfIndex].cursorrow,BGHS[SelfIndex].cursorcol); + SetHomeCol(hWnd,SelfIndex,BGHS[SelfIndex].cursorrow,BGHS[SelfIndex].cursorcol); + RefreshGrid(hWnd); + break; + } + if(wParam == VK_DOWN) + { + if(BGHS[SelfIndex].EDITING) + { + CloseEdit(hWnd,SelfIndex); + } + + if(BGHS[SelfIndex].rows == 0){break;} + if(BGHS[SelfIndex].cursorrow == BGHS[SelfIndex].rows){break;} + DrawCursor(hWnd,SelfIndex); + BGHS[SelfIndex].cursorrow ++; + if(BGHS[SelfIndex].cursorrow > BGHS[SelfIndex].rows) + { + BGHS[SelfIndex].cursorrow = BGHS[SelfIndex].rows; + } + else + { + NotifyRowChanged(hWnd,SelfIndex); + } + DrawCursor(hWnd,SelfIndex); + SetCurrentCellStatus(hWnd,SelfIndex); + SetHomeRow(hWnd,SelfIndex,BGHS[SelfIndex].cursorrow,BGHS[SelfIndex].cursorcol); + SetHomeCol(hWnd,SelfIndex,BGHS[SelfIndex].cursorrow,BGHS[SelfIndex].cursorcol); + RefreshGrid(hWnd); + break; + } + if(wParam == VK_UP) + { + if(BGHS[SelfIndex].EDITING) + { + CloseEdit(hWnd,SelfIndex); + } + + if(BGHS[SelfIndex].rows == 0){break;} + if(BGHS[SelfIndex].cursorrow == 1){break;} + + DrawCursor(hWnd,SelfIndex); + BGHS[SelfIndex].cursorrow --; + if(BGHS[SelfIndex].cursorrow < 1) + { + BGHS[SelfIndex].cursorrow = 1; + } + else + { + NotifyRowChanged(hWnd,SelfIndex); + } + DrawCursor(hWnd,SelfIndex); + SetCurrentCellStatus(hWnd,SelfIndex); + SetHomeRow(hWnd,SelfIndex,BGHS[SelfIndex].cursorrow,BGHS[SelfIndex].cursorcol); + SetHomeCol(hWnd,SelfIndex,BGHS[SelfIndex].cursorrow,BGHS[SelfIndex].cursorcol); + RefreshGrid(hWnd); + break; + } + + if(wParam == VK_LEFT) + { + int k; + if(BGHS[SelfIndex].EDITING) + { + CloseEdit(hWnd,SelfIndex); + } + + if(!GetNextColWithWidth(SelfIndex,BGHS[SelfIndex].cursorcol,-1)) + { + break; + } + DrawCursor(hWnd,SelfIndex); + k=GetNextColWithWidth(SelfIndex,BGHS[SelfIndex].cursorcol,-1); + if(k) + { + BGHS[SelfIndex].cursorcol = k; + NotifyColChanged(hWnd,SelfIndex); + } + DrawCursor(hWnd,SelfIndex); + SetCurrentCellStatus(hWnd,SelfIndex); + SetHomeRow(hWnd,SelfIndex,BGHS[SelfIndex].cursorrow,BGHS[SelfIndex].cursorcol); + SetHomeCol(hWnd,SelfIndex,BGHS[SelfIndex].cursorrow,BGHS[SelfIndex].cursorcol); + break; + } + + if(wParam == VK_RIGHT) + { + int k; + if(BGHS[SelfIndex].EDITING) + { + CloseEdit(hWnd,SelfIndex); + } + DrawCursor(hWnd,SelfIndex); + k=GetNextColWithWidth(SelfIndex,BGHS[SelfIndex].cursorcol,1); + if(k) + { + BGHS[SelfIndex].cursorcol = k; + NotifyColChanged(hWnd,SelfIndex); + } + DrawCursor(hWnd,SelfIndex); + SetCurrentCellStatus(hWnd,SelfIndex); + SetHomeRow(hWnd,SelfIndex,BGHS[SelfIndex].cursorrow,BGHS[SelfIndex].cursorcol); + SetHomeCol(hWnd,SelfIndex,BGHS[SelfIndex].cursorrow,BGHS[SelfIndex].cursorcol); + RefreshGrid(hWnd); + break; + } + + SetCurrentCellStatus(hWnd,SelfIndex); + + + + if((BGHS[SelfIndex].CURRENTCELLPROTECTED)&&(wParam == 13)) + + { + DrawCursor(hWnd,SelfIndex); + BGHS[SelfIndex].cursorrow ++; + if(BGHS[SelfIndex].cursorrow > BGHS[SelfIndex].rows) + { + BGHS[SelfIndex].cursorrow = BGHS[SelfIndex].rows; + } + else + { + NotifyRowChanged(hWnd,SelfIndex); + } + DrawCursor(hWnd,SelfIndex); + SetCurrentCellStatus(hWnd,SelfIndex); + SetHomeRow(hWnd,SelfIndex,BGHS[SelfIndex].cursorrow,BGHS[SelfIndex].cursorcol); + RefreshGrid(hWnd); + break; + } + + if(BGHS[SelfIndex].CURRENTCELLPROTECTED){break;} + + if(!BGHS[SelfIndex].EDITABLE) + { + int ascii; + ascii=GetASCII(wParam,lParam); + if(ascii == 13) //enter pressed, treat as arrow down + { + //same as arrow down + DrawCursor(hWnd,SelfIndex); + BGHS[SelfIndex].cursorrow ++; + if(BGHS[SelfIndex].cursorrow > BGHS[SelfIndex].rows) + { + BGHS[SelfIndex].cursorrow = BGHS[SelfIndex].rows; + } + else + { + NotifyRowChanged(hWnd,SelfIndex); + } + DrawCursor(hWnd,SelfIndex); + SetCurrentCellStatus(hWnd,SelfIndex); + SetHomeRow(hWnd,SelfIndex,BGHS[SelfIndex].cursorrow,BGHS[SelfIndex].cursorcol); + RefreshGrid(hWnd); + break; + + } + + } + + //if it's not an arrow key, make an edit box in the active cell rectangle + if((BGHS[SelfIndex].EDITABLE)&&(BGHS[SelfIndex].rows > 0)) + { + + SetHomeRow(hWnd,SelfIndex,BGHS[SelfIndex].cursorrow,BGHS[SelfIndex].cursorcol); + DrawCursor(hWnd,SelfIndex); + DrawCursor(hWnd,SelfIndex); + + { + int ascii; + ascii=GetASCII(wParam,lParam); + wParam = ascii; + if((wParam >= 32)&&(wParam <= 125)) + { + TCHAR tstring[2]; + if(!BGHS[SelfIndex].EDITING) + { + NotifyEditBegin(hWnd,SelfIndex); + } + BGHS[SelfIndex].EDITING = TRUE; + tstring[0]=wParam; + tstring[1]=0x00; + DisplayEditString(hWnd,SelfIndex,tstring); + break; + } + if(wParam == 8) //backspace + { + if(!BGHS[SelfIndex].EDITING) + { + NotifyEditBegin(hWnd,SelfIndex); + } + + BGHS[SelfIndex].EDITING = TRUE; + if(lstrlen(BGHS[SelfIndex].editstring)==0) + { + DisplayEditString(hWnd,SelfIndex, TEXT("")); + break; + } + else + { + int j; + j=lstrlen(BGHS[SelfIndex].editstring); + BGHS[SelfIndex].editstring[j-1]=0x00; + DisplayEditString(hWnd,SelfIndex, TEXT("")); + } + break; + } + if(wParam == 13) + { + //same as arrow down + if(BGHS[SelfIndex].EDITING) + { + CloseEdit(hWnd,SelfIndex); + } + DrawCursor(hWnd,SelfIndex); + BGHS[SelfIndex].cursorrow ++; + if(BGHS[SelfIndex].cursorrow > BGHS[SelfIndex].rows) + { + BGHS[SelfIndex].cursorrow = BGHS[SelfIndex].rows; + } + else + { + NotifyRowChanged(hWnd,SelfIndex); + } + DrawCursor(hWnd,SelfIndex); + SetCurrentCellStatus(hWnd,SelfIndex); + SetHomeRow(hWnd,SelfIndex,BGHS[SelfIndex].cursorrow,BGHS[SelfIndex].cursorcol); + RefreshGrid(hWnd); + BGHS[SelfIndex].EDITING = FALSE; + break; + } + } + } + break; + case WM_HSCROLL: + SetFocus(hWnd); + if((LOWORD(wParam==SB_LINERIGHT))||(LOWORD(wParam)==SB_PAGERIGHT)) + { + int cp,np; + cp=GetScrollPos(hWnd,SB_HORZ); + SetScrollPos(hWnd,SB_HORZ,cp+1,TRUE); + cp=GetScrollPos(hWnd,SB_HORZ); + np=GetNthVisibleColumn(hWnd,SelfIndex,cp); + BGHS[SelfIndex].homecol = np; + SetScrollPos(hWnd,SB_HORZ,cp,TRUE); + RefreshGrid(hWnd); + } + if((LOWORD(wParam==SB_LINELEFT))||(LOWORD(wParam)==SB_PAGELEFT)) + { + int cp,np; + cp=GetScrollPos(hWnd,SB_HORZ); + SetScrollPos(hWnd,SB_HORZ,cp-1,TRUE); + cp=GetScrollPos(hWnd,SB_HORZ); + np=GetNthVisibleColumn(hWnd,SelfIndex,cp); + BGHS[SelfIndex].homecol = np; + SetScrollPos(hWnd,SB_HORZ,cp,TRUE); + RefreshGrid(hWnd); + } + if(LOWORD(wParam)==SB_THUMBTRACK) + { + int cp,np; + cp=HIWORD(wParam); + np=GetNthVisibleColumn(hWnd,SelfIndex,cp); + SetScrollPos(hWnd,SB_HORZ,np,TRUE); + BGHS[SelfIndex].homecol = np; + SetScrollPos(hWnd,SB_HORZ,cp,TRUE); + RefreshGrid(hWnd); + } + + + break; + + case WM_MOUSEWHEEL : + { + short zDelta = (short) HIWORD(wParam); + ::SendMessage(hWnd, WM_VSCROLL, zDelta < 0?SB_LINEDOWN:SB_LINEUP, 0); + return TRUE; + } + + case WM_VSCROLL: + SetFocus(hWnd); + if(LOWORD(wParam)==SB_THUMBTRACK) + { + RECT gridrect; + int min,max; + BGHS[SelfIndex].homerow = HIWORD(wParam); + SetScrollPos(hWnd,SB_VERT,HIWORD(wParam),TRUE); + GetClientRect(hWnd,&gridrect); + GetScrollRange(hWnd,SB_VERT,&min,&max); + if(HIWORD(wParam)==max) + { + gridrect.top = gridrect.bottom - (BGHS[SelfIndex].rowheight); + InvalidateRect(hWnd,&gridrect,TRUE); + } + else + { + InvalidateRect(hWnd,&gridrect,FALSE); + } + } + + if(LOWORD(wParam)==SB_PAGEDOWN) + { + RECT gridrect; + int min,max,sp,rpp; + //get rows per page + GetClientRect(hWnd,&gridrect); + rpp = (gridrect.bottom - (BGHS[SelfIndex].headerrowheight+BGHS[SelfIndex].titleheight))/BGHS[SelfIndex].rowheight; + GetScrollRange(hWnd,SB_VERT,&min,&max); + sp=GetScrollPos(hWnd,SB_VERT); + sp += rpp; + if(sp > max){sp=max;} + BGHS[SelfIndex].homerow = sp; + SetScrollPos(hWnd,SB_VERT,sp,TRUE); + SetHomeRow(hWnd,SelfIndex,sp,BGHS[SelfIndex].homecol); + if(sp==max) + { + gridrect.top = gridrect.bottom - (BGHS[SelfIndex].rowheight); + InvalidateRect(hWnd,&gridrect,TRUE); + } + else + { + InvalidateRect(hWnd,&gridrect,FALSE); + } + + } + if(LOWORD(wParam)==SB_LINEDOWN) + { + RECT gridrect; + int min,max,sp; + //get rows per page + GetClientRect(hWnd,&gridrect); + GetScrollRange(hWnd,SB_VERT,&min,&max); + sp=GetScrollPos(hWnd,SB_VERT); + sp += 1; + if(sp > max){sp=max;} + BGHS[SelfIndex].homerow = sp; + SetScrollPos(hWnd,SB_VERT,sp,TRUE); + SetHomeRow(hWnd,SelfIndex,sp,BGHS[SelfIndex].homecol); + if(sp==max) + { + gridrect.top = gridrect.bottom - (BGHS[SelfIndex].rowheight); + InvalidateRect(hWnd,&gridrect,TRUE); + } + else + { + InvalidateRect(hWnd,&gridrect,FALSE); + } + + } + + + + if(LOWORD(wParam)==SB_PAGEUP) + { + RECT gridrect; + int min,max,sp,rpp; + //get rows per page + GetClientRect(hWnd,&gridrect); + rpp = (gridrect.bottom - (BGHS[SelfIndex].headerrowheight+BGHS[SelfIndex].titleheight))/BGHS[SelfIndex].rowheight; + GetScrollRange(hWnd,SB_VERT,&min,&max); + sp=GetScrollPos(hWnd,SB_VERT); + sp -= rpp; + if(sp < 1){sp=1;} + BGHS[SelfIndex].homerow = sp; + SetScrollPos(hWnd,SB_VERT,sp,TRUE); + SetHomeRow(hWnd,SelfIndex,sp,BGHS[SelfIndex].homecol); + if(sp==max) + { + gridrect.top = gridrect.bottom - (BGHS[SelfIndex].rowheight); + InvalidateRect(hWnd,&gridrect,TRUE); + } + else + { + InvalidateRect(hWnd,&gridrect,FALSE); + } + + } + if(LOWORD(wParam)==SB_LINEUP) + { + RECT gridrect; + int min,max,sp; + //get rows per page + GetClientRect(hWnd,&gridrect); + sp=GetScrollPos(hWnd,SB_VERT); + GetScrollRange(hWnd,SB_VERT,&min,&max); + sp -= 1; + if(sp < 1){sp=1;} + BGHS[SelfIndex].homerow = sp; + SetScrollPos(hWnd,SB_VERT,sp,TRUE); + SetHomeRow(hWnd,SelfIndex,sp,BGHS[SelfIndex].homecol); + if(sp==max) + { + gridrect.top = gridrect.bottom - (BGHS[SelfIndex].rowheight); + InvalidateRect(hWnd,&gridrect,TRUE); + } + else + { + InvalidateRect(hWnd,&gridrect,FALSE); + } + + } + RefreshGrid(hWnd); + + break; + case WM_DESTROY: + { int k; + if(CountGrids()==0) + { + DeleteObject(hfontbody); + DeleteObject(hfontheader); + DeleteObject(hfonttitle); + } + SendMessage(BGHS[SelfIndex].hlist1,LB_RESETCONTENT,0,0); + DestroyWindow(BGHS[SelfIndex].hlist1); + BGHS[SelfIndex].gridmenu = 0; + BGHS[SelfIndex].hlist1 = NULL; + BGHS[SelfIndex].hfont = NULL; + lstrcpy(BGHS[SelfIndex].protect, TEXT("U")); + BGHS[SelfIndex].rows = 100; + BGHS[SelfIndex].cols = 255; + BGHS[SelfIndex].homerow = 1; + BGHS[SelfIndex].homecol = 1; + BGHS[SelfIndex].rowheight = 20; + BGHS[SelfIndex].headerrowheight = 20; + BGHS[SelfIndex].ROWSNUMBERED = TRUE; + BGHS[SelfIndex].COLUMNSNUMBERED = TRUE; + BGHS[SelfIndex].DRAWHIGHLIGHT = TRUE; + + BGHS[SelfIndex].cursorcol = 1; + BGHS[SelfIndex].cursorrow = 1; + BGHS[SelfIndex].columnwidths[0]=40; + BGHS[SelfIndex].ADVANCEROW = TRUE; + BGHS[SelfIndex].cursorcolor = RGB(255,255,255); + BGHS[SelfIndex].protectcolor = RGB(128,128,128); + BGHS[SelfIndex].unprotectcolor = RGB(255,255,255); + for(k=1;khInstance; + + + BG_GridIndex = AddGrid((UINT)GetMenu(hWnd)); + + if(CountGrids()==1) + { + hfontbody=CreateFont(16,0,0, 0, + 100, + FALSE, + FALSE,FALSE,DEFAULT_CHARSET, + OUT_DEFAULT_PRECIS, + CLIP_DEFAULT_PRECIS, + 0, + 0 , + TEXT("MS Shell Dlg")); + hfontheader=CreateFont(18,0,0, 0,FW_HEAVY,FALSE,FALSE,FALSE,DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, 0, 0, TEXT("MS Shell Dlg")); + hfonttitle=CreateFont(20,0,0, 0,FW_HEAVY,FALSE,FALSE,FALSE,DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, 0, 0, TEXT("MS Shell Dlg")); + } + + + if((BG_GridIndex >= 0)&&(BG_GridIndex < MAX_GRIDS))//if you aren't over the MAX_GRIDS limit, add a grid + { + + BGHS[BG_GridIndex].gridmenu = (UINT)GetMenu(hWnd); + + BGHS[BG_GridIndex].hlist1=CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("LISTBOX"), TEXT(""), + WS_CHILD|LBS_STANDARD,50,150,200,100,hWnd,NULL,hInst,NULL); + + BGHS[BG_GridIndex].hfont = hfontbody; + BGHS[BG_GridIndex].htitlefont = hfonttitle; + BGHS[BG_GridIndex].hcolumnheadingfont = hfontheader; + lstrcpy(BGHS[BG_GridIndex].title,lpcs->lpszName); + SendMessage(hWnd,WM_SETTEXT,0,(LPARAM)lpcs->lpszName); + + + } + if(BG_GridIndex == -1) + { + DestroyWindow(hWnd); + } + break; + default: + return DefWindowProc(hWnd, message, wParam, lParam); + } + return ReturnValue; +} + +int CountGrids() + { + int j,count; + count=0; + for(j=0;j= 0)) + { + BGHS[empty_space].gridmenu = menuid; + returnvalue=empty_space; + } + if(MATCH) + { + return returnvalue+MAX_GRIDS; + } + if((!MATCH)&&(empty_space == -1)) + { + return -1; + } + return returnvalue; + + } + +int FindGrid( UINT menuid) + { + //if grid doesn't exist, return -1, else return gridindex + int returnvalue; + int j; + returnvalue = -1; + for(j=0;j0) + { + //it was greater than the tail... not found + ReturnValue = LB_ERR; + return ReturnValue; + } + + //is it the finger? + ReturnValue = LB_ERR; + FOUND=FALSE; + + + while((!FOUND)&&((tail-head)>1)) + { + finger = head + ((tail - head) / 2); + + SendMessage(lbhWnd,LB_GETTEXT,finger,(LPARAM)tbuffer); + tbuffer[9] = 0x00; + p=lstrcmp(tbuffer,searchtext); + if(p==0) + { + FOUND=TRUE; + ReturnValue = finger; + } + + if(p<0) + { + //change tail to finger + head = finger; + } + if(p>0) + { + //change head to finger + tail = finger; + } + + + } + return ReturnValue; + } + diff --git a/PowerEditor/src/WinControls/Grid/BabyGrid.h b/PowerEditor/src/WinControls/Grid/BabyGrid.h new file mode 100644 index 00000000..3922a3b0 --- /dev/null +++ b/PowerEditor/src/WinControls/Grid/BabyGrid.h @@ -0,0 +1,109 @@ +//BABYGRID code is copyrighted (C) 20002 by David Hillard +// +//This code must retain this copyright message +// +//Printed BABYGRID message reference and tutorial available. +//email: mudcat@mis.net for more information. + + +#include +#include "resource.h" + +#ifndef WM_MOUSEWHEEL +#define WM_MOUSEWHEEL 0x020A +#endif //WM_MOUSEWHEEL + +#define BGN_LBUTTONDOWN 0x0001 +#define BGN_MOUSEMOVE 0x0002 +#define BGN_OUTOFRANGE 0x0003 +#define BGN_OWNERDRAW 0x0004 +#define BGN_SELCHANGE 0x0005 +#define BGN_ROWCHANGED 0x0006 +#define BGN_COLCHANGED 0x0007 +#define BGN_EDITBEGIN 0x0008 +#define BGN_DELETECELL 0x0009 +#define BGN_EDITEND 0x000A +#define BGN_F1 0x000B +#define BGN_F2 0x000C +#define BGN_F3 0x000D +#define BGN_F4 0x000E +#define BGN_F5 0x000F +#define BGN_F6 0x0010 +#define BGN_F7 0x0011 +#define BGN_F8 0x0012 +#define BGN_F9 0x0013 +#define BGN_F10 0x0014 +#define BGN_F11 0x0015 +#define BGN_F12 0x0016 +#define BGN_GOTFOCUS 0x0017 +#define BGN_LOSTFOCUS 0x0018 +#define BGN_CELLCLICKED 0x0019 +#define BGN_CELLDBCLICKED 0x001A +#define BGN_CELLRCLICKED 0x001B + + + +#define BGM_PROTECTCELL BABYGRID_USER + 1 +#define BGM_SETPROTECT BABYGRID_USER + 2 +#define BGM_SETCELLDATA BABYGRID_USER + 3 +#define BGM_GETCELLDATA BABYGRID_USER + 4 +#define BGM_CLEARGRID BABYGRID_USER + 5 +#define BGM_SETGRIDDIM BABYGRID_USER + 6 +#define BGM_DELETECELL BABYGRID_USER + 7 +#define BGM_SETCURSORPOS BABYGRID_USER + 8 +#define BGM_AUTOROW BABYGRID_USER + 9 +#define BGM_GETOWNERDRAWITEM BABYGRID_USER + 10 +#define BGM_SETCOLWIDTH BABYGRID_USER + 11 +#define BGM_SETHEADERROWHEIGHT BABYGRID_USER + 12 +#define BGM_GETTYPE BABYGRID_USER + 13 +#define BGM_GETPROTECTION BABYGRID_USER + 14 +#define BGM_DRAWCURSOR BABYGRID_USER + 15 +#define BGM_SETROWHEIGHT BABYGRID_USER + 16 +#define BGM_SETCURSORCOLOR BABYGRID_USER + 17 +#define BGM_SETPROTECTCOLOR BABYGRID_USER + 18 +#define BGM_SETUNPROTECTCOLOR BABYGRID_USER + 19 +#define BGM_SETROWSNUMBERED BABYGRID_USER + 20 +#define BGM_SETCOLSNUMBERED BABYGRID_USER + 21 +#define BGM_SHOWHILIGHT BABYGRID_USER + 22 +#define BGM_GETROWS BABYGRID_USER + 23 +#define BGM_GETCOLS BABYGRID_USER + 24 +#define BGM_NOTIFYROWCHANGED BABYGRID_USER + 25 +#define BGM_NOTIFYCOLCHANGED BABYGRID_USER + 26 +#define BGM_GETROW BABYGRID_USER + 27 +#define BGM_GETCOL BABYGRID_USER + 28 +#define BGM_PAINTGRID BABYGRID_USER + 29 +#define BGM_GETCOLWIDTH BABYGRID_USER + 30 +#define BGM_GETROWHEIGHT BABYGRID_USER + 31 +#define BGM_GETHEADERROWHEIGHT BABYGRID_USER + 32 +#define BGM_SETTITLEHEIGHT BABYGRID_USER + 33 + +#define BGM_SETHILIGHTCOLOR BABYGRID_USER + 34 +#define BGM_SETHILIGHTTEXTCOLOR BABYGRID_USER + 35 +#define BGM_SETEDITABLE BABYGRID_USER + 36 +#define BGM_SETGRIDLINECOLOR BABYGRID_USER + 37 +#define BGM_EXTENDLASTCOLUMN BABYGRID_USER + 38 +#define BGM_SHOWINTEGRALROWS BABYGRID_USER + 39 +#define BGM_SETELLIPSIS BABYGRID_USER + 40 +#define BGM_SETCOLAUTOWIDTH BABYGRID_USER + 41 +#define BGM_SETALLOWCOLRESIZE BABYGRID_USER + 42 +#define BGM_SETTITLEFONT BABYGRID_USER + 43 +#define BGM_SETHEADINGFONT BABYGRID_USER + 44 + + struct _BGCELL { + int row; + int col; + }; + + +//function forward declarations +ATOM RegisterGridClass(HINSTANCE); +LRESULT CALLBACK GridProc(HWND, UINT, WPARAM, LPARAM); +void SetCell(_BGCELL *cell,int row, int col); + + +//global variables + + + + + diff --git a/PowerEditor/src/WinControls/Grid/BabyGridWrapper.cpp b/PowerEditor/src/WinControls/Grid/BabyGridWrapper.cpp new file mode 100644 index 00000000..8c0b9f6b --- /dev/null +++ b/PowerEditor/src/WinControls/Grid/BabyGridWrapper.cpp @@ -0,0 +1,41 @@ +/* +this file is part of notepad++ +Copyright (C)2003 Don HO ( donho@altern.org ) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "BabyGridWrapper.h" +const TCHAR *babyGridClassName = TEXT("BABYGRID"); + +bool BabyGridWrapper::_isRegistered = false; + +void BabyGridWrapper::init(HINSTANCE hInst, HWND parent, int id) +{ + Window::init(hInst, parent); + + if (!_isRegistered) + RegisterGridClass(_hInst); + + _hSelf = ::CreateWindowEx(WS_EX_CLIENTEDGE, + babyGridClassName,\ + TEXT(""),\ + WS_CHILD | WS_VISIBLE,\ + CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,\ + _hParent,\ + (HMENU)id,\ + _hInst,\ + (LPVOID)/*this*/NULL); +} diff --git a/PowerEditor/src/WinControls/Grid/BabyGridWrapper.h b/PowerEditor/src/WinControls/Grid/BabyGridWrapper.h new file mode 100644 index 00000000..33104541 --- /dev/null +++ b/PowerEditor/src/WinControls/Grid/BabyGridWrapper.h @@ -0,0 +1,91 @@ +/* +this file is part of notepad++ +Copyright (C)2003 Don HO ( donho@altern.org ) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ +#ifndef BABYGRIDWRAPPER +#define BABYGRIDWRAPPER + +#include "babygrid.h" +#include "Window.h" + +class BabyGridWrapper : public Window +{ +public : + BabyGridWrapper() : Window(){}; + ~BabyGridWrapper(){}; + virtual void init(HINSTANCE hInst, HWND parent, int id); + virtual void destroy() { + ::DestroyWindow(_hSelf); + }; + void setLineColNumber(size_t nbRow, size_t nbCol) { + ::SendMessage(_hSelf, BGM_SETGRIDDIM, nbRow, nbCol); + }; + + void setCursorColour(COLORREF coulour) { + ::SendMessage(_hSelf, BGM_SETCURSORCOLOR, (UINT)coulour, 0); + }; + + void hideCursor() { + setCursorColour(RGB(0, 0, 0)); + }; + + void setColsNumbered(bool isNumbered = true) { + ::SendMessage(_hSelf, BGM_SETCOLSNUMBERED, isNumbered?TRUE:FALSE, 0); + } + + void setText(size_t row, size_t col, const TCHAR *text) { + _BGCELL cell; + cell.row = row; + cell.col = col; + ::SendMessage(_hSelf, BGM_SETCELLDATA, (UINT)&cell, (long)text); + }; + + void makeColAutoWidth(bool autoWidth = true) { + ::SendMessage(_hSelf, BGM_SETCOLAUTOWIDTH, autoWidth?TRUE:FALSE, 0); + }; + + int getSelectedRow() { + return ::SendMessage(_hSelf, BGM_GETROW, 0, 0); + }; + + void deleteCell(int row, int col) { + _BGCELL cell; + cell.row = row; + cell.col = col; + ::SendMessage(_hSelf, BGM_DELETECELL, (UINT)&cell, 0); + }; + + void setColWidth(unsigned int col, unsigned int width) { + ::SendMessage(_hSelf, BGM_SETCOLWIDTH, col, width); + }; + + void clear() { + ::SendMessage(_hSelf, BGM_CLEARGRID, 0, 0); + }; + +private : + static bool _isRegistered; +/* + static LRESULT CALLBACK staticWinProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { + return (((BabyGridWrapper *)(::GetWindowLongPtr(hwnd, GWL_USERDATA)))->runProc(Message, wParam, lParam)); + }; + LRESULT runProc(UINT Message, WPARAM wParam, LPARAM lParam); +*/ +}; + +#endif //BABYGRIDWRAPPER + diff --git a/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp b/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp new file mode 100644 index 00000000..3ccfca40 --- /dev/null +++ b/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp @@ -0,0 +1,400 @@ +/* +this file is part of notepad++ +Copyright (C)2003 Don HO ( donho@altern.org ) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "ShortcutMapper.h" +#include "Notepad_plus.h" + +void ShortcutMapper::initTabs() { + HWND hTab = _hTabCtrl = ::GetDlgItem(_hSelf, IDC_BABYGRID_TABBAR); + TCITEM tie; + tie.mask = TCIF_TEXT; + tie.pszText = tabNames[0]; + ::SendMessage(hTab, TCM_INSERTITEM, 0, (LPARAM)(&tie) ); + tie.pszText = tabNames[1]; + ::SendMessage(hTab, TCM_INSERTITEM, 1, (LPARAM)(&tie) ); + tie.pszText = tabNames[2]; + ::SendMessage(hTab, TCM_INSERTITEM, 2, (LPARAM)(&tie) ); + tie.pszText = tabNames[3]; + ::SendMessage(hTab, TCM_INSERTITEM, 3, (LPARAM)(&tie) ); + tie.pszText = tabNames[4]; + ::SendMessage(hTab, TCM_INSERTITEM, 4, (LPARAM)(&tie) ); +} + +void ShortcutMapper::translateTab(int index, const TCHAR * newname) { + if (index < 0 || index > 4) + return; + generic_strncpy(tabNames[index], newname, maxTabName); +} + +void ShortcutMapper::initBabyGrid() { + RECT rect; + getClientRect(rect); + + _babygrid.init(_hInst, _hSelf, IDD_BABYGRID_ID1); + //_babygrid.reSizeTo(rect); + _babygrid.reSizeToWH(rect); + _babygrid.hideCursor(); + _babygrid.makeColAutoWidth(); + _babygrid.setColsNumbered(false); + _babygrid.setColWidth(0, 30); + _babygrid.setColWidth(1, 250); +} + +void ShortcutMapper::fillOutBabyGrid() +{ + NppParameters *nppParam = NppParameters::getInstance(); + _babygrid.clear(); + + size_t nrItems = 0; + + switch(_currentState) { + case STATE_MENU: { + nrItems = nppParam->getUserShortcuts().size(); + _babygrid.setLineColNumber(nrItems, 2); + break; } + case STATE_MACRO: { + nrItems = nppParam->getMacroList().size(); + _babygrid.setLineColNumber(nrItems, 2); + break; } + case STATE_USER: { + nrItems = nppParam->getUserCommandList().size(); + _babygrid.setLineColNumber(nrItems, 2); + break; } + case STATE_PLUGIN: { + nrItems = nppParam->getPluginCommandList().size(); + _babygrid.setLineColNumber(nrItems, 2); + break; } + case STATE_SCINTILLA: { + nrItems = nppParam->getScintillaKeyList().size(); + _babygrid.setLineColNumber(nrItems, 2); + break; } + } + + _babygrid.setText(0, 1, TEXT("Name")); + _babygrid.setText(0, 2, TEXT("Shortcut")); + + switch(_currentState) { + case STATE_MENU: { + vector & cshortcuts = nppParam->getUserShortcuts(); + for(size_t i = 0; i < nrItems; i++) { + _babygrid.setText(i+1, 1, cshortcuts[i].getName()); + _babygrid.setText(i+1, 2, cshortcuts[i].toString().c_str()); + } + break; } + case STATE_MACRO: { + vector & cshortcuts = nppParam->getMacroList(); + for(size_t i = 0; i < nrItems; i++) { + _babygrid.setText(i+1, 1, cshortcuts[i].getName()); + _babygrid.setText(i+1, 2, cshortcuts[i].toString().c_str()); + } + break; } + case STATE_USER: { + vector & cshortcuts = nppParam->getUserCommandList(); + for(size_t i = 0; i < nrItems; i++) { + _babygrid.setText(i+1, 1, cshortcuts[i].getName()); + _babygrid.setText(i+1, 2, cshortcuts[i].toString().c_str()); + } + break; } + case STATE_PLUGIN: { + vector & cshortcuts = nppParam->getPluginCommandList(); + for(size_t i = 0; i < nrItems; i++) { + _babygrid.setText(i+1, 1, cshortcuts[i].getName()); + _babygrid.setText(i+1, 2, cshortcuts[i].toString().c_str()); + } + break; } + case STATE_SCINTILLA: { + vector & cshortcuts = nppParam->getScintillaKeyList(); + for(size_t i = 0; i < nrItems; i++) { + _babygrid.setText(i+1, 1, cshortcuts[i].getName()); + _babygrid.setText(i+1, 2, cshortcuts[i].toString().c_str()); + } + break; } + } +} + +BOOL CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) +{ + switch (message) + { + case WM_INITDIALOG : + { + + initBabyGrid(); + initTabs(); + fillOutBabyGrid(); + _babygrid.display(); + goToCenter(); + return TRUE; + } + + case WM_NOTIFY: { + NMHDR nmh = *((NMHDR*)lParam); + if (nmh.hwndFrom == _hTabCtrl) { + if (nmh.code == TCN_SELCHANGE) { + int index = TabCtrl_GetCurSel(_hTabCtrl); + switch (index) { + case 0: + _currentState = STATE_MENU; + break; + case 1: + _currentState = STATE_MACRO; + break; + case 2: + _currentState = STATE_USER; + break; + case 3: + _currentState = STATE_PLUGIN; + break; + case 4: + _currentState = STATE_SCINTILLA; + break; + } + fillOutBabyGrid(); + } + } + break; } + + case WM_COMMAND : + { + switch (LOWORD(wParam)) + { + case IDCANCEL : + { + ::EndDialog(_hSelf, -1); + return TRUE; + } + case IDOK : + { + ::EndDialog(_hSelf, 0); + return TRUE; + } + + case IDM_BABYGRID_MODIFY : + { + NppParameters *nppParam = NppParameters::getInstance(); + int row = _babygrid.getSelectedRow(); + + switch(_currentState) { + case STATE_MENU: { + //Get CommandShortcut corresponding to row + vector & shortcuts = nppParam->getUserShortcuts(); + CommandShortcut csc = shortcuts[row - 1], prevcsc = shortcuts[row - 1]; + csc.init(_hInst, _hSelf); + if (csc.doDialog() != -1 && prevcsc != csc) { //shortcut was altered + nppParam->addUserModifiedIndex(row-1); + shortcuts[row - 1] = csc; + _babygrid.setText(row, 2, csc.toString().c_str()); + //Notify current Accelerator class to update everything + nppParam->getAccelerator()->updateShortcuts(); + + } + break; } + case STATE_MACRO: { + //Get MacroShortcut corresponding to row + vector & shortcuts = nppParam->getMacroList(); + MacroShortcut msc = shortcuts[row - 1], prevmsc = shortcuts[row - 1]; + msc.init(_hInst, _hSelf); + if (msc.doDialog() != -1 && prevmsc != msc) { //shortcut was altered + shortcuts[row - 1] = msc; + _babygrid.setText(row, 1, msc.getName()); + _babygrid.setText(row, 2, msc.toString().c_str()); + + //Notify current Accelerator class to update everything + nppParam->getAccelerator()->updateShortcuts(); + + } + break; } + case STATE_USER: { + //Get UserCommand corresponding to row + vector & shortcuts = nppParam->getUserCommandList(); + UserCommand ucmd = shortcuts[row - 1], prevucmd = shortcuts[row - 1]; + ucmd.init(_hInst, _hSelf); + prevucmd = ucmd; + if (ucmd.doDialog() != -1 && prevucmd != ucmd) { //shortcut was altered + shortcuts[row - 1] = ucmd; + _babygrid.setText(row, 1, ucmd.getName()); + _babygrid.setText(row, 2, ucmd.toString().c_str()); + + //Notify current Accelerator class to update everything + nppParam->getAccelerator()->updateShortcuts(); + + } + break; } + case STATE_PLUGIN: { + //Get PluginCmdShortcut corresponding to row + vector & shortcuts = nppParam->getPluginCommandList(); + PluginCmdShortcut pcsc = shortcuts[row - 1], prevpcsc = shortcuts[row - 1]; + pcsc.init(_hInst, _hSelf); + prevpcsc = pcsc; + if (pcsc.doDialog() != -1 && prevpcsc != pcsc) { //shortcut was altered + nppParam->addPluginModifiedIndex(row-1); + shortcuts[row - 1] = pcsc; + _babygrid.setText(row, 2, pcsc.toString().c_str()); + + //Notify current Accelerator class to update everything + nppParam->getAccelerator()->updateShortcuts(); + unsigned long cmdID = pcsc.getID(); + ShortcutKey shortcut; + shortcut._isAlt = pcsc.getKeyCombo()._isAlt; + shortcut._isCtrl = pcsc.getKeyCombo()._isCtrl; + shortcut._isShift = pcsc.getKeyCombo()._isShift; + shortcut._key = pcsc.getKeyCombo()._key; + + ::SendMessage(_hParent, NPPM_INTERNAL_PLUGINSHORTCUTMOTIFIED, cmdID, (LPARAM)&shortcut); + } + break; } + case STATE_SCINTILLA: { + //Get ScintillaKeyMap corresponding to row + vector & shortcuts = nppParam->getScintillaKeyList(); + ScintillaKeyMap skm = shortcuts[row - 1], prevskm = shortcuts[row-1]; + skm.init(_hInst, _hSelf); + if (skm.doDialog() != -1 && prevskm != skm) + { + //shortcut was altered + nppParam->addScintillaModifiedIndex(row-1); + shortcuts[row-1] = skm; + _babygrid.setText(row, 2, skm.toString().c_str()); + + //Notify current Accelerator class to update key + nppParam->getScintillaAccelerator()->updateKeys(); + } + break; + } + } + return TRUE; + } + case IDM_BABYGRID_DELETE : + { + NppParameters *nppParam = NppParameters::getInstance(); + if (::MessageBox(_hSelf, TEXT("Are you sure you want to delete this shortcut?"), TEXT("Are you sure?"), MB_OKCANCEL) == IDOK) + { + const int row = _babygrid.getSelectedRow(); + int shortcutIndex = row-1; + DWORD cmdID;// = _pAccel->_pAccelArray[row-1].cmd; + + // Menu data + size_t posBase; + size_t nbElem; + HMENU hMenu; + + switch(_currentState) { + case STATE_MENU: + case STATE_PLUGIN: + case STATE_SCINTILLA: { + return FALSE; //this is bad + break; } + case STATE_MACRO: { + vector & theMacros = nppParam->getMacroList(); + vector::iterator it = theMacros.begin(); + cmdID = theMacros[shortcutIndex].getID(); + theMacros.erase(it + shortcutIndex); + fillOutBabyGrid(); + + // preparing to remove from menu + posBase = 6; + nbElem = theMacros.size(); + hMenu = ::GetSubMenu((HMENU)::SendMessage(_hParent, NPPM_INTERNAL_GETMENU, 0, 0), MENUINDEX_MACRO); + for (size_t i = shortcutIndex ; i < nbElem ; i++) //lower the IDs of the remaining items so there are no gaps + { + MacroShortcut ms = theMacros[i]; + ms.setID(ms.getID() - 1); //shift all IDs + theMacros[i] = ms; + } + //::SendMessage(_hParent, NPPM_INTERNAL_MACROLIST_MODIFIED, 0, 0); + break; } + case STATE_USER: { + vector & theUserCmds = nppParam->getUserCommandList(); + vector::iterator it = theUserCmds.begin(); + cmdID = theUserCmds[shortcutIndex].getID(); + theUserCmds.erase(it + shortcutIndex); + fillOutBabyGrid(); + + // preparing to remove from menu + posBase = 2; + nbElem = theUserCmds.size(); + hMenu = ::GetSubMenu((HMENU)::SendMessage(_hParent, NPPM_INTERNAL_GETMENU, 0, 0), MENUINDEX_RUN); + for (size_t i = shortcutIndex ; i < nbElem ; i++) //lower the IDs of the remaining items so there are no gaps + { + UserCommand uc = theUserCmds[i]; + uc.setID(uc.getID() - 1); //shift all IDs + theUserCmds[i] = uc; + } + + //::SendMessage(_hParent, NPPM_INTERNAL_USERCMDLIST_MODIFIED, 0, 0); + break; } + } + + // remove from menu + ::RemoveMenu(hMenu, cmdID, MF_BYCOMMAND); + cmdID++; + if (nbElem == 0) { + ::RemoveMenu(hMenu, posBase-1, MF_BYPOSITION); //remove separator + } else { + for (size_t i = shortcutIndex ; i < nbElem ; i++) //lower the IDs of the remaining menu items so there are no gaps + { + const int commandSize = 64; + TCHAR cmdName[commandSize]; + ::GetMenuString(hMenu, cmdID, cmdName, commandSize, MF_BYCOMMAND); + ::ModifyMenu(hMenu, cmdID, MF_BYCOMMAND, cmdID-1, cmdName); //update commandID + } + } + + nppParam->getAccelerator()->updateShortcuts(); + } + return TRUE; + } + case IDD_BABYGRID_ID1: { + if(HIWORD(wParam) == BGN_CELLDBCLICKED) //a cell was clicked in the properties grid + { + return ::SendMessage(_hSelf, WM_COMMAND, IDM_BABYGRID_MODIFY, LOWORD(lParam)); + } + else if(HIWORD(wParam) == BGN_CELLRCLICKED) //a cell was clicked in the properties grid + { + POINT p; + ::GetCursorPos(&p); + if (!_rightClickMenu.isCreated()) + { + vector itemUnitArray; + itemUnitArray.push_back(MenuItemUnit(IDM_BABYGRID_MODIFY, TEXT("Modify"))); + itemUnitArray.push_back(MenuItemUnit(IDM_BABYGRID_DELETE, TEXT("Delete"))); + _rightClickMenu.create(_hSelf, itemUnitArray); + } + switch(_currentState) { + case STATE_MACRO: + case STATE_USER: { + _rightClickMenu.enableItem(IDM_BABYGRID_DELETE, true); + break; } + case STATE_MENU: + case STATE_PLUGIN: + case STATE_SCINTILLA: { + _rightClickMenu.enableItem(IDM_BABYGRID_DELETE, false); + break; } + } + + _rightClickMenu.display(p); + return TRUE; + } + } + } + } + default: + return FALSE; + } + return FALSE; +} diff --git a/PowerEditor/src/WinControls/Grid/ShortcutMapper.h b/PowerEditor/src/WinControls/Grid/ShortcutMapper.h new file mode 100644 index 00000000..986272f9 --- /dev/null +++ b/PowerEditor/src/WinControls/Grid/ShortcutMapper.h @@ -0,0 +1,80 @@ +/* +this file is part of notepad++ +Copyright (C)2003 Don HO ( donho@altern.org ) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef SHORTCUTMAPPER +#define SHORTCUTMAPPER + +#include "BabyGridWrapper.h" +#include "ShortcutMapper_rc.h" +#include "shortcut.h" +#include "ContextMenu.h" + +enum GridState {STATE_MENU, STATE_MACRO, STATE_USER, STATE_PLUGIN, STATE_SCINTILLA}; + +class ShortcutMapper : public StaticDialog { +public: + ShortcutMapper() : _currentState(STATE_MENU), StaticDialog() { + generic_strncpy(tabNames[0], TEXT("Main menu"), maxTabName); + generic_strncpy(tabNames[1], TEXT("Macros"), maxTabName); + generic_strncpy(tabNames[2], TEXT("Run commands"), maxTabName); + generic_strncpy(tabNames[3], TEXT("Plugin commands"), maxTabName); + generic_strncpy(tabNames[4], TEXT("Scintilla commands"), maxTabName); + }; + ~ShortcutMapper() {}; + //void init(HINSTANCE hInst, HWND parent) {}; + void destroy() {}; + void doDialog(bool isRTL = false) { + if (isRTL) + { + DLGTEMPLATE *pMyDlgTemplate = NULL; + HGLOBAL hMyDlgTemplate = makeRTLResource(IDD_SHORTCUTMAPPER_DLG, &pMyDlgTemplate); + ::DialogBoxIndirectParam(_hInst, pMyDlgTemplate, _hParent, (DLGPROC)dlgProc, (LPARAM)this); + ::GlobalFree(hMyDlgTemplate); + } + else + ::DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_SHORTCUTMAPPER_DLG), _hParent, (DLGPROC)dlgProc, (LPARAM)this); + }; + void getClientRect(RECT & rc) const { + Window::getClientRect(rc); + rc.top += 40; + rc.bottom -= 20; + rc.left += 5; + }; + + void translateTab(int index, const TCHAR * newname); + +protected : + BOOL CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam); + +private: + static const int maxTabName = 64; + BabyGridWrapper _babygrid; + ContextMenu _rightClickMenu; + + GridState _currentState; + HWND _hTabCtrl; + + TCHAR tabNames[5][maxTabName]; + + void initTabs(); + void initBabyGrid(); + void fillOutBabyGrid(); +}; + +#endif //SHORTCUTMAPPER diff --git a/PowerEditor/src/WinControls/Grid/ShortcutMapper.rc b/PowerEditor/src/WinControls/Grid/ShortcutMapper.rc new file mode 100644 index 00000000..96453772 --- /dev/null +++ b/PowerEditor/src/WinControls/Grid/ShortcutMapper.rc @@ -0,0 +1,38 @@ +/* +this file is part of notepad++ +Copyright (C)2003 Don HO < donho@altern.org > + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + + +#include +#include "ShortcutMapper_rc.h" + +#ifndef IDC_STATIC +#define IDC_STATIC -1 +#endif + +IDD_SHORTCUTMAPPER_DLG DIALOGEX 0, 0, 391, 344 +STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | + WS_SYSMENU +//EXSTYLE WS_EX_TOOLWINDOW +CAPTION "Shortcut mapper" +FONT 8, TEXT("MS Shell Dlg"), 400, 0, 0x1 +BEGIN + DEFPUSHBUTTON "Close",IDOK,172,319,47,14 + CONTROL "",IDC_BABYGRID_TABBAR,"SysTabControl32",TCS_BUTTONS,6,6,372, + 12 +END diff --git a/PowerEditor/src/WinControls/Grid/ShortcutMapper_rc.h b/PowerEditor/src/WinControls/Grid/ShortcutMapper_rc.h new file mode 100644 index 00000000..405d095d --- /dev/null +++ b/PowerEditor/src/WinControls/Grid/ShortcutMapper_rc.h @@ -0,0 +1,24 @@ +/* +this file is part of notepad++ +Copyright (C)2003 Don HO < donho@altern.org > + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#define IDD_SHORTCUTMAPPER_DLG 2600 +#define IDD_BABYGRID_ID1 (IDD_SHORTCUTMAPPER_DLG + 1) +#define IDM_BABYGRID_MODIFY (IDD_SHORTCUTMAPPER_DLG + 2) +#define IDM_BABYGRID_DELETE (IDD_SHORTCUTMAPPER_DLG + 3) +#define IDC_BABYGRID_TABBAR (IDD_SHORTCUTMAPPER_DLG + 4) diff --git a/PowerEditor/src/WinControls/ImageListSet/ImageListSet.cpp b/PowerEditor/src/WinControls/ImageListSet/ImageListSet.cpp new file mode 100644 index 00000000..231461a3 --- /dev/null +++ b/PowerEditor/src/WinControls/ImageListSet/ImageListSet.cpp @@ -0,0 +1,62 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#include "ImageListSet.h" +//#include "resource.h" + +void ToolBarIcons::init(ToolBarButtonUnit *buttonUnitArray, int arraySize) +{ + for (int i = 0 ; i < arraySize ; i++) + _tbiis.push_back(buttonUnitArray[i]); + _nbCmd = arraySize; +} + +void ToolBarIcons::create(HINSTANCE hInst, int iconSize) +{ + _iconListVector.push_back(IconList()); + _iconListVector.push_back(IconList()); + _iconListVector.push_back(IconList()); + //_iconListVector.push_back(IconList()); + + _iconListVector[HLIST_DEFAULT].create(hInst, iconSize); + _iconListVector[HLIST_HOT].create(hInst, iconSize); + _iconListVector[HLIST_DISABLE].create(hInst, iconSize); + //_iconListVector[HLIST_UGLY].create(hInst, 16); + + reInit(iconSize); +} + +void ToolBarIcons::destroy() +{ + _iconListVector[HLIST_DEFAULT].destroy(); + _iconListVector[HLIST_HOT].destroy(); + _iconListVector[HLIST_DISABLE].destroy(); + //_iconListVector[HLIST_UGLY].destroy(); +} +/* +bool IconList::changeIcon(int index, const TCHAR *iconLocation) const +{ + HBITMAP hBmp = (HBITMAP)::LoadImage(_hInst, iconLocation, IMAGE_ICON, _iconSize, _iconSize, LR_LOADFROMFILE ); + if (!hBmp) + return false; + int i = ImageList_ReplaceIcon(_hImglst, index, (HICON)hBmp); + ::DeleteObject(hBmp); + return (i == index); +} +*/ + + diff --git a/PowerEditor/src/WinControls/ImageListSet/ImageListSet.h b/PowerEditor/src/WinControls/ImageListSet/ImageListSet.h new file mode 100644 index 00000000..ec87929c --- /dev/null +++ b/PowerEditor/src/WinControls/ImageListSet/ImageListSet.h @@ -0,0 +1,184 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef IMAGE_LIST_H +#define IMAGE_LIST_H + +#include +#include +#include + +const int nbMax = 45; +#define IDI_SEPARATOR_ICON -1 + +class IconList +{ +public : + IconList() : _hImglst(NULL) {}; + + void create(HINSTANCE hInst, int iconSize) { + InitCommonControls(); + _hInst = hInst; + _iconSize = iconSize; + _hImglst = ImageList_Create(iconSize, iconSize, ILC_COLOR32 | ILC_MASK, 0, nbMax); + if (!_hImglst) + throw int(25); + }; + + void create(int iconSize, HINSTANCE hInst, int *iconIDArray, int iconIDArraySize) { + create(hInst, iconSize); + _pIconIDArray = iconIDArray; + _iconIDArraySize = iconIDArraySize; + + for (int i = 0 ; i < iconIDArraySize ; i++) + addIcon(iconIDArray[i]); + }; + + void destroy() { + ImageList_Destroy(_hImglst); + }; + + HIMAGELIST getHandle() const {return _hImglst;}; + + void addIcon(int iconID) const { + HICON hIcon = ::LoadIcon(_hInst, MAKEINTRESOURCE(iconID)); + if (!hIcon) + throw int(26); + ImageList_AddIcon(_hImglst, hIcon); + ::DestroyIcon(hIcon); + }; + + bool changeIcon(int index, const TCHAR *iconLocation) const{ + HBITMAP hBmp = (HBITMAP)::LoadImage(_hInst, iconLocation, IMAGE_ICON, _iconSize, _iconSize, LR_LOADFROMFILE | LR_LOADMAP3DCOLORS | LR_LOADTRANSPARENT); + if (!hBmp) + return false; + int i = ImageList_ReplaceIcon(_hImglst, index, (HICON)hBmp); + ImageList_AddMasked(_hImglst, (HBITMAP)hBmp, RGB(255,0,255)); + ::DeleteObject(hBmp); + return (i == index); + }; + + void setIconSize(int size) const { + ImageList_SetIconSize(_hImglst, size, size); + for (int i = 0 ; i < _iconIDArraySize ; i++) + addIcon(_pIconIDArray[i]); + }; +private : + HIMAGELIST _hImglst; + HINSTANCE _hInst; + int *_pIconIDArray; + int _iconIDArraySize; + int _iconSize; +}; + +typedef struct +{ + int _cmdID; + + int _defaultIcon; + int _hotIcon; + int _grayIcon; + + int _stdIcon; +}ToolBarButtonUnit; + +typedef std::vector ToolBarIconIDs; + +typedef std::vector IconListVector; + +class IconLists +{ +public : + IconLists() {}; + HIMAGELIST getImageListHandle(int index) const { + return _iconListVector[index].getHandle(); + }; + +protected : + IconListVector _iconListVector; +}; + +const int HLIST_DEFAULT = 0; +const int HLIST_HOT = 1; +const int HLIST_DISABLE = 2; + +class ToolBarIcons : public IconLists +{ +public : + ToolBarIcons() : _nbCmd(0) {}; + + void init(ToolBarButtonUnit *buttonUnitArray, int arraySize); + void create(HINSTANCE hInst, int iconSize); + void destroy(); + + HIMAGELIST getDefaultLst() const { + return IconLists::getImageListHandle(HLIST_DEFAULT); + }; + + HIMAGELIST getHotLst() const { + return IconLists::getImageListHandle(HLIST_HOT); + }; + + HIMAGELIST getDisableLst() const { + return IconLists::getImageListHandle(HLIST_DISABLE); + }; + + unsigned int getNbCommand() const {return _nbCmd;}; + int getCommandAt(int index) const {return _cmdArray[index];}; + void resizeIcon(int size) { + reInit(size); + }; + + void reInit(int size) { + ImageList_SetIconSize(getDefaultLst(), size, size); + ImageList_SetIconSize(getHotLst(), size, size); + ImageList_SetIconSize(getDisableLst(), size, size); + + for (int i = 0 ; i < int(_tbiis.size()) ; i++) + { + if (_tbiis[i]._defaultIcon != -1) + { + _iconListVector[HLIST_DEFAULT].addIcon(_tbiis[i]._defaultIcon); + _iconListVector[HLIST_HOT].addIcon(_tbiis[i]._hotIcon); + _iconListVector[HLIST_DISABLE].addIcon(_tbiis[i]._grayIcon); + } + } + + }; + + int getNbIcon() const { + return int(_tbiis.size()); + }; + + int getStdIconAt(int i) const { + return _tbiis[i]._stdIcon; + }; + + bool replaceIcon(int witchList, int iconIndex, const TCHAR *iconLocation) const { + if ((witchList != HLIST_DEFAULT) && (witchList != HLIST_HOT) && (witchList != HLIST_DISABLE)) + return false; + return _iconListVector[witchList].changeIcon(iconIndex, iconLocation); + + }; + +private : + ToolBarIconIDs _tbiis; + int _cmdArray[nbMax]; + unsigned int _nbCmd; +}; + +#endif //IMAGE_LIST_H diff --git a/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.cpp b/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.cpp new file mode 100644 index 00000000..33edc2a8 --- /dev/null +++ b/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.cpp @@ -0,0 +1,409 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#include +#include "FileDialog.h" + + +FileDialog *FileDialog::staticThis = NULL; +//int FileDialog::_dialogFileBoxId = (NppParameters::getInstance())->getWinVersion() < WV_W2K?edt1:cmb13; + +FileDialog::FileDialog(HWND hwnd, HINSTANCE hInst) + : _nbCharFileExt(0), _nbExt(0), _fileExt(NULL) +{ + staticThis = this; + //for (int i = 0 ; i < nbExtMax ; i++) + // _extArray[i][0] = '\0'; + + _fileName[0] = '\0'; + + _winVersion = (NppParameters::getInstance())->getWinVersion(); + + _ofn.lStructSize = sizeof(_ofn); + if (_winVersion < WV_W2K) + _ofn.lStructSize = sizeof(OPENFILENAME); + _ofn.hwndOwner = hwnd; + _ofn.hInstance = hInst; + _ofn.lpstrCustomFilter = (LPTSTR) NULL; + _ofn.nMaxCustFilter = 0L; + _ofn.nFilterIndex = 1L; + _ofn.lpstrFile = _fileName; + _ofn.nMaxFile = sizeof(_fileName)/sizeof(TCHAR); + _ofn.lpstrFileTitle = NULL; + _ofn.nMaxFileTitle = 0; + _ofn.lpstrInitialDir = NULL; + _ofn.lpstrTitle = NULL; + _ofn.nFileOffset = 0; + _ofn.nFileExtension = 0; + _ofn.lpfnHook = NULL; + _ofn.lpstrDefExt = NULL; // No default extension + _ofn.lCustData = 0; + _ofn.Flags = OFN_PATHMUSTEXIST | OFN_EXPLORER | OFN_LONGNAMES | DS_CENTER | OFN_HIDEREADONLY; + _ofn.pvReserved = NULL; + _ofn.dwReserved = 0; + _ofn.FlagsEx = 0; +} + +FileDialog::~FileDialog() +{ + if (_fileExt) + { + delete[] _fileExt; + _fileExt = NULL; + } +} + +// This function set and concatenate the filter into the list box of FileDialog. +// The 1st parameter is the description of the file type, the 2nd .. Nth parameter(s) is (are) +// the file extension which should be ".WHATEVER", otherwise it (they) will be considered as +// a file name to filter. Since the nb of arguments is variable, you have to add NULL at the end. +// example : +// FileDialog.setExtFilter(TEXT("c/c++ src file"), TEXT(".c"), TEXT(".cpp"), TEXT(".cxx"), TEXT(".h"), NULL); +// FileDialog.setExtFilter(TEXT("Makefile"), TEXT("makefile"), TEXT("GNUmakefile"), NULL); +void FileDialog::setExtFilter(const TCHAR *extText, const TCHAR *ext, ...) +{ + // fill out the ext array for save as file dialog + //if (_nbExt < nbExtMax) + // lstrcpy(_extArray[_nbExt++], ext); + // + std::generic_string exts; + + va_list pArg; + va_start(pArg, ext); + + const TCHAR *ext2Concat; + ext2Concat = ext; + do + { + if (ext2Concat[0] == TEXT('.')) + exts += TEXT("*"); + exts += ext2Concat; + exts += TEXT(";"); + } + while ( (ext2Concat = va_arg(pArg, const TCHAR *)) != NULL ); + + va_end(pArg); + + // remove the last ';' + exts = exts.substr(0, exts.length()-1); + + setExtsFilter(extText, exts.c_str()); +} + +int FileDialog::setExtsFilter(const TCHAR *extText, const TCHAR *exts) +{ + // fill out the ext array for save as file dialog + //if (_nbExt < nbExtMax) + // lstrcpy(_extArray[_nbExt++], exts); + // + std::generic_string extFilter = extText; + TCHAR *oldFilter = NULL; + + extFilter += TEXT(" ("); + extFilter += exts; + extFilter += TEXT(")"); + + // Resize filter buffer + int nbCharAdditional = extFilter.length() + lstrlen(exts) + 3; // 3 additional for nulls + if (_fileExt) + { + oldFilter = new TCHAR[_nbCharFileExt]; + memcpy(oldFilter, _fileExt, _nbCharFileExt * sizeof(TCHAR)); + + delete[] _fileExt; + _fileExt = NULL; + } + + int nbCharNewFileExt = _nbCharFileExt + nbCharAdditional; + _fileExt = new TCHAR[nbCharNewFileExt]; + memset(_fileExt, 0, nbCharNewFileExt * sizeof(TCHAR)); + + // Restore previous filters + if (oldFilter) + { + memcpy(_fileExt, oldFilter, _nbCharFileExt * sizeof(TCHAR)); + delete[] oldFilter; + oldFilter = NULL; + } + + // Append new filter + TCHAR *pFileExt = _fileExt + _nbCharFileExt; + lstrcpy(pFileExt, extFilter.c_str()); + _nbCharFileExt += extFilter.length() + 1; + + pFileExt = _fileExt + _nbCharFileExt; + lstrcpy(pFileExt, exts); + _nbCharFileExt += lstrlen(exts) + 1; + + // Set file dialog pointer + _ofn.lpstrFilter = _fileExt; + + return _nbExt; +} + +TCHAR * FileDialog::doOpenSingleFileDlg() +{ + TCHAR dir[MAX_PATH]; + ::GetCurrentDirectory(MAX_PATH, dir); + NppParameters * params = NppParameters::getInstance(); + _ofn.lpstrInitialDir = params->getWorkingDir(); + + _ofn.Flags |= OFN_FILEMUSTEXIST; + + TCHAR *fn = NULL; + try { + fn = ::GetOpenFileName((OPENFILENAME*)&_ofn)?_fileName:NULL; + + if (params->getNppGUI()._openSaveDir == dir_last) + { + ::GetCurrentDirectory(MAX_PATH, dir); + params->setWorkingDir(dir); + } + } + catch(...) { + ::MessageBox(NULL, TEXT("GetSaveFileName crashes!!!"), TEXT(""), MB_OK); + } + + ::SetCurrentDirectory(dir); + + return (fn); +} + +stringVector * FileDialog::doOpenMultiFilesDlg() +{ + TCHAR dir[MAX_PATH]; + ::GetCurrentDirectory(MAX_PATH, dir); + //_ofn.lpstrInitialDir = dir; + + NppParameters * params = NppParameters::getInstance(); + _ofn.lpstrInitialDir = params->getWorkingDir(); + + _ofn.Flags |= OFN_FILEMUSTEXIST | OFN_ALLOWMULTISELECT; + + BOOL res = ::GetOpenFileName((OPENFILENAME*)&_ofn); + if (params->getNppGUI()._openSaveDir == dir_last) + { + ::GetCurrentDirectory(MAX_PATH, dir); + params->setWorkingDir(dir); + } + ::SetCurrentDirectory(dir); + + if (res) + { + TCHAR fn[MAX_PATH]; + TCHAR *pFn = _fileName + lstrlen(_fileName) + 1; + if (!(*pFn)) + _fileNames.push_back(std::generic_string(_fileName)); + else + { + lstrcpy(fn, _fileName); + if (fn[lstrlen(fn)-1] != '\\') + lstrcat(fn, TEXT("\\")); + } + int term = int(lstrlen(fn)); + + while (*pFn) + { + fn[term] = '\0'; + lstrcat(fn, pFn); + _fileNames.push_back(std::generic_string(fn)); + pFn += lstrlen(pFn) + 1; + } + + return &_fileNames; + } + else + return NULL; +} + +TCHAR * FileDialog::doSaveDlg() +{ + TCHAR dir[MAX_PATH]; + ::GetCurrentDirectory(MAX_PATH, dir); + //_ofn.lpstrInitialDir = dir; + + NppParameters * params = NppParameters::getInstance(); + _ofn.lpstrInitialDir = params->getWorkingDir(); + + _ofn.Flags |= OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_ENABLESIZING; + + _ofn.Flags |= OFN_ENABLEHOOK; + _ofn.lpfnHook = OFNHookProc; + + TCHAR *fn = NULL; + try { + fn = ::GetSaveFileName((OPENFILENAME*)&_ofn)?_fileName:NULL; + if (params->getNppGUI()._openSaveDir == dir_last) + { + ::GetCurrentDirectory(MAX_PATH, dir); + params->setWorkingDir(dir); + } + } + catch(...) { + ::MessageBox(NULL, TEXT("GetSaveFileName crashes!!!"), TEXT(""), MB_OK); + } + + ::SetCurrentDirectory(dir); + + return (fn); +} + +static HWND hFileDlg = NULL; +static WNDPROC oldProc = NULL; +static generic_string currentExt = TEXT(""); + +static BOOL CALLBACK fileDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { + switch (message) + { + case WM_COMMAND : + { + switch (wParam) + { + case IDOK : + { + HWND fnControl = ::GetDlgItem(hwnd, FileDialog::_dialogFileBoxId); + TCHAR fn[MAX_PATH]; + ::GetWindowText(fnControl, fn, MAX_PATH); + if (*fn == '\0') + return oldProc(hwnd, message, wParam, lParam); + + if (currentExt != TEXT("")) + { + generic_string fnExt = changeExt(fn, currentExt); + ::SetWindowText(fnControl, fnExt.c_str()); + } + return oldProc(hwnd, message, wParam, lParam); + } + + default : + break; + } + } + } + return oldProc(hwnd, message, wParam, lParam); +}; + +static TCHAR * get1stExt(TCHAR *ext) { // precondition : ext should be under the format : Batch (*.bat;*.cmd;*.nt) + TCHAR *begin = ext; + for ( ; *begin != '.' ; begin++); + TCHAR *end = ++begin; + for ( ; *end != ';' && *end != ')' ; end++); + *end = '\0'; + if (*begin == '*') + *begin = '\0'; + return begin; +}; + +static generic_string addExt(HWND textCtrl, HWND typeCtrl) { + TCHAR fn[MAX_PATH]; + ::GetWindowText(textCtrl, fn, MAX_PATH); + + int i = ::SendMessage(typeCtrl, CB_GETCURSEL, 0, 0); + + int cbTextLen = ::SendMessage(typeCtrl, CB_GETLBTEXTLEN, i, 0); + TCHAR * ext = new TCHAR[cbTextLen + 1]; + ::SendMessage(typeCtrl, CB_GETLBTEXT, i, (LPARAM)ext); + + TCHAR *pExt = get1stExt(ext); + if (*fn != '\0') + { + generic_string fnExt = changeExt(fn, pExt); + ::SetWindowText(textCtrl, fnExt.c_str()); + } + + generic_string returnExt = pExt; + delete[] ext; + return returnExt; +}; + + +UINT_PTR CALLBACK FileDialog::OFNHookProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + switch(uMsg) + { + case WM_INITDIALOG : + { + NppParameters *pNppParam = NppParameters::getInstance(); + int index = pNppParam->getFileSaveDlgFilterIndex(); + + ::SetWindowLongPtr(hWnd, GWL_USERDATA, (long)staticThis); + hFileDlg = ::GetParent(hWnd); + goToCenter(hFileDlg); + + if (index != -1) + { + HWND typeControl = ::GetDlgItem(hFileDlg, cmb1); + ::SendMessage(typeControl, CB_SETCURSEL, index, 0); + } + + // Don't touch the following 3 lines, they are cursed !!! + oldProc = (WNDPROC)::GetWindowLongPtr(hFileDlg, GWL_WNDPROC); + if ((long)oldProc > 0) + ::SetWindowLongPtr(hFileDlg, GWL_WNDPROC, (LONG)fileDlgProc); + + return FALSE; + } + + default : + { + FileDialog *pFileDialog = reinterpret_cast(::GetWindowLongPtr(hWnd, GWL_USERDATA)); + if (!pFileDialog) + { + return FALSE; + } + return pFileDialog->run(hWnd, uMsg, wParam, lParam); + } + } + return FALSE; +} + +BOOL APIENTRY FileDialog::run(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + switch (uMsg) + { + case WM_NOTIFY : + { + LPNMHDR pNmhdr = (LPNMHDR)lParam; + switch(pNmhdr->code) + { + case CDN_TYPECHANGE : + { + HWND fnControl = ::GetDlgItem(::GetParent(hWnd), _dialogFileBoxId); + HWND typeControl = ::GetDlgItem(::GetParent(hWnd), cmb1); + currentExt = addExt(fnControl, typeControl); + return TRUE; + //break; + } + + case CDN_FILEOK : + { + HWND typeControl = ::GetDlgItem(::GetParent(hWnd), cmb1); + int index = ::SendMessage(typeControl, CB_GETCURSEL, 0, 0); + NppParameters *pNppParam = NppParameters::getInstance(); + pNppParam->setFileSaveDlgFilterIndex(index); + return TRUE; + //break; + } + + default : + return FALSE; + } + + } + default : + return FALSE; + } +} diff --git a/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.h b/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.h new file mode 100644 index 00000000..abe1a3ff --- /dev/null +++ b/PowerEditor/src/WinControls/OpenSaveFileDialog/FileDialog.h @@ -0,0 +1,152 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef FILE_DIALOG_H +#define FILE_DIALOG_H + +//#define _WIN32_WINNT 0x0600 + +#include +#include +#include +#include +#include "Parameters.h" + +const int nbExtMax = 256; +const int extLenMax = 64; + +using namespace std; + +typedef vector stringVector; +//const bool styleOpen = true; +//const bool styleSave = false; + +struct OPENFILENAMENPP { + DWORD lStructSize; + HWND hwndOwner; + HINSTANCE hInstance; + LPCTSTR lpstrFilter; + LPTSTR lpstrCustomFilter; + DWORD nMaxCustFilter; + DWORD nFilterIndex; + LPTSTR lpstrFile; + DWORD nMaxFile; + LPTSTR lpstrFileTitle; + DWORD nMaxFileTitle; + LPCTSTR lpstrInitialDir; + LPCTSTR lpstrTitle; + DWORD Flags; + WORD nFileOffset; + WORD nFileExtension; + LPCTSTR lpstrDefExt; + LPARAM lCustData; + LPOFNHOOKPROC lpfnHook; + LPCTSTR lpTemplateName; + void * pvReserved; + DWORD dwReserved; + DWORD FlagsEx; +}; + + +static generic_string changeExt(generic_string fn, generic_string ext) +{ + if (ext == TEXT("")) + return fn; + + generic_string fnExt = fn; + + int index = fnExt.find_last_of(TEXT(".")); + generic_string extension = TEXT("."); + extension += ext; + if (index == generic_string::npos) + { + fnExt += extension; + } + else + { + int len = (extension.length() > fnExt.length() - index + 1)?extension.length():fnExt.length() - index + 1; + fnExt.replace(index, len, extension); + } + return fnExt; +}; + +static void goToCenter(HWND hwnd) +{ + RECT rc; + HWND hParent = ::GetParent(hwnd); + ::GetClientRect(hParent, &rc); + + //If window coordinates are all zero(ie,window is minimised),then assign desktop as the parent window. + if(rc.left == 0 && rc.right == 0 && rc.top == 0 && rc.bottom == 0) + { + //hParent = ::GetDesktopWindow(); + ::ShowWindow(hParent, SW_SHOWNORMAL); + ::GetClientRect(hParent,&rc); + } + + POINT center; + center.x = rc.left + (rc.right - rc.left)/2; + center.y = rc.top + (rc.bottom - rc.top)/2; + ::ClientToScreen(hParent, ¢er); + + RECT _rc; + ::GetWindowRect(hwnd, &_rc); + int x = center.x - (_rc.right - _rc.left)/2; + int y = center.y - (_rc.bottom - _rc.top)/2; + + ::SetWindowPos(hwnd, HWND_TOP, x, y, _rc.right - _rc.left, _rc.bottom - _rc.top, SWP_SHOWWINDOW); +}; + +class FileDialog +{ +public: + FileDialog(HWND hwnd, HINSTANCE hInst); + ~FileDialog(); + void setExtFilter(const TCHAR *, const TCHAR *, ...); + + int setExtsFilter(const TCHAR *extText, const TCHAR *exts); + void setDefFileName(const TCHAR *fn){lstrcpy(_fileName, fn);} + + TCHAR * doSaveDlg(); + stringVector * doOpenMultiFilesDlg(); + TCHAR * doOpenSingleFileDlg(); + bool isReadOnly() {return _ofn.Flags & OFN_READONLY;}; + + static int _dialogFileBoxId; +protected : + static UINT_PTR CALLBACK OFNHookProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); + BOOL APIENTRY run(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); + +private: + TCHAR _fileName[MAX_PATH*8]; + + TCHAR * _fileExt; + int _nbCharFileExt; + + stringVector _fileNames; + + OPENFILENAMENPP _ofn; + winVer _winVersion; + + + //TCHAR _extArray[nbExtMax][extLenMax]; + int _nbExt; + + static FileDialog *staticThis; +}; + +#endif //FILE_DIALOG_H diff --git a/PowerEditor/src/WinControls/Preference/preference.rc b/PowerEditor/src/WinControls/Preference/preference.rc new file mode 100644 index 00000000..aefc85d8 --- /dev/null +++ b/PowerEditor/src/WinControls/Preference/preference.rc @@ -0,0 +1,252 @@ +/* +this file is part of notepad++ +Copyright (C)2003 Don HO < donho@altern.org > + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include +#include "preference_rc.h" + +#ifndef IDC_STATIC +#define IDC_STATIC -1 +#endif +IDD_PREFERENCE_BOX DIALOGEX 0, 0, 400, 235 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU +EXSTYLE WS_EX_TOOLWINDOW | WS_EX_WINDOWEDGE +CAPTION "Preferences" +FONT 8, TEXT("MS Shell Dlg"), 0, 0, 0x1 +BEGIN + PUSHBUTTON "Close",IDC_BUTTON_CLOSE,174,212,45,14 +END + + +IDD_PREFERENCE_BAR_BOX DIALOGEX 0, 0, 390, 185 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD +FONT 8, "MS Shell Dlg", 0, 0, 0x1 +BEGIN + GROUPBOX "Tool bar",IDC_TOOLBAR_GB_STATIC,17,45,147,68,BS_CENTER + CONTROL "Hide",IDC_CHECK_HIDE,"Button",BS_AUTOCHECKBOX,24,55,94,10 + CONTROL "Small icons",IDC_RADIO_SMALLICON,"Button",BS_AUTORADIOBUTTON,24,69,114,10 + CONTROL "Big icons",IDC_RADIO_BIGICON,"Button",BS_AUTORADIOBUTTON,24,83,109,10 + CONTROL "Small standard icons",IDC_RADIO_STANDARD,"Button",BS_AUTORADIOBUTTON,24,97,119,10 + GROUPBOX "Tab bar",IDC_TABBAR_GB_STATIC,183,6,176,151,BS_CENTER + CONTROL "Hide",IDC_CHECK_TAB_HIDE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,189,16,108,10 + CONTROL "Multi-Line",IDC_CHECK_TAB_MULTILINE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,189,30,134,10 + CONTROL "Vertical",IDC_CHECK_TAB_VERTICAL,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,189,44,134,10 + CONTROL "Reduce",IDC_CHECK_REDUCE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,189,59,108,10 + CONTROL "Lock (No Drag N Drop)",IDC_CHECK_LOCK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,189,73,134,10 + CONTROL "Draw the inactive tabs",IDC_CHECK_DRAWINACTIVE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,189,88,134,10 + CONTROL "Draw the orange top bar",IDC_CHECK_ORANGE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,189,103,133,10 + CONTROL "Enable close button on each tab",IDC_CHECK_ENABLETABCLOSE, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,189,118,133,10 + CONTROL "Double click to close document",IDC_CHECK_DBCLICK2CLOSE, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,189,133,133,10 + CONTROL "Show Status Bar",IDC_CHECK_SHOWSTATUSBAR,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,18,163,130,10 + GROUPBOX "Menu bar",IDC_MENUBAR_GB_STATIC,17,117,147,40,BS_CENTER + CONTROL "Hide (Use Alt or F10 key to toggle it)",IDC_CHECK_HIDEMENUBAR, + "Button",BS_AUTOCHECKBOX | BS_MULTILINE,24,127,135,25 + GROUPBOX "Localization",IDC_LOCALIZATION_GB_STATIC,17,6,147,35,BS_CENTER + COMBOBOX IDC_COMBO_LOCALIZATION,28,20,119,80,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP +END + +IDD_PREFERENCE_MARGEIN_BOX DIALOGEX 0, 0, 390, 185 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD +FONT 8, "MS Shell Dlg", 0, 0, 0x1 +BEGIN + GROUPBOX "Folder margin style",IDC_FMS_GB_STATIC,32,69,149,42,BS_CENTER + CONTROL "Simple",IDC_RADIO_SIMPLE,"Button",BS_AUTORADIOBUTTON | WS_GROUP,41,82,59,10 + CONTROL "Arrow",IDC_RADIO_ARROW,"Button",BS_AUTORADIOBUTTON,41,96,60,10 + CONTROL "Circle tree",IDC_RADIO_CIRCLE,"Button",BS_AUTORADIOBUTTON,114,82,62,10 + CONTROL "Box tree",IDC_RADIO_BOX,"Button",BS_AUTORADIOBUTTON,114,96,61,10 + CONTROL "Display line number margin",IDC_CHECK_LINENUMBERMARGE, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,33,117,141,10 + CONTROL "Display bookmark margin",IDC_CHECK_BOOKMARKMARGE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,33,129,150,10 + //CONTROL "Display line change state margin",IDC_CHECK_DOCCHANGESTATEMARGE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,33,141,162,10 + CONTROL "Enable current line highlight",IDC_CHECK_CURRENTLINEHILITE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,33,141,129,10 + CONTROL "Show vertical edge",IDC_CHECK_SHOWVERTICALEDGE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,212,81,122,10 + RTEXT "Number of columns :",IDC_NBCOLONE_STATIC,207,129,83,8 + LTEXT "0",IDC_COLONENUMBER_STATIC,297,128,18,8 + GROUPBOX "Vertical Edge Setting",IDC_VES_GB_STATIC,201,69,148,77,BS_CENTER + CONTROL "Line mode",IDC_RADIO_LNMODE,"Button",BS_AUTORADIOBUTTON,215,97,91,10 + CONTROL "Background mode",IDC_RADIO_BGMODE,"Button",BS_AUTORADIOBUTTON,215,111,91,10 + GROUPBOX "",IDC_STATIC,20,54,350,118,0,WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE + COMBOBOX IDC_COMBO_SCINTILLAVIEWCHOIX,139,51,96,40,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + GROUPBOX "Caret settings",IDC_CARETSETTING_STATIC,23,5,199,40,BS_CENTER + LTEXT "Width :",IDC_WIDTH_STATIC,27,24,37,8,0,WS_EX_RIGHT + COMBOBOX IDC_WIDTH_COMBO,66,22,40,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + LTEXT "Blink Rate :",IDC_BLINKRATE_STATIC,138,17,50,8 + CONTROL "",IDC_CARETBLINKRATE_SLIDER,"msctls_trackbar32",TBS_AUTOTICKS | TBS_BOTH | TBS_NOTICKS | WS_TABSTOP,133,29,67,13 + GROUPBOX "Tab Setting",IDC_TABSETTING_GB_STATIC,238,4,130,40,BS_CENTER + CONTROL "Replace by space",IDC_CHECK_REPLACEBYSPACE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,256,27,100,10 + RTEXT "Tab size : ",IDC_TABSIZE_STATIC,251,14,58,8 + LTEXT "0",IDC_TABSIZEVAL_STATIC,311,14,18,8 + LTEXT "S",IDC_CARETBLINKRATE_S_STATIC,202,29,12,8 + LTEXT "F",IDC_CARETBLINKRATE_F_STATIC,121,29,12,8,0,WS_EX_RIGHT +END + + +IDD_PREFERENCE_SETTING_BOX DIALOGEX 0, 0, 390, 185 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD +FONT 8, "MS Shell Dlg", 0, 0, 0x1 +BEGIN + GROUPBOX "History File Setting",IDC_HISTORY_GB_STATIC,15,4,155,39,BS_CENTER + RTEXT "Max number history file :",IDC_MAXNBFILE_STATIC,18,14,112,8 + LTEXT "0",IDC_MAXNBFILEVAL_STATIC,137,14,15,8 + CONTROL "Don't check at launch time",IDC_CHECK_DONTCHECKHISTORY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,23,27,140,10 + GROUPBOX "Document switcher (Ctrl+TAB)",IDC_DOCUMENTSWITCHER_STATIC,15,48,155,39,BS_CENTER + CONTROL "Enable",IDC_CHECK_ENABLEDOCSWITCHER,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,23,59,69,10 + CONTROL "Enable MRU behaviour",IDC_CHECK_STYLEMRU,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,23,72,140,10 + CONTROL "Enable Notepad++ auto-updater",IDC_CHECK_AUTOUPDATE,"Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,16,94,150,10 + CONTROL "Smart highlighting",IDC_CHECK_ENABLSMARTHILITE,"Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,16,136,150,10 + CONTROL "Auto-indent",IDC_CHECK_MAINTAININDENT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,108,150,10 + CONTROL "Minimize to sys tray",IDC_CHECK_MIN2SYSTRAY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,122,150,10 + CONTROL "Show only filename in titlebar",IDC_CHECK_SHORTTITLE, "Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,16,150,217,10 + CONTROL "Remember the current session for next launch",IDC_CHECK_REMEMBERSESSION,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,164,217,10 + GROUPBOX "Clickable link setting",IDC_CLICKABLELINK_STATIC,193,4,155,39,BS_CENTER + CONTROL "Enable",IDC_CHECK_CLICKABLELINK_ENABLE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,201,15,140,10 + CONTROL "Don't draw underline",IDC_CHECK_CLICKABLELINK_NOUNDERLINE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,201,28,140,10 + GROUPBOX "File Status Auto-detection",IDC_FILEAUTODETECTION_STATIC,193,47,155,50,BS_CENTER + CONTROL "Enable",IDC_CHECK_FILEAUTODETECTION,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,201,57,140,10 + CONTROL "Update silently",IDC_CHECK_UPDATESILENTLY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,201,69,140,10 + CONTROL "Scroll to the last line after update",IDC_CHECK_UPDATEGOTOEOF,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,201,81,140,10 + GROUPBOX "Highlight matching tags",IDC_TAGMATCHEDHILITE_STATIC,193,101,155,50,BS_CENTER + CONTROL "Enable",IDC_CHECK_ENABLTAGSMATCHHILITE,"Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,201,111,140,10 + CONTROL "Highlight tag attributes",IDC_CHECK_ENABLTAGATTRHILITE,"Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,202,123,140,10 + CONTROL "Highlight php/asp zone",IDC_CHECK_HIGHLITENONEHTMLZONE, "Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,202,136,140,10 + RTEXT "Session file ext:",IDC_SESSIONFILEEXT_STATIC,205,160,108,8 + EDITTEXT IDC_EDIT_SESSIONFILEEXT,315,157,34,14,ES_AUTOHSCROLL +END + +IDD_PREFERENCE_NEWDOCSETTING_BOX DIALOGEX 0, 0, 390, 185 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD +FONT 8, "MS Shell Dlg", 0, 0, 0x1 +BEGIN + GROUPBOX "Format",IDC_FORMAT_GB_STATIC,225,12,110,55,BS_CENTER + CONTROL "Windows",IDC_RADIO_F_WIN,"Button",BS_AUTORADIOBUTTON | WS_GROUP,233,25,48,10 + CONTROL "Unix",IDC_RADIO_F_UNIX,"Button",BS_AUTORADIOBUTTON,233,38,56,10 + CONTROL "Mac",IDC_RADIO_F_MAC,"Button",BS_AUTORADIOBUTTON,233,52,60,10 + GROUPBOX "Encoding",IDC_ENCODING_STATIC,57,11,144,91,BS_CENTER + CONTROL "ANSI",IDC_RADIO_ANSI,"Button",BS_AUTORADIOBUTTON | WS_GROUP,64,20,80,10 + CONTROL "UTF-8 without BOM",IDC_RADIO_UTF8SANSBOM,"Button",BS_AUTORADIOBUTTON,64,34,128,10 + CONTROL "UTF-8",IDC_RADIO_UTF8,"Button",BS_AUTORADIOBUTTON,64,59,62,10 + CONTROL "UCS-2 big endian",IDC_RADIO_UCS2BIG,"Button",BS_AUTORADIOBUTTON,64,73,103,10 + CONTROL "UCS-2 small endian",IDC_RADIO_UCS2SMALL,"Button",BS_AUTORADIOBUTTON,64,87,102,10 + RTEXT "Default Language :",IDC_DEFAULTLANG_STATIC,203,83,77,8 + COMBOBOX IDC_COMBO_DEFAULTLANG,285,81,60,140,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + GROUPBOX "New Document",IDC_NEWDOCUMENT_GR_STATIC,47,2,304,108,BS_CENTER + GROUPBOX "File Open/Save Directory",IDC_OPENSAVEDIR_GR_STATIC,47,117,304,61,BS_CENTER + CONTROL "Follow the current document",IDC_OPENSAVEDIR_FOLLOWCURRENT_RADIO, + "Button",BS_AUTORADIOBUTTON | WS_GROUP,64,129,200,10 + CONTROL "Remember the last operation directory",IDC_OPENSAVEDIR_REMEMBERLAST_RADIO, + "Button",BS_AUTORADIOBUTTON,64,144,217,10 + CONTROL "",IDC_OPENSAVEDIR_ALWAYSON_RADIO,"Button",BS_AUTORADIOBUTTON,64,156,11,10 + EDITTEXT IDC_OPENSAVEDIR_ALWAYSON_EDIT,80,157,179,14,ES_AUTOHSCROLL + PUSHBUTTON "...",IDD_OPENSAVEDIR_ALWAYSON_BROWSE_BUTTON,266,156,16,14 + CONTROL "Apply while open ANSI file",IDC_CHECK_OPENANSIASUTF8,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,74,46,124,10 +END + +IDD_PREFERENCE_LANG_BOX DIALOGEX 0, 0, 390, 185 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD +FONT 8, TEXT("MS Shell Dlg"), 0, 0, 0x1 +BEGIN + LISTBOX IDC_LIST_ENABLEDLANG,85,39,78,120,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP + LISTBOX IDC_LIST_DISABLEDLANG,231,39,78,120,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP + PUSHBUTTON "->",IDC_BUTTON_REMOVE,172,71,50,14 + PUSHBUTTON "<-",IDC_BUTTON_RESTORE,173,102,50,14 + CTEXT "Available items",IDC_ENABLEDITEMS_STATIC,88,26,72,8 + CTEXT "Disabled items",IDC_DISABLEDITEMS_STATIC,234,26,72,8 + CONTROL "Make Language Menu compact",IDC_CHECK_LANGMENUCOMPACT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,86,5,174,10 +END + +IDD_PREFERENCE_PRINT_BOX DIALOGEX 0, 0, 390, 185 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD +FONT 8, TEXT("MS Shell Dlg"), 0, 0, 0x1 +BEGIN + CONTROL "WYSIWYG",IDC_RADIO_WYSIWYG,"Button",BS_AUTORADIOBUTTON,50,65,123,10 + CONTROL "Invert",IDC_RADIO_INVERT,"Button",BS_AUTORADIOBUTTON,50,80,90,10 + CONTROL "Black on white",IDC_RADIO_BW,"Button",BS_AUTORADIOBUTTON,50,95,90,10 + CONTROL "No background colour",IDC_RADIO_NOBG,"Button",BS_AUTORADIOBUTTON,50,111,123,10 + GROUPBOX "Colour Option",IDC_COLOUROPT_STATIC,45,45,133,96,BS_CENTER + CONTROL "Print Line Number",IDC_CHECK_PRINTLINENUM,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,46,30,145,10 + EDITTEXT IDC_EDIT_ML,228,88,17,14,ES_NUMBER + EDITTEXT IDC_EDIT_MT,249,69,17,14,ES_NUMBER + EDITTEXT IDC_EDIT_MR,269,88,17,14,ES_NUMBER + EDITTEXT IDC_EDIT_MB,249,109,17,14,ES_NUMBER + RTEXT "Left",IDC_ML_STATIC,195,91,30,8 + CTEXT "Top",IDC_MT_STATIC,231,59,54,8 + LTEXT "Right",IDC_MR_STATIC,291,91,29,8 + CTEXT "Bottom",IDC_MB_STATIC,231,124,54,8 + GROUPBOX "Margin Setting (Unit:mm)",IDC_MARGESETTINGS_STATIC,187,45,144,96,BS_CENTER +END + +IDD_PREFERENCE_PRINT2_BOX DIALOGEX 0, 0, 390, 185 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD +FONT 8, TEXT("MS Shell Dlg"), 0, 0, 0x1 +BEGIN + EDITTEXT IDC_EDIT_HLEFT,59,48,83,14,ES_AUTOHSCROLL + EDITTEXT IDC_EDIT_HMIDDLE,149,48,83,14,ES_CENTER | ES_AUTOHSCROLL + EDITTEXT IDC_EDIT_HRIGHT,239,48,83,14,ES_RIGHT | ES_AUTOHSCROLL + COMBOBOX IDC_COMBO_HFONTNAME,59,66,84,104,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + COMBOBOX IDC_COMBO_HFONTSIZE,149,66,31,72,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + CONTROL "Bold",IDC_CHECK_HBOLD,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,189,66,46,10 + CONTROL "Italic",IDC_CHECK_HITALIC,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,249,66,43,10 + GROUPBOX "Header",IDC_HGB_STATIC,51,29,279,56,BS_CENTER + CTEXT "Left part",IDC_HL_STATIC,61,39,79,8 + CTEXT "Middle part",IDC_HM_STATIC,153,39,75,8 + CTEXT "Right part",IDC_HR_STATIC,241,39,78,8 + EDITTEXT IDC_EDIT_FLEFT,59,106,83,14,ES_AUTOHSCROLL + EDITTEXT IDC_EDIT_FMIDDLE,150,106,83,14,ES_CENTER | ES_AUTOHSCROLL + EDITTEXT IDC_EDIT_FRIGHT,239,106,83,14,ES_RIGHT | ES_AUTOHSCROLL + COMBOBOX IDC_COMBO_FFONTNAME,59,124,84,119,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + COMBOBOX IDC_COMBO_FFONTSIZE,151,124,31,71,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + CONTROL "Bold",IDC_CHECK_FBOLD,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,190,126,46,10 + CONTROL "Italic",IDC_CHECK_FITALIC,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,249,126,47,10 + GROUPBOX "Footer",IDC_FGB_STATIC,51,87,279,58,BS_CENTER + CTEXT "Left part",IDC_FL_STATIC,61,97,78,8 + CTEXT "Middle part",IDC_FM_STATIC,150,97,82,8 + CTEXT "Right part",IDC_FR_STATIC,241,97,79,8 + COMBOBOX IDC_COMBO_VARLIST,113,14,70,58,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + PUSHBUTTON "Add",IDC_BUTTON_ADDVAR,191,14,44,12 + RTEXT "Variable :",IDC_VAR_STATIC,52,16,59,8 + RTEXT "Which part :",IDC_WHICHPART_STATIC,38,149,80,8 + LTEXT "",IDC_VIEWPANEL_STATIC,121,149,213,8 +END + +IDD_PREFERENCE_BACKUP_BOX DIALOGEX 0, 0, 390, 185 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD +FONT 8, TEXT("MS Shell Dlg"), 0, 0, 0x1 +BEGIN + GROUPBOX "Backup",IDC_BACKUPDIR_GRP_STATIC,46,11,289,86,BS_CENTER + CONTROL "None",IDC_RADIO_BKNONE,"Button",BS_AUTORADIOBUTTON | WS_GROUP,71,24,87,10 + CONTROL "Simple Backup",IDC_RADIO_BKSIMPLE,"Button",BS_AUTORADIOBUTTON,195,24,111,10 + CONTROL "Verbose Backup",IDC_RADIO_BKVERBOSE,"Button",BS_AUTORADIOBUTTON,195,38,111,10 + GROUPBOX "User custom backup directory",IDC_BACKUPDIR_USERCUSTOMDIR_GRPSTATIC,62,50,260,40 + CONTROL "",IDC_BACKUPDIR_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,58,50,8,10 + RTEXT "Directory :",IDD_BACKUPDIR_STATIC,66,67,40,8 + EDITTEXT IDC_BACKUPDIR_EDIT,113,65,179,14,ES_AUTOHSCROLL + PUSHBUTTON "...",IDD_BACKUPDIR_BROWSE_BUTTON,299,65,16,14 + GROUPBOX "Auto-completion",IDD_AUTOC_GRPSTATIC,46,103,289,73,BS_CENTER + CONTROL "Enable Auto-completion on each input",IDD_AUTOC_ENABLECHECK, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,51,114,150,10 + CONTROL "Function completion",IDD_AUTOC_FUNCRADIO,"Button",BS_AUTORADIOBUTTON | WS_GROUP,78,128,145,10 + CONTROL "Word completion",IDD_AUTOC_WORDRADIO,"Button",BS_AUTORADIOBUTTON,78,144,145,10 + RTEXT "From",IDD_AUTOC_STATIC_FROM,208,114,47,8 + CTEXT "1",IDD_AUTOC_STATIC_N,259,114,8,8 + LTEXT "th characters",IDD_AUTOC_STATIC_CHAR,273,114,57,8 + LTEXT "Valid value : 1 - 9",IDD_AUTOC_STATIC_NOTE,238,124,93,8 + CONTROL "Function parameters hint on input",IDD_FUNC_CHECK, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,51,156,160,10 +END diff --git a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp new file mode 100644 index 00000000..87692526 --- /dev/null +++ b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp @@ -0,0 +1,1778 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#include +#include "preferenceDlg.h" + +const int BLINKRATE_FASTEST = 50; +const int BLINKRATE_SLOWEST = 2500; +const int BLINKRATE_INTERVAL = 50; + +BOOL CALLBACK PreferenceDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam) +{ + switch (Message) + { + case WM_INITDIALOG : + { + _ctrlTab.init(_hInst, _hSelf, false, true, true); + _ctrlTab.setFont(TEXT("Tahoma"), 13); + + _barsDlg.init(_hInst, _hSelf); + _barsDlg.create(IDD_PREFERENCE_BAR_BOX); + _barsDlg.display(); + + _marginsDlg.init(_hInst, _hSelf); + _marginsDlg.create(IDD_PREFERENCE_MARGEIN_BOX); + + _settingsDlg.init(_hInst, _hSelf); + _settingsDlg.create(IDD_PREFERENCE_SETTING_BOX); + + _defaultNewDocDlg.init(_hInst, _hSelf); + _defaultNewDocDlg.create(IDD_PREFERENCE_NEWDOCSETTING_BOX); + + _fileAssocDlg.init(_hInst, _hSelf); + _fileAssocDlg.create(IDD_REGEXT_BOX); + + _printSettingsDlg.init(_hInst, _hSelf); + _printSettingsDlg.create(IDD_PREFERENCE_PRINT_BOX); + + + _printSettings2Dlg.init(_hInst, _hSelf); + _printSettings2Dlg.create(IDD_PREFERENCE_PRINT2_BOX); + + _langMenuDlg.init(_hInst, _hSelf); + _langMenuDlg.create(IDD_PREFERENCE_LANG_BOX); + + _backupDlg.init(_hInst, _hSelf); + _backupDlg.create(IDD_PREFERENCE_BACKUP_BOX); + + _wVector.push_back(DlgInfo(&_barsDlg, TEXT("Global"), TEXT("Global"))); + _wVector.push_back(DlgInfo(&_marginsDlg, TEXT("Edit Components"), TEXT("Scintillas"))); + _wVector.push_back(DlgInfo(&_defaultNewDocDlg, TEXT("New Document/Open Save Directory"), TEXT("NewDoc"))); + _wVector.push_back(DlgInfo(&_fileAssocDlg, TEXT("File Association"), TEXT("FileAssoc"))); + _wVector.push_back(DlgInfo(&_langMenuDlg, TEXT("Language Menu"), TEXT("LangMenu"))); + _wVector.push_back(DlgInfo(&_printSettingsDlg, TEXT("Print - Colour and Margin"), TEXT("Print1"))); + _wVector.push_back(DlgInfo(&_printSettings2Dlg, TEXT("Print - Header and Footer"), TEXT("Print2"))); + _wVector.push_back(DlgInfo(&_backupDlg, TEXT("Backup/Auto-completion"), TEXT("Backup"))); + _wVector.push_back(DlgInfo(&_settingsDlg, TEXT("MISC"), TEXT("MISC"))); + _ctrlTab.createTabs(_wVector); + _ctrlTab.display(); + RECT rc; + getClientRect(rc); + _ctrlTab.reSizeTo(rc); + rc.bottom -= 30; + + _barsDlg.reSizeTo(rc); + _marginsDlg.reSizeTo(rc); + _settingsDlg.reSizeTo(rc); + _defaultNewDocDlg.reSizeTo(rc); + _fileAssocDlg.reSizeTo(rc); + _langMenuDlg.reSizeTo(rc); + _printSettingsDlg.reSizeTo(rc); + _printSettings2Dlg.reSizeTo(rc); + _backupDlg.reSizeTo(rc); + + NppParameters *pNppParam = NppParameters::getInstance(); + ETDTProc enableDlgTheme = (ETDTProc)pNppParam->getEnableThemeDlgTexture(); + if (enableDlgTheme) + enableDlgTheme(_hSelf, ETDT_ENABLETAB); + return TRUE; + } + + case WM_NOTIFY : + { + NMHDR *nmhdr = (NMHDR *)lParam; + if (nmhdr->code == TCN_SELCHANGE) + { + if (nmhdr->hwndFrom == _ctrlTab.getHSelf()) + { + _ctrlTab.clickedUpdate(); + return TRUE; + } + } + break; + } + + case WM_COMMAND : + { + switch (wParam) + { + case IDC_BUTTON_CLOSE : + case IDCANCEL : + display(false); + return TRUE; + + default : + ::SendMessage(_hParent, WM_COMMAND, wParam, lParam); + return TRUE; + } + } + } + return FALSE; +} + +BOOL CALLBACK BarsDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam) +{ + NppParameters *pNppParam = NppParameters::getInstance(); + switch (Message) + { + case WM_INITDIALOG : + { + const NppGUI & nppGUI = pNppParam->getNppGUI(); + toolBarStatusType tbStatus = nppGUI._toolBarStatus; + int tabBarStatus = nppGUI._tabStatus; + bool showTool = nppGUI._toolbarShow; + bool showStatus = nppGUI._statusBarShow; + bool showMenu = nppGUI._menuBarShow; + + + ::SendDlgItemMessage(_hSelf, IDC_CHECK_HIDE, BM_SETCHECK, showTool?BST_UNCHECKED:BST_CHECKED, 0); + int ID2Check = 0; + switch (tbStatus) + { + case TB_SMALL : + ID2Check = IDC_RADIO_SMALLICON; + break; + case TB_LARGE : + ID2Check = IDC_RADIO_BIGICON; + break; + case TB_STANDARD: + default : + ID2Check = IDC_RADIO_STANDARD; + } + ::SendDlgItemMessage(_hSelf, ID2Check, BM_SETCHECK, BST_CHECKED, 0); + + ::SendDlgItemMessage(_hSelf, IDC_CHECK_REDUCE, BM_SETCHECK, tabBarStatus & TAB_REDUCE, 0); + ::SendDlgItemMessage(_hSelf, IDC_CHECK_LOCK, BM_SETCHECK, !(tabBarStatus & TAB_DRAGNDROP), 0); + ::SendDlgItemMessage(_hSelf, IDC_CHECK_ORANGE, BM_SETCHECK, tabBarStatus & TAB_DRAWTOPBAR, 0); + ::SendDlgItemMessage(_hSelf, IDC_CHECK_DRAWINACTIVE, BM_SETCHECK, tabBarStatus & TAB_DRAWINACTIVETAB, 0); + ::SendDlgItemMessage(_hSelf, IDC_CHECK_ENABLETABCLOSE, BM_SETCHECK, tabBarStatus & TAB_CLOSEBUTTON, 0); + ::SendDlgItemMessage(_hSelf, IDC_CHECK_DBCLICK2CLOSE, BM_SETCHECK, tabBarStatus & TAB_DBCLK2CLOSE, 0); + ::SendDlgItemMessage(_hSelf, IDC_CHECK_TAB_VERTICAL, BM_SETCHECK, tabBarStatus & TAB_VERTICAL, 0); + ::SendDlgItemMessage(_hSelf, IDC_CHECK_TAB_MULTILINE, BM_SETCHECK, tabBarStatus & TAB_MULTILINE, 0); + + ::SendDlgItemMessage(_hSelf, IDC_CHECK_TAB_HIDE, BM_SETCHECK, tabBarStatus & TAB_HIDE, 0); + ::SendMessage(_hSelf, WM_COMMAND, IDC_CHECK_TAB_HIDE, 0); + ::SendDlgItemMessage(_hSelf, IDC_CHECK_SHOWSTATUSBAR, BM_SETCHECK, showStatus, 0); + ::SendDlgItemMessage(_hSelf, IDC_CHECK_HIDEMENUBAR, BM_SETCHECK, !showMenu, 0); + +#ifndef UNICODE + ::EnableWindow(::GetDlgItem(_hSelf, IDC_LOCALIZATION_GB_STATIC), FALSE); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_COMBO_LOCALIZATION), FALSE); +#else + LocalizationSwitcher & localizationSwitcher = pNppParam->getLocalizationSwitcher(); + + for (size_t i = 0 ; i < localizationSwitcher.size() ; i++) + { + pair localizationInfo = localizationSwitcher.getElementFromIndex(i); + ::SendDlgItemMessage(_hSelf, IDC_COMBO_LOCALIZATION, CB_ADDSTRING, 0, (LPARAM)localizationInfo.first.c_str()); + } +#endif + + ETDTProc enableDlgTheme = (ETDTProc)pNppParam->getEnableThemeDlgTexture(); + if (enableDlgTheme) + enableDlgTheme(_hSelf, ETDT_ENABLETAB); + + return TRUE; + } + + case WM_COMMAND : + { + switch (wParam) + { + case IDC_CHECK_SHOWSTATUSBAR : + { + bool isChecked = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_CHECK_SHOWSTATUSBAR, BM_GETCHECK, 0, 0)); + ::SendMessage(::GetParent(_hParent), NPPM_HIDESTATUSBAR, 0, isChecked?FALSE:TRUE); + } + return TRUE; + + case IDC_CHECK_HIDEMENUBAR : + { + bool isChecked = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_CHECK_HIDEMENUBAR, BM_GETCHECK, 0, 0)); + ::SendMessage(::GetParent(_hParent), NPPM_HIDEMENU, 0, isChecked?TRUE:FALSE); + } + return TRUE; + + case IDC_CHECK_TAB_HIDE : + { + bool toBeHidden = (BST_CHECKED == ::SendMessage(::GetDlgItem(_hSelf, IDC_CHECK_TAB_HIDE), BM_GETCHECK, 0, 0)); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_CHECK_TAB_MULTILINE), !toBeHidden); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_CHECK_TAB_VERTICAL), !toBeHidden); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_CHECK_REDUCE), !toBeHidden); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_CHECK_LOCK), !toBeHidden); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_CHECK_ORANGE), !toBeHidden); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_CHECK_DRAWINACTIVE), !toBeHidden); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_CHECK_ENABLETABCLOSE), !toBeHidden); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_CHECK_DBCLICK2CLOSE), !toBeHidden); + + ::SendMessage(::GetParent(_hParent), NPPM_HIDETABBAR, 0, toBeHidden); + return TRUE; + } + + case IDC_CHECK_TAB_VERTICAL: + ::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_DRAWTABBAR_VERTICAL, 0); + return TRUE; + + case IDC_CHECK_TAB_MULTILINE : + ::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_DRAWTABBAR_MULTILINE, 0); + return TRUE; + + + + case IDC_CHECK_REDUCE : + ::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_REDUCETABBAR, 0); + return TRUE; + + case IDC_CHECK_LOCK : + ::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_LOCKTABBAR, 0); + return TRUE; + + case IDC_CHECK_ORANGE : + ::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_DRAWTABBAR_TOPBAR, 0); + return TRUE; + + case IDC_CHECK_DRAWINACTIVE : + ::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_DRAWTABBAR_INACIVETAB, 0); + return TRUE; + + case IDC_CHECK_ENABLETABCLOSE : + ::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_DRAWTABBAR_CLOSEBOTTUN, 0); + return TRUE; + + case IDC_CHECK_DBCLICK2CLOSE : + ::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_DRAWTABBAR_DBCLK2CLOSE, 0); + return TRUE; + + case IDC_CHECK_HIDE : + { + bool isChecked = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_CHECK_HIDE, BM_GETCHECK, 0, 0)); + ::SendMessage(::GetParent(_hParent), NPPM_HIDETOOLBAR, 0, isChecked?TRUE:FALSE); + } + return TRUE; + + case IDC_RADIO_SMALLICON : + ::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_TOOLBAR_REDUCE, 0); + return TRUE; + + case IDC_RADIO_BIGICON : + ::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_TOOLBAR_ENLARGE, 0); + return TRUE; + + case IDC_RADIO_STANDARD : + ::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_TOOLBAR_STANDARD, 0); + return TRUE; + + default : + switch (HIWORD(wParam)) + { + case CBN_SELCHANGE : // == case LBN_SELCHANGE : + { + switch (LOWORD(wParam)) + { + case IDC_COMBO_LOCALIZATION : + { +#ifdef UNICODE + LocalizationSwitcher & localizationSwitcher = pNppParam->getLocalizationSwitcher(); + int index = ::SendDlgItemMessage(_hSelf, IDC_COMBO_LOCALIZATION, CB_GETCURSEL, 0, 0); + wchar_t langName[MAX_PATH]; + ::SendDlgItemMessage(_hSelf, IDC_COMBO_LOCALIZATION, CB_GETLBTEXT, index, (LPARAM)langName); + if (langName[0]) + { + + // Make English as basic language + if (localizationSwitcher.switchToLang(TEXT("English"))) + { + ::SendMessage(::GetParent(_hParent), NPPM_INTERNAL_RELOADNATIVELANG, 0, 0); + } + // Change the language + if (localizationSwitcher.switchToLang(langName)) + { + ::SendMessage(::GetParent(_hParent), NPPM_INTERNAL_RELOADNATIVELANG, 0, 0); + ::InvalidateRect(_hParent, NULL, TRUE); + } + //::SendMessage(::GetParent(_hParent), NPPM_INTERNAL_RELOADSTYLERS, 0, 0); + } +#endif + } + return TRUE; +/* + case IDC_COMBO_THEME : + { + LocalizationSwitcher & localizationSwitcher = pNppParam->getLocalizationSwitcher(); + int index = ::SendDlgItemMessage(_hSelf, IDC_COMBO_LOCALIZATION, CB_GETCURSEL, 0, 0); + TCHAR themeName[MAX_PATH]; + ::SendDlgItemMessage(_hSelf, IDC_COMBO_LOCALIZATION, CB_GETLBTEXT, index, (LPARAM)themeName); + if (langName[0]) + { + // Make English as basic language + if (localizationSwitcher.switchToLang(TEXT("English"))) + { + ::SendMessage(::GetParent(_hParent), NPPM_INTERNAL_RELOADNATIVELANG, 0, 0); + } + // Change the language + if (localizationSwitcher.switchToLang(langName)) + { + ::SendMessage(::GetParent(_hParent), NPPM_INTERNAL_RELOADNATIVELANG, 0, 0); + ::InvalidateRect(_hParent, NULL, TRUE); + } + } + } + return TRUE; + */ + default: + break; + } + } + } + } + } + } + return FALSE; +} + +void MarginsDlg::changePanelTo(int index) +{ + NppParameters *pNppParam = NppParameters::getInstance(); + const ScintillaViewParams & svp = pNppParam->getSVP(index?SCIV_SECOND:SCIV_PRIMARY); + + ::SendDlgItemMessage(_hSelf, IDC_RADIO_BOX, BM_SETCHECK, FALSE, 0); + ::SendDlgItemMessage(_hSelf, IDC_RADIO_CIRCLE, BM_SETCHECK, FALSE, 0); + ::SendDlgItemMessage(_hSelf, IDC_RADIO_ARROW, BM_SETCHECK, FALSE, 0); + ::SendDlgItemMessage(_hSelf, IDC_RADIO_SIMPLE, BM_SETCHECK, FALSE, 0); + + int id = 0; + switch (svp._folderStyle) + { + case FOLDER_STYLE_BOX: + id = IDC_RADIO_BOX; + break; + case FOLDER_STYLE_CIRCLE: + id = IDC_RADIO_CIRCLE; + break; + case FOLDER_STYLE_ARROW: + id = IDC_RADIO_ARROW; + break; + default : // FOLDER_STYLE_SIMPLE: + id = IDC_RADIO_SIMPLE; + } + ::SendDlgItemMessage(_hSelf, id, BM_SETCHECK, TRUE, 0); + + ::SendDlgItemMessage(_hSelf, IDC_CHECK_LINENUMBERMARGE, BM_SETCHECK, svp._lineNumberMarginShow, 0); + ::SendDlgItemMessage(_hSelf, IDC_CHECK_BOOKMARKMARGE, BM_SETCHECK, svp._bookMarkMarginShow, 0); + //::SendDlgItemMessage(_hSelf, IDC_CHECK_DOCCHANGESTATEMARGE, BM_SETCHECK, svp._docChangeStateMarginShow, 0); + ::SendDlgItemMessage(_hSelf, IDC_CHECK_CURRENTLINEHILITE, BM_SETCHECK, svp._currentLineHilitingShow, 0); + + bool isEnable = !(svp._edgeMode == EDGE_NONE); + ::SendDlgItemMessage(_hSelf, IDC_CHECK_SHOWVERTICALEDGE, BM_SETCHECK, isEnable, 0); + ::SendDlgItemMessage(_hSelf, IDC_RADIO_LNMODE, BM_SETCHECK, (svp._edgeMode == EDGE_LINE), 0); + ::SendDlgItemMessage(_hSelf, IDC_RADIO_BGMODE, BM_SETCHECK, (svp._edgeMode == EDGE_BACKGROUND), 0); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_RADIO_LNMODE), isEnable); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_RADIO_BGMODE), isEnable); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_NBCOLONE_STATIC), isEnable); + + TCHAR nbColStr[10]; + wsprintf(nbColStr, TEXT("%d"), svp._edgeNbColumn); + ::SetWindowText(::GetDlgItem(_hSelf, IDC_COLONENUMBER_STATIC), nbColStr); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_COLONENUMBER_STATIC), isEnable); + +} + +BOOL CALLBACK MarginsDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam) +{ + NppParameters *pNppParam = NppParameters::getInstance(); + NppGUI & nppGUI = (NppGUI &)pNppParam->getNppGUI(); + switch (Message) + { + case WM_INITDIALOG : + { + TCHAR nbStr[10]; + wsprintf(nbStr, TEXT("%d"), nppGUI._tabSize); + HWND hTabSize_val = ::GetDlgItem(_hSelf, IDC_TABSIZEVAL_STATIC); + ::SetWindowText(hTabSize_val, nbStr); + + _tabSizeVal.init(_hInst, _hSelf); + _tabSizeVal.create(hTabSize_val, IDM_SETTING_TAB_SIZE); + ::SendDlgItemMessage(_hSelf, IDC_CHECK_REPLACEBYSPACE, BM_SETCHECK, nppGUI._tabReplacedBySpace, 0); + + _verticalEdgeLineNbColVal.init(_hInst, _hSelf); + _verticalEdgeLineNbColVal.create(::GetDlgItem(_hSelf, IDC_COLONENUMBER_STATIC), IDM_SETTING_EDGE_SIZE); + + ::SendDlgItemMessage(_hSelf, IDC_WIDTH_COMBO, CB_ADDSTRING, 0, (LPARAM)TEXT("0")); + ::SendDlgItemMessage(_hSelf, IDC_WIDTH_COMBO, CB_ADDSTRING, 0, (LPARAM)TEXT("1")); + ::SendDlgItemMessage(_hSelf, IDC_WIDTH_COMBO, CB_ADDSTRING, 0, (LPARAM)TEXT("2")); + ::SendDlgItemMessage(_hSelf, IDC_WIDTH_COMBO, CB_ADDSTRING, 0, (LPARAM)TEXT("3")); + ::SendDlgItemMessage(_hSelf, IDC_WIDTH_COMBO, CB_ADDSTRING, 0, (LPARAM)TEXT("Block")); + + + ::SendMessage(::GetDlgItem(_hSelf, IDC_WIDTH_COMBO), CB_SETCURSEL, nppGUI._caretWidth, 0); + + ::SendMessage(::GetDlgItem(_hSelf, IDC_CARETBLINKRATE_SLIDER),TBM_SETRANGEMIN, TRUE, BLINKRATE_FASTEST); + ::SendMessage(::GetDlgItem(_hSelf, IDC_CARETBLINKRATE_SLIDER),TBM_SETRANGEMAX, TRUE, BLINKRATE_SLOWEST); + ::SendMessage(::GetDlgItem(_hSelf, IDC_CARETBLINKRATE_SLIDER),TBM_SETPAGESIZE, 0, BLINKRATE_INTERVAL); + int blinkRate = (nppGUI._caretBlinkRate==0)?BLINKRATE_SLOWEST:nppGUI._caretBlinkRate; + ::SendMessage(::GetDlgItem(_hSelf, IDC_CARETBLINKRATE_SLIDER),TBM_SETPOS, TRUE, blinkRate); + + ::SendDlgItemMessage(_hSelf, IDC_COMBO_SCINTILLAVIEWCHOIX, CB_ADDSTRING, 0, (LPARAM)TEXT("Primary View")); + ::SendDlgItemMessage(_hSelf, IDC_COMBO_SCINTILLAVIEWCHOIX, CB_ADDSTRING, 0, (LPARAM)TEXT("Second View")); + ::SendDlgItemMessage(_hSelf, IDC_COMBO_SCINTILLAVIEWCHOIX, CB_SETCURSEL, 0, 0); + + changePanelTo(SCIV_PRIMARY); + + ETDTProc enableDlgTheme = (ETDTProc)pNppParam->getEnableThemeDlgTexture(); + if (enableDlgTheme) + enableDlgTheme(_hSelf, ETDT_ENABLETAB); + return TRUE; + } + + case WM_HSCROLL: + { + //case IDC_CARETBLINKRATE_SLIDER: + NppGUI & nppGUI = (NppGUI &)NppParameters::getInstance()->getNppGUI(); + //nppGUI._caretBlinkRate = ::SendMessage(::GetDlgItem(_hSelf, IDC_CARETBLINKRATE_SLIDER),TBM_GETPOS, 0, 0); + int blinkRate = (int)::SendMessage(::GetDlgItem(_hSelf, IDC_CARETBLINKRATE_SLIDER),TBM_GETPOS, 0, 0); + if (blinkRate == BLINKRATE_SLOWEST) + blinkRate = 0; + nppGUI._caretBlinkRate = blinkRate; + + ::SendMessage(::GetParent(_hParent), NPPM_INTERNAL_SETCARETBLINKRATE, 0, 0); + return 0; //return zero when handled + + } + + case WM_COMMAND : + { + int i = ::SendDlgItemMessage(_hSelf, IDC_COMBO_SCINTILLAVIEWCHOIX, CB_GETCURSEL, 0, 0); + ScintillaViewParams & svp = (ScintillaViewParams &)pNppParam->getSVP(i?SCIV_SECOND:SCIV_PRIMARY); + int iView = i + 1; + switch (wParam) + { + case IDM_SETTING_TAB_SIZE: + { + ::SendMessage(_hParent, WM_COMMAND, IDM_SETTING_TAB_SIZE, 0); + TCHAR nbStr[10]; + wsprintf(nbStr, TEXT("%d"), nppGUI._tabSize); + ::SetWindowText(::GetDlgItem(_hSelf, IDC_TABSIZEVAL_STATIC), nbStr); + return TRUE; + } + + case IDC_CHECK_REPLACEBYSPACE: + ::SendMessage(_hParent, WM_COMMAND, IDM_SETTING_TAB_REPLCESPACE, 0); + return TRUE; + + case IDC_CHECK_LINENUMBERMARGE: + svp._lineNumberMarginShow = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_CHECK_LINENUMBERMARGE, BM_GETCHECK, 0, 0)); + ::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_LINENUMBER, iView); + return TRUE; + + case IDC_CHECK_BOOKMARKMARGE: + svp._bookMarkMarginShow = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_CHECK_BOOKMARKMARGE, BM_GETCHECK, 0, 0)); + ::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_SYMBOLMARGIN, iView); + return TRUE; +/* + case IDC_CHECK_DOCCHANGESTATEMARGE: + svp._docChangeStateMarginShow = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_CHECK_DOCCHANGESTATEMARGE, BM_GETCHECK, 0, 0)); + ::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_DOCCHANGEMARGIN, iView); + return TRUE; +*/ + case IDC_CHECK_CURRENTLINEHILITE: + svp._currentLineHilitingShow = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_CHECK_CURRENTLINEHILITE, BM_GETCHECK, 0, 0)); + ::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_CURLINE_HILITING, iView); + return TRUE; + + + case IDC_RADIO_SIMPLE: + svp._folderStyle = FOLDER_STYLE_SIMPLE; + ::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_FOLDERMAGIN_SIMPLE, iView); + return TRUE; + case IDC_RADIO_ARROW: + svp._folderStyle = FOLDER_STYLE_ARROW; + ::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_FOLDERMAGIN_ARROW, iView); + return TRUE; + case IDC_RADIO_CIRCLE: + svp._folderStyle = FOLDER_STYLE_CIRCLE; + ::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_FOLDERMAGIN_CIRCLE, iView); + return TRUE; + case IDC_RADIO_BOX: + svp._folderStyle = FOLDER_STYLE_BOX; + ::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_FOLDERMAGIN_BOX, iView); + return TRUE; + + + case IDC_CHECK_SHOWVERTICALEDGE: + { + int modeID = 0; + bool isChecked = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_CHECK_SHOWVERTICALEDGE, BM_GETCHECK, 0, 0)); + if (isChecked) + { + ::SendDlgItemMessage(_hSelf, IDC_RADIO_LNMODE, BM_SETCHECK, TRUE, 0); + svp._edgeMode = EDGE_LINE; + modeID = IDM_VIEW_EDGELINE; + } + else + { + ::SendDlgItemMessage(_hSelf, IDC_RADIO_LNMODE, BM_SETCHECK, FALSE, 0); + ::SendDlgItemMessage(_hSelf, IDC_RADIO_BGMODE, BM_SETCHECK, FALSE, 0); + svp._edgeMode = EDGE_NONE; + modeID = IDM_VIEW_EDGENONE; + } + ::EnableWindow(::GetDlgItem(_hSelf, IDC_RADIO_LNMODE), isChecked); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_RADIO_BGMODE), isChecked); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_NBCOLONE_STATIC), isChecked); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_COLONENUMBER_STATIC), isChecked); + + ::SendMessage(_hParent, WM_COMMAND, modeID, iView); + return TRUE; + } + case IDC_RADIO_LNMODE: + svp._edgeMode = EDGE_LINE; + ::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_EDGELINE, iView); + return TRUE; + + case IDC_RADIO_BGMODE: + svp._edgeMode = EDGE_BACKGROUND; + ::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_EDGEBACKGROUND, iView); + return TRUE; + + case IDM_SETTING_EDGE_SIZE: + { + ::SendMessage(_hParent, WM_COMMAND, IDM_SETTING_EDGE_SIZE, iView); + TCHAR nbColStr[10]; + wsprintf(nbColStr, TEXT("%d"), svp._edgeNbColumn); + ::SetWindowText(::GetDlgItem(_hSelf, IDC_COLONENUMBER_STATIC), nbColStr); + return TRUE; + } + + default : + switch (HIWORD(wParam)) + { + case CBN_SELCHANGE : // == case LBN_SELCHANGE : + { + switch (LOWORD(wParam)) + { + case IDC_COMBO_SCINTILLAVIEWCHOIX : + { + changePanelTo(i); + return TRUE; + } + case IDC_WIDTH_COMBO: + { + nppGUI._caretWidth = ::SendDlgItemMessage(_hSelf, IDC_WIDTH_COMBO, CB_GETCURSEL, 0, 0); + ::SendMessage(::GetParent(_hParent), NPPM_INTERNAL_SETCARETWIDTH, 0, 0); + return TRUE; + } + default: + break; + } + } + } + } + } + } + return FALSE; +} + +BOOL CALLBACK SettingsDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam) +{ + NppParameters *pNppParam = NppParameters::getInstance(); + NppGUI & nppGUI = (NppGUI &)pNppParam->getNppGUI(); + switch (Message) + { + case WM_INITDIALOG : + { + TCHAR nbStr[10]; + wsprintf(nbStr, TEXT("%d"), pNppParam->getNbMaxFile()); + ::SetWindowText(::GetDlgItem(_hSelf, IDC_MAXNBFILEVAL_STATIC), nbStr); + + _nbHistoryVal.init(_hInst, _hSelf); + _nbHistoryVal.create(::GetDlgItem(_hSelf, IDC_MAXNBFILEVAL_STATIC), IDM_SETTING_HISTORY_SIZE); + + ::SendDlgItemMessage(_hSelf, IDC_CHECK_DONTCHECKHISTORY, BM_SETCHECK, !nppGUI._checkHistoryFiles, 0); + + if (nppGUI._fileAutoDetection == cdEnabled) + { + ::SendDlgItemMessage(_hSelf, IDC_CHECK_FILEAUTODETECTION, BM_SETCHECK, BST_CHECKED, 0); + } + else if (nppGUI._fileAutoDetection == cdAutoUpdate) + { + ::SendDlgItemMessage(_hSelf, IDC_CHECK_FILEAUTODETECTION, BM_SETCHECK, BST_CHECKED, 0); + ::SendDlgItemMessage(_hSelf, IDC_CHECK_UPDATESILENTLY, BM_SETCHECK, BST_CHECKED, 0); + } + else if (nppGUI._fileAutoDetection == cdGo2end) + { + ::SendDlgItemMessage(_hSelf, IDC_CHECK_FILEAUTODETECTION, BM_SETCHECK, BST_CHECKED, 0); + ::SendDlgItemMessage(_hSelf, IDC_CHECK_UPDATEGOTOEOF, BM_SETCHECK, BST_CHECKED, 0); + } + else if (nppGUI._fileAutoDetection == cdAutoUpdateGo2end) + { + ::SendDlgItemMessage(_hSelf, IDC_CHECK_FILEAUTODETECTION, BM_SETCHECK, BST_CHECKED, 0); + ::SendDlgItemMessage(_hSelf, IDC_CHECK_UPDATESILENTLY, BM_SETCHECK, BST_CHECKED, 0); + ::SendDlgItemMessage(_hSelf, IDC_CHECK_UPDATEGOTOEOF, BM_SETCHECK, BST_CHECKED, 0); + } + else //cdDisabled + { + ::EnableWindow(::GetDlgItem(_hSelf, IDC_CHECK_UPDATESILENTLY), FALSE); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_CHECK_UPDATEGOTOEOF), FALSE); + } + + ::SendDlgItemMessage(_hSelf, IDC_CHECK_MIN2SYSTRAY, BM_SETCHECK, nppGUI._isMinimizedToTray, 0); + ::SendDlgItemMessage(_hSelf, IDC_CHECK_REMEMBERSESSION, BM_SETCHECK, nppGUI._rememberLastSession, 0); + ::SendDlgItemMessage(_hSelf, IDC_CHECK_AUTOUPDATE, BM_SETCHECK, !nppGUI._neverUpdate, 0); + + ::ShowWindow(::GetDlgItem(_hSelf, IDC_CHECK_AUTOUPDATE), nppGUI._doesExistUpdater?SW_SHOW:SW_HIDE); + + BOOL linkEnable = FALSE; + BOOL dontUnderline = FALSE; + BOOL dontUnderlineState = FALSE; + if (nppGUI._styleURL == 1) + { + linkEnable = TRUE; + dontUnderline = TRUE; + dontUnderlineState = TRUE; + + } + else if (nppGUI._styleURL == 2) + { + linkEnable = TRUE; + dontUnderline = FALSE; + dontUnderlineState = TRUE; + } + + ::SendDlgItemMessage(_hSelf, IDC_CHECK_CLICKABLELINK_ENABLE, BM_SETCHECK, linkEnable, 0); + ::SendDlgItemMessage(_hSelf, IDC_CHECK_CLICKABLELINK_NOUNDERLINE, BM_SETCHECK, dontUnderline, 0); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_CHECK_CLICKABLELINK_NOUNDERLINE), dontUnderlineState); + + ::SendDlgItemMessage(_hSelf, IDC_EDIT_SESSIONFILEEXT, WM_SETTEXT, 0, (LPARAM)nppGUI._definedSessionExt.c_str()); + + ::SendDlgItemMessage(_hSelf, IDC_CHECK_ENABLEDOCSWITCHER, BM_SETCHECK, nppGUI._doTaskList, 0); + ::SendDlgItemMessage(_hSelf, IDC_CHECK_MAINTAININDENT, BM_SETCHECK, nppGUI._maitainIndent, 0); + ::SendDlgItemMessage(_hSelf, IDC_CHECK_STYLEMRU, BM_SETCHECK, nppGUI._styleMRU, 0); + ::SendDlgItemMessage(_hSelf, IDC_CHECK_ENABLSMARTHILITE, BM_SETCHECK, nppGUI._enableSmartHilite, 0); + ::SendDlgItemMessage(_hSelf, IDC_CHECK_ENABLTAGSMATCHHILITE, BM_SETCHECK, nppGUI._enableTagsMatchHilite, 0); + ::SendDlgItemMessage(_hSelf, IDC_CHECK_ENABLTAGATTRHILITE, BM_SETCHECK, nppGUI._enableTagAttrsHilite, 0); + ::SendDlgItemMessage(_hSelf, IDC_CHECK_HIGHLITENONEHTMLZONE, BM_SETCHECK, nppGUI._enableHiliteNonHTMLZone, 0); + + ::EnableWindow(::GetDlgItem(_hSelf, IDC_CHECK_ENABLTAGATTRHILITE), nppGUI._enableTagsMatchHilite); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_CHECK_HIGHLITENONEHTMLZONE), nppGUI._enableTagsMatchHilite); + + ::SendDlgItemMessage(_hSelf, IDC_CHECK_SHORTTITLE, BM_SETCHECK, nppGUI._shortTitlebar, 0); + + ETDTProc enableDlgTheme = (ETDTProc)pNppParam->getEnableThemeDlgTexture(); + if (enableDlgTheme) + enableDlgTheme(_hSelf, ETDT_ENABLETAB); + + return TRUE; + } + + case WM_COMMAND : + { + if (HIWORD(wParam) == EN_CHANGE) + { + switch (LOWORD(wParam)) + { + case IDC_EDIT_SESSIONFILEEXT: + { + TCHAR sessionExt[MAX_PATH]; + ::SendDlgItemMessage(_hSelf, IDC_EDIT_SESSIONFILEEXT, WM_GETTEXT, MAX_PATH, (LPARAM)sessionExt); + nppGUI._definedSessionExt = sessionExt; + return TRUE; + } + } + } + + switch (wParam) + { + case IDC_CHECK_DONTCHECKHISTORY: + nppGUI._checkHistoryFiles = !isCheckedOrNot(IDC_CHECK_DONTCHECKHISTORY); + return TRUE; + + case IDC_CHECK_FILEAUTODETECTION: + { + bool isChecked = isCheckedOrNot(IDC_CHECK_FILEAUTODETECTION); + if (!isChecked) + { + ::SendDlgItemMessage(_hSelf, IDC_CHECK_UPDATESILENTLY, BM_SETCHECK, BST_UNCHECKED, 0); + ::SendDlgItemMessage(_hSelf, IDC_CHECK_UPDATEGOTOEOF, BM_SETCHECK, BST_UNCHECKED, 0); + } + ::EnableWindow(::GetDlgItem(_hSelf, IDC_CHECK_UPDATESILENTLY), isChecked); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_CHECK_UPDATEGOTOEOF), isChecked); + + nppGUI._fileAutoDetection = isChecked?cdAutoUpdate:cdDisabled; + } + return TRUE; + + case IDC_CHECK_UPDATESILENTLY: + case IDC_CHECK_UPDATEGOTOEOF: + { + bool isSilent = isCheckedOrNot(IDC_CHECK_UPDATESILENTLY); + bool isGo2End = isCheckedOrNot(IDC_CHECK_UPDATEGOTOEOF); + + ChangeDetect cd; + + if (!isSilent && !isGo2End) + cd = cdEnabled; + else if (!isSilent && isGo2End) + cd = cdGo2end; + else if (isSilent && !isGo2End) + cd = cdAutoUpdate; + else //(isSilent && isGo2End) + cd = cdAutoUpdateGo2end; + + nppGUI._fileAutoDetection = cd; + } + return TRUE; + + case IDC_CHECK_CLICKABLELINK_ENABLE: + { + bool isChecked = isCheckedOrNot(IDC_CHECK_CLICKABLELINK_ENABLE); + if (!isChecked) + ::SendDlgItemMessage(_hSelf, IDC_CHECK_CLICKABLELINK_NOUNDERLINE, BM_SETCHECK, BST_UNCHECKED, 0); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_CHECK_CLICKABLELINK_NOUNDERLINE), isChecked); + + nppGUI._styleURL = isChecked?2:0; + } + return TRUE; + + case IDC_CHECK_CLICKABLELINK_NOUNDERLINE: + { + bool isChecked = isCheckedOrNot(IDC_CHECK_CLICKABLELINK_NOUNDERLINE); + nppGUI._styleURL = isChecked?1:2; + } + return TRUE; + + case IDC_CHECK_AUTOUPDATE: + nppGUI._neverUpdate = !isCheckedOrNot(wParam); + return TRUE; + + case IDC_CHECK_MIN2SYSTRAY: + nppGUI._isMinimizedToTray = isCheckedOrNot(wParam); + return TRUE; + + case IDC_CHECK_REMEMBERSESSION: + //::SendMessage(_hParent, WM_COMMAND, IDM_SETTING_REMEMBER_LAST_SESSION, 0); + nppGUI._rememberLastSession = isCheckedOrNot(wParam); + return TRUE; + + case IDM_SETTING_HISTORY_SIZE: + { + ::SendMessage(_hParent, WM_COMMAND, IDM_SETTING_HISTORY_SIZE, 0); + TCHAR nbStr[10]; + wsprintf(nbStr, TEXT("%d"), pNppParam->getNbMaxFile()); + ::SetWindowText(::GetDlgItem(_hSelf, IDC_MAXNBFILEVAL_STATIC), nbStr); + return TRUE; + } + + case IDC_CHECK_ENABLEDOCSWITCHER : + { + nppGUI._doTaskList = !nppGUI._doTaskList; + if (nppGUI._doTaskList) + { + ::EnableWindow(::GetDlgItem(_hSelf, IDC_CHECK_STYLEMRU), TRUE); + } + else + { + nppGUI._styleMRU = false; + ::SendDlgItemMessage(_hSelf, IDC_CHECK_STYLEMRU, BM_SETCHECK, false, 0); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_CHECK_STYLEMRU), FALSE); + } + return TRUE; + } + + case IDC_CHECK_MAINTAININDENT : + { + nppGUI._maitainIndent = !nppGUI._maitainIndent; + return TRUE; + } + + case IDC_CHECK_ENABLSMARTHILITE : + { + nppGUI._enableSmartHilite = !nppGUI._enableSmartHilite; + if (!nppGUI._enableSmartHilite) + { + HWND grandParent = ::GetParent(_hParent); + ::SendMessage(grandParent, NPPM_INTERNAL_CLEARINDICATOR, 0, 0); + } + return TRUE; + } + case IDC_CHECK_ENABLTAGSMATCHHILITE: + { + nppGUI._enableTagsMatchHilite = !nppGUI._enableTagsMatchHilite; + if (!nppGUI._enableTagsMatchHilite) + { + HWND grandParent = ::GetParent(_hParent); + ::SendMessage(grandParent, NPPM_INTERNAL_CLEARINDICATORTAGMATCH, 0, 0); + } + ::EnableWindow(::GetDlgItem(_hSelf, IDC_CHECK_ENABLTAGATTRHILITE), nppGUI._enableTagsMatchHilite); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_CHECK_HIGHLITENONEHTMLZONE), nppGUI._enableTagsMatchHilite); + return TRUE; + } + case IDC_CHECK_ENABLTAGATTRHILITE: + { + nppGUI._enableTagAttrsHilite = !nppGUI._enableTagAttrsHilite; + if (!nppGUI._enableTagAttrsHilite) + { + HWND grandParent = ::GetParent(_hParent); + ::SendMessage(grandParent, NPPM_INTERNAL_CLEARINDICATORTAGATTR, 0, 0); + } + return TRUE; + } + + case IDC_CHECK_HIGHLITENONEHTMLZONE: + { + nppGUI._enableHiliteNonHTMLZone = !nppGUI._enableHiliteNonHTMLZone; + return TRUE; + } + + case IDC_CHECK_STYLEMRU : + { + nppGUI._styleMRU = !nppGUI._styleMRU; + return TRUE; + } + + case IDC_CHECK_SHORTTITLE: + { + nppGUI._shortTitlebar = !nppGUI._shortTitlebar; + HWND grandParent = ::GetParent(_hParent); + ::SendMessage(grandParent, NPPM_INTERNAL_UPDATETITLEBAR, 0, 0); + return TRUE; + } + } + } + } + return FALSE; +} + +BOOL CALLBACK DefaultNewDocDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam) +{ + NppParameters *pNppParam = NppParameters::getInstance(); + NppGUI & nppGUI = (NppGUI & )pNppParam->getNppGUI(); + NewDocDefaultSettings & ndds = (NewDocDefaultSettings &)nppGUI.getNewDocDefaultSettings(); + + switch (Message) + { + case WM_INITDIALOG : + { + int ID2Check = 0; + + switch (ndds._format) + { + case MAC_FORMAT : + ID2Check = IDC_RADIO_F_MAC; + break; + case UNIX_FORMAT : + ID2Check = IDC_RADIO_F_UNIX; + break; + + default : //WIN_FORMAT + ID2Check = IDC_RADIO_F_WIN; + } + ::SendDlgItemMessage(_hSelf, ID2Check, BM_SETCHECK, BST_CHECKED, 0); + + switch (ndds._encoding) + { + case uni16BE : + ID2Check = IDC_RADIO_UCS2BIG; + break; + case uni16LE : + ID2Check = IDC_RADIO_UCS2SMALL; + break; + case uniUTF8 : + ID2Check = IDC_RADIO_UTF8; + break; + case uniCookie : + ID2Check = IDC_RADIO_UTF8SANSBOM; + break; + + default : //uni8Bit + ID2Check = IDC_RADIO_ANSI; + } + ::SendDlgItemMessage(_hSelf, ID2Check, BM_SETCHECK, BST_CHECKED, 0); + ::SendDlgItemMessage(_hSelf, IDC_CHECK_OPENANSIASUTF8, BM_SETCHECK, (ID2Check == IDC_RADIO_UTF8SANSBOM && ndds._openAnsiAsUtf8)?BST_CHECKED:BST_UNCHECKED, 0); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_CHECK_OPENANSIASUTF8), ID2Check == IDC_RADIO_UTF8SANSBOM); + int index = 0; + for (int i = L_TXT ; i < pNppParam->L_END ; i++) + { + generic_string str; + if ((LangType)i != L_USER) + { + int cmdID = pNppParam->langTypeToCommandID((LangType)i); + if ((cmdID != -1)) + { + getNameStrFromCmd(cmdID, str); + if (str.length() > 0) + { + _langList.push_back(LangID_Name((LangType)i, str)); + ::SendDlgItemMessage(_hSelf, IDC_COMBO_DEFAULTLANG, CB_ADDSTRING, 0, (LPARAM)str.c_str()); + if (ndds._lang == i) + index = _langList.size() - 1; + } + } + } + } + ::SendDlgItemMessage(_hSelf, IDC_COMBO_DEFAULTLANG, CB_SETCURSEL, index, 0); + + bool shouldActivated; + switch (nppGUI._openSaveDir) + { + case dir_last : + ID2Check = IDC_OPENSAVEDIR_REMEMBERLAST_RADIO; + shouldActivated = false; + break; + case dir_userDef : + ID2Check = IDC_OPENSAVEDIR_ALWAYSON_RADIO; + shouldActivated = true; + break; + + default : + ID2Check = IDC_OPENSAVEDIR_FOLLOWCURRENT_RADIO; + shouldActivated = false; + } + ::SendDlgItemMessage(_hSelf, ID2Check, BM_SETCHECK, BST_CHECKED, 0); + ::SendDlgItemMessage(_hSelf, IDC_OPENSAVEDIR_ALWAYSON_EDIT, WM_SETTEXT, 0, (LPARAM)nppGUI._defaultDir); + //::ExpandEnvironmentStrings(nppGUI._defaultDir, nppGUI._defaultDirExp, 500); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_OPENSAVEDIR_ALWAYSON_EDIT), shouldActivated); + ::EnableWindow(::GetDlgItem(_hSelf, IDD_OPENSAVEDIR_ALWAYSON_BROWSE_BUTTON), shouldActivated); + + ETDTProc enableDlgTheme = (ETDTProc)pNppParam->getEnableThemeDlgTexture(); + if (enableDlgTheme) + enableDlgTheme(_hSelf, ETDT_ENABLETAB); + } + + case WM_COMMAND : + { + if (HIWORD(wParam) == EN_CHANGE) + { + switch (LOWORD(wParam)) + { + case IDC_OPENSAVEDIR_ALWAYSON_EDIT: + { + TCHAR inputDir[MAX_PATH]; + ::SendDlgItemMessage(_hSelf, IDC_OPENSAVEDIR_ALWAYSON_EDIT, WM_GETTEXT, MAX_PATH, (LPARAM)inputDir); + lstrcpy(nppGUI._defaultDir, inputDir); + ::ExpandEnvironmentStrings(nppGUI._defaultDir, nppGUI._defaultDirExp, 500); + pNppParam->setWorkingDir(nppGUI._defaultDirExp); + return TRUE; + } + } + } + + switch (wParam) + { + case IDC_RADIO_UCS2BIG: + ndds._encoding = uni16BE; + ndds._openAnsiAsUtf8 = false; + makeOpenAnsiAsUtf8(false); + return TRUE; + case IDC_RADIO_UCS2SMALL: + ndds._encoding = uni16LE; + ndds._openAnsiAsUtf8 = false; + makeOpenAnsiAsUtf8(false); + return TRUE; + case IDC_RADIO_UTF8: + ndds._encoding = uniUTF8; + ndds._openAnsiAsUtf8 = false; + makeOpenAnsiAsUtf8(false); + return TRUE; + case IDC_RADIO_UTF8SANSBOM: + ndds._encoding = uniCookie; + makeOpenAnsiAsUtf8(true); + return TRUE; + case IDC_RADIO_ANSI: + ndds._encoding = uni8Bit; + ndds._openAnsiAsUtf8 = false; + makeOpenAnsiAsUtf8(false); + return TRUE; + + case IDC_CHECK_OPENANSIASUTF8 : + ndds._openAnsiAsUtf8 = (BST_CHECKED == ::SendMessage(::GetDlgItem(_hSelf, IDC_CHECK_OPENANSIASUTF8), BM_GETCHECK, 0, 0)); + return TRUE; + + + case IDC_RADIO_F_MAC: + ndds._format = MAC_FORMAT; + return TRUE; + case IDC_RADIO_F_UNIX: + ndds._format = UNIX_FORMAT; + return TRUE; + case IDC_RADIO_F_WIN: + ndds._format = WIN_FORMAT; + return TRUE; + + + + + case IDC_OPENSAVEDIR_FOLLOWCURRENT_RADIO: + nppGUI._openSaveDir = dir_followCurrent; + ::EnableWindow(::GetDlgItem(_hSelf, IDC_OPENSAVEDIR_ALWAYSON_EDIT), false); + ::EnableWindow(::GetDlgItem(_hSelf, IDD_OPENSAVEDIR_ALWAYSON_BROWSE_BUTTON), false); + return TRUE; + case IDC_OPENSAVEDIR_REMEMBERLAST_RADIO: + nppGUI._openSaveDir = dir_last; + ::EnableWindow(::GetDlgItem(_hSelf, IDC_OPENSAVEDIR_ALWAYSON_EDIT), false); + ::EnableWindow(::GetDlgItem(_hSelf, IDD_OPENSAVEDIR_ALWAYSON_BROWSE_BUTTON), false); + return TRUE; + case IDC_OPENSAVEDIR_ALWAYSON_RADIO: + nppGUI._openSaveDir = dir_userDef; + ::EnableWindow(::GetDlgItem(_hSelf, IDC_OPENSAVEDIR_ALWAYSON_EDIT), true); + ::EnableWindow(::GetDlgItem(_hSelf, IDD_OPENSAVEDIR_ALWAYSON_BROWSE_BUTTON), true); + return TRUE; + + case IDD_OPENSAVEDIR_ALWAYSON_BROWSE_BUTTON : + folderBrowser(_hSelf, IDC_OPENSAVEDIR_ALWAYSON_EDIT); + return TRUE; + + default: + if ((HIWORD(wParam) == CBN_SELCHANGE) && (LOWORD(wParam) == IDC_COMBO_DEFAULTLANG)) + { + int index = ::SendDlgItemMessage(_hSelf, IDC_COMBO_DEFAULTLANG, CB_GETCURSEL, 0, 0); + ndds._lang = _langList[index]._id; + return TRUE; + } + return FALSE; + } + } + } + return FALSE; +} + +BOOL CALLBACK LangMenuDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam) +{ + NppParameters *pNppParam = NppParameters::getInstance(); + NppGUI & nppGUI = (NppGUI & )pNppParam->getNppGUI(); + + switch (Message) + { + case WM_INITDIALOG : + { + for (int i = L_TXT ; i < pNppParam->L_END ; i++) + { + generic_string str; + if ((LangType)i != L_USER) + { + int cmdID = pNppParam->langTypeToCommandID((LangType)i); + if ((cmdID != -1)) + { + getNameStrFromCmd(cmdID, str); + if (str.length() > 0) + { + _langList.push_back(LangMenuItem((LangType)i, cmdID, str)); + ::SendDlgItemMessage(_hSelf, IDC_LIST_ENABLEDLANG, LB_ADDSTRING, 0, (LPARAM)str.c_str()); + } + } + } + } + + for (size_t i = 0 ; i < nppGUI._excludedLangList.size() ; i++) + { + ::SendDlgItemMessage(_hSelf, IDC_LIST_DISABLEDLANG, LB_ADDSTRING, 0, (LPARAM)nppGUI._excludedLangList[i]._langName.c_str()); + } + + ::SendDlgItemMessage(_hSelf, IDC_CHECK_LANGMENUCOMPACT, BM_SETCHECK, nppGUI._isLangMenuCompact?BST_CHECKED:BST_UNCHECKED, 0); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_BUTTON_REMOVE), FALSE); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_BUTTON_RESTORE), FALSE); + + ETDTProc enableDlgTheme = (ETDTProc)pNppParam->getEnableThemeDlgTexture(); + if (enableDlgTheme) + enableDlgTheme(_hSelf, ETDT_ENABLETAB); + + return TRUE; + } + case WM_COMMAND : + { + switch (LOWORD(wParam)) + { + case IDC_LIST_DISABLEDLANG : + case IDC_LIST_ENABLEDLANG : + { + HWND hEnableList = ::GetDlgItem(_hSelf, IDC_LIST_ENABLEDLANG); + HWND hDisableList = ::GetDlgItem(_hSelf, IDC_LIST_DISABLEDLANG); + if (HIWORD(wParam) == LBN_DBLCLK) + { + if (HWND(lParam) == hEnableList) + ::SendMessage(_hSelf, WM_COMMAND, IDC_BUTTON_REMOVE, 0); + else if (HWND(lParam) == hDisableList) + ::SendMessage(_hSelf, WM_COMMAND, IDC_BUTTON_RESTORE, 0); + return TRUE; + } + int idButton2Enable; + int idButton2Disable; + + if (LOWORD(wParam) == IDC_LIST_ENABLEDLANG) + { + idButton2Enable = IDC_BUTTON_REMOVE; + idButton2Disable = IDC_BUTTON_RESTORE; + } + else //IDC_LIST_DISABLEDLANG + { + idButton2Enable = IDC_BUTTON_RESTORE; + idButton2Disable = IDC_BUTTON_REMOVE; + } + + int i = ::SendDlgItemMessage(_hSelf, LOWORD(wParam), LB_GETCURSEL, 0, 0); + if (i != LB_ERR) + { + ::EnableWindow(::GetDlgItem(_hSelf, idButton2Enable), TRUE); + int idListbox2Disable = (LOWORD(wParam)== IDC_LIST_ENABLEDLANG)?IDC_LIST_DISABLEDLANG:IDC_LIST_ENABLEDLANG; + ::SendDlgItemMessage(_hSelf, idListbox2Disable, LB_SETCURSEL, (WPARAM)-1, 0); + ::EnableWindow(::GetDlgItem(_hSelf, idButton2Disable), FALSE); + } + return TRUE; + } + + case IDC_CHECK_LANGMENUCOMPACT : + { + nppGUI._isLangMenuCompact = (BST_CHECKED == ::SendMessage(::GetDlgItem(_hSelf, IDC_CHECK_LANGMENUCOMPACT), BM_GETCHECK, 0, 0)); + ::MessageBox(_hSelf, + nppGUI._isLangMenuCompact?TEXT("This option will be enable on the next launch."):TEXT("This option will be disable on the next launch."), + TEXT("Compact Language Menu"), MB_OK); + return TRUE; + } + + case IDC_BUTTON_RESTORE : + case IDC_BUTTON_REMOVE : + { + int list2Remove, list2Add, idButton2Enable, idButton2Disable; + vector *pSrcLst, *pDestLst; + + if (LOWORD(wParam)==IDC_BUTTON_REMOVE) + { + list2Remove = IDC_LIST_ENABLEDLANG; + list2Add = IDC_LIST_DISABLEDLANG; + idButton2Enable = IDC_BUTTON_RESTORE; + idButton2Disable = IDC_BUTTON_REMOVE; + pSrcLst = &_langList; + pDestLst = &nppGUI._excludedLangList; + } + else + { + list2Remove = IDC_LIST_DISABLEDLANG; + list2Add = IDC_LIST_ENABLEDLANG; + idButton2Enable = IDC_BUTTON_REMOVE; + idButton2Disable = IDC_BUTTON_RESTORE; + pSrcLst = &nppGUI._excludedLangList; + pDestLst = &_langList; + } + size_t iRemove = ::SendDlgItemMessage(_hSelf, list2Remove, LB_GETCURSEL, 0, 0); + if (iRemove == -1) + return TRUE; + + TCHAR s[32]; + ::SendDlgItemMessage(_hSelf, list2Remove, LB_GETTEXT, iRemove, (LPARAM)s); + + LangMenuItem lmi = pSrcLst->at(iRemove); + vector::iterator lang2Remove = pSrcLst->begin() + iRemove; + pSrcLst->erase(lang2Remove); + + int iAdd = ::SendDlgItemMessage(_hSelf, list2Add, LB_ADDSTRING, 0, (LPARAM)s); + ::SendDlgItemMessage(_hSelf, list2Remove, LB_DELETESTRING, iRemove, 0); + pDestLst->push_back(lmi); + + ::SendDlgItemMessage(_hSelf, list2Add, LB_SETCURSEL, iAdd, 0); + ::SendDlgItemMessage(_hSelf, list2Remove, LB_SETCURSEL, -1, 0); + ::EnableWindow(::GetDlgItem(_hSelf, idButton2Enable), TRUE); + ::EnableWindow(::GetDlgItem(_hSelf, idButton2Disable), FALSE); + + if ((lmi._langType >= L_EXTERNAL) && (lmi._langType < pNppParam->L_END)) + { + bool found(false); + for(size_t x = 0; x < pNppParam->getExternalLexerDoc()->size() && !found; x++) + { + TiXmlNode *lexersRoot = pNppParam->getExternalLexerDoc()->at(x)->FirstChild(TEXT("NotepadPlus"))->FirstChildElement(TEXT("LexerStyles")); + for (TiXmlNode *childNode = lexersRoot->FirstChildElement(TEXT("LexerType")); + childNode ; + childNode = childNode->NextSibling(TEXT("LexerType"))) + { + TiXmlElement *element = childNode->ToElement(); + + if (generic_string(element->Attribute(TEXT("name"))) == lmi._langName) + { + element->SetAttribute(TEXT("excluded"), (LOWORD(wParam)==IDC_BUTTON_REMOVE)?TEXT("yes"):TEXT("no")); + pNppParam->getExternalLexerDoc()->at(x)->SaveFile(); + found = true; + break; + } + } + } + } + + HWND grandParent = ::GetParent(_hParent); + + if (LOWORD(wParam)==IDC_BUTTON_REMOVE) + { + ::DeleteMenu((HMENU)::SendMessage(grandParent, NPPM_INTERNAL_GETMENU, 0, 0), lmi._cmdID, MF_BYCOMMAND); + } + else + { + ::InsertMenu(::GetSubMenu((HMENU)::SendMessage(grandParent, NPPM_INTERNAL_GETMENU, 0, 0), MENUINDEX_LANGUAGE), iAdd-1, MF_BYPOSITION, lmi._cmdID, lmi._langName.c_str()); + } + ::DrawMenuBar(grandParent); + return TRUE; + } + } + } + } + return FALSE; +} + +BOOL CALLBACK PrintSettingsDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam) +{ + NppParameters *pNppParam = NppParameters::getInstance(); + NppGUI & nppGUI = (NppGUI & )pNppParam->getNppGUI(); + + switch (Message) + { + case WM_INITDIALOG : + { + bool printLN = nppGUI._printSettings._printLineNumber; + ::SendDlgItemMessage(_hSelf, IDC_CHECK_PRINTLINENUM, BM_SETCHECK, printLN, 0); + + int ID2Check = 0; + switch (nppGUI._printSettings._printOption) + { + case SC_PRINT_NORMAL : + ID2Check = IDC_RADIO_WYSIWYG; + break; + case SC_PRINT_INVERTLIGHT : + ID2Check = IDC_RADIO_INVERT; + break; + case SC_PRINT_BLACKONWHITE : + ID2Check = IDC_RADIO_BW; + break; + case SC_PRINT_COLOURONWHITE : + ID2Check = IDC_RADIO_NOBG; + break; + } + ::SendDlgItemMessage(_hSelf, ID2Check, BM_SETCHECK, BST_CHECKED, 0); + + TCHAR valStrL[10]; + wsprintf(valStrL, TEXT("%d"), nppGUI._printSettings._marge.left); + + TCHAR valStrR[10]; + wsprintf(valStrR, TEXT("%d"), nppGUI._printSettings._marge.right); + + TCHAR valStrT[10]; + wsprintf(valStrT, TEXT("%d"), nppGUI._printSettings._marge.top); + + TCHAR valStrB[10]; + wsprintf(valStrB, TEXT("%d"), nppGUI._printSettings._marge.bottom); + + ::SendDlgItemMessage(_hSelf, IDC_EDIT_ML, WM_SETTEXT, 0, (LPARAM)valStrL); + ::SendDlgItemMessage(_hSelf, IDC_EDIT_MR, WM_SETTEXT, 0, (LPARAM)valStrR); + ::SendDlgItemMessage(_hSelf, IDC_EDIT_MT, WM_SETTEXT, 0, (LPARAM)valStrT); + ::SendDlgItemMessage(_hSelf, IDC_EDIT_MB, WM_SETTEXT, 0, (LPARAM)valStrB); + + ETDTProc enableDlgTheme = (ETDTProc)pNppParam->getEnableThemeDlgTexture(); + if (enableDlgTheme) + enableDlgTheme(_hSelf, ETDT_ENABLETAB); + break; + } + case WM_COMMAND : + { + if (HIWORD(wParam) == EN_CHANGE) + { + switch (LOWORD(wParam)) + { + case IDC_EDIT_ML: + nppGUI._printSettings._marge.left = ::GetDlgItemInt(_hSelf, IDC_EDIT_ML, NULL, FALSE); + return TRUE; + + case IDC_EDIT_MR: + nppGUI._printSettings._marge.right = ::GetDlgItemInt(_hSelf, IDC_EDIT_MR, NULL, FALSE); + return TRUE; + + case IDC_EDIT_MT : + nppGUI._printSettings._marge.top = ::GetDlgItemInt(_hSelf, IDC_EDIT_MT, NULL, FALSE); + return TRUE; + + case IDC_EDIT_MB : + nppGUI._printSettings._marge.bottom = ::GetDlgItemInt(_hSelf, IDC_EDIT_MB, NULL, FALSE); + return TRUE; + + default : + return FALSE; + } + } + + switch (wParam) + { + case IDC_CHECK_PRINTLINENUM: + nppGUI._printSettings._printLineNumber = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_CHECK_PRINTLINENUM, BM_GETCHECK, 0, 0)); + break; + + case IDC_RADIO_WYSIWYG: + nppGUI._printSettings._printOption = SC_PRINT_NORMAL; + break; + + case IDC_RADIO_INVERT: + nppGUI._printSettings._printOption = SC_PRINT_INVERTLIGHT; + break; + + case IDC_RADIO_BW : + nppGUI._printSettings._printOption = SC_PRINT_BLACKONWHITE; + break; + + case IDC_RADIO_NOBG : + nppGUI._printSettings._printOption = SC_PRINT_COLOURONWHITE; + break; + } + return TRUE; + } + } + return FALSE; +} + +void trim(generic_string & str) +{ + generic_string::size_type pos = str.find_last_not_of(' '); + + if (pos != generic_string::npos) + { + str.erase(pos + 1); + pos = str.find_first_not_of(' '); + if(pos != generic_string::npos) str.erase(0, pos); + } + else str.erase(str.begin(), str.end()); +}; + +BOOL CALLBACK PrintSettings2Dlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam) +{ + NppParameters *pNppParam = NppParameters::getInstance(); + NppGUI & nppGUI = (NppGUI & )pNppParam->getNppGUI(); + + switch (Message) + { + case WM_INITDIALOG : + { + ::SendDlgItemMessage(_hSelf, IDC_EDIT_HLEFT, WM_SETTEXT, 0, (LPARAM)nppGUI._printSettings._headerLeft.c_str()); + ::SendDlgItemMessage(_hSelf, IDC_EDIT_HMIDDLE, WM_SETTEXT, 0, (LPARAM)nppGUI._printSettings._headerMiddle.c_str()); + ::SendDlgItemMessage(_hSelf, IDC_EDIT_HRIGHT, WM_SETTEXT, 0, (LPARAM)nppGUI._printSettings._headerRight.c_str()); + ::SendDlgItemMessage(_hSelf, IDC_EDIT_FLEFT, WM_SETTEXT, 0, (LPARAM)nppGUI._printSettings._footerLeft.c_str()); + ::SendDlgItemMessage(_hSelf, IDC_EDIT_FMIDDLE, WM_SETTEXT, 0, (LPARAM)nppGUI._printSettings._footerMiddle.c_str()); + ::SendDlgItemMessage(_hSelf, IDC_EDIT_FRIGHT, WM_SETTEXT, 0, (LPARAM)nppGUI._printSettings._footerRight.c_str()); + + TCHAR intStr[5]; + for(size_t i = 6 ; i < 15 ; i++) + { + wsprintf(intStr, TEXT("%d"), i); + ::SendDlgItemMessage(_hSelf, IDC_COMBO_HFONTSIZE, CB_ADDSTRING, 0, (LPARAM)intStr); + ::SendDlgItemMessage(_hSelf, IDC_COMBO_FFONTSIZE, CB_ADDSTRING, 0, (LPARAM)intStr); + } + const std::vector & fontlist = pNppParam->getFontList(); + for (size_t i = 0 ; i < fontlist.size() ; i++) + { + int j = ::SendDlgItemMessage(_hSelf, IDC_COMBO_HFONTNAME, CB_ADDSTRING, 0, (LPARAM)fontlist[i].c_str()); + ::SendDlgItemMessage(_hSelf, IDC_COMBO_FFONTNAME, CB_ADDSTRING, 0, (LPARAM)fontlist[i].c_str()); + + ::SendDlgItemMessage(_hSelf, IDC_COMBO_HFONTNAME, CB_SETITEMDATA, j, (LPARAM)fontlist[i].c_str()); + ::SendDlgItemMessage(_hSelf, IDC_COMBO_FFONTNAME, CB_SETITEMDATA, j, (LPARAM)fontlist[i].c_str()); + } + + int index = ::SendDlgItemMessage(_hSelf, IDC_COMBO_HFONTNAME, CB_FINDSTRINGEXACT, (WPARAM)-1, (LPARAM)nppGUI._printSettings._headerFontName.c_str()); + if (index == CB_ERR) + index = 0; + ::SendDlgItemMessage(_hSelf, IDC_COMBO_HFONTNAME, CB_SETCURSEL, index, 0); + index = ::SendDlgItemMessage(_hSelf, IDC_COMBO_FFONTNAME, CB_FINDSTRINGEXACT, (WPARAM)-1, (LPARAM)nppGUI._printSettings._footerFontName.c_str()); + if (index == CB_ERR) + index = 0; + ::SendDlgItemMessage(_hSelf, IDC_COMBO_FFONTNAME, CB_SETCURSEL, index, 0); + + wsprintf(intStr, TEXT("%d"), nppGUI._printSettings._headerFontSize); + ::SendDlgItemMessage(_hSelf, IDC_COMBO_HFONTSIZE, CB_SELECTSTRING, -1, (LPARAM)intStr); + wsprintf(intStr, TEXT("%d"), nppGUI._printSettings._footerFontSize); + ::SendDlgItemMessage(_hSelf, IDC_COMBO_FFONTSIZE, CB_SELECTSTRING, -1, (LPARAM)intStr); + + ::SendDlgItemMessage(_hSelf, IDC_CHECK_HBOLD, BM_SETCHECK, nppGUI._printSettings._headerFontStyle & FONTSTYLE_BOLD?TRUE:FALSE, 0); + ::SendDlgItemMessage(_hSelf, IDC_CHECK_HITALIC, BM_SETCHECK, nppGUI._printSettings._headerFontStyle & FONTSTYLE_ITALIC?TRUE:FALSE, 0); + ::SendDlgItemMessage(_hSelf, IDC_CHECK_FBOLD, BM_SETCHECK, nppGUI._printSettings._footerFontStyle & FONTSTYLE_BOLD?TRUE:FALSE, 0); + ::SendDlgItemMessage(_hSelf, IDC_CHECK_FITALIC, BM_SETCHECK, nppGUI._printSettings._footerFontStyle & FONTSTYLE_ITALIC?TRUE:FALSE, 0); + + varList.push_back(strCouple(TEXT("Full file name path"), TEXT("$(FULL_CURRENT_PATH)"))); + varList.push_back(strCouple(TEXT("File name"), TEXT("$(FILE_NAME)"))); + varList.push_back(strCouple(TEXT("File directory"), TEXT("$(FULL_CURRENT_PATH)"))); + varList.push_back(strCouple(TEXT("Page"), TEXT("$(CURRENT_PRINTING_PAGE)"))); + varList.push_back(strCouple(TEXT("Short date format"), TEXT("$(SHORT_DATE)"))); + varList.push_back(strCouple(TEXT("Long date format"), TEXT("$(LONG_DATE)"))); + varList.push_back(strCouple(TEXT("Time"), TEXT("$(TIME)"))); + + for (size_t i = 0 ; i < varList.size() ; i++) + { + int j = ::SendDlgItemMessage(_hSelf, IDC_COMBO_VARLIST, CB_ADDSTRING, 0, (LPARAM)varList[i]._varDesc.c_str()); + ::SendDlgItemMessage(_hSelf, IDC_COMBO_VARLIST, CB_SETITEMDATA, j, (LPARAM)varList[i]._var.c_str()); + } + ::SendDlgItemMessage(_hSelf, IDC_COMBO_VARLIST, CB_SETCURSEL, 0, 0); + + //_colourHooker.setColour(RGB(0, 0, 0xFF)); + //_colourHooker.hookOn(::GetDlgItem(_hSelf, IDC_VIEWPANEL_STATIC)); + ETDTProc enableDlgTheme = (ETDTProc)pNppParam->getEnableThemeDlgTexture(); + if (enableDlgTheme) + enableDlgTheme(_hSelf, ETDT_ENABLETAB); + + return TRUE; + } + case WM_COMMAND : + { + if (HIWORD(wParam) == EN_CHANGE) + { + const int stringSize = 256; + TCHAR str[stringSize]; + _focusedEditCtrl = LOWORD(wParam); + ::GetDlgItemText(_hSelf, _focusedEditCtrl, str, stringSize); + ::SendDlgItemMessage(_hSelf, IDC_VIEWPANEL_STATIC, WM_SETTEXT, 0, (LPARAM)str); + + switch (LOWORD(wParam)) + { + case IDC_EDIT_HLEFT: + nppGUI._printSettings._headerLeft = str; + trim(nppGUI._printSettings._headerLeft); + return TRUE; + + case IDC_EDIT_HMIDDLE: + nppGUI._printSettings._headerMiddle = str; + trim(nppGUI._printSettings._headerMiddle); + return TRUE; + + case IDC_EDIT_HRIGHT : + nppGUI._printSettings._headerRight = str; + trim(nppGUI._printSettings._headerRight); + return TRUE; + + case IDC_EDIT_FLEFT: + nppGUI._printSettings._footerLeft = str; + trim(nppGUI._printSettings._footerLeft); + return TRUE; + + case IDC_EDIT_FMIDDLE: + nppGUI._printSettings._footerMiddle = str; + trim(nppGUI._printSettings._footerMiddle); + return TRUE; + + case IDC_EDIT_FRIGHT : + nppGUI._printSettings._footerRight = str; + trim(nppGUI._printSettings._footerRight); + return TRUE; + + default : + return FALSE; + } + } + else if (HIWORD(wParam) == EN_SETFOCUS) + { + const int stringSize = 256; + TCHAR str[stringSize]; + _focusedEditCtrl = LOWORD(wParam); + ::GetDlgItemText(_hSelf, _focusedEditCtrl, str, stringSize); + //_colourHooker.setColour(RGB(0, 0, 0xFF)); + ::SendDlgItemMessage(_hSelf, IDC_VIEWPANEL_STATIC, WM_SETTEXT, 0, (LPARAM)str); + + int focusedEditStatic; + int groupStatic; + switch (_focusedEditCtrl) + { + case IDC_EDIT_HLEFT : focusedEditStatic = IDC_HL_STATIC; groupStatic = IDC_HGB_STATIC; break; + case IDC_EDIT_HMIDDLE : focusedEditStatic = IDC_HM_STATIC; groupStatic = IDC_HGB_STATIC; break; + case IDC_EDIT_HRIGHT : focusedEditStatic = IDC_HR_STATIC; groupStatic = IDC_HGB_STATIC; break; + case IDC_EDIT_FLEFT : focusedEditStatic = IDC_FL_STATIC; groupStatic = IDC_FGB_STATIC; break; + case IDC_EDIT_FMIDDLE : focusedEditStatic = IDC_FM_STATIC; groupStatic = IDC_FGB_STATIC; break; + case IDC_EDIT_FRIGHT : focusedEditStatic = IDC_FR_STATIC; groupStatic = IDC_FGB_STATIC; break; + } + + ::GetDlgItemText(_hSelf, groupStatic, str, stringSize); + generic_string title = str; + title += TEXT(" "); + ::GetDlgItemText(_hSelf, focusedEditStatic, str, stringSize); + title += str; + title += TEXT(" : "); + + ::SendDlgItemMessage(_hSelf, IDC_WHICHPART_STATIC, WM_SETTEXT, 0, (LPARAM)title.c_str()); + return TRUE; + } + else if (HIWORD(wParam) == CBN_SELCHANGE) + { + int iSel = ::SendDlgItemMessage(_hSelf, LOWORD(wParam), CB_GETCURSEL, 0, 0); + + switch (LOWORD(wParam)) + { + case IDC_COMBO_HFONTNAME : + case IDC_COMBO_FFONTNAME : + { + TCHAR *fnStr = (TCHAR *)::SendDlgItemMessage(_hSelf, LOWORD(wParam), CB_GETITEMDATA, iSel, 0); + if (LOWORD(wParam) == IDC_COMBO_HFONTNAME) + nppGUI._printSettings._headerFontName = fnStr; + else + nppGUI._printSettings._footerFontName = fnStr; + } + break; + + + case IDC_COMBO_HFONTSIZE : + case IDC_COMBO_FFONTSIZE : + { + TCHAR intStr[5]; + ::SendDlgItemMessage(_hSelf, LOWORD(wParam), CB_GETLBTEXT, iSel, (LPARAM)intStr); + + int *pVal = (LOWORD(wParam) == IDC_COMBO_HFONTSIZE)?&(nppGUI._printSettings._headerFontSize):&(nppGUI._printSettings._footerFontSize); + + if ((!intStr) || (!intStr[0])) + *pVal = 0; + else + *pVal = generic_strtol(intStr, NULL, 10); + } + break; + + case IDC_COMBO_VARLIST : + { + } + break; + } + return TRUE; + + } + + switch (wParam) + { + case IDC_CHECK_HBOLD: + nppGUI._printSettings._headerFontStyle ^= FONTSTYLE_BOLD; + break; + + case IDC_CHECK_HITALIC: + nppGUI._printSettings._headerFontStyle ^= FONTSTYLE_ITALIC; + break; + + case IDC_CHECK_FBOLD: + nppGUI._printSettings._footerFontStyle ^= FONTSTYLE_BOLD; + break; + + case IDC_CHECK_FITALIC: + nppGUI._printSettings._footerFontStyle ^= FONTSTYLE_ITALIC; + break; + + case IDC_BUTTON_ADDVAR: + { + if (!_focusedEditCtrl) + return TRUE; + + int iSel = ::SendDlgItemMessage(_hSelf, IDC_COMBO_VARLIST, CB_GETCURSEL, 0, 0); + TCHAR *varStr = (TCHAR *)::SendDlgItemMessage(_hSelf, IDC_COMBO_VARLIST, CB_GETITEMDATA, iSel, 0); + + ::SendDlgItemMessage(_hSelf, _focusedEditCtrl, EM_GETSEL, (WPARAM)&_selStart, (LPARAM)&_selEnd); +/* + TCHAR toto[32]; + wsprintf(toto, TEXT("_selStart = %d\r_selEnd = %d"), _selStart, _selEnd); + ::MessageBox(NULL, toto, TEXT(""), MB_OK); +*/ + const int stringSize = 256; + TCHAR str[stringSize]; + ::SendDlgItemMessage(_hSelf, _focusedEditCtrl, WM_GETTEXT, stringSize, (LPARAM)str); + //::MessageBox(NULL, str, TEXT(""), MB_OK); + + generic_string str2Set(str); + str2Set.replace(_selStart, _selEnd - _selStart, varStr); + + ::SetDlgItemText(_hSelf, _focusedEditCtrl, str2Set.c_str()); + } + break; + + } + return TRUE; + } + } + return FALSE; +} + +BOOL CALLBACK BackupDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam) +{ + NppParameters *pNppParam = NppParameters::getInstance(); + NppGUI & nppGUI = (NppGUI &)pNppParam->getNppGUI(); + switch (Message) + { + case WM_INITDIALOG : + { + TCHAR nbStr[10]; + wsprintf(nbStr, TEXT("%d"), nppGUI._autocFromLen); + HWND hNbChar_val = ::GetDlgItem(_hSelf, IDD_AUTOC_STATIC_N); + ::SetWindowText(hNbChar_val, nbStr); + + _nbCharVal.init(_hInst, _hSelf); + _nbCharVal.create(hNbChar_val, IDM_SETTING_AUTOCNBCHAR); + + int ID2Check = 0; + + switch (nppGUI._backup) + { + case bak_simple : + ID2Check = IDC_RADIO_BKSIMPLE; + break; + case bak_verbose : + ID2Check = IDC_RADIO_BKVERBOSE; + break; + + default : //bak_none + ID2Check = IDC_RADIO_BKNONE; + } + ::SendDlgItemMessage(_hSelf, ID2Check, BM_SETCHECK, BST_CHECKED, 0); + + if (nppGUI._useDir) + ::SendDlgItemMessage(_hSelf, IDC_BACKUPDIR_CHECK, BM_SETCHECK, BST_CHECKED, 0); + + ::SendDlgItemMessage(_hSelf, IDC_BACKUPDIR_EDIT, WM_SETTEXT, 0, (LPARAM)nppGUI._backupDir); + + bool isEnableAutoC = nppGUI._autocStatus != nppGUI.autoc_none; + + ::SendDlgItemMessage(_hSelf, IDD_AUTOC_ENABLECHECK, BM_SETCHECK, isEnableAutoC?BST_CHECKED:BST_UNCHECKED, 0); + ::SendDlgItemMessage(_hSelf, IDD_AUTOC_FUNCRADIO, BM_SETCHECK, nppGUI._autocStatus == nppGUI.autoc_func?BST_CHECKED:BST_UNCHECKED, 0); + ::SendDlgItemMessage(_hSelf, IDD_AUTOC_WORDRADIO, BM_SETCHECK, nppGUI._autocStatus == nppGUI.autoc_word?BST_CHECKED:BST_UNCHECKED, 0); + ::SendDlgItemMessage(_hSelf, IDD_FUNC_CHECK, BM_SETCHECK, nppGUI._funcParams?BST_CHECKED:BST_UNCHECKED, 0); + if (!isEnableAutoC) + { + ::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_FUNCRADIO), FALSE); + ::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_WORDRADIO), FALSE); + ::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_STATIC_FROM), FALSE); + ::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_STATIC_N), FALSE); + ::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_STATIC_CHAR), FALSE); + ::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_STATIC_NOTE), FALSE); + } + updateBackupGUI(); + return TRUE; + } + case WM_COMMAND : + { + if (HIWORD(wParam) == EN_CHANGE) + { + switch (LOWORD(wParam)) + { + case IDC_BACKUPDIR_EDIT: + { + TCHAR inputDir[MAX_PATH]; + ::SendDlgItemMessage(_hSelf, IDC_BACKUPDIR_EDIT, WM_GETTEXT, MAX_PATH, (LPARAM)inputDir); + lstrcpy(nppGUI._backupDir, inputDir); + return TRUE; + } + } + } + + switch (wParam) + { + case IDC_RADIO_BKSIMPLE: + { + nppGUI._backup = bak_simple; + updateBackupGUI(); + return TRUE; + } + + case IDC_RADIO_BKVERBOSE: + { + nppGUI._backup = bak_verbose; + updateBackupGUI(); + return TRUE; + } + + case IDC_RADIO_BKNONE: + { + nppGUI._backup = bak_none; + updateBackupGUI(); + return TRUE; + } + + case IDC_BACKUPDIR_CHECK: + { + nppGUI._useDir = !nppGUI._useDir; + updateBackupGUI(); + return TRUE; + } + case IDD_BACKUPDIR_BROWSE_BUTTON : + { + folderBrowser(_hSelf, IDC_BACKUPDIR_EDIT); + return TRUE; + } + + case IDD_AUTOC_ENABLECHECK : + { + bool isEnableAutoC = BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDD_AUTOC_ENABLECHECK, BM_GETCHECK, 0, 0); + + if (isEnableAutoC) + { + ::SendDlgItemMessage(_hSelf, IDD_AUTOC_FUNCRADIO, BM_SETCHECK, BST_CHECKED, 0); + nppGUI._autocStatus = nppGUI.autoc_func; + } + else + { + ::SendDlgItemMessage(_hSelf, IDD_AUTOC_FUNCRADIO, BM_SETCHECK, BST_UNCHECKED, 0); + ::SendDlgItemMessage(_hSelf, IDD_AUTOC_WORDRADIO, BM_SETCHECK, BST_UNCHECKED, 0); + nppGUI._autocStatus = nppGUI.autoc_none; + } + ::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_FUNCRADIO), isEnableAutoC); + ::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_WORDRADIO), isEnableAutoC); + ::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_STATIC_FROM), isEnableAutoC); + ::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_STATIC_N), isEnableAutoC); + ::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_STATIC_CHAR), isEnableAutoC); + ::EnableWindow(::GetDlgItem(_hSelf, IDD_AUTOC_STATIC_NOTE), isEnableAutoC); + return TRUE; + } + + case IDD_AUTOC_FUNCRADIO : + { + nppGUI._autocStatus = nppGUI.autoc_func; + return TRUE; + } + + case IDD_AUTOC_WORDRADIO : + { + nppGUI._autocStatus = nppGUI.autoc_word; + return TRUE; + } + case IDD_FUNC_CHECK : + { + nppGUI._funcParams = (BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDD_FUNC_CHECK, BM_GETCHECK, 0, 0)); + return TRUE; + } + + case IDM_SETTING_AUTOCNBCHAR : + { + ::SendMessage(_hParent, WM_COMMAND, IDM_SETTING_AUTOCNBCHAR, 0); + TCHAR nbStr[10]; + wsprintf(nbStr, TEXT("%d"), pNppParam->getNppGUI()._autocFromLen); + ::SetWindowText(::GetDlgItem(_hSelf, IDD_AUTOC_STATIC_N), nbStr); + return TRUE; + } + + default : + return FALSE; + } + + } + } + return FALSE; +} + +void BackupDlg::updateBackupGUI() +{ + bool noBackup = BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_RADIO_BKNONE, BM_GETCHECK, 0, 0); + bool isEnableGlobableCheck = false; + bool isEnableLocalCheck = false; + + if (!noBackup) + { + isEnableGlobableCheck = true; + isEnableLocalCheck = BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_BACKUPDIR_CHECK, BM_GETCHECK, 0, 0); + } + ::EnableWindow(::GetDlgItem(_hSelf, IDC_BACKUPDIR_USERCUSTOMDIR_GRPSTATIC), isEnableGlobableCheck); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_BACKUPDIR_CHECK), isEnableGlobableCheck); + + ::EnableWindow(::GetDlgItem(_hSelf, IDD_BACKUPDIR_STATIC), isEnableLocalCheck); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_BACKUPDIR_EDIT), isEnableLocalCheck); + ::EnableWindow(::GetDlgItem(_hSelf, IDD_BACKUPDIR_BROWSE_BUTTON), isEnableLocalCheck); +} diff --git a/PowerEditor/src/WinControls/Preference/preferenceDlg.h b/PowerEditor/src/WinControls/Preference/preferenceDlg.h new file mode 100644 index 00000000..09c83268 --- /dev/null +++ b/PowerEditor/src/WinControls/Preference/preferenceDlg.h @@ -0,0 +1,187 @@ +/* +this file is part of notepad++ +Copyright (C)2003 Don HO < donho@altern.org > + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef PREFERENCE_DLG_H +#define PREFERENCE_DLG_H + +#include "Window.h" +#include "StaticDialog.h" +#include "ControlsTab.h" +#include "preference_rc.h" +#include "URLCtrl.h" +#include "Parameters.h" +#include "regExtDlg.h" +#include "WordStyleDlg.h" + +class SettingsDlg : public StaticDialog +{ +public : + SettingsDlg() {}; + virtual void destroy() { + _nbHistoryVal.destroy(); + }; +private : + URLCtrl _nbHistoryVal; + bool isCheckedOrNot(int checkControlID) const { + return (BST_CHECKED == ::SendMessage(::GetDlgItem(_hSelf, checkControlID), BM_GETCHECK, 0, 0)); + }; + BOOL CALLBACK run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam); +}; + +class BarsDlg : public StaticDialog +{ +public : + BarsDlg() {}; +private : + BOOL CALLBACK run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam); +}; + +class MarginsDlg : public StaticDialog +{ +public : + MarginsDlg() {}; + virtual void destroy() { + _tabSizeVal.destroy(); + _verticalEdgeLineNbColVal.destroy(); + }; + +private : + URLCtrl _tabSizeVal; + URLCtrl _verticalEdgeLineNbColVal; + BOOL CALLBACK run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam); + void changePanelTo(int index); +}; + +struct LangID_Name +{ + LangType _id; + generic_string _name; + LangID_Name(LangType id, generic_string name) : _id(id), _name(name){}; +}; + +class DefaultNewDocDlg : public StaticDialog +{ +public : + DefaultNewDocDlg() {}; +private : + std::vector _langList; + void makeOpenAnsiAsUtf8(bool doIt){ + if (!doIt) + ::SendDlgItemMessage(_hSelf, IDC_CHECK_OPENANSIASUTF8, BM_SETCHECK, BST_UNCHECKED, 0); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_CHECK_OPENANSIASUTF8), doIt); + }; + BOOL CALLBACK run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam); +}; + +class LangMenuDlg : public StaticDialog +{ +public : + LangMenuDlg() {}; +private : + BOOL CALLBACK run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam); + vector _langList; +}; + +class PrintSettingsDlg : public StaticDialog +{ +public : + PrintSettingsDlg() {}; +private : + BOOL CALLBACK run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam); +}; + +class BackupDlg : public StaticDialog +{ +public : + BackupDlg() {}; +private : + URLCtrl _nbCharVal; + void updateBackupGUI(); + BOOL CALLBACK run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam); +}; + +struct strCouple { + generic_string _varDesc; + generic_string _var; + strCouple(TCHAR *varDesc, TCHAR *var): _varDesc(varDesc), _var(var){}; +}; + +class PrintSettings2Dlg : public StaticDialog +{ +public : + PrintSettings2Dlg():_focusedEditCtrl(0), _selStart(0), _selEnd(0){}; +private : + BOOL CALLBACK run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam); + vector varList; + int _focusedEditCtrl; + DWORD _selStart; + DWORD _selEnd; + + //ColourStaticTextHooker _colourHooker; +}; + +class PreferenceDlg : public StaticDialog +{ +friend class Notepad_plus; + +public : + PreferenceDlg(){}; + + void init(HINSTANCE hInst, HWND parent) { + Window::init(hInst, parent); + }; + + void doDialog(bool isRTL = false) { + if (!isCreated()) + { + create(IDD_PREFERENCE_BOX, isRTL); + goToCenter(); + } + display(); + }; + + virtual void destroy() { + _ctrlTab.destroy(); + _barsDlg.destroy(); + _marginsDlg.destroy(); + _settingsDlg.destroy(); + _fileAssocDlg.destroy(); + _langMenuDlg.destroy(); + _printSettingsDlg.destroy(); + _printSettings2Dlg.destroy(); + _defaultNewDocDlg.destroy(); + }; +private : + BOOL CALLBACK run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam); + ControlsTab _ctrlTab; + WindowVector _wVector; + BarsDlg _barsDlg; + MarginsDlg _marginsDlg; + SettingsDlg _settingsDlg; + RegExtDlg _fileAssocDlg; + LangMenuDlg _langMenuDlg; + PrintSettingsDlg _printSettingsDlg; + PrintSettings2Dlg _printSettings2Dlg; + DefaultNewDocDlg _defaultNewDocDlg; + BackupDlg _backupDlg; +}; + + + +#endif //PREFERENCE_DLG_H \ No newline at end of file diff --git a/PowerEditor/src/WinControls/Preference/preference_rc.h b/PowerEditor/src/WinControls/Preference/preference_rc.h new file mode 100644 index 00000000..b9fa101b --- /dev/null +++ b/PowerEditor/src/WinControls/Preference/preference_rc.h @@ -0,0 +1,206 @@ +/* +this file is part of notepad++ +Copyright (C)2003 Don HO ( donho@altern.org ) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#define IDD_PREFERENCE_BOX 6000 + #define IDC_BUTTON_CLOSE (IDD_PREFERENCE_BOX + 1) + + +#define IDD_PREFERENCE_BAR_BOX 6100 //(IDD_PREFERENCE_BOX + 100) + #define IDC_TOOLBAR_GB_STATIC (IDD_PREFERENCE_BAR_BOX + 1) + #define IDC_CHECK_HIDE (IDD_PREFERENCE_BAR_BOX + 2) + #define IDC_RADIO_SMALLICON (IDD_PREFERENCE_BAR_BOX + 3) + #define IDC_RADIO_BIGICON (IDD_PREFERENCE_BAR_BOX + 4) + #define IDC_RADIO_STANDARD (IDD_PREFERENCE_BAR_BOX + 5) + + #define IDC_TABBAR_GB_STATIC (IDD_PREFERENCE_BAR_BOX + 6) + #define IDC_CHECK_REDUCE (IDD_PREFERENCE_BAR_BOX + 7) + #define IDC_CHECK_LOCK (IDD_PREFERENCE_BAR_BOX + 8) + #define IDC_CHECK_DRAWINACTIVE (IDD_PREFERENCE_BAR_BOX + 9) + #define IDC_CHECK_ORANGE (IDD_PREFERENCE_BAR_BOX + 10) + #define IDC_CHECK_SHOWSTATUSBAR (IDD_PREFERENCE_BAR_BOX + 11) + #define IDC_CHECK_ENABLETABCLOSE (IDD_PREFERENCE_BAR_BOX + 12) + #define IDC_CHECK_DBCLICK2CLOSE (IDD_PREFERENCE_BAR_BOX + 13) + #define IDC_CHECK_ENABLEDOCSWITCHER (IDD_PREFERENCE_BAR_BOX + 14) + #define IDC_CHECK_MAINTAININDENT (IDD_PREFERENCE_BAR_BOX + 15) + #define IDC_CHECK_KEEPINSAMEDIR (IDD_PREFERENCE_BAR_BOX + 16) + #define IDC_CHECK_STYLEMRU (IDD_PREFERENCE_BAR_BOX + 17) + #define IDC_CHECK_TAB_HIDE (IDD_PREFERENCE_BAR_BOX + 18) + #define IDC_CHECK_TAB_MULTILINE (IDD_PREFERENCE_BAR_BOX + 19) + #define IDC_CHECK_TAB_VERTICAL (IDD_PREFERENCE_BAR_BOX + 20) + #define IDC_MENUBAR_GB_STATIC (IDD_PREFERENCE_BAR_BOX + 21) + #define IDC_CHECK_HIDEMENUBAR (IDD_PREFERENCE_BAR_BOX + 22) + #define IDC_LOCALIZATION_GB_STATIC (IDD_PREFERENCE_BAR_BOX + 23) + #define IDC_COMBO_LOCALIZATION (IDD_PREFERENCE_BAR_BOX + 24) + +#define IDD_PREFERENCE_MARGEIN_BOX 6200 //(IDD_PREFERENCE_BOX + 200) + #define IDC_FMS_GB_STATIC (IDD_PREFERENCE_MARGEIN_BOX + 1) + #define IDC_RADIO_SIMPLE (IDD_PREFERENCE_MARGEIN_BOX + 2) + #define IDC_RADIO_ARROW (IDD_PREFERENCE_MARGEIN_BOX + 3) + #define IDC_RADIO_CIRCLE (IDD_PREFERENCE_MARGEIN_BOX + 4) + #define IDC_RADIO_BOX (IDD_PREFERENCE_MARGEIN_BOX + 5) + + #define IDC_CHECK_LINENUMBERMARGE (IDD_PREFERENCE_MARGEIN_BOX + 6) + #define IDC_CHECK_BOOKMARKMARGE (IDD_PREFERENCE_MARGEIN_BOX + 7) + + #define IDC_CHECK_SHOWVERTICALEDGE (IDD_PREFERENCE_MARGEIN_BOX + 8) + #define IDC_NBCOLONE_STATIC (IDD_PREFERENCE_MARGEIN_BOX + 9) + #define IDC_COLONENUMBER_STATIC (IDD_PREFERENCE_MARGEIN_BOX + 10) + + #define IDC_VES_GB_STATIC (IDD_PREFERENCE_MARGEIN_BOX + 11) + #define IDC_RADIO_LNMODE (IDD_PREFERENCE_MARGEIN_BOX + 12) + #define IDC_RADIO_BGMODE (IDD_PREFERENCE_MARGEIN_BOX + 13) + #define IDC_CHECK_CURRENTLINEHILITE (IDD_PREFERENCE_MARGEIN_BOX + 14) + #define IDC_COMBO_SCINTILLAVIEWCHOIX (IDD_PREFERENCE_MARGEIN_BOX + 15) + + #define IDC_CARETSETTING_STATIC (IDD_PREFERENCE_MARGEIN_BOX + 16) + #define IDC_WIDTH_STATIC (IDD_PREFERENCE_MARGEIN_BOX + 17) + #define IDC_WIDTH_COMBO (IDD_PREFERENCE_MARGEIN_BOX + 18) + #define IDC_BLINKRATE_STATIC (IDD_PREFERENCE_MARGEIN_BOX + 19) + #define IDC_CARETBLINKRATE_SLIDER (IDD_PREFERENCE_MARGEIN_BOX + 20) + #define IDC_CARETBLINKRATE_F_STATIC (IDD_PREFERENCE_MARGEIN_BOX + 21) + #define IDC_CARETBLINKRATE_S_STATIC (IDD_PREFERENCE_MARGEIN_BOX + 22) + #define IDC_CHECK_DOCCHANGESTATEMARGE (IDD_PREFERENCE_MARGEIN_BOX + 23) + +#define IDD_PREFERENCE_SETTING_BOX 6300 //(IDD_PREFERENCE_BOX + 300) + #define IDC_TABSETTING_GB_STATIC (IDD_PREFERENCE_SETTING_BOX + 1) + #define IDC_CHECK_REPLACEBYSPACE (IDD_PREFERENCE_SETTING_BOX + 2) + #define IDC_TABSIZE_STATIC (IDD_PREFERENCE_SETTING_BOX + 3) + #define IDC_HISTORY_GB_STATIC (IDD_PREFERENCE_SETTING_BOX + 4) + #define IDC_CHECK_DONTCHECKHISTORY (IDD_PREFERENCE_SETTING_BOX + 5) + #define IDC_MAXNBFILE_STATIC (IDD_PREFERENCE_SETTING_BOX + 6) + #define IDC_CHECK_FILEAUTODETECTION (IDD_PREFERENCE_SETTING_BOX + 7) + #define IDC_CHECK_MIN2SYSTRAY (IDD_PREFERENCE_SETTING_BOX + 8) + #define IDC_CHECK_REMEMBERSESSION (IDD_PREFERENCE_SETTING_BOX + 9) + #define IDC_TABSIZEVAL_STATIC (IDD_PREFERENCE_SETTING_BOX + 10) + #define IDC_MAXNBFILEVAL_STATIC (IDD_PREFERENCE_SETTING_BOX + 11) + #define IDC_FILEAUTODETECTION_STATIC (IDD_PREFERENCE_SETTING_BOX + 12) + #define IDC_CHECK_UPDATESILENTLY (IDD_PREFERENCE_SETTING_BOX + 13) + #define IDC_BACKUP_GB_STATIC (IDD_PREFERENCE_SETTING_BOX + 14) + #define IDC_RADIO_BKNONE (IDD_PREFERENCE_SETTING_BOX + 15) + #define IDC_RADIO_BKSIMPLE (IDD_PREFERENCE_SETTING_BOX + 16) + #define IDC_RADIO_BKVERBOSE (IDD_PREFERENCE_SETTING_BOX + 17) + #define IDC_CLICKABLELINK_STATIC (IDD_PREFERENCE_SETTING_BOX + 18) + #define IDC_CHECK_CLICKABLELINK_ENABLE (IDD_PREFERENCE_SETTING_BOX + 19) + #define IDC_CHECK_CLICKABLELINK_NOUNDERLINE (IDD_PREFERENCE_SETTING_BOX + 20) + #define IDC_EDIT_SESSIONFILEEXT (IDD_PREFERENCE_SETTING_BOX + 21) + #define IDC_SESSIONFILEEXT_STATIC (IDD_PREFERENCE_SETTING_BOX + 22) + #define IDC_CHECK_AUTOUPDATE (IDD_PREFERENCE_SETTING_BOX + 23) + #define IDC_DOCUMENTSWITCHER_STATIC (IDD_PREFERENCE_SETTING_BOX + 24) + #define IDC_CHECK_UPDATEGOTOEOF (IDD_PREFERENCE_SETTING_BOX + 25) + #define IDC_CHECK_ENABLSMARTHILITE (IDD_PREFERENCE_SETTING_BOX + 26) + #define IDC_CHECK_ENABLTAGSMATCHHILITE (IDD_PREFERENCE_SETTING_BOX + 27) + #define IDC_CHECK_ENABLTAGATTRHILITE (IDD_PREFERENCE_SETTING_BOX + 28) + #define IDC_TAGMATCHEDHILITE_STATIC (IDD_PREFERENCE_SETTING_BOX + 29) + #define IDC_CHECK_HIGHLITENONEHTMLZONE (IDD_PREFERENCE_SETTING_BOX + 30) + #define IDC_CHECK_SHORTTITLE (IDD_PREFERENCE_SETTING_BOX + 31) + +#define IDD_PREFERENCE_NEWDOCSETTING_BOX 6400 //(IDD_PREFERENCE_BOX + 400) + #define IDC_FORMAT_GB_STATIC (IDD_PREFERENCE_NEWDOCSETTING_BOX + 1) + #define IDC_RADIO_F_WIN (IDD_PREFERENCE_NEWDOCSETTING_BOX + 2) + #define IDC_RADIO_F_UNIX (IDD_PREFERENCE_NEWDOCSETTING_BOX + 3) + #define IDC_RADIO_F_MAC (IDD_PREFERENCE_NEWDOCSETTING_BOX + 4) + #define IDC_ENCODING_STATIC (IDD_PREFERENCE_NEWDOCSETTING_BOX + 5) + #define IDC_RADIO_ANSI (IDD_PREFERENCE_NEWDOCSETTING_BOX + 6) + #define IDC_RADIO_UTF8SANSBOM (IDD_PREFERENCE_NEWDOCSETTING_BOX + 7) + #define IDC_RADIO_UTF8 (IDD_PREFERENCE_NEWDOCSETTING_BOX + 8) + #define IDC_RADIO_UCS2BIG (IDD_PREFERENCE_NEWDOCSETTING_BOX + 9) + #define IDC_RADIO_UCS2SMALL (IDD_PREFERENCE_NEWDOCSETTING_BOX + 10) + #define IDC_DEFAULTLANG_STATIC (IDD_PREFERENCE_NEWDOCSETTING_BOX + 11) + #define IDC_COMBO_DEFAULTLANG (IDD_PREFERENCE_NEWDOCSETTING_BOX + 12) + #define IDC_OPENSAVEDIR_GR_STATIC (IDD_PREFERENCE_NEWDOCSETTING_BOX + 13) + #define IDC_OPENSAVEDIR_FOLLOWCURRENT_RADIO (IDD_PREFERENCE_NEWDOCSETTING_BOX + 14) + #define IDC_OPENSAVEDIR_REMEMBERLAST_RADIO (IDD_PREFERENCE_NEWDOCSETTING_BOX + 15) + #define IDC_OPENSAVEDIR_ALWAYSON_RADIO (IDD_PREFERENCE_NEWDOCSETTING_BOX + 16) + #define IDC_OPENSAVEDIR_ALWAYSON_EDIT (IDD_PREFERENCE_NEWDOCSETTING_BOX + 17) + #define IDD_OPENSAVEDIR_ALWAYSON_BROWSE_BUTTON (IDD_PREFERENCE_NEWDOCSETTING_BOX + 18) + #define IDC_NEWDOCUMENT_GR_STATIC (IDD_PREFERENCE_NEWDOCSETTING_BOX + 19) + #define IDC_CHECK_OPENANSIASUTF8 (IDD_PREFERENCE_NEWDOCSETTING_BOX + 20) + +#define IDD_PREFERENCE_LANG_BOX 6500 //(IDD_PREFERENCE_BOX + 500) + #define IDC_LIST_ENABLEDLANG (IDD_PREFERENCE_LANG_BOX + 1) + #define IDC_LIST_DISABLEDLANG (IDD_PREFERENCE_LANG_BOX + 2) + #define IDC_BUTTON_REMOVE (IDD_PREFERENCE_LANG_BOX + 3) + #define IDC_BUTTON_RESTORE (IDD_PREFERENCE_LANG_BOX + 4) + #define IDC_ENABLEDITEMS_STATIC (IDD_PREFERENCE_LANG_BOX + 5) + #define IDC_DISABLEDITEMS_STATIC (IDD_PREFERENCE_LANG_BOX + 6) + #define IDC_CHECK_LANGMENUCOMPACT (IDD_PREFERENCE_LANG_BOX + 7) + +#define IDD_PREFERENCE_PRINT_BOX 6600 //(IDD_PREFERENCE_BOX + 600) + #define IDC_CHECK_PRINTLINENUM (IDD_PREFERENCE_PRINT_BOX + 1) + #define IDC_COLOUROPT_STATIC (IDD_PREFERENCE_PRINT_BOX + 2) + #define IDC_RADIO_WYSIWYG (IDD_PREFERENCE_PRINT_BOX + 3) + #define IDC_RADIO_INVERT (IDD_PREFERENCE_PRINT_BOX + 4) + #define IDC_RADIO_BW (IDD_PREFERENCE_PRINT_BOX + 5) + #define IDC_RADIO_NOBG (IDD_PREFERENCE_PRINT_BOX + 6) + #define IDC_MARGESETTINGS_STATIC (IDD_PREFERENCE_PRINT_BOX + 7) + #define IDC_EDIT_ML (IDD_PREFERENCE_PRINT_BOX + 8) + #define IDC_EDIT_MT (IDD_PREFERENCE_PRINT_BOX + 9) + #define IDC_EDIT_MR (IDD_PREFERENCE_PRINT_BOX + 10) + #define IDC_EDIT_MB (IDD_PREFERENCE_PRINT_BOX + 11) + #define IDC_ML_STATIC (IDD_PREFERENCE_PRINT_BOX + 12) + #define IDC_MT_STATIC (IDD_PREFERENCE_PRINT_BOX + 13) + #define IDC_MR_STATIC (IDD_PREFERENCE_PRINT_BOX + 14) + #define IDC_MB_STATIC (IDD_PREFERENCE_PRINT_BOX + 15) + +#define IDD_PREFERENCE_PRINT2_BOX 6700 //(IDD_PREFERENCE_BOX + 700) + #define IDC_EDIT_HLEFT (IDD_PREFERENCE_PRINT2_BOX + 1) + #define IDC_EDIT_HMIDDLE (IDD_PREFERENCE_PRINT2_BOX + 2) + #define IDC_EDIT_HRIGHT (IDD_PREFERENCE_PRINT2_BOX + 3) + #define IDC_COMBO_HFONTNAME (IDD_PREFERENCE_PRINT2_BOX + 4) + #define IDC_COMBO_HFONTSIZE (IDD_PREFERENCE_PRINT2_BOX + 5) + #define IDC_CHECK_HBOLD (IDD_PREFERENCE_PRINT2_BOX + 6) + #define IDC_CHECK_HITALIC (IDD_PREFERENCE_PRINT2_BOX + 7) + #define IDC_HGB_STATIC (IDD_PREFERENCE_PRINT2_BOX + 8) + #define IDC_HL_STATIC (IDD_PREFERENCE_PRINT2_BOX + 9) + #define IDC_HM_STATIC (IDD_PREFERENCE_PRINT2_BOX + 10) + #define IDC_HR_STATIC (IDD_PREFERENCE_PRINT2_BOX + 11) + #define IDC_EDIT_FLEFT (IDD_PREFERENCE_PRINT2_BOX + 12) + #define IDC_EDIT_FMIDDLE (IDD_PREFERENCE_PRINT2_BOX + 13) + #define IDC_EDIT_FRIGHT (IDD_PREFERENCE_PRINT2_BOX + 14) + #define IDC_COMBO_FFONTNAME (IDD_PREFERENCE_PRINT2_BOX + 15) + #define IDC_COMBO_FFONTSIZE (IDD_PREFERENCE_PRINT2_BOX + 16) + #define IDC_CHECK_FBOLD (IDD_PREFERENCE_PRINT2_BOX + 17) + #define IDC_CHECK_FITALIC (IDD_PREFERENCE_PRINT2_BOX + 18) + #define IDC_FGB_STATIC (IDD_PREFERENCE_PRINT2_BOX + 19) + #define IDC_FL_STATIC (IDD_PREFERENCE_PRINT2_BOX + 20) + #define IDC_FM_STATIC (IDD_PREFERENCE_PRINT2_BOX + 21) + #define IDC_FR_STATIC (IDD_PREFERENCE_PRINT2_BOX + 22) + #define IDC_BUTTON_ADDVAR (IDD_PREFERENCE_PRINT2_BOX + 23) + #define IDC_COMBO_VARLIST (IDD_PREFERENCE_PRINT2_BOX + 24) + #define IDC_VAR_STATIC (IDD_PREFERENCE_PRINT2_BOX + 25) + #define IDC_VIEWPANEL_STATIC (IDD_PREFERENCE_PRINT2_BOX + 26) + #define IDC_WHICHPART_STATIC (IDD_PREFERENCE_PRINT2_BOX + 27) + + +#define IDD_PREFERENCE_BACKUP_BOX 6800 //(IDD_PREFERENCE_BOX + 800) + #define IDC_BACKUPDIR_GRP_STATIC (IDD_PREFERENCE_BACKUP_BOX + 1) + #define IDC_BACKUPDIR_CHECK (IDD_PREFERENCE_BACKUP_BOX + 2) + #define IDD_BACKUPDIR_STATIC (IDD_PREFERENCE_BACKUP_BOX + 3) + #define IDC_BACKUPDIR_USERCUSTOMDIR_GRPSTATIC (IDD_PREFERENCE_BACKUP_BOX + 4) + #define IDC_BACKUPDIR_EDIT (IDD_PREFERENCE_BACKUP_BOX + 5) + #define IDD_BACKUPDIR_BROWSE_BUTTON (IDD_PREFERENCE_BACKUP_BOX + 6) + #define IDD_AUTOC_GRPSTATIC (IDD_PREFERENCE_BACKUP_BOX + 7) + #define IDD_AUTOC_ENABLECHECK (IDD_PREFERENCE_BACKUP_BOX + 8) + #define IDD_AUTOC_FUNCRADIO (IDD_PREFERENCE_BACKUP_BOX + 9) + #define IDD_AUTOC_WORDRADIO (IDD_PREFERENCE_BACKUP_BOX + 10) + #define IDD_AUTOC_STATIC_FROM (IDD_PREFERENCE_BACKUP_BOX + 11) + #define IDD_AUTOC_STATIC_N (IDD_PREFERENCE_BACKUP_BOX + 12) + #define IDD_AUTOC_STATIC_CHAR (IDD_PREFERENCE_BACKUP_BOX + 13) + #define IDD_AUTOC_STATIC_NOTE (IDD_PREFERENCE_BACKUP_BOX + 14) + #define IDD_FUNC_CHECK (IDD_PREFERENCE_BACKUP_BOX + 15) diff --git a/PowerEditor/src/WinControls/SplitterContainer/Splitter.cpp b/PowerEditor/src/WinControls/SplitterContainer/Splitter.cpp new file mode 100644 index 00000000..75b7b1de --- /dev/null +++ b/PowerEditor/src/WinControls/SplitterContainer/Splitter.cpp @@ -0,0 +1,691 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +#include "Splitter.h" +#include "Common.h" + +bool Splitter::_isHorizontalRegistered = false; +bool Splitter::_isVerticalRegistered = false; +bool Splitter::_isHorizontalFixedRegistered = false; +bool Splitter::_isVerticalFixedRegistered = false; + + +#define SPLITTER_SIZE 8 + +Splitter::Splitter() : Window() +{ + //hInstance = GetModuleHandle(NULL); + _rect.left = 0; // x axis + _rect.top = 0; // y axis + _rect.right = 0; // Width of the spliter. + _rect.bottom = 0; // Height of the spliter + _isFixed = false; +} + + +void Splitter::init( HINSTANCE hInst, HWND hPere, int splitterSize, + int iSplitRatio, DWORD dwFlags) +{ + Window::init(hInst, hPere); + _spiltterSize = splitterSize; + + WNDCLASSEX wcex; + DWORD dwExStyle = 0L; + DWORD dwStyle = WS_CHILD | WS_VISIBLE; + + if (hPere == NULL) + { + ::MessageBox(NULL, TEXT("pas de pere?"), TEXT("Splitter::init"), MB_OK); + throw int(96); + } + if (iSplitRatio < 0) + { + ::MessageBox(NULL, TEXT("it shoulds be 0 < ratio < 100"), TEXT("Splitter::init"), MB_OK); + throw int(96); + } + _hParent = hPere; + _dwFlags = dwFlags; + + if (_dwFlags & SV_FIXED) + { + //Fixed spliter + _isFixed = true; + } + else + { + if (iSplitRatio >= 100) + { + //cant be 100 % or more + ::MessageBox(NULL, TEXT("it shoulds be 0 < ratio < 100"), TEXT("Splitter::init"), MB_OK); + throw int(96); + } + } + + _splitPercent = iSplitRatio; + + wcex.cbSize = sizeof(WNDCLASSEX); + wcex.style = CS_HREDRAW | CS_VREDRAW; + wcex.lpfnWndProc = (WNDPROC)staticWndProc; + wcex.cbClsExtra = 0; + wcex.cbWndExtra = 0; + wcex.hInstance = _hInst; + wcex.hIcon = NULL; + + ::GetClientRect(_hParent, &_rect); + + if (_dwFlags & SV_HORIZONTAL) //Horizontal spliter + { + _rect.top = ((_rect.bottom * _splitPercent)/100); + // y axis determined by the split% of the parent windows height + + _rect.left = 0; + // x axis is always 0 + + _rect.bottom = _spiltterSize; + // the height of the spliter + + // the width of the splitter remains the same as the width of the parent window. + } + else //Vertical spliter + { + // y axis is 0 always + + _rect.left = ((_rect.right * _splitPercent)/100); + // x axis determined by split% of the parent windows width. + + _rect.right = _spiltterSize; + // width of the spliter. + + //height of the spliter remains the same as the height of the parent window + } + + if (!_isFixed) + { + if ((_dwFlags & SV_ENABLERDBLCLK) || (_dwFlags & SV_ENABLELDBLCLK)) + { + wcex.style = wcex.style | CS_DBLCLKS; + // enable mouse double click messages. + } + } + + if (_isFixed) + { + wcex.hCursor = ::LoadCursor(NULL, IDC_ARROW); + // if fixed spliter then choose default cursor type. + if (_dwFlags & SV_HORIZONTAL) + wcex.lpszClassName = TEXT("fxdnsspliter"); + else + wcex.lpszClassName = TEXT("fxdwespliter"); + } + else + { + if (_dwFlags & SV_HORIZONTAL) + { + //double sided arrow pointing north-south as cursor + wcex.hCursor = ::LoadCursor(NULL,IDC_SIZENS); + wcex.lpszClassName = TEXT("nsspliter"); + } + else + { + // double sided arrow pointing east-west as cursor + wcex.hCursor = ::LoadCursor(NULL,IDC_SIZEWE); + wcex.lpszClassName = TEXT("wespliter"); + } + } + + wcex.hbrBackground = (HBRUSH)(COLOR_3DFACE+1); + wcex.lpszMenuName = NULL; + wcex.hIconSm = NULL; + + if ((_dwFlags & SV_HORIZONTAL)&&(!_isHorizontalRegistered)) + { + RegisterClassEx(&wcex); + _isHorizontalRegistered = true; + } + else if (isVertical()&&(!_isVerticalRegistered)) + { + RegisterClassEx(&wcex); + _isVerticalRegistered = true; + } + else if ((_dwFlags & SV_HORIZONTAL)&&(!_isHorizontalFixedRegistered)) + { + RegisterClassEx(&wcex); + _isHorizontalFixedRegistered = true; + } + else if (isVertical()&&(!_isVerticalFixedRegistered)) + { + RegisterClassEx(&wcex); + _isVerticalFixedRegistered = true; + } + + _hSelf = CreateWindowEx( + dwExStyle, + wcex.lpszClassName, + TEXT(""), + dwStyle, + _rect.left, + _rect.top, + _rect.right, + _rect.bottom, + _hParent, + NULL, + _hInst, + (LPVOID)this); + + if (!_hSelf) + { + systemMessage(TEXT("System Err")); + throw int(345); + } + + RECT rc; + getClientRect(rc); + //::GetClientRect(_hParent,&rc); + + _clickZone2TL.left = rc.left; + _clickZone2TL.top = rc.top; + + int clickZoneWidth = getClickZone(WIDTH); + int clickZoneHeight = getClickZone(HEIGHT); + _clickZone2TL.right = clickZoneWidth; + _clickZone2TL.bottom = clickZoneHeight; + + _clickZone2BR.left = rc.right - clickZoneWidth; + _clickZone2BR.top = rc.bottom - clickZoneHeight; + _clickZone2BR.right = clickZoneWidth; + _clickZone2BR.bottom = clickZoneHeight; + + display(); + ::SendMessage(_hParent, WM_RESIZE_CONTAINER, _rect.left, _rect.top); + +} +// determinated by (_dwFlags & SV_VERTICAL) && _splitterSize +int Splitter::getClickZone(WH which) +{ + if (_spiltterSize <= 8) + { + return isVertical()?(which==WIDTH?_spiltterSize:HIEGHT_MINIMAL) + :(which==WIDTH?HIEGHT_MINIMAL:_spiltterSize); + } + else // (_spiltterSize > 8) + { + return isVertical()?(which==WIDTH? 8:15) + :(which==WIDTH?15:8); + } +} + +LRESULT CALLBACK Splitter::staticWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + switch(uMsg) + { + case WM_NCCREATE: + { + Splitter * pSplitter = (Splitter *)((LPCREATESTRUCT)lParam)->lpCreateParams; + pSplitter->_hSelf = hWnd; + ::SetWindowLongPtr(hWnd, GWL_USERDATA, (long)pSplitter); + return TRUE; + } + default: + { + Splitter * pSplitter = (Splitter *)::GetWindowLongPtr(hWnd, GWL_USERDATA); + if (!pSplitter) + return ::DefWindowProc(hWnd, uMsg, wParam, lParam); + + return pSplitter->spliterWndProc(uMsg, wParam, lParam); + } + } +} + +LRESULT CALLBACK Splitter::spliterWndProc(UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + switch (uMsg) + { +/* + case WM_LBUTTONDBLCLK: + { +::MessageBox(NULL, TEXT(""), TEXT(""), MB_OK); + } + return 0; + + case WM_RBUTTONDBLCLK: + { + + } + return 0; + */ + case WM_LBUTTONDOWN: + { + POINT p; + p.x = LOWORD(lParam); + p.y = HIWORD(lParam); + + if ((isInLeftTopZone(p))&&(wParam == MK_LBUTTON)) + { + gotoTopLeft(); + return TRUE; + } + + if ((isInRightBottomZone(p))&&(wParam == MK_LBUTTON)) + { + gotoRightBouuom(); + return TRUE; + } + + if (!_isFixed) + { + ::SetCapture(_hSelf); + _isDraged = true; + } + } + return 0; + + case WM_RBUTTONDOWN : + ::SendMessage(_hParent, WM_DOPOPUPMENU, wParam, lParam); + return TRUE; + + case WM_MOUSEMOVE: + { + POINT p; + p.x = LOWORD(lParam); + p.y = HIWORD(lParam); + + if (isInLeftTopZone(p) || isInRightBottomZone(p)) + { + //::SetCursor(::LoadCursor(_hInst, MAKEINTRESOURCE(IDC_UP_ARROW))); + ::SetCursor(::LoadCursor(NULL, IDC_ARROW)); + return TRUE; + } + + if ((!_isFixed) && (wParam == MK_LBUTTON)) + { + POINT pt; RECT rt; + ::GetClientRect(_hParent, &rt); + + ::GetCursorPos(&pt); + ::ScreenToClient(_hParent, &pt); + + if (_dwFlags & SV_HORIZONTAL) + { + if (pt.y <= 1) + { + _rect.top = 1; + _splitPercent = 1; + } + else + { + if (pt.y <= (rt.bottom - 5)) + { + _rect.top = pt.y; + _splitPercent = ((pt.y * 100 / rt.bottom*100) / 100); + } + else + { + _rect.top = rt.bottom - 5; + _splitPercent = 99; + } + } + } + else + { + if (pt.x <= 1) + { + _rect.left = 1; + _splitPercent = 1; + } + else + { + if (pt.x <= (rt.right - 5)) + { + _rect.left = pt.x; + _splitPercent = ((pt.x*100/rt.right*100)/100); + } + else + { + _rect.left = rt.right - 5; + _splitPercent = 99; + } + } + } + + ::SendMessage(_hParent, WM_RESIZE_CONTAINER, _rect.left, _rect.top); + ::MoveWindow(_hSelf, _rect.left, _rect.top, _rect.right, _rect.bottom, FALSE); + redraw(); + } + return 0; + } + + case WM_LBUTTONUP: + { + if (!_isFixed) + { + ReleaseCapture(); + } + return 0; + } + case WM_CAPTURECHANGED: + { + if (_isDraged) + { + ::SendMessage(_hParent, WM_RESIZE_CONTAINER, _rect.left, _rect.top); + ::MoveWindow(_hSelf, _rect.left, _rect.top, _rect.right, _rect.bottom, TRUE); + _isDraged = false; + } + return 0; + } + + case WM_PAINT : + drawSplitter(); + return 0; + + case WM_CLOSE: + destroy(); + return 0; + } + return ::DefWindowProc(_hSelf, uMsg, wParam, lParam); +} + +void Splitter::resizeSpliter(RECT *pRect) +{ + RECT rect; + + if (pRect) + rect = *pRect; + else + ::GetClientRect(_hParent,&rect); + + if (_dwFlags & SV_HORIZONTAL) + { + // for a Horizontal spliter the width remains the same + // as the width of the parent window, so get the new width of the parent. + _rect.right = rect.right; + + //if resizeing should be done proportionately. + if (_dwFlags & SV_RESIZEWTHPERCNT) + _rect.top = ((rect.bottom * _splitPercent)/100); + else // soit la fenetre en haut soit la fenetre en bas qui est fixee + _rect.top = getSplitterFixPosY(); + } + else + { + // for a (default) Vertical spliter the height remains the same + // as the height of the parent window, so get the new height of the parent. + _rect.bottom = rect.bottom; + + //if resizeing should be done proportionately. + if (_dwFlags & SV_RESIZEWTHPERCNT) + { + _rect.left = ((rect.right * _splitPercent)/100); + } + else // soit la fenetre gauche soit la fenetre droit qui est fixee + _rect.left = getSplitterFixPosX(); + + } + ::MoveWindow(_hSelf, _rect.left, _rect.top, _rect.right, _rect.bottom, TRUE); + ::SendMessage(_hParent, WM_RESIZE_CONTAINER, _rect.left, _rect.top); + + RECT rc; + getClientRect(rc); + _clickZone2BR.right = getClickZone(WIDTH); + _clickZone2BR.bottom = getClickZone(HEIGHT); + _clickZone2BR.left = rc.right - _clickZone2BR.right; + _clickZone2BR.top = rc.bottom - _clickZone2BR.bottom; + + + //force the window to repaint, to make sure the splitter is visible + // in the new position. + redraw(); +} + +void Splitter::gotoTopLeft() +{ + if ((_dwFlags & SV_ENABLELDBLCLK) && (!_isFixed) && (_splitPercent > 1)) + { + if (_dwFlags & SV_HORIZONTAL) + _rect.top = 1; + else + _rect.left = 1; + _splitPercent = 1; + + ::SendMessage(_hParent, WM_RESIZE_CONTAINER, _rect.left, _rect.top); + ::MoveWindow(_hSelf, _rect.left, _rect.top, _rect.right, _rect.bottom, TRUE); + redraw(); + } +} + +void Splitter::gotoRightBouuom() +{ + if ((_dwFlags & SV_ENABLERDBLCLK) && (!_isFixed) && (_splitPercent < 99)) + { + RECT rt; + GetClientRect(_hParent,&rt); + + if (_dwFlags & SV_HORIZONTAL) + _rect.top = rt.bottom - _spiltterSize; + else + _rect.left = rt.right - _spiltterSize; + + _splitPercent = 99; + + ::SendMessage(_hParent, WM_RESIZE_CONTAINER, _rect.left, _rect.top); + ::MoveWindow(_hSelf, _rect.left, _rect.top, _rect.right, _rect.bottom, TRUE); + redraw(); + } +} + +void Splitter::drawSplitter() +{ + PAINTSTRUCT ps; + RECT rc, rcToDraw1, rcToDraw2, TLrc, BRrc; + + HDC hdc = ::BeginPaint(_hSelf, &ps); + getClientRect(rc); + + if ((_spiltterSize >= 4) && (_dwFlags & SV_RESIZEWTHPERCNT)) + { + adjustZoneToDraw(TLrc, TOP_LEFT); + adjustZoneToDraw(BRrc, BOTTOM_RIGHT); + paintArrow(hdc, TLrc, isVertical()?ARROW_LEFT:ARROW_UP); + } + + if (isVertical()) + { + rcToDraw2.top = (_dwFlags & SV_RESIZEWTHPERCNT)?_clickZone2TL.bottom:0; + rcToDraw2.bottom = rcToDraw2.top + 2; + + rcToDraw1.top = rcToDraw2.top + 1; + rcToDraw1.bottom = rcToDraw1.top + 2; + } + else + { + rcToDraw2.top = 1; + rcToDraw2.bottom = 3; + + rcToDraw1.top = 2; + rcToDraw1.bottom = 4; + } + + int bottom = 0; + if (_dwFlags & SV_RESIZEWTHPERCNT) + bottom = (isVertical() ? rc.bottom - _clickZone2BR.bottom : rc.bottom); + else + bottom = rc.bottom; + + while (rcToDraw1.bottom <= bottom) + { + if (isVertical()) + { + rcToDraw2.left = 1; + rcToDraw2.right = 3; + + rcToDraw1.left = 2; + rcToDraw1.right = 4; + } + else + { + rcToDraw2.left = _clickZone2TL.right; + rcToDraw2.right = rcToDraw2.left + 2; + + rcToDraw1.left = rcToDraw2.left; + rcToDraw1.right = rcToDraw1.left + 2; + } + + while (rcToDraw1.right <= (isVertical() ? rc.right : rc.right - _clickZone2BR.right)) + { + ::FillRect(hdc, &rcToDraw1, (HBRUSH)(RGB(0xFF, 0xFF, 0xFF))); + ::FillRect(hdc, &rcToDraw2, (HBRUSH)(COLOR_3DSHADOW+1)); + + rcToDraw2.left += 4; + rcToDraw2.right += 4; + rcToDraw1.left += 4; + rcToDraw1.right += 4; + } + rcToDraw2.top += 4; + rcToDraw2.bottom += 4; + rcToDraw1.top += 4; + rcToDraw1.bottom += 4; + } + + if ((_spiltterSize >= 4) && (_dwFlags & SV_RESIZEWTHPERCNT)) + paintArrow(hdc, BRrc, isVertical()?ARROW_RIGHT:ARROW_DOWN); + + ::EndPaint(_hSelf, &ps); +} + +void Splitter::rotate() +{ + if (!_isFixed) + { + destroy(); + if (_dwFlags & SV_HORIZONTAL) + { + _dwFlags ^= SV_HORIZONTAL; + _dwFlags |= SV_VERTICAL; + } + else //SV_VERTICAL + { + _dwFlags ^= SV_VERTICAL; + _dwFlags |= SV_HORIZONTAL; + } + init(_hInst, _hParent, _spiltterSize, _splitPercent, _dwFlags); + } +} + +void Splitter::paintArrow(HDC hdc, const RECT &rect, Arrow arrowDir) +{ + RECT rc; + rc.left = rect.left; rc.top = rect.top; + rc.right = rect.right; rc.bottom = rect.bottom; + if (arrowDir == ARROW_LEFT) + { + int x = rc.right; + int y = rc.top; + + //::MoveToEx(hdc, x, y, NULL); + for (; (x > rc.left) && (y != rc.bottom) ; x--) + { + ::MoveToEx(hdc, x, y++, NULL); + ::LineTo(hdc, x, rc.bottom--); + } + } + else if (arrowDir == ARROW_RIGHT) + { + int x = rc.left; + int y = rc.top; + + //::MoveToEx(hdc, x, y, NULL); + for (; (x < rc.right) && (y != rc.bottom) ; x++) + { + ::MoveToEx(hdc, x, y++, NULL); + ::LineTo(hdc, x, rc.bottom--); + } + } + else if (arrowDir == ARROW_UP) + { + int x = rc.left; + int y = rc.bottom; + + //::MoveToEx(hdc, x, y, NULL); + for (; (y > rc.top) && (x != rc.right) ; y--) + { + ::MoveToEx(hdc, x++, y, NULL); + ::LineTo(hdc, rc.right--, y); + } + } + else if (arrowDir == ARROW_DOWN) + { + int x = rc.left; + int y = rc.top; + + //::MoveToEx(hdc, x, y, NULL); + for (; (y < rc.bottom) && (x != rc.right) ; y++) + { + ::MoveToEx(hdc, x++, y, NULL); + ::LineTo(hdc, rc.right--, y); + } + } +} +void Splitter::adjustZoneToDraw(RECT & rc2def, ZONE_TYPE whichZone) +{ + if (_spiltterSize < 4) return; + int x0, y0, x1, y1, w, h; + if ((4 <= _spiltterSize) && (_spiltterSize <= 8)) + { + w = (isVertical()?4:7); + h = (isVertical()?7:4); + } + else // (_spiltterSize > 8) + { + w = (isVertical()?6:11); + h = (isVertical()?11:6); + } + + if (isVertical()) + {//w=4 h=7 + if (whichZone == TOP_LEFT) + { + x0 = 0; + y0 = (_clickZone2TL.bottom - h) / 2; + } + else // whichZone == BOTTOM_RIGHT + { + x0 = _clickZone2BR.left + _clickZone2BR.right - w; + y0 = (_clickZone2BR.bottom - h) / 2 + _clickZone2BR.top; + } + x1 = x0 + w; + y1 = y0 + h; + } + else // Horizontal + {//w=7 h=4 + if (whichZone == TOP_LEFT) + { + x0 = (_clickZone2TL.right - w) / 2; + y0 = 0; + } + else // whichZone == BOTTOM_RIGHT + { + x0 = ((_clickZone2BR.right - w) / 2) + _clickZone2BR.left; + y0 = _clickZone2BR.top + _clickZone2BR.bottom - h; + } + x1 = x0 + w; + y1 = y0 + h; + } + rc2def.left = x0; + rc2def.top = y0; + rc2def.right = x1; + rc2def.bottom = y1; +} diff --git a/PowerEditor/src/WinControls/SplitterContainer/Splitter.h b/PowerEditor/src/WinControls/SplitterContainer/Splitter.h new file mode 100644 index 00000000..24a83ee3 --- /dev/null +++ b/PowerEditor/src/WinControls/SplitterContainer/Splitter.h @@ -0,0 +1,117 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef SPLITTER_H +#define SPLITTER_H + +#include +#include "Window.h" +#include "resource.h" + +#define SV_HORIZONTAL 0x00000001 +#define SV_VERTICAL 0x00000002 +#define SV_FIXED 0x00000004 +#define SV_ENABLERDBLCLK 0x00000008 +#define SV_ENABLELDBLCLK 0x00000010 +#define SV_RESIZEWTHPERCNT 0x00000020 + + +#define WM_GETSPLITTER_X (SPLITTER_USER + 1) +#define WM_GETSPLITTER_Y (SPLITTER_USER + 2) +#define WM_DOPOPUPMENU (SPLITTER_USER + 3) +#define WM_RESIZE_CONTAINER (SPLITTER_USER + 4) + +const int HIEGHT_MINIMAL = 15; + +enum Arrow {ARROW_LEFT, ARROW_UP, ARROW_RIGHT, ARROW_DOWN}; + +typedef bool WH; +const bool WIDTH = true; +const bool HEIGHT = false; + +typedef bool ZONE_TYPE; +const bool TOP_LEFT = true; +const bool BOTTOM_RIGHT = false; + +enum SplitterMode { + DYNAMIC, LEFT_FIX, RIGHT_FIX +}; + +class Splitter : public Window +{ +public: + Splitter(); + ~Splitter(){}; + void destroy() { + ::DestroyWindow(_hSelf); + }; + void resizeSpliter(RECT *pRect = NULL); + void init(HINSTANCE hInst, HWND hPere, int splitterSize, + int iSplitRatio, DWORD dwFlags); + void rotate(); + int getPhisicalSize() const { + return _spiltterSize; + }; + +private: + RECT _rect; + int _splitPercent; + int _spiltterSize; + bool _isDraged; + DWORD _dwFlags; + bool _isFixed; + static bool _isHorizontalRegistered; + static bool _isVerticalRegistered; + static bool _isHorizontalFixedRegistered; + static bool _isVerticalFixedRegistered; + + RECT _clickZone2TL, _clickZone2BR; + + static LRESULT CALLBACK staticWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); + LRESULT CALLBACK spliterWndProc(UINT uMsg, WPARAM wParam, LPARAM lParam); + + int getClickZone(WH which); + void adjustZoneToDraw(RECT & rc2def, ZONE_TYPE whichZone); + void drawSplitter(); + bool isVertical() const {return (_dwFlags & SV_VERTICAL) != 0;}; + void paintArrow(HDC hdc, const RECT &rect, Arrow arrowDir); + void gotoTopLeft(); + void gotoRightBouuom(); + + bool isInLeftTopZone(const POINT &p) const { + return (((p.x >= _clickZone2TL.left) && (p.x <= _clickZone2TL.left + _clickZone2TL.right)) && + (p.y >= _clickZone2TL.top) && (p.y <= _clickZone2TL.top + _clickZone2TL.bottom)); + }; + + bool isInRightBottomZone(const POINT &p) const { + return (((p.x >= _clickZone2BR.left) && + (p.x <= _clickZone2BR.left + _clickZone2BR.right)) && + (p.y >= _clickZone2BR.top) && + (p.y <= _clickZone2BR.top + _clickZone2BR.bottom)); + }; + + int getSplitterFixPosX() { + long result = long(::SendMessage(_hParent, WM_GETSPLITTER_X, 0, 0)); + return (LOWORD(result) - ((HIWORD(result) == RIGHT_FIX) ? _spiltterSize : 0)); + }; + + int getSplitterFixPosY() { + long result = long(::SendMessage(_hParent, WM_GETSPLITTER_Y, 0, 0)); + return (LOWORD(result) - ((HIWORD(result) == RIGHT_FIX) ? _spiltterSize : 0)); + }; +}; +#endif // SPLITTER_H diff --git a/PowerEditor/src/WinControls/SplitterContainer/SplitterContainer.cpp b/PowerEditor/src/WinControls/SplitterContainer/SplitterContainer.cpp new file mode 100644 index 00000000..8fdf1dfc --- /dev/null +++ b/PowerEditor/src/WinControls/SplitterContainer/SplitterContainer.cpp @@ -0,0 +1,240 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#include "SplitterContainer.h" +#include "Common.h" + +bool SplitterContainer::_isRegistered = false; + +void SplitterContainer::create(Window *pWin0, Window *pWin1, int splitterSize, + SplitterMode mode, int ratio, bool isVertical) +{ + //Window::init(hInst, parent); + _pWin0 = pWin0; + _pWin1 = pWin1; + _splitterSize = splitterSize; + _splitterMode = mode; + _ratio = ratio; + _dwSplitterStyle |= isVertical?SV_VERTICAL:SV_HORIZONTAL; + if (_splitterMode != DYNAMIC) + { + _dwSplitterStyle |= SV_FIXED; + _dwSplitterStyle &= ~SV_RESIZEWTHPERCNT; + } + if (!_isRegistered) + { + WNDCLASS splitterContainerClass; + + splitterContainerClass.style = 0; + splitterContainerClass.lpfnWndProc = staticWinProc; + splitterContainerClass.cbClsExtra = 0; + splitterContainerClass.cbWndExtra = 0; + splitterContainerClass.hInstance = _hInst; + splitterContainerClass.hIcon = NULL; + splitterContainerClass.hCursor = ::LoadCursor(NULL, IDC_ARROW); + + // hbrBackground must be NULL, + // otherwise this window will hide some parts of 2 windows + splitterContainerClass.hbrBackground = NULL; + splitterContainerClass.lpszMenuName = NULL; + splitterContainerClass.lpszClassName = SPC_CLASS_NAME;//_className; + + if (!::RegisterClass(&splitterContainerClass)) + { + systemMessage(TEXT("System Err")); + throw int(98); + } + _isRegistered = true; + } + + _hSelf = ::CreateWindowEx( + 0, + SPC_CLASS_NAME, + TEXT("a koi sert?"), + WS_CHILD | WS_CLIPCHILDREN, + CW_USEDEFAULT, CW_USEDEFAULT, + CW_USEDEFAULT, CW_USEDEFAULT, + _hParent, + NULL, + _hInst, + (LPVOID)this); + + if (!_hSelf) + { + systemMessage(TEXT("System Err")); + throw int(777); + } +} + +void SplitterContainer::rotateTo(DIRECTION direction) +{ + bool doSwitchWindow = false; + if (_dwSplitterStyle & SV_VERTICAL) + { + _dwSplitterStyle ^= SV_VERTICAL; + _dwSplitterStyle |= SV_HORIZONTAL; + doSwitchWindow = (direction == LEFT); + } + else + { + _dwSplitterStyle ^= SV_HORIZONTAL; + _dwSplitterStyle |= SV_VERTICAL; + doSwitchWindow = (direction == RIGHT); + } + if (doSwitchWindow) + { + Window *tmp = _pWin0; + _pWin0 = _pWin1; + _pWin1 = tmp; + } + _splitter.rotate(); + +} + +LRESULT CALLBACK SplitterContainer::staticWinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + SplitterContainer *pSplitterContainer = NULL; + switch (message) + { + case WM_NCCREATE : + pSplitterContainer = (SplitterContainer *)(((LPCREATESTRUCT)lParam)->lpCreateParams); + pSplitterContainer->_hSelf = hwnd; + ::SetWindowLongPtr(hwnd, GWL_USERDATA, reinterpret_cast(pSplitterContainer)); + return TRUE; + + default : + pSplitterContainer = (SplitterContainer *)::GetWindowLongPtr(hwnd, GWL_USERDATA); + if (!pSplitterContainer) + return ::DefWindowProc(hwnd, message, wParam, lParam); + return pSplitterContainer->runProc(message, wParam, lParam); + } +} + +LRESULT SplitterContainer::runProc(UINT message, WPARAM wParam, LPARAM lParam) +{ + switch (message) + { + case WM_CREATE : + _splitter.init(_hInst, _hSelf, _splitterSize, _ratio, _dwSplitterStyle); + return TRUE; + + case WM_COMMAND : + { + switch (LOWORD(wParam)) + { + case ROTATION_A_GAUCHE: + rotateTo(LEFT); + return TRUE; + case ROTATION_A_DROITE: + rotateTo(RIGHT); + return TRUE; + } + return TRUE; + } + case WM_RESIZE_CONTAINER : + { + RECT rc0, rc1; + getClientRect(rc0); + + rc1.top = rc0.top += _y; + rc1.bottom = rc0.bottom; + rc1.left = rc0.left += _x; + rc1.right = rc0.right; + + if (_dwSplitterStyle & SV_VERTICAL) + { + if (wParam != 0) + { + rc0.right = int(wParam); + + rc1.left = int(wParam) + _x + _splitter.getPhisicalSize(); + rc1.right = rc1.right - rc1.left + _x; + } + } + else //SV_HORIZONTAL + { + if (lParam != 0) + { + rc0.bottom = int(lParam); + + rc1.top = int(lParam) + _y + _splitter.getPhisicalSize(); + rc1.bottom = rc1.bottom - rc1.top + _y; + } + } + _pWin0->reSizeTo(rc0); + _pWin1->reSizeTo(rc1); + + ::InvalidateRect(_splitter.getHSelf(), NULL, TRUE); + return TRUE; + } + + case WM_DOPOPUPMENU : + { + if ((_splitterMode != LEFT_FIX) && (_splitterMode != RIGHT_FIX) ) + { + POINT p; + ::GetCursorPos(&p); + + if (!_hPopupMenu) + { + POINT p; + ::GetCursorPos(&p); + _hPopupMenu = ::CreatePopupMenu(); + ::InsertMenu(_hPopupMenu, 1, MF_BYPOSITION, ROTATION_A_GAUCHE, TEXT("Rotate to left")); + ::InsertMenu(_hPopupMenu, 0, MF_BYPOSITION, ROTATION_A_DROITE, TEXT("Rotate to right")); + } + + ::TrackPopupMenu(_hPopupMenu, TPM_LEFTALIGN, p.x, p.y, 0, _hSelf, NULL); + } + return TRUE; + } + + case WM_GETSPLITTER_X : + { + if (_splitterMode == LEFT_FIX) + return MAKELONG(_pWin0->getWidth(), LEFT_FIX); + else if (_splitterMode == RIGHT_FIX) + { + int x = getWidth()-_pWin1->getWidth(); + if (x < 0) + x = 0; + return MAKELONG(x, RIGHT_FIX); + } + else + return MAKELONG(0, DYNAMIC); + + } + + case WM_GETSPLITTER_Y : + { + if (_splitterMode == LEFT_FIX) + return MAKELONG(_pWin0->getHeight(), LEFT_FIX); + else if (_splitterMode == RIGHT_FIX) + { + int y = getHeight()-_pWin1->getHeight(); + if (y < 0) + y = 0; + return MAKELONG(y, RIGHT_FIX); + } + else + return MAKELONG(0, DYNAMIC); + } + + default : + return ::DefWindowProc(_hSelf, message, wParam, lParam); + } +} diff --git a/PowerEditor/src/WinControls/SplitterContainer/SplitterContainer.h b/PowerEditor/src/WinControls/SplitterContainer/SplitterContainer.h new file mode 100644 index 00000000..92d29c0f --- /dev/null +++ b/PowerEditor/src/WinControls/SplitterContainer/SplitterContainer.h @@ -0,0 +1,101 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef SPLITTER_CONTAINER_H +#define SPLITTER_CONTAINER_H + +#include "Window.h" +#include "Splitter.h" + +#define SPC_CLASS_NAME TEXT("splitterContainer") + +#define ROTATION_A_GAUCHE 2000 +#define ROTATION_A_DROITE 2001 + +typedef bool DIRECTION; +const bool LEFT = true; +const bool RIGHT = false; + + + +class SplitterContainer : public Window +{ +public : + SplitterContainer(): Window(), _x(0), _y(0), _hPopupMenu(NULL), + _dwSplitterStyle(SV_ENABLERDBLCLK | SV_ENABLELDBLCLK | SV_RESIZEWTHPERCNT){ + }; + ~SplitterContainer(){}; + void create(Window *pWin0, Window *pWin1, int splitterSize = 4, + SplitterMode mode = DYNAMIC, int ratio = 50, bool _isVertical = true); + + void destroy() { + if (_hPopupMenu) + ::DestroyMenu(_hPopupMenu); + _splitter.destroy(); + ::DestroyWindow(_hSelf); + }; + void reSizeTo(RECT & rc) { + _x = rc.left; + _y = rc.top; + ::MoveWindow(_hSelf, _x, _y, rc.right, rc.bottom, FALSE); + _splitter.resizeSpliter(); + }; + virtual void display(bool toShow = true) const { + Window::display(toShow); + + _pWin0->display(toShow); + _pWin1->display(toShow); + _splitter.display(toShow); + }; + virtual void redraw() const { + _pWin0->redraw(); + _pWin1->redraw(); + }; + + void setWin0(Window *pWin) { + _pWin0 = pWin; + + }; + + void setWin1(Window *pWin) { + _pWin1 = pWin; + }; + + bool isVertical() const { + return ((_dwSplitterStyle & SV_VERTICAL) != 0); + }; +private : + Window *_pWin0; // left or top window + Window *_pWin1; // right or bottom window + + Splitter _splitter; + int _splitterSize; + int _ratio; + int _x, _y; + HMENU _hPopupMenu; + DWORD _dwSplitterStyle; + + SplitterMode _splitterMode; + static bool _isRegistered; + + static LRESULT CALLBACK staticWinProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam); + LRESULT runProc(UINT Message, WPARAM wParam, LPARAM lParam); + void rotateTo(DIRECTION direction); + +}; + +#endif //SPLITTER_CONTAINER_H diff --git a/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg.cpp b/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg.cpp new file mode 100644 index 00000000..2d08ea66 --- /dev/null +++ b/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg.cpp @@ -0,0 +1,299 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#include "RunDlg.h" +#include "FileDialog.h" +//#include "resource.h" +#include "Notepad_plus_msgs.h" +#include "shortcut.h" +#include "Parameters.h" +#include "Notepad_plus.h" + + +void Command::extractArgs(TCHAR *cmd2Exec, TCHAR *args, const TCHAR *cmdEntier) +{ + int i = 0; + bool quoted = false; + for ( ; i < int(lstrlen(cmdEntier)) ; i++) + { + if ((cmdEntier[i] == ' ') && (!quoted)) + break; + if (cmdEntier[i]=='"') + quoted = !quoted; + + cmd2Exec[i] = cmdEntier[i]; + } + cmd2Exec[i] = '\0'; + + if (i < int(lstrlen(cmdEntier))) + { + for ( ; (i < int(lstrlen(cmdEntier))) && (cmdEntier[i] == ' ') ; i++); + if (i < int(lstrlen(cmdEntier))) + { + for (int k = 0 ; i <= int(lstrlen(cmdEntier)) ; i++, k++) + { + args[k] = cmdEntier[i]; + } + } + + int l = lstrlen(args); + if (args[l-1] == ' ') + { + for (l -= 2 ; (l > 0) && (args[l] == ' ') ; l--); + args[l+1] = '\0'; + } + + } + else + args[0] = '\0'; +} + + +int whichVar(TCHAR *str) +{ + if (!lstrcmp(fullCurrentPath, str)) + return FULL_CURRENT_PATH; + else if (!lstrcmp(currentDirectory, str)) + return CURRENT_DIRECTORY; + else if (!lstrcmp(onlyFileName, str)) + return FILE_NAME; + else if (!lstrcmp(fileNamePart, str)) + return NAME_PART; + else if (!lstrcmp(fileExtPart, str)) + return EXT_PART; + else if (!lstrcmp(currentWord, str)) + return CURRENT_WORD; + else if (!lstrcmp(nppDir, str)) + return NPP_DIRECTORY; + else if (!lstrcmp(currentLine, str)) + return CURRENT_LINE; + else if (!lstrcmp(currentColumn, str)) + return CURRENT_COLUMN; + + return VAR_NOT_RECOGNIZED; +} + +// Since I'm sure the length will be 256, I won't check the lstrlen : watch out! +void expandNppEnvironmentStrs(const TCHAR *strSrc, TCHAR *stringDest, size_t strDestLen, HWND hWnd) +{ + size_t j = 0; + for (int i = 0 ; i < lstrlen(strSrc) ; i++) + { + int iBegin = -1; + int iEnd = -1; + if ((strSrc[i] == '$') && (strSrc[i+1] == '(')) + { + iBegin = i += 2; + for ( ; i < lstrlen(strSrc) ; i++) + { + if (strSrc[i] == ')') + { + iEnd = i - 1; + break; + } + } + } + if (iBegin != -1) + { + if (iEnd != -1) + { + TCHAR str[MAX_PATH]; + int m = 0; + for (int k = iBegin ; k <= iEnd ; k++) + str[m++] = strSrc[k]; + str[m] = '\0'; + + int internalVar = whichVar(str); + if (internalVar == VAR_NOT_RECOGNIZED) + { + i = iBegin - 2; + if (j < (strDestLen-1)) + stringDest[j++] = strSrc[i]; + else + break; + } + else + { + TCHAR expandedStr[CURRENTWORD_MAXLENGTH]; + if (internalVar == CURRENT_LINE || internalVar == CURRENT_COLUMN) + { + int lineNumber = ::SendMessage(hWnd, RUNCOMMAND_USER + internalVar, 0, 0); + wsprintf(expandedStr, TEXT("%d"), lineNumber); + } + else + ::SendMessage(hWnd, RUNCOMMAND_USER + internalVar, CURRENTWORD_MAXLENGTH, (LPARAM)expandedStr); + + for (int p = 0 ; p < lstrlen(expandedStr) ; p++) + { + if (j < (strDestLen-1)) + stringDest[j++] = expandedStr[p]; + else + break; + } + } + } + else + { + i = iBegin - 2; + if (j < (strDestLen-1)) + stringDest[j++] = strSrc[i]; + else + break; + } + } + else + if (j < (strDestLen-1)) + stringDest[j++] = strSrc[i]; + else + break; + } + stringDest[j] = '\0'; +} + +HINSTANCE Command::run(HWND hWnd) +{ + const int argsIntermediateLen = MAX_PATH*2; + const int args2ExecLen = CURRENTWORD_MAXLENGTH+MAX_PATH*2; + + TCHAR cmdPure[MAX_PATH]; + TCHAR cmdIntermediate[MAX_PATH]; + TCHAR cmd2Exec[MAX_PATH]; + TCHAR args[MAX_PATH]; + TCHAR argsIntermediate[argsIntermediateLen]; + TCHAR args2Exec[args2ExecLen]; + + extractArgs(cmdPure, args, _cmdLine.c_str()); + int nbTchar = ::ExpandEnvironmentStrings(cmdPure, cmdIntermediate, MAX_PATH); + if (!nbChar) + lstrcpy(cmdIntermediate, cmdPure); + else if (nbTchar >= MAX_PATH) + cmdIntermediate[MAX_PATH-1] = '\0'; + + nbTchar = ::ExpandEnvironmentStrings(args, argsIntermediate, argsIntermediateLen); + if (!nbChar) + lstrcpy(argsIntermediate, args); + else if (nbTchar >= argsIntermediateLen) + argsIntermediate[argsIntermediateLen-1] = '\0'; + + expandNppEnvironmentStrs(cmdIntermediate, cmd2Exec, MAX_PATH, hWnd); + expandNppEnvironmentStrs(argsIntermediate, args2Exec, args2ExecLen, hWnd); + + HINSTANCE res = ::ShellExecute(hWnd, TEXT("open"), cmd2Exec, args2Exec, TEXT("."), SW_SHOW); + return res; +} + +BOOL CALLBACK RunDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) +{ + switch (message) + { + case WM_COMMAND : + { + switch (wParam) + { + case IDCANCEL : + display(false); + return TRUE; + + case IDOK : + { + TCHAR cmd[MAX_PATH]; + ::GetDlgItemText(_hSelf, IDC_COMBO_RUN_PATH, cmd, MAX_PATH); + _cmdLine = cmd; + + HINSTANCE hInst = run(_hParent); + if (int(hInst) > 32) + { + addTextToCombo(_cmdLine.c_str()); + display(false); + } + else + { + removeTextFromCombo(_cmdLine.c_str()); + } + return TRUE; + } + case IDC_BUTTON_SAVE : + { + std::vector & theUserCmds = (NppParameters::getInstance())->getUserCommandList(); + + int nbCmd = theUserCmds.size(); + + int cmdID = ID_USER_CMD + nbCmd; + TCHAR cmd[MAX_PATH]; + ::GetDlgItemText(_hSelf, IDC_COMBO_RUN_PATH, cmd, MAX_PATH); + UserCommand uc(Shortcut(), cmd, cmdID); + uc.init(_hInst, _hSelf); + + if (uc.doDialog() != -1) + { + HMENU hRunMenu = ::GetSubMenu((HMENU)::SendMessage(_hParent, NPPM_INTERNAL_GETMENU, 0, 0), MENUINDEX_RUN); + int const posBase = 2; + + if (nbCmd == 0) + ::InsertMenu(hRunMenu, posBase - 1, MF_BYPOSITION, (unsigned int)-1, 0); + + theUserCmds.push_back(uc); + ::InsertMenu(hRunMenu, posBase + nbCmd, MF_BYPOSITION, cmdID, uc.toMenuItemString().c_str()); + (NppParameters::getInstance())->getAccelerator()->updateShortcuts(); + } + return TRUE; + } + case IDC_BUTTON_FILE_BROWSER : + { + FileDialog fd(_hSelf, _hInst); + fd.setExtFilter(TEXT("Executable file : "), TEXT(".exe"), TEXT(".com"), TEXT(".cmd"), TEXT(".bat"), NULL); + fd.setExtFilter(TEXT("All files : "), TEXT(".*"), NULL); + + if (const TCHAR *fn = fd.doOpenSingleFileDlg()) + addTextToCombo(fn); + return TRUE; + } + + default : + break; + } + } + } + return FALSE; +} + +void RunDlg::addTextToCombo(const TCHAR *txt2Add) const +{ + HWND handle = ::GetDlgItem(_hSelf, IDC_COMBO_RUN_PATH); + int i = ::SendMessage(handle, CB_FINDSTRINGEXACT, (WPARAM)-1, (LPARAM)txt2Add); + if (i == CB_ERR) + i = ::SendMessage(handle, CB_ADDSTRING, 0, (LPARAM)txt2Add); + ::SendMessage(handle, CB_SETCURSEL, i, 0); +} +void RunDlg::removeTextFromCombo(const TCHAR *txt2Remove) const +{ + HWND handle = ::GetDlgItem(_hSelf, IDC_COMBO_RUN_PATH); + int i = ::SendMessage(handle, CB_FINDSTRINGEXACT, (WPARAM)-1, (LPARAM)txt2Remove); + if (i == CB_ERR) + return; + ::SendMessage(handle, CB_DELETESTRING, i, 0); +} + +void RunDlg::doDialog(bool isRTL) +{ + if (!isCreated()) + create(IDD_RUN_DLG, isRTL); + + // Adjust the position in the center + goToCenter(); + ::SetFocus(::GetDlgItem(_hSelf, IDC_COMBO_RUN_PATH)); +}; diff --git a/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg.h b/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg.h new file mode 100644 index 00000000..e21911f8 --- /dev/null +++ b/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg.h @@ -0,0 +1,77 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef RUN_DLG_H +#define RUN_DLG_H + +#include "StaticDialog.h" +#include "RunDlg_rc.h" +#include +#include "Common.h" + +//static void extractArgs(TCHAR *cmd2Exec, TCHAR *args, const TCHAR *cmdEntier); + +using namespace std; + +#define CURRENTWORD_MAXLENGTH 2048 + +const TCHAR fullCurrentPath[] = TEXT("FULL_CURRENT_PATH"); +const TCHAR currentDirectory[] = TEXT("CURRENT_DIRECTORY"); +const TCHAR onlyFileName[] = TEXT("FILE_NAME"); +const TCHAR fileNamePart[] = TEXT("NAME_PART"); +const TCHAR fileExtPart[] = TEXT("EXT_PART"); +const TCHAR currentWord[] = TEXT("CURRENT_WORD"); +const TCHAR nppDir[] = TEXT("NPP_DIRECTORY"); +const TCHAR currentLine[] = TEXT("CURRENT_LINE"); +const TCHAR currentColumn[] = TEXT("CURRENT_COLUMN"); + +int whichVar(TCHAR *str); +void expandNppEnvironmentStrs(const TCHAR *strSrc, TCHAR *stringDest, size_t strDestLen, HWND hWnd); + +class Command { +public : + Command(){}; + Command(TCHAR *cmd) : _cmdLine(cmd){}; + Command(generic_string cmd) : _cmdLine(cmd){}; + HINSTANCE run(HWND hWnd); + +protected : + generic_string _cmdLine; +private : + void extractArgs(TCHAR *cmd2Exec, TCHAR *args, const TCHAR *cmdEntier); +}; + +class RunDlg : public Command, public StaticDialog +{ +public : + RunDlg() : StaticDialog() {}; + + void doDialog(bool isRTL = false); + + virtual void destroy() { + + }; + +protected : + virtual BOOL CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam); + +private : + void addTextToCombo(const TCHAR *txt2Add) const; + void removeTextFromCombo(const TCHAR *txt2Remove) const; +}; + +#endif //RUN_DLG_H diff --git a/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg.rc b/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg.rc new file mode 100644 index 00000000..23dcedc2 --- /dev/null +++ b/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg.rc @@ -0,0 +1,43 @@ +/* +this file is part of notepad++ +Copyright (C)2003 Don HO < donho@altern.org > + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + + +#include +#include "RunDlg_rc.h" + +#ifndef IDC_STATIC +#define IDC_STATIC -1 +#endif + +IDD_RUN_DLG DIALOGEX 0, 0, 196, 100 +STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | + WS_SYSMENU +EXSTYLE WS_EX_TOOLWINDOW +CAPTION "Run..." +FONT 8, TEXT("MS Shell Dlg"), 400, 0, 0x1 +BEGIN + DEFPUSHBUTTON "Run!",IDOK,16,74,47,14 + PUSHBUTTON "Cancel",IDCANCEL, 121,74,48,14 + PUSHBUTTON "...",IDC_BUTTON_FILE_BROWSER,154,30,16,14 + COMBOBOX IDC_COMBO_RUN_PATH,14,31,136,71,CBS_DROPDOWN | + CBS_AUTOHSCROLL | CBS_SORT | WS_VSCROLL | WS_TABSTOP + GROUPBOX "Type your program to run here",IDC_MAINTEXT_STATIC,7,10, + 172,49,BS_CENTER + PUSHBUTTON "Save...",IDC_BUTTON_SAVE,68,74,50,14 +END diff --git a/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg_rc.h b/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg_rc.h new file mode 100644 index 00000000..1a44f317 --- /dev/null +++ b/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg_rc.h @@ -0,0 +1,5 @@ +#define IDD_RUN_DLG 1900 +#define IDC_BUTTON_FILE_BROWSER (IDD_RUN_DLG + 1) +#define IDC_COMBO_RUN_PATH (IDD_RUN_DLG + 2) +#define IDC_MAINTEXT_STATIC (IDD_RUN_DLG + 3) +#define IDC_BUTTON_SAVE (IDD_RUN_DLG + 4) diff --git a/PowerEditor/src/WinControls/StaticDialog/StaticDialog.cpp b/PowerEditor/src/WinControls/StaticDialog/StaticDialog.cpp new file mode 100644 index 00000000..9544f19f --- /dev/null +++ b/PowerEditor/src/WinControls/StaticDialog/StaticDialog.cpp @@ -0,0 +1,168 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#include "StaticDialog.h" +#include "Common.h" + +void StaticDialog::goToCenter() +{ + RECT rc; + ::GetClientRect(_hParent, &rc); + POINT center; + center.x = rc.left + (rc.right - rc.left)/2; + center.y = rc.top + (rc.bottom - rc.top)/2; + ::ClientToScreen(_hParent, ¢er); + + int x = center.x - (_rc.right - _rc.left)/2; + int y = center.y - (_rc.bottom - _rc.top)/2; + + ::SetWindowPos(_hSelf, HWND_TOP, x, y, _rc.right - _rc.left, _rc.bottom - _rc.top, SWP_SHOWWINDOW); +} + + +void StaticDialog::display(bool toShow) const +{ + if (toShow) { + // If the user has switched from a dual monitor to a single monitor since we last + // displayed the dialog, then ensure that it's still visible on the single monitor. + RECT workAreaRect, rc; + ::SystemParametersInfo(SPI_GETWORKAREA, 0, &workAreaRect, 0); + ::GetWindowRect(_hSelf, &rc); + int newLeft = rc.left; + int newTop = rc.top; + int margin = ::GetSystemMetrics(SM_CYSMCAPTION); + if (newLeft > ::GetSystemMetrics(SM_CXVIRTUALSCREEN)-margin) + newLeft -= rc.right - workAreaRect.right; + if (newLeft + (rc.right - rc.left) < ::GetSystemMetrics(SM_XVIRTUALSCREEN)+margin) + newLeft = workAreaRect.left; + if (newTop > ::GetSystemMetrics(SM_CYVIRTUALSCREEN)-margin) + newTop -= rc.bottom - workAreaRect.bottom; + if (newTop + (rc.bottom - rc.top) < ::GetSystemMetrics(SM_YVIRTUALSCREEN)+margin) + newTop = workAreaRect.top; + + if ((newLeft != rc.left) || (newTop != rc.top)) // then the virtual screen size has shrunk + // Remember that MoveWindow wants width/height. + ::MoveWindow(_hSelf, newLeft, newTop, rc.right - rc.left, rc.bottom - rc.top, TRUE); + } + + Window::display(toShow); +} + + +HGLOBAL StaticDialog::makeRTLResource(int dialogID, DLGTEMPLATE **ppMyDlgTemplate) +{ + // Get Dlg Template resource + HRSRC hDialogRC = ::FindResource(_hInst, MAKEINTRESOURCE(dialogID), RT_DIALOG); + HGLOBAL hDlgTemplate = ::LoadResource(_hInst, hDialogRC); + DLGTEMPLATE *pDlgTemplate = (DLGTEMPLATE *)::LockResource(hDlgTemplate); + + // Duplicate Dlg Template resource + unsigned long sizeDlg = ::SizeofResource(_hInst, hDialogRC); + HGLOBAL hMyDlgTemplate = ::GlobalAlloc(GPTR, sizeDlg); + *ppMyDlgTemplate = (DLGTEMPLATE *)::GlobalLock(hMyDlgTemplate); + + ::memcpy(*ppMyDlgTemplate, pDlgTemplate, sizeDlg); + + DLGTEMPLATEEX *pMyDlgTemplateEx = (DLGTEMPLATEEX *)*ppMyDlgTemplate; + if (pMyDlgTemplateEx->signature == 0xFFFF) + pMyDlgTemplateEx->exStyle |= WS_EX_LAYOUTRTL; + else + (*ppMyDlgTemplate)->dwExtendedStyle |= WS_EX_LAYOUTRTL; + + return hMyDlgTemplate; +} + +void StaticDialog::create(int dialogID, bool isRTL) +{ + if (isRTL) + { + DLGTEMPLATE *pMyDlgTemplate = NULL; + HGLOBAL hMyDlgTemplate = makeRTLResource(dialogID, &pMyDlgTemplate); + _hSelf = ::CreateDialogIndirectParam(_hInst, pMyDlgTemplate, _hParent, (DLGPROC)dlgProc, (LPARAM)this); + ::GlobalFree(hMyDlgTemplate); + } + else + _hSelf = ::CreateDialogParam(_hInst, MAKEINTRESOURCE(dialogID), _hParent, (DLGPROC)dlgProc, (LPARAM)this); + + if (!_hSelf) + { + //systemMessage(TEXT("StaticDialog")); + //throw int(666); + return; + } + + ::SendMessage(_hParent, NPPM_MODELESSDIALOG, MODELESSDIALOGADD, (WPARAM)_hSelf); +} + +BOOL CALLBACK StaticDialog::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + switch (message) + { + case WM_INITDIALOG : + { + StaticDialog *pStaticDlg = (StaticDialog *)(lParam); + pStaticDlg->_hSelf = hwnd; + ::SetWindowLongPtr(hwnd, GWL_USERDATA, (long)lParam); + ::GetWindowRect(hwnd, &(pStaticDlg->_rc)); + pStaticDlg->run_dlgProc(message, wParam, lParam); + + return TRUE; + } + + default : + { + StaticDialog *pStaticDlg = reinterpret_cast(::GetWindowLongPtr(hwnd, GWL_USERDATA)); + if (!pStaticDlg) + return FALSE; + return pStaticDlg->run_dlgProc(message, wParam, lParam); + } + } +} + +void StaticDialog::alignWith(HWND handle, HWND handle2Align, PosAlign pos, POINT & point) +{ + RECT rc, rc2; + ::GetWindowRect(handle, &rc); + + point.x = rc.left; + point.y = rc.top; + + switch (pos) + { + case ALIGNPOS_LEFT : + ::GetWindowRect(handle2Align, &rc2); + point.x -= rc2.right - rc2.left; + break; + + case ALIGNPOS_RIGHT : + ::GetWindowRect(handle, &rc2); + point.x += rc2.right - rc2.left; + break; + + case ALIGNPOS_TOP : + ::GetWindowRect(handle2Align, &rc2); + point.y -= rc2.bottom - rc2.top; + break; + + default : //ALIGNPOS_BOTTOM + ::GetWindowRect(handle, &rc2); + point.y += rc2.bottom - rc2.top; + break; + } + + ::ScreenToClient(_hSelf, &point); +} diff --git a/PowerEditor/src/WinControls/StaticDialog/StaticDialog.h b/PowerEditor/src/WinControls/StaticDialog/StaticDialog.h new file mode 100644 index 00000000..9b42e1ff --- /dev/null +++ b/PowerEditor/src/WinControls/StaticDialog/StaticDialog.h @@ -0,0 +1,89 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef STATIC_DIALOG_H +#define STATIC_DIALOG_H + +//#include "resource.h" +#include "Window.h" +#include "Notepad_plus_msgs.h" + +#include + +typedef HRESULT (WINAPI * ETDTProc) (HWND, DWORD); + +enum PosAlign{ALIGNPOS_LEFT, ALIGNPOS_RIGHT, ALIGNPOS_TOP, ALIGNPOS_BOTTOM}; + +struct DLGTEMPLATEEX { + WORD dlgVer; + WORD signature; + DWORD helpID; + DWORD exStyle; + DWORD style; + WORD cDlgItems; + short x; + short y; + short cx; + short cy; + // The structure has more fields but are variable length +} ; + +class StaticDialog : public Window +{ +public : + StaticDialog() : Window() {}; + ~StaticDialog(){ + if (isCreated()) { + ::SetWindowLongPtr(_hSelf, GWL_USERDATA, (long)NULL); //Prevent run_dlgProc from doing anything, since its virtual + destroy(); + } + }; + virtual void create(int dialogID, bool isRTL = false); + + virtual bool isCreated() const { + return (_hSelf != NULL); + }; + + void goToCenter(); + + void display(bool toShow = true) const; + + POINT getLeftTopPoint(HWND hwnd/*, POINT & p*/) const { + RECT rc; + ::GetWindowRect(hwnd, &rc); + POINT p; + p.x = rc.left; + p.y = rc.top; + ::ScreenToClient(_hSelf, &p); + return p; + }; + + void destroy() { + ::SendMessage(_hParent, NPPM_MODELESSDIALOG, MODELESSDIALOGREMOVE, (WPARAM)_hSelf); + ::DestroyWindow(_hSelf); + }; + +protected : + RECT _rc; + static BOOL CALLBACK dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); + virtual BOOL CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) = 0; + + void alignWith(HWND handle, HWND handle2Align, PosAlign pos, POINT & point); + HGLOBAL makeRTLResource(int dialogID, DLGTEMPLATE **ppMyDlgTemplate); +}; + +#endif //STATIC_DIALOG_H diff --git a/PowerEditor/src/WinControls/StatusBar/StatusBar.cpp b/PowerEditor/src/WinControls/StatusBar/StatusBar.cpp new file mode 100644 index 00000000..b8897f4b --- /dev/null +++ b/PowerEditor/src/WinControls/StatusBar/StatusBar.cpp @@ -0,0 +1,77 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#include "StatusBar.h" +#include "Common.h" + +//#define IDC_STATUSBAR 789 + +const int defaultPartWidth = 5; + +void StatusBar::init(HINSTANCE hInst, HWND hPere, int nbParts) +{ + Window::init(hInst, hPere); + InitCommonControls(); + + _hSelf = //CreateStatusWindow(WS_CHILD | WS_CLIPSIBLINGS, NULL, _hParent, IDC_STATUSBAR); + ::CreateWindowEx( + 0, + STATUSCLASSNAME, + TEXT(""), + WS_CHILD | SBARS_SIZEGRIP , + 0, 0, 0, 0, + _hParent, + NULL, + _hInst, + 0); + + if (!_hSelf) + { + systemMessage(TEXT("System Err")); + throw int(9); + } + + _nbParts = nbParts; + _partWidthArray = new int[_nbParts]; + + // Set the default width + for (int i = 0 ; i < _nbParts ; i++) + _partWidthArray[i] = defaultPartWidth; + + // Allocate an array for holding the right edge coordinates. + _hloc = ::LocalAlloc(LHND, sizeof(int) * _nbParts); + _lpParts = (LPINT)::LocalLock(_hloc); + + RECT rc; + ::GetClientRect(_hParent, &rc); + adjustParts(rc.right); +} + +void StatusBar::adjustParts(int clientWidth) +{ + // Calculate the right edge coordinate for each part, and + // copy the coordinates to the array. + int nWidth = clientWidth - 20; + for (int i = _nbParts - 1 ; i >= 0 ; i--) + { + _lpParts[i] = nWidth; + nWidth -= _partWidthArray[i]; + } + + // Tell the status bar to create the window parts. + ::SendMessage(_hSelf, SB_SETPARTS, (WPARAM)_nbParts, (LPARAM)_lpParts); +} diff --git a/PowerEditor/src/WinControls/StatusBar/StatusBar.h b/PowerEditor/src/WinControls/StatusBar/StatusBar.h new file mode 100644 index 00000000..321bebba --- /dev/null +++ b/PowerEditor/src/WinControls/StatusBar/StatusBar.h @@ -0,0 +1,84 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef STATUS_BAR_H +#define STATUS_BAR_H +#include "Window.h" + +#ifndef _WIN32_IE +#define _WIN32_IE 0x0600 +#endif //_WIN32_IE + +#include + +class StatusBar : public Window +{ +public : + StatusBar() : Window(), _partWidthArray(NULL), _hloc(NULL), _lpParts(NULL) {}; + virtual ~StatusBar(){ + if (_hloc) + { + ::LocalUnlock(_hloc); + ::LocalFree(_hloc); + } + if (_partWidthArray) + delete [] _partWidthArray; + }; + + virtual void init(HINSTANCE hInst, HWND hPere, int nbParts); + + bool setPartWidth(int whichPart, int width) { + if (whichPart >= _nbParts) + return false; + + _partWidthArray[whichPart] = width; + return true; + }; + virtual void destroy() { + ::DestroyWindow(_hSelf); + }; + + virtual void reSizeTo(RECT & rc) { + ::MoveWindow(_hSelf, rc.left, rc.top, rc.right, rc.bottom, TRUE); + adjustParts(rc.right); + redraw(); + }; + + + int getHeight() const { + if (!::IsWindowVisible(_hSelf)) + return 0; + return Window::getHeight(); + }; + + bool setText(const TCHAR *str, int whichPart) const { + if (whichPart > _nbParts) + return false; + return (::SendMessage(_hSelf, SB_SETTEXT, whichPart, (LPARAM)str) == TRUE); + }; + + void adjustParts(int clientWidth); + +private : + int _nbParts; + int *_partWidthArray; + + HLOCAL _hloc; + LPINT _lpParts; +}; + +#endif // STATUS_BAR_H diff --git a/PowerEditor/src/WinControls/TabBar/ControlsTab.cpp b/PowerEditor/src/WinControls/TabBar/ControlsTab.cpp new file mode 100644 index 00000000..ec8e77be --- /dev/null +++ b/PowerEditor/src/WinControls/TabBar/ControlsTab.cpp @@ -0,0 +1,71 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +#include "ControlsTab.h" +/* +void ControlsTab::init(HINSTANCE hInst, HWND hwnd, bool isVertical, WindowVector & winVector) +{ + _isVertical = isVertical; + _pWinVector = &winVector; + + TabBar::init(hInst, hwnd, false, true); + for (int i = 0 ; i < winVector.size() ; i++) + TabBar::insertAtEnd(winVector[i]._name); + + TabBar::activateAt(0); + activateWindowAt(0); +} +*/ + + +void ControlsTab::createTabs(WindowVector & winVector) +{ + _pWinVector = &winVector; + + for (int i = 0 ; i < int(winVector.size()) ; i++) + TabBar::insertAtEnd(winVector[i]._name); + + TabBar::activateAt(0); + activateWindowAt(0); +} + +void ControlsTab::reSizeTo(RECT & rc) +{ + TabBar::reSizeTo(rc); + rc.left += marge; + rc.top += marge; + + //-- We do those dirty things + //-- because it's a "vertical" tab control + if (_isVertical) + { + rc.right -= 40; + rc.bottom -= 20; + if (getRowCount() == 2) + { + rc.right -= 20; + } + } + //-- end of dirty things + rc.bottom -= 55; + rc.right -= 20; + + (*_pWinVector)[_current]._dlg->reSizeTo(rc); + (*_pWinVector)[_current]._dlg->redraw(); + +}; diff --git a/PowerEditor/src/WinControls/TabBar/ControlsTab.h b/PowerEditor/src/WinControls/TabBar/ControlsTab.h new file mode 100644 index 00000000..eff6a718 --- /dev/null +++ b/PowerEditor/src/WinControls/TabBar/ControlsTab.h @@ -0,0 +1,110 @@ +/* +this file is part of notepad++ +Copyright (C)2003 Don HO + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef CONTROLS_TAB_H +#define CONTROLS_TAB_H + +#include "TabBar.h" +#include "StaticDialog.h" +//#include "SplitterContainer.h" +#include + +struct DlgInfo { + Window *_dlg; + TCHAR _name[64]; + TCHAR _internalName[32]; + + DlgInfo(Window *dlg, TCHAR *name, TCHAR *internalName = NULL): _dlg(dlg) { + lstrcpy(_name, name); + if (!internalName) + _internalName[0] = '\0'; + else + lstrcpy(_internalName, internalName); + }; +}; + +typedef std::vector WindowVector; + +class ControlsTab : public TabBar +{ +public : + ControlsTab() : TabBar(), _pWinVector(NULL), _current(0), _isVertical(false) {}; + ~ControlsTab(){}; + //void init(HINSTANCE hInst, HWND pere, bool isVertical, WindowVector & winVector); + virtual void init(HINSTANCE hInst, HWND hwnd, bool isVertical = false, bool isTraditional = false, bool isMultiLine = false) { + _isVertical = isVertical; + //TabBar::init(hInst, hwnd, false, true); + TabBar::init(hInst, hwnd, false, isTraditional, isMultiLine); + }; + void ControlsTab::createTabs(WindowVector & winVector); + + void destroy() { + TabBar::destroy(); + }; + + virtual void reSizeTo(RECT & rc); + + void activateWindowAt(int index) + { + if (index == _current) return; + (*_pWinVector)[_current]._dlg->display(false); + (*_pWinVector)[index]._dlg->display(true); + _current = index; + }; + + void clickedUpdate() + { + int indexClicked = int(::SendMessage(_hSelf, TCM_GETCURSEL, 0, 0)); + activateWindowAt(indexClicked); + }; + + void renameTab(int index, const TCHAR *newName) { + TCITEM tie; + tie.mask = TCIF_TEXT; + tie.pszText = (TCHAR *)newName; + TabCtrl_SetItem(_hSelf, index, &tie); + }; + + bool renameTab(const TCHAR *internalName, const TCHAR *newName) { + bool foundIt = false; + size_t i = 0; + for ( ; i < _pWinVector->size() ; i++) + { + if (!lstrcmp((*_pWinVector)[i]._internalName, internalName)) + { + foundIt = true; + break; + } + } + if (!foundIt) + return false; + + renameTab(i, newName); + return true; + }; + +private : + WindowVector *_pWinVector; + int _current; + bool _isVertical; +}; + + + +#endif //CONTROLS_TAB_H diff --git a/PowerEditor/src/WinControls/TabBar/TabBar.cpp b/PowerEditor/src/WinControls/TabBar/TabBar.cpp new file mode 100644 index 00000000..fe0a5159 --- /dev/null +++ b/PowerEditor/src/WinControls/TabBar/TabBar.cpp @@ -0,0 +1,810 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#include "TabBar.h" +#include "Common.h" + +const COLORREF blue = RGB(0, 0, 0xFF); +const COLORREF black = RGB(0, 0, 0); +const COLORREF white = RGB(0xFF, 0xFF, 0xFF); +const COLORREF grey = RGB(128, 128, 128); + +#define IDC_DRAG_TAB 1404 +#define IDC_DRAG_INTERDIT_TAB 1405 +#define IDC_DRAG_PLUS_TAB 1406 +#define IDC_DRAG_OUT_TAB 1407 + +bool TabBarPlus::_doDragNDrop = false; + +bool TabBarPlus::_drawTopBar = true; +bool TabBarPlus::_drawInactiveTab = true; +bool TabBarPlus::_drawTabCloseButton = false; +bool TabBarPlus::_isDbClk2Close = false; +bool TabBarPlus::_isCtrlVertical = false; +bool TabBarPlus::_isCtrlMultiLine = false; + +COLORREF TabBarPlus::_activeTextColour = ::GetSysColor(COLOR_BTNTEXT); +COLORREF TabBarPlus::_activeTopBarFocusedColour = RGB(250, 170, 60); +COLORREF TabBarPlus::_activeTopBarUnfocusedColour = RGB(250, 210, 150); +COLORREF TabBarPlus::_inactiveTextColour = grey; +COLORREF TabBarPlus::_inactiveBgColour = RGB(192, 192, 192); + +HWND TabBarPlus::_hwndArray[nbCtrlMax] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}; +int TabBarPlus::_nbCtrl = 0; + +void TabBar::init(HINSTANCE hInst, HWND parent, bool isVertical, bool isTraditional, bool isMultiLine) +{ + Window::init(hInst, parent); + int vertical = isVertical?(TCS_VERTICAL | TCS_MULTILINE | TCS_RIGHTJUSTIFY):0; + _isTraditional = isTraditional; + _isVertical = isVertical; + _isMultiLine = isMultiLine; + + INITCOMMONCONTROLSEX icce; + icce.dwSize = sizeof(icce); + icce.dwICC = ICC_TAB_CLASSES; + InitCommonControlsEx(&icce); + int multiLine = isMultiLine?(_isTraditional?TCS_MULTILINE:0):0; + + int style = WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE |\ + /* WS_BORDER |*/TCS_FOCUSNEVER | TCS_TABS | vertical | multiLine; + + _hSelf = ::CreateWindowEx( + 0/*TCS_EX_FLATSEPARATORS*/ , + WC_TABCONTROL, + TEXT("Tab"), + style, + 0, 0, 0, 0, + _hParent, + NULL, + _hInst, + 0); + + if (!_hSelf) + { + systemMessage(TEXT("System Err")); + throw int(69); + } +} + +int TabBar::insertAtEnd(const TCHAR *subTabName) +{ + TCITEM tie; + tie.mask = TCIF_TEXT | TCIF_IMAGE; + int index = -1; + + if (_hasImgLst) + index = 0; + tie.iImage = index; + tie.pszText = (TCHAR *)subTabName; + return int(::SendMessage(_hSelf, TCM_INSERTITEM, _nbItem++, reinterpret_cast(&tie))); +} + +void TabBar::getCurrentTitle(TCHAR *title, int titleLen) +{ + TCITEM tci; + tci.mask = TCIF_TEXT; + tci.pszText = title; + tci.cchTextMax = titleLen-1; + ::SendMessage(_hSelf, TCM_GETITEM, getCurrentTabIndex(), reinterpret_cast(&tci)); +} + +void TabBar::deletItemAt(int index) { + if ((index == _nbItem-1)) { + //prevent invisible tabs. If last visible tab is removed, other tabs are put in view but not redrawn + //Therefore, scroll one tab to the left if only one tab visible + if (_nbItem > 1) { + RECT itemRect; + ::SendMessage(_hSelf, TCM_GETITEMRECT, (WPARAM)index, (LPARAM)&itemRect); + if (itemRect.left < 5) { //if last visible tab, scroll left once (no more than 5px away should be safe, usually 2px depending on the drawing) + //To scroll the tab control to the left, use the WM_HSCROLL notification + //Doesn't really seem to be documented anywhere, but the values do match the message parameters + //The up/down control really is just some sort of scrollbar + //There seems to be no negative effect on any internal state of the tab control or the up/down control + int wParam = MAKEWPARAM(SB_THUMBPOSITION, index - 1); + ::SendMessage(_hSelf, WM_HSCROLL, wParam, 0); + + wParam = MAKEWPARAM(SB_ENDSCROLL, index - 1); + ::SendMessage(_hSelf, WM_HSCROLL, wParam, 0); + } + } + } + ::SendMessage(_hSelf, TCM_DELETEITEM, index, 0); + _nbItem--; + }; + +void TabBar::reSizeTo(RECT & rc2Ajust) +{ + RECT RowRect; + int RowCount, TabsLength; + + // Important to do that! + // Otherwise, the window(s) it contains will take all the resouce of CPU + // We don't need to resize the contained windows if they are even invisible anyway + display(rc2Ajust.right > 10); + RECT rc = rc2Ajust; + Window::reSizeTo(rc); + //TabCtrl_AdjustRect(_hSelf, FALSE, &rc2Ajust); + + // Do our own calculations because TabCtrl_AdjustRect doesn't work + // on vertical or multi-lined tab controls + + RowCount = TabCtrl_GetRowCount(_hSelf); + TabCtrl_GetItemRect(_hSelf, 0, &RowRect); + if (_isTraditional) + { + TabCtrl_AdjustRect(_hSelf, FALSE, &rc2Ajust); + } + else if (_isVertical) + { + TabsLength = RowCount * (RowRect.right - RowRect.left); + TabsLength += GetSystemMetrics(SM_CXEDGE); + + rc2Ajust.left += TabsLength + 5; + rc2Ajust.right -= TabsLength + 10; + rc2Ajust.top += 5; + rc2Ajust.bottom -= 10; + } + else + { + TabsLength = RowCount * (RowRect.bottom - RowRect.top); + TabsLength += GetSystemMetrics(SM_CYEDGE); + + rc2Ajust.top += TabsLength + 5; + rc2Ajust.bottom -= TabsLength + 10; + rc2Ajust.left += 5; + rc2Ajust.right -= 10; + } +} + +void TabBarPlus::init(HINSTANCE hInst, HWND parent, bool isVertical, bool isTraditional, bool isMultiLine) +{ + Window::init(hInst, parent); + int vertical = isVertical?(TCS_VERTICAL | TCS_MULTILINE | TCS_RIGHTJUSTIFY):0; + _isTraditional = isTraditional; + _isVertical = isVertical; + _isMultiLine = isMultiLine; + + INITCOMMONCONTROLSEX icce; + icce.dwSize = sizeof(icce); + icce.dwICC = ICC_TAB_CLASSES; + InitCommonControlsEx(&icce); + int multiLine = isMultiLine?(_isTraditional?TCS_MULTILINE:0):0; + + int style = WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE |\ + TCS_TOOLTIPS | TCS_FOCUSNEVER | TCS_TABS | vertical | multiLine; + + //if (isOwnerDrawTab() && (!_isTraditional)) + { + style |= TCS_OWNERDRAWFIXED; + //printStr(TEXT("ownerDraw")); + } + _hSelf = ::CreateWindowEx( + /*TCS_EX_FLATSEPARATORS */0, + WC_TABCONTROL, + TEXT("Tab"), + style, + 0, 0, 0, 0, + _hParent, + NULL, + _hInst, + 0); + + if (!_hSelf) + { + systemMessage(TEXT("System Err")); + throw int(69); + } + if (!_isTraditional) + { + if (!_hwndArray[_nbCtrl]) + { + _hwndArray[_nbCtrl] = _hSelf; + _ctrlID = _nbCtrl; + } + else + { + int i = 0; + bool found = false; + for ( ; i < nbCtrlMax && !found ; i++) + if (!_hwndArray[i]) + found = true; + if (!found) + { + _ctrlID = -1; + ::MessageBox(NULL, TEXT("The nb of Tab Control is over its limit"), TEXT("Tab Control err"), MB_OK); + destroy(); + throw int(96); + } + _hwndArray[i] = _hSelf; + _ctrlID = i; + } + _nbCtrl++; + + ::SetWindowLongPtr(_hSelf, GWL_USERDATA, reinterpret_cast(this)); + _tabBarDefaultProc = reinterpret_cast(::SetWindowLongPtr(_hSelf, GWL_WNDPROC, reinterpret_cast(TabBarPlus_Proc))); + } + + LOGFONT LogFont; + + _hFont = (HFONT)::SendMessage(_hSelf, WM_GETFONT, 0, 0); + + if (_hFont == NULL) + _hFont = (HFONT)::GetStockObject(DEFAULT_GUI_FONT); + + if (_hLargeFont == NULL) + _hLargeFont = (HFONT)::GetStockObject(SYSTEM_FONT); + + if (::GetObject(_hFont, sizeof(LOGFONT), &LogFont) != 0) + { + LogFont.lfEscapement = 900; + LogFont.lfOrientation = 900; + _hVerticalFont = CreateFontIndirect(&LogFont); + + LogFont.lfWeight = 900; + _hVerticalLargeFont = CreateFontIndirect(&LogFont); + } +} + +LRESULT TabBarPlus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) +{ + switch (Message) + { + // Custom window message to change tab control style on the fly + case WM_TABSETSTYLE: + { + DWORD style; + //::SendMessage(upDownWnd, UDM_SETBUDDY, NULL, 0); + style = ::GetWindowLongPtr(hwnd, GWL_STYLE); + + if (wParam > 0) + style |= lParam; + else + style &= ~lParam; + + _isVertical = ((style & TCS_VERTICAL) != 0); + _isMultiLine = ((style & TCS_MULTILINE) != 0); + + ::SetWindowLongPtr(hwnd, GWL_STYLE, style); + ::InvalidateRect(hwnd, NULL, TRUE); + + return TRUE; + } + + case WM_LBUTTONDOWN : + { + if (_drawTabCloseButton) + { + int xPos = LOWORD(lParam); + int yPos = HIWORD(lParam); + + if (_closeButtonZone.isHit(xPos, yPos, _currentHoverTabRect)) + { + _whichCloseClickDown = getTabIndexAt(xPos, yPos); + ::SendMessage(_hParent, WM_COMMAND, IDM_VIEW_REFRESHTABAR, 0); + return TRUE; + } + } + + ::CallWindowProc(_tabBarDefaultProc, hwnd, Message, wParam, lParam); + int currentTabOn = ::SendMessage(_hSelf, TCM_GETCURSEL, 0, 0); + + if (wParam == 2) + return TRUE; + + if (_doDragNDrop) + { + _nSrcTab = _nTabDragged = currentTabOn; + + POINT point; + point.x = LOWORD(lParam); + point.y = HIWORD(lParam); + if(::DragDetect(hwnd, point)) + { + // Yes, we're beginning to drag, so capture the mouse... + _isDragging = true; + ::SetCapture(hwnd); + } + } + + TBHDR nmhdr; + nmhdr.hdr.hwndFrom = _hSelf; + nmhdr.hdr.code = NM_CLICK; + nmhdr.hdr.idFrom = reinterpret_cast(this); + nmhdr.tabOrigin = currentTabOn; + + ::SendMessage(_hParent, WM_NOTIFY, 0, reinterpret_cast(&nmhdr)); + + return TRUE; + } + case WM_RBUTTONDOWN : //rightclick selects tab aswell + { + ::CallWindowProc(_tabBarDefaultProc, hwnd, WM_LBUTTONDOWN, wParam, lParam); + return TRUE; + } + + case WM_MOUSEMOVE : + { + if (_isDragging) + { + POINT p; + p.x = LOWORD(lParam); + p.y = HIWORD(lParam); + exchangeItemData(p); + + // Get cursor position of "Screen" + // For using the function "WindowFromPoint" afterward!!! + ::GetCursorPos(&_draggingPoint); + draggingCursor(_draggingPoint); + return TRUE; + } + + if (_drawTabCloseButton) + { + int xPos = LOWORD(lParam); + int yPos = HIWORD(lParam); + + int index = getTabIndexAt(xPos, yPos); + + if (index != -1) + { + // Reduce flicker by only redrawing needed tabs + + bool oldVal = _isCloseHover; + int oldIndex = _currentHoverTabItem; + RECT oldRect; + + ::SendMessage(_hSelf, TCM_GETITEMRECT, index, (LPARAM)&_currentHoverTabRect); + ::SendMessage(_hSelf, TCM_GETITEMRECT, oldIndex, (LPARAM)&oldRect); + _currentHoverTabItem = index; + _isCloseHover = _closeButtonZone.isHit(xPos, yPos, _currentHoverTabRect); + + if (oldVal != _isCloseHover) + { + InvalidateRect(hwnd, &oldRect, FALSE); + InvalidateRect(hwnd, &_currentHoverTabRect, FALSE); + } + } + } + break; + } + + case WM_LBUTTONUP : + { + int xPos = LOWORD(lParam); + int yPos = HIWORD(lParam); + int currentTabOn = getTabIndexAt(xPos, yPos); + if (_isDragging) + { + if(::GetCapture() == _hSelf) + ::ReleaseCapture(); + + // Send a notification message to the parent with wParam = 0, lParam = 0 + // nmhdr.idFrom = this + // destIndex = this->_nSrcTab + // scrIndex = this->_nTabDragged + TBHDR nmhdr; + nmhdr.hdr.hwndFrom = _hSelf; + nmhdr.hdr.code = _isDraggingInside?TCN_TABDROPPED:TCN_TABDROPPEDOUTSIDE; + nmhdr.hdr.idFrom = reinterpret_cast(this); + nmhdr.tabOrigin = currentTabOn; + + ::SendMessage(_hParent, WM_NOTIFY, 0, reinterpret_cast(&nmhdr)); + return TRUE; + } + + if (_drawTabCloseButton) + { + if ((_whichCloseClickDown == currentTabOn) && _closeButtonZone.isHit(xPos, yPos, _currentHoverTabRect)) + { + TBHDR nmhdr; + nmhdr.hdr.hwndFrom = _hSelf; + nmhdr.hdr.code = TCN_TABDELETE; + nmhdr.hdr.idFrom = reinterpret_cast(this); + nmhdr.tabOrigin = currentTabOn; + + ::SendMessage(_hParent, WM_NOTIFY, 0, reinterpret_cast(&nmhdr)); + + _whichCloseClickDown = -1; + return TRUE; + } + _whichCloseClickDown = -1; + } + + break; + } + + case WM_CAPTURECHANGED : + { + if (_isDragging) + { + _isDragging = false; + return TRUE; + } + break; + } + + case WM_DRAWITEM : + { + drawItem((DRAWITEMSTRUCT *)lParam); + return TRUE; + } + + case WM_KEYDOWN : + { + if (wParam == VK_LCONTROL) + ::SetCursor(::LoadCursor(_hInst, MAKEINTRESOURCE(IDC_DRAG_PLUS_TAB))); + return TRUE; + } + + case WM_MBUTTONUP: + { + int xPos = LOWORD(lParam); + int yPos = HIWORD(lParam); + int currentTabOn = getTabIndexAt(xPos, yPos); + TBHDR nmhdr; + nmhdr.hdr.hwndFrom = _hSelf; + nmhdr.hdr.code = TCN_TABDELETE; + nmhdr.hdr.idFrom = reinterpret_cast(this); + nmhdr.tabOrigin = currentTabOn; + + ::SendMessage(_hParent, WM_NOTIFY, 0, reinterpret_cast(&nmhdr)); + return TRUE; + } + + case WM_LBUTTONDBLCLK : + { + if (_isDbClk2Close) + { + int xPos = LOWORD(lParam); + int yPos = HIWORD(lParam); + int currentTabOn = getTabIndexAt(xPos, yPos); + TBHDR nmhdr; + nmhdr.hdr.hwndFrom = _hSelf; + nmhdr.hdr.code = TCN_TABDELETE; + nmhdr.hdr.idFrom = reinterpret_cast(this); + nmhdr.tabOrigin = currentTabOn; + + ::SendMessage(_hParent, WM_NOTIFY, 0, reinterpret_cast(&nmhdr)); + } + return TRUE; + } + } + return ::CallWindowProc(_tabBarDefaultProc, hwnd, Message, wParam, lParam); +} + +void TabBarPlus::drawItem(DRAWITEMSTRUCT *pDrawItemStruct) +{ + RECT rect = pDrawItemStruct->rcItem; + + int nTab = pDrawItemStruct->itemID; + if (nTab < 0) + { + ::MessageBox(NULL, TEXT("nTab < 0"), TEXT(""), MB_OK); + //return ::CallWindowProc(_tabBarDefaultProc, hwnd, Message, wParam, lParam); + } + bool isSelected = (nTab == ::SendMessage(_hSelf, TCM_GETCURSEL, 0, 0)); + + TCHAR label[MAX_PATH]; + TCITEM tci; + tci.mask = TCIF_TEXT|TCIF_IMAGE; + tci.pszText = label; + tci.cchTextMax = MAX_PATH-1; + + if (!::SendMessage(_hSelf, TCM_GETITEM, nTab, reinterpret_cast(&tci))) + { + ::MessageBox(NULL, TEXT("! TCM_GETITEM"), TEXT(""), MB_OK); + //return ::CallWindowProc(_tabBarDefaultProc, hwnd, Message, wParam, lParam); + } + HDC hDC = pDrawItemStruct->hDC; + + int nSavedDC = ::SaveDC(hDC); + + ::SetBkMode(hDC, TRANSPARENT); + HBRUSH hBrush = ::CreateSolidBrush(::GetSysColor(COLOR_BTNFACE)); + ::FillRect(hDC, &rect, hBrush); + ::DeleteObject((HGDIOBJ)hBrush); + + if (isSelected) + { + if (_drawTopBar) + { + RECT barRect = rect; + + if (_isVertical) + { + barRect.right = barRect.left + 6; + rect.left += 2; + } + else + { + barRect.bottom = barRect.top + 6; + rect.top += 2; + } + + if (::SendMessage(_hParent, NPPM_INTERNAL_ISFOCUSEDTAB, 0, (LPARAM)_hSelf)) + hBrush = ::CreateSolidBrush(_activeTopBarFocusedColour); // #FAAA3C + else + hBrush = ::CreateSolidBrush(_activeTopBarUnfocusedColour); // #FAD296 + + ::FillRect(hDC, &barRect, hBrush); + ::DeleteObject((HGDIOBJ)hBrush); + } + } + else + { + if (_drawInactiveTab) + { + RECT barRect = rect; + + hBrush = ::CreateSolidBrush(_inactiveBgColour); + ::FillRect(hDC, &barRect, hBrush); + ::DeleteObject((HGDIOBJ)hBrush); + } + } + + if (_drawTabCloseButton) + { + RECT closeButtonRect = _closeButtonZone.getButtonRectFrom(rect); + if (isSelected) + { + if (!_isVertical) + { + //closeButtonRect.top += 2; + closeButtonRect.left -= 2; + } + } + else + { + if (_isVertical) + closeButtonRect.left += 2; + } + + + // 3 status for each inactive tab and selected tab close item : + // normal / hover / pushed + int idCloseImg; + + if (_isCloseHover && (_currentHoverTabItem == nTab) && (_whichCloseClickDown == -1)) // hover + idCloseImg = IDR_CLOSETAB_HOVER; + else if (_isCloseHover && (_currentHoverTabItem == nTab) && (_whichCloseClickDown == _currentHoverTabItem)) // pushed + idCloseImg = IDR_CLOSETAB_PUSH; + else + idCloseImg = isSelected?IDR_CLOSETAB:IDR_CLOSETAB_INACT; + + + HDC hdcMemory; + hdcMemory = ::CreateCompatibleDC(hDC); + HBITMAP hBmp = ::LoadBitmap(_hInst, MAKEINTRESOURCE(idCloseImg)); + BITMAP bmp; + ::GetObject(hBmp, sizeof(bmp), &bmp); + + if (_isVertical) + rect.top = closeButtonRect.top + bmp.bmHeight; + else + rect.right = closeButtonRect.left; + + ::SelectObject(hdcMemory, hBmp); + ::BitBlt(hDC, closeButtonRect.left, closeButtonRect.top, bmp.bmWidth, bmp.bmHeight, hdcMemory, 0, 0, SRCCOPY); + ::DeleteDC(hdcMemory); + ::DeleteObject(hBmp); + } + + // Draw image + HIMAGELIST hImgLst = (HIMAGELIST)::SendMessage(_hSelf, TCM_GETIMAGELIST, 0, 0); + + SIZE charPixel; + ::GetTextExtentPoint(hDC, TEXT(" "), 1, &charPixel); + int spaceUnit = charPixel.cx; + + if (hImgLst && tci.iImage >= 0) + { + IMAGEINFO info; + int yPos = 0, xPos = 0; + int marge = 0; + + ImageList_GetImageInfo(hImgLst, tci.iImage, &info); + + RECT & imageRect = info.rcImage; + + if (_isVertical) + xPos = (rect.left + (rect.right - rect.left)/2 + 2) - (imageRect.right - imageRect.left)/2; + else + yPos = (rect.top + (rect.bottom - rect.top)/2 + (isSelected?0:2)) - (imageRect.bottom - imageRect.top)/2; + + if (isSelected) + marge = spaceUnit*2; + else + marge = spaceUnit; + + if (_isVertical) + { + rect.bottom -= imageRect.bottom - imageRect.top; + ImageList_Draw(hImgLst, tci.iImage, hDC, xPos, rect.bottom - marge, isSelected?ILD_TRANSPARENT:ILD_SELECTED); + rect.bottom += marge; + } + else + { + rect.left += marge; + ImageList_Draw(hImgLst, tci.iImage, hDC, rect.left, yPos, isSelected?ILD_TRANSPARENT:ILD_SELECTED); + rect.left += imageRect.right - imageRect.left; + } + } + + bool isStandardSize = (::SendMessage(_hParent, NPPM_INTERNAL_ISTABBARREDUCED, 0, 0) == TRUE); + + if (isStandardSize) + { + if (_isVertical) + SelectObject(hDC, _hVerticalFont); + else + SelectObject(hDC, _hFont); + } + else + { + if (_isVertical) + SelectObject(hDC, _hVerticalLargeFont); + else + SelectObject(hDC, _hLargeFont); + } + + int Flags = DT_SINGLELINE; + + if (_drawTabCloseButton) + { + Flags |= DT_LEFT; + } + else + { + if (!_isVertical) + Flags |= DT_CENTER; + } + + // the following uses pixel values the fix alignments issues with DrawText + // and font's that are rotated 90 degrees + if (isSelected) + { + //COLORREF selectedColor = RGB(0, 0, 255); + ::SetTextColor(hDC, _activeTextColour); + + if (_isVertical) + { + rect.bottom -= 2; + rect.left += ::GetSystemMetrics(SM_CXEDGE) + 4; + rect.top += (_drawTabCloseButton)?spaceUnit:0; + } + else + { + rect.top -= ::GetSystemMetrics(SM_CYEDGE); + rect.top += 3; + rect.left += _drawTabCloseButton?spaceUnit:0; + } + + if (!_isVertical) + Flags |= DT_VCENTER; + else + Flags |= DT_BOTTOM; + } + else + { + ::SetTextColor(hDC, _inactiveTextColour); + if (_isVertical) + { + rect.top += 2; + rect.bottom += 4; + rect.left += ::GetSystemMetrics(SM_CXEDGE) + 2; + } + else + { + rect.left += (_drawTabCloseButton)?spaceUnit:0; + } + + if (!_isVertical) + Flags |= DT_BOTTOM; + else + Flags |= DT_BOTTOM; + } + ::DrawText(hDC, label, lstrlen(label), &rect, Flags); + ::RestoreDC(hDC, nSavedDC); +} + + +void TabBarPlus::draggingCursor(POINT screenPoint) +{ + HWND hWin = ::WindowFromPoint(screenPoint); + if (_hSelf == hWin) + ::SetCursor(::LoadCursor(NULL, IDC_ARROW)); + else + { + TCHAR className[256]; + ::GetClassName(hWin, className, 256); + if ((!lstrcmp(className, TEXT("Scintilla"))) || (!lstrcmp(className, WC_TABCONTROL))) + { + if (::GetKeyState(VK_LCONTROL) & 0x80000000) + ::SetCursor(::LoadCursor(_hInst, MAKEINTRESOURCE(IDC_DRAG_PLUS_TAB))); + else + ::SetCursor(::LoadCursor(_hInst, MAKEINTRESOURCE(IDC_DRAG_TAB))); + } + else if (isPointInParentZone(screenPoint)) + ::SetCursor(::LoadCursor(_hInst, MAKEINTRESOURCE(IDC_DRAG_INTERDIT_TAB))); + else // drag out of application + ::SetCursor(::LoadCursor(_hInst, MAKEINTRESOURCE(IDC_DRAG_OUT_TAB))); + } +} + +void TabBarPlus::exchangeItemData(POINT point) +{ + // Find the destination tab... + int nTab = getTabIndexAt(point); + + // The position is over a tab. + //if (hitinfo.flags != TCHT_NOWHERE) + if (nTab != -1) + { + _isDraggingInside = true; + + if (nTab != _nTabDragged) + { + //1. set to focus + ::SendMessage(_hSelf, TCM_SETCURSEL, nTab, 0); + + //2. shift their data, and insert the source + TCITEM itemData_nDraggedTab, itemData_shift; + itemData_nDraggedTab.mask = itemData_shift.mask = TCIF_IMAGE | TCIF_TEXT | TCIF_PARAM; + const int stringSize = 256; + TCHAR str1[stringSize]; + TCHAR str2[stringSize]; + + itemData_nDraggedTab.pszText = str1; + itemData_nDraggedTab.cchTextMax = (stringSize); + + itemData_shift.pszText = str2; + itemData_shift.cchTextMax = (stringSize); + + ::SendMessage(_hSelf, TCM_GETITEM, _nTabDragged, reinterpret_cast(&itemData_nDraggedTab)); + + if (_nTabDragged > nTab) + { + for (int i = _nTabDragged ; i > nTab ; i--) + { + ::SendMessage(_hSelf, TCM_GETITEM, i-1, reinterpret_cast(&itemData_shift)); + ::SendMessage(_hSelf, TCM_SETITEM, i, reinterpret_cast(&itemData_shift)); + } + } + else + { + for (int i = _nTabDragged ; i < nTab ; i++) + { + ::SendMessage(_hSelf, TCM_GETITEM, i+1, reinterpret_cast(&itemData_shift)); + ::SendMessage(_hSelf, TCM_SETITEM, i, reinterpret_cast(&itemData_shift)); + } + } + // + ::SendMessage(_hSelf, TCM_SETITEM, nTab, reinterpret_cast(&itemData_nDraggedTab)); + + //3. update the current index + _nTabDragged = nTab; + + } + } + else + { + //::SetCursor(::LoadCursor(_hInst, MAKEINTRESOURCE(IDC_DRAG_TAB))); + _isDraggingInside = false; + } + +} diff --git a/PowerEditor/src/WinControls/TabBar/TabBar.h b/PowerEditor/src/WinControls/TabBar/TabBar.h new file mode 100644 index 00000000..eb5399b6 --- /dev/null +++ b/PowerEditor/src/WinControls/TabBar/TabBar.h @@ -0,0 +1,382 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef TAB_BAR_H +#define TAB_BAR_H + +#include "Window.h" + +#ifndef _WIN32_IE +#define _WIN32_IE 0x0600 +#endif //_WIN32_IE + +//Notification message +#define TCN_TABDROPPED (TCN_FIRST - 10) +#define TCN_TABDROPPEDOUTSIDE (TCN_FIRST - 11) +#define TCN_TABDELETE (TCN_FIRST - 12) + +#define WM_TABSETSTYLE (WM_APP + 0x024) + +const int marge = 8; +const int nbCtrlMax = 10; + +#include +#include "menuCmdID.h" +#include "resource.h" + +const TCHAR TABBAR_ACTIVEFOCUSEDINDCATOR[64] = TEXT("Active tab focused indicator"); +const TCHAR TABBAR_ACTIVEUNFOCUSEDINDCATOR[64] = TEXT("Active tab unfocused indicator"); +const TCHAR TABBAR_ACTIVETEXT[64] = TEXT("Active tab text"); +const TCHAR TABBAR_INACTIVETEXT[64] = TEXT("Inactive tabs"); + +struct TBHDR { + NMHDR hdr; + int tabOrigin; +}; + +class TabBar : public Window +{ +public: + TabBar() : Window(), _nbItem(0), _hasImgLst(false), _hFont(NULL){}; + + virtual ~TabBar() {}; + + virtual void destroy(){ + if (_hFont) + DeleteObject(_hFont); + + if (_hLargeFont) + DeleteObject(_hLargeFont); + + if (_hVerticalFont) + DeleteObject(_hVerticalFont); + + if (_hVerticalLargeFont) + DeleteObject(_hVerticalLargeFont); + + ::DestroyWindow(_hSelf); + _hSelf = NULL; + }; + + virtual void init(HINSTANCE hInst, HWND hwnd, bool isVertical = false, bool isTraditional = false, bool isMultiLine = false); + + virtual void reSizeTo(RECT & rc2Ajust); + + int insertAtEnd(const TCHAR *subTabName); + + void activateAt(int index) const { + if (getCurrentTabIndex() != index) { + ::SendMessage(_hSelf, TCM_SETCURSEL, index, 0);} + TBHDR nmhdr; + nmhdr.hdr.hwndFrom = _hSelf; + nmhdr.hdr.code = TCN_SELCHANGE; + nmhdr.hdr.idFrom = reinterpret_cast(this); + nmhdr.tabOrigin = index; + + }; + void getCurrentTitle(TCHAR *title, int titleLen); + + int getCurrentTabIndex() const { + return ::SendMessage(_hSelf, TCM_GETCURSEL, 0, 0); + }; + void deletItemAt(int index); + + void deletAllItem() { + ::SendMessage(_hSelf, TCM_DELETEALLITEMS, 0, 0); + _nbItem = 0; + }; + + void setImageList(HIMAGELIST himl) { + _hasImgLst = true; + ::SendMessage(_hSelf, TCM_SETIMAGELIST, 0, (LPARAM)himl); + }; + + int nbItem() const { + return _nbItem; + }; + + void setFont(TCHAR *fontName, size_t fontSize) { + if (_hFont) + ::DeleteObject(_hFont); + + _hFont = ::CreateFont( fontSize, 0, + (_isVertical) ? 900:0, + (_isVertical) ? 900:0, + FW_NORMAL, + 0, 0, 0, 0, + 0, 0, 0, 0, + fontName); + if (_hFont) + ::SendMessage(_hSelf, WM_SETFONT, reinterpret_cast(_hFont), 0); + }; + + void setVertical(bool b) { + _isVertical = b; + }; + + void setMultiLine(bool b) { + _isMultiLine = b; + }; + + +protected: + size_t _nbItem; + bool _hasImgLst; + HFONT _hFont; + HFONT _hLargeFont; + HFONT _hVerticalFont; + HFONT _hVerticalLargeFont; + + int _ctrlID; + bool _isTraditional; + + bool _isVertical; + bool _isMultiLine; + + long getRowCount() const { + return long(::SendMessage(_hSelf, TCM_GETROWCOUNT, 0, 0)); + }; +}; + + +struct CloseButtonZone { + + CloseButtonZone(): _width(11), _hight(11), _fromTop(5), _fromRight(3){}; + + bool isHit(int x, int y, const RECT & testZone) const { + if (((x + _width + _fromRight) < testZone.right) || (x > (testZone.right - _fromRight))) + return false; + + if (((y - _hight - _fromTop) > testZone.top) || (y < (testZone.top + _fromTop))) + return false; + + return true; + }; + + RECT getButtonRectFrom(const RECT & tabItemRect) const { + RECT rect; + rect.right = tabItemRect.right - _fromRight; + rect.left = rect.right - _width; + rect.top = tabItemRect.top + _fromTop; + rect.bottom = rect.top + _hight; + + return rect; + }; + + int _width; + int _hight; + + int _fromTop; // distance from top in pixzl + int _fromRight; // distance from right in pixzl +}; + +class TabBarPlus : public TabBar +{ +public : + + TabBarPlus() : TabBar(), _isDragging(false), _tabBarDefaultProc(NULL), _currentHoverTabItem(-1),\ + _isCloseHover(false), _whichCloseClickDown(-1), _lmbdHit(false) {}; + enum tabColourIndex { + activeText, activeFocusedTop, activeUnfocusedTop, inactiveText, inactiveBg + }; + + static void doDragNDrop(bool justDoIt) { + _doDragNDrop = justDoIt; + }; + + virtual void init(HINSTANCE hInst, HWND hwnd, bool isVertical = false, bool isTraditional = false, bool isMultiLine = false); + + static bool doDragNDropOrNot() { + return _doDragNDrop; + }; + + int getSrcTabIndex() const { + return _nSrcTab; + }; + + int getTabDraggedIndex() const { + return _nTabDragged; + }; + + POINT getDraggingPoint() const { + return _draggingPoint; + }; + + static void doOwnerDrawTab() { + ::SendMessage(_hwndArray[0], TCM_SETPADDING, 0, MAKELPARAM(6, 0)); + for (int i = 0 ; i < _nbCtrl ; i++) + { + if (_hwndArray[i]) + { + DWORD style = ::GetWindowLongPtr(_hwndArray[i], GWL_STYLE); + if (isOwnerDrawTab()) + style |= TCS_OWNERDRAWFIXED; + else + style &= ~TCS_OWNERDRAWFIXED; + + ::SetWindowLongPtr(_hwndArray[i], GWL_STYLE, style); + ::InvalidateRect(_hwndArray[i], NULL, TRUE); + + const int base = 6; + ::SendMessage(_hwndArray[i], TCM_SETPADDING, 0, MAKELPARAM(_drawTabCloseButton?base+3:base, 0)); + } + } + }; + + static void doVertical() { + for (int i = 0 ; i < _nbCtrl ; i++) + { + if (_hwndArray[i]) + SendMessage(_hwndArray[i], WM_TABSETSTYLE, isVertical(), TCS_VERTICAL); + } + }; + + static void doMultiLine() { + for (int i = 0 ; i < _nbCtrl ; i++) + { + if (_hwndArray[i]) + SendMessage(_hwndArray[i], WM_TABSETSTYLE, isMultiLine(), TCS_MULTILINE); + } + }; + + static bool isOwnerDrawTab() {return true;};//(_drawInactiveTab || _drawTopBar || _drawTabCloseButton);}; + static bool drawTopBar() {return _drawTopBar;}; + static bool drawInactiveTab() {return _drawInactiveTab;}; + static bool drawTabCloseButton() {return _drawTabCloseButton;}; + static bool isDbClk2Close() {return _isDbClk2Close;}; + static bool isVertical() { return _isCtrlVertical;}; + static bool isMultiLine() { return _isCtrlMultiLine;}; + + static void setDrawTopBar(bool b) { + _drawTopBar = b; + doOwnerDrawTab(); + }; + static void setDrawInactiveTab(bool b) { + _drawInactiveTab = b; + doOwnerDrawTab(); + }; + static void setDrawTabCloseButton(bool b) { + _drawTabCloseButton = b; + doOwnerDrawTab(); + }; + + static void setDbClk2Close(bool b) { + _isDbClk2Close = b; + }; + + static void setVertical(bool b) { + _isCtrlVertical = b; + doVertical(); + }; + + static void setMultiLine(bool b) { + _isCtrlMultiLine = b; + doMultiLine(); + }; + + static void setColour(COLORREF colour2Set, tabColourIndex i) { + switch (i) + { + case activeText: + _activeTextColour = colour2Set; + break; + case activeFocusedTop: + _activeTopBarFocusedColour = colour2Set; + break; + case activeUnfocusedTop: + _activeTopBarUnfocusedColour = colour2Set; + break; + case inactiveText: + _inactiveTextColour = colour2Set; + break; + case inactiveBg : + _inactiveBgColour = colour2Set; + break; + default : + return; + } + doOwnerDrawTab(); + }; + +protected: + // it's the boss to decide if we do the drag N drop + static bool _doDragNDrop; + // drag N drop members + bool _isDragging; + bool _isDraggingInside; + int _nSrcTab; + int _nTabDragged; + POINT _draggingPoint; // coordinate of Screen + WNDPROC _tabBarDefaultProc; + + RECT _currentHoverTabRect; + int _currentHoverTabItem; + + CloseButtonZone _closeButtonZone; + bool _isCloseHover; + int _whichCloseClickDown; + bool _lmbdHit; // Left Mouse Button Down Hit + + LRESULT runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam); + + static LRESULT CALLBACK TabBarPlus_Proc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { + return (((TabBarPlus *)(::GetWindowLongPtr(hwnd, GWL_USERDATA)))->runProc(hwnd, Message, wParam, lParam)); + }; + void exchangeItemData(POINT point); + + + // it's the boss to decide if we do the ownerDraw style tab + static bool _drawInactiveTab; + static bool _drawTopBar; + static bool _drawTabCloseButton; + static bool _isDbClk2Close; + static bool _isCtrlVertical; + static bool _isCtrlMultiLine; + + static COLORREF _activeTextColour; + static COLORREF _activeTopBarFocusedColour; + static COLORREF _activeTopBarUnfocusedColour; + static COLORREF _inactiveTextColour; + static COLORREF _inactiveBgColour; + + static int _nbCtrl; + static HWND _hwndArray[nbCtrlMax]; + + void drawItem(DRAWITEMSTRUCT *pDrawItemStruct); + void draggingCursor(POINT screenPoint); + + int getTabIndexAt(const POINT & p) { + return getTabIndexAt(p.x, p.y); + }; + + int getTabIndexAt(int x, int y) { + TCHITTESTINFO hitInfo; + hitInfo.pt.x = x; + hitInfo.pt.y = y; + + return ::SendMessage(_hSelf, TCM_HITTEST, 0, (LPARAM)&hitInfo); + }; + + bool isPointInParentZone(POINT screenPoint) const { + RECT parentZone; + ::GetWindowRect(_hParent, &parentZone); + return (((screenPoint.x >= parentZone.left) && (screenPoint.x <= parentZone.right)) && + (screenPoint.y >= parentZone.top) && (screenPoint.y <= parentZone.bottom)); + }; +}; + +#endif // TAB_BAR_H diff --git a/PowerEditor/src/WinControls/TaskList/TaskList.cpp b/PowerEditor/src/WinControls/TaskList/TaskList.cpp new file mode 100644 index 00000000..8ac27f3a --- /dev/null +++ b/PowerEditor/src/WinControls/TaskList/TaskList.cpp @@ -0,0 +1,243 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#include "TaskList.h" +#include "TaskListDlg_rc.h" +#include "colors.h" +#include "Common.h" + +void TaskList::init(HINSTANCE hInst, HWND parent, HIMAGELIST hImaLst, int nbItem, int index2set) +{ + Window::init(hInst, parent); + + _currentIndex = index2set; + + INITCOMMONCONTROLSEX icex; + + // Ensure that the common control DLL is loaded. + icex.dwSize = sizeof(INITCOMMONCONTROLSEX); + icex.dwICC = ICC_LISTVIEW_CLASSES; + InitCommonControlsEx(&icex); + + _nbItem = nbItem; + + // Create the list-view window in report view with label editing enabled. + int listViewStyles = LVS_REPORT | LVS_OWNERDATA | LVS_NOCOLUMNHEADER | LVS_NOSORTHEADER\ + | LVS_NOSCROLL | LVS_SINGLESEL | LVS_AUTOARRANGE | LVS_OWNERDRAWFIXED\ + | LVS_SHAREIMAGELISTS/* | WS_BORDER*/; + + _hSelf = ::CreateWindow(WC_LISTVIEW, + TEXT(""), + WS_CHILD | listViewStyles, + 0, + 0, + 0, + 0, + _hParent, + (HMENU) NULL, + hInst, + NULL); + if (!_hSelf) + { + systemMessage(TEXT("System Err")); + throw int(69); + } + + ::SetWindowLongPtr(_hSelf, GWL_USERDATA, reinterpret_cast(this)); + _defaultProc = reinterpret_cast(::SetWindowLongPtr(_hSelf, GWL_WNDPROC, reinterpret_cast(staticProc))); + + DWORD exStyle = ListView_GetExtendedListViewStyle(_hSelf); + exStyle |= LVS_EX_FULLROWSELECT | LVS_EX_BORDERSELECT ; + ListView_SetExtendedListViewStyle(_hSelf, exStyle); + + + LVCOLUMN lvColumn; + lvColumn.mask = LVCF_WIDTH; + + lvColumn.cx = 1500; + + ListView_InsertColumn(_hSelf, 0, &lvColumn); + + ListView_SetItemCountEx(_hSelf, _nbItem, LVSICF_NOSCROLL); + ListView_SetImageList(_hSelf, hImaLst, LVSIL_SMALL); + + ListView_SetItemState(_hSelf, _currentIndex, LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED); + ListView_SetBkColor(_hSelf, veryLiteGrey); + ListView_SetTextBkColor(_hSelf, veryLiteGrey); +} + +RECT TaskList::adjustSize() +{ + RECT rc; + ListView_GetItemRect(_hSelf, 0, &rc, LVIR_ICON); + const int imgWidth = rc.right - rc.left; + const int marge = 30; + + for (int i = 0 ; i < _nbItem ; i++) + { + TCHAR buf[MAX_PATH]; + ListView_GetItemText(_hSelf, i, 0, buf, MAX_PATH); + int width = ListView_GetStringWidth(_hSelf, buf); + + if (width > (_rc.right - _rc.left)) + _rc.right = _rc.left + width + imgWidth + marge; + + _rc.bottom += rc.bottom - rc.top; + + } + + // additional space for horizontal scroll-bar + _rc.bottom += rc.bottom - rc.top; + + reSizeTo(_rc); + return _rc; +} + +int TaskList::updateCurrentIndex() +{ + for (int i = 0 ; i < _nbItem ; i++) + { + int isSelected = ListView_GetItemState(_hSelf, i, LVIS_SELECTED); + if (isSelected == LVIS_SELECTED) + { + _currentIndex = i; + return _currentIndex; + } + } + return _currentIndex; +} + +LRESULT TaskList::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) +{ + switch (Message) + { + case WM_KEYUP: + { + if (wParam == VK_CONTROL) + { + ::SendMessage(_hParent, WM_COMMAND, ID_PICKEDUP, _currentIndex); + } + } + return TRUE; + + case WM_MOUSEWHEEL : + { + //if (LOWORD(wParam) & MK_RBUTTON) + // It's not easy to press RBUTTON while moving a mouse wheel and holding CTRL :-) + // Actually, I thought MOUSEWHEEL is not working until I saw this code + { + short zDelta = (short) HIWORD(wParam); + if (zDelta > 0) + { + size_t selected = (_currentIndex - 1) < 0 ? (_nbItem - 1) : (_currentIndex - 1); + ListView_SetItemState(_hSelf, _currentIndex, 0, LVIS_SELECTED|LVIS_FOCUSED); + // tells what item(s) to be repainted + ListView_RedrawItems(_hSelf, _currentIndex, _currentIndex); + // repaint item(s) + UpdateWindow(_hSelf); + ListView_SetItemState(_hSelf, selected, LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED); + // tells what item(s) to be repainted + ListView_RedrawItems(_hSelf, selected, selected); + // repaint item(s) + UpdateWindow(_hSelf); + _currentIndex = selected; + } + else + { + size_t selected = (_currentIndex + 1) > (_nbItem - 1) ? 0 : (_currentIndex + 1); + ListView_SetItemState(_hSelf, _currentIndex, 0, LVIS_SELECTED|LVIS_FOCUSED); + // tells what item(s) to be repainted + ListView_RedrawItems(_hSelf, _currentIndex, _currentIndex); + // repaint item(s) + UpdateWindow(_hSelf); + ListView_SetItemState(_hSelf, selected, LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED); + // tells what item(s) to be repainted + ListView_RedrawItems(_hSelf, selected, selected); + // repaint item(s) + UpdateWindow(_hSelf); + _currentIndex = selected; + } + } + return TRUE; + } + + case WM_KEYDOWN : + { + //printStr(TEXT("WM_KEYDOWN")); + return TRUE; + } + + + case WM_GETDLGCODE : + { + MSG *msg = (MSG*)lParam; + + if ( msg != NULL) + { + if ((msg->message == WM_KEYDOWN) && (0x80 & GetKeyState(VK_CONTROL))) + { + // Shift+Tab is cool but I think VK_UP and VK_LEFT are also cool :-) + if (((msg->wParam == VK_TAB) && (0x80 & GetKeyState(VK_SHIFT))) || + (msg->wParam == VK_UP)) + { + size_t selected = (_currentIndex - 1) < 0 ? (_nbItem - 1) : (_currentIndex - 1); + ListView_SetItemState(_hSelf, _currentIndex, 0, LVIS_SELECTED|LVIS_FOCUSED); + // tells what item(s) to be repainted + ListView_RedrawItems(_hSelf, _currentIndex, _currentIndex); + // repaint item(s) + UpdateWindow(_hSelf); + ListView_SetItemState(_hSelf, selected, LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED); + // tells what item(s) to be repainted + ListView_RedrawItems(_hSelf, selected, selected); + // repaint item(s) + UpdateWindow(_hSelf); + _currentIndex = selected; + } + // VK_DOWN and VK_RIGHT do the same as VK_TAB does + else if ((msg->wParam == VK_TAB) || (msg->wParam == VK_DOWN)) + { + size_t selected = (_currentIndex + 1) > (_nbItem - 1) ? 0 : (_currentIndex + 1); + ListView_SetItemState(_hSelf, _currentIndex, 0, LVIS_SELECTED|LVIS_FOCUSED); + // tells what item(s) to be repainted + ListView_RedrawItems(_hSelf, _currentIndex, _currentIndex); + // repaint item(s) + UpdateWindow(_hSelf); + ListView_SetItemState(_hSelf, selected, LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED); + // tells what item(s) to be repainted + ListView_RedrawItems(_hSelf, selected, selected); + // repaint item(s) + UpdateWindow(_hSelf); + _currentIndex = selected; + } + } + else + { + //printStr(TEXT("else")); + return TRUE; + } + //return DLGC_WANTALLKEYS ; + + } + return DLGC_WANTALLKEYS ; + } + + default : + return ::CallWindowProc(_defaultProc, hwnd, Message, wParam, lParam); + } + return FALSE; +} + diff --git a/PowerEditor/src/WinControls/TaskList/TaskList.h b/PowerEditor/src/WinControls/TaskList/TaskList.h new file mode 100644 index 00000000..647ef4c2 --- /dev/null +++ b/PowerEditor/src/WinControls/TaskList/TaskList.h @@ -0,0 +1,89 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef TASKLIST_H +#define TASKLIST_H + +#include "Window.h" + +#ifndef WM_MOUSEWHEEL +#define WM_MOUSEWHEEL 0x020A +#endif //WM_MOUSEWHEEL + +#include + +class TaskList : public Window +{ +public: + TaskList() : Window(), _currentIndex(0) { + _rc.left = 0; + _rc.top = 0; + _rc.right = 150; + _rc.bottom = 0; + }; + + virtual ~TaskList() {}; + + virtual void destroy(){ + if (_hFont) + DeleteObject(_hFont); + ::DestroyWindow(_hSelf); + _hSelf = NULL; + }; + + void init(HINSTANCE hInst, HWND hwnd, HIMAGELIST hImaLst, int nbItem, int index2set); + + void setFont(TCHAR *fontName, size_t fontSize) { + if (_hFont) + ::DeleteObject(_hFont); + + _hFont = ::CreateFont( fontSize, 0, 0, 0, + FW_NORMAL, + 0, 0, 0, 0, + 0, 0, 0, 0, + fontName); + if (_hFont) + ::SendMessage(_hSelf, WM_SETFONT, reinterpret_cast(_hFont), 0); + }; + + + RECT adjustSize(); + int getCurrentIndex() const { + return _currentIndex; + }; + int updateCurrentIndex(); + + HIMAGELIST getImgLst() const { + return ListView_GetImageList(_hSelf, LVSIL_SMALL); + }; +protected: + + WNDPROC _defaultProc; + LRESULT runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam); + + static LRESULT CALLBACK staticProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { + return (((TaskList *)(::GetWindowLongPtr(hwnd, GWL_USERDATA)))->runProc(hwnd, Message, wParam, lParam)); + }; + + HFONT _hFont; + int _nbItem; + int _currentIndex; + RECT _rc; +}; + + +#endif // TASKLIST_H diff --git a/PowerEditor/src/WinControls/TaskList/TaskListDlg.h b/PowerEditor/src/WinControls/TaskList/TaskListDlg.h new file mode 100644 index 00000000..6d29f341 --- /dev/null +++ b/PowerEditor/src/WinControls/TaskList/TaskListDlg.h @@ -0,0 +1,255 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef TASKLISTDLG_H +#define TASKLISTDLG_H + +#include "StaticDialog.h" +#include "TaskListDlg_rc.h" +#include "TaskList.h" +#include "ImageListSet.h" +#include "Notepad_plus_msgs.h" + +const bool dirUp = true; +const bool dirDown = false; + +#define TASKLIST_USER (WM_USER + 8000) + #define WM_GETTASKLISTINFO (TASKLIST_USER + 01) + +struct TaskLstFnStatus { + int _iView; + int _docIndex; + generic_string _fn; + int _status; + TaskLstFnStatus(generic_string str, int status) : _fn(str), _status(status){}; + TaskLstFnStatus(int iView, int docIndex, generic_string str, int status) : _iView(iView), _docIndex(docIndex), _fn(str), _status(status) {}; +}; + +struct TaskListInfo { + vector _tlfsLst; + int _currentIndex; +}; + +static HWND hWndServer = NULL; +static HHOOK hook = NULL; + +static LRESULT CALLBACK hookProc(UINT nCode, WPARAM wParam, LPARAM lParam) +{ + if ((nCode >= 0) && (wParam == WM_RBUTTONUP)) + { + ::PostMessage(hWndServer, WM_RBUTTONUP, 0, 0); + } + + return ::CallNextHookEx(hook, nCode, wParam, lParam); +}; + +class TaskListDlg : public StaticDialog +{ +public : + TaskListDlg() : StaticDialog() {}; + void init(HINSTANCE hInst, HWND parent, HIMAGELIST hImgLst, bool dir) { + Window::init(hInst, parent); + _hImalist = hImgLst; + _initDir = dir; + }; + + int doDialog(bool isRTL = false) { + if (isRTL) + { + DLGTEMPLATE *pMyDlgTemplate = NULL; + HGLOBAL hMyDlgTemplate = makeRTLResource(IDD_VALUE_DLG, &pMyDlgTemplate); + int result = ::DialogBoxIndirectParam(_hInst, pMyDlgTemplate, _hParent, (DLGPROC)dlgProc, (LPARAM)this); + ::GlobalFree(hMyDlgTemplate); + return result; + } + return ::DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_TASKLIST_DLG), _hParent, (DLGPROC)dlgProc, (LPARAM)this); + }; + + virtual void destroy() {}; + +protected : + BOOL CALLBACK run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam) { + + switch (Message) + { + case WM_INITDIALOG : + { + ::SendMessage(_hParent, WM_GETTASKLISTINFO, (WPARAM)&_taskListInfo, 0); + int nbTotal = _taskListInfo._tlfsLst.size(); + + int i2set = _taskListInfo._currentIndex + (_initDir == dirDown?1:-1); + + if (i2set < 0) + i2set = nbTotal - 1; + + if (i2set > (nbTotal - 1)) + i2set = 0; + + _taskList.init(_hInst, _hSelf, _hImalist, nbTotal, i2set); + _taskList.setFont(TEXT("Verdana"), 14); + _rc = _taskList.adjustSize(); + + reSizeTo(_rc); + goToCenter(); + + _taskList.display(true); + hWndServer = _hSelf; + +#ifndef WH_MOUSE_LL +#define WH_MOUSE_LL 14 +#endif + winVer ver = (NppParameters::getInstance())->getWinVersion(); + _hHooker = ::SetWindowsHookEx(ver >= WV_W2K?WH_MOUSE_LL:WH_MOUSE, (HOOKPROC)hookProc, _hInst, 0); + hook = _hHooker; + return FALSE; + } + + case WM_DESTROY : + { + _taskList.destroy(); + ::UnhookWindowsHookEx(_hHooker); + return TRUE; + } + + + case WM_RBUTTONUP: + { + ::SendMessage(_hSelf, WM_COMMAND, ID_PICKEDUP, _taskList.getCurrentIndex()); + return TRUE; + } + + + case WM_DRAWITEM : + { + drawItem((DRAWITEMSTRUCT *)lParam); + return TRUE; + } + + case WM_NOTIFY: + { + switch (((LPNMHDR)lParam)->code) + { + case LVN_GETDISPINFO: + { + LV_ITEM &lvItem = reinterpret_cast((LV_DISPINFO FAR *)lParam)->item; + + TaskLstFnStatus & fileNameStatus = _taskListInfo._tlfsLst[lvItem.iItem]; + + lvItem.pszText = (TCHAR *)fileNameStatus._fn.c_str(); + lvItem.iImage = fileNameStatus._status; + + return TRUE; + } + + case NM_CLICK : + case NM_RCLICK : + { + ::SendMessage(_hSelf, WM_COMMAND, ID_PICKEDUP, _taskList.updateCurrentIndex()); + return TRUE; + } + + default: + break; + } + break; + } + + case WM_COMMAND : + { + switch (wParam) + { + case ID_PICKEDUP : + { + int listIndex = lParam; + int view2set = _taskListInfo._tlfsLst[listIndex]._iView; + int index2Switch = _taskListInfo._tlfsLst[listIndex]._docIndex; + ::SendMessage(_hParent, NPPM_ACTIVATEDOC, view2set, index2Switch); + ::EndDialog(_hSelf, -1); + return TRUE; + } + + default: + return FALSE; + } + } + + default : + return FALSE; + } + + return FALSE; + }; + +private : + TaskList _taskList; + TaskListInfo _taskListInfo; + HIMAGELIST _hImalist; + bool _initDir; + HHOOK _hHooker; + + void drawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) + { + RECT rect = lpDrawItemStruct->rcItem; + HDC hDC = lpDrawItemStruct->hDC; + int nItem = lpDrawItemStruct->itemID; + const TCHAR *label = _taskListInfo._tlfsLst[nItem]._fn.c_str(); + int iImage = _taskListInfo._tlfsLst[nItem]._status; + + COLORREF textColor = darkGrey; + int imgStyle = ILD_SELECTED; + + if (lpDrawItemStruct->itemState && ODS_SELECTED) + { + imgStyle = ILD_TRANSPARENT; + textColor = black; + + HFONT selectedFont = (HFONT)::GetStockObject(SYSTEM_FONT); + ::SelectObject(hDC, selectedFont); + } + + // + // DRAW IMAGE + // + HIMAGELIST hImgLst = _taskList.getImgLst(); + + IMAGEINFO info; + ImageList_GetImageInfo(hImgLst, iImage, &info); + + RECT & imageRect = info.rcImage; + //int yPos = (rect.top + (rect.bottom - rect.top)/2 + (isSelected?0:2)) - (imageRect.bottom - imageRect.top)/2; + + SIZE charPixel; + ::GetTextExtentPoint(hDC, TEXT(" "), 1, &charPixel); + int spaceUnit = charPixel.cx; + int marge = spaceUnit; + + rect.left += marge; + ImageList_Draw(hImgLst, iImage, hDC, rect.left, rect.top, imgStyle); + rect.left += imageRect.right - imageRect.left + spaceUnit * 2; + + // + // DRAW TEXT + // + ::SetTextColor(hDC, textColor); + rect.top -= ::GetSystemMetrics(SM_CYEDGE); + + ::DrawText(hDC, label, lstrlen(label), &rect, DT_SINGLELINE | DT_VCENTER | DT_LEFT); + }; +}; + + +#endif // TASKLISTDLG_H diff --git a/PowerEditor/src/WinControls/TaskList/TaskListDlg.rc b/PowerEditor/src/WinControls/TaskList/TaskListDlg.rc new file mode 100644 index 00000000..1b82e494 --- /dev/null +++ b/PowerEditor/src/WinControls/TaskList/TaskListDlg.rc @@ -0,0 +1,26 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#include +#include "TaskListDlg_rc.h" + +IDD_TASKLIST_DLG DIALOGEX DISCARDABLE 0, 0, 300, 300 +STYLE WS_POPUP | WS_VISIBLE +FONT 8, TEXT("MS Shell Dlg"), 0, 0, 0x1 +BEGIN +END + diff --git a/PowerEditor/src/WinControls/TaskList/TaskListDlg_rc.h b/PowerEditor/src/WinControls/TaskList/TaskListDlg_rc.h new file mode 100644 index 00000000..ad19a531 --- /dev/null +++ b/PowerEditor/src/WinControls/TaskList/TaskListDlg_rc.h @@ -0,0 +1,24 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef TASKLISTDLGRC_H +#define TASKLISTDLGRC_H + +#define IDD_TASKLIST_DLG 2450 + #define ID_PICKEDUP (IDD_TASKLIST_DLG + 1) + +#endif // TASKLISTDLGRC_H diff --git a/PowerEditor/src/WinControls/ToolBar/ToolBar.cpp b/PowerEditor/src/WinControls/ToolBar/ToolBar.cpp new file mode 100644 index 00000000..18bcf3f1 --- /dev/null +++ b/PowerEditor/src/WinControls/ToolBar/ToolBar.cpp @@ -0,0 +1,392 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +//#include "..\..\resource.h" +#include "ToolBar.h" +#include "Shortcut.h" + +const int WS_TOOLBARSTYLE = WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | TBSTYLE_TOOLTIPS |TBSTYLE_FLAT | CCS_TOP | BTNS_AUTOSIZE | CCS_NOPARENTALIGN | CCS_NORESIZE | CCS_NODIVIDER; + +bool ToolBar::init( HINSTANCE hInst, HWND hPere, toolBarStatusType type, + ToolBarButtonUnit *buttonUnitArray, int arraySize) +{ + Window::init(hInst, hPere); + _state = type; + int iconSize = (_state == TB_LARGE?32:16); + + _toolBarIcons.init(buttonUnitArray, arraySize); + _toolBarIcons.create(_hInst, iconSize); + + INITCOMMONCONTROLSEX icex; + icex.dwSize = sizeof(INITCOMMONCONTROLSEX); + icex.dwICC = ICC_WIN95_CLASSES|ICC_COOL_CLASSES|ICC_BAR_CLASSES|ICC_USEREX_CLASSES; + InitCommonControlsEx(&icex); + + //Create the list of buttons + _nrButtons = arraySize; + _nrDynButtons = _vDynBtnReg.size(); + _nrTotalButtons = _nrButtons + (_nrDynButtons ? _nrDynButtons + 1 : 0); + _pTBB = new TBBUTTON[_nrTotalButtons]; //add one for the extra separator + + int cmd = 0; + int bmpIndex = -1, style; + size_t i = 0; + for (; i < _nrButtons ; i++) + { + cmd = buttonUnitArray[i]._cmdID; + if (cmd != 0) + { + bmpIndex++; + style = BTNS_BUTTON; + } + else + { + style = BTNS_SEP; + } + + _pTBB[i].iBitmap = (cmd != 0?bmpIndex:0); + _pTBB[i].idCommand = cmd; + _pTBB[i].fsState = TBSTATE_ENABLED; + _pTBB[i].fsStyle = style; + _pTBB[i].dwData = 0; + _pTBB[i].iString = 0; + } + + if (_nrDynButtons > 0) { + //add separator + _pTBB[i].iBitmap = 0; + _pTBB[i].idCommand = 0; + _pTBB[i].fsState = TBSTATE_ENABLED; + _pTBB[i].fsStyle = BTNS_SEP; + _pTBB[i].dwData = 0; + _pTBB[i].iString = 0; + i++; + //add plugin buttons + for (size_t j = 0; j < _nrDynButtons ; j++, i++) + { + cmd = _vDynBtnReg[j].message; + bmpIndex++; + + _pTBB[i].iBitmap = bmpIndex; + _pTBB[i].idCommand = cmd; + _pTBB[i].fsState = TBSTATE_ENABLED; + _pTBB[i].fsStyle = BTNS_BUTTON; + _pTBB[i].dwData = 0; + _pTBB[i].iString = 0; + } + } + + reset(true); //load icons etc + + return true; +} + +void ToolBar::destroy() { + if (_pRebar) { + _pRebar->removeBand(_rbBand.wID); + _pRebar = NULL; + } + delete [] _pTBB; + ::DestroyWindow(_hSelf); + _hSelf = NULL; + _toolBarIcons.destroy(); +}; + +int ToolBar::getWidth() const { + RECT btnRect; + int totalWidth = 0; + for(size_t i = 0; i < _nrCurrentButtons; i++) { + ::SendMessage(_hSelf, TB_GETITEMRECT, i, (LPARAM)&btnRect); + totalWidth += btnRect.right - btnRect.left; + } + return totalWidth; +} + +int ToolBar::getHeight() const { + DWORD size = (DWORD)SendMessage(_hSelf, TB_GETBUTTONSIZE, 0, 0); + DWORD padding = (DWORD)SendMessage(_hSelf, TB_GETPADDING, 0,0); + int totalHeight = HIWORD(size) + HIWORD(padding); + + return totalHeight; +} + +void ToolBar::reset(bool create) +{ + + if(create && _hSelf) { + //Store current button state information + TBBUTTON tempBtn; + for(size_t i = 0; i < _nrCurrentButtons; i++) { + ::SendMessage(_hSelf, TB_GETBUTTON, (WPARAM)i, (LPARAM)&tempBtn); + _pTBB[i].fsState = tempBtn.fsState; + } + ::DestroyWindow(_hSelf); + _hSelf = NULL; + } + + if(!_hSelf) { + _hSelf = ::CreateWindowEx( + WS_EX_PALETTEWINDOW, + TOOLBARCLASSNAME, + TEXT(""), + WS_TOOLBARSTYLE, + 0, 0, + 0, 0, + _hParent, + NULL, + _hInst, + 0); + // Send the TB_BUTTONSTRUCTSIZE message, which is required for + // backward compatibility. + ::SendMessage(_hSelf, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0); + ::SendMessage(_hSelf, TB_SETEXTENDEDSTYLE, 0, (LPARAM)TBSTYLE_EX_HIDECLIPPEDBUTTONS); + } + + if (!_hSelf) + { + systemMessage(TEXT("System Err")); + throw int(9); + } + + if (_state != TB_STANDARD) + { + //If non standard icons, use custom imagelists + setDefaultImageList(); + setHotImageList(); + setDisableImageList(); + } + else + { + //Else set the internal imagelist with standard bitmaps + TBADDBITMAP addbmp = {_hInst, 0}; + TBADDBITMAP addbmpdyn = {0, 0}; + for (size_t i = 0 ; i < _nrButtons ; i++) + { + addbmp.nID = _toolBarIcons.getStdIconAt(i); + ::SendMessage(_hSelf, TB_ADDBITMAP, 1, (LPARAM)&addbmp); + } + if (_nrDynButtons > 0) { + for (size_t j = 0; j < _nrDynButtons; j++) + { + addbmpdyn.nID = (UINT_PTR)_vDynBtnReg.at(j).hBmp; + ::SendMessage(_hSelf, TB_ADDBITMAP, 1, (LPARAM)&addbmpdyn); + } + } + } + + if (create) { //if the toolbar has been recreated, readd the buttons + size_t nrBtnToAdd = (_state == TB_STANDARD?_nrTotalButtons:_nrButtons); + _nrCurrentButtons = nrBtnToAdd; + WORD btnSize = (_state == TB_LARGE?32:16); + ::SendMessage(_hSelf, TB_SETBUTTONSIZE , (WPARAM)0, (LPARAM)MAKELONG (btnSize, btnSize)); + ::SendMessage(_hSelf, TB_ADDBUTTONS, (WPARAM)nrBtnToAdd, (LPARAM)_pTBB); + } + ::SendMessage(_hSelf, TB_AUTOSIZE, 0, 0); + + if (_pRebar) { + _rbBand.hwndChild = getHSelf(); + _rbBand.cxMinChild = 0; + _rbBand.cyIntegral = 1; + _rbBand.cyMinChild = _rbBand.cyMaxChild = getHeight(); + _rbBand.cxIdeal = getWidth(); + + _pRebar->reNew(REBAR_BAR_TOOLBAR, &_rbBand); + } +} + +void ToolBar::registerDynBtn(UINT messageID, toolbarIcons* tIcon) +{ + // Note: Register of buttons only possible before init! + if ((_hSelf == NULL) && (messageID != 0) && (tIcon->hToolbarBmp != NULL)) + { + tDynamicList dynList; + dynList.message = messageID; + dynList.hBmp = tIcon->hToolbarBmp; + dynList.hIcon = tIcon->hToolbarIcon; + _vDynBtnReg.push_back(dynList); + } +} + +void ToolBar::doPopop(POINT chevPoint) { + //first find hidden buttons + int width = Window::getWidth(); + + size_t start = 0; + RECT btnRect = {0,0,0,0}; + while(start < _nrCurrentButtons) { + ::SendMessage(_hSelf, TB_GETITEMRECT, start, (LPARAM)&btnRect); + if(btnRect.right > width) + break; + start++; + } + + if (start < _nrCurrentButtons) { //some buttons are hidden + HMENU menu = ::CreatePopupMenu(); + int cmd; + generic_string text; + while (start < _nrCurrentButtons) { + cmd = _pTBB[start].idCommand; + getNameStrFromCmd(cmd, text); + if (_pTBB[start].idCommand != 0) { + if (::SendMessage(_hSelf, TB_ISBUTTONENABLED, cmd, 0) != 0) + AppendMenu(menu, MF_ENABLED, cmd, text.c_str()); + else + AppendMenu(menu, MF_DISABLED|MF_GRAYED, cmd, text.c_str()); + } else + AppendMenu(menu, MF_SEPARATOR, 0, TEXT("")); + start++; + } + TrackPopupMenu(menu, 0, chevPoint.x, chevPoint.y, 0, _hSelf, NULL); + } +} + +void ToolBar::addToRebar(ReBar * rebar) { + if (_pRebar) + return; + _pRebar = rebar; + + ZeroMemory(&_rbBand, sizeof(REBARBANDINFO)); + _rbBand.cbSize = sizeof(REBARBANDINFO); + _rbBand.fMask = RBBIM_STYLE | RBBIM_CHILD | RBBIM_CHILDSIZE | + RBBIM_SIZE | RBBIM_IDEALSIZE | RBBIM_ID; + + _rbBand.fStyle = RBBS_VARIABLEHEIGHT | RBBS_USECHEVRON; + _rbBand.hwndChild = getHSelf(); + _rbBand.wID = REBAR_BAR_TOOLBAR; //ID REBAR_BAR_TOOLBAR for toolbar + _rbBand.cxMinChild = 0; + _rbBand.cyIntegral = 1; + _rbBand.cyMinChild = _rbBand.cyMaxChild = getHeight(); + _rbBand.cxIdeal = _rbBand.cx = getWidth(); + + _pRebar->addBand(&_rbBand, true); + + _rbBand.fMask = RBBIM_CHILD | RBBIM_CHILDSIZE | RBBIM_IDEALSIZE | RBBIM_SIZE; +} + +void ReBar::init(HINSTANCE hInst, HWND hPere) +{ + Window::init(hInst, hPere); + + _hSelf = CreateWindowEx(WS_EX_TOOLWINDOW, + REBARCLASSNAME, + NULL, + WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|RBS_VARHEIGHT| + RBS_BANDBORDERS | CCS_NODIVIDER | CCS_NOPARENTALIGN, + 0,0,0,0, _hParent, NULL, _hInst, NULL); + + REBARINFO rbi; + ZeroMemory(&rbi, sizeof(REBARINFO)); + rbi.cbSize = sizeof(REBARINFO); + rbi.fMask = 0; + rbi.himl = (HIMAGELIST)NULL; + ::SendMessage(_hSelf, RB_SETBARINFO, 0, (LPARAM)&rbi); +} + +bool ReBar::addBand(REBARBANDINFO * rBand, bool useID) { + if (rBand->fMask & RBBIM_STYLE) + rBand->fStyle |= RBBS_GRIPPERALWAYS; + else + rBand->fStyle = RBBS_GRIPPERALWAYS; + rBand->fMask |= RBBIM_ID | RBBIM_STYLE; + if (useID) { + if (isIDTaken(rBand->wID)) + return false; + + } else { + rBand->wID = getNewID(); + } + ::SendMessage(_hSelf, RB_INSERTBAND, (WPARAM)-1, (LPARAM)rBand); //add to end of list + return true; +} + +void ReBar::reNew(int id, REBARBANDINFO * rBand) { + int index = (int)SendMessage(_hSelf, RB_IDTOINDEX, (WPARAM)id, 0); + ::SendMessage(_hSelf, RB_SETBANDINFO, (WPARAM)index, (LPARAM)rBand); +}; + +void ReBar::removeBand(int id) { + int index = (int)SendMessage(_hSelf, RB_IDTOINDEX, (WPARAM)id, 0); + if (id >= REBAR_BAR_EXTERNAL) + releaseID(id); + ::SendMessage(_hSelf, RB_DELETEBAND, (WPARAM)index, (LPARAM)0); +} + +void ReBar::setIDVisible(int id, bool show) { + int index = (int)SendMessage(_hSelf, RB_IDTOINDEX, (WPARAM)id, 0); + if (index == -1 ) + return; //error + REBARBANDINFO rbBand; + rbBand.cbSize = sizeof(rbBand); + rbBand.fMask = RBBIM_STYLE; + ::SendMessage(_hSelf, RB_GETBANDINFO, (WPARAM)index, (LPARAM)&rbBand); + if (show) + rbBand.fStyle &= (RBBS_HIDDEN ^ -1); + else + rbBand.fStyle |= RBBS_HIDDEN; + ::SendMessage(_hSelf, RB_SETBANDINFO, (WPARAM)index, (LPARAM)&rbBand); +} + +bool ReBar::getIDVisible(int id) { + int index = (int)SendMessage(_hSelf, RB_IDTOINDEX, (WPARAM)id, 0); + if (index == -1 ) + return false; //error + REBARBANDINFO rbBand; + rbBand.cbSize = sizeof(rbBand); + rbBand.fMask = RBBIM_STYLE; + ::SendMessage(_hSelf, RB_GETBANDINFO, (WPARAM)index, (LPARAM)&rbBand); + return ((rbBand.fStyle & RBBS_HIDDEN) == 0); +} + +int ReBar::getNewID() { + int idToUse = REBAR_BAR_EXTERNAL; + int curVal = 0; + size_t size = usedIDs.size(); + for(size_t i = 0; i < size; i++) { + curVal = usedIDs.at(i); + if (curVal < idToUse) { + continue; + } else if (curVal == idToUse) { + idToUse++; + } else { + break; //found gap + } + } + + usedIDs.push_back(idToUse); + return idToUse; +} + +void ReBar::releaseID(int id) { + size_t size = usedIDs.size(); + for(size_t i = 0; i < size; i++) { + if (usedIDs.at(i) == id) { + usedIDs.erase(usedIDs.begin()+i); + break; + } + } +} + +bool ReBar::isIDTaken(int id) { + size_t size = usedIDs.size(); + for(size_t i = 0; i < size; i++) { + if (usedIDs.at(i) == id) { + return true; + } + } + return false; +} + diff --git a/PowerEditor/src/WinControls/ToolBar/ToolBar.h b/PowerEditor/src/WinControls/ToolBar/ToolBar.h new file mode 100644 index 00000000..1c0979e4 --- /dev/null +++ b/PowerEditor/src/WinControls/ToolBar/ToolBar.h @@ -0,0 +1,174 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef TOOL_BAR_H +#define TOOL_BAR_H + +#include "Window.h" +#include "Notepad_plus_msgs.h" + +#define REBAR_BAR_TOOLBAR 0 +#define REBAR_BAR_SEARCH 1 + +#define REBAR_BAR_EXTERNAL 10 +#ifndef _WIN32_IE +#define _WIN32_IE 0x0600 +#endif //_WIN32_IE + +#include +#include +using namespace std; + +enum toolBarStatusType {/*TB_HIDE, */TB_SMALL, TB_LARGE, TB_STANDARD}; + +#include "ImageListSet.h" + + +typedef struct { + UINT message; // identification of icon in tool bar (menu ID) + HBITMAP hBmp; // bitmap for toolbar + HICON hIcon; // icon for toolbar +} tDynamicList; + +class ReBar; + +class ToolBar : public Window +{ +public : + ToolBar():Window(), _pTBB(NULL), _nrButtons(0), _nrDynButtons(0), _nrTotalButtons(0), _nrCurrentButtons(0), _pRebar(NULL) {}; + virtual ~ToolBar(){}; + + virtual bool init(HINSTANCE hInst, HWND hPere, toolBarStatusType type, + ToolBarButtonUnit *buttonUnitArray, int arraySize); + + virtual void destroy(); + void enable(int cmdID, bool doEnable) const { + ::SendMessage(_hSelf, TB_ENABLEBUTTON, cmdID, (LPARAM)doEnable); + }; + + int getWidth() const; + int getHeight() const; + + void reduce() { + if (_state == TB_SMALL) + return; + + _toolBarIcons.resizeIcon(16); + bool recreate = (_state == TB_STANDARD); + setState(TB_SMALL); + reset(recreate); //recreate toolbar if std icons were used + Window::redraw(); + }; + void enlarge() { + if (_state == TB_LARGE) + return; + + _toolBarIcons.resizeIcon(32); + bool recreate = (_state == TB_STANDARD); + setState(TB_LARGE); + reset(recreate); //recreate toolbar if std icons were used + Window::redraw(); + }; + void setToUglyIcons() { + if (_state == TB_STANDARD) + return; + bool recreate = true; + setState(TB_STANDARD); + reset(recreate); //must recreate toolbar if setting to internal bitmaps + Window::redraw(); + } + + bool getCheckState(int ID2Check) const { + return bool(::SendMessage(_hSelf, TB_GETSTATE, (WPARAM)ID2Check, 0) & TBSTATE_CHECKED); + }; + + void setCheck(int ID2Check, bool willBeChecked) const { + ::SendMessage(_hSelf, TB_CHECKBUTTON, (WPARAM)ID2Check, (LPARAM)MAKELONG(willBeChecked, 0)); + }; + + toolBarStatusType getState() const { + return _state; + }; + + bool changeIcons(int whichLst, int iconIndex, const TCHAR *iconLocation){ + return _toolBarIcons.replaceIcon(whichLst, iconIndex, iconLocation); + }; + + void registerDynBtn(UINT message, toolbarIcons* hBmp); + + void doPopop(POINT chevPoint); //show the popup if buttons are hidden + + void addToRebar(ReBar * rebar); + +private : + TBBUTTON *_pTBB; + ToolBarIcons _toolBarIcons; + toolBarStatusType _state; + vector _vDynBtnReg; + size_t _nrButtons; + size_t _nrDynButtons; + size_t _nrTotalButtons; + size_t _nrCurrentButtons; + ReBar * _pRebar; + REBARBANDINFO _rbBand; + + + void setDefaultImageList() { + ::SendMessage(_hSelf, TB_SETIMAGELIST , (WPARAM)0, (LPARAM)_toolBarIcons.getDefaultLst()); + }; + void setHotImageList() { + ::SendMessage(_hSelf, TB_SETHOTIMAGELIST , (WPARAM)0, (LPARAM)_toolBarIcons.getHotLst()); + }; + void setDisableImageList() { + ::SendMessage(_hSelf, TB_SETDISABLEDIMAGELIST, (WPARAM)0, (LPARAM)_toolBarIcons.getDisableLst()); + }; + + void reset(bool create = false); + void setState(toolBarStatusType state) { + _state = state; + } + +}; + +class ReBar : public Window +{ +public : + ReBar():Window() { usedIDs.clear(); }; + + virtual void destroy() { + ::DestroyWindow(_hSelf); + _hSelf = NULL; + usedIDs.clear(); + }; + + void init(HINSTANCE hInst, HWND hPere); + bool addBand(REBARBANDINFO * rBand, bool useID); //useID true if ID from info should be used (false for plugins). wID in bandinfo will be set to used ID + void reNew(int id, REBARBANDINFO * rBand); //wID from bandinfo is used for update + void removeBand(int id); + + void setIDVisible(int id, bool show); + bool getIDVisible(int id); + +private: + vector usedIDs; + + int getNewID(); + void releaseID(int id); + bool isIDTaken(int id); +}; + +#endif // TOOL_BAR_H diff --git a/PowerEditor/src/WinControls/ToolTip/ToolTip.cpp b/PowerEditor/src/WinControls/ToolTip/ToolTip.cpp new file mode 100644 index 00000000..63cf4209 --- /dev/null +++ b/PowerEditor/src/WinControls/ToolTip/ToolTip.cpp @@ -0,0 +1,81 @@ +/* +this file is part of notepad++ +Copyright (C)2003 Don HO < donho@altern.org > + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "ToolTip.h" + + + +LRESULT CALLBACK dlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); + + +void ToolTip::init(HINSTANCE hInst, HWND hParent) +{ + if (_hSelf == NULL) + { + Window::init(hInst, hParent); + + _hSelf = CreateWindowEx( 0, TOOLTIPS_CLASS, NULL, WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, + CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, NULL, NULL ); + if (!_hSelf) + { + systemMessage(TEXT("System Err")); + throw int(6969); + } + + ::SetWindowLongPtr(_hSelf, GWL_USERDATA, reinterpret_cast(this)); + _defaultProc = reinterpret_cast(::SetWindowLongPtr(_hSelf, GWL_WNDPROC, reinterpret_cast(staticWinProc))); + } +} + + +void ToolTip::Show(RECT rectTitle, TCHAR * pszTitle, int iXOff, int iWidthOff) +{ + if (isVisible()) + destroy(); + + if (lstrlen(pszTitle) == 0) + return; + + // INITIALIZE MEMBERS OF THE TOOLINFO STRUCTURE + _ti.cbSize = sizeof(TOOLINFO); + _ti.uFlags = TTF_TRACK | TTF_ABSOLUTE; + _ti.hwnd = ::GetParent(_hParent); + _ti.hinst = _hInst; + _ti.uId = 0; + + _ti.rect.left = rectTitle.left; + _ti.rect.top = rectTitle.top; + _ti.rect.right = rectTitle.right; + _ti.rect.bottom = rectTitle.bottom; + + HFONT _hFont = (HFONT)::SendMessage(_hParent, WM_GETFONT, 0, 0); + ::SendMessage(_hSelf, WM_SETFONT, reinterpret_cast(_hFont), TRUE); + + _ti.lpszText = pszTitle; + ::SendMessage(_hSelf, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &_ti); + ::SendMessage(_hSelf, TTM_TRACKPOSITION, 0, (LPARAM)(DWORD) MAKELONG(_ti.rect.left + iXOff, _ti.rect.top + iWidthOff)); + ::SendMessage(_hSelf, TTM_TRACKACTIVATE, true, (LPARAM)(LPTOOLINFO) &_ti); +} + + +LRESULT ToolTip::runProc(UINT message, WPARAM wParam, LPARAM lParam) +{ + return ::CallWindowProc(_defaultProc, _hSelf, message, wParam, lParam); +} + diff --git a/PowerEditor/src/WinControls/ToolTip/ToolTip.h b/PowerEditor/src/WinControls/ToolTip/ToolTip.h new file mode 100644 index 00000000..aa0db2d4 --- /dev/null +++ b/PowerEditor/src/WinControls/ToolTip/ToolTip.h @@ -0,0 +1,63 @@ +/* +this file is part of notepad++ +Copyright (C)2003 Don HO < donho@altern.org > + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef __TOOLTIP_H__ +#define __TOOLTIP_H__ + +#include +#include "Notepad_plus.h" +#include "Window.h" +#include + + +using namespace std; + + +class ToolTip : public Window +{ +public : + ToolTip() : _bTrackMouse(FALSE) {}; + + void destroy(void){ + ::DestroyWindow(_hSelf); + _hSelf = NULL; + }; + +// Attributes +public: + +// Implementation +public: + virtual void init(HINSTANCE hInst, HWND hParent); + void Show(RECT rectTitle, TCHAR* pszTitleText, int iXOff = 0, int iWidthOff = 0); + +protected: + WNDPROC _defaultProc; + BOOL _bTrackMouse; + TOOLINFO _ti; + + + static LRESULT CALLBACK staticWinProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { + return (((ToolTip *)(::GetWindowLongPtr(hwnd, GWL_USERDATA)))->runProc(Message, wParam, lParam)); + }; + LRESULT runProc(UINT Message, WPARAM wParam, LPARAM lParam); + void SendHitMessage(void); +}; + +#endif // __TOOLTIP_H__ diff --git a/PowerEditor/src/WinControls/TrayIcon/trayIconControler.cpp b/PowerEditor/src/WinControls/TrayIcon/trayIconControler.cpp new file mode 100644 index 00000000..6cd2c4e2 --- /dev/null +++ b/PowerEditor/src/WinControls/TrayIcon/trayIconControler.cpp @@ -0,0 +1,26 @@ +#include "trayIconControler.h" +#include +trayIconControler::trayIconControler(HWND hwnd, UINT uID, UINT uCBMsg, HICON hicon, TCHAR *tip) +{ + _nid.cbSize = sizeof(_nid); + _nid.hWnd = hwnd; + _nid.uID = uID; + _nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; + _nid.uCallbackMessage = uCBMsg; + _nid.hIcon = hicon; + lstrcpy(_nid.szTip, tip); + + ::RegisterWindowMessage(TEXT("TaskbarCreated")); + _isIconShowed = false; +} + +int trayIconControler::doTrayIcon(DWORD op) +{ + if ((op != ADD)&&(op != REMOVE)) return INCORRECT_OPERATION; + if (((_isIconShowed)&&(op == ADD))||((!_isIconShowed)&&(op == REMOVE))) + return OPERATION_INCOHERENT; + ::Shell_NotifyIcon(op, &_nid); + _isIconShowed = !_isIconShowed; + + return 0; +} diff --git a/PowerEditor/src/WinControls/TrayIcon/trayIconControler.h b/PowerEditor/src/WinControls/TrayIcon/trayIconControler.h new file mode 100644 index 00000000..c4dd3c44 --- /dev/null +++ b/PowerEditor/src/WinControls/TrayIcon/trayIconControler.h @@ -0,0 +1,25 @@ +#ifndef TRAY_ICON_CONTROLER_H +#define TRAY_ICON_CONTROLER_H + +#include + +#define ADD NIM_ADD +#define REMOVE NIM_DELETE + +// code d'erreur +#define INCORRECT_OPERATION 1 +#define OPERATION_INCOHERENT 2 + +class trayIconControler +{ +public: + trayIconControler(HWND hwnd, UINT uID, UINT uCBMsg, HICON hicon, TCHAR *tip); + int doTrayIcon(DWORD op); + bool isInTray() const {return _isIconShowed;}; + +private: + NOTIFYICONDATA _nid; + bool _isIconShowed; +}; + +#endif //TRAY_ICON_CONTROLER_H diff --git a/PowerEditor/src/WinControls/TreeView/TreeView.cpp b/PowerEditor/src/WinControls/TreeView/TreeView.cpp new file mode 100644 index 00000000..86e20089 --- /dev/null +++ b/PowerEditor/src/WinControls/TreeView/TreeView.cpp @@ -0,0 +1,73 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#include "TreeView.h" + +HTREEITEM TreeView::insertTo(HTREEITEM parent, TCHAR *itemStr, int imgIndex) +{ + TV_INSERTSTRUCT tvinsert; + tvinsert.hParent=parent; + tvinsert.hInsertAfter=parent?TVI_LAST:TVI_ROOT; + tvinsert.item.mask=TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE; + tvinsert.item.pszText=itemStr; + tvinsert.item.iImage=imgIndex; + tvinsert.item.iSelectedImage=0; + return (HTREEITEM)::SendMessage(_hSelf, TVM_INSERTITEM, 0, (LPARAM)&tvinsert); +} + +void TreeView::init(HINSTANCE hInst, HWND pere) +{ + Window::init(hInst, pere); + InitCommonControls(); + + HTREEITEM Parent; // Tree item handle + HTREEITEM Before; // ....... + HTREEITEM Root; + + // Get the dimensions of the parent window's client area, and create + // the tree-view control. + + _hSelf = CreateWindowEx(0, + WC_TREEVIEW, + TEXT("Tree View"), + WS_VISIBLE | WS_CHILD | WS_BORDER | + TVS_HASLINES | TVS_HASBUTTONS | TVS_SHOWSELALWAYS , + 0, 0, 0, 0, + _hParent, + NULL, + _hInst, + NULL); + + if (!_hSelf) + throw int(56); + + Parent = insertTo(NULL, TEXT("MAOCS30 Command"), 0); + Root=Parent; + Before=Parent; + + Parent = insertTo(Parent, TEXT("Native command"), 0); + insertTo(Parent, TEXT("Power On"), 0); + insertTo(Parent, TEXT("Power off"), 0); + insertTo(Parent, TEXT("Entrant"), 0); + insertTo(Parent, TEXT("Sortant"), 0); + Parent = insertTo(Before, TEXT("Macro"), 0); + insertTo(Parent, TEXT("ChangeCode"), 0); + insertTo(Parent, TEXT("CipherData"), 0); + + insertTo(NULL, TEXT("Bla bla bla bla..."), 0); + //display(); +} \ No newline at end of file diff --git a/PowerEditor/src/WinControls/TreeView/TreeView.h b/PowerEditor/src/WinControls/TreeView/TreeView.h new file mode 100644 index 00000000..5d6deeb9 --- /dev/null +++ b/PowerEditor/src/WinControls/TreeView/TreeView.h @@ -0,0 +1,44 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef TREE_VIEW_H +#define TREE_VIEW_H + +#include +#include "Window.h" + +#ifndef _WIN32_IE +#define _WIN32_IE 0x0600 +#endif //_WIN32_IE + +#include + +class TreeView : public Window +{ +public : + TreeView(){}; + ~TreeView(){}; + virtual void init(HINSTANCE hInst, HWND pere); + virtual void destroy() { + ::DestroyWindow(_hSelf); + }; + +private : + HTREEITEM insertTo(HTREEITEM parent, TCHAR *itemStr, int imgIndex); +}; + +#endif \ No newline at end of file diff --git a/PowerEditor/src/WinControls/Window.h b/PowerEditor/src/WinControls/Window.h new file mode 100644 index 00000000..7bd64cbd --- /dev/null +++ b/PowerEditor/src/WinControls/Window.h @@ -0,0 +1,119 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef WINDOW_CONTROL_H +#define WINDOW_CONTROL_H + +#include + +class Window +{ +public: + Window(): _hInst(NULL), _hParent(NULL), _hSelf(NULL){}; + virtual ~Window() {}; + + virtual void init(HINSTANCE hInst, HWND parent) + { + _hInst = hInst; + _hParent = parent; + } + + virtual void destroy() = 0; + + virtual void display(bool toShow = true) const { + ::ShowWindow(_hSelf, toShow?SW_SHOW:SW_HIDE); + }; + + virtual void reSizeTo(RECT & rc) // should NEVER be const !!! + { + ::MoveWindow(_hSelf, rc.left, rc.top, rc.right, rc.bottom, TRUE); + redraw(); + }; + + virtual void reSizeToWH(RECT & rc) // should NEVER be const !!! + { + ::MoveWindow(_hSelf, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, TRUE); + redraw(); + }; + + virtual void redraw() const { + ::InvalidateRect(_hSelf, NULL, TRUE); + ::UpdateWindow(_hSelf); + }; + + virtual void getClientRect(RECT & rc) const { + ::GetClientRect(_hSelf, &rc); + }; + + virtual void getWindowRect(RECT & rc) const { + ::GetWindowRect(_hSelf, &rc); + }; + + virtual int getWidth() const { + RECT rc; + ::GetClientRect(_hSelf, &rc); + return (rc.right - rc.left); + }; + + virtual int getHeight() const { + RECT rc; + ::GetClientRect(_hSelf, &rc); + if (::IsWindowVisible(_hSelf) == TRUE) + return (rc.bottom - rc.top); + return 0; + }; + + virtual bool isVisible() const { + return (::IsWindowVisible(_hSelf)?true:false); + }; + + HWND getHSelf() const { + /* + if (!_hSelf) + { + ::MessageBox(NULL, TEXT("_hSelf == NULL"), TEXT("class Window"), MB_OK); + throw int(999); + } + */ + return _hSelf; + }; + + HWND getHParent() const { + return _hParent; + }; + + void getFocus() const { + ::SetFocus(_hSelf); + }; + + HINSTANCE getHinst() const { + if (!_hInst) + { + ::MessageBox(NULL, TEXT("_hInst == NULL"), TEXT("class Window"), MB_OK); + throw int(1999); + } + return _hInst; + }; +protected: + HINSTANCE _hInst; + HWND _hParent; + HWND _hSelf; +}; + +#endif //WINDOW_CONTROL_H + + diff --git a/PowerEditor/src/WinControls/WindowInterface.h b/PowerEditor/src/WinControls/WindowInterface.h new file mode 100644 index 00000000..276a1e6d --- /dev/null +++ b/PowerEditor/src/WinControls/WindowInterface.h @@ -0,0 +1,33 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef WINDOW_INTERFACE_H +#define WINDOW_INTERFACE_H + +#include "Window.h" + +class WindowInterface : public Window +{ +public : + void init(HINSTANCE hInst, HWND parent, HWND hSelf) { + Window::init(hInst, parent); + _hSelf = hSelf; + }; + virtual void destroy() {}; +}; + +#endif // WINDOW_INTERFACE_H diff --git a/PowerEditor/src/WinControls/WindowsDlg/SizeableDlg.cpp b/PowerEditor/src/WinControls/WindowsDlg/SizeableDlg.cpp new file mode 100644 index 00000000..ff358309 --- /dev/null +++ b/PowerEditor/src/WinControls/WindowsDlg/SizeableDlg.cpp @@ -0,0 +1,58 @@ +#include +#include "WindowsDlg.h" +#include "WindowsDlgRc.h" + +SizeableDlg::SizeableDlg(WINRECT* pWinMap) + : MyBaseClass(), _winMgr(pWinMap) +{ +} + +BOOL SizeableDlg::onInitDialog() +{ + _winMgr.InitToFitSizeFromCurrent(_hSelf); + _winMgr.CalcLayout(_hSelf); + _winMgr.SetWindowPositions(_hSelf); + //getClientRect(_rc); + return TRUE; +} + +void SizeableDlg::onSize(UINT nType, int cx, int cy) +{ + _winMgr.CalcLayout(cx,cy,_hSelf); + _winMgr.SetWindowPositions(_hSelf); +} + +void SizeableDlg::onGetMinMaxInfo(MINMAXINFO* lpMMI) +{ + _winMgr.GetMinMaxInfo(_hSelf, lpMMI); +} + +LRESULT SizeableDlg::onWinMgr(WPARAM wp, LPARAM lp) +{ + return 0; +} + +BOOL CALLBACK SizeableDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) +{ + switch (message) + { + case WM_INITDIALOG : + return onInitDialog(); + + case WM_GETMINMAXINFO : + onGetMinMaxInfo((MINMAXINFO*)lParam); + return TRUE; + + case WM_SIZE: + onSize(wParam, LOWORD(lParam), HIWORD(lParam)); + return TRUE; + + default: + if (message == WM_WINMGR) + { + return (BOOL)onWinMgr(wParam, lParam); + } + break; + } + return FALSE; +} \ No newline at end of file diff --git a/PowerEditor/src/WinControls/WindowsDlg/SizeableDlg.h b/PowerEditor/src/WinControls/WindowsDlg/SizeableDlg.h new file mode 100644 index 00000000..2d4f2c8a --- /dev/null +++ b/PowerEditor/src/WinControls/WindowsDlg/SizeableDlg.h @@ -0,0 +1,20 @@ + + +#include "StaticDialog.h" +#include "WindowsDlgRc.h" +#include "WinMgr.h" + +class SizeableDlg : public StaticDialog { + typedef StaticDialog MyBaseClass; +public: + SizeableDlg(WINRECT* pWinMap); + +protected: + CWinMgr _winMgr; // window manager + + virtual BOOL CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam); + virtual BOOL onInitDialog(); + virtual void onSize(UINT nType, int cx, int cy); + virtual void onGetMinMaxInfo(MINMAXINFO* lpMMI); + virtual LRESULT onWinMgr(WPARAM wp, LPARAM lp); +}; diff --git a/PowerEditor/src/WinControls/WindowsDlg/WinMgr.cpp b/PowerEditor/src/WinControls/WindowsDlg/WinMgr.cpp new file mode 100644 index 00000000..88cc623c --- /dev/null +++ b/PowerEditor/src/WinControls/WindowsDlg/WinMgr.cpp @@ -0,0 +1,480 @@ +//////////////////////////////////////////////////////////////// +// MSDN Magazine -- July 2001 +// If this code works, it was written by Paul DiLascia. +// If not, I don't know who wrote it. +// Compiles with Visual C++ 6.0. Runs on Win 98 and probably Win 2000 too. +// Set tabsize = 3 in your editor. +// +// Theo - Heavily modified to remove MFC dependencies. +// Replaced CWnd*/HWND, CRect/RECT, CSize/SIZE, CPoint/POINT + +#include +#include +#include "WinMgr.h" + +// Theo - Style Helpers +inline static DWORD GetStyle(HWND hWnd) { + return (DWORD)GetWindowLongPtr(hWnd, GWL_STYLE); +} + +inline static DWORD GetExStyle(HWND hWnd) { + return (DWORD)GetWindowLongPtr(hWnd, GWL_EXSTYLE); +} + +const UINT WM_WINMGR = RegisterWindowMessage(TEXT("WM_WINMGR")); + +CWinMgr::CWinMgr(WINRECT* pWinMap) : m_map(pWinMap) +{ + WINRECT::InitMap(m_map); +} + +CWinMgr::~CWinMgr() +{ +} + +////////////////// +// Set each control's tofit (desired) size to current size. Useful for +// dialogs, to "remember" the current sizes as desired size. +// +void CWinMgr::InitToFitSizeFromCurrent(HWND hWnd) +{ + assert(hWnd); + assert(m_map); + GetWindowPositions(hWnd); + for (WINRECT* w = m_map; !w->IsEnd(); w++) { + if (w->Type()==WRCT_TOFIT && !w->IsGroup()) { + w->SetToFitSize(RectToSize(w->GetRect())); + } + } +} + +////////////////// +// Load all rectangles from current window positions. +// +void CWinMgr::GetWindowPositions(HWND hWnd) +{ + assert(m_map); + assert(hWnd); + for (WINRECT* wrc=m_map; !wrc->IsEnd(); wrc++) { + if (wrc->IsWindow()) { + HWND HChild = GetDlgItem(hWnd, wrc->GetID()); + if (HChild) { + GetWindowRect(HChild, &wrc->GetRect()); + ::ScreenToClient(hWnd, &RectToPoint(wrc->GetRect())); + } + } + } +} + +////////////////// +// Move all the windows. Use DeferWindowPos for speed. +// +void +CWinMgr::SetWindowPositions(HWND hWnd) +{ + int nWindows = CountWindows(); + if (m_map && hWnd && nWindows>0) { + HDWP hdwp = ::BeginDeferWindowPos(nWindows); + int count=0; + for (WINRECT* wrc=m_map; !wrc->IsEnd(); wrc++) { + if (wrc->IsWindow()) { + assert(count < nWindows); + HWND hwndChild = ::GetDlgItem(hWnd, wrc->GetID()); + if (hwndChild) { + const RECT& rc = wrc->GetRect(); + ::DeferWindowPos(hdwp, + hwndChild, + NULL, // HWND insert after + rc.left,rc.top,RectWidth(rc),RectHeight(rc), + SWP_NOZORDER); + InvalidateRect(hwndChild,NULL,TRUE); // repaint + count++; + } + } else { + // not a window: still need to repaint background + InvalidateRect(hWnd, &wrc->GetRect(), TRUE); + } + } + ::EndDeferWindowPos(hdwp); + } +} + +////////////////// +// Count number of table entries that correspond to windows--ie, +// that have a child window ID associated with the entry. +// +int CWinMgr::CountWindows() +{ + assert(m_map); + int nWin = 0; + for (WINRECT* w=m_map; !w->IsEnd(); w++) { + if (w->IsWindow()) + nWin++; + } + return nWin; +} + +////////////////// +// Find the entry for a given control ID +// +WINRECT* CWinMgr::FindRect(UINT nID) +{ + assert(m_map); + for (WINRECT* w=m_map; !w->IsEnd(); w++) { + if (w->GetID()==nID) + return w; + } + return NULL; +} + +////////////////// +// Calculate size/positions for a row or column group This is the main +// algorithm. If a window is given, it's used to get the min/max size and +// desired size for TOFIT types. +// +void +CWinMgr::CalcGroup(WINRECT* pGroup, HWND hWnd) +{ + // If this bombs, most likely the first entry in your map is not a group! + assert(pGroup && pGroup->IsGroup()); + assert(hWnd); + + // adjust total avail by margins + RECT rcTotal = pGroup->GetRect(); + int w,h; + if (pGroup->GetMargins(w,h)) { + w = min(abs(w), RectWidth(rcTotal)/2); + h = min(abs(h), RectHeight(rcTotal)/2); + ::InflateRect(&rcTotal, -w, -h); + } + + BOOL bRow = pGroup->IsRowGroup(); // Is this a row group? + + // Running height or width: start with total + int hwRemaining = bRow ? RectHeight(rcTotal) : RectWidth(rcTotal); + + // First, set all rects to their minimum sizes. + // This ensures that each rect gets its min size. + CWinGroupIterator it; + for (it=pGroup; it; it.Next()) { + WINRECT* wrc = it; + SIZEINFO szi; + OnGetSizeInfo(szi, wrc, hWnd); + int hwMin = bRow ? szi.szMin.cy : szi.szMin.cx; + hwMin = min(hwMin, hwRemaining); // truncate + wrc->SetHeightOrWidth(hwMin, bRow); // set + hwRemaining -= hwMin; // decrement remaining height/width + assert(hwRemaining>=0); + } + + // Now adjust all rects upward to desired size. Save REST rect for last. + WINRECT* pRestRect = NULL; + for (it=pGroup; it; it.Next()) { + WINRECT* wrc = it; + if (wrc->Type()==WRCT_REST) { + assert(pRestRect==NULL); // can only be one REST rect! + pRestRect = wrc; // remember it + } else { + AdjustSize(wrc, bRow, hwRemaining, hWnd); + } + } + assert(hwRemaining>=0); + + // Adjust REST rect if any + if (pRestRect) { + AdjustSize(pRestRect, bRow, hwRemaining, hWnd); + assert(hwRemaining==0); + } + + // All the sizes of the entries have been calculated, including + // groups (but not their children). Now move all the rects so they're + // adjacent to one another, without altering sizes. + PositionRects(pGroup, rcTotal, bRow); + + // Finally, descend recursively into each subgroup. + for (it=pGroup; it; it.Next()) { + WINRECT* wrc = it; + if (wrc->IsGroup()) + CalcGroup(wrc, hWnd); // recurse! + } +} + +////////////////// +// Adjust the size of a single entry upwards to its desired size. +// Decrement hwRemaining by amount increased. +// +void +CWinMgr::AdjustSize(WINRECT* wrc, BOOL bRow, + int& hwRemaining, HWND hWnd) +{ + SIZEINFO szi; + OnGetSizeInfo(szi, wrc, hWnd); + int hw = bRow ? szi.szDesired.cy : szi.szDesired.cx; // desired ht or wid + if (wrc->Type() == WRCT_REST) { + // for REST type, use all remaining space + RECT& rc = wrc->GetRect(); + hw = hwRemaining + (bRow ? RectHeight(rc) : RectWidth(rc)); + } + + // Now hw is the desired height or width, and the current size of the + // entry is the min size. So adjust the size upwards, and decrement + // hwRemaining appropriately. This is a little confusing, but necessary so + // each entry gets its min size. + // + int hwCurrent = wrc->GetHeightOrWidth(bRow); // current size + int hwExtra = hw - hwCurrent; // amount extra + hwExtra = min(max(hwExtra, 0), hwRemaining); // truncate + hw = hwCurrent + hwExtra; // new height-or-width + wrc->SetHeightOrWidth(hw, bRow); // set... + hwRemaining -= hwExtra; // and adjust remaining +} + +////////////////// +// Position all the rects so they're as wide/high as the total and follow one +// another; ie, are adjacent. This operation leaves the height (rows) and +// width (columns) unaffected. For rows, set each row's width to rcTotal and +// one below the other; for columns, set each column as tall as rcTotal and +// each to the right of the previous. +// +void +CWinMgr::PositionRects(WINRECT* pGroup, const RECT& rcTotal, BOOL bRow) +{ + LONG xoryPos = bRow ? rcTotal.top : rcTotal.left; + + CWinGroupIterator it; + for (it=pGroup; it; it.Next()) { + WINRECT* wrc = it; + RECT& rc = wrc->GetRect(); + if (bRow) { // for ROWS: + LONG height = RectHeight(rc); // height of row = total height + rc.top = xoryPos; // top = running yPos + rc.bottom = rc.top + height; // ... + rc.left = rcTotal.left; // ... + rc.right = rcTotal.right; // ... + xoryPos += height; // increment yPos + + } else { // for COLS: + LONG width = RectWidth(rc); // width = total width + rc.left = xoryPos; // left = running xPos + rc.right = rc.left + width; // ... + rc.top = rcTotal.top; // ... + rc.bottom = rcTotal.bottom; // ... + xoryPos += width; // increment xPos + } + } +} + +////////////////// +// Get size information for a single entry (WINRECT). Returns size info in +// the SIZEINFO argument. For a group, calculate size info as aggregate of +// subentries. +// +void +CWinMgr::OnGetSizeInfo(SIZEINFO& szi, WINRECT* wrc, HWND hWnd) +{ + szi.szMin = SIZEZERO; // default min size = zero + szi.szMax = SIZEMAX; // default max size = infinite + szi.szDesired = RectToSize(wrc->GetRect()); // default desired size = current + + if (wrc->IsGroup()) { + // For groups, calculate min, max, desired size as aggregate of children + szi.szDesired = SIZEZERO; + BOOL bRow = wrc->IsRowGroup(); + + CWinGroupIterator it; + for (it=wrc; it; it.Next()) { + WINRECT* wrc2 = it; + SIZEINFO szi2; + OnGetSizeInfo(szi2, wrc2, hWnd); + if (bRow) { + szi.szMin.cx = max(szi.szMin.cx, szi2.szMin.cx); + szi.szMin.cy += szi2.szMin.cy; + szi.szMax.cx = min(szi.szMax.cx, szi2.szMax.cx); + szi.szMax.cy = min(szi.szMax.cy + szi2.szMax.cy, INFINITY); + szi.szDesired.cx = max(szi.szDesired.cx, szi2.szDesired.cx); + szi.szDesired.cy += szi2.szDesired.cy; + + } else { + szi.szMin.cx += szi2.szMin.cx; + szi.szMin.cy = max(szi.szMin.cy, szi2.szMin.cy); + szi.szMax.cx = min(szi.szMax.cx + szi2.szMax.cx, INFINITY); + szi.szMax.cy = min(szi.szMax.cy, szi2.szMax.cy); + szi.szDesired.cx += szi2.szDesired.cx; + szi.szDesired.cy = max(szi.szDesired.cy, szi2.szDesired.cy); + } + } + + // Add margins. + int w2,h2; + wrc->GetMargins(w2,h2); // get margins + w2<<=1; h2<<=1; // double + szi.szMin.cx += max(0,w2); // negative margins ==> don't include in min + szi.szMin.cy += max(0,h2); // ditto + szi.szDesired.cx += abs(w2); // for desired size, use abs vallue + szi.szDesired.cy += abs(h2); // ditto + + } else { + // not a group + WINRECT* parent = wrc->Parent(); + assert(parent); + RECT& rcParent = parent->GetRect(); + BOOL bRow = parent->IsRowGroup(); + int hw, hwMin, hwTotal, pct; + + switch (wrc->Type()) { + case WRCT_FIXED: + hw = hwMin = wrc->GetParam(); // ht/wid is parameter + if (hw<0) { // if fixed val is negative: + hw = -hw; // use absolute val for desired.. + hwMin = 0; // ..and zero for minimum + } + if (bRow) { + szi.szMax.cy = szi.szDesired.cy = hw; + szi.szMin.cy = hwMin; + } else { + szi.szMax.cx = szi.szDesired.cx = hw; + szi.szMin.cx = hwMin; + } + break; + + case WRCT_PCT: + pct = wrc->GetParam(); + assert(0HasToFitSize()) { + szi.szDesired = wrc->GetToFitSize(); + } + break; + + case WRCT_REST: + break; + + default: + assert(FALSE); + } + + // If the entry is a window, send message to get min/max/tofit size. + // Only set tofit size if type is TOFIT. + // + if (wrc->IsWindow() && hWnd) { + HWND hChild = GetDlgItem(hWnd, wrc->GetID()); + if (hChild) { + if (!IsWindowVisible(hChild) && IsWindowVisible(hWnd)) { + // parent visible but child not ==> tofit size is zero + // important so hidden windows use no space + szi.szDesired = SIZEZERO; + } else { + szi.szAvail = RectToSize(rcParent); + SendGetSizeInfo(szi, hWnd, wrc->GetID()); + } + } + } + szi.szDesired = maxsize(minsize(szi.szDesired,szi.szMax), szi.szMin); + } +} + +////////////////// +// Send message to parent, then window itself, to get size info. +// +BOOL CWinMgr::SendGetSizeInfo(SIZEINFO& szi, HWND hWnd, UINT nID) +{ + NMWINMGR nmw; + nmw.code = NMWINMGR::GET_SIZEINFO; // request size info + nmw.idFrom = nID; // ID of child I'm computing + nmw.sizeinfo = szi; // copy + + if (!SendMessage(hWnd, WM_WINMGR, nID, (LPARAM)&nmw) && !nmw.processed) { + HWND hwndChild = ::GetDlgItem(hWnd, nID); + if (!hwndChild || !::SendMessage(hwndChild,WM_WINMGR,nID,(LPARAM)&nmw)) + return FALSE; + } + szi = nmw.sizeinfo; // copy back to caller's struct + return TRUE; +} + +////////////////// +// Get min/max info. +// +void +CWinMgr::GetMinMaxInfo(HWND hWnd, MINMAXINFO* lpMMI) +{ + SIZEINFO szi; + GetMinMaxInfo(hWnd, szi); // call overloaded version + lpMMI->ptMinTrackSize = SizeToPoint(szi.szMin); + lpMMI->ptMaxTrackSize = SizeToPoint(szi.szMax); +} + +////////////////// +// Get min/max info. +// +void CWinMgr::GetMinMaxInfo(HWND hWnd, SIZEINFO& szi) +{ + OnGetSizeInfo(szi, m_map, hWnd); // get size info + if (!hWnd) // window not created ==> done + return; + + // Add extra space for frame/dialog screen junk. + DWORD dwStyle = GetStyle(hWnd); + DWORD dwExStyle = GetExStyle(hWnd); + if (dwStyle & WS_VISIBLE) { + SIZE& szMin = szi.szMin; // ref! + if (!(dwStyle & WS_CHILD)) { + if (dwStyle & WS_CAPTION) + szMin.cy += GetSystemMetrics(SM_CYCAPTION); + if (::GetMenu(hWnd)) + szMin.cy += GetSystemMetrics(SM_CYMENU); + } + if (dwStyle & WS_THICKFRAME) { + szMin.cx += 2*GetSystemMetrics(SM_CXSIZEFRAME); + szMin.cy += 2*GetSystemMetrics(SM_CYSIZEFRAME); + } else if (dwStyle & WS_BORDER) { + szMin.cx += 2*GetSystemMetrics(SM_CXBORDER); + szMin.cy += 2*GetSystemMetrics(SM_CYBORDER); + } + if (dwExStyle & WS_EX_CLIENTEDGE) { + szMin.cx += 2*GetSystemMetrics(SM_CXEDGE); + szMin.cy += 2*GetSystemMetrics(SM_CYEDGE); + } + } +} + +////////////////// +// Move desired rectangle by a given vector amount. +// Call this when a sizer bar tells you it has moved. +// +void CWinMgr::MoveRect(WINRECT* pwrcMove, POINT ptMove, HWND pParentWnd) +{ + assert(pwrcMove); + WINRECT* prev = pwrcMove->Prev(); + assert(prev); + WINRECT* next = pwrcMove->Next(); + assert(next); + + BOOL bIsRow = pwrcMove->Parent()->IsRowGroup(); + + RECT& rcNext = next->GetRect(); + RECT& rcPrev = prev->GetRect(); + if (bIsRow) { + // a row can only be moved up or down + ptMove.x = 0; + rcPrev.bottom += ptMove.y; + rcNext.top += ptMove.y; + } else { + // a column can only be moved left or right + ptMove.y = 0; + rcPrev.right += ptMove.x; + rcNext.left += ptMove.x; + } + OffsetRect(pwrcMove->GetRect(), ptMove); + if (prev->IsGroup()) + CalcGroup(prev, pParentWnd); + if (next->IsGroup()) + CalcGroup(next, pParentWnd); +} + +// Theo - Removed Tracing diff --git a/PowerEditor/src/WinControls/WindowsDlg/WinMgr.h b/PowerEditor/src/WinControls/WindowsDlg/WinMgr.h new file mode 100644 index 00000000..30421805 --- /dev/null +++ b/PowerEditor/src/WinControls/WindowsDlg/WinMgr.h @@ -0,0 +1,303 @@ +//////////////////////////////////////////////////////////////// +// MSDN Magazine -- July 2001 +// If this code works, it was written by Paul DiLascia. +// If not, I don't know who wrote it. +// Compiles with Visual C++ 6.0. Runs on Win 98 and probably Win 2000 too. +// Set tabsize = 3 in your editor. +// +// WinMgr.h -- Main header file for WinMgr library. +// +// Theo - Heavily modified to remove MFC dependencies +// Replaced CWnd*/HWND, CRect/RECT, CSize/SIZE, CPoint/POINT +#ifndef WINMGR_H +#define WINMGR_H + +#ifndef _WINDOWS_H_ +# include +#endif +#include + +#pragma once + +// when using screen dimensions, this is infinite +//const LONG INFINITY=0x7fff; // max short +//change to DEFINE for GCC +#define INFINITY 0x7fff // max short + +const SIZE SIZEZERO = {0, 0}; +const SIZE SIZEMAX = {INFINITY,INFINITY}; + +inline SIZE GetSize(LONG w, LONG h) { + SIZE sz = {w, h}; return sz; +} + +inline POINT GetPoint(LONG x, LONG y) { + POINT pt = {x, y}; return pt; +} + +inline LONG RectWidth(const RECT& rc) { + return rc.right - rc.left; +} + +inline LONG RectHeight(const RECT& rc) { + return rc.bottom - rc.top; +} + +inline SIZE RectToSize(const RECT& rc) { + return GetSize(RectWidth(rc), RectHeight(rc)); +} + +inline POINT RectToPoint(const RECT& rc) { + POINT pt = {rc.left, rc.top}; + return pt; +} + +inline POINT SizeToPoint(SIZE sz) { + return GetPoint(sz.cx, sz.cy); +} + +inline RECT &OffsetRect(RECT& rc, POINT pt) { + rc.left += pt.x; rc.right += pt.x; + rc.top += pt.y; rc.bottom += pt.y; + return rc; +} + +// handy functions to take the min or max of a SIZE +inline SIZE minsize(SIZE a, SIZE b) { + return GetSize(min((UINT)a.cx,(UINT)b.cx),min((UINT)a.cy,(UINT)b.cy)); +} + +inline SIZE maxsize(SIZE a, SIZE b) { + return GetSize(max((UINT)a.cx,(UINT)b.cx),max((UINT)a.cy,(UINT)b.cy)); +} + +////////////////// +// Size info about a rectangle/row/column +// +struct SIZEINFO { + SIZE szAvail; // total size avail (passed) + SIZE szDesired; // desired size: default=current + SIZE szMin; // minimum size: default=SIZEZERO + SIZE szMax; // maximum size: default=MAXSIZE +}; + +// types of rectangles: +#define WRCT_END 0 // end of table +#define WRCT_FIXED 0x0001 // height/width is fixed +#define WRCT_PCT 0x0002 // height/width is percent of total +#define WRCT_REST 0x0003 // height/width is whatever remains +#define WRCT_TOFIT 0x0004 // height/width to fit contents +#define WRCF_TYPEMASK 0x000F + +// group flags +#define WRCF_ROWGROUP 0x0010 // beginning of row group +#define WRCF_COLGROUP 0x0020 // beginning of column group +#define WRCF_ENDGROUP 0x00F0 // end of group +#define WRCF_GROUPMASK 0x00F0 + +////////////////// +// This structure is used to hold a rectangle and describe its layout. Each +// WINRECT corresponds to a child rectangle/window. Each window that uses +// WinMgr provides a table (C array) of these to describe its layout. +// +class WINRECT { +protected: + // pointers initialized by the window manager for easy traversing: + WINRECT* next; // next at this level + WINRECT* prev; // prev at this level + + // data + RECT rc; // current rectangle position/size + WORD flags; // flags (see above) + UINT nID; // window ID if this WINRECT represents a window + LONG param; // arg depends on type + +public: + WINRECT(WORD f, UINT id, LONG p); + + static WINRECT* InitMap(WINRECT* map, WINRECT* parent=NULL); + + WINRECT* Prev() { return prev; } + WINRECT* Next() { return next; } + WINRECT* Children() { return IsGroup() ? this+1 : NULL; } + WINRECT* Parent(); + WORD GetFlags() { return flags; } + WORD SetFlags(WORD f) { return flags=f; } + LONG GetParam() { return param; } + LONG SetParam(LONG p) { return param=p; } + UINT GetID() { return nID; } + UINT SetID(UINT id) { return nID=id; } + RECT& GetRect() { return rc; } + void SetRect(const RECT& r) { rc = r; } + WORD Type() const { return flags & WRCF_TYPEMASK; } + WORD GroupType() const { return flags & WRCF_GROUPMASK; } + BOOL IsGroup() const { return GroupType() && GroupType()!=WRCF_ENDGROUP; } + BOOL IsEndGroup() const { return flags==0 || flags==WRCF_ENDGROUP; } + BOOL IsEnd() const { return flags==0; } + BOOL IsWindow() const { return nID>0; } + BOOL IsRowGroup() const { return (flags & WRCF_GROUPMASK)==WRCF_ROWGROUP; } + void SetHeight(LONG h) { rc.bottom = rc.top + h; } + void SetWidth(LONG w) { rc.right = rc.left + w; } + LONG GetHeightOrWidth(BOOL bHeight) const { + return bHeight ? RectHeight(rc) : RectWidth(rc); + } + void SetHeightOrWidth(LONG horw, BOOL bHeight) { + bHeight ? SetHeight(horw) : SetWidth(horw); + } + BOOL GetMargins(int& w, int& h); + + // For TOFIT types, param is the TOFIT size, if nonzero. Used in dialogs, + // with CWinMgr::InitToFitSizeFromCurrent. + BOOL HasToFitSize() { return param != 0; } + SIZE GetToFitSize() { SIZE sz = {LOWORD(param),HIWORD(param)}; return sz; } + void SetToFitSize(SIZE sz) { param = MAKELONG(sz.cx,sz.cy); } +}; + +////////////////// +// Below are all the macros to build your window map. +// + +// Begin/end window map. 'name' can be anything you want +#define BEGIN_WINDOW_MAP(name) WINRECT name[] = { +#define END_WINDOW_MAP() WINRECT(WRCT_END,-1,0) }; + +// Begin/end a group. +// The first entry in your map must be BEGINROWS or BEGINCOLS. +#define BEGINROWS(type,id,m) WINRECT(WRCF_ROWGROUP|type,id,m), +#define BEGINCOLS(type,id,m) WINRECT(WRCF_COLGROUP|type,id,m), +#define ENDGROUP() WINRECT(WRCF_ENDGROUP,-1,0), + +// This macros is used only with BEGINGROWS or BEGINCOLS to specify margins +#define RCMARGINS(w,h) MAKELONG(w,h) + +// Macros for primitive (non-group) entries. +// val applies to height for a row entry; width for a column entry. +#define RCFIXED(id,val) WINRECT(WRCT_FIXED,id,val), +#define RCPERCENT(id,val) WINRECT(WRCT_PCT,id,val), +#define RCREST(id) WINRECT(WRCT_REST,id,0), +#define RCTOFIT(id) WINRECT(WRCT_TOFIT,id,0), +#define RCSPACE(val) RCFIXED(-1,val) + +////////////////// +// Use this to iterate the entries in a group. +// +// CWinGroupIterator it; +// for (it=pGroup; it; it.Next()) { +// WINRECT* wrc = it; +// .. +// } +// +class CWinGroupIterator { +protected: + WINRECT* pCur; // current entry +public: + CWinGroupIterator() { pCur = NULL; } + CWinGroupIterator& operator=(WINRECT* pg) { + assert(pg->IsGroup()); // can only iterate a group! + pCur = pg->Children(); + return *this; + } + operator WINRECT*() { return pCur; } + WINRECT* pWINRECT() { return pCur; } + WINRECT* Next() { return pCur = pCur ? pCur->Next() : NULL;} +}; + +// Registered WinMgr message +extern const UINT WM_WINMGR; + +// Notification struct, passed as LPARAM +struct NMWINMGR : public NMHDR { + enum { // notification codes: + GET_SIZEINFO = 1, // WinMgr is requesting size info + SIZEBAR_MOVED // user moved sizer bar + }; + + // each notification code has its own part of union + union { + SIZEINFO sizeinfo; // used for GET_SIZEINFO + struct { // used for SIZEBAR_MOVED + POINT ptMoved; // distance moved (x or y = zero) + } sizebar; + }; + BOOL processed; + + // ctor: initialize to zeroes + NMWINMGR() { memset(this,0,sizeof(NMWINMGR)); } +}; + +/////////////////// +// Window manager. This class calculates all the sizes and positions of the +// rectangles in the window map. +// +class CWinMgr /*: public CObject*/ { +public: + CWinMgr(WINRECT* map); + virtual ~CWinMgr(); + + virtual void GetWindowPositions(HWND hWnd); // load map from window posns + virtual void SetWindowPositions(HWND hWnd); // set window posns from map + + // get min/max/desired size of a rectangle + virtual void OnGetSizeInfo(SIZEINFO& szi, WINRECT* pwrc, HWND hWnd=NULL); + + // calc layout using client area as total area + void CalcLayout(HWND hWnd) { + assert(hWnd); + RECT rcClient; + GetClientRect(hWnd, &rcClient); + CalcLayout(rcClient, hWnd); + } + + // calc layout using cx, cy (for OnSize) + void CalcLayout(int cx, int cy, HWND hWnd=NULL) { + RECT rc = {0,0,cx,cy}; + CalcLayout(rc, hWnd); + } + + // calc layout using given rect as total area + void CalcLayout(RECT rcTotal, HWND hWnd=NULL) { + assert(m_map); + m_map->SetRect(rcTotal); + CalcGroup(m_map, hWnd); + } + + // Move rectangle vertically or horizontally. Used with sizer bars. + void MoveRect(int nID, POINT ptMove, HWND pParentWnd) { + MoveRect(FindRect(nID), ptMove, pParentWnd); + } + void MoveRect(WINRECT* pwrcMove, POINT ptMove, HWND pParentWnd); + + RECT GetRect(UINT nID) { return FindRect(nID)->GetRect(); } + void SetRect(UINT nID, const RECT& rc) { FindRect(nID)->SetRect(rc); } + + // get WINRECT corresponding to ID + WINRECT* FindRect(UINT nID); + + // Calculate MINMAXINFO + void GetMinMaxInfo(HWND hWnd, MINMAXINFO* lpMMI); + void GetMinMaxInfo(HWND hWnd, SIZEINFO& szi); + + // set TOFIT size for all windows from current window sizes + void InitToFitSizeFromCurrent(HWND hWnd); + + // Theo - Removed Tracing + +protected: + WINRECT* m_map; // THE window map + + int CountWindows(); + BOOL SendGetSizeInfo(SIZEINFO& szi, HWND hWnd, UINT nID); + + // you can override to do wierd stuff or fix bugs + virtual void CalcGroup(WINRECT* group, HWND hWnd); + virtual void AdjustSize(WINRECT* pEntry, BOOL bRow, + int& hwRemaining, HWND hWnd); + virtual void PositionRects(WINRECT* pGroup, + const RECT& rcTotal,BOOL bRow); + +private: + CWinMgr() { assert(FALSE); } // no default constructor +}; + +// Theo - Removed CSizerBar and CSizeableDlg +#endif \ No newline at end of file diff --git a/PowerEditor/src/WinControls/WindowsDlg/WinRect.cpp b/PowerEditor/src/WinControls/WindowsDlg/WinRect.cpp new file mode 100644 index 00000000..2ae1cbf6 --- /dev/null +++ b/PowerEditor/src/WinControls/WindowsDlg/WinRect.cpp @@ -0,0 +1,84 @@ +//////////////////////////////////////////////////////////////// +// MSDN Magazine -- July 2001 +// If this code works, it was written by Paul DiLascia. +// If not, I don't know who wrote it. +// Compiles with Visual C++ 6.0. Runs on Win 98 and probably Win 2000 too. +// Set tabsize = 3 in your editor. +// +//#include "StdAfx.h" +#include "windows.h" +#include +#include "WinMgr.h" + +////////////////// +// Construct from args +// +WINRECT::WINRECT(WORD f, UINT id, LONG p) +{ + memset(this, 0, sizeof(WINRECT)); + flags = f; + nID = id; + param = p; +} + +////////////////// +// Get the parent of a given WINRECT. To find the parent, chase the prev +// pointer to the start of the list, then take the item before that in +// memory. +// +WINRECT* WINRECT::Parent() +{ + WINRECT* pEntry = NULL; + for (pEntry=this; pEntry->Prev(); pEntry=pEntry->Prev()) { + ; // go backwards to the end + } + // the entry before the first child is the group + WINRECT *parent = pEntry-1; + assert(parent->IsGroup()); + return parent; +} + +////////////////// +// Get group margins +// +BOOL WINRECT::GetMargins(int& w, int& h) +{ + if (IsGroup()) { + w=(short)LOWORD(param); + h=(short)HIWORD(param); + return TRUE; + } + w=h=0; + return FALSE; +} + +////////////////// +// Initialize map: set up all the next/prev pointers. This converts the +// linear array to a more convenient linked list. Called from END_WINDOW_MAP. +// +WINRECT* WINRECT::InitMap(WINRECT* pWinMap, WINRECT* parent) +{ + assert(pWinMap); + + WINRECT* pwrc = pWinMap; // current table entry + WINRECT* prev = NULL; // previous entry starts out none + + while (!pwrc->IsEndGroup()) { + pwrc->prev=prev; + pwrc->next=NULL; + if (prev) + prev->next = pwrc; + prev = pwrc; + if (pwrc->IsGroup()) { + pwrc = InitMap(pwrc+1,pwrc); // recurse! Returns end-of-grp + assert(pwrc->IsEndGroup()); + } + pwrc++; + } + // safety checks + assert(pwrc->IsEndGroup()); + assert(prev); + assert(prev->next==NULL); + return parent ? pwrc : NULL; +} + diff --git a/PowerEditor/src/WinControls/WindowsDlg/WindowsDlg.cpp b/PowerEditor/src/WinControls/WindowsDlg/WindowsDlg.cpp new file mode 100644 index 00000000..1ac32fb8 --- /dev/null +++ b/PowerEditor/src/WinControls/WindowsDlg/WindowsDlg.cpp @@ -0,0 +1,882 @@ +#include +#include "WindowsDlg.h" +#include "WindowsDlgRc.h" +#include "DocTabView.h" +#include +#include +#include + +#ifndef _countof +#define _countof(x) (sizeof(x)/sizeof((x)[0])) +#endif + +#ifndef LVS_EX_DOUBLEBUFFER +#define LVS_EX_DOUBLEBUFFER 0x00010000 +#endif + +static const TCHAR *readonlyString = TEXT(" [Read Only]"); +const UINT WDN_NOTIFY = RegisterWindowMessage(TEXT("WDN_NOTIFY")); + +inline static DWORD GetStyle(HWND hWnd) { + return (DWORD)GetWindowLongPtr(hWnd, GWL_STYLE); +} +inline static DWORD GetExStyle(HWND hWnd) { + return (DWORD)GetWindowLongPtr(hWnd, GWL_EXSTYLE); +} + +inline static BOOL ModifyStyle(HWND hWnd, DWORD dwRemove, DWORD dwAdd) { + DWORD dwStyle = ::GetWindowLongPtr(hWnd, GWL_STYLE); + DWORD dwNewStyle = (dwStyle & ~dwRemove) | dwAdd; + if(dwStyle == dwNewStyle) + return FALSE; + ::SetWindowLongPtr(hWnd, GWL_STYLE, dwNewStyle); + return TRUE; +} + +inline static BOOL ModifyStyleEx(HWND hWnd, DWORD dwRemove, DWORD dwAdd) { + DWORD dwStyle = ::GetWindowLongPtr(hWnd, GWL_EXSTYLE); + DWORD dwNewStyle = (dwStyle & ~dwRemove) | dwAdd; + if(dwStyle == dwNewStyle) + return FALSE; + ::SetWindowLongPtr(hWnd, GWL_EXSTYLE, dwNewStyle); + return TRUE; +} + + +struct NumericStringEquivalence +{ + bool operator()(const TCHAR* s1, const TCHAR* s2) const + { return numstrcmp(s1, s2) < 0; } + static inline int numstrcmp_get(const TCHAR **str, int *length) + { + const TCHAR *p = *str; + int value = 0; + for (*length = 0; isdigit(*p); (*length)++) + value = value * 10 + *p++ - '0'; + *str = p; + return (value); + } + static int numstrcmp(const TCHAR *str1, const TCHAR *str2) + { + TCHAR *p1, *p2; + int c1, c2, lcmp; + for(;;) + { + c1 = tolower(*str1), c2 = tolower(*str2); + if ( c1 == 0 || c2 == 0 ) + break; + else if (isdigit(c1) && isdigit(c2)) + { + lcmp = generic_strtol(str1, &p1, 10) - generic_strtol(str2, &p2, 10); + if ( lcmp == 0 ) + lcmp = (p2 - str2) - (p1 - str1); + if ( lcmp != 0 ) + return (lcmp > 0 ? 1 : -1); + str1 = p1, str2 = p2; + } + else + { + lcmp = (c1 - c2); + if (lcmp != 0) + return (lcmp > 0 ? 1 : -1); + ++str1, ++str2; + } + } + lcmp = (c1 - c2); + return ( lcmp < 0 ) ? -1 : (lcmp > 0 ? 1 : 0); + } +}; + +struct BufferEquivalent +{ + NumericStringEquivalence _strequiv; + DocTabView *_pTab; + int _iColumn; + bool _reverse; + BufferEquivalent(DocTabView *pTab, int iColumn, bool reverse) + : _pTab(pTab), _iColumn(iColumn), _reverse(reverse) + {} + + bool operator()(int i1, int i2) const + { + if (i1 == i2) return false; // equivalence test not equality + if (_reverse) std::swap(i1, i2); + return compare(i1, i2); + } + + bool compare(int i1, int i2) const + { + BufferID bid1 = _pTab->getBufferByIndex(i1); + BufferID bid2 = _pTab->getBufferByIndex(i2); + Buffer * b1 = MainFileManager->getBufferByID(bid1); + Buffer * b2 = MainFileManager->getBufferByID(bid2); + if (_iColumn == 0) + { + const TCHAR *s1 = b1->getFileName(); + const TCHAR *s2 = b2->getFileName(); + return _strequiv(s1, s2); + } + else if (_iColumn == 1) + { + const TCHAR *s1 = b1->getFullPathName(); + const TCHAR *s2 = b2->getFullPathName(); + return _strequiv(s1, s2); //we can compare the full path to sort on directory, since after sorting directories sorting files is the second thing to do (if directories are the same that is) + } + else if (_iColumn == 2) + { + int t1 = (int)b1->getLangType(); + int t2 = (int)b2->getLangType(); + return (t1 < t2); // yeah should be the name + } + return false; + } +}; + +////////////////// +// Window map tells CWinMgr how to position dialog controls +// +BEGIN_WINDOW_MAP(WindowsDlgMap) + BEGINROWS(WRCT_REST,0,RCMARGINS(8,8)) + BEGINCOLS(WRCT_REST,0,0) // Begin list control column + BEGINROWS(WRCT_REST,0,0) + RCREST(IDC_WINDOWS_LIST) + RCSPACE(20) + ENDGROUP() + RCSPACE(12) + BEGINROWS(WRCT_TOFIT,0,0) + RCSPACE(12) + RCTOFIT(IDOK) + RCSPACE(-12) + RCTOFIT(IDC_WINDOWS_SAVE) + RCSPACE(-12) + RCTOFIT(IDC_WINDOWS_CLOSE) + RCSPACE(-12) + RCTOFIT(IDC_WINDOWS_SORT) + RCREST(-1) + RCTOFIT(IDCANCEL) + ENDGROUP() + ENDGROUP() + ENDGROUP() +END_WINDOW_MAP() + +RECT WindowsDlg::_lastKnownLocation; + +WindowsDlg::WindowsDlg() : MyBaseClass(WindowsDlgMap), _isSorted(false) +{ + _szMinButton = SIZEZERO; + _szMinListCtrl = SIZEZERO; +} + +void WindowsDlg::init(HINSTANCE hInst, HWND parent, DocTabView *pTab) +{ + MyBaseClass::init(hInst, parent); + _pTab = pTab; +} + +void WindowsDlg::init(HINSTANCE hInst, HWND parent) +{ + assert(!"Call other initialize method"); + MyBaseClass::init(hInst, parent); + _pTab = NULL; +} + +BOOL CALLBACK WindowsDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) +{ + switch (message) + { + case WM_INITDIALOG : + { + changeDlgLang(); + return MyBaseClass::run_dlgProc(message, wParam, lParam); + } + case WM_COMMAND : + { + switch (wParam) + { + case IDOK : + activateCurrent(); + return TRUE; + + case IDCANCEL : + ::GetWindowRect(_hSelf, &_lastKnownLocation); + EndDialog(_hSelf, IDCANCEL); + return TRUE; + + case IDC_WINDOWS_SAVE: + doSave(); + return TRUE; + + case IDC_WINDOWS_CLOSE: + doClose(); + return TRUE; + + case IDC_WINDOWS_SORT: + doSortToTabs(); + _isSorted = false; + updateButtonState(); + break; + + default : + break; + } + } + + case WM_DESTROY : + //destroy(); + return TRUE; + + case WM_NOTIFY : + { + if (wParam == IDC_WINDOWS_LIST) + { + NMHDR* pNMHDR = (NMHDR*)lParam; + if (pNMHDR->code == LVN_GETDISPINFO) + { + NMLVDISPINFO *pLvdi = (NMLVDISPINFO *)pNMHDR; + //if(pLvdi->item.mask & LVIF_IMAGE) + // ; + if(pLvdi->item.mask & LVIF_TEXT) + { + pLvdi->item.pszText[0] = 0; + int index = pLvdi->item.iItem; + if (index >= _pTab->nbItem() || index >= (int)_idxMap.size()) + return FALSE; + index = _idxMap[index]; + + //const Buffer& buffer = _pView->getBufferAt(index); + BufferID bufID = _pTab->getBufferByIndex(index); + Buffer * buf = MainFileManager->getBufferByID(bufID); + if (pLvdi->item.iSubItem == 0) // file name + { + int len = pLvdi->item.cchTextMax; + const TCHAR *fileName = buf->getFileName(); + generic_strncpy(pLvdi->item.pszText, fileName, len-1); + pLvdi->item.pszText[len-1] = 0; + len = lstrlen(pLvdi->item.pszText); + if (buf->isDirty()) + { + if (len < pLvdi->item.cchTextMax) + { + pLvdi->item.pszText[len++] = '*'; + pLvdi->item.pszText[len] = 0; + } + } + else if (buf->isReadOnly()) + { + len += lstrlen(readonlyString); + if (len <= pLvdi->item.cchTextMax) + lstrcat(pLvdi->item.pszText, readonlyString); + } + } + else if (pLvdi->item.iSubItem == 1) // directory + { + const TCHAR *fullName = buf->getFullPathName(); + const TCHAR *fileName = buf->getFileName(); + int len = lstrlen(fullName)-lstrlen(fileName); + if (!len) { + len = 1; + fullName = TEXT(""); + } + if (pLvdi->item.cchTextMax < len) + len = pLvdi->item.cchTextMax; + generic_strncpy(pLvdi->item.pszText, fullName, len-1); + pLvdi->item.pszText[len-1] = 0; + } + else if (pLvdi->item.iSubItem == 2) // Type + { + int len = pLvdi->item.cchTextMax; + NppParameters *pNppParameters = NppParameters::getInstance(); + Lang *lang = pNppParameters->getLangFromID(buf->getLangType()); + if (NULL != lang) + { + generic_strncpy(pLvdi->item.pszText, lang->getLangName(), len-1); + } + } + } + return TRUE; + } + else if (pNMHDR->code == LVN_COLUMNCLICK) // sort columns with stable sort + { + NMLISTVIEW *pNMLV = (NMLISTVIEW *)pNMHDR; + if (pNMLV->iItem == -1) + { + bool reverse = false; + int iColumn = pNMLV->iSubItem; + if (_lastSort == iColumn) + { + reverse = true; + _lastSort = -1; + } + else + { + _lastSort = iColumn; + } + int i; + int n = _idxMap.size(); + vector sortMap; + sortMap.resize(n); + for (i=0; icode == LVN_ITEMACTIVATE || pNMHDR->code == LVN_ITEMCHANGED || pNMHDR->code == LVN_ODSTATECHANGED) + { + updateButtonState(); + return TRUE; + } + else if (pNMHDR->code == NM_DBLCLK) + { + ::PostMessage(_hSelf, WM_COMMAND, IDOK, 0); + //activateCurrent(); + return TRUE; + } + else if (pNMHDR->code == LVN_KEYDOWN) + { + NMLVKEYDOWN *lvkd = (NMLVKEYDOWN *)pNMHDR; + // Ctrl+A + short ctrl = GetKeyState(VK_CONTROL); + short alt = GetKeyState(VK_MENU); + short shift = GetKeyState(VK_SHIFT); + if (lvkd->wVKey == 0x41/*a*/ && ctrl<0 && alt>=0 && shift>=0) + { + for (int i=0, n=ListView_GetItemCount(_hList); iGetDocument()->FirstChild()->ToDeclaration(); + if (declaration) + { + const char * encodingStr = declaration->Encoding(); + nativeLangEncoding = getCpFromStringValue(encodingStr); + } +#endif + + // Set Title + const char *titre = (_dlgNode->ToElement())->Attribute("title"); + if (titre && titre[0]) + { +#ifdef UNICODE + const wchar_t *nameW = wmc->char2wchar(titre, nativeLangEncoding); + ::SetWindowText(_hSelf, nameW); +#else + ::SetWindowText(_hSelf, titre); +#endif + } + + // Set the text of child control + for (TiXmlNodeA *childNode = _dlgNode->FirstChildElement("Item"); + childNode ; + childNode = childNode->NextSibling("Item") ) + { + TiXmlElementA *element = childNode->ToElement(); + int id; + const char *sentinel = element->Attribute("id", &id); + const char *name = element->Attribute("name"); + if (sentinel && (name && name[0])) + { + HWND hItem = ::GetDlgItem(_hSelf, id); + if (hItem) + { +#ifdef UNICODE + const wchar_t *nameW = wmc->char2wchar(name, nativeLangEncoding); + ::SetWindowText(hItem, nameW); +#else + ::SetWindowText(hItem, name); +#endif + } + } + } + return true; +} + +BOOL WindowsDlg::onInitDialog() +{ + _winMgr.InitToFitSizeFromCurrent(_hSelf); + + // save min size for OK/Cancel buttons + _szMinButton = RectToSize(_winMgr.GetRect(IDOK)); + _szMinListCtrl = RectToSize(_winMgr.GetRect(IDC_WINDOWS_LIST)); + _lastSort = -1; + + _winMgr.CalcLayout(_hSelf); + _winMgr.SetWindowPositions(_hSelf); + getClientRect(_rc); + + _hList = ::GetDlgItem(_hSelf, IDC_WINDOWS_LIST); + DWORD exStyle = ListView_GetExtendedListViewStyle(_hList); + exStyle |= LVS_EX_HEADERDRAGDROP|LVS_EX_FULLROWSELECT|LVS_EX_DOUBLEBUFFER; + ListView_SetExtendedListViewStyle(_hList, exStyle); + RECT rc; + GetClientRect(_hList, &rc); + LONG width = rc.right - rc.left; + + LVCOLUMN lvColumn; + memset(&lvColumn, 0, sizeof(lvColumn)); + lvColumn.mask = LVCF_WIDTH|LVCF_TEXT|LVCF_SUBITEM|LVCF_FMT; + lvColumn.fmt = LVCFMT_LEFT; + lvColumn.pszText = TEXT("Name"); + lvColumn.cx = width/4; + SendMessage(_hList, LVM_INSERTCOLUMN, 0, LPARAM(&lvColumn)); + + lvColumn.pszText = TEXT("Path"); + lvColumn.cx = 300; + SendMessage(_hList, LVM_INSERTCOLUMN, 1, LPARAM(&lvColumn)); + + lvColumn.fmt = LVCFMT_CENTER; + lvColumn.pszText = TEXT("Type"); + lvColumn.cx = 40; + SendMessage(_hList, LVM_INSERTCOLUMN, 2, LPARAM(&lvColumn)); + + fitColumnsToSize(); + + if (_lastKnownLocation.bottom > 0 && _lastKnownLocation.right > 0) + { + SetWindowPos(_hSelf, NULL, _lastKnownLocation.left, _lastKnownLocation.top, + _lastKnownLocation.right-_lastKnownLocation.left, _lastKnownLocation.bottom-_lastKnownLocation.top, SWP_SHOWWINDOW); + } + else + { + goToCenter(); + } + + doRefresh(true); + return TRUE; +} + +void WindowsDlg::onSize(UINT nType, int cx, int cy) +{ + MyBaseClass::onSize(nType, cx, cy); + fitColumnsToSize(); +} + +void WindowsDlg::onGetMinMaxInfo(MINMAXINFO* lpMMI) +{ + MyBaseClass::onGetMinMaxInfo(lpMMI); +} + +LRESULT WindowsDlg::onWinMgr(WPARAM wp, LPARAM lp) +{ + NMWINMGR &nmw = *(NMWINMGR *)lp; + if (nmw.code==NMWINMGR::GET_SIZEINFO) { + switch(wp) + { + case IDOK: + case IDCANCEL: + case IDC_WINDOWS_SAVE: + case IDC_WINDOWS_CLOSE: + case IDC_WINDOWS_SORT: + nmw.sizeinfo.szMin = _szMinButton; + nmw.processed = TRUE; + return TRUE; + + case IDC_WINDOWS_LIST: + nmw.sizeinfo.szMin = _szMinListCtrl; + nmw.processed = TRUE; + return TRUE; + } + } + return MyBaseClass::onWinMgr(wp, lp); +} + +void WindowsDlg::doRefresh(bool invalidate /*= false*/) +{ + if (_hSelf != NULL && isVisible()) + { + if (_hList != NULL) + { + size_t count = (_pTab != NULL) ? _pTab->nbItem() : 0; + size_t oldSize = _idxMap.size(); + if (!invalidate && count == oldSize) + return; + + if (count != oldSize) + { + size_t lo = 0; + _idxMap.resize(count); + if (oldSize < count) + lo = oldSize; + for (size_t i=lo; igetCurrentTabIndex(); + int pos = 0; + for (vector::iterator itr = _idxMap.begin(), end = _idxMap.end(); itr != end; ++itr, ++pos) + { + if (*itr == curSel) + { + ListView_SetItemState(_hList, pos, LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED) + } + else + { + ListView_SetItemState(_hList, pos, 0, LVIS_SELECTED); + } + } +} + +void WindowsDlg::doSave() +{ + NMWINDLG nmdlg; + nmdlg.type = WDT_SAVE; + nmdlg.curSel = ListView_GetNextItem(_hList, -1, LVNI_SELECTED); + nmdlg.hwndFrom = _hSelf; + nmdlg.code = WDN_NOTIFY; + nmdlg.nItems = ListView_GetSelectedCount(_hList); + nmdlg.Items = new UINT[nmdlg.nItems]; + for (UINT i=-1, j=0;;++j) { + i = ListView_GetNextItem(_hList, i, LVNI_SELECTED); + if (i == -1) break; + nmdlg.Items[j] = _idxMap[i]; + } + SendMessage(_hParent, WDN_NOTIFY, 0, LPARAM(&nmdlg)); + delete[] nmdlg.Items; + ::InvalidateRect(_hList, &_rc, FALSE); + ListView_RedrawItems(_hList, 0, ListView_GetSelectedCount(_hList)); +} + +void WindowsDlg::destroy() +{ + ::GetWindowRect(_hSelf, &_lastKnownLocation); + + HWND hSelf = _hSelf; + _hSelf = NULL; + ::DestroyWindow(hSelf); + +} + +void WindowsDlg::activateCurrent() +{ + if (ListView_GetSelectedCount(_hList) == 1) + { + NMWINDLG nmdlg; + nmdlg.type = WDT_ACTIVATE; + //nmdlg.curSel = ListView_GetNextItem(_hList, -1, LVNI_ALL|LVNI_SELECTED); + nmdlg.curSel = _idxMap[ListView_GetNextItem(_hList, -1, LVNI_ALL|LVNI_SELECTED)]; + nmdlg.hwndFrom = _hSelf; + nmdlg.code = WDN_NOTIFY; + SendMessage(_hParent, WDN_NOTIFY, 0, LPARAM(&nmdlg)); + + ::GetWindowRect(_hSelf, &_lastKnownLocation); + EndDialog(_hSelf, IDOK); + } +} + +void WindowsDlg::doClose() +{ + NMWINDLG nmdlg; + nmdlg.type = WDT_CLOSE; + //nmdlg.curSel = ListView_GetNextItem(_hList, -1, LVNI_SELECTED); + int index = ListView_GetNextItem(_hList, -1, LVNI_ALL|LVNI_SELECTED); + if (index == -1) return; + + nmdlg.curSel = _idxMap[index]; + nmdlg.hwndFrom = _hSelf; + nmdlg.code = WDN_NOTIFY; + UINT n = nmdlg.nItems = ListView_GetSelectedCount(_hList); + nmdlg.Items = new UINT[nmdlg.nItems]; + vector key; + key.resize(n, 0x7fffffff); + for(UINT i=-1, j=0;; ++j) { + i = ListView_GetNextItem(_hList, i, LVNI_SELECTED); + if (i == -1) break; + ListView_SetItemState(_hList, i, 0, LVIS_SELECTED); // deselect + nmdlg.Items[j] = _idxMap[i]; + key[j] = i; + } + SendMessage(_hParent, WDN_NOTIFY, 0, LPARAM(&nmdlg)); + if (nmdlg.processed) + { + // Trying to retain sort order. fairly sure there is a much better algorithm for this + vector::iterator kitr = key.begin(); + for (UINT i=0; i::iterator itr = _idxMap.begin(), end = _idxMap.end(); itr != end; ++itr) + if (*itr > oldVal) + --(*itr); + } + } + _idxMap.erase(std::remove_if(_idxMap.begin(), _idxMap.end(), bind2nd(equal_to(), -1)), _idxMap.end()); + } + delete[] nmdlg.Items; + + if (_pTab->nbItem() != _idxMap.size()) + doRefresh(true); + else + { + // select first previously selected item (or last one if only the last one was removed) + if (index == _idxMap.size()) index --; + if (index >= 0) + { + ListView_SetItemState(_hList, index, LVIS_SELECTED, LVIS_SELECTED); + ListView_RedrawItems(_hList, 0, _idxMap.size() - 1); + } + ListView_SetItemCount(_hList, _idxMap.size()); + } +} + +void WindowsDlg::doSortToTabs() +{ + int curSel = ListView_GetNextItem(_hList, -1, LVNI_SELECTED); + + if (curSel == -1) + curSel = 0; + + NMWINDLG nmdlg; + nmdlg.type = WDT_SORT; + nmdlg.hwndFrom = _hSelf; + //nmdlg.curSel = curSel; + nmdlg.curSel = _idxMap[curSel]; + nmdlg.code = WDN_NOTIFY; + UINT n = nmdlg.nItems = ListView_GetItemCount(_hList); + nmdlg.Items = new UINT[nmdlg.nItems]; + vector key; + key.resize(n, 0x7fffffff); + for(UINT i=-1, j=0;; ++j) { + i = ListView_GetNextItem(_hList, i, LVNI_ALL); + if (i == -1) break; + nmdlg.Items[j] = _idxMap[i]; + if (i == curSel) + nmdlg.curSel = j; + key[j] = i; + } + + SendMessage(_hParent, WDN_NOTIFY, 0, LPARAM(&nmdlg)); + if (nmdlg.processed) + { + _idxMap.clear(); + doRefresh(true); + } + delete[] nmdlg.Items; +} + +WindowsMenu::WindowsMenu() +{} + +WindowsMenu::~WindowsMenu() +{ + if (_hMenu) + DestroyMenu(_hMenu); +} + +void WindowsMenu::init(HINSTANCE hInst, HMENU hMainMenu, const TCHAR *translation) +{ + _hMenu = ::LoadMenu(hInst, MAKEINTRESOURCE(IDR_WINDOWS_MENU)); + + if (translation && translation[0]) + { + generic_string windowStr(translation); + windowStr += TEXT("..."); + ::ModifyMenu(_hMenu, IDM_WINDOW_WINDOWS, MF_BYCOMMAND, IDM_WINDOW_WINDOWS, windowStr.c_str()); + } + + UINT pos = 0; + for(pos = GetMenuItemCount(hMainMenu) - 1; pos > 0; --pos) + { + if ((GetMenuState(hMainMenu, pos, MF_BYPOSITION) & MF_POPUP) != MF_POPUP) + continue; + break; + } + + MENUITEMINFO mii; + memset(&mii, 0, sizeof(mii)); + mii.cbSize = sizeof(mii); + mii.fMask = MIIM_STRING|MIIM_SUBMENU; + + TCHAR buffer[32]; + LoadString(hInst, IDR_WINDOWS_MENU, buffer, 32); + mii.dwTypeData = (TCHAR *)((translation && translation[0])?translation:buffer); + mii.hSubMenu = _hMenu; + InsertMenuItem(hMainMenu, pos, TRUE, &mii); +} + +void WindowsMenu::initPopupMenu(HMENU hMenu, DocTabView *pTab) +{ + if (hMenu == _hMenu) + { + int curDoc = pTab->getCurrentTabIndex(); + int nMaxDoc = IDM_WINDOW_MRU_LIMIT - IDM_WINDOW_MRU_FIRST + 1; + int nDoc = pTab->nbItem(); + nDoc = min(nDoc, nMaxDoc); + int id, pos; + for (id=IDM_WINDOW_MRU_FIRST, pos=0; idgetBufferByIndex(pos); + Buffer * buf = MainFileManager->getBufferByID(bufID); + + MENUITEMINFO mii; + memset(&mii, 0, sizeof(mii)); + mii.cbSize = sizeof(mii); + mii.fMask = MIIM_STRING|MIIM_STATE|MIIM_ID; + mii.dwTypeData = buildFileName(buffer, 60, pos, buf->getFileName()); + mii.fState &= ~(MF_GRAYED|MF_DISABLED|MF_CHECKED); + if (pos == curDoc) + mii.fState |= MF_CHECKED; + mii.wID = id; + + UINT state = GetMenuState(hMenu, id, MF_BYCOMMAND); + if (state == -1) + InsertMenuItem(hMenu, IDM_WINDOW_WINDOWS, FALSE, &mii); + else + SetMenuItemInfo(hMenu, id, FALSE, &mii); + } + for ( ; id<=IDM_WINDOW_MRU_LIMIT; ++id) + { + DeleteMenu(hMenu, id, FALSE); + } + } +} +/* +void WindowsMenu::uninitPopupMenu(HMENU hMenu, ScintillaEditView *pView) +{ + if (hMenu == _hMenu) + { + + } +} +*/ +static TCHAR* convertFileName(TCHAR *buffer, const TCHAR *filename) +{ + TCHAR *b = buffer; + const TCHAR *p = filename; + while (*p) + { + if (*p == '&') *b++ = '&'; + *b++ = *p++; + } + *b = 0; + return buffer; +} + +TCHAR *WindowsMenu::buildFileName(TCHAR *buffer, int len, int pos, const TCHAR *filename) +{ + TCHAR cwd[MAX_PATH]; + buffer[0] = 0; + GetCurrentDirectory(_countof(cwd), cwd); + lstrcat(cwd, TEXT("\\")); + + TCHAR *itr = buffer; + TCHAR *end = buffer + len - 1; + if (pos < 9) + { + *itr++ = '&'; + *itr++ = '1' + pos; + } + else if (pos == 9) + { + *itr++ = '1'; + *itr++ = '&'; + *itr++ = '0'; + } + else + { + wsprintf(itr, TEXT("%d"), pos+1); + itr = itr + lstrlen(itr); + } + *itr++ = ':'; + *itr++ = ' '; + if (0 == generic_strnicmp(filename, cwd, lstrlen(cwd))) + { + TCHAR cnvName[MAX_PATH]; + const TCHAR *s1 = PathFindFileName(filename); + int len = lstrlen(s1); + if (len < (end-itr)) + { + lstrcpy(cnvName, s1); + } + else + { + int n = (len-3-(itr-buffer))/2; + generic_strncpy(cnvName, s1, n); + lstrcpy(cnvName+n, TEXT("...")); + lstrcat(cnvName, s1 + lstrlen(s1) - n); + } + convertFileName(itr, cnvName); + } + else + { + TCHAR cnvName[MAX_PATH*2]; + const TCHAR *s1 = convertFileName(cnvName, filename); + PathCompactPathEx(itr, filename, len - (itr-buffer), 0); + } + return buffer; +} \ No newline at end of file diff --git a/PowerEditor/src/WinControls/WindowsDlg/WindowsDlg.h b/PowerEditor/src/WinControls/WindowsDlg/WindowsDlg.h new file mode 100644 index 00000000..1580804e --- /dev/null +++ b/PowerEditor/src/WinControls/WindowsDlg/WindowsDlg.h @@ -0,0 +1,114 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef WINDOWS_DLG_H +#define WINDOWS_DLG_H + +#include "SizeableDlg.h" +#include "WindowsDlgRc.h" +#include "Parameters.h" +#include +#include + +class DocTabView; + +typedef enum { + WDT_ACTIVATE = 1, + WDT_SAVE = 2, + WDT_CLOSE = 3, + WDT_SORT = 4, +} WinDlgNotifyType; + + +struct NMWINDLG : public NMHDR { + + BOOL processed; + WinDlgNotifyType type; + UINT curSel; + UINT nItems; + UINT *Items; + + // ctor: initialize to zeroes + NMWINDLG() { memset(this,0,sizeof(NMWINDLG)); } +}; + +extern const UINT WDN_NOTIFY; + + +class WindowsDlg : public SizeableDlg +{ + typedef SizeableDlg MyBaseClass; + + class CachedValue + { + std::generic_string fullname; + int index; + }; + +public : + WindowsDlg(); + int doDialog(TiXmlNodeA *dlgNode); + virtual void init(HINSTANCE hInst, HWND parent, DocTabView *pTab); + + void doRefresh(bool invalidate = false); + bool changeDlgLang(); + +protected : + virtual BOOL CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam); + virtual BOOL onInitDialog(); + virtual void onSize(UINT nType, int cx, int cy); + virtual void onGetMinMaxInfo(MINMAXINFO* lpMMI); + virtual LRESULT onWinMgr(WPARAM wp, LPARAM lp); + virtual void destroy(); + void fitColumnsToSize(); + void resetSelection(); + void doSave(); + void doClose(); + void doSortToTabs(); + void updateButtonState(); + void activateCurrent(); + + HWND _hList; + static RECT _lastKnownLocation; + SIZE _szMinButton; + SIZE _szMinListCtrl; + DocTabView *_pTab; + std::vector _idxMap; + int _lastSort; + bool _isSorted; + TiXmlNodeA *_dlgNode; + +private: + virtual void init(HINSTANCE hInst, HWND parent); +}; + +class WindowsMenu +{ +public: + WindowsMenu(); + ~WindowsMenu(); + void init(HINSTANCE hInst, HMENU hMainMenu, const TCHAR *translation); + //void initMenu(HMENU hMenu, ScintillaEditView *pView); + void initPopupMenu(HMENU hMenu, DocTabView *pTab); + //void uninitPopupMenu(HMENU hMenu, ScintillaEditView *pView); +private: + TCHAR *buildFileName(TCHAR *buffer, int len, int pos, const TCHAR *filename); + HMENU _hMenu; +}; + + +#endif //WINDOWS_DLG_H diff --git a/PowerEditor/src/WinControls/WindowsDlg/WindowsDlg.rc b/PowerEditor/src/WinControls/WindowsDlg/WindowsDlg.rc new file mode 100644 index 00000000..6ee96843 --- /dev/null +++ b/PowerEditor/src/WinControls/WindowsDlg/WindowsDlg.rc @@ -0,0 +1,48 @@ +/* +this file is part of notepad++ +Copyright (C)2003 Don HO < donho@altern.org > + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +//#ifndef _WINDOWS_ +#include +//#endif +#include "WindowsDlgRc.h" + +IDD_WINDOWS DIALOGEX 0, 0, 450, 300 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | DS_MODALFRAME +CAPTION "Windows" +FONT 8, TEXT("MS Shell Dlg"), 400, 0, 0x1 +BEGIN + CONTROL "", IDC_WINDOWS_LIST, TEXT("SysListView32"), LVS_REPORT | LVS_OWNERDATA | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP, 7, 7, 206, 160 + DEFPUSHBUTTON "&Activate",IDOK,219,7,60,14 + PUSHBUTTON "&Save",IDC_WINDOWS_SAVE,219,26,60,14 + PUSHBUTTON "&Close Window(s)",IDC_WINDOWS_CLOSE,219,44,60,14 + PUSHBUTTON "Sort &Tabs",IDC_WINDOWS_SORT,219,60,60,14 + PUSHBUTTON "&OK",IDCANCEL,219,169,60,14 +END + +IDR_WINDOWS_MENU MENU +BEGIN + MENUITEM "Recent Window", IDM_WINDOW_MRU_FIRST, GRAYED + MENUITEM "&Windows...", IDM_WINDOW_WINDOWS +END + + +STRINGTABLE +BEGIN + IDR_WINDOWS_MENU "&Window" +END diff --git a/PowerEditor/src/WinControls/WindowsDlg/WindowsDlgRc.h b/PowerEditor/src/WinControls/WindowsDlg/WindowsDlgRc.h new file mode 100644 index 00000000..dbd18323 --- /dev/null +++ b/PowerEditor/src/WinControls/WindowsDlg/WindowsDlgRc.h @@ -0,0 +1,19 @@ +#ifdef __GNUC__ +#define _WIN32_IE 0x0600 + + #ifndef LVS_OWNERDATA + #define LVS_OWNERDATA 4096 + #endif + +#endif + +#define IDD_WINDOWS 7000 + #define IDC_WINDOWS_LIST (IDD_WINDOWS + 1) + #define IDC_WINDOWS_SAVE (IDD_WINDOWS + 2) + #define IDC_WINDOWS_CLOSE (IDD_WINDOWS + 3) + #define IDC_WINDOWS_SORT (IDD_WINDOWS + 4) + +#define IDR_WINDOWS_MENU 11000 + #define IDM_WINDOW_WINDOWS (IDR_WINDOWS_MENU + 1) + #define IDM_WINDOW_MRU_FIRST (IDR_WINDOWS_MENU + 20) + #define IDM_WINDOW_MRU_LIMIT (IDR_WINDOWS_MENU + 29) diff --git a/PowerEditor/src/WinControls/shortcut/RunMacroDlg.cpp b/PowerEditor/src/WinControls/shortcut/RunMacroDlg.cpp new file mode 100644 index 00000000..4cf0bad3 --- /dev/null +++ b/PowerEditor/src/WinControls/shortcut/RunMacroDlg.cpp @@ -0,0 +1,115 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +// created by Daniel Volk mordorpost@volkarts.com + +#include "RunMacroDlg.h" +#include "ScintillaEditView.h" +#include "Notepad_plus_msgs.h" +//#include "constant.h" + + +BOOL CALLBACK RunMacroDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) +{ + switch (message) + { + case WM_INITDIALOG : + { + initMacroList(); + + TCHAR str[512]; + wsprintf(str, TEXT("%d"), m_Times); + + ::SetDlgItemText(_hSelf, IDC_M_RUN_TIMES, str); + switch ( m_Mode ) + { + case RM_RUN_MULTI: + check(IDC_M_RUN_MULTI); + break; + case RM_RUN_EOF: + check(IDC_M_RUN_EOF); + break; + } + ::SendDlgItemMessage(_hSelf, IDC_M_RUN_TIMES, EM_LIMITTEXT, 4, 0); + goToCenter(); + + return TRUE; + } + + case WM_COMMAND : + { + if (HIWORD(wParam) == EN_CHANGE) + { + switch (LOWORD(wParam)) + { + case IDC_M_RUN_TIMES: + check(IDC_M_RUN_MULTI); + return TRUE; + + default: + return FALSE; + } + } + + switch (wParam) + { + case IDCANCEL : + ::ShowWindow(_hSelf, SW_HIDE); + return TRUE; + + case IDOK : + if ( isCheckedOrNot(IDC_M_RUN_MULTI) ) + { + m_Mode = RM_RUN_MULTI; + m_Times = ::GetDlgItemInt(_hSelf, IDC_M_RUN_TIMES, NULL, FALSE); + } + else if ( isCheckedOrNot(IDC_M_RUN_EOF) ) + { + m_Mode = RM_RUN_EOF; + } + + if (::SendDlgItemMessage(_hSelf, IDC_MACRO_COMBO, CB_GETCOUNT, 0, 0)) + ::SendMessage(_hParent, WM_MACRODLGRUNMACRO, 0, 0); + + return TRUE; + + default: + if ((HIWORD(wParam) == CBN_SELCHANGE) && (LOWORD(wParam) == IDC_MACRO_COMBO)) + { + m_macroIndex = ::SendDlgItemMessage(_hSelf, IDC_MACRO_COMBO, CB_GETCURSEL, 0, 0); + return TRUE; + } + } + } + } + return FALSE; +} + +void RunMacroDlg::check(int id) +{ + // IDC_M_RUN_MULTI + if ( id == IDC_M_RUN_MULTI ) + ::SendDlgItemMessage(_hSelf, IDC_M_RUN_MULTI, BM_SETCHECK, BST_CHECKED, 0); + else + ::SendDlgItemMessage(_hSelf, IDC_M_RUN_MULTI, BM_SETCHECK, BST_UNCHECKED, 0); + + // IDC_M_RUN_EOF + if ( id == IDC_M_RUN_EOF ) + ::SendDlgItemMessage(_hSelf, IDC_M_RUN_EOF, BM_SETCHECK, BST_CHECKED, 0); + else + ::SendDlgItemMessage(_hSelf, IDC_M_RUN_EOF, BM_SETCHECK, BST_UNCHECKED, 0); +} diff --git a/PowerEditor/src/WinControls/shortcut/RunMacroDlg.h b/PowerEditor/src/WinControls/shortcut/RunMacroDlg.h new file mode 100644 index 00000000..8630caf2 --- /dev/null +++ b/PowerEditor/src/WinControls/shortcut/RunMacroDlg.h @@ -0,0 +1,97 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +// created by Daniel Volk mordorpost@volkarts.com + +#ifndef RUN_MACRO_DLG_H +#define RUN_MACRO_DLG_H + +#include + +#include "StaticDialog.h" +#include "RunMacroDlg_rc.h" +#include "Buffer.h" +#include "ScintillaEditView.h" +#include "StatusBar.h" + + +using namespace std; + +#define RM_CANCEL -1 +#define RM_RUN_MULTI 1 +#define RM_RUN_EOF 2 + +class RunMacroDlg : public StaticDialog +{ +public : + RunMacroDlg() : StaticDialog(), m_Mode(RM_RUN_MULTI), m_Times(1) {}; + ~RunMacroDlg() { + }; + + void init(HINSTANCE hInst, HWND hPere/*, ScintillaEditView **ppEditView*/) { + Window::init(hInst, hPere); + }; + + void doDialog(bool isRTL = false) { + if (!isCreated()) + create(IDD_RUN_MACRO_DLG, isRTL); + else + ::ShowWindow(_hSelf, SW_SHOW); + }; + + //virtual void create(int, bool = false); + + void initMacroList() { + if (!isCreated()) return; + + NppParameters *pNppParam = NppParameters::getInstance(); + vector & macroList = pNppParam->getMacroList(); + + ::SendDlgItemMessage(_hSelf, IDC_MACRO_COMBO, CB_RESETCONTENT, 0, 0); + + if (::SendMessage(_hParent, WM_ISCURRENTMACRORECORDED, 0, 0)) + ::SendDlgItemMessage(_hSelf, IDC_MACRO_COMBO, CB_ADDSTRING, 0, (LPARAM)TEXT("Current recorded macro")); + + for (size_t i = 0 ; i < macroList.size() ; i++) + ::SendDlgItemMessage(_hSelf, IDC_MACRO_COMBO, CB_ADDSTRING, 0, (LPARAM)macroList[i].getName()); + + ::SendDlgItemMessage(_hSelf, IDC_MACRO_COMBO, CB_SETCURSEL, 0, 0); + m_macroIndex = 0; + }; + + int getMode() const {return m_Mode;}; + int getTimes() const {return m_Times;}; + int getMacro2Exec() const { + bool isCurMacroPresent = ::SendMessage(_hParent, WM_ISCURRENTMACRORECORDED, 0, 0) == TRUE; + return isCurMacroPresent?(m_macroIndex - 1):m_macroIndex; + }; + +private : + virtual BOOL CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam); + + bool isCheckedOrNot(int checkControlID) const { + return (BST_CHECKED == ::SendMessage(::GetDlgItem(_hSelf, checkControlID), BM_GETCHECK, 0, 0)); + }; + + void check(int); + + int m_Mode; + int m_Times; + int m_macroIndex; +}; + +#endif //RUN_MACRO_DLG_H diff --git a/PowerEditor/src/WinControls/shortcut/RunMacroDlg.rc b/PowerEditor/src/WinControls/shortcut/RunMacroDlg.rc new file mode 100644 index 00000000..615a75aa --- /dev/null +++ b/PowerEditor/src/WinControls/shortcut/RunMacroDlg.rc @@ -0,0 +1,41 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +// created by Daniel Volk mordorpost@volkarts.com + +#ifndef RUN_MACRO_DLG_RC +#define RUN_MACRO_DLG_RC +#include +#include "RunMacroDlg_rc.h" + +IDD_RUN_MACRO_DLG DIALOGEX 0, 0, 168, 110 +STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | + WS_SYSMENU +EXSTYLE WS_EX_TOOLWINDOW +CAPTION "Run Macro Multiple Times" +FONT 8, TEXT("MS Shell Dlg"), 400, 0, 0x1 +BEGIN + DEFPUSHBUTTON "&Run",IDOK,27,82,50,14 + PUSHBUTTON "&Cancel",IDCANCEL,91,82,50,14 + CONTROL "Run",IDC_M_RUN_MULTI,"Button",BS_AUTORADIOBUTTON,21,38,47,10 + CONTROL "Run until &end of file", IDC_M_RUN_EOF,"Button", BS_AUTORADIOBUTTON,21,56,140,10 + EDITTEXT IDC_M_RUN_TIMES,68,35,25,14,ES_AUTOHSCROLL | ES_NUMBER | WS_EX_DLGMODALFRAME + COMBOBOX IDC_MACRO_COMBO,67,10,96,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + RTEXT "Macro to run :",IDC_MACRO2RUN_STATIC,5,12,59,8 + LTEXT "times",IDC_TIMES_STATIC,97,38,65,8 +END +#endif // RUN_MACRO_DLG_RC diff --git a/PowerEditor/src/WinControls/shortcut/RunMacroDlg_rc.h b/PowerEditor/src/WinControls/shortcut/RunMacroDlg_rc.h new file mode 100644 index 00000000..685c4eb0 --- /dev/null +++ b/PowerEditor/src/WinControls/shortcut/RunMacroDlg_rc.h @@ -0,0 +1,32 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +// created by Daniel Volk mordorpost@volkarts.com + +#ifndef RUN_MACRO_DLG_RC_H +#define RUN_MACRO_DLG_RC_H + +#define IDD_RUN_MACRO_DLG 8000 +#define IDC_M_RUN_MULTI 8001 +#define IDC_M_RUN_EOF 8002 +#define IDC_M_RUN_TIMES 8003 +#define IDC_MACRO_COMBO 8004 +//#define IDC_MACROGROUP_STATIC 8005 +#define IDC_TIMES_STATIC 8005 +#define IDC_MACRO2RUN_STATIC 8006 + +#endif //RUN_MACRO_DLG_RC_H diff --git a/PowerEditor/src/WinControls/shortcut/shortcut.cpp b/PowerEditor/src/WinControls/shortcut/shortcut.cpp new file mode 100644 index 00000000..1b96f63b --- /dev/null +++ b/PowerEditor/src/WinControls/shortcut/shortcut.cpp @@ -0,0 +1,823 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#include "shortcut.h" +#include "Parameters.h" +#include "ScintillaEditView.h" +#include "resource.h" +#include "Notepad_plus.h" + +#include "keys.h" +const int KEY_STR_LEN = 16; + +struct KeyIDNAME { + const TCHAR * name; + UCHAR id; +}; + +KeyIDNAME namedKeyArray[] = { +{TEXT("None"), VK_NULL}, + +{TEXT("Backspace"), VK_BACK}, +{TEXT("Tab"), VK_TAB}, +{TEXT("Enter"), VK_RETURN}, +{TEXT("Esc"), VK_ESCAPE}, +{TEXT("Spacebar"), VK_SPACE}, + +{TEXT("Page up"), VK_PRIOR}, +{TEXT("Page down"), VK_NEXT}, +{TEXT("End"), VK_END}, +{TEXT("Home"), VK_HOME}, +{TEXT("Left"), VK_LEFT}, +{TEXT("Up"), VK_UP}, +{TEXT("Right"), VK_RIGHT}, +{TEXT("Down"), VK_DOWN}, + +{TEXT("INS"), VK_INSERT}, +{TEXT("DEL"), VK_DELETE}, + +{TEXT("0"), VK_0}, +{TEXT("1"), VK_1}, +{TEXT("2"), VK_2}, +{TEXT("3"), VK_3}, +{TEXT("4"), VK_4}, +{TEXT("5"), VK_5}, +{TEXT("6"), VK_6}, +{TEXT("7"), VK_7}, +{TEXT("8"), VK_8}, +{TEXT("9"), VK_9}, +{TEXT("A"), VK_A}, +{TEXT("B"), VK_B}, +{TEXT("C"), VK_C}, +{TEXT("D"), VK_D}, +{TEXT("E"), VK_E}, +{TEXT("F"), VK_F}, +{TEXT("G"), VK_G}, +{TEXT("H"), VK_H}, +{TEXT("I"), VK_I}, +{TEXT("J"), VK_J}, +{TEXT("K"), VK_K}, +{TEXT("L"), VK_L}, +{TEXT("M"), VK_M}, +{TEXT("N"), VK_N}, +{TEXT("O"), VK_O}, +{TEXT("P"), VK_P}, +{TEXT("Q"), VK_Q}, +{TEXT("R"), VK_R}, +{TEXT("S"), VK_S}, +{TEXT("T"), VK_T}, +{TEXT("U"), VK_U}, +{TEXT("V"), VK_V}, +{TEXT("W"), VK_W}, +{TEXT("X"), VK_X}, +{TEXT("Y"), VK_Y}, +{TEXT("Z"), VK_Z}, + +{TEXT("Numpad 0"), VK_NUMPAD0}, +{TEXT("Numpad 1"), VK_NUMPAD1}, +{TEXT("Numpad 2"), VK_NUMPAD2}, +{TEXT("Numpad 3"), VK_NUMPAD3}, +{TEXT("Numpad 4"), VK_NUMPAD4}, +{TEXT("Numpad 5"), VK_NUMPAD5}, +{TEXT("Numpad 6"), VK_NUMPAD6}, +{TEXT("Numpad 7"), VK_NUMPAD7}, +{TEXT("Numpad 8"), VK_NUMPAD8}, +{TEXT("Numpad 9"), VK_NUMPAD9}, +{TEXT("Num *"), VK_MULTIPLY}, +{TEXT("Num +"), VK_ADD}, +//{TEXT("Num Enter"), VK_SEPARATOR}, //this one doesnt seem to work +{TEXT("Num -"), VK_SUBTRACT}, +{TEXT("Num ."), VK_DECIMAL}, +{TEXT("Num /"), VK_DIVIDE}, +{TEXT("F1"), VK_F1}, +{TEXT("F2"), VK_F2}, +{TEXT("F3"), VK_F3}, +{TEXT("F4"), VK_F4}, +{TEXT("F5"), VK_F5}, +{TEXT("F6"), VK_F6}, +{TEXT("F7"), VK_F7}, +{TEXT("F8"), VK_F8}, +{TEXT("F9"), VK_F9}, +{TEXT("F10"), VK_F10}, +{TEXT("F11"), VK_F11}, +{TEXT("F12"), VK_F12}, + +{TEXT("~"), VK_OEM_3}, +{TEXT("-"), VK_OEM_MINUS}, +{TEXT("="), VK_OEM_PLUS}, +{TEXT("["), VK_OEM_4}, +{TEXT("]"), VK_OEM_6}, +{TEXT(";"), VK_OEM_1}, +{TEXT("'"), VK_OEM_7}, +{TEXT("\\"), VK_OEM_5}, +{TEXT(","), VK_OEM_COMMA}, +{TEXT("."), VK_OEM_PERIOD}, +{TEXT("/"), VK_OEM_2}, + +{TEXT("<>"), VK_OEM_102}, +}; + +#define nrKeys sizeof(namedKeyArray)/sizeof(KeyIDNAME) + +/* +TCHAR vKeyArray[][KEY_STR_LEN] = \ +{TEXT(""), TEXT("BACKSPACE"), TEXT("TAB"), TEXT("ENTER"), TEXT("PAUSE"), TEXT("CAPS LOCK"), TEXT("ESC"), TEXT("SPACEBAR"), TEXT("PAGE UP"), TEXT("PAGE DOWN"),\ +"END", TEXT("HOME"), TEXT("LEFT ARROW"), TEXT("UP ARROW"), TEXT("RIGHT ARROW"), TEXT("DOWN ARROW"), TEXT("INS"), TEXT("DEL"),\ +"0", TEXT("1"), TEXT("2"), TEXT("3"), TEXT("4"), TEXT("5"), TEXT("6"), TEXT("7"), TEXT("8"), TEXT("9"),\ +"A", TEXT("B"), TEXT("C"), TEXT("D"), TEXT("E"), TEXT("F"), TEXT("G"), TEXT("H"), TEXT("I"), TEXT("J"), TEXT("K"), TEXT("L"), TEXT("M"),\ +"N", TEXT("O"), TEXT("P"), TEXT("Q"), TEXT("R"), TEXT("S"), TEXT("T"), TEXT("U"), TEXT("V"), TEXT("W"), TEXT("X"), TEXT("Y"), TEXT("Z"),\ +"NUMPAD0", TEXT("NUMPAD1"), TEXT("NUMPAD2"), TEXT("NUMPAD3"), TEXT("NUMPAD4"),\ +"NUMPAD5", TEXT("NUMPAD6"), TEXT("NUMPAD7"), TEXT("NUMPAD8"), TEXT("NUMPAD9"),\ +"F1", TEXT("F2"), TEXT("F3"), TEXT("F4"), TEXT("F5"), TEXT("F6"),\ +"F7", TEXT("F8"), TEXT("F9"), TEXT("F10"), TEXT("F11"), TEXT("F12")}; + +UCHAR vkeyValue[] = {\ +0x00, 0x08, 0x09, 0x0D, 0x13, 0x14, 0x1B, 0x20, 0x21, 0x22,\ +0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x2D, 0x2E, 0x30, 0x31,\ +0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x41, 0x42,\ +0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C,\ +0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56,\ +0x57, 0x58, 0x59, 0x5A, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65,\ +0x66, 0x67, 0x68, 0x69, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75,\ +0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B}; +*/ + +generic_string Shortcut::toString() const +{ + generic_string sc = TEXT(""); + if (!isEnabled()) + return sc; + + if (_keyCombo._isCtrl) + sc += TEXT("Ctrl+"); + if (_keyCombo._isAlt) + sc += TEXT("Alt+"); + if (_keyCombo._isShift) + sc += TEXT("Shift+"); + + generic_string keyString; + getKeyStrFromVal(_keyCombo._key, keyString); + sc += keyString; + return sc; +} + +void Shortcut::setName(const TCHAR * name) { + lstrcpyn(_menuName, name, nameLenMax); + lstrcpyn(_name, name, nameLenMax); + int i = 0, j = 0; + while(name[j] != 0 && i < nameLenMax) { + if (name[j] != '&') { + _name[i] = name[j]; + i++; + } else { //check if this ampersand is being escaped + if (name[j+1] == '&') { //escaped ampersand + _name[i] = name[j]; + i++; + j++; //skip escaped ampersand + } + } + j++; + } + _name[i] = 0; +} + +generic_string ScintillaKeyMap::toString() const { + return toString(0); +} + +generic_string ScintillaKeyMap::toString(int index) const { + generic_string sc = TEXT(""); + if (!isEnabled()) + return sc; + + KeyCombo kc = _keyCombos[index]; + if (kc._isCtrl) + sc += TEXT("Ctrl+"); + if (kc._isAlt) + sc += TEXT("Alt+"); + if (kc._isShift) + sc += TEXT("Shift+"); + + generic_string keyString; + getKeyStrFromVal(kc._key, keyString); + sc += keyString; + return sc; +} + +KeyCombo ScintillaKeyMap::getKeyComboByIndex(int index) const { + return _keyCombos[index]; +} + +void ScintillaKeyMap::setKeyComboByIndex(int index, KeyCombo combo) { + if(combo._key == 0 && (size > 1)) { //remove the item if possible + _keyCombos.erase(_keyCombos.begin() + index); + } + _keyCombos[index] = combo; +} + +void ScintillaKeyMap::removeKeyComboByIndex(int index) { + if (size > 1 && index > -1 && index < int(size)) { + _keyCombos.erase(_keyCombos.begin() + index); + size--; + } +} + +int ScintillaKeyMap::addKeyCombo(KeyCombo combo) { //returns index where key is added, or -1 when invalid + if (combo._key == 0) //do not allow to add disabled keycombos + return -1; + if (!isEnabled()) { //disabled, override current combo with new enabled one + _keyCombos[0] = combo; + return 0; + } + for(size_t i = 0; i < size; i++) { //if already in the list do not add it + KeyCombo & kc = _keyCombos[i]; + if (combo._key == kc._key && combo._isCtrl == kc._isCtrl && combo._isAlt == kc._isAlt && combo._isShift == kc._isShift) + return i; //already in the list + } + _keyCombos.push_back(combo); + size++; + return (size - 1); +} + +bool ScintillaKeyMap::isEnabled() const { + return (_keyCombos[0]._key != 0); +} + +size_t ScintillaKeyMap::getSize() const { + return size; +} + +void getKeyStrFromVal(UCHAR keyVal, generic_string & str) +{ + str = TEXT(""); + bool found = false; + int i; + for (i = 0; i < nrKeys; i++) { + if (keyVal == namedKeyArray[i].id) { + found = true; + break; + } + } + if (found) + str = namedKeyArray[i].name; + else + str = TEXT("Unlisted"); +} + +void getNameStrFromCmd(DWORD cmd, generic_string & str) +{ + if ((cmd >= ID_MACRO) && (cmd < ID_MACRO_LIMIT)) + { + vector & theMacros = (NppParameters::getInstance())->getMacroList(); + int i = cmd - ID_MACRO; + str = theMacros[i].getName(); + } + else if ((cmd >= ID_USER_CMD) && (cmd < ID_USER_CMD_LIMIT)) + { + vector & userCommands = (NppParameters::getInstance())->getUserCommandList(); + int i = cmd - ID_USER_CMD; + str = userCommands[i].getName(); + } + else if ((cmd >= ID_PLUGINS_CMD) && (cmd < ID_PLUGINS_CMD_LIMIT)) + { + vector & pluginCmds = (NppParameters::getInstance())->getPluginCommandList(); + int i = 0; + for (size_t j = 0 ; j < pluginCmds.size() ; j++) + { + if (pluginCmds[j].getID() == cmd) + { + i = j; + break; + } + } + str = pluginCmds[i].getName(); + } + else + { + HWND hNotepad_plus = ::FindWindow(Notepad_plus::getClassName(), NULL); + const int commandSize = 64; + TCHAR cmdName[commandSize]; + int nbChar = ::GetMenuString((HMENU)::SendMessage(hNotepad_plus, NPPM_INTERNAL_GETMENU, 0, 0), cmd, cmdName, commandSize, MF_BYCOMMAND); + if (!nbChar) + return; + bool fin = false; + int j = 0; + size_t len = lstrlen(cmdName); + for (size_t i = 0 ; i < len; i++) + { + switch(cmdName[i]) + { + case '\t': + cmdName[j] = '\0'; + fin = true; + break; + + case '&': + break; + + default : + cmdName[j++] = cmdName[i]; + } + if (fin) + break; + } + cmdName[j] = '\0'; + str = cmdName; + } + return; +} + +BOOL CALLBACK Shortcut::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam) +{ + switch (Message) + { + case WM_INITDIALOG : + { + ::SetDlgItemText(_hSelf, IDC_NAME_EDIT, getMenuName()); //display the menu name, with ampersands + if (!_canModifyName) + ::SendDlgItemMessage(_hSelf, IDC_NAME_EDIT, EM_SETREADONLY, TRUE, 0); + int textlen = (int)::SendDlgItemMessage(_hSelf, IDC_NAME_EDIT, WM_GETTEXTLENGTH, 0, 0); + + ::SendDlgItemMessage(_hSelf, IDC_CTRL_CHECK, BM_SETCHECK, _keyCombo._isCtrl?BST_CHECKED:BST_UNCHECKED, 0); + ::SendDlgItemMessage(_hSelf, IDC_ALT_CHECK, BM_SETCHECK, _keyCombo._isAlt?BST_CHECKED:BST_UNCHECKED, 0); + ::SendDlgItemMessage(_hSelf, IDC_SHIFT_CHECK, BM_SETCHECK, _keyCombo._isShift?BST_CHECKED:BST_UNCHECKED, 0); + ::EnableWindow(::GetDlgItem(_hSelf, IDOK), isValid() && (textlen > 0 || !_canModifyName)); + int iFound = -1; + for (size_t i = 0 ; i < nrKeys ; i++) + { + ::SendDlgItemMessage(_hSelf, IDC_KEY_COMBO, CB_ADDSTRING, 0, (LPARAM)namedKeyArray[i].name); + + if (_keyCombo._key == namedKeyArray[i].id) + iFound = i; + } + + if (iFound != -1) + ::SendDlgItemMessage(_hSelf, IDC_KEY_COMBO, CB_SETCURSEL, iFound, 0); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_WARNING_STATIC), isEnabled()?SW_HIDE:SW_SHOW); + + goToCenter(); + return TRUE; + } + + case WM_COMMAND : + { + int textlen = (int)::SendDlgItemMessage(_hSelf, IDC_NAME_EDIT, WM_GETTEXTLENGTH, 0, 0); + switch (wParam) + { + case IDC_CTRL_CHECK : + _keyCombo._isCtrl = BST_CHECKED == ::SendDlgItemMessage(_hSelf, wParam, BM_GETCHECK, 0, 0); + ::EnableWindow(::GetDlgItem(_hSelf, IDOK), isValid() && (textlen > 0 || !_canModifyName)); + return TRUE; + + case IDC_ALT_CHECK : + _keyCombo._isAlt = BST_CHECKED == ::SendDlgItemMessage(_hSelf, wParam, BM_GETCHECK, 0, 0); + ::EnableWindow(::GetDlgItem(_hSelf, IDOK), isValid() && (textlen > 0 || !_canModifyName)); + return TRUE; + + case IDC_SHIFT_CHECK : + _keyCombo._isShift = BST_CHECKED == ::SendDlgItemMessage(_hSelf, wParam, BM_GETCHECK, 0, 0); + return TRUE; + + case IDOK : + if (!isEnabled()) { + _keyCombo._isCtrl = _keyCombo._isAlt = _keyCombo._isShift = false; + } + if (_canModifyName) { + TCHAR editName[nameLenMax]; + ::SendDlgItemMessage(_hSelf, IDC_NAME_EDIT, WM_GETTEXT, nameLenMax, (LPARAM)editName); + setName(editName); + } + ::EndDialog(_hSelf, 0); + return TRUE; + + case IDCANCEL : + ::EndDialog(_hSelf, -1); + return TRUE; + + default: + if (HIWORD(wParam) == EN_CHANGE) + { + if (LOWORD(wParam) == IDC_NAME_EDIT) + { + ::EnableWindow(::GetDlgItem(_hSelf, IDOK), isValid() && (textlen > 0 || !_canModifyName)); + return TRUE; + } + } + else if (HIWORD(wParam) == CBN_SELCHANGE) + { + if (LOWORD(wParam) == IDC_KEY_COMBO) + { + int i = ::SendDlgItemMessage(_hSelf, LOWORD(wParam), CB_GETCURSEL, 0, 0); + _keyCombo._key = namedKeyArray[i].id; + ::EnableWindow(::GetDlgItem(_hSelf, IDOK), isValid() && (textlen > 0 || !_canModifyName)); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_WARNING_STATIC), isEnabled()?SW_HIDE:SW_SHOW); + return TRUE; + } + } + return FALSE; + } + } + default : + return FALSE; + } + return FALSE; +} + +// return true if one of CommandShortcuts is deleted. Otherwise false. +void Accelerator::updateShortcuts() +{ + NppParameters *pNppParam = NppParameters::getInstance(); + + vector & shortcuts = pNppParam->getUserShortcuts(); + vector & macros = pNppParam->getMacroList(); + vector & userCommands = pNppParam->getUserCommandList(); + vector & pluginCommands = pNppParam->getPluginCommandList(); + + size_t nbMenu = shortcuts.size(); + size_t nbMacro = macros.size(); + size_t nbUserCmd = userCommands.size(); + size_t nbPluginCmd = pluginCommands.size(); + + if (_pAccelArray) + delete [] _pAccelArray; + _pAccelArray = new ACCEL[nbMenu+nbMacro+nbUserCmd+nbPluginCmd]; + + int offset = 0; + size_t i = 0; + //no validation performed, it might be that invalid shortcuts are being used by default. Allows user to 'hack', might be a good thing + for(i = 0; i < nbMenu; i++) { + if (shortcuts[i].isEnabled()) {// && shortcuts[i].isValid()) { + _pAccelArray[offset].cmd = (WORD)(shortcuts[i].getID()); + _pAccelArray[offset].fVirt = shortcuts[i].getAcceleratorModifiers(); + _pAccelArray[offset].key = shortcuts[i].getKeyCombo()._key; + offset++; + } + } + + for(i = 0; i < nbMacro; i++) { + if (macros[i].isEnabled()) {// && macros[i].isValid()) { + _pAccelArray[offset].cmd = (WORD)(macros[i].getID()); + _pAccelArray[offset].fVirt = macros[i].getAcceleratorModifiers(); + _pAccelArray[offset].key = macros[i].getKeyCombo()._key; + offset++; + } + } + + for(i = 0; i < nbUserCmd; i++) { + if (userCommands[i].isEnabled()) {// && userCommands[i].isValid()) { + _pAccelArray[offset].cmd = (WORD)(userCommands[i].getID()); + _pAccelArray[offset].fVirt = userCommands[i].getAcceleratorModifiers(); + _pAccelArray[offset].key = userCommands[i].getKeyCombo()._key; + offset++; + } + } + + for(i = 0; i < nbPluginCmd; i++) { + if (pluginCommands[i].isEnabled()) {// && pluginCommands[i].isValid()) { + _pAccelArray[offset].cmd = (WORD)(pluginCommands[i].getID()); + _pAccelArray[offset].fVirt = pluginCommands[i].getAcceleratorModifiers(); + _pAccelArray[offset].key = pluginCommands[i].getKeyCombo()._key; + offset++; + } + } + + _nbAccelItems = offset; + + updateFullMenu(); + reNew(); //update the table + return; +} + +void Accelerator::updateFullMenu() { + NppParameters * pNppParam = NppParameters::getInstance(); + vector commands = pNppParam->getUserShortcuts(); + for(size_t i = 0; i < commands.size(); i++) { + updateMenuItemByCommand(commands[i]); + } + + vector mcommands = pNppParam->getMacroList(); + for(size_t i = 0; i < mcommands.size(); i++) { + updateMenuItemByCommand(mcommands[i]); + } + + vector ucommands = pNppParam->getUserCommandList(); + for(size_t i = 0; i < ucommands.size(); i++) { + updateMenuItemByCommand(ucommands[i]); + } + + vector pcommands = pNppParam->getPluginCommandList(); + for(size_t i = 0; i < pcommands.size(); i++) { + updateMenuItemByCommand(pcommands[i]); + } + + ::DrawMenuBar(_hMenuParent); +} + +void Accelerator::updateMenuItemByCommand(CommandShortcut csc) { + int cmdID = (int)csc.getID(); + ::ModifyMenu(_hAccelMenu, cmdID, MF_BYCOMMAND, cmdID, csc.toMenuItemString().c_str()); +} + +recordedMacroStep::recordedMacroStep(int iMessage, long wParam, long lParam) + : message(iMessage), wParameter(wParam), lParameter(lParam), MacroType(mtUseLParameter) +{ + if (lParameter) { + switch (message) { + case SCI_SETTEXT : + case SCI_REPLACESEL : + case SCI_REPLACETARGET : + case SCI_REPLACETARGETRE : + case SCI_SEARCHINTARGET : + case SCI_ADDTEXT : + case SCI_ADDSTYLEDTEXT : + case SCI_INSERTTEXT : + case SCI_APPENDTEXT : + case SCI_SETWORDCHARS : + case SCI_SETWHITESPACECHARS : + case SCI_SETSTYLINGEX : + case SCI_TEXTWIDTH : + case SCI_STYLESETFONT : + case SCI_SEARCHNEXT : + case SCI_SEARCHPREV : + sParameter = *reinterpret_cast(lParameter); + MacroType = mtUseSParameter; + lParameter = 0; + break; + + default : // for all other messages, use lParameter "as is" + break; + } + } +} + +void recordedMacroStep::PlayBack(Window* pNotepad, ScintillaEditView *pEditView) +{ + if (MacroType == mtMenuCommand) + ::SendMessage(pNotepad->getHSelf(), WM_COMMAND, wParameter, 0); + + else + { + long lParam = lParameter; + if (MacroType == mtUseSParameter) + lParam = reinterpret_cast(sParameter.c_str()); + pEditView->execute(message, wParameter, lParam); + if ( (message == SCI_SETTEXT) + || (message == SCI_REPLACESEL) + || (message == SCI_ADDTEXT) + || (message == SCI_ADDSTYLEDTEXT) + || (message == SCI_INSERTTEXT) + || (message == SCI_APPENDTEXT) ) { + SCNotification scnN; + scnN.nmhdr.code = SCN_CHARADDED; + scnN.nmhdr.hwndFrom = pEditView->getHSelf(); + scnN.nmhdr.idFrom = 0; + scnN.ch = sParameter.at(0); + ::SendMessage(pNotepad->getHSelf(), WM_NOTIFY, 0, reinterpret_cast(&scnN)); + } + } +} + +void ScintillaAccelerator::init(vector * vScintillas, HMENU hMenu, HWND menuParent) { + _hAccelMenu = hMenu; + _hMenuParent = menuParent; + size_t nr = vScintillas->size(); + for(size_t i = 0; i < nr; i++) { + _vScintillas.push_back(vScintillas->at(i)); + } + _nrScintillas = (int)nr; +} + +void ScintillaAccelerator::updateKeys() +{ + NppParameters *pNppParam = NppParameters::getInstance(); + vector & map = pNppParam->getScintillaKeyList(); + size_t mapSize = map.size(); + size_t index; + + for(int i = 0; i < _nrScintillas; i++) + { + ::SendMessage(_vScintillas[i], SCI_CLEARALLCMDKEYS, 0, 0); + for(size_t j = mapSize - 1; j >= 0; j--) //reverse order, top of the list has highest priority + { + ScintillaKeyMap skm = map[j]; + if (skm.isEnabled()) + { //no validating, scintilla accepts more keys + size_t size = skm.getSize(); + for(index = 0; index < size; index++) + ::SendMessage(_vScintillas[i], SCI_ASSIGNCMDKEY, skm.toKeyDef(index), skm.getScintillaKeyID()); + } + if (skm.getMenuCmdID() != 0) + { + updateMenuItemByID(skm, skm.getMenuCmdID()); + } + if (j == 0) //j is unsigned, so default method doesnt work + break; + } + } +} + +void ScintillaAccelerator::updateMenuItemByID(ScintillaKeyMap skm, int id) +{ + NppParameters *pNppParam = NppParameters::getInstance(); + const int commandSize = 64; + TCHAR cmdName[commandSize]; + ::GetMenuString(_hAccelMenu, id, cmdName, commandSize, MF_BYCOMMAND); + int i = 0; + while(cmdName[i] != 0) + { + if (cmdName[i] == '\t') + { + cmdName[i] = 0; + break; + } + i++; + } + generic_string menuItem = cmdName; + if (skm.isEnabled()) + { + menuItem += TEXT("\t"); + //menuItem += TEXT("Sc:"); //sc: scintilla shortcut + menuItem += skm.toString(); + } + ::ModifyMenu(_hAccelMenu, id, MF_BYCOMMAND, id, menuItem.c_str()); + ::DrawMenuBar(_hMenuParent); +} + +//This procedure uses _keyCombo as a temp. variable to store current settings which can then later be applied (by pressing OK) +void ScintillaKeyMap::applyToCurrentIndex() { + int index = (int)::SendDlgItemMessage(_hSelf, IDC_LIST_KEYS, LB_GETCURSEL, 0, 0); + if(index == LB_ERR) + return; + setKeyComboByIndex(index, _keyCombo); + updateListItem(index); + ::SendDlgItemMessage(_hSelf, IDC_LIST_KEYS, LB_SETCURSEL, index, 0); + +} + +void ScintillaKeyMap::validateDialog() { + bool valid = isValid(); //current combo valid? + bool isDisabling = _keyCombo._key == 0; //true if this keycombo were to disable the shortcut + bool isDisabled = !isEnabled(); //true if this shortcut already is + + ::EnableWindow(::GetDlgItem(_hSelf, IDC_BUTTON_ADD), valid && !isDisabling); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_BUTTON_APPLY), valid && (!isDisabling || size == 1)); + ::EnableWindow(::GetDlgItem(_hSelf, IDC_BUTTON_RMVE), (size > 1)?TRUE:FALSE); + ::ShowWindow(::GetDlgItem(_hSelf, IDC_WARNING_STATIC), isDisabled?SW_SHOW:SW_HIDE); +} + +void ScintillaKeyMap::showCurrentSettings() { + int i = ::SendDlgItemMessage(_hSelf, IDC_LIST_KEYS, LB_GETCURSEL, 0, 0); + _keyCombo = _keyCombos[i]; + ::SendDlgItemMessage(_hSelf, IDC_CTRL_CHECK, BM_SETCHECK, _keyCombo._isCtrl?BST_CHECKED:BST_UNCHECKED, 0); + ::SendDlgItemMessage(_hSelf, IDC_ALT_CHECK, BM_SETCHECK, _keyCombo._isAlt?BST_CHECKED:BST_UNCHECKED, 0); + ::SendDlgItemMessage(_hSelf, IDC_SHIFT_CHECK, BM_SETCHECK, _keyCombo._isShift?BST_CHECKED:BST_UNCHECKED, 0); + for (size_t i = 0 ; i < nrKeys ; i++) + { + if (_keyCombo._key == namedKeyArray[i].id) + { + ::SendDlgItemMessage(_hSelf, IDC_KEY_COMBO, CB_SETCURSEL, i, 0); + break; + } + } +} + +void ScintillaKeyMap::updateListItem(int index) { + ::SendDlgItemMessage(_hSelf, IDC_LIST_KEYS, LB_INSERTSTRING, index, (LPARAM)toString(index).c_str()); + ::SendDlgItemMessage(_hSelf, IDC_LIST_KEYS, LB_DELETESTRING, index+1, 0); +} + +BOOL CALLBACK ScintillaKeyMap::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam) +{ + + switch (Message) + { + case WM_INITDIALOG : + { + ::SetDlgItemText(_hSelf, IDC_NAME_EDIT, _name); + int textlen = (int)::SendDlgItemMessage(_hSelf, IDC_NAME_EDIT, WM_GETTEXTLENGTH, 0, 0); + _keyCombo = _keyCombos[0]; + + for (size_t i = 0 ; i < nrKeys ; i++) + { + ::SendDlgItemMessage(_hSelf, IDC_KEY_COMBO, CB_ADDSTRING, 0, (LPARAM)namedKeyArray[i].name); + } + + for(size_t i = 0; i < size; i++) { + ::SendDlgItemMessage(_hSelf, IDC_LIST_KEYS, LB_ADDSTRING, 0, (LPARAM)toString(i).c_str()); + } + ::SendDlgItemMessage(_hSelf, IDC_LIST_KEYS, LB_SETCURSEL, 0, 0); + + showCurrentSettings(); + validateDialog(); + + goToCenter(); + return TRUE; + } + + case WM_COMMAND : + { + switch (wParam) + { + case IDC_CTRL_CHECK : + _keyCombo._isCtrl = BST_CHECKED == ::SendDlgItemMessage(_hSelf, wParam, BM_GETCHECK, 0, 0); + //applyToCurrentIndex(); + validateDialog(); + return TRUE; + + case IDC_ALT_CHECK : + _keyCombo._isAlt = BST_CHECKED == ::SendDlgItemMessage(_hSelf, wParam, BM_GETCHECK, 0, 0); + //applyToCurrentIndex(); + validateDialog(); + return TRUE; + + case IDC_SHIFT_CHECK : + _keyCombo._isShift = BST_CHECKED == ::SendDlgItemMessage(_hSelf, wParam, BM_GETCHECK, 0, 0); + //applyToCurrentIndex(); + return TRUE; + + case IDOK : + //Cleanup + _keyCombo._key = 0; + _keyCombo._isCtrl = _keyCombo._isAlt = _keyCombo._isShift = false; + ::EndDialog(_hSelf, 0); + return TRUE; + + case IDCANCEL : + ::EndDialog(_hSelf, -1); + return TRUE; + + case IDC_BUTTON_ADD: { + int oldsize = size; + int res = addKeyCombo(_keyCombo); + if (res > -1) { + if (res == oldsize) { + ::SendDlgItemMessage(_hSelf, IDC_LIST_KEYS, LB_INSERTSTRING, -1, (LPARAM)toString(res).c_str()); + }else { //update current generic_string, can happen if it was disabled + updateListItem(res); + } + ::SendDlgItemMessage(_hSelf, IDC_LIST_KEYS, LB_SETCURSEL, res, 0); + } + showCurrentSettings(); + validateDialog(); + return TRUE; } + + case IDC_BUTTON_RMVE: { + if (size == 1) //cannot delete last shortcut + return TRUE; + int i = ::SendDlgItemMessage(_hSelf, IDC_LIST_KEYS, LB_GETCURSEL, 0, 0); + removeKeyComboByIndex(i); + ::SendDlgItemMessage(_hSelf, IDC_LIST_KEYS, LB_DELETESTRING, i, 0); + if (i == size) + i = size - 1; + ::SendDlgItemMessage(_hSelf, IDC_LIST_KEYS, LB_SETCURSEL, i, 0); + showCurrentSettings(); + validateDialog(); + return TRUE; } + + case IDC_BUTTON_APPLY: { + applyToCurrentIndex(); + validateDialog(); + return TRUE; } + + default: + if (HIWORD(wParam) == CBN_SELCHANGE || HIWORD(wParam) == LBN_SELCHANGE) + { + switch(LOWORD(wParam)) { + case IDC_KEY_COMBO: + { + int i = ::SendDlgItemMessage(_hSelf, IDC_KEY_COMBO, CB_GETCURSEL, 0, 0); + _keyCombo._key = namedKeyArray[i].id; + //applyToCurrentIndex(); + validateDialog(); + return TRUE; + } + case IDC_LIST_KEYS: + { + showCurrentSettings(); + return TRUE; + } + } + } + return FALSE; + } + } + default : + return FALSE; + } + + return FALSE; +} diff --git a/PowerEditor/src/WinControls/shortcut/shortcut.h b/PowerEditor/src/WinControls/shortcut/shortcut.h new file mode 100644 index 00000000..c9c5b438 --- /dev/null +++ b/PowerEditor/src/WinControls/shortcut/shortcut.h @@ -0,0 +1,381 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#ifndef SHORTCUTS_H +#define SHORTCUTS_H + +//#include "Parameters.h" +#include +#include +#include +#include "shortcutRc.h" +#include "StaticDialog.h" +#include "Scintilla.h" +#include "Common.h" + +using namespace std; + +const size_t nameLenMax = 64; + +class NppParameters; + +void getKeyStrFromVal(UCHAR keyVal, generic_string & str); +void getNameStrFromCmd(DWORD cmd, generic_string & str); +static int keyTranslate(int keyIn) { + switch (keyIn) { + case VK_DOWN: return SCK_DOWN; + case VK_UP: return SCK_UP; + case VK_LEFT: return SCK_LEFT; + case VK_RIGHT: return SCK_RIGHT; + case VK_HOME: return SCK_HOME; + case VK_END: return SCK_END; + case VK_PRIOR: return SCK_PRIOR; + case VK_NEXT: return SCK_NEXT; + case VK_DELETE: return SCK_DELETE; + case VK_INSERT: return SCK_INSERT; + case VK_ESCAPE: return SCK_ESCAPE; + case VK_BACK: return SCK_BACK; + case VK_TAB: return SCK_TAB; + case VK_RETURN: return SCK_RETURN; + case VK_ADD: return SCK_ADD; + case VK_SUBTRACT: return SCK_SUBTRACT; + case VK_DIVIDE: return SCK_DIVIDE; + case VK_OEM_2: return '/'; + case VK_OEM_3: return '`'; + case VK_OEM_4: return '['; + case VK_OEM_5: return '\\'; + case VK_OEM_6: return ']'; + default: return keyIn; + } +}; + +struct KeyCombo { + bool _isCtrl; + bool _isAlt; + bool _isShift; + UCHAR _key; +}; + +class Shortcut : public StaticDialog { +public: + Shortcut(): _canModifyName(false) { + setName(TEXT("")); + _keyCombo._isCtrl = false; + _keyCombo._isAlt = false; + _keyCombo._isShift = false; + _keyCombo._key = 0; + }; + + Shortcut(const TCHAR *name, bool isCtrl, bool isAlt, bool isShift, UCHAR key) : _canModifyName(false) { + _name[0] = '\0'; + if (name) { + setName(name); + } else { + setName(TEXT("")); + } + _keyCombo._isCtrl = isCtrl; + _keyCombo._isAlt = isAlt; + _keyCombo._isShift = isShift; + _keyCombo._key = key; + }; + + Shortcut(const Shortcut & sc) { + setName(sc.getMenuName()); + _keyCombo = sc._keyCombo; + _canModifyName = sc._canModifyName; + } + + BYTE getAcceleratorModifiers() { + return ( FVIRTKEY | (_keyCombo._isCtrl?FCONTROL:0) | (_keyCombo._isAlt?FALT:0) | (_keyCombo._isShift?FSHIFT:0) ); + }; + + Shortcut & operator=(const Shortcut & sc) { + //Do not allow setting empty names + //So either we have an empty name or the other name has to be set + if (_name[0] == 0 || sc._name[0] != 0) { + setName(sc.getMenuName()); + } + _keyCombo = sc._keyCombo; + this->_canModifyName = sc._canModifyName; + return *this; + } + friend inline const bool operator==(const Shortcut & a, const Shortcut & b) { + return ((lstrcmp(a.getMenuName(), b.getMenuName()) == 0) && + (a._keyCombo._isCtrl == b._keyCombo._isCtrl) && + (a._keyCombo._isAlt == b._keyCombo._isAlt) && + (a._keyCombo._isShift == b._keyCombo._isShift) && + (a._keyCombo._key == b._keyCombo._key) + ); + }; + + friend inline const bool operator!=(const Shortcut & a, const Shortcut & b) { + return !(a == b); + }; + + virtual int doDialog() { + return ::DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_SHORTCUT_DLG), _hParent, (DLGPROC)dlgProc, (LPARAM)this); + }; + + virtual bool isValid() const { //valid should only be used in cases where the shortcut isEnabled(). + if (_keyCombo._key == 0) + return true; //disabled _keyCombo always valid, just disabled + + //These keys need a modifier, else invalid + if ( ((_keyCombo._key >= 'A') && (_keyCombo._key <= 'Z')) || ((_keyCombo._key >= '0') && (_keyCombo._key <= '9')) || _keyCombo._key == VK_SPACE || _keyCombo._key == VK_CAPITAL || _keyCombo._key == VK_BACK || _keyCombo._key == VK_RETURN) { + return ((_keyCombo._isCtrl) || (_keyCombo._isAlt)); + } + // the remaining keys are always valid + return true; + }; + virtual bool isEnabled() const { //true if _keyCombo != 0, false if _keyCombo == 0, in which case no accelerator should be made + return (_keyCombo._key != 0); + }; + + virtual generic_string toString() const; //the hotkey part + generic_string toMenuItemString() const { //generic_string suitable for menu + generic_string str = _menuName; + if(isEnabled()) + { + str += TEXT("\t"); + str += toString(); + } + return str; + }; + const KeyCombo & getKeyCombo() const { + return _keyCombo; + }; + + const TCHAR * getName() const { + return _name; + }; + + const TCHAR * getMenuName() const { + return _menuName; + } + + void setName(const TCHAR * name); + +protected : + KeyCombo _keyCombo; + virtual BOOL CALLBACK run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam); + bool _canModifyName; + TCHAR _name[nameLenMax]; //normal name is plain text (for display purposes) + TCHAR _menuName[nameLenMax]; //menu name has ampersands for quick keys +}; + +class CommandShortcut : public Shortcut { +public: + CommandShortcut(Shortcut sc, long id) : Shortcut(sc), _id(id) {}; + unsigned long getID() const {return _id;}; + void setID(unsigned long id) { _id = id;}; + +private : + unsigned long _id; +}; + + +class ScintillaKeyMap : public Shortcut { +public: + ScintillaKeyMap(Shortcut sc, unsigned long scintillaKeyID, unsigned long id): Shortcut(sc), _menuCmdID(id), _scintillaKeyID(scintillaKeyID) { + _keyCombos.clear(); + _keyCombos.push_back(_keyCombo); + _keyCombo._key = 0; + size = 1; + }; + unsigned long getScintillaKeyID() const {return _scintillaKeyID;}; + int getMenuCmdID() const {return _menuCmdID;}; + int toKeyDef(int index) const { + KeyCombo kc = _keyCombos[index]; + int keymod = (kc._isCtrl?SCMOD_CTRL:0) | (kc._isAlt?SCMOD_ALT:0) | (kc._isShift?SCMOD_SHIFT:0); + return keyTranslate((int)kc._key) + (keymod << 16); + }; + + KeyCombo getKeyComboByIndex(int index) const; + void ScintillaKeyMap::setKeyComboByIndex(int index, KeyCombo combo); + void removeKeyComboByIndex(int index); + void clearDups() { + if (size > 1) + _keyCombos.erase(_keyCombos.begin()+1, _keyCombos.end()); + size = 1; + }; + int addKeyCombo(KeyCombo combo); + bool isEnabled() const; + size_t getSize() const; + + generic_string toString() const; + generic_string toString(int index) const; + + int doDialog() { + return ::DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_SHORTCUTSCINT_DLG), _hParent, (DLGPROC)dlgProc, (LPARAM)this); + }; + + //only compares the internal KeyCombos, nothing else + friend inline const bool operator==(const ScintillaKeyMap & a, const ScintillaKeyMap & b) { + bool equal = a.size == b.size; + if (!equal) + return false; + size_t i = 0; + while(equal && (i < a.size)) { + equal = + (a._keyCombos[i]._isCtrl == b._keyCombos[i]._isCtrl) && + (a._keyCombos[i]._isAlt == b._keyCombos[i]._isAlt) && + (a._keyCombos[i]._isShift == b._keyCombos[i]._isShift) && + (a._keyCombos[i]._key == b._keyCombos[i]._key); + i++; + } + return equal; + }; + + friend inline const bool operator!=(const ScintillaKeyMap & a, const ScintillaKeyMap & b) { + return !(a == b); + }; + +private: + unsigned long _scintillaKeyID; + int _menuCmdID; + vector _keyCombos; + size_t size; + void applyToCurrentIndex(); + void validateDialog(); + void showCurrentSettings(); + void updateListItem(int index); +protected : + BOOL CALLBACK run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam); +}; + + +class Window; +class ScintillaEditView; + +struct recordedMacroStep { + enum MacroTypeIndex {mtUseLParameter, mtUseSParameter, mtMenuCommand}; + + int message; + long wParameter; + long lParameter; + generic_string sParameter; + MacroTypeIndex MacroType; + + recordedMacroStep(int iMessage, long wParam, long lParam); + recordedMacroStep(int iCommandID) : message(0), wParameter(iCommandID), lParameter(0), MacroType(mtMenuCommand) {}; + + recordedMacroStep(int type, int iMessage, long wParam, long lParam, const TCHAR *sParam) + : message(iMessage), wParameter(wParam), lParameter(lParam), MacroType(MacroTypeIndex(type)){ + sParameter = *reinterpret_cast(sParam); + }; + bool isValid() const { + return true; + }; + + void PlayBack(Window* pNotepad, ScintillaEditView *pEditView); +}; + +typedef vector Macro; + +class MacroShortcut : public CommandShortcut { +friend class NppParameters; +public: + MacroShortcut(Shortcut sc, Macro macro, int id) : CommandShortcut(sc, id), _macro(macro) {_canModifyName = true;}; + Macro & getMacro() {return _macro;}; +private: + Macro _macro; +}; + + +class UserCommand : public CommandShortcut { +friend class NppParameters; +public: + UserCommand(Shortcut sc, const TCHAR *cmd, int id) : CommandShortcut(sc, id), _cmd(cmd) {_canModifyName = true;}; + const TCHAR* getCmd() const {return _cmd.c_str();}; +private: + generic_string _cmd; +}; + +class PluginCmdShortcut : public CommandShortcut { +//friend class NppParameters; +public: + PluginCmdShortcut(Shortcut sc, int id, const TCHAR *moduleName, unsigned short internalID) :\ + CommandShortcut(sc, id), _id(id), _internalID(internalID) { + lstrcpy(_moduleName, moduleName); + }; + bool isValid() const { + if (!Shortcut::isValid()) + return false; + if ((!_moduleName[0]) || (_internalID == -1)) + return false; + return true; + } + const TCHAR * getModuleName() const {return _moduleName;}; + int getInternalID() const {return _internalID;}; + unsigned long getID() const {return _id;}; + +private : + unsigned long _id; + TCHAR _moduleName[nameLenMax]; + int _internalID; +}; + +class Accelerator { //Handles accelerator keys for Notepad++ menu, including custom commands +friend class ShortcutMapper; +public: + Accelerator():_hAccelMenu(NULL), _hMenuParent(NULL), _hAccTable(NULL), _pAccelArray(NULL), _nbAccelItems(0){}; + ~Accelerator(){ + if (_hAccTable) + ::DestroyAcceleratorTable(_hAccTable); + if (_pAccelArray) + delete [] _pAccelArray; + }; + void init(HMENU hMenu, HWND menuParent) { + _hAccelMenu = hMenu; + _hMenuParent = menuParent; + updateShortcuts(); + }; + HACCEL getAccTable() const {return _hAccTable;}; + + void updateShortcuts(); + void updateFullMenu(); + +private: + HMENU _hAccelMenu; + HWND _hMenuParent; + HACCEL _hAccTable; + ACCEL *_pAccelArray; + int _nbAccelItems; + + void reNew() { + if(_hAccTable) + ::DestroyAcceleratorTable(_hAccTable); + _hAccTable = ::CreateAcceleratorTable(_pAccelArray, _nbAccelItems); + }; + void updateMenuItemByCommand(CommandShortcut csc); +}; + +class ScintillaAccelerator { //Handles accelerator keys for scintilla +public: + ScintillaAccelerator() : _nrScintillas(0) {}; + void init(vector * vScintillas, HMENU hMenu, HWND menuParent); + void updateKeys(); + void updateKey(ScintillaKeyMap skmOld, ScintillaKeyMap skm); +private: + HMENU _hAccelMenu; + HWND _hMenuParent; + vector _vScintillas; + int _nrScintillas; + + void updateMenuItemByID(ScintillaKeyMap skm, int id); +}; + +#endif //SHORTCUTS_H diff --git a/PowerEditor/src/WinControls/shortcut/shortcut.rc b/PowerEditor/src/WinControls/shortcut/shortcut.rc new file mode 100644 index 00000000..65f0eef8 --- /dev/null +++ b/PowerEditor/src/WinControls/shortcut/shortcut.rc @@ -0,0 +1,79 @@ +/* +this file is part of notepad++ +Copyright (C)2003 Don HO < donho@altern.org > + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include +#include "shortcutRc.h" + +#ifndef IDC_STATIC +#define IDC_STATIC -1 +#endif + +IDD_SHORTCUT_DLG DIALOGEX 0, 0, 180, 102 +STYLE DS_SETFONT | /*DS_MODALFRAME |*/ DS_FIXEDSYS | WS_POPUP | WS_CAPTION | + WS_SYSMENU +EXSTYLE WS_EX_TOOLWINDOW +CAPTION "Shortcut" +FONT 8, TEXT("MS Shell Dlg"), 400, 0, 0x1 +BEGIN + CONTROL "CTRL",IDC_CTRL_CHECK,"Button",BS_AUTOCHECKBOX | + WS_TABSTOP,12,30,33,10 + CONTROL "ALT",IDC_ALT_CHECK,"Button",BS_AUTOCHECKBOX | + WS_TABSTOP,12,51,28,10 + CONTROL "SHIFT",IDC_SHIFT_CHECK,"Button",BS_AUTOCHECKBOX | + WS_TABSTOP,57,42,35,10 + COMBOBOX IDC_KEY_COMBO,110,40,64,270,CBS_DROPDOWNLIST | + WS_VSCROLL | WS_TABSTOP + PUSHBUTTON "OK",IDOK,32,74,50,14 + PUSHBUTTON "Cancel",IDCANCEL,103,73,50,14 + LTEXT "+",IDC_STATIC,45,42,8,8 + LTEXT "+",IDC_STATIC,96,42,8,8 + EDITTEXT IDC_NAME_EDIT,56,9,93,14,ES_AUTOHSCROLL + LTEXT "Name :",IDC_NAME_STATIC,15,12,34,8,0,WS_EX_RIGHT + LTEXT "This will disable the accelerator!",IDC_WARNING_STATIC, + 6,90,170,8 +END + +IDD_SHORTCUTSCINT_DLG DIALOGEX 0, 0, 286, 114 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU +EXSTYLE WS_EX_TOOLWINDOW +CAPTION "Shortcut" +FONT 8, TEXT("MS Shell Dlg"), 400, 0, 0x1 +BEGIN + CONTROL "CTRL",IDC_CTRL_CHECK,"Button",BS_AUTOCHECKBOX | + WS_TABSTOP,114,27,33,10 + CONTROL "ALT",IDC_ALT_CHECK,"Button",BS_AUTOCHECKBOX | + WS_TABSTOP,114,48,28,10 + CONTROL "SHIFT",IDC_SHIFT_CHECK,"Button",BS_AUTOCHECKBOX | + WS_TABSTOP,159,39,35,10 + COMBOBOX IDC_KEY_COMBO,212,37,64,270,CBS_DROPDOWNLIST | + WS_VSCROLL | WS_TABSTOP + PUSHBUTTON "OK",IDOK,144,78,48,14 + PUSHBUTTON "Cancel",IDCANCEL,210,78,48,14 + LTEXT "+",IDC_STATIC,147,39,8,8 + LTEXT "+",IDC_STATIC,198,39,8,8 + EDITTEXT IDC_NAME_EDIT,158,6,93,14,ES_AUTOHSCROLL | ES_READONLY + LTEXT "Name :",IDC_NAME_STATIC,117,9,34,8,0,WS_EX_RIGHT + LTEXT "This will remove the accelerator!",IDC_WARNING_STATIC, + 120,98,138,8 + LISTBOX IDC_LIST_KEYS,6,6,90,72,LBS_NOINTEGRALHEIGHT | + WS_VSCROLL | WS_TABSTOP + PUSHBUTTON "Add",IDC_BUTTON_ADD,6,84,42,14 + PUSHBUTTON "Remove",IDC_BUTTON_RMVE,56,84,40,14 + PUSHBUTTON "Apply",IDC_BUTTON_APPLY,210,60,48,14 +END diff --git a/PowerEditor/src/WinControls/shortcut/shortcutRc.h b/PowerEditor/src/WinControls/shortcut/shortcutRc.h new file mode 100644 index 00000000..0f244af0 --- /dev/null +++ b/PowerEditor/src/WinControls/shortcut/shortcutRc.h @@ -0,0 +1,36 @@ +/* +this file is part of notepad++ +Copyright (C)2003 Don HO < donho@altern.org > + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef IDD_SHORTCUT_DLG + +#define IDD_SHORTCUT_DLG 5000 +#define IDD_SHORTCUTSCINT_DLG 5001 + +#define IDC_CTRL_CHECK (IDD_SHORTCUT_DLG + 1) +#define IDC_ALT_CHECK (IDD_SHORTCUT_DLG + 2) +#define IDC_SHIFT_CHECK (IDD_SHORTCUT_DLG + 3) +#define IDC_KEY_COMBO (IDD_SHORTCUT_DLG + 4) +#define IDC_NAME_EDIT (IDD_SHORTCUT_DLG + 5) +#define IDC_NAME_STATIC (IDD_SHORTCUT_DLG + 6) +#define IDC_WARNING_STATIC (IDD_SHORTCUT_DLG + 7) +#define IDC_BUTTON_ADD (IDD_SHORTCUT_DLG + 8) +#define IDC_BUTTON_RMVE (IDD_SHORTCUT_DLG + 9) +#define IDC_BUTTON_APPLY (IDD_SHORTCUT_DLG + 10) +#define IDC_LIST_KEYS (IDD_SHORTCUT_DLG + 11) +#endif //IDD_SHORTCUT_DLG diff --git a/PowerEditor/src/config.model.xml b/PowerEditor/src/config.model.xml new file mode 100644 index 00000000..34668133 --- /dev/null +++ b/PowerEditor/src/config.model.xml @@ -0,0 +1,82 @@ + + + + + standard + + show + + + + vertical + + hide + + + + + + + + yes + no + no + yes + + + + + + + + yes + no + + no + yes + yes + 0 + + + + + + + diff --git a/PowerEditor/src/contextMenu.xml b/PowerEditor/src/contextMenu.xml new file mode 100644 index 00000000..19b66b21 --- /dev/null +++ b/PowerEditor/src/contextMenu.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/PowerEditor/src/cursors/drag.cur b/PowerEditor/src/cursors/drag.cur new file mode 100644 index 00000000..1258fb79 Binary files /dev/null and b/PowerEditor/src/cursors/drag.cur differ diff --git a/PowerEditor/src/cursors/drag_interdit.cur b/PowerEditor/src/cursors/drag_interdit.cur new file mode 100644 index 00000000..f4ca240a Binary files /dev/null and b/PowerEditor/src/cursors/drag_interdit.cur differ diff --git a/PowerEditor/src/cursors/drag_out.cur b/PowerEditor/src/cursors/drag_out.cur new file mode 100644 index 00000000..21103204 Binary files /dev/null and b/PowerEditor/src/cursors/drag_out.cur differ diff --git a/PowerEditor/src/cursors/drag_plus.cur b/PowerEditor/src/cursors/drag_plus.cur new file mode 100644 index 00000000..545d771d Binary files /dev/null and b/PowerEditor/src/cursors/drag_plus.cur differ diff --git a/PowerEditor/src/font/LINEDRAW.TTF b/PowerEditor/src/font/LINEDRAW.TTF new file mode 100644 index 00000000..5f57f844 Binary files /dev/null and b/PowerEditor/src/font/LINEDRAW.TTF differ diff --git a/PowerEditor/src/icons/allChars_off.ico b/PowerEditor/src/icons/allChars_off.ico new file mode 100644 index 00000000..425a9adf Binary files /dev/null and b/PowerEditor/src/icons/allChars_off.ico differ diff --git a/PowerEditor/src/icons/allChars_on.ico b/PowerEditor/src/icons/allChars_on.ico new file mode 100644 index 00000000..7d627ea2 Binary files /dev/null and b/PowerEditor/src/icons/allChars_on.ico differ diff --git a/PowerEditor/src/icons/closeAll.bmp b/PowerEditor/src/icons/closeAll.bmp new file mode 100644 index 00000000..ca23d93f Binary files /dev/null and b/PowerEditor/src/icons/closeAll.bmp differ diff --git a/PowerEditor/src/icons/closeFile.bmp b/PowerEditor/src/icons/closeFile.bmp new file mode 100644 index 00000000..e35aef83 Binary files /dev/null and b/PowerEditor/src/icons/closeFile.bmp differ diff --git a/PowerEditor/src/icons/closeTabButton.bmp b/PowerEditor/src/icons/closeTabButton.bmp new file mode 100644 index 00000000..f673c0d4 Binary files /dev/null and b/PowerEditor/src/icons/closeTabButton.bmp differ diff --git a/PowerEditor/src/icons/closeTabButton_hover.bmp b/PowerEditor/src/icons/closeTabButton_hover.bmp new file mode 100644 index 00000000..44490fd3 Binary files /dev/null and b/PowerEditor/src/icons/closeTabButton_hover.bmp differ diff --git a/PowerEditor/src/icons/closeTabButton_inact.bmp b/PowerEditor/src/icons/closeTabButton_inact.bmp new file mode 100644 index 00000000..211027e7 Binary files /dev/null and b/PowerEditor/src/icons/closeTabButton_inact.bmp differ diff --git a/PowerEditor/src/icons/closeTabButton_push.bmp b/PowerEditor/src/icons/closeTabButton_push.bmp new file mode 100644 index 00000000..e136d11d Binary files /dev/null and b/PowerEditor/src/icons/closeTabButton_push.bmp differ diff --git a/PowerEditor/src/icons/copy.bmp b/PowerEditor/src/icons/copy.bmp new file mode 100644 index 00000000..3ca261d3 Binary files /dev/null and b/PowerEditor/src/icons/copy.bmp differ diff --git a/PowerEditor/src/icons/cut.bmp b/PowerEditor/src/icons/cut.bmp new file mode 100644 index 00000000..e0b34d8d Binary files /dev/null and b/PowerEditor/src/icons/cut.bmp differ diff --git a/PowerEditor/src/icons/cut_dis.ico b/PowerEditor/src/icons/cut_dis.ico new file mode 100644 index 00000000..b7269815 Binary files /dev/null and b/PowerEditor/src/icons/cut_dis.ico differ diff --git a/PowerEditor/src/icons/cut_off.ico b/PowerEditor/src/icons/cut_off.ico new file mode 100644 index 00000000..b0ee93eb Binary files /dev/null and b/PowerEditor/src/icons/cut_off.ico differ diff --git a/PowerEditor/src/icons/cut_on.ico b/PowerEditor/src/icons/cut_on.ico new file mode 100644 index 00000000..0d184437 Binary files /dev/null and b/PowerEditor/src/icons/cut_on.ico differ diff --git a/PowerEditor/src/icons/delete.ico b/PowerEditor/src/icons/delete.ico new file mode 100644 index 00000000..760a5c0f Binary files /dev/null and b/PowerEditor/src/icons/delete.ico differ diff --git a/PowerEditor/src/icons/dupli_dis.ico b/PowerEditor/src/icons/dupli_dis.ico new file mode 100644 index 00000000..38b4cf6c Binary files /dev/null and b/PowerEditor/src/icons/dupli_dis.ico differ diff --git a/PowerEditor/src/icons/dupli_off.ico b/PowerEditor/src/icons/dupli_off.ico new file mode 100644 index 00000000..f7a5a70e Binary files /dev/null and b/PowerEditor/src/icons/dupli_off.ico differ diff --git a/PowerEditor/src/icons/dupli_on.ico b/PowerEditor/src/icons/dupli_on.ico new file mode 100644 index 00000000..b4121cac Binary files /dev/null and b/PowerEditor/src/icons/dupli_on.ico differ diff --git a/PowerEditor/src/icons/find.bmp b/PowerEditor/src/icons/find.bmp new file mode 100644 index 00000000..cf295f5d Binary files /dev/null and b/PowerEditor/src/icons/find.bmp differ diff --git a/PowerEditor/src/icons/findReplace.bmp b/PowerEditor/src/icons/findReplace.bmp new file mode 100644 index 00000000..88ec37e7 Binary files /dev/null and b/PowerEditor/src/icons/findReplace.bmp differ diff --git a/PowerEditor/src/icons/findResult.ico b/PowerEditor/src/icons/findResult.ico new file mode 100644 index 00000000..15b7a9dc Binary files /dev/null and b/PowerEditor/src/icons/findResult.ico differ diff --git a/PowerEditor/src/icons/find_off.ico b/PowerEditor/src/icons/find_off.ico new file mode 100644 index 00000000..0e3555e1 Binary files /dev/null and b/PowerEditor/src/icons/find_off.ico differ diff --git a/PowerEditor/src/icons/find_on.ico b/PowerEditor/src/icons/find_on.ico new file mode 100644 index 00000000..d33b4c15 Binary files /dev/null and b/PowerEditor/src/icons/find_on.ico differ diff --git a/PowerEditor/src/icons/findrep_off.ico b/PowerEditor/src/icons/findrep_off.ico new file mode 100644 index 00000000..951219d9 Binary files /dev/null and b/PowerEditor/src/icons/findrep_off.ico differ diff --git a/PowerEditor/src/icons/findrep_on.ico b/PowerEditor/src/icons/findrep_on.ico new file mode 100644 index 00000000..60190671 Binary files /dev/null and b/PowerEditor/src/icons/findrep_on.ico differ diff --git a/PowerEditor/src/icons/imprim_off.ico b/PowerEditor/src/icons/imprim_off.ico new file mode 100644 index 00000000..b5220847 Binary files /dev/null and b/PowerEditor/src/icons/imprim_off.ico differ diff --git a/PowerEditor/src/icons/imprim_on.ico b/PowerEditor/src/icons/imprim_on.ico new file mode 100644 index 00000000..d109437c Binary files /dev/null and b/PowerEditor/src/icons/imprim_on.ico differ diff --git a/PowerEditor/src/icons/indentGuide.bmp b/PowerEditor/src/icons/indentGuide.bmp new file mode 100644 index 00000000..a12342d1 Binary files /dev/null and b/PowerEditor/src/icons/indentGuide.bmp differ diff --git a/PowerEditor/src/icons/indentGuide_off.ico b/PowerEditor/src/icons/indentGuide_off.ico new file mode 100644 index 00000000..a7e585a6 Binary files /dev/null and b/PowerEditor/src/icons/indentGuide_off.ico differ diff --git a/PowerEditor/src/icons/indentGuide_on.ico b/PowerEditor/src/icons/indentGuide_on.ico new file mode 100644 index 00000000..d87f8139 Binary files /dev/null and b/PowerEditor/src/icons/indentGuide_on.ico differ diff --git a/PowerEditor/src/icons/invisibleChar.bmp b/PowerEditor/src/icons/invisibleChar.bmp new file mode 100644 index 00000000..64f5fac5 Binary files /dev/null and b/PowerEditor/src/icons/invisibleChar.bmp differ diff --git a/PowerEditor/src/icons/newFile.bmp b/PowerEditor/src/icons/newFile.bmp new file mode 100644 index 00000000..1b9ce9ff Binary files /dev/null and b/PowerEditor/src/icons/newFile.bmp differ diff --git a/PowerEditor/src/icons/new_off.ico b/PowerEditor/src/icons/new_off.ico new file mode 100644 index 00000000..67c29451 Binary files /dev/null and b/PowerEditor/src/icons/new_off.ico differ diff --git a/PowerEditor/src/icons/new_on.ico b/PowerEditor/src/icons/new_on.ico new file mode 100644 index 00000000..0c4fd808 Binary files /dev/null and b/PowerEditor/src/icons/new_on.ico differ diff --git a/PowerEditor/src/icons/npp.ico b/PowerEditor/src/icons/npp.ico new file mode 100644 index 00000000..bd272c7e Binary files /dev/null and b/PowerEditor/src/icons/npp.ico differ diff --git a/PowerEditor/src/icons/openFile.bmp b/PowerEditor/src/icons/openFile.bmp new file mode 100644 index 00000000..4607c7a3 Binary files /dev/null and b/PowerEditor/src/icons/openFile.bmp differ diff --git a/PowerEditor/src/icons/open_off.ico b/PowerEditor/src/icons/open_off.ico new file mode 100644 index 00000000..39f1938e Binary files /dev/null and b/PowerEditor/src/icons/open_off.ico differ diff --git a/PowerEditor/src/icons/open_on.ico b/PowerEditor/src/icons/open_on.ico new file mode 100644 index 00000000..44d5a342 Binary files /dev/null and b/PowerEditor/src/icons/open_on.ico differ diff --git a/PowerEditor/src/icons/paste.bmp b/PowerEditor/src/icons/paste.bmp new file mode 100644 index 00000000..88d79d87 Binary files /dev/null and b/PowerEditor/src/icons/paste.bmp differ diff --git a/PowerEditor/src/icons/paste_dis.ico b/PowerEditor/src/icons/paste_dis.ico new file mode 100644 index 00000000..16bcbf5d Binary files /dev/null and b/PowerEditor/src/icons/paste_dis.ico differ diff --git a/PowerEditor/src/icons/paste_off.ico b/PowerEditor/src/icons/paste_off.ico new file mode 100644 index 00000000..3122eadd Binary files /dev/null and b/PowerEditor/src/icons/paste_off.ico differ diff --git a/PowerEditor/src/icons/paste_on.ico b/PowerEditor/src/icons/paste_on.ico new file mode 100644 index 00000000..97475080 Binary files /dev/null and b/PowerEditor/src/icons/paste_on.ico differ diff --git a/PowerEditor/src/icons/playRecord.bmp b/PowerEditor/src/icons/playRecord.bmp new file mode 100644 index 00000000..49350957 Binary files /dev/null and b/PowerEditor/src/icons/playRecord.bmp differ diff --git a/PowerEditor/src/icons/playRecord_m.bmp b/PowerEditor/src/icons/playRecord_m.bmp new file mode 100644 index 00000000..bfb62cdd Binary files /dev/null and b/PowerEditor/src/icons/playRecord_m.bmp differ diff --git a/PowerEditor/src/icons/playrecord_dis.ico b/PowerEditor/src/icons/playrecord_dis.ico new file mode 100644 index 00000000..c16b60ff Binary files /dev/null and b/PowerEditor/src/icons/playrecord_dis.ico differ diff --git a/PowerEditor/src/icons/playrecord_m_dis.ico b/PowerEditor/src/icons/playrecord_m_dis.ico new file mode 100644 index 00000000..bc02bb8b Binary files /dev/null and b/PowerEditor/src/icons/playrecord_m_dis.ico differ diff --git a/PowerEditor/src/icons/playrecord_m_off.ico b/PowerEditor/src/icons/playrecord_m_off.ico new file mode 100644 index 00000000..3d2f464c Binary files /dev/null and b/PowerEditor/src/icons/playrecord_m_off.ico differ diff --git a/PowerEditor/src/icons/playrecord_m_on.ico b/PowerEditor/src/icons/playrecord_m_on.ico new file mode 100644 index 00000000..78a92116 Binary files /dev/null and b/PowerEditor/src/icons/playrecord_m_on.ico differ diff --git a/PowerEditor/src/icons/playrecord_off.ico b/PowerEditor/src/icons/playrecord_off.ico new file mode 100644 index 00000000..494a980b Binary files /dev/null and b/PowerEditor/src/icons/playrecord_off.ico differ diff --git a/PowerEditor/src/icons/playrecord_on.ico b/PowerEditor/src/icons/playrecord_on.ico new file mode 100644 index 00000000..3a5eb58a Binary files /dev/null and b/PowerEditor/src/icons/playrecord_on.ico differ diff --git a/PowerEditor/src/icons/print.bmp b/PowerEditor/src/icons/print.bmp new file mode 100644 index 00000000..488abf83 Binary files /dev/null and b/PowerEditor/src/icons/print.bmp differ diff --git a/PowerEditor/src/icons/readonly.ico b/PowerEditor/src/icons/readonly.ico new file mode 100644 index 00000000..b545cbc8 Binary files /dev/null and b/PowerEditor/src/icons/readonly.ico differ diff --git a/PowerEditor/src/icons/readonly.ico.old b/PowerEditor/src/icons/readonly.ico.old new file mode 100644 index 00000000..001f9ceb Binary files /dev/null and b/PowerEditor/src/icons/readonly.ico.old differ diff --git a/PowerEditor/src/icons/redo.bmp b/PowerEditor/src/icons/redo.bmp new file mode 100644 index 00000000..454e6741 Binary files /dev/null and b/PowerEditor/src/icons/redo.bmp differ diff --git a/PowerEditor/src/icons/redo_dis.ico b/PowerEditor/src/icons/redo_dis.ico new file mode 100644 index 00000000..2c3ad723 Binary files /dev/null and b/PowerEditor/src/icons/redo_dis.ico differ diff --git a/PowerEditor/src/icons/redo_off.ico b/PowerEditor/src/icons/redo_off.ico new file mode 100644 index 00000000..b8776b47 Binary files /dev/null and b/PowerEditor/src/icons/redo_off.ico differ diff --git a/PowerEditor/src/icons/redo_on.ico b/PowerEditor/src/icons/redo_on.ico new file mode 100644 index 00000000..db7c85ab Binary files /dev/null and b/PowerEditor/src/icons/redo_on.ico differ diff --git a/PowerEditor/src/icons/saveAll.bmp b/PowerEditor/src/icons/saveAll.bmp new file mode 100644 index 00000000..7437e9f0 Binary files /dev/null and b/PowerEditor/src/icons/saveAll.bmp differ diff --git a/PowerEditor/src/icons/saveFile.bmp b/PowerEditor/src/icons/saveFile.bmp new file mode 100644 index 00000000..14737d39 Binary files /dev/null and b/PowerEditor/src/icons/saveFile.bmp differ diff --git a/PowerEditor/src/icons/saveRecord.bmp b/PowerEditor/src/icons/saveRecord.bmp new file mode 100644 index 00000000..77707f4c Binary files /dev/null and b/PowerEditor/src/icons/saveRecord.bmp differ diff --git a/PowerEditor/src/icons/save_dis.ico b/PowerEditor/src/icons/save_dis.ico new file mode 100644 index 00000000..27253573 Binary files /dev/null and b/PowerEditor/src/icons/save_dis.ico differ diff --git a/PowerEditor/src/icons/save_off.ico b/PowerEditor/src/icons/save_off.ico new file mode 100644 index 00000000..d2f4fe9b Binary files /dev/null and b/PowerEditor/src/icons/save_off.ico differ diff --git a/PowerEditor/src/icons/save_on.ico b/PowerEditor/src/icons/save_on.ico new file mode 100644 index 00000000..79a8e55f Binary files /dev/null and b/PowerEditor/src/icons/save_on.ico differ diff --git a/PowerEditor/src/icons/saveall_dis.ico b/PowerEditor/src/icons/saveall_dis.ico new file mode 100644 index 00000000..31b5ff15 Binary files /dev/null and b/PowerEditor/src/icons/saveall_dis.ico differ diff --git a/PowerEditor/src/icons/saveall_off.ico b/PowerEditor/src/icons/saveall_off.ico new file mode 100644 index 00000000..37b78b03 Binary files /dev/null and b/PowerEditor/src/icons/saveall_off.ico differ diff --git a/PowerEditor/src/icons/saveall_on.ico b/PowerEditor/src/icons/saveall_on.ico new file mode 100644 index 00000000..66543c50 Binary files /dev/null and b/PowerEditor/src/icons/saveall_on.ico differ diff --git a/PowerEditor/src/icons/saved.ico b/PowerEditor/src/icons/saved.ico new file mode 100644 index 00000000..7c7d16c9 Binary files /dev/null and b/PowerEditor/src/icons/saved.ico differ diff --git a/PowerEditor/src/icons/saved.ico.old b/PowerEditor/src/icons/saved.ico.old new file mode 100644 index 00000000..a8c2ab30 Binary files /dev/null and b/PowerEditor/src/icons/saved.ico.old differ diff --git a/PowerEditor/src/icons/saverecord_dis.ico b/PowerEditor/src/icons/saverecord_dis.ico new file mode 100644 index 00000000..e6fc91d7 Binary files /dev/null and b/PowerEditor/src/icons/saverecord_dis.ico differ diff --git a/PowerEditor/src/icons/saverecord_off.ico b/PowerEditor/src/icons/saverecord_off.ico new file mode 100644 index 00000000..847e9a8e Binary files /dev/null and b/PowerEditor/src/icons/saverecord_off.ico differ diff --git a/PowerEditor/src/icons/saverecord_on.ico b/PowerEditor/src/icons/saverecord_on.ico new file mode 100644 index 00000000..3556f501 Binary files /dev/null and b/PowerEditor/src/icons/saverecord_on.ico differ diff --git a/PowerEditor/src/icons/showPannel.bmp b/PowerEditor/src/icons/showPannel.bmp new file mode 100644 index 00000000..f0d57fcc Binary files /dev/null and b/PowerEditor/src/icons/showPannel.bmp differ diff --git a/PowerEditor/src/icons/startRecord.bmp b/PowerEditor/src/icons/startRecord.bmp new file mode 100644 index 00000000..a0381d71 Binary files /dev/null and b/PowerEditor/src/icons/startRecord.bmp differ diff --git a/PowerEditor/src/icons/startrecord_dis.ico b/PowerEditor/src/icons/startrecord_dis.ico new file mode 100644 index 00000000..0feb7145 Binary files /dev/null and b/PowerEditor/src/icons/startrecord_dis.ico differ diff --git a/PowerEditor/src/icons/startrecord_off.ico b/PowerEditor/src/icons/startrecord_off.ico new file mode 100644 index 00000000..6a804db4 Binary files /dev/null and b/PowerEditor/src/icons/startrecord_off.ico differ diff --git a/PowerEditor/src/icons/startrecord_on.ico b/PowerEditor/src/icons/startrecord_on.ico new file mode 100644 index 00000000..dc3c5163 Binary files /dev/null and b/PowerEditor/src/icons/startrecord_on.ico differ diff --git a/PowerEditor/src/icons/stopRecord.bmp b/PowerEditor/src/icons/stopRecord.bmp new file mode 100644 index 00000000..bd9de13e Binary files /dev/null and b/PowerEditor/src/icons/stopRecord.bmp differ diff --git a/PowerEditor/src/icons/stoprecord_dis.ico b/PowerEditor/src/icons/stoprecord_dis.ico new file mode 100644 index 00000000..7e5478b0 Binary files /dev/null and b/PowerEditor/src/icons/stoprecord_dis.ico differ diff --git a/PowerEditor/src/icons/stoprecord_off.ico b/PowerEditor/src/icons/stoprecord_off.ico new file mode 100644 index 00000000..3116a3af Binary files /dev/null and b/PowerEditor/src/icons/stoprecord_off.ico differ diff --git a/PowerEditor/src/icons/stoprecord_on.ico b/PowerEditor/src/icons/stoprecord_on.ico new file mode 100644 index 00000000..c6278ba9 Binary files /dev/null and b/PowerEditor/src/icons/stoprecord_on.ico differ diff --git a/PowerEditor/src/icons/supp_off.ico b/PowerEditor/src/icons/supp_off.ico new file mode 100644 index 00000000..9b977e08 Binary files /dev/null and b/PowerEditor/src/icons/supp_off.ico differ diff --git a/PowerEditor/src/icons/supp_on.ico b/PowerEditor/src/icons/supp_on.ico new file mode 100644 index 00000000..658ba716 Binary files /dev/null and b/PowerEditor/src/icons/supp_on.ico differ diff --git a/PowerEditor/src/icons/suppall_off.ico b/PowerEditor/src/icons/suppall_off.ico new file mode 100644 index 00000000..a3649742 Binary files /dev/null and b/PowerEditor/src/icons/suppall_off.ico differ diff --git a/PowerEditor/src/icons/suppall_on.ico b/PowerEditor/src/icons/suppall_on.ico new file mode 100644 index 00000000..d8165160 Binary files /dev/null and b/PowerEditor/src/icons/suppall_on.ico differ diff --git a/PowerEditor/src/icons/syncH.bmp b/PowerEditor/src/icons/syncH.bmp new file mode 100644 index 00000000..ba588b88 Binary files /dev/null and b/PowerEditor/src/icons/syncH.bmp differ diff --git a/PowerEditor/src/icons/syncH_dis.ico b/PowerEditor/src/icons/syncH_dis.ico new file mode 100644 index 00000000..a6aabe2b Binary files /dev/null and b/PowerEditor/src/icons/syncH_dis.ico differ diff --git a/PowerEditor/src/icons/syncH_off.ico b/PowerEditor/src/icons/syncH_off.ico new file mode 100644 index 00000000..e1bc73d4 Binary files /dev/null and b/PowerEditor/src/icons/syncH_off.ico differ diff --git a/PowerEditor/src/icons/syncH_on.ico b/PowerEditor/src/icons/syncH_on.ico new file mode 100644 index 00000000..f9a50dd4 Binary files /dev/null and b/PowerEditor/src/icons/syncH_on.ico differ diff --git a/PowerEditor/src/icons/syncV.bmp b/PowerEditor/src/icons/syncV.bmp new file mode 100644 index 00000000..81533af0 Binary files /dev/null and b/PowerEditor/src/icons/syncV.bmp differ diff --git a/PowerEditor/src/icons/syncV_dis.ico b/PowerEditor/src/icons/syncV_dis.ico new file mode 100644 index 00000000..cdbab9ad Binary files /dev/null and b/PowerEditor/src/icons/syncV_dis.ico differ diff --git a/PowerEditor/src/icons/syncV_off.ico b/PowerEditor/src/icons/syncV_off.ico new file mode 100644 index 00000000..693b28c8 Binary files /dev/null and b/PowerEditor/src/icons/syncV_off.ico differ diff --git a/PowerEditor/src/icons/syncV_on.ico b/PowerEditor/src/icons/syncV_on.ico new file mode 100644 index 00000000..c457d602 Binary files /dev/null and b/PowerEditor/src/icons/syncV_on.ico differ diff --git a/PowerEditor/src/icons/undo.bmp b/PowerEditor/src/icons/undo.bmp new file mode 100644 index 00000000..3ed55cec Binary files /dev/null and b/PowerEditor/src/icons/undo.bmp differ diff --git a/PowerEditor/src/icons/undo_dis.ico b/PowerEditor/src/icons/undo_dis.ico new file mode 100644 index 00000000..53524439 Binary files /dev/null and b/PowerEditor/src/icons/undo_dis.ico differ diff --git a/PowerEditor/src/icons/undo_off.ico b/PowerEditor/src/icons/undo_off.ico new file mode 100644 index 00000000..ffdbe854 Binary files /dev/null and b/PowerEditor/src/icons/undo_off.ico differ diff --git a/PowerEditor/src/icons/undo_on.ico b/PowerEditor/src/icons/undo_on.ico new file mode 100644 index 00000000..832c8ffb Binary files /dev/null and b/PowerEditor/src/icons/undo_on.ico differ diff --git a/PowerEditor/src/icons/unsaved.ico b/PowerEditor/src/icons/unsaved.ico new file mode 100644 index 00000000..919f73ce Binary files /dev/null and b/PowerEditor/src/icons/unsaved.ico differ diff --git a/PowerEditor/src/icons/unsaved.ico.old b/PowerEditor/src/icons/unsaved.ico.old new file mode 100644 index 00000000..923cadec Binary files /dev/null and b/PowerEditor/src/icons/unsaved.ico.old differ diff --git a/PowerEditor/src/icons/userDefineDlg_off.ico b/PowerEditor/src/icons/userDefineDlg_off.ico new file mode 100644 index 00000000..c1bc22d6 Binary files /dev/null and b/PowerEditor/src/icons/userDefineDlg_off.ico differ diff --git a/PowerEditor/src/icons/userDefineDlg_on.ico b/PowerEditor/src/icons/userDefineDlg_on.ico new file mode 100644 index 00000000..ce653b93 Binary files /dev/null and b/PowerEditor/src/icons/userDefineDlg_on.ico differ diff --git a/PowerEditor/src/icons/wrap.bmp b/PowerEditor/src/icons/wrap.bmp new file mode 100644 index 00000000..adc31781 Binary files /dev/null and b/PowerEditor/src/icons/wrap.bmp differ diff --git a/PowerEditor/src/icons/wrap_dis.ico b/PowerEditor/src/icons/wrap_dis.ico new file mode 100644 index 00000000..972af962 Binary files /dev/null and b/PowerEditor/src/icons/wrap_dis.ico differ diff --git a/PowerEditor/src/icons/wrap_off.ico b/PowerEditor/src/icons/wrap_off.ico new file mode 100644 index 00000000..842dbf25 Binary files /dev/null and b/PowerEditor/src/icons/wrap_off.ico differ diff --git a/PowerEditor/src/icons/wrap_on.ico b/PowerEditor/src/icons/wrap_on.ico new file mode 100644 index 00000000..29535fbc Binary files /dev/null and b/PowerEditor/src/icons/wrap_on.ico differ diff --git a/PowerEditor/src/icons/xxxx.bmp b/PowerEditor/src/icons/xxxx.bmp new file mode 100644 index 00000000..ae0e7e86 Binary files /dev/null and b/PowerEditor/src/icons/xxxx.bmp differ diff --git a/PowerEditor/src/icons/zoomIn.bmp b/PowerEditor/src/icons/zoomIn.bmp new file mode 100644 index 00000000..eb649e19 Binary files /dev/null and b/PowerEditor/src/icons/zoomIn.bmp differ diff --git a/PowerEditor/src/icons/zoomIn_off.ico b/PowerEditor/src/icons/zoomIn_off.ico new file mode 100644 index 00000000..6d05520c Binary files /dev/null and b/PowerEditor/src/icons/zoomIn_off.ico differ diff --git a/PowerEditor/src/icons/zoomIn_on.ico b/PowerEditor/src/icons/zoomIn_on.ico new file mode 100644 index 00000000..66a55141 Binary files /dev/null and b/PowerEditor/src/icons/zoomIn_on.ico differ diff --git a/PowerEditor/src/icons/zoomOut.bmp b/PowerEditor/src/icons/zoomOut.bmp new file mode 100644 index 00000000..6e1107ca Binary files /dev/null and b/PowerEditor/src/icons/zoomOut.bmp differ diff --git a/PowerEditor/src/icons/zoomOut_off.ico b/PowerEditor/src/icons/zoomOut_off.ico new file mode 100644 index 00000000..012b59a7 Binary files /dev/null and b/PowerEditor/src/icons/zoomOut_off.ico differ diff --git a/PowerEditor/src/icons/zoomOut_on.ico b/PowerEditor/src/icons/zoomOut_on.ico new file mode 100644 index 00000000..10207216 Binary files /dev/null and b/PowerEditor/src/icons/zoomOut_on.ico differ diff --git a/PowerEditor/src/keys.h b/PowerEditor/src/keys.h new file mode 100644 index 00000000..d96bd9cc --- /dev/null +++ b/PowerEditor/src/keys.h @@ -0,0 +1,178 @@ +/* +See winuser.h +Altered list to support VK_0-9 and VK_A-Z +*/ + +#define VK_NULL 0x00 + +#define VK_CANCEL 0x03 + +#define VK_BACK 0x08 +#define VK_TAB 0x09 + +#define VK_CLEAR 0x0C +#define VK_RETURN 0x0D + +#define VK_SHIFT 0x10 +#define VK_CONTROL 0x11 +#define VK_MENU 0x12 +#define VK_PAUSE 0x13 +#define VK_CAPITAL 0x14 + +#define VK_KANA 0x15 +#define VK_HANGUL 0x15 +#define VK_JUNJA 0x17 +#define VK_FINAL 0x18 +#define VK_HANJA 0x19 +#define VK_KANJI 0x19 + +#define VK_ESCAPE 0x1B + +#define VK_CONVERT 0x1C +#define VK_NONCONVERT 0x1D +#define VK_ACCEPT 0x1E +#define VK_MODECHANGE 0x1F + +#define VK_SPACE 0x20 +#define VK_PRIOR 0x21 +#define VK_NEXT 0x22 +#define VK_END 0x23 +#define VK_HOME 0x24 +#define VK_LEFT 0x25 +#define VK_UP 0x26 +#define VK_RIGHT 0x27 +#define VK_DOWN 0x28 +#define VK_SELECT 0x29 +#define VK_PRINT 0x2A +#define VK_EXECUTE 0x2B +#define VK_SNAPSHOT 0x2C +#define VK_INSERT 0x2D +#define VK_DELETE 0x2E +#define VK_HELP 0x2F + +#define VK_0 0x30 +#define VK_1 0x31 +#define VK_2 0x32 +#define VK_3 0x33 +#define VK_4 0x34 +#define VK_5 0x35 +#define VK_6 0x36 +#define VK_7 0x37 +#define VK_8 0x38 +#define VK_9 0x39 +#define VK_A 0x41 +#define VK_B 0x42 +#define VK_C 0x43 +#define VK_D 0x44 +#define VK_E 0x45 +#define VK_F 0x46 +#define VK_G 0x47 +#define VK_H 0x48 +#define VK_I 0x49 +#define VK_J 0x4A +#define VK_K 0x4B +#define VK_L 0x4C +#define VK_M 0x4D +#define VK_N 0x4E +#define VK_O 0x4F +#define VK_P 0x50 +#define VK_Q 0x51 +#define VK_R 0x52 +#define VK_S 0x53 +#define VK_T 0x54 +#define VK_U 0x55 +#define VK_V 0x56 +#define VK_W 0x57 +#define VK_X 0x58 +#define VK_Y 0x59 +#define VK_Z 0x5A + +#define VK_LWIN 0x5B +#define VK_RWIN 0x5C +#define VK_APPS 0x5D + + +#define VK_SLEEP 0x5F + +#define VK_NUMPAD0 0x60 +#define VK_NUMPAD1 0x61 +#define VK_NUMPAD2 0x62 +#define VK_NUMPAD3 0x63 +#define VK_NUMPAD4 0x64 +#define VK_NUMPAD5 0x65 +#define VK_NUMPAD6 0x66 +#define VK_NUMPAD7 0x67 +#define VK_NUMPAD8 0x68 +#define VK_NUMPAD9 0x69 +#define VK_MULTIPLY 0x6A +#define VK_ADD 0x6B +#define VK_SEPARATOR 0x6C +#define VK_SUBTRACT 0x6D +#define VK_DECIMAL 0x6E +#define VK_DIVIDE 0x6F +#define VK_F1 0x70 +#define VK_F2 0x71 +#define VK_F3 0x72 +#define VK_F4 0x73 +#define VK_F5 0x74 +#define VK_F6 0x75 +#define VK_F7 0x76 +#define VK_F8 0x77 +#define VK_F9 0x78 +#define VK_F10 0x79 +#define VK_F11 0x7A +#define VK_F12 0x7B +#define VK_F13 0x7C +#define VK_F14 0x7D +#define VK_F15 0x7E +#define VK_F16 0x7F +#define VK_F17 0x80 +#define VK_F18 0x81 +#define VK_F19 0x82 +#define VK_F20 0x83 +#define VK_F21 0x84 +#define VK_F22 0x85 +#define VK_F23 0x86 +#define VK_F24 0x87 + +#define VK_NUMLOCK 0x90 +#define VK_SCROLL 0x91 + +#define VK_OEM_1 0xBA // ';:' for US +#define VK_OEM_PLUS 0xBB // '+' any country +#define VK_OEM_COMMA 0xBC // ',' any country +#define VK_OEM_MINUS 0xBD // '-' any country +#define VK_OEM_PERIOD 0xBE // '.' any country +#define VK_OEM_2 0xBF // '/?' for US +#define VK_OEM_3 0xC0 // '`~' for US + +#define VK_OEM_4 0xDB // '[{' for US +#define VK_OEM_5 0xDC // '\|' for US +#define VK_OEM_6 0xDD // ']}' for US +#define VK_OEM_7 0xDE // ''"' for US +#define VK_OEM_8 0xDF + +#define VK_OEM_102 0xE2 // "<>" or "\|" on RT 102-key kbd. + +#define VK_OEM_RESET 0xE9 +#define VK_OEM_JUMP 0xEA +#define VK_OEM_PA1 0xEB +#define VK_OEM_PA2 0xEC +#define VK_OEM_PA3 0xED +#define VK_OEM_WSCTRL 0xEE +#define VK_OEM_CUSEL 0xEF +#define VK_OEM_ATTN 0xF0 +#define VK_OEM_FINISH 0xF1 +#define VK_OEM_COPY 0xF2 +#define VK_OEM_AUTO 0xF3 +#define VK_OEM_ENLW 0xF4 +#define VK_OEM_BACKTAB 0xF5 +#define VK_ATTN 0xF6 +#define VK_CRSEL 0xF7 +#define VK_EXSEL 0xF8 +#define VK_EREOF 0xF9 +#define VK_PLAY 0xFA +#define VK_ZOOM 0xFB +#define VK_NONAME 0xFC +#define VK_PA1 0xFD +#define VK_OEM_CLEAR 0xFE \ No newline at end of file diff --git a/PowerEditor/src/langs.model.xml b/PowerEditor/src/langs.model.xml new file mode 100644 index 00000000..76ed65b1 --- /dev/null +++ b/PowerEditor/src/langs.model.xml @@ -0,0 +1,209 @@ + + + + + + + + add for lt tellTarget and function ne this break ge new typeof continue gt not var delete if on void do ifFrameLoaded onClipEvent while else in or with eq le return instanceof case default switch + arguments constructor class dynamic false extends implements import interface intrinsic newline null private public super static true undefined Accessibility Arguments Array Boolean Button Camera ContextMenu ContextMenuItem CustomActions Color Date Error Function Key LoadVars LocalConnection Math Microphone Mouse MovieClip MovieClipLoader NetConnection NetStream Number PrintJob Object TextField StyleSheet TextFormat TextSnapshot SharedObject Selection Sound Stage String System XML XMLNode XMLSocket Void abs acos asin atan atan2 ceil cos exp floor log max min pow random round sin sqrt tan onActivity onChanged onClose onConnect onData onDragOut onDragOver onEnterFrame onID3 onKeyDown onKeyUp onKillFocus onLoad onLoadComplete onLoadError onLoadInit onLoadProgress onLoadStart onMouseDown onMouseMove onMouseUp onMouseWheel onPress onRelease onReleaseOutside onResize onRollOut onRollOver onScroller onSelect onSetFocus onSoundComplete onStatus onUnload onUpdate onXML addListener addPage addProperty addRequestHeader allowDomain allowInsecureDomain appendChild apply applyChanges asfunction attachAudio attachMovie attachSound attachVideo beginFill beginGradientFill call ceil charAt charCodeAt clear clearInterval cloneNode close concat connect copy cos createElement createEmptyMovieClip createTextField createTextNode curveTo domain duplicateMovieClip endFill escape eval evaluate exp findText floor fscommand flush fromCharCode get getAscii getBeginIndex getBounds getBytesLoaded getBytesTotal getCaretIndex getCode getCount getDate getDay getDepth getEndIndex getFocus getFontList getFullYear getHours getInstanceAtDepth getLocal getMilliseconds getMinutes getMonth getNewTextFormat getNextHighestDepth getPan getProggress getProperty getRGB getSeconds getSelected getSelectedText getSize getStyle getStyleNames getSWFVersion getText getTextExtent getTextFormat getTextSnapshot getTime getTimer getTimezoneOffset getTransform getURL getUTCDate getUTCDay getUTCFullYear getUTCHours getUTCMilliseconds getUTCMinutes getUTCMonth getUTCSeconds getVersion getVolume getYear globalToLocal gotoAndPlay gotoAndStop hasChildNodes hide hideBuiltInItems hitTest hitTestTextNearPos indexOf insertBefore install isActive isDown isToggled join lastIndexOf lineStyle lineTo list load loadClip loadMovie loadMovieNum loadSound loadVariables loadVariablesNum localToGlobal log mbchr mblength mbord mbsubstring min MMExecute moveTo nextFrame nextScene parseCSS parseFloat parseInt parseXML pause play pop pow prevScene print printAsBitmap printAsBitmapNum printNum push random registerClass removeListener removeMovieClip removeNode removeTextField replaceSel replaceText reverse round seek send sendAndLoad setBufferTime set setDate setFocus setFullYear setGain setHours setInterval setMask setMilliseconds setMinutes setMode setMonth setMotionLevel setNewTextFormat setPan setProperty setQuality setRate setRGB setSeconds setSelectColor setSelected setSelection setSilenceLevel setStyle setTextFormat setTime setTransform setUseEchoSuppression setUTCDate setUTCFullYear setUTCHours setUTCMilliseconds setUTCMinutes setUTCMonth setUTCSeconds setVolume setYear shift show showSettings silenceLevel silenceTimeout sin slice sort sortOn splice split sqrt start startDrag stop stopAllSounds stopDrag substr substring swapDepths tan toggleHighQuality toLowerCase toString toUpperCase trace unescape uninstall unLoadClip unloadMovie unloadMovieNum unshift unwatch updateAfterEvent updateProperties useEchoSuppression valueOf watch endinitclip include initclip __proto__ _accProps _alpha _currentframe _droptarget _focusrect _framesloaded _global _height _highquality _level _lockroot _name _parent _quality _root _rotation _soundbuftime _target _totalframes _url _visible _width _x _xmouse _xscale _y _ymouse _yscale activityLevel align allowDomain allowInsecureDomain attributes autoSize avHardwareDisable background backgroundColor bandwidth blockIndent bold border borderColor bottomScroll bufferLenght bufferTime builtInItems bullet bytesLoaded bytesTotal callee caller capabilities caption childNodes color condenseWhite contentType currentFps customItems data deblocking docTypeDecl duration embedFonts enabled exactSettings firstChild focusEnabled font fps gain globalStyleFormat hasAccessibility hasAudio hasAudioEncoder hasEmbeddedVideo hasMP3 hasPrinting hasScreenBroadcast hasScreenPlayback hasStreamingAudio hasStreamingVideo hasVideoEncoder height hitArea hscroll html htmlText indent index italic instanceof int ignoreWhite isDebugger isDown isFinite italic language lastChild leading leftMargin length loaded localFileReadDisable manufacturer maxChars maxhscroll maxscroll menu message motionLevel motionTimeout mouseWheelEnabled multiline muted name names NaN nextSibling nodeName nodeType nodeValue os parentNode password pixelAspectRatio playerType previousSibling prototype quality rate restrict resolutionX resolutionY rightMargin scaleMode screenColor screenDPI screenResolutionX screenResolutionY scroll selectable separatorBefore showMenu size smoothing status styleSheet tabChildren tabEnabled tabIndex tabStops target targetPath text textColor textHeight textWidth time trackAsMenu type underline url useCodepage useEchoSuppression useHandCursor variable version visible width wordWrap xmlDecl + + + abort abstract accept access aliased all and array at begin body case constant declare delay delta digits do else elsif end entry exception exit for function generic goto if in is limited loop new not null of others out or package pragma private procedure protected raise range record renames requeue return reverse select separate subtype tagged task terminate then type until use when while with + + + aaa aad aam aas adc add and call cbw clc cld cli cmc cmp cmps cmpsb cmpsw cwd daa das dec div esc hlt idiv imul in inc int into iret ja jae jb jbe jc jcxz je jg jge jl jle jmp jna jnae jnb jnbe jnc jne jng jnge jnl jnle jno jnp jns jnz jo jp jpe jpo js jz lahf lds lea les lods lodsb lodsw loop loope loopew loopne loopnew loopnz loopnzw loopw loopz loopzw mov movs movsb movsw mul neg nop not or out pop popf push pushf rcl rcr ret retf retn rol ror sahf sal sar sbb scas scasb scasw shl shr stc std sti stos stosb stosw sub test wait xchg xlat xlatb xor bound enter ins insb insw leave outs outsb outsw popa pusha pushw arpl lar lsl sgdt sidt sldt smsw str verr verw clts lgdt lidt lldt lmsw ltr bsf bsr bt btc btr bts cdq cmpsd cwde insd iretd iretdf iretf jecxz lfs lgs lodsd loopd looped loopned loopnzd loopzd lss movsd movsx movzx outsd popad popfd pushad pushd pushfd scasd seta setae setb setbe setc sete setg setge setl setle setna setnae setnb setnbe setnc setne setng setnge setnl setnle setno setnp setns setnz seto setp setpe setpo sets setz shld shrd stosd bswap cmpxchg invd invlpg wbinvd xadd lock rep repe repne repnz repz cflush cpuid emms femms cmovo cmovno cmovb cmovc cmovnae cmovae cmovnb cmovnc cmove cmovz cmovne cmovnz cmovbe cmovna cmova cmovnbe cmovs cmovns cmovp cmovpe cmovnp cmovpo cmovl cmovnge cmovge cmovnl cmovle cmovng cmovg cmovnle cmpxchg486 cmpxchg8b loadall loadall286 ibts icebp int1 int3 int01 int03 iretw popaw popfw pushaw pushfw rdmsr rdpmc rdshr rdtsc rsdc rsldt rsm rsts salc smi smint smintold svdc svldt svts syscall sysenter sysexit sysret ud0 ud1 ud2 umov xbts wrmsr wrshr + f2xm1 fabs fadd faddp fbld fbstp fchs fclex fcom fcomp fcompp fdecstp fdisi fdiv fdivp fdivr fdivrp feni ffree fiadd ficom ficomp fidiv fidivr fild fimul fincstp finit fist fistp fisub fisubr fld fld1 fldcw fldenv fldenvw fldl2e fldl2t fldlg2 fldln2 fldpi fldz fmul fmulp fnclex fndisi fneni fninit fnop fnsave fnsavew fnstcw fnstenv fnstenvw fnstsw fpatan fprem fptan frndint frstor frstorw fsave fsavew fscale fsqrt fst fstcw fstenv fstenvw fstp fstsw fsub fsubp fsubr fsubrp ftst fwait fxam fxch fxtract fyl2x fyl2xp1 fsetpm fcos fldenvd fnsaved fnstenvd fprem1 frstord fsaved fsin fsincos fstenvd fucom fucomp fucompp fcomi fcomip ffreep fcmovb fcmove fcmovbe fcmovu fcmovnb fcmovne fcmovnbe fcmovnu + ah al ax bh bl bp bx ch cl cr0 cr2 cr3 cr4 cs cx dh di dl dr0 dr1 dr2 dr3 dr6 dr7 ds dx eax ebp ebx ecx edi edx es esi esp fs gs si sp ss st tr3 tr4 tr5 tr6 tr7 st0 st1 st2 st3 st4 st5 st6 st7 mm0 mm1 mm2 mm3 mm4 mm5 mm6 mm7 xmm0 xmm1 xmm2 xmm3 xmm4 xmm5 xmm6 xmm7 + .186 .286 .286c .286p .287 .386 .386c .386p .387 .486 .486p .8086 .8087 .alpha .break .code .const .continue .cref .data .data? .dosseg .else .elseif .endif .endw .err .err1 .err2 .errb .errdef .errdif .errdifi .erre .erridn .erridni .errnb .errndef .errnz .exit .fardata .fardata? .if .lall .lfcond .list .listall .listif .listmacro .listmacroall .model .no87 .nocref .nolist .nolistif .nolistmacro .radix .repeat .sall .seq .sfcond .stack .startup .tfcond .type .until .untilcxz .while .xall .xcref .xlist alias align assume catstr comm comment db dd df dosseg dq dt dup dw echo else elseif elseif1 elseif2 elseifb elseifdef elseifdif elseifdifi elseife elseifidn elseifidni elseifnb elseifndef end endif endm endp ends eq equ even exitm extern externdef extrn for forc ge goto group gt high highword if if1 if2 ifb ifdef ifdif ifdifi ife ifidn ifidni ifnb ifndef include includelib instr invoke irp irpc label le length lengthof local low lowword lroffset lt macro mask mod .msfloat name ne offset opattr option org %out page popcontext proc proto ptr public purge pushcontext record repeat rept seg segment short size sizeof sizestr struc struct substr subtitle subttl textequ this title type typedef union while width db dw dd dq dt resb resw resd resq rest incbin equ times %define %idefine %xdefine %xidefine %undef %assign %iassign %strlen %substr %macro %imacro %endmacro %rotate .nolist %if %elif %else %endif %ifdef %ifndef %elifdef %elifndef %ifmacro %ifnmacro %elifmacro %elifnmacro %ifctk %ifnctk %elifctk %elifnctk %ifidn %ifnidn %elifidn %elifnidn %ifidni %ifnidni %elifidni %elifnidni %ifid %ifnid %elifid %elifnid %ifstr %ifnstr %elifstr %elifnstr %ifnum %ifnnum %elifnum %elifnnum %error %rep %endrep %exitrep %include %push %pop %repl struct endstruc istruc at iend align alignb %arg %stacksize %local %line bits use16 use32 section absolute extern global common cpu org section group import export + $ ? @b @f addr basic byte c carry? dword far far16 fortran fword near near16 overflow? parity? pascal qword real4 real8 real10 sbyte sdword sign? stdcall sword syscall tbyte vararg word zero? flat near32 far32 abs all assumes at casemap common compact cpu dotname emulator epilogue error export expr16 expr32 farstack flat forceframe huge language large listing ljmp loadds m510 medium memory nearstack nodotname noemulator nokeyword noljmp nom510 none nonunique nooldmacros nooldstructs noreadonly noscoped nosignextend nothing notpublic oldmacros oldstructs os_dos para private prologue radix readonly req scoped setif2 smallstack tiny use16 use32 uses a16 a32 o16 o32 byte word dword nosplit $ $$ seq wrt flat large small .text .data .bss near far %0 %1 %2 %3 %4 %5 %6 %7 %8 %9 + addpd addps addsd addss andpd andps andnpd andnps cmpeqpd cmpltpd cmplepd cmpunordpd cmpnepd cmpnltpd cmpnlepd cmpordpd cmpeqps cmpltps cmpleps cmpunordps cmpneps cmpnltps cmpnleps cmpordps cmpeqsd cmpltsd cmplesd cmpunordsd cmpnesd cmpnltsd cmpnlesd cmpordsd cmpeqss cmpltss cmpless cmpunordss cmpness cmpnltss cmpnless cmpordss comisd comiss cvtdq2pd cvtdq2ps cvtpd2dq cvtpd2pi cvtpd2ps cvtpi2pd cvtpi2ps cvtps2dq cvtps2pd cvtps2pi cvtss2sd cvtss2si cvtsd2si cvtsd2ss cvtsi2sd cvtsi2ss cvttpd2dq cvttpd2pi cvttps2dq cvttps2pi cvttsd2si cvttss2si divpd divps divsd divss fxrstor fxsave ldmxscr lfence mfence maskmovdqu maskmovdq maxpd maxps paxsd maxss minpd minps minsd minss movapd movaps movdq2q movdqa movdqu movhlps movhpd movhps movd movq movlhps movlpd movlps movmskpd movmskps movntdq movnti movntpd movntps movntq movq2dq movsd movss movupd movups mulpd mulps mulsd mulss orpd orps packssdw packsswb packuswb paddb paddsb paddw paddsw paddd paddsiw paddq paddusb paddusw pand pandn pause paveb pavgb pavgw pavgusb pdistib pextrw pcmpeqb pcmpeqw pcmpeqd pcmpgtb pcmpgtw pcmpgtd pf2id pf2iw pfacc pfadd pfcmpeq pfcmpge pfcmpgt pfmax pfmin pfmul pmachriw pmaddwd pmagw pmaxsw pmaxub pminsw pminub pmovmskb pmulhrwc pmulhriw pmulhrwa pmulhuw pmulhw pmullw pmuludq pmvzb pmvnzb pmvlzb pmvgezb pfnacc pfpnacc por prefetch prefetchw prefetchnta prefetcht0 prefetcht1 prefetcht2 pfrcp pfrcpit1 pfrcpit2 pfrsqit1 pfrsqrt pfsub pfsubr pi2fd pf2iw pinsrw psadbw pshufd pshufhw pshuflw pshufw psllw pslld psllq pslldq psraw psrad psrlw psrld psrlq psrldq psubb psubw psubd psubq psubsb psubsw psubusb psubusw psubsiw pswapd punpckhbw punpckhwd punpckhdq punpckhqdq punpcklbw punpcklwd punpckldq punpcklqdq pxor rcpps rcpss rsqrtps rsqrtss sfence shufpd shufps sqrtpd sqrtps sqrtsd sqrtss stmxcsr subpd subps subsd subss ucomisd ucomiss unpckhpd unpckhps unpcklpd unpcklps xorpd xorps + + + addhandler addressof andalso alias and ansi as assembly attribute auto begin boolean byref byte byval call case catch cbool cbyte cchar cdate cdec cdbl char cint class clng cobj compare const continue cshort csng cstr ctype currency date decimal declare default delegate dim do double each else elseif end enum erase error event exit explicit false finally for friend function get gettype global gosub goto handles if implement implements imports in inherits integer interface is let lib like load long loop lset me mid mod module mustinherit mustoverride mybase myclass namespace new next not nothing notinheritable notoverridable object on option optional or orelse overloads overridable overrides paramarray preserve private property protected public raiseevent readonly redim rem removehandler rset resume return select set shadows shared short single static step stop string structure sub synclock then throw to true try type typeof unload unicode until variant wend when while with withevents writeonly xor + + + and byref case continueloop dim do else elseif endfunc endif endselect exit exitloop for func global if local next not or return select step then to until wend while exit + abs acos adlibdisable adlibenable asc asin atan autoitsetoption autoitwingettitle autoitwinsettitle bitand bitnot bitor bitshift bitxor blockinput break call cdtray chr clipget clipput controlclick controlcommand controldisable controlenable controlfocus controlgetfocus controlgetpos controlgettext controlhide controlmove controlsend controlsettext controlshow cos dec dircopy dircreate dirmove dirremove drivegetdrive drivegetfilesystem drivegetlabel drivegetserial drivegettype drivesetlabel drivespacefree drivespacetotal drivestatus envget envset envupdate eval exp filechangedir fileclose filecopy filecreateshortcut filedelete fileexists filefindfirstfile filefindnextfile filegetattrib filegetlongname filegetshortname filegetsize filegettime filegetversion fileinstall filemove fileopen fileopendialog fileread filereadline filerecycle filerecycleempty filesavedialog fileselectfolder filesetattrib filesettime filewrite filewriteline guicreate guicreateex guidefaultfont guidelete guigetcontrolstate guihide guimsg guiread guirecvmsg guisendmsg guisetcontrol guisetcontroldata guisetcontrolex guisetcontrolfont guisetcontrolnotify guisetcoord guisetcursor guishow guiwaitclose guiwrite hex hotkeyset inidelete iniread iniwrite inputbox int isadmin isarray isdeclared isfloat isint isnumber isstring log memgetstats mod mouseclick mouseclickdrag mousedown mousegetcursor mousegetpos mousemove mouseup mousewheel msgbox number pixelchecksum pixelgetcolor pixelsearch processclose processexists processsetpriority processwait processwaitclose progressoff progresson progressset random regdelete regenumkey regenumval regread regwrite round run runasset runwait send seterror shutdown sin sleep soundplay soundsetwavevolume splashimageon splashoff splashtexton sqrt statusbargettext string stringaddcr stringformat stringinstr stringisalnum stringisalpha stringisascii stringisdigit stringisfloat stringisint stringislower stringisspace stringisupper stringisxdigit stringleft stringlen stringlower stringmid stringreplace stringright stringsplit stringstripcr stringstripws stringtrimleft stringtrimright stringupper tan timerstart timerstop tooltip traytip ubound urldownloadtofile winactivate winactive winclose winexists wingetcaretpos wingetclasslist wingetclientsize wingethandle wingetpos wingetstate wingettext wingettitle winkill winmenuselectitem winminimizeall winminimizeallundo winmove winsetontop winsetstate winsettitle winwait winwaitactive winwaitclose winwaitnotactive + @appdatacommondir @appdatadir @autoitversion @commonfilesdir @compiled @computername @comspec @cr @crlf @desktopcommondir @desktopdir @desktopheight @desktopwidth @documentscommondir @error @favoritescommondir @favoritesdir @homedrive @homepath @homeshare @hour @ipaddress1 @ipaddress2 @ipaddress3 @ipaddress4 @lf @logondnsdomain @logondomain @logonserver @mday @min @mon @mydocumentsdir @osbuild @oslang @osservicepack @ostype @osversion @programfilesdir @programscommondir @programsdir @scriptdir @scriptfullpath @scriptname @sec @startmenucommondir @startmenudir @startupcommondir @startupdir @sw_hide @sw_maximize @sw_minimize @sw_restore @sw_show @systemdir @tab @tempdir @userprofiledir @username @wday @windowsdir @workingdir @yday @year + {!} {#} {^} {{} {}} {+} {alt} {altdown} {altup} {appskey} {asc} {backspace} {browser_back} {browser_favorites} {browser_forward} {browser_home} {browser_refresh} {browser_search} {browser_stop} {bs} {capslock} {ctrlbreak} {ctrldown} {ctrlup} {del} {delete} {down} {end} {enter} {esc} {escape} {f1} {f10} {f11} {f12} {f2} {f3} {f4} {f5} {f6} {f7} {f8} {f9} {home} {ins} {insert} {lalt} {launch_app1} {launch_app2} {launch_mail} {launch_media} {lctrl} {left} {lshift} {lwin} {lwindown} {media_next} {media_play_pause} {media_prev} {media_stop} {numlock} {numpad0} {numpad1} {numpad2} {numpad3} {numpad4} {numpad5} {numpad6} {numpad7} {numpad8} {numpad9} {numpadadd} {numpaddiv} {numpaddot} {numpadenter} {numpadmult} {numpadsub} {pause} {pgdn} {pgup} {printscreen} {ralt} {rctrl} {right} {rshift} {rwin} {rwindown} {scrolllock} {shiftdown} {shiftup} {sleep} {space} {tab} {up} {volume_down} {volume_mute} {volume_up} + #include #include-once + #region #endregion + + + + alias ar asa awk banner basename bash bc bdiff break bunzip2 bzip2 cal calendar case cat cc cd chmod cksum clear cmp col comm compress continue cp cpio crypt csplit ctags cut date dc dd declare deroff dev df diff diff3 dircmp dirname do done du echo ed egrep elif else env esac eval ex exec exit expand export expr false fc fgrep fi file find fmt fold for function functions getconf getopt getopts grep gres hash head help history iconv id if in integer jobs join kill local lc let line ln logname look ls m4 mail mailx make man mkdir more mt mv newgrp nl nm nohup ntps od pack paste patch pathchk pax pcat perl pg pr print printf ps pwd read readonly red return rev rm rmdir sed select set sh shift size sleep sort spell split start stop strings strip stty sum suspend sync tail tar tee test then time times touch tr trap true tsort tty type typeset ulimit umask unalias uname uncompress unexpand uniq unpack unset until uudecode uuencode vi vim vpax wait wc whence which while who wpaste wstart xargs zcat + + + rem set if else exist errorlevel for in do break call copy chcp cd chdir choice cls country ctty date del erase dir echo exit goto loadfix loadhigh mkdir md move path pause prompt rename ren rmdir rd shift time type ver verify vol com con lpt nul defined not errorlevel cmdextversion + + + if else switch case default break goto return for while do continue typedef sizeof NULL + void struct union enum char short int long double float signed unsigned const static extern auto register volatile + + + and as assert asr begin class constraint do done downto else end exception external false for fun function functor if in include inherit initializer land lazy let lor lsl lsr lxor match method mod module mutable new object of open or private rec sig struct then to true try type val virtual when while with + option Some None ignore ref lnot succ pred + array bool char float int list string unit + + + add_custom_command add_custom_target add_definitions add_dependencies add_executable add_library add_subdirectory add_test aux_source_directory build_command build_name cmake_minimum_required configure_file create_test_sourcelist else elseif enable_language enable_testing endforeach endif endmacro endwhile exec_program execute_process export_library_dependencies file find_file find_library find_package find_path find_program fltk_wrap_ui foreach get_cmake_property get_directory_property get_filename_component get_source_file_property get_target_property get_test_property if include include_directories include_external_msproject include_regular_expression install install_files install_programs install_targets link_directories link_libraries list load_cache load_command macro make_directory mark_as_advanced math message option output_required_files project qt_wrap_cpp qt_wrap_ui remove remove_definitions separate_arguments set set_directory_properties set_source_files_properties set_target_properties set_tests_properties site_name source_group string subdir_depends subdirs target_link_libraries try_compile try_run use_mangled_mesa utility_source variable_requires vtk_make_instantiator vtk_wrap_java vtk_wrap_python vtk_wrap_tcl while write_file + ABSOLUTE ABSTRACT ADDITIONAL_MAKE_CLEAN_FILES ALL AND APPEND ARGS ASCII BEFORE CACHE CACHE_VARIABLES CLEAR COMMAND COMMANDS COMMAND_NAME COMMENT COMPARE COMPILE_FLAGS COPYONLY DEFINED DEFINE_SYMBOL DEPENDS DOC EQUAL ESCAPE_QUOTES EXCLUDE EXCLUDE_FROM_ALL EXISTS EXPORT_MACRO EXT EXTRA_INCLUDE FATAL_ERROR FILE FILES FORCE FUNCTION GENERATED GLOB GLOB_RECURSE GREATER GROUP_SIZE HEADER_FILE_ONLY HEADER_LOCATION IMMEDIATE INCLUDES INCLUDE_DIRECTORIES INCLUDE_INTERNALS INCLUDE_REGULAR_EXPRESSION LESS LINK_DIRECTORIES LINK_FLAGS LOCATION MACOSX_BUNDLE MACROS MAIN_DEPENDENCY MAKE_DIRECTORY MATCH MATCHALL MATCHES MODULE NAME NAME_WE NOT NOTEQUAL NO_SYSTEM_PATH OBJECT_DEPENDS OPTIONAL OR OUTPUT OUTPUT_VARIABLE PATH PATHS POST_BUILD POST_INSTALL_SCRIPT PREFIX PREORDER PRE_BUILD PRE_INSTALL_SCRIPT PRE_LINK PROGRAM PROGRAM_ARGS PROPERTIES QUIET RANGE READ REGEX REGULAR_EXPRESSION REPLACE REQUIRED RETURN_VALUE RUNTIME_DIRECTORY SEND_ERROR SHARED SOURCES STATIC STATUS STREQUAL STRGREATER STRLESS SUFFIX TARGET TOLOWER TOUPPER VAR VARIABLES VERSION WIN32 WRAP_EXCLUDE WRITE APPLE MINGW MSYS CYGWIN BORLAND WATCOM MSVC MSVC_IDE MSVC60 MSVC70 MSVC71 MSVC80 CMAKE_COMPILER_2005 OFF ON + + + + if else switch case default break goto return for while do continue typedef sizeof NULL new delete throw try catch namespace operator this const_cast static_cast dynamic_cast reinterpret_cast true false using typeid and and_eq bitand bitor compl not not_eq or or_eq xor xor_eq + void struct union enum char short int long double float signed unsigned const static extern auto register volatile bool class private protected public friend inline template virtual asm explicit typename mutable + a addindex addtogroup anchor arg attention author b brief bug c class code date def defgroup deprecated dontinclude e em endcode endhtmlonly endif endlatexonly endlink endverbatim enum example exception f$ f[ f] file fn hideinitializer htmlinclude htmlonly if image include ingroup internal invariant interface latexonly li line link mainpage name namespace nosubgrouping note overload p page par param post preref relates remarks return retval sa section see showinitializer since skip skipline struct subsection test throw throws todo typedef union until var verbatim verbinclude version warning weakgroup $ @ \ & < > # { } + + + abstract as base break case catch checked continue default delegate do else event explicit extern false finally fixed for foreach goto if implicit in interface internal is lock namespace new null object operator out override params private protected public readonly ref return sealed sizeof stackalloc switch this throw true try typeof unchecked unsafe using virtual while + bool byte char class const decimal double enum float int long sbyte short static string struct uint ulong ushort void + + + azimuth background background-attachment background-color background-image background-position background-repeat border border-bottom border-bottom-color border-bottom-style border-bottom-width border-collapse border-color border-left border-left-color border-left-style border-left-width border-right border-right-color border-right-style border-right-width border-spacing border-style border-top border-top-color border-top-style border-top-width border-width bottom caption-side clear clip color content counter-increment counter-reset cue cue-after cue-before cursor direction display elevation empty-cells float font font-family font-size font-size-adjust font-stretch font-style font-variant font-weight height left letter-spacing line-height list-style list-style-image list-style-position list-style-type margin margin-bottom margin-left margin-right margin-top marker-offset marks max-height max-width min-height min-width orphans outline outline-color outline-style outline-width overflow padding padding-bottom padding-left padding-right padding-top page page-break-after page-break-before page-break-inside pause pause-after pause-before pitch pitch-range play-during position quotes richness right size speak speak-header speak-numeral speak-ponctuation speech-rate stress table-layout text-align text-decoration text-indent text-shadow text-transform top unicode-bidi vertical-align visibility voice-family volume white-space widows width word-spacing z-index + active after before first first-child first-letter first-line focus hover lang left link right visited + + + + + access action advance allocatable allocate apostrophe assign assignment associate asynchronous backspace bind blank blockdata call case character class close common complex contains continue cycle data deallocate decimal delim default dimension direct do dowhile double doubleprecision else elseif elsewhere encoding end endassociate endblockdata enddo endfile endforall endfunction endif endinterface endmodule endprogram endselect endsubroutine endtype endwhere entry eor equivalence err errmsg exist exit external file flush fmt forall form format formatted function go goto id if implicit in include inout integer inquire intent interface intrinsic iomsg iolength iostat kind len logical module name named namelist nextrec nml none nullify number only open opened operator optional out pad parameter pass pause pending pointer pos position precision print private program protected public quote read readwrite real rec recl recursive result return rewind save select selectcase selecttype sequential sign size stat status stop stream subroutine target then to type unformatted unit use value volatile wait where while write + abs achar acos acosd adjustl adjustr aimag aimax0 aimin0 aint ajmax0 ajmin0 akmax0 akmin0 all allocated alog alog10 amax0 amax1 amin0 amin1 amod anint any asin asind associated atan atan2 atan2d atand bitest bitl bitlr bitrl bjtest bit_size bktest break btest cabs ccos cdabs cdcos cdexp cdlog cdsin cdsqrt ceiling cexp char clog cmplx conjg cos cosd cosh count cpu_time cshift csin csqrt dabs dacos dacosd dasin dasind datan datan2 datan2d datand date date_and_time dble dcmplx dconjg dcos dcosd dcosh dcotan ddim dexp dfloat dflotk dfloti dflotj digits dim dimag dint dlog dlog10 dmax1 dmin1 dmod dnint dot_product dprod dreal dsign dsin dsind dsinh dsqrt dtan dtand dtanh eoshift epsilon errsns exp exponent float floati floatj floatk floor fraction free huge iabs iachar iand ibclr ibits ibset ichar idate idim idint idnint ieor ifix iiabs iiand iibclr iibits iibset iidim iidint iidnnt iieor iifix iint iior iiqint iiqnnt iishft iishftc iisign ilen imax0 imax1 imin0 imin1 imod index inint inot int int1 int2 int4 int8 iqint iqnint ior ishft ishftc isign isnan izext jiand jibclr jibits jibset jidim jidint jidnnt jieor jifix jint jior jiqint jiqnnt jishft jishftc jisign jmax0 jmax1 jmin0 jmin1 jmod jnint jnot jzext kiabs kiand kibclr kibits kibset kidim kidint kidnnt kieor kifix kind kint kior kishft kishftc kisign kmax0 kmax1 kmin0 kmin1 kmod knint knot kzext lbound leadz len len_trim lenlge lge lgt lle llt log log10 logical lshift malloc matmul max max0 max1 maxexponent maxloc maxval merge min min0 min1 minexponent minloc minval mod modulo mvbits nearest nint not nworkers number_of_processors pack popcnt poppar precision present product radix random random_number random_seed range real repeat reshape rrspacing rshift scale scan secnds selected_int_kind selected_real_kind set_exponent shape sign sin sind sinh size sizeof sngl snglq spacing spread sqrt sum system_clock tan tand tanh tiny transfer transpose trim ubound unpack verify + cdabs cdcos cdexp cdlog cdsin cdsqrt cotan cotand dcmplx dconjg dcotan dcotand decode dimag dll_export dll_import doublecomplex dreal dvchk encode find flen flush getarg getcharqq getcl getdat getenv gettim hfix ibchng identifier imag int1 int2 int4 intc intrup invalop iostat_msg isha ishc ishl jfix lacfar locking locnear map nargs nbreak ndperr ndpexc offset ovefl peekcharqq precfill prompt qabs qacos qacosd qasin qasind qatan qatand qatan2 qcmplx qconjg qcos qcosd qcosh qdim qexp qext qextd qfloat qimag qlog qlog10 qmax1 qmin1 qmod qreal qsign qsin qsind qsinh qsqrt qtan qtand qtanh ran rand randu rewrite segment setdat settim system timer undfl unlock union val virtual volatile zabs zcos zexp zlog zsin zsqrt + + + as case class data default deriving do else hiding if import in infix infixl infixr instance let module newtype of proc qualified rec then type where _ + + + !doctype a abbr accept-charset accept accesskey acronym action address align alink alt applet archive area axis b background base basefont bdo bgcolor big blockquote body border br button caption cellpadding cellspacing center char charoff charset checkbox checked cite class classid clear code codebase codetype col colgroup color cols colspan comment compact content coords data datafld dataformatas datapagesize datasrc datetime dd declare defer del dfn dir disabled div dl dt em embed enctype event face fieldset file font for form frame frameborder frameset h1 h2 h3 h4 h5 h6 head headers height hidden hr href hreflang hspace html http-equiv i id iframe image img input ins isindex ismap kbd label lang language leftmargin legend li link longdesc map marginwidth marginheight maxlength media menu meta method multiple name noframes nohref noresize noscript noshade nowrap object ol onblur onchange onclick ondblclick onfocus onkeydown onkeypress onkeyup onload onmousedown onmousemove onmouseover onmouseout onmouseup optgroup option onreset onselect onsubmit onunload p param password profile pre prompt public q radio readonly rel reset rev rows rowspan rules s samp scheme scope script scrolling select selected shape size small span src standby start strike strong style sub submit summary sup tabindex table target tbody td text textarea tfoot th thead title topmargin tr tt type u ul usemap valign value valuetype var version vlink vspace width xml xmlns + + + + + code components custommessages dirs files icons ini installdelete langoptions languages messages registry run setup types tasks uninstalldelete uninstallrun _istool + allowcancelduringinstall allownoicons allowrootdirectory allowuncpath alwaysrestart alwaysshowcomponentslist alwaysshowdironreadypage alwaysshowgrouponreadypage alwaysusepersonalgroup appcomments appcontact appcopyright appenddefaultdirname appenddefaultgroupname appid appmodifypath appmutex appname apppublisher apppublisherurl appreadmefile appsupporturl appupdatesurl appvername appversion architecturesallowed architecturesinstallin64bitmode backcolor backcolor2 backcolordirection backsolid changesassociations changesenvironment compression copyrightfontname copyrightfontsize createappdir createuninstallregkey defaultdirname defaultgroupname defaultuserinfoname defaultuserinfoorg defaultuserinfoserial dialogfontname dialogfontsize direxistswarning disabledirpage disablefinishedpage disableprogramgrouppage disablereadymemo disablereadypage disablestartupprompt diskclustersize diskslicesize diskspanning enablesdirdoesntexistwarning encryption extradiskspacerequired flatcomponentslist infoafterfile infobeforefile internalcompresslevel languagedetectionmethod languagecodepage languageid languagename licensefile mergeduplicatefiles minversion onlybelowversion outputbasefilename outputdir outputmanifestfile password privilegesrequired reservebytes restartifneededbyrun setupiconfile showcomponentsizes showlanguagedialog showtaskstreelines slicesperdisk solidcompression sourcedir timestamprounding timestampsinutc titlefontname titlefontsize touchdate touchtime uninstallable uninstalldisplayicon uninstalldisplayname uninstallfilesdir uninstalllogmode uninstallrestartcomputer updateuninstalllogappname usepreviousappdir usepreviousgroup useprevioussetuptype useprevioustasks useprevioususerinfo userinfopage usesetupldr versioninfocompany versioninfocopyright versioninfodescription versioninfotextversion versioninfoversion welcomefontname welcomefontsize windowshowcaption windowstartmaximized windowresizable windowvisible wizardimagebackcolor wizardimagefile wizardimagestretch wizardsmallimagefile + afterinstall attribs beforeinstall check comment components copymode description destdir destname excludes extradiskspacerequired filename flags fontinstall groupdescription hotkey infoafterfile infobeforefile iconfilename iconindex key languages licensefile messagesfile minversion name onlybelowversion parameters permissions root runonceid section source statusmsg string subkey tasks type types valuedata valuename valuetype workingdir + append define dim else emit endif endsub error expr file for if ifdef ifexist ifndef ifnexist include insert pragma sub undef + begin break case const continue do downto else end except finally for function if of procedure repeat then to try until uses var while with + + + + instanceof assert if else switch case default break goto return for while do continue new throw throws try catch finally this super extends implements import true false null + package transient strictfp void char short int long double float const static volatile byte boolean class interface native private protected public final abstract synchronized enum + + + abstract boolean break byte case catch char class const continue debugger default delete do double else enum export extends final finally float for function goto if implements import in instanceof int interface long native new package private protected public return short static super switch synchronized this throw throws transient try typeof var void volatile while with true false prototype + + + ? and beep big break call cd cls color cookie1 copy debug del dim display do until exit flushkb for each next function endfunction get gets global go gosub goto if else endif md or password play quit rd redim return run select case endselect set setl setm settime shell sleep small use while loop + abs addkey addprinterconnection addprogramgroup addprogramitem asc ascan at backupeventlog box cdbl chr cint cleareventlog close comparefiletimes createobject cstr dectohex delkey delprinterconnection delprogramgroup delprogramitem deltree delvalue dir enumgroup enumipinfo enumkey enumlocalgroup enumvalue execute exist existkey expandenvironmentvars fix formatnumber freefilehandle getdiskspace getfileattr getfilesize getfiletime getfileversion getobject iif ingroup instr instrrev int isdeclared join kbhit keyexist lcase left len loadhive loadkey logevent logoff ltrim memorysize messagebox open readline readprofilestring readtype readvalue redirectoutput right rnd round rtrim savekey sendkeys sendmessage setascii setconsole setdefaultprinter setfileattr setfocus setoption setsystemstate settitle setwallpaper showprogramgroup shutdown sidtoname split srnd substr trim ubound ucase unloadhive val vartype vartypename writeline writeprofilestring writevalue + address build color comment cpu crlf csd curdir date day domain dos error fullname homedir homedrive homeshr hostname inwin ipaddress0 ipaddress1 ipaddress2 ipaddress3 kix lanroot ldomain ldrive lm logonmode longhomedir lserver maxpwage mdayno mhz monthno month msecs pid primarygroup priv productsuite producttype pwage ras result rserver scriptdir scriptexe scriptname serror sid site startdir syslang ticks time userid userlang wdayno wksta wuserid ydayno year + + + not defun + - * / = < > <= >= princ eval apply funcall quote identity function complement backquote lambda set setq setf defun defmacro gensym make symbol intern symbol name symbol value symbol plist get getf putprop remprop hash make array aref car cdr caar cadr cdar cddr caaar caadr cadar caddr cdaar cdadr cddar cdddr caaaar caaadr caadar caaddr cadaar cadadr caddar cadddr cdaaar cdaadr cdadar cdaddr cddaar cddadr cdddar cddddr cons list append reverse last nth nthcdr member assoc subst sublis nsubst nsublis remove length list length mapc mapcar mapl maplist mapcan mapcon rplaca rplacd nconc delete atom symbolp numberp boundp null listp consp minusp zerop plusp evenp oddp eq eql equal cond case and or let l if prog prog1 prog2 progn go return do dolist dotimes catch throw error cerror break continue errset baktrace evalhook truncate float rem min max abs sin cos tan expt exp sqrt random logand logior logxor lognot bignums logeqv lognand lognor logorc2 logtest logbitp logcount integer length nil + + + and break do else elseif end false for function if in local nil not or repeat return then true until while + _VERSION assert collectgarbage dofile error gcinfo loadfile loadstring print tonumber tostring type unpack _ALERT _ERRORMESSAGE _INPUT _PROMPT _OUTPUT _STDERR _STDIN _STDOUT call dostring foreach foreachi getn globals newtype rawget rawset require sort tinsert tremove _G getfenv getmetatable ipairs loadlib next pairs pcall rawegal rawget rawset require setfenv setmetatable xpcall string table math coroutine io os debug + abs acos asin atan atan2 ceil cos deg exp floor format frexp gsub ldexp log log10 max min mod rad random randomseed sin sqrt strbyte strchar strfind strlen strlower strrep strsub strupper tan string.byte string.char string.dump string.find string.len string.lower string.rep string.sub string.upper string.format string.gfind string.gsub table.concat table.foreach table.foreachi table.getn table.sort table.insert table.remove table.setn math.abs math.acos math.asin math.atan math.atan2 math.ceil math.cos math.deg math.exp math.floor math.frexp math.ldexp math.log math.log10 math.max math.min math.mod math.pi math.rad math.random math.randomseed math.sin math.sqrt math.tan + openfile closefile readfrom writeto appendto remove rename flush seek tmpfile tmpname read write clock date difftime execute exit getenv setlocale time coroutine.create coroutine.resume coroutine.status coroutine.wrap coroutine.yield io.close io.flush io.input io.lines io.open io.output io.read io.tmpfile io.type io.write io.stdin io.stdout io.stderr os.clock os.date os.difftime os.execute os.exit os.getenv os.remove os.rename os.setlocale os.time os.tmpname + + + + + break case catch continue else elseif end for function global if otherwise persistent return switch try while + + + + + Abort AddBrandingImage AddSize AllowRootDirInstall AllowSkipFiles AutoCloseWindow BGFont BGGradient BrandingText BringToFront Call CallInstDLL Caption ChangeUI CheckBitmap ClearErrors CompletedText ComponentText CopyFiles CRCCheck CreateDirectory CreateFont CreateShortCut Delete DeleteINISec DeleteINIStr DeleteRegKey DeleteRegValue DetailPrint DetailsButtonText DirShow DirText DirVar DirVerify DisabledBitmap EnabledBitmap EnableWindow EnumRegKey EnumRegValue Exch Exec ExecShell ExecWait ExpandEnvStrings File FileBufSize FileClose FileErrorText FileOpen FileRead FileReadByte FileSeek FileWrite FileWriteByte FindClose FindFirst FindNext FindWindow FlushINI Function FunctionEnd GetCurInstType GetCurrentAddress GetDlgItem GetDLLVersion GetDLLVersionLocal GetErrorLevel GetFileTime GetFileTimeLocal GetFullPathName GetFunctionAddress GetInstDirError GetLabelAddress GetTempFileName Goto HideWindow Icon IfAbort IfErrors IfFileExists IfRebootFlag IfSilent InitPluginsDir InstallButtonText InstallColors InstallDir InstallDirRegKey InstProgressFlags InstType InstTypeGetText InstTypeSetText IntCmp IntCmpU IntFmt IntOp IsWindow LangString LangStringUP LicenseBkColor LicenseData LicenseForceSelection LicenseLangString LicenseText LoadLanguageFile LockWindow LogSet LogText MessageBox MiscButtonText Name OutFile Page PageEx PageExEnd PluginDir Pop Push Quit ReadEnvStr ReadINIStr ReadRegDWORD ReadRegStr Reboot RegDLL Rename RequestExecutionLevel ReserveFile Return RMDir SearchPath Section SectionDivider SectionEnd SectionGetFlags SectionGetInstTypes SectionGetSize SectionGetText SectionGroup SectionGroupEnd SectionIn SectionSetFlags SectionSetInstTypes SectionSetSize SectionSetText SendMessage SetAutoClose SetBrandingImage SetCompress SetCompressionLevel SetCompressor SetCompressorDictSize SetCtlColors SetCurInstType SetDatablockOptimize SetDateSave SetDetailsPrint SetDetailsView SetErrorLevel SetErrors SetFileAttributes SetFont SetOutPath SetOverwrite SetPluginUnload SetRebootFlag SetShellVarContext SetSilent SetStaticBkColor ShowInstDetails ShowUninstDetails ShowWindow SilentInstall SilentUnInstall Sleep SpaceTexts StrCmp StrCmpS StrCpy StrLen SubSection SubSectionEnd UninstallButtonText UninstallCaption UninstallEXEName UninstallIcon UninstallSubCaption UninstallText UninstPage UnRegDLL Var VIAddVersionKey VIProductVersion WindowIcon WriteINIStr WriteRegBin WriteRegDWORD WriteRegExpandStr WriteRegStr WriteUninstaller XPStyle !AddIncludeDir !AddPluginDir !appendfile !cd !define !delfile !echo !else !endif !error !execute !ifdef !ifmacrodef !ifmacrondef !ifndef !include !insertmacro !macro !macroend !packhdr !system !tempfile !undef !verbose !warning + $0 $1 $2 $3 $4 $5 $6 $7 $8 $9 $R0 $R1 $R2 $R3 $R4 $R5 $R6 $R7 $R8 $R9 $APPDATA $CMDLINE $DESKTOP $EXEDIR $HWNDPARENT $INSTDIR $OUTDIR $PROGRAMFILES ${NSISDIR} $\n $\r $QUICKLAUNCH $SMPROGRAMS $SMSTARTUP $STARTMENU $SYSDIR $TEMP $WINDIR + ARCHIVE FILE_ATTRIBUTE_ARCHIVE FILE_ATTRIBUTE_HIDDEN FILE_ATTRIBUTE_NORMAL FILE_ATTRIBUTE_OFFLINE FILE_ATTRIBUTE_READONLY FILE_ATTRIBUTE_SYSTEM FILE_ATTRIBUTE_TEMPORARY HIDDEN HKCC HKCR HKCU HKDD HKEY_CLASSES_ROOT HKEY_CURRENT_CONFIG HKEY_CURRENT_USER HKEY_DYN_DATA HKEY_LOCAL_MACHINE HKEY_PERFORMANCE_DATA HKEY_USERS HKLM HKPD HKU IDABORT IDCANCEL IDIGNORE IDNO IDOK IDRETRY IDYES MB_ABORTRETRYIGNORE MB_DEFBUTTON1 MB_DEFBUTTON2 MB_DEFBUTTON3 MB_DEFBUTTON4 MB_ICONEXCLAMATION MB_ICONINFORMATION MB_ICONQUESTION MB_ICONSTOP MB_OK MB_OKCANCEL MB_RETRYCANCEL MB_RIGHT MB_SETFOREGROUND MB_TOPMOST MB_YESNO MB_YESNOCANCEL NORMAL OFFLINE READONLY SW_SHOWMAXIMIZED SW_SHOWMINIMIZED SW_SHOWNORMAL SYSTEM TEMPORARY auto colored false force hide ifnewer nevershow normal off on show silent silentlog smooth true try + + + + if else switch case default break goto return for while do continue typedef sizeof NULL self super nil NIL + interface implementation protocol end private protected public class selector encode defs + void struct union enum char short int long double float signed unsigned const static extern auto register volatile id Class SEL IMP BOOL + oneway in out inout bycopy byref + + + and array asm begin case cdecl class const constructor default destructor div do downto else end end. except exit exports external far file finalization finally for function goto if implementation in index inherited initialization inline interface label library message mod near nil not object of on or out overload override packed pascal private procedure program property protected public published raise read record register repeat resourcestring safecall set shl shr stdcall stored string then threadvar to try type unit until uses var virtual while with write xor + + + NULL __FILE__ __LINE__ __PACKAGE__ __DATA__ __END__ AUTOLOAD BEGIN CORE DESTROY END EQ GE GT INIT LE LT NE CHECK abs accept alarm and atan2 bind binmode bless caller chdir chmod chomp chop chown chr chroot close closedir cmp connect continue cos crypt dbmclose dbmopen defined delete die do dump each else elsif endgrent endhostent endnetent endprotoent endpwent endservent eof eq eval exec exists exit exp fcntl fileno flock for foreach fork format formline ge getc getgrent getgrgid getgrnam gethostbyaddr gethostbyname gethostent getlogin getnetbyaddr getnetbyname getnetent getpeername getpgrp getppid getpriority getprotobyname getprotobynumber getprotoent getpwent getpwnam getpwuid getservbyname getservbyport getservent getsockname getsockopt glob gmtime goto grep gt hex if index int ioctl join keys kill last lc lcfirst le length link listen local localtime lock log lstat lt m map mkdir msgctl msgget msgrcv msgsnd my ne next no not oct open opendir or ord our pack package pipe pop pos print printf prototype push q qq qr quotemeta qu qw qx rand read readdir readline readlink readpipe recv redo ref rename require reset return reverse rewinddir rindex rmdir s scalar seek seekdir select semctl semget semop send setgrent sethostent setnetent setpgrp setpriority setprotoent setpwent setservent setsockopt shift shmctl shmget shmread shmwrite shutdown sin sleep socket socketpair sort splice split sprintf sqrt srand stat study sub substr symlink syscall sysopen sysread sysseek system syswrite tell telldir tie tied time times tr truncate uc ucfirst umask undef unless unlink unpack unshift untie until use utime values vec wait waitpid wantarray warn while write x xor y + + + and or xor __file__ __line__ array as break case cfunction class const continue declare default die do echo else elseif empty enddeclare endfor endforeach endif endswitch endwhile eval exit extends for foreach function global if include include_once isset list new old_function print require require_once return static switch unset use var while __function__ __class__ php_version php_os default_include_path pear_install_dir pear_extension_dir php_extension_dir php_bindir php_libdir php_datadir php_sysconfdir php_localstatedir php_config_file_path php_output_handler_start php_output_handler_cont php_output_handler_end e_error e_warning e_parse e_notice e_core_error e_core_warning e_compile_error e_compile_warning e_user_error e_user_warning e_user_notice e_all true false bool boolean int integer float double real string array object resource null class extends parent stdclass directory __sleep __wakeup interface implements abstract public protected private + + + $error = == FontDirectory StandardEncoding UserObjects abs add aload anchorsearch and arc arcn arcto array ashow astore atan awidthshow begin bind bitshift bytesavailable cachestatus ceiling charpath clear cleardictstack cleartomark clip clippath closefile closepath concat concatmatrix copy copypage cos count countdictstack countexecstack counttomark currentcmykcolor currentcolorspace currentdash currentdict currentfile currentflat currentfont currentgray currenthsbcolor currentlinecap currentlinejoin currentlinewidth currentmatrix currentmiterlimit currentpagedevice currentpoint currentrgbcolor currentscreen currenttransfer cvi cvlit cvn cvr cvrs cvs cvx def defaultmatrix definefont dict dictstack div dtransform dup echo end eoclip eofill eq erasepage errordict exch exec execstack executeonly executive exit exp false file fill findfont flattenpath floor flush flushfile for forall ge get getinterval grestore grestoreall gsave gt idetmatrix idiv idtransform if ifelse image imagemask index initclip initgraphics initmatrix inustroke invertmatrix itransform known kshow le length lineto ln load log loop lt makefont mark matrix maxlength mod moveto mul ne neg newpath noaccess nor not null nulldevice or pathbbox pathforall pop print prompt pstack put putinterval quit rand rcheck rcurveto read readhexstring readline readonly readstring rectstroke repeat resetfile restore reversepath rlineto rmoveto roll rotate round rrand run save scale scalefont search setblackgeneration setcachedevice setcachelimit setcharwidth setcolorscreen setcolortransfer setdash setflat setfont setgray sethsbcolor setlinecap setlinejoin setlinewidth setmatrix setmiterlimit setpagedevice setrgbcolor setscreen settransfer setvmthreshold show showpage sin sqrt srand stack start status statusdict stop stopped store string stringwidth stroke strokepath sub systemdict token token transform translate true truncate type ueofill undefineresource userdict usertime version vmstatus wcheck where widthshow write writehexstring writestring xcheck xor + GlobalFontDirectory ISOLatin1Encoding SharedFontDirectory UserObject arct colorimage cshow currentblackgeneration currentcacheparams currentcmykcolor currentcolor currentcolorrendering currentcolorscreen currentcolorspace currentcolortransfer currentdevparams currentglobal currentgstate currenthalftone currentobjectformat currentoverprint currentpacking currentpagedevice currentshared currentstrokeadjust currentsystemparams currentundercolorremoval currentuserparams defineresource defineuserobject deletefile execform execuserobject filenameforall fileposition filter findencoding findresource gcheck globaldict glyphshow gstate ineofill infill instroke inueofill inufill inustroke languagelevel makepattern packedarray printobject product realtime rectclip rectfill rectstroke renamefile resourceforall resourcestatus revision rootfont scheck selectfont serialnumber setbbox setblackgeneration setcachedevice2 setcacheparams setcmykcolor setcolor setcolorrendering setcolorscreen setcolorspace setcolortranfer setdevparams setfileposition setglobal setgstate sethalftone setobjectformat setoverprint setpacking setpagedevice setpattern setshared setstrokeadjust setsystemparams setucacheparams setundercolorremoval setuserparams setvmthreshold shareddict startjob uappend ucache ucachestatus ueofill ufill undef undefinefont undefineresource undefineuserobject upath ustroke ustrokepath vmreclaim writeobject xshow xyshow yshow + cliprestore clipsave composefont currentsmoothness findcolorrendering setsmoothness shfill + .begintransparencygroup .begintransparencymask .bytestring .charboxpath .currentaccuratecurves .currentblendmode .currentcurvejoin .currentdashadapt .currentdotlength .currentfilladjust2 .currentlimitclamp .currentopacityalpha .currentoverprintmode .currentrasterop .currentshapealpha .currentsourcetransparent .currenttextknockout .currenttexturetransparent .dashpath .dicttomark .discardtransparencygroup .discardtransparencymask .endtransparencygroup .endtransparencymask .execn .filename .filename .fileposition .forceput .forceundef .forgetsave .getbitsrect .getdevice .inittransparencymask .knownget .locksafe .makeoperator .namestring .oserrno .oserrorstring .peekstring .rectappend .runandhide .setaccuratecurves .setblendmode .setcurvejoin .setdashadapt .setdebug .setdefaultmatrix .setdotlength .setfilladjust2 .setlimitclamp .setmaxlength .setopacityalpha .setoverprintmode .setrasterop .setsafe .setshapealpha .setsourcetransparent .settextknockout .settexturetransparent .stringbreak .stringmatch .tempfile .type1decrypt .type1encrypt .type1execchar .unread arccos arcsin copydevice copyscanlines currentdevice finddevice findlibfile findprotodevice flushpage getdeviceprops getenv makeimagedevice makewordimagedevice max min putdeviceprops setdevice + + + + + and as assert break class continue def del elif else except exec finally for from global if import in is lambda None not or pass print raise return triple try while with yield + + + ACCELERATORS ALT AUTO3STATE AUTOCHECKBOX AUTORADIOBUTTON BEGIN BITMAP BLOCK BUTTON CAPTION CHARACTERISTICS CHECKBOX CLASS COMBOBOX CONTROL CTEXT CURSOR DEFPUSHBUTTON DIALOG DIALOGEX DISCARDABLE EDITTEXT END EXSTYLE FONT GROUPBOX ICON LANGUAGE LISTBOX LTEXT MENU MENUEX MENUITEM MESSAGETABLE POPUP PUSHBUTTON RADIOBUTTON RCDATA RTEXT SCROLLBAR SEPARATOR SHIFT STATE3 STRINGTABLE STYLE TEXTINCLUDE VALUE VERSION VERSIONINFO VIRTKEY + + + __FILE__ and def end in or self unless __LINE__ begin defined? ensure module redo super until BEGIN break do false next rescue then when END case else for nil retry true while alias class elsif if not return undef yield + + + + - * / = < > <= >= => abs acos and angle append apply asin assoc assoc assq assv atan begin boolean? caar cadr call-with-current-continuation call/cc call-with-input-file call-with-output-file call-with-values car cdr caar cadr cdar cddr caaar caadr cadar caddr cdaar cdadr cddar cdddr caaaar caaadr caadar caaddr cadaar cadadr caddar cadddr cdaaar cdaadr cdadar cdaddr cddaar cddadr cdddar cddddr case ceiling char->integer char-alphabetic? char-ci<=? char-ci<? char-ci=? char-ci>=? char-ci>? char-downcase char-lower-case? char-numeric? char-ready? char-upcase char-upper-case? char-whitespace? char<=? char<? char=? char>=? char>? char? close-input-port close-output-port complex? cond cons cos current-input-port current-output-port define define-syntax delay denominator display do dynamic-wind else eof-object? eq? equal? eqv? eval even? exact->inexact exact? exp expt floor for-each force gcd if imag-part inexact->exact inexact? input-port? integer->char integer? interaction-environment lambda lcm length let let* let-syntax letrec letrec-syntax list list->string list->vector list-ref list-tail list? load log magnitude make-polar make-rectangular make-string make-vector map max member memq memv min modulo negative? newline not null-environment null? number->string number? numerator odd? open-input-file open-output-file or output-port? pair? peek-char input-port? output-port? positive? procedure? quasiquote quote quotient rational? rationalize read read-char real-part real? remainder reverse round scheme-report-environment set! set-car! set-cdr! sin sqrt string string->list string->number string->symbol string-append string-ci<=? string-ci<? string-ci=? string-ci>=? string-ci>? string-copy string-fill! string-length string-ref string-set! string<=? string<? string=? string>=? string>? string? substring symbol->string symbol? syntax-rules transcript-off transcript-on truncate unquote unquote-splicing values vector vector->list vector-fill! vector-length vector-ref vector-set! vector? with-input-from-file with-output-to-file write write-char zero? + + + ifTrue: ifFalse: whileTrue: whileFalse: ifNil: ifNotNil: whileTrue whileFalse repeat isNil notNil + + + abs absolute access acos add add_months adddate admin after aggregate all allocate alter and any app_name are array as asc ascii asin assertion at atan atn2 audit authid authorization autonomous_transaction avg before begin benchmark between bfilename bin binary binary_checksum binary_integer bit bit_count bit_and bit_or blob body boolean both breadth bulk by call cascade cascaded case cast catalog ceil ceiling char char_base character charindex chartorowid check checksum checksum_agg chr class clob close cluster coalesce col_length col_name collate collation collect column comment commit completion compress concat concat_ws connect connection constant constraint constraints constructorcreate contains containsable continue conv convert corr corresponding cos cot count count_big covar_pop covar_samp create cross cube cume_dist current current_date current_path current_role current_time current_timestamp current_user currval cursor cycle data datalength databasepropertyex date date_add date_format date_sub dateadd datediff datename datepart day db_id db_name deallocate dec declare decimal decode default deferrable deferred degrees delete dense_rank depth deref desc describe descriptor destroy destructor deterministic diagnostics dictionary disconnect difference distinct do domain double drop dump dynamic each else elsif empth encode encrypt end end-exec equals escape every except exception exclusive exec execute exists exit exp export_set extends external extract false fetch first first_value file float floor file_id file_name filegroup_id filegroup_name filegroupproperty fileproperty for forall foreign format formatmessage found freetexttable from from_days fulltextcatalog fulltextservice function general get get_lock getdate getansinull getutcdate global go goto grant greatest group grouping having heap hex hextoraw host host_id host_name hour ident_incr ident_seed ident_current identified identity if ifnull ignore immediate in increment index index_col indexproperty indicator initcap initial initialize initially inner inout input insert instr instrb int integer interface intersect interval into is is_member is_srvrolemember is_null is_numeric isdate isnull isolation iterate java join key lag language large last last_day last_value lateral lcase lead leading least left len length lengthb less level like limit limited ln lpad local localtime localtimestamp locator lock log log10 long loop lower ltrim make_ref map match max maxextents mid min minus minute mlslabel mod mode modifies modify module month months_between names national natural naturaln nchar nclob new new_time newid next next_day nextval no noaudit nocompress nocopy none not nowait null nullif number number_base numeric nvl nvl2 object object_id object_name object_property ocirowid oct of off offline old on online only opaque open operator operation option or ord order ordinalityorganization others out outer output package pad parameter parameters partial partition path pctfree percent_rank pi pls_integer positive positiven postfix pow power pragma precision prefix preorder prepare preserve primary prior private privileges procedure public radians raise rand range rank ratio_to_export raw rawtohex read reads real record recursive ref references referencing reftohex relative release release_lock rename repeat replace resource restrict result return returns reverse revoke right rollback rollup round routine row row_number rowid rowidtochar rowlabel rownum rows rowtype rpad rtrim savepoint schema scroll scope search second section seddev_samp select separate sequence session session_user set sets share sign sin sinh size smallint some soundex space specific specifictype sql sqlcode sqlerrm sqlexception sqlstate sqlwarning sqrt start state statement static std stddev stdev_pop strcmp structure subdate substr substrb substring substring_index subtype successful sum synonym sys_context sys_guid sysdate system_user table tan tanh temporary terminate than then time timestamp timezone_abbr timezone_minute timezone_hour timezone_region to to_char to_date to_days to_number to_single_byte trailing transaction translate translation treat trigger trim true trunc truncate type ucase uid under union unique unknown unnest update upper usage use user userenv using validate value values var_pop var_samp varchar varchar2 variable variance varying view vsize when whenever where with without while with work write year zone + + + after append array auto_execok auto_import auto_load auto_load_index auto_qualify beep binary break case catch cd clock close concat continue dde default echo else elseif encoding eof error eval exec exit expr fblocked fconfigure fcopy file fileevent flush for foreach format gets glob global history if incr info interp join lappend lindex linsert list llength load lrange lreplace lsearch lsort namespace open package pid pkg_mkIndex proc puts pwd read regexp regsub rename resource return scan seek set socket source split string subst switch tclLog tclMacPkgSearch tclPkgSetup tclPkgUnknown tell time trace unknown unset update uplevel upvar variable vwait while + bell bind bindtags button canvas checkbutton console destroy entry event focus font frame grab grid image label listbox menu menubutton message pack place radiobutton raise scale scrollbar text tk tkwait toplevel winfo wm + @scope body class code common component configbody constructor define destructor hull import inherit itcl itk itk_component itk_initialize itk_interior itk_option iwidgets keep method private protected public + tkButtonDown tkButtonEnter tkButtonInvoke tkButtonLeave tkButtonUp tkCancelRepeat tkCheckRadioInvoke tkDarken tkEntryAutoScan tkEntryBackspace tkEntryButton1 tkEntryClosestGap tkEntryInsert tkEntryKeySelect tkEntryMouseSelect tkEntryNextWord tkEntryPaste tkEntryPreviousWord tkEntrySeeInsert tkEntrySetCursor tkEntryTranspose tkEventMotifBindings tkFDGetFileTypes tkFirstMenu tkFocusGroup_Destroy tkFocusGroup_In tkFocusGroup_Out tkFocusOK tkListboxAutoScan tkListboxBeginExtend tkListboxBeginSelect tkListboxBeginToggle tkListboxCancel tkListboxDataExtend tkListboxExtendUpDown tkListboxMotion tkListboxSelectAll tkListboxUpDown tkMbButtonUp tkMbEnter tkMbLeave tkMbMotion tkMbPost tkMenuButtonDown tkMenuDownArrow tkMenuDup tkMenuEscape tkMenuFind tkMenuFindName tkMenuFirstEntry tkMenuInvoke tkMenuLeave tkMenuLeftArrow tkMenuMotion tkMenuNextEntry tkMenuNextMenu tkMenuRightArrow tkMenuUnpost tkMenuUpArrow tkMessageBox tkPostOverPoint tkRecolorTree tkRestoreOldGrab tkSaveGrabInfo tkScaleActivate tkScaleButton2Down tkScaleButtonDown tkScaleControlPress tkScaleDrag tkScaleEndDrag tkScaleIncrement tkScreenChanged tkScrollButton2Down tkScrollButtonDown tkScrollButtonUp tkScrollByPages tkScrollByUnits tkScrollDrag tkScrollEndDrag tkScrollSelect tkScrollStartDrag tkScrollToPos tkScrollTopBottom tkTabToWindow tkTearOffMenu tkTextAutoScan tkTextButton1 tkTextClosestGap tkTextInsert tkTextKeyExtend tkTextKeySelect tkTextNextPara tkTextNextPos tkTextNextWord tkTextPaste tkTextPrevPara tkTextPrevPos tkTextResetAnchor tkTextScrollPages tkTextSelectTo tkTextSetCursor tkTextTranspose tkTextUpDownLine tkTraverseToMenu tkTraverseWithinMenu tk_bisque tk_chooseColor tk_dialog tk_focusFollowsMouse tk_focusNext tk_focusPrev tk_getOpenFile tk_getSaveFile tk_messageBox tk_optionMenu tk_popup tk_setPalette tk_textCopy tk_textCut tk_textPaste + + + + + addhandler addressof andalso alias and ansi as assembly attribute auto begin boolean byref byte byval call case catch cbool cbyte cchar cdate cdec cdbl char cint class clng cobj compare const continue cshort csng cstr ctype currency date decimal declare default delegate dim do double each else elseif end enum erase error event exit explicit false finally for friend function get gettype global gosub goto handles if implement implements imports in inherits integer interface is let lib like load long loop lset me mid mod module mustinherit mustoverride mybase myclass namespace new next not nothing notinheritable notoverridable object on option optional or orelse overloads overridable overrides paramarray preserve private property protected public raiseevent readonly redim rem removehandler rset resume return select set shadows shared short single static step stop string structure sub synclock then throw to true try type typeof unload unicode until variant wend when while with withevents writeonly xor + + + always and assign attribute begin buf bufif0 bufif1 case casex casez cmos deassign default defparam disable edge else end endattribute endcase endfunction endmodule endprimitive endspecify endtable endtask event for force forever fork function highz0 highz1 if ifnone initial inout input integer join medium module large localparam macromodule nand negedge nmos nor not notif0 notif1 or output parameter pmos posedge primitive pull0 pull1 pulldown pullup rcmos real realtime reg release repeat rnmos rpmos rtran rtranif0 rtranif1 scalared signed small specify specparam strength strong0 strong1 supply0 supply1 table task time tran tranif0 tranif1 tri tri0 tri1 triand trior trireg unsigned vectored wait wand weak0 weak1 while wire wor xnor xor + $readmemb $readmemh $sreadmemb $sreadmemh $display $write $strobe $monitor $fdisplay $fwrite $fstrobe $fmonitor $fopen $fclose $time $stime $realtime $scale $printtimescale $timeformat $stop $finish $save $incsave $restart $input $log $nolog $key $nokey $scope $showscopes $showscopes $showvars $showvars $countdrivers $list $monitoron $monitoroff $dumpon $dumpoff $dumpfile $dumplimit $dumpflush $dumpvars $dumpall $reset $reset $reset $reset $reset $random $getpattern $rtoi $itor $realtobits $bitstoreal $setup $hold $setuphold $period $width $skew $recovery + + + + access after alias all architecture array assert attribute begin block body buffer bus case component configuration constant disconnect downto else elsif end entity exit file for function generate generic group guarded if impure in inertial inout is label library linkage literal loop map new next null of on open others out package port postponed procedure process pure range record register reject report return select severity shared signal subtype then to transport type unaffected units until use variable wait when while with + abs and mod nand nor not or rem rol ror sla sll sra srl xnor xor + left right low high ascending image value pos val succ pred leftof rightof base range reverse_range length delayed stable quiet transaction event active last_event last_active last_value driving driving_value simple_name path_name instance_name + now readline read writeline write endfile resolved to_bit to_bitvector to_stdulogic to_stdlogicvector to_stdulogicvector to_x01 to_x01z to_UX01 rising_edge falling_edge is_x shift_left shift_right rotate_left rotate_right resize to_integer to_unsigned to_signed std_match to_01 + std ieee work standard textio std_logic_1164 std_logic_arith std_logic_misc std_logic_signed std_logic_textio std_logic_unsigned numeric_bit numeric_std math_complex math_real vital_primitives vital_timing + boolean bit character severity_level integer real time delay_length natural positive string bit_vector file_open_kind file_open_status line text side width std_ulogic std_ulogic_vector std_logic std_logic_vector X01 X01Z UX01 UX01Z unsigned signed + + + + + + + + + + + + + diff --git a/PowerEditor/src/lastRecentFileList.cpp b/PowerEditor/src/lastRecentFileList.cpp new file mode 100644 index 00000000..65a83afd --- /dev/null +++ b/PowerEditor/src/lastRecentFileList.cpp @@ -0,0 +1,209 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#include "lastRecentFileList.h" +#include "menuCmdID.h" + + +void LastRecentFileList::initMenu(HMENU hMenu, int idBase, int posBase) { + _hMenu = hMenu; + _idBase = idBase; + _posBase = posBase; + + for (int i = 0 ; i < sizeof(_idFreeArray) ; i++) + _idFreeArray[i] = true; +}; + +void LastRecentFileList::updateMenu() { + if (!_hasSeparators && _size > 0) { //add separators + const char * nativeLangOpenAllFiles = (NppParameters::getInstance())->getNativeLangMenuStringA(IDM_OPEN_ALL_RECENT_FILE); + const char * nativeLangCleanFilesList = (NppParameters::getInstance())->getNativeLangMenuStringA(IDM_CLEAN_RECENT_FILE_LIST); + + const char * openAllFileStr = nativeLangOpenAllFiles?nativeLangOpenAllFiles:"Open All Recent Files"; + const char * cleanFileListStr = nativeLangCleanFilesList?nativeLangCleanFilesList:"Clean Recent Files List"; + ::InsertMenu(_hMenu, _posBase + 0, MF_BYPOSITION, UINT(-1), 0); +#ifdef UNICODE + WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); + const wchar_t * openAllFileStrW = wmc->char2wchar(openAllFileStr, CP_ANSI_LATIN_1); + ::InsertMenu(_hMenu, _posBase + 1, MF_BYPOSITION, IDM_OPEN_ALL_RECENT_FILE, openAllFileStrW); + const wchar_t * cleanFileListStrW = wmc->char2wchar(cleanFileListStr, CP_ANSI_LATIN_1); + ::InsertMenu(_hMenu, _posBase + 2, MF_BYPOSITION, IDM_CLEAN_RECENT_FILE_LIST, cleanFileListStrW); +#else + ::InsertMenu(_hMenu, _posBase + 1, MF_BYPOSITION, IDM_OPEN_ALL_RECENT_FILE, openAllFileStr); + ::InsertMenu(_hMenu, _posBase + 2, MF_BYPOSITION, IDM_CLEAN_RECENT_FILE_LIST, cleanFileListStr); +#endif + ::InsertMenu(_hMenu, _posBase + 3, MF_BYPOSITION, UINT(-1), 0); + _hasSeparators = true; + + } + else if (_hasSeparators && _size == 0) //remove separators + { + ::RemoveMenu(_hMenu, _posBase + 3, MF_BYPOSITION); + ::RemoveMenu(_hMenu, IDM_CLEAN_RECENT_FILE_LIST, MF_BYCOMMAND); + ::RemoveMenu(_hMenu, IDM_OPEN_ALL_RECENT_FILE, MF_BYCOMMAND); + ::RemoveMenu(_hMenu, _posBase + 0, MF_BYPOSITION); + _hasSeparators = false; + + } + + //Remove all menu items + for(int i = 0; i < _size; i++) { + ::RemoveMenu(_hMenu, _lrfl.at(i)._id, MF_BYCOMMAND); + } + //Then readd them, so everything stays in sync + TCHAR indexBuffer[4]; + for(int j = 0; j < _size; j++) { + std::generic_string menuString = TEXT(""); + if (j < 9) { //first 9 have accelerator (0 unused) + menuString += TEXT("&"); + } + wsprintf(indexBuffer, TEXT("%d"), j+1);//one based numbering + menuString += indexBuffer; + menuString += TEXT(" "); + menuString += _lrfl.at(j)._name; + ::InsertMenu(_hMenu, _posBase + j, MF_BYPOSITION, _lrfl.at(j)._id, menuString.c_str()); + } +} + +void LastRecentFileList::add(const TCHAR *fn) { + if (_userMax == 0 || _locked) + return; + + RecentItem itemToAdd(fn); + + int index = find(fn); + if (index != -1) { //already in list, bump upwards + remove(index); + } + + if (_size == _userMax) { + itemToAdd._id = _lrfl.back()._id; + _lrfl.pop_back(); //remove oldest + } else { + itemToAdd._id = popFirstAvailableID(); + _size++; + } + _lrfl.push_front(itemToAdd); + updateMenu(); +}; + +void LastRecentFileList::remove(const TCHAR *fn) { + int index = find(fn); + if (index != -1) + remove(index); +}; + +void LastRecentFileList::remove(int index) { + if (_size == 0 || _locked) + return; + if (index > -1 && index < (int)_lrfl.size()) { + ::RemoveMenu(_hMenu, _lrfl.at(index)._id, MF_BYCOMMAND); + setAvailable(_lrfl.at(index)._id); + _lrfl.erase(_lrfl.begin() + index); + _size--; + updateMenu(); + } +}; + + +void LastRecentFileList::clear() { + if (_size == 0) + return; + + for(int i = (_size-1); i >= 0; i--) { + ::RemoveMenu(_hMenu, _lrfl.at(i)._id, MF_BYCOMMAND); + setAvailable(_lrfl.at(i)._id); + _lrfl.erase(_lrfl.begin() + i); + } + _size = 0; + updateMenu(); +} + + +std::generic_string & LastRecentFileList::getItem(int id) { + int i = 0; + for(; i < _size; i++) { + if (_lrfl.at(i)._id == id) + break; + } + if (i == _size) + i = 0; + return _lrfl.at(i)._name; //if not found, return first +}; + +std::generic_string & LastRecentFileList::getIndex(int index) { + return _lrfl.at(index)._name; //if not found, return first +}; + + +void LastRecentFileList::setUserMaxNbLRF(int size) { + _userMax = size; + if (_size > _userMax) { //start popping items + int toPop = _size-_userMax; + while(toPop > 0) { + ::RemoveMenu(_hMenu, _lrfl.back()._id, MF_BYCOMMAND); + setAvailable(_lrfl.back()._id); + _lrfl.pop_back(); + toPop--; + _size--; + } + updateMenu(); + _size = _userMax; + } +}; + + + +void LastRecentFileList::saveLRFL() { + NppParameters *pNppParams = NppParameters::getInstance(); + if (pNppParams->writeNbHistoryFile(_userMax)) + { + for(int i = _size - 1; i >= 0; i--) //reverse order: so loading goes in correct order + { + pNppParams->writeHistory(_lrfl.at(i)._name.c_str()); + } + } +}; + + + +int LastRecentFileList::find(const TCHAR *fn) { + int i = 0; + for(int i = 0; i < _size; i++) { + if (!lstrcmpi(_lrfl.at(i)._name.c_str(), fn)) { + return i; + } + } + return -1; +}; + +int LastRecentFileList::popFirstAvailableID() { + for (int i = 0 ; i < NB_MAX_LRF_FILE ; i++) + { + if (_idFreeArray[i]) + { + _idFreeArray[i] = false; + return i + _idBase; + } + } + return 0; +}; + +void LastRecentFileList::setAvailable(int id) { + int index = id - _idBase; + _idFreeArray[index] = true; +}; diff --git a/PowerEditor/src/lastRecentFileList.h b/PowerEditor/src/lastRecentFileList.h new file mode 100644 index 00000000..8f1c039a --- /dev/null +++ b/PowerEditor/src/lastRecentFileList.h @@ -0,0 +1,74 @@ +#ifndef LASTRECENTFILELIST_H +#define LASTRECENTFILELIST_H + +#include +#include +#include "windows.h" +#include "Parameters.h" + +struct RecentItem { + int _id; + std::generic_string _name; + RecentItem(const TCHAR * name) : _name(name) {}; +}; + +typedef std::deque recentList; + +class LastRecentFileList +{ +public : + LastRecentFileList() : _hasSeparators(false), _size(0), _locked(false) { + _userMax = (NppParameters::getInstance())->getNbMaxFile(); + }; + + void initMenu(HMENU hMenu, int idBase, int posBase); + + void updateMenu(); + + void add(const TCHAR *fn); + void remove(const TCHAR *fn); + void remove(int index); + void clear(); + + int getSize() { + return _size; + }; + + int getMaxNbLRF() const { + return NB_MAX_LRF_FILE; + }; + + int getUserMaxNbLRF() const { + return _userMax; + }; + + std::generic_string & getItem(int id); //use menu id + std::generic_string & getIndex(int index); //use menu id + + void setUserMaxNbLRF(int size); + + void saveLRFL(); + + void setLock(bool lock) { + _locked = lock; + }; +private: + recentList _lrfl; + int _userMax; + int _size; + + // For the menu + HMENU _hMenu; + int _posBase; + int _idBase; + bool _idFreeArray[NB_MAX_LRF_FILE]; + bool _hasSeparators; + bool _locked; + + int find(const TCHAR *fn); + + int popFirstAvailableID(); + void setAvailable(int id); +}; + +#endif //LASTRECENTFILELIST_H diff --git a/PowerEditor/src/lesDlgs.h b/PowerEditor/src/lesDlgs.h new file mode 100644 index 00000000..8eb4d933 --- /dev/null +++ b/PowerEditor/src/lesDlgs.h @@ -0,0 +1,131 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO < donho@altern.org > +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef SIZE_DLG_H +#define SIZE_DLG_H + +#include "StaticDialog.h" +const int DEFAULT_NB_NUMBER = 2; +class ValueDlg : public StaticDialog +{ +public : + ValueDlg() : StaticDialog(), _nbNumber(DEFAULT_NB_NUMBER) {}; + void init(HINSTANCE hInst, HWND parent, int valueToSet, const TCHAR *text) { + Window::init(hInst, parent); + _defaultValue = valueToSet; + lstrcpy(_name, text); + }; + + int doDialog(POINT p, bool isRTL = false) { + _p = p; + if (isRTL) + { + DLGTEMPLATE *pMyDlgTemplate = NULL; + HGLOBAL hMyDlgTemplate = makeRTLResource(IDD_VALUE_DLG, &pMyDlgTemplate); + int result = ::DialogBoxIndirectParam(_hInst, pMyDlgTemplate, _hParent, (DLGPROC)dlgProc, (LPARAM)this); + ::GlobalFree(hMyDlgTemplate); + return result; + } + return ::DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_VALUE_DLG), _hParent, (DLGPROC)dlgProc, (LPARAM)this); + }; + + void setNBNumber(int nbNumber) { + if (nbNumber > 0) + _nbNumber = nbNumber; + }; + + int reSizeValueBox() + { + if (_nbNumber == DEFAULT_NB_NUMBER) return 0; + RECT rect; + POINT p; + + HWND hEdit = ::GetDlgItem(_hSelf, IDC_VALUE_EDIT); + + //get screen coordonnees (x,y) + ::GetWindowRect(hEdit, &rect); + int w = rect.right - rect.left; + int h = rect.bottom - rect.top; + + p.x = rect.left; + p.y = rect.top; + + // convert screen coordonnees to client coordonnees + ::ScreenToClient(_hSelf, &p); + + int unit = w / (DEFAULT_NB_NUMBER + 2); + int extraSize = (_nbNumber-DEFAULT_NB_NUMBER)*unit; + ::MoveWindow(hEdit, p.x, p.y, w + extraSize, h, FALSE); + + return extraSize; + }; + + virtual void destroy() {}; + +protected : + BOOL CALLBACK run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam) { + + switch (Message) + { + case WM_INITDIALOG : + { + ::SetDlgItemText(_hSelf, IDC_VALUE_STATIC, _name); + ::SetDlgItemInt(_hSelf, IDC_VALUE_EDIT, _defaultValue, FALSE); + + RECT rc; + ::GetClientRect(_hSelf, &rc); + int size = reSizeValueBox(); + ::MoveWindow(_hSelf, _p.x, _p.y, rc.right - rc.left + size, rc.bottom - rc.top + 30, TRUE); + + return TRUE; + } + + case WM_COMMAND : + { + switch (wParam) + { + case IDOK : + { + int i = ::GetDlgItemInt(_hSelf, IDC_VALUE_EDIT, NULL, FALSE); + ::EndDialog(_hSelf, i); + return TRUE; + } + + case IDCANCEL : + ::EndDialog(_hSelf, -1); + return TRUE; + + default: + return FALSE; + } + } + default : + return FALSE; + } + + return FALSE; + }; + +private : + int _nbNumber; + int _defaultValue; + TCHAR _name[32]; + POINT _p; + +}; + +#endif //TABSIZE_DLG_H diff --git a/PowerEditor/src/localizationString.h b/PowerEditor/src/localizationString.h new file mode 100644 index 00000000..45c21bec Binary files /dev/null and b/PowerEditor/src/localizationString.h differ diff --git a/PowerEditor/src/menuCmdID.h b/PowerEditor/src/menuCmdID.h new file mode 100644 index 00000000..1d6641ae --- /dev/null +++ b/PowerEditor/src/menuCmdID.h @@ -0,0 +1,307 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef MENUCMDID_H +#define MENUCMDID_H + +#define IDM 40000 + +#define IDM_FILE (IDM + 1000) + #define IDM_FILE_NEW (IDM_FILE + 1) + #define IDM_FILE_OPEN (IDM_FILE + 2) + #define IDM_FILE_CLOSE (IDM_FILE + 3) + #define IDM_FILE_CLOSEALL (IDM_FILE + 4) + #define IDM_FILE_CLOSEALL_BUT_CURRENT (IDM_FILE + 5) + #define IDM_FILE_SAVE (IDM_FILE + 6) + #define IDM_FILE_SAVEALL (IDM_FILE + 7) + #define IDM_FILE_SAVEAS (IDM_FILE + 8) + #define IDM_FILE_ASIAN_LANG (IDM_FILE + 9) + #define IDM_FILE_PRINT (IDM_FILE + 10) + #define IDM_FILE_PRINTNOW 1001 + #define IDM_FILE_EXIT (IDM_FILE + 11) + #define IDM_FILE_LOADSESSION (IDM_FILE + 12) + #define IDM_FILE_SAVESESSION (IDM_FILE + 13) + #define IDM_FILE_RELOAD (IDM_FILE + 14) + #define IDM_FILE_SAVECOPYAS (IDM_FILE + 15) + #define IDM_FILE_DELETE (IDM_FILE + 16) + #define IDM_FILE_RENAME (IDM_FILE + 17) + + // A mettre à jour si on ajoute nouveau menu item dans le menu "File" + #define IDM_FILEMENU_LASTONE IDM_FILE_RENAME + +#define IDM_EDIT (IDM + 2000) + #define IDM_EDIT_CUT (IDM_EDIT + 1) + #define IDM_EDIT_COPY (IDM_EDIT + 2) + #define IDM_EDIT_UNDO (IDM_EDIT + 3) + #define IDM_EDIT_REDO (IDM_EDIT + 4) + #define IDM_EDIT_PASTE (IDM_EDIT + 5) + #define IDM_EDIT_DELETE (IDM_EDIT + 6) + #define IDM_EDIT_SELECTALL (IDM_EDIT + 7) + + #define IDM_EDIT_INS_TAB (IDM_EDIT + 8) + #define IDM_EDIT_RMV_TAB (IDM_EDIT + 9) + #define IDM_EDIT_DUP_LINE (IDM_EDIT + 10) + #define IDM_EDIT_TRANSPOSE_LINE (IDM_EDIT + 11) + #define IDM_EDIT_SPLIT_LINES (IDM_EDIT + 12) + #define IDM_EDIT_JOIN_LINES (IDM_EDIT + 13) + #define IDM_EDIT_LINE_UP (IDM_EDIT + 14) + #define IDM_EDIT_LINE_DOWN (IDM_EDIT + 15) + #define IDM_EDIT_UPPERCASE (IDM_EDIT + 16) + #define IDM_EDIT_LOWERCASE (IDM_EDIT + 17) + + #define IDM_EDIT_BLOCK_COMMENT (IDM_EDIT + 22) + #define IDM_EDIT_STREAM_COMMENT (IDM_EDIT + 23) + #define IDM_EDIT_TRIMTRAILING (IDM_EDIT + 24) + + #define IDM_EDIT_RTL (IDM_EDIT+26) + #define IDM_EDIT_LTR (IDM_EDIT+27) + #define IDM_EDIT_SETREADONLY (IDM_EDIT+28) + #define IDM_EDIT_FULLPATHTOCLIP (IDM_EDIT+29) + #define IDM_EDIT_FILENAMETOCLIP (IDM_EDIT+30) + #define IDM_EDIT_CURRENTDIRTOCLIP (IDM_EDIT+31) + + #define IDM_EDIT_CLEARREADONLY (IDM_EDIT+33) + #define IDM_EDIT_COLUMNMODE (IDM_EDIT+34) + #define IDM_EDIT_BLOCK_COMMENT_SET (IDM_EDIT+35) + #define IDM_EDIT_BLOCK_UNCOMMENT (IDM_EDIT+36) + + #define IDM_EDIT_AUTOCOMPLETE (50000+0) + #define IDM_EDIT_AUTOCOMPLETE_CURRENTFILE (50000+1) + #define IDM_EDIT_FUNCCALLTIP (50000+2) + + //Belong to MENU FILE + #define IDM_OPEN_ALL_RECENT_FILE (IDM_EDIT + 40) + #define IDM_CLEAN_RECENT_FILE_LIST (IDM_EDIT + 41) + +#define IDM_SEARCH (IDM + 3000) + + #define IDM_SEARCH_FIND (IDM_SEARCH + 1) + #define IDM_SEARCH_FINDNEXT (IDM_SEARCH + 2) + #define IDM_SEARCH_REPLACE (IDM_SEARCH + 3) + #define IDM_SEARCH_GOTOLINE (IDM_SEARCH + 4) + #define IDM_SEARCH_TOGGLE_BOOKMARK (IDM_SEARCH + 5) + #define IDM_SEARCH_NEXT_BOOKMARK (IDM_SEARCH + 6) + #define IDM_SEARCH_PREV_BOOKMARK (IDM_SEARCH + 7) + #define IDM_SEARCH_CLEAR_BOOKMARKS (IDM_SEARCH + 8) + #define IDM_SEARCH_GOTOMATCHINGBRACE (IDM_SEARCH + 9) + #define IDM_SEARCH_FINDPREV (IDM_SEARCH + 10) + #define IDM_SEARCH_FINDINCREMENT (IDM_SEARCH + 11) + #define IDM_SEARCH_FINDINFILES (IDM_SEARCH + 13) + #define IDM_SEARCH_VOLATILE_FINDNEXT (IDM_SEARCH + 14) + #define IDM_SEARCH_VOLATILE_FINDPREV (IDM_SEARCH + 15) + #define IDM_SEARCH_CUTMARKEDLINES (IDM_SEARCH + 18) + #define IDM_SEARCH_COPYMARKEDLINES (IDM_SEARCH + 19) + #define IDM_SEARCH_PASTEMARKEDLINES (IDM_SEARCH + 20) + #define IDM_SEARCH_DELETEMARKEDLINES (IDM_SEARCH + 21) + #define IDM_SEARCH_MARKALLEXT1 (IDM_SEARCH + 22) + #define IDM_SEARCH_UNMARKALLEXT1 (IDM_SEARCH + 23) + #define IDM_SEARCH_MARKALLEXT2 (IDM_SEARCH + 24) + #define IDM_SEARCH_UNMARKALLEXT2 (IDM_SEARCH + 25) + #define IDM_SEARCH_MARKALLEXT3 (IDM_SEARCH + 26) + #define IDM_SEARCH_UNMARKALLEXT3 (IDM_SEARCH + 27) + #define IDM_SEARCH_MARKALLEXT4 (IDM_SEARCH + 28) + #define IDM_SEARCH_UNMARKALLEXT4 (IDM_SEARCH + 29) + #define IDM_SEARCH_MARKALLEXT5 (IDM_SEARCH + 30) + #define IDM_SEARCH_UNMARKALLEXT5 (IDM_SEARCH + 31) + #define IDM_SEARCH_CLEARALLMARKS (IDM_SEARCH + 32) + +#define IDM_VIEW (IDM + 4000) + //#define IDM_VIEW_TOOLBAR_HIDE (IDM_VIEW + 1) + #define IDM_VIEW_TOOLBAR_REDUCE (IDM_VIEW + 2) + #define IDM_VIEW_TOOLBAR_ENLARGE (IDM_VIEW + 3) + #define IDM_VIEW_TOOLBAR_STANDARD (IDM_VIEW + 4) + #define IDM_VIEW_REDUCETABBAR (IDM_VIEW + 5) + #define IDM_VIEW_LOCKTABBAR (IDM_VIEW + 6) + #define IDM_VIEW_DRAWTABBAR_TOPBAR (IDM_VIEW + 7) + #define IDM_VIEW_DRAWTABBAR_INACIVETAB (IDM_VIEW + 8) + #define IDM_VIEW_POSTIT (IDM_VIEW + 9) + #define IDM_VIEW_TOGGLE_FOLDALL (IDM_VIEW + 10) + #define IDM_VIEW_USER_DLG (IDM_VIEW + 11) + #define IDM_VIEW_LINENUMBER (IDM_VIEW + 12) + #define IDM_VIEW_SYMBOLMARGIN (IDM_VIEW + 13) + #define IDM_VIEW_FOLDERMAGIN (IDM_VIEW + 14) + #define IDM_VIEW_FOLDERMAGIN_SIMPLE (IDM_VIEW + 15) + #define IDM_VIEW_FOLDERMAGIN_ARROW (IDM_VIEW + 16) + #define IDM_VIEW_FOLDERMAGIN_CIRCLE (IDM_VIEW + 17) + #define IDM_VIEW_FOLDERMAGIN_BOX (IDM_VIEW + 18) + #define IDM_VIEW_ALL_CHARACTERS (IDM_VIEW + 19) + #define IDM_VIEW_INDENT_GUIDE (IDM_VIEW + 20) + #define IDM_VIEW_CURLINE_HILITING (IDM_VIEW + 21) + #define IDM_VIEW_WRAP (IDM_VIEW + 22) + #define IDM_VIEW_ZOOMIN (IDM_VIEW + 23) + #define IDM_VIEW_ZOOMOUT (IDM_VIEW + 24) + #define IDM_VIEW_TAB_SPACE (IDM_VIEW + 25) + #define IDM_VIEW_EOL (IDM_VIEW + 26) + #define IDM_VIEW_EDGELINE (IDM_VIEW + 27) + #define IDM_VIEW_EDGEBACKGROUND (IDM_VIEW + 28) + #define IDM_VIEW_TOGGLE_UNFOLDALL (IDM_VIEW + 29) + #define IDM_VIEW_FOLD_CURRENT (IDM_VIEW + 30) + #define IDM_VIEW_UNFOLD_CURRENT (IDM_VIEW + 31) + #define IDM_VIEW_FULLSCREENTOGGLE (IDM_VIEW + 32) + #define IDM_VIEW_ZOOMRESTORE (IDM_VIEW + 33) + #define IDM_VIEW_ALWAYSONTOP (IDM_VIEW + 34) + #define IDM_VIEW_SYNSCROLLV (IDM_VIEW + 35) + #define IDM_VIEW_SYNSCROLLH (IDM_VIEW + 36) + #define IDM_VIEW_EDGENONE (IDM_VIEW + 37) + #define IDM_VIEW_DRAWTABBAR_CLOSEBOTTUN (IDM_VIEW + 38) + #define IDM_VIEW_DRAWTABBAR_DBCLK2CLOSE (IDM_VIEW + 39) + #define IDM_VIEW_REFRESHTABAR (IDM_VIEW + 40) + #define IDM_VIEW_WRAP_SYMBOL (IDM_VIEW + 41) + #define IDM_VIEW_HIDELINES (IDM_VIEW + 42) + #define IDM_VIEW_DRAWTABBAR_VERTICAL (IDM_VIEW + 43) + #define IDM_VIEW_DRAWTABBAR_MULTILINE (IDM_VIEW + 44) + #define IDM_VIEW_DOCCHANGEMARGIN (IDM_VIEW + 45) + + + #define IDM_VIEW_FOLD (IDM_VIEW + 50) + #define IDM_VIEW_FOLD_1 (IDM_VIEW_FOLD + 1) + #define IDM_VIEW_FOLD_2 (IDM_VIEW_FOLD + 2) + #define IDM_VIEW_FOLD_3 (IDM_VIEW_FOLD + 3) + #define IDM_VIEW_FOLD_4 (IDM_VIEW_FOLD + 4) + #define IDM_VIEW_FOLD_5 (IDM_VIEW_FOLD + 5) + #define IDM_VIEW_FOLD_6 (IDM_VIEW_FOLD + 6) + #define IDM_VIEW_FOLD_7 (IDM_VIEW_FOLD + 7) + #define IDM_VIEW_FOLD_8 (IDM_VIEW_FOLD + 8) + + #define IDM_VIEW_UNFOLD (IDM_VIEW + 60) + #define IDM_VIEW_UNFOLD_1 (IDM_VIEW_UNFOLD + 1) + #define IDM_VIEW_UNFOLD_2 (IDM_VIEW_UNFOLD + 2) + #define IDM_VIEW_UNFOLD_3 (IDM_VIEW_UNFOLD + 3) + #define IDM_VIEW_UNFOLD_4 (IDM_VIEW_UNFOLD + 4) + #define IDM_VIEW_UNFOLD_5 (IDM_VIEW_UNFOLD + 5) + #define IDM_VIEW_UNFOLD_6 (IDM_VIEW_UNFOLD + 6) + #define IDM_VIEW_UNFOLD_7 (IDM_VIEW_UNFOLD + 7) + #define IDM_VIEW_UNFOLD_8 (IDM_VIEW_UNFOLD + 8) + + + #define IDM_VIEW_GOTO_ANOTHER_VIEW 10001 + #define IDM_VIEW_CLONE_TO_ANOTHER_VIEW 10002 + #define IDM_VIEW_GOTO_NEW_INSTANCE 10003 + #define IDM_VIEW_LOAD_IN_NEW_INSTANCE 10004 + + #define IDM_VIEW_SWITCHTO_OTHER_VIEW (IDM_VIEW + 72) + + +#define IDM_FORMAT (IDM + 5000) + #define IDM_FORMAT_TODOS (IDM_FORMAT + 1) + #define IDM_FORMAT_TOUNIX (IDM_FORMAT + 2) + #define IDM_FORMAT_TOMAC (IDM_FORMAT + 3) + #define IDM_FORMAT_ANSI (IDM_FORMAT + 4) + #define IDM_FORMAT_UTF_8 (IDM_FORMAT + 5) + #define IDM_FORMAT_UCS_2BE (IDM_FORMAT + 6) + #define IDM_FORMAT_UCS_2LE (IDM_FORMAT + 7) + #define IDM_FORMAT_AS_UTF_8 (IDM_FORMAT + 8) + #define IDM_FORMAT_CONV2_ANSI (IDM_FORMAT + 9) + #define IDM_FORMAT_CONV2_AS_UTF_8 (IDM_FORMAT + 10) + #define IDM_FORMAT_CONV2_UTF_8 (IDM_FORMAT + 11) + #define IDM_FORMAT_CONV2_UCS_2BE (IDM_FORMAT + 12) + #define IDM_FORMAT_CONV2_UCS_2LE (IDM_FORMAT + 13) + +#define IDM_LANG (IDM + 6000) + #define IDM_LANGSTYLE_CONFIG_DLG (IDM_LANG + 1) + #define IDM_LANG_C (IDM_LANG + 2) + #define IDM_LANG_CPP (IDM_LANG + 3) + #define IDM_LANG_JAVA (IDM_LANG + 4) + #define IDM_LANG_HTML (IDM_LANG + 5) + #define IDM_LANG_XML (IDM_LANG + 6) + #define IDM_LANG_JS (IDM_LANG + 7) + #define IDM_LANG_PHP (IDM_LANG + 8) + #define IDM_LANG_ASP (IDM_LANG + 9) + #define IDM_LANG_CSS (IDM_LANG + 10) + #define IDM_LANG_PASCAL (IDM_LANG + 11) + #define IDM_LANG_PYTHON (IDM_LANG + 12) + #define IDM_LANG_PERL (IDM_LANG + 13) + #define IDM_LANG_OBJC (IDM_LANG + 14) + #define IDM_LANG_ASCII (IDM_LANG + 15) + #define IDM_LANG_TEXT (IDM_LANG + 16) + #define IDM_LANG_RC (IDM_LANG + 17) + #define IDM_LANG_MAKEFILE (IDM_LANG + 18) + #define IDM_LANG_INI (IDM_LANG + 19) + #define IDM_LANG_SQL (IDM_LANG + 20) + #define IDM_LANG_VB (IDM_LANG + 21) + #define IDM_LANG_BATCH (IDM_LANG + 22) + #define IDM_LANG_CS (IDM_LANG + 23) + #define IDM_LANG_LUA (IDM_LANG + 24) + #define IDM_LANG_TEX (IDM_LANG + 25) + #define IDM_LANG_FORTRAN (IDM_LANG + 26) + #define IDM_LANG_SH (IDM_LANG + 27) + #define IDM_LANG_FLASH (IDM_LANG + 28) + #define IDM_LANG_NSIS (IDM_LANG + 29) + #define IDM_LANG_TCL (IDM_LANG + 30) + #define IDM_LANG_LISP (IDM_LANG + 31) + #define IDM_LANG_SCHEME (IDM_LANG + 32) + #define IDM_LANG_ASM (IDM_LANG + 33) + #define IDM_LANG_DIFF (IDM_LANG + 34) + #define IDM_LANG_PROPS (IDM_LANG + 35) + #define IDM_LANG_PS (IDM_LANG + 36) + #define IDM_LANG_RUBY (IDM_LANG + 37) + #define IDM_LANG_SMALLTALK (IDM_LANG + 38) + #define IDM_LANG_VHDL (IDM_LANG + 39) + #define IDM_LANG_CAML (IDM_LANG + 40) + #define IDM_LANG_KIX (IDM_LANG + 41) + #define IDM_LANG_ADA (IDM_LANG + 42) + #define IDM_LANG_VERILOG (IDM_LANG + 43) + #define IDM_LANG_AU3 (IDM_LANG + 44) + #define IDM_LANG_MATLAB (IDM_LANG + 45) + #define IDM_LANG_HASKELL (IDM_LANG + 46) + #define IDM_LANG_INNO (IDM_LANG + 47) + #define IDM_LANG_CMAKE (IDM_LANG + 48) + #define IDM_LANG_YAML (IDM_LANG + 49) + + #define IDM_LANG_EXTERNAL (IDM_LANG + 50) + #define IDM_LANG_EXTERNAL_LIMIT (IDM_LANG + 79) + + #define IDM_LANG_USER (IDM_LANG + 80) //46080 + #define IDM_LANG_USER_LIMIT (IDM_LANG + 110) //46110 + + +#define IDM_ABOUT (IDM + 7000) + #define IDM_HOMESWEETHOME (IDM_ABOUT + 1) + #define IDM_PROJECTPAGE (IDM_ABOUT + 2) + #define IDM_ONLINEHELP (IDM_ABOUT + 3) + #define IDM_FORUM (IDM_ABOUT + 4) + #define IDM_PLUGINSHOME (IDM_ABOUT + 5) + #define IDM_UPDATE_NPP (IDM_ABOUT + 6) + #define IDM_WIKIFAQ (IDM_ABOUT + 7) + #define IDM_HELP (IDM_ABOUT + 8) + + +#define IDM_SETTING (IDM + 8000) + #define IDM_SETTING_TAB_SIZE (IDM_SETTING + 1) + #define IDM_SETTING_TAB_REPLCESPACE (IDM_SETTING + 2) + #define IDM_SETTING_HISTORY_SIZE (IDM_SETTING + 3) + #define IDM_SETTING_EDGE_SIZE (IDM_SETTING + 4) + #define IDM_SETTING_FILEASSOCIATION_DLG (IDM_SETTING + 5) + + #define IDM_SETTING_HISTORY_DONT_CHECK (IDM_SETTING + 7) + #define IDM_SETTING_TRAYICON (IDM_SETTING + 8) + #define IDM_SETTING_SHORTCUT_MAPPER (IDM_SETTING + 9) + #define IDM_SETTING_REMEMBER_LAST_SESSION (IDM_SETTING + 10) + #define IDM_SETTING_PREFERECE (IDM_SETTING + 11) + + #define IDM_SETTING_AUTOCNBCHAR (IDM_SETTING + 15) + +// Menu macro + #define IDM_MACRO_STARTRECORDINGMACRO (IDM_EDIT + 18) + #define IDM_MACRO_STOPRECORDINGMACRO (IDM_EDIT + 19) + #define IDM_MACRO_PLAYBACKRECORDEDMACRO (IDM_EDIT + 21) + #define IDM_MACRO_SAVECURRENTMACRO (IDM_EDIT + 25) + #define IDM_MACRO_RUNMULTIMACRODLG (IDM_EDIT+32) + +#define IDM_EXECUTE (IDM + 9000) + +#endif //MENUCMDID_H diff --git a/PowerEditor/src/notepad++.exe.manifest b/PowerEditor/src/notepad++.exe.manifest new file mode 100644 index 00000000..c80f5855 --- /dev/null +++ b/PowerEditor/src/notepad++.exe.manifest @@ -0,0 +1,32 @@ + + + +Notepad++ + + + + + + + + + + + + + \ No newline at end of file diff --git a/PowerEditor/src/resource.h b/PowerEditor/src/resource.h new file mode 100644 index 00000000..dac1c87d --- /dev/null +++ b/PowerEditor/src/resource.h @@ -0,0 +1,375 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#ifndef RESOURCE_H +#define RESOURCE_H + +#define NOTEPAD_PLUS_VERSION TEXT("Notepad++ v5.3.1") +#define VERSION_VALUE TEXT("5.31\0") // should be X.Y : ie. if VERSION_DIGITALVALUE == 4, 7, 1, 0 , then X = 4, Y = 71 +#define VERSION_DIGITALVALUE 5, 3, 1, 0 + +#ifdef UNICODE +#define UNICODE_ANSI_MODE TEXT("(UNICODE)") +#else +#define UNICODE_ANSI_MODE TEXT("(ANSI)") +#endif + +#ifndef IDC_STATIC +#define IDC_STATIC -1 +#endif + +#define IDI_M30ICON 100 +#define IDR_MENU1 101 +#define IDR_RT_MANIFEST 103 + +#define IDI_NEW_OFF_ICON 201 +#define IDI_OPEN_OFF_ICON 202 +#define IDI_CLOSE_OFF_ICON 203 +#define IDI_CLOSEALL_OFF_ICON 204 +#define IDI_SAVE_OFF_ICON 205 +#define IDI_SAVEALL_OFF_ICON 206 +#define IDI_CUT_OFF_ICON 207 +#define IDI_COPY_OFF_ICON 208 +#define IDI_PASTE_OFF_ICON 209 +#define IDI_UNDO_OFF_ICON 210 +#define IDI_REDO_OFF_ICON 211 +#define IDI_FIND_OFF_ICON 212 +#define IDI_REPLACE_OFF_ICON 213 +#define IDI_ZOOMIN_OFF_ICON 214 +#define IDI_ZOOMOUT_OFF_ICON 215 +#define IDI_VIEW_UD_DLG_OFF_ICON 216 +#define IDI_PRINT_OFF_ICON 217 +#define IDI_VIEW_ALL_CHAR_ON_ICON 218 +#define IDI_VIEW_INDENT_ON_ICON 219 +#define IDI_VIEW_WRAP_ON_ICON 220 + +#define IDI_STARTRECORD_OFF_ICON 221 +#define IDI_STARTRECORD_ON_ICON 222 +#define IDI_STARTRECORD_DISABLE_ICON 223 +#define IDI_STOPRECORD_OFF_ICON 224 +#define IDI_STOPRECORD_ON_ICON 225 +#define IDI_STOPRECORD_DISABLE_ICON 226 +#define IDI_PLAYRECORD_OFF_ICON 227 +#define IDI_PLAYRECORD_ON_ICON 228 +#define IDI_PLAYRECORD_DISABLE_ICON 229 +#define IDI_SAVERECORD_OFF_ICON 230 +#define IDI_SAVERECORD_ON_ICON 231 +#define IDI_SAVERECORD_DISABLE_ICON 232 + +// multi run macro +#define IDI_MMPLAY_DIS_ICON 233 +#define IDI_MMPLAY_OFF_ICON 234 +#define IDI_MMPLAY_ON_ICON 235 + +#define IDI_NEW_ON_ICON 301 +#define IDI_OPEN_ON_ICON 302 +#define IDI_CLOSE_ON_ICON 303 +#define IDI_CLOSEALL_ON_ICON 304 +#define IDI_SAVE_ON_ICON 305 +#define IDI_SAVEALL_ON_ICON 306 +#define IDI_CUT_ON_ICON 307 +#define IDI_COPY_ON_ICON 308 +#define IDI_PASTE_ON_ICON 309 +#define IDI_UNDO_ON_ICON 310 +#define IDI_REDO_ON_ICON 311 +#define IDI_FIND_ON_ICON 312 +#define IDI_REPLACE_ON_ICON 313 +#define IDI_ZOOMIN_ON_ICON 314 +#define IDI_ZOOMOUT_ON_ICON 315 +#define IDI_VIEW_UD_DLG_ON_ICON 316 +#define IDI_PRINT_ON_ICON 317 +#define IDI_VIEW_ALL_CHAR_OFF_ICON 318 +#define IDI_VIEW_INDENT_OFF_ICON 319 +#define IDI_VIEW_WRAP_OFF_ICON 320 + +//#define IDI_NEW_DISABLE_ICON 401 +//#define IDI_OPEN_ON_ICON 402 +#define IDI_SAVE_DISABLE_ICON 403 +#define IDI_SAVEALL_DISABLE_ICON 404 +//#define IDI_CLOSE_ON_ICON 405 +//#define IDI_CLOSEALL_ON_ICON 406 +#define IDI_CUT_DISABLE_ICON 407 +#define IDI_COPY_DISABLE_ICON 408 +#define IDI_PASTE_DISABLE_ICON 409 +#define IDI_UNDO_DISABLE_ICON 410 +#define IDI_REDO_DISABLE_ICON 411 +#define IDI_DELETE_ICON 412 + +#define IDI_SYNCV_OFF_ICON 413 +#define IDI_SYNCV_ON_ICON 414 +#define IDI_SYNCV_DISABLE_ICON 415 + +#define IDI_SYNCH_OFF_ICON 416 +#define IDI_SYNCH_ON_ICON 417 +#define IDI_SYNCH_DISABLE_ICON 418 + +#define IDI_SAVED_ICON 501 +#define IDI_UNSAVED_ICON 502 +#define IDI_READONLY_ICON 503 +#define IDI_FIND_RESULT_ICON 504 + +#define IDC_MY_CUR 1402 +#define IDC_UP_ARROW 1403 +#define IDC_DRAG_TAB 1404 +#define IDC_DRAG_INTERDIT_TAB 1405 +#define IDC_DRAG_PLUS_TAB 1406 +#define IDC_DRAG_OUT_TAB 1407 + +#define IDC_MACRO_RECORDING 1408 + +#define IDR_SAVEALL 1500 +#define IDR_CLOSEFILE 1501 +#define IDR_CLOSEALL 1502 +#define IDR_FIND 1503 +#define IDR_REPLACE 1504 +#define IDR_ZOOMIN 1505 +#define IDR_ZOOMOUT 1506 +#define IDR_WRAP 1507 +#define IDR_INVISIBLECHAR 1508 +#define IDR_INDENTGUIDE 1509 +#define IDR_SHOWPANNEL 1510 +#define IDR_STARTRECORD 1511 +#define IDR_STOPRECORD 1512 +#define IDR_PLAYRECORD 1513 +#define IDR_SAVERECORD 1514 +#define IDR_SYNCV 1515 +#define IDR_SYNCH 1516 +#define IDR_FILENEW 1517 +#define IDR_FILEOPEN 1518 +#define IDR_FILESAVE 1519 +#define IDR_PRINT 1520 +#define IDR_CUT 1521 +#define IDR_COPY 1522 +#define IDR_PASTE 1523 +#define IDR_UNDO 1524 +#define IDR_REDO 1525 +#define IDR_M_PLAYRECORD 1526 + +#define IDR_CLOSETAB 1530 +#define IDR_CLOSETAB_INACT 1531 +#define IDR_CLOSETAB_HOVER 1532 +#define IDR_CLOSETAB_PUSH 1533 + +#define ID_MACRO 20000 +#define ID_MACRO_LIMIT 20200 + +#define ID_USER_CMD 21000 +#define ID_USER_CMD_LIMIT 21200 + +#define ID_PLUGINS_CMD 22000 +#define ID_PLUGINS_CMD_LIMIT 22500 + +//#define IDM 40000 + +#define IDCMD 50000 + //#define IDM_EDIT_AUTOCOMPLETE (IDCMD+0) + //#define IDM_EDIT_AUTOCOMPLETE_CURRENTFILE (IDCMD+1) + + #define IDC_PREV_DOC (IDCMD+3) + #define IDC_NEXT_DOC (IDCMD+4) + #define IDC_EDIT_TOGGLEMACRORECORDING (IDCMD+5) + //#define IDC_KEY_HOME (IDCMD+6) + //#define IDC_KEY_END (IDCMD+7) + //#define IDC_KEY_SELECT_2_HOME (IDCMD+8) + //#define IDC_KEY_SELECT_2_END (IDCMD+9) + +#define IDCMD_LIMIT (IDCMD+20) + +#define IDSCINTILLA 60000 + #define IDSCINTILLA_KEY_HOME (IDSCINTILLA+0) + #define IDSCINTILLA_KEY_HOME_WRAP (IDSCINTILLA+1) + #define IDSCINTILLA_KEY_END (IDSCINTILLA+2) + #define IDSCINTILLA_KEY_END_WRAP (IDSCINTILLA+3) + #define IDSCINTILLA_KEY_LINE_DUP (IDSCINTILLA+4) + #define IDSCINTILLA_KEY_LINE_CUT (IDSCINTILLA+5) + #define IDSCINTILLA_KEY_LINE_DEL (IDSCINTILLA+6) + #define IDSCINTILLA_KEY_LINE_TRANS (IDSCINTILLA+7) + #define IDSCINTILLA_KEY_LINE_COPY (IDSCINTILLA+8) + #define IDSCINTILLA_KEY_CUT (IDSCINTILLA+9) + #define IDSCINTILLA_KEY_COPY (IDSCINTILLA+10) + #define IDSCINTILLA_KEY_PASTE (IDSCINTILLA+11) + #define IDSCINTILLA_KEY_DEL (IDSCINTILLA+12) + #define IDSCINTILLA_KEY_SELECTALL (IDSCINTILLA+13) + #define IDSCINTILLA_KEY_OUTDENT (IDSCINTILLA+14) + #define IDSCINTILLA_KEY_UNDO (IDSCINTILLA+15) + #define IDSCINTILLA_KEY_REDO (IDSCINTILLA+16) +#define IDSCINTILLA_LIMIT (IDSCINTILLA+30) + +#define IDD_FILEVIEW_DIALOG 1000 + +#define IDC_MINIMIZED_TRAY 67001 + +#define IDD_CREATE_DIRECTORY 1100 +#define IDC_STATIC_CURRENT_FOLDER 1101 +#define IDC_EDIT_NEW_FOLDER 1102 + +#define IDD_INSERT_INPUT_TEXT 1200 +#define IDC_EDIT_INPUT_VALUE 1201 +#define IDC_STATIC_INPUT_TITLE 1202 +#define IDC_ICON_INPUT_ICON 1203 + +#define IDR_M30_MENU 1500 + +// #define IDD_FIND_REPLACE_DLG 1600 + +#define IDD_ABOUTBOX 1700 +#define IDC_LICENCE_EDIT 1701 +#define IDC_HOME_ADDR 1702 +#define IDC_EMAIL_ADDR 1703 +#define IDC_ONLINEHELP_ADDR 1704 +#define IDC_AUTHOR_NAME 1705 +#define IDC_BUILD_DATETIME 1706 //LS: CompileDateInAboutDialog: Automatically insert compile date as additional version info in About-dialog! +//#define IDD_USER_DEFINE_BOX 1800 + +//#define IDD_RUN_DLG 1900 + +#define IDD_GOLINE 2000 +#define ID_GOLINE_EDIT (IDD_GOLINE + 1) +#define ID_CURRLINE (IDD_GOLINE + 2) +#define ID_LASTLINE (IDD_GOLINE + 3) +#define ID_URHERE_STATIC (IDD_GOLINE + 4) +#define ID_UGO_STATIC (IDD_GOLINE + 5) +#define ID_NOMORETHAN_STATIC (IDD_GOLINE + 6) +#define IDC_RADIO_GOTOLINE (IDD_GOLINE + 7) +#define IDC_RADIO_GOTOOFFSET (IDD_GOLINE + 8) + +// voir columnEditor_rc.h +//#define IDD_COLUMNEDIT 2020 + + +//#define IDD_COLOUR_POPUP 2100 + +// See WordStyleDlgRes.h +//#define IDD_STYLER_DLG 2200 +//#define IDD_GLOBAL_STYLER_DLG 2300 + +#define IDD_VALUE_DLG 2400 +#define IDC_VALUE_STATIC 2401 +#define IDC_VALUE_EDIT 2402 + +// see TaskListDlg_rc.h +//#define IDD_TASKLIST_DLG 2450 +#define IDD_SETTING_DLG 2500 + +//See ShortcutMapper_rc.h +//#define IDD_SHORTCUTMAPPER_DLG 2600 + +// See regExtDlg.h +//#define IDD_REGEXT 4000 + +// See shortcutRc.h +//#define IDD_SHORTCUT_DLG 5000 + +// See preference.rc +//#define IDD_PREFERENCE_BOX 6000 + +#define NOTEPADPLUS_USER_INTERNAL (WM_USER + 0000) + #define NPPM_INTERNAL_USERCMDLIST_MODIFIED (NOTEPADPLUS_USER_INTERNAL + 1) + #define NPPM_INTERNAL_CMDLIST_MODIFIED (NOTEPADPLUS_USER_INTERNAL + 2) + #define NPPM_INTERNAL_MACROLIST_MODIFIED (NOTEPADPLUS_USER_INTERNAL + 3) + #define NPPM_INTERNAL_PLUGINCMDLIST_MODIFIED (NOTEPADPLUS_USER_INTERNAL + 4) + #define NPPM_INTERNAL_CLEARSCINTILLAKEY (NOTEPADPLUS_USER_INTERNAL + 5) + #define NPPM_INTERNAL_BINDSCINTILLAKEY (NOTEPADPLUS_USER_INTERNAL + 6) + #define NPPM_INTERNAL_SCINTILLAKEYMODIFIED (NOTEPADPLUS_USER_INTERNAL + 7) + #define NPPM_INTERNAL_SCINTILLAFINFERCOLLAPSE (NOTEPADPLUS_USER_INTERNAL + 8) + #define NPPM_INTERNAL_SCINTILLAFINFERUNCOLLAPSE (NOTEPADPLUS_USER_INTERNAL + 9) + //#define NPPM_INTERNAL_DOCSWITCHOFF (NOTEPADPLUS_USER_INTERNAL + 10) + //#define NPPM_INTERNAL_DOCSWITCHIN (NOTEPADPLUS_USER_INTERNAL + 11) + #define NPPM_INTERNAL_ISTABBARREDUCED (NOTEPADPLUS_USER_INTERNAL + 12) + #define NPPM_INTERNAL_ISFOCUSEDTAB (NOTEPADPLUS_USER_INTERNAL + 13) + #define NPPM_INTERNAL_GETMENU (NOTEPADPLUS_USER_INTERNAL + 14) + #define NPPM_INTERNAL_CLEARINDICATOR (NOTEPADPLUS_USER_INTERNAL + 15) + #define NPPM_INTERNAL_SCINTILLAFINFERCOPY (NOTEPADPLUS_USER_INTERNAL + 16) + #define NPPM_INTERNAL_SCINTILLAFINFERSELECTALL (NOTEPADPLUS_USER_INTERNAL + 17) + #define NPPM_INTERNAL_SETCARETWIDTH (NOTEPADPLUS_USER_INTERNAL + 18) + #define NPPM_INTERNAL_SETCARETBLINKRATE (NOTEPADPLUS_USER_INTERNAL + 19) + #define NPPM_INTERNAL_CLEARINDICATORTAGMATCH (NOTEPADPLUS_USER_INTERNAL + 20) + #define NPPM_INTERNAL_CLEARINDICATORTAGATTR (NOTEPADPLUS_USER_INTERNAL + 21) + #define NPPM_INTERNAL_SWITCHVIEWFROMHWND (NOTEPADPLUS_USER_INTERNAL + 22) + #define NPPM_INTERNAL_UPDATETITLEBAR (NOTEPADPLUS_USER_INTERNAL + 23) + #define NPPM_INTERNAL_CANCEL_FIND_IN_FILES (NOTEPADPLUS_USER_INTERNAL + 24) + #define NPPM_INTERNAL_RELOADNATIVELANG (NOTEPADPLUS_USER_INTERNAL + 25) + #define NPPM_INTERNAL_PLUGINSHORTCUTMOTIFIED (NOTEPADPLUS_USER_INTERNAL + 26) + #define NPPM_INTERNAL_SCINTILLAFINFERCLEARALL (NOTEPADPLUS_USER_INTERNAL + 27) + #define NPPM_INTERNAL_SEARCH_GOTONEXTFOUND (NOTEPADPLUS_USER_INTERNAL + 28) + #define NPPM_INTERNAL_SEARCH_GOTOPREVFOUND (NOTEPADPLUS_USER_INTERNAL + 29) + #define NPPM_INTERNAL_FOCUS_ON_FOUND_RESULTS (NOTEPADPLUS_USER_INTERNAL + 30) + #define NPPM_INTERNAL_RELOADSTYLERS (NOTEPADPLUS_USER_INTERNAL + 31) + +// See Notepad_plus_msgs.h +//#define NOTEPADPLUS_USER (WM_USER + 1000) + + // + // Used by Doc Monitor plugin + // + #define NPPM_INTERNAL_CHECKDOCSTATUS (NPPMSG + 53) + // VOID NPPM_CHECKDOCSTATUS(BOOL, 0) + // check all opened documents status. + // If files are modified, then reloaod (with or without prompt, it depends on settings). + // if files are deleted, then prompt user to close the documents + + #define NPPM_INTERNAL_ENABLECHECKDOCOPT (NPPMSG + 54) + // VOID NPPM_ENABLECHECKDOCOPT(OPT, 0) + // where OPT is : + #define CHECKDOCOPT_NONE 0 + #define CHECKDOCOPT_UPDATESILENTLY 1 + #define CHECKDOCOPT_UPDATEGO2END 2 + + #define NPPM_INTERNAL_GETCHECKDOCOPT (NPPMSG + 55) + // INT NPPM_GETCHECKDOCOPT(0, 0) + #define NPPM_INTERNAL_SETCHECKDOCOPT (NPPMSG + 56) + // INT NPPM_SETCHECKDOCOPT(OPT, 0) + + // + // Used by netnote plugin + // + #define NPPM_INTERNAL_SETFILENAME (NPPMSG + 63) + //wParam: BufferID to rename + //lParam: name to set (TCHAR*) + //Buffer must have been previously unnamed (eg "new 1" document types) + +#define SCINTILLA_USER (WM_USER + 2000) + + +#define MACRO_USER (WM_USER + 4000) + #define WM_ISCURRENTMACRORECORDED (MACRO_USER + 01) + #define WM_MACRODLGRUNMACRO (MACRO_USER + 02) + + +// See Notepad_plus_msgs.h +//#define RUNCOMMAND_USER (WM_USER + 3000) +#define SPLITTER_USER (WM_USER + 4000) +#define WORDSTYLE_USER (WM_USER + 5000) +#define COLOURPOPUP_USER (WM_USER + 6000) +#define BABYGRID_USER (WM_USER + 7000) + +//#define IDD_DOCKING_MNG (IDM + 7000) + +#define MENUINDEX_FILE 0 +#define MENUINDEX_EDIT 1 +#define MENUINDEX_SEARCH 2 +#define MENUINDEX_VIEW 3 +#define MENUINDEX_FORMAT 4 +#define MENUINDEX_LANGUAGE 5 +#define MENUINDEX_SETTINGS 6 +#define MENUINDEX_MACRO 7 +#define MENUINDEX_RUN 8 +#define MENUINDEX_PLUGINS 9 + +#endif // RESOURCE_H + + diff --git a/PowerEditor/src/shortcuts.xml b/PowerEditor/src/shortcuts.xml new file mode 100644 index 00000000..c343f3c6 --- /dev/null +++ b/PowerEditor/src/shortcuts.xml @@ -0,0 +1,20 @@ + + + + + + + + + + firefox "$(FULL_CURRENT_PATH)" + iexplore "$(FULL_CURRENT_PATH)" + http://www.php.net/%20$(CURRENT_WORD) + http://www.google.com/search?q=$(CURRENT_WORD) + http://en.wikipedia.org/wiki/Special:Search?search=$(CURRENT_WORD) + $(NPP_DIRECTORY)\notepad++.exe $(CURRENT_WORD) + $(NPP_DIRECTORY)\notepad++.exe $(CURRENT_WORD) -nosession -multiInst + explorer $(CURRENT_DIRECTORY) + cmd /K cd $(CURRENT_DIRECTORY) + + diff --git a/PowerEditor/src/stylers.model.xml b/PowerEditor/src/stylers.model.xml new file mode 100644 index 00000000..e7dedf08 --- /dev/null +++ b/PowerEditor/src/stylers.model.xml @@ -0,0 +1,730 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PowerEditor/src/toolbarIcons.xml b/PowerEditor/src/toolbarIcons.xml new file mode 100644 index 00000000..1b3387ce --- /dev/null +++ b/PowerEditor/src/toolbarIcons.xml @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PowerEditor/src/tools/IExplorerShell/makefile b/PowerEditor/src/tools/IExplorerShell/makefile new file mode 100644 index 00000000..109e4a77 --- /dev/null +++ b/PowerEditor/src/tools/IExplorerShell/makefile @@ -0,0 +1,2 @@ +ALL: + gcc nppIExplorerShell.cpp -o nppIExplorerShell.exe -mwindows -lshlwapi -Os -s \ No newline at end of file diff --git a/PowerEditor/src/tools/IExplorerShell/nppIExplorerShell.cpp b/PowerEditor/src/tools/IExplorerShell/nppIExplorerShell.cpp new file mode 100644 index 00000000..8823f453 --- /dev/null +++ b/PowerEditor/src/tools/IExplorerShell/nppIExplorerShell.cpp @@ -0,0 +1,40 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#include +#include + +const int CMD_LEN = 512; +const int PARAM_LEN = 1024; +const char *NPP = "\\notepad++.exe"; +const char *FLAG_LEXER_HTML = "-lhtml "; + +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR lpszCmdLine, int nCmdShow) +{ + char cmd[CMD_LEN]; + ::GetModuleFileName(NULL, cmd, CMD_LEN); + PathRemoveFileSpec(cmd); + strcat(cmd, NPP); + + char param[PARAM_LEN] = ""; + + strcat(strcat(param, FLAG_LEXER_HTML), lpszCmdLine); + ::MessageBox(NULL, param, "", MB_OK); + HINSTANCE hInst = ::ShellExecute(NULL, "open", cmd, param, ".", SW_SHOW); + return (UINT)0; +} + diff --git a/PowerEditor/src/tools/nppCM/Makefile b/PowerEditor/src/tools/nppCM/Makefile new file mode 100644 index 00000000..2058468f --- /dev/null +++ b/PowerEditor/src/tools/nppCM/Makefile @@ -0,0 +1,24 @@ +TARGETOS = BOTH +!include + +lflags = /NODEFAULTLIB /INCREMENTAL:NO /RELEASE /NOLOGO +dlllflags = $(lflags) -entry:_DllMainCRTStartup$(DLLENTRY) -dll + +all: nppcm.dll + +nppcm.dll: nppcm.obj nppcm.res + $(implib) -machine:$(CPU) -def:nppcm.def $** -out:nppcm.lib + $(link) $(dlllflags) -base:0x1C000000 -out:$*.dll $** $(olelibsdll) shell32.lib nppcm.lib comctl32.lib nppcm.exp + +.cpp.obj: + $(cc) $(cflags) $(cvarsdll) $*.cpp + +nppcm.res: nppcm.rc + $(rc) $(rcflags) $(rcvars) nppcm.rc + +clean: + -1 del nppcm.dll nppcm.obj nppcm.exp nppcm.res + +zip: + -1 del *.zip + perl abpack.pl \ No newline at end of file diff --git a/PowerEditor/src/tools/nppCM/license.txt b/PowerEditor/src/tools/nppCM/license.txt new file mode 100644 index 00000000..16618f39 --- /dev/null +++ b/PowerEditor/src/tools/nppCM/license.txt @@ -0,0 +1,19 @@ +Copyright (c) 2003 Andre Burgaud (http://www.burgaud.com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/PowerEditor/src/tools/nppCM/npp.bmp b/PowerEditor/src/tools/nppCM/npp.bmp new file mode 100644 index 00000000..92ae60e6 Binary files /dev/null and b/PowerEditor/src/tools/nppCM/npp.bmp differ diff --git a/PowerEditor/src/tools/nppCM/nppcm.RES b/PowerEditor/src/tools/nppCM/nppcm.RES new file mode 100644 index 00000000..ab2ad2f9 Binary files /dev/null and b/PowerEditor/src/tools/nppCM/nppcm.RES differ diff --git a/PowerEditor/src/tools/nppCM/nppcm.cpp b/PowerEditor/src/tools/nppCM/nppcm.cpp new file mode 100644 index 00000000..b671543f --- /dev/null +++ b/PowerEditor/src/tools/nppCM/nppcm.cpp @@ -0,0 +1,481 @@ +//--------------------------------------------------------------------------- +// Copyright 2002-2003 by Andre Burgaud +// See license.txt +//--------------------------------------------------------------------------- + +//--------------------------------------------------------------------------- +// wscitecm.cpp +// Defines the entry point for the DLL application. +//--------------------------------------------------------------------------- + +//--------------------------------------------------------------------------- +// Modified by Don HO +// to meet the need of Notepad++ +//--------------------------------------------------------------------------- + + +#ifndef STRICT +#define STRICT +#endif + +#define INC_OLE2 +#define UNICODE + +#ifdef UNICODE + #define generic_strrchr wcsrchr +#else + + #define generic_strrchr strrchr + +#endif + + +#include +#include +#include + +#define GUID_SIZE 128 +#define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0])) +#define MAX_FILES 10 +#define MAX_CMDSTR (MAX_PATH * MAX_FILES) +#define ResultFromShort(i) ResultFromScode(MAKE_SCODE(SEVERITY_SUCCESS, 0, (USHORT)(i))) + +#pragma data_seg(".text") +#define INITGUID +#include +#include +#include "resource.h" +#include "nppcm.h" +#pragma data_seg() + +//--------------------------------------------------------------------------- +// Global variables +//--------------------------------------------------------------------------- +UINT _cRef = 0; // COM Reference count. +HINSTANCE _hModule = NULL; // DLL Module. + +typedef struct{ + HKEY hRootKey; + LPTSTR szSubKey; + LPTSTR lpszValueName; + LPTSTR szData; +} DOREGSTRUCT, *LPDOREGSTRUCT; + +TCHAR szNppName[] = TEXT("notepad++.exe"); +TCHAR szShellExtensionTitle[] = TEXT("Notepad++"); + +BOOL RegisterServer(CLSID, LPTSTR); +BOOL UnregisterServer(CLSID, LPTSTR); +void MsgBox(LPTSTR); +void MsgBoxDebug(LPTSTR); +void MsgBoxError(LPTSTR); + +//--------------------------------------------------------------------------- +// DllMain +//--------------------------------------------------------------------------- +extern "C" int APIENTRY +DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) { + if (dwReason == DLL_PROCESS_ATTACH) { + _hModule = hInstance; + } + return 1; +} + +//--------------------------------------------------------------------------- +// DllCanUnloadNow +//--------------------------------------------------------------------------- +STDAPI DllCanUnloadNow(void) { + return (_cRef == 0 ? S_OK : S_FALSE); +} + +//--------------------------------------------------------------------------- +// DllGetClassObject +//--------------------------------------------------------------------------- +STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppvOut) { + *ppvOut = NULL; + if (IsEqualIID(rclsid, CLSID_ShellExtension)) { + CShellExtClassFactory *pcf = new CShellExtClassFactory; + return pcf->QueryInterface(riid, ppvOut); + } + return CLASS_E_CLASSNOTAVAILABLE; +} + +//--------------------------------------------------------------------------- +// DllRegisterServer +//--------------------------------------------------------------------------- +STDAPI DllRegisterServer() { + return (RegisterServer(CLSID_ShellExtension, szShellExtensionTitle) ? S_OK : E_FAIL); +} + +//--------------------------------------------------------------------------- +// DllUnregisterServer +//--------------------------------------------------------------------------- +STDAPI DllUnregisterServer(void) { + return (UnregisterServer(CLSID_ShellExtension, szShellExtensionTitle) ? S_OK : E_FAIL); +} + +//--------------------------------------------------------------------------- +// CheckNpp +//--------------------------------------------------------------------------- +BOOL CheckNpp() { + TCHAR szModuleFullName[MAX_PATH]; + TCHAR szExeFullName[MAX_PATH]; + int nLenPath = 0; + TCHAR* pDest; + LPTSTR *lpFilePart = NULL; + + GetModuleFileName(_hModule, szModuleFullName, MAX_PATH); + pDest = generic_strrchr(szModuleFullName, '\\' ); + pDest++; + pDest[0] = 0; + + DWORD dw = SearchPath(szModuleFullName, szShellExtensionTitle, TEXT(".exe"), MAX_PATH, szExeFullName, lpFilePart); + + return (dw ? TRUE : FALSE); +} + +//--------------------------------------------------------------------------- +// RegisterServer +//--------------------------------------------------------------------------- +BOOL RegisterServer(CLSID clsid, LPTSTR lpszTitle) { + int i; + HKEY hKey; + LRESULT lResult; + DWORD dwDisp; + TCHAR szSubKey[MAX_PATH]; + TCHAR szCLSID[MAX_PATH]; + TCHAR szModule[MAX_PATH]; + LPWSTR pwsz; + + if (!CheckNpp()) { + MsgBoxError(TEXT("To register the Notepad++ context menu extension,\r\ninstall nppcm.dll in the same directory than Notepad++.exe.")); + return FALSE; + } + + StringFromIID(clsid, &pwsz); + if(pwsz) { +#ifdef UNICODE + lstrcpy(szCLSID, pwsz); +#else + WideCharToMultiByte(CP_ACP, 0, pwsz, -1, szCLSID, ARRAYSIZE(szCLSID), NULL, NULL); +#endif + //free the string + LPMALLOC pMalloc; + CoGetMalloc(1, &pMalloc); + pMalloc->Free(pwsz); + pMalloc->Release(); + } + + //get this app's path and file name + GetModuleFileName(_hModule, szModule, MAX_PATH); + + DOREGSTRUCT ClsidEntries[] = { + HKEY_CLASSES_ROOT, TEXT("CLSID\\%s"), NULL, lpszTitle, + HKEY_CLASSES_ROOT, TEXT("CLSID\\%s\\InprocServer32"), NULL, szModule, + HKEY_CLASSES_ROOT, TEXT("CLSID\\%s\\InprocServer32"), TEXT("ThreadingModel"), TEXT("Apartment"), + HKEY_CLASSES_ROOT, TEXT("*\\shellex\\ContextMenuHandlers\\Notepad++"), NULL, szCLSID, + NULL, NULL, NULL, NULL + }; + + // Register the CLSID entries + for(i = 0; ClsidEntries[i].hRootKey; i++) { + // Create the sub key string - for this case, insert the file extension + wsprintf(szSubKey, ClsidEntries[i].szSubKey, szCLSID); + lResult = RegCreateKeyEx(ClsidEntries[i].hRootKey, szSubKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, &dwDisp); + if(NOERROR == lResult) { + TCHAR szData[MAX_PATH]; + // If necessary, create the value string + wsprintf(szData, ClsidEntries[i].szData, szModule); + lResult = RegSetValueEx(hKey, ClsidEntries[i].lpszValueName, 0, REG_SZ, (LPBYTE)szData, (lstrlen(szData) + 1) * sizeof(TCHAR)); + RegCloseKey(hKey); + } + else + return FALSE; + } + return TRUE; +} + +//--------------------------------------------------------------------------- +// UnregisterServer +//--------------------------------------------------------------------------- +BOOL UnregisterServer(CLSID clsid, LPTSTR lpszTitle) { + TCHAR szCLSID[GUID_SIZE + 1]; + TCHAR szCLSIDKey[GUID_SIZE + 32]; + TCHAR szKeyTemp[MAX_PATH + GUID_SIZE]; + LPWSTR pwsz; + + StringFromIID(clsid, &pwsz); + if(pwsz) { +#ifdef UNICODE + lstrcpy(szCLSID, pwsz); +#else + WideCharToMultiByte(CP_ACP, 0, pwsz, -1, szCLSID, ARRAYSIZE(szCLSID), NULL, NULL); +#endif + //free the string + LPMALLOC pMalloc; + CoGetMalloc(1, &pMalloc); + pMalloc->Free(pwsz); + pMalloc->Release(); + } + + lstrcpy(szCLSIDKey, TEXT("CLSID\\")); + lstrcat(szCLSIDKey, szCLSID); + + wsprintf(szKeyTemp, TEXT("*\\shellex\\ContextMenuHandlers\\%s"), lpszTitle); + RegDeleteKey(HKEY_CLASSES_ROOT, szKeyTemp); + + wsprintf(szKeyTemp, TEXT("%s\\%s"), szCLSIDKey, TEXT("InprocServer32")); + RegDeleteKey(HKEY_CLASSES_ROOT, szKeyTemp); + RegDeleteKey(HKEY_CLASSES_ROOT, szCLSIDKey); + + return TRUE; +} + +//--------------------------------------------------------------------------- +// MsgBoxDebug +//--------------------------------------------------------------------------- +void MsgBoxDebug(LPTSTR lpszMsg) { + MessageBox(NULL, + lpszMsg, + TEXT("DEBUG"), + MB_OK); +} + +//--------------------------------------------------------------------------- +// MsgBox +//--------------------------------------------------------------------------- +void MsgBox(LPTSTR lpszMsg) { + MessageBox(NULL, + lpszMsg, + TEXT("Notepad++ Extension"), + MB_OK); +} + +//--------------------------------------------------------------------------- +// MsgBoxError +//--------------------------------------------------------------------------- +void MsgBoxError(LPTSTR lpszMsg) { + MessageBox(NULL, + lpszMsg, + TEXT("Notepad++ Extension"), + MB_OK | MB_ICONSTOP); +} + +//--------------------------------------------------------------------------- +// CShellExtClassFactory +//--------------------------------------------------------------------------- +CShellExtClassFactory::CShellExtClassFactory() { + m_cRef = 0L; + _cRef++; +} + +CShellExtClassFactory::~CShellExtClassFactory() { + _cRef--; +} + +STDMETHODIMP CShellExtClassFactory::QueryInterface(REFIID riid, LPVOID FAR *ppv) { + *ppv = NULL; + if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IClassFactory)) { + *ppv = (LPCLASSFACTORY)this; + AddRef(); + return NOERROR; + } + return E_NOINTERFACE; +} + +STDMETHODIMP_(ULONG) CShellExtClassFactory::AddRef() { + return ++m_cRef; +} + +STDMETHODIMP_(ULONG) CShellExtClassFactory::Release() +{ + if (--m_cRef) + return m_cRef; + delete this; + return 0L; +} + +STDMETHODIMP CShellExtClassFactory::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, LPVOID *ppvObj) { + *ppvObj = NULL; + if (pUnkOuter) + return CLASS_E_NOAGGREGATION; + LPCSHELLEXT pShellExt = new CShellExt(); + if (NULL == pShellExt) + return E_OUTOFMEMORY; + return pShellExt->QueryInterface(riid, ppvObj); +} + +STDMETHODIMP CShellExtClassFactory::LockServer(BOOL fLock) { + return NOERROR; +} + +//--------------------------------------------------------------------------- +// CShellExt +//--------------------------------------------------------------------------- +CShellExt::CShellExt() { + m_cRef = 0L; + m_pDataObj = NULL; + _cRef++; + m_hNppBmp = LoadBitmap(_hModule, MAKEINTRESOURCE(IDB_NPP)); + HRESULT hr; + hr = SHGetMalloc(&m_pAlloc); + if (FAILED(hr)) + m_pAlloc = NULL; +} + +CShellExt::~CShellExt() { + if (m_pDataObj) + m_pDataObj->Release(); + _cRef--; + m_pAlloc->Release(); +} + +STDMETHODIMP CShellExt::QueryInterface(REFIID riid, LPVOID FAR *ppv) { + *ppv = NULL; + if (IsEqualIID(riid, IID_IShellExtInit) || IsEqualIID(riid, IID_IUnknown)) { + *ppv = (LPSHELLEXTINIT)this; + } + else if (IsEqualIID(riid, IID_IContextMenu)) { + *ppv = (LPCONTEXTMENU)this; + } + if (*ppv) { + AddRef(); + return NOERROR; + } + return E_NOINTERFACE; +} + +STDMETHODIMP_(ULONG) CShellExt::AddRef() { + return ++m_cRef; +} + +STDMETHODIMP_(ULONG) CShellExt::Release() { + if (--m_cRef) + return m_cRef; + delete this; + return 0L; +} + +STDMETHODIMP CShellExt::Initialize(LPCITEMIDLIST pIDFolder, LPDATAOBJECT pDataObj, HKEY hRegKey) { + HRESULT hres = 0; + if (m_pDataObj) + m_pDataObj->Release(); + if (pDataObj) { + m_pDataObj = pDataObj; + pDataObj->AddRef(); + } + return NOERROR; +} + +STDMETHODIMP CShellExt::QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags) { + UINT idCmd = idCmdFirst; + BOOL bAppendItems=TRUE; + TCHAR szItemNpp[] = TEXT("Edit with &Notepad++"); + + FORMATETC fmte = { + CF_HDROP, + (DVTARGETDEVICE FAR *)NULL, + DVASPECT_CONTENT, + -1, + TYMED_HGLOBAL + }; + + HRESULT hres = m_pDataObj->GetData(&fmte, &m_stgMedium); + + if (SUCCEEDED(hres)) { + if (m_stgMedium.hGlobal) + m_cbFiles = DragQueryFile((HDROP)m_stgMedium.hGlobal, (UINT)-1, 0, 0); + } + + UINT nIndex = indexMenu++; + InsertMenu(hMenu, nIndex, MF_STRING|MF_BYPOSITION, idCmd++, szItemNpp); + + if (m_hNppBmp) { + SetMenuItemBitmaps (hMenu, nIndex, MF_BYPOSITION, m_hNppBmp, m_hNppBmp); + } + + return ResultFromShort(idCmd-idCmdFirst); +} + +STDMETHODIMP CShellExt::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi) { + HRESULT hr = E_INVALIDARG; + + if (!HIWORD(lpcmi->lpVerb)) { + UINT idCmd = LOWORD(lpcmi->lpVerb); + switch(idCmd) { + case 0: + hr = InvokeNpp(lpcmi->hwnd, lpcmi->lpDirectory, lpcmi->lpVerb, lpcmi->lpParameters, lpcmi->nShow); + break; + } + } + return hr; +} + +STDMETHODIMP CShellExt::GetCommandString(UINT idCmd, UINT uFlags, UINT FAR *reserved, LPSTR pszName, UINT cchMax) { + if (uFlags == GCS_HELPTEXT && cchMax > 35) + strcpy(pszName, "Edits the selected file(s) with Notepad++"); + return NOERROR; +} + +static void getNppName(TCHAR *name) { + TCHAR szModuleFullName[MAX_PATH]; + int nLenPath = 0; + TCHAR* pDest; + + name[0] = 0; + GetModuleFileName(_hModule, szModuleFullName, MAX_PATH); + pDest = generic_strrchr(szModuleFullName, '\\' ); + pDest++; + pDest[0] = 0; + lstrcpy(name, szModuleFullName); + lstrcat(name, szNppName); + + if (name[0] == 0) + lstrcpy(name, szNppName); +} + +STDMETHODIMP CShellExt::InvokeNpp(HWND hParent, LPCSTR pszWorkingDir, LPCSTR pszCmd, LPCSTR pszParam, int iShowCmd) { + TCHAR szFileUserClickedOn[MAX_PATH]; + LPTSTR pszCommand; + UINT i; + + FORMATETC fmte = { + CF_HDROP, + (DVTARGETDEVICE FAR *)NULL, + DVASPECT_CONTENT, + -1, + TYMED_HGLOBAL + }; + + pszCommand = (LPTSTR)m_pAlloc->Alloc(MAX_PATH * (m_cbFiles + 1) * sizeof(TCHAR)); + + if (pszCommand) + getNppName(pszCommand); + else { + MsgBoxError(TEXT("Insufficient memory available.")); + return E_FAIL; + } + + for (i = 0; i < m_cbFiles; i++) { + DragQueryFile((HDROP)m_stgMedium.hGlobal, i, szFileUserClickedOn, MAX_PATH); + lstrcat(pszCommand, TEXT(" \"")); + lstrcat(pszCommand, szFileUserClickedOn); + lstrcat(pszCommand, TEXT("\"")); + } + + STARTUPINFO si; + PROCESS_INFORMATION pi; + ZeroMemory(&si, sizeof(si)); + si.cb = sizeof(si); + si.dwFlags = STARTF_USESHOWWINDOW; + si.wShowWindow = SW_RESTORE; + if (!CreateProcess (NULL, pszCommand, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) { + MessageBox(hParent, + TEXT("Error creating process: nppcm.dll needs to be in the same directory than notepad++.exe"), + TEXT("Notepad++ Extension"), + MB_OK); + } + + m_pAlloc->Free(pszCommand); + return NOERROR; +} diff --git a/PowerEditor/src/tools/nppCM/nppcm.def b/PowerEditor/src/tools/nppCM/nppcm.def new file mode 100644 index 00000000..f60eedd3 --- /dev/null +++ b/PowerEditor/src/tools/nppCM/nppcm.def @@ -0,0 +1,10 @@ +;nppcm.def : Declares the module parameters for the DLL. + +LIBRARY nppcm +DESCRIPTION 'Notepad++ Shell Extension' + +EXPORTS + DllCanUnloadNow PRIVATE + DllGetClassObject PRIVATE + DllRegisterServer PRIVATE + DllUnregisterServer PRIVATE diff --git a/PowerEditor/src/tools/nppCM/nppcm.h b/PowerEditor/src/tools/nppCM/nppcm.h new file mode 100644 index 00000000..f3b0ed34 --- /dev/null +++ b/PowerEditor/src/tools/nppCM/nppcm.h @@ -0,0 +1,79 @@ +//--------------------------------------------------------------------------- +// Copyright 2002-2003 by Andre Burgaud +// See license.txt +//--------------------------------------------------------------------------- + +//--------------------------------------------------------------------------- +// wscitecm.h +//--------------------------------------------------------------------------- + +//--------------------------------------------------------------------------- +// Modified by Don HO +// to meet the need of Notepad++ +//--------------------------------------------------------------------------- + +// {120b94b5-2e6a-4f13-94d0-414bcb64fa0f} +DEFINE_GUID(CLSID_ShellExtension, 0x120b94b5, 0x2e6a, 0x4f13, 0x94, 0xd0, 0x41, 0x4b, 0xcb, 0x64, 0xfa, 0x0f); + + +class CShellExtClassFactory : public IClassFactory { +protected: + ULONG m_cRef; + +public: + CShellExtClassFactory(); + ~CShellExtClassFactory(); + + STDMETHODIMP QueryInterface(REFIID, LPVOID FAR *); + STDMETHODIMP_(ULONG) AddRef(); + STDMETHODIMP_(ULONG) Release(); + STDMETHODIMP CreateInstance(LPUNKNOWN, REFIID, LPVOID FAR *); + STDMETHODIMP LockServer(BOOL); +}; +typedef CShellExtClassFactory *LPCSHELLEXTCLASSFACTORY; + +class CShellExt : public IContextMenu, IShellExtInit { +public: +protected: + ULONG m_cRef; + UINT m_cbFiles; + STGMEDIUM m_stgMedium; + LPDATAOBJECT m_pDataObj; + HBITMAP m_hNppBmp; + LPMALLOC m_pAlloc; + TCHAR m_szDllDir [MAX_PATH]; + + STDMETHODIMP InvokeNpp(HWND hParent, + LPCSTR pszWorkingDir, + LPCSTR pszCmd, + LPCSTR pszParam, + int iShowCmd); + +public: + CShellExt(); + ~CShellExt(); + + STDMETHODIMP QueryInterface(REFIID, LPVOID FAR *); + STDMETHODIMP_(ULONG) AddRef(); + STDMETHODIMP_(ULONG) Release(); + + STDMETHODIMP QueryContextMenu(HMENU hMenu, + UINT indexMenu, + UINT idCmdFirst, + UINT idCmdLast, + UINT uFlags); + + STDMETHODIMP InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi); + + STDMETHODIMP GetCommandString(UINT idCmd, + UINT uFlags, + UINT FAR *reserved, + LPSTR pszName, + UINT cchMax); + + STDMETHODIMP Initialize(LPCITEMIDLIST pIDFolder, + LPDATAOBJECT pDataObj, + HKEY hKeyID); +}; + +typedef CShellExt *LPCSHELLEXT; diff --git a/PowerEditor/src/tools/nppCM/nppcm.rc b/PowerEditor/src/tools/nppCM/nppcm.rc new file mode 100644 index 00000000..62d03b71 --- /dev/null +++ b/PowerEditor/src/tools/nppCM/nppcm.rc @@ -0,0 +1,116 @@ +//Microsoft Developer Studio generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "afxres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +#ifdef _WIN32 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) +#endif //_WIN32 + +#ifndef _MAC +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 1,3,0,0 + PRODUCTVERSION 1,3,0,0 + FILEFLAGSMASK 0x3fL +#ifdef _DEBUG + FILEFLAGS 0x3L +#else + FILEFLAGS 0x2L +#endif + FILEOS 0x4L + FILETYPE 0x2L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "Comments", "\0" + VALUE "CompanyName", "Burgaud.com\0" + VALUE "FileDescription", "Context Handler Menu for Notepad++\0" + VALUE "FileVersion", "1.3\0" + VALUE "InternalName", "\0" + VALUE "LegalCopyright", "Copyright © 2000-2003 Andre Burgaud\0" + VALUE "LegalTrademarks", "\0" + VALUE "OriginalFilename", "nppcm.dll\0" + VALUE "PrivateBuild", "\0" + VALUE "ProductName", "\0" + VALUE "ProductVersion", "1.3\0" + VALUE "SpecialBuild", "\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END + +#endif // !_MAC + + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE DISCARDABLE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE DISCARDABLE +BEGIN + "#include ""afxres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE DISCARDABLE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Bitmap +// + +IDB_NPP BITMAP DISCARDABLE "npp.bmp" +#endif // English (U.S.) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/PowerEditor/src/tools/nppCM/readme.txt b/PowerEditor/src/tools/nppCM/readme.txt new file mode 100644 index 00000000..a2f3bdcc --- /dev/null +++ b/PowerEditor/src/tools/nppCM/readme.txt @@ -0,0 +1,62 @@ + +Overview +-------- +nppcm.dll is a shell extension component for Notepad++. +This component is modified from the MIT open source project WSciTEcm +(Context Menu Extension for SciTE), made by Andre Burgaud , +to meet the need of Notepad++. +Installing this Context Menu Handler (nppcm.dll) creates a new command +"Edit with Notepad++" in the context menu of Windows Explorer. +You can quickly open one or several selected files in Windows Explorer: +right click on the selection and click on the command "Edit with Notepad++". + +The manual installation is describe in the following sections. + + +Installation +------------ +1) Copy nppcm.dll in Notepad++ directory. +2) In Notepad++ directory installation, type the command "regsvr32 nppcm.dll". +This will register the dll. + +If everything goes well, you should have "Edit with Notepad++" +when you right click on selected file(s) in Windows Explorer. + +Uninstallation +-------------- +In Notepad++ directory installation, type the command "regsvr32 /u nppcm.dll". + + +Unload the dll +-------------- +If you try to delete or override the dll file and you get the error "Access is +denied.", the library is already loaded. +There are several options to workaround this issue: + +Solution 1: +- Close all the Windows Explorer instances open on your desktop and copy +nppcm.dll using the command line (Example : "C:/>cp nppcm.dll "). + +Solution 2: +- Reboot the computer and delete or override nppcm.dll (with the command line) +before starting Windows Explorer and using the context menu (right-click). + +Solution 3: +- Open a command line window +- Type CTRL+ALT+DEL to display the Windows Task Manager, display the Process tab +and "kill" the explorer.exe process. +- If your exlorer did not restart automatically, start it manually from the command line window +(c:/>explorer) +- Delete or override nppcm.dll before using the context menu (Example: "C:/>cp nppcm.dll "). + +Build +----- +nppcm.dll is built with Visual C++ 6.0. A Makefile is provided with the +sources: in the source directory, type "nmake". Ensure that all the +environment variables and paths are set correctly. To do so, use the command +file "VCVARS32.BAT" available in the bin directory of Visual C++ installation. + +License +------- +Copyright 2002-2003 by Andre Burgaud +See license.txt \ No newline at end of file diff --git a/PowerEditor/src/tools/nppCM/resource.h b/PowerEditor/src/tools/nppCM/resource.h new file mode 100644 index 00000000..6754d602 --- /dev/null +++ b/PowerEditor/src/tools/nppCM/resource.h @@ -0,0 +1,17 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Developer Studio generated include file. +// Used by wscitecm.rc +// +#define IDI_SCITE 101 +#define IDB_NPP 102 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 104 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1000 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/PowerEditor/src/tools/xmlApiSorter/sorter.cpp b/PowerEditor/src/tools/xmlApiSorter/sorter.cpp new file mode 100644 index 00000000..5952bbc8 --- /dev/null +++ b/PowerEditor/src/tools/xmlApiSorter/sorter.cpp @@ -0,0 +1,176 @@ +#include +#include +#include "tinyxml.h" + +#include +#include + +using namespace std; + +struct xmlname{ + TiXmlElement * node; + const char * name; + xmlname(TiXmlElement * n, const char * na) { node = n; name = na;} +}; + +//true if x1 smaller +bool sortXMLCase(const xmlname & x1, const xmlname & x2) { + return (strcmp(x1.name, x2.name) < 0); +} + +inline bool lower(char c) { + return (c >= 'a' && c <= 'z'); +} + +inline bool match(char c1, char c2) { + if (c1 == c2) return true; + if (lower(c1)) + return ((c1-32) == c2); + if (lower(c2)) + return ((c2-32) == c1); + return false; +} + +//true if x1 smaller +bool sortXML(const xmlname & x1, const xmlname & x2) { + + const char * n1 = x1.name, * n2 = x2.name; + int i = 0; + while(match(n2[i], n1[i])) { + if (n1[i] == 0) { + return true; //equal + } + i++; + } + + int subs1 = lower(n1[i])?32:0; + int subs2 = lower(n2[i])?32:0; + + return ( (n1[i]-subs1) < (n2[i]-subs2) ); + +} + +void merge(TiXmlElement * n1, TiXmlElement * n2); + +int main(int argc, char *argv[]) +{ + const char * file = NULL; + + if (argc < 2) { + cout << "Usage: sorter.exe xmlfile.xml" << endl; + return 1; + } + file = argv[1]; + + TiXmlDocument *pXmlApi = NULL; + pXmlApi = new TiXmlDocument(file); + bool loadOkay = pXmlApi->LoadFile(); + if (!loadOkay) return 1; + + TiXmlNode *root = pXmlApi->FirstChild("NotepadPlus"); + if (!root) { + cout << "NotepadPlus node not found\n"; + return 1; + } + TiXmlElement *autoc = root->FirstChildElement("AutoComplete"); + if (!autoc) { + cout << "AutoComplete node not found\n"; + return 1; + } + const char * langName = autoc->Attribute("language"); + + TiXmlElement *envNode = autoc->FirstChildElement("Environment"); + bool ignoreCase = false; + if (envNode) { + cout << "Found environment settings\n"; + const char * ignoreCaseText = envNode->Attribute("ignoreCase"); + if (ignoreCaseText) { + ignoreCase = (strcmp(ignoreCaseText, "yes") == 0); + if (ignoreCase) { + cout << "Sorting case insensitive\n"; + } else { + cout << "Sorting case sensitive\n"; + } + } else { + cout <<"Cannot find attribute \"ignoreCase\", defaulting to case sensitive sort\nConsider adding the node\n"; + } + } else { + cout << "No environment settings found, defaulting to case sensitive sort\nConsider adding the node\n"; + } + + vector words; + for (TiXmlElement *childNode = autoc->FirstChildElement("KeyWord"); + childNode ; + childNode = childNode->NextSiblingElement("KeyWord") ) + { + const char * name = childNode->Attribute("name"); + if (!name) { + cout << "Warning: KeyWord without name!, skipping...\n"; + continue; + } else { + int i = 0; + while(name[i] != 0) { + if (!isalnum(name[i]) && name[i] != '_') { + cout << "Warning, keyword " << name << " contains unsupported characters!\n"; + break; + } + i++; + } + words.push_back(xmlname(childNode, name)); + } + } + + if (ignoreCase) + sort(words.begin(), words.end(), sortXML); + else + sort(words.begin(), words.end(), sortXMLCase); + + for(size_t i = 1; i < words.size(); i++) { + //merge duplicates + if (!strcmp(words[i].name, words[i-1].name)) { + merge(words[i-1].node, words[i].node); + words.erase(words.begin() + i); + } + } + + TiXmlDocument doc; + TiXmlDeclaration * decl = new TiXmlDeclaration( "1.0", "Windows-1252", "" ); + doc.LinkEndChild( decl ); + TiXmlElement * element = new TiXmlElement( "NotepadPlus" ); + doc.LinkEndChild( element ); + TiXmlElement * element2 = new TiXmlElement( "AutoComplete" ); + element->LinkEndChild( element2 ); + + if (langName) + element2->SetAttribute("language", langName); + + if (envNode) + element2->LinkEndChild(envNode); + + for(size_t i = 0; i < words.size(); i++) { + element2->LinkEndChild(words[i].node); + } + + doc.SaveFile( file ); + + return 0; +} + +void merge(TiXmlElement * n1, TiXmlElement * n2) { + const char * funcAttr = NULL; + funcAttr = n2->Attribute("func"); + if (!funcAttr || !strcmp(funcAttr, "yes")) { + return; + } + + n1->SetAttribute("func", "yes"); + + for (TiXmlElement *childNode = n2->FirstChildElement("Overload"); + childNode ; + childNode = childNode->NextSiblingElement("Overload") ) + { + n1->LinkEndChild(childNode); + } + + return; +} diff --git a/PowerEditor/src/tools/xmlApiSorter/sorter.vcproj b/PowerEditor/src/tools/xmlApiSorter/sorter.vcproj new file mode 100644 index 00000000..45dcfb16 --- /dev/null +++ b/PowerEditor/src/tools/xmlApiSorter/sorter.vcproj @@ -0,0 +1,160 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PowerEditor/src/tools/xmlUpdater/configModel.xml b/PowerEditor/src/tools/xmlUpdater/configModel.xml new file mode 100644 index 00000000..bcef6f65 --- /dev/null +++ b/PowerEditor/src/tools/xmlUpdater/configModel.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/PowerEditor/src/tools/xmlUpdater/langsModel.xml b/PowerEditor/src/tools/xmlUpdater/langsModel.xml new file mode 100644 index 00000000..ba690cfa --- /dev/null +++ b/PowerEditor/src/tools/xmlUpdater/langsModel.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/PowerEditor/src/tools/xmlUpdater/makefile b/PowerEditor/src/tools/xmlUpdater/makefile new file mode 100644 index 00000000..19af6758 --- /dev/null +++ b/PowerEditor/src/tools/xmlUpdater/makefile @@ -0,0 +1,56 @@ +# this file is part of notepad++ +# Copyright (C)2003 Don HO ( donho@altern.org ) +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +.SUFFIXES: .cpp +CPP = g++ +CFLAGS = -Wall -Os -DNDEBUG + +MAINOBJS = xmlUpdater.o +TINYXMLOBJS = tinystr.o tinyxml.o tinyxmlerror.o tinyxmlparser.o + +TINYXMLDIR = ../../TinyXml + +OBJS = $(MAINOBJS) $(TINYXMLOBJS) + +PROG = xmlUpdater.exe + +INCLUDEDIR = $(TINYXMLDIR) +INCLUDEFLAGS = -I$(INCLUDEDIR) +LDFLAGS = +#-mwindows -lshlwapi -Os -s + +ALL : $(PROG) + + +$(PROG) : $(OBJS) + $(CPP) -o $@ $(OBJS) $(LDFLAGS) + +xmlUpdater.o : $(INCLUDEDIR)/tinyxml.h + $(CPP) -c xmlUpdater.cpp -o $@ $(INCLUDEFLAGS) + +tinystr.o: $(TINYXMLDIR)/tinystr.h $(TINYXMLDIR)/tinyxml.h + $(CPP) $(CFLAGS) -c $(TINYXMLDIR)/tinystr.cpp -o $@ $(INCLUDEFLAGS) + +tinyxml.o: $(TINYXMLDIR)/tinyxml.h + $(CPP) $(CFLAGS) -c $(TINYXMLDIR)/tinyxml.cpp -o $@ $(INCLUDEFLAGS) + +tinyxmlerror.o: $(TINYXMLDIR)/tinyxml.h + $(CPP) $(CFLAGS) -c $(TINYXMLDIR)/tinyxmlerror.cpp -o $@ $(INCLUDEFLAGS) + +tinyxmlparser.o: $(TINYXMLDIR)/tinyxml.h + $(CPP) $(CFLAGS) -c $(TINYXMLDIR)/tinyxmlparser.cpp -o $@ $(INCLUDEFLAGS) + diff --git a/PowerEditor/src/tools/xmlUpdater/stylers_remove.xml b/PowerEditor/src/tools/xmlUpdater/stylers_remove.xml new file mode 100644 index 00000000..041502ca --- /dev/null +++ b/PowerEditor/src/tools/xmlUpdater/stylers_remove.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/PowerEditor/src/tools/xmlUpdater/stylesModel.xml b/PowerEditor/src/tools/xmlUpdater/stylesModel.xml new file mode 100644 index 00000000..16bf01a0 --- /dev/null +++ b/PowerEditor/src/tools/xmlUpdater/stylesModel.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/PowerEditor/src/tools/xmlUpdater/xmlUpdater.cpp b/PowerEditor/src/tools/xmlUpdater/xmlUpdater.cpp new file mode 100644 index 00000000..e0231981 --- /dev/null +++ b/PowerEditor/src/tools/xmlUpdater/xmlUpdater.cpp @@ -0,0 +1,337 @@ +/* +this file is part of notepad++ +Copyright (C)2003 Don HO ( donho@altern.org ) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include +#include "tinyxml.h" +#define MODEL_INVALID 1 +#define SRC_INVALID 2 +#define DEST_INVALID 3 + +static bool isInList(const char *token2Find, char *list2Clean) { + char word[1024]; + bool isFileNamePart = false; + + for (int i = 0, j = 0 ; i <= int(strlen(list2Clean)) ; i++) + { + if ((list2Clean[i] == ' ') || (list2Clean[i] == '\0')) + { + if ((j) && (!isFileNamePart)) + { + word[j] = '\0'; + j = 0; + bool bingo = !strcmp(token2Find, word); + + if (bingo) + { + int wordLen = int(strlen(word)); + int prevPos = i - wordLen; + + for (i = i + 1 ; i <= int(strlen(list2Clean)) ; i++, prevPos++) + list2Clean[prevPos] = list2Clean[i]; + + list2Clean[prevPos] = '\0'; + + return true; + } + } + } + else if (list2Clean[i] == '"') + { + isFileNamePart = !isFileNamePart; + } + else + { + word[j++] = list2Clean[i]; + } + } + return false; +}; + + +void update(TiXmlNode *modelNode, TiXmlNode *srcNode, TiXmlNode *destNode) { + TiXmlNode *srcChildNode = NULL; + TiXmlNode *destChildNode = NULL; + TiXmlNode *modelChildNode = modelNode->FirstChild("Node"); + + if (!srcNode) return; + + for (modelChildNode = modelNode->FirstChild("Node"); + modelChildNode; + modelChildNode = modelChildNode->NextSibling("Node")) + { + const char *nodeName = (modelChildNode->ToElement())->Attribute("nodeName"); + const char *name = (modelChildNode->ToElement())->Attribute("name"); + if (nodeName) + { + srcChildNode = srcNode->FirstChild(nodeName); + if (!srcChildNode) continue; + + destChildNode = destNode->FirstChild(nodeName); + if (!destChildNode) + { + //Insertion + destNode->InsertEndChild(*srcChildNode); + continue; + } + if (name && name[0]) + { + srcChildNode = srcNode->FirstChild(nodeName); + while (srcChildNode) + { + const char *attrib = (srcChildNode->ToElement())->Attribute(name); + if (attrib) + { + const char *action = (srcChildNode->ToElement())->Attribute("action"); + bool remove = false; + bool found = false; + + if (action && !strcmp(action, "remove")) + remove = true; + + destChildNode = destNode->FirstChild(nodeName); + while (destChildNode) + { + const char *attribDest = (destChildNode->ToElement())->Attribute(name); + if ((attribDest) && (!strcmp(attrib, attribDest))) + { + found = true; + break; + } + destChildNode = destChildNode->NextSibling(nodeName); + } + if (remove) + { + if (found) destNode->RemoveChild(destChildNode); + } + else + { + if (found) + update(modelChildNode, srcChildNode, destChildNode); + else + destNode->InsertEndChild(*srcChildNode); + } + } + srcChildNode = srcChildNode->NextSibling(nodeName); + } // while srcChildNode + } + } + update(modelChildNode, srcChildNode, destChildNode); + } +}; + + +int main(int argc, char *argv[]) +{ + if (argc != 4) + { + printf("Syntax : xmlUpdater model.xml src.xml dest.xml"); + return -1; + } + + char *xmlModelPath = argv[1]; + char *xmlSrcPath = argv[2]; + char *xmlDestPath = argv[3]; + + //printf("%s\n", xmlModelPath); + //printf("%s\n", xmlSrcPath); + //printf("%s\n", xmlDestPath); + + TiXmlDocument *pXmlModel = NULL; + TiXmlDocument *pXmlSrc = NULL; + TiXmlDocument *pXmlDest = NULL; + + try { + pXmlModel = new TiXmlDocument(xmlModelPath); + bool loadOkay = pXmlModel->LoadFile(); + if (!loadOkay) throw int(MODEL_INVALID); + + pXmlSrc = new TiXmlDocument(xmlSrcPath); + loadOkay = pXmlSrc->LoadFile(); + if (!loadOkay) throw int(SRC_INVALID); + + pXmlDest = new TiXmlDocument(xmlDestPath); + loadOkay = pXmlDest->LoadFile(); + if (!loadOkay) throw int(DEST_INVALID); + + TiXmlNode *root = pXmlModel->FirstChild("Node"); + const char *nodeRootName = (root->ToElement())->Attribute("nodeName"); + if (nodeRootName) + { + TiXmlNode *srcRoot = pXmlSrc->FirstChild(nodeRootName); + if (!srcRoot) throw int(4); + TiXmlNode *destRoot = pXmlDest->FirstChild(nodeRootName); + if (!destRoot) + { + throw int(DEST_INVALID); + } + else + { + update(root, srcRoot, destRoot); + } + } + } catch (int errMsg) { + char *msg; + if (errMsg == MODEL_INVALID) + msg = "Model file is invalidated"; + if (errMsg == SRC_INVALID) + msg = "Source file is invalidated"; + if (errMsg == DEST_INVALID) + msg = "File to update is invalidated"; + + if (pXmlModel) delete pXmlModel; + if (pXmlSrc) delete pXmlSrc; + if (pXmlDest) delete pXmlDest; + + printf("Update Failure"); + return -1; + } + + pXmlDest->SaveFile(); + + delete pXmlModel; + delete pXmlSrc; + delete pXmlDest; + printf("Update successful"); + + return 0; +} + +/* +const char FLAG_SILENT[] = "-silent"; + +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR lpszCmdLine, int nCmdShow) +//int main(int argc, char *argv[]) +{ + bool isSilentMode = isInList(FLAG_SILENT, lpszCmdLine); + + int argc=0; + LPSTR argv[10]; + LPSTR p, q; + + argv[argc] = "xmlUpdater.exe"; + // Parse command line handling quotes. + p = lpszCmdLine; + while (*p) + { + // for each argument + while ((*p) && (*p == ' ')) + p++; // skip over leading spaces + if (*p == '\042') + { + p++; // skip " + q = p; + // scan to end of argument + // doesn't handle embedded quotes + while ((*p) && (*p != '\042')) + p++; + argv[++argc] = q; + if (*p) + *p++ = '\0'; + } + else if (*p) + { + // delimited by spaces + q = p; + while ((*p) && (*p != ' ')) + p++; + argv[++argc] = q; + if (*p) + *p++ = '\0'; + } + } + argv[++argc] = (LPSTR)NULL; + + if (argc < 4) + { + //printf(); + if (!isSilentMode) + MessageBox(NULL, "xmlUpdater model.xml src.xml dest.xml", "Syntax", MB_OK); + return -1; + } + + char *xmlModelPath = argv[1]; + char *xmlSrcPath = argv[2]; + char *xmlDestPath = argv[3]; + + //printf("%s\n", xmlModelPath); + //printf("%s\n", xmlSrcPath); + //printf("%s\n", xmlDestPath); + + TiXmlDocument *pXmlModel = NULL; + TiXmlDocument *pXmlSrc = NULL; + TiXmlDocument *pXmlDest = NULL; + + try { + pXmlModel = new TiXmlDocument(xmlModelPath); + bool loadOkay = pXmlModel->LoadFile(); + if (!loadOkay) throw int(MODEL_INVALID); + + pXmlSrc = new TiXmlDocument(xmlSrcPath); + loadOkay = pXmlSrc->LoadFile(); + if (!loadOkay) throw int(SRC_INVALID); + + pXmlDest = new TiXmlDocument(xmlDestPath); + loadOkay = pXmlDest->LoadFile(); + if (!loadOkay) throw int(DEST_INVALID); + + TiXmlNode *root = pXmlModel->FirstChild("Node"); + const char *nodeRootName = (root->ToElement())->Attribute("nodeName"); + if (nodeRootName) + { + TiXmlNode *srcRoot = pXmlSrc->FirstChild(nodeRootName); + if (!srcRoot) throw int(4); + TiXmlNode *destRoot = pXmlDest->FirstChild(nodeRootName); + if (!destRoot) + { + throw int(DEST_INVALID); + } + else + { + update(root, srcRoot, destRoot); + } + } + } catch (int errMsg) { + char *msg; + if (errMsg == MODEL_INVALID) + msg = "Model file is invalidated"; + if (errMsg == SRC_INVALID) + msg = "Source file is invalidated"; + if (errMsg == DEST_INVALID) + msg = "File to update is invalidated"; + + if (pXmlModel) delete pXmlModel; + if (pXmlSrc) delete pXmlSrc; + if (pXmlDest) delete pXmlDest; + + if (!isSilentMode) + MessageBox(NULL, msg, "Update Failure", MB_OK); + return -1; + } + + pXmlDest->SaveFile(); + + delete pXmlModel; + delete pXmlSrc; + delete pXmlDest; + if (!isSilentMode) + MessageBox(NULL, "Update successful", "Update status", MB_OK); + + return 0; +} +*/ diff --git a/PowerEditor/src/tools/xmlUpdater/xmlUpdater.vcproj b/PowerEditor/src/tools/xmlUpdater/xmlUpdater.vcproj new file mode 100644 index 00000000..ad38fa48 --- /dev/null +++ b/PowerEditor/src/tools/xmlUpdater/xmlUpdater.vcproj @@ -0,0 +1,224 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PowerEditor/src/userDefineLang.xml b/PowerEditor/src/userDefineLang.xml new file mode 100644 index 00000000..d9dbac64 --- /dev/null +++ b/PowerEditor/src/userDefineLang.xml @@ -0,0 +1,62 @@ + + + + + + + + + BEGIN + END + , + 0// 1/* 0REM 2*/ + STYLE FONT DIALOGEX + COMBOBOX LTEXT CONTROL EDITTEXT + + + + + + + + + + + + + + + + + + + + + + + + + function procedure switch when forEach for while + endFunc endProc endSwitch endWhen endFor endWhile + - ( ) * , . / : ? @ [ ] + = + 0; + if elseif else endIf return break + + uses type self var _Result + Nil True False and or + + + + + + + + + + + + + + + + diff --git a/PowerEditor/src/winmain.cpp b/PowerEditor/src/winmain.cpp new file mode 100644 index 00000000..829a56f3 --- /dev/null +++ b/PowerEditor/src/winmain.cpp @@ -0,0 +1,383 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#include "Common.h" +#include "Notepad_plus.h" +#include "Process.h" + +#include //default C++ exception +#include "Win32Exception.h" //Win32 exception +#include "MiniDumper.h" //Write dump files + +typedef std::vector ParamVector; + +bool checkSingleFile(const TCHAR * commandLine) { + TCHAR fullpath[MAX_PATH]; + ::GetFullPathName(commandLine, MAX_PATH, fullpath, NULL); + if (::PathFileExists(fullpath)) { + return true; + } + + return false; +} + +//commandLine should contain path to n++ executable running +void parseCommandLine(TCHAR * commandLine, ParamVector & paramVector) { + //params.erase(params.begin()); + //remove the first element, since thats the path the the executable (GetCommandLine does that) + TCHAR stopChar = TEXT(' '); + int i = 0; + if (commandLine[0] == TEXT('\"')) { + stopChar = TEXT('\"'); + commandLine++; + } + //while this is not really DBCS compliant, space and quote are in the lower 127 ASCII range + while(commandLine[0] && commandLine[0] != stopChar) + commandLine++; + commandLine++; //advance past stopChar + //kill remaining spaces + while(commandLine[0] == TEXT(' ')) + commandLine++; + + + bool isFile = checkSingleFile(commandLine); //if the commandline specifies only a file, open it as such + if (isFile) { + paramVector.push_back(commandLine); + return; + } + bool isInFile = false; + bool isInWhiteSpace = true; + paramVector.clear(); + size_t commandLength = lstrlen(commandLine); + for(size_t i = 0; i < commandLength; i++) { + switch(commandLine[i]) { + case '\"': { //quoted filename, ignore any following whitespace + if (!isInFile) { //" will always be treated as start or end of param, in case the user forgot to add an space + paramVector.push_back(commandLine+i+1); //add next param(since zero terminated generic_string original, no overflow of +1) + } + isInFile = !isInFile; + isInWhiteSpace = false; + //because we dont want to leave in any quotes in the filename, remove them now (with zero terminator) + commandLine[i] = 0; + break; } + case '\t': //also treat tab as whitespace + case ' ': { + isInWhiteSpace = true; + if (!isInFile) + commandLine[i] = 0; //zap spaces into zero terminators, unless its part of a filename + break; } + default: { //default TCHAR, if beginning of word, add it + if (!isInFile && isInWhiteSpace) { + paramVector.push_back(commandLine+i); //add next param + isInWhiteSpace = false; + } + break; } + } + } + //the commandline generic_string is now a list of zero terminated strings concatenated, and the vector contains all the substrings +} + +bool isInList(const TCHAR *token2Find, ParamVector & params) { + int nrItems = params.size(); + + for (int i = 0; i < nrItems; i++) + { + if (!lstrcmp(token2Find, params.at(i))) { + params.erase(params.begin() + i); + return true; + } + } + return false; +}; + +bool getParamVal(TCHAR c, ParamVector & params, generic_string & value) { + value = TEXT(""); + int nrItems = params.size(); + + for (int i = 0; i < nrItems; i++) + { + const TCHAR * token = params.at(i); + if (token[0] == '-' && lstrlen(token) >= 2 && token[1] == c) { //dash, and enough chars + value = (token+2); + params.erase(params.begin() + i); + return true; + } + } + return false; +} + +LangType getLangTypeFromParam(ParamVector & params) { + generic_string langStr; + if (!getParamVal('l', params, langStr)) + return L_EXTERNAL; + return NppParameters::getLangIDFromStr(langStr.c_str()); +}; + +int getNumberFromParam(char paramName, ParamVector & params, bool & isParamePresent) { + generic_string numStr; + if (!getParamVal(paramName, params, numStr)) + { + isParamePresent = false; + return -1; + } + isParamePresent = true; + return generic_atoi(numStr.c_str()); +}; +/* +int getLn2GoFromParam(ParamVector & params) { + generic_string lineNumStr; + if (!getParamVal('n', params, lineNumStr)) + return -1; + return generic_atoi(lineNumStr.c_str()); +}; + +int getPointXFromParam(ParamVector & params) { + generic_string pointXStr; + if (!getParamVal('x', params, pointXStr)) + return -1; + return generic_atoi(pointXStr.c_str()); +}; +*/ + +const TCHAR FLAG_MULTI_INSTANCE[] = TEXT("-multiInst"); +const TCHAR FLAG_NO_PLUGIN[] = TEXT("-noPlugin"); +const TCHAR FLAG_READONLY[] = TEXT("-ro"); +const TCHAR FLAG_NOSESSION[] = TEXT("-nosession"); +const TCHAR FLAG_NOTABBAR[] = TEXT("-notabbar"); + +void doException(Notepad_plus & notepad_plus_plus); + +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR cmdLineAnsi, int nCmdShow) +{ + LPTSTR cmdLine = ::GetCommandLine(); + ParamVector params; + parseCommandLine(cmdLine, params); + + MiniDumper mdump; //for debugging purposes. + + bool TheFirstOne = true; + ::SetLastError(NO_ERROR); + ::CreateMutex(NULL, false, TEXT("nppInstance")); + if (::GetLastError() == ERROR_ALREADY_EXISTS) + TheFirstOne = false; + + bool isParamePresent; + CmdLineParams cmdLineParams; + bool isMultiInst = isInList(FLAG_MULTI_INSTANCE, params); + cmdLineParams._isNoTab = isInList(FLAG_NOTABBAR, params); + cmdLineParams._isNoPlugin = isInList(FLAG_NO_PLUGIN, params); + cmdLineParams._isReadOnly = isInList(FLAG_READONLY, params); + cmdLineParams._isNoSession = isInList(FLAG_NOSESSION, params); + cmdLineParams._langType = getLangTypeFromParam(params); + cmdLineParams._line2go = getNumberFromParam('n', params, isParamePresent); + cmdLineParams._column2go = getNumberFromParam('c', params, isParamePresent); + cmdLineParams._point.x = getNumberFromParam('x', params, cmdLineParams._isPointXValid); + cmdLineParams._point.y = getNumberFromParam('y', params, cmdLineParams._isPointYValid); + + NppParameters *pNppParameters = NppParameters::getInstance(); + // override the settings if notepad style is present + if (pNppParameters->asNotepadStyle()) + { + isMultiInst = true; + cmdLineParams._isNoTab = true; + cmdLineParams._isNoSession = true; + } + + generic_string quotFileName = TEXT(""); + // tell the running instance the FULL path to the new files to load + size_t nrFilesToOpen = params.size(); + const TCHAR * currentFile; + TCHAR fullFileName[MAX_PATH]; + + for(size_t i = 0; i < nrFilesToOpen; i++) + { + currentFile = params.at(i); + //check if relative or full path. Relative paths dont have a colon for driveletter + BOOL isRelative = ::PathIsRelative(currentFile); + quotFileName += TEXT("\""); + if (isRelative) + { + ::GetFullPathName(currentFile, MAX_PATH, fullFileName, NULL); + quotFileName += fullFileName; + } + else + { + quotFileName += currentFile; + } + quotFileName += TEXT("\" "); + } + + //Only after loading all the file paths set the working directory + ::SetCurrentDirectory(NppParameters::getInstance()->getNppPath()); //force working directory to path of module, preventing lock + + if ((!isMultiInst) && (!TheFirstOne)) + { + HWND hNotepad_plus = ::FindWindow(Notepad_plus::getClassName(), NULL); + for (int i = 0 ;!(hNotepad_plus = ::FindWindow(Notepad_plus::getClassName(), NULL)) && i < 5 ; i++) + Sleep(100); + + if (hNotepad_plus) + { + // First of all, destroy static object NppParameters + pNppParameters->destroyInstance(); + MainFileManager->destroyInstance(); + + int sw; + + if (::IsZoomed(hNotepad_plus)) + sw = SW_MAXIMIZE; + else if (::IsIconic(hNotepad_plus)) + sw = SW_RESTORE; + else + sw = SW_SHOW; + + // IMPORTANT !!! + ::ShowWindow(hNotepad_plus, sw); + + ::SetForegroundWindow(hNotepad_plus); + + if (params.size() > 0) //if there are files to open, use the WM_COPYDATA system + { + COPYDATASTRUCT paramData; + paramData.dwData = COPYDATA_PARAMS; + paramData.lpData = &cmdLineParams; + paramData.cbData = sizeof(cmdLineParams); + + COPYDATASTRUCT fileNamesData; + fileNamesData.dwData = COPYDATA_FILENAMES; + fileNamesData.lpData = (void *)quotFileName.c_str(); + fileNamesData.cbData = long(quotFileName.length() + 1)*(sizeof(TCHAR)); + + ::SendMessage(hNotepad_plus, WM_COPYDATA, (WPARAM)hInstance, (LPARAM)¶mData); + ::SendMessage(hNotepad_plus, WM_COPYDATA, (WPARAM)hInstance, (LPARAM)&fileNamesData); + } + return 0; + } + } + + pNppParameters->load(); + Notepad_plus notepad_plus_plus; + + NppGUI & nppGui = (NppGUI &)pNppParameters->getNppGUI(); + + generic_string updaterDir = pNppParameters->getNppPath(); + updaterDir += TEXT("\\updater\\"); + + generic_string updaterFullPath = updaterDir + TEXT("gup.exe"); + + generic_string version = TEXT("-v"); + version += VERSION_VALUE; + + winVer curWinVer = notepad_plus_plus.getWinVersion(); + + bool isUpExist = nppGui._doesExistUpdater = (::PathFileExists(updaterFullPath.c_str()) == TRUE); + bool doUpdate = !nppGui._neverUpdate; + bool winSupported = (curWinVer >= WV_W2K); + + // Vista UAC de mes couilles!!! + bool isVista = (curWinVer == WV_VISTA); + + if (!winSupported) + nppGui._doesExistUpdater = false; + + if (TheFirstOne && isUpExist && doUpdate && winSupported && !isVista) + { + Process updater(updaterFullPath.c_str(), version.c_str(), updaterDir.c_str()); + updater.run(); + } + + MSG msg; + msg.wParam = 0; + Win32Exception::installHandler(); + try { + notepad_plus_plus.init(hInstance, NULL, quotFileName.c_str(), &cmdLineParams); + bool unicodeSupported = notepad_plus_plus.getWinVersion() >= WV_NT; + bool going = true; + while (going) + { + going = (unicodeSupported?(::GetMessageW(&msg, NULL, 0, 0)):(::GetMessageA(&msg, NULL, 0, 0))) != 0; + if (going) + { + // if the message doesn't belong to the notepad_plus_plus's dialog + if (!notepad_plus_plus.isDlgsMsg(&msg, unicodeSupported)) + { + if (::TranslateAccelerator(notepad_plus_plus.getHSelf(), notepad_plus_plus.getAccTable(), &msg) == 0) + { + ::TranslateMessage(&msg); + if (unicodeSupported) + ::DispatchMessageW(&msg); + else + ::DispatchMessage(&msg); + } + } + } + } + } catch(int i) { + if (i == 106901) + ::MessageBox(NULL, TEXT("Scintilla.init is failed!"), TEXT("Notepad++ Exception: 106901"), MB_OK); + else { + TCHAR str[50] = TEXT("God Damned Exception : "); + TCHAR code[10]; + wsprintf(code, TEXT("%d"), i); + ::MessageBox(Notepad_plus::gNppHWND, lstrcat(str, code), TEXT("Notepad++ Exception"), MB_OK); + doException(notepad_plus_plus); + } + } catch (const Win32Exception & ex) { + TCHAR message[1024]; //TODO: sane number + wsprintf(message, TEXT("An exception occured. Notepad++ cannot recover and must be shut down.\r\nThe exception details are as follows:\r\n") +#ifdef UNICODE + TEXT("Code:\t0x%08X\r\nType:\t%S\r\nException address: 0x%08X"), +#else + TEXT("Code:\t0x%08X\r\nType:\t%s\r\nException address: 0x%08X"), +#endif + ex.code(), ex.what(), ex.where()); + ::MessageBox(Notepad_plus::gNppHWND, message, TEXT("Win32Exception"), MB_OK | MB_ICONERROR); + mdump.writeDump(ex.info()); + doException(notepad_plus_plus); + } catch(std::exception ex) { +#ifdef UNICODE + const wchar_t * text = WcharMbcsConvertor::getInstance()->char2wchar(ex.what(), CP_ACP); + ::MessageBox(Notepad_plus::gNppHWND, text, TEXT("C++ Exception"), MB_OK); +#else + ::MessageBox(Notepad_plus::gNppHWND, ex.what(), TEXT("C++ Exception"), MB_OK); +#endif + doException(notepad_plus_plus); + } catch(...) { //this shouldnt ever have to happen + doException(notepad_plus_plus); + } + + return (UINT)msg.wParam; +} + +void doException(Notepad_plus & notepad_plus_plus) { + Win32Exception::removeHandler(); //disable exception handler after excpetion, we dont want corrupt data structurs to crash the exception handler + ::MessageBox(Notepad_plus::gNppHWND, TEXT("Notepad++ will attempt to save any unsaved data. However, dataloss is very likely."), TEXT("Recovery initiating"), MB_OK | MB_ICONINFORMATION); + + TCHAR tmpDir[1024]; + GetTempPath(1024, tmpDir); + generic_string emergencySavedDir = tmpDir; + emergencySavedDir += TEXT("\\N++RECOV"); + + bool res = notepad_plus_plus.emergency(emergencySavedDir); + if (res) { + generic_string displayText = TEXT("Notepad++ was able to successfully recover some unsaved documents, or nothing to be saved could be found.\r\nYou can find the results at :\r\n"); + displayText += emergencySavedDir; + ::MessageBox(Notepad_plus::gNppHWND, displayText.c_str(), TEXT("Recovery success"), MB_OK | MB_ICONINFORMATION); + } else { + ::MessageBox(Notepad_plus::gNppHWND, TEXT("Unfortunatly, Notepad++ was not able to save your work. We are sorry for any lost data."), TEXT("Recovery failure"), MB_OK | MB_ICONERROR); + } +} diff --git a/PowerEditor/src/xpm_icons.h b/PowerEditor/src/xpm_icons.h new file mode 100644 index 00000000..f9a8352b --- /dev/null +++ b/PowerEditor/src/xpm_icons.h @@ -0,0 +1,287 @@ +//this file is part of notepad++ +//Copyright (C)2003 Don HO ( donho@altern.org ) +// +//This program is free software; you can redistribute it and/or +//modify it under the terms of the GNU General Public License +//as published by the Free Software Foundation; either +//version 2 of the License, or (at your option) any later version. +// +//This program is distributed in the hope that it will be useful, +//but WITHOUT ANY WARRANTY; without even the implied warranty of +//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +//GNU General Public License for more details. +// +//You should have received a copy of the GNU General Public License +//along with this program; if not, write to the Free Software +//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +static char * acTop_xpm[] = { +"12 12 56 1", +" c #FFFFFF", +". c #8AB2E9", +"+ c #CCDCF6", +"@ c #80ABEA", +"# c #7DA9E8", +"$ c #C7DAF3", +"% c #79A7E6", +"& c #ADC8EF", +"* c #87B0E8", +"= c #BBD2F0", +"- c #6EA0E2", +"; c #A8C7EE", +"> c #A3C2ED", +", c #75A4E3", +"' c #A7C4EB", +") c #6297E1", +"! c #A1C1EC", +"~ c #92B7E8", +"{ c #99BBE9", +"] c #6197DD", +"^ c #96B9E6", +"/ c #538EDB", +"( c #99BBEA", +"_ c #80AAE3", +": c #81ABE3", +"< c #8AB1E4", +"[ c #4B88D6", +"} c #4882D1", +"| c #4384D6", +"1 c #90B5E7", +"2 c #74A3E0", +"3 c #77A4E0", +"4 c #81ABE2", +"5 c #437FD3", +"6 c #7FA2DF", +"7 c #3577D2", +"8 c #87AFE4", +"9 c #72A1DF", +"0 c #7CA9E1", +"a c #3F7AD0", +"b c #85A4DE", +"c c #FBFCFE", +"d c #236ECD", +"e c #7EA8E1", +"f c #79A6E0", +"g c #3D77D0", +"h c #87A4DC", +"i c #1A62C9", +"j c #75A3DF", +"k c #3C74CF", +"l c #8DA6DE", +"m c #1859C4", +"n c #3B71CC", +"o c #8EA5DD", +"p c #164EC0", +"q c #92A7DD", +" .+ ", +" @#$ ", +" %&*= ", +" -;>,' ", +" )!~{]^ ", +" /(_:<[} ", +" |123456 ", +" 7890abc ", +" defgh ", +" ijkl ", +" mno ", +" pq "}; + + +static char * acBottom_xpm[] = { +"12 12 54 1", +" c #FFFFFF", +". c #C4D7F3", +"+ c #72A1E3", +"@ c #C1D6F2", +"# c #6397E1", +"$ c #5990DD", +"% c #BBD2F0", +"& c #7AA6E5", +"* c #9ABDEA", +"= c #4A87D9", +"- c #B1CAEE", +"; c #75A4E3", +"> c #99BBE9", +", c #95B9E8", +"' c #3A7CD4", +") c #A9C6EC", +"! c #71A0E0", +"~ c #86AFE5", +"{ c #8DB2E6", +"] c #2A72CF", +"^ c #73A0E0", +"/ c #6B9DE0", +"( c #95B8E8", +"_ c #81ABE3", +": c #72A1DF", +"< c #83ADE3", +"[ c #1B65C9", +"} c #5F95DC", +"| c #8BB3E5", +"1 c #77A4E0", +"2 c #679ADC", +"3 c #7AA6E1", +"4 c #195CC6", +"5 c #FCFDFE", +"6 c #8DB2E4", +"7 c #4885D6", +"8 c #7CA9E1", +"9 c #6698DB", +"0 c #71A1DE", +"a c #1752C0", +"b c #88ABE0", +"c c #3D77D0", +"d c #6E9FDD", +"e c #699BDC", +"f c #1547BD", +"g c #8DA6DE", +"h c #376BC9", +"i c #6295DA", +"j c #1440B9", +"k c #8DA0DB", +"l c #315FC4", +"m c #1339B7", +"n c #909FDA", +"o c #1233B4", +" .+ ", +" @#$ ", +" %&*= L", +" -;>,' ", +" )!>~{] ", +" ^/(_:<[ ", +" (}|1234 ", +" 567890a ", +" bcdef ", +" ghij ", +" klm ", +" no "}; + +/* XPM */ +static char * bookmark_xpm[] = { +"15 15 64 1", +" c None", +". c #FE0000", +"+ c #9DD3D2", +"@ c #2DC7C9", +"# c #00A0A6", +"$ c #007A76", +"% c #50C4C6", +"& c #02C4C6", +"* c #81C6C7", +"= c #1DBCD9", +"- c #9CCFDA", +"; c #CAECF2", +"> c #8FC8C9", +", c #003236", +"' c #006A96", +") c #0092E6", +"! c #47B0E1", +"~ c #53BAE5", +"{ c #19C5C7", +"] c #003B68", +"^ c #00358E", +"/ c #0048A0", +"( c #005FA8", +"_ c #0065C4", +": c #002040", +"< c #003690", +"[ c #003F9E", +"} c #005BB0", +"| c #004BA8", +"1 c #000636", +"2 c #0040A0", +"3 c #0061C4", +"4 c #0078E8", +"5 c #008AF4", +"6 c #001656", +"7 c #0053B0", +"8 c #0081EE", +"9 c #0994FF", +"0 c #23A4FF", +"a c #1197FF", +"b c #00316E", +"c c #49B4FF", +"d c #53BCFF", +"e c #35ACFF", +"f c #59C2FF", +"g c #6BC8FD", +"h c #62C5FE", +"i c #003B78", +"j c #73D1FD", +"k c #7BD7FD", +"l c #A3D7D7", +"m c #008490", +"n c #003F80", +"o c #0983FF", +"p c #7BDAFD", +"q c #1990FF", +"r c #BEE6E8", +"s c #004A74", +"t c #0088E8", +"u c #19A0FF", +"v c #B6E4E2", +"w c #3DC7C9", +"x c #12C2C4", +"y c #64C6C5", +" +@#$#@+ ", +" %&**+**&% ", +" %&=-;;;-=&% ", +" >,')!~~~!)',> ", +" {]^/(___(/^]{ ", +" :^<[}___}|<^: ", +" 12|3455543|21 ", +" 67389000a8376 ", +" b|8a0cddea8|b ", +" '[5edfghde9[' ", +" >i4cgjkjgc8i> ", +" lmnofjpkfqnml ", +" r*@s(tut(s@*r ", +" v*w{x&x{w*v ", +" l*yyy*l "}; +/* +static char * modifUnsaved_xpm[] = { +"6 18 2 1", +"z c #FF8000", +"o c #FFC000", +"zozozo", +"ozozoz", +"zozozo", +"ozozoz", +"zozozo", +"ozozoz", +"zozozo", +"ozozoz", +"zozozo", +"ozozoz", +"zozozo", +"ozozoz", +"zozozo", +"ozozoz", +"zozozo", +"ozozoz", +"zozozo", +"ozozoz"}; + +static char * modifSaved_xpm[] = { +"6 18 2 1", +"z c #008000", +"o c #FFFFFF", +"zozozo", +"ozozoz", +"zozozo", +"ozozoz", +"zozozo", +"ozozoz", +"zozozo", +"ozozoz", +"zozozo", +"ozozoz", +"zozozo", +"ozozoz", +"zozozo", +"ozozoz", +"zozozo", +"ozozoz", +"zozozo", +"ozozoz"}; +*/ \ No newline at end of file diff --git a/PowerEditor/visual.net/no_ms_shit.vsprops b/PowerEditor/visual.net/no_ms_shit.vsprops new file mode 100644 index 00000000..32fa5ef6 --- /dev/null +++ b/PowerEditor/visual.net/no_ms_shit.vsprops @@ -0,0 +1,11 @@ + + + + diff --git a/PowerEditor/visual.net/notepadPlus.vc.7.0.vcproj b/PowerEditor/visual.net/notepadPlus.vc.7.0.vcproj new file mode 100644 index 00000000..f5b75359 --- /dev/null +++ b/PowerEditor/visual.net/notepadPlus.vc.7.0.vcproj @@ -0,0 +1,1091 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/PowerEditor/visual.net/notepadPlus.vcproj b/PowerEditor/visual.net/notepadPlus.vcproj new file mode 100644 index 00000000..425489dd --- /dev/null +++ b/PowerEditor/visual.net/notepadPlus.vcproj @@ -0,0 +1,1344 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +