home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / View.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  6.6 KB  |  300 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.    View.cpp -- implementation file for View.
  20.    Created: Chris Toshok <toshok@netscape.com>, 17-Sep-96.
  21.  */
  22.  
  23.  
  24.  
  25. #include "View.h"
  26. #include "ViewGlue.h"
  27. #include "xfe.h"
  28. #include "xp_mem.h"
  29. #include "xpassert.h"
  30. #include "xfe2_extern.h"
  31. #include "Xfe/Xfe.h"
  32.  
  33. const char * XFE_View::chromeNeedsUpdating = "XFE_View::chromeNeedsUpdating";
  34. const char * XFE_View::commandNeedsUpdating = "XFE_View::commandNeedsUpdating";
  35. const char * XFE_View::statusNeedsUpdating = "XFE_View::statusNeedsUpdating";
  36. const char * XFE_View::statusNeedsUpdatingMidTruncated = "XFE_View::statusNeedsUpdatingMidTruncated";
  37.  
  38. XFE_View::XFE_View(XFE_Component *toplevel_component,
  39.            XFE_View *parent_view, MWContext *context) : XFE_Component(toplevel_component)
  40. {
  41.   m_parentView = parent_view;
  42.   m_subviews = NULL;
  43.   m_numsubviews = 0;
  44.   m_numsubviews_allocated = 0 ;
  45.   m_contextData = context;
  46.  
  47.   /* View can contains other view as its sub-views*/
  48.   m_numsubviews = 0;
  49.   m_numsubviews_allocated = 1;
  50.  
  51.   m_subviews = (XFE_View**)XP_CALLOC(m_numsubviews_allocated, sizeof(XFE_View*));
  52.  
  53.   setScrollbarsActive(TRUE);
  54. }
  55.  
  56. XFE_View::~XFE_View()
  57. {
  58.  
  59.   if (m_numsubviews)
  60.     {
  61.       int i;
  62.  
  63.       for (i = 0; i < m_numsubviews; i ++)
  64.     delete m_subviews[i];
  65.     }
  66.  
  67.   XP_FREE(m_subviews);
  68. }
  69.  
  70. XFE_View *
  71. XFE_View::getParent()
  72. {
  73.   return m_parentView;
  74. }
  75.  
  76. MWContext *
  77. XFE_View::getContext()
  78. {
  79.   return m_contextData;
  80. }
  81.  
  82. int
  83. XFE_View::getNumSubViews()
  84. {
  85.   return m_numsubviews;
  86. }
  87.  
  88. void
  89. XFE_View::setParent(XFE_View *parent_view)
  90. {
  91.   m_parentView = parent_view;
  92. }
  93.  
  94. void
  95. XFE_View::addView(XFE_View *new_view)
  96. {
  97.   if (m_numsubviews == m_numsubviews_allocated)
  98.         {
  99.           m_numsubviews_allocated *= 2;
  100.  
  101.           m_subviews = (XFE_View**)XP_REALLOC(m_subviews,
  102.                                            sizeof(XFE_View*) * m_numsubviews_allocated);
  103.         }
  104.  
  105.   m_subviews[ m_numsubviews ++ ] = new_view;
  106. }
  107.  
  108. Boolean
  109. XFE_View::hasSubViews() 
  110. {
  111.   return fe_GetFocusGridOfContext (getContext()) ? True : False;
  112. }
  113.  
  114. XFE_View *
  115. XFE_View::widgetToView(Widget w)
  116. {
  117.   int i;
  118.  
  119.   for (i = 0; i < m_numsubviews; i ++)
  120.     if (m_subviews[i]->isWidgetInside(w))
  121.       return m_subviews[i]->widgetToView(w);
  122.  
  123.   if (isWidgetInside(w))
  124.     return this;
  125.   else
  126.     return NULL; /* not anywhere in this view heirarchy. */
  127. }
  128.  
  129. Boolean
  130. XFE_View::isCommandEnabled(CommandType cmd,
  131.                            void *calldata, XFE_CommandInfo* info)
  132. {
  133.   if ( cmd == xfeCmdStopLoading
  134.        && m_contextData )
  135.     {
  136.       return fe_IsContextStoppable(m_contextData);
  137.     }
  138.   else if (cmd == xfeCmdAboutMozilla
  139.            || cmd == xfeCmdSearchAddress
  140.            || cmd == xfeCmdOpenCustomUrl
  141.            )
  142.       {
  143.           return !XP_IsContextBusy(m_contextData);
  144.       }
  145.   else
  146.     {
  147.       for (int i = 0; i < m_numsubviews; i ++)
  148.     {
  149.       if (m_subviews[i]->handlesCommand(cmd, calldata, info))
  150.         return m_subviews[i]->isCommandEnabled(cmd, calldata, info);
  151.     }
  152.  
  153.       return False;
  154.     }
  155. }
  156.  
  157. void
  158. XFE_View::doCommand(CommandType cmd, void *calldata, XFE_CommandInfo* info)
  159. {
  160.   if ( cmd == xfeCmdStopLoading
  161.        && m_contextData )
  162.     {
  163.       XP_InterruptContext(m_contextData);
  164.     }
  165.   else if ( cmd == xfeCmdAboutMozilla )
  166.     {
  167.       fe_about_cb(NULL, m_contextData, NULL);
  168.     }
  169. #ifdef MOZ_MAIL_NEWS
  170.   else if ( cmd == xfeCmdSearchAddress)
  171.     {
  172.       fe_showLdapSearch(XfeAncestorFindApplicationShell(getToplevel()->getBaseWidget()),
  173.                         ViewGlue_getFrame(m_contextData),
  174.                         (Chrome*)NULL);
  175.     
  176.     }
  177. #endif
  178.   else
  179.     {
  180.       for (int i = 0; i < m_numsubviews; i ++)
  181.     {
  182.       if (m_subviews[i]->handlesCommand(cmd, calldata, info))
  183.         {
  184.           m_subviews[i]->doCommand(cmd, calldata, info);
  185.           return;
  186.         }
  187.     }
  188.  
  189.       XBell(XtDisplay(m_widget), 0);
  190.     }
  191. }
  192.  
  193. Boolean
  194. XFE_View::handlesCommand(CommandType cmd,
  195.                          void *calldata, XFE_CommandInfo* info)
  196. {
  197.   if (cmd == xfeCmdStopLoading)
  198.     {
  199.       return True;
  200.     }
  201.   else if (cmd == xfeCmdAboutMozilla
  202.            || cmd == xfeCmdSearchAddress
  203.            || cmd == xfeCmdOpenCustomUrl
  204.            )
  205.     {
  206.       return True;
  207.     }
  208.   else
  209.     {
  210.       for (int i = 0; i < m_numsubviews; i ++)
  211.     {
  212.       if (m_subviews[i]->handlesCommand(cmd, calldata, info))
  213.         return True;
  214.     }
  215.       
  216.       return False;
  217.     }
  218. }
  219.  
  220. char *
  221. XFE_View::commandToString(CommandType cmd,
  222.                           void *calldata, XFE_CommandInfo* info)
  223. {
  224.   for (int i = 0; i < m_numsubviews; i ++)
  225.     {
  226.       if (m_subviews[i]->handlesCommand(cmd, calldata, info))
  227.           return m_subviews[i]->commandToString(cmd, calldata, info);
  228.     }
  229.   
  230.   return NULL;
  231. }
  232.  
  233. Boolean
  234. XFE_View::isCommandSelected(CommandType cmd,
  235.                             void *calldata, XFE_CommandInfo* info)
  236. {
  237.   for (int i = 0; i < m_numsubviews; i ++)
  238.     {
  239.       if (m_subviews[i]->handlesCommand(cmd, calldata, info))
  240.         return m_subviews[i]->isCommandSelected(cmd, calldata, info);
  241.     }
  242.   return False;
  243. }
  244.  
  245. Pixel
  246. XFE_View::getFGPixel()
  247. {
  248.   return CONTEXT_DATA(m_contextData)->fg_pixel;
  249. }
  250.  
  251. Pixel
  252. XFE_View::getBGPixel()
  253. {
  254.   return CONTEXT_DATA(m_contextData)->default_bg_pixel;
  255. }
  256.  
  257. Pixel
  258. XFE_View::getTopShadowPixel()
  259. {
  260.   return CONTEXT_DATA(m_contextData)->top_shadow_pixel;
  261. }
  262.  
  263. Pixel
  264. XFE_View::getBottomShadowPixel()
  265. {
  266.   return CONTEXT_DATA(m_contextData)->bottom_shadow_pixel;
  267. }
  268.  
  269. void
  270. XFE_View::setScrollbarsActive(XP_Bool b)
  271. {
  272.   m_areScrollbarsActive = b;
  273.   if (m_contextData) {
  274.     CONTEXT_DATA(m_contextData)->are_scrollbars_active = b;
  275.   }
  276. }
  277.  
  278. XP_Bool
  279. XFE_View::getScrollbarsActive()
  280. {
  281.   return m_areScrollbarsActive;
  282. }
  283.  
  284. XFE_View*
  285. XFE_View::getCommandView(XFE_Command* command)
  286. {
  287.     int i;
  288.     CommandType cmd_id = command->getId();
  289.  
  290.     for (i = 0; i < m_numsubviews; i ++) {
  291.         if (m_subviews[i]->getCommand(cmd_id) == command)
  292.             return m_subviews[i];
  293.     }
  294.     
  295.     if (getCommand(cmd_id) == command)
  296.         return this;
  297.     else
  298.         return NULL;
  299. }
  300.