Slight change to behaviour of default preview window
Hi folks,
just wondered if there was a simple way to slightly modify the
behaviour of the standard print preview dialog. We have a kiosk-type
application and usually there's no mouse to hand. In an ideal world,
I'd like to modify the standard previewer so that "ESCAPE" fired the
close button and "RETURN" fired the print button.
Can that be done in a few lines of code, or am I looking at writing our
own custom viewer?
Sorry for the lame question, historically I'm more of a ReportBuilder
end-user than a programmer.
Delphi 7, RB v7.03 professional, incidentally.
Many thanks
--
Rob
just wondered if there was a simple way to slightly modify the
behaviour of the standard print preview dialog. We have a kiosk-type
application and usually there's no mouse to hand. In an ideal world,
I'd like to modify the standard previewer so that "ESCAPE" fired the
close button and "RETURN" fired the print button.
Can that be done in a few lines of code, or am I looking at writing our
own custom viewer?
Sorry for the lame question, historically I'm more of a ReportBuilder
end-user than a programmer.
Delphi 7, RB v7.03 professional, incidentally.
Many thanks
--
Rob
This discussion has been closed.
Comments
With the recent plugin architecture of the Report Previewer, it is very
simple to add or remove custom functionality to the preview window. All you
need to do is create a simple descendent to the TppPreview class and
register it using the TppPreviewPlugin class. Fortunately I have an example
that closes the preview when the ESC button is pressed. This should get you
on the right track for any other functionality you would like to add. Hope
this helps.
http://www.digital-metaphors.com/tips/PreviewCloseOnEscape.zip
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
fine. I'll have a nose around and see if I can coax the Return key into
working too.
Many thanks for your quick response!
the return key is that the Cancel button seems to have focus, so by
default pressing return seems to close the dialog.
All we have done is to trap the return key in the same manner as Nico
(sorry I misspelt your name before Nico) suggested, then in the
BeforePreview event we call the "FocusToKeyCatcher" method. Crude, but
effective.
Should anyone find this useful, here's our unit:
unit u_AmberPrintPreviewPlugIn;
interface
uses
Classes, Windows, ppPreview, ppTypes;
type
TAmberPrintPreviewPlugin = class(TppPreview)
protected
procedure CreateToolbarControls; override;
public
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure BeforePreview; override;
end;
implementation
uses
dialogs, controls;
procedure TAmberPrintPreviewPlugin.CreateToolbarControls;
begin
inherited;
// just forcing cancel button to behave way we want it to
CancelButton.OnKeyDown := KeyDownEvent;
CancelButton.Cancel:=true;
end;
procedure TAmberPrintPreviewPlugin.KeyDown(var Key: Word; Shift:
TShiftState);
begin
inherited KeyDown(Key, Shift);
case Key of
VK_RETURN:
begin
PerformPreviewAction(paPrint);
PerformPreviewAction(paClose);
key:=0;
end;
VK_ESCAPE:
begin
PerformPreviewAction(paClose);
key:=0;
end;
end;
end;
procedure TAmberPrintPreviewPlugin.BeforePreview;
begin
inherited BeforePreview;
self.FocusToKeyCatcher; // take focus away from "cancel" button
end;
initialization
// causes all print previews in the project to come through here
TppPreviewPlugIn.Register(TAmberPrintPreviewPlugin);
finalization
TppPreviewPlugIn.UnRegister(TAmberPrintPreviewPlugin);
end.
Cheers
Rob