EnterTextView.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright 2021, Jaidyn Levesque <jadedctrl@teknik.io>
  3. * All rights reserved. Distributed under the terms of the MIT license.
  4. */
  5. #include "EnterTextView.h"
  6. #include <Window.h>
  7. EnterTextView::EnterTextView(const char* name)
  8. :
  9. UrlTextView(name),
  10. fTarget(NULL)
  11. {
  12. }
  13. EnterTextView::EnterTextView(const char* name, const BFont* initialFont,
  14. const rgb_color* initialColor, uint32 flags)
  15. :
  16. UrlTextView(name, initialFont, initialColor, flags),
  17. fTarget(NULL)
  18. {
  19. }
  20. void
  21. EnterTextView::KeyDown(const char* bytes, int32 numBytes)
  22. {
  23. int32 modifiers = Window()->CurrentMessage()->GetInt32("modifiers", 0);
  24. if (fTarget != NULL && (bytes[0] == B_ENTER) && (modifiers == 0))
  25. {
  26. BMessage* msg = new BMessage(fMessage);
  27. if (fTextSlot.IsEmpty() == false) {
  28. msg->AddString(fTextSlot.String(), Text());
  29. SetText("");
  30. ScrollToOffset(0);
  31. }
  32. fTarget->MessageReceived(msg);
  33. }
  34. else
  35. BTextView::KeyDown(bytes, numBytes);
  36. }
  37. void
  38. EnterTextView::SetMessage(BMessage msg, const char* textSlot)
  39. {
  40. fMessage = msg;
  41. if (textSlot != NULL)
  42. fTextSlot.SetTo(textSlot);
  43. }