📄 appform.c
字号:
#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 "AppForm.h"
#include "Calculator.bid"
#include "Calculator.brh"
// app form structure
struct AppForm {
IShell* piShell;
IRootForm* rootForm;
IForm* mainForm;
HandlerDesc mainFormHandler;
IDialog* exitConfirmationDialog;
HandlerDesc exitConfirmationHandler;
IPopupMenu* optionsMenu;
HandlerDesc optionsMenuHandler;
IXYContainer* mainContainer;
IWidget* numberStatic;
IWidget* opStatic;
ModelListener pickVmListener;
uint32 nAccumulator;
AECHAR* operatorString; //values to be populated in the pick widget array model
};
#define CALCULATOR_RES_FILE "calculator.bar"
int AppForm_CreateExitConfDialog(AppForm* pMe);
int AppForm_CreateOptionsMenu(AppForm* pMe);
void AppForm_Delete(AppForm* pMe) {
LISTENER_Cancel(&pMe->pickVmListener);
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->opStatic)
IWIDGET_Release(pMe->opStatic);
if(pMe->numberStatic)
IWIDGET_Release(pMe->numberStatic);
if(pMe->operatorString)
FREE(pMe->operatorString);
if(pMe)
FREE(pMe);
}
void AppForm_UpdateValueModel(AppForm *me)
{
IValueModel *pivm = 0;
char ach[12];
AECHAR awch[12];
SNPRINTF(ach, sizeof(ach)-1, "%lu", (uint32)me->nAccumulator);
STRTOWSTR(ach, awch, sizeof(awch));
if(SUCCESS == IWIDGET_GetModel(me->numberStatic, AEEIID_VALUEMODEL, (IModel**) &pivm)) {
IVALUEMODEL_SetText(pivm, awch, -1);
IVALUEMODEL_Release(pivm);
}
}
void AppForm_UpdateNum(AppForm* me, int16 newNum)
{
if(me->nAccumulator < 429496728) {
me->nAccumulator = (me->nAccumulator * 10) + newNum;
AppForm_UpdateValueModel(me);
}
}
void AppForm_ClearDigit(AppForm* me)
{
if(me->nAccumulator > 0) {
me->nAccumulator /= 10;
AppForm_UpdateValueModel(me);
}
}
static boolean AppForm_HandleEvent(void *po, AEEEvent evt, uint16 wParam, uint32 dwParam)
{
AppForm* pMe = (AppForm*) po;
if(evt== EVT_KEY) {
if(wParam == AVK_SOFT1) {
int result = AppForm_CreateOptionsMenu(pMe);
if (result == 0)
IROOTFORM_PushForm(pMe->rootForm, (IForm*)pMe->optionsMenu);
return TRUE;
}
if(wParam == AVK_SOFT2) {
//display a dialog form asking the user to confirm exit
int result = AppForm_CreateExitConfDialog(pMe);
if(result == 0)
IROOTFORM_PushForm(pMe->rootForm, (IForm*)pMe->exitConfirmationDialog);
return TRUE;
}
if(wParam >= AVK_0 && wParam <= AVK_9) {
AppForm_UpdateNum(pMe, (int16)(wParam - AEE_AVK_BASE - 1));
return TRUE;
}
if(wParam == AVK_CLR) {
AppForm_ClearDigit(pMe);
return TRUE;
}
}
//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);
}
//Create Warning dialog
int AppForm_CreateExitConfDialog(AppForm* pMe) {
IWidget* backdropWidget = NULL;
ISHELL_CreateInstance(pMe->piShell, AEECLSID_WARNDIALOG, (void**) &pMe->exitConfirmationDialog);
if(pMe->exitConfirmationDialog) {
IFORM_SetSoftkeys((IForm*)pMe->exitConfirmationDialog, CALCULATOR_RES_FILE, EXITFORMSOFTKEY1, EXITFORMSOFTKEY2);
IFORM_SetCancelKey((IForm*)pMe->exitConfirmationDialog, AVK_SOFT2);
IFORM_SetResText((IForm*)pMe->exitConfirmationDialog, FID_TITLE, CALCULATOR_RES_FILE, EXITFORMTITLE);
IFORM_SetResText((IForm*)pMe->exitConfirmationDialog, FID_TEXT, CALCULATOR_RES_FILE, EXITFORMTEXT);
//set the transparency of the backdrop
IFORM_GetWidget((IForm*)pMe->exitConfirmationDialog, WID_BACKDROP, &backdropWidget);
if(backdropWidget) {
IWIDGET_SetTransparency(backdropWidget, 35);
IFORM_SetWidget((IForm*)pMe->exitConfirmationDialog, WID_BACKDROP, backdropWidget);
IWIDGET_Release(backdropWidget);
}
HANDLERDESC_Init(&pMe->exitConfirmationHandler, exitConfirmationDialog_HandleEvent, pMe, 0);
IFORM_SetHandler((IForm*)pMe->exitConfirmationDialog, &pMe->exitConfirmationHandler);
return AEE_SUCCESS;
}
return EFAILED;
}
static boolean OptionsEventHandler(void *po, AEEEvent evt, uint16 wParam, uint32 dwParam)
{
AppForm* pMe = (AppForm*) po;
if(evt == EVT_WDG_GETPROPERTY && wParam == FID_PREFRECT) {
//catch FID_PREFRECT and set preferred extent of menu
AEERect rc;
rc.x = 0;
rc.y = 116;
rc.dx = 48;
rc.dy = 28;
*(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);
}
// Function to process menu selection
static void OptionSelectionHandler(AppForm* pMe, int idOption) {
IWidget* titleWidget = NULL;
RGBVAL rgbVal;
if(idOption == 0)
rgbVal = MAKE_RGB(255, 0, 0);
else if(idOption == 1)
rgbVal = MAKE_RGB(0, 255, 0);
else
rgbVal = MAKE_RGB(0, 0, 0);
//get the root form's title widget, set the FG color and set the title widget
IFORM_GetWidget(IROOTFORM_TO_IFORM(pMe->rootForm), WID_TITLE, &titleWidget);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -