Project JEDI - Issue Tracker
Mantis Bugtracker

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0002587 [JEDI VCL] 00 JVCL Components minor always 2005-02-02 08:11 2005-03-01 13:34
Reporter CCR View Status public  
Assigned To remkobonte
Priority normal Resolution fixed  
Status resolved   Product Version
Summary 0002587: Replace TJvCustomRichEdit.InsertBitmap with TJvCustomRichEdit.InsertGraphic, like this...
Description With TImageDataObject do this:
1) Remove GetExtent, as it's a bit pointless.
2) Replace FBitmap: TBitmap with FGraphic: TGraphic,
   and alter the constructor to fit.
3) Rewrite GetData to be the following:

function TImageDataObject.GetData(const FormatEtcIn: TFormatEtc;
  out Medium: TStgMedium): HRESULT;
var
  SizeMetric: TPoint;
  Buffer: Pointer;
  Length: UINT;
  DC: HDC;
  hMF: HMETAFILE;
  hMem: THandle;
  pMFP: PMetafilePict;
begin
  // Handle only MetaFile
  if (FormatEtcIn.tymed and TYMED_MFPICT) = 0 then
  begin
    Result := DV_E_FORMATETC;
    Exit;
  end;
  if FGraphic is TMetafile then //Get a Win3x-style HMETAFILE handle
    with TMetafile(FGraphic) do //from a HENHMETAFILE one.
    begin
      SizeMetric.X := MMWidth;
      SizeMetric.Y := MMHeight;
      Buffer := nil;
      Length := 0;
      DC := GetDC(0);
      try
        Length := GetWinMetaFileBits(Handle, 0, nil, MM_ANISOTROPIC, DC);
        GetMem(Buffer, Length);
        if GetWinMetaFileBits(Handle, Length, Buffer,
             MM_ANISOTROPIC, DC) = Length then
          hMF := SetMetaFileBitsEx(Length, Buffer)
        else
          hMF := 0;
      finally
        if Buffer <> nil then FreeMem(Buffer, Length);
        ReleaseDC(0, DC);
      end;
    end
  else
  begin
    SizeMetric.X := MulDiv(FGraphic.Width,
      CHundredthMMPerInch, Screen.PixelsPerInch);
    SizeMetric.Y := MulDiv(FGraphic.Height,
      CHundredthMMPerInch, Screen.PixelsPerInch);
    // Create Metafile DC and set it up
    DC := CreateMetafile(nil);
    SetWindowOrgEx(DC, 0, 0, nil);
    SetWindowExtEx(DC, SizeMetric.X, SizeMetric.Y, nil);

    if FGraphic.ClassType = TIcon then
      DrawIconEx(DC, 0, 0, TIcon(FGraphic).Handle, SizeMetric.X, SizeMetric.Y,
        0, 0, DI_NORMAL)
    else
      with TCanvas.Create do
      try
        Handle := DC;
        StretchDraw(Rect(0, 0, SizeMetric.X, SizeMetric.Y), FGraphic);
      finally
        Free;
      end;
    hMF := CloseMetaFile(DC);
  end;
  if hMF = 0 then
  begin
    Result := E_UNEXPECTED;
    Exit;
  end;
  // Get memory handle
  hMem := GlobalAlloc(GMEM_SHARE or GMEM_MOVEABLE, SizeOf(METAFILEPICT));
  if hMem = 0 then
  begin
    DeleteMetaFile(hMF);
    Result := STG_E_MEDIUMFULL;
    Exit;
  end;
  pMFP := PMetafilePict(GlobalLock(hMem));
  pMFP^.hMF := hMF;
  pMFP^.mm := MM_ANISOTROPIC;
  pMFP^.xExt := SizeMetric.X;
  pMFP^.yExt := SizeMetric.Y;
  GlobalUnlock(hMem);

  Medium.tymed := TYMED_MFPICT;
  Medium.hGlobal := hMem;
  Medium.unkForRelease := nil;

  Result := S_OK;
end;

Finally, in TJvCustomRichEdit rename InsertBitmap to InsertGraphic, update the method's parameter from Bitmap: TBitmap to AGraphic: TGraphic, and send AGraphic instead of ABitmap to TImageDataObject.Create.
Additional Information
Tags No tags attached.
Attached Files

- Relationships

-  Notes
(0006348)
obones (administrator)
2005-02-03 00:41

What's the point of this change?
(0006412)
CCR (reporter)
2005-02-04 20:31

To allow sizeable metafiles (e.g. the clipart one gets with MS Office) to be inserted as sizeable metafiles. As in, copy a metafile to a bitmap first, and when enlarged it will become distorted. Hence, allow it to be inserted directly as itself (so to speak), and the user can then resize it without distortion.

The suggested change also allows the direct insertion of JPEG pictures, of course.
(0006625)
remkobonte (developer)
2005-03-01 13:34

Thanks, this is now in CVS.

- Issue History
Date Modified Username Field Change
2005-02-02 08:11 CCR New Issue
2005-02-03 00:41 obones Note Added: 0006348
2005-02-03 00:41 obones Status new => feedback
2005-02-04 20:31 CCR Note Added: 0006412
2005-03-01 13:34 remkobonte Status feedback => resolved
2005-03-01 13:34 remkobonte Fixed in Version => 3.00
2005-03-01 13:34 remkobonte Resolution open => fixed
2005-03-01 13:34 remkobonte Assigned To => remkobonte
2005-03-01 13:34 remkobonte Note Added: 0006625


Mantis 1.1.6[^]
Copyright © 2000 - 2008 Mantis Group
Powered by Mantis Bugtracker