⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 windowfilelist.c

📁 上一个上传的有问题,这个是好的。visopsys包括系统内核和GUI的全部SOURCE code ,还包括一些基本的docs文档。里面src子目录对应所有SOURCE code.对于想研究操作系统的朋
💻 C
📖 第 1 页 / 共 2 页
字号:
	      return (status);	    }  	  if (strcmp(tmpFile.name, "."))	    {	      memcpy(&(tmpFileEntries[tmpNumFileEntries].file), &tmpFile,		     sizeof(file));	      sprintf(tmpFileName, "%s/%s", path, tmpFile.name);	      fileFixupPath(tmpFileName,			    tmpFileEntries[tmpNumFileEntries].fullName);	      if (!classifyEntry(&tmpFileEntries[tmpNumFileEntries]))		tmpNumFileEntries += 1; 	    }	}    }    // Commit, baby.  strncpy(fileList->cwd, path, MAX_PATH_LENGTH);  if (fileList->fileEntries)    free(fileList->fileEntries);  fileList->fileEntries = tmpFileEntries;  fileList->numFileEntries = tmpNumFileEntries;  return (status = 0);}static listItemParameters *allocateIconParameters(windowFileList *fileList){  listItemParameters *newIconParams = NULL;  int count;  if (fileList->numFileEntries)    {      newIconParams =	malloc(fileList->numFileEntries * sizeof(listItemParameters));      if (newIconParams == NULL)	{	  error("Memory allocation error creating icon parameters");	  return (newIconParams);	}      // Fill in an array of list item parameters structures for our file      // entries.  It will get passed to the window list creation function      // a moment      for (count = 0; count < fileList->numFileEntries; count ++)	memcpy(&(newIconParams[count]), (listItemParameters *)	       &(((fileEntry *) fileList->fileEntries)[count].iconParams),	       sizeof(listItemParameters));    }  return (newIconParams);}static int changeDirWithLock(windowFileList *fileList, const char *newDir){  // Rescan the directory information and rebuild the file list, with locking  // so that our GUI thread and main thread don't trash one another  int status = 0;  static lock dataLock;  listItemParameters *iconParams = NULL;  status = lockGet(&dataLock);  if (status < 0)    return (status);  windowSwitchPointer(fileList->key, "busy");  status = changeDirectory(fileList, newDir);  if (status < 0)    {      windowSwitchPointer(fileList->key, "default");      lockRelease(&dataLock);      return (status);    }  iconParams = allocateIconParameters(fileList);  if (iconParams == NULL)    {      windowSwitchPointer(fileList->key, "default");      lockRelease(&dataLock);      return (status = ERR_MEMORY);    }  windowComponentSetSelected(fileList->key, 0);  windowComponentSetData(fileList->key, iconParams, fileList->numFileEntries);  windowSwitchPointer(fileList->key, "default");  free(iconParams);  lockRelease(&dataLock);  return (status = 0);}static int update(windowFileList *fileList){  // Update the supplied file list from the supplied directory.  This is  // useful for changing the current directory, for example.  return (changeDirWithLock(fileList, fileList->cwd));}static int destroy(windowFileList *fileList){  // Detroy and deallocate the file list.  if (fileList->fileEntries)    free(fileList->fileEntries);  free(fileList);  return (0);}static int eventHandler(windowFileList *fileList, windowEvent *event){  int status = 0;  int selected = -1;  fileEntry *fileEntries = (fileEntry *) fileList->fileEntries;  fileEntry saveEntry;  // Get the selected item  windowComponentGetSelected(fileList->key, &selected);  if (selected < 0)    {      error("Can't get selected item");      return (status = selected);    }  // Check for events in our icon list.  We consider the icon 'clicked'  // if it is a mouse click selection, or an ENTER key selection  if ((event->type & EVENT_SELECTION) &&      ((event->type & EVENT_MOUSE_LEFTUP) ||       ((event->type & EVENT_KEY_DOWN) && (event->key == 10))))    {      memcpy(&saveEntry, &fileEntries[selected], sizeof(fileEntry));      switch (fileEntries[selected].file.type)	{	case dirT:	  if (fileList->browseFlags & WINFILEBROWSE_CAN_CD)	    {	      // Change to the directory, get the list of icon	      // parameters, and update our window list.	      status =		changeDirWithLock(fileList, fileEntries[selected].fullName);	      if (status < 0)		{		  error("Can't change to directory %s",			fileEntries[selected].file.name);		  return (status);		}	    }	  break;		  	case linkT:	  if ((fileList->browseFlags & WINFILEBROWSE_CAN_CD) &&	      !strcmp((char *) fileEntries[selected].file.name, ".."))	    {	      // Change to the directory, get the list of icon	      // parameters, and update our window list.	      status =		changeDirWithLock(fileList, fileEntries[selected].fullName);	      if (status < 0)		{		  error("Can't change to directory %s",			fileEntries[selected].file.name);		  return (status);		}	    }	  break;		  	default:	  break;	}      if (fileList->selectionCallback)	fileList->selectionCallback((file *) &saveEntry.file,				    (char *) saveEntry.fullName,				    (loaderFileClass *) &saveEntry.class);    }  else if ((event->type & EVENT_KEY_DOWN) && (event->key == 127))    {      if ((fileList->browseFlags & WINFILEBROWSE_CAN_DEL) &&	  strcmp((char *) fileEntries[selected].file.name, ".."))	{	  windowSwitchPointer(fileList->key, "busy");	  status =	    fileDeleteRecursive((char *) fileEntries[selected].fullName);	  windowSwitchPointer(fileList->key, "default");	  if (status < 0)	    error("Error deleting file %s", fileEntries[selected].file.name);	  status = update(fileList);	  if (status < 0)	    return (status);	  if (selected >= fileList->numFileEntries)	    selected = (fileList->numFileEntries - 1);	  windowComponentSetSelected(fileList, selected);	}    }  return (status = 0);}////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Below here, the functions are exported for external use////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////_X_ windowFileList *windowNewFileList(objectKey parent, windowListType type, int rows, int columns, const char *directory, int flags, void *callback, componentParameters *params){  // Desc: Create a new file list widget with the parent window 'parent', the window list type 'type' (windowlist_textonly or windowlist_icononly is currently supported), of height 'rows' and width 'columns', the name of the starting location 'directory', flags (such as WINFILEBROWSE_CAN_CD or WINFILEBROWSE_CAN_DEL -- see sys/window.h), a function 'callback' for when the status changes, and component parameters 'params'.  int status = 0;  windowFileList *fileList = NULL;  listItemParameters *iconParams = NULL;  int count;  // Check params.  Callback can be NULL.  if ((parent == NULL) || (directory == NULL) || (params == NULL))    {      errno = ERR_NULLPARAMETER;      return (fileList = NULL);    }  if (!initialized)    {      // Clear some memory      bzero(&folderImage, sizeof(image));      for (count = 0; count < (int) (sizeof(iconList) / sizeof(icon));	   count ++)	bzero(iconList[count].image, sizeof(image));        // Try to read our config file      status = configurationReader(FILEBROWSE_CONFIG, &config);      if (status < 0)	{	  error("Can't locate configuration file %s", FILEBROWSE_CONFIG);	  errno = ERR_NODATA;	  return (fileList = NULL);	}      initialized = 1;    }  // Allocate memory for our file list  fileList = malloc(sizeof(windowFileList));  if (fileList == NULL)    return (fileList);  // Scan the directory  status = changeDirectory(fileList, directory);  if (status < 0)    {      fileList->destroy(fileList);      errno = status;      return (fileList = NULL);    }  // Get our array of icon parameters  iconParams = allocateIconParameters(fileList);  // Create a window list to hold the icons  fileList->key = windowNewList(parent, type, rows, columns, 0, iconParams,				fileList->numFileEntries, params);  if (iconParams)    free(iconParams);  fileList->selectionCallback = callback;  fileList->browseFlags = flags;  fileList->eventHandler = &eventHandler;  fileList->update = &update;  fileList->destroy = &destroy;  return (fileList);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -