Still working on making dflat32 a dll. Alot of this will be cleaned up in the
authorSteven Edwards <winehacker@gmail.com>
Sun, 14 Apr 2002 10:15:06 +0000 (10:15 +0000)
committerSteven Edwards <winehacker@gmail.com>
Sun, 14 Apr 2002 10:15:06 +0000 (10:15 +0000)
next few weeks. I'm going through the DFLAT api doc and fixing the export
names and then going to try to build a simple hello dflat application.

svn path=/trunk/; revision=2844

37 files changed:
rosapps/lib/dflat32/Makefile
rosapps/lib/dflat32/applicat.c [new file with mode: 0644]
rosapps/lib/dflat32/box.c [new file with mode: 0644]
rosapps/lib/dflat32/checkbox.c [new file with mode: 0644]
rosapps/lib/dflat32/clipbord.c
rosapps/lib/dflat32/config.c
rosapps/lib/dflat32/console.c
rosapps/lib/dflat32/decomp.c [new file with mode: 0644]
rosapps/lib/dflat32/dfalloc.c
rosapps/lib/dflat32/dflat32.def
rosapps/lib/dflat32/dialbox.c [new file with mode: 0644]
rosapps/lib/dflat32/dialogs.c [new file with mode: 0644]
rosapps/lib/dflat32/dllmain.c
rosapps/lib/dflat32/editbox.c [new file with mode: 0644]
rosapps/lib/dflat32/helpbox.c [new file with mode: 0644]
rosapps/lib/dflat32/keys.c [new file with mode: 0644]
rosapps/lib/dflat32/listbox.c [new file with mode: 0644]
rosapps/lib/dflat32/lists.c [new file with mode: 0644]
rosapps/lib/dflat32/log.c [new file with mode: 0644]
rosapps/lib/dflat32/menu.c [new file with mode: 0644]
rosapps/lib/dflat32/menubar.c [new file with mode: 0644]
rosapps/lib/dflat32/menus.c [new file with mode: 0644]
rosapps/lib/dflat32/message.c
rosapps/lib/dflat32/msgbox.c [new file with mode: 0644]
rosapps/lib/dflat32/normal.c [new file with mode: 0644]
rosapps/lib/dflat32/pictbox.c [new file with mode: 0644]
rosapps/lib/dflat32/popdown.c [new file with mode: 0644]
rosapps/lib/dflat32/radio.c [new file with mode: 0644]
rosapps/lib/dflat32/rect.c
rosapps/lib/dflat32/spinbutt.c [new file with mode: 0644]
rosapps/lib/dflat32/statbar.c [new file with mode: 0644]
rosapps/lib/dflat32/stubs.c
rosapps/lib/dflat32/sysmenu.c [new file with mode: 0644]
rosapps/lib/dflat32/text.c [new file with mode: 0644]
rosapps/lib/dflat32/video.c
rosapps/lib/dflat32/watch.c [new file with mode: 0644]
rosapps/lib/dflat32/window.c

index e34cd01..967be3b 100644 (file)
@@ -18,16 +18,42 @@ TARGET_BASE = 0x98000000
 TARGET_CFLAGS = # -pipe -O2 -Wall -Wstrict-prototypes -fno-builtin  -DDBG
 
 TARGET_OBJECTS = \
 TARGET_CFLAGS = # -pipe -O2 -Wall -Wstrict-prototypes -fno-builtin  -DDBG
 
 TARGET_OBJECTS = \
+applicat.o \
+box.o \
+checkbox.o \
 clipbord.o \
 config.o \
 console.o \
 clipbord.o \
 config.o \
 console.o \
-dllmain.o \
+decomp.o \
 dfalloc.o \
 dfalloc.o \
+dialbox.o \
+dialogs.o \
+dllmain.o \
+editbox.o \
+lists.o \
+helpbox.o \
+listbox.o \
+log.o \
 message.o \
 message.o \
+menu.o \
+menubar.o \
+menus.o \
+msgbox.o \
+normal.o \
+pictbox.o \
+popdown.o \
+keys.o \
+radio.o \
 rect.o \
 rect.o \
-stubs.o \
+spinbutt.o \
+statbar.o \
+stubs.o\
+sysmenu.o \
+text.o \
+textbox.o \
 video.o \
 video.o \
-window.o
+watch.o \
+window.o 
 
 include $(PATH_TO_TOP)/rules.mak
 
 
 include $(PATH_TO_TOP)/rules.mak
 
