cmCursesStringWidget.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #ifndef cmCursesStringWidget_h
  4. #define cmCursesStringWidget_h
  5. #include "cmConfigure.h" // IWYU pragma: keep
  6. #include "cmCursesStandardIncludes.h"
  7. #include "cmCursesWidget.h"
  8. #include <string>
  9. class cmCursesMainForm;
  10. /** \class cmCursesStringWidget
  11. * \brief A simple entry widget.
  12. *
  13. * cmCursesStringWdiget is a simple text entry widget.
  14. */
  15. class cmCursesStringWidget : public cmCursesWidget
  16. {
  17. public:
  18. cmCursesStringWidget(int width, int height, int left, int top);
  19. cmCursesStringWidget(cmCursesStringWidget const&) = delete;
  20. cmCursesStringWidget& operator=(cmCursesStringWidget const&) = delete;
  21. /**
  22. * Handle user input. Called by the container of this widget
  23. * when this widget has focus. Returns true if the input was
  24. * handled.
  25. */
  26. bool HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w) override;
  27. /**
  28. * Set/Get the string.
  29. */
  30. void SetString(const std::string& value);
  31. const char* GetString();
  32. const char* GetValue() override;
  33. /**
  34. * Set/Get InEdit flag. Can be used to tell the widget to leave
  35. * edit mode (in case of a resize for example).
  36. */
  37. void SetInEdit(bool inedit) { this->InEdit = inedit; }
  38. bool GetInEdit() { return this->InEdit; }
  39. /**
  40. * This method is called when different keys are pressed. The
  41. * subclass can have a special implementation handler for this.
  42. */
  43. virtual void OnTab(cmCursesMainForm* fm, WINDOW* w);
  44. virtual void OnReturn(cmCursesMainForm* fm, WINDOW* w);
  45. virtual void OnType(int& key, cmCursesMainForm* fm, WINDOW* w);
  46. /**
  47. * If there are any, print the widget specific commands
  48. * in the toolbar and return true. Otherwise, return false
  49. * and the parent widget will print.
  50. */
  51. bool PrintKeys() override;
  52. protected:
  53. // true if the widget is in edit mode
  54. bool InEdit;
  55. char* OriginalString;
  56. bool Done;
  57. };
  58. #endif // cmCursesStringWidget_h