home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / edframe.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  83.9 KB  |  2,340 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. // edframe.cpp : implementation file
  20. //
  21. #include "stdafx.h"
  22. #ifdef EDITOR
  23. #include "edt.h"
  24. #include "netsvw.h"
  25. #include "edview.h"
  26. #include "edprops.h"
  27. #include "mainfrm.h"
  28. #include "edframe.h"
  29. #include "edres2.h"
  30. #include "compfrm.h"
  31. #include "resource.h"
  32. #include "prefapi.h"
  33. #include "prefapi.h"
  34. #include "eddialog.h"
  35. #include "template.h"
  36. #include "edtplug.h"
  37. // For XP Strings
  38. extern "C" {
  39. #include "xpgetstr.h"
  40. #define WANT_ENUM_STRING_IDS
  41. #include "allxpstr.h"
  42. #undef WANT_ENUM_STRING_IDS
  43. }
  44.  
  45.  
  46. #ifdef _DEBUG
  47. #undef THIS_FILE
  48. static char BASED_CODE THIS_FILE[] = __FILE__;
  49. #endif
  50.  
  51. // Globals in TEMPLATE.CPP - 
  52. //     saves last frame location for new window postioning
  53. //     and flag to overlay current window (default = cascaded windows)
  54. extern BOOL wfe_bUseLastFrameLocation;
  55. extern CGenericFrame *wfe_pLastFrame;
  56.  
  57. char *EDT_NEW_DOC_URL = NULL;
  58. char *EDT_NEW_DOC_NAME = NULL;
  59.  
  60. extern TagType FEED_nParagraphTags[];
  61.  
  62. void FED_SetupStrings(void)
  63. {
  64.     // Get strings from XP_MSG.I for new document stuff
  65.     // These are the same strings used in \LIB\LIBNET\MKGETURL.C
  66.     //  to do most of the new doc stuff at cross-platform level
  67.     if (EDT_NEW_DOC_URL == NULL) {
  68.         StrAllocCopy(EDT_NEW_DOC_URL, XP_GetString(XP_EDIT_NEW_DOC_URL) );
  69.     }
  70.     if (EDT_NEW_DOC_NAME == NULL) {
  71.         StrAllocCopy(EDT_NEW_DOC_NAME, XP_GetString(XP_EDIT_NEW_DOC_NAME) );
  72.     }
  73. }
  74.  
  75. static UINT nTraceCount = 0;
  76.  
  77. // toolbar buttons - IDs are command buttons except for ID_SEPARATOR and 
  78. //   ID_COMBOBOX, the placeholder for comboboxes.built with CComboToolBar  _WIN32
  79. // Main edit toolbar:
  80. static UINT BASED_CODE nIDEditBarArray[] =
  81. {
  82.     // same order as in the bitmap for toolbar
  83.     ID_EDT_NEW_DOC_BLANK,
  84.     ID_FILE_OPEN,
  85.     ID_EDT_FILE_SAVE,
  86.     ID_FILE_PUBLISH,
  87.     ID_OPEN_NAV_WINDOW,
  88.     ID_FILE_PRINT,
  89.     ID_CHECK_SPELLING,
  90.     ID_MAKE_LINK,
  91.     ID_INSERT_TARGET,
  92.     ID_INSERT_IMAGE,
  93.     ID_INSERT_HRULE,
  94.     ID_INSERT_TABLE_OR_PROPS,
  95. };
  96. #define EDITBAR_ID_COUNT ((sizeof(nIDEditBarArray))/sizeof(UINT))
  97.  
  98. // Character Format Toolbar:
  99. // NOTE: We now use a NSToolbar2 for the button array
  100. static UINT BASED_CODE nIDCharacterBarArray[] =
  101. {
  102.     // same order as in the bitmap for toolbar
  103.     ID_COMBOBOX,        // Paragraph style
  104.     ID_COMBOBOX,        // Font Face
  105.     ID_COMBOBOX,        // Font Size
  106.     ID_COMBOBOX         // Font Color combobox in Win4+ versions - define COLOR_COMBO_INDEX as this location
  107. };
  108. #define CHARBAR_ID_COUNT ((sizeof(nIDCharacterBarArray))/sizeof(UINT))
  109.  
  110. static UINT BASED_CODE nIDCharButtonBarArray[] =
  111. {
  112.     // same order as in the bitmap for toolbar
  113.     ID_FORMAT_CHAR_BOLD,
  114.     ID_FORMAT_CHAR_ITALIC,
  115.     ID_FORMAT_CHAR_UNDERLINE,
  116.     ID_FORMAT_CHAR_NONE,
  117.     ID_UNUM_LIST,
  118.     ID_NUM_LIST,
  119.     ID_FORMAT_OUTDENT,
  120.     ID_FORMAT_INDENT,
  121.     ID_ALIGN_POPUP,
  122.     ID_INSERT_POPUP
  123. };
  124. #define CHARBUTTONBAR_ID_COUNT ((sizeof(nIDCharButtonBarArray))/sizeof(UINT))
  125.  
  126. #define COLOR_COMBO_INDEX 3 // Location of color combo we hide in Win16/NT3.51
  127.  
  128. // Global strings for dropdown property combos
  129. // Filled in once in InitComposer()
  130. char * ed_pOther = NULL;
  131. char * ed_pMixedFonts = NULL;
  132. char * ed_pDontChange = NULL;
  133. CBitmap ed_DragCaretBitmap;
  134.  
  135. //////////////////////////////////////////////////////////////////////////
  136. // The height of an item in the dropdown listbox part of a comobbox
  137. extern int wfe_iListItemHeight;
  138. extern void SetCurrentDefaultFontColor();
  139.  
  140. // Callback notification when preferences are changed
  141. int PR_CALLBACK ed_prefWatcher(const char *pPrefName, void *pData)
  142. {
  143.     switch ((int)pData) {
  144.         case 1:
  145.         {
  146.             int32 iDelay;
  147.             PREF_GetIntPref("editor.auto_save_delay", &iDelay);
  148.  
  149.             CGenericFrame * f;
  150.             // We must set the autosave values for ALL edit contexts
  151.             for(f = theApp.m_pFrameList; f; f = f->m_pNext) {
  152.                 MWContext *pMWContext = f->GetMainContext()->GetContext();
  153.     
  154.                 if ( pMWContext && EDT_IS_EDITOR(pMWContext) && !pMWContext->bIsComposeWindow ){
  155.                     EDT_SetAutoSavePeriod(pMWContext, iDelay);
  156.                 }
  157.             }
  158.             break;
  159.         }
  160.         case 2:
  161.         {
  162.             PREF_GetIntPref("editor.fontsize_mode", &wfe_iFontSizeMode);
  163.  
  164.             CGenericFrame * f;
  165.             // We update font size combobox for ALL edit contexts
  166.             for(f = theApp.m_pFrameList; f; f = f->m_pNext) {
  167.                 MWContext *pMWContext = f->GetMainContext()->GetContext();
  168.                 if ( pMWContext && EDT_IS_EDITOR(pMWContext) ){
  169.                     CNetscapeEditView * pView = (CNetscapeEditView*)f->GetActiveView();
  170.                     if( pView ){
  171.                         pView->UpdateFontSizeCombo();
  172.                     }
  173.                 }
  174.             }
  175.             break;        
  176.         }
  177.         case 3:
  178.         {
  179.             // Find all composer windows and change Author name only if it
  180.             //   isn't already set in the page
  181.             CGenericFrame * f;
  182.             for(f = theApp.m_pFrameList; f; f = f->m_pNext) {
  183.                 MWContext *pMWContext = f->GetMainContext()->GetContext();
  184.     
  185.                 if ( pMWContext && EDT_IS_EDITOR(pMWContext) && !pMWContext->bIsComposeWindow ){
  186.                     int count = EDT_MetaDataCount(pMWContext);
  187.                     BOOL bFound = FALSE;
  188.                     EDT_MetaData* pData = NULL;
  189.                     for ( int i = 0; i < count; i++ ) {
  190.                         pData = EDT_GetMetaData(pMWContext, i);
  191.                         if( pData ){
  192.                             if( 0 != _stricmp(pData->pName, "Author") ){
  193.                                 bFound = TRUE;
  194.                                 EDT_FreeMetaData(pData);
  195.                                 break;
  196.                             }
  197.                             EDT_FreeMetaData(pData);
  198.                         }
  199.                     }                        
  200.                     // Use preference only if Author tag not already found
  201.                     if(!bFound){
  202.                         pData->pName = XP_STRDUP("Author");
  203.                         PREF_CopyCharPref("editor.author", &pData->pContent);
  204.                         EDT_SetMetaData(pMWContext, pData);
  205.                         EDT_FreeMetaData(pData);
  206.                     }
  207.                 }
  208.             }
  209.             break;
  210.         }
  211.     }
  212.  
  213.     return PREF_NOERROR;
  214. }
  215.  
  216. static void wfe_EditURLCallback(const char* urlToOpen){
  217.     FE_LoadUrl((char*) urlToOpen, LOAD_URL_COMPOSER);
  218. }
  219.  
  220. // Initialize global data (Note: we don't have a MWContext/Frame/View yet)
  221. void WFE_InitComposer()
  222. {     
  223.     // Check to make sure range of IDs in EDRES1.H (which start at 36000)
  224.     //  don't collide with those in RESOURCE.H
  225.     ASSERT(ID_EDIT_LAST_ID < 42000);
  226.     int i;
  227.  
  228.     UINT   n = ID_FORMAT_FONTFACE_BASE;
  229.  
  230.     char   pPref[32];
  231.     char * pLocation = NULL;
  232.     // Count the number of most-recently-used template locations
  233.     theApp.m_iTemplateLocationCount = 0;
  234.     for ( i = 0; i < MAX_TEMPLATE_LOCATIONS; i++ ){
  235.         sprintf( pPref, "editor.template_history_%d", i);
  236.         PREF_CopyCharPref(pPref, &pLocation);
  237.         if( pLocation && *pLocation ){
  238.             // We have a non-empty string - count it
  239.             theApp.m_iTemplateLocationCount++;
  240.             XP_FREEIF(pLocation);
  241.         } else {
  242.             break;
  243.         }
  244.     }
  245.     XP_FREEIF(pLocation);
  246.  
  247.     // Initialize the static string "Other" we use in comboboxes
  248.     if( !ed_pOther ){
  249.         ed_pOther = XP_STRDUP(szLoadString(IDS_OTHER));
  250.     }
  251.     if( !ed_pMixedFonts ){
  252.         ed_pMixedFonts = XP_STRDUP(szLoadString(IDS_MIXED_FONTS));
  253.     }
  254.     if( !ed_pDontChange ){
  255.         ed_pDontChange = XP_STRDUP(szLoadString(IDS_DONT_CHANGE));
  256.     }
  257.     // This will be updated in CGenericFrame::OnDisplayPreferences() 
  258.     PREF_GetIntPref("editor.fontsize_mode", &wfe_iFontSizeMode);
  259.  
  260.     // Register callbacks for items we need to know immediately when changed
  261.     PREF_RegisterCallback("editor.auto_save_delay", ed_prefWatcher, (void*)1);
  262.     PREF_RegisterCallback("editor.fontsize_mode", ed_prefWatcher, (void*)2);
  263.     PREF_RegisterCallback("editor.author", ed_prefWatcher, (void*)3);
  264.  
  265.     wfe_pFont = new CFont();
  266.     if( wfe_pFont ){
  267.         if( GetSystemMetrics(SM_DBCSENABLED) ){
  268.             HFONT    hFont = NULL;
  269.  
  270. #ifdef _WIN32
  271.             hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
  272. #endif
  273.             if (!hFont){
  274.                 hFont = (HFONT)GetStockObject(SYSTEM_FONT);
  275.             }
  276.             wfe_pFont->Attach(hFont);
  277.  
  278.         } else {
  279.             //  Get a 1-pixel font
  280.             LOGFONT logFont;
  281.             memset(&logFont, 0, sizeof(logFont));
  282.             //logFont.lfHeight = -MulDiv(9, ::GetDeviceCaps(hDC, LOGPIXELSY), 72);
  283.             logFont.lfHeight = -10; // This maps to "8 pts"
  284.             logFont.lfWeight = FW_NORMAL;
  285.             logFont.lfCharSet = IntlGetLfCharset(CIntlWin::GetSystemLocaleCsid());
  286.             logFont.lfPitchAndFamily = VARIABLE_PITCH | FF_SWISS;
  287.             if (CIntlWin::GetSystemLocaleCsid() == CS_LATIN1)
  288.                 _tcscpy(logFont.lfFaceName, "MS Sans Serif");
  289.             else
  290.                 _tcscpy(logFont.lfFaceName, IntlGetUIPropFaceName(CIntlWin::GetSystemLocaleCsid()));
  291.  
  292.             if( !wfe_pFont->CreateFontIndirect(&logFont) ){
  293.                 delete wfe_pFont;
  294.                 wfe_pFont = NULL;
  295.             }
  296.         }
  297.     }
  298.  
  299.     // Set default Author name to the same as mail username if not already set    
  300.     char * pAuthor = NULL;
  301.     if( PREF_CopyCharPref("editor.author", &pAuthor) != PREF_NOERROR || !pAuthor || !*pAuthor ){
  302.         // No Author field - copy the mail username
  303.         char * pUserName = NULL;
  304.         if( PREF_CopyCharPref("mail.identity.username", &pUserName) == PREF_NOERROR &&
  305.             pUserName && *pUserName ){
  306.             PREF_SetCharPref("editor.author", pUserName);
  307.         }
  308.         XP_FREEIF(pUserName);
  309.     }
  310.     XP_FREEIF(pAuthor);
  311.  
  312.     // Register edtplug java-to-C++ Open-the-editor callback.
  313.     EDTPLUG_RegisterEditURLCallback(&wfe_EditURLCallback);
  314.  
  315.     ed_DragCaretBitmap.LoadBitmap(IDB_ED_DRAG);
  316.  
  317.     // Get global last-color-picked from prefs
  318.     char * pCustomColor = NULL;
  319.     LO_Color LoColor;
  320.  
  321.     PREF_CopyCharPref("editor.last_color_picked", &pCustomColor);    
  322.     if( pCustomColor )
  323.     {        
  324.         EDT_ParseColorString(&LoColor, pCustomColor);
  325.         wfe_crLastColorPicked =  RGB(LoColor.red, LoColor.green, LoColor.blue);
  326.         XP_FREEIF(pCustomColor);
  327.     } else {
  328.         wfe_crLastColorPicked = 0;
  329.     }
  330.     
  331.     //  Fill color table with 0s
  332.     memset((void*)wfe_CustomPalette, 0, 16*sizeof(COLORREF));
  333.     
  334.     // We should make this an expandable list so we can 
  335.     //   append document colors to the list
  336.     for( i = 1; i <= MAX_CUSTOM_COLORS; i++ )
  337.     {
  338.         wsprintf(pPref, "editor.custom_color_%d", (i < MAX_CUSTOM_COLORS) ? i : 0);
  339.         PREF_CopyCharPref(pPref, &pCustomColor);    
  340.         if (pCustomColor)
  341.             EDT_ParseColorString(&LoColor, pCustomColor);
  342.         XP_FREEIF(pCustomColor);
  343.  
  344.         // Save color to test if it changed
  345.         wfe_CustomPalette[i] = RGB(LoColor.red, LoColor.green, LoColor.blue);
  346.     }
  347. }
  348.  
  349. void WFE_ExitComposer()
  350. {
  351.     if( wfe_pFont ){
  352.         delete wfe_pFont;
  353.     }
  354.     XP_FREEIF(ed_pOther);
  355.     XP_FREEIF(ed_pMixedFonts);
  356.     XP_FREEIF(ed_pDontChange);
  357.     ed_DragCaretBitmap.DeleteObject();
  358. }
  359.  
  360. /////////////////////////////////////////////////////////////////////////////
  361. // Toolbar controller class used by Edit and Mail compose frames
  362. //
  363. CEditToolBarController::CEditToolBarController(CWnd * pParent) :
  364.     m_pWnd(pParent),
  365.     m_iFontColorOtherIndex(0),
  366.     m_pCharacterToolbar(0)
  367. {
  368. }
  369.  
  370. CEditToolBarController::~CEditToolBarController()
  371. {
  372.     if( m_pCharacterToolbar )
  373.         delete m_pCharacterToolbar;
  374. }
  375.  
  376. BOOL CEditToolBarController::CreateEditBars(MWContext *pMWContext, unsigned ett)
  377. {
  378.     // Initialize things needed by both CNetscapeEditFrame and CComposeFrame
  379.     CGenericFrame *pParent = (CGenericFrame*)GetParent();
  380.  
  381.     if (ett & DISPLAY_EDIT_TOOLBAR) {
  382.         CButtonToolbarWindow *pWindow;
  383.         BOOL bOpen, bShowing;
  384.         int32 nPos;
  385.  
  386.         //I'm hardcoding because I don't want this translated
  387.         pParent->GetChrome()->LoadToolbarConfiguration(IDS_EDIT_TOOLBAR_CAPTION, CString("Composition_Toolbar"),nPos, bOpen, bShowing);
  388.  
  389.         // Add a customizable toolbar
  390.         LPNSTOOLBAR pIToolBar;
  391.         pParent->GetChrome()->QueryInterface( IID_INSToolBar, (LPVOID *) &pIToolBar );
  392.         if ( pIToolBar ) {
  393.             pIToolBar->Create( pParent, WS_CHILD|WS_CLIPCHILDREN|WS_VISIBLE|CBRS_TOP );
  394.             pIToolBar->SetButtons( nIDEditBarArray, EDITBAR_ID_COUNT );
  395.             // Set menu/toolbar popup styles for specific buttons:
  396.             pIToolBar->SetButtonStyle(ID_EDT_NEW_DOC_BLANK, TB_HAS_TIMED_MENU);
  397.             pIToolBar->SetButtonStyle(ID_FILE_OPEN, TB_HAS_TIMED_MENU);
  398.             pIToolBar->SetButtonStyle(ID_FILE_PRINT, TB_HAS_TIMED_MENU);
  399.             
  400.             // First pair are actually ignored! Second is bitmap size
  401.             pIToolBar->SetSizes( CSize( 29, 27 ), CSize( 23, 21 ) );
  402.             pIToolBar->LoadBitmap( MAKEINTRESOURCE( IDB_FILE_PICT_TOOLBAR ) );
  403.             pIToolBar->SetToolbarStyle( theApp.m_pToolbarStyle );
  404.             pWindow = new CButtonToolbarWindow(CWnd::FromHandlePermanent(pIToolBar->GetHWnd()), theApp.m_pToolbarStyle, 43, 27, eLARGE_HTAB);
  405.             pParent->GetChrome()->GetCustomizableToolbar()->AddNewWindow(IDS_EDIT_TOOLBAR_CAPTION, pWindow,nPos, 50, 37, 0, CString(szLoadString(IDS_EDIT_TOOLBAR_CAPTION)),theApp.m_pToolbarStyle, bOpen, FALSE);
  406.             pParent->GetChrome()->ShowToolbar(IDS_EDIT_TOOLBAR_CAPTION, bShowing);
  407.                pIToolBar->Release();
  408.         }
  409.     }
  410.  
  411.     // Character Format toolbar
  412.     if( ett & DISPLAY_CHARACTER_TOOLBAR ){
  413.         // We don't use the "Insert Object" last item if we are displaying the edit toolbar,
  414.         //  which has these items
  415.         if (!m_wndCharacterBar.Create(ett & DISPLAY_EDIT_TOOLBAR, GetParent(), IDW_PARA_TOOLBAR, IDS_CHAR_TOOLBAR_CAPTION,
  416.                                    nIDCharacterBarArray, CHARBAR_ID_COUNT,
  417.                                    IDB_NEW_FORMAT_TOOLBAR,
  418.                                    CSize(8, ED_TB_BUTTON_HEIGHT),
  419.                                    CSize(1,ED_TB_BITMAP_HEIGHT) ) )
  420.             return FALSE;
  421.         m_pCharacterToolbar = CreateCharacterToolbar((ett & DISPLAY_EDIT_TOOLBAR) ?  CHARBUTTONBAR_ID_COUNT-1 : CHARBUTTONBAR_ID_COUNT);
  422.  
  423.         m_wndCharacterBar.SetCNSToolbar(m_pCharacterToolbar);
  424.  
  425.  
  426.         // Paragraph styles Combo
  427.         CRect rect;
  428.         rect.SetRectEmpty();  //Don't need size to create it
  429.  
  430.         if (!m_ParagraphCombo.Create(CBS_DROPDOWNLIST|WS_VISIBLE|WS_TABSTOP|WS_VSCROLL,
  431.                                      rect, &m_wndCharacterBar, ID_COMBO_PARA))
  432.         {
  433.             TRACE0("Failed to create paragraph format combo-box\n");
  434.             return FALSE;
  435.         }
  436.  
  437.         // Font Face Combo
  438.         if (!m_FontFaceCombo.Create(rect, &m_wndCharacterBar, ID_COMBO_FONTFACE))
  439.         {
  440.             return FALSE;
  441.         }
  442.  
  443.         // Font Size Combo      
  444.         if (!m_FontSizeCombo.Create(rect, &m_wndCharacterBar, ID_COMBO_FONTSIZE))
  445.         {
  446.             TRACE0("Failed to create Font Size combo-box\n");
  447.             return FALSE;
  448.         }
  449.  
  450.         if ( wfe_pFont ){
  451.             m_ParagraphCombo.SetFont(wfe_pFont);
  452.             //Other combos are CNSComboBox and have font set in Create or Subclass calls
  453.         }
  454.  
  455.         if( !m_FontColorCombo.CreateAndFill(rect, &m_wndCharacterBar,
  456.                                             ID_COMBO_FONTCOLOR, DEFAULT_COLORREF) ){
  457.             return FALSE;
  458.         }
  459.  
  460.         //  Fill the other combo boxes
  461.         CString csTemp;
  462.         // Paragraph - Get maximum width while loading strings
  463.         int iMaxParaWidth = 0;
  464.         CDC *pDC = m_ParagraphCombo.GetDC();
  465.         CSize cSize;
  466.         int wincsid = INTL_CharSetNameToID(INTL_ResourceCharSet());
  467.         for ( int i = 0; FEED_nParagraphTags[i] != P_UNKNOWN; i++ ){
  468.             if (csTemp.LoadString(CASTUINT(ID_LIST_TEXT_PARAGRAPH_BASE+FEED_nParagraphTags[i]))){
  469.                 m_ParagraphCombo.AddString((LPCTSTR)csTemp);
  470.                 if ( pDC ){            
  471.                     cSize = CIntlWin::GetTextExtent(wincsid, pDC->GetSafeHdc(), csTemp, csTemp.GetLength());
  472.                     pDC->LPtoDP(&cSize);
  473.                     if ( cSize.cx > iMaxParaWidth ){
  474.                         iMaxParaWidth = cSize.cx;
  475.                     }
  476.                 }
  477.             }
  478.         }
  479.         csTemp = "55";
  480.         cSize = CIntlWin::GetTextExtent(wincsid, pDC->GetSafeHdc(), csTemp, csTemp.GetLength());
  481.         pDC->LPtoDP(&cSize);
  482.         // Save the full height of this font
  483.         wfe_iFontHeight = cSize.cy;
  484.         
  485.         // Calculate list item height from font size and store in global variable
  486.         // Trim 1 pixel off height to fit more items in the list
  487.         wfe_iListItemHeight = wfe_iFontHeight - 1;
  488.         int iFontSizeWidth = cSize.cx + sysInfo.m_iScrollWidth + 6;
  489.  
  490.         m_ParagraphCombo.ReleaseDC(pDC);
  491.  
  492.         // Initialize app-global list of TrueType fonts
  493.         //  and fill the toolbar combo with all font strings
  494.         // WARNING: This is a user-draw listbox and pointers to font-name strings
  495.         //          must be STATIC 
  496.         pDC = m_FontFaceCombo.GetDC();
  497.         wfe_InitTrueTypeArray(pDC);
  498.         int iMaxFontWidth = 0;
  499.         wfe_iFontFaceOtherIndex = wfe_FillFontComboBox(&m_FontFaceCombo, &iMaxFontWidth);
  500.         // ??? "NEEDED ONLY IF NOT A WINDOW"
  501.         m_FontFaceCombo.ReleaseDC(pDC);
  502.  
  503.         // Font Size
  504.         // This gets filled on every call to open the combobox
  505.         wfe_FillFontSizeCombo(pMWContext, &m_FontSizeCombo);
  506.  
  507.         m_FontFaceCombo.SetCurSel(0);         // show the first entry 
  508.  
  509.         // Now that we have a font, we can set the full size of comboboxes
  510.         // The order of these calls determine order of appearence in toolbar
  511.         // Use 0 for height (param 5) to let class figure out optimal height
  512.         // Note that we use Scroll Width to get size of combobox since users
  513.         //  can change that in Win95 and NT4.0 and that size determines width
  514.         //  of combobox dropdown button
  515.         m_wndCharacterBar.SetComboBox( ID_COMBO_PARA, &m_ParagraphCombo, 
  516.                                        sysInfo.m_iScrollWidth+61, iMaxParaWidth + 4, 0 );
  517.         m_ParagraphCombo.SetCurSel(0);
  518.  
  519.         int iWidth = sysInfo.m_iScrollWidth;
  520.         // Allow wider closed-combo-size when screen width is > 640
  521.         // (We can't test pMWContext->bIsComposeWindow, it is not set at this stage)
  522.         if( sysInfo.m_iScreenWidth <= 640 || !(ett & DISPLAY_EDIT_TOOLBAR) ){
  523.             // We are in Message Composer - use fixed width
  524.             iWidth += 80;
  525.         } else {
  526.             // Add width of 1st string so it displays fully in closed combobox
  527.             pDC = m_FontFaceCombo.GetDC();
  528.             if ( pDC ){
  529.                 csTemp = XP_GetString(XP_NSFONT_DEFAULT);            
  530.                 cSize = CIntlWin::GetTextExtent(wincsid, pDC->GetSafeHdc(), csTemp, csTemp.GetLength());
  531.                 pDC->LPtoDP(&cSize);
  532.                 // but never smaller than 90 so other long names show better 
  533.                 // in Win16/NT3.51, which can't expand width of dropdown
  534.                 iWidth += max(90, cSize.cy);
  535.                 m_FontFaceCombo.ReleaseDC(pDC);
  536.             } else {
  537.                 iWidth += 90;
  538.             }
  539.         }
  540.         m_wndCharacterBar.SetComboBox( ID_COMBO_FONTFACE, &m_FontFaceCombo, 
  541.                                        iWidth, iMaxFontWidth, 0 );
  542.  
  543.  
  544.         m_wndCharacterBar.SetComboBox( ID_COMBO_FONTSIZE, &m_FontSizeCombo, 
  545.                                        iFontSizeWidth /*sysInfo.m_iScrollWidth+20*/, 0, 0 );
  546.         m_FontSizeCombo.SetCurSel(2); // Initialize with the "default" size - 3rd in list
  547.  
  548.         // Set the color combobox data
  549.         m_wndCharacterBar.SetComboBox( ID_COMBO_FONTCOLOR, &m_FontColorCombo, 
  550.                                        sysInfo.m_iScrollWidth+16, 0, 0);
  551.         m_FontColorCombo.SetCurSel(0); // Initialize with default color
  552.  
  553.         // Make the Alignment and "Insert Object" buttons do their actions on button down
  554.         //  Used to popup a CDropDownToolbar
  555.         m_wndCharacterBar.SetDoOnButtonDown(ID_ALIGN_POPUP, TRUE);
  556.         m_wndCharacterBar.SetDoOnButtonDown(ID_INSERT_POPUP, TRUE);
  557.  
  558.  
  559. #ifdef XP_WIN16
  560.         // This will add tooltips for Win16
  561.         m_wndCharacterBar.RecalcLayout();
  562. #endif
  563.     }
  564.  
  565.     return TRUE;
  566. }
  567.  
  568. CCommandToolbar* CEditToolBarController::CreateCharacterToolbar(int nCount)
  569. {
  570.     CCommandToolbar *pCharToolbar =new CCommandToolbar(15, theApp.m_pToolbarStyle, 43, 25 /*27*/, 25 /*27*/);
  571.  
  572.     if (!pCharToolbar->Create(GetParent()))
  573.     {
  574.             return FALSE;
  575.     }
  576.  
  577.     pCharToolbar->SetBitmap(IDB_CHAR_FORMAT_TOOLBAR);
  578.  
  579.     CString statusStr, toolTipStr, textStr;
  580.     int nBitmapIndex = 0;
  581.  
  582.     for(int i = 0; i < nCount; i++)
  583.     {
  584.         CCommandToolbarButton *pCommandButton = new CCommandToolbarButton;
  585.  
  586.         WFE_ParseButtonString(nIDCharButtonBarArray[i], statusStr, toolTipStr, textStr);
  587.  
  588.         pCommandButton->Create(pCharToolbar, TB_PICTURES, 
  589.                         CSize(44, 37)/*novice size*/, CSize(25, 25) /*advanced size*/,
  590.                         "",(const char*) toolTipStr, (const char*) statusStr,
  591.                         IDB_CHAR_FORMAT_TOOLBAR, i, CSize(20,18)/*Bitmap size*/, 
  592.                         nIDCharButtonBarArray[i], -1, (DWORD)0/*button style*/);
  593.  
  594.         pCommandButton->SetPicturesOnly(TRUE);
  595.         pCommandButton->SetBitmap(pCharToolbar->GetBitmap(), TRUE);
  596.  
  597.         pCharToolbar->AddButton(pCommandButton, i);
  598.     }
  599.  
  600.  
  601.     return pCharToolbar;
  602. }
  603.  
  604. int CEditToolBarController::GetSelectedFontFaceIndex()
  605. {
  606.     int iSel = m_FontFaceCombo.GetCurSel();
  607.     if( wfe_iFontFaceOtherIndex && iSel == wfe_iFontFaceOtherIndex ){
  608.         return INDEX_OTHER;
  609.     }
  610.     return iSel;
  611. }
  612.  
  613. int CEditToolBarController::GetSelectedFontColorIndex()
  614. {
  615.     int iSel = m_FontColorCombo.GetCurSel();
  616.     if( m_iFontColorOtherIndex && iSel == m_iFontColorOtherIndex ){
  617.         return INDEX_OTHER;
  618.     }
  619.     return iSel;
  620. }
  621.  
  622. void CEditToolBarController::ShowToolBar( BOOL bShow, CComboToolBar * pToolBar)
  623. {
  624.     ASSERT(m_pWnd);
  625.     ASSERT(pToolBar);
  626.     CFrameWnd * pFrame = pToolBar->GetParentFrame();
  627.  
  628.     if ( pFrame != m_pWnd ) {
  629.         // Parent frame isn't toolbar Controller - must be a floating "MiniFrame"
  630.         pFrame->ShowWindow(bShow ? SW_SHOW : SW_HIDE);
  631.     }
  632.     // Do this even if we have mini-frame because we use
  633.     //  the toolbar's show state to tell us current visibility
  634.     pToolBar->ShowWindow(bShow ? SW_SHOW : SW_HIDE);
  635.     pFrame->RecalcLayout();
  636. }
  637.  
  638. /////////////////////////////////////////////////////////////////////////////
  639. // CEditFrame
  640.  
  641. #undef new
  642. IMPLEMENT_DYNCREATE(CEditFrame, CMainFrame)
  643. #define new DEBUG_NEW
  644.  
  645. BEGIN_MESSAGE_MAP(CEditFrame, CMainFrame)
  646.     //{{AFX_MSG_MAP(CEditFrame)
  647.     ON_MESSAGE(WM_TOOLCONTROLLER,OnToolController)
  648.     ON_WM_CREATE()
  649.     ON_WM_INITMENUPOPUP()
  650.     ON_WM_CLOSE()
  651.     ON_COMMAND(ID_FILE_CLOSE, OnFileClose)
  652.     ON_WM_QUERYENDSESSION()
  653.     ON_COMMAND(ID_EDIT_WINDOW_BOOKMARKS, OnShowBookmarkWindow) // Override CMainFrame
  654.     //}}AFX_MSG_MAP
  655.     ON_MESSAGE(WM_SETMESSAGESTRING, OnSetMessageString)
  656.     ON_MESSAGE(NSBUTTONMENUOPEN, OnButtonMenuOpen)
  657. END_MESSAGE_MAP()
  658.  
  659.  
  660. /////////////////////////////////////////////////////////////////////////////
  661. CEditFrame::CEditFrame()
  662. {
  663.     m_pToolBarController = new CEditToolBarController( this );
  664.     m_hPal = NULL;
  665.     m_pTemplateContext = NULL;
  666.     m_bImportTextFile = FALSE;
  667. }
  668.  
  669. CEditFrame::~CEditFrame()
  670. {
  671.     delete m_pToolBarController;
  672. }
  673.  
  674. /////////////////////////////////////////////////////////////////////////////
  675. // CEditFrame diagnostics
  676.  
  677. #ifdef _DEBUG
  678. void CEditFrame::AssertValid() const
  679. {
  680.     CMainFrame::AssertValid();
  681. }
  682.  
  683. void CEditFrame::Dump(CDumpContext& dc) const
  684. {
  685.     CMainFrame::Dump(dc);
  686. }
  687.  
  688. #endif //_DEBUG
  689.  
  690. /////////////////////////////////////////////////////////////////////////////
  691. // CEditFrame member functions
  692. BOOL CEditFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext *pContext)
  693. {
  694.     // Call the base - it creates our CWinCX context
  695.     return CMainFrame::OnCreateClient(lpcs, pContext);
  696.  
  697.     //  We don't need to set the context flag since it is now
  698.     //  set in CMainFrame::OnCreateClient() [framinit.cpp]
  699.     //  because of a SetFocus() call done there, which needs to have
  700.     //  is_editor already set to avoid JavaScript message problems
  701. #if 0
  702.     if(bRetval == TRUE)     {
  703.         CWinCX * pContext = GetMainWinContext();
  704.         ASSERT( pContext );
  705.         // Tell net and stream processors that we are an editor
  706.         MWContext * pMWContext = pContext->GetContext();
  707.         ASSERT( pMWContext );
  708.         pMWContext->is_editor = TRUE;
  709.     }
  710.  
  711.     return bRetval;
  712. #endif
  713. }
  714.  
  715. void CEditFrame::DockControlBarLeftOf(CToolBar* Bar,CToolBar* LeftOf)
  716. {
  717. #ifdef XP_WIN32
  718.     CRect rect;
  719.     DWORD dw;
  720.     UINT n;
  721.  
  722.     // get MFC to adjust the dimensions of all docked ToolBars
  723.     // so that GetWindowRect will be accurate
  724.     RecalcLayout();
  725.  
  726.     LeftOf->GetWindowRect(&rect);
  727.     rect.OffsetRect(10,10);
  728.     dw=LeftOf->GetBarStyle();
  729.     n = 0;
  730.     n = (dw&CBRS_ALIGN_TOP) ? AFX_IDW_DOCKBAR_TOP : n;
  731.     n = (dw&CBRS_ALIGN_BOTTOM && n==0) ? AFX_IDW_DOCKBAR_BOTTOM : n;
  732.     n = (dw&CBRS_ALIGN_LEFT && n==0) ? AFX_IDW_DOCKBAR_LEFT : n;
  733.     n = (dw&CBRS_ALIGN_RIGHT && n==0) ? AFX_IDW_DOCKBAR_RIGHT : n;
  734.  
  735.     // When we take the default parameters on rect, DockControlBar will dock
  736.     // each Toolbar on a seperate line.  By calculating a rectangle, we in effect
  737.     // are simulating a Toolbar being dragged to that location and docked.
  738.     DockControlBar(Bar,n,&rect);
  739. #endif
  740. }
  741.  
  742. /////////////////////////////////////////////////////////////////////////////
  743. // CEditFrame message handlers
  744.  
  745. int CEditFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  746. {
  747.     // Most of the work is done in base class
  748.     if (CMainFrame::OnCreate(lpCreateStruct) == -1)
  749.         return -1;
  750.  
  751.     ASSERT(m_pToolBarController);
  752.  
  753.     GetChrome()->CreateCustomizableToolbar("Composer"/*ID_COMPOSER*/, 2, FALSE);
  754.  
  755.     if ( !m_pToolBarController->CreateEditBars(GetMainContext()->GetContext()) )
  756.         return -1;      // fail to create
  757.  
  758.     // Need to do this to get accurate toolbar size info
  759.     RecalcLayout();
  760.  
  761.     CControlBarToolbarWindow *pWindow;
  762.     BOOL bOpen, bShowing;
  763.     int32 nPos;
  764.  
  765.     //putterman: I'm hardcoding because I don't want this translated
  766.     GetChrome()->LoadToolbarConfiguration(IDS_CHAR_TOOLBAR_CAPTION, CString("Formatting_Toolbar"), nPos, bOpen, bShowing);
  767.  
  768.     pWindow = new CControlBarToolbarWindow(m_pToolBarController->GetCharacterBar(), theApp.m_pToolbarStyle, 43, 27, eLARGE_HTAB);
  769.     GetChrome()->GetCustomizableToolbar()->AddNewWindow(IDS_CHAR_TOOLBAR_CAPTION, pWindow,nPos, 50, 37, 0, CString(szLoadString(IDS_CHAR_TOOLBAR_CAPTION)),theApp.m_pToolbarStyle, bOpen, FALSE);
  770.     GetChrome()->ShowToolbar(IDS_CHAR_TOOLBAR_CAPTION, bShowing);
  771.  
  772.     GetChrome()->SetWindowTitle(szLoadString(IDS_NETSCAPE_COMPOSER));
  773.     SetCursor(theApp.LoadStandardCursor(IDC_WAIT));
  774.     
  775.     // Attach the submenus shared by Composer, Message Composer, and right-button popups
  776.     HMENU hMenu = ::GetMenu(m_hWnd);
  777.     if( hMenu )
  778.     {
  779.         HMENU hTableMenu = ::GetSubMenu(hMenu, ED_MENU_TABLE);
  780.         if( hTableMenu )
  781.         {
  782.             ::ModifyMenu( hTableMenu, ID_SELECT_TABLE, MF_BYCOMMAND | MF_POPUP | MF_STRING,
  783.                           (UINT)::LoadMenu(AfxGetResourceHandle(), MAKEINTRESOURCE(IDM_COMPOSER_TABLE_SELECTMENU)),
  784.                           szLoadString(IDS_SUBMENU_SELECT_TABLE) );
  785.             ::ModifyMenu( hTableMenu, ID_INSERT_TABLE, MF_BYCOMMAND | MF_POPUP | MF_STRING,
  786.                           (UINT)::LoadMenu(AfxGetResourceHandle(), MAKEINTRESOURCE(IDM_COMPOSER_TABLE_INSERTMENU)),
  787.                           szLoadString(IDS_SUBMENU_INSERT_TABLE) );
  788.             ::ModifyMenu( hTableMenu, ID_DELETE_TABLE, MF_BYCOMMAND | MF_POPUP | MF_STRING,
  789.                           (UINT)::LoadMenu(AfxGetResourceHandle(), MAKEINTRESOURCE(IDM_COMPOSER_TABLE_DELETEMENU)),
  790.                           szLoadString(IDS_SUBMENU_DELETE_TABLE) );
  791.         }
  792.     }
  793.     return 0;
  794. }
  795.  
  796. // Global function so we can use it in CComposeFrame as well
  797. // Returns TRUE only if message was supplied
  798. BOOL edt_GetMessageString(CView * pView, UINT MenuID, CString& Message)
  799. {
  800.     if (MenuID >= ID_EDITOR_PLUGINS_BASE && MenuID < (ID_EDITOR_PLUGINS_BASE + MAX_EDITOR_PLUGINS))
  801.     {
  802.         uint32 CategoryId, PluginId;
  803.         CNetscapeEditView *pEditView = (CNetscapeEditView *)pView;
  804.         ASSERT(pView != NULL && pView->IsKindOf(RUNTIME_CLASS(CNetscapeEditView)));
  805.  
  806.         if (pEditView->GetPluginInfo(MenuID, &CategoryId, &PluginId))
  807.             Message = EDT_GetPluginMenuHelp(CategoryId, PluginId);
  808.         return TRUE;
  809.     }
  810.     else if (MenuID >= ID_EDIT_HISTORY_BASE && MenuID < (ID_EDIT_HISTORY_BASE + MAX_EDIT_HISTORY_LOCATIONS) )
  811.     {
  812.         char * pStatusTitle = NULL;
  813.         // Get the string for Page Title associated with menu item (which shows the URL)
  814.         //  (NULL means we don't need to get the URL string)
  815.         if( EDT_GetEditHistory( ((CGenericView*)pView)->GetContext()->GetContext(), 
  816.                                 MenuID-ID_EDIT_HISTORY_BASE, NULL, &pStatusTitle) )
  817.         {
  818.             Message = pStatusTitle;
  819.             return TRUE;
  820.         }
  821.     }
  822.     return FALSE;
  823. }
  824.  
  825. // Helper to test for dynamic menus shared by Page and Message Composer frame windows
  826. BOOL edt_IsEditorDynamicMenu(WPARAM wParam)
  827. {
  828.     return( (wParam >= ID_EDITOR_PLUGINS_BASE && wParam < (ID_EDITOR_PLUGINS_BASE + MAX_EDITOR_PLUGINS)) ||
  829.             (wParam >= ID_EDIT_HISTORY_BASE && wParam < (ID_EDIT_HISTORY_BASE + MAX_EDIT_HISTORY_LOCATIONS)) );
  830. }
  831.  
  832. // GetMessageString - Override of CFrameWnd virtual. It sets the menu help strings for the 
  833. // dynamically loaded editor plugins.
  834. void CEditFrame::GetMessageString(UINT MenuID, CString& Message) const
  835. {
  836.     if( edt_GetMessageString(GetActiveView(), MenuID, Message) )
  837.         return;
  838.  
  839.     CMainFrame::GetMessageString(MenuID, Message);
  840. }
  841.  
  842. // OnSetMessageString - Override of CMainFrame's WM_SETMESSAGESTRING message handler. We need this 
  843. // because the base class (actually CGenericFrame) is supressing the dynamically created menu help
  844. // strings for Composer
  845. LRESULT CEditFrame::OnSetMessageString(WPARAM wParam, LPARAM lParam)
  846. {
  847.     if( edt_IsEditorDynamicMenu(wParam) )
  848.         return CFrameWnd::OnSetMessageString(wParam, lParam);
  849.     else
  850.         return CMainFrame::OnSetMessageString(wParam, lParam);
  851. }
  852.  
  853. LONG CEditFrame::OnToolController(UINT,LONG)
  854. {
  855.     return (LONG)m_pToolBarController;
  856. }
  857.  
  858. void CEditFrame::OnShowBookmarkWindow()
  859. {
  860.     XP_Bool prefBool;
  861.     PREF_GetBoolPref("editor.hints.bookmark",&prefBool);
  862.  
  863.     if ( prefBool ){
  864.         // Show a "Hint" dialog about drag and drop until
  865.         //   user checks "Don't show this" in dialog
  866.         CEditHintDlg dlg(this, IDS_DRAG_BOOKMARK_HINT);
  867.  
  868.         dlg.DoModal();
  869.         if ( dlg.m_bDontShowAgain ) {
  870.             PREF_SetBoolPref("editor.hints.bookmark",FALSE);
  871.         }
  872.     }
  873.     CGenericFrame::OnShowBookmarkWindow();
  874. }
  875.  
  876.  
  877. // Handy dandy routine to get a preference and prompt
  878. //  user to set it in Editor Preferences if it does
  879. //  not already exist
  880. char* CEditFrame::GetLocationFromPreferences(const char *pPrefName, UINT nID_Msg, UINT nID_Caption, UINT nID_FileCaption)
  881. {
  882.     if( pPrefName == NULL ){
  883.         return NULL;
  884.     }
  885.  
  886.     char *pLocation = NULL;
  887.     PREF_CopyCharPref(pPrefName, &pLocation);
  888.  
  889.     if( pLocation == NULL || pLocation[0] == '\0' ){
  890.         // Popup dialog to allow user to set location now
  891.         CGetLocationDlg dlg(this, nID_Msg, nID_Caption, nID_FileCaption);
  892.         if(dlg.DoModal() == IDOK){
  893.             if( !dlg.m_csLocation.IsEmpty() ){
  894.                 pLocation = XP_STRDUP((char*)LPCSTR(dlg.m_csLocation));
  895.                 PREF_SetCharPref(pPrefName, pLocation);
  896.             }
  897.         }
  898.     }
  899.  
  900.     if( pLocation && pLocation[0] == '\0' ){
  901.         XP_FREE(pLocation);
  902.         return NULL;
  903.     }
  904.  
  905.     return pLocation;
  906. }
  907.  
  908. void CEditFrame::OnClose() 
  909. {
  910.     MWContext *pMWContext;
  911.     if( GetMainContext() == NULL ||
  912.         (pMWContext = GetMainContext()->GetContext()) == NULL )
  913.         return;
  914.  
  915.     // Stop any active plugin
  916.     if (!CheckAndCloseEditorPlugin(pMWContext)) 
  917.         return;
  918.  
  919.      // Ignore close if we are doing something
  920.     if(pMWContext->edit_saving_url ||
  921.        pMWContext->waitingMode ||
  922.        (EDT_IsBlocked(pMWContext) &&LO_GetEDBuffer(pMWContext))//if we dont have an edit buffer, we should not be blocked from closing!
  923.         ) {
  924.         return;
  925.     }
  926.     
  927.     // The CGenericFrame flag should be respected only for
  928.     //  one attempt to close, so clear it here
  929.     BOOL bPromptForSaving = !m_bSkipSaveEditChanges;
  930.     m_bSkipSaveEditChanges = FALSE;
  931.     
  932.     // Check for changes to doc and prompt to save:    
  933.     // except if we are a new document AND nothing was ever edited,
  934.     //   don't prompt to save it
  935.     // Don't close if user cancels when prompted to save
  936.     if( LO_GetEDBuffer( ABSTRACTCX(pMWContext)->GetDocumentContext() ) ){
  937.         if( bPromptForSaving && 
  938.             !FE_CheckAndSaveDocument(pMWContext) ){
  939.             return;
  940.         }
  941.             History_entry * hist_entry = SHIST_GetCurrent(&(pMWContext ->hist));
  942.         EDT_PreClose(pMWContext,hist_entry ? hist_entry->address: NULL,
  943.                          RealCloseS,(void *)this);
  944.         return;
  945.     }
  946.   RealClose();
  947. }
  948.  
  949. void CEditFrame::RealCloseS(void* hook) {
  950.   CEditFrame *pEdFrame = (CEditFrame *)hook;
  951.   if (!pEdFrame) {
  952.     ASSERT(0);
  953.     return;
  954.   }
  955.   pEdFrame->RealClose();  
  956. }
  957.  
  958. void CEditFrame::RealClose() {
  959.   MWContext *pMWContext;
  960.   if( GetMainContext() == NULL ||
  961.       (pMWContext = GetMainContext()->GetContext()) == NULL )
  962.     return;
  963.  
  964.   if( LO_GetEDBuffer( ABSTRACTCX(pMWContext)->GetDocumentContext() ) ){
  965.     EDT_DestroyEditBuffer(pMWContext);
  966.   }
  967.  
  968.   //I'm hardcoding because I don't want this translated
  969.   GetChrome()->SaveToolbarConfiguration(IDS_EDIT_TOOLBAR_CAPTION, CString("Composition_Toolbar"));
  970.   GetChrome()->SaveToolbarConfiguration(IDS_CHAR_TOOLBAR_CAPTION, CString("Formatting_Toolbar"));
  971.  
  972.   CMainFrame::OnClose();  
  973. }
  974.  
  975. void CEditFrame::OnFileClose() 
  976. {
  977.     MWContext *pMWContext;
  978.     if( GetMainContext() == NULL ||
  979.     (pMWContext = GetMainContext()->GetContext()) == NULL )
  980.     return;
  981.  
  982.     // Stop any active plugin
  983.     if (!CheckAndCloseEditorPlugin(pMWContext)) 
  984.         return;
  985.  
  986.     if ( FE_CheckAndSaveDocument(pMWContext) ) {
  987.         m_bSkipSaveEditChanges = TRUE;
  988.         CMainFrame::OnFrameExit();
  989.     }
  990. }
  991.  
  992. BOOL CEditFrame::OnQueryEndSession() 
  993. {
  994.     if (!CMainFrame::OnQueryEndSession())
  995.         return FALSE;
  996.     
  997.     MWContext *pMWContext;
  998.     if( GetMainContext() == NULL ||
  999.     (pMWContext = GetMainContext()->GetContext()) == NULL )
  1000.     return TRUE;
  1001.  
  1002.     // Returns FALSE if user cancels from dialog - stops shutdown
  1003.     return FE_CheckAndSaveDocument(pMWContext);
  1004. }
  1005.  
  1006. // These are Frame load/creation routines for editor, formerly in GENFRAME.CPP
  1007.  
  1008. // Get pointer to URL passed from 2nd instance
  1009. char* GetGlobalUrlPointer(HANDLE handle) {
  1010.     char * pUrl = NULL;
  1011. #ifdef WIN32
  1012.     // Read URL from memory-mapped file and load it
  1013.     handle = OpenFileMapping(FILE_MAP_READ | FILE_MAP_WRITE, TRUE, szNGMemoryMapFilename);
  1014.  
  1015.     if (NULL != handle) {
  1016.         char * szFile = (char*)MapViewOfFile(handle, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0);
  1017.         if (szFile ) {
  1018.             pUrl = XP_STRDUP(szFile);
  1019.         } else {
  1020.             TRACE1( "OpenFileMapping error: %u\n", GetLastError() );
  1021.         }
  1022.         CloseHandle(handle);
  1023.     }
  1024.  
  1025. #else
  1026.     pUrl = (char*)GlobalLock(handle);
  1027. #endif
  1028.     return pUrl;
  1029. }
  1030.  
  1031. // Save the last-use template URL
  1032. //  to our list of recently-accessed templates
  1033. //  Call from FE_EditorGetUrlExitRoutine after template successfully loaded
  1034. void  CEditFrame::SaveTemplateLocation(char *pLastLoc)
  1035. {
  1036.     int iToBeMoved = -1;
  1037.     char szLocName[32];
  1038.     char szLocation[256];
  1039.     int iLen = 256;
  1040.     char * pLastLocation = NULL;
  1041.     int i;
  1042.  
  1043.     if( pLastLoc ){
  1044.         pLastLocation = XP_STRDUP(pLastLoc);
  1045.     } else {
  1046.         PREF_CopyCharPref("editor.template_last_loc",&pLastLocation);
  1047.     }
  1048.     if( !pLastLocation ){
  1049.         return;
  1050.     }
  1051.  
  1052.     // First scan the list to find pref that matches new item
  1053.     for( i = 0; i < theApp.m_iTemplateLocationCount; i++ ){
  1054.         wsprintf(szLocName,"editor.template_history_%d",i);
  1055.         PREF_GetCharPref(szLocName,szLocation,&iLen);
  1056.         
  1057.         if( 0 == strcmp(szLocation,pLastLocation) ){
  1058.             // URL is already in the list
  1059.             if (i ==0) 
  1060.                 // It is already at the start of list,
  1061.                 // so there's nothing more to do!
  1062.                 return;
  1063.  
  1064.             iToBeMoved = i;
  1065.             break;
  1066.         }
  1067.     }
  1068.  
  1069.     // If our list was already at the limit, we will delete the oldest item
  1070.     if( theApp.m_iTemplateLocationCount >= MAX_TEMPLATE_LOCATIONS ){
  1071.         theApp.m_iTemplateLocationCount = MAX_TEMPLATE_LOCATIONS;
  1072.     } else if( iToBeMoved == -1 ){
  1073.         // We will be adding 1 new item        
  1074.         theApp.m_iTemplateLocationCount++;
  1075.     }
  1076.  
  1077.     // Start at 1 less than new count or item to-be-deleted
  1078.     // that is, start at the number to be replaced after
  1079.     // adjusting for the zero index
  1080.     int iStart;
  1081.     if (iToBeMoved > 0){
  1082.         iStart = iToBeMoved;
  1083.     } else {
  1084.         iStart = theApp.m_iTemplateLocationCount-1;
  1085.     }
  1086.     
  1087.     for( i = iStart; i > 0; i-- ){
  1088.         // iterate backwards and move everything up 1 position
  1089.         wsprintf(szLocName, "editor.template_history_%d", i-1);
  1090.         PREF_GetCharPref(szLocName, szLocation, &iLen);
  1091.  
  1092.         wsprintf(szLocName, "editor.template_history_%d", i);
  1093.  
  1094.         PREF_SetCharPref(szLocName,szLocation);
  1095.     }
  1096.  
  1097.     // Add the new item to list
  1098.     wsprintf(szLocName, "editor.template_history_%d", 0);
  1099.  
  1100.     PREF_SetCharPref(szLocName, pLastLocation);
  1101.  
  1102.     if (pLastLocation) XP_FREE(pLastLocation);
  1103. }
  1104.  
  1105. // Route toolbar menu messages to edit view
  1106. LRESULT CEditFrame::OnButtonMenuOpen(WPARAM wParam, LPARAM lParam)
  1107. {
  1108.     if( GetMainWinContext()){
  1109.         return ::SendMessage( GetMainWinContext()->GetPane(), NSBUTTONMENUOPEN, wParam, lParam);
  1110.     }
  1111.     return 0;
  1112. }
  1113.  
  1114.  
  1115. //////////////////////////////////////////////////////////////////////
  1116. // Frame load/creation methods
  1117. //      Prototypes of CGenericFrame functions are in GENFRAME.H
  1118. //
  1119. int FindCurrentUrlInHistory(MWContext * pMWcontext, char * szAddress)
  1120. {
  1121.     if(!pMWcontext)
  1122.         return 0;
  1123.  
  1124.     XP_List * list_ptr;
  1125.     History_entry *pEntry;
  1126.     int nIndex = 0;
  1127.     list_ptr = pMWcontext->hist.list_ptr;
  1128.     
  1129.     while((pEntry = (History_entry *) XP_ListNextObject(list_ptr))!=0) {
  1130.         nIndex++;
  1131.         if (0 == XP_STRCMP(pEntry->address, szAddress )) {
  1132.             return nIndex;
  1133.         }
  1134.     }
  1135.     // If no match found:
  1136.     return 0;
  1137. }
  1138.  
  1139. // Use this to activate a Navigator or Editor frame instead 
  1140. //   of creating a new one.
  1141. MWContext * FE_ActivateFrameWithURL(char * pUrl, BOOL bFindEditor)
  1142. {
  1143.     if ( pUrl == NULL ) {
  1144.         return NULL;
  1145.     }
  1146.  
  1147.     for(CGenericFrame * f = theApp.m_pFrameList; f; f = f->m_pNext) {
  1148.         MWContext *pMWContext = f->GetMainContext()->GetContext();
  1149.  
  1150.         if ( pMWContext && 
  1151.              (bFindEditor && EDT_IS_EDITOR(pMWContext)) ||
  1152.              (!bFindEditor && !EDT_IS_EDITOR(pMWContext)) ) {
  1153.             History_entry * pEntry = SHIST_GetCurrent(&pMWContext->hist);
  1154.             if( pEntry && pEntry->address && EDT_IsSameURL(pEntry->address, pUrl,0,0) )
  1155.             {
  1156.                 if ( f->IsIconic() ){
  1157.                     f->ShowWindow(SW_RESTORE);
  1158.                 }
  1159.                 f->SetActiveWindow();
  1160.                 // Don't close the frame
  1161.                 f->m_bCloseFrame = FALSE;
  1162.                 return pMWContext;
  1163.             }
  1164.         }
  1165.     }
  1166.     return NULL;
  1167. }
  1168.  
  1169. // Use this to activate a Navigator frame with supplied URL,
  1170. //   or the frame that is previous in app's frame list,
  1171. //   or create a new frame if no other frames exist
  1172. //   Use when we can't edit a file -- not found or not editable type
  1173. void FE_RevertToPreviousFrame(char * pUrl, MWContext *pMWContext)
  1174. {
  1175.     CGenericFrame *pFrame = (CGenericFrame*)GetFrame(pMWContext);
  1176.     if( !pFrame ){
  1177.         return;
  1178.     }    
  1179.     
  1180.     // If we were loading into an untouched new doc,
  1181.     //   the only case when we DON'T create a new frame first,
  1182.     //   then stay in that doc -- don't close it
  1183.     if( EDT_IS_EDITOR(pMWContext) && EDT_IS_NEW_DOCUMENT(pMWContext) && !EDT_DirtyFlag(pMWContext) ){
  1184.         // If ESC key is used to cancel load URL, focus needs to be set
  1185.         pFrame->GetActiveView()->SetFocus();
  1186.         return;
  1187.     }
  1188.  
  1189.     // Find the browser with the same URL    
  1190.     if( FE_ActivateFrameWithURL(pUrl, FALSE) ){
  1191.         // Close caller's frame
  1192.         pFrame->PostMessage(WM_CLOSE);
  1193.         return;
  1194.     }
  1195.  
  1196.     if( wfe_pLastFrame ){
  1197.         if ( wfe_pLastFrame->IsIconic() ){
  1198.             // Bloody unlikely!
  1199.             wfe_pLastFrame->ShowWindow(SW_RESTORE);
  1200.         }
  1201.         wfe_pLastFrame->m_bCloseFrame = FALSE;
  1202.         wfe_pLastFrame->SetActiveWindow();
  1203.     } else {
  1204.         // No existing frame,
  1205.         //  create a new browser at same location
  1206.         //  and load home page
  1207.         wfe_bUseLastFrameLocation = TRUE;
  1208.         MWContext *pNavContext = CFE_CreateNewDocWindow(NULL, NULL);
  1209.         if( pNavContext ){
  1210.             ((CMainFrame*)GetFrame(pNavContext))->OnLoadHomePage();
  1211.         }
  1212.     }
  1213.     // Be sure this is clear so we don't get prompted to save bogus empty document
  1214.     EDT_SetDirtyFlag(pMWContext, FALSE);
  1215.  
  1216.     // Close caller's frame
  1217.     pFrame->PostMessage(WM_CLOSE);
  1218. }
  1219.  
  1220. void FE_EditorGetUrlExitRoutine(URL_Struct *pUrlStruct, int iStatus, MWContext *pMWContext)
  1221. {
  1222.     // Error status is negative, but don't close
  1223.     //  if error is from publishing upload
  1224.     if( EDT_IS_EDITOR(pMWContext) && !pMWContext->bIsComposeWindow ) {
  1225.         CEditFrame * pFrame = (CEditFrame*)GetFrame(pMWContext);
  1226.         if(iStatus < 0 ){
  1227.             //Enable window if we have an error -- it is disabled in CEditFrame::OnCreate()
  1228.             // WE DON'T DISABLE WINDOW ANY MORE
  1229.             //pFrame->GetActiveView()->EnableWindow(TRUE);
  1230.             
  1231.             // Be sure this is cleared, else next load will think
  1232.             //   we want a template. This is used by FE_EditorDocumentLoaded
  1233.             //   to convert a template doc into a new doc
  1234.             pFrame->m_pTemplateContext = NULL;
  1235.  
  1236.             // Default is to try to load the failed address
  1237.             char *pAddress = pUrlStruct->address;
  1238.             
  1239.             if( pUrlStruct->files_to_post == NULL ){
  1240.                 // we failed to to load a document into an editor context
  1241.                 // Try to find frame with our URL,
  1242.                 //   or the previous frame in list,
  1243.                 //   or create a new browser frame
  1244.                 // (also closes current edit frame)
  1245.                 //
  1246.                 // But first check if we failed to load the URL
  1247.                 // Save preference
  1248.                 int iTemp = theApp.m_nChangeHomePage;
  1249.                 // These are (dynamically?) defined. See allxpstr.h
  1250.                 //  TODO: We should probably check a whole range of values
  1251.                 if( iStatus == MK_UNABLE_TO_LOCATE_FILE
  1252.                     || iStatus == MK_MALFORMED_URL_ERROR ){
  1253.                     // This will prevent trying to load 
  1254.                     //   a bad startup URL on the command line
  1255.                     theApp.m_nChangeHomePage = FALSE;
  1256.                     // If we didn't find URL at startup,
  1257.                     //  then don't try to load it in Browser either
  1258.                     if( iStatus == -209 ){
  1259.                         pAddress = NULL;
  1260.                     }
  1261.                 }
  1262.                 // Close current window and go back to last active window
  1263.                 FE_RevertToPreviousFrame(pAddress, pMWContext);
  1264.                 theApp.m_nChangeHomePage = iTemp;
  1265.             }
  1266.         } else {
  1267.             // Set flag that we are importing a text file so we treat it
  1268.             //  like a template file
  1269.              // (But Message composition should do the template stuff -- 
  1270.              //  We end up here with a MWContextMessageComposition type 
  1271.              //   when replying to a mail message.)
  1272.             if( pUrlStruct && pUrlStruct->content_type &&
  1273.                 pMWContext->type == MWContextBrowser &&
  1274.                 0 == strcmpi(pUrlStruct->content_type, INTERNAL_PARSER) )
  1275.             {
  1276.                 pFrame->m_bImportTextFile = TRUE;
  1277.             }
  1278.         }
  1279.     }
  1280.  
  1281. #ifdef XP_WIN32
  1282.     // Do this even if not an edit context
  1283.     if ( iStatus == MK_DATA_LOADED && pMWContext->type == MWContextSaveToDisk &&
  1284.      pMWContext->save_as_name ){
  1285.         // Notify site manager that a file was saved
  1286.         // CString csUrlFileName; 
  1287.         // Convert local file to URL format
  1288.         // WFE_ConvertFile2Url(csUrlFileName, (const char*)pMWContext->save_as_name);
  1289.         // For now, give local name to SiteManager:
  1290.         if ( bSiteMgrIsActive ) {
  1291.             pITalkSMClient->SavedURL(pMWContext->save_as_name);
  1292.         }
  1293.     }
  1294. #endif // XP_WIN32
  1295. }
  1296.  
  1297. // Editor calls us when we are finished loading
  1298. void FE_EditorDocumentLoaded(MWContext* pMWContext)
  1299. {
  1300.     if ( ! pMWContext ) {
  1301.         return;
  1302.     }
  1303.     CEditFrame* pFrame = (CEditFrame*)GetFrame(pMWContext);
  1304.  
  1305.     // Clear cached pointers to old elements
  1306.     CWinCX * pContext = WINCX(pMWContext);
  1307.     if(pContext){
  1308.         pContext->ClearLastElement();
  1309.     }
  1310.  
  1311.     History_entry * hist_ent = SHIST_GetCurrent(&pMWContext->hist);
  1312.     ASSERT(hist_ent);
  1313.     ASSERT(hist_ent->address);
  1314.     if( !hist_ent || !hist_ent->address ){
  1315.         return;
  1316.     }
  1317.  
  1318.     // Tell edit core the file Auto Save preference
  1319.     int32 iSave;
  1320.     PREF_GetIntPref("editor.auto_save_delay",&iSave);
  1321.     EDT_SetAutoSavePeriod(pMWContext, iSave );
  1322.  
  1323.     // Close the caller's window if marked to do so
  1324.     if( wfe_pLastFrame && wfe_pLastFrame->m_bCloseFrame){
  1325.         wfe_pLastFrame->PostMessage(WM_CLOSE);
  1326.     }
  1327.  
  1328.     if( pFrame->m_bImportTextFile || pMWContext == pFrame->m_pTemplateContext )
  1329.     {
  1330.         // We loaded a URL (template or text file)
  1331.         //  that we want to convert to a new doc
  1332.  
  1333.         // If it is a template file, save in history
  1334.         if( pMWContext == pFrame->m_pTemplateContext )
  1335.             pFrame->SaveTemplateLocation(hist_ent->address);
  1336.  
  1337.         EDT_ConvertCurrentDocToNewDoc(pMWContext);
  1338.         pFrame->m_pTemplateContext = NULL;
  1339.         pFrame->m_bImportTextFile = FALSE;
  1340.     }
  1341.  
  1342.     // This is really needed only for Win16 -- to set initial focus,
  1343.     //   but it shouldn't hurt to do this all the time
  1344.     if( pFrame->IsKindOf(RUNTIME_CLASS(CEditFrame)) ) {
  1345.         pFrame->PostMessage(WM_SETFOCUS, 0, 0);
  1346.     }
  1347.  
  1348. #ifdef MOZ_MAIL_NEWS
  1349.     if (pMWContext->type == MWContextMessageComposition)
  1350.     {
  1351.         CGenericFrame * pFrame = wfe_FrameFromXPContext(pMWContext);
  1352.         if (pFrame)
  1353.         {
  1354.             CComposeFrame * pCompose = (CComposeFrame*)pFrame;
  1355.             if (pCompose->UseHtml())
  1356.             {
  1357.                 if (!pCompose->Initialized())
  1358.                     pCompose->InsertInitialText();
  1359.                 else {
  1360.                     int32 startOffset = pCompose->GetQuoteSel();
  1361.                     if (startOffset != -1) {
  1362.                         int32 endOffset = startOffset;
  1363.                         int32 eReplyOnTop = 0;
  1364.                         if (PREF_NOERROR ==
  1365.                                 PREF_GetIntPref("mailnews.reply_on_top", &eReplyOnTop))
  1366.                             {
  1367.                                 switch (eReplyOnTop) {
  1368.                                 case 1:
  1369.                                 default:
  1370.                                     EDT_SetInsertPointToOffset(pMWContext, startOffset, 0);
  1371.                                     break;
  1372.                                 case 2:
  1373.                                 case 3:
  1374.                                     endOffset = EDT_GetInsertPointOffset(pMWContext);
  1375.                                     EDT_SetInsertPointToOffset( pMWContext, startOffset, 
  1376.                                                                 endOffset - startOffset);
  1377.                                     break;
  1378.                                 }
  1379.                             }
  1380.                         pCompose->SetQuoteSel(-1);
  1381.                     }
  1382.                 }
  1383.     
  1384.             } // UseHtml()
  1385.         } // pFrame
  1386.     } // MWContextMessageComposition
  1387. #endif // MOZ_MAIL_NEWS
  1388. }
  1389.  
  1390. void FE_FinishedRelayout(MWContext * pMWContext)
  1391. {
  1392.     // Clear cached pointers to old elements
  1393.     if( pMWContext ){
  1394.         CWinCX * pContext = WINCX(pMWContext);
  1395.         if(pContext){
  1396.             pContext->ClearLastElement();
  1397.         }
  1398.     }
  1399. }
  1400.  
  1401.  
  1402. //////////////////////////////////////////////////////////////////////////
  1403. enum {
  1404.     ED_LOAD_CURRENT_PAGE,
  1405.     ED_LOAD_CURRENT_FRAME,
  1406.     ED_LOAD_NEW_PAGE,
  1407.     ED_LOAD_TEMPLATE
  1408. };
  1409.  
  1410. typedef struct _EDT_LoadUrlData {
  1411.     int             iStyle;
  1412.     BOOL            bNewWindow;
  1413.     CGenericFrame * pFrame;
  1414.     MWContext     * pCopyHistoryContext;
  1415. } EDT_LoadUrlData;
  1416.  
  1417.  
  1418. // Access function for calling from outside to Edit or Navigate
  1419. // Used by LiveWire SiteManager, DDE, OLE, and JAVA interfaces
  1420. void FE_LoadUrl( char *pUrl, BOOL bEdit )
  1421. {
  1422.     if ( *pUrl == '\0' ){
  1423.         // An empty string is same as none
  1424.         // Will load new blank page if bEdit is TRUE,
  1425.         //   else load HomePage into browser
  1426.         pUrl = NULL;
  1427.     }
  1428.  
  1429.     CString csUrlFileName;
  1430.     if ( pUrl && NET_URL_Type(pUrl) == 0 ) {
  1431.         // Assume "file:///" if no URL type supplied
  1432.         WFE_ConvertFile2Url(csUrlFileName, (const char*)pUrl);
  1433.         pUrl = (char*)LPCSTR(csUrlFileName);
  1434.     }
  1435.  
  1436.     // Get the last active browser or editor frame
  1437.     // It doesn't matter which frame's function we call
  1438.     //  since we are assured of having a URL and don't need history or other data. 
  1439.     CGenericFrame* pFrame = (CGenericFrame*)FEU_GetLastActiveFrame(MWContextBrowser, FEU_FINDBROWSERANDEDITOR);
  1440.     
  1441.     // Default is to start a new editor frame
  1442.     BOOL bNewEditor = TRUE;
  1443.     
  1444.     MWContext * pMWContext = NULL;
  1445.  
  1446.     if( pFrame ){
  1447.         if( pFrame->GetMainContext() ){
  1448.             pMWContext = pFrame->GetMainContext()->GetContext();
  1449.         }
  1450.  
  1451.         // If any frame already exists, then create a new editor in LoadUrlEditor
  1452.         //   but if we are loading from an empty/untouched new document, then use that frame instead
  1453.         if( pMWContext && EDT_IS_NEW_DOCUMENT(pMWContext) && !EDT_DirtyFlag(pMWContext) ){
  1454.             bNewEditor = FALSE;
  1455.         }
  1456.     } else {
  1457.         // We end up here if launched from OLE automation, e.g., Sitemanager
  1458.         if( bEdit ){
  1459.             theApp.m_EditTmplate->OpenDocumentFile(NULL);
  1460.             pFrame = (CGenericFrame*)FEU_GetLastActiveFrame(MWContextBrowser, FEU_FINDEDITORONLY);
  1461.             // We don't need a new frame -- load the URL into the frame just created
  1462.             bNewEditor = FALSE;
  1463.         } else {
  1464.             theApp.m_ViewTmplate->OpenDocumentFile(NULL);
  1465.             pFrame = (CGenericFrame*)FEU_GetLastActiveFrame(MWContextBrowser, FEU_FINDBROWSERONLY);
  1466.         }
  1467.     }
  1468.     if( pFrame ){
  1469.         if( !pMWContext && pFrame->GetMainContext() ){
  1470.             pMWContext = pFrame->GetMainContext()->GetContext();
  1471.         }
  1472.         if ( bEdit ) {
  1473.             // This will look for exisiting window AFTER
  1474.             //   passing through EDT_PreOpen() plugin hook
  1475.             pFrame->LoadUrlEditor( pUrl, bNewEditor, pUrl ? ED_LOAD_CURRENT_PAGE : ED_LOAD_NEW_PAGE );
  1476.         } else if( !FE_ActivateFrameWithURL(pUrl, FALSE) ) {
  1477.             // We didn't find a Browser with that URL - find or create a Browser
  1478.             if( !pFrame->GetMainContext() || EDT_IS_EDITOR(pMWContext) ){
  1479.                 // The last active frame was an editor - we need a Browser
  1480.                 pFrame = (CGenericFrame*)FEU_GetLastActiveFrame(MWContextBrowser, FEU_FINDBROWSERONLY);
  1481.             }
  1482.             if( pFrame ){
  1483.                 // Bring this page to the foreground
  1484.                 if ( pFrame->IsIconic() ){
  1485.                     pFrame->ShowWindow(SW_RESTORE);
  1486.                 }
  1487.                 pFrame->SetActiveWindow();
  1488.                 // Load into existing Browser
  1489.                 pFrame->GetMainContext()->NormalGetUrl(pUrl);
  1490.             } else {
  1491.                 // Start a new Browser frame with supplied URL
  1492.                 wfe_CreateNavigator(pUrl);
  1493.             }
  1494.         }
  1495.     } else {
  1496.         //VERY BAD TO BE HERE - EXIT APP!
  1497.         ::MessageBox(0, "Failed to create new window\nfrom OLE Automation launch", 0, 0);
  1498.         // We know there are no visible windows to ask user about,
  1499.         //  so just exit
  1500.         theApp.CommonAppExit();
  1501.     }
  1502. }
  1503.  
  1504. void FE_SetNewDocumentProperties(MWContext * pMWContext)
  1505. {
  1506.     EDT_PageData *pPageData = EDT_GetPageData(pMWContext);
  1507.     if ( pPageData == NULL ){
  1508.         return;
  1509.     }
  1510.  
  1511.     // Copy background image if not in same directory as document
  1512.     int bKeepImages;
  1513.     PREF_GetBoolPref("editor.publish_keep_images",&bKeepImages);
  1514.  
  1515.     pPageData->bKeepImagesWithDoc = bKeepImages;
  1516.  
  1517.     // Get editor colors if using custom colors
  1518.     XP_Bool prefBool;
  1519.     PREF_GetBoolPref("editor.use_custom_colors",&prefBool);
  1520.     if( prefBool ) {
  1521.         COLORREF clr;
  1522.         
  1523.         PREF_GetColorPrefDWord("editor.text_color",&clr);
  1524.         WFE_SetLO_ColorPtr(clr,&pPageData->pColorText);
  1525.         
  1526.         PREF_GetColorPrefDWord("editor.link_color",&clr);
  1527.         WFE_SetLO_ColorPtr(clr,&pPageData->pColorLink);
  1528.  
  1529.         PREF_GetColorPrefDWord("editor.active_link_color",&clr);
  1530.         WFE_SetLO_ColorPtr(clr,&pPageData->pColorActiveLink);
  1531.  
  1532.         PREF_GetColorPrefDWord("editor.followed_link_color",&clr);
  1533.         WFE_SetLO_ColorPtr(clr,&pPageData->pColorFollowedLink);
  1534.  
  1535.         // Set the background color even if we use an image TODO: CHECK IF THIS IS SOURCE OF BUG
  1536.         PREF_GetColorPrefDWord("editor.background_color",&clr);
  1537.         WFE_SetLO_ColorPtr(clr, &pPageData->pColorBackground);
  1538.     }
  1539.     char * szBack = NULL;
  1540.     PREF_CopyCharPref("editor.background_image",&szBack);
  1541.     XP_Bool bBack;
  1542.     PREF_GetBoolPref("editor.use_background_image",&bBack);
  1543.     // Background image preference is independent from color preferences
  1544.     if( bBack && szBack ){
  1545.         pPageData->pBackgroundImage = XP_STRDUP(szBack);
  1546.         XP_FREE(szBack);
  1547.     }
  1548.   
  1549.     EDT_SetPageData(pMWContext, pPageData);
  1550.     EDT_FreePageData(pPageData);
  1551.  
  1552.     // Add fixed MetaData items:
  1553.     EDT_MetaData *pMetaData = EDT_NewMetaData();
  1554.     if ( pMetaData == NULL ){
  1555.         return;
  1556.     }
  1557.     
  1558.     //What generated this document:
  1559.     pMetaData->bHttpEquiv = FALSE;
  1560.  
  1561.     pMetaData->pName = XP_STRDUP("Author");
  1562.  
  1563.     PREF_CopyCharPref("editor.author",&(pMetaData->pContent));    
  1564.  
  1565.     EDT_SetMetaData(pMWContext, pMetaData);     
  1566.     EDT_FreeMetaData(pMetaData);
  1567.  
  1568.     // Force entire view to be painted 
  1569.     // (if not, a browser background image leaks through at top, 
  1570.     //  above caret on first line)
  1571.     ::InvalidateRect( (PANECX(pMWContext))->GetPane(), NULL, TRUE);
  1572.  
  1573. // From the Composer button on the Taskbar:
  1574. void CGenericFrame::OnOpenComposerWindow()
  1575. {
  1576.     CAbstractCX *pCX = GetMainContext();
  1577.     if(pCX != NULL)
  1578.     {
  1579.         int nCount = FEU_GetNumActiveFrames(MWContextBrowser, FEU_FINDEDITORONLY);
  1580.  
  1581.         if((nCount == 1 && (pCX->GetContext()->type == MWContextBrowser && EDT_IS_EDITOR(pCX->GetContext()))) ||
  1582.             nCount == 0){
  1583.             // If we didn't find an editor, start a new one
  1584.             OnEditNewBlankDocument();
  1585.         }
  1586.         else if(nCount > 1 || !(pCX->GetContext()->type == MWContextBrowser && EDT_IS_EDITOR(pCX->GetContext())))
  1587.         {
  1588.             CFrameWnd *pFrame;
  1589.  
  1590.             //if we are an editor then get the bottom most editor
  1591.             if(pCX->GetContext()->type == MWContextBrowser && EDT_IS_EDITOR(pCX->GetContext()))
  1592.             {
  1593.                 pFrame = FEU_GetBottomFrame(MWContextBrowser, FEU_FINDEDITORONLY);
  1594.             }
  1595.             else
  1596.             // if we are not an editor, then get the last active editor
  1597.                 pFrame = FEU_GetLastActiveFrame(MWContextBrowser, FEU_FINDEDITORONLY);
  1598.  
  1599.             if(pFrame){
  1600.  
  1601.                 if(pFrame->IsIconic())
  1602.                     pFrame->ShowWindow(SW_RESTORE);
  1603.  
  1604. #ifdef _WIN32
  1605.                 pFrame->SetForegroundWindow();
  1606. #else    
  1607.                 pFrame->SetActiveWindow();
  1608. #endif
  1609.             }
  1610.         }
  1611.  
  1612.     }
  1613. }
  1614.  
  1615. static void FinishLoadUrlEditor(XP_Bool bUserCanceled, char* pUrl, void* user_data)
  1616. {
  1617.     ASSERT(user_data);
  1618.     if( !user_data){
  1619.         return;
  1620.     }
  1621.  
  1622.     EDT_LoadUrlData * pData = (EDT_LoadUrlData*)user_data;
  1623.     if( bUserCanceled ){
  1624.         // Note: We usually create a new Compose window below,
  1625.         //       except when we need to create one in FE_LoadUrl
  1626.         //         because no Browser or Composer windows existed
  1627.         //         before trying to start Composer.
  1628.         //       If this window was already created,
  1629.         //         create a Navigator with the URL instead
  1630.         //         and close the Composer window
  1631.         if( !pData->bNewWindow && pData->pFrame ){
  1632.             wfe_CreateNavigator(pUrl);
  1633.             pData->pFrame->PostMessage(WM_CLOSE,0,0);
  1634.         }
  1635.         return;
  1636.     }
  1637.  
  1638.  
  1639.     // Use the MAIN context for frameset URL or if active context is not found
  1640.     CWinCX *pWinContext = NULL;
  1641.     if( pData->iStyle == ED_LOAD_CURRENT_FRAME ||
  1642.         !(pWinContext = pData->pFrame->GetActiveWinContext()) ){
  1643.         pWinContext = pData->pFrame->GetMainWinContext();
  1644.     }
  1645.  
  1646.     URL_Struct *pUrlStruct = NULL;
  1647.     History_entry * pEntry = NULL;
  1648.     if( pWinContext ){
  1649.         pEntry = SHIST_GetCurrent(&(pWinContext->GetContext()->hist));
  1650.     }
  1651.  
  1652.     // An empty string is same as blank
  1653.     if( pUrl && *pUrl == '\0' ){
  1654.         pUrl = NULL;
  1655.     }
  1656.     BOOL bNewDocument = (pData->iStyle == ED_LOAD_NEW_PAGE) || (pUrl == NULL);
  1657.  
  1658.     if( !bNewDocument ){
  1659.         // Try to activate an existing window EXCEPT if loading a template
  1660.         if( pUrl && pData->iStyle != ED_LOAD_TEMPLATE &&
  1661.             FE_ActivateFrameWithURL( pUrl, TRUE ) ){
  1662.             // We found existing window - we're done
  1663.             delete pData;
  1664.             return;
  1665.         }
  1666.         // Important! We need to detect when URL to load is same as current history's URL
  1667.         //   so we create the URL Struct from the appropriate context
  1668.         if ( pUrl == NULL || 
  1669.              (pEntry && pEntry->address && !strcmp(pEntry->address, pUrl)) )
  1670.         {
  1671.             // Create a new URL struct using the data in current page's context
  1672.             if(pEntry){
  1673.                 pUrlStruct = SHIST_CreateURLStructFromHistoryEntry(pWinContext->GetContext(), pEntry);
  1674.                 // Above defaults to NET_DONT_RELOAD. 
  1675.                 // We need NET_NORMAL_RELOAD to be sure we do normal server checks 
  1676.                 //   to see if doc changed at original source (fix for bug 80606)
  1677.                 pUrlStruct->force_reload = NET_NORMAL_RELOAD;
  1678.             } else {
  1679.                 // Unlikely event - no current history entry
  1680.                 bNewDocument = TRUE;
  1681.             }
  1682.         } else {
  1683.             // Create a new URL structures and copy URL string to it
  1684.             pUrlStruct = NET_CreateURLStruct(pUrl, NET_NORMAL_RELOAD);
  1685.         }
  1686.     }
  1687.  
  1688.     if ( pUrlStruct ) {
  1689.         // Must clear this to correctly load URL
  1690.         pUrlStruct->fe_data = NULL;
  1691.         //      If this structure changes in the future to hold data which can be carried
  1692.         //              across contexts, then we lose.
  1693.         memset((void *)&(pUrlStruct->savedData), 0, sizeof(SHIST_SavedData));
  1694.     }
  1695.  
  1696.     MWContext * pEditContext = NULL;
  1697.     if( pData->bNewWindow ){
  1698.         // Most uses create a new context, frame, view set and load the URL if supplied
  1699.         pEditContext = FE_CreateNewEditWindow(NULL, pUrlStruct );
  1700.     } else {
  1701.         // Or load URL into an existing window only if its already an editor
  1702.         if( EDT_IS_EDITOR(pWinContext->GetContext()) ){
  1703.             pEditContext = pWinContext->GetContext();
  1704.         }
  1705.         if( !bNewDocument ){
  1706.             // If Composer frame was created at startup, 
  1707.             //  we end up here to load URL from the command line
  1708.             // Suppress the "-embedding" string we get from OLE launch
  1709.             if( 0 == strcmpi(pUrl, "-embedding") ){
  1710.                 bNewDocument = TRUE;
  1711.             } else {
  1712.                 pWinContext->NormalGetUrl(pUrl);
  1713.             }
  1714.         }
  1715.     }
  1716.  
  1717.     if( pEditContext ){
  1718.         if ( bNewDocument ) {
  1719.             // Start a new document - Get the view from the newly-created edit context
  1720.             // Start new doc with URL = "about:editfilenew"
  1721.             WINCX(pEditContext)->NormalGetUrl(EDT_NEW_DOC_URL);
  1722.         } else {
  1723.             if( pData->iStyle == ED_LOAD_TEMPLATE ){
  1724.     
  1725.                 // This will trigger changing to new doc name and URL
  1726.                 //   in Edit FE_EditorGetUrlExitRoutine.
  1727.                 ((CEditFrame*)GetFrame(pEditContext))->m_pTemplateContext = pEditContext;
  1728.             }
  1729.  
  1730.             // Copy the history of the "caller" browser window if it was set
  1731.             // Note, after LoadUrlEditor, if user closes the Navigator window
  1732.             //  before canceling out of a "Can't Edit URL" prompt, 
  1733.             //  pNavContext will be BAD, so check if context  is in the list
  1734.             if ( pData->pCopyHistoryContext && 
  1735.                  XP_IsContextInList(pData->pCopyHistoryContext) &&
  1736.                  pData->pCopyHistoryContext != pEditContext ) {
  1737.                 // Copy History from current window to Edit context
  1738.                 // (This sets current history index to 1)
  1739.                 SHIST_CopySession(pEditContext, pData->pCopyHistoryContext);
  1740.  
  1741.                 //      Set the current session history index for the new context
  1742.                 //   by finding same location of old address in new context
  1743.                 //  If there is not pCurrentEntry, then browser had no history
  1744.                 //   and we got a new doc when editor was created: index = 1
  1745.                 int nIndex = 1;
  1746.                 if ( pEntry && pEntry->address != NULL ) {
  1747.                     nIndex = FindCurrentUrlInHistory(pEditContext, pEntry->address );
  1748.                 }
  1749.                 SHIST_SetCurrent(&(pEditContext->hist), nIndex );
  1750.             }
  1751.         }
  1752.     }
  1753.     delete pData;
  1754. }
  1755.  
  1756. void CGenericFrame::LoadUrlEditor(char * pUrl,
  1757.                                   BOOL bNewWindow,
  1758.                                   int iLoadStyle, 
  1759.                                   MWContext * pCopyHistoryContext)
  1760. {
  1761.     EDT_LoadUrlData * pData = new EDT_LoadUrlData;
  1762.     if( pData ){
  1763.         pData->pFrame = this;
  1764.         pData->iStyle = iLoadStyle;
  1765.         // We MUST create a new window if current window is not an editor
  1766.         pData->bNewWindow = EDT_IS_EDITOR(GetMainContext()->GetContext()) ? bNewWindow : TRUE;
  1767.         
  1768.         // We will copy history from a source browser context ONLY if creating a new window
  1769.         pData->pCopyHistoryContext = pData->bNewWindow ? pCopyHistoryContext : NULL;
  1770.         
  1771.         if( pUrl && *pUrl){
  1772.             // Be sure we have URL format by now
  1773.             CString csURL;
  1774.             WFE_ConvertFile2Url(csURL, pUrl);
  1775.  
  1776.             // Call Editor Plugin to possibly replace the supplied URL
  1777.             //   or do source file locking
  1778.             
  1779.             //EDT_PreOpen(GetMainContext()->GetContext(), (char*)(LPCSTR(csURL)), &FinishLoadUrlEditor, pData);
  1780.             //TODO: REMOVE THIS - TEMP - SKIP PLUGIN TO AVOID NSPR20 PROBLEMS????
  1781.             FinishLoadUrlEditor(FALSE, (char*)(LPCSTR(csURL)), pData);
  1782.         } else {
  1783.             // No URL address given - Don't go through plugin
  1784.             FinishLoadUrlEditor(FALSE, NULL, pData);
  1785.         }
  1786.     }
  1787. }
  1788.  
  1789. // Start New document in a new window
  1790. // This is used by both Browser and Editor
  1791. void CGenericFrame::OnEditNewBlankDocument()
  1792. {
  1793.     if ( GetMainContext() == NULL || GetMainContext()->GetContext() == NULL ) {
  1794.         return;
  1795.     }
  1796.     // Create a new window with a new blank page
  1797.     LoadUrlEditor(NULL, TRUE, ED_LOAD_NEW_PAGE);
  1798. }
  1799.  
  1800. // Open a Editor window with current URL from a browser window
  1801. void CGenericFrame::OnNavigateToEdit()
  1802. {
  1803.     CWinCX *pContext = GetMainWinContext();
  1804.  
  1805.     if( !pContext || !pContext->GetContext())
  1806.         return;
  1807.  
  1808.     OpenEditorWindow(ED_LOAD_CURRENT_PAGE);
  1809. }
  1810.  
  1811. void CGenericFrame::OnEditFrame()
  1812. {
  1813.     CWinCX *pContext = GetActiveWinContext();
  1814.  
  1815.     if( !pContext || !pContext->GetContext())
  1816.         return;
  1817.     // This style really doesn't do anything --
  1818.     //   we will look for active frame no matter
  1819.     //   what style is if not ED_LOAD_CURRENT_PAGE
  1820.     OpenEditorWindow(ED_LOAD_CURRENT_FRAME);
  1821. }
  1822.  
  1823. void CGenericFrame::OpenEditorWindow(int iLoadStyle)
  1824. {
  1825.     CWinCX *pWinContext = NULL;
  1826.     
  1827.     // If editing a frameset, or no active window, use top-level (frameset) URL
  1828.     if( iLoadStyle == ED_LOAD_CURRENT_PAGE ||
  1829.         !(pWinContext = GetActiveWinContext()) ){
  1830.         pWinContext = GetMainWinContext();
  1831.     }
  1832.     if( !pWinContext ){
  1833.         return;
  1834.     }
  1835.     MWContext * pCurrentContext = pWinContext->GetContext();
  1836.     if(!pCurrentContext){
  1837.         return;
  1838.     }
  1839.  
  1840.     History_entry * pEntry = SHIST_GetCurrent(&(pWinContext->GetContext()->hist));
  1841.     // Get current address from history and load that into editor
  1842.     // Pass pCurrentContext to signal FinishLoadUrlEditor to copy history from this context
  1843.     LoadUrlEditor((pEntry && pEntry->address) ? pEntry->address : NULL,
  1844.                   TRUE, iLoadStyle, pCurrentContext);
  1845. }
  1846.  
  1847. // Called by other apps via registered message
  1848. // TODO: TEST IF THESE ARE USED ANY MORE -- LIVEWIRE???
  1849. LRESULT CGenericFrame::OnOpenEditor(WPARAM wParam, LPARAM lParam )
  1850. {
  1851.     HANDLE handle = NULL;
  1852. #ifndef WIN32
  1853.     // We get data passed to us if Win16
  1854.     handle = (HANDLE)wParam;
  1855. #endif
  1856.     char *pUrl = GetGlobalUrlPointer(handle);
  1857.     
  1858.     // In Win32, handle wil be obtained from memory-mapped file
  1859.     // This will load an empty editor window if no data is found
  1860.     // This will try to locate an existing window AFTER passing 
  1861.     //    through EDT_PreOpen() plugin hook function
  1862.     LoadUrlEditor(pUrl);
  1863.  
  1864. #ifndef WIN32
  1865.     if ( NULL != handle) {
  1866.         GlobalUnlock(handle);
  1867.     }
  1868. #else   // Win16
  1869.     if ( pUrl ) {
  1870.         XP_FREE(pUrl );
  1871.     }
  1872. #endif
  1873.     return 0;
  1874. }
  1875.  
  1876. // Called by other apps via registered message
  1877. LRESULT CGenericFrame::OnOpenNavigator(WPARAM wParam, LPARAM lParam )
  1878. {
  1879.     HANDLE handle = NULL;
  1880. #ifndef WIN32
  1881.     // We get data passed to us if Win16
  1882.     handle = (HANDLE)wParam;
  1883. #endif
  1884.     char *pUrl = GetGlobalUrlPointer(handle);
  1885.  
  1886.     // First try to find existing frame
  1887.     if ( ! FE_ActivateFrameWithURL( pUrl, FALSE ) ) {
  1888.         wfe_CreateNavigator( pUrl );
  1889.     }
  1890.  
  1891. #ifndef WIN32
  1892.     if ( NULL != handle) {
  1893.         GlobalUnlock(handle);
  1894.     }
  1895. #else   // Win16
  1896.     if ( pUrl ) {
  1897.         XP_FREE(pUrl );
  1898.     }
  1899. #endif
  1900.     return 0;
  1901. }
  1902.  
  1903. // Should be called only from Edit view
  1904. //   or from EditToNavigate (which is called from view)
  1905. //   after FE_CheckAndSaveDocument is called
  1906.  
  1907. void CGenericFrame::OpenNavigatorWindow(MWContext * pMWContext)
  1908. {
  1909.     if ( !pMWContext ){
  1910.         return;
  1911.     }
  1912.     BOOL bNewDocument = FALSE;
  1913.     MWContext * pNavContext = NULL;
  1914.     BOOL bNewWindow = TRUE;
  1915.     
  1916.     URL_Struct *pUrlStruct = NULL;
  1917.     History_entry * pCurrentEntry = SHIST_GetCurrent(&(pMWContext->hist));
  1918.     if ( pCurrentEntry != NULL && pCurrentEntry->address ) {
  1919.         if ( 0 == XP_STRCMP(pCurrentEntry->address, EDT_NEW_DOC_NAME) ) {
  1920.             // Suppress trying to load "Untitled" document, load home page instead
  1921.             bNewDocument = TRUE;
  1922.             pCurrentEntry = NULL;
  1923.         }
  1924.         else {
  1925.             // First try to find existing frame
  1926.             pNavContext = FE_ActivateFrameWithURL( pCurrentEntry->address, FALSE );
  1927.             if ( pNavContext ) {
  1928.                 bNewWindow = FALSE;
  1929.                 // Do reload in case the contents of the found browser window 
  1930.                 //  are older than the editor we are switching from
  1931.                 // (Note: Must get new CWinCX from MWcontext since
  1932.                 //        this will get sent before view is activated,
  1933.                 //        i.e., Main and Active contexts not set yet)
  1934.                 WINCX(pNavContext)->Reload(NET_SUPER_RELOAD);
  1935.             } else {
  1936.                 pUrlStruct = SHIST_CreateURLStructFromHistoryEntry(GetMainContext()->GetContext(), 
  1937.                                          pCurrentEntry);
  1938.                 if ( pUrlStruct ) {
  1939.                     // Must clear this to correctly load URL into new context
  1940.                     pUrlStruct->fe_data = NULL;
  1941.  
  1942.                     // Always check the server to get most up-to-date version
  1943.                     pUrlStruct->force_reload = NET_NORMAL_RELOAD;
  1944.  
  1945.                     // This prevents URL from being added twice 
  1946.                     //  to history list -- we copy from old to new context
  1947.                     //  and reposition "current" to that history item
  1948.                     pUrlStruct->history_num = 0;
  1949.                     //      If this structure changes in the future to hold data which can be carried
  1950.                     //              across contexts, then we lose.
  1951.                     memset((void *)&(pUrlStruct->savedData), 0, sizeof(SHIST_SavedData));
  1952.                 }
  1953.             }
  1954.         }
  1955.     } else {
  1956.         // If no current history, this will cause loading the Home Page
  1957.         bNewDocument = TRUE;
  1958.     }
  1959.  
  1960.     if ( !pNavContext ) {
  1961.     // Create new Frame+View+Context
  1962.         pNavContext = CFE_CreateNewDocWindow(NULL, pUrlStruct );
  1963.     }
  1964.  
  1965.  
  1966.     if ( pNavContext ) {
  1967.         if ( bNewWindow ) {
  1968.             // Copy History from Editor to Navigator context
  1969.             // Note: This function was modified to not copy any "Untitled" new doc entries
  1970.             SHIST_CopySession(pNavContext, pMWContext);
  1971.  
  1972.             //      Set the current session history index for the new context
  1973.             //   by finding same location of old address in new context
  1974.             //  (Note: pCurrentEntry = NULL in browser when changing to browser
  1975.             //         from an empty document. Set default Index to 0 to handle this)
  1976.             int nIndex = 0;
  1977.             if ( pCurrentEntry && pCurrentEntry->address != NULL ) {
  1978.             nIndex = FindCurrentUrlInHistory(pNavContext, pCurrentEntry->address );
  1979.             }
  1980.             SHIST_SetCurrent(&(pNavContext->hist), nIndex );
  1981.         }
  1982.         // Do this AFTER copying history so homepage appears in new history list
  1983.         if ( bNewDocument ) {
  1984.             // Load home page if no URL or "Untitled" was supplied
  1985.             // TODO: Find existing instance of current home page? (very tricky!)
  1986.             ((CMainFrame*)GetFrame(pNavContext))->OnLoadHomePage();
  1987.         }
  1988.     }
  1989. }
  1990.  
  1991. // Replace Editor with a Navigator window with current Editor URL
  1992. // This and OpenEditorWindow should be called
  1993. //  only after FE_CheckAndSaveDocument
  1994. void CGenericFrame::EditToNavigate(MWContext * pEditContext, BOOL bNewDocument )
  1995. {
  1996.     if ( pEditContext == NULL ) {
  1997.         return;
  1998.     }
  1999.     // Place Browser at same place
  2000.     wfe_bUseLastFrameLocation = TRUE;
  2001.  
  2002.     OpenNavigatorWindow(pEditContext);
  2003.  
  2004.     // Close the underlying editor
  2005.     ((CMainFrame*)GetFrame(pEditContext))->PostMessage(WM_CLOSE);
  2006. }
  2007.  
  2008. LRESULT CGenericFrame::OnNetscapeGoldIsActive(WPARAM wParam, LPARAM lParam)
  2009. {
  2010.     // Return handle to Frame window as response to
  2011.     //  our special message - another instance or app
  2012.     //  is asking if we are here
  2013.     return (LRESULT)(this->m_hWnd);
  2014. }
  2015.  
  2016. void CGenericFrame::OnEditNewDocFromTemplate()
  2017. {
  2018.     if ( GetMainContext() == NULL || GetMainContext()->GetContext() == NULL ) {
  2019.         return;
  2020.     }
  2021.     
  2022.     // Popup dialog to allow user to set location, choose from 20 most recent, or choose new file
  2023.     COpenTemplateDlg dlg(this);
  2024.     if(dlg.DoModal() == IDOK){
  2025.         char *pTemplate = NULL;
  2026.         if( !dlg.m_csLocation.IsEmpty() ){
  2027.             pTemplate = XP_STRDUP((char*)LPCSTR(dlg.m_csLocation));
  2028.             if( pTemplate ) {
  2029.                 // Save the location chosen; if it is loaded successfully,
  2030.                 //   it will be added to template history list
  2031.                 PREF_SetCharPref("editor.template_last_loc", pTemplate);
  2032.  
  2033.                 // Load a browser with this template URL
  2034.                 char * pDefault = NULL;
  2035.                 PREF_CopyCharPref("editor.default_template_location", &pDefault);
  2036.                 if( pDefault &&  0 == strcmp(pDefault, pTemplate) ){
  2037.                     // Current location is Netscape's Template page,
  2038.                     // Load into Browser
  2039.                     wfe_CreateNavigator(pTemplate);
  2040.                 } else {
  2041.                     // Check if user is already editing this template
  2042.                     MWContext *pEditContext = FE_ActivateFrameWithURL(pTemplate, TRUE);
  2043.                     if( pEditContext && EDT_DirtyFlag(pEditContext) ){
  2044.                         CGenericFrame *pFrame = (CGenericFrame*)GetFrame(pEditContext);
  2045.                         // Warn the user that template is being edited
  2046.                         //  and new page wont have unsaved changes
  2047.                         pFrame->MessageBox(szLoadString(IDS_EDITING_TEMPLATE),
  2048.                                            szLoadString(IDS_NEW_PAGE_TEMPLATE),
  2049.                                            MB_ICONEXCLAMATION | MB_OK);
  2050.                     }
  2051.                     // Load template page into a new edit window
  2052.                     LoadUrlEditor(pTemplate, TRUE, ED_LOAD_TEMPLATE);
  2053.                 }
  2054.                 XP_FREEIF(pDefault);
  2055.                 XP_FREE(pTemplate);
  2056.             }
  2057.         }
  2058.     }
  2059. }
  2060.  
  2061. //////////////////////////////////////////////////////////////////////
  2062. // SiteManager communications methods
  2063. //
  2064. #ifdef XP_WIN32
  2065. // Site Manager tells us it is being activated or destroyed
  2066. LRESULT CGenericFrame::OnSiteMgrMessage(WPARAM wParam, LPARAM lParam)
  2067. {
  2068.     if( wParam == SM_IS_ALIVE ){
  2069.         if( pITalkSMClient && !pITalkSMClient->IsRegistered() ){
  2070.             // This should occur only if SiteManager was run the very first time
  2071.             //  after our instance started (it wasn't registered)
  2072.             // Recreating our class will reset registration flag
  2073.             delete pITalkSMClient;
  2074.             pITalkSMClient = new (ITalkSMClient);
  2075.         }
  2076.         if( pITalkSMClient && pITalkSMClient->IsRegistered() ){
  2077.             bSiteMgrIsActive = TRUE;
  2078.             pITalkSMClient->SetKnownSMState(TRUE);
  2079.         }
  2080.         return 1;
  2081.     } else if( wParam == SM_IS_DEAD ){
  2082.         bSiteMgrIsActive = FALSE;
  2083.         if( pITalkSMClient ){
  2084.             pITalkSMClient->SetKnownSMState(FALSE);
  2085.         }
  2086.         return 1;
  2087.     }
  2088.  
  2089.     return 0;
  2090. }
  2091. #endif
  2092.  
  2093. void CGenericFrame::OnActivateSiteManager()
  2094. {
  2095. #ifdef XP_WIN32
  2096.     XP_Bool prefBool;
  2097.     PREF_GetBoolPref("editor.hints.sitemanager",&prefBool);
  2098.  
  2099.     if( bSiteMgrIsRegistered ) {
  2100.         if ( prefBool ) {
  2101.             // Show a "Hint" dialog about drag and drop until
  2102.             //   user checks "Don't show this" in dialog
  2103.             CEditHintDlg dlg(this, IDS_DRAG_SITEMAN_HINT);
  2104.             dlg.DoModal();
  2105.             if ( dlg.m_bDontShowAgain ) {
  2106.                 PREF_SetBoolPref("editor.hints.sitemanager",FALSE);
  2107.             }
  2108.         }
  2109.         // This will invoke SiteManager if it is not already running
  2110.         if( pITalkSMClient->BecomeActive() ){
  2111.             bSiteMgrIsActive = TRUE;
  2112.         }
  2113.     }
  2114. #endif
  2115. }
  2116.  
  2117. void CGenericFrame::OnUpdateActivateSiteManager(CCmdUI* pCmdUI)
  2118. {
  2119. #ifdef XP_WIN32
  2120.     pCmdUI->Enable( bSiteMgrIsRegistered );    
  2121. #endif
  2122. }
  2123.  
  2124. static BOOL bInFontMenu = FALSE;
  2125. static BOOL bInSizeMenu = FALSE;
  2126. static BOOL bInHistoryMenu = FALSE;
  2127. static BOOL bInTableMenu = FALSE;
  2128.  
  2129. // Put all Composer-only code here - called only from CGenericFrame::OnMenuSelect()
  2130. void CGenericFrame::OnMenuSelectComposer(UINT nItemID, UINT nFlags, HMENU hSysMenu)
  2131. {
  2132.     if ( nFlags == 0xFFFF && hSysMenu == 0 )
  2133.     {
  2134.         // Menu is being destroyed - clear rebuild flags
  2135.         bInFontMenu = FALSE;
  2136.         bInSizeMenu = FALSE;
  2137.         bInHistoryMenu = FALSE;
  2138.         bInTableMenu = FALSE;
  2139.         return;
  2140.     }
  2141.  
  2142.     if ( nFlags & MF_POPUP )
  2143.     {
  2144.         MWContext * pMWContext = GetMainContext()->GetContext();
  2145.         HMENU hMenu = ::GetMenu(m_hWnd);
  2146.         if( !hMenu || !pMWContext ){
  2147.             return;
  2148.         }
  2149.         int nCount = GetMenuItemCount(hMenu);
  2150.         HMENU hEditHistoryMenu = NULL;
  2151.         HMENU hFormatMenu = NULL;
  2152.         HMENU hFontMenu = NULL;
  2153.         HMENU hSizeMenu = NULL;
  2154.         HMENU hSubMenu = NULL;
  2155.         HMENU hSubSubMenu;
  2156.         int i;
  2157.  
  2158.         for( i = 0; i < nCount; i++)
  2159.         {
  2160.             hSubMenu = GetSubMenu(hMenu, i);
  2161.             if( hSubMenu )
  2162.             {
  2163.                 // Modify item(s) in the Table menu
  2164.                 if( i == ED_MENU_TABLE )
  2165.                 {
  2166.                     if( bInTableMenu )
  2167.                         return;
  2168.                     bInTableMenu = TRUE;
  2169.  
  2170.                     //TODO: Enable/Disable items appropriate only when inside a table
  2171.                     BOOL bInTable = EDT_IsInsertPointInTable(pMWContext);
  2172.                     ::ModifyMenu(hSubMenu, ID_TABLE_TEXT_CONVERT, MF_BYCOMMAND | MF_STRING, ID_TABLE_TEXT_CONVERT,
  2173.                                  szLoadString(bInTable ? IDS_CONVERT_TABLE_TO_TEXT : IDS_CONVERT_TEXT_TO_TABLE) );
  2174.                     // We can return here ONLY if we don't need to look at menus after "Table"
  2175.                     break;
  2176.                 }
  2177.                 // Search for the "Open Recent" subsubmenu under the File submenu,
  2178.                 //  which is always the first top-level menu
  2179.                 UINT nSubCount = GetMenuItemCount(hSubMenu);
  2180.                 for(UINT j = 0; j < nSubCount; j++ )
  2181.                 {
  2182.                     hSubSubMenu = GetSubMenu(hSubMenu, j);
  2183.                     UINT nID = GetMenuItemID(hSubMenu, j);
  2184.  
  2185.                     // Is the the currently-selected menu?
  2186.                     if( hSubSubMenu &&
  2187. #ifdef XP_WIN32
  2188.                         // In Win32, nItemID is INDEX to the submenu item...
  2189.                         nItemID == j && hSysMenu == hSubMenu )
  2190. #else
  2191.                         // ...in Win16, it is the handle to subsubmenu
  2192.                         nItemID == (UINT)hSubSubMenu )
  2193. #endif
  2194.                     {
  2195.                         // The first item in the SubSubMenu identifies that menu
  2196.                         UINT nID = GetMenuItemID(hSubSubMenu, 0);
  2197.                         switch( nID )
  2198.                         {
  2199.                             case ID_EDIT_HISTORY_BASE:
  2200.                                 // Build a menu of recently-edited URL titles
  2201.                                 ((CNetscapeEditView*)GetActiveView())->BuildEditHistoryMenu(hSubSubMenu, 0);
  2202.                                 return;
  2203.                             case ID_FORMAT_FONTSIZE_BASE:
  2204.                                 hFormatMenu = hSubMenu;
  2205.                                 hSizeMenu = hSubSubMenu;
  2206.                                 break;
  2207.                             case ID_FORMAT_FONTFACE_BASE:
  2208.                                 hFormatMenu = hSubMenu;
  2209.                                 hFontMenu = hSubSubMenu;
  2210.                                 break;
  2211.                         }
  2212.                     }
  2213.                 }
  2214.                 // We are done when we found the format menu
  2215.                 if( hFormatMenu )
  2216.                     break;
  2217.             }
  2218.         }
  2219.  
  2220.         // The reest only pertain to Format menu
  2221.         if( !hFormatMenu )
  2222.             return;
  2223.  
  2224.         if( hFontMenu )
  2225.         {
  2226.             // Prevent rebuilding menu when mouse moves away
  2227.             if( bInFontMenu )
  2228.                 return;
  2229.             bInFontMenu = TRUE;
  2230.             TRACE0("Recreating Font Menu\n");
  2231.             
  2232.             // Delete any existing items
  2233.             for( int i = ::GetMenuItemCount(hFontMenu) - 1; i >= 0; i--){
  2234.                 DeleteMenu(hFontMenu, i, MF_BYPOSITION);
  2235.             }
  2236.             // Get list of FontFace fonts defined in XP_Strings
  2237.             char * pFontFaces = EDT_GetFontFaces();
  2238.  
  2239.             // Build the FontFace menu
  2240.             if( pFontFaces )
  2241.             {
  2242.                 char * pFont = pFontFaces;
  2243.                 ::AppendMenu(hFontMenu, MF_STRING, ID_FORMAT_FONTFACE_BASE, pFont);
  2244.                 pFont += XP_STRLEN(pFont) + 1;
  2245.                 if( *pFont )
  2246.                 {
  2247.                     ::AppendMenu(hFontMenu, MF_STRING, ID_FORMAT_FONTFACE_BASE+1, pFont);
  2248.                 }
  2249.                 int nCount = 0;
  2250.                 if( wfe_iTrueTypeFontCount && wfe_ppTrueTypeFonts )
  2251.                 {
  2252.                     // Add separator
  2253.                     ::AppendMenu(hFontMenu, MF_SEPARATOR,0,0);
  2254.                 
  2255.                     // Add TrueType fonts but don't overflow the screen height
  2256.                     // Number of items that will fit, minus some for items already
  2257.                     //  added, separators, and a bit extra
  2258.                     nCount = (sysInfo.m_iScreenHeight / GetSystemMetrics(SM_CYMENU)) - 6;
  2259.                     for( int i = 0; i < min(wfe_iTrueTypeFontCount, nCount); i++ ){
  2260.                         ::AppendMenu(hFontMenu, MF_STRING, ID_FORMAT_FONTFACE_BASE+i+2, 
  2261.                                      wfe_ppTrueTypeFonts[i]);
  2262.                     }
  2263.                 }                    
  2264.                 if( nCount < wfe_iTrueTypeFontCount )
  2265.                 {
  2266.                     ::AppendMenu(hFontMenu, MF_SEPARATOR,0,0);
  2267.                     // Last item is "Other..." to launch Window's Font Face dialog
  2268.                     ::AppendMenu(hFontMenu, MF_STRING, ID_OTHER_FONTFACE, ed_pOther);
  2269.                 }
  2270.             }
  2271.         }  
  2272.         else if( hSizeMenu )
  2273.         {
  2274.             if( bInSizeMenu )
  2275.                 return;
  2276.             bInSizeMenu = TRUE;
  2277.  
  2278.             // Delete any existing items
  2279.             for( i = ::GetMenuItemCount(hSizeMenu) - 1; i >= 0; i--)
  2280.             {
  2281.                 DeleteMenu(hSizeMenu, i, MF_BYPOSITION);
  2282.             }
  2283.             // Check if current base font is fixed width
  2284.             BOOL bFixedWidth = (EDT_GetFontFaceIndex(pMWContext) == 1);
  2285.             // Change font size strings based on current font base
  2286.             for ( i = 0; i < MAX_FONT_SIZE; i++ ){
  2287.                 ::AppendMenu( hSizeMenu, MF_STRING, ID_FORMAT_FONTSIZE_BASE + i,
  2288.                               wfe_GetFontSizeString(pMWContext, i+1, bFixedWidth,
  2289.                                                     TRUE) ); // Format for menu
  2290.             }
  2291.             if( wfe_iFontSizeMode == ED_FONTSIZE_ADVANCED )
  2292.             {
  2293.                 // The "Advanced" absolute point size strings
  2294.                 ::AppendMenu( hSizeMenu, MF_SEPARATOR, 0, 0);
  2295.                 ::AppendMenu( hSizeMenu, MF_STRING, ID_FORMAT_POINTSIZE_BASE, "8");
  2296.                 ::AppendMenu( hSizeMenu, MF_STRING, ID_FORMAT_POINTSIZE_BASE+1, "9");
  2297.                 ::AppendMenu( hSizeMenu, MF_STRING, ID_FORMAT_POINTSIZE_BASE+2, "10");
  2298.                 ::AppendMenu( hSizeMenu, MF_STRING, ID_FORMAT_POINTSIZE_BASE+3, "11");
  2299.                 ::AppendMenu( hSizeMenu, MF_STRING, ID_FORMAT_POINTSIZE_BASE+4, "12");
  2300.                 ::AppendMenu( hSizeMenu, MF_STRING, ID_FORMAT_POINTSIZE_BASE+5, "14");
  2301.                 ::AppendMenu( hSizeMenu, MF_STRING, ID_FORMAT_POINTSIZE_BASE+6, "16");
  2302.                 ::AppendMenu( hSizeMenu, MF_STRING, ID_FORMAT_POINTSIZE_BASE+7, "18");
  2303.                 ::AppendMenu( hSizeMenu, MF_STRING, ID_FORMAT_POINTSIZE_BASE+8, "20");
  2304.                 ::AppendMenu( hSizeMenu, MF_STRING, ID_FORMAT_POINTSIZE_BASE+9, "22");
  2305.                 ::AppendMenu( hSizeMenu, MF_STRING, ID_FORMAT_POINTSIZE_BASE+10, "24");
  2306.                 ::AppendMenu( hSizeMenu, MF_STRING, ID_FORMAT_POINTSIZE_BASE+11, "26");
  2307.                 ::AppendMenu( hSizeMenu, MF_STRING, ID_FORMAT_POINTSIZE_BASE+12, "28");
  2308.                 ::AppendMenu( hSizeMenu, MF_STRING, ID_FORMAT_POINTSIZE_BASE+13, "36");
  2309.                 ::AppendMenu( hSizeMenu, MF_STRING, ID_FORMAT_POINTSIZE_BASE+14, "48");
  2310.                 ::AppendMenu( hSizeMenu, MF_STRING, ID_FORMAT_POINTSIZE_BASE+15, "72");
  2311.             }
  2312.         }
  2313.     }
  2314. }
  2315.  
  2316. /////////////////////////////////////////////////////////////////////////////
  2317.  
  2318. // Checks if there is any active editor plugin and lets the user stop it.
  2319. // Return: TRUE - no plugin was running or user stopped the active plugin
  2320. //         FALSE - user didn't want to stop the plugin
  2321.  
  2322. BOOL CheckAndCloseEditorPlugin(MWContext *pMWContext)
  2323. {
  2324.     if (EDT_IsPluginActive(pMWContext)) {
  2325.         CGenericView* pView = WINCX(pMWContext)->GetView();
  2326.         CWnd *pParentWnd = pView->GetFrame()->GetFrameWnd()->GetLastActivePopup();
  2327.  
  2328.         if (pParentWnd->MessageBox(szLoadString(IDS_CONFIRM_STOP_PLUGIN), NULL, MB_YESNO | MB_ICONQUESTION) == IDYES)
  2329.             EDT_StopPlugin(pMWContext);
  2330.         else
  2331.             return FALSE;
  2332.     }
  2333.  
  2334.     return TRUE;
  2335. }
  2336.  
  2337. #endif // EDITOR
  2338.  
  2339.