Changeset 1743 for trunk/src/oleaut32/iPicture.cpp
- Timestamp:
- Nov 14, 1999, 10:07:18 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/oleaut32/iPicture.cpp
r1729 r1743 1 /* $Id: iPicture.cpp,v 1. 1 1999-11-14 01:26:35davidr Exp $ */1 /* $Id: iPicture.cpp,v 1.2 1999-11-14 21:05:08 davidr Exp $ */ 2 2 /* 3 3 * OLE Picture functions … … 20 20 21 21 #include "oleaut32.h" 22 #include "olectl.h" 22 23 #include "ipicture.h" 23 24 24 typedef struct IPictureImpl {25 26 // IUnknown, IPictureImpl27 ICOM_VTABLE(IPicture) * lpvtbl1;28 29 // IDispatch, IPictureImplDisp30 ICOM_VTABLE(IDispatch) * lpvtbl2;31 32 // IPersistStream33 ICOM_VTABLE(IPersistStream) * lpvtbl3;34 35 ULONG ref; // Reference counter...36 37 // PICTDESC description;38 39 short sType;40 HANDLE hPicture;41 HANDLE hPal;42 BOOL fKeepOriginalFormat;43 BOOL fOwn;44 HDC hdc;45 DWORD lAttrib;46 47 } IPictureImpl;48 49 // Access macros50 #define _ICOM_THIS(class, name) class* This = (class*)name;51 #define _ICOM_THIS_From_IDispatch(class, name) class * This = (class*)(((char*)name)-sizeof(void*));52 #define _ICOM_THIS_From_IPersistStream(class, name) class * This = (class*)(((char*)name)-2*sizeof(void*));53 25 54 26 // ====================================================================== … … 190 162 191 163 // ---------------------------------------------------------------------- 164 // Uninitialised Picture 165 // ---------------------------------------------------------------------- 166 HRESULT IPictureNone::get_Handle(OLE_HANDLE * pHandle) 167 { 168 *pHandle = 0; 169 return E_FAIL; 170 } 171 172 HRESULT IPictureNone::get_hPal(OLE_HANDLE * phPal) 173 { 174 *phPal = 0; 175 return E_FAIL; 176 } 177 178 HRESULT IPictureNone::get_Type(SHORT * pType) 179 { 180 *pType = PICTYPE_UNINITIALIZED; 181 return S_OK; 182 } 183 184 HRESULT IPictureNone::get_Width(OLE_XSIZE_HIMETRIC * pWidth) 185 { 186 *pWidth = 0; 187 return E_FAIL; 188 } 189 190 HRESULT IPictureNone::get_Height(OLE_YSIZE_HIMETRIC * pHeight) 191 { 192 *pHeight = 0; 193 return E_FAIL; 194 } 195 196 HRESULT IPictureNone::Render(HDC hdc, LONG x, LONG y, LONG cx, LONG cy, 197 OLE_XPOS_HIMETRIC xSrc, OLE_YPOS_HIMETRIC ySrc, 198 OLE_XSIZE_HIMETRIC cxSrc, OLE_YSIZE_HIMETRIC cySrc, 199 LPCRECT pRcWBounds) 200 { 201 return E_FAIL; 202 } 203 204 HRESULT IPictureNone::set_hPal(OLE_HANDLE hPal) 205 { 206 return E_FAIL; 207 } 208 209 HRESULT IPictureNone::SaveAsFile(LPSTREAM pStream, BOOL fSaveMemCopy, LONG * pCbSize) 210 { 211 return E_FAIL; 212 } 213 214 HRESULT IPictureNone::get_Attributes(DWORD * pDwAttr) 215 { 216 *pDwAttr = 0; 217 return S_OK; 218 } 219 220 IPictureBmp::IPictureBmp(IPictureImpl * a_pPicture, HBITMAP hbitmap, HPALETTE hpal) 221 : IPictureStrat(a_pPicture) 222 { 223 pPicture->u.bmp.hbitmap = hbitmap; 224 pPicture->u.bmp.hpal = hpal; 225 } 226 227 // ---------------------------------------------------------------------- 228 // Icon Picture 229 // ---------------------------------------------------------------------- 230 IPictureBmp::~IPictureBmp() 231 { 232 if (pPicture->fOwn) 233 { 234 // Free bitmap... 235 DeleteObject(pPicture->u.bmp.hbitmap); 236 DeleteObject(pPicture->u.bmp.hpal); 237 } 238 } 239 240 HRESULT IPictureBmp::get_Handle(OLE_HANDLE * pHandle) 241 { 242 *pHandle = pPicture->u.bmp.hbitmap; 243 return S_OK; 244 } 245 246 HRESULT IPictureBmp::get_hPal(OLE_HANDLE * phPal) 247 { 248 *phPal = pPicture->u.bmp.hpal; 249 return S_OK; 250 } 251 252 HRESULT IPictureBmp::get_Type(SHORT * pType) 253 { 254 *pType = PICTYPE_BITMAP; 255 return S_OK; 256 } 257 258 HRESULT IPictureBmp::get_Width(OLE_XSIZE_HIMETRIC * pWidth) 259 { 260 SIZE size; 261 262 if (GetBitmapDimensionEx( pPicture->u.bmp.hbitmap, &size) == 0) 263 { 264 *pWidth = 0; 265 return E_FAIL; 266 } 267 268 *pWidth = size.cx; 269 270 return S_OK; 271 } 272 273 HRESULT IPictureBmp::get_Height(OLE_YSIZE_HIMETRIC * pHeight) 274 { 275 SIZE size; 276 277 if (GetBitmapDimensionEx( pPicture->u.bmp.hbitmap, &size) == 0) 278 { 279 *pHeight = 0; 280 return E_FAIL; 281 } 282 283 *pHeight = size.cy; 284 285 return S_OK; 286 } 287 288 HRESULT IPictureBmp::Render(HDC hdc, LONG x, LONG y, LONG cx, LONG cy, 289 OLE_XPOS_HIMETRIC xSrc, OLE_YPOS_HIMETRIC ySrc, 290 OLE_XSIZE_HIMETRIC cxSrc, OLE_YSIZE_HIMETRIC cySrc, 291 LPCRECT pRcWBounds) 292 { 293 return E_FAIL; 294 } 295 296 HRESULT IPictureBmp::set_hPal(OLE_HANDLE hPal) 297 { 298 pPicture->u.bmp.hpal = hPal; 299 return S_OK; 300 } 301 302 HRESULT IPictureBmp::SaveAsFile(LPSTREAM pStream, BOOL fSaveMemCopy, LONG * pCbSize) 303 { 304 return E_FAIL; 305 } 306 307 HRESULT IPictureBmp::get_Attributes(DWORD * pDwAttr) 308 { 309 // Although bitmaps may be scaled, it is really stretching. 310 *pDwAttr = 0; 311 return S_OK; 312 } 313 314 // ---------------------------------------------------------------------- 315 // Metafile Picture 316 // ---------------------------------------------------------------------- 317 IPictureIcon::IPictureIcon(IPictureImpl * a_pPicture, HICON hicon) 318 : IPictureStrat(a_pPicture) 319 { 320 pPicture->u.icon.hicon = hicon; 321 } 322 323 IPictureIcon::~IPictureIcon() 324 { 325 if (pPicture->fOwn) 326 { 327 // Free icon... 328 DestroyIcon(pPicture->u.icon.hicon); 329 } 330 } 331 332 HRESULT IPictureIcon::get_Handle(OLE_HANDLE * pHandle) 333 { 334 *pHandle = pPicture->u.icon.hicon; 335 return S_OK; 336 } 337 338 HRESULT IPictureIcon::get_hPal(OLE_HANDLE * phPal) 339 { 340 *phPal = 0; 341 return S_OK; 342 } 343 344 HRESULT IPictureIcon::get_Type(SHORT * pType) 345 { 346 *pType = PICTYPE_ICON; 347 return S_OK; 348 } 349 350 HRESULT IPictureIcon::get_Width(OLE_XSIZE_HIMETRIC * pWidth) 351 { 352 // FIXME - Read from system constants... 353 *pWidth = 32; 354 355 return S_OK; 356 } 357 358 HRESULT IPictureIcon::get_Height(OLE_YSIZE_HIMETRIC * pHeight) 359 { 360 // FIXME - Read from system constants... 361 *pHeight = 32; 362 363 return S_OK; 364 } 365 366 HRESULT IPictureIcon::Render(HDC hdc, LONG x, LONG y, LONG cx, LONG cy, 367 OLE_XPOS_HIMETRIC xSrc, OLE_YPOS_HIMETRIC ySrc, 368 OLE_XSIZE_HIMETRIC cxSrc, OLE_YSIZE_HIMETRIC cySrc, 369 LPCRECT pRcWBounds) 370 { 371 return E_FAIL; 372 } 373 374 HRESULT IPictureIcon::set_hPal(OLE_HANDLE hPal) 375 { 376 return E_FAIL; 377 } 378 379 HRESULT IPictureIcon::SaveAsFile(LPSTREAM pStream, BOOL fSaveMemCopy, LONG * pCbSize) 380 { 381 return E_FAIL; 382 } 383 384 HRESULT IPictureIcon::get_Attributes(DWORD * pDwAttr) 385 { 386 *pDwAttr = PICTURE_TRANSPARENT; 387 return S_OK; 388 } 389 390 // ---------------------------------------------------------------------- 391 // Enhanced Metafile Picture 392 // ---------------------------------------------------------------------- 393 394 IPictureMeta::IPictureMeta(IPictureImpl * a_pPicture, HMETAFILE hmeta, int xExt, int yExt) 395 : IPictureStrat(a_pPicture) 396 { 397 pPicture->u.wmf.hmeta = hmeta; 398 pPicture->u.wmf.xExt = xExt; 399 pPicture->u.wmf.yExt = yExt; 400 } 401 402 IPictureMeta::~IPictureMeta() 403 { 404 if (pPicture->fOwn) 405 { 406 // Free metafile... 407 DeleteMetaFile(pPicture->u.wmf.hmeta); 408 } 409 } 410 411 HRESULT IPictureMeta::get_Handle(OLE_HANDLE * pHandle) 412 { 413 *pHandle = pPicture->u.wmf.hmeta; 414 return S_OK; 415 } 416 417 HRESULT IPictureMeta::get_hPal(OLE_HANDLE * phPal) 418 { 419 *phPal = 0; 420 return E_FAIL; 421 } 422 423 HRESULT IPictureMeta::get_Type(SHORT * pType) 424 { 425 *pType = PICTYPE_METAFILE; 426 return S_OK; 427 } 428 429 HRESULT IPictureMeta::get_Width(OLE_XSIZE_HIMETRIC * pWidth) 430 { 431 *pWidth = pPicture->u.wmf.xExt; 432 return S_OK; 433 } 434 435 HRESULT IPictureMeta::get_Height(OLE_YSIZE_HIMETRIC * pHeight) 436 { 437 *pHeight = pPicture->u.wmf.yExt; 438 return S_OK; 439 } 440 441 HRESULT IPictureMeta::Render(HDC hdc, LONG x, LONG y, LONG cx, LONG cy, 442 OLE_XPOS_HIMETRIC xSrc, OLE_YPOS_HIMETRIC ySrc, 443 OLE_XSIZE_HIMETRIC cxSrc, OLE_YSIZE_HIMETRIC cySrc, 444 LPCRECT pRcWBounds) 445 { 446 return E_FAIL; 447 } 448 449 HRESULT IPictureMeta::set_hPal(OLE_HANDLE hPal) 450 { 451 return E_FAIL; 452 } 453 454 HRESULT IPictureMeta::SaveAsFile(LPSTREAM pStream, BOOL fSaveMemCopy, LONG * pCbSize) 455 { 456 return E_FAIL; 457 } 458 459 HRESULT IPictureMeta::get_Attributes(DWORD * pDwAttr) 460 { 461 *pDwAttr = PICTURE_SCALEABLE | PICTURE_TRANSPARENT; 462 return S_OK; 463 } 464 465 // ---------------------------------------------------------------------- 192 466 // IPictureImpl_QueryInterface 193 467 // ---------------------------------------------------------------------- … … 200 474 return 0; 201 475 202 dprintf(("OLEAUT32: IPictureImpl(%p)->Contructor( )\n", newObject));476 dprintf(("OLEAUT32: IPictureImpl(%p)->Contructor(fOwn = %d)\n", newObject, fOwn)); 203 477 204 478 // Initialise the vft's … … 213 487 // If a description is not passed then leave the picture uninitialised... 214 488 if (description == 0) 215 newObject-> sType = PICTYPE_NONE;489 newObject->pStrat = new IPictureNone(newObject); 216 490 else 217 491 { … … 225 499 { 226 500 case PICTYPE_BITMAP: 227 dprintf(("OLEAUT32: IPictureImpl(%p)->Constructor - Creating bitmap", newObject)); 228 229 newObject->sType = PICTYPE_BITMAP; 230 231 // Allocate picture from bitmap... 232 233 // newObject->description.u.bmp.hbitmap = description->u.bmp.hbitmap; 234 // newObject->description.u.bmp.hpal = description->u.bmp.hpal; 235 501 newObject->pStrat = new IPictureBmp( 502 newObject, 503 description->u.bmp.hbitmap, 504 description->u.bmp.hpal); 236 505 break; 237 506 238 507 case PICTYPE_METAFILE: 239 dprintf(("OLEAUT32: IPictureImpl(%p)->Constructor - Creating metafile", newObject)); 240 241 newObject->sType = PICTYPE_METAFILE; 242 243 // newObject->description.u.wmf.hmeta = description->u.wmf.hmeta; 244 // newObject->description.u.wmf.xExt = description->u.wmf.xExt; 245 // newObject->description.u.wmf.yExt = description->u.wmf.yExt; 508 newObject->pStrat = new IPictureMeta(newObject, 509 description->u.wmf.hmeta, 510 description->u.wmf.xExt, 511 description->u.wmf.yExt); 246 512 break; 247 513 248 514 case PICTYPE_ICON: 249 dprintf(("OLEAUT32: IPictureImpl(%p)->Constructor - Creating icon", newObject)); 250 251 newObject->sType = PICTYPE_ICON; 252 253 // newObject->description.u.icon.hicon = description->u.icon.hicon; 515 newObject->pStrat = new IPictureIcon(newObject, 516 description->u.icon.hicon); 254 517 break; 255 518 256 519 case PICTYPE_ENHMETAFILE: 257 dprintf(("OLEAUT32: IPictureImpl(%p)->Constructor - Creating enh metafile", newObject)); 258 newObject->sType = PICTYPE_ENHMETAFILE; 259 260 // newObject->description.u.emf.hemf = description->u.emf.hemf; 520 newObject->pStrat = new IPictureIcon(newObject, 521 description->u.emf.hemf); 261 522 break; 262 523 263 524 default: 264 525 // assume uninitialised... 265 dprintf(("OLEAUT32: IPictureImpl(%p)->Constructor - Creating uninitialised", newObject)); 266 newObject->sType = PICTYPE_NONE; 526 newObject->pStrat = new IPictureNone(newObject); 267 527 break; 268 528 } … … 278 538 { 279 539 dprintf(("OLEAUT32: IPictureImpl(%p)->Destructor()\n", obj)); 540 541 delete obj->pStrat; 280 542 281 543 HeapFree(GetProcessHeap(), 0, obj); … … 362 624 363 625 // Return the handle... 364 *pHandle = This->hPicture; 365 366 return S_OK; 626 return This->pStrat->get_Handle(pHandle); 367 627 } 368 628 … … 382 642 383 643 // Return the handle... 384 *phPal = This->hPal; 385 386 return S_OK; 644 return This->pStrat->get_hPal(phPal); 387 645 } 388 646 … … 402 660 403 661 // Return the type... 404 if (This->sType == PICTYPE_NONE) 405 *pType = PICTYPE_UNINITIALIZED; 406 else 407 *pType = This->sType; 408 409 return S_OK; 410 } 411 412 // ---------------------------------------------------------------------- 413 // 662 return This->pStrat->get_Type(pType); 663 } 664 665 // ---------------------------------------------------------------------- 666 // IPictureImpl_get_Width 414 667 // ---------------------------------------------------------------------- 415 668 static HRESULT WIN32API IPictureImpl_get_Width(LPPICTURE iface, … … 420 673 dprintf(("OLEAUT32: IPictureImpl(%p)->get_Width()", This)); 421 674 422 return E_NOTIMPL; 423 } 424 425 // ---------------------------------------------------------------------- 426 // 675 // Sanity check... 676 if (pWidth == 0) 677 return E_POINTER; 678 679 // Return the width... 680 return This->pStrat->get_Width(pWidth); 681 } 682 683 // ---------------------------------------------------------------------- 684 // IPictureImpl_get_Height 427 685 // ---------------------------------------------------------------------- 428 686 static HRESULT WIN32API IPictureImpl_get_Height(LPPICTURE iface, … … 433 691 dprintf(("OLEAUT32: IPictureImpl(%p)->get_Height()", This)); 434 692 435 return E_NOTIMPL; 436 } 437 438 // ---------------------------------------------------------------------- 439 // 693 // Sanity check... 694 if (pHeight == 0) 695 return E_POINTER; 696 697 // Return the height... 698 return This->pStrat->get_Height(pHeight); 699 } 700 701 // ---------------------------------------------------------------------- 702 // IPictureImpl_Render 440 703 // ---------------------------------------------------------------------- 441 704 static HRESULT WIN32API IPictureImpl_Render(LPPICTURE iface, … … 449 712 dprintf(("OLEAUT32: IPictureImpl(%p)->Render()", This)); 450 713 451 return E_NOTIMPL; 452 } 453 454 // ---------------------------------------------------------------------- 455 // 714 // Delegate... 715 return This->pStrat->Render(hdc, x, y, cx, cy, xSrc, ySrc, cxSrc, cySrc, pRcWBounds); 716 } 717 718 // ---------------------------------------------------------------------- 719 // IPictureImpl_set_hPal 456 720 // ---------------------------------------------------------------------- 457 721 static HRESULT WIN32API IPictureImpl_set_hPal(LPPICTURE iface, … … 462 726 dprintf(("OLEAUT32: IPictureImpl(%p)->set_hPal()", This)); 463 727 464 return E_NOTIMPL; 465 } 466 467 // ---------------------------------------------------------------------- 468 // 728 //Delegate... 729 return This->pStrat->set_hPal(hPal); 730 } 731 732 // ---------------------------------------------------------------------- 733 // IPictureImpl_get_CurDC 469 734 // ---------------------------------------------------------------------- 470 735 static HRESULT WIN32API IPictureImpl_get_CurDC(LPPICTURE iface, … … 475 740 dprintf(("OLEAUT32: IPictureImpl(%p)->get_CurDC()", This)); 476 741 477 return E_NOTIMPL; 478 } 479 480 // ---------------------------------------------------------------------- 481 // 742 // Sanity check 743 if (phDC == 0) 744 return E_POINTER; 745 746 // Return current hDC 747 *phDC = This->hCurDC; 748 749 return S_OK; 750 } 751 752 // ---------------------------------------------------------------------- 753 // IPictureImpl_SelectPicture 482 754 // ---------------------------------------------------------------------- 483 755 static HRESULT WIN32API IPictureImpl_SelectPicture(LPPICTURE iface, … … 486 758 _ICOM_THIS(IPictureImpl, iface); 487 759 488 dprintf(("OLEAUT32: IPictureImpl(%p)->SelectPicture() ", This));760 dprintf(("OLEAUT32: IPictureImpl(%p)->SelectPicture() - Stub", This)); 489 761 490 762 return E_NOTIMPL; … … 492 764 493 765 // ---------------------------------------------------------------------- 494 // 766 // IPictureImpl_get_KeepOriginalFormat 495 767 // ---------------------------------------------------------------------- 496 768 static HRESULT WIN32API IPictureImpl_get_KeepOriginalFormat(LPPICTURE iface, … … 512 784 513 785 // ---------------------------------------------------------------------- 514 // 786 // IPictureImpl_put_KeepOriginalFormat 515 787 // ---------------------------------------------------------------------- 516 788 static HRESULT WIN32API IPictureImpl_put_KeepOriginalFormat(LPPICTURE iface, … … 528 800 529 801 // ---------------------------------------------------------------------- 530 // 802 // IPictureImpl_PictureChanged 531 803 // ---------------------------------------------------------------------- 532 804 static HRESULT WIN32API IPictureImpl_PictureChanged(LPPICTURE iface) … … 540 812 541 813 // ---------------------------------------------------------------------- 542 // 814 // IPictureImpl_SaveAsFile 543 815 // ---------------------------------------------------------------------- 544 816 static HRESULT WIN32API IPictureImpl_SaveAsFile(LPPICTURE iface, … … 549 821 dprintf(("OLEAUT32: IPictureImpl(%p)->SaveAsFile()", This)); 550 822 551 return E_NOTIMPL; 552 } 553 554 // ---------------------------------------------------------------------- 555 // 823 //Delegate... 824 return This->pStrat->SaveAsFile(pStream, fSaveMemCopy, pCbSize); 825 } 826 827 // ---------------------------------------------------------------------- 828 // IPictureImpl_get_Attributes 556 829 // ---------------------------------------------------------------------- 557 830 static HRESULT WIN32API IPictureImpl_get_Attributes(LPPICTURE iface, … … 562 835 dprintf(("OLEAUT32: IPictureImpl(%p)->get_Attributes()", This)); 563 836 564 return E_NOTIMPL; 565 } 566 567 568 // ---------------------------------------------------------------------- 569 // 837 // Sanity check 838 if (pDwAttr == 0) 839 return E_POINTER; 840 841 //Delegate... 842 return This->pStrat->get_Attributes(pDwAttr); 843 } 844 845 846 // ---------------------------------------------------------------------- 847 // IPictureImpl_IDispatch_QueryInterface 570 848 // ---------------------------------------------------------------------- 571 849 static HRESULT WINAPI IPictureImpl_IDispatch_QueryInterface(LPDISPATCH iface, … … 578 856 579 857 // ---------------------------------------------------------------------- 580 // 858 // IPictureImpl_IDispatch_AddRef 581 859 // ---------------------------------------------------------------------- 582 860 static ULONG WINAPI IPictureImpl_IDispatch_AddRef(LPDISPATCH iface) … … 588 866 589 867 // ---------------------------------------------------------------------- 590 // 868 // IPictureImpl_IDispatch_Release 591 869 // ---------------------------------------------------------------------- 592 870 static ULONG WINAPI IPictureImpl_IDispatch_Release(LPDISPATCH iface)
Note:
See TracChangeset
for help on using the changeset viewer.