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

📄 appform.c

📁 高通brew平台上的BUIW控件中的ImageStaticWidget使用示例
💻 C
📖 第 1 页 / 共 2 页
字号:
#include "AEEDialog.h"
#include "AEERootForm.h"
#include "AEEPopUp.h"
//#include "AEEScrollWidget.h"
//#include "AEEWProperties.h"
#include "AEEXYContainer.h"
//#include "AEEPropContainer.h"
#include "AEEStaticWidget.h"
//#include "AEEListWidget.h"
//#include "AEEArrayModel.h"
#include "AEEStdLib.h"
#include "AEEImageStaticWidget.h"

#include "AppForm.h"
#include "WidgetTest.bid"
#include "WidgetTest.brh"


// app form structure
struct AppForm {
	IShell* piShell;
	IRootForm* rootForm;
	
	IForm* mainForm;
	HandlerDesc mainFormHandler;
	
	IDialog* exitConfirmationDialog;
	HandlerDesc exitConfirmationHandler;
	
	IPopupMenu* optionsMenu;
	HandlerDesc optionsMenuHandler;

	IWidget* ImageStaticWidget;
	uint32 dwImageStaticFlags;
	IXYContainer* mainContainer;

	int16 dwCurrentImageID;
};

#define WIDGETTEST_RES_FILE "widgettest.bar"


int AppForm_CreateExitConfDialog(AppForm* pMe);
int AppForm_CreateOptionsMenu(AppForm* pMe);

void AppForm_Delete(AppForm* pMe) {
	if(pMe->mainForm)
		IFORM_Release(pMe->mainForm);
	if(pMe->exitConfirmationDialog)
		IDIALOG_Release(pMe->exitConfirmationDialog);
	if(pMe->optionsMenu)
		IPOPUPMENU_Release(pMe->optionsMenu);
	if(pMe->mainContainer)
		IXYCONTAINER_Release(pMe->mainContainer);
	if(pMe->ImageStaticWidget)
		IWIDGET_Release(pMe->ImageStaticWidget);
	if(pMe)
		FREE(pMe);
}

static boolean AppForm_HandleEvent(void *po, AEEEvent evt, uint16 wParam, uint32 dwParam)
{
	AppForm* pMe = (AppForm*) po;
	int result = 0;
	
	switch (evt) {
	case EVT_KEY:
		switch (wParam) {
		case AVK_SOFT1:
			result = AppForm_CreateOptionsMenu(pMe);
			if (result == 0)
				IROOTFORM_PushForm(pMe->rootForm, (IForm*)pMe->optionsMenu);
			return TRUE;
		case AVK_SOFT2:
			result = AppForm_CreateExitConfDialog(pMe);
			if(result == 0)
				IROOTFORM_PushForm(pMe->rootForm, (IForm*)pMe->exitConfirmationDialog);
			return TRUE;
		case AVK_CLR:
			return TRUE;
		}
		break;
//	case EVT_KEY_PRESS:
//		switch (wParam) {
//		case AVK_END:
//			result = AppForm_CreateExitConfDialog(pMe);
//			if(result == 0)
//				IROOTFORM_PushForm(pMe->rootForm, (IForm*)pMe->exitConfirmationDialog);
//			return TRUE;
//		}
//		break;
	}
	//the  default form handler is swapped with the AppForm handler
	// calling this allows the default form handler to handle the event
	return HANDLERDESC_Call(&pMe->mainFormHandler, evt, wParam, dwParam);
}


// Warning dialog handler event
static boolean exitConfirmationDialog_HandleEvent(void *po, AEEEvent evt, uint16 wParam, uint32 dwParam)
{
	AppForm* pMe = (AppForm*) po;
	
	if(evt == EVT_KEY) {
		
		switch(wParam) {
		case AVK_SOFT1:
			//okay: exit app
			ISHELL_CloseApplet(pMe->piShell, TRUE);
			return TRUE;
			
		case AVK_SOFT2:
		case AVK_CLR:
			// release exit conf dialog
			if(pMe->exitConfirmationDialog) {
				IDIALOG_Release(pMe->exitConfirmationDialog);
				pMe->exitConfirmationDialog = NULL;
			}
		}
	}
	
	//the  default form handler is swapped with the exitConfirmationForm handler
	// calling this allows the default form handler to handle the event
	return HANDLERDESC_Call(&pMe->exitConfirmationHandler, evt, wParam, dwParam);
}

static boolean OptionsEventHandler(void *po, AEEEvent evt, uint16 wParam, uint32 dwParam)
{
	AppForm* pMe = (AppForm*) po;

	// 设置窗体的显示位置以及大小
	if(evt == EVT_WDG_GETPROPERTY && wParam == FID_PREFRECT) {
		AEERect rc;
		rc.x = 1;
		rc.y = 57;
		rc.dx = 80;
		rc.dy = 131;
		*(AEERect*) dwParam = rc;
		return TRUE;
	}
	
	if(evt == EVT_KEY && wParam == AVK_CLR) {
		if(pMe->optionsMenu) {
			IPOPUPMENU_Release(pMe->optionsMenu);
			pMe->optionsMenu = NULL;
		}
	}

	//the  default form handler is swapped with the AppForm handler
	// calling this allows the default form handler to handle the event
	return HANDLERDESC_Call(&pMe->optionsMenuHandler, evt, wParam, dwParam);
}

