// Code generated by girgen. DO NOT EDIT.

package adw

import (
	"fmt"
	"runtime"
	"unsafe"

	"github.com/diamondburned/gotk4/pkg/core/gextras"
	coreglib "github.com/diamondburned/gotk4/pkg/core/glib"
	"github.com/diamondburned/gotk4/pkg/gtk/v4"
)

// #include <stdlib.h>
// #include <adwaita.h>
// #include <glib-object.h>
import "C"

// GType values.
var (
	GTypeCenteringPolicy = coreglib.Type(C.adw_centering_policy_get_type())
	GTypeHeaderBar       = coreglib.Type(C.adw_header_bar_get_type())
)

func init() {
	coreglib.RegisterGValueMarshalers([]coreglib.TypeMarshaler{
		coreglib.TypeMarshaler{T: GTypeCenteringPolicy, F: marshalCenteringPolicy},
		coreglib.TypeMarshaler{T: GTypeHeaderBar, F: marshalHeaderBar},
	})
}

// CenteringPolicy describes title centering behavior of a headerbar widget.
type CenteringPolicy C.gint

const (
	// CenteringPolicyLoose: keep the title centered when possible.
	CenteringPolicyLoose CenteringPolicy = iota
	// CenteringPolicyStrict: keep the title centered at all cost.
	CenteringPolicyStrict
)

func marshalCenteringPolicy(p uintptr) (interface{}, error) {
	return CenteringPolicy(coreglib.ValueFromNative(unsafe.Pointer(p)).Enum()), nil
}

// String returns the name in string for CenteringPolicy.
func (c CenteringPolicy) String() string {
	switch c {
	case CenteringPolicyLoose:
		return "Loose"
	case CenteringPolicyStrict:
		return "Strict"
	default:
		return fmt.Sprintf("CenteringPolicy(%d)", c)
	}
}

// HeaderBarOverrides contains methods that are overridable.
type HeaderBarOverrides struct {
}

func defaultHeaderBarOverrides(v *HeaderBar) HeaderBarOverrides {
	return HeaderBarOverrides{}
}

// HeaderBar: title bar widget.
//
// <picture> <source srcset="header-bar-dark.png" media="(prefers-color-scheme:
// dark)"> <img src="header-bar.png" alt="header-bar"> </picture>
//
// AdwHeaderBar is similar to gtk.HeaderBar, but provides additional features
// compared to it. Refer to GtkHeaderBar for details. It is typically used as a
// top bar within toolbarview.
//
// # Dialog Integration
//
// When placed inside an dialog, AdwHeaderBar will display the dialog
// title instead of window title. It will also adjust the decoration
// layout to ensure it always has a close button and nothing else. Set
// headerbar:show-start-title-buttons and headerbar:show-end-title-buttons to
// FALSE to remove it if it's unwanted.
//
// # Navigation View Integration
//
// When placed inside an navigationpage, AdwHeaderBar will display the page
// title instead of window title.
//
// When used together with navigationview or navigationsplitview, it will also
// display a back button that can be used to go back to the previous page.
// The button also has a context menu, allowing to pop multiple pages at once,
// potentially across multiple navigation views.
//
// Set headerbar:show-back-button to FALSE to disable this behavior in rare
// scenarios where it's unwanted.
//
// # Split View Integration
//
// When placed inside navigationsplitview or overlaysplitview, AdwHeaderBar will
// automatically hide the title buttons other than at the edges of the window.
//
// # Bottom Sheet Integration
//
// When played inside bottomsheet, AdwHeaderBar will not show the title
// unless bottomsheet:show-drag-handle is set to FALSE, regardless of
// headerbar:show-title. This only applies to the default title, titles set with
// headerbar:title-widget will still be shown.
//
// # Centering Policy
//
// headerbar:centering-policy allows to enforce strict centering of the title
// widget. This can be useful for entries inside clamp.
//
// # Title Buttons
//
// Unlike GtkHeaderBar, AdwHeaderBar allows to toggle title button visibility
// for each side individually, using the headerbar:show-start-title-buttons and
// headerbar:show-end-title-buttons properties.
//
// CSS nodes
//
//	headerbar
//	╰── windowhandle
//	    ╰── box
//	        ├── widget
//	        │   ╰── box.start
//	        │       ├── windowcontrols.start
//	        │       ├── widget
//	        │       │   ╰── [button.back]
//	        │       ╰── [other children]
//	        ├── widget
//	        │   ╰── [Title Widget]
//	        ╰── widget
//	            ╰── box.end
//	                ├── [other children]
//	                ╰── windowcontrols.end
//
// AdwHeaderBar's CSS node is called headerbar. It contains a windowhandle
// subnode, which contains a box subnode, which contains three widget subnodes
// at the start, center and end of the header bar. The start and end subnodes
// contain a box subnode with the .start and .end style classes respectively,
// and the center node contains a node that represents the title.
//
// Each of the boxes contains a windowcontrols subnode, see gtk.WindowControls
// for details, as well as other children.
//
// When headerbar:show-back-button is TRUE, the start box also contains a node
// with the name widget that contains a node with the name button and .back
// style class.
//
// # Accessibility
//
// AdwHeaderBar uses the GTK_ACCESSIBLE_ROLE_GROUP role.
type HeaderBar struct {
	_ [0]func() // equal guard
	gtk.Widget
}

