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

📄 mainmenu.c

📁 brew 文件浏览器实现,是纯c编写的
💻 C
字号:
//////////////////////////////////////////////////////////////////////////
//mainmenu.c
//////////////////////////////////////////////////////////////////////////


#include "MainMenu.h"
#include "Comm_FileMgr.h"

static boolean MainMenu_HandleCommandEvent(MainMenu* pthis,uint16 wParam,uint32 dwParam);
static boolean MainMenu_HandleKeyEvent(MainMenu* pthis,uint16 wPram);
static boolean MainMenu_HandlePenEvent(MainMenu* pthis,AEEEvent eCode,uint32 dwparam);

static void  MainMenuUpdate(MainMenu* pthis);

/************************************************************************
初始化菜单内部数据。
	@pthis菜单内部数据结构指针。
	@pMe主程序内部数据结构指针。
	@返回是否初始化失败。
************************************************************************/
boolean MainMenuNew(MainMenu* pthis,MFileMgr* pMe)
{
    pthis->pMe=pMe;
	pthis->menu=NULL;

	pthis->curFile=(char*)MALLOC(MAX_FILE_NAME*2);

	 if (pthis->curFile == NULL) {
		   return FALSE;
	   }

  pthis->srcFile=pthis->curFile+MAX_FILE_NAME;

   return TRUE;
}

/************************************************************************
创建菜单窗口。
	@pthis菜单内部数据结构指针。
	@返回是否创建成功。
************************************************************************/
boolean MainMenuOpen(MainMenu* pthis)
{
    uint16 fh=0;
	uint16 fw=0;
	AEERect rect;
	AECHAR wp[AEE_MAX_FILE_NAME]={0};

   
	if (SUCCESS != (ISHELL_CreateInstance(pthis->pMe->a.m_pIShell,AEECLSID_MENUCTL,
		(void**)&pthis->menu))) 
	{
		return FALSE;
	}


	if((fh=IDisplay_GetFontMetrics(pthis->pMe->a.m_pIShell,AEE_FONT_NORMAL,0,0)) == EFAILED)
	{
		fh=15; // if get font height failue,then set the default height 15.
	}
     
	//set rect fo menu

	if (BASENAME(pthis->curFile) == "") {
		rect.dy=(fh+1)*5;
	}
	else
	{
		rect.dy=(fh+1)*3;
	}
    rect.dx=pthis->pMe->xScreen;
	rect.x=5;
	rect.y=pthis->pMe->yScreen-fh-1-rect.dy;	

	IMENUCTL_SetRect(pthis->menu,&rect);

	// If is  a folder or file.
	if (BASENAME(pthis->curFile) == "") 
	{
		//add create file item
         IMENUCTL_AddItem(pthis->menu,RES_FILE,IDS_CREATE_FILE,IDM_CREATE_FILE,0,0);
        //add create folder item
		 IMENUCTL_AddItem(pthis->menu,RES_FILE,IDS_CREATE_FOLDER,IDM_CREATE_FOLDER,0,0);
		//add delete folder item
		 IMENUCTL_AddItem(pthis->menu,RES_FILE,IDS_DELETE_FOLDER,IDM_DELETE_FOLDER,0,0);
		//add search file item
		 IMENUCTL_AddItem(pthis->menu,RES_FILE,IDS_SEARCH_FILE,IDM_SEARCH_FILE,0,0);
		//add paste file item
		 IMENUCTL_AddItem(pthis->menu,RES_FILE,IDS_PASTE_FILE,IDM_PASTE_FILE,0,0);
	}
	else
	{ 
			// Add rename file item
		 IMENUCTL_AddItem(pthis->menu,RES_FILE,IDS_RENAME_FILE,IDM_RENAME_FILE,0,0);
			// Add delete file item
		 IMENUCTL_AddItem(pthis->menu,RES_FILE,IDS_DELETE_FILE,IDM_DELETE_FILE,0,0);
			// Add copy file item
		 IMENUCTL_AddItem(pthis->menu,RES_FILE,IDS_COPY_FILE,IDM_COPY_FILE,0,0);
	}

	//draw softkey selection

	if (0 == LoadResString(pthis->pMe->a.m_pIShell,RES_FILE,IDS_MENU_OK,wp,sizeof(wp)))
	{
		IDISPLAY_DrawText(pthis->pMe->a.m_pIShell,AEE_FONT_NORMAL,wp,-1,0,
			pthis->pMe->yScreen+fh,0,0);
	}

	if (0 == LoadResString(pthis->pMe->a.m_pIShell,RES_FILE,IDS_MENU_CANCEL,wp,sizeof(wp)))
	{
		if (0 == (fw=ISHELL_MeasureText(pthis->pMe->a.m_pIShell,wp))) {
                   fw=20;  //if get font widht failue,then set default 20 width.
		}

		IDISPLAY_DrawText(pthis->pMe->a.m_pIShell,AEE_FONT_NORMAL,wp,-1,
			pthis->pMe->xScreen-fw-1);
	}

	MainMenuUpdate(pthis);

	return TRUE;
}

/************************************************************************
更新屏幕。
	@pthis主菜单内部数据结构。
************************************************************************/
static void MainMenuUpdate(MainMenu* pthis)
{
	IMENUCTL_SetActive(pthis->menu);
	IMENUCTL_Redraw(pthis->pMe);
}

