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

📄 testsliderwidget.c

📁 滑动控件的使用哈,只是测试用, 一起共享受一下资源是!
💻 C
字号:
/*===========================================================================
Demo of Brew BUIW Slider Widget
Version 1.00
FILE: SliderWidgetDemo.c 
zhangjunzhi@yulong.com
2006.05.18
===========================================================================*/

/*===============================================================================
INCLUDES AND VARIABLE DEFINITIONS
=============================================================================== */
#include "AEEModGen.h"          // Module interface definitions
#include "AEEAppGen.h"          // Applet interface definitions
#include "AEEShell.h"           // Shell interface definitions
#include "AEEForm.h"
#include "AEERootForm.h"

//#include "AEEDialog.h"
#include "AEERootForm.h"
#include "AEEWProperties.h"
#include "AEEXYContainer.h"
#include "AEEPropContainer.h"
#include "AEEStaticWidget.h"
#include "AEEStdLib.h"
#include "AEESliderWidget.h"
#include "AEETextWidget.h"
#include "AEETextModel.h"
#include "ScrollWidget.h"

//#include "AEECLSID_YLSCROLLWIDGET_bid.h"
#include "YLScrollWidget.h"

#include "testsliderwidget.bid"		// class ID
#include "testsliderwidget.brh"		


#define SLIDERWIDGETDEMO_RES_FILE "testsliderwidget.bar"

//define applet structure
typedef struct _sliderwidget_App {
	AEEApplet		a;
	IRootForm*		rootForm;
	IForm*			mainForm;
} sliderwidget_App;


// app form structure
typedef struct sliderwidget_AppForm sliderwidget_AppForm;

struct sliderwidget_AppForm {
	IShell*			piShell;				
	IRootForm*		rootForm;				
	
	IForm*			mainForm;				
	HandlerDesc		mainFormHandler;		
	
	IXYContainer*	mainContainer;			
//	IWidget*		numberStatic;			

	IWidget*		psliderwidget;	
    IWidget*		ptextwidget;
	
	uint8			focus;	//焦点		


	uint16			slider_maxPos;			
	uint16			slider_curPos;			

};


//定义slider滑杆颜色与手柄位置的关系
#define		sliderwidget_ACTIVE_BORDER_COLOR(pos)		MAKE_RGB(pos*25,0,255-pos*2)		

/*-------------------------------------------------------------------
Function Prototypes
-------------------------------------------------------------------*/
static boolean		sliderwidget_HandleEvent (IApplet * pi, AEEEvent eCode,uint16 wParam, uint32 dwParam);
static int			sliderwidget_InitAppData (sliderwidget_App* pMe);
static void			sliderwidget_FreeAppData (sliderwidget_App* pMe);
static int			sliderwidget_AppForm_New (IForm** ppo, IShell *piShell, IRootForm *pRootForm);
static int			sliderwidget_AppForm_PopulateMainContainer (sliderwidget_AppForm* pMe);
static boolean		sliderwidget_AppForm_HandleEvent (void *po, AEEEvent evt, uint16 wParam, uint32 dwParam);
static void			sliderwidget_AppForm_Delete (sliderwidget_AppForm* pMe);

/*===============================================================================
FUNCTION DEFINITIONS
=============================================================================== */


//=====================================================================================
//
//=====================================================================================
void sliderwidget_AppForm_Delete(sliderwidget_AppForm* pMe)
{
	
	if(pMe->mainForm)
		IFORM_Release(pMe->mainForm);
	if(pMe->mainContainer)
		IXYCONTAINER_Release(pMe->mainContainer);
//	if(pMe->numberStatic)
//		IWIDGET_Release(pMe->numberStatic);
	if(pMe->psliderwidget)
		IWIDGET_Release(pMe->psliderwidget);
	if(pMe->ptextwidget)
		IWIDGET_Release(pMe->ptextwidget);
	if(pMe)
		FREE(pMe);
}


