UserPopUp.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Copyright 2009, Pier Luigi Fiorini. All rights reserved.
  3. * Distributed under the terms of the MIT License.
  4. *
  5. * Authors:
  6. * Pier Luigi Fiorini, pierluigi.fiorini@gmail.com
  7. */
  8. #include "UserPopUp.h"
  9. #include <GroupLayout.h>
  10. #include <GroupLayoutBuilder.h>
  11. #include <StringView.h>
  12. #include <TextControl.h>
  13. #include <libinterface/BitmapView.h>
  14. #include "User.h"
  15. #include "NotifyMessage.h"
  16. const window_feel kMenuWindowFeel = window_feel(B_NORMAL_WINDOW_FEEL);
  17. const int32 kNickChanged = 'NICH';
  18. UserPopUp::UserPopUp(User* user)
  19. : BWindow(BRect(0, 0, 1, 1), "UserPopUp", B_BORDERED_WINDOW_LOOK,
  20. kMenuWindowFeel, B_NOT_MOVABLE | B_NOT_CLOSABLE | B_NOT_MINIMIZABLE |
  21. B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS |
  22. B_AVOID_FOCUS | B_AUTO_UPDATE_SIZE_LIMITS),
  23. fCoords(B_ORIGIN)
  24. {
  25. // Box to change nick name
  26. fNickBox = new BTextControl("nickBox", NULL, user->GetName(),
  27. new BMessage(kNickChanged));
  28. // Real nick name
  29. fLabel = new BStringView("label", user->GetId());
  30. // Avatar bitmap
  31. fAvatarView = new BitmapView("avatarView");
  32. fAvatarView->SetBitmap(user->AvatarBitmap());
  33. // Layout
  34. SetLayout(new BGroupLayout(B_VERTICAL));
  35. AddChild(BGroupLayoutBuilder(B_HORIZONTAL, 10)
  36. .AddGroup(B_VERTICAL)
  37. .Add(fNickBox)
  38. .Add(fLabel)
  39. .AddGlue()
  40. .End()
  41. .Add(fAvatarView)
  42. .SetInsets(10, 10, 10, 10)
  43. .TopView()
  44. );
  45. }
  46. void
  47. UserPopUp::MessageReceived(BMessage* msg)
  48. {
  49. switch (msg->what) {
  50. case kNickChanged:
  51. break;
  52. default:
  53. BWindow::MessageReceived(msg);
  54. }
  55. }
  56. void
  57. UserPopUp::MoveTo(BPoint where)
  58. {
  59. if (fCoords != where) {
  60. if (Lock()) {
  61. BWindow::MoveTo(where);
  62. fCoords = where;
  63. Unlock();
  64. }
  65. }
  66. }
  67. void
  68. UserPopUp::ObserveString(int32 what, BString str)
  69. {
  70. switch (what) {
  71. case STR_CONTACT_NAME:
  72. if (Lock()) {
  73. fLabel->SetText(str);
  74. Unlock();
  75. }
  76. break;
  77. }
  78. }
  79. void
  80. UserPopUp::ObservePointer(int32 what, void* ptr)
  81. {
  82. switch (what) {
  83. case PTR_AVATAR_BITMAP:
  84. if (Lock()) {
  85. fAvatarView->SetBitmap((BBitmap*)ptr);
  86. Unlock();
  87. }
  88. break;
  89. }
  90. }
  91. void
  92. UserPopUp::ObserveInteger(int32 what, int32 val)
  93. {
  94. switch (what) {
  95. case INT_CONTACT_STATUS:
  96. break;
  97. }
  98. }