home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
tvos200.zip
/
TVISION
/
HARDOS2.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1995-04-25
|
10KB
|
315 lines
/*------------------------------------------------------------*/
/* filename - hardos2.cpp */
/* */
/* function(s) */
/* Member variables for THardwareInfo class */
/* under the OS/2 OS. */
/* */
/*------------------------------------------------------------*/
/*
* Turbo Vision - Version 2.0
*
* Copyright (c) 1994 by Borland International
* All Rights Reserved.
*
*/
#if defined(__OS2__) // Compile module for DOS only.
#define Uses_TKeys
#define Uses_TEvent
#define Uses_TScreen
#define Uses_THardwareInfo
#define Uses_TSystemError
#include <tvision\tv.h>
#include <tvision/os2stuff.h>
#include <assert.h>
//** OS/2-specific THardwareInfo stuff..
Boolean THardwareInfo::insertState = True;
THardwareInfo::PlatformType THardwareInfo::platform = THardwareInfo::plOS2;
static Boolean initMouse();
/*
* Constructor()..
*/
THardwareInfo::THardwareInfo()
{
platform = plOS2; // Just define the OS/2 platform.
initMouse(); // Open the mouse interface
}
/****************************************************************************/
/* */
/* CODING: Screen functions. */
/* */
/****************************************************************************/
ushort THardwareInfo::getScreenMode()
{
VIOCONFIGINFO vci;
VIOMODEINFO vmi;
int mono;
USHORT mode;
vci.cb = sizeof(vci);
VioGetConfig(0, &vci, 0);
vmi.cb = sizeof(vmi);
VioGetMode(&vmi, 0);
mono = vci.display == MONITOR_MONOCHROME; /* Set T when in MONO mode, */
switch(vci.adapter)
{
case DISPLAY_MONOCHROME: mode = TDisplay::smMono; break;
case DISPLAY_CGA: mode = TDisplay::smCO80; break;
case DISPLAY_EGA: mode = TDisplay::smCO80; break;
default:
if(vci.adapter < 7)
{
mode = TDisplay::smMono;
break;
}
/**** Else continue & use VGA. ****/
case 8: // ?? Reported by OS/2 2.0??
case DISPLAY_VGA:
mode = TDisplay::smCO80;
break;
}
if(getScreenRows() > 25)
mode |= TDisplay::smFont8x8; // Stupid hardware dependent stuff
return mode;
}
void THardwareInfo::setScreenMode( ushort mode )
{
//** $NI$: Currently not implemented.
}
void THardwareInfo::screenWrite( ushort x, ushort y, ushort *buf, unsigned len )
{
VioWrtCellStr((PCH) buf, ushort(len), y, x, 0);
}
ushort THardwareInfo::getScreenCols()
{
ushort errc;
VIOMODEINFO vmi;
vmi.cb = sizeof(vmi);
errc= VioGetMode(&vmi, 0); // Get Mode Info,
if(errc) return 25; // On error return default #rows,
return vmi.row < 80 ? 80 : vmi.col; // Return #rows, at least 25!
}
ushort THardwareInfo::getScreenRows()
{
ushort errc;
VIOMODEINFO vmi;
vmi.cb = sizeof(vmi);
errc= VioGetMode(&vmi, 0); // Get Mode Info,
if(errc) return 25; // On error return default #rows,
return vmi.row < 25 ? 25 : vmi.row; // Return #rows, at least 25!
}
/****************************************************************************/
/* */
/* CODING: Caret (hardware cursor) functions. */
/* */
/****************************************************************************/
ushort THardwareInfo::getCaretSize()
{
VIOCURSORINFO vci;
VioGetCurType(&vci, 0); // Get cursor shape,
return (vci.yStart << 8) | vci.cEnd;
}
void THardwareInfo::setCaretPosition( ushort x, ushort y )
{
VioSetCurPos(y, x, 0); // Set cursor position,
}
void THardwareInfo::setCaretSize(ushort ct)
{
VIOCURSORINFO vci;
/**** The HIGH part of ct contains the TOP line, the LOW part == count, ****/
VioGetCurType(&vci, 0); // Get cursor shape,
if(ct == 0 || (ct >> 8) > 8) // Cursor OFF request?
vci.attr = 0xffff; // Then switch OFF the cursor!!
else
{
vci.yStart = ct >> 8;
vci.cEnd = ct & 0xff;
}
VioSetCurType(&vci, 0);
}
/****************************************************************************/
/* */
/* CODING: Event functions - keyboard interface. */
/* */
/****************************************************************************/
Boolean THardwareInfo::getKeyEvent( TEvent& event )
{
ushort key, state;
key = osKeyFast(& state); // Get keycode && state, no block,
if(key == 0) // No key was pressed?
{
event.what = evNothing;
return False;
}
/**** Translate the OS/2 state to the Turbo Vision defines.. ****/
/*
* The OS/2 values are the same as the DOS values, so leave'm!! This is
* NOT portable but fast..
*/
event.what = evKeyDown;
event.keyDown.charScan.scanCode = uchar( key >> 8 );
event.keyDown.charScan.charCode = uchar( key );
event.keyDown.controlKeyState = state;
return True;
}
/****************************************************************************/
/* */
/* CODING: Mouse events. */
/* */
/****************************************************************************/
/*
* Mouse event handler. This mouse event handler uses Mou* subsystem calls to
* manipulate the rodent. This is not reentrant. To find mouse state
* differences the routines keep a global "state" variable which contains the
* last known mouse state. When the new state is read it is compared with the
* previous state, and from that comparison the events are generated.
*/
static Boolean Initialized = False; // T when 1st call is done.
static MouseEventType LastMouse; // Last event gotten,
static HMOU Handle;
static Boolean HasMouse = False;
/*
* initMouse() initializes the mouse for OS/2. Called from the constructor.
*/
static Boolean initMouse()
{
USHORT msk = MOUSE_MOTION | MOUSE_BN1_DOWN | MOUSE_MOTION_WITH_BN1_DOWN |
MOUSE_MOTION_WITH_BN2_DOWN | MOUSE_BN2_DOWN;
assert(! HasMouse); // Cannot have mouse yet!
if(MouOpen(NULL, &Handle) == 0) // Open the MOUSE device,
{
HasMouse = True;
MouSetEventMask(&msk, Handle); // Set events we need,
MouFlushQue(Handle); // Release current queue,
return True;
}
return False;
}
/*
* hasMouseEvent() checks if a mouse event has occured and, if so, retrieves
* the event.
*/
static Boolean hasMouseEvent(MouseEventType& me)
{
USHORT errc;
MOUEVENTINFO mei;
MOUQUEINFO qi;
USHORT flg = MOU_NOWAIT;
if(! HasMouse)
{
if(! initMouse()) return False;
}
errc= MouGetNumQueEl(&qi, Handle); // Are there elements?
if(errc != 0 || qi.cEvents <= 0) return False; // No-> no events.
errc= MouReadEventQue(&mei, &flg, Handle); // Read queue. OK?
if(errc != 0) return False; // Failed-> no events.
me.where.x = mei.col;
me.where.y = mei.row;
me.controlKeyState = osKeyState(); // Get keystate at time of event
me.buttons = 0;
if((mei.fs & (MOUSE_MOTION_WITH_BN1_DOWN|MOUSE_BN1_DOWN)) != 0)
me.buttons |= mbLeftButton;
if((mei.fs & (MOUSE_MOTION_WITH_BN2_DOWN|MOUSE_BN2_DOWN)) != 0)
me.buttons |= mbRightButton;
return True;
}
ulong THardwareInfo::getButtonCount()
{
return HasMouse ? 2 : 0;
}
Boolean THardwareInfo::getMouseEvent( MouseEventType& ev )
{
if(! hasMouseEvent(ev)) return False; // No event-> exit.
//** An event has occured. If this is the 1st event we see then init the
//** event variable..
if(! Initialized)
{
LastMouse = ev; // Initialize last mouse;
LastMouse.buttons = 0; // No buttons pressed, though,
Initialized = True;
}
return True;
}
ulong THardwareInfo::getTickCount()
{
return osTimeGetRunning() / 55; // Get ticks from ms counter. Bah.
}
void THardwareInfo::cursorOn()
{
MouDrawPtr(Handle); // Display mouse.
}
void THardwareInfo::cursorOff()
{
NOPTRRECT nr;
nr.row = 0;
nr.col = 0;
nr.cRow = TScreen::screenHeight-1;
nr.cCol = TScreen::screenWidth-1;
MouRemovePtr(&nr, Handle); // Remove mouse in this rect,
}
void THardwareInfo::clearScreen(ushort, ushort)
{
static char s[] = "\x1b" "[2J";
VioWrtTTY((PCH)s, sizeof(s)-1, 0);
}
#endif // __OS2__ defined.