1
0

grouptips.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #include "precomp.h"
  2. #include <bfc/wasabi_std.h>
  3. #include "grouptips.h"
  4. #include <api/wnd/api_window.h>
  5. #include <api/script/objects/c_script/c_group.h>
  6. #include <api/script/objects/c_script/c_text.h>
  7. #include <api/script/scriptguid.h>
  8. #include <api/script/objects/guiobject.h>
  9. #ifndef _WASABIRUNTIME
  10. BEGIN_SERVICES(GroupTips_Svc);
  11. DECLARE_SERVICETMULTI(svc_toolTipsRenderer, GroupTips);
  12. END_SERVICES(GroupTips_Svc, _GroupTips_Svc);
  13. #ifdef _X86_
  14. extern "C" { int _link_GroupTipsSvc; }
  15. #else
  16. extern "C" { int __link_GroupTipsSvc; }
  17. #endif
  18. #endif
  19. GroupTips::GroupTips()
  20. {
  21. tipwnd = NULL;
  22. }
  23. GroupTips::~GroupTips()
  24. {
  25. if (tipwnd)
  26. WASABI_API_SKIN->group_destroy(tipwnd);
  27. }
  28. int GroupTips::spawnTooltip(const wchar_t *text)
  29. {
  30. int x, y;
  31. Wasabi::Std::getMousePos(&x, &y);
  32. ifc_window *wnd = WASABI_API_SKIN->group_create_layout(L"wasabi.tooltip.group");
  33. if (wnd)
  34. {
  35. wnd->setStartHidden(1);
  36. wnd->setParent(WASABI_API_WND->main_getRootWnd());
  37. wnd->init(WASABI_API_WND->main_getRootWnd(), TRUE);
  38. wnd->getGuiObject()->guiobject_onStartup();
  39. RECT r;
  40. wnd->getClientRect(&r);
  41. int w = r.right - r.left;
  42. int h = r.bottom - r.top;
  43. y -= h; // move tip above mouse by default
  44. POINT pt = {x, y};
  45. RECT vpr;
  46. Wasabi::Std::getViewport(&vpr, &pt, NULL, NULL);
  47. if (x + w > vpr.right) x -= vpr.right - w;
  48. if (x < vpr.left) x = vpr.left;
  49. if (x + w > vpr.right)
  50. {
  51. w = vpr.right - vpr.left;
  52. x = 0;
  53. }
  54. if (y + h > vpr.bottom) y -= vpr.bottom - w;
  55. if (y < vpr.top) y = vpr.top;
  56. if (y + h > vpr.bottom)
  57. {
  58. h = vpr.bottom - vpr.top;
  59. y = 0;
  60. }
  61. wnd->resize(x, y, w, h);
  62. ScriptObject *group = static_cast<ScriptObject *>(wnd->getInterface(scriptObjectGuid));
  63. if (group)
  64. {
  65. ScriptObject *txt = C_Group(group).getObject(L"tooltip.text");
  66. if (txt)
  67. C_Text(txt).setText(text);
  68. }
  69. // tooltips should always be on top otherwise they're pointless <dro>
  70. Wasabi::Std::Wnd::setTopmost(wnd->getOsWindowHandle(), TRUE);
  71. wnd->setVisible(1);
  72. tipwnd = wnd;
  73. }
  74. return 1;
  75. }