C (240/301)

From:JSteic1957
Date:30 Aug 99 at 04:00:53
Subject:RawKey Handling

From: JSteic1957@aol.com

All right all you Amiga-C honchos, let's see if you can solve a hardproblem
for a change! Here's the problem: Add RawKey support to a program that uses
GadTools in its GUI. Most of the code shown was generated by GadToolsBox
V37.300, which is a most useful program (IMHO, it's much easier to use
GadTools than MUI for making GUI's).I'm in the process of re-writing a
program that interfaces to a customLogic Analyzer, which used to work under
Amiga OS 2.0. Apparently,the method the system uses to handle RawKeys has
changed for OS 3.1. Looking at the RawKey.c example in the RKRM (pgs
277-280), I can seethat a console has to be opened in order for a window to
see the RawKeys. I'd prefer NOT to have to change the HandleLAIDCMP()
functionshown in order to deal with RawKeys. I know how to open consoles &
do I/O with them, so that's simple. Is there a re-write of RawKey.cthat will
fit the method of handling IDCMPs documented here?

PUBLIC int HandleLAIDCMP( void )
{
struct IntuiMessage *m;
struct MenuItem *n;
int (*func)( void ), (*mfunc)( void );
BOOL running = TRUE;

while (running == TRUE) {

if ((m = GT_GetIMsg( LAWnd->UserPort )) == NULL) {
(void) Wait( 1L << LAWnd->UserPort->mp_SigBit );
continue; }

CopyMem( (char *) m, (char *) &LAMsg,
(long) sizeof( struct IntuiMessage ) );

GT_ReplyIMsg( m ); // This might conflict with RawKey.c example.
switch (LAMsg.Class) {
case IDCMP_REFRESHWINDOW:
GT_BeginRefresh( LAWnd );
GT_EndRefresh( LAWnd, TRUE );
break;

case IDCMP_CLOSEWINDOW:
running = LACloseWindow();
break;

case IDCMP_VANILLAKEY:
running = LAVanillaKey( LAMsg.Code );
break;

case IDCMP_RAWKEY: // What do you use for arguments here?

running = LARawKey( ?? );
break;

case IDCMP_GADGETUP:
func = (void *) ((struct Gadget *)LAMsg.IAddress)->UserData;
if (func != NULL)
running = func();

break;

case IDCMP_MOUSEMOVE:
if (LAMsg.MouseX > (CTRL_Left + LAWnd->BorderLeft))
{
if (LAMsg.MouseY > (CTRL_Height + LAWnd->BorderTop
+ LAWnd->BorderBottom)) {

WindowToFront( LAWnd );
DrawCrossHairs( &LAMsg ); } }

break;

case IDCMP_MENUPICK:
/* Beware! Quit menu-item should only return FALSE,
** NOT call CloseLAWindow() or this code will choke:
*/
while ( LAMsg.Code != MENUNULL ) {
n = ItemAddress( LAMenus, LAMsg.Code );
if (n != NULL)
mfunc = (void *) (GTMENUITEM_USERDATA( n ));

if (mfunc != NULL)
running = mfunc();

LAMsg.Code = n->NextSelect; }

break; } }
return( running );
}

// Vanilla keys are quite easy to deal with:

PRIVATE int LAVanillaKey( int whichkey )
{
int rval = TRUE;
switch (whichkey) {
case 'l':
case 'L':
if (WhatDisplay == TIMING_DISPLAY)
if ((layer->Scroll_X - deltaX) > 0 ) {
ScrollLayer( layer_info, layer, -deltaX, 0 );
UpdateCount( -1, 0 ); }

break;

case 'r':
case 'R':
if (WhatDisplay == TIMING_DISPLAY)
if ((layer->Scroll_X + deltaX) < maxXScroll( LAWnd ) )

{
ScrollLayer( layer_info, layer, deltaX, 0 );
UpdateCount( 1, 0 ); }

break;

case 'd':
case 'D':
DrawWaves( CStart, CEnd );
break;

default: break;
}

return( rval );
}

PRIVATE int LARawKey( ?? )
{
int rval = TRUE;

switch (??) {
case LEFT: /* <-- arrow key */
if (WhatDisplay == TIMING_DISPLAY)
if ((layer->Scroll_X - deltaX) > 0 ) {
ScrollLayer( layer_info, layer, -deltaX, 0 );
UpdateCount( -1, 0 ); }

break;

case RIGHT: /* --> arrow key */
if (WhatDisplay == TIMING_DISPLAY)
if ((layer->Scroll_X + deltaX) < maxXScroll( LAWnd ) )
{
ScrollLayer( layer_info, layer, deltaX, 0 );
UpdateCount( 1, 0 ); }

break;

case UP: /* Up arrow key */
if (WhatDisplay != TIMING_DISPLAY)
if ((layer->Scroll_Y + deltaY) < maxYScroll( LAWnd ) )

ScrollLayer( layer_info, layer, 0, deltaY );
break;

case DOWN: /* Down arrow key */
if (WhatDisplay != TIMING_DISPLAY)
if ((layer->Scroll_Y - deltaY) > 0 )
ScrollLayer( layer_info, layer, 0, -deltaY );
break;

case HELP:
case F1:
..... // etc.
case F10:
break;

default:
break;
}

return( rval );
}

PUBLIC int OpenLAWindow( struct BitMap *bitmap )
{
struct NewGadget ng;
struct Gadget *g;
UWORD lc, tc;
UWORD wleft = LALeft, wtop = LATop, ww, wh;
...... // Other stuff goes here.

if (!(LAWnd = OpenWindowTags( NULL,
WA_Left, wleft,
WA_Top, wtop,
WA_Width, ww + CFont.OffX + Scr->WBorRight,
WA_Height, wh + CFont.OffY + Scr->WBorBottom,
WA_IDCMP, STRINGIDCMP | BUTTONIDCMP
| IDCMP_MOUSEMOVE | IDCMP_MENUPICK | IDCMP_CLOSEWINDOW
| IDCMP_VANILLAKEY | IDCMP_REFRESHWINDOW,

/* Simply adding IDCMP_RAWKEY doesn't allow RawKeys to
** make it into the Program!
*/
WA_Flags, WFLG_DRAGBAR | WFLG_DEPTHGADGET
| WFLG_CLOSEGADGET | WFLG_SMART_REFRESH
| WFLG_SUPER_BITMAP | WFLG_GIMMEZEROZERO
| WFLG_ACTIVATE,

WA_Gadgets, LAGList,
WA_Title, LAWdt,
WA_ScreenTitle, ScreenTitle,
WA_SuperBitMap, bitmap,
TAG_DONE )) )

return( 4L );

SetMenuStrip( LAWnd, LAMenus );
GT_RefreshWindow( LAWnd, NULL );
return( 0 );
}

Sorry if the code is a little hard to read, it was perfectly fine before I
used the stupid AOL e-mail editor to take care of adding the CRLFs that
IBM-Land requires!