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 -->
<!ENTITY calendar.print.window.title "Print A Calendar">
<!ENTITY calendar.print.title.label "Title">
<!ENTITY calendar.print.layout.label "Layout">
<!ENTITY calendar.print.range.label "Range to print">
<!ENTITY calendar.print.title.label "Title:">
<!ENTITY calendar.print.layout.label "Layout:">
<!ENTITY calendar.print.range.label "What to Print">
<!ENTITY calendar.print.currentview.label "Events in current view">
<!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.to.label "To:">
<!ENTITY calendar.print.settingsGroup.label "Print Settings">
<!-- Error reporting -->
<!ENTITY calendar.error.detail "Details...">

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

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

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

@ -436,12 +436,6 @@ function closeCalendar()
self.close();
}
function calPrint()
{
window.openDialog("chrome://calendar/content/printDialog.xul",
"printdialog","chrome");
}
/* Change the only-workday checkbox */
function changeOnlyWorkdayCheckbox() {
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
* Eric Belhaire <belhaire@ief.u-psud.fr>
* Michiel van Leeuwen <mvl@exedo.nl>
* Matthew Willis <mattwillis@gmail.com>
*
* 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
@ -41,40 +42,17 @@
*
* ***** END LICENSE BLOCK ***** */
/***** calendar/printDialog.js
* PRIMARY AUTHOR
* Chris Allen
*
* NOTES
* Code for the calendar's print dialog.
*
* IMPLEMENTATION NOTES
**********
*/
var gTempFile = null;
var gPrintSettings = null;
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()
{
// set the date to the currently selected date
document.getElementById("start-date-picker").value =
window.opener.document.getElementById("view-deck").selectedPanel.startDay.jsDate;
document.getElementById("end-date-picker").value =
window.opener.document.getElementById("view-deck").selectedPanel.endDay.jsDate;
// start focus on title
var firstFocus = document.getElementById( "title-field" ).focus();
// set the datepickers to the currently selected dates
var theView = window.opener.currentView();
document.getElementById("start-date-picker").value = theView.startDay.jsDate;
document.getElementById("end-date-picker").value = theView.endDay.jsDate;
// Get a list of formatters
var contractids = new Array();
@ -82,36 +60,48 @@ function loadCalendarPrintDialog()
.getService(Components.interfaces.nsICategoryManager);
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");
while (catenum.hasMoreElements()) {
var entry = catenum.getNext();
entry = entry.QueryInterface(Components.interfaces.nsISupportsCString);
var contractid = catman.getCategoryEntry('cal-print-formatters', entry);
var formatter = Components.classes[contractid]
.getService(Components.interfaces.calIPrintFormatter);
.getService(Components.interfaces.calIPrintFormatter);
// Use the contractid as value
layoutList.appendItem(formatter.name, contractid);
}
layoutList.selectedIndex = 0;
opener.setCursor( "auto" );
opener.setCursor("auto");
refreshHtml();
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 start;
var end;
var eventList;
var listener = {
mEventArray: new Array(),
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) {
@ -126,16 +116,18 @@ function printCalendar() {
var start;
var end;
var eventList;
switch (document.getElementById("view-field").selectedItem.value) {
case 'currentview':
case '': //just in case
start = window.opener.document.getElementById("view-deck").selectedPanel.startDay;
end = window.opener.document.getElementById("view-deck").selectedPanel.endDay;
var theView = window.opener.currentView();
start = theView.startDay;
end = theView.endDay;
break;
case 'selected' :
case 'selected':
eventList = gCalendarWindow.EventSelection.selectedEvents;
break;
case 'custom' :
case 'custom':
start = jsDateToDateTime(document.getElementById("start-date-picker").value);
end = jsDateToDateTime(document.getElementById("end-date-picker").value);
break ;
@ -149,29 +141,73 @@ function printCalendar() {
end.normalize();
ccalendar.getItems(filter, 0, start, end, listener);
} 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();
args.title = document.getElementById("title-field").value;
args.layoutContractid = document.getElementById("layout-field").value;
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.
/**
* Looks at the selections the user has made (start date, layout, etc.), and
* updates the HTML in the iframe accordingly. This is also called when a
* dialog UI element has changed, since we'll want to refresh the preview.
*/
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() {
radioGroupSelectItem("view-field", "custom-range");
refreshHtml();
}

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

@ -25,6 +25,7 @@
- Chris Charabaruk <ccharabaruk@meldstar.com>
- ArentJan Banck <ajbanck@planet.nl>
- Chris Allen <chris@netinflux.com>
- Matthew Willis <mattwillis@gmail.com>
-
- 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
@ -54,6 +55,7 @@
[
<!ENTITY % dtd1 SYSTEM "chrome://calendar/locale/global.dtd" > %dtd1;
<!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"
title="&calendar.print.window.title;"
onload="loadCalendarPrintDialog()"
onunload="unloadCalendarPrintDialog()"
buttons="accept,cancel"
ondialogaccept="printCalendar()"
buttonlabelaccept="&calendar.print.button.label;"
buttonaccesskeyaccept="&calendar.print.accesskey;"
defaultButton="accept"
ondialogaccept="PrintUtils.print();"
ondialogcancel="return true;"
persist="screenX screenY"
persist="screenX screenY width height"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
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/applicationUtil.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">
<grid>
<columns>
<column />
<column flex="1"/>
</columns>
<hbox id="firstHbox" flex="1">
<vbox id="groupboxVbox">
<rows>
<!-- Title -->
<row align="center">
<hbox class="field-label-box-class">
<label for="title-field" value="&calendar.print.title.label;"/>
</hbox>
<textbox id="title-field"/>
</row>
<groupbox id="settingsGroup">
<caption label="&calendar.print.settingsGroup.label;"/>
<!-- Layout -->
<row align="center">
<hbox class="field-label-box-class">
<label for="title-field" value="&calendar.print.layout.label;"/>
</hbox>
<menulist id="layout-field">
<!-- menupopup will be filled in printDialog.js -->
<menupopup id="layout-menulist-menupopup"/>
</menulist>
</row>
</rows>
</grid>
<grid>
<columns>
<column/>
<column flex="1"/>
</columns>
<groupbox>
<caption label="&calendar.print.range.label;"/>
<radiogroup id="view-field" >
<radio 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"/>
<hbox align="center">
<label value="&calendar.print.from.label;"/>
<datepicker id="start-date-picker" onchange="onDatePick();"/>
<label value="&calendar.print.to.label;"/>
<datepicker id="end-date-picker" onchange="onDatePick();"/>
</hbox>
</radiogroup>
</groupbox>
</vbox>
<rows>
<row align="center">
<label class="field-label-box-class"
control="title-field"
value="&calendar.print.title.label;"/>
<textbox id="title-field"
class="padded"
flex="1"
onchange="refreshHtml();"/>
</row>
<row align="center">
<label class="field-label-box-class"
control="layout-field"
value="&calendar.print.layout.label;"/>
<hbox>
<menulist id="layout-field">
<!-- This menupopup will be populated by printDialog.js -->
<menupopup id="layout-menulist-menupopup"
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>

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

@ -35,9 +35,6 @@ calendar.jar:
content/calendar/calendarWindow.js (content/calendarWindow.js)
content/calendar/calErrorPrompt.xul (/calendar/base/content/calErrorPrompt.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.js (content/calendarCreation.js)
content/calendar/calendarProperties.xul (content/calendarProperties.xul)

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

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