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