home *** CD-ROM | disk | FTP | other *** search
-
- /*
- **
- ** $VER: classbase.c 1.3 (12.10.97)
- ** embed.datatype 1.3
- **
- ** Library routines for a DataTypes class
- **
- ** Written 1996/1997 by Roland 'Gizzy' Mainz
- ** Original example source from David N. Junod
- **
- */
-
-
- /* main includes */
- #include "classbase.h"
-
-
- /****** embed.datatype/--datasheed-- *****************************************
- *
- * NAME
- * embed.datatype -- data type which embeds other objects
- *
- * SUPERCLASS
- * text.datatype
- *
- * FUNCTION
- * The embed data type, a sub-class of the text.datatype, is used
- * to view documents with embedded datatypes objects.
- *
- * METHODS
- * OM_NEW -- Create a new text object from a embed document file. The
- * source may only be a file.
- *
- * OM_GET -- The DTA_Methods attribute is created from local context.
- *
- * GM_GOACTIVE
- * GM_GOINACTIVE
- * DTM_CLEARSELECTED --
- *
- * DTM_TRIGGER --
- *
- * ATTRIBUTES
- * DTA_Methods -- Set to the supported set of methods, based
- * on the set got from the superclass, extended with methods
- * got from members.
- *
- + DTA_TriggerMethods -- Set of trigger methods
- *
- * BUGS
- * Horrors !
- *
- * - The text rendered by text.datatype ignores and "height" in the
- * line node, this results in a crazy display of text.
- * The embedded objects are shown correctly.
- *
- * - Inside GM_HANDLEINPUT: Return codes GMR_PREVACTIVE and
- * GMR_NEXTACTIVE are not supported yet; the usage of string
- * gadgets is limmited therefore :-(
- *
- * - A line box is drawn around each datatype, but the line is
- * outside of the gadget box set in the struct Line node.
- * A result of this inconsisteny may be an overwritten
- * window border.
- *
- * - Embedding the document itself causes an endless loop until
- * memory is full (then the datatypes waits for more memory...).
- *
- * - A new stack frame is allocated for each method; a smarter
- * stack managing scheme should be used.
- *
- * - animation.datatype has problems when calculating the
- * gadget box for it's tapedeck.gadget.
- * This works usually fine, but sometimes a small part of the
- * left border will be overwritten.
- *
- * - Trigger methods are send as a broadcast method to all
- * members instead to specific ones.
- *
- * - DTM_PRINT, DTM_COPY, DTM_WRITE etc. are currently not supported.
- *
- *
- * HISTORY
- * V1.1
- * Released to dta@amigaworld.com mailinglist for comments.
- *
- * V1.2
- * - Implemented own GM_RENDER, which supersets text.datatypes rendering
- * completely.
- *
- * - Minor corrections
- *
- * V1.3
- * - Recompiled with SAS/C 6.58
- *
- * - Added missing WaitBlit in GM_RENDER.
- *
- * - AllocBitMap used for Line rebdering now uses BMF_MINPLANES and a
- * friend bitmap.
- *
- * - Internal DescroyVisibleList now sets the object's domain box to
- * { SHRT_MAX, SHRT_MAX, 0, 0 } instead of { 0, 0, 0, 0 }.
- *
- * This should fix problems if a datatypes class has problems with
- * clipping (e.g. 0 width and/or height).
- *
- * - Fixed (hopefully) the bug that the box EraseRect'ed at GM_RENDER
- * was 1 pixel in x/y too large.
- *
- * - Now implements correct usage of DTSIF_LAYOUT. This avoids
- * rendering and other unwanted actions during layout (e.g. this
- * reduces flickering).
- *
- * - Now a black box is drawn around the object. This feature can be
- * turned off at compile time by disableing the
- * DRAW_BOX_AROUND_OBJECT define cpp statement.
- * A 0-color box would be more usefull if HAM pictures/anims are
- * shown (ide taken from cdgxl).
- *
- *
- * NOTES
- *
- * SEE ALSO
- * text.datatype, amigaguide.datatype,
- * document.datatype
- *
- *******************************************************************************
- *
- */
-
- /*****************************************************************************/
-
- /* local prototypes */
- static struct ClassLibrary *OpenClassLibrary( struct ClassBase *, STRPTR, ULONG );
-
- /*****************************************************************************/
-
- DISPATCHERFLAGS
- struct IClass *ObtainEmbedEngine( REGA6 struct ClassBase *cb )
- {
- return( (cb -> cb_Lib . cl_Class) );
- }
-
- /*****************************************************************************/
-
- DISPATCHERFLAGS
- struct Library *LibInit( REGD0 struct ClassBase *cb, REGA0 BPTR seglist, REGA6 struct ExecBase *sysbase )
- {
- cb -> cb_SegList = seglist;
- cb -> cb_SysBase = sysbase;
-
- InitSemaphore( (&(cb -> cb_Lock)) );
-
- if( (cb -> cb_SysBase -> LibNode . lib_Version) >= 39UL )
- {
- /* Obtain ROM libs */
- if( cb -> cb_IntuitionBase = OpenLibrary( "intuition.library", 39UL ) )
- {
- if( cb -> cb_GfxBase = OpenLibrary( "graphics.library", 39UL ) )
- {
- if( cb -> cb_DOSBase = OpenLibrary( "dos.library", 39UL ) )
- {
- if( cb -> cb_UtilityBase = OpenLibrary( "utility.library", 39UL ) )
- {
- return( (&(cb -> cb_Lib . cl_Lib)) );
-
- #ifdef COMMENTED_OUT
- CloseLibrary( UtilityBase );
- #endif /* COMMENTED_OUT */
- }
-
- CloseLibrary( DOSBase );
- }
-
- CloseLibrary( GfxBase );
- }
-
- CloseLibrary( IntuitionBase );
- }
- }
-
- return( NULL );
- }
-
- /*****************************************************************************/
-
- DISPATCHERFLAGS
- LONG LibOpen( REGA6 struct ClassBase *cb )
- {
- LONG retval = (LONG)cb;
- BOOL success = TRUE;
-
- ObtainSemaphore( (&(cb -> cb_Lock)) );
-
- /* Use an internal use counter */
- cb -> cb_Lib . cl_Lib . lib_OpenCnt++;
- cb -> cb_Lib . cl_Lib . lib_Flags &= ~LIBF_DELEXP;
-
- if( (cb -> cb_Lib . cl_Lib . lib_OpenCnt) == 1U )
- {
- if( (cb -> cb_Lib . cl_Class) == NULL )
- {
- success = FALSE;
-
- if( cb -> cb_DataTypesBase = OpenLibrary( "datatypes.library", 39UL ) )
- {
- if( cb -> cb_SuperClassBase = OpenLibrary( "datatypes/text.datatype", 39UL ) )
- {
- cb -> cb_CalendarBase = OpenClassLibrary( cb, "gadgets/calendar.gadget", 37UL );
-
- success = initClass( cb );
- }
- }
- }
- }
-
- if( !success )
- {
- CloseLibrary( (&(cb -> cb_CalendarBase -> cl_Lib)) );
- CloseLibrary( (cb -> cb_SuperClassBase) );
- CloseLibrary( (cb -> cb_DataTypesBase) );
-
- cb -> cb_DataTypesBase = cb -> cb_SuperClassBase = NULL;
- cb -> cb_CalendarBase = NULL;
-
- (cb -> cb_Lib . cl_Lib . lib_OpenCnt)--;
-
- retval = 0L;
- }
-
- ReleaseSemaphore( (&(cb -> cb_Lock)) );
-
- return( retval );
- }
-
- /*****************************************************************************/
-
- DISPATCHERFLAGS
- LONG LibClose( REGA6 struct ClassBase *cb )
- {
- LONG retval = 0L;
-
- ObtainSemaphore( (&(cb -> cb_Lock)) );
-
- if( cb -> cb_Lib . cl_Lib . lib_OpenCnt )
- {
- (cb -> cb_Lib . cl_Lib . lib_OpenCnt)--;
- }
-
- if( ((cb -> cb_Lib . cl_Lib . lib_OpenCnt) == 0U) && (cb -> cb_Lib . cl_Class) )
- {
- if( FreeClass( (cb -> cb_Lib . cl_Class) ) )
- {
- cb -> cb_Lib . cl_Class = NULL;
-
- /* Ignores FreeClass return value because there are no embed models without embedclass objects */
- (void)FreeClass( (cb -> cb_EmbedModel) );
- cb -> cb_EmbedModel = NULL;
-
- CloseLibrary( (&(cb -> cb_CalendarBase -> cl_Lib)) );
- CloseLibrary( (cb -> cb_SuperClassBase) );
- CloseLibrary( (cb -> cb_DataTypesBase) );
- }
- else
- {
- cb -> cb_Lib . cl_Lib . lib_Flags |= LIBF_DELEXP;
- }
- }
-
- ReleaseSemaphore( (&(cb -> cb_Lock)) );
-
- if( (cb -> cb_Lib . cl_Lib . lib_Flags) & LIBF_DELEXP )
- {
- retval = LibExpunge( cb );
- }
-
- return( retval );
- }
-
- /*****************************************************************************/
-
- DISPATCHERFLAGS
- LONG LibExpunge( REGA6 struct ClassBase *cb )
- {
- BPTR seg;
-
- if( cb -> cb_Lib . cl_Lib . lib_OpenCnt )
- {
- cb -> cb_Lib . cl_Lib . lib_Flags |= LIBF_DELEXP;
-
- seg = NULL;
- }
- else
- {
- Remove( (&(cb -> cb_Lib . cl_Lib . lib_Node)) );
-
- seg = cb -> cb_SegList;
-
- CloseLibrary( (cb -> cb_UtilityBase) );
- CloseLibrary( (cb -> cb_DOSBase) );
- CloseLibrary( (cb -> cb_GfxBase) );
- CloseLibrary( (cb -> cb_IntuitionBase) );
-
- FreeMem( (APTR)((ULONG)(cb) - (ULONG)(cb -> cb_Lib . cl_Lib . lib_NegSize)), (ULONG)((cb -> cb_Lib . cl_Lib . lib_NegSize) + (cb -> cb_Lib . cl_Lib . lib_PosSize)) );
- }
-
- return( (LONG)seg );
- }
-
-
- /* Try opening the class library from a number of common places. Adapted from CALENDAR_TEST.c/openclass */
- static
- struct ClassLibrary *OpenClassLibrary( struct ClassBase *cb, STRPTR name, ULONG version )
- {
- struct Library *retval;
- UBYTE buffer[ 512 ];
-
- if( (retval = OpenLibrary( name, version ) ) == NULL )
- {
- mysprintf( cb, buffer, ":classes/%s", name );
-
- if( (retval = OpenLibrary( buffer, version ) ) == NULL )
- {
- mysprintf( cb, buffer, "classes/%s", name );
-
- retval = OpenLibrary( buffer, version );
- }
- }
-
- return( (struct ClassLibrary *)retval );
- }
-
-
-