/*** JanoPrefs wants some additionnal information ***/ ULONG change_screen_mode(WORD *whd, ULONG ModeID) #endif { struct ScreenModeRequester *smr; if((smr = (void *) AllocAslRequestTags(ASL_ScreenModeRequest, ASLSM_DoWidth, FALSE, ASLSM_DoHeight, FALSE, ASLSM_DoAutoScroll, FALSE, ASLSM_DoOverscanType, FALSE, ASLSM_DoDepth, TRUE, ASLSM_InitialDisplayID, ModeID, ASLFR_Screen, (ULONG)Scr, TAG_DONE) )) { if( AslRequest(smr,NULL) ) { /* Extract some interresting information about screen */ #ifndef JANOPREF *Depth = smr->sm_DisplayDepth; #else whd[0] = smr->sm_DisplayWidth; whd[1] = smr->sm_DisplayHeight; whd[2] = smr->sm_DisplayDepth; #endif ModeID = smr->sm_DisplayID; } else ModeID = INVALID_ID; FreeAslRequest(smr); return ModeID; } return INVALID_ID; }
/*** Ask for a new font, fixed or not ***/ struct TextFont *change_fonts(struct TextAttr *buf, void *Wnd, BOOL fixed) { struct FontRequester *fr; struct TextFont *newfont = NULL; if((fr = (void *) AllocAslRequestTags(ASL_FontRequest, ASLFO_FixedWidthOnly, fixed, ASLFO_SleepWindow, TRUE, ASLFO_InitialName, (ULONG)buf->ta_Name, ASLFO_InitialSize, buf->ta_YSize, ASLFO_Window, (ULONG)Wnd, TAG_DONE))) { if( AslRequest(fr, NULL) ) { /* User may hit cancel! */ newfont = (void *) OpenDiskFont( &fr->fo_Attr ); if( newfont ) { CopyMem(&fr->fo_Attr, buf, sizeof(*buf)); /* The ta_Name field will be freed with FreeAslRequest call ! */ buf->ta_Name = newfont->tf_Message.mn_Node.ln_Name; } else ThrowError(Wnd, ErrMsg(ERR_LOADFONT)); } FreeAslRequest(fr); /* Window will be reinitiated later... */ } return newfont; }
// Solicit a font short request_font( struct Window *parent, char *title, char *buffer, short *size, ULONG flags, unsigned short font_pen_count, unsigned char *font_pen_table, short *fpen, short *bpen) { struct IBox coords; struct FontRequester *fontreq; short ret; // Get current requester coordinates GetSemaphore(&GUI->req_lock,SEMF_SHARED,0); coords=GUI->req_coords; FreeSemaphore(&GUI->req_lock); // Allocate fontrequester if (!(fontreq=AllocAslRequestTags(ASL_FontRequest, ASLFO_Window,parent, ASLFO_TitleText,title, ASLFO_InitialName,buffer, ASLFO_InitialSize,*size, ASLFO_Flags,flags|FOF_PRIVATEIDCMP, ASLFO_InitialLeftEdge,coords.Left, ASLFO_InitialTopEdge,coords.Top, ASLFO_InitialWidth,coords.Width, ASLFO_InitialHeight,coords.Height, ASLFO_MaxFrontPen,font_pen_count, ASLFO_MaxBackPen,font_pen_count, ASLFO_FrontPens,font_pen_table, ASLFO_BackPens,font_pen_table, ASLFO_InitialFrontPen,(fpen)?*fpen:0, ASLFO_InitialBackPen,(bpen)?*bpen:0, TAG_END))) { return 0; } // Display requester ret=AslRequest(fontreq,0); // Success? if (ret) { // Store new font strcpy(buffer,fontreq->fo_Attr.ta_Name); *size=fontreq->fo_Attr.ta_YSize; // Store colours if (fpen) *fpen=map_font_colour(fontreq->fo_FrontPen); if (bpen) *bpen=map_font_colour(fontreq->fo_BackPen); } // Save coordinates GetSemaphore(&GUI->req_lock,SEMF_EXCLUSIVE,0); GUI->req_coords=*((struct IBox *)&fontreq->fo_LeftEdge); FreeSemaphore(&GUI->req_lock); // Free font requester FreeAslRequest(fontreq); return ret; }
// Solicit a file request_file( struct Window *parent, char *title, char *buffer, char *def, ULONG flags, char *pattern) { struct IBox coords; struct FileRequester *filereq; char *path,*file=0; int ret; // Allocate path if (!(path=AllocVec(300,MEMF_CLEAR))) return 0; // Get current path if (buffer[0]) strcpy(path,buffer); else if (def) strcpy(path,def); if (path[0]) { file=FilePart(path); if (file && file>path) { strcpy(path+256,file); *file=0; file=path+256; } } // Get current requester coordinates GetSemaphore(&GUI->req_lock,SEMF_SHARED,0); coords=GUI->req_coords; FreeSemaphore(&GUI->req_lock); // Allocate filerequester if (!(filereq=AllocAslRequestTags(ASL_FileRequest, (flags&(1<<30))?ASLFR_Screen:ASLFR_Window,parent, ASLFR_TitleText,title, (file)?ASLFR_InitialFile:TAG_IGNORE,file, (*path)?ASLFR_InitialDrawer:TAG_IGNORE,path, ASLFR_Flags1,(flags|FRF_PRIVATEIDCMP)&~((1<<31)|(1<<30)|(1<<29)), ASLFR_Flags2,(flags&(1<<31))?0:FRF_REJECTICONS, ASLFR_InitialLeftEdge,coords.Left, ASLFR_InitialTopEdge,coords.Top, ASLFR_InitialWidth,coords.Width, ASLFR_InitialHeight,coords.Height, (flags&(1<<29))?ASLFR_InitialPattern:TAG_IGNORE,pattern, TAG_END))) { FreeVec(path); return 0; } // Display requester ret=AslRequest(filereq,0); // Build path strcpy(buffer,filereq->fr_Drawer); AddPart(buffer,filereq->fr_File,256); if (!*buffer || !*filereq->fr_File) ret=0; // Save coordinates GetSemaphore(&GUI->req_lock,SEMF_EXCLUSIVE,0); GUI->req_coords=*((struct IBox *)&filereq->fr_LeftEdge); FreeSemaphore(&GUI->req_lock); // Free file requester FreeAslRequest(filereq); FreeVec(path); return ret; }
ULONG _AHIsub_Start( ULONG Flags, struct AHIAudioCtrlDrv *AudioCtrl, struct DriverBase* AHIsubBase ) { struct FilesaveBase* FilesaveBase = (struct FilesaveBase*) AHIsubBase; AHIsub_Stop(Flags, AudioCtrl); if(Flags & AHISF_PLAY) { ULONG savebufferlength; if(!(dd->fs_MixBuffer = AllocVec(AudioCtrl->ahiac_BuffSize, MEMF_ANY))) return AHIE_NOMEM; dd->fs_SaveBufferSize = AudioCtrl->ahiac_MaxBuffSamples; // S16 has two buffers (L/R) instead if((AudioCtrl->ahiac_Flags & AHIACF_STEREO) && dd->fs_Format != FORMAT_S16) { dd->fs_SaveBufferSize <<=1; } if(dd->fs_SaveBufferSize < SAVEBUFFERSIZE) { dd->fs_SaveBufferSize = SAVEBUFFERSIZE; } savebufferlength = dd->fs_SaveBufferSize; switch(dd->fs_Format) { case FORMAT_8SVX: break; case FORMAT_AIFF: savebufferlength <<= 1; break; case FORMAT_AIFC: savebufferlength <<= 1; break; case FORMAT_S16: savebufferlength <<= 1; break; case FORMAT_WAVE: savebufferlength <<= 1; break; default: break; } if(!(dd->fs_SaveBuffer = AllocVec(savebufferlength, MEMF_ANY))) { return AHIE_NOMEM; } if ((AudioCtrl->ahiac_Flags & AHIACF_STEREO) && dd->fs_Format == FORMAT_S16) { if(!(dd->fs_SaveBuffer2 = AllocVec(savebufferlength, MEMF_ANY))) { return AHIE_NOMEM; } } if(AslRequest(dd->fs_FileReq,NULL)) { struct TagItem proctags[] = { { NP_Entry, (ULONG) SlaveEntry }, { NP_Name, (ULONG) LibName }, { NP_Priority, -1 }, // It's a number cruncher... { NP_StackSize, 10000, }, { TAG_DONE, 0 } }; Forbid(); dd->fs_SlaveTask = CreateNewProc( proctags ); if( dd->fs_SlaveTask != NULL ) { dd->fs_SlaveTask->pr_Task.tc_UserData = AudioCtrl; } Permit(); if(dd->fs_SlaveTask) { Wait(1L<<dd->fs_MasterSignal); // Wait for slave to come alive if(dd->fs_SlaveTask == NULL) // Is slave alive or dead? { return AHIE_UNKNOWN; } } else { return AHIE_NOMEM; } } else { if(IoErr()) { return AHIE_NOMEM; //error occured } else { return AHIE_ABORTED; //requester cancelled } } } if(Flags & AHISF_RECORD) { if(!(dd->fs_RecBuffer = AllocVec(RECBUFFERSIZE*4,MEMF_ANY))) { return AHIE_NOMEM; } if(AslRequest(dd->fs_RecFileReq,NULL)) { struct TagItem proctags[] = { { NP_Entry, (ULONG) RecSlaveEntry }, { NP_Name, (ULONG) LibName }, { NP_Priority, 1 }, // Make it steady... { TAG_DONE, 0 } }; Delay(TICKS_PER_SECOND); // Wait for window to close etc... Forbid(); dd->fs_RecSlaveTask = CreateNewProc( proctags ); if( dd->fs_RecSlaveTask != NULL ) { dd->fs_RecSlaveTask->pr_Task.tc_UserData = AudioCtrl; } Permit(); if(dd->fs_RecSlaveTask) { Wait(1L<<dd->fs_RecMasterSignal); // Wait for slave to come alive if(dd->fs_RecSlaveTask == NULL) // Is slave alive or dead? { return AHIE_UNKNOWN; } } else { return AHIE_NOMEM; } } else { if(IoErr()) { return AHIE_NOMEM; //error occured } else { return AHIE_ABORTED; //requester cancelled } } } return AHIE_OK; }
// varargs AslRequestTags BOOL __stdargs AslRequestTags( APTR req, Tag tag1,...) { return AslRequest(req,(struct TagItem *)&tag1); }
void FunctionEditor(void) { struct IntuiMessage *gmsg,msg; int break_flag=0; UWORD gadgetid=0; ULONG waitbits; FuncEdData *data; IPCData *ipc; NewConfigWindow newwin; FunctionStartup *startup=0; IPCMessage *submsg; int success=0; BOOL open_window=1; BPTR lock; ConfigWindow windims; // Do startup if (!(ipc=Local_IPC_ProcStartup((ULONG *)&startup, (APTR)&funced_init))) { funced_cleanup(startup->data); return; } // Get data pointer data=startup->data; // Lock RAM: and CD to it if ((lock=Lock("ram:",ACCESS_READ))) lock=CurrentDir(lock); // Copy dimensions if (startup->flags&FUNCEDF_CENTER) windims=_function_editor_window_center; else if (startup->flags&FUNCEDF_LABEL) windims=_function_editor_label_window; else windims=_function_editor_window; // Fill in new window newwin.parent=startup->window; newwin.dims=&windims; newwin.title=(startup->title[0])?startup->title:(char *)GetString(startup->locale,MSG_FUNCED_TITLE); newwin.locale=startup->locale; newwin.port=0; newwin.flags=WINDOW_VISITOR|WINDOW_AUTO_KEYS|WINDOW_REQ_FILL;//|WINDOW_SIZE_BOTTOM; newwin.font=0; // Build flag list funced_build_flaglist(data); waitbits=1<<ipc->command_port->mp_SigBit|1<<data->drag.timer->port->mp_SigBit; // Event loop FOREVER { // Check drag if (config_drag_check(&data->drag)) { // End drag functioned_end_drag(data,0); } // Task message? while ((submsg=(IPCMessage *)GetMsg(ipc->command_port))) { // Close message? if (submsg->command==IPC_QUIT) { // Keep changes? success=submsg->flags; // Set break flag break_flag=1; } // Activate else if (submsg->command==IPC_ACTIVATE && data->window) { WindowToFront(data->window); ActivateWindow(data->window); } // Hide else if (submsg->command==IPC_HIDE && data->window) { // Store changes in function funced_store_edits(data); // End any drag in progress functioned_end_drag(data,0); // Remove AppWindow RemoveAppWindow(data->appwindow); data->appwindow=0; // Close window CloseConfigWindow(data->window); // Zero stuff data->window=0; data->objlist=0; waitbits=1<<ipc->command_port->mp_SigBit; } // Show else if (submsg->command==IPC_SHOW && !data->window) { // Set flag to open window open_window=1; newwin.parent=(struct Window *)submsg->data; } // Passed-along app message else if (submsg->command==CFG_APPMESSAGE_PASS) { funced_appmsg(data,submsg->data); ReplyMsg((struct Message *)submsg->data); } // Update our identity else if (submsg->command==CFG_NEW_ID) { data->function->function.func_type=submsg->flags; startup->object_flags=(ULONG)submsg->data; } // Copy a function else if (submsg->command==FUNCTIONEDIT_COPY_LINE) { FunctionEntry *entry,*next; // Copy function functioned_copy_line( data, (FunctionEntry *)submsg->data, 0, (Point *)submsg->data_free); // Free function entry=(FunctionEntry *)submsg->data; while (entry) { // Get next next=(FunctionEntry *)entry->node; // Free entry FreeVec(entry); entry=next; } } // Clip button else if (submsg->command==BUTTONEDIT_CLIP_BUTTON) { Cfg_ButtonFunction *func; // Show busy pointer SetWindowBusy(data->window); // Stop editing funced_end_edit(data,data->edit_node,0,0); data->edit_node=0; // Get first function if ((func=(Cfg_ButtonFunction *) FindFunctionType( (struct List *)&((Cfg_Button *)submsg->data)->function_list, FTYPE_LEFT_BUTTON))) { FunctionEntry dummy; Cfg_Instruction *ins; // Go through instructions for (ins=(Cfg_Instruction *)func->instructions.mlh_Head; ins->node.mln_Succ; ins=(Cfg_Instruction *)ins->node.mln_Succ) { // Fill out dummy entry dummy.type=ins->type; if (ins->string) strcpy(dummy.buffer,ins->string); else dummy.buffer[0]=0; // Copy function line data->edit_node=funced_new_entry(data,0,&dummy); } // Start editing last line funced_start_edit(data); // Get flags data->function->function.flags=func->function.flags; data->function->function.code=func->function.code; data->function->function.qual=func->function.qual; data->function->function.qual_mask=func->function.qual_mask; data->function->function.qual_same=func->function.qual_same; // Update flag list funced_update_flaglist(data); // Update key funced_show_key(data); } // Free button FreeButton((Cfg_Button *)submsg->data); // Clear busy pointer ClearWindowBusy(data->window); } // Reply the message IPC_Reply(submsg); } // Open window? if (open_window) { // Open window if (!(data->window=OpenConfigWindow(&newwin)) || !(data->p_objlist=AddObjectList( data->window, (startup->flags&FUNCEDF_IMAGE)?_function_editor_image_objects: ((startup->flags&FUNCEDF_LABEL)?_function_editor_label_objects: _function_editor_normal_objects))) || !(data->objlist=AddObjectList(data->window,_function_editor_objects))) break; // Add use or save button AddObjectList(data->window,(startup->flags&FUNCEDF_SAVE)?_function_editor_objects_save:_function_editor_objects_use); // Store window for drag data->drag.window=data->window; // Set window ID SetWindowID(data->window,0,WINDOW_FUNCTION_EDITOR,(struct MsgPort *)ipc); // Add menus AddWindowMenus(data->window,_funced_menus); // Make this an AppWindow data->appwindow=AddAppWindowA(0,0,data->window,data->appport,0); // Get waitbits waitbits|=1<<data->window->UserPort->mp_SigBit; if (data->appwindow) waitbits|=1<<data->appport->mp_SigBit; // Disable key? if (startup->flags&FUNCEDF_NO_KEY) { DisableObject(data->objlist,GAD_FUNCED_KEY,TRUE); } // Initialise gadgets with function data. funced_init_gads(data); open_window=0; } // Intuimessage if (data->window) { while ((gmsg=GetWindowMsg(data->window->UserPort))) { Att_Node *node; // Copy message and reply (unless IDCMPUPDATE) msg=*gmsg; if (gmsg->Class!=IDCMP_IDCMPUPDATE) { ReplyWindowMsg(gmsg); gmsg=0; } // Get GadgetID if (msg.Class==IDCMP_GADGETDOWN || msg.Class==IDCMP_GADGETUP) gadgetid=((struct Gadget *)msg.IAddress)->GadgetID; // Look at message switch (msg.Class) { // Key press case IDCMP_VANILLAKEY: // If editing something, activate string gadget if (data->edit_node) ActivateStrGad(GADGET(GetObject(data->objlist,GAD_FUNCED_EDIT)),data->window); break; // Close window case IDCMP_CLOSEWINDOW: // Set break flag break_flag=1; break; // Mouse move case IDCMP_MOUSEMOVE: // Handle drag move config_drag_move(&data->drag); break; // Inactive window does menu down case IDCMP_INACTIVEWINDOW: msg.Code=MENUDOWN; // Mouse buttons case IDCMP_MOUSEBUTTONS: // Valid drag info? if (data->drag.drag) { short ok=-1; // Dropped ok? if (msg.Code==SELECTUP) { // Is shift down? if (msg.Qualifier&(IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT)) data->drag_shift=1; else data->drag_shift=0; // Remember last position data->drag.drag_x=data->window->WScreen->MouseX; data->drag.drag_y=data->window->WScreen->MouseY; ok=1; } // Aborted else if (msg.Code==MENUDOWN) { // Set abort ok=0; } // End drag? if (ok!=-1) functioned_end_drag(data,ok); } break; // Menu case IDCMP_MENUPICK: { struct MenuItem *item; // Get item if (!(item=ItemAddress(data->window->MenuStrip,msg.Code))) break; // Treat as gadget gadgetid=MENUID(item); } // Gadget case IDCMP_GADGETUP: case IDCMP_GADGETDOWN: // Look at gadget ID switch (gadgetid) { // Hotkey case GAD_FUNCED_KEY: { IX ix; char *ptr; // Get key, see if it's invalid if ((ptr=(char *)GetGadgetValue(data->objlist,GAD_FUNCED_KEY)) && *ptr) { // Try to parse if (ParseIX(ptr,&ix)) { // Flash screen DisplayBeep(data->window->WScreen); // Activate key field again ActivateStrGad(GADGET(GetObject(data->objlist,GAD_FUNCED_KEY)),data->window); } else { data->function->function.code=ix.ix_Code; data->function->function.qual=QualValid(ix.ix_Qualifier); data->function->function.qual_mask=ix.ix_QualMask; data->function->function.qual_same=ix.ix_QualSame; } } } break; // Flag selected case GAD_FUNCED_FLAGS: // Get selected node node=Att_FindNode(data->flag_list,msg.Code); // Set flag data->function->function.flags^=node->data; // Check change funced_check_flag(&data->function->function.flags,node->data); // Update flag list funced_update_flaglist(data); break; // Edit a line case GAD_FUNCED_LISTER: // Get selected node node=Att_FindNode(data->func_display_list,msg.Code); // Is this the node we're already editing? if (node==data->edit_node) break; // If we're editing another one, store its contents if (data->edit_node) funced_end_edit(data,data->edit_node,0,0); // Start editing this entry data->edit_node=node; funced_start_edit(data); break; // Return pressed in edit line case GAD_FUNCED_EDIT: // See if we were editing something if (data->edit_node) { // Stop editing funced_end_edit(data,data->edit_node,END_DISABLE,msg.Qualifier); data->edit_node=0; } break; // New entry case GAD_FUNCED_NEW_ENTRY: case GAD_FUNCED_INSERT_ENTRY: // Create new entry functioned_copy_line(data,0,gadgetid,0); break; // Delete entry case GAD_FUNCED_DELETE_ENTRY: // Check we were editing something if (!data->edit_node) break; // Stop editing (signal delete) funced_end_edit(data,data->edit_node,END_DISABLE|END_DELETE,0); data->edit_node=0; break; // Function type case GAD_FUNCED_FUNCTION_TYPE: // Check we were editing something if (!data->edit_node) break; // Store type ((FunctionEntry *)data->edit_node->data)->type=msg.Code; // Disable popup button if no functions DisableObject( data->objlist, GAD_FUNCED_EDIT_GLASS, (msg.Code==INST_COMMAND && !data->startup->func_list)); break; // Glass gadget case GAD_FUNCED_EDIT_GLASS: // Check we were editing something if (data->edit_node) { char buffer[256]; // Put up requester if (!(funced_command_req( data, buffer, ((FunctionEntry *)data->edit_node->data)->type))) break; // Insert string in edit line funced_edit_insertstring( data->objlist, GAD_FUNCED_EDIT, buffer, DOpusBase,(struct Library *)IntuitionBase); } break; // Argument list case GAD_FUNCED_EDIT_ARGUMENT: // Check we were editing something if (data->edit_node) { char buffer[80]; // Put up requester if (!(funced_command_req( data, buffer, -1))) break; // Insert string in edit line funced_edit_insertstring( data->objlist, GAD_FUNCED_EDIT, buffer, DOpusBase,(struct Library *)IntuitionBase); } break; // Export case MENU_FUNCED_EXPORT_ASCII: case MENU_FUNCED_EXPORT_CMD: // Got file requester? if (WINREQUESTER(data->window)) { struct TagItem tags[6]; struct FileRequester *req=WINREQUESTER(data->window); // Show busy pointer SetWindowBusy(data->window); // File requester tags tags[0].ti_Tag=ASLFR_Window; tags[0].ti_Data=(ULONG)data->window; tags[1].ti_Tag=ASLFR_TitleText; tags[1].ti_Data=(ULONG)GetString(startup->locale,MSG_FUNCED_SELECT_FILE); tags[2].ti_Tag=ASLFR_Flags1; tags[2].ti_Data=FRF_DOSAVEMODE|FRF_PRIVATEIDCMP; tags[3].ti_Tag=ASLFR_Flags2; tags[3].ti_Data=FRF_REJECTICONS; tags[4].ti_Tag=(gadgetid==MENU_FUNCED_EXPORT_CMD)?ASLFR_InitialDrawer:TAG_DONE; tags[4].ti_Data=(ULONG)"DOpus5:Commands"; tags[5].ti_Tag=TAG_DONE; // Show filerequester if (AslRequest(req,tags)) { // Build filename strcpy(data->buffer,req->fr_Drawer); AddPart(data->buffer,req->fr_File,256); // Store changes in function funced_store_edits(data); // Do export if (gadgetid==MENU_FUNCED_EXPORT_CMD) function_export_cmd(data->buffer,0,data->function); else L_FunctionExportASCII(data->buffer,0,data->function,startup->a4); } // Remove busy pointer ClearWindowBusy(data->window); } break; // Cut/Copy case MENU_FUNCED_CUT: case MENU_FUNCED_COPY: { APTR iff; // Set busy pointer SetWindowBusy(data->window); // Open clipboard if ((iff=IFFOpen((char *)0,IFF_CLIP_WRITE,ID_OPUS))) { // Stop editing funced_end_edit(data,data->edit_node,END_DISABLE,0); data->edit_node=0; // Store changes in function funced_store_edits(data); // Save function SaveFunction(iff,data->function); // Close clipboard IFFClose(iff); } // Just copy, not cut? if (gadgetid==MENU_FUNCED_COPY) { // Clear busy pointer ClearWindowBusy(data->window); break; } // Fall through, paste null function } // Paste case MENU_FUNCED_PASTE: { Cfg_Function *func=0; // Set busy pointer SetWindowBusy(data->window); // End any edit funced_end_edit(data,data->edit_node,END_DISABLE,0); data->edit_node=0; // Paste? if (gadgetid==MENU_FUNCED_PASTE) { APTR iff; // Open clipboard if ((iff=IFFOpen((char *)0,IFF_CLIP_READ,ID_OPUS))) { // Find function if (IFFNextChunk(iff,ID_FUNC)) { // Read function func=ReadFunction(iff,0,0,0); } // Close clipboard IFFClose(iff); } // No valid function? if (!func) { // Flash error DisplayBeep(data->window->WScreen); ClearWindowBusy(data->window); break; } } // Detach existing list SetGadgetChoices(data->objlist,GAD_FUNCED_FLAGS,(APTR)~0); // Clear function list Att_RemList(data->function_list,REMLIST_SAVELIST|REMLIST_FREEDATA); // Free existing instructions FreeInstructionList(data->function); // Rebuild display list funced_build_display(data); // Clear flags data->function->function.flags=0; funced_update_flaglist(data); // Clear key data->function->function.code=0xffff; SetGadgetValue(data->objlist,GAD_FUNCED_KEY,0); // Clear label if (startup->flags&FUNCEDF_LABEL) { data->label[0]=0; SetGadgetValue(data->p_objlist,GAD_FUNCED_LABEL,0); } // Paste function in? if (func) { short type; // Save type type=data->function->function.func_type; // Copy function in CopyFunction(func,0,data->function); data->function->function.func_type=type; // Free copied function FreeFunction(func); // Initialise gadgets funced_init_gads(data); } // Clear busy pointer ClearWindowBusy(data->window); } break; // Use case GAD_FUNCED_USE: success=1; // Cancel case GAD_FUNCED_CANCEL: break_flag=1; break; } break; // Key press case IDCMP_RAWKEY: // Help? if (msg.Code==0x5f && !(msg.Qualifier&VALID_QUALIFIERS)) { // Set busy pointer SetWindowBusy(data->window); // Send help command IPC_Command(startup->main_owner,IPC_HELP,(1<<31),"Function Editor",0,REPLY_NO_PORT); // Clear busy pointer ClearWindowBusy(data->window); } break; // BOOPSI message case IDCMP_IDCMPUPDATE: { struct TagItem *tags=(struct TagItem *)msg.IAddress; short item; // Check ID if (GetTagData(GA_ID,0,tags)!=GAD_FUNCED_LISTER) break; // Get item if ((item=GetTagData(DLV_DragNotify,-1,tags))!=-1) { // Start the drag config_drag_start(&data->drag,data->func_display_list,item,tags,TRUE); } } break; // Ticks case IDCMP_INTUITICKS: ++data->drag.tick_count; break; } // Reply to any outstanding message if (gmsg) ReplyWindowMsg(gmsg); } } // AppMessage if (data->appwindow) { struct AppMessage *msg; while ((msg=(struct AppMessage *)GetMsg(data->appport))) { // Make sure window is active ActivateWindow(data->window); // Handle message funced_appmsg(data,msg); ReplyMsg((struct Message *)msg); } } // Check break flag if (break_flag) break; // Wait for message Wait(waitbits); } // Restore CD if (lock) UnLock(CurrentDir(lock)); // Edit successful? if (success) { FunctionReturn ret; // Store changes in function funced_store_edits(data); // Fill out return data ret.object=startup->object; ret.object_flags=startup->object_flags; ret.function=data->function; // Send new function back IPC_Command(startup->owner_ipc,FUNCTIONEDIT_RETURN,0,&ret,0,REPLY_NO_PORT); } // End any drag in progress functioned_end_drag(data,0); // Free edit function FreeFunction(data->function); // Close window RemoveAppWindow(data->appwindow); CloseConfigWindow(data->window); // Close application port if (data->appport) { struct Message *msg; while ((msg=GetMsg(data->appport))) ReplyMsg(msg); DeleteMsgPort(data->appport); } // Say goodbye IPC_Goodbye(ipc,startup->owner_ipc,startup->object_flags); // Delete IPC data Forbid(); IPC_Free(ipc); // Free data funced_cleanup(data); FreeVec(startup); }
short LIBFUNC L_DoSimpleRequest( REG(a0, struct Window *parent), REG(a1, struct DOpusSimpleRequest *simple), REG(a6, struct Library *libbase)) { APTR memory; simplereq_data *data; UWORD gadgetid=0; #ifdef __amigaos4__ libbase = (struct Library *)dopuslibbase_global; #endif // Allocate memory handle if (!(memory=L_NewMemHandle(0,0,MEMF_CLEAR))) return 1; // Allocate data if (!(data=(simplereq_data *)L_AllocMemH(memory,sizeof(simplereq_data)))) { L_FreeMemHandle(memory); return 1; } // Initialise data->simple=simple; data->parent=parent; data->string_buffer=simple->string_buffer; data->gadgets=simple->gadgets; data->libbase=(struct MyLibrary *)libbase; data->signal=-1; data->memory=memory; // Center window; over mouse? if (simple->flags&SRF_MOUSE_POS) { data->req_dims.char_dim.Left=POS_MOUSE_CENTER; data->req_dims.char_dim.Top=POS_MOUSE_CENTER; } // Over parent else { data->req_dims.char_dim.Left=POS_CENTER; data->req_dims.char_dim.Top=POS_CENTER; } // Construct requester if (!(simple_build(data))) { // Failed L_FreeMemHandle(memory); return 1; } // IPC port supplied? if (simple->flags&SRF_IPC && simple->ipc) { data->ipc=simple->ipc; data->waitbits=1<<data->ipc->command_port->mp_SigBit; } // Signal supplied? else if (simple->flags&SRF_SIGNAL) { data->signal=(short)simple->ipc; data->waitbits=1<<data->signal; } // Otherwise else { data->waitbits=IPCSIG_QUIT; SetSignal(0,IPCSIG_QUIT); } // Open requester if (_simplereq_open(data,parent)) { // Wait on requester FOREVER { struct IntuiMessage *msg; IPCMessage *imsg; short break_flag=0; ULONG waitres; // IPC message? if (data->ipc) { while ((imsg=(IPCMessage *)GetMsg(data->ipc->command_port))) { if (imsg->command==IPC_HIDE) _simplereq_close(data); else if (imsg->command==IPC_SHOW) { if (!(_simplereq_open(data,imsg->data))) break_flag=1; } else if (imsg->command==IPC_ACTIVATE) { if (data->window) { WindowToFront(data->window); ActivateWindow(data->window); } } else if (imsg->command==IPC_QUIT || imsg->command==IPC_ABORT) { break_flag=1; gadgetid=(UWORD)-1; } L_IPC_Reply(imsg); } } // Intuition message? if (data->window) { while ((msg=L_GetWindowMsg(data->window->UserPort, (APTR)libbase))) { struct IntuiMessage copy_msg; // Copy message and reply copy_msg=*msg; L_ReplyWindowMsg(msg); // Check message type if (copy_msg.Class==IDCMP_GADGETUP) { // Get gadget ID gadgetid=((struct Gadget *)copy_msg.IAddress)->GadgetID; // Checkbox? if (gadgetid==GAD_CHECK_ID) { // Store value if (simple->check_ptr) *simple->check_ptr=copy_msg.Code; } // Tab on a string gadget? else if (gadgetid==GAD_STRING2_ID || (gadgetid==GAD_STRING_ID && (copy_msg.Code==0x9 || copy_msg.Code==0x45 || copy_msg.Qualifier&(IEQUALIFIER_LSHIFT|IEQUALIFIER_RSHIFT)))) continue; // Popup gadget? else if (gadgetid==GAD_POPUP_ID) { char buf[400],file[40],*ptr; struct TagItem tags[4]; // Get initial path and file strcpy(buf,(char *)L_GetGadgetValue(data->objlist,GAD_STRING_ID,data->libbase)); if ((ptr=FilePart(buf))) { stccpy(file,ptr,40); *ptr=0; } else file[0]=0; // Initialise tags tags[0].ti_Tag=ASLFR_Window; tags[0].ti_Data=(ULONG)data->window; tags[1].ti_Tag=ASLFR_InitialFile; tags[1].ti_Data=(ULONG)file; tags[2].ti_Tag=ASLFR_InitialDrawer; tags[2].ti_Data=(ULONG)buf; tags[3].ti_Tag=TAG_END; // Show requester if (simple->filereq && AslRequest(simple->filereq,tags)) { // Build new path strcpy(buf,((struct FileRequester *)simple->filereq)->fr_Drawer); AddPart(buf,((struct FileRequester *)simple->filereq)->fr_File,400); // Show in string gadget L_SetGadgetValue(data->objlist,GAD_STRING_ID,(long)buf); L_ActivateStrGad(GADGET(L_GetObject(data->objlist,GAD_STRING_ID)),data->window); } continue; } // Set break flag else break_flag=1; } // Key press else if (copy_msg.Class==IDCMP_VANILLAKEY) { // Y = yes if (copy_msg.Code=='y' || copy_msg.Code=='Y') { gadgetid=1; break_flag=1; } // N = no else if (copy_msg.Code=='n' || copy_msg.Code=='N') { gadgetid=0; break_flag=1; } } } } // Check break flag if (break_flag) break; // Wait for a message waitres=Wait(data->waitbits| ((data->window)?(1<<data->window->UserPort->mp_SigBit):0)); // Quit? if (waitres&IPCSIG_QUIT) { gadgetid=0; break; } // Signal? else if (data->signal!=-1 && (waitres&(1<<data->signal))) { gadgetid=(UWORD)-5; break; } } } // Close requester _simplereq_close(data); // Free memory L_FreeMemHandle(memory); // Return gadget code return gadgetid; }
main(int argc, char *argv[]) { unsigned char str[256]; int i; int j; struct RastPort rp; unsigned char *pp; struct BitMap bm = { 256, /* bytes per row */ 8, /* rows */ 0, /* flags */ 1, /* depth */ 0, /* pad */ 0 /* planes */ }; struct TextAttr ta; struct TextFont *tf; struct FontRequester *fr; struct TagItem frtags[] = { ASL_Hail, (ULONG)"NetBSD font choices", ASL_Width, 640, ASL_Height, 400, ASL_LeftEdge, 10, ASL_TopEdge, 10, ASL_OKText, (ULONG)"Dump", ASL_CancelText, (ULONG)"Cancel", ASL_FontName, (ULONG)"topaz.font", ASL_FontHeight, 8L, ASL_FontStyles, FS_NORMAL, ASL_FuncFlags, FONF_STYLES | FONF_FIXEDWIDTH, TAG_DONE }; /* Let the user pick a font to dump */ if (fr = (struct FontRequester *) AllocAslRequest(ASL_FontRequest, frtags)) { if (!AslRequest(fr, NULL)) { FreeAslRequest(fr); fprintf(stderr, "User requested exit\n"); exit (0); } ta.ta_Name = (STRPTR)malloc(strlen(fr->fo_Attr.ta_Name)); strcpy(ta.ta_Name, fr->fo_Attr.ta_Name); ta.ta_YSize = fr->fo_Attr.ta_YSize; ta.ta_Style = fr->fo_Attr.ta_Style; ta.ta_Flags = fr->fo_Attr.ta_Flags; FreeAslRequest(fr); } else { fprintf(stderr, "Can't allocate Font Requestor\n"); exit (1); } /* Open the selected font */ tf = (struct TextFont *)OpenDiskFont (&ta); if (! tf) { fprintf (stderr, "Can't open font: %s\n", ta.ta_Name); exit (1); } #ifdef DEBUG fprintf(stderr, "Information on selected font:\n"); fprintf(stderr, "Name=%s\n", ta.ta_Name); fprintf(stderr, "Height=%d tf_Style=%x tf_Flags=%x Width=%d Baseline=%d\n", tf->tf_YSize, tf->tf_Style, tf->tf_Flags, tf->tf_XSize, tf->tf_Baseline); #endif /* Check for NetBSD restrictions */ if (tf->tf_Flags & FPF_PROPORTIONAL) { fprintf(stderr, "NetBSD does not support proportional fonts\n"); exit (1); } if (tf->tf_XSize > NetBSDwidth) { fprintf(stderr, "NetBSD does not support fonts wider than %d pixels\n", NetBSDwidth); exit (1); } /* Allocate area to render font in */ InitBitMap(&bm, 1, 256 * NetBSDwidth, tf->tf_YSize); InitRastPort (&rp); rp.BitMap = &bm; bm.Planes[0] = pp = AllocRaster (256 * NetBSDwidth, tf->tf_YSize); if (!pp) { fprintf (stderr, "Can't allocate raster!\n"); exit (1); } /* Initialize string to be rendered */ for (i = 32; i < 256; i++) { str[i - 32] = i; } /* Render string with selected font */ SetFont (&rp, tf); SetSoftStyle(&rp, ta.ta_Style ^ tf->tf_Style, FSF_BOLD | FSF_UNDERLINED | FSF_ITALIC); Move (&rp, 0, tf->tf_Baseline); ClearEOL(&rp); if (tf->tf_XSize != NetBSDwidth) { /* right-justify char in cell */ Move (&rp, NetBSDwidth - tf->tf_XSize, tf->tf_Baseline); /* Narrow font, put each character in space of normal font */ for (i = 0; i < (256 - 32); i++) { Text (&rp, &str[i], 1); Move (&rp, rp.cp_x + (NetBSDwidth - tf->tf_XSize), rp.cp_y); } } else { Text (&rp, str, 256 - 32); } /* Dump them.. */ printf ("/* Generated automatically by fontdumper.c. *DONT* distribute\n"); printf (" this file, it may contain information Copyright by Commodore!\n"); printf ("\n"); printf (" Font: %s/%d\n", ta.ta_Name, tf->tf_YSize); printf (" */\n\n"); printf ("unsigned char kernel_font_width = %d;\n", tf->tf_XSize); printf ("unsigned char kernel_font_height = %d;\n", tf->tf_YSize); printf ("unsigned char kernel_font_baseline = %d;\n", tf->tf_Baseline); printf ("short kernel_font_boldsmear = %d;\n", tf->tf_BoldSmear); printf ("unsigned char kernel_font_lo = 32;\n"); printf ("unsigned char kernel_font_hi = 255;\n\n"); printf ("unsigned char kernel_cursor[] = {\n"); for (j = 0; j < (tf->tf_YSize -1); j++) { printf ("0xff, "); } printf ("0xff };\n\n"); printf ("unsigned char kernel_font[] = {\n"); for (i = 0; i < 256 - 32; i++) { printf ("/* %c */", i + 32); for (j = 0; j < tf->tf_YSize; j++) { printf (" 0x%02x,", pp[i+j*256]); } printf ("\n"); } printf ("};\n"); CloseFont (tf); FreeRaster (pp, 256 * NetBSDwidth, tf->tf_YSize); return (0); }