static uint32 dispatchAGClass(Class *cl, Object *o, Msg msg) { switch (msg->MethodID) { case OM_NEW: return om_new(cl, o, (struct opSet *)msg); case OM_DISPOSE: return om_dispose(cl, o, msg); case OM_UPDATE: case OM_SET: return om_set(cl, o, (struct opSet *)msg); case OM_GET: return om_get(cl, o, (struct opGet *)msg); case AGM_OPEN: return agm_open(cl, o, msg); case AGM_CLOSE: return agm_close(cl, o, msg); case AGM_PROCESS: return agm_process(cl, o, msg); default: return IIntuition->IDoSuperMethodA(cl, o, msg); } }
uint32 agm_process(Class *cl, Object *o, Msg msg) { struct localObjectData *lod = (struct localObjectData *)INST_DATA(cl, o); uint32 retVal = 0L; if (lod->agHandle) { while ( (lod->agm = IAmigaGuide->GetAmigaGuideMsg(lod->agHandle)) ) { switch (lod->agm->agm_Type) { case ShutdownMsgID: agm_close(cl, o, msg); retVal = 1L; break; default: //printf("%d\n", lod->agm->agm_Type); break; } IAmigaGuide->ReplyAmigaGuideMsg(lod->agm); } } return retVal; }
uint32 om_dispose(Class *cl, Object *o, Msg msg) { // Close the document, should it still be opened. agm_close(cl, o, msg); // Let superclass dispose of the object. return IIntuition->IDoSuperMethodA(cl, o, msg); }
uint32 agm_open(Class *cl, Object *o, Msg msg) { struct localObjectData *lod = (struct localObjectData *)INST_DATA(cl, o); BOOL agActive = FALSE; uint32 retVal = 0L; // Close a previous instance. if ( lod->agHandle ) agm_close(cl, o, msg); // (Re)establish the AmigaGuide context and open the database asynchronously. if ( (lod->agHandle = IAmigaGuide->OpenAmigaGuideAsync(&(lod->nag), NULL)) ) { if ( (lod->agSignal = IAmigaGuide->AmigaGuideSignal(lod->agHandle)) ) { // Wait until the database is displayed and ready. IExec->Wait(lod->agSignal); while ( agActive == FALSE ) { while ( (lod->agm = IAmigaGuide->GetAmigaGuideMsg(lod->agHandle)) ) { // The AmigaGuide process started OK. if ( lod->agm->agm_Type == ActiveToolID ) agActive = TRUE; // Opening the guide file failed for some reason, continue as usual. if ( lod->agm->agm_Type == ToolStatusID && lod->agm->agm_Pri_Ret ) agActive = TRUE; IAmigaGuide->ReplyAmigaGuideMsg(lod->agm); } } if ( lod->nag.nag_Context ) { // A context node array is provided = open the current context node. IAmigaGuide->SetAmigaGuideContext(lod->agHandle, lod->agContextID, NULL); retVal = IAmigaGuide->SendAmigaGuideContext(lod->agHandle, NULL); } else { // No context array is provided = open the main node. retVal = IAmigaGuide->SendAmigaGuideCmd(lod->agHandle, "LINK MAIN", TAG_DONE); } } } return retVal; }
uint32 om_set(Class *cl, Object *o, struct opSet *msg) { struct localObjectData *lod = (struct localObjectData *)INST_DATA(cl, o); struct TagItem *tags, *ti; tags = msg->ops_AttrList; while ((ti = IUtility->NextTagItem (&tags))) { switch (ti->ti_Tag) { case AMIGAGUIDE_Name: lod->nag.nag_Name = (STRPTR)ti->ti_Data; lod->agActive = FALSE; // Database name has changed, we must setup the help system again. break; case AMIGAGUIDE_Screen: lod->nag.nag_Screen = (struct Screen *)ti->ti_Data; lod->agActive = FALSE; // Screen pointer has changed, we must setup the help system again. break; case AMIGAGUIDE_PubScreen: lod->nag.nag_PubScreen = (STRPTR)ti->ti_Data; lod->agActive = FALSE; // Pubscreen name has changed, we must setup the help system again. break; case AMIGAGUIDE_BaseName: lod->nag.nag_BaseName = (STRPTR)ti->ti_Data; lod->agActive = FALSE; // Application basename has changed, we must setup the help system again. break; case AMIGAGUIDE_ContextArray: lod->nag.nag_Context = (STRPTR *)ti->ti_Data; lod->agActive = FALSE; // Context array has changed, we must setup the help system again. break; case AMIGAGUIDE_ContextID: lod->agContextID = (uint32)ti->ti_Data; break; default: break; } } // Setup the help system, if not ready yet or needs changing. if ( lod->agActive == FALSE ) { // Shut down help system should it already be running. if ( lod->agHandle ) agm_close(cl, o, (Msg)msg); // (Re)establish the AmigaGuide context and open the database asynchronously. if ( (lod->agHandle = IAmigaGuide->OpenAmigaGuideAsync(&(lod->nag), NULL)) ) { if ( (lod->agSignal = IAmigaGuide->AmigaGuideSignal(lod->agHandle)) ) { // Wait until the help system is up and running. IExec->Wait(lod->agSignal); while ( !(lod->agActive) ) { while ( (lod->agm = IAmigaGuide->GetAmigaGuideMsg(lod->agHandle)) ) { // The AmigaGuide process started OK. if ( lod->agm->agm_Type == ActiveToolID ) lod->agActive = TRUE; // Opening the guide file failed for some reason, continue as usual. if ( lod->agm->agm_Type == ToolStatusID && lod->agm->agm_Pri_Ret ) lod->agActive = TRUE; IAmigaGuide->ReplyAmigaGuideMsg(lod->agm); } } } } } return (uint32)lod->agHandle; }