MenuButton.cpp 817 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright 2021, Jaidyn Levesque <jadedctrl@teknik.io>
  3. * All rights reserved. Distributed under the terms of the MIT license.
  4. */
  5. #include "MenuButton.h"
  6. #include <PopUpMenu.h>
  7. MenuButton::MenuButton(const char* name, const char* label, BMessage* message)
  8. :
  9. BButton(name, label, message),
  10. fMenu(NULL)
  11. {
  12. SetBehavior(B_POP_UP_BEHAVIOR);
  13. }
  14. void
  15. MenuButton::MouseDown(BPoint where)
  16. {
  17. BButton::MouseDown(where);
  18. if (fMenu != NULL)
  19. fMenu->Go(ConvertToScreen(Bounds().LeftBottom()), true, true, true);
  20. }
  21. void
  22. MenuButton::MouseUp(BPoint where)
  23. {
  24. BButton::MouseUp(where);
  25. SetValue(B_CONTROL_OFF);
  26. }
  27. void
  28. MenuButton::MouseMoved(BPoint where, uint32 code, const BMessage* dragMsg)
  29. {
  30. }
  31. BPopUpMenu*
  32. MenuButton::Menu()
  33. {
  34. return fMenu;
  35. }
  36. void
  37. MenuButton::SetMenu(BPopUpMenu* menu)
  38. {
  39. fMenu = menu;
  40. }