Serenity Operating System
at master 123 lines 3.8 kB view raw
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 9#pragma once 10 11#include <LibGUI/AbstractScrollableWidget.h> 12#include <LibGUI/TextRange.h> 13#include <LibGfx/Font/BitmapFont.h> 14#include <LibUnicode/CharacterTypes.h> 15 16namespace GUI { 17 18class GlyphMapWidget final : public AbstractScrollableWidget { 19 C_OBJECT(GlyphMapWidget) 20public: 21 virtual ~GlyphMapWidget() override = default; 22 23 ErrorOr<void> set_font(Gfx::Font const&); 24 25 class Selection { 26 public: 27 Selection() = default; 28 Selection(int start, int size) 29 : m_start(start) 30 , m_size(size) 31 { 32 } 33 34 int size() const { return m_size; } 35 void set_size(int i) { m_size = i; } 36 int start() const { return m_start; } 37 void set_start(int i) { m_start = i; } 38 39 Selection normalized() const; 40 bool contains(int) const; 41 void resize_by(int i); 42 void extend_to(int); 43 44 private: 45 int m_start { 0 }; 46 int m_size { 1 }; 47 }; 48 49 Selection selection() const { return m_selection; } 50 int active_glyph() const { return m_active_glyph; } 51 52 enum class ShouldResetSelection { 53 Yes, 54 No 55 }; 56 57 void set_active_range(Unicode::CodePointRange); 58 void set_active_glyph(int, ShouldResetSelection = ShouldResetSelection::Yes); 59 60 void set_selection(int start, int size, Optional<u32> active_glyph = {}); 61 void restore_selection(int start, int size, int active_glyph); 62 63 void scroll_to_glyph(int); 64 void update_glyph(int); 65 66 void set_highlight_modifications(bool); 67 void set_show_system_emoji(bool); 68 69 void set_glyph_modified(u32 glyph, bool modified); 70 bool glyph_is_modified(u32 glyph); 71 72 void select_previous_existing_glyph(); 73 void select_next_existing_glyph(); 74 75 int rows() const { return m_rows; } 76 int columns() const { return m_columns; } 77 78 Function<void()> on_escape_pressed; 79 Function<void(int)> on_active_glyph_changed; 80 Function<void(int)> on_glyph_double_clicked; 81 Function<void(ContextMenuEvent&)> on_context_menu_request; 82 83private: 84 GlyphMapWidget(); 85 virtual void paint_event(PaintEvent&) override; 86 virtual void mousedown_event(MouseEvent&) override; 87 virtual void mouseup_event(GUI::MouseEvent&) override; 88 virtual void mousemove_event(GUI::MouseEvent&) override; 89 virtual void doubleclick_event(MouseEvent&) override; 90 virtual void keydown_event(KeyEvent&) override; 91 virtual void resize_event(ResizeEvent&) override; 92 virtual void did_change_font() override; 93 virtual void context_menu_event(ContextMenuEvent&) override; 94 virtual void enter_event(Core::Event&) override; 95 virtual void leave_event(Core::Event&) override; 96 virtual void automatic_scrolling_timer_did_fire() override; 97 virtual Optional<UISize> calculated_min_size() const override; 98 99 Gfx::IntRect get_outer_rect(int glyph) const; 100 Optional<int> glyph_at_position(Gfx::IntPoint) const; 101 int glyph_at_position_clamped(Gfx::IntPoint) const; 102 103 void recalculate_content_size(); 104 105 RefPtr<Gfx::Font> m_original_font; 106 int m_glyph_count { 0x110000 }; 107 int m_columns { 0 }; 108 int m_rows { 0 }; 109 int m_visible_rows { 0 }; 110 int m_horizontal_spacing { 4 }; 111 int m_vertical_spacing { 4 }; 112 Selection m_selection; 113 int m_active_glyph { 0 }; 114 int m_visible_glyphs { 0 }; 115 bool m_in_drag_select { false }; 116 bool m_highlight_modifications { false }; 117 bool m_show_system_emoji { false }; 118 HashTable<u32> m_modified_glyphs; 119 Unicode::CodePointRange m_active_range { 0x0000, 0x10FFFF }; 120 Gfx::IntPoint m_last_mousemove_position; 121}; 122 123}