1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 06:45:07 +00:00
serenity/Libraries/LibVT/TerminalWidget.h
Andreas Kling 94ca55cefd Meta: Add license header to source files
As suggested by Joshua, this commit adds the 2-clause BSD license as a
comment block to the top of every source file.

For the first pass, I've just added myself for simplicity. I encourage
everyone to add themselves as copyright holders of any file they've
added or modified in some significant way. If I've added myself in
error somewhere, feel free to replace it with the appropriate copyright
holder instead.

Going forward, all new source files should include a license header.
2020-01-18 09:45:54 +01:00

167 lines
5.2 KiB
C++

/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <AK/String.h>
#include <LibCore/CConfigFile.h>
#include <LibCore/CNotifier.h>
#include <LibCore/CTimer.h>
#include <LibDraw/GraphicsBitmap.h>
#include <LibDraw/Rect.h>
#include <LibGUI/GFrame.h>
#include <LibVT/Terminal.h>
class GScrollBar;
class TerminalWidget final : public GFrame
, public VT::TerminalClient {
C_OBJECT(TerminalWidget)
public:
TerminalWidget(int ptm_fd, bool automatic_size_policy, RefPtr<CConfigFile> config);
virtual ~TerminalWidget() override;
void set_pty_master_fd(int fd);
void inject_string(const StringView& string)
{
m_terminal.inject_string(string);
flush_dirty_lines();
}
void create_window();
void flush_dirty_lines();
void force_repaint();
void apply_size_increments_to_window(GWindow&);
const Font& bold_font() const { return *m_bold_font; }
void set_opacity(u8);
float opacity() { return m_opacity; };
bool should_beep() { return m_should_beep; }
void set_should_beep(bool sb) { m_should_beep = sb; };
RefPtr<CConfigFile> config() const { return m_config; }
bool has_selection() const;
bool selection_contains(const VT::Position&) const;
String selected_text() const;
VT::Position buffer_position_at(const Point&) const;
VT::Position normalized_selection_start() const;
VT::Position normalized_selection_end() const;
bool is_scrollable() const;
GAction& copy_action() { return *m_copy_action; }
GAction& paste_action() { return *m_paste_action; }
void copy();
void paste();
virtual bool accepts_focus() const override { return true; }
Function<void(const StringView&)> on_title_change;
Function<void()> on_command_exit;
private:
// ^GWidget
virtual void event(CEvent&) override;
virtual void paint_event(GPaintEvent&) override;
virtual void resize_event(GResizeEvent&) override;
virtual void keydown_event(GKeyEvent&) override;
virtual void mousedown_event(GMouseEvent&) override;
virtual void mousemove_event(GMouseEvent&) override;
virtual void mousewheel_event(GMouseEvent&) override;
virtual void doubleclick_event(GMouseEvent&) override;
virtual void focusin_event(CEvent&) override;
virtual void focusout_event(CEvent&) override;
virtual void context_menu_event(GContextMenuEvent&) override;
virtual void did_change_font() override;
// ^TerminalClient
virtual void beep() override;
virtual void set_window_title(const StringView&) override;
virtual void terminal_did_resize(u16 columns, u16 rows) override;
virtual void terminal_history_changed() override;
void set_logical_focus(bool);
Rect glyph_rect(u16 row, u16 column);
Rect row_rect(u16 row);
void update_cursor();
void invalidate_cursor();
void relayout(const Size&);
Size compute_base_size() const;
int first_selection_column_on_row(int row) const;
int last_selection_column_on_row(int row) const;
VT::Terminal m_terminal;
VT::Position m_selection_start;
VT::Position m_selection_end;
bool m_should_beep { false };
bool m_belling { false };
int m_pixel_width { 0 };
int m_pixel_height { 0 };
int m_inset { 2 };
int m_line_spacing { 4 };
int m_line_height { 0 };
int m_ptm_fd { -1 };
bool m_has_logical_focus { false };
RefPtr<CNotifier> m_notifier;
u8 m_opacity { 255 };
bool m_needs_background_fill { true };
bool m_cursor_blink_state { true };
bool m_automatic_size_policy { false };
RefPtr<Font> m_bold_font;
int m_glyph_width { 0 };
RefPtr<CTimer> m_cursor_blink_timer;
RefPtr<CTimer> m_visual_beep_timer;
RefPtr<CConfigFile> m_config;
RefPtr<GScrollBar> m_scrollbar;
RefPtr<GAction> m_copy_action;
RefPtr<GAction> m_paste_action;
RefPtr<GMenu> m_context_menu;
CElapsedTimer m_triple_click_timer;
};