[EDIT.COM] Integrate EDIT.COM, based on the FreeDOS Edit port for Win32 by Carlo Bramini

CORE-11751
This commit is contained in:
Hermès Bélusca-Maïto
2025-11-01 20:34:05 +01:00
parent 420799228d
commit 3d51117282
87 changed files with 20374 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ add_subdirectory(comp)
add_subdirectory(cscript)
add_subdirectory(dbgprint)
add_subdirectory(doskey)
add_subdirectory(edit)
add_subdirectory(eventcreate)
add_subdirectory(fc)
add_subdirectory(find)

View File

@@ -0,0 +1,88 @@
list(APPEND DFLAT_SOURCE
fdeditw32/applicat.c
## fdeditw32/barchart.c
fdeditw32/box.c
fdeditw32/button.c
fdeditw32/calendar.c
fdeditw32/checkbox.c
fdeditw32/clipbord.c
fdeditw32/combobox.c
fdeditw32/config.c
fdeditw32/console.c
fdeditw32/decomp.c
fdeditw32/dfalloc.c
fdeditw32/dialbox.c
fdeditw32/direct.c
fdeditw32/editbox.c
fdeditw32/editor.c
fdeditw32/fileopen.c
fdeditw32/helpbox.c
fdeditw32/keys.c
fdeditw32/listbox.c
fdeditw32/lists.c
fdeditw32/log.c
fdeditw32/menu.c
fdeditw32/menubar.c
fdeditw32/message.c
fdeditw32/mouse.c
fdeditw32/msgbox.c
fdeditw32/normal.c
fdeditw32/pictbox.c
fdeditw32/popdown.c
fdeditw32/radio.c
fdeditw32/rect.c
fdeditw32/search.c
fdeditw32/slidebox.c
fdeditw32/spinbutt.c
fdeditw32/statbar.c
fdeditw32/sysmenu.c
fdeditw32/text.c
fdeditw32/textbox.c
fdeditw32/video.c
fdeditw32/watch.c
fdeditw32/window.c
)
add_library(dflat20_static ${DFLAT_SOURCE})
## FILES += timer_w32 country_w32 dir_w32 video_w32 console_w32 clipbord_w32
add_executable(huffc fdeditw32/huffc.c fdeditw32/htree.c)
set_module_type(huffc win32cui) ## UNICODE
add_importlibs(huffc user32 msvcrt kernel32)
add_executable(fixhelp fdeditw32/decomp.c fdeditw32/fixhelp.c)
set_module_type(fixhelp win32cui) ## UNICODE
add_importlibs(fixhelp user32 msvcrt kernel32)
# add_custom_target(edit_help DEPENDS ${rosapps_converted_item})
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/edit.hlp
COMMAND huffc fdeditw32/edit.txt ${CMAKE_CURRENT_BINARY_DIR}/edit.hlp
COMMAND fixhelp ${CMAKE_CURRENT_BINARY_DIR}/edit.hlp
DEPENDS huffc fixhelp)
list(APPEND EDIT_SOURCE
fdeditw32/dialogs.c
fdeditw32/edit.c
fdeditw32/menus.c
fdeditw32/rdonly.c
)
add_executable(edit ${EDIT_SOURCE} edit.rc)
target_compile_definitions(edit PRIVATE
INCLUDE_PICTUREBOX
INCLUDE_MULTI_WINDOWS
INCLUDE_WINDOWOPTIONS
INCLUDE_MAXIMIZE
INCLUDE_MINIMIZE
INCLUDE_RESTORE
INCLUDE_EXTENDEDSELECTIONS
_FDEDIT_PRIVATE_CLIPBOARD
)
set_module_type(edit win32cui) ## UNICODE
add_importlibs(edit user32 msvcrt kernel32)
set_target_properties(edit PROPERTIES OUTPUT_NAME "edit" SUFFIX ".com")
add_cd_file(TARGET edit DESTINATION reactos/system32 FOR all)

View File

@@ -0,0 +1,57 @@
#include <windef.h>
//#include "resource.h"
#define REACTOS_STR_FILE_DESCRIPTION "ReactOS EDIT Command"
#define REACTOS_STR_INTERNAL_NAME "edit"
#define REACTOS_STR_ORIGINAL_FILENAME "edit.com"
#include <reactos/version.rc>
/* UTF-8 */
#pragma code_page(65001)
//#ifdef LANGUAGE_BG_BG
// #include "lang/bg-BG.rc"
//#endif
//#ifdef LANGUAGE_DE_DE
// #include "lang/de-DE.rc"
//#endif
//#ifdef LANGUAGE_EN_US
// #include "lang/en-US.rc"
//#endif
//#ifdef LANGUAGE_ES_ES
// #include "lang/es-ES.rc"
//#endif
//#ifdef LANGUAGE_FR_FR
// #include "lang/fr-FR.rc"
//#endif
//#ifdef LANGUAGE_IT_IT
// #include "lang/it-IT.rc"
//#endif
//#ifdef LANGUAGE_PL_PL
// #include "lang/pl-PL.rc"
//#endif
//#ifdef LANGUAGE_RO_RO
// #include "lang/ro-RO.rc"
//#endif
//#ifdef LANGUAGE_RU_RU
// #include "lang/ru-RU.rc"
//#endif
//#ifdef LANGUAGE_SV_SE
// #include "lang/sv-SE.rc"
//#endif
//#ifdef LANGUAGE_SQ_AL
// #include "lang/sq-AL.rc"
//#endif
//#ifdef LANGUAGE_TR_TR
// #include "lang/tr-TR.rc"
//#endif
//#ifdef LANGUAGE_UK_UA
// #include "lang/uk-UA.rc"
//#endif
//#ifdef LANGUAGE_ZH_CN
// #include "lang/zh-CN.rc"
//#endif
//#ifdef LANGUAGE_ZH_TW
// #include "lang/zh-TW.rc"
//#endif

View File

@@ -0,0 +1 @@
make

View File

@@ -0,0 +1,6 @@
@ECHO OFF
REM Clean up everything
ECHO Cleaning...
del *.obj
del *.map
del *.lib

View File

@@ -0,0 +1,41 @@
+menu &
+window &
+video &
+message &
+mouse &
+console &
+normal &
+textbox &
+listbox &
+menubar &
+popdown &
+rect &
+applicat &
+keys &
+config &
+sysmenu &
+editbox &
+dialbox &
+button &
+msgbox &
+helpbox &
+lists &
+statbar &
+decomp &
+combobox &
+clipbord &
+search &
+fileopen &
+dfalloc &
+checkbox &
+text &
+radio &
+box &
+watch &
+slidebox &
+spinbutt &
+direct &
+log &
+calendar &
+pictbox &
+editor

View File

@@ -0,0 +1,31 @@
FreeDOS Edit 0.82
Based on DFLAT TUI toolkit as described in Dr. Dobbs Journal (DDJ)
See DFLAT.TXT for more information.
Compiling:
Tested with Borland's Turbo C 2.01 (TC2), Turbo C++ 1.01 (TC++1),
Turbo C/C++ 3.0 (TC3), and Borland C/C++ 3.1 (TC3/BC3)
Should also work with later versions.
To compile, 1st edit MAKEFILE to match your compiler, followed by
running 'make'. You may wish to then run clean to remove object
files and lib files, the executables (*.exe) will still be available.
(If compiling with TC3 or earlier? under NT, you may need to ensure
your environment space is not to cluttered, i.e. unset unneeded
environment variables, e.g. 'set PROCESSOR_IDENTIER=', etc. before make.)
Once compiled you may wish to compress with an executable compressor
such as UPX. If upx.exe is in your path, after make or instead of
'make all' you may run 'make upx' to build and then compress edit.exe
Known Issues:
- The beep() function in console.c produces warnings with TC3 if outp
macro is defined (you can #undef outp to remove them for TC3, but
TC++1 does not have an outp function only the macro).
- The keyboard routines block control-break, presently the control-break
handler is #ifdef'd out as it is unused; reenable if necessary (MESSAGE.C).
- See http://www.freedos.org/bugs/ for additional bugs or to report a bug.
20041022

View File

@@ -0,0 +1,71 @@
FreeDOS edit for Win32 (version 0.82)
---------------------------------------
FreeDOS edit is a text editor, originally written for DOS platforms.
This port to Win32 adds several bug fixes and improvements including:
1) the limit of 64 KBytes doesnt exist here.
2) direct access to console and mouse.
3) mouse wheel supported.
4) supports sleeping mode for inexpensive execution.
5) copy and paste text from the Win32 keyboard.
Excluding these changes, this version has the same look and feel of the DOS one, so I suggest you to read its documentation if you have some doubts.
This version has been tested and it worked fine on:
* Win98
* WinXP
* ReactOS 0.3.0
COMPILATION (MinGW)
--------------------
You need a working MinGW distribution for compiling the sources.
Everything is already configured, you just need to enter into the directory with sources and type:
> make
At the end you will have two files: "edit.exe" and "edit.hlp".
If you get an error when executing "huffc.exe" and/or "fixhelp.exe", probably you lanched the process out of the MSYS enviroment.
In this case, you can complete the process manually by typing:
> huffc edit.txt edit.hlp
and then:
> fixhelp edit
That's all.
COMPILATION (MSVC)
-------------------
As you can see, I don't provide Microsoft VisualC projects.
Sorry, but I don't own those development tools.
However, it shouldn't be too difficult to make the projects yourself.
Just remember to add these definitions to the preprocessor:
INCLUDE_PICTUREBOX
INCLUDE_MULTI_WINDOWS
INCLUDE_WINDOWOPTIONS
INCLUDE_MAXIMIZE
INCLUDE_MINIMIZE
INCLUDE_RESTORE
INCLUDE_EXTENDEDSELECTIONS
and everything should work fine.
TODO
-----
* Adding support for hardware tabs (selectable).
* Some OEM keys may be unsupported.
* Quick switch between windows (with "ALT + number").
* Fixing some bugs still hidden somewhere.
* It would be nice to have a common timer code, but separated from MESSAGE.C for all platforms. The porter will have to implement only a "GetTicks()" function for making it working.
CLOSING WORDS AND THANKS
-------------------------
Not much to say here...
I hope that this programme will be useful to all fans of text mode tools ;-)
More important, thanks to all people who made the original DOS source.
Last note, but not less important: don't use this editor for editing the files with hardware tabs, because this tool always expands them into spaces!
Carlo Bramini - 09/02/2007

View File

@@ -0,0 +1,15 @@
FreeDOS Edit Bugs
-----------------
The FreeDOS bug database is available at:
http://www.freedos.org/bugs
If you have a bug to report, do it there. Also, please email the maintainer,
Joe Cosentino, at hardmarine@comcast.net. Please do not fill out a bug
report for one that's already been reported.
Thanks,
Joe Cosentino
hardmarine@comcast.net

View File

@@ -0,0 +1,17 @@
The following people have helped with the development of FreeDOS Editor:
Dr. Dobb's Journal: Originally wrote the application, D-Flat, which Edit is
based on.
Shaun Raven: Fixed many bugs from D-Flat and made it more stable.
Joe Cosentino: Fixed lots more bugs, changed the user interface around,
added or fixed 90% of additional features.
Eric Auer: Fixed many bugs including the file handling bugs and
the AltGr bug.
Jeremy Davis: Added the Control+Break Handler, added additional video
functions.
Nagy Daniel: Fixed the bug that turned TAB's into circles.

View File

@@ -0,0 +1,339 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
675 Mass Ave, Cambridge, MA 02139, 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.
GNU GENERAL PUBLIC LICENSE
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
Appendix: How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) 19yy <name of author>
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.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) 19yy name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.

View File

@@ -0,0 +1,14 @@
Begin3
Title: Edit
Version: 0.82
Entered-date: 22 Oct 2004
Description: FreeDOS improved clone of MS-DOS Edit
Keywords: Edit Editor
Author: Joe Cosentino <hardmarine@comcast.net>
Maintained-by: Joe Cosentino <hardmarine@comcast.net>
Primary-site: http://www.geocities.com/xsaintx69/freedos
Alternate-site: http://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/dos/edit
Original-site: http://www.geocities.com/xsaintx69/freedos
Platforms: DOS
Copying-policy: GPL
End

View File

@@ -0,0 +1,9 @@
0.82 beta 2 (20070228)
=======================
* Fixed bug: Window menu can crash program.
If there are no open windows, going to the Window menu (Alt-W) and pressing down causes a segmentation fault.
* Implemented support for Win32 clipboard.
0.82 beta 1 (20070209)
=======================
First write.

View File

@@ -0,0 +1,862 @@
/* ------------- applicat.c ------------- */
#include "dflat.h"
static int ScreenHeight;
static BOOL DisplayModified=FALSE;
WINDOW ApplicationWindow;
extern DBOX Display;
#ifdef INCLUDE_MULTI_WINDOWS
extern DBOX Windows;
#endif
#ifdef INCLUDE_LOGGING
extern DBOX Log;
#endif
#ifdef INCLUDE_SHELLDOS
static void ShellDOS(WINDOW);
#endif
static void CreateMenu(WINDOW);
static void CreateStatusBar(WINDOW);
static void SelectColors(WINDOW);
static void SetScreenHeight(int);
static void SelectLines(WINDOW);
static void SelectLoadBlank(void);
#ifdef INCLUDE_WINDOWOPTIONS
static void SelectTexture(void);
static void SelectBorder(WINDOW);
static void SelectTitle(WINDOW);
static void SelectStatusBar(WINDOW);
#endif
static WINDOW oldFocus;
#ifdef INCLUDE_MULTI_WINDOWS
static void CloseAll(WINDOW, int);
static void MoreWindows(WINDOW);
static void ChooseWindow(WINDOW, int);
static int WindowSel;
/* avoid allocation into a read-only region! */
static char Menu_1[] = "~1. ";
static char Menu_2[] = "~2. ";
static char Menu_3[] = "~3. ";
static char Menu_4[] = "~4. ";
static char Menu_5[] = "~5. ";
static char Menu_6[] = "~6. ";
static char Menu_7[] = "~7. ";
static char Menu_8[] = "~8. ";
static char Menu_9[] = "~9. ";
static char *Menus[9] = {
Menu_1,
Menu_2,
Menu_3,
Menu_4,
Menu_5,
Menu_6,
Menu_7,
Menu_8,
Menu_9,
};
#endif
static char Cwd[65];
#ifdef ENABLEGLOBALARGV
char **Argv;
#endif
/* --------------- CREATE_WINDOW Message -------------- */
static int CreateWindowMsg(WINDOW wnd)
{
int rtn;
ApplicationWindow=wnd;
ScreenHeight=SCREENHEIGHT;
getcwd(Cwd, 64);
if (!DisplayModified)
{
int i;
CTLWINDOW *ct, *ct1;
ct=FindCommand(&Display, ID_SNOWY, CHECKBOX);
if (!isVGA())
{
/* ---- Modify Display Dialog Box for EGA, CGA ---- */
if (isEGA())
ct1=FindCommand(&Display,ID_50LINES,RADIOBUTTON);
else
{
CTLWINDOW *ct2;
ct2=FindCommand(&Display,ID_COLOR,RADIOBUTTON)-1;
if (ct2)
{
ct2->dwnd.w++;
for (i=0;i<7;i++)
(ct2+i)->dwnd.x += 8;
}
ct1=FindCommand(&Display,ID_25LINES,RADIOBUTTON)-1;
}
if (ct && ct1)
for (i=0;i<6;i++)
*ct1++ = *ct++;
}
if (isVGA() || isEGA())
{
/* Eliminate the snowy check box */
ct=FindCommand(&Display, ID_SNOWY, CHECKBOX);
if (ct != NULL)
for (i=0;i<4;i++)
*(ct+i) = *(ct+2+i);
}
DisplayModified=TRUE;
}
#ifdef INCLUDE_WINDOWOPTIONS
if (cfg.Border)
SetCheckBox(&Display, ID_BORDER);
if (cfg.Title)
SetCheckBox(&Display, ID_TITLE);
if (cfg.StatusBar)
SetCheckBox(&Display, ID_STATUSBAR);
if (cfg.Texture)
SetCheckBox(&Display, ID_TEXTURE);
#endif
if (cfg.mono==1)
PushRadioButton(&Display, ID_MONO);
else if (cfg.mono==2)
PushRadioButton(&Display, ID_REVERSE);
else
PushRadioButton(&Display, ID_COLOR);
if (cfg.ScreenLines==25)
PushRadioButton(&Display, ID_25LINES);
else if (cfg.ScreenLines==43)
PushRadioButton(&Display, ID_43LINES);
else if (cfg.ScreenLines==50)
PushRadioButton(&Display, ID_50LINES);
if (cfg.snowy)
SetCheckBox(&Display, ID_SNOWY);
if (cfg.loadblank)
SetCheckBox(&Display, ID_LOADBLANK);
if (SCREENHEIGHT != cfg.ScreenLines)
{
SetScreenHeight(cfg.ScreenLines);
if (WindowHeight(wnd)==ScreenHeight || SCREENHEIGHT-1 < GetBottom(wnd))
{
WindowHeight(wnd)=SCREENHEIGHT;
GetBottom(wnd)=GetTop(wnd)+WindowHeight(wnd)-1;
wnd->RestoredRC=WindowRect(wnd);
}
}
SelectColors(wnd);
#ifdef INCLUDE_WINDOWOPTIONS
SelectBorder(wnd);
SelectTitle(wnd);
SelectStatusBar(wnd);
#endif
rtn=BaseWndProc(APPLICATION, wnd, CREATE_WINDOW, 0, 0);
if (wnd->extension != NULL)
CreateMenu(wnd);
CreateStatusBar(wnd);
SendMessage(NULL, SHOW_MOUSE, 0, 0);
return rtn;
}
/* --------- ADDSTATUS Message ---------- */
static void AddStatusMsg(WINDOW wnd, PARAM p1)
{
if (wnd->StatusBar != NULL)
{
if (p1 && *(char *)p1)
SendMessage(wnd->StatusBar, SETTEXT, p1, 0);
else
SendMessage(wnd->StatusBar, CLEARTEXT, 0, 0);
SendMessage(wnd->StatusBar, PAINT, 0, 0);
}
}
/* -------- SETFOCUS Message -------- */
static void SetFocusMsg(WINDOW wnd, BOOL p1)
{
if (p1)
SendMessage(inFocus, SETFOCUS, FALSE, 0);
inFocus=p1 ? wnd : NULL;
SendMessage(NULL, HIDE_CURSOR, 0, 0);
if (isVisible(wnd))
SendMessage(wnd, BORDER, 0, 0);
else
SendMessage(wnd, SHOW_WINDOW, 0, 0);
}
/* ------- SIZE Message -------- */
static void SizeMsg(WINDOW wnd, PARAM p1, PARAM p2)
{
BOOL WasVisible;
WasVisible=isVisible(wnd);
if (WasVisible)
SendMessage(wnd, HIDE_WINDOW, 0, 0);
if (p1-GetLeft(wnd) < 30)
p1=GetLeft(wnd)+30;
BaseWndProc(APPLICATION, wnd, SIZE, p1, p2);
CreateMenu(wnd);
CreateStatusBar(wnd);
if (WasVisible)
SendMessage(wnd, SHOW_WINDOW, 0, 0);
}
/* ----------- KEYBOARD Message ------------ */
static int KeyboardMsg(WINDOW wnd, PARAM p1, PARAM p2)
{
if (WindowMoving || WindowSizing || (int) p1==F1)
return BaseWndProc(APPLICATION, wnd, KEYBOARD, p1, p2);
switch ((int) p1)
{
case ALT_F4:
if (TestAttribute(wnd, CONTROLBOX))
PostMessage(wnd, CLOSE_WINDOW, 0, 0);
return TRUE;
#ifdef INCLUDE_MULTI_WINDOWS
case ALT_F6:
SetNextFocus();
return TRUE;
#endif
case ALT_HYPHEN:
if (TestAttribute(wnd, CONTROLBOX))
BuildSystemMenu(wnd);
return TRUE;
default:
break;
}
PostMessage(wnd->MenuBarWnd, KEYBOARD, p1, p2);
return TRUE;
}
/* --------- SHIFT_CHANGED Message -------- */
static void ShiftChangedMsg(WINDOW wnd, PARAM p1)
{
extern BOOL AltDown;
if ((int)p1 & ALTKEY)
AltDown=TRUE;
else if (AltDown)
{
AltDown=FALSE;
if (wnd->MenuBarWnd != inFocus)
SendMessage(NULL, HIDE_CURSOR, 0, 0);
SendMessage(wnd->MenuBarWnd, KEYBOARD, F10, 0);
}
}
/* -------- COMMAND Message ------- */
static void CommandMsg(WINDOW wnd, PARAM p1, PARAM p2)
{
switch ((int)p1)
{
case ID_HELP:
DisplayHelp(wnd, DFlatApplication);
break;
case ID_HELPHELP:
DisplayHelp(wnd, "HelpHelp");
break;
case ID_EXTHELP:
DisplayHelp(wnd, "ExtHelp");
break;
case ID_KEYSHELP:
DisplayHelp(wnd, "KeysHelp");
break;
case ID_HELPINDEX:
DisplayHelp(wnd, "HelpIndex");
break;
#ifdef INCLUDE_LOGGING
case ID_LOG:
MessageLog(wnd);
break;
#endif
#ifdef INCLUDE_SHELLDOS
case ID_DOS:
ShellDOS(wnd);
break;
#endif
case ID_EXIT:
case ID_SYSCLOSE:
PostMessage(wnd, CLOSE_WINDOW, 0, 0);
break;
case ID_DISPLAY:
if (DialogBox(wnd, &Display, TRUE, NULL))
{
if (inFocus==wnd->MenuBarWnd || inFocus==wnd->StatusBar)
oldFocus=ApplicationWindow;
else
oldFocus=inFocus;
SendMessage(wnd, HIDE_WINDOW, 0, 0);
SelectColors(wnd);
SelectLines(wnd);
SelectLoadBlank();
#ifdef INCLUDE_WINDOWOPTIONS
SelectBorder(wnd);
SelectTitle(wnd);
SelectStatusBar(wnd);
SelectTexture();
#endif
CreateMenu(wnd);
CreateStatusBar(wnd);
SendMessage(wnd, SHOW_WINDOW, 0, 0);
SendMessage(oldFocus, SETFOCUS, TRUE, 0);
}
break;
case ID_SAVEOPTIONS:
SaveConfig();
break;
#ifdef INCLUDE_MULTI_WINDOWS
case ID_WINDOW:
ChooseWindow(wnd, CurrentMenuSelection-2);
break;
case ID_CLOSEALL:
CloseAll(wnd, FALSE);
break;
case ID_MOREWINDOWS:
MoreWindows(wnd);
break;
#endif
#ifdef INCLUDE_RESTORE
case ID_SYSRESTORE:
#endif
case ID_SYSMOVE:
case ID_SYSSIZE:
#ifdef INCLUDE_MINIMIZE
case ID_SYSMINIMIZE:
#endif
#ifdef INCLUDE_MAXIMIZE
case ID_SYSMAXIMIZE:
#endif
BaseWndProc(APPLICATION, wnd, COMMAND, p1, p2);
break;
default:
if (inFocus != wnd->MenuBarWnd && inFocus != wnd)
PostMessage(inFocus, COMMAND, p1, p2);
break;
}
}
/* --------- CLOSE_WINDOW Message -------- */
static int CloseWindowMsg(WINDOW wnd)
{
int rtn;
#ifdef INCLUDE_MULTI_WINDOWS
CloseAll(wnd, TRUE);
WindowSel=0;
#endif
PostMessage(NULL, STOP, 0, 0);
rtn=BaseWndProc(APPLICATION, wnd, CLOSE_WINDOW, 0, 0);
if (ScreenHeight != SCREENHEIGHT)
SetScreenHeight(ScreenHeight);
UnLoadHelpFile();
DisplayModified=FALSE;
ApplicationWindow=NULL;
setdisk(toupper(*Cwd) - 'A');
chdir(Cwd+2);
return rtn;
}
/* --- APPLICATION Window Class window processing module --- */
int ApplicationProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
switch (msg)
{
case CREATE_WINDOW:
return CreateWindowMsg(wnd);
case HIDE_WINDOW:
if (wnd==inFocus)
inFocus=NULL;
break;
case ADDSTATUS:
AddStatusMsg(wnd, p1);
return TRUE;
case SETFOCUS:
if ((int)p1==(inFocus != wnd))
{
SetFocusMsg(wnd, (BOOL) p1);
return TRUE;
}
break;
case SIZE:
SizeMsg(wnd, p1, p2);
return TRUE;
#ifdef INCLUDE_MINIMIZE
case MINIMIZE:
return TRUE;
#endif
case KEYBOARD:
return KeyboardMsg(wnd, p1, p2);
case SHIFT_CHANGED:
ShiftChangedMsg(wnd, p1);
return TRUE;
case PAINT:
if (isVisible(wnd))
{
int cl=cfg.Texture ? APPLCHAR : ' ';
ClearWindow(wnd, (RECT *)p1, cl);
}
return TRUE;
case COMMAND:
CommandMsg(wnd, p1, p2);
return TRUE;
case CLOSE_WINDOW:
return CloseWindowMsg(wnd);
default:
break;
}
return BaseWndProc(APPLICATION, wnd, msg, p1, p2);
}
#ifdef INCLUDE_SHELLDOS
static void SwitchCursor(void)
{
SendMessage(NULL, SAVE_CURSOR, 0, 0);
SwapCursorStack();
SendMessage(NULL, RESTORE_CURSOR, 0, 0);
}
/* ------- Shell out to DOS ---------- */
static void ShellDOS(WINDOW wnd)
{
oldFocus=inFocus;
SendMessage(wnd, HIDE_WINDOW, 0, 0);
SwitchCursor();
if (ScreenHeight != SCREENHEIGHT)
SetScreenHeight(ScreenHeight);
SendMessage(NULL, HIDE_MOUSE, 0, 0);
printf("Type EXIT to return to %s.\n\n", DFlatApplication);
fflush(stdout);
spawnl(P_WAIT, getenv("COMSPEC"), NULL);
if (SCREENHEIGHT != cfg.ScreenLines)
SetScreenHeight(cfg.ScreenLines);
SwitchCursor();
SendMessage(wnd, SHOW_WINDOW, 0, 0);
SendMessage(oldFocus, SETFOCUS, TRUE, 0);
SendMessage(NULL, SHOW_MOUSE, 0, 0);
}
#endif
/* -------- Create the menu bar -------- */
static void CreateMenu(WINDOW wnd)
{
AddAttribute(wnd, HASMENUBAR);
if (wnd->MenuBarWnd != NULL)
SendMessage(wnd->MenuBarWnd, CLOSE_WINDOW, 0, 0);
wnd->MenuBarWnd=CreateWindow(MENUBAR, NULL, GetClientLeft(wnd), GetClientTop(wnd)-1, 1, ClientWidth(wnd), NULL, wnd, NULL, 0);
SendMessage(wnd->MenuBarWnd,BUILDMENU, (PARAM)wnd->extension,0);
AddAttribute(wnd->MenuBarWnd, VISIBLE);
}
/* ----------- Create the status bar ------------- */
static void CreateStatusBar(WINDOW wnd)
{
if (wnd->StatusBar != NULL)
{
SendMessage(wnd->StatusBar, CLOSE_WINDOW, 0, 0);
wnd->StatusBar=NULL;
}
if (TestAttribute(wnd, HASSTATUSBAR))
{
wnd->StatusBar=CreateWindow(STATUSBAR, NULL, GetClientLeft(wnd), GetBottom(wnd), 1, ClientWidth(wnd), NULL, wnd, NULL, 0);
AddAttribute(wnd->StatusBar, VISIBLE);
}
}
#ifdef INCLUDE_MULTI_WINDOWS
/* -------- return the name of a document window ------- */
static char *WindowName(WINDOW wnd)
{
if (GetTitle(wnd)==NULL)
{
if (GetClass(wnd)==DIALOG)
return ((DBOX *)(wnd->extension))->HelpName;
else
return "Untitled";
}
else
return GetTitle(wnd);
}
/* ----------- Prepare the Window menu ------------ */
void PrepWindowMenu(void *w, struct Menu *mnu)
{
WINDOW wnd=w,cwnd;
struct PopDown *p0=mnu->Selections;
struct PopDown *pd=mnu->Selections+2;
struct PopDown *ca=mnu->Selections+13;
int MenuNo=0;
mnu->Selection=0;
oldFocus=NULL;
if (GetClass(wnd) != APPLICATION)
{
oldFocus=wnd;
if (ApplicationWindow==NULL) /* Point to the APPLICATION window */
return;
cwnd=FirstWindow(ApplicationWindow);
/* ----- get the first 9 document windows ----- */
while (cwnd != NULL && MenuNo < 9)
{
if (isVisible(cwnd) && GetClass(cwnd) != MENUBAR && GetClass(cwnd) != STATUSBAR)
{
/* Add the document window to the menu */
strncpy(Menus[MenuNo]+4, WindowName(cwnd), 20);
pd->SelectionTitle=Menus[MenuNo];
if (cwnd==oldFocus)
{
/* -- mark the current document -- */
pd->Attrib |= CHECKED;
mnu->Selection=MenuNo+2;
}
else
pd->Attrib &= ~CHECKED;
pd++;
MenuNo++;
}
cwnd=NextWindow(cwnd);
}
}
if (MenuNo)
p0->SelectionTitle="~Close all";
else
p0->SelectionTitle=NULL;
if (MenuNo >= 9)
{
*pd++=*ca;
if (mnu->Selection==0)
mnu->Selection=11;
}
pd->SelectionTitle=NULL;
}
/* window processing module for the More Windows dialog box */
static int WindowPrep(WINDOW wnd,MESSAGE msg,PARAM p1,PARAM p2)
{
switch (msg)
{
case INITIATE_DIALOG:
{
WINDOW cwnd=ControlWindow(&Windows,ID_WINDOWLIST),wnd1;
int sel=0;
if (cwnd==NULL)
return FALSE;
wnd1=FirstWindow(ApplicationWindow);
while (wnd1 != NULL)
{
if (isVisible(wnd1) && wnd1 != wnd && GetClass(wnd1) != MENUBAR && GetClass(wnd1) != STATUSBAR)
{
if (wnd1==oldFocus)
WindowSel=sel;
SendMessage(cwnd, ADDTEXT, (PARAM) WindowName(wnd1), 0);
sel++;
}
wnd1=NextWindow(wnd1);
}
SendMessage(cwnd, LB_SETSELECTION, WindowSel, 0);
AddAttribute(cwnd, VSCROLLBAR);
PostMessage(cwnd, SHOW_WINDOW, 0, 0);
break;
}
case COMMAND:
switch ((int) p1)
{
case ID_OK:
if ((int)p2==0)
WindowSel=SendMessage(ControlWindow(&Windows, ID_WINDOWLIST), LB_CURRENTSELECTION, 0, 0);
break;
case ID_WINDOWLIST:
if ((int) p2==LB_CHOOSE)
SendMessage(wnd, COMMAND, ID_OK, 0);
break;
default:
break;
}
break;
default:
break;
}
return DefaultWndProc(wnd, msg, p1, p2);
}
/* ---- the More Windows command on the Window menu ---- */
static void MoreWindows(WINDOW wnd)
{
if (DialogBox(wnd, &Windows, TRUE, WindowPrep))
ChooseWindow(wnd, WindowSel);
}
/* ----- user chose a window from the Window menu or the More Window dialog box ----- */
static void ChooseWindow(WINDOW wnd, int WindowNo)
{
WINDOW cwnd=FirstWindow(wnd);
while (cwnd != NULL)
{
if (isVisible(cwnd) && GetClass(cwnd) != MENUBAR && GetClass(cwnd) != STATUSBAR)
if (WindowNo-- == 0)
break;
cwnd=NextWindow(cwnd);
}
if (cwnd != NULL)
{
SendMessage(cwnd, SETFOCUS, TRUE, 0);
if (cwnd->condition==ISMINIMIZED)
SendMessage(cwnd, RESTORE, 0, 0);
}
}
/* ----- Close all document windows ----- */
static void CloseAll(WINDOW wnd, int closing)
{
WINDOW wnd1, wnd2;
SendMessage(wnd, SETFOCUS, TRUE, 0);
wnd1=LastWindow(wnd);
while (wnd1 != NULL)
{
wnd2=PrevWindow(wnd1);
if (isVisible(wnd1) && GetClass(wnd1) != MENUBAR && GetClass(wnd1) != STATUSBAR)
{
ClearVisible(wnd1);
SendMessage(wnd1, CLOSE_WINDOW, 0, 0);
}
wnd1=wnd2;
}
if (!closing)
SendMessage(wnd, PAINT, 0, 0);
}
#endif /* #ifdef INCLUDE_MULTI_WINDOWS */
static void DoWindowColors(WINDOW wnd)
{
WINDOW cwnd;
InitWindowColors(wnd);
cwnd=FirstWindow(wnd);
while (cwnd != NULL)
{
DoWindowColors(cwnd);
if (GetClass(cwnd)==TEXT && GetText(cwnd) != NULL)
SendMessage(cwnd, CLEARTEXT, 0, 0);
cwnd=NextWindow(cwnd);
}
}
/* ----- set up colors for the application window ------ */
static void SelectColors(WINDOW wnd)
{
if (RadioButtonSetting(&Display, ID_MONO))
cfg.mono=1;
else if (RadioButtonSetting(&Display, ID_REVERSE))
cfg.mono=2;
else
cfg.mono=0;
cfg.snowy=CheckBoxSetting(&Display, ID_SNOWY);
get_videomode();
if ((ismono() || video_mode==2) && cfg.mono==0)
cfg.mono=1;
if (cfg.mono==1)
memcpy(cfg.clr, bw, sizeof bw);
else if (cfg.mono==2)
memcpy(cfg.clr, reverse, sizeof reverse);
else
memcpy(cfg.clr, color, sizeof color);
DoWindowColors(wnd);
}
static void SelectLoadBlank(void)
{
cfg.loadblank=CheckBoxSetting(&Display, ID_LOADBLANK);
}
/* ---- select screen lines ---- */
static void SelectLines(WINDOW wnd)
{
cfg.ScreenLines=25;
if (isEGA() || isVGA())
{
if (RadioButtonSetting(&Display, ID_43LINES))
cfg.ScreenLines=43;
else if (RadioButtonSetting(&Display, ID_50LINES))
cfg.ScreenLines=50;
}
if (SCREENHEIGHT != cfg.ScreenLines)
{
SetScreenHeight(cfg.ScreenLines);
if (wnd->condition==ISMAXIMIZED)
{
SendMessage(wnd, SIZE, (PARAM) GetRight(wnd), SCREENHEIGHT-1);
return;
}
/* --- adjust if current size does not fit --- */
if (WindowHeight(wnd) > SCREENHEIGHT)
SendMessage(wnd, SIZE, (PARAM) GetRight(wnd), (PARAM) GetTop(wnd)+SCREENHEIGHT-1);
/* --- if window is off-screen, move it on-screen --- */
if (GetTop(wnd) >= SCREENHEIGHT-1)
SendMessage(wnd, MOVE, (PARAM) GetLeft(wnd), (PARAM) SCREENHEIGHT-WindowHeight(wnd));
}
}
/* ---- set the screen height in the video hardware ---- */
static void SetScreenHeight(int height)
{
if (isEGA() || isVGA())
{
SendMessage(NULL, SAVE_CURSOR, 0, 0);
switch (height)
{
case 25:
Set25();
break;
case 43:
Set43();
break;
case 50:
Set50();
break;
default:
break;
}
SendMessage(NULL, RESTORE_CURSOR, 0, 0);
SendMessage(NULL, RESET_MOUSE, 0, 0);
SendMessage(NULL, SHOW_MOUSE, 0, 0);
}
}
#ifdef INCLUDE_WINDOWOPTIONS
/* ----- select the screen texture ----- */
static void SelectTexture(void)
{
cfg.Texture=CheckBoxSetting(&Display, ID_TEXTURE);
}
/* -- select whether the application screen has a border -- */
static void SelectBorder(WINDOW wnd)
{
cfg.Border=CheckBoxSetting(&Display, ID_BORDER);
if (cfg.Border)
AddAttribute(wnd, HASBORDER);
else
ClearAttribute(wnd, HASBORDER);
}
/* select whether the application screen has a status bar */
static void SelectStatusBar(WINDOW wnd)
{
cfg.StatusBar=CheckBoxSetting(&Display, ID_STATUSBAR);
if (cfg.StatusBar)
AddAttribute(wnd, HASSTATUSBAR);
else
ClearAttribute(wnd, HASSTATUSBAR);
}
/* select whether the application screen has a title bar */
static void SelectTitle(WINDOW wnd)
{
cfg.Title=CheckBoxSetting(&Display, ID_TITLE);
if (cfg.Title)
AddAttribute(wnd, HASTITLEBAR);
else
ClearAttribute(wnd, HASTITLEBAR);
}
#endif

View File

@@ -0,0 +1,35 @@
/* ----------- box.c ------------ */
#include "dflat.h"
int BoxProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
int rtn;
CTLWINDOW *ct = GetControl(wnd);
if (ct != NULL)
{
switch (msg)
{
case SETFOCUS:
case PAINT:
return FALSE;
case LEFT_BUTTON:
case BUTTON_RELEASED:
return SendMessage(GetParent(wnd), msg, p1, p2);
case BORDER:
rtn = BaseWndProc(BOX, wnd, msg, p1, p2);
if (ct != NULL && ct->itext != NULL)
writeline(wnd, ct->itext, 1, 0, FALSE);
return rtn;
default:
break;
}
}
return BaseWndProc(BOX, wnd, msg, p1, p2);
}

View File

@@ -0,0 +1,88 @@
/* -------------- button.c -------------- */
#include "dflat.h"
void PaintMsg(WINDOW wnd, CTLWINDOW *ct, RECT *rc)
{
if (isVisible(wnd)) {
if (TestAttribute(wnd, SHADOW) && cfg.mono == 0) {
/* -------- draw the button's shadow ------- */
int x;
background = WndBackground(GetParent(wnd));
foreground = BLACK;
for (x = 1; x <= WindowWidth(wnd); x++)
wputch(wnd, 223, x, 1);
wputch(wnd, 220, WindowWidth(wnd), 0);
}
if (ct->itext != NULL) {
unsigned char *txt;
txt = DFcalloc(1, strlen(ct->itext)+10);
if (ct->setting == OFF) {
txt[0] = CHANGECOLOR;
txt[1] = wnd->WindowColors
[HILITE_COLOR] [FG] | 0x80;
txt[2] = wnd->WindowColors
[STD_COLOR] [BG] | 0x80;
}
CopyCommand(txt+strlen(txt),ct->itext,!ct->setting,
WndBackground(wnd));
SendMessage(wnd, CLEARTEXT, 0, 0);
SendMessage(wnd, ADDTEXT, (PARAM) txt, 0);
free(txt);
}
/* --------- write the button's text ------- */
WriteTextLine(wnd, rc, 0, wnd == inFocus);
}
}
void LeftButtonMsg(WINDOW wnd, MESSAGE msg, CTLWINDOW *ct)
{
if (cfg.mono == 0) {
/* --------- draw a pushed button -------- */
int x;
background = WndBackground(GetParent(wnd));
foreground = WndBackground(wnd);
wputch(wnd, ' ', 0, 0);
for (x = 0; x < WindowWidth(wnd); x++) {
wputch(wnd, 220, x+1, 0);
wputch(wnd, 223, x+1, 1);
}
}
if (msg == LEFT_BUTTON)
SendMessage(NULL, WAITMOUSE, 0, 0);
else
SendMessage(NULL, WAITKEYBOARD, 0, 0);
SendMessage(wnd, PAINT, 0, 0);
if (ct->setting == ON)
PostMessage(GetParent(wnd), COMMAND, ct->command, 0);
else
beep();
}
int ButtonProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
CTLWINDOW *ct = GetControl(wnd);
if (ct != NULL) {
switch (msg) {
case SETFOCUS:
BaseWndProc(BUTTON, wnd, msg, p1, p2);
p1 = 0;
/* ------- fall through ------- */
case PAINT:
PaintMsg(wnd, ct, (RECT*)p1);
return TRUE;
case KEYBOARD:
if (p1 != '\r')
break;
/* ---- fall through ---- */
case LEFT_BUTTON:
LeftButtonMsg(wnd, msg, ct);
return TRUE;
case HORIZSCROLL:
return TRUE;
default:
break;
}
}
return BaseWndProc(BUTTON, wnd, msg, p1, p2);
}

View File

@@ -0,0 +1,254 @@
/* ------------- calendar.c ------------- */
#include "dflat.h"
#ifndef NOCALENDAR
#define CALHEIGHT 17
#define CALWIDTH 33
static int DyMo[]={31,28,31,30,31,30,31,31,30,31,30,31};
static struct tm ttm, ctm;
static int dys[42];
static WINDOW Cwnd;
#ifndef strftime
static char *nameOfMonth[12]={"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
#endif
/* Returns 1 if year (0-based, not 1900-based) is a leap year (longer) */
int isLeapYear(int year)
{
if (!(year % 400))
return 1; /* 2000 is a leap year */
if (!(year % 100))
return 0; /* 1900 and 2100 are not */
if (!(year % 4))
return 1; /* multiple of 4? Then it is a leap year */
return 0; /* default: not a leap year */
}
static void FixDate(void)
{
int i,j;
/* Adjust Feb for leap year */
DyMo[1]=isLeapYear(1900+ttm.tm_year) ? 29 : 28;
/* Enforce ranges: 1..?? for mday, 0..11 for mon */
while (ttm.tm_mday > DyMo[ttm.tm_mon])
{
ttm.tm_mday -= DyMo[ttm.tm_mon];
ttm.tm_mon++;
if (ttm.tm_mon > 11)
{
ttm.tm_mon=0;
ttm.tm_year++;
}
}
/* re-calculate yday in 0..??? range */
ttm.tm_yday=0;
i=0;
while (i < ttm.tm_mon)
{
ttm.tm_yday += DyMo[i];
i++;
}
ttm.tm_yday+=ttm.tm_mday-1;
/* 1st of January of 1900 (tm_year base) was a Monday (wday=1) */
i=0;
j=1;
if (ttm.tm_year >= 1980)
{
i=80;
j=2;
}
while (i < ttm.tm_year)
{
j += isLeapYear(i+1900) ? 2 : 1; /* shift 1 or 2 days each year */
if (j>6)
j -= 7;
i++;
}
ttm.tm_wday=(j + ttm.tm_yday) % 7; /* "day of year" helps us! */
}
/* ---- build calendar dates array ---- */
static void BuildDateArray(void)
{
int offset, dy=0;
memset(dys, 0, sizeof dys);
FixDate();
/* Compute the weekday for the 1st */
offset=((ttm.tm_mday-1) - ttm.tm_wday) % 7;
if (offset < 0)
offset += 7;
if (offset)
offset=(offset - 7) * -1;
/* Build the dates into the array */
for (dy=1; dy <= DyMo[ttm.tm_mon]; dy++)
dys[offset++]=dy;
}
static void CreateWindowMsg(WINDOW wnd)
{
int x, y;
DrawBox(wnd, 1, 2, CALHEIGHT-4, CALWIDTH-4);
for (x=5;x<CALWIDTH-4;x += 4)
DrawVector(wnd, x, 2, CALHEIGHT-4, FALSE);
for (y=4;y<CALHEIGHT-3;y+=2)
DrawVector(wnd, 1, y, CALWIDTH-4, TRUE);
}
static void DisplayDates(WINDOW wnd)
{
int week, day,offset;
char dyln[10],banner[CALWIDTH-1],banner1[30];
SetStandardColor(wnd);
PutWindowLine(wnd, "Sun Mon Tue Wed Thu Fri Sat", 2, 1);
memset(banner, ' ', CALWIDTH-2);
#ifndef strftime
sprintf(banner1, "%s, %i", nameOfMonth[ttm.tm_mon], 1900+ttm.tm_year);
#else
strftime(banner1, 16, "%B, %Y", &ttm);
#endif
offset=(CALWIDTH-2 - strlen(banner1)) / 2;
strcpy(banner+offset, banner1);
strcat(banner, " ");
PutWindowLine(wnd, banner, 0, 0);
BuildDateArray();
for (week=0;week<6;week++)
{
for (day=0;day<7;day++)
{
int dy=dys[week*7+day];
if (dy == 0)
strcpy(dyln, " ");
else
{
/* If current day of current month then highlight */
if ((dy == ctm.tm_mday) && (ctm.tm_mon == ttm.tm_mon))
sprintf(dyln, "%c%c%c%2d %c", CHANGECOLOR,
SelectForeground(wnd)+0x80,
SelectBackground(wnd)+0x80,
dy, RESETCOLOR);
else
sprintf(dyln, "%2d ", dy);
}
SetStandardColor(wnd);
PutWindowLine(wnd, dyln, 2 + day * 4, 3 + week*2);
}
}
}
static int KeyboardMsg(WINDOW wnd, PARAM p1)
{
switch ((int)p1)
{
case PGUP:
if (ttm.tm_mon == 0)
{
ttm.tm_mon=12;
ttm.tm_year--;
}
ttm.tm_mon--;
FixDate();
DisplayDates(wnd);
return TRUE;
case PGDN:
ttm.tm_mon++;
if (ttm.tm_mon == 12)
{
ttm.tm_mon=0;
ttm.tm_year++;
}
FixDate();
DisplayDates(wnd);
return TRUE;
default:
break;
}
return FALSE;
}
static int CalendarProc(WINDOW wnd,MESSAGE msg, PARAM p1,PARAM p2)
{
switch (msg)
{
case CREATE_WINDOW:
DefaultWndProc(wnd, msg, p1, p2);
CreateWindowMsg(wnd);
return TRUE;
case KEYBOARD:
if (KeyboardMsg(wnd, p1))
return TRUE;
break;
case PAINT:
DefaultWndProc(wnd, msg, p1, p2);
DisplayDates(wnd);
return TRUE;
case COMMAND:
if ((int)p1 == ID_HELP)
{
DisplayHelp(wnd, "Calendar");
return TRUE;
}
break;
case CLOSE_WINDOW:
Cwnd=NULL;
break;
default:
break;
}
return DefaultWndProc(wnd, msg, p1, p2);
}
void Calendar(WINDOW pwnd)
{
if (Cwnd == NULL)
{
time_t tim=time(NULL);
ttm=*localtime(&tim);
ctm=ttm; /* Store current calendar day and month */
Cwnd=CreateWindow(PICTUREBOX,"Calendar",-1,-1,CALHEIGHT,CALWIDTH,NULL,pwnd,CalendarProc,
SHADOW | MINMAXBOX | CONTROLBOX | MOVEABLE | HASBORDER);
}
SendMessage(Cwnd, SETFOCUS, TRUE, 0);
}
#endif

View File

@@ -0,0 +1,45 @@
/* -------------- checkbox.c ------------ */
#include "dflat.h"
int CheckBoxProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
int rtn;
CTLWINDOW *ct = GetControl(wnd);
if (ct != NULL) {
switch (msg) {
case SETFOCUS:
if (!(int)p1)
SendMessage(NULL, HIDE_CURSOR, 0, 0);
case MOVE:
rtn = BaseWndProc(CHECKBOX, wnd, msg, p1, p2);
SetFocusCursor(wnd);
return rtn;
case PAINT: {
char cb[] = "[ ]";
if (ct->setting)
cb[1] = 'X';
SendMessage(wnd, CLEARTEXT, 0, 0);
SendMessage(wnd, ADDTEXT, (PARAM) cb, 0);
SetFocusCursor(wnd);
break;
}
case KEYBOARD:
if ((int)p1 != ' ')
break;
case LEFT_BUTTON:
ct->setting ^= ON;
SendMessage(wnd, PAINT, 0, 0);
return TRUE;
default:
break;
}
}
return BaseWndProc(CHECKBOX, wnd, msg, p1, p2);
}
BOOL CheckBoxSetting(DBOX *db, enum commands cmd)
{
CTLWINDOW *ct = FindCommand(db, cmd, CHECKBOX);
return ct ? (ct->wnd ? (ct->setting==ON) : (ct->isetting==ON)) : FALSE;
}

View File

@@ -0,0 +1,31 @@
/* ---------------- classdef.h --------------- */
#ifndef CLASSDEF_H
#define CLASSDEF_H
typedef struct classdefs {
CLASS base; /* base window class */
int (*wndproc)(struct window *,enum messages,PARAM,PARAM);
int attrib;
} CLASSDEFS;
extern CLASSDEFS classdefs[];
#define SHADOW 0x0001
#define MOVEABLE 0x0002
#define SIZEABLE 0x0004
#define HASMENUBAR 0x0008
#define VSCROLLBAR 0x0010
#define HSCROLLBAR 0x0020
#define VISIBLE 0x0040
#define SAVESELF 0x0080
#define HASTITLEBAR 0x0100
#define CONTROLBOX 0x0200
#define MINMAXBOX 0x0400
#define NOCLIP 0x0800
#define READONLY 0x1000
#define MULTILINE 0x2000
#define HASBORDER 0x4000
#define HASSTATUSBAR 0x8000
#endif

View File

@@ -0,0 +1,58 @@
/* ----------- classes.h ------------ */
/*
* Class definition source file
* Make class changes to this source file
* Other source files will adapt
*
* You must add entries to the color tables in
* CONFIG.C for new classes.
*
* Class Name Base Class Processor Attribute
* ------------ --------- --------------- -----------
*/
ClassDef( NORMAL, -1, NormalProc, 0 )
ClassDef( APPLICATION, NORMAL, ApplicationProc, VISIBLE |
SAVESELF |
CONTROLBOX )
ClassDef( TEXTBOX, NORMAL, TextBoxProc, 0 )
ClassDef( LISTBOX, TEXTBOX, ListBoxProc, 0 )
ClassDef( EDITBOX, TEXTBOX, EditBoxProc, 0 )
ClassDef( MENUBAR, NORMAL, MenuBarProc, NOCLIP )
ClassDef( POPDOWNMENU, LISTBOX, PopDownProc, SAVESELF |
NOCLIP |
HASBORDER )
#ifdef INCLUDE_PICTUREBOX
ClassDef( PICTUREBOX, TEXTBOX, PictureProc, 0 )
#endif
ClassDef( DIALOG, NORMAL, DialogProc, SHADOW |
MOVEABLE |
CONTROLBOX|
HASBORDER |
NOCLIP )
ClassDef( BOX, NORMAL, BoxProc, HASBORDER )
ClassDef( BUTTON, TEXTBOX, ButtonProc, SHADOW )
ClassDef( COMBOBOX, EDITBOX, ComboProc, 0 )
ClassDef( TEXT, TEXTBOX, TextProc, 0 )
ClassDef( RADIOBUTTON, TEXTBOX, RadioButtonProc, 0 )
ClassDef( CHECKBOX, TEXTBOX, CheckBoxProc, 0 )
ClassDef( SPINBUTTON, LISTBOX, SpinButtonProc, 0 )
ClassDef( ERRORBOX, DIALOG, NULL, SHADOW |
HASBORDER )
ClassDef( MESSAGEBOX, DIALOG, NULL, SHADOW |
HASBORDER )
ClassDef( HELPBOX, DIALOG, HelpBoxProc, MOVEABLE |
SAVESELF |
HASBORDER |
NOCLIP |
CONTROLBOX )
ClassDef( STATUSBAR, TEXTBOX, StatusBarProc, NOCLIP )
ClassDef( EDITOR, EDITBOX, EditorProc, 0 )
/*
* ========> Add new classes here <========
*/
/* ---------- pseudo classes to create enums, etc. ---------- */
ClassDef( TITLEBAR, -1, NULL, 0 )
ClassDef( DUMMY, -1, NULL, HASBORDER )

View File

@@ -0,0 +1,99 @@
/* Edit's Clipboard
*/
#include "dflat.h"
char *Clipboard;
unsigned int ClipboardLength;
#ifndef _FDEDIT_PRIVATE_CLIPBOARD
void CopyTextToClipboard(char *text)
{
ClipboardLength = strlen(text);
Clipboard = DFrealloc(Clipboard, ClipboardLength);
memmove(Clipboard, text, ClipboardLength);
}
void CopyMemToClipboard(void *text, int size)
{
ClipboardLength = size;
Clipboard = DFrealloc(Clipboard, ClipboardLength);
memmove(Clipboard, text, ClipboardLength);
}
char *ReadClipboard(void)
{
return Clipboard;
}
void ClearClipboard(void)
{
if (Clipboard != NULL)
{
free(Clipboard);
Clipboard = NULL;
}
}
#endif
void CopyToClipboard(WINDOW wnd)
{
if (TextBlockMarked(wnd))
{
/* char *bbl=TextLine(wnd,wnd->BlkBegLine)+wnd->BlkBegCol;
char *bel=TextLine(wnd,wnd->BlkEndLine)+wnd->BlkEndCol;
*/
char *bbl=TextBlockBegin(wnd);
char *bel=TextBlockEnd(wnd);
if (bbl>=bel)
{
ErrorMessage("Not copied to clipboard");
return;
}
CopyMemToClipboard(bbl, bel-bbl);
/*
ClipboardLength=(unsigned) (bel-bbl);
Clipboard = DFrealloc(Clipboard, ClipboardLength);
memmove(Clipboard, bbl, ClipboardLength);
*/
}
}
BOOL PasteText(WINDOW wnd, char *SaveTo, unsigned len)
{
if (cfg.read_only)
{
MessageBox("Edit", "You cannot modify a read only file");
wnd->TextChanged=FALSE;
return TRUE;
}
if (SaveTo != NULL && len > 0)
{
unsigned plen = strlen(wnd->text) + len;
if (plen <= wnd->MaxTextLength)
{
if (plen+1 > wnd->textlen)
{
wnd->text = DFrealloc(wnd->text, plen+3);
wnd->textlen = plen+1;
}
memmove(CurrChar+len, CurrChar, strlen(CurrChar)+1);
memmove(CurrChar, SaveTo, len);
BuildTextPointers(wnd);
wnd->TextChanged = TRUE;
return TRUE;
}
}
return FALSE;
}

View File

@@ -0,0 +1,83 @@
/* Edit's Clipboard
*/
#include <windows.h>
extern char *Clipboard;
extern unsigned int ClipboardLength;
void CopyTextToClipboard(char *str)
{
if (Clipboard != NULL) {
free(Clipboard);
Clipboard = NULL;
}
if(OpenClipboard(NULL)) {
HGLOBAL clipbuffer;
char *buffer;
EmptyClipboard();
clipbuffer = GlobalAlloc(GMEM_DDESHARE, strlen(str)+1);
buffer = (char *)GlobalLock(clipbuffer);
strcpy(buffer, str);
GlobalUnlock(clipbuffer);
SetClipboardData(CF_TEXT,clipbuffer);
CloseClipboard();
}
}
void CopyMemToClipboard(void *ptr, unsigned int size)
{
if (Clipboard != NULL) {
free(Clipboard);
Clipboard = NULL;
}
if(OpenClipboard(NULL)) {
HGLOBAL clipbuffer;
char *buffer;
EmptyClipboard();
clipbuffer = GlobalAlloc(GMEM_DDESHARE, size+1);
buffer = (char *)GlobalLock(clipbuffer);
memcpy(buffer, ptr, size);
buffer[size] = '\0';
GlobalUnlock(clipbuffer);
SetClipboardData(CF_TEXT,clipbuffer);
CloseClipboard();
}
}
char *ReadClipboard(void)
{
char *buffer = NULL;
if (Clipboard != NULL)
return Clipboard;
if (OpenClipboard(NULL)) {
HANDLE hData = GetClipboardData(CF_TEXT);
char *fromClipboard;
if (hData != NULL) {
fromClipboard = (char *)GlobalLock(hData);
buffer = Clipboard = strdup(fromClipboard);
GlobalUnlock( hData );
ClipboardLength = strlen(buffer);
}
CloseClipboard();
}
return buffer;
}
void ClearClipboard(void)
{
if(OpenClipboard(NULL)) {
EmptyClipboard();
CloseClipboard();
}
if (Clipboard != NULL) {
free(Clipboard);
Clipboard = NULL;
}
}

View File

@@ -0,0 +1,130 @@
/* -------------- combobox.c -------------- */
#include "dflat.h"
int ListProc(WINDOW, MESSAGE, PARAM, PARAM);
int ComboProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
switch (msg) {
case CREATE_WINDOW:
wnd->extension = CreateWindow(
LISTBOX,
NULL,
wnd->rc.lf,wnd->rc.tp+1,
wnd->ht-1, wnd->wd+1,
NULL,
wnd,
ListProc,
HASBORDER | NOCLIP | SAVESELF);
((WINDOW)(wnd->extension))->ct->command =
wnd->ct->command;
wnd->ht = 1;
wnd->rc.bt = wnd->rc.tp;
break;
case PAINT:
foreground = WndBackground(wnd);
background = WndForeground(wnd);
wputch(wnd, DOWNSCROLLBOX, WindowWidth(wnd), 0);
break;
case KEYBOARD:
if ((int)p1 == DN) {
SendMessage(wnd->extension, SETFOCUS, TRUE, 0);
return TRUE;
}
break;
case LEFT_BUTTON:
if ((int)p1 == GetRight(wnd) + 1)
SendMessage(wnd->extension, SETFOCUS, TRUE, 0);
break;
case CLOSE_WINDOW:
SendMessage(wnd->extension, CLOSE_WINDOW, 0, 0);
break;
default:
break;
}
return BaseWndProc(COMBOBOX, wnd, msg, p1, p2);
}
int ListProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
WINDOW pwnd = GetParent(GetParent(wnd));
DBOX *db = pwnd->extension;
WINDOW cwnd;
char text[130];
int rtn;
WINDOW currFocus;
switch (msg) {
case CREATE_WINDOW:
wnd->ct = DFmalloc(sizeof(CTLWINDOW));
wnd->ct->setting = OFF;
wnd->WindowColors[FRAME_COLOR][FG] =
wnd->WindowColors[STD_COLOR][FG];
wnd->WindowColors[FRAME_COLOR][BG] =
wnd->WindowColors[STD_COLOR][BG];
rtn = DefaultWndProc(wnd, msg, p1, p2);
return rtn;
case SETFOCUS:
if ((int)p1 == FALSE) {
if (!wnd->isHelping) {
SendMessage(wnd, HIDE_WINDOW, 0, 0);
wnd->ct->setting = OFF;
}
}
else
wnd->ct->setting = ON;
break;
case SHOW_WINDOW:
if (wnd->ct->setting == OFF)
return TRUE;
break;
case BORDER:
currFocus = inFocus;
inFocus = NULL;
rtn = DefaultWndProc(wnd, msg, p1, p2);
inFocus = currFocus;
return rtn;
case LB_SELECTION:
rtn = DefaultWndProc(wnd, msg, p1, p2);
SendMessage(wnd, LB_GETTEXT,
(PARAM) text, wnd->selection);
PutItemText(pwnd, wnd->ct->command, text);
cwnd = ControlWindow(db, wnd->ct->command);
SendMessage(cwnd, PAINT, 0, 0);
cwnd->TextChanged = TRUE;
return rtn;
case KEYBOARD:
switch ((int) p1) {
case ESC:
case FWD:
case BS:
cwnd = ControlWindow(db, wnd->ct->command);
SendMessage(cwnd, SETFOCUS, TRUE, 0);
return TRUE;
default:
break;
}
break;
case LB_CHOOSE:
cwnd = ControlWindow(db, wnd->ct->command);
SendMessage(cwnd, SETFOCUS, TRUE, 0);
return TRUE;
case CLOSE_WINDOW:
if (wnd->ct != NULL)
free(wnd->ct);
wnd->ct = NULL;
break;
default:
break;
}
return DefaultWndProc(wnd, msg, p1, p2);
}
void PutComboListText(WINDOW wnd, enum commands cmd, char *text)
{
CTLWINDOW *ct = FindCommand(wnd->extension, cmd, COMBOBOX);
if (ct != NULL) {
WINDOW lwnd = ((WINDOW)(ct->wnd))->extension;
SendMessage(lwnd, ADDTEXT, (PARAM) text, 0);
}
}

View File

@@ -0,0 +1,126 @@
/* ---------------- commands.h ----------------- */
/*
* Command values sent as the first parameter
* in the COMMAND message
*
* Add application-specific commands to this enum
*/
#ifndef COMMANDS_H
#define COMMANDS_H
enum commands {
/* --------------- File menu ---------------- */
ID_OPEN,
ID_NEW,
ID_SAVE,
ID_SAVEAS,
ID_CLOSE,
ID_DELETEFILE,
ID_PRINT,
ID_PRINTSETUP,
ID_DOS,
ID_EXIT,
/* --------------- Edit menu ---------------- */
ID_UNDO,
ID_CUT,
ID_COPY,
ID_PASTE,
ID_PARAGRAPH,
ID_CLEAR,
ID_DELETETEXT,
/* --------------- Search Menu -------------- */
ID_SEARCH,
ID_REPLACE,
ID_SEARCHNEXT,
/* --------------- Utilities Menu ------------- */
#ifndef NOCALENDAR
ID_CALENDAR,
#endif
/* -------------- Options menu -------------- */
ID_INSERT,
ID_WRAP,
ID_LOG,
ID_TABS,
ID_DISPLAY,
ID_SAVEOPTIONS,
/* --------------- Window menu -------------- */
ID_CLOSEALL,
ID_WINDOW,
ID_MOREWINDOWS,
/* --------------- Help menu ---------------- */
ID_HELPHELP,
ID_EXTHELP,
ID_KEYSHELP,
ID_HELPINDEX,
ID_ABOUT,
/* --------------- System menu -------------- */
#ifdef INCLUDE_RESTORE
ID_SYSRESTORE,
#endif
ID_SYSMOVE,
ID_SYSSIZE,
#ifdef INCLUDE_MINIMIZE
ID_SYSMINIMIZE,
#endif
#ifdef INCLUDE_MAXIMIZE
ID_SYSMAXIMIZE,
#endif
ID_SYSCLOSE,
/* ---- FileOpen and SaveAs dialog boxes ---- */
ID_FILENAME,
ID_FILES,
ID_DIRECTORY,
ID_DRIVE,
ID_PATH,
ID_READONLY,
/* ----- Search and Replace dialog boxes ---- */
ID_SEARCHFOR,
ID_REPLACEWITH,
ID_MATCHCASE,
ID_REPLACEALL,
/* ----------- Windows dialog box ----------- */
ID_WINDOWLIST,
/* --------- generic command buttons -------- */
ID_OK,
ID_CANCEL,
ID_THREE,
ID_HELP,
/* -------------- TabStops menu ------------- */
ID_TAB2,
ID_TAB4,
ID_TAB6,
ID_TAB8,
/* ------------ Display dialog box ---------- */
ID_BORDER,
ID_TITLE,
ID_STATUSBAR,
ID_TEXTURE,
ID_LOADBLANK,
ID_SNOWY,
ID_COLOR,
ID_MONO,
ID_REVERSE,
ID_25LINES,
ID_43LINES,
ID_50LINES,
/* ------------- Log dialog box ------------- */
ID_LOGLIST,
ID_LOGGING,
/* ------------ HelpBox dialog box ---------- */
ID_HELPTEXT,
ID_BACK,
ID_PREV,
ID_NEXT,
/* ---------- Print Select dialog box --------- */
ID_PRINTERPORT,
ID_LEFTMARGIN,
ID_RIGHTMARGIN,
ID_TOPMARGIN,
ID_BOTTOMMARGIN,
/* ----------- InputBox dialog box ------------ */
ID_INPUTTEXT
};
#endif

View File

@@ -0,0 +1,551 @@
/* ------------- config.c ------------- */
#include "dflat.h"
/* ----- default colors for color video system ----- */
unsigned char color[CLASSCOUNT] [4] [2] = {
/* ------------ NORMAL ------------ */
{{LIGHTGRAY, BLACK}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{WHITE, BLACK}, /* FRAME_COLOR */
{LIGHTGRAY, BLACK}},/* HILITE_COLOR */
/* ---------- APPLICATION --------- */
{{LIGHTGRAY, BLUE}, /* STD_COLOR */
{LIGHTGRAY, BLUE}, /* SELECT_COLOR */
{LIGHTGRAY, BLUE}, /* FRAME_COLOR */
{LIGHTGRAY, BLUE}}, /* HILITE_COLOR */
/* ------------ TEXTBOX ----------- */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}},/* HILITE_COLOR */
/* ------------ LISTBOX ----------- */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}},/* HILITE_COLOR */
/* ----------- EDITBOX ------------ */
{{LIGHTGRAY, BLUE}, /* STD_COLOR */
{BLACK, LIGHTGRAY}, /* SELECT_COLOR */
{LIGHTGRAY, BLACK}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}},/* HILITE_COLOR */
/* ---------- MENUBAR ------------- */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{BLACK, CYAN}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{DARKGRAY, RED}}, /* HILITE_COLOR
Inactive, Shortcut (both FG) */
/* ---------- POPDOWNMENU --------- */
{{BLACK, CYAN}, /* STD_COLOR */
{BLACK, LIGHTGRAY}, /* SELECT_COLOR */
{BLACK, CYAN}, /* FRAME_COLOR */
{DARKGRAY, RED}}, /* HILITE_COLOR
Inactive ,Shortcut (both FG) */
#ifdef INCLUDE_PICTUREBOX
/* ------------ PICTUREBOX ----------- */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}},/* HILITE_COLOR */
#endif
/* ------------- DIALOG ----------- */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{BLACK, LIGHTGRAY}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{LIGHTGRAY, BLUE}}, /* HILITE_COLOR */
/* ------------ BOX --------------- */
{{LIGHTGRAY, BLUE}, /* STD_COLOR */
{LIGHTGRAY, BLUE}, /* SELECT_COLOR */
{LIGHTGRAY, BLUE}, /* FRAME_COLOR */
{LIGHTGRAY, BLUE}}, /* HILITE_COLOR */
/* ------------ BUTTON ------------ */
{{BLACK, CYAN}, /* STD_COLOR */
{WHITE, CYAN}, /* SELECT_COLOR */
{BLACK, CYAN}, /* FRAME_COLOR */
{DARKGRAY, RED}}, /* HILITE_COLOR
Inactive ,Shortcut (both FG) */
/* ------------ COMBOBOX ----------- */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{LIGHTGRAY, BLACK}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}},/* HILITE_COLOR */
/* ------------- TEXT ----------- */
{{0xff, 0xff}, /* STD_COLOR */
{0xff, 0xff}, /* SELECT_COLOR */
{0xff, 0xff}, /* FRAME_COLOR */
{0xff, 0xff}}, /* HILITE_COLOR */
/* ------------- RADIOBUTTON ----------- */
{{LIGHTGRAY, BLUE}, /* STD_COLOR */
{BLACK, LIGHTGRAY}, /* SELECT_COLOR */
{LIGHTGRAY, BLUE}, /* FRAME_COLOR */
{LIGHTGRAY, BLUE}}, /* HILITE_COLOR */
/* ------------- CHECKBOX ----------- */
{{LIGHTGRAY, BLUE}, /* STD_COLOR */
{BLACK, LIGHTGRAY}, /* SELECT_COLOR */
{LIGHTGRAY, BLUE}, /* FRAME_COLOR */
{LIGHTGRAY, BLUE}}, /* HILITE_COLOR */
/* ------------ SPINBUTTON ----------- */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{BLACK, LIGHTGRAY}, /* SELECT_COLOR */
{LIGHTGRAY, BLACK}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}},/* HILITE_COLOR */
/* ----------- ERRORBOX ----------- */
{{YELLOW, RED}, /* STD_COLOR */
{YELLOW, RED}, /* SELECT_COLOR */
{YELLOW, RED}, /* FRAME_COLOR */
{YELLOW, RED}}, /* HILITE_COLOR */
/* ----------- MESSAGEBOX --------- */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{BLACK, LIGHTGRAY}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}},/* HILITE_COLOR */
/* ----------- HELPBOX ------------ */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{LIGHTGRAY, BLUE}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{WHITE, LIGHTGRAY}},/* HILITE_COLOR */
/* ---------- STATUSBAR ------------- */
{{BLACK, CYAN}, /* STD_COLOR */
{BLACK, CYAN}, /* SELECT_COLOR */
{BLACK, CYAN}, /* FRAME_COLOR */
{BLACK, CYAN}}, /* HILITE_COLOR */
/* ----------- EDITOR ------------ */
{{LIGHTGRAY, BLUE}, /* STD_COLOR */
{BLACK, LIGHTGRAY}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}},/* HILITE_COLOR */
/* ---------- TITLEBAR ------------ */
{{BLACK, CYAN}, /* STD_COLOR */
{BLACK, CYAN}, /* SELECT_COLOR */
{CYAN, BLACK}, /* FRAME_COLOR */
{WHITE, CYAN}}, /* HILITE_COLOR */
/* ------------ DUMMY ------------- */
{{GREEN, LIGHTGRAY}, /* STD_COLOR */
{GREEN, LIGHTGRAY}, /* SELECT_COLOR */
{GREEN, LIGHTGRAY}, /* FRAME_COLOR */
{GREEN, LIGHTGRAY}} /* HILITE_COLOR */
};
/* ----- default colors for mono video system ----- */
unsigned char bw[CLASSCOUNT] [4] [2] = {
/* ------------ NORMAL ------------ */
{{LIGHTGRAY, BLACK}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{LIGHTGRAY, BLACK}, /* FRAME_COLOR */
{LIGHTGRAY, BLACK}},/* HILITE_COLOR */
/* ---------- APPLICATION --------- */
{{LIGHTGRAY, BLACK}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{LIGHTGRAY, BLACK}, /* FRAME_COLOR */
{LIGHTGRAY, BLACK}},/* HILITE_COLOR */
/* ------------ TEXTBOX ----------- */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}},/* HILITE_COLOR */
/* ------------ LISTBOX ----------- */
{{LIGHTGRAY, BLACK}, /* STD_COLOR */
{BLACK, LIGHTGRAY}, /* SELECT_COLOR */
{LIGHTGRAY, BLACK}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}},/* HILITE_COLOR */
/* ----------- EDITBOX ------------ */
{{LIGHTGRAY, BLACK}, /* STD_COLOR */
{BLACK, LIGHTGRAY}, /* SELECT_COLOR */
{LIGHTGRAY, BLACK}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}},/* HILITE_COLOR */
/* ---------- MENUBAR ------------- */
{{LIGHTGRAY, BLACK}, /* STD_COLOR */
{BLACK, LIGHTGRAY}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{DARKGRAY, WHITE}}, /* HILITE_COLOR
Inactive, Shortcut (both FG) */
/* ---------- POPDOWNMENU --------- */
{{LIGHTGRAY, BLACK}, /* STD_COLOR */
{BLACK, LIGHTGRAY}, /* SELECT_COLOR */
{LIGHTGRAY, BLACK}, /* FRAME_COLOR */
{DARKGRAY, WHITE}}, /* HILITE_COLOR
Inactive ,Shortcut (both FG) */
#ifdef INCLUDE_PICTUREBOX
/* ------------ PICTUREBOX ----------- */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}},/* HILITE_COLOR */
#endif
/* ------------- DIALOG ----------- */
{{LIGHTGRAY, BLACK}, /* STD_COLOR */
{BLACK, LIGHTGRAY}, /* SELECT_COLOR */
{LIGHTGRAY, BLACK}, /* FRAME_COLOR */
{LIGHTGRAY, BLACK}}, /* HILITE_COLOR */
/* ------------ BOX --------------- */
{{LIGHTGRAY, BLACK}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{LIGHTGRAY, BLACK}, /* FRAME_COLOR */
{LIGHTGRAY, BLACK}}, /* HILITE_COLOR */
/* ------------ BUTTON ------------ */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{WHITE, LIGHTGRAY}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{DARKGRAY, WHITE}}, /* HILITE_COLOR
Inactive ,Shortcut (both FG) */
/* ------------ COMBOBOX ----------- */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}},/* HILITE_COLOR */
/* ------------- TEXT ----------- */
{{0xff, 0xff}, /* STD_COLOR */
{0xff, 0xff}, /* SELECT_COLOR */
{0xff, 0xff}, /* FRAME_COLOR */
{0xff, 0xff}}, /* HILITE_COLOR */
/* ------------- RADIOBUTTON ----------- */
{{LIGHTGRAY, BLACK}, /* STD_COLOR */
{BLACK, LIGHTGRAY}, /* SELECT_COLOR */
{LIGHTGRAY, BLACK}, /* FRAME_COLOR */
{LIGHTGRAY, BLACK}}, /* HILITE_COLOR */
/* ------------- CHECKBOX ----------- */
{{LIGHTGRAY, BLACK}, /* STD_COLOR */
{BLACK, LIGHTGRAY}, /* SELECT_COLOR */
{LIGHTGRAY, BLACK}, /* FRAME_COLOR */
{LIGHTGRAY, BLACK}}, /* HILITE_COLOR */
/* ------------ SPINBUTTON ----------- */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{BLACK, LIGHTGRAY}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}},/* HILITE_COLOR */
/* ----------- ERRORBOX ----------- */
{{LIGHTGRAY, BLACK}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{LIGHTGRAY, BLACK}, /* FRAME_COLOR */
{LIGHTGRAY, BLACK}},/* HILITE_COLOR */
/* ----------- MESSAGEBOX --------- */
{{LIGHTGRAY, BLACK}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{LIGHTGRAY, BLACK}, /* FRAME_COLOR */
{LIGHTGRAY, BLACK}},/* HILITE_COLOR */
/* ----------- HELPBOX ------------ */
{{LIGHTGRAY, BLACK}, /* STD_COLOR */
{WHITE, BLACK}, /* SELECT_COLOR */
{LIGHTGRAY, BLACK}, /* FRAME_COLOR */
{WHITE, LIGHTGRAY}},/* HILITE_COLOR */
/* ---------- STATUSBAR ------------- */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{BLACK, LIGHTGRAY}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}},/* HILITE_COLOR */
/* ----------- EDITOR ------------ */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{LIGHTGRAY, BLACK}},/* HILITE_COLOR */
/* ---------- TITLEBAR ------------ */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{BLACK, LIGHTGRAY}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}},/* HILITE_COLOR */
/* ------------ DUMMY ------------- */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{BLACK, LIGHTGRAY}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}} /* HILITE_COLOR */
};
/* ----- default colors for reverse mono video ----- */
unsigned char reverse[CLASSCOUNT] [4] [2] = {
/* ------------ NORMAL ------------ */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{BLACK, LIGHTGRAY}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}},/* HILITE_COLOR */
/* ---------- APPLICATION --------- */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{BLACK, LIGHTGRAY}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}},/* HILITE_COLOR */
/* ------------ TEXTBOX ----------- */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}},/* HILITE_COLOR */
/* ------------ LISTBOX ----------- */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}},/* HILITE_COLOR */
/* ----------- EDITBOX ------------ */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}},/* HILITE_COLOR */
/* ---------- MENUBAR ------------- */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{LIGHTGRAY, BLACK}, /* FRAME_COLOR */
{DARKGRAY, WHITE}}, /* HILITE_COLOR
Inactive, Shortcut (both FG) */
/* ---------- POPDOWNMENU --------- */
{{LIGHTGRAY, BLACK}, /* STD_COLOR */
{BLACK, LIGHTGRAY}, /* SELECT_COLOR */
{LIGHTGRAY, BLACK}, /* FRAME_COLOR */
{DARKGRAY, WHITE}}, /* HILITE_COLOR
Inactive ,Shortcut (both FG) */
#ifdef INCLUDE_PICTUREBOX
/* ------------ PICTUREBOX ----------- */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}},/* HILITE_COLOR */
#endif
/* ------------- DIALOG ----------- */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}}, /* HILITE_COLOR */
/* ------------ BOX --------------- */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{BLACK, LIGHTGRAY}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}}, /* HILITE_COLOR */
/* ------------ BUTTON ------------ */
{{LIGHTGRAY, BLACK}, /* STD_COLOR */
{WHITE, BLACK}, /* SELECT_COLOR */
{LIGHTGRAY, BLACK}, /* FRAME_COLOR */
{DARKGRAY, WHITE}}, /* HILITE_COLOR
Inactive ,Shortcut (both FG) */
/* ------------ COMBOBOX ----------- */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{LIGHTGRAY, BLACK}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}},/* HILITE_COLOR */
/* ------------- TEXT ----------- */
{{0xff, 0xff}, /* STD_COLOR */
{0xff, 0xff}, /* SELECT_COLOR */
{0xff, 0xff}, /* FRAME_COLOR */
{0xff, 0xff}}, /* HILITE_COLOR */
/* ------------- RADIOBUTTON ----------- */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}}, /* HILITE_COLOR */
/* ------------- CHECKBOX ----------- */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}}, /* HILITE_COLOR */
/* ------------ SPINBUTTON ----------- */
{{LIGHTGRAY, BLACK}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{LIGHTGRAY, BLACK}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}},/* HILITE_COLOR */
/* ----------- ERRORBOX ----------- */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{BLACK, LIGHTGRAY}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}}, /* HILITE_COLOR */
/* ----------- MESSAGEBOX --------- */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{BLACK, LIGHTGRAY}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}},/* HILITE_COLOR */
/* ----------- HELPBOX ------------ */
{{BLACK, LIGHTGRAY}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{BLACK, LIGHTGRAY}, /* FRAME_COLOR */
{WHITE, LIGHTGRAY}},/* HILITE_COLOR */
/* ---------- STATUSBAR ------------- */
{{LIGHTGRAY, BLACK}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{LIGHTGRAY, BLACK}, /* FRAME_COLOR */
{LIGHTGRAY, BLACK}}, /* HILITE_COLOR */
/* ----------- EDITOR ------------ */
{{LIGHTGRAY, BLACK}, /* STD_COLOR */
{BLACK, LIGHTGRAY}, /* SELECT_COLOR */
{LIGHTGRAY, BLACK}, /* FRAME_COLOR */
{BLACK, LIGHTGRAY}},/* HILITE_COLOR */
/* ---------- TITLEBAR ------------ */
{{LIGHTGRAY, BLACK}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{LIGHTGRAY, BLACK}, /* FRAME_COLOR */
{LIGHTGRAY, BLACK}}, /* HILITE_COLOR */
/* ------------ DUMMY ------------- */
{{LIGHTGRAY, BLACK}, /* STD_COLOR */
{LIGHTGRAY, BLACK}, /* SELECT_COLOR */
{LIGHTGRAY, BLACK}, /* FRAME_COLOR */
{LIGHTGRAY, BLACK}} /* HILITE_COLOR */
};
/* ------ default configuration values ------- */
CONFIG cfg = {
VERSION,
0, /* Color */
FALSE, /* Snowy CGA */
TRUE, /* Editor Insert Mode */
4, /* Editor tab stops */
FALSE, /* Editor word wrap */
0, /* Read Only? */
FALSE, /* Load blank file on startup */
#ifdef INCLUDE_WINDOWOPTIONS
TRUE, /* Application Border */
TRUE, /* Application Title */
TRUE, /* Status Bar */
#endif
FALSE, /* Textured application window */
25, /* Number of screen lines */
"Lpt1", /* Printer Port */
66, /* Lines per printer page */
80, /* characters per printer line */
6, /* Left printer margin */
70, /* Right printer margin */
3, /* Top printer margin */
55 /* Bottom printer margin */
};
void BuildFileName(char *path, const char *fn, const char *ext)
{
char *cp=path;
/* if Argv[0] is available then open file in same dir as Application binary */
#ifdef ENABLEGLOBALARGV
strcpy(path, Argv[0]);
cp=strrchr(path, '\\');
if (cp==NULL)
cp=path;
else
cp++;
#endif
strcpy(cp, fn);
strcat(cp, ext);
}
FILE *OpenConfig(char *mode)
{
char path[64];
BuildFileName(path, DFlatApplication, ".cfg");
return fopen(path, mode);
}
/* ------ load a configuration file from disk ------- */
BOOL LoadConfig(void)
{
static BOOL ConfigLoaded=FALSE;
if (ConfigLoaded==FALSE)
{
FILE *fp=OpenConfig("rb");
if (fp != NULL)
{
fread(cfg.version, sizeof cfg.version+1, 1, fp);
if (strcmp(cfg.version, VERSION) == 0)
{
fseek(fp, 0L, SEEK_SET);
fread(&cfg, sizeof(CONFIG), 1, fp);
fclose(fp);
}
else
{
char path[64];
BuildFileName(path, DFlatApplication, ".cfg");
fclose(fp);
unlink(path);
strcpy(cfg.version, VERSION);
}
ConfigLoaded=TRUE;
}
}
return ConfigLoaded;
}
/* ------ save a configuration file to disk ------- */
void SaveConfig(void)
{
FILE *fp=OpenConfig("wb");
if (fp != NULL)
{
fwrite(&cfg, sizeof(CONFIG), 1, fp);
fclose(fp);
}
}
/* --------- set window colors --------- */
void SetStandardColor(WINDOW wnd)
{
foreground=WndForeground(wnd);
background=WndBackground(wnd);
}
void SetReverseColor(WINDOW wnd)
{
foreground=SelectForeground(wnd);
background=SelectBackground(wnd);
}

View File

@@ -0,0 +1,52 @@
/* ---------------- config.h -------------- */
#ifndef CONFIG_H
#define CONFIG_H
enum colortypes {
STD_COLOR,
SELECT_COLOR,
FRAME_COLOR,
HILITE_COLOR
};
enum grounds { FG, BG };
/* ----------- configuration parameters ----------- */
typedef struct config {
char version[sizeof VERSION];
char mono; /* 0=color, 1=mono, 2=reverse mono */
BOOL snowy; /* TRUE = snowy CGA display */
BOOL InsertMode; /* Editor insert mode */
int Tabs; /* Editor tab stops */
BOOL WordWrap; /* True to word wrap editor */
int read_only; /* Read Only? */
BOOL loadblank; /* True to load blank file on startup */
#ifdef INCLUDE_WINDOWOPTIONS
BOOL Border; /* True for application window border */
BOOL Title; /* True for application window title */
BOOL StatusBar; /* True for appl'n window status bar */
#endif
BOOL Texture; /* True for textured appl window */
int ScreenLines; /* Number of screen lines (25/43/50) */
char PrinterPort[5];
int LinesPage; /* Lines per printer page */
int CharsLine; /* Characters per printer line */
int LeftMargin; /* Printer margins */
int RightMargin;
int TopMargin;
int BottomMargin;
unsigned char clr[CLASSCOUNT] [4] [2]; /* Colors */
} CONFIG;
extern CONFIG cfg;
extern unsigned char color[CLASSCOUNT] [4] [2];
extern unsigned char bw[CLASSCOUNT] [4] [2];
extern unsigned char reverse[CLASSCOUNT] [4] [2];
BOOL LoadConfig(void);
void SaveConfig(void);
FILE *OpenConfig(char *);
#endif

View File

@@ -0,0 +1,402 @@
/* ----------- console.c ---------- */
#include "dflat.h"
/* ----- table of alt keys for finding shortcut keys ----- */
static int altconvert[] = {
ALT_A,ALT_B,ALT_C,ALT_D,ALT_E,ALT_F,ALT_G,ALT_H,
ALT_I,ALT_J,ALT_K,ALT_L,ALT_M,ALT_N,ALT_O,ALT_P,
ALT_Q,ALT_R,ALT_S,ALT_T,ALT_U,ALT_V,ALT_W,ALT_X,
ALT_Y,ALT_Z,ALT_0,ALT_1,ALT_2,ALT_3,ALT_4,ALT_5,
ALT_6,ALT_7,ALT_8,ALT_9
};
unsigned video_mode;
unsigned video_page;
static int near cursorpos[MAXSAVES];
static int near cursorshape[MAXSAVES];
static union REGS regs;
static int cs;
static int far *clk = MK_FP(0x40,0x6c);
/* ------- macro to wait one clock tick -------- */
#define wait() \
{ \
int now = *clk; \
while (now == *clk); \
}
/* ------------- clear the screen -------------- */
void clearscreen(void)
{
int ht=SCREENHEIGHT;
int wd=SCREENWIDTH;
cursor(0, 0);
regs.h.al=' ';
regs.h.ah=9;
regs.x.bx=7;
regs.x.cx=ht * wd;
int86(VIDEO, &regs, &regs);
}
void SwapCursorStack(void)
{
if (cs > 1)
{
swap(cursorpos[cs-2], cursorpos[cs-1]);
swap(cursorshape[cs-2], cursorshape[cs-1]);
}
}
/* ---- BIOS keyboard routines with 84 and 102 key keyboard support ---- */
int Xbioskey(int cmd)
{
static int keybase=-1;
union REGS kregs;
if (keybase < 0)
{
volatile char far *kbtype = MK_FP(0x40,0x96); /* BIOS data flag */
keybase=(((*kbtype) & 0x10) != 0) ? 0x10 : 0;
/* 0 for 84 key XT mode, 0x10 for 102 key AT mode. */
/* (0x20 for 122 key mode, which is not used here) */
}
kregs.h.ah = (char) (keybase + cmd);
kregs.h.al = 0;
int86(0x16, &kregs, &kregs);
if ((cmd == 1) && (kregs.x.flags & 0x40 /* zero flag */))
return 0;
return kregs.x.ax;
}
/* ---- Test for keystroke ---- */
BOOL keyhit(void)
{
#if MSC | WATCOM
return (kbhit() ? TRUE : FALSE);
#else
return (Xbioskey(1) != 0) ? TRUE : FALSE;
#endif
}
/* ---- Read a keystroke ---- */
int getkey(void)
{
unsigned int c;
unsigned int theShift;
unsigned int theScan;
while (keyhit() == FALSE); /* Wait for a key */
c=Xbioskey(0); /* Fetch key */
theShift=getshift();
theScan=c >> 8; /* Scan code */
c=c & 0xff; /* ASCII code or 0 of 0xe0 */
if (theShift & (LEFTSHIFT|RIGHTSHIFT))
{
/* BIOS normally calls shift-ins "ins" and shift-del "del" */
if (theScan == 0x52) /* INS */
return CTRL_V; /* SHIFT_INS */
if (theScan == 0x53) /* DEL */
return CTRL_X; /* SHIFT_DEL */
}
if ((theShift & ALTKEY) && (theScan == 0x0e)) /* Alt-BS */
return CTRL_Z; /* ALT_BS */
if (theShift & CTRLKEY)
{
if (theScan == 0x92) /* ^ins */
{
return CTRL_C; /* CTRL_INS */
}
}
if ((c != 0) && (c != 0xe0)) /* Nonzero / nonnumpad ASCII part? */
return c; /* Then return only the ASCII part */
/* Watch out: Special case for Russian non-numpad "0xe0 ASCII" */
if ((c == 0xe0) && (theScan == 0))
return 0xe0;
return (FKEY | theScan);
}
/* ---------- read the keyboard shift status --------- */
int getshift(void)
{
static int enhkeyb=-1; /* 1 for an enhanced keyboard */
static char far *kbtype = MK_FP(0x40,0x96);
if (enhkeyb == -1) /* If we do not yet know... */
{
enhkeyb=(((*kbtype) & 0x10) != 0) ? 1 : 0; /* read BIOS data flag! */
} /* Now enhkeyb is either 0 or 1 - Eric */
if (!enhkeyb) /* Old/new by Eric */
{
regs.h.ah = 2;
int86(KEYBRD, &regs, &regs);
return regs.h.al;
}
else
{
regs.h.ah=0x12; /* Extended shift: AL as above... */
int86(KEYBRD, &regs, &regs);
/* Ignore SysRQ (Alt-PrtScr) and shift lock presses */
regs.x.ax &= 0x0fff;
if (regs.x.ax & RALTKEY) /* Treat RALT as NO ALT (but as AltGr */
regs.x.ax &= ~ALTKEY;
return regs.x.ax;
}
}
/* -------- sound a buzz tone, using hardware directly ---------- */
void beep(void)
{
wait();
outp(0x43, 0xb6); /* program the frequency */
outp(0x42, (int) (COUNT % 256));
outp(0x42, (int) (COUNT / 256));
outp(0x61, inp(0x61) | 3); /* start the sound */
wait();
outp(0x61, inp(0x61) & ~3); /* stop the sound */
}
/* -------- get the video mode and page from BIOS -------- */
void videomode(void)
{
regs.h.ah = 15;
int86(VIDEO, &regs, &regs);
video_mode = regs.h.al;
video_page = regs.x.bx;
video_page &= 0xff00;
video_mode &= 0x7f;
}
/* ------ position the cursor ------ */
void cursor(int x, int y)
{
videomode();
regs.x.dx=((y << 8) & 0xff00)+x;
regs.h.ah=SETCURSOR;
regs.x.bx=video_page;
int86(VIDEO, &regs, &regs);
}
/* ------ get cursor shape and position ------ */
static void near getcursor(void)
{
videomode();
regs.h.ah=READCURSOR;
regs.x.bx=video_page;
int86(VIDEO, &regs, &regs);
}
/* ------- get the current cursor position ------- */
void curr_cursor(int *x, int *y)
{
getcursor();
*x=regs.h.dl;
*y=regs.h.dh;
}
/* ------ save the current cursor configuration ------ */
void savecursor(void)
{
if (cs < MAXSAVES)
{
getcursor();
cursorshape[cs]=regs.x.cx;
cursorpos[cs]=regs.x.dx;
cs++;
}
}
/* ---- restore the saved cursor configuration ---- */
void restorecursor(void)
{
if (cs)
{
--cs;
videomode();
regs.x.dx=cursorpos[cs];
regs.h.ah=SETCURSOR;
regs.x.bx=video_page;
int86(VIDEO, &regs, &regs);
set_cursor_type(cursorshape[cs]);
}
}
/* ------ make a normal cursor ------ */
void normalcursor(void)
{
set_cursor_type(0x0106);
}
/* ------ hide the cursor ------ */
void hidecursor(void)
{
getcursor();
regs.h.ch |= HIDECURSOR;
regs.h.ah = SETCURSORTYPE;
int86(VIDEO, &regs, &regs);
}
/* ------ unhide the cursor ------ */
void unhidecursor(void)
{
getcursor();
regs.h.ch &= ~HIDECURSOR;
regs.h.ah = SETCURSORTYPE;
int86(VIDEO, &regs, &regs);
}
/* ---- use BIOS to set the cursor type ---- */
void set_cursor_type(unsigned t)
{
videomode();
regs.h.ah=SETCURSORTYPE;
regs.x.bx=video_page;
regs.x.cx=t;
int86(VIDEO, &regs, &regs);
}
/* ---- test for EGA -------- */
BOOL isEGA(void)
{
if (isVGA())
return FALSE;
regs.h.ah=0x12;
regs.h.bl=0x10;
int86(VIDEO, &regs, &regs);
return regs.h.bl != 0x10;
}
/* ---- test for VGA -------- */
BOOL isVGA(void)
{
regs.x.ax=0x1a00;
int86(VIDEO, &regs, &regs);
return regs.h.al == 0x1a && regs.h.bl > 6;
}
static void Scan350(void)
{
regs.x.ax=0x1201;
regs.h.bl=0x30;
int86(VIDEO, &regs, &regs);
regs.h.ah=0x0f;
int86(VIDEO, &regs, &regs);
regs.h.ah=0x00;
int86(VIDEO, &regs, &regs);
}
static void Scan400(void)
{
regs.x.ax=0x1202;
regs.h.bl=0x30;
int86(VIDEO, &regs, &regs);
regs.h.ah=0x0f;
int86(VIDEO, &regs, &regs);
regs.h.ah=0x00;
int86(VIDEO, &regs, &regs);
}
/* ---------- set 25 line mode ------- */
void Set25(void)
{
if (isVGA())
{
Scan400();
regs.x.ax=0x1114;
}
else
regs.x.ax=0x1111;
regs.h.bl=0;
int86(VIDEO, &regs, &regs);
}
/* ---------- set 43 line mode ------- */
void Set43(void)
{
if (isVGA())
Scan350();
regs.x.ax=0x1112;
regs.h.bl=0;
int86(VIDEO, &regs, &regs);
}
/* ---------- set 50 line mode ------- */
void Set50(void)
{
if (isVGA())
Scan400();
regs.x.ax=0x1112;
regs.h.bl=0;
int86(VIDEO, &regs, &regs);
}
/* ------ convert an Alt+ key to its letter equivalent ----- */
int AltConvert(int c)
{
int i,a=0;
for (i=0;i<36;i++)
if (c == altconvert[i])
break;
if (i < 26)
a='a'+i;
else if (i < 36)
a='0'+i-26;
return a;
}
#if MSC | WATCOM
int getdisk(void)
{
unsigned int cd;
_dos_getdrive(&cd);
cd -= 1;
return cd;
}
#endif

View File

@@ -0,0 +1,797 @@
/* ----------- console.c ---------- */
#include <windows.h>
#include "keys.h"
#define MAXSAVES 50
#define swap(a,b) a^=b; b^=a; a^=b;
/* ----- table of alt keys for finding shortcut keys ----- */
static const int altconvert[] = {
ALT_A,ALT_B,ALT_C,ALT_D,ALT_E,ALT_F,ALT_G,ALT_H,
ALT_I,ALT_J,ALT_K,ALT_L,ALT_M,ALT_N,ALT_O,ALT_P,
ALT_Q,ALT_R,ALT_S,ALT_T,ALT_U,ALT_V,ALT_W,ALT_X,
ALT_Y,ALT_Z,ALT_0,ALT_1,ALT_2,ALT_3,ALT_4,ALT_5,
ALT_6,ALT_7,ALT_8,ALT_9
};
/*
Set text and background colors
*/
static const WORD col_fore[] = {
/*
dark colors
*/
0, /* BLACK */
FOREGROUND_BLUE, /* BLUE */
FOREGROUND_GREEN, /* GREEN */
FOREGROUND_BLUE | /* CYAN */
FOREGROUND_GREEN,
FOREGROUND_RED, /* RED */
FOREGROUND_BLUE | /* MAGENTA */
FOREGROUND_RED,
FOREGROUND_RED | /* BROWN */
FOREGROUND_GREEN,
FOREGROUND_RED | /* LIGHTGRAY */
FOREGROUND_GREEN |
FOREGROUND_BLUE,
/*
light colors
*/
FOREGROUND_INTENSITY,/* DARKGRAY */
FOREGROUND_BLUE | /* LIGHTBLUE */
FOREGROUND_INTENSITY,
FOREGROUND_GREEN | /* LIGHTGREEN */
FOREGROUND_INTENSITY,
FOREGROUND_BLUE | /* LIGHTCYAN */
FOREGROUND_GREEN |
FOREGROUND_INTENSITY,
FOREGROUND_RED | /* LIGHTRED */
FOREGROUND_INTENSITY,
FOREGROUND_BLUE | /* MAGENTA */
FOREGROUND_RED |
FOREGROUND_INTENSITY,
FOREGROUND_RED | /* YELLOW */
FOREGROUND_GREEN |
FOREGROUND_INTENSITY,
FOREGROUND_RED | /* WHITE */
FOREGROUND_GREEN |
FOREGROUND_BLUE |
FOREGROUND_INTENSITY,
};
static const WORD col_back[] = {
/*
dark colors
*/
0, /* BLACK */
BACKGROUND_BLUE, /* BLUE */
BACKGROUND_GREEN, /* GREEN */
BACKGROUND_BLUE | /* CYAN */
BACKGROUND_GREEN,
BACKGROUND_RED, /* RED */
BACKGROUND_BLUE | /* MAGENTA */
BACKGROUND_RED,
BACKGROUND_RED | /* BROWN */
BACKGROUND_GREEN,
BACKGROUND_RED | /* LIGHTGRAY */
BACKGROUND_GREEN |
BACKGROUND_BLUE,
/*
light colors
*/
BACKGROUND_INTENSITY,/* DARKGRAY */
BACKGROUND_BLUE | /* LIGHTBLUE */
BACKGROUND_INTENSITY,
BACKGROUND_GREEN | /* LIGHTGREEN */
BACKGROUND_INTENSITY,
BACKGROUND_BLUE | /* LIGHTCYAN */
BACKGROUND_GREEN |
BACKGROUND_INTENSITY,
BACKGROUND_RED | /* LIGHTRED */
BACKGROUND_INTENSITY,
BACKGROUND_BLUE | /* MAGENTA */
BACKGROUND_RED |
BACKGROUND_INTENSITY,
BACKGROUND_RED | /* YELLOW */
BACKGROUND_GREEN |
BACKGROUND_INTENSITY,
BACKGROUND_RED | /* WHITE */
BACKGROUND_GREEN |
BACKGROUND_BLUE |
BACKGROUND_INTENSITY,
};
static int cursorpos[MAXSAVES];
static int cursorshape[MAXSAVES];
static int cs;
static HANDLE hConsoleIn;
static HANDLE hConsoleOut;
static HANDLE hNewScreenBuffer;
static CONSOLE_SCREEN_BUFFER_INFO csbi;
static SMALL_RECT updateRect;
static COORD updateCoord;
static COORD updateCoordSrc;
static CHAR_INFO *chiBuffer;
static unsigned char *coiBuffer;
static COORD lastCurPos;
static BOOL cursor_state;
static COORD origCurPos;
static BOOL initialized_vmode=FALSE;
static int shift_mask;
static COORD c_mouse;
static int b_mouse;
static int s_mouse;
void SwapCursorStack(void)
{
if (cs > 1) {
swap(cursorpos[cs-2], cursorpos[cs-1]);
swap(cursorshape[cs-2], cursorshape[cs-1]);
}
}
/* ---- Test for keystroke ---- */
typedef struct {
unsigned int in_key;
unsigned int out_key;
unsigned int buf[32];
} keyb_t;
typedef struct {
WORD vk;
WORD kb;
WORD alt_kb;
WORD ctrl_kb;
} key_tbl_t;
static const key_tbl_t key_tbl[] = {
{ 'A', 'a', ALT_A, CTRL_A, },
{ 'B', 'b', ALT_B, CTRL_B, },
{ 'C', 'c', ALT_C, CTRL_C, },
{ 'D', 'd', ALT_D, CTRL_D, },
{ 'E', 'e', ALT_E, CTRL_E, },
{ 'F', 'f', ALT_F, CTRL_F, },
{ 'G', 'g', ALT_G, CTRL_G, },
{ 'H', 'h', ALT_H, CTRL_H, },
{ 'I', 'i', ALT_I, CTRL_I, },
{ 'J', 'j', ALT_J, CTRL_J, },
{ 'K', 'k', ALT_K, CTRL_K, },
{ 'L', 'l', ALT_L, CTRL_L, },
{ 'M', 'm', ALT_M, CTRL_M, },
{ 'N', 'n', ALT_N, CTRL_N, },
{ 'O', 'o', ALT_O, CTRL_O, },
{ 'P', 'p', ALT_P, CTRL_P, },
{ 'Q', 'q', ALT_Q, CTRL_Q, },
{ 'R', 'r', ALT_R, CTRL_R, },
{ 'S', 's', ALT_S, CTRL_S, },
{ 'T', 't', ALT_T, CTRL_T, },
{ 'U', 'u', ALT_U, CTRL_U, },
{ 'V', 'v', ALT_V, CTRL_V, },
{ 'W', 'w', ALT_W, CTRL_W, },
{ 'X', 'x', ALT_X, CTRL_X, },
{ 'Y', 'y', ALT_Y, CTRL_Y, },
{ 'Z', 'z', ALT_Z, CTRL_Z, },
};
#define VK_APIC 0xDE
static const key_tbl_t key_tbl3[] = {
{ VK_F1, F1, ALT_F1, CTRL_F1, },
{ VK_F2, F2, ALT_F2, CTRL_F2, },
{ VK_F3, F3, ALT_F3, CTRL_F3, },
{ VK_F4, F4, ALT_F4, CTRL_F4, },
{ VK_F5, F5, ALT_F5, CTRL_F5, },
{ VK_F6, F6, ALT_F6, CTRL_F6, },
{ VK_F7, F7, ALT_F7, CTRL_F7, },
{ VK_F8, F8, ALT_F8, CTRL_F8, },
{ VK_F9, F9, ALT_F9, CTRL_F9, },
{ VK_F10, F10, ALT_F10, CTRL_F10, },
/* other keys */
{ VK_UP, UP, -1, -1, },
{ VK_DOWN, DN, -1, -1, },
{ VK_LEFT, /*BS*/LARROW, ALT_BS, CTRL_BS, },
{ VK_RIGHT, FWD, -1, -1,/*CTRL_FWD,*/ },
{ VK_PRIOR, PGUP, -1, CTRL_PGUP, },
{ VK_NEXT, PGDN, -1, CTRL_PGDN, },
{ VK_HOME, HOME, -1, CTRL_HOME, },
{ VK_END, END, -1, CTRL_END, },
{ VK_INSERT, INS, -1, CTRL_INS, },
{ VK_DELETE, DEL, -1, /*ALT_DEL,*/ -1, },
};
static keyb_t keyb = { 0, 0, { 0 } };
int w32_getkey()
{
DWORD dwInputs;
INPUT_RECORD inRec;
unsigned int x;
int c;
if (!GetNumberOfConsoleInputEvents(hConsoleIn, &dwInputs))
return -1;
if (!dwInputs)
return -1;
if (!ReadConsoleInput(hConsoleIn, &inRec, 1, &dwInputs))
return -1;
if (inRec.EventType == KEY_EVENT) {
if (inRec.Event.KeyEvent.bKeyDown) {
if (inRec.Event.KeyEvent.dwControlKeyState & (LEFT_ALT_PRESSED|RIGHT_ALT_PRESSED))
shift_mask |= ALTKEY;
if (inRec.Event.KeyEvent.dwControlKeyState & (LEFT_CTRL_PRESSED|RIGHT_CTRL_PRESSED))
shift_mask |= CTRLKEY;
if ((inRec.Event.KeyEvent.dwControlKeyState & SHIFT_PRESSED))
shift_mask |= LEFTSHIFT;
c = inRec.Event.KeyEvent.uChar.AsciiChar;
if (!c) {
c = -1;
/* special cases */
/* test for extended keys */
for (x=0; x<sizeof(key_tbl3)/sizeof(key_tbl3[0]); x++) {
if (key_tbl3[x].vk == inRec.Event.KeyEvent.wVirtualKeyCode) {
if (inRec.Event.KeyEvent.dwControlKeyState & (LEFT_ALT_PRESSED|RIGHT_ALT_PRESSED))
c = key_tbl3[x].alt_kb;
else
if (inRec.Event.KeyEvent.dwControlKeyState & (LEFT_CTRL_PRESSED|RIGHT_CTRL_PRESSED))
c = key_tbl3[x].ctrl_kb;
else
c = key_tbl3[x].kb;
break;
}
}
} else {
/* special case: Shift-TAB */
if (c == 9 && (inRec.Event.KeyEvent.dwControlKeyState & SHIFT_PRESSED))
return SHIFT_HT;
for (x=0; x<sizeof(key_tbl)/sizeof(key_tbl[0]); x++) {
if (key_tbl[x].vk == inRec.Event.KeyEvent.wVirtualKeyCode) {
if (inRec.Event.KeyEvent.dwControlKeyState & (LEFT_ALT_PRESSED|RIGHT_ALT_PRESSED))
c = key_tbl[x].alt_kb;
else
if (inRec.Event.KeyEvent.dwControlKeyState & (LEFT_CTRL_PRESSED|RIGHT_CTRL_PRESSED))
c = key_tbl[x].ctrl_kb;
break;
}
}
}
return c;
} else {
if (!(inRec.Event.KeyEvent.dwControlKeyState & (LEFT_ALT_PRESSED|RIGHT_ALT_PRESSED)))
shift_mask &= ~ALTKEY;
if (!(inRec.Event.KeyEvent.dwControlKeyState & (LEFT_CTRL_PRESSED|RIGHT_CTRL_PRESSED)))
shift_mask &= ~CTRLKEY;
if (!(inRec.Event.KeyEvent.dwControlKeyState & SHIFT_PRESSED))
shift_mask &= ~LEFTSHIFT;
}
}
if (inRec.EventType == MOUSE_EVENT) {
int old_mask = b_mouse;
c_mouse = inRec.Event.MouseEvent.dwMousePosition;
b_mouse = 0;
if (inRec.Event.MouseEvent.dwButtonState & FROM_LEFT_1ST_BUTTON_PRESSED)
b_mouse |= 1;
if (inRec.Event.MouseEvent.dwButtonState & RIGHTMOST_BUTTON_PRESSED)
b_mouse |= 2;
s_mouse |= old_mask ^ b_mouse;
if (inRec.Event.MouseEvent.dwEventFlags & MOUSE_WHEELED) {
int wheel = ( (int)inRec.Event.MouseEvent.dwButtonState ) >> 16;
if (wheel < 0) return DN;
if (wheel > 0) return UP;
}
}
return -1;
}
void update_key_buffer(void)
{
int c;
while ((c=w32_getkey()) != -1) {
keyb.buf[keyb.in_key] = c;
keyb.in_key = (keyb.in_key+1) % (sizeof(keyb.buf)/sizeof(keyb.buf[0]));
}
}
void clearBIOSbuffer(void)
{
/* not a good idea... */
/*
keyb.in_key = keyb.out_key;
FlushConsoleInputBuffer(hConsoleIn);
*/
}
BOOL keyhit(void)
{
update_key_buffer();
return (keyb.in_key != keyb.out_key);
}
/* ---- Read a keystroke ---- */
int getkey(void)
{
int c;
while (keyhit() == FALSE)
Sleep(10);
c = keyb.buf[keyb.out_key];
keyb.out_key = (keyb.out_key+1) % (sizeof(keyb.buf)/sizeof(keyb.buf[0]));
return c;
}
/* ---------- read the keyboard shift status --------- */
int getshift(void)
{
return shift_mask;
}
/* -------- sound a buzz tone ---------- */
void beep(void)
{
}
/* -------- get the video mode and page from BIOS -------- */
void videomode(void)
{
/*
regs.h.ah = 15;
int86(VIDEO, &regs, &regs);
video_mode = regs.h.al;
video_page = regs.x.bx;
video_page &= 0xff00;
video_mode &= 0x7f;
*/
}
void init_videomode(void)
{
CONSOLE_CURSOR_INFO curInfo;
DWORD dwMode;
int x,y;
if (initialized_vmode)
return;
initialized_vmode = TRUE;
hConsoleIn = GetStdHandle(STD_INPUT_HANDLE);
hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE);
hNewScreenBuffer = CreateConsoleScreenBuffer(
GENERIC_READ | /* read/write access */
GENERIC_WRITE,
0, /* not shared */
NULL, /* default security attributes */
CONSOLE_TEXTMODE_BUFFER, /* must be TEXTMODE */
NULL);
GetConsoleScreenBufferInfo(hConsoleOut, &csbi);
origCurPos = csbi.dwCursorPosition;
SetConsoleActiveScreenBuffer(hNewScreenBuffer);
updateCoord.X = csbi.dwSize.X;
/* updateCoord.Y = csbi.dwSize.Y; */
updateCoord.Y = 25;
chiBuffer = (CHAR_INFO *)malloc(updateCoord.X*updateCoord.Y*sizeof(CHAR_INFO));
coiBuffer = (unsigned char *)malloc(updateCoord.X*updateCoord.Y);
updateCoordSrc.X = 0;
updateCoordSrc.Y = 0;
updateRect.Top = 0;
updateRect.Left = 0;
updateRect.Bottom = updateCoord.Y-1;
updateRect.Right = updateCoord.X-1;
for (y=0; y<updateCoord.Y; y++) {
for (x=0; x<updateCoord.X; x++) {
chiBuffer[x+y*updateCoord.X].Char.AsciiChar = ' ';
chiBuffer[x+y*updateCoord.X].Attributes = 0;
}
}
WriteConsoleOutput(
hNewScreenBuffer,
chiBuffer,
updateCoord,
updateCoordSrc,
&updateRect);
GetConsoleMode(hConsoleIn, &dwMode);
/*
1) Without ENABLE_PROCESSED_INPUT we can use CTRL-C too.
2) Sometimes, for some unknown reasons, WinXP didnt enable the mouse
into the console, so its better to always enable it manually.
*/
dwMode = (dwMode & ~ENABLE_PROCESSED_INPUT) | ENABLE_MOUSE_INPUT;
SetConsoleMode(hConsoleIn, dwMode);
lastCurPos.X = 0x7FFF;
lastCurPos.Y = 0x7FFF;
/* cursor is off by default into our screen buffer */
cursor_state = FALSE;
memset(&curInfo, 0, sizeof(CONSOLE_CURSOR_INFO));
curInfo.dwSize = 1;
curInfo.bVisible = FALSE;
SetConsoleCursorInfo(hNewScreenBuffer, &curInfo);
/* mouse */
c_mouse.X = 0;
c_mouse.Y = 0;
b_mouse = 0;
s_mouse = 0;
}
/* ------ position the cursor ------ */
void cursor(int x, int y)
{
COORD point;
point.X = x; point.Y = y;
if (memcmp(&point, &lastCurPos, sizeof(COORD))) {
lastCurPos = point;
SetConsoleCursorPosition(hNewScreenBuffer, point);
}
}
/* ------- get the current cursor position ------- */
void curr_cursor(int *x, int *y)
{
GetConsoleScreenBufferInfo(hNewScreenBuffer, &csbi);
*x = csbi.dwCursorPosition.X;
*y = csbi.dwCursorPosition.Y;
}
/* ------ save the current cursor configuration ------ */
void savecursor(void)
{
if (cs < MAXSAVES) {
/*
getcursor();
cursorshape[cs] = regs.x.cx;
cursorpos[cs] = regs.x.dx;
*/
cs++;
}
}
/* ---- restore the saved cursor configuration ---- */
void restorecursor(void)
{
if (cs) {
--cs;
/*
videomode();
regs.x.dx = cursorpos[cs];
regs.h.ah = SETCURSOR;
regs.x.bx = video_page;
int86(VIDEO, &regs, &regs);
set_cursor_type(cursorshape[cs]);
*/
}
}
/* ------ make a normal cursor ------ */
void normalcursor(void)
{
/* set_cursor_type(0x0607); */
}
/* ------ hide the cursor ------ */
void hidecursor(void)
{
CONSOLE_CURSOR_INFO curInfo;
if (cursor_state == TRUE) {
cursor_state = FALSE;
memset(&curInfo, 0, sizeof(CONSOLE_CURSOR_INFO));
curInfo.dwSize = 1;
curInfo.bVisible = FALSE;
SetConsoleCursorInfo(hNewScreenBuffer, &curInfo);
}
}
/* ------ unhide the cursor ------ */
void unhidecursor(void)
{
CONSOLE_CURSOR_INFO curInfo;
if (cursor_state == FALSE) {
cursor_state = TRUE;
memset(&curInfo, 0, sizeof(CONSOLE_CURSOR_INFO));
curInfo.dwSize = 1;
curInfo.bVisible = TRUE;
SetConsoleCursorInfo(hNewScreenBuffer, &curInfo);
}
}
/* ---- use BIOS to set the cursor type ---- */
void set_cursor_type(unsigned t)
{
/*
videomode();
regs.h.ah = SETCURSORTYPE;
regs.x.bx = video_page;
regs.x.cx = t;
int86(VIDEO, &regs, &regs);
*/
}
/* ---- test for EGA -------- */
BOOL isEGA(void)
{
return 0;
}
/* ---- test for VGA -------- */
BOOL isVGA(void)
{
return 1;
}
/* ---------- set 25 line mode ------- */
void Set25(void)
{
}
/* ---------- set 43 line mode ------- */
void Set43(void)
{
}
/* ---------- set 50 line mode ------- */
void Set50(void)
{
}
/* ------ convert an Alt+ key to its letter equivalent ----- */
int AltConvert(int c)
{
int i, a = 0;
for (i = 0; i < 36; i++)
if (c == altconvert[i])
break;
if (i < 26)
a = 'a' + i;
else if (i < 36)
a = '0' + i - 26;
return a;
}
void w32_put_video(int x, int y, int ch_att)
{
SMALL_RECT srctRect;
COORD coordBufCoord;
chiBuffer[x+y*updateCoord.X].Char.AsciiChar = ch_att & 0xFF;
ch_att >>= 8;
coiBuffer[x+y*updateCoord.X] = ch_att;
chiBuffer[x+y*updateCoord.X].Attributes = col_fore[ch_att & 0xF] |
col_back[ch_att >> 4];
srctRect.Top = y;
srctRect.Left = x;
srctRect.Bottom = y;
srctRect.Right = x;
coordBufCoord.X = x;
coordBufCoord.Y = y;
WriteConsoleOutput(
hNewScreenBuffer,
chiBuffer,
updateCoord,
coordBufCoord,
&srctRect);
}
int w32_get_video(int x, int y)
{
int n = x+y*updateCoord.X;
return (chiBuffer[n].Char.AsciiChar & 0xFF) | (coiBuffer[n] << 8);
}
void w32_scroll_up(int x1,int y1,int x2,int y2,int attr)
{
int x,y,addr1,addr2,ch_att;
SMALL_RECT srctRect;
COORD coordBufCoord;
ch_att = col_fore[attr & 0xF] | col_back[attr >> 4];
addr1 = y1*updateCoord.X;
addr2 = addr1+updateCoord.X;
for (y=y1+1; y<=y2; y++,addr1=addr2,addr2+=updateCoord.X) {
for (x=x1; x<=x2; x++) {
chiBuffer[addr1+x].Char = chiBuffer[addr2+x].Char;
chiBuffer[addr1+x].Attributes = chiBuffer[addr2+x].Attributes;
coiBuffer[addr1+x] = coiBuffer[addr2+x];
}
}
for (x=x1; x<=x2; x++) {
chiBuffer[addr1+x].Char.AsciiChar = ' ';
chiBuffer[addr1+x].Attributes = ch_att;
coiBuffer[addr1+x] = attr;
}
srctRect.Top = y1;
srctRect.Left = x1;
srctRect.Bottom = y2;
srctRect.Right = x2;
coordBufCoord.X = x1;
coordBufCoord.Y = y1;
WriteConsoleOutput(
hNewScreenBuffer,
chiBuffer,
updateCoord,
coordBufCoord,
&srctRect);
}
void w32_scroll_dw(int x1,int y1,int x2,int y2,int attr)
{
int x,y,addr1,addr2,ch_att;
SMALL_RECT srctRect;
COORD coordBufCoord;
ch_att = col_fore[attr & 0xF] | col_back[attr >> 4];
addr1 = y2*updateCoord.X;
addr2 = addr1-updateCoord.X;
for (y=y2-1; y>=y1; y--,addr1=addr2,addr2-=updateCoord.X) {
for (x=x1; x<=x2; x++) {
chiBuffer[addr1+x].Char = chiBuffer[addr2+x].Char;
chiBuffer[addr1+x].Attributes = chiBuffer[addr2+x].Attributes;
coiBuffer[addr1+x] = coiBuffer[addr2+x];
}
}
for (x=x1; x<=x2; x++) {
chiBuffer[addr1+x].Char.AsciiChar = ' ';
chiBuffer[addr1+x].Attributes = ch_att;
coiBuffer[addr1+x] = attr;
}
srctRect.Top = y1;
srctRect.Left = x1;
srctRect.Bottom = y2;
srctRect.Right = x2;
coordBufCoord.X = x1;
coordBufCoord.Y = y1;
WriteConsoleOutput(
hNewScreenBuffer,
chiBuffer,
updateCoord,
coordBufCoord,
&srctRect);
}
void movetoscreen(void *bf, int offset, int len)
{
int x;
unsigned char *cbf = (unsigned char *)bf;
SMALL_RECT srctRect;
COORD coordBufCoord;
len >>= 1;
offset >>= 1;
for (x=0; x<len; x++,cbf+=2) {
chiBuffer[offset+x].Char.AsciiChar = cbf[0];
chiBuffer[offset+x].Attributes = col_fore[cbf[1] & 0xF] | col_back[cbf[1] >> 4];
coiBuffer[offset+x] = cbf[1];
}
srctRect.Top = offset/updateCoord.X;
srctRect.Left = offset%updateCoord.X;
srctRect.Bottom = (offset+len-1)/updateCoord.X;
srctRect.Right = (offset+len-1)%updateCoord.X;
coordBufCoord.X = srctRect.Left;
coordBufCoord.Y = srctRect.Top;
WriteConsoleOutput(
hNewScreenBuffer,
chiBuffer,
updateCoord,
coordBufCoord,
&srctRect);
}
void movefromscreen(void *bf, int offset, int len)
{
int x;
unsigned char *cbf = (unsigned char *)bf;
len >>= 1;
offset >>= 1;
for (x=0; x<len; x++, cbf+=2) {
cbf[0] = chiBuffer[offset+x].Char.AsciiChar;
cbf[1] = coiBuffer[offset+x];
}
}
int w32_screenwidth()
{
return updateCoord.X;
}
int w32_screenheight()
{
return updateCoord.Y;
}
void uninit_videomode(void)
{
free(chiBuffer);
free(coiBuffer);
SetConsoleActiveScreenBuffer(hConsoleOut);
CloseHandle(hNewScreenBuffer);
}
void w32_trap_to_sched(void)
{
Sleep(10);
}
/* ---------- reset the mouse ---------- */
void resetmouse(void)
{
}
/* ----- test to see if the mouse driver is installed ----- */
BOOL mouse_installed(void)
{
return 1;
}
/* ------ return true if mouse buttons are pressed ------- */
int mousebuttons(void)
{
update_key_buffer();
return b_mouse;
}
/* ---------- return mouse coordinates ---------- */
void get_mouseposition(int *x, int *y)
{
update_key_buffer();
*x = c_mouse.X;
*y = c_mouse.Y;
}
/* -------- position the mouse cursor -------- */
void set_mouseposition(int x, int y)
{
}
/* --------- display the mouse cursor -------- */
void show_mousecursor(void)
{
}
/* --------- hide the mouse cursor ------- */
void hide_mousecursor(void)
{
}
/* --- return true if a mouse button has been released --- */
int button_releases(void)
{
int ret;
update_key_buffer();
ret = s_mouse & ~b_mouse;
s_mouse = 0;
return ret;
}
/* ----- set mouse travel limits ------- */
void set_mousetravel(int minx, int maxx, int miny, int maxy)
{
minx=maxx=miny=maxy=0;
}

View File

@@ -0,0 +1,9 @@
#include <windows.h>
#include "country_w32.h"
struct COUNTRY *country( int xcode, struct COUNTRY *ct )
{
return NULL;
}

View File

@@ -0,0 +1,22 @@
#ifndef __country_w32_h__
#define __country_w32_h__
struct country {
int co_date; /* date format */
char co_curr[ 5 ]; /* currency symbol */
char co_thsep[ 2 ]; /* thousands separator */
char co_desep[ 2 ]; /* decimal separator */
char co_dtsep[ 2 ]; /* date separator */
char co_tmsep[ 2 ]; /* time separator */
char co_currstyle; /* currency style */
char co_digits; /* significant digits in currency */
char co_time; /* time format */
long co_case; /* case map */
char co_dasep[ 2 ]; /* data separator */
char co_fill[ 10 ]; /* filler */
};
#define COUNTRY country
struct COUNTRY *country( int xcode, struct COUNTRY *ct );
#endif

View File

@@ -0,0 +1,128 @@
/*
* Decompress the application.HLP file
* or load the application.TXT file if the .HLP file
* does not exist
*/
#include <assert.h>
#include "dflat.h"
#include "htree.h"
static int in8;
static int ct8 = 8;
static FILE *fi;
static BYTECOUNTER bytectr;
struct htr *HelpTree;
static int root;
/* ------- open the help database file -------- */
FILE *OpenHelpFile(const char *fn, const char *md)
{
int treect, i;
char helpname[65];
/* Get the name of the help file */
BuildFileName(helpname, fn, ".hlp");
if ((fi = fopen(helpname, md)) == NULL)
return NULL;
if (HelpTree == NULL)
{
fread(&bytectr, sizeof(bytectr), 1, fi); /* Read the byte count */
fread(&treect, sizeof(treect), 1, fi); /* Read the frequency count */
fread(&root, sizeof(root), 1, fi); /* Read the root offset */
HelpTree=calloc(treect-256, sizeof(struct htr));
if (HelpTree != NULL)
{
for (i=0;i<treect-256;i++) /* Read in the tree */
{
fread(&HelpTree[i].left, sizeof(HelpTree[i].left), 1, fi);
fread(&HelpTree[i].right, sizeof(HelpTree[i].right), 1, fi);
}
}
}
return fi;
}
/* ----- read a line of text from the help database ----- */
void *GetHelpLine(char *line)
{
int h;
*line = '\0';
while (TRUE)
{
/* Decompress a line from the file */
h=root;
/* Walk the Huffman tree */
while (h > 255)
{
/* h is a node pointer */
if (ct8 == 8)
{
/* Read 8 bits of compressed data */
if ((in8 = fgetc(fi)) == EOF)
{
*line = '\0';
return NULL;
}
ct8 = 0;
}
/* Point to left or right node based on msb */
if (in8 & 0x80)
h = HelpTree[h-256].left;
else
h = HelpTree[h-256].right;
/* Shift the next bit in */
in8 <<= 1;
ct8++;
}
/* h < 255 = decompressed character */
if (h == '\r') /* Skip the '\r' character */
continue;
*line++ = h; /* Put the character in the buffer */
if (h == '\n') /* End of line */
break;
}
*line = '\0'; /* Null-terminate the line */
return line;
}
/* --- compute the database file byte and bit position --- */
void HelpFilePosition(long *offset, int *bit)
{
*offset = ftell(fi);
if (ct8 < 8)
--*offset;
*bit = ct8;
}
/* -- position the database to the specified byte and bit -- */
void SeekHelpLine(long offset, int bit)
{
int fs = fseek(fi, offset, 0);
assert(fs == 0);
ct8 = bit;
if (ct8 < 8)
{
in8 = fgetc(fi);
in8 <<= bit;
}
}

View File

@@ -0,0 +1,75 @@
/* ---------- dfalloc.c ---------- */
#include "dflat.h"
static void AllocationError(void)
{
static BOOL OnceIn=FALSE;
extern jmp_buf AllocError;
extern BOOL AllocTesting;
static char *ErrMsg[]={
"ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿",
"³ Out of Memory! ³",
"ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ"};
int x,y;
char savbuf[108];
RECT rc={30,11,47,13};
if (!OnceIn)
{
OnceIn=TRUE;
/* Close all windows */
SendMessage(ApplicationWindow, CLOSE_WINDOW, 0, 0);
getvideo(rc, savbuf);
for (x=0;x<18;x++)
{
for (y=0;y<3;y++)
{
int c=(255 & (*(*(ErrMsg+y)+x))) | 0x7000;
PutVideoChar(x+rc.lf, y+rc.tp, c);
}
}
getkey();
storevideo(rc, savbuf);
if (AllocTesting)
longjmp(AllocError, 1);
}
}
void *DFcalloc(size_t nitems, size_t size)
{
void *rtn=calloc(nitems, size);
if (size && rtn == NULL)
AllocationError();
return rtn;
}
void *DFmalloc(size_t size)
{
void *rtn=malloc(size);
if (size && rtn == NULL)
AllocationError();
return rtn;
}
void *DFrealloc(void *block, size_t size)
{
void *rtn=(block == NULL) ? malloc(size) : realloc(block,size);
if (size && rtn == NULL)
AllocationError();
return rtn;
}

View File

@@ -0,0 +1,515 @@
/* ------------- dflat.h ----------- */
#ifndef DFLAT_H
#define DFLAT_H
#ifdef BUILD_FULL_DFLAT
#define INCLUDE_MULTI_WINDOWS
/* #define INCLUDE_LOGGING */
#define INCLUDE_SHELLDOS
#define INCLUDE_WINDOWOPTIONS
#define INCLUDE_PICTUREBOX
#define INCLUDE_MINIMIZE
#define INCLUDE_MAXIMIZE
#define INCLUDE_RESTORE
#define INCLUDE_EXTENDEDSELECTIONS
#endif
/* To disable calendar item in utils define NOCALENDAR */
/* #define NOCALENDAR */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <dos.h>
#include <process.h>
#include <conio.h>
#ifndef _WIN32
#include <bios.h>
#endif
#include <ctype.h>
#include <io.h>
#include <sys\types.h>
#include <sys\stat.h>
#include <time.h>
#include <setjmp.h>
#if defined(_WIN32) || defined(__DJGPP__)
#define far
#define near
#endif
#ifndef VERSION
#define VERSION "0.82"
#endif
/* currently only required so config file created/opened in same dir as main executable */
#define ENABLEGLOBALARGV
#ifdef ENABLEGLOBALARGV
extern char **Argv;
#endif
void *DFcalloc(size_t, size_t);
void *DFmalloc(size_t);
void *DFrealloc(void *, size_t);
typedef enum {FALSE, TRUE} BOOL;
#define MAXMESSAGES 100
#define DELAYTICKS 1
#define FIRSTDELAY 7
#define DOUBLETICKS 5
#ifdef _WIN32
#define MAXTEXTLEN (16*1024*1024) /* 16 MB is enought! */
#else
#define MAXTEXTLEN 65000U /* maximum text buffer */
#endif
#define EDITLEN 1024 /* starting length for multiliner */
#define ENTRYLEN 256 /* starting length for one-liner */
#define GROWLENGTH 64 /* buffers grow by this much */
#include "system.h"
#include "config.h"
#include "rect.h"
#include "menu.h"
#include "keys.h"
#include "commands.h"
#include "dialbox.h"
#include "helpbox.h"
/* ------ integer type for message parameters ----- */
typedef long PARAM;
enum Condition {
ISRESTORED, ISMINIMIZED, ISMAXIMIZED, ISCLOSING
};
typedef struct window {
CLASS Class; /* window class */
char *title; /* window title */
int (*wndproc)
(struct window *, enum messages, PARAM, PARAM);
/* ---------------- window dimensions ----------------- */
RECT rc; /* window coordinates
(0/0 to 79/24) */
int ht, wd; /* window height and width */
RECT RestoredRC; /* restored condition rect */
/* ----------------- window colors -------------------- */
char WindowColors[4][2];
/* -------------- linked list pointers ---------------- */
struct window *parent; /* parent window */
struct window *firstchild; /* first child this parent */
struct window *lastchild; /* last child this parent */
struct window *nextsibling; /* next sibling */
struct window *prevsibling; /* previous sibling */
struct window *childfocus; /* child that ha(s/d) focus */
int attrib; /* Window attributes */
char *videosave; /* video save buffer */
enum Condition condition; /* Restored, Maximized,
Minimized, Closing */
enum Condition oldcondition;/* previous condition */
BOOL wasCleared;
int restored_attrib; /* attributes when restored */
void *extension; /* menus, dialogs, documents, etc */
void *wrapper; /* used by C++ wrapper class */
struct window *PrevMouse; /* previous mouse capture */
struct window *PrevKeyboard;/* previous keyboard capture*/
struct window *PrevClock; /* previous clock capture */
struct window *MenuBarWnd;/* menu bar */
struct window *StatusBar; /* status bar */
int isHelping; /* > 0 when help is being displayed */
/* ----------------- text box fields ------------------ */
int wlines; /* number of lines of text */
int wtop; /* text line that is on the top display */
unsigned char *text; /* window text */
unsigned int textlen; /* text length */
int wleft; /* left position in window viewport */
int textwidth; /* width of longest line in textbox */
int BlkBegLine; /* beginning line of marked block */
int BlkBegCol; /* beginning column of marked block */
int BlkEndLine; /* ending line of marked block */
int BlkEndCol; /* ending column of marked block */
int HScrollBox; /* position of horizontal scroll box */
int VScrollBox; /* position of vertical scroll box */
unsigned int *TextPointers; /* -> list of line offsets */
/* ----------------- list box fields ------------------ */
int selection; /* current selection */
BOOL AddMode; /* adding extended selections mode */
int AnchorPoint;/* anchor point for extended selections */
int SelectCount;/* count of selected items */
/* ----------------- edit box fields ------------------ */
int CurrCol; /* Current column */
int CurrLine; /* Current line */
int WndRow; /* Current window row */
BOOL TextChanged; /* TRUE if text has changed */
BOOL protect; /* TRUE to display '*' */
unsigned char *DeletedText; /* for undo */
unsigned DeletedLength; /* Length of deleted field */
BOOL InsertMode; /* TRUE or FALSE for text insert */
BOOL WordWrapMode; /* TRUE or FALSE for word wrap */
unsigned int MaxTextLength; /* maximum text length */
/* ---------------- dialog box fields ----------------- */
int ReturnCode; /* return code from a dialog box */
BOOL Modal; /* True if a modeless dialog box */
CTLWINDOW *ct; /* control structure */
struct window *dfocus; /* control window that has focus */
/* -------------- popdownmenu fields ------------------ */
MENU *mnu; /* points to menu structure */
MBAR *holdmenu; /* previous active menu */
struct window *oldFocus;
/* -------------- status bar fields ------------------- */
BOOL TimePosted; /* True if time has been posted */
#ifdef INCLUDE_PICTUREBOX
/* ------------- picture box fields ------------------- */
int VectorCount; /* number of vectors in vector list */
void *VectorList; /* list of picture box vectors */
#endif
} * WINDOW;
#include "classdef.h"
#include "video.h"
void LogMessages (WINDOW, MESSAGE, PARAM, PARAM);
void MessageLog(WINDOW);
/* ------- window methods ----------- */
#define ICONHEIGHT 3
#define ICONWIDTH 10
#define WindowHeight(w) ((w)->ht)
#define WindowWidth(w) ((w)->wd)
#define BorderAdj(w) (TestAttribute(w,HASBORDER)?1:0)
#define BottomBorderAdj(w) (TestAttribute(w,HASSTATUSBAR)?1:BorderAdj(w))
#define TopBorderAdj(w) ((TestAttribute(w,HASTITLEBAR) && \
TestAttribute(w,HASMENUBAR)) ? \
2 : (TestAttribute(w,HASTITLEBAR | \
HASMENUBAR | HASBORDER) ? 1 : 0))
#define ClientWidth(w) (WindowWidth(w)-BorderAdj(w)*2)
#define ClientHeight(w) (WindowHeight(w)-TopBorderAdj(w)-\
BottomBorderAdj(w))
#define WindowRect(w) ((w)->rc)
#define GetTop(w) (RectTop(WindowRect(w)))
#define GetBottom(w) (RectBottom(WindowRect(w)))
#define GetLeft(w) (RectLeft(WindowRect(w)))
#define GetRight(w) (RectRight(WindowRect(w)))
#define GetClientTop(w) (GetTop(w)+TopBorderAdj(w))
#define GetClientBottom(w) (GetBottom(w)-BottomBorderAdj(w))
#define GetClientLeft(w) (GetLeft(w)+BorderAdj(w))
#define GetClientRight(w) (GetRight(w)-BorderAdj(w))
#define GetTitle(w) ((w)->title)
#define GetParent(w) ((w)->parent)
#define FirstWindow(w) ((w)->firstchild)
#define LastWindow(w) ((w)->lastchild)
#define NextWindow(w) ((w)->nextsibling)
#define PrevWindow(w) ((w)->prevsibling)
#define GetClass(w) ((w)->Class)
#define GetAttribute(w) ((w)->attrib)
#define AddAttribute(w,a) (GetAttribute(w) |= a)
#define ClearAttribute(w,a) (GetAttribute(w) &= ~(a))
#define TestAttribute(w,a) (GetAttribute(w) & (a))
#define isHidden(w) (!(GetAttribute(w) & VISIBLE))
#define SetVisible(w) (GetAttribute(w) |= VISIBLE)
#define ClearVisible(w) (GetAttribute(w) &= ~VISIBLE)
#define gotoxy(w,x,y) cursor(w->rc.lf+(x)+1,w->rc.tp+(y)+1)
BOOL isVisible(WINDOW);
WINDOW CreateWindow(CLASS,const char *,int,int,int,int,void*,WINDOW,
int (*)(struct window *,enum messages,PARAM,PARAM),int);
void AddTitle(WINDOW, const char *);
void InsertTitle(WINDOW, const char *);
void DisplayTitle(WINDOW, RECT *);
void RepaintBorder(WINDOW, RECT *);
void PaintShadow(WINDOW);
void ClearWindow(WINDOW, RECT *, int);
void writeline(WINDOW, char *, int, int, BOOL);
void InitWindowColors(WINDOW);
void SetNextFocus(void);
void SetPrevFocus(void);
void RemoveWindow(WINDOW);
void AppendWindow(WINDOW);
void ReFocus(WINDOW);
void SkipApplicationControls(void);
BOOL CharInView(WINDOW, int, int);
void CreatePath(char *, char *, int, int);
#define SwapVideoBuffer(wnd, ish, fh) swapvideo(wnd, wnd->videosave, ish, fh)
int LineLength(char *);
RECT AdjustRectangle(WINDOW, RECT);
BOOL isDerivedFrom(WINDOW, CLASS);
WINDOW GetAncestor(WINDOW);
void PutWindowChar(WINDOW,int,int,int);
void PutWindowLine(WINDOW, void *,int,int);
#define BaseWndProc(Class,wnd,msg,p1,p2) \
(*classdefs[(classdefs[Class].base)].wndproc)(wnd,msg,p1,p2)
#define DefaultWndProc(wnd,msg,p1,p2) \
(classdefs[wnd->Class].wndproc == NULL) ? \
BaseWndProc(wnd->Class,wnd,msg,p1,p2) : \
(*classdefs[wnd->Class].wndproc)(wnd,msg,p1,p2)
struct LinkedList {
WINDOW FirstWindow;
WINDOW LastWindow;
};
extern WINDOW ApplicationWindow;
extern WINDOW inFocus;
extern WINDOW CaptureMouse;
extern WINDOW CaptureKeyboard;
extern int foreground, background;
extern BOOL WindowMoving;
extern BOOL WindowSizing;
extern BOOL VSliding;
extern BOOL HSliding;
extern char DFlatApplication[];
extern char *Clipboard;
extern unsigned ClipboardLength;
extern BOOL ClipString;
extern int CurrentMenuSelection;
/* --------- space between menubar labels --------- */
#define MSPACE 2
/* --------------- border characters ------------- */
#define FOCUS_NW (unsigned char) '\xda' /* \xc9 */
#define FOCUS_NE (unsigned char) '\xbf' /* \xbb */
#define FOCUS_SE (unsigned char) '\xd9' /* \xbc */
#define FOCUS_SW (unsigned char) '\xc0' /* \xc8 */
#define FOCUS_SIDE (unsigned char) '\xb3' /* \xba */
#define FOCUS_LINE (unsigned char) '\xc4' /* \xcd */
#define NW (unsigned char) '\xda'
#define NE (unsigned char) '\xbf'
#define SE (unsigned char) '\xd9'
#define SW (unsigned char) '\xc0'
#define SIDE (unsigned char) '\xb3'
#define LINE (unsigned char) '\xc4'
#define LEDGE (unsigned char) '\xc3'
#define REDGE (unsigned char) '\xb4'
#define SIZETOKEN (unsigned char) '\x04'
/* ------------- scroll bar characters ------------ */
#define UPSCROLLBOX (unsigned char) '\x1e'
#define DOWNSCROLLBOX (unsigned char) '\x1f'
#define LEFTSCROLLBOX (unsigned char) '\x11'
#define RIGHTSCROLLBOX (unsigned char) '\x10'
#define SCROLLBARCHAR (unsigned char) 176
#define SCROLLBOXCHAR (unsigned char) 178
/* ------------------ menu characters --------------------- */
#define CHECKMARK (unsigned char) (SCREENHEIGHT==25?251:4)
#define CASCADEPOINTER (unsigned char) '\x10'
/* ----------------- title bar characters ----------------- */
#define CONTROLBOXCHAR (unsigned char) '\xf0'
#define MAXPOINTER 24 /* maximize token */
#define MINPOINTER 25 /* minimize token */
#define RESTOREPOINTER 18 /* restore token */
/* --------------- text control characters ---------------- */
#define APPLCHAR (unsigned char) 176 /* fills application window */
#define SHORTCUTCHAR '~' /* prefix: shortcut key display */
#define CHANGECOLOR (unsigned char) 174 /* prefix to change colors */
#define RESETCOLOR (unsigned char) 175 /* reset colors to default */
#define LISTSELECTOR 4 /* selected list box entry */
/* --------- message prototypes ----------- */
BOOL init_messages(void);
void PostEvent(MESSAGE, int, int);
void PostMessage(WINDOW, MESSAGE, PARAM, PARAM);
int SendMessage(WINDOW, MESSAGE, PARAM, PARAM);
BOOL dispatch_message(void);
void handshake(void);
int TestCriticalError(void);
/* ---- standard window message processing prototypes ----- */
int ApplicationProc(WINDOW, MESSAGE, PARAM, PARAM);
int NormalProc(WINDOW, MESSAGE, PARAM, PARAM);
int TextBoxProc(WINDOW, MESSAGE, PARAM, PARAM);
int ListBoxProc(WINDOW, MESSAGE, PARAM, PARAM);
int EditBoxProc(WINDOW, MESSAGE, PARAM, PARAM);
int EditorProc(WINDOW, MESSAGE, PARAM, PARAM);
int PictureProc(WINDOW, MESSAGE, PARAM, PARAM);
int MenuBarProc(WINDOW, MESSAGE, PARAM, PARAM);
int PopDownProc(WINDOW, MESSAGE, PARAM, PARAM);
int ButtonProc(WINDOW, MESSAGE, PARAM, PARAM);
int ComboProc(WINDOW, MESSAGE, PARAM, PARAM);
int TextProc(WINDOW, MESSAGE, PARAM, PARAM);
int RadioButtonProc(WINDOW, MESSAGE, PARAM, PARAM);
int CheckBoxProc(WINDOW, MESSAGE, PARAM, PARAM);
int SpinButtonProc(WINDOW, MESSAGE, PARAM, PARAM);
int BoxProc(WINDOW, MESSAGE, PARAM, PARAM);
int DialogProc(WINDOW, MESSAGE, PARAM, PARAM);
int SystemMenuProc(WINDOW, MESSAGE, PARAM, PARAM);
int HelpBoxProc(WINDOW, MESSAGE, PARAM, PARAM);
int MessageBoxProc(WINDOW, MESSAGE, PARAM, PARAM);
int CancelBoxProc(WINDOW, MESSAGE, PARAM, PARAM);
int ErrorBoxProc(WINDOW, MESSAGE, PARAM, PARAM);
int YesNoBoxProc(WINDOW, MESSAGE, PARAM, PARAM);
int StatusBarProc(WINDOW, MESSAGE, PARAM, PARAM);
int WatchIconProc(WINDOW, MESSAGE, PARAM, PARAM);
/* ------------- normal box prototypes ------------- */
void SetStandardColor(WINDOW);
void SetReverseColor(WINDOW);
BOOL isAncestor(WINDOW, WINDOW);
#define HitControlBox(wnd, p1, p2) \
(TestAttribute(wnd, CONTROLBOX) && \
p1 == 2 && p2 == 0)
#define WndForeground(wnd) \
(wnd->WindowColors [STD_COLOR] [FG])
#define WndBackground(wnd) \
(wnd->WindowColors [STD_COLOR] [BG])
#define FrameForeground(wnd) \
(wnd->WindowColors [FRAME_COLOR] [FG])
#define FrameBackground(wnd) \
(wnd->WindowColors [FRAME_COLOR] [BG])
#define SelectForeground(wnd) \
(wnd->WindowColors [SELECT_COLOR] [FG])
#define SelectBackground(wnd) \
(wnd->WindowColors [SELECT_COLOR] [BG])
#define HighlightForeground(wnd) \
(wnd->WindowColors [HILITE_COLOR] [FG])
#define HighlightBackground(wnd) \
(wnd->WindowColors [HILITE_COLOR] [BG])
#define WindowClientColor(wnd, fg, bg) \
WndForeground(wnd) = fg, WndBackground(wnd) = bg
#define WindowReverseColor(wnd, fg, bg) \
SelectForeground(wnd) = fg, SelectBackground(wnd) = bg
#define WindowFrameColor(wnd, fg, bg) \
FrameForeground(wnd) = fg, FrameBackground(wnd) = bg
#define WindowHighlightColor(wnd, fg, bg) \
HighlightForeground(wnd) = fg, HighlightBackground(wnd) = bg
/* -------- text box prototypes ---------- */
#define TextLine(wnd, sel) \
(wnd->text + *((wnd->TextPointers) + sel))
void WriteTextLine(WINDOW, RECT *, int, BOOL);
#define TextBlockMarked(wnd) ( wnd->BlkBegLine || \
wnd->BlkEndLine || \
wnd->BlkBegCol || \
wnd->BlkEndCol)
void MarkTextBlock(WINDOW, int, int, int, int);
#define ClearTextBlock(wnd) wnd->BlkBegLine = wnd->BlkEndLine = \
wnd->BlkBegCol = wnd->BlkEndCol = 0;
#define TextBlockBegin(wnd) (TextLine(wnd,wnd->BlkBegLine)+wnd->BlkBegCol)
#define TextBlockEnd(wnd) (TextLine(wnd,wnd->BlkEndLine)+wnd->BlkEndCol)
#define GetText(w) ((w)->text)
#define GetTextLines(w) ((w)->wlines)
void ClearTextPointers(WINDOW);
void BuildTextPointers(WINDOW);
int TextLineNumber(WINDOW, char *);
/* ------------ Clipboard prototypes ------------- */
void CopyTextToClipboard(char *);
void CopyMemToClipboard(void *, int);
char *ReadClipboard(void);
void CopyToClipboard(WINDOW);
#define PasteFromClipboard(wnd) PasteText(wnd,ReadClipboard(),ClipboardLength)
BOOL PasteText(WINDOW, char *, unsigned);
void ClearClipboard(void);
/* --------- menu prototypes ---------- */
int CopyCommand(unsigned char *, unsigned char *, int, int);
void PrepFileMenu(void *, struct Menu *);
void PrepEditMenu(void *, struct Menu *);
void PrepSearchMenu(void *, struct Menu *);
void PrepWindowMenu(void *, struct Menu *);
void BuildSystemMenu(WINDOW);
BOOL isActive(MBAR *, int);
char *GetCommandText(MBAR *, int);
BOOL isCascadedCommand(MBAR *,int);
void ActivateCommand(MBAR *,int);
void DeactivateCommand(MBAR *,int);
BOOL GetCommandToggle(MBAR *,int);
void SetCommandToggle(MBAR *,int);
void ClearCommandToggle(MBAR *,int);
void InvertCommandToggle(MBAR *,int);
int BarSelection(int);
/* ------------- list box prototypes -------------- */
BOOL ItemSelected(WINDOW, int);
/* ------------- edit box prototypes ----------- */
#define CurrChar (TextLine(wnd, wnd->CurrLine)+wnd->CurrCol)
#define WndCol (wnd->CurrCol-wnd->wleft)
#define isMultiLine(wnd) TestAttribute(wnd, MULTILINE)
#define SetProtected(wnd) (wnd)->protect=TRUE
void SearchText(WINDOW);
void ReplaceText(WINDOW);
void SearchNext(WINDOW);
/* ------------- editor prototypes ----------- */
void CollapseTabs(WINDOW wnd);
void ExpandTabs(WINDOW wnd);
/* --------- message box prototypes -------- */
WINDOW SliderBox(int, char *, char *);
BOOL InputBox(WINDOW, char *, char *, char *, int, int);
BOOL GenericMessage(WINDOW, char *, char *, int,
int (*)(struct window *, enum messages, PARAM, PARAM),
char *, char *, int, int, int);
#define TestErrorMessage(msg) \
GenericMessage(NULL, "Error", msg, 2, ErrorBoxProc, \
Ok, Cancel, ID_OK, ID_CANCEL, TRUE)
#define ErrorMessage(msg) \
GenericMessage(NULL, "Error", msg, 1, ErrorBoxProc, \
Ok, NULL, ID_OK, 0, TRUE)
#define MessageBox(ttl, msg) \
GenericMessage(NULL, ttl, msg, 1, MessageBoxProc, \
Ok, NULL, ID_OK, 0, TRUE)
#define YesNoBox(msg) \
GenericMessage(NULL, "", msg, 2, YesNoBoxProc, \
Yes, No, ID_OK, ID_CANCEL, TRUE)
#define CancelBox(wnd, msg) \
GenericMessage(wnd, "Wait...", msg, 1, CancelBoxProc, \
Cancel, NULL, ID_CANCEL, 0, FALSE)
void CloseCancelBox(void);
WINDOW MomentaryMessage(char *);
int MsgHeight(char *);
int MsgWidth(char *);
/* ------------- dialog box prototypes -------------- */
BOOL DialogBox(WINDOW, DBOX *, BOOL,
int (*)(struct window *, enum messages, PARAM, PARAM));
void ClearDialogBoxes(void);
BOOL OpenFileDialogBox(char *, char *);
BOOL SaveAsDialogBox(char *, char *, char *);
void GetDlgListText(WINDOW, char *, enum commands);
BOOL RadioButtonSetting(DBOX *, enum commands);
void PushRadioButton(DBOX *, enum commands);
void PutItemText(WINDOW, enum commands, char *);
void PutComboListText(WINDOW, enum commands, char *);
void GetItemText(WINDOW, enum commands, char *, int);
char *GetDlgTextString(DBOX *, enum commands, CLASS);
void SetDlgTextString(DBOX *, enum commands, char *, CLASS);
BOOL CheckBoxSetting(DBOX *, enum commands);
CTLWINDOW *FindCommand(DBOX *, enum commands, int);
WINDOW ControlWindow(const DBOX *, enum commands);
void SetScrollBars(WINDOW);
void SetRadioButton(DBOX *, CTLWINDOW *);
void ControlSetting(DBOX *, enum commands, int, int);
BOOL isControlOn(DBOX *, enum commands, int);
void SetFocusCursor(WINDOW);
#define GetControl(wnd) (wnd->ct)
#define GetDlgText(db, cmd) GetDlgTextString(db, cmd, TEXT)
#define GetDlgTextBox(db, cmd) GetDlgTextString(db, cmd, TEXTBOX)
#define GetEditBoxText(db, cmd) GetDlgTextString(db, cmd, EDITBOX)
#define GetComboBoxText(db, cmd) GetDlgTextString(db, cmd, COMBOBOX)
#define SetDlgText(db, cmd, s) SetDlgTextString(db, cmd, s, TEXT)
#define SetDlgTextBox(db, cmd, s) SetDlgTextString(db, cmd, s, TEXTBOX)
#define SetEditBoxText(db, cmd, s) SetDlgTextString(db, cmd, s, EDITBOX)
#define SetComboBoxText(db, cmd, s) SetDlgTextString(db, cmd, s, COMBOBOX)
#define SetDlgTitle(db, ttl) ((db)->dwnd.title = ttl)
#define SetCheckBox(db, cmd) ControlSetting(db, cmd, CHECKBOX, ON)
#define ClearCheckBox(db, cmd) ControlSetting(db, cmd, CHECKBOX, OFF)
#define EnableButton(db, cmd) ControlSetting(db, cmd, BUTTON, ON)
#define DisableButton(db, cmd) ControlSetting(db, cmd, BUTTON, OFF)
#define ButtonEnabled(db, cmd) isControlOn(db, cmd, BUTTON)
#define CheckBoxEnabled(db, cmd) isControlOn(db, cmd, CHECKBOX)
/* ---- types of vectors that can be in a picture box ------- */
enum VectTypes {VECTOR, SOLIDBAR, HEAVYBAR, CROSSBAR, LIGHTBAR};
/* ------------- picture box prototypes ------------- */
void DrawVector(WINDOW, int, int, int, int);
void DrawBox(WINDOW, int, int, int, int);
void DrawBar(WINDOW, enum VectTypes, int, int, int, int);
WINDOW WatchIcon(void);
/* ------------- help box prototypes ------------- */
int LoadHelpFile(char *);
void UnLoadHelpFile(void);
BOOL DisplayHelp(WINDOW, char *);
char *HelpComment(char *);
extern char *ClassNames[];
void BuildFileName(char *path, const char *fn, const char *ext);
/* -------------- calendar ------------------------ */
#ifndef NOCALENDAR
void Calendar(WINDOW pwnd);
#endif
#endif

View File

@@ -0,0 +1,105 @@
/* ----------- dflatmsg.h ------------ */
/*
* message foundation file
* make message changes here
* other source files will adapt
*/
/* -------------- process communication messages ----------- */
DFlatMsg(START) /* start message processing */
DFlatMsg(STOP) /* stop message processing */
DFlatMsg(COMMAND) /* send a command to a window */
/* -------------- window management messages --------------- */
DFlatMsg(CREATE_WINDOW) /* create a window */
DFlatMsg(OPEN_WINDOW) /* open a window */
DFlatMsg(SHOW_WINDOW) /* show a window */
DFlatMsg(HIDE_WINDOW) /* hide a window */
DFlatMsg(CLOSE_WINDOW) /* delete a window */
DFlatMsg(SETFOCUS) /* set and clear the focus */
DFlatMsg(PAINT) /* paint the window's data space*/
DFlatMsg(BORDER) /* paint the window's border */
DFlatMsg(TITLE) /* display the window's title */
DFlatMsg(MOVE) /* move the window */
DFlatMsg(SIZE) /* change the window's size */
#ifdef INCLUDE_MAXIMIZE
DFlatMsg(MAXIMIZE) /* maximize the window */
#endif
#ifdef INCLUDE_MINIMIZE
DFlatMsg(MINIMIZE) /* minimize the window */
#endif
DFlatMsg(RESTORE) /* restore the window */
DFlatMsg(INSIDE_WINDOW) /* test x/y inside a window */
/* ---------------- clock messages ------------------------- */
DFlatMsg(CLOCKTICK) /* the clock ticked */
DFlatMsg(CAPTURE_CLOCK) /* capture clock into a window */
DFlatMsg(RELEASE_CLOCK) /* release clock to the system */
/* -------------- keyboard and screen messages ------------- */
DFlatMsg(KEYBOARD) /* key was pressed */
DFlatMsg(CAPTURE_KEYBOARD) /* capture keyboard into a window */
DFlatMsg(RELEASE_KEYBOARD) /* release keyboard to system */
DFlatMsg(KEYBOARD_CURSOR) /* position the keyboard cursor */
DFlatMsg(CURRENT_KEYBOARD_CURSOR) /*read the cursor position */
DFlatMsg(HIDE_CURSOR) /* hide the keyboard cursor */
DFlatMsg(SHOW_CURSOR) /* display the keyboard cursor */
DFlatMsg(SAVE_CURSOR) /* save the cursor's configuration*/
DFlatMsg(RESTORE_CURSOR) /* restore the saved cursor */
DFlatMsg(SHIFT_CHANGED) /* the shift status changed */
DFlatMsg(WAITKEYBOARD) /* waits for a key to be released */
/* ---------------- mouse messages ------------------------- */
DFlatMsg(RESET_MOUSE) /* reset the mouse */
DFlatMsg(MOUSE_TRAVEL) /* set the mouse travel */
DFlatMsg(MOUSE_INSTALLED) /* test for mouse installed */
DFlatMsg(RIGHT_BUTTON) /* right button pressed */
DFlatMsg(LEFT_BUTTON) /* left button pressed */
DFlatMsg(DOUBLE_CLICK) /* left button double-clicked */
DFlatMsg(MOUSE_MOVED) /* mouse changed position */
DFlatMsg(BUTTON_RELEASED) /* mouse button released */
DFlatMsg(CURRENT_MOUSE_CURSOR)/* get mouse position */
DFlatMsg(MOUSE_CURSOR) /* set mouse position */
DFlatMsg(SHOW_MOUSE) /* make mouse cursor visible */
DFlatMsg(HIDE_MOUSE) /* hide mouse cursor */
DFlatMsg(WAITMOUSE) /* wait until button released */
DFlatMsg(TESTMOUSE) /* test any mouse button pressed*/
DFlatMsg(CAPTURE_MOUSE) /* capture mouse into a window */
DFlatMsg(RELEASE_MOUSE) /* release the mouse to system */
/* ---------------- text box messages ---------------------- */
DFlatMsg(ADDTEXT) /* append text to the text box */
DFlatMsg(INSERTTEXT) /* insert line of text */
DFlatMsg(DELETETEXT) /* delete line of text */
DFlatMsg(CLEARTEXT) /* clear the edit box */
DFlatMsg(SETTEXT) /* copy text to text buffer */
DFlatMsg(SCROLL) /* vertical line scroll */
DFlatMsg(HORIZSCROLL) /* horizontal column scroll */
DFlatMsg(SCROLLPAGE) /* vertical page scroll */
DFlatMsg(HORIZPAGE) /* horizontal page scroll */
DFlatMsg(SCROLLDOC) /* scroll to beginning/end */
/* ---------------- edit box messages ---------------------- */
DFlatMsg(GETTEXT) /* get text from an edit box */
DFlatMsg(SETTEXTLENGTH) /* set maximum text length */
/* ---------------- menubar messages ----------------------- */
DFlatMsg(BUILDMENU) /* build the menu display */
DFlatMsg(MB_SELECTION) /* menubar selection */
/* ---------------- popdown messages ----------------------- */
DFlatMsg(BUILD_SELECTIONS) /* build the menu display */
DFlatMsg(CLOSE_POPDOWN) /* tell parent popdown is closing */
/* ---------------- list box messages ---------------------- */
DFlatMsg(LB_SELECTION) /* sent to parent on selection */
DFlatMsg(LB_CHOOSE) /* sent when user chooses */
DFlatMsg(LB_CURRENTSELECTION)/* return the current selection */
DFlatMsg(LB_GETTEXT) /* return the text of selection */
DFlatMsg(LB_SETSELECTION) /* sets the listbox selection */
/* ---------------- dialog box messages -------------------- */
DFlatMsg(INITIATE_DIALOG) /* begin a dialog */
DFlatMsg(ENTERFOCUS) /* tell DB control got focus */
DFlatMsg(LEAVEFOCUS) /* tell DB control lost focus */
DFlatMsg(ENDDIALOG) /* end a dialog */
/* ---------------- help box messages ---------------------- */
DFlatMsg(DISPLAY_HELP)
/* --------------- application window messages ------------- */
DFlatMsg(ADDSTATUS)
/* --------------- picture box messages -------------------- */
DFlatMsg(DRAWVECTOR)
DFlatMsg(DRAWBOX)
DFlatMsg(DRAWBAR)

View File

@@ -0,0 +1,841 @@
/* ----------------- dialbox.c -------------- */
#include "dflat.h"
static int inFocusCommand(DBOX *);
static BOOL dbShortcutKeys(DBOX *, int);
static int ControlProc(WINDOW, MESSAGE, PARAM, PARAM);
static void FirstFocus(DBOX *db);
static void NextFocus(DBOX *db);
static void PrevFocus(DBOX *db);
static CTLWINDOW *AssociatedControl(DBOX *, enum commands);
static BOOL SysMenuOpen;
static DBOX **dbs = NULL;
static int dbct = 0;
/* --- clear all heap allocations to control text fields --- */
void ClearDialogBoxes(void)
{
int i;
for (i=0;i<dbct;i++)
{
CTLWINDOW *ct = (*(dbs+i))->ctl;
while (ct->Class)
{
if ((ct->Class == EDITBOX || ct->Class == TEXTBOX || ct->Class == COMBOBOX) && ct->itext != NULL)
{
free(ct->itext);
ct->itext = NULL;
}
ct++;
}
}
if (dbs != NULL)
{
free(dbs);
dbs = NULL;
}
dbct = 0;
}
/* -------- CREATE_WINDOW Message --------- */
static int CreateWindowMsg(WINDOW wnd, PARAM p1, PARAM p2)
{
DBOX *db = wnd->extension;
CTLWINDOW *ct = db->ctl;
WINDOW cwnd;
int rtn, i;
/* ---- build a table of processed dialog boxes ---- */
for (i=0;i<dbct;i++)
if (db == dbs[i])
break;
if (i == dbct)
{
dbs = DFrealloc(dbs, sizeof(DBOX *) * (dbct+1));
*(dbs + dbct++) = db;
}
rtn = BaseWndProc(DIALOG, wnd, CREATE_WINDOW, p1, p2);
ct = db->ctl;
while (ct->Class)
{
int attrib = 0;
if (TestAttribute(wnd, NOCLIP))
attrib |= NOCLIP;
if (wnd->Modal)
attrib |= SAVESELF;
ct->setting = ct->isetting;
if (ct->Class == EDITBOX && ct->dwnd.h > 1)
attrib |= (MULTILINE | HASBORDER);
else if ((ct->Class == LISTBOX || ct->Class == TEXTBOX) && ct->dwnd.h > 2)
attrib |= HASBORDER;
cwnd = CreateWindow(ct->Class,
ct->dwnd.title,
ct->dwnd.x+GetClientLeft(wnd),
ct->dwnd.y+GetClientTop(wnd),
ct->dwnd.h,
ct->dwnd.w,
ct,
wnd,
ControlProc,
attrib);
if ((ct->Class == EDITBOX || ct->Class == TEXTBOX ||
ct->Class == COMBOBOX) && ct->itext != NULL)
SendMessage(cwnd, SETTEXT, (PARAM) ct->itext, 0);
ct++;
}
return rtn;
}
/* -------- LEFT_BUTTON Message --------- */
static BOOL LeftButtonMsg(WINDOW wnd, PARAM p1, PARAM p2)
{
DBOX *db = wnd->extension;
CTLWINDOW *ct = db->ctl;
if (WindowSizing || WindowMoving)
return TRUE;
if (HitControlBox(wnd, p1-GetLeft(wnd), p2-GetTop(wnd))) {
PostMessage(wnd, KEYBOARD, ' ', ALTKEY);
return TRUE;
}
while (ct->Class) {
WINDOW cwnd = ct->wnd;
if (ct->Class == COMBOBOX) {
if (p2 == GetTop(cwnd)) {
if (p1 == GetRight(cwnd)+1) {
SendMessage(cwnd, LEFT_BUTTON, p1, p2);
return TRUE;
}
}
if (GetClass(inFocus) == LISTBOX)
SendMessage(wnd, SETFOCUS, TRUE, 0);
}
else if (ct->Class == SPINBUTTON) {
if (p2 == GetTop(cwnd)) {
if (p1 == GetRight(cwnd)+1 ||
p1 == GetRight(cwnd)+2) {
SendMessage(cwnd, LEFT_BUTTON, p1, p2);
return TRUE;
}
}
}
ct++;
}
return FALSE;
}
/* -------- KEYBOARD Message --------- */
static BOOL KeyboardMsg(WINDOW wnd, PARAM p1, PARAM p2)
{
DBOX *db = wnd->extension;
CTLWINDOW *ct;
if (WindowMoving || WindowSizing)
return FALSE;
switch ((int)p1)
{
case F1:
ct = GetControl(inFocus);
if (ct != NULL)
if (DisplayHelp(wnd, ct->help))
return TRUE;
break;
case SHIFT_HT:
case LARROW:
case UP:
PrevFocus(db);
break;
case ALT_F6:
case '\t':
case FWD:
case DN:
NextFocus(db);
break;
case ' ':
if (((int)p2 & ALTKEY) && TestAttribute(wnd, CONTROLBOX))
{
SysMenuOpen = TRUE;
BuildSystemMenu(wnd);
return TRUE;
}
break;
case CTRL_F4:
case ESC:
SendMessage(wnd, COMMAND, ID_CANCEL, 0);
break;
default:
/* ------ search all the shortcut keys ----- */
if (dbShortcutKeys(db, (int) p1))
return TRUE;
break;
}
return wnd->Modal;
}
/* -------- COMMAND Message --------- */
static BOOL CommandMsg(WINDOW wnd, PARAM p1, PARAM p2)
{
DBOX *db = wnd->extension;
switch ((int) p1)
{
case ID_OK:
case ID_CANCEL:
if ((int)p2 != 0)
return TRUE;
wnd->ReturnCode = (int) p1;
if (wnd->Modal)
PostMessage(wnd, ENDDIALOG, 0, 0);
else
SendMessage(wnd, CLOSE_WINDOW, TRUE, 0);
return TRUE;
case ID_THREE:
if ((int)p2 != 0)
return FALSE;
wnd->ReturnCode = (int) p1;
PostMessage(wnd, ENDDIALOG, 0, 0);
SendMessage(wnd, PAINT, 0, 0);
return FALSE;
case ID_HELP:
if ((int)p2 != 0)
return TRUE;
return DisplayHelp(wnd, db->HelpName);
default:
break;
}
return FALSE;
}
/* ----- window-processing module, DIALOG window class ----- */
int DialogProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
int rtn;
DBOX *db = wnd->extension;
switch (msg) {
case CREATE_WINDOW:
return CreateWindowMsg(wnd, p1, p2);
case SHIFT_CHANGED:
if (wnd->Modal)
return TRUE;
break;
case LEFT_BUTTON:
if (LeftButtonMsg(wnd, p1, p2))
return TRUE;
break;
case KEYBOARD:
if (KeyboardMsg(wnd, p1, p2))
return TRUE;
break;
case CLOSE_POPDOWN:
SysMenuOpen = FALSE;
break;
case LB_SELECTION:
case LB_CHOOSE:
if (SysMenuOpen)
return TRUE;
SendMessage(wnd, COMMAND, inFocusCommand(db), msg);
break;
case SETFOCUS:
if ((int)p1 && wnd->dfocus != NULL && isVisible(wnd))
return SendMessage(wnd->dfocus, SETFOCUS, TRUE, 0);
break;
case COMMAND:
if (CommandMsg(wnd, p1, p2))
return TRUE;
break;
case PAINT:
p2 = TRUE;
break;
case MOVE:
case SIZE:
rtn = BaseWndProc(DIALOG, wnd, msg, p1, p2);
if (wnd->dfocus != NULL && isVisible(wnd))
SendMessage(wnd->dfocus, SETFOCUS, TRUE, 0);
return rtn;
case CLOSE_WINDOW:
if (!p1) {
SendMessage(wnd, COMMAND, ID_CANCEL, 0);
return TRUE;
}
break;
default:
break;
}
return BaseWndProc(DIALOG, wnd, msg, p1, p2);
}
/* ------- create and execute a dialog box ---------- */
BOOL DialogBox(WINDOW wnd, DBOX *db, BOOL Modal,
int (*wndproc)(struct window *, enum messages, PARAM, PARAM))
{
BOOL rtn = FALSE;
int x = db->dwnd.x, y = db->dwnd.y;
WINDOW DialogWnd;
DialogWnd = CreateWindow(DIALOG,
db->dwnd.title,
x, y,
db->dwnd.h,
db->dwnd.w,
db,
wnd,
wndproc,
(Modal ? SAVESELF : 0));
SendMessage(DialogWnd, SETFOCUS, TRUE, 0);
DialogWnd->Modal = Modal;
FirstFocus(db);
PostMessage(DialogWnd, INITIATE_DIALOG, 0, 0);
if (Modal) {
SendMessage(DialogWnd, CAPTURE_MOUSE, 0, 0);
SendMessage(DialogWnd, CAPTURE_KEYBOARD, 0, 0);
while (dispatch_message())
TRAP_TO_SCHEDULER
;
rtn = DialogWnd->ReturnCode == ID_OK;
SendMessage(DialogWnd, RELEASE_MOUSE, 0, 0);
SendMessage(DialogWnd, RELEASE_KEYBOARD, 0, 0);
SendMessage(DialogWnd, CLOSE_WINDOW, TRUE, 0);
}
return rtn;
}
/* ----- return command code of in-focus control window ---- */
static int inFocusCommand(DBOX *db)
{
CTLWINDOW *ct = db->ctl;
while (ct->Class) {
if (ct->wnd == inFocus)
return ct->command;
ct++;
}
return -1;
}
/* -------- find a specified control structure ------- */
CTLWINDOW *FindCommand(DBOX *db, enum commands cmd, int Class)
{
CTLWINDOW *ct = db->ctl;
while (ct->Class) {
if (Class == -1 || ct->Class == Class)
if (cmd == ct->command)
return ct;
ct++;
}
return NULL;
}
/* ---- return the window handle of a specified command ---- */
WINDOW ControlWindow(const DBOX *db, enum commands cmd)
{
const CTLWINDOW *ct = db->ctl;
while (ct->Class) {
if (ct->Class != TEXT && cmd == ct->command)
return ct->wnd;
ct++;
}
return NULL;
}
/* --- return a pointer to the control structure that matches a window --- */
CTLWINDOW *WindowControl(DBOX *db, WINDOW wnd)
{
CTLWINDOW *ct = db->ctl;
while (ct->Class) {
if (ct->wnd == wnd)
return ct;
ct++;
}
return NULL;
}
/* ---- set a control ON or OFF ----- */
void ControlSetting(DBOX *db, enum commands cmd,
int Class, int setting)
{
CTLWINDOW *ct = FindCommand(db, cmd, Class);
if (ct != NULL) {
ct->isetting = setting;
if (ct->wnd != NULL)
ct->setting = setting;
}
}
/* ----- test if a control is on or off ----- */
BOOL isControlOn(DBOX *db, enum commands cmd, int Class)
{
const CTLWINDOW *ct = FindCommand(db, cmd, Class);
return ct ? (ct->wnd ? ct->setting : ct->isetting) : FALSE;
}
/* ---- return pointer to the text of a control window ---- */
char *GetDlgTextString(DBOX *db,enum commands cmd,CLASS Class)
{
CTLWINDOW *ct = FindCommand(db, cmd, Class);
if (ct != NULL)
return ct->itext;
else
return NULL;
}
/* ------- set the text of a control specification ------ */
void SetDlgTextString(DBOX *db, enum commands cmd,
char *text, CLASS Class)
{
CTLWINDOW *ct = FindCommand(db, cmd, Class);
if (ct != NULL) {
if (text != NULL) {
if (ct->Class == TEXT)
ct->itext = text; /* text may not go out of scope */
else {
ct->itext = DFrealloc(ct->itext, strlen(text)+1);
strcpy(ct->itext, text);
}
}
else {
if (ct->Class == TEXT)
ct->itext = "";
else {
free(ct->itext);
ct->itext = NULL;
}
}
if (ct->wnd != NULL) {
if (text != NULL)
SendMessage(ct->wnd, SETTEXT, (PARAM) text, 0);
else
SendMessage(ct->wnd, CLEARTEXT, 0, 0);
SendMessage(ct->wnd, PAINT, 0, 0);
}
}
}
/* ------- set the text of a control window ------ */
void PutItemText(WINDOW wnd, enum commands cmd, char *text)
{
CTLWINDOW *ct = FindCommand(wnd->extension, cmd, EDITBOX);
if (ct == NULL)
ct = FindCommand(wnd->extension, cmd, TEXTBOX);
if (ct == NULL)
ct = FindCommand(wnd->extension, cmd, COMBOBOX);
if (ct == NULL)
ct = FindCommand(wnd->extension, cmd, LISTBOX);
if (ct == NULL)
ct = FindCommand(wnd->extension, cmd, SPINBUTTON);
if (ct == NULL)
ct = FindCommand(wnd->extension, cmd, TEXT);
if (ct != NULL) {
WINDOW cwnd = (WINDOW) (ct->wnd);
switch (ct->Class) {
case COMBOBOX:
case EDITBOX:
SendMessage(cwnd, CLEARTEXT, 0, 0);
SendMessage(cwnd, ADDTEXT, (PARAM) text, 0);
if (!isMultiLine(cwnd))
SendMessage(cwnd, PAINT, 0, 0);
break;
case LISTBOX:
case TEXTBOX:
case SPINBUTTON:
SendMessage(cwnd, ADDTEXT, (PARAM) text, 0);
break;
case TEXT: {
SendMessage(cwnd, CLEARTEXT, 0, 0);
SendMessage(cwnd, ADDTEXT, (PARAM) text, 0);
SendMessage(cwnd, PAINT, 0, 0);
break;
}
default:
break;
}
}
}
/* ------- get the text of a control window ------ */
void GetItemText(WINDOW wnd, enum commands cmd,
char *text, int len)
{
CTLWINDOW *ct = FindCommand(wnd->extension, cmd, EDITBOX);
unsigned char *cp;
if (ct == NULL)
ct = FindCommand(wnd->extension, cmd, COMBOBOX);
if (ct == NULL)
ct = FindCommand(wnd->extension, cmd, TEXTBOX);
if (ct == NULL)
ct = FindCommand(wnd->extension, cmd, TEXT);
if (ct != NULL) {
WINDOW cwnd = (WINDOW) (ct->wnd);
if (cwnd != NULL) {
switch (ct->Class) {
case TEXT:
if (GetText(cwnd) != NULL) {
cp = strchr(GetText(cwnd), '\n');
if (cp != NULL)
len = (int) (cp - GetText(cwnd));
strncpy(text, GetText(cwnd), len);
*(text+len) = '\0';
}
break;
case TEXTBOX:
if (GetText(cwnd) != NULL)
strncpy(text, GetText(cwnd), len);
break;
case COMBOBOX:
case EDITBOX:
SendMessage(cwnd,GETTEXT,(PARAM)text,len);
break;
default:
break;
}
}
}
}
/* ------- set the text of a listbox control window ------ */
void GetDlgListText(WINDOW wnd, char *text, enum commands cmd)
{
CTLWINDOW *ct = FindCommand(wnd->extension, cmd, LISTBOX);
int sel = SendMessage(ct->wnd, LB_CURRENTSELECTION, 0, 0);
SendMessage(ct->wnd, LB_GETTEXT, (PARAM) text, sel);
}
/* -- find control structure associated with text control -- */
static CTLWINDOW *AssociatedControl(DBOX *db,enum commands Tcmd)
{
CTLWINDOW *ct = db->ctl;
while (ct->Class) {
if (ct->Class != TEXT)
if (ct->command == Tcmd)
break;
ct++;
}
return ct;
}
/* --- process dialog box shortcut keys --- */
static BOOL dbShortcutKeys(DBOX *db, int ky)
{
CTLWINDOW *ct;
int ch = AltConvert(ky);
if (ch != 0) {
ct = db->ctl;
while (ct->Class) {
char *cp = ct->itext;
while (cp && *cp) {
if (*cp == SHORTCUTCHAR &&
tolower(*(cp+1)) == ch) {
if (ct->Class == TEXT)
ct = AssociatedControl(db, ct->command);
if (ct->Class == RADIOBUTTON)
SetRadioButton(db, ct);
else if (ct->Class == CHECKBOX) {
ct->setting ^= ON;
SendMessage(ct->wnd, PAINT, 0, 0);
}
else if (ct->Class) {
SendMessage(ct->wnd, SETFOCUS, TRUE, 0);
if (ct->Class == BUTTON)
SendMessage(ct->wnd,KEYBOARD,'\r',0);
}
return TRUE;
}
cp++;
}
ct++;
}
}
return FALSE;
}
/* --- dynamically add or remove scroll bars
from a control window ---- */
void SetScrollBars(WINDOW wnd)
{
int oldattr = GetAttribute(wnd);
if (wnd->wlines > ClientHeight(wnd))
AddAttribute(wnd, VSCROLLBAR);
else
ClearAttribute(wnd, VSCROLLBAR);
if (wnd->textwidth > ClientWidth(wnd))
AddAttribute(wnd, HSCROLLBAR);
else
ClearAttribute(wnd, HSCROLLBAR);
if (GetAttribute(wnd) != oldattr)
SendMessage(wnd, BORDER, 0, 0);
}
/* ------- CREATE_WINDOW Message (Control) ----- */
static void CtlCreateWindowMsg(WINDOW wnd)
{
CTLWINDOW *ct;
ct = wnd->ct = wnd->extension;
wnd->extension = NULL;
if (ct != NULL)
ct->wnd = wnd;
}
/* ------- KEYBOARD Message (Control) ----- */
static BOOL CtlKeyboardMsg(WINDOW wnd, PARAM p1, PARAM p2)
{
CTLWINDOW *ct = GetControl(wnd);
switch ((int) p1) {
case F1:
if (WindowMoving || WindowSizing)
break;
if (!DisplayHelp(wnd, ct->help))
SendMessage(GetParent(wnd),COMMAND,ID_HELP,0);
return TRUE;
case ' ':
if (!((int)p2 & ALTKEY))
break;
case ALT_F6:
case CTRL_F4:
case ALT_F4:
PostMessage(GetParent(wnd), KEYBOARD, p1, p2);
return TRUE;
default:
break;
}
if (GetClass(wnd) == EDITBOX)
if (isMultiLine(wnd))
return FALSE;
if (GetClass(wnd) == TEXTBOX)
if (WindowHeight(wnd) > 1)
return FALSE;
switch ((int) p1) {
case LARROW:
case DN:
if (!isDerivedFrom(wnd, LISTBOX) && !isDerivedFrom(wnd, COMBOBOX))
p1 = '\t';
if (isDerivedFrom(wnd, BUTTON))
break;
break;
case FWD:
if (!isDerivedFrom(wnd, EDITBOX))
p1 = '\t';
break;
case '\r':
if (isDerivedFrom(wnd, EDITBOX))
if (isMultiLine(wnd))
break;
if (isDerivedFrom(wnd, BUTTON))
break;
if (isDerivedFrom(wnd, LISTBOX))
break;
SendMessage(GetParent(wnd), COMMAND, ID_OK, 0);
return TRUE;
default:
break;
}
return FALSE;
}
/* ------- CLOSE_WINDOW Message (Control) ----- */
static void CtlCloseWindowMsg(WINDOW wnd)
{
CTLWINDOW *ct = GetControl(wnd);
if (ct != NULL) {
ct->wnd = NULL;
if (GetParent(wnd)->ReturnCode == ID_OK) {
if (ct->Class == EDITBOX || ct->Class == COMBOBOX) {
ct->itext=DFrealloc(ct->itext,strlen(wnd->text)+1);
strcpy(ct->itext, wnd->text);
if (!isMultiLine(wnd)) {
char *cp = ct->itext+strlen(ct->itext)-1;
if (*cp == '\n')
*cp = '\0';
}
}
else if (ct->Class == RADIOBUTTON || ct->Class == CHECKBOX)
ct->isetting = ct->setting;
}
}
}
static void FixColors(WINDOW wnd)
{
CTLWINDOW *ct = wnd->ct;
if (ct->Class != BUTTON) {
if (ct->Class != SPINBUTTON && ct->Class != COMBOBOX) {
if (ct->Class != EDITBOX && ct->Class != LISTBOX) {
wnd->WindowColors[FRAME_COLOR][FG] =
GetParent(wnd)->WindowColors[FRAME_COLOR][FG];
wnd->WindowColors[FRAME_COLOR][BG] =
GetParent(wnd)->WindowColors[FRAME_COLOR][BG];
wnd->WindowColors[STD_COLOR][FG] =
GetParent(wnd)->WindowColors[STD_COLOR][FG];
wnd->WindowColors[STD_COLOR][BG] =
GetParent(wnd)->WindowColors[STD_COLOR][BG];
}
}
}
}
/* -- generic window processor used by dialog box controls -- */
static int ControlProc(WINDOW wnd,MESSAGE msg,PARAM p1,PARAM p2)
{
DBOX *db;
if (wnd == NULL)
return FALSE;
db = GetParent(wnd) ? GetParent(wnd)->extension : NULL;
switch (msg) {
case CREATE_WINDOW:
CtlCreateWindowMsg(wnd);
break;
case KEYBOARD:
if (CtlKeyboardMsg(wnd, p1, p2))
return TRUE;
break;
case PAINT:
FixColors(wnd);
if (GetClass(wnd) == EDITBOX ||
GetClass(wnd) == LISTBOX ||
GetClass(wnd) == TEXTBOX)
SetScrollBars(wnd);
break;
case BORDER:
FixColors(wnd);
if (GetClass(wnd) == EDITBOX) {
WINDOW oldFocus = inFocus;
inFocus = NULL;
DefaultWndProc(wnd, msg, p1, p2);
inFocus = oldFocus;
return TRUE;
}
break;
case SETFOCUS: {
WINDOW pwnd = GetParent(wnd);
if (p1) {
WINDOW oldFocus = inFocus;
if (pwnd && GetClass(oldFocus) != APPLICATION &&
!isAncestor(inFocus, pwnd)) {
inFocus = NULL;
SendMessage(oldFocus, BORDER, 0, 0);
SendMessage(pwnd, SHOW_WINDOW, 0, 0);
inFocus = oldFocus;
ClearVisible(oldFocus);
}
if (GetClass(oldFocus) == APPLICATION &&
NextWindow(pwnd) != NULL)
pwnd->wasCleared = FALSE;
DefaultWndProc(wnd, msg, p1, p2);
SetVisible(oldFocus);
if (pwnd != NULL) {
pwnd->dfocus = wnd;
SendMessage(pwnd, COMMAND,
inFocusCommand(db), ENTERFOCUS);
}
return TRUE;
}
else
SendMessage(pwnd, COMMAND,
inFocusCommand(db), LEAVEFOCUS);
break;
}
case CLOSE_WINDOW:
CtlCloseWindowMsg(wnd);
break;
default:
break;
}
return DefaultWndProc(wnd, msg, p1, p2);
}
/* ---- change the focus to the first control --- */
static void FirstFocus(DBOX *db)
{
CTLWINDOW *ct = db->ctl;
if (ct != NULL) {
while (ct->Class == TEXT || ct->Class == BOX) {
ct++;
if (ct->Class == 0)
return;
}
SendMessage(ct->wnd, SETFOCUS, TRUE, 0);
}
}
/* ---- change the focus to the next control --- */
static void NextFocus(DBOX *db)
{
CTLWINDOW *ct = WindowControl(db, inFocus);
int looped = 0;
if (ct != NULL) {
do {
ct++;
if (ct->Class == 0) {
if (looped)
return;
looped++;
ct = db->ctl;
}
} while (ct->Class == TEXT || ct->Class == BOX);
SendMessage(ct->wnd, SETFOCUS, TRUE, 0);
}
}
/* ---- change the focus to the previous control --- */
static void PrevFocus(DBOX *db)
{
CTLWINDOW *ct = WindowControl(db, inFocus);
int looped = 0;
if (ct != NULL) {
do {
if (ct == db->ctl) {
if (looped)
return;
looped++;
while (ct->Class)
ct++;
}
--ct;
} while (ct->Class == TEXT || ct->Class == BOX);
SendMessage(ct->wnd, SETFOCUS, TRUE, 0);
}
}
void SetFocusCursor(WINDOW wnd)
{
if (wnd == inFocus) {
SendMessage(NULL, SHOW_CURSOR, 0, 0);
SendMessage(wnd, KEYBOARD_CURSOR, 1, 0);
}
}

View File

@@ -0,0 +1,55 @@
/* ----------------- dialbox.h ---------------- */
#ifndef DIALOG_H
#define DIALOG_H
#include <stdio.h>
#define MAXCONTROLS 30
#define MAXRADIOS 20
#define OFF FALSE
#define ON TRUE
/* -------- dialog box and control window structure ------- */
typedef struct {
char *title; /* window title */
int x, y; /* relative coordinates */
int h, w; /* size */
} DIALOGWINDOW;
/* ------ one of these for each control window ------- */
typedef struct {
DIALOGWINDOW dwnd;
CLASS Class; /* LISTBOX, BUTTON, etc */
char *itext; /* initialized text */
int command; /* command code */
char *help; /* help mnemonic */
BOOL isetting; /* initially ON or OFF */
BOOL setting; /* ON or OFF */
void *wnd; /* window handle */
} CTLWINDOW;
/* --------- one of these for each dialog box ------- */
typedef struct {
char *HelpName;
DIALOGWINDOW dwnd;
CTLWINDOW ctl[MAXCONTROLS+1];
} DBOX;
/* -------- macros for dialog box resource compile -------- */
#define DIALOGBOX(db) DBOX db={ #db,
#define DB_TITLE(ttl,x,y,h,w) {ttl,x,y,h,w},{
#define CONTROL(ty,tx,x,y,h,w,c) \
{{NULL,x,y,h,w},ty, \
(ty==EDITBOX||ty==COMBOBOX?NULL:tx), \
c,#c,(ty==BUTTON?ON:OFF),OFF,NULL},
#define ENDDB {{NULL}} }};
#define Cancel " Cancel "
#define Ok " OK "
#define Yes " Yes "
#define No " No "
#endif

View File

@@ -0,0 +1,198 @@
/* Edit's Dialogs
Part of FreeDOS Edit
*/
#include "dflat.h"
/* --- The File/Open Dialog Box */
DIALOGBOX(FileOpen)
DB_TITLE("Open File", -1,-1,19,57)
CONTROL(TEXT, "File ~Name:", 3, 1, 1,10, ID_FILENAME)
CONTROL(EDITBOX, NULL, 14, 1, 1,40, ID_FILENAME)
CONTROL(TEXT, NULL, 3, 3, 1,50, ID_PATH)
CONTROL(TEXT, "~Files:", 3, 5, 1, 6, ID_FILES)
CONTROL(LISTBOX, NULL, 3, 6,10,14, ID_FILES)
CONTROL(TEXT, "~Directories:",19, 5, 1,12, ID_DIRECTORY)
CONTROL(LISTBOX, NULL, 19, 6,10,13, ID_DIRECTORY)
CONTROL(TEXT, "Dri~ves:", 34, 5, 1, 7, ID_DRIVE)
CONTROL(LISTBOX, NULL, 34, 6,10,10, ID_DRIVE)
CONTROL(BUTTON, " ~OK ", 46, 5, 1, 8, ID_OK)
CONTROL(BUTTON, " ~Cancel ", 46, 8, 1, 8, ID_CANCEL)
CONTROL(BUTTON, " ~Help ", 46,11, 1, 8, ID_HELP)
CONTROL(TEXT, "~Read", 50,13, 1, 5, ID_READONLY)
CONTROL(TEXT, "Only", 50,14, 1, 5, ID_READONLY)
CONTROL(CHECKBOX, NULL, 46,13, 1, 3, ID_READONLY)
ENDDB
/* --- The Save As Dialog Box --- */
DIALOGBOX(SaveAs)
DB_TITLE("Save As", -1,-1,19,57)
CONTROL(TEXT, "File ~Name:", 3, 1, 1, 9, ID_FILENAME)
CONTROL(EDITBOX, NULL, 13, 1, 1,40, ID_FILENAME)
CONTROL(TEXT, NULL, 3, 3, 1,50, ID_PATH)
CONTROL(TEXT, "~Files:", 3, 5, 1, 6, ID_FILES)
CONTROL(LISTBOX, NULL, 3, 6,10,14, ID_FILES)
CONTROL(TEXT, "~Directories:",19, 5, 1,12, ID_DIRECTORY)
CONTROL(LISTBOX, NULL, 19, 6,10,13, ID_DIRECTORY)
CONTROL(TEXT, "Dri~ves:", 34, 5, 1, 7, ID_DRIVE)
CONTROL(LISTBOX, NULL, 34, 6,10,10, ID_DRIVE)
CONTROL(BUTTON, " ~OK ", 46, 7, 1, 8, ID_OK)
CONTROL(BUTTON, " ~Cancel ", 46,10, 1, 8, ID_CANCEL)
CONTROL(BUTTON, " ~Help ", 46,13, 1, 8, ID_HELP)
ENDDB
/* --- The Printer Setup Dialog Box --- */
DIALOGBOX(PrintSetup)
DB_TITLE("Print Setup", -1, -1, 17, 32)
CONTROL(BOX, "Margins", 2, 3, 9, 26, 0)
CONTROL(TEXT, "~Port:", 4, 1, 1, 5, ID_PRINTERPORT)
CONTROL(COMBOBOX, NULL, 12, 1, 8, 9, ID_PRINTERPORT)
CONTROL(TEXT, "~Left:", 6, 4, 1, 5, ID_LEFTMARGIN)
CONTROL(SPINBUTTON, NULL, 17, 4, 1, 6, ID_LEFTMARGIN)
CONTROL(TEXT, "~Right:", 6, 6, 1, 6, ID_RIGHTMARGIN)
CONTROL(SPINBUTTON, NULL, 17, 6, 1, 6, ID_RIGHTMARGIN)
CONTROL(TEXT, "~Top:", 6, 8, 1, 4, ID_TOPMARGIN)
CONTROL(SPINBUTTON, NULL, 17, 8, 1, 6, ID_TOPMARGIN)
CONTROL(TEXT, "~Bottom:", 6, 10, 1, 7, ID_BOTTOMMARGIN)
CONTROL(SPINBUTTON, NULL, 17, 10, 1, 6, ID_BOTTOMMARGIN)
CONTROL(BUTTON, " ~OK ", 1, 13, 1, 8, ID_OK)
CONTROL(BUTTON, " ~Cancel ", 11, 13, 1, 8, ID_CANCEL)
CONTROL(BUTTON, " ~Help ", 21, 13, 1, 8, ID_HELP)
ENDDB
/* --- The Search Text Dialog Box --- */
DIALOGBOX(SearchTextDB)
DB_TITLE("Find",-1,-1,9,48)
CONTROL(TEXT, "~Find What:", 2, 1, 1, 11, ID_SEARCHFOR)
CONTROL(EDITBOX, NULL, 14, 1, 1, 29, ID_SEARCHFOR)
CONTROL(TEXT, "Match ~Case:" , 2, 3, 1, 23, ID_MATCHCASE)
CONTROL(CHECKBOX, NULL, 26, 3, 1, 3, ID_MATCHCASE)
CONTROL(BUTTON, " ~OK ", 7, 5, 1, 8, ID_OK)
CONTROL(BUTTON, " ~Cancel ", 19, 5, 1, 8, ID_CANCEL)
CONTROL(BUTTON, " ~Help ", 31, 5, 1, 8, ID_HELP)
ENDDB
/* --- The Replace Text dialog box --- */
DIALOGBOX(ReplaceTextDB)
DB_TITLE("Replace",-1,-1,12,50)
CONTROL(TEXT, "~Search for:", 2, 1, 1, 11, ID_SEARCHFOR)
CONTROL(EDITBOX, NULL, 16, 1, 1, 29, ID_SEARCHFOR)
CONTROL(TEXT, "~Replace with:", 2, 3, 1, 13, ID_REPLACEWITH)
CONTROL(EDITBOX, NULL, 16, 3, 1, 29, ID_REPLACEWITH)
CONTROL(TEXT, "Match ~Case:", 2, 5, 1, 23, ID_MATCHCASE)
CONTROL(CHECKBOX, NULL, 26, 5, 1, 3, ID_MATCHCASE)
CONTROL(TEXT, "Replace ~All:", 2, 6, 1, 23, ID_REPLACEALL)
CONTROL(CHECKBOX, NULL, 26, 6, 1, 3, ID_REPLACEALL)
CONTROL(BUTTON, " ~OK ", 7, 8, 1, 8, ID_OK)
CONTROL(BUTTON, " ~Cancel ", 20, 8, 1, 8, ID_CANCEL)
CONTROL(BUTTON, " ~Help ", 33, 8, 1, 8, ID_HELP)
ENDDB
/* --- Generic message dialog box --- */
DIALOGBOX(MsgBox)
DB_TITLE(NULL,-1,-1, 0, 0)
CONTROL(TEXT, NULL, 1, 1, 0, 0, 0)
CONTROL(BUTTON, NULL, 0, 0, 1, 8, ID_OK)
CONTROL(0, NULL, 0, 0, 1, 8, ID_CANCEL)
CONTROL(0, NULL, 0, 0, 1, 8, ID_THREE)
ENDDB
/* ----------- InputBox Dialog Box ------------ */
DIALOGBOX(InputBoxDB)
DB_TITLE(NULL,-1,-1, 9, 0)
CONTROL(TEXT, NULL, 1, 1, 1, 0, 0)
CONTROL(EDITBOX, NULL, 1, 3, 1, 0, ID_INPUTTEXT)
CONTROL(BUTTON, " ~OK ", 0, 5, 1, 8, ID_OK)
CONTROL(BUTTON, " ~Cancel ", 0, 5, 1, 8, ID_CANCEL)
ENDDB
/* ----------- SliderBox Dialog Box ------------- */
DIALOGBOX(SliderBoxDB)
DB_TITLE(NULL,-1,-1, 9, 0)
CONTROL(TEXT, NULL, 0, 1, 1, 0, 0)
CONTROL(TEXT, NULL, 0, 3, 1, 0, 0)
CONTROL(BUTTON, " Cancel ", 0, 5, 1, 8, ID_CANCEL)
ENDDB
#ifdef INCLUDE_WINDOWOPTIONS
#define offset 7
#else
#define offset 0
#endif
/* ------------ Options dialog box -------------- */
DIALOGBOX(Display)
DB_TITLE("Display", -1, -1, 12+offset, 35)
#ifdef INCLUDE_WINDOWOPTIONS
CONTROL(BOX, "Window", 7, 1, 6,20, 0)
CONTROL(CHECKBOX, NULL, 9, 2, 1, 3, ID_TITLE)
CONTROL(TEXT, "~Title", 15, 2, 1, 5, ID_TITLE)
CONTROL(CHECKBOX, NULL, 9, 3, 1, 3, ID_BORDER)
CONTROL(TEXT, "~Border", 15, 3, 1, 6, ID_BORDER)
CONTROL(CHECKBOX, NULL, 9, 4, 1, 3, ID_STATUSBAR)
CONTROL(TEXT, "~Status bar",15, 4, 1,10, ID_STATUSBAR)
CONTROL(CHECKBOX, NULL, 9, 5, 1, 3, ID_TEXTURE)
CONTROL(TEXT, "Te~xture", 15, 5, 1, 7, ID_TEXTURE)
#endif
CONTROL(BOX, "Colors", 1, 1+offset,5,15, 0)
CONTROL(RADIOBUTTON, NULL, 3, 2+offset,1,3,ID_COLOR)
CONTROL(TEXT, "Co~lor", 7, 2+offset,1,5,ID_COLOR)
CONTROL(RADIOBUTTON, NULL, 3, 3+offset,1,3,ID_MONO)
CONTROL(TEXT, "~Mono", 7, 3+offset,1,4,ID_MONO)
CONTROL(RADIOBUTTON, NULL, 3, 4+offset,1,3,ID_REVERSE)
CONTROL(TEXT, "~Reverse", 7, 4+offset,1,7,ID_REVERSE)
CONTROL(BOX, "Lines", 17, 1+offset,5,15, 0)
CONTROL(RADIOBUTTON, NULL, 19, 2+offset,1,3,ID_25LINES)
CONTROL(TEXT, "~25", 23, 2+offset,1,2,ID_25LINES)
CONTROL(RADIOBUTTON, NULL, 19, 3+offset,1,3,ID_43LINES)
CONTROL(TEXT, "~43", 23, 3+offset,1,2,ID_43LINES)
CONTROL(RADIOBUTTON, NULL, 19, 4+offset,1,3,ID_50LINES)
CONTROL(TEXT, "~50", 23, 4+offset,1,2,ID_50LINES)
/*
CONTROL(CHECKBOX, NULL, 11, 6+offset,1,3,ID_SNOWY)
CONTROL(TEXT, "S~nowy", 15, 6+offset,1,7,ID_SNOWY)
*/
CONTROL(CHECKBOX, NULL, 1, 6+offset, 1, 3,ID_LOADBLANK)
CONTROL(TEXT, "Open ~new window on load", 5, 6+offset, 1,23,ID_LOADBLANK)
CONTROL(BUTTON, " ~OK ", 2, 8+offset,1,8,ID_OK)
CONTROL(BUTTON, " ~Cancel ", 12, 8+offset,1,8,ID_CANCEL)
CONTROL(BUTTON, " ~Help ", 22, 8+offset,1,8,ID_HELP)
ENDDB
/* ------------ Windows dialog box -------------- */
DIALOGBOX(Windows)
DB_TITLE("Windows", -1, -1, 19, 24)
CONTROL(LISTBOX, NULL, 1, 1,11,20, ID_WINDOWLIST)
CONTROL(BUTTON, " ~OK ", 2, 13, 1, 8, ID_OK)
CONTROL(BUTTON, " ~Cancel ", 12, 13, 1, 8, ID_CANCEL)
CONTROL(BUTTON, " ~Help ", 7, 15, 1, 8, ID_HELP)
ENDDB
#ifdef INCLUDE_LOGGING
/* ------------ Message Log dialog box -------------- */
DIALOGBOX(Log)
DB_TITLE("Edit Message Log", -1, -1, 18, 41)
CONTROL(TEXT, "~Messages", 10, 1, 1, 8, ID_LOGLIST)
CONTROL(LISTBOX, NULL, 1, 2, 14, 26, ID_LOGLIST)
CONTROL(TEXT, "~Logging:", 29, 4, 1, 10, ID_LOGGING)
CONTROL(CHECKBOX, NULL, 31, 5, 1, 3, ID_LOGGING)
CONTROL(BUTTON, " ~OK ", 29, 7, 1, 8, ID_OK)
CONTROL(BUTTON, " ~Cancel ", 29, 10, 1, 8, ID_CANCEL)
CONTROL(BUTTON, " ~Help ", 29, 13, 1, 8, ID_HELP)
ENDDB
#endif
/* ------------ the Help window dialog box -------------- */
DIALOGBOX(HelpBox)
DB_TITLE(NULL, -1, -1, 0, 45)
CONTROL(TEXTBOX, NULL, 1, 1, 0, 40, ID_HELPTEXT)
CONTROL(BUTTON, " ~Close ", 0, 0, 1, 8, ID_CANCEL)
CONTROL(BUTTON, " ~Back ", 10, 0, 1, 8, ID_BACK)
CONTROL(BUTTON, "<< ~Prev ", 20, 0, 1, 8, ID_PREV)
CONTROL(BUTTON, " ~Next >>", 30, 0, 1, 8, ID_NEXT)
ENDDB

View File

@@ -0,0 +1,233 @@
#include <windows.h>
#include <io.h>
#include <stdlib.h>
#include <direct.h>
#include <ctype.h>
#include <string.h>
#include "dir_w32.h"
int findfirst(const char *_pathname, struct ffblk *_ffblk, int _attrib)
{
struct _finddata_t c_file;
int hFile;
unsigned int wmask = 0;
if (_attrib & FA_RDONLY) wmask |= _A_RDONLY;
if (_attrib & FA_HIDDEN) wmask |= _A_HIDDEN;
if (_attrib & FA_SYSTEM) wmask |= _A_SYSTEM;
if (_attrib & FA_LABEL) wmask |= 0; /* not available */
if (_attrib & FA_DIREC) wmask |= _A_SUBDIR;
if (_attrib & FA_ARCH) wmask |= _A_ARCH;
if( (hFile = _findfirst(_pathname, &c_file )) == -1L )
return 1;
while (((c_file.attrib & wmask) != wmask && wmask != 0) ||
((c_file.attrib & (FA_RDONLY|FA_HIDDEN|FA_ARCH)) == 0 && wmask == 0)) {
if (_findnext( hFile, &c_file ) != 0) {
_findclose(hFile);
return 1;
}
}
_ffblk->__wmask = wmask;
_ffblk->__hFile = hFile;
strcpy(_ffblk->ff_name, c_file.name);
_ffblk->ff_fsize = c_file.size;
wmask = 0;
if (c_file.attrib & _A_RDONLY) wmask |= FA_RDONLY;
if (c_file.attrib & _A_HIDDEN) wmask |= FA_HIDDEN;
if (c_file.attrib & _A_SYSTEM) wmask |= FA_SYSTEM;
if (c_file.attrib & _A_SUBDIR) wmask |= FA_DIREC;
if (c_file.attrib & _A_ARCH) wmask |= FA_ARCH;
_ffblk->ff_attrib = wmask;
return 0;
}
int findnext(struct ffblk *_ffblk)
{
struct _finddata_t c_file;
int hFile = _ffblk->__hFile;
unsigned int wmask = _ffblk->__wmask;
do {
if (_findnext( hFile, &c_file ) != 0) {
_findclose(hFile);
return 1;
}
} while (((c_file.attrib & wmask) != wmask && wmask != 0) ||
((c_file.attrib & (FA_RDONLY|FA_HIDDEN|FA_ARCH)) == 0 && wmask == 0));
strcpy(_ffblk->ff_name, c_file.name);
_ffblk->ff_fsize = c_file.size;
wmask = 0;
if (c_file.attrib & _A_RDONLY) wmask |= FA_RDONLY;
if (c_file.attrib & _A_HIDDEN) wmask |= FA_HIDDEN;
if (c_file.attrib & _A_SYSTEM) wmask |= FA_SYSTEM;
if (c_file.attrib & _A_SUBDIR) wmask |= FA_DIREC;
if (c_file.attrib & _A_ARCH) wmask |= FA_ARCH;
_ffblk->ff_attrib = wmask;
return 0;
}
int getdisk(void)
{
return _getdrive()-1;
}
int setdisk(int curdrive)
{
DWORD drives;
int maxdrive;
/* If we can switch to the drive, it exists. */
drives = GetLogicalDrives();
for (maxdrive=31; maxdrive>=0; maxdrive--) {
if (drives & (1<<maxdrive))
break;
}
if (drives & (1<<curdrive))
_chdrive(curdrive+1);
return maxdrive;
}
int w32_getdisks(void)
{
return GetLogicalDrives();
}
/* taken from DJGPP library source code */
static char *
max_ptr(char *p1, char *p2)
{
if (p1 > p2)
return p1;
else
return p2;
}
int
fnsplit (const char *path, char *drive, char *dir,
char *name, char *ext)
{
int flags = 0, len;
const char *pp, *pe;
if (drive)
*drive = '\0';
if (dir)
*dir = '\0';
if (name)
*name = '\0';
if (ext)
*ext = '\0';
pp = path;
if ((isalpha((unsigned char )*pp)
|| strchr("[\\]^_`", *pp)) && (pp[1] == ':'))
{
flags |= DRIVE;
if (drive)
{
strncpy(drive, pp, 2);
drive[2] = '\0';
}
pp += 2;
}
pe = max_ptr(strrchr(pp, '\\'), strrchr(pp, '/'));
if (pe)
{
flags |= DIRECTORY;
pe++;
len = pe - pp;
if (dir)
{
strncpy(dir, pp, len);
dir[len] = '\0';
}
pp = pe;
}
else
pe = pp;
/* Special case: "c:/path/." or "c:/path/.."
These mean FILENAME, not EXTENSION. */
while (*pp == '.')
++pp;
if (pp > pe)
{
flags |= FILENAME;
if (name)
{
len = pp - pe;
strncpy(name, pe, len);
name[len] = '\0';
/* advance name over '.'s so they don't get scragged later on when the
* rest of the name (if any) is copied (for files like .emacs). - WJC
*/
name+=len;
}
}
pe = strrchr(pp, '.');
if (pe)
{
flags |= EXTENSION;
if (ext)
strcpy(ext, pe);
}
else
pe = strchr( pp, '\0');
if (pp != pe)
{
flags |= FILENAME;
len = pe - pp;
if (name)
{
strncpy(name, pp, len);
name[len] = '\0';
}
}
if (strcspn(path, "*?[") < strlen(path))
flags |= WILDCARDS;
return flags;
}
void
fnmerge (char *path, const char *drive, const char *dir,
const char *name, const char *ext)
{
*path = '\0';
if (drive && *drive)
{
path[0] = drive[0];
path[1] = ':';
path[2] = 0;
}
if (dir && *dir)
{
char last_dir_char = dir[strlen(dir) - 1];
strcat(path, dir);
if (last_dir_char != '/' && last_dir_char != '\\')
strcat(path, strchr(dir, '\\') ? "\\" : "/");
}
if (name)
strcat(path, name);
if (ext && *ext)
{
if (*ext != '.')
strcat(path, ".");
strcat(path, ext);
}
}

View File

@@ -0,0 +1,49 @@
#ifndef __dir_w32_h__
#define __dir_w32_h__
struct ffblk {
char lfn_magic[6];
short lfn_handle;
unsigned short lfn_ctime;
unsigned short lfn_cdate;
unsigned short lfn_atime;
unsigned short lfn_adate;
char _ff_reserved[5];
unsigned char ff_attrib;
unsigned short ff_ftime;
unsigned short ff_fdate;
unsigned long ff_fsize;
char ff_name[260];
/* Win32 private date */
int __hFile;
unsigned int __wmask;
};
#define FA_RDONLY 1
#define FA_HIDDEN 2
#define FA_SYSTEM 4
#define FA_LABEL 8
#define FA_DIREC 16
#define FA_ARCH 32
/* for fnmerge/fnsplit */
#define MAXPATH 260
#define MAXDRIVE 3
#define MAXDIR 256
#define MAXFILE 256
#define MAXEXT 255
#define WILDCARDS 0x01
#define EXTENSION 0x02
#define FILENAME 0x04
#define DIRECTORY 0x08
#define DRIVE 0x10
int findfirst(const char *_pathname, struct ffblk *_ffblk, int _attrib);
int findnext(struct ffblk *_ffblk);
void fnmerge (char *_path, const char *_drive, const char *_dir, const char *_name, const char *_ext);
int fnsplit (const char *_path, char *_drive, char *_dir, char *_name, char *_ext);
int getdisk(void);
int setdisk(int _drive);
#endif

View File

@@ -0,0 +1,262 @@
/* ---------- direct.c --------- */
#include "dflat.h"
#ifndef FA_DIREC
#define FA_DIREC 0x10
#endif
static char path[MAXPATH];
static char drive[MAXDRIVE] = " :";
static char dir[MAXDIR];
static char name[MAXFILE];
static char ext[MAXEXT];
/* ----- Create unambiguous path from file spec, filling in the
drive and directory if incomplete. Optionally change to
the new drive and subdirectory ------ */
void CreatePath(char *spath,char *fspec,int InclName,int Change)
{
int cm = 0;
unsigned currdrive;
char currdir[MAXPATH+1],*cp;
currdrive = getdisk();
if (!Change)
{
/* ---- save the current drive and subdirectory ---- */
getcwd(currdir, sizeof currdir);
memmove(currdir, currdir+2, strlen(currdir+1));
cp = currdir+strlen(currdir)-1;
if ((*cp == '\\') && (strlen(dir) > 1)) /* save "\\" - Eric */
*cp = '\0';
}
*drive = *dir = *name = *ext = '\0';
fnsplit(fspec, drive, dir, name, ext);
if (!InclName)
*name = *ext = '\0';
*drive = toupper(*drive);
if (*ext)
cm |= EXTENSION;
if (InclName && *name)
cm |= FILENAME;
if (*dir)
cm |= DIRECTORY;
if (*drive)
cm |= DRIVE;
if (cm & DRIVE)
setdisk(*drive - 'A');
else
{
*drive = getdisk();
*drive += 'A';
}
if (cm & DIRECTORY)
{
cp = dir+strlen(dir)-1;
if ((*cp == '\\') && (strlen(dir) > 1)) /* save "\\" - Eric */
*cp = '\0';
chdir(dir);
}
getcwd(dir, sizeof dir);
memmove(dir, dir+2, strlen(dir+1));
if (InclName)
{
if (!(cm & FILENAME))
strcpy(name, "*");
if (!(cm & EXTENSION) && strchr(fspec, '.') != NULL)
strcpy(ext, ".*");
}
else
*name = *ext = '\0';
if (dir[strlen(dir)-1] != '\\')
strcat(dir, "\\");
if (spath != NULL)
fnmerge(spath, drive, dir, name, ext);
if (!Change)
{
setdisk(currdrive);
chdir(currdir);
}
}
static int dircmp(const void *c1, const void *c2)
{
return stricmp(*(char **)c1, *(char **)c2);
}
static BOOL BuildList(WINDOW wnd, char *fspec, BOOL dirs)
{
int ax, i = 0, criterr = 1;
struct ffblk ff;
CTLWINDOW *ct = FindCommand(wnd->extension, dirs ? ID_DIRECTORY : ID_FILES,LISTBOX);
WINDOW lwnd;
char **dirlist = NULL;
if (ct != NULL)
{
lwnd = ct->wnd;
SendMessage(lwnd, CLEARTEXT, 0, 0);
while (criterr == 1)
{
ax = findfirst(fspec, &ff, dirs ? FA_DIREC : 0);
criterr = TestCriticalError();
}
if (criterr)
return FALSE;
while (ax == 0)
{
if (!dirs || ((ff.ff_attrib & FA_DIREC) && strcmp(ff.ff_name, ".")))
{
dirlist = DFrealloc(dirlist, sizeof(char *)*(i+1));
dirlist[i] = DFmalloc(strlen(ff.ff_name)+1);
strcpy(dirlist[i++], ff.ff_name);
}
ax = findnext(&ff);
}
if (dirlist != NULL)
{
int j;
/* -- sort file or directory list box data -- */
qsort(dirlist, i, sizeof(void *), dircmp);
/* ---- send sorted list to list box ---- */
for (j=0;j<i;j++)
{
SendMessage(lwnd,ADDTEXT,(PARAM)dirlist[j],0);
free(dirlist[j]);
}
free(dirlist);
}
SendMessage(lwnd, SHOW_WINDOW, 0, 0);
}
return TRUE;
}
BOOL BuildFileList(WINDOW wnd, char *fspec)
{
return BuildList(wnd, fspec, FALSE);
}
void BuildDirectoryList(WINDOW wnd)
{
BuildList(wnd, "*.*", TRUE);
}
void BuildDriveList(WINDOW wnd)
{
CTLWINDOW *ct = FindCommand(wnd->extension, ID_DRIVE,LISTBOX);
if (ct != NULL)
{
#ifndef _WIN32
union REGS regs;
#endif
char drname[15];
unsigned int cd, dr;
WINDOW lwnd = ct->wnd;
SendMessage(lwnd, CLEARTEXT, 0, 0);
#ifndef _WIN32
cd = getdisk();
for (dr=0;dr<26;dr++)
{
unsigned ndr;
setdisk(dr);
ndr = getdisk();
if (ndr == dr)
{
/* Test for remapped B drive */
if (dr == 1)
{
regs.x.ax = 0x440e; /* IOCTL func 14 */
regs.h.bl = dr+1;
int86(DOS, &regs, &regs);
if (regs.h.al != 0)
continue;
}
sprintf(drname, "[-%c-]", dr+'A');
/* Test for network or RAM disk */
/*
-- Commented out for now...don't really like or need this
as of right now -- Joe
regs.x.ax = 0x4409; // IOCTL func 9
regs.h.bl = dr+1;
int86(DOS, &regs, &regs);
if (!regs.x.cflag)
{
if (regs.x.dx & 0x1000)
{
drname[0]='<';
drname[4]='>';
};
}
*/
SendMessage(lwnd,ADDTEXT,(PARAM)drname,0);
}
}
SendMessage(lwnd, SHOW_WINDOW, 0, 0);
setdisk(cd);
#else
cd = w32_getdisks();
for (dr = 0; dr < 26; dr++) {
if (cd & (1<<dr)) {
sprintf(drname, "[-%c-]", dr+'A');
SendMessage(lwnd,ADDTEXT,(PARAM)drname,0);
}
}
SendMessage(lwnd, SHOW_WINDOW, 0, 0);
#endif
}
}
void BuildPathDisplay(WINDOW wnd)
{
CTLWINDOW *ct = FindCommand(wnd->extension, ID_PATH,TEXT);
if (ct != NULL)
{
int len;
WINDOW lwnd = ct->wnd;
CreatePath(path, "*.*", FALSE, FALSE);
len = strlen(path);
if (len > 3)
path[len-1] = '\0';
SendMessage(lwnd,SETTEXT,(PARAM)path,0);
SendMessage(lwnd, PAINT, 0, 0);
}
}

View File

@@ -0,0 +1,931 @@
/* FreeDOS Editor
Some portions copyright (c) Joe Cosentino 2000-2004.
Modified by Eric Auer 2002.
*/
/* I N C L U D E S /////////////////////////////////////////////////////// */
#include "dflat.h"
/* D E F I N E S ///////////////////////////////////////////////////////// */
#define CHARSLINE 80
#define LINESPAGE 66
/* G L O B A L S ///////////////////////////////////////////////////////// */
extern DBOX PrintSetup;
char DFlatApplication[] = "Edit";
static char Untitled[] = "Untitled";
static int wndpos, LineCtr, CharCtr;
static char *ports[] = {
"Lpt1", "Lpt2", "Lpt3",
"Com1", "Com2", "Com3", "Com4",
NULL
};
/* P R O T O T Y P E S /////////////////////////////////////////////////// */
int classify_args(int, char *[], char *[], char *[]);
static int MemoPadProc(WINDOW, MESSAGE, PARAM, PARAM);
static void NewFile(WINDOW,char *);
static void SelectFile(WINDOW);
static void PadWindow(WINDOW, char *);
static void OpenPadWindow(WINDOW, char *,char *);
static void LoadFile(WINDOW);
static void PrintPad(WINDOW);
static void SaveFile(WINDOW, int);
static int EditorProc(WINDOW, MESSAGE, PARAM, PARAM);
static char *NameComponent(char *);
static int PrintSetupProc(WINDOW, MESSAGE, PARAM, PARAM);
static void FixTabMenu(void);
/* F U N C T I O N S ///////////////////////////////////////////////////// */
int classify_args(int argc, char *rawargs[], char *fileargs[], char *optargs[])
{
int index, jndex, kndex;
char *argptr;
/* skip index=0, aka argv[0]==edit.exe */
for (index=1,jndex=0,kndex=0;index<argc;index++)
{
argptr=rawargs[index];
if (*argptr == '/')
{
argptr++;
optargs[kndex++]=argptr;
}
else
{
fileargs[jndex++]=argptr;
}
}
return kndex;
}
int main(int argc, char *argv[])
{
WINDOW wnd;
FILE *fp;
char *fileargs[64], *optargs[64];
int n_options, n_files, index, help_flag=0;
n_options=classify_args(argc, argv, fileargs, optargs);
n_files=argc-n_options-1/*argv[0]*/;
for (index=0;index<n_options;index++)
{
if (optargs[index][0] == '?') help_flag=1;
else if (optargs[index][0] == 'B' || optargs[index][0] == 'b') cfg.mono=1;
else if (optargs[index][0] == 'H' || optargs[index][0] == 'h') cfg.ScreenLines=SCREENHEIGHT;
else if (optargs[index][0] == 'R' || optargs[index][0] == 'r') cfg.read_only=1;
else
{
printf("Invalid parameter - /%s\n", strupr(optargs[index]));
return 1;
}
}
if (help_flag)
{
printf("FreeDOS Editor\tVersion " VERSION ".\n\n"
"Syntax: EDIT [/B] [/R] [/?] [file(s)]\n"
" /B Forces monochrome mode\n"
" /R Opens a file as read only\n"
" /? Displays this help message\n"
" [file] Specifies initial file(s) to load. Wildcards and multiple\n"
" files can be given\n");
return 1;
}
if (!init_messages())
return 1;
init_videomode();
#ifdef ENABLEGLOBALARGV
Argv = argv;
#endif
if (!LoadConfig())
cfg.ScreenLines = SCREENHEIGHT;
fix_mbar(&MainMenu);
wnd = CreateWindow(APPLICATION, "FreeDOS Edit", 0, 0, -1, -1, &MainMenu, NULL, MemoPadProc, MOVEABLE | SIZEABLE | HASBORDER | MINMAXBOX | HASSTATUSBAR);
LoadHelpFile(DFlatApplication);
SendMessage(wnd, SETFOCUS, TRUE, 0);
if (cfg.loadblank)
NewFile(wnd,NULL);
/* Load the files from args - if the file does not exist, open a new
window.... */
for (index=0;index<n_files;index++)
{
/* Check if the file exists... */
/* added by Eric: Do NOT try to open files with names */
/* that contain wildcards, otherwise you may NewFile */
/* files with wildcards in their names. Sigh! 11/2002 */
fp = NULL;
if (((strchr(fileargs[index],'*') == NULL)) && ((strchr(fileargs[index],'?') == NULL)) && ((fp = fopen(fileargs[index],"rt")) == NULL))
{
NewFile(wnd,fileargs[index]);
}
else
{
if (fp != NULL)
fclose(fp); /* don't leave open file handle [from test if exists in above if] */
PadWindow(wnd, fileargs[index]);
}
}
while (dispatch_message())
TRAP_TO_SCHEDULER
;
uninit_videomode();
return 0;
}
/* ------ open text files and put them into editboxes ----- */
static void PadWindow(WINDOW wnd, char *FileName)
{
int ax,criterr=1;
struct ffblk ff;
char path[66],*cp;
CreatePath(path, FileName, FALSE, FALSE);
cp = path+strlen(path);
CreatePath(path, FileName, TRUE, FALSE);
while (criterr == 1)
{
ax = findfirst(path, &ff, 0);
criterr = TestCriticalError();
}
while (ax == 0 && !criterr)
{
strcpy(cp, ff.ff_name);
OpenPadWindow(wnd, path,NULL);
ax = findnext(&ff);
}
}
/* ------- window processing module for the Edit application window ----- */
static int MemoPadProc(WINDOW wnd,MESSAGE msg,PARAM p1,PARAM p2)
{
int rtn;
switch (msg)
{
case CREATE_WINDOW:
rtn = DefaultWndProc(wnd, msg, p1, p2);
if (cfg.InsertMode)
SetCommandToggle(&MainMenu, ID_INSERT);
if (cfg.WordWrap)
SetCommandToggle(&MainMenu, ID_WRAP);
FixTabMenu();
return rtn;
case COMMAND:
switch ((int)p1)
{
case ID_NEW:
NewFile(wnd,NULL);
return TRUE;
case ID_OPEN:
SelectFile(wnd);
return TRUE;
case ID_SAVE:
SaveFile(inFocus, FALSE);
return TRUE;
case ID_SAVEAS:
SaveFile(inFocus, TRUE);
return TRUE;
case ID_CLOSE:
SendMessage(inFocus, CLOSE_WINDOW, 0, 0);
SkipApplicationControls();
return TRUE;
case ID_PRINTSETUP:
DialogBox(wnd, &PrintSetup, TRUE, PrintSetupProc);
return TRUE;
case ID_PRINT:
PrintPad(inFocus);
return TRUE;
case ID_EXIT:
break;
case ID_WRAP:
cfg.WordWrap = GetCommandToggle(&MainMenu, ID_WRAP);
return TRUE;
case ID_INSERT:
cfg.InsertMode = GetCommandToggle(&MainMenu, ID_INSERT);
return TRUE;
case ID_TAB2:
cfg.Tabs = 2;
FixTabMenu();
return TRUE;
case ID_TAB4:
cfg.Tabs = 4;
FixTabMenu();
return TRUE;
case ID_TAB6:
cfg.Tabs = 6;
FixTabMenu();
return TRUE;
case ID_TAB8:
cfg.Tabs = 8;
FixTabMenu();
return TRUE;
#ifndef NOCALENDAR
case ID_CALENDAR:
Calendar(wnd);
return TRUE;
#endif
case ID_ABOUT:
{
char aboutMsg[] =
" FreeDOS Edit \n"
" Version @ \n"
" \n"
" FreeDOS Edit is based on the \n"
" D-Flat application published \n"
" in Dr. Dobb's Journal. \n"
" \n"
" ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ \n"
" \n"
"FreeDOS Edit is a clone of MS-DOS\n"
"editor for the FreeDOS Project \n"
"Released under the GNU GPL License";
if (strchr(aboutMsg,'@') != NULL)
strncpy(strchr(aboutMsg,'@'), VERSION, strlen(VERSION));
MessageBox("About FreeDOS Edit", aboutMsg);
}
return TRUE;
default:
break;
}
break;
default:
break;
}
return DefaultWndProc(wnd, msg, p1, p2);
}
/* The New command. Open an empty editor window */
static void NewFile(WINDOW wnd, char *FileName)
{
OpenPadWindow(wnd, Untitled,FileName);
}
/* --- The Open... command. Select a file --- */
static void SelectFile(WINDOW wnd)
{
char FileName[64];
if (OpenFileDialogBox("*.*", FileName))
{
/* See if the document is already in a window */
WINDOW wnd1 = FirstWindow(wnd);
while (wnd1 != NULL)
{
if (wnd1->extension && stricmp(FileName, wnd1->extension) == 0)
{
SendMessage(wnd1, SETFOCUS, TRUE, 0);
SendMessage(wnd1, RESTORE, 0, 0);
return;
}
wnd1 = NextWindow(wnd1);
}
OpenPadWindow(wnd, FileName,NULL);
}
}
/* --- open a document window and load a file --- */
static void OpenPadWindow(WINDOW wnd, char *FileName,char *NewFileName)
{
static WINDOW wnd1 = NULL;
WINDOW wwnd;
struct stat sb;
char *Fname = FileName;
#if !defined(_WIN32)
char *ermsg;
#endif
if (strcmp(FileName, Untitled))
{
if (stat(FileName, &sb))
{
NewFile(wnd,FileName);
return;
}
Fname = NameComponent(FileName);
/* This limit doesn't exist in protected mode!!! */
#if !defined(_WIN32)
/* check file size */
if (sb.st_size > 64000UL)
{
ermsg = DFmalloc(strlen(FileName)+100);
strcpy(ermsg, "File too large for this version of Edit\n");
ErrorMessage(ermsg);
free(ermsg);
return;
}
#endif
}
wwnd = WatchIcon();
wndpos += 2;
if (NewFileName != NULL)
Fname = NameComponent(NewFileName);
if (wndpos == 20)
wndpos = 2;
wnd1 = CreateWindow(EDITBOX, Fname,
(wndpos-1)*2, wndpos, 10, 40,
NULL, wnd, EditorProc,
SHADOW |
MINMAXBOX |
CONTROLBOX |
VSCROLLBAR |
HSCROLLBAR |
MOVEABLE |
HASBORDER |
SIZEABLE |
MULTILINE);
if (NewFileName != NULL)
{
/* Either a command line new file or one that's on the
disk to load - Either way, must set the extension
to the given filename */
wnd1->extension = DFmalloc(strlen(NewFileName) + 1);
strcpy(wnd1->extension,NewFileName);
}
else
{
if (strcmp(FileName,Untitled) || wnd1->extension == NULL)
wnd1->extension = DFmalloc(strlen(FileName)+1);
strcpy(wnd1->extension, FileName);
LoadFile(wnd1); /* Only load if not a new file */
}
SendMessage(wwnd, CLOSE_WINDOW, 0, 0);
SendMessage(wnd1, SETFOCUS, TRUE, 0);
SendMessage(wnd1, MAXIMIZE, 0, 0);
}
/* --- Load the notepad file into the editor text buffer --- */
static void LoadFile(WINDOW wnd)
{
char *Buf = NULL;
unsigned int recptr = 0;
FILE *fp;
if (!strcmp(wnd->extension, Untitled)) /* Not a real file load */
{
SendMessage(wnd, SETTEXT, (PARAM) "", 0);
return;
}
if ((fp = fopen(wnd->extension, "rt")) != NULL)
{
while (!feof(fp))
{
handshake();
Buf = DFrealloc(Buf, recptr+150);
memset(Buf+recptr, 0, 150);
fgets(Buf+recptr, 150, fp);
recptr += strlen(Buf+recptr);
}
fclose(fp);
if (Buf[strlen(Buf) - 1] != '\n')
{
Buf = DFrealloc(Buf, strlen(Buf)+2);
Buf[strlen(Buf)] = '\n';
Buf[strlen(Buf)] = 0;
}
if (Buf != NULL)
{
SendMessage(wnd, SETTEXT, (PARAM) Buf, 0);
free(Buf);
}
}
else
{
char fMsg[200];
sprintf(fMsg, "Could not load %s", (strlen(wnd->extension)>120) ? "file" : (char *)(wnd->extension));
ErrorMessage(fMsg);
}
}
/* ------- print a character -------- */
static void PrintChar(FILE *prn, int c)
{
int i;
if (c == '\n' || CharCtr == cfg.RightMargin)
{
fputs("\r\n", prn);
LineCtr++;
if (LineCtr == cfg.BottomMargin)
{
fputc('\f', prn);
for (i=0;i<cfg.TopMargin;i++)
fputc('\n', prn);
LineCtr=cfg.TopMargin;
}
CharCtr=0;
if (c == '\n')
return;
}
if (CharCtr == 0)
{
for (i=0;i<cfg.LeftMargin;i++)
{
fputc(' ', prn);
CharCtr++;
}
}
CharCtr++;
fputc(c, prn);
}
/* --- print the current notepad --- */
static void PrintPad(WINDOW wnd)
{
if (*cfg.PrinterPort)
{
FILE *prn;
if ((prn = fopen(cfg.PrinterPort, "wt")) != NULL)
{
unsigned int percent;
BOOL KeepPrinting=TRUE;
unsigned char *text=GetText(wnd);
unsigned int oldpct=100, cct=0, len=strlen(text);
WINDOW swnd=SliderBox(20, GetTitle(wnd), "Printing");
/* Print the notepad text */
LineCtr=CharCtr=0;
while (KeepPrinting && *text)
{
PrintChar(prn, *text++);
percent=((unsigned long) ++cct * 100) / len;
if (percent != oldpct)
{
oldpct=percent;
KeepPrinting=SendMessage(swnd, PAINT, 0, oldpct);
}
}
if (KeepPrinting) /* User did not cancel */
if (oldpct < 100)
SendMessage(swnd, PAINT, 0, 100);
/* Follow with a form feed? */
if (YesNoBox("Form Feed?"))
fputc('\f', prn);
fclose(prn);
}
else
ErrorMessage("Cannot open printer file");
}
else
ErrorMessage("No printer selected");
}
/* ---------- save a file to disk ------------ */
static void SaveFile(WINDOW wnd, int Saveas)
{
FILE *fp;
char FileName[64];
struct ffblk ffblk;
if (wnd->extension == NULL || Saveas)
{
if (SaveAsDialogBox("*.*", NULL, FileName))
{
if (wnd->extension != NULL)
free(wnd->extension);
wnd->extension = DFmalloc(strlen(FileName)+1);
strcpy(wnd->extension, FileName);
SendMessage(wnd, BORDER, 0, 0);
}
else
return;
}
if (wnd->extension != NULL)
{
WINDOW mwnd;
tryagain:
mwnd=MomentaryMessage("Saving...");
if (findfirst(wnd->extension, &ffblk, 0) == 0)
{
char fMsg[200];
sprintf(fMsg,"Replace existing file?");
if (!YesNoBox(fMsg))
{
SendMessage(mwnd, CLOSE_WINDOW, 0, 0);
return;
}
}
if ((fp = fopen(wnd->extension, "wt")) != NULL)
{
size_t howmuch=strlen(GetText(wnd));
howmuch=fwrite(GetText(wnd), howmuch, 1, fp);
fclose(fp);
SendMessage(mwnd, CLOSE_WINDOW, 0, 0);
if (howmuch != 1)
{
ErrorMessage("Not enough room on the disk\n");
return;
}
else
{
wnd->TextChanged = FALSE;
}
}
else
{
char fMsg[200];
SendMessage(mwnd, CLOSE_WINDOW, 0, 0);
sprintf(fMsg," Could not save\n '%s'\n Try again?", (strlen(wnd->extension)>120) ? "file" : strupr(wnd->extension));
if (YesNoBox(fMsg))
goto tryagain;
}
}
}
/* ------ display the row and column in the statusbar ------ */
static void ShowPosition(WINDOW wnd)
{
/* This is where we place the "INS" display */
char status[64], *InsModeText, *ReadOnlyText;
if (wnd->InsertMode)
{
InsModeText = " "; /* Not on */
}
else
{
InsModeText = "INS"; /* Insert is on */
}
if (cfg.read_only)
{
ReadOnlyText = "READ";
}
else
{
ReadOnlyText = " ";
}
if (WindowWidth(wnd) < 50) /* Auto-condense new in 0.8 */
{
sprintf(status, "%c Li:%6d Co:%d", ReadOnlyText[0], wnd->CurrLine, wnd->CurrCol);
}
else
sprintf(status, "%4s %3s Line:%6d Col:%d", ReadOnlyText, InsModeText, wnd->CurrLine+1, wnd->CurrCol+1);
SendMessage(GetParent(wnd), ADDSTATUS, (PARAM) status, 0);
}
/* ----- window processing module for the editboxes ----- */
static int EditorProc(WINDOW wnd,MESSAGE msg,PARAM p1,PARAM p2)
{
int rtn;
switch (msg)
{
case SETFOCUS:
if ((int)p1)
{
wnd->InsertMode = GetCommandToggle(&MainMenu, ID_INSERT);
wnd->WordWrapMode = GetCommandToggle(&MainMenu, ID_WRAP);
}
rtn = DefaultWndProc(wnd, msg, p1, p2);
if ((int)p1 == FALSE)
SendMessage(GetParent(wnd), ADDSTATUS, 0, 0);
else
ShowPosition(wnd);
return rtn;
case KEYBOARD_CURSOR:
rtn = DefaultWndProc(wnd, msg, p1, p2);
ShowPosition(wnd);
return rtn;
case COMMAND:
switch ((int) p1)
{
case ID_SEARCH:
SearchText(wnd);
return TRUE;
case ID_REPLACE:
ReplaceText(wnd);
return TRUE;
case ID_SEARCHNEXT:
SearchNext(wnd);
return TRUE;
case ID_CUT:
CopyToClipboard(wnd);
SendMessage(wnd, COMMAND, ID_DELETETEXT, 0);
SendMessage(wnd, PAINT, 0, 0);
return TRUE;
case ID_COPY:
CopyToClipboard(wnd);
ClearTextBlock(wnd);
SendMessage(wnd, PAINT, 0, 0);
return TRUE;
case ID_PASTE:
PasteFromClipboard(wnd);
SendMessage(wnd, PAINT, 0, 0);
return TRUE;
case ID_DELETETEXT:
case ID_CLEAR:
rtn = DefaultWndProc(wnd, msg, p1, p2);
SendMessage(wnd, PAINT, 0, 0);
return rtn;
case ID_HELP:
DisplayHelp(wnd, "MEMOPADDOC");
return TRUE;
case ID_WRAP:
SendMessage(GetParent(wnd), COMMAND, ID_WRAP, 0);
wnd->WordWrapMode = cfg.WordWrap;
return TRUE;
case ID_INSERT:
SendMessage(GetParent(wnd), COMMAND, ID_INSERT, 0);
wnd->InsertMode = cfg.InsertMode;
SendMessage(NULL, SHOW_CURSOR, wnd->InsertMode, 0);
return TRUE;
default:
break;
}
break;
case CLOSE_WINDOW: /* If we're only closing, not exiting */
if (cfg.read_only)
{
cfg.read_only=0;
wnd->TextChanged=FALSE;
}
if (wnd->TextChanged)
{
char *cp = DFmalloc(80+strlen(GetTitle(wnd)));
SendMessage(wnd, SETFOCUS, TRUE, 0);
strcpy(cp, " The file\n '");
strcat(cp, GetTitle(wnd));
strcat(cp, "'\nhas not been saved yet. Save it now?");
if (YesNoBox(cp))
SendMessage(GetParent(wnd), COMMAND, ID_SAVE, 0);
free(cp);
}
wndpos=0;
if (wnd->extension != NULL)
{
free(wnd->extension);
wnd->extension=NULL;
}
break;
default:
break;
}
return DefaultWndProc(wnd, msg, p1, p2);
}
/* -- point to the name component of a file specification -- */
static char *NameComponent(char *FileName)
{
char *Fname;
if ((Fname = strrchr(FileName, '\\')) == NULL)
if ((Fname = strrchr(FileName, ':')) == NULL)
Fname = FileName-1;
return Fname + 1;
}
static int PrintSetupProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
int rtn, i = 0, mar;
char marg[10];
WINDOW cwnd;
switch (msg)
{
case CREATE_WINDOW:
rtn = DefaultWndProc(wnd, msg, p1, p2);
PutItemText(wnd, ID_PRINTERPORT, cfg.PrinterPort);
while (ports[i] != NULL)
PutComboListText(wnd, ID_PRINTERPORT, ports[i++]);
for (mar=CHARSLINE;mar>=0;--mar)
{
sprintf(marg, "%3d", mar);
PutItemText(wnd, ID_LEFTMARGIN, marg);
PutItemText(wnd, ID_RIGHTMARGIN, marg);
}
for (mar=LINESPAGE;mar>=0;--mar)
{
sprintf(marg, "%3d", mar);
PutItemText(wnd, ID_TOPMARGIN, marg);
PutItemText(wnd, ID_BOTTOMMARGIN, marg);
}
cwnd = ControlWindow(&PrintSetup, ID_LEFTMARGIN);
SendMessage(cwnd, LB_SETSELECTION, CHARSLINE-cfg.LeftMargin, 0);
cwnd = ControlWindow(&PrintSetup, ID_RIGHTMARGIN);
SendMessage(cwnd, LB_SETSELECTION, CHARSLINE-cfg.RightMargin, 0);
cwnd = ControlWindow(&PrintSetup, ID_TOPMARGIN);
SendMessage(cwnd, LB_SETSELECTION, LINESPAGE-cfg.TopMargin, 0);
cwnd = ControlWindow(&PrintSetup, ID_BOTTOMMARGIN);
SendMessage(cwnd, LB_SETSELECTION, LINESPAGE-cfg.BottomMargin, 0);
return rtn;
case COMMAND:
if ((int) p1 == ID_OK && (int) p2 == 0)
{
GetItemText(wnd, ID_PRINTERPORT, cfg.PrinterPort, 4);
cwnd = ControlWindow(&PrintSetup, ID_LEFTMARGIN);
cfg.LeftMargin = CHARSLINE - SendMessage(cwnd, LB_CURRENTSELECTION, 0, 0);
cwnd = ControlWindow(&PrintSetup, ID_RIGHTMARGIN);
cfg.RightMargin = CHARSLINE - SendMessage(cwnd, LB_CURRENTSELECTION, 0, 0);
cwnd = ControlWindow(&PrintSetup, ID_TOPMARGIN);
cfg.TopMargin = LINESPAGE - SendMessage(cwnd, LB_CURRENTSELECTION, 0, 0);
cwnd = ControlWindow(&PrintSetup, ID_BOTTOMMARGIN);
cfg.BottomMargin = LINESPAGE - SendMessage(cwnd, LB_CURRENTSELECTION, 0, 0);
}
break;
default:
break;
}
return DefaultWndProc(wnd, msg, p1, p2);
}
static void FixTabMenu(void)
{
char *cp = GetCommandText(&MainMenu, ID_TABS);
if (cp != NULL)
{
cp = strchr(cp, '(');
if (cp != NULL)
{
*(cp+1) = cfg.Tabs + '0';
if (inFocus) {
if (GetClass(inFocus) == POPDOWNMENU)
SendMessage(inFocus, PAINT, 0, 0);
}
}
}
}
void PrepFileMenu(void *w, struct Menu *mnu)
{
WINDOW wnd=w; mnu=mnu;
DeactivateCommand(&MainMenu, ID_SAVE);
DeactivateCommand(&MainMenu, ID_SAVEAS);
DeactivateCommand(&MainMenu, ID_CLOSE);
DeactivateCommand(&MainMenu, ID_PRINT);
if (wnd != NULL && GetClass(wnd) == EDITBOX)
{
if (isMultiLine(wnd))
{
if (!cfg.read_only)
{
ActivateCommand(&MainMenu, ID_SAVE);
ActivateCommand(&MainMenu, ID_SAVEAS);
}
ActivateCommand(&MainMenu, ID_CLOSE);
ActivateCommand(&MainMenu, ID_PRINT);
}
}
}
void PrepSearchMenu(void *w, struct Menu *mnu)
{
WINDOW wnd=w; mnu=mnu;
DeactivateCommand(&MainMenu, ID_SEARCH);
DeactivateCommand(&MainMenu, ID_REPLACE);
DeactivateCommand(&MainMenu, ID_SEARCHNEXT);
if (wnd != NULL && GetClass(wnd) == EDITBOX)
{
if (isMultiLine(wnd))
{
ActivateCommand(&MainMenu, ID_SEARCH);
ActivateCommand(&MainMenu, ID_REPLACE);
ActivateCommand(&MainMenu, ID_SEARCHNEXT);
}
}
}
void PrepEditMenu(void *w, struct Menu *mnu)
{
WINDOW wnd=w; mnu=mnu;
DeactivateCommand(&MainMenu, ID_CUT);
DeactivateCommand(&MainMenu, ID_COPY);
DeactivateCommand(&MainMenu, ID_CLEAR);
DeactivateCommand(&MainMenu, ID_DELETETEXT);
DeactivateCommand(&MainMenu, ID_PARAGRAPH);
DeactivateCommand(&MainMenu, ID_PASTE);
DeactivateCommand(&MainMenu, ID_UNDO);
if (wnd != NULL && GetClass(wnd) == EDITBOX)
{
if (isMultiLine(wnd))
{
if (TextBlockMarked(wnd))
{
ActivateCommand(&MainMenu, ID_CUT);
ActivateCommand(&MainMenu, ID_COPY);
ActivateCommand(&MainMenu, ID_CLEAR);
ActivateCommand(&MainMenu, ID_DELETETEXT);
}
ActivateCommand(&MainMenu, ID_PARAGRAPH);
if (!TestAttribute(wnd, READONLY) && ReadClipboard() != NULL)
ActivateCommand(&MainMenu, ID_PASTE);
if (wnd->DeletedText != NULL)
ActivateCommand(&MainMenu, ID_UNDO);
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,245 @@
/* ------------- editor.c ------------ */
#include "dflat.h"
#define pTab ('\t' + 0x80)
#define sTab ('\f' + 0x80)
/* ---------- SETTEXT Message ------------ */
static int SetTextMsg(WINDOW wnd, char *Buf)
{
unsigned char *tp,*ep,*ttp;
int x=0,sz=0,rtn;
tp=Buf;
/* Compute the buffer size based on tabs in the text */
while (*tp)
{
if (*tp == '\t')
{
/* Tab, adjust the buffer length */
int sps=cfg.Tabs-(x % cfg.Tabs);
sz+=sps;
x+=sps;
}
else
{
/* Not a tab, count the character */
sz++;
x++;
}
if (*tp == '\n')
x=0; /* Newline, reset x */
tp++;
}
ep=DFcalloc(1, sz+1); /* Allocate a buffer */
/* Detab the input file */
tp=Buf;
ttp=ep;
x=0;
while (*tp)
{
x++; /* Put the character (\t, too) into the buffer */
/* Expand tab into subst tab (\f + 0x80) and expansions (\t + 0x80) */
if (*tp == '\t')
{
*ttp++ = sTab; /* Substitute tab character */
while ((x % cfg.Tabs) != 0)
*ttp++ = pTab, x++;
}
else
{
*ttp++ = *tp;
if (*tp == '\n')
x=0;
}
tp++;
}
*ttp='\0';
rtn=BaseWndProc(EDITOR, wnd, SETTEXT, (PARAM) ep, 0);
free(ep);
return rtn;
}
void CollapseTabs(WINDOW wnd)
{
unsigned char *cp = wnd->text, *cp2;
while (*cp)
{
if (*cp == pTab)
{
*cp='\t';
cp2=cp;
while (*++cp2 == sTab);
memmove(cp+1, cp2, strlen(cp2)+1);
}
cp++;
}
}
void ExpandTabs(WINDOW wnd)
{
int Holdwtop = wnd->wtop, Holdwleft = wnd->wleft, HoldRow = wnd->CurrLine, HoldCol = wnd->CurrCol, HoldwRow = wnd->WndRow;
SendMessage(wnd, SETTEXT, (PARAM) wnd->text, 0);
wnd->wtop=Holdwtop;
wnd->wleft=Holdwleft;
wnd->CurrLine=HoldRow;
wnd->CurrCol=HoldCol;
wnd->WndRow=HoldwRow;
SendMessage(wnd, PAINT, 0, 0);
SendMessage(wnd, KEYBOARD_CURSOR, 0, wnd->WndRow);
}
/* --- When inserting or deleting, adjust next following tab, same line --- */
static void AdjustTab(WINDOW wnd)
{
int col=wnd->CurrCol;
while (*CurrChar && *CurrChar != '\n')
{
if (*CurrChar == sTab)
{
int exp=(cfg.Tabs-1)-(wnd->CurrCol % cfg.Tabs);
wnd->CurrCol++;
while (*CurrChar == pTab)
BaseWndProc(EDITOR, wnd, KEYBOARD, DEL, 0);
while (exp--)
BaseWndProc(EDITOR, wnd, KEYBOARD, pTab, 0);
break;
}
wnd->CurrCol++;
}
wnd->CurrCol=col;
}
static void TurnOffDisplay(WINDOW wnd)
{
SendMessage(NULL, HIDE_CURSOR, 0, 0);
ClearVisible(wnd);
}
static void TurnOnDisplay(WINDOW wnd)
{
SetVisible(wnd);
SendMessage(NULL, SHOW_CURSOR, 0, 0);
}
static void RepaintLine(WINDOW wnd)
{
SendMessage(wnd, KEYBOARD_CURSOR, WndCol, wnd->WndRow);
WriteTextLine(wnd, NULL, wnd->CurrLine, FALSE);
}
/* --------- KEYBOARD Message ---------- */
static int KeyboardMsg(WINDOW wnd, PARAM p1, PARAM p2)
{
int c=(int) p1;
BOOL delnl;
PARAM pn=p1;
if (WindowMoving || WindowSizing || ((int)p2 & ALTKEY))
return FALSE;
switch (c)
{
case PGUP:
case PGDN:
case UP:
case DN:
pn=(PARAM) BS;
case FWD:
case LARROW:
TurnOffDisplay(wnd);
BaseWndProc(EDITOR, wnd, KEYBOARD, p1, p2);
while (*CurrChar == pTab)
BaseWndProc(EDITOR, wnd, KEYBOARD, pn, p2);
TurnOnDisplay(wnd);
return TRUE;
case DEL:
TurnOffDisplay(wnd);
delnl = *CurrChar == '\n' || TextBlockMarked(wnd);
BaseWndProc(EDITOR, wnd, KEYBOARD, p1, p2);
while (*CurrChar == pTab)
BaseWndProc(EDITOR, wnd, KEYBOARD, p1, p2);
AdjustTab(wnd);
TurnOnDisplay(wnd);
RepaintLine(wnd);
if (delnl)
SendMessage(wnd, PAINT, 0, 0);
return TRUE;
case '\t':
TurnOffDisplay(wnd);
BaseWndProc(EDITOR, wnd, KEYBOARD, (PARAM) sTab, p2);
while ((wnd->CurrCol % cfg.Tabs) != 0)
BaseWndProc(EDITOR, wnd, KEYBOARD, pTab, p2);
TurnOnDisplay(wnd);
RepaintLine(wnd);
return TRUE;
default:
if (((c & FKEY) == 0) && (isprint(c) || c == '\r'))
{
TurnOffDisplay(wnd);
BaseWndProc(EDITOR, wnd, KEYBOARD, p1, p2);
AdjustTab(wnd);
TurnOnDisplay(wnd);
RepaintLine(wnd);
if (c == '\r')
SendMessage(wnd, PAINT, 0, 0);
return TRUE;
}
break;
}
return FALSE;
}
/* ------- Window processing module for EDITBOX class ------ */
int EditorProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
switch (msg)
{
case KEYBOARD:
if (KeyboardMsg(wnd, p1, p2))
return TRUE;
break;
case SETTEXT:
return SetTextMsg(wnd, (char *) p1);
default:
break;
}
return BaseWndProc(EDITOR, wnd, msg, p1, p2);
}

View File

@@ -0,0 +1,231 @@
/* File-Open Dialog Box
Part of FreeDOS Edit
*/
/* I N C L U D E S /////////////////////////////////////////////////////// */
#include "dflat.h"
/* G L O B A L S ///////////////////////////////////////////////////////// */
static char FileSpec[15], SrchSpec[15], FileName[15];
extern DBOX FileOpen, SaveAs;
/* P R O T O T Y P E S /////////////////////////////////////////////////// */
static BOOL DlgFileOpen(char *, char *, char *, DBOX *);
static int DlgFnOpen(WINDOW, MESSAGE, PARAM, PARAM);
static void InitDlgBox(WINDOW);
/*static void StripPath(char *);*/ /*unused?*/
static BOOL IncompleteFilename(char *);
BOOL BuildFileList(WINDOW, char *);
void BuildDirectoryList(WINDOW);
void BuildDriveList(WINDOW);
void BuildPathDisplay(WINDOW);
/* F U N C T I O N S ///////////////////////////////////////////////////// */
BOOL OpenFileDialogBox(char *Fspec, char *Fname)
{
return DlgFileOpen(Fspec, Fspec, Fname, &FileOpen);
}
/* Save as Dialog Box */
BOOL SaveAsDialogBox(char *Fspec, char *Sspec, char *Fname)
{
return DlgFileOpen(Fspec, Sspec ? Sspec : Fspec, Fname, &SaveAs);
}
/* Generic File Open */
static BOOL DlgFileOpen(char *Fspec, char *Sspec, char *Fname, DBOX *db)
{
BOOL rtn;
strncpy(FileSpec, Fspec, 15);
strncpy(SrchSpec, Sspec, 15);
if ((rtn = DialogBox(NULL, db, TRUE, DlgFnOpen)) != FALSE)
strcpy(Fname, FileName);
return rtn;
}
/* Process dialog box messages */
static int DlgFnOpen(WINDOW wnd,MESSAGE msg,PARAM p1,PARAM p2)
{
switch (msg)
{
case CREATE_WINDOW:
{
int rtn = DefaultWndProc(wnd, msg, p1, p2);
DBOX *db = wnd->extension;
WINDOW cwnd = ControlWindow(db, ID_FILENAME);
SendMessage(cwnd, SETTEXTLENGTH, 64, 0);
return rtn;
}
case INITIATE_DIALOG:
InitDlgBox(wnd);
break;
case COMMAND:
switch ((int) p1)
{
case ID_OK:
{
if ((int)p2 == 0)
{
char fn[MAXPATH+1], nm[MAXFILE], ext[MAXEXT];
GetItemText(wnd, ID_FILENAME, fn, MAXPATH);
fnsplit(fn, NULL, NULL, nm, ext);
strcpy(FileName, nm);
strcat(FileName, ext);
CreatePath(NULL, fn, FALSE, TRUE);
if (IncompleteFilename(FileName))
{
/* --- no file name yet --- */
DBOX *db = wnd->extension;
WINDOW cwnd = ControlWindow(db, ID_FILENAME);
strcpy(FileSpec, FileName);
strcpy(SrchSpec, FileName);
InitDlgBox(wnd);
SendMessage(cwnd, SETFOCUS, TRUE, 0);
return TRUE;
}
}
break;
}
case ID_FILES:
switch ((int) p2)
{
case ENTERFOCUS:
case LB_SELECTION:
/* Selected a different filename */
GetDlgListText(wnd, FileName, ID_FILES);
PutItemText(wnd, ID_FILENAME, FileName);
break;
case LB_CHOOSE:
/* Choose a file name */
GetDlgListText(wnd, FileName, ID_FILES);
SendMessage(wnd, COMMAND, ID_OK, 0);
break;
default:
break;
}
return TRUE;
case ID_DIRECTORY:
switch ((int) p2)
{
case ENTERFOCUS:
PutItemText(wnd, ID_FILENAME, FileSpec);
break;
case LB_CHOOSE:
{
/* Choose dir */
char dd[15];
GetDlgListText(wnd, dd, ID_DIRECTORY);
chdir(dd);
InitDlgBox(wnd);
SendMessage(wnd, COMMAND, ID_OK, 0);
break;
}
default:
break;
}
return TRUE;
case ID_DRIVE:
switch ((int) p2)
{
case ENTERFOCUS:
PutItemText(wnd, ID_FILENAME, FileSpec);
break;
case LB_CHOOSE:
{
/* Choose dir */
char dr[15];
GetDlgListText(wnd, dr, ID_DRIVE);
setdisk(dr[2] - 'A');
InitDlgBox(wnd);
SendMessage(wnd, COMMAND, ID_OK, 0);
}
default:
break;
}
return TRUE;
case ID_READONLY:
cfg.read_only=1;
return TRUE;
default:
break;
}
default:
break;
}
return DefaultWndProc(wnd, msg, p1, p2);
}
/* Initialize the dialog box */
static void InitDlgBox(WINDOW wnd)
{
if (*FileSpec)
PutItemText(wnd, ID_FILENAME, FileSpec);
BuildPathDisplay(wnd);
if (BuildFileList(wnd, SrchSpec))
BuildDirectoryList(wnd);
BuildDriveList(wnd);
}
/* Strip the drive and path information from a file spec */
/*
static void StripPath(char *filespec)
{
char *cp, *cp1;
cp = strchr(filespec, ':');
if (cp != NULL)
cp++;
else
cp = filespec;
while (TRUE)
{
cp1 = strchr(cp, '\\');
if (cp1 == NULL)
break;
cp = cp1+1;
}
strcpy(filespec, cp);
}
*/
static BOOL IncompleteFilename(char *s)
{
int lc = strlen(s)-1;
if (strchr(s, '?') || strchr(s, '*') || !*s)
return TRUE;
if (*(s+lc) == ':' || *(s+lc) == '\\')
return TRUE;
return FALSE;
}

View File

@@ -0,0 +1,243 @@
/* ------ fixhelp.c ------ */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "htree.h"
#define FIXHELP
#include "helpbox.h"
#ifndef max
#define max(a,b) ((a)>(b)?(a):(b))
#endif
static FILE *helpfp;
static char hline [160];
static struct helps *FirstHelp;
static struct helps *LastHelp;
static struct helps *ThisHelp;
static void WriteText(char *);
/* ---- compute the displayed length of a help text line --- */
static int HelpLength(char *s)
{
int len=strlen(s);
char *cp=strchr(s, '[');
while (cp != NULL)
{
len -= 4;
cp=strchr(cp+1, '[');
}
cp=strchr(s, '<');
while (cp != NULL)
{
char *cp1=strchr(cp, '>');
if (cp1 != NULL)
len -= (int) (cp1-cp)+1;
cp=strchr(cp1, '<');
}
return len;
}
int FindHelp(char *nm)
{
int hlp=0;
struct helps *thishelp=FirstHelp;
if (nm == NULL)
return -1;
while (thishelp != NULL)
{
if (strcmp(nm, thishelp->hname)==0)
break;
hlp++;
thishelp=thishelp->NextHelp;
}
return thishelp ? hlp : -1;
}
void BuildFileName(char *fn, const char *fname, const char *ext)
{
strcpy(fn, fname);
strcat(fn, ext);
}
static void WriteText(char *text)
{
char *np=text ? text : "";
int len=strlen(np);
fwrite(&len, sizeof(int), 1, helpfp);
if (len)
fwrite(np, len+1, 1, helpfp);
}
int main(int argc, char *argv[])
{
char *cp;
int HelpCount=0;
long where;
if (argc < 2)
return -1;
if ((helpfp=OpenHelpFile(argv[1], "r+b"))==NULL)
return -1;
*hline='\0';
while (*hline != '<')
{
if (GetHelpLine(hline)==NULL)
{
fclose(helpfp);
return -1;
}
}
while (*hline=='<')
{
if (strncmp(hline, "<end>", 5)==0)
break;
/* Parse the help window's text name */
if ((cp=strchr(hline, '>')) != NULL)
{
ThisHelp=calloc(1, sizeof(struct helps));
if (FirstHelp==NULL)
FirstHelp=ThisHelp;
*cp='\0';
ThisHelp->hname=malloc(strlen(hline+1)+1);
strcpy(ThisHelp->hname, hline+1);
HelpFilePosition(&ThisHelp->hptr, &ThisHelp->bit);
if (GetHelpLine(hline)==NULL)
break;
/* Build the help linked list entry */
while (*hline=='[')
{
HelpFilePosition(&ThisHelp->hptr, &ThisHelp->bit);
/* Parse a comment */
if (strncmp(hline, "[*]", 3)==0)
{
ThisHelp->comment=malloc(strlen(hline+3)+1);
strcpy(ThisHelp->comment, hline+3);
if (GetHelpLine(hline)==NULL)
break;
continue;
}
/* Parse the <<prev button pointer */
if (strncmp(hline, "[<<]", 4)==0)
{
char *cp=strchr(hline+4, '<');
if (cp != NULL)
{
char *cp1=strchr(cp, '>');
if (cp1 != NULL)
{
int len=(int) (cp1-cp);
ThisHelp->PrevName=calloc(1,len);
strncpy(ThisHelp->PrevName, cp+1,len-1);
}
}
if (GetHelpLine(hline)==NULL)
break;
continue;
}
/* Parse the next>> button pointer */
else if (strncmp(hline, "[>>]", 4)==0)
{
char *cp=strchr(hline+4, '<');
if (cp != NULL)
{
char *cp1=strchr(cp, '>');
if (cp1 != NULL)
{
int len=(int) (cp1-cp);
ThisHelp->NextName=calloc(1,len);
strncpy(ThisHelp->NextName,cp+1,len-1);
}
}
if (GetHelpLine(hline)==NULL)
break;
continue;
}
else
break;
}
ThisHelp->hheight=0;
ThisHelp->hwidth=0;
ThisHelp->NextHelp=NULL;
/* Append entry to the linked list */
if (LastHelp != NULL)
LastHelp->NextHelp=ThisHelp;
LastHelp=ThisHelp;
HelpCount++;
}
/* Move to the next <helpname> token */
if (GetHelpLine(hline)==NULL)
strcpy(hline, "<end>");
while (*hline != '<')
{
ThisHelp->hwidth=max(ThisHelp->hwidth, HelpLength(hline));
ThisHelp->hheight++;
if (GetHelpLine(hline)==NULL)
strcpy(hline, "<end>");
}
}
/* Append the help structures to the file */
fseek(helpfp, 0L, SEEK_END);
where=ftell(helpfp);
ThisHelp=FirstHelp;
fwrite(&HelpCount, sizeof(HelpCount), 1, helpfp);
while (ThisHelp != NULL)
{
ThisHelp->nexthlp=FindHelp(ThisHelp->NextName);
ThisHelp->prevhlp=FindHelp(ThisHelp->PrevName);
WriteText(ThisHelp->hname);
WriteText(ThisHelp->comment);
fwrite(&ThisHelp->hptr, sizeof(int)*5+sizeof(long), 1, helpfp);
ThisHelp=ThisHelp->NextHelp;
}
fwrite(&where, sizeof(long), 1, helpfp);
fclose(helpfp);
return 0;
}

View File

@@ -0,0 +1,756 @@
/* ------------ helpbox.c ----------- */
#include "dflat.h"
#include "htree.h"
extern DBOX HelpBox;
/* Strings of D-Flat classes for calling default help text collections */
char *ClassNames[] = {
#undef ClassDef
#define ClassDef(c,b,p,a) #c,
#include "classes.h"
NULL
};
#define MAXHEIGHT (SCREENHEIGHT-10)
#define MAXHELPKEYWORDS 50 /* Maximum keywords in a window */
#define MAXHELPSTACK 100
static struct helps *FirstHelp;
static struct helps *ThisHelp;
static char HelpFileName[9];
static char hline[160];
static int HelpCount;
static int HelpStack[MAXHELPSTACK];
static int stacked;
static int keywordcount;
static FILE *helpfp;
static BOOL Helping;
/* --- keywords in the current help text -------- */
static struct keywords {
struct helps *hkey;
int lineno;
int off1, off2, off3;
char isDefinition;
} KeyWords[MAXHELPKEYWORDS];
static struct keywords *thisword;
static void SelectHelp(WINDOW, struct helps *, BOOL);
static void ReadHelp(WINDOW);
static struct helps *FindHelp(char *);
static void DisplayDefinition(WINDOW, char *);
static void BestFit(WINDOW, DIALOGWINDOW *);
/* ------------- CREATE_WINDOW message ------------ */
static void CreateWindowMsg(WINDOW wnd)
{
Helping=TRUE;
GetClass(wnd)=HELPBOX;
InitWindowColors(wnd);
if (ThisHelp != NULL)
ThisHelp->hwnd=wnd;
}
/* ------------- COMMAND message ------------ */
static BOOL CommandMsg(WINDOW wnd, PARAM p1)
{
switch ((int)p1)
{
case ID_PREV:
if (ThisHelp != NULL)
SelectHelp(wnd, FirstHelp+(ThisHelp->prevhlp), TRUE);
return TRUE;
case ID_NEXT:
if (ThisHelp != NULL)
SelectHelp(wnd, FirstHelp+(ThisHelp->nexthlp), TRUE);
return TRUE;
case ID_BACK:
if (stacked)
SelectHelp(wnd, FirstHelp+HelpStack[--stacked], FALSE);
return TRUE;
default:
break;
}
return FALSE;
}
/* ------------- KEYBOARD message ------------ */
static BOOL KeyboardMsg(WINDOW wnd, PARAM p1)
{
WINDOW cwnd;
cwnd=ControlWindow(wnd->extension, ID_HELPTEXT);
if (cwnd == NULL || inFocus != cwnd)
return FALSE;
switch ((int)p1)
{
case '\r':
if (keywordcount)
if (thisword != NULL)
{
char *hp=thisword->hkey->hname;
if (thisword->isDefinition)
DisplayDefinition(GetParent(wnd), hp);
else
SelectHelp(wnd, thisword->hkey, TRUE);
}
return TRUE;
case '\t':
if (!keywordcount)
return TRUE;
if (thisword == NULL || ++thisword == KeyWords+keywordcount)
thisword=KeyWords;
break;
case SHIFT_HT:
if (!keywordcount)
return TRUE;
if (thisword == NULL || thisword == KeyWords)
thisword=KeyWords+keywordcount;
--thisword;
break;
default:
return FALSE;
}
if (thisword->lineno < cwnd->wtop || thisword->lineno >= cwnd->wtop+ClientHeight(cwnd))
{
int distance=ClientHeight(cwnd)/2;
do
{
cwnd->wtop=thisword->lineno-distance;
distance /= 2;
}
while (cwnd->wtop < 0);
}
SendMessage(cwnd, PAINT, 0, 0);
return TRUE;
}
/* ---- window processing module for the HELPBOX ------- */
int HelpBoxProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
switch (msg)
{
case CREATE_WINDOW:
CreateWindowMsg(wnd);
break;
case INITIATE_DIALOG:
ReadHelp(wnd);
break;
case COMMAND:
if (p2 != 0)
break;
if (CommandMsg(wnd, p1))
return TRUE;
break;
case KEYBOARD:
if (WindowMoving)
break;
if (KeyboardMsg(wnd, p1))
return TRUE;
break;
case CLOSE_WINDOW:
if (ThisHelp != NULL)
ThisHelp->hwnd=NULL;
Helping=FALSE;
break;
default:
break;
}
return BaseWndProc(HELPBOX, wnd, msg, p1, p2);
}
/* ---- PAINT message for the helpbox text editbox ---- */
static int PaintMsg(WINDOW wnd, PARAM p1, PARAM p2)
{
int rtn;
if (thisword != NULL)
{
WINDOW pwnd=GetParent(wnd);
char *cp;
cp=TextLine(wnd, thisword->lineno);
cp+=thisword->off1;
*(cp+1)=(pwnd->WindowColors[SELECT_COLOR][FG] & 255) | 0x80;
*(cp+2)=(pwnd->WindowColors[SELECT_COLOR][BG] & 255) | 0x80;
rtn=DefaultWndProc(wnd, PAINT, p1, p2);
*(cp+1)=(pwnd->WindowColors[HILITE_COLOR][FG] & 255) | 0x80;
*(cp+2)=(pwnd->WindowColors[HILITE_COLOR][BG] & 255) | 0x80;
return rtn;
}
return DefaultWndProc(wnd, PAINT, p1, p2);
}
/* ---- LEFT_BUTTON message for the helpbox text editbox ---- */
static int LeftButtonMsg(WINDOW wnd, PARAM p1, PARAM p2)
{
int rtn,mx,my,i;
rtn=DefaultWndProc(wnd, LEFT_BUTTON, p1, p2);
mx=(int)p1-GetClientLeft(wnd);
my=(int)p2-GetClientTop(wnd);
my+=wnd->wtop;
thisword=KeyWords;
for (i=0;i<keywordcount;i++)
{
if (my == thisword->lineno)
{
if (mx >= thisword->off2 && mx < thisword->off3)
{
SendMessage(wnd, PAINT, 0, 0);
if (thisword->isDefinition)
{
WINDOW pwnd=GetParent(wnd);
if (pwnd != NULL)
DisplayDefinition(GetParent(pwnd), thisword->hkey->hname);
}
break;
}
}
thisword++;
}
if (i == keywordcount)
thisword=NULL;
return rtn;
}
/* --- window processing module for HELPBOX's text EDITBOX -- */
int HelpTextProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
switch (msg)
{
case KEYBOARD:
break;
case PAINT:
return PaintMsg(wnd, p1, p2);
case LEFT_BUTTON:
return LeftButtonMsg(wnd, p1, p2);
case DOUBLE_CLICK:
PostMessage(wnd, KEYBOARD, '\r', 0);
break;
default:
break;
}
return DefaultWndProc(wnd, msg, p1, p2);
}
/* -------- read the help text into the editbox ------- */
static void ReadHelp(WINDOW wnd)
{
WINDOW cwnd=ControlWindow(wnd->extension, ID_HELPTEXT);
int linectr=0;
if (cwnd == NULL)
return;
thisword=KeyWords;
keywordcount=0;
cwnd->wndproc=HelpTextProc;
SendMessage(cwnd, CLEARTEXT, 0, 0);
/* Read the help text */
while (TRUE)
{
char *cp=hline, *cp1;
int colorct=0;
if (GetHelpLine(hline) == NULL)
break;
if (*hline == '<')
break;
hline[strlen(hline)-1]='\0';
/* Add help text to the help window */
while (cp != NULL)
{
if ((cp=strchr(cp, '[')) != NULL)
{
if (*(cp+1) != '.' && *(cp+1) != '*')
{
cp++;
continue;
}
thisword->lineno=cwnd->wlines;
thisword->off1=(int) (cp-hline);
thisword->off2=thisword->off1-colorct * 4;
thisword->isDefinition=*(cp+1) == '*';
colorct++;
*cp++ =CHANGECOLOR;
*cp++ =(wnd->WindowColors [HILITE_COLOR] [FG] & 255) | 0x80;
*cp++ =(wnd->WindowColors [HILITE_COLOR] [BG] & 255) | 0x80;
cp1=cp;
if ((cp=strchr(cp, ']')) != NULL)
{
if (thisword != NULL)
thisword->off3=thisword->off2+(int) (cp-cp1);
*cp++ = RESETCOLOR;
}
if ((cp=strchr(cp, '<')) != NULL)
{
char *cp1=strchr(cp, '>');
if (cp1 != NULL)
{
char hname[80];
int len=(int) (cp1-cp);
memset(hname, 0, 80);
strncpy(hname, cp+1, len-1);
thisword->hkey=FindHelp(hname);
memmove(cp, cp1+1, strlen(cp1));
}
}
thisword++;
keywordcount++;
}
}
PutItemText(wnd, ID_HELPTEXT, hline);
/* Display help text as soon as window is full */
if (++linectr == ClientHeight(cwnd))
{
struct keywords *holdthis=thisword;
thisword=NULL;
SendMessage(cwnd, PAINT, 0, 0);
thisword=holdthis;
}
if (linectr > ClientHeight(cwnd) && !TestAttribute(cwnd, VSCROLLBAR))
{
AddAttribute(cwnd, VSCROLLBAR);
SendMessage(cwnd, BORDER, 0, 0);
}
}
thisword=NULL;
}
/* ---- compute the displayed length of a help text line --- */
/*
static int HelpLength(char *s)
{
int len=strlen(s);
char *cp=strchr(s, '[');
while (cp != NULL)
{
len -= 4;
cp=strchr(cp+1, '[');
}
cp=strchr(s, '<');
while (cp != NULL)
{
char *cp1=strchr(cp, '>');
if (cp1 != NULL)
len -= (int) (cp1-cp)+1;
cp=strchr(cp1, '<');
}
return len;
}
*/
/* ----------- load the help text file ------------ */
int LoadHelpFile(char *fname)
{
long where;
int i;
if (Helping)
return 0;
UnLoadHelpFile();
if ((helpfp=OpenHelpFile(fname, "rb")) == NULL)
return 0;
strcpy(HelpFileName, fname);
fseek(helpfp, - (long) sizeof(long), SEEK_END);
fread(&where, sizeof(long), 1, helpfp);
fseek(helpfp, where, SEEK_SET);
fread(&HelpCount, sizeof(HelpCount), 1, helpfp);
FirstHelp=DFcalloc(sizeof(struct helps) * HelpCount, 1);
for (i=0;i<HelpCount;i++)
{
int len;
fread(&len, sizeof(len), 1, helpfp);
if (len)
{
(FirstHelp+i)->hname=DFcalloc(len+1, 1);
fread((FirstHelp+i)->hname, len+1, 1, helpfp);
}
fread(&len, sizeof(len), 1, helpfp);
if (len)
{
(FirstHelp+i)->comment=DFcalloc(len+1, 1);
fread((FirstHelp+i)->comment, len+1, 1, helpfp);
}
fread(&(FirstHelp+i)->hptr, sizeof(int)*5+sizeof(long), 1, helpfp);
}
fclose(helpfp);
helpfp=NULL;
return 1;
}
/* ------ free the memory used by the help file table ------ */
void UnLoadHelpFile(void)
{
int i;
if (FirstHelp != NULL) {
for (i=0;i<HelpCount;i++) {
free((FirstHelp+i)->comment);
free((FirstHelp+i)->hname);
}
free(FirstHelp);
FirstHelp=NULL;
}
if (HelpTree != NULL) {
free(HelpTree);
HelpTree=NULL;
}
}
static void BuildHelpBox(WINDOW wnd)
{
int offset, i;
/* Seek to the first line of the help text */
SeekHelpLine(ThisHelp->hptr, ThisHelp->bit);
/* Read the title */
GetHelpLine(hline);
hline[strlen(hline)-1]='\0';
free(HelpBox.dwnd.title);
HelpBox.dwnd.title=DFmalloc(strlen(hline)+1);
strcpy(HelpBox.dwnd.title, hline);
/* Set the height and width */
HelpBox.dwnd.h=min(ThisHelp->hheight, MAXHEIGHT)+7;
HelpBox.dwnd.w=max(45, ThisHelp->hwidth+6);
/* Position the help window */
if (wnd != NULL)
BestFit(wnd, &HelpBox.dwnd);
/* Position the command buttons */
HelpBox.ctl[0].dwnd.w=max(40, ThisHelp->hwidth+2);
HelpBox.ctl[0].dwnd.h=min(ThisHelp->hheight, MAXHEIGHT)+2;
offset=(HelpBox.dwnd.w-40) / 2;
for (i=1;i<5;i++)
{
HelpBox.ctl[i].dwnd.y=min(ThisHelp->hheight, MAXHEIGHT)+3;
HelpBox.ctl[i].dwnd.x=(i-1) * 10+offset;
}
/* Disable ineffective buttons */
if (ThisHelp->nexthlp == -1)
DisableButton(&HelpBox, ID_NEXT);
else
EnableButton(&HelpBox, ID_NEXT);
if (ThisHelp->prevhlp == -1)
DisableButton(&HelpBox, ID_PREV);
else
EnableButton(&HelpBox, ID_PREV);
}
/* ----- select a new help window from its name ----- */
static void SelectHelp(WINDOW wnd, struct helps *newhelp, BOOL recall)
{
if (newhelp != NULL)
{
int i,x,y;
SendMessage(wnd, HIDE_WINDOW, 0, 0);
if (recall && stacked < MAXHELPSTACK)
HelpStack[stacked++]=ThisHelp-FirstHelp;
ThisHelp=newhelp;
SendMessage(GetParent(wnd), DISPLAY_HELP, (PARAM) ThisHelp->hname, 0);
if (stacked)
EnableButton(&HelpBox, ID_BACK);
else
DisableButton(&HelpBox, ID_BACK);
BuildHelpBox(NULL);
AddTitle(wnd, HelpBox.dwnd.title);
/* Reposition and resize the help window */
HelpBox.dwnd.x=(SCREENWIDTH-HelpBox.dwnd.w)/2;
HelpBox.dwnd.y=(SCREENHEIGHT-HelpBox.dwnd.h)/2;
SendMessage(wnd, MOVE, HelpBox.dwnd.x, HelpBox.dwnd.y);
SendMessage(wnd, SIZE, HelpBox.dwnd.x+HelpBox.dwnd.w-1, HelpBox.dwnd.y+HelpBox.dwnd.h-1);
/* Reposition the controls */
for (i=0;i<5;i++)
{
WINDOW cwnd=HelpBox.ctl[i].wnd;
x=HelpBox.ctl[i].dwnd.x+GetClientLeft(wnd);
y=HelpBox.ctl[i].dwnd.y+GetClientTop(wnd);
SendMessage(cwnd, MOVE, x, y);
if (i == 0)
{
x+=HelpBox.ctl[i].dwnd.w-1;
y+=HelpBox.ctl[i].dwnd.h-1;
SendMessage(cwnd, SIZE, x, y);
}
}
/* Read the help text into the help window */
ReadHelp(wnd);
ReFocus(wnd);
SendMessage(wnd, SHOW_WINDOW, 0, 0);
}
}
/* ---- strip tildes from the help name ---- */
static void StripTildes(char *fh, char *hp)
{
while (*hp)
{
if (*hp != '~')
*fh++ = *hp;
hp++;
}
*fh='\0';
}
/* --- return the comment associated with a help window --- */
char *HelpComment(char *Help)
{
char FixedHelp[30];
StripTildes(FixedHelp, Help);
if ((ThisHelp=FindHelp(FixedHelp)) != NULL)
return ThisHelp->comment;
return NULL;
}
/* ---------- display help text ----------- */
BOOL DisplayHelp(WINDOW wnd, char *Help)
{
char FixedHelp[30];
BOOL rtn=FALSE;
if (Helping)
return TRUE;
StripTildes(FixedHelp, Help);
stacked=0;
wnd->isHelping++;
if ((ThisHelp=FindHelp(FixedHelp)) != NULL)
{
if ((helpfp=OpenHelpFile(HelpFileName, "rb")) != NULL)
{
BuildHelpBox(wnd);
DisableButton(&HelpBox, ID_BACK);
/* Display the help window */
DialogBox(NULL, &HelpBox, TRUE, HelpBoxProc);
free(HelpBox.dwnd.title);
HelpBox.dwnd.title=NULL;
fclose(helpfp);
helpfp=NULL;
rtn=TRUE;
}
}
--wnd->isHelping;
return rtn;
}
/* ------- display a definition window --------- */
static void DisplayDefinition(WINDOW wnd, char *def)
{
WINDOW hwnd=wnd,dwnd;
int y;
struct helps *HoldThisHelp;
HoldThisHelp=ThisHelp;
if (GetClass(wnd) == POPDOWNMENU)
hwnd=GetParent(wnd);
y=GetClass(hwnd) == MENUBAR ? 2 : 1;
if ((ThisHelp=FindHelp(def)) != NULL)
{
dwnd=CreateWindow(TEXTBOX, NULL, GetClientLeft(hwnd), GetClientTop(hwnd)+y, min(ThisHelp->hheight, MAXHEIGHT)+3, ThisHelp->hwidth+2, NULL, wnd, NULL, HASBORDER | NOCLIP | SAVESELF);
if (dwnd != NULL)
{
clearBIOSbuffer();
/* Read the help text */
SeekHelpLine(ThisHelp->hptr, ThisHelp->bit);
while (TRUE)
{
clearBIOSbuffer();
if (GetHelpLine(hline) == NULL)
break;
if (*hline == '<')
break;
hline[strlen(hline)-1]='\0';
SendMessage(dwnd,ADDTEXT,(PARAM)hline,0);
}
SendMessage(dwnd, SHOW_WINDOW, 0, 0);
SendMessage(NULL, WAITKEYBOARD, 0, 0);
SendMessage(NULL, WAITMOUSE, 0, 0);
SendMessage(dwnd, CLOSE_WINDOW, 0, 0);
}
}
ThisHelp=HoldThisHelp;
}
/* ------ compare help names with wild cards ----- */
static BOOL wildcmp(char *s1, char *s2)
{
while (*s1 || *s2)
{
if (tolower(*s1) != tolower(*s2))
if (*s1 != '?' && *s2 != '?')
return TRUE;
s1++, s2++;
}
return FALSE;
}
/* --- ThisHelp=the help window matching specified name --- */
static struct helps *FindHelp(char *Help)
{
int i;
struct helps *thishelp=NULL;
for (i=0;i<HelpCount;i++)
{
if (wildcmp(Help, (FirstHelp+i)->hname) == FALSE)
{
thishelp=FirstHelp+i;
break;
}
}
return thishelp;
}
static int OverLap(int a, int b)
{
int ov=a-b;
if (ov<0)
ov=0;
return ov;
}
/* ----- compute the best location for a help dialogbox ----- */
static void BestFit(WINDOW wnd, DIALOGWINDOW *dwnd)
{
int above, below, right, left;
if (GetClass(wnd) == MENUBAR || GetClass(wnd) == APPLICATION)
{
dwnd->x=dwnd->y=-1;
return;
}
above=OverLap(dwnd->h, GetTop(wnd)); /* Compute above overlap */
below=OverLap(GetBottom(wnd), SCREENHEIGHT-dwnd->h); /* Compute below overlap */
right=OverLap(GetRight(wnd), SCREENWIDTH-dwnd->w); /* Compute right overlap */
left=OverLap(dwnd->w, GetLeft(wnd)); /* Compute left overlap */
if (above < below)
dwnd->y=max(0, GetTop(wnd)-dwnd->h-2);
else
dwnd->y=min(SCREENHEIGHT-dwnd->h, GetBottom(wnd)+2);
if (right < left)
dwnd->x=min(GetRight(wnd)+2, SCREENWIDTH-dwnd->w);
else
dwnd->x=max(0, GetLeft(wnd)-dwnd->w-2);
if (dwnd->x == GetRight(wnd)+2 || dwnd->x == GetLeft(wnd)-dwnd->w-2)
dwnd->y=-1;
if (dwnd->y ==GetTop(wnd)-dwnd->h-2 || dwnd->y == GetBottom(wnd)+2)
dwnd->x=-1;
}

View File

@@ -0,0 +1,24 @@
/* --------- helpbox.h ----------- */
#ifndef HELPBOX_H
#define HELPBOX_H
/* --------- linked list of help text collections -------- */
struct helps {
char *hname;
char *comment;
long hptr;
int bit;
int hheight;
int hwidth;
int nexthlp;
int prevhlp;
void *hwnd;
char *PrevName;
char *NextName;
#ifdef FIXHELP
struct helps *NextHelp;
#endif
};
#endif

View File

@@ -0,0 +1,64 @@
/* ------------------- htree.c -------------------- */
#include "dflat.h"
#include "htree.h"
struct htree *ht;
int root;
int treect;
/* ------ build a Huffman tree from a frequency array ------ */
void buildtree(void)
{
int i;
treect = 256;
/* ---- preset node pointers to -1 ---- */
for (i = 0; i < treect; i++) {
ht[i].parent = -1;
ht[i].right = -1;
ht[i].left = -1;
}
/* ---- build the huffman tree ----- */
while (1) {
int h1 = -1, h2 = -1;
/* ---- find the two lowest frequencies ---- */
for (i = 0; i < treect; i++) {
if (i != h1) {
struct htree *htt = ht+i;
/* --- find a node without a parent --- */
if (htt->cnt > 0 && htt->parent == -1) {
/* ---- h1 & h2 -> lowest nodes ---- */
if (h1 == -1 || htt->cnt < ht[h1].cnt) {
if (h2 == -1 || ht[h1].cnt < ht[h2].cnt)
h2 = h1;
h1 = i;
}
else if (h2 == -1 || htt->cnt < ht[h2].cnt)
h2 = i;
}
}
}
/* --- if only h1 -> a node, that's the root --- */
if (h2 == -1) {
root = h1;
break;
}
/* --- combine two nodes and add one --- */
ht[h1].parent = treect;
ht[h2].parent = treect;
ht = realloc(ht, (treect+1) * sizeof(struct htree));
if (ht == NULL)
break;
/* --- the new node's frequency is the sum of the two
nodes with the lowest frequencies --- */
ht[treect].cnt = ht[h1].cnt + ht[h2].cnt;
/* - the new node points to the two that it combines */
ht[treect].right = h1;
ht[treect].left = h2;
/* --- the new node has no parent (yet) --- */
ht[treect].parent = -1;
treect++;
}
}

View File

@@ -0,0 +1,31 @@
/* ------------------- htree.h -------------------- */
#ifndef HTREE_H
#define HTREE_H
typedef unsigned int BYTECOUNTER;
/* ---- Huffman tree structure for building ---- */
struct htree {
BYTECOUNTER cnt; /* character frequency */
int parent; /* offset to parent node */
int right; /* offset to right child node */
int left; /* offset to left child node */
};
/* ---- Huffman tree structure in compressed file ---- */
struct htr {
int right; /* offset to right child node */
int left; /* offset to left child node */
};
extern struct htr *HelpTree;
void buildtree(void);
FILE *OpenHelpFile(const char *fn, const char *md);
void HelpFilePosition(long *, int *);
void *GetHelpLine(char *);
void SeekHelpLine(long, int);
#endif

View File

@@ -0,0 +1,152 @@
/* FreeDOS Edit Help Compiler
Part of the FreeDOS Project
Originally part of D-Flat, by Dr. Dobbs Journal
Modified by Joe Cosentino 2002.
*/
/* I N C L U D E S /////////////////////////////////////////////////////// */
#include "dflat.h"
#include "htree.h"
/* G L O B A L S ///////////////////////////////////////////////////////// */
extern struct htree *ht;
extern int root;
extern int treect;
static int lastchar='\n';
static int ct8;
static char out8;
/* P R O T O T Y P E S /////////////////////////////////////////////////// */
static void compress(FILE *, int, int);
static void outbit(FILE *, int);
/* F U N C T I O N S ///////////////////////////////////////////////////// */
static int fgetcx(FILE *fi)
{
int c;
/* Bypass comments */
if ((c=fgetc(fi))==';' && lastchar=='\n')
do
{
while (c != '\n' && c != EOF)
c=fgetc(fi);
}
while (c==';');
lastchar=c;
return c;
}
/* Compress a character value into a bit stream */
static void compress(FILE *fo, int h, int child)
{
if (ht[h].parent != -1)
compress(fo, ht[h].parent, h);
if (child)
{
if (child == ht[h].right)
outbit(fo, 0);
else if (child == ht[h].left)
outbit(fo, 1);
}
}
/* Collect and write bits to the compressed output file */
static void outbit(FILE *fo, int bit)
{
if (ct8==8 || bit==-1)
{
while (ct8<8)
{
out8 <<= 1;
ct8++;
}
fputc(out8, fo);
ct8=0;
}
out8=(out8 << 1) | bit;
ct8++;
}
int main(int argc, char *argv[])
{
FILE *fi, *fo;
int c;
BYTECOUNTER bytectr = 0;
if (argc < 3)
{
printf("Syntax: HUFFC infile outfile\n");
return 1;
}
if ((fi = fopen(argv[1], "rb")) == NULL)
{
printf("Cannot open %s\n", argv[1]);
return 1;
}
if ((fo = fopen(argv[2], "wb")) == NULL)
{
printf("Cannot open %s\n", argv[2]);
fclose(fi);
return 1;
}
ht = calloc(256, sizeof(struct htree));
/* Read the input file and count character frequency */
while ((c = fgetcx(fi)) != EOF)
{
c &= 255;
ht[c].cnt++;
bytectr++;
}
/* Build the huffman tree */
buildtree();
/* Write the byte count to the output file */
fwrite(&bytectr, sizeof bytectr, 1, fo);
/* Write the tree count to the output file */
fwrite(&treect, sizeof treect, 1, fo);
/* Write the root offset to the output file */
fwrite(&root, sizeof root, 1, fo);
/* Write the tree to the output file */
for (c=256;c<treect;c++)
{
fwrite(&ht[c].left, sizeof(ht[c].left), 1, fo);
fwrite(&ht[c].right, sizeof(ht[c].right), 1, fo);
}
/* Compress the file */
fseek(fi, 0L, 0);
while ((c = fgetcx(fi)) != EOF)
compress(fo, (c & 255), 0);
outbit(fo, -1);
fclose(fi);
fclose(fo);
free(ht);
return 0;
}

View File

@@ -0,0 +1,87 @@
/* Key combinations
Part of the FreeDOS Editor
*/
#include <stdio.h>
#include "keys.h"
struct keys keys[] = {
{F1, "F1"},
{F2, "F2"},
{F3, "F3"},
{F4, "F4"},
{F5, "F5"},
{F6, "F6"},
{F7, "F7"},
{F8, "F8"},
{F9, "F9"},
{F10, "F10"},
{CTRL_F1, "Ctrl+F1"},
{CTRL_F2, "Ctrl+F2"},
{CTRL_F3, "Ctrl+F3"},
{CTRL_F4, "Ctrl+F4"},
{CTRL_F5, "Ctrl+F5"},
{CTRL_F6, "Ctrl+F6"},
{CTRL_F7, "Ctrl+F7"},
{CTRL_F8, "Ctrl+F8"},
{CTRL_F9, "Ctrl+F9"},
{CTRL_F10, "Ctrl+F10"},
{ALT_F1, "Alt+F1"},
{ALT_F2, "Alt+F2"},
{ALT_F3, "Alt+F3"},
{ALT_F4, "Alt+F4"},
{ALT_F5, "Alt+F5"},
{ALT_F6, "Alt+F6"},
{ALT_F7, "Alt+F7"},
{ALT_F8, "Alt+F8"},
{ALT_F9, "Alt+F9"},
{ALT_F10, "Alt+F10"},
{HOME, "Home"},
{UP, "Up"},
{PGUP, "PgUp"},
{BS, "BS"},
{END, "End"},
{DN, "Dn"},
{PGDN, "PgDn"},
{INS, "Ins"},
{DEL, "Del"},
{CTRL_HOME, "Ctrl+Home"},
{CTRL_PGUP, "Ctrl+PgUp"},
{CTRL_BS, "Ctrl+BS"},
{CTRL_END, "Ctrl+End"},
{CTRL_PGDN, "Ctrl+PgDn"},
{SHIFT_HT, "Shift+Tab"},
{ALT_A, "Alt+A"},
{ALT_B, "Alt+B"},
{ALT_C, "Alt+C"},
{ALT_D, "Alt+D"},
{ALT_E, "Alt+E"},
{ALT_F, "Alt+F"},
{ALT_G, "Alt+G"},
{ALT_H, "Alt+H"},
{ALT_I, "Alt+I"},
{ALT_J, "Alt+J"},
{ALT_K, "Alt+K"},
{ALT_L, "Alt+L"},
{ALT_M, "Alt+M"},
{ALT_N, "Alt+N"},
{ALT_O, "Alt+O"},
{ALT_P, "Alt+P"},
{ALT_Q, "Alt+Q"},
{ALT_R, "Alt+R"},
{ALT_S, "Alt+S"},
{ALT_T, "Alt+T"},
{ALT_U, "Alt+U"},
{ALT_V, "Alt+V"},
{ALT_W, "Alt+W"},
{ALT_X, "Alt+X"},
{ALT_Y, "Alt+Y"},
{ALT_Z, "Alt+Z"},
{CTRL_C, "Ctrl+C"},
{CTRL_J, "Ctrl+F"},
{CTRL_V, "Ctrl+V"},
{CTRL_X, "Ctrl+X"},
{-1, NULL}
};

View File

@@ -0,0 +1,171 @@
/* ----------- keys.h ------------ */
#ifndef KEYS_H
#define KEYS_H
#define FKEY 0x1000 /* offset for non-ASCII keys */
#define BELL 7 /* no scancode */
#define BS 8 /* scancode: 14 */ /* backspace / rubout */
#define TAB 9 /* scancode: 15 */
#define ESC 27 /* scancode: 1 */
#define F1 (FKEY+0x3b) /* scancode: 0x3b */
#define F2 (FKEY+0x3c)
#define F3 (FKEY+0x3d)
#define F4 (FKEY+0x3e)
#define F5 (FKEY+0x3f)
#define F6 (FKEY+0x40)
#define F7 (FKEY+0x41)
#define F8 (FKEY+0x42)
#define F9 (FKEY+0x43)
#define F10 (FKEY+0x44)
#define CTRL_F1 (FKEY+94)
#define CTRL_F2 (FKEY+95)
#define CTRL_F3 (FKEY+96)
#define CTRL_F4 (FKEY+97)
#define CTRL_F5 (FKEY+98)
#define CTRL_F6 (FKEY+99)
#define CTRL_F7 (FKEY+100)
#define CTRL_F8 (FKEY+101)
#define CTRL_F9 (FKEY+102)
#define CTRL_F10 (FKEY+103)
#define ALT_F1 (FKEY+104)
#define ALT_F2 (FKEY+105)
#define ALT_F3 (FKEY+106)
#define ALT_F4 (FKEY+107)
#define ALT_F5 (FKEY+108)
#define ALT_F6 (FKEY+109)
#define ALT_F7 (FKEY+110)
#define ALT_F8 (FKEY+111)
#define ALT_F9 (FKEY+112)
#define ALT_F10 (FKEY+113)
#define HOME (FKEY+0x47) /* scancode: 0x47 */
#define UP (FKEY+0x48)
#define PGUP (FKEY+0x49)
/* 4a: grey- 4b: left 4c: keypad5 4d: right 4e: grey+ */
#define END (FKEY+0x4f)
#define DN (FKEY+0x50)
#define PGDN (FKEY+0x51)
#define INS (FKEY+0x52)
#define DEL (FKEY+0x53)
#define LARROW (FKEY+0x4b)
#define FWD (FKEY+0x4d)
/* valid in ANSI, so assuming that those are universal: */
#define CTRL_END (FKEY+117)
#define CTRL_PGDN (FKEY+118)
#define CTRL_HOME (FKEY+119)
#define CTRL_PGUP (FKEY+132)
/* #define CTRL_FIVE (143) */ /* ctrl-numeric-keypad-5 */
#define CTRL_LARROW (FKEY+0x73) /* ctrl-leftarrow */
#define CTRL_RARROW (FKEY+0x74) /* ctrl-rightarrow */
#define CTRL_BS (127) /* yet another deletion keystroke */
#define SHIFT_HT (FKEY+0x0f) /* scancode: 0x0f */
#define ALT_HYPHEN (130)
#define ALT_BS CTRL_Z /* undo block removal */
#define CTRL_INS CTRL_C /* clipboard copy */
#define SHIFT_DEL CTRL_X /* clipboard cut */
#define SHIFT_INS CTRL_V /* clipboard paste */
/* Stupid...those depend on keyboard layout! */
#define ALT_A (FKEY+0x1e) /* scancode 0x1e */
#define ALT_S (FKEY+0x1f)
#define ALT_D (FKEY+0x20)
#define ALT_F (FKEY+0x21)
#define ALT_G (FKEY+0x22)
#define ALT_H (FKEY+0x23)
#define ALT_J (FKEY+0x24)
#define ALT_K (FKEY+0x25)
#define ALT_L (FKEY+0x26)
#define ALT_Q (FKEY+0x10)
#define ALT_W (FKEY+0x11)
#define ALT_E (FKEY+0x12)
#define ALT_R (FKEY+0x13)
#define ALT_T (FKEY+0x14)
#define ALT_Y (FKEY+0x15)
#define ALT_U (FKEY+0x16)
#define ALT_I (FKEY+0x17)
#define ALT_O (FKEY+0x18)
#define ALT_P (FKEY+0x19)
#define ALT_Z (FKEY+0x2c)
#define ALT_X (FKEY+0x2d)
#define ALT_C (FKEY+0x2e)
#define ALT_B (FKEY+0x2f)
#define ALT_V (FKEY+0x30)
#define ALT_N (FKEY+0x31)
#define ALT_M (FKEY+0x32)
#define ALT_1 (FKEY+0x78) /* 120 */
#define ALT_2 (FKEY+0x79)
#define ALT_3 (FKEY+0x7a)
#define ALT_4 (FKEY+0x7b)
#define ALT_5 (FKEY+0x7c)
#define ALT_6 (FKEY+0x7d)
#define ALT_7 (FKEY+0x7e)
#define ALT_8 (FKEY+0x7f)
#define ALT_9 (FKEY+0x80)
#define ALT_0 (FKEY+0x81)
/* Those are values that are at least typical for DOS: */
#define CTRL_A 1
#define CTRL_B 2
#define CTRL_C 3 /* must have "ignore ^C / ^Break handler to use this */
#define CTRL_D 4
#define CTRL_E 5
#define CTRL_F 10 /* (special meaning for DOS-CON readline?) */
#define CTRL_G 7
#define CTRL_H 8
#define CTRL_I 9
#define CTRL_J 6
#define CTRL_K 11
#define CTRL_L 12
#define CTRL_M 13
#define CTRL_N 14
#define CTRL_O 15
#define CTRL_P 16 /* (causes print in DOS-CON) */
#define CTRL_Q 17
#define CTRL_R 18
#define CTRL_S 19 /* (causes scroll-halt in DOS-CON) */
#define CTRL_T 20
#define CTRL_U 21
#define CTRL_V 22
#define CTRL_W 23
#define CTRL_X 24
#define CTRL_Y 25
#define CTRL_Z 26 /* (marks EOF in DOS-CON) */
/* Shift bit mask */
#define RIGHTSHIFT 0x01
#define LEFTSHIFT 0x02
#define CTRLKEY 0x04
#define ALTKEY 0x08
#define SCROLLLOCK 0x10
#define NUMLOCK 0x20
#define CAPSLOCK 0x40 /* caps lock BEING on */
#define INSERTKEY 0x80
/* Following is new by Eric 11/2002, but see CONSOLE.C */
#define SYSRQKEY 0x8000
#define CAPSLKEY 0x4000 /* PRESSING caps lock */
#define NUMLKEY 0x2000
#define SCROLLLKEY 0x1000
/* Especially the L/R distinction is important - Eric */
#define RALTKEY 0x800 /* treat this als AltGr, which is NOT Alt */
#define RCTRLKEY 0x400
#define LALTKEY 0x200
#define LCTRLKEY 0x100
struct keys {
int keycode;
char *keylabel;
};
extern struct keys keys[];
#endif

View File

@@ -0,0 +1,570 @@
/* ------------- listbox.c ------------ */
#include "dflat.h"
#ifdef INCLUDE_EXTENDEDSELECTIONS
static int ExtendSelections(WINDOW, int, int);
static void TestExtended(WINDOW, PARAM);
static void ClearAllSelections(WINDOW);
static void SetSelection(WINDOW, int);
static void FlipSelection(WINDOW, int);
static void ClearSelection(WINDOW, int);
#else
#define TestExtended(w,p) /**/
#endif
static void near ChangeSelection(WINDOW, int, int);
static void near WriteSelection(WINDOW, int, int, RECT *);
static BOOL SelectionInWindow(WINDOW, int);
static int py=-1; /* the previous y mouse coordinate */
#ifdef INCLUDE_EXTENDEDSELECTIONS
/* --------- CTRL_F8 Key ------------ */
static void AddModeKey(WINDOW wnd)
{
if (isMultiLine(wnd))
{
wnd->AddMode ^= TRUE;
SendMessage(GetParent(wnd), ADDSTATUS, wnd->AddMode ? ((PARAM) "Add Mode") : 0, 0);
}
}
#endif
/* --------- UP (Up Arrow) Key ------------ */
static void UpKey(WINDOW wnd, PARAM p2)
{
if (wnd->selection > 0)
{
if (wnd->selection == wnd->wtop)
{
BaseWndProc(LISTBOX, wnd, KEYBOARD, UP, p2);
PostMessage(wnd, LB_SELECTION, wnd->selection-1, isMultiLine(wnd) ? p2 : FALSE);
}
else
{
int newsel=wnd->selection-1;
if (wnd->wlines == ClientHeight(wnd))
while (*TextLine(wnd, newsel) == LINE)
--newsel;
PostMessage(wnd, LB_SELECTION, newsel,
#ifdef INCLUDE_EXTENDEDSELECTIONS
isMultiLine(wnd) ? p2 :
#endif
FALSE);
}
}
}
/* --------- DN (Down Arrow) Key ------------ */
static void DnKey(WINDOW wnd, PARAM p2)
{
if (wnd->selection < wnd->wlines-1)
{
if (wnd->selection == wnd->wtop+ClientHeight(wnd)-1)
{
BaseWndProc(LISTBOX, wnd, KEYBOARD, DN, p2);
PostMessage(wnd, LB_SELECTION, wnd->selection+1, isMultiLine(wnd) ? p2 : FALSE);
}
else
{
int newsel=wnd->selection+1;
if (wnd->wlines == ClientHeight(wnd))
while (*TextLine(wnd, newsel) == LINE)
newsel++;
PostMessage(wnd, LB_SELECTION, newsel,
#ifdef INCLUDE_EXTENDEDSELECTIONS
isMultiLine(wnd) ? p2 :
#endif
FALSE);
}
}
}
/* --------- HOME and PGUP Keys ------------ */
static void HomePgUpKey(WINDOW wnd, PARAM p1, PARAM p2)
{
BaseWndProc(LISTBOX, wnd, KEYBOARD, p1, p2);
PostMessage(wnd, LB_SELECTION, wnd->wtop,
#ifdef INCLUDE_EXTENDEDSELECTIONS
isMultiLine(wnd) ? p2 :
#endif
FALSE);
}
/* --------- END and PGDN Keys ------------ */
static void EndPgDnKey(WINDOW wnd, PARAM p1, PARAM p2)
{
int bot;
BaseWndProc(LISTBOX, wnd, KEYBOARD, p1, p2);
bot=wnd->wtop+ClientHeight(wnd)-1;
if (bot > wnd->wlines-1)
bot=wnd->wlines-1;
PostMessage(wnd, LB_SELECTION, bot,
#ifdef INCLUDE_EXTENDEDSELECTIONS
isMultiLine(wnd) ? p2 :
#endif
FALSE);
}
#ifdef INCLUDE_EXTENDEDSELECTIONS
/* --------- Space Bar Key ------------ */
static void SpacebarKey(WINDOW wnd, PARAM p2)
{
if (isMultiLine(wnd))
{
int sel=SendMessage(wnd, LB_CURRENTSELECTION, 0, 0);
if (sel != -1)
{
if (wnd->AddMode)
FlipSelection(wnd, sel);
if (ItemSelected(wnd, sel))
{
if (!((int) p2 & (LEFTSHIFT | RIGHTSHIFT)))
wnd->AnchorPoint=sel;
ExtendSelections(wnd, sel, (int) p2);
}
else
wnd->AnchorPoint=-1;
SendMessage(wnd, PAINT, 0, 0);
}
}
}
#endif
/* --------- Enter ('\r') Key ------------ */
static void EnterKey(WINDOW wnd)
{
if (wnd->selection != -1)
{
SendMessage(wnd, LB_SELECTION, wnd->selection, TRUE);
SendMessage(wnd, LB_CHOOSE, wnd->selection, 0);
}
}
/* --------- All Other Key Presses ------------ */
static void KeyPress(WINDOW wnd, PARAM p1, PARAM p2)
{
int sel=wnd->selection+1;
while (sel < wnd->wlines)
{
char *cp=TextLine(wnd, sel);
if (cp == NULL)
break;
#ifdef INCLUDE_EXTENDEDSELECTIONS
if (isMultiLine(wnd))
cp++;
#endif
if (tolower(*cp) == (int)p1)
{
SendMessage(wnd, LB_SELECTION, sel, isMultiLine(wnd) ? p2 : FALSE);
if (!SelectionInWindow(wnd, sel))
{
wnd->wtop=sel-ClientHeight(wnd)+1;
SendMessage(wnd, PAINT, 0, 0);
}
break;
}
sel++;
}
}
/* --------- KEYBOARD Message ------------ */
static int KeyboardMsg(WINDOW wnd, PARAM p1, PARAM p2)
{
switch ((int) p1)
{
#ifdef INCLUDE_EXTENDEDSELECTIONS
case CTRL_F8:
AddModeKey(wnd);
return TRUE;
#endif
case UP:
TestExtended(wnd, p2);
UpKey(wnd, p2);
return TRUE;
case DN:
TestExtended(wnd, p2);
DnKey(wnd, p2);
return TRUE;
case PGUP:
case HOME:
TestExtended(wnd, p2);
HomePgUpKey(wnd, p1, p2);
return TRUE;
case PGDN:
case END:
TestExtended(wnd, p2);
EndPgDnKey(wnd, p1, p2);
return TRUE;
#ifdef INCLUDE_EXTENDEDSELECTIONS
case ' ':
SpacebarKey(wnd, p2);
break;
#endif
case '\r':
EnterKey(wnd);
return TRUE;
default:
KeyPress(wnd, p1, p2);
break;
}
return FALSE;
}
/* ------- LEFT_BUTTON Message -------- */
static int LeftButtonMsg(WINDOW wnd, PARAM p1, PARAM p2)
{
int my=(int) p2-GetTop(wnd);
if (my >= wnd->wlines-wnd->wtop)
my=wnd->wlines-wnd->wtop;
if (!InsideRect(p1, p2, ClientRect(wnd)))
return FALSE;
if (wnd->wlines && my != py)
{
int sel=wnd->wtop+my-1;
#ifdef INCLUDE_EXTENDEDSELECTIONS
int sh=getshift();
if (!(sh & (LEFTSHIFT | RIGHTSHIFT)))
{
if (!(sh & CTRLKEY))
ClearAllSelections(wnd);
wnd->AnchorPoint=sel;
SendMessage(wnd, PAINT, 0, 0);
}
#endif
SendMessage(wnd, LB_SELECTION, sel, TRUE);
py=my;
}
return TRUE;
}
/* ------------- DOUBLE_CLICK Message ------------ */
static int DoubleClickMsg(WINDOW wnd, PARAM p1, PARAM p2)
{
if (WindowMoving || WindowSizing)
return FALSE;
if (wnd->wlines)
{
RECT rc=ClientRect(wnd);
BaseWndProc(LISTBOX, wnd, DOUBLE_CLICK, p1, p2);
if (InsideRect(p1, p2, rc))
SendMessage(wnd, LB_CHOOSE, wnd->selection, 0);
}
return TRUE;
}
/* ------------ ADDTEXT Message -------------- */
static int AddTextMsg(WINDOW wnd, PARAM p1, PARAM p2)
{
int rtn=BaseWndProc(LISTBOX, wnd, ADDTEXT, p1, p2);
if (wnd->selection == -1)
SendMessage(wnd, LB_SETSELECTION, 0, 0);
#ifdef INCLUDE_EXTENDEDSELECTIONS
if (*(char *)p1 == LISTSELECTOR)
wnd->SelectCount++;
#endif
return rtn;
}
/* --------- GETTEXT Message ------------ */
static void GetTextMsg(WINDOW wnd, PARAM p1, PARAM p2)
{
if ((int)p2 != -1)
{
char *cp1=(char *)p1, *cp2=TextLine(wnd, (int)p2);
while (cp2 && *cp2 && *cp2 != '\n')
*cp1++ = *cp2++;
*cp1='\0';
}
}
/* --------- LISTBOX Window Processing Module ------------ */
int ListBoxProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
switch (msg)
{
case CREATE_WINDOW:
BaseWndProc(LISTBOX, wnd, msg, p1, p2);
wnd->selection=-1;
#ifdef INCLUDE_EXTENDEDSELECTIONS
wnd->AnchorPoint=-1;
#endif
return TRUE;
case KEYBOARD:
if (WindowMoving || WindowSizing)
break;
if (KeyboardMsg(wnd, p1, p2))
return TRUE;
break;
case LEFT_BUTTON:
if (LeftButtonMsg(wnd, p1, p2) == TRUE)
return TRUE;
break;
case DOUBLE_CLICK:
if (DoubleClickMsg(wnd, p1, p2))
return TRUE;
break;
case BUTTON_RELEASED:
if (WindowMoving || WindowSizing || VSliding)
break;
py=-1;
return TRUE;
case ADDTEXT:
return AddTextMsg(wnd, p1, p2);
case LB_GETTEXT:
GetTextMsg(wnd, p1, p2);
return TRUE;
case CLEARTEXT:
wnd->selection=-1;
#ifdef INCLUDE_EXTENDEDSELECTIONS
wnd->AnchorPoint=-1;
#endif
wnd->SelectCount=0;
break;
case PAINT:
BaseWndProc(LISTBOX, wnd, msg, p1, p2);
WriteSelection(wnd, wnd->selection, TRUE, (RECT *)p1);
return TRUE;
case SETFOCUS:
BaseWndProc(LISTBOX, wnd, msg, p1, p2);
if ((int)p1)
WriteSelection(wnd, wnd->selection, TRUE, NULL);
return TRUE;
case SCROLL:
case HORIZSCROLL:
case SCROLLPAGE:
case HORIZPAGE:
case SCROLLDOC:
BaseWndProc(LISTBOX, wnd, msg, p1, p2);
WriteSelection(wnd,wnd->selection,TRUE,NULL);
return TRUE;
case LB_CHOOSE:
SendMessage(GetParent(wnd), LB_CHOOSE, p1, p2);
return TRUE;
case LB_SELECTION:
ChangeSelection(wnd, (int) p1, (int) p2);
SendMessage(GetParent(wnd), LB_SELECTION, wnd->selection, 0);
return TRUE;
case LB_CURRENTSELECTION:
return wnd->selection;
case LB_SETSELECTION:
ChangeSelection(wnd, (int) p1, 0);
return TRUE;
#ifdef INCLUDE_EXTENDEDSELECTIONS
case CLOSE_WINDOW:
if (isMultiLine(wnd) && wnd->AddMode)
{
wnd->AddMode=FALSE;
SendMessage(GetParent(wnd), ADDSTATUS, 0, 0);
}
break;
#endif
default:
break;
}
return BaseWndProc(LISTBOX, wnd, msg, p1, p2);
}
static BOOL SelectionInWindow(WINDOW wnd, int sel)
{
return (wnd->wlines && sel >= wnd->wtop && sel < wnd->wtop+ClientHeight(wnd));
}
static void near WriteSelection(WINDOW wnd, int sel, int reverse, RECT *rc)
{
if (isVisible(wnd))
if (SelectionInWindow(wnd, sel))
WriteTextLine(wnd, rc, sel, reverse);
}
#ifdef INCLUDE_EXTENDEDSELECTIONS
/* ----- Test for extended selections in the listbox ----- */
static void TestExtended(WINDOW wnd, PARAM p2)
{
if (isMultiLine(wnd) && !wnd->AddMode && !((int) p2 & (LEFTSHIFT | RIGHTSHIFT)))
{
if (wnd->SelectCount > 1)
{
ClearAllSelections(wnd);
SendMessage(wnd, PAINT, 0, 0);
}
}
}
/* ----- Clear selections in the listbox ----- */
static void ClearAllSelections(WINDOW wnd)
{
if (isMultiLine(wnd) && wnd->SelectCount > 0)
{
int sel;
for (sel=0;sel<wnd->wlines;sel++)
ClearSelection(wnd, sel);
}
}
/* ----- Invert a selection in the listbox ----- */
static void FlipSelection(WINDOW wnd, int sel)
{
if (isMultiLine(wnd))
{
if (ItemSelected(wnd, sel))
ClearSelection(wnd, sel);
else
SetSelection(wnd, sel);
}
}
static int ExtendSelections(WINDOW wnd, int sel, int shift)
{
if (shift & (LEFTSHIFT | RIGHTSHIFT) && wnd->AnchorPoint != -1)
{
int i=sel,j=wnd->AnchorPoint,rtn;
if (j > i)
swap(i,j);
rtn=i-j;
while (j <= i)
SetSelection(wnd, j++);
return rtn;
}
return 0;
}
static void SetSelection(WINDOW wnd, int sel)
{
if (isMultiLine(wnd) && !ItemSelected(wnd, sel))
{
char *lp=TextLine(wnd, sel);
*lp=LISTSELECTOR;
wnd->SelectCount++;
}
}
static void ClearSelection(WINDOW wnd, int sel)
{
if (isMultiLine(wnd) && ItemSelected(wnd, sel))
{
char *lp=TextLine(wnd, sel);
*lp=' ';
--wnd->SelectCount;
}
}
BOOL ItemSelected(WINDOW wnd, int sel)
{
if (sel != -1 && isMultiLine(wnd) && sel < wnd->wlines)
{
char *cp=TextLine(wnd, sel);
return (int)((*cp) & 255) == LISTSELECTOR;
}
return FALSE;
}
#endif
static void near ChangeSelection(WINDOW wnd,int sel,int shift)
{
if (sel != wnd->selection)
{
#ifdef INCLUDE_EXTENDEDSELECTIONS
if (sel != -1 && isMultiLine(wnd))
{
int sels;
if (!wnd->AddMode)
ClearAllSelections(wnd);
sels=ExtendSelections(wnd, sel, shift);
if (sels > 1)
SendMessage(wnd, PAINT, 0, 0);
if (sels == 0 && !wnd->AddMode)
{
ClearSelection(wnd, wnd->selection);
SetSelection(wnd, sel);
wnd->AnchorPoint=sel;
}
}
#endif
WriteSelection(wnd, wnd->selection, FALSE, NULL);
wnd->selection=sel;
if (sel != -1)
WriteSelection(wnd, sel, TRUE, NULL);
}
}

View File

@@ -0,0 +1,124 @@
/* --------------- lists.c -------------- */
#include "dflat.h"
/* ----- set focus to the next sibling ----- */
void SetNextFocus()
{
if (inFocus != NULL) {
WINDOW wnd1 = inFocus, pwnd;
while (TRUE) {
pwnd = GetParent(wnd1);
if (NextWindow(wnd1) != NULL)
wnd1 = NextWindow(wnd1);
else if (pwnd != NULL)
wnd1 = FirstWindow(pwnd);
if (wnd1 == NULL || wnd1 == inFocus) {
wnd1 = pwnd;
break;
}
if (GetClass(wnd1) == STATUSBAR || GetClass(wnd1) == MENUBAR)
continue;
if (isVisible(wnd1))
break;
}
if (wnd1 != NULL) {
while (wnd1->childfocus != NULL)
wnd1 = wnd1->childfocus;
if (wnd1->condition != ISCLOSING)
SendMessage(wnd1, SETFOCUS, TRUE, 0);
}
}
}
/* ----- set focus to the previous sibling ----- */
void SetPrevFocus()
{
if (inFocus != NULL) {
WINDOW wnd1 = inFocus, pwnd;
while (TRUE) {
pwnd = GetParent(wnd1);
if (PrevWindow(wnd1) != NULL)
wnd1 = PrevWindow(wnd1);
else if (pwnd != NULL)
wnd1 = LastWindow(pwnd);
if (wnd1 == NULL || wnd1 == inFocus) {
wnd1 = pwnd;
break;
}
if (GetClass(wnd1) == STATUSBAR)
continue;
if (isVisible(wnd1))
break;
}
if (wnd1 != NULL) {
while (wnd1->childfocus != NULL)
wnd1 = wnd1->childfocus;
if (wnd1->condition != ISCLOSING)
SendMessage(wnd1, SETFOCUS, TRUE, 0);
}
}
}
/* ------- move a window to the end of its parents list ----- */
void ReFocus(WINDOW wnd)
{
if (GetParent(wnd) != NULL) {
RemoveWindow(wnd);
AppendWindow(wnd);
ReFocus(GetParent(wnd));
}
}
/* ---- remove a window from the linked list ---- */
void RemoveWindow(WINDOW wnd)
{
if (wnd != NULL) {
WINDOW pwnd = GetParent(wnd);
if (PrevWindow(wnd) != NULL)
NextWindow(PrevWindow(wnd)) = NextWindow(wnd);
if (NextWindow(wnd) != NULL)
PrevWindow(NextWindow(wnd)) = PrevWindow(wnd);
if (pwnd != NULL) {
if (wnd == FirstWindow(pwnd))
FirstWindow(pwnd) = NextWindow(wnd);
if (wnd == LastWindow(pwnd))
LastWindow(pwnd) = PrevWindow(wnd);
}
}
}
/* ---- append a window to the linked list ---- */
void AppendWindow(WINDOW wnd)
{
if (wnd != NULL) {
WINDOW pwnd = GetParent(wnd);
if (pwnd != NULL) {
if (FirstWindow(pwnd) == NULL)
FirstWindow(pwnd) = wnd;
if (LastWindow(pwnd) != NULL)
NextWindow(LastWindow(pwnd)) = wnd;
PrevWindow(wnd) = LastWindow(pwnd);
LastWindow(pwnd) = wnd;
}
NextWindow(wnd) = NULL;
}
}
/* ----- if document windows and statusbar or menubar get the focus,
pass it on ------- */
void SkipApplicationControls(void)
{
BOOL EmptyAppl = FALSE;
int ct = 0;
while (!EmptyAppl && inFocus != NULL) {
CLASS cl = GetClass(inFocus);
if (cl == MENUBAR || cl == STATUSBAR) {
SetPrevFocus();
EmptyAppl = (cl == MENUBAR && ct++);
}
else
break;
}
}

View File

@@ -0,0 +1,70 @@
/* ------------ log .c ------------ */
#include "dflat.h"
#ifdef INCLUDE_LOGGING
static char *message[] = {
#undef DFlatMsg
#define DFlatMsg(m) " " #m,
#include "dflatmsg.h"
NULL
};
static FILE *log = NULL;
extern DBOX Log;
void LogMessages (WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
if (log != NULL && message[msg][0] != ' ')
fprintf(log,
"%-20.20s %-12.12s %-20.20s, %5.5ld, %5.5ld\n",
wnd ? (GetTitle(wnd) ? GetTitle(wnd) : "") : "",
wnd ? ClassNames[GetClass(wnd)] : "",
message[msg]+1, p1, p2);
}
static int LogProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
WINDOW cwnd = ControlWindow(&Log, ID_LOGLIST);
char **mn = message;
switch (msg) {
case INITIATE_DIALOG:
AddAttribute(cwnd, MULTILINE | VSCROLLBAR);
while (*mn) {
SendMessage(cwnd, ADDTEXT, (PARAM) (*mn), 0);
mn++;
}
SendMessage(cwnd, SHOW_WINDOW, 0, 0);
break;
case COMMAND:
if ((int) p1 == ID_OK) {
int item;
int tl = GetTextLines(cwnd);
for (item = 0; item < tl; item++)
if (ItemSelected(cwnd, item))
mn[item][0] = LISTSELECTOR;
}
break;
default:
break;
}
return DefaultWndProc(wnd, msg, p1, p2);
}
void MessageLog(WINDOW wnd)
{
if (DialogBox(wnd, &Log, TRUE, LogProc)) {
if (CheckBoxSetting(&Log, ID_LOGGING)) {
log = fopen("DFLAT.LOG", "wt");
SetCommandToggle(&MainMenu, ID_LOG);
}
else if (log != NULL) {
fclose(log);
log = NULL;
ClearCommandToggle(&MainMenu, ID_LOG);
}
}
}
#endif

View File

@@ -0,0 +1,50 @@
# Makefile
CPP = g++.exe
CC = gcc.exe
WINDRES = windres.exe
DIR_OBJECTS = obj/
DIR_INCLUDE =
DEFS = -DINCLUDE_PICTUREBOX -DINCLUDE_MULTI_WINDOWS
DEFS += -DINCLUDE_WINDOWOPTIONS -DINCLUDE_MAXIMIZE
DEFS += -DINCLUDE_MINIMIZE -DINCLUDE_RESTORE
DEFS += -DINCLUDE_EXTENDEDSELECTIONS
DEFS += -D_FDEDIT_PRIVATE_CLIPBOARD
INCLUDE =
DEBUG = -Wall #-W -ansi #-Xlinker -M # -Werror
OPTIMIZE = -O2 -fomit-frame-pointer -mpreferred-stack-boundary=2
OPTIMIZE+= -march=pentium -mtune=pentium
LIBS = -mconsole -s
CFLAGS = $(DEFS) $(INCLUDE) $(DEBUG) $(OPTIMIZE)
FILES = window message textbox listbox normal dialogs menus rdonly
FILES += config menu menubar popdown rect applicat keys sysmenu
FILES += dialbox button fileopen msgbox helpbox log lists statbar
FILES += combobox pictbox calendar clipbord search dfalloc editor editbox
FILES += checkbox text radio box spinbutt watch slidebox direct
FILES += decomp edit
FILES += timer_w32 country_w32 dir_w32 video_w32 console_w32 clipbord_w32
OBJS= $(addprefix $(DIR_OBJECTS), $(addsuffix .o, $(FILES)))
all : edit.exe edit.hlp
edit.exe: $(OBJS)
$(CC) $^ -o $@ $(LIBS)
$(DIR_OBJECTS)%.o: %.c
$(CC) -c $< -o $@ $(CFLAGS)
huffc.exe : $(DIR_OBJECTS)huffc.o $(DIR_OBJECTS)htree.o
$(CC) $^ -o $@ $(LIBS)
fixhelp.exe : $(DIR_OBJECTS)fixhelp.o $(DIR_OBJECTS)decomp.o
$(CC) $^ -o $@ $(LIBS)
edit.hlp : edit.txt huffc.exe fixhelp.exe
huffc edit.txt $@

View File

@@ -0,0 +1,85 @@
/* ------------- menu.c ------------- */
#include "dflat.h"
static struct PopDown *FindCmd(MBAR *mn, int cmd)
{
MENU *mnu = mn->PullDown;
while (mnu->Title != (void *)-1) {
struct PopDown *pd = mnu->Selections;
while (pd->SelectionTitle != NULL) {
if (pd->ActionId == cmd)
return pd;
pd++;
}
mnu++;
}
return NULL;
}
char *GetCommandText(MBAR *mn, int cmd)
{
struct PopDown *pd = FindCmd(mn, cmd);
if (pd != NULL)
return pd->SelectionTitle;
return NULL;
}
BOOL isCascadedCommand(MBAR *mn, int cmd)
{
struct PopDown *pd = FindCmd(mn, cmd);
if (pd != NULL)
return pd->Attrib & CASCADED;
return FALSE;
}
void ActivateCommand(MBAR *mn, int cmd)
{
struct PopDown *pd = FindCmd(mn, cmd);
if (pd != NULL)
pd->Attrib &= ~INACTIVE;
}
void DeactivateCommand(MBAR *mn, int cmd)
{
struct PopDown *pd = FindCmd(mn, cmd);
if (pd != NULL)
pd->Attrib |= INACTIVE;
}
BOOL isActive(MBAR *mn, int cmd)
{
struct PopDown *pd = FindCmd(mn, cmd);
if (pd != NULL)
return !(pd->Attrib & INACTIVE);
return FALSE;
}
BOOL GetCommandToggle(MBAR *mn, int cmd)
{
struct PopDown *pd = FindCmd(mn, cmd);
if (pd != NULL)
return (pd->Attrib & CHECKED) != 0;
return FALSE;
}
void SetCommandToggle(MBAR *mn, int cmd)
{
struct PopDown *pd = FindCmd(mn, cmd);
if (pd != NULL)
pd->Attrib |= CHECKED;
}
void ClearCommandToggle(MBAR *mn, int cmd)
{
struct PopDown *pd = FindCmd(mn, cmd);
if (pd != NULL)
pd->Attrib &= ~CHECKED;
}
void InvertCommandToggle(MBAR *mn, int cmd)
{
struct PopDown *pd = FindCmd(mn, cmd);
if (pd != NULL)
pd->Attrib ^= CHECKED;
}

View File

@@ -0,0 +1,63 @@
/* ------------ menu.h ------------- */
#ifndef MENU_H
#define MENU_H
#define MAXPULLDOWNS 15
#define MAXSELECTIONS 20
#define MAXCASCADES 3 /* nesting level of cascaded menus */
/* ----------- popdown menu selection structure
one for each selection on a popdown menu --------- */
struct PopDown {
unsigned char *SelectionTitle; /* title of the selection */
int ActionId; /* the command executed */
int Accelerator; /* the accelerator key */
int Attrib; /* INACTIVE | CHECKED | TOGGLE | CASCADED*/
char *help; /* Help mnemonic */
};
/* ----------- popdown menu structure
one for each popdown menu on the menu bar -------- */
typedef struct Menu {
char *Title; /* title on the menu bar */
void (*PrepMenu)(void *, struct Menu *); /* function */
char *StatusText; /* text for the status bar */
int CascadeId; /* command id of cascading selection */
int Selection; /* most recent selection */
struct PopDown Selections[MAXSELECTIONS+1];
} MENU;
/* ----- one for each menu bar ----- */
typedef struct MenuBar {
int ActiveSelection;
MENU PullDown[MAXPULLDOWNS+1];
} MBAR;
/* --------- macros to define a menu bar with
popdowns and selections ------------- */
#define SEPCHAR "\xc4"
#define DEFMENU(m) MBAR m = {-1,{
#define POPDOWN(ttl,func,stat) {ttl,func,stat,-1,0,{
#define CASCADED_POPDOWN(id,func) {NULL,func,NULL,id,0,{
#define SELECTION(stxt,acc,id,attr) {stxt,acc,id,attr,#acc},
#define SEPARATOR {SEPCHAR},
#define ENDPOPDOWN {NULL}}},
#define ENDMENU {(char *)-1} }};
/* -------- menu selection attributes -------- */
#define INACTIVE 1
#define CHECKED 2
#define TOGGLE 4
#define CASCADED 8
/* --------- the standard menus ---------- */
extern MBAR MainMenu;
extern MBAR SystemMenu;
extern MBAR *ActiveMenuBar;
int MenuHeight(struct PopDown *);
int MenuWidth(struct PopDown *);
#endif

View File

@@ -0,0 +1,482 @@
/* ---------------- menubar.c ------------------ */
#include "dflat.h"
static void reset_menubar(WINDOW);
static struct {
int x1, x2; /* position in menu bar */
char sc; /* shortcut key value */
} menu[10];
static int mctr;
static int casc;
MBAR *ActiveMenuBar;
static MENU *ActiveMenu;
static BOOL Selecting;
static WINDOW mwnd;
static WINDOW Cascaders[MAXCASCADES];
static WINDOW GetDocFocus(void);
/* ----------- SETFOCUS Message ----------- */
static int SetFocusMsg(WINDOW wnd, PARAM p1)
{
int rtn;
rtn=BaseWndProc(MENUBAR, wnd, SETFOCUS, p1, 0);
if (!(int)p1)
SendMessage(GetParent(wnd), ADDSTATUS, 0, 0);
else
SendMessage(NULL, HIDE_CURSOR, 0, 0);
return rtn;
}
/* --------- BUILDMENU Message --------- */
static void BuildMenuMsg(WINDOW wnd, PARAM p1)
{
int offset=3;
reset_menubar(wnd);
mctr=0;
ActiveMenuBar=(MBAR *) p1;
ActiveMenu=ActiveMenuBar->PullDown;
while (ActiveMenu->Title != NULL && ActiveMenu->Title != (void*)-1)
{
char *cp;
if (strlen(GetText(wnd)+offset) < strlen(ActiveMenu->Title)+3)
break;
GetText(wnd)=DFrealloc(GetText(wnd), strlen(GetText(wnd))+5);
memmove(GetText(wnd)+offset+4, GetText(wnd)+offset, strlen(GetText(wnd))-offset+1);
CopyCommand(GetText(wnd)+offset,ActiveMenu->Title,FALSE, wnd->WindowColors [STD_COLOR] [BG]);
menu[mctr].x1=offset;
offset += strlen(ActiveMenu->Title)+(3+MSPACE);
menu[mctr].x2=offset-MSPACE;
cp=strchr(ActiveMenu->Title, SHORTCUTCHAR);
if (cp)
menu[mctr].sc=tolower(*(cp+1));
mctr++;
ActiveMenu++;
}
ActiveMenu=ActiveMenuBar->PullDown;
}
/* ---------- PAINT Message ---------- */
static void PaintMsg(WINDOW wnd)
{
if (Selecting)
return;
if (wnd == inFocus)
SendMessage(GetParent(wnd), ADDSTATUS, 0, 0);
SetStandardColor(wnd);
wputs(wnd, GetText(wnd), 0, 0);
if (ActiveMenuBar->ActiveSelection != -1 && (wnd == inFocus || mwnd != NULL))
{
char *sel,*cp;
int offset,offset1;
sel=DFmalloc(200);
offset=menu[ActiveMenuBar->ActiveSelection].x1;
offset1=menu[ActiveMenuBar->ActiveSelection].x2;
GetText(wnd)[offset1]='\0';
SetReverseColor(wnd);
memset(sel, '\0', 200);
strcpy(sel, GetText(wnd)+offset);
cp=strchr(sel, CHANGECOLOR);
if (cp != NULL)
*(cp+2)=background | 0x80;
wputs(wnd, sel, offset-ActiveMenuBar->ActiveSelection*4, 0);
GetText(wnd)[offset1]=' ';
if (mwnd == NULL && wnd == inFocus)
{
char *st=ActiveMenu[ActiveMenuBar->ActiveSelection].StatusText;
if (st != NULL)
SendMessage(GetParent(wnd), ADDSTATUS, (PARAM)st, 0);
}
free(sel);
}
}
/* ------------ KEYBOARD Message ------------- */
static void KeyboardMsg(WINDOW wnd, PARAM p1)
{
MENU *mnu;
int sel;
if (mwnd == NULL)
{
/* Search for menu bar shortcut keys */
int c=tolower((int)p1),a=AltConvert((int)p1),j;
for (j=0;j<mctr;j++)
{
if ((inFocus == wnd && menu[j].sc == c) || (a && menu[j].sc == a))
{
SendMessage(wnd, SETFOCUS, TRUE, 0);
SendMessage(wnd, MB_SELECTION, j, 0);
return;
}
}
}
/* Search for accelerator keys */
mnu=ActiveMenu;
while (mnu->Title != (void *)-1)
{
struct PopDown *pd=mnu->Selections;
if (mnu->PrepMenu)
(*(mnu->PrepMenu))(GetDocFocus(), mnu);
while (pd->SelectionTitle != NULL)
{
if (pd->Accelerator == (int) p1)
{
if (pd->Attrib & INACTIVE)
beep();
else
{
if (pd->Attrib & TOGGLE)
pd->Attrib ^= CHECKED;
SendMessage(GetDocFocus(), SETFOCUS, TRUE, 0);
PostMessage(GetParent(wnd), COMMAND, pd->ActionId, 0);
}
return;
}
pd++;
}
mnu++;
}
switch ((int)p1)
{
case F1:
if (ActiveMenu == NULL || ActiveMenuBar == NULL)
break;
sel=ActiveMenuBar->ActiveSelection;
if (sel == -1)
{
BaseWndProc(MENUBAR, wnd, KEYBOARD, F1, 0);
return;
}
mnu=ActiveMenu+sel;
if (mwnd == NULL || mnu->Selections[0].SelectionTitle == NULL)
{
DisplayHelp(wnd,mnu->Title);
return;
}
break;
case '\r':
if (mwnd == NULL && ActiveMenuBar->ActiveSelection != -1)
SendMessage(wnd, MB_SELECTION, ActiveMenuBar->ActiveSelection, 0);
break;
case F10:
if (wnd != inFocus && mwnd == NULL)
{
SendMessage(wnd, SETFOCUS, TRUE, 0);
if (ActiveMenuBar->ActiveSelection == -1)
ActiveMenuBar->ActiveSelection=0;
SendMessage(wnd, PAINT, 0, 0);
break;
}
/* Fall through */
case ESC:
if (inFocus == wnd && mwnd == NULL)
{
ActiveMenuBar->ActiveSelection = -1;
SendMessage(GetDocFocus(),SETFOCUS,TRUE,0);
SendMessage(wnd, PAINT, 0, 0);
}
break;
case FWD:
ActiveMenuBar->ActiveSelection++;
if (ActiveMenuBar->ActiveSelection == mctr)
ActiveMenuBar->ActiveSelection=0;
if (mwnd != NULL)
SendMessage(wnd, MB_SELECTION, ActiveMenuBar->ActiveSelection, 0);
else
SendMessage(wnd, PAINT, 0, 0);
break;
case LARROW:
if (ActiveMenuBar->ActiveSelection == 0 || ActiveMenuBar->ActiveSelection == -1)
ActiveMenuBar->ActiveSelection=mctr;
--ActiveMenuBar->ActiveSelection;
if (mwnd != NULL)
SendMessage(wnd, MB_SELECTION, ActiveMenuBar->ActiveSelection, 0);
else
SendMessage(wnd, PAINT, 0, 0);
break;
default:
break;
}
}
/* --------------- LEFT_BUTTON Message ---------- */
static void LeftButtonMsg(WINDOW wnd, PARAM p1)
{
int mx=(int) p1-GetLeft(wnd),i;
/* Compute the selection that the left button hit */
for (i=0;i<mctr;i++)
if (mx >= menu[i].x1-4*i && mx <= menu[i].x2-4*i-5)
break;
if (i < mctr)
if (i != ActiveMenuBar->ActiveSelection || mwnd == NULL)
SendMessage(wnd, MB_SELECTION, i, 0);
}
/* -------------- MB_SELECTION Message -------------- */
static void SelectionMsg(WINDOW wnd, PARAM p1, PARAM p2)
{
int wd,mx,my;
MENU *mnu;
if (!p2)
{
ActiveMenuBar->ActiveSelection = -1;
SendMessage(wnd, PAINT, 0, 0);
}
Selecting=TRUE;
mnu=ActiveMenu+(int)p1;
if (mnu->PrepMenu != NULL)
(*(mnu->PrepMenu))(GetDocFocus(), mnu);
wd=MenuWidth(mnu->Selections);
if (p2)
{
int brd=GetRight(wnd);
mx=GetLeft(mwnd)+WindowWidth(mwnd)-1;
if (mx+wd > brd)
mx=brd-wd;
my=GetTop(mwnd)+mwnd->selection;
}
else
{
int offset=menu[(int)p1].x1-4 * (int)p1;
if (mwnd != NULL)
SendMessage(mwnd, CLOSE_WINDOW, 0, 0);
ActiveMenuBar->ActiveSelection=(int) p1;
if (offset > WindowWidth(wnd)-wd)
offset=WindowWidth(wnd)-wd;
mx=GetLeft(wnd)+offset;
my=GetTop(wnd)+1;
}
mwnd=CreateWindow(POPDOWNMENU, NULL, mx, my, MenuHeight(mnu->Selections), wd, NULL, wnd, NULL, SHADOW);
if (!p2)
{
Selecting=FALSE;
SendMessage(wnd, PAINT, 0, 0);
Selecting=TRUE;
}
if (mnu->Selections[0].SelectionTitle != NULL)
{
SendMessage(mwnd, BUILD_SELECTIONS, (PARAM) mnu, 0);
SendMessage(mwnd, SETFOCUS, TRUE, 0);
SendMessage(mwnd, SHOW_WINDOW, 0, 0);
}
Selecting=FALSE;
}
/* --------- COMMAND Message ---------- */
static void CommandMsg(WINDOW wnd, PARAM p1, PARAM p2)
{
if (p1 == ID_HELP)
{
BaseWndProc(MENUBAR, wnd, COMMAND, p1, p2);
return;
}
if (isCascadedCommand(ActiveMenuBar, (int)p1))
{
/* Find the cascaded menu based on command id in p1 */
MENU *mnu=ActiveMenu+mctr;
while (mnu->Title != (void *)-1)
{
if (mnu->CascadeId == (int) p1)
{
if (casc < MAXCASCADES)
{
Cascaders[casc++]=mwnd;
SendMessage(wnd, MB_SELECTION, (PARAM)(mnu-ActiveMenu), TRUE);
}
break;
}
mnu++;
}
}
else
{
if (mwnd != NULL)
SendMessage(mwnd, CLOSE_WINDOW, 0, 0);
SendMessage(GetDocFocus(), SETFOCUS, TRUE, 0);
PostMessage(GetParent(wnd), COMMAND, p1, p2);
}
}
/* --------------- CLOSE_POPDOWN Message --------------- */
static void ClosePopdownMsg(WINDOW wnd)
{
if (casc > 0)
SendMessage(Cascaders[--casc], CLOSE_WINDOW, 0, 0);
else
{
mwnd=NULL;
ActiveMenuBar->ActiveSelection = -1;
if (!Selecting)
{
SendMessage(GetDocFocus(), SETFOCUS, TRUE, 0);
SendMessage(wnd, PAINT, 0, 0);
}
}
}
/* ---------------- CLOSE_WINDOW Message --------------- */
static void CloseWindowMsg(WINDOW wnd)
{
if (GetText(wnd) != NULL)
{
free(GetText(wnd));
GetText(wnd)=NULL;
}
mctr=0;
ActiveMenuBar->ActiveSelection = -1;
ActiveMenu=NULL;
ActiveMenuBar=NULL;
}
/* --- Window processing module for MENUBAR window class --- */
int MenuBarProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
int rtn;
switch (msg)
{
case CREATE_WINDOW:
reset_menubar(wnd);
break;
case SETFOCUS:
return SetFocusMsg(wnd, p1);
case BUILDMENU:
BuildMenuMsg(wnd, p1);
break;
case PAINT:
if (!isVisible(wnd) || GetText(wnd) == NULL)
break;
PaintMsg(wnd);
return FALSE;
case BORDER:
if (mwnd == NULL)
SendMessage(wnd, PAINT, 0, 0);
return TRUE;
case KEYBOARD:
KeyboardMsg(wnd, p1);
return TRUE;
case LEFT_BUTTON:
LeftButtonMsg(wnd, p1);
return TRUE;
case MB_SELECTION:
SelectionMsg(wnd, p1, p2);
break;
case COMMAND:
CommandMsg(wnd, p1, p2);
return TRUE;
case INSIDE_WINDOW:
return InsideRect(p1, p2, WindowRect(wnd));
case CLOSE_POPDOWN:
ClosePopdownMsg(wnd);
return TRUE;
case CLOSE_WINDOW:
CloseWindowMsg(wnd);
rtn=BaseWndProc(MENUBAR, wnd, msg, p1, p2);
return rtn;
default:
break;
}
return BaseWndProc(MENUBAR, wnd, msg, p1, p2);
}
/* ------------- reset the MENUBAR -------------- */
static void reset_menubar(WINDOW wnd)
{
GetText(wnd)=DFrealloc(GetText(wnd), SCREENWIDTH+5);
memset(GetText(wnd), ' ', SCREENWIDTH);
*(GetText(wnd)+WindowWidth(wnd))='\0';
}
static WINDOW GetDocFocus(void)
{
WINDOW wnd=ApplicationWindow;
if (wnd != NULL)
{
wnd=LastWindow(wnd);
while (wnd != NULL && (GetClass(wnd) == MENUBAR || GetClass(wnd) == STATUSBAR))
wnd=PrevWindow(wnd);
if (wnd != NULL)
while (wnd->childfocus != NULL)
wnd=wnd->childfocus;
}
return wnd ? wnd : ApplicationWindow;
}

View File

@@ -0,0 +1,124 @@
/* -------------- menus.c ------------- */
#include "dflat.h"
/* --------------------- the main menu --------------------- */
DEFMENU(MainMenu)
/* --------------- the File popdown menu ----------------*/
POPDOWN("~File", PrepFileMenu, "Commands for manipulating files")
SELECTION("~New", ID_NEW, CTRL_N, 0)
SELECTION("~Open...", ID_OPEN, CTRL_O, 0)
SEPARATOR
SELECTION("~Save", ID_SAVE, CTRL_S, INACTIVE)
SELECTION("Save ~as...", ID_SAVEAS, 0, INACTIVE)
SELECTION("~Close", ID_CLOSE, CTRL_F4, INACTIVE)
SEPARATOR
SELECTION("~Print", ID_PRINT, 0, INACTIVE)
SELECTION("P~rinter setup...", ID_PRINTSETUP, 0, 0)
SEPARATOR
#ifndef _WIN32 // doesn't have much sense in this enviroment
SELECTION("~DOS Shell", ID_DOS, 0, 0)
#endif
SELECTION("E~xit", ID_EXIT, ALT_X, 0)
ENDPOPDOWN
/* --------------- the Edit popdown menu ----------------*/
POPDOWN("~Edit", PrepEditMenu, "Commands for editing files")
SELECTION("~Undo", ID_UNDO, CTRL_Z, INACTIVE)
SEPARATOR
SELECTION("Cu~t", ID_CUT, CTRL_X, INACTIVE)
SELECTION("~Copy", ID_COPY, CTRL_C, INACTIVE)
SELECTION("~Paste", ID_PASTE, CTRL_V, INACTIVE)
SEPARATOR
SELECTION("Cl~ear", ID_CLEAR, 0, INACTIVE)
SELECTION("~Delete", ID_DELETETEXT, DEL, INACTIVE)
SEPARATOR
SELECTION("Pa~ragraph", ID_PARAGRAPH, ALT_P, INACTIVE)
ENDPOPDOWN
/* --------------- the Search popdown menu ----------------*/
POPDOWN("~Search", PrepSearchMenu, "Search and replace text")
SELECTION("~Find...", ID_SEARCH, CTRL_J, INACTIVE)
SELECTION("~Next", ID_SEARCHNEXT, F3, INACTIVE)
SELECTION("~Replace...",ID_REPLACE, 0, INACTIVE)
ENDPOPDOWN
/* ------------ the Utilities popdown menu --------------- */
POPDOWN("~Utilities", NULL, "Utility programs")
#ifndef NOCALENDAR
SELECTION("~Calendar", ID_CALENDAR, 0, 0)
#endif
ENDPOPDOWN
/* ------------- the Options popdown menu ---------------*/
POPDOWN("~Options", NULL, "Commands for setting editor and display options")
SELECTION("D~isplay...", ID_DISPLAY, 0, 0)
SEPARATOR
#ifdef INCLUDE_LOGGING
SELECTION("~Log messages", ID_LOG, ALT_L, 0)
SEPARATOR
#endif
SELECTION("~Insert", ID_INSERT, INS, TOGGLE)
SELECTION("~Word wrap", ID_WRAP, 0, TOGGLE)
SELECTION("~Tabs ( )", ID_TABS, 0, CASCADED)
SEPARATOR
SELECTION("~Save options", ID_SAVEOPTIONS, 0, 0)
ENDPOPDOWN
/* --------------- the Window popdown menu --------------*/
POPDOWN("~Window", PrepWindowMenu, "Select/close document windows")
SELECTION(NULL, ID_CLOSEALL, 0, 0)
SEPARATOR
SELECTION(NULL, ID_WINDOW, 0, 0)
SELECTION(NULL, ID_WINDOW, 0, 0)
SELECTION(NULL, ID_WINDOW, 0, 0)
SELECTION(NULL, ID_WINDOW, 0, 0)
SELECTION(NULL, ID_WINDOW, 0, 0)
SELECTION(NULL, ID_WINDOW, 0, 0)
SELECTION(NULL, ID_WINDOW, 0, 0)
SELECTION(NULL, ID_WINDOW, 0, 0)
SELECTION(NULL, ID_WINDOW, 0, 0)
SELECTION(NULL, ID_WINDOW, 0, 0)
SELECTION(NULL, ID_WINDOW, 0, 0)
SELECTION("~More Windows...", ID_MOREWINDOWS, 0, 0)
SELECTION(NULL, ID_WINDOW, 0, 0)
ENDPOPDOWN
/* --------------- the Help popdown menu ----------------*/
POPDOWN("~Help", NULL, "Get help...really.")
SELECTION("~Help for help...", ID_HELPHELP, 0, 0)
SELECTION("~Extended help...", ID_EXTHELP, 0, 0)
SELECTION("~Keys help...", ID_KEYSHELP, 0, 0)
SELECTION("Help ~index...", ID_HELPINDEX, 0, 0)
SEPARATOR
SELECTION("~About...", ID_ABOUT, 0, 0)
ENDPOPDOWN
/* ----- cascaded pulldown from Tabs... above ----- */
CASCADED_POPDOWN(ID_TABS, NULL)
SELECTION("~2 tab stops", ID_TAB2, 0, 0)
SELECTION("~4 tab stops", ID_TAB4, 0, 0)
SELECTION("~6 tab stops", ID_TAB6, 0, 0)
SELECTION("~8 tab stops", ID_TAB8, 0, 0)
ENDPOPDOWN
ENDMENU
/* ------------- the System Menu --------------------- */
DEFMENU(SystemMenu)
POPDOWN("System Menu", NULL, NULL)
#ifdef INCLUDE_RESTORE
SELECTION("~Restore", ID_SYSRESTORE, 0, 0 )
#endif
SELECTION("~Move", ID_SYSMOVE, 0, 0 )
SELECTION("~Size", ID_SYSSIZE, 0, 0 )
#ifdef INCLUDE_MINIMIZE
SELECTION("Mi~nimize", ID_SYSMINIMIZE, 0, 0 )
#endif
#ifdef INCLUDE_MAXIMIZE
SELECTION("Ma~ximize", ID_SYSMAXIMIZE, 0, 0 )
#endif
SEPARATOR
SELECTION("~Close", ID_SYSCLOSE, CTRL_F4, 0 )
ENDPOPDOWN
ENDMENU

View File

@@ -0,0 +1,839 @@
/* --------- message.c ---------- */
#include "dflat.h"
#ifndef _WIN32
#define USECBRKHNLDR 1
#endif
static int px = -1, py = -1;
static int pmx = -1, pmy = -1;
static int mx, my;
static int handshaking=0;
static volatile BOOL CriticalError;
BOOL AllocTesting=FALSE,AltDown=FALSE;
jmp_buf AllocError;
/* ---------- event queue ---------- */
static struct events {
MESSAGE event;
int mx;
int my;
} EventQueue[MAXMESSAGES];
/* ---------- message queue --------- */
static struct msgs {
WINDOW wnd;
MESSAGE msg;
PARAM p1;
PARAM p2;
} MsgQueue[MAXMESSAGES];
static int EventQueueOnCtr;
static int EventQueueOffCtr;
static int EventQueueCtr;
static int MsgQueueOnCtr;
static int MsgQueueOffCtr;
static int MsgQueueCtr;
static int lagdelay = FIRSTDELAY;
WINDOW CaptureMouse;
WINDOW CaptureKeyboard;
static BOOL NoChildCaptureMouse;
static BOOL NoChildCaptureKeyboard;
static int doubletimer = 0;
static int delaytimer = 1;
static int clocktimer = 2;
#ifndef _WIN32
static char timerused[3] = {0, 0, 0};
static long unsigned int timerend[3] = {0, 0, 0};
static long unsigned int timerstart[3] = {0, 0, 0};
volatile long unsigned int *biostimer = MK_FP(0x40,0x6c);
#endif
char time_string[] = "12:34pm ";
static WINDOW Cwnd;
static void StopMsg(void);
/* ------- timer interrupt service routine ------- */
/* More complex countdown handling by Eric Auer */
/* Allows us to work without hooking intr. 0x08 */
#ifndef _WIN32
int timed_out(int timer) /* was: countdown 0? */
{
if ((timer > 2) || (timer < 0))
return -1; /* invalid -> always elapsed */
if (timerused[timer] == 0) /* not active at all? */
return 0;
if (timerused[timer] == 2) /* timeout already known? */
return 1;
if ((biostimer[0] < timerstart[timer]) || (biostimer[0] >= timerend[timer]))
{
timerused[timer] = 2; /* countdown elapsed */
return 1;
}
return 0; /* still waiting */
}
int timer_running(int timer) /* was: countdown > 0? */
{
if ((timer > 2) || (timer < 0))
return 0; /* invalid -> never running */
if (timerused[timer] == 1) /* running? */
{
return (1 - timed_out(timer)); /* if not elapsed, running */
}
else
return 0; /* certainly not running */
}
int timer_disabled(int timer) /* was: countdown -1? */
{
if ((timer > 2) || (timer < 0))
return 1; /* invalid -> always disabled */
return (timerused[timer] == 0);
}
void disable_timer(int timer) /* was: countdown = -1 */
{
if ((timer > 2) || (timer < 0))
return;
timerused[timer] = 0;
}
void set_timer(int timer, int secs)
{
if ((timer > 2) || (timer < 0))
return;
timerstart[timer]=biostimer[0];
timerend[timer]=timerstart[timer] + (secs*182UL/10) + 1;
timerused[timer]=1; /* mark as running */
}
void set_timer_ticks(int timer, int ticks)
{
if ((timer > 2) || (timer < 0))
return;
timerstart[timer]=biostimer[0];
timerend[timer]=timerstart[timer] + ticks;
timerused[timer]=1; /* mark as running */
}
#endif
#ifdef OLDCRITERR
static char ermsg[] = "Error accessing drive x:";
#else
static char ermsg[] = "Error accessing drive";
#endif
/* -------- test for critical errors --------- */
int TestCriticalError(void)
{
int rtn = 0;
if (CriticalError)
{
beep();
rtn = 1;
CriticalError = FALSE;
if (TestErrorMessage(ermsg) == FALSE)
rtn = 2;
}
return rtn;
}
/* ------ critical error interrupt service routine ------ */
#ifdef OLDCRITERR
static void interrupt far newcrit(IREGS ir);
static void interrupt far newcrit(IREGS ir)
{
if (!(ir.ax & 0x8000)) /* If any drive affected... */
{
ermsg[sizeof(ermsg)-2]=(ir.ax & 0xff) + 'A';
CriticalError=TRUE; /* ... only then we have a crit. error */
}
ir.ax = 0;
}
#else
int crit_error(void);
/* ----- critical error handler ----- */
int crit_error(void)
{
CriticalError = TRUE;
#ifndef _WIN32
hardretn(-1); /* return an error! */
#endif
return 2; /* is this correct??? */
/* some possibilities: hardresume(1) is retry, */
/* hardresume(2) is abort. Or return to the caller */
/* with a fake function result: hardretn(result) */
}
#endif
static void StopMsg(void)
{
ClearClipboard();
ClearDialogBoxes();
restorecursor();
unhidecursor();
hide_mousecursor();
}
#ifdef USECBRKHNLDR
/* ------ control break handler --------- */
#define ABORT 0
#define CONTINUE 1 /* any non-zero # will continue */
int c_break(void)
{
/* PostMessage(NULL, STOP, 0, 0);
StopMsg();
*/
return CONTINUE; /* JUST IGNORE CTRL BREAK ... */
}
#endif
/* ------------ initialize the message system --------- */
BOOL init_messages(void)
{
AllocTesting = TRUE;
if (setjmp(AllocError) != 0)
{
StopMsg();
return FALSE;
}
resetmouse();
set_mousetravel(0, SCREENWIDTH-1, 0, SCREENHEIGHT-1);
savecursor();
hidecursor();
px = py = -1;
pmx = pmy = -1;
mx = my = 0;
CaptureMouse = CaptureKeyboard = NULL;
NoChildCaptureMouse = FALSE;
NoChildCaptureKeyboard = FALSE;
MsgQueueOnCtr = MsgQueueOffCtr = MsgQueueCtr = 0;
EventQueueOnCtr = EventQueueOffCtr = EventQueueCtr = 0;
#ifdef OLDCRITERR /* old style: hook intr 0x24 manually */
setvect(CRIT, newcrit); /* (vector save/restore not needed here) */
#else
#ifndef _WIN32
harderr(crit_error); /* set critical error handler (dos.h) */
#endif /* handler uses hardretn / hardresume */
#endif
#ifdef USECBRKHNLDR
ctrlbrk(c_break); /* set ctrl break handler (dos.h) */
/* handler returns 0 to abort program */
setcbrk(0); /* 1 = all / 0 = only con calls check */
#endif
PostMessage(NULL,START,0,0);
lagdelay = FIRSTDELAY;
return TRUE;
}
/* ----- post an event and parameters to event queue ---- */
void PostEvent(MESSAGE event, int p1, int p2)
{
if (EventQueueCtr != MAXMESSAGES)
{
EventQueue[EventQueueOnCtr].event = event;
EventQueue[EventQueueOnCtr].mx = p1;
EventQueue[EventQueueOnCtr].my = p2;
if (++EventQueueOnCtr == MAXMESSAGES)
EventQueueOnCtr = 0;
EventQueueCtr++;
}
}
/* ------ collect mouse, clock, and keyboard events ----- */
static void near collect_events(void)
{
static int ShiftKeys=0;
int sk,hr;
struct tm *now;
update_key_buffer();
/* Test for a clock event (one/second) */
if (timed_out(clocktimer))
{
struct COUNTRY thiscountry; /* Country support new 0.8 */
time_t t=time(NULL); /* The current time */
char timesep=':'; /* Default 12:12am separator */
int ampmflag=1;
if (country(0, &thiscountry)) /* dos.h (int 21.38) */
{
timesep=thiscountry.co_tmsep[0];
ampmflag=(thiscountry.co_time == 0); /* 0 ampm 1 24h clock */
}
/* Get the current time */
now=localtime(&t);
hr=now->tm_hour;
if (ampmflag && (hr > 12)) hr -= 12;
if (ampmflag && (hr == 0)) hr = 12;
if (ampmflag)
{
sprintf(time_string, "%2d%c%02d%s", hr, timesep, now->tm_min, ((now->tm_hour > 11) ? "pm " : "am "));
}
else
sprintf(time_string, "%2d%c%02d", hr, timesep, now->tm_min);
set_timer(clocktimer, 1); /* Reset the timer */
#ifdef _WIN32
PostEvent(CLOCKTICK, (int)time_string, 0);
#else
PostEvent(CLOCKTICK, FP_SEG(time_string), FP_OFF(time_string));
#endif
}
/* Keyboard events */
if ((sk=getshift()) != ShiftKeys)
{
ShiftKeys=sk;
/* The shift status changed */
PostEvent(SHIFT_CHANGED, sk, 0);
if (sk & ALTKEY)
AltDown=TRUE;
}
/* Test for keystroke */
if (keyhit())
{
int c=getkey();
AltDown=FALSE;
PostEvent(KEYBOARD, c, sk);
}
/* Test for mouse events */
if (button_releases())
{
/* The button was released */
AltDown=FALSE;
set_timer_ticks(doubletimer, DOUBLETICKS);
PostEvent(BUTTON_RELEASED, mx, my);
disable_timer(delaytimer);
}
get_mouseposition(&mx, &my);
if (mx != px || my != py)
{
px=mx;
py=my;
PostEvent(MOUSE_MOVED, mx, my);
}
if (rightbutton())
{
AltDown=FALSE;
PostEvent(RIGHT_BUTTON, mx, my);
}
if (leftbutton())
{
AltDown=FALSE;
if (mx == pmx && my == pmy)
{
/* Same position as last left button */
if (timer_running(doubletimer))
{
/* Second click before double timeout */
disable_timer(doubletimer);
PostEvent(DOUBLE_CLICK, mx, my);
}
else if (!timer_running(delaytimer))
{
/* Button held down a while */
set_timer_ticks(delaytimer, lagdelay);
lagdelay=DELAYTICKS;
PostEvent(LEFT_BUTTON, mx, my);
}
}
else
{
/* New button press */
disable_timer(doubletimer);
set_timer_ticks(delaytimer, FIRSTDELAY);
lagdelay=DELAYTICKS;
PostEvent(LEFT_BUTTON, mx, my);
pmx=mx;
pmy=my;
}
}
else
lagdelay=FIRSTDELAY;
}
/* ----- post a message and parameters to msg queue ---- */
void PostMessage(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
if (MsgQueueCtr != MAXMESSAGES)
{
MsgQueue[MsgQueueOnCtr].wnd=wnd;
MsgQueue[MsgQueueOnCtr].msg=msg;
MsgQueue[MsgQueueOnCtr].p1=p1;
MsgQueue[MsgQueueOnCtr].p2=p2;
if (++MsgQueueOnCtr == MAXMESSAGES)
MsgQueueOnCtr=0;
MsgQueueCtr++;
}
}
/* --------- send a message to a window ----------- */
int SendMessage(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
int rtn=TRUE,x,y;
#ifdef INCLUDE_LOGGING
LogMessages(wnd, msg, p1, p2);
#endif
if (wnd != NULL)
switch (msg)
{
case PAINT:
case BORDER:
/* Don't send these messages unless the window is visible */
if (isVisible(wnd))
rtn=(*wnd->wndproc)(wnd, msg, p1, p2);
break;
case RIGHT_BUTTON:
case LEFT_BUTTON:
case DOUBLE_CLICK:
case BUTTON_RELEASED:
/* Don't send these messages unless the window is
visible or has captured the mouse */
if (isVisible(wnd) || wnd == CaptureMouse)
rtn=(*wnd->wndproc)(wnd, msg, p1, p2);
break;
case KEYBOARD:
case SHIFT_CHANGED:
/* Don't send these messages unless the window is
visible or has captured the keyboard */
if (!(isVisible(wnd) || wnd == CaptureKeyboard))
break;
default:
rtn=(*wnd->wndproc)(wnd, msg, p1, p2);
break;
}
/* Window processor returned true or the message was sent to no window at all. */
if (rtn != FALSE)
{
/* Process messages that a window sends to the system itself */
switch (msg)
{
case STOP:
StopMsg();
break;
/* Clock messages */
case CAPTURE_CLOCK:
if (Cwnd == NULL)
set_timer(clocktimer, 0);
wnd->PrevClock = Cwnd;
Cwnd = wnd;
break;
case RELEASE_CLOCK:
Cwnd = wnd->PrevClock;
if (Cwnd == NULL)
disable_timer(clocktimer);
break;
/* Keyboard messages */
case KEYBOARD_CURSOR:
if (wnd == NULL)
cursor((int)p1, (int)p2);
else if (wnd == inFocus)
cursor(GetClientLeft(wnd)+(int)p1,GetClientTop(wnd)+(int)p2);
break;
case CAPTURE_KEYBOARD:
if (p2)
((WINDOW)p2)->PrevKeyboard=CaptureKeyboard;
else
wnd->PrevKeyboard = CaptureKeyboard;
CaptureKeyboard=wnd;
NoChildCaptureKeyboard=(int)p1;
break;
case RELEASE_KEYBOARD:
if (wnd != NULL)
{
if (CaptureKeyboard == wnd || (int)p1)
CaptureKeyboard=wnd->PrevKeyboard;
else
{
WINDOW twnd=CaptureKeyboard;
while (twnd != NULL)
{
if (twnd->PrevKeyboard == wnd)
{
twnd->PrevKeyboard=wnd->PrevKeyboard;
break;
}
twnd=twnd->PrevKeyboard;
}
if (twnd == NULL)
CaptureKeyboard = NULL;
}
wnd->PrevKeyboard = NULL;
}
else
CaptureKeyboard = NULL;
NoChildCaptureKeyboard = FALSE;
break;
case CURRENT_KEYBOARD_CURSOR:
curr_cursor(&x, &y);
*(int*)p1=x;
*(int*)p2=y;
break;
case SAVE_CURSOR:
savecursor();
break;
case RESTORE_CURSOR:
restorecursor();
break;
case HIDE_CURSOR:
normalcursor();
hidecursor();
break;
case SHOW_CURSOR:
if (p1)
set_cursor_type(0x0607); /* Û */
else
set_cursor_type(0x0106); /* _ */
unhidecursor();
break;
case WAITKEYBOARD:
waitforkeyboard();
break;
/* Mouse messages */
case RESET_MOUSE:
resetmouse();
set_mousetravel(0, SCREENWIDTH-1, 0, SCREENHEIGHT-1);
break;
case MOUSE_INSTALLED:
rtn=mouse_installed();
break;
case MOUSE_TRAVEL:
{
RECT rc;
if (!p1)
{
rc.lf=rc.tp=0;
rc.rt=SCREENWIDTH-1;
rc.bt=SCREENHEIGHT-1;
}
else
rc=*(RECT *)p1;
set_mousetravel(rc.lf, rc.rt, rc.tp, rc.bt);
break;
}
case SHOW_MOUSE:
show_mousecursor();
break;
case HIDE_MOUSE:
hide_mousecursor();
break;
case MOUSE_CURSOR:
set_mouseposition((int)p1, (int)p2);
break;
case CURRENT_MOUSE_CURSOR:
get_mouseposition((int*)p1,(int*)p2);
break;
case WAITMOUSE:
waitformouse();
break;
case TESTMOUSE:
rtn=mousebuttons();
break;
case CAPTURE_MOUSE:
if (p2)
((WINDOW)p2)->PrevMouse=CaptureMouse;
else
wnd->PrevMouse=CaptureMouse;
CaptureMouse=wnd;
NoChildCaptureMouse=(int)p1;
break;
case RELEASE_MOUSE:
if (wnd != NULL)
{
if (CaptureMouse == wnd || (int)p1)
CaptureMouse=wnd->PrevMouse;
else
{
WINDOW twnd=CaptureMouse;
while (twnd != NULL)
{
if (twnd->PrevMouse == wnd)
{
twnd->PrevMouse=wnd->PrevMouse;
break;
}
twnd=twnd->PrevMouse;
}
if (twnd == NULL)
CaptureMouse = NULL;
}
wnd->PrevMouse = NULL;
}
else
CaptureMouse = NULL;
NoChildCaptureMouse = FALSE;
break;
default:
break;
}
}
return rtn;
}
static RECT VisibleRect(WINDOW wnd)
{
RECT rc=WindowRect(wnd);
if (!TestAttribute(wnd, NOCLIP))
{
WINDOW pwnd=GetParent(wnd);
RECT prc;
if (pwnd != NULL) {
prc=ClientRect(pwnd);
while (pwnd != NULL)
{
if (TestAttribute(pwnd, NOCLIP))
break;
rc=subRectangle(rc, prc);
if (!ValidRect(rc))
break;
if ((pwnd=GetParent(pwnd)) != NULL)
prc=ClientRect(pwnd);
}
}
}
return rc;
}
/* ----- find window that mouse coordinates are in --- */
static WINDOW inWindow(WINDOW wnd, int x, int y)
{
WINDOW Hit=NULL;
while (wnd != NULL)
{
if (isVisible(wnd))
{
WINDOW wnd1;
RECT rc=VisibleRect(wnd);
if (InsideRect(x, y, rc))
Hit=wnd;
if ((wnd1=inWindow(LastWindow(wnd), x, y)) != NULL)
Hit=wnd1;
if (Hit != NULL)
break;
}
wnd=PrevWindow(wnd);
}
return Hit;
}
/* Get the window in which a mouse event occurred */
static WINDOW MouseWindow(int x, int y)
{
WINDOW Mwnd=inWindow(ApplicationWindow, x, y);
/* Process mouse captures ----- */
if (CaptureMouse != NULL)
{
if (NoChildCaptureMouse || Mwnd == NULL || !isAncestor(Mwnd, CaptureMouse))
Mwnd=CaptureMouse;
}
return Mwnd;
}
void handshake(void)
{
handshaking++;
dispatch_message();
--handshaking;
}
/* ---- dispatch messages to the message proc function ---- */
BOOL dispatch_message(void)
{
WINDOW Mwnd, Kwnd;
collect_events(); /* Collect mouse and keyboard events */
/* Dequeue and process events */
while (EventQueueCtr > 0)
{
struct events ev;
ev = EventQueue[EventQueueOffCtr];
if (++EventQueueOffCtr == MAXMESSAGES)
EventQueueOffCtr = 0;
--EventQueueCtr;
/* Get the window in which a keyboard event occurred */
Kwnd=inFocus;
/* Process keyboard captures */
if (CaptureKeyboard != NULL)
if (Kwnd == NULL || NoChildCaptureKeyboard || !isAncestor(Kwnd, CaptureKeyboard))
Kwnd = CaptureKeyboard;
/* Send mouse and keyboard messages to the window that should get them */
switch (ev.event)
{
case SHIFT_CHANGED:
case KEYBOARD:
if (!handshaking)
SendMessage(Kwnd, ev.event, ev.mx, ev.my);
break;
case LEFT_BUTTON:
if (!handshaking)
{
Mwnd=MouseWindow(ev.mx, ev.my);
if (!CaptureMouse || (!NoChildCaptureMouse && isAncestor(Mwnd, CaptureMouse)))
if (Mwnd != inFocus)
SendMessage(Mwnd, SETFOCUS, TRUE, 0);
SendMessage(Mwnd, LEFT_BUTTON, ev.mx, ev.my);
}
break;
case BUTTON_RELEASED:
case DOUBLE_CLICK:
case RIGHT_BUTTON:
if (handshaking)
break;
case MOUSE_MOVED:
Mwnd=MouseWindow(ev.mx, ev.my);
SendMessage(Mwnd, ev.event, ev.mx, ev.my);
break;
case CLOCKTICK:
#ifdef _WIN32
SendMessage(Cwnd, ev.event,ev.mx, 0);
#else
SendMessage(Cwnd, ev.event,(PARAM) MK_FP(ev.mx, ev.my), 0);
#endif
break;
default:
break;
}
}
/* Dequeue and process messages */
while (MsgQueueCtr > 0)
{
struct msgs mq;
mq=MsgQueue[MsgQueueOffCtr];
if (++MsgQueueOffCtr == MAXMESSAGES)
MsgQueueOffCtr=0;
--MsgQueueCtr;
SendMessage(mq.wnd, mq.msg, mq.p1, mq.p2);
if (mq.msg == ENDDIALOG)
return FALSE;
if (mq.msg == STOP)
{
PostMessage(NULL, STOP, 0, 0);
return FALSE;
}
}
return TRUE;
}

View File

@@ -0,0 +1,110 @@
/* ------------- mouse.c ------------- */
#include "dflat.h"
static union REGS regs;
static struct SREGS sregs;
static void near mouse(int m1,int m2,int m3,int m4)
{
regs.x.dx = m4;
regs.x.cx = m3;
regs.x.bx = m2;
regs.x.ax = m1;
int86x(MOUSE, &regs, &regs, &sregs);
}
/* ---------- reset the mouse ---------- */
void resetmouse(void)
{
segread(&sregs);
mouse(0,0,0,0);
}
/* ----- test to see if the mouse driver is installed ----- */
BOOL mouse_installed(void)
{
unsigned char far *ms;
ms = MK_FP(peek(0, MOUSE*4+2), peek(0, MOUSE*4));
return (SCREENWIDTH <= 80 && ms != NULL && *ms != 0xcf);
}
/* ------ return true if mouse buttons are pressed ------- */
int mousebuttons(void)
{
if (mouse_installed()) {
segread(&sregs);
mouse(3,0,0,0);
return regs.x.bx & 3;
}
return 0;
}
/* ---------- return mouse coordinates ---------- */
void get_mouseposition(int *x, int *y)
{
*x = *y = -1;
if (mouse_installed()) {
segread(&sregs);
mouse(3,0,0,0);
*x = regs.x.cx/8;
*y = regs.x.dx/8;
if (SCREENWIDTH == 40)
*x /= 2;
}
}
/* -------- position the mouse cursor -------- */
void set_mouseposition(int x, int y)
{
if (mouse_installed()) {
segread(&sregs);
if (SCREENWIDTH == 40)
x *= 2;
mouse(4,0,x*8,y*8);
}
}
/* --------- display the mouse cursor -------- */
void show_mousecursor(void)
{
if (mouse_installed()) {
segread(&sregs);
mouse(1,0,0,0);
}
}
/* --------- hide the mouse cursor ------- */
void hide_mousecursor(void)
{
if (mouse_installed()) {
segread(&sregs);
mouse(2,0,0,0);
}
}
/* --- return true if a mouse button has been released --- */
int button_releases(void)
{
if (mouse_installed()) {
segread(&sregs);
mouse(6,0,0,0);
return regs.x.bx;
}
return 0;
}
/* ----- set mouse travel limits ------- */
void set_mousetravel(int minx, int maxx, int miny, int maxy)
{
if (mouse_installed()) {
if (SCREENWIDTH == 40) {
minx *= 2;
maxx *= 2;
}
segread(&sregs);
mouse(7, 0, minx*8, maxx*8);
mouse(8, 0, miny*8, maxy*8);
}
}

View File

@@ -0,0 +1,248 @@
/* ------------------ msgbox.c ------------------ */
#include "dflat.h"
extern DBOX MsgBox;
extern DBOX InputBoxDB;
WINDOW CancelWnd;
static int ReturnValue;
static int TextLength;
static char *InputText;
int MessageBoxProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
switch (msg)
{
case CREATE_WINDOW:
GetClass(wnd) = MESSAGEBOX;
InitWindowColors(wnd);
ClearAttribute(wnd, CONTROLBOX);
break;
case KEYBOARD:
if (p1 == '\r' || p1 == ESC)
ReturnValue = (int)p1;
break;
default:
break;
}
return BaseWndProc(MESSAGEBOX, wnd, msg, p1, p2);
}
int YesNoBoxProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
switch (msg)
{
case CREATE_WINDOW:
GetClass(wnd) = MESSAGEBOX;
InitWindowColors(wnd);
ClearAttribute(wnd, CONTROLBOX);
break;
case KEYBOARD:
{
int c = tolower((int)p1);
if (c == 'y')
SendMessage(wnd, COMMAND, ID_OK, 0);
else if (c == 'n')
SendMessage(wnd, COMMAND, ID_CANCEL, 0);
break;
}
default:
break;
}
return BaseWndProc(MESSAGEBOX, wnd, msg, p1, p2);
}
int ErrorBoxProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
switch (msg)
{
case CREATE_WINDOW:
GetClass(wnd) = ERRORBOX;
InitWindowColors(wnd);
break;
case KEYBOARD:
if (p1 == '\r' || p1 == ESC)
ReturnValue = (int)p1;
break;
default:
break;
}
return BaseWndProc(ERRORBOX, wnd, msg, p1, p2);
}
int CancelBoxProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
switch (msg)
{
case CREATE_WINDOW:
CancelWnd = wnd;
SendMessage(wnd, CAPTURE_MOUSE, 0, 0);
SendMessage(wnd, CAPTURE_KEYBOARD, 0, 0);
break;
case COMMAND:
if ((int) p1 == ID_CANCEL && (int) p2 == 0)
SendMessage(GetParent(wnd), msg, p1, p2);
return TRUE;
case CLOSE_WINDOW:
CancelWnd = NULL;
SendMessage(wnd, RELEASE_MOUSE, 0, 0);
SendMessage(wnd, RELEASE_KEYBOARD, 0, 0);
p1 = TRUE;
break;
default:
break;
}
return BaseWndProc(MESSAGEBOX, wnd, msg, p1, p2);
}
void CloseCancelBox(void)
{
if (CancelWnd != NULL)
SendMessage(CancelWnd, CLOSE_WINDOW, 0, 0);
}
int InputBoxProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
int rtn;
switch (msg)
{
case CREATE_WINDOW:
rtn = DefaultWndProc(wnd, msg, p1, p2);
SendMessage(ControlWindow(&InputBoxDB,ID_INPUTTEXT),
SETTEXTLENGTH, TextLength, 0);
SendMessage(ControlWindow(&InputBoxDB,ID_INPUTTEXT),
ADDTEXT, (PARAM) InputText, 0);
return rtn;
case COMMAND:
if ((int) p1 == ID_OK && (int) p2 == 0)
GetItemText(wnd, ID_INPUTTEXT, InputText, TextLength);
break;
default:
break;
}
return DefaultWndProc(wnd, msg, p1, p2);
}
BOOL InputBox(WINDOW wnd,char *ttl,char *msg,char *text,int len,int wd)
{
int ln = wd ? wd : len;
ln=min(SCREENWIDTH-8, ln);
InputText=text;
TextLength=len;
InputBoxDB.dwnd.title=ttl;
InputBoxDB.dwnd.w=4+max(20, max(ln, max(strlen(ttl), strlen(msg))));
InputBoxDB.ctl[1].dwnd.x = (InputBoxDB.dwnd.w-2-ln)/2;
InputBoxDB.ctl[0].dwnd.w = strlen(msg);
InputBoxDB.ctl[0].itext = msg;
InputBoxDB.ctl[1].itext = NULL;
InputBoxDB.ctl[1].dwnd.w = ln;
InputBoxDB.ctl[2].dwnd.x = (InputBoxDB.dwnd.w - 20) / 2;
InputBoxDB.ctl[3].dwnd.x = InputBoxDB.ctl[2].dwnd.x + 10;
InputBoxDB.ctl[2].isetting = ON;
InputBoxDB.ctl[3].isetting = ON;
return DialogBox(wnd, &InputBoxDB, TRUE, InputBoxProc);
}
BOOL GenericMessage(WINDOW wnd,char *ttl,char *msg,int buttonct,
int (*wndproc)(struct window *,enum messages,PARAM,PARAM),
char *b1, char *b2, int c1, int c2, int isModal)
{
BOOL rtn;
MsgBox.dwnd.title = ttl;
MsgBox.ctl[0].dwnd.h = MsgHeight(msg);
MsgBox.ctl[0].dwnd.w = max(max(MsgWidth(msg), buttonct*8 + buttonct + 2), strlen(ttl)+2);
MsgBox.dwnd.h = MsgBox.ctl[0].dwnd.h+6;
MsgBox.dwnd.w = MsgBox.ctl[0].dwnd.w+4;
if (buttonct == 1)
MsgBox.ctl[1].dwnd.x = (MsgBox.dwnd.w - 10) / 2;
else
{
MsgBox.ctl[1].dwnd.x = (MsgBox.dwnd.w - 20) / 2;
MsgBox.ctl[2].dwnd.x = MsgBox.ctl[1].dwnd.x + 10;
MsgBox.ctl[2].Class = BUTTON;
}
MsgBox.ctl[1].dwnd.y = MsgBox.dwnd.h - 4;
MsgBox.ctl[2].dwnd.y = MsgBox.dwnd.h - 4;
MsgBox.ctl[0].itext = msg;
MsgBox.ctl[1].itext = b1;
MsgBox.ctl[2].itext = b2;
MsgBox.ctl[1].command = c1;
MsgBox.ctl[2].command = c2;
MsgBox.ctl[1].isetting = ON;
MsgBox.ctl[2].isetting = ON;
rtn = DialogBox(wnd, &MsgBox, isModal, wndproc);
MsgBox.ctl[2].Class = 0;
return rtn;
}
WINDOW MomentaryMessage(char *msg)
{
WINDOW wnd = CreateWindow(TEXTBOX,NULL,-1,-1,MsgHeight(msg)+2,MsgWidth(msg)+2,NULL,NULL,NULL,HASBORDER | SHADOW | SAVESELF);
SendMessage(wnd, SETTEXT, (PARAM) msg, 0);
if (cfg.mono == 0)
{
WindowClientColor(wnd, WHITE, GREEN);
WindowFrameColor(wnd, WHITE, GREEN);
}
SendMessage(wnd, SHOW_WINDOW, 0, 0);
return wnd;
}
int MsgHeight(char *msg)
{
int h=1;
while ((msg = strchr(msg, '\n')) != NULL)
{
h++;
msg++;
}
return min(h, SCREENHEIGHT-10);
}
int MsgWidth(char *msg)
{
int w=0;
char *cp=msg;
while ((cp=strchr(msg, '\n')) != NULL)
{
w=max(w, (int) (cp-msg));
msg=cp+1;
}
return min(max(strlen(msg),w), SCREENWIDTH-10);
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1 @@
Object files will be placed here.

View File

@@ -0,0 +1,283 @@
/* -------------- pictbox.c -------------- */
#include "dflat.h"
typedef struct {
enum VectTypes vt;
RECT rc;
} VECT;
unsigned char CharInWnd[] = "ijڿÙÀÅôÁÂ";
unsigned char VectCvt[3][11][2][4] = {
{ /* --- first character in collision vector --- */
/* ( drawing Ä ) ( drawing ³ ) */
{{"ÄÄÄ"}, {"ÚÃÀ"}},
{{"Ú¿"}, {"³³³"}},
{{"ÚÂÂ"}, {"ÚÃÃ"}},
{{"¿¿¿"}, {"¿¿¿"}},
{{"ÙÙÙ"}, {"ÙÙÙ"}},
{{"ÀÁÁ"}, {"ÃÃÀ"}},
{{"ÅÅÅ"}, {"ÅÅÅ"}},
{{"ÃÅÅ"}, {"ÃÃÃ"}},
{{"´´´"}, {"´´´"}},
{{"ÁÁÁ"}, {"ÁÁÁ"}},
{{"ÂÂÂ"}, {"ÂÅÅ"}} },
{ /* --- middle character in collision vector --- */
/* ( drawing Ä ) ( drawing ³ ) */
{{"ÄÄÄ"}, {"ÂÅÁ"}},
{{"ÃÅ´"}, {"³³³"}},
{{"ÚÚÚ"}, {"ÚÚÚ"}},
{{"¿¿¿"}, {"¿¿¿"}},
{{"ÙÙÙ"}, {"ÙÙÙ"}},
{{"ÀÀÀ"}, {"ÀÀÀ"}},
{{"ÅÅÅ"}, {"ÅÅÅ"}},
{{"ÃÃÃ"}, {"ÃÃÃ"}},
{{"ÅÅ´"}, {"´´´"}},
{{"ÁÁÁ"}, {"ÅÅÁ"}},
{{"ÂÂÂ"}, {"ÂÂÂ"}} },
{ /* --- last character in collision vector --- */
/* ( drawing Ä ) ( drawing ³ ) */
{{"ÄÄÄ"}, {"¿´Ù"}},
{{"ÀÁÙ"}, {"³³³"}},
{{"ÚÚÚ"}, {"ÚÚÚ"}},
{{"¿"}, {"¿´´"}},
{{"ÁÁÙ"}, {"´´Ù"}},
{{"ÀÀÀ"}, {"ÀÀÀ"}},
{{"ÅÅÅ"}, {"ÅÅÅ"}},
{{"ÃÃÃ"}, {"ÃÃÃ"}},
{{"ÅÅ´"}, {"´´´"}},
{{"ÁÁÁ"}, {"ÅÅÁ"}},
{{"ÂÂÂ"}, {"ÂÂÂ"}} }
};
/* -- compute whether character is first, middle, or last -- */
static int FindVector(WINDOW wnd, RECT rc, int x, int y)
{
RECT rcc;
VECT *vc = wnd->VectorList;
int i, coll = -1;
for (i = 0; i < wnd->VectorCount; i++) {
if ((vc+i)->vt == VECTOR) {
rcc = (vc+i)->rc;
/* --- skip the colliding vector --- */
if (rcc.lf == rc.lf && rcc.rt == rc.rt &&
rcc.tp == rc.tp && rc.bt == rcc.bt)
continue;
if (rcc.tp == rcc.bt) {
/* ---- horizontal vector,
see if character is in it --- */
if (rc.lf+x >= rcc.lf && rc.lf+x <= rcc.rt &&
rc.tp+y == rcc.tp) {
/* --- it is --- */
if (rc.lf+x == rcc.lf)
coll = 0;
else if (rc.lf+x == rcc.rt)
coll = 2;
else
coll = 1;
}
}
else {
/* ---- vertical vector,
see if character is in it --- */
if (rc.tp+y >= rcc.tp && rc.tp+y <= rcc.bt &&
rc.lf+x == rcc.lf) {
/* --- it is --- */
if (rc.tp+y == rcc.tp)
coll = 0;
else if (rc.tp+y == rcc.bt)
coll = 2;
else
coll = 1;
}
}
}
}
return coll;
}
static void PaintVector(WINDOW wnd, RECT rc)
{
int i, xi, yi, len;
unsigned int ch, nc;
unsigned int newch;
static int cw, fml, vertvect, coll;
if (rc.rt == rc.lf) {
/* ------ vertical vector ------- */
nc = '³';
vertvect = 1;
len = rc.bt-rc.tp+1;
}
else {
/* ------ horizontal vector ------- */
nc = 'Ä';
vertvect = 0;
len = rc.rt-rc.lf+1;
}
for (i = 0; i < len; i++) {
newch = nc;
xi = yi = 0;
if (vertvect)
yi = i;
else
xi = i;
ch = videochar(GetClientLeft(wnd)+rc.lf+xi,
GetClientTop(wnd)+rc.tp+yi);
for (cw = 0; cw < sizeof(CharInWnd); cw++) {
if (ch == CharInWnd[cw]) {
/* ---- hit another vector character ---- */
if ((coll=FindVector(wnd, rc, xi, yi)) != -1) {
/* compute first/middle/last subscript */
if (i == len-1)
fml = 2;
else if (i == 0)
fml = 0;
else
fml = 1;
newch = VectCvt[coll][cw][vertvect][fml];
}
}
}
PutWindowChar(wnd, newch, rc.lf+xi, rc.tp+yi);
}
}
static void PaintBar(WINDOW wnd, RECT rc, enum VectTypes vt)
{
int i, vertbar, len;
unsigned int tys[] = {219, 178, 177, 176};
/* unsigned int tys[] = {'Û', '²', '±', '°'};
*/
unsigned int nc = tys[vt-1];
if (rc.rt == rc.lf) {
/* ------ vertical bar ------- */
vertbar = 1;
len = rc.bt-rc.tp+1;
}
else {
/* ------ horizontal bar ------- */
vertbar = 0;
len = rc.rt-rc.lf+1;
}
for (i = 0; i < len; i++) {
int xi = 0, yi = 0;
if (vertbar)
yi = i;
else
xi = i;
PutWindowChar(wnd, nc, rc.lf+xi, rc.tp+yi);
}
}
static void PaintMsg(WINDOW wnd)
{
int i;
VECT *vc = wnd->VectorList;
for (i = 0; i < wnd->VectorCount; i++) {
if (vc->vt == VECTOR)
PaintVector(wnd, vc->rc);
else
PaintBar(wnd, vc->rc, vc->vt);
vc++;
}
}
static void DrawVectorMsg(WINDOW wnd,PARAM p1,enum VectTypes vt)
{
if (p1) {
VECT vc;
wnd->VectorList = DFrealloc(wnd->VectorList,
sizeof(VECT) * (wnd->VectorCount + 1));
vc.vt = vt;
vc.rc = *(RECT *)p1;
*(((VECT *)(wnd->VectorList))+wnd->VectorCount)=vc;
wnd->VectorCount++;
}
}
static void DrawBoxMsg(WINDOW wnd, PARAM p1)
{
if (p1) {
RECT rc = *(RECT *)p1;
rc.bt = rc.tp;
SendMessage(wnd, DRAWVECTOR, (PARAM) &rc, TRUE);
rc = *(RECT *)p1;
rc.lf = rc.rt;
SendMessage(wnd, DRAWVECTOR, (PARAM) &rc, FALSE);
rc = *(RECT *)p1;
rc.tp = rc.bt;
SendMessage(wnd, DRAWVECTOR, (PARAM) &rc, TRUE);
rc = *(RECT *)p1;
rc.rt = rc.lf;
SendMessage(wnd, DRAWVECTOR, (PARAM) &rc, FALSE);
}
}
int PictureProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
switch (msg) {
case PAINT:
BaseWndProc(PICTUREBOX, wnd, msg, p1, p2);
PaintMsg(wnd);
return TRUE;
case DRAWVECTOR:
DrawVectorMsg(wnd, p1, VECTOR);
return TRUE;
case DRAWBOX:
DrawBoxMsg(wnd, p1);
return TRUE;
case DRAWBAR:
DrawVectorMsg(wnd, p1, (enum VectTypes)p2);
return TRUE;
case CLOSE_WINDOW:
if (wnd->VectorList != NULL)
free(wnd->VectorList);
break;
default:
break;
}
return BaseWndProc(PICTUREBOX, wnd, msg, p1, p2);
}
static RECT PictureRect(int x, int y, int len, int hv)
{
RECT rc;
rc.lf = rc.rt = x;
rc.tp = rc.bt = y;
if (hv)
/* ---- horizontal vector ---- */
rc.rt += len-1;
else
/* ---- vertical vector ---- */
rc.bt += len-1;
return rc;
}
void DrawVector(WINDOW wnd, int x, int y, int len, int hv)
{
RECT rc = PictureRect(x,y,len,hv);
SendMessage(wnd, DRAWVECTOR, (PARAM) &rc, 0);
}
void DrawBox(WINDOW wnd, int x, int y, int ht, int wd)
{
RECT rc;
rc.lf = x;
rc.tp = y;
rc.rt = x+wd-1;
rc.bt = y+ht-1;
SendMessage(wnd, DRAWBOX, (PARAM) &rc, 0);
}
void DrawBar(WINDOW wnd,enum VectTypes vt,
int x,int y,int len,int hv)
{
RECT rc = PictureRect(x,y,len,hv);
SendMessage(wnd, DRAWBAR, (PARAM) &rc, (PARAM) vt);
}

View File

@@ -0,0 +1,423 @@
/* ------------- popdown.c ----------- */
#include "dflat.h"
static int SelectionWidth(struct PopDown *);
static int py = -1;
int CurrentMenuSelection;
/* ------------ CREATE_WINDOW Message ------------- */
static int CreateWindowMsg(WINDOW wnd)
{
int rtn, adj;
ClearAttribute(wnd, HASTITLEBAR |
VSCROLLBAR |
MOVEABLE |
SIZEABLE |
HSCROLLBAR);
/* ------ adjust to keep popdown on screen ----- */
adj = SCREENHEIGHT-1-wnd->rc.bt;
if (adj < 0) {
wnd->rc.tp += adj;
wnd->rc.bt += adj;
}
adj = SCREENWIDTH-1-wnd->rc.rt;
if (adj < 0) {
wnd->rc.lf += adj;
wnd->rc.rt += adj;
}
rtn = BaseWndProc(POPDOWNMENU, wnd, CREATE_WINDOW, 0, 0);
SendMessage(wnd, CAPTURE_MOUSE, 0, 0);
SendMessage(wnd, CAPTURE_KEYBOARD, 0, 0);
SendMessage(NULL, SAVE_CURSOR, 0, 0);
SendMessage(NULL, HIDE_CURSOR, 0, 0);
wnd->oldFocus = inFocus;
inFocus = wnd;
return rtn;
}
/* --------- LEFT_BUTTON Message --------- */
static void LeftButtonMsg(WINDOW wnd, PARAM p1, PARAM p2)
{
int my = (int) p2 - GetTop(wnd);
if (InsideRect(p1, p2, ClientRect(wnd))) {
if (my != py) {
SendMessage(wnd, LB_SELECTION,
(PARAM) wnd->wtop+my-1, TRUE);
py = my;
}
}
else if ((int)p2 == GetTop(GetParent(wnd)))
if (GetClass(GetParent(wnd)) == MENUBAR)
PostMessage(GetParent(wnd), LEFT_BUTTON, p1, p2);
}
/* -------- BUTTON_RELEASED Message -------- */
static BOOL ButtonReleasedMsg(WINDOW wnd, PARAM p1, PARAM p2)
{
py = -1;
if (InsideRect((int)p1, (int)p2, ClientRect(wnd))) {
int sel = (int)p2 - GetClientTop(wnd);
if (*TextLine(wnd, sel) != LINE)
SendMessage(wnd, LB_CHOOSE, wnd->selection, 0);
}
else {
WINDOW pwnd = GetParent(wnd);
if (GetClass(pwnd) == MENUBAR && (int)p2==GetTop(pwnd))
return FALSE;
if ((int)p1 == GetLeft(pwnd)+2)
return FALSE;
SendMessage(wnd, CLOSE_WINDOW, 0, 0);
return TRUE;
}
return FALSE;
}
/* --------- PAINT Message -------- */
static void PaintMsg(WINDOW wnd)
{
int wd;
unsigned char sep[80],*cp=sep,sel[80];
struct PopDown *ActivePopDown,*pd1;
ActivePopDown = pd1 = wnd->mnu->Selections;
wd = MenuWidth(ActivePopDown)-2;
while (wd--)
*cp++ = LINE;
*cp = '\0';
SendMessage(wnd, CLEARTEXT, 0, 0);
wnd->selection = wnd->mnu->Selection;
while (pd1->SelectionTitle != NULL)
{
if (*pd1->SelectionTitle == LINE)
SendMessage(wnd, ADDTEXT, (PARAM) sep, 0);
else
{
int len;
memset(sel, '\0', sizeof sel);
if (pd1->Attrib & INACTIVE)
/* ------ inactive menu selection ----- */
sprintf(sel, "%c%c%c", CHANGECOLOR, wnd->WindowColors [HILITE_COLOR] [FG]|0x80, wnd->WindowColors [STD_COLOR] [BG]|0x80);
strcat(sel, " ");
if (pd1->Attrib & CHECKED)
/* ---- paint the toggle checkmark ---- */
sel[strlen(sel)-1] = CHECKMARK;
len=CopyCommand(sel+strlen(sel),pd1->SelectionTitle, pd1->Attrib & INACTIVE, wnd->WindowColors [STD_COLOR] [BG]);
if (pd1->Accelerator)
{
/* ---- paint accelerator key ---- */
int i,wd1=2+SelectionWidth(ActivePopDown)-strlen(pd1->SelectionTitle),key=pd1->Accelerator;
if (key > 0 && key < 27)
{
/* --- CTRL+ key --- */
while (wd1--)
strcat(sel, " ");
sprintf(sel+strlen(sel), "Ctrl+%c", key-1+'A');
}
else
{
for (i = 0; keys[i].keylabel; i++)
{
if (keys[i].keycode == key)
{
while (wd1--)
strcat(sel, " ");
sprintf(sel+strlen(sel), "%s",
keys[i].keylabel);
break;
}
}
}
}
if (pd1->Attrib & CASCADED)
{
/* ---- paint cascaded menu token ---- */
if (!pd1->Accelerator)
{
wd = MenuWidth(ActivePopDown)-len+1;
while (wd--)
strcat(sel, " ");
}
sel[strlen(sel)-1] = CASCADEPOINTER;
}
else
strcat(sel, " ");
strcat(sel, " ");
sel[strlen(sel)-1] = RESETCOLOR;
SendMessage(wnd, ADDTEXT, (PARAM) sel, 0);
}
pd1++;
}
}
/* ---------- BORDER Message ----------- */
static int BorderMsg(WINDOW wnd)
{
int i, rtn = TRUE;
WINDOW currFocus;
if (wnd->mnu != NULL) {
currFocus = inFocus;
inFocus = NULL;
rtn = BaseWndProc(POPDOWNMENU, wnd, BORDER, 0, 0);
inFocus = currFocus;
for (i = 0; i < ClientHeight(wnd); i++) {
if (*TextLine(wnd, i) == LINE) {
wputch(wnd, LEDGE, 0, i+1);
wputch(wnd, REDGE, WindowWidth(wnd)-1, i+1);
}
}
}
return rtn;
}
/* -------------- LB_CHOOSE Message -------------- */
static void LBChooseMsg(WINDOW wnd, PARAM p1)
{
struct PopDown *ActivePopDown = wnd->mnu->Selections;
if (ActivePopDown != NULL)
{
int *attr = &(ActivePopDown+(int)p1)->Attrib;
wnd->mnu->Selection = (int)p1;
if (!(*attr & INACTIVE))
{
WINDOW pwnd = GetParent(wnd);
if (*attr & TOGGLE)
*attr ^= CHECKED;
if (pwnd != NULL)
{
CurrentMenuSelection = (int)p1;
PostMessage(pwnd, COMMAND, (ActivePopDown+(int)p1)->ActionId, 0);
}
}
else
beep();
}
}
/* ---------- KEYBOARD Message --------- */
static BOOL KeyboardMsg(WINDOW wnd, PARAM p1, PARAM p2)
{
struct PopDown *ActivePopDown = wnd->mnu->Selections;
if (wnd->mnu != NULL) {
if (ActivePopDown != NULL) {
int c = (int)p1;
int sel = 0;
int a;
struct PopDown *pd = ActivePopDown;
if ((c & FKEY) == 0)
c = tolower(c);
a = AltConvert(c);
while (pd->SelectionTitle != NULL) {
char *cp = strchr(pd->SelectionTitle,
SHORTCUTCHAR);
if (cp != NULL) {
int sc = tolower(*(cp+1));
if ((cp && sc == c) ||
(a && sc == a) ||
pd->Accelerator == c) {
PostMessage(wnd, LB_SELECTION, sel, 0);
PostMessage(wnd, LB_CHOOSE, sel, TRUE);
return TRUE;
}
}
pd++, sel++;
}
}
}
switch ((int)p1) {
case F1:
if (ActivePopDown == NULL)
SendMessage(GetParent(wnd), KEYBOARD, p1, p2);
else
DisplayHelp(wnd,
(ActivePopDown+wnd->selection)->help);
return TRUE;
case ESC:
SendMessage(wnd, CLOSE_WINDOW, 0, 0);
return TRUE;
case FWD:
case LARROW:
if (GetClass(GetParent(wnd)) == MENUBAR)
PostMessage(GetParent(wnd), KEYBOARD, p1, p2);
return TRUE;
case UP:
if (wnd->selection == 0) {
if (wnd->wlines == ClientHeight(wnd)) {
PostMessage(wnd, LB_SELECTION,
wnd->wlines-1, FALSE);
return TRUE;
}
}
break;
case DN:
if (wnd->selection == wnd->wlines-1) {
if (wnd->wlines == ClientHeight(wnd)) {
PostMessage(wnd, LB_SELECTION, 0, FALSE);
return TRUE;
}
}
break;
case HOME:
case END:
case '\r':
break;
default:
return TRUE;
}
return FALSE;
}
/* ----------- CLOSE_WINDOW Message ---------- */
static int CloseWindowMsg(WINDOW wnd)
{
int rtn;
WINDOW pwnd = GetParent(wnd);
SendMessage(wnd, RELEASE_MOUSE, 0, 0);
SendMessage(wnd, RELEASE_KEYBOARD, 0, 0);
SendMessage(NULL, RESTORE_CURSOR, 0, 0);
inFocus = wnd->oldFocus;
rtn = BaseWndProc(POPDOWNMENU, wnd, CLOSE_WINDOW, 0, 0);
SendMessage(pwnd, CLOSE_POPDOWN, 0, 0);
return rtn;
}
/* - Window processing module for POPDOWNMENU window class - */
int PopDownProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
switch (msg) {
case CREATE_WINDOW:
return CreateWindowMsg(wnd);
case LEFT_BUTTON:
LeftButtonMsg(wnd, p1, p2);
return FALSE;
case DOUBLE_CLICK:
return TRUE;
case LB_SELECTION:
/* Check if the sub menu is empty */
if (wnd->text == NULL || wnd->TextPointers == NULL)
return TRUE;
if (*TextLine(wnd, (int)p1) == LINE)
return TRUE;
wnd->mnu->Selection = (int)p1;
break;
case BUTTON_RELEASED:
if (ButtonReleasedMsg(wnd, p1, p2))
return TRUE;
break;
case BUILD_SELECTIONS:
wnd->mnu = (void *) p1;
wnd->selection = wnd->mnu->Selection;
break;
case PAINT:
if (wnd->mnu == NULL)
return TRUE;
PaintMsg(wnd);
break;
case BORDER:
return BorderMsg(wnd);
case LB_CHOOSE:
LBChooseMsg(wnd, p1);
return TRUE;
case KEYBOARD:
if (KeyboardMsg(wnd, p1, p2))
return TRUE;
break;
case CLOSE_WINDOW:
return CloseWindowMsg(wnd);
default:
break;
}
return BaseWndProc(POPDOWNMENU, wnd, msg, p1, p2);
}
/* --------- compute menu height -------- */
int MenuHeight(struct PopDown *pd)
{
int ht = 0;
while (pd[ht].SelectionTitle != NULL)
ht++;
return ht+2;
}
/* --------- compute menu width -------- */
int MenuWidth(struct PopDown *pd)
{
int wd = 0, i;
int len = 0;
wd = SelectionWidth(pd);
while (pd->SelectionTitle != NULL) {
if (pd->Accelerator) {
for (i = 0; keys[i].keylabel; i++)
if (keys[i].keycode == pd->Accelerator) {
len = max(len, 2+strlen(keys[i].keylabel));
break;
}
}
if (pd->Attrib & CASCADED)
len = max(len, 2);
pd++;
}
return wd+5+len;
}
/* ---- compute the maximum selection width in a menu ---- */
static int SelectionWidth(struct PopDown *pd)
{
int wd = 0;
while (pd->SelectionTitle != NULL) {
int len = strlen(pd->SelectionTitle)-1;
wd = max(wd, len);
pd++;
}
return wd;
}
/* ----- copy a menu command to a display buffer ---- */
int CopyCommand(unsigned char *dest, unsigned char *src,
int skipcolor, int bg)
{
unsigned char *d = dest;
while (*src && *src != '\n') {
if (*src == SHORTCUTCHAR) {
src++;
if (!skipcolor) {
*dest++ = CHANGECOLOR;
*dest++ = cfg.clr[POPDOWNMENU]
[HILITE_COLOR] [BG] | 0x80;
*dest++ = bg | 0x80;
*dest++ = *src++;
*dest++ = RESETCOLOR;
}
}
else
*dest++ = *src++;
}
return (int) (dest - d);
}

View File

@@ -0,0 +1,112 @@
/* -------- radio.c -------- */
#include "dflat.h"
static CTLWINDOW *rct[MAXRADIOS];
int RadioButtonProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
int rtn;
DBOX *db = GetParent(wnd)->extension;
CTLWINDOW *ct = GetControl(wnd);
if (ct != NULL) {
switch (msg) {
case SETFOCUS:
if (!(int)p1)
SendMessage(NULL, HIDE_CURSOR, 0, 0);
case MOVE:
rtn = BaseWndProc(RADIOBUTTON,wnd,msg,p1,p2);
SetFocusCursor(wnd);
return rtn;
case PAINT: {
char rb[] = "( )";
if (ct->setting)
rb[1] = 7;
SendMessage(wnd, CLEARTEXT, 0, 0);
SendMessage(wnd, ADDTEXT, (PARAM) rb, 0);
SetFocusCursor(wnd);
break;
}
case KEYBOARD:
if ((int)p1 != ' ')
break;
case LEFT_BUTTON:
SetRadioButton(db, ct);
break;
default:
break;
}
}
return BaseWndProc(RADIOBUTTON, wnd, msg, p1, p2);
}
static BOOL Setting = TRUE;
void SetRadioButton(DBOX *db, CTLWINDOW *ct)
{
Setting = FALSE;
PushRadioButton(db, ct->command);
Setting = TRUE;
}
void PushRadioButton(DBOX *db, enum commands cmd)
{
CTLWINDOW *ctt = db->ctl;
CTLWINDOW *ct = FindCommand(db, cmd, RADIOBUTTON);
int i;
if (ct == NULL)
return;
/* --- clear all the radio buttons
in this group on the dialog box --- */
/* -------- build a table of all radio buttons at the
same x vector ---------- */
for (i = 0; i < MAXRADIOS; i++)
rct[i] = NULL;
while (ctt->Class) {
if (ctt->Class == RADIOBUTTON)
if (ct->dwnd.x == ctt->dwnd.x)
rct[ctt->dwnd.y] = ctt;
ctt++;
}
/* ----- find the start of the radiobutton group ---- */
i = ct->dwnd.y;
while (i >= 0 && rct[i] != NULL)
--i;
/* ---- ignore everthing before the group ------ */
while (i >= 0)
rct[i--] = NULL;
/* ----- find the end of the radiobutton group ---- */
i = ct->dwnd.y;
while (i < MAXRADIOS && rct[i] != NULL)
i++;
/* ---- ignore everthing past the group ------ */
while (i < MAXRADIOS)
rct[i++] = NULL;
for (i = 0; i < MAXRADIOS; i++) {
if (rct[i] != NULL) {
int wason = rct[i]->setting;
rct[i]->setting = OFF;
if (Setting)
rct[i]->isetting = OFF;
if (wason)
SendMessage(rct[i]->wnd, PAINT, 0, 0);
}
}
/* ----- set the specified radio button on ----- */
ct->setting = ON;
if (Setting)
ct->isetting = ON;
SendMessage(ct->wnd, PAINT, 0, 0);
}
BOOL RadioButtonSetting(DBOX *db, enum commands cmd)
{
CTLWINDOW *ct = FindCommand(db, cmd, RADIOBUTTON);
return ct ? (ct->wnd ? (ct->setting==ON) : (ct->isetting==ON)) : FALSE;
}

View File

@@ -0,0 +1,37 @@
#include "dflat.h"
void fix_popdown(struct PopDown *popdown)
{
if (popdown->SelectionTitle != NULL)
popdown->SelectionTitle = strdup(popdown->SelectionTitle);
if (popdown->help != NULL)
popdown->help = strdup(popdown->help);
}
void fix_menu(MENU *menu)
{
unsigned int x;
if (menu->Title != NULL)
menu->Title = strdup(menu->Title);
if (menu->StatusText != NULL)
menu->StatusText = strdup(menu->StatusText);
for (x=0; x<MAXSELECTIONS; x++) {
if (menu->Title == NULL)
break;
else
fix_popdown(&(menu->Selections[x]));
}
}
void fix_mbar(MBAR *mbar)
{
unsigned int x;
for (x=0; x<MAXPULLDOWNS; x++) {
if (mbar->PullDown[x].Title == (void *)0xffffffff)
break;
else
fix_menu(&(mbar->PullDown[x]));
}
}

View File

@@ -0,0 +1,94 @@
/* ------------- rect.c --------------- */
#include "dflat.h"
/* --- Produce the vector end points produced by the overlap
of two other vectors --- */
static void subVector(int *v1, int *v2,
int t1, int t2, int o1, int o2)
{
*v1 = *v2 = -1;
if (within(o1, t1, t2)) {
*v1 = o1;
if (within(o2, t1, t2))
*v2 = o2;
else
*v2 = t2;
}
else if (within(o2, t1, t2)) {
*v2 = o2;
if (within(o1, t1, t2))
*v1 = o1;
else
*v1 = t1;
}
else if (within(t1, o1, o2)) {
*v1 = t1;
if (within(t2, o1, o2))
*v2 = t2;
else
*v2 = o2;
}
else if (within(t2, o1, o2)) {
*v2 = t2;
if (within(t1, o1, o2))
*v1 = t1;
else
*v1 = o1;
}
}
/* --- Return the rectangle produced by the overlap
of two other rectangles ---- */
RECT subRectangle(RECT r1, RECT r2)
{
RECT r = {0,0,0,0};
subVector((int *) &RectLeft(r), (int *) &RectRight(r),
RectLeft(r1), RectRight(r1),
RectLeft(r2), RectRight(r2));
subVector((int *) &RectTop(r), (int *) &RectBottom(r),
RectTop(r1), RectBottom(r1),
RectTop(r2), RectBottom(r2));
if (RectRight(r) == -1 || RectTop(r) == -1)
RectRight(r) =
RectLeft(r) =
RectTop(r) =
RectBottom(r) = 0;
return r;
}
/* ------- return the client rectangle of a window ------ */
RECT ClientRect(void *wnd)
{
RECT rc;
RectLeft(rc) = GetClientLeft((WINDOW)wnd);
RectTop(rc) = GetClientTop((WINDOW)wnd);
RectRight(rc) = GetClientRight((WINDOW)wnd);
RectBottom(rc) = GetClientBottom((WINDOW)wnd);
return rc;
}
/* ----- return the rectangle relative to
its window's screen position -------- */
RECT RelativeWindowRect(void *wnd, RECT rc)
{
RectLeft(rc) -= GetLeft((WINDOW)wnd);
RectRight(rc) -= GetLeft((WINDOW)wnd);
RectTop(rc) -= GetTop((WINDOW)wnd);
RectBottom(rc) -= GetTop((WINDOW)wnd);
return rc;
}
/* ----- clip a rectangle to the parents of the window ----- */
RECT ClipRectangle(void *wnd, RECT rc)
{
RECT sr;
RectLeft(sr) = RectTop(sr) = 0;
RectRight(sr) = SCREENWIDTH-1;
RectBottom(sr) = SCREENHEIGHT-1;
if (!TestAttribute((WINDOW)wnd, NOCLIP))
while ((wnd = GetParent((WINDOW)wnd)) != NULL)
rc = subRectangle(rc, ClientRect(wnd));
return subRectangle(rc, sr);
}

View File

@@ -0,0 +1,24 @@
/* ----------- rect.h ------------ */
#ifndef RECT_H
#define RECT_H
typedef struct {
int lf,tp,rt,bt;
} RECT;
#define within(p,v1,v2) ((p)>=(v1)&&(p)<=(v2))
#define RectTop(r) (r.tp)
#define RectBottom(r) (r.bt)
#define RectLeft(r) (r.lf)
#define RectRight(r) (r.rt)
#define InsideRect(x,y,r) (within((x),RectLeft(r),RectRight(r))\
&& \
within((y),RectTop(r),RectBottom(r)))
#define ValidRect(r) (RectRight(r) || RectLeft(r) || \
RectTop(r) || RectBottom(r))
#define RectWidth(r) (RectRight(r)-RectLeft(r)+1)
#define RectHeight(r) (RectBottom(r)-RectTop(r)+1)
RECT subRectangle(RECT, RECT);
RECT ClientRect(void *);
RECT RelativeWindowRect(void *, RECT);
RECT ClipRectangle(void *, RECT);
#endif

View File

@@ -0,0 +1,168 @@
/* ---------------- search.c ------------- */
#include "dflat.h"
extern DBOX SearchTextDB;
extern DBOX ReplaceTextDB;
static int CheckCase = FALSE;
static int Replacing = FALSE;
static int lastsize;
/* - case-insensitive, white-space-normalized char compare - */
static BOOL SearchCmp(int a, int b)
{
if (b == '\n')
b = ' ';
if (CheckCase)
return a != b;
return tolower(a) != tolower(b);
}
/* ----- replace a matching block of text ----- */
static void replacetext(WINDOW wnd, char *cp1, DBOX *db)
{
char *cr = GetEditBoxText(db, ID_REPLACEWITH);
char *cp = GetEditBoxText(db, ID_SEARCHFOR);
int oldlen = strlen(cp); /* length of text being replaced */
int newlen = strlen(cr); /* length of replacing text */
int dif;
lastsize = newlen;
if (oldlen < newlen) {
/* ---- new text expands text size ---- */
dif = newlen-oldlen;
if (wnd->textlen < strlen(wnd->text)+dif) {
/* ---- need to reallocate the text buffer ---- */
int offset = (int)(cp1-((char *)wnd->text));
wnd->textlen += dif;
wnd->text = DFrealloc(wnd->text, wnd->textlen+2);
cp1 = wnd->text + offset;
}
memmove(cp1+dif, cp1, strlen(cp1)+1);
}
else if (oldlen > newlen) {
/* ---- new text collapses text size ---- */
dif = oldlen-newlen;
memmove(cp1, cp1+dif, strlen(cp1)+1);
}
strncpy(cp1, cr, newlen);
}
/* ------- search for the occurrance of a string ------- */
static void SearchTextBox(WINDOW wnd, int incr)
{
char *s1 = NULL, *s2 = NULL, *cp1;
DBOX *db = Replacing ? &ReplaceTextDB : &SearchTextDB;
char *cp = GetEditBoxText(db, ID_SEARCHFOR);
BOOL rpl = TRUE, FoundOne = FALSE;
while (rpl == TRUE && cp != NULL && *cp) {
rpl = Replacing ?
CheckBoxSetting(&ReplaceTextDB, ID_REPLACEALL) :
FALSE;
if (TextBlockMarked(wnd)) {
ClearTextBlock(wnd);
SendMessage(wnd, PAINT, 0, 0);
}
/* search for a match starting at cursor position */
cp1 = CurrChar;
if (incr)
cp1 += lastsize; /* start past the last hit */
/* --- compare at each character position --- */
while (*cp1) {
s1 = cp;
s2 = cp1;
while (*s1 && *s1 != '\n') {
if (SearchCmp(*s1, *s2))
break;
s1++, s2++;
}
if (*s1 == '\0' || *s1 == '\n')
break;
cp1++;
}
if (s1 != NULL && (*s1 == 0 || *s1 == '\n')) {
/* ----- match at *cp1 ------- */
FoundOne = TRUE;
/* mark a block at beginning of matching text */
wnd->BlkEndLine = TextLineNumber(wnd, s2);
wnd->BlkBegLine = TextLineNumber(wnd, cp1);
if (wnd->BlkEndLine < wnd->BlkBegLine)
wnd->BlkEndLine = wnd->BlkBegLine;
wnd->BlkEndCol =
(int)(s2 - (char *)TextLine(wnd, wnd->BlkEndLine));
wnd->BlkBegCol =
(int)(cp1 - (char *)TextLine(wnd, wnd->BlkBegLine));
/* position the cursor at the matching text */
wnd->CurrCol = wnd->BlkBegCol;
wnd->CurrLine = wnd->BlkBegLine;
wnd->WndRow = wnd->CurrLine - wnd->wtop;
/* -- remember the size of the matching text -- */
lastsize = strlen(cp);
/* align the window scroll to matching text */
if (WndCol > ClientWidth(wnd)-1)
wnd->wleft = wnd->CurrCol;
if (wnd->WndRow > ClientHeight(wnd)-1) {
wnd->wtop = wnd->CurrLine;
wnd->WndRow = 0;
}
SendMessage(wnd, PAINT, 0, 0);
SendMessage(wnd, KEYBOARD_CURSOR,
WndCol, wnd->WndRow);
if (Replacing) {
if (rpl || YesNoBox("Replace the text?")) {
replacetext(wnd, cp1, db);
wnd->TextChanged = TRUE;
BuildTextPointers(wnd);
if (rpl) {
incr = TRUE;
continue;
}
}
ClearTextBlock(wnd);
SendMessage(wnd, PAINT, 0, 0);
}
return;
}
break;
}
if (!FoundOne)
MessageBox("Edit", "Edit was unable to find a match");
}
/* ------- search for the occurrance of a string,
replace it with a specified string ------- */
void ReplaceText(WINDOW wnd)
{
Replacing = TRUE;
lastsize = 0;
if (CheckCase)
SetCheckBox(&ReplaceTextDB, ID_MATCHCASE);
if (DialogBox(NULL, &ReplaceTextDB, TRUE, NULL)) {
CheckCase=CheckBoxSetting(&ReplaceTextDB,ID_MATCHCASE);
SearchTextBox(wnd, FALSE);
}
}
/* ------- search for the first occurrance of a string ------ */
void SearchText(WINDOW wnd)
{
Replacing = FALSE;
lastsize = 0;
if (CheckCase)
SetCheckBox(&SearchTextDB, ID_MATCHCASE);
if (DialogBox(NULL, &SearchTextDB, TRUE, NULL)) {
CheckCase=CheckBoxSetting(&SearchTextDB,ID_MATCHCASE);
SearchTextBox(wnd, FALSE);
}
}
/* ------- search for the next occurrance of a string ------- */
void SearchNext(WINDOW wnd)
{
SearchTextBox(wnd, TRUE);
}

View File

@@ -0,0 +1,111 @@
/* ------------- slidebox.c ------------ */
#include "dflat.h"
static int (*GenericProc)
(WINDOW wnd,MESSAGE msg,PARAM p1,PARAM p2);
static BOOL KeepRunning;
static int SliderLen;
static int Percent;
extern DBOX SliderBoxDB;
static void InsertPercent(char *s)
{
int offset;
char pcc[5];
sprintf(s, "%c%c%c",
CHANGECOLOR,
color[DIALOG][SELECT_COLOR][FG]+0x80,
color[DIALOG][SELECT_COLOR][BG]+0x80);
s += 3;
memset(s, ' ', SliderLen);
*(s+SliderLen) = '\0';
sprintf(pcc, "%d%%", Percent);
strncpy(s+SliderLen/2-1, pcc, strlen(pcc));
offset = (SliderLen * Percent) / 100;
memmove(s+offset+4, s+offset, strlen(s+offset)+1);
sprintf(pcc, "%c%c%c%c",
RESETCOLOR,
CHANGECOLOR,
color[DIALOG][SELECT_COLOR][BG]+0x80,
color[DIALOG][SELECT_COLOR][FG]+0x80);
strncpy(s+offset, pcc, 4);
*(s + strlen(s) - 1) = RESETCOLOR;
}
static int SliderTextProc(
WINDOW wnd,MESSAGE msg,PARAM p1,PARAM p2)
{
switch (msg) {
case PAINT:
Percent = (int)p2;
InsertPercent(GetText(wnd) ?
GetText(wnd) : SliderBoxDB.ctl[1].itext);
GenericProc(wnd, PAINT, 0, 0);
if (Percent >= 100)
SendMessage(GetParent(wnd),COMMAND,ID_CANCEL,0);
if (!dispatch_message())
PostMessage(GetParent(wnd), ENDDIALOG, 0, 0);
return KeepRunning;
default:
break;
}
return GenericProc(wnd, msg, p1, p2);
}
static int SliderBoxProc(
WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
int rtn;
WINDOW twnd;
switch (msg) {
case CREATE_WINDOW:
AddAttribute(wnd, SAVESELF);
rtn = DefaultWndProc(wnd, msg, p1, p2);
twnd = SliderBoxDB.ctl[1].wnd;
GenericProc = twnd->wndproc;
twnd->wndproc = SliderTextProc;
KeepRunning = TRUE;
SendMessage(wnd, CAPTURE_MOUSE, 0, 0);
SendMessage(wnd, CAPTURE_KEYBOARD, 0, 0);
return rtn;
case COMMAND:
if ((int)p2 == 0 && (int)p1 == ID_CANCEL) {
if (Percent >= 100 ||
YesNoBox("Terminate process?"))
KeepRunning = FALSE;
else
return TRUE;
}
break;
case CLOSE_WINDOW:
SendMessage(wnd, RELEASE_MOUSE, 0, 0);
SendMessage(wnd, RELEASE_KEYBOARD, 0, 0);
break;
default:
break;
}
return DefaultWndProc(wnd, msg, p1, p2);
}
WINDOW SliderBox(int len, char *ttl, char *msg)
{
SliderLen = len;
SliderBoxDB.dwnd.title = ttl;
SliderBoxDB.dwnd.w =
max(strlen(ttl),max(len, strlen(msg)))+4;
SliderBoxDB.ctl[0].itext = msg;
SliderBoxDB.ctl[0].dwnd.w = strlen(msg);
SliderBoxDB.ctl[0].dwnd.x =
(SliderBoxDB.dwnd.w - strlen(msg)-1) / 2;
SliderBoxDB.ctl[1].itext =
DFrealloc(SliderBoxDB.ctl[1].itext, len+10);
Percent = 0;
InsertPercent(SliderBoxDB.ctl[1].itext);
SliderBoxDB.ctl[1].dwnd.w = len;
SliderBoxDB.ctl[1].dwnd.x = (SliderBoxDB.dwnd.w-len-1)/2;
SliderBoxDB.ctl[2].dwnd.x = (SliderBoxDB.dwnd.w-10)/2;
DialogBox(NULL, &SliderBoxDB, FALSE, SliderBoxProc);
return SliderBoxDB.ctl[1].wnd;
}

View File

@@ -0,0 +1,46 @@
/* ------------ spinbutt.c ------------- */
#include "dflat.h"
int SpinButtonProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
int rtn;
CTLWINDOW *ct = GetControl(wnd);
if (ct != NULL) {
switch (msg) {
case CREATE_WINDOW:
wnd->wd -= 2;
wnd->rc.rt -= 2;
break;
case SETFOCUS:
rtn = BaseWndProc(SPINBUTTON, wnd, msg, p1, p2);
if (!(int)p1)
SendMessage(NULL, HIDE_CURSOR, 0, 0);
SetFocusCursor(wnd);
return rtn;
case PAINT:
foreground = WndBackground(wnd);
background = WndForeground(wnd);
wputch(wnd,UPSCROLLBOX,WindowWidth(wnd), 0);
wputch(wnd,DOWNSCROLLBOX,WindowWidth(wnd)+1,0);
SetFocusCursor(wnd);
break;
case LEFT_BUTTON:
if (p1 == GetRight(wnd) + 1)
SendMessage(wnd, KEYBOARD, UP, 0);
else if (p1 == GetRight(wnd) + 2)
SendMessage(wnd, KEYBOARD, DN, 0);
if (wnd != inFocus)
SendMessage(wnd, SETFOCUS, TRUE, 0);
return TRUE;
case LB_SETSELECTION:
rtn = BaseWndProc(SPINBUTTON, wnd, msg, p1, p2);
wnd->wtop = (int) p1;
SendMessage(wnd, PAINT, 0, 0);
return rtn;
default:
break;
}
}
return BaseWndProc(SPINBUTTON, wnd, msg, p1, p2);
}

View File

@@ -0,0 +1,73 @@
/* Status Bar
Part of the FreeDOS Editor
*/
#include "dflat.h"
extern char time_string[];
int StatusBarProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
char *statusbar;
switch (msg)
{
case CREATE_WINDOW:
SendMessage(wnd, CAPTURE_CLOCK, 0, 0);
break;
case KEYBOARD:
if ((int)p1 == CTRL_F4)
return TRUE;
break;
case PAINT:
if (!isVisible(wnd))
break;
statusbar = DFcalloc(1, WindowWidth(wnd)+1);
memset(statusbar, ' ', WindowWidth(wnd));
*(statusbar+WindowWidth(wnd)) = '\0';
strncpy(statusbar+1, "F1=Help Ý", 9);
if (wnd->text)
{
int len = min(strlen(wnd->text), WindowWidth(wnd)-9);
if (len > 0)
{
int off=(WindowWidth(wnd)-67);
strncpy(statusbar+off, wnd->text, len);
}
}
strncpy(statusbar+WindowWidth(wnd)-10, "³", 1);
if (wnd->TimePosted)
*(statusbar+WindowWidth(wnd)-8) = '\0';
else
strncpy(statusbar+WindowWidth(wnd)-8,time_string, 9);
SetStandardColor(wnd);
PutWindowLine(wnd, statusbar, 0, 0);
free(statusbar);
return TRUE;
case BORDER:
return TRUE;
case CLOCKTICK:
SetStandardColor(wnd);
PutWindowLine(wnd, (char *)p1, WindowWidth(wnd)-8, 0);
wnd->TimePosted = TRUE;
SendMessage(wnd->PrevClock, msg, p1, p2);
return TRUE;
case CLOSE_WINDOW:
SendMessage(wnd, RELEASE_CLOCK, 0, 0);
break;
default:
break;
}
return BaseWndProc(STATUSBAR, wnd, msg, p1, p2);
}

View File

@@ -0,0 +1,106 @@
/* ------------- sysmenu.c ------------ */
#include "dflat.h"
int SystemMenuProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
int mx, my;
WINDOW wnd1;
switch (msg) {
case CREATE_WINDOW:
wnd->holdmenu = ActiveMenuBar;
ActiveMenuBar = &SystemMenu;
SystemMenu.PullDown[0].Selection = 0;
break;
case LEFT_BUTTON:
wnd1 = GetParent(wnd);
mx = (int) p1 - GetLeft(wnd1);
my = (int) p2 - GetTop(wnd1);
if (HitControlBox(wnd1, mx, my))
return TRUE;
break;
case LB_CHOOSE:
PostMessage(wnd, CLOSE_WINDOW, 0, 0);
break;
case DOUBLE_CLICK:
if (p2 == GetTop(GetParent(wnd))) {
PostMessage(GetParent(wnd), msg, p1, p2);
SendMessage(wnd, CLOSE_WINDOW, TRUE, 0);
}
return TRUE;
case SHIFT_CHANGED:
return TRUE;
case CLOSE_WINDOW:
ActiveMenuBar = wnd->holdmenu;
break;
default:
break;
}
return DefaultWndProc(wnd, msg, p1, p2);
}
/* ------- Build a system menu -------- */
void BuildSystemMenu(WINDOW wnd)
{
int lf, tp, ht, wd;
WINDOW SystemMenuWnd;
SystemMenu.PullDown[0].Selections[6].Accelerator =
(GetClass(wnd) == APPLICATION) ? ALT_F4 : CTRL_F4;
lf = GetLeft(wnd)+1;
tp = GetTop(wnd)+1;
ht = MenuHeight(SystemMenu.PullDown[0].Selections);
wd = MenuWidth(SystemMenu.PullDown[0].Selections);
if (lf+wd > SCREENWIDTH-1)
lf = (SCREENWIDTH-1) - wd;
if (tp+ht > SCREENHEIGHT-2)
tp = (SCREENHEIGHT-2) - ht;
SystemMenuWnd = CreateWindow(POPDOWNMENU, NULL,
lf,tp,ht,wd,NULL,wnd,SystemMenuProc, 0);
#ifdef INCLUDE_RESTORE
if (wnd->condition == ISRESTORED)
DeactivateCommand(&SystemMenu, ID_SYSRESTORE);
else
ActivateCommand(&SystemMenu, ID_SYSRESTORE);
#endif
if (TestAttribute(wnd, MOVEABLE)
#ifdef INCLUDE_MAXIMIZE
&& wnd->condition != ISMAXIMIZED
#endif
)
ActivateCommand(&SystemMenu, ID_SYSMOVE);
else
DeactivateCommand(&SystemMenu, ID_SYSMOVE);
if (wnd->condition != ISRESTORED ||
TestAttribute(wnd, SIZEABLE) == FALSE)
DeactivateCommand(&SystemMenu, ID_SYSSIZE);
else
ActivateCommand(&SystemMenu, ID_SYSSIZE);
#ifdef INCLUDE_MINIMIZE
if (wnd->condition == ISMINIMIZED ||
TestAttribute(wnd, MINMAXBOX) == FALSE)
DeactivateCommand(&SystemMenu, ID_SYSMINIMIZE);
else
ActivateCommand(&SystemMenu, ID_SYSMINIMIZE);
#endif
#ifdef INCLUDE_MAXIMIZE
if (wnd->condition != ISRESTORED ||
TestAttribute(wnd, MINMAXBOX) == FALSE)
DeactivateCommand(&SystemMenu, ID_SYSMAXIMIZE);
else
ActivateCommand(&SystemMenu, ID_SYSMAXIMIZE);
#endif
SendMessage(SystemMenuWnd, BUILD_SELECTIONS,
(PARAM) &SystemMenu.PullDown[0], 0);
SendMessage(SystemMenuWnd, SETFOCUS, TRUE, 0);
SendMessage(SystemMenuWnd, SHOW_WINDOW, 0, 0);
}

View File

@@ -0,0 +1,214 @@
/* --------------- system.h -------------- */
#ifndef SYSTEM_H
#define SYSTEM_H
/*#if MSC | WATCOM*/
#if defined(_MSC_VER) || defined(WATCOM)
#include <direct.h>
#else
#include <dir.h>
#endif
#define swap(a,b){int x=a;a=b;b=x;}
/* ------- platform-dependent values ------ */
#ifdef _WIN32
#include "dir_w32.h"
#include "country_w32.h"
int w32_screenwidth();
int w32_screenheight();
#define SCREENWIDTH w32_screenwidth()
#define SCREENHEIGHT w32_screenheight()
void init_videomode(void);
void uninit_videomode(void);
void clearBIOSbuffer(void);
void w32_trap_to_sched(void);
int w32_get_video(int x, int y);
void w32_put_video(int x, int y, int ch);
void w32_scroll_up(int x1,int y1,int x2,int y2,int attr);
void w32_scroll_dw(int x1,int y1,int x2,int y2,int attr);
#define waitforkeyboard()
#define TRAP_TO_SCHEDULER w32_trap_to_sched();
#ifndef max
#define max(a,b) ((a)>(b)?(a):(b))
#endif
#ifndef min
#define min(a,b) ((a)<(b)?(a):(b))
#endif
void init_timer(void);
void exit_timer(void);
void update_key_buffer(void);
int w32_getdisks(void);
/* these must be placed somewhere... */
/*
void fix_popdown(struct PopDown *popdown);
void fix_menu(MENU *menu);
void fix_mbar(MBAR *mbar);
*/
#else
#define init_videomode()
#define uninit_videomode()
/* ----- interrupt vectors ----- */
#define TIMER 8
#define VIDEO 0x10
#define KEYBRD 0x16
#define DOS 0x21
#define CRIT 0x24
#define MOUSE 0x33
#define KEYBOARDVECT 9
#define KEYBOARDPORT 0x60
#define FREQUENCY 100
#define COUNT (1193280L / FREQUENCY)
#define ZEROFLAG 0x40
#define MAXSAVES 50
#define SCREENWIDTH (peekb(0x40,0x4a) & 255)
#define SCREENHEIGHT (isVGA() || isEGA() ? peekb(0x40,0x84)+1 : 25)
#define clearBIOSbuffer() *(int far *)(MK_FP(0x40,0x1a)) = \
*(int far *)(MK_FP(0x40,0x1c));
#define waitforkeyboard() while (Xbioskey(1)) (void)Xbioskey(0)
#define TRAP_TO_SCHEDULER
/* ----- keyboard BIOS (0x16) functions -------- */
#define READKB 0
#define KBSTAT 1
/* ------- video BIOS (0x10) functions --------- */
#define SETCURSORTYPE 1
#define SETCURSOR 2
#define READCURSOR 3
#define READATTRCHAR 8
#define WRITEATTRCHAR 9
#define HIDECURSOR 0x20
/* ------- the interrupt function registers -------- */
typedef struct {
int bp,di,si,ds,es,dx,cx,bx,ax,ip,cs,fl;
} IREGS;
#endif
/* ---------- keyboard prototypes -------- */
int AltConvert(int);
int getkey(void);
int getshift(void);
BOOL keyhit(void);
void beep(void);
/* ---------- cursor prototypes -------- */
void curr_cursor(int *x, int *y);
void cursor(int x, int y);
void hidecursor(void);
void unhidecursor(void);
void savecursor(void);
void restorecursor(void);
void normalcursor(void);
void set_cursor_type(unsigned t);
void videomode(void);
void SwapCursorStack(void);
/* --------- screen prototpyes -------- */
void clearscreen(void);
/* ---------- mouse prototypes ---------- */
BOOL mouse_installed(void);
int mousebuttons(void);
void get_mouseposition(int *x, int *y);
void set_mouseposition(int x, int y);
void show_mousecursor(void);
void hide_mousecursor(void);
int button_releases(void);
void resetmouse(void);
void set_mousetravel(int, int, int, int);
#define leftbutton() (mousebuttons()&1)
#define rightbutton() (mousebuttons()&2)
#define waitformouse() while(mousebuttons());
/* ------------ timer macros -------------- */
int timed_out(int timer);
void set_timer(int timer, int secs);
void set_timer_ticks(int timer, int ticks);
void disable_timer(int timer);
int timer_running(int timer);
/* void countdown(int timer); -- only used in IRQ handler anyway -- */
int timer_disabled(int timer);
/* ----------- video adaptor prototypes ----------- */
BOOL isEGA(void);
BOOL isVGA(void);
void Set25(void);
void Set43(void);
void Set50(void);
#ifndef BLACK
/* ============= Color Macros ============ */
#define BLACK 0
#define BLUE 1
#define GREEN 2
#define CYAN 3
#define RED 4
#define MAGENTA 5
#define BROWN 6
#define LIGHTGRAY 7
#define DARKGRAY 8
#define LIGHTBLUE 9
#define LIGHTGREEN 10
#define LIGHTCYAN 11
#define LIGHTRED 12
#define LIGHTMAGENTA 13
#define YELLOW 14
#define WHITE 15
#endif
#if MSC | WATCOM
/*#define keyhit ((kbhit()) ? TRUE : FALSE)*/
#endif
#if MSC | WATCOM
/* ============= Compatibility Macros ============ */
#define asm __asm
#undef FP_OFF
#undef FP_SEG
#undef MK_FP
#define FP_OFF(p) ((unsigned)(p))
#define FP_SEG(p) ((unsigned)((unsigned long)(p) >> 16))
#define MK_FP(s,o) ((void far *) \
(((unsigned long)(s) << 16) | (unsigned)(o)))
#define findfirst(p,f,a) _dos_findfirst(p,a,f)
#define findnext(f) _dos_findnext(f)
#define ffblk find_t
#define ff_name name
#define ff_fsize size
#define ff_attrib attrib
#define poke(a,b,c) (*((int far*)MK_FP((a),(b))) = (int)(c))
#define pokeb(a,b,c) (*((char far*)MK_FP((a),(b))) = (char)(c))
#define peek(a,b) (*((int far*)MK_FP((a),(b))))
#define peekb(a,b) (*((char far*)MK_FP((a),(b))))
#define getvect(v) _dos_getvect(v)
#define setvect(v,f) _dos_setvect(v,f)
#define fnsplit _splitpath
#define fnmerge _makepath
#define EXTENSION 2
#define FILENAME 4
#define DIRECTORY 8
#define DRIVE 16
int getdisk(void);
#define setdisk(d) _dos_setdrive((d)+1, NULL)
#define bioskey _bios_keybrd
#define MAXPATH 80
#define MAXDRIVE 3
#define MAXDIR 66
#define MAXFILE 9
#define MAXEXT 5
#endif
typedef enum messages {
#ifdef WATCOM
WATCOMFIX1 = -1,
#endif
#undef DFlatMsg
#define DFlatMsg(m) m,
#include "dflatmsg.h"
MESSAGECOUNT
} MESSAGE;
typedef enum window_class {
#ifdef WATCOM
WATCOMFIX2 = -1,
#endif
#define ClassDef(c,b,p,a) c,
#include "classes.h"
CLASSCOUNT
} CLASS;
#endif

View File

@@ -0,0 +1 @@
make

View File

@@ -0,0 +1,49 @@
/* -------------- text.c -------------- */
#include "dflat.h"
int TextProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
int i, len;
CTLWINDOW *ct = GetControl(wnd);
char *cp, *cp2 = ct->itext;
switch (msg) {
case SETFOCUS:
return TRUE;
case LEFT_BUTTON:
return TRUE;
case PAINT:
if (ct == NULL ||
ct->itext == NULL ||
GetText(wnd) != NULL)
break;
len = min(ct->dwnd.h, MsgHeight(cp2));
cp = cp2;
for (i = 0; i < len; i++) {
int mlen;
char *txt = cp;
char *cp1 = cp;
char *np = strchr(cp, '\n');
mlen = strlen(cp);
if ((cp + mlen) > np && np != NULL)
mlen = np-cp;
while ((cp1=strchr(cp1,SHORTCUTCHAR)) != NULL) {
if (cp1 > np && np != NULL)
break;
mlen += 3;
cp1++;
}
txt = DFmalloc(mlen+1);
CopyCommand(txt, cp, FALSE, WndBackground(wnd));
txt[mlen] = '\0';
SendMessage(wnd, ADDTEXT, (PARAM)txt, 0);
if ((cp = strchr(cp, '\n')) != NULL)
cp++;
free(txt);
}
break;
default:
break;
}
return BaseWndProc(TEXT, wnd, msg, p1, p2);
}

View File

@@ -0,0 +1,947 @@
/* ------------- textbox.c ------------ */
#include "dflat.h"
static void ComputeWindowTop(WINDOW);
static void ComputeWindowLeft(WINDOW);
static int ComputeVScrollBox(WINDOW);
static int ComputeHScrollBox(WINDOW);
static void MoveScrollBox(WINDOW, int);
static char *GetTextLine(WINDOW, int);
BOOL VSliding;
BOOL HSliding;
/* ------------ ADDTEXT Message -------------- */
static BOOL AddTextMsg(WINDOW wnd, char *txt)
{
/* --- append text to the textbox's buffer --- */
unsigned adln = strlen(txt);
/* This 64K limitation doesn't exist in protected mode */
#ifndef _WIN32
if (adln > (unsigned)0xfff0)
return FALSE;
#endif
if (wnd->text != NULL) {
/* ---- appending to existing text ---- */
unsigned txln = strlen(wnd->text);
/* This 64K limitation doesn't exist in protected mode */
#ifndef _WIN32
if ((long)txln+adln > (unsigned) 0xfff0)
return FALSE;
#endif
if (txln+adln > wnd->textlen) {
wnd->text = DFrealloc(wnd->text, txln+adln+3);
wnd->textlen = txln+adln+1;
}
}
else {
/* ------ 1st text appended ------ */
wnd->text = DFcalloc(1, adln+3);
wnd->textlen = adln+1;
}
wnd->TextChanged = TRUE;
if (wnd->text != NULL) {
/* ---- append the text ---- */
strcat(wnd->text, txt);
strcat(wnd->text, "\n");
BuildTextPointers(wnd);
return TRUE;
}
return FALSE;
}
/* ------------ DELETETEXT Message -------------- */
static void DeleteTextMsg(WINDOW wnd, int lno)
{
char *cp1 = TextLine(wnd, lno);
--wnd->wlines;
if (lno == wnd->wlines)
*cp1 = '\0';
else {
char *cp2 = TextLine(wnd, lno+1);
memmove(cp1, cp2, strlen(cp2)+1);
}
BuildTextPointers(wnd);
}
/* ------------ INSERTTEXT Message -------------- */
static void InsertTextMsg(WINDOW wnd, char *txt, int lno)
{
if (AddTextMsg(wnd, txt)) {
int len = strlen(txt)+1;
char *cp2 = TextLine(wnd, lno);
char *cp1 = cp2+len;
memmove(cp1, cp2, strlen(cp2)-len);
strcpy(cp2, txt);
*(cp2+len-1) = '\n';
BuildTextPointers(wnd);
wnd->TextChanged = TRUE;
}
}
/* ------------ SETTEXT Message -------------- */
static void SetTextMsg(WINDOW wnd, char *txt)
{
unsigned char *tp, *ep, *ttp;
unsigned int len = 0;
int x = 0, n;
tp = txt;
while (*tp) {
if (*tp == '\t')
{
/* --- tab, adjust the buffer length --- */
int sps = cfg.Tabs - (x % cfg.Tabs);
len += sps;
x += sps;
}
else
{
/* --- not a tab, count the character --- */
len++;
x++;
}
if (*tp == '\n')
x = 0; /* newline, reset x --- */
tp++;
}
/* -- assign new text value to textbox buffer -- */
SendMessage(wnd, CLEARTEXT, 0, 0);
wnd->textlen = len;
wnd->text=DFrealloc(wnd->text, len + 2);
wnd->text[len] = '\0';
ep = DFcalloc(1, len + 1); /* allocate a buffer */
/* --- detab the input file --- */
tp = txt;
ttp = ep;
x = 0;
while (*tp)
{
if (*tp == '\t')
{
if((x % cfg.Tabs) == 0)
n = cfg.Tabs;
else
n = cfg.Tabs - (x % cfg.Tabs);
for( ; n; n--, ttp++, x++)
*ttp = ' ';
}
else
{
*ttp++ = *tp;
x++;
if (*tp == '\n')
x = 0;
}
tp++;
}
*ttp = '\0';
strcpy(wnd->text, ep);
free(ep);
BuildTextPointers(wnd);
}
/* ------------ CLEARTEXT Message -------------- */
static void ClearTextMsg(WINDOW wnd)
{
/* ----- clear text from textbox ----- */
if (wnd->text != NULL)
free(wnd->text);
wnd->text = NULL;
wnd->textlen = 0;
wnd->wlines = 0;
wnd->textwidth = 0;
wnd->wtop = wnd->wleft = 0;
ClearTextBlock(wnd);
ClearTextPointers(wnd);
}
/* ------------ KEYBOARD Message -------------- */
static int KeyboardMsg(WINDOW wnd, PARAM p1)
{
switch ((int) p1) {
case UP:
return SendMessage(wnd,SCROLL,FALSE,0);
case DN:
return SendMessage(wnd,SCROLL,TRUE,0);
case FWD:
return SendMessage(wnd,HORIZSCROLL,TRUE,0);
case LARROW:
return SendMessage(wnd,HORIZSCROLL,FALSE,0);
case PGUP:
return SendMessage(wnd,SCROLLPAGE,FALSE,0);
case PGDN:
return SendMessage(wnd,SCROLLPAGE,TRUE,0);
case CTRL_PGUP:
return SendMessage(wnd,HORIZPAGE,FALSE,0);
case CTRL_PGDN:
return SendMessage(wnd,HORIZPAGE,TRUE,0);
case HOME:
return SendMessage(wnd,SCROLLDOC,TRUE,0);
case END:
return SendMessage(wnd,SCROLLDOC,FALSE,0);
default:
break;
}
return FALSE;
}
/* ------------ LEFT_BUTTON Message -------------- */
static int LeftButtonMsg(WINDOW wnd, PARAM p1, PARAM p2)
{
int mx = (int) p1 - GetLeft(wnd);
int my = (int) p2 - GetTop(wnd);
if (TestAttribute(wnd, VSCROLLBAR) &&
mx == WindowWidth(wnd)-1) {
/* -------- in the right border ------- */
if (my == 0 || my == ClientHeight(wnd)+1)
/* --- above or below the scroll bar --- */
return FALSE;
if (my == 1)
/* -------- top scroll button --------- */
return SendMessage(wnd, SCROLL, FALSE, 0);
if (my == ClientHeight(wnd))
/* -------- bottom scroll button --------- */
return SendMessage(wnd, SCROLL, TRUE, 0);
/* ---------- in the scroll bar ----------- */
if (!VSliding && my-1 == wnd->VScrollBox) {
RECT rc;
VSliding = TRUE;
rc.lf = rc.rt = GetRight(wnd);
rc.tp = GetTop(wnd)+2;
rc.bt = GetBottom(wnd)-2;
return SendMessage(NULL, MOUSE_TRAVEL,
(PARAM) &rc, 0);
}
if (my-1 < wnd->VScrollBox)
return SendMessage(wnd,SCROLLPAGE,FALSE,0);
if (my-1 > wnd->VScrollBox)
return SendMessage(wnd,SCROLLPAGE,TRUE,0);
}
if (TestAttribute(wnd, HSCROLLBAR) &&
my == WindowHeight(wnd)-1) {
/* -------- in the bottom border ------- */
if (mx == 0 || my == ClientWidth(wnd)+1)
/* ------ outside the scroll bar ---- */
return FALSE;
if (mx == 1)
return SendMessage(wnd, HORIZSCROLL,FALSE,0);
if (mx == WindowWidth(wnd)-2)
return SendMessage(wnd, HORIZSCROLL,TRUE,0);
if (!HSliding && mx-1 == wnd->HScrollBox) {
/* --- hit the scroll box --- */
RECT rc;
rc.lf = GetLeft(wnd)+2;
rc.rt = GetRight(wnd)-2;
rc.tp = rc.bt = GetBottom(wnd);
/* - keep the mouse in the scroll bar - */
SendMessage(NULL,MOUSE_TRAVEL,(PARAM)&rc,0);
HSliding = TRUE;
return TRUE;
}
if (mx-1 < wnd->HScrollBox)
return SendMessage(wnd,HORIZPAGE,FALSE,0);
if (mx-1 > wnd->HScrollBox)
return SendMessage(wnd,HORIZPAGE,TRUE,0);
}
return FALSE;
}
/* ------------ MOUSE_MOVED Message -------------- */
static BOOL MouseMovedMsg(WINDOW wnd, PARAM p1, PARAM p2)
{
int mx = (int) p1 - GetLeft(wnd);
int my = (int) p2 - GetTop(wnd);
if (VSliding) {
/* ---- dragging the vertical scroll box --- */
if (my-1 != wnd->VScrollBox) {
foreground = FrameForeground(wnd);
background = FrameBackground(wnd);
wputch(wnd, SCROLLBARCHAR, WindowWidth(wnd)-1,
wnd->VScrollBox+1);
wnd->VScrollBox = my-1;
wputch(wnd, SCROLLBOXCHAR, WindowWidth(wnd)-1,
my);
}
return TRUE;
}
if (HSliding) {
/* --- dragging the horizontal scroll box --- */
if (mx-1 != wnd->HScrollBox) {
foreground = FrameForeground(wnd);
background = FrameBackground(wnd);
wputch(wnd, SCROLLBARCHAR, wnd->HScrollBox+1,
WindowHeight(wnd)-1);
wnd->HScrollBox = mx-1;
wputch(wnd, SCROLLBOXCHAR, mx, WindowHeight(wnd)-1);
}
return TRUE;
}
return FALSE;
}
/* ------------ BUTTON_RELEASED Message -------------- */
static void ButtonReleasedMsg(WINDOW wnd)
{
if (HSliding || VSliding) {
/* release the mouse ouside the scroll bar */
SendMessage(NULL, MOUSE_TRAVEL, 0, 0);
VSliding ? ComputeWindowTop(wnd):ComputeWindowLeft(wnd);
SendMessage(wnd, PAINT, 0, 0);
SendMessage(wnd, KEYBOARD_CURSOR, 0, 0);
VSliding = HSliding = FALSE;
}
}
/* ------------ SCROLL Message -------------- */
static BOOL ScrollMsg(WINDOW wnd, PARAM p1)
{
/* ---- vertical scroll one line ---- */
if (p1) {
/* ----- scroll one line up ----- */
if (wnd->wtop+ClientHeight(wnd) >= wnd->wlines)
return FALSE;
wnd->wtop++;
}
else {
/* ----- scroll one line down ----- */
if (wnd->wtop == 0)
return FALSE;
--wnd->wtop;
}
if (isVisible(wnd)) {
RECT rc;
rc = ClipRectangle(wnd, ClientRect(wnd));
if (ValidRect(rc)) {
/* ---- scroll the window ----- */
if (wnd != inFocus)
SendMessage(wnd, PAINT, 0, 0);
else {
scroll_window(wnd, rc, (int)p1);
if (!(int)p1)
/* -- write top line (down) -- */
WriteTextLine(wnd,NULL,wnd->wtop,FALSE);
else {
/* -- write bottom line (up) -- */
int y=RectBottom(rc)-GetClientTop(wnd);
WriteTextLine(wnd, NULL,
wnd->wtop+y, FALSE);
}
}
}
/* ---- reset the scroll box ---- */
if (TestAttribute(wnd, VSCROLLBAR)) {
int vscrollbox = ComputeVScrollBox(wnd);
if (vscrollbox != wnd->VScrollBox)
MoveScrollBox(wnd, vscrollbox);
}
}
return TRUE;
}
/* ------------ HORIZSCROLL Message -------------- */
static BOOL HorizScrollMsg(WINDOW wnd, PARAM p1)
{
/* --- horizontal scroll one column --- */
if (p1) {
/* --- scroll left --- */
if (wnd->wleft + ClientWidth(wnd)-1 >= wnd->textwidth)
return FALSE;
wnd->wleft++;
}
else {
/* --- scroll right --- */
if (wnd->wleft == 0)
return FALSE;
--wnd->wleft;
}
SendMessage(wnd, PAINT, 0, 0);
return TRUE;
}
/* ------------ SCROLLPAGE Message -------------- */
static void ScrollPageMsg(WINDOW wnd, PARAM p1)
{
/* --- vertical scroll one page --- */
if ((int) p1 == FALSE) {
/* ---- page up ---- */
if (wnd->wtop)
wnd->wtop -= ClientHeight(wnd);
}
else {
/* ---- page down ---- */
if (wnd->wtop+ClientHeight(wnd) < wnd->wlines) {
wnd->wtop += ClientHeight(wnd);
if (wnd->wtop>wnd->wlines-ClientHeight(wnd))
wnd->wtop=wnd->wlines-ClientHeight(wnd);
}
}
if (wnd->wtop < 0)
wnd->wtop = 0;
SendMessage(wnd, PAINT, 0, 0);
}
/* ------------ HORIZSCROLLPAGE Message -------------- */
static void HorizScrollPageMsg(WINDOW wnd, PARAM p1)
{
/* --- horizontal scroll one page --- */
if ((int) p1 == FALSE)
/* ---- page left ----- */
wnd->wleft -= ClientWidth(wnd);
else {
/* ---- page right ----- */
wnd->wleft += ClientWidth(wnd);
if (wnd->wleft > wnd->textwidth-ClientWidth(wnd))
wnd->wleft = wnd->textwidth-ClientWidth(wnd);
}
if (wnd->wleft < 0)
wnd->wleft = 0;
SendMessage(wnd, PAINT, 0, 0);
}
/* ------------ SCROLLDOC Message -------------- */
static void ScrollDocMsg(WINDOW wnd, PARAM p1)
{
/* --- scroll to beginning or end of document --- */
if ((int) p1)
wnd->wtop = wnd->wleft = 0;
else if (wnd->wtop+ClientHeight(wnd) < wnd->wlines){
wnd->wtop = wnd->wlines-ClientHeight(wnd);
wnd->wleft = 0;
}
SendMessage(wnd, PAINT, 0, 0);
}
/* ------------ PAINT Message -------------- */
static void PaintMsg(WINDOW wnd, PARAM p1, PARAM p2)
{
/* ------ paint the client area ----- */
RECT rc, rcc;
int y;
char blankline[201];
/* ----- build the rectangle to paint ----- */
if ((RECT *)p1 == NULL)
rc=RelativeWindowRect(wnd, WindowRect(wnd));
else
rc= *(RECT *)p1;
if (TestAttribute(wnd, HASBORDER) &&
RectRight(rc) >= WindowWidth(wnd)-1) {
if (RectLeft(rc) >= WindowWidth(wnd)-1)
return;
RectRight(rc) = WindowWidth(wnd)-2;
}
rcc = AdjustRectangle(wnd, rc);
if (!p2 && wnd != inFocus)
ClipString++;
/* ----- blank line for padding ----- */
memset(blankline, ' ', SCREENWIDTH);
blankline[RectRight(rcc)+1] = '\0';
/* ------- each line within rectangle ------ */
for (y = RectTop(rc); y <= RectBottom(rc); y++){
int yy;
/* ---- test outside of Client area ---- */
if (TestAttribute(wnd,
HASBORDER | HASTITLEBAR)) {
if (y < TopBorderAdj(wnd))
continue;
if (y > WindowHeight(wnd)-2)
continue;
}
yy = y-TopBorderAdj(wnd);
if (yy < wnd->wlines-wnd->wtop)
/* ---- paint a text line ---- */
WriteTextLine(wnd, &rc,
yy+wnd->wtop, FALSE);
else {
/* ---- paint a blank line ---- */
SetStandardColor(wnd);
writeline(wnd, blankline+RectLeft(rcc),
RectLeft(rcc)+BorderAdj(wnd), y, FALSE);
}
}
/* ------- position the scroll box ------- */
if (TestAttribute(wnd, VSCROLLBAR|HSCROLLBAR)) {
int hscrollbox = ComputeHScrollBox(wnd);
int vscrollbox = ComputeVScrollBox(wnd);
if (hscrollbox != wnd->HScrollBox ||
vscrollbox != wnd->VScrollBox) {
wnd->HScrollBox = hscrollbox;
wnd->VScrollBox = vscrollbox;
SendMessage(wnd, BORDER, p1, 0);
}
}
if (!p2 && wnd != inFocus)
--ClipString;
}
/* ------------ CLOSE_WINDOW Message -------------- */
static void CloseWindowMsg(WINDOW wnd)
{
SendMessage(wnd, CLEARTEXT, 0, 0);
if (wnd->TextPointers != NULL) {
free(wnd->TextPointers);
wnd->TextPointers = NULL;
}
}
/* ----------- TEXTBOX Message-processing Module ----------- */
int TextBoxProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
switch (msg) {
case CREATE_WINDOW:
wnd->HScrollBox = wnd->VScrollBox = 1;
ClearTextPointers(wnd);
break;
case ADDTEXT:
return AddTextMsg(wnd, (char *) p1);
case DELETETEXT:
DeleteTextMsg(wnd, (int) p1);
return TRUE;
case INSERTTEXT:
InsertTextMsg(wnd, (char *) p1, (int) p2);
return TRUE;
case SETTEXT:
SetTextMsg(wnd, (char *) p1);
return TRUE;
case CLEARTEXT:
ClearTextMsg(wnd);
break;
case KEYBOARD:
if (WindowMoving || WindowSizing)
break;
if (KeyboardMsg(wnd, p1))
return TRUE;
break;
case LEFT_BUTTON:
if (WindowSizing || WindowMoving)
return FALSE;
if (LeftButtonMsg(wnd, p1, p2))
return TRUE;
break;
case MOUSE_MOVED:
if (MouseMovedMsg(wnd, p1, p2))
return TRUE;
break;
case BUTTON_RELEASED:
ButtonReleasedMsg(wnd);
break;
case SCROLL:
return ScrollMsg(wnd, p1);
case HORIZSCROLL:
return HorizScrollMsg(wnd, p1);
case SCROLLPAGE:
ScrollPageMsg(wnd, p1);
return TRUE;
case HORIZPAGE:
HorizScrollPageMsg(wnd, p1);
return TRUE;
case SCROLLDOC:
ScrollDocMsg(wnd, p1);
return TRUE;
case PAINT:
if (isVisible(wnd)) {
PaintMsg(wnd, p1, p2);
return FALSE;
}
break;
case CLOSE_WINDOW:
CloseWindowMsg(wnd);
break;
default:
break;
}
return BaseWndProc(TEXTBOX, wnd, msg, p1, p2);
}
/* ------ compute the vertical scroll box position from
the text pointers --------- */
static int ComputeVScrollBox(WINDOW wnd)
{
int pagelen = wnd->wlines - ClientHeight(wnd);
int barlen = ClientHeight(wnd)-2;
int lines_tick;
int vscrollbox;
if (pagelen < 1 || barlen < 1)
vscrollbox = 1;
else {
if (pagelen > barlen)
lines_tick = pagelen / barlen;
else
lines_tick = barlen / pagelen;
vscrollbox = 1 + (wnd->wtop / lines_tick);
if (vscrollbox > ClientHeight(wnd)-2 ||
wnd->wtop + ClientHeight(wnd) >= wnd->wlines)
vscrollbox = ClientHeight(wnd)-2;
}
return vscrollbox;
}
/* ---- compute top text line from scroll box position ---- */
static void ComputeWindowTop(WINDOW wnd)
{
int pagelen = wnd->wlines - ClientHeight(wnd);
if (wnd->VScrollBox == 0)
wnd->wtop = 0;
else if (wnd->VScrollBox == ClientHeight(wnd)-2)
wnd->wtop = pagelen;
else {
int barlen = ClientHeight(wnd)-2;
int lines_tick;
if (pagelen > barlen)
lines_tick = barlen ? (pagelen / barlen) : 0;
else
lines_tick = pagelen ? (barlen / pagelen) : 0;
wnd->wtop = (wnd->VScrollBox-1) * lines_tick;
if (wnd->wtop + ClientHeight(wnd) > wnd->wlines)
wnd->wtop = pagelen;
}
if (wnd->wtop < 0)
wnd->wtop = 0;
}
/* ------ compute the horizontal scroll box position from
the text pointers --------- */
static int ComputeHScrollBox(WINDOW wnd)
{
int pagewidth = wnd->textwidth - ClientWidth(wnd);
int barlen = ClientWidth(wnd)-2;
int chars_tick;
int hscrollbox;
if (pagewidth < 1 || barlen < 1)
hscrollbox = 1;
else {
if (pagewidth > barlen)
chars_tick = barlen ? (pagewidth / barlen) : 0;
else
chars_tick = pagewidth ? (barlen / pagewidth) : 0;
hscrollbox = 1 + (chars_tick ? (wnd->wleft / chars_tick) : 0);
if (hscrollbox > ClientWidth(wnd)-2 ||
wnd->wleft + ClientWidth(wnd) >= wnd->textwidth)
hscrollbox = ClientWidth(wnd)-2;
}
return hscrollbox;
}
/* ---- compute left column from scroll box position ---- */
static void ComputeWindowLeft(WINDOW wnd)
{
int pagewidth = wnd->textwidth - ClientWidth(wnd);
if (wnd->HScrollBox == 0)
wnd->wleft = 0;
else if (wnd->HScrollBox == ClientWidth(wnd)-2)
wnd->wleft = pagewidth;
else {
int barlen = ClientWidth(wnd)-2;
int chars_tick;
if (pagewidth > barlen)
chars_tick = pagewidth / barlen;
else
chars_tick = barlen / pagewidth;
wnd->wleft = (wnd->HScrollBox-1) * chars_tick;
if (wnd->wleft + ClientWidth(wnd) > wnd->textwidth)
wnd->wleft = pagewidth;
}
if (wnd->wleft < 0)
wnd->wleft = 0;
}
/* ----- get the text to a specified line ----- */
static char *GetTextLine(WINDOW wnd, int selection)
{
char *line;
int len = 0;
char *cp, *cp1;
cp = cp1 = TextLine(wnd, selection);
while (*cp && *cp != '\n') {
len++;
cp++;
}
line = DFmalloc(len+7);
memmove(line, cp1, len);
line[len] = '\0';
return line;
}
/* ------- write a line of text to a textbox window ------- */
void WriteTextLine(WINDOW wnd, RECT *rcc, int y, BOOL reverse)
{
int len = 0;
int dif = 0;
unsigned char line[200];
RECT rc;
unsigned char *lp, *svlp;
int lnlen;
int i;
BOOL trunc = FALSE;
/* ------ make sure y is inside the window ----- */
if (y < wnd->wtop || y >= wnd->wtop+ClientHeight(wnd))
return;
/* ---- build the retangle within which can write ---- */
if (rcc == NULL) {
rc = RelativeWindowRect(wnd, WindowRect(wnd));
if (TestAttribute(wnd, HASBORDER) &&
RectRight(rc) >= WindowWidth(wnd)-1)
RectRight(rc) = WindowWidth(wnd)-2;
}
else
rc = *rcc;
/* ----- make sure rectangle is within window ------ */
if (RectLeft(rc) >= WindowWidth(wnd)-1)
return;
if (RectRight(rc) == 0)
return;
rc = AdjustRectangle(wnd, rc);
if (y-wnd->wtop<RectTop(rc) || y-wnd->wtop>RectBottom(rc))
return;
/* --- get the text and length of the text line --- */
lp = svlp = GetTextLine(wnd, y);
if (svlp == NULL)
return;
lnlen = LineLength(lp);
if (wnd->protect) {
char *pp = lp;
while (*pp) {
if (isprint(*pp))
*pp = '*';
pp++;
}
}
/* -------- insert block color change controls ------- */
if (TextBlockMarked(wnd)) {
int bbl = wnd->BlkBegLine;
int bel = wnd->BlkEndLine;
int bbc = wnd->BlkBegCol;
int bec = wnd->BlkEndCol;
int by = y;
/* ----- put lowest marker first ----- */
if (bbl > bel) {
swap(bbl, bel);
swap(bbc, bec);
}
if (bbl == bel && bbc > bec)
swap(bbc, bec);
if (by >= bbl && by <= bel) {
/* ------ the block includes this line ----- */
int blkbeg = 0;
int blkend = lnlen;
if (!(by > bbl && by < bel)) {
/* --- the entire line is not in the block -- */
if (by == bbl)
/* ---- the block begins on this line --- */
blkbeg = bbc;
if (by == bel)
/* ---- the block ends on this line ---- */
blkend = bec;
}
if (blkend == 0 && lnlen == 0) {
strcpy(lp, " ");
blkend++;
}
/* ----- insert the reset color token ----- */
memmove(lp+blkend+1,lp+blkend,strlen(lp+blkend)+1);
lp[blkend] = RESETCOLOR;
/* ----- insert the change color token ----- */
memmove(lp+blkbeg+3,lp+blkbeg,strlen(lp+blkbeg)+1);
lp[blkbeg] = CHANGECOLOR;
/* ----- insert the color tokens ----- */
SetReverseColor(wnd);
lp[blkbeg+1] = foreground | 0x80;
lp[blkbeg+2] = background | 0x80;
lnlen += 4;
}
}
/* - make sure left margin doesn't overlap color change - */
for (i = 0; i < wnd->wleft+3; i++) {
if (*(lp+i) == '\0')
break;
if (*(unsigned char *)(lp + i) == RESETCOLOR)
break;
}
if (*(lp+i) && i < wnd->wleft+3) {
if (wnd->wleft+4 > lnlen)
trunc = TRUE;
else
lp += 4;
}
else {
/* --- it does, shift the color change over --- */
for (i = 0; i < wnd->wleft; i++) {
if (*(lp+i) == '\0')
break;
if (*(unsigned char *)(lp + i) == CHANGECOLOR) {
*(lp+wnd->wleft+2) = *(lp+i+2);
*(lp+wnd->wleft+1) = *(lp+i+1);
*(lp+wnd->wleft) = *(lp+i);
break;
}
}
}
/* ------ build the line to display -------- */
if (!trunc) {
if (lnlen < wnd->wleft)
lnlen = 0;
else
lp += wnd->wleft;
if (lnlen > RectLeft(rc)) {
/* ---- the line exceeds the rectangle ---- */
int ct = RectLeft(rc);
char *initlp = lp;
/* --- point to end of clipped line --- */
while (ct) {
if (*(unsigned char *)lp == CHANGECOLOR)
lp += 3;
else if (*(unsigned char *)lp == RESETCOLOR)
lp++;
else
lp++, --ct;
}
if (RectLeft(rc)) {
char *lpp = lp;
while (*lpp) {
if (*(unsigned char*)lpp==CHANGECOLOR)
break;
if (*(unsigned char*)lpp==RESETCOLOR) {
lpp = lp;
while (lpp >= initlp) {
if (*(unsigned char *)lpp ==
CHANGECOLOR) {
lp -= 3;
memmove(lp,lpp,3);
break;
}
--lpp;
}
break;
}
lpp++;
}
}
lnlen = LineLength(lp);
len = min(lnlen, RectWidth(rc));
dif = strlen(lp) - lnlen;
len += dif;
if (len > 0)
strncpy(line, lp, len);
}
}
/* -------- pad the line --------- */
while (len < RectWidth(rc)+dif)
line[len++] = ' ';
line[len] = '\0';
dif = 0;
/* ------ establish the line's main color ----- */
if (reverse) {
char *cp = line;
SetReverseColor(wnd);
while ((cp = strchr(cp, CHANGECOLOR)) != NULL) {
cp += 2;
*cp++ = background | 0x80;
}
if (*(unsigned char *)line == CHANGECOLOR)
dif = 3;
}
else
SetStandardColor(wnd);
/* ------- display the line -------- */
writeline(wnd, line+dif,
RectLeft(rc)+BorderAdj(wnd),
y-wnd->wtop+TopBorderAdj(wnd), FALSE);
free(svlp);
}
void MarkTextBlock(WINDOW wnd, int BegLine, int BegCol,
int EndLine, int EndCol)
{
wnd->BlkBegLine = BegLine;
wnd->BlkEndLine = EndLine;
wnd->BlkBegCol = BegCol;
wnd->BlkEndCol = EndCol;
}
/* ----- clear and initialize text line pointer array ----- */
void ClearTextPointers(WINDOW wnd)
{
wnd->TextPointers = DFrealloc(wnd->TextPointers, sizeof(int));
*(wnd->TextPointers) = 0;
}
#define INITLINES 100
/* ---- build array of pointers to text lines ---- */
void BuildTextPointers(WINDOW wnd)
{
unsigned char *cp = wnd->text, *cp1;
int incrs = INITLINES;
unsigned int off;
wnd->textwidth = wnd->wlines = 0;
while (*cp) {
if (incrs == INITLINES) {
incrs = 0;
wnd->TextPointers = DFrealloc(wnd->TextPointers,
(wnd->wlines + INITLINES) * sizeof(int));
}
off = (unsigned int) (cp - wnd->text);
*((wnd->TextPointers) + wnd->wlines) = off;
wnd->wlines++;
incrs++;
cp1 = cp;
while (*cp && *cp != '\n')
cp++;
wnd->textwidth = max(wnd->textwidth,
(unsigned int) (cp - cp1));
if (*cp)
cp++;
}
}
static void MoveScrollBox(WINDOW wnd, int vscrollbox)
{
foreground = FrameForeground(wnd);
background = FrameBackground(wnd);
wputch(wnd, SCROLLBARCHAR, WindowWidth(wnd)-1,
wnd->VScrollBox+1);
wputch(wnd, SCROLLBOXCHAR, WindowWidth(wnd)-1,
vscrollbox+1);
wnd->VScrollBox = vscrollbox;
}
int TextLineNumber(WINDOW wnd, char *lp)
{
int lineno;
char *cp;
for (lineno = 0; lineno < wnd->wlines; lineno++) {
cp = wnd->text + *((wnd->TextPointers) + lineno);
if (cp == lp)
return lineno;
if (cp > lp)
break;
}
return lineno-1;
}

View File

@@ -0,0 +1,83 @@
#include <windows.h>
static char timerused[3] = {0, 0, 0};
static long unsigned int timerend[3] = {0, 0, 0};
static long unsigned int timerstart[3] = {0, 0, 0};
/* ------- timer interrupt service routine ------- */
/* More complex countdown handling by Eric Auer */
/* Allows us to work without hooking intr. 0x08 */
int timed_out(int timer) /* was: countdown 0? */
{
if ((timer > 2) || (timer < 0))
return -1; /* invalid -> always elapsed */
if (timerused[timer] == 0) /* not active at all? */
return 0;
if (timerused[timer] == 2) /* timeout already known? */
return 1;
if (GetTickCount() < timerstart[timer] ||
GetTickCount() >= timerend[timer])
{
timerused[timer] = 2; /* countdown elapsed */
return 1;
}
return 0; /* still waiting */
}
int timer_running(int timer) /* was: countdown > 0? */
{
if ((timer > 2) || (timer < 0))
return 0; /* invalid -> never running */
if (timerused[timer] == 1) /* running? */
{
return (1 - timed_out(timer)); /* if not elapsed, running */
}
else
return 0; /* certainly not running */
}
int timer_disabled(int timer) /* was: countdown -1? */
{
if ((timer > 2) || (timer < 0))
return 1; /* invalid -> always disabled */
return (timerused[timer] == 0);
}
void disable_timer(int timer) /* was: countdown = -1 */
{
if ((timer > 2) || (timer < 0))
return;
timerused[timer] = 0;
}
void set_timer(int timer, int secs)
{
if ((timer > 2) || (timer < 0))
return;
timerstart[timer]=GetTickCount();
timerend[timer]=timerstart[timer] + (secs*1000) + 1;
timerused[timer]=1; /* mark as running */
}
void set_timer_ticks(int timer, int ticks)
{
if ((timer > 2) || (timer < 0))
return;
timerstart[timer]=GetTickCount();
timerend[timer]=timerstart[timer] + ticks*55;
timerused[timer]=1; /* mark as running */
}

View File

@@ -0,0 +1,311 @@
/* --------------------- video.c -------------------- */
#include "dflat.h"
BOOL ClipString;
static BOOL snowy;
static unsigned video_address;
static int near vpeek(int far *vp);
static void near vpoke(int far *vp, int c);
void movefromscreen(void *bf, int offset, int len);
void movetoscreen(void *bf, int offset, int len);
/* -- read a rectangle of video memory into a save buffer -- */
void getvideo(RECT rc, void far *bf)
{
int ht = RectBottom(rc)-RectTop(rc)+1;
int bytes_row = (RectRight(rc)-RectLeft(rc)+1) * 2;
unsigned vadr = vad(RectLeft(rc), RectTop(rc));
hide_mousecursor();
while (ht--) {
movefromscreen(bf, vadr, bytes_row);
vadr += SCREENWIDTH*2;
bf = (char far *)bf + bytes_row;
}
show_mousecursor();
}
/* -- write a rectangle of video memory from a save buffer -- */
void storevideo(RECT rc, void far *bf)
{
int ht = RectBottom(rc)-RectTop(rc)+1;
int bytes_row = (RectRight(rc)-RectLeft(rc)+1) * 2;
unsigned vadr = vad(RectLeft(rc), RectTop(rc));
hide_mousecursor();
while (ht--) {
movetoscreen(bf, vadr, bytes_row);
vadr += SCREENWIDTH*2;
bf = (char far *)bf + bytes_row;
}
show_mousecursor();
}
/* -------- read a character of video memory ------- */
unsigned int GetVideoChar(int x, int y)
{
int c;
hide_mousecursor();
if (snowy)
c = vpeek(MK_FP(video_address, vad(x,y)));
else
c = peek(video_address, vad(x,y));
show_mousecursor();
return c;
}
/* -------- write a character of video memory ------- */
void PutVideoChar(int x, int y, int c)
{
if (x < SCREENWIDTH && y < SCREENHEIGHT) {
hide_mousecursor();
if (snowy)
vpoke(MK_FP(video_address, vad(x,y)), c);
else
poke(video_address, vad(x,y), c);
show_mousecursor();
}
}
BOOL CharInView(WINDOW wnd, int x, int y)
{
WINDOW nwnd = NextWindow(wnd);
WINDOW pwnd;
RECT rc;
int x1 = GetLeft(wnd)+x;
int y1 = GetTop(wnd)+y;
if (!TestAttribute(wnd, VISIBLE))
return FALSE;
if (!TestAttribute(wnd, NOCLIP)) {
WINDOW wnd1 = GetParent(wnd);
while (wnd1 != NULL) {
/* --- clip character to parent's borders -- */
if (!TestAttribute(wnd1, VISIBLE))
return FALSE;
if (!InsideRect(x1, y1, ClientRect(wnd1)))
return FALSE;
wnd1 = GetParent(wnd1);
}
}
while (nwnd != NULL) {
if (!isHidden(nwnd) /* && !isAncestor(wnd, nwnd) */ ) {
rc = WindowRect(nwnd);
if (TestAttribute(nwnd, SHADOW)) {
RectBottom(rc)++;
RectRight(rc)++;
}
if (!TestAttribute(nwnd, NOCLIP)) {
pwnd = nwnd;
while (GetParent(pwnd)) {
pwnd = GetParent(pwnd);
rc = subRectangle(rc, ClientRect(pwnd));
}
}
if (InsideRect(x1,y1,rc))
return FALSE;
}
nwnd = NextWindow(nwnd);
}
return (x1 < SCREENWIDTH && y1 < SCREENHEIGHT);
}
/* -------- write a character to a window ------- */
void wputch(WINDOW wnd, int c, int x, int y)
{
if (CharInView(wnd, x, y)) {
int ch = (c & 255) | (clr(foreground, background) << 8);
int xc = GetLeft(wnd)+x;
int yc = GetTop(wnd)+y;
hide_mousecursor();
if (snowy)
vpoke(MK_FP(video_address, vad(xc, yc)), ch);
else
poke(video_address, vad(xc, yc), ch);
show_mousecursor();
}
}
/* ------- write a string to a window ---------- */
void wputs(WINDOW wnd, void *s, int x, int y)
{
int x1=GetLeft(wnd)+x, x2=x1, y1=GetTop(wnd)+y;
if (x1 < SCREENWIDTH && y1 < SCREENHEIGHT && isVisible(wnd))
{
int ln[200], *cp1=ln, fg=foreground,bg=background,len,off=0;
unsigned char *str=s;
while (*str)
{
if (*str == CHANGECOLOR)
{
str++;
foreground = (*str++) & 0x7f;
background = (*str++) & 0x7f;
continue;
}
if (*str == RESETCOLOR)
{
foreground = fg & 0x7f;
background = bg & 0x7f;
str++;
continue;
}
if (*str == ('\t' | 0x80) || *str == ('\f' | 0x80))
*cp1 = ' ' | (clr(foreground, background) << 8);
else
*cp1 = (*str & 255) | (clr(foreground, background) << 8);
if (ClipString)
if (!CharInView(wnd, x, y))
*cp1 = peek(video_address, vad(x2,y1));
cp1++;
str++;
x++;
x2++;
}
foreground = fg;
background = bg;
len = (int)(cp1-ln);
if (x1+len > SCREENWIDTH)
len = SCREENWIDTH-x1;
if (!ClipString && !TestAttribute(wnd, NOCLIP))
{
/* -- clip the line to within ancestor windows -- */
RECT rc = WindowRect(wnd);
WINDOW nwnd = GetParent(wnd);
while (len > 0 && nwnd != NULL)
{
if (!isVisible(nwnd))
{
len = 0;
break;
}
rc = subRectangle(rc, ClientRect(nwnd));
nwnd = GetParent(nwnd);
}
while (len > 0 && !InsideRect(x1+off,y1,rc))
{
off++;
--len;
}
if (len > 0)
{
x2 = x1+len-1;
while (len && !InsideRect(x2,y1,rc))
{
--x2;
--len;
}
}
}
if (len > 0)
{
hide_mousecursor();
movetoscreen(ln+off, vad(x1+off,y1), len*2);
show_mousecursor();
}
}
}
/* --------- get the current video mode -------- */
void get_videomode(void)
{
videomode();
/* ---- Monochrome Display Adaptor or text mode ---- */
snowy = FALSE;
if (ismono())
video_address = 0xb000;
else
{
/* ------ Text mode -------- */
video_address = 0xb800 + video_page;
if (!isEGA() && !isVGA())
/* -------- CGA --------- */
snowy = cfg.snowy;
}
}
/* --------- scroll the window. d: 1 = up, 0 = dn ---------- */
void scroll_window(WINDOW wnd, RECT rc, int d)
{
if (RectTop(rc) != RectBottom(rc)) {
union REGS regs;
regs.h.cl = RectLeft(rc);
regs.h.ch = RectTop(rc);
regs.h.dl = RectRight(rc);
regs.h.dh = RectBottom(rc);
regs.h.bh = clr(WndForeground(wnd),WndBackground(wnd));
regs.h.ah = 7 - d;
regs.h.al = 1;
hide_mousecursor();
int86(VIDEO, &regs, &regs);
show_mousecursor();
}
}
static void near waitforretrace(void)
{
disable(); /* Disable interrupts */
/* Catch a FULL vretrace */
if (inp(0x3da) & 8) /* If inside vertical retrace */
while (inp(0x3da) & 8); /* Wait until retrace ends */
while (!(inp(0x3da) & 8)); /* Wait for vretrace to START */
while (!(inp(0x3da) & 0x01)); /* Wait for 1st hretrace in it */
enable(); /* Re-enable interrupts */
}
void movetoscreen(void *bf, int offset, int len)
{
if (snowy)
waitforretrace();
movedata(FP_SEG(bf), FP_OFF(bf), video_address, offset, len);
}
void movefromscreen(void *bf, int offset, int len)
{
if (snowy)
waitforretrace();
movedata(video_address, offset, FP_SEG(bf), FP_OFF(bf), len);
}
static int near vpeek(int far *vp)
{
int c;
waitforretrace();
c = *vp;
return c;
}
static void near vpoke(int far *vp, int c)
{
waitforretrace();
*vp = c;
}

View File

@@ -0,0 +1,32 @@
/* ---------------- video.h ----------------- */
#ifndef VIDEO_H
#define VIDEO_H
#include "rect.h"
void getvideo(RECT, void far *);
void storevideo(RECT, void far *);
void wputch(WINDOW, int, int, int);
unsigned int GetVideoChar(int, int);
void PutVideoChar(int, int, int);
void get_videomode(void);
void wputs(WINDOW, void *, int, int);
void scroll_window(WINDOW, RECT, int);
#define clr(fg,bg) ((fg)|((bg)<<4))
#define vad(x,y) ((y)*(SCREENWIDTH*2)+(x)*2)
#define videochar(x,y) (GetVideoChar(x,y) & 255)
#ifdef _WIN32
#define video_mode 1
#define ismono() 0
#define istext() 1
#else
extern unsigned video_mode;
extern unsigned video_page;
#define ismono() (video_mode == 7)
#define istext() (video_mode < 4)
#endif
#endif

View File

@@ -0,0 +1,238 @@
/* --------------------- video.c -------------------- */
#include "dflat.h"
BOOL ClipString;
void movefromscreen(void *bf, int offset, int len);
void movetoscreen(void *bf, int offset, int len);
/* -- read a rectangle of video memory into a save buffer -- */
void getvideo(RECT rc, void far *bf)
{
int x1 = RectLeft(rc);
int x2 = RectRight(rc);
int y1 = RectTop(rc);
int y2 = RectBottom(rc);
int ht;
int bytes_row;
int pitch_row = (x2-x1+1)*2;
unsigned long int vadr = vad(x1, y1);
/* perform clipping! */
if (x1 >= SCREENWIDTH ||
y1 >= SCREENHEIGHT)
return;
if (x2 >= SCREENWIDTH)
x2 = SCREENWIDTH-1;
if (y2 >= SCREENHEIGHT)
y2 = SCREENHEIGHT-1;
/* number of rows to transfer */
ht = y2-y1+1;
/* number of columns to transfer (byte size) */
bytes_row = (x2-x1+1) * 2;
while (ht--) {
movefromscreen(bf, vadr, bytes_row);
vadr += SCREENWIDTH*2;
bf = (char *)bf + pitch_row;
}
}
/* -- write a rectangle of video memory from a save buffer -- */
void storevideo(RECT rc, void far *bf)
{
int x1 = RectLeft(rc);
int x2 = RectRight(rc);
int y1 = RectTop(rc);
int y2 = RectBottom(rc);
int ht;
int bytes_row;
int pitch_row = (x2-x1+1)*2;
unsigned long int vadr = vad(x1, y1);
/* perform clipping! */
if (x1 >= SCREENWIDTH ||
y1 >= SCREENHEIGHT)
return;
if (x2 >= SCREENWIDTH)
x2 = SCREENWIDTH-1;
if (y2 >= SCREENHEIGHT)
y2 = SCREENHEIGHT-1;
/* number of rows to transfer */
ht = y2-y1+1;
/* number of columns to transfer (byte size) */
bytes_row = (x2-x1+1) * 2;
while (ht--) {
movetoscreen(bf, vadr, bytes_row);
vadr += SCREENWIDTH*2;
bf = (char *)bf + pitch_row;
}
}
/* -------- read a character of video memory ------- */
unsigned int GetVideoChar(int x, int y)
{
return w32_get_video(x,y);
}
/* -------- write a character of video memory ------- */
void PutVideoChar(int x, int y, int c)
{
if (x < SCREENWIDTH && y < SCREENHEIGHT) {
w32_put_video(x, y, c);
}
}
BOOL CharInView(WINDOW wnd, int x, int y)
{
WINDOW nwnd = NextWindow(wnd);
WINDOW pwnd;
RECT rc;
int x1 = GetLeft(wnd)+x;
int y1 = GetTop(wnd)+y;
if (!TestAttribute(wnd, VISIBLE))
return FALSE;
if (!TestAttribute(wnd, NOCLIP)) {
WINDOW wnd1 = GetParent(wnd);
while (wnd1 != NULL) {
/* --- clip character to parent's borders -- */
if (!TestAttribute(wnd1, VISIBLE))
return FALSE;
if (!InsideRect(x1, y1, ClientRect(wnd1)))
return FALSE;
wnd1 = GetParent(wnd1);
}
}
while (nwnd != NULL) {
if (!isHidden(nwnd) && !isAncestor(wnd, nwnd)) {
rc = WindowRect(nwnd);
if (TestAttribute(nwnd, SHADOW)) {
RectBottom(rc)++;
RectRight(rc)++;
}
if (!TestAttribute(nwnd, NOCLIP)) {
pwnd = nwnd;
while (GetParent(pwnd)) {
pwnd = GetParent(pwnd);
rc = subRectangle(rc, ClientRect(pwnd));
}
}
if (InsideRect(x1,y1,rc))
return FALSE;
}
nwnd = NextWindow(nwnd);
}
return (x1 < SCREENWIDTH && y1 < SCREENHEIGHT);
}
/* -------- write a character to a window ------- */
void wputch(WINDOW wnd, int c, int x, int y)
{
if (CharInView(wnd, x, y)) {
int ch = (c & 255) | (clr(foreground, background) << 8);
int xc = GetLeft(wnd)+x;
int yc = GetTop(wnd)+y;
w32_put_video(xc, yc, ch);
}
}
/* ------- write a string to a window ---------- */
void wputs(WINDOW wnd, void *s, int x, int y)
{
int x1 = GetLeft(wnd)+x;
int x2 = x1;
int y1 = GetTop(wnd)+y;
if (x1 < SCREENWIDTH && y1 < SCREENHEIGHT && isVisible(wnd)) {
unsigned short int ln[200];
unsigned short int *cp1 = ln;
unsigned char *str = s;
int fg = foreground;
int bg = background;
int len;
int off = 0;
while (*str) {
if (*str == CHANGECOLOR) {
str++;
foreground = (*str++) & 0x7f;
background = (*str++) & 0x7f;
continue;
}
if (*str == RESETCOLOR) {
foreground = fg & 0x7f;
background = bg & 0x7f;
str++;
continue;
}
*cp1 = (*str & 255) | (clr(foreground, background) << 8);
if (ClipString)
if (!CharInView(wnd, x, y))
*cp1 = w32_get_video(x2,y1);
cp1++;
str++;
x++;
x2++;
}
foreground = fg;
background = bg;
len = (int)(cp1-ln);
if (x1+len > SCREENWIDTH)
len = SCREENWIDTH-x1;
if (!ClipString && !TestAttribute(wnd, NOCLIP)) {
/* -- clip the line to within ancestor windows -- */
RECT rc = WindowRect(wnd);
WINDOW nwnd = GetParent(wnd);
while (len > 0 && nwnd != NULL) {
if (!isVisible(nwnd)) {
len = 0;
break;
}
rc = subRectangle(rc, ClientRect(nwnd));
nwnd = GetParent(nwnd);
}
while (len > 0 && !InsideRect(x1+off,y1,rc)) {
off++;
--len;
}
if (len > 0) {
x2 = x1+len-1;
while (len && !InsideRect(x2,y1,rc)) {
--x2;
--len;
}
}
}
if (len > 0) {
movetoscreen(ln+off, vad(x1+off,y1), len*2);
}
}
}
/* --------- get the current video mode -------- */
void get_videomode(void)
{
}
/* --------- scroll the window. d: 1 = up, 0 = dn ---------- */
void scroll_window(WINDOW wnd, RECT rc, int d)
{
if (RectTop(rc) != RectBottom(rc)) {
if (d)
w32_scroll_up(RectLeft(rc), RectTop(rc),
RectRight(rc), RectBottom(rc),
clr(WndForeground(wnd),WndBackground(wnd))
);
else
w32_scroll_dw(RectLeft(rc), RectTop(rc),
RectRight(rc), RectBottom(rc),
clr(WndForeground(wnd),WndBackground(wnd))
);
}
}

View File

@@ -0,0 +1,64 @@
/* Little watch icon
*/
#include "dflat.h"
int WatchIconProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
{
int rtn;
static int tick = 0;
static char *hands[] = { " À ", " Ú ", " ª ", " Ù " };
switch (msg)
{
case CREATE_WINDOW:
tick = 0;
rtn = DefaultWndProc(wnd, msg, p1, p2);
SendMessage(wnd, CAPTURE_MOUSE, 0, 0);
SendMessage(wnd, HIDE_MOUSE, 0, 0);
SendMessage(wnd, CAPTURE_KEYBOARD, 0, 0);
SendMessage(wnd, CAPTURE_CLOCK, 0, 0);
return rtn;
case CLOCKTICK:
++tick;
tick &= 3;
SendMessage(wnd->PrevClock, msg, p1, p2);
/* (fall through and paint) */
case PAINT:
SetStandardColor(wnd);
writeline(wnd, hands[tick], 1, 1, FALSE);
return TRUE;
case BORDER:
rtn = DefaultWndProc(wnd, msg, p1, p2);
writeline(wnd, "Í", 2, 0, FALSE);
return rtn;
case MOUSE_MOVED:
SendMessage(wnd, HIDE_WINDOW, 0, 0);
SendMessage(wnd, MOVE, p1, p2);
SendMessage(wnd, SHOW_WINDOW, 0, 0);
return TRUE;
case CLOSE_WINDOW:
SendMessage(wnd, RELEASE_CLOCK, 0, 0);
SendMessage(wnd, RELEASE_MOUSE, 0, 0);
SendMessage(wnd, RELEASE_KEYBOARD, 0, 0);
SendMessage(wnd, SHOW_MOUSE, 0, 0);
break;
default:
break;
}
return DefaultWndProc(wnd, msg, p1, p2);
}
WINDOW WatchIcon(void)
{
int mx,my;
WINDOW wnd;
SendMessage(NULL, CURRENT_MOUSE_CURSOR, (PARAM) &mx, (PARAM) &my);
wnd = CreateWindow(BOX, NULL, mx, my, 3, 5, NULL,NULL,
WatchIconProc, VISIBLE | HASBORDER | SHADOW | SAVESELF);
return wnd;
}

View File

@@ -0,0 +1,526 @@
/* ---------- window.c ------------- */
#include "dflat.h"
WINDOW inFocus = NULL;
int foreground, background; /* current video colors */
static void TopLine(WINDOW, int, RECT);
/* --------- create a window ------------ */
WINDOW CreateWindow(
CLASS Class, /* class of this window */
const char *ttl, /* title or NULL */
int left, int top, /* upper left coordinates */
int height, int width, /* dimensions */
void *extension, /* pointer to additional data */
WINDOW parent, /* parent of this window */
int (*wndproc)(struct window *,enum messages,PARAM,PARAM),
int attrib) /* window attribute */
{
WINDOW wnd = DFcalloc(1, sizeof(struct window));
get_videomode();
if (wnd != NULL) {
int base;
/* ----- height, width = -1: fill the screen ------- */
if (height == -1)
height = SCREENHEIGHT;
if (width == -1)
width = SCREENWIDTH;
/* ----- coordinates -1, -1 = center the window ---- */
if (left == -1)
wnd->rc.lf = (SCREENWIDTH-width)/2;
else
wnd->rc.lf = left;
if (top == -1)
wnd->rc.tp = (SCREENHEIGHT-height)/2;
else
wnd->rc.tp = top;
wnd->attrib = attrib;
if (ttl != NULL)
if (*ttl != '\0')
AddAttribute(wnd, HASTITLEBAR);
if (wndproc == NULL)
wnd->wndproc = classdefs[Class].wndproc;
else
wnd->wndproc = wndproc;
/* ---- derive attributes of base classes ---- */
base = Class;
while (base != -1) {
AddAttribute(wnd, classdefs[base].attrib);
base = classdefs[base].base;
}
if (parent) {
if (!TestAttribute(wnd, NOCLIP)) {
/* -- keep upper left within borders of parent - */
wnd->rc.lf = max(wnd->rc.lf,GetClientLeft(parent));
wnd->rc.tp = max(wnd->rc.tp,GetClientTop(parent));
}
}
else
parent = ApplicationWindow;
wnd->Class = Class;
wnd->extension = extension;
wnd->rc.rt = GetLeft(wnd)+width-1;
wnd->rc.bt = GetTop(wnd)+height-1;
wnd->ht = height;
wnd->wd = width;
if (ttl != NULL)
InsertTitle(wnd, ttl);
wnd->parent = parent;
wnd->oldcondition = wnd->condition = ISRESTORED;
wnd->RestoredRC = wnd->rc;
InitWindowColors(wnd);
SendMessage(wnd, CREATE_WINDOW, 0, 0);
if (isVisible(wnd))
SendMessage(wnd, SHOW_WINDOW, 0, 0);
}
return wnd;
}
/* -------- add a title to a window --------- */
void AddTitle(WINDOW wnd, const char *ttl)
{
InsertTitle(wnd, ttl);
SendMessage(wnd, BORDER, 0, 0);
}
/* ----- insert a title into a window ---------- */
void InsertTitle(WINDOW wnd, const char *ttl)
{
wnd->title=DFrealloc(wnd->title,strlen(ttl)+1);
strcpy(wnd->title, ttl);
}
static unsigned char line[300];
/* ------ write a line to video window client area ------ */
void writeline(WINDOW wnd, char *str, int x, int y, BOOL pad)
{
char *cp;
int len;
int dif;
char wline[200];
memset(wline, 0, 200);
len = LineLength(str);
dif = strlen(str) - len;
strncpy(wline, str, ClientWidth(wnd) + dif);
if (pad) {
cp = wline+strlen(wline);
while (len++ < ClientWidth(wnd)-x)
*cp++ = ' ';
}
wputs(wnd, wline, x, y);
}
RECT AdjustRectangle(WINDOW wnd, RECT rc)
{
/* -------- adjust the rectangle ------- */
if (TestAttribute(wnd, HASBORDER)) {
if (RectLeft(rc) == 0)
--rc.rt;
else if (RectLeft(rc) < RectRight(rc) &&
RectLeft(rc) < WindowWidth(wnd)+1)
--rc.lf;
}
if (TestAttribute(wnd, HASBORDER | HASTITLEBAR)) {
if (RectTop(rc) == 0)
--rc.bt;
else if (RectTop(rc) < RectBottom(rc) &&
RectTop(rc) < WindowHeight(wnd)+1)
--rc.tp;
}
RectRight(rc) = max(RectLeft(rc),
min(RectRight(rc),WindowWidth(wnd)));
RectBottom(rc) = max(RectTop(rc),
min(RectBottom(rc),WindowHeight(wnd)));
return rc;
}
/* -------- display a window's title --------- */
void DisplayTitle(WINDOW wnd, RECT *rcc)
{
if (GetTitle(wnd) != NULL) {
int tlen = min(strlen(GetTitle(wnd)), WindowWidth(wnd)-2);
int tend = WindowWidth(wnd)-3-BorderAdj(wnd);
RECT rc;
if (rcc == NULL)
rc = RelativeWindowRect(wnd, WindowRect(wnd));
else
rc = *rcc;
rc = AdjustRectangle(wnd, rc);
if (SendMessage(wnd, TITLE, (PARAM) rcc, 0)) {
if (wnd == inFocus) {
foreground = cfg.clr[TITLEBAR] [HILITE_COLOR] [FG];
background = cfg.clr[TITLEBAR] [HILITE_COLOR] [BG];
}
else {
foreground = cfg.clr[TITLEBAR] [STD_COLOR] [FG];
background = cfg.clr[TITLEBAR] [STD_COLOR] [BG];
}
memset(line,' ',WindowWidth(wnd));
#ifdef INCLUDE_MINIMIZE
if (wnd->condition != ISMINIMIZED)
#endif
strncpy(line + ((WindowWidth(wnd)-2 - tlen) / 2),
wnd->title, tlen);
if (TestAttribute(wnd, CONTROLBOX))
line[2-BorderAdj(wnd)] = CONTROLBOXCHAR;
if (TestAttribute(wnd, MINMAXBOX)) {
switch (wnd->condition) {
case ISRESTORED:
#ifdef INCLUDE_MAXIMIZE
line[tend+1] = MAXPOINTER;
#endif
#ifdef INCLUDE_MINIMIZE
line[tend] = MINPOINTER;
#endif
break;
#ifdef INCLUDE_MINIMIZE
case ISMINIMIZED:
line[tend+1] = MAXPOINTER;
break;
#endif
#ifdef INCLUDE_MAXIMIZE
case ISMAXIMIZED:
#ifdef INCLUDE_MINIMIZE
line[tend] = MINPOINTER;
#endif
#ifdef INCLUDE_RESTORE
line[tend+1] = RESTOREPOINTER;
#endif
break;
#endif
default:
break;
}
}
line[RectRight(rc)+1] = line[tend+3] = '\0';
if (wnd != inFocus)
ClipString++;
writeline(wnd, line+RectLeft(rc),
RectLeft(rc)+BorderAdj(wnd),
0,
FALSE);
ClipString = 0;
}
}
}
#ifdef INCLUDE_MINIMIZE
#define MinTest() (wnd->condition == ISMINIMIZED) ||
#else
#define MinTest() /**/
#endif
#ifdef INCLUDE_MAXIMIZE
#define MaxTest() (wnd->condition == ISMAXIMIZED) ||
#else
#define MaxTest() /**/
#endif
#define NoShadow(wnd) \
(TestAttribute(wnd, SHADOW) == 0 || \
MinTest() \
MaxTest() \
cfg.mono)
/* --- display right border shadow character of a window --- */
static void near shadow_char(WINDOW wnd, int y)
{
int fg = foreground;
int bg = background;
int x = WindowWidth(wnd);
int c = videochar(GetLeft(wnd)+x, GetTop(wnd)+y);
if (NoShadow(wnd))
return;
foreground = DARKGRAY;
background = BLACK;
wputch(wnd, c, x, y);
foreground = fg;
background = bg;
}
/* --- display the bottom border shadow line for a window -- */
static void near shadowline(WINDOW wnd, RECT rc)
{
int i;
int y = GetBottom(wnd)+1;
int fg = foreground;
int bg = background;
if (NoShadow(wnd))
return;
for (i = 0; i < WindowWidth(wnd)+1; i++)
line[i] = videochar(GetLeft(wnd)+i, y);
line[i] = '\0';
foreground = DARKGRAY;
background = BLACK;
line[RectRight(rc)+1] = '\0';
if (RectLeft(rc) == 0)
rc.lf++;
ClipString++;
wputs(wnd, line+RectLeft(rc), RectLeft(rc),
WindowHeight(wnd));
--ClipString;
foreground = fg;
background = bg;
}
static RECT ParamRect(WINDOW wnd, RECT *rcc)
{
RECT rc;
if (rcc == NULL) {
rc = RelativeWindowRect(wnd, WindowRect(wnd));
if (TestAttribute(wnd, SHADOW)) {
rc.rt++;
rc.bt++;
}
}
else
rc = *rcc;
return rc;
}
void PaintShadow(WINDOW wnd)
{
int y;
RECT rc = ParamRect(wnd, NULL);
for (y = 1; y < WindowHeight(wnd); y++)
shadow_char(wnd, y);
shadowline(wnd, rc);
}
static unsigned int SeCorner(WINDOW wnd, unsigned int stdse)
{
if (TestAttribute(wnd, SIZEABLE) && wnd->condition == ISRESTORED)
return SIZETOKEN;
return stdse;
}
/* ------- display a window's border ----- */
void RepaintBorder(WINDOW wnd, RECT *rcc)
{
int y;
unsigned int lin, side, ne, nw, se, sw;
RECT rc, clrc;
if (!TestAttribute(wnd, HASBORDER))
return;
rc = ParamRect(wnd, rcc);
clrc = AdjustRectangle(wnd, rc);
if (wnd == inFocus) {
lin = FOCUS_LINE;
side = FOCUS_SIDE;
ne = FOCUS_NE;
nw = FOCUS_NW;
se = SeCorner(wnd, FOCUS_SE);
sw = FOCUS_SW;
}
else {
lin = LINE;
side = SIDE;
ne = NE;
nw = NW;
se = SeCorner(wnd, SE);
sw = SW;
}
line[WindowWidth(wnd)] = '\0';
/* ---------- window title ------------ */
if (TestAttribute(wnd, HASTITLEBAR))
if (RectTop(rc) == 0)
if (RectLeft(rc) < WindowWidth(wnd)-BorderAdj(wnd))
DisplayTitle(wnd, &rc);
foreground = FrameForeground(wnd);
background = FrameBackground(wnd);
/* -------- top frame corners --------- */
if (RectTop(rc) == 0) {
if (RectLeft(rc) == 0)
wputch(wnd, nw, 0, 0);
if (RectLeft(rc) < WindowWidth(wnd)) {
if (RectRight(rc) >= WindowWidth(wnd)-1)
wputch(wnd, ne, WindowWidth(wnd)-1, 0);
TopLine(wnd, lin, clrc);
}
}
/* ----------- window body ------------ */
for (y = RectTop(rc); y <= RectBottom(rc); y++) {
int ch;
if (y == 0 || y >= WindowHeight(wnd)-1)
continue;
if (RectLeft(rc) == 0)
wputch(wnd, side, 0, y);
if (RectLeft(rc) < WindowWidth(wnd) &&
RectRight(rc) >= WindowWidth(wnd)-1) {
if (TestAttribute(wnd, VSCROLLBAR))
ch = ( y == 1 ? UPSCROLLBOX :
y == WindowHeight(wnd)-2 ?
DOWNSCROLLBOX :
y-1 == wnd->VScrollBox ?
SCROLLBOXCHAR :
SCROLLBARCHAR );
else
ch = side;
wputch(wnd, ch, WindowWidth(wnd)-1, y);
}
if (RectRight(rc) == WindowWidth(wnd))
shadow_char(wnd, y);
}
if (RectTop(rc) <= WindowHeight(wnd)-1 &&
RectBottom(rc) >= WindowHeight(wnd)-1) {
/* -------- bottom frame corners ---------- */
if (RectLeft(rc) == 0)
wputch(wnd, sw, 0, WindowHeight(wnd)-1);
if (RectLeft(rc) < WindowWidth(wnd) &&
RectRight(rc) >= WindowWidth(wnd)-1)
wputch(wnd, se, WindowWidth(wnd)-1,
WindowHeight(wnd)-1);
if (wnd->StatusBar == NULL) {
/* ----------- bottom line ------------- */
memset(line,lin,WindowWidth(wnd)-1);
if (TestAttribute(wnd, HSCROLLBAR)) {
line[0] = LEFTSCROLLBOX;
line[WindowWidth(wnd)-3] = RIGHTSCROLLBOX;
memset(line+1, SCROLLBARCHAR, WindowWidth(wnd)-4);
line[wnd->HScrollBox] = SCROLLBOXCHAR;
}
line[WindowWidth(wnd)-2] = line[RectRight(rc)] = '\0';
if (RectLeft(rc) != RectRight(rc) ||
(RectLeft(rc) && RectLeft(rc) < WindowWidth(wnd)-1)) {
if (wnd != inFocus)
ClipString++;
writeline(wnd,
line+(RectLeft(clrc)),
RectLeft(clrc)+1,
WindowHeight(wnd)-1,
FALSE);
ClipString = 0;
}
}
if (RectRight(rc) == WindowWidth(wnd))
shadow_char(wnd, WindowHeight(wnd)-1);
}
if (RectBottom(rc) == WindowHeight(wnd))
/* ---------- bottom shadow ------------- */
shadowline(wnd, rc);
}
static void TopLine(WINDOW wnd, int lin, RECT rc)
{
if (TestAttribute(wnd, HASMENUBAR))
return;
if (TestAttribute(wnd, HASTITLEBAR) && GetTitle(wnd))
return;
if (RectLeft(rc) == 0) {
RectLeft(rc) += BorderAdj(wnd);
RectRight(rc) += BorderAdj(wnd);
}
if (RectRight(rc) < WindowWidth(wnd)-1)
RectRight(rc)++;
if (RectLeft(rc) < RectRight(rc)) {
/* ----------- top line ------------- */
memset(line,lin,WindowWidth(wnd)-1);
if (TestAttribute(wnd, CONTROLBOX)) {
strncpy(line+1, " ", 3);
*(line+2) = CONTROLBOXCHAR;
}
line[RectRight(rc)] = '\0';
writeline(wnd, line+RectLeft(rc),
RectLeft(rc), 0, FALSE);
}
}
/* ------ clear the data space of a window -------- */
void ClearWindow(WINDOW wnd, RECT *rcc, int clrchar)
{
if (isVisible(wnd)) {
int y;
RECT rc = rcc ? *rcc : RelativeWindowRect(wnd, WindowRect(wnd));
int top = TopBorderAdj(wnd);
int bot = WindowHeight(wnd)-1-BottomBorderAdj(wnd);
if (RectLeft(rc) == 0)
RectLeft(rc) = BorderAdj(wnd);
if (RectRight(rc) > WindowWidth(wnd)-1)
RectRight(rc) = WindowWidth(wnd)-1;
SetStandardColor(wnd);
memset(line, clrchar, sizeof line);
line[RectRight(rc)+1] = '\0';
for (y = RectTop(rc); y <= RectBottom(rc); y++) {
if (y < top || y > bot)
continue;
writeline(wnd,
line+(RectLeft(rc)),
RectLeft(rc),
y,
FALSE);
}
}
}
/* ------ compute the logical line length of a window ------ */
int LineLength(char *ln)
{
int len = strlen(ln);
char *cp = ln;
while ((cp = strchr(cp, CHANGECOLOR)) != NULL) {
cp++;
len -= 3;
}
cp = ln;
while ((cp = strchr(cp, RESETCOLOR)) != NULL) {
cp++;
--len;
}
return len;
}
void InitWindowColors(WINDOW wnd)
{
int fbg,col;
int cls = GetClass(wnd);
/* window classes without assigned colors inherit parent's colors */
if (cfg.clr[cls][0][0] == 0xff && GetParent(wnd) != NULL)
cls = GetClass(GetParent(wnd));
/* ---------- set the colors ---------- */
for (fbg = 0; fbg < 2; fbg++)
for (col = 0; col < 4; col++)
wnd->WindowColors[col][fbg] = cfg.clr[cls][col][fbg];
}
void PutWindowChar(WINDOW wnd, int c, int x, int y)
{
if (x < ClientWidth(wnd) && y < ClientHeight(wnd))
wputch(wnd, c, x+BorderAdj(wnd), y+TopBorderAdj(wnd));
}
void PutWindowLine(WINDOW wnd, void *s, int x, int y)
{
int saved = FALSE, sv;
if (x < ClientWidth(wnd) && y < ClientHeight(wnd)) {
char *en = (char *)s+ClientWidth(wnd)-x;
if (strlen(s)+x > ClientWidth(wnd)) {
sv = *en;
*en = '\0';
saved = TRUE;
}
ClipString++;
wputs(wnd, s, x+BorderAdj(wnd), y+TopBorderAdj(wnd));
--ClipString;
if (saved)
*en = sv;
}
}