/************************************************************************
菜单事件处理函数。
	@pthis主菜单内部数据结构。
	@eCode消息类型。
	@wPram,dwParam消息附带数据。
	@返回是否处理了消息。
************************************************************************/
boolean MainMenu_HandleEvent(MainMenu* pthis,AEEEvent eCode,uint16 wParam,uint32 dwParam)
{
  switch(eCode) {
  case EVT_COMMAND:
  	return MainMenu_HandleCommandEvent(pthis,wParam,dwParam);
  case EVT_KEY:
	  if ((wParam==EVK_SOFT1) || (wParam==EVK_SOFT2)) {
            return MainMenu_HandleKeyEvent(pthis,wParam);
	  }
      else
	  {
		  return IMENUCTL_HandleEvent(pthis->menu,eCode,wParam,dwParam); 
	  }		  
  case EVT_APP_SUSPEND:
	  return TRUE;
  case  EVT_APP_RESUME:
	  MainMenuUpdate(pthis);
	  return TRUE;
  default:
	  return FALSE;
  }

  return FALSE;
}


/************************************************************************
处理用户按键事件.
	@pthis菜单内部数据结构指针。
	@wParam按键代码。
	@返回是否对按键进行了处理。
************************************************************************/
static boolean MainMenu_HandleKeyEvent(MainMenu* pthis,uint16 wPram)
{
   switch(wPram) {
   case EVK_SOFT1:
	   //open textinupt window or list window.
   	break;
   case EVK_SOFT2:
	   //open list window 
   	break;
   default:
   }
   return FALSE;
}

/************************************************************************
处理命令事件信息。
	@pthis菜单显示内部数据结构。
	@wParam菜单的命令id。
	@dwParam菜单的附带数据。
	@返回是否对消息进行了处理。
************************************************************************/
static boolean MainMenu_HandleCommandEvent(MainMenu* pthis,uint16 wParam,uint32 dwParam)
{

	char dstname[AEE_MAX_FILE_NAME]={0};

	switch(wParam) {
	case IDM_CREATE_FILE:
		// user not input file name
		if (pthis->pMe->textinput.id <= 0) 
		{
			pthis->pMe->textinput.id=IDM_CREATE_FILE;
             SetActiveWindow(pthis->pMe,IDW_TEXTINPUT);
		}
		else
		{

			pthis->pMe->textinput.id=0;
			
			STRCAT(pthis->curFile,pthis->pMe->textinput.itext);

			CreateFile(pthis->curFile);

			SetActiveWindow(pthis->pMe,IDW_LISTWND);
		}
		return TRUE;
	case IDM_CREATE_FOLDER:
		// if user not input folder name.
		if (pthis->pMe->textinput.id <= 0) 
		{
            pthis->pMe->textinput.id=IDM_CREATE_FOLDER;
			SetActiveWindow(pthis->pMe,IDW_TEXTINPUT);
		}
		else
		{
			pthis->pMe->textinput.id=0;
			
			STRCAT(pthis->curFile,pthis->pMe->textinput.itext);
			
			STRCAT(pthis->curFile,"/");
			
			CreateDir(pthis->curFile);
			
			SetActiveWindow(pthis->pMe,IDW_LISTWND);
		}
		return TRUE;
    case IDM_DELETE_FOLDER:
		DeleteDir(pthis->curFile);
	   return TRUE;
	case  IDM_SEARCH_FILE:
	    if (pthis->pMe->textinput.id <= 0) 
		{
			pthis->pMe->textinput.id=IDM_SEARCH_FILE;
			SetActiveWindow(pthis->pMe,IDW_TEXTINPUT);
	    }
		else
		{
			pthis->pMe->textinput.id=0;
			
			SearchFile(pthis->curFile,pthis->pMe->textinput.itext,NULL);
		}
		return TRUE;
	case IDM_RENAME_FILE:
		if (pthis->pMe->textinput.id <= 0) 
		{
			pthis->pMe->textinput.id=IDM_RENAME_FILE;
			SetActiveWindow(pthis->pMe,IDW_TEXTINPUT);
		}
		else
		{
			pthis->pMe->textinput.id=0;

			STRCPY(dstname,pthis->curFile);

			STRCPY((char*)BASENAME(dstname),pthis->pMe->textinput.itext);

			RenameFile(pthis->curFile,dstname);
		}
		return TRUE;
    case IDM_DELETE_FILE:
		DeleteFile(pthis->curFile);
		return TRUE;
    case IDM_COPY_FILE:
		STRCPY(pthis->srcFile,pthis->curFile);
		SetActiveWindow(pthis->pMe,IDW_LISTWND);
		return TRUE;
	case IDM_PASTE_FILE:
		CopyFile(pthis->srcFile,pthis->curFile);
		SetActiveWindow(pthis->pMe,IDW_LISTWND);
		return TRUE;
	default:
		return FALSE;
	}
	return FALSE;
}

/************************************************************************
指针事件。
	@pthis菜单界面内部数据结构。
	@eCode指针事件类型。
	@dwParam低16位是y坐标,高16位是x坐标。
	@返回是否对事件进行了处理。
************************************************************************/
static boolean MainMenu_HandlePenEvent(MainMenu* pthis,AEEEvent eCode,uint32 dwparam)
{
	return FALSE;
}

/************************************************************************
关闭菜单。
	@pthis菜单内部数据指针。
************************************************************************/
void MainMenuClose(MainMenu* pthis)
{
    if (pthis->menu) {
		IMENUCTL_Release(pthis->menu);
		pthis->menu=NULL;
    }
}

void MainMenuRelease(MainMenu* pthis)
{
	
	if (pthis->curFile) {
		FREEIF(pthis->curFile);
	}

}

⌨️ 快捷键说明

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