3,176
社区成员




#include "AEE.h"
#include "AEEShell.h"
#include "AEEFont.h"
#include "AEEDisp.h"
#include "AEEStdLib.h"
#include "AEEText.h"
#include "AEEWidget.h"
#include "AEERootContainer.h"
#include "AEEDisplayCanvas.h"
#include "AEEDecorator.h"
#include "AEETextWidget.h"
#include "AEEScrollWidget.h"
#include "TestApp.bid"
#ifndef RELEASEIF
#define RELEASEIF(p) ReleaseIf((IBase**)&p)
static void ReleaseIf(IBase **ppif) {
if (*ppif) {
IBASE_Release(*ppif);
*ppif = 0;
}
}
#endif
#define HOME_PAGE "hsrc/index.htm"
#define GO_BACK 0
/*-------------------------------------------------------------------
Applet structure. All variables in here are reference via "me->"
-------------------------------------------------------------------*/
// create an applet structure that's passed around. All variables in
// here will be able to be referenced as static.
typedef struct _testapp {
IApplet ia;
IAppletVtbl iavt;
int nRefs;
IDisplay *pIDisplay; // give a standard way to access the Display interface
IShell *pIShell; // give a standard way to access the Shell interface
IModule *pIModule;
AEEDeviceInfo DeviceInfo; // always have access to the hardware device information
// add your own variables here...
//IController * piTextCtl; // text controller
IRootContainer * picRoot; // root container
IWidget * piwRoot; // root container's widget i/f
AEERect rcRoot;
ICanvas * piCanvas;
IWidget * piwScroll;
IWidget * piwText;
} testapp;
static uint32 testapp_AddRef (IApplet *po);
static uint32 testapp_Release (IApplet *po);
static boolean testapp_HandleEvent (IApplet *pi, AEEEvent eCode, uint16 wParam, uint32 dwParam);
static boolean testapp_HandleEvent(IApplet * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
testapp *me = (testapp *)pi;
if(EVT_APP_START == wParam)
return TRUE;
if(me->piwText)
if (IWIDGET_HandleEvent(me->piwText, eCode, wParam, dwParam))
return TRUE;
return FALSE;
}
static int testapp_CreateHelloWidget(testapp *me)
{
int nErr=0;
IBitmap *pib = 0;
WidgetPos dwpos;
WExtent we;
AEEBitmapInfo biDevice;
dwpos.x = dwpos.y = 0;
dwpos.bVisible = TRUE;
me->DeviceInfo.wStructSize = sizeof(me->DeviceInfo);
ISHELL_GetDeviceInfo(me->pIShell,&me->DeviceInfo);
nErr = ISHELL_CreateInstance(me->pIShell, AEECLSID_DISPLAY, (void **)&(me->pIDisplay));
nErr = ISHELL_CreateInstance(me->pIShell, AEECLSID_ROOTCONTAINER, (void *)(&me->picRoot));
if (SUCCESS != nErr)
return FALSE;
nErr = IROOTCONTAINER_QueryInterface(me->picRoot, AEEIID_WIDGET, (void *)(&me->piwRoot));
if (SUCCESS != nErr)
return FALSE;
nErr = IDISPLAY_GetDeviceBitmap(me->pIDisplay, &pib);
if (SUCCESS != nErr)
return FALSE;
IBITMAP_GetInfo(pib, &biDevice, sizeof(biDevice));
SETAEERECT(&(me->rcRoot), 0, 0, (short) biDevice.cx, (short) biDevice.cy);
nErr = ISHELL_CreateInstance(me->pIShell, AEECLSID_DISPLAYCANVAS, (void**)&(me->piCanvas));
if (SUCCESS != nErr)
{
IBITMAP_Release(pib);
return FALSE;
}
nErr = IDISPLAYCANVAS_SetDisplay((IDisplayCanvas*)me->piCanvas, me->pIDisplay);
if (SUCCESS != nErr)
return FALSE;
IROOTCONTAINER_SetCanvas(me->picRoot, me->piCanvas, &(me->rcRoot));
// begin creating all widgets here
nErr = ISHELL_CreateInstance(me->pIShell, AEECLSID_TEXTWIDGET, (void **)&(me->piwText));
if (SUCCESS != nErr)
return FALSE;
IWIDGET_SetFlags(me->piwText,TWF_MULTILINE);
IWIDGET_GetPreferredExtent(me->piwText, &we);
we.width = (me->DeviceInfo).cxScreen/2;
we.height = (me->DeviceInfo).cyScreen/2;
IWIDGET_SetExtent(me->piwText, &we);
nErr = ISHELL_CreateInstance(me->pIShell, AEECLSID_SCROLLBARWIDGET, (void**)&me->piwScroll);
if (SUCCESS != nErr)
return FALSE;
IWIDGET_SetProperty((me->piwScroll), PROP_ACTIVE_SCROLLCOLOR,MAKE_RGB(0,255,0));
IWIDGET_SetProperty((me->piwScroll), PROP_INACTIVE_SCROLLCOLOR,MAKE_RGB(0,255,0));
IWIDGET_SetProperty((me->piwScroll), PROP_ACTIVE_SCROLLHANDLECOLOR, MAKE_RGB(255,0,0));
IWIDGET_SetProperty((me->piwScroll), PROP_INACTIVE_SCROLLHANDLECOLOR, MAKE_RGB(255,0,0));
IWIDGET_SetProperty((me->piwScroll), PROP_FLAGS, SCROLL_VERT|SBWF_NOAUTOHIDE|SBWF_ARROWS );
IDECORATOR_SetWidget((IDecorator*)me->piwScroll, (IWidget *)me->piwText);
IROOTCONTAINER_Insert(me->picRoot, me->piwScroll, WIDGET_ZNORMAL, &dwpos);
RELEASEIF(pib);
return TRUE;
}
static int testapp_Construct(testapp *me, IModule * piModule, IShell * piShell)
{
me->ia.pvt = &me->iavt;
me->iavt.AddRef = testapp_AddRef;
me->iavt.Release = testapp_Release;
me->iavt.HandleEvent = testapp_HandleEvent;
me->nRefs = 1;
me->pIShell = piShell;
ISHELL_AddRef(piShell);
me->pIModule = piModule;
IMODULE_AddRef(piModule);
testapp_CreateHelloWidget(me);
return 0;
}
static void testapp_Dtor(testapp *me)
{
RELEASEIF(me->piwText);
RELEASEIF(me->piwScroll);
RELEASEIF(me->piwRoot);
RELEASEIF(me->pIDisplay);
RELEASEIF(me->piCanvas);
RELEASEIF(me->pIModule);
RELEASEIF(me->pIShell);
}
static uint32 testapp_AddRef(IApplet *po)
{
testapp *me = (testapp *)po;
return ++me->nRefs;
}
static uint32 testapp_Release(IApplet *po)
{
testapp *me = (testapp *)po;
uint32 nRefs = --me->nRefs;
if (nRefs == 0) {
testapp_Dtor(me);
FREE(me);
}
return nRefs;
}
#include "xmod.h"
int xModule_CreateInstance(IModule *module, IShell *shell, AEECLSID idClass, void **pp)
{
if (idClass == AEECLSID_TESTAPP) {
testapp *me = MALLOCREC(testapp);
if (me == 0) {
return ENOMEMORY;
} else {
*pp = &me->ia;
return testapp_Construct(me, module, shell);
}
}
*pp = 0;
return ECLASSNOTSUPPORT;
}