gtk4/
response_type.rs
1use std::fmt;
4
5use crate::{ffi, prelude::*};
6use glib::{translate::*, value::FromValue, Type, Value};
7
8#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
17#[doc(alias = "GtkResponseType")]
18pub enum ResponseType {
19 #[doc(alias = "GTK_RESPONSE_NONE")]
22 None,
23 #[doc(alias = "GTK_RESPONSE_REJECT")]
25 Reject,
26 #[doc(alias = "GTK_RESPONSE_ACCEPT")]
28 Accept,
29 #[doc(alias = "GTK_RESPONSE_DELETE_EVENT")]
31 DeleteEvent,
32 #[doc(alias = "GTK_RESPONSE_OK")]
34 Ok,
35 #[doc(alias = "GTK_RESPONSE_CANCEL")]
37 Cancel,
38 #[doc(alias = "GTK_RESPONSE_CLOSE")]
40 Close,
41 #[doc(alias = "GTK_RESPONSE_YES")]
43 Yes,
44 #[doc(alias = "GTK_RESPONSE_NO")]
46 No,
47 #[doc(alias = "GTK_RESPONSE_APPLY")]
49 Apply,
50 #[doc(alias = "GTK_RESPONSE_HELP")]
52 Help,
53 Other(u16),
54 #[doc(hidden)]
55 __Unknown(i32),
56}
57
58#[doc(hidden)]
59impl IntoGlib for ResponseType {
60 type GlibType = ffi::GtkResponseType;
61
62 #[inline]
63 fn into_glib(self) -> ffi::GtkResponseType {
64 match self {
65 Self::None => ffi::GTK_RESPONSE_NONE,
66 Self::Reject => ffi::GTK_RESPONSE_REJECT,
67 Self::Accept => ffi::GTK_RESPONSE_ACCEPT,
68 Self::DeleteEvent => ffi::GTK_RESPONSE_DELETE_EVENT,
69 Self::Ok => ffi::GTK_RESPONSE_OK,
70 Self::Cancel => ffi::GTK_RESPONSE_CANCEL,
71 Self::Close => ffi::GTK_RESPONSE_CLOSE,
72 Self::Yes => ffi::GTK_RESPONSE_YES,
73 Self::No => ffi::GTK_RESPONSE_NO,
74 Self::Apply => ffi::GTK_RESPONSE_APPLY,
75 Self::Help => ffi::GTK_RESPONSE_HELP,
76 Self::Other(value) => value as ffi::GtkResponseType,
77 Self::__Unknown(value) => value,
78 }
79 }
80}
81
82#[doc(hidden)]
83impl FromGlib<ffi::GtkResponseType> for ResponseType {
84 #[inline]
85 unsafe fn from_glib(value: ffi::GtkResponseType) -> Self {
86 skip_assert_initialized!();
87 match value {
88 ffi::GTK_RESPONSE_NONE => Self::None,
89 ffi::GTK_RESPONSE_REJECT => Self::Reject,
90 ffi::GTK_RESPONSE_ACCEPT => Self::Accept,
91 ffi::GTK_RESPONSE_DELETE_EVENT => Self::DeleteEvent,
92 ffi::GTK_RESPONSE_OK => Self::Ok,
93 ffi::GTK_RESPONSE_CANCEL => Self::Cancel,
94 ffi::GTK_RESPONSE_CLOSE => Self::Close,
95 ffi::GTK_RESPONSE_YES => Self::Yes,
96 ffi::GTK_RESPONSE_NO => Self::No,
97 ffi::GTK_RESPONSE_APPLY => Self::Apply,
98 ffi::GTK_RESPONSE_HELP => Self::Help,
99 value if value >= 0 && value <= u16::MAX as i32 => Self::Other(value as u16),
100 value => Self::__Unknown(value),
101 }
102 }
103}
104
105impl fmt::Display for ResponseType {
106 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
107 write!(
108 f,
109 "ResponseType::{}",
110 match *self {
111 Self::None => "None",
112 Self::Reject => "Reject",
113 Self::Accept => "Accept",
114 Self::DeleteEvent => "DeleteEvent",
115 Self::Ok => "Ok",
116 Self::Cancel => "Cancel",
117 Self::Close => "Close",
118 Self::Yes => "Yes",
119 Self::No => "No",
120 Self::Apply => "Apply",
121 Self::Help => "Help",
122 Self::Other(_) => "Other",
123 Self::__Unknown(_) => "Unknown",
124 }
125 )
126 }
127}
128
129impl StaticType for ResponseType {
130 #[inline]
131 #[doc(alias = "gtk_response_type_get_type")]
132 fn static_type() -> Type {
133 unsafe { from_glib(ffi::gtk_response_type_get_type()) }
134 }
135}
136
137impl ValueType for ResponseType {
138 type Type = Self;
139}
140
141unsafe impl FromValue<'_> for ResponseType {
142 type Checker = glib::value::GenericValueTypeChecker<Self>;
143
144 #[inline]
145 unsafe fn from_value(value: &glib::Value) -> Self {
146 skip_assert_initialized!();
147 from_glib(glib::gobject_ffi::g_value_get_enum(value.to_glib_none().0))
148 }
149}
150
151impl ToValue for ResponseType {
152 #[inline]
153 fn to_value(&self) -> Value {
154 let mut value = glib::Value::for_value_type::<Self>();
155 unsafe { glib::gobject_ffi::g_value_set_enum(value.to_glib_none_mut().0, self.into_glib()) }
156 value
157 }
158
159 #[inline]
160 fn value_type(&self) -> Type {
161 Self::static_type()
162 }
163}
164
165impl From<ResponseType> for Value {
166 #[inline]
167 fn from(t: ResponseType) -> Self {
168 skip_assert_initialized!();
169 t.to_value()
170 }
171}
172
173impl PartialEq<i32> for ResponseType {
174 #[inline]
175 fn eq(&self, other: &i32) -> bool {
176 self.into_glib().eq(other)
177 }
178}
179
180impl PartialEq<ResponseType> for i32 {
181 #[inline]
182 fn eq(&self, other: &ResponseType) -> bool {
183 other.into_glib().eq(self)
184 }
185}
186
187impl From<i32> for ResponseType {
188 #[inline]
189 fn from(response: i32) -> Self {
190 skip_assert_initialized!();
191 unsafe { Self::from_glib(response) }
192 }
193}
194
195impl From<ResponseType> for i32 {
196 #[inline]
197 fn from(r: ResponseType) -> Self {
198 skip_assert_initialized!();
199 r.into_glib()
200 }
201}