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

📄 appform.c

📁 Form/widget演示程序
💻 C
📖 第 1 页 / 共 2 页
字号:
   if(titleWidget) {
      IWIDGET_SetFGColor(titleWidget, rgbVal);
      IFORM_SetWidget(IROOTFORM_TO_IFORM(pMe->rootForm), WID_TITLE, titleWidget);
      IWIDGET_Release(titleWidget);
   }

   //dismiss the pop up menu
   IROOTFORM_PopForm(pMe->rootForm);
   IPOPUPMENU_Release(pMe->optionsMenu);
   pMe->optionsMenu = NULL;

}



//create Options Menu
int AppForm_CreateOptionsMenu(AppForm* pMe) {
   int result = 0;

   result = ISHELL_CreateInstance(pMe->piShell, AEECLSID_POPUPMENUFORM, (void**) &pMe->optionsMenu);
   if(result == 0) {
      result = IPOPUPMENU_LoadMenuItem(pMe->optionsMenu, CALCULATOR_RES_FILE, MENUITEM1, 0,MMF_ENABLED);
      result += IPOPUPMENU_LoadMenuItem(pMe->optionsMenu, CALCULATOR_RES_FILE, MENUITEM2, 1,MMF_ENABLED);
      result += IPOPUPMENU_LoadMenuItem(pMe->optionsMenu, CALCULATOR_RES_FILE, MENUITEM3, 2,MMF_ENABLED);
   }

   if(result==0) {
      IFORM_SetSoftkeys((IForm*)pMe->optionsMenu, CALCULATOR_RES_FILE, MAINFORMSOFTKEY1, 0);
	  IFORM_SetSelectHandler((IForm*)pMe->optionsMenu, (PFNSELECT)OptionSelectionHandler, pMe);
	  

      HANDLERDESC_Init(&pMe->optionsMenuHandler, OptionsEventHandler, pMe, 0);
      IFORM_SetHandler((IForm*)pMe->optionsMenu, &pMe->optionsMenuHandler);

      //wrap the pop-up form in a scrollbar decorator
      {
         IWidget* piScrollWidget = NULL;
         result = ISHELL_CreateInstance(pMe->piShell, AEECLSID_SCROLLBARWIDGET, (void**) &piScrollWidget);
         if(result == 0) {
			 IWidget* mainFormWidget = NULL;
            // change the scroll pad
            IWIDGET_SetProperty(piScrollWidget, PROP_SCROLLPAD, 0);
			IFORM_GetWidget((IForm*)pMe->optionsMenu, WID_FORM, &mainFormWidget);
			IDECORATOR_SetWidget((IDecorator*)piScrollWidget, mainFormWidget);
            IFORM_SetWidget((IForm*)pMe->optionsMenu, WID_FORM, piScrollWidget);
			IWIDGET_Release(mainFormWidget);
            IWIDGET_Release(piScrollWidget);   
         }
      }
   }

   return result;
}


//update the operator display when an operator is selected from the pickwidget
//pev->dwParam is the index of the selected item
static void PickWidget_ViewModelHandler(AppForm *pMe, ModelEvent *pev) {
   if(pev->evCode == EVT_MDL_FOCUS_SELECT) {
      //display operator
      AECHAR* buff = NULL;
      buff = (AECHAR*) MALLOC(4);
      buff[0] = pMe->operatorString[pev->dwParam];  
      IWIDGET_SetText(pMe->opStatic, buff, TRUE);
   }
}


// pick value adapter
/* At draw time, the value model gets set from the list model but 
the length of the data is set to -1, which means, for a StaticWidget, 
that the string length must be calculated with WSTRLEN(). We need to override
the length*/
static void PickAdapter(void *pUnused, void **ppValueIn, int nLen, void **ppValueOut, int *pnLenOut)
{
   *pnLenOut = 1;  // force length to be 1, instead of calculating
}