var (
	_ gtk.Widgetter = (*HeaderBar)(nil)
)

func init() {
	coreglib.RegisterClassInfo[*HeaderBar, *HeaderBarClass, HeaderBarOverrides](
		GTypeHeaderBar,
		initHeaderBarClass,
		wrapHeaderBar,
		defaultHeaderBarOverrides,
	)
}

func initHeaderBarClass(gclass unsafe.Pointer, overrides HeaderBarOverrides, classInitFunc func(*HeaderBarClass)) {
	if classInitFunc != nil {
		class := (*HeaderBarClass)(gextras.NewStructNative(gclass))
		classInitFunc(class)
	}
}

func wrapHeaderBar(obj *coreglib.Object) *HeaderBar {
	return &HeaderBar{
		Widget: gtk.Widget{
			InitiallyUnowned: coreglib.InitiallyUnowned{
				Object: obj,
			},
			Object: obj,
			Accessible: gtk.Accessible{
				Object: obj,
			},
			Buildable: gtk.Buildable{
				Object: obj,
			},
			ConstraintTarget: gtk.ConstraintTarget{
				Object: obj,
			},
		},
	}
}

func marshalHeaderBar(p uintptr) (interface{}, error) {
	return wrapHeaderBar(coreglib.ValueFromNative(unsafe.Pointer(p)).Object()), nil
}

// NewHeaderBar creates a new AdwHeaderBar.
//
// The function returns the following values:
//
//   - headerBar: newly created AdwHeaderBar.
func NewHeaderBar() *HeaderBar {
	var _cret *C.GtkWidget // in

	_cret = C.adw_header_bar_new()

	var _headerBar *HeaderBar // out

	_headerBar = wrapHeaderBar(coreglib.Take(unsafe.Pointer(_cret)))

	return _headerBar
}

// CenteringPolicy gets the policy for aligning the center widget.
//
// The function returns the following values:
//
//   - centeringPolicy: centering policy.
func (self *HeaderBar) CenteringPolicy() CenteringPolicy {
	var _arg0 *C.AdwHeaderBar      // out
	var _cret C.AdwCenteringPolicy // in

	_arg0 = (*C.AdwHeaderBar)(unsafe.Pointer(coreglib.InternObject(self).Native()))

	_cret = C.adw_header_bar_get_centering_policy(_arg0)
	runtime.KeepAlive(self)

	var _centeringPolicy CenteringPolicy // out

	_centeringPolicy = CenteringPolicy(_cret)

	return _centeringPolicy
}

// DecorationLayout gets the decoration layout for self.
//
// The function returns the following values:
//
//   - utf8 (optional): decoration layout.
func (self *HeaderBar) DecorationLayout() string {
	var _arg0 *C.AdwHeaderBar // out
	var _cret *C.char         // in

	_arg0 = (*C.AdwHeaderBar)(unsafe.Pointer(coreglib.InternObject(self).Native()))

	_cret = C.adw_header_bar_get_decoration_layout(_arg0)
	runtime.KeepAlive(self)

	var _utf8 string // out

	if _cret != nil {
		_utf8 = C.GoString((*C.gchar)(unsafe.Pointer(_cret)))
	}

	return _utf8
}

