Resources | developer.brewmp.com Resources | developer.brewmp.com

Developer

resources

Using button widget

The button widget is instantiated by calling ISHELL_CreateInstance(0 with the AEECLSID_ButtonWidget ClassID.

The button widget is derived from the border widget class (AEECLSID_BorderWidget) and supports all properties and functions supported by the border widget class. The button widget acts as a decorator to decorate a given widget to give it the look and feel of a button.

The following code example creates a button widget, then creates a static widget, and sets the button widget to decorate the static widget. This example also adds a listener for the button widget, sets its extent, and inserts the button widget in a container.

// --- BUTTON WIDGET
   if(AEE_SUCCESS == nErr) {
      nErr = ISHELL_CreateInstance(me->piShell, AEECLSID_ButtonWidget,
                  (void**)&me->piwButton);
   }
   if(AEE_SUCCESS == nErr) {
      IWidget *piwButton = me->piwButton;
      IWidget *pchild = NULL;
      nErr = ISHELL_CreateInstance(me->piShell, AEECLSID_StaticWidget,
                  (void**)&pchild);
      if(NULL != pchild)
      {
         (void)IWIDGET_SetText(pchild, awchButton, FALSE);
         (void)IWidget_SetBorderWidth(pchild, 0);
         (void)IWidget_SetFontClass(pchild, AEECLSID_FONTSYSBOLD);
         (void)IWidget_SetFlags(pchild, IDF_ALIGN_CENTER|IDF_ALIGN_MIDDLE);

         IDECORATOR_SetWidget(CAST(IDecorator *, piwButton), pchild);
      }
      RELEASEIF(pchild);

      // add a listener for button
      {
         IModel *pivmOK = 0;
         (void)IWidget_GetViewModel(piwButton, &pivmOK);
         (void)IMODEL_AddListenerEx(pivmOK, &me->mlButton,
                     (PFNLISTENER)confirmform_ButtonListener, me);
         RELEASEIF(pivmOK);
      }

      // insert
      {
         WidgetPos wpos;
         WExtent wex;
         IWidget_GetPreferredExtent(piwButton, &wex);
         IWidget_SetExtent(piwButton, &wex);
         wpos.x = (int)( ((int)me->rcPop.dx-2*me->nPad-wex.width) / 2);
         wpos.y = nY;
         wpos.bVisible = TRUE;
         (void)IXYCONTAINER_Insert(picXY, piwButton, NULL, &wpos);
         GETNEXT_XY(weCont, wex, nX, nY, dX, dY);
      }
   }