Back to index

lightning-sunbird  0.9+nobinonly
EditorFrm.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: Mozilla-sample-code 1.0
00004  *
00005  * Copyright (c) 2002 Netscape Communications Corporation and
00006  * other contributors
00007  *
00008  * Permission is hereby granted, free of charge, to any person obtaining a
00009  * copy of this Mozilla sample software and associated documentation files
00010  * (the "Software"), to deal in the Software without restriction, including
00011  * without limitation the rights to use, copy, modify, merge, publish,
00012  * distribute, sublicense, and/or sell copies of the Software, and to permit
00013  * persons to whom the Software is furnished to do so, subject to the
00014  * following conditions:
00015  *
00016  * The above copyright notice and this permission notice shall be included
00017  * in all copies or substantial portions of the Software.
00018  *
00019  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00020  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00021  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00022  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00023  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00024  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00025  * DEALINGS IN THE SOFTWARE.
00026  *
00027  * Contributor(s):
00028  *   Mike Judge <mjudge@netscape.com>
00029  *   Chak Nanga <chak@netscape.com>
00030  *
00031  * ***** END LICENSE BLOCK ***** */
00032 
00033 #include "stdafx.h"
00034 #include "MfcEmbed.h"
00035 #include "BrowserFrm.h"
00036 #include "EditorFrm.h"
00037 #include "Dialogs.h"
00038 #include "nsComponentManagerUtils.h"
00039 #include "nsMemory.h"
00040 #include "nsIEditor.h"
00041 #include "nsIHTMLEditor.h"
00042 
00043 //------------------------------------------------------------
00044 //              Editor Command/Parameter Names
00045 //------------------------------------------------------------
00046 #define BOLD_COMMAND            "cmd_bold"
00047 #define ITALIC_COMMAND          "cmd_italic"
00048 #define UNDERLINE_COMMAND       "cmd_underline"
00049 #define INDENT_COMMAND          "cmd_indent"
00050 #define OUTDENT_COMMAND         "cmd_outdent"
00051 #define FONTCOLOR_COMMAND       "cmd_fontColor"
00052 #define BACKGROUNDCOLOR_COMMAND "cmd_backgroundColor"
00053 #define COMMAND_NAME            "cmd_name"
00054 #define INCREASEFONT_COMMAND    "cmd_increaseFont"
00055 #define DECREASEFONT_COMMAND    "cmd_decreaseFont"
00056 #define FONTFACE_COMMAND        "cmd_fontFace"
00057 #define ALIGN_COMMAND           "cmd_align"
00058 #define UNDO_COMMAND            "cmd_undo"
00059 #define REDO_COMMAND            "cmd_redo"
00060 
00061 
00062 //states
00063 #define STATE_ALL           "state_all"
00064 #define STATE_MIXED         "state_mixed"
00065 #define STATE_ATTRIBUTE     "state_attribute"
00066 #define STATE_ENABLED       "state_enabled"
00067 
00068 //colors
00069 #define COLOR_RED       "#FF0000"
00070 #define COLOR_BLACK     "#000000"
00071 
00072 //fonts
00073 #define FONT_ARIAL            "Helvetica, Arial, sans-serif"
00074 #define FONT_TIMES            "Times New Roman, Times, serif"
00075 #define FONT_COURIER        "Courier New, Courier, monospace"
00076 
00077 //align
00078 #define ALIGN_LEFT      "left"
00079 #define ALIGN_RIGHT     "right"
00080 #define ALIGN_CENTER    "center"
00081 
00082 
00083 //value
00084 #define STATE_EMPTY        ""
00085 
00086 IMPLEMENT_DYNAMIC(CEditorFrame, CBrowserFrame)
00087 
00088 BEGIN_MESSAGE_MAP(CEditorFrame, CBrowserFrame)
00089     //{{AFX_MSG_MAP(CEditorFrame)
00090     ON_COMMAND(ID_BOLD, OnBold)
00091     ON_UPDATE_COMMAND_UI(ID_BOLD, OnUpdateBold)
00092     ON_COMMAND(ID_ITALICS, OnItalics)
00093     ON_UPDATE_COMMAND_UI(ID_ITALICS, OnUpdateItalics)
00094     ON_COMMAND(ID_UNDERLINE, OnUnderline)
00095     ON_UPDATE_COMMAND_UI(ID_UNDERLINE, OnUpdateUnderline)
00096     ON_COMMAND(ID_INDENT, OnIndent)
00097     ON_UPDATE_COMMAND_UI(ID_INDENT, OnUpdateIndent)
00098     ON_COMMAND(ID_OUTDENT, OnOutdent)
00099     ON_UPDATE_COMMAND_UI(ID_OUTDENT, OnUpdateOutdent)
00100     ON_COMMAND(ID_FONTRED, OnFontred)
00101     ON_UPDATE_COMMAND_UI(ID_FONTRED, OnUpdateFontred)
00102     ON_COMMAND(ID_FONTBLACK, OnFontblack)
00103     ON_UPDATE_COMMAND_UI(ID_FONTBLACK, OnUpdateFontblack)
00104     ON_COMMAND(ID_BGCOLOR, OnBgcolor)
00105     ON_UPDATE_COMMAND_UI(ID_BGCOLOR, OnUpdateBgcolor)
00106     ON_COMMAND(ID_NOBGCOLOR, OnNobgcolor)
00107     ON_UPDATE_COMMAND_UI(ID_NOBGCOLOR, OnUpdateNobgcolor)
00108     ON_COMMAND(ID_FONTSIZEINCREASE, OnFontsizeincrease)
00109     ON_COMMAND(ID_FONTSIZEDECREASE, OnFontsizedecrease)
00110     ON_COMMAND(ID_ARIAL, OnArial)
00111     ON_COMMAND(ID_TIMES, OnTimes)
00112     ON_COMMAND(ID_COURIER, OnCourier)
00113     ON_COMMAND(ID_ALIGNLEFT, OnAlignleft)
00114     ON_UPDATE_COMMAND_UI(ID_ALIGNLEFT, OnUpdateAlignleft)
00115     ON_COMMAND(ID_ALIGNRIGHT, OnAlignright)
00116     ON_UPDATE_COMMAND_UI(ID_ALIGNRIGHT, OnUpdateAlignright)
00117     ON_COMMAND(ID_ALIGNCENTER, OnAligncenter)
00118     ON_UPDATE_COMMAND_UI(ID_ALIGNCENTER, OnUpdateAligncenter)
00119     ON_COMMAND(ID_INSERTLINK, OnInsertlink)
00120     ON_COMMAND(ID_EDITOR_UNDO, OnEditUndo)
00121     ON_COMMAND(ID_EDITOR_REDO, OnEditRedo)
00122     ON_UPDATE_COMMAND_UI(ID_EDITOR_REDO, OnUpdateEditRedo)
00123     ON_UPDATE_COMMAND_UI(ID_EDITOR_UNDO, OnUpdateEditUndo)
00124     //}}AFX_MSG_MAP
00125 END_MESSAGE_MAP()
00126 
00127 CEditorFrame::CEditorFrame(PRUint32 chromeMask)
00128 {
00129     m_chromeMask = chromeMask;
00130 
00131     mCommandManager = nsnull;
00132 }
00133 
00134 CEditorFrame::~CEditorFrame()
00135 {
00136 }
00137 
00138 BOOL CEditorFrame::InitEditor()
00139 {
00140     // Get and save off nsICommandManager for later use
00141     //
00142     nsresult rv;
00143     mCommandManager = do_GetInterface(m_wndBrowserView.mWebBrowser, &rv);
00144 
00145     rv = MakeEditable();
00146  
00147     return (NS_SUCCEEDED(rv));
00148 }
00149 
00150 void CEditorFrame::OnBold() 
00151 {
00152     ExecuteStyleCommand(BOLD_COMMAND);
00153 }
00154 
00155 void CEditorFrame::OnUpdateBold(CCmdUI* pCmdUI) 
00156 {
00157     UpdateStyleToolBarBtn(BOLD_COMMAND, pCmdUI);
00158 }
00159 
00160 void CEditorFrame::OnItalics() 
00161 {
00162     ExecuteStyleCommand(ITALIC_COMMAND);
00163 }
00164 
00165 void CEditorFrame::OnUpdateItalics(CCmdUI* pCmdUI) 
00166 {
00167     UpdateStyleToolBarBtn(ITALIC_COMMAND, pCmdUI);
00168 }
00169 
00170 void CEditorFrame::OnUnderline() 
00171 {
00172     ExecuteStyleCommand(UNDERLINE_COMMAND);
00173 }
00174 
00175 void CEditorFrame::OnUpdateUnderline(CCmdUI* pCmdUI) 
00176 {
00177     UpdateStyleToolBarBtn(UNDERLINE_COMMAND, pCmdUI);
00178 }
00179 
00180 
00181 //Called to make a nsICommandParams with the 1 value pair of command name
00182 NS_METHOD
00183 CEditorFrame::MakeCommandParams(const char *aCommand,nsICommandParams **aParams)
00184 {
00185     nsresult rv;
00186     nsCOMPtr<nsICommandParams> params = do_CreateInstance(NS_COMMAND_PARAMS_CONTRACTID,&rv);
00187     if (NS_FAILED(rv))
00188         return rv;
00189     if (!params)
00190         return NS_ERROR_FAILURE;
00191     *aParams = params;
00192     NS_ADDREF(*aParams);
00193     return rv;
00194 }
00195 
00196 
00197 // Called in response to the ON_COMMAND messages generated
00198 // when style related toolbar buttons(bold, italic etc)
00199 // are clicked
00200 //
00201 NS_METHOD
00202 CEditorFrame::ExecuteStyleCommand(const char *aCommand)
00203 {
00204   return DoCommand(aCommand,0);
00205 }
00206 
00207 // Called in response to the UPDATE_COMMAND_UI messages for 
00208 // style related toolbar buttons(bold, italic etc.)
00209 // to update their current state
00210 //
00211 void CEditorFrame::UpdateStyleToolBarBtn(const char *aCommand, CCmdUI* pCmdUI)
00212 {
00213     nsCOMPtr<nsICommandParams> params;
00214     nsresult rv;
00215     rv = MakeCommandParams(aCommand,getter_AddRefs(params));
00216     if (NS_FAILED(rv) || !params)
00217         return;
00218     rv = GetCommandState(aCommand,params);
00219     if (NS_SUCCEEDED(rv))
00220     {
00221         // Does our current selection span mixed styles?
00222         // If so, set the toolbar button to an indeterminate
00223         // state
00224         //
00225         PRBool bMixedStyle = PR_FALSE;
00226         rv = params->GetBooleanValue(STATE_MIXED, &bMixedStyle);
00227         if (NS_SUCCEEDED(rv))
00228         {
00229             if(bMixedStyle)
00230             {
00231                 pCmdUI->SetCheck(2);
00232                 return;
00233             }
00234         }
00235 
00236         // We're not in STATE_MIXED. Enable/Disable the
00237         // toolbar button based on it's current state
00238         //
00239         PRBool bCmdEnabled = PR_FALSE;
00240         rv = params->GetBooleanValue(STATE_ALL, &bCmdEnabled);
00241         if (NS_SUCCEEDED(rv))
00242         {
00243             bCmdEnabled ? pCmdUI->SetCheck(1) : pCmdUI->SetCheck(0);
00244         }
00245     }
00246 }
00247 
00248 NS_METHOD
00249 CEditorFrame::MakeEditable()
00250 {
00251     nsresult rv;
00252 
00253     m_wndBrowserView.mWebBrowser->GetContentDOMWindow(getter_AddRefs(mDOMWindow));
00254     if (!mDOMWindow)
00255         return NS_ERROR_FAILURE;
00256 
00257     mEditingSession = do_GetInterface(m_wndBrowserView.mWebBrowser);
00258     if (!mEditingSession)
00259         return NS_ERROR_FAILURE;
00260   
00261     rv= mEditingSession->MakeWindowEditable(mDOMWindow, NULL, PR_TRUE);
00262   
00263     return rv;  
00264 }
00265 
00266 NS_METHOD
00267 CEditorFrame::DoCommand(const char *aCommand, nsICommandParams *aCommandParams)
00268 {
00269     nsCOMPtr<nsIDOMWindow> domWindow;
00270     m_wndBrowserView.mWebBrowser->GetContentDOMWindow(getter_AddRefs(domWindow));
00271     return mCommandManager ? mCommandManager->DoCommand(aCommand, aCommandParams, domWindow) : NS_ERROR_FAILURE;
00272 }
00273 
00274 NS_METHOD
00275 CEditorFrame::IsCommandEnabled(const char *aCommand, PRBool *retval)
00276 {
00277     nsCOMPtr<nsIDOMWindow> domWindow;
00278     m_wndBrowserView.mWebBrowser->GetContentDOMWindow(getter_AddRefs(domWindow));
00279     return mCommandManager ? mCommandManager->IsCommandEnabled(aCommand, domWindow, retval) : NS_ERROR_FAILURE;
00280 }
00281 
00282 
00283 NS_METHOD
00284 CEditorFrame::GetCommandState(const char *aCommand, nsICommandParams *aCommandParams)
00285 {
00286     nsCOMPtr<nsIDOMWindow> domWindow;
00287     m_wndBrowserView.mWebBrowser->GetContentDOMWindow(getter_AddRefs(domWindow));
00288     return mCommandManager ? mCommandManager->GetCommandState(aCommand, domWindow, aCommandParams) : NS_ERROR_FAILURE;
00289 }
00290 
00291 NS_METHOD
00292 CEditorFrame::ExecuteNoParam(const char *aCommand)
00293 {
00294     return DoCommand(aCommand,0);
00295 }
00296 
00297 void CEditorFrame::OnIndent() 
00298 {
00299     ExecuteNoParam(INDENT_COMMAND);    
00300 }
00301 
00302 void CEditorFrame::OnUpdateIndent(CCmdUI* pCmdUI) 
00303 {
00304     // TODO: Add your command update UI handler code here
00305 }
00306 
00307 void CEditorFrame::OnOutdent() 
00308 {
00309     ExecuteNoParam(OUTDENT_COMMAND);    
00310 }
00311 
00312 void CEditorFrame::OnUpdateOutdent(CCmdUI* pCmdUI) 
00313 {
00314     // TODO: Add your command update UI handler code here
00315 }
00316 
00317 NS_METHOD
00318 CEditorFrame::ExecuteAttribParam(const char *aCommand, const char *aAttribute)
00319 {
00320   nsresult rv;
00321   nsCOMPtr<nsICommandParams> params;
00322   rv = MakeCommandParams(aCommand,getter_AddRefs(params));
00323   if (NS_FAILED(rv))
00324    return rv;
00325   if (!params)
00326     return NS_ERROR_FAILURE;
00327   params->SetCStringValue(STATE_ATTRIBUTE, aAttribute);
00328   return DoCommand(aCommand,params);
00329 }
00330 
00331 NS_METHOD
00332 CEditorFrame::GetAttributeParamValue(const char *aCommand, nsEmbedCString &aValue)
00333 {
00334   nsresult rv;
00335   nsCOMPtr<nsICommandParams> params;
00336   rv = MakeCommandParams(aCommand,getter_AddRefs(params));
00337   if (NS_FAILED(rv))
00338     return rv;
00339   if (!params)
00340     return NS_ERROR_FAILURE;
00341   rv = GetCommandState(aCommand, params);
00342   if (NS_SUCCEEDED(rv))
00343   {
00344     char *tchar;
00345     rv = params->GetCStringValue(STATE_ATTRIBUTE,&tchar);
00346     aValue.Assign(tchar);
00347     nsMemory::Free(tchar);
00348     return rv;
00349   }
00350   return rv;
00351 }
00352 
00353 
00354 void CEditorFrame::OnFontred() 
00355 {
00356     ExecuteAttribParam(FONTCOLOR_COMMAND,COLOR_RED);    
00357 }
00358 
00359 void CEditorFrame::OnUpdateFontred(CCmdUI* pCmdUI) 
00360 {
00361     // TODO: Add your command update UI handler code here
00362 }
00363 
00364 void CEditorFrame::OnFontblack() 
00365 {
00366     ExecuteAttribParam(FONTCOLOR_COMMAND,COLOR_BLACK);        
00367 }
00368 
00369 void CEditorFrame::OnUpdateFontblack(CCmdUI* pCmdUI) 
00370 {
00371     // TODO: Add your command update UI handler code here   
00372 }
00373 
00374 void CEditorFrame::OnBgcolor() 
00375 {
00376     ExecuteAttribParam(BACKGROUNDCOLOR_COMMAND,COLOR_RED);
00377 }
00378 
00379 void CEditorFrame::OnUpdateBgcolor(CCmdUI* pCmdUI) 
00380 {
00381     // TODO: Add your command update UI handler code here
00382 }
00383 
00384 void CEditorFrame::OnNobgcolor() 
00385 {
00386     ExecuteAttribParam(BACKGROUNDCOLOR_COMMAND,STATE_EMPTY);
00387 }
00388 
00389 void CEditorFrame::OnUpdateNobgcolor(CCmdUI* pCmdUI) 
00390 {
00391     // TODO: Add your command update UI handler code here
00392 }
00393 
00394 void CEditorFrame::OnFontsizeincrease() 
00395 {
00396     ExecuteNoParam(INCREASEFONT_COMMAND);
00397 }
00398 
00399 void CEditorFrame::OnFontsizedecrease() 
00400 {
00401     ExecuteNoParam(DECREASEFONT_COMMAND);    
00402 }
00403 
00404 void CEditorFrame::OnArial() 
00405 {
00406     ExecuteAttribParam(FONTFACE_COMMAND,FONT_ARIAL);
00407 }
00408 
00409 void CEditorFrame::OnTimes() 
00410 {
00411     ExecuteAttribParam(FONTFACE_COMMAND,FONT_TIMES);    
00412 }
00413 
00414 void CEditorFrame::OnCourier() 
00415 {
00416     ExecuteAttribParam(FONTFACE_COMMAND,FONT_COURIER);
00417 }
00418 
00419 void CEditorFrame::OnAlignleft() 
00420 {
00421     ExecuteAttribParam(ALIGN_COMMAND,ALIGN_LEFT);    
00422 }
00423 
00424 
00425 void CEditorFrame::OnUpdateAlignleft(CCmdUI* pCmdUI) 
00426 {
00427   nsEmbedCString tValue;
00428 
00429   nsresult rv = GetAttributeParamValue(ALIGN_COMMAND,tValue);
00430   if (NS_SUCCEEDED(rv))
00431   {
00432     if (strcmp(tValue.get(), ALIGN_LEFT) == 0)
00433       pCmdUI->SetCheck(1);
00434     else
00435       pCmdUI->SetCheck(0);
00436   }
00437 }
00438 
00439 void CEditorFrame::OnAlignright() 
00440 {
00441     ExecuteAttribParam(ALIGN_COMMAND,ALIGN_RIGHT);
00442 }
00443 
00444 void CEditorFrame::OnUpdateAlignright(CCmdUI* pCmdUI) 
00445 {
00446   nsEmbedCString tValue;
00447   nsresult rv = GetAttributeParamValue(ALIGN_COMMAND,tValue);
00448   if (NS_SUCCEEDED(rv))
00449   {
00450     if (strcmp(tValue.get(), ALIGN_RIGHT) == 0)
00451       pCmdUI->SetCheck(1);
00452     else
00453       pCmdUI->SetCheck(0);
00454   }
00455 }
00456 
00457 void CEditorFrame::OnAligncenter() 
00458 {
00459     ExecuteAttribParam(ALIGN_COMMAND,ALIGN_CENTER);
00460 }
00461 
00462 void CEditorFrame::OnUpdateAligncenter(CCmdUI* pCmdUI) 
00463 {
00464   nsEmbedCString tValue;
00465   nsresult rv = GetAttributeParamValue(ALIGN_COMMAND,tValue);
00466   if (NS_SUCCEEDED(rv))
00467   {
00468     if (strcmp(tValue.get(), ALIGN_CENTER) == 0)
00469       pCmdUI->SetCheck(1);
00470     else
00471       pCmdUI->SetCheck(0);
00472   }
00473 }
00474 
00475 void CEditorFrame::OnInsertlink() 
00476 {
00477     if (InLink())
00478        ShowEditLinkDlg();
00479     else
00480        ShowInsertLinkDlg();
00481 }
00482 
00483 void CEditorFrame::ShowInsertLinkDlg()
00484 {
00485     CLinkPropertiesDlg dlg;
00486 
00487     if(dlg.DoModal() == IDOK)
00488     {
00489         InsertLink(dlg.m_LinkText, dlg.m_LinkLocation);
00490     }
00491 }
00492 
00493 void CEditorFrame::InsertLink(CString& linkText, CString& linkLocation)
00494 {
00495     CString html = " &nbsp;<A HREF=\"" + linkLocation + "\">" + linkText + "</A>&nbsp; ";
00496 
00497     InsertHTML(html);
00498 }
00499 
00500 void CEditorFrame::InsertHTML(CString& str)
00501 {
00502     nsEmbedString htmlToInsert;
00503 #ifdef _UNICODE
00504     htmlToInsert.Assign(str.GetBuffer(0));
00505 #else
00506     NS_CStringToUTF16(nsEmbedCString(str.GetBuffer(0)),
00507                       NS_CSTRING_ENCODING_ASCII,
00508                       htmlToInsert);
00509 #endif
00510 
00511     nsCOMPtr<nsIHTMLEditor> htmlEditor;
00512     GetHTMLEditor(getter_AddRefs(htmlEditor)); 
00513     if (htmlEditor) 
00514        htmlEditor->InsertHTML(htmlToInsert);
00515 }
00516 
00517 void CEditorFrame::ShowEditLinkDlg()
00518 {
00519     nsCOMPtr<nsIDOMHTMLAnchorElement> anchorElement;
00520     CLinkPropertiesDlg dlg;
00521 
00522     if (GetCurrentLinkInfo(dlg.m_LinkText, dlg.m_LinkLocation, getter_AddRefs(anchorElement)))
00523     {
00524         if(dlg.DoModal() == IDOK)
00525         {
00526             //Select the link being edited and then insert the
00527             //new link into it's place i.e. essentially a replace operation
00528             nsCOMPtr<nsIHTMLEditor> htmlEditor;
00529             GetHTMLEditor(getter_AddRefs(htmlEditor)); 
00530             if (htmlEditor) 
00531                htmlEditor->SelectElement(anchorElement);
00532 
00533             InsertLink(dlg.m_LinkText, dlg.m_LinkLocation);
00534         }
00535     }
00536 }
00537 
00538 BOOL CEditorFrame::GetCurrentLinkInfo(CString& strLinkText, CString& strLinkLocation, nsIDOMHTMLAnchorElement** anchorElement)
00539 {
00540     USES_CONVERSION;
00541 
00542     nsCOMPtr<nsIHTMLEditor> htmlEditor;
00543 
00544     GetHTMLEditor(getter_AddRefs(htmlEditor));
00545     if (!htmlEditor)
00546         return FALSE;
00547 
00548     nsCOMPtr<nsIDOMElement> domElement;
00549     htmlEditor->GetElementOrParentByTagName(nsEmbedString(L"href"), 
00550                                             nsnull,
00551                                             getter_AddRefs(domElement));
00552     if (!domElement)
00553         return FALSE;
00554 
00555     nsEmbedString linkLocation, linkText;
00556     nsresult rv = NS_ERROR_FAILURE;
00557 
00558     // Determine linkLocation
00559     nsCOMPtr<nsIDOMHTMLAnchorElement> linkElement(do_QueryInterface(domElement, &rv));
00560     if (NS_SUCCEEDED(rv))
00561         rv = linkElement->GetHref(linkLocation);
00562     if (NS_FAILED(rv))
00563         return FALSE;
00564 
00565     // Determine linkText
00566     nsCOMPtr<nsIDOMNode> firstChild;
00567     rv = linkElement->GetFirstChild(getter_AddRefs(firstChild));
00568     if (NS_FAILED(rv))
00569         return FALSE;
00570     firstChild->GetNodeValue(linkText);
00571     if (NS_FAILED(rv))
00572         return FALSE;
00573 
00574     strLinkText = W2CT(linkText.get());
00575     strLinkLocation = W2CT(linkLocation.get());
00576 
00577     *anchorElement = linkElement;
00578     NS_ADDREF(*anchorElement);
00579 
00580        return TRUE;
00581 }
00582 
00583 void CEditorFrame::OnEditUndo() 
00584 {
00585     ExecuteNoParam(UNDO_COMMAND);
00586 }
00587 
00588 void CEditorFrame::OnEditRedo() 
00589 {
00590     ExecuteNoParam(REDO_COMMAND);    
00591 }
00592 
00593 void CEditorFrame::OnUpdateEditRedo(CCmdUI* pCmdUI) 
00594 {
00595   nsresult rv;
00596   nsCOMPtr<nsICommandParams> params;
00597   rv = MakeCommandParams(REDO_COMMAND,getter_AddRefs(params));
00598   if (NS_FAILED(rv))
00599     return;
00600   if (!params)
00601     return;
00602   rv = GetCommandState(REDO_COMMAND, params);
00603   if (NS_SUCCEEDED(rv))
00604   {
00605     PRBool tValue;
00606     params->GetBooleanValue(STATE_ENABLED,&tValue);
00607     if (tValue)
00608     {
00609       pCmdUI->Enable(TRUE);
00610       return;
00611     }
00612   }
00613   pCmdUI->Enable(FALSE);    
00614 }
00615 
00616 void CEditorFrame::OnUpdateEditUndo(CCmdUI* pCmdUI) 
00617 {
00618   nsresult rv;
00619   nsCOMPtr<nsICommandParams> params;
00620   rv = MakeCommandParams(UNDO_COMMAND,getter_AddRefs(params));
00621   if (NS_FAILED(rv))
00622     return;
00623   if (!params)
00624     return;
00625   rv = GetCommandState(UNDO_COMMAND, params);
00626   if (NS_SUCCEEDED(rv))
00627   {
00628     PRBool tValue;
00629     params->GetBooleanValue(STATE_ENABLED,&tValue);
00630     if (tValue)
00631     {
00632       pCmdUI->Enable(TRUE);
00633       return;
00634     }
00635   }
00636   pCmdUI->Enable(FALSE);        
00637 }
00638 
00639 void CEditorFrame::GetEditor(nsIEditor** editor)
00640 {
00641     mEditingSession->GetEditorForWindow(mDOMWindow, editor);
00642 }
00643 
00644 void CEditorFrame::GetHTMLEditor(nsIHTMLEditor** htmlEditor)
00645 {
00646     *htmlEditor = 0;
00647 
00648     nsCOMPtr<nsIEditor> editor;
00649     GetEditor(getter_AddRefs(editor));
00650     if (!editor) 
00651        {
00652         return;
00653     }
00654 
00655     editor->QueryInterface(NS_GET_IID(nsIHTMLEditor), (void**)htmlEditor);
00656 }
00657 
00658 BOOL CEditorFrame::InLink()
00659 {
00660     nsCOMPtr<nsIHTMLEditor> htmlEditor;
00661 
00662     GetHTMLEditor(getter_AddRefs(htmlEditor));
00663 
00664     if (htmlEditor) 
00665        {
00666         nsCOMPtr<nsIDOMElement> domElememt;
00667         htmlEditor->GetElementOrParentByTagName(nsEmbedString(L"href"), 
00668                                                 nsnull,
00669                                                 getter_AddRefs(domElememt));
00670         return domElememt ? TRUE : FALSE;
00671     }
00672 
00673     return false;
00674 }