static int motToggleSetValueAttrib(Ihandle* ih, const char* value) { Ihandle *radio; unsigned char check; if (iupStrEqualNoCase(value,"TOGGLE")) check = (unsigned char)-1; else if (iupStrEqualNoCase(value,"NOTDEF")) check = XmINDETERMINATE; else if (iupStrBoolean(value)) check = XmSET; else check = XmUNSET; /* This is necessary because Motif toggle does not have support for radio. It is implemented using an external RadioBox that we do not use. */ radio = iupRadioFindToggleParent(ih); if (radio) { Ihandle* last_tg; unsigned char oldcheck; if (check == (unsigned char)-1) check = XmSET; XtVaGetValues(ih->handle, XmNset, &oldcheck, NULL); last_tg = (Ihandle*)iupAttribGet(radio, "_IUPMOT_LASTTOGGLE"); if (check) { if (iupObjectCheck(last_tg) && last_tg != ih) XtVaSetValues(last_tg->handle, XmNset, XmUNSET, NULL); iupAttribSet(radio, "_IUPMOT_LASTTOGGLE", (char*)ih); } if (last_tg != ih && oldcheck != check) XtVaSetValues(ih->handle, XmNset, check, NULL); } else { if (check == (unsigned char)-1) { unsigned char oldcheck; XtVaGetValues(ih->handle, XmNset, &oldcheck, NULL); if (oldcheck == XmSET) check = XmUNSET; else check = XmSET; } XtVaSetValues(ih->handle, XmNset, check, NULL); } return 0; }
static char* iFlatButtonGetRadioAttrib(Ihandle* ih) { if (iupAttribGetBoolean(ih, "TOGGLE")) { Ihandle* radio = iupRadioFindToggleParent(ih); return iupStrReturnBoolean(radio != NULL); } else return NULL; }
static void motToggleValueChangedCallback(Widget w, Ihandle* ih, XmToggleButtonCallbackStruct* call_data) { Ihandle *radio; IFni cb; int check = call_data->set; /* Must manually hide the tip if the toggle is pressed. */ iupmotTipLeaveNotify(); /* This is necessary because Motif toggle does not have support for radio. It is implemented using an external RadioBox that we do not use. */ radio = iupRadioFindToggleParent(ih); if (radio) { if (check) { Ihandle* last_tg = (Ihandle*)iupAttribGetStr(radio, "_IUPMOT_LASTTOGGLE"); if (iupObjectCheck(last_tg) && last_tg != ih) { cb = (IFni) IupGetCallback(last_tg, "ACTION"); if (cb && cb(last_tg, 0) == IUP_CLOSE) IupExitLoop(); XtVaSetValues(last_tg->handle, XmNset, XmUNSET, NULL); } iupAttribSetStr(radio, "_IUPMOT_LASTTOGGLE", (char*)ih); if (last_tg != ih) { cb = (IFni)IupGetCallback(ih, "ACTION"); if (cb && cb (ih, 1) == IUP_CLOSE) IupExitLoop(); } } else { /* Force stay checked */ XtVaSetValues(ih->handle, XmNset, XmSET, NULL); } } else { if (check == XmINDETERMINATE) check = -1; cb = (IFni)IupGetCallback(ih, "ACTION"); if (cb) { if (cb(ih, check) == IUP_CLOSE) IupExitLoop(); } } (void)w; }
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 gtkToggleSetValueAttrib(Ihandle* ih, const char* value) { if (iupStrEqualNoCase(value,"NOTDEF")) gtk_toggle_button_set_inconsistent((GtkToggleButton*)ih->handle, TRUE); else { int check; Ihandle* last_ih = NULL; Ihandle* radio = iupRadioFindToggleParent(ih); gtk_toggle_button_set_inconsistent((GtkToggleButton*)ih->handle, FALSE); /* This action causes the toggled signal to be emitted. */ iupAttribSet(ih, "_IUPGTK_IGNORE_TOGGLE", "1"); if (radio) { last_ih = (Ihandle*)IupGetAttribute(radio, "VALUE_HANDLE"); if (last_ih) iupAttribSet(last_ih, "_IUPGTK_IGNORE_TOGGLE", "1"); } if (iupStrEqualNoCase(value,"TOGGLE")) { if (gtk_toggle_button_get_active((GtkToggleButton*)ih->handle)) check = 0; else check = 1; } else check = iupStrBoolean(value); if (check) gtk_toggle_button_set_active((GtkToggleButton*)ih->handle, TRUE); else { gtk_toggle_button_set_active((GtkToggleButton*)ih->handle, FALSE); if (ih->data->type == IUP_TOGGLE_IMAGE && ih->data->flat) gtk_button_set_relief((GtkButton*)ih->handle, GTK_RELIEF_NONE); } if (ih->data->type == IUP_TOGGLE_IMAGE) gtkToggleUpdateImage(ih, iupdrvIsActive(ih), gtkToggleGetCheck(ih)); iupAttribSet(ih, "_IUPGTK_IGNORE_TOGGLE", NULL); if (last_ih) iupAttribSet(last_ih, "_IUPGTK_IGNORE_TOGGLE", NULL); } return 0; }
static int iFlatButtonSetValueAttrib(Ihandle* ih, const char* value) { if (iupAttribGetBoolean(ih, "TOGGLE")) { Ihandle* radio = iupRadioFindToggleParent(ih); if (radio) { /* can only set Radio to ON */ if (iupStrEqualNoCase(value, "TOGGLE") || iupStrBoolean(value)) { Ihandle* last_tg = (Ihandle*)iupAttribGet(radio, "_IUP_FLATBUTTON_LASTRADIO"); if (iupObjectCheck(last_tg) && last_tg != ih) { iupAttribSet(last_tg, "VALUE", "OFF"); if (last_tg->handle) iupdrvRedrawNow(last_tg); } iupAttribSet(radio, "_IUP_FLATBUTTON_LASTRADIO", (char*)ih); } else return 0; } else { if (iupStrEqualNoCase(value, "TOGGLE")) { int oldcheck = iupAttribGetBoolean(ih, "VALUE"); if (oldcheck) iupAttribSet(ih, "VALUE", "OFF"); else iupAttribSet(ih, "VALUE", "ON"); if (ih->handle) iupdrvRedrawNow(ih); return 0; } } if (ih->handle) iupdrvPostRedraw(ih); return 1; } else return 0; }
static int motToggleMapMethod(Ihandle* ih) { Ihandle* radio = iupRadioFindToggleParent(ih); char* value; int num_args = 0; Arg args[40]; if (radio) ih->data->radio = 1; value = iupAttribGetStr(ih, "IMAGE"); if (value) { ih->data->type = IUP_TOGGLE_IMAGE; iupmotSetArg(args[num_args++], XmNlabelType, XmPIXMAP) } else {
static int iFlatButtonMapMethod(Ihandle* ih) { if (iupAttribGetBoolean(ih, "TOGGLE")) { Ihandle* radio = iupRadioFindToggleParent(ih); if (radio) { if (!iupAttribGet(radio, "_IUP_FLATBUTTON_LASTRADIO")) { /* this is the first toggle in the radio, and then set it with VALUE=ON */ iupAttribSet(ih, "VALUE", "ON"); } /* make sure it has at least one name */ if (!iupAttribGetHandleName(ih)) iupAttribSetHandleName(ih); } } return IUP_NOERROR; }
static int gtkToggleMapMethod(Ihandle* ih) { Ihandle* radio = iupRadioFindToggleParent(ih); char *value; int is3state = 0; if (!ih->parent) return IUP_ERROR; if (radio) ih->data->radio = 1; value = iupAttribGet(ih, "IMAGE"); if (value) ih->data->type = IUP_TOGGLE_IMAGE; else ih->data->type = IUP_TOGGLE_TEXT; if (radio) { GtkRadioButton* last_tg = (GtkRadioButton*)iupAttribGet(radio, "_IUPGTK_LASTRADIOBUTTON"); if (last_tg) ih->handle = gtk_radio_button_new_from_widget(last_tg); else ih->handle = gtk_radio_button_new(NULL); iupAttribSetStr(radio, "_IUPGTK_LASTRADIOBUTTON", (char*)ih->handle); } else { if (ih->data->type == IUP_TOGGLE_TEXT) { ih->handle = gtk_check_button_new(); if (iupAttribGetInt(ih, "3STATE")) is3state = 1; } else ih->handle = gtk_toggle_button_new(); } if (!ih->handle) return IUP_ERROR; if (ih->data->type == IUP_TOGGLE_TEXT) { gtk_button_set_image((GtkButton*)ih->handle, gtk_label_new(NULL)); gtk_toggle_button_set_mode((GtkToggleButton*)ih->handle, TRUE); } else { gtk_button_set_image((GtkButton*)ih->handle, gtk_image_new()); gtk_toggle_button_set_mode((GtkToggleButton*)ih->handle, FALSE); } /* add to the parent, all GTK controls must call this. */ iupgtkBaseAddToParent(ih); if (!iupStrBoolean(iupAttribGetStr(ih, "CANFOCUS"))) GTK_WIDGET_FLAGS(ih->handle) &= ~GTK_CAN_FOCUS; g_signal_connect(G_OBJECT(ih->handle), "enter-notify-event", G_CALLBACK(iupgtkEnterLeaveEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "leave-notify-event", G_CALLBACK(iupgtkEnterLeaveEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "focus-in-event", G_CALLBACK(iupgtkFocusInOutEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "focus-out-event", G_CALLBACK(iupgtkFocusInOutEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "key-press-event", G_CALLBACK(iupgtkKeyPressEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "show-help", G_CALLBACK(iupgtkShowHelp), ih); g_signal_connect(G_OBJECT(ih->handle), "toggled", G_CALLBACK(gtkToggleToggled), ih); if (ih->data->type == IUP_TOGGLE_IMAGE || is3state) { g_signal_connect(G_OBJECT(ih->handle), "button-press-event", G_CALLBACK(gtkToggleButtonEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "button-release-event",G_CALLBACK(gtkToggleButtonEvent), ih); } if (is3state) { g_signal_connect(G_OBJECT(ih->handle), "key-press-event", G_CALLBACK(gtkToggleKeyEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "key-release-event", G_CALLBACK(gtkToggleKeyEvent), ih); } gtk_widget_realize(ih->handle); return IUP_NOERROR; }
static int gtkToggleMapMethod(Ihandle* ih) { Ihandle* radio = iupRadioFindToggleParent(ih); char *value; int is3state = 0; if (!ih->parent) return IUP_ERROR; value = iupAttribGet(ih, "IMAGE"); if (value) ih->data->type = IUP_TOGGLE_IMAGE; else ih->data->type = IUP_TOGGLE_TEXT; if (radio) { GtkRadioButton* last_tg = (GtkRadioButton*)iupAttribGet(radio, "_IUPGTK_LASTRADIOBUTTON"); if (last_tg) ih->handle = gtk_radio_button_new_from_widget(last_tg); else ih->handle = gtk_radio_button_new(NULL); iupAttribSet(radio, "_IUPGTK_LASTRADIOBUTTON", (char*)ih->handle); /* make sure it has at least one name */ if (!iupAttribGetHandleName(ih)) iupAttribSetHandleName(ih); ih->data->is_radio = 1; } else { if (ih->data->type == IUP_TOGGLE_TEXT) { ih->handle = gtk_check_button_new(); if (iupAttribGetBoolean(ih, "3STATE")) is3state = 1; } else ih->handle = gtk_toggle_button_new(); } if (!ih->handle) return IUP_ERROR; if (ih->data->type == IUP_TOGGLE_TEXT) { gtk_button_set_image((GtkButton*)ih->handle, gtk_label_new(NULL)); gtk_toggle_button_set_mode((GtkToggleButton*)ih->handle, TRUE); } else { gtk_button_set_image((GtkButton*)ih->handle, gtk_image_new()); gtk_toggle_button_set_mode((GtkToggleButton*)ih->handle, FALSE); } iupgtkClearSizeStyleCSS(ih->handle); /* add to the parent, all GTK controls must call this. */ iupgtkAddToParent(ih); if (!iupAttribGetBoolean(ih, "CANFOCUS")) iupgtkSetCanFocus(ih->handle, 0); if (ih->data->type == IUP_TOGGLE_IMAGE && ih->data->flat) { gtk_button_set_relief((GtkButton*)ih->handle, GTK_RELIEF_NONE); g_signal_connect(G_OBJECT(ih->handle), "enter-notify-event", G_CALLBACK(gtkToggleEnterLeaveEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "leave-notify-event", G_CALLBACK(gtkToggleEnterLeaveEvent), ih); } else { g_signal_connect(G_OBJECT(ih->handle), "enter-notify-event", G_CALLBACK(iupgtkEnterLeaveEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "leave-notify-event", G_CALLBACK(iupgtkEnterLeaveEvent), ih); } g_signal_connect(G_OBJECT(ih->handle), "focus-in-event", G_CALLBACK(iupgtkFocusInOutEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "focus-out-event", G_CALLBACK(iupgtkFocusInOutEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "key-press-event", G_CALLBACK(iupgtkKeyPressEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "show-help", G_CALLBACK(iupgtkShowHelp), ih); g_signal_connect(G_OBJECT(ih->handle), "toggled", G_CALLBACK(gtkToggleToggled), ih); if (ih->data->type == IUP_TOGGLE_IMAGE || is3state) { g_signal_connect(G_OBJECT(ih->handle), "button-press-event", G_CALLBACK(gtkToggleButtonEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "button-release-event",G_CALLBACK(gtkToggleButtonEvent), ih); } if (is3state) { g_signal_connect(G_OBJECT(ih->handle), "key-press-event", G_CALLBACK(gtkToggleKeyEvent), ih); g_signal_connect(G_OBJECT(ih->handle), "key-release-event", G_CALLBACK(gtkToggleKeyEvent), ih); } gtk_widget_realize(ih->handle); /* update a mnemonic in a label if necessary */ iupgtkUpdateMnemonic(ih); return IUP_NOERROR; }
static int winToggleMapMethod(Ihandle* ih) { Ihandle* radio = iupRadioFindToggleParent(ih); char* value; int ownerdraw = 0; DWORD dwStyle = WS_CHILD | WS_CLIPSIBLINGS | BS_NOTIFY; /* necessary because of the base messages */ if (!ih->parent) return IUP_ERROR; if (radio) ih->data->radio = 1; value = iupAttribGet(ih, "IMAGE"); if (value) { ih->data->type = IUP_TOGGLE_IMAGE; if (!iupwin_comctl32ver6 && ih->data->flat) { dwStyle |= BS_OWNERDRAW; ownerdraw = 1; } else dwStyle |= BS_BITMAP|BS_PUSHLIKE; } else { ih->data->type = IUP_TOGGLE_TEXT; dwStyle |= BS_TEXT|BS_MULTILINE; if (iupAttribGetBoolean(ih, "RIGHTBUTTON")) dwStyle |= BS_RIGHTBUTTON; } if (iupAttribGetBoolean(ih, "CANFOCUS")) dwStyle |= WS_TABSTOP; if (radio) { if (!ownerdraw) dwStyle |= BS_RADIOBUTTON; if (!iupAttribGet(radio, "_IUPWIN_LASTTOGGLE")) { /* this is the first toggle in the radio, and then set it with VALUE=ON */ iupAttribSet(ih, "VALUE","ON"); } } else if (!ownerdraw) { if (ih->data->type == IUP_TOGGLE_TEXT && iupAttribGetBoolean(ih, "3STATE")) dwStyle |= BS_AUTO3STATE; else dwStyle |= BS_AUTOCHECKBOX; } if (!iupwinCreateWindow(ih, WC_BUTTON, 0, dwStyle, NULL)) return IUP_ERROR; /* Process WM_COMMAND */ IupSetCallback(ih, "_IUPWIN_COMMAND_CB", (Icallback)winToggleWmCommand); /* Process background color */ IupSetCallback(ih, "_IUPWIN_CTLCOLOR_CB", (Icallback)winToggleCtlColor); if (ih->data->type == IUP_TOGGLE_IMAGE) { if (iupwin_comctl32ver6) { IupSetCallback(ih, "_IUPWIN_NOTIFY_CB", (Icallback)winToggleImageWmNotify); /* Process WM_NOTIFY */ if (ih->data->flat) IupSetCallback(ih, "_IUPWIN_CTRLMSGPROC_CB", (Icallback)winToggleImageFlatMsgProc); } else { if (ih->data->flat) { iupAttribSet(ih, "FLAT_ALPHA", "NO"); IupSetCallback(ih, "_IUPWIN_DRAWITEM_CB", (Icallback)winToggleDrawItem); /* Process WM_DRAWITEM */ IupSetCallback(ih, "_IUPWIN_CTRLMSGPROC_CB", (Icallback)winToggleImageFlatMsgProc); } else { IupSetCallback(ih, "_IUPWIN_CTRLMSGPROC_CB", (Icallback)winToggleImageClassicMsgProc); iupAttribSet(ih, "_IUPWIN_ACTIVE", "YES"); } } } return IUP_NOERROR; }
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 */ }
static int motToggleMapMethod(Ihandle* ih) { Ihandle* radio = iupRadioFindToggleParent(ih); char* value; int num_args = 0; Arg args[40]; if (radio) ih->data->radio = 1; value = iupAttribGet(ih, "IMAGE"); if (value) { ih->data->type = IUP_TOGGLE_IMAGE; iupmotSetArg(args[num_args++], XmNlabelType, XmPIXMAP); } else { ih->data->type = IUP_TOGGLE_TEXT; iupmotSetArg(args[num_args++], XmNlabelType, XmSTRING); } /* Core */ iupmotSetArg(args[num_args++], XmNmappedWhenManaged, False); /* not visible when managed */ iupmotSetArg(args[num_args++], XmNx, 0); /* x-position */ iupmotSetArg(args[num_args++], XmNy, 0); /* y-position */ iupmotSetArg(args[num_args++], XmNwidth, 10); /* default width to avoid 0 */ iupmotSetArg(args[num_args++], XmNheight, 10); /* default height to avoid 0 */ /* Primitive */ if (iupStrBoolean(iupAttribGetStr(ih, "CANFOCUS"))) iupmotSetArg(args[num_args++], XmNtraversalOn, True); else iupmotSetArg(args[num_args++], XmNtraversalOn, False); iupmotSetArg(args[num_args++], XmNhighlightThickness, 2); iupmotSetArg(args[num_args++], XmNnavigationType, XmTAB_GROUP); /* Label */ iupmotSetArg(args[num_args++], XmNrecomputeSize, False); /* no automatic resize from text */ iupmotSetArg(args[num_args++], XmNmarginHeight, 0); /* default padding */ iupmotSetArg(args[num_args++], XmNmarginWidth, 0); iupmotSetArg(args[num_args++], XmNmarginTop, 0); /* no extra margins */ iupmotSetArg(args[num_args++], XmNmarginLeft, 0); iupmotSetArg(args[num_args++], XmNmarginBottom, 0); iupmotSetArg(args[num_args++], XmNmarginRight, 0); if (radio) { iupmotSetArg(args[num_args++], XmNtoggleMode, XmTOGGLE_BOOLEAN); iupmotSetArg(args[num_args++], XmNindicatorType, XmONE_OF_MANY_ROUND); if (!iupAttribGet(radio, "_IUPMOT_LASTTOGGLE")) { /* this is the first toggle in the radio, and the last toggle with VALUE=ON */ iupAttribSetStr(ih, "VALUE","ON"); } } else { if (ih->data->type == IUP_TOGGLE_TEXT && iupAttribGetInt(ih, "3STATE")) iupmotSetArg(args[num_args++], XmNtoggleMode, XmTOGGLE_INDETERMINATE); else iupmotSetArg(args[num_args++], XmNtoggleMode, XmTOGGLE_BOOLEAN); iupmotSetArg(args[num_args++], XmNindicatorType, XmN_OF_MANY); } if (ih->data->type == IUP_TOGGLE_IMAGE) { iupmotSetArg(args[num_args++], XmNindicatorOn, XmINDICATOR_NONE); iupmotSetArg(args[num_args++], XmNalignment, XmALIGNMENT_CENTER); iupmotSetArg(args[num_args++], XmNshadowThickness, 2); } else { iupmotSetArg(args[num_args++], XmNspacing, 3); iupmotSetArg(args[num_args++], XmNindicatorOn, XmINDICATOR_CHECK_BOX); iupmotSetArg(args[num_args++], XmNalignment, XmALIGNMENT_BEGINNING); if (radio) { iupmotSetArg(args[num_args++], XmNindicatorSize, 13); iupmotSetArg(args[num_args++], XmNselectColor, iupmotColorGetPixel(0, 0, 0)); } else iupmotSetArg(args[num_args++], XmNindicatorSize, 15); iupmotSetArg(args[num_args++], XmNshadowThickness, 0); iupmotSetArg(args[num_args++], XmNdetailShadowThickness, 2); } ih->handle = XtCreateManagedWidget( iupDialogGetChildIdStr(ih), /* child identifier */ xmToggleButtonWidgetClass, /* widget class */ iupChildTreeGetNativeParentHandle(ih), /* widget parent */ args, num_args); if (!ih->handle) return IUP_ERROR; ih->serial = iupDialogGetChildId(ih); /* must be after using the string */ XtAddCallback(ih->handle, XmNhelpCallback, (XtCallbackProc)iupmotHelpCallback, (XtPointer)ih); XtAddEventHandler(ih->handle, EnterWindowMask, False, (XtEventHandler)iupmotEnterLeaveWindowEvent, (XtPointer)ih); XtAddEventHandler(ih->handle, LeaveWindowMask, False, (XtEventHandler)iupmotEnterLeaveWindowEvent, (XtPointer)ih); XtAddEventHandler(ih->handle, FocusChangeMask, False, (XtEventHandler)iupmotFocusChangeEvent, (XtPointer)ih); XtAddEventHandler(ih->handle, KeyPressMask, False, (XtEventHandler)iupmotKeyPressEvent, (XtPointer)ih); XtAddCallback(ih->handle, XmNvalueChangedCallback, (XtCallbackProc)motToggleValueChangedCallback, (XtPointer)ih); /* Disable Drag Source */ iupmotDisableDragSource(ih->handle); /* initialize the widget */ XtRealizeWidget(ih->handle); if (ih->data->type == IUP_TOGGLE_TEXT) iupmotSetString(ih->handle, XmNlabelString, ""); return IUP_NOERROR; }
static int iFlatButtonButton_CB(Ihandle* ih, int button, int pressed, int x, int y, char* status) { IFniiiis cb = (IFniiiis)IupGetCallback(ih, "FLAT_BUTTON_CB"); if (cb) { if (cb(ih, button, pressed, x, y, status) == IUP_IGNORE) return IUP_DEFAULT; } if (button == IUP_BUTTON1) { if (iupAttribGetBoolean(ih, "TOGGLE")) { Ihandle* radio = iupRadioFindToggleParent(ih); int selected = iupAttribGetInt(ih, "VALUE"); Ihandle* last_tg = NULL; if (!pressed) { if (selected) /* was ON */ { if (!radio) { iupAttribSet(ih, "VALUE", "OFF"); selected = 0; } else last_tg = ih; /* to avoid the callback call */ } else /* was OFF */ { if (radio) { last_tg = (Ihandle*)iupAttribGet(radio, "_IUP_FLATBUTTON_LASTRADIO"); if (iupObjectCheck(last_tg) && last_tg != ih) { iupAttribSet(last_tg, "VALUE", "OFF"); iupdrvRedrawNow(last_tg); } else last_tg = NULL; iupAttribSet(radio, "_IUP_FLATBUTTON_LASTRADIO", (char*)ih); } iupAttribSet(ih, "VALUE", "ON"); selected = 1; } } ih->data->pressed = pressed; iupdrvRedrawNow(ih); if (!pressed) { if (last_tg && ih != last_tg) iFlatButtonNotify(last_tg, 1); if (!radio || ih != last_tg) iFlatButtonNotify(ih, 1); } } else { ih->data->pressed = pressed; iupdrvRedrawNow(ih); if (!pressed) iFlatButtonNotify(ih, 0); } } return IUP_DEFAULT; }
static int winToggleMapMethod(Ihandle* ih) { Ihandle* radio = iupRadioFindToggleParent(ih); char* value; DWORD dwStyle = WS_CHILD | WS_CLIPSIBLINGS | BS_NOTIFY; /* necessary because of the base messages */ if (!ih->parent) return IUP_ERROR; if (radio) ih->data->radio = 1; value = iupAttribGet(ih, "IMAGE"); if (value) { ih->data->type = IUP_TOGGLE_IMAGE; dwStyle |= BS_BITMAP|BS_PUSHLIKE; } else { ih->data->type = IUP_TOGGLE_TEXT; dwStyle |= BS_TEXT|BS_MULTILINE; if (iupAttribGetBoolean(ih, "RIGHTBUTTON")) dwStyle |= BS_RIGHTBUTTON; } if (iupAttribGetBoolean(ih, "CANFOCUS")) dwStyle |= WS_TABSTOP; if (radio) { dwStyle |= BS_RADIOBUTTON; if (!iupAttribGet(radio, "_IUPWIN_LASTTOGGLE")) { /* this is the first toggle in the radio, and the last toggle with VALUE=ON */ iupAttribSetStr(ih, "VALUE","ON"); } } else { if (ih->data->type == IUP_TOGGLE_TEXT && iupAttribGetBoolean(ih, "3STATE")) dwStyle |= BS_AUTO3STATE; else dwStyle |= BS_AUTOCHECKBOX; } if (!iupwinCreateWindowEx(ih, "BUTTON", 0, dwStyle)) return IUP_ERROR; /* Process WM_COMMAND */ IupSetCallback(ih, "_IUPWIN_COMMAND_CB", (Icallback)winToggleWmCommand); /* Process background color */ IupSetCallback(ih, "_IUPWIN_CTLCOLOR_CB", (Icallback)winToggleCtlColor); if (ih->data->type == IUP_TOGGLE_IMAGE) { if (iupwin_comctl32ver6) IupSetCallback(ih, "_IUPWIN_NOTIFY_CB", (Icallback)winToggleWmNotify); /* Process WM_NOTIFY */ else { IupSetCallback(ih, "_IUPWIN_CTRLPROC_CB", (Icallback)winToggleProc); iupAttribSetStr(ih, "_IUPWIN_ACTIVE", "YES"); } } return IUP_NOERROR; }