home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The CDPD Public Domain Collection for CDTV 3
/
CDPDIII.bin
/
pd
/
commodities
/
findfile
/
ffsource.lha
/
FFWindow.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-04-03
|
9KB
|
353 lines
/******************************** FindFile Window Management **********************
FindFile window management routines
1.8
**********************************************************************************/
#include "FindFile.h"
/* Export library bases */
extern struct Library *IntuitionBase;
extern struct Library *GadToolsBase;
extern struct Library *CxBase;
extern struct Library *IconBase;
extern struct TextAttr DefaultFont;
extern char *windowTitle;
void
OpenFFWindow( struct controlPanel *cp )
{
struct Screen *defScreen;
WORD left,
top;
if( cp->ffWindow )
{
WindowToFront( cp->ffWindow );
ActivateWindow( cp->ffWindow );
return;
}
if( !( defScreen = (struct Screen *)LockPubScreen( NULL )))
Shutdown( cp, 20 );
if( !(cp->ffWinVi = GetVisualInfo( defScreen, TAG_DONE )))
Shutdown( cp, 20 );
CreateFFGadgets( cp, ( defScreen->WBorTop + defScreen->Font->ta_YSize+1 ),
defScreen->WBorLeft );
if( (cp->centerWindow) || cp->lastX == -1 || cp->lastY == -1 )
CenterWindow( defScreen, &left, &top );
else
{
left = cp->lastX;
top = cp->lastY;
}
cp->ffWindow = OpenWindowTags( NULL, WA_Left , left,
WA_Top, top,
WA_InnerWidth, FF_WIDTH,
WA_InnerHeight, FF_HEIGHT,
WA_Activate, TRUE,
WA_Flags, WFLG_DRAGBAR | WFLG_DEPTHGADGET |
WFLG_CLOSEGADGET |
WFLG_SMART_REFRESH,
WA_IDCMP, STRINGIDCMP|CYCLEIDCMP|
BUTTONIDCMP|LISTVIEWIDCMP|
IDCMP_CLOSEWINDOW|
IDCMP_VANILLAKEY|
IDCMP_REFRESHWINDOW|
IDCMP_DISKINSERTED|
IDCMP_DISKREMOVED,
WA_PubScreen, defScreen,
WA_Title, windowTitle,
WA_Gadgets, cp->ffWinGadList,
TAG_DONE );
GT_RefreshWindow( cp->ffWindow, NULL );
GT_SetGadgetAttrs( cp->ffWinGads[ID_FOUNDLIST],
cp->ffWindow, NULL,
GTLV_Labels, (&cp->foundList),
GTLV_Selected, ~0L,
TAG_DONE );
UnlockPubScreen( NULL , defScreen );
}
void
CloseFFWindow( struct controlPanel *cp )
{
int count;
cp->lastX = cp->ffWindow->LeftEdge;
cp->lastY = cp->ffWindow->TopEdge;
CloseWindow( cp->ffWindow );
cp->ffWindow = NULL;
FreeVisualInfo( cp->ffWinVi );
cp->ffWinVi = NULL;
FreeGadgets( cp->ffWinGadList );
cp->ffWinGadList = NULL;
for( count = 0; count < ID_NUMGADS; count++ )
cp->ffWinGads[ count ] = NULL;
}
void
HandleFFWindowCommand( struct controlPanel *cp )
{
struct IntuiMessage *msg;
while( msg = GT_GetIMsg( cp->ffWindow->UserPort ) )
{
struct Gadget *gad;
ULONG class;
UWORD code,
qualifier;
gad = (struct Gadget *)msg->IAddress;
class = msg->Class;
code = msg->Code;
qualifier = msg->Qualifier;
GT_ReplyIMsg( msg );
switch( class )
{
case IDCMP_CLOSEWINDOW : CMD_Hide( cp );
break;
case IDCMP_VANILLAKEY : switch( code )
{
case '?' : DoFileReq( cp );
GT_SetGadgetAttrs(cp->ffWinGads[ID_DEVGAD],
cp->ffWindow, NULL,
GTST_String, cp->searchPath,
TAG_END );
break;
case 'p' :
case 'P' : ActivateGadget(cp->ffWinGads[ID_PATGAD],
cp->ffWindow, NULL );
break;
case 'D' :
case 'd' : ActivateGadget(cp->ffWinGads[ID_DEVGAD],
cp->ffWindow, NULL );
break;
case 'F' : if( cp->currFound != ~0 )
cp->currFound = cp->currFound == 0 ?
0 :
(--(cp->currFound)) % cp->numFound;
GT_SetGadgetAttrs( cp->ffWinGads[ID_FOUNDLIST],
cp->ffWindow, NULL,
GTLV_Selected, cp->currFound,
GTLV_Top, cp->currFound,
TAG_END );
break;
case 'f' : if( cp->currFound == ~0 )
cp->currFound = 0;
else
cp->currFound = cp->currFound == (cp->numFound-1) ?
cp->currFound :
(++cp->currFound) % cp->numFound;
GT_SetGadgetAttrs( cp->ffWinGads[ID_FOUNDLIST],
cp->ffWindow, NULL,
GTLV_Selected, cp->currFound,
GTLV_Top, cp->currFound,
TAG_END );
break;
case 'h' :
case 'H' : CMD_Hide( cp );
break;
case 's' :
case 'S' : CMD_Search( cp );
break;
case 'q' :
case 'Q' : CMD_Quit( cp );
break;
}
break;
case IDCMP_REFRESHWINDOW : GT_BeginRefresh(cp->ffWindow);
GT_EndRefresh(cp->ffWindow,TRUE);
break;
case IDCMP_GADGETUP : switch( gad->GadgetID )
{
case ID_PATGAD : strncpy( cp->searchString ,
((struct StringInfo *)
cp->ffWinGads[ID_PATGAD]
->SpecialInfo)->Buffer ,
MAXSTR );
break;
case ID_DEVGAD : strncpy( cp->searchPath,
((struct StringInfo *)
cp->ffWinGads[ID_DEVGAD]
->SpecialInfo)->Buffer,
MAXSTR );
break;
case ID_FILEREQ: DBf("File Request on %s\n",cp->searchPath )
DoFileReq( cp );
GT_SetGadgetAttrs(cp->ffWinGads[ID_DEVGAD],
cp->ffWindow, NULL,
GTST_String, cp->searchPath,
TAG_END );
DBf("File request returned %s\n",cp->searchPath )
break;
case ID_SEARCH : CMD_Search( cp );
break;
case ID_HIDE : CMD_Hide( cp );
break;
case ID_QUIT : CMD_Quit( cp );
break;
}
break;
}
if( ! cp->ffWindow )
break;
}
}
void
CreateFFGadgets( struct controlPanel *cp, int topEdge , BYTE leftEdge)
{
struct Gadget *gadget;
struct NewGadget ng;
cp->ffWinGadList = NULL;
if( ! ( gadget = CreateContext( &(cp->ffWinGadList) ) ) )
Shutdown( cp , 20 );
ng.ng_Width = 312;
ng.ng_Height = 16;
ng.ng_GadgetText = "Search _Pattern :";
ng.ng_TextAttr = &DefaultFont;
ng.ng_VisualInfo = cp->ffWinVi;
ng.ng_GadgetID = ID_PATGAD;
ng.ng_Flags = 0;
ng.ng_LeftEdge = ( strlen( ng.ng_GadgetText ) + 2 - 1 ) * 8 - 2 + leftEdge;
ng.ng_TopEdge = 5 + topEdge;
cp->ffWinGads[ID_PATGAD] = gadget = CreateGadget( STRING_KIND, gadget, &ng,
GT_Underscore, '_',
GTST_MaxChars, MAXSTR,
GTST_String, cp->searchString,
TAG_DONE );
ng.ng_GadgetID = ID_DEVGAD;
ng.ng_GadgetText = "_Device to Search :";
ng.ng_TopEdge += ng.ng_Height + INTERHEIGHT;
ng.ng_LeftEdge = ( strlen( ng.ng_GadgetText ) + 2 - 1 ) * 8 - 2 + leftEdge;
ng.ng_Width = 275;
ng.ng_Height = 18;
cp->ffWinGads[ID_DEVGAD] = gadget = CreateGadget( STRING_KIND, gadget, &ng,
GT_Underscore, '_',
GTST_MaxChars, MAXSTR,
GTST_String, cp->searchPath,
TAG_DONE );
ng.ng_GadgetID = ID_FILEREQ;
ng.ng_GadgetText = "_?";
ng.ng_LeftEdge = ng.ng_LeftEdge + ng.ng_Width;
ng.ng_Width = 20;
cp->ffWinGads[ID_FILEREQ] = gadget = CreateGadget( BUTTON_KIND, gadget, &ng,
GT_Underscore, '_',
TAG_DONE );
ng.ng_GadgetID = ID_FOUNDLIST;
ng.ng_GadgetText = "_Files Found :";
ng.ng_TopEdge += ng.ng_Height + 16;
ng.ng_LeftEdge = leftEdge + 5;
ng.ng_Width = 448;
ng.ng_Height = 76;
cp->ffWinGads[ID_FOUNDLIST] = gadget = CreateGadget( LISTVIEW_KIND, gadget, &ng,
GTLV_ShowSelected, NULL,
GT_Underscore, '_',
TAG_DONE );
ng.ng_GadgetID = ID_SEARCH;
ng.ng_GadgetText = "_Search";
ng.ng_LeftEdge = leftEdge + 5L;
ng.ng_TopEdge += ng.ng_Height + 4;
ng.ng_Width = 106;
ng.ng_Height = 20;
cp->ffWinGads[ID_SEARCH] = gadget = CreateGadget( BUTTON_KIND, gadget, &ng,
GT_Underscore, '_',
TAG_DONE );
ng.ng_GadgetID = ID_ABORT;
ng.ng_GadgetText = "_Abort";
ng.ng_LeftEdge += ng.ng_Width + INTERWIDTH;
cp->ffWinGads[ID_ABORT] = gadget = CreateGadget( BUTTON_KIND, gadget, &ng,
GT_Underscore, '_',
GA_Disabled, TRUE,
TAG_DONE );
ng.ng_GadgetID = ID_HIDE;
ng.ng_GadgetText = "_Hide";
ng.ng_LeftEdge += ng.ng_Width + INTERWIDTH;
cp->ffWinGads[ID_HIDE] = gadget = CreateGadget( BUTTON_KIND, gadget, &ng,
GT_Underscore, '_',
TAG_DONE );
ng.ng_GadgetID = ID_QUIT;
ng.ng_GadgetText = "_Quit";
ng.ng_LeftEdge += ng.ng_Width + INTERWIDTH;
cp->ffWinGads[ID_QUIT] = gadget = CreateGadget( BUTTON_KIND, gadget, &ng,
GT_Underscore, '_',
TAG_DONE );
}
void
CenterWindow( struct Screen *sc, WORD *leftEdge, WORD *topEdge )
{
(*leftEdge) = sc->MouseX - (FF_WIDTH >> 1);
(*topEdge) = sc->MouseY - (FF_HEIGHT >> 1);
while((*leftEdge) + FF_WIDTH > sc->Width)
(*leftEdge)--;
while((*leftEdge) < 0)
(*leftEdge)++;
while((*topEdge) + FF_HEIGHT > sc->Height)
(*topEdge)--;
while((*topEdge) < 0)
(*topEdge)++;
}