/*********************************************************************
*
*       MainTask
*/
void MainTask(void) {
  WM_HWIN hTree;
  TREEVIEW_ITEM_Handle hNode;
  int xSize, ySize;
  char acBuffer[(TREEVIEW_DEPTH << 1) + 1];

  //
  // Initialize emWin
  //
  WM_SetCreateFlags(WM_CF_MEMDEV);
  GUI_Init();
  xSize = LCD_GetXSize();
  ySize = LCD_GetYSize();
  //
  // Set defaults for background and widgets
  //
  WM_SetCallback(WM_HBKWIN, _cbBk);
  SCROLLBAR_SetDefaultSkin(SCROLLBAR_SKIN_FLEX);
  SCROLLBAR_SetDefaultWidth(20);
  SCROLLBAR_SetThumbSizeMin(25);
  //
  //
  //
  GUI_SetFont(GUI_FONT_24_ASCII);
  GUI_DispStringHCenterAt("Customized TREEVIEW widget", 160, 5);
  //
  // Create TREEVIEW
  //
  hTree = TREEVIEW_CreateEx(0, 35, xSize, ySize - 35, WM_HBKWIN, WM_CF_SHOW | WM_CF_HASTRANS, 0, GUI_ID_TREEVIEW0);
  TREEVIEW_SetAutoScrollV(hTree, 1);
  TREEVIEW_SetFont(hTree, GUI_FONT_24_ASCII);
  TREEVIEW_SetIndent(hTree, 30);
  TREEVIEW_SetTextIndent(hTree, 20);
  TREEVIEW_SetImage(hTree, TREEVIEW_BI_PLUS, &bmPlus);
  TREEVIEW_SetImage(hTree, TREEVIEW_BI_MINUS, &bmMinus);
  TREEVIEW_SetImage(hTree, TREEVIEW_BI_CLOSED, &bmClosed);
  TREEVIEW_SetImage(hTree, TREEVIEW_BI_OPEN, &bmOpen);
  TREEVIEW_SetImage(hTree, TREEVIEW_BI_LEAF, &bmLeaf);
  TREEVIEW_SetBitmapOffset(hTree, TREEVIEW_BI_PM, -21, -6);
  TREEVIEW_SetOwnerDraw(hTree, _TREEVIEW_OwnerDraw);
  TREEVIEW_SetBkColor(hTree, TREEVIEW_CI_SEL, USER_COLOR);
  TREEVIEW_SetBkColor(hTree, TREEVIEW_CI_UNSEL, GUI_BLACK);
  TREEVIEW_SetTextColor(hTree, TREEVIEW_CI_SEL, GUI_WHITE);
  TREEVIEW_SetTextColor(hTree, TREEVIEW_CI_UNSEL, GUI_WHITE);
  WIDGET_SetEffect(hTree, &WIDGET_Effect_None);
  //
  // Fill TREEVIEW
  //
  hNode = TREEVIEW_InsertItem(hTree, TREEVIEW_ITEM_TYPE_NODE, 0, 0, "Tree");
  _FillNode(hTree, hNode, NUM_CHILD_NODES, NUM_CHILD_ITEMS, TREEVIEW_DEPTH, TREEVIEW_DEPTH, acBuffer, acBuffer);
  TREEVIEW_ITEM_Expand(hNode);
  WM_SetFocus(hTree);
  while (1) {
    GUI_Delay(100);
  }
}
Exemplo n.º 2
0
void StartFsTask(void const * argument)
{
	printf("Fs task started\n");
	taskENTER_CRITICAL();
	TREEVIEW_Handle filesystem  = TREEVIEW_CreateEx(	500, 0,
														300, 480,
														0, WM_CF_SHOW,
														TREEVIEW_CF_AUTOSCROLLBAR_V |
														TREEVIEW_CF_AUTOSCROLLBAR_H |
														TREEVIEW_CF_ROWSELECT,
														GUI_ID_TREEVIEW0
													);
	TREEVIEW_SetFont(filesystem, GUI_FONT_24_ASCII);
	scan_files("", &filesystem);
	TREEVIEW_ITEM_ExpandAll(TREEVIEW_GetItem(filesystem, 0, TREEVIEW_GET_FIRST));
	WM_SetCallback(WM_HBKWIN, _cbHBKWIN);
	WM_SetFocus(filesystem);
	taskEXIT_CRITICAL();

    while(1)
    {
		osDelay(5000);
    }
}
Exemplo n.º 3
0
FRESULT scan_files (
	char* path,        /* Start node to be scanned (also used as work area) */
	TREEVIEW_Handle *hpath
)
{
	printf("calling scan_files(%s)\n", path);
    FRESULT res;
    FILINFO fno;
    DIR dir;
    int i;
    char *fn;   /* This function assumes non-Unicode configuration */
    static char lfn[_MAX_LFN + 1];   /* Buffer to store the LFN */
    fno.lfname = lfn;
    fno.lfsize = sizeof lfn;


    res = f_opendir(&dir, path);                       /* Open the directory */
    if (res == FR_OK) {
		// Create directory in treeview
		TREEVIEW_ITEM_Handle node =  TREEVIEW_InsertItem(	*hpath,
															TREEVIEW_ITEM_TYPE_NODE,
															0,
															0,
															(const char *)path
														);
		myfd_t * this_fd = malloc(sizeof(struct myfd));
		this_fd->type = 0;
		char * file_path = malloc(strlen(path)+1);
		sprintf(file_path, "%s", path);
		//printf("%s\n", file_path);
		this_fd->path = file_path;
		TREEVIEW_ITEM_SetUserData(node, (uint32_t)this_fd);

		int nb_child = 0;
		TREEVIEW_ITEM_Handle last_item = NULL;
        i = strlen(path);
        for (;;) {
            res = f_readdir(&dir, &fno);                   /* Read a directory item */
            if (res != FR_OK || fno.fname[0] == 0) break;  /* Break on error or end of dir */
            if (fno.fname[0] == '.') 
			{
					continue;             /* Ignore dot entry */
			}
            fn = *fno.lfname ? fno.lfname : fno.fname;
            if (fno.fattrib & AM_DIR) {                    /* It is a directory */
				int j = strlen(fn);
				char * dirname = malloc(j);
				strcpy(dirname, fn);
				char newpath[i+j]; // "/0" du i renplacé par "/" plus bas
				newpath[0] = '\0';
				strcat(newpath, path);
				strcat(newpath, "/");
				strcat(newpath, fn);
				TREEVIEW_Handle child_tree = TREEVIEW_CreateEx(0,0,0,0,0,0,0,0);
                res = scan_files(newpath, &child_tree);
				TREEVIEW_ITEM_Handle child_tree_first_node = TREEVIEW_GetItem(	child_tree,
																				0,
																				TREEVIEW_GET_FIRST
																				);
				if (child_tree_first_node != 0)
				{
						child_tree_first_node = TREEVIEW_ITEM_SetText(	child_tree_first_node,
								dirname);
						TREEVIEW_AttachItem(	*hpath,
								child_tree_first_node,
								nb_child ? last_item : node,
								nb_child ? TREEVIEW_INSERT_BELOW : TREEVIEW_INSERT_FIRST_CHILD
								);
						last_item = child_tree_first_node;
				}
				free(dirname);
                if (res != FR_OK) break;
				nb_child++;
            } else {                                       /* It is a file. */
				if (correct_extention(fn))
				{
					last_item = TREEVIEW_InsertItem(	*hpath,
														TREEVIEW_ITEM_TYPE_LEAF,
														nb_child ? last_item : node,
														nb_child ? TREEVIEW_INSERT_BELOW : TREEVIEW_INSERT_FIRST_CHILD,
														(const char *) fn
													);
					nb_child++;
					myfd_t * this_fd = malloc(sizeof(struct myfd));
					this_fd->type = 1;
					char * file_path = malloc(strlen(path)+strlen(fn)+2);
					sprintf(file_path, "%s/%s", path, fn);
					//printf("%s\n", file_path);
					this_fd->path = file_path;
					TREEVIEW_ITEM_SetUserData(last_item, (uint32_t)this_fd);
				}
            }
        }
        f_closedir(&dir);
    }

    return res;
}
Exemplo n.º 4
0
/*********************************************************************
*
*       MainTask
*/
void MainTask(void) {
  TREEVIEW_ITEM_Handle hNode;
  WM_HWIN              hTree;
  int                  xSize;
  int                  ySize;
  int                  yPos;
  int                  r;
  int                  TimeStart;
  int                  TimeUsed;
  int                  ySizeText;
  U32                  BytesFree;
  U32                  BytesUsed;
  char                 acBuffer[(TREEVIEW_DEPTH << 1) + 1];
  char                 acNumNodes[30]  = "Nodes:  ";
  char                 acNumLeaves[30] = "Leaves: ";
  char                 acNumTotal[30]  = "Total:  ";
  char                 acTimeUsed[30]  = "Time:   ";
  char                 acBytesUsed[30] = "Memory: ";

  //
  // Initialize emWin
  //
  WM_SetCreateFlags(WM_CF_MEMDEV);
  GUI_Init();
  xSize = LCD_GetXSize();
  ySize = LCD_GetYSize();
  //
  // Set defaults for background and widgets
  //
  WM_SetDesktopColor(GUI_BLACK);
  SCROLLBAR_SetDefaultSkin(SCROLLBAR_SKIN_FLEX);
  SCROLLBAR_SetDefaultWidth(20);
  SCROLLBAR_SetThumbSizeMin(25);
  TEXT_SetDefaultFont(GUI_FONT_6X8);
  //
  // Draw info message before creating the widgets
  //
  GUI_DrawGradientV(0, 0, xSize - 1, ySize - 1, GUI_BLUE, GUI_BLACK);
  GUI_SetFont(GUI_FONT_20F_ASCII);
  GUI_DispStringHCenterAt("Filling TREEVIEW widget...", xSize >> 1, ySize / 3);
  GUI_X_Delay(1000);
  //
  // Create TREEVIEW
  //
  hTree = TREEVIEW_CreateEx(0, 0, xSize, ySize, WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_TREEVIEW0);
  TREEVIEW_SetAutoScrollV(hTree, 1);//管理自动使用垂直滚动条。
  TREEVIEW_SetSelMode(hTree, TREEVIEW_SELMODE_ROW);
  //
  // Fill TREEVIEW
  //
  hNode = TREEVIEW_InsertItem(hTree, TREEVIEW_ITEM_TYPE_NODE, 0, 0, "Tree");
  BytesFree = GUI_ALLOC_GetNumFreeBytes();
  TimeStart = GUI_GetTime();
  r = _FillNode(hTree, hNode, NUM_CHILD_NODES, NUM_CHILD_ITEMS, TREEVIEW_DEPTH, TREEVIEW_DEPTH, acBuffer, acBuffer);
  TimeUsed = GUI_GetTime() - TimeStart;
  BytesUsed = BytesFree - GUI_ALLOC_GetNumFreeBytes();
  if (r) {
    //
    // Error message
    //
    WM_DeleteWindow(hTree);
    GUI_MessageBox("Error", "Not enough memory available!", 0);
  } else {
    //
    // Show result
    //
    yPos = 20;
    ySizeText = GUI_GetYDistOfFont( TEXT_GetDefaultFont()) + 5;
    _MakeNumberText(hTree, xSize >> 1, &yPos, xSize >> 1, ySizeText, acNumNodes, _NumNodes);
    _MakeNumberText(hTree, xSize >> 1, &yPos, xSize >> 1, ySizeText, acNumLeaves, _NumLeaves);
    _MakeNumberText(hTree, xSize >> 1, &yPos, xSize >> 1, ySizeText, acNumTotal, _NumNodes + _NumLeaves);
    _MakeNumberText(hTree, xSize >> 1, &yPos, xSize >> 1, ySizeText, acTimeUsed, TimeUsed);
    _MakeNumberText(hTree, xSize >> 1, &yPos, xSize >> 1, ySizeText, acBytesUsed, BytesUsed);
    WM_SetFocus(hTree);
  }
  while (1) {
    GUI_Delay(100);
  }
}