1 // this file is part of Function List Plugin for Notepad++
2 // Copyright (C)2005 Jens Lorenz <jens.plugin.npp@gmx.de>
3 // 
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either
7 // version 2 of the License, or (at your option) any later version.
8 // 
9 // Note that the GPL places important restrictions on "derived works", yet
10 // it does not provide a detailed definition of that term.  To avoid      
11 // misunderstandings, we consider an application to constitute a          
12 // "derivative work" for the purpose of this license if it does any of the
13 // following:                                                             
14 // 1. Integrates source code from Notepad++.
15 // 2. Integrates/includes/aggregates Notepad++ into a proprietary executable
16 //    installer, such as those produced by InstallShield.
17 // 3. Links to a library or executes a program that does any of the above.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 // GNU General Public License for more details.
23 // 
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 /**
27  *
28  *
29  * License: GPL-2.0 or later
30  */
31 module npp_api.PowerEditor.WinControls.DockingWnd.DockingDlgInterface;
32 
33 
34 version (Windows):
35 version (Not_betterC):
36 
37 //pragma(lib, "kernel32");
38 //pragma(lib, "user32");
39 
40 private static import core.sys.windows.basetsd;
41 private static import core.sys.windows.shlwapi;
42 private static import core.sys.windows.winbase;
43 private static import core.sys.windows.windef;
44 private static import core.sys.windows.winnt;
45 private static import core.sys.windows.winuser;
46 private static import npp_api.PowerEditor.MISC.PluginsManager.Notepad_plus_msgs;
47 private static import npp_api.PowerEditor.WinControls.DockingWnd.Docking;
48 private static import npp_api.PowerEditor.WinControls.DockingWnd.dockingResource;
49 private static import npp_api.PowerEditor.WinControls.StaticDialog.StaticDialog;
50 private static import npp_api.pluginfunc.npp_msgs;
51 private static import std.path;
52 private static import std.string;
53 private static import std.utf;
54 
55 class DockingDlgInterface : npp_api.PowerEditor.WinControls.StaticDialog.StaticDialog.StaticDialog
56 {
57 protected:
58 	// Handles
59 	core.sys.windows.windef.HWND _HSource = core.sys.windows.windef.NULL;
60 	int _dlgID = -1;
61 	bool _isFloating = true;
62 	int _iDockedPos = 0;
63 	core.sys.windows.winnt.WCHAR[core.sys.windows.windef.MAX_PATH] _moduleName;
64 	core.sys.windows.winnt.WCHAR[core.sys.windows.windef.MAX_PATH] _pluginName;
65 	bool _isClosed = false;
66 
67 public:
68 	pure nothrow @safe @nogc
69 	this()
70 
71 		do
72 		{
73 			super();
74 		}
75 
76 	pure nothrow @safe @nogc
77 	this(int dlgID)
78 
79 		do
80 		{
81 			super();
82 			this._dlgID = dlgID;
83 		}
84 
85 	nothrow @nogc
86 	override void initialize(core.sys.windows.windef.HINSTANCE hInst, core.sys.windows.windef.HWND parent)
87 
88 		do
89 		{
90 			super.initialize(hInst, parent);
91 			core.sys.windows.winbase.GetModuleFileNameW(cast(core.sys.windows.windef.HMODULE)(hInst), &(this._moduleName[0]), core.sys.windows.windef.MAX_PATH);
92 
93 			core.sys.windows.winbase.lstrcpyW(&(this._moduleName[0]), &((std.path.baseName(this._moduleName)[0])));
94 
95 			super.initialize(hInst, parent);
96 			core.sys.windows.winnt.WCHAR[core.sys.windows.windef.MAX_PATH] temp;
97 			core.sys.windows.winbase.GetModuleFileNameW(cast(core.sys.windows.windef.HMODULE)(hInst), &(temp[0]), core.sys.windows.windef.MAX_PATH);
98 
99 			//this._moduleName = core.sys.windows.shlwapi.PathFindFileNameW(temp);
100 			core.sys.windows.winbase.lstrcpyW(&(this._moduleName[0]), &((std.path.baseName(this._moduleName)[0])));
101 		}
102 
103 	void create(void* dialog_p, ref npp_api.PowerEditor.WinControls.DockingWnd.Docking.tTbData data, bool isRTL = false)
104 
105 		in
106 		{
107 			assert(dialog_p != null);
108 		}
109 
110 		do
111 		{
112 			super.create(dialog_p, this._dlgID, isRTL);
113 			core.sys.windows.winnt.WCHAR[core.sys.windows.windef.MAX_PATH] temp;
114 			core.sys.windows.winuser.GetWindowTextW(this._hSelf, &(temp[0]), core.sys.windows.windef.MAX_PATH);
115 			static assert(this._pluginName.length == temp.length);
116 			static assert(this._pluginName.length == core.sys.windows.windef.MAX_PATH);
117 			this._pluginName[0 .. core.sys.windows.windef.MAX_PATH] = temp[0 .. core.sys.windows.windef.MAX_PATH];
118 
119 			// user information
120 			data.hClient = this._hSelf;
121 			data.pszName = &(this._pluginName[0]);
122 
123 			// supported features by plugin
124 			data.uMask = 0;
125 
126 			// additional info
127 			data.pszAddInfo = null;
128 		}
129 
130 	override void create(void* dialog_p, int dialogID, bool isRTL = false, bool msgDestParent = true)
131 
132 		in
133 		{
134 			assert(dialog_p != null);
135 		}
136 
137 		do
138 		{
139 			super.create(dialog_p, dialogID, isRTL, msgDestParent);
140 		}
141 
142 	nothrow @nogc
143 	void updateDockingDlg()
144 
145 		do
146 		{
147 			npp_api.pluginfunc.npp_msgs.send_NPPM_DMMUPDATEDISPINFO(this._hParent, this._hSelf);
148 		}
149 
150 	pure nothrow @safe @nogc
151 	override void destroy()
152 
153 		do
154 		{
155 		}
156 
157 	void setBackgroundColor(core.sys.windows.windef.COLORREF bgColour) = 0;
158 	void setForegroundColor(core.sys.windows.windef.COLORREF bgColour) = 0;
159 
160 	nothrow @nogc
161 	override void display(bool toShow = true, bool enhancedPositioningCheckWhenShowing = false)
162 
163 		do
164 		{
165 			core.sys.windows.winuser.SendMessageW(this._hParent, (toShow) ? (npp_api.PowerEditor.MISC.PluginsManager.Notepad_plus_msgs.NPPM_DMMSHOW) : (npp_api.PowerEditor.MISC.PluginsManager.Notepad_plus_msgs.NPPM_DMMHIDE), 0, cast(core.sys.windows.windef.LPARAM)(this._hSelf));
166 		}
167 
168 	pure nothrow @safe @nogc
169 	bool isClosed() const
170 
171 		do
172 		{
173 			return this._isClosed;
174 		}
175 
176 	pure nothrow @safe @nogc
177 	void setClosed(bool toClose)
178 
179 		do
180 		{
181 			this._isClosed = toClose;
182 		}
183 
184 	pure nothrow @safe @nogc
185 	const (core.sys.windows.winnt.WCHAR)* getPluginFileName() const
186 
187 		do
188 		{
189 			return &(this._moduleName[0]);
190 		}
191 
192 protected:
193 	extern (Windows)
194 	nothrow @nogc
195 	override core.sys.windows.basetsd.INT_PTR run_dlgProc(core.sys.windows.windef.UINT message, core.sys.windows.windef.WPARAM wParam, core.sys.windows.windef.LPARAM lParam)
196 
197 		do
198 		{
199 			switch (message) {
200 				case core.sys.windows.winuser.WM_NOTIFY:
201 					core.sys.windows.winuser.LPNMHDR pnmh = cast(core.sys.windows.winuser.LPNMHDR)(lParam);
202 
203 					if ((*pnmh).hwndFrom == this._hParent) {
204 						switch (core.sys.windows.windef.LOWORD((*pnmh).code)) {
205 							case npp_api.PowerEditor.WinControls.DockingWnd.dockingResource.DMN_CLOSE:
206 								break;
207 
208 							case npp_api.PowerEditor.WinControls.DockingWnd.dockingResource.DMN_FLOAT:
209 								this._isFloating = true;
210 
211 								break;
212 
213 							case npp_api.PowerEditor.WinControls.DockingWnd.dockingResource.DMN_DOCK:
214 								this._iDockedPos = core.sys.windows.windef.HIWORD(pnmh.code);
215 								this._isFloating = false;
216 
217 								break;
218 
219 							default:
220 								break;
221 						}
222 					}
223 
224 					break;
225 
226 				default:
227 					break;
228 			}
229 
230 			return core.sys.windows.windef.FALSE;
231 		}
232 }