TextBox.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibGUI/Action.h>
  8. #include <LibGUI/TextEditor.h>
  9. namespace GUI {
  10. class TextBox : public TextEditor {
  11. C_OBJECT(TextBox)
  12. public:
  13. TextBox();
  14. virtual ~TextBox() override;
  15. Function<void()> on_up_pressed;
  16. Function<void()> on_down_pressed;
  17. void set_history_enabled(bool enabled) { m_history_enabled = enabled; }
  18. void add_current_text_to_history();
  19. private:
  20. virtual void keydown_event(GUI::KeyEvent&) override;
  21. bool has_no_history() const { return !m_history_enabled || m_history.is_empty(); }
  22. bool can_go_backwards_in_history() const { return m_history_index > 0; }
  23. bool can_go_forwards_in_history() const { return m_history_index < static_cast<int>(m_history.size()) - 1; }
  24. void add_input_to_history(String);
  25. bool m_history_enabled { false };
  26. Vector<String> m_history;
  27. int m_history_index { -1 };
  28. String m_saved_input;
  29. };
  30. class PasswordBox : public TextBox {
  31. C_OBJECT(PasswordBox)
  32. public:
  33. PasswordBox();
  34. };
  35. class UrlBox : public TextBox {
  36. C_OBJECT(UrlBox)
  37. public:
  38. UrlBox();
  39. virtual ~UrlBox() override;
  40. void set_focus_transition(bool focus_transition) { m_focus_transition = focus_transition; }
  41. bool is_focus_transition() const { return m_focus_transition; }
  42. private:
  43. virtual void mousedown_event(GUI::MouseEvent&) override;
  44. virtual void focusout_event(GUI::FocusEvent&) override;
  45. bool m_focus_transition { true };
  46. };
  47. }