bug 275883 - Fixes printing on mac and linux without xprint. r1=ssitter,r2=jminta

This commit is contained in:
mattwillis%gmail.com 2006-08-23 23:38:24 +00:00
Родитель 06d244cd3c
Коммит 8925b0ccd1
8 изменённых файлов: 195 добавлений и 125 удалений

Просмотреть файл

@ -559,14 +559,15 @@
<!-- Calendar Printing --> <!-- Calendar Printing -->
<!ENTITY calendar.print.window.title "Print A Calendar"> <!ENTITY calendar.print.window.title "Print A Calendar">
<!ENTITY calendar.print.title.label "Title"> <!ENTITY calendar.print.title.label "Title:">
<!ENTITY calendar.print.layout.label "Layout"> <!ENTITY calendar.print.layout.label "Layout:">
<!ENTITY calendar.print.range.label "Range to print"> <!ENTITY calendar.print.range.label "What to Print">
<!ENTITY calendar.print.currentview.label "Events in current view"> <!ENTITY calendar.print.currentview.label "Events in current view">
<!ENTITY calendar.print.selected.label "Selected events"> <!ENTITY calendar.print.selected.label "Selected events">
<!ENTITY calendar.print.custom.label "Custom:"> <!ENTITY calendar.print.custom.label "Custom date range:">
<!ENTITY calendar.print.from.label "From:"> <!ENTITY calendar.print.from.label "From:">
<!ENTITY calendar.print.to.label "To:"> <!ENTITY calendar.print.to.label "To:">
<!ENTITY calendar.print.settingsGroup.label "Print Settings">
<!-- Error reporting --> <!-- Error reporting -->
<!ENTITY calendar.error.detail "Details..."> <!ENTITY calendar.error.detail "Details...">

Просмотреть файл

@ -39,6 +39,7 @@
AllDayEvents=All Day Events AllDayEvents=All Day Events
PrintPreviewWindowTitle=Print Preview of %1$S PrintPreviewWindowTitle=Print Preview of %1$S
Untitled=Untitled
# Default name for new events # Default name for new events
newEvent=New Event newEvent=New Event

Просмотреть файл

@ -436,12 +436,6 @@ function closeCalendar()
self.close(); self.close();
} }
function calPrint()
{
window.openDialog("chrome://calendar/content/printDialog.xul",
"printdialog","chrome");
}
/* Change the only-workday checkbox */ /* Change the only-workday checkbox */
function changeOnlyWorkdayCheckbox() { function changeOnlyWorkdayCheckbox() {
var oldValue = (document.getElementById("toggle_workdays_only") var oldValue = (document.getElementById("toggle_workdays_only")

Просмотреть файл

@ -531,3 +531,12 @@ function setDefaultAlarmValues(aItem)
} }
} }
} }
/**
* Opens the print dialog
*/
function calPrint()
{
window.openDialog("chrome://calendar/content/printDialog.xul", "Print",
"centerscreen,chrome,resizable");
}

Просмотреть файл

