~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/webshell/tests/viewer/nsImageInspectorDialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */
 
2
/* ***** BEGIN LICENSE BLOCK *****
 
3
 * Version: NPL 1.1/GPL 2.0/LGPL 2.1
 
4
 *
 
5
 * The contents of this file are subject to the Netscape Public License
 
6
 * Version 1.1 (the "License"); you may not use this file except in
 
7
 * compliance with the License. You may obtain a copy of the License at
 
8
 * http://www.mozilla.org/NPL/
 
9
 *
 
10
 * Software distributed under the License is distributed on an "AS IS" basis,
 
11
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
12
 * for the specific language governing rights and limitations under the
 
13
 * License.
 
14
 *
 
15
 * The Original Code is mozilla.org code.
 
16
 *
 
17
 * The Initial Developer of the Original Code is 
 
18
 * Netscape Communications Corporation.
 
19
 * Portions created by the Initial Developer are Copyright (C) 1998
 
20
 * the Initial Developer. All Rights Reserved.
 
21
 *
 
22
 * Contributor(s):
 
23
 *
 
24
 * Alternatively, the contents of this file may be used under the terms of
 
25
 * either the GNU General Public License Version 2 or later (the "GPL"), or 
 
26
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
27
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
28
 * of those above. If you wish to allow use of your version of this file only
 
29
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
30
 * use your version of this file under the terms of the NPL, indicate your
 
31
 * decision by deleting the provisions above and replace them with the notice
 
32
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
33
 * the provisions above, a recipient may use your version of this file under
 
34
 * the terms of any one of the NPL, the GPL or the LGPL.
 
35
 *
 
36
 * ***** END LICENSE BLOCK ***** */
 
37
 
 
38
#include "nsCOMPtr.h"
 
39
#include "nsImageInspectorDialog.h"
 
40
#include "nsIDOMEvent.h"
 
41
#include "nsIXPBaseWindow.h"
 
42
#include "nsBrowserWindow.h"
 
43
#include "nsIDOMEventTarget.h"
 
44
#include "nsIDOMDocument.h"
 
45
 
 
46
#include "nsIDOMHTMLInputElement.h"
 
47
#include "nsIDOMHTMLDocument.h"
 
48
 
 
49
 
 
50
//-------------------------------------------------------------------------
 
51
//
 
52
// nsImageInspectorDialog constructor
 
53
//
 
54
//-------------------------------------------------------------------------
 
55
//-----------------------------------------------------------------
 
56
nsImageInspectorDialog::nsImageInspectorDialog(nsBrowserWindow * aBrowserWindow, nsIDOMDocument * aDoc) :
 
57
  nsBaseDialog(aBrowserWindow),
 
58
  mOKBtn(nsnull),
 
59
  mDOMDoc(aDoc)
 
60
{
 
61
}
 
62
 
 
63
//-----------------------------------------------------------------
 
64
nsImageInspectorDialog::~nsImageInspectorDialog()
 
65
{
 
66
}
 
67
 
 
68
//---------------------------------------------------------------
 
69
void nsImageInspectorDialog::Initialize(nsIXPBaseWindow * aWindow) 
 
70
{
 
71
  nsBaseDialog::Initialize(aWindow);
 
72
 
 
73
  nsIDOMHTMLDocument *doc = nsnull;
 
74
  mWindow->GetDocument(doc);
 
75
  if (nsnull != doc) {
 
76
    doc->GetElementById(NS_LITERAL_STRING("ok"), &mOKBtn);
 
77
 
 
78
    // XXX: Register event listening on each dom element. We should change this so
 
79
    // all DOM events are automatically passed through.
 
80
    mWindow->AddEventListener(mOKBtn);
 
81
    //SetChecked(mMatchCaseCB, PR_FALSE);
 
82
    
 
83
    NS_RELEASE(doc);
 
84
  }
 
85
}
 
86
 
 
87
#if 0
 
88
//-----------------------------------------------------------------
 
89
void nsImageInspectorDialog::GetSetupInfo(PrintSetupInfo & aPSI)
 
90
{
 
91
  aPSI.mPortrait         = IsChecked("portrait");
 
92
  aPSI.mBevelLines       = IsChecked("bevellines");
 
93
  aPSI.mBlackText        = IsChecked("blacktext");
 
94
  aPSI.mBlackLines       = IsChecked("blacklines");
 
95
  aPSI.mLastPageFirst    = IsChecked("lastpagefirst");
 
96
  aPSI.mPrintBackgrounds = IsChecked("printbg");
 
97
 
 
98
  nsString str;
 
99
  GetText("toptext", str);
 
100
  aPSI.mTopMargin = GetFloat(str);
 
101
 
 
102
  GetText("lefttext", str);
 
103
  aPSI.mLeftMargin = GetFloat(str);
 
104
 
 
105
  GetText("bottomtext", str);
 
106
  aPSI.mBottomMargin = GetFloat(str);
 
107
 
 
108
  GetText("righttext", str);
 
109
  aPSI.mRightMargin = GetFloat(str);
 
110
 
 
111
  GetText("lefttext",   str);
 
112
  GetText("bottomtext", str);
 
113
  GetText("righttext",  str);
 
114
 
 
115
  nsString header("");
 
116
  nsString footer("");
 
117
  GetText("headertext",  header);
 
118
  GetText("footertext",  footer);
 
119
  aPSI.mHeaderText = header;
 
120
  aPSI.mFooterText = footer;
 
121
 
 
122
  //GetText("headertext",  aPSI.mHeaderText);
 
123
  //GetText("footertext",  aPSI.mFooterText);
 
124
 
 
125
  aPSI.mDocTitle    = IsChecked("doctitle");
 
126
  aPSI.mDocLocation = IsChecked("docloc");
 
127
  aPSI.mPageNum     = IsChecked("pagenum");
 
128
  aPSI.mPageTotal   = IsChecked("pagetotal");
 
129
  aPSI.mDatePrinted = IsChecked("dateprinted");
 
130
 
 
131
}
 
