Back to index

lightning-sunbird  0.9+nobinonly
nsImageInspectorDialog.cpp
Go to the documentation of this file.
00001 /* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "nsCOMPtr.h"
00039 #include "nsImageInspectorDialog.h"
00040 #include "nsIDOMEvent.h"
00041 #include "nsIXPBaseWindow.h"
00042 #include "nsBrowserWindow.h"
00043 #include "nsIDOMEventTarget.h"
00044 #include "nsIDOMDocument.h"
00045 
00046 #include "nsIDOMHTMLInputElement.h"
00047 #include "nsIDOMHTMLDocument.h"
00048 
00049 
00050 //-------------------------------------------------------------------------
00051 //
00052 // nsImageInspectorDialog constructor
00053 //
00054 //-------------------------------------------------------------------------
00055 //-----------------------------------------------------------------
00056 nsImageInspectorDialog::nsImageInspectorDialog(nsBrowserWindow * aBrowserWindow, nsIDOMDocument * aDoc) :
00057   nsBaseDialog(aBrowserWindow),
00058   mOKBtn(nsnull),
00059   mDOMDoc(aDoc)
00060 {
00061 }
00062 
00063 //-----------------------------------------------------------------
00064 nsImageInspectorDialog::~nsImageInspectorDialog()
00065 {
00066 }
00067 
00068 //---------------------------------------------------------------
00069 void nsImageInspectorDialog::Initialize(nsIXPBaseWindow * aWindow) 
00070 {
00071   nsBaseDialog::Initialize(aWindow);
00072 
00073   nsIDOMHTMLDocument *doc = nsnull;
00074   mWindow->GetDocument(doc);
00075   if (nsnull != doc) {
00076     doc->GetElementById(NS_LITERAL_STRING("ok"), &mOKBtn);
00077 
00078     // XXX: Register event listening on each dom element. We should change this so
00079     // all DOM events are automatically passed through.
00080     mWindow->AddEventListener(mOKBtn);
00081     //SetChecked(mMatchCaseCB, PR_FALSE);
00082     
00083     NS_RELEASE(doc);
00084   }
00085 }
00086 
00087 #if 0
00088 //-----------------------------------------------------------------
00089 void nsImageInspectorDialog::GetSetupInfo(PrintSetupInfo & aPSI)
00090 {
00091   aPSI.mPortrait         = IsChecked("portrait");
00092   aPSI.mBevelLines       = IsChecked("bevellines");
00093   aPSI.mBlackText        = IsChecked("blacktext");
00094   aPSI.mBlackLines       = IsChecked("blacklines");
00095   aPSI.mLastPageFirst    = IsChecked("lastpagefirst");
00096   aPSI.mPrintBackgrounds = IsChecked("printbg");
00097 
00098   nsString str;
00099   GetText("toptext", str);
00100   aPSI.mTopMargin = GetFloat(str);
00101 
00102   GetText("lefttext", str);
00103   aPSI.mLeftMargin = GetFloat(str);
00104 
00105   GetText("bottomtext", str);
00106   aPSI.mBottomMargin = GetFloat(str);
00107 
00108   GetText("righttext", str);
00109   aPSI.mRightMargin = GetFloat(str);
00110 
00111   GetText("lefttext",   str);
00112   GetText("bottomtext", str);
00113   GetText("righttext",  str);
00114 
00115   nsString header("");
00116   nsString footer("");
00117   GetText("headertext",  header);
00118   GetText("footertext",  footer);
00119   aPSI.mHeaderText = header;
00120   aPSI.mFooterText = footer;
00121 
00122   //GetText("headertext",  aPSI.mHeaderText);
00123   //GetText("footertext",  aPSI.mFooterText);
00124 
00125   aPSI.mDocTitle    = IsChecked("doctitle");
00126   aPSI.mDocLocation = IsChecked("docloc");
00127   aPSI.mPageNum     = IsChecked("pagenum");
00128   aPSI.mPageTotal   = IsChecked("pagetotal");
00129   aPSI.mDatePrinted = IsChecked("dateprinted");
00130 
00131 }
00132 
00133 //-----------------------------------------------------------------
00134 void nsImageInspectorDialog::SetSetupInfo(const PrintSetupInfo & aPSI)
00135 {
00136   if (nsnull == mWindow) {
00137     mPrinterSetupInfo = new PrintSetupInfo(aPSI);
00138   } else {
00139     SetSetupInfoInternal(aPSI);
00140   }
00141 }
00142 
00143 //-----------------------------------------------------------------
00144 void nsImageInspectorDialog::SetSetupInfoInternal(const PrintSetupInfo & aPSI)
00145 {
00146   SetChecked("portrait",      aPSI.mPortrait);
00147   SetChecked("bevellines",    aPSI.mBevelLines);
00148   SetChecked("blacktext",     aPSI.mBlackText);
00149   SetChecked("blacklines",    aPSI.mBlackLines);
00150   SetChecked("lastpagefirst", aPSI.mLastPageFirst);
00151   SetChecked("printbg",       aPSI.mPrintBackgrounds);
00152 
00153   char str[64];
00154   sprintf(str, "%5.2f", aPSI.mTopMargin);
00155   SetText("toptext", str);
00156   sprintf(str, "%5.2f", aPSI.mLeftMargin);
00157   SetText("lefttext", str);
00158   sprintf(str, "%5.2f", aPSI.mBottomMargin);
00159   SetText("bottomtext", str);
00160   sprintf(str, "%5.2f", aPSI.mRightMargin);
00161   SetText("righttext",  str);
00162 
00163   SetText("headertext",  aPSI.mHeaderText);
00164   SetText("footertext",  aPSI.mFooterText);
00165 
00166   SetChecked("doctitle",    aPSI.mDocTitle);
00167   SetChecked("docloc",      aPSI.mDocLocation);
00168   SetChecked("pagenum",     aPSI.mPageNum);
00169   SetChecked("pagetotal",   aPSI.mPageTotal);
00170   SetChecked("dateprinted", aPSI.mDatePrinted);
00171 
00172 }
00173 #endif
00174 
00175 //-----------------------------------------------------------------
00176 void nsImageInspectorDialog::MouseClick(nsIDOMEvent* aMouseEvent, nsIXPBaseWindow * aWindow, PRBool &aStatus)
00177 {
00178    // Event Dispatch. This method should not contain
00179    // anything but calls to methods. This idea is that this dispatch
00180    // mechanism may be replaced by JavaScript EventHandlers which call the idl'ed
00181    // interfaces to perform the same operation that is currently being handled by
00182    // this C++ code.
00183 
00184   nsBaseDialog::MouseClick(aMouseEvent, aWindow, aStatus);
00185   if (!aStatus) { // is not consumed
00186     nsCOMPtr<nsIDOMEventTarget> target;
00187     aMouseEvent->GetTarget(getter_AddRefs(target));
00188     if (target) {
00189       nsCOMPtr<nsIDOMElement> node(do_QueryInterface(target));
00190       if (node.get() == mOKBtn) {
00191         nsString str;
00192         GetText(NS_LITERAL_STRING("url"), str);
00193         //DoClose();
00194       } 
00195     }
00196   }
00197 }
00198 
00199 //-----------------------------------------------------------------
00200 void nsImageInspectorDialog::Destroy(nsIXPBaseWindow * aWindow)
00201 {
00202   // Unregister event listeners that were registered in the
00203   // Initialize here. 
00204   // XXX: Should change code in XPBaseWindow to automatically unregister
00205   // all event listening, That way this code will not be necessary.
00206   aWindow->RemoveEventListener(mOKBtn);
00207 }
00208 
00209 
00210 void
00211 nsImageInspectorDialog::DoClose()
00212 {
00213   mWindow->SetVisible(PR_FALSE);
00214 }
00215 
00216