@ -26,6 +26,7 @@
* Chris Allen * Chris Allen
* Eric Belhaire <belhaire@ief.u-psud.fr> * Eric Belhaire <belhaire@ief.u-psud.fr>
* Michiel van Leeuwen <mvl@exedo.nl> * Michiel van Leeuwen <mvl@exedo.nl>
* Matthew Willis <mattwillis@gmail.com>
* *
* Alternatively, the contents of this file may be used under the terms of * Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or * either the GNU General Public License Version 2 or later (the "GPL"), or
@ -41,40 +42,17 @@
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
var gTempFile = null;
/***** calendar/printDialog.js
* PRIMARY AUTHOR
* Chris Allen
*
* NOTES
* Code for the calendar's print dialog.
*
* IMPLEMENTATION NOTES
**********
*/
var gPrintSettings = null; var gPrintSettings = null;
var gCalendarWindow = window.opener.gCalendarWindow; var gCalendarWindow = window.opener.gCalendarWindow;
/*-----------------------------------------------------------------
* W I N D O W F U N C T I O N S
*/
/*-----------------------------------------------------------------
* Called when the dialog is loaded.
*/
function loadCalendarPrintDialog() function loadCalendarPrintDialog()
{ {
// set the date to the currently selected date // set the datepickers to the currently selected dates
document.getElementById("start-date-picker").value = var theView = window.opener.currentView();
window.opener.document.getElementById("view-deck").selectedPanel.startDay.jsDate; document.getElementById("start-date-picker").value = theView.startDay.jsDate;
document.getElementById("end-date-picker").value = document.getElementById("end-date-picker").value = theView.endDay.jsDate;
window.opener.document.getElementById("view-deck").selectedPanel.endDay.jsDate;
// start focus on title
var firstFocus = document.getElementById( "title-field" ).focus();
// Get a list of formatters // Get a list of formatters
var contractids = new Array(); var contractids = new Array();
@ -82,36 +60,48 @@ function loadCalendarPrintDialog()
.getService(Components.interfaces.nsICategoryManager); .getService(Components.interfaces.nsICategoryManager);
var catenum = catman.enumerateCategory('cal-print-formatters'); var catenum = catman.enumerateCategory('cal-print-formatters');
// Walk the list, adding item to the layout menupopup // Walk the list, adding items to the layout menupopup
var layoutList = document.getElementById("layout-field"); var layoutList = document.getElementById("layout-field");
while (catenum.hasMoreElements()) { while (catenum.hasMoreElements()) {
var entry = catenum.getNext(); var entry = catenum.getNext();
entry = entry.QueryInterface(Components.interfaces.nsISupportsCString); entry = entry.QueryInterface(Components.interfaces.nsISupportsCString);
var contractid = catman.getCategoryEntry('cal-print-formatters', entry); var contractid = catman.getCategoryEntry('cal-print-formatters', entry);
var formatter = Components.classes[contractid] var formatter = Components.classes[contractid]
.getService(Components.interfaces.calIPrintFormatter); .getService(Components.interfaces.calIPrintFormatter);
// Use the contractid as value // Use the contractid as value
layoutList.appendItem(formatter.name, contractid); layoutList.appendItem(formatter.name, contractid);
} }
layoutList.selectedIndex = 0; layoutList.selectedIndex = 0;
opener.setCursor( "auto" ); opener.setCursor("auto");
refreshHtml();
self.focus(); self.focus();
} }
function unloadCalendarPrintDialog()
{
gTempFile.remove(false);
}
function printCalendar() { /**
* Gets the settings from the dialog's UI widgets.
* @returns an Object with title, layoutCId, eventList, start, and end
* properties containing the appropriate values.
*/
function getDialogSettings()
{
var settings = new Object();
var ccalendar = window.opener.getCompositeCalendar(); var ccalendar = window.opener.getCompositeCalendar();
var start;
var end;
var eventList;
var listener = { var listener = {
mEventArray: new Array(), mEventArray: new Array(),
onOperationComplete: function (aCalendar, aStatus, aOperationType, aId, aDateTime) { onOperationComplete: function (aCalendar, aStatus, aOperationType, aId, aDateTime) {
printInitWindow(listener.mEventArray, start, end); settings.eventList = listener.mEventArray;
settings.start = start;
settings.end = end;
}, },
onGetResult: function (aCalendar, aStatus, aItemType, aDetail, aCount, aItems) { onGetResult: function (aCalendar, aStatus, aItemType, aDetail, aCount, aItems) {
@ -126,16 +116,18 @@ function printCalendar() {
var start; var start;
var end; var end;
var eventList;
switch (document.getElementById("view-field").selectedItem.value) { switch (document.getElementById("view-field").selectedItem.value) {
case 'currentview': case 'currentview':
case '': //just in case case '': //just in case
start = window.opener.document.getElementById("view-deck").selectedPanel.startDay; var theView = window.opener.currentView();
end = window.opener.document.getElementById("view-deck").selectedPanel.endDay; start = theView.startDay;
end = theView.endDay;
break; break;
case 'selected' : case 'selected':
eventList = gCalendarWindow.EventSelection.selectedEvents; eventList = gCalendarWindow.EventSelection.selectedEvents;
break; break;
case 'custom' : case 'custom':
start = jsDateToDateTime(document.getElementById("start-date-picker").value); start = jsDateToDateTime(document.getElementById("start-date-picker").value);
end = jsDateToDateTime(document.getElementById("end-date-picker").value); end = jsDateToDateTime(document.getElementById("end-date-picker").value);
break ; break ;
@ -149,29 +141,73 @@ function printCalendar() {
end.normalize(); end.normalize();
ccalendar.getItems(filter, 0, start, end, listener); ccalendar.getItems(filter, 0, start, end, listener);
} else { } else {
printInitWindow(eventList, null, null); settings.eventList = eventList;
settings.start = null;
settings.end = null;
} }
var tempTitle = document.getElementById("title-field").value;
settings.title = (tempTitle || calGetString("calendar", "Untitled"));
settings.layoutCId = document.getElementById("layout-field").value;
return settings;
} }
function printInitWindow(aEventList, aStart, aEnd) { /**
var args = new Object(); * Looks at the selections the user has made (start date, layout, etc.), and
args.title = document.getElementById("title-field").value; * updates the HTML in the iframe accordingly. This is also called when a
args.layoutContractid = document.getElementById("layout-field").value; * dialog UI element has changed, since we'll want to refresh the preview.
args.eventList = aEventList;
args.start = aStart;
args.end = aEnd;
window.openDialog("chrome://calendar/content/calPrintEngine.xul",
"CalendarPrintWindow",
"chrome,dialog=no,all,centerscreen",
args);
}
/*-----------------------------------------------------------------
* Called when a datepicker is finished, and a date was picked.
*/ */
function refreshHtml()
{
var settings = getDialogSettings();
// I'd like to use calGetString, but it can't do "formatStringFromName".
var sbs = Components.classes["@mozilla.org/intl/stringbundle;1"]
.getService(Components.interfaces.nsIStringBundleService);
var props = sbs.createBundle("chrome://calendar/locale/calendar.properties");
document.title = props.formatStringFromName("PrintPreviewWindowTitle",
[settings.title], 1);
var printformatter = Components.classes[settings.layoutCId]
.createInstance(Components.interfaces.calIPrintFormatter);
// Fail-safe check to not init twice, to prevent leaking files
if (gTempFile) {
gTempFile.remove(false);
}
const nsIFile = Components.interfaces.nsIFile;
var dirService = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties);
gTempFile = dirService.get("TmpD", nsIFile);
gTempFile.append("calendarPrint.html");
gTempFile.createUnique(nsIFile.NORMAL_FILE_TYPE, 0600); // 0600 = -rw-------
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var tempUri = ioService.newFileURI(gTempFile);
var stream = Components.classes["@mozilla.org/network/file-output-stream;1"]
.createInstance(Components.interfaces.nsIFileOutputStream);
try {
// 0x2A = PR_TRUNCATE, PR_CREATE_FILE, PR_WRONLY
// 0600 = -rw-------
stream.init(gTempFile, 0x2A, 0600, 0);
printformatter.formatToHtml(stream, settings.start, settings.end,
settings.eventList.length,
settings.eventList, settings.title);
stream.close();
} catch (e) {
dump("printDialog::refreshHtml:"+e+"\n");
}
document.getElementById("content").contentWindow.location = gTempUri.spec;
}
/**
* Called when once a date has been selected in the datepicker.
*/
function onDatePick() { function onDatePick() {
radioGroupSelectItem("view-field", "custom-range"); radioGroupSelectItem("view-field", "custom-range");
refreshHtml();
} }

Просмотреть файл

@ -25,6 +25,7 @@
- Chris Charabaruk <ccharabaruk@meldstar.com> - Chris Charabaruk <ccharabaruk@meldstar.com>
- ArentJan Banck <ajbanck@planet.nl> - ArentJan Banck <ajbanck@planet.nl>
- Chris Allen <chris@netinflux.com> - Chris Allen <chris@netinflux.com>
- Matthew Willis <mattwillis@gmail.com>
- -
- Alternatively, the contents of this file may be used under the terms of - Alternatively, the contents of this file may be used under the terms of
- either the GNU General Public License Version 2 or later (the "GPL"), or - either the GNU General Public License Version 2 or later (the "GPL"), or
@ -54,6 +55,7 @@
[ [
<!ENTITY % dtd1 SYSTEM "chrome://calendar/locale/global.dtd" > %dtd1; <!ENTITY % dtd1 SYSTEM "chrome://calendar/locale/global.dtd" > %dtd1;
<!ENTITY % dtd2 SYSTEM "chrome://calendar/locale/calendar.dtd" > %dtd2; <!ENTITY % dtd2 SYSTEM "chrome://calendar/locale/calendar.dtd" > %dtd2;
<!ENTITY % dtd3 SYSTEM "chrome://calendar/locale/menuOverlay.dtd"> %dtd3;
]> ]>
@ -61,63 +63,99 @@
id="calendar-new-printwindow" id="calendar-new-printwindow"
title="&calendar.print.window.title;" title="&calendar.print.window.title;"
onload="loadCalendarPrintDialog()" onload="loadCalendarPrintDialog()"
onunload="unloadCalendarPrintDialog()"
buttons="accept,cancel" buttons="accept,cancel"
ondialogaccept="printCalendar()" buttonlabelaccept="&calendar.print.button.label;"
buttonaccesskeyaccept="&calendar.print.accesskey;"
defaultButton="accept"
ondialogaccept="PrintUtils.print();"
ondialogcancel="return true;" ondialogcancel="return true;"
persist="screenX screenY" persist="screenX screenY width height"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
xmlns:nc="http://home.netscape.com/NC-rdf#"> xmlns:nc="http://home.netscape.com/NC-rdf#">
<script type="application/x-javascript" src="chrome://calendar/content/printDialog.js"/> <script type="application/x-javascript" src="chrome://calendar/content/printDialog.js"/>
<script type="application/x-javascript" src="chrome://calendar/content/applicationUtil.js"/> <script type="application/x-javascript" src="chrome://calendar/content/applicationUtil.js"/>
<script type="application/x-javascript" src="chrome://calendar/content/calendarUtils.js"/> <script type="application/x-javascript" src="chrome://calendar/content/calendarUtils.js"/>
<script type="application/x-javascript" src="chrome://global/content/printUtils.js"/>
<vbox id="standard-dialog-content" flex="1"> <hbox id="firstHbox" flex="1">
<grid> <vbox id="groupboxVbox">
<columns>
<column />
<column flex="1"/>
</columns>
<rows> <groupbox id="settingsGroup">
<!-- Title --> <caption label="&calendar.print.settingsGroup.label;"/>
<row align="center">
<hbox class="field-label-box-class">
<label for="title-field" value="&calendar.print.title.label;"/>
</hbox>
<textbox id="title-field"/>
</row>
<!-- Layout --> <grid>
<row align="center"> <columns>
<hbox class="field-label-box-class"> <column/>
<label for="title-field" value="&calendar.print.layout.label;"/> <column flex="1"/>
</hbox> </columns>
<menulist id="layout-field">
<!-- menupopup will be filled in printDialog.js -->
<menupopup id="layout-menulist-menupopup"/>
</menulist>
</row>
</rows>
</grid>
<groupbox> <rows>
<caption label="&calendar.print.range.label;"/> <row align="center">
<radiogroup id="view-field" > <label class="field-label-box-class"
<radio label="&calendar.print.currentview.label;" control="title-field"
value="currentview" value="&calendar.print.title.label;"/>
selected="true" /> <textbox id="title-field"
<radio id="selected" label="&calendar.print.selected.label;" class="padded"
value="selected"/> flex="1"
<radio id="custom-range" label="&calendar.print.custom.label;" onchange="refreshHtml();"/>
value="custom"/> </row>
<hbox align="center"> <row align="center">
<label value="&calendar.print.from.label;"/> <label class="field-label-box-class"
<datepicker id="start-date-picker" onchange="onDatePick();"/> control="layout-field"
<label value="&calendar.print.to.label;"/> value="&calendar.print.layout.label;"/>
<datepicker id="end-date-picker" onchange="onDatePick();"/> <hbox>
</hbox> <menulist id="layout-field">
</radiogroup> <!-- This menupopup will be populated by printDialog.js -->
</groupbox> <menupopup id="layout-menulist-menupopup"
</vbox> oncommand="refreshHtml();"/>
</menulist>
<spacer flex="1"/>
</hbox>
</row>
</rows>
</grid>
</groupbox>
<groupbox id="whatToPrintGroup">
<caption label="&calendar.print.range.label;"/>
<radiogroup id="view-field" oncommand="refreshHtml();">
<radio id="printCurrentViewRadio"
label="&calendar.print.currentview.label;"
value="currentview" selected="true" />
<radio id="selected" label="&calendar.print.selected.label;"
value="selected"/>
<radio id="custom-range" label="&calendar.print.custom.label;"
value="custom"/>
<grid>
<columns>
<column/>
<column flex="1"/>
</columns>
<rows>
<row align="center">
<label class="field-label-box-class"
control="start-date-picker"
value="&calendar.print.from.label;"/>
<datepicker id="start-date-picker" onchange="onDatePick();"/>
</row>
<row align="center">
<label class="field-label-box-class"
control="end-date-picker"
value="&calendar.print.to.label;"/>
<datepicker id="end-date-picker" onchange="onDatePick();"/>
</row>
</rows>
</grid>
</radiogroup>
</groupbox>
</vbox>
<splitter/>
<iframe src="about:blank" id="content" flex="1"
style="border: 2px solid #3c3c3c; width:30em; height:30em;"/>
</hbox>
</dialog> </dialog>

Просмотреть файл

@ -35,9 +35,6 @@ calendar.jar:
content/calendar/calendarWindow.js (content/calendarWindow.js) content/calendar/calendarWindow.js (content/calendarWindow.js)
content/calendar/calErrorPrompt.xul (/calendar/base/content/calErrorPrompt.xul) content/calendar/calErrorPrompt.xul (/calendar/base/content/calErrorPrompt.xul)
content/calendar/chooseCalendarDialog.xul (/calendar/base/content/chooseCalendarDialog.xul) content/calendar/chooseCalendarDialog.xul (/calendar/base/content/chooseCalendarDialog.xul)
content/calendar/calPrintEngine.js (content/calPrintEngine.js)
content/calendar/calPrintEngine.xul (content/calPrintEngine.xul)
content/calendar/calPrintEngine.css (content/calPrintEngine.css)
content/calendar/calendarCreation.xul (content/calendarCreation.xul) content/calendar/calendarCreation.xul (content/calendarCreation.xul)
content/calendar/calendarCreation.js (content/calendarCreation.js) content/calendar/calendarCreation.js (content/calendarCreation.js)
content/calendar/calendarProperties.xul (content/calendarProperties.xul) content/calendar/calendarProperties.xul (content/calendarProperties.xul)

Просмотреть файл

@ -35,12 +35,6 @@
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
/* the main content of the dialog */
#standard-dialog-content
{
padding: 10px;
}
#calendar-serverwindow #calendar-serverwindow
{ {
width: 60em; width: 60em;