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

📄 appform.c

📁 Brew 下一个字自动滚动的实例
💻 C
字号:
#include "AEEDialog.h"
#include "AEERootForm.h"
#include "AEEWProperties.h"
#include "AEEXYContainer.h"
#include "AEETextWidget.h"
#include "AEEStaticWidget.h"
#include "AEEScrollWidget.h"
#include "AEEStdLib.h"
#include "wutil.h"

#include "StaticTransition.h"
#include "AppForm.h"
#include "testdemo.bid"
#include "testdemo.brh"


// app form structure
struct AppForm {
   IModule* pIModule;
	IShell* piShell;
	IRootForm* rootForm;

	IForm* mainForm;
	HandlerDesc mainFormHandler;

	IDialog* exitConfirmationDialog;
	HandlerDesc exitConfirmationHandler;
	IXYContainer* mainContainer;

	IWidget* pText;
	IWidget* pStatic;
	IDecorator* pScrollBar;
   ITransition* pStaticTransition;

};

#define TESTDEMO_RES_FILE "testdemo.bar"


void AppForm_Delete(AppForm* pMe) {
   if(pMe->mainForm)
      IFORM_Release(pMe->mainForm);
   if(pMe->exitConfirmationDialog)
      IDIALOG_Release(pMe->exitConfirmationDialog);
   if(pMe->mainContainer)
      IXYCONTAINER_Release(pMe->mainContainer);
   if(pMe->pText)
      IWIDGET_Release(pMe->pText);
   if(pMe->pStatic)
      IWIDGET_Release(pMe->pStatic);
   if(pMe->pScrollBar)
	  IDECORATOR_Release(pMe->pScrollBar);
   if(pMe->pStaticTransition)
	  ITRANSITION_Release(pMe->pStaticTransition);

   if(pMe)
      FREE(pMe);
}

// 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, FALSE);
         return TRUE;
      }
   }

   return HANDLERDESC_Call(&pMe->exitConfirmationHandler, evt, wParam, dwParam);
}


//Create Warning dialog
int AppForm_CreateExitConfDialog(AppForm* pMe) {
   ISHELL_CreateInstance(pMe->piShell, AEECLSID_WARNDIALOG, (void**) &pMe->exitConfirmationDialog);

   if(pMe->exitConfirmationDialog) {
      IFORM_SetSoftkeys((IForm*)pMe->exitConfirmationDialog, TESTDEMO_RES_FILE, EXITFORMSOFTKEY1, EXITFORMSOFTKEY2);
      IFORM_SetCancelKey((IForm*)pMe->exitConfirmationDialog, AVK_SOFT2);

      IFORM_SetResText((IForm*)pMe->exitConfirmationDialog, FID_TITLE, TESTDEMO_RES_FILE, EXITFORMTITLE);
      IFORM_SetResText((IForm*)pMe->exitConfirmationDialog, FID_TEXT, TESTDEMO_RES_FILE, EXITFORMTEXT);

      HANDLERDESC_Init(&pMe->exitConfirmationHandler, exitConfirmationDialog_HandleEvent, pMe, 0);
      IFORM_SetHandler((IForm*)pMe->exitConfirmationDialog, &pMe->exitConfirmationHandler);
      return AEE_SUCCESS;
   }
   return EFAILED;
}

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

   if(evt== EVT_KEY) {

	   if(wParam == AVK_SOFT2) {
         //display a dialog form asking the user to confirm exit
         IROOTFORM_PushForm(pMe->rootForm, (IForm*)pMe->exitConfirmationDialog);
         return TRUE;
	   }
	   if((wParam == AVK_UP) || (wParam == AVK_DOWN)) {

			boolean bFocus;
			IXYCONTAINER_QueryInterface(pMe->mainContainer, AEEIID_WIDGET, (void **)&piwc);
			
			IWIDGET_HasFocus(pMe->pText, &bFocus);
			if (bFocus)	
				IWIDGET_MoveFocus(piwc, (IWidget*)pMe->pStatic);
			else
				IWIDGET_MoveFocus(piwc, (IWidget*)pMe->pText);

			RELEASEIF(piwc);
			return TRUE;
		}
	   if(wParam == AVK_CLR) {
         //display a dialog form asking the user to confirm exit
         IROOTFORM_PushForm(pMe->rootForm, (IForm*)pMe->exitConfirmationDialog);
         return TRUE;
	   }
   }
   return HANDLERDESC_Call(&pMe->mainFormHandler, evt, wParam, dwParam);
}

