' *********************************************************************************************
' SED_115 - MDI code editor based on the Scintilla Edit Control.
' Compilers supported: PBWin 7+, PBCC 3+
' *********************************************************************************************

' *********************************************************************************************
' DISCLAIMER:
' *********************************************************************************************
' This software and accompanying documentation are provided "as is" and without warranties as
' to performance or merchantability or any other warranties wether expressed or implied.
' Because of the various hardware and software environments into which this application may be
' used, no warranty of fitness for a particular purpose is offered. The user must assume the
' entire risk of using this software. In no case shall any of the contributors to this project
' be liable for any incidental, special or consequential damages or loss, including, without
' limitation, lost profits or the inability to use equipment or access data. This is true even
' if we are advised of the possibility of such damages. We also don't have any obligation of
' fix eventual bugs or to add new features.
' *********************************************************************************************

' *********************************************************************************************
' This is a collective work made by members of the so called PowerBasic community, i.e. users
' of the PowerBasic compilers. His names and contributions are specified in the history below.
' All of them have agreed to donate his work for this project to the public domain, so there are
' no restrictions of his use unless otherwise stated. If you use the code for your own projects,
' please give us the due credit.
' Project started and leaded by Jos Roca. http://csdsoft.com/josescied.htm
' Co-author: Raymond L. King, http://csdsoft.com , rayking@csdsoft.com
' (Ray has written the lexer for PowerBasic and has closely collaborated in all the whole project
' from the beginning, hosting the editor's page in his site, looking for an icon's provider, etc.).
' This project could not have been possible without his collaboration and friendship.
' Scintilla is a free source code editing component. It comes with complete source code and a
' license that permits his use in any free project or commercial product.
' Scintilla site: http://www.scintilla.org/
' Icons donated for the project by Marc Keeley, http://www.glyfz.com/ The icons and the bitmap
' strips can only be used to recompile the SED editor or a variation of it, but not for commercial
' purposes.
' The freeware Tsunami Record Manager 2.5 is used for the creation of the codetips database
' and the management of the code/templates database. Tsunami web page: http://www.trm-ug.com
' Special thanks to Don Dickinson for let us to use his ddoc print and preview engine, Ken Myers
' for providing excellent routines for scanning and parsing files used to generate the codetips
' database and Borje Hagsten for his public domain utilities that I have extensively used and
' abused. Borje's freeware and public domain utilities and samples can be downloaded at
' http://www.tolkenxp.com/pb/
' Note: This project started as an example of how to use the Scintilla control with Power Basic.
' For this example I used portions of PBNOTE2.BAS Copyright (c) 1997,1999,2001,2002 PowerBASIC, Inc.,
' one of the sample programs that come with the PBWin compiler. Do not remove this copyright notice.
' *********************************************************************************************

' *********************************************************************************************
' ddoc_p32.inc
' *********************************************************************************************
' This header file is necessary for scieditor to interface with ddoc32.dll and ddoc.exe
' ddoc is a shared print/preview engine written by Don Dickinson
' It is licensed especially for the scieditor project by the author.
' You may recompile scieditor including the ddoc functionality without
' paying royalty to or licensing the print engine from Don Dickinson.
' If you wish to use ddoc Print and Preview in an application besides scieditor
' you must purchase a license from the author. See www.greatwebdivde.com
' For more details or contact the author directly: don@greatwebdivide.com
' *********************************************************************************************

' *********************************************************************************************
' Some good freeware programs
' *********************************************************************************************
' IconEdit32: http://www.xs4all.nl/~pathou/otbf/iedit32.zip
' ToolbarPaint: http://donkey.visualassembler.com/
' WinGIMP: http://www.wingimp.org/
' ResourceHacker: http://www.users.on.net/johnson/resourcehacker/
' PE Resource Editor: http://www.wilsonc.demon.co.uk/d6peresourceeditor.htm
' ResEd: http://radasm.visualassembler.com/Upload/ResEd.zip
' Tsunami Record Manager: http://www.trm-ug.com
' *********************************************************************************************

