#include "libcef_dll/cpptoc/print_settings_cpptoc.h"
#include <algorithm>
#include "libcef_dll/shutdown_checker.h"
CEF_EXPORT cef_print_settings_t* cef_print_settings_create() {
shutdown_checker::AssertNotShutdown();
CefRefPtr<CefPrintSettings> _retval = CefPrintSettings::Create();
return CefPrintSettingsCppToC::Wrap(_retval);
}
namespace {
int CEF_CALLBACK print_settings_is_valid(struct _cef_print_settings_t* self) {
shutdown_checker::AssertNotShutdown();
DCHECK(self);
if (!self)
return 0;
bool _retval = CefPrintSettingsCppToC::Get(self)->IsValid();
return _retval;
}
int CEF_CALLBACK
print_settings_is_read_only(struct _cef_print_settings_t* self) {
shutdown_checker::AssertNotShutdown();
DCHECK(self);
if (!self)
return 0;
bool _retval = CefPrintSettingsCppToC::Get(self)->IsReadOnly();
return _retval;
}
void CEF_CALLBACK
print_settings_set_orientation(struct _cef_print_settings_t* self,
int landscape) {
shutdown_checker::AssertNotShutdown();
DCHECK(self);
if (!self)
return;
CefPrintSettingsCppToC::Get(self)->SetOrientation(landscape ? true : false);
}
int CEF_CALLBACK
print_settings_is_landscape(struct _cef_print_settings_t* self) {
shutdown_checker::AssertNotShutdown();
DCHECK(self);
if (!self)
return 0;
bool _retval = CefPrintSettingsCppToC::Get(self)->IsLandscape();
return _retval;
}
void CEF_CALLBACK print_settings_set_printer_printable_area(
struct _cef_print_settings_t* self,
const cef_size_t* physical_size_device_units,
const cef_rect_t* printable_area_device_units,
int landscape_needs_flip) {
shutdown_checker::AssertNotShutdown();
DCHECK(self);
if (!self)
return;
DCHECK(physical_size_device_units);
if (!physical_size_device_units)
return;
DCHECK(printable_area_device_units);
if (!printable_area_device_units)
return;
CefSize physical_size_device_unitsVal =
physical_size_device_units ? *physical_size_device_units : CefSize();
CefRect printable_area_device_unitsVal =
printable_area_device_units ? *printable_area_device_units : CefRect();
CefPrintSettingsCppToC::Get(self)->SetPrinterPrintableArea(
physical_size_device_unitsVal, printable_area_device_unitsVal,
landscape_needs_flip ? true : false);
}
void CEF_CALLBACK
print_settings_set_device_name(struct _cef_print_settings_t* self,
const cef_string_t* name) {
shutdown_checker::AssertNotShutdown();
DCHECK(self);
if (!self)
return;
CefPrintSettingsCppToC::Get(self)->SetDeviceName(CefString(name));
}
cef_string_userfree_t CEF_CALLBACK
print_settings_get_device_name(struct _cef_print_settings_t* self) {
shutdown_checker::AssertNotShutdown();
DCHECK(self);
if (!self)
return NULL;
CefString _retval = CefPrintSettingsCppToC::Get(self)->GetDeviceName();
return _retval.DetachToUserFree();
}
void CEF_CALLBACK print_settings_set_dpi(struct _cef_print_settings_t* self,
int dpi) {
shutdown_checker::AssertNotShutdown();
DCHECK(self);
if (!self)
return;
CefPrintSettingsCppToC::Get(self)->SetDPI(dpi);
}
int CEF_CALLBACK print_settings_get_dpi(struct _cef_print_settings_t* self) {
shutdown_checker::AssertNotShutdown();
DCHECK(self);
if (!self)
return 0;
int _retval = CefPrintSettingsCppToC::Get(self)->GetDPI();
return _retval;
}
void CEF_CALLBACK
print_settings_set_page_ranges(struct _cef_print_settings_t* self,
size_t rangesCount,
cef_range_t const* ranges) {
shutdown_checker::AssertNotShutdown();
DCHECK(self);
if (!self)
return;
DCHECK(rangesCount == 0 || ranges);
if (rangesCount > 0 && !ranges)
return;
std::vector<CefRange> rangesList;
if (rangesCount > 0) {
for (size_t i = 0; i < rangesCount; ++i) {
CefRange rangesVal = ranges[i];
rangesList.push_back(rangesVal);
}
}
CefPrintSettingsCppToC::Get(self)->SetPageRanges(rangesList);
}
size_t CEF_CALLBACK
print_settings_get_page_ranges_count(struct _cef_print_settings_t* self) {
shutdown_checker::AssertNotShutdown();
DCHECK(self);
if (!self)
return 0;
size_t _retval = CefPrintSettingsCppToC::Get(self)->GetPageRangesCount();
return _retval;
}
void CEF_CALLBACK
print_settings_get_page_ranges(struct _cef_print_settings_t* self,
size_t* rangesCount,
cef_range_t* ranges) {
shutdown_checker::AssertNotShutdown();
DCHECK(self);
if (!self)
return;
DCHECK(rangesCount && (*rangesCount == 0 || ranges));
if (!rangesCount || (*rangesCount > 0 && !ranges))
return;
std::vector<CefRange> rangesList;
if (rangesCount && *rangesCount > 0 && ranges) {
for (size_t i = 0; i < *rangesCount; ++i) {
rangesList.push_back(ranges[i]);
}
}
CefPrintSettingsCppToC::Get(self)->GetPageRanges(rangesList);
if (rangesCount && ranges) {
*rangesCount = std::min(rangesList.size(), *rangesCount);
if (*rangesCount > 0) {
for (size_t i = 0; i < *rangesCount; ++i) {
ranges[i] = rangesList[i];
}
}
}
}
void CEF_CALLBACK
print_settings_set_selection_only(struct _cef_print_settings_t* self,
int selection_only) {
shutdown_checker::AssertNotShutdown();
DCHECK(self);
if (!self)
return;
CefPrintSettingsCppToC::Get(self)->SetSelectionOnly(selection_only ? true
: false);
}
int CEF_CALLBACK
print_settings_is_selection_only(struct _cef_print_settings_t* self) {
shutdown_checker::AssertNotShutdown();
DCHECK(self);
if (!self)
return 0;
bool _retval = CefPrintSettingsCppToC::Get(self)->IsSelectionOnly();
return _retval;
}
void CEF_CALLBACK print_settings_set_collate(struct _cef_print_settings_t* self,
int collate) {
shutdown_checker::AssertNotShutdown();
DCHECK(self);
if (!self)
return;
CefPrintSettingsCppToC::Get(self)->SetCollate(collate ? true : false);
}
int CEF_CALLBACK
print_settings_will_collate(struct _cef_print_settings_t* self) {
shutdown_checker::AssertNotShutdown();
DCHECK(self);
if (!self)
return 0;
bool _retval = CefPrintSettingsCppToC::Get(self)->WillCollate();
return _retval;
}
void CEF_CALLBACK
print_settings_set_color_model(struct _cef_print_settings_t* self,
cef_color_model_t model) {
shutdown_checker::AssertNotShutdown();
DCHECK(self);
if (!self)
return;
CefPrintSettingsCppToC::Get(self)->SetColorModel(model);
}
cef_color_model_t CEF_CALLBACK
print_settings_get_color_model(struct _cef_print_settings_t* self) {
shutdown_checker::AssertNotShutdown();
DCHECK(self);
if (!self)
return COLOR_MODEL_UNKNOWN;
cef_color_model_t _retval =
CefPrintSettingsCppToC::Get(self)->GetColorModel();
return _retval;
}
void CEF_CALLBACK print_settings_set_copies(struct _cef_print_settings_t* self,
int copies) {
shutdown_checker::AssertNotShutdown();
DCHECK(self);
if (!self)
return;
CefPrintSettingsCppToC::Get(self)->SetCopies(copies);
}
int CEF_CALLBACK print_settings_get_copies(struct _cef_print_settings_t* self) {
shutdown_checker::AssertNotShutdown();
DCHECK(self);
if (!self)
return 0;
int _retval = CefPrintSettingsCppToC::Get(self)->GetCopies();
return _retval;
}
void CEF_CALLBACK
print_settings_set_duplex_mode(struct _cef_print_settings_t* self,
cef_duplex_mode_t mode) {
shutdown_checker::AssertNotShutdown();
DCHECK(self);
if (!self)
return;
CefPrintSettingsCppToC::Get(self)->SetDuplexMode(mode);
}
cef_duplex_mode_t CEF_CALLBACK
print_settings_get_duplex_mode(struct _cef_print_settings_t* self) {
shutdown_checker::AssertNotShutdown();
DCHECK(self);
if (!self)
return DUPLEX_MODE_UNKNOWN;
cef_duplex_mode_t _retval =
CefPrintSettingsCppToC::Get(self)->GetDuplexMode();
return _retval;
}
}
CefPrintSettingsCppToC::CefPrintSettingsCppToC() {
GetStruct()->is_valid = print_settings_is_valid;
GetStruct()->is_read_only = print_settings_is_read_only;
GetStruct()->set_orientation = print_settings_set_orientation;
GetStruct()->is_landscape = print_settings_is_landscape;
GetStruct()->set_printer_printable_area =
print_settings_set_printer_printable_area;
GetStruct()->set_device_name = print_settings_set_device_name;
GetStruct()->get_device_name = print_settings_get_device_name;
GetStruct()->set_dpi = print_settings_set_dpi;
GetStruct()->get_dpi = print_settings_get_dpi;
GetStruct()->set_page_ranges = print_settings_set_page_ranges;
GetStruct()->get_page_ranges_count = print_settings_get_page_ranges_count;
GetStruct()->get_page_ranges = print_settings_get_page_ranges;
GetStruct()->set_selection_only = print_settings_set_selection_only;
GetStruct()->is_selection_only = print_settings_is_selection_only;
GetStruct()->set_collate = print_settings_set_collate;
GetStruct()->will_collate = print_settings_will_collate;
GetStruct()->set_color_model = print_settings_set_color_model;
GetStruct()->get_color_model = print_settings_get_color_model;
GetStruct()->set_copies = print_settings_set_copies;
GetStruct()->get_copies = print_settings_get_copies;
GetStruct()->set_duplex_mode = print_settings_set_duplex_mode;
GetStruct()->get_duplex_mode = print_settings_get_duplex_mode;
}
CefPrintSettingsCppToC::~CefPrintSettingsCppToC() {
shutdown_checker::AssertNotShutdown();
}
template <>
CefRefPtr<CefPrintSettings> CefCppToCRefCounted<
CefPrintSettingsCppToC,
CefPrintSettings,
cef_print_settings_t>::UnwrapDerived(CefWrapperType type,
cef_print_settings_t* s) {
NOTREACHED() << "Unexpected class type: " << type;
return nullptr;
}
template <>
CefWrapperType CefCppToCRefCounted<CefPrintSettingsCppToC,
CefPrintSettings,
cef_print_settings_t>::kWrapperType =
WT_PRINT_SETTINGS;