1use crate::{
6 ffi, Accessible, AccessibleRole, Align, Buildable, ConstraintTarget, Editable, LayoutManager,
7 Overflow, Widget,
8};
9#[cfg(feature = "v4_14")]
10#[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
11use crate::{InputHints, InputPurpose};
12use glib::{
13 object::ObjectType as _,
14 prelude::*,
15 signal::{connect_raw, SignalHandlerId},
16 translate::*,
17};
18use std::boxed::Box as Box_;
19
20glib::wrapper! {
21 #[doc(alias = "GtkSearchEntry")]
22 pub struct SearchEntry(Object<ffi::GtkSearchEntry>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget, Editable;
23
24 match fn {
25 type_ => || ffi::gtk_search_entry_get_type(),
26 }
27}
28
29impl SearchEntry {
30 #[doc(alias = "gtk_search_entry_new")]
31 pub fn new() -> SearchEntry {
32 assert_initialized_main_thread!();
33 unsafe { Widget::from_glib_none(ffi::gtk_search_entry_new()).unsafe_cast() }
34 }
35
36 pub fn builder() -> SearchEntryBuilder {
41 SearchEntryBuilder::new()
42 }
43
44 #[cfg(feature = "v4_14")]
45 #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
46 #[doc(alias = "gtk_search_entry_get_input_hints")]
47 #[doc(alias = "get_input_hints")]
48 #[doc(alias = "input-hints")]
49 pub fn input_hints(&self) -> InputHints {
50 unsafe { from_glib(ffi::gtk_search_entry_get_input_hints(self.to_glib_none().0)) }
51 }
52
53 #[cfg(feature = "v4_14")]
54 #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
55 #[doc(alias = "gtk_search_entry_get_input_purpose")]
56 #[doc(alias = "get_input_purpose")]
57 #[doc(alias = "input-purpose")]
58 pub fn input_purpose(&self) -> InputPurpose {
59 unsafe {
60 from_glib(ffi::gtk_search_entry_get_input_purpose(
61 self.to_glib_none().0,
62 ))
63 }
64 }
65
66 #[doc(alias = "gtk_search_entry_get_key_capture_widget")]
67 #[doc(alias = "get_key_capture_widget")]
68 pub fn key_capture_widget(&self) -> Option<Widget> {
69 unsafe {
70 from_glib_none(ffi::gtk_search_entry_get_key_capture_widget(
71 self.to_glib_none().0,
72 ))
73 }
74 }
75
76 #[cfg(feature = "v4_8")]
77 #[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
78 #[doc(alias = "gtk_search_entry_get_search_delay")]
79 #[doc(alias = "get_search_delay")]
80 #[doc(alias = "search-delay")]
81 pub fn search_delay(&self) -> u32 {
82 unsafe { ffi::gtk_search_entry_get_search_delay(self.to_glib_none().0) }
83 }
84
85 #[cfg(feature = "v4_14")]
86 #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
87 #[doc(alias = "gtk_search_entry_set_input_hints")]
88 #[doc(alias = "input-hints")]
89 pub fn set_input_hints(&self, hints: InputHints) {
90 unsafe {
91 ffi::gtk_search_entry_set_input_hints(self.to_glib_none().0, hints.into_glib());
92 }
93 }
94
95 #[cfg(feature = "v4_14")]
96 #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
97 #[doc(alias = "gtk_search_entry_set_input_purpose")]
98 #[doc(alias = "input-purpose")]
99 pub fn set_input_purpose(&self, purpose: InputPurpose) {
100 unsafe {
101 ffi::gtk_search_entry_set_input_purpose(self.to_glib_none().0, purpose.into_glib());
102 }
103 }
104
105 #[doc(alias = "gtk_search_entry_set_key_capture_widget")]
106 pub fn set_key_capture_widget(&self, widget: Option<&impl IsA<Widget>>) {
107 unsafe {
108 ffi::gtk_search_entry_set_key_capture_widget(
109 self.to_glib_none().0,
110 widget.map(|p| p.as_ref()).to_glib_none().0,
111 );
112 }
113 }
114
115 #[cfg(feature = "v4_8")]
116 #[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
117 #[doc(alias = "gtk_search_entry_set_search_delay")]
118 #[doc(alias = "search-delay")]
119 pub fn set_search_delay(&self, delay: u32) {
120 unsafe {
121 ffi::gtk_search_entry_set_search_delay(self.to_glib_none().0, delay);
122 }
123 }
124
125 #[doc(alias = "activates-default")]
126 pub fn activates_default(&self) -> bool {
127 ObjectExt::property(self, "activates-default")
128 }
129
130 #[doc(alias = "activates-default")]
131 pub fn set_activates_default(&self, activates_default: bool) {
132 ObjectExt::set_property(self, "activates-default", activates_default)
133 }
134
135 #[doc(alias = "placeholder-text")]
136 pub fn placeholder_text(&self) -> Option<glib::GString> {
137 ObjectExt::property(self, "placeholder-text")
138 }
139
140 #[doc(alias = "placeholder-text")]
141 pub fn set_placeholder_text(&self, placeholder_text: Option<&str>) {
142 ObjectExt::set_property(self, "placeholder-text", placeholder_text)
143 }
144
145 #[doc(alias = "activate")]
146 pub fn connect_activate<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
147 unsafe extern "C" fn activate_trampoline<F: Fn(&SearchEntry) + 'static>(
148 this: *mut ffi::GtkSearchEntry,
149 f: glib::ffi::gpointer,
150 ) {
151 let f: &F = &*(f as *const F);
152 f(&from_glib_borrow(this))
153 }
154 unsafe {
155 let f: Box_<F> = Box_::new(f);
156 connect_raw(
157 self.as_ptr() as *mut _,
158 c"activate".as_ptr() as *const _,
159 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
160 activate_trampoline::<F> as *const (),
161 )),
162 Box_::into_raw(f),
163 )
164 }
165 }
166
167 pub fn emit_activate(&self) {
168 self.emit_by_name::<()>("activate", &[]);
169 }
170
171 #[doc(alias = "next-match")]
172 pub fn connect_next_match<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
173 unsafe extern "C" fn next_match_trampoline<F: Fn(&SearchEntry) + 'static>(
174 this: *mut ffi::GtkSearchEntry,
175 f: glib::ffi::gpointer,
176 ) {
177 let f: &F = &*(f as *const F);
178 f(&from_glib_borrow(this))
179 }
180 unsafe {
181 let f: Box_<F> = Box_::new(f);
182 connect_raw(
183 self.as_ptr() as *mut _,
184 c"next-match".as_ptr() as *const _,
185 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
186 next_match_trampoline::<F> as *const (),
187 )),
188 Box_::into_raw(f),
189 )
190 }
191 }
192
193 pub fn emit_next_match(&self) {
194 self.emit_by_name::<()>("next-match", &[]);
195 }
196
197 #[doc(alias = "previous-match")]
198 pub fn connect_previous_match<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
199 unsafe extern "C" fn previous_match_trampoline<F: Fn(&SearchEntry) + 'static>(
200 this: *mut ffi::GtkSearchEntry,
201 f: glib::ffi::gpointer,
202 ) {
203 let f: &F = &*(f as *const F);
204 f(&from_glib_borrow(this))
205 }
206 unsafe {
207 let f: Box_<F> = Box_::new(f);
208 connect_raw(
209 self.as_ptr() as *mut _,
210 c"previous-match".as_ptr() as *const _,
211 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
212 previous_match_trampoline::<F> as *const (),
213 )),
214 Box_::into_raw(f),
215 )
216 }
217 }
218
219 pub fn emit_previous_match(&self) {
220 self.emit_by_name::<()>("previous-match", &[]);
221 }
222
223 #[doc(alias = "search-changed")]
224 pub fn connect_search_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
225 unsafe extern "C" fn search_changed_trampoline<F: Fn(&SearchEntry) + 'static>(
226 this: *mut ffi::GtkSearchEntry,
227 f: glib::ffi::gpointer,
228 ) {
229 let f: &F = &*(f as *const F);
230 f(&from_glib_borrow(this))
231 }
232 unsafe {
233 let f: Box_<F> = Box_::new(f);
234 connect_raw(
235 self.as_ptr() as *mut _,
236 c"search-changed".as_ptr() as *const _,
237 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
238 search_changed_trampoline::<F> as *const (),
239 )),
240 Box_::into_raw(f),
241 )
242 }
243 }
244
245 #[doc(alias = "search-started")]
246 pub fn connect_search_started<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
247 unsafe extern "C" fn search_started_trampoline<F: Fn(&SearchEntry) + 'static>(
248 this: *mut ffi::GtkSearchEntry,
249 f: glib::ffi::gpointer,
250 ) {
251 let f: &F = &*(f as *const F);
252 f(&from_glib_borrow(this))
253 }
254 unsafe {
255 let f: Box_<F> = Box_::new(f);
256 connect_raw(
257 self.as_ptr() as *mut _,
258 c"search-started".as_ptr() as *const _,
259 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
260 search_started_trampoline::<F> as *const (),
261 )),
262 Box_::into_raw(f),
263 )
264 }
265 }
266
267 #[doc(alias = "stop-search")]
268 pub fn connect_stop_search<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
269 unsafe extern "C" fn stop_search_trampoline<F: Fn(&SearchEntry) + 'static>(
270 this: *mut ffi::GtkSearchEntry,
271 f: glib::ffi::gpointer,
272 ) {
273 let f: &F = &*(f as *const F);
274 f(&from_glib_borrow(this))
275 }
276 unsafe {
277 let f: Box_<F> = Box_::new(f);
278 connect_raw(
279 self.as_ptr() as *mut _,
280 c"stop-search".as_ptr() as *const _,
281 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
282 stop_search_trampoline::<F> as *const (),
283 )),
284 Box_::into_raw(f),
285 )
286 }
287 }
288
289 pub fn emit_stop_search(&self) {
290 self.emit_by_name::<()>("stop-search", &[]);
291 }
292
293 #[doc(alias = "activates-default")]
294 pub fn connect_activates_default_notify<F: Fn(&Self) + 'static>(
295 &self,
296 f: F,
297 ) -> SignalHandlerId {
298 unsafe extern "C" fn notify_activates_default_trampoline<F: Fn(&SearchEntry) + 'static>(
299 this: *mut ffi::GtkSearchEntry,
300 _param_spec: glib::ffi::gpointer,
301 f: glib::ffi::gpointer,
302 ) {
303 let f: &F = &*(f as *const F);
304 f(&from_glib_borrow(this))
305 }
306 unsafe {
307 let f: Box_<F> = Box_::new(f);
308 connect_raw(
309 self.as_ptr() as *mut _,
310 c"notify::activates-default".as_ptr() as *const _,
311 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
312 notify_activates_default_trampoline::<F> as *const (),
313 )),
314 Box_::into_raw(f),
315 )
316 }
317 }
318
319 #[cfg(feature = "v4_14")]
320 #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
321 #[doc(alias = "input-hints")]
322 pub fn connect_input_hints_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
323 unsafe extern "C" fn notify_input_hints_trampoline<F: Fn(&SearchEntry) + 'static>(
324 this: *mut ffi::GtkSearchEntry,
325 _param_spec: glib::ffi::gpointer,
326 f: glib::ffi::gpointer,
327 ) {
328 let f: &F = &*(f as *const F);
329 f(&from_glib_borrow(this))
330 }
331 unsafe {
332 let f: Box_<F> = Box_::new(f);
333 connect_raw(
334 self.as_ptr() as *mut _,
335 c"notify::input-hints".as_ptr() as *const _,
336 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
337 notify_input_hints_trampoline::<F> as *const (),
338 )),
339 Box_::into_raw(f),
340 )
341 }
342 }
343
344 #[cfg(feature = "v4_14")]
345 #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
346 #[doc(alias = "input-purpose")]
347 pub fn connect_input_purpose_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
348 unsafe extern "C" fn notify_input_purpose_trampoline<F: Fn(&SearchEntry) + 'static>(
349 this: *mut ffi::GtkSearchEntry,
350 _param_spec: glib::ffi::gpointer,
351 f: glib::ffi::gpointer,
352 ) {
353 let f: &F = &*(f as *const F);
354 f(&from_glib_borrow(this))
355 }
356 unsafe {
357 let f: Box_<F> = Box_::new(f);
358 connect_raw(
359 self.as_ptr() as *mut _,
360 c"notify::input-purpose".as_ptr() as *const _,
361 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
362 notify_input_purpose_trampoline::<F> as *const (),
363 )),
364 Box_::into_raw(f),
365 )
366 }
367 }
368
369 #[doc(alias = "placeholder-text")]
370 pub fn connect_placeholder_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
371 unsafe extern "C" fn notify_placeholder_text_trampoline<F: Fn(&SearchEntry) + 'static>(
372 this: *mut ffi::GtkSearchEntry,
373 _param_spec: glib::ffi::gpointer,
374 f: glib::ffi::gpointer,
375 ) {
376 let f: &F = &*(f as *const F);
377 f(&from_glib_borrow(this))
378 }
379 unsafe {
380 let f: Box_<F> = Box_::new(f);
381 connect_raw(
382 self.as_ptr() as *mut _,
383 c"notify::placeholder-text".as_ptr() as *const _,
384 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
385 notify_placeholder_text_trampoline::<F> as *const (),
386 )),
387 Box_::into_raw(f),
388 )
389 }
390 }
391
392 #[cfg(feature = "v4_8")]
393 #[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
394 #[doc(alias = "search-delay")]
395 pub fn connect_search_delay_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
396 unsafe extern "C" fn notify_search_delay_trampoline<F: Fn(&SearchEntry) + 'static>(
397 this: *mut ffi::GtkSearchEntry,
398 _param_spec: glib::ffi::gpointer,
399 f: glib::ffi::gpointer,
400 ) {
401 let f: &F = &*(f as *const F);
402 f(&from_glib_borrow(this))
403 }
404 unsafe {
405 let f: Box_<F> = Box_::new(f);
406 connect_raw(
407 self.as_ptr() as *mut _,
408 c"notify::search-delay".as_ptr() as *const _,
409 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
410 notify_search_delay_trampoline::<F> as *const (),
411 )),
412 Box_::into_raw(f),
413 )
414 }
415 }
416}
417
418impl Default for SearchEntry {
419 fn default() -> Self {
420 Self::new()
421 }
422}
423
424#[must_use = "The builder must be built to be used"]
429pub struct SearchEntryBuilder {
430 builder: glib::object::ObjectBuilder<'static, SearchEntry>,
431}
432
433impl SearchEntryBuilder {
434 fn new() -> Self {
435 Self {
436 builder: glib::object::Object::builder(),
437 }
438 }
439
440 pub fn activates_default(self, activates_default: bool) -> Self {
441 Self {
442 builder: self
443 .builder
444 .property("activates-default", activates_default),
445 }
446 }
447
448 #[cfg(feature = "v4_14")]
449 #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
450 pub fn input_hints(self, input_hints: InputHints) -> Self {
451 Self {
452 builder: self.builder.property("input-hints", input_hints),
453 }
454 }
455
456 #[cfg(feature = "v4_14")]
457 #[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
458 pub fn input_purpose(self, input_purpose: InputPurpose) -> Self {
459 Self {
460 builder: self.builder.property("input-purpose", input_purpose),
461 }
462 }
463
464 pub fn placeholder_text(self, placeholder_text: impl Into<glib::GString>) -> Self {
465 Self {
466 builder: self
467 .builder
468 .property("placeholder-text", placeholder_text.into()),
469 }
470 }
471
472 #[cfg(feature = "v4_8")]
473 #[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
474 pub fn search_delay(self, search_delay: u32) -> Self {
475 Self {
476 builder: self.builder.property("search-delay", search_delay),
477 }
478 }
479
480 pub fn can_focus(self, can_focus: bool) -> Self {
481 Self {
482 builder: self.builder.property("can-focus", can_focus),
483 }
484 }
485
486 pub fn can_target(self, can_target: bool) -> Self {
487 Self {
488 builder: self.builder.property("can-target", can_target),
489 }
490 }
491
492 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
493 Self {
494 builder: self.builder.property("css-classes", css_classes.into()),
495 }
496 }
497
498 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
499 Self {
500 builder: self.builder.property("css-name", css_name.into()),
501 }
502 }
503
504 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
505 Self {
506 builder: self.builder.property("cursor", cursor.clone()),
507 }
508 }
509
510 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
511 Self {
512 builder: self.builder.property("focus-on-click", focus_on_click),
513 }
514 }
515
516 pub fn focusable(self, focusable: bool) -> Self {
517 Self {
518 builder: self.builder.property("focusable", focusable),
519 }
520 }
521
522 pub fn halign(self, halign: Align) -> Self {
523 Self {
524 builder: self.builder.property("halign", halign),
525 }
526 }
527
528 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
529 Self {
530 builder: self.builder.property("has-tooltip", has_tooltip),
531 }
532 }
533
534 pub fn height_request(self, height_request: i32) -> Self {
535 Self {
536 builder: self.builder.property("height-request", height_request),
537 }
538 }
539
540 pub fn hexpand(self, hexpand: bool) -> Self {
541 Self {
542 builder: self.builder.property("hexpand", hexpand),
543 }
544 }
545
546 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
547 Self {
548 builder: self.builder.property("hexpand-set", hexpand_set),
549 }
550 }
551
552 pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
553 Self {
554 builder: self
555 .builder
556 .property("layout-manager", layout_manager.clone().upcast()),
557 }
558 }
559
560 #[cfg(feature = "v4_18")]
561 #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
562 pub fn limit_events(self, limit_events: bool) -> Self {
563 Self {
564 builder: self.builder.property("limit-events", limit_events),
565 }
566 }
567
568 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
569 Self {
570 builder: self.builder.property("margin-bottom", margin_bottom),
571 }
572 }
573
574 pub fn margin_end(self, margin_end: i32) -> Self {
575 Self {
576 builder: self.builder.property("margin-end", margin_end),
577 }
578 }
579
580 pub fn margin_start(self, margin_start: i32) -> Self {
581 Self {
582 builder: self.builder.property("margin-start", margin_start),
583 }
584 }
585
586 pub fn margin_top(self, margin_top: i32) -> Self {
587 Self {
588 builder: self.builder.property("margin-top", margin_top),
589 }
590 }
591
592 pub fn name(self, name: impl Into<glib::GString>) -> Self {
593 Self {
594 builder: self.builder.property("name", name.into()),
595 }
596 }
597
598 pub fn opacity(self, opacity: f64) -> Self {
599 Self {
600 builder: self.builder.property("opacity", opacity),
601 }
602 }
603
604 pub fn overflow(self, overflow: Overflow) -> Self {
605 Self {
606 builder: self.builder.property("overflow", overflow),
607 }
608 }
609
610 pub fn receives_default(self, receives_default: bool) -> Self {
611 Self {
612 builder: self.builder.property("receives-default", receives_default),
613 }
614 }
615
616 pub fn sensitive(self, sensitive: bool) -> Self {
617 Self {
618 builder: self.builder.property("sensitive", sensitive),
619 }
620 }
621
622 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
623 Self {
624 builder: self
625 .builder
626 .property("tooltip-markup", tooltip_markup.into()),
627 }
628 }
629
630 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
631 Self {
632 builder: self.builder.property("tooltip-text", tooltip_text.into()),
633 }
634 }
635
636 pub fn valign(self, valign: Align) -> Self {
637 Self {
638 builder: self.builder.property("valign", valign),
639 }
640 }
641
642 pub fn vexpand(self, vexpand: bool) -> Self {
643 Self {
644 builder: self.builder.property("vexpand", vexpand),
645 }
646 }
647
648 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
649 Self {
650 builder: self.builder.property("vexpand-set", vexpand_set),
651 }
652 }
653
654 pub fn visible(self, visible: bool) -> Self {
655 Self {
656 builder: self.builder.property("visible", visible),
657 }
658 }
659
660 pub fn width_request(self, width_request: i32) -> Self {
661 Self {
662 builder: self.builder.property("width-request", width_request),
663 }
664 }
665
666 pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
667 Self {
668 builder: self.builder.property("accessible-role", accessible_role),
669 }
670 }
671
672 pub fn editable(self, editable: bool) -> Self {
673 Self {
674 builder: self.builder.property("editable", editable),
675 }
676 }
677
678 pub fn enable_undo(self, enable_undo: bool) -> Self {
679 Self {
680 builder: self.builder.property("enable-undo", enable_undo),
681 }
682 }
683
684 pub fn max_width_chars(self, max_width_chars: i32) -> Self {
685 Self {
686 builder: self.builder.property("max-width-chars", max_width_chars),
687 }
688 }
689
690 pub fn text(self, text: impl Into<glib::GString>) -> Self {
691 Self {
692 builder: self.builder.property("text", text.into()),
693 }
694 }
695
696 pub fn width_chars(self, width_chars: i32) -> Self {
697 Self {
698 builder: self.builder.property("width-chars", width_chars),
699 }
700 }
701
702 pub fn xalign(self, xalign: f32) -> Self {
703 Self {
704 builder: self.builder.property("xalign", xalign),
705 }
706 }
707
708 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
711 pub fn build(self) -> SearchEntry {
712 assert_initialized_main_thread!();
713 self.builder.build()
714 }
715}