//=====================================================================================
//
//=====================================================================================
static boolean sliderwidget_AppForm_HandleEvent(void *po, AEEEvent evt, uint16 wParam, uint32 dwParam)
{
	sliderwidget_AppForm* pMe = (sliderwidget_AppForm*) po;
	
	if( (evt== EVT_KEY)){
		
		if (wParam == AVK_SOFT2) {
			ISHELL_CloseApplet(pMe->piShell, TRUE);
			return TRUE;
		}
		else if(wParam == AVK_SOFT1){
		    int result;
			IWidget* containerWidget = NULL;
			
			result = IXYCONTAINER_QueryInterface(pMe->mainContainer, AEEIID_WIDGET, (void**)&containerWidget);
			if (pMe->focus == 1) {
				
				IWIDGET_MoveFocus(containerWidget, pMe->ptextwidget);
				pMe->focus = 2;
			}else if (pMe->focus == 2) {
				// 设置焦点为Slider3
				IWIDGET_MoveFocus(containerWidget, pMe->psliderwidget);
				pMe->focus = 1;
				IWIDGET_Release(containerWidget);
			    return TRUE;
			}	
		}
		
	}
	
	//the  default form handler is swapped with the sliderwidget_AppForm handler
	// calling this allows the default form handler to handle the event
	return HANDLERDESC_Call(&pMe->mainFormHandler, evt, wParam, dwParam);
}


