home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / framinit.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  26.0 KB  |  858 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. // mainfrm.cpp : implementation of the CMainFrame class
  20. //                                           
  21.  
  22. #include "stdafx.h"
  23.  
  24. #include "dialog.h"                                                                  
  25. #include "mainfrm.h"
  26. #include "netsvw.h"
  27. #include "toolbar.cpp"
  28. #include "usertlbr.h"
  29. #include "urlbar.h"
  30. #include "prefapi.h"
  31. #include "csttlbr2.h"
  32. #include "prefinfo.h"
  33. #include "libevent.h"
  34. #include "navfram.h"
  35. #include "edview.h"
  36.  
  37. #ifdef _DEBUG
  38. #undef THIS_FILE
  39. static char BASED_CODE THIS_FILE[] = __FILE__;
  40. #endif
  41.  
  42. /////////////////////////////////////////////////////////////////////////////
  43. // CMainFrame
  44.  
  45. #ifndef _AFXDLL
  46. #undef new
  47. #endif
  48. IMPLEMENT_DYNCREATE(CMainFrame, CGenericFrame)
  49. #ifndef _AFXDLL
  50. #define new DEBUG_NEW
  51. #endif
  52.  
  53. const UINT NEAR msg_RegistrationComplete = RegisterWindowMessage("NetscapeRegistrationComplete");
  54. const UINT NEAR msg_AbortRegistration = RegisterWindowMessage("NetscapeAbortRegistration");
  55.  
  56. #define FILEMENU 0
  57. #define EDITMENU 1
  58. #define VIEWMENU 2
  59. #define GOMENU   3
  60.  
  61. BEGIN_MESSAGE_MAP(CMainFrame, CGenericFrame)
  62.     //{{AFX_MSG_MAP(CMainFrame)
  63.     ON_WM_INITMENUPOPUP()
  64.     ON_WM_MENUSELECT()
  65.     ON_WM_SHOWWINDOW()
  66.     ON_COMMAND(ID_OPTIONS_TITLELOCATION_BAR, OnOptionsTitlelocationBar)
  67.     ON_UPDATE_COMMAND_UI(ID_OPTIONS_TITLELOCATION_BAR, OnUpdateOptionsTitlelocationBar)
  68.     ON_WM_TIMER()
  69.     ON_WM_WINDOWPOSCHANGED()
  70.     ON_WM_CREATE()
  71.     ON_WM_DESTROY()
  72.     ON_COMMAND(ID_OPTIONS_TOGGLENETDEBUG, OnOptionsTogglenetdebug)
  73.     ON_UPDATE_COMMAND_UI(ID_OPTIONS_LOADINLINEDIMAGES, OnUpdateToggleImageLoad)
  74.     ON_COMMAND(ID_HOTLIST_MCOM, OnNetscapeHome)
  75.     ON_COMMAND(ID_PLACES, OnGuide)
  76.     ON_COMMAND(ID_OPTIONS_FLUSHCACHE, OnFlushCache)
  77.     ON_COMMAND(ID_OPTIONS_SHOWFTPFILEINFORMATION, OnToggleFancyFtp)
  78.     ON_UPDATE_COMMAND_UI(ID_OPTIONS_SHOWFTPFILEINFORMATION, OnUpdateToggleFancyFtp)
  79.     ON_UPDATE_COMMAND_UI(ID_OPTIONS_SHOWSTARTERBUTTONS, OnUpdateOptionsShowstarterbuttons)
  80.     ON_UPDATE_COMMAND_UI(ID_EDIT_UNDO, OnUpdateEditUndo)
  81.     ON_WM_CLOSE()
  82.     ON_WM_DROPFILES()
  83.     ON_COMMAND(ID_HELP_SECURITY, OnHelpSecurity)
  84.     ON_WM_SYSCOMMAND()
  85.     ON_WM_SETFOCUS()
  86.     ON_COMMAND(ID_VIEW_TOOLBAR, OnOptionsViewToolBar)
  87.     ON_COMMAND(ID_OPTIONS_LOADINLINEDIMAGES, OnToggleImageLoad)
  88.     ON_COMMAND(ID_OPTIONS_SHOWSTARTERBUTTONS, OnOptionsShowstarterbuttons)
  89.     ON_COMMAND(ID_OPEN_MAIL_WINDOW, OnOpenMailWindow)
  90.     ON_COMMAND(ID_COMMAND_HELPINDEX, OnHelpMenu)
  91.     ON_MESSAGE(NSBUTTONMENUOPEN, OnButtonMenuOpen)
  92.     ON_MESSAGE(TB_FILLINTOOLTIP, OnFillInToolTip)
  93.     ON_MESSAGE(TB_FILLINSTATUS, OnFillInToolbarButtonStatus)
  94.     ON_COMMAND(ID_VIEW_INCREASEFONT, OnIncreaseFont)
  95.     ON_COMMAND(ID_VIEW_DECREASEFONT, OnDecreaseFont)
  96.     ON_UPDATE_COMMAND_UI(ID_NETSEARCH, OnUpdateNetSearch)
  97.     ON_COMMAND(ID_NETSEARCH, OnNetSearch)
  98.     ON_UPDATE_COMMAND_UI(ID_SECURITY, OnUpdateSecurity)
  99.     ON_UPDATE_COMMAND_UI(IDS_SECURITY_STATUS, OnUpdateSecurityStatus)
  100.     ON_UPDATE_COMMAND_UI(ID_VIEW_COMMANDTOOLBAR, OnUpdateViewCommandToolbar)
  101.     ON_UPDATE_COMMAND_UI(ID_VIEW_LOCATIONTOOLBAR, OnUpdateViewLocationToolbar)
  102.     ON_UPDATE_COMMAND_UI(ID_VIEW_CUSTOMTOOLBAR, OnUpdateViewCustomToolbar)
  103.     ON_UPDATE_COMMAND_UI(ID_VIEW_NAVCENTER, OnUpdateViewNavCenter)
  104.  
  105.     //}}AFX_MSG_MAP
  106. END_MESSAGE_MAP()
  107.  
  108. #ifndef _AFXDLL
  109. #define new DEBUG_NEW  // MSVC Debugging new...goes to regular new in release mode
  110. #endif
  111.  
  112. /////////////////////////////////////////////////////////////////////////////
  113. // CMainFrame construction/destruction
  114. CMainFrame::CMainFrame()
  115. {
  116.     m_pNext = NULL;
  117.     m_pHistoryWindow = NULL;
  118.     m_pDocInfoWindow = NULL;
  119.     m_barLocation = NULL;
  120.     m_barLinks = NULL;
  121.     m_pCommandToolbar = NULL;
  122.  
  123.     m_tabFocusInMainFrm = TAB_FOCUS_IN_NULL ;
  124.     m_SrvrItemCount = 0;
  125.     m_bAutoMenuEnable = FALSE;  // enable all items by default -- needed for hotlist/etc which have no handler
  126. }
  127.  
  128. CMainFrame::~CMainFrame()
  129. {
  130.     if(m_barLinks)
  131.         delete m_barLinks;
  132.  
  133.     if(m_barLocation)
  134.         delete m_barLocation;
  135.  
  136.     if(m_pCommandToolbar)
  137.         delete m_pCommandToolbar;
  138. }
  139.  
  140.  
  141. //
  142. // Create the ledges
  143. //
  144. BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext *pContext)
  145. {
  146.     //    Call the base, have it do the creation magic.
  147.     BOOL bRetval = CGenericFrame::OnCreateClient(lpcs, pContext);
  148.     if(bRetval == TRUE)    {
  149.         //    Context Forever
  150.         //    We know that the view that was made for the frame was the very last one
  151.         //        created, use it to construct the context.
  152.         //    Create a grid for each initial view.
  153.         CWnd *pView = GetDescendantWindow(AFX_IDW_PANE_FIRST, TRUE);
  154.         ASSERT(pView);
  155.         CWinCX *pDontCare = new CWinCX((CGenericDoc *)pContext->m_pCurrentDoc,
  156.             this, (CGenericView *)pView);
  157.         SetMainContext(pDontCare);    //    This is the main context.
  158.         SetActiveContext(pDontCare);    //    And the active one
  159.  
  160.         // cmanske: The following SetFocus() causes trouble for the Editor!
  161.         // We don't have our pMWContext->is_editor flag set yet 
  162.         //   and we have problems with JavaScript message processing
  163.         //   caused by the SetFocus message.
  164.         // So test for Edit frame and set the context flag now
  165. #ifdef EDITOR
  166.         if( IsEditFrame() && pDontCare->GetContext() ) {
  167.             pDontCare->GetContext()->is_editor = TRUE;
  168.         }
  169. #endif //EDITOR
  170.         // mwh - CDCCX::Initialize() will initialize the color palette, but we have to make sure we have 
  171.         // the focus first for realizePalette()    to work.
  172.         ::SetFocus(pView->m_hWnd);
  173.         RECT rect;
  174.         GetClientRect(&rect);
  175.         pDontCare->Initialize(pDontCare->CDCCX::IsOwnDC(), &rect);
  176.  
  177. #pragma message(__FILE__ ": move all this into the context constructor")
  178.         pDontCare->GetContext()->fancyFTP = TRUE;
  179.         pDontCare->GetContext()->fancyNews = TRUE;
  180.         pDontCare->GetContext()->intrupt = FALSE;
  181.         pDontCare->GetContext()->reSize = FALSE;
  182.     }
  183.     return bRetval;    
  184. }
  185.  
  186. int CMainFrame::m_FirstFrame = 1;
  187.  
  188. // Read the initial sizes out of preferences file
  189. //
  190. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  191. {
  192.     int16 iLeft,iRight,iTop,iBottom;
  193.     PREF_GetRectPref("browser.window_rect", &iLeft, &iTop, &iRight, &iBottom);
  194.  
  195.     if (iLeft != -1) {
  196.         cs.x = iLeft;
  197.         cs.y = iTop;
  198.         cs.cx = iRight - cs.x;
  199.         cs.cy = iBottom - cs.y;
  200.     }
  201.     
  202.     if(theApp.m_iCmdLnCX != -1) {
  203.         cs.cx = theApp.m_iCmdLnCX;
  204.     }
  205.     if(theApp.m_iCmdLnCY != -1) {
  206.         cs.cy = theApp.m_iCmdLnCY;
  207.     }
  208.     // no menu in kiosk mode.  duh.
  209.     if (theApp.m_bKioskMode || theApp.m_ParentAppWindow)
  210.         cs.hMenu = NULL;
  211.  
  212.     return(CGenericFrame::PreCreateWindow(cs));
  213. }
  214.  
  215.                                           
  216. //
  217. // Initialize the Frame window
  218. //
  219. //#define DONT_DO_ANIM_PAL
  220. #ifndef DONT_DO_ANIM_PAL
  221. IL_RGB animationPalette[] =
  222.     { //  R   G   B
  223.         {255,255,204,0},
  224.         {204,153,102,0},
  225.         {255,102,51, 0},
  226.         { 66,154,167,0},
  227.         {  0, 55, 60,0},
  228.         {  0,153,255,0},
  229.         { 51, 51,102,0},
  230.         {128,  0,  0,0},
  231.         {255,102,204,0},
  232.         {153,  0,102,0},
  233.         {153,102,204,0},
  234.         { 34, 34 ,34,0},
  235.         {204,204,255,0},
  236.         {153,153,255,0},
  237.         {102,102,204,0},
  238.         { 51,255,153,0}
  239.     };
  240.  
  241. int iLowerSystemColors = 10;
  242. // int iLowerAnimationColors = 12;
  243. int iLowerAnimationColors = 16;
  244. int iLowerColors = 26; // iLowerSystemColors + iLowerAnimationColors;
  245. int colorCubeSize = 216;
  246.  
  247. #endif
  248.  
  249. //      Toolbar width and heights.
  250. #define MIXED_HEIGHT  32
  251. #define MIXED_WIDTH   40
  252. #define PICT_HEIGHT   21
  253. #define PICT_WIDTH    23
  254. #ifdef XP_WIN32
  255. #define TEXT_HEIGHT     14
  256. #define TEXT_WIDTH      42
  257. #else
  258. #define TEXT_HEIGHT     14
  259. #define TEXT_WIDTH      49
  260. #endif
  261.  
  262.  
  263. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  264. {
  265.  
  266.     if (CGenericFrame::OnCreate(lpCreateStruct) == -1)
  267.         return -1;
  268.  
  269.     if( IsEditFrame() ){
  270.         // Note: Don't create the Browser toolbars in Editor frame,
  271.         //   except for the status bar
  272.         LPNSSTATUSBAR pIStatusBar = NULL;
  273.         GetChrome()->QueryInterface( IID_INSStatusBar, (LPVOID *) &pIStatusBar );
  274.         if ( pIStatusBar ) {
  275.             pIStatusBar->Create( this );
  276.             pIStatusBar->Release();
  277.         }
  278.     } else {
  279.         
  280.         //I'm hardcoding string since I don't want it translated.
  281.         GetChrome()->CreateCustomizableToolbar("Browser", 5, TRUE);
  282.  
  283.         // Now that the application palette has been created (if 
  284.         //   appropriate) we can create the url bar.  The animation 
  285.         //   might need custom colors so we need the palette to be around
  286.         //
  287.         CreateMainToolbar();
  288.  
  289.         if (!theApp.m_bInGetCriticalFiles) { // if we are here, don't show link bar
  290.             CreateLocationBar();
  291.             CreateLinkBar();  
  292.             GetChrome()->FinishedAddingBrowserToolbars();
  293.         }
  294.  
  295.         LPNSSTATUSBAR pIStatusBar = NULL;
  296.         GetChrome()->QueryInterface( IID_INSStatusBar, (LPVOID *) &pIStatusBar );
  297.         if( pIStatusBar ) 
  298.         {
  299.             pIStatusBar->Create( this );
  300.             pIStatusBar->Release();
  301.             if (theApp.m_ParentAppWindow || theApp.m_bKioskMode)
  302.                 pIStatusBar->Show(FALSE);
  303.         }
  304.  
  305.         if(!IsEditFrame())
  306.         {
  307.             AddToMenuMap(FILEMENU, IDM_MAINFRAMEFILEMENU);
  308.             AddToMenuMap(EDITMENU, IDM_MAINFRAMEEDITMENU);
  309.             AddToMenuMap(VIEWMENU, IDM_MAINFRAMEVIEWMENU);
  310.             AddToMenuMap(GOMENU, IDM_MAINFRAMEGOMENU);
  311.         }
  312.  
  313.     }
  314.  
  315.     //////////////////////////////////////////////////////////////////////////
  316.     // Turn off widgets on demand
  317.  
  318.     m_iCSID = INTL_DefaultDocCharSetID(0); // Set Global default.
  319.  
  320.     m_iCSID = INTL_DefaultDocCharSetID(0); // Set Global default.
  321.  
  322.     //  Success so far.  Also, accept drag and drop files from
  323.     //      the file manager.
  324.     //
  325.     DragAcceptFiles();
  326.  
  327.     return 0;
  328. }
  329.  
  330. int CMainFrame::CreateLocationBar()
  331. {
  332.  
  333.  
  334.     m_barLocation=new CURLBar(); 
  335.  
  336.     if (!m_barLocation->Create(this, CURLBar::IDD, CBRS_TOP,CURLBar::IDD)) {
  337.         return FALSE;
  338.     }
  339.     CToolbarWindow *pWindow = new CToolbarWindow(m_barLocation, theApp.m_pToolbarStyle, 23, 23, eSMALL_HTAB);
  340.  
  341.     BOOL bOpen, bShowing;
  342.     int32 nPos;
  343.  
  344.     //I'm hardcoding because I don't want this translated
  345.     GetChrome()->LoadToolbarConfiguration(ID_LOCATION_TOOLBAR, CString("Location_Toolbar"), nPos, bOpen, bShowing);
  346.  
  347.     if(PREF_PrefIsLocked("browser.chrome.show_url_bar"))
  348.     {
  349.         bShowing = m_bLocationBar;
  350.     }
  351.  
  352.     GetChrome()->GetCustomizableToolbar()->AddNewWindow(ID_LOCATION_TOOLBAR, pWindow, nPos, 21, 21, 3, CString(szLoadString(ID_LOCATION_TOOLBAR)), theApp.m_pToolbarStyle, bOpen, FALSE);
  353.     if (theApp.m_ParentAppWindow || theApp.m_bKioskMode)
  354.         GetChrome()->ShowToolbar(ID_LOCATION_TOOLBAR, FALSE);
  355.     else
  356.         GetChrome()->ShowToolbar(ID_LOCATION_TOOLBAR, bShowing);
  357.  
  358.     m_barLocation->SetContext((LPUNKNOWN)GetMainContext());
  359.  
  360.     RecalcLayout();
  361.  
  362.     return TRUE;
  363. }
  364.  
  365. int CMainFrame::CreateLinkBar(void)
  366. {
  367.     m_barLinks = CLinkToolbar::CreateUserToolbar(this);
  368.  
  369.     CButtonToolbarWindow *pWindow = new CButtonToolbarWindow(m_barLinks, theApp.m_pToolbarStyle, 43, 27, eSMALL_HTAB);
  370.  
  371.     BOOL bOpen, bShowing;
  372.  
  373.     int32 nPos;
  374.  
  375.     //I'm hardcoding because I don't want this translated
  376.     GetChrome()->LoadToolbarConfiguration(ID_PERSONAL_TOOLBAR, CString("Personal_Toolbar"), nPos, bOpen, bShowing);
  377.  
  378.     if(PREF_PrefIsLocked("browser.chrome.show_directory_buttons"))
  379.     {
  380.         bShowing = m_bStarter;
  381.     }
  382.  
  383.     GetChrome()->GetCustomizableToolbar()->AddNewWindow(ID_PERSONAL_TOOLBAR, pWindow, nPos, 43, 27, 1, CString(szLoadString(ID_PERSONAL_TOOLBAR)),theApp.m_pToolbarStyle, bOpen, FALSE);
  384.     if (theApp.m_ParentAppWindow || theApp.m_bKioskMode)
  385.         GetChrome()->ShowToolbar(ID_PERSONAL_TOOLBAR, FALSE);
  386.     else
  387.          GetChrome()->ShowToolbar(ID_PERSONAL_TOOLBAR, bShowing);
  388.  
  389.     RecalcLayout();
  390.  
  391.     return TRUE;
  392. }
  393.  
  394. int CMainFrame::CreateMainToolbar(void)
  395. {
  396.  
  397.     m_pCommandToolbar =new CCommandToolbar(15, theApp.m_pToolbarStyle, 43, 27, 27);
  398.  
  399.  
  400.  
  401.     if (!m_pCommandToolbar->Create(this))
  402.     {
  403.             return FALSE;
  404.     }
  405.  
  406.  
  407.     m_pCommandToolbar->SetBitmap(IDB_PICTURES);
  408.  
  409.     CButtonToolbarWindow *pWindow = new CButtonToolbarWindow(m_pCommandToolbar, theApp.m_pToolbarStyle, 43, 27, eLARGE_HTAB);
  410.  
  411.  
  412.     CString statusStr, toolTipStr, textStr;
  413.     int nBitmapIndex = 0;
  414.  
  415.     int nCount = theApp.m_bShowNetscapeButton ? sizeof(buttons)/sizeof(UINT) : (sizeof(buttons)/sizeof(UINT)) - 1;
  416.  
  417.     for(int i = 0; i < nCount; i++)
  418.     {
  419.         CCommandToolbarButton *pCommandButton = new CCommandToolbarButton;
  420.  
  421.         WFE_ParseButtonString(buttons[i], statusStr, toolTipStr, textStr);
  422.  
  423.         DWORD dwButtonStyle = 0;
  424.  
  425.         if(buttons[i] == ID_NAVIGATE_FORWARD || buttons[i] == ID_NAVIGATE_BACK)
  426.         {
  427.             dwButtonStyle = TB_HAS_TIMED_MENU | TB_DYNAMIC_TOOLTIP;
  428.         }
  429.         else if(buttons[i] == ID_GO_HOME)
  430.         {
  431.             dwButtonStyle = TB_DYNAMIC_TOOLTIP;
  432.         }
  433.         else if(buttons[i] == ID_FILE_PRINT)
  434.         {
  435.             dwButtonStyle = TB_DYNAMIC_TOOLTIP | TB_DYNAMIC_STATUS;
  436.         }
  437.         else if(buttons[i] == ID_PLACES)
  438.         {
  439.             dwButtonStyle = TB_HAS_TIMED_MENU;
  440.         }
  441.         else if(buttons[i]== ID_NAVIGATE_INTERRUPT)
  442.         {
  443.             toolTipStr.LoadString(IDS_BROWSER_STOP_TIP);
  444.         }
  445.     
  446.         pCommandButton->Create(m_pCommandToolbar, theApp.m_pToolbarStyle, CSize(44, 37), CSize(25, 25),
  447.                         (const char*) textStr,(const char*) toolTipStr, (const char*) statusStr,
  448.                         0, nBitmapIndex, CSize(23,21), buttons[i], -1, dwButtonStyle);
  449.  
  450.         pCommandButton->SetBitmap(m_pCommandToolbar->GetBitmap(), TRUE);
  451.  
  452.         m_pCommandToolbar->AddButton(pCommandButton, i);
  453.         if(buttons[i] == ID_FILE_PRINT)
  454.             nBitmapIndex+=2;
  455.  
  456.         nBitmapIndex++;
  457.     }
  458.     
  459.  
  460.     if(prefInfo.m_bAutoLoadImages)
  461.     {
  462.         m_pCommandToolbar->HideButtonByCommand(ID_VIEW_LOADIMAGES);
  463.     }
  464.     BOOL bOpen, bShowing;
  465.  
  466.     int32 nPos;
  467.  
  468.     //I'm hardcoding because I don't want this translated
  469.     GetChrome()->LoadToolbarConfiguration(ID_NAVIGATION_TOOLBAR, CString("Navigation_Toolbar"), nPos, bOpen, bShowing);
  470.  
  471.     if(PREF_PrefIsLocked("browser.chrome.show_toolbar"))
  472.     {
  473.         bShowing = m_bShowToolbar;
  474.     }
  475.     GetChrome()->GetCustomizableToolbar()->AddNewWindow(ID_NAVIGATION_TOOLBAR, pWindow,nPos, 50, 37, 0, CString(szLoadString(ID_NAVIGATION_TOOLBAR)),theApp.m_pToolbarStyle, bOpen, FALSE);
  476.  
  477.     if (theApp.m_ParentAppWindow || theApp.m_bKioskMode)
  478.         GetChrome()->ShowToolbar(ID_NAVIGATION_TOOLBAR, FALSE);
  479.     else
  480.         GetChrome()->ShowToolbar(ID_NAVIGATION_TOOLBAR, bShowing);
  481.     
  482.  
  483.     RecalcLayout();
  484.  
  485.     return TRUE;
  486. }
  487.  
  488. void CMainFrame::OnShowWindow (BOOL bShow, UINT nStatus)
  489. {
  490.     CGenericFrame::OnShowWindow(bShow,nStatus);
  491.     // We don't seem to draw correctly as a child window on the initial pass.
  492.     if(theApp.m_bChildWindow)
  493.     RecalcLayout();
  494. }
  495.  
  496. // returns TRUE if something was added to the folder, false otherwise
  497. BOOL CMainFrame::FileBookmark(HT_Resource pFolder)
  498. {
  499.  
  500.         History_entry *pHistEnt = SHIST_GetCurrent( &(GetMainContext()->GetContext()->hist) );
  501.  
  502.         if(pHistEnt)
  503.         {
  504.  
  505.             HT_AddToContainer(pFolder, GetMainContext()->GetContext()->title, pHistEnt->address);
  506.             return TRUE;
  507.         }
  508.  
  509.         return FALSE;
  510. }
  511.  
  512. //
  513. // The window has been created and activated so the user can
  514. //   see it.  Only now is it safe to load the home page
  515. //
  516. void CMainFrame::OnLoadHomePage()
  517. {
  518. #ifdef EDITOR
  519.     if ( IsEditFrame() )
  520.     {
  521.         if ( theApp.m_CmdLineLoadURL ) {
  522.             // Load command line URL, FALSE = do NOT start new window
  523.             LoadUrlEditor(theApp.m_CmdLineLoadURL, FALSE);
  524.             // The filename supplied with the -EDIT switch
  525.             //   should NOT be stored as the "home page",
  526.             //   load it only once then remove the URL
  527.             XP_FREE(theApp.m_CmdLineLoadURL);
  528.             theApp.m_CmdLineLoadURL = NULL;
  529.         } else {
  530.             // Start new doc with URL
  531.             GetMainContext()->NormalGetUrl("about:editfilenew");
  532.         }
  533.         return;
  534.     }
  535. #endif /* EDITOR */
  536.     
  537.     LPCSTR    lpszHomePage = (LPCSTR)theApp.m_pHomePage;
  538.     int32     nStartup = 1;  // 0 = blank, 1 = home, 2 = last
  539.     CString    strLastURL;
  540.     CString csTmp;
  541.     char *tmpBuf;
  542.     XP_Bool bOverride = FALSE;
  543.  
  544.     PREF_GetBoolPref("browser.startup.homepage_override",&bOverride);
  545.  
  546.     if (bOverride) {
  547.         // if the over-ride preference is set, use that instead
  548.         PREF_CopyConfigString("startup.homepage_override_url",&tmpBuf);
  549.         if (tmpBuf && tmpBuf[0]) {
  550.             csTmp = tmpBuf;
  551.             lpszHomePage = csTmp;
  552.             XP_FREE(tmpBuf);
  553.         }
  554.         PREF_SetBoolPref("browser.startup.homepage_override",FALSE);
  555.     }
  556.  
  557.     // If the user has specified a URL on the command line assume they want
  558.     // to load it; otherwise don't load the homepage if the autoload entry
  559.     // isn't "yes"
  560.     if (theApp.m_CmdLineLoadURL && theApp.m_nChangeHomePage) {
  561.         lpszHomePage = (LPCSTR)theApp.m_CmdLineLoadURL;
  562.  
  563.     } else {
  564.         // There was neither a command line home page nor an Initial Home
  565.         // Page entry so see if the user wants to load their default
  566.         // home page or not
  567.         if (theApp.m_bDontLoadHome)
  568.             nStartup = 0;
  569.         else
  570.             PREF_GetIntPref("browser.startup.page", &nStartup);
  571.     }
  572.  
  573.     // See if they want us to load the last page they viewed
  574.     if (nStartup == 2) {
  575.         if (GH_GetMRUPage(strLastURL.GetBufferSetLength(1024), 1024) > 0)
  576.             lpszHomePage = (LPCSTR)strLastURL;
  577.     }
  578.  
  579.     // If there is a home page location put it in the URL bar only if  we
  580.     // autoload
  581.     if (lpszHomePage) {
  582.         if (nStartup != 0){
  583.             GetMainContext()->NormalGetUrl(lpszHomePage);
  584.  
  585.             CURLBar *pUrlBar = (CURLBar *)GetChrome()->GetToolbar(ID_LOCATION_TOOLBAR);
  586.             if(pUrlBar != NULL)
  587.                 pUrlBar->UpdateFields(lpszHomePage);
  588.         }
  589.     }
  590. }
  591.  
  592. //////////////////////////////////////////////////////////////////////////////
  593.  
  594. void CMainFrame::OnDestroy()
  595. {
  596.     // The maps should be empty, because the dynamic menu items are
  597.     // freed when the pop-up menus go away
  598.  
  599.     //////////////////////////////////////////////////////////////////////
  600.     //  Clean up the location/starter button bars
  601.     CGenericFrame::OnDestroy();
  602. }
  603.  
  604.  
  605. void CMainFrame::OnClose()
  606. {
  607. //  Purpose:            Close a window.
  608. //  Arguments:          void
  609. //  Return Value:       void
  610. //  Comments:           Wrap up any processing of frame that
  611. //                          needs to be handled, such as
  612. //                          shutting down print preview.
  613. //  Revision History:
  614. //      11-06-94    created GAB
  615. //
  616.     // This frame still begin used by OLE server.
  617.     if (HasSrvrItem()) {
  618.         return;
  619.     }
  620.     //    See if the document will allow closing.
  621.     //  Do not only query the active document as MFC does.
  622.     //  Instead, query the main context document, and it will check children also.
  623.     CDocument* pDocument = NULL;
  624.     if(GetMainWinContext())    {
  625.         pDocument = (CDocument *)GetMainWinContext()->GetDocument();
  626.     }
  627.     if (pDocument != NULL && !pDocument->CanCloseFrame(this))
  628.     {
  629.         // document can't close right now -- don't close it
  630.         return;
  631.     }
  632.  
  633.     //    Only save the window position if we're an browser context and the size wasn't chrome specified.
  634.     //    This blocks saving the size/pos on things like html dialogs,
  635.     //        view source, and document info.
  636.     if(GetMainWinContext() && GetMainWinContext()->GetContext()->type == MWContextBrowser && 
  637.        GetMainWinContext()->m_bSizeIsChrome == FALSE)    {
  638.         WINDOWPLACEMENT wp;
  639.         FEU_InitWINDOWPLACEMENT(GetSafeHwnd(), &wp);
  640.  
  641.         PREF_SetRectPref("browser.window_rect", (int)wp.rcNormalPosition.left,
  642.             (int)wp.rcNormalPosition.top, (int)wp.rcNormalPosition.right,
  643.             (int)wp.rcNormalPosition.bottom);
  644.  
  645.         //I'm hardcoding because I don't want this translated
  646.         GetChrome()->SaveToolbarConfiguration(ID_NAVIGATION_TOOLBAR, CString("Navigation_Toolbar"));
  647.         GetChrome()->SaveToolbarConfiguration(ID_LOCATION_TOOLBAR, CString("Location_Toolbar"));
  648.         GetChrome()->SaveToolbarConfiguration(ID_PERSONAL_TOOLBAR, CString("Personal_Toolbar"));
  649.         PREF_SetIntPref("browser.wfe.show_value",(int)wp.showCmd);
  650.     }
  651.  
  652.     //    Tell our views to get rid of their contexts.
  653.     if(GetMainWinContext())    {
  654.         GetMainWinContext()->GetView()->FrameClosing();
  655.     }
  656.  
  657.     //  Call base to close.
  658.     //
  659.  
  660.     CGenericFrame::OnClose();
  661. }
  662.  
  663. typedef struct drop_files_closure {
  664.     HDROP        hDropInfo;
  665.     CMainFrame      * pMain;
  666.     char     ** urlArray;
  667. } drop_files_closure;
  668.  
  669. /* Mocha has processed the event handler for the drop event.  Now come back and execute
  670.  * the drop files call if EVENT_OK or cleanup and go away.
  671.  */
  672. static void
  673. win_drop_files_callback(MWContext * pContext, LO_Element * pEle, int32 event,
  674.                      void * pObj, ETEventStatus status)
  675. {
  676.     HDROP hDropInfo;
  677.     
  678.     drop_files_closure * pClose = (drop_files_closure *) pObj;
  679.     hDropInfo = pClose->hDropInfo;
  680.  
  681.     // make sure document hasn't gone away or event cancelled
  682.     if(status == EVENT_PANIC || status == EVENT_CANCEL) {
  683.     int i_loop=0;
  684.     while ((pClose->urlArray)[i_loop])
  685.         XP_FREE((pClose->urlArray)[i_loop++]);
  686.     XP_FREE(pClose->urlArray);
  687.         XP_FREE(pClose);
  688.         ::DragFinish(hDropInfo);
  689.     return;
  690.     }
  691.  
  692.     // find out who we are
  693.     CMainFrame * pMain = pClose->pMain;
  694.  
  695.     //  First, check the number of files dropped.
  696.     //
  697.     auto int i_num = ::DragQueryFile(hDropInfo, (UINT)-1, NULL, 0);
  698.  
  699.     // Get the current history entry
  700.     History_entry * his = SHIST_GetCurrent(&(pMain->GetMainContext()->GetContext()->hist));
  701.  
  702.     // If we got a history entry, see if it's an
  703.     // FTP directory listing.  If it is then lets ask the
  704.     // user if they want to upload the dropped files.
  705.     if(his 
  706.         && !strncasecomp(his->address, "ftp", 3)
  707.           && his->address[strlen(his->address)-1] == '/'
  708.             && FE_Confirm(pMain->GetMainContext()->GetContext(), szLoadString(IDS_UPLOAD_FILES)))
  709.       {
  710.         // If the user wants to upload them, stuff the files
  711.         // in the URL struct and start the load
  712.         URL_Struct * URL_s = NET_CreateURLStruct(his->address, NET_SUPER_RELOAD);
  713.  
  714.         if(!URL_s)
  715.             goto clean_up;
  716.  
  717.         URL_s->method = URL_POST_METHOD;
  718.         URL_s->files_to_post = (char **)XP_ALLOC((i_num+1) * sizeof(char*));
  719.  
  720.         if(!URL_s->files_to_post)
  721.           {
  722.             NET_FreeURLStruct(URL_s);
  723.             goto clean_up;
  724.           }                                             
  725.  
  726.         // load the file names into the files_to_post array
  727.           auto char ca_drop[_MAX_PATH];
  728.           for(auto int i_loop = 0; i_loop < i_num; i_loop++)
  729.             {
  730.               ::DragQueryFile(hDropInfo, i_loop, ca_drop, _MAX_PATH);
  731.  
  732.               URL_s->files_to_post[i_loop] = XP_STRDUP((const char*)ca_drop);
  733.           }
  734.         URL_s->files_to_post[i_loop] = NULL; // terminate array
  735.  
  736.         pMain->GetMainContext()->GetUrl(URL_s, FO_CACHE_AND_PRESENT);
  737.       }
  738.     else
  739.       {
  740.         //  Loop through them, each doing a load.
  741.         //  This should be insane fun with external viewers.
  742.         //
  743.         auto char ca_drop[_MAX_PATH];
  744.         CString csUrl;
  745.         for(auto int i_loop = 0; i_loop < i_num; i_loop++)  {
  746.             ::DragQueryFile(hDropInfo, i_loop, ca_drop, _MAX_PATH);
  747.  
  748.             //  Convert to an acceptable URL.
  749.             //  It always has the full path!
  750.             //
  751.             WFE_ConvertFile2Url(csUrl, ca_drop);
  752.  
  753.             pMain->GetMainContext()->NormalGetUrl(csUrl);
  754.  
  755.             //  Block until load is complete, if they did multiple
  756.             //      files.
  757.             //
  758.             if(i_loop != i_num - 1) {
  759.                 auto int net_ret = 1;
  760.                 winfeInProcessNet = TRUE;
  761.                 while(net_ret)  {
  762.                     net_ret = NET_ProcessNet(NULL, NET_EVERYTIME_TYPE);
  763.                 }
  764.                 winfeInProcessNet = FALSE;
  765.             }
  766.          }
  767.       }
  768.  
  769. clean_up:
  770.     //  Clean up
  771.     //
  772.     // Free mocha closure obj
  773.     int i_loop=0;
  774.     while ((pClose->urlArray)[i_loop])
  775.         XP_FREE((pClose->urlArray)[i_loop++]);
  776.     XP_FREE(pClose->urlArray);
  777.         XP_FREE(pClose);
  778.         ::DragFinish(hDropInfo);
  779.  
  780.     //  Don't call this, or GPF, since we do it all anyways....
  781.     //
  782.     //CGenericFrame::OnDropFiles(hDropInfo);
  783.  
  784. }
  785.  
  786. void CMainFrame::OnDropFiles(HDROP hDropInfo)
  787. {
  788.     // TODO: Add your message handler code here and/or call default
  789.     //
  790.  
  791.     //    Make sure we have a main context.
  792.     if(GetMainContext() == NULL)    {
  793.         return;
  794.     }
  795. #ifdef EDITOR
  796.     // The view handles all dragNdrop in editor
  797.     if( IsEditFrame() ){
  798.         CWnd * pWnd = FromHandle(GetMainWinContext()->GetPane());
  799.         if( pWnd ){
  800.             ((CNetscapeEditView*)pWnd)->DropFiles(hDropInfo, TRUE);
  801.         }
  802.         return;
  803.     }
  804. #endif
  805.  
  806.     //  First, check the number of files dropped.
  807.     //
  808.     auto int i_num = ::DragQueryFile(hDropInfo, (UINT)-1, NULL, 0);
  809.  
  810.     // Mocha sends an event here now to allow cancellation of OnDropFiles message.
  811.     auto char ca_drop[_MAX_PATH];
  812.     CString csUrl;
  813.     int size = sizeof(char*) * (i_num + 1);
  814.     char ** urlArray = (char**)XP_ALLOC(size);
  815.     XP_ASSERT(urlArray);
  816.  
  817.     int i_loop;
  818.     for(i_loop = 0; i_loop < i_num; i_loop++)  {
  819.         ::DragQueryFile(hDropInfo, i_loop, ca_drop, _MAX_PATH);
  820.  
  821.     //  Convert to an acceptable URL.
  822.     //  It always has the full path!
  823.     //
  824.     WFE_ConvertFile2Url(csUrl, ca_drop);
  825.     urlArray[i_loop] = XP_STRDUP(csUrl);
  826.     }
  827.     urlArray[i_loop] = 0;
  828.  
  829.     drop_files_closure * pClosure = XP_NEW_ZAP(drop_files_closure);
  830.     pClosure->pMain = this;
  831.     pClosure->hDropInfo = hDropInfo;
  832.     pClosure->urlArray = urlArray;
  833.  
  834.     // Get mouse at time of drop
  835.     POINT pointDrop;
  836.  
  837.     ::DragQueryPoint( hDropInfo, &pointDrop);
  838.  
  839.     ClientToScreen( &pointDrop );
  840.  
  841.     JSEvent *event;
  842.     event = XP_NEW_ZAP(JSEvent);
  843.     event->type = EVENT_DRAGDROP;
  844.     event->screenx = pointDrop.x;
  845.     event->screeny = pointDrop.y;
  846.     event->modifiers = (GetKeyState(VK_SHIFT) < 0 ? EVENT_SHIFT_MASK : 0) 
  847.             | (GetKeyState(VK_CONTROL) < 0 ? EVENT_CONTROL_MASK : 0) 
  848.             | (GetKeyState(VK_MENU) < 0 ? EVENT_ALT_MASK : 0); 
  849.     event->data = (void *)urlArray;
  850.     event->dataSize = i_num;
  851.  
  852.     ET_SendEvent(GetMainContext()->GetContext(), 0, event, win_drop_files_callback, pClosure);
  853.     return;
  854.  
  855.     //Mocha will handle cleanup and DragFinish when it calls back in.
  856.     
  857. }
  858.