aboutsummaryrefslogtreecommitdiff
path: root/Src/Plugins/Library/ml_local/view_miniinfo.cpp
blob: 997efe63d0616b7f8b963dc085c9e326b2997b41 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#include "main.h"
#include "api__ml_local.h"
#include "..\..\General\gen_ml/config.h"
#include "resource.h"

#include "..\..\General\gen_ml/ml_ipc_0313.h"

static int g_displayinfo = TRUE, g_displayinfochanged=FALSE;

static HWND m_media_hwnd = NULL;
static HWND m_info_hwnd = NULL;

static HRGN g_rgnUpdate = NULL;
static int offsetX = 0, offsetY = 0;

#define IDC_WEBINFO		0x1000

static void LayoutWindows(HWND hwnd, BOOL fShowInfo, BOOL fRedraw)
{
	RECT rc, ri, rg;
	HRGN rgn = NULL;

	GetClientRect(hwnd, &rc);
	SetRect(&rg, 0, 0, 0, 0);

	if (rc.bottom - rc.top < WASABI_API_APP->getScaleY(180)) fShowInfo = FALSE;
	if (rc.bottom <= rc.top || rc.right <= rc.left) return;

	if (fShowInfo) 
	{
		if (!IsWindow(m_info_hwnd)) // create browser
		{
			WEBINFOCREATE wic = {0};
			wic.hwndParent = hwnd;
			wic.uMsgQuery = WM_QUERYFILEINFO;
			wic.x = rc.left;
			wic.y = rc.bottom - WASABI_API_APP->getScaleY(101);
			wic.cx = (rc.right - rc.left) - WASABI_API_APP->getScaleX(3);
			wic.cy = WASABI_API_APP->getScaleY(100);
			wic.ctrlId = IDC_WEBINFO;
					
			m_info_hwnd = (HWND)SENDMLIPC(plugin.hwndLibraryParent, ML_IPC_CREATEWEBINFO, (WPARAM)&wic);
			if (IsWindow(m_info_hwnd))
			{
				SetWindowPos(m_info_hwnd, HWND_BOTTOM, 0, 0, 0, 0, 
							 SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_NOREDRAW | SWP_NOCOPYBITS);
				ShowWindow(m_info_hwnd, SW_SHOWNORMAL);
			}
		}
		else 
		{
			SetWindowPos(m_info_hwnd, NULL, rc.left, rc.bottom - WASABI_API_APP->getScaleY(101),
						 rc.right - WASABI_API_APP->getScaleX(3), WASABI_API_APP->getScaleY(100),
						 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOCOPYBITS | SWP_NOREDRAW);
		}

		if (IsWindow(m_info_hwnd))
		{
			rc.bottom -= WASABI_API_APP->getScaleY(104);
			SetRect(&rg, rc.left, rc.bottom - WASABI_API_APP->getScaleY(101),
					rc.right - WASABI_API_APP->getScaleX(10),
					rc.bottom - WASABI_API_APP->getScaleY(1));
		}
	}

	InvalidateRect(hwnd, NULL, TRUE);

	if (IsWindow(m_media_hwnd))
	{
		SetRect(&ri, rc.left, rc.top, rc.right, rc.bottom);
		rgn = CreateRectRgn(0, 0, ri.right - ri.left, ri.bottom - ri.top);	
		SendMessage(m_media_hwnd, WM_USER + 0x201, MAKEWPARAM(offsetX, offsetY), (LPARAM)rgn);
		SetWindowPos(m_media_hwnd, NULL, ri.left, ri.top, ri.right - ri.left, ri.bottom - ri.top,  
					 SWP_NOZORDER | SWP_NOCOPYBITS | SWP_NOACTIVATE | ((!fRedraw) ? SWP_NOREDRAW : 0));
		SendMessage(m_media_hwnd, WM_USER + 0x201, 0, 0L);
		if (IsWindowVisible(m_media_hwnd))
		{
			ValidateRect(hwnd, &ri);
			if (GetUpdateRect(m_media_hwnd, NULL, FALSE)) 
			{
				GetUpdateRgn(m_media_hwnd, rgn, FALSE);
				OffsetRgn(rgn, ri.left, ri.top);
				InvalidateRgn(hwnd, rgn, FALSE);
			}
		}
	}

	if (fRedraw) 
	{
		UpdateWindow(hwnd);
		if (IsWindow(m_media_hwnd)) UpdateWindow(m_media_hwnd);
	}
	if (g_rgnUpdate)
	{
		GetUpdateRgn(hwnd, g_rgnUpdate, FALSE);
		if (rgn)
		{
			OffsetRgn(rgn, rc.left, rc.top);
			CombineRgn(g_rgnUpdate, g_rgnUpdate, rgn, RGN_OR);
		}
	}
	ValidateRgn(hwnd, NULL);
	if (rgn) DeleteObject(rgn);
}