int AppForm_PopulateMainContainer(AppForm* pMe) {
   int result=0;
   IWidget* containerWidget = NULL;
   IPropContainer* numOpContainer = NULL;
   IWidget* opPickList;
   IArrayModel* opPickArrayModel = NULL;
   IWidget* pickItemWidget = NULL;
   IValueModel* pickItemValueModel = NULL;

   WExtent we;
   WidgetProp wp;
   WidgetPos wpos;

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

   result = ISHELL_CreateInstance(pMe->piShell, AEECLSID_PROPCONTAINER, (void**) &numOpContainer);

   result += ISHELL_CreateInstance(pMe->piShell, AEECLSID_STATICWIDGET, (void**)&pMe->numberStatic);

   result += ISHELL_CreateInstance(pMe->piShell, AEECLSID_STATICWIDGET, (void**)&pMe->opStatic);

   if(result != 0)
      return EFAILED;

   //set static widget properties
   IWIDGET_SetBorderColor(pMe->numberStatic, MAKE_RGB(100, 100, 100));
   IWIDGET_SetBorderWidth(pMe->numberStatic, 1);
   IWIDGET_SetFlags(pMe->numberStatic, IDF_ALIGN_RIGHT | IDF_ALIGN_MIDDLE);

   IWIDGET_SetBorderColor(pMe->opStatic, MAKE_RGB(100, 100, 100));
   IWIDGET_SetBorderWidth(pMe->opStatic, 1);
   IWIDGET_SetFlags(pMe->opStatic, IDF_ALIGN_CENTER | IDF_ALIGN_MIDDLE);

   //insert static widgets into the prop container
   wp.bVisible = TRUE;
   wp.prop = 6;
   IPROPCONTAINER_Insert(numOpContainer, pMe->numberStatic, WIDGET_ZNORMAL, &wp);

   wp.prop = 1;
   IPROPCONTAINER_Insert(numOpContainer, pMe->opStatic, WIDGET_ZNORMAL, &wp);

   // set the properties and extent of the prop container
   result = IPROPCONTAINER_QueryInterface(numOpContainer, AEEIID_WIDGET, (void**)&containerWidget);
   if(result == 0) {
      IWIDGET_SetLayoutStyle(containerWidget, LAYOUT_HORZ);
      IWIDGET_SetBorderColor(containerWidget, RGB_BLACK);
      IWIDGET_SetBorderWidth(containerWidget, 1);
      we.height = 22;
      we.width = 95;
      IWIDGET_SetExtent(containerWidget, &we);
   }

   if(result == 0) {
      //insert prop container into main container
      wpos.x = 30;
      wpos.y = 5;
      wpos.bVisible = TRUE;
      IXYCONTAINER_Insert(pMe->mainContainer, containerWidget, WIDGET_ZNORMAL, &wpos);
      IWIDGET_Release(containerWidget);
   }

   //release the prop container
   if(numOpContainer)
      IPROPCONTAINER_Release(numOpContainer);

   result = ISHELL_CreateInstance(pMe->piShell, AEECLSID_PICKWIDGET, (void**)&opPickList);
   result += ISHELL_CreateInstance(pMe->piShell, AEECLSID_ARRAYMODEL, (void**)&opPickArrayModel);
   result += ISHELL_CreateInstance(pMe->piShell, AEECLSID_STATICWIDGET, (void**)&pickItemWidget);

   if(result != 0)
      return EFAILED;

   //set the array model items
   pMe->operatorString = (AECHAR*) MALLOC(12);
   ISHELL_LoadResString(pMe->piShell, CALCULATOR_RES_FILE, OPERATORSTRING, pMe->operatorString, 12);
   IARRAYMODEL_SetItems(opPickArrayModel, (void*)pMe->operatorString, 5, sizeof(AECHAR));
   IWIDGET_SetModel(opPickList, (IModel*)opPickArrayModel);

   //set the picklist widget properties
   IWIDGET_SetBorderWidth(opPickList, 1);
   IWIDGET_SetItemHeight(opPickList, 15);
   IWIDGET_SetItemWidth(opPickList, 15);
   IWIDGET_SetHintCols(opPickList, 5);
   IWIDGET_GetPreferredExtent(opPickList, &we);
   IWIDGET_SetExtent(opPickList, &we);

   IWIDGET_SetBorderWidth(pickItemWidget, 1);
   IWIDGET_SetBorderColor(pickItemWidget, RGB_BLACK);
   IWIDGET_SetSelectedBorderColor(pickItemWidget, RGB_WHITE);
   IWIDGET_SetFlags(pickItemWidget, SWF_NOSHORTENTEXT | IDF_ALIGN_CENTER | IDF_ALIGN_MIDDLE);

   IDECORATOR_SetWidget((IDecorator*)opPickList, pickItemWidget);

   IWIDGET_GetModel(pickItemWidget, AEEIID_VALUEMODEL, (IModel**)&pickItemValueModel);
   IVALUEMODEL_AdaptGet(pickItemValueModel, (PFNADAPTGET)PickAdapter, 0);

   if(pickItemWidget)
      IWIDGET_Release(pickItemWidget);
   if(pickItemValueModel)
      IVALUEMODEL_Release(pickItemValueModel);

   // get the view model of the opPickList and register a listener 
   // in order to to pick up operator selection
   {
      IModel* pickListViewModel = NULL;
      IWIDGET_GetViewModel(opPickList, &pickListViewModel);
      IMODEL_AddListenerEx(pickListViewModel, &pMe->pickVmListener, (PFNLISTENER)PickWidget_ViewModelHandler, pMe);
      IMODEL_Release(pickListViewModel);
   }

   //insert the opPickList widget into the main container
   wpos.x = 50;
   wpos.y = 60;
   wpos.bVisible = TRUE;
   IXYCONTAINER_Insert(pMe->mainContainer, opPickList, WIDGET_ZNORMAL, &wpos);

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

   if(opPickList)
      IWIDGET_Release(opPickList);
   if(opPickArrayModel)
      IARRAYMODEL_Release(opPickArrayModel);

   return result;
}


int AppForm_New(IForm** ppo, IShell *piShell, IRootForm *pRootForm, IDisplay *piDisplay) {
   int result=0;

   //allocate space for the form
   AppForm *pMe = MALLOCREC(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, CALCULATOR_RES_FILE, MAINFORMSOFTKEY1, MAINFORMSOFTKEY2);
      result += IFORM_SetResText(pMe->mainForm, FID_TITLE, CALCULATOR_RES_FILE, MAINFORMTITLE);

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

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

   if(result==0)
      AppForm_UpdateValueModel(pMe);
   return result;
}

⌨️ 快捷键说明

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