diff --git a/win-linux/src/cprintdata.cpp b/win-linux/src/cprintdata.cpp index 0f68d3a92..ae1f88c6c 100644 --- a/win-linux/src/cprintdata.cpp +++ b/win-linux/src/cprintdata.cpp @@ -135,6 +135,9 @@ class CPrintData::CPrintDataPrivate pages_count = data->get_PagesCount(); current_page = data->get_CurrentPage(); + print_range = QPrintDialog::AllPages; + page_from = 1; + page_to = pages_count; parseJsonOptions(data->get_Options()); } diff --git a/win-linux/src/platform_linux/gtkprintdialog.cpp b/win-linux/src/platform_linux/gtkprintdialog.cpp index ca9d84a70..49574f05a 100644 --- a/win-linux/src/platform_linux/gtkprintdialog.cpp +++ b/win-linux/src/platform_linux/gtkprintdialog.cpp @@ -4,6 +4,7 @@ #include "gtkprintdialog.h" #include #include +#include "components/cmessage.h" #define PDF_PRINTER_NAME "Print to File" #define LPR_PRINTER_NAME "Print to LPR" @@ -65,6 +66,7 @@ GtkPrintDialog::GtkPrintDialog(QPrinter *printer, QWidget *parent) : if (m_printer->collateCopies()) m_options |= PrintOption::PrintCollateCopies; m_page_ranges.append(PageRanges(m_printer->fromPage(), m_printer->toPage())); + m_pages_count = m_printer->toPage(); } GtkPrintDialog::~GtkPrintDialog() @@ -445,7 +447,14 @@ int GtkPrintDialog::toPage() void GtkPrintDialog::setFromTo(int from, int to) { - m_printer->setFromTo(from, to); + from < 1 && (from = 1); to < 1 && (to = 1); + if (m_pages_count < from || m_pages_count < to) { + CMessage::warning(m_parent, QObject::tr("Specified range %1-%2 exceeds document limits: maximum number of pages is %3") + .arg(QString::number(from), QString::number(to), QString::number(m_pages_count))); + } + from > m_pages_count && (from = m_pages_count); + to > m_pages_count && (to = m_pages_count); + m_printer->setFromTo(from > to ? to : from, from > to ? from : to); if (!m_page_ranges.isEmpty()) m_page_ranges.clear(); m_page_ranges.append(PageRanges(m_printer->fromPage(), m_printer->toPage())); diff --git a/win-linux/src/platform_linux/gtkprintdialog.h b/win-linux/src/platform_linux/gtkprintdialog.h index f88d0de81..4476d558e 100644 --- a/win-linux/src/platform_linux/gtkprintdialog.h +++ b/win-linux/src/platform_linux/gtkprintdialog.h @@ -39,6 +39,7 @@ class GtkPrintDialog PrintOptions m_options; PrintRange m_print_range; QVector m_page_ranges; + int m_pages_count; }; #endif // GTKPRINTDIALOG_H diff --git a/win-linux/src/platform_win/printdialog.cpp b/win-linux/src/platform_win/printdialog.cpp index 31068f830..6d788a832 100644 --- a/win-linux/src/platform_win/printdialog.cpp +++ b/win-linux/src/platform_win/printdialog.cpp @@ -32,8 +32,10 @@ #include #include +#include #include "printdialog.h" #include "utils.h" +#include "components/cmessage.h" #define MAXPAGERANGES 32 #define PRINT_DIALOG_REG_KEY L"Software\\Microsoft\\Print\\UnifiedPrintDialog\0" @@ -352,7 +354,8 @@ QDialog::DialogCode PrintDialog::exec() dlg.lpCallback = static_cast(&clb); QDialog::DialogCode exit_code = QDialog::DialogCode::Rejected; - if (PrintDlgEx(&dlg) == S_OK) { + HRESULT hr = PrintDlgEx(&dlg); + if (hr == S_OK) { switch (dlg.dwResultAction) { case PD_RESULT_PRINT: { LPDEVMODE pDevmode = (LPDEVMODE)GlobalLock(dlg.hDevMode); @@ -410,6 +413,9 @@ QDialog::DialogCode PrintDialog::exec() #endif if (pDevMode) GlobalFree(pDevMode); + + const wchar_t *err = _com_error(hr).ErrorMessage(); + CMessage::error(m_parent, QObject::tr("Unable to open print dialog:
%1").arg(QString::fromStdWString(err))); } GlobalFree(page_ranges); @@ -448,7 +454,14 @@ int PrintDialog::toPage() void PrintDialog::setFromTo(int from, int to) { - m_printer->setFromTo(from, to); + from < 1 && (from = 1); to < 1 && (to = 1); + if (m_pages_count < from || m_pages_count < to) { + CMessage::warning(m_parent, QObject::tr("Specified range %1-%2 exceeds document limits: maximum number of pages is %3") + .arg(QString::number(from), QString::number(to), QString::number(m_pages_count))); + } + from > m_pages_count && (from = m_pages_count); + to > m_pages_count && (to = m_pages_count); + m_printer->setFromTo(from > to ? to : from, from > to ? from : to); if (!m_page_ranges.isEmpty()) m_page_ranges.clear(); m_page_ranges.append(PageRanges(m_printer->fromPage(), m_printer->toPage())); diff --git a/win-linux/src/windows/ceditorwindow_p.h b/win-linux/src/windows/ceditorwindow_p.h index c74d022de..7c4a0f16a 100644 --- a/win-linux/src/windows/ceditorwindow_p.h +++ b/win-linux/src/windows/ceditorwindow_p.h @@ -477,8 +477,9 @@ class CEditorWindowPrivate : public CCefEventsGate if ( isPrinting ) return; isPrinting = true; + QWidget *parent = window->handle(); #ifdef Q_OS_LINUX - WindowHelper::CParentDisable oDisabler(window->handle()); + WindowHelper::CParentDisable oDisabler(parent); #endif if ( !(pagescount < 1) ) { CAscMenuEvent * pEvent; @@ -583,7 +584,8 @@ class CEditorWindowPrivate : public CCefEventsGate #ifndef _WIN32 RELEASEOBJECT(dialog) #endif - } + } else + CMessage::warning(parent, tr("There are no pages set to print.")); isPrinting = false; } @@ -755,7 +757,7 @@ class CEditorWindowPrivate : public CCefEventsGate void onWebAppsFeatures(int, std::wstring f) override { - bool is_read_only = panel()->data()->hasFeature(L"readonly\":"); + bool is_read_only = panel()->data()->hasFeature(L"readonly\":true"); panel()->data()->setFeatures(f); if ( m_panel->data()->hasFeature(L"uitype\":\"fillform") ) { diff --git a/win-linux/src/windows/cmainwindow.cpp b/win-linux/src/windows/cmainwindow.cpp index 43b675d7f..9daf52c7d 100644 --- a/win-linux/src/windows/cmainwindow.cpp +++ b/win-linux/src/windows/cmainwindow.cpp @@ -1063,8 +1063,9 @@ void CMainWindow::onDocumentPrint(void * opts) printInProcess = true; else return; + QWidget *parent = qobject_cast(this); #ifdef Q_OS_LINUX - WindowHelper::CParentDisable disabler(qobject_cast(this)); + WindowHelper::CParentDisable disabler(parent); #endif CCefView * pView = AscAppManager::getInstance().GetViewById(AscAppManager::printData().viewId()); @@ -1177,7 +1178,8 @@ void CMainWindow::onDocumentPrint(void * opts) #ifndef _WIN32 RELEASEOBJECT(dialog) #endif - } + } else + CMessage::warning(parent, tr("There are no pages set to print.")); printInProcess = false; // RELEASEINTERFACE(pData)