TextBox.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. virtual ~TextBox() override;
  14. Function<void()> on_up_pressed;
  15. Function<void()> on_down_pressed;
  16. void set_history_enabled(bool enabled) { m_history_enabled = enabled; }
  17. void add_current_text_to_history();
  18. protected:
  19. TextBox();
  20. private:
  21. virtual void keydown_event(GUI::KeyEvent&) override;
  22. bool has_no_history() const { return !m_history_enabled || m_history.is_empty(); }
  23. bool can_go_backwards_in_history() const { return m_history_index > 0; }
  24. bool can_go_forwards_in_history() const { return m_history_index < static_cast<int>(m_history.size()) - 1; }
  25. void add_input_to_history(String);
  26. bool m_history_enabled { false };
  27. Vector<String> m_history;
  28. int m_history_index { -1 };
  29. String m_saved_input;
  30. };
  31. class PasswordBox : public TextBox {
  32. C_OBJECT(PasswordBox)
  33. private:
  34. PasswordBox();
  35. };
  36. class UrlBox : public TextBox {
  37. C_OBJECT(UrlBox)
  38. public:
  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. UrlBox();
  44. virtual void mousedown_event(GUI::MouseEvent&) override;
  45. virtual void focusout_event(GUI::FocusEvent&) override;
  46. bool m_focus_transition { true };
  47. };
  48. }