cmCursesStringWidget.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 <string>
  7. #include "cmCursesStandardIncludes.h"
  8. #include "cmCursesWidget.h"
  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. /**
  20. * Handle user input. Called by the container of this widget
  21. * when this widget has focus. Returns true if the input was
  22. * handled.
  23. */
  24. bool HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w) override;
  25. /**
  26. * Set/Get the string.
  27. */
  28. void SetString(const std::string& value);
  29. const char* GetString();
  30. const char* GetValue() override;
  31. /**
  32. * Set/Get InEdit flag. Can be used to tell the widget to leave
  33. * edit mode (in case of a resize for example).
  34. */
  35. void SetInEdit(bool inedit) { this->InEdit = inedit; }
  36. bool GetInEdit() { return this->InEdit; }
  37. /**
  38. * This method is called when different keys are pressed. The
  39. * subclass can have a special implementation handler for this.
  40. */
  41. virtual void OnTab(cmCursesMainForm* fm, WINDOW* w);
  42. virtual void OnReturn(cmCursesMainForm* fm, WINDOW* w);
  43. virtual void OnType(int& key, cmCursesMainForm* fm, WINDOW* w);
  44. /**
  45. * If there are any, print the widget specific commands
  46. * in the toolbar and return true. Otherwise, return false
  47. * and the parent widget will print.
  48. */
  49. bool PrintKeys() override;
  50. protected:
  51. // true if the widget is in edit mode
  52. bool InEdit;
  53. std::string OriginalString;
  54. bool Done;
  55. };
  56. #endif // cmCursesStringWidget_h