' *********************************************************************************************
' SED's history:
' *********************************************************************************************
' April 25, 2005 : Version 1.15.01
' - Fixed the code for color printing and preview that caused these options to fail in clean
'   installs because it relied in some settings of the .ini file that were no present unless
'   the user had set them. Now, if no present, it uses default values.
' April 20, 2005 : Version 1.15.01
' - Fixed a bug in the Find and Replace code. The change to unselect text to allow Replace All
'   in the whole document if there wasn't a block selected caused Replace misbehavior.
'   Thanks to John R. Heathcote for reporting it.
' April 15, 2005 : Version 1.15
' - The name of the current sub/function is now shown in the statusbar instead of the codefinder
'   combobox. In order to show it in the combobox it was necessary to scan the names of all the
'   procedures and functions in the edited file and this caused a noticeable delay when editing
'   files with many sub/functions.
' April 5, 2005 : Version 1.15
' - Added view windows and color printing and print preview. Coded by Nicholas Melnick.
'   You can split the window both horizontally and vertically, giving up to four view
'   windows. The splitter bars are located at the top and left sides of the edit window.
'   To split the window drag the splitter bar with the mouse.
'   A new option called "Initialize As New" (in the Edit menu) allows to clear any of the
'   selected view windows (except the main one) and allow to use it for entering notes or
'   paste selected text into it.
' - Added "Use DDOC for printing" checkbox in the Editor options. If checked, SED will use
'   DDOC for printing and print preview; otherwise, color printing will be used.
' - The caret is now repositioned when you click the right mouse button to activate the
'   context menu (unless there is a block of text selected).
' March 19, 2005 : Version 1.15
' - Modified the FileOpen function to allow to open a file as "read-only" checking the read-only
'   checkbox in the Open File Dialog. You will be not allowed to edit a file opened this way.
'   It can be useful if you want to open a file to inspect it but don't want to alter it accidentally.
'   Please note that this is not the same that opening a file that has the read-only attribute set.
' March 18, 2005 : Version 1.15
' - Bug fix: Compile failed if the code had both the new #COMPILER metastatement and a name
'   for the program after the #COMPILE EXE metastatement. Thanks to Trento Castricone for
'   reporting it.
' March 10, 2005 : Version 1.15
' - Added the following code to the Find and Replace option to allow to do a replace in the
'   whole document if the selected text is not a block.
'      ' Unselect text to allow replace all in the whole document
'      SendMessage(GetEdit, %SCI_SETSELECTIONSTART, 0, 0)
'      SendMessage(GetEdit, %SCI_SETSELECTIONEND, 0, 0)
' March 08, 2005 : Version 1.15
' - Modified the size of several popup dialogs that doesn't looked well when using big fonts.
' - Added two more checkboxes to the Menu-->Options-->Colors and Fonts: "Use always the default
'   font" and "Use always the default font size". This allows to set the font and size of all
''   the styles changing only the Default one.
' March 02, 2005 : Version 1.15
' - Fixed an small bug that was causing a desktop redraw at startup.
' - Fixed another small bug: When closing a project, the primary source file name was not cleared.
' February 18, 2005 : Version 1.14
' - Added support for PB templates: When clicking the small arrow at the right side of the
'   "New File" icon, SED scans the BIN folder of the compiler to search all the files with
'   the .pbtpl extension and shows them in a dropdown menu. Clicking one of the descriptions
'   loads the template in a new window. Contrarily to the PB Ide, clicking the "New File" icon
'   doesn't load the default template, but creates a new empty window, just in case that is
'   what you want. As the BIN folder is scaned each time you click this option, if you create
'   new templates they are available without having to restart the editor. Templates are shown
'   ordered alphabetically by description.
' - Added keystroke Ctrl+M (Compile only) for compatibility with the PB compilers.
' - Changed the following keystrokes: Selection to upper case (Ctrl+Alt+U instead of Ctrl+U),
'   Selection to lower case (Ctrl+Alt+L instead of Ctrl+L), Selection to mixed case
'   (Ctrl+Alt+M instead of Ctrl+M).
' - Added new keywords for PBWIN 8.0 and PBCC 4.0.
' - Added comboboxes in the compiler options to select the version of the compilers:
'   PBWIN 7.x or 8.x and PBCC 3.x or 4.x. This setting is used by the Compile and Debug
'   option to be able to start the integrated debugger of the PB compilers.
' January 16, 2005 : Version 1.14
'   Added keyboard macros, Menu->Tools->Keyboard Macros
'   This option calls an external program called SED_MACROS.EXE that allows to to define unlimited
'   text to each combination of Alt0...9, Ctrl0...9 keys. This text will be inserted at the caret
'   position when the key combination is pressed.
' January 13, 2005 : Version 1.14
'   Added the "System Information" option (in the View menu). Calls MSINFO32.EXE.
' January 9, 2005 : Version 1.14
'   Added the "File Properties" option (in the View menu). Shows the standard file properties dialog.
' November 22, 2004 : Version 1.14
' - Added a new option to set the background color of the menu icons.
'   Options-->Colors and Fonts-->Menu icons background.
' - Added the option "Use always the default background color" to allow the setting of the
'   background color without having to change the background colors of the other items.
'   Options-->Colors and Fonts-->Use always the default background color (check the box
'   and click the Apply button).
' November 21, 2004 : Version 1.14
' - Unavailable options are now grayed in the menus.
' October 6, 2004: Version 1.14
' - Changed tab orientation from bottom to top because the %TCS_BOTTOM style is not supported
'   if you use ComCtl32.dll version 6 (Windows XP with XP themes enabled). The tab control
'   behaves as it has only one orientation: top. In fact, it has all four orientations, but all
'   four of them (for some reason) have the same appearance. The Tab control is hidden when
'   there are not files opened.
' - When the number of tabs excedeed a certain amount and closing one file caused the tabs
'   to scroll they weren't redraw. Fixed deleting all the tabs and inserting them again.
' October 4, 2004 : Version 1.14
' - New shortcut keys: Ctrl+Alt+P (Page setup), Ctrl+Alt+O (Command prompt), Ctrl+Alt+Y
'   (Set primary source file), Ctrl+F10 (Visual designer), Ctrl+F9 (Poffs).
' September 30, 2004 : Version 1.14
' - Changed (in SED_113.BAS)
'      CASE %IDCANCEL
'         ' Return the focus to the edit control
'         IF GetFocus = hCodeFinder THEN
'   to:
'      CASE %IDCANCEL
'         ' Return the focus to the edit control
'         IF GetFocus = hCodeFinder THEN
'            SED_ResetCodefinder
'            SetFocus GetEdit
'         end if
'         exit function
'   to solve a problem of the editor returning to a wrong document after selecting an
'   item with the codefinder using the keyboard and then pressing ESC twice.
'   Thanks to Zori de Marco for spotting it.
' September 28, 2004 : Version 1.14
' - Added an exe version of GotCha (GotxhaEx.exe), callable from the Tools menu or using the
'   shortcut key Ctrl+Shift+J. This allows to cut code in Gotcha and paste it into editor and
'   to have several instances of GotCha running at the same time.
' September 27, 2004 : Version 1.14
' - The projects docking window can be used also to see the results of the compiler. It can be
'   dragged and tracked. Please note that when it is placed in the bottom side of the screen
'   you must click in the double line at the left of the window to drag it, instead of in the
'   caption. This is because if the splitter bar and the caption were together we will be unable
'   to perform tracking.
'   F12 toggles between showing the projects tree or the compiler results (you can also switch
'   views clicking the small arrow button at the top keft corner of the window).
'   Shift+F12 hides the Projects/Messages window and Ctrl+F12 shows it. You can also hide
'   this window clicking the small "x" button placed at the top right side. Please note that
'   the project is not closed, but hidden.
'   If a document is open, you can hide or show the projects/messages window clicking the
'   right button and selecting the appropiate option in the context menu.
'   Note: There is no need to have a project openened to be able to use the messages window.
'   In this case, the editor will create an in-memory empty project titled "NoName.spf".
' September 26, 2004 : Version 1.14
' - The full paths of the loaded files are stored in the array g_TabFilePaths() to solve a
'   problem that happened when you loaded two files with the same name from different paths.
' - Fixed several redrawing problems of the docking projects window in XP.
' - Modified Gotcha (used in the Find in Files option) to fix some redrawing problems in Windows XP.
' September 24, 2004 : Version 1.14
' - The "Code analyzer" can be called using the shortcut key Ctrl+Shift+Y and the results are
'   now shown in a new window of the editor.
' September 8, 2004: Version 1.14
' - The procedures SED_WithinProc, SED_GotoBeginProc and SED_GotoEndProc didn't worked properly
'   if the sub/function contained a line like END IF: EXIT FUNCTION. Thanks to Charles Dietz
'   for reporting it.
' September 5, 2004 : Version 1.13
' - Keyboard modifications: By request of several users, now you can copy with Ctrl+Ins and
'   paste with Shift+Ins, besides Ctrl+C and Ctrl+V.
' - Added "Backup editor files" in the Editor Options dialog. When saving files, the editor will
'   rename the previous disk file with the .BAK file extension, and save the latest copy under
'   the original filename.
' - Modified the SED_SaveLoadedFilesPaths and SED_LoadPreviousFileSet procedures to save also
'   the bookmarks. Thanks to Jordi Valls for his suggestion and for providing some code.
' - Bug fix: When saving or loading a file with the Trim trailing blanks option checked
'   only one for each line was removed. Thanks to Jordi Valls for spotting it.
' September 4, 2004 : Version 1.13
' - Added a post-processor (see comments in the file SED_POSP.INC).
'   You must check the Menu-->Options-->Editor-->Call post-processor option.
'   Coded by Theo Gottwald: yposp@it-berater.org
' September 2, 2004 : Version 1.13
' - Added a new option called "Load project". It shows the project window and loads all the
'   files that belong to the project.
' - Bug fix: Files belonging to a project didn't always close when the project was closed.
' September 1, 2004 : Version 1.13
' - Added a new option (Menu-->Options-->Editor) called "Attach resources". It creates a
'   resource file on the fly with the text placed after '% RC TEXT comments and attaches it to
'   the exe file. Code written by Semen Matusovski and used with his permission.
'   Example of comments added to the header of the main .bas file to create a resource file:
    '% RC TEXT #include "c:\pbwin\winapi\resource.h"
    '% RC TEXT
    '% RC TEXT OemIcon      ICON Oem.Ico
    '% RC TEXT SelectedIcon ICON Selected.Ico
    '% RC TEXT
    '% RC TEXT // Version information
    '% RC TEXT VS_VERSION_INFO VERSIONINFO
    '% RC TEXT   FILEVERSION 1,2,10,0
    '% RC TEXT   PRODUCTVERSION 1,2,10,0
    '% RC TEXT   {
    '% RC TEXT   BLOCK "StringFileInfo"
    '% RC TEXT     {
    '% RC TEXT     BLOCK "040904E4"
    '% RC TEXT       {
    '% RC TEXT         VALUE "CompanyName",      "Semion Matusovskiy"
    '% RC TEXT         VALUE "FileDescription",  "Dll-spy for PbEdit/CcEdit"
    '% RC TEXT         VALUE "FileVersion",      "1.02"
    '% RC TEXT         VALUE "InternalName",     "PrePbEd.Dll"
    '% RC TEXT         VALUE "LegalCopyright",   "Public Domain"
    '% RC TEXT         VALUE "OriginalFilename", "PrePbEd.Dll"
    '% RC TEXT         VALUE "ProductName",      "PrePbEd for PB/WIN 7.* and PB/CC 3.*\0"
    '% RC TEXT         VALUE "ProductVersion",    "1.2\0"
    '% RC TEXT       }
    '% RC TEXT     }
    '% RC TEXT   BLOCK "VarFileInfo" { VALUE "Translation", 0x409, 1252 }
    '% RC TEXT   }
