Changeset 7
- Timestamp:
- 10/26/07 02:18:22 (11 months ago)
- Files:
-
- trunk/win32/dfl/application.d (modified) (5 diffs)
- trunk/win32/dfl/base.d (modified) (5 diffs)
- trunk/win32/dfl/button.d (modified) (2 diffs)
- trunk/win32/dfl/collections.d (modified) (1 diff)
- trunk/win32/dfl/combobox.d (modified) (4 diffs)
- trunk/win32/dfl/control.d (modified) (32 diffs)
- trunk/win32/dfl/drawing.d (modified) (17 diffs)
- trunk/win32/dfl/fontdialog.d (modified) (9 diffs)
- trunk/win32/dfl/form.d (modified) (17 diffs)
- trunk/win32/dfl/groupbox.d (modified) (2 diffs)
- trunk/win32/dfl/imagelist.d (added)
- trunk/win32/dfl/internal/com.d (modified) (3 diffs)
- trunk/win32/dfl/internal/dlib.d (modified) (2 diffs)
- trunk/win32/dfl/internal/utf.d (modified) (5 diffs)
- trunk/win32/dfl/internal/winapi.d (modified) (5 diffs)
- trunk/win32/dfl/label.d (modified) (1 diff)
- trunk/win32/dfl/listbox.d (modified) (6 diffs)
- trunk/win32/dfl/listview.d (modified) (13 diffs)
- trunk/win32/dfl/makelib.bat (modified) (5 diffs)
- trunk/win32/dfl/menu.d (modified) (5 diffs)
- trunk/win32/dfl/progressbar.d (modified) (2 diffs)
- trunk/win32/dfl/registry.d (modified) (25 diffs)
- trunk/win32/dfl/richtextbox.d (modified) (2 diffs)
- trunk/win32/dfl/socket.d (modified) (1 diff)
- trunk/win32/dfl/splitter.d (modified) (7 diffs)
- trunk/win32/dfl/statusbar.d (modified) (14 diffs)
- trunk/win32/dfl/tabcontrol.d (modified) (1 diff)
- trunk/win32/dfl/treeview.d (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/win32/dfl/application.d
r5 r7 120 120 { 121 121 version = WINDOWS_HUNG_WORKAROUND; 122 } 123 124 125 deprecated enum DflCompat 126 { 127 NONE = 0, 128 MENU_092 = 0x1, // Adding to menus is the old way. 129 CONTROL_RECREATE_095 = 0x2, // Controls don't recreate automatically when necessary. 130 CONTROL_KEYEVENT_096 = 0x4, // Key events don't propagate up the control hierarchy when they are not handled. 131 FORM_DIALOGRESULT_096 = 0x8, // When a Form is in showDialog, changing the dialogResult from NONE doesn't close the form. 122 132 } 123 133 … … 236 246 237 247 248 /+ 249 // /// 250 bool visualStyles() // getter 251 { 252 // IsAppThemed: 253 // "Do not call this function during DllMain or global objects contructors. 254 // This may cause invalid return values in Microsoft Windows Vista and may cause Windows XP to become unstable." 255 } 256 +/ 257 258 238 259 /// Path of the executable including its file name. 239 260 char[] executablePath() // getter … … 1138 1159 1139 1160 1161 version(DFL_NO_COMPAT) 1162 package const DflCompat _compat = DflCompat.NONE; 1163 else 1164 package DflCompat _compat = DflCompat.NONE; 1165 1166 1167 deprecated void setCompat(DflCompat dflcompat) 1168 { 1169 version(DFL_NO_COMPAT) 1170 { 1171 assert(0, "Compatibility disabled"); // version=DFL_NO_COMPAT 1172 } 1173 else 1174 { 1175 if(messageLoop) 1176 { 1177 assert(0, "setCompat"); // Called too late, must enable compatibility sooner. 1178 return; 1179 } 1180 1181 _compat |= dflcompat; 1182 } 1183 } 1184 1185 1140 1186 private static size_t _doref(void* p, int by) 1141 1187 { … … 1380 1426 1381 1427 1382 /+1383 1428 // Note: phobos-only. 1384 1429 debug(SHOW_MESSAGE_INFO) … … 1556 1601 } 1557 1602 } 1558 +/1559 1603 1560 1604 trunk/win32/dfl/base.d
r5 r7 297 297 298 298 /// 299 enum CheckState: ubyte 300 { 301 UNCHECKED = BST_UNCHECKED, /// 302 CHECKED = BST_CHECKED, /// ditto 303 INDETERMINATE = BST_INDETERMINATE, /// ditto 304 } 305 306 307 /// 299 308 struct Message // docmain 300 309 { … … 512 521 513 522 523 interface IDialogResult 524 { 525 // /// 526 DialogResult dialogResult(); // getter 527 // /// ditto 528 void dialogResult(DialogResult); // setter 529 } 530 531 514 532 /// 515 533 enum SortOrder: ubyte … … 669 687 670 688 /// 689 enum ColorDepth: ubyte 690 { 691 DEPTH_4BIT = 1, /// 692 DEPTH_8BIT , /// ditto 693 DEPTH_16BIT, /// ditto 694 DEPTH_24BIT, /// ditto 695 DEPTH_32BIT, /// ditto 696 } 697 698 699 /// 671 700 class PaintEventArgs: EventArgs 672 701 { … … 883 912 884 913 914 /+ 885 915 /// 886 916 class LabelEditEventArgs: EventArgs … … 937 967 938 968 alias Event!(LabelEditEventArgs) LabelEditEventHandler; // deprecated 969 +/ 939 970 940 971 trunk/win32/dfl/button.d
r5 r7 11 11 12 12 private extern(Windows) void _initButton(); 13 14 15 ///16 enum CheckState: ubyte17 {18 UNCHECKED = BST_UNCHECKED, ///19 CHECKED = BST_CHECKED, /// ditto20 INDETERMINATE = BST_INDETERMINATE, /// ditto21 }22 13 23 14 … … 325 316 326 317 onClick(EventArgs.empty); 318 } 319 320 321 protected override void onClick(EventArgs ea) 322 { 323 super.onClick(ea); 324 325 if(!(Application._compat & DflCompat.FORM_DIALOGRESULT_096)) 326 { 327 if(DialogResult.NONE != this.dialogResult) 328 { 329 auto xx = cast(IDialogResult)topLevelControl; 330 if(xx) 331 xx.dialogResult = this.dialogResult; 332 } 333 } 327 334 } 328 335 trunk/win32/dfl/collections.d
r5 r7 265 265 else 266 266 { 267 if(getObjectString(onval) == value) // ?268 return true;267 if(getObjectString(onval) == value) 268 return idx; 269 269 } 270 270 } trunk/win32/dfl/combobox.d
r5 r7 508 508 static class ObjectCollection 509 509 { 510 this(ComboBox lbox)510 protected this(ComboBox lbox) 511 511 { 512 512 this.lbox = lbox; … … 514 514 515 515 516 this(ComboBox lbox, Object[] range)516 protected this(ComboBox lbox, Object[] range) 517 517 { 518 518 this.lbox = lbox; … … 521 521 522 522 523 this(ComboBox lbox, char[][] range)523 protected this(ComboBox lbox, char[][] range) 524 524 { 525 525 this.lbox = lbox; … … 529 529 530 530 /+ 531 this(ComboBox lbox, ObjectCollection range)531 protected this(ComboBox lbox, ObjectCollection range) 532 532 { 533 533 this.lbox = lbox; trunk/win32/dfl/control.d
r5 r7 670 670 static class ControlCollection 671 671 { 672 this(Control owner)672 protected this(Control owner) 673 673 { 674 674 _owner = owner; … … 976 976 977 977 onControlAdded(cea); 978 } 979 980 981 private void _ctrlremoved(ControlEventArgs cea) 982 { 983 alayout(cea.control); 984 985 onControlRemoved(cea); 978 986 } 979 987 … … 1070 1078 +/ 1071 1079 1072 sdock = cast(DockStyle)sdock.init; // Can't be set at the same time. 1080 //sdock = cast(DockStyle)sdock.init; // Can't be set at the same time. 1081 sdock = DockStyle.NONE; // Can't be set at the same time. 1073 1082 } 1074 1083 … … 2055 2064 2056 2065 2066 /+ 2067 /// 2068 // ea is the new parent. 2069 protected void onParentChanging(ControlEventArgs ea) 2070 { 2071 } 2072 +/ 2073 2074 2057 2075 /// 2058 2076 final Form findForm() … … 2084 2102 throw new DflException("Cannot add a top level control to a control"); 2085 2103 2104 //scope ControlEventArgs pcea = new ControlEventArgs(c); 2105 //onParentChanging(pcea); 2106 2086 2107 Control oldparent; 2087 2108 _FixAmbientOld oldinfo; … … 2132 2153 onParentChanged(EventArgs.empty); 2133 2154 if(oldparent) 2134 oldparent. onControlRemoved(cea);2155 oldparent._ctrlremoved(cea); 2135 2156 c._ctrladded(cea); 2136 2157 _fixAmbient(&oldinfo); … … 2146 2167 onParentChanged(EventArgs.empty); 2147 2168 if(oldparent) 2148 oldparent. onControlRemoved(cea);2169 oldparent._ctrlremoved(cea); 2149 2170 c._ctrladded(cea); 2150 2171 _fixAmbient(&oldinfo); … … 2164 2185 onParentChanged(EventArgs.empty); 2165 2186 assert(oldparent !is null); 2166 oldparent. onControlRemoved(cea);2187 oldparent._ctrlremoved(cea); 2167 2188 _fixAmbient(&oldinfo); 2168 2189 } … … 3187 3208 3188 3209 3210 override int opCmp(Object o) 3211 { 3212 Control ctrl = cast(Control)o; 3213 if(!ctrl) 3214 return -1; 3215 return opCmp(ctrl); 3216 } 3217 3218 3219 int opCmp(Control ctrl) 3220 { 3221 if(!isHandleCreated || hwnd != ctrl.hwnd) 3222 return super.opCmp(ctrl); 3223 return 0; 3224 } 3225 3226 3189 3227 /// 3190 3228 final bool focus() … … 3330 3368 3331 3369 RedrawWindow(hwnd, null, rgn.handle, RDW_ERASE | RDW_INVALIDATE | (andChildren ? RDW_ALLCHILDREN : RDW_NOCHILDREN)); 3370 } 3371 3372 3373 /// 3374 // Redraws the entire control, including nonclient area. 3375 final void redraw() 3376 { 3377 if(!hwnd) 3378 return; 3379 3380 RedrawWindow(hwnd, null, HRGN.init, RDW_ERASE | RDW_INVALIDATE | RDW_FRAME); 3332 3381 } 3333 3382 … … 4445 4494 case WM_SYSCHAR: 4446 4495 //case WM_IMECHAR: 4496 /+ 4447 4497 if(processKeyEventArgs(msg)) 4448 4498 { … … 4453 4503 msg.result = 1; // The key was not processed. 4454 4504 break; 4505 +/ 4506 msg.result = !processKeyEventArgs(msg); 4507 return; 4455 4508 4456 4509 case WM_MOUSEWHEEL: // Requires Windows 98 or NT4. … … 4914 4967 if(ctrl) 4915 4968 { 4916 onControlRemoved(new ControlEventArgs(ctrl));4969 _ctrlremoved(new ControlEventArgs(ctrl)); 4917 4970 4918 4971 // ? … … 4993 5046 } 4994 5047 } 5048 5049 defWndProc(msg); 5050 // Only want chars if ALT isn't down, because it would break mnemonics. 5051 if(!(GetAsyncKeyState(VK_MENU) & 0x8000)) 5052 msg.result |= DLGC_WANTCHARS; 5053 return; 4995 5054 } 4996 5055 4997 /+ // This prevents mnemonics from working.4998 defWndProc(msg);4999 msg.result |= DLGC_WANTCHARS; // For keyPress.5000 return;5001 +/5002 5056 break; 5003 5057 … … 5429 5483 package final void doShow() 5430 5484 { 5431 //ShowWindow(hwnd, SW_SHOW);5432 //SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW);5433 //SetWindowPos(hwnd, GetParent(hwnd) ? HWND_BOTTOM : HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW); // ?5434 //if(GetParent(hwnd))5435 5485 if(wparent) // Exclude owner. 5436 5486 { 5437 HWND hw; 5438 hw = GetWindow(hwnd, GW_HWNDPREV); 5439 if(!hw) 5440 hw = HWND_BOTTOM; // ? 5441 SetWindowPos(hwnd, hw, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW); 5442 //SetWindowPos(hwnd, HWND.init, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW); 5487 SetWindowPos(hwnd, HWND.init, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER); 5443 5488 } 5444 5489 else … … 5451 5496 package final void doHide() 5452 5497 { 5453 //ShowWindow(hwnd, SW_HIDE); 5454 SetWindowPos(hwnd, HWND.init, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_HIDEWINDOW); 5498 SetWindowPos(hwnd, HWND.init, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_HIDEWINDOW | SWP_NOZORDER); 5455 5499 } 5456 5500 … … 5730 5774 5731 5775 /+ 5732 // /5776 // /// 5733 5777 final bool hasVisualStyle() // getter 5734 5778 { 5779 bool result = false; 5735 5780 HWND hw = handle; // Always reference handle. 5736 5781 HMODULE huxtheme = GetModuleHandleA("uxtheme.dll"); … … 5741 5786 if(getwintheme) 5742 5787 { 5743 re turngetwintheme(hw) != null;5744 } 5745 FreeLibrary(huxtheme);5746 } 5747 return false;5788 result = getwintheme(hw) != null; 5789 } 5790 //FreeLibrary(huxtheme); 5791 } 5792 return result; 5748 5793 } 5749 5794 +/ … … 6365 6410 } 6366 6411 6367 return kea.handled; 6412 if(kea.handled) 6413 return true; 6368 6414 } 6369 6415 break; … … 6374 6420 scope KeyEventArgs kea = new KeyEventArgs(cast(Keys)(msg.wParam | modifierKeys)); 6375 6421 onKeyUp(kea); 6376 return kea.handled; 6422 if(kea.handled) 6423 return true; 6377 6424 } 6378 6425 break; … … 6387 6434 scope KeyEventArgs kea = new KeyEventArgs(cast(Keys)(vk | modifierKeys)); 6388 6435 onKeyPress(kea); 6389 return kea.handled; 6436 if(kea.handled) 6437 return true; 6390 6438 } 6391 6439 break; … … 6408 6456 } 6409 6457 6458 if(Application._compat & DflCompat.CONTROL_KEYEVENT_096) 6459 goto def_action; 6460 6461 // ? 6462 if(!parent 6463 || (IsWindowVisible(hwnd) 6464 && ((ctrlStyle & ControlStyles.SELECTABLE) 6465 || (SendMessageA(hwnd, WM_GETDLGCODE, 0, 0) & DLGC_WANTALLKEYS)))) 6466 { 6467 def_action: 6468 defWndProc(msg); 6469 //return true; 6470 return !msg.result; 6471 } 6472 else 6473 { 6474 //if(parent) 6475 assert(parent !is null); 6476 return parent.processKeyEventArgs(msg); 6477 } 6478 6410 6479 return false; 6411 6480 } … … 6453 6522 else 6454 6523 { 6455 _compat = CCompat.DFL095; 6524 //_compat = CCompat.DFL095; 6525 Application.setCompat(DflCompat.CONTROL_RECREATE_095); 6456 6526 } 6457 6527 } … … 6464 6534 6465 6535 version(SET_DFL_095) 6466 private const ubyte _compat = CCompat.DFL095; 6536 package const ubyte _compat = CCompat.DFL095; 6537 else version(DFL_NO_COMPAT) 6538 package const ubyte _compat = CCompat.NONE; 6467 6539 else 6468 private ubyte _compat = CCompat.NONE; 6540 package CCompat _compat() // getter 6541 { if(Application._compat & DflCompat.CONTROL_RECREATE_095) return CCompat.DFL095; return CCompat.NONE; } 6469 6542 6470 6543 … … 6815 6888 case WM_SYSKEYUP: 6816 6889 case WM_SYSCHAR: 6817 //case WM_IMECHAR: 6890 //case WM_IMECHAR: // ? 6818 6891 prevWndProc(m); 6819 6892 break; … … 7059 7132 result.height = result.height - dpad.bottom - dpad.top; 7060 7133 7134 // Add scroll width. 7061 7135 if(scrollSize.width > clientSize.width) 7062 7136 result.width = result.width + (scrollSize.width - clientSize.width); … … 7064 7138 result.height = result.height + (scrollSize.height - clientSize.height); 7065 7139 7140 // Adjust scroll position. 7141 result.location = Point(result.location.x - scrollPosition.x, result.location.y - scrollPosition.y); 7142 7066 7143 return result; 7067 7144 } … … 7196 7273 7197 7274 const Size DEFAULT_SCALE = { 5, 13 }; 7198 7199 7200 protected:7201 7275 7202 7276 /// … … 7241 7315 return (_style() & WS_VSCROLL) != 0; 7242 7316 } 7317 7318 7319 protected: 7243 7320 7244 7321 … … 7309 7386 case SB_THUMBTRACK: 7310 7387 case SB_THUMBPOSITION: 7311 delta = cast(int)HIWORD(m.wParam) - yspos; 7388 //delta = cast(int)HIWORD(m.wParam) - yspos; // Limited to 16-bits. 7389 delta = si.nTrackPos - yspos; 7312 7390 break; 7313 7391 case SB_BOTTOM: … … 7371 7449 case SB_THUMBTRACK: 7372 7450 case SB_THUMBPOSITION: 7373 delta = cast(int)HIWORD(m.wParam) - xspos; 7451 //delta = cast(int)HIWORD(m.wParam) - xspos; // Limited to 16-bits. 7452 delta = si.nTrackPos - xspos; 7374 7453 break; 7375 7454 case SB_RIGHT: … … 7575 7654 /// 7576 7655 Control activeControl(); // getter 7577 /// ditto7656 7578 7657 deprecated void activeControl(Control); // setter 7579 7658 7580 ///7581 7659 deprecated bool activateControl(Control); 7582 7660 } trunk/win32/dfl/drawing.d
r5 r7 1088 1088 1089 1089 1090 version(Tango) 1091 { 1092 // TO-DO: not implemented yet. 1093 } 1094 else 1095 { 1096 private import std.stream; // TO-DO: remove this import; use dfl.internal.dlib. 1097 1098 1099 /// 1100 class Picture: Image // docmain 1101 { 1102 // Note: requires OleInitialize(null). 1103 1104 1105 /// 1106 // Throws exception on failure. 1107 this(Stream stm) 1108 { 1109 this.ipic = _fromStdStream(stm); 1110 if(!this.ipic) 1111 throw new DflException("Unable to load picture from stream"); 1112 } 1113 1114 /// ditto 1115 // Throws exception on failure. 1116 this(char[] fileName) 1117 { 1118 this.ipic = _fromFileName(fileName); 1119 if(!this.ipic) 1120 throw new DflException("Unable to load picture from file '" ~ fileName ~ "'"); 1121 } 1122 1123 1124 private this(dfl.internal.wincom.IPicture ipic) 1125 { 1126 this.ipic = ipic; 1127 } 1128 1129 1130 /// 1131 // Returns null on failure instead of throwing exception. 1132 static Picture fromStream(Stream stm) 1133 { 1134 dfl.internal.wincom.IPicture ipic; 1135 ipic = _fromStdStream(stm); 1136 if(!ipic) 1137 return null; 1138 return new Picture(ipic); 1139 } 1140 1141 1142 /// 1143 // Returns null on failure instead of throwing exception. 1144 static Picture fromFile(char[] fileName) 1145 { 1146 dfl.internal.wincom.IPicture ipic; 1147 ipic = _fromFileName(fileName); 1148 if(!ipic) 1149 return null; 1150 return new Picture(ipic); 1151 } 1152 1153 1154 /// 1155 final void draw(HDC hdc, Point pt) // package 1156 { 1157 int lhx, lhy; 1158 int width, height; 1159 lhx = loghimX; 1160 lhy = loghimY; 1161 width = MAP_LOGHIM_TO_PIX(lhx, GetDeviceCaps(hdc, LOGPIXELSX)); 1162 height = MAP_LOGHIM_TO_PIX(lhy, GetDeviceCaps(hdc, LOGPIXELSY)); 1163 ipic.Render(hdc, pt.x, pt.y + height, width, -height, 0, 0, lhx, lhy, null); 1164 } 1165 1166 /// ditto 1167 final override void draw(Graphics g, Point pt) 1168 { 1169 return draw(g.handle, pt); 1170 } 1171 1172 1173 /// 1174 final void drawStretched(HDC hdc, Rect r) // package 1175 { 1176 int lhx, lhy; 1177 lhx = loghimX; 1178 lhy = loghimY; 1179 ipic.Render(hdc, r.x, r.y + r.height, r.width, -r.height, 0, 0, lhx, lhy, null); 1180 } 1181 1182 /// ditto 1183 final override void drawStretched(Graphics g, Rect r) 1184 { 1185 return drawStretched(g.handle, r); 1186 } 1187 1188 1189 /// 1190 final OLE_XSIZE_HIMETRIC loghimX() // getter 1191 { 1192 OLE_XSIZE_HIMETRIC xsz; 1193 if(S_OK != ipic.get_Width(&xsz)) 1194 return 0; // ? 1195 return xsz; 1196 } 1197 1198 /// ditto 1199 final OLE_YSIZE_HIMETRIC loghimY() // getter 1200 { 1201 OLE_YSIZE_HIMETRIC ysz; 1202 if(S_OK != ipic.get_Height(&ysz)) 1203 return 0; // ? 1204 return ysz; 1205 } 1206 1207 1208 /// 1209 final override int width() // getter 1210 { 1211 Graphics g; 1212 int result; 1213 g = Graphics.getScreen(); 1214 result = getWidth(g); 1215 g.dispose(); 1216 return result; 1217 } 1218 1219 1220 /// 1221 final override int height() // getter 1222 { 1223 Graphics g; 1224 int result; 1225 g = Graphics.getScreen(); 1226 result = getHeight(g); 1227 g.dispose(); 1228 return result; 1229 } 1230 1231 1232 /// 1233 final override Size size() // getter 1234 { 1235 Graphics g; 1236 Size result; 1237 g = Graphics.getScreen(); 1238 result = getSize(g); 1239 g.dispose(); 1240 return result; 1241 } 1242 1243 1244 /// 1245 final int getWidth(HDC hdc) // package 1246 { 1247 return MAP_LOGHIM_TO_PIX(loghimX, GetDeviceCaps(hdc, LOGPIXELSX)); 1248 } 1249 1250 /// ditto 1251 final int getWidth(Graphics g) 1252 { 1253 return getWidth(g.handle); 1254 } 1255 1256 1257 /// 1258 final int getHeight(HDC hdc) // package 1259 { 1260 return MAP_LOGHIM_TO_PIX(loghimY, GetDeviceCaps(hdc, LOGPIXELSX)); 1261 } 1262 1263 /// ditto 1264 final int getHeight(Graphics g) 1265 { 1266 return getHeight(g.handle); 1267 } 1268 1269 1270 final Size getSize(HDC hdc) // package 1271 { 1272 return Size(getWidth(hdc), getHeight(hdc)); 1273 } 1274 1275 /// 1276 final Size getSize(Graphics g) 1277 { 1278 return Size(getWidth(g), getHeight(g)); 1279 } 1280 1281 1282 /// 1283 void dispose() 1284 { 1285 if(ipic) 1090 /// 1091 class Picture: Image // docmain 1092 { 1093 // Note: requires OleInitialize(null). 1094 1095 1096 /// 1097 // Throws exception on failure. 1098 this(DStream stm) 1099 { 1100 this.ipic = _fromDStream(stm); 1101 if(!this.ipic) 1102 throw new DflException("Unable to load picture from stream"); 1103 } 1104 1105 /// ditto 1106 // Throws exception on failure. 1107 this(char[] fileName) 1108 { 1109 this.ipic = _fromFileName(fileName); 1110 if(!this.ipic) 1111 throw new DflException("Unable to load picture from file '" ~ fileName ~ "'"); 1112 } 1113 1114 1115 private this(dfl.internal.wincom.IPicture ipic) 1116 { 1117 this.ipic = ipic; 1118 } 1119 1120 1121 /// 1122 // Returns null on failure instead of throwing exception. 1123 static Picture fromStream(DStream stm) 1124 { 1125 dfl.internal.wincom.IPicture ipic; 1126 ipic = _fromDStream(stm); 1127 if(!ipic) 1128 return null; 1129 return new Picture(ipic); 1130 } 1131 1132 1133 /// 1134 // Returns null on failure instead of throwing exception. 1135 static Picture fromFile(char[] fileName) 1136 { 1137 dfl.internal.wincom.IPicture ipic; 1138 ipic = _fromFileName(fileName); 1139 if(!ipic) 1140 return null; 1141 return new Picture(ipic); 1142 } 1143 1144 1145 /// 1146 final void draw(HDC hdc, Point pt) // package 1147 { 1148 int lhx, lhy; 1149 int width, height; 1150 lhx = loghimX; 1151 lhy = loghimY; 1152 width = MAP_LOGHIM_TO_PIX(lhx, GetDeviceCaps(hdc, LOGPIXELSX)); 1153 height = MAP_LOGHIM_TO_PIX(lhy, GetDeviceCaps(hdc, LOGPIXELSY)); 1154 ipic.Render(hdc, pt.x, pt.y + height, width, -height, 0, 0, lhx, lhy, null); 1155 } 1156 1157 /// ditto 1158 final override void draw(Graphics g, Point pt) 1159 { 1160 return draw(g.handle, pt); 1161 } 1162 1163 1164 /// 1165 final void drawStretched(HDC hdc, Rect r) // package 1166 { 1167 int lhx, lhy; 1168 lhx = loghimX; 1169 lhy = loghimY; 1170 ipic.Render(hdc, r.x, r.y + r.height, r.width, -r.height, 0, 0, lhx, lhy, null); 1171 } 1172 1173 /// ditto 1174 final override void drawStretched(Graphics g, Rect r) 1175 { 1176 return drawStretched(g.handle, r); 1177 } 1178 1179 1180 /// 1181 final OLE_XSIZE_HIMETRIC loghimX() // getter 1182 { 1183 OLE_XSIZE_HIMETRIC xsz; 1184 if(S_OK != ipic.get_Width(&xsz)) 1185 return 0; // ? 1186 return xsz; 1187 } 1188 1189 /// ditto 1190 final OLE_YSIZE_HIMETRIC loghimY() // getter 1191 { 1192 OLE_YSIZE_HIMETRIC ysz; 1193 if(S_OK != ipic.get_Height(&ysz)) 1194 return 0; // ? 1195 return ysz; 1196 } 1197 1198 1199 /// 1200 final override int width() // getter 1201 { 1202 Graphics g; 1203 int result; 1204 g = Graphics.getScreen(); 1205 result = getWidth(g); 1206 g.dispose(); 1207 return result; 1208 } 1209 1210 1211 /// 1212 final override int height() // getter 1213 { 1214 Graphics g; 1215 int result; 1216 g = Graphics.getScreen(); 1217 result = getHeight(g); 1218 g.dispose(); 1219 return result; 1220 } 1221 1222 1223 /// 1224 final override Size size() // getter 1225 { 1226 Graphics g; 1227 Size result; 1228 g = Graphics.getScreen(); 1229 result = getSize(g); 1230 g.dispose(); 1231 return result; 1232 } 1233 1234 1235 /// 1236 final int getWidth(HDC hdc) // package 1237 { 1238 return MAP_LOGHIM_TO_PIX(loghimX, GetDeviceCaps(hdc, LOGPIXELSX)); 1239 } 1240 1241 /// ditto 1242 final int getWidth(Graphics g) 1243 { 1244 return getWidth(g.handle); 1245 } 1246 1247 1248 /// 1249 final int getHeight(HDC hdc) // package 1250 { 1251 return MAP_LOGHIM_TO_PIX(loghimY, GetDeviceCaps(hdc, LOGPIXELSX)); 1252 } 1253 1254 /// ditto 1255 final int getHeight(Graphics g) 1256 { 1257 return getHeight(g.handle); 1258 } 1259 1260 1261 final Size getSize(HDC hdc) // package 1262 { 1263 return Size(getWidth(hdc), getHeight(hdc)); 1264 } 1265 1266 /// 1267 final Size getSize(Graphics g) 1268 { 1269 return Size(getWidth(g), getHeight(g)); 1270 } 1271 1272 1273 /// 1274 void dispose() 1275 { 1276 if(ipic) 1277 { 1278 ipic.Release(); 1279 ipic = null; 1280 } 1281 } 1282 1283 1284 ~this() 1285 { 1286 dispose(); 1287 } 1288 1289 1290 final HBITMAP toHBitmap(HDC hdc) // package 1291 { 1292 HDC memdc; 1293 HBITMAP result; 1294 HGDIOBJ oldbm; 1295 memdc = CreateCompatibleDC(hdc); 1296 if(!memdc) 1297 throw new DflException("Device error"); 1298 try 1299 { 1300 Size sz; 1301 sz = getSize(hdc); 1302 result = CreateCompatibleBitmap(hdc, sz.width, sz.height); 1303 if(!result) 1286 1304 { 1287 ipic.Release();1288 ipic = null;1305 bad_bm: 1306 throw new DflException("Unable to allocate image"); 1289 1307 } 1290 } 1291 1292 1293 ~this() 1294 { 1295 dispose(); 1296 } 1297 1298 1299 final HBITMAP toHBitmap(HDC hdc) // package 1300 { 1301 &