132
 
 
133
//-----------------------------------------------------------------
 
134
void nsImageInspectorDialog::SetSetupInfo(const PrintSetupInfo & aPSI)
 
135
{
 
136
  if (nsnull == mWindow) {
 
137
    mPrinterSetupInfo = new PrintSetupInfo(aPSI);
 
138
  } else {
 
139
    SetSetupInfoInternal(aPSI);
 
140
  }
 
141
}
 
142
 
 
143
//-----------------------------------------------------------------
 
144
void nsImageInspectorDialog::SetSetupInfoInternal(const PrintSetupInfo & aPSI)
 
145
{
 
146
  SetChecked("portrait",      aPSI.mPortrait);
 
147
  SetChecked("bevellines",    aPSI.mBevelLines);
 
148
  SetChecked("blacktext",     aPSI.mBlackText);
 
149
  SetChecked("blacklines",    aPSI.mBlackLines);
 
150
  SetChecked("lastpagefirst", aPSI.mLastPageFirst);
 
151
  SetChecked("printbg",       aPSI.mPrintBackgrounds);
 
152
 
 
153
  char str[64];
 
154
  sprintf(str, "%5.2f", aPSI.mTopMargin);
 
155
  SetText("toptext", str);
 
156
  sprintf(str, "%5.2f", aPSI.mLeftMargin);
 
157
  SetText("lefttext", str);
 
158
  sprintf(str, "%5.2f", aPSI.mBottomMargin);
 
159
  SetText("bottomtext", str);
 
160
  sprintf(str, "%5.2f", aPSI.mRightMargin);
 
161
  SetText("righttext",  str);
 
162
 
 
163
  SetText("headertext",  aPSI.mHeaderText);
 
164
  SetText("footertext",  aPSI.mFooterText);
 
165
 
 
166
  SetChecked("doctitle",    aPSI.mDocTitle);
 
167
  SetChecked("docloc",      aPSI.mDocLocation);
 
168
  SetChecked("pagenum",     aPSI.mPageNum);
 
169
  SetChecked("pagetotal",   aPSI.mPageTotal);
 
170
  SetChecked("dateprinted", aPSI.mDatePrinted);
 
171
 
 
172
}
 
173
#endif
 
174
 
 
175
//-----------------------------------------------------------------
 
176
void nsImageInspectorDialog::MouseClick(nsIDOMEvent* aMouseEvent, nsIXPBaseWindow * aWindow, PRBool &aStatus)
 
177
{
 
178
   // Event Dispatch. This method should not contain
 
179
   // anything but calls to methods. This idea is that this dispatch
 
180
   // mechanism may be replaced by JavaScript EventHandlers which call the idl'ed
 
181
   // interfaces to perform the same operation that is currently being handled by
 
182
   // this C++ code.
 
183
 
 
184
  nsBaseDialog::MouseClick(aMouseEvent, aWindow, aStatus);
 
185
  if (!aStatus) { // is not consumed
 
186
    nsCOMPtr<nsIDOMEventTarget> target;
 
187
    aMouseEvent->GetTarget(getter_AddRefs(target));
 
188
    if (target) {
 
189
      nsCOMPtr<nsIDOMElement> node(do_QueryInterface(target));
 
190
      if (node.get() == mOKBtn) {
 
191
        nsString str;
 
192
        GetText(NS_LITERAL_STRING("url"), str);
 
193
        //DoClose();
 
194
      } 
 
195
    }
 
196
  }
 
197
}
 
198
 
 
199
//-----------------------------------------------------------------
 
200
void nsImageInspectorDialog::Destroy(nsIXPBaseWindow * aWindow)
 
201
{
 
202
  // Unregister event listeners that were registered in the
 
203
  // Initialize here. 
 
204
  // XXX: Should change code in XPBaseWindow to automatically unregister
 
205
  // all event listening, That way this code will not be necessary.
 
206
  aWindow->RemoveEventListener(mOKBtn);
 
207
}
 
208
 
 
209
 
 
210
void
 
211
nsImageInspectorDialog::DoClose()
 
212
{
 
213
  mWindow->SetVisible(PR_FALSE);
 
214
}
 
215
 
 
216