1 // This file is part of Notepad++ project 2 // Copyright (C)2020 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.WinControls.Window; 33 34 35 version (Windows): 36 version (Not_betterC): 37 38 //pragma(lib, "user32"); 39 40 private static import core.sys.windows.windef; 41 private static import core.sys.windows.winuser; 42 43 abstract class Window 44 { 45 protected: 46 core.sys.windows.windef.HINSTANCE _hInst = core.sys.windows.windef.NULL; 47 core.sys.windows.windef.HWND _hParent = core.sys.windows.windef.NULL; 48 core.sys.windows.windef.HWND _hSelf = core.sys.windows.windef.NULL; 49 50 public: 51 pure nothrow @safe @nogc 52 this() 53 54 do 55 { 56 this._hInst = core.sys.windows.windef.NULL; 57 this._hParent = core.sys.windows.windef.NULL; 58 this._hSelf = core.sys.windows.windef.NULL; 59 } 60 61 /* 62 //! \name Constructors & Destructor 63 //@{ 64 this() = default; 65 this(const Window &) = delete; 66 ~this() = default; 67 //@} 68 */ 69 70 nothrow @nogc 71 void initialize(core.sys.windows.windef.HINSTANCE hInst, core.sys.windows.windef.HWND parent) 72 73 in 74 { 75 } 76 77 do 78 { 79 this._hInst = hInst; 80 this._hParent = parent; 81 } 82 83 nothrow @nogc 84 void destroy(); 85 86 nothrow @nogc 87 void display(bool toShow = true, bool enhancedPositioningCheckWhenShowing = false) 88 89 in 90 { 91 } 92 93 do 94 { 95 core.sys.windows.winuser.ShowWindow(this._hSelf, (toShow) ? (core.sys.windows.winuser.SW_SHOW) : (core.sys.windows.winuser.SW_HIDE)); 96 } 97 98 // should NEVER be const !!! 99 nothrow @nogc 100 void reSizeTo(ref core.sys.windows.windef.RECT rc) 101 102 in 103 { 104 } 105 106 do 107 { 108 core.sys.windows.winuser.MoveWindow(this._hSelf, rc.left, rc.top, rc.right, rc.bottom, core.sys.windows.windef.TRUE); 109 this.redraw(); 110 } 111 112 // should NEVER be const !!! 113 nothrow @nogc 114 void reSizeToWH(ref core.sys.windows.windef.RECT rc) 115 116 in 117 { 118 } 119 120 do 121 { 122 core.sys.windows.winuser.MoveWindow(this._hSelf, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, core.sys.windows.windef.TRUE); 123 this.redraw(); 124 } 125 126 nothrow @nogc 127 void redraw(bool forceUpdate = false) 128 129 in 130 { 131 } 132 133 do 134 { 135 core.sys.windows.winuser.InvalidateRect(this._hSelf, core.sys.windows.windef.NULL, core.sys.windows.windef.TRUE); 136 137 if (forceUpdate) { 138 core.sys.windows.winuser.UpdateWindow(this._hSelf); 139 } 140 } 141 142 nothrow @nogc 143 void getClientRect(ref core.sys.windows.windef.RECT rc) 144 145 in 146 { 147 } 148 149 do 150 { 151 core.sys.windows.winuser.GetClientRect(this._hSelf, &rc); 152 } 153 154 nothrow @nogc 155 void getWindowRect(ref core.sys.windows.windef.RECT rc) 156 157 in 158 { 159 } 160 161 do 162 { 163 core.sys.windows.winuser.GetWindowRect(this._hSelf, &rc); 164 } 165 166 nothrow @nogc 167 int getWidth() 168 169 do 170 { 171 core.sys.windows.windef.RECT rc; 172 core.sys.windows.winuser.GetClientRect(this._hSelf, &rc); 173 174 return (rc.right - rc.left); 175 } 176 177 nothrow @nogc 178 int getHeight() 179 180 do 181 { 182 core.sys.windows.windef.RECT rc; 183 core.sys.windows.winuser.GetClientRect(this._hSelf, &rc); 184 185 if (core.sys.windows.winuser.IsWindowVisible(this._hSelf) == core.sys.windows.windef.TRUE) { 186 return (rc.bottom - rc.top); 187 } 188 189 return 0; 190 } 191 192 nothrow @nogc 193 bool isVisible() 194 195 do 196 { 197 return ((core.sys.windows.winuser.IsWindowVisible(this._hSelf)) ? (true) : (false)); 198 } 199 200 pure nothrow @safe @nogc 201 core.sys.windows.windef.HWND getHSelf() 202 203 do 204 { 205 return this._hSelf; 206 } 207 208 pure nothrow @safe @nogc 209 core.sys.windows.windef.HWND getHParent() 210 211 do 212 { 213 return this._hParent; 214 } 215 216 nothrow @nogc 217 void getFocus() 218 219 do 220 { 221 core.sys.windows.winuser.SetFocus(this._hSelf); 222 } 223 224 pure nothrow @safe @nogc 225 core.sys.windows.windef.HINSTANCE getHinst() 226 227 in 228 { 229 assert(this._hInst != core.sys.windows.windef.NULL); 230 } 231 232 do 233 { 234 return this._hInst; 235 } 236 237 //Window &operator = (const Window &) = delete; 238 }