summaryrefslogtreecommitdiff
path: root/plugins/MagneticWindows/src/MagneticWindows.cpp
blob: c7f2d7f9869ce7fbe14452c5d3610c5e7793ca8d (plain)
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
#include "stdafx.h"

///////////////////////////////////////////////////////////////////////////////////////////////////
//
//  Magnetic Windows
//
//  Autor: Michael Kunz
//  EMail: Michael.Kunz@s2005.tu-chemnitz.de
//  
//
//  thanks to: pescuma
//
///////////////////////////////////////////////////////////////////////////////////////////////////


///////////////////////////////////////////////////////////////////////////////////////////////////
// Variables
///////////////////////////////////////////////////////////////////////////////////////////////////

PLUGININFOEX pluginInfo = {
	sizeof(PLUGININFOEX),
	__PLUGIN_NAME,
	PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM),
	__DESCRIPTION,
	__AUTHOR,
	__COPYRIGHT,
	__AUTHORWEB,
	UNICODE_AWARE,
	// {08C01613-24C8-486F-BDAE-2C3DDCAF9347}
	{0x8c01613, 0x24c8, 0x486f, { 0xbd, 0xae, 0x2c, 0x3d, 0xdc, 0xaf, 0x93, 0x47 }} 
};

HINSTANCE hInst;
int hLangpack;
CLIST_INTERFACE *pcli;

///////////////////////////////////////////////////////////////////////////////////////////////////
// Plugin Functions
///////////////////////////////////////////////////////////////////////////////////////////////////


//For other Plugins to start snapping for other Windows
INT_PTR SnapPluginWindowStart(WPARAM wParam, LPARAM)
{
	if (!WindowOpen((HWND)wParam)) return 1;
	return 0;
}

//For other Plugins to stop snapping for other Windows
INT_PTR SnapPluginWindowStop(WPARAM wParam, LPARAM)
{
	if (!WindowClose((HWND)wParam)) return 1;
	return 0;
}

int PluginMessageWindowEvent(WPARAM, LPARAM lParam)
{
	MessageWindowEventData *Data = (MessageWindowEventData*) lParam;
	
	switch (Data->uType) {
	case MSG_WINDOW_EVT_OPEN: 
		{
			HWND hWnd = Data->hwndWindow;
			HWND hWndParent = GetParent(hWnd);
			while ((hWndParent != 0) && (hWndParent != GetDesktopWindow()) && (IsWindowVisible(hWndParent))) {			
				hWnd = hWndParent;
				hWndParent = GetParent(hWnd);			
			}

			WindowOpen(hWnd);
		}
		break;

	case MSG_WINDOW_EVT_CLOSING:
		WindowClose(Data->hwndWindow);
		break;
	}

	return 0;
}


///////////////////////////////////////////////////////////////////////////////////////////////////
// Main Functions
///////////////////////////////////////////////////////////////////////////////////////////////////

int SnapPluginStart(WPARAM, LPARAM)
{
	LoadOptions();

	HookEvent(ME_MSG_WINDOWEVENT, PluginMessageWindowEvent);

	WindowOpen(pcli->hwndContactList);
	return 0;
}

int SnapPluginShutDown(WPARAM, LPARAM)
{
	WindowCloseAll();
	return 0;
}


///////////////////////////////////////////////////////////////////////////////////////////////////
// Exportet Functions
///////////////////////////////////////////////////////////////////////////////////////////////////

extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD)
{
	return &pluginInfo;
}

extern "C" int __declspec(dllexport) Load()
{
	mir_getLP(&pluginInfo);
	pcli = Clist_GetInterface();
	
	HookEvent(ME_SYSTEM_MODULESLOADED, SnapPluginStart);
	HookEvent(ME_SYSTEM_PRESHUTDOWN, SnapPluginShutDown);
	HookEvent(ME_OPT_INITIALISE, InitOptions);

	CreateServiceFunction(MS_MW_ADDWINDOW, SnapPluginWindowStart);
	CreateServiceFunction(MS_MW_REMWINDOW, SnapPluginWindowStop);
	CreateServiceFunction(MS_MW_SNAPTOLIST, SnapToList);

	WindowStart();
	return 0;
}

extern "C" int __declspec(dllexport) Unload()
{
	return 0;
}

///////////////////////////////////////////////////////////////////////////////////////////////////
// DLL MAIN
///////////////////////////////////////////////////////////////////////////////////////////////////


BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD, LPVOID)
{
	hInst = hinstDLL;
	return TRUE;
}