home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / ThreePaneView.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  6.6 KB  |  244 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.    ThreePaneView.cpp -- class definition for ThreePaneView
  20.    Created: Chris Toshok <toshok@netscape.com>, 7-Aug-96.
  21.  */
  22.  
  23.  
  24.  
  25. #include "ThreePaneView.h"
  26. #include "ThreadFrame.h"
  27. #include "prefs.h"
  28. #include "prefapi.h"
  29.  
  30. #include <Xfe/Pane.h>
  31.  
  32. const char* XFE_ThreePaneView::ShowFolder = "XFE_ThreePaneView::ShowFolder";
  33. #define THREEPANEVIEW_SHOW_PREF "mail.threadpane.3pane"
  34.  
  35. // Minimum and maximum sizes for the paned window panes:
  36. #define PANE_MIN 50
  37. #define PANE_MAX 6000
  38.  
  39.  
  40. XFE_ThreePaneView::XFE_ThreePaneView(XFE_Component *toplevel_component,
  41.                        Widget parent, XFE_View *parent_view,
  42.                        MWContext *context)
  43.   : XFE_View(toplevel_component, parent_view, context)
  44. {
  45.   Widget    hpane;
  46.  
  47.   hpane = XtVaCreateWidget("hpane",
  48.                            xfePaneWidgetClass,
  49.                            parent,
  50.                            XmNorientation,            XmHORIZONTAL,
  51.                            XmNsashPosition,            200,
  52.                            XmNsashThickness,        10,
  53.                            XmNsashShadowThickness,    1,
  54.                            XmNpaneSashType,            XmPANE_SASH_LIVE,
  55.                            NULL);
  56.  
  57.   m_focusview = NULL;
  58.   m_folderview = new XFE_FolderView(toplevel_component, hpane, this,
  59.                     context);
  60.   m_threadview = new XFE_ThreadView(toplevel_component, hpane, this,
  61.                     context);
  62.  
  63.   // add our subviews to the list of subviews for command dispatching and
  64.   // deletion.
  65.   addView(m_folderview);
  66.   addView(m_threadview);
  67.  
  68.   m_folderview->registerInterest(XFE_FolderView::folderSelected,
  69.                  this,
  70.                  (XFE_FunctionNotification)userClickedFolder_cb);
  71.   getToplevel()->registerInterest(XFE_MNBanner::twoPaneView,
  72.                 this,
  73.                 (XFE_FunctionNotification)twoPaneView_cb);
  74.  
  75.   getToplevel()->registerInterest(XFE_MNListView::changeFocus,
  76.                 this,
  77.                 (XFE_FunctionNotification)changeFocus_cb);
  78.   XP_Bool show_folder;
  79.   PREF_GetBoolPref(THREEPANEVIEW_SHOW_PREF, &show_folder);
  80.  
  81.  
  82.   if (show_folder)
  83.   {
  84.       m_folderview->show();
  85.   }
  86.  
  87.   m_threadview->show();
  88.  
  89.   
  90.   /* when show 3 pane, the folder view is the focus by default */
  91.   if ( show_folder )
  92.   {
  93.     m_threadview->setInFocus(False);
  94.     m_folderview->setInFocus(True); 
  95.  
  96.     /* need to remember to set m_focusview to remember which view 
  97.     ** is in-focus.
  98.     */
  99.     m_focusview= m_folderview; 
  100.   }
  101.   else
  102.   {
  103.     /* when show 2 pane, the thread view is the focus by default */
  104.     m_threadview->setInFocus(True);
  105.     m_folderview->setInFocus(False); 
  106.     m_focusview= m_threadview; 
  107.   }
  108.  
  109.  
  110.   setBaseWidget(hpane);
  111. }
  112.  
  113. XFE_ThreePaneView::~XFE_ThreePaneView()
  114. {
  115.  
  116.     /* unregister all interests */
  117.     m_folderview->unregisterInterest(XFE_FolderView::folderSelected,
  118.                                  this,
  119.                                  (XFE_FunctionNotification)userClickedFolder_cb);
  120.     getToplevel()->unregisterInterest(XFE_MNBanner::twoPaneView,
  121.                                 this,
  122.                                 (XFE_FunctionNotification)twoPaneView_cb);
  123.  
  124.     if ( m_folderview->isShown() )
  125.      {
  126.       PREF_SetBoolPref(THREEPANEVIEW_SHOW_PREF, (XP_Bool)True);
  127.      }
  128.     else
  129.      {
  130.       PREF_SetBoolPref(THREEPANEVIEW_SHOW_PREF, (XP_Bool)False);
  131.      }
  132.  
  133.     /* XFE_View destroy m_folderview and m_threadview for us */
  134. }
  135.  
  136. void
  137. XFE_ThreePaneView::selectFolder(MSG_FolderInfo *info)
  138. {
  139.   m_folderview->selectFolder(info);
  140. }
  141.  
  142. XFE_View*
  143. XFE_ThreePaneView::getThreadView()
  144. {
  145.     return m_threadview;
  146. }
  147.  
  148. XFE_View*
  149. XFE_ThreePaneView::getFolderView()
  150. {
  151.     return m_folderview;
  152. }
  153.  
  154. XFE_CALLBACK_DEFN(XFE_ThreePaneView,userClickedFolder)(XFE_NotificationCenter *,
  155.                                  void *, void* calldata)
  156. {
  157.   MSG_FolderInfo *info = (MSG_FolderInfo*)calldata;
  158.  
  159.   ((XFE_ThreadFrame*)getToplevel())->loadFolder(info);
  160. }
  161.  
  162. XFE_CALLBACK_DEFN(XFE_ThreePaneView,twoPaneView)(XFE_NotificationCenter *,
  163.                                  void *, void*)
  164. {
  165.     if ( m_folderview->isShown() )
  166.     {
  167.         m_folderview->hide();
  168.         if (m_focusview == m_folderview) 
  169.         {
  170.             m_folderview->setInFocus(False);
  171.         m_focusview = m_threadview;
  172.         }
  173.         m_focusview->setInFocus(True);
  174.     }
  175.     else m_folderview->show();
  176. }
  177.  
  178. XFE_CALLBACK_DEFN(XFE_ThreePaneView,changeFocus)(XFE_NotificationCenter *,
  179.                                  void *, void* calldata)
  180. {
  181.     XFE_MNListView *infocus_view = (XFE_MNListView*)calldata;
  182.     
  183.     XP_ASSERT( calldata != NULL);
  184.  
  185.     if (m_focusview != infocus_view)
  186.     {
  187.         if (m_focusview )
  188.         m_focusview->setInFocus(False);
  189.         infocus_view->setInFocus(True);
  190.         m_focusview=infocus_view;
  191.         getToplevel()->notifyInterested(XFE_View::chromeNeedsUpdating);
  192.     }
  193. }
  194.  
  195. Boolean
  196. XFE_ThreePaneView::isCommandEnabled(CommandType cmd, void *calldata, XFE_CommandInfo* info)
  197. {
  198.  
  199.   XP_ASSERT( m_focusview != NULL);
  200.  
  201.   return m_focusview->isCommandEnabled(cmd,calldata,info);
  202. }
  203.  
  204. void
  205. XFE_ThreePaneView::doCommand(CommandType cmd, void *calldata, XFE_CommandInfo* info)
  206. {
  207. #define IS_CMD(command) cmd == (command)
  208.   XP_ASSERT( m_focusview != NULL);
  209.  
  210.   if (IS_CMD(xfeCmdMommy) && m_focusview != m_threadview && m_threadview)
  211.   {
  212.     m_threadview->doCommand(cmd,calldata,info);
  213.   }
  214.   else
  215.        m_focusview->doCommand(cmd,calldata,info);
  216. }
  217.  
  218. Boolean
  219. XFE_ThreePaneView::handlesCommand(CommandType cmd, void *calldata, XFE_CommandInfo* info)
  220. {
  221. #define IS_CMD(command) cmd == (command)
  222.   XP_ASSERT( m_focusview != NULL);
  223.   if (IS_CMD(xfeCmdMommy) && m_focusview != m_threadview && m_threadview)
  224.   {
  225.     return m_threadview->handlesCommand(cmd,calldata,info);
  226.   }
  227.  
  228.   return m_focusview->handlesCommand(cmd,calldata,info);
  229. }
  230.  
  231. Boolean
  232. XFE_ThreePaneView::isCommandSelected(CommandType cmd, void *calldata, XFE_CommandInfo* info)
  233. {
  234.    XP_ASSERT( m_focusview != NULL);
  235.    return m_focusview->isCommandSelected(cmd,calldata,info);
  236. }
  237.  
  238. char*
  239. XFE_ThreePaneView::commandToString(CommandType cmd, void *calldata, XFE_CommandInfo* info)
  240. {
  241.    XP_ASSERT( m_focusview != NULL);
  242.    return m_focusview->commandToString(cmd,calldata,info);
  243. }
  244.