//=====================================================================================
//
//=====================================================================================
int sliderwidget_AppForm_PopulateMainContainer(sliderwidget_AppForm* pMe)
{


	int					result = 0;
	IWidget*			containerWidget = NULL;
	IPropContainer*		propContainer = NULL;
	
	WExtent				we;
//	WidgetProp			wp;
	WidgetPos			wpos;
	IValueModel*		sliderwidget_ValueModel = NULL;

//    IWidget*            ptextwidget = NULL;
	ITextModel *        pTextModel = NULL;
	IWidget*            piScrollWidget = NULL;
	AEEDeviceInfo       DeviceInfo;
	

	//
	result =  ISHELL_CreateInstance(pMe->piShell, AEECLSID_XYCONTAINER, (void**) &pMe->mainContainer);	
	result += ISHELL_CreateInstance(pMe->piShell, AEECLSID_PROPCONTAINER, (void**) &propContainer);		
	result += ISHELL_CreateInstance(pMe->piShell, AEECLSID_SLIDERWIDGET, (void**)&pMe->psliderwidget);	
    result += ISHELL_CreateInstance(pMe->piShell, AEECLSID_TEXTWIDGET, (void**)&pMe->ptextwidget);	

	if(result != 0)	
		return EFAILED;

	pMe->focus = 1;

	//test textwidget
    we.width = 60;
    we.height = 30;	
	
    ISHELL_GetDeviceInfo(pMe->piShell,&DeviceInfo);
    IWIDGET_SetExtent(pMe->ptextwidget,&we);
    IWIDGET_SetFlags(pMe->ptextwidget,TWF_MULTILINE);
    IWIDGET_SetProperty(pMe->ptextwidget,PROP_BORDERWIDTH,1);
    IWIDGET_SetProperty(pMe->ptextwidget,PROP_ACTIVE_BORDERWIDTH,2);
//	IWIDGET_GetModel(pMe->ptextwidget,AEEIID_TEXTMODEL,&pTextModel);


	// insert into the main container
	/*
	wpos.x = 10;
		wpos.y = 50;
		wpos.bVisible = TRUE;*/
	
//	IXYCONTAINER_Insert(pMe->mainContainer, ptextwidget, WIDGET_ZNORMAL, &wpos);
	
//	IWidget* piScrollWidget = NULL;
    result = ISHELL_CreateInstance(pMe->piShell, AEECLSID_SCROLLBARWIDGET, (void**) &piScrollWidget);
    if(result == 0) {
	 IWidget* mainFormWidget = NULL;
     YLScrollbarWidget* pYLSB=(YLScrollbarWidget*)piScrollWidget;
	 IWIDGET_SetScrollHandleWidth(piScrollWidget,11);
     IWIDGET_SetFlags(piScrollWidget, SBWF_ARROWS);
   	 IDECORATOR_SetWidget((IDecorator*)piScrollWidget, pMe->ptextwidget);
    
   
	wpos.x = 10;
	wpos.y = 50;
	wpos.bVisible = TRUE;
     IXYCONTAINER_Insert(pMe->mainContainer, piScrollWidget, WIDGET_ZNORMAL, &wpos);

     IWIDGET_Release(piScrollWidget);
   }
	//test sliderwidget
	IWIDGET_SetProperty(pMe->psliderwidget,	PROP_SLIDER_MAXPOS,		10);	
	// 设置Slider手柄边框的颜色 (宏PROP_SLIDER_HANDLEBORDERCOLOR)
	IWIDGET_SetProperty(pMe->psliderwidget,	PROP_SLIDER_HANDLEBORDERCOLOR,		MAKE_RGB( 255, 255, 000));
	// 设置Slider滑杆边框的颜色 (同时设定了手柄颜色)
	IWIDGET_SetProperty(pMe->psliderwidget,	PROP_INACTIVE_BORDERCOLOR,		MAKE_RGB(0, 255, 0));
	IWIDGET_SetProperty(pMe->psliderwidget,	PROP_ACTIVE_BORDERCOLOR,		MAKE_RGB( 0, 255,  255));
	// 设置Slider滑杆杆体的颜色(滑杆底色)
	IWIDGET_SetProperty(pMe->psliderwidget,	PROP_ACTIVE_BGCOLOR,		MAKE_RGB(0, 0, 255));
	IWIDGET_SetProperty(pMe->psliderwidget,	PROP_INACTIVE_BGCOLOR,		MAKE_RGB(255, 0, 0));
	IWIDGET_SetProperty(pMe->psliderwidget,	PROP_LAYOUTSTYLE,	LAYOUT_NONE);	// 不指定方向
	IWIDGET_SetProperty(pMe->psliderwidget,	PROP_BORDERSTYLE,	BORDERSTYLE_ROUNDED);	// 圆角风格
	

	
	we.height	= 10;
	we.width	= 100;
	IWIDGET_SetExtent(pMe->psliderwidget,&we);

	IWIDGET_GetModel(pMe->psliderwidget, AEEIID_VALUEMODEL, (IModel**)&sliderwidget_ValueModel);	// 获得sliderwidget1的ValueModel
	IVALUEMODEL_SetValue(sliderwidget_ValueModel, (void*)6, 0, NULL);								// 通过该ValueModel赋初值
	IVALUEMODEL_Release(sliderwidget_ValueModel);
	IWIDGET_SetProperty(pMe->psliderwidget,	PROP_ACTIVE_BGCOLOR,	sliderwidget_ACTIVE_BORDER_COLOR(6));
	
	// insert into the main container
	wpos.x = 10;
	wpos.y = 5;
	wpos.bVisible = TRUE;
	IXYCONTAINER_Insert(pMe->mainContainer, pMe->psliderwidget, WIDGET_ZNORMAL, &wpos);

	result = IXYCONTAINER_QueryInterface(pMe->mainContainer, AEEIID_WIDGET, (void**)&containerWidget);
	if(result ==0) {
		IFORM_SetWidget(pMe->mainForm, WID_FORM, containerWidget);
		//IWIDGET_MoveFocus(containerWidget, opPickList);//pMe->psliderwidget);
		IWIDGET_Release(containerWidget);
	}
	
	return result;
}


