pane.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * OleView (pane.c)
  3. *
  4. * Copyright 2006 Piotr Caban
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  19. */
  20. #include "main.h"
  21. static int GetSplitPos(HWND hWnd)
  22. {
  23. PANE *pane = (PANE *)GetMenu(hWnd);
  24. if(pane->pos < pane->size/2+1) pane->pos = pane->size/2+1;
  25. return (pane->width>pane->pos+pane->size/2+1 ?
  26. pane->pos : pane->width-pane->size/2-1);
  27. }
  28. static void DrawSplitMoving(HWND hWnd, int x)
  29. {
  30. RECT rt;
  31. HDC hdc = GetDC(hWnd);
  32. PANE *pane = (PANE *)GetMenu(hWnd);
  33. GetClientRect(hWnd, &rt);
  34. if(pane->last!=-1)
  35. {
  36. rt.left = pane->last-pane->size/2;
  37. rt.right = pane->last+pane->size/2;
  38. InvertRect(hdc, &rt);
  39. }
  40. pane->pos = x>MAX_WINDOW_WIDTH ? -1 : x;
  41. x = GetSplitPos(hWnd);
  42. pane->pos = x;
  43. rt.left = x-pane->size/2;
  44. rt.right = x+pane->size/2;
  45. pane->last = x;
  46. InvertRect(hdc, &rt);
  47. ReleaseDC(hWnd, hdc);
  48. }
  49. static LRESULT CALLBACK PaneProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  50. {
  51. POINT pt;
  52. PANE *pane = (PANE*)GetMenu(hWnd);
  53. switch(uMsg)
  54. {
  55. case WM_SETCURSOR:
  56. GetCursorPos(&pt);
  57. ScreenToClient(hWnd, &pt);
  58. if(pt.x >= GetSplitPos(hWnd)-pane->size/2 &&
  59. pt.x <= GetSplitPos(hWnd)+pane->size/2)
  60. SetCursor(LoadCursorW(0, (LPWSTR)IDC_SIZEWE));
  61. break;
  62. case WM_LBUTTONDOWN:
  63. if((short)LOWORD(lParam) >= GetSplitPos(hWnd)-pane->size/2 &&
  64. (short)LOWORD(lParam) <= GetSplitPos(hWnd)+pane->size/2)
  65. {
  66. pane->last = -1;
  67. DrawSplitMoving(hWnd, (short)LOWORD(lParam));
  68. SetCapture(hWnd);
  69. }
  70. break;
  71. case WM_LBUTTONUP:
  72. if(GetCapture() == hWnd)
  73. {
  74. pane->last = -1;
  75. DrawSplitMoving(hWnd, (short)LOWORD(lParam));
  76. MoveWindow(pane->left, 0, 0,
  77. GetSplitPos(hWnd)-pane->size/2, pane->height, TRUE);
  78. MoveWindow(pane->right, GetSplitPos(hWnd)+pane->size/2, 0,
  79. pane->width-GetSplitPos(hWnd)-pane->size/2, pane->height, TRUE);
  80. ReleaseCapture();
  81. }
  82. break;
  83. case WM_MOUSEMOVE:
  84. if(GetCapture() == hWnd)
  85. DrawSplitMoving(hWnd, (short)LOWORD(lParam));
  86. break;
  87. case WM_NOTIFY:
  88. if((int)wParam != TYPELIB_TREE) break;
  89. switch(((LPNMHDR)lParam)->code)
  90. {
  91. case TVN_SELCHANGEDW:
  92. UpdateData(((NMTREEVIEWW *)lParam)->itemNew.hItem);
  93. break;
  94. }
  95. break;
  96. case WM_SIZE:
  97. if(wParam == SIZE_MINIMIZED) break;
  98. pane->width = LOWORD(lParam);
  99. pane->height = HIWORD(lParam);
  100. MoveWindow(pane->left, 0, 0,
  101. GetSplitPos(hWnd)-pane->size/2, HIWORD(lParam), TRUE);
  102. MoveWindow(pane->right, GetSplitPos(hWnd)+pane->size/2, 0,
  103. LOWORD(lParam)-GetSplitPos(hWnd)-pane->size/2,
  104. HIWORD(lParam), TRUE);
  105. break;
  106. case WM_DESTROY:
  107. HeapFree(GetProcessHeap(), 0, pane);
  108. break;
  109. default:
  110. return DefWindowProcW(hWnd, uMsg, wParam, lParam);
  111. }
  112. return 0;
  113. }
  114. BOOL PaneRegisterClassW(void)
  115. {
  116. WNDCLASSW wcc;
  117. const WCHAR wszPaneClass[] = { 'P','A','N','E','\0' };
  118. memset(&wcc, 0, sizeof(WNDCLASSW));
  119. wcc.lpfnWndProc = PaneProc;
  120. wcc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  121. wcc.hCursor = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
  122. wcc.lpszClassName = wszPaneClass;
  123. if(!RegisterClassW(&wcc))
  124. return FALSE;
  125. return TRUE;
  126. }
  127. BOOL CreatePanedWindow(HWND hWnd, HWND *hWndCreated, HINSTANCE hInst)
  128. {
  129. const WCHAR wszPaneClass[] = { 'P','A','N','E','\0' };
  130. PANE *pane;
  131. pane = HeapAlloc(GetProcessHeap(), 0, sizeof(PANE));
  132. *hWndCreated = CreateWindowW(wszPaneClass, NULL, WS_CHILD|WS_VISIBLE,
  133. CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, hWnd, (HMENU)pane, hInst, NULL);
  134. if(!*hWndCreated)
  135. {
  136. HeapFree(GetProcessHeap(), 0, pane);
  137. return FALSE;
  138. }
  139. pane->left = NULL;
  140. pane->right = NULL;
  141. pane->pos = 300;
  142. pane->size = 5;
  143. return TRUE;
  144. }
  145. void SetLeft(HWND hParent, HWND hWnd)
  146. {
  147. PANE *pane = (PANE *)GetMenu(hParent);
  148. pane->left = hWnd;
  149. }
  150. void SetRight(HWND hParent, HWND hWnd)
  151. {
  152. PANE *pane = (PANE *)GetMenu(hParent);
  153. pane->right = hWnd;
  154. }