4 * Copyright 2006 Piotr Caban
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.
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.
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
23 int GetSplitPos(HWND hWnd)
25 PANE *pane = (PANE *)GetMenu(hWnd);
27 if(pane->pos < pane->size/2+1) pane->pos = pane->size/2+1;
29 return (pane->width>pane->pos+pane->size/2+1 ?
30 pane->pos : pane->width-pane->size/2-1);
33 void DrawSplitMoving(HWND hWnd, int x)
36 HDC hdc = GetDC(hWnd);
37 PANE *pane = (PANE *)GetMenu(hWnd);
39 GetClientRect(hWnd, &rt);
43 rt.left = pane->last-pane->size/2;
44 rt.right = pane->last+pane->size/2;
48 pane->pos = x>MAX_WINDOW_WIDTH ? -1 : x;
49 x = GetSplitPos(hWnd);
52 rt.left = x-pane->size/2;
53 rt.right = x+pane->size/2;
60 LRESULT CALLBACK PaneProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
63 PANE *pane = (PANE*)GetMenu(hWnd);
69 ScreenToClient(hWnd, &pt);
71 if(pt.x >= GetSplitPos(hWnd)-pane->size/2 &&
72 pt.x <= GetSplitPos(hWnd)+pane->size/2)
73 SetCursor(LoadCursor(0, IDC_SIZEWE));
76 if((short)LOWORD(lParam) >= GetSplitPos(hWnd)-pane->size/2 &&
77 (short)LOWORD(lParam) <= GetSplitPos(hWnd)+pane->size/2)
80 DrawSplitMoving(hWnd, (short)LOWORD(lParam));
85 if(GetCapture() == hWnd)
88 DrawSplitMoving(hWnd, (short)LOWORD(lParam));
90 MoveWindow(pane->left, 0, 0,
91 GetSplitPos(hWnd)-pane->size/2, pane->height, TRUE);
92 MoveWindow(pane->right, GetSplitPos(hWnd)+pane->size/2, 0,
93 pane->width-GetSplitPos(hWnd)-pane->size/2, pane->height, TRUE);
99 if(GetCapture() == hWnd)
100 DrawSplitMoving(hWnd, (short)LOWORD(lParam));
103 if((int)wParam != TYPELIB_TREE) break;
104 switch(((LPNMHDR)lParam)->code)
107 UpdateData(((NMTREEVIEW *)lParam)->itemNew.hItem);
112 if(wParam == SIZE_MINIMIZED) break;
113 pane->width = LOWORD(lParam);
114 pane->height = HIWORD(lParam);
116 MoveWindow(pane->left, 0, 0,
117 GetSplitPos(hWnd)-pane->size/2, HIWORD(lParam), TRUE);
118 MoveWindow(pane->right, GetSplitPos(hWnd)+pane->size/2, 0,
119 LOWORD(lParam)-GetSplitPos(hWnd)-pane->size/2,
120 HIWORD(lParam), TRUE);
123 HeapFree(GetProcessHeap(), 0, pane);
126 return DefWindowProc(hWnd, uMsg, wParam, lParam);
131 BOOL PaneRegisterClass(void)
134 const WCHAR wszPaneClass[] = { 'P','A','N','E','\0' };
136 memset(&wcc, 0, sizeof(WNDCLASS));
137 wcc.lpfnWndProc = PaneProc;
138 wcc.hbrBackground = (HBRUSH)(COLOR_WINDOW);
139 wcc.lpszClassName = wszPaneClass;
141 if(!RegisterClass(&wcc))
146 BOOL CreatePanedWindow(HWND hWnd, HWND *hWndCreated, HINSTANCE hInst)
148 const WCHAR wszPaneClass[] = { 'P','A','N','E','\0' };
151 pane = HeapAlloc(GetProcessHeap(), 0, sizeof(PANE));
152 *hWndCreated = CreateWindow(wszPaneClass, NULL, WS_CHILD|WS_VISIBLE,
153 CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, hWnd, (HMENU)pane, hInst, NULL);
154 if(!hWndCreated) return FALSE;
164 void SetLeft(HWND hParent, HWND hWnd)
166 PANE *pane = (PANE *)GetMenu(hParent);
170 void SetRight(HWND hParent, HWND hWnd)
172 PANE *pane = (PANE *)GetMenu(hParent);