static void AppForm_ImageStaticInfoFree(void* pData)
{
	ImageStaticInfo *ptImageStaticInfo = (ImageStaticInfo*)pData;
	FREEIF(ptImageStaticInfo->pwText);
	if(ptImageStaticInfo && ptImageStaticInfo->piImage)
		IIMAGE_Release(ptImageStaticInfo->piImage);
	FREEIF(ptImageStaticInfo);
}

static void OptionSelectionHandler(AppForm* pMe, int idOption) 
{
	int result = 0;
	int iBorderWidth = 0;
	uint32 dwFlags = 0;
	IWidget *iwStatic = NULL, *iwImage = NULL;

	IValueModel *pivm = NULL;
	int nValueLen = sizeof(ImageStaticInfo);
	ImageStaticInfo *ptImageStaticInfo = NULL, *ptInfoNew = NULL;

	switch(idOption) {
	case MENUITEM_SETBORDER:	// 设置控件边框
		// 可以给控件加上边框,也可以去掉边框
		IWIDGET_GetBorderWidth(pMe->ImageStaticWidget, &iBorderWidth);
		if(iBorderWidth>0)
			IWIDGET_SetBorderWidth(pMe->ImageStaticWidget, 0);
		else
		{
			IWIDGET_SetBorderColor(pMe->ImageStaticWidget,RGB_BLACK);
			IWIDGET_SetBorderWidth(pMe->ImageStaticWidget,1);
		}
		break;

	case MENUITEM_SETSTATICFLAGS:		// 设置字体对齐
		// ImageStaticWidget控件是由两个控件组合而成,设置自字体的属性,必须先将字体的Widget取出来
		IWIDGET_GetImageStaticStaticWidget(pMe->ImageStaticWidget, &iwStatic);
		// 把Static当前的标志取出来
		IWIDGET_GetFlags(iwStatic, &dwFlags);
		// 我们这里设置了顶部/中心/底部对齐
		if(dwFlags & IDF_ALIGN_MIDDLE) {
			dwFlags &= ~IDF_ALIGN_MIDDLE;
			dwFlags |= IDF_ALIGN_BOTTOM;
		} else if(dwFlags & IDF_ALIGN_BOTTOM) {
			dwFlags &= ~IDF_ALIGN_BOTTOM;
			dwFlags |= IDF_ALIGN_TOP;
		} else {
			dwFlags &= ~IDF_ALIGN_TOP;
			dwFlags |= IDF_ALIGN_MIDDLE;
		}
		// 设置控件的标志
		IWIDGET_SetFlags(iwStatic, dwFlags);
		// 将字体的Widget控件重新设进去
		IWIDGET_SetImageStaticStaticWidget(pMe->ImageStaticWidget, iwStatic);
		IWIDGET_Release(iwStatic);
		break;
	case MENUITEM_SETFLAG:				// 设置图片位置
		//IWIDGET_GetFlags(pMe->ImageStaticWidget, &dwFlags);							// ??这个函数无法取到正确的dwFlags
		// 真没有用,连文本原来的对齐方式都要我来维护,不维护就是顶部对齐
		IWIDGET_GetImageStaticStaticWidget(pMe->ImageStaticWidget, &iwStatic);
		IWIDGET_GetFlags(iwStatic, &dwFlags);
		// 由于GetFlags和SetImageStaticFlags都无法正常使用,dwFlags要自己记录,这里一定要改进
		if(pMe->dwImageStaticFlags & ISWF_LAYOUT_IMAGERIGHT)
		{
			IWIDGET_RemoveFlags(pMe->ImageStaticWidget, ISWF_LAYOUT_IMAGERIGHT);
			pMe->dwImageStaticFlags &= ~ISWF_LAYOUT_IMAGERIGHT;
		}
		else
		{
			IWIDGET_AddFlags(pMe->ImageStaticWidget, ISWF_LAYOUT_IMAGERIGHT);
			pMe->dwImageStaticFlags |= ISWF_LAYOUT_IMAGERIGHT;
		}
		// 将文本对齐的方式设置回去,真是垃圾,在控件里完全可以完成的
		IWIDGET_SetFlags(iwStatic, dwFlags);
		IWIDGET_SetImageStaticStaticWidget(pMe->ImageStaticWidget, iwStatic);
		IWIDGET_Release(iwStatic);
		//IWIDGET_SetImageStaticFlags(pMe->ImageStaticWidget, IDF_ALIGN_RIGHT);			// ??这个函数不能用
		break;
	case MENUITEM_UPDATEIMAGE:			// 更换图片
		// 先通过ValueModel获取旧的ImageStaticInfo,主要是保留原来的Static
		IWIDGET_GetModel(pMe->ImageStaticWidget, AEEIID_VALUEMODEL, (IModel**)&pivm);
		ptImageStaticInfo = IVALUEMODEL_GetValue(pivm, &nValueLen);

		// 初始化新结构
		ptInfoNew = MALLOCREC(ImageStaticInfo);
		ptInfoNew->pwText = (AECHAR*)MALLOC(128);
		// 将原来的文本保留
		WSTRCPY(ptInfoNew->pwText, ptImageStaticInfo->pwText);
		// 读取另一张图片
		if(pMe->dwCurrentImageID == IMAGE1_OF_WIDGET) {

⌨️ 快捷键说明

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