// Handle drop on an object BOOL desktop_drop_on_object(BackdropInfo *info,DOpusAppMessage **msg,BackdropObject *drop_obj,UWORD qual) { char *name; short ret=1; // Allocate buffer if (!(name=AllocVec(1024,0))) return 1; // Was it an AppIcon? if (drop_obj->type==BDO_APP_ICON) { // Is the icon busy? if (drop_obj->flags&BDOF_BUSY) { // Flash error DisplayBeep(info->window->WScreen); } // Otherwise, pass message on else { struct MsgPort *port; // Turn message into an AppIcon one (*msg)->da_Msg.am_Type=MTYPE_APPICON; // Get port and info port=WB_AppWindowData( (struct AppWindow *)drop_obj->misc_data, &(*msg)->da_Msg.am_ID, &(*msg)->da_Msg.am_UserData); // Fix reply port (*msg)->da_Msg.am_Message.mn_ReplyPort=GUI->appmsg_port; // Send the message on PutMsg(port,(struct Message *)*msg); // Zero message pointer *msg=0; } } // Was it a group? else if (drop_obj->type==BDO_GROUP) { short arg; GroupData *group; BOOL ok=0; // Find group if it's open lock_listlock(&GUI->group_list,0); if (!(group=backdrop_find_group(drop_obj))) unlock_listlock(&GUI->group_list); // Go through arguments for (arg=0;arg<(*msg)->da_Msg.am_NumArgs;arg++) { // Valid file? if ((*msg)->da_Msg.am_ArgList[arg].wa_Name && *(*msg)->da_Msg.am_ArgList[arg].wa_Name) { // Get filename GetWBArgPath(&(*msg)->da_Msg.am_ArgList[arg],name,512); // Send add message to group if it's open if (group) { char *copy; // Copy name if ((copy=AllocVec(strlen(name)+1,0))) { strcpy(copy,name); IPC_Command(group->ipc,GROUP_ADD_ICON,0,0,copy,0); ok=1; } } // Otherwise add object to group else { backdrop_group_add_object(drop_obj->name,0,name,-1,-1); ok=1; } } } // Show error if no ok if (!ok) DisplayBeep(GUI->screen_pointer); // Unlock process list if it's locked if (group) unlock_listlock(&GUI->group_list); } // Or a project? else if (drop_obj->icon->do_Type==WBPROJECT) { // Is it an Opus command? if (command_filetype) { BPTR lock,old; // Set failure initially ret=0; // Get lock on directory if ((lock=backdrop_icon_lock(drop_obj))) { // Go there old=CurrentDir(lock); // See if it's a command if (filetype_match_type(drop_obj->name,command_filetype)) { // Run command with args backdrop_object_open( info, drop_obj, 0, 0, (*msg)->da_Msg.am_NumArgs, (*msg)->da_Msg.am_ArgList); ret=1; } // Restore CD CurrentDir(old); } } // Beep if not a command if (!ret) DisplayBeep(GUI->screen_pointer); } // Or a tool? else if (drop_obj->icon->do_Type==WBTOOL) { // Run program with args backdrop_object_open( info, drop_obj, 0, 0, (*msg)->da_Msg.am_NumArgs, (*msg)->da_Msg.am_ArgList); } // Or a disk/directory? else if (drop_obj->icon->do_Type==WBDISK || drop_obj->icon->do_Type==WBDRAWER || drop_obj->icon->do_Type==WBGARBAGE) { struct ArgArray *arg_array; // Get arg array if ((arg_array=AppArgArray(*msg,AAF_ALLOW_DIRS))) { BPTR lock; // Get pathname of first file DevNameFromLockDopus((*msg)->da_Msg.am_ArgList[0].wa_Lock,name,512); // Need source directory; if no name, get parent if ((!(*msg)->da_Msg.am_ArgList[0].wa_Name || !*(*msg)->da_Msg.am_ArgList[0].wa_Name) && (lock=ParentDir((*msg)->da_Msg.am_ArgList[0].wa_Lock))) { // Get pathname of parent DevNameFromLockDopus(lock,name,512); UnLock(lock); } // Get destination path if ((lock=backdrop_icon_lock(drop_obj))) { short action; // Get path DevNameFromLockDopus(lock,name+512,512); UnLock(lock); // Is object a left-out? if (drop_obj->type==BDO_LEFT_OUT) { // Add left-out name AddPart(name+512,drop_obj->name,512); } // Get filetype action if (qual&IEQUALIFIER_CONTROL) action=FTTYPE_CTRL_DRAGDROP; else if (qual&(IEQUALIFIER_LALT|IEQUALIFIER_RALT)) action=FTTYPE_ALT_DRAGDROP; else action=FTTYPE_DRAG_DROP; // Do filetype action on files function_launch( FUNCTION_FILETYPE, 0, action, FUNCF_DRAG_DROP|FUNCF_ICONS, 0,0, name,name+512, arg_array, 0, (Buttons *)CopyAppMessage(*msg,global_memory_pool)); } } } else ret=0; FreeVec(name); return ret; }
// Rename some objects void icon_rename(IPCData *ipc,BackdropInfo *info,BackdropObject *icon) { Att_List *list; Att_Node *node; BackdropObject *object; BOOL save_pos=0; BPTR lock=0,old=0; // Group? if (info->flags&BDIF_GROUP) { GroupData *group; // Get group pointer group=(GroupData *)IPCDATA(info->ipc); // Build directory name lsprintf(info->buffer,"dopus5:groups/%s",group->name); // Lock directory if (!(lock=Lock(info->buffer,ACCESS_READ))) return; // Change directory old=CurrentDir(lock); } // Create list if (!(list=Att_NewList(0))) { if (lock) UnLock(CurrentDir(old)); return; } // Lock backdrop list lock_listlock(&info->objects,0); // Go through backdrop list (backwards, just for the hell of it) for (object=(BackdropObject *)info->objects.list.lh_TailPred; object->node.ln_Pred; object=(BackdropObject *)object->node.ln_Pred) { // Correct type? if (object->type!=BDO_APP_ICON && object->type!=BDO_BAD_DISK && !(object->flags&BDOF_CACHE)) { // Selected or supplied? if ((!icon && object->state) || icon==object) { // Add object to list Att_NewNode( list, (object->flags&BDOF_CUSTOM_LABEL)?object->device_name:object->name, (ULONG)object, 0); if (icon) break; } } } // Unlock backdrop list unlock_listlock(&info->objects); // Go through list of objects for (node=(Att_Node *)list->list.lh_Head; node->node.ln_Succ; node=(Att_Node *)node->node.ln_Succ) { char *name,*origname; BackdropObject *object; short ret,copy=1; BOOL retry,fail=0; if (!(name=AllocVec(512,0))) break; origname=name+256; // Loop on retries do { // Clear retry flag retry=0; // Copy name strcpy(name,node->node.ln_Name); // Build message lsprintf(info->buffer,GetString(&locale,MSG_RENAME_DISK),name); // Strip trailing colon for assigns if (name[(ret=(strlen(name)-1))]==':') name[ret]=0; // Copy original name strcpy(origname,name); // Ask for new name if (!(ret=super_request_args( info->window, info->buffer, SRF_BUFFER|SRF_IPC|SRF_PATH_FILTER|SRF_MOUSE_POS, name,255, ipc, GetString(&locale,MSG_OKAY), GetString(&locale,(node->node.ln_Succ->ln_Succ)?MSG_SKIP:MSG_CANCEL), (node->node.ln_Succ->ln_Succ)?GetString(&locale,MSG_CANCEL):0,0))) { // Cancel fail=1; break; } // Ok to rename? else if (ret!=2) { // Lock backdrop list lock_listlock(&info->objects,0); // Is object still valid?> if ((object=find_backdrop_object(info,(BackdropObject *)node->data))) { // Object in a group? if (info->flags&BDIF_GROUP) { // Must have custom label if (object->flags&BDOF_CUSTOM_LABEL) { // Try to rename object if (Rename(object->device_name,name)) { // Store new name strcpy(object->device_name,name); ret=1; copy=0; } } } // Assign? else if (object->flags&BDOF_ASSIGN) { BPTR lock; // Lock the assign if ((lock=Lock(object->name,ACCESS_READ))) { // Assign the new name to it while (!(ret=AssignLock(name,lock))) { // Failed, display requester if (!(error_request( info->window, ERF_MOUSE, GetString(&locale,MSG_RENAMING), -1, object->name, ":", 0))) break; } // Success? if (ret) { // Delete the old assignment AssignLock(origname,0); } // Otherwise free the lock else UnLock(lock); } } // Disk? else if (object->type==BDO_DISK) { // Try to relabel while (!(ret=OriginalRelabel(object->device_name,name))) { // Failed, display requester if (!(error_request( info->window, ERF_MOUSE, GetString(&locale,MSG_RENAMING), -1, object->name, ":", 0))) break; } // Success? if (ret) { // Pass name change through to things notify_disk_name_change(info,object->device_name,name); } } // Group, desktop folder else if (object->type==BDO_GROUP || (object->type==BDO_LEFT_OUT && object->flags&BDOF_DESKTOP_FOLDER)) { BPTR old=0,lock; // Change directory if ((lock=Lock(object->path,ACCESS_READ))) old=CurrentDir(lock); // Rename file if (!(ret=Rename(object->name,name))) { // Show error requester if (error_request( info->window, ERF_MOUSE, GetString(&locale,MSG_RENAMING), -1, object->name, ":", 0)) { // Set flag to retry retry=1; } } // Success? if (ret) { GroupData *group; // Add .infos on strcpy(info->buffer,object->name); strcat(info->buffer,".info"); strcpy(info->buffer+300,name); strcat(info->buffer+300,".info"); // Rename icon Rename(info->buffer,info->buffer+300); // Group? if (object->type==BDO_GROUP) { // Lock process list lock_listlock(&GUI->group_list,0); // See if group is open if ((group=backdrop_find_group(object))) { char *name_copy; // Get a copy of the name if ((name_copy=AllocVec(strlen(name)+1,0))) { // Signal it to update its name strcpy(name_copy,name); IPC_Command(group->ipc,GROUP_NEW_NAME,0,0,name_copy,0); } } // Unlock process list unlock_listlock(&GUI->group_list); } } // Restore directory if (lock) UnLock(CurrentDir(old)); } // Left-out else if (object->type==BDO_LEFT_OUT) { leftout_record *left; // Lock position list lock_listlock(&GUI->positions,0); // Look for entry for icon for (left=(leftout_record *)&GUI->positions.list.lh_Head; left->node.ln_Succ; left=(leftout_record *)left->node.ln_Succ) { // Leftout? if (left->node.ln_Type==PTYPE_LEFTOUT) { // Match this icon? if (object->misc_data==(ULONG)left) { // Store new label stccpy(left->icon_label,name,sizeof(left->icon_label)); save_pos=1; break; } } } // Unlock position list unlock_listlock(&GUI->positions); // Store name in icon if (object->flags&BDOF_CUSTOM_LABEL) { strcpy(object->device_name,name); ret=1; copy=0; } } // Successful? if (ret) { // Erase object backdrop_erase_icon(info,object,0); // Store new name if (copy) { strcpy(object->name,name); if (object->flags&BDOF_ASSIGN) strcat(object->name,":"); } // Show new object backdrop_render_object(info,object,BRENDERF_CLIP); } } // Unlock backdrop list unlock_listlock(&info->objects); } } while (retry); // Abort? FreeVec(name); if (fail) break; } // Free list Att_RemList(list,0); // Lock backdrop list lock_listlock(&info->objects,0); // Save any left-outs if (save_pos) { // Lock list lock_listlock(&GUI->positions,0); // Save list SavePositions(&GUI->positions.list,GUI->position_name); // Unlock list unlock_listlock(&GUI->positions); } // Unlock backdrop list unlock_listlock(&info->objects); // Restore CD if (lock) UnLock(CurrentDir(old)); }
// Open a group void backdrop_open_group(BackdropInfo *info,BackdropObject *object,BOOL activate) { GroupData *group; IPCData *ipc=0; // Valid object? if (!object || !object->icon || object->icon->do_Type!=WBDRAWER) return; // See if it's already open lock_listlock(&GUI->group_list,0); if (group=backdrop_find_group(object)) { // Send activate message if (activate) IPC_Command(group->ipc,IPC_ACTIVATE,0,0,0,0); } unlock_listlock(&GUI->group_list); // If it was open, return if (group) return; // Allocate group packet if (!(group=AllocVec(sizeof(GroupData),MEMF_CLEAR))) return; // Fill in group packet group->screen=info->window->WScreen; if (object->icon->do_DrawerData) group->dimensions=*((struct IBox *)&object->icon->do_DrawerData->dd_NewWindow.LeftEdge); else { group->dimensions.Left=20; group->dimensions.Top=20; group->dimensions.Width=200; group->dimensions.Height=150; } strcpy(group->name,object->name); group->object=object; // Initialise popup menu if (group->popup=PopUpNewHandle(0,0,&locale)) { // Add items PopUpNewItem(group->popup,MSG_ICON_SNAPSHOT_MENU,MENU_ICON_SNAPSHOT_WINDOW,0); PopUpNewItem(group->popup,MSG_ICON_CLEANUP,MENU_ICON_CLEANUP,0); } // Launch process IPC_Launch( &GUI->group_list, &ipc, "dopus_group", (ULONG)backdrop_group_handler, STACK_DEFAULT, (ULONG)group,(struct Library *)DOSBase); // Failed? if (!ipc) { // Free PopUpFreeHandle(group->popup); FreeVec(group); } }
// Snapshot objects void backdrop_snapshot(BackdropInfo *info,BOOL unsnapshot,BOOL all,BackdropObject *icon) { BackdropObject *object; Lister *lister; IPCData *ipc; BPTR old,lock; short count=0,beep=0; #ifdef DISTINCT_OK BOOL save_env=0; #endif BOOL savepos=0; // Lock backdrop list lock_listlock(&info->objects,0); // Lock lister list lock_listlock(&GUI->lister_list,0); // Lock group list lock_listlock(&GUI->group_list,0); // Go through backdrop list for (object=(BackdropObject *)info->objects.list.lh_Head; object->node.ln_Succ; object=(BackdropObject *)object->node.ln_Succ) { BOOL ok=0; // Icon supplied? if (icon) { // Does it match? if (object!=icon || !object->icon) continue; } // Is object selected? else if ((!object->state && !all) || !object->icon) continue; beep=1; // Appicon? if (object->type==BDO_APP_ICON) { // Does icon support snapshot itself? if (WB_AppIconFlags((struct AppIcon *)object->misc_data)&APPENTF_SNAPSHOT) { backdrop_appicon_message(object,(unsnapshot)?BAPPF_UNSNAPSHOT:0); ++count; } // Otherwise, fake snapshot else if (*object->name) ok=1; } // Otherwise, is it ok to snapshot? else if (object->type!=BDO_BAD_DISK) ok=1; // Ok to snapshot? if (ok) { short x,y; // UnShapshot? if (unsnapshot) { // Set "no position" position x=-1; y=-1; } // Snapshot else { // Drawer? if (object->icon->do_DrawerData) { // Group icon? if (object->type==BDO_GROUP) { GroupData *group; // See if group is open if ((group=backdrop_find_group(object))) { // Update window position *((struct IBox *)&object->icon->do_DrawerData->dd_NewWindow.LeftEdge)=group->dimensions; } } // Otherwise go through listers else for (ipc=(IPCData *)GUI->lister_list.list.lh_Head; ipc->node.mln_Succ; ipc=(IPCData *)ipc->node.mln_Succ) { // Get lister lister=IPCDATA(ipc); // Is lister from this icon? if (lister->backdrop==object) { // Update lister PositionUpdate(lister,POSUPF_SAVE); break; } } } // Get position x=object->pos.Left; y=object->pos.Top; } // AppIcon? if (object->type==BDO_APP_ICON) { leftout_record *left; // Lock position list lock_listlock(&GUI->positions,TRUE); // Look for entry for icon for (left=(leftout_record *)&GUI->positions.list.lh_Head; left->node.ln_Succ; left=(leftout_record *)left->node.ln_Succ) { // Leftout? if (left->node.ln_Type==PTYPE_APPICON) { // Match this icon? if (strcmp(left->icon_label,object->name)==0) break; } } // Didn't find one? if (!(left->node.ln_Succ) && !unsnapshot) { // Create a new entry if ((left=AllocMemH(GUI->position_memory,sizeof(leftout_record)))) { // Fill out entry stccpy(left->icon_label,object->name,sizeof(left->icon_label)); left->node.ln_Name=left->name; left->node.ln_Type=PTYPE_APPICON; // Add to list AddTail((struct List *)&GUI->positions,(struct Node *)left); } } // Got one? if (left->node.ln_Succ) { // Unsnapshot? if (unsnapshot) { // Remove entry and free it Remove((struct Node *)left); FreeMemH(left); } // Update entry else { ULONG iflags; // Adjust for borders? if (!((iflags=GetIconFlags(object->icon))&ICONF_BORDER_OFF) && (!(environment->env->desktop_flags&DESKTOPF_NO_BORDERS) || (iflags&ICONF_BORDER_ON))) { // Shift back by border size x-=ICON_BORDER_X; y-=ICON_BORDER_Y_TOP; } // Save position left->icon_x=x; left->icon_y=y; left->flags&=~LEFTOUTF_NO_POSITION; } // Set flag to save positions savepos=1; } // Can't snapshot for some reason else if (!unsnapshot) beep=1; // Unlock position list unlock_listlock(&GUI->positions); } // Left-out on desktop? else if (object->type==BDO_LEFT_OUT && !(object->flags&BDOF_DESKTOP_FOLDER) && info->flags&BDIF_MAIN_DESKTOP) { leftout_record *left; // Lock position list lock_listlock(&GUI->positions,0); // Look for entry for icon for (left=(leftout_record *)&GUI->positions.list.lh_Head; left->node.ln_Succ; left=(leftout_record *)left->node.ln_Succ) { // Leftout? if (left->node.ln_Type==PTYPE_LEFTOUT) { // Match this icon? if (object->misc_data==(ULONG)left) break; } } // Got one? if (left->node.ln_Succ) { // Save position left->icon_x=x; left->icon_y=y; left->flags&=~LEFTOUTF_NO_POSITION; // Set flag to save positions savepos=1; } // Must be temporary else beep=1; // Unlock position list unlock_listlock(&GUI->positions); } #ifdef DISTINCT_OK // Distinct icon positions? else if (environment->env->desktop_flags&DESKTOPF_DISTINCT && info->flags&BDIF_MAIN_DESKTOP) { // Snapshot icon for this environment desktop_snapshot_icon(object,x,y); save_env=1; } #endif // Group icon? else if (info->flags&BDIF_GROUP) { // Snapshot in group group_snapshot_icon(info,object,x,y); } // Save to icon else { // Using Workbench positions? if (environment->env->display_options&DISPOPTF_ICON_POS) { // Set position object->icon->do_CurrentX=(unsnapshot)?NO_ICON_POSITION:x-WBICONMAGIC_X; object->icon->do_CurrentY=(unsnapshot)?NO_ICON_POSITION:y-WBICONMAGIC_Y; // Removing Opus positions? if (environment->env->display_options&DISPOPTF_REMOPUSPOS) { // Remove Opus position from icon SetIconFlags(object->icon,GetIconFlags(object->icon)&~ICONF_POSITION_OK); } } // Using Opus positions else { // Set "position ok" flag SetIconFlags(object->icon,GetIconFlags(object->icon)|ICONF_POSITION_OK); // Update icon position SetIconPosition(object->icon,x,y); } // Get icon lock if ((lock=backdrop_icon_lock(object))) { // Change directory old=CurrentDir(lock); // Save this object out if (!(WriteIcon((object->icon->do_Type==WBDISK)?"Disk":object->name,object->icon))) beep=1; // Success; is this in a lister? else if (info->lister) { char name[256]; // Get icon name strcpy(name,(object->icon->do_Type==WBDISK)?"Disk":object->name); strcat(name,".info"); // Reload the file rexx_lister_reload_file(info->lister,name); } // Restore directory CurrentDir(old); UnLock(lock); } } ++count; } // Icon supplied? if (icon) break; } // Failed to do anything? if (!count && beep) DisplayBeep(info->window->WScreen); // Unlock group list unlock_listlock(&GUI->group_list); // Unlock backdrop list unlock_listlock(&info->objects); // Unlock lister list unlock_listlock(&GUI->lister_list); #ifdef DISTINCT_OK // Save environment file? if (save_env && environment->env->flags&ENVF_CHANGED) { // Save environment if (environment_save(environment,environment->path,0,0)) environment->env->flags&=~ENVF_CHANGED; } #endif // Save positions? if (savepos) { // Lock list lock_listlock(&GUI->positions,0); // Save list SavePositions(&GUI->positions.list,GUI->position_name); // Unlock list unlock_listlock(&GUI->positions); } // If this is a lister, update its datestamp if (info->lister) update_buffer_stamp(info->lister); }