cmCursesStringWidget.h 1.9 KB

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