| 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 | // Generic value prompt implementation text/windowed |
|---|
| 34 | // |
|---|
| 35 | // Author: J. van Wijk |
|---|
| 36 | // |
|---|
| 37 | // JvW 19-08-2005 Initial version, split off from TXCON.C |
|---|
| 38 | |
|---|
| 39 | #include <txlib.h> |
|---|
| 40 | #include <txwpriv.h> // private window interface |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | #if defined (USEWINDOWING) |
|---|
| 44 | static char txMsgPromTitle[] = " Request for additional input "; |
|---|
| 45 | #endif |
|---|
| 46 | |
|---|
| 47 | /*****************************************************************************/ |
|---|
| 48 | // Prompt for user input with a message and read the input |
|---|
| 49 | /*****************************************************************************/ |
|---|
| 50 | BOOL TxPrompt // RET value not empty |
|---|
| 51 | ( |
|---|
| 52 | ULONG helpid, // IN helpid confirmation |
|---|
| 53 | short length, // IN max length of value |
|---|
| 54 | char *value, // OUT entry field value |
|---|
| 55 | char *fmt, // IN format string (printf) |
|---|
| 56 | ... // IN variable arguments |
|---|
| 57 | ) |
|---|
| 58 | { |
|---|
| 59 | char text[512]; |
|---|
| 60 | va_list varargs; |
|---|
| 61 | char **mText; // formatted text for display |
|---|
| 62 | int ll; // real max line length |
|---|
| 63 | int lines; // nr of lines |
|---|
| 64 | DEVICE_STATE sa = TxScreenState(DEVICE_TEST); |
|---|
| 65 | |
|---|
| 66 | if ((ll = TxScreenCols() -12) < 20) // ScreenCols will be 0 if |
|---|
| 67 | { // output is redirected! |
|---|
| 68 | ll = 20; |
|---|
| 69 | } |
|---|
| 70 | if ((txwa->desktop != NULL) && (!TxaExeSwitch('p'))) |
|---|
| 71 | { |
|---|
| 72 | TxScreenState(DEVICE_OFF); // no regular text if windowed |
|---|
| 73 | } // and not 'pedantic mode' |
|---|
| 74 | else |
|---|
| 75 | { |
|---|
| 76 | TxScreenState(DEVICE_ON); // force screen on for input |
|---|
| 77 | } |
|---|
| 78 | va_start(varargs, fmt); |
|---|
| 79 | vsprintf( text, fmt, varargs); // format the message |
|---|
| 80 | |
|---|
| 81 | mText = txString2Text( text, &ll, &lines); // convert to multi-line |
|---|
| 82 | TxPrint( "\n"); // force empty line before |
|---|
| 83 | TxShowTxt( mText); // display in scrollbuffer |
|---|
| 84 | txFreeText( mText); // free the text memory |
|---|
| 85 | TxPrint("\n"); |
|---|
| 86 | |
|---|
| 87 | #if defined (USEWINDOWING) |
|---|
| 88 | if (txwa->desktop != NULL) // there is a desktop |
|---|
| 89 | { |
|---|
| 90 | TxStripAnsiCodes( text); // remove colors for popup |
|---|
| 91 | if (txwPromptBox( TXHWND_DESKTOP, TXHWND_DESKTOP, NULL, |
|---|
| 92 | text, txMsgPromTitle, helpid, |
|---|
| 93 | TXPB_MOVEABLE | TXPB_HCENTER, |
|---|
| 94 | length, value) |
|---|
| 95 | == TXDID_CANCEL) |
|---|
| 96 | { |
|---|
| 97 | strcpy( value, ""); // wipe value, signal cancel |
|---|
| 98 | TxCancelAbort(); // avoid aborting on Escape ... |
|---|
| 99 | } |
|---|
| 100 | } |
|---|
| 101 | else // use non-windowed interface |
|---|
| 102 | #endif // USEWINDOWING |
|---|
| 103 | { |
|---|
| 104 | TXLN defval; |
|---|
| 105 | |
|---|
| 106 | memset( defval, 0, TXMAXLN); |
|---|
| 107 | strncpy( defval, value, length); |
|---|
| 108 | TxPrint( "\nDefault on <Enter>: '%s'\n", defval); |
|---|
| 109 | |
|---|
| 110 | TxPrint( "or different value: "); |
|---|
| 111 | memset( value, 0, length); |
|---|
| 112 | fgets( value, length, stdin); // get the value |
|---|
| 113 | TxRepl( value, '\n', 0); |
|---|
| 114 | TxPrint("\n"); |
|---|
| 115 | if (strlen( value) == 0) // empty ==> use default |
|---|
| 116 | { |
|---|
| 117 | strcpy( value, defval); |
|---|
| 118 | } |
|---|
| 119 | } |
|---|
| 120 | TxScreenState(sa); // restore screen state |
|---|
| 121 | |
|---|
| 122 | return(strlen(value) != 0); |
|---|
| 123 | } // end 'TxPrompt' |
|---|
| 124 | /*---------------------------------------------------------------------------*/ |
|---|