home *** CD-ROM | disk | FTP | other *** search
- #include <string.h>
- #include "minmax.h"
- #include "ScrollingList.h"
- #include "ScrollingListClass.h"
- #include "EmbossedGadgetClass.h"
- #include "precognition.h"
- #ifndef __GNUC__
- #include <clib/exec_protos.h>
- #include <clib/intuition_protos.h>
- #include <clib/graphics_protos.h>
- #endif
- #ifdef __GNUC__
- #include <proto/exec.h>
- #include <proto/intuition.h>
- #include <proto/graphics.h>
- #endif
- #ifdef __SASC
- #include <proto/exec.h>
- #include <proto/intuition.h>
- #include <proto/graphics.h>
- #endif
- #include "amigamem.h"
-
- #define CHAR_WIDTH 8 /* Width of Topaz 80 font. */
- #define CHAR_HEIGHT 9 /* Height of Topaz 80 font. */
- #define BROWSER_ENTRY_HEIGHT (CHAR_HEIGHT + 1)
- #define BORDER_WIDTH 3
- #define BASELINE 7
-
-
- void ScrollingList_SetKnobInfo( ScrollingList *self )
- {
- USHORT position, knobsize, nElts, nRows;
-
- nElts = self->list.List.nEntries;
-
- if( nElts == 0 )
- {
- position = 0;
- knobsize = 0xFFFF;
- }
- else
- {
- nRows = self->list.nRows;
-
- position = ( (ULONG) self->list.YOffset << 16 ) / nElts;
-
- if( nElts <= nRows )
- {
- knobsize = 0xFFFF;
- }
- else
- {
- knobsize = ( (ULONG) nRows << 16 ) / nElts;
- }
- }
- SetKnobSize( (Positioner *)&self->vscroller, knobsize );
- SetValue( (Valuator *)&self->vscroller, position );
- }
-
-
- void ScrollingList_PositionList( ScrollingList *self )
- {
- USHORT position, /* Position of self->vscroller. */
- new_YOffset, /* new list YOffset. */
- nElts, /* # of elements in list. */
- nRows, /* # of rows in display */
- range; /* range of positions for YOffset */
-
- ULONG temp;
-
- nElts = self->list.List.nEntries;
-
- if( nElts )
- {
- nRows = self->list.nRows;
-
- if( ( range = nElts - nRows +1 ) > 0 )
- {
- position = Value( (Valuator *)&self->vscroller );
-
- temp = position * range;
- new_YOffset = temp >> 16;
- new_YOffset = MIN( new_YOffset, nElts -1 );
-
- if( new_YOffset != self->list.YOffset )
- {
- self->list.YOffset = new_YOffset;
- Refresh( (Interactor *)&self->list );
- }
- }
- }
- }
-
-
- void ScrollingList_Init( ScrollingList *self,
- PIXELS LeftEdge,
- PIXELS TopEdge,
- PIXELS Width,
- PIXELS Height,
- pcg_3DPens Pens,
- BOOL SelectMany )
- {
- Gadget *g;
-
- StringLister_Init( (StringLister *)self );
- self->slister.isa = ScrollingListClass();
- self->Pens = Pens;
-
- ListBrowser_Init( &self->list, 0,0, 0,0, Pens, SelectMany );
-
- VScroller_Init( &self->vscroller, 0,0, Height, Pens, NULL );
-
- for ( g = FirstGadget( (Interactor *)&self->list );
- g->NextGadget != NULL;
- g = g->NextGadget );
-
- g->NextGadget = FirstGadget( (Interactor *)&self->vscroller );
- self->list.eg.Next = &self->vscroller;
-
- SetSize( (GraphicObject *)self, Width, Height );
- SetLocation( (GraphicObject *)self, LeftEdge, TopEdge );
- }
-
- void ScrollingList_CleanUp( ScrollingList *self )
- {
- CleanUp( (PObject *)&self->list );
- CleanUp( (PObject *)&self->vscroller );
- }
-
- USHORT ScrollingList_nGadgets( ScrollingList *self )
- {
- return( (USHORT)( nGadgets( (Interactor *)&self->list ) +
- nGadgets( (Interactor *)&self->vscroller ) ) );
- }
-
- Gadget *ScrollingList_FirstGadget( ScrollingList *self )
- {
- return FirstGadget( (Interactor *)&self->list );
- }
-
- Point ScrollingList_AskSize( ScrollingList *self,
- PIXELS Width,
- PIXELS Height )
- {
- Point size, list_size, vscroller_size;
-
- vscroller_size = AskSize( (GraphicObject *)&self->vscroller, Width, Height );
- /* vscroller's have a fixed width */
-
- list_size.x = Width - vscroller_size.x;
- list_size.y = vscroller_size.y;
-
- list_size = AskSize( (GraphicObject *)&self->list, list_size.x, list_size.y );
-
- size.x = list_size.x + vscroller_size.x;
- size.y = list_size.y;
-
- return size;
- }
-
-
- Point ScrollingList_SetSize( ScrollingList *self,
- PIXELS Width,
- PIXELS Height )
- {
- Point size, list_size, vscroller_size;
-
- size = AskSize( (GraphicObject *)self, Width, Height );
-
- vscroller_size = SetSize( (GraphicObject *)&self->vscroller, size.x, size.y );
- list_size = SetSize( (GraphicObject *)&self->list, size.x - vscroller_size.x, size.y );
- self->slister.Size = size;
-
- SetLocation( (GraphicObject *)self, self->slister.Location.x, self->slister.Location.y );
- ScrollingList_SetKnobInfo( self );
-
- return size;
- }
-
- Point ScrollingList_SetLocation( ScrollingList *self,
- PIXELS LeftEdge,
- PIXELS TopEdge )
- {
- Point size, location;
-
- size = Size( (GraphicObject *)&self->list );
- SetLocation( (GraphicObject *)&self->list, LeftEdge, TopEdge );
- SetLocation( (GraphicObject *)&self->vscroller, LeftEdge+size.x, TopEdge );
-
- location.x = LeftEdge;
- location.y = TopEdge;
- self->slister.Location = location;
-
- return location;
- }
-
-
- USHORT ScrollingList_SetYOffset( ScrollingList *self,
- USHORT YOffset )
- {
- return ListBrowser_SetYOffset( &self->list, YOffset );
- }
-
-
- void ScrollingList_Render( ScrollingList *self,
- RastPort *RPort )
- {
- Render( (GraphicObject *)&self->list, RPort );
- Render( (GraphicObject *)&self->vscroller, RPort );
- }
-
-
- void ScrollingList_SelectAll( ScrollingList *self, BOOL Select )
- /* Selects or deselects everything in the list. */
- {
- ListBrowser_SelectAll( &self->list, Select );
- }
-
-
- const StringList *ScrollingList_StringList_of( ScrollingList *self )
- {
- return StringList_of( (StringLister *)&self->list );
- }
-
- /* Changed to BOOL from void -- EDB */
- BOOL ScrollingList_AddString( ScrollingList *self,
- char *entry,
- UBYTE qualifier )
- {
- BOOL test = FALSE;
- test = AddString( (StringLister *)&self->list, entry, qualifier );
- ScrollingList_SetKnobInfo( self );
- return test; /* added return -- EDB */
- }
-
-
- /* Changed to BOOL from void -- EDB */
- BOOL ScrollingList_DeleteString( ScrollingList *self,
- USHORT entry )
- {
- BOOL test = FALSE;
- test = DeleteString( (StringLister *)&self->list, entry );
- ScrollingList_SetKnobInfo( self );
- return test; /* added return -- EDB */
- }
-
- /* Changed to BOOL from void -- EDB */
- BOOL ScrollingList_DeleteAllStrings( ScrollingList *self )
- {
- BOOL test = FALSE;
- test = DeleteAllStrings( (StringLister *)&self->list );
- ScrollingList_SetKnobInfo( self );
- return test; /* added return -- EDB */
- }
-
- void ScrollingList_SelectString( ScrollingList *self,
- USHORT entry,
- BOOL Select )
- {
- SelectString( (StringLister *)&self->list, entry, Select );
- }
-
-
- void ScrollingList_Refresh( Interactor *us )
- {
- ScrollingList *self = NULL;
- self = (ScrollingList *)us;
- Refresh( (Interactor *)&self->list );
- Refresh( (Interactor *)&self->vscroller );
- }
-
- USHORT ScrollingList_ClaimEvent( ScrollingList *self,
- IntuiMessage *event )
- {
- return( (USHORT)( ClaimEvent( (Interactor *)&self->list,event )
- | ClaimEvent( (Interactor *)&self->vscroller, event ) ) );
- }
-
-
- #define CLAIM_EVENT(b,e) ( &b->g == (Gadget *)e->IAddress )
-
- USHORT ScrollingList_Respond( ScrollingList *self,
- IntuiMessage *Event )
- {
- USHORT list_response;
- USHORT vscroller_response = 0;
-
- list_response = Respond( (Interactor *)&self->list, Event );
-
- if( ! ( list_response & CONSUMED_EVENT ) )
- {
- vscroller_response = Respond( (Interactor *)&self->vscroller, Event );
- if( vscroller_response & CHANGED_STATE )
- {
- ScrollingList_PositionList( self );
- /* scroll list */
- vscroller_response = RESPONDED; /* Don't propagate the CHANGED_STATE. */
- }
- }
- return( (USHORT)( list_response | vscroller_response ) );
- }
-
-
- void ScrollingList_SetInteractorWindow( ScrollingList *self,
- pcgWindow *window )
- {
- self->slister.IaWindow = window;
- SetInteractorWindow( (Interactor *)&self->list, window );
- SetInteractorWindow( (Interactor *)&self->vscroller, window );
- }
-
- ULONG ScrollingList_IDCMPFlags( ScrollingList *self )
- {
- return IDCMPFlags( (Interactor *)&self->list ) |
- IDCMPFlags( (Interactor *)&self->vscroller );
- }
-
- BOOL ScrollingList_EnableIactor( ScrollingList *self, BOOL enable )
- {
- EnableIactor( (Interactor *)&self->list, enable );
- EnableIactor( (Interactor *)&self->vscroller, enable );
- return enable;
- }
-
-
- BOOL ScrollingList_elaborated = FALSE;
-
- struct StringListerClass ScrollingList_Class;
-
- void ScrollingListClass_Init( struct StringListerClass *class )
- {
- StringListerClass_Init( class );
- class->isa = StringListerClass();
- class->CleanUp = (void(*)(PObject *))ScrollingList_CleanUp;
- class->ClassName = "ScrollingList";
- class->AskSize = (Point(*)(GraphicObject *, PIXELS, PIXELS))ScrollingList_AskSize;
- class->SetSize = (Point(*)(GraphicObject *, PIXELS, PIXELS))ScrollingList_SetSize;
- class->SetLocation = (Point(*)(GraphicObject *, PIXELS, PIXELS))ScrollingList_SetLocation;
- class->Respond = (USHORT(*)(Interactor *, IntuiMessage *))ScrollingList_Respond;
- class->Refresh = (void(*)(Interactor *))ScrollingList_Refresh;
- class->Render = (void(*)(GraphicObject *, RastPort *))ScrollingList_Render;
- class->ClaimEvent = (USHORT(*)(Interactor *, IntuiMessage *))ScrollingList_ClaimEvent;
- class->nGadgets = (USHORT(*)(Interactor *))ScrollingList_nGadgets;
- class->FirstGadget = (Gadget*(*)(Interactor *))ScrollingList_FirstGadget;
- class->SetInteractorWindow = (void(*)(Interactor *, struct pcgWindow *))ScrollingList_SetInteractorWindow;
- class->IDCMPFlags = (ULONG(*)(Interactor *))ScrollingList_IDCMPFlags;
- class->isEnabled = (BOOL(*)(Interactor *))EmbossedGadget_isEnabled;
- class->EnableIactor = (BOOL(*)(Interactor *, BOOL))ScrollingList_EnableIactor;
-
- class->StringList_of = (StringList*(*)(StringLister *))ScrollingList_StringList_of;
- class->AddString = (BOOL(*)(StringLister *, char *, UBYTE))ScrollingList_AddString;
- class->DeleteString = (BOOL(*)(StringLister *, USHORT))ScrollingList_DeleteString;
- class->DeleteAllStrings = (BOOL(*)(StringLister *))ScrollingList_DeleteAllStrings;
- class->SelectString = (void(*)(StringLister *, USHORT, BOOL))ScrollingList_SelectString;
-
- }
-
-
-
- struct StringListerClass *ScrollingListClass( void )
- {
- if( ! ScrollingList_elaborated )
- {
- ScrollingListClass_Init( &ScrollingList_Class );
- ScrollingList_elaborated = TRUE;
- }
-
- return &ScrollingList_Class;
- }
-