|
|
@@ -8,9 +8,16 @@ unit BGRADialogs;
|
|
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
|
|
+{$ifdef WINDOWS}
|
|
|
+ //{$define Show_PreviewControl} //THIS IS JUST FOR TESTING, It is not recommended for now under Windows
|
|
|
+{$endif}
|
|
|
+
|
|
|
interface
|
|
|
|
|
|
uses
|
|
|
+ {$ifdef Show_PreviewControl}
|
|
|
+ Windows, Graphics,
|
|
|
+ {$endif}
|
|
|
Classes, SysUtils, ExtDlgs, Controls, StdCtrls, ExtCtrls,
|
|
|
BGRABitmapTypes, BCRoundedImage;
|
|
|
|
|
|
@@ -18,6 +25,9 @@ resourcestring
|
|
|
rsSelectAPreviewFile = 'Select the File to preview';
|
|
|
|
|
|
type
|
|
|
+
|
|
|
+ { TBGRAOpenPictureDialog }
|
|
|
+
|
|
|
TBGRAOpenPictureDialog = class(TPreviewFileDialog)
|
|
|
private
|
|
|
FDefaultFilter: string;
|
|
|
@@ -27,12 +37,22 @@ type
|
|
|
FPreviewFilename: string;
|
|
|
|
|
|
protected
|
|
|
+ {$ifdef Show_PreviewControl}
|
|
|
+ DialogWnd,
|
|
|
+ pParentWnd, pBrotherWnd : HWnd;
|
|
|
+ {$endif}
|
|
|
+
|
|
|
class procedure WSRegisterClass; override;
|
|
|
function IsFilterStored: Boolean; virtual;
|
|
|
procedure InitPreviewControl; override;
|
|
|
procedure ClearPreview; virtual;
|
|
|
procedure UpdatePreview; virtual;
|
|
|
|
|
|
+ {$ifdef Show_PreviewControl}
|
|
|
+ procedure GetDialogWnd;
|
|
|
+ procedure ResizePreviewControl;
|
|
|
+ {$endif}
|
|
|
+
|
|
|
property ImageCtrl: TBCRoundedImage read FImageCtrl;
|
|
|
property PicturePanel: TPanel read FPicturePanel;
|
|
|
property PictureDetails: TLabel read FPictureDetails;
|
|
|
@@ -69,7 +89,8 @@ procedure Register;
|
|
|
|
|
|
implementation
|
|
|
|
|
|
-uses WSExtDlgs, Masks, FileUtil, LazFileUtils, LCLStrConsts, LCLType;
|
|
|
+uses
|
|
|
+ WSExtDlgs, Masks, FileUtil, LazFileUtils, LCLStrConsts, LCLType;
|
|
|
|
|
|
function GetBGRAFormatFilter(AFormat: TBGRAImageFormat): String;
|
|
|
begin
|
|
|
@@ -144,8 +165,8 @@ end;
|
|
|
|
|
|
procedure TBGRAOpenPictureDialog.DoClose;
|
|
|
begin
|
|
|
- ClearPreview;
|
|
|
inherited DoClose;
|
|
|
+// PreviewFileControl.ParentWindow:=0;
|
|
|
end;
|
|
|
|
|
|
procedure TBGRAOpenPictureDialog.DoSelectionChange;
|
|
|
@@ -197,7 +218,13 @@ procedure TBGRAOpenPictureDialog.UpdatePreview;
|
|
|
var
|
|
|
CurFilename: String;
|
|
|
FileIsValid: boolean;
|
|
|
+
|
|
|
begin
|
|
|
+ {$ifdef Show_PreviewControl}
|
|
|
+ if (DialogWnd = 0) then GetDialogWnd;
|
|
|
+ ResizePreviewControl;
|
|
|
+ {$endif}
|
|
|
+
|
|
|
FPicturePanel.Caption:= '';
|
|
|
FPictureDetails.Caption:='';
|
|
|
|
|
|
@@ -221,6 +248,63 @@ begin
|
|
|
if not FileIsValid then ClearPreview;
|
|
|
end;
|
|
|
|
|
|
+{$ifdef Show_PreviewControl}
|
|
|
+procedure TBGRAOpenPictureDialog.GetDialogWnd;
|
|
|
+var
|
|
|
+ pHandle: HWND;
|
|
|
+ thID, prID, appID:DWord;
|
|
|
+
|
|
|
+begin
|
|
|
+ pBrotherWnd:= 0;
|
|
|
+ pParentWnd:= 0;
|
|
|
+
|
|
|
+ //LCL doesn't pass us the Dialog Handle, so we have to look for it the old fashioned way
|
|
|
+ appID:= GetProcessId;
|
|
|
+ repeat
|
|
|
+ DialogWnd:= FindWindowEx(0, DialogWnd, PChar('#32770'), nil);
|
|
|
+ thID:= GetWindowThreadProcessId(DialogWnd, prID);
|
|
|
+ until (DialogWnd=0) or (prID = appID);
|
|
|
+
|
|
|
+ //Get Parent and Brother Control
|
|
|
+ // this depends on the OS and needs to be tested as much as possible (for now it works with Windows 10)
|
|
|
+ if (DialogWnd<>0) then
|
|
|
+ begin
|
|
|
+ pHandle:= FindWindowEx(DialogWnd, 0, PChar('DUIViewWndClassName'), nil);
|
|
|
+ if (pHandle<>0) then //Windows 10
|
|
|
+ begin
|
|
|
+ pParentWnd:= FindWindowEx(pHandle, 0, PChar('DirectUIHWND'), nil);
|
|
|
+ if (pParentWnd<>0) then
|
|
|
+ begin
|
|
|
+ repeat
|
|
|
+ pBrotherWnd:= FindWindowEx(pParentWnd, pBrotherWnd, PChar('CtrlNotifySink'), nil);
|
|
|
+ pHandle:= FindWindowEx(pBrotherWnd, 0, PChar('SHELLDLL_DefView'), nil);
|
|
|
+ until (pBrotherWnd=0) or (pHandle<>0);
|
|
|
+
|
|
|
+ if (pBrotherWnd<>0) and (pHandle<>0) then PreviewFileControl.ParentWindow:=pParentWnd;
|
|
|
+ end;
|
|
|
+ end;
|
|
|
+ end;
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TBGRAOpenPictureDialog.ResizePreviewControl;
|
|
|
+var
|
|
|
+ rectParent, rectBrother: TRect;
|
|
|
+
|
|
|
+begin
|
|
|
+ if (DialogWnd<>0) and (pParentWnd<>0) and (pBrotherWnd<>0) then
|
|
|
+ begin
|
|
|
+ if GetClientRect(pParentWnd, rectParent) and GetWindowRect(pBrotherWnd, rectBrother) then
|
|
|
+ begin
|
|
|
+ ScreenToClient(pParentWnd, rectBrother.TopLeft);
|
|
|
+ ScreenToClient(pParentWnd, rectBrother.BottomRight);
|
|
|
+ PreviewFileControl.SetBounds(rectBrother.Left+4+rectBrother.Width, rectBrother.Top+4,
|
|
|
+ rectParent.Right-rectBrother.Right-8,
|
|
|
+ rectParent.Bottom-rectBrother.Top-8);
|
|
|
+ end;
|
|
|
+ end;
|
|
|
+end;
|
|
|
+{$endif}
|
|
|
+
|
|
|
constructor TBGRAOpenPictureDialog.Create(TheOwner: TComponent);
|
|
|
begin
|
|
|
inherited Create(TheOwner);
|
|
|
@@ -228,6 +312,12 @@ begin
|
|
|
Format(rsAllFiles,[GetAllFilesMask, GetAllFilesMask,'']);
|
|
|
Filter:=FDefaultFilter;
|
|
|
|
|
|
+ {$ifdef Show_PreviewControl}
|
|
|
+ DialogWnd:= 0;
|
|
|
+ pBrotherWnd:= 0;
|
|
|
+ pParentWnd:= 0;
|
|
|
+ {$endif}
|
|
|
+
|
|
|
FPicturePanel:=TPanel.Create(Self);
|
|
|
with FPicturePanel do begin
|
|
|
Name:='FPicturePanel';
|