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