// ShowBackButton gets whether self can show the back button.
//
// The function returns the following values:
//
//   - ok: whether to show the back button.
func (self *HeaderBar) ShowBackButton() bool {
	var _arg0 *C.AdwHeaderBar // out
	var _cret C.gboolean      // in

	_arg0 = (*C.AdwHeaderBar)(unsafe.Pointer(coreglib.InternObject(self).Native()))

	_cret = C.adw_header_bar_get_show_back_button(_arg0)
	runtime.KeepAlive(self)

	var _ok bool // out

	if _cret != 0 {
		_ok = true
	}

	return _ok
}

// ShowEndTitleButtons gets whether to show title buttons at the end of self.
//
// The function returns the following values:
//
//   - ok: TRUE if title buttons at the end are shown.
func (self *HeaderBar) ShowEndTitleButtons() bool {
	var _arg0 *C.AdwHeaderBar // out
	var _cret C.gboolean      // in

	_arg0 = (*C.AdwHeaderBar)(unsafe.Pointer(coreglib.InternObject(self).Native()))

	_cret = C.adw_header_bar_get_show_end_title_buttons(_arg0)
	runtime.KeepAlive(self)

	var _ok bool // out

	if _cret != 0 {
		_ok = true
	}

	return _ok
}

// ShowStartTitleButtons gets whether to show title buttons at the start of
// self.
//
// The function returns the following values:
//
//   - ok: TRUE if title buttons at the start are shown.
func (self *HeaderBar) ShowStartTitleButtons() bool {
	var _arg0 *C.AdwHeaderBar // out
	var _cret C.gboolean      // in

	_arg0 = (*C.AdwHeaderBar)(unsafe.Pointer(coreglib.InternObject(self).Native()))

	_cret = C.adw_header_bar_get_show_start_title_buttons(_arg0)
	runtime.KeepAlive(self)

	var _ok bool // out

	if _cret != 0 {
		_ok = true
	}

	return _ok
}

// ShowTitle gets whether the title widget should be shown.
//
// The function returns the following values:
//
//   - ok: whether the title widget should be shown.
func (self *HeaderBar) ShowTitle() bool {
	var _arg0 *C.AdwHeaderBar // out
	var _cret C.gboolean      // in

	_arg0 = (*C.AdwHeaderBar)(unsafe.Pointer(coreglib.InternObject(self).Native()))

	_cret = C.adw_header_bar_get_show_title(_arg0)
	runtime.KeepAlive(self)

	var _ok bool // out

	if _cret != 0 {
		_ok = true
	}

	return _ok
}

// TitleWidget gets the title widget widget of self.
//
// The function returns the following values:
//
//   - widget (optional): title widget.
func (self *HeaderBar) TitleWidget() gtk.Widgetter {
	var _arg0 *C.AdwHeaderBar // out
	var _cret *C.GtkWidget    // in

	_arg0 = (*C.AdwHeaderBar)(unsafe.Pointer(coreglib.InternObject(self).Native()))

	_cret = C.adw_header_bar_get_title_widget(_arg0)
	runtime.KeepAlive(self)

	var _widget gtk.Widgetter // out

	if _cret != nil {
		{
			objptr := unsafe.Pointer(_cret)

			object := coreglib.Take(objptr)
			casted := object.WalkCast(func(obj coreglib.Objector) bool {
				_, ok := obj.(gtk.Widgetter)
				return ok
			})
			rv, ok := casted.(gtk.Widgetter)
			if !ok {
				panic("no marshaler for " + object.TypeFromInstance().String() + " matching gtk.Widgetter")
			}
			_widget = rv
		}
	}

	return _widget
}

// PackEnd adds child to self, packed with reference to the end of self.
//
// The function takes the following parameters:
//
//   - child: widget to be added to self.
func (self *HeaderBar) PackEnd(child gtk.Widgetter) {
	var _arg0 *C.AdwHeaderBar // out
	var _arg1 *C.GtkWidget    // out

	_arg0 = (*C.AdwHeaderBar)(unsafe.Pointer(coreglib.InternObject(self).Native()))
	_arg1 = (*C.GtkWidget)(unsafe.Pointer(coreglib.InternObject(child).Native()))

	C.adw_header_bar_pack_end(_arg0, _arg1)
	runtime.KeepAlive(self)
	runtime.KeepAlive(child)
}

