/** * @brief Explores disk. * @param hTree: tree view handle * @retval None */ static void ExploreDisks(WM_HWIN hTree) { TREEVIEW_ITEM_Handle hItem = 0; TREEVIEW_ITEM_Handle hUSBItem = 0; TREEVIEW_ITEM_Handle Node = 0; uint32_t Position = 0; Node = TREEVIEW_InsertItem(hTree, TREEVIEW_ITEM_TYPE_NODE, 0, 0, "Local disks"); if(k_StorageGetStatus(MSD_DISK_UNIT) == 1) { hItem = TREEVIEW_InsertItem(hTree, TREEVIEW_ITEM_TYPE_NODE, Node, TREEVIEW_INSERT_FIRST_CHILD, "microSD"); } if(k_StorageGetStatus(USB_DISK_UNIT) == 1) { Position = hItem ? TREEVIEW_INSERT_BELOW : TREEVIEW_INSERT_FIRST_CHILD; hUSBItem = hItem ? hItem : Node; hUSBItem = TREEVIEW_InsertItem(hTree, TREEVIEW_ITEM_TYPE_NODE, hUSBItem, Position, "USB Disk"); } if(k_StorageGetStatus(MSD_DISK_UNIT) == 1) { ShowNodeContent(hTree, hItem, mSDDISK_Drive, pFileList); } if(k_StorageGetStatus(USB_DISK_UNIT) == 1) { ShowNodeContent(hTree, hUSBItem, USBDISK_Drive, pFileList); } TREEVIEW_SetAutoScrollH(hTree, 1); TREEVIEW_SetAutoScrollV(hTree, 1); TREEVIEW_SetIndent(hTree, 22); hItem = TREEVIEW_GetItem(hTree, 0, TREEVIEW_GET_FIRST); TREEVIEW_ITEM_Expand(hItem); hItem = TREEVIEW_GetItem(hTree, hItem, TREEVIEW_GET_FIRST_CHILD); if(hItem != 0) { TREEVIEW_ITEM_Expand(hItem); hItem = TREEVIEW_GetItem(hTree, hItem, TREEVIEW_GET_NEXT_SIBLING); if(hItem != 0) { TREEVIEW_ITEM_Expand(hItem); } } WM_SetFocus(hTree); }
/** * @brief Finds full path of selected file. * @param hObj: object handle * @param hTVItem: window handle * @param str: Pointer to str * @retval None */ void _FindFullPath(TREEVIEW_Handle hObj, TREEVIEW_ITEM_Handle hTVItem, char *str) { TREEVIEW_ITEM_INFO hInfo; char strtmp[FILEMGR_FULL_PATH_SIZE]; uint8_t Level = FILEMGR_MAX_LEVEL; /* Find File name */ TREEVIEW_ITEM_GetText(hTVItem, (uint8_t *)str, FILEMGR_FULL_PATH_SIZE); /* Find folders */ while( Level > 1) { TREEVIEW_ITEM_GetInfo(hTVItem, &hInfo); hTVItem = TREEVIEW_GetItem(hObj, hTVItem,TREEVIEW_GET_PARENT); TREEVIEW_ITEM_GetText(hTVItem, (uint8_t *)strtmp, FILEMGR_FULL_PATH_SIZE); if(strcmp(strtmp, "USB Disk") == 0) { strcpy(strtmp, "0:"); } strcat(strtmp, "/"); strcat(strtmp, str); strcpy(str, strtmp); TREEVIEW_ITEM_GetInfo(hTVItem, &hInfo); Level = hInfo.Level; } }
/** * @brief Refresh browser. * @param hWin: pointer to the parent handle * @retval None */ static void _RefreshBrowser ( WM_HWIN hWin) { WM_HWIN hItem, Hint; TREEVIEW_ITEM_Handle hTreeView; uint32_t free, total; char str[FILEMGR_FULL_PATH_SIZE]; GUI_Exec(); /* Show Hint */ Hint = WM_CreateWindowAsChild(30, 120, 180, 32, hWin, WM_CF_SHOW , _cbHint, 0); GUI_Exec(); hItem = WM_GetDialogItem(hWin, ID_PROGBAR_USB); if(k_StorageGetStatus (USB_DISK_UNIT)) { free = k_StorageGetFree(USB_DISK_UNIT); total = k_StorageGetCapacity(USB_DISK_UNIT); PROGBAR_SetValue (hItem, ((total - free) * 100)/total); hItem = WM_GetDialogItem(hWin, ID_TEXT_USB); sprintf(str, "USB Disk [%lu MB]", total / (2 * 1024)); TEXT_SetText(hItem, str); } else { PROGBAR_SetValue (hItem, 0); hItem = WM_GetDialogItem(hWin, ID_TEXT_USB); TEXT_SetText(hItem, "USB Disk [N/A]" ); } hTreeView = WM_GetDialogItem(hWin, ID_TREEVIEW); hItem = TREEVIEW_GetItem(hTreeView, 0, TREEVIEW_GET_FIRST); if(hItem != 0) { TREEVIEW_ITEM_Delete (hItem); } ExploreDisks(hTreeView); WM_DeleteWindow(Hint); }
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); } }
/** * @brief Callback routine of popup menu. * @param pMsg: pointer to data structure of type WM_MESSAGE * @retval None */ static void _cbPopup(WM_MESSAGE * pMsg) { K_GET_DIRECT_OPEN_FUNC * pfOpen; MENU_MSG_DATA* pData; TREEVIEW_ITEM_Handle hTreeView; TREEVIEW_ITEM_INFO Info; WM_HWIN hItem; char ext[4]; switch (pMsg->MsgId) { case WM_INIT_DIALOG: break; case WM_MENU: /* Process the menu message */ pData = (MENU_MSG_DATA*)pMsg->Data.p; switch (pData->MsgType) { case MENU_ON_ITEMSELECT: /* Menu item has been selected */ switch (pData->ItemId) { case ID_MENU_OPENFILE: k_GetExtOnly(SelectedFileName, ext); pfOpen = k_ModuleCheckLink(ext); if(pfOpen != NULL) { pfOpen(SelectedFileName); } else { _ShowMessageBox(hExplorerWin, "File Browser", "No external module is linked to\n this extension!", 0); } break; case ID_MENU_DELETE: if (_ShowMessageBox(hExplorerWin, "File Browser", "Are you sure you want to\ndelete selected file?", 1)) { f_unlink (SelectedFileName); _RefreshBrowser(hExplorerWin); } break; case ID_MENU_PROPRIETIES: if(hFileInfo == 0) { hFileInfo = GUI_CreateDialogBox(_aFileInfoDialogCreate, GUI_COUNTOF(_aFileInfoDialogCreate), _cbFileInfoDialog, hExplorerWin, 5, 75); } break; case ID_MENU_EXIT: break; } hItem = WM_GetDialogItem(hExplorerWin, ID_TREEVIEW); hTreeView = TREEVIEW_GetSel(hItem); TREEVIEW_ITEM_GetInfo(hTreeView, &Info); if(Info.IsNode == 0) { /*Force Deselect item */ hTreeView = TREEVIEW_GetItem(hItem, hTreeView, TREEVIEW_GET_PARENT); TREEVIEW_SetSel(hItem, hTreeView); } } break; default: WM_DefaultProc(pMsg); break; } }
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; }
/********************************************************************* * * _cbPage1 * * Purpose: * Callback routine for the second page of the multipage widget */ static void _cbPage1(WM_MESSAGE * pMsg) { TREEVIEW_ITEM_Handle hTVI0, hTVI1; TREEVIEW_ITEM_INFO ItemInfo; WM_HWIN hItem, hDlg, hTree0, hTree1; int i, NCode, Id; hDlg = pMsg->hWin; switch (pMsg->MsgId) { case WM_NOTIFY_PARENT: hTree0= WM_GetDialogItem(WM_GetFirstChild(WM_HBKWIN), GUI_ID_TREEVIEW0); hTree1= WM_GetDialogItem(WM_GetFirstChild(WM_HBKWIN), GUI_ID_TREEVIEW1); Id = WM_GetId(pMsg->hWinSrc); /* Id of widget */ NCode = pMsg->Data.v; /* Notification code */ hItem = WM_GetDialogItem(hDlg, Id); switch (Id) { case GUI_ID_BUTTON0: /* Delete */ switch (NCode) { case WM_NOTIFICATION_RELEASED: hTVI0 = TREEVIEW_GetSel(hTree0); if (hTVI0) { TREEVIEW_ITEM_Delete(hTVI0); } else { GUI_MessageBox("No item selected!", "Info", GUI_MESSAGEBOX_CF_MODAL); WM_SetFocus(hTree0); } break; } break; case GUI_ID_BUTTON1: /* Detach */ switch (NCode) { case WM_NOTIFICATION_RELEASED: hTVI1 = TREEVIEW_GetItem(hTree1, 0, TREEVIEW_GET_FIRST); if (hTVI1) { TREEVIEW_ITEM_Delete(hTVI1); } hTVI0 = TREEVIEW_GetSel(hTree0); TREEVIEW_ITEM_Detach(hTVI0); TREEVIEW_AttachItem(hTree1, hTVI0, 0, TREEVIEW_GET_FIRST); break; } break; case GUI_ID_BUTTON2: /* Attach */ switch (NCode) { case WM_NOTIFICATION_RELEASED: hTVI1 = TREEVIEW_GetItem(hTree1, 0, TREEVIEW_GET_FIRST); if (hTVI1) { hTVI0 = TREEVIEW_GetSel(hTree0); TREEVIEW_ITEM_Detach(hTVI1); if (hTVI0) { TREEVIEW_AttachItem(hTree0, hTVI1, hTVI0, TREEVIEW_INSERT_ABOVE); } else { TREEVIEW_AttachItem(hTree0, hTVI1, 0, 0); } } else { GUI_MessageBox("No item in buffer!", "Info", GUI_MESSAGEBOX_CF_MODAL); WM_SetFocus(hTree0); } break; } break; case GUI_ID_BUTTON3: /* Move up */ switch (NCode) { case WM_NOTIFICATION_RELEASED: hTVI0 = TREEVIEW_GetSel(hTree0); if (hTVI0) { hTVI1 = TREEVIEW_GetItem(hTree0, hTVI0, TREEVIEW_GET_PREV_SIBLING); if (hTVI1) { TREEVIEW_ITEM_Detach(hTVI0); TREEVIEW_AttachItem(hTree0, hTVI0, hTVI1, TREEVIEW_INSERT_ABOVE); TREEVIEW_SetSel(hTree0, hTVI0); } else { GUI_MessageBox("Item is already on top!", "Info", GUI_MESSAGEBOX_CF_MODAL); WM_SetFocus(hTree0); } } break; } break; case GUI_ID_BUTTON4: /* Move down */ switch (NCode) { case WM_NOTIFICATION_RELEASED: hTVI0 = TREEVIEW_GetSel(hTree0); if (hTVI0) { hTVI1 = TREEVIEW_GetItem(hTree0, hTVI0, TREEVIEW_GET_NEXT_SIBLING); if (hTVI1) { TREEVIEW_ITEM_Detach(hTVI0); TREEVIEW_AttachItem(hTree0, hTVI0, hTVI1, TREEVIEW_INSERT_BELOW); TREEVIEW_SetSel(hTree0, hTVI0); } else { GUI_MessageBox("Item is already on bottom!", "Info", GUI_MESSAGEBOX_CF_MODAL); WM_SetFocus(hTree0); } } break; } break; case GUI_ID_BUTTON5: /* New node */ switch (NCode) { case WM_NOTIFICATION_RELEASED: hTVI0 = TREEVIEW_GetSel(hTree0); if (hTVI0) { TREEVIEW_ITEM_GetInfo(hTVI0, &ItemInfo); if (ItemInfo.IsNode) { hTVI0 = TREEVIEW_InsertItem(hTree0, TREEVIEW_ITEM_TYPE_NODE, hTVI0, TREEVIEW_INSERT_BELOW, "New node"); } else { hTVI0 = TREEVIEW_InsertItem(hTree0, TREEVIEW_ITEM_TYPE_NODE, hTVI0, TREEVIEW_INSERT_ABOVE, "New node"); } } else { hTVI0 = TREEVIEW_InsertItem(hTree0, TREEVIEW_ITEM_TYPE_NODE, 0, 0, "New node"); } hTVI0 = TREEVIEW_InsertItem(hTree0, TREEVIEW_ITEM_TYPE_LEAF, hTVI0, TREEVIEW_INSERT_FIRST_CHILD, "New.A"); hTVI0 = TREEVIEW_InsertItem(hTree0, TREEVIEW_ITEM_TYPE_LEAF, hTVI0, TREEVIEW_INSERT_BELOW, "New.B"); hTVI0 = TREEVIEW_InsertItem(hTree0, TREEVIEW_ITEM_TYPE_LEAF, hTVI0, TREEVIEW_INSERT_BELOW, "New.C"); hTVI0 = TREEVIEW_InsertItem(hTree0, TREEVIEW_ITEM_TYPE_LEAF, hTVI0, TREEVIEW_INSERT_BELOW, "New.D"); break; } break; case GUI_ID_BUTTON6: /* New leaf */ switch (NCode) { case WM_NOTIFICATION_RELEASED: hTVI0 = TREEVIEW_GetSel(hTree0); if (hTVI0) { TREEVIEW_ITEM_GetInfo(hTVI0, &ItemInfo); hTVI0 = TREEVIEW_InsertItem(hTree0, TREEVIEW_ITEM_TYPE_LEAF, hTVI0, TREEVIEW_INSERT_BELOW, "New leaf"); } else { hTVI0 = TREEVIEW_InsertItem(hTree0, TREEVIEW_ITEM_TYPE_LEAF, 0, 0, "New leaf"); } break; } break; case GUI_ID_BUTTON7: /* Leaf bitmap */ switch (NCode) { case WM_NOTIFICATION_RELEASED: hTVI0 = TREEVIEW_GetSel(hTree0); if (hTVI0) { TREEVIEW_ITEM_GetInfo(hTVI0, &ItemInfo); if (ItemInfo.IsNode == 0) { TREEVIEW_ITEM_SetImage(hTVI0, TREEVIEW_BI_LEAF, &_bmSmilie); } else { GUI_MessageBox("Item is not a leaf!", "Info", GUI_MESSAGEBOX_CF_MODAL); WM_SetFocus(hTree0); } } else { GUI_MessageBox("No item selected!", "Info", GUI_MESSAGEBOX_CF_MODAL); WM_SetFocus(hTree0); } break; } break; case GUI_ID_BUTTON8: /* Open bitmap */ switch (NCode) { case WM_NOTIFICATION_RELEASED: hTVI0 = TREEVIEW_GetSel(hTree0); if (hTVI0) { TREEVIEW_ITEM_GetInfo(hTVI0, &ItemInfo); if (ItemInfo.IsNode) { TREEVIEW_ITEM_SetImage(hTVI0, TREEVIEW_BI_OPEN, &_bmBookOpen); } else { GUI_MessageBox("Item is not a node!", "Info", GUI_MESSAGEBOX_CF_MODAL); WM_SetFocus(hTree0); } } else { GUI_MessageBox("No item selected!", "Info", GUI_MESSAGEBOX_CF_MODAL); WM_SetFocus(hTree0); } break; } break; case GUI_ID_BUTTON9: /* Closed bitmap */ switch (NCode) { case WM_NOTIFICATION_RELEASED: hTVI0 = TREEVIEW_GetSel(hTree0); if (hTVI0) { TREEVIEW_ITEM_GetInfo(hTVI0, &ItemInfo); if (ItemInfo.IsNode) { TREEVIEW_ITEM_SetImage(hTVI0, TREEVIEW_BI_CLOSED, &_bmBookClosed); } else { GUI_MessageBox("Item is not a node!", "Info", GUI_MESSAGEBOX_CF_MODAL); WM_SetFocus(hTree0); } } else { GUI_MessageBox("No item selected!", "Info", GUI_MESSAGEBOX_CF_MODAL); WM_SetFocus(hTree0); } break; } break; } break; case WM_INIT_DIALOG: /* Initialize the items of the dialog */ for (i = GUI_ID_BUTTON0; i <= GUI_ID_BUTTON9; i++) { hItem = WM_GetDialogItem(hDlg, i); if (hItem) { BUTTON_SetFocussable(hItem, 0); /* So the focus remains on the treeview after pressing the buttons */ } } break; default: WM_DefaultProc(pMsg); } }