INT_PTR CALLBACK view_miniinfoDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam) 
{ 
	BOOL a=dialogSkinner.Handle(hwndDlg,uMsg,wParam,lParam); if (a) return a;

	switch(uMsg)
	{
		case WM_DISPLAYCHANGE:
			if (IsWindow(m_media_hwnd)) PostMessageW(m_media_hwnd, WM_DISPLAYCHANGE, wParam, lParam);
			if (IsWindow(m_info_hwnd)) PostMessageW(m_info_hwnd, WM_DISPLAYCHANGE, wParam, lParam);
		break;

		case WM_INITDIALOG:
		{
			g_displayinfo = g_view_metaconf->ReadInt(L"midivvis", 1);
			g_displayinfochanged = FALSE;
			m_media_hwnd = (lParam) ? WASABI_API_CREATEDIALOGW(((INT_PTR*)lParam)[1], hwndDlg, (DLGPROC)((INT_PTR*)lParam)[0]) : NULL;
			SetWindowPos(m_media_hwnd, NULL, 0,0,0,0, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_NOREDRAW | SWP_SHOWWINDOW);

			MLSKINWINDOW m = {0};
			m.skinType = SKINNEDWND_TYPE_DIALOG;
			m.hwndToSkin = hwndDlg;
			m.style = SWS_USESKINFONT | SWS_USESKINCOLORS | SWS_USESKINCURSORS;
			MLSkinWindow(plugin.hwndLibraryParent, &m);
		}
		return TRUE;

		case WM_WINDOWPOSCHANGED:
			if ((SWP_NOSIZE | SWP_NOMOVE) != ((SWP_NOSIZE | SWP_NOMOVE) & ((WINDOWPOS*)lParam)->flags) || 
				(SWP_FRAMECHANGED & ((WINDOWPOS*)lParam)->flags))
			{
				LayoutWindows(hwndDlg, g_displayinfo, !(SWP_NOREDRAW & ((WINDOWPOS*)lParam)->flags));
			}
			return 0;

		case WM_APP+1: //sent by parent for resizing window
			if (IsWindow(m_media_hwnd)) return SendMessage(m_media_hwnd,uMsg,wParam,lParam); // forward on
			return 0;

		case WM_APP+2: //sent by media child to get current query
			return SendMessage(GetParent(hwndDlg),uMsg,wParam,lParam); // forward on

		case WM_QUERYFILEINFO:	if(IsWindow(m_media_hwnd)) PostMessageW(m_media_hwnd, uMsg, wParam, lParam);  break;

		case WM_SHOWFILEINFO:				
			if (IsWindow(m_info_hwnd))
			{
				WEBINFOSHOW wis = {0};
				wis.pszFileName = (LPCWSTR)lParam;
				wis.fFlags = (TRUE == wParam) ? WISF_FORCE : WISF_NORMAL;
				SENDMLIPC(m_info_hwnd, ML_IPC_WEBINFO_SHOWINFO, (WPARAM)&wis);
			}
		case WM_USER+66:
			if (wParam == -1) 
			{
				g_displayinfo = !g_displayinfo;
				g_displayinfochanged = !g_displayinfochanged;
				if (IsWindow(m_info_hwnd)) ShowWindow(m_info_hwnd, (g_displayinfo) ? SW_SHOWNA : SW_HIDE);
				LayoutWindows(hwndDlg, g_displayinfo, TRUE);
			}
			SetWindowLongPtr(hwndDlg,DWLP_MSGRESULT, (g_displayinfo) ? 0xff : 0xf0);
		return TRUE;

		case WM_USER + 0x200:
			SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, 1); // yes, we support no - redraw resize
		return TRUE;

		case WM_USER + 0x201:
			offsetX = (short)LOWORD(wParam);
			offsetY = (short)HIWORD(wParam);
			g_rgnUpdate = (HRGN)lParam;
		return TRUE;

		case WM_PAINT:
		{
			if (GetDlgItem(hwndDlg, IDC_WEBINFO))
			{
				static int tab[] = { IDC_WEBINFO | DCW_SUNKENBORDER };
				dialogSkinner.Draw(hwndDlg, tab, sizeof(tab) / sizeof(tab[0]));
			}
			else
				dialogSkinner.Draw(hwndDlg, 0, 0);
		}
		return 0;

		case WM_ERASEBKGND:
		return 1; //handled by WADlg_DrawChildWindowBorders in WM_PAINT

		case WM_DESTROY:
			if(g_displayinfochanged) g_view_metaconf->WriteInt(L"midivvis", g_displayinfo);
			if (IsWindow(m_info_hwnd)) SENDMLIPC(m_info_hwnd, ML_IPC_WEBINFO_RELEASE, 0);
			m_media_hwnd = NULL; 	 
			m_info_hwnd = NULL;
		break;
	}
	return FALSE;
}