//=====================================================================================
//
//=====================================================================================
int sliderwidget_AppForm_New(IForm** ppo, IShell *piShell, IRootForm *pRootForm) {
	int result=0;
	
	//allocate space for the form
	sliderwidget_AppForm *pMe = MALLOCREC(sliderwidget_AppForm);
	
	if(!pMe)
		return ENOMEMORY;
	
	pMe->piShell = piShell;
	pMe->rootForm = pRootForm;
	
	result = ISHELL_CreateInstance(pMe->piShell, AEECLSID_FORM, (void**) &pMe->mainForm);
	if(result==0) {
		*ppo = pMe->mainForm;
	}
	
	if(result==0) {
		result =  IFORM_SetSoftkeys(pMe->mainForm, SLIDERWIDGETDEMO_RES_FILE, MAINFORMSOFTKEY1, MAINFORMSOFTKEY2);
		result += IFORM_SetResText(pMe->mainForm, FID_TITLE, SLIDERWIDGETDEMO_RES_FILE, MAINFORMTITLE);		
		HANDLERDESC_Init(&pMe->mainFormHandler, sliderwidget_AppForm_HandleEvent, pMe, sliderwidget_AppForm_Delete);
		IFORM_SetHandler(pMe->mainForm, &pMe->mainFormHandler);
	}
	
	if(result==0)
		result = sliderwidget_AppForm_PopulateMainContainer(pMe);
	
	return result;
}


//=====================================================================================
/* Initialize applet data*/
//=====================================================================================
int sliderwidget_InitAppData(sliderwidget_App* pMe) {
	int result = 0;
	
	pMe->mainForm = NULL;
	
	//create rootForm
	result = ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_ROOTFORM, (void**) &pMe->rootForm);
	
	//set the theme
	if(result == 0)
		result = IROOTFORM_SetThemeFileName(pMe->rootForm, "theme.bar");

	return result;
}

//=====================================================================================
// Free app data
//=====================================================================================
static void sliderwidget_FreeAppData(sliderwidget_App* pMe) {
	if(pMe->rootForm) {
		IROOTFORM_Release(pMe->rootForm);
		pMe->rootForm = NULL;
	}
	
	if(pMe->mainForm) {
		IFORM_Release(pMe->mainForm);
		pMe->mainForm = NULL;
	}
	
}


//=====================================================================================
// App handle event
//=====================================================================================
static boolean sliderwidget_HandleEvent(IApplet * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{  
	int result=0;
	sliderwidget_App* pMe = (sliderwidget_App*) pi;
	
	// Allow rootform to handle event first
	if(IROOTFORM_HandleEvent(pMe->rootForm, eCode, wParam, dwParam)) {
		return TRUE;
	}
	
	switch(eCode) {
	case EVT_APP_START: 
		// create main app form and push it onto the stack
		if(sliderwidget_AppForm_New(&pMe->mainForm, pMe->a.m_pIShell, pMe->rootForm) == 0) {
			IROOTFORM_PushForm(pMe->rootForm, pMe->mainForm);
			return TRUE;
		}
		break;
		
	case EVT_APP_STOP:
		return TRUE;
		
	default:
		break;
	}
	return FALSE;
}


//=====================================================================================
// 
//=====================================================================================
int AEEClsCreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj)
{
	sliderwidget_App* pMe=NULL;
	*ppObj = NULL;
	
	if(!AEEApplet_New(sizeof(sliderwidget_App), 
		ClsId, pIShell,po,(IApplet**)ppObj,
		(AEEHANDLER)sliderwidget_HandleEvent, 
		(PFNFREEAPPDATA) sliderwidget_FreeAppData))
		return ENOMEMORY;
	
	pMe = (sliderwidget_App*) *ppObj;
	
	if(sliderwidget_InitAppData(pMe) != 0)
		return EFAILED;
	
	return AEE_SUCCESS;
}


//=====================================================================================
//================================The end==============================================
//=====================================================================================

⌨️ 快捷键说明

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