Widget.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #include <AK/Assertions.h>
  27. #include <AK/JsonObject.h>
  28. #include <LibGUI/Action.h>
  29. #include <LibGUI/Application.h>
  30. #include <LibGUI/Button.h>
  31. #include <LibGUI/CheckBox.h>
  32. #include <LibGUI/Event.h>
  33. #include <LibGUI/GroupBox.h>
  34. #include <LibGUI/Label.h>
  35. #include <LibGUI/Layout.h>
  36. #include <LibGUI/Menu.h>
  37. #include <LibGUI/Painter.h>
  38. #include <LibGUI/RadioButton.h>
  39. #include <LibGUI/ScrollBar.h>
  40. #include <LibGUI/Slider.h>
  41. #include <LibGUI/SpinBox.h>
  42. #include <LibGUI/TextBox.h>
  43. #include <LibGUI/Widget.h>
  44. #include <LibGUI/Window.h>
  45. #include <LibGUI/WindowServerConnection.h>
  46. #include <LibGfx/Bitmap.h>
  47. #include <LibGfx/Palette.h>
  48. #include <unistd.h>
  49. namespace GUI {
  50. REGISTER_GWIDGET(Button)
  51. REGISTER_GWIDGET(CheckBox)
  52. REGISTER_GWIDGET(GroupBox)
  53. REGISTER_GWIDGET(Label)
  54. REGISTER_GWIDGET(RadioButton)
  55. REGISTER_GWIDGET(ScrollBar)
  56. REGISTER_GWIDGET(Slider)
  57. REGISTER_GWIDGET(SpinBox)
  58. REGISTER_GWIDGET(TextBox)
  59. REGISTER_GWIDGET(Widget)
  60. static HashMap<String, WidgetClassRegistration*>& widget_classes()
  61. {
  62. static HashMap<String, WidgetClassRegistration*>* map;
  63. if (!map)
  64. map = new HashMap<String, WidgetClassRegistration*>;
  65. return *map;
  66. }
  67. WidgetClassRegistration::WidgetClassRegistration(const String& class_name, Function<NonnullRefPtr<Widget>(Widget*)> factory)
  68. : m_class_name(class_name)
  69. , m_factory(move(factory))
  70. {
  71. widget_classes().set(class_name, this);
  72. }
  73. WidgetClassRegistration::~WidgetClassRegistration()
  74. {
  75. }
  76. void WidgetClassRegistration::for_each(Function<void(const WidgetClassRegistration&)> callback)
  77. {
  78. for (auto& it : widget_classes()) {
  79. callback(*it.value);
  80. }
  81. }
  82. const WidgetClassRegistration* WidgetClassRegistration::find(const String& class_name)
  83. {
  84. return widget_classes().get(class_name).value_or(nullptr);
  85. }
  86. Widget::Widget(Widget* parent)
  87. : Core::Object(parent, true)
  88. , m_font(Gfx::Font::default_font())
  89. , m_palette(Application::the().palette().impl())
  90. {
  91. }
  92. Widget::~Widget()
  93. {
  94. }
  95. void Widget::child_event(Core::ChildEvent& event)
  96. {
  97. if (event.type() == Event::ChildAdded) {
  98. if (event.child() && Core::is<Widget>(*event.child()) && layout()) {
  99. if (event.insertion_before_child() && event.insertion_before_child()->is_widget())
  100. layout()->insert_widget_before(Core::to<Widget>(*event.child()), Core::to<Widget>(*event.insertion_before_child()));
  101. else
  102. layout()->add_widget(Core::to<Widget>(*event.child()));
  103. }
  104. }
  105. if (event.type() == Event::ChildRemoved) {
  106. if (layout()) {
  107. if (event.child() && Core::is<Widget>(*event.child()))
  108. layout()->remove_widget(Core::to<Widget>(*event.child()));
  109. else
  110. invalidate_layout();
  111. }
  112. update();
  113. }
  114. return Core::Object::child_event(event);
  115. }
  116. void Widget::set_relative_rect(const Gfx::Rect& a_rect)
  117. {
  118. // Get rid of negative width/height values.
  119. Gfx::Rect rect = {
  120. a_rect.x(),
  121. a_rect.y(),
  122. max(a_rect.width(), 0),
  123. max(a_rect.height(), 0)
  124. };
  125. if (rect == m_relative_rect)
  126. return;
  127. auto old_rect = m_relative_rect;
  128. bool size_changed = m_relative_rect.size() != rect.size();
  129. m_relative_rect = rect;
  130. if (size_changed) {
  131. ResizeEvent resize_event(m_relative_rect.size(), rect.size());
  132. event(resize_event);
  133. }
  134. if (auto* parent = parent_widget())
  135. parent->update(old_rect);
  136. update();
  137. }
  138. void Widget::event(Core::Event& event)
  139. {
  140. switch (event.type()) {
  141. case Event::Paint:
  142. return handle_paint_event(static_cast<PaintEvent&>(event));
  143. case Event::Resize:
  144. return handle_resize_event(static_cast<ResizeEvent&>(event));
  145. case Event::FocusIn:
  146. return focusin_event(event);
  147. case Event::FocusOut:
  148. return focusout_event(event);
  149. case Event::Show:
  150. return show_event(static_cast<ShowEvent&>(event));
  151. case Event::Hide:
  152. return hide_event(static_cast<HideEvent&>(event));
  153. case Event::KeyDown:
  154. return keydown_event(static_cast<KeyEvent&>(event));
  155. case Event::KeyUp:
  156. return keyup_event(static_cast<KeyEvent&>(event));
  157. case Event::MouseMove:
  158. return mousemove_event(static_cast<MouseEvent&>(event));
  159. case Event::MouseDown:
  160. return handle_mousedown_event(static_cast<MouseEvent&>(event));
  161. case Event::MouseDoubleClick:
  162. return handle_mousedoubleclick_event(static_cast<MouseEvent&>(event));
  163. case Event::MouseUp:
  164. return handle_mouseup_event(static_cast<MouseEvent&>(event));
  165. case Event::MouseWheel:
  166. return mousewheel_event(static_cast<MouseEvent&>(event));
  167. case Event::DragMove:
  168. return drag_move_event(static_cast<DragEvent&>(event));
  169. case Event::Drop:
  170. return drop_event(static_cast<DropEvent&>(event));
  171. case Event::Enter:
  172. return handle_enter_event(event);
  173. case Event::Leave:
  174. return handle_leave_event(event);
  175. case Event::EnabledChange:
  176. return change_event(static_cast<Event&>(event));
  177. default:
  178. return Core::Object::event(event);
  179. }
  180. }
  181. void Widget::handle_paint_event(PaintEvent& event)
  182. {
  183. ASSERT(is_visible());
  184. if (fill_with_background_color()) {
  185. Painter painter(*this);
  186. painter.fill_rect(event.rect(), palette().color(background_role()));
  187. } else {
  188. #ifdef DEBUG_WIDGET_UNDERDRAW
  189. // FIXME: This is a bit broken.
  190. // If the widget is not opaque, let's not mess it up with debugging color.
  191. Painter painter(*this);
  192. painter.fill_rect(rect(), Color::Red);
  193. #endif
  194. }
  195. paint_event(event);
  196. for_each_child_widget([&](auto& child) {
  197. if (!child.is_visible())
  198. return IterationDecision::Continue;
  199. if (child.relative_rect().intersects(event.rect())) {
  200. PaintEvent local_event(event.rect().intersected(child.relative_rect()).translated(-child.relative_position()));
  201. child.dispatch_event(local_event, this);
  202. }
  203. return IterationDecision::Continue;
  204. });
  205. second_paint_event(event);
  206. }
  207. void Widget::set_layout(OwnPtr<Layout>&& layout)
  208. {
  209. if (m_layout)
  210. m_layout->notify_disowned({}, *this);
  211. m_layout = move(layout);
  212. if (m_layout) {
  213. m_layout->notify_adopted({}, *this);
  214. do_layout();
  215. } else {
  216. update();
  217. }
  218. }
  219. void Widget::do_layout()
  220. {
  221. for_each_child_widget([&](auto& child) {
  222. child.do_layout();
  223. return IterationDecision::Continue;
  224. });
  225. custom_layout();
  226. if (!m_layout)
  227. return;
  228. m_layout->run(*this);
  229. did_layout();
  230. update();
  231. }
  232. void Widget::notify_layout_changed(Badge<Layout>)
  233. {
  234. invalidate_layout();
  235. }
  236. void Widget::handle_resize_event(ResizeEvent& event)
  237. {
  238. resize_event(event);
  239. do_layout();
  240. }
  241. void Widget::handle_mouseup_event(MouseEvent& event)
  242. {
  243. mouseup_event(event);
  244. }
  245. void Widget::handle_mousedown_event(MouseEvent& event)
  246. {
  247. if (accepts_focus())
  248. set_focus(true);
  249. mousedown_event(event);
  250. if (event.button() == MouseButton::Right) {
  251. ContextMenuEvent c_event(event.position(), screen_relative_rect().location().translated(event.position()));
  252. context_menu_event(c_event);
  253. }
  254. }
  255. void Widget::handle_mousedoubleclick_event(MouseEvent& event)
  256. {
  257. doubleclick_event(event);
  258. }
  259. void Widget::handle_enter_event(Core::Event& event)
  260. {
  261. if (has_tooltip())
  262. Application::the().show_tooltip(m_tooltip, screen_relative_rect().center().translated(0, height() / 2));
  263. enter_event(event);
  264. }
  265. void Widget::handle_leave_event(Core::Event& event)
  266. {
  267. Application::the().hide_tooltip();
  268. leave_event(event);
  269. }
  270. void Widget::click_event(MouseEvent&)
  271. {
  272. }
  273. void Widget::doubleclick_event(MouseEvent&)
  274. {
  275. }
  276. void Widget::resize_event(ResizeEvent&)
  277. {
  278. }
  279. void Widget::paint_event(PaintEvent&)
  280. {
  281. }
  282. void Widget::second_paint_event(PaintEvent&)
  283. {
  284. }
  285. void Widget::show_event(ShowEvent&)
  286. {
  287. }
  288. void Widget::hide_event(HideEvent&)
  289. {
  290. }
  291. void Widget::keydown_event(KeyEvent& event)
  292. {
  293. if (!event.alt() && !event.ctrl() && !event.logo() && event.key() == KeyCode::Key_Tab) {
  294. if (event.shift())
  295. focus_previous_widget();
  296. else
  297. focus_next_widget();
  298. event.accept();
  299. return;
  300. }
  301. event.ignore();
  302. }
  303. void Widget::keyup_event(KeyEvent&)
  304. {
  305. }
  306. void Widget::mousedown_event(MouseEvent&)
  307. {
  308. }
  309. void Widget::mouseup_event(MouseEvent&)
  310. {
  311. }
  312. void Widget::mousemove_event(MouseEvent&)
  313. {
  314. }
  315. void Widget::mousewheel_event(MouseEvent&)
  316. {
  317. }
  318. void Widget::context_menu_event(ContextMenuEvent&)
  319. {
  320. }
  321. void Widget::focusin_event(Core::Event&)
  322. {
  323. }
  324. void Widget::focusout_event(Core::Event&)
  325. {
  326. }
  327. void Widget::enter_event(Core::Event&)
  328. {
  329. }
  330. void Widget::leave_event(Core::Event&)
  331. {
  332. }
  333. void Widget::change_event(Event&)
  334. {
  335. }
  336. void Widget::drag_move_event(DragEvent& event)
  337. {
  338. dbg() << class_name() << "{" << this << "} DRAG MOVE position: " << event.position() << ", data_type: '" << event.data_type() << "'";
  339. event.ignore();
  340. }
  341. void Widget::drop_event(DropEvent& event)
  342. {
  343. dbg() << class_name() << "{" << this << "} DROP position: " << event.position() << ", text: '" << event.text() << "'";
  344. event.ignore();
  345. }
  346. void Widget::update()
  347. {
  348. if (rect().is_empty())
  349. return;
  350. update(rect());
  351. }
  352. void Widget::update(const Gfx::Rect& rect)
  353. {
  354. if (!is_visible())
  355. return;
  356. if (!updates_enabled())
  357. return;
  358. Window* window = m_window;
  359. Widget* parent = parent_widget();
  360. while (parent) {
  361. if (!parent->updates_enabled())
  362. return;
  363. window = parent->m_window;
  364. parent = parent->parent_widget();
  365. }
  366. if (window)
  367. window->update(rect.translated(window_relative_rect().location()));
  368. }
  369. Gfx::Rect Widget::window_relative_rect() const
  370. {
  371. auto rect = relative_rect();
  372. for (auto* parent = parent_widget(); parent; parent = parent->parent_widget()) {
  373. rect.move_by(parent->relative_position());
  374. }
  375. return rect;
  376. }
  377. Gfx::Rect Widget::screen_relative_rect() const
  378. {
  379. return window_relative_rect().translated(window()->position());
  380. }
  381. Widget* Widget::child_at(const Gfx::Point& point) const
  382. {
  383. for (int i = children().size() - 1; i >= 0; --i) {
  384. if (!Core::is<Widget>(children()[i]))
  385. continue;
  386. auto& child = Core::to<Widget>(children()[i]);
  387. if (!child.is_visible())
  388. continue;
  389. if (child.relative_rect().contains(point))
  390. return const_cast<Widget*>(&child);
  391. }
  392. return nullptr;
  393. }
  394. Widget::HitTestResult Widget::hit_test(const Gfx::Point& position, ShouldRespectGreediness should_respect_greediness)
  395. {
  396. if (should_respect_greediness == ShouldRespectGreediness::Yes && is_greedy_for_hits())
  397. return { this, position };
  398. if (auto* child = child_at(position))
  399. return child->hit_test(position - child->relative_position());
  400. return { this, position };
  401. }
  402. void Widget::set_window(Window* window)
  403. {
  404. if (m_window == window)
  405. return;
  406. m_window = window;
  407. }
  408. bool Widget::is_focused() const
  409. {
  410. auto* win = window();
  411. if (!win)
  412. return false;
  413. if (!win->is_active())
  414. return false;
  415. return win->focused_widget() == this;
  416. }
  417. void Widget::set_focus(bool focus)
  418. {
  419. auto* win = window();
  420. if (!win)
  421. return;
  422. if (focus) {
  423. win->set_focused_widget(this);
  424. } else {
  425. if (win->focused_widget() == this)
  426. win->set_focused_widget(nullptr);
  427. }
  428. }
  429. void Widget::set_font(const Gfx::Font* font)
  430. {
  431. if (m_font.ptr() == font)
  432. return;
  433. if (!font)
  434. m_font = Gfx::Font::default_font();
  435. else
  436. m_font = *font;
  437. did_change_font();
  438. update();
  439. }
  440. void Widget::set_global_cursor_tracking(bool enabled)
  441. {
  442. auto* win = window();
  443. if (!win)
  444. return;
  445. win->set_global_cursor_tracking_widget(enabled ? this : nullptr);
  446. }
  447. bool Widget::global_cursor_tracking() const
  448. {
  449. auto* win = window();
  450. if (!win)
  451. return false;
  452. return win->global_cursor_tracking_widget() == this;
  453. }
  454. void Widget::set_preferred_size(const Gfx::Size& size)
  455. {
  456. if (m_preferred_size == size)
  457. return;
  458. m_preferred_size = size;
  459. invalidate_layout();
  460. }
  461. void Widget::set_size_policy(Orientation orientation, SizePolicy policy)
  462. {
  463. if (orientation == Orientation::Horizontal)
  464. set_size_policy(policy, m_vertical_size_policy);
  465. else
  466. set_size_policy(m_horizontal_size_policy, policy);
  467. }
  468. void Widget::set_size_policy(SizePolicy horizontal_policy, SizePolicy vertical_policy)
  469. {
  470. if (m_horizontal_size_policy == horizontal_policy && m_vertical_size_policy == vertical_policy)
  471. return;
  472. m_horizontal_size_policy = horizontal_policy;
  473. m_vertical_size_policy = vertical_policy;
  474. invalidate_layout();
  475. }
  476. void Widget::invalidate_layout()
  477. {
  478. if (window())
  479. window()->schedule_relayout();
  480. }
  481. void Widget::set_visible(bool visible)
  482. {
  483. if (visible == m_visible)
  484. return;
  485. m_visible = visible;
  486. if (auto* parent = parent_widget())
  487. parent->invalidate_layout();
  488. if (m_visible)
  489. update();
  490. if (m_visible) {
  491. ShowEvent e;
  492. event(e);
  493. } else {
  494. HideEvent e;
  495. event(e);
  496. }
  497. }
  498. bool Widget::spans_entire_window_horizontally() const
  499. {
  500. auto* w = window();
  501. if (!w)
  502. return false;
  503. auto* main_widget = w->main_widget();
  504. if (!main_widget)
  505. return false;
  506. if (main_widget == this)
  507. return true;
  508. auto wrr = window_relative_rect();
  509. return wrr.left() == main_widget->rect().left() && wrr.right() == main_widget->rect().right();
  510. }
  511. void Widget::set_enabled(bool enabled)
  512. {
  513. if (m_enabled == enabled)
  514. return;
  515. m_enabled = enabled;
  516. Event e(Event::EnabledChange);
  517. event(e);
  518. update();
  519. }
  520. void Widget::move_to_front()
  521. {
  522. auto* parent = parent_widget();
  523. if (!parent)
  524. return;
  525. if (parent->children().size() == 1)
  526. return;
  527. parent->children().remove_first_matching([this](auto& entry) {
  528. return entry == this;
  529. });
  530. parent->children().append(*this);
  531. parent->update();
  532. }
  533. void Widget::move_to_back()
  534. {
  535. auto* parent = parent_widget();
  536. if (!parent)
  537. return;
  538. if (parent->children().size() == 1)
  539. return;
  540. parent->children().remove_first_matching([this](auto& entry) {
  541. return entry == this;
  542. });
  543. parent->children().prepend(*this);
  544. parent->update();
  545. }
  546. bool Widget::is_frontmost() const
  547. {
  548. auto* parent = parent_widget();
  549. if (!parent)
  550. return true;
  551. return &parent->children().last() == this;
  552. }
  553. bool Widget::is_backmost() const
  554. {
  555. auto* parent = parent_widget();
  556. if (!parent)
  557. return true;
  558. return &parent->children().first() == this;
  559. }
  560. Action* Widget::action_for_key_event(const KeyEvent& event)
  561. {
  562. Shortcut shortcut(event.modifiers(), (KeyCode)event.key());
  563. Action* found_action = nullptr;
  564. for_each_child_of_type<Action>([&](auto& action) {
  565. if (action.shortcut() == shortcut) {
  566. found_action = &action;
  567. return IterationDecision::Break;
  568. }
  569. return IterationDecision::Continue;
  570. });
  571. return found_action;
  572. }
  573. void Widget::set_updates_enabled(bool enabled)
  574. {
  575. if (m_updates_enabled == enabled)
  576. return;
  577. m_updates_enabled = enabled;
  578. if (enabled)
  579. update();
  580. }
  581. void Widget::focus_previous_widget()
  582. {
  583. auto focusable_widgets = window()->focusable_widgets();
  584. for (int i = focusable_widgets.size() - 1; i >= 0; --i) {
  585. if (focusable_widgets[i] != this)
  586. continue;
  587. if (i > 0)
  588. focusable_widgets[i - 1]->set_focus(true);
  589. else
  590. focusable_widgets.last()->set_focus(true);
  591. }
  592. }
  593. void Widget::focus_next_widget()
  594. {
  595. auto focusable_widgets = window()->focusable_widgets();
  596. for (int i = 0; i < focusable_widgets.size(); ++i) {
  597. if (focusable_widgets[i] != this)
  598. continue;
  599. if (i < focusable_widgets.size() - 1)
  600. focusable_widgets[i + 1]->set_focus(true);
  601. else
  602. focusable_widgets.first()->set_focus(true);
  603. }
  604. }
  605. void Widget::set_backcolor(const StringView& color_string)
  606. {
  607. auto color = Color::from_string(color_string);
  608. if (!color.has_value())
  609. return;
  610. set_background_color(color.value());
  611. }
  612. void Widget::set_forecolor(const StringView& color_string)
  613. {
  614. auto color = Color::from_string(color_string);
  615. if (!color.has_value())
  616. return;
  617. set_foreground_color(color.value());
  618. }
  619. void Widget::save_to(AK::JsonObject& json)
  620. {
  621. json.set("relative_rect", relative_rect().to_string());
  622. json.set("fill_with_background_color", fill_with_background_color());
  623. json.set("tooltip", tooltip());
  624. json.set("visible", is_visible());
  625. json.set("focused", is_focused());
  626. json.set("enabled", is_enabled());
  627. json.set("background_color", background_color().to_string());
  628. json.set("foreground_color", foreground_color().to_string());
  629. json.set("preferred_size", preferred_size().to_string());
  630. json.set("size_policy", String::format("[%s,%s]", to_string(horizontal_size_policy()), to_string(vertical_size_policy())));
  631. Core::Object::save_to(json);
  632. }
  633. Vector<Widget*> Widget::child_widgets() const
  634. {
  635. Vector<Widget*> widgets;
  636. widgets.ensure_capacity(children().size());
  637. for (auto& child : const_cast<Widget*>(this)->children()) {
  638. if (child.is_widget())
  639. widgets.append(static_cast<Widget*>(&child));
  640. }
  641. return widgets;
  642. }
  643. void Widget::set_palette(const Palette& palette)
  644. {
  645. m_palette = palette.impl();
  646. }
  647. }