home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / gui / CNetscapeWindow.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  5.1 KB  |  159 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. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  20. //    CNetscapeWindow.cp
  21. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  22.  
  23. #include "CNetscapeWindow.h"
  24.  
  25. #ifdef PowerPlant_PCH
  26. #include PowerPlant_PCH
  27. #endif
  28.  
  29. #include "prefapi.h"
  30. #include "resgui.h"
  31.  
  32. #include "CDragBar.h"
  33. #include "CDragBarContainer.h"
  34. #include "CNSContext.h"
  35. #include "net.h"
  36. #include "client.h"
  37. #include "PascalString.h"
  38.  
  39. //-----------------------------------
  40. CNetscapeWindow::CNetscapeWindow(LStream *inStream, DataIDT inWindowType)
  41. //-----------------------------------
  42. :    CMediatedWindow(inStream, inWindowType)
  43. {
  44.     // We need to read the preferences to really know whether
  45.     // or not a tool bar should be visible. This can be taken
  46.     // care of in the FinishCreateSelf method of derived classes.
  47.     // For now, just assume they are all visible
  48.     for (int i = 0; i < kMaxToolbars; i++)
  49.         mToolbarShown[i] = true;
  50.     SetAttribute(windAttr_DelaySelect);
  51. } // CNetscapeWindow::CNetscapeWindow
  52.                                     
  53. //-----------------------------------
  54. CNetscapeWindow::~CNetscapeWindow()
  55. //-----------------------------------
  56. {
  57. }
  58.     
  59. //-----------------------------------
  60. Boolean CNetscapeWindow::ObeyCommand(CommandT inCommand, void *ioParam)
  61. //-----------------------------------
  62. {
  63.     Boolean        cmdHandled = true;
  64.     
  65.     switch (inCommand)
  66.     {
  67.         case cmd_Preferences:
  68.             DoDefaultPrefs();
  69.             break;
  70.         default:
  71.             cmdHandled = Inherited::ObeyCommand(inCommand, ioParam);
  72.             break;
  73.     }
  74.         
  75.     return cmdHandled;
  76. }
  77.  
  78. //-----------------------------------
  79. void CNetscapeWindow::ShowOneDragBar(PaneIDT dragBarID, Boolean isShown)
  80. // shows or hides a single toolbar
  81. // This used to be in CBrowserWindow. Moved up to CNetscapeWindow on 5/23/97 by andrewb
  82. //-----------------------------------
  83. {
  84.     CDragBarContainer* container = dynamic_cast<CDragBarContainer*>(FindPaneByID(CDragBarContainer::class_ID));
  85.     CDragBar* theBar = dynamic_cast<CDragBar*>(FindPaneByID(dragBarID));
  86.     
  87.     if (container && theBar) {
  88.         if (isShown)
  89.             container->ShowBar(theBar);
  90.         else
  91.             container->HideBar(theBar);
  92.     }
  93. } // CNetscapeWindow::ShowOneDragBar
  94.  
  95. //-----------------------------------
  96. void CNetscapeWindow::ToggleDragBar(PaneIDT dragBarID, int whichBar, const char* prefName)
  97. // toggles a toolbar and updates the specified preference
  98. // This used to be in CBrowserWindow. Moved up to CNetscapeWindow on 5/23/97 by andrewb
  99. //-----------------------------------
  100. {
  101.     Boolean showIt = ! mToolbarShown[whichBar];
  102.     ShowOneDragBar(dragBarID, showIt);
  103.     
  104.     if (prefName) {
  105.         PREF_SetBoolPref(prefName, showIt);
  106.     }
  107.     
  108.     // force menu items to update show "Show" and "Hide" string changes are reflected
  109.     LCommander::SetUpdateCommandStatus(true);
  110.         
  111.     mToolbarShown[whichBar] = showIt;
  112. } // CNetscapeWindow::ToggleDragBar
  113.  
  114. //-----------------------------------
  115. URL_Struct* CNetscapeWindow::CreateURLForProxyDrag(char* outTitle)
  116. //-----------------------------------
  117. {
  118.     // Default implementation
  119.     URL_Struct* result = nil;
  120.     CNSContext* context = GetWindowContext();
  121.     if (context)
  122.     {        
  123.         History_entry* theCurrentHistoryEntry = context->GetCurrentHistoryEntry();
  124.         if (theCurrentHistoryEntry)
  125.         {
  126.             result = NET_CreateURLStruct(theCurrentHistoryEntry->address, NET_NORMAL_RELOAD);
  127.             if (outTitle)
  128.             {
  129.                 // The longest string that outTitle can contain is 255 characters but it
  130.                 // will eventually be truncated to 31 characters before it's used so why
  131.                 // not just truncate it here.  Fixes bug #86628 where a page has an
  132.                 // obscenely long (something like 1000 characters) title
  133.                 strncpy(outTitle, theCurrentHistoryEntry->title, 255);
  134.                 outTitle[255] = 0;    // Make damn sure it's truncated
  135.                 NET_UnEscape(outTitle);
  136.             }
  137.         }
  138.     }
  139.     return result;
  140. } // CNetscapeWindow::CreateURLForProxyDrag
  141.  
  142. //-----------------------------------
  143. /*static*/void CNetscapeWindow::DisplayStatusMessageInAllWindows(ConstStringPtr inMessage)
  144. //-----------------------------------
  145. {
  146.     CMediatedWindow* aWindow = NULL;
  147.     CWindowIterator iter(WindowType_Any);
  148.     while (iter.Next(aWindow))
  149.     {
  150.         CNetscapeWindow* nscpWindow = dynamic_cast<CNetscapeWindow*>(aWindow);
  151.         if (nscpWindow)
  152.         {
  153.             MWContext* mwContext = *nscpWindow->GetWindowContext();
  154.             if (mwContext)
  155.                 FE_Progress(mwContext, CStr255(inMessage));
  156.         }
  157.     }
  158. } // CNetscapeWindow::DisplayStatusMessageInAllWindows
  159.