1 // This file is part of Notepad++ project
2 // Copyright (C)2003 Don HO <don.h@free.fr>
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 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 /**
28  *
29  *
30  * License: GPL-2.0 or later
31  */
32 module npp_api.powereditor.scitillacomponent.gotolinedlg;
33 
34 
35 version (Windows):
36 version (Not_betterC):
37 
38 pragma(lib, "user32.lib");
39 
40 private static import core.sys.windows.basetsd;
41 private static import core.sys.windows.windef;
42 private static import core.sys.windows.winuser;
43 private static import npp_api.scintilla.scintilla;
44 private static import npp_api.powereditor.wincontrols.dockingwnd.dockingdlginterface;
45 private static import npp_api.powereditor.wincontrols.staticdialog.staticdialog;
46 private static import npp_api.powereditor.resource;
47 private static import npp_api.powereditor.misc.pluginsmanager.plugininterface;
48 private static import npp_api.pluginfunc.scintilla_msg;
49 
50 version (none) {
51 	extern class ScintillaEditView;
52 }
53 
54 class DemoDlg : npp_api.powereditor.wincontrols.dockingwnd.dockingdlginterface.DockingDlgInterface
55 {
56 public:
57 	pure nothrow @safe @nogc
58 	this()
59 
60 		do
61 		{
62 			super();
63 		}
64 
65 	version (none) {
66 		void initialize(core.sys.windows.windef.HINSTANCE hInst, core.sys.windows.windef.HWND hPere, ScintillaEditView** ppEditView)
67 
68 			do
69 			{
70 				super.initialize(hInst, hPere);
71 
72 				if (ppEditView == null) {
73 					throw new Exception(`GoToLineDlg.initialize : ppEditView is null.`);
74 				}
75 
76 				this._ppEditView = ppEditView;
77 			}
78 	}
79 
80 	nothrow @nogc
81 	override void initialize(core.sys.windows.windef.HINSTANCE hInst, core.sys.windows.windef.HWND parent)
82 
83 		do
84 		{
85 			super.initialize(hInst, parent);
86 		}
87 
88 	override void create(void* dialog_p, int dialogID, bool isRTL = false, bool msgDestParent = true)
89 
90 		in
91 		{
92 			assert(dialog_p != null);
93 		}
94 
95 		do
96 		{
97 			super.create(dialog_p, dialogID, isRTL, msgDestParent);
98 		}
99 
100 	void doDialog(void* dialog_p, bool isRTL = false)
101 
102 		do
103 		{
104 			if (!super.isCreated()) {
105 				this.create(dialog_p, npp_api.powereditor.resource.IDD_GOLINE, isRTL);
106 			}
107 
108 			this.display();
109 		}
110 
111 	nothrow @nogc
112 	override void display(bool toShow = true)
113 
114 		do
115 		{
116 			super.display(toShow);
117 
118 			if (toShow) {
119 				core.sys.windows.winuser.SetFocus(core.sys.windows.winuser.GetDlgItem(this._hSelf, npp_api.powereditor.resource.ID_GOLINE_EDIT));
120 			}
121 		}
122 protected:
123 	enum mode
124 	{
125 		go2line,
126 		go2offsset,
127 	}
128 
129 	mode _mode = this.mode.go2line;
130 
131 	extern (Windows)
132 	nothrow @nogc
133 	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)
134 
135 		do
136 		{
137 			switch (message) {
138 				case core.sys.windows.winuser.WM_INITDIALOG:
139 					core.sys.windows.winuser.SendDlgItemMessageW(this._hSelf, npp_api.powereditor.resource.IDC_RADIO_GOTOLINE, core.sys.windows.winuser.BM_SETCHECK, core.sys.windows.windef.TRUE, 0);
140 					this.goToCenter();
141 
142 					return core.sys.windows.windef.TRUE;
143 
144 				case core.sys.windows.winuser.WM_COMMAND:
145 					switch (wParam) {
146 						case core.sys.windows.winuser.IDCANCEL : // Close
147 							this.display(false);
148 							this.cleanLineEdit();
149 
150 							return core.sys.windows.windef.TRUE;
151 
152 						case core.sys.windows.winuser.IDOK:
153 							npp_api.pluginfunc.scintilla_msg.line line = this.getLine();
154 
155 							if (line != -1) {
156 								this.display(false);
157 								this.cleanLineEdit();
158 
159 								version (none) {
160 									if (this._mode == this.mode.go2line) {
161 										(*this._ppEditView).execute(npp_api.scintilla.scintilla.SCI_ENSUREVISIBLE, line - 1);
162 										(*this._ppEditView).execute(npp_api.scintilla.scintilla.SCI_GOTOLINE, line - 1);
163 									} else {
164 										auto sci_line = (*this._ppEditView).execute(npp_api.scintilla.scintilla.SCI_LINEFROMPOSITION, line);
165 										(*this._ppEditView).execute(npp_api.scintilla.scintilla.SCI_ENSUREVISIBLE, sci_line);
166 										(*this._ppEditView).execute(npp_api.scintilla.scintilla.SCI_GOTOPOS, line);
167 									}
168 								}
169 							}
170 
171 							npp_api.scintilla.scintilla.SCNotification notification = {};
172 							notification.nmhdr.code = npp_api.scintilla.scintilla.SCN_PAINTED;
173 							notification.nmhdr.hwndFrom = this._hSelf;
174 							notification.nmhdr.idFrom = core.sys.windows.winuser.GetDlgCtrlID(this._hSelf);
175 
176 							//common.h
177 							enum LINKTRIGGERED = core.sys.windows.winuser.WM_USER + 555;
178 
179 							core.sys.windows.winuser.SendMessageW(this._hParent, core.sys.windows.winuser.WM_NOTIFY, LINKTRIGGERED, cast(core.sys.windows.windef.LPARAM)(&notification));
180 
181 							version (none) {
182 								(*this._ppEditView).getFocus();
183 							}
184 
185 							return core.sys.windows.windef.TRUE;
186 
187 						default:
188 							switch (core.sys.windows.windef.HIWORD(wParam)) {
189 								case core.sys.windows.winuser.EN_SETFOCUS :
190 								case core.sys.windows.winuser.BN_SETFOCUS :
191 									this.updateLinesNumbers();
192 
193 									return core.sys.windows.windef.TRUE;
194 
195 								default :
196 									return core.sys.windows.windef.TRUE;
197 							}
198 					}
199 
200 				default:
201 					return core.sys.windows.windef.FALSE;
202 			}
203 		}
204 
205 private:
206 	version (none) {
207 		ScintillaEditView **_ppEditView = null;
208 	}
209 
210 	nothrow @nogc
211 	void updateLinesNumbers()
212 
213 		do
214 		{
215 			uint current = 0;
216 			uint limit = 0;
217 			
218 			version (none) {
219 				if (this._mode == this.mode.go2line) {
220 					current = cast(uint)((*this._ppEditView).getCurrentLineNumber() + 1);
221 					limit = cast(uint)((*this._ppEditView).execute(npp_api.scintilla.scintilla.SCI_GETLINECOUNT));
222 				} else {
223 					current = cast(uint)((*this._ppEditView).execute(npp_api.scintilla.scintilla.SCI_GETCURRENTPOS));
224 					limit = cast(uint)((*this._ppEditView).getCurrentDocLen() - 1);
225 				}
226 			}
227 
228 			core.sys.windows.winuser.SetDlgItemInt(this._hSelf, npp_api.powereditor.resource.ID_CURRLINE, current, core.sys.windows.windef.FALSE);
229 			core.sys.windows.winuser.SetDlgItemInt(this._hSelf, npp_api.powereditor.resource.ID_LASTLINE, limit, core.sys.windows.windef.FALSE);
230 		}
231 
232 	nothrow @nogc
233 	void cleanLineEdit()
234 
235 		do
236 		{
237 			core.sys.windows.winuser.SetDlgItemTextW(this._hSelf, npp_api.powereditor.resource.ID_GOLINE_EDIT, &("\0"w[0]));
238 		}
239 
240 	nothrow @nogc
241 	npp_api.pluginfunc.scintilla_msg.line getLine()
242 
243 		in
244 		{
245 		}
246 
247 		do
248 		{
249 			core.sys.windows.windef.BOOL isSuccessful;
250 			npp_api.pluginfunc.scintilla_msg.line line = core.sys.windows.winuser.GetDlgItemInt(this._hSelf, npp_api.powereditor.resource.ID_GOLINE_EDIT, &isSuccessful, core.sys.windows.windef.FALSE);
251 
252 			return (isSuccessful) ? (line) : (-1);
253 		}
254 }