// PackStart adds child to self, packed with reference to the start of the self.
//
// The function takes the following parameters:
//
//   - child: widget to be added to self.
func (self *HeaderBar) PackStart(child gtk.Widgetter) {
	var _arg0 *C.AdwHeaderBar // out
	var _arg1 *C.GtkWidget    // out

	_arg0 = (*C.AdwHeaderBar)(unsafe.Pointer(coreglib.InternObject(self).Native()))
	_arg1 = (*C.GtkWidget)(unsafe.Pointer(coreglib.InternObject(child).Native()))

	C.adw_header_bar_pack_start(_arg0, _arg1)
	runtime.KeepAlive(self)
	runtime.KeepAlive(child)
}

// Remove removes a child from self.
//
// The child must have been added with headerbar.PackStart, headerbar.PackEnd or
// headerbar:title-widget.
//
// The function takes the following parameters:
//
//   - child to remove.
func (self *HeaderBar) Remove(child gtk.Widgetter) {
	var _arg0 *C.AdwHeaderBar // out
	var _arg1 *C.GtkWidget    // out

	_arg0 = (*C.AdwHeaderBar)(unsafe.Pointer(coreglib.InternObject(self).Native()))
	_arg1 = (*C.GtkWidget)(unsafe.Pointer(coreglib.InternObject(child).Native()))

	C.adw_header_bar_remove(_arg0, _arg1)
	runtime.KeepAlive(self)
	runtime.KeepAlive(child)
}

// SetCenteringPolicy sets the policy for aligning the center widget.
//
// The function takes the following parameters:
//
//   - centeringPolicy: centering policy.
func (self *HeaderBar) SetCenteringPolicy(centeringPolicy CenteringPolicy) {
	var _arg0 *C.AdwHeaderBar      // out
	var _arg1 C.AdwCenteringPolicy // out

	_arg0 = (*C.AdwHeaderBar)(unsafe.Pointer(coreglib.InternObject(self).Native()))
	_arg1 = C.AdwCenteringPolicy(centeringPolicy)

	C.adw_header_bar_set_centering_policy(_arg0, _arg1)
	runtime.KeepAlive(self)
	runtime.KeepAlive(centeringPolicy)
}

// SetDecorationLayout sets the decoration layout for self.
//
// If this property is not set, the gtk.Settings:gtk-decoration-layout setting
// is used.
//
// The format of the string is button names, separated by commas. A colon
// separates the buttons that should appear at the start from those at the end.
// Recognized button names are minimize, maximize, close and icon (the window
// icon).
//
// For example, “icon:minimize,maximize,close” specifies an icon at the start,
// and minimize, maximize and close buttons at the end.
//
// The function takes the following parameters:
//
//   - layout (optional): decoration layout.
func (self *HeaderBar) SetDecorationLayout(layout string) {
	var _arg0 *C.AdwHeaderBar // out
	var _arg1 *C.char         // out

	_arg0 = (*C.AdwHeaderBar)(unsafe.Pointer(coreglib.InternObject(self).Native()))
	if layout != "" {
		_arg1 = (*C.char)(unsafe.Pointer(C.CString(layout)))
		defer C.free(unsafe.Pointer(_arg1))
	}

	C.adw_header_bar_set_decoration_layout(_arg0, _arg1)
	runtime.KeepAlive(self)
	runtime.KeepAlive(layout)
}

// SetShowBackButton sets whether self can show the back button.
//
// The back button will never be shown unless the header bar is placed inside an
// navigationview. Usually, there is no reason to set it to FALSE.
//
// The function takes the following parameters:
//
//   - showBackButton: whether to show the back button.
func (self *HeaderBar) SetShowBackButton(showBackButton bool) {
	var _arg0 *C.AdwHeaderBar // out
	var _arg1 C.gboolean      // out

	_arg0 = (*C.AdwHeaderBar)(unsafe.Pointer(coreglib.InternObject(self).Native()))
	if showBackButton {
		_arg1 = C.TRUE
	}

	C.adw_header_bar_set_show_back_button(_arg0, _arg1)
	runtime.KeepAlive(self)
	runtime.KeepAlive(showBackButton)
}

