1
0

snappnt.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. #include <precomp.h>
  2. #include "snappnt.h"
  3. #include <api/wndmgr/layout.h>
  4. #include <api/wnd/wndtrack.h>
  5. #include <api/config/items/cfgitem.h>
  6. SnapPoint::SnapPoint(Layout *l, Container *c)
  7. {
  8. points.addItem(this);
  9. setParentLayout(l);
  10. setParentContainer(c);
  11. }
  12. SnapPoint::~SnapPoint()
  13. {
  14. points.removeItem(this);
  15. }
  16. void SnapPoint::removeAll()
  17. {
  18. points.deleteAllSafe();
  19. }
  20. int SnapPoint::setXmlParam(const wchar_t *paramname, const wchar_t *strvalue)
  21. {
  22. if (!WCSICMP(paramname, L"id")) id = strvalue;
  23. else if (!WCSICMP(paramname, L"x")) x = WTOI(strvalue);
  24. else if (!WCSICMP(paramname, L"y")) y = WTOI(strvalue);
  25. else if (!WCSICMP(paramname, L"relatx")) relatx = WTOI(strvalue);
  26. else if (!WCSICMP(paramname, L"relaty")) relaty = WTOI(strvalue);
  27. else return 0;
  28. return 1;
  29. }
  30. void SnapPoint::setParentLayout(Layout *l)
  31. {
  32. playout = l;
  33. }
  34. void SnapPoint::setParentContainer(Container *c)
  35. {
  36. pcontainer = c;
  37. }
  38. Container *SnapPoint::getParentContainer()
  39. {
  40. return pcontainer;
  41. }
  42. Layout *SnapPoint::getParentLayout()
  43. {
  44. return playout;
  45. }
  46. const wchar_t *SnapPoint::getId()
  47. {
  48. return id;
  49. }
  50. int SnapPoint::getX()
  51. {
  52. if (getParentLayout())
  53. return (int)((double)x * getParentLayout()->getRenderRatio());
  54. return x;
  55. }
  56. int SnapPoint::getY()
  57. {
  58. if (getParentLayout())
  59. return (int)((double)y * getParentLayout()->getRenderRatio());
  60. return y;
  61. }
  62. PtrList<SnapPoint> SnapPoint::points;
  63. int SnapPoint::match(ifc_window *master, RECT *z, ifc_window *slave, int flag, int *donex, int *doney, int w, int h)
  64. {
  65. SnapPoint *pmast;
  66. SnapPoint *pslav;
  67. for (int i = 0;i < points.getNumItems();i++)
  68. if (points.enumItem(i)->getParentLayout() == master)
  69. {
  70. pmast = points.enumItem(i);
  71. for (int j = 0;j < points.getNumItems();j++)
  72. if (points.enumItem(j)->getParentLayout() == slave)
  73. {
  74. pslav = points.enumItem(j);
  75. int r = do_match(pmast, pslav, z, flag, donex, doney, w, h);
  76. if (r)
  77. return 1;
  78. }
  79. }
  80. return 0;
  81. }
  82. int SnapPoint::do_match(SnapPoint *pmast, SnapPoint *pslav, RECT *z, int mask, int *donex, int *doney, int w, int h)
  83. {
  84. //#if 0//BU> lone needs to make this work again
  85. //fg> maybe it would have been a good idea to tell me about it... especially since it *works fine*
  86. ASSERT(pmast);
  87. ASSERT(pslav);
  88. int f = 0;
  89. if (((mask & KEEPSIZE) == 0) && !z)
  90. {
  91. ASSERTPR(0, "match resize with no rect");
  92. }
  93. if (!z)
  94. { // just testing if docked
  95. if (!WCSICMP(pmast->getId(), pslav->getId()))
  96. {
  97. BaseWnd *wm = pmast->getParentLayout();
  98. BaseWnd *ws = pslav->getParentLayout();
  99. if (ws && ws)
  100. {
  101. RECT pmr, psr;
  102. wm->getWindowRect(&pmr);
  103. ws->getWindowRect(&psr);
  104. pmr.left += pmast->relatx ? pmast->getX() : (pmr.right - pmr.left + pmast->getX());
  105. pmr.top += pmast->relaty ? pmast->getY() : (pmr.bottom - pmr.top + pmast->getY());
  106. psr.left += pmast->relatx ? pslav->getX() : (psr.right - psr.left + pslav->getX());
  107. psr.top += pmast->relaty ? pslav->getY() : (psr.bottom - psr.top + pslav->getY());
  108. if (pmr.left == psr.left && pmr.top == psr.top)
  109. {
  110. if (donex) *donex = 1;
  111. if (doney) *doney = 1;
  112. return 1;
  113. }
  114. }
  115. }
  116. }
  117. else
  118. {
  119. ASSERT(donex);
  120. ASSERT(doney);
  121. if (!WCSICMP(pmast->getId(), pslav->getId()))
  122. {
  123. //CUT: BaseWnd *wm = pmast->getParentLayout();
  124. BaseWnd *ws = pslav->getParentLayout();
  125. if (ws && ws)
  126. {
  127. RECT pmr, psr, osr, omr;
  128. pmr = omr = *z;
  129. ws->getWindowRect(&psr);
  130. osr = psr;
  131. pmr.left += pmast->relatx ? pmast->getX() : (pmr.right - pmr.left + pmast->getX());
  132. pmr.top += pmast->relaty ? pmast->getY() : (pmr.bottom - pmr.top + pmast->getY());
  133. psr.left += pmast->relatx ? pslav->getX() : (psr.right - psr.left + pslav->getX());
  134. psr.top += pmast->relaty ? pslav->getY() : (psr.bottom - psr.top + pslav->getY());
  135. if (pmr.left > psr.left - 10 && pmr.left < psr.left + 10 && (mask & LEFT) && ! *donex)
  136. {
  137. *donex = 1;
  138. z->left = omr.left - (pmr.left - psr.left);
  139. if (mask & KEEPSIZE)
  140. z->right = z->left + w;
  141. f++;
  142. }
  143. if (pmr.top > psr.top - 10 && pmr.top < psr.top + 10 && (mask & TOP) && ! *doney)
  144. {
  145. z->top = omr.top - (pmr.top - psr.top);
  146. *doney = 1;
  147. if (mask & KEEPSIZE)
  148. z->bottom = z->top + h;
  149. f++;
  150. }
  151. }
  152. }
  153. return f > 0;
  154. }
  155. return 0;
  156. }