aboutsummaryrefslogtreecommitdiffstats
path: root/embed/mozilla/MozillaPrivate.cpp
blob: daa3e284db377ecdbf04ad2304ead8c3b08dd50c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
 *  Copyright (C) 2003 Marco Pesenti Gritti
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 *  $Id$
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "ephy-embed.h"
#include "mozilla-embed.h"

#include "MozillaPrivate.h"

#include <nsIServiceManagerUtils.h>
#include <nsIWindowWatcher.h>
#include <nsIEmbeddingSiteWindow.h>
#include <nsIWebBrowserChrome.h>
#include <gtkmozembed.h>

GtkWidget *MozillaFindEmbed (nsIDOMWindow *aDOMWindow)
{
    if (!aDOMWindow) return nsnull;

        nsCOMPtr<nsIWindowWatcher> wwatch
                (do_GetService("@mozilla.org/embedcomp/window-watcher;1"));
        NS_ENSURE_TRUE (wwatch, nsnull);

    /* this DOM window may belong to some inner frame, we need
     * to get the topmost DOM window to get the embed
     */
    nsCOMPtr<nsIDOMWindow> topWindow;
    aDOMWindow->GetTop (getter_AddRefs (topWindow));
    if (!topWindow) return nsnull;
    
        nsCOMPtr<nsIWebBrowserChrome> windowChrome;
        wwatch->GetChromeForWindow (topWindow, getter_AddRefs(windowChrome));
    NS_ENSURE_TRUE (windowChrome, nsnull);

        nsCOMPtr<nsIEmbeddingSiteWindow> window (do_QueryInterface(windowChrome));
    NS_ENSURE_TRUE (window, nsnull);

        nsresult result;
        GtkWidget *mozembed;
        result = window->GetSiteWindow ((void **)&mozembed);
    NS_ENSURE_SUCCESS (result, nsnull);

    return mozembed;
}

GtkWidget *MozillaFindGtkParent (nsIDOMWindow *aDOMWindow)
{
    GtkWidget *embed = MozillaFindEmbed (aDOMWindow);
    NS_ENSURE_TRUE (embed, nsnull);

    return gtk_widget_get_toplevel (GTK_WIDGET (embed));
}

#define MM_TO_INCH(x)       (((double) x) / 25.4)

NS_METHOD MozillaCollatePrintSettings (const EmbedPrintInfo *info,
                      nsIPrintSettings *options)
{
    const static int frame_types[] = {
                nsIPrintSettings::kFramesAsIs,
                nsIPrintSettings::kSelectedFrame,
                nsIPrintSettings::kEachFrameSep
        };


        switch (info->pages)
        {
        case 0:
        options->SetPrintRange (nsIPrintSettings::kRangeAllPages);
                break;
        case 1:
                options->SetPrintRange (nsIPrintSettings::kRangeSpecifiedPageRange);
                options->SetStartPageRange (info->from_page);
                options->SetEndPageRange (info->to_page);
                break;
        case 2:
                options->SetPrintRange (nsIPrintSettings::kRangeSelection);
                break;
        }

        options->SetMarginTop (MM_TO_INCH (info->top_margin));
        options->SetMarginBottom (MM_TO_INCH (info->bottom_margin));
        options->SetMarginLeft (MM_TO_INCH (info->left_margin));
        options->SetMarginRight (MM_TO_INCH (info->right_margin));

        options->SetPrinterName(NS_LITERAL_STRING("PostScript/default").get());

        options->SetHeaderStrLeft(NS_ConvertUTF8toUTF16(info->header_left_string).get());

        options->SetHeaderStrCenter(NS_ConvertUTF8toUTF16(info->header_center_string).get());

        options->SetHeaderStrRight(NS_ConvertUTF8toUTF16(info->header_right_string).get());

        options->SetFooterStrLeft(NS_ConvertUTF8toUTF16(info->footer_left_string).get());

        options->SetFooterStrCenter(NS_ConvertUTF8toUTF16(info->footer_center_string).get());

        options->SetFooterStrRight(NS_ConvertUTF8toUTF16(info->footer_right_string).get());

        options->SetToFileName (NS_ConvertUTF8toUTF16(info->file).get());

    options->SetPrintCommand (NS_ConvertUTF8toUTF16(info->printer).get());

    /**
     * Work around a mozilla bug where paper size & orientation are ignored
     * and the specified file is created (containing invalid postscript)
     * in print preview mode if we set "print to file" to true.
     * See epiphany bug #119818.
     */
    if (info->preview)
    {
        options->SetPrintToFile (PR_FALSE);
    }
    else
    {
        options->SetPrintToFile (info->print_to_file);
    }

    /* native paper size formats. Our dialog does not support custom yet */
    options->SetPaperSize (nsIPrintSettings::kPaperSizeNativeData);
    options->SetPaperName (NS_ConvertUTF8toUTF16(info->paper).get());

        options->SetPrintInColor (info->print_color);
        options->SetOrientation (info->orientation);
        options->SetPrintFrameType (frame_types[info->frame_type]);

    return NS_OK;
}