GlyphMapWidget.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
  4. * Copyright (c) 2022, the SerenityOS developers.
  5. *
  6. * SPDX-License-Identifier: BSD-2-Clause
  7. */
  8. #pragma once
  9. #include <LibGUI/AbstractScrollableWidget.h>
  10. #include <LibGUI/TextRange.h>
  11. #include <LibGfx/Font/BitmapFont.h>
  12. #include <LibUnicode/CharacterTypes.h>
  13. namespace GUI {
  14. class GlyphMapWidget final : public AbstractScrollableWidget {
  15. C_OBJECT(GlyphMapWidget)
  16. public:
  17. virtual ~GlyphMapWidget() override = default;
  18. ErrorOr<void> set_font(Gfx::Font const&);
  19. class Selection {
  20. public:
  21. Selection() = default;
  22. Selection(int start, int size)
  23. : m_start(start)
  24. , m_size(size)
  25. {
  26. }
  27. int size() const { return m_size; }
  28. void set_size(int i) { m_size = i; }
  29. int start() const { return m_start; }
  30. void set_start(int i) { m_start = i; }
  31. Selection normalized() const;
  32. bool contains(int) const;
  33. void resize_by(int i);
  34. void extend_to(int);
  35. private:
  36. int m_start { 0 };
  37. int m_size { 1 };
  38. };
  39. Selection selection() const { return m_selection; }
  40. int active_glyph() const { return m_active_glyph; }
  41. enum class ShouldResetSelection {
  42. Yes,
  43. No
  44. };
  45. void set_active_range(Unicode::CodePointRange);
  46. void set_active_glyph(int, ShouldResetSelection = ShouldResetSelection::Yes);
  47. void set_selection(int start, int size, Optional<u32> active_glyph = {});
  48. void restore_selection(int start, int size, int active_glyph);
  49. void scroll_to_glyph(int);
  50. void update_glyph(int);
  51. void set_highlight_modifications(bool);
  52. void set_show_system_emoji(bool);
  53. void set_glyph_modified(u32 glyph, bool modified);
  54. bool glyph_is_modified(u32 glyph);
  55. void select_previous_existing_glyph();
  56. void select_next_existing_glyph();
  57. int rows() const { return m_rows; }
  58. int columns() const { return m_columns; }
  59. Function<void()> on_escape_pressed;
  60. Function<void(int)> on_active_glyph_changed;
  61. Function<void(int)> on_glyph_double_clicked;
  62. Function<void(ContextMenuEvent&)> on_context_menu_request;
  63. private:
  64. GlyphMapWidget();
  65. virtual void paint_event(PaintEvent&) override;
  66. virtual void mousedown_event(MouseEvent&) override;
  67. virtual void mouseup_event(GUI::MouseEvent&) override;
  68. virtual void mousemove_event(GUI::MouseEvent&) override;
  69. virtual void doubleclick_event(MouseEvent&) override;
  70. virtual void keydown_event(KeyEvent&) override;
  71. virtual void resize_event(ResizeEvent&) override;
  72. virtual void did_change_font() override;
  73. virtual void context_menu_event(ContextMenuEvent&) override;
  74. virtual void enter_event(Core::Event&) override;
  75. virtual void leave_event(Core::Event&) override;
  76. virtual void automatic_scrolling_timer_did_fire() override;
  77. virtual Optional<UISize> calculated_min_size() const override;
  78. Gfx::IntRect get_outer_rect(int glyph) const;
  79. Optional<int> glyph_at_position(Gfx::IntPoint) const;
  80. int glyph_at_position_clamped(Gfx::IntPoint) const;
  81. void recalculate_content_size();
  82. RefPtr<Gfx::Font> m_original_font;
  83. int m_glyph_count { 0x110000 };
  84. int m_columns { 0 };
  85. int m_rows { 0 };
  86. int m_visible_rows { 0 };
  87. int m_horizontal_spacing { 4 };
  88. int m_vertical_spacing { 4 };
  89. Selection m_selection;
  90. int m_active_glyph { 0 };
  91. int m_visible_glyphs { 0 };
  92. bool m_in_drag_select { false };
  93. bool m_highlight_modifications { false };
  94. bool m_show_system_emoji { false };
  95. HashTable<u32> m_modified_glyphs;
  96. Unicode::CodePointRange m_active_range { 0x0000, 0x10FFFF };
  97. Gfx::IntPoint m_last_mousemove_position;
  98. };
  99. }