| 1 | #define SAM_D "Popup and scrollbuffer sample for JvW-Fsys TXW OpenWatcom build environment." |
|---|
| 2 | |
|---|
| 3 | #define SAM_C "(c) 2005: Jan van Wijk" |
|---|
| 4 | |
|---|
| 5 | #define SAM_V "1.01 23-09-2005" // Added scroll-buffer for better trace demo |
|---|
| 6 | //efine SAM_V "1.00 21-09-2005" // Initial version |
|---|
| 7 | |
|---|
| 8 | #include <txlib.h> // TX library interface |
|---|
| 9 | #if defined (WIN32) |
|---|
| 10 | #define SAM_N "SAM4 winNT" |
|---|
| 11 | #elif defined (DOS32) |
|---|
| 12 | #define SAM_N "SAM4 Dos32" |
|---|
| 13 | #elif defined (LINUX) |
|---|
| 14 | #define SAM_N "SAM4 Linux" |
|---|
| 15 | #else |
|---|
| 16 | #define SAM_N "SAM4 OS/2" |
|---|
| 17 | #endif |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | #define SAM_MANDATORY_PARAMS 1 // # of mandatory params to EXE |
|---|
| 21 | |
|---|
| 22 | char *usagetext[] = |
|---|
| 23 | { |
|---|
| 24 | " mandatory-params [optional-params]", |
|---|
| 25 | "", |
|---|
| 26 | " Switch character for EXE switches is '-' or '/'. All single letter", |
|---|
| 27 | " switches are case-sensitive, long switchnames like 'query' are not.", |
|---|
| 28 | "", |
|---|
| 29 | #if defined (DUMP) |
|---|
| 30 | " -123[t][s][l][r][dxx] = trace level 123, [t]stamp; [s]creen; No [l]ogging;" |
|---|
| 31 | " [r]e-open [d]elay xx ms per line", |
|---|
| 32 | #endif |
|---|
| 33 | "", |
|---|
| 34 | " -? = help on executable commandline switches (this text)", |
|---|
| 35 | " -7 = Use 7-bit ASCII only (no 'graphic' characters)", |
|---|
| 36 | " -a = switch off usage of ANSI escape characters for color", |
|---|
| 37 | " -l:logfile = start logging immediately to 'logfile.log'", |
|---|
| 38 | "", |
|---|
| 39 | NULL |
|---|
| 40 | }; |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | #define SAM_SCROLL_L 1000 // lines in scroll-buffer |
|---|
| 44 | #define SAM_SCROLL_W 132 // columns in scroll-buffer |
|---|
| 45 | |
|---|
| 46 | static TXSBDATA scrollBufData = |
|---|
| 47 | { |
|---|
| 48 | 20, |
|---|
| 49 | 80, |
|---|
| 50 | 60, |
|---|
| 51 | 0, |
|---|
| 52 | FALSE, // no scrolling when in middle |
|---|
| 53 | TRUE, // wrap on write on long lines |
|---|
| 54 | 0, |
|---|
| 55 | NULL |
|---|
| 56 | }; |
|---|
| 57 | |
|---|
| 58 | static TXWHANDLE desktop = 0; |
|---|
| 59 | static TXWHANDLE sbufwin = 0; |
|---|
| 60 | static TXWINDOW scrbuffwin; |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | // Standard window procedure, for any window-class |
|---|
| 64 | static ULONG samStdWindowProc // RET result |
|---|
| 65 | ( |
|---|
| 66 | TXWHANDLE hwnd, // IN current window |
|---|
| 67 | ULONG msg, // IN message id |
|---|
| 68 | ULONG mp1, // IN msg param 1 |
|---|
| 69 | ULONG mp2 // IN msg param 2 |
|---|
| 70 | ); |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | int main (int argc, char *argv[]); |
|---|
| 74 | |
|---|
| 75 | /*****************************************************************************/ |
|---|
| 76 | /* Main function of the program, handle commandline-arguments */ |
|---|
| 77 | /*****************************************************************************/ |
|---|
| 78 | int main (int argc, char *argv[]) |
|---|
| 79 | { |
|---|
| 80 | ULONG rc = NO_ERROR; // function return |
|---|
| 81 | |
|---|
| 82 | TxINITmain( "SAMTRACE", "SAM", FALSE, 0); |
|---|
| 83 | |
|---|
| 84 | if (TxaExeSwitch('l')) // start logfile now ? |
|---|
| 85 | { |
|---|
| 86 | TxAppendToLogFile( TxaExeSwitchStr( 'l', NULL, "sam"), TRUE); |
|---|
| 87 | } |
|---|
| 88 | if ((TxaExeSwitch('?')) || // switch help requested |
|---|
| 89 | (TxaExeArgc() <= SAM_MANDATORY_PARAMS)) // or not enough params |
|---|
| 90 | { |
|---|
| 91 | TxPrint( "\n%s %s %s\n%s\n\nUsage: %s", |
|---|
| 92 | SAM_N, SAM_V, SAM_C, SAM_D, TxaExeArgv(0)); |
|---|
| 93 | TxShowTxt( usagetext); |
|---|
| 94 | } |
|---|
| 95 | else |
|---|
| 96 | { |
|---|
| 97 | if ((desktop = txwInitializeDesktop( NULL, NULL)) != 0) |
|---|
| 98 | { |
|---|
| 99 | TXWQMSG qmsg; // one message |
|---|
| 100 | TXRECT dtsize; // desktop client size |
|---|
| 101 | |
|---|
| 102 | txwQueryWindowRect( desktop, FALSE, &dtsize); // get client area |
|---|
| 103 | scrollBufData.length = SAM_SCROLL_L; |
|---|
| 104 | scrollBufData.width = max( SAM_SCROLL_W, TxScreenCols()); |
|---|
| 105 | scrollBufData.vsize = dtsize.bottom -1; // sbstatus line |
|---|
| 106 | |
|---|
| 107 | if ((rc = txwInitPrintfSBHook(&scrollBufData)) == NO_ERROR) |
|---|
| 108 | { |
|---|
| 109 | txwSetupWindowData( |
|---|
| 110 | 0, 0 , dtsize.bottom, dtsize.right, |
|---|
| 111 | TXWS_STDWINDOW | TXWS_MOVEABLE | |
|---|
| 112 | TXWS_HCHILD_SIZE | TXWS_VCHILD_SIZE | |
|---|
| 113 | TXWS_SIDEBORDERS | TXWS_TITLEBORDER, |
|---|
| 114 | 0, ' ', ' ', TXWSCHEME_COLORS, " text output window " , "", |
|---|
| 115 | &scrbuffwin); |
|---|
| 116 | scrbuffwin.sb.topline = scrollBufData.firstline; |
|---|
| 117 | scrbuffwin.sb.leftcol = 0; |
|---|
| 118 | scrbuffwin.sb.sbdata = &scrollBufData; |
|---|
| 119 | scrbuffwin.sb.scolor = cSchemeColor; |
|---|
| 120 | scrbuffwin.sb.altcol = TXSB_COLOR_B2BLUE | TXSB_COLOR_BRIGHT; |
|---|
| 121 | sbufwin = txwCreateWindow( desktop, TXW_SBVIEW, desktop, 0, |
|---|
| 122 | &scrbuffwin, samStdWindowProc); |
|---|
| 123 | scrollBufData.view = sbufwin; // register view for update |
|---|
| 124 | // txwInvalidateWindow( sbufwin, TRUE, TRUE); // and have it painted |
|---|
| 125 | |
|---|
| 126 | txwPostMsg( sbufwin, TXWM_USER, 0, 0); // start the action ... |
|---|
| 127 | |
|---|
| 128 | while (txwGetMsg( &qmsg)) |
|---|
| 129 | { |
|---|
| 130 | txwDispatchMsg( &qmsg); |
|---|
| 131 | } |
|---|
| 132 | txwTermPrintfSBHook(); |
|---|
| 133 | } |
|---|
| 134 | txwTerminateDesktop(); |
|---|
| 135 | } |
|---|
| 136 | else |
|---|
| 137 | { |
|---|
| 138 | TxPrint("Failed to intialize desktop\n"); |
|---|
| 139 | } |
|---|
| 140 | } |
|---|
| 141 | TxEXITmain(rc); // TX Exit code, incl tracing |
|---|
| 142 | } // end 'main' |
|---|
| 143 | /*---------------------------------------------------------------------------*/ |
|---|
| 144 | |
|---|
| 145 | /*****************************************************************************/ |
|---|
| 146 | // SAMPLE standard window procedure, for any window-class |
|---|
| 147 | /*****************************************************************************/ |
|---|
| 148 | static ULONG samStdWindowProc // RET result |
|---|
| 149 | ( |
|---|
| 150 | TXWHANDLE hwnd, // IN current window |
|---|
| 151 | ULONG msg, // IN message id |
|---|
| 152 | ULONG mp1, // IN msg param 1 |
|---|
| 153 | ULONG mp2 // IN msg param 2 |
|---|
| 154 | ) |
|---|
| 155 | { |
|---|
| 156 | ULONG rc = NO_ERROR; |
|---|
| 157 | TXWINDOW *win; |
|---|
| 158 | TXLN text; |
|---|
| 159 | |
|---|
| 160 | |
|---|
| 161 | ENTER(); |
|---|
| 162 | TRCMSG( hwnd, msg, mp1, mp2); |
|---|
| 163 | if (hwnd != 0) |
|---|
| 164 | { |
|---|
| 165 | TRCLAS( "SAM std - ", hwnd); |
|---|
| 166 | win = txwWindowData( hwnd); |
|---|
| 167 | switch (msg) |
|---|
| 168 | { |
|---|
| 169 | case TXWM_USER: |
|---|
| 170 | sprintf( text, "Hello from SAMPLE-4\n\n" |
|---|
| 171 | " param-1 = '%s'\n param-2 = '%s'\n param-3 = '%s'\n\n" |
|---|
| 172 | "Want to quit this game ? [Y/N] ", |
|---|
| 173 | TxaExeArgv(1), TxaExeArgv(2), TxaExeArgv(3)); |
|---|
| 174 | |
|---|
| 175 | if (TxConfirm( 0, text)) // confirmation popup |
|---|
| 176 | { |
|---|
| 177 | txwPostMsg( hwnd, TXWM_CLOSE, 0, 0); // quit the application |
|---|
| 178 | } |
|---|
| 179 | else |
|---|
| 180 | { |
|---|
| 181 | TxPrint( "\n\nOK, there we go again ...\n"); |
|---|
| 182 | TxSleep( 500); |
|---|
| 183 | txwPostMsg( hwnd, TXWM_USER, 0, 0); // restart the action ... |
|---|
| 184 | } |
|---|
| 185 | break; |
|---|
| 186 | |
|---|
| 187 | default: |
|---|
| 188 | rc = txwDefWindowProc( hwnd, msg, mp1, mp2); |
|---|
| 189 | break; |
|---|
| 190 | } |
|---|
| 191 | } |
|---|
| 192 | else |
|---|
| 193 | { |
|---|
| 194 | rc = TX_INVALID_HANDLE; |
|---|
| 195 | } |
|---|
| 196 | RETURN( rc); |
|---|
| 197 | } // end 'samStdWindowProc' |
|---|
| 198 | /*---------------------------------------------------------------------------*/ |
|---|