static int winToggleImageClassicMsgProc(Ihandle* ih, UINT msg, WPARAM wp, LPARAM lp, LRESULT *result)
{
    /* Called only when (ih->data->type==IUP_TOGGLE_IMAGE && !iupwin_comctl32ver6 && !ih->data->flat) */

    switch (msg)
    {
    case WM_MOUSEACTIVATE:
        if (!winToggleIsActive(ih))
        {
            *result = MA_NOACTIVATEANDEAT;
            return 1;
        }
        break;
    case WM_LBUTTONDOWN:
    case WM_LBUTTONUP:
    case WM_ACTIVATE:
    case WM_SETFOCUS:
        if (!winToggleIsActive(ih))
        {
            *result = 0;
            return 1;
        }
        break;
    }

    if (msg == WM_LBUTTONDOWN)
        winToggleUpdateImage(ih, 1, 1);
    else if (msg == WM_LBUTTONUP)
        winToggleUpdateImage(ih, 1, 0);

    return iupwinBaseMsgProc(ih, msg, wp, lp, result);
}
Exemple #2
0
static int winToggleProc(Ihandle* ih, UINT msg, WPARAM wp, LPARAM lp, LRESULT *result)
{
  (void)lp;
  (void)wp;

  switch (msg)
  {
    case WM_MOUSEACTIVATE:
      if (!winToggleIsActive(ih))
      {
        *result = MA_NOACTIVATEANDEAT;
        return 1;
      }
      break;
    case WM_LBUTTONDOWN:
    case WM_LBUTTONUP:
    case WM_ACTIVATE:
    case WM_SETFOCUS:
      if (!winToggleIsActive(ih)) 
      {
        *result = 0;
        return 1;
      }
      break;
  }

  if (msg == WM_LBUTTONDOWN)
    winToggleUpdateImage(ih, 1, 1);
  else if (msg == WM_LBUTTONUP)
    winToggleUpdateImage(ih, 1, 0);

  return iupwinBaseProc(ih, msg, wp, lp, result);
}
static int winToggleSetActiveAttrib(Ihandle* ih, const char* value)
{
    /* update the inactive image if necessary */
    if (ih->data->type==IUP_TOGGLE_IMAGE)
    {
        if (iupwin_comctl32ver6 || ih->data->flat)
        {
            iupBaseSetActiveAttrib(ih, value);
            iupdrvRedrawNow(ih);
            return 0;
        }
        else
        {
            int active = iupStrBoolean(value);
            int check = SendMessage(ih->handle, BM_GETCHECK, 0, 0L);
            if (active)
                iupAttribSet(ih, "_IUPWIN_ACTIVE", "YES");
            else
                iupAttribSet(ih, "_IUPWIN_ACTIVE", "NO");
            winToggleUpdateImage(ih, active, check);
            return 0;
        }
    }

    return iupBaseSetActiveAttrib(ih, value);
}
static int winToggleSetValueAttrib(Ihandle* ih, const char* value)
{
    Ihandle *radio;
    int check;

    if (iupStrEqualNoCase(value,"TOGGLE"))
        check = -1;
    else if (iupStrEqualNoCase(value,"NOTDEF"))
        check = BST_INDETERMINATE;
    else if (iupStrBoolean(value))
        check = BST_CHECKED;
    else
        check = BST_UNCHECKED;

    /* This is necessary because Windows does not handle the radio state
       when a toggle is programatically changed. */
    radio = iupRadioFindToggleParent(ih);
    if (radio)
    {
        Ihandle* last_tg;

        int oldcheck = winToggleGetCheck(ih);
        if (check == -1)
            check = BST_CHECKED;

        last_tg = (Ihandle*)iupAttribGet(radio, "_IUPWIN_LASTTOGGLE");
        if (check)
        {
            if (iupObjectCheck(last_tg) && last_tg != ih)
                winToggleSetCheck(last_tg, BST_UNCHECKED);
            iupAttribSet(radio, "_IUPWIN_LASTTOGGLE", (char*)ih);
        }

        if (last_tg != ih && oldcheck != check)
            winToggleSetCheck(ih, check);
    }
    else
    {
        if (check == -1)
        {
            int oldcheck = winToggleGetCheck(ih);
            if (oldcheck)
                check = BST_UNCHECKED;
            else
                check = BST_CHECKED;
        }

        winToggleSetCheck(ih, check);
    }

    if (ih->data->type==IUP_TOGGLE_IMAGE && !iupwin_comctl32ver6 && !ih->data->flat)
        winToggleUpdateImage(ih, winToggleIsActive(ih), check);

    return 0;
}
static int winToggleSetImPressAttrib(Ihandle* ih, const char* value)
{
    if (ih->data->type==IUP_TOGGLE_IMAGE)
    {
        if (value != iupAttribGet(ih, "IMPRESS"))
            iupAttribSet(ih, "IMPRESS", (char*)value);

        if (iupwin_comctl32ver6 || ih->data->flat)
            iupdrvRedrawNow(ih);
        else
        {
            int check = SendMessage(ih->handle, BM_GETCHECK, 0L, 0L);
            winToggleUpdateImage(ih, winToggleIsActive(ih), check);
        }
        return 1;
    }
    else
        return 0;
}
Exemple #6
0
static int winToggleSetImInactiveAttrib(Ihandle* ih, const char* value)
{
  if (ih->data->type == IUP_TOGGLE_IMAGE)
  {
    if (value != iupAttribGet(ih, "IMINACTIVE"))
      iupAttribSetStr(ih, "IMINACTIVE", (char*)value);

    if (iupwin_comctl32ver6)
      iupdrvDisplayRedraw(ih);
    else
    {
      int check = SendMessage(ih->handle, BM_GETCHECK, 0L, 0L);
      winToggleUpdateImage(ih, winToggleIsActive(ih), check);
    }
    return 1;
  }
  else
    return 0;
}
static int winToggleWmCommand(Ihandle* ih, WPARAM wp, LPARAM lp)
{
    (void)lp;

    switch (HIWORD(wp))
    {
    case BN_DOUBLECLICKED:
    case BN_CLICKED:
    {
        Ihandle *radio;
        IFni cb;
        int check = winToggleGetCheck(ih);

        if (ih->data->type==IUP_TOGGLE_IMAGE && !iupwin_comctl32ver6 && !ih->data->flat)
        {
            int active = winToggleIsActive(ih);
            winToggleUpdateImage(ih, active, check);
            if (!active)
                return 0;
        }

        radio = iupRadioFindToggleParent(ih);
        if (radio)
        {
            /* This is necessary because Windows does not send a message
               when a toggle is unchecked in a Radio.
               Also if the toggle is already checked in a radio,
               a click will call the callback again. */

            Ihandle* last_tg = (Ihandle*)iupAttribGet(radio, "_IUPWIN_LASTTOGGLE");
            if (iupObjectCheck(last_tg) && last_tg != ih)
            {
                /* uncheck last toggle */
                winToggleSetCheck(last_tg, BST_UNCHECKED);

                cb = (IFni) IupGetCallback(last_tg, "ACTION");
                if (cb && cb(last_tg, 0) == IUP_CLOSE)
                    IupExitLoop();

                if (iupObjectCheck(last_tg))
                    iupBaseCallValueChangedCb(last_tg);
            }
            iupAttribSet(radio, "_IUPWIN_LASTTOGGLE", (char*)ih);

            if (last_tg != ih)
            {
                /* check new toggle */
                winToggleSetCheck(ih, BST_CHECKED);

                cb = (IFni)IupGetCallback(ih, "ACTION");
                if (cb && cb (ih, 1) == IUP_CLOSE)
                    IupExitLoop();

                if (iupObjectCheck(ih))
                    iupBaseCallValueChangedCb(ih);
            }
        }
        else
        {
            if ((ih->data->type==IUP_TOGGLE_IMAGE && !iupwin_comctl32ver6 && ih->data->flat) ||
                    (HIWORD(wp)==BN_DOUBLECLICKED))
            {
                /* toggle the value manually */
                check = check? 0: BST_CHECKED;
                winToggleSetCheck(ih, check);
            }

            if (check == BST_INDETERMINATE)
                check = -1;

            cb = (IFni)IupGetCallback(ih, "ACTION");
            if (cb && cb (ih, check) == IUP_CLOSE)
                IupExitLoop();

            if (iupObjectCheck(ih))
                iupBaseCallValueChangedCb(ih);
        }
    }
    }

    return 0; /* not used */
}