' August 31, 2004 : Version 1.13
' - Added the code below at the end of the ReplaceAll code to fix a bug that locked the editor
'   if you tried to do a replace all action having the searched word selected. This caused to
'   enter in an infinite loop. Thanks to Wayne Hill for reporting it.
'   IF endPos <= startPos THEN
'      MessageBox(BYVAL hFind, FORMAT$(numItems) & " replacements  ", " Replace all", _
'         %MB_OK OR %MB_ICONINFORMATION OR %MB_APPLMODAL)
'      EXIT DO
'   END IF
' June 24, 2004: Version 1.13: Changes by Stefan Menner:
' - Recently I noticed that popup menus do not appear next to the mouse when the SED main window
'   is located on the secondary display. (I love to work using two monitors.)
'   These are the changes to fix this.
'   In FUNCTION CodeProc
'   - I added a variable "LOCAL Pt AS PointApi"
'   - Right before TrackPopupMenu i inserted "GetCursorPos PT"
'   - I changed the TrackPopupMenu to look like this "TrackPopupMenu hPopupMenu, 0, PT.x, PT.y, 0, hWnd , BYVAL 0"
' June 19, 2004: Version 1.13: Changes made by Steve Miltiadous:
' - "When I have an instance of SED running and I dblclick on a SED project file, BAS file,
'   "INC file etc.. it reloads the last fileset which I think is wrong in this case
'   "Because I just want to work with the new files.
'   "So I changed the following line in WINMAIN procedure.
'   "  IF ISTRUE EdOpt.ReloadFilesAtStartup and LEN(COMMAND$) = 0 THEN
'   "     SED_LoadPreviousFileSet
'   "  END IF
' - "Another small change to put the caret when opening the last files in the middle of the
'   "window instead the top.
' - "Some changes for SED to work smoother with project files.
'   "1. If a project is active and has a primary file you can compile/run the file even if the
'   "   primary is not open.
'   "2. If the primary source file is different from the projects primary and you close it then
'   "   the primary source results to the project's primary (if it has one) and tool buttons
'   "   for compile/run are enabled.
'   "3. I save/load the last project with the last files.
'   "4. If you close all files with a project active then the primary source file results to
'   "   the project's primary.
' June 15, 2004: Version 1.12.2
' - Added "Reload previous file set at start" (in the "Editor options").
'   The files that were previously open in the editor are reloaded automatically the next time
'   the editor starts up. The caret position(s) are maintained.
' - Added "Start in last folder" (in the "Editor options"). If checked, SED changes to this
'   directory when it is started.
' - The codefinder combobox is not longer automatically closed when you press a key. Now it
'   stays open, allowing to press more keys or navigate with the up and down arrows. Press Escape
'   to close the dropdown list and Escape again to return to the edit control.
' - Added the following hot keys:
'   Alt+F7 : Loads the file that has the same name that the one under the caret.
'   Ctrl+F7 : Searches the function or procedure that has the same name that the one under the caret.
'   Shift+F7 : Returns to the last saved position.
' - Non available options in the popup menu are now removed instead of grayed to keep his size
'   more manageable.
' June 14, 2004: Version 1.12.2
' - F3 will search always downwards and a new keystroke, Shift+F3 has been added to search always backwards.
' June 14, 2004: Version 1.12.2
' - Added "Execute without compiling" (in the "Run" menu). Hot key: Ctrl+Shift+E.
' - Changed hot key to run Explorer from Ctrl+Shift+E to Ctrl+Shift+O.
' June 14, 2004: Version 1.12.2
' - Modified the SED_CodeFinder procedure to deal with syntaxes like:
'      FUNCTION _
'         MyFuncName ( _
'            BYVAL lVar1 AS LONG, _
'            sVar2 AS STRING _
'         ) AS LONG
'      END FUNCTION
' June 13, 2004: Version 1.12.2
' - Modified the line p1 = INSTR(buffer, "Error") to
'                     p1 = INSTR(buffer, $CRLF & "Error ")
'   to fix a bug that prevented to run a file with "Error" in the name.
' May 30, 2004: Version 1.12.1
' - Added "More Tools..." in the "Tools" menu. It calls the program SED_TOOLS.EXE that allows
'   to create and manage a database with the names and paths of external tools.
'   - To add a tool to the database fill the fields Name, Path and Parameters (optional) and
'     click the Save button.
'   - The Clear button clears the input fields.
'   - To delete a tool select it in the listbox and click the Delete button.
'   - To Update a tool, change the path and/or parameters and click Save.
'     Note: Since the Name of the tool is used as the index, if you need to change it you need
'     to delete the entry and add a new one.
'   - To execute a tool, select it in the listbox and click the Execute button or simply double
'     click his name in the listbox.
' May 29, 2004: Version 1.12
' - Added "Find in Files" in the "Search" menu. Adaptation of the GotCha.bas by Pierre Bellisle.
'   GotCha.bas, version 3.26 - http://www.powerbasic.com/support/forums/Forum7/HTML/001726.html
'   Note: The added "Load" button closes GotCha and loads the file in the editor.
' - Added "Windows Find" in the "Search" menu. Calls the Windows' Find program.
' May 25, 2004: Version 1.12
' - Added a Message box designer to the Tools menu. Coded by Pierre Bellisle based on a pevious
'   work by Greg Turgeon.
' May 19, 2004: Version 1.12
' - Added "Show caret line" to the "Editor options" and "Caret line" to the "Colors and Fonts"
'   dialog. If this option is checked, the line under the caret will be shown in the background
'   color selected (the default color is yellow).
' May 15, 2004: Version 1.12
' - Modified the Autocompletion function to scan all loaded files and to include the matching
'   function names of the codetips database in the list of words that will appear in the listbox.
'   Remember that to activate the autocompletion listbox you must type at least two characters
'   and press Ctrl+Enter or Ctrl+Spacebar.
' - Modified the Codetips builder tool to index also the constants. These constants will appear
'   also in the Autocompletion listbox.
' May 8, 2004: Version 1.12
' - Modified the scanning routines of the Codetips builder tool to make them a bit faster and to
'   show action while they are working.
'   Note: Pre-built .TRM files for codetips and types are included in this version.
' - Added extension checking to the functions that load the files to allow loading of BAS, INC
'   and RC files containing non-ASCII characters.
' May 4, 2004: Version 1.12
' - Added up to four recent project files to the project menu, in the same fashion as the most
'   recent files. This allows to quickly reload a project without having to navigate to the folder
'   where the project file is located. Coded by Steve Miltiadous.
' May 4, 2004: Version 1.11
' - New optional feature: "Trim trailing blanks" (in the "Editor options"). Removes trailing
'   spaces and tabs when loading or saving a file.
' - New optional feature: "Show sub/function name" (in the "Editor options"). Shows in the
'   Codefinder the name of the sub or function where you are. Coded by Steve Miltiadous.
'   Note: Since this feature slows down the editor when dealing with long files such Win32Api.inc,
'   that don't have functions (only constants and declares), a shortcut key, Ctrl+Shift+S, has
'   been provided to quickly toggle this option on or off.
' May 3, 2004: Version 1.11
' - New shortcuts: Ctrl+Up Arrow and Ctrl+Down Arrow - Scrolls the screen up and down.
' - New shortcuts: Ctrl+Shift+Up Arrow and Ctrl+Shift+Down Arrow - Goes to the beginning/end
'   of the sub/function.
' - New shortcuts: Ctrl+Alt+Up Arrow and Ctrl+Alt+Down Arrow - Goes to the beginning/end
'   of the sub/function within that sub/function.
' - Added a check in the Projects_OpenThisFile to see if the primary file still exists to
'   avoid the creation of an empty file.
' - Added "Replace Spaces with Tabs" and "Replace Tabs with Spaces" (in the "View" menu).
' April 23, 2004: Version 1.11
' - Fixed a bug that prevented to run a program if it had the .EXE extension in the #COMPILE
'   metastatement, e.g. "#COMPILE EXE "ProgName.EXE"
' April 20, 2004: Version 1.11
' - Added the CloseProjectFiles procedure to close only the files that belong to the project
'   being closed.
' - Added double quotes to strExeFile to deal with long file names.
' April 19, 2004: Version 1.11
' - Modified the SED_CompileResource procedure to make uppercased comparations of the directory names.
' - Fixed a bug in the %IDM_COMPILEANDRUN rotuine that caused a reloading of the file if an
'   error happened during compiling.
' April 18, 2004: Version 1.10
' - Added four new accelerator keys: Ctrl+Shift+H (hides the project window), Ctrl+Shift+R
'   (restores the project window), Ctrl+Shift+UpArrow (goes to the begining of the sub/function),
'   Ctrl+Shift+DownArrow (goes to the end of the sub/function).
'   Note: Ctrl+Shift+H and Ctrl+Shift+R have been changed to Shift+F12 and Ctrl+F12 in version 1.14.
' - Fixed a bug in the Search/Replace all option. The end position needed to be recalculated
'   after each replace of the text since the length of the file or the selection is changed if
'   the replace text is shorter or longer.
' - Added an image, and a tooltip showing the full path of the file, to the tabs.
' - Added the Save File As and Close buttons to the toolbar.
' April 17, 2004: Version 1.10
' - New feature coded by Steve Miltiadous: The "Project" menu has options to allow to work with
'   projects. The projects docking window uses a TreeView that allows you do several actions like
'   adding or removing files to the project using the trackmenu that appears when you right click
'   the mouse over one of the items of the TreeView. Double clicking a file loads it into the
'   editor.
' - New feature coded by Steve Miltiadous: The "Codetype Builder" (in the "Tools" menu) allows to
'   build a database of TYPEs. Then, if the "Autocomplete types" checkbox (in the "Editor options")
'   is checked, the editor shows a listbox with the stored types after you tpe " AS ".
' - Modified the indent, format and autocompletion routines to take into account if the Use Tabs
'   option is active and replace spaces with tabs according the tab size.
' - Fixed a bug in the Convert to html option: some keywords were not coloured.
' March 5, 2004: Version 1.10
' - Added the SED_Shell function as workaround to a problem with the WOW32 layer in W2K and XP
'   when calling the PB compiler. The function detects the OS version and uses the SHELL procedure
'   with Win9x and CreateProcess with WinNT platforms.
' March 3, 2004: Version 1.10
' - Added a manifest file for XP themes and made a few adjustements to the menu and the dialogs.
' February 26, 2004: Version 1.10
' - Changed the code that searches for the file when an error occurs during compiling to work
'   properly when the error resides in an include file.
' - Added an icon to the MDI windows system menu.
' February 25, 2004: Version 1.10
' - Replaced the function SED_FormatRegion by a modified one written by Steve Miltiadous to
'   solve an small problem with formatting.
' - Added two new options to the context menu: A find option that uses Lynx to retrieve a
'   Sub/Function, even if it is in another file, as long as the file is included in the list
'   of files of the Lynx project (if Lynx is not active, it has the same effect that pressing
'   the F1 key), and a "Go Back" option, that returns to the previous position after a search
'   with Lynx.
' February 22, 2004: Version 1.09b
' - Fixed a couple of issues with untitled files: The current directory changed to the temporary
'   one and, when an error happened, a new window was created.
'   Thanks to Steve Miltiadous for reporting it.
' - Added code to the Find Files dialog to save the last used path.
' February 21, 2004: Version 1.09b
' - Modified the menu, track menu and context menu to fix a problem with the "&" shortcuts.
'   Also added numbers to the recent files.
' - Changed the order of the Indent/Unindent and Comment/Uncomment icons and designed a new
'   icon for the Compile and Debug option.
' - Added code to the Charmap dialog to save the last used font.
' - Replaced the SED_FormatRegion procedure with a modified one to fix a problem with operators
'   inside strings and also with line continuation underscores. Code by Steve Miltiadous.
' - Added a fix to the SED_PrintDoc function to replace tabs with spaces.
'   Thanks to Don Dickinson for reporting it and for providing the fix.
' February 17, 2004: Version 1.09
' - Added options in the "Help" menu to launch the default browser and connect with the SED
'   web page, the PowerBasic page, the MSDN home page or Google.
' - Added the "Explore" option in the "Search" menu (shortcut: Ctrl+Shift+E). Launches Explorer
'   in the current directory, which you can use to drag and drop files to the editor.
' - Supressed the "Reopen" nested menu: Now the recent files are listed in the "File" submenu.
'   Modified the recent files track popup menu and the context menu to make them ownerdraw.
'   New bitmap strips incorporate icons for the tools and new options. Bookmark icons by
'   courtesy of Paul Squires.
' - Added "Character map" to the "Tools" menu. It is an adaptation of Borje Hagsten's public
'   domain program charmap2.bas. I have modified it to allow to insert characters directly
'   into the editor, without the need of copy and paste them.
' February 16, 2004: Version 1.09
' - Added support to compile and run untitled files by saving them in the Windows temporary
'   folder. It can be useful for quick tests that you don't want or don't need to save.
'   Based on an idea and sample code by Steve Miltiadous.
' February 14, 2004: Version 1.09
' - Fixed a bug in the SED_FormatRegion. It was adding an space between the ")" and the "." in
'   arrays in user defined types.
' - Fixed a bug in the compile and run option. The name of the file never matched with the
'   one of the window causing to be reloaded.
' February 10, 2004: Version 1.09
' - Added a call to EnumMdiTitleToTab to activate the associated tab when the user changes
'   of window using the Window submenu. Thanks to Steve Miltiadous for this fix.
' - Removed an unneeded EXIT DO in the ShowSetPrimarySourceFileDialog function.
'   Thanks to Wayne Hill for spotting it.
' - Removed EOF checking to allow editing of files saved with DOS editors.
'   Thanks to Steve Miltiadous for reporting this problem.
' February 8, 2004: Version 1.08
' - Added Wayne Hill's modifications to his previous code to deal with primary source files.
' February 7, 2004: Version 1.08
' - Added a tabbed interface. Code provided by Steve Miltiadous, based on public domain code by
'   Jules Marchildon. Made minor modifications to integrate it in the editor and added code to
'   the OpenThisFile function to activate the correct tab when reloading a file, to the
'   %IDM_SWITCHWINDOW message to activate the correct tab when switching windows and to the
'   SaveFile function to change the name of the tab in case the file is saved with other name.
' February 6, 2004: Version 1.08
' - Fixed a bug with the Colors and Fonts popup dialog that caused a wrong repaint of the main
'   window. Thanks to several users that reported it.
' - Added two new options: "Format text" (Ctrl+B), that strips excess of spaces and adds spaces
'   between operators if needed, and "Tabulate text", that tabulates the selected text.
'   Code contributed by Steve Miltiadous.
' - Added counters for untitled bas and html files.
' - Added detection for STATIC FUNCTION and STATIC SUB in the CodeFinder procedure.
' February 4, 2004: Version 1.08
' - Modified the ownerdraw menu routines to solve some problems with alignment of keyboard
'   accelerator names and to change the menu's look.
' - Added "Submenu text" and "Submenu highlighted text" to the "Colors and Fonts options" to
'   allow to customize the submenu colors.
' - Added the "Calculator" option in the Tools menu.
' - Fixed an small bug in the Replace all routine. Thanks to Carlo Pagani for reporting it.
'   http://www.powerbasic.com/support/forums/Forum8/HTML/002646.html
' February 3, 2004: Version 1.08
' - Fixed a bug in the ShowSetPrimarySourceFileDialog function. The tooltip was not updated
'   with text from the combobox. Thanks to Wayne Hill for reporting it.
' - Modified the SED_ProcessCommandLine procedure to work properly in XP. Thanks to Colin
'   Schmidt for reporting it and for providing code to fix the problem.
' February 1, 2004: Version 1.07
' - Changed the "Reopen file" behavior. Now it checks for the existence of the file and if it
'   doesn't exist shows a message and cleans himself. The trackmenu of the toolbar does the
'   cleanup automatically, before showing the recent files list.
' - Added the "Set primary source file" option. Thanks to Wayne Hill for providing the code.
' January 30, 2004: Version 1.07
' - Added the "Compile and Debug" option (F6 key). It forces the PB IDE to load the file and
'   activates the Compile and Debug option. Instead of launching the compiler each time, it
'   uses any instance of the compiler already running.
' January 29, 2004: Version 1.07
' - Added compilation of resource files. When the file has an .RC extension, clicking the
'   Compile button calls to RC.EXE and PBRES.EXE to compile it. Thanks to Steve Miltiadous for
'   his suggestion and for providing sample code.
' - You can now add SED_PBWIN or SED_PBCC (in uppercase) in a comment line to select the
'   default compiler without the need to change the editor options. Thanks to Don Ewald for
'   suggesting this and for providing some sample code.
' January 28, 2004: Version 1.07
' - Modification: pressing Ctrl+P or choosing the Print File menu option will show the Print
'   dialog, but clicking the toolbar print button will print directly without showing it.
' - Fixed a printing problem: The calculation of the printing area was incorrect.
' January 27, 2004: Version 1.07
' - Added command line support. Syntax: SED_107 <progname> <line>
' - Added Lynx support. In the global settings of the editor you must fill the following fields:
'     o Editor path: <Your Path>
'     o Identify by class name. Class name = SED
'     o Line syntax: *F *L
'   Thanks to Steve Miltiadous for his suggestion and for providing sample code.
' January 26, 2004: Version 1.07
' - Added "Andale Mono" to the list of monospaced fonts in the "Page setup" dialog.
' - Fixed the misplaced Insert button in the "Code keeper" dialog.
' - Added code to remove the last function from the code finder list box after opening/reopening
'   a new file. Thanks to Steve Miltiadous for reporting this.
' January 25, 2004: Version 1.06
' - Added a Printer setup dialog and the options "Print Preview" and "Print", that make use of
'   Don Dickinson's ddoc print and preview engine. Please, read the above license for terms of use.
'   Appropiate values for the printer setup are margins of 0.5 inches, Courier New font with a
'   size of 10 points and a line height of 0.17 inches (6 lines for inch). Allows printing of
'   selected text.
' - Added code written by Wayne Hill to the Compile/Compile and execute routine to switch to the
'   current child window with the error. If not available, the file with the error will be loaded
'   into the editor. The caret will be positioned at the error line at the top of the editor.
' - Added SetFocus GetEdit to the %CBN_SELCHANGE message of the CodeFinder to restore the focus
'   to the Scintilla control after selecting a function. Thanks to Steve Miltiadous for reporting this.
' January 24, 2004: Version 1.06
' - Changed the Find and Find and Replace behavior to search for selected text; if there is not
'   text selected, it will revert to the standard behavior. Thanks to Nick Melnick for the suggestion.
' - New lexer to correct a problem with the "()" always being in black color. Now appear in the
'   foreground and background colors selected for operators.
' January 23, 2004: Version 1.06
' - Added a "Code Keeper" option (F9). It allows to maintain a database of code snipets, templates
'   or even whole programs. To add a new record, write a name to identify it (40 characters
'   maximum), press return and enter o paste the text; then click the Save button. To modify a
'   record, write his name and press intro or select it in the combobox and press intro; made the
'   changes wanted and click the Save button. To delete a record, write his name and click delete.
'   To insert the contents of a record in the editor, write his or name or select it in the combobox
'   and click the Insert button. Backup the file, called "SCI_CODKP.TRM", in a regular basis to
'   restore it if it becomes corrupted.
' - Corrected a bug in the Find and Replace option. The routine was not replacing the first word
'   encountered, but the next, and was not searching for the next occurrence of the word.
'   Thanks to Nick Melnick for bring me the attention about it.
' January 22, 2004: Version 1.06
' - New bitmap strips made with icons kindly donated for the project by Marc Keeley of GlyFz.com.
' - Modified the menus and the toolbar to add these icons.
' January 21, 2004: Version 1.06
' - Modified the code under %IDC_CODEFINDER | %CBN_SELCHANGE to set the retrieved function or
'   procedure on top of the editor. Thanks to Wayne Hill for providing this tip.
' - The "Colors and Fonts" window became oversized when using high resolutions.
'   Thanks to several users that have reported this.
' - Disabled Scintilla context menu and implemented a custom one: it has more options and allows
'   to dowload the file under the caret (please note: the caret, not the cursor; the caret must
'   be positioned over the name of the file to download).
'   Thanks to Steve Miltiadous for the suggestion and for providing some sample code.
' January 20, 2004: Version 1.05
' - Added codetips. If there are more than one parameter, they are split in several lines.
'   The defined limits are 64 bytes for the name of the function or procedure and 512 bytes
'   for the parameters. For efficient storage, spaces are compressed. To append the declarations
'   of a file, simply select it and click Add. To replace modified declarations, follow the
'   same procedure: the old declarations will be replaced with the new. If you want to rebuild
'   the database from scratch, simply delete it and proceed to add files.
'   The indexed file is created with the use of the freeware Tsunami Record Manager 2.5.
'   Tsunami web page: http://www.trm-ug.com
' - Added "Codetips" to the menu of colors. Default is light gray on white, but you can choose
'   the colors that you want.
' - Changed GetWindowText GetEdit, BYVAL STRPTR(Buffer), LEN(Buffer) for
'   SendMessage GetEdit, %SCI_GETTEXT, BYVAL LEN(Buffer), BYVAL STRPTR(Buffer)
'   because GetWindowText has a limit of around 32Kb in 16-bit Window's versions.
'   Thanks to Nick Melnick for reporting this issue.
' January 18, 2004: Version 1.05
' - If the main window is resized, the window placement is saved and restored when the editor
'   is restarted. However, the zoom state (maximized or normal) is managed by the "Maximize
'   main window" option in the "Editor options" popup dialog. A new menu option, "Restore main
'   window size", in the "Window" menu, restores the default size.
' January 17, 2004: Version 1.05
' - New bitmap strips by Raymond L. King (the undo and redo buttons of one of them were reversed).
'   I have recompiled the resource file and changed the number of the icons in the ownerdraw menu.
' - Corrected the typo "Swicht Window".
' - Added support for #COMPILE "Progname.exe". Previously, the editor assumed that the exe file
'   name was the same as the .bas file.
' - Added checking of external changes. If another application changes the content of the file
'   being edited this is detected when the child window gets the focus and asks if you want
'   to reload it.
' - Changed the behavior of the Find and Find and Replace options. Now it retrieves the word
'   under the caret and fills the search edit box with it. If the caret is over a white space,
'   the search edit box is filled with the last word searched.
'   NOTE: I have remed the code because, after using it, I prefer the old behavior. Unrem the
'   code under CASE %IDM_FIND, %IDM_REPLACE if you want to add this feature.
' January 16, 2004: Version 1.05
' - Changed Ctrl+B to Ctrl+Shift+V the shortcut for copy and paste code using Internet Explorer.
'   This new shortcut looks more appropiate to me.
' - Modified the replace all routine: If there is selected text, the replacements are done only
'   within this selection.
' - Added the Refresh button to the toolbar: Reloads the file from disk. Useful when you want
'   to discard unsaved changes or have modified the file with another application.
' January 15, 2004: Version 1.05
' - Changed Shift+Q to Ctrl+Shift+Q for Uncomment shortcut.
' - Added the DP (for Debug Print) macro to allow debugging capabilities via OutputDebugString
'   using SysInternal's freeware application DebugView.
'   Another good freeware utility is PE Resource Editor (includes Delphi's source code)
'   http://www.wilsonc.demon.co.uk/d6peresourceeditor.htm
' - Added "Debug tool" option in the "Compiler options", callable from the "Run" menu option.
'   One good freeware debugging tool is DebugView. Provides a sort of enhanced Debug Print,
'   intercepting calls to the API function OutputDebugString. You can add the macro DP (short
'   for Debug Print to your program) and use it as, e.g. DP("Value: " & str$(value)).
' - You can control the activation of the debug macro with the constant:
'     %ENABLE_DEBUG = 0    ' 0 to disable debugging, 1 to enable
'   And use the macro:
'     MACRO DP(st)
'        #IF %ENABLE_DEBUG
'            OutputDebugString BYCOPY st
'        #ENDIF
'     END MACRO
' January 14, 2004: Version 1.04
' - Added a dialog to customize colors and fonts. You must select one of the items of the listbox,
'   select the wanted options, and click the "Apply" button. Repeat these operations for the other
'   items. Note: If you have a file loaded, you can see the results in real time.
' January 12, 2004: Version 1.03
' - Added a Folding Options dialog to the menu. It allows to choose the folding level: Sub/Function
'   level (SUBS, FUNCTIONSs, MACROS, TYPES and UNIONS), Keyword level (all folding) or none.
' - New lexer for Scintilla 1.58 by Raymond L. King.
'   Note: Due to the way the Scintilla control works, folding only works properly if SUB/END SUB,
'   FUNCTION/END FUNCTION, etc., starts at the first column, but this is not a high price to pay
'   to have such a nice feature!
' January 11, 2004: Version 1.03
' - Added "Find files" option, adaptation of Borje's public domain example FileFind.Bas.
'   Allows to search for an specified type of file.
' - Added "Convert to Html" option. Based on Borje's public domain program WebCoder.bas.
'   Converts the source code of the loaded program to html and shows it in a new window,
'   allowing to edit it and to save it.
' - Added CopyCat (another great Borje's tool) in the list of callable tools.
' January 10, 2004: Version 1.03
' - Added Template Code option (Ctrl+Shift+C). Generates SDK or DDT code templates for Main DIalog,
'   Popup dialog, button, checkbox, combobox, listbox, etc. The main dialog option provides an
'   skeleton ready to compile; then you can begin to add controls to it. There is also a
'   template that creates a resizable dialog skeleton with gradient.
' January 9, 2004: Version 1.03
' - Added Autocompletion. You must enter at least 2 letters (identifiers such % don't count)
'   and press Ctrl+Return. The program will scan the document to find all the words that begin
'   with these letters and show the result in a listbox. To select one of them press Tab or
'   Return; to exit, press Escape.
' - Added Command Line dialog (256 characters maximum).
' January 8, 2004: Version 1.03
' - Added IncLean in the Tools options.
' - Added several customization options to the Edit Options: Color Syntax Highlighting,
'   Code Tips, Maximize main window on startup, Maximize Edit Windows, Ask before exiting the
'   editor and Allow multiple instances of the editor.
' - Added drag and drop files.
' - The default compiler, PBWIN or PBCC, is now shown in the status bar.
' January 7, 2004: Version 1.03
' - Added a Code Analyzer (in the Tools menu), adaptation of Borje Hagsten's PBCODEC.BAS).
' - Added a Magnification spin control to set the zoom on startup (range: +20, -10 points).
' January 5, 2004: Version 1.03
' - Added Delete line keyboard shortcut (Ctrl+Y)
' - Changed Redo keyboard shortcut from Ctrl+Y to Ctrl+K
' - Added change of directory before compiling the program to allow the compiler to find
'   the include files.
' - When compiling, the loaded program is autosaved, but not the files in the other windows.
'   If you have loaded and modified an include file used by the program to compile, save it
'   before compiling.
' Dec 30, 2003: Version 1.03
' - Modified the help context algo to read the character before and after the word to be able
'   to analyze it. PowerBasic help needs that we pass the identifier when it is a constant, a
'   metastament or a function that ends with a $, but when calling the Win32Help file, if it is
'   a constant we have to strip the identifier (e.g. %WM_COMMAND is indexed as WM_COMMAND).
' - Modified the CreateSciControl to deal with untitled files. They are assumed to be .BAS
'   (the most frequent case) to allow syntax highlighting in new files not already saved.
' Dec 29, 2003: Version 1.02
' - Added Compiler Options popup dialog.
' - Added PBCC keywords.
' - Added creation of .BAK files in the SaveFile function.
' - Syntax highlighting is disabled if the file has not a .BAS, .INC or .BI extension.
' - Added Tools Options popup dialog. It allows to enter the paths of several tools and the
'   paths of the help files used by the context help (see below).
' - Added context sensitive help pressing F1.
' - Notes: Resource Hacker is a freeware resource editor. You can download it at:
'   http://www.users.on.net/johnson/resourcehacker/
' - Toolbar Paint is a Freeware bitmap strip maker. You can download it at:
'   http://donkey.visualassembler.com/
' Dec 28, 2003: Version 1.02
' - Added Editor Options dialog (changing these options doesn't affect to documents already loaded).
' - The tab size and the edge are expressed in characters; the widths of the line numbers and the
'   margin for folder symbols are expressed in pixels.
' - Use tabs option: Determines whether indentation should be created out of a mixture of tabs
'   and spaces or be based purely on spaces.
' - Tab size: Sets the tab size (1 to 8); 0 sets the default value (8).
' - Indent size: Sets the indent size (1 to 8); 0 sets the default (= tab size).
' - End of line option: Shows or hides the end of line characters.
' - Added options to convert end of line characters to $CRLF, $CR or $LF
' Dec 22, 2003: Version 1.02
' - Added "Paste IE" (Ctrl+B) to allow cut and pasting code using Internet Explorer.
' - Added "Whitespace" option (shows white spaces as dots).
' Dec 21, 2003: Version 1.01
' - Changed the toolbar routines to use image lists.
' - Changed standard menu to ownerdraw (code based on DrawMenu.bas, a public domain example by
'   Borje Hagsten, modified by Raymond L. King to use image lists).
' - Added zoom in/zoom out options (plus/minus 20 points).
' - Added "Go to line" poup dialog.
' - Added bookmarks.
' - Added block comment/uncomment (Ctrl+Q).
' - For block indent use Tab; for block unindent use Ctrl+Tab.
' Dec 14, 2003 - Version 1.00
' - Added ASM keywords.
' - Bug correction: "Save as..." option didn't show an overwrite warning.
' Dec 13, 2003 - Version 1.00
' - Added a code finder combobox.
' Dec 12, 2003 - Version 1.00
' - First version posted in the PowerBasic forums.
' *********************************************************************************************  