int AppForm_PopulateMainContainer(AppForm* pMe, IDisplay *piDisplay) {
	int result=0;
	IWidget* containerWidget = NULL;
	WExtent we, we1;
	WidgetPos wpos;
   StaticTransitionDesc desc;

	result =  ISHELL_CreateInstance(pMe->piShell, AEECLSID_XYCONTAINER, (void**) &pMe->mainContainer);
	if(result != 0)
		return EFAILED;

	result = ISHELL_CreateInstance(pMe->piShell, AEECLSID_TEXTWIDGET, (void**)&pMe->pText);
	if(result != 0)
		return EFAILED;

	result = ISHELL_CreateInstance(pMe->piShell, AEECLSID_STATICWIDGET, (void**)&pMe->pStatic);
	if(result != 0)
		return EFAILED;

	result = ISHELL_CreateInstance(pMe->piShell, AEECLSID_SCROLLBARWIDGET, (void**)&pMe->pScrollBar);
	if(result != 0)
		return EFAILED;


// Text Widget

	IWIDGET_SetTextWidgetText(pMe->pText, L"1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ");
	IWIDGET_SetFlags(pMe->pText, TWF_MULTILINE);

	IWIDGET_SetHintRows(pMe->pText, 3);
	IWIDGET_SetHintWidth(pMe->pText, 50);
	IWIDGET_GetPreferredExtent(pMe->pText, &we);
	IWIDGET_SetExtent(pMe->pText, &we);

   // Scroll Bar Widget
	IWIDGET_SetProperty(IDECORATOR_TO_IWIDGET(pMe->pScrollBar), PROP_SCROLLPAD, 0);             
	IDECORATOR_SetWidget(pMe->pScrollBar, pMe->pText);


// Static Widget

	IWIDGET_SetProperty(pMe->pStatic, PROP_FGCOLOR, RGBA_WHITE);
	IWIDGET_SetProperty(pMe->pStatic, PROP_BGCOLOR, RGBA_BLACK);
	IWIDGET_SetProperty(pMe->pStatic, PROP_FLAGS, SWF_NOSHORTENTEXT);
   we1.width = 60; we1.height = 15;
	IWIDGET_SetExtent(pMe->pStatic, &we1);

// Static偺暥帤儖乕僾梡Transition偺嶌惉丅杮摉偼偪傖傫偲僋儔僗偱嶌偭偨傎偆偑偄偄偲巚偄傑偡偑僥僗僩梡偱偡丅

   result = StaticTransition_New((ITransition **)&pMe->pStaticTransition, pMe->piShell, pMe->pIModule);
	if(result != 0)
		return EFAILED;

   STATICTRANSITIONDESC_Init(&desc, pMe->pStatic, L"1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ");
   ITRANSITION_Start((ITransition *)pMe->pStaticTransition, (TransitionDesc *)&desc, 10000L, NULL, NULL);

	wpos.x = 10;
	wpos.y = 5;
	wpos.bVisible = TRUE;
	IXYCONTAINER_Insert(pMe->mainContainer, IDECORATOR_TO_IWIDGET(pMe->pScrollBar), WIDGET_ZNORMAL, &wpos);

	wpos.x = 10;
	wpos.y = we.height + 20;
	wpos.bVisible = TRUE;
	IXYCONTAINER_Insert(pMe->mainContainer, pMe->pStatic, WIDGET_ZNORMAL, &wpos);

	result = IXYCONTAINER_QueryInterface(pMe->mainContainer, AEEIID_WIDGET, (void**)&containerWidget);
	if(result != 0)
		return EFAILED;

	IFORM_SetWidget(pMe->mainForm, WID_FORM, containerWidget);
	IWIDGET_Release(containerWidget);

	return 0;
}


int AppForm_New(IForm** ppo, IModule *piModule, IShell *piShell, IRootForm *pRootForm, IDisplay *piDisplay) {

	int result=0;

	//allocate space for the form
	AppForm *pMe = MALLOCREC(AppForm);

	if(!pMe)
      return ENOMEMORY;

	pMe->pIModule = piModule;
	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_SetResBGImage(pMe->mainForm, TESTDEMO_RES_FILE, MAINFORMBGIMAGE);
	  result = IFORM_SetSoftkeys(pMe->mainForm, TESTDEMO_RES_FILE, 0, MAINFORMSOFTKEY2);
     result = IFORM_SetResText(pMe->mainForm, FID_TITLE, TESTDEMO_RES_FILE, MAINFORMTITLE);

     HANDLERDESC_Init(&pMe->mainFormHandler, AppForm_HandleEvent, pMe, AppForm_Delete);
     IFORM_SetHandler(pMe->mainForm, &pMe->mainFormHandler);
   }

   if(result ==0)
      result = AppForm_CreateExitConfDialog(pMe);

   if(result==0)
      result = AppForm_PopulateMainContainer(pMe, piDisplay);
   return result;
}

⌨️ 快捷键说明

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