diff --git a/rosapps/lib/dflat32/applicat.c b/rosapps/lib/dflat32/applicat.c
new file mode 100644 (file)
index 0000000..fc1d886
--- /dev/null
@@ -0,0 +1,622 @@
+/* ------------- applicat.c ------------- */
+
+#include "dflat32/dflat.h"
+
+static BOOL DisplayModified = FALSE;
+DFWINDOW ApplicationWindow;
+
+extern DBOX Display;
+extern DBOX Windows;
+
+#ifdef INCLUDE_LOGGING
+extern DBOX Log;
+#endif
+
+#ifdef INCLUDE_SHELLDOS
+static void ShellDOS(DFWINDOW);
+#endif
+static void DfCreateMenu(DFWINDOW);
+static void CreateStatusBar(DFWINDOW);
+static void SelectColors(DFWINDOW);
+
+#ifdef INCLUDE_WINDOWOPTIONS
+static void SelectTexture(void);
+static void SelectBorder(DFWINDOW);
+static void SelectTitle(DFWINDOW);
+static void SelectStatusBar(DFWINDOW);
+#endif
+
+static DFWINDOW oldFocus;
+#ifdef INCLUDE_MULTI_WINDOWS
+static void CloseAll(DFWINDOW, int);
+static void MoreWindows(DFWINDOW);
+static void ChooseWindow(DFWINDOW, int);
+static int WindowSel;
+static char Menus[9][26] =
+{
+       "~1.                      ",
+       "~2.                      ",
+       "~3.                      ",
+       "~4.                      ",
+       "~5.                      ",
+       "~6.                      ",
+       "~7.                      ",
+       "~8.                      ",
+       "~9.                      "
+};
+#endif
+
+/* --------------- CREATE_WINDOW Message -------------- */
+static int CreateWindowMsg(DFWINDOW wnd)
+{
+       int rtn;
+
+       ApplicationWindow = wnd;
+#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
+    SelectColors(wnd);
+#ifdef INCLUDE_WINDOWOPTIONS
+    SelectBorder(wnd);
+    SelectTitle(wnd);
+    SelectStatusBar(wnd);
+#endif
+    rtn = BaseWndProc(APPLICATION, wnd, CREATE_WINDOW, 0, 0);
+    if (wnd->extension != NULL)
+        DfCreateMenu(wnd);
+    CreateStatusBar(wnd);
+    return rtn;
+}
+
+/* --------- ADDSTATUS Message ---------- */
+static void AddStatusMsg(DFWINDOW wnd, PARAM p1)
+{
+    if (wnd->StatusBar != NULL)    {
+        if (p1 && *(char *)p1)
+            DfSendMessage(wnd->StatusBar, SETTEXT, p1, 0);
+        else 
+            DfSendMessage(wnd->StatusBar, CLEARTEXT, 0, 0);
+        DfSendMessage(wnd->StatusBar, PAINT, 0, 0);
+    }
+}
+
+/* -------- SETFOCUS Message -------- */
+static void SetFocusMsg(DFWINDOW wnd, BOOL p1)
+{
+    if (p1)
+        DfSendMessage(inFocus, SETFOCUS, FALSE, 0);
+    inFocus = p1 ? wnd : NULL;
+       if (isVisible(wnd))
+           DfSendMessage(wnd, BORDER, 0, 0);
+       else 
+           DfSendMessage(wnd, SHOW_WINDOW, 0, 0);
+}
+
+/* ------- SIZE Message -------- */
+static void SizeMsg(DFWINDOW wnd, PARAM p1, PARAM p2)
+{
+    BOOL WasVisible;
+    WasVisible = isVisible(wnd);
+    if (WasVisible)
+        DfSendMessage(wnd, DFM_HIDE_WINDOW, 0, 0);
+    if (p1-GetLeft(wnd) < 30)
+        p1 = GetLeft(wnd) + 30;
+    BaseWndProc(APPLICATION, wnd, DFM_SIZE, p1, p2);
+    DfCreateMenu(wnd);
+    CreateStatusBar(wnd);
+    if (WasVisible)
+        DfSendMessage(wnd, SHOW_WINDOW, 0, 0);
+}
+
+/* ----------- KEYBOARD Message ------------ */
+static int KeyboardMsg(DFWINDOW wnd, PARAM p1, PARAM p2)
+{
+    if (WindowMoving || WindowSizing || (int) p1 == F1)
+        return BaseWndProc(APPLICATION, wnd, KEYBOARD, p1, p2);
+    switch ((int) p1)    {
+        case ALT_F4:
+            DfPostMessage(wnd, CLOSE_WINDOW, 0, 0);
+            return TRUE;
+#ifdef INCLUDE_MULTI_WINDOWS
+        case ALT_F6:
+            SetNextFocus();
+            return TRUE;
+#endif
+        case ALT_HYPHEN:
+            BuildSystemMenu(wnd);
+            return TRUE;
+        default:
+            break;
+    }
+    DfPostMessage(wnd->MenuBarWnd, KEYBOARD, p1, p2);
+    return TRUE;
+}
+
+/* --------- SHIFT_CHANGED Message -------- */
+static void ShiftChangedMsg(DFWINDOW wnd, PARAM p1)
+{
+       extern BOOL AltDown;
+    if ((int)p1 & ALTKEY)
+        AltDown = TRUE;
+    else if (AltDown)    {
+        AltDown = FALSE;
+        if (wnd->MenuBarWnd != inFocus)
+            DfSendMessage(NULL, HIDE_CURSOR, 0, 0);
+        DfSendMessage(wnd->MenuBarWnd, KEYBOARD, F10, 0);
+    }
+}
+
+/* -------- COMMAND Message ------- */
+static void CommandMsg(DFWINDOW 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 TESTING_DFLAT
+        case ID_LOADHELP:
+            LoadHelpFile();
+            break;
+#endif
+#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:
+            DfPostMessage(wnd, CLOSE_WINDOW, 0, 0);
+            break;
+        case ID_DISPLAY:
+            if (DfDialogBox(wnd, &Display, TRUE, NULL))    {
+                               if (inFocus == wnd->MenuBarWnd || inFocus == wnd->StatusBar)
+                                       oldFocus = ApplicationWindow;
+                               else 
+                                       oldFocus = inFocus;
+                DfSendMessage(wnd, DFM_HIDE_WINDOW, 0, 0);
+                SelectColors(wnd);
+#ifdef INCLUDE_WINDOWOPTIONS
+                SelectBorder(wnd);
+                SelectTitle(wnd);
+                SelectStatusBar(wnd);
+                SelectTexture();
+#endif
+                DfCreateMenu(wnd);
+                CreateStatusBar(wnd);
+                DfSendMessage(wnd, SHOW_WINDOW, 0, 0);
+                           DfSendMessage(oldFocus, SETFOCUS, TRUE, 0);
+            }
+            break;
+        case ID_SAVEOPTIONS:
+            SaveConfig();
+            break;
+#ifdef INCLUDE_MULTI_WINDOWS
+        case ID_WINDOW:
+            ChooseWindow(wnd, (int)p2-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, DFM_COMMAND, p1, p2);
+            break;
+        default:
+            if (inFocus != wnd->MenuBarWnd && inFocus != wnd)
+                DfPostMessage(inFocus, DFM_COMMAND, p1, p2);
+            break;
+    }
+}
+
+/* --------- CLOSE_WINDOW Message -------- */
+static int CloseWindowMsg(DFWINDOW wnd)
+{
+    int rtn;
+#ifdef INCLUDE_MULTI_WINDOWS
+    CloseAll(wnd, TRUE);
+       WindowSel = 0;
+#endif
+    DfPostMessage(NULL, DFM_STOP, 0, 0);
+    rtn = BaseWndProc(APPLICATION, wnd, CLOSE_WINDOW, 0, 0);
+    UnLoadHelpFile();
+       DisplayModified = FALSE;
+       ApplicationWindow = NULL;
+    return rtn;
+}
+
+/* --- APPLICATION Window Class window processing module --- */
+int ApplicationProc(DFWINDOW wnd, DFMESSAGE msg, PARAM p1, PARAM p2)
+{
+    switch (msg)
+    {
+        case CREATE_WINDOW:
+            return CreateWindowMsg(wnd);
+        case DFM_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 DFM_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))    {
+#ifdef INCLUDE_WINDOWOPTIONS
+                int cl = cfg.Texture ? APPLCHAR : ' ';
+#else
+                int cl = APPLCHAR;
+#endif
+                ClearWindow(wnd, (DFRECT *)p1, cl);
+            }
+            return TRUE;
+        case DFM_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)
+{
+    DfSendMessage(NULL, SAVE_CURSOR, 0, 0);
+    SwapCursorStack();
+    DfSendMessage(NULL, RESTORE_CURSOR, 0, 0);
+}
+
+/* ------- Shell out to DOS ---------- */
+static void ShellDOS(DFWINDOW wnd)
+{
+       oldFocus = inFocus;
+    DfSendMessage(wnd, DFM_HIDE_WINDOW, 0, 0);
+    SwitchCursor();
+    printf("To return to %s, execute the DOS exit command.",
+                    DFlatApplication);
+    fflush(stdout);
+    _spawnl(P_WAIT, getenv("COMSPEC"), " ", NULL);
+    SwitchCursor();
+       DfSendMessage(wnd, SHOW_WINDOW, 0, 0);
+    DfSendMessage(oldFocus, SETFOCUS, TRUE, 0);
+}
+#endif
+
+/* -------- Create the menu bar -------- */
+static void DfCreateMenu(DFWINDOW wnd)
+{
+    AddAttribute(wnd, HASMENUBAR);
+    if (wnd->MenuBarWnd != NULL)
+        DfSendMessage(wnd->MenuBarWnd, CLOSE_WINDOW, 0, 0);
+    wnd->MenuBarWnd = DfCreateWindow(MENUBAR,
+                        NULL,
+                        GetClientLeft(wnd),
+                        GetClientTop(wnd)-1,
+                        1,
+                        ClientWidth(wnd),
+                        NULL,
+                        wnd,
+                        NULL,
+                        0);
+    DfSendMessage(wnd->MenuBarWnd,BUILDMENU,
+        (PARAM)wnd->extension,0);
+    AddAttribute(wnd->MenuBarWnd, VISIBLE);
+}
+
+/* ----------- Create the status bar ------------- */
+static void CreateStatusBar(DFWINDOW wnd)
+{
+    if (wnd->StatusBar != NULL)    {
+        DfSendMessage(wnd->StatusBar, CLOSE_WINDOW, 0, 0);
+        wnd->StatusBar = NULL;
+    }
+    if (TestAttribute(wnd, HASSTATUSBAR))    {
+        wnd->StatusBar = DfCreateWindow(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(DFWINDOW 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)
+{
+    DFWINDOW wnd = w;
+    struct PopDown *p0 = mnu->Selections;
+    struct PopDown *pd = mnu->Selections + 2;
+    struct PopDown *ca = mnu->Selections + 13;
+    int MenuNo = 0;
+    DFWINDOW cwnd;
+
+       mnu->Selection = 0;
+       oldFocus = NULL;
+
+       if (GetClass(wnd) != APPLICATION)
+       {
+               oldFocus = wnd;
+
+               /* point to the APPLICATION window */
+               if (ApplicationWindow == NULL)
+                       return;
+
+               cwnd = FirstWindow(ApplicationWindow);
+               /* get the first 9 document windows */
+               while (cwnd != NULL && MenuNo < 9)
+               {
+                       if (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(DFWINDOW wnd,DFMESSAGE msg,PARAM p1,PARAM p2)
+{
+    switch (msg)    {
+        case INITIATE_DIALOG:    {
+            DFWINDOW wnd1;
+            DFWINDOW cwnd = ControlWindow(&Windows,ID_WINDOWLIST);
+            int sel = 0;
+            if (cwnd == NULL)
+                return FALSE;
+                       wnd1 = FirstWindow(ApplicationWindow);
+                       while (wnd1 != NULL)    {
+                if (wnd1 != wnd && GetClass(wnd1) != MENUBAR &&
+                        GetClass(wnd1) != STATUSBAR)    {
+                    if (wnd1 == oldFocus)
+                        WindowSel = sel;
+                    DfSendMessage(cwnd, ADDTEXT,
+                        (PARAM) WindowName(wnd1), 0);
+                    sel++;
+                }
+                               wnd1 = NextWindow(wnd1);
+            }
+            DfSendMessage(cwnd, LB_SETSELECTION, WindowSel, 0);
+            AddAttribute(cwnd, VSCROLLBAR);
+            DfPostMessage(cwnd, SHOW_WINDOW, 0, 0);
+            break;
+        }
+        case DFM_COMMAND:
+            switch ((int) p1)    {
+                case ID_OK:
+                    if ((int)p2 == 0)
+                        WindowSel = DfSendMessage(
+                                    ControlWindow(&Windows,
+                                    ID_WINDOWLIST),
+                                    LB_CURRENTSELECTION, 0, 0);
+                    break;
+                case ID_WINDOWLIST:
+                    if ((int) p2 == LB_CHOOSE)
+                        DfSendMessage(wnd, DFM_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(DFWINDOW wnd)
+{
+    if (DfDialogBox(wnd, &Windows, TRUE, WindowPrep))
+        ChooseWindow(wnd, WindowSel);
+}
+
+/* ----- user chose a window from the Window menu
+        or the More Window dialog box ----- */
+static void ChooseWindow(DFWINDOW wnd, int WindowNo)
+{
+    DFWINDOW cwnd = FirstWindow(wnd);
+       while (cwnd != NULL)
+       {
+        if (GetClass(cwnd) != MENUBAR &&
+                GetClass(cwnd) != STATUSBAR)
+            if (WindowNo-- == 0)
+                break;
+               cwnd = NextWindow(cwnd);
+    }
+    if (cwnd != NULL)    {
+        DfSendMessage(cwnd, SETFOCUS, TRUE, 0);
+        if (cwnd->condition == ISMINIMIZED)
+            DfSendMessage(cwnd, RESTORE, 0, 0);
+    }
+}
+
+/* ----- Close all document windows ----- */
+static void CloseAll(DFWINDOW wnd, int closing)
+{
+       DFWINDOW wnd1, wnd2;
+
+       DfSendMessage(wnd, SETFOCUS, TRUE, 0);
+       wnd1 = LastWindow(wnd);
+       while (wnd1 != NULL)
+       {
+               wnd2 = PrevWindow(wnd1);
+               if (GetClass(wnd1) != MENUBAR && GetClass(wnd1) != STATUSBAR)
+               {
+                       ClearVisible(wnd1);
+                       DfSendMessage(wnd1, CLOSE_WINDOW, 0, 0);
+               }
+               wnd1 = wnd2;
+       }
+       if (!closing)
+               DfSendMessage(wnd, PAINT, 0, 0);
+}
+
+#endif    /* #ifdef INCLUDE_MULTI_WINDOWS */
+
+static void DoWindowColors(DFWINDOW wnd)
+{
+       DFWINDOW cwnd;
+
+       InitWindowColors(wnd);
+       cwnd = FirstWindow(wnd);
+       while (cwnd != NULL)
+       {
+               DoWindowColors(cwnd);
+               if (GetClass(cwnd) == TEXT && GetText(cwnd) != NULL)
+                       DfSendMessage(cwnd, CLEARTEXT, 0, 0);
+               cwnd = NextWindow(cwnd);
+       }
+}
+
+/* set up colors for the application window */
+static void SelectColors(DFWINDOW wnd)
+{
+       memcpy(cfg.clr, color, sizeof color);
+       DoWindowColors(wnd);
+}
+
+
+#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(DFWINDOW 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(DFWINDOW 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(DFWINDOW wnd)
+{
+    cfg.Title = CheckBoxSetting(&Display, ID_TITLE);
+    if (cfg.Title)
+        AddAttribute(wnd, HASTITLEBAR);
+    else
+        ClearAttribute(wnd, HASTITLEBAR);
+}
+
+#endif
+
+/* EOF */
diff --git a/rosapps/lib/dflat32/box.c b/rosapps/lib/dflat32/box.c
new file mode 100644 (file)
index 0000000..7db2566
--- /dev/null
@@ -0,0 +1,44 @@
+/* ----------- box.c ------------ */
+
+#include "dflat32/dflat.h"
+
+int BoxProc(DFWINDOW wnd, DFMESSAGE msg, PARAM p1, PARAM p2)
+{
+       int rtn;
+       DFWINDOW oldFocus;
+       CTLWINDOW *ct = GetControl(wnd);
+       static BOOL SettingFocus = FALSE;
+       if (ct != NULL)
+       {
+               switch (msg)
+               {
+                       case SETFOCUS:
+                               SettingFocus = isVisible(wnd);
+                               rtn = BaseWndProc(BOX, wnd, msg, p1, p2);
+                               SettingFocus = FALSE;
+                               return rtn;
+
+            case PAINT:
+                return FALSE;
+            case LEFT_BUTTON:
+            case DFM_BUTTON_RELEASED:
+                return DfSendMessage(GetParent(wnd), msg, p1, p2);
+            case BORDER:
+                               if (SettingFocus)
+                                       return TRUE;
+                               oldFocus = inFocus;
+                               inFocus = NULL;
+                               rtn = BaseWndProc(BOX, wnd, msg, p1, p2);
+                               inFocus = oldFocus;
+                if (ct != NULL)
+                    if (ct->itext != NULL)
+                        writeline(wnd, ct->itext, 1, 0, FALSE);
+                               return rtn;
+            default:
+                break;
+        }
+    }
+    return BaseWndProc(BOX, wnd, msg, p1, p2);
+}
+
+/* EOF */
diff --git a/rosapps/lib/dflat32/checkbox.c b/rosapps/lib/dflat32/checkbox.c
new file mode 100644 (file)
index 0000000..0a8238b
--- /dev/null
@@ -0,0 +1,49 @@
+/* -------------- checkbox.c ------------ */
+
+#include "dflat32/dflat.h"
+
+int CheckBoxProc(DFWINDOW wnd, DFMESSAGE msg, PARAM p1, PARAM p2)
+{
+    int rtn;
+    CTLWINDOW *ct = GetControl(wnd);
+    if (ct != NULL)    {
+        switch (msg)    {
+            case SETFOCUS:
+                if (!(int)p1)
+                    DfSendMessage(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';
+                DfSendMessage(wnd, CLEARTEXT, 0, 0);
+                DfSendMessage(wnd, ADDTEXT, (PARAM) cb, 0);
+                SetFocusCursor(wnd);
+                break;
+            }
+            case KEYBOARD:
+                if ((int)p1 != ' ')
+                    break;
+            case LEFT_BUTTON:
+                ct->setting ^= ON;
+                DfSendMessage(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);
+    if (ct != NULL)
+        return (ct->isetting == ON);
+    return FALSE;
+}
+
+/* EOF */
index 6007f5d..c2e4bb9 100644 (file)
@@ -1,9 +1,5 @@
-/* ----------- clipbord.c ------------ 
- * Clipbord funcations. 
- *
- * sedwards
- */
-#include <dflat32\dflat.h>
+/* ----------- clipbord.c ------------ */
+#include "dflat32/dflat.h"
 
 char *Clipboard;
 unsigned ClipboardLength;
 
 char *Clipboard;
 unsigned ClipboardLength;
index d72f886..2d2b1e6 100644 (file)
@@ -1,6 +1,6 @@
 /* ------------- config.c ------------- */
 
 /* ------------- config.c ------------- */
 
-#include <dflat32/dflat.h>
+#include "dflat32/dflat.h"
 
 /* ----- default colors for color video system ----- */
 unsigned char color[CLASSCOUNT] [4] [2] = {
 
 /* ----- default colors for color video system ----- */
 unsigned char color[CLASSCOUNT] [4] [2] = {
@@ -440,7 +440,6 @@ CONFIG cfg = {
        55                               /* Bottom printer margin               */
 };
 
        55                               /* Bottom printer margin               */
 };
 
-char **Argv;
 void BuildFileName(char *path, char *ext)
 {
        extern char **Argv;
 void BuildFileName(char *path, char *ext)
 {
        extern char **Argv;
index 848a230..b4035fc 100644 (file)
@@ -1,10 +1,10 @@
 /* ----------- console.c ---------- */
 
 /* ----------- console.c ---------- */
 
-//#define WIN32_LEAN_AND_MEAN
+// #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 
 
 #include <windows.h>
 
 
-#include <dflat32/dflat.h>
+#include "dflat32/dflat.h"
 
 
 /* ----- table of alt keys for finding shortcut keys ----- */
 
 
 /* ----- table of alt keys for finding shortcut keys ----- */
diff --git a/rosapps/lib/dflat32/decomp.c b/rosapps/lib/dflat32/decomp.c
new file mode 100644 (file)
index 0000000..64211fe
--- /dev/null
@@ -0,0 +1,134 @@
+/* ------------------- decomp.c -------------------- */
+
+/*
+ * Decompress the application.HLP file
+ * or load the application.TXT file if the .HLP file
+ * does not exist
+ */
+
+#include "dflat32/dflat.h"
+#include "dflat32/htree.h"
+
+static int in8;
+static int ct8 = 8;
+static FILE *fi;
+static BYTECOUNTER bytectr;
+static int LoadingASCII;
+struct htr *HelpTree;
+static int root;
+
+/* ------- open the help database file -------- */
+FILE *OpenHelpFile(void)
+{
+    char *cp;
+    int treect, i;
+    char helpname[65];
+
+    /* -------- get the name of the help file ---------- */
+    BuildFileName(helpname, ".hlp");
+    LoadingASCII = FALSE;
+    if ((fi = fopen(helpname, "rb")) == NULL)    {
+        /* ---- no .hlp file, look for .txt file ---- */
+        if ((cp = strrchr(helpname, '.')) != NULL)    {
+            strcpy(cp, ".TXT");
+            fi = fopen(helpname, "rt");
+        }
+        if (fi == NULL)
+            return NULL;
+        LoadingASCII = TRUE;
+    }
+
+    if (!LoadingASCII && HelpTree == NULL)    {
+           /* ----- read the byte count ------ */
+           fread(&bytectr, sizeof bytectr, 1, fi);
+           /* ----- read the frequency count ------ */
+           fread(&treect, sizeof treect, 1, fi);
+           /* ----- read the root offset ------ */
+           fread(&root, sizeof root, 1, fi);
+        HelpTree = DFcalloc(treect-256, sizeof(struct htr));
+        /* ---- read in the tree --- */
+        for (i = 0; i < treect-256; i++)    {
+               fread(&HelpTree[i].left,  sizeof(int), 1, fi);
+            fread(&HelpTree[i].right, sizeof(int), 1, fi);
+        }
+    }
+    return fi;
+}
+
+/* ----- read a line of text from the help database ----- */
+void *GetHelpLine(char *line)
+{
+    int h;
+    if (LoadingASCII)  {
+               void *hp;
+               do
+                       hp = fgets(line, 160, fi);
+               while (*line == ';');
+               return hp;
+       }
+    *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')
+            continue;    /* skip the '\r' character */
+        /* --- put the character in the buffer --- */
+        *line++ = h;
+        /* --- if '\n', end of line --- */
+        if (h == '\n')
+            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 (LoadingASCII)
+        *bit = 0;
+    else    {
+        if (ct8 < 8)
+            --*offset;
+        *bit = ct8;
+    }
+}
+
+/* -- position the database to the specified byte and bit -- */
+void SeekHelpLine(long offset, int bit)
+{
+    int i;
+    fseek(fi, offset, 0);
+    if (!LoadingASCII)    {
+        ct8 = bit;
+        if (ct8 < 8)    {
+            in8 = fgetc(fi);
+            for (i = 0; i < bit; i++)
+                in8 <<= 1;
+        }
+    }
+}
+
+
index deb2f7a..4c0c2d0 100644 (file)
@@ -1,15 +1,9 @@
-/* ---------- dfalloc.c ---------- 
- * This seems simple enough, if a AllocationError occors
- * then try to handle it in a somewhat clean fashion.
- *
- * Dont ask I didnt write it. - sedwards
- */
-
-/* #define WIN32_LEAN_AND_MEAN         Removed for ROS */      
+/* ---------- dfalloc.c ---------- */
 
 
+//#define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 
 #include <windows.h>
 
-#include <dflat32/dflat.h>
+#include "dflat32/dflat.h"
 
 static void AllocationError(void)
 {
 
 static void AllocationError(void)
 {
index 04a2b33..ec5cff6 100644 (file)
 ;
 ;
-; ReactOS dflat32 COnsole Windowing Library
+; ReactOS dflat32 Console Windowing Library
 ;
 LIBRARY DFLAT32.DLL
 
 EXPORTS
 ;
 LIBRARY DFLAT32.DLL
 
 EXPORTS
-AllocError                     ; dfalloc.c
-AltConvert                     ; console.c
-beep                           ; console.c
-cursor                         ; console.c
-curr_cursor                    ; console.c
-CopyTextToClipboard            ; clipbord.c
-CopyToClipboard                        ; clipbord.c
-ClearClipboard                 ; clipbord.c
-DFcalloc                       ; dfalloc.c
-DFmalloc                       ; dfalloc.c
-DFrealloc                      ; dfalloc.c
-GetKey                         ; console.c
-getshift                       ; console.c
-hidecursor                     ; console.c
-normalcursor                   ; console.c
-PasteText                      ; clipbord.c
-restorecursor                  ; console.c
-savecursor                     ; console.c
-set_cursor_size                        ; console.c
-SetStandardColor               ; config.c
-SetReverseColor                        ; config.c
-SwapCursorStack                        ; console.c
-unhidecursor                   ; console.c
-; Update this stuff below from message.c
-DfDispatchMessage              ; message.c
-handshake                      ; message.c
-DfSendMessage                  ; message.c
-DfPostMessage                  ; message.c
-DfTerminate                    ; message.c
-DfInitialize                   ; message.c
-DfGetScreenWidth               ; message.c
-DfGetScreenHeight              ; message.c
-; Update this stuff below from Rect.c 
-subRectangle
-ClientRect
-RelativeWindowRect
-ClipRectangle
-; stuff from video.c
-GetVideo
-StoreVideo
-GetVideoChar
-PutVideoChar
+DfCreateWindow         
+DfInitialize                    ;message.c             
+DfPostMessage                   ;message.c
+DfSendMessage                   ;message.c
+DfDispatchMessage               ;message.c
+handshake                       ;message.c
+TestCriticalError              ;stubs.c
+;DefaultWndProc         
+;BaseWndProc            
+;WindowHeight           
+;WindowWidth            
+;ClientWidth            
+;ClientHeight           
+;GetTop                        
+;GetBottom             
+;GetLeft                       
+;GetRight              
+;GetClientTop          
+;GetClientBottom               
+;GetClientLeft         
+;GetClientRight                
+;GetParent             
+;FirstWindow
+;LastWindow 
+;NextWindow
+;PrevWindow 
 CharInView
 CharInView
-wputch
-wputs
-scroll_window
-; stuff from window.c
-DfCreateWindow
+;TopBorderAdj
+;BorderAdj
+;GetTitle
 AddTitle
 AddTitle
-InsertTitle
-writeline
-AdjustRectangle
-DisplayTitle
-PaintShadow
-RepaintBorder
-ClearWindow
-LineLength
-InitWindowColors
-PutWindowChar
+;GetClass
+;GetAttribute
+;AddAttribute
+;ClearAttribute
+;TestAttribute
+isVisible                      ;normal.o
+;GetText
+;GetTextLines
+;TextLine
+;SetProtected
+isActive
+GetCommandText
+ActivateCommand
+DeactivateCommand
+GetCommandToggle
+SetCommandToggle
+ClearCommandToggle
+InvertCommandToggle
+ItemSelected
+;DialogBox
+ControlWindow
+;MessageBox
+;CancelBox
+;ErrorMessage
+;TestErrorMessage
+;YesNoBox
+MomentaryMessage
+InputBox
+;SliderBox
+RadioButtonSetting
+;EnableButton
+;DisableButton
+;ButtonEnabled
+PutItemText
+;PutComboListText
+GetItemText
+;GetEditBoxText
+;GetComboBoxText
+;SetEditBoxText
+;SetComboBoxText
+;GetDlgText
+;SetDlgText
+;GetDlgTextBox
+;SetDlgTextBox
+;SetCheckBox
+;ClearCheckBox
+CheckBoxSetting
+;SetDlgTitle
+LoadHelpFile
+DisplayHelp                            ;helpbox.o
+;HelpComment
+UnLoadHelpFile                         ;helpbox.o
+;SearchText
+;ReplaceText
+;SearchNext
+WriteTextLine
 PutWindowLine
 PutWindowLine
-; exports from the stubs
-classdefs
\ No newline at end of file
+PutWindowChar
+DrawVector
+DrawBox
+DrawBar
+;WindowClientColor
+;WindowReverseColor
+;WindowFrameColor
+;WindowHighlightColor
+MarkTextBlock
+;ClearTextBlock
+CopyToClipboard                        ;clipbord.o
+CopyTextToClipboard                    ;clipbord.o
+PasteText                               ;clipbord.o
+ClearClipboard                         ;clipbord.o
+WatchIcon                               ;watch.o
+;
+;
+;
+; Everything below here is not part of the dflat32 api (documentation)
+DfTerminate
+LoadConfig
diff --git a/rosapps/lib/dflat32/dialbox.c b/rosapps/lib/dflat32/dialbox.c
new file mode 100644 (file)
index 0000000..8cec719
--- /dev/null
@@ -0,0 +1,792 @@
+/* ----------------- dialbox.c -------------- */
+
+#include "dflat32/dflat.h"
+
+static int inFocusCommand(DBOX *);
+static void dbShortcutKeys(DBOX *, int);
+static int ControlProc(DFWINDOW, DFMESSAGE, 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 == COMBOBOX) &&
+                           ct->itext != NULL)
+                       {
+                               free(ct->itext);
+                       }
+                       ct++;
+               }
+       }
+
+       if (dbs != NULL)
+       {
+               free(dbs);
+               dbs = NULL;
+       }
+       dbct = 0;
+}
+
+
+/* -------- CREATE_WINDOW Message --------- */
+static int CreateWindowMsg(DFWINDOW wnd, PARAM p1, PARAM p2)
+{
+    DBOX *db = wnd->extension;
+    CTLWINDOW *ct = db->ctl;
+    DFWINDOW 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 = DfCreateWindow(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 == COMBOBOX) &&
+                    ct->itext != NULL)
+            DfSendMessage(cwnd, SETTEXT, (PARAM) ct->itext, 0);
+        ct++;
+    }
+    return rtn;
+}
+
+/* -------- LEFT_BUTTON Message --------- */
+static BOOL LeftButtonMsg(DFWINDOW 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))) {
+        DfPostMessage(wnd, KEYBOARD, ' ', ALTKEY);
+        return TRUE;
+    }
+    while (ct->class)    {
+        DFWINDOW cwnd = ct->wnd;
+        if (ct->class == COMBOBOX)    {
+            if (p2 == GetTop(cwnd))    {
+                if (p1 == GetRight(cwnd)+1)    {
+                    DfSendMessage(cwnd, LEFT_BUTTON, p1, p2);
+                    return TRUE;
+                }
+            }
+            if (GetClass(inFocus) == LISTBOX)
+                DfSendMessage(wnd, SETFOCUS, TRUE, 0);
+        }
+        else if (ct->class == SPINBUTTON)    {
+            if (p2 == GetTop(cwnd))    {
+                if (p1 == GetRight(cwnd)+1 ||
+                        p1 == GetRight(cwnd)+2)    {
+                    DfSendMessage(cwnd, LEFT_BUTTON, p1, p2);
+                    return TRUE;
+                }
+            }
+        }
+        ct++;
+    }
+    return FALSE;
+}
+
+/* -------- KEYBOARD Message --------- */
+static BOOL KeyboardMsg(DFWINDOW 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 BS:
+        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);
+            }
+            break;
+        case CTRL_F4:
+        case ESC:
+            DfSendMessage(wnd, DFM_COMMAND, ID_CANCEL, 0);
+            break;
+        default:
+            /* ------ search all the shortcut keys ----- */
+            dbShortcutKeys(db, (int) p1);
+            break;
+    }
+    return wnd->Modal;
+}
+
+/* -------- COMMAND Message --------- */
+static BOOL CommandMsg(DFWINDOW 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)
+                DfPostMessage(wnd, ENDDIALOG, 0, 0);
+            else
+                DfSendMessage(wnd, CLOSE_WINDOW, TRUE, 0);
+            return TRUE;
+        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(DFWINDOW wnd, DFMESSAGE 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;
+            DfSendMessage(wnd, DFM_COMMAND, inFocusCommand(db), msg);
+            break;
+        case DFM_COMMAND:
+            if (CommandMsg(wnd, p1, p2))
+                return TRUE;
+            break;
+        case PAINT:
+            p2 = TRUE;
+            break;
+               case MOVE:
+               case DFM_SIZE:
+                       rtn = BaseWndProc(DIALOG, wnd, msg, p1, p2);
+                       if (wnd->dfocus != NULL)
+                               DfSendMessage(wnd->dfocus, SETFOCUS, TRUE, 0);
+                       return rtn;
+
+               case CLOSE_WINDOW:
+                       if (!p1)
+                       {
+                DfSendMessage(wnd, DFM_COMMAND, ID_CANCEL, 0);
+                return TRUE;
+            }
+            break;
+
+        default:
+            break;
+    }
+    return BaseWndProc(DIALOG, wnd, msg, p1, p2);
+}
+
+/* ------- create and execute a dialog box ---------- */
+BOOL DfDialogBox(DFWINDOW wnd, DBOX *db, BOOL Modal,
+  int (*wndproc)(struct window *, enum messages, PARAM, PARAM))
+{
+    BOOL rtn;
+    int x = db->dwnd.x, y = db->dwnd.y;
+    DFWINDOW DialogWnd;
+
+    if (!Modal && wnd != NULL)
+    {
+        x += GetLeft(wnd);
+        y += GetTop(wnd);
+    }
+    DialogWnd = DfCreateWindow(DIALOG,
+                        db->dwnd.title,
+                        x, y,
+                        db->dwnd.h,
+                        db->dwnd.w,
+                        db,
+                        wnd,
+                        wndproc,
+                        Modal ? SAVESELF : 0);
+    DialogWnd->Modal = Modal;
+    FirstFocus(db);
+    DfPostMessage(DialogWnd, INITIATE_DIALOG, 0, 0);
+    if (Modal)
+    {
+        DfSendMessage(DialogWnd, CAPTURE_MOUSE, 0, 0);
+        DfSendMessage(DialogWnd, CAPTURE_KEYBOARD, 0, 0);
+        while (DfDispatchMessage ())
+            ;
+        rtn = DialogWnd->ReturnCode == ID_OK;
+        DfSendMessage(DialogWnd, RELEASE_MOUSE, 0, 0);
+        DfSendMessage(DialogWnd, RELEASE_KEYBOARD, 0, 0);
+        DfSendMessage(DialogWnd, CLOSE_WINDOW, TRUE, 0);
+        return rtn;
+    }
+    return FALSE;
+}
+
+/* ----- 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 (ct->class == class)
+            if (cmd == ct->command)
+                return ct;
+        ct++;
+    }
+    return NULL;
+}
+
+/* ---- return the window handle of a specified command ---- */
+DFWINDOW ControlWindow(DBOX *db, enum commands cmd)
+{
+    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, DFWINDOW 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;
+       }
+}
+
+/* ---- return pointer to the text of a control window ---- */
+char *GetDlgTextString(DBOX *db,enum commands cmd,DFCLASS 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, DFCLASS class)
+{
+    CTLWINDOW *ct = FindCommand(db, cmd, class);
+    if (ct != NULL)    {
+        ct->itext = DFrealloc(ct->itext, strlen(text)+1);
+        strcpy(ct->itext, text);
+    }
+}
+
+/* ------- set the text of a control window ------ */
+void PutItemText(DFWINDOW 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)        {
+        DFWINDOW cwnd = (DFWINDOW) (ct->wnd);
+        switch (ct->class)    {
+            case COMBOBOX:
+            case EDITBOX:
+                DfSendMessage(cwnd, CLEARTEXT, 0, 0);
+                DfSendMessage(cwnd, ADDTEXT, (PARAM) text, 0);
+                if (!isMultiLine(cwnd))
+                    DfSendMessage(cwnd, PAINT, 0, 0);
+                break;
+            case LISTBOX:
+            case TEXTBOX:
+            case SPINBUTTON:
+                DfSendMessage(cwnd, ADDTEXT, (PARAM) text, 0);
+                break;
+            case TEXT:    {
+                DfSendMessage(cwnd, CLEARTEXT, 0, 0);
+                DfSendMessage(cwnd, ADDTEXT, (PARAM) text, 0);
+                DfSendMessage(cwnd, PAINT, 0, 0);
+                break;
+            }
+            default:
+                break;
+        }
+    }
+}
+
+/* ------- get the text of a control window ------ */
+void GetItemText(DFWINDOW 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)    {
+        DFWINDOW cwnd = (DFWINDOW) (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:
+                    DfSendMessage(cwnd,GETTEXT,(PARAM)text,len);
+                    break;
+                default:
+                    break;
+            }
+        }
+    }
+}
+
+/* ------- set the text of a listbox control window ------ */
+void GetDlgListText(DFWINDOW wnd, char *text, enum commands cmd)
+{
+    CTLWINDOW *ct = FindCommand(wnd->extension, cmd, LISTBOX);
+    int sel = DfSendMessage(ct->wnd, LB_CURRENTSELECTION, 0, 0);
+    DfSendMessage(ct->wnd, DFM_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 void 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;
+                        DfSendMessage(ct->wnd, PAINT, 0, 0);
+                    }
+                    else if (ct->class)    {
+                        DfSendMessage(ct->wnd, SETFOCUS, TRUE, 0);
+                        if (ct->class == BUTTON)
+                           DfSendMessage(ct->wnd,KEYBOARD,'\r',0);
+                    }
+                    return;
+                }
+                cp++;
+            }
+            ct++;
+        }
+    }
+}
+
+/* --- dynamically add or remove scroll bars
+                            from a control window ---- */
+void SetScrollBars(DFWINDOW 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)
+        DfSendMessage(wnd, BORDER, 0, 0);
+}
+
+/* ------- CREATE_WINDOW Message (Control) ----- */
+static void CtlCreateWindowMsg(DFWINDOW wnd)
+{
+    CTLWINDOW *ct;
+    ct = wnd->ct = wnd->extension;
+    wnd->extension = NULL;
+    if (ct != NULL)
+        ct->wnd = wnd;
+}
+
+/* ------- KEYBOARD Message (Control) ----- */
+static BOOL CtlKeyboardMsg(DFWINDOW wnd, PARAM p1, PARAM p2)
+{
+    CTLWINDOW *ct = GetControl(wnd);
+    switch ((int) p1)    {
+        case F1:
+            if (WindowMoving || WindowSizing)
+                break;
+            if (!DisplayHelp(wnd, ct->help))
+                DfSendMessage(GetParent(wnd),DFM_COMMAND,ID_HELP,0);
+            return TRUE;
+        case ' ':
+            if (!((int)p2 & ALTKEY))
+                break;
+        case ALT_F6:
+        case CTRL_F4:
+        case ALT_F4:
+            DfPostMessage(GetParent(wnd), KEYBOARD, p1, p2);
+            return TRUE;
+        default:
+            break;
+    }
+    if (GetClass(wnd) == EDITBOX)
+        if (isMultiLine(wnd))
+            return FALSE;
+    switch ((int) p1)    {
+        case UP:
+            if (!isDerivedFrom(wnd, LISTBOX))    {
+                p1 = CTRL_FIVE;
+                p2 = LEFTSHIFT;
+            }
+            break;
+        case BS:
+            if (!isDerivedFrom(wnd, EDITBOX))    {
+                p1 = CTRL_FIVE;
+                p2 = LEFTSHIFT;
+            }
+            break;
+        case DN:
+            if (!isDerivedFrom(wnd, LISTBOX) &&
+                    !isDerivedFrom(wnd, COMBOBOX))
+                p1 = '\t';
+            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;
+            DfSendMessage(GetParent(wnd), DFM_COMMAND, ID_OK, 0);
+            return TRUE;
+        default:
+            break;
+    }
+    return FALSE;
+}
+
+/* ------- CLOSE_WINDOW Message (Control) ----- */
+static void CtlCloseWindowMsg(DFWINDOW wnd)
+{
+    CTLWINDOW *ct = GetControl(wnd);
+    if (ct != NULL)    {
+        ct->wnd = NULL;
+        if (GetParent(wnd)->ReturnCode == ID_OK)       {
+            if (ct->class == EDITBOX || ct->class == COMBOBOX) {
+               if (wnd->TextChanged)    {
+                       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(DFWINDOW wnd)
+{
+       CTLWINDOW *ct = wnd->ct;
+
+       if (ct->class != BUTTON)
+       {
+               if (ct->class != SPINBUTTON && ct->class != COMBOBOX)
+               {
+                       wnd->WindowColors[FRAME_COLOR][FG] = 
+                               GetParent(wnd)->WindowColors[FRAME_COLOR][FG];
+                       wnd->WindowColors[FRAME_COLOR][BG] = 
+                               GetParent(wnd)->WindowColors[FRAME_COLOR][BG];
+                       if (ct->class != EDITBOX && ct->class != LISTBOX)
+                       {
+                               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(DFWINDOW wnd,DFMESSAGE 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)    {
+                DFWINDOW oldFocus = inFocus;
+                inFocus = NULL;
+                DefaultWndProc(wnd, msg, p1, p2);
+                inFocus = oldFocus;
+                return TRUE;
+            }
+            break;
+        case SETFOCUS: {
+                       DFWINDOW pwnd = GetParent(wnd);
+                       if (p1)
+                       {
+                               DefaultWndProc(wnd, msg, p1, p2);
+                               if (pwnd != NULL)
+                               {
+                                       pwnd->dfocus = wnd;
+                                       DfSendMessage(pwnd, DFM_COMMAND,
+                                               inFocusCommand(db), ENTERFOCUS);
+                               }
+                return TRUE;
+            }
+            else
+                DfSendMessage(pwnd, DFM_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;
+               }
+               DfSendMessage(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);
+               DfSendMessage(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);
+               DfSendMessage(ct->wnd, SETFOCUS, TRUE, 0);
+       }
+}
+
+void SetFocusCursor(DFWINDOW wnd)
+{
+       if (wnd == inFocus)
+       {
+               DfSendMessage(NULL, SHOW_CURSOR, 0, 0);
+               DfSendMessage(wnd, KEYBOARD_CURSOR, 1, 0);
+       }
+}
+
+/* EOF */
diff --git a/rosapps/lib/dflat32/dialogs.c b/rosapps/lib/dflat32/dialogs.c
new file mode 100644 (file)
index 0000000..c1577e1
--- /dev/null
@@ -0,0 +1,160 @@
+/* ----------- dialogs.c --------------- */
+
+#include "dflat32/dflat.h"
+
+/* -------------- the File Open dialog box --------------- */
+DIALOGBOX( FileOpen )
+    DB_TITLE(        "Open File",    -1,-1,19,48)
+    CONTROL(TEXT,    "~Filename",     2, 1, 1, 8, ID_FILENAME)
+    CONTROL(EDITBOX, NULL,           13, 1, 1,29, ID_FILENAME)
+    CONTROL(TEXT,    "Directory:",    2, 3, 1,10, 0)
+    CONTROL(TEXT,    NULL,           13, 3, 1,28, ID_PATH)
+    CONTROL(TEXT,    "F~iles",        2, 5, 1, 5, ID_FILES)
+    CONTROL(LISTBOX, NULL,            2, 6,11,16, ID_FILES)
+    CONTROL(TEXT,    "~Directories", 19, 5, 1,11, ID_DRIVE)
+    CONTROL(LISTBOX, NULL,           19, 6,11,16, ID_DRIVE)
+    CONTROL(BUTTON,  "   ~OK   ",    36, 7, 1, 8, ID_OK)
+    CONTROL(BUTTON,  " ~Cancel ",    36,10, 1, 8, ID_CANCEL)
+    CONTROL(BUTTON,  "  ~Help  ",    36,13, 1, 8, ID_HELP)
+ENDDB
+
+/* -------------- the Save As dialog box --------------- */
+DIALOGBOX( SaveAs )
+    DB_TITLE(        "Save As",    -1,-1,19,48)
+    CONTROL(TEXT,    "~Filename",   2, 1, 1, 8, ID_FILENAME)
+    CONTROL(EDITBOX, NULL,         13, 1, 1,29, ID_FILENAME)
+    CONTROL(TEXT,    "Directory:",  2, 3, 1,10, 0)
+    CONTROL(TEXT,    NULL,         13, 3, 1,28, ID_PATH)
+    CONTROL(TEXT,    "~Directories",2, 5, 1,11, ID_DRIVE)
+    CONTROL(LISTBOX, NULL,          2, 6,11,16, ID_DRIVE)
+    CONTROL(BUTTON,  "   ~OK   ",  36, 7, 1, 8, ID_OK)
+    CONTROL(BUTTON,  " ~Cancel ",  36,10, 1, 8, ID_CANCEL)
+    CONTROL(BUTTON,  "  ~Help  ",  36,13, 1, 8, ID_HELP)
+ENDDB
+
+/* -------------- The Printer Setup dialog box ------------------ */
+DIALOGBOX( PrintSetup )
+       DB_TITLE( "Printer 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(        "Search Text",    -1,-1,9,48)
+    CONTROL(TEXT,    "~Search for:",          2, 1, 1, 11, ID_SEARCHFOR)
+    CONTROL(EDITBOX, NULL,                   14, 1, 1, 29, ID_SEARCHFOR)
+    CONTROL(TEXT, "~Match upper/lower 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 Text",    -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 upper/lower case:", 2, 5, 1, 23, ID_MATCHCASE)
+       CONTROL(CHECKBOX,  NULL,                 26, 5, 1,  3, ID_MATCHCASE)
+    CONTROL(TEXT, "Replace ~Every Match:",    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)
+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
+
+
+/* ------------ Display dialog box -------------- */
+DIALOGBOX( Display )
+    DB_TITLE(     "Display", -1, -1, 12, 35)
+
+       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)
+
+    CONTROL(BUTTON, "   ~OK   ",   2, 8,1,8,ID_OK)
+    CONTROL(BUTTON, " ~Cancel ",  12, 8,1,8,ID_CANCEL)
+    CONTROL(BUTTON, "  ~Help  ",  22, 8,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(    "D-Flat 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
+
+/* EOF */
\ No newline at end of file
index d034661..9036d9b 100644 (file)
@@ -1,7 +1,7 @@
 /* 
 /* 
- * 
  * ReactOS DFLAT32.DLL
  */
  * ReactOS DFLAT32.DLL
  */
+
 #include <windows.h>
 BOOLEAN __stdcall DllMain(
        PVOID   hinstDll,
 #include <windows.h>
 BOOLEAN __stdcall DllMain(
        PVOID   hinstDll,
diff --git a/rosapps/lib/dflat32/editbox.c b/rosapps/lib/dflat32/editbox.c
new file mode 100644 (file)
index 0000000..91562de
--- /dev/null
@@ -0,0 +1,1113 @@
+/* ------------- editbox.c ------------ */
+#include "dflat32/dflat.h"
+
+#define EditBufLen(wnd) (isMultiLine(wnd) ? EDITLEN : ENTRYLEN)
+#define SetLinePointer(wnd, ln) (wnd->CurrLine = ln)
+#define isWhite(c)     ((c)==' '||(c)=='\n')
+/* ---------- local prototypes ----------- */
+static void SaveDeletedText(DFWINDOW, char *, int);
+static void Forward(DFWINDOW);
+static void Backward(DFWINDOW);
+static void End(DFWINDOW);
+static void Home(DFWINDOW);
+static void Downward(DFWINDOW);
+static void Upward(DFWINDOW);
+static void StickEnd(DFWINDOW);
+static void NextWord(DFWINDOW);
+static void PrevWord(DFWINDOW);
+static void ModTextPointers(DFWINDOW, int, int);
+static void SetAnchor(DFWINDOW, int, int);
+/* -------- local variables -------- */
+static BOOL KeyBoardMarking, ButtonDown;
+static BOOL TextMarking;
+static int ButtonX, ButtonY;
+static int PrevY = -1;
+
+/* ----------- CREATE_WINDOW Message ---------- */
+static int CreateWindowMsg(DFWINDOW wnd)
+{
+    int rtn = BaseWndProc(EDITBOX, wnd, CREATE_WINDOW, 0, 0);
+    wnd->MaxTextLength = MAXTEXTLEN+1;
+    wnd->textlen = EditBufLen(wnd);
+    wnd->InsertMode = TRUE;
+       DfSendMessage(wnd, CLEARTEXT, 0, 0);
+    return rtn;
+}
+/* ----------- SETTEXT Message ---------- */
+static int SetTextMsg(DFWINDOW wnd, PARAM p1)
+{
+    int rtn = FALSE;
+    if (strlen((char *)p1) <= wnd->MaxTextLength)
+        rtn = BaseWndProc(EDITBOX, wnd, SETTEXT, p1, 0);
+    return rtn;
+}
+/* ----------- CLEARTEXT Message ------------ */
+static int ClearTextMsg(DFWINDOW wnd)
+{
+    int rtn = BaseWndProc(EDITBOX, wnd, CLEARTEXT, 0, 0);
+    unsigned blen = EditBufLen(wnd)+2;
+    wnd->text = DFrealloc(wnd->text, blen);
+    memset(wnd->text, 0, blen);
+    wnd->wlines = 0;
+    wnd->CurrLine = 0;
+    wnd->CurrCol = 0;
+    wnd->WndRow = 0;
+    wnd->wleft = 0;
+    wnd->wtop = 0;
+    wnd->textwidth = 0;
+    wnd->TextChanged = FALSE;
+    return rtn;
+}
+/* ----------- ADDTEXT Message ---------- */
+static int AddTextMsg(DFWINDOW wnd, PARAM p1, PARAM p2)
+{
+    int rtn = FALSE;
+    if (strlen((char *)p1)+wnd->textlen <= wnd->MaxTextLength) {
+        rtn = BaseWndProc(EDITBOX, wnd, ADDTEXT, p1, p2);
+        if (rtn != FALSE)    {
+            if (!isMultiLine(wnd))    {
+                wnd->CurrLine = 0;
+                wnd->CurrCol = strlen((char *)p1);
+                if (wnd->CurrCol >= ClientWidth(wnd))    {
+                    wnd->wleft = wnd->CurrCol-ClientWidth(wnd);
+                    wnd->CurrCol -= wnd->wleft;
+                }
+                wnd->BlkEndCol = wnd->CurrCol;
+                DfSendMessage(wnd, KEYBOARD_CURSOR,
+                                     WndCol, wnd->WndRow);
+            }
+        }
+    }
+    return rtn;
+}
+/* ----------- GETTEXT Message ---------- */
+static int GetTextMsg(DFWINDOW wnd, PARAM p1, PARAM p2)
+{
+    char *cp1 = (char *)p1;
+    char *cp2 = wnd->text;
+    if (cp2 != NULL)    {
+        while (p2-- && *cp2 && *cp2 != '\n')
+            *cp1++ = *cp2++;
+        *cp1 = '\0';
+        return TRUE;
+    }
+    return FALSE;
+}
+/* ----------- SETTEXTLENGTH Message ---------- */
+static int SetTextLengthMsg(DFWINDOW wnd, unsigned int len)
+{
+    if (++len < MAXTEXTLEN)    {
+        wnd->MaxTextLength = len;
+        if (len < wnd->textlen)    {
+            wnd->text=DFrealloc(wnd->text, len+2);
+            wnd->textlen = len;
+            *((wnd->text)+len) = '\0';
+            *((wnd->text)+len+1) = '\0';
+            BuildTextPointers(wnd);
+        }
+        return TRUE;
+    }
+    return FALSE;
+}
+/* ----------- KEYBOARD_CURSOR Message ---------- */
+static void KeyboardCursorMsg(DFWINDOW wnd, PARAM p1, PARAM p2)
+{
+    wnd->CurrCol = (int)p1 + wnd->wleft;
+    wnd->WndRow = (int)p2;
+    wnd->CurrLine = (int)p2 + wnd->wtop;
+    if (wnd == inFocus)        {
+               if (CharInView(wnd, (int)p1, (int)p2))
+               DfSendMessage(NULL, SHOW_CURSOR,
+                               (wnd->InsertMode && !TextMarking), 0);
+       else
+                       DfSendMessage(NULL, HIDE_CURSOR, 0, 0);
+       }
+}
+/* ----------- SIZE Message ---------- */
+int SizeMsg(DFWINDOW wnd, PARAM p1, PARAM p2)
+{
+    int rtn = BaseWndProc(EDITBOX, wnd, DFM_SIZE, p1, p2);
+    if (WndCol > ClientWidth(wnd)-1)
+        wnd->CurrCol = ClientWidth(wnd)-1 + wnd->wleft;
+    if (wnd->WndRow > ClientHeight(wnd)-1)    {
+        wnd->WndRow = ClientHeight(wnd)-1;
+        SetLinePointer(wnd, wnd->WndRow+wnd->wtop);
+    }
+    DfSendMessage(wnd, KEYBOARD_CURSOR, WndCol, wnd->WndRow);
+    return rtn;
+}
+/* ----------- SCROLL Message ---------- */
+static int ScrollMsg(DFWINDOW wnd, PARAM p1)
+{
+    int rtn = FALSE;
+    if (isMultiLine(wnd))    {
+        rtn = BaseWndProc(EDITBOX,wnd,SCROLL,p1,0);
+        if (rtn != FALSE)    {
+            if (p1)    {
+                /* -------- scrolling up --------- */
+                if (wnd->WndRow == 0)    {
+                    wnd->CurrLine++;
+                    StickEnd(wnd);
+                }
+                else
+                    --wnd->WndRow;
+            }
+            else    {
+                /* -------- scrolling down --------- */
+                if (wnd->WndRow == ClientHeight(wnd)-1)    {
+                    if (wnd->CurrLine > 0)
+                        --wnd->CurrLine;
+                    StickEnd(wnd);
+                }
+                else
+                    wnd->WndRow++;
+            }
+            DfSendMessage(wnd,KEYBOARD_CURSOR,WndCol,wnd->WndRow);
+        }
+    }
+    return rtn;
+}
+/* ----------- HORIZSCROLL Message ---------- */
+static int HorizScrollMsg(DFWINDOW wnd, PARAM p1)
+{
+    int rtn = FALSE;
+    char *currchar = CurrChar;
+    if (!(p1 &&
+            wnd->CurrCol == wnd->wleft && *currchar == '\n'))  {
+        rtn = BaseWndProc(EDITBOX, wnd, HORIZSCROLL, p1, 0);
+        if (rtn != FALSE)    {
+            if (wnd->CurrCol < wnd->wleft)
+                wnd->CurrCol++;
+            else if (WndCol == ClientWidth(wnd))
+                --wnd->CurrCol;
+            DfSendMessage(wnd,KEYBOARD_CURSOR,WndCol,wnd->WndRow);
+        }
+    }
+    return rtn;
+}
+/* ----------- SCROLLPAGE Message ---------- */
+static int ScrollPageMsg(DFWINDOW wnd, PARAM p1)
+{
+    int rtn = FALSE;
+    if (isMultiLine(wnd))    {
+        rtn = BaseWndProc(EDITBOX, wnd, SCROLLPAGE, p1, 0);
+        SetLinePointer(wnd, wnd->wtop+wnd->WndRow);
+        StickEnd(wnd);
+        DfSendMessage(wnd, KEYBOARD_CURSOR,WndCol, wnd->WndRow);
+    }
+    return rtn;
+}
+/* ----------- HORIZSCROLLPAGE Message ---------- */
+static int HorizPageMsg(DFWINDOW wnd, PARAM p1)
+{
+    int rtn = BaseWndProc(EDITBOX, wnd, HORIZPAGE, p1, 0);
+    if ((int) p1 == FALSE)    {
+        if (wnd->CurrCol > wnd->wleft+ClientWidth(wnd)-1)
+            wnd->CurrCol = wnd->wleft+ClientWidth(wnd)-1;
+    }
+    else if (wnd->CurrCol < wnd->wleft)
+        wnd->CurrCol = wnd->wleft;
+    DfSendMessage(wnd, KEYBOARD_CURSOR, WndCol, wnd->WndRow);
+    return rtn;
+}
+/* ----- Extend the marked block to the new x,y position ---- */
+static void ExtendBlock(DFWINDOW wnd, int x, int y)
+{
+    int bbl, bel;
+    int ptop = min(wnd->BlkBegLine, wnd->BlkEndLine);
+    int pbot = max(wnd->BlkBegLine, wnd->BlkEndLine);
+    char *lp = TextLine(wnd, wnd->wtop+y);
+    int len = (int) (strchr(lp, '\n') - lp);
+    x = max(0, min(x, len));
+    y = max(0, y);
+    wnd->BlkEndCol = min(len, x+wnd->wleft);
+    wnd->BlkEndLine = y+wnd->wtop;
+    DfSendMessage(wnd, KEYBOARD_CURSOR, wnd->BlkEndCol, wnd->BlkEndLine);
+    bbl = min(wnd->BlkBegLine, wnd->BlkEndLine);
+    bel = max(wnd->BlkBegLine, wnd->BlkEndLine);
+    while (ptop < bbl)    {
+        WriteTextLine(wnd, NULL, ptop, FALSE);
+        ptop++;
+    }
+    for (y = bbl; y <= bel; y++)
+        WriteTextLine(wnd, NULL, y, FALSE);
+    while (pbot > bel)    {
+        WriteTextLine(wnd, NULL, pbot, FALSE);
+        --pbot;
+    }
+}
+/* ----------- LEFT_BUTTON Message ---------- */
+static int LeftButtonMsg(DFWINDOW wnd, PARAM p1, PARAM p2)
+{
+    int MouseX = (int) p1 - GetClientLeft(wnd);
+    int MouseY = (int) p2 - GetClientTop(wnd);
+    DFRECT rc = ClientRect(wnd);
+    char *lp;
+    int len;
+    if (KeyBoardMarking)
+        return TRUE;
+    if (WindowMoving || WindowSizing)
+        return FALSE;
+    if (isMultiLine(wnd))    {
+        if (TextMarking)    {
+            if (!InsideRect(p1, p2, rc))    {
+                               int x = MouseX, y = MouseY;
+                               int dir;
+                               DFMESSAGE msg = 0;
+                if ((int)p2 == GetTop(wnd))
+                                       y++, dir = FALSE, msg = SCROLL;
+                else if ((int)p2 == GetBottom(wnd))
+                                       --y, dir = TRUE, msg = SCROLL;
+                else if ((int)p1 == GetLeft(wnd))
+                                       --x, dir = FALSE, msg = HORIZSCROLL;
+                else if ((int)p1 == GetRight(wnd))
+                                       x++, dir = TRUE, msg = HORIZSCROLL;
+                               if (msg != 0)   {
+                    if (DfSendMessage(wnd, msg, dir, 0))
+                        ExtendBlock(wnd, x, y);
+                       DfSendMessage(wnd, PAINT, 0, 0);
+                               }
+            }
+            return TRUE;
+        }
+        if (!InsideRect(p1, p2, rc))
+            return FALSE;
+        if (TextBlockMarked(wnd))    {
+            ClearTextBlock(wnd);
+            DfSendMessage(wnd, PAINT, 0, 0);
+        }
+        if (wnd->wlines)    {
+            if (MouseY > wnd->wlines-1)
+                return TRUE;
+            lp = TextLine(wnd, MouseY+wnd->wtop);
+            len = (int) (strchr(lp, '\n') - lp);
+            MouseX = min(MouseX, len);
+            if (MouseX < wnd->wleft)    {
+                MouseX = 0;
+                DfSendMessage(wnd, KEYBOARD, HOME, 0);
+            }
+            ButtonDown = TRUE;
+            ButtonX = MouseX;
+            ButtonY = MouseY;
+        }
+        else
+            MouseX = MouseY = 0;
+        wnd->WndRow = MouseY;
+        SetLinePointer(wnd, MouseY+wnd->wtop);
+    }
+    if (isMultiLine(wnd) ||
+        (!TextBlockMarked(wnd)
+            && (int)(MouseX+wnd->wleft) < (int)strlen(wnd->text)))
+        wnd->CurrCol = MouseX+wnd->wleft;
+    DfSendMessage(wnd, KEYBOARD_CURSOR, WndCol, wnd->WndRow);
+    return TRUE;
+}
+/* ----------- MOUSE_MOVED Message ---------- */
+static int MouseMovedMsg(DFWINDOW wnd, PARAM p1, PARAM p2)
+{
+    int MouseX = (int) p1 - GetClientLeft(wnd);
+    int MouseY = (int) p2 - GetClientTop(wnd);
+    DFRECT rc = ClientRect(wnd);
+    if (!InsideRect(p1, p2, rc))
+        return FALSE;
+    if (MouseY > wnd->wlines-1)
+        return FALSE;
+    if (ButtonDown)    {
+        SetAnchor(wnd, ButtonX+wnd->wleft, ButtonY+wnd->wtop);
+        TextMarking = TRUE;
+               rc = WindowRect(wnd);
+        DfSendMessage(NULL,MOUSE_TRAVEL,(PARAM) &rc, 0);
+        ButtonDown = FALSE;
+    }
+    if (TextMarking && !(WindowMoving || WindowSizing))    {
+        ExtendBlock(wnd, MouseX, MouseY);
+        return TRUE;
+    }
+    return FALSE;
+}
+static void StopMarking(DFWINDOW wnd)
+{
+    TextMarking = FALSE;
+    if (wnd->BlkBegLine > wnd->BlkEndLine)    {
+        swap(wnd->BlkBegLine, wnd->BlkEndLine);
+        swap(wnd->BlkBegCol, wnd->BlkEndCol);
+    }
+    if (wnd->BlkBegLine == wnd->BlkEndLine &&
+            wnd->BlkBegCol > wnd->BlkEndCol)
+        swap(wnd->BlkBegCol, wnd->BlkEndCol);
+}
+/* ----------- BUTTON_RELEASED Message ---------- */
+static int ButtonReleasedMsg(DFWINDOW wnd)
+{
+    if (isMultiLine(wnd))    {
+        ButtonDown = FALSE;
+        if (TextMarking && !(WindowMoving || WindowSizing))  {
+            /* release the mouse ouside the edit box */
+            DfSendMessage(NULL, MOUSE_TRAVEL, 0, 0);
+            StopMarking(wnd);
+            return TRUE;
+        }
+        else
+            PrevY = -1;
+    }
+    return FALSE;
+}
+/* ---- Process text block keys for multiline text box ---- */
+static void DoMultiLines(DFWINDOW wnd, int c, PARAM p2)
+{
+    if (isMultiLine(wnd) && !KeyBoardMarking)    {
+        if ((int)p2 & (LEFTSHIFT | RIGHTSHIFT))    {
+            switch (c)    {
+                case HOME:
+                case CTRL_HOME:
+                case CTRL_BS:
+                case PGUP:
+                case CTRL_PGUP:
+                case UP:
+                case BS:
+                case END:
+                case CTRL_END:
+                case PGDN:
+                case CTRL_PGDN:
+                case DN:
+                case FWD:
+                case CTRL_FWD:
+                    KeyBoardMarking = TextMarking = TRUE;
+                    SetAnchor(wnd, wnd->CurrCol, wnd->CurrLine);
+                    break;
+                default:
+                    break;
+            }
+        }
+    }
+}
+/* ---------- page/scroll keys ----------- */
+static int DoScrolling(DFWINDOW wnd, int c, PARAM p2)
+{
+    switch (c)    {
+        case PGUP:
+        case PGDN:
+            if (isMultiLine(wnd))
+                BaseWndProc(EDITBOX, wnd, KEYBOARD, c, p2);
+            break;
+        case CTRL_PGUP:
+        case CTRL_PGDN:
+            BaseWndProc(EDITBOX, wnd, KEYBOARD, c, p2);
+            break;
+        case HOME:
+            Home(wnd);
+            break;
+        case END:
+            End(wnd);
+            break;
+        case CTRL_FWD:
+            NextWord(wnd);
+            break;
+        case CTRL_BS:
+            PrevWord(wnd);
+            break;
+        case CTRL_HOME:
+            if (isMultiLine(wnd))    {
+                DfSendMessage(wnd, SCROLLDOC, TRUE, 0);
+                wnd->CurrLine = 0;
+                wnd->WndRow = 0;
+            }
+            Home(wnd);
+            break;
+        case CTRL_END:
+                       if (isMultiLine(wnd) &&
+                                       wnd->WndRow+wnd->wtop+1 < wnd->wlines
+                                               && wnd->wlines > 0) {
+                DfSendMessage(wnd, SCROLLDOC, FALSE, 0);
+                SetLinePointer(wnd, wnd->wlines-1);
+                wnd->WndRow =
+                    min(ClientHeight(wnd)-1, wnd->wlines-1);
+                Home(wnd);
+            }
+            End(wnd);
+            break;
+        case UP:
+            if (isMultiLine(wnd))
+                Upward(wnd);
+            break;
+        case DN:
+            if (isMultiLine(wnd))
+                Downward(wnd);
+            break;
+        case FWD:
+            Forward(wnd);
+            break;
+        case BS:
+            Backward(wnd);
+            break;
+        default:
+            return FALSE;
+    }
+    if (!KeyBoardMarking && TextBlockMarked(wnd))    {
+        ClearTextBlock(wnd);
+        DfSendMessage(wnd, PAINT, 0, 0);
+    }
+    DfSendMessage(wnd, KEYBOARD_CURSOR, WndCol, wnd->WndRow);
+    return TRUE;
+}
+/* -------------- Del key ---------------- */
+static void DelKey(DFWINDOW wnd)
+{
+    char *currchar = CurrChar;
+    int repaint = *currchar == '\n';
+    if (TextBlockMarked(wnd))    {
+        DfSendMessage(wnd, DFM_COMMAND, ID_DELETETEXT, 0);
+        DfSendMessage(wnd, PAINT, 0, 0);
+        return;
+    }
+    if (isMultiLine(wnd) && *currchar == '\n' && *(currchar+1) == '\0')
+        return;
+    strcpy(currchar, currchar+1);
+    if (repaint)    {
+        BuildTextPointers(wnd);
+        DfSendMessage(wnd, PAINT, 0, 0);
+    }
+    else    {
+        ModTextPointers(wnd, wnd->CurrLine+1, -1);
+        WriteTextLine(wnd, NULL, wnd->WndRow+wnd->wtop, FALSE);
+    }
+    wnd->TextChanged = TRUE;
+}
+/* ------------ Tab key ------------ */
+static void TabKey(DFWINDOW wnd, PARAM p2)
+{
+    if (isMultiLine(wnd))    {
+        int insmd = wnd->InsertMode;
+        do  {
+            char *cc = CurrChar+1;
+            if (!insmd && *cc == '\0')
+                break;
+            if (wnd->textlen == wnd->MaxTextLength)
+                break;
+            DfSendMessage(wnd,KEYBOARD,insmd ? ' ' : FWD,0);
+        } while (wnd->CurrCol % cfg.Tabs);
+    }
+       else
+           DfPostMessage(GetParent(wnd), KEYBOARD, '\t', p2);
+}
+/* ------------ Shift+Tab key ------------ */
+static void ShiftTabKey(DFWINDOW wnd, PARAM p2)
+{
+    if (isMultiLine(wnd))    {
+        do  {
+            if (CurrChar == GetText(wnd))
+                break;
+            DfSendMessage(wnd,KEYBOARD,BS,0);
+        } while (wnd->CurrCol % cfg.Tabs);
+    }
+       else
+           DfPostMessage(GetParent(wnd), KEYBOARD, SHIFT_HT, p2);
+}
+/* --------- All displayable typed keys ------------- */
+static void KeyTyped(DFWINDOW wnd, int c)
+{
+    char *currchar = CurrChar;
+    if ((c != '\n' && c < ' ') || (c & 0x1000))
+        /* ---- not recognized by editor --- */
+        return;
+    if (!isMultiLine(wnd) && TextBlockMarked(wnd))    {
+               DfSendMessage(wnd, CLEARTEXT, 0, 0);
+        currchar = CurrChar;
+    }
+    /* ---- test typing at end of text ---- */
+    if (currchar == wnd->text+wnd->MaxTextLength)    {
+        /* ---- typing at the end of maximum buffer ---- */
+        beep();
+        return;
+    }
+    if (*currchar == '\0')    {
+        /* --- insert a newline at end of text --- */
+        *currchar = '\n';
+        *(currchar+1) = '\0';
+        BuildTextPointers(wnd);
+    }
+    /* --- displayable char or newline --- */
+    if (c == '\n' || wnd->InsertMode || *currchar == '\n') {
+        /* ------ inserting the keyed character ------ */
+        if (wnd->text[wnd->textlen-1] != '\0')    {
+            /* --- the current text buffer is full --- */
+            if (wnd->textlen == wnd->MaxTextLength)    {
+                /* --- text buffer is at maximum size --- */
+                beep();
+                return;
+            }
+            /* ---- increase the text buffer size ---- */
+            wnd->textlen += GROWLENGTH;
+            /* --- but not above maximum size --- */
+            if (wnd->textlen > wnd->MaxTextLength)
+                wnd->textlen = wnd->MaxTextLength;
+            wnd->text = DFrealloc(wnd->text, wnd->textlen+2);
+            wnd->text[wnd->textlen-1] = '\0';
+            currchar = CurrChar;
+        }
+        memmove(currchar+1, currchar, strlen(currchar)+1);
+        ModTextPointers(wnd, wnd->CurrLine+1, 1);
+        if (isMultiLine(wnd) && wnd->wlines > 1)
+            wnd->textwidth = max(wnd->textwidth,
+                (int) (TextLine(wnd, wnd->CurrLine+1)-
+                TextLine(wnd, wnd->CurrLine)));
+        else
+            wnd->textwidth = max((int)wnd->textwidth,
+                (int)strlen(wnd->text));
+        WriteTextLine(wnd, NULL,
+            wnd->wtop+wnd->WndRow, FALSE);
+    }
+    /* ----- put the char in the buffer ----- */
+    *currchar = c;
+    wnd->TextChanged = TRUE;
+    if (c == '\n')    {
+        wnd->wleft = 0;
+        BuildTextPointers(wnd);
+        End(wnd);
+        Forward(wnd);
+        DfSendMessage(wnd, PAINT, 0, 0);
+        return;
+    }
+    /* ---------- test end of window --------- */
+    if (WndCol == ClientWidth(wnd)-1)    {
+        if (!isMultiLine(wnd)) {
+                       if (!(currchar == wnd->text+wnd->MaxTextLength-2))
+            DfSendMessage(wnd, HORIZSCROLL, TRUE, 0);
+               }
+               else    {
+                       char *cp = currchar;
+               while (*cp != ' ' && cp != TextLine(wnd, wnd->CurrLine))
+                   --cp;
+               if (cp == TextLine(wnd, wnd->CurrLine) ||
+                       !wnd->WordWrapMode)
+                   DfSendMessage(wnd, HORIZSCROLL, TRUE, 0);
+               else    {
+                   int dif = 0;
+                   if (c != ' ')    {
+                       dif = (int) (currchar - cp);
+                       wnd->CurrCol -= dif;
+                       DfSendMessage(wnd, KEYBOARD, DEL, 0);
+                       --dif;
+                   }
+                   DfSendMessage(wnd, KEYBOARD, '\n', 0);
+                   currchar = CurrChar;
+                   wnd->CurrCol = dif;
+                   if (c == ' ')
+                       return;
+               }
+           }
+       }
+    /* ------ display the character ------ */
+    SetStandardColor(wnd);
+    PutWindowChar(wnd, c, WndCol, wnd->WndRow);
+    /* ----- advance the pointers ------ */
+    wnd->CurrCol++;
+}
+/* ------------ screen changing key strokes ------------- */
+static void DoKeyStroke(DFWINDOW wnd, int c, PARAM p2)
+{
+    switch (c)    {
+        case RUBOUT:
+                       if (wnd->CurrCol == 0 && wnd->CurrLine == 0)
+                               break;
+            Backward(wnd);
+        case DEL:
+            DelKey(wnd);
+            break;
+        case SHIFT_HT:
+            ShiftTabKey(wnd, p2);
+            break;
+        case '\t':
+            TabKey(wnd, p2);
+            break;
+        case '\r':
+            if (!isMultiLine(wnd))    {
+                DfPostMessage(GetParent(wnd), KEYBOARD, c, p2);
+                break;
+            }
+            c = '\n';
+        default:
+            if (TextBlockMarked(wnd))    {
+                DfSendMessage(wnd, DFM_COMMAND, ID_DELETETEXT, 0);
+                DfSendMessage(wnd, PAINT, 0, 0);
+            }
+            KeyTyped(wnd, c);
+            break;
+    }
+}
+/* ----------- KEYBOARD Message ---------- */
+static int KeyboardMsg(DFWINDOW wnd, PARAM p1, PARAM p2)
+{
+       int c = (int) p1;
+
+       if (WindowMoving || WindowSizing || ((int)p2 & ALTKEY))
+               return FALSE;
+
+       switch (c)
+       {
+               /* these keys get processed by lower classes */
+               case ESC:
+               case F1:
+               case F2:
+               case F3:
+               case F4:
+               case F5:
+               case F6:
+               case F7:
+               case F8:
+               case F9:
+               case F10:
+               case INS:
+               case SHIFT_INS:
+               case SHIFT_DEL:
+                       return FALSE;
+
+               /* these keys get processed here */
+               case CTRL_FWD:
+               case CTRL_BS:
+               case CTRL_HOME:
+               case CTRL_END:
+               case CTRL_PGUP:
+               case CTRL_PGDN:
+                       break;
+
+               default:
+                       /* other ctrl keys get processed by lower classes */
+                       if ((int)p2 & CTRLKEY)
+                               return FALSE;
+                       /* all other keys get processed here */
+                       break;
+       }
+
+       DoMultiLines(wnd, c, p2);
+       if (DoScrolling(wnd, c, p2))
+       {
+               if (KeyBoardMarking)
+                       ExtendBlock(wnd, WndCol, wnd->WndRow);
+       }
+       else if (!TestAttribute(wnd, READONLY))
+       {
+               DoKeyStroke(wnd, c, p2);
+               DfSendMessage(wnd, KEYBOARD_CURSOR, WndCol, wnd->WndRow);
+       }
+       else
+               beep();
+
+       return TRUE;
+}
+
+/* ----------- SHIFT_CHANGED Message ---------- */
+static void ShiftChangedMsg(DFWINDOW wnd, PARAM p1)
+{
+    if (!((int)p1 & (LEFTSHIFT | RIGHTSHIFT)) &&
+                                   KeyBoardMarking)    {
+        StopMarking(wnd);
+        KeyBoardMarking = FALSE;
+    }
+}
+/* ----------- ID_DELETETEXT Command ---------- */
+static void DeleteTextCmd(DFWINDOW wnd)
+{
+    if (TextBlockMarked(wnd))    {
+        char *bbl=TextLine(wnd,wnd->BlkBegLine)+wnd->BlkBegCol;
+        char *bel=TextLine(wnd,wnd->BlkEndLine)+wnd->BlkEndCol;
+        int len = (int) (bel - bbl);
+        SaveDeletedText(wnd, bbl, len);
+        wnd->TextChanged = TRUE;
+        strcpy(bbl, bel);
+        wnd->CurrLine = TextLineNumber(wnd, bbl-wnd->BlkBegCol);
+        wnd->CurrCol = wnd->BlkBegCol;
+        wnd->WndRow = wnd->BlkBegLine - wnd->wtop;
+        if (wnd->WndRow < 0)    {
+            wnd->wtop = wnd->BlkBegLine;
+            wnd->WndRow = 0;
+        }
+        DfSendMessage(wnd, KEYBOARD_CURSOR, WndCol, wnd->WndRow);
+        ClearTextBlock(wnd);
+        BuildTextPointers(wnd);
+    }
+}
+/* ----------- ID_CLEAR Command ---------- */
+static void ClearCmd(DFWINDOW wnd)
+{
+    if (TextBlockMarked(wnd))    {
+        char *bbl=TextLine(wnd,wnd->BlkBegLine)+wnd->BlkBegCol;
+        char *bel=TextLine(wnd,wnd->BlkEndLine)+wnd->BlkEndCol;
+        int len = (int) (bel - bbl);
+        SaveDeletedText(wnd, bbl, len);
+        wnd->CurrLine = TextLineNumber(wnd, bbl);
+        wnd->CurrCol = wnd->BlkBegCol;
+        wnd->WndRow = wnd->BlkBegLine - wnd->wtop;
+        if (wnd->WndRow < 0)    {
+            wnd->WndRow = 0;
+            wnd->wtop = wnd->BlkBegLine;
+        }
+        /* ------ change all text lines in block to \n ----- */
+        while (bbl < bel)    {
+            char *cp = strchr(bbl, '\n');
+            if (cp > bel)
+                cp = bel;
+            strcpy(bbl, cp);
+            bel -= (int) (cp - bbl);
+            bbl++;
+        }
+        ClearTextBlock(wnd);
+        BuildTextPointers(wnd);
+        DfSendMessage(wnd, KEYBOARD_CURSOR, WndCol, wnd->WndRow);
+        wnd->TextChanged = TRUE;
+    }
+}
+/* ----------- ID_UNDO Command ---------- */
+static void UndoCmd(DFWINDOW wnd)
+{
+    if (wnd->DeletedText != NULL)    {
+        PasteText(wnd, wnd->DeletedText, wnd->DeletedLength);
+        free(wnd->DeletedText);
+        wnd->DeletedText = NULL;
+        wnd->DeletedLength = 0;
+        DfSendMessage(wnd, PAINT, 0, 0);
+    }
+}
+/* ----------- ID_PARAGRAPH Command ---------- */
+static void ParagraphCmd(DFWINDOW wnd)
+{
+    int bc, fl;
+    char *bl, *bbl, *bel, *bb;
+
+    ClearTextBlock(wnd);
+    /* ---- forming paragraph from cursor position --- */
+    fl = wnd->wtop + wnd->WndRow;
+    bbl = bel = bl = TextLine(wnd, wnd->CurrLine);
+    if ((bc = wnd->CurrCol) >= ClientWidth(wnd))
+        bc = 0;
+    Home(wnd);
+    /* ---- locate the end of the paragraph ---- */
+    while (*bel)    {
+        int blank = TRUE;
+        char *bll = bel;
+        /* --- blank line marks end of paragraph --- */
+        while (*bel && *bel != '\n')    {
+            if (*bel != ' ')
+                blank = FALSE;
+            bel++;
+        }
+        if (blank)    {
+            bel = bll;
+            break;
+        }
+        if (*bel)
+            bel++;
+    }
+    if (bel == bbl)    {
+        DfSendMessage(wnd, KEYBOARD, DN, 0);
+        return;
+    }
+    if (*bel == '\0')
+        --bel;
+    if (*bel == '\n')
+        --bel;
+    /* --- change all newlines in block to spaces --- */
+    while (CurrChar < bel)    {
+        if (*CurrChar == '\n')    {
+            *CurrChar = ' ';
+            wnd->CurrLine++;
+            wnd->CurrCol = 0;
+        }
+        else
+            wnd->CurrCol++;
+    }
+    /* ---- insert newlines at new margin boundaries ---- */
+    bb = bbl;
+    while (bbl < bel)    {
+        bbl++;
+        if ((int)(bbl - bb) == ClientWidth(wnd)-1)    {
+            while (*bbl != ' ' && bbl > bb)
+                --bbl;
+            if (*bbl != ' ')    {
+                bbl = strchr(bbl, ' ');
+                if (bbl == NULL || bbl >= bel)
+                    break;
+            }
+            *bbl = '\n';
+            bb = bbl+1;
+        }
+    }
+    BuildTextPointers(wnd);
+    /* --- put cursor back at beginning --- */
+    wnd->CurrLine = TextLineNumber(wnd, bl);
+    wnd->CurrCol = bc;
+    if (fl < wnd->wtop)
+        wnd->wtop = fl;
+    wnd->WndRow = fl - wnd->wtop;
+    DfSendMessage(wnd, PAINT, 0, 0);
+    DfSendMessage(wnd, KEYBOARD_CURSOR, WndCol, wnd->WndRow);
+    wnd->TextChanged = TRUE;
+    BuildTextPointers(wnd);
+}
+/* ----------- COMMAND Message ---------- */
+static int CommandMsg(DFWINDOW wnd, PARAM p1)
+{
+    switch ((int)p1)    {
+        case ID_DELETETEXT:
+            DeleteTextCmd(wnd);
+            return TRUE;
+        case ID_CLEAR:
+            ClearCmd(wnd);
+            return TRUE;
+        case ID_UNDO:
+            UndoCmd(wnd);
+            return TRUE;
+        case ID_PARAGRAPH:
+            ParagraphCmd(wnd);
+            return TRUE;
+        default:
+            break;
+    }
+    return FALSE;
+}
+/* ---------- CLOSE_WINDOW Message ----------- */
+static int CloseWindowMsg(DFWINDOW wnd, PARAM p1, PARAM p2)
+{
+       int rtn;
+    DfSendMessage(NULL, HIDE_CURSOR, 0, 0);
+    if (wnd->DeletedText != NULL)
+        free(wnd->DeletedText);
+       if (wnd->text != NULL)
+       {
+               free(wnd->text);
+               wnd->text = NULL;
+       }
+    rtn = BaseWndProc(EDITBOX, wnd, CLOSE_WINDOW, p1, p2);
+    return rtn;
+}
+
+/* ------- Window processing module for EDITBOX class ------ */
+int EditBoxProc(DFWINDOW wnd, DFMESSAGE msg, PARAM p1, PARAM p2)
+{
+    int rtn;
+    switch (msg)    {
+        case CREATE_WINDOW:
+            return CreateWindowMsg(wnd);
+        case ADDTEXT:
+            return AddTextMsg(wnd, p1, p2);
+        case SETTEXT:
+            return SetTextMsg(wnd, p1);
+        case CLEARTEXT:
+                       return ClearTextMsg(wnd);
+        case GETTEXT:
+            return GetTextMsg(wnd, p1, p2);
+        case SETTEXTLENGTH:
+            return SetTextLengthMsg(wnd, (unsigned) p1);
+        case KEYBOARD_CURSOR:
+            KeyboardCursorMsg(wnd, p1, p2);
+                       return TRUE;
+        case SETFOCUS:
+                       if (!(int)p1)
+                               DfSendMessage(NULL, HIDE_CURSOR, 0, 0);
+        case PAINT:
+        case MOVE:
+            rtn = BaseWndProc(EDITBOX, wnd, msg, p1, p2);
+            DfSendMessage(wnd,KEYBOARD_CURSOR,WndCol,wnd->WndRow);
+            return rtn;
+        case DFM_SIZE:
+            return SizeMsg(wnd, p1, p2);
+        case SCROLL:
+            return ScrollMsg(wnd, p1);
+        case HORIZSCROLL:
+            return HorizScrollMsg(wnd, p1);
+        case SCROLLPAGE:
+            return ScrollPageMsg(wnd, p1);
+        case HORIZPAGE:
+            return HorizPageMsg(wnd, p1);
+        case LEFT_BUTTON:
+            if (LeftButtonMsg(wnd, p1, p2))
+                return TRUE;
+            break;
+        case MOUSE_MOVED:
+            if (MouseMovedMsg(wnd, p1, p2))
+                return TRUE;
+            break;
+        case DFM_BUTTON_RELEASED:
+            if (ButtonReleasedMsg(wnd))
+                return TRUE;
+            break;
+        case KEYBOARD:
+            if (KeyboardMsg(wnd, p1, p2))
+                return TRUE;
+            break;
+        case SHIFT_CHANGED:
+            ShiftChangedMsg(wnd, p1);
+            break;
+        case DFM_COMMAND:
+            if (CommandMsg(wnd, p1))
+                return TRUE;
+            break;
+        case CLOSE_WINDOW:
+            return CloseWindowMsg(wnd, p1, p2);
+        default:
+            break;
+    }
+    return BaseWndProc(EDITBOX, wnd, msg, p1, p2);
+}
+/* ------ save deleted text for the Undo command ------ */
+static void SaveDeletedText(DFWINDOW wnd, char *bbl, int len)
+{
+    wnd->DeletedLength = len;
+    wnd->DeletedText=DFrealloc(wnd->DeletedText,len);
+    memmove(wnd->DeletedText, bbl, len);
+}
+/* ---- cursor right key: right one character position ---- */
+static void Forward(DFWINDOW wnd)
+{
+    char *cc = CurrChar+1;
+    if (*cc == '\0')
+        return;
+    if (*CurrChar == '\n')    {
+        Home(wnd);
+        Downward(wnd);
+    }
+    else    {
+        wnd->CurrCol++;
+        if (WndCol == ClientWidth(wnd))
+            DfSendMessage(wnd, HORIZSCROLL, TRUE, 0);
+    }
+}
+/* ----- stick the moving cursor to the end of the line ---- */
+static void StickEnd(DFWINDOW wnd)
+{
+    char *cp = TextLine(wnd, wnd->CurrLine);
+    char *cp1 = strchr(cp, '\n');
+    int len = cp1 ? (int) (cp1 - cp) : 0;
+    wnd->CurrCol = min(len, wnd->CurrCol);
+    if (wnd->wleft > wnd->CurrCol)    {
+        wnd->wleft = max(0, wnd->CurrCol - 4);
+        DfSendMessage(wnd, PAINT, 0, 0);
+    }
+    else if (wnd->CurrCol-wnd->wleft >= ClientWidth(wnd))    {
+        wnd->wleft = wnd->CurrCol - (ClientWidth(wnd)-1);
+        DfSendMessage(wnd, PAINT, 0, 0);
+    }
+}
+/* --------- cursor down key: down one line --------- */
+static void Downward(DFWINDOW wnd)
+{
+    if (isMultiLine(wnd) &&
+            wnd->WndRow+wnd->wtop+1 < wnd->wlines)  {
+        wnd->CurrLine++;
+        if (wnd->WndRow == ClientHeight(wnd)-1)
+            BaseWndProc(EDITBOX, wnd, SCROLL, TRUE, 0);
+        else
+            wnd->WndRow++;
+        StickEnd(wnd);
+    }
+}
+/* -------- cursor up key: up one line ------------ */
+static void Upward(DFWINDOW wnd)
+{
+    if (isMultiLine(wnd) && wnd->CurrLine != 0)    {
+        --wnd->CurrLine;
+        if (wnd->WndRow == 0)
+            BaseWndProc(EDITBOX, wnd, SCROLL, FALSE, 0);
+        else
+            --wnd->WndRow;
+        StickEnd(wnd);
+    }
+}
+/* ---- cursor left key: left one character position ---- */
+static void Backward(DFWINDOW wnd)
+{
+    if (wnd->CurrCol)    {
+        --wnd->CurrCol;
+        if (wnd->CurrCol < wnd->wleft)
+            DfSendMessage(wnd, HORIZSCROLL, FALSE, 0);
+    }
+    else if (isMultiLine(wnd) && wnd->CurrLine != 0)    {
+        Upward(wnd);
+        End(wnd);
+    }
+}
+/* -------- End key: to end of line ------- */
+static void End(DFWINDOW wnd)
+{
+    while (*CurrChar && *CurrChar != '\n')
+        ++wnd->CurrCol;
+    if (WndCol >= ClientWidth(wnd))    {
+        wnd->wleft = wnd->CurrCol - (ClientWidth(wnd)-1);
+        DfSendMessage(wnd, PAINT, 0, 0);
+    }
+}
+/* -------- Home key: to beginning of line ------- */
+static void Home(DFWINDOW wnd)
+{
+    wnd->CurrCol = 0;
+    if (wnd->wleft != 0)    {
+        wnd->wleft = 0;
+        DfSendMessage(wnd, PAINT, 0, 0);
+    }
+}
+/* -- Ctrl+cursor right key: to beginning of next word -- */
+static void NextWord(DFWINDOW wnd)
+{
+    int savetop = wnd->wtop;
+    int saveleft = wnd->wleft;
+    ClearVisible(wnd);
+    while (!isWhite(*CurrChar))    {
+        char *cc = CurrChar+1;
+        if (*cc == '\0')
+            break;
+        Forward(wnd);
+    }
+    while (isWhite(*CurrChar))    {
+        char *cc = CurrChar+1;
+        if (*cc == '\0')
+            break;
+        Forward(wnd);
+    }
+    SetVisible(wnd);
+    DfSendMessage(wnd, KEYBOARD_CURSOR, WndCol, wnd->WndRow);
+    if (wnd->wtop != savetop || wnd->wleft != saveleft)
+        DfSendMessage(wnd, PAINT, 0, 0);
+}
+/* -- Ctrl+cursor left key: to beginning of previous word -- */
+static void PrevWord(DFWINDOW wnd)
+{
+    int savetop = wnd->wtop;
+    int saveleft = wnd->wleft;
+    ClearVisible(wnd);
+    Backward(wnd);
+    while (isWhite(*CurrChar))    {
+        if (wnd->CurrLine == 0 && wnd->CurrCol == 0)
+            break;
+        Backward(wnd);
+    }
+    while (wnd->CurrCol != 0 && !isWhite(*CurrChar))
+        Backward(wnd);
+    if (isWhite(*CurrChar))
+        Forward(wnd);
+    SetVisible(wnd);
+    if (wnd->wleft != saveleft)
+        if (wnd->CurrCol >= saveleft)
+            if (wnd->CurrCol - saveleft < ClientWidth(wnd))
+                wnd->wleft = saveleft;
+    DfSendMessage(wnd, KEYBOARD_CURSOR, WndCol, wnd->WndRow);
+    if (wnd->wtop != savetop || wnd->wleft != saveleft)
+        DfSendMessage(wnd, PAINT, 0, 0);
+}
+/* ----- modify text pointers from a specified position
+                by a specified plus or minus amount ----- */
+static void ModTextPointers(DFWINDOW wnd, int lineno, int var)
+{
+    while (lineno < wnd->wlines)
+        *((wnd->TextPointers) + lineno++) += var;
+}
+/* ----- set anchor point for marking text block ----- */
+static void SetAnchor(DFWINDOW wnd, int mx, int my)
+{
+    ClearTextBlock(wnd);
+    /* ------ set the anchor ------ */
+    wnd->BlkBegLine = wnd->BlkEndLine = my;
+    wnd->BlkBegCol = wnd->BlkEndCol = mx;
+    DfSendMessage(wnd, PAINT, 0, 0);
+}
+
+/* EOF */
diff --git a/rosapps/lib/dflat32/helpbox.c b/rosapps/lib/dflat32/helpbox.c
new file mode 100644 (file)
index 0000000..62e33a0
--- /dev/null
@@ -0,0 +1,717 @@
+/* ------------ helpbox.c ----------- */
+
+#include "dflat32/dflat.h"
+#include "dflat32/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 "dflat32/classes.h"
+    NULL
+};
+
+#define MAXHEIGHT (DfGetScreenHeight()-10)
+
+/* --------- linked list of help text collections -------- */
+struct helps {
+    char *hname;
+    char *NextName;
+    char *PrevName;
+    long hptr;
+    int bit;
+    int hheight;
+    int hwidth;
+    DFWINDOW hwnd;
+    struct helps *NextHelp;
+};
+static struct helps *FirstHelp;
+static struct helps *LastHelp;
+static struct helps *ThisHelp;
+
+/* --- linked stack of help windows that have beed used --- */
+struct HelpStack {
+    char *hname;
+    struct HelpStack *PrevStack;
+};
+static struct HelpStack *LastStack;
+static struct HelpStack *ThisStack;
+
+/* --- linked list of keywords in the current help
+           text collection (listhead is in window) -------- */
+struct keywords {
+    char *hname;
+    int lineno;
+    int off1, off2, off3;
+    int isDefinition;
+    struct keywords *nextword;
+    struct keywords *prevword;
+};
+
+static FILE *helpfp;
+static char hline [160];
+static BOOL Helping;
+
+static void SelectHelp(DFWINDOW, char *);
+static void ReadHelp(DFWINDOW);
+static void FindHelp(char *);
+static void FindHelpWindow(DFWINDOW);
+static void DisplayDefinition(DFWINDOW, char *);
+static void BestFit(DFWINDOW, DIALOGWINDOW *);
+
+/* ------------- CREATE_WINDOW message ------------ */
+static void CreateWindowMsg(DFWINDOW wnd)
+{
+    Helping = TRUE;
+    GetClass(wnd) = HELPBOX;
+    InitWindowColors(wnd);
+    if (ThisHelp != NULL)
+        ThisHelp->hwnd = wnd;
+}
+
+/* ------------- COMMAND message ------------ */
+static BOOL CommandMsg(DFWINDOW wnd, PARAM p1)
+{
+    switch ((int)p1)    {
+        case ID_CANCEL:
+            ThisStack = LastStack;
+            while (ThisStack != NULL)    {
+                LastStack = ThisStack->PrevStack;
+                if (ThisStack->hname != NULL)
+                    free(ThisStack->hname);
+                free(ThisStack);
+                ThisStack = LastStack;
+            }
+            break;
+        case ID_PREV:
+            FindHelpWindow(wnd);
+            if (ThisHelp != NULL)
+                SelectHelp(wnd, ThisHelp->PrevName);
+            return TRUE;
+        case ID_NEXT:
+            FindHelpWindow(wnd);
+            if (ThisHelp != NULL)
+                SelectHelp(wnd, ThisHelp->NextName);
+            return TRUE;
+        case ID_BACK:
+            if (LastStack != NULL)    {
+                if (LastStack->PrevStack != NULL)    {
+                    ThisStack = LastStack->PrevStack;
+                    if (LastStack->hname != NULL)
+                        free(LastStack->hname);
+                    free(LastStack);
+                    LastStack = ThisStack;
+                    SelectHelp(wnd, ThisStack->hname);
+                }
+            }
+            return TRUE;
+        default:
+            break;
+    }
+    return FALSE;
+}
+
+/* ------------- KEYBOARD message ------------ */
+static BOOL KeyboardMsg(DFWINDOW wnd, PARAM p1)
+{
+    DFWINDOW cwnd;
+    struct keywords *thisword;
+    static char HelpName[50];
+
+    cwnd = ControlWindow(wnd->extension, ID_HELPTEXT);
+    if (cwnd == NULL || inFocus != cwnd)
+        return FALSE;
+    thisword = cwnd->thisword;
+    switch ((int)p1)    {
+        case '\r':
+            if (thisword != NULL)    {
+                if (thisword->isDefinition)
+                    DisplayDefinition(GetParent(wnd),
+                                        thisword->hname);
+                else    {
+                    strncpy(HelpName, thisword->hname,
+                        sizeof HelpName);
+                    SelectHelp(wnd, HelpName);
+                }
+            }
+            return TRUE;
+        case '\t':
+            if (thisword == NULL)
+                thisword = cwnd->firstword;
+            else {
+                if (thisword->nextword == NULL)
+                    thisword = cwnd->firstword;
+                else
+                    thisword = thisword->nextword;
+            }
+            break;
+        case SHIFT_HT:
+            if (thisword == NULL)
+                thisword = cwnd->lastword;
+            else {
+                if (thisword->prevword == NULL)
+                    thisword = cwnd->lastword;
+                else
+                    thisword = thisword->prevword;
+            }
+            break;
+        default:
+            thisword = NULL;
+            break;
+    }
+    if (thisword != NULL)    {
+        cwnd->thisword = thisword;
+        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);
+        }
+        DfSendMessage(cwnd, PAINT, 0, 0);
+        return TRUE;
+    }
+    return FALSE;
+}
+
+/* ---- window processing module for the HELPBOX ------- */
+int HelpBoxProc(DFWINDOW wnd, DFMESSAGE msg, PARAM p1, PARAM p2)
+{
+    DBOX *db = wnd->extension;
+
+    switch (msg)    {
+        case CREATE_WINDOW:
+            CreateWindowMsg(wnd);
+            break;
+        case INITIATE_DIALOG:
+            ReadHelp(wnd);
+            break;
+        case DFM_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 (db != NULL)    {
+                if (db->dwnd.title != NULL)    {
+                    free(db->dwnd.title);
+                    db->dwnd.title = NULL;
+                }
+            }
+            FindHelpWindow(wnd);
+            if (ThisHelp != NULL)
+                ThisHelp->hwnd = NULL;
+            Helping = FALSE;
+            break;
+        default:
+            break;
+    }
+    return BaseWndProc(HELPBOX, wnd, msg, p1, p2);
+}
+
+/* ----- select a new help window from its name ----- */
+static void SelectHelp(DFWINDOW wnd, char *hname)
+{
+    if (hname != NULL)    {
+        DFWINDOW pwnd = GetParent(wnd);
+        DfPostMessage(wnd, ENDDIALOG, 0, 0);
+        DfPostMessage(pwnd, DISPLAY_HELP, (PARAM) hname, 0);
+    }
+}
+
+/* ---- PAINT message for the helpbox text editbox ---- */
+static int PaintMsg(DFWINDOW wnd, PARAM p1, PARAM p2)
+{
+    struct keywords *thisword;
+    int rtn;
+    if (wnd->thisword != NULL)    {
+        DFWINDOW pwnd = GetParent(wnd);
+        char *cp;
+        thisword = wnd->thisword;
+        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(DFWINDOW wnd, PARAM p1, PARAM p2)
+{
+    struct keywords *thisword;
+    int rtn, mx, my;
+
+    rtn = DefaultWndProc(wnd, LEFT_BUTTON, p1, p2);
+    mx = (int)p1 - GetClientLeft(wnd);
+    my = (int)p2 - GetClientTop(wnd);
+    my += wnd->wtop;
+    thisword = wnd->firstword;
+    while (thisword != NULL)    {
+        if (my == thisword->lineno)    {
+            if (mx >= thisword->off2 &&
+                        mx < thisword->off3)    {
+                wnd->thisword = thisword;
+                DfSendMessage(wnd, PAINT, 0, 0);
+                if (thisword->isDefinition)    {
+                    DFWINDOW pwnd = GetParent(wnd);
+                    if (pwnd != NULL)
+                        DisplayDefinition(GetParent(pwnd),
+                            thisword->hname);
+                }
+                break;
+            }
+        }
+        thisword = thisword->nextword;
+    }
+    return rtn;
+}
+
+/* --- window processing module for HELPBOX's text EDITBOX -- */
+int HelpTextProc(DFWINDOW wnd, DFMESSAGE msg, PARAM p1, PARAM p2)
+{
+    struct keywords *thisword;
+    switch (msg)    {
+        case PAINT:
+            return PaintMsg(wnd, p1, p2);
+        case LEFT_BUTTON:
+            return LeftButtonMsg(wnd, p1, p2);
+        case DOUBLE_CLICK:
+            DfPostMessage(wnd, KEYBOARD, '\r', 0);
+            break;
+        case CLOSE_WINDOW:
+            thisword = wnd->firstword;
+            while (thisword != NULL)    {
+                struct keywords *nextword = thisword->nextword;
+                if (thisword->hname != NULL)
+                    free(thisword->hname);
+                free(thisword);
+                thisword = nextword;
+            }
+            break;
+        default:
+            break;
+    }
+    return DefaultWndProc(wnd, msg, p1, p2);
+}
+
+/* -------- read the help text into the editbox ------- */
+static void ReadHelp(DFWINDOW wnd)
+{
+    DFWINDOW cwnd = ControlWindow(wnd->extension, ID_HELPTEXT);
+    int linectr = 0;
+    if (cwnd == NULL)
+        return;
+    cwnd->wndproc = HelpTextProc;
+    /* ----- read the help text ------- */
+    while (TRUE)    {
+        unsigned 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)    {
+                /* ----- hit a new key word ----- */
+                struct keywords *thisword;
+                if (*(cp+1) != '.' && *(cp+1) != '*')    {
+                    cp++;
+                    continue;
+                }
+                thisword = DFcalloc(1, sizeof(struct keywords));
+                if (cwnd->firstword == NULL)
+                    cwnd->firstword = thisword;
+                if (cwnd->lastword != NULL)    {
+                    ((struct keywords *)
+                        (cwnd->lastword))->nextword = thisword;
+                    thisword->prevword = cwnd->lastword;
+                }
+                cwnd->lastword = thisword;
+                thisword->lineno = cwnd->wlines;
+                thisword->off1 = (int) ((int)cp - (int)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)    {
+                        int len = (int) ((int)cp1 - (int)cp);
+                        thisword->hname = DFcalloc(1, len);
+                        strncpy(thisword->hname, cp+1, len-1);
+                        memmove(cp, cp1+1, strlen(cp1));
+                    }
+                }
+            }
+        }
+        PutItemText(wnd, ID_HELPTEXT, hline);
+        /* -- display help text as soon as window is full -- */
+        if (++linectr == ClientHeight(cwnd))
+            DfSendMessage(cwnd, PAINT, 0, 0);
+        if (linectr > ClientHeight(cwnd) &&
+                !TestAttribute(cwnd, VSCROLLBAR))    {
+            AddAttribute(cwnd, VSCROLLBAR);
+            DfSendMessage(cwnd, BORDER, 0, 0);
+        }
+    }
+}
+
+/* ---- 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 ------------ */
+void LoadHelpFile()
+{
+    char *cp;
+
+    if (Helping)
+        return;
+    UnLoadHelpFile();
+    if ((helpfp = OpenHelpFile()) == NULL)
+        return;
+    *hline = '\0';
+    while (*hline != '<')    {
+        if (GetHelpLine(hline) == NULL)    {
+            fclose(helpfp);
+            return;
+        }
+    }
+    while (*hline == '<')   {
+        if (strncmp(hline, "<end>", 5) == 0)
+            break;
+
+        /* -------- parse the help window's text name ----- */
+        if ((cp = strchr(hline, '>')) != NULL)    {
+            ThisHelp = DFcalloc(1, sizeof(struct helps));
+            if (FirstHelp == NULL)
+            FirstHelp = ThisHelp;
+            *cp = '\0';
+            ThisHelp->hname=DFmalloc(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 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=DFcalloc(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=DFcalloc(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;
+        }
+        /* -------- 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>");
+        }
+    }
+    fclose(helpfp);
+}
+
+/* ------ free the memory used by the help file table ------ */
+void UnLoadHelpFile(void)
+{
+    while (FirstHelp != NULL)    {
+        ThisHelp = FirstHelp;
+        if (ThisHelp->hname != NULL)
+            free(ThisHelp->hname);
+        if (ThisHelp->PrevName != NULL)
+            free(ThisHelp->PrevName);
+        if (ThisHelp->NextName != NULL)
+            free(ThisHelp->NextName);
+        FirstHelp = ThisHelp->NextHelp;
+        free(ThisHelp);
+    }
+    ThisHelp = LastHelp = NULL;
+    free(HelpTree);
+       HelpTree = NULL;
+}
+
+/* ---------- display a specified help text ----------- */
+BOOL DisplayHelp(DFWINDOW wnd, char *Help)
+{
+       BOOL rtn = FALSE;
+    if (Helping)
+        return TRUE;
+       wnd->isHelping++;
+    FindHelp(Help);
+    if (ThisHelp != NULL)    {
+        if (LastStack == NULL ||
+                stricmp(Help, LastStack->hname))    {
+            /* ---- add the window to the history stack ---- */
+            ThisStack = DFcalloc(1,sizeof(struct HelpStack));
+            ThisStack->hname = DFmalloc(strlen(Help)+1);
+            if (ThisStack->hname != NULL)
+                strcpy(ThisStack->hname, Help);
+            ThisStack->PrevStack = LastStack;
+            LastStack = ThisStack;
+        }
+        if ((helpfp = OpenHelpFile()) != NULL)    {
+            DBOX *db;
+            int offset, i;
+
+            db = DFcalloc(1,sizeof HelpBox);
+            memcpy(db, &HelpBox, sizeof HelpBox);
+            /* -- seek to the first line of the help text -- */
+            SeekHelpLine(ThisHelp->hptr, ThisHelp->bit);
+            /* ----- read the title ----- */
+            GetHelpLine(hline);
+            hline[strlen(hline)-1] = '\0';
+            db->dwnd.title = DFmalloc(strlen(hline)+1);
+            strcpy(db->dwnd.title, hline);
+            /* ----- set the height and width ----- */
+            db->dwnd.h = min(ThisHelp->hheight, MAXHEIGHT)+7;
+            db->dwnd.w = max(45, ThisHelp->hwidth+6);
+            /* ------ position the help window ----- */
+            BestFit(wnd, &db->dwnd);
+            /* ------- position the command buttons ------ */
+            db->ctl[0].dwnd.w = max(40, ThisHelp->hwidth+2);
+            db->ctl[0].dwnd.h =
+                        min(ThisHelp->hheight, MAXHEIGHT)+2;
+            offset = (db->dwnd.w-40) / 2;
+            for (i = 1; i < 5; i++)    {
+                db->ctl[i].dwnd.y =
+                        min(ThisHelp->hheight, MAXHEIGHT)+3;
+                db->ctl[i].dwnd.x += offset;
+            }
+            /* ---- disable ineffective buttons ---- */
+            if (ThisStack != NULL)
+                if (ThisStack->PrevStack == NULL)
+                    DisableButton(db, ID_BACK);
+            if (ThisHelp->NextName == NULL)
+                DisableButton(db, ID_NEXT);
+            if (ThisHelp->PrevName == NULL)
+                DisableButton(db, ID_PREV);
+            /* ------- display the help window ----- */
+            DfDialogBox(NULL, db, TRUE, HelpBoxProc);
+            free(db);
+            fclose(helpfp);
+            rtn = TRUE;
+        }
+    }
+       --wnd->isHelping;
+    return rtn;
+}
+
+/* ------- display a definition window --------- */
+static void DisplayDefinition(DFWINDOW wnd, char *def)
+{
+    DFWINDOW dwnd;
+    DFWINDOW hwnd = wnd;
+    int y;
+
+    if (GetClass(wnd) == POPDOWNMENU)
+        hwnd = GetParent(wnd);
+    y = GetClass(hwnd) == MENUBAR ? 2 : 1;
+    FindHelp(def);
+    if (ThisHelp != NULL)    {
+        if ((helpfp = OpenHelpFile()) != NULL)    {
+            dwnd = DfCreateWindow(
+                        TEXTBOX,
+                        NULL,
+                        GetClientLeft(hwnd),
+                        GetClientTop(hwnd)+y,
+                        min(ThisHelp->hheight, MAXHEIGHT)+3,
+                        ThisHelp->hwidth+2,
+                        NULL,
+                        wnd,
+                        NULL,
+                        HASBORDER | NOCLIP | SAVESELF);
+            if (dwnd != NULL)    {
+                /* ----- read the help text ------- */
+                SeekHelpLine(ThisHelp->hptr, ThisHelp->bit);
+                while (TRUE)    {
+                    if (GetHelpLine(hline) == NULL)
+                        break;
+                    if (*hline == '<')
+                        break;
+                    hline[strlen(hline)-1] = '\0';
+                    DfSendMessage(dwnd,ADDTEXT,(PARAM)hline,0);
+                }
+                DfSendMessage(dwnd, SHOW_WINDOW, 0, 0);
+                DfSendMessage(NULL, WAITKEYBOARD, 0, 0);
+                DfSendMessage(NULL, WAITMOUSE, 0, 0);
+                DfSendMessage(dwnd, CLOSE_WINDOW, 0, 0);
+            }
+            fclose(helpfp);
+        }
+    }
+}
+
+/* ------ 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 void FindHelp(char *Help)
+{
+    ThisHelp = FirstHelp;
+    while (ThisHelp != NULL)    {
+        if (wildcmp(Help, ThisHelp->hname) == FALSE)
+            break;
+        ThisHelp = ThisHelp->NextHelp;
+    }
+}
+
+/* --- ThisHelp = the help window matching specified wnd --- */
+static void FindHelpWindow(DFWINDOW wnd)
+{
+    ThisHelp = FirstHelp;
+    while (ThisHelp != NULL)    {
+        if (wnd == ThisHelp->hwnd)
+            break;
+        ThisHelp = ThisHelp->NextHelp;
+    }
+}
+
+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(DFWINDOW wnd, DIALOGWINDOW *dwnd)
+{
+    int above, below, right, left;
+    if (GetClass(wnd) == MENUBAR ||
+                GetClass(wnd) == APPLICATION)    {
+        dwnd->x = dwnd->y = -1;
+        return;
+    }
+    /* --- compute above overlap ---- */
+    above = OverLap(dwnd->h, GetTop(wnd));
+    /* --- compute below overlap ---- */
+    below = OverLap(GetBottom(wnd), DfGetScreenHeight()-dwnd->h);
+    /* --- compute right overlap ---- */
+    right = OverLap(GetRight(wnd), DfGetScreenWidth()-dwnd->w);
+    /* --- compute left  overlap ---- */
+    left = OverLap(dwnd->w, GetLeft(wnd));
+
+    if (above < below)
+        dwnd->y = max(0, GetTop(wnd)-dwnd->h-2);
+    else
+        dwnd->y = min(DfGetScreenHeight()-dwnd->h, GetBottom(wnd)+2);
+    if (right < left)
+        dwnd->x = min(GetRight(wnd)+2, DfGetScreenWidth()-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;
+}
+
+/* EOF */
diff --git a/rosapps/lib/dflat32/keys.c b/rosapps/lib/dflat32/keys.c
new file mode 100644 (file)
index 0000000..0f8c3d2
--- /dev/null
@@ -0,0 +1,86 @@
+/* ------------- keys.c ----------- */
+
+#include <stdio.h>
+#include "dflat32/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_BS,        "Alt+BS"},
+       {ALT_DEL,   "Alt+Del"},
+       {SHIFT_DEL,     "Shift+Del"},
+       {SHIFT_INS,     "Shift+Ins"},
+       {CTRL_INS,      "Ctrl+Ins"},
+       {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"},
+       {-1,            NULL}
+};
+
+/* EOF */
diff --git a/rosapps/lib/dflat32/listbox.c b/rosapps/lib/dflat32/listbox.c
new file mode 100644 (file)
index 0000000..e815bfe
--- /dev/null
@@ -0,0 +1,469 @@
+/* ------------- listbox.c ------------ */
+
+#include "dflat32/dflat.h"
+
+#ifdef INCLUDE_EXTENDEDSELECTIONS
+static int ExtendSelections(DFWINDOW, int, int);
+static void TestExtended(DFWINDOW, PARAM);
+static void ClearAllSelections(DFWINDOW);
+static void SetSelection(DFWINDOW, int);
+static void FlipSelection(DFWINDOW, int);
+static void ClearSelection(DFWINDOW, int);
+#else
+#define TestExtended(w,p) /**/
+#endif
+static void ChangeSelection(DFWINDOW, int, int);
+static void WriteSelection(DFWINDOW, int, int, DFRECT *);
+static BOOL SelectionInWindow(DFWINDOW, int);
+
+static int py = -1;    /* the previous y mouse coordinate */
+
+#ifdef INCLUDE_EXTENDEDSELECTIONS
+/* --------- SHIFT_F8 Key ------------ */
+static void AddModeKey(DFWINDOW wnd)
+{
+    if (isMultiLine(wnd))    {
+        wnd->AddMode ^= TRUE;
+        DfSendMessage(GetParent(wnd), ADDSTATUS,
+            wnd->AddMode ? ((PARAM) "Add Mode") : 0, 0);
+    }
+}
+#endif
+
+/* --------- UP (Up Arrow) Key ------------ */
+static void UpKey(DFWINDOW wnd, PARAM p2)
+{
+    if (wnd->selection > 0)    {
+        if (wnd->selection == wnd->wtop)    {
+            BaseWndProc(LISTBOX, wnd, KEYBOARD, UP, p2);
+            DfPostMessage(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;
+            DfPostMessage(wnd, LB_SELECTION, newsel,
+#ifdef INCLUDE_EXTENDEDSELECTIONS
+                isMultiLine(wnd) ? p2 :
+#endif
+                FALSE);
+        }
+    }
+}
+
+/* --------- DN (Down Arrow) Key ------------ */
+static void DnKey(DFWINDOW wnd, PARAM p2)
+{
+    if (wnd->selection < wnd->wlines-1)    {
+        if (wnd->selection == wnd->wtop+ClientHeight(wnd)-1)  {
+            BaseWndProc(LISTBOX, wnd, KEYBOARD, DN, p2);
+            DfPostMessage(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++;
+            DfPostMessage(wnd, LB_SELECTION, newsel,
+#ifdef INCLUDE_EXTENDEDSELECTIONS
+                isMultiLine(wnd) ? p2 :
+#endif
+                FALSE);
+        }
+    }
+}
+
+/* --------- HOME and PGUP Keys ------------ */
+static void HomePgUpKey(DFWINDOW wnd, PARAM p1, PARAM p2)
+{
+    BaseWndProc(LISTBOX, wnd, KEYBOARD, p1, p2);
+    DfPostMessage(wnd, LB_SELECTION, wnd->wtop,
+#ifdef INCLUDE_EXTENDEDSELECTIONS
+        isMultiLine(wnd) ? p2 :
+#endif
+        FALSE);
+}
+
+/* --------- END and PGDN Keys ------------ */
+static void EndPgDnKey(DFWINDOW 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;
+    DfPostMessage(wnd, LB_SELECTION, bot,
+#ifdef INCLUDE_EXTENDEDSELECTIONS
+        isMultiLine(wnd) ? p2 :
+#endif
+        FALSE);
+}
+
+#ifdef INCLUDE_EXTENDEDSELECTIONS
+/* --------- Space Bar Key ------------ */
+static void SpacebarKey(DFWINDOW wnd, PARAM p2)
+{
+    if (isMultiLine(wnd))    {
+        int sel = DfSendMessage(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;
+            DfSendMessage(wnd, PAINT, 0, 0);
+        }
+    }
+}
+#endif
+
+/* --------- Enter ('\r') Key ------------ */
+static void EnterKey(DFWINDOW wnd)
+{
+    if (wnd->selection != -1)    {
+        DfSendMessage(wnd, LB_SELECTION, wnd->selection, TRUE);
+        DfSendMessage(wnd, LB_CHOOSE, wnd->selection, 0);
+    }
+}
+
+/* --------- All Other Key Presses ------------ */
+static void KeyPress(DFWINDOW 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
+        /* --- special for directory list box --- */
+        if (*cp == '[')
+            cp++;
+        if (tolower(*cp) == (int)p1)    {
+            DfSendMessage(wnd, LB_SELECTION, sel,
+                isMultiLine(wnd) ? p2 : FALSE);
+            if (!SelectionInWindow(wnd, sel))    {
+                wnd->wtop = sel-ClientHeight(wnd)+1;
+                DfSendMessage(wnd, PAINT, 0, 0);
+            }
+            break;
+        }
+        sel++;
+    }
+}
+
+/* --------- KEYBOARD Message ------------ */
+static int KeyboardMsg(DFWINDOW wnd, PARAM p1, PARAM p2)
+{
+    switch ((int) p1)    {
+#ifdef INCLUDE_EXTENDEDSELECTIONS
+        case SHIFT_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(DFWINDOW 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;
+            DfSendMessage(wnd, PAINT, 0, 0);
+        }
+#endif
+        DfSendMessage(wnd, LB_SELECTION, sel, TRUE);
+        py = my;
+    }
+    return TRUE;
+}
+
+/* ------------- DOUBLE_CLICK Message ------------ */
+static int DoubleClickMsg(DFWINDOW wnd, PARAM p1, PARAM p2)
+{
+    if (WindowMoving || WindowSizing)
+        return FALSE;
+    if (wnd->wlines)    {
+        DFRECT rc = ClientRect(wnd);
+        BaseWndProc(LISTBOX, wnd, DOUBLE_CLICK, p1, p2);
+        if (InsideRect(p1, p2, rc))
+            DfSendMessage(wnd, LB_CHOOSE, wnd->selection, 0);
+    }
+    return TRUE;
+}
+
+/* ------------ ADDTEXT Message -------------- */
+static int AddTextMsg(DFWINDOW wnd, PARAM p1, PARAM p2)
+{
+    int rtn = BaseWndProc(LISTBOX, wnd, ADDTEXT, p1, p2);
+    if (wnd->selection == -1)
+        DfSendMessage(wnd, LB_SETSELECTION, 0, 0);
+#ifdef INCLUDE_EXTENDEDSELECTIONS
+    if (*(char *)p1 == LISTSELECTOR)
+        wnd->SelectCount++;
+#endif
+    return rtn;
+}
+
+/* --------- GETTEXT Message ------------ */
+static void GetTextMsg(DFWINDOW wnd, PARAM p1, PARAM p2)
+{
+    if ((int)p2 != -1)    {
+        char *cp1 = (char *)p1;
+        char *cp2 = TextLine(wnd, (int)p2);
+        while (cp2 && *cp2 && *cp2 != '\n')
+            *cp1++ = *cp2++;
+        *cp1 = '\0';
+    }
+}
+
+/* --------- LISTBOX Window Processing Module ------------ */
+int ListBoxProc(DFWINDOW wnd, DFMESSAGE 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 DFM_BUTTON_RELEASED:
+            if (WindowMoving || WindowSizing || VSliding)
+                break;
+            py = -1;
+            return TRUE;
+        case ADDTEXT:
+            return AddTextMsg(wnd, p1, p2);
+        case DFM_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, (DFRECT *)p1);
+            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:
+            DfSendMessage(GetParent(wnd), LB_CHOOSE, p1, p2);
+            return TRUE;
+        case LB_SELECTION:
+            ChangeSelection(wnd, (int) p1, (int) p2);
+            DfSendMessage(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;
+                DfSendMessage(GetParent(wnd), ADDSTATUS, 0, 0);
+            }
+            break;
+#endif
+        default:
+            break;
+    }
+    return BaseWndProc(LISTBOX, wnd, msg, p1, p2);
+}
+
+static BOOL SelectionInWindow(DFWINDOW wnd, int sel)
+{
+    return (wnd->wlines && sel >= wnd->wtop &&
+            sel < wnd->wtop+ClientHeight(wnd));
+}
+
+static void WriteSelection(DFWINDOW wnd, int sel,
+                                    int reverse, DFRECT *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(DFWINDOW wnd, PARAM p2)
+{
+    if (isMultiLine(wnd) && !wnd->AddMode &&
+            !((int) p2 & (LEFTSHIFT | RIGHTSHIFT)))    {
+        if (wnd->SelectCount > 1)    {
+            ClearAllSelections(wnd);
+            DfSendMessage(wnd, PAINT, 0, 0);
+        }
+    }
+}
+
+/* ----- Clear selections in the listbox ----- */
+static void ClearAllSelections(DFWINDOW 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(DFWINDOW wnd, int sel)
+{
+    if (isMultiLine(wnd))    {
+        if (ItemSelected(wnd, sel))
+            ClearSelection(wnd, sel);
+        else
+            SetSelection(wnd, sel);
+    }
+}
+
+static int ExtendSelections(DFWINDOW wnd, int sel, int shift)
+{    
+    if (shift & (LEFTSHIFT | RIGHTSHIFT) &&
+                        wnd->AnchorPoint != -1)    {
+        int i = sel;
+        int j = wnd->AnchorPoint;
+        int rtn;
+        if (j > i)
+            swap(i,j);
+        rtn = i - j;
+        while (j <= i)
+            SetSelection(wnd, j++);
+        return rtn;
+    }
+    return 0;
+}
+
+static void SetSelection(DFWINDOW wnd, int sel)
+{
+    if (isMultiLine(wnd) && !ItemSelected(wnd, sel))    {
+        char *lp = TextLine(wnd, sel);
+        *lp = LISTSELECTOR;
+        wnd->SelectCount++;
+    }
+}
+
+static void ClearSelection(DFWINDOW wnd, int sel)
+{
+    if (isMultiLine(wnd) && ItemSelected(wnd, sel))    {
+        char *lp = TextLine(wnd, sel);
+        *lp = ' ';
+        --wnd->SelectCount;
+    }
+}
+
+BOOL ItemSelected(DFWINDOW 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 ChangeSelection(DFWINDOW wnd,int sel,int shift)
+{
+    if (sel != wnd->selection)    {
+#ifdef INCLUDE_EXTENDEDSELECTIONS
+        if (isMultiLine(wnd))        {
+            int sels;
+            if (!wnd->AddMode)
+                ClearAllSelections(wnd);
+            sels = ExtendSelections(wnd, sel, shift);
+            if (sels > 1)
+                DfSendMessage(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;
+        WriteSelection(wnd, sel, TRUE, NULL);
+     }
+}
+
+/* EOF */
diff --git a/rosapps/lib/dflat32/lists.c b/rosapps/lib/dflat32/lists.c
new file mode 100644 (file)
index 0000000..b2db9c5
--- /dev/null
@@ -0,0 +1,149 @@
+/* --------------- lists.c -------------- */
+
+#include "dflat32/dflat.h"
+
+/* ----- set focus to the next sibling ----- */
+void SetNextFocus (void)
+{
+       if (inFocus != NULL)
+       {
+               DFWINDOW 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)
+                               DfSendMessage(wnd1, SETFOCUS, TRUE, 0);
+               }
+       }
+}
+
+/* ----- set focus to the previous sibling ----- */
+void SetPrevFocus(void)
+{
+       if (inFocus != NULL)
+       {
+               DFWINDOW 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)
+                               DfSendMessage(wnd1, SETFOCUS, TRUE, 0);
+               }
+       }
+}
+
+/* ------- move a window to the end of its parents list ----- */
+void ReFocus(DFWINDOW wnd)
+{
+       if (GetParent(wnd) != NULL)
+       {
+               RemoveWindow(wnd);
+               AppendWindow(wnd);
+               ReFocus(GetParent(wnd));
+       }
+}
+
+/* ---- remove a window from the linked list ---- */
+void RemoveWindow(DFWINDOW wnd)
+{
+       if (wnd != NULL)
+       {
+               DFWINDOW 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(DFWINDOW wnd)
+{
+       if (wnd != NULL)
+       {
+               DFWINDOW pwnd = GetParent(wnd);
+               if (pwnd != NULL)
+               {
+                       if (FirstWindow(pwnd) == NULL)
+                       {
+                               FirstWindow(pwnd) = wnd;
+                               LastWindow(pwnd) = wnd;
+                               PrevWindow(wnd) = NULL;
+                       }
+                       else
+                       {
+                               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)
+       {
+               DFCLASS cl = GetClass(inFocus);
+               if (cl == MENUBAR || cl == STATUSBAR)
+               {
+                       SetPrevFocus();
+                       EmptyAppl = (cl == MENUBAR && ct++);
+               }
+               else
+                       break;
+       }
+}
+
+/* EOF */
diff --git a/rosapps/lib/dflat32/log.c b/rosapps/lib/dflat32/log.c
new file mode 100644 (file)
index 0000000..03f7ec0
--- /dev/null
@@ -0,0 +1,75 @@
+/* ------------ log .c ------------ */
+
+#include "dflat32/dflat.h"
+
+#ifdef INCLUDE_LOGGING
+
+static char *message[] = {
+    #undef DFlatMsg
+    #define DFlatMsg(m) " " #m,
+    #include "dflat32/dflatmsg.h"
+    NULL
+};
+
+static FILE *logfile = NULL;
+extern DBOX Log;
+
+void LogMessages (DFWINDOW wnd, DFMESSAGE msg, PARAM p1, PARAM p2)
+{
+    if (logfile != NULL && message[msg][0] != ' ')
+        fprintf(logfile,
+            "%-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(DFWINDOW wnd, DFMESSAGE msg, PARAM p1, PARAM p2)
+{
+    DFWINDOW cwnd = ControlWindow(&Log, ID_LOGLIST);
+    char **mn = message;
+    switch (msg)    {
+        case INITIATE_DIALOG:
+            AddAttribute(cwnd, MULTILINE | VSCROLLBAR);
+            while (*mn)    {
+                DfSendMessage(cwnd, ADDTEXT, (PARAM) (*mn), 0);
+                mn++;
+            }
+            DfSendMessage(cwnd, SHOW_WINDOW, 0, 0);
+            break;
+        case DFM_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(DFWINDOW wnd)
+{
+       if (DfDialogBox(wnd, &Log, TRUE, LogProc))
+       {
+               if (CheckBoxSetting(&Log, ID_LOGGING))
+               {
+                       logfile = fopen("DFLAT.LOG", "wt");
+                       SetCommandToggle(&MainMenu, ID_LOG);
+               }
+               else if (logfile != NULL)
+               {
+                       fclose(logfile);
+                       logfile = NULL;
+                       ClearCommandToggle(&MainMenu, ID_LOG);
+               }
+       }
+}
+
+#endif
+
+/* EOF */
\ No newline at end of file
diff --git a/rosapps/lib/dflat32/menu.c b/rosapps/lib/dflat32/menu.c
new file mode 100644 (file)
index 0000000..9171002
--- /dev/null
@@ -0,0 +1,85 @@
+/* ------------- menu.c ------------- */
+
+#include "dflat32/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;
+}
diff --git a/rosapps/lib/dflat32/menubar.c b/rosapps/lib/dflat32/menubar.c
new file mode 100644 (file)
index 0000000..900272b
--- /dev/null
@@ -0,0 +1,432 @@
+/* ---------------- menubar.c ------------------ */
+
+#include "dflat32/dflat.h"
+
+static void reset_menubar(DFWINDOW);
+
+static struct {
+    int x1, x2;     /* position in menu bar */
+    char sc;        /* shortcut key value   */
+} menu[10];
+static int mctr;
+
+MBAR *ActiveMenuBar;
+static MENU *ActiveMenu;
+
+static DFWINDOW mwnd;
+static BOOL Selecting;
+
+static DFWINDOW Cascaders[MAXCASCADES];
+static int casc;
+static DFWINDOW GetDocFocus(void);
+
+/* ----------- SETFOCUS Message ----------- */
+static int SetFocusMsg(DFWINDOW wnd, PARAM p1)
+{
+       int rtn;
+       rtn = BaseWndProc(MENUBAR, wnd, SETFOCUS, p1, 0);
+       if (!(int)p1)
+               DfSendMessage(GetParent(wnd), ADDSTATUS, 0, 0);
+       return rtn;
+}
+
+/* --------- BUILDMENU Message --------- */
+static void BuildMenuMsg(DFWINDOW 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(DFWINDOW wnd)
+{
+       if (Selecting)
+               return;
+    if (wnd == inFocus)
+        DfSendMessage(GetParent(wnd), ADDSTATUS, 0, 0);
+    SetStandardColor(wnd);
+    wputs(wnd, GetText(wnd), 0, 0);
+    if (ActiveMenuBar == NULL)
+       return;
+    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)
+                DfSendMessage(GetParent(wnd), ADDSTATUS,
+                    (PARAM)st, 0);
+        }
+        free(sel);
+    }
+}
+
+/* ------------ KEYBOARD Message ------------- */
+static void KeyboardMsg(DFWINDOW wnd, PARAM p1)
+{
+       MENU *mnu;
+       int sel;
+    if (mwnd == NULL)
+    {
+        /* ----- search for menu bar shortcut keys ---- */
+        int c = tolower((int)p1);
+        int a = AltConvert((int)p1);
+        int j;
+        for (j = 0; j < mctr; j++)    {
+            if ((inFocus == wnd && menu[j].sc == c) ||
+                    (a && menu[j].sc == a))    {
+                               DfSendMessage(wnd, SETFOCUS, TRUE, 0);
+                DfSendMessage(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;
+                    DfSendMessage(GetDocFocus(),
+                        SETFOCUS, TRUE, 0);
+                    DfPostMessage(GetParent(wnd),
+                        DFM_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+1);
+                               return;
+                       }
+                       break;
+
+        case '\r':
+            if (mwnd == NULL &&
+                    ActiveMenuBar->ActiveSelection != -1)
+                DfSendMessage(wnd, MB_SELECTION,
+                    ActiveMenuBar->ActiveSelection, 0);
+            break;
+        case F10:
+            if (wnd != inFocus && mwnd == NULL)    {
+                DfSendMessage(wnd, SETFOCUS, TRUE, 0);
+                           if ( ActiveMenuBar->ActiveSelection == -1)
+                               ActiveMenuBar->ActiveSelection = 0;
+                           DfSendMessage(wnd, PAINT, 0, 0);
+                break;
+            }
+            /* ------- fall through ------- */
+        case ESC:
+            if (inFocus == wnd && mwnd == NULL)    {
+                ActiveMenuBar->ActiveSelection = -1;
+                DfSendMessage(GetDocFocus(),SETFOCUS,TRUE,0);
+                DfSendMessage(wnd, PAINT, 0, 0);
+            }
+            break;
+        case FWD:
+            ActiveMenuBar->ActiveSelection++;
+            if (ActiveMenuBar->ActiveSelection == mctr)
+                ActiveMenuBar->ActiveSelection = 0;
+            if (mwnd != NULL)
+                DfSendMessage(wnd, MB_SELECTION,
+                    ActiveMenuBar->ActiveSelection, 0);
+            else 
+                DfSendMessage(wnd, PAINT, 0, 0);
+            break;
+        case BS:
+            if (ActiveMenuBar->ActiveSelection == 0 ||
+                                       ActiveMenuBar->ActiveSelection == -1)
+                ActiveMenuBar->ActiveSelection = mctr;
+            --ActiveMenuBar->ActiveSelection;
+            if (mwnd != NULL)
+                DfSendMessage(wnd, MB_SELECTION,
+                    ActiveMenuBar->ActiveSelection, 0);
+            else 
+                DfSendMessage(wnd, PAINT, 0, 0);
+            break;
+        default:
+            break;
+    }
+}
+
+/* --------------- LEFT_BUTTON Message ---------- */
+static void LeftButtonMsg(DFWINDOW wnd, PARAM p1)
+{
+    int i;
+    int mx = (int) p1 - GetLeft(wnd);
+    /* --- 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)
+            DfSendMessage(wnd, MB_SELECTION, i, 0);
+}
+
+/* -------------- MB_SELECTION Message -------------- */
+static void SelectionMsg(DFWINDOW wnd, PARAM p1, PARAM p2)
+{
+    int wd, mx, my;
+    MENU *mnu;
+
+       if (!p2)
+       {
+               ActiveMenuBar->ActiveSelection = -1;
+               DfSendMessage(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)
+            DfSendMessage(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 = DfCreateWindow(POPDOWNMENU, NULL,
+                mx, my,
+                MenuHeight(mnu->Selections),
+                wd,
+                NULL,
+                wnd,
+                NULL,
+                SHADOW);
+       if (!p2)
+       {
+               Selecting = FALSE;
+               DfSendMessage(wnd, PAINT, 0, 0);
+               Selecting = TRUE;
+       }
+       if (mnu->Selections[0].SelectionTitle != NULL)
+       {
+               DfSendMessage(mwnd, BUILD_SELECTIONS, (PARAM) mnu, 0);
+               DfSendMessage(mwnd, SETFOCUS, TRUE, 0);
+               DfSendMessage(mwnd, SHOW_WINDOW, 0, 0);
+       }
+       Selecting = FALSE;
+}
+
+/* --------- COMMAND Message ---------- */
+static void CommandMsg(DFWINDOW wnd, PARAM p1, PARAM p2)
+{
+       if (p1 == ID_HELP)
+       {
+               BaseWndProc(MENUBAR, wnd, DFM_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;
+                    DfSendMessage(wnd, MB_SELECTION,
+                        (PARAM)(mnu-ActiveMenu), TRUE);
+                }
+                break;
+            }
+            mnu++;
+        }
+    }
+    else     {
+        if (mwnd != NULL)
+            DfSendMessage(mwnd, CLOSE_WINDOW, 0, 0);
+        DfSendMessage(GetDocFocus(), SETFOCUS, TRUE, 0);
+        DfPostMessage(GetParent(wnd), DFM_COMMAND, p1, p2);
+    }
+}
+
+/* --------------- CLOSE_POPDOWN Message --------------- */
+static void ClosePopdownMsg(DFWINDOW wnd)
+{
+       if (casc > 0)
+               DfSendMessage(Cascaders[--casc], CLOSE_WINDOW, 0, 0);
+       else
+       {
+               mwnd = NULL;
+               ActiveMenuBar->ActiveSelection = -1;
+               if (!Selecting)
+               {
+                       DfSendMessage(GetDocFocus(), SETFOCUS, TRUE, 0);
+                       DfSendMessage(wnd, PAINT, 0, 0);
+               }
+       }
+}
+
+/* ---------------- CLOSE_WINDOW Message --------------- */
+static void CloseWindowMsg(DFWINDOW 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(DFWINDOW wnd, DFMESSAGE 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)
+                               DfSendMessage(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 DFM_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(DFWINDOW wnd)
+{
+    GetText(wnd) = DFrealloc(GetText(wnd), DfGetScreenWidth()+5);
+    memset(GetText(wnd), ' ', DfGetScreenWidth());
+    *(GetText(wnd)+WindowWidth(wnd)) = '\0';
+}
+
+static DFWINDOW GetDocFocus(void)
+{
+       DFWINDOW 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;
+}
+
+/* EOF */
diff --git a/rosapps/lib/dflat32/menus.c b/rosapps/lib/dflat32/menus.c
new file mode 100644 (file)
index 0000000..b78e8f8
--- /dev/null
@@ -0,0 +1,126 @@
+/* -------------- menus.c ------------- */
+
+#include "dflat32/dflat.h"
+
+/* --------------------- the main menu --------------------- */
+DEFMENU(MainMenu)
+    /* --------------- the File popdown menu ----------------*/
+    POPDOWN( "~File",  PrepFileMenu, "Read/write/print files. Go to DOS" )
+        SELECTION( "~New",        ID_NEW,          0, 0 )
+        SELECTION( "~Open...",    ID_OPEN,         0, 0 )
+        SEPARATOR
+        SELECTION( "~Save",       ID_SAVE,     ALT_S, INACTIVE)
+        SELECTION( "Save ~as...", ID_SAVEAS,       0, INACTIVE)
+        SELECTION( "D~elete",     ID_DELETEFILE,   0, INACTIVE)
+        SEPARATOR
+        SELECTION( "~Print",      ID_PRINT,        0, INACTIVE)
+        SELECTION( "P~rinter setup...", ID_PRINTSETUP, 0, 0   )
+        SEPARATOR
+        SELECTION( "~DOS",        ID_DOS,          0, 0 )
+        SELECTION( "E~xit",       ID_EXIT,     ALT_X, 0 )
+    ENDPOPDOWN
+
+    /* --------------- the Edit popdown menu ----------------*/
+    POPDOWN( "~Edit", PrepEditMenu, "Clipboard, delete text, paragraph" )
+        SELECTION( "~Undo",      ID_UNDO,  ALT_BS,    INACTIVE)
+        SEPARATOR
+        SELECTION( "Cu~t",       ID_CUT,   SHIFT_DEL, INACTIVE)
+        SELECTION( "~Copy",      ID_COPY,  CTRL_INS,  INACTIVE)
+        SELECTION( "~Paste",     ID_PASTE, SHIFT_INS, 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" )
+        SELECTION( "~Search...", ID_SEARCH,      0,    INACTIVE)
+        SELECTION( "~Replace...",ID_REPLACE,     0,    INACTIVE)
+        SELECTION( "~Next",      ID_SEARCHNEXT,  F3,   INACTIVE)
+    ENDPOPDOWN
+
+       /* ------------ the Utilities popdown menu --------------- */
+       POPDOWN( "~Utilities", NULL, "Utility programs" )
+               SELECTION( "~Calendar",   ID_CALENDAR,     0,   0)
+//                SELECTION( "~Bar chart",  ID_BARCHART,     0,   0)
+       ENDPOPDOWN
+
+    /* ------------- the Options popdown menu ---------------*/
+    POPDOWN( "~Options", NULL, "Editor and display options" )
+        SELECTION( "~Display...",   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" )
+        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 )
+#ifdef TESTING_DFLAT
+        SEPARATOR
+        SELECTION(  "~Reload help database",ID_LOADHELP,0, 0 )
+#endif
+    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
+
index 31dfaef..b7700b0 100644 (file)
@@ -1,13 +1,7 @@
-/* --------- message.c ---------- 
- * Message Que code for all events that dflat32
- * should know how to handle.
- *
- * You understand this? Good I'm glad one of us
- * does. - sedwards 3-24-02
- */
-
-#include <dflat32/dflat.h>
-#include <dflat32/system.h>
+/* --------- message.c ---------- */
+
+#include "dflat32/dflat.h"
+#include "dflat32/system.h"
 
 static int handshaking = 0;
 
 
 static int handshaking = 0;
 
diff --git a/rosapps/lib/dflat32/msgbox.c b/rosapps/lib/dflat32/msgbox.c
new file mode 100644 (file)
index 0000000..643c290
--- /dev/null
@@ -0,0 +1,216 @@
+/* ------------------ msgbox.c ------------------ */
+
+#include "dflat32/dflat.h"
+
+extern DBOX MsgBox;
+extern DBOX InputBoxDB;
+DFWINDOW CancelWnd;
+
+static int ReturnValue;
+
+int MessageBoxProc(DFWINDOW wnd, DFMESSAGE 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(DFWINDOW wnd, DFMESSAGE 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')
+                DfSendMessage(wnd, DFM_COMMAND, ID_OK, 0);
+            else if (c == 'n')
+                DfSendMessage(wnd, DFM_COMMAND, ID_CANCEL, 0);
+            break;
+        }
+        default:
+            break;
+    }
+    return BaseWndProc(MESSAGEBOX, wnd, msg, p1, p2);
+}
+
+int ErrorBoxProc(DFWINDOW wnd, DFMESSAGE 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(DFWINDOW wnd, DFMESSAGE msg, PARAM p1, PARAM p2)
+{
+    switch (msg)    {
+        case CREATE_WINDOW:
+            CancelWnd = wnd;
+            DfSendMessage(wnd, CAPTURE_MOUSE, 0, 0);
+            DfSendMessage(wnd, CAPTURE_KEYBOARD, 0, 0);
+            break;
+        case DFM_COMMAND:
+            if ((int) p1 == ID_CANCEL && (int) p2 == 0)
+                DfSendMessage(GetParent(wnd), msg, p1, p2);
+            return TRUE;
+        case CLOSE_WINDOW:
+            CancelWnd = NULL;
+            DfSendMessage(wnd, RELEASE_MOUSE, 0, 0);
+            DfSendMessage(wnd, RELEASE_KEYBOARD, 0, 0);
+            p1 = TRUE;
+            break;
+        default:
+            break;
+    }
+    return BaseWndProc(MESSAGEBOX, wnd, msg, p1, p2);
+}
+
+void CloseCancelBox(void)
+{
+    if (CancelWnd != NULL)
+        DfSendMessage(CancelWnd, CLOSE_WINDOW, 0, 0);
+}
+
+static char *InputText;
+static int TextLength;
+
+int InputBoxProc(DFWINDOW wnd, DFMESSAGE msg, PARAM p1, PARAM p2)
+{
+    int rtn;
+    switch (msg)    {
+        case CREATE_WINDOW:
+            rtn = DefaultWndProc(wnd, msg, p1, p2);
+            DfSendMessage(ControlWindow(&InputBoxDB,ID_INPUTTEXT),
+                        SETTEXTLENGTH, TextLength, 0);
+            return rtn;
+        case DFM_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(DFWINDOW wnd,char *ttl,char *msg,char *text,int len)
+{
+    InputText = text;
+    TextLength = len;
+    InputBoxDB.dwnd.title = ttl;
+    InputBoxDB.dwnd.w = 4 + 
+        max(20, max(len, max((int)strlen(ttl), (int)strlen(msg))));
+    InputBoxDB.ctl[1].dwnd.x = (InputBoxDB.dwnd.w-2-len)/2;
+    InputBoxDB.ctl[0].dwnd.w = strlen(msg);
+    InputBoxDB.ctl[0].itext = msg;
+    InputBoxDB.ctl[1].dwnd.w = len;
+    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 DfDialogBox(wnd, &InputBoxDB, TRUE, InputBoxProc);
+}
+
+BOOL GenericMessage(DFWINDOW 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);
+       if (ttl)
+               MsgBox.ctl[0].dwnd.w = max(max(MsgWidth(msg),
+                          (int)(buttonct*8 + buttonct + 2)), (int)strlen(ttl)+2);
+       else
+               MsgBox.ctl[0].dwnd.w = max(MsgWidth(msg), (int)(buttonct*8 + buttonct + 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 = DfDialogBox(wnd, &MsgBox, isModal, wndproc);
+    MsgBox.ctl[2].class = 0;
+    return rtn;
+}
+
+DFWINDOW MomentaryMessage(char *msg)
+{
+    DFWINDOW wnd = DfCreateWindow(
+                    TEXTBOX,
+                    NULL,
+                    -1,-1,MsgHeight(msg)+2,MsgWidth(msg)+2,
+                    NULL,NULL,NULL,
+                    HASBORDER | SHADOW | SAVESELF);
+    DfSendMessage(wnd, SETTEXT, (PARAM) msg, 0);
+    WindowClientColor(wnd, WHITE, GREEN);
+    WindowFrameColor(wnd, WHITE, GREEN);
+    DfSendMessage (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, DfGetScreenHeight ()-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((int)strlen(msg), (int)w), DfGetScreenWidth()-10);
+}
+
+/* EOF */
\ No newline at end of file
diff --git a/rosapps/lib/dflat32/normal.c b/rosapps/lib/dflat32/normal.c
new file mode 100644 (file)
index 0000000..262c345
--- /dev/null
@@ -0,0 +1,1085 @@
+/* ------------- normal.c ------------ */
+
+#include "dflat32/dflat.h"
+
+#ifdef INCLUDE_MULTI_WINDOWS
+static void PaintOverLappers(DFWINDOW wnd);
+static void PaintUnderLappers(DFWINDOW wnd);
+#endif
+
+static BOOL InsideWindow(DFWINDOW, int, int);
+static void TerminateMoveSize(void);
+static void SaveBorder(DFRECT);
+static void RestoreBorder(DFRECT);
+static void GetVideoBuffer(DFWINDOW);
+static void PutVideoBuffer(DFWINDOW);
+#ifdef INCLUDE_MINIMIZE
+static DFRECT PositionIcon(DFWINDOW);
+#endif
+static void dragborder(DFWINDOW, int, int);
+static void sizeborder(DFWINDOW, int, int);
+static int px = -1, py = -1;
+static int diff;
+static struct window dwnd = {DUMMY, NULL, NormalProc,
+                                {-1,-1,-1,-1}};
+static PCHAR_INFO Bsave;
+static int Bht, Bwd;
+BOOL WindowMoving;
+BOOL WindowSizing;
+/* -------- array of class definitions -------- */
+CLASSDEFS classdefs[] = {
+    #undef ClassDef
+    #define ClassDef(c,b,p,a) {b,p,a},
+    #include "dflat32/classes.h"
+};
+DFWINDOW HiddenWindow;
+
+/* --------- CREATE_WINDOW Message ---------- */
+static void CreateWindowMsg(DFWINDOW wnd)
+{
+       AppendWindow(wnd);
+//     ClearAttribute(wnd, VSCROLLBAR | HSCROLLBAR);
+       if (TestAttribute(wnd, SAVESELF) && isVisible(wnd))
+               GetVideoBuffer(wnd);
+}
+
+/* --------- SHOW_WINDOW Message ---------- */
+static void ShowWindowMsg(DFWINDOW wnd, PARAM p1, PARAM p2)
+{
+       if (GetParent(wnd) == NULL || isVisible(GetParent(wnd)))
+       {
+               DFWINDOW cwnd;
+
+               if (TestAttribute(wnd, SAVESELF) && wnd->videosave == NULL)
+                       GetVideoBuffer(wnd);
+               SetVisible(wnd);
+               DfSendMessage(wnd, PAINT, 0, TRUE);
+               DfSendMessage(wnd, BORDER, 0, 0);
+               /* --- show the children of this window --- */
+               cwnd = FirstWindow(wnd);
+               while (cwnd != NULL)
+               {
+                       if (cwnd->condition != ISCLOSING)
+                               DfSendMessage(cwnd, SHOW_WINDOW, p1, p2);
+                       cwnd = NextWindow(cwnd);
+               }
+       }
+}
+
+/* --------- HIDE_WINDOW Message ---------- */
+static void HideWindowMsg(DFWINDOW wnd)
+{
+       if (isVisible(wnd))
+       {
+               ClearVisible(wnd);
+               /* --- paint what this window covered --- */
+               if (TestAttribute(wnd, SAVESELF))
+                       PutVideoBuffer(wnd);
+#ifdef INCLUDE_MULTI_WINDOWS
+               else
+                       PaintOverLappers(wnd);
+#endif
+    }
+}
+
+/* --------- KEYBOARD Message ---------- */
+static BOOL KeyboardMsg(DFWINDOW wnd, PARAM p1, PARAM p2)
+{
+    if (WindowMoving || WindowSizing)    {
+        /* -- move or size a window with keyboard -- */
+        int x, y;
+        x=WindowMoving?GetLeft(&dwnd):GetRight(&dwnd);
+        y=WindowMoving?GetTop(&dwnd):GetBottom(&dwnd);
+        switch ((int)p1)    {
+            case ESC:
+                TerminateMoveSize();
+                return TRUE;
+            case UP:
+                if (y)
+                    --y;
+                break;
+            case DN:
+                if (y < DfGetScreenHeight()-1)
+                    y++;
+                break;
+            case FWD:
+                if (x < DfGetScreenWidth()-1)
+                    x++;
+                break;
+            case BS:
+                if (x)
+                    --x;
+                break;
+            case '\r':
+                DfSendMessage(wnd, DFM_BUTTON_RELEASED,x,y);
+            default:
+                return TRUE;
+        }
+        /* -- use the mouse functions to move/size - */
+        DfSendMessage(wnd, MOUSE_MOVED, x, y);
+        return TRUE;
+    }
+
+       switch ((int)p1)
+       {
+               case F1:
+                       DfSendMessage(wnd, DFM_COMMAND, ID_HELP, 0);
+                       return TRUE;
+
+               case ' ':
+                       if ((int)p2 & ALTKEY)
+                               if (TestAttribute(wnd, HASTITLEBAR))
+                                       if (TestAttribute(wnd, CONTROLBOX))
+                                               BuildSystemMenu(wnd);
+                       return TRUE;
+
+               case CTRL_F4:
+                       if (TestAttribute(wnd, CONTROLBOX))
+                       {
+                               DfSendMessage(wnd, CLOSE_WINDOW, 0, 0);
+                               SkipApplicationControls();
+                               return TRUE;
+                       }
+                       break;
+
+               default:
+                       break;
+       }
+
+       return FALSE;
+}
+
+/* --------- COMMAND Message ---------- */
+static void CommandMsg(DFWINDOW wnd, PARAM p1)
+{
+    switch ((int)p1)    {
+        case ID_HELP:
+            DisplayHelp(wnd,ClassNames[GetClass(wnd)]);
+            break;
+#ifdef INCLUDE_RESTORE
+        case ID_SYSRESTORE:
+            DfSendMessage(wnd, RESTORE, 0, 0);
+            break;
+#endif
+        case ID_SYSMOVE:
+            DfSendMessage(wnd, CAPTURE_MOUSE, TRUE,
+                (PARAM) &dwnd);
+            DfSendMessage(wnd, CAPTURE_KEYBOARD, TRUE,
+                (PARAM) &dwnd);
+            WindowMoving = TRUE;
+            dragborder(wnd, GetLeft(wnd), GetTop(wnd));
+            break;
+        case ID_SYSSIZE:
+            DfSendMessage(wnd, CAPTURE_MOUSE, TRUE,
+                (PARAM) &dwnd);
+            DfSendMessage(wnd, CAPTURE_KEYBOARD, TRUE,
+                (PARAM) &dwnd);
+            WindowSizing = TRUE;
+            dragborder(wnd, GetLeft(wnd), GetTop(wnd));
+            break;
+#ifdef INCLUDE_MINIMIZE
+        case ID_SYSMINIMIZE:
+            DfSendMessage(wnd, MINIMIZE, 0, 0);
+            break;
+#endif
+#ifdef INCLUDE_MAXIMIZE
+        case ID_SYSMAXIMIZE:
+            DfSendMessage(wnd, MAXIMIZE, 0, 0);
+            break;
+#endif
+        case ID_SYSCLOSE:
+            DfSendMessage(wnd, CLOSE_WINDOW, 0, 0);
+                       SkipApplicationControls();
+            break;
+        default:
+            break;
+    }
+}
+
+/* --------- SETFOCUS Message ---------- */
+static void SetFocusMsg(DFWINDOW wnd, PARAM p1)
+{
+       DFRECT rc = {0,0,0,0};
+
+       if (p1 && wnd != NULL && inFocus != wnd)
+       {
+               DFWINDOW this, thispar;
+               DFWINDOW that = NULL, thatpar = NULL;
+
+               DFWINDOW cwnd = wnd, fwnd = GetParent(wnd);
+               /* ---- post focus in ancestors ---- */
+               while (fwnd != NULL)
+               {
+                       fwnd->childfocus = cwnd;
+                       cwnd = fwnd;
+                       fwnd = GetParent(fwnd);
+               }
+               /* ---- de-post focus in self and children ---- */
+               fwnd = wnd;
+               while (fwnd != NULL)
+               {
+                       cwnd = fwnd->childfocus;
+                       fwnd->childfocus = NULL;
+                       fwnd = cwnd;
+               }
+
+               this = wnd;
+               that = thatpar = inFocus;
+
+               /* ---- find common ancestor of prev focus and this window --- */
+               while (thatpar != NULL)
+               {
+                       thispar = wnd;
+                       while (thispar != NULL)
+                       {
+                               if (this == CaptureMouse || this == CaptureKeyboard)
+                               {
+                                       /* ---- don't repaint if this window has capture ---- */
+                                       that = thatpar = NULL;
+                                       break;
+                               }
+                               if (thispar == thatpar)
+                               {
+                                       /* ---- don't repaint if SAVESELF window had focus ---- */
+                                       if (this != that && TestAttribute(that, SAVESELF))
+                                               that = thatpar = NULL;
+                                       break;
+                               }
+                               this = thispar;
+                               thispar = GetParent(thispar);
+                       }
+                       if (thispar != NULL)
+                               break;
+                       that = thatpar;
+                       thatpar = GetParent(thatpar);
+               }
+               if (inFocus != NULL)
+                       DfSendMessage(inFocus, SETFOCUS, FALSE, 0);
+               inFocus = wnd;
+               if (that != NULL && isVisible(wnd))
+               {
+                       rc = subRectangle(WindowRect(that), WindowRect(this));
+                       if (!ValidRect(rc))
+                       {
+                               if (ApplicationWindow != NULL)
+                               {
+                                       DFWINDOW fwnd = FirstWindow(ApplicationWindow);
+                                       while (fwnd != NULL)
+                                       {
+                                               if (!isAncestor(wnd, fwnd))
+                                               {
+                                                       rc = subRectangle(WindowRect(wnd),WindowRect(fwnd));
+                                                       if (ValidRect(rc))
+                                                               break;
+                                               }
+                                               fwnd = NextWindow(fwnd);
+                                       }
+                               }
+                       }
+               }
+               if (that != NULL && !ValidRect(rc) && isVisible(wnd))
+               {
+                       DfSendMessage(wnd, BORDER, 0, 0);
+                       this = NULL;
+               }
+               ReFocus(wnd);
+               if (this != NULL)
+               DfSendMessage(this, SHOW_WINDOW, 0, 0);
+       }
+       else if (!p1 && inFocus == wnd)
+       {
+               /* clearing focus */
+               inFocus = NULL;
+               DfSendMessage(wnd, BORDER, 0, 0);
+       }
+}
+
+/* --------- DOUBLE_CLICK Message ---------- */
+static void DoubleClickMsg(DFWINDOW wnd, PARAM p1, PARAM p2)
+{
+    int mx = (int) p1 - GetLeft(wnd);
+    int my = (int) p2 - GetTop(wnd);
+    if (!WindowSizing && !WindowMoving)        {
+        if (HitControlBox(wnd, mx, my))        {
+            DfPostMessage(wnd, CLOSE_WINDOW, 0, 0);
+                       SkipApplicationControls();
+               }
+       }
+}
+
+/* --------- LEFT_BUTTON Message ---------- */
+static void LeftButtonMsg(DFWINDOW wnd, PARAM p1, PARAM p2)
+{
+    int mx = (int) p1 - GetLeft(wnd);
+    int my = (int) p2 - GetTop(wnd);
+    if (WindowSizing || WindowMoving)
+        return;
+    if (HitControlBox(wnd, mx, my))    {
+        BuildSystemMenu(wnd);
+        return;
+    }
+    if (my == 0 && mx > -1 && mx < WindowWidth(wnd))  {
+        /* ---------- hit the top border -------- */
+        if (TestAttribute(wnd, MINMAXBOX) &&
+                TestAttribute(wnd, HASTITLEBAR))  {
+            if (mx == WindowWidth(wnd)-2)    {
+                if (wnd->condition != ISRESTORED)
+                    /* --- hit the restore box --- */
+                    DfSendMessage(wnd, RESTORE, 0, 0);
+#ifdef INCLUDE_MAXIMIZE
+                else
+                    /* --- hit the maximize box --- */
+                    DfSendMessage(wnd, MAXIMIZE, 0, 0);
+#endif
+                return;
+            }
+#ifdef INCLUDE_MINIMIZE
+            if (mx == WindowWidth(wnd)-3)    {
+                /* --- hit the minimize box --- */
+                if (wnd->condition != ISMINIMIZED)
+                    DfSendMessage(wnd, MINIMIZE, 0, 0);
+                return;
+            }
+#endif
+        }
+#ifdef INCLUDE_MAXIMIZE
+        if (wnd->condition == ISMAXIMIZED)
+            return;
+#endif
+        if (TestAttribute(wnd, MOVEABLE))    {
+            WindowMoving = TRUE;
+            px = mx;
+            py = my;
+            diff = (int) mx;
+            DfSendMessage(wnd, CAPTURE_MOUSE, TRUE,
+                (PARAM) &dwnd);
+            dragborder(wnd, GetLeft(wnd), GetTop(wnd));
+        }
+        return;
+    }
+    if (mx == WindowWidth(wnd)-1 &&
+            my == WindowHeight(wnd)-1)    {
+        /* ------- hit the resize corner ------- */
+#ifdef INCLUDE_MINIMIZE
+        if (wnd->condition == ISMINIMIZED)
+            return;
+#endif
+        if (!TestAttribute(wnd, SIZEABLE))
+            return;
+#ifdef INCLUDE_MAXIMIZE
+        if (wnd->condition == ISMAXIMIZED)    {
+            if (GetParent(wnd) == NULL)
+                return;
+            if (TestAttribute(GetParent(wnd),HASBORDER))
+                return;
+            /* ----- resizing a maximized window over a
+                    borderless parent ----- */
+            wnd = GetParent(wnd);
+        }
+#endif
+        WindowSizing = TRUE;
+        DfSendMessage(wnd, CAPTURE_MOUSE,
+            TRUE, (PARAM) &dwnd);
+        dragborder(wnd, GetLeft(wnd), GetTop(wnd));
+    }
+}
+
+/* --------- MOUSE_MOVED Message ---------- */
+static BOOL MouseMovedMsg(DFWINDOW wnd, PARAM p1, PARAM p2)
+{
+    if (WindowMoving)    {
+        int leftmost = 0, topmost = 0,
+            bottommost = DfGetScreenHeight()-2,
+            rightmost = DfGetScreenWidth()-2;
+        int x = (int) p1 - diff;
+        int y = (int) p2;
+        if (GetParent(wnd) != NULL &&
+                !TestAttribute(wnd, NOCLIP))    {
+            DFWINDOW wnd1 = GetParent(wnd);
+            topmost    = GetClientTop(wnd1);
+            leftmost   = GetClientLeft(wnd1);
+            bottommost = GetClientBottom(wnd1);
+            rightmost  = GetClientRight(wnd1);
+        }
+        if (x < leftmost || x > rightmost ||
+                y < topmost || y > bottommost)    {
+            x = max(x, leftmost);
+            x = min(x, rightmost);
+            y = max(y, topmost);
+            y = min(y, bottommost);
+        }
+
+        if (x != px || y != py)    {
+            px = x;
+            py = y;
+            dragborder(wnd, x, y);
+        }
+        return TRUE;
+    }
+    if (WindowSizing)    {
+        sizeborder(wnd, (int) p1, (int) p2);
+        return TRUE;
+    }
+    return FALSE;
+}
+
+#ifdef INCLUDE_MAXIMIZE
+/* --------- MAXIMIZE Message ---------- */
+static void MaximizeMsg(DFWINDOW wnd)
+{
+    DFRECT rc = {0, 0, 0, 0};
+    DFRECT holdrc;
+    holdrc = wnd->RestoredRC;
+    rc.rt = DfGetScreenWidth()-1;
+    rc.bt = DfGetScreenHeight()-1;
+    if (GetParent(wnd))
+        rc = ClientRect(GetParent(wnd));
+    wnd->oldcondition = wnd->condition;
+    wnd->condition = ISMAXIMIZED;
+    DfSendMessage(wnd, DFM_HIDE_WINDOW, 0, 0);
+    DfSendMessage(wnd, MOVE,
+        RectLeft(rc), RectTop(rc));
+    DfSendMessage(wnd, DFM_SIZE,
+        RectRight(rc), RectBottom(rc));
+    if (wnd->restored_attrib == 0)
+        wnd->restored_attrib = wnd->attrib;
+    ClearAttribute(wnd, SHADOW);
+    DfSendMessage(wnd, SHOW_WINDOW, 0, 0);
+    wnd->RestoredRC = holdrc;
+}
+#endif
+
+#ifdef INCLUDE_MINIMIZE
+/* --------- MINIMIZE Message ---------- */
+static void MinimizeMsg(DFWINDOW wnd)
+{
+    DFRECT rc;
+    DFRECT holdrc;
+
+    holdrc = wnd->RestoredRC;
+    rc = PositionIcon(wnd);
+    wnd->oldcondition = wnd->condition;
+    wnd->condition = ISMINIMIZED;
+    DfSendMessage(wnd, DFM_HIDE_WINDOW, 0, 0);
+    DfSendMessage(wnd, MOVE,
+        RectLeft(rc), RectTop(rc));
+    DfSendMessage(wnd, DFM_SIZE,
+        RectRight(rc), RectBottom(rc));
+       if (wnd == inFocus)
+           SetNextFocus();
+    if (wnd->restored_attrib == 0)
+        wnd->restored_attrib = wnd->attrib;
+    ClearAttribute(wnd,
+        SHADOW | SIZEABLE | HASMENUBAR |
+        VSCROLLBAR | HSCROLLBAR);
+    DfSendMessage(wnd, SHOW_WINDOW, 0, 0);
+    wnd->RestoredRC = holdrc;
+}
+#endif
+
+#ifdef INCLUDE_RESTORE
+/* --------- RESTORE Message ---------- */
+static void RestoreMsg(DFWINDOW wnd)
+{
+    DFRECT holdrc;
+    holdrc = wnd->RestoredRC;
+    wnd->oldcondition = wnd->condition;
+    wnd->condition = ISRESTORED;
+    DfSendMessage(wnd, DFM_HIDE_WINDOW, 0, 0);
+    wnd->attrib = wnd->restored_attrib;
+    wnd->restored_attrib = 0;
+    DfSendMessage(wnd, MOVE, wnd->RestoredRC.lf,
+        wnd->RestoredRC.tp);
+    wnd->RestoredRC = holdrc;
+    DfSendMessage(wnd, DFM_SIZE, wnd->RestoredRC.rt,
+        wnd->RestoredRC.bt);
+       if (wnd != inFocus)
+           DfSendMessage(wnd, SETFOCUS, TRUE, 0);
+       else
+           DfSendMessage(wnd, SHOW_WINDOW, 0, 0);
+}
+#endif
+
+/* --------- MOVE Message ---------- */
+static void MoveMsg(DFWINDOW wnd, PARAM p1, PARAM p2)
+{
+    DFWINDOW cwnd;
+    BOOL wasVisible = isVisible(wnd);
+    int xdif = (int) p1 - wnd->rc.lf;
+    int ydif = (int) p2 - wnd->rc.tp;
+
+    if (xdif == 0 && ydif == 0)
+        return;
+    if (wasVisible)
+        DfSendMessage(wnd, DFM_HIDE_WINDOW, 0, 0);
+    wnd->rc.lf = (int) p1;
+    wnd->rc.tp = (int) p2;
+    wnd->rc.rt = GetLeft(wnd)+WindowWidth(wnd)-1;
+    wnd->rc.bt = GetTop(wnd)+WindowHeight(wnd)-1;
+    if (wnd->condition == ISRESTORED)
+        wnd->RestoredRC = wnd->rc;
+
+       cwnd = FirstWindow(wnd);
+       while (cwnd != NULL)    {
+        DfSendMessage(cwnd, MOVE, cwnd->rc.lf+xdif, cwnd->rc.tp+ydif);
+               cwnd = NextWindow(cwnd);
+    }
+    if (wasVisible)
+        DfSendMessage(wnd, SHOW_WINDOW, 0, 0);
+}
+
+/* --------- SIZE Message ---------- */
+static void SizeMsg(DFWINDOW wnd, PARAM p1, PARAM p2)
+{
+    BOOL wasVisible = isVisible(wnd);
+    DFWINDOW cwnd;
+    DFRECT rc;
+    int xdif = (int) p1 - wnd->rc.rt;
+    int ydif = (int) p2 - wnd->rc.bt;
+
+    if (xdif == 0 && ydif == 0)
+        return;
+    if (wasVisible)
+        DfSendMessage(wnd, DFM_HIDE_WINDOW, 0, 0);
+    wnd->rc.rt = (int) p1;
+    wnd->rc.bt = (int) p2;
+    wnd->ht = GetBottom(wnd)-GetTop(wnd)+1;
+    wnd->wd = GetRight(wnd)-GetLeft(wnd)+1;
+
+    if (wnd->condition == ISRESTORED)
+        wnd->RestoredRC = WindowRect(wnd);
+
+#ifdef INCLUDE_MAXIMIZE
+    rc = ClientRect(wnd);
+
+       cwnd = FirstWindow(wnd);
+       while (cwnd != NULL)    {
+        if (cwnd->condition == ISMAXIMIZED)
+            DfSendMessage(cwnd, DFM_SIZE, RectRight(rc), RectBottom(rc));
+               cwnd = NextWindow(cwnd);
+    }
+
+#endif
+    if (wasVisible)
+        DfSendMessage(wnd, SHOW_WINDOW, 0, 0);
+}
+
+/* --------- CLOSE_WINDOW Message ---------- */
+static void CloseWindowMsg(DFWINDOW wnd)
+{
+    DFWINDOW cwnd;
+    wnd->condition = ISCLOSING;
+    if (wnd->PrevMouse != NULL)
+        DfSendMessage(wnd, RELEASE_MOUSE, 0, 0);
+    if (wnd->PrevKeyboard != NULL)
+        DfSendMessage(wnd, RELEASE_KEYBOARD, 0, 0);
+    /* ----------- hide this window ------------ */
+    DfSendMessage(wnd, DFM_HIDE_WINDOW, 0, 0);
+    /* --- close the children of this window --- */
+
+       cwnd = LastWindow(wnd);
+       while (cwnd != NULL)    {
+        if (inFocus == cwnd)
+            inFocus = wnd;
+        DfSendMessage(cwnd,CLOSE_WINDOW,0,0);
+               cwnd = LastWindow(wnd);
+    }
+
+    /* --- change focus if this window had it -- */
+       if (wnd == inFocus)
+           SetPrevFocus();
+    /* -- free memory allocated to this window - */
+    if (wnd->title != NULL)
+        free(wnd->title);
+    if (wnd->videosave != NULL)
+        free(wnd->videosave);
+    /* -- remove window from parent's list of children -- */
+       RemoveWindow(wnd);
+    if (wnd == inFocus)
+        inFocus = NULL;
+    free(wnd);
+}
+
+/* ---- Window-processing module for NORMAL window class ---- */
+int NormalProc(DFWINDOW wnd, DFMESSAGE msg, PARAM p1, PARAM p2)
+{
+    switch (msg)    {
+        case CREATE_WINDOW:
+            CreateWindowMsg(wnd);
+            break;
+        case SHOW_WINDOW:
+            ShowWindowMsg(wnd, p1, p2);
+            break;
+        case DFM_HIDE_WINDOW:
+            HideWindowMsg(wnd);
+            break;
+        case DISPLAY_HELP:
+            DisplayHelp(wnd, (char *)p1);
+            break;
+        case INSIDE_WINDOW:
+            return InsideWindow(wnd, (int) p1, (int) p2);
+        case KEYBOARD:
+            if (KeyboardMsg(wnd, p1, p2))
+                return TRUE;
+            /* ------- fall through ------- */
+        case ADDSTATUS:
+        case SHIFT_CHANGED:
+            if (GetParent(wnd) != NULL)
+                DfPostMessage(GetParent(wnd), msg, p1, p2);
+            break;
+        case PAINT:
+            if (isVisible(wnd))
+                ClearWindow(wnd, (DFRECT *)p1, ' ');
+            break;
+        case BORDER:
+            if (isVisible(wnd))
+            {
+                if (TestAttribute(wnd, HASBORDER))
+                    RepaintBorder(wnd, (DFRECT *)p1);
+                else if (TestAttribute(wnd, HASTITLEBAR))
+                    DisplayTitle(wnd, (DFRECT *)p1);
+            }
+            break;
+        case DFM_COMMAND:
+            CommandMsg(wnd, p1);
+            break;
+        case SETFOCUS:
+            SetFocusMsg(wnd, p1);
+            break;
+        case DFM_DOUBLE_CLICK:
+            DoubleClickMsg(wnd, p1, p2);
+            break;
+        case LEFT_BUTTON:
+            LeftButtonMsg(wnd, p1, p2);
+            break;
+        case MOUSE_MOVED:
+            if (MouseMovedMsg(wnd, p1, p2))
+                return TRUE;
+            break;
+        case DFM_BUTTON_RELEASED:
+            if (WindowMoving || WindowSizing)
+            {
+                if (WindowMoving)
+                    DfPostMessage(wnd,MOVE,dwnd.rc.lf,dwnd.rc.tp);
+                else
+                    DfPostMessage(wnd, DFM_SIZE,dwnd.rc.rt,dwnd.rc.bt);
+                TerminateMoveSize();
+            }
+            break;
+#ifdef INCLUDE_MAXIMIZE
+        case MAXIMIZE:
+            if (wnd->condition != ISMAXIMIZED)
+                MaximizeMsg(wnd);
+            break;
+#endif
+#ifdef INCLUDE_MINIMIZE
+        case MINIMIZE:
+            if (wnd->condition != ISMINIMIZED)
+                MinimizeMsg(wnd);
+            break;
+#endif
+#ifdef INCLUDE_RESTORE
+        case RESTORE:
+            if (wnd->condition != ISRESTORED)    {
+#ifdef INCLUDE_MAXIMIZE
+                if (wnd->oldcondition == ISMAXIMIZED)
+                    DfSendMessage(wnd, MAXIMIZE, 0, 0);
+                else
+#endif
+                    RestoreMsg(wnd);
+            }
+            break;
+#endif
+        case MOVE:
+            MoveMsg(wnd, p1, p2);
+            break;
+        case DFM_SIZE:    {
+            SizeMsg(wnd, p1, p2);
+            break;
+        }
+        case CLOSE_WINDOW:
+            CloseWindowMsg(wnd);
+            break;
+        default:
+            break;
+    }
+    return TRUE;
+}
+#ifdef INCLUDE_MINIMIZE
+/* ---- compute lower right icon space in a rectangle ---- */
+static DFRECT LowerRight(DFRECT prc)
+{
+    DFRECT rc;
+    RectLeft(rc) = RectRight(prc) - ICONWIDTH;
+    RectTop(rc) = RectBottom(prc) - ICONHEIGHT;
+    RectRight(rc) = RectLeft(rc)+ICONWIDTH-1;
+    RectBottom(rc) = RectTop(rc)+ICONHEIGHT-1;
+    return rc;
+}
+/* ----- compute a position for a minimized window icon ---- */
+static DFRECT PositionIcon(DFWINDOW wnd)
+{
+       DFWINDOW pwnd = GetParent(wnd);
+    DFRECT rc;
+    RectLeft(rc) = DfGetScreenWidth()-ICONWIDTH;
+    RectTop(rc) = DfGetScreenHeight()-ICONHEIGHT;
+    RectRight(rc) = DfGetScreenWidth()-1;
+    RectBottom(rc) = DfGetScreenHeight()-1;
+    if (pwnd != NULL)    {
+        DFRECT prc = WindowRect(pwnd);
+               DFWINDOW cwnd = FirstWindow(pwnd);
+        rc = LowerRight(prc);
+        /* - search for icon available location - */
+               while (cwnd != NULL)    {
+            if (cwnd->condition == ISMINIMIZED)    {
+                DFRECT rc1;
+                rc1 = WindowRect(cwnd);
+                if (RectLeft(rc1) == RectLeft(rc) &&
+                        RectTop(rc1) == RectTop(rc))    {
+                    RectLeft(rc) -= ICONWIDTH;
+                    RectRight(rc) -= ICONWIDTH;
+                    if (RectLeft(rc) < RectLeft(prc)+1)   {
+                        RectLeft(rc) =
+                            RectRight(prc)-ICONWIDTH;
+                        RectRight(rc) =
+                            RectLeft(rc)+ICONWIDTH-1;
+                        RectTop(rc) -= ICONHEIGHT;
+                        RectBottom(rc) -= ICONHEIGHT;
+                        if (RectTop(rc) < RectTop(prc)+1)
+                            return LowerRight(prc);
+                    }
+                    break;
+                }
+            }
+                       cwnd = NextWindow(cwnd);
+        }
+    }
+    return rc;
+}
+#endif
+/* ----- terminate the move or size operation ----- */
+static void TerminateMoveSize(void)
+{
+    px = py = -1;
+    diff = 0;
+    DfSendMessage(&dwnd, RELEASE_MOUSE, TRUE, 0);
+    DfSendMessage(&dwnd, RELEASE_KEYBOARD, TRUE, 0);
+    RestoreBorder(dwnd.rc);
+    WindowMoving = WindowSizing = FALSE;
+}
+/* ---- build a dummy window border for moving or sizing --- */
+static void dragborder(DFWINDOW wnd, int x, int y)
+{
+    RestoreBorder(dwnd.rc);
+    /* ------- build the dummy window -------- */
+    dwnd.rc.lf = x;
+    dwnd.rc.tp = y;
+    dwnd.rc.rt = dwnd.rc.lf+WindowWidth(wnd)-1;
+    dwnd.rc.bt = dwnd.rc.tp+WindowHeight(wnd)-1;
+    dwnd.ht = WindowHeight(wnd);
+    dwnd.wd = WindowWidth(wnd);
+    dwnd.parent = GetParent(wnd);
+    dwnd.attrib = VISIBLE | HASBORDER | NOCLIP;
+    InitWindowColors(&dwnd);
+    SaveBorder(dwnd.rc);
+    RepaintBorder(&dwnd, NULL);
+}
+/* ---- write the dummy window border for sizing ---- */
+static void sizeborder(DFWINDOW wnd, int rt, int bt)
+{
+    int leftmost = GetLeft(wnd)+10;
+    int topmost = GetTop(wnd)+3;
+    int bottommost = DfGetScreenHeight()-1;
+    int rightmost  = DfGetScreenWidth()-1;
+    if (GetParent(wnd))    {
+        bottommost = min(bottommost,
+            GetClientBottom(GetParent(wnd)));
+        rightmost  = min(rightmost,
+            GetClientRight(GetParent(wnd)));
+    }
+    rt = min(rt, rightmost);
+    bt = min(bt, bottommost);
+    rt = max(rt, leftmost);
+    bt = max(bt, topmost);
+
+    if (rt != px || bt != py)
+        RestoreBorder(dwnd.rc);
+
+    /* ------- change the dummy window -------- */
+    dwnd.ht = bt-dwnd.rc.tp+1;
+    dwnd.wd = rt-dwnd.rc.lf+1;
+    dwnd.rc.rt = rt;
+    dwnd.rc.bt = bt;
+    if (rt != px || bt != py)    {
+        px = rt;
+        py = bt;
+        SaveBorder(dwnd.rc);
+        RepaintBorder(&dwnd, NULL);
+    }
+}
+#ifdef INCLUDE_MULTI_WINDOWS
+/* ----- adjust a rectangle to include the shadow ----- */
+static DFRECT adjShadow(DFWINDOW wnd)
+{
+    DFRECT rc;
+    rc = wnd->rc;
+    if (TestAttribute(wnd, SHADOW))    {
+        if (RectRight(rc) < DfGetScreenWidth()-1)
+            RectRight(rc)++;
+        if (RectBottom(rc) < DfGetScreenHeight()-1)
+            RectBottom(rc)++;
+    }
+    return rc;
+}
+/* --- repaint a rectangular subsection of a window --- */
+static void PaintOverLap(DFWINDOW wnd, DFRECT rc)
+{
+    if (isVisible(wnd))    {
+        int isBorder, isTitle, isData;
+        isBorder = isTitle = FALSE;
+        isData = TRUE;
+        if (TestAttribute(wnd, HASBORDER))    {
+            isBorder =  RectLeft(rc) == 0 &&
+                        RectTop(rc) < WindowHeight(wnd);
+            isBorder |= RectLeft(rc) < WindowWidth(wnd) &&
+                        RectRight(rc) >= WindowWidth(wnd)-1 &&
+                        RectTop(rc) < WindowHeight(wnd);
+            isBorder |= RectTop(rc) == 0 &&
+                        RectLeft(rc) < WindowWidth(wnd);
+            isBorder |= RectTop(rc) < WindowHeight(wnd) &&
+                        RectBottom(rc) >= WindowHeight(wnd)-1 &&
+                        RectLeft(rc) < WindowWidth(wnd);
+        }
+        else if (TestAttribute(wnd, HASTITLEBAR))
+            isTitle = RectTop(rc) == 0 &&
+                      RectRight(rc) > 0 &&
+                      RectLeft(rc)<WindowWidth(wnd)-BorderAdj(wnd);
+
+        if (RectLeft(rc) >= WindowWidth(wnd)-BorderAdj(wnd))
+            isData = FALSE;
+        if (RectTop(rc) >= WindowHeight(wnd)-BottomBorderAdj(wnd))
+            isData = FALSE;
+        if (TestAttribute(wnd, HASBORDER))    {
+            if (RectRight(rc) == 0)
+                isData = FALSE;
+            if (RectBottom(rc) == 0)
+                isData = FALSE;
+        }
+        if (TestAttribute(wnd, SHADOW))
+            isBorder |= RectRight(rc) == WindowWidth(wnd) ||
+                        RectBottom(rc) == WindowHeight(wnd);
+        if (isData)
+            DfSendMessage(wnd, PAINT, (PARAM) &rc, TRUE);
+        if (isBorder)
+            DfSendMessage(wnd, BORDER, (PARAM) &rc, 0);
+        else if (isTitle)
+            DisplayTitle(wnd, &rc);
+    }
+}
+/* ------ paint the part of a window that is overlapped
+            by another window that is being hidden ------- */
+static void PaintOver(DFWINDOW wnd)
+{
+    DFRECT wrc, rc;
+    wrc = adjShadow(HiddenWindow);
+    rc = adjShadow(wnd);
+    rc = subRectangle(rc, wrc);
+    if (ValidRect(rc))
+        PaintOverLap(wnd, RelativeWindowRect(wnd, rc));
+}
+/* --- paint the overlapped parts of all children --- */
+static void PaintOverChildren(DFWINDOW pwnd)
+{
+    DFWINDOW cwnd = FirstWindow(pwnd);
+    while (cwnd != NULL)    {
+        if (cwnd != HiddenWindow)    {
+            PaintOver(cwnd);
+            PaintOverChildren(cwnd);
+        }
+        cwnd = NextWindow(cwnd);
+    }
+}
+/* -- recursive overlapping paint of parents -- */
+static void PaintOverParents(DFWINDOW wnd)
+{
+    DFWINDOW pwnd = GetParent(wnd);
+    if (pwnd != NULL)    {
+        PaintOverParents(pwnd);
+        PaintOver(pwnd);
+        PaintOverChildren(pwnd);
+    }
+}
+/* - paint the parts of all windows that a window is over - */
+static void PaintOverLappers(DFWINDOW wnd)
+{
+    HiddenWindow = wnd;
+    PaintOverParents(wnd);
+}
+/* --- paint those parts of a window that are overlapped --- */
+static void PaintUnderLappers(DFWINDOW wnd)
+{
+    DFWINDOW hwnd = NextWindow(wnd);
+    while (hwnd != NULL)    {
+        /* ------- test only at document window level ------ */
+        DFWINDOW pwnd = GetParent(hwnd);
+/*        if (pwnd == NULL || GetClass(pwnd) == APPLICATION)  */  {
+            /* ---- don't bother testing self ----- */
+            if (isVisible(hwnd) && hwnd != wnd)    {
+                /* --- see if other window is descendent --- */
+                while (pwnd != NULL)    {
+                    if (pwnd == wnd)
+                        break;
+                    pwnd = GetParent(pwnd);
+                }
+                /* ----- don't test descendent overlaps ----- */
+                if (pwnd == NULL)    {
+                    /* -- see if other window is ancestor --- */
+                    pwnd = GetParent(wnd);
+                    while (pwnd != NULL)    {
+                        if (pwnd == hwnd)
+                            break;
+                        pwnd = GetParent(pwnd);
+                    }
+                    /* --- don't test ancestor overlaps --- */
+                    if (pwnd == NULL)    {
+                        HiddenWindow = GetAncestor(hwnd);
+                        ClearVisible(HiddenWindow);
+                        PaintOver(wnd);
+                        SetVisible(HiddenWindow);
+                    }
+                }
+            }
+        }
+        hwnd = NextWindow(hwnd);
+    }
+    /* --------- repaint all children of this window
+        the same way ----------- */
+    hwnd = FirstWindow(wnd);
+    while (hwnd != NULL)    {
+        PaintUnderLappers(hwnd);
+        hwnd = NextWindow(hwnd);
+    }
+}
+#endif /* #ifdef INCLUDE_MULTI_WINDOWS */
+
+/* --- save video area to be used by dummy window border --- */
+static void SaveBorder(DFRECT rc)
+{
+       Bht = RectBottom(rc) - RectTop(rc) + 1;
+       Bwd = RectRight(rc) - RectLeft(rc) + 1;
+       Bsave = DFrealloc(Bsave, Bht * Bwd * sizeof(CHAR_INFO));
+
+       GetVideo(rc,Bsave);
+}
+/* ---- restore video area used by dummy window border ---- */
+static void RestoreBorder(DFRECT rc)
+{
+       if (Bsave != NULL)
+       {
+               StoreVideo(rc, Bsave);
+               free(Bsave);
+               Bsave = NULL;
+       }
+}
+/* ----- test if screen coordinates are in a window ---- */
+static BOOL InsideWindow(DFWINDOW wnd, int x, int y)
+{
+    DFRECT rc;
+    rc = WindowRect(wnd);
+    if (!TestAttribute(wnd, NOCLIP))
+    {
+        DFWINDOW pwnd = GetParent(wnd);
+        while (pwnd != NULL)
+               {
+            rc = subRectangle(rc, ClientRect(pwnd));
+            pwnd = GetParent(pwnd);
+        }
+    }
+    return InsideRect(x, y, rc);
+}
+
+BOOL isDerivedFrom(DFWINDOW wnd, DFCLASS class)
+{
+    DFCLASS tclass = GetClass(wnd);
+    while (tclass != -1)    {
+        if (tclass == class)
+            return TRUE;
+        tclass = (classdefs[tclass].base);
+    }
+    return FALSE;
+}
+
+/* -- find the oldest document window ancestor of a window -- */
+DFWINDOW GetAncestor(DFWINDOW wnd)
+{
+    if (wnd != NULL)    {
+        while (GetParent(wnd) != NULL)    {
+            if (GetClass(GetParent(wnd)) == APPLICATION)
+                break;
+            wnd = GetParent(wnd);
+        }
+    }
+    return wnd;
+}
+
+BOOL isVisible(DFWINDOW wnd)
+{
+    while (wnd != NULL)    {
+        if (isHidden(wnd))
+            return FALSE;
+        wnd = GetParent(wnd);
+    }
+    return TRUE;
+}
+
+/* -- adjust a window's rectangle to clip it to its parent - */
+static DFRECT ClipRect(DFWINDOW wnd)
+{
+    DFRECT rc;
+    rc = WindowRect(wnd);
+    if (TestAttribute(wnd, SHADOW))    {
+        RectBottom(rc)++;
+        RectRight(rc)++;
+    }
+       return ClipRectangle(wnd, rc);
+}
+
+/* -- get the video memory that is to be used by a window -- */
+static void GetVideoBuffer(DFWINDOW wnd)
+{
+    DFRECT rc;
+    int ht;
+    int wd;
+
+    rc = ClipRect(wnd);
+    ht = RectBottom(rc) - RectTop(rc) + 1;
+    wd = RectRight(rc) - RectLeft(rc) + 1;
+    wnd->videosave = DFrealloc(wnd->videosave, (ht * wd * sizeof(CHAR_INFO)));
+    GetVideo(rc, wnd->videosave);
+}
+
+/* -- put the video memory that is used by a window -- */
+static void PutVideoBuffer(DFWINDOW wnd)
+{
+       if (wnd->videosave != NULL)
+       {
+               DFRECT rc;
+               rc = ClipRect(wnd);
+               StoreVideo(rc, wnd->videosave);
+               free(wnd->videosave);
+               wnd->videosave = NULL;
+       }
+}
+
+/* ------- return TRUE if awnd is an ancestor of wnd ------- */
+BOOL isAncestor(DFWINDOW wnd, DFWINDOW awnd)
+{
+       while (wnd != NULL)     {
+               if (wnd == awnd)
+                       return TRUE;
+               wnd = GetParent(wnd);
+       }
+       return FALSE;
+}
+
+/* EOF */
diff --git a/rosapps/lib/dflat32/pictbox.c b/rosapps/lib/dflat32/pictbox.c
new file mode 100644 (file)
index 0000000..e22842d
--- /dev/null
@@ -0,0 +1,284 @@
+/* -------------- pictbox.c -------------- */
+
+#include "dflat32/dflat.h"
+
+typedef struct    {
+    enum VectTypes vt;
+    DFRECT 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(DFWINDOW wnd, DFRECT rc, int x, int y)
+{
+    DFRECT 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(DFWINDOW wnd, DFRECT 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(DFWINDOW wnd, DFRECT 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(DFWINDOW 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(DFWINDOW 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 = *(DFRECT *)p1;
+        *(((VECT *)(wnd->VectorList))+wnd->VectorCount)=vc;
+        wnd->VectorCount++;
+    }
+}
+
+static void DrawBoxMsg(DFWINDOW wnd, PARAM p1)
+{
+    if (p1)    {
+        DFRECT rc = *(DFRECT *)p1;
+        rc.bt = rc.tp;
+        DfSendMessage(wnd, DRAWVECTOR, (PARAM) &rc, TRUE);
+        rc = *(DFRECT *)p1;
+        rc.lf = rc.rt;
+        DfSendMessage(wnd, DRAWVECTOR, (PARAM) &rc, FALSE);
+        rc = *(DFRECT *)p1;
+        rc.tp = rc.bt;
+        DfSendMessage(wnd, DRAWVECTOR, (PARAM) &rc, TRUE);
+        rc = *(DFRECT *)p1;
+        rc.rt = rc.lf;
+        DfSendMessage(wnd, DRAWVECTOR, (PARAM) &rc, FALSE);
+    }
+}
+
+int PictureProc(DFWINDOW wnd, DFMESSAGE 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 DFRECT PictureRect(int x, int y, int len, int hv)
+{
+    DFRECT 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(DFWINDOW wnd, int x, int y, int len, int hv)
+{
+    DFRECT rc = PictureRect(x,y,len,hv);
+    DfSendMessage(wnd, DRAWVECTOR, (PARAM) &rc, 0);
+}
+
+void DrawBox(DFWINDOW wnd, int x, int y, int ht, int wd)
+{
+    DFRECT rc;
+    rc.lf = x;
+    rc.tp = y;
+    rc.rt = x+wd-1;
+    rc.bt = y+ht-1;
+    DfSendMessage(wnd, DRAWBOX, (PARAM) &rc, 0);
+}
+
+void DrawBar(DFWINDOW wnd,enum VectTypes vt,
+                        int x,int y,int len,int hv)
+{
+    DFRECT rc = PictureRect(x,y,len,hv);
+    DfSendMessage(wnd, DRAWBAR, (PARAM) &rc, (PARAM) vt);
+}
+
+/* EOF */
diff --git a/rosapps/lib/dflat32/popdown.c b/rosapps/lib/dflat32/popdown.c
new file mode 100644 (file)
index 0000000..2ea8b22
--- /dev/null
@@ -0,0 +1,396 @@
+/* ------------- popdown.c ----------- */
+
+#include "dflat32/dflat.h"
+
+static int SelectionWidth(struct PopDown *);
+static int py = -1;
+
+/* ------------ CREATE_WINDOW Message ------------- */
+static int CreateWindowMsg(DFWINDOW wnd)
+{
+       int rtn, adj;
+
+       ClearAttribute (wnd,
+                       HASTITLEBAR |
+                       VSCROLLBAR  |
+                       MOVEABLE    |
+                       SIZEABLE    |
+                       HSCROLLBAR);
+
+       /* ------ adjust to keep popdown on screen ----- */
+       adj = DfGetScreenHeight()-1-wnd->rc.bt;
+       if (adj < 0)
+       {
+               wnd->rc.tp += adj;
+               wnd->rc.bt += adj;
+       }
+       adj = DfGetScreenWidth()-1-wnd->rc.rt;
+       if (adj < 0)
+       {
+               wnd->rc.lf += adj;
+               wnd->rc.rt += adj;
+       }
+
+       rtn = BaseWndProc(POPDOWNMENU, wnd, CREATE_WINDOW, 0, 0);
+       DfSendMessage(wnd, CAPTURE_MOUSE, 0, 0);
+       DfSendMessage(wnd, CAPTURE_KEYBOARD, 0, 0);
+       DfSendMessage(NULL, SAVE_CURSOR, 0, 0);
+       DfSendMessage(NULL, HIDE_CURSOR, 0, 0);
+       wnd->oldFocus = inFocus;
+       inFocus = wnd;
+
+       return rtn;
+}
+
+/* --------- LEFT_BUTTON Message --------- */
+static void LeftButtonMsg(DFWINDOW wnd, PARAM p1, PARAM p2)
+{
+    int my = (int) p2 - GetTop(wnd);
+    if (InsideRect(p1, p2, ClientRect(wnd)))    {
+        if (my != py)    {
+            DfSendMessage(wnd, LB_SELECTION,
+                    (PARAM) wnd->wtop+my-1, TRUE);
+            py = my;
+        }
+    }
+    else if ((int)p2 == GetTop(GetParent(wnd)))
+        if (GetClass(GetParent(wnd)) == MENUBAR)
+            DfPostMessage(GetParent(wnd), LEFT_BUTTON, p1, p2);
+}
+
+/* -------- BUTTON_RELEASED Message -------- */
+static BOOL ButtonReleasedMsg(DFWINDOW 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)
+            DfSendMessage(wnd, LB_CHOOSE, wnd->selection, 0);
+    }
+    else    {
+        DFWINDOW pwnd = GetParent(wnd);
+        if (GetClass(pwnd) == MENUBAR && (int)p2==GetTop(pwnd))
+            return FALSE;
+        if ((int)p1 == GetLeft(pwnd)+2)
+            return FALSE;
+        DfSendMessage(wnd, CLOSE_WINDOW, 0, 0);
+        return TRUE;
+    }
+    return FALSE;
+}
+
+/* --------- PAINT Message -------- */
+static void PaintMsg(DFWINDOW wnd)
+{
+    int wd;
+    unsigned char sep[80], *cp = sep;
+    unsigned char sel[80];
+    struct PopDown *ActivePopDown;
+    struct PopDown *pd1;
+
+    ActivePopDown = pd1 = wnd->mnu->Selections;
+    wd = MenuWidth(ActivePopDown)-2;
+    while (wd--)
+        *cp++ = LINE;
+    *cp = '\0';
+    DfSendMessage(wnd, CLEARTEXT, 0, 0);
+    wnd->selection = wnd->mnu->Selection;
+    while (pd1->SelectionTitle != NULL)    {
+        if (*pd1->SelectionTitle == LINE)
+            DfSendMessage(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;
+                int wd1 = 2+SelectionWidth(ActivePopDown) -
+                                    strlen(pd1->SelectionTitle);
+                for (i = 0; keys[i].keylabel; i++)    {
+                    if (keys[i].keycode == pd1->Accelerator)   {
+                        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;
+            DfSendMessage(wnd, ADDTEXT, (PARAM) sel, 0);
+        }
+        pd1++;
+    }
+}
+
+/* ---------- BORDER Message ----------- */
+static int BorderMsg(DFWINDOW wnd)
+{
+    int i, rtn = TRUE;
+    DFWINDOW 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(DFWINDOW 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))    {
+            if (*attr & TOGGLE)
+                *attr ^= CHECKED;
+            DfPostMessage(GetParent(wnd), DFM_COMMAND,
+                (ActivePopDown+(int)p1)->ActionId, p1);
+        }
+        else
+            beep();
+    }
+}
+
+/* ---------- KEYBOARD Message --------- */
+static BOOL KeyboardMsg(DFWINDOW 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 & OFFSET) == 0)
+                               c = tolower(c);
+                       a = AltConvert(c);
+
+                       while (pd->SelectionTitle != NULL)
+                       {
+                               char *cp = strchr(pd->SelectionTitle, SHORTCUTCHAR);
+
+/* FIXME: AltConvert bug !! */
+                               if ((cp && tolower(*(cp+1)) == c) ||
+//                                     (a && tolower(*(cp+1)) == a) ||
+                                       pd->Accelerator == c)
+                               {
+                                       DfPostMessage(wnd, LB_SELECTION, sel, 0);
+                                       DfPostMessage(wnd, LB_CHOOSE, sel, TRUE);
+                                       return TRUE;
+                               }
+                               pd++;
+                               sel++;
+                       }
+               }
+       }
+
+       switch ((int)p1)
+       {
+        case F1:
+            if (ActivePopDown == NULL)
+                DfSendMessage(GetParent(wnd), KEYBOARD, p1, p2);
+            else 
+                DisplayHelp(wnd,
+                    (ActivePopDown+wnd->selection)->help);
+            return TRUE;
+        case ESC:
+            DfSendMessage(wnd, CLOSE_WINDOW, 0, 0);
+            return TRUE;
+        case FWD:
+        case BS:
+            if (GetClass(GetParent(wnd)) == MENUBAR)
+                DfPostMessage(GetParent(wnd), KEYBOARD, p1, p2);
+            return TRUE;
+        case UP:
+            if (wnd->selection == 0)    {
+                if (wnd->wlines == ClientHeight(wnd))    {
+                    DfPostMessage(wnd, LB_SELECTION,
+                                    wnd->wlines-1, FALSE);
+                    return TRUE;
+                }
+            }
+            break;
+        case DN:
+            if (wnd->selection == wnd->wlines-1)    {
+                if (wnd->wlines == ClientHeight(wnd))    {
+                    DfPostMessage(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(DFWINDOW wnd)
+{
+    int rtn;
+       DFWINDOW pwnd = GetParent(wnd);
+    DfSendMessage(wnd, RELEASE_MOUSE, 0, 0);
+    DfSendMessage(wnd, RELEASE_KEYBOARD, 0, 0);
+    DfSendMessage(NULL, RESTORE_CURSOR, 0, 0);
+       inFocus = wnd->oldFocus;
+    rtn = BaseWndProc(POPDOWNMENU, wnd, CLOSE_WINDOW, 0, 0);
+    DfSendMessage(pwnd, CLOSE_POPDOWN, 0, 0);
+    return rtn;
+}
+
+/* - Window processing module for POPDOWNMENU window class - */
+int PopDownProc(DFWINDOW wnd, DFMESSAGE 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:
+            if (*TextLine(wnd, (int)p1) == LINE)
+                return TRUE;
+            wnd->mnu->Selection = (int)p1;
+            break;
+        case DFM_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, (int)(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);
+}
+
+/* EOF */
diff --git a/rosapps/lib/dflat32/radio.c b/rosapps/lib/dflat32/radio.c
new file mode 100644 (file)
index 0000000..0b02528
--- /dev/null
@@ -0,0 +1,116 @@
+/* -------- radio.c -------- */
+
+#include "dflat32/dflat.h"
+
+static CTLWINDOW *rct[MAXRADIOS];
+
+int RadioButtonProc(DFWINDOW wnd, DFMESSAGE 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)
+                    DfSendMessage(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;
+                DfSendMessage(wnd, CLEARTEXT, 0, 0);
+                DfSendMessage(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)
+                DfSendMessage(rct[i]->wnd, PAINT, 0, 0);
+        }
+    }
+       /* ----- set the specified radio button on ----- */
+    ct->setting = ON;
+       if (Setting)
+           ct->isetting = ON;
+    DfSendMessage(ct->wnd, PAINT, 0, 0);
+}
+
+BOOL RadioButtonSetting(DBOX *db, enum commands cmd)
+{
+    CTLWINDOW *ct = FindCommand(db, cmd, RADIOBUTTON);
+    if (ct != NULL)
+        return (ct->setting == ON);
+    return FALSE;
+}
+
+/* EOF */
index b7b5692..70a52df 100644 (file)
@@ -1,6 +1,6 @@
 /* ------------- rect.c --------------- */
 
 /* ------------- rect.c --------------- */
 
-#include <dflat32/dflat.h>
+#include "dflat32/dflat.h"
 
  /* --- Produce the vector end points produced by the overlap
         of two other vectors --- */
 
  /* --- Produce the vector end points produced by the overlap
         of two other vectors --- */
diff --git a/rosapps/lib/dflat32/spinbutt.c b/rosapps/lib/dflat32/spinbutt.c
new file mode 100644 (file)
index 0000000..62a2d20
--- /dev/null
@@ -0,0 +1,48 @@
+/* ------------ spinbutt.c ------------- */
+
+#include "dflat32/dflat.h"
+
+int SpinButtonProc(DFWINDOW wnd, DFMESSAGE 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)
+                    DfSendMessage(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)
+                    DfSendMessage(wnd, KEYBOARD, UP, 0);
+                else if (p1 == GetRight(wnd) + 2)
+                    DfSendMessage(wnd, KEYBOARD, DN, 0);
+                if (wnd != inFocus)
+                    DfSendMessage(wnd, SETFOCUS, TRUE, 0);
+                return TRUE;
+            case LB_SETSELECTION:
+                rtn = BaseWndProc(SPINBUTTON, wnd, msg, p1, p2);
+                wnd->wtop = (int) p1;
+                DfSendMessage(wnd, PAINT, 0, 0);
+                return rtn;
+            default:
+                break;
+        }
+    }
+    return BaseWndProc(SPINBUTTON, wnd, msg, p1, p2);
+}
+
+/* EOF */
diff --git a/rosapps/lib/dflat32/statbar.c b/rosapps/lib/dflat32/statbar.c
new file mode 100644 (file)
index 0000000..1616ca6
--- /dev/null
@@ -0,0 +1,53 @@
+/* ---------------- statbar.c -------------- */
+
+#include "dflat32/dflat.h"
+
+int StatusBarProc(DFWINDOW wnd, DFMESSAGE msg, PARAM p1, PARAM p2)
+{
+       char *statusbar;
+       switch (msg)    {
+               case CREATE_WINDOW:
+               case MOVE:
+                       DfSendMessage(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 Ý FreeDos Edit", 22);
+                       if (wnd->text)  {
+                               int len = min((int)strlen(wnd->text), (int)(WindowWidth(wnd)-17));
+                               if (len > 0)    {
+                                       int off=(WindowWidth(wnd)-len)/2;
+                                       strncpy(statusbar+off, wnd->text, len);
+                               }
+                       }
+                       if (wnd->TimePosted)
+                               *(statusbar+WindowWidth(wnd)-8) = '\0';
+                       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;
+                       return TRUE;
+               case CLOSE_WINDOW:
+                       DfSendMessage(NULL, RELEASE_CLOCK, 0, 0);
+                       break;
+               default:
+                       break;
+       }
+       return BaseWndProc(STATUSBAR, wnd, msg, p1, p2);
+}
+
+/* EOF */
index ffa7d27..5e5143d 100644 (file)
@@ -1,48 +1,28 @@
-#include <dflat32/dflat.h>
+#include "dflat32/dflat.h"
 
 
-DFWINDOW ApplicationWindow; //applicat.c
-
-void ClearDialogBoxes(void) // no clue
+int TestCriticalError(void)
 {
 }
 
 
 {
 }
 
 
-// from normal.c
+/* These are functions that are supposed to be part of the application
+ * not part of the dflat32.dll
+ *
+ * - Fixme 
+ */
 
 
-/* -------- array of class definitions -------- */
-CLASSDEFS classdefs[] = {
-    #undef ClassDef
-    #define ClassDef(c,b,p,a) {b,p,a},
-//    #include <dflat32/classes.h>
-};
+char DFlatApplication[] = "none";   //edit.c
 
 
-BOOL isAncestor(DFWINDOW wnd, DFWINDOW awnd)
+void PrepFileMenu(void *w, struct Menu *mnu) //edit.c
 {
 {
-       while (wnd != NULL)     {
-               if (wnd == awnd)
-                       return TRUE;
-               wnd = GetParent(wnd);
-       }
-       return FALSE;
 }
 
 }
 
-BOOL isVisible(DFWINDOW wnd)
+void PrepSearchMenu(void *w, struct Menu *mnu) //edit.c
 {
 {
-    while (wnd != NULL)    {
-        if (isHidden(wnd))
-            return FALSE;
-        wnd = GetParent(wnd);
-    }
-    return TRUE;
 }
 
 }
 
-
-void BuildTextPointers(DFWINDOW wnd)
+void PrepEditMenu(void *w, struct Menu *mnu) //edit.c
 {
 }
 
 {
 }
 
-
-// log.c
-void LogMessages (DFWINDOW wnd, DFMESSAGE msg, PARAM p1, PARAM p2)
-{
-}
\ No newline at end of file
+char **Argv; //edit.c
\ No newline at end of file
diff --git a/rosapps/lib/dflat32/sysmenu.c b/rosapps/lib/dflat32/sysmenu.c
new file mode 100644 (file)
index 0000000..d41aaee
--- /dev/null
@@ -0,0 +1,108 @@
+/* ------------- sysmenu.c ------------ */
+
+#include "dflat32/dflat.h"
+
+int SystemMenuProc(DFWINDOW wnd, DFMESSAGE msg, PARAM p1, PARAM p2)
+{
+    int mx, my;
+    DFWINDOW 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:
+            DfPostMessage(wnd, CLOSE_WINDOW, 0, 0);
+            break;
+        case DOUBLE_CLICK:
+            if (p2 == GetTop(GetParent(wnd)))    {
+                DfPostMessage(GetParent(wnd), msg, p1, p2);
+                DfSendMessage(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(DFWINDOW wnd)
+{
+       int lf, tp, ht, wd;
+    DFWINDOW 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 > DfGetScreenWidth()-1)
+        lf = (DfGetScreenWidth()-1) - wd;
+    if (tp+ht > DfGetScreenHeight()-2)
+        tp = (DfGetScreenHeight()-2) - ht;
+
+    SystemMenuWnd = DfCreateWindow(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
+
+    DfSendMessage(SystemMenuWnd, BUILD_SELECTIONS,
+                (PARAM) &SystemMenu.PullDown[0], 0);
+    DfSendMessage(SystemMenuWnd, SETFOCUS, TRUE, 0);
+    DfSendMessage(SystemMenuWnd, SHOW_WINDOW, 0, 0);
+}
+
+/* EOF */
diff --git a/rosapps/lib/dflat32/text.c b/rosapps/lib/dflat32/text.c
new file mode 100644 (file)
index 0000000..e1ff2ca
--- /dev/null
@@ -0,0 +1,65 @@
+/* -------------- text.c -------------- */
+
+#include "dflat32/dflat.h"
+
+int TextProc(DFWINDOW wnd, DFMESSAGE msg, PARAM p1, PARAM p2)
+{
+       int i, len;
+       CTLWINDOW *ct = GetControl(wnd);
+       char *cp, *cp2 = ct->itext;
+       char *ptr;
+
+       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));
+
+                       ptr = DFmalloc (strlen (cp2) + 1);
+                       strcpy (ptr, cp2);
+                       cp = ptr;
+                       for (i = 0; i < len; i++)
+                       {
+                               int mlen;
+                               char *txt = cp;
+                               char *cp1 = cp;
+                               char *np = strchr(cp, '\n');
+                               if (np != NULL)
+                                       *np = '\0';
+                               mlen = strlen(cp);
+                               while ((cp1=strchr(cp1,SHORTCUTCHAR)) != NULL)
+                               {
+                                       mlen += 3;
+                                       cp1++;
+                               }
+
+                               if (np != NULL)
+                                       *np = '\n';
+                               txt = DFmalloc(mlen+1);
+                               CopyCommand(txt, cp, FALSE, WndBackground(wnd));
+                               txt[mlen] = '\0';
+                               DfSendMessage(wnd, ADDTEXT, (PARAM)txt, 0);
+                               if ((cp = strchr(cp, '\n')) != NULL)
+                                       cp++;
+                               free(txt);
+                       }
+                       free (ptr);
+                       break;
+
+               default:
+                       break;
+       }
+
+       return BaseWndProc(TEXT, wnd, msg, p1, p2);
+}
+
+/* EOF */
index d090469..0c89b2a 100644 (file)
@@ -1,6 +1,6 @@
 /* --------------------- video.c -------------------- */
 
 /* --------------------- video.c -------------------- */
 
-#include <dflat32/dflat.h>
+#include "dflat32/dflat.h"
 
 #define clr(fg,bg) ((fg)|((bg)<<4))
 
 
 #define clr(fg,bg) ((fg)|((bg)<<4))
 
diff --git a/rosapps/lib/dflat32/watch.c b/rosapps/lib/dflat32/watch.c
new file mode 100644 (file)
index 0000000..e7f9816
--- /dev/null
@@ -0,0 +1,58 @@
+/* ----------- watch.c ----------- */
+
+#include "dflat32/dflat.h"
+
+int WatchIconProc(DFWINDOW wnd, DFMESSAGE msg, PARAM p1, PARAM p2)
+{
+    int rtn;
+    switch (msg)    {
+        case CREATE_WINDOW:
+            rtn = DefaultWndProc(wnd, msg, p1, p2);
+            DfSendMessage(wnd, CAPTURE_MOUSE, 0, 0);
+            DfSendMessage(wnd, CAPTURE_KEYBOARD, 0, 0);
+            return rtn;
+        case PAINT:
+            SetStandardColor(wnd);
+            writeline(wnd, " R ", 1, 1, FALSE);
+            return TRUE;
+        case BORDER:
+            rtn = DefaultWndProc(wnd, msg, p1, p2);
+            writeline(wnd, "Í", 2, 0, FALSE);
+            return rtn;
+        case MOUSE_MOVED:
+            DfSendMessage(wnd, DFM_HIDE_WINDOW, 0, 0);
+            DfSendMessage(wnd, MOVE, p1, p2);
+            DfSendMessage(wnd, SHOW_WINDOW, 0, 0);
+            return TRUE;
+        case CLOSE_WINDOW:
+            DfSendMessage(wnd, RELEASE_MOUSE, 0, 0);
+            DfSendMessage(wnd, RELEASE_KEYBOARD, 0, 0);
+            break;
+        default:
+            break;
+    }
+    return DefaultWndProc(wnd, msg, p1, p2);
+}
+
+DFWINDOW WatchIcon(void)
+{
+    int mx, my;
+    DFWINDOW wnd;
+
+/* this won't work !! */
+//    DfSendMessage(NULL, DFM_CURRENT_MOUSE_CURSOR,
+//                        (PARAM) &mx, (PARAM) &my);
+
+    mx = 0;//SCREENWIDTH / 2;
+    mx = 0;//SCREENHEIGHT / 2;
+    wnd = DfCreateWindow(
+                    BOX,
+                    NULL,
+                    mx, my, 3, 5,
+                    NULL,NULL,
+                    WatchIconProc,
+                    VISIBLE | HASBORDER | SHADOW | SAVESELF);
+    return wnd;
+}
+
+/* EOF */
index 4b75b56..7c0fd35 100644 (file)
@@ -1,6 +1,6 @@
 /* ---------- window.c ------------- */
 
 /* ---------- window.c ------------- */
 
-#include <dflat32/dflat.h>
+#include "dflat32/dflat.h"
 
 DFWINDOW inFocus = NULL;
 
 
 DFWINDOW inFocus = NULL;