//-------------------------------------------------------------------------------
//
//	FILE: main_menu.c
//
//	IMenuCtl interfaceのサブプログラム 
//
//-------------------------------------------------------------------------------

#include "MenuCtl.h"
#include "menu_res.h"
#include "main_res.h"


//	CreateMenuCtl :: メインメニューコントロールの作成
boolean CreateMenuCtl( MyApp *pApp )
{
	// 作業変数の定義
	AEECLSID		cls;
	AEEDeviceInfo	di;
	AEERect			adummy;
	int				ierror;
	AEEItemStyle	rNormalStyle;
	AEEItemStyle	rSelStyle;
	boolean			bRet;
	
	// 初期化
	bRet = FALSE;
	
	// NULLチェック
	if ( pApp == NULL )
	{
		DBGPRINTF( "pApp is NULL" );
		return bRet;
	}
	
	
	// メニューコントロールの作成
	switch ( pApp->ctype )
	{
	case MENUCTL:
		cls = AEECLSID_MENUCTL;
		break;
	case LISTCTL:
		cls = AEECLSID_LISTCTL;
		break;
	case ICONVIEWCTL:
		cls = AEECLSID_ICONVIEWCTL;
		break;
	default:
		cls = 1;
		break;
	}
	
	// インスタンス作成
	ierror = ISHELL_CreateInstance( pApp->app.m_pIShell, cls, (void**)&pApp->pimc );
	
	if ( ierror == 0 )
	{
		// 領域設定
		SETAEERECT( &adummy, 0, 0, 0, 0 );
		IHTMLVIEWER_SetRect( pApp->m_pihv, &adummy );
		IDISPLAY_ClearScreen( pApp->app.m_pIDisplay );
		
		// 最大描画サイズ設定
		ISHELL_GetDeviceInfo( pApp->app.m_pIShell, &di );
		SETAEERECT( &pApp->arect, 0, 0, di.cxScreen, di.cyScreen );
		
		// IMENUCTL_SetRect()の試験
		test_SetRect( pApp, &pApp->arect );
		
		// IMENUCTL_SetTitle()の試験
		test_SetTitle( pApp, MENU_RES_FILE, TITLE, NULL );
		
		// スタイル設定
		// 処理中･･･
		disp_mng( pApp );
		
		switch ( pApp->ctype )
		{
		case MENUCTL:
		case ICONVIEWCTL:
			ISHELL_GetItemStyle( pApp->app.m_pIShell, AEE_IT_MENU, &rNormalStyle, &rSelStyle );
			rNormalStyle.roImage = AEE_RO_TRANSPARENT;
			rSelStyle.roImage = AEE_RO_TRANSPARENT;
			// IMENUCTL_SetStyle()の試験
			test_SetStyle( pApp, &rNormalStyle, &rSelStyle );
			
			// 項目作成
			if ( pApp->ctype == MENUCTL )
			{
				make_MenuItem( pApp );
			}
			else
			{
				make_OtherItem( pApp );
			}
			
			break;
		case LISTCTL:
			// 項目作成
			make_OtherItem( pApp );
			break;
		default:
			break;
		}
		
		// メニュー画面アクティブ化
		test_SetActive( pApp, TRUE );
		
		bRet = TRUE;
	}
	
	return bRet;
}

void make_MenuItem( MyApp *pApp )
{
	CtlAddItem		Cai;
	int				nLoop;
	uint16			unTbl[2][CNT_MENUITEM] 
						= { {TEXT1, TEXT2, TEXT3, TEXT4, TEXT5, TEXT6, TEXT7, TEXT8, TEXT9, TEXT10, TEXT11, TEXT12, TEXT13, TEXT14 },
							{0,     1,     2,     3,     4,     5,     6,     7,     8,     9,      10,     11,     12,     13 } };
	
	// default
	Cai.pText = NULL;
	Cai.pImage = NULL;
	Cai.wFont = TEST_FONT;
	Cai.pszResImage = MAIN_RES_FILE;
	Cai.pszResText = MAIN_RES_FILE;
	
	for ( nLoop = 0; nLoop < CNT_MENUITEM; nLoop++ )
	{
		Cai.wText = unTbl[0][nLoop];
		Cai.wImage = IMAGE1+nLoop;
		Cai.wItemID = (uint16)unTbl[1][nLoop];
		Cai.dwData = (uint32)unTbl[1][nLoop];
		
		test_AddItemEx( pApp, &Cai );
	}
	
	return;
}

void make_OtherItem( MyApp *pApp )
{
	CtlAddItem		Cai;
	int				nLoop;
	uint16			unTbl[2][CNT_OTHERITEM]
						= { {TEXT1, TEXT2, TEXT3, TEXT4, TEXT5, TEXT7, TEXT8, TEXT9, TEXT10, TEXT11, TEXT12, TEXT13, TEXT14 },
							{0,     1,     2,     3,     4,     6,     7,     8,     9,      10,     11,     12,     13 } };
	
	// default
	Cai.pText = NULL;
	Cai.pImage = NULL;
	Cai.wFont = TEST_FONT;
	Cai.pszResImage = MAIN_RES_FILE;
	Cai.pszResText = MAIN_RES_FILE;
	
	for ( nLoop = 0; nLoop < CNT_OTHERITEM; nLoop++ )
	{
		Cai.wText = unTbl[0][nLoop];
		Cai.wImage = IMAGE1+nLoop;
		Cai.wItemID = (uint16)unTbl[1][nLoop];
		Cai.dwData = (uint32)unTbl[1][nLoop];
		
		test_AddItemEx( pApp, &Cai );
	}
	
	return;
}
