Jacek Caban : mshtml: Set default print template in exec_print.

Alexandre Julliard julliard at wine.codeweavers.com
Thu Dec 14 07:03:45 CST 2006


Module: wine
Branch: master
Commit: cc6e4e2525a8adf8506ffe5427590dde415b93c5
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=cc6e4e2525a8adf8506ffe5427590dde415b93c5

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Thu Dec 14 00:21:50 2006 +0100

mshtml: Set default print template in exec_print.

---

 dlls/mshtml/olecmd.c   |  125 +++++++++++++++++++++++++++++++++++++++++++++++-
 dlls/mshtml/resource.h |    3 +
 2 files changed, 127 insertions(+), 1 deletions(-)

diff --git a/dlls/mshtml/olecmd.c b/dlls/mshtml/olecmd.c
index 1e78f66..8de5e0d 100644
--- a/dlls/mshtml/olecmd.c
+++ b/dlls/mshtml/olecmd.c
@@ -37,6 +37,7 @@
 #include "wine/unicode.h"
 
 #include "mshtml_private.h"
+#include "resource.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
 
@@ -95,10 +96,126 @@ static HRESULT exec_save_copy_as(HTMLDoc
     return E_NOTIMPL;
 }
 
+static nsresult set_head_text(nsIPrintSettings *settings, LPCWSTR template, BOOL head, int pos)
+{
+    if(head) {
+        switch(pos) {
+        case 0:
+            return nsIPrintSettings_SetHeaderStrLeft(settings, template);
+        case 1:
+            return nsIPrintSettings_SetHeaderStrRight(settings, template);
+        case 2:
+            return nsIPrintSettings_SetHeaderStrCenter(settings, template);
+        }
+    }else {
+        switch(pos) {
+        case 0:
+            return nsIPrintSettings_SetFooterStrLeft(settings, template);
+        case 1:
+            return nsIPrintSettings_SetFooterStrRight(settings, template);
+        case 2:
+            return nsIPrintSettings_SetFooterStrCenter(settings, template);
+        }
+    }
+
+    return NS_OK;
+}
+
+static void set_print_template(nsIPrintSettings *settings, LPCWSTR template, BOOL head)
+{
+    PRUnichar nstemplate[200]; /* FIXME: Use dynamic allocation */
+    PRUnichar *p = nstemplate;
+    LPCWSTR ptr=template;
+    int pos=0;
+
+    while(*ptr) {
+        if(*ptr != '&') {
+            *p++ = *ptr++;
+            continue;
+        }
+
+        switch(*++ptr) {
+        case '&':
+            *p++ = '&';
+            *p++ = '&';
+            ptr++;
+            break;
+        case 'b': /* change align */
+            ptr++;
+            *p = 0;
+            set_head_text(settings, nstemplate, head, pos);
+            p = nstemplate;
+            pos++;
+            break;
+        case 'd': { /* short date */
+            SYSTEMTIME systime;
+            GetLocalTime(&systime);
+            GetDateFormatW(LOCALE_SYSTEM_DEFAULT, 0, &systime, NULL, p,
+                    sizeof(nstemplate)-(p-nstemplate)*sizeof(WCHAR));
+            p += strlenW(p);
+            ptr++;
+            break;
+        }
+        case 'p': /* page number */
+            *p++ = '&';
+            *p++ = 'P';
+            ptr++;
+            break;
+        case 'P': /* page count */
+            *p++ = '?'; /* FIXME */
+            ptr++;
+            break;
+        case 'u':
+            *p++ = '&';
+            *p++ = 'U';
+            ptr++;
+            break;
+        case 'w':
+            /* FIXME: set window title */
+            ptr++;
+            break;
+        default:
+            *p++ = '&';
+            *p++ = *ptr++;
+        }
+    }
+
+    *p = 0;
+    set_head_text(settings, nstemplate, head, pos);
+
+    while(++pos < 3)
+        set_head_text(settings, p, head, pos);
+}
+
+static void set_default_templates(nsIPrintSettings *settings)
+{
+    WCHAR buf[64];
+
+    static const PRUnichar empty[] = {0};
+
+    nsIPrintSettings_SetHeaderStrLeft(settings, empty);
+    nsIPrintSettings_SetHeaderStrRight(settings, empty);
+    nsIPrintSettings_SetHeaderStrCenter(settings, empty);
+    nsIPrintSettings_SetFooterStrLeft(settings, empty);
+    nsIPrintSettings_SetFooterStrRight(settings, empty);
+    nsIPrintSettings_SetFooterStrCenter(settings, empty);
+
+    if(LoadStringW(get_shdoclc(), IDS_PRINT_HEADER_TEMPLATE, buf,
+                   sizeof(buf)/sizeof(WCHAR)))
+        set_print_template(settings, buf, TRUE);
+
+
+    if(LoadStringW(get_shdoclc(), IDS_PRINT_FOOTER_TEMPLATE, buf,
+                   sizeof(buf)/sizeof(WCHAR)))
+        set_print_template(settings, buf, FALSE);
+
+}
+
 static HRESULT exec_print(HTMLDocument *This, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
 {
     nsIInterfaceRequestor *iface_req;
     nsIWebBrowserPrint *nsprint;
+    nsIPrintSettings *settings;
     nsresult nsres;
 
     TRACE("(%p)->(%d %p %p)\n", This, nCmdexecopt, pvaIn, pvaOut);
@@ -126,7 +243,13 @@ static HRESULT exec_print(HTMLDocument *
         return S_OK;
     }
 
-    nsres = nsIWebBrowserPrint_Print(nsprint, NULL, NULL);
+    nsres = nsIWebBrowserPrint_GetGlobalPrintSettings(nsprint, &settings);
+    if(NS_FAILED(nsres))
+        ERR("GetCurrentPrintSettings failed: %08x\n", nsres);
+
+    set_default_templates(settings);
+
+    nsres = nsIWebBrowserPrint_Print(nsprint, settings, NULL);
     if(NS_FAILED(nsres))
         ERR("Print failed: %08x\n", nsres);
 
diff --git a/dlls/mshtml/resource.h b/dlls/mshtml/resource.h
index 5dfbc42..27dae83 100644
--- a/dlls/mshtml/resource.h
+++ b/dlls/mshtml/resource.h
@@ -28,6 +28,9 @@
 
 #define IDS_MESSAGE_BOX_TITLE  2213
 
+#define IDS_PRINT_HEADER_TEMPLATE  8403
+#define IDS_PRINT_FOOTER_TEMPLATE  8404
+
 #define IDR_BROWSE_CONTEXT_MENU  24641
 
 #define IDM_TRACETAGS           6004




More information about the wine-cvs mailing list