wine/programs/oleview/pane.c

180 lines
5.1 KiB
C
Raw Normal View History

2006-06-14 17:51:27 +00:00
/*
* OleView (pane.c)
*
* Copyright 2006 Piotr Caban
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
2006-06-14 17:51:27 +00:00
*/
#include "main.h"
2007-03-12 15:50:54 +00:00
static int GetSplitPos(HWND hWnd)
2006-06-14 17:51:27 +00:00
{
PANE *pane = (PANE *)GetMenu(hWnd);
if(pane->pos < pane->size/2+1) pane->pos = pane->size/2+1;
return (pane->width>pane->pos+pane->size/2+1 ?
pane->pos : pane->width-pane->size/2-1);
}
2007-03-12 15:50:54 +00:00
static void DrawSplitMoving(HWND hWnd, int x)
2006-06-14 17:51:27 +00:00
{
RECT rt;
HDC hdc = GetDC(hWnd);
PANE *pane = (PANE *)GetMenu(hWnd);
GetClientRect(hWnd, &rt);
if(pane->last!=-1)
{
rt.left = pane->last-pane->size/2;
rt.right = pane->last+pane->size/2;
InvertRect(hdc, &rt);
}
pane->pos = x>MAX_WINDOW_WIDTH ? -1 : x;
x = GetSplitPos(hWnd);
pane->pos = x;
rt.left = x-pane->size/2;
rt.right = x+pane->size/2;
pane->last = x;
InvertRect(hdc, &rt);
ReleaseDC(hWnd, hdc);
}
2009-01-07 11:23:42 +00:00
static LRESULT CALLBACK PaneProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
2006-06-14 17:51:27 +00:00
{
POINT pt;
PANE *pane = (PANE*)GetMenu(hWnd);
switch(uMsg)
{
case WM_SETCURSOR:
GetCursorPos(&pt);
ScreenToClient(hWnd, &pt);
if(pt.x >= GetSplitPos(hWnd)-pane->size/2 &&
pt.x <= GetSplitPos(hWnd)+pane->size/2)
SetCursor(LoadCursorW(0, (LPWSTR)IDC_SIZEWE));
2006-06-14 17:51:27 +00:00
break;
case WM_LBUTTONDOWN:
if((short)LOWORD(lParam) >= GetSplitPos(hWnd)-pane->size/2 &&
(short)LOWORD(lParam) <= GetSplitPos(hWnd)+pane->size/2)
2006-06-14 17:51:27 +00:00
{
pane->last = -1;
DrawSplitMoving(hWnd, (short)LOWORD(lParam));
2006-06-14 17:51:27 +00:00
SetCapture(hWnd);
}
break;
case WM_LBUTTONUP:
if(GetCapture() == hWnd)
{
pane->last = -1;
DrawSplitMoving(hWnd, (short)LOWORD(lParam));
2006-06-14 17:51:27 +00:00
MoveWindow(pane->left, 0, 0,
GetSplitPos(hWnd)-pane->size/2, pane->height, TRUE);
MoveWindow(pane->right, GetSplitPos(hWnd)+pane->size/2, 0,
pane->width-GetSplitPos(hWnd)-pane->size/2, pane->height, TRUE);
ReleaseCapture();
}
break;
case WM_MOUSEMOVE:
if(GetCapture() == hWnd)
DrawSplitMoving(hWnd, (short)LOWORD(lParam));
2006-06-14 17:51:27 +00:00
break;
case WM_NOTIFY:
if((int)wParam != TYPELIB_TREE) break;
switch(((LPNMHDR)lParam)->code)
{
case TVN_SELCHANGEDW:
UpdateData(((NMTREEVIEWW *)lParam)->itemNew.hItem);
break;
}
break;
2006-06-14 17:51:27 +00:00
case WM_SIZE:
if(wParam == SIZE_MINIMIZED) break;
pane->width = LOWORD(lParam);
pane->height = HIWORD(lParam);
MoveWindow(pane->left, 0, 0,
GetSplitPos(hWnd)-pane->size/2, HIWORD(lParam), TRUE);
MoveWindow(pane->right, GetSplitPos(hWnd)+pane->size/2, 0,
LOWORD(lParam)-GetSplitPos(hWnd)-pane->size/2,
HIWORD(lParam), TRUE);
break;
case WM_DESTROY:
2023-09-08 01:03:13 +00:00
free(pane);
2006-06-14 17:51:27 +00:00
break;
default:
return DefWindowProcW(hWnd, uMsg, wParam, lParam);
2006-06-14 17:51:27 +00:00
}
return 0;
}
BOOL PaneRegisterClassW(void)
2006-06-14 17:51:27 +00:00
{
WNDCLASSW wcc;
2006-06-14 17:51:27 +00:00
const WCHAR wszPaneClass[] = { 'P','A','N','E','\0' };
memset(&wcc, 0, sizeof(WNDCLASSW));
2006-06-14 17:51:27 +00:00
wcc.lpfnWndProc = PaneProc;
wcc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcc.hCursor = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
2006-06-14 17:51:27 +00:00
wcc.lpszClassName = wszPaneClass;
if(!RegisterClassW(&wcc))
2006-06-14 17:51:27 +00:00
return FALSE;
return TRUE;
}
BOOL CreatePanedWindow(HWND hWnd, HWND *hWndCreated, HINSTANCE hInst)
{
const WCHAR wszPaneClass[] = { 'P','A','N','E','\0' };
PANE *pane;
2006-06-14 17:51:27 +00:00
2023-09-08 01:03:13 +00:00
pane = malloc(sizeof(PANE));
*hWndCreated = CreateWindowW(wszPaneClass, NULL, WS_CHILD|WS_VISIBLE,
2006-06-14 17:51:27 +00:00
CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, hWnd, (HMENU)pane, hInst, NULL);
2009-09-04 20:42:47 +00:00
if(!*hWndCreated)
2007-10-17 20:15:53 +00:00
{
2023-09-08 01:03:13 +00:00
free(pane);
2007-10-17 20:15:53 +00:00
return FALSE;
}
2006-06-14 17:51:27 +00:00
pane->left = NULL;
pane->right = NULL;
pane->pos = 300;
pane->size = 5;
return TRUE;
}
void SetLeft(HWND hParent, HWND hWnd)
{
PANE *pane = (PANE *)GetMenu(hParent);
pane->left = hWnd;
}
void SetRight(HWND hParent, HWND hWnd)
{
PANE *pane = (PANE *)GetMenu(hParent);
pane->right = hWnd;
}