WndWindow.cpp
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:21k
源码类别:

模拟服务器

开发平台:

C/C++

  1. /*****************************************************************************************
  2. // 剑侠引擎,界面窗口体系结构的最基本窗口对象
  3. // Copyright : Kingsoft 2002
  4. // Author :   Wooy(Wu yue)
  5. // CreateTime: 2002-7-9
  6. *****************************************************************************************/
  7. #include "KWin32.h"
  8. #include "KIniFile.h"
  9. #include "../Elem/WndMessage.h"
  10. #include "WndWindow.h"
  11. #include "shlwapi.h"
  12. #include "Wnds.h"
  13. #include "MouseHover.h"
  14. #include "../../../Represent/iRepresent/iRepresentShell.h"
  15. #include "../../../Represent/iRepresent/KRepresentUnit.h"
  16. extern iRepresentShell* g_pRepresentShell;
  17. int WND_SHOW_DEBUG_FRAME_TEXT = false;
  18. #define MOSE_HOVER_TIME_VALVE 1000
  19. //--------------------------------------------------------------------------
  20. // 功能:构造函数
  21. //--------------------------------------------------------------------------
  22. KWndWindow::KWndWindow()
  23. {
  24. #ifdef _DEBUG
  25. m_Caption[0] = 0;
  26. m_Caption[31] = 0;
  27. #endif
  28. m_Left = 0;
  29. m_Top = 0;
  30. m_Width = 0;
  31. m_Height = 0;
  32. m_nAbsoluteLeft = 0;
  33. m_nAbsoluteTop = 0;
  34. m_bMoving = false;
  35. m_nLastMouseHoldPosX = m_nLastMouseHoldPosY = 0;
  36. m_pPreviousWnd = NULL;
  37. m_pNextWnd = NULL;
  38. m_pFirstChild = NULL;
  39. m_pParentWnd = NULL;
  40. m_Style = WND_S_VISIBLE;
  41. }
  42. //--------------------------------------------------------------------------
  43. // 功能:分构函数
  44. //--------------------------------------------------------------------------
  45. KWndWindow::~KWndWindow()
  46. {
  47. LeaveAlone();
  48. Wnd_OnWindowDelete(this);
  49. g_MouseOver.OnWndClosed((void*)this);
  50. }
  51. //--------------------------------------------------------------------------
  52. // 功能:把窗口移动到最前面
  53. //--------------------------------------------------------------------------
  54. void KWndWindow::BringToTop()
  55. {
  56. if (m_pNextWnd)
  57. {
  58. KWndWindow* pLast = m_pNextWnd;
  59. while(pLast->m_pNextWnd)
  60. pLast = pLast->m_pNextWnd;
  61. pLast->m_pNextWnd = this;
  62. m_pNextWnd->m_pPreviousWnd = m_pPreviousWnd;
  63. if (m_pPreviousWnd)
  64. m_pPreviousWnd->m_pNextWnd = m_pNextWnd;
  65. else if (m_pParentWnd && m_pParentWnd->m_pFirstChild == this)
  66. m_pParentWnd->m_pFirstChild = m_pNextWnd;
  67. m_pNextWnd = NULL;
  68. m_pPreviousWnd = pLast;
  69. }
  70. }
  71. //--------------------------------------------------------------------------
  72. // 功能:获取窗口位置
  73. //--------------------------------------------------------------------------
  74. void KWndWindow::GetPosition(int* pLeft, int* pTop)
  75. {
  76. if (pLeft)
  77. *pLeft = m_Left;
  78. if (pTop)
  79. *pTop = m_Top;
  80. }
  81. //--------------------------------------------------------------------------
  82. // 功能:设置窗口位置(左上角相对于父窗口左上角位置的位移)
  83. //--------------------------------------------------------------------------
  84. void KWndWindow::SetPosition(int nLeft, int nTop)
  85. {
  86. AbsoluteMove(nLeft - m_Left, nTop - m_Top);
  87. m_Left = nLeft;
  88. m_Top  = nTop;
  89. }
  90. //--------------------------------------------------------------------------
  91. // 功能:获取窗口位置,绝对坐标
  92. //--------------------------------------------------------------------------
  93. void KWndWindow::GetAbsolutePos(int* pLeft, int* pTop)
  94. {
  95. if (pLeft)
  96. *pLeft = m_nAbsoluteLeft;
  97. if (pTop)
  98. *pTop = m_nAbsoluteTop;
  99. }
  100. //--------------------------------------------------------------------------
  101. // 功能:获取窗口大小
  102. //--------------------------------------------------------------------------
  103. void KWndWindow::GetSize(int* pWidth, int* pHeight)
  104. {
  105. if (pWidth)
  106. *pWidth = m_Width;
  107. if (pHeight)
  108. *pHeight = m_Height;
  109. }
  110. //--------------------------------------------------------------------------
  111. // 功能:设置窗口大小
  112. //--------------------------------------------------------------------------
  113. void KWndWindow::SetSize(int nWidth, int nHeight)
  114. {
  115. if (nWidth < 0)
  116. nWidth = 0;
  117. if (nHeight < 0)
  118. nHeight = 0;
  119. int nDX = nWidth - m_Width;
  120. int nDY = nHeight - m_Height;
  121. if (nDX == 0 && nDY == 0)
  122. return;
  123. m_Width = nWidth;
  124. m_Height = nHeight;
  125. KWndWindow* pChild = m_pFirstChild;
  126. while(pChild)
  127. {
  128. int x, y, w, h;
  129. pChild->GetPosition(&x, &y);
  130. pChild->GetSize(&w, &h);
  131. if (nDX)
  132. {
  133. if (pChild->m_Style & WND_S_SIZE_WITH_R_EDGE)
  134. pChild->SetSize(w + nDX, h);
  135. if (pChild->m_Style & WND_S_MOVE_WITH_R_EDGE)
  136. pChild->SetPosition(x + nDX, y);
  137. }
  138. if (nDY)
  139. {
  140. if (pChild->m_Style & WND_S_SIZE_WITH_B_EDGE)
  141. pChild->SetSize(w, h + nDY);
  142. if (pChild->m_Style & WND_S_MOVE_WITH_B_EDGE)
  143. pChild->SetPosition(x, y + nDY);
  144. }
  145. pChild = pChild->m_pNextWnd;
  146. };
  147. //to be check.!!!!!
  148. //一些窗口类可能会有根据窗口大小计算出一些变量保存下来供后继运算使用,
  149. //目前没有提供大小改变的通知消息,可能那些窗口的行为会有未知的结果。
  150. //但是目前情况来看那样的窗口一般不会被调用SetSize。
  151. }
  152. //--------------------------------------------------------------------------
  153. // 功能:绝对坐标的调整
  154. //--------------------------------------------------------------------------
  155. void KWndWindow::AbsoluteMove(int dx, int dy)
  156. {
  157. m_nAbsoluteLeft += dx;
  158. m_nAbsoluteTop  += dy;
  159. KWndWindow* pChild = m_pFirstChild;
  160. while(pChild)
  161. {
  162. pChild->AbsoluteMove(dx, dy);
  163. pChild = pChild->m_pNextWnd;
  164. }
  165. }
  166. //--------------------------------------------------------------------------
  167. // 功能:显示窗口
  168. //--------------------------------------------------------------------------
  169. void KWndWindow::Show()
  170. {
  171. m_Style |= WND_S_VISIBLE;
  172. }
  173. //--------------------------------------------------------------------------
  174. // 功能:隐藏窗口
  175. //--------------------------------------------------------------------------
  176. void KWndWindow::Hide()
  177. {
  178. m_Style &= ~WND_S_VISIBLE;
  179. g_MouseOver.OnWndClosed((void*)this);
  180. KWndWindow* pFocus = Wnd_GetFocusWnd();
  181. while(pFocus)
  182. {
  183. if (pFocus != this)
  184. pFocus = pFocus->m_pParentWnd;
  185. else
  186. {
  187. Wnd_SetFocusWnd(NULL);
  188. break;
  189. }
  190. }
  191. Wnd_ReleaseExclusive(this);
  192. }
  193. //--------------------------------------------------------------------------
  194. // 功能:判断窗口是否被显示
  195. //--------------------------------------------------------------------------
  196. int KWndWindow::IsVisible()
  197. {
  198. return (m_Style & WND_S_VISIBLE);
  199. }
  200. //--------------------------------------------------------------------------
  201. // 功能:禁止或者允许使窗口被操作
  202. //--------------------------------------------------------------------------
  203. void KWndWindow::Enable(int bEnable)
  204. {
  205. if (bEnable)
  206. m_Style &= ~WND_S_DISABLE;
  207. else
  208. m_Style |= WND_S_DISABLE;
  209. }
  210. void KWndWindow::Destroy()
  211. {
  212. m_Style |= WND_S_TOBEDESTROY;
  213. }
  214. void KWndWindow::Clone(KWndWindow* pCopy)
  215. {
  216. if (pCopy)
  217. {
  218. pCopy->m_Width = m_Width;
  219. pCopy->m_Height = m_Height;
  220. pCopy->m_Style = m_Style;
  221. pCopy->SetPosition(m_Left, m_Top);
  222. }
  223. }
  224. //--------------------------------------------------------------------------
  225. // 功能:初始化窗口
  226. //--------------------------------------------------------------------------
  227. int KWndWindow::Init(KIniFile* pIniFile, const char* pSection)
  228. {
  229. int nValue1, nValue2;
  230. if (pIniFile && pSection)
  231. {
  232. #ifdef _DEBUG
  233. strncpy(m_Caption, pSection, 32);
  234. #endif
  235. pIniFile->GetInteger(pSection, "Width", 0, &m_Width);
  236. pIniFile->GetInteger(pSection, "Height",0, &m_Height);
  237. pIniFile->GetInteger(pSection, "Left",  0, &nValue1);
  238. pIniFile->GetInteger(pSection, "Top",   0, &nValue2);
  239. SetPosition(nValue1, nValue2);
  240. pIniFile->GetInteger(pSection, "Disable",  0, &nValue1);
  241. pIniFile->GetInteger(pSection, "Moveable", 0, &nValue2);
  242. if (nValue1)
  243. m_Style |= WND_S_DISABLE;
  244. else
  245. m_Style &= ~WND_S_DISABLE;
  246. if (nValue2)
  247. m_Style |= WND_S_MOVEALBE;
  248. else
  249. m_Style &= ~WND_S_MOVEALBE;
  250. nValue1 = nValue2 = 0;
  251. pIniFile->GetInteger2(pSection, "FollowMove", &nValue1, &nValue2);
  252. if (nValue1)
  253. m_Style |= WND_S_MOVE_WITH_R_EDGE;
  254. else
  255. m_Style &= ~WND_S_MOVE_WITH_R_EDGE;
  256. if (nValue2)
  257. m_Style |= WND_S_MOVE_WITH_B_EDGE;
  258. else
  259. m_Style &= ~WND_S_MOVE_WITH_B_EDGE;
  260. nValue1 = nValue2 = 0;
  261. pIniFile->GetInteger2(pSection, "FollowSize", &nValue1, &nValue2);
  262. if (nValue1)
  263. m_Style |= WND_S_SIZE_WITH_R_EDGE;
  264. else
  265. m_Style &= ~WND_S_SIZE_WITH_R_EDGE;
  266. if (nValue2)
  267. m_Style |= WND_S_SIZE_WITH_B_EDGE;
  268. else
  269. m_Style &= ~WND_S_SIZE_WITH_B_EDGE;
  270. pIniFile->GetInteger(pSection, "DummyWnd", 0, &nValue1);
  271. if (nValue1 == 0)
  272. m_Style &= ~WND_S_SIZE_WITH_ALL_CHILD;
  273. else
  274. m_Style |= WND_S_SIZE_WITH_ALL_CHILD;
  275. return true;
  276. }
  277. return false;
  278. }
  279. //--------------------------------------------------------------------------
  280. // 功能:判断一个点是否落在窗口内,传入的是绝对坐标
  281. //--------------------------------------------------------------------------
  282. int KWndWindow::PtInWindow(int x, int y)
  283. {
  284. int nRet = 0;
  285. if (m_Style & WND_S_VISIBLE)
  286. {
  287. if ((m_Style & WND_S_SIZE_WITH_ALL_CHILD) == 0)
  288. {
  289. nRet = (x >= m_nAbsoluteLeft && y >= m_nAbsoluteTop &&
  290. x < m_nAbsoluteLeft + m_Width && y < m_nAbsoluteTop + m_Height);
  291. }
  292. else
  293. {
  294. KWndWindow* pChild = m_pFirstChild;
  295. while(pChild)
  296. {
  297. if (pChild->PtInWindow(x, y))
  298. {
  299. nRet = 1;
  300. break;
  301. }
  302. pChild = pChild->m_pNextWnd;
  303. };
  304. }
  305. }
  306. return nRet;
  307. }
  308. //--------------------------------------------------------------------------
  309. // 功能:绘制窗口(包括子窗口与后继兄弟窗口)
  310. //--------------------------------------------------------------------------
  311. void KWndWindow::Paint()
  312. {
  313. if (m_Style & WND_S_VISIBLE)
  314. {
  315. PaintWindow();
  316. if (m_pFirstChild)
  317. m_pFirstChild->Paint();
  318. }
  319. if (m_pNextWnd)
  320. m_pNextWnd->Paint();
  321. }
  322. //--------------------------------------------------------------------------
  323. // 功能:让窗口活动
  324. //--------------------------------------------------------------------------
  325. void KWndWindow::LetMeBreathe()
  326. {
  327. if (m_pNextWnd)
  328. m_pNextWnd->LetMeBreathe();
  329. if (m_Style & WND_S_TOBEDESTROY)
  330. delete this;
  331. else if ((m_Style & (WND_S_VISIBLE | WND_S_DISABLE)) == WND_S_VISIBLE)
  332. Breathe();
  333. }
  334. //--------------------------------------------------------------------------
  335. // 功能:添加子窗口
  336. //--------------------------------------------------------------------------
  337. void KWndWindow::AddChild(KWndWindow* pChild)
  338. {
  339. if (pChild)
  340. {
  341. pChild->SplitSmaleFamily();
  342. //调整绝对坐标
  343. pChild->AbsoluteMove(m_nAbsoluteLeft + pChild->m_Left - pChild->m_nAbsoluteLeft,
  344. m_nAbsoluteTop + pChild->m_Top - pChild->m_nAbsoluteTop);
  345. //调整级连关系
  346. pChild->m_pParentWnd = this;
  347. if (m_pFirstChild == NULL)
  348. m_pFirstChild = pChild;
  349. else
  350. {
  351. KWndWindow* pBrother = m_pFirstChild;
  352. while(pBrother->m_pNextWnd)
  353. pBrother = pBrother->m_pNextWnd;
  354. pBrother->m_pNextWnd = pChild;
  355. pChild->m_pPreviousWnd = pBrother;
  356. }
  357. }
  358. }
  359. //--------------------------------------------------------------------------
  360. // 功能:添加子窗口
  361. //--------------------------------------------------------------------------
  362. void KWndWindow::AddBrother(KWndWindow* pBrother)
  363. {
  364. if (pBrother)
  365. {
  366. pBrother->SplitSmaleFamily();
  367. //调整绝对坐标
  368. if (m_pParentWnd)
  369. {
  370. pBrother->AbsoluteMove(m_pParentWnd->m_nAbsoluteLeft + pBrother->m_Left - pBrother->m_nAbsoluteLeft,
  371. m_pParentWnd->m_nAbsoluteTop + pBrother->m_Top - pBrother->m_nAbsoluteTop);
  372. }
  373. //调整级连关系
  374. pBrother->m_pParentWnd = m_pParentWnd;
  375. if (m_pNextWnd == NULL)
  376. {
  377. m_pNextWnd = pBrother;
  378. pBrother->m_pPreviousWnd = this;
  379. }
  380. else
  381. {
  382. KWndWindow* pWnd = m_pNextWnd;
  383. while(pWnd->m_pNextWnd)
  384. pWnd = pWnd->m_pNextWnd;
  385. pWnd->m_pNextWnd = pBrother;
  386. pBrother->m_pPreviousWnd = pWnd;
  387. }
  388. }
  389. }
  390. //--------------------------------------------------------------------------
  391. // 功能:世间再无窗在我左右,一无牵连
  392. //--------------------------------------------------------------------------
  393. void KWndWindow::LeaveAlone()
  394. {
  395. SplitSmaleFamily();
  396. while (m_pFirstChild)
  397. {
  398. m_pFirstChild->m_pParentWnd = NULL;
  399. m_pFirstChild = m_pFirstChild->m_pNextWnd;
  400. }
  401. }
  402. //--------------------------------------------------------------------------
  403. // 功能:(抛父弃兄唯留子,成立小家庭),把自己(及子窗口)从窗口树里面里面分离出来
  404. //--------------------------------------------------------------------------
  405. void KWndWindow::SplitSmaleFamily()
  406. {
  407. if (IsVisible())
  408. {
  409. KWndWindow::Hide();
  410. KWndWindow::Show();
  411. }
  412. if (m_pPreviousWnd)
  413. m_pPreviousWnd->m_pNextWnd = m_pNextWnd;
  414. else if (m_pParentWnd)
  415. m_pParentWnd->m_pFirstChild = m_pNextWnd;
  416. if (m_pNextWnd)
  417. m_pNextWnd->m_pPreviousWnd = m_pPreviousWnd;
  418. m_pPreviousWnd = NULL;
  419. m_pNextWnd     = NULL;
  420. m_pParentWnd   = NULL;
  421. }
  422. //--------------------------------------------------------------------------
  423. // 功能:窗口函数(处理消息)
  424. //--------------------------------------------------------------------------
  425. int KWndWindow::WndProc(unsigned int uMsg, unsigned int uParam, int nParam)
  426. {
  427. int nRet = 0;
  428. switch(uMsg)
  429. {
  430. case WM_LBUTTONDOWN:
  431. OnLBtnDown(LOWORD(nParam), HIWORD(nParam));
  432. nRet = 1;
  433. break;
  434. case WM_RBUTTONDOWN:
  435. if (m_pParentWnd)
  436. {
  437. m_pParentWnd->WndProc(WND_M_POPUPMENU, (unsigned int)(KWndWindow*)this, nParam);
  438. nRet = 1;
  439. }
  440. break;
  441. case WM_MOUSEMOVE:
  442. if (m_bMoving)
  443. {
  444. OnMoveWnd();
  445. nRet = 1;
  446. }
  447. break;
  448. case WM_LBUTTONUP:
  449. if (m_bMoving)
  450. {
  451. Wnd_ReleaseCapture();
  452. m_bMoving = false;
  453. if (m_pParentWnd)
  454. {
  455. m_pParentWnd->WndProc(WND_N_CHILD_MOVE, (unsigned int)(KWndWindow*)this, 0);
  456. }
  457. }
  458. nRet = 1;
  459. break;
  460. case WND_M_CAPTURECHANGED:
  461. m_bMoving = false;
  462. nRet = 1;
  463. break;
  464. }
  465. return nRet;
  466. }
  467. //--------------------------------------------------------------------------
  468. // 功能:响应鼠标左键按下的操作
  469. //--------------------------------------------------------------------------
  470. void KWndWindow::OnLBtnDown(int x, int y)
  471. {
  472. if (m_Style & WND_S_MOVEALBE)
  473. {
  474. m_bMoving = TRUE;
  475. m_nLastMouseHoldPosX = x;
  476. m_nLastMouseHoldPosY = y;
  477. Wnd_SetCapture(this);
  478. }
  479. }
  480. //--------------------------------------------------------------------------
  481. // 功能:响应鼠标左键按下移动的操作
  482. //--------------------------------------------------------------------------
  483. void KWndWindow::OnMoveWnd()
  484. {
  485. int x, y;
  486. Wnd_GetCursorPos(&x, &y);
  487. if (x != m_nLastMouseHoldPosX || y != m_nLastMouseHoldPosY)
  488. {
  489. x -= m_nLastMouseHoldPosX;
  490. y -= m_nLastMouseHoldPosY;
  491. SetPosition(x + m_Left, y + m_Top);
  492. m_nLastMouseHoldPosX += x;
  493. m_nLastMouseHoldPosY += y;
  494. x = ((x & 0xffff) | ((y & 0xffff) << 16));
  495. if (x && m_pParentWnd)
  496. {
  497. m_pParentWnd->WndProc(WND_N_CHILD_MOVE, (unsigned int)(KWndWindow*)this, x);
  498. }
  499. }
  500. }
  501. //--------------------------------------------------------------------------
  502. // 功能:得到处于指定坐标位置的最上层窗口,传入的坐标为绝对坐标
  503. //--------------------------------------------------------------------------
  504. KWndWindow* KWndWindow::TopChildFromPoint(int x, int y)
  505. {
  506. KWndWindow* pLastMatch = NULL;
  507. if (PtInWindow(x, y))
  508. {
  509. pLastMatch = this;
  510. KWndWindow* pWnd = m_pFirstChild;
  511. while(pWnd)
  512. {
  513. //一系列同级的兄弟窗口,要从最上面(链表最末端的)开始判断
  514. while(pWnd->m_pNextWnd)
  515. pWnd = pWnd->m_pNextWnd;
  516. while(pWnd)
  517. {
  518. if (pWnd->PtInWindow(x, y) && !pWnd->IsDisable())
  519. {
  520. pLastMatch = pWnd;
  521. pWnd = pLastMatch->m_pFirstChild;
  522. break;
  523. }
  524. pWnd = pWnd->m_pPreviousWnd;
  525. }
  526. }
  527. }
  528. return pLastMatch;
  529. }
  530. //--------------------------------------------------------------------------
  531. // 功能:获得最顶层的父窗口
  532. //--------------------------------------------------------------------------
  533. KWndWindow* KWndWindow::GetOwner()
  534. {
  535. KWndWindow* pWnd = this;
  536. while(pWnd->m_pParentWnd)
  537. pWnd = pWnd->m_pParentWnd;
  538. return pWnd;
  539. }
  540. //--------------------------------------------------------------------------
  541. // 功能:设置窗口标题
  542. //--------------------------------------------------------------------------
  543. #ifdef _DEBUG
  544. void KWndWindow::SetCaption(char* pszCaption)
  545. {
  546. if (pszCaption)
  547. strncpy(m_Caption, pszCaption, 31);
  548. }
  549. #endif
  550. void KWndWindow::PaintDebugInfo()
  551. {
  552. char szInfo[128];
  553. szInfo[0] = 0;
  554. int nInfoLen = 0;
  555. int nOld = WND_SHOW_DEBUG_FRAME_TEXT;
  556. WND_SHOW_DEBUG_FRAME_TEXT = true;
  557. KWndWindow::PaintWindow();
  558. WND_SHOW_DEBUG_FRAME_TEXT = nOld;
  559. #ifdef _DEBUG
  560. sprintf(szInfo, "Name:%s, Pos:%d,%d,Size:%d,%d", m_Caption,
  561. m_nAbsoluteLeft, m_nAbsoluteTop, m_Width, m_Height);
  562. nInfoLen = strlen(szInfo);
  563. #else
  564. sprintf(szInfo, "Pos:%d,%d,Size:%d,%d", m_nAbsoluteLeft, m_nAbsoluteTop, m_Width, m_Height);
  565. nInfoLen = strlen(szInfo);
  566. #endif
  567. if (m_Style & WND_S_SIZE_WITH_ALL_CHILD)
  568. {
  569. RECT rc;
  570. GetAllChildLayoutRect(&rc);
  571. sprintf(&szInfo[nInfoLen], ",Rect:%d,%d-%d,%d", rc.left, rc.top,
  572. rc.right, rc.bottom);
  573. nInfoLen = strlen(szInfo);
  574. }
  575. int x, y, w, h;
  576. Wnd_GetCursorPos(&x, &y);
  577. Wnd_GetScreenSize(w, h);
  578. if (x + nInfoLen * 6  + 24 > w)
  579. x = w - nInfoLen * 6 - 24;
  580. if (y + 25 > h)
  581. y = h - 13;
  582. else
  583. y += 12;
  584. g_pRepresentShell->OutputText(12, szInfo, nInfoLen, x, y, 0xFFFF0000,
  585. 0, TEXT_IN_SINGLE_PLANE_COORD, 0xffffffff);
  586. }
  587. //--------------------------------------------------------------------------
  588. // 功能:窗体绘制
  589. //--------------------------------------------------------------------------
  590. void KWndWindow::PaintWindow()
  591. {
  592. if (m_bMoving)
  593. OnMoveWnd();
  594. if (g_pRepresentShell && WND_SHOW_DEBUG_FRAME_TEXT)
  595. {
  596. KRULine Line[4];
  597. for(int i = 0; i < 4; i++)
  598. {
  599. Line[i].Color.Color_dw = 0xff0000ff;
  600. Line[i].oPosition.nX = Line[i].oEndPos.nX = m_nAbsoluteLeft;
  601. Line[i].oPosition.nY = Line[i].oEndPos.nY = m_nAbsoluteTop;
  602. }
  603. Line[0].oEndPos.nX += m_Width;
  604. Line[1].oPosition.nY += m_Height;
  605. Line[1].oEndPos.nX += m_Width;
  606. Line[1].oEndPos.nY += m_Height;
  607. Line[2].oEndPos.nY += m_Height;
  608. Line[3].oPosition.nX += m_Width;
  609. Line[3].oEndPos.nX += m_Width;
  610. Line[3].oEndPos.nY += m_Height;
  611. g_pRepresentShell->DrawPrimitives(4, Line, RU_T_LINE, true);
  612. if (m_Style & WND_S_SIZE_WITH_ALL_CHILD)
  613. {
  614. for(int i = 0; i < 4; i++)
  615. Line[i].Color.Color_dw = 0xffff0000;
  616. RECT rc;
  617. GetAllChildLayoutRect(&rc);
  618. Line[0].oPosition.nX = Line[1].oPosition.nX = rc.left;
  619. Line[0].oEndPos.nX = Line[1].oEndPos.nX = rc.right;
  620. Line[0].oPosition.nY = Line[0].oEndPos.nY = rc.top;
  621. Line[1].oPosition.nY = Line[1].oEndPos.nY = rc.bottom;
  622. Line[0].oPosition.nY = Line[1].oPosition.nY = rc.top;
  623. Line[0].oEndPos.nY = Line[1].oEndPos.nY = rc.bottom;
  624. Line[0].oPosition.nX = Line[0].oEndPos.nX = rc.left;
  625. Line[1].oPosition.nX = Line[1].oEndPos.nX = rc.right;
  626. g_pRepresentShell->DrawPrimitives(4, Line, RU_T_LINE, true);
  627. }
  628. #ifdef _DEBUG
  629. g_pRepresentShell->OutputText(12, m_Caption, -1, m_nAbsoluteLeft, m_nAbsoluteTop, 0xFFFFFFFF);
  630. #endif
  631. }
  632. }
  633. //--------------------------------------------------------------------------
  634. // 功能:把字符串表示的颜色信息转为数值表示
  635. //--------------------------------------------------------------------------
  636. unsigned int GetColor(LPCTSTR pString)
  637. {
  638. if (pString == NULL)
  639. return 0;
  640. unsigned int Color = 0xFF000000;
  641. char Buf[16] = "";
  642. int  i = 0;
  643. int  n = 0;
  644. while (pString[i] != ',')
  645. {
  646. if (pString[i] == 0 || n >= 15)
  647. return Color;
  648. Buf[n++] = pString[i++];
  649. }
  650. Buf[n] = 0;
  651. Color += ((atoi(Buf) & 0xFF) << 16);
  652. n = 0;
  653. i++;
  654. while (pString[i] != ',')
  655. {
  656. if (pString[i] == 0 || n >= 15)
  657. return Color;
  658. Buf[n++] = pString[i++];
  659. }
  660. Buf[n] = 0;
  661. Color += ((atoi(Buf) & 0xFF) << 8);
  662. n = 0;
  663. i++;
  664. while (pString[i] != 0)
  665. {
  666. if (n >= 15)
  667. return Color;
  668. Buf[n++] = pString[i++];
  669. }
  670. Buf[n] = 0;
  671. Color += (atoi(Buf) & 0xFF);
  672. return Color;
  673. }
  674. const char* GetColorString(unsigned int nColor)
  675. {
  676. static char szColor[12];
  677. KRColor c;
  678. c.Color_dw = nColor;
  679. sprintf(szColor, "%d,%d,%d", c.Color_b.r, c.Color_b.g, c.Color_b.b);
  680. szColor[11] = 0;
  681. return szColor;
  682. }
  683. //使鼠标指针以移动到悬浮在此窗口中的位置上
  684. void KWndWindow::SetCursorAbove()
  685. {
  686. Wnd_SetCursorPos(m_nAbsoluteLeft + m_Width / 2,
  687. m_nAbsoluteTop + m_Height / 2);
  688. }
  689. //取得包含所有子窗口分布区域的最小区域
  690. void KWndWindow::GetAllChildLayoutRect(RECT* pRect)
  691. {
  692. if (pRect == NULL)
  693. return;
  694. if (m_pFirstChild == NULL)
  695. {
  696. pRect->left = pRect->right = m_nAbsoluteLeft;
  697. pRect->top = pRect->bottom = m_nAbsoluteTop;
  698. }
  699. else
  700. {
  701. m_pFirstChild->GetAbsolutePos((int*)&pRect->left, (int*)&pRect->top);
  702. pRect->right = pRect->left;
  703. pRect->bottom = pRect->top;
  704. KWndWindow* pChild = m_pFirstChild;
  705. do
  706. {
  707. RECT rc;
  708. pChild->GetAllChildLayoutRect(&rc);
  709. int x, y, w, h;
  710. pChild->GetAbsolutePos(&x, &y);
  711. pChild->GetSize(&w, &h);
  712. if (rc.left > x)
  713. rc.left = x;
  714. if (rc.top > y)
  715. rc.top = y;
  716. if (rc.right < x + w)
  717. rc.right = x + w;
  718. if (rc.bottom < y + h)
  719. rc.bottom = y + h;
  720. if (pRect->left > rc.left)
  721. pRect->left = rc.left;
  722. if (pRect->top > rc.top)
  723. pRect->top = rc.top;
  724. if (pRect->right < rc.right)
  725. pRect->right = rc.right;
  726. if (pRect->bottom < rc.bottom)
  727. pRect->bottom = rc.bottom;
  728. }while(pChild = pChild->m_pNextWnd);
  729. }
  730. }