CEF4Delphi/source/uCEFPrintSettings.pas

240 lines
7.3 KiB
ObjectPascal
Raw Normal View History

2017-01-27 16:37:51 +01:00
// ************************************************************************
// ***************************** CEF4Delphi *******************************
// ************************************************************************
//
// CEF4Delphi is based on DCEF3 which uses CEF3 to embed a chromium-based
// browser in Delphi applications.
//
// The original license of DCEF3 still applies to CEF4Delphi.
//
// For more information about CEF4Delphi visit :
// https://www.briskbard.com/index.php?lang=en&pageid=cef
//
// Copyright <20> 2019 Salvador Diaz Fau. All rights reserved.
2017-01-27 16:37:51 +01:00
//
// ************************************************************************
// ************ vvvv Original license and comments below vvvv *************
// ************************************************************************
(*
* Delphi Chromium Embedded 3
*
* Usage allowed under the restrictions of the Lesser GNU General Public License
* or alternatively the restrictions of the Mozilla Public License 1.1
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* Unit owner : Henri Gourvest <hgourvest@gmail.com>
* Web site : http://www.progdigy.com
* Repository : http://code.google.com/p/delphichromiumembedded/
* Group : http://groups.google.com/group/delphichromiumembedded
*
* Embarcadero Technologies, Inc is not permitted to use or redistribute
* this source code without explicit permission.
*
*)
unit uCEFPrintSettings;
{$IFDEF FPC}
{$MODE OBJFPC}{$H+}
{$ENDIF}
{$IFNDEF CPUX64}{$ALIGN ON}{$ENDIF}
{$MINENUMSIZE 4}
2017-01-27 16:37:51 +01:00
2017-02-05 20:56:46 +01:00
{$I cef.inc}
2017-01-27 16:37:51 +01:00
interface
uses
uCEFBaseRefCounted, uCEFInterfaces, uCEFTypes;
2017-01-27 16:37:51 +01:00
type
TCefPrintSettingsRef = class(TCefBaseRefCountedRef, ICefPrintSettings)
2017-01-27 16:37:51 +01:00
protected
2018-03-29 20:02:04 +02:00
function IsValid: Boolean;
function IsReadOnly: Boolean;
function Copy: ICefPrintSettings;
2017-01-27 16:37:51 +01:00
procedure SetOrientation(landscape: Boolean);
2018-03-29 20:02:04 +02:00
function IsLandscape: Boolean;
procedure SetPrinterPrintableArea(const physicalSizeDeviceUnits: PCefSize; const printableAreaDeviceUnits: PCefRect; landscapeNeedsFlip: Boolean);
2017-01-27 16:37:51 +01:00
procedure SetDeviceName(const name: ustring);
2018-03-29 20:02:04 +02:00
function GetDeviceName: ustring;
2017-01-27 16:37:51 +01:00
procedure SetDpi(dpi: Integer);
2018-03-29 20:02:04 +02:00
function GetDpi: Integer;
2017-01-27 16:37:51 +01:00
procedure SetPageRanges(const ranges: TCefRangeArray);
2018-03-29 20:02:04 +02:00
function GetPageRangesCount: NativeUInt;
2017-01-27 16:37:51 +01:00
procedure GetPageRanges(out ranges: TCefRangeArray);
procedure SetSelectionOnly(selectionOnly: Boolean);
2018-03-29 20:02:04 +02:00
function IsSelectionOnly: Boolean;
2017-01-27 16:37:51 +01:00
procedure SetCollate(collate: Boolean);
2018-03-29 20:02:04 +02:00
function WillCollate: Boolean;
2017-01-27 16:37:51 +01:00
procedure SetColorModel(model: TCefColorModel);
2018-03-29 20:02:04 +02:00
function GetColorModel: TCefColorModel;
2017-01-27 16:37:51 +01:00
procedure SetCopies(copies: Integer);
2018-03-29 20:02:04 +02:00
function GetCopies: Integer;
2017-01-27 16:37:51 +01:00
procedure SetDuplexMode(mode: TCefDuplexMode);
2018-03-29 20:02:04 +02:00
function GetDuplexMode: TCefDuplexMode;
2017-01-27 16:37:51 +01:00
public
class function New: ICefPrintSettings;
class function UnWrap(data: Pointer): ICefPrintSettings;
end;
implementation
uses
uCEFMiscFunctions, uCEFLibFunctions;
function TCefPrintSettingsRef.Copy: ICefPrintSettings;
begin
Result := UnWrap(PCefPrintSettings(FData)^.copy(FData))
2017-01-27 16:37:51 +01:00
end;
function TCefPrintSettingsRef.GetColorModel: TCefColorModel;
begin
Result := PCefPrintSettings(FData)^.get_color_model(FData);
2017-01-27 16:37:51 +01:00
end;
function TCefPrintSettingsRef.GetCopies: Integer;
begin
Result := PCefPrintSettings(FData)^.get_copies(FData);
2017-01-27 16:37:51 +01:00
end;
function TCefPrintSettingsRef.GetDeviceName: ustring;
begin
Result := CefStringFreeAndGet(PCefPrintSettings(FData)^.get_device_name(FData));
2017-01-27 16:37:51 +01:00
end;
function TCefPrintSettingsRef.GetDpi: Integer;
begin
Result := PCefPrintSettings(FData)^.get_dpi(FData);
2017-01-27 16:37:51 +01:00
end;
function TCefPrintSettingsRef.GetDuplexMode: TCefDuplexMode;
begin
Result := PCefPrintSettings(FData)^.get_duplex_mode(FData);
2017-01-27 16:37:51 +01:00
end;
procedure TCefPrintSettingsRef.GetPageRanges(out ranges: TCefRangeArray);
2017-01-27 16:37:51 +01:00
var
TempLen : NativeUInt;
2017-01-27 16:37:51 +01:00
begin
TempLen := GetPageRangesCount;
SetLength(ranges, TempLen);
if (TempLen > 0) then PCefPrintSettings(FData)^.get_page_ranges(FData, @TempLen, @ranges[0]);
2017-01-27 16:37:51 +01:00
end;
function TCefPrintSettingsRef.GetPageRangesCount: NativeUInt;
begin
Result := PCefPrintSettings(FData)^.get_page_ranges_count(FData);
2017-01-27 16:37:51 +01:00
end;
function TCefPrintSettingsRef.IsLandscape: Boolean;
begin
Result := PCefPrintSettings(FData)^.is_landscape(FData) <> 0;
2017-01-27 16:37:51 +01:00
end;
function TCefPrintSettingsRef.IsReadOnly: Boolean;
begin
Result := PCefPrintSettings(FData)^.is_read_only(FData) <> 0;
2017-01-27 16:37:51 +01:00
end;
function TCefPrintSettingsRef.IsSelectionOnly: Boolean;
begin
Result := PCefPrintSettings(FData)^.is_selection_only(FData) <> 0;
2017-01-27 16:37:51 +01:00
end;
function TCefPrintSettingsRef.IsValid: Boolean;
begin
Result := PCefPrintSettings(FData)^.is_valid(FData) <> 0;
2017-01-27 16:37:51 +01:00
end;
class function TCefPrintSettingsRef.New: ICefPrintSettings;
begin
Result := UnWrap(cef_print_settings_create());
2017-01-27 16:37:51 +01:00
end;
procedure TCefPrintSettingsRef.SetCollate(collate: Boolean);
begin
PCefPrintSettings(FData)^.set_collate(FData, Ord(collate));
2017-01-27 16:37:51 +01:00
end;
procedure TCefPrintSettingsRef.SetColorModel(model: TCefColorModel);
begin
PCefPrintSettings(FData)^.set_color_model(FData, model);
2017-01-27 16:37:51 +01:00
end;
procedure TCefPrintSettingsRef.SetCopies(copies: Integer);
begin
PCefPrintSettings(FData)^.set_copies(FData, copies);
2017-01-27 16:37:51 +01:00
end;
procedure TCefPrintSettingsRef.SetDeviceName(const name: ustring);
var
TempName : TCefString;
2017-01-27 16:37:51 +01:00
begin
TempName := CefString(name);
PCefPrintSettings(FData)^.set_device_name(FData, @TempName);
2017-01-27 16:37:51 +01:00
end;
procedure TCefPrintSettingsRef.SetDpi(dpi: Integer);
begin
PCefPrintSettings(FData)^.set_dpi(FData, dpi);
2017-01-27 16:37:51 +01:00
end;
procedure TCefPrintSettingsRef.SetDuplexMode(mode: TCefDuplexMode);
begin
PCefPrintSettings(FData)^.set_duplex_mode(FData, mode);
2017-01-27 16:37:51 +01:00
end;
procedure TCefPrintSettingsRef.SetOrientation(landscape: Boolean);
begin
PCefPrintSettings(FData)^.set_orientation(FData, Ord(landscape));
2017-01-27 16:37:51 +01:00
end;
procedure TCefPrintSettingsRef.SetPageRanges(const ranges: TCefRangeArray);
2017-01-27 16:37:51 +01:00
var
TempLen : NativeUInt;
2017-01-27 16:37:51 +01:00
begin
TempLen := Length(ranges);
if (TempLen > 0) then
PCefPrintSettings(FData)^.set_page_ranges(FData, TempLen, @ranges[0])
else
PCefPrintSettings(FData)^.set_page_ranges(FData, 0, nil);
2017-01-27 16:37:51 +01:00
end;
procedure TCefPrintSettingsRef.SetPrinterPrintableArea(const physicalSizeDeviceUnits : PCefSize;
const printableAreaDeviceUnits : PCefRect;
landscapeNeedsFlip : Boolean);
2017-01-27 16:37:51 +01:00
begin
PCefPrintSettings(FData)^.set_printer_printable_area(FData,
physicalSizeDeviceUnits,
printableAreaDeviceUnits,
Ord(landscapeNeedsFlip));
2017-01-27 16:37:51 +01:00
end;
procedure TCefPrintSettingsRef.SetSelectionOnly(selectionOnly: Boolean);
begin
PCefPrintSettings(FData)^.set_selection_only(FData, Ord(selectionOnly));
2017-01-27 16:37:51 +01:00
end;
class function TCefPrintSettingsRef.UnWrap(data: Pointer): ICefPrintSettings;
2017-01-27 16:37:51 +01:00
begin
if (data <> nil) then
Result := Create(data) as ICefPrintSettings
else
2017-01-27 16:37:51 +01:00
Result := nil;
end;
function TCefPrintSettingsRef.WillCollate: Boolean;
begin
Result := PCefPrintSettings(FData)^.will_collate(FData) <> 0;
2017-01-27 16:37:51 +01:00
end;
end.