home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / Dashboard.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  35.9 KB  |  1,355 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.    Dashboard.cpp -- The chrome along the bottom of a frame.
  20.    Created: Chris Toshok <toshok@netscape.com>, 11-Oct-1996
  21.  */
  22.  
  23.  
  24.  
  25. #include "Dashboard.h"
  26. #include "Button.h"
  27. #include "View.h"
  28. #include "DisplayFactory.h"
  29. #include "MozillaApp.h"
  30. #include "prefapi.h"
  31. #include "PopupMenu.h"
  32. #include "BookmarkFrame.h"
  33.  
  34. #ifdef MOZ_TASKBAR
  35. #include "TaskBar.h"
  36. #endif
  37.  
  38. #include <Xm/Form.h>
  39. #include <Xm/MwmUtil.h>
  40.  
  41. #include <Xfe/XfeAll.h>
  42.  
  43. #if 0
  44. #define D(x) x
  45. #else
  46. #define D(x)
  47. #endif
  48.  
  49. // Widget names
  50. #define DASH_BOARD_NAME                "dashBoard"
  51. #define ICON_TOOL_BAR_NAME            "securityBar"
  52. #define PROGRESS_BAR_NAME            "progressBar"
  53. #define STATUS_BAR_NAME                "statusBar"
  54.  
  55. #define MIN_DASH_HEIGHT                    22
  56.  
  57. #ifdef MOZ_TASKBAR
  58.  
  59. #define FLOATING_SHELL_NAME                "mozillaComponentBar"
  60. #define FLOATING_ORIGIN_OFFSET            50
  61. #define MAX_FLOATING_RAISES_PER_SECOND    4
  62.  
  63. /* static */ MenuSpec 
  64. XFE_Dashboard::m_floatingPopupMenuSpec[] = 
  65. {
  66.     { xfeCmdFloatingTaskBarAlwaysOnTop,    TOGGLEBUTTON },
  67.     { xfeCmdFloatingTaskBarHorizontal,    PUSHBUTTON },
  68.     { xfeCmdFloatingTaskBarClose,        PUSHBUTTON },
  69.     { NULL }
  70. };
  71.  
  72. //
  73. // Task Bar members
  74. //
  75.  
  76. /* static */ XFE_PopupMenu *
  77. XFE_Dashboard::m_floatingPopup = NULL;
  78.  
  79. /* static */ XFE_TaskBar *
  80. XFE_Dashboard::m_floatingTaskBar = NULL;
  81.  
  82. /* static */ Widget
  83. XFE_Dashboard::m_floatingShell = NULL;
  84.  
  85. /* static */ XP_Bool
  86. XFE_Dashboard::m_floatingDocked = False;
  87.  
  88. /* static */ time_t
  89. XFE_Dashboard::m_floatingLastRaisedTime = 0;
  90.  
  91. /* static */ int
  92. XFE_Dashboard::m_floatingTimesRaisedPerSecond = 0;
  93.  
  94. // Needed to determine the colormap used by the floating shell colormap
  95. extern "C" Colormap fe_getColormap(fe_colormap *colormap);
  96.  
  97. //////////////////////////////////////////////////////////////////////////
  98. //
  99. // XFE_Dashboard notification callbacks names
  100. //
  101. //////////////////////////////////////////////////////////////////////////
  102.  
  103. /* static */ const char * 
  104. XFE_Dashboard::taskBarDockedCallback = "XFE_Dashboard::taskBarDockedCallback";
  105.  
  106. /* static */ const char * 
  107. XFE_Dashboard::taskBarUndockedCallback = "XFE_Dashboard::taskBarUndockedCallback";
  108.  
  109. #endif
  110.  
  111. // Needed to truncate strings 
  112. extern "C" XmString fe_StringChopCreate(char* message, char* tag,
  113.                                         XmFontList font_list,int maxwidth);
  114.  
  115.  
  116. //////////////////////////////////////////////////////////////////////////
  117. XFE_Dashboard::XFE_Dashboard(XFE_Component *    toplevel_component,
  118.                              Widget                parent,
  119.                              XFE_Frame *        frame,
  120.                              XP_Bool            have_task_bar)
  121.     : XFE_Component(toplevel_component)
  122. {
  123.     m_parentFrame   = frame;
  124.     m_statusBar     = NULL;
  125.     m_progressBar    = NULL;
  126.     m_securityIcon    = NULL;
  127.     m_signedIcon    = NULL;
  128.     m_securityBar    = NULL;
  129.  
  130. #ifdef MOZ_TASKBAR
  131.     m_dockedTaskBar    = NULL;
  132. #endif
  133.  
  134. #ifndef MOZ_TASKBAR
  135.     have_task_bar = False;
  136. #endif
  137.  
  138.     m_securityRegistered    = False;
  139.  
  140.     m_widget = XtVaCreateWidget(DASH_BOARD_NAME,
  141.                                 xfeDashBoardWidgetClass,
  142.                                 parent,
  143.                                 XmNusePreferredWidth,    False,
  144.                                 XmNusePreferredHeight,    True,
  145.                                 XmNshowDockedTaskBar,    have_task_bar,
  146.                                 XmNminHeight,            MIN_DASH_HEIGHT,
  147.                                 NULL);
  148.  
  149. #ifdef MOZ_TASKBAR
  150.     // Add floating shell map/unmap callbacks to dashboard
  151.     XtAddCallback(m_widget,
  152.                   XmNfloatingMapCallback,
  153.                   XFE_Dashboard::floatingMappingCB,
  154.                   (XtPointer) this);
  155.  
  156.     XtAddCallback(m_widget,
  157.                   XmNfloatingUnmapCallback,
  158.                   XFE_Dashboard::floatingMappingCB,
  159.                   (XtPointer) this);
  160. #endif
  161.  
  162. #ifdef MOZ_TASKBAR
  163.     // Start the floating shell only if a parent frame is given
  164.     if (m_parentFrame)
  165.     {
  166.         // The task bar parent frame will always be the bookmark frame since
  167.         // it is the only frame that sticks around for the duration of the 
  168.         // application.
  169.         XFE_Frame * taskBarParentFrame = NULL;
  170.  
  171.         // If our parent frame is the bookmark frame, use that.
  172.         if (m_parentFrame->getType() == FRAME_BOOKMARK)
  173.         {
  174.             taskBarParentFrame = m_parentFrame;
  175.         }
  176.         // Otherwise get the bookmark frame
  177.         else
  178.         {
  179.             taskBarParentFrame = XFE_BookmarkFrame::getBookmarkFrame();
  180.         }
  181.  
  182.         // Make sure the floating task bar is started
  183.         XFE_Dashboard::startFloatingTaskBar(taskBarParentFrame);
  184.     }
  185.  
  186.     // Create the docked task bar if needed
  187.     if (have_task_bar)
  188.     {
  189.         createDockedTaskBar();
  190.     }
  191. #endif
  192.   
  193.     installDestroyHandler();
  194. }
  195. //////////////////////////////////////////////////////////////////////////
  196. XFE_Dashboard::~XFE_Dashboard()
  197. {
  198.     D( printf ("In XFE_Dashboard::~XFE_Dashboard\n");)
  199.     
  200.     // Unregister status notifications with top level component
  201.     if (m_statusBar)
  202.     {
  203.         m_toplevel->unregisterInterest(
  204.             Command::commandArmedCallback,
  205.             this,
  206.             (XFE_FunctionNotification)showCommandStringNotice_cb);
  207.         
  208.         m_toplevel->unregisterInterest(
  209.             Command::commandDisarmedCallback,
  210.             this,
  211.             (XFE_FunctionNotification)eraseCommandStringNotice_cb);
  212.         
  213.         m_toplevel->unregisterInterest(
  214.             XFE_View::statusNeedsUpdatingMidTruncated,
  215.             this,
  216.             (XFE_FunctionNotification)setStatusTextNotice_cb);
  217.         
  218.         m_toplevel->unregisterInterest(
  219.             XFE_View::statusNeedsUpdating,
  220.             this,
  221.             (XFE_FunctionNotification)setStatusTextNotice_cb);
  222.     }
  223.  
  224.     // Unregister progress notifications with parent
  225.     if (m_parentFrame && m_progressBar)
  226.     {
  227.         m_parentFrame->unregisterInterest(
  228.             XFE_Frame::progressBarCylonStart,
  229.             this,
  230.             startCylonNotice_cb);
  231.         
  232.         m_parentFrame->unregisterInterest(
  233.             XFE_Frame::progressBarCylonStop,
  234.             this,
  235.             stopCylonNotice_cb);
  236.         
  237.         m_parentFrame->unregisterInterest(
  238.             XFE_Frame::progressBarCylonTick,
  239.             this,
  240.             tickCylonNotice_cb);
  241.         
  242.         m_parentFrame->unregisterInterest(
  243.             XFE_Frame::progressBarUpdatePercent,
  244.             this,
  245.             progressBarUpdatePercentNotice_cb);
  246.  
  247.         m_parentFrame->unregisterInterest(
  248.             XFE_Frame::progressBarUpdateText,
  249.             this,
  250.             progressBarUpdateTextNotice_cb);
  251.     }
  252.  
  253.     // Unregister parent frame update chrome notifications if needed
  254.     if (m_parentFrame && m_securityRegistered)
  255.     {
  256.         m_parentFrame->unregisterInterest(
  257.             XFE_View::chromeNeedsUpdating,
  258.             this,
  259.             (XFE_FunctionNotification)update_cb);
  260.     }
  261.  
  262.     D(    printf ("Leaving XFE_Dashboard::~XFE_Dashboard\n");)
  263. }
  264. //////////////////////////////////////////////////////////////////////////
  265. void
  266. XFE_Dashboard::createStatusBar()
  267. {
  268.     XP_ASSERT( XfeIsAlive(m_widget) );
  269.  
  270.     m_statusBar = 
  271.         XtVaCreateWidget(STATUS_BAR_NAME,
  272.                          xfeLabelWidgetClass,
  273.                          m_widget,
  274.  
  275.                          XmNusePreferredHeight,    True,
  276.                          XmNusePreferredWidth,    False,
  277.  
  278.                          XmNtruncateProc,        fe_StringChopCreate,
  279.  
  280.                          XmNtraversalOn,        True,
  281.                          XmNhighlightThickness,    0,
  282.                          NULL);
  283.  
  284.     // Clear the status bar to begin with
  285.     setStatusText("");
  286.  
  287.     // Register status notifications with top level component
  288.     m_toplevel->registerInterest(
  289.         Command::commandArmedCallback,
  290.         this,
  291.         (XFE_FunctionNotification)showCommandStringNotice_cb);
  292.     
  293.     m_toplevel->registerInterest(
  294.         Command::commandDisarmedCallback,
  295.         this,
  296.         (XFE_FunctionNotification)eraseCommandStringNotice_cb);
  297.     
  298.     m_toplevel->registerInterest(
  299.         XFE_View::statusNeedsUpdatingMidTruncated,
  300.         this,
  301.         (XFE_FunctionNotification)setStatusTextNotice_cb);
  302.     
  303.     m_toplevel->registerInterest(
  304.         XFE_View::statusNeedsUpdating,
  305.         this,
  306.         (XFE_FunctionNotification)setStatusTextNotice_cb);
  307. }
  308. //////////////////////////////////////////////////////////////////////////
  309. void
  310. XFE_Dashboard::createProgressBar()
  311. {
  312.     XP_ASSERT( XfeIsAlive(m_widget) );
  313.     XP_ASSERT( m_progressBar == NULL );
  314.  
  315.     m_progressBar = 
  316.         XtVaCreateManagedWidget(PROGRESS_BAR_NAME,
  317.                                 xfeProgressBarWidgetClass,
  318.                                 m_widget,
  319.  
  320.                                 XmNusePreferredHeight,        True,
  321.                                 XmNusePreferredWidth,        False,
  322.  
  323.                                 XmNtraversalOn,                True,
  324.                                 XmNhighlightThickness,        0,
  325.                                 NULL);
  326.  
  327.     // Clear the progress bar to begin with
  328.     setProgressBarText("");
  329.     setProgressBarPercent(0);
  330.  
  331.     // Register progress notifications with parent
  332.     if (m_parentFrame)
  333.     {
  334.         m_parentFrame->registerInterest(
  335.             XFE_Frame::progressBarCylonStart,
  336.             this,
  337.             startCylonNotice_cb);
  338.         
  339.         m_parentFrame->registerInterest(
  340.             XFE_Frame::progressBarCylonStop,
  341.             this,
  342.             stopCylonNotice_cb);
  343.         
  344.         m_parentFrame->registerInterest(
  345.             XFE_Frame::progressBarCylonTick,
  346.             this,
  347.             tickCylonNotice_cb);
  348.         
  349.         m_parentFrame->registerInterest(
  350.             XFE_Frame::progressBarUpdatePercent,
  351.             this,
  352.             progressBarUpdatePercentNotice_cb);
  353.  
  354.         m_parentFrame->registerInterest(
  355.             XFE_Frame::progressBarUpdateText,
  356.             this,
  357.             progressBarUpdateTextNotice_cb);
  358.     }
  359. }
  360. //////////////////////////////////////////////////////////////////////////
  361. #ifdef MOZ_TASKBAR
  362. void
  363. XFE_Dashboard::createDockedTaskBar()
  364. {
  365.     XP_ASSERT( XfeIsAlive(m_widget) );
  366.     XP_ASSERT( XFE_Dashboard::floatingTaskBarIsAlive() );
  367.     XP_ASSERT( m_parentFrame != NULL );
  368.     
  369.     // Create the docked taskbar here
  370.     m_dockedTaskBar = new XFE_TaskBar(m_widget,m_parentFrame,False);
  371.     
  372.     // Add action cb to dashboard
  373.     XtAddCallback(m_dockedTaskBar->getBaseWidget(),
  374.                   XmNactionCallback,
  375.                   XFE_Dashboard::floatingActionCB,
  376.                   (XtPointer) this);
  377.     
  378.     // Install the global floating task bar on the dash board
  379.     XtVaSetValues(m_widget,XmNfloatingShell,m_floatingShell,NULL);
  380. }
  381. #endif
  382. //////////////////////////////////////////////////////////////////////////
  383. void
  384. XFE_Dashboard::createSecurityBar()
  385. {
  386.     XP_ASSERT( m_parentFrame != NULL );
  387.     XP_ASSERT( XfeIsAlive(m_widget) );
  388.     XP_ASSERT( m_securityBar == NULL );
  389.  
  390.     if (!m_parentFrame)
  391.         return;
  392.  
  393.     // Create the icon toolbar
  394.     m_securityBar = XtVaCreateWidget(ICON_TOOL_BAR_NAME,
  395.                                      xfeToolBarWidgetClass,
  396.                                      m_widget,
  397.                                      NULL);
  398. }
  399. //////////////////////////////////////////////////////////////////////////
  400. void
  401. XFE_Dashboard::addSecurityIcon()
  402. {
  403.     XP_ASSERT( m_parentFrame != NULL );
  404.     XP_ASSERT( XfeIsAlive(m_widget) );
  405.     XP_ASSERT( XfeIsAlive(m_securityBar) );
  406.     XP_ASSERT( m_securityIcon == NULL );
  407.  
  408.     if (!m_parentFrame)
  409.         return;
  410.  
  411.     m_securityIcon = new XFE_Button(m_parentFrame,
  412.                                     m_securityBar,
  413.                                     xfeCmdViewSecurity,
  414.                                     &Dash_Unsecure_group,
  415.                                     &Dash_Secure_group,
  416.                                     &Dash_Unsecure_group,
  417.                                     &Dash_Secure_group);
  418.  
  419.     // Show or hide the new security icon based on its isEnabled state.
  420.     m_securityIcon->show();
  421.  
  422.     // Configure the icon
  423.     m_securityIcon->setToplevel(m_parentFrame);
  424.  
  425.     XtVaSetValues(m_securityIcon->getBaseWidget(),
  426.                   XmNtraversalOn,            True,
  427.                   XmNhighlightThickness,    0,
  428.                   NULL);
  429.  
  430.     // Add chrome update notice to parent frame if needed
  431.     if (m_parentFrame && !m_securityRegistered)
  432.     {
  433.         m_securityRegistered = True;
  434.         
  435.         m_parentFrame->registerInterest(XFE_View::chromeNeedsUpdating,
  436.                                         this,
  437.                                         (XFE_FunctionNotification)update_cb);
  438.     }
  439.  
  440.     // Add button command notice
  441.     m_securityIcon->registerInterest(
  442.         XFE_Button::doCommandCallback,
  443.         this,
  444.         (XFE_FunctionNotification)doSecurityCommand_cb);
  445. }
  446. //////////////////////////////////////////////////////////////////////////
  447. void
  448. XFE_Dashboard::addSignedIcon()
  449. {
  450.     XP_ASSERT( m_parentFrame != NULL );
  451.     XP_ASSERT( XfeIsAlive(m_widget) );
  452.     XP_ASSERT( XfeIsAlive(m_securityBar) );
  453.     XP_ASSERT( m_signedIcon == NULL );
  454.  
  455.     if (!m_parentFrame)
  456.         return;
  457.  
  458.     m_signedIcon = new XFE_Button(m_parentFrame,
  459.                                   m_securityBar,
  460.                                   xfeCmdViewSecurity,
  461.                                   &Dash_Unsigned_group,
  462.                                   &Dash_Unsigned_group,
  463.                                   &Dash_Signed_group,
  464.                                   &Dash_Signed_group);
  465.  
  466.     // Show or hide the new signed icon based on its isEnabled state.
  467.     m_signedIcon->show();
  468.  
  469.     // Configure the icon
  470.     m_signedIcon->setToplevel(m_parentFrame);
  471.  
  472.     XtVaSetValues(m_signedIcon->getBaseWidget(),
  473.                   XmNtraversalOn,            True,
  474.                   XmNhighlightThickness,    0,
  475.                   NULL);
  476.  
  477.     // Add chrome update notice to parent frame if needed
  478.     if (m_parentFrame && !m_securityRegistered)
  479.     {
  480.         m_securityRegistered = True;
  481.         
  482.         m_parentFrame->registerInterest(XFE_View::chromeNeedsUpdating,
  483.                                         this,
  484.                                         (XFE_FunctionNotification)update_cb);
  485.     }
  486.  
  487.     // Add button command notice
  488.     m_signedIcon->registerInterest(
  489.         XFE_Button::doCommandCallback,
  490.         this,
  491.         (XFE_FunctionNotification)doSecurityCommand_cb);
  492. }
  493. //////////////////////////////////////////////////////////////////////////
  494. void
  495. XFE_Dashboard::configureSecurityBar()
  496. {
  497.     // Make sure the is a security bar to configure
  498.     if (XfeIsAlive(m_securityBar))
  499.     {
  500.         XfeSetManagedState(m_securityBar,
  501.                            isSecurityIconShown() || isSignedIconShown());
  502.     }
  503. }
  504. //////////////////////////////////////////////////////////////////////////
  505. void
  506. XFE_Dashboard::setStatusText(const char * text)
  507. {
  508.     D(
  509.         Widget top = m_toplevel->getBaseWidget();
  510.         printf("%s: setStatusText: %s\n", XtName(top), text);
  511.     )
  512.  
  513.     XP_ASSERT( XfeIsAlive(m_statusBar) );
  514.     XfeLabelSetStringPSZ(m_statusBar,(String) text);
  515. }
  516. //////////////////////////////////////////////////////////////////////////
  517. void
  518. XFE_Dashboard::setProgressBarText(const char * text)
  519. {
  520.     XP_ASSERT( XfeIsAlive(m_progressBar) );
  521.  
  522.     XfeLabelSetStringPSZ(m_progressBar,(String) text);
  523. }
  524. //////////////////////////////////////////////////////////////////////////
  525. void
  526. XFE_Dashboard::setProgressBarPercent(int percent)
  527. {
  528.     XP_ASSERT( XfeIsAlive(m_progressBar) );
  529.  
  530.     if (percent < 0)
  531.     {
  532.         percent = 0;
  533.     }
  534.  
  535.     if (percent > 100)
  536.     {
  537.         percent = 100;
  538.     }
  539.     XfeProgressBarSetPercentages(m_progressBar,0,percent);
  540. }
  541. //////////////////////////////////////////////////////////////////////////
  542. void
  543. XFE_Dashboard::startCylon()
  544. {
  545.     XP_ASSERT( XfeIsAlive(m_progressBar) );
  546.  
  547.     XfeProgressBarCylonStart(m_progressBar);
  548. }
  549. //////////////////////////////////////////////////////////////////////////
  550. void
  551. XFE_Dashboard::stopCylon()
  552. {
  553.     XP_ASSERT( XfeIsAlive(m_progressBar) );
  554.  
  555.     XfeProgressBarCylonStop(m_progressBar);
  556. }
  557. //////////////////////////////////////////////////////////////////////////
  558. void
  559. XFE_Dashboard::tickCylon()
  560. {
  561.     XP_ASSERT( XfeIsAlive(m_progressBar) );
  562.  
  563.     XfeProgressBarCylonTick(m_progressBar);
  564. }
  565. //////////////////////////////////////////////////////////////////////////
  566. #ifdef MOZ_TASKBAR
  567. /* static */ void
  568. XFE_Dashboard::dockTaskBar()
  569. {
  570.     if (!XFE_Dashboard::isTaskBarDocked() && 
  571.         XFE_Dashboard::floatingTaskBarIsAlive())
  572.     {
  573.         XtUnmanageChild(XFE_Dashboard::m_floatingTaskBar->getBaseWidget());
  574.     }
  575. }
  576. //////////////////////////////////////////////////////////////////////////
  577. /* static */ void
  578. XFE_Dashboard::unDockTaskBar()
  579. {
  580.     if (XFE_Dashboard::isTaskBarDocked() && 
  581.         XFE_Dashboard::floatingTaskBarIsAlive())
  582.     {
  583.         if (m_floatingTaskBar->numEnabledButtons())
  584.         {
  585.             XtManageChild(XFE_Dashboard::m_floatingTaskBar->getBaseWidget());
  586.         }
  587.     }
  588. }
  589. //////////////////////////////////////////////////////////////////////////
  590. /* static */ void
  591. XFE_Dashboard::toggleTaskBar()
  592. {
  593.     if (XFE_Dashboard::isTaskBarDocked())
  594.     {
  595.         XFE_Dashboard::unDockTaskBar();
  596.     }
  597.     else
  598.     {
  599.         XFE_Dashboard::dockTaskBar();
  600.     }
  601. }
  602. //////////////////////////////////////////////////////////////////////////
  603. /* static */ XP_Bool
  604. XFE_Dashboard::isTaskBarDocked()
  605. {
  606.     return (XFE_Dashboard::floatingTaskBarIsAlive() &&
  607.             !XtIsManaged(XFE_Dashboard::m_floatingTaskBar->getBaseWidget()));
  608. }
  609. //////////////////////////////////////////////////////////////////////////
  610. /* static */ XP_Bool
  611. XFE_Dashboard::floatingTaskBarIsAlive()
  612. {
  613.     return (XfeIsAlive(XFE_Dashboard::m_floatingShell) && 
  614.             XfeIsAlive(XFE_Dashboard::m_floatingTaskBar->getBaseWidget()));
  615. }
  616. //////////////////////////////////////////////////////////////////////////
  617. /* static */ void
  618. XFE_Dashboard::startFloatingTaskBar(XFE_Frame * parentFrame)
  619. {
  620.     // Make sure the floating task bar has not been started yet
  621.     if (XFE_Dashboard::floatingTaskBarIsAlive())
  622.     {
  623.         return;
  624.     }
  625.  
  626.     XP_ASSERT( parentFrame != NULL );
  627.  
  628.     Widget            app_shell;
  629.     int                decor;
  630.     int                funcs;
  631.     fe_colormap *    floating_fe_colormap;
  632.     Colormap        floating_colormap;
  633.     Visual *        floating_visual;
  634.     int                floating_depth;
  635.  
  636.     // Access the application shell (confusingly known as top_level)
  637.     app_shell = FE_GetToplevelWidget();
  638.     
  639.     // Make sure the display factory is running
  640.     fe_startDisplayFactory(app_shell);
  641.     
  642.     // Obtain the colormap / depth / and visual to use for the
  643.     // floating shell.  These cannot be gotten from the parent
  644.     // frame, since it might go away.
  645.     floating_fe_colormap = 
  646.         XFE_DisplayFactory::theFactory()->getSharedColormap();
  647.  
  648.     floating_colormap = fe_getColormap(floating_fe_colormap);
  649.     
  650.     floating_depth = 
  651.         XFE_DisplayFactory::theFactory()->getVisualDepth();
  652.     
  653.     floating_visual = 
  654.         XFE_DisplayFactory::theFactory()->getVisual();
  655.  
  656.     // Set the window manager decorations and functions
  657.     decor = MWM_DECOR_BORDER | MWM_DECOR_TITLE | MWM_DECOR_MENU;
  658.     funcs = MWM_FUNC_CLOSE | MWM_FUNC_MOVE;
  659.  
  660.     // Create the floating shell
  661.     XFE_Dashboard::m_floatingShell = 
  662.         XtVaCreatePopupShell(FLOATING_SHELL_NAME,
  663.                              xmDialogShellWidgetClass,
  664.                              app_shell,
  665.                              XmNvisual,                floating_visual,
  666.                              XmNdepth,                floating_depth,
  667.                              XmNcolormap,            floating_colormap,
  668.                              XmNallowShellResize,    True,
  669.                              XmNmwmDecorations,        decor,
  670.                              XmNmwmFunctions,        funcs,
  671.                              XmNdeleteResponse,        XmDO_NOTHING,
  672.                              NULL);
  673.  
  674.     // Create the floating task bar
  675.     XFE_Dashboard::m_floatingTaskBar = new XFE_TaskBar(m_floatingShell,
  676.                                                        parentFrame,True);
  677.  
  678.     // Create the floating taskbar popup menu
  679.     XFE_Dashboard::m_floatingPopup = new XFE_PopupMenu("taskBarContextMenu",
  680.                                                        parentFrame,
  681.                                                        FE_GetToplevelWidget());
  682.  
  683.     XFE_Dashboard::m_floatingPopup->setMenuSpec(XFE_Dashboard::m_floatingPopupMenuSpec);
  684.  
  685.     // Add popup menu post event handler to floating task bar items
  686.     XfeChildrenAddEventHandler(
  687.         XFE_Dashboard::m_floatingTaskBar->getBaseWidget(),
  688.         ButtonPressMask,
  689.         True,
  690.         &XFE_Dashboard::floatingButtonEH,
  691.         NULL);
  692.  
  693.     // Add floating shell configure event handler
  694.     XtAddEventHandler(XFE_Dashboard::m_floatingShell,
  695.                       StructureNotifyMask | VisibilityChangeMask,
  696.                       True,
  697.                       &XFE_Dashboard::floatingConfigureEH,
  698.                       NULL);
  699.  
  700.     // Look for the defaults, in which case we use a decent default
  701.     // Why are the defaults (-1,-1) ???
  702.     if (fe_globalPrefs.task_bar_x == -1)
  703.     {
  704.         fe_globalPrefs.task_bar_x = FLOATING_ORIGIN_OFFSET;
  705.     }
  706.  
  707.     if (fe_globalPrefs.task_bar_y == -1)
  708.     {
  709.         fe_globalPrefs.task_bar_y = FLOATING_ORIGIN_OFFSET;
  710.     }
  711.  
  712.     XFE_Dashboard::setFloatingTaskBarPosition(fe_globalPrefs.task_bar_x,
  713.                                               fe_globalPrefs.task_bar_y);
  714.  
  715.     XFE_Dashboard::setFloatingTaskBarHorizontal(fe_globalPrefs.task_bar_horizontal);
  716.     XFE_Dashboard::setFloatingTaskBarOnTop(fe_globalPrefs.task_bar_ontop);
  717.  
  718.     // Set the title for the floating dialog
  719.     XFE_Dashboard::m_floatingTaskBar->setFloatingTitle(" ");
  720.  
  721.     // Set the initial state of the taskbar
  722.     XFE_Dashboard::m_floatingDocked = True;
  723.  
  724.     // Undock the taskbar if needed
  725.     if (fe_globalPrefs.task_bar_floating)
  726.     {
  727.         unDockTaskBar();
  728.     }
  729. }
  730. //////////////////////////////////////////////////////////////////////////
  731. /* static */ void
  732. XFE_Dashboard::stopFloatingTaskBar()
  733. {
  734.     // Return right away if the task bar is docked
  735.     if (XFE_Dashboard::isTaskBarDocked())
  736.     {
  737.         return;
  738.     }
  739.  
  740.     // Make sure the floating task bar is still alive
  741.     if (!XFE_Dashboard::floatingTaskBarIsAlive())
  742.     {
  743.         return;
  744.     }
  745.  
  746.     // Simpy unmap the taskbar shell.  The widgets (and objects) will be
  747.     // destroyed later.
  748.     XUnmapWindow(XtDisplay(XFE_Dashboard::m_floatingShell),
  749.                  XtWindow(XFE_Dashboard::m_floatingShell));
  750. }
  751. //////////////////////////////////////////////////////////////////////////
  752. /* static */ void
  753. XFE_Dashboard::setFloatingTaskBarPosition(int32 x,int32 y)
  754. {
  755.     XP_ASSERT( XFE_Dashboard::floatingTaskBarIsAlive() );
  756.  
  757. //    printf("setFloatingTaskBarPosition(%d,%d)\n",x,y);
  758.  
  759.     // Update the prefs
  760.     fe_globalPrefs.task_bar_x = x;
  761.     fe_globalPrefs.task_bar_y = y;
  762.  
  763.     // Update the floating shell's position
  764.     XtVaSetValues(XFE_Dashboard::m_floatingShell,
  765.                   XmNx,x,
  766.                   XmNy,y,
  767.                   NULL);
  768. }
  769. //////////////////////////////////////////////////////////////////////////
  770. /* static */ void
  771. XFE_Dashboard::setFloatingTaskBarHorizontal(XP_Bool horizontal)
  772. {
  773.     XP_ASSERT( XFE_Dashboard::floatingTaskBarIsAlive() );
  774.  
  775.     // Update the prefs
  776.     fe_globalPrefs.task_bar_horizontal = horizontal;
  777.  
  778.     // Update the floating task bar's orientation
  779.     XtVaSetValues(m_floatingTaskBar->getBaseWidget(),
  780.                   XmNorientation,horizontal ? XmHORIZONTAL : XmVERTICAL,
  781.                   NULL);
  782. }
  783. //////////////////////////////////////////////////////////////////////////
  784. /* static */ void
  785. XFE_Dashboard::setFloatingTaskBarOnTop(XP_Bool ontop)
  786. {
  787.     XP_ASSERT( XFE_Dashboard::floatingTaskBarIsAlive() );
  788.  
  789.     // Update the prefs
  790.     fe_globalPrefs.task_bar_ontop = ontop;
  791.  
  792.     // Raise the shell if needed
  793.     if (fe_globalPrefs.task_bar_ontop)
  794.     {
  795.         XFE_Dashboard::raiseFloatingShell();
  796.     }
  797. }
  798. //////////////////////////////////////////////////////////////////////////
  799. /* static */ void
  800. XFE_Dashboard::showFloatingTaskBar(XFE_Frame * parentFrame)
  801. {
  802.     // Make sure the floating task bar is started
  803.     XFE_Dashboard::startFloatingTaskBar(parentFrame);
  804.  
  805.     // Manage the floating task bar
  806.     XtManageChild(XFE_Dashboard::m_floatingTaskBar->getBaseWidget());
  807. }
  808. #endif
  809. //////////////////////////////////////////////////////////////////////////
  810. XFE_CALLBACK_DEFN(XFE_Dashboard, showCommandStringNotice)
  811.     (XFE_NotificationCenter *    /* obj */,
  812.      void *                        /* clientData */,
  813.      void *                        callData)
  814. {
  815.     CommandType cmd = (CommandType)callData;
  816.     XFE_Component*  component = (XFE_Component*)m_toplevel;
  817.     char*       doc_string = NULL;
  818.  
  819.     if (!XfeIsAlive(m_widget))
  820.         return;
  821.  
  822.     if (component!= NULL)
  823.         doc_string = component->getDocString(cmd);
  824.  
  825. #ifdef DEBUG
  826.     if (doc_string == NULL)
  827.         doc_string = "No Documentation String for this command!!!!";
  828. #endif
  829.  
  830.     setStatusText(doc_string);
  831. }
  832. //////////////////////////////////////////////////////////////////////////
  833. XFE_CALLBACK_DEFN(XFE_Dashboard, eraseCommandStringNotice)
  834.     (XFE_NotificationCenter *    /* obj */,
  835.      void *                        /* clientData */,
  836.      void *                        /* callData */)
  837. {
  838.     if (!XfeIsAlive(m_widget))
  839.         return;
  840.  
  841.     setStatusText("");
  842. }
  843. //////////////////////////////////////////////////////////////////////////
  844. XFE_CALLBACK_DEFN(XFE_Dashboard, setStatusTextNotice)
  845.     (XFE_NotificationCenter *    /* obj */,
  846.      void *                        /* clientData */,
  847.      void *                        callData)
  848. {
  849.     if (!XfeIsAlive(m_widget))
  850.         return;
  851.  
  852.     setStatusText((char *) callData);
  853. }
  854. //////////////////////////////////////////////////////////////////////////
  855. XFE_CALLBACK_DEFN(XFE_Dashboard, update)
  856.     (XFE_NotificationCenter *    /* obj */, 
  857.      void *                        /* clientData */, 
  858.      void *                        /* callData */)
  859. {
  860.     if (!XfeIsAlive(m_widget))
  861.         return;
  862.  
  863.   if (m_securityIcon && m_securityIcon->isAlive())
  864.       {
  865.           m_securityIcon->setPretendSensitive(m_parentFrame->isCommandEnabled((CommandType)m_securityIcon->getName()));
  866.           m_securityIcon->useIconGroup(m_parentFrame->getSecurityStatus());
  867.       }
  868.   if (m_signedIcon && m_signedIcon->isAlive())
  869.       {
  870.           m_signedIcon->setPretendSensitive(m_parentFrame->isCommandEnabled((CommandType)m_signedIcon->getName()));
  871.           m_signedIcon->useIconGroup(m_parentFrame->getSecurityStatus());
  872.       }
  873. }
  874. //////////////////////////////////////////////////////////////////////////
  875. XFE_CALLBACK_DEFN(XFE_Dashboard, doSecurityCommand)
  876.     (XFE_NotificationCenter *        /* obj */,
  877.      void *                            /* clientData */,
  878.      void *                            callData)
  879. {
  880.   XFE_DoCommandArgs *cmdArgs = (XFE_DoCommandArgs *)callData;
  881.  
  882.     if (!XfeIsAlive(m_widget))
  883.         return;
  884.  
  885.   m_parentFrame->doCommand(cmdArgs->cmd, cmdArgs->callData,
  886.                            cmdArgs->info );
  887.     
  888.   m_parentFrame->notifyInterested(Command::commandDispatchedCallback, 
  889.                                   callData);
  890. }
  891. //////////////////////////////////////////////////////////////////////////
  892. XFE_CALLBACK_DEFN(XFE_Dashboard, startCylonNotice)
  893.     (XFE_NotificationCenter *    /* obj */,
  894.      void *                        /* clientData */,
  895.      void *                        /* callData */)
  896. {
  897.     if (!XfeIsAlive(m_widget))
  898.         return;
  899.  
  900.     startCylon();
  901. }
  902. //////////////////////////////////////////////////////////////////////////
  903. XFE_CALLBACK_DEFN(XFE_Dashboard, stopCylonNotice)
  904.     (XFE_NotificationCenter *    /* obj */,
  905.      void *                        /* clientData */,
  906.      void *                        /* callData */)
  907. {
  908.     if (!XfeIsAlive(m_widget))
  909.         return;
  910.  
  911.     stopCylon();
  912. }
  913. //////////////////////////////////////////////////////////////////////////
  914. XFE_CALLBACK_DEFN(XFE_Dashboard, tickCylonNotice)
  915.     (XFE_NotificationCenter *    /* obj */,
  916.      void *                        /* clientData */,
  917.      void *                        /* callData */)
  918. {
  919.     if (!XfeIsAlive(m_widget))
  920.         return;
  921.  
  922.     tickCylon();
  923. }
  924. //////////////////////////////////////////////////////////////////////////
  925. XFE_CALLBACK_DEFN(XFE_Dashboard, progressBarUpdatePercentNotice)
  926.     (XFE_NotificationCenter *    /* obj */,
  927.      void *                        /* clientData */,
  928.      void *                        callData)
  929. {
  930.     if (!XfeIsAlive(m_widget))
  931.         return;
  932.  
  933.     setProgressBarPercent((int) callData);
  934. }
  935. //////////////////////////////////////////////////////////////////////////
  936. XFE_CALLBACK_DEFN(XFE_Dashboard, progressBarUpdateTextNotice)
  937.     (XFE_NotificationCenter *    /* obj */,
  938.      void *                        /* clientData */,
  939.      void *                        callData)
  940. {
  941.     setProgressBarText((char *) callData);
  942. }
  943. //////////////////////////////////////////////////////////////////////////
  944.  
  945. #ifdef MOZ_TASKBAR
  946. /* static */ void
  947. XFE_Dashboard::floatingMappingCB(Widget        /* w */,
  948.                                  XtPointer    clientData,
  949.                                  XtPointer    callData)
  950. {
  951.     XFE_Dashboard *            db = (XFE_Dashboard *) clientData;
  952.     XmAnyCallbackStruct *    cbs = (XmAnyCallbackStruct *) callData;
  953.  
  954.     XP_ASSERT( db != NULL );
  955.     XP_ASSERT( cbs != NULL );
  956.  
  957.     if (!db || !cbs)
  958.     {
  959.         return;
  960.     }
  961.  
  962.     switch(cbs->reason)
  963.     {
  964.     case XmCR_FLOATING_MAP:
  965.  
  966.         if (XFE_Dashboard::m_floatingDocked)
  967.         {
  968.             // Floating task bar is now docked
  969.             XFE_Dashboard::m_floatingDocked = False;
  970.  
  971.             // Increase the top level window count for the floating taskbar
  972.             fe_WindowCount++;
  973.             
  974.             // Notify all frames about the change in top level window count
  975.             XFE_MozillaApp::theApp()->notifyInterested(
  976.                 XFE_MozillaApp::changeInToplevelFrames,
  977.                 (void *) fe_WindowCount);
  978.             
  979.             D( printf("  map = undock (%s,%s) count = %d\n",
  980.                       XtName(db->m_parentFrame->getBaseWidget()),
  981.                       XtName(XtParent(XtParent(w))),
  982.                       fe_WindowCount); );
  983.  
  984.             // Update the prefs
  985.             fe_globalPrefs.task_bar_floating = True;
  986.  
  987.             // Make sure the floating shell is raised
  988.             XFE_Dashboard::raiseFloatingShell();
  989.         }
  990.  
  991.         break;
  992.  
  993.     case XmCR_FLOATING_UNMAP:
  994.  
  995.         if (!XFE_Dashboard::m_floatingDocked)
  996.         {
  997.             // Floating task bar is now un docked
  998.             XFE_Dashboard::m_floatingDocked = True;
  999.  
  1000.             // Decrease the top level window count for the floating taskbar
  1001.             fe_WindowCount--;
  1002.             
  1003.             // Notify all frames about the change in top level window count
  1004.             XFE_MozillaApp::theApp()->notifyInterested(
  1005.                 XFE_MozillaApp::changeInToplevelFrames,
  1006.                 (void *) fe_WindowCount);
  1007.             
  1008.             D( printf("unmap =   dock (%s,%s) count = %d\n",
  1009.                       XtName(db->m_parentFrame->getBaseWidget()),
  1010.                       XtName(XtParent(XtParent(w))),
  1011.                       fe_WindowCount); );
  1012.  
  1013.             // If no windows are left after closing the floating task bar, exit
  1014.             if (XFE_MozillaApp::theApp()->toplevelWindowCount() == 0)
  1015.             {
  1016.                 // If the app is closed from the taskbar, then the 
  1017.                 // instead of changing the pref to not floating, we make 
  1018.                 // sure it remains floating.
  1019.                 fe_globalPrefs.task_bar_floating = True;
  1020.  
  1021.                 XFE_MozillaApp::theApp()->exit(0);
  1022.             }
  1023.             else
  1024.             {
  1025.                 // Update the prefs
  1026.                 fe_globalPrefs.task_bar_floating = False;
  1027.             }
  1028.         }
  1029.  
  1030.         break;
  1031.     }
  1032. }
  1033. //////////////////////////////////////////////////////////////////////////
  1034. /* static */ void
  1035. XFE_Dashboard::floatingActionCB(Widget        /* w */,
  1036.                                 XtPointer    clientData,
  1037.                                 XtPointer    /* callData */)
  1038. {
  1039.     XFE_Dashboard *            db = (XFE_Dashboard *) clientData;
  1040.  
  1041.     XP_ASSERT( db != NULL );
  1042.  
  1043.     if (!db)
  1044.     {
  1045.         return;
  1046.     }
  1047. }
  1048. //////////////////////////////////////////////////////////////////////////
  1049. /* static */ void
  1050. XFE_Dashboard::floatingButtonEH(Widget        /* w */,
  1051.                                 XtPointer    /* clientData */,
  1052.                                 XEvent *    event,
  1053.                                 Boolean *    cont)
  1054. {
  1055.     // Make sure Button3 was pressed
  1056.     if ((event->type == ButtonPress) && (event->xbutton.button == Button3))
  1057.     {
  1058.          XFE_Dashboard::m_floatingPopup->position(event);
  1059.          XFE_Dashboard::m_floatingPopup->show();
  1060.          XFE_Dashboard::m_floatingPopup->raise();
  1061.     }
  1062.     
  1063.     *cont = True;
  1064. }
  1065. //////////////////////////////////////////////////////////////////////////
  1066. /* static */ void
  1067. XFE_Dashboard::floatingConfigureEH(Widget        /* w */,
  1068.                                    XtPointer    /* clientData */,
  1069.                                    XEvent *        event,
  1070.                                    Boolean *    cont)
  1071. {
  1072.     // Configure
  1073.     if (event->type == ConfigureNotify)
  1074.     {
  1075.         Position x = XfeRootX(XFE_Dashboard::m_floatingShell);
  1076.         Position y = XfeRootY(XFE_Dashboard::m_floatingShell);
  1077.         Position offset_x;
  1078.         Position offset_y;
  1079.  
  1080.         // Try and obtain the offset occupied by the wm decorations
  1081.         if (!XfeShellGetDecorationOffset(XFE_Dashboard::m_floatingShell,
  1082.                                          &offset_x,&offset_y))
  1083.         {
  1084.             offset_x = 0;
  1085.             offset_y = 0;
  1086.         }
  1087.  
  1088.          x -= offset_x;
  1089.          y -= offset_y;
  1090.  
  1091.         // Update the new position in the prefs
  1092.         fe_globalPrefs.task_bar_x = x;
  1093.         fe_globalPrefs.task_bar_y = y;
  1094.     }
  1095.     // Visibility
  1096.     else if (event->type == VisibilityNotify)
  1097.     {
  1098.         // If it is, raise the floating shell
  1099.         XFE_Dashboard::raiseFloatingShell();
  1100.     }
  1101.     
  1102.     *cont = True;
  1103. }
  1104. #endif
  1105. //////////////////////////////////////////////////////////////////////////
  1106. void
  1107. XFE_Dashboard::setShowSecurityIcon(XP_Bool state)
  1108. {
  1109.     XP_ASSERT( XfeIsAlive(m_widget) );
  1110.  
  1111.     // Create the security icon only if it is not disabled through resources.
  1112.     if (!XfeChildIsEnabled(m_widget,
  1113.                            xfeCmdViewSecurity,
  1114.                            "ViewSecurity",
  1115.                            True))
  1116.     {
  1117.         return;
  1118.     }
  1119.  
  1120.     // Create the security bar if needed
  1121.     if (!m_securityBar)
  1122.     {
  1123.         createSecurityBar();
  1124.     }
  1125.  
  1126.     // Create the security icon if needed
  1127.     if (!m_securityIcon)
  1128.     {
  1129.         addSecurityIcon();
  1130.     }
  1131.  
  1132.     XP_ASSERT( m_securityIcon != NULL );
  1133.  
  1134.     if (m_securityIcon && m_securityIcon->isAlive())
  1135.     {
  1136.         m_securityIcon->setManagedState(state);
  1137.     }
  1138.  
  1139.     // Configure the secutiry bar
  1140.     configureSecurityBar();
  1141. }
  1142. //////////////////////////////////////////////////////////////////////////
  1143. void
  1144. XFE_Dashboard::setShowStatusBar(XP_Bool state)
  1145. {
  1146.     XP_ASSERT( XfeIsAlive(m_widget) );
  1147.  
  1148.     // Create the status bar if needed
  1149.     if (!m_statusBar)
  1150.     {
  1151.         createStatusBar();
  1152.     }
  1153.  
  1154.     XfeSetManagedState(m_statusBar,state);
  1155. }
  1156. //////////////////////////////////////////////////////////////////////////
  1157. void
  1158. XFE_Dashboard::setShowProgressBar(XP_Bool state)
  1159. {
  1160.     XP_ASSERT( XfeIsAlive(m_widget) );
  1161.  
  1162.     // Create the progress bar if needed
  1163.     if (!m_progressBar)
  1164.     {
  1165.         createProgressBar();
  1166.     }
  1167.  
  1168.     XfeSetManagedState(m_progressBar,state);
  1169. }
  1170. //////////////////////////////////////////////////////////////////////////
  1171. void
  1172. XFE_Dashboard::setShowSignedIcon(XP_Bool state)
  1173. {
  1174.     XP_ASSERT( XfeIsAlive(m_widget) );
  1175.  
  1176.     // Create the signed icon only if it is not disabled through resources.
  1177.     if (!XfeChildIsEnabled(m_widget,
  1178.                            xfeCmdViewSecurity,
  1179.                            "ViewSecurity",
  1180.                            True))
  1181.     {
  1182.         return;
  1183.     }
  1184.  
  1185.  
  1186.     // Create the security bar if needed
  1187.     if (!m_securityBar)
  1188.     {
  1189.         createSecurityBar();
  1190.     }
  1191.  
  1192.     // Create the signed icon if needed
  1193.     if (!m_signedIcon)
  1194.     {
  1195.         addSignedIcon();
  1196.     }
  1197.  
  1198.     XP_ASSERT( m_signedIcon != NULL );
  1199.  
  1200.     if (m_signedIcon && m_signedIcon->isAlive())
  1201.     {
  1202.         m_signedIcon->setManagedState(state);
  1203.     }
  1204.  
  1205.     // Configure the secutiry bar
  1206.     configureSecurityBar();
  1207. }
  1208. //////////////////////////////////////////////////////////////////////////
  1209. XP_Bool
  1210. XFE_Dashboard::isSecurityIconShown()
  1211. {
  1212.     return (m_securityIcon && m_securityIcon->isShown());
  1213. }
  1214. //////////////////////////////////////////////////////////////////////////
  1215. XP_Bool
  1216. XFE_Dashboard::isSignedIconShown()
  1217. {
  1218.     return (m_signedIcon && m_signedIcon->isShown());
  1219. }
  1220. //////////////////////////////////////////////////////////////////////////
  1221. XP_Bool
  1222. XFE_Dashboard::processTraversal(XmTraversalDirection direction)
  1223. {
  1224.     // Try the security icon
  1225.     if ((m_securityIcon && m_securityIcon->isAlive()) && 
  1226.         XmProcessTraversal(m_securityIcon->getBaseWidget(),direction))
  1227.     {
  1228.         return True;
  1229.     }
  1230.  
  1231.     // Try the signed icon
  1232.     if ((m_signedIcon && m_signedIcon->isAlive()) && 
  1233.         XmProcessTraversal(m_signedIcon->getBaseWidget(),direction))
  1234.     {
  1235.         return True;
  1236.     }
  1237.  
  1238.     // Try the progress bar
  1239.     if (XfeIsAlive(m_progressBar) && 
  1240.         XmProcessTraversal(m_progressBar,direction))
  1241.     {
  1242.         return True;
  1243.     }
  1244.  
  1245.     // Try the status bar
  1246.     if (XfeIsAlive(m_statusBar) && 
  1247.         XmProcessTraversal(m_statusBar,direction))
  1248.     {
  1249.         return True;
  1250.     }
  1251.  
  1252. #ifdef MOZ_TASKBAR
  1253.     // Try the task bar
  1254.     if ((m_dockedTaskBar && m_dockedTaskBar->isAlive()) && 
  1255.         XmProcessTraversal(m_dockedTaskBar->getBaseWidget(),direction))
  1256.     {
  1257.         return True;
  1258.     }
  1259. #endif
  1260.  
  1261.     // Try the base widget
  1262.     if (XfeIsAlive(m_widget) && 
  1263.         XmProcessTraversal(m_widget,direction))
  1264.     {
  1265.         return True;
  1266.     }
  1267.  
  1268.     return False;
  1269. }
  1270. //////////////////////////////////////////////////////////////////////////
  1271. #ifdef MOZ_TASKBAR
  1272. /* static */ XFE_TaskBar *
  1273. XFE_Dashboard::getTaskBar()
  1274. {
  1275.     return m_dockedTaskBar;
  1276. }
  1277. //////////////////////////////////////////////////////////////////////////
  1278. /* static */ void
  1279. XFE_Dashboard::raiseFloatingShell()
  1280. {
  1281.     XP_ASSERT( XFE_Dashboard::floatingTaskBarIsAlive() );
  1282.  
  1283.     // Dont raise the window if the XmDisplay is grabbed or a tooltip is
  1284.     // showing
  1285.     if (XfeDisplayIsUserGrabbed(XFE_Dashboard::m_floatingShell) ||
  1286.         fe_ToolTipIsShowing())
  1287.     {
  1288.         return;
  1289.     }
  1290.  
  1291.     // If the taskbar needs to be ontop, raise it
  1292.     if (fe_globalPrefs.task_bar_ontop)
  1293.     {
  1294.         // The time 'now'
  1295.         time_t time_now = time(NULL);
  1296.  
  1297.         // The time difference between 'now' and the last time we were called
  1298.         time_t time_diff = time_now - m_floatingLastRaisedTime;
  1299.  
  1300.         // If the difference is 0, then we are being called more than once
  1301.         // in one second.
  1302.         if (time_diff == 0)
  1303.         {
  1304.             m_floatingTimesRaisedPerSecond++;
  1305.         }
  1306.         // Otherwise we are being called after a 'long' interval and we 
  1307.         // reset the time/sec counter.
  1308.         else
  1309.         {
  1310.             m_floatingTimesRaisedPerSecond = 0;
  1311.         }
  1312.  
  1313.         // If the times/sec counter is more than a magic number, then we
  1314.         // are being called too often and we are most likely in an infinite
  1315.         // loop fighting with another window that also wants to be always
  1316.         // on top.
  1317.         if (m_floatingTimesRaisedPerSecond <= MAX_FLOATING_RAISES_PER_SECOND)
  1318.         {
  1319.             Widget shell = XFE_Dashboard::m_floatingShell;
  1320.             
  1321.             // Place window on top
  1322.             XWindowChanges changes;
  1323.             
  1324.             changes.stack_mode = Above;
  1325.             
  1326.             XReconfigureWMWindow(XtDisplay(shell),
  1327.                                  XtWindow(shell), 
  1328.                                  XScreenNumberOfScreen(XtScreen(shell)),
  1329.                                  CWStackMode,&changes);
  1330.  
  1331.             m_floatingLastRaisedTime = time_now;
  1332.         }
  1333.     }
  1334. }
  1335. //////////////////////////////////////////////////////////////////////////
  1336. /* static */ XFE_TaskBar *
  1337. XFE_Dashboard::getFloatingTaskBar()
  1338. {
  1339.     XP_ASSERT( XFE_Dashboard::floatingTaskBarIsAlive() );
  1340.     
  1341.     return XFE_Dashboard::m_floatingTaskBar;
  1342. }
  1343. //////////////////////////////////////////////////////////////////////////
  1344. extern "C" void
  1345. fe_showTaskBar(Widget /* toplevel */)
  1346. {
  1347.     XFE_BookmarkFrame * parentFrame = XFE_BookmarkFrame::getBookmarkFrame();
  1348.  
  1349.     XP_ASSERT( parentFrame != NULL );
  1350.  
  1351.     XFE_Dashboard::showFloatingTaskBar(parentFrame);
  1352. }
  1353. //////////////////////////////////////////////////////////////////////////
  1354. #endif
  1355.