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