Back to index

lightning-sunbird  0.9+nobinonly
IEHtmlTxtRange.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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  *   Alexandre Trémon <atremon@elansoftware.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #include "stdafx.h"
00040 #include "IEHtmlTxtRange.h"
00041 #include "IEHtmlNode.h"
00042 #include "IEHtmlElement.h"
00043 
00044 #include "nsIDomNsRange.h"
00045 #include "nsIDOMDocumentFragment.h"
00046 
00047 CRange::CRange()
00048 {
00049 }
00050 
00051 CRange::~CRange()
00052 {
00053 }
00054 
00055 void CRange::SetRange(nsIDOMRange *pRange)
00056 {
00057     mRange = pRange;
00058 }
00059 
00060 HRESULT CRange::GetParentElement(IHTMLElement **ppParent)
00061 {
00062     if (ppParent == NULL)
00063         return E_INVALIDARG;
00064     *ppParent = NULL;
00065     // get common ancestor property:
00066     nsCOMPtr<nsIDOMNode> domNode;
00067     mRange->GetCommonAncestorContainer(getter_AddRefs(domNode));
00068     if (!domNode)
00069         return S_OK;
00070     nsCOMPtr<nsIDOMElement> domElement = do_QueryInterface(domNode);
00071     if (!domElement)
00072     {
00073         // domNode can be a nsITextNode. In this case, its parent is a nsIDOMElement:
00074         nsCOMPtr<nsIDOMNode> parentNode;
00075         domNode->GetParentNode(getter_AddRefs(parentNode));
00076         domElement = do_QueryInterface(parentNode);
00077         // Is a textrange always supposed to have a parentElement? Remove 2 lines if not:
00078         if (!domElement)
00079             return E_UNEXPECTED;
00080         domNode = parentNode;
00081     }
00082     // get or create com object:
00083     CComPtr<IUnknown> pNode;
00084     HRESULT hr = CIEHtmlDomNode::FindOrCreateFromDOMNode(domNode, &pNode);
00085     if (FAILED(hr))
00086         return hr;
00087     if (FAILED(pNode->QueryInterface(IID_IHTMLElement, (void **)ppParent)))
00088         return E_UNEXPECTED;
00089 
00090     return S_OK;
00091 }
00092 
00093 // CIEHtmlTxtRange
00094 
00095 CIEHtmlTxtRange::CIEHtmlTxtRange()
00096 {
00097 }
00098 
00099 CIEHtmlTxtRange::~CIEHtmlTxtRange()
00100 {
00101 }
00102 
00103 HRESULT STDMETHODCALLTYPE CIEHtmlTxtRange::pasteHTML(BSTR html)
00104 {
00105     nsCOMPtr<nsIDOMDocumentFragment> domDocFragment;
00106     nsAutoString nsStrHtml(OLE2W(html));
00107 
00108     if (NS_FAILED(mRange->DeleteContents()))
00109         return E_FAIL;
00110     nsCOMPtr<nsIDOMNSRange> domNSRange = do_QueryInterface(mRange);
00111     if (!domNSRange)
00112         return E_FAIL;
00113     domNSRange->CreateContextualFragment(nsStrHtml, getter_AddRefs(domDocFragment));
00114     if (!domDocFragment)
00115         return E_FAIL;
00116     mRange->InsertNode(domDocFragment);
00117     mRange->Detach();
00118     
00119     return S_OK;
00120 }
00121 
00122 HRESULT STDMETHODCALLTYPE CIEHtmlTxtRange::get_text(BSTR __RPC_FAR *p)
00123 {
00124     if (p == NULL)
00125         return E_INVALIDARG;
00126     *p = NULL;
00127 
00128     nsAutoString strText;
00129     mRange->ToString(strText);
00130     
00131     *p = SysAllocString(strText.get());
00132     return *p ? S_OK : E_OUTOFMEMORY;
00133 }
00134 
00135 HRESULT STDMETHODCALLTYPE CIEHtmlTxtRange::parentElement(IHTMLElement __RPC_FAR *__RPC_FAR *Parent)
00136 {
00137     return GetParentElement(Parent);
00138 }
00139 
00140 HRESULT STDMETHODCALLTYPE CIEHtmlTxtRange::get_htmlText(BSTR __RPC_FAR *p)
00141 {
00142     return E_NOTIMPL;
00143 }
00144 
00145 HRESULT STDMETHODCALLTYPE CIEHtmlTxtRange::put_text(BSTR v)
00146 {
00147     return E_NOTIMPL;
00148 }
00149 
00150 HRESULT STDMETHODCALLTYPE CIEHtmlTxtRange::duplicate(IHTMLTxtRange __RPC_FAR *__RPC_FAR *Duplicate)
00151 {
00152     return E_NOTIMPL;
00153 }
00154 
00155 HRESULT STDMETHODCALLTYPE CIEHtmlTxtRange::inRange(IHTMLTxtRange __RPC_FAR *Range, VARIANT_BOOL __RPC_FAR *InRange)
00156 {
00157     return E_NOTIMPL;
00158 }
00159 
00160 HRESULT STDMETHODCALLTYPE CIEHtmlTxtRange::isEqual(IHTMLTxtRange __RPC_FAR *Range, VARIANT_BOOL __RPC_FAR *IsEqual)
00161 {
00162     return E_NOTIMPL;
00163 }
00164 
00165 HRESULT STDMETHODCALLTYPE CIEHtmlTxtRange::scrollIntoView(VARIANT_BOOL fStart/* = -1*/)
00166 {
00167     return E_NOTIMPL;
00168 }
00169 
00170 HRESULT STDMETHODCALLTYPE CIEHtmlTxtRange::collapse(VARIANT_BOOL Start/* = -1*/)
00171 {
00172     nsresult rv = mRange->Collapse(Start?PR_TRUE:PR_FALSE);
00173     return FAILED(rv)?E_FAIL:S_OK;
00174 }
00175 
00176 HRESULT STDMETHODCALLTYPE CIEHtmlTxtRange::expand(BSTR Unit,VARIANT_BOOL __RPC_FAR *Success)
00177 {
00178     return E_NOTIMPL;
00179 }
00180 
00181 HRESULT STDMETHODCALLTYPE CIEHtmlTxtRange::move(BSTR Unit, long Count, long __RPC_FAR *ActualCount)
00182 {
00183     return E_NOTIMPL;
00184 }
00185 
00186 HRESULT STDMETHODCALLTYPE CIEHtmlTxtRange::moveStart(BSTR Unit, long Count, long __RPC_FAR *ActualCount)
00187 {
00188     return E_NOTIMPL;
00189 }
00190 
00191 HRESULT STDMETHODCALLTYPE CIEHtmlTxtRange::moveEnd(BSTR Unit, long Count, long __RPC_FAR *ActualCount)
00192 {
00193     return E_NOTIMPL;
00194 }
00195 
00196 HRESULT STDMETHODCALLTYPE CIEHtmlTxtRange::select( void)
00197 {
00198     return E_NOTIMPL;
00199 }
00200 
00201 HRESULT STDMETHODCALLTYPE CIEHtmlTxtRange::moveToElementText(IHTMLElement __RPC_FAR *element)
00202 {
00203     return E_NOTIMPL;
00204 }
00205 
00206 HRESULT STDMETHODCALLTYPE CIEHtmlTxtRange::setEndPoint(BSTR how, IHTMLTxtRange __RPC_FAR *SourceRange)
00207 {
00208     return E_NOTIMPL;
00209 }
00210 
00211 HRESULT STDMETHODCALLTYPE CIEHtmlTxtRange::compareEndPoints(BSTR how, IHTMLTxtRange __RPC_FAR *SourceRange, long __RPC_FAR *ret)
00212 {
00213     return E_NOTIMPL;
00214 }
00215 
00216 HRESULT STDMETHODCALLTYPE CIEHtmlTxtRange::findText(BSTR String, long count, long Flags, VARIANT_BOOL __RPC_FAR *Success)
00217 {
00218     return E_NOTIMPL;
00219 }
00220 
00221 HRESULT STDMETHODCALLTYPE CIEHtmlTxtRange::moveToPoint(long x, long y)
00222 {
00223     return E_NOTIMPL;
00224 }
00225 
00226 HRESULT STDMETHODCALLTYPE CIEHtmlTxtRange::getBookmark(BSTR __RPC_FAR *Boolmark)
00227 {
00228     return E_NOTIMPL;
00229 }
00230 
00231 HRESULT STDMETHODCALLTYPE CIEHtmlTxtRange::moveToBookmark(BSTR Bookmark, VARIANT_BOOL __RPC_FAR *Success)
00232 {
00233     return E_NOTIMPL;
00234 }
00235 
00236 HRESULT STDMETHODCALLTYPE CIEHtmlTxtRange::queryCommandSupported(BSTR cmdID, VARIANT_BOOL __RPC_FAR *pfRet)
00237 {
00238     return E_NOTIMPL;
00239 }
00240 
00241 HRESULT STDMETHODCALLTYPE CIEHtmlTxtRange::queryCommandEnabled(BSTR cmdID, VARIANT_BOOL __RPC_FAR *pfRet)
00242 {
00243     return E_NOTIMPL;
00244 }
00245 
00246 HRESULT STDMETHODCALLTYPE CIEHtmlTxtRange::queryCommandState(BSTR cmdID, VARIANT_BOOL __RPC_FAR *pfRet)
00247 {
00248     return E_NOTIMPL;
00249 }
00250 
00251 HRESULT STDMETHODCALLTYPE CIEHtmlTxtRange::queryCommandIndeterm(BSTR cmdID, VARIANT_BOOL __RPC_FAR *pfRet)
00252 {
00253     return E_NOTIMPL;
00254 }
00255 
00256 HRESULT STDMETHODCALLTYPE CIEHtmlTxtRange::queryCommandText(BSTR cmdID, BSTR __RPC_FAR *pcmdText)
00257 {
00258     return E_NOTIMPL;
00259 }
00260 
00261 HRESULT STDMETHODCALLTYPE CIEHtmlTxtRange::queryCommandValue(BSTR cmdID, VARIANT __RPC_FAR *pcmdValue)
00262 {
00263     return E_NOTIMPL;
00264 }
00265 
00266 HRESULT STDMETHODCALLTYPE CIEHtmlTxtRange::execCommand(BSTR cmdID, VARIANT_BOOL showUI, VARIANT value, VARIANT_BOOL __RPC_FAR *pfRet)
00267 {
00268     return E_NOTIMPL;
00269 }
00270 
00271 HRESULT STDMETHODCALLTYPE CIEHtmlTxtRange::execCommandShowHelp(BSTR cmdID, VARIANT_BOOL __RPC_FAR *pfRet)
00272 {
00273     return E_NOTIMPL;
00274 }
00275 
00276 // IHTMLControlRange
00277 
00278 CIEHtmlControlRange::CIEHtmlControlRange()
00279 {
00280 }
00281 
00282 CIEHtmlControlRange::~CIEHtmlControlRange()
00283 {
00284 }
00285 
00286 HRESULT STDMETHODCALLTYPE CIEHtmlControlRange::commonParentElement(IHTMLElement __RPC_FAR *__RPC_FAR *parent)
00287 {
00288     return GetParentElement(parent);
00289 }
00290 
00291 HRESULT STDMETHODCALLTYPE CIEHtmlControlRange::select( void)
00292 {
00293     return E_NOTIMPL;
00294 }
00295 
00296 HRESULT STDMETHODCALLTYPE CIEHtmlControlRange::add(IHTMLControlElement __RPC_FAR *item)
00297 {
00298     return E_NOTIMPL;
00299 }
00300 
00301 HRESULT STDMETHODCALLTYPE CIEHtmlControlRange::remove(long index)
00302 {
00303     return E_NOTIMPL;
00304 }
00305 
00306 HRESULT STDMETHODCALLTYPE CIEHtmlControlRange::item(long index, IHTMLElement __RPC_FAR *__RPC_FAR *pdisp)
00307 {
00308     return E_NOTIMPL;
00309 }
00310 
00311 HRESULT STDMETHODCALLTYPE CIEHtmlControlRange::scrollIntoView(VARIANT varargStart)
00312 {
00313     return E_NOTIMPL;
00314 }
00315 
00316 HRESULT STDMETHODCALLTYPE CIEHtmlControlRange::queryCommandSupported(BSTR cmdID, VARIANT_BOOL __RPC_FAR *pfRet)
00317 {
00318     return E_NOTIMPL;
00319 }
00320 
00321 HRESULT STDMETHODCALLTYPE CIEHtmlControlRange::queryCommandEnabled(BSTR cmdID, VARIANT_BOOL __RPC_FAR *pfRet)
00322 {
00323     return E_NOTIMPL;
00324 }
00325 
00326 HRESULT STDMETHODCALLTYPE CIEHtmlControlRange::queryCommandState(BSTR cmdID, VARIANT_BOOL __RPC_FAR *pfRet)
00327 {
00328     return E_NOTIMPL;
00329 }
00330 
00331 HRESULT STDMETHODCALLTYPE CIEHtmlControlRange::queryCommandIndeterm(BSTR cmdID, VARIANT_BOOL __RPC_FAR *pfRet)
00332 {
00333     return E_NOTIMPL;
00334 }
00335 
00336 HRESULT STDMETHODCALLTYPE CIEHtmlControlRange::queryCommandText(BSTR cmdID, BSTR __RPC_FAR *pcmdText)
00337 {
00338     return E_NOTIMPL;
00339 }
00340 
00341 HRESULT STDMETHODCALLTYPE CIEHtmlControlRange::queryCommandValue(BSTR cmdID, VARIANT __RPC_FAR *pcmdValue)
00342 {
00343     return E_NOTIMPL;
00344 }
00345 
00346 HRESULT STDMETHODCALLTYPE CIEHtmlControlRange::execCommand(BSTR cmdID, VARIANT_BOOL showUI, VARIANT value, VARIANT_BOOL __RPC_FAR *pfRet)
00347 {
00348     return E_NOTIMPL;
00349 }
00350 
00351 HRESULT STDMETHODCALLTYPE CIEHtmlControlRange::execCommandShowHelp(BSTR cmdID, VARIANT_BOOL __RPC_FAR *pfRet)
00352 {
00353     return E_NOTIMPL;
00354 }
00355 
00356 HRESULT STDMETHODCALLTYPE CIEHtmlControlRange::get_length(long __RPC_FAR *p)
00357 {
00358     return E_NOTIMPL;
00359 }
00360