// SetShowEndTitleButtons sets whether to show title buttons at the end of self.
//
// See headerbar:show-start-title-buttons for the other side.
//
// Which buttons are actually shown and where is determined by the
// headerbar:decoration-layout property, and by the state of the window (e.g.
// a close button will not be shown if the window can't be closed).
//
// The function takes the following parameters:
//
//   - setting: TRUE to show standard title buttons.
func (self *HeaderBar) SetShowEndTitleButtons(setting bool) {
	var _arg0 *C.AdwHeaderBar // out
	var _arg1 C.gboolean      // out

	_arg0 = (*C.AdwHeaderBar)(unsafe.Pointer(coreglib.InternObject(self).Native()))
	if setting {
		_arg1 = C.TRUE
	}

	C.adw_header_bar_set_show_end_title_buttons(_arg0, _arg1)
	runtime.KeepAlive(self)
	runtime.KeepAlive(setting)
}

// SetShowStartTitleButtons sets whether to show title buttons at the start of
// self.
//
// See headerbar:show-end-title-buttons for the other side.
//
// Which buttons are actually shown and where is determined by the
// headerbar:decoration-layout property, and by the state of the window (e.g.
// a close button will not be shown if the window can't be closed).
//
// The function takes the following parameters:
//
//   - setting: TRUE to show standard title buttons.
func (self *HeaderBar) SetShowStartTitleButtons(setting bool) {
	var _arg0 *C.AdwHeaderBar // out
	var _arg1 C.gboolean      // out

	_arg0 = (*C.AdwHeaderBar)(unsafe.Pointer(coreglib.InternObject(self).Native()))
	if setting {
		_arg1 = C.TRUE
	}

	C.adw_header_bar_set_show_start_title_buttons(_arg0, _arg1)
	runtime.KeepAlive(self)
	runtime.KeepAlive(setting)
}

// SetShowTitle sets whether the title widget should be shown.
//
// The function takes the following parameters:
//
//   - showTitle: whether the title widget is visible.
func (self *HeaderBar) SetShowTitle(showTitle bool) {
	var _arg0 *C.AdwHeaderBar // out
	var _arg1 C.gboolean      // out

	_arg0 = (*C.AdwHeaderBar)(unsafe.Pointer(coreglib.InternObject(self).Native()))
	if showTitle {
		_arg1 = C.TRUE
	}

	C.adw_header_bar_set_show_title(_arg0, _arg1)
	runtime.KeepAlive(self)
	runtime.KeepAlive(showTitle)
}

// SetTitleWidget sets the title widget for self.
//
// When set to NULL, the header bar will display the title of the window it is
// contained in.
//
// To use a different title, use windowtitle:
//
//	<object class="AdwHeaderBar">
//	  <property name="title-widget">
//	    <object class="AdwWindowTitle">
//	      <property name="title" translatable="yes">Title</property>
//	    </object>
//	  </property>
//	</object>.
//
// The function takes the following parameters:
//
//   - titleWidget (optional): widget to use for a title.
func (self *HeaderBar) SetTitleWidget(titleWidget gtk.Widgetter) {
	var _arg0 *C.AdwHeaderBar // out
	var _arg1 *C.GtkWidget    // out

	_arg0 = (*C.AdwHeaderBar)(unsafe.Pointer(coreglib.InternObject(self).Native()))
	if titleWidget != nil {
		_arg1 = (*C.GtkWidget)(unsafe.Pointer(coreglib.InternObject(titleWidget).Native()))
	}

	C.adw_header_bar_set_title_widget(_arg0, _arg1)
	runtime.KeepAlive(self)
	runtime.KeepAlive(titleWidget)
}

// HeaderBarClass: instance of this type is always passed by reference.
type HeaderBarClass struct {
	*headerBarClass
}

// headerBarClass is the struct that's finalized.
type headerBarClass struct {
	native *C.AdwHeaderBarClass
}

func (h *HeaderBarClass) ParentClass() *gtk.WidgetClass {
	valptr := &h.native.parent_class
	var _v *gtk.WidgetClass // out
	_v = (*gtk.WidgetClass)(gextras.NewStructNative(unsafe.Pointer(valptr)))
	return _v
}
