1
0

cmCursesStringWidget.h 1.8 KB

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