[Contents] [Back] [Prev] [Up] [Next] [Forward]

# Package Gtk.Toggle`_`Button

A Gtk_Toggle_Button is like a regular button, but can be in one of two states, "active" or "inactive". Its visual aspect is modified when the state is changed.

You should consider using a Gtk_Check_Button instead, since it looks nicer and provides more visual clues that the button can be toggled.

- Gtk.Toggle_Button Widget Hierarchy
- Gtk.Toggle_Button Signals
- Gtk.Toggle_Button Subprograms
- Gtk.Toggle_Button Example

## Widget Hierarchy

    GObject                       (see section Package Glib.Object)
    Gtk_Object                    (see section Package Gtk.Object)
       \___ Gtk_Widget            (see section Package Gtk.Widget)
          \___ Gtk_Container      (see section Package Gtk.Container)
             \___ Gtk_Bin         (see section Package Gtk.Bin)
                \___ Gtk_Button   (see section Package Gtk.Button)
                   \___ Gtk_Toggle_Button (see section Package Gtk.Toggle_Button)

## Signals

- "toggled" procedure Handler (Toggle : access Gtk_Toggle_Button_Record'Class);
  This signal is emitted every time the state of the button is modified.

## Subprograms

    procedure Gtk_New
      (Toggle_Button      : out    Gtk_Toggle_Button;
       Label              :        UTF8_String := "");

| Initialize a button. If Label is "", then no label is created inside the button and you will have to provide your own child through a call to Gtk.Container.Add. This is the recommended way to put a pixmap inside a toggle button.

    procedure Gtk_New_With_Mnemonic
      (Toggle_Button      : out    Gtk_Toggle_Button;
       Label              :        UTF8_String);

| Create a Gtk_Toggle_Button containing Label. The Label will be created using Gtk.Label.Gtk_New_With_Mnemonic, so underscores in Label indicate the mnemonic for the button.

    procedure Initialize_With_Mnemonic
      (Toggle_Button      : access Gtk_Toggle_Button_Record'Class;
       Label              :        UTF8_String);

| Internal initialization function.

    function Get_Type              return Glib.GType;

| Return the internal value associated with a Gtk_Toggle_Button.

    procedure Set_Mode
      (Toggle_Button      : access Gtk_Toggle_Button_Record;
       Draw_Indicator     :        Boolean);

| Change the mode of the button. If Draw_Indicator is False, then the button is hidden.

    function Get_Mode
      (Toggle_Button      : access Gtk_Toggle_Button_Record)
       return Boolean;

| Return the mode of the button.

    procedure Set_Active
      (Toggle_Button      : access Gtk_Toggle_Button_Record;
       Is_Active          :        Boolean);

| Change the state of the button. When Is_Active is True, the button is drawn as a pressed button.

    function Get_Active
      (Toggle_Button      : access Gtk_Toggle_Button_Record)
       return Boolean;

| Return true if the button is in its active state, i.e is pressed.

    procedure Set_Inconsistent
      (Toggle_Button      : access Gtk_Toggle_Button_Record;
       Setting            :        Boolean := True);

If the user has selected a range of elements (such as some text or
spreadsheet cells) that are affected by a toggle button, and the current values in that range are inconsistent, you may want to display the toggle in an "in between" state. This function turns on "in between" display. Normally you would turn off the inconsistent state again if the user toggles the toggle button. This has to be done manually, Set_Inconsistent only affects visual appearance, it doesn't affect the semantics of the button.

    function Get_Inconsistent
      (Toggle_Button      : access Gtk_Toggle_Button_Record)
       return Boolean;

| Get the value set by Set_Inconsistent.

### Signals emission

    procedure Toggled
      (Toggle_Button      : access Gtk_Toggle_Button_Record);

| Emit the toggled signal on this widget. Note that the state of the button is not changed, only the callbacks are called.

## Example

     --  This example creates a toggle button with a pixmap in it

     with Gtk.Toggle_Button, Gdk.Pixmap, Gdk.Bitmap, Gtk.Pixmap;
     with Gtk.Style, Gtk.Enums;

     procedure Toggle is
        Toggle    : Gtk.Toggle_Button.Gtk_Toggle_Button;
        Style     : Gtk.Style.Gtk_Style;
        Pixmap    : Gdk.Pixmap.Gdk_Pixmap;
        Mask      : Gdk.Bitmap.Gdk_Bitmap;
        PixmapWid : Gtk.Pixmap.Gtk_Pixmap;
     begin
        --  Do not specify a label
        Gtk.Toggle_Button.Gtk_New (Toggle);

        Style := Gtk.Toggle_Button.Get_Style (Toggle);
        Gdk.Pixmap.Create_From_Xpm
          (Pixmap,
           Gtk.Toggle_Button.Get_Window (Toggle),
           Mask,
           Gtk.Style.Get_Bg (Style, Gtk.Enums.State_Normal),
           "icon.xpm");
        Gtk.Pixmap.Gtk_New (PixmapWid, Pixmap, Mask);

        --  Add the pixmap to the button
        Gtk.Toggle_Button.Add (Toggle, PixmapWid);
     end Toggle;

[Contents] [Back] [Prev] [Up] [Next] [Forward]