| 1 | // |
|---|
| 2 | // TxWin, Textmode Windowing Library |
|---|
| 3 | // |
|---|
| 4 | // Original code Copyright (c) 1995-2005 Fsys Software and Jan van Wijk |
|---|
| 5 | // |
|---|
| 6 | // ========================================================================== |
|---|
| 7 | // |
|---|
| 8 | // This file contains Original Code and/or Modifications of Original Code as |
|---|
| 9 | // defined in and that are subject to the GNU Lesser General Public License. |
|---|
| 10 | // You may not use this file except in compliance with the License. |
|---|
| 11 | // BY USING THIS FILE YOU AGREE TO ALL TERMS AND CONDITIONS OF THE LICENSE. |
|---|
| 12 | // A copy of the License is provided with the Original Code and Modifications, |
|---|
| 13 | // and is also available at http://www.dfsee.com/txwin/lgpl.htm |
|---|
| 14 | // |
|---|
| 15 | // This library is free software; you can redistribute it and/or modify |
|---|
| 16 | // it under the terms of the GNU Lesser General Public License as published |
|---|
| 17 | // by the Free Software Foundation; either version 2.1 of the License, |
|---|
| 18 | // or (at your option) any later version. |
|---|
| 19 | // |
|---|
| 20 | // This library is distributed in the hope that it will be useful, |
|---|
| 21 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 22 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|---|
| 23 | // See the GNU Lesser General Public License for more details. |
|---|
| 24 | // |
|---|
| 25 | // You should have received a copy of the GNU Lesser General Public License |
|---|
| 26 | // along with this library; (lgpl.htm) if not, write to the Free Software |
|---|
| 27 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 28 | // |
|---|
| 29 | // Questions on TxWin licensing can be directed to: txwin@fsys.nl |
|---|
| 30 | // |
|---|
| 31 | // ========================================================================== |
|---|
| 32 | // |
|---|
| 33 | // TX library anchor and init/terminate functions |
|---|
| 34 | // file-logging facilities |
|---|
| 35 | // |
|---|
| 36 | // Author: J. van Wijk |
|---|
| 37 | // |
|---|
| 38 | // JvW 24-07-2005 Initial version, split off from TXCON.C |
|---|
| 39 | |
|---|
| 40 | #include <txlib.h> |
|---|
| 41 | #include <txwpriv.h> // private window interface |
|---|
| 42 | |
|---|
| 43 | // Needs to be in a non-windowing component for the OEM versions |
|---|
| 44 | TXW_ANCHOR txwanchor = |
|---|
| 45 | { |
|---|
| 46 | #if defined (DEV32) |
|---|
| 47 | PT_WINDOWABLEVIO, // sessiontype default (VIO/FS) |
|---|
| 48 | FALSE, // KBD reader thread kill |
|---|
| 49 | #elif defined (DOS32) |
|---|
| 50 | NULL, // DPMI parameter ptr, 512 |
|---|
| 51 | NULL, // DPMI parameter ptr, 512 |
|---|
| 52 | 0, |
|---|
| 53 | 0, |
|---|
| 54 | #endif |
|---|
| 55 | FALSE, // global insert-mode |
|---|
| 56 | TRUE, // typeahead enabled |
|---|
| 57 | TXW_ARROW_STD, // stdandard arrow handling |
|---|
| 58 | 0, // first auto assigned id |
|---|
| 59 | 0, // std radix bits, all decimal |
|---|
| 60 | 0, 0, // saved cursor position |
|---|
| 61 | {0,0,79,24}, // default 80x25 screen |
|---|
| 62 | 0, // no automenu header ID |
|---|
| 63 | 0, 0, 0, // start pos and flags for drag |
|---|
| 64 | TRUE, // mouse enabled |
|---|
| 65 | TXHWND_NULL, // no mouse capture |
|---|
| 66 | TXHWND_DESKTOP, // default modality |
|---|
| 67 | NULL, // focus window |
|---|
| 68 | NULL, // first window in chain |
|---|
| 69 | NULL, // last window in chain |
|---|
| 70 | 0, // actual window count |
|---|
| 71 | NULL, // SBview for quick status |
|---|
| 72 | TXHWND_NULL, // Entryfield marked as cmdline |
|---|
| 73 | TXHWND_NULL, // Canvas marked as main menu |
|---|
| 74 | TRUE, // show default status |
|---|
| 75 | 75, // resize dialog, rsmaxlines |
|---|
| 76 | 437, // codepage, std 437 compatible |
|---|
| 77 | NULL, // system accelerator table |
|---|
| 78 | "" // list match string value |
|---|
| 79 | }; |
|---|
| 80 | |
|---|
| 81 | TXW_ANCHOR *txwa = &txwanchor; // private anchor (HAB) |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | /*****************************************************************************/ |
|---|
| 85 | // Initialize TX-libary, after parsing EXE parameters and switches |
|---|
| 86 | /*****************************************************************************/ |
|---|
| 87 | void TxLibraryInit |
|---|
| 88 | ( |
|---|
| 89 | BOOL screenOff // IN start with screen off |
|---|
| 90 | ) |
|---|
| 91 | { |
|---|
| 92 | #if defined (DEV32) |
|---|
| 93 | TIB *tib; |
|---|
| 94 | PIB *pib; |
|---|
| 95 | #endif |
|---|
| 96 | |
|---|
| 97 | ENTER(); |
|---|
| 98 | |
|---|
| 99 | #if defined (DEV32) |
|---|
| 100 | if (DosGetInfoBlocks( &tib, &pib) == NO_ERROR) |
|---|
| 101 | { |
|---|
| 102 | txwa->session = pib->pib_ultype; |
|---|
| 103 | } |
|---|
| 104 | #endif |
|---|
| 105 | |
|---|
| 106 | if (screenOff) |
|---|
| 107 | { |
|---|
| 108 | TxScreenState(DEVICE_OFF); |
|---|
| 109 | TxSetAnsiMode( A_OFF); |
|---|
| 110 | } |
|---|
| 111 | TxFsSetCritErrHandler( TRUE); |
|---|
| 112 | if (TxaExeSwitchUnSet( TXA_O_MOUSE)) // don't use the mouse |
|---|
| 113 | { |
|---|
| 114 | txwa->useMouse = FALSE; |
|---|
| 115 | } |
|---|
| 116 | #if defined (DOS32) |
|---|
| 117 | if (TxaExeSwitchSet( TXA_O_KEYB)) // keyb switch |
|---|
| 118 | { |
|---|
| 119 | TxSetNlsKeyboard( TxaExeSwitchStr( TXA_O_KEYB, "", "us"), ""); |
|---|
| 120 | } |
|---|
| 121 | txwa->dpmi1 = txDpmiAlloc( 1, 512, &(txwa->dpmi1Selector)); |
|---|
| 122 | txwa->dpmi2 = txDpmiAlloc( 1, 512, &(txwa->dpmi2Selector)); |
|---|
| 123 | #endif |
|---|
| 124 | TxPrintInit( TxaExeSwitch('a'), TxaExeSwitch('7')); |
|---|
| 125 | #if defined (USEWINDOWING) |
|---|
| 126 | TxInputInitialize(); // Init windowed KBD/MOU input |
|---|
| 127 | #endif |
|---|
| 128 | VRETURN (); |
|---|
| 129 | } // end 'TxLibraryInit' |
|---|
| 130 | /*---------------------------------------------------------------------------*/ |
|---|
| 131 | |
|---|
| 132 | |
|---|
| 133 | /*****************************************************************************/ |
|---|
| 134 | // Terminate TX-libary, after parsing EXE parameters and switches |
|---|
| 135 | /*****************************************************************************/ |
|---|
| 136 | void TxLibraryExit |
|---|
| 137 | ( |
|---|
| 138 | void |
|---|
| 139 | ) |
|---|
| 140 | { |
|---|
| 141 | TxAppendToLogFile("", TRUE); |
|---|
| 142 | #if defined (USEWINDOWING) |
|---|
| 143 | TxInputTerminate(); // stop windowed KBD/MOU input |
|---|
| 144 | #endif |
|---|
| 145 | TxPrintTerminate(); // stop printf redirection |
|---|
| 146 | TxFsSetCritErrHandler( FALSE); |
|---|
| 147 | TxScreenTerminate(); |
|---|
| 148 | |
|---|
| 149 | #if defined (DOS32) |
|---|
| 150 | txDpmiFree( txwa->dpmi1Selector); |
|---|
| 151 | txDpmiFree( txwa->dpmi2Selector); |
|---|
| 152 | #endif |
|---|
| 153 | } // end 'TxLibraryExit' |
|---|
| 154 | /*---------------------------------------------------------------------------*/ |
|---|
| 155 | |
|---|
| 156 | |
|---|
| 157 | /*****************************************************************************/ |
|---|
| 158 | // Terminate TxPrint environment |
|---|
| 159 | /*****************************************************************************/ |
|---|
| 160 | void TxPrintTerminate |
|---|
| 161 | ( |
|---|
| 162 | void |
|---|
| 163 | ) |
|---|
| 164 | { |
|---|
| 165 | //- nothing to do yet ... |
|---|
| 166 | } // end 'TxPrintTerminate' |
|---|
| 167 | /*---------------------------------------------------------------------------*/ |
|---|
| 168 | |
|---|
| 169 | |
|---|
| 170 | /*****************************************************************************/ |
|---|
| 171 | // Initialise Ansi environment |
|---|
| 172 | /*****************************************************************************/ |
|---|
| 173 | void TxPrintInit |
|---|
| 174 | ( |
|---|
| 175 | BOOL ansiOff, // IN don't use ANSI colors |
|---|
| 176 | BOOL ascii7 // IN Convert to 7-bit ASCII |
|---|
| 177 | ) |
|---|
| 178 | { |
|---|
| 179 | #if defined (DOS32) |
|---|
| 180 | static BOOL force_ansi_probe = FALSE; |
|---|
| 181 | #endif |
|---|
| 182 | |
|---|
| 183 | if (ansiOff) |
|---|
| 184 | { |
|---|
| 185 | TxSetAnsiMode( A_OFF); // so do not use it |
|---|
| 186 | } |
|---|
| 187 | else |
|---|
| 188 | { |
|---|
| 189 | TxSetAnsiMode( A_ON); // Allow ANSI to start with |
|---|
| 190 | |
|---|
| 191 | #if defined (DOS32) // but conditionally for DOS |
|---|
| 192 | if ((TxaExeSwitchUnSet('w')) || // when non-windowed to avoid |
|---|
| 193 | (force_ansi_probe)) // on-screen garbage strings |
|---|
| 194 | { // if ANSI.SYS not loaded |
|---|
| 195 | short col = TxCursorCol(); |
|---|
| 196 | |
|---|
| 197 | printf("%s", CNN); // Reset color attribute |
|---|
| 198 | fflush( stdout); // make sure it is done! |
|---|
| 199 | if (col != TxCursorCol()) // cursor has moved! |
|---|
| 200 | { // ANSI not working |
|---|
| 201 | TxSetAnsiMode( A_OFF); // so do not use it |
|---|
| 202 | printf( " "); // try to undo the probe |
|---|
| 203 | } |
|---|
| 204 | } |
|---|
| 205 | else |
|---|
| 206 | { |
|---|
| 207 | force_ansi_probe = TRUE; // always probe after first |
|---|
| 208 | } // time (non EXE startup) |
|---|
| 209 | #endif |
|---|
| 210 | } |
|---|
| 211 | TRACES(( "ASCII7 set 2: %s\n", (ascii7) ? "TRUE" : "FALSE")); |
|---|
| 212 | TxSetAscii7Mode( ascii7); |
|---|
| 213 | |
|---|
| 214 | TxClaimKeyboard(); |
|---|
| 215 | |
|---|
| 216 | TxSetBrightBgMode( TRUE); // no blinking, use bright BG |
|---|
| 217 | } // end 'TxPrintInit' |
|---|
| 218 | /*---------------------------------------------------------------------------*/ |
|---|