📄 oper_int.cpp
字号:
}
void COperatorWindow::AddOutputItem (const char* aLabel, long* aData)
{
OutputItems->Insert (DT_LONG, aLabel, (void*)aData);
}
void COperatorWindow::AddOutputItem (const char* aLabel, float* aData)
{
OutputItems->Insert (DT_FLOAT, aLabel, (void*)aData);
}
void COperatorWindow::AddOutputItem (const char* aLabel, double* aData)
{
OutputItems->Insert (DT_DOUBLE, aLabel, (void*)aData);
}
void COperatorWindow::AddOutputItem (const char* aLabel, long double* aData)
{
OutputItems->Insert (DT_LONG_DBL, aLabel, (void*)aData);
}
void COperatorWindow::AddOutputItem (const char* aLabel, char* aData)
{
OutputItems->Insert (DT_STRING, aLabel, (void*)aData);
}
//-------------------------------------------------------------------------------------
// Function: AddKey
// This function places the given key item into the operator window's list of key
// maps.
void COperatorWindow::AddKey (int aChar, const char* aLn1, const char* aLn2,
void (*aFunc)(void))
{
// Check the key item to make sure it's not an invalid item - some characters,
// such as ^C, ^H, etc. have special meaning on many operating systems. If your
// OS defines other special characters, you can add them to this list.
switch (aChar)
{
case 'C': // Control-C is kill current process
case 'H': // Control-H is a backspace
case 'I': // Control-I is a tab character
case 'J': // Control-J is a linefeed character
case 'M': // Control-M is a carriage return
gotoxy (2, 2);
char Err[3];
sprintf (Err, "ERROR: Cannot use key Ctrl-%c in user interface", aChar);
OPI_print (Err);
exit (2);
}
// OK, the key is legitimate so insert it in the list
KeyItems->Insert (aChar, aLn1, aLn2, aFunc, KeyItemSerialNumber++);
}
//-------------------------------------------------------------------------------------
// Function: ShowAll
// This function tells all the input, output, and key items in the lists to show
// themselves. It's called by Display().
void COperatorWindow::ShowAll (void)
{
CKeyItem* pKeyItem; // Points to a key item which must be displayed
// Make sure that this operator window will be displayed, not some other one
CurrentOpWin = this;
// Display all input items with titles in columns on the left half of the screen
InputItems->GetHead ();
while (InputItems->PaintOne () == true);
// Display the output items and titles in columns on the right half of the screen
OutputItems->GetHead ();
while (OutputItems->PaintOne () == true);
// Display all the key items in the list
pKeyItem = (CKeyItem*) KeyItems->GetHead ();
while (pKeyItem != NULL)
{
pKeyItem->Paint ();
pKeyItem = (CKeyItem*) KeyItems->GetNext();
}
}
//-------------------------------------------------------------------------------------
// Function: Display
// This function is the one which the user calls when he wants to display the
// operator window for the first time after he's constructed it. It clears the
// whole screen and paints on the new operator window.
void COperatorWindow::Display (void)
{
NeedToDrawKeys = 1; // Set these flags so that key functions
NeedToDrawTitle = 1; // and title are drawn first by Update()
// Set the chosen-input-item pointer to the first element in the list
// Changed 10/96 by DMA
SelectedInput = (CDataItem*)InputItems->GetHead ();
CurrentOpWin = this; // Set current-window pointer to this one
clrscr (); // Clear anything which was there off
#ifndef _Windows
_setcursortype (_NOCURSOR); // turn the cursor off
#endif
}
//-------------------------------------------------------------------------------------
// Function: Close
// This function causes the operator window to stop displaying itself, but it
// still remains in memory, ready to show itself if the user needs it.
void COperatorWindow::Close (void)
{
// Set pointer-to-current-OpWin to NULL, meaning don't show this one
CurrentOpWin = NULL;
// clrscr ();
#ifndef _Windows // If not running EasyWin,
_setcursortype (_NORMALCURSOR); // turn the cursor back on again
#endif
}
//-------------------------------------------------------------------------------------
// Function: CheckKeyboard
// When the Update() function (see below) runs, it repaints part of the screen
// and then checks the keyboard for input. The keyboard checking stuff is here
// - just to make the program easier to read.
void COperatorWindow::CheckKeyboard (void)
{
int InputChar; // Character read from the keyboard
CKeyItem* pKey; // Pointer to key mapping object
// Check for a keyboard hit. If there's been one, see what kind of key it was,
// and act appropriately
if (kbhit ())
{
InputChar = getch ();
// Somebody hit the TAB key. Save data and move the selection down, and if
// it's at the last item, wrap back to the first one
if (InputChar == '\t')
{
if (SelectedInput != NULL)
{
SelectedInput->SetValue (InputBuffer);
InputItems->GetObjWith (SelectedInput);
if (InputItems->GetNext () != NULL)
SelectedInput = (CDataItem*) InputItems->GetCurrent ();
else
{
if (InputItems->GetHead () != NULL);
SelectedInput = (CDataItem*) InputItems->GetHead ();
}
InputIndex = 0;
InputBuffer[0] = '\0';
}
}
// This stuff runs if someone presses the accent (`) key. It moves the
// selection up after saving data - like a reverse-tab. By the way, the
// ASCII number for this thing is 96.
if (InputChar == '`')
{
if (SelectedInput != NULL)
{
SelectedInput->SetValue (InputBuffer);
InputItems->GetObjWith (SelectedInput);
if (InputItems->GetPrevious () != NULL)
SelectedInput = (CDataItem*) InputItems->GetCurrent ();
else
{
if (InputItems->GetTail () != NULL);
SelectedInput = (CDataItem*) InputItems->GetTail ();
}
InputIndex = 0;
InputBuffer[0] = '\0';
}
}
// A RETURN character causes the input buffer to be processed
else if (InputChar == '\n' || InputChar == '\r')
{
if (SelectedInput != NULL)
{
SelectedInput->SetValue (InputBuffer);
InputIndex = 0;
InputBuffer[0] = '\0';
}
}
// A backspace key causes the last character in buffer to be deleted
else if (InputChar == 8)
{
InputIndex--;
InputBuffer[InputIndex] = '\0';
}
// If someone pressed a function key Ctrl-A to Ctrl-Z, scan through function
// key mappings until we find one corresponding to the key just pressed
else if (InputChar < 27)
{
pKey = (CKeyItem *) KeyItems->GetHead ();
while (pKey != NULL)
{
int WhichChar = pKey->GetKeyChar ();
if (WhichChar == (InputChar + 64))
{
pKey->RunKeyFunction ();
break;
}
pKey = (CKeyItem*) KeyItems->GetNext ();
}
}
// Default means it's just an ordinary alphanumeric key; save it
else
{
if (SelectedInput != NULL)
{
InputBuffer[InputIndex++] = (char)InputChar;
InputBuffer[InputIndex] = '\0';
}
}
}
}
//-------------------------------------------------------------------------------------
// Function: Update
// This function performs a real-time partial update of the operator window. One
// screen item (and only one) is scanned and, if need be, redrawn. We scan just
// one item at a time to reduce the latency associated with screen stuff. The
// versions of this function for DOS and Windows are different. The DOS one here
// checks for user input at the keyboard.
void COperatorWindow::Update (void)
{
static bool ToggleList = true; // True if showing input items now
CKeyItem* pKeyItem; // Points to one key item to be displayed
// Call the function above to take care of any keys the user might have pressed
CheckKeyboard ();
// If the key item descriptions or the window title need to be drawn, do so now
// and return having done so. This reduces the latency of calling Display()
if (NeedToDrawKeys != 0)
{
// Display all the key item legends
pKeyItem = (CKeyItem*) KeyItems->GetHead ();
while (pKeyItem != NULL)
{
pKeyItem->Paint ();
pKeyItem = (CKeyItem*) KeyItems->GetNext ();
}
NeedToDrawKeys = 0;
return;
}
// If the title-drawing flag is set, display the operator window title in its
// position near top of the screen
if (NeedToDrawTitle != 0)
{
gotoxy (2, 2);
OPI_print (Title);
NeedToDrawTitle = 0;
return;
}
// Repaint one input item. If we're currently working from the input list, check
// to see if we're that the end of that list (The PaintOne() method will return
// false at end of list); if at the end, set the toggle so next time we'll begin
// going through the output items list. And vice versa of course.
if (ToggleList == true)
{
if (InputItems->PaintOne () == false)
ToggleList = false;
}
else
{
if (OutputItems->PaintOne () == false)
ToggleList = true;
}
}
//-------------------------------------------------------------------------------------
// Function: Paint
// This function isn't needed in the DOS version. It gets called in the Windows
// version whenever the window needs repainting - for example, when the function
// InvalidateRect() has sent a WM_PAINT message to the application - and that
// doesn't happen in a DOS app. So, this is just a dummy function.
void COperatorWindow::Paint (void)
{
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -